From 7f8666b3d1f8029b9978837f469c610b78adce17 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 20 Jul 2023 10:55:59 +0100 Subject: [PATCH 001/980] Create README.md --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..78f36fba --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# PrimAITE From c6cbb5ae8d22cffc1e91e8aec878ee731afed96f Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 26 Jul 2023 19:38:28 +0100 Subject: [PATCH 002/980] Create python-package.yml CI pipeline --- .github/workflows/python-package.yml | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/python-package.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 00000000..055882d2 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,66 @@ +name: Python package + +on: + push: + branches: + - main + - dev + - dev-gui + - 'release/**' + pull_request: + branches: + - main + - dev + - dev-gui + - 'release/**' +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install python dev + run: | + sudo apt update + sudo add-apt-repository ppa:deadsnakes/ppa -y + sudo apt install python${{ matrix.python-version}}-dev -y + + - name: Install Build Dependencies + run: | + python -m pip install --upgrade pip==23.0.1 + pip install wheel==0.38.4 --upgrade + pip install setuptools==66 --upgrade + pip install build + + - name: Build PrimAITE + run: | + python -m build + + - name: Install Yawning-Titan + run: | + PRIMAITE_WHEEL=$(ls ./dist/primaite*.whl) + python -m pip install $PRIMAITE_WHEEL[dev] + + - name: Perform PrimAITE Setup + run: | + primaite setup + + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics + + - name: Run unmarked tests + run: | + pytest tests/ From 5c5528bb94eb40ffaf6b97bd72367f11235db850 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 26 Jul 2023 19:49:24 +0100 Subject: [PATCH 003/980] Updated the README.md with developer install specific instructions --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f7c6efd7..066a8af3 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ ## Getting Started with PrimAITE + ### Pre-Requisites In order to get **PrimAITE** installed, you will need to have the following installed: @@ -12,38 +13,37 @@ In order to get **PrimAITE** installed, you will need to have the following inst **PrimAITE** is designed to be OS-agnostic, and thus should work on most variations/distros of Linux, Windows, and MacOS. -### Installation from source -#### 1. Navigate to the PrimAITE folder and create a new python virtual environment (venv) +### Installation from source (Developer Install) +#### 1. Create a new python virtual environment (venv) ```unix -python3 -m venv +python3 -m venv venv ``` #### 2. Activate the venv ##### Unix ```bash -source /bin/activate +source venv/bin/activate ``` -##### Windows +##### Windows (Powershell) ```powershell -.\\Scripts\activate +.\venv\Scripts\activate ``` -#### 3. Install `primaite` into the venv along with all of it's dependencies - -```bash -python3 -m pip install -e . -``` - -### Development Installation -To install the development dependencies, postfix the command in step 3 above with the `[dev]` extra. Example: +#### 3. Install `primaite` with the dev extra into the venv along with all of it's dependencies ```bash python3 -m pip install -e .[dev] ``` +#### 4. Perform the PrimAITE setup: + +```bash +primaite setup +``` + ## Building documentation The PrimAITE documentation can be built with the following commands: @@ -53,7 +53,7 @@ cd docs make html ``` -##### Windows +##### Windows (Powershell) ```powershell cd docs .\make.bat html From 1c4695d3919422de169af08a2b00308651e9c011 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 26 Jul 2023 20:05:44 +0100 Subject: [PATCH 004/980] Dropped the ADF build files and updated the package name install step in python-package.yml. Added bug_report.md and feature_request.md files for GitHub --- .azure/.pypirc | 6 -- .azure/artifact-release-pipeline.yaml | 38 --------- .azure/azure-build-deploy-docs-pipeline.yml | 49 ----------- .azure/azure-ci-build-pipeline.yaml | 90 --------------------- .azuredevops/pull_request_template.md | 12 --- .github/ISSUE_TEMPLATE/bug_report.md | 41 ++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 24 ++++++ .github/workflows/python-package.yml | 6 +- README.md | 4 - 9 files changed, 68 insertions(+), 202 deletions(-) delete mode 100644 .azure/.pypirc delete mode 100644 .azure/artifact-release-pipeline.yaml delete mode 100644 .azure/azure-build-deploy-docs-pipeline.yml delete mode 100644 .azure/azure-ci-build-pipeline.yaml delete mode 100644 .azuredevops/pull_request_template.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.azure/.pypirc b/.azure/.pypirc deleted file mode 100644 index 9f89d0ea..00000000 --- a/.azure/.pypirc +++ /dev/null @@ -1,6 +0,0 @@ -[distutils] -Index-servers = - PrimAITE - -[PrimAITE] -Repository = https://pkgs.dev.azure.com/ma-dev-uk/PrimAITE/_packaging/PrimAITE/pypi/upload/ diff --git a/.azure/artifact-release-pipeline.yaml b/.azure/artifact-release-pipeline.yaml deleted file mode 100644 index 47e9aacc..00000000 --- a/.azure/artifact-release-pipeline.yaml +++ /dev/null @@ -1,38 +0,0 @@ -trigger: -- main - -pool: - vmImage: ubuntu-latest -strategy: - matrix: - Python310: - python.version: '3.10' - -steps: -- task: UsePythonVersion@0 - inputs: - versionSpec: '$(python.version)' - displayName: 'Use Python $(python.version)' - -- script: | - python -m pip install --upgrade pip==23.0.1 - pip install wheel==0.38.4 --upgrade - pip install setuptools==66 --upgrade - pip install build==0.10.0 - pip install twine - pip install keyring - pip install artifacts-keyring - displayName: 'Install build dependencies' - -- script: | - python -m build - displayName: 'Build PrimAITE sdist and wheel' - -- task: TwineAuthenticate@1 - displayName: 'Twine Authenticate' - inputs: - artifactFeed: PrimAITE/PrimAITE - -- script: | - python -m twine upload --verbose -r PrimAITE --config-file $(PYPIRC_PATH) dist/*.whl - displayName: 'Artifact Upload' diff --git a/.azure/azure-build-deploy-docs-pipeline.yml b/.azure/azure-build-deploy-docs-pipeline.yml deleted file mode 100644 index 0f44b0c8..00000000 --- a/.azure/azure-build-deploy-docs-pipeline.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Azure Static Web Apps CI/CD - -pr: none -trigger: - branches: - include: - - dev - -jobs: -- job: build_and_deploy_job - displayName: Build and Deploy Job - condition: or(eq(variables['Build.Reason'], 'Manual'),or(eq(variables['Build.Reason'], 'PullRequest'),eq(variables['Build.Reason'], 'IndividualCI'))) - pool: - vmImage: ubuntu-latest - variables: - - group: Azure-Static-Web-Apps-nice-bay-0ad032c03-variable-group - steps: - - checkout: self - submodules: true - - - script: | - python -m pip install --upgrade pip==23.0.1 - pip install wheel==0.38.4 --upgrade - pip install setuptools==66 --upgrade - pip install build==0.10.0 - displayName: 'Install build dependencies' - - - script: | - pip install -e .[dev] - displayName: 'Install Yawning-Titan for docs autosummary' - - - script: | - primaite setup - displayName: 'Perform PrimAITE Setup' - - - script: | - cd docs - make html - cd .. - cd .. - displayName: 'Build Docs' - - - task: AzureStaticWebApp@0 - inputs: - azure_static_web_apps_api_token: $(AZURE_STATIC_WEB_APPS_API_TOKEN_NICE_BAY_0AD032C03) - app_location: "/docs/_build/html" - api_location: "" - output_location: "/" - displayName: 'Deploy Docs to nice-bay-0ad032c03' diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml deleted file mode 100644 index 0bb03594..00000000 --- a/.azure/azure-ci-build-pipeline.yaml +++ /dev/null @@ -1,90 +0,0 @@ -trigger: -- main -- dev -- feature/* -- hotfix/* -- bugfix/* -- release/* - -parameters: - # https://stackoverflow.com/a/70046417 - - name: matrix - type: object - default: - - job_name: 'UbuntuPython38' - py: '3.8' - img: 'ubuntu-latest' - every_time: false - - job_name: 'UbuntuPython310' - py: '3.10' - img: 'ubuntu-latest' - every_time: true - - job_name: 'WindowsPython38' - py: '3.8' - img: 'windows-latest' - every_time: false - - job_name: 'WindowsPython310' - py: '3.10' - img: 'windows-latest' - every_time: false - - job_name: 'MacOSPython38' - py: '3.8' - img: 'macOS-latest' - every_time: false - - job_name: 'MacOSPython310' - py: '3.10' - img: 'macOS-latest' - every_time: false - -stages: - - stage: Test - jobs: - - ${{ each item in parameters.matrix }}: - - job: ${{ item.job_name }} - pool: - vmImage: ${{ item.img }} - - condition: or( eq(variables['Build.Reason'], 'PullRequest'), ${{ item.every_time }} ) - - steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: ${{ item.py }} - displayName: 'Use Python ${{ item.py }}' - - - script: | - python -m pip install pre-commit - pre-commit install - pre-commit run --all-files - displayName: 'Run pre-commits' - - - script: | - python -m pip install --upgrade pip==23.0.1 - pip install wheel==0.38.4 --upgrade - pip install setuptools==66 --upgrade - pip install build==0.10.0 - pip install pytest-azurepipelines - displayName: 'Install build dependencies' - - - script: | - python -m build - displayName: 'Build PrimAITE' - - - script: | - PRIMAITE_WHEEL=$(ls ./dist/primaite*.whl) - python -m pip install $PRIMAITE_WHEEL[dev] - displayName: 'Install PrimAITE' - condition: or(eq( variables['Agent.OS'], 'Linux' ), eq( variables['Agent.OS'], 'Darwin' )) - - - script: | - forfiles /p dist\ /m *.whl /c "cmd /c python -m pip install @file[dev]" - displayName: 'Install PrimAITE' - condition: eq( variables['Agent.OS'], 'Windows_NT' ) - - - script: | - primaite setup - displayName: 'Perform PrimAITE Setup' - - - script: | - pytest -n 4 - displayName: 'Run tests' diff --git a/.azuredevops/pull_request_template.md b/.azuredevops/pull_request_template.md deleted file mode 100644 index 538baf5c..00000000 --- a/.azuredevops/pull_request_template.md +++ /dev/null @@ -1,12 +0,0 @@ -## Summary -*Replace this text with an explanation of what the changes are and how you implemented them. Can this impact any other parts of the codebase that we should keep in mind?* - -## Test process -*How have you tested this (if applicable)?* - -## Checklist -- [ ] This PR is linked to a **work item** -- [ ] I have performed **self-review** of the code -- [ ] I have written **tests** for any new functionality added with this PR -- [ ] I have updated the **documentation** if this PR changes or adds functionality -- [ ] I have run **pre-commit** checks for code style diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..1ee05bfa --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,41 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "[BUG] - " +labels: bug +assignees: '' + +--- + +### Describe the bug: + +A clear and concise description of what the bug is. + +### To Reproduce: + +Steps to reproduce the behaviour: + +1. Import '...' +2. Instantiate '....' +3. Pass to '....' +4. Run '....' +5. See error + +### Expected behaviour + +A clear and concise description of what you expected to happen. + +### Screenshots/Outputs + +If applicable, add screenshots to help explain your problem. + +### Environment (please complete the following information) + + - **OS:** [e.g. Ubuntu 22.04] + - **Python:** [e.g. 3.10.11] + - **PrimAITE Version:** [e.g. v2.0.0] + - **Software:** [e.g. cli, Jupyter, PyCharm, VSCode etc.] + +### Additional context + +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..c0a20642 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,24 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "[REQUEST] - " +labels: feature_request +assignees: '' + +--- + +### Is your feature request related to a problem? + +If so, please give a concise description of what the problem is. Ex. I'm always frustrated when [...] + +### Describe the solution you'd like: + +A clear and concise description of what you want to happen. + +### Describe alternatives you've considered: + +A clear and concise description of any alternative solutions or features you've considered. + +### Additional context: + +Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 055882d2..ed94ad97 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -45,11 +45,11 @@ jobs: run: | python -m build - - name: Install Yawning-Titan + - name: Install PrimAITE run: | PRIMAITE_WHEEL=$(ls ./dist/primaite*.whl) python -m pip install $PRIMAITE_WHEEL[dev] - + - name: Perform PrimAITE Setup run: | primaite setup @@ -61,6 +61,6 @@ jobs: # exit-zero treats all errors as warnings. flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics - - name: Run unmarked tests + - name: Run tests run: | pytest tests/ diff --git a/README.md b/README.md index 066a8af3..d078829e 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,3 @@ make html cd docs .\make.bat html ``` - -This will build the documentation as a collection of HTML files which uses the Read The Docs sphinx theme. Other build -options are available but may require additional dependencies such as LaTeX and PDF. Please refer to the Sphinx documentation -for your specific output requirements. From efbb6ef8df4f21afdc2e50d4d5b181ad9adf85c1 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 26 Jul 2023 20:17:29 +0100 Subject: [PATCH 005/980] Added a CONTRIBUTING.md and added a URL to the Yawning-Titan reference in index.rst --- CONTRIBUTING.md | 39 +++++++++++++++++++++++++++++++++++++++ docs/index.rst | 4 +--- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..4d70ebb3 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,39 @@ +# How to contribute to PrimAITE? + + +### **Did you find a bug?** + + +* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/issues). +* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/issues/new?assignees=&labels=bug&projects=&template=bug_report.md&title=%5BBUG%5D+-+%3Cbug+title+goes+here%3E). Be sure to follow our bug report template with the headers **Describe the bug**, **To Reproduce**, **Expected behaviour**, **Screenshots/Outputs**, **Environment**, and **Additional context** + + +### **Do you have a solution to fix the bug?** + +* [Fork the repository](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/fork). +* Install the pre-commit hook with `pre-commit install`. +* Implement the bug fix. +* Update documentation where applicable. +* Update the **UNRELEASED** section of the [CHANGELOG.md](CHANGELOG.md) file +* Write a suitable test/tests. +* Commit the bug fix to the dev branch on your fork. If the bug has an open issue under [Issues](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/issues), reference the issue in the commit message (e.g. #1 references issue 1). +* Submit a pull request from your dev branch to the Autonomous-Resilient-Cyber-Defence/PrimAITE dev branch. Again, if the bug has an open issue under [Issues](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/issues), reference the issue in the pull request description. + +### **Did you fix whitespace, format code, or make a purely cosmetic patch?** + +Changes that are cosmetic in nature and do not add anything substantial to the stability, functionality, or testability of PrimAITE will generally not be accepted. + +### **Do you intend to add a new feature or change an existing one?** + +* Submit a [feature request issue](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/issues/new?assignees=&labels=feature_request&projects=&template=feature_request.md&title=%5BREQUEST%5D+-+%3Crequest+title+goes+here%3E). +* Know how to implement the new feature or change? Follow the same steps in the bug fix section above to fork, build, document, test, commit, and submit a pull request. + +### **Do you have questions about the source code?** + +Ask any question about how to use PrimAITE in our discussions section. + +### **Do you want to contribute to the PrimAITE documentation?** + +Please follow the "Do you intend to add a new feature or change an existing one?" section above and tag your feature request issue and pull request with the documentation tag. + +Thank you from the PrimAITE dev team! 🙌 diff --git a/docs/index.rst b/docs/index.rst index 208d5abc..3b1a13ec 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -14,9 +14,7 @@ PrimAITE (Primary-level AI Training Environment) is a simulation environment for * The ability to model key characteristics of a platform / system by representing connections, IP addresses, ports, traffic loading, operating systems, file system, services and processes; * Operates at machine-speed to enable fast training cycles. -PrimAITE aims to evolve into an ARCD environment that could be used as the follow-on from Reception level approaches (e.g. YAWNING TITAN), and help bridge the Sim-to-Real gap into Secondary level environments (e.g. IMAGINARY YAK). - -This is similar to the approach taken by FVEY international partners (e.g. AUS CyBORG, US NSA FARLAND and CAN CyGil). These environments are referenced by the Dstl ARCD Agent Training Environments Knowledge Transfer document (TR141342). +PrimAITE aims to evolve into an ARCD environment that could be used as the follow-on from Reception level approaches (e.g. `Yawning-Titan `_), and help bridge the Sim-to-Real gap into Secondary level environments. What is PrimAITE built with -------------------------------------- From 499219eb40d633076bb58b24b9743b5504435552 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 26 Jul 2023 21:11:15 +0100 Subject: [PATCH 006/980] Added project urls to pyproject.toml and a setup.cfg file for PyPi to pickup author and url --- pyproject.toml | 6 ++++++ setup.cfg | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 setup.cfg diff --git a/pyproject.toml b/pyproject.toml index 9691f65c..c2c8076b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,3 +81,9 @@ order_by_type = "False" [tool.black] line-length = 120 + +[project.urls] +Homepage = "https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE" +Documentation = "https://Autonomous-Resilient-Cyber-Defence.github.io/PrimAITE/" +Repository = "https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE" +Changelog = "https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/blob/dev/CHANGELOG.md" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..e46aafd6 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[metadata] +url = https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE +author = Defence Science and Technology Laboratory UK +author_email = oss@dstl.gov.uk From fce4e7893356fb708437f30f3b710b17a20ca864 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 26 Jul 2023 21:40:30 +0100 Subject: [PATCH 007/980] Synced with the github repo release --- .azure/.pypirc | 6 ++ .azure/artifact-release-pipeline.yaml | 38 +++++++++ .azure/azure-build-deploy-docs-pipeline.yml | 49 +++++++++++ .azure/azure-ci-build-pipeline.yaml | 90 +++++++++++++++++++++ .azuredevops/pull_request_template.md | 12 +++ 5 files changed, 195 insertions(+) create mode 100644 .azure/.pypirc create mode 100644 .azure/artifact-release-pipeline.yaml create mode 100644 .azure/azure-build-deploy-docs-pipeline.yml create mode 100644 .azure/azure-ci-build-pipeline.yaml create mode 100644 .azuredevops/pull_request_template.md diff --git a/.azure/.pypirc b/.azure/.pypirc new file mode 100644 index 00000000..9f89d0ea --- /dev/null +++ b/.azure/.pypirc @@ -0,0 +1,6 @@ +[distutils] +Index-servers = + PrimAITE + +[PrimAITE] +Repository = https://pkgs.dev.azure.com/ma-dev-uk/PrimAITE/_packaging/PrimAITE/pypi/upload/ diff --git a/.azure/artifact-release-pipeline.yaml b/.azure/artifact-release-pipeline.yaml new file mode 100644 index 00000000..47e9aacc --- /dev/null +++ b/.azure/artifact-release-pipeline.yaml @@ -0,0 +1,38 @@ +trigger: +- main + +pool: + vmImage: ubuntu-latest +strategy: + matrix: + Python310: + python.version: '3.10' + +steps: +- task: UsePythonVersion@0 + inputs: + versionSpec: '$(python.version)' + displayName: 'Use Python $(python.version)' + +- script: | + python -m pip install --upgrade pip==23.0.1 + pip install wheel==0.38.4 --upgrade + pip install setuptools==66 --upgrade + pip install build==0.10.0 + pip install twine + pip install keyring + pip install artifacts-keyring + displayName: 'Install build dependencies' + +- script: | + python -m build + displayName: 'Build PrimAITE sdist and wheel' + +- task: TwineAuthenticate@1 + displayName: 'Twine Authenticate' + inputs: + artifactFeed: PrimAITE/PrimAITE + +- script: | + python -m twine upload --verbose -r PrimAITE --config-file $(PYPIRC_PATH) dist/*.whl + displayName: 'Artifact Upload' diff --git a/.azure/azure-build-deploy-docs-pipeline.yml b/.azure/azure-build-deploy-docs-pipeline.yml new file mode 100644 index 00000000..0f44b0c8 --- /dev/null +++ b/.azure/azure-build-deploy-docs-pipeline.yml @@ -0,0 +1,49 @@ +name: Azure Static Web Apps CI/CD + +pr: none +trigger: + branches: + include: + - dev + +jobs: +- job: build_and_deploy_job + displayName: Build and Deploy Job + condition: or(eq(variables['Build.Reason'], 'Manual'),or(eq(variables['Build.Reason'], 'PullRequest'),eq(variables['Build.Reason'], 'IndividualCI'))) + pool: + vmImage: ubuntu-latest + variables: + - group: Azure-Static-Web-Apps-nice-bay-0ad032c03-variable-group + steps: + - checkout: self + submodules: true + + - script: | + python -m pip install --upgrade pip==23.0.1 + pip install wheel==0.38.4 --upgrade + pip install setuptools==66 --upgrade + pip install build==0.10.0 + displayName: 'Install build dependencies' + + - script: | + pip install -e .[dev] + displayName: 'Install Yawning-Titan for docs autosummary' + + - script: | + primaite setup + displayName: 'Perform PrimAITE Setup' + + - script: | + cd docs + make html + cd .. + cd .. + displayName: 'Build Docs' + + - task: AzureStaticWebApp@0 + inputs: + azure_static_web_apps_api_token: $(AZURE_STATIC_WEB_APPS_API_TOKEN_NICE_BAY_0AD032C03) + app_location: "/docs/_build/html" + api_location: "" + output_location: "/" + displayName: 'Deploy Docs to nice-bay-0ad032c03' diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml new file mode 100644 index 00000000..0bb03594 --- /dev/null +++ b/.azure/azure-ci-build-pipeline.yaml @@ -0,0 +1,90 @@ +trigger: +- main +- dev +- feature/* +- hotfix/* +- bugfix/* +- release/* + +parameters: + # https://stackoverflow.com/a/70046417 + - name: matrix + type: object + default: + - job_name: 'UbuntuPython38' + py: '3.8' + img: 'ubuntu-latest' + every_time: false + - job_name: 'UbuntuPython310' + py: '3.10' + img: 'ubuntu-latest' + every_time: true + - job_name: 'WindowsPython38' + py: '3.8' + img: 'windows-latest' + every_time: false + - job_name: 'WindowsPython310' + py: '3.10' + img: 'windows-latest' + every_time: false + - job_name: 'MacOSPython38' + py: '3.8' + img: 'macOS-latest' + every_time: false + - job_name: 'MacOSPython310' + py: '3.10' + img: 'macOS-latest' + every_time: false + +stages: + - stage: Test + jobs: + - ${{ each item in parameters.matrix }}: + - job: ${{ item.job_name }} + pool: + vmImage: ${{ item.img }} + + condition: or( eq(variables['Build.Reason'], 'PullRequest'), ${{ item.every_time }} ) + + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: ${{ item.py }} + displayName: 'Use Python ${{ item.py }}' + + - script: | + python -m pip install pre-commit + pre-commit install + pre-commit run --all-files + displayName: 'Run pre-commits' + + - script: | + python -m pip install --upgrade pip==23.0.1 + pip install wheel==0.38.4 --upgrade + pip install setuptools==66 --upgrade + pip install build==0.10.0 + pip install pytest-azurepipelines + displayName: 'Install build dependencies' + + - script: | + python -m build + displayName: 'Build PrimAITE' + + - script: | + PRIMAITE_WHEEL=$(ls ./dist/primaite*.whl) + python -m pip install $PRIMAITE_WHEEL[dev] + displayName: 'Install PrimAITE' + condition: or(eq( variables['Agent.OS'], 'Linux' ), eq( variables['Agent.OS'], 'Darwin' )) + + - script: | + forfiles /p dist\ /m *.whl /c "cmd /c python -m pip install @file[dev]" + displayName: 'Install PrimAITE' + condition: eq( variables['Agent.OS'], 'Windows_NT' ) + + - script: | + primaite setup + displayName: 'Perform PrimAITE Setup' + + - script: | + pytest -n 4 + displayName: 'Run tests' diff --git a/.azuredevops/pull_request_template.md b/.azuredevops/pull_request_template.md new file mode 100644 index 00000000..5ff03e18 --- /dev/null +++ b/.azuredevops/pull_request_template.md @@ -0,0 +1,12 @@ +## Summary +*Replace this text with an explanation of what the changes are and how you implemented them. Can this impact any other parts of the codebase that we should keep in mind?* + +## Test process +*How have you tested this (if applicable)?* + +## Checklist +- [ ] This PR is linked to a **work item** +- [ ] I have performed **self-review** of the code +- [ ] I have written **tests** for any new functionality added with this PR +- [ ] I have updated the **documentation** if this PR changes or adds functionality +- [ ] I have run **pre-commit** checks for code style From 472e85cffb17762342ce49d4f6608adabc2831a2 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 26 Jul 2023 21:49:36 +0100 Subject: [PATCH 008/980] Added additional install instructions to the README.md --- README.md | 76 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index d078829e..53d58509 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,72 @@ # PrimAITE +PrimAITE (Primary-level AI Training Environment) is a simulation environment for training AI under the ARCD programme. + ## Getting Started with PrimAITE - -### Pre-Requisites - -In order to get **PrimAITE** installed, you will need to have the following installed: - -- `python3.8+` -- `python3-pip` -- `virtualenv` - +### 💫 Install & Run **PrimAITE** is designed to be OS-agnostic, and thus should work on most variations/distros of Linux, Windows, and MacOS. +Currently, the PRimAITE wheel can only be installed from GitHub. This may change in the future with release to PyPi. -### Installation from source (Developer Install) -#### 1. Create a new python virtual environment (venv) +#### Windows (PowerShell) + +**Prerequisites:** +* Manual install of Python >= 3.8 < 3.11 + +**Install:** + +``` powershell +mkdir ~\primaite +cd ~\primaite +python3 -m venv .venv +attrib +h .venv /s /d # Hides the .venv directory +.\.venv\Scripts\activate +pip install https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/releases/download/v2.0.0/primaite-2.0.0-py3-none-any.whl +primaite setup +``` + +#### Unix + +**Prerequisites:** +* Manual install of Python >= 3.8 < 3.11 + +``` bash +sudo add-apt-repository ppa:deadsnakes/ppa +sudo apt install python3.10 +sudo apt-get install python3-pip +sudo apt-get install python3-venv +``` +**Install:** + +``` bash +mkdir ~/primaite +cd ~/primaite +python3 -m venv .venv +source .venv/bin/activate +pip install https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/releases/download/v2.0.0/primaite-2.0.0-py3-none-any.whl +primaite setup +``` + + +### Developer Install from Source +To make your own changes to PrimAITE, perform the install from source (developer install) + +#### 1. Clone the PrimAITE repository +``` unix +git clone git@github.com:Autonomous-Resilient-Cyber-Defence/PrimAITE.git +``` + +#### 2. CD into the repo directory +``` unix +cd PrimAITE +``` +#### 3. Create a new python virtual environment (venv) ```unix python3 -m venv venv ``` -#### 2. Activate the venv +#### 4. Activate the venv ##### Unix ```bash @@ -32,19 +78,19 @@ source venv/bin/activate .\venv\Scripts\activate ``` -#### 3. Install `primaite` with the dev extra into the venv along with all of it's dependencies +#### 5. Install `primaite` with the dev extra into the venv along with all of it's dependencies ```bash python3 -m pip install -e .[dev] ``` -#### 4. Perform the PrimAITE setup: +#### 6. Perform the PrimAITE setup: ```bash primaite setup ``` -## Building documentation +## 📚 Building documentation The PrimAITE documentation can be built with the following commands: ##### Unix From c5a23fa035f7a04c551ab78178c837e26402aabc Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 26 Jul 2023 22:10:59 +0100 Subject: [PATCH 009/980] Added run section with primaite session command in the README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 53d58509..326cc27e 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,12 @@ pip install https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/relea primaite setup ``` +**Run:** + +``` bash +primaite session +``` + #### Unix **Prerequisites:** @@ -47,6 +53,12 @@ pip install https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/relea primaite setup ``` +**Run:** + +``` bash +primaite session +``` + ### Developer Install from Source To make your own changes to PrimAITE, perform the install from source (developer install) From bd30bab096135955be364570604cdd43db69975a Mon Sep 17 00:00:00 2001 From: jamesshort1 <107395948+jamesshort1@users.noreply.github.com> Date: Thu, 27 Jul 2023 08:59:24 +0100 Subject: [PATCH 010/980] Update README.md --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 326cc27e..40d49c11 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,34 @@ PrimAITE (Primary-level AI Training Environment) is a simulation environment for training AI under the ARCD programme. +The ARCD Primary-level AI Training Environment (PrimAITE) provides an effective simulation capability for the purposes of training and evaluating AI in a cyber-defensive role. It incorporates the functionality required of a primary-level ARCD environment, which includes: + +- The ability to model a relevant platform / system context; + +- The ability to model key characteristics of a platform / system by representing connections, IP addresses, ports, traffic loading, operating systems, services and processes; + +- Operates at machine-speed to enable fast training cycles. + +PrimAITE presents the following features: + +- Highly configurable (via YAML files) to provide the means to model a variety of platform / system laydowns and adversarial attack scenarios; + +- A Reinforcement Learning (RL) reward function based on (a) the ability to counter the specific modelled adversarial cyber-attack, and (b) the ability to ensure success; + +- Provision of logging to support AI evaluation and metrics gathering; + +- Uses the concept of Information Exchange Requirements (IERs) to model background pattern of life and adversarial behaviour; + +- An Access Control List (ACL) function, mimicking the behaviour of a network firewall, is applied across the model, following standard ACL rule format (e.g. DENY/ALLOW, source IP address, destination IP address, protocol and port); + +- Application of IERs to the platform / system laydown adheres to the ACL ruleset; + +- Presents an OpenAI gym or RLLib interface to the environment, allowing integration with any OpenAI gym compliant defensive agents; + +- Full capture of discrete logs relating to agent training (full system state, agent actions taken, instantaneous and average reward for every step of every episode)​; + +- NetworkX provides laydown visualisation capability.  + ## Getting Started with PrimAITE ### 💫 Install & Run From fde033b3871a1b5b09548160c41a63b0c53244b7 Mon Sep 17 00:00:00 2001 From: jamesshort1 <107395948+jamesshort1@users.noreply.github.com> Date: Thu, 27 Jul 2023 08:59:43 +0100 Subject: [PATCH 011/980] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 40d49c11..390f7f50 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # PrimAITE -PrimAITE (Primary-level AI Training Environment) is a simulation environment for training AI under the ARCD programme. - The ARCD Primary-level AI Training Environment (PrimAITE) provides an effective simulation capability for the purposes of training and evaluating AI in a cyber-defensive role. It incorporates the functionality required of a primary-level ARCD environment, which includes: - The ability to model a relevant platform / system context; From 858396f3d6c6c933b3cf71b4e507193c6e54129d Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 27 Jul 2023 11:03:25 +0100 Subject: [PATCH 012/980] Dropped MIT license until public release --- LICENSE | 21 --------------------- pyproject.toml | 5 ++--- 2 files changed, 2 insertions(+), 24 deletions(-) delete mode 100644 LICENSE diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 93d6f98b..00000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 - 2025 Defence Science and Technology Laboratory UK (https://dstl.gov.uk) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/pyproject.toml b/pyproject.toml index c2c8076b..3cd5922a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,11 +6,11 @@ build-backend = "setuptools.build_meta" name = "primaite" description = "PrimAITE (Primary-level AI Training Environment) is a simulation environment for training AI under the ARCD programme." authors = [{name="Defence Science and Technology Laboratory UK", email="oss@dstl.gov.uk"}] -license = {file = "LICENSE"} +license = {text = "MIT License"} requires-python = ">=3.8, <3.11" dynamic = ["version", "readme"] classifiers = [ - "License :: OSI Approved :: MIT License", + "License :: MIT License", "Development Status :: 5 - Production/Stable", "Operating System :: Microsoft :: Windows", "Operating System :: MacOS", @@ -47,7 +47,6 @@ readme = {file = ["README.md"]} [tool.setuptools] package-dir = {"" = "src"} include-package-data = true -license-files = ["LICENSE"] [project.optional-dependencies] From 92671796a15801366d26d9eaf8510e2dd629b46f Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 27 Jul 2023 11:40:29 +0100 Subject: [PATCH 013/980] Added GFX license conditions. Included LICENSE file in build. Fixed a few character issues in README.md --- LICENSE | 28 ++++++++++++++++++++++++++++ README.md | 28 ++++++++++++++-------------- pyproject.toml | 3 ++- 3 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..3f5e4bb3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,28 @@ +MIT License License + +MIT License Conditions + +These MIT License conditions confirm the provision of the following artefacts as MIT License by Defence Science and Technology +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights + +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + + + diff --git a/README.md b/README.md index 390f7f50..4baf47b9 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,38 @@ # PrimAITE -The ARCD Primary-level AI Training Environment (PrimAITE) provides an effective simulation capability for the purposes of training and evaluating AI in a cyber-defensive role. It incorporates the functionality required of a primary-level ARCD environment, which includes: +The ARCD Primary-level AI Training Environment (**PrimAITE**) provides an effective simulation capability for the purposes of training and evaluating AI in a cyber-defensive role. It incorporates the functionality required of a primary-level ARCD environment, which includes: -- The ability to model a relevant platform / system context; +- The ability to model a relevant platform / system context; -- The ability to model key characteristics of a platform / system by representing connections, IP addresses, ports, traffic loading, operating systems, services and processes; +- The ability to model key characteristics of a platform / system by representing connections, IP addresses, ports, traffic loading, operating systems, services and processes; - Operates at machine-speed to enable fast training cycles. -PrimAITE presents the following features: +PrimAITE presents the following features: -- Highly configurable (via YAML files) to provide the means to model a variety of platform / system laydowns and adversarial attack scenarios; +- Highly configurable (via YAML files) to provide the means to model a variety of platform / system laydowns and adversarial attack scenarios; -- A Reinforcement Learning (RL) reward function based on (a) the ability to counter the specific modelled adversarial cyber-attack, and (b) the ability to ensure success; +- A Reinforcement Learning (RL) reward function based on (a) the ability to counter the specific modelled adversarial cyber-attack, and (b) the ability to ensure success; -- Provision of logging to support AI evaluation and metrics gathering; +- Provision of logging to support AI evaluation and metrics gathering; -- Uses the concept of Information Exchange Requirements (IERs) to model background pattern of life and adversarial behaviour; +- Uses the concept of Information Exchange Requirements (IERs) to model background pattern of life and adversarial behaviour; -- An Access Control List (ACL) function, mimicking the behaviour of a network firewall, is applied across the model, following standard ACL rule format (e.g. DENY/ALLOW, source IP address, destination IP address, protocol and port); +- An Access Control List (ACL) function, mimicking the behaviour of a network firewall, is applied across the model, following standard ACL rule format (e.g. DENY/ALLOW, source IP address, destination IP address, protocol and port); -- Application of IERs to the platform / system laydown adheres to the ACL ruleset; +- Application of IERs to the platform / system laydown adheres to the ACL ruleset; -- Presents an OpenAI gym or RLLib interface to the environment, allowing integration with any OpenAI gym compliant defensive agents; +- Presents an OpenAI gym or RLLib interface to the environment, allowing integration with any OpenAI gym compliant defensive agents; -- Full capture of discrete logs relating to agent training (full system state, agent actions taken, instantaneous and average reward for every step of every episode)​; +- Full capture of discrete logs relating to agent training (full system state, agent actions taken, instantaneous and average reward for every step of every episode); -- NetworkX provides laydown visualisation capability.  +- NetworkX provides laydown visualisation capability. ## Getting Started with PrimAITE ### 💫 Install & Run **PrimAITE** is designed to be OS-agnostic, and thus should work on most variations/distros of Linux, Windows, and MacOS. -Currently, the PRimAITE wheel can only be installed from GitHub. This may change in the future with release to PyPi. +Currently, the PrimAITE wheel can only be installed from GitHub. This may change in the future with release to PyPi. #### Windows (PowerShell) diff --git a/pyproject.toml b/pyproject.toml index 3cd5922a..b66b0168 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" name = "primaite" description = "PrimAITE (Primary-level AI Training Environment) is a simulation environment for training AI under the ARCD programme." authors = [{name="Defence Science and Technology Laboratory UK", email="oss@dstl.gov.uk"}] -license = {text = "MIT License"} +license = {file = "LICENSE"} requires-python = ">=3.8, <3.11" dynamic = ["version", "readme"] classifiers = [ @@ -47,6 +47,7 @@ readme = {file = ["README.md"]} [tool.setuptools] package-dir = {"" = "src"} include-package-data = true +license-files = ["LICENSE"] [project.optional-dependencies] From 378001ff68eba301b9cd409e6a5feed70c1c6fd0 Mon Sep 17 00:00:00 2001 From: jamesshort1 <107395948+jamesshort1@users.noreply.github.com> Date: Thu, 27 Jul 2023 14:57:08 +0100 Subject: [PATCH 014/980] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4baf47b9..b995bf61 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # PrimAITE +![image](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/assets/107395948/c59cc1c2-b5eb-4e0f-91a1-ce0036295e54) + + The ARCD Primary-level AI Training Environment (**PrimAITE**) provides an effective simulation capability for the purposes of training and evaluating AI in a cyber-defensive role. It incorporates the functionality required of a primary-level ARCD environment, which includes: - The ability to model a relevant platform / system context; From 74e3dabae967bf6e2ef42d423ee312c6e500e576 Mon Sep 17 00:00:00 2001 From: jamesshort1 <107395948+jamesshort1@users.noreply.github.com> Date: Fri, 28 Jul 2023 09:39:05 +0100 Subject: [PATCH 015/980] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index b995bf61..a4066647 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # PrimAITE -![image](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/assets/107395948/c59cc1c2-b5eb-4e0f-91a1-ce0036295e54) - +![image](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/assets/107395948/0a14464b-82ba-455e-bc90-5def52f2ce88) The ARCD Primary-level AI Training Environment (**PrimAITE**) provides an effective simulation capability for the purposes of training and evaluating AI in a cyber-defensive role. It incorporates the functionality required of a primary-level ARCD environment, which includes: From 546c66c542f98803e07e01e5cd1786454fae3037 Mon Sep 17 00:00:00 2001 From: jamesshort1 <107395948+jamesshort1@users.noreply.github.com> Date: Fri, 28 Jul 2023 09:40:05 +0100 Subject: [PATCH 016/980] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a4066647..5b18314f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PrimAITE -![image](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/assets/107395948/0a14464b-82ba-455e-bc90-5def52f2ce88) +![image](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/assets/107395948/87d51f0d-1a13-4d2c-aa4d-5de6834acb85) The ARCD Primary-level AI Training Environment (**PrimAITE**) provides an effective simulation capability for the purposes of training and evaluating AI in a cyber-defensive role. It incorporates the functionality required of a primary-level ARCD environment, which includes: From e62846255f20446a4677fa7024b3aabb635c92f2 Mon Sep 17 00:00:00 2001 From: jamesshort1 <107395948+jamesshort1@users.noreply.github.com> Date: Fri, 28 Jul 2023 09:41:29 +0100 Subject: [PATCH 017/980] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b18314f..9a4ff749 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PrimAITE -![image](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/assets/107395948/87d51f0d-1a13-4d2c-aa4d-5de6834acb85) +![image](https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/assets/107395948/fdefa884-1105-44da-88fe-e3a1c98ee361) The ARCD Primary-level AI Training Environment (**PrimAITE**) provides an effective simulation capability for the purposes of training and evaluating AI in a cyber-defensive role. It incorporates the functionality required of a primary-level ARCD environment, which includes: From 7c843d3caa1e91b9221494f7f4ff07be03542b41 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 28 Jul 2023 12:53:49 +0100 Subject: [PATCH 018/980] #1711 - Added the ability to load legacy lay down config files. Added extensive unit testing and end-to-end testing. Also added the ability to set exactly how many num_train_steps, num_eval_steps, num_train_episodes, and num_eval_episode and used when converting a legacy training config. --- src/primaite/config/lay_down_config.py | 43 +- src/primaite/config/training_config.py | 14 +- src/primaite/environment/primaite_env.py | 2 +- .../legacy_config_1_DDOS_BASIC.yaml | 170 ++++++ .../legacy_config_2_DDOS_BASIC.yaml | 362 ++++++++++++ .../legacy_config_3_DOS_VERY_BASIC.yaml | 166 ++++++ .../legacy_config_5_DATA_MANIPULATION.yaml | 534 ++++++++++++++++++ .../new_training_config.yaml | 8 + tests/test_full_legacy_config_session.py | 49 ++ tests/test_lay_down_config.py | 44 ++ 10 files changed, 1383 insertions(+), 9 deletions(-) create mode 100644 tests/config/legacy_conversion/legacy_config_1_DDOS_BASIC.yaml create mode 100644 tests/config/legacy_conversion/legacy_config_2_DDOS_BASIC.yaml create mode 100644 tests/config/legacy_conversion/legacy_config_3_DOS_VERY_BASIC.yaml create mode 100644 tests/config/legacy_conversion/legacy_config_5_DATA_MANIPULATION.yaml create mode 100644 tests/test_full_legacy_config_session.py create mode 100644 tests/test_lay_down_config.py diff --git a/src/primaite/config/lay_down_config.py b/src/primaite/config/lay_down_config.py index 65ca7e91..fe3e3429 100644 --- a/src/primaite/config/lay_down_config.py +++ b/src/primaite/config/lay_down_config.py @@ -1,7 +1,7 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK from logging import Logger from pathlib import Path -from typing import Any, Dict, Final, Union +from typing import Any, Dict, Final, List, Union import yaml @@ -12,14 +12,43 @@ _LOGGER: Logger = getLogger(__name__) _EXAMPLE_LAY_DOWN: Final[Path] = PRIMAITE_PATHS.user_config_path / "example_config" / "lay_down" -def convert_legacy_lay_down_config_dict(legacy_config_dict: Dict[str, Any]) -> Dict[str, Any]: +def convert_legacy_lay_down_config(legacy_config: List[Dict[str, Any]]) -> List[Dict[str, Any]]: """ - Convert a legacy lay down config dict to the new format. + Convert a legacy lay down config to the new format. - :param legacy_config_dict: A legacy lay down config dict. + :param legacy_config: A legacy lay down config. """ - _LOGGER.warning("Legacy lay down config conversion not yet implemented") - return legacy_config_dict + field_conversion_map = { + "itemType": "item_type", + "portsList": "ports_list", + "serviceList": "service_list", + "baseType": "node_class", + "nodeType": "node_type", + "hardwareState": "hardware_state", + "softwareState": "software_state", + "startStep": "start_step", + "endStep": "end_step", + "fileSystemState": "file_system_state", + "ipAddress": "ip_address", + "missionCriticality": "mission_criticality", + } + new_config = [] + for item in legacy_config: + if "itemType" in item: + if item["itemType"] in ["ACTIONS", "STEPS"]: + continue + new_dict = {} + for key in item.keys(): + conversion_key = field_conversion_map.get(key) + if key == "id" and "itemType" in item: + if item["itemType"] == "NODE": + conversion_key = "node_id" + if conversion_key: + new_dict[conversion_key] = item[key] + else: + new_dict[key] = item[key] + new_config.append(new_dict) + return new_config def load(file_path: Union[str, Path], legacy_file: bool = False) -> Dict: @@ -39,7 +68,7 @@ def load(file_path: Union[str, Path], legacy_file: bool = False) -> Dict: _LOGGER.debug(f"Loading lay down config file: {file_path}") if legacy_file: try: - config = convert_legacy_lay_down_config_dict(config) + config = convert_legacy_lay_down_config(config) except KeyError: msg = ( f"Failed to convert lay down config file {file_path} " diff --git a/src/primaite/config/training_config.py b/src/primaite/config/training_config.py index ebfee09a..b0f99603 100644 --- a/src/primaite/config/training_config.py +++ b/src/primaite/config/training_config.py @@ -314,6 +314,9 @@ def convert_legacy_training_config_dict( agent_identifier: AgentIdentifier = AgentIdentifier.PPO, action_type: ActionType = ActionType.ANY, num_train_steps: int = 256, + num_eval_steps: int = 256, + num_train_episodes: int = 10, + num_eval_episodes: int = 1, ) -> Dict[str, Any]: """ Convert a legacy training config dict to the new format. @@ -325,8 +328,14 @@ def convert_legacy_training_config_dict( training configs don't have agent_identifier values. :param action_type: The action space type to set as legacy training configs don't have action_type values. - :param num_train_steps: The number of steps to set as legacy training configs + :param num_train_steps: The number of train steps to set as legacy training configs don't have num_train_steps values. + :param num_eval_steps: The number of eval steps to set as legacy training configs + don't have num_eval_steps values. + :param num_train_episodes: The number of train episodes to set as legacy training configs + don't have num_train_episodes values. + :param num_eval_episodes: The number of eval episodes to set as legacy training configs + don't have num_eval_episodes values. :return: The converted training config dict. """ config_dict = { @@ -334,6 +343,9 @@ def convert_legacy_training_config_dict( "agent_identifier": agent_identifier.name, "action_type": action_type.name, "num_train_steps": num_train_steps, + "num_eval_steps": num_eval_steps, + "num_train_episodes": num_train_episodes, + "num_eval_episodes": num_eval_episodes, "sb3_output_verbose_level": SB3OutputVerboseLevel.INFO.name, } session_type_map = {"TRAINING": "TRAIN", "EVALUATION": "EVAL"} diff --git a/src/primaite/environment/primaite_env.py b/src/primaite/environment/primaite_env.py index cde586ed..98702375 100644 --- a/src/primaite/environment/primaite_env.py +++ b/src/primaite/environment/primaite_env.py @@ -1027,7 +1027,7 @@ class Primaite(Env): acl_rule_destination = item["destination"] acl_rule_protocol = item["protocol"] acl_rule_port = item["port"] - acl_rule_position = item["position"] + acl_rule_position = item.get("position") self.acl.add_rule( acl_rule_permission, diff --git a/tests/config/legacy_conversion/legacy_config_1_DDOS_BASIC.yaml b/tests/config/legacy_conversion/legacy_config_1_DDOS_BASIC.yaml new file mode 100644 index 00000000..5db0ff24 --- /dev/null +++ b/tests/config/legacy_conversion/legacy_config_1_DDOS_BASIC.yaml @@ -0,0 +1,170 @@ +# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +- itemType: ACTIONS + type: NODE +- itemType: STEPS + steps: 128 +- itemType: PORTS + portsList: + - port: '80' +- itemType: SERVICES + serviceList: + - name: TCP +- itemType: NODE + id: '1' + name: PC1 + baseType: SERVICE + nodeType: COMPUTER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.1.2 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '2' + name: SERVER + baseType: SERVICE + nodeType: SERVER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.1.3 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '3' + name: PC2 + baseType: SERVICE + nodeType: COMPUTER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.1.4 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '4' + name: SWITCH1 + baseType: ACTIVE + nodeType: SWITCH + priority: P2 + hardwareState: 'ON' + ipAddress: 192.168.1.5 + softwareState: GOOD + fileSystemState: GOOD +- itemType: NODE + id: '5' + name: SWITCH2 + baseType: ACTIVE + nodeType: SWITCH + priority: P2 + hardwareState: 'ON' + ipAddress: 192.168.1.6 + softwareState: GOOD + fileSystemState: GOOD +- itemType: NODE + id: '6' + name: SWITCH3 + baseType: ACTIVE + nodeType: SWITCH + priority: P2 + hardwareState: 'ON' + ipAddress: 192.168.1.7 + softwareState: GOOD + fileSystemState: GOOD +- itemType: LINK + id: '7' + name: link1 + bandwidth: 1000000000 + source: '1' + destination: '4' +- itemType: LINK + id: '8' + name: link2 + bandwidth: 1000000000 + source: '4' + destination: '2' +- itemType: LINK + id: '9' + name: link3 + bandwidth: 1000000000 + source: '2' + destination: '5' +- itemType: LINK + id: '10' + name: link4 + bandwidth: 1000000000 + source: '2' + destination: '6' +- itemType: LINK + id: '11' + name: link5 + bandwidth: 1000000000 + source: '5' + destination: '3' +- itemType: LINK + id: '12' + name: link6 + bandwidth: 1000000000 + source: '6' + destination: '3' +- itemType: GREEN_IER + id: '13' + startStep: 1 + endStep: 128 + load: 100000 + protocol: TCP + port: '80' + source: '3' + destination: '2' + missionCriticality: 5 +- itemType: RED_POL + id: '14' + startStep: 50 + endStep: 50 + targetNodeId: '1' + initiator: DIRECT + type: SERVICE + protocol: TCP + state: COMPROMISED + sourceNodeId: NA + sourceNodeService: NA + sourceNodeServiceState: NA +- itemType: RED_IER + id: '15' + startStep: 60 + endStep: 100 + load: 1000000 + protocol: TCP + port: '80' + source: '1' + destination: '2' + missionCriticality: 0 +- itemType: RED_POL + id: '16' + startStep: 80 + endStep: 80 + targetNodeId: '2' + initiator: IER + type: SERVICE + protocol: TCP + state: COMPROMISED + sourceNodeId: NA + sourceNodeService: NA + sourceNodeServiceState: NA +- itemType: ACL_RULE + id: '17' + permission: ALLOW + source: ANY + destination: ANY + protocol: ANY + port: ANY diff --git a/tests/config/legacy_conversion/legacy_config_2_DDOS_BASIC.yaml b/tests/config/legacy_conversion/legacy_config_2_DDOS_BASIC.yaml new file mode 100644 index 00000000..2e791bb1 --- /dev/null +++ b/tests/config/legacy_conversion/legacy_config_2_DDOS_BASIC.yaml @@ -0,0 +1,362 @@ +# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +- itemType: ACTIONS + type: NODE +- itemType: STEPS + steps: 128 +- itemType: PORTS + portsList: + - port: '80' +- itemType: SERVICES + serviceList: + - name: TCP +- itemType: NODE + id: '1' + name: PC1 + baseType: SERVICE + nodeType: COMPUTER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.10.11 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '2' + name: PC2 + baseType: SERVICE + nodeType: COMPUTER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.10.12 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '3' + name: PC3 + baseType: SERVICE + nodeType: COMPUTER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.10.13 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '4' + name: PC4 + baseType: SERVICE + nodeType: COMPUTER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.20.14 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '5' + name: SWITCH1 + baseType: ACTIVE + nodeType: SWITCH + priority: P2 + hardwareState: 'ON' + ipAddress: 192.168.1.2 + softwareState: GOOD + fileSystemState: GOOD +- itemType: NODE + id: '6' + name: IDS + baseType: SERVICE + nodeType: SERVER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.1.4 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '7' + name: SWITCH2 + baseType: ACTIVE + nodeType: SWITCH + priority: P2 + hardwareState: 'ON' + ipAddress: 192.168.1.3 + softwareState: GOOD + fileSystemState: GOOD +- itemType: NODE + id: '8' + name: LOP1 + baseType: SERVICE + nodeType: LOP + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.1.12 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '9' + name: SERVER1 + baseType: SERVICE + nodeType: SERVER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.10.14 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '10' + name: SERVER2 + baseType: SERVICE + nodeType: SERVER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.20.15 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: LINK + id: '11' + name: link1 + bandwidth: 1000000000 + source: '1' + destination: '5' +- itemType: LINK + id: '12' + name: link2 + bandwidth: 1000000000 + source: '2' + destination: '5' +- itemType: LINK + id: '13' + name: link3 + bandwidth: 1000000000 + source: '3' + destination: '5' +- itemType: LINK + id: '14' + name: link4 + bandwidth: 1000000000 + source: '4' + destination: '5' +- itemType: LINK + id: '15' + name: link5 + bandwidth: 1000000000 + source: '5' + destination: '6' +- itemType: LINK + id: '16' + name: link6 + bandwidth: 1000000000 + source: '5' + destination: '8' +- itemType: LINK + id: '17' + name: link7 + bandwidth: 1000000000 + source: '6' + destination: '7' +- itemType: LINK + id: '18' + name: link8 + bandwidth: 1000000000 + source: '8' + destination: '7' +- itemType: LINK + id: '19' + name: link9 + bandwidth: 1000000000 + source: '7' + destination: '9' +- itemType: LINK + id: '20' + name: link10 + bandwidth: 1000000000 + source: '7' + destination: '10' +- itemType: GREEN_IER + id: '21' + startStep: 1 + endStep: 128 + load: 100000 + protocol: TCP + port: '80' + source: '1' + destination: '9' + missionCriticality: 2 +- itemType: GREEN_IER + id: '22' + startStep: 1 + endStep: 128 + load: 100000 + protocol: TCP + port: '80' + source: '2' + destination: '9' + missionCriticality: 2 +- itemType: GREEN_IER + id: '23' + startStep: 1 + endStep: 128 + load: 100000 + protocol: TCP + port: '80' + source: '9' + destination: '3' + missionCriticality: 5 +- itemType: GREEN_IER + id: '24' + startStep: 1 + endStep: 128 + load: 100000 + protocol: TCP + port: '80' + source: '4' + destination: '10' + missionCriticality: 2 +- itemType: ACL_RULE + id: '25' + permission: ALLOW + source: 192.168.10.11 + destination: 192.168.10.14 + protocol: TCP + port: 80 +- itemType: ACL_RULE + id: '26' + permission: ALLOW + source: 192.168.10.12 + destination: 192.168.10.14 + protocol: TCP + port: 80 +- itemType: ACL_RULE + id: '27' + permission: ALLOW + source: 192.168.10.13 + destination: 192.168.10.14 + protocol: TCP + port: 80 +- itemType: ACL_RULE + id: '28' + permission: ALLOW + source: 192.168.20.14 + destination: 192.168.20.15 + protocol: TCP + port: 80 +- itemType: ACL_RULE + id: '29' + permission: ALLOW + source: 192.168.10.14 + destination: 192.168.10.13 + protocol: TCP + port: 80 +- itemType: ACL_RULE + id: '30' + permission: DENY + source: 192.168.10.11 + destination: 192.168.20.15 + protocol: TCP + port: 80 +- itemType: ACL_RULE + id: '31' + permission: DENY + source: 192.168.10.12 + destination: 192.168.20.15 + protocol: TCP + port: 80 +- itemType: ACL_RULE + id: '32' + permission: DENY + source: 192.168.10.13 + destination: 192.168.20.15 + protocol: TCP + port: 80 +- itemType: ACL_RULE + id: '33' + permission: DENY + source: 192.168.20.14 + destination: 192.168.10.14 + protocol: TCP + port: 80 +- itemType: RED_POL + id: '34' + startStep: 20 + endStep: 20 + targetNodeId: '1' + initiator: DIRECT + type: SERVICE + protocol: TCP + state: COMPROMISED + sourceNodeId: NA + sourceNodeService: NA + sourceNodeServiceState: NA +- itemType: RED_POL + id: '35' + startStep: 20 + endStep: 20 + targetNodeId: '2' + initiator: DIRECT + type: SERVICE + protocol: TCP + state: COMPROMISED + sourceNodeId: NA + sourceNodeService: NA + sourceNodeServiceState: NA +- itemType: RED_IER + id: '36' + startStep: 30 + endStep: 128 + load: 440000000 + protocol: TCP + port: '80' + source: '1' + destination: '9' + missionCriticality: 0 +- itemType: RED_IER + id: '37' + startStep: 30 + endStep: 128 + load: 440000000 + protocol: TCP + port: '80' + source: '2' + destination: '9' + missionCriticality: 0 +- itemType: RED_POL + id: '38' + startStep: 30 + endStep: 30 + targetNodeId: '9' + initiator: IER + type: SERVICE + protocol: TCP + state: OVERWHELMED + sourceNodeId: NA + sourceNodeService: NA + sourceNodeServiceState: NA diff --git a/tests/config/legacy_conversion/legacy_config_3_DOS_VERY_BASIC.yaml b/tests/config/legacy_conversion/legacy_config_3_DOS_VERY_BASIC.yaml new file mode 100644 index 00000000..232dd8c7 --- /dev/null +++ b/tests/config/legacy_conversion/legacy_config_3_DOS_VERY_BASIC.yaml @@ -0,0 +1,166 @@ +# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +- itemType: ACTIONS + type: NODE +- itemType: STEPS + steps: 256 +- itemType: PORTS + portsList: + - port: '80' +- itemType: SERVICES + serviceList: + - name: TCP +- itemType: NODE + id: '1' + name: PC1 + baseType: SERVICE + nodeType: COMPUTER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.1.2 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '2' + name: PC2 + baseType: SERVICE + nodeType: COMPUTER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.1.3 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '3' + name: SWITCH1 + baseType: ACTIVE + nodeType: SWITCH + priority: P2 + hardwareState: 'ON' + ipAddress: 192.168.1.1 + softwareState: GOOD + fileSystemState: GOOD +- itemType: NODE + id: '4' + name: SERVER1 + baseType: SERVICE + nodeType: SERVER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.1.4 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: LINK + id: '5' + name: link1 + bandwidth: 1000000000 + source: '1' + destination: '3' +- itemType: LINK + id: '6' + name: link2 + bandwidth: 1000000000 + source: '2' + destination: '3' +- itemType: LINK + id: '7' + name: link3 + bandwidth: 1000000000 + source: '3' + destination: '4' +- itemType: GREEN_IER + id: '8' + startStep: 1 + endStep: 256 + load: 10000 + protocol: TCP + port: '80' + source: '1' + destination: '4' + missionCriticality: 1 +- itemType: GREEN_IER + id: '9' + startStep: 1 + endStep: 256 + load: 10000 + protocol: TCP + port: '80' + source: '2' + destination: '4' + missionCriticality: 1 +- itemType: GREEN_IER + id: '10' + startStep: 1 + endStep: 256 + load: 10000 + protocol: TCP + port: '80' + source: '4' + destination: '2' + missionCriticality: 5 +- itemType: ACL_RULE + id: '11' + permission: ALLOW + source: 192.168.1.2 + destination: 192.168.1.4 + protocol: TCP + port: 80 +- itemType: ACL_RULE + id: '12' + permission: ALLOW + source: 192.168.1.3 + destination: 192.168.1.4 + protocol: TCP + port: 80 +- itemType: ACL_RULE + id: '13' + permission: ALLOW + source: 192.168.1.4 + destination: 192.168.1.3 + protocol: TCP + port: 80 +- itemType: RED_POL + id: '14' + startStep: 20 + endStep: 20 + targetNodeId: '1' + initiator: DIRECT + type: SERVICE + protocol: TCP + state: COMPROMISED + sourceNodeId: NA + sourceNodeService: NA + sourceNodeServiceState: NA +- itemType: RED_IER + id: '15' + startStep: 30 + endStep: 256 + load: 10000000 + protocol: TCP + port: '80' + source: '1' + destination: '4' + missionCriticality: 0 +- itemType: RED_POL + id: '16' + startStep: 40 + endStep: 40 + targetNodeId: '4' + initiator: IER + type: SERVICE + protocol: TCP + state: OVERWHELMED + sourceNodeId: NA + sourceNodeService: NA + sourceNodeServiceState: NA diff --git a/tests/config/legacy_conversion/legacy_config_5_DATA_MANIPULATION.yaml b/tests/config/legacy_conversion/legacy_config_5_DATA_MANIPULATION.yaml new file mode 100644 index 00000000..6aa6a4ef --- /dev/null +++ b/tests/config/legacy_conversion/legacy_config_5_DATA_MANIPULATION.yaml @@ -0,0 +1,534 @@ +# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +- itemType: ACTIONS + type: NODE +- itemType: STEPS + steps: 256 +- itemType: PORTS + portsList: + - port: '80' + - port: '1433' + - port: '53' +- itemType: SERVICES + serviceList: + - name: TCP + - name: TCP_SQL + - name: UDP +- itemType: NODE + id: '1' + name: CLIENT_1 + baseType: SERVICE + nodeType: COMPUTER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.10.11 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD + - name: UDP + port: '53' + state: GOOD +- itemType: NODE + id: '2' + name: CLIENT_2 + baseType: SERVICE + nodeType: COMPUTER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.10.12 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: NODE + id: '3' + name: SWITCH_1 + baseType: ACTIVE + nodeType: SWITCH + priority: P2 + hardwareState: 'ON' + ipAddress: 192.168.10.1 + softwareState: GOOD + fileSystemState: GOOD +- itemType: NODE + id: '4' + name: SECURITY_SUITE + baseType: SERVICE + nodeType: SERVER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.1.10 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD + - name: UDP + port: '53' + state: GOOD +- itemType: NODE + id: '5' + name: MANAGEMENT_CONSOLE + baseType: SERVICE + nodeType: SERVER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.1.12 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD + - name: UDP + port: '53' + state: GOOD +- itemType: NODE + id: '6' + name: SWITCH_2 + baseType: ACTIVE + nodeType: SWITCH + priority: P2 + hardwareState: 'ON' + ipAddress: 192.168.2.1 + softwareState: GOOD + fileSystemState: GOOD +- itemType: NODE + id: '7' + name: WEB_SERVER + baseType: SERVICE + nodeType: SERVER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.2.10 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD + - name: TCP_SQL + port: '1433' + state: GOOD +- itemType: NODE + id: '8' + name: DATABASE_SERVER + baseType: SERVICE + nodeType: SERVER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.2.14 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD + - name: TCP_SQL + port: '1433' + state: GOOD + - name: UDP + port: '53' + state: GOOD +- itemType: NODE + id: '9' + name: BACKUP_SERVER + baseType: SERVICE + nodeType: SERVER + priority: P5 + hardwareState: 'ON' + ipAddress: 192.168.2.16 + softwareState: GOOD + fileSystemState: GOOD + services: + - name: TCP + port: '80' + state: GOOD +- itemType: LINK + id: '10' + name: LINK_1 + bandwidth: 1000000000 + source: '1' + destination: '3' +- itemType: LINK + id: '11' + name: LINK_2 + bandwidth: 1000000000 + source: '2' + destination: '3' +- itemType: LINK + id: '12' + name: LINK_3 + bandwidth: 1000000000 + source: '3' + destination: '4' +- itemType: LINK + id: '13' + name: LINK_4 + bandwidth: 1000000000 + source: '3' + destination: '5' +- itemType: LINK + id: '14' + name: LINK_5 + bandwidth: 1000000000 + source: '4' + destination: '6' +- itemType: LINK + id: '15' + name: LINK_6 + bandwidth: 1000000000 + source: '5' + destination: '6' +- itemType: LINK + id: '16' + name: LINK_7 + bandwidth: 1000000000 + source: '6' + destination: '7' +- itemType: LINK + id: '17' + name: LINK_8 + bandwidth: 1000000000 + source: '6' + destination: '8' +- itemType: LINK + id: '18' + name: LINK_9 + bandwidth: 1000000000 + source: '6' + destination: '9' +- itemType: GREEN_IER + id: '19' + startStep: 1 + endStep: 256 + load: 10000 + protocol: TCP + port: '80' + source: '1' + destination: '7' + missionCriticality: 5 +- itemType: GREEN_IER + id: '20' + startStep: 1 + endStep: 256 + load: 10000 + protocol: TCP + port: '80' + source: '7' + destination: '1' + missionCriticality: 5 +- itemType: GREEN_IER + id: '21' + startStep: 1 + endStep: 256 + load: 10000 + protocol: TCP + port: '80' + source: '2' + destination: '7' + missionCriticality: 5 +- itemType: GREEN_IER + id: '22' + startStep: 1 + endStep: 256 + load: 10000 + protocol: TCP + port: '80' + source: '7' + destination: '2' + missionCriticality: 5 +- itemType: GREEN_IER + id: '23' + startStep: 1 + endStep: 256 + load: 5000 + protocol: TCP_SQL + port: '1433' + source: '7' + destination: '8' + missionCriticality: 5 +- itemType: GREEN_IER + id: '24' + startStep: 1 + endStep: 256 + load: 100000 + protocol: TCP_SQL + port: '1433' + source: '8' + destination: '7' + missionCriticality: 5 +- itemType: GREEN_IER + id: '25' + startStep: 1 + endStep: 256 + load: 50000 + protocol: TCP + port: '80' + source: '1' + destination: '9' + missionCriticality: 2 +- itemType: GREEN_IER + id: '26' + startStep: 1 + endStep: 256 + load: 50000 + protocol: TCP + port: '80' + source: '2' + destination: '9' + missionCriticality: 2 +- itemType: GREEN_IER + id: '27' + startStep: 1 + endStep: 256 + load: 5000 + protocol: TCP + port: '80' + source: '5' + destination: '7' + missionCriticality: 1 +- itemType: GREEN_IER + id: '28' + startStep: 1 + endStep: 256 + load: 5000 + protocol: TCP + port: '80' + source: '7' + destination: '5' + missionCriticality: 1 +- itemType: GREEN_IER + id: '29' + startStep: 1 + endStep: 256 + load: 5000 + protocol: TCP + port: '80' + source: '5' + destination: '8' + missionCriticality: 1 +- itemType: GREEN_IER + id: '30' + startStep: 1 + endStep: 256 + load: 5000 + protocol: TCP + port: '80' + source: '8' + destination: '5' + missionCriticality: 1 +- itemType: GREEN_IER + id: '31' + startStep: 1 + endStep: 256 + load: 5000 + protocol: TCP + port: '80' + source: '5' + destination: '9' + missionCriticality: 1 +- itemType: GREEN_IER + id: '32' + startStep: 1 + endStep: 256 + load: 5000 + protocol: TCP + port: '80' + source: '9' + destination: '5' + missionCriticality: 1 +- itemType: ACL_RULE + id: '33' + permission: ALLOW + source: 192.168.10.11 + destination: 192.168.2.10 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '34' + permission: ALLOW + source: 192.168.10.11 + destination: 192.168.2.14 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '35' + permission: ALLOW + source: 192.168.10.12 + destination: 192.168.2.14 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '36' + permission: ALLOW + source: 192.168.10.12 + destination: 192.168.2.10 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '37' + permission: ALLOW + source: 192.168.2.10 + destination: 192.168.10.11 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '38' + permission: ALLOW + source: 192.168.2.10 + destination: 192.168.10.12 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '39' + permission: ALLOW + source: 192.168.2.10 + destination: 192.168.2.14 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '40' + permission: ALLOW + source: 192.168.2.14 + destination: 192.168.2.10 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '41' + permission: ALLOW + source: 192.168.10.11 + destination: 192.168.2.16 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '42' + permission: ALLOW + source: 192.168.10.12 + destination: 192.168.2.16 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '43' + permission: ALLOW + source: 192.168.1.12 + destination: 192.168.2.10 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '44' + permission: ALLOW + source: 192.168.1.12 + destination: 192.168.2.14 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '45' + permission: ALLOW + source: 192.168.1.12 + destination: 192.168.2.16 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '46' + permission: ALLOW + source: 192.168.2.10 + destination: 192.168.1.12 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '47' + permission: ALLOW + source: 192.168.2.14 + destination: 192.168.1.12 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '48' + permission: ALLOW + source: 192.168.2.16 + destination: 192.168.1.12 + protocol: ANY + port: ANY +- itemType: ACL_RULE + id: '49' + permission: DENY + source: ANY + destination: ANY + protocol: ANY + port: ANY +- itemType: RED_POL + id: '50' + startStep: 50 + endStep: 50 + targetNodeId: '1' + initiator: DIRECT + type: SERVICE + protocol: UDP + state: COMPROMISED + sourceNodeId: NA + sourceNodeService: NA + sourceNodeServiceState: NA +- itemType: RED_IER + id: '51' + startStep: 75 + endStep: 105 + load: 10000 + protocol: UDP + port: '53' + source: '1' + destination: '8' + missionCriticality: 0 +- itemType: RED_POL + id: '52' + startStep: 100 + endStep: 100 + targetNodeId: '8' + initiator: IER + type: SERVICE + protocol: UDP + state: COMPROMISED + sourceNodeId: NA + sourceNodeService: NA + sourceNodeServiceState: NA +- itemType: RED_POL + id: '53' + startStep: 105 + endStep: 105 + targetNodeId: '8' + initiator: SERVICE + type: FILE + protocol: NA + state: CORRUPT + sourceNodeId: '8' + sourceNodeService: UDP + sourceNodeServiceState: COMPROMISED +- itemType: RED_POL + id: '54' + startStep: 105 + endStep: 105 + targetNodeId: '8' + initiator: SERVICE + type: SERVICE + protocol: TCP_SQL + state: COMPROMISED + sourceNodeId: '8' + sourceNodeService: UDP + sourceNodeServiceState: COMPROMISED +- itemType: RED_POL + id: '55' + startStep: 125 + endStep: 125 + targetNodeId: '7' + initiator: SERVICE + type: SERVICE + protocol: TCP + state: OVERWHELMED + sourceNodeId: '8' + sourceNodeService: TCP_SQL + sourceNodeServiceState: COMPROMISED diff --git a/tests/config/legacy_conversion/new_training_config.yaml b/tests/config/legacy_conversion/new_training_config.yaml index 1ec36e97..1991eb06 100644 --- a/tests/config/legacy_conversion/new_training_config.yaml +++ b/tests/config/legacy_conversion/new_training_config.yaml @@ -21,12 +21,20 @@ agent_identifier: PPO # "ACL" # "ANY" node and acl actions action_type: ANY + # Number of episodes for training to run per session num_train_episodes: 10 # Number of time_steps for training per episode num_train_steps: 256 +# Number of episodes for evaluation to run per session +num_eval_episodes: 1 + +# Number of time_steps for evaluation per episode +num_eval_steps: 256 + + # Time delay between steps (for generic agents) time_delay: 10 # Type of session to be run (TRAINING or EVALUATION) diff --git a/tests/test_full_legacy_config_session.py b/tests/test_full_legacy_config_session.py new file mode 100644 index 00000000..1e003020 --- /dev/null +++ b/tests/test_full_legacy_config_session.py @@ -0,0 +1,49 @@ +# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +import tempfile +from pathlib import Path + +import pytest +import yaml + +from primaite.config import training_config +from primaite.config.lay_down_config import convert_legacy_lay_down_config +from primaite.main import run +from tests import TEST_CONFIG_ROOT + + +@pytest.mark.parametrize( + "legacy_file", + [ + ("legacy_config_1_DDOS_BASIC.yaml"), + ("legacy_config_2_DDOS_BASIC.yaml"), + ("legacy_config_3_DOS_VERY_BASIC.yaml"), + ("legacy_config_5_DATA_MANIPULATION.yaml"), + ], +) +def test_legacy_training_config_run_session(legacy_file): + """Tests using legacy training and lay down config files in PrimAITE session end-to-end.""" + # Load the legacy lay down config yaml file + with open(TEST_CONFIG_ROOT / "legacy_conversion" / legacy_file, "r") as file: + legacy_lay_down_config = yaml.safe_load(file) + + # Convert the legacy lay down config to the new format + converted_lay_down_config = convert_legacy_lay_down_config(legacy_lay_down_config) + + # Write the converted lay down config file to yaml file + temp_dir = Path(tempfile.gettempdir()) + converted_legacy_lay_down_path = temp_dir / legacy_file.replace("legacy_", "") + with open(converted_legacy_lay_down_path, "w") as file: + yaml.dump(converted_lay_down_config, file) + + # Load the legacy training config yaml file and covvert it to the new format + converted_legacy_training_config = training_config.load( + TEST_CONFIG_ROOT / "legacy_conversion" / "legacy_training_config.yaml", legacy_file=True + ) + + # Write the converted training config file to yaml file + converted_legacy_training_path = temp_dir / "training_config.yaml" + with open(converted_legacy_training_path, "w") as file: + yaml.dump(converted_legacy_training_config.to_dict(json_serializable=True), file) + + # Run a PrimAITE session using the paths of both the converted training and lay down config files + run(converted_legacy_training_path, converted_legacy_lay_down_path) diff --git a/tests/test_lay_down_config.py b/tests/test_lay_down_config.py new file mode 100644 index 00000000..99e66708 --- /dev/null +++ b/tests/test_lay_down_config.py @@ -0,0 +1,44 @@ +# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +import pytest +import yaml + +from primaite.config.lay_down_config import ( + convert_legacy_lay_down_config, + data_manipulation_config_path, + ddos_basic_one_config_path, + ddos_basic_two_config_path, + dos_very_basic_config_path, +) +from tests import TEST_CONFIG_ROOT + + +@pytest.mark.parametrize( + "legacy_file, new_path", + [ + ("legacy_config_1_DDOS_BASIC.yaml", ddos_basic_one_config_path()), + ("legacy_config_2_DDOS_BASIC.yaml", ddos_basic_two_config_path()), + ("legacy_config_3_DOS_VERY_BASIC.yaml", dos_very_basic_config_path()), + ("legacy_config_5_DATA_MANIPULATION.yaml", data_manipulation_config_path()), + ], +) +def test_legacy_lay_down_config_load(legacy_file, new_path): + """Tests converting legacy lay down files into the new format.""" + with open(TEST_CONFIG_ROOT / "legacy_conversion" / legacy_file, "r") as file: + legacy_lay_down_config = yaml.safe_load(file) + + with open(new_path, "r") as file: + new_lay_down_config = yaml.safe_load(file) + + converted_lay_down_config = convert_legacy_lay_down_config(legacy_lay_down_config) + + assert len(converted_lay_down_config) == len(new_lay_down_config) + + for i, new_item in enumerate(new_lay_down_config): + converted_item = converted_lay_down_config[i] + + for key, val in new_item.items(): + if key == "position": + continue + assert key in converted_item + + assert val == converted_item[key] From 0fb9268f44e8b76b2b303252858ee98b6907a1a1 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 28 Jul 2023 13:49:26 +0100 Subject: [PATCH 019/980] #1711 - Fully Integrated the legacy training config and lay down config options into the CLI, run PrimaiteSession, and Agent classes. Made the ese test in test_full_legacy_config_session.py use this new integrated option to read the legacy file. --- src/primaite/agents/agent_abc.py | 14 +++++++-- src/primaite/agents/sb3.py | 12 +++++++- src/primaite/cli.py | 23 ++++++++++++--- src/primaite/config/training_config.py | 4 ++- src/primaite/environment/primaite_env.py | 19 ++++++++----- src/primaite/main.py | 18 ++++++++---- src/primaite/primaite_session.py | 30 +++++++++++++++++--- tests/test_full_legacy_config_session.py | 36 ++++++------------------ 8 files changed, 104 insertions(+), 52 deletions(-) diff --git a/src/primaite/agents/agent_abc.py b/src/primaite/agents/agent_abc.py index 54c38abf..359790ad 100644 --- a/src/primaite/agents/agent_abc.py +++ b/src/primaite/agents/agent_abc.py @@ -52,6 +52,8 @@ class AgentSessionABC(ABC): training_config_path: Optional[Union[str, Path]] = None, lay_down_config_path: Optional[Union[str, Path]] = None, session_path: Optional[Union[str, Path]] = None, + legacy_training_config: bool = False, + legacy_lay_down_config: bool = False, ) -> None: """ Initialise an agent session from config files, or load a previous session. @@ -64,6 +66,10 @@ class AgentSessionABC(ABC): :type training_config_path: Union[path, str] :param lay_down_config_path: YAML file containing configurable items for generating network laydown. :type lay_down_config_path: Union[path, str] + :param legacy_training_config: True if the training config file is a legacy file from PrimAITE < 2.0, + otherwise False. + :param legacy_lay_down_config: True if the lay_down config file is a legacy file from PrimAITE < 2.0, + otherwise False. :param session_path: directory path of the session to load """ # initialise variables @@ -72,6 +78,8 @@ class AgentSessionABC(ABC): self._can_learn: bool = False self._can_evaluate: bool = False self.is_eval = False + self.legacy_training_config = legacy_training_config + self.legacy_lay_down_config = legacy_lay_down_config self.session_timestamp: datetime = datetime.now() @@ -91,12 +99,14 @@ class AgentSessionABC(ABC): if not isinstance(training_config_path, Path): training_config_path = Path(training_config_path) self._training_config_path: Union[Path, str] = training_config_path - self._training_config: TrainingConfig = training_config.load(self._training_config_path) + self._training_config: TrainingConfig = training_config.load( + self._training_config_path, legacy_file=legacy_training_config + ) if not isinstance(lay_down_config_path, Path): lay_down_config_path = Path(lay_down_config_path) self._lay_down_config_path: Union[Path, str] = lay_down_config_path - self._lay_down_config: Dict = lay_down_config.load(self._lay_down_config_path) + self._lay_down_config: Dict = lay_down_config.load(self._lay_down_config_path, legacy_lay_down_config) self.sb3_output_verbose_level = self._training_config.sb3_output_verbose_level # set random UUID for session diff --git a/src/primaite/agents/sb3.py b/src/primaite/agents/sb3.py index 783f57eb..92c5ee5f 100644 --- a/src/primaite/agents/sb3.py +++ b/src/primaite/agents/sb3.py @@ -26,6 +26,8 @@ class SB3Agent(AgentSessionABC): training_config_path: Optional[Union[str, Path]] = None, lay_down_config_path: Optional[Union[str, Path]] = None, session_path: Optional[Union[str, Path]] = None, + legacy_training_config: bool = False, + legacy_lay_down_config: bool = False, ) -> None: """ Initialise the SB3 Agent training session. @@ -35,11 +37,17 @@ class SB3Agent(AgentSessionABC): :type training_config_path: Union[path, str] :param lay_down_config_path: YAML file containing configurable items for generating network laydown. :type lay_down_config_path: Union[path, str] + :param legacy_training_config: True if the training config file is a legacy file from PrimAITE < 2.0, + otherwise False. + :param legacy_lay_down_config: True if the lay_down config file is a legacy file from PrimAITE < 2.0, + otherwise False. :raises ValueError: If the training config contains an unexpected value for agent_framework (should be "SB3") :raises ValueError: If the training config contains an unexpected value for agent_identifies (should be `PPO` or `A2C`) """ - super().__init__(training_config_path, lay_down_config_path, session_path) + super().__init__( + training_config_path, lay_down_config_path, session_path, legacy_training_config, legacy_lay_down_config + ) if not self._training_config.agent_framework == AgentFramework.SB3: msg = f"Expected SB3 agent_framework, " f"got {self._training_config.agent_framework}" _LOGGER.error(msg) @@ -75,6 +83,8 @@ class SB3Agent(AgentSessionABC): lay_down_config_path=self._lay_down_config_path, session_path=self.session_path, timestamp_str=self.timestamp_str, + legacy_training_config=self.legacy_training_config, + legacy_lay_down_config=self.legacy_lay_down_config, ) # check if there is a zip file that needs to be loaded diff --git a/src/primaite/cli.py b/src/primaite/cli.py index 4e37f75c..9bdc414d 100644 --- a/src/primaite/cli.py +++ b/src/primaite/cli.py @@ -18,9 +18,9 @@ app = typer.Typer() @app.command() def build_dirs() -> None: """Build the PrimAITE app directories.""" - from primaite.setup import setup_app_dirs + from primaite import PRIMAITE_PATHS - setup_app_dirs.run() + PRIMAITE_PATHS.mkdirs() @app.command() @@ -137,7 +137,13 @@ def setup(overwrite_existing: bool = True) -> None: @app.command() -def session(tc: Optional[str] = None, ldc: Optional[str] = None, load: Optional[str] = None) -> None: +def session( + tc: Optional[str] = None, + ldc: Optional[str] = None, + load: Optional[str] = None, + legacy_tc: bool = False, + legacy_ldc: bool = False, +) -> None: """ Run a PrimAITE session. @@ -153,6 +159,10 @@ def session(tc: Optional[str] = None, ldc: Optional[str] = None, load: Optional[ will use the default training config and laydown config. Inversely, if a training config and laydown config is passed while a session directory is passed, PrimAITE will load the session and ignore the training config and laydown config. + + legacy_tc: If the training config file is a legacy file from PrimAITE < 2.0. + + legacy_ldf: If the lay down config file is a legacy file from PrimAITE < 2.0. """ from primaite.config.lay_down_config import dos_very_basic_config_path from primaite.config.training_config import main_training_config_path @@ -170,7 +180,12 @@ def session(tc: Optional[str] = None, ldc: Optional[str] = None, load: Optional[ if not ldc: ldc = dos_very_basic_config_path() - run(training_config_path=tc, lay_down_config_path=ldc) + run( + training_config_path=tc, + lay_down_config_path=ldc, + legacy_training_config=legacy_tc, + legacy_lay_down_config=legacy_ldc, + ) @app.command() diff --git a/src/primaite/config/training_config.py b/src/primaite/config/training_config.py index b0f99603..7f5dc568 100644 --- a/src/primaite/config/training_config.py +++ b/src/primaite/config/training_config.py @@ -291,12 +291,14 @@ def load(file_path: Union[str, Path], legacy_file: bool = False) -> TrainingConf if legacy_file: try: config = convert_legacy_training_config_dict(config) - except KeyError: + + except KeyError as e: msg = ( f"Failed to convert training config file {file_path} " f"from legacy format. Attempting to use file as is." ) _LOGGER.error(msg) + raise e try: return TrainingConfig.from_dict(config) except TypeError as e: diff --git a/src/primaite/environment/primaite_env.py b/src/primaite/environment/primaite_env.py index 98702375..62af6c5b 100644 --- a/src/primaite/environment/primaite_env.py +++ b/src/primaite/environment/primaite_env.py @@ -10,7 +10,6 @@ from typing import Any, Dict, Final, List, Tuple, Union import networkx as nx import numpy as np -import yaml from gym import Env, spaces from matplotlib import pyplot as plt @@ -34,6 +33,7 @@ from primaite.common.enums import ( ) from primaite.common.service import Service from primaite.config import training_config +from primaite.config.lay_down_config import load from primaite.config.training_config import TrainingConfig from primaite.environment.observations import ObservationsHandler from primaite.environment.reward import calculate_reward_function @@ -68,6 +68,8 @@ class Primaite(Env): lay_down_config_path: Union[str, Path], session_path: Path, timestamp_str: str, + legacy_training_config: bool = False, + legacy_lay_down_config: bool = False, ) -> None: """ The Primaite constructor. @@ -76,13 +78,19 @@ class Primaite(Env): :param lay_down_config_path: The lay down config filepath. :param session_path: The directory path the session is writing to. :param timestamp_str: The session timestamp in the format: _. + :param legacy_training_config: True if the training config file is a legacy file from PrimAITE < 2.0, + otherwise False. + :param legacy_lay_down_config: True if the lay_down config file is a legacy file from PrimAITE < 2.0, + otherwise False. """ self.session_path: Final[Path] = session_path self.timestamp_str: Final[str] = timestamp_str self._training_config_path: Union[str, Path] = training_config_path self._lay_down_config_path: Union[str, Path] = lay_down_config_path + self.legacy_training_config = legacy_training_config + self.legacy_lay_down_config = legacy_lay_down_config - self.training_config: TrainingConfig = training_config.load(training_config_path) + self.training_config: TrainingConfig = training_config.load(training_config_path, self.legacy_training_config) _LOGGER.info(f"Using: {str(self.training_config)}") # Number of steps in an episode @@ -191,11 +199,8 @@ class Primaite(Env): self._obs_space_description: List[str] = None "The env observation space description for transactions writing" - # Open the config file and build the environment laydown - with open(self._lay_down_config_path, "r") as file: - # Open the config file and build the environment laydown - self.lay_down_config = yaml.safe_load(file) - self.load_lay_down_config() + self.lay_down_config = load(self._lay_down_config_path, self.legacy_lay_down_config) + self.load_lay_down_config() # Store the node objects as node attributes # (This is so we can access them as objects) diff --git a/src/primaite/main.py b/src/primaite/main.py index 03f4fb35..45cd0d8d 100644 --- a/src/primaite/main.py +++ b/src/primaite/main.py @@ -14,18 +14,26 @@ def run( training_config_path: Optional[Union[str, Path]] = "", lay_down_config_path: Optional[Union[str, Path]] = "", session_path: Optional[Union[str, Path]] = None, + legacy_training_config: bool = False, + legacy_lay_down_config: bool = False, ) -> None: """ Run the PrimAITE Session. :param training_config_path: YAML file containing configurable items defined in `primaite.config.training_config.TrainingConfig` - :type training_config_path: Union[path, str] - :param lay_down_config_path: YAML file containing configurable items for generating network laydown. - :type lay_down_config_path: Union[path, str] - :param session_path: directory path of the session to load + :type training_config_path: Union[path, str] + :param lay_down_config_path: YAML file containing configurable items for generating network laydown. + :type lay_down_config_path: Union[path, str] + :param session_path: directory path of the session to load + :param legacy_training_config: True if the training config file is a legacy file from PrimAITE < 2.0, + otherwise False. + :param legacy_lay_down_config: True if the lay_down config file is a legacy file from PrimAITE < 2.0, + otherwise False. """ - session = PrimaiteSession(training_config_path, lay_down_config_path, session_path) + session = PrimaiteSession( + training_config_path, lay_down_config_path, session_path, legacy_training_config, legacy_lay_down_config + ) session.setup() session.learn() diff --git a/src/primaite/primaite_session.py b/src/primaite/primaite_session.py index c64b51fb..f7495c48 100644 --- a/src/primaite/primaite_session.py +++ b/src/primaite/primaite_session.py @@ -34,6 +34,8 @@ class PrimaiteSession: training_config_path: Optional[Union[str, Path]] = "", lay_down_config_path: Optional[Union[str, Path]] = "", session_path: Optional[Union[str, Path]] = None, + legacy_training_config: bool = False, + legacy_lay_down_config: bool = False, ) -> None: """ The PrimaiteSession constructor. @@ -44,12 +46,18 @@ class PrimaiteSession: :param lay_down_config_path: YAML file containing configurable items for generating network laydown. :type lay_down_config_path: Union[path, str] :param session_path: directory path of the session to load + :param legacy_training_config: True if the training config file is a legacy file from PrimAITE < 2.0, + otherwise False. + :param legacy_lay_down_config: True if the lay_down config file is a legacy file from PrimAITE < 2.0, + otherwise False. """ self._agent_session: AgentSessionABC = None # noqa self.session_path: Path = session_path # noqa self.timestamp_str: str = None # noqa self.learning_path: Path = None # noqa self.evaluation_path: Path = None # noqa + self.legacy_training_config = legacy_training_config + self.legacy_lay_down_config = legacy_lay_down_config # check if session path is provided if session_path is not None: @@ -67,12 +75,14 @@ class PrimaiteSession: if not isinstance(training_config_path, Path): training_config_path = Path(training_config_path) self._training_config_path: Final[Union[Path, str]] = training_config_path - self._training_config: Final[TrainingConfig] = training_config.load(self._training_config_path) + self._training_config: Final[TrainingConfig] = training_config.load( + self._training_config_path, legacy_training_config + ) if not isinstance(lay_down_config_path, Path): lay_down_config_path = Path(lay_down_config_path) self._lay_down_config_path: Final[Union[Path, str]] = lay_down_config_path - self._lay_down_config: Dict = lay_down_config.load(self._lay_down_config_path) # noqa + self._lay_down_config: Dict = lay_down_config.load(self._lay_down_config_path, legacy_lay_down_config) # noqa def setup(self) -> None: """Performs the session setup.""" @@ -139,12 +149,24 @@ class PrimaiteSession: elif self._training_config.agent_framework == AgentFramework.SB3: _LOGGER.debug(f"PrimaiteSession Setup: Agent Framework = {AgentFramework.SB3}") # Stable Baselines3 Agent - self._agent_session = SB3Agent(self._training_config_path, self._lay_down_config_path, self.session_path) + self._agent_session = SB3Agent( + self._training_config_path, + self._lay_down_config_path, + self.session_path, + self.legacy_training_config, + self.legacy_lay_down_config, + ) elif self._training_config.agent_framework == AgentFramework.RLLIB: _LOGGER.debug(f"PrimaiteSession Setup: Agent Framework = {AgentFramework.RLLIB}") # Ray RLlib Agent - self._agent_session = RLlibAgent(self._training_config_path, self._lay_down_config_path, self.session_path) + self._agent_session = RLlibAgent( + self._training_config_path, + self._lay_down_config_path, + self.session_path, + self.legacy_training_config, + self.legacy_lay_down_config, + ) else: # Invalid AgentFramework diff --git a/tests/test_full_legacy_config_session.py b/tests/test_full_legacy_config_session.py index 1e003020..33f827f1 100644 --- a/tests/test_full_legacy_config_session.py +++ b/tests/test_full_legacy_config_session.py @@ -1,12 +1,7 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import tempfile -from pathlib import Path import pytest -import yaml -from primaite.config import training_config -from primaite.config.lay_down_config import convert_legacy_lay_down_config from primaite.main import run from tests import TEST_CONFIG_ROOT @@ -22,28 +17,13 @@ from tests import TEST_CONFIG_ROOT ) def test_legacy_training_config_run_session(legacy_file): """Tests using legacy training and lay down config files in PrimAITE session end-to-end.""" - # Load the legacy lay down config yaml file - with open(TEST_CONFIG_ROOT / "legacy_conversion" / legacy_file, "r") as file: - legacy_lay_down_config = yaml.safe_load(file) - - # Convert the legacy lay down config to the new format - converted_lay_down_config = convert_legacy_lay_down_config(legacy_lay_down_config) - - # Write the converted lay down config file to yaml file - temp_dir = Path(tempfile.gettempdir()) - converted_legacy_lay_down_path = temp_dir / legacy_file.replace("legacy_", "") - with open(converted_legacy_lay_down_path, "w") as file: - yaml.dump(converted_lay_down_config, file) - - # Load the legacy training config yaml file and covvert it to the new format - converted_legacy_training_config = training_config.load( - TEST_CONFIG_ROOT / "legacy_conversion" / "legacy_training_config.yaml", legacy_file=True - ) - - # Write the converted training config file to yaml file - converted_legacy_training_path = temp_dir / "training_config.yaml" - with open(converted_legacy_training_path, "w") as file: - yaml.dump(converted_legacy_training_config.to_dict(json_serializable=True), file) + legacy_training_config_path = TEST_CONFIG_ROOT / "legacy_conversion" / "legacy_training_config.yaml" + legacy_lay_down_config_path = TEST_CONFIG_ROOT / "legacy_conversion" / legacy_file # Run a PrimAITE session using the paths of both the converted training and lay down config files - run(converted_legacy_training_path, converted_legacy_lay_down_path) + run( + legacy_training_config_path, + legacy_lay_down_config_path, + legacy_training_config=True, + legacy_lay_down_config=True, + ) From bb8b41a5ec1bbf65dbc26f15d396c0039f17003e Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 28 Jul 2023 14:02:17 +0100 Subject: [PATCH 020/980] #1711 - Removed the legacy bools from the RLlibAgent constructor in primaite_session.py --- src/primaite/primaite_session.py | 8 +------- tests/test_full_legacy_config_session.py | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/primaite/primaite_session.py b/src/primaite/primaite_session.py index f7495c48..2cb0d5bd 100644 --- a/src/primaite/primaite_session.py +++ b/src/primaite/primaite_session.py @@ -160,13 +160,7 @@ class PrimaiteSession: elif self._training_config.agent_framework == AgentFramework.RLLIB: _LOGGER.debug(f"PrimaiteSession Setup: Agent Framework = {AgentFramework.RLLIB}") # Ray RLlib Agent - self._agent_session = RLlibAgent( - self._training_config_path, - self._lay_down_config_path, - self.session_path, - self.legacy_training_config, - self.legacy_lay_down_config, - ) + self._agent_session = RLlibAgent(self._training_config_path, self._lay_down_config_path, self.session_path) else: # Invalid AgentFramework diff --git a/tests/test_full_legacy_config_session.py b/tests/test_full_legacy_config_session.py index 33f827f1..066ff72c 100644 --- a/tests/test_full_legacy_config_session.py +++ b/tests/test_full_legacy_config_session.py @@ -20,7 +20,7 @@ def test_legacy_training_config_run_session(legacy_file): legacy_training_config_path = TEST_CONFIG_ROOT / "legacy_conversion" / "legacy_training_config.yaml" legacy_lay_down_config_path = TEST_CONFIG_ROOT / "legacy_conversion" / legacy_file - # Run a PrimAITE session using the paths of both the converted training and lay down config files + # Run a PrimAITE session using legacy training and lay down config file paths run( legacy_training_config_path, legacy_lay_down_config_path, From 77e7941510cdac9780ab3b4ae6e04c9a6c4cb694 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 28 Jul 2023 14:39:01 +0100 Subject: [PATCH 021/980] #1711 - Last minute docs changes --- docs/index.rst | 9 ++++----- docs/source/primaite_session.rst | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 3b1a13ec..2c7d4690 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -6,7 +6,7 @@ Welcome to PrimAITE's documentation ==================================== What is PrimAITE? ------------------------- +----------------- PrimAITE (Primary-level AI Training Environment) is a simulation environment for training AI under the ARCD programme. It incorporates the functionality required of a Primary-level environment, as specified in the Dstl ARCD Training Environment Matrix document: @@ -14,10 +14,9 @@ PrimAITE (Primary-level AI Training Environment) is a simulation environment for * The ability to model key characteristics of a platform / system by representing connections, IP addresses, ports, traffic loading, operating systems, file system, services and processes; * Operates at machine-speed to enable fast training cycles. -PrimAITE aims to evolve into an ARCD environment that could be used as the follow-on from Reception level approaches (e.g. `Yawning-Titan `_), and help bridge the Sim-to-Real gap into Secondary level environments. What is PrimAITE built with --------------------------------------- +--------------------------- * `OpenAI's Gym `_ is used as the basis for AI blue agent interaction with the PrimAITE environment * `Networkx `_ is used as the underlying data structure used for the PrimAITE environment @@ -29,8 +28,8 @@ What is PrimAITE built with * `Plotly `_ is used for building high level charts -Where next? ------------- +Getting Started with PrimAITE +----------------------------- Head over to the :ref:`getting-started` page to install and setup PrimAITE! diff --git a/docs/source/primaite_session.rst b/docs/source/primaite_session.rst index ed023499..15ba9f4c 100644 --- a/docs/source/primaite_session.rst +++ b/docs/source/primaite_session.rst @@ -49,6 +49,34 @@ For example, when running a session at 17:30:00 on 31st January 2023, the sessio ``primaite session`` can be ran in the terminal/command prompt without arguments. It will use the default configs in the directory ``primaite/config/example_config``. +To run a PrimAITE session using legacy training or laydown config files, add the ``--legacy-tc`` and/or ``legacy-ldc`` options. + +.. tabs:: + + .. code-tab:: bash + :caption: Unix CLI + + cd ~/primaite/2.0.0 + source ./.venv/bin/activate + primaite session --tc ./config/my_legacy_training_config.yaml --legacy-tc --ldc ./config/my_legacy_lay_down_config.yaml --legacy-ldc + + .. code-tab:: powershell + :caption: Powershell CLI + + cd ~\primaite\2.0.0 + .\.venv\Scripts\activate + primaite session --tc .\config\my_legacy_training_config.yaml --legacy-tc --ldc .\config\my_legacy_lay_down_config.yaml --legacy-ldc + + + .. code-tab:: python + :caption: Python + + from primaite.main import run + + training_config = + lay_down_config = + run(training_config, lay_down_config, legacy_training_config=True, legacy_lay_down_config=True) + Outputs ------- From 0f8d31c72c02b16a594184e2d9b792162c21f04a Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 28 Jul 2023 14:41:39 +0100 Subject: [PATCH 022/980] #1711 - Last minute docs changes --- docs/index.rst | 9 ++++----- docs/source/primaite_session.rst | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 3b1a13ec..2c7d4690 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -6,7 +6,7 @@ Welcome to PrimAITE's documentation ==================================== What is PrimAITE? ------------------------- +----------------- PrimAITE (Primary-level AI Training Environment) is a simulation environment for training AI under the ARCD programme. It incorporates the functionality required of a Primary-level environment, as specified in the Dstl ARCD Training Environment Matrix document: @@ -14,10 +14,9 @@ PrimAITE (Primary-level AI Training Environment) is a simulation environment for * The ability to model key characteristics of a platform / system by representing connections, IP addresses, ports, traffic loading, operating systems, file system, services and processes; * Operates at machine-speed to enable fast training cycles. -PrimAITE aims to evolve into an ARCD environment that could be used as the follow-on from Reception level approaches (e.g. `Yawning-Titan `_), and help bridge the Sim-to-Real gap into Secondary level environments. What is PrimAITE built with --------------------------------------- +--------------------------- * `OpenAI's Gym `_ is used as the basis for AI blue agent interaction with the PrimAITE environment * `Networkx `_ is used as the underlying data structure used for the PrimAITE environment @@ -29,8 +28,8 @@ What is PrimAITE built with * `Plotly `_ is used for building high level charts -Where next? ------------- +Getting Started with PrimAITE +----------------------------- Head over to the :ref:`getting-started` page to install and setup PrimAITE! diff --git a/docs/source/primaite_session.rst b/docs/source/primaite_session.rst index ed023499..15ba9f4c 100644 --- a/docs/source/primaite_session.rst +++ b/docs/source/primaite_session.rst @@ -49,6 +49,34 @@ For example, when running a session at 17:30:00 on 31st January 2023, the sessio ``primaite session`` can be ran in the terminal/command prompt without arguments. It will use the default configs in the directory ``primaite/config/example_config``. +To run a PrimAITE session using legacy training or laydown config files, add the ``--legacy-tc`` and/or ``legacy-ldc`` options. + +.. tabs:: + + .. code-tab:: bash + :caption: Unix CLI + + cd ~/primaite/2.0.0 + source ./.venv/bin/activate + primaite session --tc ./config/my_legacy_training_config.yaml --legacy-tc --ldc ./config/my_legacy_lay_down_config.yaml --legacy-ldc + + .. code-tab:: powershell + :caption: Powershell CLI + + cd ~\primaite\2.0.0 + .\.venv\Scripts\activate + primaite session --tc .\config\my_legacy_training_config.yaml --legacy-tc --ldc .\config\my_legacy_lay_down_config.yaml --legacy-ldc + + + .. code-tab:: python + :caption: Python + + from primaite.main import run + + training_config = + lay_down_config = + run(training_config, lay_down_config, legacy_training_config=True, legacy_lay_down_config=True) + Outputs ------- From b129c4fc9747d20474bfdbf02fb8cfbf0b475b8e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 28 Jul 2023 14:49:21 +0100 Subject: [PATCH 023/980] Add SimComponent core class --- docs/index.rst | 1 + docs/source/custom_agent.rst | 4 +- docs/source/simulation.rst | 10 +++ pyproject.toml | 3 +- src/primaite/simulator/__init__.py | 0 src/primaite/simulator/core.py | 38 ++++++++ tests/unit_tests/__init__.py | 0 tests/unit_tests/primaite/__init__.py | 0 .../unit_tests/primaite/simulator/__init__.py | 0 .../primaite/simulator/test_core.py | 87 +++++++++++++++++++ 10 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 docs/source/simulation.rst create mode 100644 src/primaite/simulator/__init__.py create mode 100644 src/primaite/simulator/core.py create mode 100644 tests/unit_tests/__init__.py create mode 100644 tests/unit_tests/primaite/__init__.py create mode 100644 tests/unit_tests/primaite/simulator/__init__.py create mode 100644 tests/unit_tests/primaite/simulator/test_core.py diff --git a/docs/index.rst b/docs/index.rst index 3b1a13ec..9745232d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -44,6 +44,7 @@ Head over to the :ref:`getting-started` page to install and setup PrimAITE! source/config source/primaite_session source/custom_agent + source/simulation PrimAITE API PrimAITE Tests source/dependencies diff --git a/docs/source/custom_agent.rst b/docs/source/custom_agent.rst index 8a95d3ae..040b4b3d 100644 --- a/docs/source/custom_agent.rst +++ b/docs/source/custom_agent.rst @@ -13,7 +13,7 @@ Integrating a user defined blue agent If you are planning to implement custom RL agents into PrimAITE, you must use the project as a repository. If you install PrimAITE as a python package from wheel, custom agents are not supported. -PrimAITE has integration with Ray RLLib and StableBaselines3 agents. All agents interface with PrimAITE through an :py:class:`primaite.agents.agent.AgentSessionABC` which provides Input/Output of agent savefiles, as well as capturing and plotting performance metrics during training and evaluation. If you wish to integrate a custom blue agent, it is recommended to create a subclass of the :py:class:`primaite.agents.agent.AgentSessionABC` and implement the ``__init__()``, ``_setup()``, ``_save_checkpoint()``, ``learn()``, ``evaluate()``, ``_get_latest_checkpoint``, ``load()``, and ``save()`` methods. +PrimAITE has integration with Ray RLLib and StableBaselines3 agents. All agents interface with PrimAITE through an :py:class:`primaite.agents.agent_abc.AgentSessionABC` which provides Input/Output of agent savefiles, as well as capturing and plotting performance metrics during training and evaluation. If you wish to integrate a custom blue agent, it is recommended to create a subclass of the :py:class:`primaite.agents.agent_abc.AgentSessionABC` and implement the ``__init__()``, ``_setup()``, ``_save_checkpoint()``, ``learn()``, ``evaluate()``, ``_get_latest_checkpoint``, ``load()``, and ``save()`` methods. Below is a barebones example of a custom agent implementation: @@ -21,7 +21,7 @@ Below is a barebones example of a custom agent implementation: # src/primaite/agents/my_custom_agent.py - from primaite.agents.agent import AgentSessionABC + from primaite.agents.agent_abc import AgentSessionABC from primaite.common.enums import AgentFramework, AgentIdentifier class CustomAgent(AgentSessionABC): diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst new file mode 100644 index 00000000..1620f6ba --- /dev/null +++ b/docs/source/simulation.rst @@ -0,0 +1,10 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +Simulation Strucutre +==================== + +The simulation is made up of many smaller components which are related to each other in a tree-like structure. At the top level, there is an object called the ``SimulationController`` _(doesn't exist yet)_, which has a physical network and a software controller for managing software and users. + +Each node of the simulation 'tree' has responsibility for creating, deleting, and updating its direct descendants. diff --git a/pyproject.toml b/pyproject.toml index b66b0168..0bae6e86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,8 @@ dependencies = [ "ray[rllib]==2.2.0", "stable-baselines3==1.6.2", "tensorflow==2.12.0", - "typer[all]==0.9.0" + "typer[all]==0.9.0", + "pydantic" ] [tool.setuptools.dynamic] diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py new file mode 100644 index 00000000..d540daf3 --- /dev/null +++ b/src/primaite/simulator/core.py @@ -0,0 +1,38 @@ +"""Core of the PrimAITE Simulator.""" +from abc import abstractmethod +from typing import Dict, List + +from pydantic import BaseModel + + +class SimComponent(BaseModel): + """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" + + @abstractmethod + def describe_state(self) -> Dict: + """ + Return a dictionary describing the state of this object and any objects managed by it. + + This is similar to pydantic ``model_dump()``, but it only outputs information about the objects owned by this + object. If there are objects referenced by this object that are owned by something else, it is not included in + this output. + """ + return {} + + @abstractmethod + def apply_action(self, action: List[str]) -> None: + """ + Apply an action to a simulation component. Action data is passed in as a 'namespaced' list of strings. + + If the list only has one element, the action is intended to be applied directly to this object. If the list has + multiple entries, the action is passed to the child of this object specified by the first one or two entries. + This is essentially a namespace. + + For example, ["turn_on",] is meant to apply an action of 'turn on' to this component. + + However, ["services", "email_client", "turn_on"] is meant to 'turn on' this component's email client service. + + :param action: List describing the action to apply to this object. + :type action: List[str] + """ + return diff --git a/tests/unit_tests/__init__.py b/tests/unit_tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/primaite/__init__.py b/tests/unit_tests/primaite/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/primaite/simulator/__init__.py b/tests/unit_tests/primaite/simulator/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/primaite/simulator/test_core.py b/tests/unit_tests/primaite/simulator/test_core.py new file mode 100644 index 00000000..ea593a0b --- /dev/null +++ b/tests/unit_tests/primaite/simulator/test_core.py @@ -0,0 +1,87 @@ +from typing import Dict, List, Literal, Tuple + +import pytest +from pydantic import ValidationError + +from primaite.simulator.core import SimComponent + + +class TestIsolatedSimComponent: + """Test the SimComponent class in isolation.""" + + def test_data_validation(self): + """ + Test that our derived class does not interfere with pydantic data validation. + + This test may seem like it's simply validating pydantic data validation, but + actually it is here to give us assurance that any custom functionality we add + to the SimComponent does not interfere with pydantic. + """ + + class TestComponent(SimComponent): + name: str + size: Tuple[float, float] + + def describe_state(self) -> Dict: + return {} + + def apply_action(self, action: List[str]) -> None: + pass + + comp = TestComponent(name="computer", size=(5, 10)) + assert isinstance(comp, TestComponent) + + with pytest.raises(ValidationError): + invalid_comp = TestComponent(name="computer", size="small") # noqa + + def test_serialisation(self): + """Validate that our added functionality does not interfere with pydantic.""" + + class TestComponent(SimComponent): + name: str + size: Tuple[float, float] + + def describe_state(self) -> Dict: + return {} + + def apply_action(self, action: List[str]) -> None: + pass + + comp = TestComponent(name="computer", size=(5, 10)) + dump = comp.model_dump() + assert dump == {"name": "computer", "size": (5, 10)} + + def test_apply_action(self): + """Validate that we can override apply_action behaviour and it updates the state of the component.""" + + class TestComponent(SimComponent): + name: str + status: Literal["on", "off"] = "off" + + def describe_state(self) -> Dict: + return {} + + def apply_action(self, action: List[str]) -> None: + possible_actions = { + "turn_off": self._turn_off, + "turn_on": self._turn_on, + } + if action[0] in possible_actions: + possible_actions[action[0]](action[1:]) + else: + raise ValueError(f"{self} received invalid action {action}") + + def _turn_off(self): + self.status = "off" + + def _turn_on(self): + self.status = "on" + + comp = TestComponent(name="computer", status="off") + + assert comp.status == "off" + comp.apply_action(["turn_on"]) + assert comp.status == "on" + + with pytest.raises(ValueError): + comp.apply_action(["do_nothing"]) From 3b4a01760bc95a339a4d4653023041dc8f2d08f7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 28 Jul 2023 15:14:43 +0100 Subject: [PATCH 024/980] Rework apply_actions to make it more standard --- src/primaite/simulator/core.py | 14 +++++++++--- .../primaite/simulator/test_core.py | 22 ++++++------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index d540daf3..67149414 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -1,6 +1,6 @@ """Core of the PrimAITE Simulator.""" from abc import abstractmethod -from typing import Dict, List +from typing import Callable, Dict, List from pydantic import BaseModel @@ -19,7 +19,6 @@ class SimComponent(BaseModel): """ return {} - @abstractmethod def apply_action(self, action: List[str]) -> None: """ Apply an action to a simulation component. Action data is passed in as a 'namespaced' list of strings. @@ -35,4 +34,13 @@ class SimComponent(BaseModel): :param action: List describing the action to apply to this object. :type action: List[str] """ - return + possible_actions = self._possible_actions() + if action[0] in possible_actions: + # take the first element off the action list and pass the remaining arguments to the corresponding action + # funciton + possible_actions[action.pop(0)](action) + else: + raise ValueError(f"{self} received invalid action {action}") + + def _possible_actions(self) -> Dict[str, Callable[[List[str]], None]]: + return {} diff --git a/tests/unit_tests/primaite/simulator/test_core.py b/tests/unit_tests/primaite/simulator/test_core.py index ea593a0b..de0732f9 100644 --- a/tests/unit_tests/primaite/simulator/test_core.py +++ b/tests/unit_tests/primaite/simulator/test_core.py @@ -1,4 +1,4 @@ -from typing import Dict, List, Literal, Tuple +from typing import Callable, Dict, List, Literal, Tuple import pytest from pydantic import ValidationError @@ -25,9 +25,6 @@ class TestIsolatedSimComponent: def describe_state(self) -> Dict: return {} - def apply_action(self, action: List[str]) -> None: - pass - comp = TestComponent(name="computer", size=(5, 10)) assert isinstance(comp, TestComponent) @@ -44,9 +41,6 @@ class TestIsolatedSimComponent: def describe_state(self) -> Dict: return {} - def apply_action(self, action: List[str]) -> None: - pass - comp = TestComponent(name="computer", size=(5, 10)) dump = comp.model_dump() assert dump == {"name": "computer", "size": (5, 10)} @@ -61,20 +55,18 @@ class TestIsolatedSimComponent: def describe_state(self) -> Dict: return {} - def apply_action(self, action: List[str]) -> None: - possible_actions = { + def _possible_actions(self) -> Dict[str, Callable[[List[str]], None]]: + return { "turn_off": self._turn_off, "turn_on": self._turn_on, } - if action[0] in possible_actions: - possible_actions[action[0]](action[1:]) - else: - raise ValueError(f"{self} received invalid action {action}") - def _turn_off(self): + def _turn_off(self, options: List[str]) -> None: + assert len(options) == 0, "This action does not support options." self.status = "off" - def _turn_on(self): + def _turn_on(self, options: List[str]) -> None: + assert len(options) == 0, "This action does not support options." self.status = "on" comp = TestComponent(name="computer", status="off") From 61fe8c20313727504324fd3b455242248e441cda Mon Sep 17 00:00:00 2001 From: jamesshort1 <107395948+jamesshort1@users.noreply.github.com> Date: Mon, 31 Jul 2023 09:16:24 +0100 Subject: [PATCH 025/980] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a4ff749..723a7a27 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The ARCD Primary-level AI Training Environment (**PrimAITE**) provides an effect - The ability to model a relevant platform / system context; -- The ability to model key characteristics of a platform / system by representing connections, IP addresses, ports, traffic loading, operating systems, services and processes; +- The ability to model key characteristics of a platform / system by representing connections, IP addresses, ports, traffic loading, operating systems and services; - Operates at machine-speed to enable fast training cycles. From 80ddf511dc6e79d47a3106f5789053a0f2a30bb8 Mon Sep 17 00:00:00 2001 From: jamesshort1 <107395948+jamesshort1@users.noreply.github.com> Date: Mon, 31 Jul 2023 09:17:48 +0100 Subject: [PATCH 026/980] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 723a7a27..3913a3d1 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ PrimAITE presents the following features: - Application of IERs to the platform / system laydown adheres to the ACL ruleset; -- Presents an OpenAI gym or RLLib interface to the environment, allowing integration with any OpenAI gym compliant defensive agents; +- Presents an OpenAI gym or RLLib interface to the environment, allowing integration with any compliant defensive agents; - Full capture of discrete logs relating to agent training (full system state, agent actions taken, instantaneous and average reward for every step of every episode); From 8e2ef1b695dcb2b1de3a2079920c7efd8d081c99 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 31 Jul 2023 10:25:29 +0000 Subject: [PATCH 027/980] Apply suggestions from code review --- src/primaite/simulator/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 67149414..76884b0a 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -40,7 +40,7 @@ class SimComponent(BaseModel): # funciton possible_actions[action.pop(0)](action) else: - raise ValueError(f"{self} received invalid action {action}") + raise ValueError(f"{self.__class__.__name__} received invalid action {action}") def _possible_actions(self) -> Dict[str, Callable[[List[str]], None]]: return {} From fa2cdf853c22bdf6fceb62d15acc9e6549aefad9 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 31 Jul 2023 11:27:16 +0100 Subject: [PATCH 028/980] Drop Ray --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0bae6e86..4e8250d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,6 @@ dependencies = [ "plotly==5.15.0", "polars==0.18.4", "PyYAML==6.0", - "ray[rllib]==2.2.0", "stable-baselines3==1.6.2", "tensorflow==2.12.0", "typer[all]==0.9.0", From a486780fba2873ae559450b2d29c1a5c65c98f97 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 31 Jul 2023 11:39:33 +0100 Subject: [PATCH 029/980] Add timestep function --- src/primaite/simulator/core.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 76884b0a..5b9bea1f 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -44,3 +44,12 @@ class SimComponent(BaseModel): def _possible_actions(self) -> Dict[str, Callable[[List[str]], None]]: return {} + + def apply_timestep(self) -> None: + """ + Apply a timestep evolution to this component. + + Override this method with anything that happens automatically in the component such as scheduled restarts or + sending data. + """ + pass From 954026d3e0dd1e10a3e3c8b66be1407063130d68 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 31 Jul 2023 12:13:52 +0100 Subject: [PATCH 030/980] Comment out RLLib support --- src/primaite/agents/rllib.py | 483 ++++++++++++----------- src/primaite/common/enums.py | 4 +- src/primaite/config/training_config.py | 4 +- src/primaite/environment/primaite_env.py | 10 +- src/primaite/primaite_session.py | 13 +- tests/test_primaite_session.py | 2 +- 6 files changed, 260 insertions(+), 256 deletions(-) diff --git a/src/primaite/agents/rllib.py b/src/primaite/agents/rllib.py index ab1b3af3..96bb0737 100644 --- a/src/primaite/agents/rllib.py +++ b/src/primaite/agents/rllib.py @@ -1,286 +1,287 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -from __future__ import annotations +# # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +# from __future__ import annotations -import json -import shutil -import zipfile -from datetime import datetime -from logging import Logger -from pathlib import Path -from typing import Any, Callable, Dict, Optional, Union -from uuid import uuid4 +# import json +# import shutil +# import zipfile +# from datetime import datetime +# from logging import Logger +# from pathlib import Path +# from typing import Any, Callable, Dict, Optional, Union +# from uuid import uuid4 -from ray.rllib.algorithms import Algorithm -from ray.rllib.algorithms.a2c import A2CConfig -from ray.rllib.algorithms.ppo import PPOConfig -from ray.tune.logger import UnifiedLogger -from ray.tune.registry import register_env +# from primaite import getLogger +# from primaite.agents.agent_abc import AgentSessionABC +# from primaite.common.enums import AgentFramework, AgentIdentifier, SessionType +# from primaite.environment.primaite_env import Primaite -from primaite import getLogger -from primaite.agents.agent_abc import AgentSessionABC -from primaite.common.enums import AgentFramework, AgentIdentifier, SessionType -from primaite.environment.primaite_env import Primaite -from primaite.exceptions import RLlibAgentError - -_LOGGER: Logger = getLogger(__name__) +# # from ray.rllib.algorithms import Algorithm +# # from ray.rllib.algorithms.a2c import A2CConfig +# # from ray.rllib.algorithms.ppo import PPOConfig +# # from ray.tune.logger import UnifiedLogger +# # from ray.tune.registry import register_env -# TODO: verify type of env_config -def _env_creator(env_config: Dict[str, Any]) -> Primaite: - return Primaite( - training_config_path=env_config["training_config_path"], - lay_down_config_path=env_config["lay_down_config_path"], - session_path=env_config["session_path"], - timestamp_str=env_config["timestamp_str"], - ) +# # from primaite.exceptions import RLlibAgentError + +# _LOGGER: Logger = getLogger(__name__) -# TODO: verify type hint return type -def _custom_log_creator(session_path: Path) -> Callable[[Dict], UnifiedLogger]: - logdir = session_path / "ray_results" - logdir.mkdir(parents=True, exist_ok=True) +# # TODO: verify type of env_config +# def _env_creator(env_config: Dict[str, Any]) -> Primaite: +# return Primaite( +# training_config_path=env_config["training_config_path"], +# lay_down_config_path=env_config["lay_down_config_path"], +# session_path=env_config["session_path"], +# timestamp_str=env_config["timestamp_str"], +# ) - def logger_creator(config: Dict) -> UnifiedLogger: - return UnifiedLogger(config, logdir, loggers=None) +# # # TODO: verify type hint return type +# # def _custom_log_creator(session_path: Path) -> Callable[[Dict], UnifiedLogger]: +# # logdir = session_path / "ray_results" +# # logdir.mkdir(parents=True, exist_ok=True) - return logger_creator +# # def logger_creator(config: Dict) -> UnifiedLogger: +# # return UnifiedLogger(config, logdir, loggers=None) + +# return logger_creator -class RLlibAgent(AgentSessionABC): - """An AgentSession class that implements a Ray RLlib agent.""" +# # class RLlibAgent(AgentSessionABC): +# # """An AgentSession class that implements a Ray RLlib agent.""" - def __init__( - self, - training_config_path: Optional[Union[str, Path]] = "", - lay_down_config_path: Optional[Union[str, Path]] = "", - session_path: Optional[Union[str, Path]] = None, - ) -> None: - """ - Initialise the RLLib Agent training session. +# # def __init__( +# # self, +# # training_config_path: Optional[Union[str, Path]] = "", +# # lay_down_config_path: Optional[Union[str, Path]] = "", +# # session_path: Optional[Union[str, Path]] = None, +# # ) -> None: +# # """ +# # Initialise the RLLib Agent training session. - :param training_config_path: YAML file containing configurable items defined in - `primaite.config.training_config.TrainingConfig` - :type training_config_path: Union[path, str] - :param lay_down_config_path: YAML file containing configurable items for generating network laydown. - :type lay_down_config_path: Union[path, str] - :raises ValueError: If the training config contains an unexpected value for agent_framework (should be "RLLIB") - :raises ValueError: If the training config contains an unexpected value for agent_identifies (should be `PPO` - or `A2C`) - """ - # TODO: implement RLlib agent loading - if session_path is not None: - msg = "RLlib agent loading has not been implemented yet" - _LOGGER.critical(msg) - raise NotImplementedError(msg) +# # :param training_config_path: YAML file containing configurable items defined in +# # `primaite.config.training_config.TrainingConfig` +# # :type training_config_path: Union[path, str] +# # :param lay_down_config_path: YAML file containing configurable items for generating network laydown. +# # :type lay_down_config_path: Union[path, str] +# # :raises ValueError: If the training config contains a bad value for agent_framework (should be "RLLIB") +# # :raises ValueError: If the training config contains a bad value for agent_identifies (should be `PPO` +# # or `A2C`) +# # """ +# # # TODO: implement RLlib agent loading +# # if session_path is not None: +# # msg = "RLlib agent loading has not been implemented yet" +# # _LOGGER.critical(msg) +# # raise NotImplementedError(msg) - super().__init__(training_config_path, lay_down_config_path) - if self._training_config.session_type == SessionType.EVAL: - msg = "Cannot evaluate an RLlib agent that hasn't been through training yet." - _LOGGER.critical(msg) - raise RLlibAgentError(msg) - if not self._training_config.agent_framework == AgentFramework.RLLIB: - msg = f"Expected RLLIB agent_framework, " f"got {self._training_config.agent_framework}" - _LOGGER.error(msg) - raise ValueError(msg) - self._agent_config_class: Union[PPOConfig, A2CConfig] - if self._training_config.agent_identifier == AgentIdentifier.PPO: - self._agent_config_class = PPOConfig - elif self._training_config.agent_identifier == AgentIdentifier.A2C: - self._agent_config_class = A2CConfig - else: - msg = "Expected PPO or A2C agent_identifier, " f"got {self._training_config.agent_identifier.value}" - _LOGGER.error(msg) - raise ValueError(msg) - self._agent_config: Union[PPOConfig, A2CConfig] +# # super().__init__(training_config_path, lay_down_config_path) +# # if self._training_config.session_type == SessionType.EVAL: +# # msg = "Cannot evaluate an RLlib agent that hasn't been through training yet." +# # _LOGGER.critical(msg) +# # raise RLlibAgentError(msg) +# # if not self._training_config.agent_framework == AgentFramework.RLLIB: +# # msg = f"Expected RLLIB agent_framework, " f"got {self._training_config.agent_framework}" +# # _LOGGER.error(msg) +# # raise ValueError(msg) +# # self._agent_config_class: Union[PPOConfig, A2CConfig] +# # if self._training_config.agent_identifier == AgentIdentifier.PPO: +# # self._agent_config_class = PPOConfig +# # elif self._training_config.agent_identifier == AgentIdentifier.A2C: +# # self._agent_config_class = A2CConfig +# # else: +# # msg = "Expected PPO or A2C agent_identifier, " f"got {self._training_config.agent_identifier.value}" +# # _LOGGER.error(msg) +# # raise ValueError(msg) +# # self._agent_config: Union[PPOConfig, A2CConfig] - self._current_result: dict - self._setup() - _LOGGER.debug( - f"Created {self.__class__.__name__} using: " - f"agent_framework={self._training_config.agent_framework}, " - f"agent_identifier=" - f"{self._training_config.agent_identifier}, " - f"deep_learning_framework=" - f"{self._training_config.deep_learning_framework}" - ) - self._train_agent = None # Required to capture the learning agent to close after eval +# # self._current_result: dict +# # self._setup() +# # _LOGGER.debug( +# # f"Created {self.__class__.__name__} using: " +# # f"agent_framework={self._training_config.agent_framework}, " +# # f"agent_identifier=" +# # f"{self._training_config.agent_identifier}, " +# # f"deep_learning_framework=" +# # f"{self._training_config.deep_learning_framework}" +# # ) +# # self._train_agent = None # Required to capture the learning agent to close after eval - def _update_session_metadata_file(self) -> None: - """ - Update the ``session_metadata.json`` file. +# # def _update_session_metadata_file(self) -> None: +# # """ +# # Update the ``session_metadata.json`` file. - Updates the `session_metadata.json`` in the ``session_path`` directory - with the following key/value pairs: +# # Updates the `session_metadata.json`` in the ``session_path`` directory +# # with the following key/value pairs: - - end_datetime: The date & time the session ended in iso format. - - total_episodes: The total number of training episodes completed. - - total_time_steps: The total number of training time steps completed. - """ - with open(self.session_path / "session_metadata.json", "r") as file: - metadata_dict = json.load(file) +# # - end_datetime: The date & time the session ended in iso format. +# # - total_episodes: The total number of training episodes completed. +# # - total_time_steps: The total number of training time steps completed. +# # """ +# # with open(self.session_path / "session_metadata.json", "r") as file: +# # metadata_dict = json.load(file) - metadata_dict["end_datetime"] = datetime.now().isoformat() - if not self.is_eval: - metadata_dict["learning"]["total_episodes"] = self._current_result["episodes_total"] # noqa - metadata_dict["learning"]["total_time_steps"] = self._current_result["timesteps_total"] # noqa - else: - metadata_dict["evaluation"]["total_episodes"] = self._current_result["episodes_total"] # noqa - metadata_dict["evaluation"]["total_time_steps"] = self._current_result["timesteps_total"] # noqa +# # metadata_dict["end_datetime"] = datetime.now().isoformat() +# # if not self.is_eval: +# # metadata_dict["learning"]["total_episodes"] = self._current_result["episodes_total"] # noqa +# # metadata_dict["learning"]["total_time_steps"] = self._current_result["timesteps_total"] # noqa +# # else: +# # metadata_dict["evaluation"]["total_episodes"] = self._current_result["episodes_total"] # noqa +# # metadata_dict["evaluation"]["total_time_steps"] = self._current_result["timesteps_total"] # noqa - filepath = self.session_path / "session_metadata.json" - _LOGGER.debug(f"Updating Session Metadata file: {filepath}") - with open(filepath, "w") as file: - json.dump(metadata_dict, file) - _LOGGER.debug("Finished updating session metadata file") +# # filepath = self.session_path / "session_metadata.json" +# # _LOGGER.debug(f"Updating Session Metadata file: {filepath}") +# # with open(filepath, "w") as file: +# # json.dump(metadata_dict, file) +# # _LOGGER.debug("Finished updating session metadata file") - def _setup(self) -> None: - super()._setup() - register_env("primaite", _env_creator) - self._agent_config = self._agent_config_class() +# # def _setup(self) -> None: +# # super()._setup() +# # register_env("primaite", _env_creator) +# # self._agent_config = self._agent_config_class() - self._agent_config.environment( - env="primaite", - env_config=dict( - training_config_path=self._training_config_path, - lay_down_config_path=self._lay_down_config_path, - session_path=self.session_path, - timestamp_str=self.timestamp_str, - ), - ) - self._agent_config.seed = self._training_config.seed +# # self._agent_config.environment( +# # env="primaite", +# # env_config=dict( +# # training_config_path=self._training_config_path, +# # lay_down_config_path=self._lay_down_config_path, +# # session_path=self.session_path, +# # timestamp_str=self.timestamp_str, +# # ), +# # ) +# # self._agent_config.seed = self._training_config.seed - self._agent_config.training(train_batch_size=self._training_config.num_train_steps) - self._agent_config.framework(framework="tf") +# # self._agent_config.training(train_batch_size=self._training_config.num_train_steps) +# # self._agent_config.framework(framework="tf") - self._agent_config.rollouts( - num_rollout_workers=1, - num_envs_per_worker=1, - horizon=self._training_config.num_train_steps, - ) - self._agent: Algorithm = self._agent_config.build(logger_creator=_custom_log_creator(self.learning_path)) +# # self._agent_config.rollouts( +# # num_rollout_workers=1, +# # num_envs_per_worker=1, +# # horizon=self._training_config.num_train_steps, +# # ) +# # self._agent: Algorithm = self._agent_config.build(logger_creator=_custom_log_creator(self.learning_path)) - def _save_checkpoint(self) -> None: - checkpoint_n = self._training_config.checkpoint_every_n_episodes - episode_count = self._current_result["episodes_total"] - save_checkpoint = False - if checkpoint_n: - save_checkpoint = episode_count % checkpoint_n == 0 - if episode_count and save_checkpoint: - self._agent.save(str(self.checkpoints_path)) +# # def _save_checkpoint(self) -> None: +# # checkpoint_n = self._training_config.checkpoint_every_n_episodes +# # episode_count = self._current_result["episodes_total"] +# # save_checkpoint = False +# # if checkpoint_n: +# # save_checkpoint = episode_count % checkpoint_n == 0 +# # if episode_count and save_checkpoint: +# # self._agent.save(str(self.checkpoints_path)) - def learn( - self, - **kwargs: Any, - ) -> None: - """ - Evaluate the agent. +# # def learn( +# # self, +# # **kwargs: Any, +# # ) -> None: +# # """ +# # Evaluate the agent. - :param kwargs: Any agent-specific key-word args to be passed. - """ - time_steps = self._training_config.num_train_steps - episodes = self._training_config.num_train_episodes +# # :param kwargs: Any agent-specific key-word args to be passed. +# # """ +# # time_steps = self._training_config.num_train_steps +# # episodes = self._training_config.num_train_episodes - _LOGGER.info(f"Beginning learning for {episodes} episodes @" f" {time_steps} time steps...") - for i in range(episodes): - self._current_result = self._agent.train() - self._save_checkpoint() - self.save() - super().learn() - # Done this way as the RLlib eval can only be performed if the session hasn't been stopped - if self._training_config.session_type is not SessionType.TRAIN: - self._train_agent = self._agent - else: - self._agent.stop() - self._plot_av_reward_per_episode(learning_session=True) +# # _LOGGER.info(f"Beginning learning for {episodes} episodes @" f" {time_steps} time steps...") +# # for i in range(episodes): +# # self._current_result = self._agent.train() +# # self._save_checkpoint() +# # self.save() +# # super().learn() +# # # Done this way as the RLlib eval can only be performed if the session hasn't been stopped +# # if self._training_config.session_type is not SessionType.TRAIN: +# # self._train_agent = self._agent +# # else: +# # self._agent.stop() +# # self._plot_av_reward_per_episode(learning_session=True) - def _unpack_saved_agent_into_eval(self) -> Path: - """Unpacks the pre-trained and saved RLlib agent so that it can be reloaded by Ray for eval.""" - agent_restore_path = self.evaluation_path / "agent_restore" - if agent_restore_path.exists(): - shutil.rmtree(agent_restore_path) - agent_restore_path.mkdir() - with zipfile.ZipFile(self._saved_agent_path, "r") as zip_file: - zip_file.extractall(agent_restore_path) - return agent_restore_path +# # def _unpack_saved_agent_into_eval(self) -> Path: +# # """Unpacks the pre-trained and saved RLlib agent so that it can be reloaded by Ray for eval.""" +# # agent_restore_path = self.evaluation_path / "agent_restore" +# # if agent_restore_path.exists(): +# # shutil.rmtree(agent_restore_path) +# # agent_restore_path.mkdir() +# # with zipfile.ZipFile(self._saved_agent_path, "r") as zip_file: +# # zip_file.extractall(agent_restore_path) +# # return agent_restore_path - def _setup_eval(self): - self._can_learn = False - self._can_evaluate = True - self._agent.restore(str(self._unpack_saved_agent_into_eval())) +# # def _setup_eval(self): +# # self._can_learn = False +# # self._can_evaluate = True +# # self._agent.restore(str(self._unpack_saved_agent_into_eval())) - def evaluate( - self, - **kwargs, - ): - """ - Evaluate the agent. +# # def evaluate( +# # self, +# # **kwargs, +# # ): +# # """ +# # Evaluate the agent. - :param kwargs: Any agent-specific key-word args to be passed. - """ - time_steps = self._training_config.num_eval_steps - episodes = self._training_config.num_eval_episodes +# # :param kwargs: Any agent-specific key-word args to be passed. +# # """ +# # time_steps = self._training_config.num_eval_steps +# # episodes = self._training_config.num_eval_episodes - self._setup_eval() +# # self._setup_eval() - self._env: Primaite = Primaite( - self._training_config_path, self._lay_down_config_path, self.session_path, self.timestamp_str - ) +# # self._env: Primaite = Primaite( +# # self._training_config_path, self._lay_down_config_path, self.session_path, self.timestamp_str +# # ) - self._env.set_as_eval() - self.is_eval = True - if self._training_config.deterministic: - deterministic_str = "deterministic" - else: - deterministic_str = "non-deterministic" - _LOGGER.info( - f"Beginning {deterministic_str} evaluation for " f"{episodes} episodes @ {time_steps} time steps..." - ) - for episode in range(episodes): - obs = self._env.reset() - for step in range(time_steps): - action = self._agent.compute_single_action(observation=obs, explore=False) +# # self._env.set_as_eval() +# # self.is_eval = True +# # if self._training_config.deterministic: +# # deterministic_str = "deterministic" +# # else: +# # deterministic_str = "non-deterministic" +# # _LOGGER.info( +# # f"Beginning {deterministic_str} evaluation for " f"{episodes} episodes @ {time_steps} time steps..." +# # ) +# # for episode in range(episodes): +# # obs = self._env.reset() +# # for step in range(time_steps): +# # action = self._agent.compute_single_action(observation=obs, explore=False) - obs, rewards, done, info = self._env.step(action) +# # obs, rewards, done, info = self._env.step(action) - self._env.reset() - self._env.close() - super().evaluate() - # Now we're safe to close the learning agent and write the mean rewards per episode for it - if self._training_config.session_type is not SessionType.TRAIN: - self._train_agent.stop() - self._plot_av_reward_per_episode(learning_session=True) - # Perform a clean-up of the unpacked agent - if (self.evaluation_path / "agent_restore").exists(): - shutil.rmtree((self.evaluation_path / "agent_restore")) +# # self._env.reset() +# # self._env.close() +# # super().evaluate() +# # # Now we're safe to close the learning agent and write the mean rewards per episode for it +# # if self._training_config.session_type is not SessionType.TRAIN: +# # self._train_agent.stop() +# # self._plot_av_reward_per_episode(learning_session=True) +# # # Perform a clean-up of the unpacked agent +# # if (self.evaluation_path / "agent_restore").exists(): +# # shutil.rmtree((self.evaluation_path / "agent_restore")) - def _get_latest_checkpoint(self) -> None: - raise NotImplementedError +# # def _get_latest_checkpoint(self) -> None: +# # raise NotImplementedError - @classmethod - def load(cls, path: Union[str, Path]) -> RLlibAgent: - """Load an agent from file.""" - raise NotImplementedError +# # @classmethod +# # def load(cls, path: Union[str, Path]) -> RLlibAgent: +# # """Load an agent from file.""" +# # raise NotImplementedError - def save(self, overwrite_existing: bool = True) -> None: - """Save the agent.""" - # Make temp dir to save in isolation - temp_dir = self.learning_path / str(uuid4()) - temp_dir.mkdir() +# # def save(self, overwrite_existing: bool = True) -> None: +# # """Save the agent.""" +# # # Make temp dir to save in isolation +# # temp_dir = self.learning_path / str(uuid4()) +# # temp_dir.mkdir() - # Save the agent to the temp dir - self._agent.save(str(temp_dir)) +# # # Save the agent to the temp dir +# # self._agent.save(str(temp_dir)) - # Capture the saved Rllib checkpoint inside the temp directory - for file in temp_dir.iterdir(): - checkpoint_dir = file - break +# # # Capture the saved Rllib checkpoint inside the temp directory +# # for file in temp_dir.iterdir(): +# # checkpoint_dir = file +# # break - # Zip the folder - shutil.make_archive(str(self._saved_agent_path).replace(".zip", ""), "zip", checkpoint_dir) # noqa +# # # Zip the folder +# # shutil.make_archive(str(self._saved_agent_path).replace(".zip", ""), "zip", checkpoint_dir) # noqa - # Drop the temp directory - shutil.rmtree(temp_dir) +# # # Drop the temp directory +# # shutil.rmtree(temp_dir) - def export(self) -> None: - """Export the agent to transportable file format.""" - raise NotImplementedError +# # def export(self) -> None: +# # """Export the agent to transportable file format.""" +# # raise NotImplementedError diff --git a/src/primaite/common/enums.py b/src/primaite/common/enums.py index 006301f1..c33e764b 100644 --- a/src/primaite/common/enums.py +++ b/src/primaite/common/enums.py @@ -99,8 +99,8 @@ class AgentFramework(Enum): "Custom Agent" SB3 = 1 "Stable Baselines3" - RLLIB = 2 - "Ray RLlib" + # RLLIB = 2 + # "Ray RLlib" class DeepLearningFramework(Enum): diff --git a/src/primaite/config/training_config.py b/src/primaite/config/training_config.py index 7f5dc568..f81bb6f7 100644 --- a/src/primaite/config/training_config.py +++ b/src/primaite/config/training_config.py @@ -248,8 +248,8 @@ class TrainingConfig: def __str__(self) -> str: obs_str = ",".join([c["name"] for c in self.observation_space["components"]]) tc = f"{self.agent_framework}, " - if self.agent_framework is AgentFramework.RLLIB: - tc += f"{self.deep_learning_framework}, " + # if self.agent_framework is AgentFramework.RLLIB: + # tc += f"{self.deep_learning_framework}, " tc += f"{self.agent_identifier}, " if self.agent_identifier is AgentIdentifier.HARDCODED: tc += f"{self.hard_coded_agent_view}, " diff --git a/src/primaite/environment/primaite_env.py b/src/primaite/environment/primaite_env.py index 62af6c5b..a809772f 100644 --- a/src/primaite/environment/primaite_env.py +++ b/src/primaite/environment/primaite_env.py @@ -17,9 +17,8 @@ from primaite import getLogger from primaite.acl.access_control_list import AccessControlList from primaite.agents.utils import is_valid_acl_action_extra, is_valid_node_action from primaite.common.custom_typing import NodeUnion -from primaite.common.enums import ( +from primaite.common.enums import ( # AgentFramework, ActionType, - AgentFramework, AgentIdentifier, FileSystemState, HardwareState, @@ -236,7 +235,8 @@ class Primaite(Env): _LOGGER.debug("Action space type NODE selected") # Terms (for node action space): # [0, num nodes] - node ID (0 = nothing, node ID) - # [0, 4] - what property it's acting on (0 = nothing, state, SoftwareState, service state, file system state) # noqa + # [0, 4] - what property it's acting on (0 = nothing, state, SoftwareState, # noqa + # service state, file system state) # noqa # [0, 3] - action on property (0 = nothing, On / Scan, Off / Repair, Reset / Patch / Restore) # noqa # [0, num services] - resolves to service ID (0 = nothing, resolves to service) # noqa self.action_dict = self.create_node_action_dict() @@ -271,8 +271,8 @@ class Primaite(Env): @property def actual_episode_count(self) -> int: """Shifts the episode_count by -1 for RLlib learning session.""" - if self.training_config.agent_framework is AgentFramework.RLLIB and not self.is_eval: - return self.episode_count - 1 + # if self.training_config.agent_framework is AgentFramework.RLLIB and not self.is_eval: + # return self.episode_count - 1 return self.episode_count def set_as_eval(self) -> None: diff --git a/src/primaite/primaite_session.py b/src/primaite/primaite_session.py index 2cb0d5bd..7d5b2709 100644 --- a/src/primaite/primaite_session.py +++ b/src/primaite/primaite_session.py @@ -10,7 +10,8 @@ from primaite import getLogger from primaite.agents.agent_abc import AgentSessionABC from primaite.agents.hardcoded_acl import HardCodedACLAgent from primaite.agents.hardcoded_node import HardCodedNodeAgent -from primaite.agents.rllib import RLlibAgent + +# from primaite.agents.rllib import RLlibAgent from primaite.agents.sb3 import SB3Agent from primaite.agents.simple import DoNothingACLAgent, DoNothingNodeAgent, DummyAgent, RandomAgent from primaite.common.enums import ActionType, AgentFramework, AgentIdentifier, SessionType @@ -157,10 +158,12 @@ class PrimaiteSession: self.legacy_lay_down_config, ) - elif self._training_config.agent_framework == AgentFramework.RLLIB: - _LOGGER.debug(f"PrimaiteSession Setup: Agent Framework = {AgentFramework.RLLIB}") - # Ray RLlib Agent - self._agent_session = RLlibAgent(self._training_config_path, self._lay_down_config_path, self.session_path) + # elif self._training_config.agent_framework == AgentFramework.RLLIB: + # _LOGGER.debug(f"PrimaiteSession Setup: Agent Framework = {AgentFramework.RLLIB}") + # # Ray RLlib Agent + # self._agent_session = RLlibAgent( + # self._training_config_path, self._lay_down_config_path, self.session_path + # ) else: # Invalid AgentFramework diff --git a/tests/test_primaite_session.py b/tests/test_primaite_session.py index b76a2ecf..6e23b3ac 100644 --- a/tests/test_primaite_session.py +++ b/tests/test_primaite_session.py @@ -13,7 +13,7 @@ _LOGGER = getLogger(__name__) @pytest.mark.parametrize( "temp_primaite_session", [ - [TEST_CONFIG_ROOT / "session_test/training_config_main_rllib.yaml", dos_very_basic_config_path()], + # [TEST_CONFIG_ROOT / "session_test/training_config_main_rllib.yaml", dos_very_basic_config_path()], [TEST_CONFIG_ROOT / "session_test/training_config_main_sb3.yaml", dos_very_basic_config_path()], ], indirect=True, From 59394c3642cf909572d40f069c5a69844da9d16b Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 31 Jul 2023 15:55:22 +0100 Subject: [PATCH 031/980] #1715 - Added Link class in physical_layer.py. Also added NIC class in physical_layer.py for #1672. Added attributes and public API functions. test_physical_layer.py ready to house the tests once logic has been implemented. --- .../primaite/simulator/network}/__init__.py | 0 .../simulator/network/physical_layer.py | 222 ++++++++++++++++++ .../simulator => _primaite}/__init__.py | 0 .../_primaite/_simulator/__init__.py | 0 .../_primaite/_simulator/_network/__init__.py | 0 .../_network/test_physical_layer.py | 26 ++ .../_simulator}/test_core.py | 0 7 files changed, 248 insertions(+) rename {tests/unit_tests/primaite => src/primaite/simulator/network}/__init__.py (100%) create mode 100644 src/primaite/simulator/network/physical_layer.py rename tests/unit_tests/{primaite/simulator => _primaite}/__init__.py (100%) create mode 100644 tests/unit_tests/_primaite/_simulator/__init__.py create mode 100644 tests/unit_tests/_primaite/_simulator/_network/__init__.py create mode 100644 tests/unit_tests/_primaite/_simulator/_network/test_physical_layer.py rename tests/unit_tests/{primaite/simulator => _primaite/_simulator}/test_core.py (100%) diff --git a/tests/unit_tests/primaite/__init__.py b/src/primaite/simulator/network/__init__.py similarity index 100% rename from tests/unit_tests/primaite/__init__.py rename to src/primaite/simulator/network/__init__.py diff --git a/src/primaite/simulator/network/physical_layer.py b/src/primaite/simulator/network/physical_layer.py new file mode 100644 index 00000000..bb4b120e --- /dev/null +++ b/src/primaite/simulator/network/physical_layer.py @@ -0,0 +1,222 @@ +from __future__ import annotations + +import re +import secrets +from ipaddress import IPv4Address +from typing import Dict, List, Optional + +from primaite.simulator.core import SimComponent + + +def generate_mac_address(oui: Optional[str] = None) -> str: + """ + Generate a random MAC Address.. + + :Example: + + >>> generate_mac_address() + 'ef:7e:97:c8:a8:ce' + + >>> generate_mac_address(oui='aa:bb:cc') + 'aa:bb:cc:42:ba:41' + + :param oui: The Organizationally Unique Identifier (OUI) portion of the MAC address. It should be a string with + the first 3 bytes (24 bits) in the format "XX:XX:XX". + :raises ValueError: If the 'oui' is not in the correct format (hexadecimal and 6 characters). + """ + random_bytes = [secrets.randbits(8) for _ in range(6)] + + if oui: + oui_pattern = re.compile(r"^([0-9A-Fa-f]{2}[:-]){2}[0-9A-Fa-f]{2}$") + if not oui_pattern.match(oui): + raise ValueError( + f"Invalid oui. The oui should be in the format 'xx:xx:xx', where x is a hexadecimal digit, got '{oui}'." + ) + oui_bytes = [int(chunk, 16) for chunk in oui.split(":")] + mac = oui_bytes + random_bytes[len(oui_bytes) :] + else: + mac = random_bytes + + return ":".join(f"{b:02x}" for b in mac) + + +class Link(SimComponent): + """ + Represents a network link between two network interface cards (NICs). + + :param endpoint_a: The first NIC connected to the Link. + :type endpoint_a: NIC + :param endpoint_b: The second NIC connected to the Link. + :type endpoint_b: NIC + :param bandwidth: The bandwidth of the Link in Mbps (default is 100 Mbps). + :type bandwidth: int + """ + + endpoint_a: NIC + endpoint_b: NIC + bandwidth: int + current_load: int = 0 + + def __init__(self, endpoint_a: NIC, endpoint_b: NIC, bandwidth: int = 100): + """ + Initialize the Link instance. + + When a Link is created, it automatically connects the endpoints to itself. + + :param endpoint_a: The first NIC connected to the link. + :type endpoint_a: NIC + :param endpoint_b: The second NIC connected to the link. + :type endpoint_b: NIC + :param bandwidth: The bandwidth of the link in Mbps (default is 100 Mbps). + :type bandwidth: int + :raise ValueError: If endpoint_a equals endpoint_b. + """ + super().__init__(endpoint_a=endpoint_a, endpoint_b=endpoint_b, bandwidth=bandwidth) + if self.endpoint_a == self.endpoint_b: + raise ValueError("endpoint_a and endpoint_b cannot be the same NIC") + + def send_frame(self, sender_nic: NIC, frame): + """ + Send a network frame from one NIC to another connected NIC. + + :param sender_nic: The NIC sending the frame. + :type sender_nic: NIC + :param frame: The network frame to be sent. + :type frame: Frame + """ + pass + + def receive_frame(self, sender_nic: NIC, frame): + """ + Receive a network frame from a connected NIC. + + :param sender_nic: The NIC sending the frame. + :type sender_nic: NIC + :param frame: The network frame being received. + :type frame: Frame + """ + pass + + def describe_state(self) -> Dict: + """ + Get the current state of the Libk as a dict. + + :return: A dict containing the current state of the Link. + """ + pass + + def apply_action(self, action: str): + """ + Apply an action to the Link. + + :param action: The action to be applied. + :type action: str + """ + pass + + +class NIC(SimComponent): + """ + Models a Network Interface Card (NIC) in a computer or network device. + + :param ip_address: The IPv4 address assigned to the NIC. + :param subnet_mask: The subnet mask assigned to the NIC. + :param gateway: The default gateway IP address for forwarding network traffic to other networks. + :param mac_address: The MAC address of the NIC. Defaults to a randomly set MAC address. + :param speed: The speed of the NIC in Mbps. + :param mtu: The Maximum Transmission Unit (MTU) of the NIC in Bytes, representing the largest data packet size it + can handle without fragmentation. + :param wake_on_lan: Indicates if the NIC supports Wake-on-LAN functionality. + :param dns_servers: List of IP addresses of DNS servers used for name resolution. + :param connected_link: The link to which the NIC is connected (default is None). + :param enabled: Indicates whether the NIC is enabled. + """ + + ip_address: IPv4Address + "The IP address assigned to the NIC for communication on an IP-based network." + subnet_mask: str + "The subnet mask assigned to the NIC." + gateway: IPv4Address + "The default gateway IP address for forwarding network traffic to other networks. Randomly generated upon creation." + mac_address: str = generate_mac_address() + "The MAC address of the NIC. Defaults to a randomly set MAC address." + speed: Optional[int] = 100 + "The speed of the NIC in Mbps. Default is 100 Mbps." + mtu: Optional[int] = 1500 + "The Maximum Transmission Unit (MTU) of the NIC in Bytes. Default is 1500 B" + wake_on_lan: Optional[bool] = False + "Indicates if the NIC supports Wake-on-LAN functionality." + dns_servers: List[IPv4Address] = [] + "List of IP addresses of DNS servers used for name resolution." + connected_link: Optional[Link] = None + "The Link to which the NIC is connected." + enabled: bool = False + "Indicates whether the NIC is enabled." + + def connect_link(self, link: Link): + """ + Connect the NIC to a link. + + :param link: The link to which the NIC is connected. + :type link: :class:`~primaite.simulator.network.physical_layer.Link` + """ + pass + + def disconnect_link(self): + """Disconnect the NIC from the connected :class:`~primaite.simulator.network.physical_layer.Link`.""" + pass + + def add_dns_server(self, ip_address: IPv4Address): + """ + Add a DNS server IP address. + + :param ip_address: The IP address of the DNS server to be added. + :type ip_address: ipaddress.IPv4Address + """ + pass + + def remove_dns_server(self, ip_address: IPv4Address): + """ + Remove a DNS server IP Address. + + :param ip_address: The IP address of the DNS server to be removed. + :type ip_address: ipaddress.IPv4Address + """ + pass + + def send_frame(self, frame): + """ + Send a network frame from the NIC to the connected link. + + :param frame: The network frame to be sent. + :type frame: :class:`~primaite.simulator.network.osi_layers.Frame` + """ + pass + + def receive_frame(self, frame): + """ + Receive a network frame from the connected link. + + The Frame is passed to the Node. + + :param frame: The network frame being received. + :type frame: :class:`~primaite.simulator.network.osi_layers.Frame` + """ + pass + + def describe_state(self) -> Dict: + """ + Get the current state of the NIC as a dict. + + :return: A dict containing the current state of the NIC. + """ + pass + + def apply_action(self, action: str): + """ + Apply an action to the NIC. + + :param action: The action to be applied. + :type action: str + """ + pass diff --git a/tests/unit_tests/primaite/simulator/__init__.py b/tests/unit_tests/_primaite/__init__.py similarity index 100% rename from tests/unit_tests/primaite/simulator/__init__.py rename to tests/unit_tests/_primaite/__init__.py diff --git a/tests/unit_tests/_primaite/_simulator/__init__.py b/tests/unit_tests/_primaite/_simulator/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_network/__init__.py b/tests/unit_tests/_primaite/_simulator/_network/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_physical_layer.py b/tests/unit_tests/_primaite/_simulator/_network/test_physical_layer.py new file mode 100644 index 00000000..137e2cd6 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/test_physical_layer.py @@ -0,0 +1,26 @@ +import re + +import pytest + +from primaite.simulator.network.physical_layer import generate_mac_address + + +def test_mac_address_generation(): + """Tests random mac address generation.""" + mac_address = generate_mac_address() + assert re.match("[0-9a-f]{2}([-:]?)[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", mac_address) + + +def test_mac_address_with_oui(): + """Tests random mac address generation with oui.""" + oui = "aa:bb:cc" + mac_address = generate_mac_address(oui=oui) + assert re.match("[0-9a-f]{2}([-:]?)[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", mac_address) + assert mac_address[:8] == oui + + +def test_invalid_oui_mac_address(): + """Tests random mac address generation fails with invalid oui.""" + invalid_oui = "aa-bb-cc" + with pytest.raises(ValueError): + generate_mac_address(oui=invalid_oui) diff --git a/tests/unit_tests/primaite/simulator/test_core.py b/tests/unit_tests/_primaite/_simulator/test_core.py similarity index 100% rename from tests/unit_tests/primaite/simulator/test_core.py rename to tests/unit_tests/_primaite/_simulator/test_core.py From c4adc2f543672e887c3a515525ae8d4bacdea7c0 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 31 Jul 2023 16:47:13 +0100 Subject: [PATCH 032/980] add flake8-annotations to pre-commits --- .pre-commit-config.yaml | 1 + pyproject.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6e435bee..494ea937 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,3 +27,4 @@ repos: - id: flake8 additional_dependencies: - flake8-docstrings + - flake8-annotations diff --git a/pyproject.toml b/pyproject.toml index 4e8250d8..4982dfd1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,6 +54,7 @@ license-files = ["LICENSE"] dev = [ "build==0.10.0", "flake8==6.0.0", + "flake8-annotations", "furo==2023.3.27", "gputil==1.4.0", "pip-licenses==4.3.0", From 0532db960a5f20cdad3bffa7cb67e41f2d62fbbe Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 31 Jul 2023 16:55:45 +0100 Subject: [PATCH 033/980] #1715 - Added more tests. MAde use of the pydantic model_post_init function for proper ipv4 cofiguration checking. Added NetworkError to exceptions.py. --- src/primaite/exceptions.py | 6 ++ .../simulator/network/physical_layer.py | 86 ++++++++++++++----- tests/integration_tests/__init__.py | 0 tests/integration_tests/network/__init__.py | 0 .../network/test_nic_link_connection.py | 14 +++ .../_network/test_physical_layer.py | 47 +++++++++- 6 files changed, 129 insertions(+), 24 deletions(-) create mode 100644 tests/integration_tests/__init__.py create mode 100644 tests/integration_tests/network/__init__.py create mode 100644 tests/integration_tests/network/test_nic_link_connection.py diff --git a/src/primaite/exceptions.py b/src/primaite/exceptions.py index 3b4058ac..025f6d41 100644 --- a/src/primaite/exceptions.py +++ b/src/primaite/exceptions.py @@ -9,3 +9,9 @@ class RLlibAgentError(PrimaiteError): """Raised when there is a generic error with a RLlib agent that is specific to PRimAITE.""" pass + + +class NetworkError(PrimaiteError): + """Raised when an error occurs at the network level.""" + + pass diff --git a/src/primaite/simulator/network/physical_layer.py b/src/primaite/simulator/network/physical_layer.py index bb4b120e..6d268b59 100644 --- a/src/primaite/simulator/network/physical_layer.py +++ b/src/primaite/simulator/network/physical_layer.py @@ -2,15 +2,19 @@ from __future__ import annotations import re import secrets -from ipaddress import IPv4Address -from typing import Dict, List, Optional +from ipaddress import IPv4Address, IPv4Network +from typing import Any, Dict, List, Optional, Union +from primaite import getLogger +from primaite.exceptions import NetworkError from primaite.simulator.core import SimComponent +_LOGGER = getLogger(__name__) + def generate_mac_address(oui: Optional[str] = None) -> str: """ - Generate a random MAC Address.. + Generate a random MAC Address. :Example: @@ -29,9 +33,8 @@ def generate_mac_address(oui: Optional[str] = None) -> str: if oui: oui_pattern = re.compile(r"^([0-9A-Fa-f]{2}[:-]){2}[0-9A-Fa-f]{2}$") if not oui_pattern.match(oui): - raise ValueError( - f"Invalid oui. The oui should be in the format 'xx:xx:xx', where x is a hexadecimal digit, got '{oui}'." - ) + msg = f"Invalid oui. The oui should be in the format xx:xx:xx, where x is a hexadecimal digit, got '{oui}'" + raise ValueError(msg) oui_bytes = [int(chunk, 16) for chunk in oui.split(":")] mac = oui_bytes + random_bytes[len(oui_bytes) :] else: @@ -54,26 +57,21 @@ class Link(SimComponent): endpoint_a: NIC endpoint_b: NIC - bandwidth: int + bandwidth: int = 100 current_load: int = 0 - def __init__(self, endpoint_a: NIC, endpoint_b: NIC, bandwidth: int = 100): + def model_post_init(self, __context: Any) -> None: """ - Initialize the Link instance. + Ensure that endpoint_a and endpoint_b are not the same :class:`~primaite.simulator.network.physical_layer.NIC`. - When a Link is created, it automatically connects the endpoints to itself. - - :param endpoint_a: The first NIC connected to the link. - :type endpoint_a: NIC - :param endpoint_b: The second NIC connected to the link. - :type endpoint_b: NIC - :param bandwidth: The bandwidth of the link in Mbps (default is 100 Mbps). - :type bandwidth: int - :raise ValueError: If endpoint_a equals endpoint_b. + :raises ValueError: If endpoint_a and endpoint_b are the same NIC. """ - super().__init__(endpoint_a=endpoint_a, endpoint_b=endpoint_b, bandwidth=bandwidth) if self.endpoint_a == self.endpoint_b: - raise ValueError("endpoint_a and endpoint_b cannot be the same NIC") + msg = "endpoint_a and endpoint_b cannot be the same NIC" + _LOGGER.error(msg) + raise ValueError(msg) + self.endpoint_a.connect_link(self) + self.endpoint_b.connect_link(self) def send_frame(self, sender_nic: NIC, frame): """ @@ -132,11 +130,11 @@ class NIC(SimComponent): :param enabled: Indicates whether the NIC is enabled. """ - ip_address: IPv4Address + ip_address: Union[str, IPv4Address] "The IP address assigned to the NIC for communication on an IP-based network." subnet_mask: str "The subnet mask assigned to the NIC." - gateway: IPv4Address + gateway: Union[str, IPv4Address] "The default gateway IP address for forwarding network traffic to other networks. Randomly generated upon creation." mac_address: str = generate_mac_address() "The MAC address of the NIC. Defaults to a randomly set MAC address." @@ -153,14 +151,56 @@ class NIC(SimComponent): enabled: bool = False "Indicates whether the NIC is enabled." + def model_post_init(self, __context: Any) -> None: + """ + Post init function converts string IPs to IPv$Address and checks for proper IP address and gateway config. + + :raises ValueError: When the ip_address and gateway are the same. And when the ip_address/subnet mask are a + network address. + """ + if not isinstance(self.ip_address, IPv4Address): + self.ip_address: IPv4Address = IPv4Address(self.ip_address) + if not isinstance(self.gateway, IPv4Address): + self.gateway: IPv4Address = IPv4Address(self.gateway) + if self.ip_address == self.gateway: + msg = f"NIC ip address {self.ip_address} cannot be the same as the gateway {self.gateway}" + _LOGGER.error(msg) + raise ValueError(msg) + if self.ip_network.network_address == self.ip_address: + msg = ( + f"Failed to set IP address {self.ip_address} and subnet mask {self.subnet_mask} as it is a " + f"network address {self.ip_network.network_address}" + ) + _LOGGER.error(msg) + raise ValueError(msg) + + @property + def ip_network(self) -> IPv4Network: + """ + Return the IPv4Network of the NIC. + + :return: The IPv4Network from the ip_address/subnet mask. + """ + return IPv4Network(f"{self.ip_address}/{self.subnet_mask}", strict=False) + def connect_link(self, link: Link): """ Connect the NIC to a link. :param link: The link to which the NIC is connected. :type link: :class:`~primaite.simulator.network.physical_layer.Link` + :raise NetworkError: When an attempt to connect a Link is made while the NIC has a connected Link. """ - pass + if not self.connected_link: + if self.connected_link != link: + # TODO: Inform the Node that a link has been connected + self.connected_link = link + else: + _LOGGER.warning(f"Cannot connect link to NIC ({self.mac_address}) as it is already connected") + else: + msg = f"Cannot connect link to NIC ({self.mac_address}) as it already has a connection" + _LOGGER.error(msg) + raise NetworkError(msg) def disconnect_link(self): """Disconnect the NIC from the connected :class:`~primaite.simulator.network.physical_layer.Link`.""" diff --git a/tests/integration_tests/__init__.py b/tests/integration_tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration_tests/network/__init__.py b/tests/integration_tests/network/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration_tests/network/test_nic_link_connection.py b/tests/integration_tests/network/test_nic_link_connection.py new file mode 100644 index 00000000..1a191200 --- /dev/null +++ b/tests/integration_tests/network/test_nic_link_connection.py @@ -0,0 +1,14 @@ +import pytest + +from primaite.simulator.network.physical_layer import Link, NIC + + +def test_link_fails_with_same_nic(): + """Tests Link creation fails with endpoint_a and endpoint_b are the same NIC.""" + with pytest.raises(ValueError): + nic_a = NIC( + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + gateway="192.168.0.1", + ) + Link(endpoint_a=nic_a, endpoint_b=nic_a) diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_physical_layer.py b/tests/unit_tests/_primaite/_simulator/_network/test_physical_layer.py index 137e2cd6..ad1226a6 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_physical_layer.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_physical_layer.py @@ -1,8 +1,9 @@ import re +from ipaddress import IPv4Address import pytest -from primaite.simulator.network.physical_layer import generate_mac_address +from primaite.simulator.network.physical_layer import generate_mac_address, NIC def test_mac_address_generation(): @@ -24,3 +25,47 @@ def test_invalid_oui_mac_address(): invalid_oui = "aa-bb-cc" with pytest.raises(ValueError): generate_mac_address(oui=invalid_oui) + + +def test_nic_ip_address_type_conversion(): + """Tests NIC IP and gateway address is converted to IPv4Address is originally a string.""" + nic = NIC( + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + gateway="192.168.0.1", + ) + assert isinstance(nic.ip_address, IPv4Address) + assert isinstance(nic.gateway, IPv4Address) + + +def test_nic_deserialize(): + """Tests NIC serialization and deserialization.""" + nic = NIC( + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + gateway="192.168.0.1", + ) + + nic_json = nic.model_dump_json() + deserialized_nic = NIC.model_validate_json(nic_json) + assert nic == deserialized_nic + + +def test_nic_ip_address_as_gateway_fails(): + """Tests NIC creation fails if ip address is the same as the gateway.""" + with pytest.raises(ValueError): + NIC( + ip_address="192.168.0.1", + subnet_mask="255.255.255.0", + gateway="192.168.0.1", + ) + + +def test_nic_ip_address_as_network_address_fails(): + """Tests NIC creation fails if ip address and subnet mask are a network address.""" + with pytest.raises(ValueError): + NIC( + ip_address="192.168.0.0", + subnet_mask="255.255.255.0", + gateway="192.168.0.1", + ) From 0a079832e9b774d858deb263fab3eaf670472daa Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 31 Jul 2023 17:00:28 +0100 Subject: [PATCH 034/980] Add self,cls to flake8-ann ignore list --- .flake8 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.flake8 b/.flake8 index 398d14fb..6e653102 100644 --- a/.flake8 +++ b/.flake8 @@ -9,5 +9,8 @@ extend-ignore = E712 D401 F811 + ANN101 + ANN102 exclude = docs/source/* + tests/* From 9cf5bfa1b25641caf740d6abc79d2e41c8214f4d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 31 Jul 2023 17:07:56 +0100 Subject: [PATCH 035/980] Fix typehint issues --- benchmark/primaite_benchmark.py | 17 +++++++++-------- src/primaite/__init__.py | 8 ++++---- src/primaite/environment/observations.py | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/benchmark/primaite_benchmark.py b/benchmark/primaite_benchmark.py index ead5723b..8a911720 100644 --- a/benchmark/primaite_benchmark.py +++ b/benchmark/primaite_benchmark.py @@ -41,7 +41,7 @@ _TRAINING_CONFIG_PATH = _BENCHMARK_ROOT / "config" / "benchmark_training_config. _LAY_DOWN_CONFIG_PATH = data_manipulation_config_path() -def get_size(size_bytes: int): +def get_size(size_bytes: int) -> str: """ Scale bytes to its proper format. @@ -84,7 +84,7 @@ def _get_system_info() -> Dict: def _build_benchmark_latex_report( benchmark_metadata_dict: Dict, this_version_plot_path: Path, all_version_plot_path: Path -): +) -> None: geometry_options = {"tmargin": "2.5cm", "rmargin": "2.5cm", "bmargin": "2.5cm", "lmargin": "2.5cm"} data = benchmark_metadata_dict primaite_version = data["primaite_version"] @@ -186,7 +186,7 @@ class BenchmarkPrimaiteSession(PrimaiteSession): self, training_config_path: Union[str, Path], lay_down_config_path: Union[str, Path], - ): + ) -> None: super().__init__(training_config_path, lay_down_config_path) self.setup() @@ -195,10 +195,11 @@ class BenchmarkPrimaiteSession(PrimaiteSession): """Direct access to the env for ease of testing.""" return self._agent_session._env # noqa - def __enter__(self): + def __enter__(self) -> "BenchmarkPrimaiteSession": return self - def __exit__(self, type, value, tb): + # TODO: typehints uncertain + def __exit__(self, type: Any, value: Any, tb: Any) -> None: shutil.rmtree(self.session_path) _LOGGER.debug(f"Deleted benchmark session directory: {self.session_path}") @@ -285,7 +286,7 @@ def _build_benchmark_results_dict(start_datetime: datetime, metadata_dict: Dict) return averaged_data -def _get_df_from_episode_av_reward_dict(data: Dict): +def _get_df_from_episode_av_reward_dict(data: Dict) -> pl.DataFrame: data: Dict = {"episode": data.keys(), "av_reward": data.values()} return ( @@ -360,7 +361,7 @@ def _plot_benchmark_metadata( return fig -def _plot_all_benchmarks_combined_session_av(): +def _plot_all_benchmarks_combined_session_av() -> Figure: """ Plot the Benchmark results for each released version of PrimAITE. @@ -410,7 +411,7 @@ def _plot_all_benchmarks_combined_session_av(): return fig -def run(): +def run() -> NotImplementedError: """Run the PrimAITE benchmark.""" start_datetime = datetime.now() av_reward_per_episode_dicts = {} diff --git a/src/primaite/__init__.py b/src/primaite/__init__.py index a0f5b7fe..ad157c9c 100644 --- a/src/primaite/__init__.py +++ b/src/primaite/__init__.py @@ -24,14 +24,14 @@ class _PrimaitePaths: The PlatformDirs appname is 'primaite' and the version is ``primaite.__version__`. """ - def __init__(self): + def __init__(self) -> None: self._dirs: Final[PlatformDirs] = PlatformDirs(appname="primaite", version=__version__) def _get_dirs_properties(self) -> List[str]: class_items = self.__class__.__dict__.items() return [k for k, v in class_items if isinstance(v, property)] - def mkdirs(self): + def mkdirs(self) -> None: """ Creates all Primaite directories. @@ -102,7 +102,7 @@ class _PrimaitePaths: """The PrimAITE app log file path.""" return self.app_log_dir_path / "primaite.log" - def __repr__(self): + def __repr__(self) -> str: properties_str = ", ".join([f"{p}='{getattr(self, p)}'" for p in self._get_dirs_properties()]) return f"{self.__class__.__name__}({properties_str})" @@ -110,7 +110,7 @@ class _PrimaitePaths: PRIMAITE_PATHS: Final[_PrimaitePaths] = _PrimaitePaths() -def _host_primaite_config(): +def _host_primaite_config() -> None: if not PRIMAITE_PATHS.app_config_file_path.exists(): pkg_config_path = Path(pkg_resources.resource_filename("primaite", "setup/_package_data/primaite_config.yaml")) shutil.copy2(pkg_config_path, PRIMAITE_PATHS.app_config_file_path) diff --git a/src/primaite/environment/observations.py b/src/primaite/environment/observations.py index 383a9b5a..be80374b 100644 --- a/src/primaite/environment/observations.py +++ b/src/primaite/environment/observations.py @@ -443,7 +443,7 @@ class AccessControlList(AbstractObservationComponent): _DATA_TYPE: type = np.int64 - def __init__(self, env: "Primaite"): + def __init__(self, env: "Primaite") -> None: """ Initialise an AccessControlList observation component. From c1bb6d8b7f1a9654eff550334f8a8b938eace11e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 31 Jul 2023 17:09:38 +0100 Subject: [PATCH 036/980] Update the PR template --- .azuredevops/pull_request_template.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.azuredevops/pull_request_template.md b/.azuredevops/pull_request_template.md index 5ff03e18..fd28ed57 100644 --- a/.azuredevops/pull_request_template.md +++ b/.azuredevops/pull_request_template.md @@ -9,4 +9,5 @@ - [ ] I have performed **self-review** of the code - [ ] I have written **tests** for any new functionality added with this PR - [ ] I have updated the **documentation** if this PR changes or adds functionality +- [ ] I have written/updated **design docs** if this PR implements new functionality. - [ ] I have run **pre-commit** checks for code style From 3324a8caae84d25c1bd5e6948a00d70029f9e7b3 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 31 Jul 2023 18:54:29 +0000 Subject: [PATCH 037/980] Apply suggestions from code review --- benchmark/primaite_benchmark.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/primaite_benchmark.py b/benchmark/primaite_benchmark.py index 8a911720..9fec5711 100644 --- a/benchmark/primaite_benchmark.py +++ b/benchmark/primaite_benchmark.py @@ -411,7 +411,7 @@ def _plot_all_benchmarks_combined_session_av() -> Figure: return fig -def run() -> NotImplementedError: +def run() -> None: """Run the PrimAITE benchmark.""" start_datetime = datetime.now() av_reward_per_episode_dicts = {} From e4b6f266e8dd65c59e26455134b4a276a1fba028 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 31 Jul 2023 20:05:36 +0100 Subject: [PATCH 038/980] #1715 - Added timestep int as a param to the apply_timestep function in core.py. Also added a reset_component_for_episode function. Updated docs with details of Link and NIC. --- .../node_nic_link_component_diagram.png | Bin 0 -> 25394 bytes docs/index.rst | 1 - docs/source/simulation.rst | 17 +- .../network/physical_layer.rst | 75 +++++++++ docs/source/simulation_structure.rst | 13 ++ src/primaite/simulator/core.py | 12 +- .../simulator/network/physical_layer.py | 156 +++++++++--------- 7 files changed, 192 insertions(+), 82 deletions(-) create mode 100644 docs/_static/node_nic_link_component_diagram.png create mode 100644 docs/source/simulation_components/network/physical_layer.rst create mode 100644 docs/source/simulation_structure.rst diff --git a/docs/_static/node_nic_link_component_diagram.png b/docs/_static/node_nic_link_component_diagram.png new file mode 100644 index 0000000000000000000000000000000000000000..00a3d93985101dde616ad36e3d5ab0f0ee54b036 GIT binary patch literal 25394 zcmd43bx<5()Tc`b?hq^_Kp5PDy9F5B-Q7L7ThIZ52KV3++}$C#ySuyV?d-Sv)mClQ z-dnZ1wfB#%8K^X&d%F8Q=lMMch`g*ADiQ$_6ciMygg96cc&&qif=)ny2Hsg^UrPfo z?;I7ygrLesKOX>Jz?ccj2tq+sMj<~Nzye<*eizqpgn~lr{xv01GO+ z>7JyAXkkm-o!z}P+%?`c+Kql%9XV>+O>-RO68q+WCI91hAyv|QQ$b9|?4(}5-@jwA z$q=a&$na0i@)s+6R|&7{{h0TzBKT+6W@c0h+MExk8K+(rXbI!v;}_5!tEzTPn#y3xwF>tX;7;hznw!)*Otl_|*ws+v*ebu43SQtuV z;KO~w!{$}AL-?`z+zU2D$I6_Uo?hhf9K<4>4){4#T>DAfOI1m$d0?iwNs|oJB4VrS zV}5Un1;R|tI$WrZLp0lp%;0pOdtJeM!23{+@l~!d^>F7?p~GrkSs5DYxPDhS}f~^x5 zkkh;pzM|{a+PV*D-uUXDA6_V#s;RW*!Nr80Tz+{nnEaW_VYkMG?Py$#qUFKg5Et!VzvH###gn7MBb68@yvC zT3k+kPPf;cEe|zcn(?Lv-(S0V2{|1r)Ultn4G8!$DYT({X(0w-b|U>RZ!xC%g$-`* z1B)JdcrS(bRAgO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rXJ5cDydoAIW5KyJY_SBg=AOij>`9xgVC3YcEQ5AoddSI*(v3o}y^QXcAwdp4 z0*^4*3HA1tCubHCmAS%ywAUjVT&z0vBECpy545jHCkB{X_9_s=$?7asdBkcYrdvku zt`I9x^_WF(HXn%v*jHBU*7yvAuG1>>{(by*J(s3?o{dCbZ}Iwb;K+3aJ`OK8I)~wdl z0rQ^{UEj2_=5C26@{LH|BNeLt$)MEm!S`Y0Tev+`o+lUnD(AIUVQ3KJF%&pg)lK}j zqxL_l0R6Y;_CNg^$;cNkZdC;%{g3As>f+!Egtf-VfVsQjm(9L+i64qgoykLf999V2 znUmeNajd6%P93SLQ{jb=7lVWu;b0%%{irx#idp@+h-%8kZ+FPXVL&lq!tzu6H5OpU zA7aqjnx~b(pBf4snl6>lF2Kj(;Nz!1n5y#$te8B8wc;-He9xaP6~|g>=TFe_pkITk ro2K4Uzk1zADG`a?gwifNN9aeK>6&vrxd*@J;*z|K3bH`T*!RBx>Q?^3 literal 0 HcmV?d00001 diff --git a/docs/index.rst b/docs/index.rst index c0e7a007..a75dd8e5 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -36,7 +36,6 @@ Head over to the :ref:`getting-started` page to install and setup PrimAITE! .. toctree:: :maxdepth: 8 :caption: Contents: - :hidden: source/getting_started source/about diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index 1620f6ba..0af6c89f 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -2,9 +2,18 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -Simulation Strucutre -==================== -The simulation is made up of many smaller components which are related to each other in a tree-like structure. At the top level, there is an object called the ``SimulationController`` _(doesn't exist yet)_, which has a physical network and a software controller for managing software and users. +Simulation +========== -Each node of the simulation 'tree' has responsibility for creating, deleting, and updating its direct descendants. +.. TODO:: Add spiel here about what the simulation is. + + +Contents +######## + +.. toctree:: + :maxdepth: 8 + + simulation_structure + simulation_components/network/physical_layer diff --git a/docs/source/simulation_components/network/physical_layer.rst b/docs/source/simulation_components/network/physical_layer.rst new file mode 100644 index 00000000..2d942847 --- /dev/null +++ b/docs/source/simulation_components/network/physical_layer.rst @@ -0,0 +1,75 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +Physical Layer +============== + +The physical layer components are mode of a ``NIC`` (Network Interface Card) and a ``Link``. These components allow +modelling of layer 1 (physical layer) in the OSI model. + +NIC +### +The ``NIC`` class is a realistic model of a Network Interface Card. The ``NIC`` acts as the interface between the +``Node`` and the ``Link``. + +NICs have the following attributes: + +- **ip_address:** The IPv4 address assigned to the NIC. +- **subnet_mask:** The subnet mask assigned to the NIC. +- **gateway:** The default gateway IP address for forwarding network traffic to other networks. +- **mac_address:** The MAC address of the NIC. Defaults to a randomly set MAC address. +- **speed:** The speed of the NIC in Mbps (default is 100 Mbps). +- **mtu:** The Maximum Transmission Unit (MTU) of the NIC in Bytes, representing the largest data packet size it can handle without fragmentation (default is 1500 B). +- **wake_on_lan:** Indicates if the NIC supports Wake-on-LAN functionality. +- **dns_servers:** List of IP addresses of DNS servers used for name resolution. +- **connected_link:** The link to which the NIC is connected. +- **enabled:** Indicates whether the NIC is enabled. + +**Basic Example** + +.. code-block:: python + + nic1 = NIC( + ip_address="192.168.1.100", + subnet_mask="255.255.255.0", + gateway="192.168.1.1" + ) + +Link +#### + +The ``Link`` class represents a physical link between two network endpoints. + +Links have the following attributes: + +- **endpoint_a:** The first NIC connected to the Link. +- **endpoint_b:** The second NIC connected to the Link. +- **bandwidth:** The bandwidth of the Link in Mbps (default is 100 Mbps). +- **current_load:** The current load on the link in Mbps. + +**Basic Example** + +.. code-block:: python + + nic1 = NIC( + ip_address="192.168.1.100", + subnet_mask="255.255.255.0", + gateway="192.168.1.1" + ) + nic1 = NIC( + ip_address="192.168.1.101", + subnet_mask="255.255.255.0", + gateway="192.168.1.1" + ) + + link = Link( + endpoint_a=nic1, + endpoint_b=nic2, + bandwidth=1000 + ) + +Link, NIC, Node Interface +######################### + +.. image:: ../../../_static/node_nic_link_component_diagram.png diff --git a/docs/source/simulation_structure.rst b/docs/source/simulation_structure.rst new file mode 100644 index 00000000..65373a72 --- /dev/null +++ b/docs/source/simulation_structure.rst @@ -0,0 +1,13 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + + +Simulation Structure +==================== + +The simulation is made up of many smaller components which are related to each other in a tree-like structure. At the +top level, there is an object called the ``SimulationController`` _(doesn't exist yet)_, which has a physical network +and a software controller for managing software and users. + +Each node of the simulation 'tree' has responsibility for creating, deleting, and updating its direct descendants. diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 5b9bea1f..c3130116 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -37,7 +37,7 @@ class SimComponent(BaseModel): possible_actions = self._possible_actions() if action[0] in possible_actions: # take the first element off the action list and pass the remaining arguments to the corresponding action - # funciton + # function possible_actions[action.pop(0)](action) else: raise ValueError(f"{self.__class__.__name__} received invalid action {action}") @@ -45,7 +45,7 @@ class SimComponent(BaseModel): def _possible_actions(self) -> Dict[str, Callable[[List[str]], None]]: return {} - def apply_timestep(self) -> None: + def apply_timestep(self, timestep: int) -> None: """ Apply a timestep evolution to this component. @@ -53,3 +53,11 @@ class SimComponent(BaseModel): sending data. """ pass + + def reset_component_for_episode(self): + """ + Reset this component to its original state for a new episode. + + Override this method with anything that needs to happen within the component for it to be reset. + """ + pass diff --git a/src/primaite/simulator/network/physical_layer.py b/src/primaite/simulator/network/physical_layer.py index 6d268b59..2bc5c2b8 100644 --- a/src/primaite/simulator/network/physical_layer.py +++ b/src/primaite/simulator/network/physical_layer.py @@ -43,76 +43,6 @@ def generate_mac_address(oui: Optional[str] = None) -> str: return ":".join(f"{b:02x}" for b in mac) -class Link(SimComponent): - """ - Represents a network link between two network interface cards (NICs). - - :param endpoint_a: The first NIC connected to the Link. - :type endpoint_a: NIC - :param endpoint_b: The second NIC connected to the Link. - :type endpoint_b: NIC - :param bandwidth: The bandwidth of the Link in Mbps (default is 100 Mbps). - :type bandwidth: int - """ - - endpoint_a: NIC - endpoint_b: NIC - bandwidth: int = 100 - current_load: int = 0 - - def model_post_init(self, __context: Any) -> None: - """ - Ensure that endpoint_a and endpoint_b are not the same :class:`~primaite.simulator.network.physical_layer.NIC`. - - :raises ValueError: If endpoint_a and endpoint_b are the same NIC. - """ - if self.endpoint_a == self.endpoint_b: - msg = "endpoint_a and endpoint_b cannot be the same NIC" - _LOGGER.error(msg) - raise ValueError(msg) - self.endpoint_a.connect_link(self) - self.endpoint_b.connect_link(self) - - def send_frame(self, sender_nic: NIC, frame): - """ - Send a network frame from one NIC to another connected NIC. - - :param sender_nic: The NIC sending the frame. - :type sender_nic: NIC - :param frame: The network frame to be sent. - :type frame: Frame - """ - pass - - def receive_frame(self, sender_nic: NIC, frame): - """ - Receive a network frame from a connected NIC. - - :param sender_nic: The NIC sending the frame. - :type sender_nic: NIC - :param frame: The network frame being received. - :type frame: Frame - """ - pass - - def describe_state(self) -> Dict: - """ - Get the current state of the Libk as a dict. - - :return: A dict containing the current state of the Link. - """ - pass - - def apply_action(self, action: str): - """ - Apply an action to the Link. - - :param action: The action to be applied. - :type action: str - """ - pass - - class NIC(SimComponent): """ Models a Network Interface Card (NIC) in a computer or network device. @@ -121,13 +51,11 @@ class NIC(SimComponent): :param subnet_mask: The subnet mask assigned to the NIC. :param gateway: The default gateway IP address for forwarding network traffic to other networks. :param mac_address: The MAC address of the NIC. Defaults to a randomly set MAC address. - :param speed: The speed of the NIC in Mbps. + :param speed: The speed of the NIC in Mbps (default is 100 Mbps). :param mtu: The Maximum Transmission Unit (MTU) of the NIC in Bytes, representing the largest data packet size it - can handle without fragmentation. + can handle without fragmentation (default is 1500 B). :param wake_on_lan: Indicates if the NIC supports Wake-on-LAN functionality. :param dns_servers: List of IP addresses of DNS servers used for name resolution. - :param connected_link: The link to which the NIC is connected (default is None). - :param enabled: Indicates whether the NIC is enabled. """ ip_address: Union[str, IPv4Address] @@ -204,7 +132,11 @@ class NIC(SimComponent): def disconnect_link(self): """Disconnect the NIC from the connected :class:`~primaite.simulator.network.physical_layer.Link`.""" - pass + if self.connected_link.endpoint_a == self: + self.connected_link.endpoint_a = None + if self.connected_link.endpoint_b == self: + self.connected_link.endpoint_b = None + self.connected_link = None def add_dns_server(self, ip_address: IPv4Address): """ @@ -260,3 +192,77 @@ class NIC(SimComponent): :type action: str """ pass + + +class Link(SimComponent): + """ + Represents a network link between two network interface cards (NICs). + + :param endpoint_a: The first NIC connected to the Link. + :type endpoint_a: NIC + :param endpoint_b: The second NIC connected to the Link. + :type endpoint_b: NIC + :param bandwidth: The bandwidth of the Link in Mbps (default is 100 Mbps). + :type bandwidth: int + """ + + endpoint_a: NIC + "The first NIC connected to the Link." + endpoint_b: NIC + "The second NIC connected to the Link." + bandwidth: int = 100 + "The bandwidth of the Link in Mbps (default is 100 Mbps)." + current_load: int = 0 + "The current load on the link in Mbps." + + def model_post_init(self, __context: Any) -> None: + """ + Ensure that endpoint_a and endpoint_b are not the same :class:`~primaite.simulator.network.physical_layer.NIC`. + + :raises ValueError: If endpoint_a and endpoint_b are the same NIC. + """ + if self.endpoint_a == self.endpoint_b: + msg = "endpoint_a and endpoint_b cannot be the same NIC" + _LOGGER.error(msg) + raise ValueError(msg) + self.endpoint_a.connect_link(self) + self.endpoint_b.connect_link(self) + + def send_frame(self, sender_nic: NIC, frame): + """ + Send a network frame from one NIC to another connected NIC. + + :param sender_nic: The NIC sending the frame. + :type sender_nic: NIC + :param frame: The network frame to be sent. + :type frame: Frame + """ + pass + + def receive_frame(self, sender_nic: NIC, frame): + """ + Receive a network frame from a connected NIC. + + :param sender_nic: The NIC sending the frame. + :type sender_nic: NIC + :param frame: The network frame being received. + :type frame: Frame + """ + pass + + def describe_state(self) -> Dict: + """ + Get the current state of the Libk as a dict. + + :return: A dict containing the current state of the Link. + """ + pass + + def apply_action(self, action: str): + """ + Apply an action to the Link. + + :param action: The action to be applied. + :type action: str + """ + pass From 557caeaac4ec6ec155a8928689b60263b3440579 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 1 Aug 2023 08:19:28 +0100 Subject: [PATCH 039/980] #1715 - Added suppress-none-returning and suppress-dummy-args to .flake8 as flake8-annotations can get very annoying --- .flake8 | 2 ++ src/primaite/simulator/network/physical_layer.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.flake8 b/.flake8 index 6e653102..1f3c7065 100644 --- a/.flake8 +++ b/.flake8 @@ -14,3 +14,5 @@ extend-ignore = exclude = docs/source/* tests/* +suppress-none-returning=True +suppress-dummy-args=True diff --git a/src/primaite/simulator/network/physical_layer.py b/src/primaite/simulator/network/physical_layer.py index 2bc5c2b8..ebc0c788 100644 --- a/src/primaite/simulator/network/physical_layer.py +++ b/src/primaite/simulator/network/physical_layer.py @@ -156,7 +156,7 @@ class NIC(SimComponent): """ pass - def send_frame(self, frame): + def send_frame(self, frame: Any): """ Send a network frame from the NIC to the connected link. @@ -165,7 +165,7 @@ class NIC(SimComponent): """ pass - def receive_frame(self, frame): + def receive_frame(self, frame: Any): """ Receive a network frame from the connected link. @@ -228,7 +228,7 @@ class Link(SimComponent): self.endpoint_a.connect_link(self) self.endpoint_b.connect_link(self) - def send_frame(self, sender_nic: NIC, frame): + def send_frame(self, sender_nic: NIC, frame: Any): """ Send a network frame from one NIC to another connected NIC. @@ -239,7 +239,7 @@ class Link(SimComponent): """ pass - def receive_frame(self, sender_nic: NIC, frame): + def receive_frame(self, sender_nic: NIC, frame: Any): """ Receive a network frame from a connected NIC. From 5ebbfab0ff738ccf35ede644d598f1551ed418ec Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 1 Aug 2023 10:02:13 +0100 Subject: [PATCH 040/980] Create some files for domain sim --- src/primaite/simulator/domain_controller/__init__.py | 0 src/primaite/simulator/domain_controller/account.py | 8 ++++++++ 2 files changed, 8 insertions(+) create mode 100644 src/primaite/simulator/domain_controller/__init__.py create mode 100644 src/primaite/simulator/domain_controller/account.py diff --git a/src/primaite/simulator/domain_controller/__init__.py b/src/primaite/simulator/domain_controller/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/domain_controller/account.py b/src/primaite/simulator/domain_controller/account.py new file mode 100644 index 00000000..1f3ac900 --- /dev/null +++ b/src/primaite/simulator/domain_controller/account.py @@ -0,0 +1,8 @@ +"""User account simulation.""" +from primaite.simulator.core import SimComponent + + +class Account(SimComponent): + """User accounts.""" + + uid: int From 8785089a1c0f8bd8edc32a28838036713ceaccbd Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 1 Aug 2023 10:32:16 +0100 Subject: [PATCH 041/980] #1715 - Moved IPv4Address conversions to the NIC init. Mak wake_on_lan not optional. Ignored ANN002 and ANN003 in .flake8 so we don't get silly 'ANN002 Missing type annotation for *args' and 'ANN003 Missing type annotation for **kwargs' flake8 failures --- .flake8 | 2 ++ .../network/physical_layer.rst | 2 +- .../simulator/network/physical_layer.py | 25 +++++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.flake8 b/.flake8 index 1f3c7065..c2d9e4bb 100644 --- a/.flake8 +++ b/.flake8 @@ -9,6 +9,8 @@ extend-ignore = E712 D401 F811 + ANN002 + ANN003 ANN101 ANN102 exclude = diff --git a/docs/source/simulation_components/network/physical_layer.rst b/docs/source/simulation_components/network/physical_layer.rst index 2d942847..1e87b72e 100644 --- a/docs/source/simulation_components/network/physical_layer.rst +++ b/docs/source/simulation_components/network/physical_layer.rst @@ -5,7 +5,7 @@ Physical Layer ============== -The physical layer components are mode of a ``NIC`` (Network Interface Card) and a ``Link``. These components allow +The physical layer components are models of a ``NIC`` (Network Interface Card) and a ``Link``. These components allow modelling of layer 1 (physical layer) in the OSI model. NIC diff --git a/src/primaite/simulator/network/physical_layer.py b/src/primaite/simulator/network/physical_layer.py index ebc0c788..b709fd0a 100644 --- a/src/primaite/simulator/network/physical_layer.py +++ b/src/primaite/simulator/network/physical_layer.py @@ -58,11 +58,11 @@ class NIC(SimComponent): :param dns_servers: List of IP addresses of DNS servers used for name resolution. """ - ip_address: Union[str, IPv4Address] + ip_address: Union[IPv4Address] "The IP address assigned to the NIC for communication on an IP-based network." subnet_mask: str "The subnet mask assigned to the NIC." - gateway: Union[str, IPv4Address] + gateway: Union[IPv4Address] "The default gateway IP address for forwarding network traffic to other networks. Randomly generated upon creation." mac_address: str = generate_mac_address() "The MAC address of the NIC. Defaults to a randomly set MAC address." @@ -70,7 +70,7 @@ class NIC(SimComponent): "The speed of the NIC in Mbps. Default is 100 Mbps." mtu: Optional[int] = 1500 "The Maximum Transmission Unit (MTU) of the NIC in Bytes. Default is 1500 B" - wake_on_lan: Optional[bool] = False + wake_on_lan: bool = False "Indicates if the NIC supports Wake-on-LAN functionality." dns_servers: List[IPv4Address] = [] "List of IP addresses of DNS servers used for name resolution." @@ -79,17 +79,22 @@ class NIC(SimComponent): enabled: bool = False "Indicates whether the NIC is enabled." - def model_post_init(self, __context: Any) -> None: + def __init__(self, **kwargs): """ - Post init function converts string IPs to IPv$Address and checks for proper IP address and gateway config. + NIC constructor. + + Performs some type conversion the calls ``super().__init__()``. Then performs some checking on the ip_address + and gateway just to check that it's all been configured correctly. :raises ValueError: When the ip_address and gateway are the same. And when the ip_address/subnet mask are a - network address. + network address. """ - if not isinstance(self.ip_address, IPv4Address): - self.ip_address: IPv4Address = IPv4Address(self.ip_address) - if not isinstance(self.gateway, IPv4Address): - self.gateway: IPv4Address = IPv4Address(self.gateway) + if not isinstance(kwargs["ip_address"], IPv4Address): + kwargs["ip_address"] = IPv4Address(kwargs["ip_address"]) + if not isinstance(kwargs["gateway"], IPv4Address): + kwargs["gateway"] = IPv4Address(kwargs["gateway"]) + super().__init__(**kwargs) + if self.ip_address == self.gateway: msg = f"NIC ip address {self.ip_address} cannot be the same as the gateway {self.gateway}" _LOGGER.error(msg) From 2769b1bfb1b3c53b9500defe47edf32a9f97265b Mon Sep 17 00:00:00 2001 From: Christopher McCarthy Date: Tue, 1 Aug 2023 11:04:16 +0000 Subject: [PATCH 042/980] Apply suggestions from code review --- src/primaite/simulator/network/physical_layer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/network/physical_layer.py b/src/primaite/simulator/network/physical_layer.py index b709fd0a..dfe54ded 100644 --- a/src/primaite/simulator/network/physical_layer.py +++ b/src/primaite/simulator/network/physical_layer.py @@ -58,11 +58,11 @@ class NIC(SimComponent): :param dns_servers: List of IP addresses of DNS servers used for name resolution. """ - ip_address: Union[IPv4Address] + ip_address: IPv4Address "The IP address assigned to the NIC for communication on an IP-based network." subnet_mask: str "The subnet mask assigned to the NIC." - gateway: Union[IPv4Address] + gateway: IPV4Address "The default gateway IP address for forwarding network traffic to other networks. Randomly generated upon creation." mac_address: str = generate_mac_address() "The MAC address of the NIC. Defaults to a randomly set MAC address." From 5ee3eff0e92e0222c4677a46544d41b199efb620 Mon Sep 17 00:00:00 2001 From: Christopher McCarthy Date: Tue, 1 Aug 2023 11:14:36 +0000 Subject: [PATCH 043/980] Apply suggestions from code review --- src/primaite/simulator/network/physical_layer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/network/physical_layer.py b/src/primaite/simulator/network/physical_layer.py index dfe54ded..aab98dc0 100644 --- a/src/primaite/simulator/network/physical_layer.py +++ b/src/primaite/simulator/network/physical_layer.py @@ -66,9 +66,9 @@ class NIC(SimComponent): "The default gateway IP address for forwarding network traffic to other networks. Randomly generated upon creation." mac_address: str = generate_mac_address() "The MAC address of the NIC. Defaults to a randomly set MAC address." - speed: Optional[int] = 100 + speed: int = 100 "The speed of the NIC in Mbps. Default is 100 Mbps." - mtu: Optional[int] = 1500 + mtu: int = 1500 "The Maximum Transmission Unit (MTU) of the NIC in Bytes. Default is 1500 B" wake_on_lan: bool = False "Indicates if the NIC supports Wake-on-LAN functionality." From 0f33b837aa3785d38d8e9b37553ecaa08b285dba Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 1 Aug 2023 12:45:36 +0100 Subject: [PATCH 044/980] #1715 - Fixed up pr code suggestion flake8 issues --- src/primaite/simulator/network/physical_layer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/network/physical_layer.py b/src/primaite/simulator/network/physical_layer.py index aab98dc0..20fae4c1 100644 --- a/src/primaite/simulator/network/physical_layer.py +++ b/src/primaite/simulator/network/physical_layer.py @@ -3,7 +3,7 @@ from __future__ import annotations import re import secrets from ipaddress import IPv4Address, IPv4Network -from typing import Any, Dict, List, Optional, Union +from typing import Any, Dict, List, Optional from primaite import getLogger from primaite.exceptions import NetworkError @@ -62,7 +62,7 @@ class NIC(SimComponent): "The IP address assigned to the NIC for communication on an IP-based network." subnet_mask: str "The subnet mask assigned to the NIC." - gateway: IPV4Address + gateway: IPv4Address "The default gateway IP address for forwarding network traffic to other networks. Randomly generated upon creation." mac_address: str = generate_mac_address() "The MAC address of the NIC. Defaults to a randomly set MAC address." From ea8c65a17e972af1ac0c6a1334c7d391a39f9065 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 1 Aug 2023 16:18:49 +0100 Subject: [PATCH 045/980] #1714: set up files --- .azure/azure-ci-build-pipeline.yaml | 2 +- src/primaite/simulator/core.py | 2 +- .../simulator/file_system}/__init__.py | 0 .../simulator/file_system/file_system.py | 77 +++++++++++++++++++ .../simulator/file_system/file_system_file.py | 34 ++++++++ .../file_system/file_system_file_type.py | 7 ++ .../file_system/file_system_folder.py | 41 ++++++++++ .../file_system/file_system_item_abc.py | 60 +++++++++++++++ tests/conftest.py | 4 +- .../simulator => _primaite}/__init__.py | 0 .../_primaite/_simulator/__init__.py | 0 .../_simulator/_file_system/__init__.py | 0 .../_file_system/test_file_system.py | 0 .../_file_system/test_file_system_file.py | 0 .../_file_system/test_file_system_folder.py | 0 .../_simulator}/test_core.py | 0 16 files changed, 223 insertions(+), 4 deletions(-) rename {tests/unit_tests/primaite => src/primaite/simulator/file_system}/__init__.py (100%) create mode 100644 src/primaite/simulator/file_system/file_system.py create mode 100644 src/primaite/simulator/file_system/file_system_file.py create mode 100644 src/primaite/simulator/file_system/file_system_file_type.py create mode 100644 src/primaite/simulator/file_system/file_system_folder.py create mode 100644 src/primaite/simulator/file_system/file_system_item_abc.py rename tests/unit_tests/{primaite/simulator => _primaite}/__init__.py (100%) create mode 100644 tests/unit_tests/_primaite/_simulator/__init__.py create mode 100644 tests/unit_tests/_primaite/_simulator/_file_system/__init__.py create mode 100644 tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py create mode 100644 tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py create mode 100644 tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py rename tests/unit_tests/{primaite/simulator => _primaite/_simulator}/test_core.py (100%) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 0bb03594..9070270a 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -86,5 +86,5 @@ stages: displayName: 'Perform PrimAITE Setup' - script: | - pytest -n 4 + pytest -n auto displayName: 'Run tests' diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 5b9bea1f..fce192c7 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -6,7 +6,7 @@ from pydantic import BaseModel class SimComponent(BaseModel): - """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" + """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" @abstractmethod def describe_state(self) -> Dict: diff --git a/tests/unit_tests/primaite/__init__.py b/src/primaite/simulator/file_system/__init__.py similarity index 100% rename from tests/unit_tests/primaite/__init__.py rename to src/primaite/simulator/file_system/__init__.py diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py new file mode 100644 index 00000000..f467595d --- /dev/null +++ b/src/primaite/simulator/file_system/file_system.py @@ -0,0 +1,77 @@ +from typing import Dict, List, Union + +from primaite.simulator.core import SimComponent +from primaite.simulator.file_system.file_system_file import FileSystemFile +from primaite.simulator.file_system.file_system_folder import FileSystemFolder + + +class FileSystem(SimComponent): + """Class that contains all the simulation File System.""" + + files: List[FileSystemFile] + """List containing all the files in the file system.""" + + folders: List[FileSystemFolder] + """List containing all the folders in the file system.""" + + def describe_state(self) -> Dict: + """ + Get the current state of the FileSystem as a dict. + + :return: A dict containing the current state of the FileSystemFile. + """ + pass + + def create_file(self): + """Creates a FileSystemFile and adds it to the list of files.""" + pass + + def create_folder(self): + """Creates a FileSystemFolder and adds it to the list of folders.""" + pass + + def delete_file(self, file_item: str): + """ + Deletes a file and removes it from the files list. + + :param file_item: The UUID of the file item to delete + :type file_item: str + """ + self.files = list(filter(lambda x: (x.get_item_uuid() != file_item), self.files)) + + def delete_folder(self, file_item: str): + """ + Deletes a folder, removes it frdom the folders list and removes any child folders and files. + + :param file_item: The UUID of the file item to delete + :type file_item: str + """ + self.files = list(filter(lambda x: (x.get_item_parent() != file_item), self.files)) + self.folders = list(filter(lambda x: (x.get_item_uuid() != file_item), self.folders)) + + def move_file_item(self, file_item: str, target_directory: str): + """ + Check to see if the file_item and target_directory exists then moves the item by changing its parent item uuid. + + :param file_item: The UUID of the file item to move + :type file_item: str + + :param target_directory: The UUID of the directory the item should be moved into + :type target_directory: str + """ + item = self._file_item_exists(file_item) + if item and any(f for f in self.folders if f.get_item_uuid() == target_directory): + item.move(target_directory) + + def _file_item_exists(self, file_item_uuid: str) -> Union[FileSystemFile, FileSystemFolder, None]: + """Returns true if the file or folder UUID exists.""" + item = next((x for x in self.files if x.get_item_uuid() == file_item_uuid), None) + if item: + return item + + next((x for x in self.folders if x.get_item_uuid() == file_item_uuid), None) + + if item: + return item + + raise Exception(f"No file or folder found with id: {file_item_uuid}") diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py new file mode 100644 index 00000000..ee4fe1e5 --- /dev/null +++ b/src/primaite/simulator/file_system/file_system_file.py @@ -0,0 +1,34 @@ +from typing import Dict + +from primaite.simulator.file_system.file_system_file_type import FileSystemFileType +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC + + +class FileSystemFile(FileSystemItemABC): + """Class that represents a file in the simulation.""" + + _file_type: FileSystemFileType + """The type of the FileSystemFile""" + + def get_file_type(self) -> FileSystemFileType: + """Returns the FileSystemFileType of the file.""" + return self._file_type + + def move(self, target_directory: str): + """ + Changes the parent_item of the FileSystemFile. + + Essentially simulates the file system item being moved from folder to folder + + :param target_directory: The UUID of the directory the file system item should be moved to + :type target_directory: str + """ + super().move(target_directory) + + def describe_state(self) -> Dict: + """ + Get the current state of the FileSystemFile as a dict. + + :return: A dict containing the current state of the FileSystemFile. + """ + pass diff --git a/src/primaite/simulator/file_system/file_system_file_type.py b/src/primaite/simulator/file_system/file_system_file_type.py new file mode 100644 index 00000000..134b38f4 --- /dev/null +++ b/src/primaite/simulator/file_system/file_system_file_type.py @@ -0,0 +1,7 @@ +from enum import Enum + + +class FileSystemFileType(str, Enum): + """Enum used to determine the FileSystemFile type.""" + + TBD = "TBD" diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py new file mode 100644 index 00000000..41b9e1dd --- /dev/null +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -0,0 +1,41 @@ +from typing import Dict + +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC + + +class FileSystemFolder(FileSystemItemABC): + """Simulation FileSystemFolder.""" + + _is_quarantined: bool + """Flag that marks the folder as quarantined if true.""" + + def quarantine(self): + """Quarantines the File System Folder.""" + self._is_quarantined = True + + def end_quarantine(self): + """Ends the quarantine of the File System Folder.""" + self._is_quarantined = False + + def quarantine_status(self) -> bool: + """Returns true if the folder is being quarantined.""" + return self._is_quarantined + + def move(self, target_directory: str): + """ + Changes the parent_item of the file system item. + + Essentially simulates the file system item being moved from folder to folder + + :param target_directory: The UUID of the directory the file system item should be moved to + :type target_directory: str + """ + super().move(target_directory) + + def describe_state(self) -> Dict: + """ + Get the current state of the FileSystemFolder as a dict. + + :return: A dict containing the current state of the FileSystemFile. + """ + pass diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py new file mode 100644 index 00000000..11a3f858 --- /dev/null +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -0,0 +1,60 @@ +from abc import ABC, abstractmethod +from uuid import uuid4 + +from primaite.simulator.core import SimComponent + + +class FileSystemItemABC(SimComponent, ABC): + """Abstract Base class for any file system items e.g. files and folders.""" + + _uuid: str + """Unique identifier for the FileSystemItem""" + + _parent_item: str + """UUID of the parent FileSystemItem""" + + _item_size: float + """Disk size of the FileSystemItem""" + + def __init__(self, parent_item: str, item_size: float): + """ + Abstract base class used by FileSystem items. + + :param parent_item: The UUID of the FileSystemItem parent + :type parent_item: str + + :param item_size: The size of the FileSystemItem + :type item_size: float + """ + super().__init__() + + # generate random uuid for file system item + self._uuid = str(uuid4()) + + self._parent_item = parent_item + + self._item_size = item_size + + def get_item_uuid(self) -> str: + """Returns the file system item UUID.""" + return self._uuid + + def get_item_parent(self) -> str: + """Returns the UUID of the item's parent.""" + return self._parent_item + + def get_item_size(self) -> float: + """Returns the item size.""" + return self._item_size + + @abstractmethod + def move(self, target_directory: str): + """ + Changes the parent_item of the file system item. + + Essentially simulates the file system item being moved from folder to folder + + :param target_directory: The UUID of the directory the file system item should be moved to + :type target_directory: str + """ + self._parent_item = target_directory diff --git a/tests/conftest.py b/tests/conftest.py index f40b0b94..8102050e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -96,7 +96,7 @@ def temp_primaite_session(request): """ training_config_path = request.param[0] lay_down_config_path = request.param[1] - with patch("primaite.agents.agent_abc.get_session_path", get_temp_session_path) as mck: + with patch("_primaite.agents.agent_abc.get_session_path", get_temp_session_path) as mck: mck.session_timestamp = datetime.now() return TempPrimaiteSession(training_config_path, lay_down_config_path) @@ -112,7 +112,7 @@ def temp_session_path() -> Path: session_timestamp = datetime.now() date_dir = session_timestamp.strftime("%Y-%m-%d") session_path = session_timestamp.strftime("%Y-%m-%d_%H-%M-%S") - session_path = Path(tempfile.gettempdir()) / "primaite" / date_dir / session_path + session_path = Path(tempfile.gettempdir()) / "_primaite" / date_dir / session_path session_path.mkdir(exist_ok=True, parents=True) return session_path diff --git a/tests/unit_tests/primaite/simulator/__init__.py b/tests/unit_tests/_primaite/__init__.py similarity index 100% rename from tests/unit_tests/primaite/simulator/__init__.py rename to tests/unit_tests/_primaite/__init__.py diff --git a/tests/unit_tests/_primaite/_simulator/__init__.py b/tests/unit_tests/_primaite/_simulator/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/__init__.py b/tests/unit_tests/_primaite/_simulator/_file_system/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/primaite/simulator/test_core.py b/tests/unit_tests/_primaite/_simulator/test_core.py similarity index 100% rename from tests/unit_tests/primaite/simulator/test_core.py rename to tests/unit_tests/_primaite/_simulator/test_core.py From 9d17a9b0d3f4548423510f7c65a4e1f6a5aaaace Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 1 Aug 2023 22:25:00 +0100 Subject: [PATCH 046/980] #1724 - Added the primaite/simulator/network/transmission sub-package with modules for each layer. They come together to build a minimal but fairly realistic network Frame. A custom PrimaiteHeader has been included to hold primaite specific metadata required in transmission for reward function and RL agent downstream. Added some basic tests that check the proper configuration of Frames with matching headers for protocols. Updated the frame typehints in NIC and Link classes. --- .../network/transmission/__init__.py | 0 .../network/transmission/data_link_layer.py | 100 +++++++++ .../network/transmission/network_layer.py | 194 ++++++++++++++++++ .../{ => transmission}/physical_layer.py | 15 +- .../network/transmission/primaite_layer.py | 40 ++++ .../network/transmission/transport_layer.py | 119 +++++++++++ .../network/test_nic_link_connection.py | 2 +- .../_network/_transmission/__init__.py | 0 .../_transmission/test_data_link_layer.py | 90 ++++++++ .../_transmission/test_network_layer.py | 24 +++ .../test_physical_layer.py | 2 +- 11 files changed, 577 insertions(+), 9 deletions(-) create mode 100644 src/primaite/simulator/network/transmission/__init__.py create mode 100644 src/primaite/simulator/network/transmission/data_link_layer.py create mode 100644 src/primaite/simulator/network/transmission/network_layer.py rename src/primaite/simulator/network/{ => transmission}/physical_layer.py (94%) create mode 100644 src/primaite/simulator/network/transmission/primaite_layer.py create mode 100644 src/primaite/simulator/network/transmission/transport_layer.py create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_transmission/__init__.py create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py rename tests/unit_tests/_primaite/_simulator/_network/{ => _transmission}/test_physical_layer.py (95%) diff --git a/src/primaite/simulator/network/transmission/__init__.py b/src/primaite/simulator/network/transmission/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py new file mode 100644 index 00000000..e8133f86 --- /dev/null +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -0,0 +1,100 @@ +from typing import Any, Optional + +from pydantic import BaseModel + +from primaite import getLogger +from primaite.simulator.network.transmission.network_layer import ICMPHeader, IPPacket, IPProtocol +from primaite.simulator.network.transmission.primaite_layer import PrimaiteHeader +from primaite.simulator.network.transmission.transport_layer import TCPHeader, UDPHeader + +_LOGGER = getLogger(__name__) + + +class EthernetHeader(BaseModel): + """ + Represents the Ethernet layer of a network frame. + + :param src_mac_addr: Source MAC address. + :param dst_mac_addr: Destination MAC address. + + :Example: + + >>> ethernet = EthernetHeader( + ... src_mac_addr='AA:BB:CC:DD:EE:FF', + ... dst_mac_addr='11:22:33:44:55:66' + ... ) + """ + + src_mac_addr: str + "Source MAC address." + dst_mac_addr: str + "Destination MAC address." + + +class Frame(BaseModel): + """ + Represents a complete network frame with all layers. + + :param ethernet: Ethernet layer. + :param ip: IP layer. + :param tcp: TCP layer. + :param payload: Payload data in the frame. + + :Example: + + >>> from ipaddress import IPv4Address + >>> frame=Frame( + ... ethernet=EthernetHeader( + ... src_mac_addr='AA:BB:CC:DD:EE:FF', + ... dst_mac_addr='11:22:33:44:55:66' + ... ), + ... ip=IPPacket( + ... src_ip=IPv4Address('192.168.0.1'), + ... dst_ip=IPv4Address('10.0.0.1'), + ... ), + ... tcp=TCPHeader( + ... src_port=8080, + ... dst_port=80, + ... ), + ... payload=b"Hello, World!" + ... ) + """ + + def __init__(self, **kwargs): + if kwargs.get("tcp") and kwargs.get("udp"): + msg = "Network Frame cannot have both a TCP header and a UDP header" + _LOGGER.error(msg) + raise ValueError(msg) + if kwargs["ip"].protocol == IPProtocol.TCP and not kwargs.get("tcp"): + msg = "Cannot build a Frame using the TCP IP Protocol without a TCPHeader" + _LOGGER.error(msg) + raise ValueError(msg) + if kwargs["ip"].protocol == IPProtocol.UDP and not kwargs.get("UDP"): + msg = "Cannot build a Frame using the UDP IP Protocol without a UDPHeader" + _LOGGER.error(msg) + raise ValueError(msg) + if kwargs["ip"].protocol == IPProtocol.ICMP and not kwargs.get("icmp"): + msg = "Cannot build a Frame using the ICMP IP Protocol without a ICMPHeader" + _LOGGER.error(msg) + raise ValueError(msg) + super().__init__(**kwargs) + + ethernet: EthernetHeader + "Ethernet header." + ip: IPPacket + "IP packet." + tcp: Optional[TCPHeader] = None + "TCP header." + udp: Optional[UDPHeader] = None + "UDP header." + icmp: Optional[ICMPHeader] = None + "ICMP header." + primaite_header: PrimaiteHeader = PrimaiteHeader() + "PrimAITE header." + payload: Optional[Any] = None + "Raw data payload." + + @property + def size(self) -> int: + """The size of the Frame in Bytes.""" + return len(self.model_dump_json().encode("utf-8")) diff --git a/src/primaite/simulator/network/transmission/network_layer.py b/src/primaite/simulator/network/transmission/network_layer.py new file mode 100644 index 00000000..69b682cc --- /dev/null +++ b/src/primaite/simulator/network/transmission/network_layer.py @@ -0,0 +1,194 @@ +import secrets +from enum import Enum +from ipaddress import IPv4Address +from typing import Union + +from pydantic import BaseModel, field_validator, validate_call +from pydantic_core.core_schema import FieldValidationInfo + +from primaite import getLogger + +_LOGGER = getLogger(__name__) + + +class IPProtocol(Enum): + """Enum representing transport layer protocols in IP header.""" + + TCP = "tcp" + UDP = "udp" + ICMP = "icmp" + + +class Precedence(Enum): + """ + Enum representing the Precedence levels in Quality of Service (QoS) for IP packets. + + Precedence values range from 0 to 7, indicating different levels of priority. + + Members: + - ROUTINE: 0 - Lowest priority level, used for ordinary data traffic that does not require special treatment. + - PRIORITY: 1 - Higher priority than ROUTINE, used for traffic that needs a bit more importance. + - IMMEDIATE: 2 - Used for more urgent traffic that requires immediate handling and minimal delay. + - FLASH: 3 - Used for highly urgent and important traffic that should be processed with high priority. + - FLASH_OVERRIDE: 4 - Higher priority than FLASH, used for critical traffic that takes precedence over most traffic. + - CRITICAL: 5 - Reserved for critical commands or control messages that are vital to the operation of the network. + - INTERNET: 6 - Used for network control messages, such as routing updates, for maintaining network operations. + - NETWORK: 7 - Highest priority for the most critical network control messages, such as routing protocol hellos. + """ + + ROUTINE = 0 + "Lowest priority level, used for ordinary data traffic that does not require special treatment." + PRIORITY = 1 + "Higher priority than ROUTINE, used for traffic that needs a bit more importance." + IMMEDIATE = 2 + "Used for more urgent traffic that requires immediate handling and minimal delay." + FLASH = 3 + "Used for highly urgent and important traffic that should be processed with high priority." + FLASH_OVERRIDE = 4 + "Has higher priority than FLASH, used for critical traffic that takes precedence over most other traffic." + CRITICAL = 5 + "Reserved for critical commands or emergency control messages that are vital to the operation of the network." + INTERNET = 6 + "Used for network control messages, such as routing updates, essential for maintaining network operations." + NETWORK = 7 + "Highest priority level, used for the most critical network control messages, such as routing protocol hellos." + + +class ICMPType(Enum): + """Enumeration of common ICMP (Internet Control Message Protocol) types.""" + + ECHO_REPLY = 0 + "Echo Reply message." + DESTINATION_UNREACHABLE = 3 + "Destination Unreachable." + REDIRECT = 5 + "Redirect." + ECHO_REQUEST = 8 + "Echo Request (ping)." + ROUTER_ADVERTISEMENT = 10 + "Router Advertisement." + ROUTER_SOLICITATION = 11 + "Router discovery/selection/solicitation." + TIME_EXCEEDED = 11 + "Time Exceeded." + TIMESTAMP_REQUEST = 13 + "Timestamp Request." + TIMESTAMP_REPLY = 14 + "Timestamp Reply." + + +@validate_call +def get_icmp_type_code_description(icmp_type: ICMPType, icmp_code: int) -> Union[str, None]: + """ + Maps ICMPType and code pairings to their respective description. + + :param icmp_type: An ICMPType. + :param icmp_code: An icmp code. + :return: The icmp type and code pairing description if it exists, otherwise returns None. + """ + icmp_code_descriptions = { + ICMPType.ECHO_REPLY: {0: "Echo reply"}, + ICMPType.DESTINATION_UNREACHABLE: { + 0: "Destination network unreachable", + 1: "Destination host unreachable", + 2: "Destination protocol unreachable", + 3: "Destination port unreachable", + 4: "Fragmentation required", + 5: "Source route failed", + 6: "Destination network unknown", + 7: "Destination host unknown", + 8: "Source host isolated", + 9: "Network administratively prohibited", + 10: "Host administratively prohibited", + 11: "Network unreachable for ToS", + 12: "Host unreachable for ToS", + 13: "Communication administratively prohibited", + 14: "Host Precedence Violation", + 15: "Precedence cutoff in effect", + }, + ICMPType.REDIRECT: { + 0: "Redirect Datagram for the Network", + 1: "Redirect Datagram for the Host", + }, + ICMPType.ECHO_REQUEST: {0: "Echo request"}, + ICMPType.ROUTER_ADVERTISEMENT: {0: "Router Advertisement"}, + ICMPType.ROUTER_SOLICITATION: {0: "Router discovery/selection/solicitation"}, + ICMPType.TIME_EXCEEDED: {0: "TTL expired in transit", 1: "Fragment reassembly time exceeded"}, + ICMPType.TIMESTAMP_REQUEST: {0: "Timestamp Request"}, + ICMPType.TIMESTAMP_REPLY: {0: "Timestamp reply"}, + } + return icmp_code_descriptions[icmp_type].get(icmp_code) + + +class ICMPHeader(BaseModel): + """Models an ICMP Header.""" + + icmp_type: ICMPType = ICMPType.ECHO_REQUEST + "ICMP Type." + icmp_code: int = 0 + "ICMP Code." + identifier: str = secrets.randbits(16) + "ICMP identifier (16 bits randomly generated)." + sequence: int = 1 + "ICMP message sequence number." + + @field_validator("icmp_code") # noqa + @classmethod + def _icmp_type_must_have_icmp_code(cls, v: int, info: FieldValidationInfo) -> int: + """Validates the icmp_type and icmp_code.""" + icmp_type = info.data["icmp_type"] + if get_icmp_type_code_description(icmp_type, v): + return v + msg = f"No Matching ICMP code for type:{icmp_type.name}, code:{v}" + _LOGGER.error(msg) + raise ValueError(msg) + + def code_description(self) -> str: + """The icmp_code description.""" + description = get_icmp_type_code_description(self.icmp_type, self.icmp_code) + if description: + return description + msg = f"No Matching ICMP code for type:{self.icmp_type.name}, code:{self.icmp_code}" + _LOGGER.error(msg) + raise ValueError(msg) + + +class IPPacket(BaseModel): + """ + Represents the IP layer of a network frame. + + :param src_ip: Source IP address. + :param dst_ip: Destination IP address. + :param protocol: The IP protocol (default is TCP). + :param ttl: Time to Live (TTL) for the packet. + :param precedence: Precedence level for Quality of Service (QoS). + + :Example: + + >>> from ipaddress import IPv4Address + >>> ip_packet = IPPacket( + ... src_ip=IPv4Address('192.168.0.1'), + ... dst_ip=IPv4Address('10.0.0.1'), + ... protocol=IPProtocol.TCP, + ... ttl=64, + ... precedence=Precedence.CRITICAL + ... ) + """ + + src_ip: IPv4Address + "Source IP address." + dst_ip: IPv4Address + "Destination IP address." + protocol: IPProtocol = IPProtocol.TCP + "IPProtocol." + ttl: int = 64 + "Time to Live (TTL) for the packet." + precedence: Precedence = Precedence.ROUTINE + "Precedence level for Quality of Service (default is Precedence.ROUTINE)." + + def __init__(self, **kwargs): + if not isinstance(kwargs["src_ip"], IPv4Address): + kwargs["src_ip"] = IPv4Address(kwargs["src_ip"]) + if not isinstance(kwargs["dst_ip"], IPv4Address): + kwargs["dst_ip"] = IPv4Address(kwargs["dst_ip"]) + super().__init__(**kwargs) diff --git a/src/primaite/simulator/network/physical_layer.py b/src/primaite/simulator/network/transmission/physical_layer.py similarity index 94% rename from src/primaite/simulator/network/physical_layer.py rename to src/primaite/simulator/network/transmission/physical_layer.py index 20fae4c1..2fbfbc6b 100644 --- a/src/primaite/simulator/network/physical_layer.py +++ b/src/primaite/simulator/network/transmission/physical_layer.py @@ -8,6 +8,7 @@ from typing import Any, Dict, List, Optional from primaite import getLogger from primaite.exceptions import NetworkError from primaite.simulator.core import SimComponent +from primaite.simulator.network.transmission.data_link_layer import Frame _LOGGER = getLogger(__name__) @@ -121,7 +122,7 @@ class NIC(SimComponent): Connect the NIC to a link. :param link: The link to which the NIC is connected. - :type link: :class:`~primaite.simulator.network.physical_layer.Link` + :type link: :class:`~primaite.simulator.network.transmission.physical_layer.Link` :raise NetworkError: When an attempt to connect a Link is made while the NIC has a connected Link. """ if not self.connected_link: @@ -136,7 +137,7 @@ class NIC(SimComponent): raise NetworkError(msg) def disconnect_link(self): - """Disconnect the NIC from the connected :class:`~primaite.simulator.network.physical_layer.Link`.""" + """Disconnect the NIC from the connected Link.""" if self.connected_link.endpoint_a == self: self.connected_link.endpoint_a = None if self.connected_link.endpoint_b == self: @@ -161,7 +162,7 @@ class NIC(SimComponent): """ pass - def send_frame(self, frame: Any): + def send_frame(self, frame: Frame): """ Send a network frame from the NIC to the connected link. @@ -170,7 +171,7 @@ class NIC(SimComponent): """ pass - def receive_frame(self, frame: Any): + def receive_frame(self, frame: Frame): """ Receive a network frame from the connected link. @@ -222,7 +223,7 @@ class Link(SimComponent): def model_post_init(self, __context: Any) -> None: """ - Ensure that endpoint_a and endpoint_b are not the same :class:`~primaite.simulator.network.physical_layer.NIC`. + Ensure that endpoint_a and endpoint_b are not the same NIC. :raises ValueError: If endpoint_a and endpoint_b are the same NIC. """ @@ -233,7 +234,7 @@ class Link(SimComponent): self.endpoint_a.connect_link(self) self.endpoint_b.connect_link(self) - def send_frame(self, sender_nic: NIC, frame: Any): + def send_frame(self, sender_nic: NIC, frame: Frame): """ Send a network frame from one NIC to another connected NIC. @@ -244,7 +245,7 @@ class Link(SimComponent): """ pass - def receive_frame(self, sender_nic: NIC, frame: Any): + def receive_frame(self, sender_nic: NIC, frame: Frame): """ Receive a network frame from a connected NIC. diff --git a/src/primaite/simulator/network/transmission/primaite_layer.py b/src/primaite/simulator/network/transmission/primaite_layer.py new file mode 100644 index 00000000..4c90c14c --- /dev/null +++ b/src/primaite/simulator/network/transmission/primaite_layer.py @@ -0,0 +1,40 @@ +from enum import Enum + +from pydantic import BaseModel + + +class DataStatus(Enum): + """ + The status of the data in transmission. + + Members: + - GOOD: 1 + - COMPROMISED: 2 + - CORRUPT: 3 + """ + + GOOD = 1 + COMPROMISED = 2 + CORRUPT = 3 + + +class AgentSource(Enum): + """ + The agent source of the transmission. + + Members: + - RED: 1 + - GREEN: 2 + - BLUE: 3 + """ + + RED = 1 + GREEN = 2 + BLUE = 3 + + +class PrimaiteHeader(BaseModel): + """A custom header for carrying PrimAITE transmission metadata required for RL.""" + + agent_source: AgentSource = AgentSource.GREEN + data_status: DataStatus = DataStatus.GOOD diff --git a/src/primaite/simulator/network/transmission/transport_layer.py b/src/primaite/simulator/network/transmission/transport_layer.py new file mode 100644 index 00000000..c8e6b89d --- /dev/null +++ b/src/primaite/simulator/network/transmission/transport_layer.py @@ -0,0 +1,119 @@ +from enum import Enum +from typing import List, Union + +from pydantic import BaseModel + + +class Port(Enum): + """Enumeration of common known TCP/UDP ports used by protocols for operation of network applications.""" + + WOL = 9 + "Wake-on-Lan (WOL) - Used to turn or awaken a computer from sleep mode by a network message." + FTP_DATA = 20 + "File Transfer [Default Data]" + FTP = 21 + "File Transfer Protocol (FTP) - FTP control (command)" + SSH = 22 + "Secure Shell (SSH) - Used for secure remote access and command execution." + SMTP = 25 + "Simple Mail Transfer Protocol (SMTP) - Used for email delivery between servers." + DNS = 53 + "Domain Name System (DNS) - Used for translating domain names to IP addresses." + HTTP = 80 + "HyperText Transfer Protocol (HTTP) - Used for web traffic." + POP3 = 110 + "Post Office Protocol version 3 (POP3) - Used for retrieving emails from a mail server." + SFTP = 115 + "Secure File Transfer Protocol (SFTP) - Used for secure file transfer over SSH." + NTP = 123 + "Network Time Protocol (NTP) - Used for clock synchronization between computer systems." + IMAP = 143 + "Internet Message Access Protocol (IMAP) - Used for retrieving emails from a mail server." + SNMP = 161 + "Simple Network Management Protocol (SNMP) - Used for network device management." + SNMP_TRAP = 162 + "SNMP Trap - Used for sending SNMP notifications (traps) to a network management system." + LDAP = 389 + "Lightweight Directory Access Protocol (LDAP) - Used for accessing and modifying directory information." + HTTPS = 443 + "HyperText Transfer Protocol Secure (HTTPS) - Used for secure web traffic." + SMB = 445 + "Server Message Block (SMB) - Used for file sharing and printer sharing in Windows environments." + IPP = 631 + "Internet Printing Protocol (IPP) - Used for printing over the internet or an intranet." + SQL_SERVER = 1433 + "Microsoft SQL Server Database Engine - Used for communication with the SQL Server." + MYSQL = 3306 + "MySQL Database Server - Used for MySQL database communication." + RDP = 3389 + "Remote Desktop Protocol (RDP) - Used for remote desktop access to Windows machines." + RTP = 5004 + "Real-time Transport Protocol (RTP) - Used for transmitting real-time media, e.g., audio and video." + RTP_ALT = 5005 + "Alternative port for RTP (RTP_ALT) - Used in some configurations for transmitting real-time media." + DNS_ALT = 5353 + "Alternative port for DNS (DNS_ALT) - Used in some configurations for DNS service." + HTTP_ALT = 8080 + "Alternative port for HTTP (HTTP_ALT) - Often used as an alternative HTTP port for web applications." + HTTPS_ALT = 8443 + "Alternative port for HTTPS (HTTPS_ALT) - Used in some configurations for secure web traffic." + + +class UDPHeader(BaseModel): + """ + Represents a UDP header for the transport layer of a Network Frame. + + :param src_port: Source port. + :param dst_port: Destination port. + + :Example: + + >>> udp_header = UDPHeader( + ... src_port=Port.HTTP_ALT, + ... dst_port=Port.HTTP, + ... ) + """ + + src_port: Union[Port, int] + dst_port: Union[Port, int] + + +class TCPFlags(Enum): + """ + Enum representing TCP control flags used in a TCP connection. + + Flags are used to indicate a particular state of the connection or provide additional information. + + Members: + - SYN: (1) - Used in the first step of connection establishment phase or 3-way handshake process between two hosts. + - ACK: (2) - Used to acknowledge packets that are successfully received by the host. + - FIN: (4) - Used to request connection termination when there is no more data from the sender. + - RST: (8) - Used to terminate the connection if there is an issue with the TCP connection. + """ + + SYN = 1 + ACK = 2 + FIN = 4 + RST = 8 + + +class TCPHeader(BaseModel): + """ + Represents a TCP header for the transport layer of a Network Frame. + + :param src_port: Source port. + :param dst_port: Destination port. + :param flags: TCP flags (list of TCPFlags members). + + :Example: + + >>> tcp_header = TCPHeader( + ... src_port=Port.HTTP_ALT, + ... dst_port=Port.HTTP, + ... flags=[TCPFlags.SYN, TCPFlags.ACK] + ... ) + """ + + src_port: int + dst_port: int + flags: List[TCPFlags] = [TCPFlags.SYN] diff --git a/tests/integration_tests/network/test_nic_link_connection.py b/tests/integration_tests/network/test_nic_link_connection.py index 1a191200..6bca3c0a 100644 --- a/tests/integration_tests/network/test_nic_link_connection.py +++ b/tests/integration_tests/network/test_nic_link_connection.py @@ -1,6 +1,6 @@ import pytest -from primaite.simulator.network.physical_layer import Link, NIC +from primaite.simulator.network.transmission.physical_layer import Link, NIC def test_link_fails_with_same_nic(): diff --git a/tests/unit_tests/_primaite/_simulator/_network/_transmission/__init__.py b/tests/unit_tests/_primaite/_simulator/_network/_transmission/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py new file mode 100644 index 00000000..e8e3fa57 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py @@ -0,0 +1,90 @@ +import pytest + +from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame +from primaite.simulator.network.transmission.network_layer import ICMPHeader, IPPacket, IPProtocol, Precedence +from primaite.simulator.network.transmission.primaite_layer import AgentSource, DataStatus +from primaite.simulator.network.transmission.transport_layer import Port, TCPFlags, TCPHeader, UDPHeader + + +def test_frame_minimal_instantiation(): + """Tests that the minimum frame (TCP SYN) using default values.""" + frame = Frame( + ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), + ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20"), + tcp=TCPHeader( + src_port=8080, + dst_port=80, + ), + ) + + # Check network layer default values + assert frame.ip.protocol == IPProtocol.TCP + assert frame.ip.ttl == 64 + assert frame.ip.precedence == Precedence.ROUTINE + + # Check transport layer default values + assert frame.tcp.flags == [TCPFlags.SYN] + + # Check primaite custom header default values + assert frame.primaite_header.agent_source == AgentSource.GREEN + assert frame.primaite_header.data_status == DataStatus.GOOD + + # Check that model can be dumped down to json and returned as size in Bytes + assert frame.size + + +def test_frame_creation_fails_tcp_without_header(): + """Tests Frame creation fails if the IPProtocol is TCP but there is no TCPHeader.""" + with pytest.raises(ValueError): + Frame( + ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), + ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.TCP), + ) + + +def test_frame_creation_fails_udp_without_header(): + """Tests Frame creation fails if the IPProtocol is UDP but there is no UDPHeader.""" + with pytest.raises(ValueError): + Frame( + ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), + ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.UDP), + ) + + +def test_frame_creation_fails_tcp_with_udp_header(): + """Tests Frame creation fails if the IPProtocol is TCP but there is a UDPHeader.""" + with pytest.raises(ValueError): + Frame( + ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), + ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.TCP), + udp=UDPHeader(src_port=8080, dst_port=80), + ) + + +def test_frame_creation_fails_udp_with_tcp_header(): + """Tests Frame creation fails if the IPProtocol is UDP but there is a TCPHeader.""" + with pytest.raises(ValueError): + Frame( + ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), + ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.UDP), + udp=TCPHeader(src_port=8080, dst_port=80), + ) + + +def test_icmp_frame_creation(): + """Tests Frame creation for ICMP.""" + frame = Frame( + ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), + ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.ICMP), + icmp=ICMPHeader(), + ) + assert frame + + +def test_icmp_frame_creation_fails_without_icmp_header(): + """Tests Frame creation for ICMP.""" + with pytest.raises(ValueError): + Frame( + ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), + ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.ICMP), + ) diff --git a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py new file mode 100644 index 00000000..584ff25d --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py @@ -0,0 +1,24 @@ +import pytest + +from primaite.simulator.network.transmission.network_layer import ICMPHeader, ICMPType + + +def test_icmp_minimal_header_creation(): + """Checks the minimal ICMPHeader (ping 1 request) creation using default values.""" + ping = ICMPHeader() + + assert ping.icmp_type == ICMPType.ECHO_REQUEST + assert ping.icmp_code == 0 + assert ping.identifier + assert ping.sequence == 1 + + +def test_valid_icmp_type_code_pairing(): + """Tests ICMPHeader creation with valid type and code pairing.""" + assert ICMPHeader(icmp_type=ICMPType.DESTINATION_UNREACHABLE, icmp_code=6) + + +def test_invalid_icmp_type_code_pairing(): + """Tests ICMPHeader creation fails with invalid type and code pairing.""" + with pytest.raises(ValueError): + assert ICMPHeader(icmp_type=ICMPType.DESTINATION_UNREACHABLE, icmp_code=16) diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_physical_layer.py b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_physical_layer.py similarity index 95% rename from tests/unit_tests/_primaite/_simulator/_network/test_physical_layer.py rename to tests/unit_tests/_primaite/_simulator/_network/_transmission/test_physical_layer.py index ad1226a6..5a33e723 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_physical_layer.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_physical_layer.py @@ -3,7 +3,7 @@ from ipaddress import IPv4Address import pytest -from primaite.simulator.network.physical_layer import generate_mac_address, NIC +from primaite.simulator.network.transmission.physical_layer import generate_mac_address, NIC def test_mac_address_generation(): From 95f5515d69d5515bd9c5bb02a3def311bd75ce81 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 2 Aug 2023 12:12:08 +0100 Subject: [PATCH 047/980] #1724 - Added documentation for the transport layer down to data link layer --- docs/source/simulation.rst | 1 + .../network/transport_to_data_link_layer.rst | 135 ++++++++++++++++++ .../network/transmission/data_link_layer.py | 4 +- .../network/transmission/physical_layer.py | 9 +- .../_transmission/test_data_link_layer.py | 4 +- 5 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 docs/source/simulation_components/network/transport_to_data_link_layer.rst diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index 0af6c89f..81476998 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -17,3 +17,4 @@ Contents simulation_structure simulation_components/network/physical_layer + simulation_components/network/transport_to_data_link_layer diff --git a/docs/source/simulation_components/network/transport_to_data_link_layer.rst b/docs/source/simulation_components/network/transport_to_data_link_layer.rst new file mode 100644 index 00000000..8273339c --- /dev/null +++ b/docs/source/simulation_components/network/transport_to_data_link_layer.rst @@ -0,0 +1,135 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +Transport Layer to Data Link Layer +================================== + +From the `OSI Model <[OSI Model](https://en.wikipedia.org/wiki/OSI_model,>`_, the transport layer (layer 4) through to +the data link layer (layer 2) have been loosely modelled to provide somewhat realistic network Frame generation. + +Transport Layer (Layer 4) +######################### + +**UDPHeader:** Represents a UDP header for the transport layer of a Network Frame. It includes source and destination +ports. UDP (User Datagram Protocol) is a connectionless and unreliable transport protocol used for data transmission. + +**TCPFlags:** Enum representing TCP control flags used in a TCP connection, such as SYN, ACK, FIN, and RST. TCP +(Transmission Control Protocol) is a connection-oriented and reliable transport protocol used for establishing and +maintaining data streams. + +**TCPHeader:** Represents a TCP header for the transport layer of a Network Frame. It includes source and destination +ports and TCP flags. This header is used for establishing and managing TCP connections. + +Network Layer (Layer 3) +####################### + + +**IPProtocol:** Enum representing transport layer protocols in the IP header, such as TCP, UDP, and ICMP. It is used to +indicate the type of transport layer protocol being used in the IP header. + +**Precedence:** Enum representing the Precedence levels in Quality of Service (QoS) for IP packets. It is used to +specify the priority of IP packets for Quality of Service handling. + +**ICMPType:** Enumeration of common ICMP (Internet Control Message Protocol) types. It defines various types of ICMP +messages used for network troubleshooting and error reporting. + +**ICMPHeader:** Models an ICMP header and includes ICMP type, code, identifier, and sequence number. It is used to +create ICMP packets for network control and error reporting. + +**IPPacket:** Represents the IP layer of a network frame. It includes source and destination IP addresses, protocol +(TCP/UDP/ICMP), Time to Live (TTL), and Precedence for QoS. This header is used to route data packets across the +network based on IP addresses. + + +PrimAITE Layer (Custom Layer) +############################# + +The PrimAITE layer has a custom header represented by the ``PrimaiteHeader`` class. It is designed to carry +PrimAITE-specific metadata required for reinforcement learning (RL) purposes. + +**PrimaiteHeader:** This is a custom header for carrying PrimAITE-specific metadata. It contains the following fields: + - **agent_source:** Enum representing the agent source of the transmission, such as RED, GREEN, or BLUE. This field helps identify the source or category of the data transmission. + - **data_status:** Enum representing the status of the data in transmission, such as GOOD, COMPROMISED, or CORRUPT. This field indicates the integrity of the data being transmitted. + +Data Link Layer (Layer 2) +######################### + +**EthernetHeader:** Represents the Ethernet layer of a network frame. It includes source and destination MAC addresses. +This header is used to identify the physical hardware addresses of devices on a local network. + +**Frame:** Represents a complete network frame with all layers. It includes an ``EthernetHeader``, an ``IPPacket``, an +optional ``TCPHeader``, ``UDPHeader``, or ``ICMPHeader``, a ``PrimaiteHeader`` and an optional payload. This class +combines all the headers and data to create a complete network frame that can be sent over the network and used in the +PrimAITE simulation. + +Basic Usage +########### + +TCP SYN Frame +------------- + +Here we will model a TCP synchronize request from a port 80 on the host 192.168.0.100 which has a NIC with a MAC +address of 'aa:bb:cc:dd:ee:ff' to port 8080 on the host 10.0.0.10 which has a NIC with a MAC address of +'11:22:33:44:55:66'. + + +.. code-block:: python + + from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame + from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol + from primaite.simulator.network.transmission.transport_layer import TCPFlags, TCPHeader + + # Transport Layer + tcp_header = TCPHeader( + src_port=80, + dst_port=8080, + flags=[TCPFlags.SYN] + ) + + # Network Layer + ip_packet = IPPacket( + src_ip="192.168.0.100", + dst_ip="10.0.0.10", + protocol=IPProtocol.TCP + ) + # Data Link Layer + ethernet_header = EthernetHeader( + src_mac_addr="aa:bb:cc:dd:ee:ff", + dst_mac_addr="11:22:33:44:55:66" + ) + + frame = Frame( + ethernet=ethernet_header, + ip=ip_packet, + tcp=tcp_header, + ) + +This produces the following ``Frame`` (displayed in json format) + +.. code-block:: json + + { + "ethernet": { + "src_mac_addr": "aa:bb:cc:dd:ee:ff", + "dst_mac_addr": "11:22:33:44:55:66" + }, + "ip": { + "src_ip": "192.168.0.100", + "dst_ip": "10.0.0.10", + "protocol": "tcp", + "ttl": 64, + "precedence": 0 + }, + "tcp": { + "src_port": 80, + "dst_port": 8080, + "flags": [ + 1 + ] + }, + "primaite": { + "agent_source": 2, + "data_status": 1 + } + } diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index e8133f86..b9d969bd 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -89,12 +89,12 @@ class Frame(BaseModel): "UDP header." icmp: Optional[ICMPHeader] = None "ICMP header." - primaite_header: PrimaiteHeader = PrimaiteHeader() + primaite: PrimaiteHeader = PrimaiteHeader() "PrimAITE header." payload: Optional[Any] = None "Raw data payload." @property def size(self) -> int: - """The size of the Frame in Bytes.""" + """The size in Bytes.""" return len(self.model_dump_json().encode("utf-8")) diff --git a/src/primaite/simulator/network/transmission/physical_layer.py b/src/primaite/simulator/network/transmission/physical_layer.py index 2fbfbc6b..ee2297b6 100644 --- a/src/primaite/simulator/network/transmission/physical_layer.py +++ b/src/primaite/simulator/network/transmission/physical_layer.py @@ -3,7 +3,7 @@ from __future__ import annotations import re import secrets from ipaddress import IPv4Address, IPv4Network -from typing import Any, Dict, List, Optional +from typing import Dict, List, Optional from primaite import getLogger from primaite.exceptions import NetworkError @@ -221,16 +221,19 @@ class Link(SimComponent): current_load: int = 0 "The current load on the link in Mbps." - def model_post_init(self, __context: Any) -> None: + def __init__(self, **kwargs): """ Ensure that endpoint_a and endpoint_b are not the same NIC. + Connect the link to the NICs after creation. + :raises ValueError: If endpoint_a and endpoint_b are the same NIC. """ - if self.endpoint_a == self.endpoint_b: + if kwargs["endpoint_a"] == kwargs["endpoint_b"]: msg = "endpoint_a and endpoint_b cannot be the same NIC" _LOGGER.error(msg) raise ValueError(msg) + super().__init__(**kwargs) self.endpoint_a.connect_link(self) self.endpoint_b.connect_link(self) diff --git a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py index e8e3fa57..83b215ca 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py @@ -26,8 +26,8 @@ def test_frame_minimal_instantiation(): assert frame.tcp.flags == [TCPFlags.SYN] # Check primaite custom header default values - assert frame.primaite_header.agent_source == AgentSource.GREEN - assert frame.primaite_header.data_status == DataStatus.GOOD + assert frame.primaite.agent_source == AgentSource.GREEN + assert frame.primaite.data_status == DataStatus.GOOD # Check that model can be dumped down to json and returned as size in Bytes assert frame.size From 091b4a801dc5a7f558fdea273fcbed579f950021 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 2 Aug 2023 13:43:31 +0100 Subject: [PATCH 048/980] Make some progress on accounts --- src/primaite/simulator/domain/__init__.py | 3 + src/primaite/simulator/domain/account.py | 92 +++++++++++++++++++ src/primaite/simulator/domain/controller.py | 13 +++ .../simulator/domain_controller/__init__.py | 0 .../simulator/domain_controller/account.py | 8 -- 5 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 src/primaite/simulator/domain/__init__.py create mode 100644 src/primaite/simulator/domain/account.py create mode 100644 src/primaite/simulator/domain/controller.py delete mode 100644 src/primaite/simulator/domain_controller/__init__.py delete mode 100644 src/primaite/simulator/domain_controller/account.py diff --git a/src/primaite/simulator/domain/__init__.py b/src/primaite/simulator/domain/__init__.py new file mode 100644 index 00000000..6f59cf49 --- /dev/null +++ b/src/primaite/simulator/domain/__init__.py @@ -0,0 +1,3 @@ +from primaite.simulator.domain.account import Account + +__all__ = ["Account"] diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py new file mode 100644 index 00000000..374675a0 --- /dev/null +++ b/src/primaite/simulator/domain/account.py @@ -0,0 +1,92 @@ +"""User account simulation.""" +from enum import Enum +from typing import Dict, List, Set, TypeAlias + +from primaite import getLogger +from primaite.simulator.core import SimComponent + +_LOGGER = getLogger(__name__) + + +__temp_node = TypeAlias() # placeholder while nodes don't exist + + +class AccountType(Enum): + """Whether the account is intended for a user to log in or for a service to use.""" + + service = 1 + "Service accounts are used to grant permissions to software on nodes to perform actions" + user = 2 + "User accounts are used to allow agents to log in and perform actions" + + +class AccountGroup(Enum): + """Permissions are set at group-level and accounts can belong to these groups.""" + + local_user = 1 + "For performing basic actions on a node" + domain_user = 2 + "For performing basic actions to the domain" + local_admin = 3 + "For full access to actions on a node" + domain_admin = 4 + "For full access" + + +class AccountStatus(Enum): + """Whether the account is active.""" + + enabled = 1 + disabled = 2 + + +class Account(SimComponent): + """User accounts.""" + + num_logons: int = 0 + "The number of times this account was logged into since last reset." + num_logoffs: int = 0 + "The number of times this account was logged out of since last reset." + num_group_changes: int = 0 + "The number of times this account was moved in or out of an AccountGroup." + username: str + "Account username." + password: str + "Account password." + account_type: AccountType + "Account Type, currently this can be service account (used by apps) or user account." + domain_groups: Set[AccountGroup] = [] + "Domain-wide groups that this account belongs to." + local_groups: Dict[__temp_node, List[AccountGroup]] + "For each node, whether this account has local/admin privileges on that node." + status: AccountStatus = AccountStatus.disabled + + def add_to_domain_group(self, group: AccountGroup) -> None: + """ + Add this account to a domain group. + + If the account is already a member of this group, nothing happens. + + :param group: The group to which to add this account. + :type group: AccountGroup + """ + self.domain_groups.add(group) + + def remove_from_domain_group(self, group: AccountGroup) -> None: + """ + Remove this account from a domain group. + + If the account is already not a member of that group, nothing happens. + + :param group: The group from which this account should be removed. + :type group: AccountGroup + """ + self.domain_groups.discard(group) + + def enable_account(self): + """Set the status to enabled.""" + self.status = AccountStatus.enabled + + def disable_account(self): + """Set the status to disabled.""" + self.status = AccountStatus.disabled diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py new file mode 100644 index 00000000..5a14e80e --- /dev/null +++ b/src/primaite/simulator/domain/controller.py @@ -0,0 +1,13 @@ +from typing import Set, TypeAlias + +from primaite.simulator.core import SimComponent +from primaite.simulator.domain import Account + +__temp_node = TypeAlias() # placeholder while nodes don't exist + + +class DomainController(SimComponent): + """Main object for controlling the domain.""" + + nodes: Set(__temp_node) = set() + accounts: Set(Account) = set() diff --git a/src/primaite/simulator/domain_controller/__init__.py b/src/primaite/simulator/domain_controller/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/primaite/simulator/domain_controller/account.py b/src/primaite/simulator/domain_controller/account.py deleted file mode 100644 index 1f3ac900..00000000 --- a/src/primaite/simulator/domain_controller/account.py +++ /dev/null @@ -1,8 +0,0 @@ -"""User account simulation.""" -from primaite.simulator.core import SimComponent - - -class Account(SimComponent): - """User accounts.""" - - uid: int From 897dbdf10c83e2bebd33952c38bbe267703a4f4f Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 2 Aug 2023 21:54:21 +0100 Subject: [PATCH 049/980] #1706 - Got the core Node class build and working with ARP and the ability to ping another node. Added some basic tests in. Next job is to create the Node subclasses. Then move ARP and ICMP into a service that is used by all nodes. --- docs/source/simulation.rst | 2 +- .../{physical_layer.rst => base_hardware.rst} | 4 +- .../network/transport_to_data_link_layer.rst | 4 +- src/primaite/simulator/core.py | 9 + .../simulator/network/hardware/__init__.py | 0 .../simulator/network/hardware/base.py | 665 ++++++++++++++++++ .../simulator/network/nodes/__init__.py | 0 .../simulator/network/protocols/__init__.py | 0 .../simulator/network/protocols/arp.py | 69 ++ .../network/transmission/data_link_layer.py | 25 +- .../network/transmission/network_layer.py | 13 +- .../network/transmission/physical_layer.py | 277 -------- .../network/transmission/transport_layer.py | 6 +- src/primaite/simulator/network/utils.py | 27 + .../network/test_frame_transmission.py | 25 + .../network/test_link_connection.py | 21 + .../network/test_nic_link_connection.py | 2 +- .../_simulator/_network/_hardware/__init__.py | 0 .../test_nic.py} | 2 +- .../_network/_hardware/test_node.py | 10 + .../_transmission/test_data_link_layer.py | 4 +- .../_transmission/test_network_layer.py | 16 +- .../_primaite/_simulator/test_core.py | 7 +- 23 files changed, 879 insertions(+), 309 deletions(-) rename docs/source/simulation_components/network/{physical_layer.rst => base_hardware.rst} (98%) create mode 100644 src/primaite/simulator/network/hardware/__init__.py create mode 100644 src/primaite/simulator/network/hardware/base.py create mode 100644 src/primaite/simulator/network/nodes/__init__.py create mode 100644 src/primaite/simulator/network/protocols/__init__.py create mode 100644 src/primaite/simulator/network/protocols/arp.py delete mode 100644 src/primaite/simulator/network/transmission/physical_layer.py create mode 100644 src/primaite/simulator/network/utils.py create mode 100644 tests/integration_tests/network/test_frame_transmission.py create mode 100644 tests/integration_tests/network/test_link_connection.py create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_hardware/__init__.py rename tests/unit_tests/_primaite/_simulator/_network/{_transmission/test_physical_layer.py => _hardware/test_nic.py} (95%) create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node.py diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index 81476998..b9f921c2 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -16,5 +16,5 @@ Contents :maxdepth: 8 simulation_structure - simulation_components/network/physical_layer + simulation_components/network/base_hardware simulation_components/network/transport_to_data_link_layer diff --git a/docs/source/simulation_components/network/physical_layer.rst b/docs/source/simulation_components/network/base_hardware.rst similarity index 98% rename from docs/source/simulation_components/network/physical_layer.rst rename to docs/source/simulation_components/network/base_hardware.rst index 1e87b72e..c3891a6e 100644 --- a/docs/source/simulation_components/network/physical_layer.rst +++ b/docs/source/simulation_components/network/base_hardware.rst @@ -2,8 +2,8 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -Physical Layer -============== +Base Hardware +============= The physical layer components are models of a ``NIC`` (Network Interface Card) and a ``Link``. These components allow modelling of layer 1 (physical layer) in the OSI model. diff --git a/docs/source/simulation_components/network/transport_to_data_link_layer.rst b/docs/source/simulation_components/network/transport_to_data_link_layer.rst index 8273339c..9332b57c 100644 --- a/docs/source/simulation_components/network/transport_to_data_link_layer.rst +++ b/docs/source/simulation_components/network/transport_to_data_link_layer.rst @@ -34,7 +34,7 @@ specify the priority of IP packets for Quality of Service handling. **ICMPType:** Enumeration of common ICMP (Internet Control Message Protocol) types. It defines various types of ICMP messages used for network troubleshooting and error reporting. -**ICMPHeader:** Models an ICMP header and includes ICMP type, code, identifier, and sequence number. It is used to +**ICMPPacket:** Models an ICMP header and includes ICMP type, code, identifier, and sequence number. It is used to create ICMP packets for network control and error reporting. **IPPacket:** Represents the IP layer of a network frame. It includes source and destination IP addresses, protocol @@ -59,7 +59,7 @@ Data Link Layer (Layer 2) This header is used to identify the physical hardware addresses of devices on a local network. **Frame:** Represents a complete network frame with all layers. It includes an ``EthernetHeader``, an ``IPPacket``, an -optional ``TCPHeader``, ``UDPHeader``, or ``ICMPHeader``, a ``PrimaiteHeader`` and an optional payload. This class +optional ``TCPHeader``, ``UDPHeader``, or ``ICMPPacket``, a ``PrimaiteHeader`` and an optional payload. This class combines all the headers and data to create a complete network frame that can be sent over the network and used in the PrimAITE simulation. diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index c3130116..d684a74b 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -1,6 +1,7 @@ """Core of the PrimAITE Simulator.""" from abc import abstractmethod from typing import Callable, Dict, List +from uuid import uuid4 from pydantic import BaseModel @@ -8,6 +9,14 @@ from pydantic import BaseModel class SimComponent(BaseModel): """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" + uuid: str + "The component UUID." + + def __init__(self, **kwargs): + if not kwargs.get("uuid"): + kwargs["uuid"] = str(uuid4()) + super().__init__(**kwargs) + @abstractmethod def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/network/hardware/__init__.py b/src/primaite/simulator/network/hardware/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py new file mode 100644 index 00000000..054eb1c6 --- /dev/null +++ b/src/primaite/simulator/network/hardware/base.py @@ -0,0 +1,665 @@ +from __future__ import annotations + +import re +import secrets +from enum import Enum +from ipaddress import IPv4Address, IPv4Network +from typing import Any, Dict, List, Optional, Union + +from primaite import getLogger +from primaite.exceptions import NetworkError +from primaite.simulator.core import SimComponent +from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket +from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame +from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader + +_LOGGER = getLogger(__name__) + + +def generate_mac_address(oui: Optional[str] = None) -> str: + """ + Generate a random MAC Address. + + :Example: + + >>> generate_mac_address() + 'ef:7e:97:c8:a8:ce' + + >>> generate_mac_address(oui='aa:bb:cc') + 'aa:bb:cc:42:ba:41' + + :param oui: The Organizationally Unique Identifier (OUI) portion of the MAC address. It should be a string with + the first 3 bytes (24 bits) in the format "XX:XX:XX". + :raises ValueError: If the 'oui' is not in the correct format (hexadecimal and 6 characters). + """ + random_bytes = [secrets.randbits(8) for _ in range(6)] + + if oui: + oui_pattern = re.compile(r"^([0-9A-Fa-f]{2}[:-]){2}[0-9A-Fa-f]{2}$") + if not oui_pattern.match(oui): + msg = f"Invalid oui. The oui should be in the format xx:xx:xx, where x is a hexadecimal digit, got '{oui}'" + raise ValueError(msg) + oui_bytes = [int(chunk, 16) for chunk in oui.split(":")] + mac = oui_bytes + random_bytes[len(oui_bytes) :] + else: + mac = random_bytes + + return ":".join(f"{b:02x}" for b in mac) + + +class NIC(SimComponent): + """ + Models a Network Interface Card (NIC) in a computer or network device. + + :param ip_address: The IPv4 address assigned to the NIC. + :param subnet_mask: The subnet mask assigned to the NIC. + :param gateway: The default gateway IP address for forwarding network traffic to other networks. + :param mac_address: The MAC address of the NIC. Defaults to a randomly set MAC address. + :param speed: The speed of the NIC in Mbps (default is 100 Mbps). + :param mtu: The Maximum Transmission Unit (MTU) of the NIC in Bytes, representing the largest data packet size it + can handle without fragmentation (default is 1500 B). + :param wake_on_lan: Indicates if the NIC supports Wake-on-LAN functionality. + :param dns_servers: List of IP addresses of DNS servers used for name resolution. + """ + + ip_address: IPv4Address + "The IP address assigned to the NIC for communication on an IP-based network." + subnet_mask: str + "The subnet mask assigned to the NIC." + gateway: IPv4Address + "The default gateway IP address for forwarding network traffic to other networks. Randomly generated upon creation." + mac_address: str + "The MAC address of the NIC. Defaults to a randomly set MAC address." + speed: int = 100 + "The speed of the NIC in Mbps. Default is 100 Mbps." + mtu: int = 1500 + "The Maximum Transmission Unit (MTU) of the NIC in Bytes. Default is 1500 B" + wake_on_lan: bool = False + "Indicates if the NIC supports Wake-on-LAN functionality." + dns_servers: List[IPv4Address] = [] + "List of IP addresses of DNS servers used for name resolution." + connected_node: Optional[Node] = None + "The Node to which the NIC is connected." + connected_link: Optional[Link] = None + "The Link to which the NIC is connected." + enabled: bool = False + "Indicates whether the NIC is enabled." + + def __init__(self, **kwargs): + """ + NIC constructor. + + Performs some type conversion the calls ``super().__init__()``. Then performs some checking on the ip_address + and gateway just to check that it's all been configured correctly. + + :raises ValueError: When the ip_address and gateway are the same. And when the ip_address/subnet mask are a + network address. + """ + if not isinstance(kwargs["ip_address"], IPv4Address): + kwargs["ip_address"] = IPv4Address(kwargs["ip_address"]) + if not isinstance(kwargs["gateway"], IPv4Address): + kwargs["gateway"] = IPv4Address(kwargs["gateway"]) + if "mac_address" not in kwargs: + kwargs["mac_address"] = generate_mac_address() + super().__init__(**kwargs) + + if self.ip_address == self.gateway: + msg = f"NIC ip address {self.ip_address} cannot be the same as the gateway {self.gateway}" + _LOGGER.error(msg) + raise ValueError(msg) + if self.ip_network.network_address == self.ip_address: + msg = ( + f"Failed to set IP address {self.ip_address} and subnet mask {self.subnet_mask} as it is a " + f"network address {self.ip_network.network_address}" + ) + _LOGGER.error(msg) + raise ValueError(msg) + + @property + def ip_network(self) -> IPv4Network: + """ + Return the IPv4Network of the NIC. + + :return: The IPv4Network from the ip_address/subnet mask. + """ + return IPv4Network(f"{self.ip_address}/{self.subnet_mask}", strict=False) + + def enable(self): + """Attempt to enable the NIC.""" + if not self.enabled: + if self.connected_node: + if self.connected_node.hardware_state == HardwareState.ON: + self.enabled = True + _LOGGER.info(f"NIC {self} enabled") + if self.connected_link: + self.connected_link.endpoint_up() + else: + _LOGGER.info(f"NIC {self} cannot be enabled as the endpoint is not turned on") + else: + msg = f"NIC {self} cannot be enabled as it is not connected to a Node" + _LOGGER.error(msg) + raise NetworkError(msg) + + def disable(self): + """Disable the NIC.""" + if self.enabled: + self.enabled = False + _LOGGER.info(f"NIC {self} disabled") + if self.connected_link: + self.connected_link.endpoint_down() + + def connect_link(self, link: Link): + """ + Connect the NIC to a link. + + :param link: The link to which the NIC is connected. + :type link: :class:`~primaite.simulator.network.transmission.physical_layer.Link` + :raise NetworkError: When an attempt to connect a Link is made while the NIC has a connected Link. + """ + if not self.connected_link: + if self.connected_link != link: + _LOGGER.info(f"NIC {self} connected to Link") + # TODO: Inform the Node that a link has been connected + self.connected_link = link + else: + _LOGGER.warning(f"Cannot connect link to NIC ({self.mac_address}) as it is already connected") + else: + msg = f"Cannot connect link to NIC ({self.mac_address}) as it already has a connection" + _LOGGER.error(msg) + raise NetworkError(msg) + + def disconnect_link(self): + """Disconnect the NIC from the connected Link.""" + if self.connected_link.endpoint_a == self: + self.connected_link.endpoint_a = None + if self.connected_link.endpoint_b == self: + self.connected_link.endpoint_b = None + self.connected_link = None + + def add_dns_server(self, ip_address: IPv4Address): + """ + Add a DNS server IP address. + + :param ip_address: The IP address of the DNS server to be added. + :type ip_address: ipaddress.IPv4Address + """ + pass + + def remove_dns_server(self, ip_address: IPv4Address): + """ + Remove a DNS server IP Address. + + :param ip_address: The IP address of the DNS server to be removed. + :type ip_address: ipaddress.IPv4Address + """ + pass + + def send_frame(self, frame: Frame) -> bool: + """ + Send a network frame from the NIC to the connected link. + + :param frame: The network frame to be sent. + :type frame: :class:`~primaite.simulator.network.osi_layers.Frame` + """ + if self.enabled: + self.connected_link.transmit_frame(sender_nic=self, frame=frame) + return True + else: + # Cannot send Frame as the NIC is not enabled + return False + + def receive_frame(self, frame: Frame) -> bool: + """ + Receive a network frame from the connected link if the NIC is enabled. + + The Frame is passed to the Node. + + :param frame: The network frame being received. + :type frame: :class:`~primaite.simulator.network.osi_layers.Frame` + """ + if self.enabled: + self.connected_node.receive_frame(frame=frame, from_nic=self) + return True + else: + return False + + def describe_state(self) -> Dict: + """ + Get the current state of the NIC as a dict. + + :return: A dict containing the current state of the NIC. + """ + pass + + def apply_action(self, action: str): + """ + Apply an action to the NIC. + + :param action: The action to be applied. + :type action: str + """ + pass + + def __str__(self) -> str: + return f"{self.mac_address}/{self.ip_address}" + + +class Link(SimComponent): + """ + Represents a network link between two network interface cards (NICs). + + :param endpoint_a: The first NIC connected to the Link. + :type endpoint_a: NIC + :param endpoint_b: The second NIC connected to the Link. + :type endpoint_b: NIC + :param bandwidth: The bandwidth of the Link in Mbps (default is 100 Mbps). + :type bandwidth: int + """ + + endpoint_a: NIC + "The first NIC connected to the Link." + endpoint_b: NIC + "The second NIC connected to the Link." + bandwidth: int = 100 + "The bandwidth of the Link in Mbps (default is 100 Mbps)." + current_load: float = 0.0 + "The current load on the link in Mbps." + + def __init__(self, **kwargs): + """ + Ensure that endpoint_a and endpoint_b are not the same NIC. + + Connect the link to the NICs after creation. + + :raises ValueError: If endpoint_a and endpoint_b are the same NIC. + """ + if kwargs["endpoint_a"] == kwargs["endpoint_b"]: + msg = "endpoint_a and endpoint_b cannot be the same NIC" + _LOGGER.error(msg) + raise ValueError(msg) + super().__init__(**kwargs) + self.endpoint_a.connect_link(self) + self.endpoint_b.connect_link(self) + if self.up: + _LOGGER.info(f"Link up between {self.endpoint_a} and {self.endpoint_b}") + + def endpoint_up(self): + """Let the Link know and endpoint has been brought up.""" + if self.up: + _LOGGER.info(f"Link up between {self.endpoint_a} and {self.endpoint_b}") + + def endpoint_down(self): + """Let the Link know and endpoint has been brought down.""" + if not self.up: + self.current_load = 0.0 + _LOGGER.info(f"Link down between {self.endpoint_a} and {self.endpoint_b}") + + @property + def up(self) -> bool: + """ + Informs whether the link is up. + + This is based upon both NIC endpoints being enabled. + """ + return self.endpoint_a.enabled and self.endpoint_b.enabled + + def _can_transmit(self, frame: Frame) -> bool: + if self.up: + frame_size_Mbits = frame.size_Mbits # noqa - Leaving it as Mbits as this is how they're expressed + return self.current_load + frame_size_Mbits <= self.bandwidth + return False + + def transmit_frame(self, sender_nic: NIC, frame: Frame) -> bool: + """ + Send a network frame from one NIC to another connected NIC. + + :param sender_nic: The NIC sending the frame. + :param frame: The network frame to be sent. + :return: True if the Frame can be sent, otherwise False. + """ + receiver_nic = self.endpoint_a + if receiver_nic == sender_nic: + receiver_nic = self.endpoint_b + frame_size = frame.size + sent = receiver_nic.receive_frame(frame) + if sent: + # Frame transmitted successfully + # Load the frame size on the link + self.current_load += frame_size + return True + # Received NIC disabled, reply + + return False + + def reset_component_for_episode(self): + """ + Link reset function. + + Reset: + - returns the link current_load to 0. + """ + self.current_load = 0 + + def describe_state(self) -> Dict: + """ + Get the current state of the Libk as a dict. + + :return: A dict containing the current state of the Link. + """ + pass + + def apply_action(self, action: str): + """ + Apply an action to the Link. + + :param action: The action to be applied. + :type action: str + """ + pass + + +class HardwareState(Enum): + """Node hardware state enumeration.""" + + ON = 1 + OFF = 2 + RESETTING = 3 + SHUTTING_DOWN = 4 + BOOTING = 5 + + +class Node(SimComponent): + """ + A basic Node class. + + :param hostname: The node hostname on the network. + :param hardware_state: The hardware state of the node. + """ + + hostname: str + "The node hostname on the network." + hardware_state: HardwareState = HardwareState.OFF + "The hardware state of the node." + nics: Dict[str, NIC] = {} + "The NICs on the node." + + accounts: Dict = {} + "All accounts on the node." + applications: Dict = {} + "All applications on the node." + services: Dict = {} + "All services on the node." + processes: Dict = {} + "All processes on the node." + file_system: Any = None + "The nodes file system." + arp_cache: Dict[IPv4Address, ARPEntry] = {} + "The ARP cache." + + revealed_to_red: bool = False + "Informs whether the node has been revealed to a red agent." + + def turn_on(self): + """Turn on the Node.""" + if self.hardware_state == HardwareState.OFF: + self.hardware_state = HardwareState.ON + _LOGGER.info(f"Node {self.hostname} turned on") + for nic in self.nics.values(): + nic.enable() + + def turn_off(self): + """Turn off the Node.""" + if self.hardware_state == HardwareState.ON: + for nic in self.nics.values(): + nic.disable() + self.hardware_state = HardwareState.OFF + _LOGGER.info(f"Node {self.hostname} turned off") + + def connect_nic(self, nic: NIC): + """ + Connect a NIC. + + :param nic: The NIC to connect. + :raise NetworkError: If the NIC is already connected. + """ + if nic.uuid not in self.nics: + self.nics[nic.uuid] = nic + nic.connected_node = self + _LOGGER.debug(f"Node {self.hostname} connected NIC {nic}") + if self.hardware_state == HardwareState.ON: + nic.enable() + else: + msg = f"Cannot connect NIC {nic} to Node {self.hostname} as it is already connected" + _LOGGER.error(msg) + raise NetworkError(msg) + + def disconnect_nic(self, nic: Union[NIC, str]): + """ + Disconnect a NIC. + + :param nic: The NIC to Disconnect. + :raise NetworkError: If the NIC is not connected. + """ + if isinstance(nic, str): + nic = self.nics.get(nic) + if nic or nic.uuid in self.nics: + self.nics.pop(nic.uuid) + nic.disable() + _LOGGER.debug(f"Node {self.hostname} disconnected NIC {nic}") + else: + msg = f"Cannot disconnect NIC {nic} from Node {self.hostname} as it is not connected" + _LOGGER.error(msg) + raise NetworkError(msg) + + def _add_arp_cache_entry(self, ip_address: IPv4Address, mac_address: str, nic: NIC): + """ + Add an ARP entry to the cache. + + :param ip_address: The IP address to be added to the cache. + :param mac_address: The MAC address associated with the IP address. + :param nic: The NIC through which the NIC with the IP address is reachable. + """ + _LOGGER.info(f"Node {self.hostname} Adding ARP cache entry for {mac_address}/{ip_address} via NIC {nic}") + arp_entry = ARPEntry(mac_address=mac_address, nic_uuid=nic.uuid) + self.arp_cache[ip_address] = arp_entry + + def _remove_arp_cache_entry(self, ip_address: IPv4Address): + """ + Remove an ARP entry from the cache. + + :param ip_address: The IP address to be removed from the cache. + """ + if ip_address in self.arp_cache: + del self.arp_cache[ip_address] + + def _get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: + """ + Get the MAC address associated with an IP address. + + :param ip_address: The IP address to look up in the cache. + :return: The MAC address associated with the IP address, or None if not found. + """ + arp_entry = self.arp_cache.get(ip_address) + if arp_entry: + return arp_entry.mac_address + + def _get_arp_cache_nic(self, ip_address: IPv4Address) -> Optional[NIC]: + """ + Get the NIC associated with an IP address. + + :param ip_address: The IP address to look up in the cache. + :return: The NIC associated with the IP address, or None if not found. + """ + arp_entry = self.arp_cache.get(ip_address) + if arp_entry: + return self.nics[arp_entry.nic_uuid] + + def _clear_arp_cache(self): + """Clear the entire ARP cache.""" + self.arp_cache.clear() + + def _send_arp_request(self, target_ip_address: Union[IPv4Address, str]): + """Perform a standard ARP request for a given target IP address.""" + for nic in self.nics.values(): + if nic.enabled: + _LOGGER.info(f"Node {self.hostname} sending ARP request from NIC {nic} for ip {target_ip_address}") + tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) + + # Network Layer + ip_packet = IPPacket( + src_ip=nic.ip_address, + dst_ip=target_ip_address, + ) + # Data Link Layer + ethernet_header = EthernetHeader(src_mac_addr=nic.mac_address, dst_mac_addr="ff:ff:ff:ff:ff:ff") + arp_packet = ARPPacket( + sender_ip=nic.ip_address, sender_mac_addr=nic.mac_address, target_ip=target_ip_address + ) + frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) + nic.send_frame(frame) + + def process_arp_packet(self, from_nic: NIC, arp_packet: ARPPacket): + """ + Process an ARP packet. + + # TODO: This will become a service that sits on the Node. + + :param from_nic: The NIC the arp packet was received at. + :param arp_packet:The ARP packet to process. + """ + if arp_packet.request: + _LOGGER.info( + f"Node {self.hostname} received ARP request from {arp_packet.sender_mac_addr}/{arp_packet.sender_ip}" + ) + self._add_arp_cache_entry( + ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic + ) + arp_packet = arp_packet.generate_reply(from_nic.mac_address) + _LOGGER.info( + f"Node {self.hostname} sending ARP reply from {arp_packet.sender_mac_addr}/{arp_packet.sender_ip} " + f"to {arp_packet.target_ip}/{arp_packet.target_mac_addr} " + ) + + tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) + + # Network Layer + ip_packet = IPPacket( + src_ip=arp_packet.sender_ip, + dst_ip=arp_packet.target_ip, + ) + # Data Link Layer + ethernet_header = EthernetHeader( + src_mac_addr=arp_packet.sender_mac_addr, dst_mac_addr=arp_packet.target_mac_addr + ) + frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) + self.send_frame(frame) + else: + _LOGGER.info( + f"Node {self.hostname} received ARP response for {arp_packet.sender_ip} " + f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" + ) + self._add_arp_cache_entry( + ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic + ) + + def process_icmp(self, frame: Frame): + """ + Process an ICMP packet. + + # TODO: This will become a service that sits on the Node. + + :param frame: The Frame containing the icmp packet to process. + """ + if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: + _LOGGER.info(f"Node {self.hostname} received echo request from {frame.ip.src_ip}") + target_mac_address = self._get_arp_cache_mac_address(frame.ip.src_ip) + src_nic = self._get_arp_cache_nic(frame.ip.src_ip) + tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) + + # Network Layer + ip_packet = IPPacket(src_ip=src_nic.ip_address, dst_ip=frame.ip.src_ip, protocol=IPProtocol.ICMP) + # Data Link Layer + ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) + icmp_reply_packet = ICMPPacket( + icmp_type=ICMPType.ECHO_REPLY, + icmp_code=0, + identifier=frame.icmp.identifier, + sequence=frame.icmp.sequence + 1, + ) + frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet) + src_nic.send_frame(frame) + elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: + _LOGGER.info(f"Node {self.hostname} received echo reply from {frame.ip.src_ip}") + if frame.icmp.sequence <= 6: # 3 pings + self._ping(frame.ip.src_ip, sequence=frame.icmp.sequence, identifier=frame.icmp.identifier) + + def _ping(self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None): + nic = self._get_arp_cache_nic(target_ip_address) + if nic: + sequence += 1 + target_mac_address = self._get_arp_cache_mac_address(target_ip_address) + src_nic = self._get_arp_cache_nic(target_ip_address) + tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) + + # Network Layer + ip_packet = IPPacket( + src_ip=nic.ip_address, + dst_ip=target_ip_address, + protocol=IPProtocol.ICMP, + ) + # Data Link Layer + ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) + icmp_packet = ICMPPacket(identifier=identifier, sequence=sequence) + frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_packet) + nic.send_frame(frame) + else: + _LOGGER.info(f"Node {self.hostname} no entry in ARP cache for {target_ip_address}") + self._send_arp_request(target_ip_address) + self._ping(target_ip_address=target_ip_address) + + def ping(self, target_ip_address: Union[IPv4Address, str]) -> bool: + """ + Ping an IP address. + + Performs a standard ICMP echo request/response four times. + + :param target_ip_address: The target IP address to ping. + :return: True if successful, otherwise False. + """ + if not isinstance(target_ip_address, IPv4Address): + target_ip_address = IPv4Address(target_ip_address) + if self.hardware_state == HardwareState.ON: + _LOGGER.info(f"Node {self.hostname} attempting to ping {target_ip_address}") + self._ping(target_ip_address) + return True + return False + + def send_frame(self, frame: Frame): + """ + Send a Frame from the Node to the connected NIC. + + :param frame: The Frame to be sent. + """ + nic: NIC = self._get_arp_cache_nic(frame.ip.dst_ip) + nic.send_frame(frame) + + def receive_frame(self, frame: Frame, from_nic: NIC): + """ + Receive a Frame from the connected NIC. + + The Frame is passed to up to the SessionManager. + + :param frame: The Frame being received. + """ + if frame.ip.protocol == IPProtocol.TCP: + if frame.tcp.src_port == Port.ARP: + self.process_arp_packet(from_nic=from_nic, arp_packet=frame.arp) + elif frame.ip.protocol == IPProtocol.UDP: + pass + elif frame.ip.protocol == IPProtocol.ICMP: + self.process_icmp(frame=frame) + + def describe_state(self) -> Dict: + """Describe the state of a Node.""" + pass diff --git a/src/primaite/simulator/network/nodes/__init__.py b/src/primaite/simulator/network/nodes/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/network/protocols/__init__.py b/src/primaite/simulator/network/protocols/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/network/protocols/arp.py b/src/primaite/simulator/network/protocols/arp.py new file mode 100644 index 00000000..bae14d28 --- /dev/null +++ b/src/primaite/simulator/network/protocols/arp.py @@ -0,0 +1,69 @@ +from __future__ import annotations + +from ipaddress import IPv4Address +from typing import Optional + +from pydantic import BaseModel + + +class ARPEntry(BaseModel): + """ + Represents an entry in the ARP cache. + + :param mac_address: The MAC address associated with the IP address. + :param nic: The NIC through which the NIC with the IP address is reachable. + """ + + mac_address: str + nic_uuid: str + + +class ARPPacket(BaseModel): + """ + Represents the ARP layer of a network frame. + + :param request: ARP operation. True if a request, False if a reply. + :param sender_mac_addr: Sender MAC address. + :param sender_ip: Sender IP address. + :param target_mac_addr: Target MAC address. + :param target_ip: Target IP address. + + :Example: + + >>> arp_request = ARPPacket( + ... sender_mac_addr="aa:bb:cc:dd:ee:ff", + ... sender_ip=IPv4Address("192.168.0.1"), + ... target_ip=IPv4Address("192.168.0.2") + ... ) + >>> arp_response = ARPPacket( + ... sender_mac_addr="aa:bb:cc:dd:ee:ff", + ... sender_ip=IPv4Address("192.168.0.1"), + ... target_ip=IPv4Address("192.168.0.2") + ... ) + """ + + request: bool = True + "ARP operation. True if a request, False if a reply." + sender_mac_addr: str + "Sender MAC address." + sender_ip: IPv4Address + "Sender IP address." + target_mac_addr: Optional[str] = None + "Target MAC address." + target_ip: IPv4Address + "Target IP address." + + def generate_reply(self, mac_address: str) -> ARPPacket: + """ + Generate a new ARPPacket to be sent as a response with a given mac address. + + :param mac_address: The mac_address that was being sought after from the original target IP address. + :return: A new instance of ARPPacket. + """ + return ARPPacket( + request=False, + sender_ip=self.target_ip, + sender_mac_addr=mac_address, + target_ip=self.sender_ip, + target_mac_addr=self.sender_mac_addr, + ) diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index b9d969bd..bc7e2453 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -3,9 +3,11 @@ from typing import Any, Optional from pydantic import BaseModel from primaite import getLogger -from primaite.simulator.network.transmission.network_layer import ICMPHeader, IPPacket, IPProtocol +from primaite.simulator.network.protocols.arp import ARPPacket +from primaite.simulator.network.transmission.network_layer import ICMPPacket, IPPacket, IPProtocol from primaite.simulator.network.transmission.primaite_layer import PrimaiteHeader from primaite.simulator.network.transmission.transport_layer import TCPHeader, UDPHeader +from primaite.simulator.network.utils import convert_bytes_to_megabits _LOGGER = getLogger(__name__) @@ -74,9 +76,11 @@ class Frame(BaseModel): _LOGGER.error(msg) raise ValueError(msg) if kwargs["ip"].protocol == IPProtocol.ICMP and not kwargs.get("icmp"): - msg = "Cannot build a Frame using the ICMP IP Protocol without a ICMPHeader" + msg = "Cannot build a Frame using the ICMP IP Protocol without a ICMPPacket" _LOGGER.error(msg) raise ValueError(msg) + kwargs["primaite"] = PrimaiteHeader() + super().__init__(**kwargs) ethernet: EthernetHeader @@ -87,14 +91,21 @@ class Frame(BaseModel): "TCP header." udp: Optional[UDPHeader] = None "UDP header." - icmp: Optional[ICMPHeader] = None + icmp: Optional[ICMPPacket] = None "ICMP header." - primaite: PrimaiteHeader = PrimaiteHeader() + arp: Optional[ARPPacket] = None + "ARP packet." + primaite: PrimaiteHeader "PrimAITE header." payload: Optional[Any] = None "Raw data payload." @property - def size(self) -> int: - """The size in Bytes.""" - return len(self.model_dump_json().encode("utf-8")) + def size(self) -> float: # noqa - Keep it as MBits as this is how they're expressed + """The size of the Frame in Bytes.""" + return float(len(self.model_dump_json().encode("utf-8"))) + + @property + def size_Mbits(self) -> float: # noqa - Keep it as MBits as this is how they're expressed + """The daa transfer size of the Frame in MBits.""" + return convert_bytes_to_megabits(self.size) diff --git a/src/primaite/simulator/network/transmission/network_layer.py b/src/primaite/simulator/network/transmission/network_layer.py index 69b682cc..afd1ecef 100644 --- a/src/primaite/simulator/network/transmission/network_layer.py +++ b/src/primaite/simulator/network/transmission/network_layer.py @@ -120,18 +120,23 @@ def get_icmp_type_code_description(icmp_type: ICMPType, icmp_code: int) -> Union return icmp_code_descriptions[icmp_type].get(icmp_code) -class ICMPHeader(BaseModel): - """Models an ICMP Header.""" +class ICMPPacket(BaseModel): + """Models an ICMP Packet.""" icmp_type: ICMPType = ICMPType.ECHO_REQUEST "ICMP Type." icmp_code: int = 0 "ICMP Code." - identifier: str = secrets.randbits(16) + identifier: int "ICMP identifier (16 bits randomly generated)." - sequence: int = 1 + sequence: int = 0 "ICMP message sequence number." + def __init__(self, **kwargs): + if not kwargs.get("identifier"): + kwargs["identifier"] = secrets.randbits(16) + super().__init__(**kwargs) + @field_validator("icmp_code") # noqa @classmethod def _icmp_type_must_have_icmp_code(cls, v: int, info: FieldValidationInfo) -> int: diff --git a/src/primaite/simulator/network/transmission/physical_layer.py b/src/primaite/simulator/network/transmission/physical_layer.py deleted file mode 100644 index ee2297b6..00000000 --- a/src/primaite/simulator/network/transmission/physical_layer.py +++ /dev/null @@ -1,277 +0,0 @@ -from __future__ import annotations - -import re -import secrets -from ipaddress import IPv4Address, IPv4Network -from typing import Dict, List, Optional - -from primaite import getLogger -from primaite.exceptions import NetworkError -from primaite.simulator.core import SimComponent -from primaite.simulator.network.transmission.data_link_layer import Frame - -_LOGGER = getLogger(__name__) - - -def generate_mac_address(oui: Optional[str] = None) -> str: - """ - Generate a random MAC Address. - - :Example: - - >>> generate_mac_address() - 'ef:7e:97:c8:a8:ce' - - >>> generate_mac_address(oui='aa:bb:cc') - 'aa:bb:cc:42:ba:41' - - :param oui: The Organizationally Unique Identifier (OUI) portion of the MAC address. It should be a string with - the first 3 bytes (24 bits) in the format "XX:XX:XX". - :raises ValueError: If the 'oui' is not in the correct format (hexadecimal and 6 characters). - """ - random_bytes = [secrets.randbits(8) for _ in range(6)] - - if oui: - oui_pattern = re.compile(r"^([0-9A-Fa-f]{2}[:-]){2}[0-9A-Fa-f]{2}$") - if not oui_pattern.match(oui): - msg = f"Invalid oui. The oui should be in the format xx:xx:xx, where x is a hexadecimal digit, got '{oui}'" - raise ValueError(msg) - oui_bytes = [int(chunk, 16) for chunk in oui.split(":")] - mac = oui_bytes + random_bytes[len(oui_bytes) :] - else: - mac = random_bytes - - return ":".join(f"{b:02x}" for b in mac) - - -class NIC(SimComponent): - """ - Models a Network Interface Card (NIC) in a computer or network device. - - :param ip_address: The IPv4 address assigned to the NIC. - :param subnet_mask: The subnet mask assigned to the NIC. - :param gateway: The default gateway IP address for forwarding network traffic to other networks. - :param mac_address: The MAC address of the NIC. Defaults to a randomly set MAC address. - :param speed: The speed of the NIC in Mbps (default is 100 Mbps). - :param mtu: The Maximum Transmission Unit (MTU) of the NIC in Bytes, representing the largest data packet size it - can handle without fragmentation (default is 1500 B). - :param wake_on_lan: Indicates if the NIC supports Wake-on-LAN functionality. - :param dns_servers: List of IP addresses of DNS servers used for name resolution. - """ - - ip_address: IPv4Address - "The IP address assigned to the NIC for communication on an IP-based network." - subnet_mask: str - "The subnet mask assigned to the NIC." - gateway: IPv4Address - "The default gateway IP address for forwarding network traffic to other networks. Randomly generated upon creation." - mac_address: str = generate_mac_address() - "The MAC address of the NIC. Defaults to a randomly set MAC address." - speed: int = 100 - "The speed of the NIC in Mbps. Default is 100 Mbps." - mtu: int = 1500 - "The Maximum Transmission Unit (MTU) of the NIC in Bytes. Default is 1500 B" - wake_on_lan: bool = False - "Indicates if the NIC supports Wake-on-LAN functionality." - dns_servers: List[IPv4Address] = [] - "List of IP addresses of DNS servers used for name resolution." - connected_link: Optional[Link] = None - "The Link to which the NIC is connected." - enabled: bool = False - "Indicates whether the NIC is enabled." - - def __init__(self, **kwargs): - """ - NIC constructor. - - Performs some type conversion the calls ``super().__init__()``. Then performs some checking on the ip_address - and gateway just to check that it's all been configured correctly. - - :raises ValueError: When the ip_address and gateway are the same. And when the ip_address/subnet mask are a - network address. - """ - if not isinstance(kwargs["ip_address"], IPv4Address): - kwargs["ip_address"] = IPv4Address(kwargs["ip_address"]) - if not isinstance(kwargs["gateway"], IPv4Address): - kwargs["gateway"] = IPv4Address(kwargs["gateway"]) - super().__init__(**kwargs) - - if self.ip_address == self.gateway: - msg = f"NIC ip address {self.ip_address} cannot be the same as the gateway {self.gateway}" - _LOGGER.error(msg) - raise ValueError(msg) - if self.ip_network.network_address == self.ip_address: - msg = ( - f"Failed to set IP address {self.ip_address} and subnet mask {self.subnet_mask} as it is a " - f"network address {self.ip_network.network_address}" - ) - _LOGGER.error(msg) - raise ValueError(msg) - - @property - def ip_network(self) -> IPv4Network: - """ - Return the IPv4Network of the NIC. - - :return: The IPv4Network from the ip_address/subnet mask. - """ - return IPv4Network(f"{self.ip_address}/{self.subnet_mask}", strict=False) - - def connect_link(self, link: Link): - """ - Connect the NIC to a link. - - :param link: The link to which the NIC is connected. - :type link: :class:`~primaite.simulator.network.transmission.physical_layer.Link` - :raise NetworkError: When an attempt to connect a Link is made while the NIC has a connected Link. - """ - if not self.connected_link: - if self.connected_link != link: - # TODO: Inform the Node that a link has been connected - self.connected_link = link - else: - _LOGGER.warning(f"Cannot connect link to NIC ({self.mac_address}) as it is already connected") - else: - msg = f"Cannot connect link to NIC ({self.mac_address}) as it already has a connection" - _LOGGER.error(msg) - raise NetworkError(msg) - - def disconnect_link(self): - """Disconnect the NIC from the connected Link.""" - if self.connected_link.endpoint_a == self: - self.connected_link.endpoint_a = None - if self.connected_link.endpoint_b == self: - self.connected_link.endpoint_b = None - self.connected_link = None - - def add_dns_server(self, ip_address: IPv4Address): - """ - Add a DNS server IP address. - - :param ip_address: The IP address of the DNS server to be added. - :type ip_address: ipaddress.IPv4Address - """ - pass - - def remove_dns_server(self, ip_address: IPv4Address): - """ - Remove a DNS server IP Address. - - :param ip_address: The IP address of the DNS server to be removed. - :type ip_address: ipaddress.IPv4Address - """ - pass - - def send_frame(self, frame: Frame): - """ - Send a network frame from the NIC to the connected link. - - :param frame: The network frame to be sent. - :type frame: :class:`~primaite.simulator.network.osi_layers.Frame` - """ - pass - - def receive_frame(self, frame: Frame): - """ - Receive a network frame from the connected link. - - The Frame is passed to the Node. - - :param frame: The network frame being received. - :type frame: :class:`~primaite.simulator.network.osi_layers.Frame` - """ - pass - - def describe_state(self) -> Dict: - """ - Get the current state of the NIC as a dict. - - :return: A dict containing the current state of the NIC. - """ - pass - - def apply_action(self, action: str): - """ - Apply an action to the NIC. - - :param action: The action to be applied. - :type action: str - """ - pass - - -class Link(SimComponent): - """ - Represents a network link between two network interface cards (NICs). - - :param endpoint_a: The first NIC connected to the Link. - :type endpoint_a: NIC - :param endpoint_b: The second NIC connected to the Link. - :type endpoint_b: NIC - :param bandwidth: The bandwidth of the Link in Mbps (default is 100 Mbps). - :type bandwidth: int - """ - - endpoint_a: NIC - "The first NIC connected to the Link." - endpoint_b: NIC - "The second NIC connected to the Link." - bandwidth: int = 100 - "The bandwidth of the Link in Mbps (default is 100 Mbps)." - current_load: int = 0 - "The current load on the link in Mbps." - - def __init__(self, **kwargs): - """ - Ensure that endpoint_a and endpoint_b are not the same NIC. - - Connect the link to the NICs after creation. - - :raises ValueError: If endpoint_a and endpoint_b are the same NIC. - """ - if kwargs["endpoint_a"] == kwargs["endpoint_b"]: - msg = "endpoint_a and endpoint_b cannot be the same NIC" - _LOGGER.error(msg) - raise ValueError(msg) - super().__init__(**kwargs) - self.endpoint_a.connect_link(self) - self.endpoint_b.connect_link(self) - - def send_frame(self, sender_nic: NIC, frame: Frame): - """ - Send a network frame from one NIC to another connected NIC. - - :param sender_nic: The NIC sending the frame. - :type sender_nic: NIC - :param frame: The network frame to be sent. - :type frame: Frame - """ - pass - - def receive_frame(self, sender_nic: NIC, frame: Frame): - """ - Receive a network frame from a connected NIC. - - :param sender_nic: The NIC sending the frame. - :type sender_nic: NIC - :param frame: The network frame being received. - :type frame: Frame - """ - pass - - def describe_state(self) -> Dict: - """ - Get the current state of the Libk as a dict. - - :return: A dict containing the current state of the Link. - """ - pass - - def apply_action(self, action: str): - """ - Apply an action to the Link. - - :param action: The action to be applied. - :type action: str - """ - pass diff --git a/src/primaite/simulator/network/transmission/transport_layer.py b/src/primaite/simulator/network/transmission/transport_layer.py index c8e6b89d..b95b4a74 100644 --- a/src/primaite/simulator/network/transmission/transport_layer.py +++ b/src/primaite/simulator/network/transmission/transport_layer.py @@ -33,6 +33,8 @@ class Port(Enum): "Simple Network Management Protocol (SNMP) - Used for network device management." SNMP_TRAP = 162 "SNMP Trap - Used for sending SNMP notifications (traps) to a network management system." + ARP = 219 + "Address resolution Protocol - Used to connect a MAC address to an IP address." LDAP = 389 "Lightweight Directory Access Protocol (LDAP) - Used for accessing and modifying directory information." HTTPS = 443 @@ -114,6 +116,6 @@ class TCPHeader(BaseModel): ... ) """ - src_port: int - dst_port: int + src_port: Port + dst_port: Port flags: List[TCPFlags] = [TCPFlags.SYN] diff --git a/src/primaite/simulator/network/utils.py b/src/primaite/simulator/network/utils.py new file mode 100644 index 00000000..496f5e13 --- /dev/null +++ b/src/primaite/simulator/network/utils.py @@ -0,0 +1,27 @@ +from typing import Union + + +def convert_bytes_to_megabits(B: Union[int, float]) -> float: # noqa - Keep it as B as this is how Bytes are expressed + """ + Convert Bytes (file size) to Megabits (data transfer). + + :param B: The file size in Bytes. + :return: File bits to transfer in Megabits. + """ + if isinstance(B, int): + B = float(B) + bits = B * 8.0 + return bits / 1024.0**2.0 + + +def convert_megabits_to_bytes(Mbits: Union[int, float]) -> float: # noqa - The same for Mbits + """ + Convert Megabits (data transfer) to Bytes (file size). + + :param Mbits bits to transfer in Megabits. + :return: The file size in Bytes. + """ + if isinstance(Mbits, int): + Mbits = float(Mbits) + bits = Mbits * 1024.0**2.0 + return bits / 8 diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py new file mode 100644 index 00000000..32abd0ef --- /dev/null +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -0,0 +1,25 @@ +from primaite.simulator.network.hardware.base import Link, NIC, Node + + +def test_node_to_node_ping(): + node_a = Node(hostname="node_a") + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") + node_a.connect_nic(nic_a) + node_a.turn_on() + + node_b = Node(hostname="node_b") + nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") + node_b.connect_nic(nic_b) + node_b.turn_on() + + Link(endpoint_a=nic_a, endpoint_b=nic_b) + + assert node_a.ping("192.168.0.11") + + node_a.turn_off() + + assert not node_a.ping("192.168.0.11") + + node_a.turn_on() + + assert node_a.ping("192.168.0.11") diff --git a/tests/integration_tests/network/test_link_connection.py b/tests/integration_tests/network/test_link_connection.py new file mode 100644 index 00000000..50abed77 --- /dev/null +++ b/tests/integration_tests/network/test_link_connection.py @@ -0,0 +1,21 @@ +from primaite.simulator.network.hardware.base import Link, NIC, Node + + +def test_link_up(): + """Tests Nodes, NICs, and Links can all be connected and be in an enabled/up state.""" + node_a = Node(hostname="node_a") + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") + node_a.connect_nic(nic_a) + node_a.turn_on() + assert nic_a.enabled + + node_b = Node(hostname="node_b") + nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") + node_b.connect_nic(nic_b) + node_b.turn_on() + + assert nic_b.enabled + + link = Link(endpoint_a=nic_a, endpoint_b=nic_b) + + assert link.up diff --git a/tests/integration_tests/network/test_nic_link_connection.py b/tests/integration_tests/network/test_nic_link_connection.py index 6bca3c0a..52a0c735 100644 --- a/tests/integration_tests/network/test_nic_link_connection.py +++ b/tests/integration_tests/network/test_nic_link_connection.py @@ -1,6 +1,6 @@ import pytest -from primaite.simulator.network.transmission.physical_layer import Link, NIC +from primaite.simulator.network.hardware.base import Link, NIC def test_link_fails_with_same_nic(): diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/__init__.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_physical_layer.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py similarity index 95% rename from tests/unit_tests/_primaite/_simulator/_network/_transmission/test_physical_layer.py rename to tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py index 5a33e723..dc508508 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_physical_layer.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py @@ -3,7 +3,7 @@ from ipaddress import IPv4Address import pytest -from primaite.simulator.network.transmission.physical_layer import generate_mac_address, NIC +from primaite.simulator.network.hardware.base import generate_mac_address, NIC def test_mac_address_generation(): diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node.py new file mode 100644 index 00000000..0e5fb4c7 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node.py @@ -0,0 +1,10 @@ +import re +from ipaddress import IPv4Address + +import pytest + +from primaite.simulator.network.hardware.base import Node + + +def test_node_creation(): + node = Node(hostname="host_1") diff --git a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py index 83b215ca..8a78d1bc 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py @@ -1,7 +1,7 @@ import pytest from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame -from primaite.simulator.network.transmission.network_layer import ICMPHeader, IPPacket, IPProtocol, Precedence +from primaite.simulator.network.transmission.network_layer import ICMPPacket, IPPacket, IPProtocol, Precedence from primaite.simulator.network.transmission.primaite_layer import AgentSource, DataStatus from primaite.simulator.network.transmission.transport_layer import Port, TCPFlags, TCPHeader, UDPHeader @@ -76,7 +76,7 @@ def test_icmp_frame_creation(): frame = Frame( ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.ICMP), - icmp=ICMPHeader(), + icmp=ICMPPacket(), ) assert frame diff --git a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py index 584ff25d..a7189452 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py @@ -1,24 +1,24 @@ import pytest -from primaite.simulator.network.transmission.network_layer import ICMPHeader, ICMPType +from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType def test_icmp_minimal_header_creation(): - """Checks the minimal ICMPHeader (ping 1 request) creation using default values.""" - ping = ICMPHeader() + """Checks the minimal ICMPPacket (ping 1 request) creation using default values.""" + ping = ICMPPacket() assert ping.icmp_type == ICMPType.ECHO_REQUEST assert ping.icmp_code == 0 assert ping.identifier - assert ping.sequence == 1 + assert ping.sequence == 0 def test_valid_icmp_type_code_pairing(): - """Tests ICMPHeader creation with valid type and code pairing.""" - assert ICMPHeader(icmp_type=ICMPType.DESTINATION_UNREACHABLE, icmp_code=6) + """Tests ICMPPacket creation with valid type and code pairing.""" + assert ICMPPacket(icmp_type=ICMPType.DESTINATION_UNREACHABLE, icmp_code=6) def test_invalid_icmp_type_code_pairing(): - """Tests ICMPHeader creation fails with invalid type and code pairing.""" + """Tests ICMPPacket creation fails with invalid type and code pairing.""" with pytest.raises(ValueError): - assert ICMPHeader(icmp_type=ICMPType.DESTINATION_UNREACHABLE, icmp_code=16) + assert ICMPPacket(icmp_type=ICMPType.DESTINATION_UNREACHABLE, icmp_code=16) diff --git a/tests/unit_tests/_primaite/_simulator/test_core.py b/tests/unit_tests/_primaite/_simulator/test_core.py index de0732f9..9f4b5fd9 100644 --- a/tests/unit_tests/_primaite/_simulator/test_core.py +++ b/tests/unit_tests/_primaite/_simulator/test_core.py @@ -1,4 +1,5 @@ from typing import Callable, Dict, List, Literal, Tuple +from uuid import uuid4 import pytest from pydantic import ValidationError @@ -35,15 +36,17 @@ class TestIsolatedSimComponent: """Validate that our added functionality does not interfere with pydantic.""" class TestComponent(SimComponent): + uuid: str name: str size: Tuple[float, float] def describe_state(self) -> Dict: return {} - comp = TestComponent(name="computer", size=(5, 10)) + uuid = str(uuid4()) + comp = TestComponent(uuid=uuid, name="computer", size=(5, 10)) dump = comp.model_dump() - assert dump == {"name": "computer", "size": (5, 10)} + assert dump == {"uuid": uuid, "name": "computer", "size": (5, 10)} def test_apply_action(self): """Validate that we can override apply_action behaviour and it updates the state of the component.""" From 209f934abd8bd860131130ea36ce24d4b560dd74 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 2 Aug 2023 22:01:15 +0100 Subject: [PATCH 050/980] #1706 - Added some extra logging --- src/primaite/simulator/network/hardware/base.py | 4 +++- .../simulator/network/transmission/data_link_layer.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 054eb1c6..c1bed5b0 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -321,12 +321,13 @@ class Link(SimComponent): receiver_nic = self.endpoint_a if receiver_nic == sender_nic: receiver_nic = self.endpoint_b - frame_size = frame.size + frame_size = frame.size_Mbits sent = receiver_nic.receive_frame(frame) if sent: # Frame transmitted successfully # Load the frame size on the link self.current_load += frame_size + _LOGGER.info(f"Link added {frame_size} Mbits, current load {self.current_load} Mbits") return True # Received NIC disabled, reply @@ -633,6 +634,7 @@ class Node(SimComponent): _LOGGER.info(f"Node {self.hostname} attempting to ping {target_ip_address}") self._ping(target_ip_address) return True + _LOGGER.info(f"Node {self.hostname} ping failed as the node is turned off") return False def send_frame(self, frame: Frame): diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index bc7e2453..97a1a423 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -107,5 +107,5 @@ class Frame(BaseModel): @property def size_Mbits(self) -> float: # noqa - Keep it as MBits as this is how they're expressed - """The daa transfer size of the Frame in MBits.""" + """The daa transfer size of the Frame in Mbits.""" return convert_bytes_to_megabits(self.size) From a0356a7fbc3e71046dd5094ecaf7200c88adfcab Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 3 Aug 2023 12:14:11 +0100 Subject: [PATCH 051/980] #1714: updated file system classes --- src/primaite/simulator/core.py | 9 ++ .../simulator/file_system/file_system.py | 131 ++++++++++++------ .../simulator/file_system/file_system_file.py | 41 ++++-- .../file_system/file_system_folder.py | 55 ++++++-- .../file_system/file_system_item_abc.py | 60 -------- .../_file_system/test_file_system.py | 80 +++++++++++ .../_file_system/test_file_system_file.py | 14 ++ .../_file_system/test_file_system_folder.py | 41 ++++++ 8 files changed, 302 insertions(+), 129 deletions(-) delete mode 100644 src/primaite/simulator/file_system/file_system_item_abc.py diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index a58e0c11..84b03498 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -1,6 +1,7 @@ """Core of the PrimAITE Simulator.""" from abc import abstractmethod from typing import Callable, Dict, List +from uuid import uuid4 from pydantic import BaseModel @@ -8,6 +9,14 @@ from pydantic import BaseModel class SimComponent(BaseModel): """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" + uuid: str + "The component UUID." + + def __init__(self, **kwargs): + if not kwargs.get("uuid"): + kwargs["uuid"] = str(uuid4()) + super().__init__(**kwargs) + @abstractmethod def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index f467595d..6af6db3e 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -1,17 +1,17 @@ -from typing import Dict, List, Union +from typing import Dict, List, Optional + +from pydantic import PrivateAttr from primaite.simulator.core import SimComponent from primaite.simulator.file_system.file_system_file import FileSystemFile +from primaite.simulator.file_system.file_system_file_type import FileSystemFileType from primaite.simulator.file_system.file_system_folder import FileSystemFolder class FileSystem(SimComponent): """Class that contains all the simulation File System.""" - files: List[FileSystemFile] - """List containing all the files in the file system.""" - - folders: List[FileSystemFolder] + _folders: List[FileSystemFolder] = PrivateAttr([]) """List containing all the folders in the file system.""" def describe_state(self) -> Dict: @@ -22,56 +22,107 @@ class FileSystem(SimComponent): """ pass - def create_file(self): - """Creates a FileSystemFile and adds it to the list of files.""" - pass + def get_folders(self) -> List[FileSystemFolder]: + """Returns the list of folders.""" + return self._folders - def create_folder(self): + def create_file(self, file_size: float, folder_uuid: Optional[str] = None) -> FileSystemFile: + """ + Creates a FileSystemFile and adds it to the list of files. + + :param: folder_uuid: The uuid of the folder to add the file to + :type: folder_uuid: str + """ + file = None + # if no folder uuid provided, create a folder and add file to it + if folder_uuid is None: + folder = FileSystemFolder() + + file = FileSystemFile(item_parent=folder.uuid, file_size=file_size, file_type=FileSystemFileType.TBD) + folder.add_file(file) + self._folders.append(folder) + else: + # otherwise check for existence and add file + folder = self.get_folder_by_id(folder_uuid) + if folder is not None: + file = FileSystemFile(file_size=file_size, file_type=FileSystemFileType.TBD) + folder.add_file(file=file) + return file + + def create_folder(self) -> FileSystemFolder: """Creates a FileSystemFolder and adds it to the list of folders.""" - pass + folder = FileSystemFolder(item_parent=None) + self._folders.append(folder) + return folder - def delete_file(self, file_item: str): + def delete_file(self, file_id: str): """ Deletes a file and removes it from the files list. - :param file_item: The UUID of the file item to delete - :type file_item: str + :param file_id: The UUID of the file item to delete + :type file_id: str """ - self.files = list(filter(lambda x: (x.get_item_uuid() != file_item), self.files)) + # iterate through folders to delete the item with the matching uuid + for folder in self._folders: + folder.remove_file(file_id) - def delete_folder(self, file_item: str): + def delete_folder(self, folder_id: str): """ - Deletes a folder, removes it frdom the folders list and removes any child folders and files. + Deletes a folder, removes it from the folders list and removes any child folders and files. - :param file_item: The UUID of the file item to delete - :type file_item: str + :param folder_id: The UUID of the file item to delete + :type folder_id: str """ - self.files = list(filter(lambda x: (x.get_item_parent() != file_item), self.files)) - self.folders = list(filter(lambda x: (x.get_item_uuid() != file_item), self.folders)) + self._folders = list(filter(lambda f: (f.uuid != folder_id), self._folders)) - def move_file_item(self, file_item: str, target_directory: str): - """ - Check to see if the file_item and target_directory exists then moves the item by changing its parent item uuid. + def move_file(self, src_folder_id: str, target_folder_id: str, file_id: str): + """Moves a file from one folder to another.""" + # check that both folders and the file exists + src = self.get_folder_by_id(src_folder_id) + target = self.get_folder_by_id(target_folder_id) - :param file_item: The UUID of the file item to move - :type file_item: str + if src is None: + raise Exception(f"src folder with UUID {src_folder_id} could not be found") - :param target_directory: The UUID of the directory the item should be moved into - :type target_directory: str - """ - item = self._file_item_exists(file_item) - if item and any(f for f in self.folders if f.get_item_uuid() == target_directory): - item.move(target_directory) + if target is None: + raise Exception(f"src folder with UUID {target_folder_id} could not be found") - def _file_item_exists(self, file_item_uuid: str) -> Union[FileSystemFile, FileSystemFolder, None]: - """Returns true if the file or folder UUID exists.""" - item = next((x for x in self.files if x.get_item_uuid() == file_item_uuid), None) - if item: - return item + file = src.get_file(file_id=file_id) + if file is None: + raise Exception(f"file with UUID {file_id} could not be found") - next((x for x in self.folders if x.get_item_uuid() == file_item_uuid), None) + # remove file from src + src.remove_file(file_id) - if item: - return item + # add file to target + target.add_file(file) - raise Exception(f"No file or folder found with id: {file_item_uuid}") + def copy_file(self, src_folder_id: str, target_folder_id: str, file_id: str): + """Copies a file from one folder to another.""" + # check that both folders and the file exists + src = self.get_folder_by_id(src_folder_id) + target = self.get_folder_by_id(target_folder_id) + + if src is None: + raise Exception(f"src folder with UUID {src_folder_id} could not be found") + + if target is None: + raise Exception(f"src folder with UUID {target_folder_id} could not be found") + + file = src.get_file(file_id=file_id) + if file is None: + raise Exception(f"file with UUID {file_id} could not be found") + + # add file to target + target.add_file(file) + + def get_file_by_id(self, file_id: str) -> FileSystemFile: + """Checks if the file exists in any file system folders.""" + for folder in self._folders: + file = folder.get_file(file_id=file_id) + if file is not None: + return file + + def get_folder_by_id(self, folder_id: str) -> FileSystemFolder: + """Checks if the folder exists.""" + return next((f for f in self._folders if f.uuid == folder_id), None) diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py index ee4fe1e5..bebaa223 100644 --- a/src/primaite/simulator/file_system/file_system_file.py +++ b/src/primaite/simulator/file_system/file_system_file.py @@ -1,30 +1,43 @@ from typing import Dict +from pydantic import PrivateAttr + +from primaite.simulator.core import SimComponent from primaite.simulator.file_system.file_system_file_type import FileSystemFileType -from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC -class FileSystemFile(FileSystemItemABC): +class FileSystemFile(SimComponent): """Class that represents a file in the simulation.""" - _file_type: FileSystemFileType + _file_type: FileSystemFileType = PrivateAttr() """The type of the FileSystemFile""" + _file_size: float = PrivateAttr() + """Disk size of the FileSystemItem""" + + def __init__(self, file_type: FileSystemFileType, file_size: float, **kwargs): + """ + Initialise FileSystemFile class. + + :param item_parent: The UUID of the FileSystemItem parent + :type item_parent: str + + :param file_size: The size of the FileSystemItem + :type file_size: float + """ + super().__init__(**kwargs) + + self._file_type = file_type + self._file_size = file_size + + def get_file_size(self) -> float: + """Returns the size of the file system item.""" + return self._file_size + def get_file_type(self) -> FileSystemFileType: """Returns the FileSystemFileType of the file.""" return self._file_type - def move(self, target_directory: str): - """ - Changes the parent_item of the FileSystemFile. - - Essentially simulates the file system item being moved from folder to folder - - :param target_directory: The UUID of the directory the file system item should be moved to - :type target_directory: str - """ - super().move(target_directory) - def describe_state(self) -> Dict: """ Get the current state of the FileSystemFile as a dict. diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py index 41b9e1dd..248a4f98 100644 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -1,14 +1,50 @@ -from typing import Dict +from typing import Dict, List -from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC +from pydantic import PrivateAttr + +from primaite.simulator.core import SimComponent +from primaite.simulator.file_system.file_system_file import FileSystemFile -class FileSystemFolder(FileSystemItemABC): +class FileSystemFolder(SimComponent): """Simulation FileSystemFolder.""" - _is_quarantined: bool + _files: List[FileSystemFile] = PrivateAttr([]) + """List of files stored in the folder.""" + + _folder_size: float = PrivateAttr(0) + """The current size of the folder""" + + _is_quarantined: bool = PrivateAttr(False) """Flag that marks the folder as quarantined if true.""" + def get_files(self) -> List[FileSystemFile]: + """Returns the list of files the folder contains.""" + return self._files + + def get_file(self, file_id: str) -> FileSystemFile: + """Return a FileSystemFile with the matching id.""" + return next((f for f in self._files if f.uuid == file_id), None) + + def add_file(self, file: FileSystemFile): + """Adds a file to the folder list.""" + self._folder_size += file.get_file_size() + + # add to list + self._files.append(file) + + def remove_file(self, file_id: str): + """Removes a file from the folder list.""" + file = next((f for f in self._files if f.uuid == file_id), None) + self._files.remove(file) + + # remove folder size from folder + self._folder_size -= file.get_file_size() + + def get_folder_size(self) -> float: + """Returns a sum of all file sizes in the files list.""" + return sum([file.get_file_size() for file in self._files]) + def quarantine(self): """Quarantines the File System Folder.""" self._is_quarantined = True @@ -21,17 +57,6 @@ class FileSystemFolder(FileSystemItemABC): """Returns true if the folder is being quarantined.""" return self._is_quarantined - def move(self, target_directory: str): - """ - Changes the parent_item of the file system item. - - Essentially simulates the file system item being moved from folder to folder - - :param target_directory: The UUID of the directory the file system item should be moved to - :type target_directory: str - """ - super().move(target_directory) - def describe_state(self) -> Dict: """ Get the current state of the FileSystemFolder as a dict. diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py deleted file mode 100644 index 11a3f858..00000000 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ /dev/null @@ -1,60 +0,0 @@ -from abc import ABC, abstractmethod -from uuid import uuid4 - -from primaite.simulator.core import SimComponent - - -class FileSystemItemABC(SimComponent, ABC): - """Abstract Base class for any file system items e.g. files and folders.""" - - _uuid: str - """Unique identifier for the FileSystemItem""" - - _parent_item: str - """UUID of the parent FileSystemItem""" - - _item_size: float - """Disk size of the FileSystemItem""" - - def __init__(self, parent_item: str, item_size: float): - """ - Abstract base class used by FileSystem items. - - :param parent_item: The UUID of the FileSystemItem parent - :type parent_item: str - - :param item_size: The size of the FileSystemItem - :type item_size: float - """ - super().__init__() - - # generate random uuid for file system item - self._uuid = str(uuid4()) - - self._parent_item = parent_item - - self._item_size = item_size - - def get_item_uuid(self) -> str: - """Returns the file system item UUID.""" - return self._uuid - - def get_item_parent(self) -> str: - """Returns the UUID of the item's parent.""" - return self._parent_item - - def get_item_size(self) -> float: - """Returns the item size.""" - return self._item_size - - @abstractmethod - def move(self, target_directory: str): - """ - Changes the parent_item of the file system item. - - Essentially simulates the file system item being moved from folder to folder - - :param target_directory: The UUID of the directory the file system item should be moved to - :type target_directory: str - """ - self._parent_item = target_directory diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index e69de29b..7b26f707 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -0,0 +1,80 @@ +from primaite.simulator.file_system.file_system import FileSystem + + +def test_create_folder_and_file(): + """Test creating a folder and a file.""" + file_system = FileSystem() + folder = file_system.create_folder() + assert len(file_system.get_folders()) is 1 + + file_system.create_file(file_size=10, folder_uuid=folder.uuid) + assert len(file_system.get_folders()[0].get_files()) is 1 + + +def test_create_file(): + """Tests that creating a file without a folder creates a folder and sets that as the file's parent.""" + file_system = FileSystem() + + file = file_system.create_file(file_size=10) + assert len(file_system.get_folders()) is 1 + assert file_system.get_folders()[0].get_file(file.uuid) is file + + +def test_delete_file(): + """Tests that a file can be deleted.""" + file_system = FileSystem() + + file = file_system.create_file(file_size=10) + assert len(file_system.get_folders()) is 1 + assert file_system.get_folders()[0].get_file(file.uuid) is file + + file_system.delete_file(file.uuid) + assert len(file_system.get_folders()) is 1 + assert len(file_system.get_folders()[0].get_files()) is 0 + + +def test_delete_folder(): + file_system = FileSystem() + folder = file_system.create_folder() + assert len(file_system.get_folders()) is 1 + + file_system.delete_folder(folder.uuid) + assert len(file_system.get_folders()) is 0 + + +def test_move_file(): + """Tests the file move function.""" + file_system = FileSystem() + src_folder = file_system.create_folder() + assert len(file_system.get_folders()) is 1 + + target_folder = file_system.create_folder() + assert len(file_system.get_folders()) is 2 + + file = file_system.create_file(file_size=10, folder_uuid=src_folder.uuid) + assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 1 + assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 0 + + file_system.move_file(src_folder.uuid, target_folder.uuid, file.uuid) + + assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 0 + assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 1 + + +def test_copy_file(): + """Tests the file copy function.""" + file_system = FileSystem() + src_folder = file_system.create_folder() + assert len(file_system.get_folders()) is 1 + + target_folder = file_system.create_folder() + assert len(file_system.get_folders()) is 2 + + file = file_system.create_file(file_size=10, folder_uuid=src_folder.uuid) + assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 1 + assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 0 + + file_system.copy_file(src_folder.uuid, target_folder.uuid, file.uuid) + + assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 1 + assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 1 diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py index e69de29b..34c8dd94 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py @@ -0,0 +1,14 @@ +from primaite.simulator.file_system.file_system_file import FileSystemFile +from primaite.simulator.file_system.file_system_file_type import FileSystemFileType + + +def test_file_type(): + """Tests tha the FileSystemFile type is set correctly.""" + file = FileSystemFile(file_size=1.5, file_type=FileSystemFileType.TBD) + assert file.get_file_type() is FileSystemFileType.TBD + + +def test_get_file_size(): + """Tests that the file size is being returned properly.""" + file = FileSystemFile(file_size=1.5, file_type=FileSystemFileType.TBD) + assert file.get_file_size() is 1.5 diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py index e69de29b..b67ea385 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py @@ -0,0 +1,41 @@ +from primaite.simulator.file_system.file_system_file import FileSystemFile +from primaite.simulator.file_system.file_system_file_type import FileSystemFileType +from primaite.simulator.file_system.file_system_folder import FileSystemFolder + + +def test_adding_removing_file(): + folder = FileSystemFolder() + + file = FileSystemFile(file_size=10, file_type=FileSystemFileType.TBD) + + folder.add_file(file) + assert folder.get_folder_size() is 10 + assert len(folder.get_files()) is 1 + + folder.remove_file(file_id=file.uuid) + assert folder.get_folder_size() is 0 + assert len(folder.get_files()) is 0 + + +def test_get_file_by_id(): + folder = FileSystemFolder() + + file = FileSystemFile(file_size=10, file_type=FileSystemFileType.TBD) + + folder.add_file(file) + assert folder.get_folder_size() is 10 + assert len(folder.get_files()) is 1 + + assert folder.get_file(file_id=file.uuid) is file + + +def test_folder_quarantine_state(): + folder = FileSystemFolder() + + assert folder.quarantine_status() is False + + folder.quarantine() + assert folder.quarantine_status() is True + + folder.end_quarantine() + assert folder.quarantine_status() is False From b08683fcd322919ce59c9c646d98121265caaa88 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 3 Aug 2023 12:42:16 +0100 Subject: [PATCH 052/980] #1714: fix tests --- pyproject.toml | 2 +- tests/conftest.py | 2 +- tests/unit_tests/_primaite/_simulator/test_core.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4982dfd1..74de37df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ dependencies = [ "stable-baselines3==1.6.2", "tensorflow==2.12.0", "typer[all]==0.9.0", - "pydantic" + "pydantic==2.1.1" ] [tool.setuptools.dynamic] diff --git a/tests/conftest.py b/tests/conftest.py index 8102050e..f1c05187 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -96,7 +96,7 @@ def temp_primaite_session(request): """ training_config_path = request.param[0] lay_down_config_path = request.param[1] - with patch("_primaite.agents.agent_abc.get_session_path", get_temp_session_path) as mck: + with patch("primaite.agents.agent_abc.get_session_path", get_temp_session_path) as mck: mck.session_timestamp = datetime.now() return TempPrimaiteSession(training_config_path, lay_down_config_path) diff --git a/tests/unit_tests/_primaite/_simulator/test_core.py b/tests/unit_tests/_primaite/_simulator/test_core.py index de0732f9..00f29791 100644 --- a/tests/unit_tests/_primaite/_simulator/test_core.py +++ b/tests/unit_tests/_primaite/_simulator/test_core.py @@ -43,7 +43,7 @@ class TestIsolatedSimComponent: comp = TestComponent(name="computer", size=(5, 10)) dump = comp.model_dump() - assert dump == {"name": "computer", "size": (5, 10)} + assert dump["name"] is "computer" def test_apply_action(self): """Validate that we can override apply_action behaviour and it updates the state of the component.""" From 3a2840bed850de3fb2c57c55fc23bdee4fc55285 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 3 Aug 2023 13:09:04 +0100 Subject: [PATCH 053/980] Overhaul sim component for permission management. --- src/primaite/simulator/core.py | 131 +++++++++++++++++--- src/primaite/simulator/domain/__init__.py | 4 +- src/primaite/simulator/domain/account.py | 46 +++---- src/primaite/simulator/domain/controller.py | 51 +++++++- 4 files changed, 182 insertions(+), 50 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index c3130116..eaedc85a 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -1,13 +1,123 @@ """Core of the PrimAITE Simulator.""" -from abc import abstractmethod -from typing import Callable, Dict, List +from abc import ABC, abstractmethod +from typing import Callable, Dict, List, Optional -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict + +from primaite import getLogger +from primaite.simulator.domain import AccountGroup + +_LOGGER = getLogger(__name__) + + +class ActionPermissionValidator(ABC): + """ + Base class for action validators. + + The permissions manager is designed to be generic. So, although in the first instance the permissions + are evaluated purely on membership to AccountGroup, this class can support validating permissions based on any + arbitrary criteria. + """ + + @abstractmethod + def __call__(self, request: List[str], context: Dict) -> bool: + """TODO.""" + pass + + +class AllowAllValidator(ActionPermissionValidator): + """Always allows the action.""" + + def __call__(self, request: List[str], context: Dict) -> bool: + """Always allow the action.""" + return True + + +class GroupMembershipValidator(ActionPermissionValidator): + """Permit actions based on group membership.""" + + def __init__(self, allowed_groups: List[AccountGroup]) -> None: + """TODO.""" + self.allowed_groups = allowed_groups + + def __call__(self, request: List[str], context: Dict) -> bool: + """Permit the action if the request comes from an account which belongs to the right group.""" + # if context request source is part of any groups mentioned in self.allow_groups, return true, otherwise false + requestor_groups: List[str] = context["request_source"]["groups"] + for allowed_group in self.allowed_groups: + if allowed_group.name in requestor_groups: + return True + return False + + +class Action: + """ + This object stores data related to a single action. + + This includes the callable that can execute the action request, and the validator that will decide whether + the action can be performed or not. + """ + + def __init__(self, func: Callable[[List[str], Dict], None], validator: ActionPermissionValidator) -> None: + """ + Save the functions that are for this action. + + Here's a description for the intended use of both of these. + + ``func`` is a function that accepts a request and a context dict. Typically this would be a lambda function + that invokes a class method of your SimComponent. For example if the component is a node and the action is for + turning it off, then the SimComponent should have a turn_off(self) method that does not need to accept any args. + Then, this Action will be given something like ``func = lambda request, context: self.turn_off()``. + + :param func: Function that performs the request. + :type func: Callable[[List[str], Dict], None] + :param validator: Function that checks if the request is authenticated given the context. + :type validator: ActionPermissionValidator + """ + self.func: Callable[[List[str], Dict], None] = func + self.validator: ActionPermissionValidator = validator + + +class ActionManager: + """TODO.""" + + def __init__(self) -> None: + """TODO.""" + self.actions: Dict[str, Action] + + def process_request(self, request: List[str], context: Dict) -> None: + """Process action request.""" + action_key = request[0] + + if action_key not in self.actions: + msg = ( + f"Action request {request} could not be processed because {action_key} is not a valid action", + "within this ActionManager", + ) + _LOGGER.error(msg) + raise RuntimeError(msg) + + action = self.actions[action_key] + action_options = request[1:] + + if not action.validator(action_options, context): + _LOGGER.debug(f"Action request {request} was denied due to insufficient permissions") + return + + action.func(action_options, context) class SimComponent(BaseModel): """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" + model_config = ConfigDict(arbitrary_types_allowed=True) + uuid: str + "The component UUID." + + def __init__(self, **kwargs) -> None: + self.action_manager: Optional[ActionManager] = None + super().__init__(**kwargs) + @abstractmethod def describe_state(self) -> Dict: """ @@ -19,7 +129,7 @@ class SimComponent(BaseModel): """ return {} - def apply_action(self, action: List[str]) -> None: + def apply_action(self, action: List[str], context: Dict = {}) -> None: """ Apply an action to a simulation component. Action data is passed in as a 'namespaced' list of strings. @@ -34,16 +144,9 @@ class SimComponent(BaseModel): :param action: List describing the action to apply to this object. :type action: List[str] """ - possible_actions = self._possible_actions() - if action[0] in possible_actions: - # take the first element off the action list and pass the remaining arguments to the corresponding action - # function - possible_actions[action.pop(0)](action) - else: - raise ValueError(f"{self.__class__.__name__} received invalid action {action}") - - def _possible_actions(self) -> Dict[str, Callable[[List[str]], None]]: - return {} + if self.action_manager is None: + return + self.action_manager.process_request(action, context) def apply_timestep(self, timestep: int) -> None: """ diff --git a/src/primaite/simulator/domain/__init__.py b/src/primaite/simulator/domain/__init__.py index 6f59cf49..0e23133f 100644 --- a/src/primaite/simulator/domain/__init__.py +++ b/src/primaite/simulator/domain/__init__.py @@ -1,3 +1,3 @@ -from primaite.simulator.domain.account import Account +from primaite.simulator.domain.account import Account, AccountGroup, AccountType -__all__ = ["Account"] +__all__ = ["Account", "AccountGroup", "AccountType"] diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py index 374675a0..c134e916 100644 --- a/src/primaite/simulator/domain/account.py +++ b/src/primaite/simulator/domain/account.py @@ -1,6 +1,6 @@ """User account simulation.""" from enum import Enum -from typing import Dict, List, Set, TypeAlias +from typing import Callable, Dict, List, TypeAlias from primaite import getLogger from primaite.simulator.core import SimComponent @@ -40,6 +40,14 @@ class AccountStatus(Enum): disabled = 2 +class PasswordPolicyLevel(Enum): + """Complexity requirements for account passwords.""" + + low = 1 + medium = 2 + high = 3 + + class Account(SimComponent): """User accounts.""" @@ -55,38 +63,18 @@ class Account(SimComponent): "Account password." account_type: AccountType "Account Type, currently this can be service account (used by apps) or user account." - domain_groups: Set[AccountGroup] = [] - "Domain-wide groups that this account belongs to." - local_groups: Dict[__temp_node, List[AccountGroup]] - "For each node, whether this account has local/admin privileges on that node." status: AccountStatus = AccountStatus.disabled - def add_to_domain_group(self, group: AccountGroup) -> None: - """ - Add this account to a domain group. - - If the account is already a member of this group, nothing happens. - - :param group: The group to which to add this account. - :type group: AccountGroup - """ - self.domain_groups.add(group) - - def remove_from_domain_group(self, group: AccountGroup) -> None: - """ - Remove this account from a domain group. - - If the account is already not a member of that group, nothing happens. - - :param group: The group from which this account should be removed. - :type group: AccountGroup - """ - self.domain_groups.discard(group) - - def enable_account(self): + def enable(self): """Set the status to enabled.""" self.status = AccountStatus.enabled - def disable_account(self): + def disable(self): """Set the status to disabled.""" self.status = AccountStatus.disabled + + def _possible_actions(self) -> Dict[str, Callable[[List[str]], None]]: + return { + "enable": self.enable, + "disable": self.disable, + } diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index 5a14e80e..c9165bbf 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -1,13 +1,54 @@ -from typing import Set, TypeAlias +from typing import Dict, Final, List, TypeAlias from primaite.simulator.core import SimComponent -from primaite.simulator.domain import Account +from primaite.simulator.domain import Account, AccountGroup, AccountType -__temp_node = TypeAlias() # placeholder while nodes don't exist +# placeholder while these objects don't yet exist +__temp_node = TypeAlias() +__temp_application = TypeAlias() +__temp_folder = TypeAlias() +__temp_file = TypeAlias() class DomainController(SimComponent): """Main object for controlling the domain.""" - nodes: Set(__temp_node) = set() - accounts: Set(Account) = set() + # owned objects + accounts: List(Account) = [] + groups: Final[List[AccountGroup]] = list(AccountGroup) + + group_membership: Dict[AccountGroup, List[Account]] + + # references to non-owned objects + nodes: List(__temp_node) = [] + applications: List(__temp_application) = [] + folders: List(__temp_folder) = [] + files: List(__temp_file) = [] + + def register_account(self, account: Account) -> None: + """TODO.""" + ... + + def deregister_account(self, account: Account) -> None: + """TODO.""" + ... + + def create_account(self, username: str, password: str, account_type: AccountType) -> Account: + """TODO.""" + ... + + def rotate_all_credentials(self) -> None: + """TODO.""" + ... + + def rotate_account_credentials(self, account: Account) -> None: + """TODO.""" + ... + + def add_account_to_group(self, account: Account, group: AccountGroup) -> None: + """TODO.""" + ... + + def remove_account_from_group(self, account: Account, group: AccountGroup) -> None: + """TODO.""" + ... From 94617c57a4a70b96840004862d1cfc7467283cf2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 3 Aug 2023 13:24:27 +0100 Subject: [PATCH 054/980] Make register and deregister acct private --- src/primaite/simulator/domain/controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index c9165bbf..bdb5fbb0 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -25,11 +25,11 @@ class DomainController(SimComponent): folders: List(__temp_folder) = [] files: List(__temp_file) = [] - def register_account(self, account: Account) -> None: + def _register_account(self, account: Account) -> None: """TODO.""" ... - def deregister_account(self, account: Account) -> None: + def _deregister_account(self, account: Account) -> None: """TODO.""" ... From cac4779244cb7ae1f42cb76bd1c276bb0f1adf7f Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 3 Aug 2023 14:37:55 +0100 Subject: [PATCH 055/980] #1706 - Started adding the core node software required by all nodes. Made some tweaks to the Frame to have send and receive timestamp. --- src/primaite/simulator/core.py | 3 +- .../simulator/network/hardware/base.py | 185 +++++++++++------- .../network/transmission/data_link_layer.py | 24 +++ src/primaite/simulator/system/__init__.py | 0 .../simulator/system/processes/__init__.py | 0 .../simulator/system/processes/pcap.py | 61 ++++++ .../simulator/system/processes/sys_log.py | 87 ++++++++ .../simulator/system/services/__init__.py | 0 .../simulator/system/services/icmp.py | 0 src/primaite/simulator/system/software.py | 94 +++++++++ .../network/test_frame_transmission.py | 27 ++- 11 files changed, 400 insertions(+), 81 deletions(-) create mode 100644 src/primaite/simulator/system/__init__.py create mode 100644 src/primaite/simulator/system/processes/__init__.py create mode 100644 src/primaite/simulator/system/processes/pcap.py create mode 100644 src/primaite/simulator/system/processes/sys_log.py create mode 100644 src/primaite/simulator/system/services/__init__.py create mode 100644 src/primaite/simulator/system/services/icmp.py create mode 100644 src/primaite/simulator/system/software.py diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index d684a74b..2b84a2a6 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -3,12 +3,13 @@ from abc import abstractmethod from typing import Callable, Dict, List from uuid import uuid4 -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict class SimComponent(BaseModel): """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" + model_config = ConfigDict(arbitrary_types_allowed=True) uuid: str "The component UUID." diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index c1bed5b0..ce0e7f25 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -4,7 +4,7 @@ import re import secrets from enum import Enum from ipaddress import IPv4Address, IPv4Network -from typing import Any, Dict, List, Optional, Union +from typing import Any, Dict, List, Optional, Tuple, Union from primaite import getLogger from primaite.exceptions import NetworkError @@ -13,6 +13,8 @@ from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader +from primaite.simulator.system.processes.pcap import PCAP +from primaite.simulator.system.processes.sys_log import SysLog _LOGGER = getLogger(__name__) @@ -85,6 +87,7 @@ class NIC(SimComponent): "The Link to which the NIC is connected." enabled: bool = False "Indicates whether the NIC is enabled." + pcap: Optional[PCAP] = None def __init__(self, **kwargs): """ @@ -129,9 +132,10 @@ class NIC(SimComponent): """Attempt to enable the NIC.""" if not self.enabled: if self.connected_node: - if self.connected_node.hardware_state == HardwareState.ON: + if self.connected_node.hardware_state == NodeOperatingState.ON: self.enabled = True _LOGGER.info(f"NIC {self} enabled") + self.pcap = PCAP(hostname=self.connected_node.hostname, ip_address=self.ip_address) if self.connected_link: self.connected_link.endpoint_up() else: @@ -203,6 +207,8 @@ class NIC(SimComponent): :type frame: :class:`~primaite.simulator.network.osi_layers.Frame` """ if self.enabled: + frame.set_sent_timestamp() + self.pcap.capture(frame) self.connected_link.transmit_frame(sender_nic=self, frame=frame) return True else: @@ -219,6 +225,9 @@ class NIC(SimComponent): :type frame: :class:`~primaite.simulator.network.osi_layers.Frame` """ if self.enabled: + frame.decrement_ttl() + frame.set_received_timestamp() + self.pcap.capture(frame) self.connected_node.receive_frame(frame=frame, from_nic=self) return True else: @@ -281,19 +290,18 @@ class Link(SimComponent): super().__init__(**kwargs) self.endpoint_a.connect_link(self) self.endpoint_b.connect_link(self) - if self.up: - _LOGGER.info(f"Link up between {self.endpoint_a} and {self.endpoint_b}") + self.endpoint_up() def endpoint_up(self): """Let the Link know and endpoint has been brought up.""" if self.up: - _LOGGER.info(f"Link up between {self.endpoint_a} and {self.endpoint_b}") + _LOGGER.info(f"Link {self} up") def endpoint_down(self): """Let the Link know and endpoint has been brought down.""" if not self.up: self.current_load = 0.0 - _LOGGER.info(f"Link down between {self.endpoint_a} and {self.endpoint_b}") + _LOGGER.info(f"Link {self} down") @property def up(self) -> bool: @@ -318,20 +326,24 @@ class Link(SimComponent): :param frame: The network frame to be sent. :return: True if the Frame can be sent, otherwise False. """ - receiver_nic = self.endpoint_a - if receiver_nic == sender_nic: - receiver_nic = self.endpoint_b - frame_size = frame.size_Mbits - sent = receiver_nic.receive_frame(frame) - if sent: - # Frame transmitted successfully - # Load the frame size on the link - self.current_load += frame_size - _LOGGER.info(f"Link added {frame_size} Mbits, current load {self.current_load} Mbits") - return True - # Received NIC disabled, reply + if self._can_transmit(frame): + receiver_nic = self.endpoint_a + if receiver_nic == sender_nic: + receiver_nic = self.endpoint_b + frame_size = frame.size_Mbits + sent = receiver_nic.receive_frame(frame) + if sent: + # Frame transmitted successfully + # Load the frame size on the link + self.current_load += frame_size + _LOGGER.info(f"Added {frame_size:.3f} Mbits to {self}, current load {self.current_load:.3f} Mbits") + return True + # Received NIC disabled, reply - return False + return False + else: + _LOGGER.info(f"Cannot transmit frame as {self} is at capacity") + return False def reset_component_for_episode(self): """ @@ -359,15 +371,21 @@ class Link(SimComponent): """ pass + def __str__(self) -> str: + return f"{self.endpoint_a}<-->{self.endpoint_b}" -class HardwareState(Enum): - """Node hardware state enumeration.""" +class NodeOperatingState(Enum): + """Enumeration of Node Operating States.""" + + OFF = 0 + "The node is powered off." ON = 1 - OFF = 2 - RESETTING = 3 - SHUTTING_DOWN = 4 - BOOTING = 5 + "The node is powered on." + SHUTTING_DOWN = 2 + "The node is in the process of shutting down." + BOOTING = 3 + "The node is in the process of booting up." class Node(SimComponent): @@ -380,7 +398,7 @@ class Node(SimComponent): hostname: str "The node hostname on the network." - hardware_state: HardwareState = HardwareState.OFF + operating_state: NodeOperatingState = NodeOperatingState.OFF "The hardware state of the node." nics: Dict[str, NIC] = {} "The NICs on the node." @@ -397,25 +415,30 @@ class Node(SimComponent): "The nodes file system." arp_cache: Dict[IPv4Address, ARPEntry] = {} "The ARP cache." + sys_log: Optional[SysLog] = None revealed_to_red: bool = False "Informs whether the node has been revealed to a red agent." + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.sys_log = SysLog(self.hostname) + def turn_on(self): """Turn on the Node.""" - if self.hardware_state == HardwareState.OFF: - self.hardware_state = HardwareState.ON - _LOGGER.info(f"Node {self.hostname} turned on") + if self.operating_state == NodeOperatingState.OFF: + self.operating_state = NodeOperatingState.ON + self.sys_log.info("Turned on") for nic in self.nics.values(): nic.enable() def turn_off(self): """Turn off the Node.""" - if self.hardware_state == HardwareState.ON: + if self.operating_state == NodeOperatingState.ON: for nic in self.nics.values(): nic.disable() - self.hardware_state = HardwareState.OFF - _LOGGER.info(f"Node {self.hostname} turned off") + self.operating_state = NodeOperatingState.OFF + self.sys_log.info("Turned off") def connect_nic(self, nic: NIC): """ @@ -427,11 +450,12 @@ class Node(SimComponent): if nic.uuid not in self.nics: self.nics[nic.uuid] = nic nic.connected_node = self - _LOGGER.debug(f"Node {self.hostname} connected NIC {nic}") - if self.hardware_state == HardwareState.ON: + self.sys_log.info(f"Connected NIC {nic}") + if self.operating_state == NodeOperatingState.ON: nic.enable() else: - msg = f"Cannot connect NIC {nic} to Node {self.hostname} as it is already connected" + msg = f"Cannot connect NIC {nic} as it is already connected" + self.sys_log.logger.error(msg) _LOGGER.error(msg) raise NetworkError(msg) @@ -447,9 +471,10 @@ class Node(SimComponent): if nic or nic.uuid in self.nics: self.nics.pop(nic.uuid) nic.disable() - _LOGGER.debug(f"Node {self.hostname} disconnected NIC {nic}") + self.sys_log.info(f"Disconnected NIC {nic}") else: - msg = f"Cannot disconnect NIC {nic} from Node {self.hostname} as it is not connected" + msg = f"Cannot disconnect NIC {nic} as it is not connected" + self.sys_log.logger.error(msg) _LOGGER.error(msg) raise NetworkError(msg) @@ -461,7 +486,7 @@ class Node(SimComponent): :param mac_address: The MAC address associated with the IP address. :param nic: The NIC through which the NIC with the IP address is reachable. """ - _LOGGER.info(f"Node {self.hostname} Adding ARP cache entry for {mac_address}/{ip_address} via NIC {nic}") + self.sys_log.info(f"Adding ARP cache entry for {mac_address}/{ip_address} via NIC {nic}") arp_entry = ARPEntry(mac_address=mac_address, nic_uuid=nic.uuid) self.arp_cache[ip_address] = arp_entry @@ -504,7 +529,7 @@ class Node(SimComponent): """Perform a standard ARP request for a given target IP address.""" for nic in self.nics.values(): if nic.enabled: - _LOGGER.info(f"Node {self.hostname} sending ARP request from NIC {nic} for ip {target_ip_address}") + self.sys_log.info(f"Sending ARP request from NIC {nic} for ip {target_ip_address}") tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) # Network Layer @@ -530,35 +555,38 @@ class Node(SimComponent): :param arp_packet:The ARP packet to process. """ if arp_packet.request: - _LOGGER.info( - f"Node {self.hostname} received ARP request from {arp_packet.sender_mac_addr}/{arp_packet.sender_ip}" - ) - self._add_arp_cache_entry( - ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic - ) - arp_packet = arp_packet.generate_reply(from_nic.mac_address) - _LOGGER.info( - f"Node {self.hostname} sending ARP reply from {arp_packet.sender_mac_addr}/{arp_packet.sender_ip} " - f"to {arp_packet.target_ip}/{arp_packet.target_mac_addr} " + self.sys_log.info( + f"Received ARP request for {arp_packet.target_ip} from " + f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip} " ) + if arp_packet.target_ip == from_nic.ip_address: + self._add_arp_cache_entry( + ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic + ) + arp_packet = arp_packet.generate_reply(from_nic.mac_address) + self.sys_log.info( + f"Sending ARP reply from {arp_packet.sender_mac_addr}/{arp_packet.sender_ip} " + f"to {arp_packet.target_ip}/{arp_packet.target_mac_addr} " + ) - tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) + tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) - # Network Layer - ip_packet = IPPacket( - src_ip=arp_packet.sender_ip, - dst_ip=arp_packet.target_ip, - ) - # Data Link Layer - ethernet_header = EthernetHeader( - src_mac_addr=arp_packet.sender_mac_addr, dst_mac_addr=arp_packet.target_mac_addr - ) - frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) - self.send_frame(frame) + # Network Layer + ip_packet = IPPacket( + src_ip=arp_packet.sender_ip, + dst_ip=arp_packet.target_ip, + ) + # Data Link Layer + ethernet_header = EthernetHeader( + src_mac_addr=arp_packet.sender_mac_addr, dst_mac_addr=arp_packet.target_mac_addr + ) + frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) + self.send_frame(frame) + else: + self.sys_log.info(f"Ignoring ARP request for {arp_packet.target_ip}") else: - _LOGGER.info( - f"Node {self.hostname} received ARP response for {arp_packet.sender_ip} " - f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" + self.sys_log.info( + f"Received ARP response for {arp_packet.sender_ip} from {arp_packet.sender_mac_addr} via NIC {from_nic}" ) self._add_arp_cache_entry( ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic @@ -573,7 +601,7 @@ class Node(SimComponent): :param frame: The Frame containing the icmp packet to process. """ if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: - _LOGGER.info(f"Node {self.hostname} received echo request from {frame.ip.src_ip}") + self.sys_log.info(f"Received echo request from {frame.ip.src_ip}") target_mac_address = self._get_arp_cache_mac_address(frame.ip.src_ip) src_nic = self._get_arp_cache_nic(frame.ip.src_ip) tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) @@ -589,13 +617,14 @@ class Node(SimComponent): sequence=frame.icmp.sequence + 1, ) frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet) + self.sys_log.info(f"Sending echo reply to {frame.ip.src_ip}") src_nic.send_frame(frame) elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: - _LOGGER.info(f"Node {self.hostname} received echo reply from {frame.ip.src_ip}") - if frame.icmp.sequence <= 6: # 3 pings - self._ping(frame.ip.src_ip, sequence=frame.icmp.sequence, identifier=frame.icmp.identifier) + self.sys_log.info(f"Received echo reply from {frame.ip.src_ip}") - def _ping(self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None): + def _ping( + self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None + ) -> Tuple[int, Union[int, None]]: nic = self._get_arp_cache_nic(target_ip_address) if nic: sequence += 1 @@ -613,13 +642,15 @@ class Node(SimComponent): ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) icmp_packet = ICMPPacket(identifier=identifier, sequence=sequence) frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_packet) + self.sys_log.info(f"Sending echo request to {target_ip_address}") nic.send_frame(frame) + return sequence, icmp_packet.identifier else: - _LOGGER.info(f"Node {self.hostname} no entry in ARP cache for {target_ip_address}") + self.sys_log.info(f"No entry in ARP cache for {target_ip_address}") self._send_arp_request(target_ip_address) - self._ping(target_ip_address=target_ip_address) + return 0, None - def ping(self, target_ip_address: Union[IPv4Address, str]) -> bool: + def ping(self, target_ip_address: Union[IPv4Address, str], pings: int = 4) -> bool: """ Ping an IP address. @@ -630,11 +661,13 @@ class Node(SimComponent): """ if not isinstance(target_ip_address, IPv4Address): target_ip_address = IPv4Address(target_ip_address) - if self.hardware_state == HardwareState.ON: - _LOGGER.info(f"Node {self.hostname} attempting to ping {target_ip_address}") - self._ping(target_ip_address) + if self.operating_state == NodeOperatingState.ON: + self.sys_log.info(f"Attempting to ping {target_ip_address}") + sequence, identifier = 0, None + while sequence < pings: + sequence, identifier = self._ping(target_ip_address, sequence, identifier) return True - _LOGGER.info(f"Node {self.hostname} ping failed as the node is turned off") + self.sys_log.info("Ping failed as the node is turned off") return False def send_frame(self, frame: Frame): diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index 97a1a423..1b7ccf7d 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -1,3 +1,4 @@ +from datetime import datetime from typing import Any, Optional from pydantic import BaseModel @@ -99,6 +100,29 @@ class Frame(BaseModel): "PrimAITE header." payload: Optional[Any] = None "Raw data payload." + sent_timestamp: Optional[datetime] = None + "The time the Frame was sent from the original source NIC." + received_timestamp: Optional[datetime] = None + "The time the Frame was received at the final destination NIC." + + def decrement_ttl(self): + """Decrement the IPPacket ttl by 1.""" + self.ip.ttl -= 1 + + @property + def can_transmit(self) -> bool: + """Informs whether the Frame can transmit based on the IPPacket tll being >= 1.""" + return self.ip.ttl >= 1 + + def set_sent_timestamp(self): + """Set the sent_timestamp.""" + if not self.sent_timestamp: + self.sent_timestamp = datetime.now() + + def set_received_timestamp(self): + """Set the received_timestamp.""" + if not self.received_timestamp: + self.received_timestamp = datetime.now() @property def size(self) -> float: # noqa - Keep it as MBits as this is how they're expressed diff --git a/src/primaite/simulator/system/__init__.py b/src/primaite/simulator/system/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/processes/__init__.py b/src/primaite/simulator/system/processes/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/processes/pcap.py b/src/primaite/simulator/system/processes/pcap.py new file mode 100644 index 00000000..c502adc8 --- /dev/null +++ b/src/primaite/simulator/system/processes/pcap.py @@ -0,0 +1,61 @@ +import logging +from pathlib import Path + + +class _JSONFilter(logging.Filter): + def filter(self, record: logging.LogRecord) -> bool: + """Filter logs that start and end with '{' and '}' (JSON-like messages).""" + return record.getMessage().startswith("{") and record.getMessage().endswith("}") + + +class PCAP: + """ + A logger class for logging Frames as json strings. + + This is essentially a PrimAITE simulated version of PCAP. + + The PCAPs are logged to: //__pcap.log + """ + + def __init__(self, hostname: str, ip_address: str): + """ + Initialize the PCAP instance. + + :param hostname: The hostname for which PCAP logs are being recorded. + :param ip_address: The IP address associated with the PCAP logs. + """ + self.hostname = hostname + self.ip_address = str(ip_address) + self._setup_logger() + + def _setup_logger(self): + """Set up the logger configuration.""" + log_path = self._get_log_path() + + file_handler = logging.FileHandler(filename=log_path) + file_handler.setLevel(60) # Custom log level > CRITICAL to prevent any unwanted standard DEBUG-CRITICAL logs + + log_format = "%(message)s" + file_handler.setFormatter(logging.Formatter(log_format)) + + logger_name = f"{self.hostname}_{self.ip_address}_pcap" + self.logger = logging.getLogger(logger_name) + self.logger.setLevel(60) # Custom log level > CRITICAL to prevent any unwanted standard DEBUG-CRITICAL logs + self.logger.addHandler(file_handler) + + self.logger.addFilter(_JSONFilter()) + + def _get_log_path(self) -> Path: + """Get the path for the log file.""" + root = Path(__file__).parent.parent.parent.parent.parent.parent / "simulation_output" / self.hostname + root.mkdir(exist_ok=True, parents=True) + return root / f"{self.hostname}_{self.ip_address}_pcap.log" + + def capture(self, frame): # noqa Please don't make me, I'll have a circular import and cant use if TYPE_CHECKING ;( + """ + Capture a Frame and log it. + + :param frame: The PCAP frame to capture. + """ + msg = frame.model_dump_json() + self.logger.log(level=60, msg=msg) # Log at custom log level > CRITICAL diff --git a/src/primaite/simulator/system/processes/sys_log.py b/src/primaite/simulator/system/processes/sys_log.py new file mode 100644 index 00000000..27b35505 --- /dev/null +++ b/src/primaite/simulator/system/processes/sys_log.py @@ -0,0 +1,87 @@ +import logging +from pathlib import Path + + +class _NotJSONFilter(logging.Filter): + def filter(self, record: logging.LogRecord) -> bool: + """Filter logs that do not start and end with '{' and '}'.""" + return not record.getMessage().startswith("{") and not record.getMessage().endswith("}") + + +class SysLog: + """ + A simple logger class for writing the sys logs of a Node. + + Logs are logged to: //_sys.log + """ + + def __init__(self, hostname: str): + """ + Initialize the SysLog instance. + + :param hostname: The hostname for which logs are being recorded. + """ + self.hostname = hostname + self._setup_logger() + + def _setup_logger(self): + """Set up the logger configuration.""" + log_path = self._get_log_path() + + file_handler = logging.FileHandler(filename=log_path) + file_handler.setLevel(logging.DEBUG) + + log_format = "%(asctime)s %(levelname)s: %(message)s" + file_handler.setFormatter(logging.Formatter(log_format)) + + self.logger = logging.getLogger(f"{self.hostname}_sys_log") + self.logger.setLevel(logging.DEBUG) + self.logger.addHandler(file_handler) + + self.logger.addFilter(_NotJSONFilter()) + + def _get_log_path(self) -> Path: + """Get the path for the log file.""" + root = Path(__file__).parent.parent.parent.parent.parent.parent / "simulation_output" / self.hostname + root.mkdir(exist_ok=True, parents=True) + return root / f"{self.hostname}_sys.log" + + def debug(self, msg: str): + """ + Log a debug message. + + :param msg: The message to log. + """ + self.logger.debug(msg) + + def info(self, msg: str): + """ + Log an info message. + + :param msg: The message to log. + """ + self.logger.info(msg) + + def warning(self, msg: str): + """ + Log a warning message. + + :param msg: The message to log. + """ + self.logger.warning(msg) + + def error(self, msg: str): + """ + Log an error message. + + :param msg: The message to log. + """ + self.logger.error(msg) + + def critical(self, msg: str): + """ + Log a critical message. + + :param msg: The message to log. + """ + self.logger.critical(msg) diff --git a/src/primaite/simulator/system/services/__init__.py b/src/primaite/simulator/system/services/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/services/icmp.py b/src/primaite/simulator/system/services/icmp.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py new file mode 100644 index 00000000..a5d0bd18 --- /dev/null +++ b/src/primaite/simulator/system/software.py @@ -0,0 +1,94 @@ +from enum import Enum + +from primaite.simulator.core import SimComponent + + +class SoftwareHealthState(Enum): + """Enumeration of the Software Health States.""" + + GOOD = 1 + "The software is in a good and healthy condition." + COMPROMISED = 2 + "The software's security has been compromised." + OVERWHELMED = 3 + "he software is overwhelmed and not functioning properly." + PATCHING = 4 + "The software is undergoing patching or updates." + + +class ApplicationOperatingState(Enum): + """Enumeration of Application Operating States.""" + + CLOSED = 0 + "The application is closed or not running." + RUNNING = 1 + "The application is running." + INSTALLING = 3 + "The application is being installed or updated." + + +class ServiceOperatingState(Enum): + """Enumeration of Service Operating States.""" + + STOPPED = 0 + "The service is not running." + RUNNING = 1 + "The service is currently running." + RESTARTING = 2 + "The service is in the process of restarting." + INSTALLING = 3 + "The service is being installed or updated." + PAUSED = 4 + "The service is temporarily paused." + DISABLED = 5 + "The service is disabled and cannot be started." + + +class ProcessOperatingState(Enum): + """Enumeration of Process Operating States.""" + + RUNNING = 1 + "The process is running." + PAUSED = 2 + "The process is temporarily paused." + + +class SoftwareCriticality(Enum): + """Enumeration of Software Criticality Levels.""" + + LOWEST = 1 + "The lowest level of criticality." + LOW = 2 + "A low level of criticality." + MEDIUM = 3 + "A medium level of criticality." + HIGH = 4 + "A high level of criticality." + HIGHEST = 5 + "The highest level of criticality." + + +class Software(SimComponent): + """ + Represents software information along with its health, criticality, and status. + + This class inherits from the Pydantic BaseModel and provides a structured way to store + information about software entities. + + Attributes: + name (str): The name of the software. + health_state_actual (SoftwareHealthState): The actual health state of the software. + health_state_visible (SoftwareHealthState): The health state of the software visible to users. + criticality (SoftwareCriticality): The criticality level of the software. + patching_count (int, optional): The count of patches applied to the software. Default is 0. + scanning_count (int, optional): The count of times the software has been scanned. Default is 0. + revealed_to_red (bool, optional): Indicates if the software has been revealed to red team. Default is False. + """ + + name: str + health_state_actual: SoftwareHealthState + health_state_visible: SoftwareHealthState + criticality: SoftwareCriticality + patching_count: int = 0 + scanning_count: int = 0 + revealed_to_red: bool = False diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index 32abd0ef..82e97049 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -16,10 +16,29 @@ def test_node_to_node_ping(): assert node_a.ping("192.168.0.11") - node_a.turn_off() - - assert not node_a.ping("192.168.0.11") +def test_multi_nic(): + node_a = Node(hostname="node_a") + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") + node_a.connect_nic(nic_a) node_a.turn_on() - assert node_a.ping("192.168.0.11") + node_b = Node(hostname="node_b") + nic_b1 = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") + nic_b2 = NIC(ip_address="10.0.0.12", subnet_mask="255.0.0.0", gateway="10.0.0.1") + node_b.connect_nic(nic_b1) + node_b.connect_nic(nic_b2) + node_b.turn_on() + + node_c = Node(hostname="node_c") + nic_c = NIC(ip_address="10.0.0.13", subnet_mask="255.0.0.0", gateway="10.0.0.1") + node_c.connect_nic(nic_c) + node_c.turn_on() + + link_a_b1 = Link(endpoint_a=nic_a, endpoint_b=nic_b1) + + link_b2_c = Link(endpoint_a=nic_b2, endpoint_b=nic_c) + + node_a.ping("192.168.0.11") + + node_c.ping("10.0.0.12") From fed65db7fc3ec6c8fc1374a95797b75ec62b5788 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 3 Aug 2023 16:04:23 +0100 Subject: [PATCH 056/980] Updated the What is PrimAITE? section in index.rst. Dropped the use of sphinx-code-tabs in the docs as building the docs in pdf (make latexpdf) is suddenly complaining about the tab buttons. --- docs/conf.py | 1 - docs/index.rst | 65 ++++++++++++++++-- docs/source/getting_started.rst | 114 +++++++++++++++---------------- docs/source/primaite_session.rst | 86 +++++++++++------------ pyproject.toml | 1 - 5 files changed, 159 insertions(+), 108 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 4a805916..efd60b49 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -43,7 +43,6 @@ extensions = [ "sphinx.ext.viewcode", # Add a link to the Python source code for classes, functions etc. "sphinx.ext.todo", "sphinx_copybutton", # Adds a copy button to code blocks - "sphinx_code_tabs", # Enables tabbed code blocks ] diff --git a/docs/index.rst b/docs/index.rst index 2c7d4690..b2c5cfaa 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -8,11 +8,68 @@ Welcome to PrimAITE's documentation What is PrimAITE? ----------------- -PrimAITE (Primary-level AI Training Environment) is a simulation environment for training AI under the ARCD programme. It incorporates the functionality required of a Primary-level environment, as specified in the Dstl ARCD Training Environment Matrix document: +Overview +^^^^^^^^ + +The ARCD Primary-level AI Training Environment (**PrimAITE**) provides an effective simulation capability for the purposes of training and evaluating AI in a cyber-defensive role. It incorporates the functionality required of a primary-level ARCD environment, which includes: + +- The ability to model a relevant platform / system context; +- Modelling an adversarial agent that the defensive agent can be trained and evaluated against; +- The ability to model key characteristics of a platform / system by representing connections, IP addresses, ports, operating systems, services and traffic loading on links; +- Modelling background pattern-of-life; +- Operates at machine-speed to enable fast training cycles. + +Features +^^^^^^^^ + +PrimAITE incorporates the following features: + +- Highly configurable (via YAML files) to provide the means to model a variety of platform / system laydowns and adversarial attack scenarios; +- A Reinforcement Learning (RL) reward function based on (a) the ability to counter the modelled adversarial cyber-attack, and (b) the ability to ensure success; +- Provision of logging to support AI performance / effectiveness assessment; +- Uses the concept of Information Exchange Requirements (IERs) to model background pattern of life and adversarial behaviour; +- An Access Control List (ACL) function, mimicking the behaviour of a network firewall, is applied across the model, following standard ACL rule format (e.g. DENY/ALLOW, source IP address, destination IP address, protocol and port); +- Application of traffic to the links of the platform / system laydown adheres to the ACL ruleset; +- Presents both an OpenAI gym and Ray RLLib interface to the environment, allowing integration with any compliant defensive agents; +- Allows for the saving and loading of trained defensive agents; +- Stochastic adversarial agent behaviour; +- Full capture of discrete logs relating to agent training or evaluation (system state, agent actions taken, instantaneous and average reward for every step of every episode); +- Distinct control over running a training and / or evaluation session; +- NetworkX provides laydown visualisation capability. + +Architecture +^^^^^^^^^^^^ + +PrimAITE is a Python application and is therefore Operating System agnostic. The OpenAI gym and Ray RLLib frameworks are employed to provide an interface and source for AI agents. Configuration of PrimAITE is achieved via included YAML files which support full control over the platform / system laydown being modelled, background pattern of life, adversarial (red agent) behaviour, and step and episode count. NetworkX based nodes and links host Python classes to present attributes and methods, and hence a more representative platform / system can be modelled within the simulation. + + + +Training & Evaluation Capability +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +PrimAITE provides a training and evaluation capability to AI agents in the context of cyber-attack, via its OpenAI Gym and RLLib compliant interface. Scenarios can be constructed to reflect platform / system laydowns consisting of any configuration of nodes (e.g. PCs, servers, switches etc.) and network links between them. All nodes can be configured to model services (and their status) and the traffic loading between them over the network links. Traffic loading is broken down into a per service granularity, relating directly to a protocol (e.g. Service A would be configured as a TCP service, and TCP traffic then flows between instances of Service A under the direction of a tailored IER). Highlights of PrimAITE’s training and evaluation capability are: + +- The scenario is not bound to a representation of any platform, system, or technology; +- Fully configurable (network / system laydown, IERs, node pattern-of-life, ACL, number of episodes, steps per episode) and repeatable to suit the requirements of AI agents; +- Can integrate with any OpenAI Gym or RLLib compliant AI agent. + +Use of PrimAITE default scenarios within ARCD is supported by a “Use Case Profile” tailored to the scenario. + +AI Assessment Capability +^^^^^^^^^^^^^^^^^^^^^^^^ + +PrimAITE includes the capability to support in-depth assessment of cyber defence AI by outputting logs of the environment state and AI behaviour throughout both training and evaluation sessions. These logs include the following data: + +- Timestamp; +- Episode and step number; +- Agent identifier; +- Observation space; +- Action taken (by defensive AI); +- Reward value. + +Logs are available in CSV format and provide coverage of the above data for every step of every episode. + -* The ability to model a relevant platform / system context; -* The ability to model key characteristics of a platform / system by representing connections, IP addresses, ports, traffic loading, operating systems, file system, services and processes; -* Operates at machine-speed to enable fast training cycles. What is PrimAITE built with diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index f07f1d27..1dbf9dec 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -14,20 +14,19 @@ Pre-Requisites In order to get **PrimAITE** installed, you will need to have a python version between 3.8 and 3.10 installed. If you don't already have it, this is how to install it: -.. tabs:: lang +.. code-block:: bash + :caption: Unix - .. code-tab:: bash - :caption: Unix + sudo add-apt-repository ppa:deadsnakes/ppa + sudo apt install python3.10 + sudo apt-get install python3-pip + sudo apt-get install python3-venv - sudo add-apt-repository ppa:deadsnakes/ppa - sudo apt install python3.10 - sudo apt-get install python3-pip - sudo apt-get install python3-venv - .. code-tab:: text - :caption: Windows (Powershell) +.. code-block:: text + :caption: Windows (Powershell) - - Manual install from: https://www.python.org/downloads/release/python-31011/ + - Manual install from: https://www.python.org/downloads/release/python-31011/ **PrimAITE** is designed to be OS-agnostic, and thus should work on most variations/distros of Linux, Windows, and MacOS. @@ -36,30 +35,30 @@ Install PrimAITE 1. Create a primaite directory in your home directory: -.. tabs:: lang - .. code-tab:: bash - :caption: Unix - mkdir ~/primaite/2.0.0 +.. code-block:: bash + :caption: Unix - .. code-tab:: powershell - :caption: Windows (Powershell) + mkdir ~/primaite/2.0.0 - mkdir ~\primaite\2.0.0 +.. code-block:: powershell + :caption: Windows (Powershell) + + mkdir ~\primaite\2.0.0 2. Navigate to the primaite directory and create a new python virtual environment (venv) -.. tabs:: lang - .. code-tab:: bash - :caption: Unix - cd ~/primaite/2.0.0 - python3 -m venv .venv +.. code-block:: bash + :caption: Unix - .. code-tab:: powershell - :caption: Windows (Powershell) + cd ~/primaite/2.0.0 + python3 -m venv .venv + +.. code-block:: powershell + :caption: Windows (Powershell) cd ~\primaite\2.0.0 python3 -m venv .venv @@ -67,44 +66,41 @@ Install PrimAITE 3. Activate the venv -.. tabs:: lang - .. code-tab:: bash - :caption: Unix +.. code-block:: bash + :caption: Unix - source .venv/bin/activate + source .venv/bin/activate - .. code-tab:: powershell - :caption: Windows (Powershell) +.. code-block:: powershell + :caption: Windows (Powershell) - .\.venv\Scripts\activate + .\.venv\Scripts\activate 4. Install PrimAITE using pip from PyPi -.. tabs:: lang - .. code-tab:: bash - :caption: Unix +.. code-block:: bash + :caption: Unix - pip install primaite + pip install primaite - .. code-tab:: powershell - :caption: Windows (Powershell) +.. code-block:: powershell + :caption: Windows (Powershell) - pip install primaite + pip install primaite 5. Perform the PrimAITE setup -.. tabs:: lang - .. code-tab:: bash - :caption: Unix +.. code-block:: bash + :caption: Unix - primaite setup + primaite setup - .. code-tab:: powershell - :caption: Windows (Powershell) +.. code-block:: powershell + :caption: Windows (Powershell) primaite setup @@ -123,33 +119,31 @@ of your choice: Create and activate your Python virtual environment (venv) -.. tabs:: lang - .. code-tab:: bash - :caption: Unix +.. code-block:: bash + :caption: Unix - python3 -m venv venv - source venv/bin/activate + python3 -m venv venv + source venv/bin/activate - .. code-tab:: powershell - :caption: Windows (Powershell) +.. code-block:: powershell + :caption: Windows (Powershell) - python3 -m venv venv - .\venv\Scripts\activate + python3 -m venv venv + .\venv\Scripts\activate Install PrimAITE with the dev extra -.. tabs:: lang - .. code-tab:: bash - :caption: Unix +.. code-block:: bash + :caption: Unix - pip install -e .[dev] + pip install -e .[dev] - .. code-tab:: powershell - :caption: Windows (Powershell) +.. code-block:: powershell + :caption: Windows (Powershell) - pip install -e .[dev] + pip install -e .[dev] To view the complete list of packages installed during PrimAITE installation, go to the dependencies page (:ref:`Dependencies`). diff --git a/docs/source/primaite_session.rst b/docs/source/primaite_session.rst index 15ba9f4c..8ccc9070 100644 --- a/docs/source/primaite_session.rst +++ b/docs/source/primaite_session.rst @@ -15,31 +15,31 @@ A PrimAITE session can be ran either with the ``primaite session`` command from Both the ``primaite session`` and :func:`primaite.main.run` take a training config and a lay down config as parameters. -.. tabs:: - - .. code-tab:: bash - :caption: Unix CLI - - cd ~/primaite/2.0.0 - source ./.venv/bin/activate - primaite session --tc ./config/my_training_config.yaml --ldc ./config/my_lay_down_config.yaml - - .. code-tab:: powershell - :caption: Powershell CLI - - cd ~\primaite\2.0.0 - .\.venv\Scripts\activate - primaite session --tc .\config\my_training_config.yaml --ldc .\config\my_lay_down_config.yaml - .. code-tab:: python - :caption: Python +.. code-block:: bash + :caption: Unix CLI - from primaite.main import run + cd ~/primaite/2.0.0 + source ./.venv/bin/activate + primaite session --tc ./config/my_training_config.yaml --ldc ./config/my_lay_down_config.yaml - training_config = - lay_down_config = - run(training_config, lay_down_config) +.. code-block:: powershell + :caption: Powershell CLI + + cd ~\primaite\2.0.0 + .\.venv\Scripts\activate + primaite session --tc .\config\my_training_config.yaml --ldc .\config\my_lay_down_config.yaml + + +.. code-block:: python + :caption: Python + + from primaite.main import run + + training_config = + lay_down_config = + run(training_config, lay_down_config) When a session is ran, a session output sub-directory is created in the users app sessions directory (``~/primaite/2.0.0/sessions``). The sub-directory is formatted as such: ``~/primaite/2.0.0/sessions//_/`` @@ -51,31 +51,33 @@ For example, when running a session at 17:30:00 on 31st January 2023, the sessio To run a PrimAITE session using legacy training or laydown config files, add the ``--legacy-tc`` and/or ``legacy-ldc`` options. -.. tabs:: - - .. code-tab:: bash - :caption: Unix CLI - - cd ~/primaite/2.0.0 - source ./.venv/bin/activate - primaite session --tc ./config/my_legacy_training_config.yaml --legacy-tc --ldc ./config/my_legacy_lay_down_config.yaml --legacy-ldc - - .. code-tab:: powershell - :caption: Powershell CLI - - cd ~\primaite\2.0.0 - .\.venv\Scripts\activate - primaite session --tc .\config\my_legacy_training_config.yaml --legacy-tc --ldc .\config\my_legacy_lay_down_config.yaml --legacy-ldc - .. code-tab:: python - :caption: Python +.. code-block:: bash + :caption: Unix CLI + + cd ~/primaite/2.0.0 + source ./.venv/bin/activate + primaite session --tc ./config/my_legacy_training_config.yaml --legacy-tc --ldc ./config/my_legacy_lay_down_config.yaml --legacy-ldc + +.. code-block:: powershell + :caption: Powershell CLI + + cd ~\primaite\2.0.0 + .\.venv\Scripts\activate + primaite session --tc .\config\my_legacy_training_config.yaml --legacy-tc --ldc .\config\my_legacy_lay_down_config.yaml --legacy-ldc + + +.. code-block:: python + :caption: Python + + from primaite.main import run + + training_config = + lay_down_config = + run(training_config, lay_down_config, legacy_training_config=True, legacy_lay_down_config=True) - from primaite.main import run - training_config = - lay_down_config = - run(training_config, lay_down_config, legacy_training_config=True, legacy_lay_down_config=True) Outputs diff --git a/pyproject.toml b/pyproject.toml index b66b0168..5a28eefd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,6 @@ dev = [ "pytest-flake8==1.1.1", "setuptools==66", "Sphinx==6.1.3", - "sphinx-code-tabs==0.5.3", "sphinx-copybutton==0.5.2", "wheel==0.38.4" ] From 2a680c1e4817764f92887a7e15d0807b5c4f5d31 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 3 Aug 2023 16:26:33 +0100 Subject: [PATCH 057/980] Test my validators --- src/primaite/simulator/core.py | 32 +--- src/primaite/simulator/domain/__init__.py | 3 - src/primaite/simulator/domain/account.py | 18 +- src/primaite/simulator/domain/controller.py | 66 +++++-- .../component_creation/__init__.py | 0 .../test_permission_system.py | 171 ++++++++++++++++++ 6 files changed, 235 insertions(+), 55 deletions(-) create mode 100644 tests/integration_tests/component_creation/__init__.py create mode 100644 tests/integration_tests/component_creation/test_permission_system.py diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index eaedc85a..17e09f85 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -1,11 +1,11 @@ """Core of the PrimAITE Simulator.""" from abc import ABC, abstractmethod from typing import Callable, Dict, List, Optional +from uuid import uuid4 -from pydantic import BaseModel, ConfigDict +from pydantic import BaseModel, ConfigDict, Extra from primaite import getLogger -from primaite.simulator.domain import AccountGroup _LOGGER = getLogger(__name__) @@ -33,23 +33,6 @@ class AllowAllValidator(ActionPermissionValidator): return True -class GroupMembershipValidator(ActionPermissionValidator): - """Permit actions based on group membership.""" - - def __init__(self, allowed_groups: List[AccountGroup]) -> None: - """TODO.""" - self.allowed_groups = allowed_groups - - def __call__(self, request: List[str], context: Dict) -> bool: - """Permit the action if the request comes from an account which belongs to the right group.""" - # if context request source is part of any groups mentioned in self.allow_groups, return true, otherwise false - requestor_groups: List[str] = context["request_source"]["groups"] - for allowed_group in self.allowed_groups: - if allowed_group.name in requestor_groups: - return True - return False - - class Action: """ This object stores data related to a single action. @@ -83,7 +66,7 @@ class ActionManager: def __init__(self) -> None: """TODO.""" - self.actions: Dict[str, Action] + self.actions: Dict[str, Action] = {} def process_request(self, request: List[str], context: Dict) -> None: """Process action request.""" @@ -106,17 +89,20 @@ class ActionManager: action.func(action_options, context) + def add_action(self, name: str, action: Action) -> None: + self.actions[name] = action + class SimComponent(BaseModel): """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" - model_config = ConfigDict(arbitrary_types_allowed=True) - uuid: str + model_config = ConfigDict(arbitrary_types_allowed=True, extra=Extra.allow) + uuid: str = str(uuid4()) "The component UUID." def __init__(self, **kwargs) -> None: - self.action_manager: Optional[ActionManager] = None super().__init__(**kwargs) + self.action_manager: Optional[ActionManager] = None @abstractmethod def describe_state(self) -> Dict: diff --git a/src/primaite/simulator/domain/__init__.py b/src/primaite/simulator/domain/__init__.py index 0e23133f..e69de29b 100644 --- a/src/primaite/simulator/domain/__init__.py +++ b/src/primaite/simulator/domain/__init__.py @@ -1,3 +0,0 @@ -from primaite.simulator.domain.account import Account, AccountGroup, AccountType - -__all__ = ["Account", "AccountGroup", "AccountType"] diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py index c134e916..0f59db2e 100644 --- a/src/primaite/simulator/domain/account.py +++ b/src/primaite/simulator/domain/account.py @@ -1,6 +1,6 @@ """User account simulation.""" from enum import Enum -from typing import Callable, Dict, List, TypeAlias +from typing import Any, Callable, Dict, List from primaite import getLogger from primaite.simulator.core import SimComponent @@ -8,9 +8,6 @@ from primaite.simulator.core import SimComponent _LOGGER = getLogger(__name__) -__temp_node = TypeAlias() # placeholder while nodes don't exist - - class AccountType(Enum): """Whether the account is intended for a user to log in or for a service to use.""" @@ -20,19 +17,6 @@ class AccountType(Enum): "User accounts are used to allow agents to log in and perform actions" -class AccountGroup(Enum): - """Permissions are set at group-level and accounts can belong to these groups.""" - - local_user = 1 - "For performing basic actions on a node" - domain_user = 2 - "For performing basic actions to the domain" - local_admin = 3 - "For full access to actions on a node" - domain_admin = 4 - "For full access" - - class AccountStatus(Enum): """Whether the account is active.""" diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index bdb5fbb0..7cb3f4a6 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -1,29 +1,71 @@ -from typing import Dict, Final, List, TypeAlias +from enum import Enum +from typing import Any, Dict, Final, List + +from primaite.simulator.core import ActionPermissionValidator, SimComponent +from primaite.simulator.domain.account import Account, AccountType -from primaite.simulator.core import SimComponent -from primaite.simulator.domain import Account, AccountGroup, AccountType # placeholder while these objects don't yet exist -__temp_node = TypeAlias() -__temp_application = TypeAlias() -__temp_folder = TypeAlias() -__temp_file = TypeAlias() +class temp_node: + pass + + +class temp_application: + pass + + +class temp_folder: + pass + + +class temp_file: + pass + + +class AccountGroup(Enum): + """Permissions are set at group-level and accounts can belong to these groups.""" + + local_user = 1 + "For performing basic actions on a node" + domain_user = 2 + "For performing basic actions to the domain" + local_admin = 3 + "For full access to actions on a node" + domain_admin = 4 + "For full access" + + +class GroupMembershipValidator(ActionPermissionValidator): + """Permit actions based on group membership.""" + + def __init__(self, allowed_groups: List[AccountGroup]) -> None: + """TODO.""" + self.allowed_groups = allowed_groups + + def __call__(self, request: List[str], context: Dict) -> bool: + """Permit the action if the request comes from an account which belongs to the right group.""" + # if context request source is part of any groups mentioned in self.allow_groups, return true, otherwise false + requestor_groups: List[str] = context["request_source"]["groups"] + for allowed_group in self.allowed_groups: + if allowed_group.name in requestor_groups: + return True + return False class DomainController(SimComponent): """Main object for controlling the domain.""" # owned objects - accounts: List(Account) = [] + accounts: List[Account] = [] groups: Final[List[AccountGroup]] = list(AccountGroup) group_membership: Dict[AccountGroup, List[Account]] # references to non-owned objects - nodes: List(__temp_node) = [] - applications: List(__temp_application) = [] - folders: List(__temp_folder) = [] - files: List(__temp_file) = [] + nodes: List[temp_node] = [] + applications: List[temp_application] = [] + folders: List[temp_folder] = [] + files: List[temp_file] = [] def _register_account(self, account: Account) -> None: """TODO.""" diff --git a/tests/integration_tests/component_creation/__init__.py b/tests/integration_tests/component_creation/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration_tests/component_creation/test_permission_system.py b/tests/integration_tests/component_creation/test_permission_system.py new file mode 100644 index 00000000..acc35b72 --- /dev/null +++ b/tests/integration_tests/component_creation/test_permission_system.py @@ -0,0 +1,171 @@ +from enum import Enum +from typing import Dict, List, Literal + +import pytest + +from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent +from primaite.simulator.domain.controller import AccountGroup, GroupMembershipValidator + + +def test_group_action_validation() -> None: + """Check that actions are denied when an unauthorised request is made.""" + + class Folder(SimComponent): + name: str + + def describe_state(self) -> Dict: + return super().describe_state() + + class Node(SimComponent): + name: str + folders: List[Folder] = [] + + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.action_manager = ActionManager() + + self.action_manager.add_action( + "create_folder", + Action( + func=lambda request, context: self.create_folder(request[0]), + validator=GroupMembershipValidator([AccountGroup.local_admin, AccountGroup.domain_admin]), + ), + ) + + def describe_state(self) -> Dict: + return super().describe_state() + + def create_folder(self, folder_name: str) -> None: + new_folder = Folder(uuid="0000-0000-0001", name=folder_name) + self.folders.append(new_folder) + + def remove_folder(self, folder: Folder) -> None: + self.folders = [x for x in self.folders if x is not folder] + + permitted_context = {"request_source": {"agent": "BLUE", "account": "User1", "groups": ["local_admin"]}} + + my_node = Node(uuid="0000-0000-1234", name="pc") + my_node.apply_action(["create_folder", "memes"], context=permitted_context) + assert len(my_node.folders) == 1 + assert my_node.folders[0].name == "memes" + + invalid_context = {"request_source": {"agent": "BLUE", "account": "User1", "groups": ["local_user", "domain_user"]}} + + my_node.apply_action(["create_folder", "memes2"], context=invalid_context) + assert len(my_node.folders) == 1 + assert my_node.folders[0].name == "memes" + + +def test_hierarchical_action_with_validation() -> None: + """Check that validation works with sub-objects""" + + class Application(SimComponent): + name: str + state: Literal["on", "off", "disabled"] = "off" + + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.action_manager = ActionManager() + + self.action_manager.add_action( + "turn_on", + Action( + func=lambda request, context: self.turn_on(), + validator=AllowAllValidator(), + ), + ) + self.action_manager.add_action( + "turn_off", + Action( + func=lambda request, context: self.turn_off(), + validator=AllowAllValidator(), + ), + ) + self.action_manager.add_action( + "disable", + Action( + func=lambda request, context: self.disable(), + validator=GroupMembershipValidator([AccountGroup.local_admin, AccountGroup.domain_admin]), + ), + ) + self.action_manager.add_action( + "enable", + Action( + func=lambda request, context: self.enable(), + validator=GroupMembershipValidator([AccountGroup.local_admin, AccountGroup.domain_admin]), + ), + ) + + def describe_state(self) -> Dict: + return super().describe_state() + + def disable(self) -> None: + self.status = "disabled" + + def enable(self) -> None: + if self.status == "disabled": + self.status = "off" + + def turn_on(self) -> None: + if self.status == "off": + self.status = "on" + + def turn_off(self) -> None: + if self.status == "on": + self.status = "off" + + class Node(SimComponent): + name: str + state: Literal["on", "off"] = "on" + apps: List[Application] = [] + + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.action_manager = ActionManager() + + self.action_manager.add_action( + "apps", + Action( + func=lambda request, context: self.send_action_to_app(request.pop(0), request, context), + validator=AllowAllValidator(), + ), + ) + + def describe_state(self) -> Dict: + return super().describe_state() + + def install_app(self, app_name: str) -> None: + new_app = Application(name=app_name) + self.apps.append(new_app) + + def send_action_to_app(self, app_name: str, options: List[str], context: Dict): + for app in self.apps: + if app_name == app.name: + app.apply_action(options) + break + else: + msg = f"Node has no app with name {app_name}" + raise LookupError(msg) + + my_node = Node(name="pc") + my_node.install_app("Chrome") + my_node.install_app("Firefox") + + non_admin_context = { + "request_source": {"agent": "BLUE", "account": "User1", "groups": ["local_user", "domain_user"]} + } + + admin_context = { + "request_source": { + "agent": "BLUE", + "account": "User1", + "groups": ["local_admin", "domain_admin", "local_user", "domain_user"], + } + } + + my_node.apply_action(["apps", "Chrome", "disable"], non_admin_context) + my_node.apply_action(["apps", "Firefox", "turn_on"], non_admin_context) + + assert my_node.apps[0].name == "Chrome" + assert my_node.apps[1].name == "Firefox" + assert my_node.apps[0].state == ... # TODO: finish From 04f1cb0dc6720c4ddf1dec60faaef8ca5595f154 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 3 Aug 2023 21:30:13 +0100 Subject: [PATCH 058/980] #1706 - Got the code services, application, and process base classes stubbed out. Need them now so that I can leverage them for core node services required. --- src/primaite/simulator/core.py | 2 +- .../simulator/network/hardware/base.py | 12 +- .../simulator/system/applications/__init__.py | 0 .../system/applications/application.py | 86 +++++++++++ src/primaite/simulator/system/arp_cache.py | 30 ++++ .../{processes/pcap.py => packet_capture.py} | 16 +- .../simulator/system/processes/process.py | 37 +++++ .../simulator/system/services/service.py | 87 +++++++++++ src/primaite/simulator/system/software.py | 142 ++++++++++++------ .../system/{processes => }/sys_log.py | 46 +++--- .../network/test_frame_transmission.py | 2 +- 11 files changed, 378 insertions(+), 82 deletions(-) create mode 100644 src/primaite/simulator/system/applications/__init__.py create mode 100644 src/primaite/simulator/system/applications/application.py create mode 100644 src/primaite/simulator/system/arp_cache.py rename src/primaite/simulator/system/{processes/pcap.py => packet_capture.py} (78%) create mode 100644 src/primaite/simulator/system/processes/process.py create mode 100644 src/primaite/simulator/system/services/service.py rename src/primaite/simulator/system/{processes => }/sys_log.py (51%) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 2b84a2a6..2125c693 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -64,7 +64,7 @@ class SimComponent(BaseModel): """ pass - def reset_component_for_episode(self): + def reset_component_for_episode(self, episode: int): """ Reset this component to its original state for a new episode. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index ce0e7f25..138c444c 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -13,8 +13,8 @@ from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader -from primaite.simulator.system.processes.pcap import PCAP -from primaite.simulator.system.processes.sys_log import SysLog +from primaite.simulator.system.packet_capture import PacketCapture +from primaite.simulator.system.sys_log import SysLog _LOGGER = getLogger(__name__) @@ -87,7 +87,7 @@ class NIC(SimComponent): "The Link to which the NIC is connected." enabled: bool = False "Indicates whether the NIC is enabled." - pcap: Optional[PCAP] = None + pcap: Optional[PacketCapture] = None def __init__(self, **kwargs): """ @@ -132,10 +132,10 @@ class NIC(SimComponent): """Attempt to enable the NIC.""" if not self.enabled: if self.connected_node: - if self.connected_node.hardware_state == NodeOperatingState.ON: + if self.connected_node.operating_state == NodeOperatingState.ON: self.enabled = True _LOGGER.info(f"NIC {self} enabled") - self.pcap = PCAP(hostname=self.connected_node.hostname, ip_address=self.ip_address) + self.pcap = PacketCapture(hostname=self.connected_node.hostname, ip_address=self.ip_address) if self.connected_link: self.connected_link.endpoint_up() else: @@ -393,7 +393,7 @@ class Node(SimComponent): A basic Node class. :param hostname: The node hostname on the network. - :param hardware_state: The hardware state of the node. + :param operating_state: The node operating state. """ hostname: str diff --git a/src/primaite/simulator/system/applications/__init__.py b/src/primaite/simulator/system/applications/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py new file mode 100644 index 00000000..31a645b5 --- /dev/null +++ b/src/primaite/simulator/system/applications/application.py @@ -0,0 +1,86 @@ +from abc import abstractmethod +from enum import Enum +from typing import Any, List, Dict, Set + +from primaite.simulator.system.software import IOSoftware + + +class ApplicationOperatingState(Enum): + """Enumeration of Application Operating States.""" + + CLOSED = 0 + "The application is closed or not running." + RUNNING = 1 + "The application is running." + INSTALLING = 3 + "The application is being installed or updated." + + +class Application(IOSoftware): + """ + Represents an Application in the simulation environment. + + Applications are user-facing programs that may perform input/output operations. + """ + operating_state: ApplicationOperatingState + "The current operating state of the Application." + execution_control_status: str + "Control status of the application's execution. It could be 'manual' or 'automatic'." + num_executions: int = 0 + "The number of times the application has been executed. Default is 0." + groups: Set[str] = set() + "The set of groups to which the application belongs." + + @abstractmethod + def describe_state(self) -> Dict: + """ + Describes the current state of the software. + + The specifics of the software's state, including its health, criticality, + and any other pertinent information, should be implemented in subclasses. + + :return: A dictionary containing key-value pairs representing the current state of the software. + :rtype: Dict + """ + pass + + def apply_action(self, action: List[str]) -> None: + """ + Applies a list of actions to the Application. + + :param action: A list of actions to apply. + """ + pass + + def reset_component_for_episode(self, episode: int): + """ + Resets the Application component for a new episode. + + This method ensures the Application is ready for a new episode, including resetting any + stateful properties or statistics, and clearing any message queues. + """ + pass + + def send(self, payload: Any) -> bool: + """ + Sends a payload to the SessionManager + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to send. + :return: True if successful, False otherwise. + """ + pass + + def receive(self, payload: Any) -> bool: + """ + Receives a payload from the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to receive. + :return: True if successful, False otherwise. + """ + pass diff --git a/src/primaite/simulator/system/arp_cache.py b/src/primaite/simulator/system/arp_cache.py new file mode 100644 index 00000000..1fb830ab --- /dev/null +++ b/src/primaite/simulator/system/arp_cache.py @@ -0,0 +1,30 @@ +from ipaddress import IPv4Address + +from pydantic import BaseModel + + +class ARPCacheService(BaseModel): + def __init__(self, node): + super().__init__() + self.node = node + + def _add_arp_cache_entry(self, ip_address: IPv4Address, mac_address: str, nic: NIC): + ... + + def _remove_arp_cache_entry(self, ip_address: IPv4Address): + ... + + def _get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: + ... + + def _get_arp_cache_nic(self, ip_address: IPv4Address) -> Optional[NIC]: + ... + + def _clear_arp_cache(self): + ... + + def _send_arp_request(self, target_ip_address: Union[IPv4Address, str]): + ... + + def process_arp_packet(self, from_nic: NIC, arp_packet: ARPPacket): + ... \ No newline at end of file diff --git a/src/primaite/simulator/system/processes/pcap.py b/src/primaite/simulator/system/packet_capture.py similarity index 78% rename from src/primaite/simulator/system/processes/pcap.py rename to src/primaite/simulator/system/packet_capture.py index c502adc8..c05b6db9 100644 --- a/src/primaite/simulator/system/processes/pcap.py +++ b/src/primaite/simulator/system/packet_capture.py @@ -8,24 +8,26 @@ class _JSONFilter(logging.Filter): return record.getMessage().startswith("{") and record.getMessage().endswith("}") -class PCAP: +class PacketCapture: """ - A logger class for logging Frames as json strings. + Represents a PacketCapture component on a Node in the simulation environment. - This is essentially a PrimAITE simulated version of PCAP. + PacketCapture is a service that logs Frames as json strings; It's Wireshark for PrimAITE. The PCAPs are logged to: //__pcap.log """ def __init__(self, hostname: str, ip_address: str): """ - Initialize the PCAP instance. + Initialize the PacketCapture process. :param hostname: The hostname for which PCAP logs are being recorded. :param ip_address: The IP address associated with the PCAP logs. """ - self.hostname = hostname - self.ip_address = str(ip_address) + self.hostname: str = hostname + "The hostname for which PCAP logs are being recorded." + self.ip_address: str = ip_address + "The IP address associated with the PCAP logs." self._setup_logger() def _setup_logger(self): @@ -51,7 +53,7 @@ class PCAP: root.mkdir(exist_ok=True, parents=True) return root / f"{self.hostname}_{self.ip_address}_pcap.log" - def capture(self, frame): # noqa Please don't make me, I'll have a circular import and cant use if TYPE_CHECKING ;( + def capture(self, frame): # noqa - I'll have a circular import and cant use if TYPE_CHECKING ;( """ Capture a Frame and log it. diff --git a/src/primaite/simulator/system/processes/process.py b/src/primaite/simulator/system/processes/process.py new file mode 100644 index 00000000..68f3102f --- /dev/null +++ b/src/primaite/simulator/system/processes/process.py @@ -0,0 +1,37 @@ +from abc import abstractmethod +from enum import Enum +from typing import List, Dict, Any + +from primaite.simulator.system.software import Software + + +class ProcessOperatingState(Enum): + """Enumeration of Process Operating States.""" + + RUNNING = 1 + "The process is running." + PAUSED = 2 + "The process is temporarily paused." + + +class Process(Software): + """ + Represents a Process, a program in execution, in the simulation environment. + + Processes are executed by a Node and do not have the ability to performing input/output operations. + """ + operating_state: ProcessOperatingState + "The current operating state of the Process." + + @abstractmethod + def describe_state(self) -> Dict: + """ + Describes the current state of the software. + + The specifics of the software's state, including its health, criticality, + and any other pertinent information, should be implemented in subclasses. + + :return: A dictionary containing key-value pairs representing the current state of the software. + :rtype: Dict + """ + pass diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py new file mode 100644 index 00000000..a66249ad --- /dev/null +++ b/src/primaite/simulator/system/services/service.py @@ -0,0 +1,87 @@ +from abc import abstractmethod +from enum import Enum +from typing import Any, Dict, List + +from primaite.simulator.system.software import IOSoftware + + +class ServiceOperatingState(Enum): + """Enumeration of Service Operating States.""" + + STOPPED = 0 + "The service is not running." + RUNNING = 1 + "The service is currently running." + RESTARTING = 2 + "The service is in the process of restarting." + INSTALLING = 3 + "The service is being installed or updated." + PAUSED = 4 + "The service is temporarily paused." + DISABLED = 5 + "The service is disabled and cannot be started." + + +class Service(IOSoftware): + """ + Represents a Service in the simulation environment. + + Services are programs that run in the background and may perform input/output operations. + """ + operating_state: ServiceOperatingState + "The current operating state of the Service." + + @abstractmethod + def describe_state(self) -> Dict: + """ + Describes the current state of the software. + + The specifics of the software's state, including its health, criticality, + and any other pertinent information, should be implemented in subclasses. + + :return: A dictionary containing key-value pairs representing the current state of the software. + :rtype: Dict + """ + pass + + def apply_action(self, action: List[str]) -> None: + """ + Applies a list of actions to the Service. + + :param action: A list of actions to apply. + """ + pass + + def reset_component_for_episode(self, episode: int): + """ + Resets the Service component for a new episode. + + This method ensures the Service is ready for a new episode, including resetting any + stateful properties or statistics, and clearing any message queues. + """ + pass + + def send(self, payload: Any) -> bool: + """ + Sends a payload to the SessionManager + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to send. + :return: True if successful, False otherwise. + """ + pass + + def receive(self, payload: Any) -> bool: + """ + Receives a payload from the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to receive. + :return: True if successful, False otherwise. + """ + pass + diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index a5d0bd18..e5991429 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -1,6 +1,9 @@ +from abc import abstractmethod from enum import Enum +from typing import Any, Dict, List, Set from primaite.simulator.core import SimComponent +from primaite.simulator.network.transmission.transport_layer import Port class SoftwareHealthState(Enum): @@ -16,43 +19,6 @@ class SoftwareHealthState(Enum): "The software is undergoing patching or updates." -class ApplicationOperatingState(Enum): - """Enumeration of Application Operating States.""" - - CLOSED = 0 - "The application is closed or not running." - RUNNING = 1 - "The application is running." - INSTALLING = 3 - "The application is being installed or updated." - - -class ServiceOperatingState(Enum): - """Enumeration of Service Operating States.""" - - STOPPED = 0 - "The service is not running." - RUNNING = 1 - "The service is currently running." - RESTARTING = 2 - "The service is in the process of restarting." - INSTALLING = 3 - "The service is being installed or updated." - PAUSED = 4 - "The service is temporarily paused." - DISABLED = 5 - "The service is disabled and cannot be started." - - -class ProcessOperatingState(Enum): - """Enumeration of Process Operating States.""" - - RUNNING = 1 - "The process is running." - PAUSED = 2 - "The process is temporarily paused." - - class SoftwareCriticality(Enum): """Enumeration of Software Criticality Levels.""" @@ -70,25 +36,101 @@ class SoftwareCriticality(Enum): class Software(SimComponent): """ - Represents software information along with its health, criticality, and status. + A base class representing software in a simulator environment. - This class inherits from the Pydantic BaseModel and provides a structured way to store - information about software entities. - - Attributes: - name (str): The name of the software. - health_state_actual (SoftwareHealthState): The actual health state of the software. - health_state_visible (SoftwareHealthState): The health state of the software visible to users. - criticality (SoftwareCriticality): The criticality level of the software. - patching_count (int, optional): The count of patches applied to the software. Default is 0. - scanning_count (int, optional): The count of times the software has been scanned. Default is 0. - revealed_to_red (bool, optional): Indicates if the software has been revealed to red team. Default is False. + This class is intended to be subclassed by specific types of software entities. + It outlines the fundamental attributes and behaviors expected of any software in the simulation. """ - name: str + "The name of the software." health_state_actual: SoftwareHealthState + "The actual health state of the software." health_state_visible: SoftwareHealthState + "The health state of the software visible to the red agent." criticality: SoftwareCriticality + "The criticality level of the software." patching_count: int = 0 + "The count of patches applied to the software, defaults to 0." scanning_count: int = 0 + "The count of times the software has been scanned, defaults to 0." revealed_to_red: bool = False + "Indicates if the software has been revealed to red agent, defaults is False." + + @abstractmethod + def describe_state(self) -> Dict: + """ + Describes the current state of the software. + + The specifics of the software's state, including its health, criticality, + and any other pertinent information, should be implemented in subclasses. + + :return: A dictionary containing key-value pairs representing the current state of the software. + :rtype: Dict + """ + pass + + def apply_action(self, action: List[str]) -> None: + """ + Applies a list of actions to the software. + + The specifics of how these actions are applied should be implemented in subclasses. + + :param action: A list of actions to apply. + :type action: List[str] + """ + pass + + def reset_component_for_episode(self, episode: int): + """ + Resets the software component for a new episode. + + This method should ensure the software is ready for a new episode, including resetting any + stateful properties or statistics, and clearing any message queues. The specifics of what constitutes a + "reset" should be implemented in subclasses. + """ + pass + + +class IOSoftware(Software): + """ + Represents software in a simulator environment that is capable of input/output operations. + + This base class is meant to be sub-classed by Application and Service classes. It provides the blueprint for + Applications and Services that can receive payloads from a Node's SessionManager (corresponding to layer 5 in the + OSI Model), process them according to their internals, and send a response payload back to the SessionManager if + required. + """ + installing_count: int = 0 + "The number of times the software has been installed. Default is 0." + max_sessions: int = 1 + "The maximum number of sessions that the software can handle simultaneously. Default is 0." + tcp: bool = True + "Indicates if the software uses TCP protocol for communication. Default is True." + udp: bool = True + "Indicates if the software uses UDP protocol for communication. Default is True." + ports: Set[Port] + "The set of ports to which the software is connected." + + def send(self, payload: Any) -> bool: + """ + Sends a payload to the SessionManager + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to send. + :return: True if successful, False otherwise. + """ + pass + + def receive(self, payload: Any) -> bool: + """ + Receives a payload from the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to receive. + :return: True if successful, False otherwise. + """ + pass diff --git a/src/primaite/simulator/system/processes/sys_log.py b/src/primaite/simulator/system/sys_log.py similarity index 51% rename from src/primaite/simulator/system/processes/sys_log.py rename to src/primaite/simulator/system/sys_log.py index 27b35505..bb2fd7ec 100644 --- a/src/primaite/simulator/system/processes/sys_log.py +++ b/src/primaite/simulator/system/sys_log.py @@ -4,28 +4,36 @@ from pathlib import Path class _NotJSONFilter(logging.Filter): def filter(self, record: logging.LogRecord) -> bool: - """Filter logs that do not start and end with '{' and '}'.""" + """ + Determines if a log message does not start and end with '{' and '}' (i.e., it is not a JSON-like message). + + :param record: LogRecord object containing all the information pertinent to the event being logged. + :return: True if log message is not JSON-like, False otherwise. + """ return not record.getMessage().startswith("{") and not record.getMessage().endswith("}") class SysLog: """ - A simple logger class for writing the sys logs of a Node. + A SysLog class is a simple logger dedicated to managing and writing system logs for a Node. - Logs are logged to: //_sys.log + Each log message is written to a file located at: //_sys.log """ def __init__(self, hostname: str): """ - Initialize the SysLog instance. + Constructs a SysLog instance for a given hostname. - :param hostname: The hostname for which logs are being recorded. + :param hostname: The hostname associated with the system logs being recorded. """ self.hostname = hostname self._setup_logger() def _setup_logger(self): - """Set up the logger configuration.""" + """ + Configures the logger for this SysLog instance. The logger is set to the DEBUG level, + and is equipped with a handler that writes to a file and filters out JSON-like messages. + """ log_path = self._get_log_path() file_handler = logging.FileHandler(filename=log_path) @@ -41,47 +49,51 @@ class SysLog: self.logger.addFilter(_NotJSONFilter()) def _get_log_path(self) -> Path: - """Get the path for the log file.""" + """ + Constructs the path for the log file based on the hostname. + + :return: Path object representing the location of the log file. + """ root = Path(__file__).parent.parent.parent.parent.parent.parent / "simulation_output" / self.hostname root.mkdir(exist_ok=True, parents=True) return root / f"{self.hostname}_sys.log" def debug(self, msg: str): """ - Log a debug message. + Logs a message with the DEBUG level. - :param msg: The message to log. + :param msg: The message to be logged. """ self.logger.debug(msg) def info(self, msg: str): """ - Log an info message. + Logs a message with the INFO level. - :param msg: The message to log. + :param msg: The message to be logged. """ self.logger.info(msg) def warning(self, msg: str): """ - Log a warning message. + Logs a message with the WARNING level. - :param msg: The message to log. + :param msg: The message to be logged. """ self.logger.warning(msg) def error(self, msg: str): """ - Log an error message. + Logs a message with the ERROR level. - :param msg: The message to log. + :param msg: The message to be logged. """ self.logger.error(msg) def critical(self, msg: str): """ - Log a critical message. + Logs a message with the CRITICAL level. - :param msg: The message to log. + :param msg: The message to be logged. """ self.logger.critical(msg) diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index 82e97049..9681e72d 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -41,4 +41,4 @@ def test_multi_nic(): node_a.ping("192.168.0.11") - node_c.ping("10.0.0.12") + node_c.ping("10.0.0.12") \ No newline at end of file From 46c70ac084631f1321fd8b9b4b5478da0ef83448 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 3 Aug 2023 22:20:14 +0100 Subject: [PATCH 059/980] #1714: refactor private attributes and made them public + serialisation tests --- .../simulator/file_system/file_system.py | 18 +++++------ .../simulator/file_system/file_system_file.py | 31 ++++++++++++------- .../file_system/file_system_folder.py | 30 +++++++++--------- .../_file_system/test_file_system.py | 15 +++++++++ .../_file_system/test_file_system_file.py | 9 ++++++ .../_file_system/test_file_system_folder.py | 22 +++++++++++-- 6 files changed, 85 insertions(+), 40 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 6af6db3e..e2f89809 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -1,7 +1,5 @@ from typing import Dict, List, Optional -from pydantic import PrivateAttr - from primaite.simulator.core import SimComponent from primaite.simulator.file_system.file_system_file import FileSystemFile from primaite.simulator.file_system.file_system_file_type import FileSystemFileType @@ -11,7 +9,7 @@ from primaite.simulator.file_system.file_system_folder import FileSystemFolder class FileSystem(SimComponent): """Class that contains all the simulation File System.""" - _folders: List[FileSystemFolder] = PrivateAttr([]) + folders: List[FileSystemFolder] = [] """List containing all the folders in the file system.""" def describe_state(self) -> Dict: @@ -24,7 +22,7 @@ class FileSystem(SimComponent): def get_folders(self) -> List[FileSystemFolder]: """Returns the list of folders.""" - return self._folders + return self.folders def create_file(self, file_size: float, folder_uuid: Optional[str] = None) -> FileSystemFile: """ @@ -40,7 +38,7 @@ class FileSystem(SimComponent): file = FileSystemFile(item_parent=folder.uuid, file_size=file_size, file_type=FileSystemFileType.TBD) folder.add_file(file) - self._folders.append(folder) + self.folders.append(folder) else: # otherwise check for existence and add file folder = self.get_folder_by_id(folder_uuid) @@ -52,7 +50,7 @@ class FileSystem(SimComponent): def create_folder(self) -> FileSystemFolder: """Creates a FileSystemFolder and adds it to the list of folders.""" folder = FileSystemFolder(item_parent=None) - self._folders.append(folder) + self.folders.append(folder) return folder def delete_file(self, file_id: str): @@ -63,7 +61,7 @@ class FileSystem(SimComponent): :type file_id: str """ # iterate through folders to delete the item with the matching uuid - for folder in self._folders: + for folder in self.folders: folder.remove_file(file_id) def delete_folder(self, folder_id: str): @@ -73,7 +71,7 @@ class FileSystem(SimComponent): :param folder_id: The UUID of the file item to delete :type folder_id: str """ - self._folders = list(filter(lambda f: (f.uuid != folder_id), self._folders)) + self.folders = list(filter(lambda f: (f.uuid != folder_id), self.folders)) def move_file(self, src_folder_id: str, target_folder_id: str, file_id: str): """Moves a file from one folder to another.""" @@ -118,11 +116,11 @@ class FileSystem(SimComponent): def get_file_by_id(self, file_id: str) -> FileSystemFile: """Checks if the file exists in any file system folders.""" - for folder in self._folders: + for folder in self.folders: file = folder.get_file(file_id=file_id) if file is not None: return file def get_folder_by_id(self, folder_id: str) -> FileSystemFolder: """Checks if the folder exists.""" - return next((f for f in self._folders if f.uuid == folder_id), None) + return next((f for f in self.folders if f.uuid == folder_id), None) diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py index bebaa223..f10ae0ad 100644 --- a/src/primaite/simulator/file_system/file_system_file.py +++ b/src/primaite/simulator/file_system/file_system_file.py @@ -1,7 +1,6 @@ +from random import choice, random from typing import Dict -from pydantic import PrivateAttr - from primaite.simulator.core import SimComponent from primaite.simulator.file_system.file_system_file_type import FileSystemFileType @@ -9,34 +8,42 @@ from primaite.simulator.file_system.file_system_file_type import FileSystemFileT class FileSystemFile(SimComponent): """Class that represents a file in the simulation.""" - _file_type: FileSystemFileType = PrivateAttr() + file_type: FileSystemFileType = None """The type of the FileSystemFile""" - _file_size: float = PrivateAttr() + file_size: float = 0 """Disk size of the FileSystemItem""" - def __init__(self, file_type: FileSystemFileType, file_size: float, **kwargs): + def __init__(self, **kwargs): """ Initialise FileSystemFile class. - :param item_parent: The UUID of the FileSystemItem parent - :type item_parent: str + :param file_type: The FileSystemFileType of the file + :type file_type: Optional[FileSystemFileType] :param file_size: The size of the FileSystemItem - :type file_size: float + :type file_size: Optional[float] """ super().__init__(**kwargs) - self._file_type = file_type - self._file_size = file_size + self.file_type = choice(list(FileSystemFileType)) + self.file_size = random() + + # set random file size if non provided + if kwargs.get("file_size") is not None: + self.file_size = kwargs.get("file_size") + + # set random file type if none provided + if kwargs.get("file_type") is None: + self.file_type = kwargs.get("file_type") def get_file_size(self) -> float: """Returns the size of the file system item.""" - return self._file_size + return self.file_size def get_file_type(self) -> FileSystemFileType: """Returns the FileSystemFileType of the file.""" - return self._file_type + return self.file_type def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py index 248a4f98..a2bcd226 100644 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -1,7 +1,5 @@ from typing import Dict, List -from pydantic import PrivateAttr - from primaite.simulator.core import SimComponent from primaite.simulator.file_system.file_system_file import FileSystemFile @@ -9,53 +7,53 @@ from primaite.simulator.file_system.file_system_file import FileSystemFile class FileSystemFolder(SimComponent): """Simulation FileSystemFolder.""" - _files: List[FileSystemFile] = PrivateAttr([]) + files: List[FileSystemFile] = [] """List of files stored in the folder.""" - _folder_size: float = PrivateAttr(0) + folder_size: float = 0 """The current size of the folder""" - _is_quarantined: bool = PrivateAttr(False) + is_quarantined: bool = False """Flag that marks the folder as quarantined if true.""" def get_files(self) -> List[FileSystemFile]: """Returns the list of files the folder contains.""" - return self._files + return self.files def get_file(self, file_id: str) -> FileSystemFile: """Return a FileSystemFile with the matching id.""" - return next((f for f in self._files if f.uuid == file_id), None) + return next((f for f in self.files if f.uuid == file_id), None) def add_file(self, file: FileSystemFile): """Adds a file to the folder list.""" - self._folder_size += file.get_file_size() + self.folder_size += file.get_file_size() # add to list - self._files.append(file) + self.files.append(file) def remove_file(self, file_id: str): """Removes a file from the folder list.""" - file = next((f for f in self._files if f.uuid == file_id), None) - self._files.remove(file) + file = next((f for f in self.files if f.uuid == file_id), None) + self.files.remove(file) # remove folder size from folder - self._folder_size -= file.get_file_size() + self.folder_size -= file.get_file_size() def get_folder_size(self) -> float: """Returns a sum of all file sizes in the files list.""" - return sum([file.get_file_size() for file in self._files]) + return sum([file.get_file_size() for file in self.files]) def quarantine(self): """Quarantines the File System Folder.""" - self._is_quarantined = True + self.is_quarantined = True def end_quarantine(self): """Ends the quarantine of the File System Folder.""" - self._is_quarantined = False + self.is_quarantined = False def quarantine_status(self) -> bool: """Returns true if the folder is being quarantined.""" - return self._is_quarantined + return self.is_quarantined def describe_state(self) -> Dict: """ diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 7b26f707..e19b2bf5 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -78,3 +78,18 @@ def test_copy_file(): assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 1 assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 1 + + +def test_serialisation(): + """Test to check that the object serialisation works correctly.""" + file_system = FileSystem() + folder = file_system.create_folder() + assert len(file_system.get_folders()) is 1 + + file_system.create_file(file_size=10, folder_uuid=folder.uuid) + assert len(file_system.get_folders()[0].get_files()) is 1 + + serialised_file_sys = file_system.model_dump_json() + deserialised_file_sys = FileSystem().model_validate_json(serialised_file_sys) + + assert file_system == deserialised_file_sys diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py index 34c8dd94..31967f31 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py @@ -12,3 +12,12 @@ def test_get_file_size(): """Tests that the file size is being returned properly.""" file = FileSystemFile(file_size=1.5, file_type=FileSystemFileType.TBD) assert file.get_file_size() is 1.5 + + +def test_serialisation(): + """Test to check that the object serialisation works correctly.""" + file = FileSystemFile(file_size=1.5, file_type=FileSystemFileType.TBD) + serialised_file = file.model_dump_json() + deserialised_file = FileSystemFile().model_validate_json(serialised_file) + + assert file == deserialised_file diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py index b67ea385..c04465c3 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py @@ -4,6 +4,7 @@ from primaite.simulator.file_system.file_system_folder import FileSystemFolder def test_adding_removing_file(): + """Test the adding and removing of a file from a folder.""" folder = FileSystemFolder() file = FileSystemFile(file_size=10, file_type=FileSystemFileType.TBD) @@ -18,18 +19,22 @@ def test_adding_removing_file(): def test_get_file_by_id(): + """Test to make sure that the correct file is returned.""" folder = FileSystemFolder() file = FileSystemFile(file_size=10, file_type=FileSystemFileType.TBD) + file2 = FileSystemFile(file_size=10, file_type=FileSystemFileType.TBD) folder.add_file(file) - assert folder.get_folder_size() is 10 - assert len(folder.get_files()) is 1 + folder.add_file(file2) + assert folder.get_folder_size() is 20 + assert len(folder.get_files()) is 2 assert folder.get_file(file_id=file.uuid) is file def test_folder_quarantine_state(): + """Tests the changing of folder quarantine status.""" folder = FileSystemFolder() assert folder.quarantine_status() is False @@ -39,3 +44,16 @@ def test_folder_quarantine_state(): folder.end_quarantine() assert folder.quarantine_status() is False + + +def test_serialisation(): + """Test to check that the object serialisation works correctly.""" + folder = FileSystemFolder() + file = FileSystemFile(file_size=10, file_type=FileSystemFileType.TBD) + folder.add_file(file) + + serialised_folder = folder.model_dump_json() + + deserialised_folder = FileSystemFolder().model_validate_json(serialised_folder) + + assert folder == deserialised_folder From 028211d2881290ca160a663f109f0a2b8d403534 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 7 Aug 2023 09:34:59 +0100 Subject: [PATCH 060/980] #1714: update to use objects instead of uuids + tests --- .../simulator/file_system/file_system.py | 158 +++++++++++++----- .../simulator/file_system/file_system_file.py | 37 ++-- .../file_system/file_system_file_type.py | 8 +- .../file_system/file_system_folder.py | 33 ++-- .../file_system/file_system_item_abc.py | 13 ++ .../_file_system/test_file_system.py | 36 ++-- .../_file_system/test_file_system_file.py | 10 +- .../_file_system/test_file_system_folder.py | 20 +-- 8 files changed, 211 insertions(+), 104 deletions(-) create mode 100644 src/primaite/simulator/file_system/file_system_item_abc.py diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index e2f89809..f8ae9d67 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -1,3 +1,4 @@ +from random import choice from typing import Dict, List, Optional from primaite.simulator.core import SimComponent @@ -24,95 +25,148 @@ class FileSystem(SimComponent): """Returns the list of folders.""" return self.folders - def create_file(self, file_size: float, folder_uuid: Optional[str] = None) -> FileSystemFile: + def create_file( + self, + file_name: str, + file_size: Optional[float] = None, + file_type: Optional[FileSystemFileType] = None, + folder: Optional[FileSystemFolder] = None, + folder_uuid: Optional[str] = None, + ) -> FileSystemFile: """ Creates a FileSystemFile and adds it to the list of files. + If no file_size or file_type are provided, one will be chosen randomly. + If no folder_uuid or folder is provided, a new folder will be created. + + :param: file_name: The file name + :type: file_name: str + + :param: file_size: The size the file takes on disk. + :type: file_size: Optional[float] + + :param: file_type: The type of the file + :type: Optional[FileSystemFileType] + :param: folder_uuid: The uuid of the folder to add the file to - :type: folder_uuid: str + :type: folder_uuid: Optional[str] """ file = None - # if no folder uuid provided, create a folder and add file to it - if folder_uuid is None: - folder = FileSystemFolder() + folder = None - file = FileSystemFile(item_parent=folder.uuid, file_size=file_size, file_type=FileSystemFileType.TBD) - folder.add_file(file) - self.folders.append(folder) - else: + if file_type is None: + file_type = self.get_random_file_type() + + # if no folder uuid provided, create a folder and add file to it + if folder_uuid is not None: # otherwise check for existence and add file folder = self.get_folder_by_id(folder_uuid) - if folder is not None: - file = FileSystemFile(file_size=file_size, file_type=FileSystemFileType.TBD) - folder.add_file(file=file) + + if folder is not None: + file = FileSystemFile(item_name=file_name, item_size=file_size, file_type=file_type) + folder.add_file(file=file) + else: + # check if a "root" folder exists + folder = self.get_folder_by_name("root") + if folder is None: + # create a root folder + folder = FileSystemFolder(item_name="root") + + # add file to root folder + file = FileSystemFile(item_name=file_name, item_size=file_size, file_type=file_type) + folder.add_file(file) + self.folders.append(folder) return file - def create_folder(self) -> FileSystemFolder: + def create_folder( + self, + folder_name: str, + ) -> FileSystemFolder: """Creates a FileSystemFolder and adds it to the list of folders.""" - folder = FileSystemFolder(item_parent=None) + folder = FileSystemFolder(item_name=folder_name) self.folders.append(folder) return folder - def delete_file(self, file_id: str): + def delete_file(self, file: Optional[FileSystemFile] = None): """ Deletes a file and removes it from the files list. + :param file: The file to delete + :type file: Optional[FileSystemFile] + :param file_id: The UUID of the file item to delete - :type file_id: str + :type file_id: Optional[str] """ # iterate through folders to delete the item with the matching uuid for folder in self.folders: - folder.remove_file(file_id) + folder.remove_file(file=file) - def delete_folder(self, folder_id: str): + def delete_folder(self, folder: FileSystemFolder): """ Deletes a folder, removes it from the folders list and removes any child folders and files. - :param folder_id: The UUID of the file item to delete - :type folder_id: str + :param folder: The folder to remove + :type folder: FileSystemFolder """ - self.folders = list(filter(lambda f: (f.uuid != folder_id), self.folders)) + self.folders.remove(folder) - def move_file(self, src_folder_id: str, target_folder_id: str, file_id: str): - """Moves a file from one folder to another.""" - # check that both folders and the file exists - src = self.get_folder_by_id(src_folder_id) - target = self.get_folder_by_id(target_folder_id) + def move_file(self, file: FileSystemFile, src_folder: FileSystemFolder, target_folder: FileSystemFolder): + """ + Moves a file from one folder to another. - if src is None: - raise Exception(f"src folder with UUID {src_folder_id} could not be found") + can provide - if target is None: - raise Exception(f"src folder with UUID {target_folder_id} could not be found") + :param: file: The file to move + :type: file: FileSystemFile + + :param: src_folder: The folder where the file is located + :type: FileSystemFolder + + :param: target_folder: The folder where the file should be moved to + :type: FileSystemFolder + """ + # check that the folders exist + if src_folder is None: + raise Exception("Source folder not provided") + + if target_folder is None: + raise Exception("Target folder not provided") - file = src.get_file(file_id=file_id) if file is None: - raise Exception(f"file with UUID {file_id} could not be found") + raise Exception("File to be moved is None") # remove file from src - src.remove_file(file_id) + src_folder.remove_file(file) # add file to target - target.add_file(file) + target_folder.add_file(file) - def copy_file(self, src_folder_id: str, target_folder_id: str, file_id: str): - """Copies a file from one folder to another.""" - # check that both folders and the file exists - src = self.get_folder_by_id(src_folder_id) - target = self.get_folder_by_id(target_folder_id) + def copy_file(self, file: FileSystemFile, src_folder: FileSystemFolder, target_folder: FileSystemFolder): + """ + Copies a file from one folder to another. - if src is None: - raise Exception(f"src folder with UUID {src_folder_id} could not be found") + can provide - if target is None: - raise Exception(f"src folder with UUID {target_folder_id} could not be found") + :param: file: The file to move + :type: file: FileSystemFile + + :param: src_folder: The folder where the file is located + :type: FileSystemFolder + + :param: target_folder: The folder where the file should be moved to + :type: FileSystemFolder + """ + if src_folder is None: + raise Exception("Source folder not provided") + + if target_folder is None: + raise Exception("Target folder not provided") - file = src.get_file(file_id=file_id) if file is None: - raise Exception(f"file with UUID {file_id} could not be found") + raise Exception("File to be moved is None") # add file to target - target.add_file(file) + target_folder.add_file(file) def get_file_by_id(self, file_id: str) -> FileSystemFile: """Checks if the file exists in any file system folders.""" @@ -121,6 +175,18 @@ class FileSystem(SimComponent): if file is not None: return file + def get_folder_by_name(self, folder_name: str) -> FileSystemFolder: + """ + Returns a the first folder with a matching name. + + :return: Returns the first FileSydtemFolder with a matching name + """ + return next((f for f in self.folders if f.get_folder_name() == folder_name), None) + def get_folder_by_id(self, folder_id: str) -> FileSystemFolder: """Checks if the folder exists.""" return next((f for f in self.folders if f.uuid == folder_id), None) + + def get_random_file_type(self) -> FileSystemFileType: + """Returns a random FileSystemFileTypeEnum.""" + return choice(list(FileSystemFileType)) diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py index f10ae0ad..441a27b0 100644 --- a/src/primaite/simulator/file_system/file_system_file.py +++ b/src/primaite/simulator/file_system/file_system_file.py @@ -1,45 +1,54 @@ -from random import choice, random +from random import choice, randint from typing import Dict -from primaite.simulator.core import SimComponent from primaite.simulator.file_system.file_system_file_type import FileSystemFileType +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC -class FileSystemFile(SimComponent): +class FileSystemFile(FileSystemItemABC): """Class that represents a file in the simulation.""" file_type: FileSystemFileType = None """The type of the FileSystemFile""" - file_size: float = 0 - """Disk size of the FileSystemItem""" - def __init__(self, **kwargs): """ Initialise FileSystemFile class. + :param item_name: The name of the file. + :type item_name: str + :param file_type: The FileSystemFileType of the file :type file_type: Optional[FileSystemFileType] - :param file_size: The size of the FileSystemItem - :type file_size: Optional[float] + :param item_size: The size of the FileSystemItem + :type item_size: Optional[float] """ super().__init__(**kwargs) - self.file_type = choice(list(FileSystemFileType)) - self.file_size = random() + # set random file type if none provided + if kwargs.get("item_name") is None: + raise Exception("File name not provided.") # set random file size if non provided - if kwargs.get("file_size") is not None: - self.file_size = kwargs.get("file_size") + if kwargs.get("item_size") is None: + kwargs["item_size"] = float(randint(1, 1000)) # set random file type if none provided if kwargs.get("file_type") is None: - self.file_type = kwargs.get("file_type") + kwargs["file_type"] = choice(list(FileSystemFileType)) + + self.item_name = kwargs.get("item_name") + self.item_size = kwargs.get("item_size") + self.file_type = kwargs.get("file_type") + + def get_file_name(self) -> str: + """Returns the name of the file.""" + return self.item_name def get_file_size(self) -> float: """Returns the size of the file system item.""" - return self.file_size + return self.item_size def get_file_type(self) -> FileSystemFileType: """Returns the FileSystemFileType of the file.""" diff --git a/src/primaite/simulator/file_system/file_system_file_type.py b/src/primaite/simulator/file_system/file_system_file_type.py index 134b38f4..fd11f30f 100644 --- a/src/primaite/simulator/file_system/file_system_file_type.py +++ b/src/primaite/simulator/file_system/file_system_file_type.py @@ -4,4 +4,10 @@ from enum import Enum class FileSystemFileType(str, Enum): """Enum used to determine the FileSystemFile type.""" - TBD = "TBD" + CSV = ("CSV",) + DOC = ("DOC",) + EXE = ("EXE",) + PDF = ("PDF",) + TXT = ("TXT",) + XML = ("XML",) + ZIP = "ZIP" diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py index a2bcd226..2d0b0eb0 100644 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -1,21 +1,26 @@ -from typing import Dict, List +from typing import Dict, List, Optional -from primaite.simulator.core import SimComponent from primaite.simulator.file_system.file_system_file import FileSystemFile +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC -class FileSystemFolder(SimComponent): +class FileSystemFolder(FileSystemItemABC): """Simulation FileSystemFolder.""" files: List[FileSystemFile] = [] """List of files stored in the folder.""" - folder_size: float = 0 - """The current size of the folder""" - is_quarantined: bool = False """Flag that marks the folder as quarantined if true.""" + def get_folder_name(self) -> str: + """Returns the item_name of the folder.""" + return self.item_name + + def get_folder_size(self) -> float: + """Returns the item_size of the folder.""" + return self.item_size + def get_files(self) -> List[FileSystemFile]: """Returns the list of files the folder contains.""" return self.files @@ -26,18 +31,24 @@ class FileSystemFolder(SimComponent): def add_file(self, file: FileSystemFile): """Adds a file to the folder list.""" - self.folder_size += file.get_file_size() + self.item_size += file.get_file_size() # add to list self.files.append(file) - def remove_file(self, file_id: str): - """Removes a file from the folder list.""" - file = next((f for f in self.files if f.uuid == file_id), None) + def remove_file(self, file: Optional[FileSystemFile]): + """ + Removes a file from the folder list. + + The method can take a FileSystemFile object or a file id. + + :param: file: The file to remove + :type: Optional[FileSystemFile] + """ self.files.remove(file) # remove folder size from folder - self.folder_size -= file.get_file_size() + self.item_size -= file.get_file_size() def get_folder_size(self) -> float: """Returns a sum of all file sizes in the files list.""" diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py new file mode 100644 index 00000000..4dca0f4e --- /dev/null +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -0,0 +1,13 @@ +from abc import ABC + +from primaite.simulator.core import SimComponent + + +class FileSystemItemABC(SimComponent, ABC): + """Abstract base class for FileSystemItems used in the file system simulation.""" + + item_size: float = 0 + """The size the item takes up on disk.""" + + item_name: str + """The name of the file system item.""" diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index e19b2bf5..dae8b34e 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -4,18 +4,20 @@ from primaite.simulator.file_system.file_system import FileSystem def test_create_folder_and_file(): """Test creating a folder and a file.""" file_system = FileSystem() - folder = file_system.create_folder() + folder = file_system.create_folder(folder_name="test_folder") assert len(file_system.get_folders()) is 1 - file_system.create_file(file_size=10, folder_uuid=folder.uuid) + file_system.create_file(file_name="test_file", file_size=10, folder_uuid=folder.uuid) assert len(file_system.get_folders()[0].get_files()) is 1 + assert file_system.get_folders()[0].get_files()[0].get_file_name() is "test_file" + assert file_system.get_folders()[0].get_files()[0].get_file_size() is 10 def test_create_file(): """Tests that creating a file without a folder creates a folder and sets that as the file's parent.""" file_system = FileSystem() - file = file_system.create_file(file_size=10) + file = file_system.create_file(file_name="test_file", file_size=10) assert len(file_system.get_folders()) is 1 assert file_system.get_folders()[0].get_file(file.uuid) is file @@ -24,38 +26,38 @@ def test_delete_file(): """Tests that a file can be deleted.""" file_system = FileSystem() - file = file_system.create_file(file_size=10) + file = file_system.create_file(file_name="test_file", file_size=10) assert len(file_system.get_folders()) is 1 assert file_system.get_folders()[0].get_file(file.uuid) is file - file_system.delete_file(file.uuid) + file_system.delete_file(file=file) assert len(file_system.get_folders()) is 1 assert len(file_system.get_folders()[0].get_files()) is 0 def test_delete_folder(): file_system = FileSystem() - folder = file_system.create_folder() + folder = file_system.create_folder(folder_name="test_folder") assert len(file_system.get_folders()) is 1 - file_system.delete_folder(folder.uuid) + file_system.delete_folder(folder) assert len(file_system.get_folders()) is 0 def test_move_file(): """Tests the file move function.""" file_system = FileSystem() - src_folder = file_system.create_folder() + src_folder = file_system.create_folder(folder_name="test_folder_1") assert len(file_system.get_folders()) is 1 - target_folder = file_system.create_folder() + target_folder = file_system.create_folder(folder_name="test_folder_2") assert len(file_system.get_folders()) is 2 - file = file_system.create_file(file_size=10, folder_uuid=src_folder.uuid) + file = file_system.create_file(file_name="test_file", file_size=10, folder_uuid=src_folder.uuid) assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 1 assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 0 - file_system.move_file(src_folder.uuid, target_folder.uuid, file.uuid) + file_system.move_file(file=file, src_folder=src_folder, target_folder=target_folder) assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 0 assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 1 @@ -64,17 +66,17 @@ def test_move_file(): def test_copy_file(): """Tests the file copy function.""" file_system = FileSystem() - src_folder = file_system.create_folder() + src_folder = file_system.create_folder(folder_name="test_folder_1") assert len(file_system.get_folders()) is 1 - target_folder = file_system.create_folder() + target_folder = file_system.create_folder(folder_name="test_folder_2") assert len(file_system.get_folders()) is 2 - file = file_system.create_file(file_size=10, folder_uuid=src_folder.uuid) + file = file_system.create_file(file_name="test_file", file_size=10, folder_uuid=src_folder.uuid) assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 1 assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 0 - file_system.copy_file(src_folder.uuid, target_folder.uuid, file.uuid) + file_system.copy_file(file=file, src_folder=src_folder, target_folder=target_folder) assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 1 assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 1 @@ -83,10 +85,10 @@ def test_copy_file(): def test_serialisation(): """Test to check that the object serialisation works correctly.""" file_system = FileSystem() - folder = file_system.create_folder() + folder = file_system.create_folder(folder_name="test_folder") assert len(file_system.get_folders()) is 1 - file_system.create_file(file_size=10, folder_uuid=folder.uuid) + file_system.create_file(file_name="test_file", file_size=10, folder_uuid=folder.uuid) assert len(file_system.get_folders()[0].get_files()) is 1 serialised_file_sys = file_system.model_dump_json() diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py index 31967f31..669be62d 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py @@ -4,20 +4,20 @@ from primaite.simulator.file_system.file_system_file_type import FileSystemFileT def test_file_type(): """Tests tha the FileSystemFile type is set correctly.""" - file = FileSystemFile(file_size=1.5, file_type=FileSystemFileType.TBD) - assert file.get_file_type() is FileSystemFileType.TBD + file = FileSystemFile(item_name="test", file_type=FileSystemFileType.DOC) + assert file.get_file_type() is FileSystemFileType.DOC def test_get_file_size(): """Tests that the file size is being returned properly.""" - file = FileSystemFile(file_size=1.5, file_type=FileSystemFileType.TBD) + file = FileSystemFile(item_name="test", item_size=1.5) assert file.get_file_size() is 1.5 def test_serialisation(): """Test to check that the object serialisation works correctly.""" - file = FileSystemFile(file_size=1.5, file_type=FileSystemFileType.TBD) + file = FileSystemFile(item_name="test", item_size=1.5, file_type=FileSystemFileType.DOC) serialised_file = file.model_dump_json() - deserialised_file = FileSystemFile().model_validate_json(serialised_file) + deserialised_file = FileSystemFile(item_name="test").model_validate_json(serialised_file) assert file == deserialised_file diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py index c04465c3..f9ba80f0 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py @@ -5,25 +5,25 @@ from primaite.simulator.file_system.file_system_folder import FileSystemFolder def test_adding_removing_file(): """Test the adding and removing of a file from a folder.""" - folder = FileSystemFolder() + folder = FileSystemFolder(item_name="test") - file = FileSystemFile(file_size=10, file_type=FileSystemFileType.TBD) + file = FileSystemFile(item_name="test_file", item_size=10, file_type=FileSystemFileType.DOC) folder.add_file(file) assert folder.get_folder_size() is 10 assert len(folder.get_files()) is 1 - folder.remove_file(file_id=file.uuid) + folder.remove_file(file) assert folder.get_folder_size() is 0 assert len(folder.get_files()) is 0 def test_get_file_by_id(): """Test to make sure that the correct file is returned.""" - folder = FileSystemFolder() + folder = FileSystemFolder(item_name="test") - file = FileSystemFile(file_size=10, file_type=FileSystemFileType.TBD) - file2 = FileSystemFile(file_size=10, file_type=FileSystemFileType.TBD) + file = FileSystemFile(item_name="test_file", item_size=10, file_type=FileSystemFileType.DOC) + file2 = FileSystemFile(item_name="test_file_2", item_size=10, file_type=FileSystemFileType.DOC) folder.add_file(file) folder.add_file(file2) @@ -35,7 +35,7 @@ def test_get_file_by_id(): def test_folder_quarantine_state(): """Tests the changing of folder quarantine status.""" - folder = FileSystemFolder() + folder = FileSystemFolder(item_name="test") assert folder.quarantine_status() is False @@ -48,12 +48,12 @@ def test_folder_quarantine_state(): def test_serialisation(): """Test to check that the object serialisation works correctly.""" - folder = FileSystemFolder() - file = FileSystemFile(file_size=10, file_type=FileSystemFileType.TBD) + folder = FileSystemFolder(item_name="test") + file = FileSystemFile(item_name="test_file", item_size=10, file_type=FileSystemFileType.DOC) folder.add_file(file) serialised_folder = folder.model_dump_json() - deserialised_folder = FileSystemFolder().model_validate_json(serialised_folder) + deserialised_folder = FileSystemFolder(item_name="test").model_validate_json(serialised_folder) assert folder == deserialised_folder From d57c2a936efd047a75cdae739894b8e4683eafb9 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 7 Aug 2023 10:10:05 +0100 Subject: [PATCH 061/980] #1714: remove duplicate method --- src/primaite/simulator/file_system/file_system_folder.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py index 2d0b0eb0..f5024966 100644 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -50,10 +50,6 @@ class FileSystemFolder(FileSystemItemABC): # remove folder size from folder self.item_size -= file.get_file_size() - def get_folder_size(self) -> float: - """Returns a sum of all file sizes in the files list.""" - return sum([file.get_file_size() for file in self.files]) - def quarantine(self): """Quarantines the File System Folder.""" self.is_quarantined = True From f0d7e03fd7548305c70638007f5bfc73829a9154 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 7 Aug 2023 10:55:29 +0100 Subject: [PATCH 062/980] Add docs and tests --- docs/source/simulation_structure.rst | 52 +++++++++++++++++++ src/primaite/simulator/domain/account.py | 18 ++++--- src/primaite/simulator/domain/controller.py | 33 ++++++++++-- .../test_permission_system.py | 51 ++++++++++++------ .../_primaite/_simulator/_domain/__init__.py | 0 .../_simulator/_domain/test_account.py | 18 +++++++ .../_simulator/_domain/test_controller.py | 0 7 files changed, 147 insertions(+), 25 deletions(-) create mode 100644 tests/unit_tests/_primaite/_simulator/_domain/__init__.py create mode 100644 tests/unit_tests/_primaite/_simulator/_domain/test_account.py create mode 100644 tests/unit_tests/_primaite/_simulator/_domain/test_controller.py diff --git a/docs/source/simulation_structure.rst b/docs/source/simulation_structure.rst index 65373a72..479b3e7b 100644 --- a/docs/source/simulation_structure.rst +++ b/docs/source/simulation_structure.rst @@ -11,3 +11,55 @@ top level, there is an object called the ``SimulationController`` _(doesn't exis and a software controller for managing software and users. Each node of the simulation 'tree' has responsibility for creating, deleting, and updating its direct descendants. + + + +Actions +======= +Agents can interact with the simulation by using actions. Actions are standardised with the +:py:class:`primaite.simulation.core.Action` class, which just holds a reference to two special functions. + +1. The action function itself, it must accept a `request` parameters which is a list of strings that describe what the + action should do. It must also accept a `context` dict which can house additional information surrounding the action. + For example, the context will typically include information about which entity intiated the action. +2. A validator function. This function should return a boolean value that decides if the request is permitted or not. + It uses the same paramters as the action function. + +Action Permissions +------------------ +When an agent tries to perform an action on a simulation component, that action will only be executed if the request is +validated. For example, some actions can require that an agent is logged into an admin account. Each action defines its +own permissions using an instance of :py:class:`primaite.simulation.core.ActionPermissionValidator`. The below code +snippet demonstrates usage of the ``ActionPermissionValidator``. + +.. code:: python + + from primaite.simulator.core import Action, ActionManager, SimComponent + from primaite.simulator.domain.controller import AccountGroup, GroupMembershipValidator + + class Smartphone(SimComponent): + name: str + apps = [] + + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.action_manager = ActionManager() + + self.action_manager.add_action( + "reset_factory_settings", + Action( + func = lambda request, context: self.reset_factory_settings(), + validator = GroupMembershipValidator([AccountGroup.domain_admin]), + ), + ) + + def reset_factory_settings(self): + self.apps = [] + + phone = Smartphone(name="phone1") + + # try to wipe the phone as a domain user, this will have no effect + phone.apply_action(["reset_factory_settings"], context={"request_source":{"groups":["domain_user"]}) + + # try to wipe the phone as an admin user, this will wipe the phone + phone.apply_action(["reset_factory_settings"], context={"request_source":{"groups":["domain_admin"]}) diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py index 0f59db2e..086022e6 100644 --- a/src/primaite/simulator/domain/account.py +++ b/src/primaite/simulator/domain/account.py @@ -1,6 +1,6 @@ """User account simulation.""" from enum import Enum -from typing import Any, Callable, Dict, List +from typing import Dict from primaite import getLogger from primaite.simulator.core import SimComponent @@ -49,6 +49,10 @@ class Account(SimComponent): "Account Type, currently this can be service account (used by apps) or user account." status: AccountStatus = AccountStatus.disabled + def describe_state(self) -> Dict: + """Describe state for agent observations.""" + return super().describe_state() + def enable(self): """Set the status to enabled.""" self.status = AccountStatus.enabled @@ -57,8 +61,10 @@ class Account(SimComponent): """Set the status to disabled.""" self.status = AccountStatus.disabled - def _possible_actions(self) -> Dict[str, Callable[[List[str]], None]]: - return { - "enable": self.enable, - "disable": self.disable, - } + def log_on(self) -> None: + """TODO.""" + self.num_logons += 1 + + def log_off(self) -> None: + """TODO.""" + self.num_logoffs += 1 diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index 7cb3f4a6..e4a73b4e 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import Any, Dict, Final, List +from typing import Dict, Final, List, Literal, Tuple from primaite.simulator.core import ActionPermissionValidator, SimComponent from primaite.simulator.domain.account import Account, AccountType @@ -7,18 +7,26 @@ from primaite.simulator.domain.account import Account, AccountType # placeholder while these objects don't yet exist class temp_node: + """Placeholder for node class for type hinting purposes.""" + pass class temp_application: + """Placeholder for application class for type hinting purposes.""" + pass class temp_folder: + """Placeholder for folder class for type hinting purposes.""" + pass class temp_file: + """Placeholder for file class for type hinting purposes.""" + pass @@ -59,9 +67,12 @@ class DomainController(SimComponent): accounts: List[Account] = [] groups: Final[List[AccountGroup]] = list(AccountGroup) - group_membership: Dict[AccountGroup, List[Account]] + domain_group_membership: Dict[Literal[AccountGroup.domain_admin, AccountGroup.domain_user], List[Account]] = {} + local_group_membership: Dict[ + Tuple(temp_node, Literal[AccountGroup.local_admin, AccountGroup.local_user]), List[Account] + ] = {} - # references to non-owned objects + # references to non-owned objects. Not sure if all are needed here. nodes: List[temp_node] = [] applications: List[temp_application] = [] folders: List[temp_folder] = [] @@ -79,6 +90,10 @@ class DomainController(SimComponent): """TODO.""" ... + def delete_account(self, account: Account) -> None: + """TODO.""" + ... + def rotate_all_credentials(self) -> None: """TODO.""" ... @@ -94,3 +109,15 @@ class DomainController(SimComponent): def remove_account_from_group(self, account: Account, group: AccountGroup) -> None: """TODO.""" ... + + def check_account_permissions(self, account: Account, node: temp_node) -> List[AccountGroup]: + """Return a list of permission groups that this account has on this node.""" + ... + + def register_node(self, node: temp_node) -> None: + """TODO.""" + ... + + def deregister_node(self, node: temp_node) -> None: + """TODO.""" + ... diff --git a/tests/integration_tests/component_creation/test_permission_system.py b/tests/integration_tests/component_creation/test_permission_system.py index acc35b72..93d0267c 100644 --- a/tests/integration_tests/component_creation/test_permission_system.py +++ b/tests/integration_tests/component_creation/test_permission_system.py @@ -8,7 +8,13 @@ from primaite.simulator.domain.controller import AccountGroup, GroupMembershipVa def test_group_action_validation() -> None: - """Check that actions are denied when an unauthorised request is made.""" + """ + Check that actions are denied when an unauthorised request is made. + + This test checks the integration between SimComponent and the permissions validation system. First, we create a + basic node and folder class. We configure the node so that only admins can create a folder. Then, we try to create + a folder as both an admin user and a non-admin user. + """ class Folder(SimComponent): name: str @@ -42,22 +48,28 @@ def test_group_action_validation() -> None: def remove_folder(self, folder: Folder) -> None: self.folders = [x for x in self.folders if x is not folder] + # check that the folder is created when a local admin tried to do it permitted_context = {"request_source": {"agent": "BLUE", "account": "User1", "groups": ["local_admin"]}} - my_node = Node(uuid="0000-0000-1234", name="pc") my_node.apply_action(["create_folder", "memes"], context=permitted_context) assert len(my_node.folders) == 1 assert my_node.folders[0].name == "memes" + # check that the number of folders is still 1 even after attempting to create a second one without permissions invalid_context = {"request_source": {"agent": "BLUE", "account": "User1", "groups": ["local_user", "domain_user"]}} - my_node.apply_action(["create_folder", "memes2"], context=invalid_context) assert len(my_node.folders) == 1 assert my_node.folders[0].name == "memes" def test_hierarchical_action_with_validation() -> None: - """Check that validation works with sub-objects""" + """ + Check that validation works with sub-objects. + + This test creates a parent object (Node) and a child object (Application) which both accept actions. The node allows + action passthrough to applications. The purpose of this test is to check that after an action is passed through to + a child object, that the permission system still works as intended. + """ class Application(SimComponent): name: str @@ -100,19 +112,19 @@ def test_hierarchical_action_with_validation() -> None: return super().describe_state() def disable(self) -> None: - self.status = "disabled" + self.state = "disabled" def enable(self) -> None: - if self.status == "disabled": - self.status = "off" + if self.state == "disabled": + self.state = "off" def turn_on(self) -> None: - if self.status == "off": - self.status = "on" + if self.state == "off": + self.state = "on" def turn_off(self) -> None: - if self.status == "on": - self.status = "off" + if self.state == "on": + self.state = "off" class Node(SimComponent): name: str @@ -141,7 +153,7 @@ def test_hierarchical_action_with_validation() -> None: def send_action_to_app(self, app_name: str, options: List[str], context: Dict): for app in self.apps: if app_name == app.name: - app.apply_action(options) + app.apply_action(options, context) break else: msg = f"Node has no app with name {app_name}" @@ -163,9 +175,16 @@ def test_hierarchical_action_with_validation() -> None: } } + # check that a non-admin can't disable this app my_node.apply_action(["apps", "Chrome", "disable"], non_admin_context) - my_node.apply_action(["apps", "Firefox", "turn_on"], non_admin_context) + assert my_node.apps[0].name == "Chrome" # if failure occurs on this line, the test itself is broken + assert my_node.apps[0].state == "off" - assert my_node.apps[0].name == "Chrome" - assert my_node.apps[1].name == "Firefox" - assert my_node.apps[0].state == ... # TODO: finish + # check that a non-admin can turn this app on + my_node.apply_action(["apps", "Firefox", "turn_on"], non_admin_context) + assert my_node.apps[1].name == "Firefox" # if failure occurs on this line, the test itself is broken + assert my_node.apps[1].state == "on" + + # check that an admin can disable this app + my_node.apply_action(["apps", "Chrome", "disable"], admin_context) + assert my_node.apps[0].state == "disabled" diff --git a/tests/unit_tests/_primaite/_simulator/_domain/__init__.py b/tests/unit_tests/_primaite/_simulator/_domain/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py new file mode 100644 index 00000000..d4a57179 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py @@ -0,0 +1,18 @@ +"""Test the account module of the simulator.""" +from primaite.simulator.domain.account import Account, AccountType + + +def test_account_serialise(): + """Test that an account can be serialised.""" + acct = Account(username="Jake", password="JakePass1!", account_type=AccountType.user) + serialised = acct.model_dump_json() + print(serialised) + + +def test_account_deserialise(): + """Test that an account can be deserialised.""" + acct_json = ( + '{"uuid":"dfb2bcaa-d3a1-48fd-af3f-c943354622b4","num_logons":0,"num_logoffs":0,"num_group_changes":0,' + '"username":"Jake","password":"JakePass1!","account_type":2,"status":2,"action_manager":null}' + ) + acct = Account.model_validate_json(acct_json) diff --git a/tests/unit_tests/_primaite/_simulator/_domain/test_controller.py b/tests/unit_tests/_primaite/_simulator/_domain/test_controller.py new file mode 100644 index 00000000..e69de29b From 84b6e2206e362e43b344084ced42a367f89824d5 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 7 Aug 2023 10:18:27 +0000 Subject: [PATCH 063/980] Updated CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d66257b5..fbdd1d5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Permission System - each agent action can define criteria that will be used to permit or deny agent actions. + + ## [2.0.0] - 2023-07-26 ### Added From 22afdc9134a5df947d12b74492e27a3c73f8502a Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 7 Aug 2023 10:19:06 +0000 Subject: [PATCH 064/980] Updated pull_request_template.md --- .azuredevops/pull_request_template.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.azuredevops/pull_request_template.md b/.azuredevops/pull_request_template.md index fd28ed57..f7533b37 100644 --- a/.azuredevops/pull_request_template.md +++ b/.azuredevops/pull_request_template.md @@ -9,5 +9,6 @@ - [ ] I have performed **self-review** of the code - [ ] I have written **tests** for any new functionality added with this PR - [ ] I have updated the **documentation** if this PR changes or adds functionality -- [ ] I have written/updated **design docs** if this PR implements new functionality. +- [ ] I have written/updated **design docs** if this PR implements new functionality +- [ ] I have update the **change log** - [ ] I have run **pre-commit** checks for code style From b58a3a3e24455707fbf5ae13d637565c7f30b9c6 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 7 Aug 2023 11:52:54 +0100 Subject: [PATCH 065/980] #1714: FileSystemItem is no longer an abstract base class + Added enums and enum sizes + stream lined FileSystemFile init --- .../simulator/file_system/file_system_file.py | 20 ++- .../file_system/file_system_file_type.py | 127 ++++++++++++++++-- .../file_system/file_system_folder.py | 4 +- .../file_system/file_system_item_abc.py | 8 +- .../_file_system/test_file_system.py | 4 +- .../_file_system/test_file_system_file.py | 4 +- .../_file_system/test_file_system_folder.py | 8 +- 7 files changed, 143 insertions(+), 32 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py index 441a27b0..efb1ae93 100644 --- a/src/primaite/simulator/file_system/file_system_file.py +++ b/src/primaite/simulator/file_system/file_system_file.py @@ -1,11 +1,11 @@ from random import choice, randint from typing import Dict -from primaite.simulator.file_system.file_system_file_type import FileSystemFileType -from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC +from primaite.simulator.file_system.file_system_file_type import file_type_sizes_KB, FileSystemFileType +from primaite.simulator.file_system.file_system_item_abc import FileSystemItem -class FileSystemFile(FileSystemItemABC): +class FileSystemFile(FileSystemItem): """Class that represents a file in the simulation.""" file_type: FileSystemFileType = None @@ -24,23 +24,19 @@ class FileSystemFile(FileSystemItemABC): :param item_size: The size of the FileSystemItem :type item_size: Optional[float] """ - super().__init__(**kwargs) - # set random file type if none provided if kwargs.get("item_name") is None: raise Exception("File name not provided.") - # set random file size if non provided - if kwargs.get("item_size") is None: - kwargs["item_size"] = float(randint(1, 1000)) - # set random file type if none provided if kwargs.get("file_type") is None: kwargs["file_type"] = choice(list(FileSystemFileType)) - self.item_name = kwargs.get("item_name") - self.item_size = kwargs.get("item_size") - self.file_type = kwargs.get("file_type") + # set random file size if none provided + if kwargs.get("item_size") is None: + kwargs["item_size"] = float(randint(1, file_type_sizes_KB[kwargs["file_type"]])) + + super().__init__(**kwargs) def get_file_name(self) -> str: """Returns the name of the file.""" diff --git a/src/primaite/simulator/file_system/file_system_file_type.py b/src/primaite/simulator/file_system/file_system_file_type.py index fd11f30f..7e2d8706 100644 --- a/src/primaite/simulator/file_system/file_system_file_type.py +++ b/src/primaite/simulator/file_system/file_system_file_type.py @@ -2,12 +2,123 @@ from enum import Enum class FileSystemFileType(str, Enum): - """Enum used to determine the FileSystemFile type.""" + """An enumeration of common file types.""" - CSV = ("CSV",) - DOC = ("DOC",) - EXE = ("EXE",) - PDF = ("PDF",) - TXT = ("TXT",) - XML = ("XML",) - ZIP = "ZIP" + UNKNOWN = 0 + "Unknown file type." + + # Text formats + TXT = 1 + "Plain text file." + DOC = 2 + "Microsoft Word document (.doc)" + DOCX = 3 + "Microsoft Word document (.docx)" + PDF = 4 + "Portable Document Format." + HTML = 5 + "HyperText Markup Language file." + XML = 6 + "Extensible Markup Language file." + CSV = 7 + "Comma-Separated Values file." + + # Spreadsheet formats + XLS = 8 + "Microsoft Excel file (.xls)" + XLSX = 9 + "Microsoft Excel file (.xlsx)" + + # Image formats + JPEG = 10 + "JPEG image file." + PNG = 11 + "PNG image file." + GIF = 12 + "GIF image file." + BMP = 13 + "Bitmap image file." + + # Audio formats + MP3 = 14 + "MP3 audio file." + WAV = 15 + "WAV audio file." + + # Video formats + MP4 = 16 + "MP4 video file." + AVI = 17 + "AVI video file." + MKV = 18 + "MKV video file." + FLV = 19 + "FLV video file." + + # Presentation formats + PPT = 20 + "Microsoft PowerPoint file (.ppt)" + PPTX = 21 + "Microsoft PowerPoint file (.pptx)" + + # Web formats + JS = 22 + "JavaScript file." + CSS = 23 + "Cascading Style Sheets file." + + # Programming languages + PY = 24 + "Python script file." + C = 25 + "C source code file." + CPP = 26 + "C++ source code file." + JAVA = 27 + "Java source code file." + + # Compressed file types + RAR = 28 + "RAR archive file." + ZIP = 29 + "ZIP archive file." + TAR = 30 + "TAR archive file." + GZ = 31 + "Gzip compressed file." + + +file_type_sizes_KB = { + FileSystemFileType.UNKNOWN: 0, + FileSystemFileType.TXT: 4, + FileSystemFileType.DOC: 50, + FileSystemFileType.DOCX: 30, + FileSystemFileType.PDF: 100, + FileSystemFileType.HTML: 15, + FileSystemFileType.XML: 10, + FileSystemFileType.CSV: 15, + FileSystemFileType.XLS: 100, + FileSystemFileType.XLSX: 25, + FileSystemFileType.JPEG: 100, + FileSystemFileType.PNG: 40, + FileSystemFileType.GIF: 30, + FileSystemFileType.BMP: 300, + FileSystemFileType.MP3: 5000, + FileSystemFileType.WAV: 25000, + FileSystemFileType.MP4: 25000, + FileSystemFileType.AVI: 50000, + FileSystemFileType.MKV: 50000, + FileSystemFileType.FLV: 15000, + FileSystemFileType.PPT: 200, + FileSystemFileType.PPTX: 100, + FileSystemFileType.JS: 10, + FileSystemFileType.CSS: 5, + FileSystemFileType.PY: 5, + FileSystemFileType.C: 5, + FileSystemFileType.CPP: 10, + FileSystemFileType.JAVA: 10, + FileSystemFileType.RAR: 1000, + FileSystemFileType.ZIP: 1000, + FileSystemFileType.TAR: 1000, + FileSystemFileType.GZ: 800, +} diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py index f5024966..a381e57d 100644 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -1,10 +1,10 @@ from typing import Dict, List, Optional from primaite.simulator.file_system.file_system_file import FileSystemFile -from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC +from primaite.simulator.file_system.file_system_item_abc import FileSystemItem -class FileSystemFolder(FileSystemItemABC): +class FileSystemFolder(FileSystemItem): """Simulation FileSystemFolder.""" files: List[FileSystemFile] = [] diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py index 4dca0f4e..a1258665 100644 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -1,9 +1,9 @@ -from abc import ABC +from typing import Dict from primaite.simulator.core import SimComponent -class FileSystemItemABC(SimComponent, ABC): +class FileSystemItem(SimComponent): """Abstract base class for FileSystemItems used in the file system simulation.""" item_size: float = 0 @@ -11,3 +11,7 @@ class FileSystemItemABC(SimComponent, ABC): item_name: str """The name of the file system item.""" + + def describe_state(self) -> Dict: + """Returns the state of the FileSystemItem.""" + pass diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index dae8b34e..f4c1ccda 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -10,7 +10,7 @@ def test_create_folder_and_file(): file_system.create_file(file_name="test_file", file_size=10, folder_uuid=folder.uuid) assert len(file_system.get_folders()[0].get_files()) is 1 assert file_system.get_folders()[0].get_files()[0].get_file_name() is "test_file" - assert file_system.get_folders()[0].get_files()[0].get_file_size() is 10 + assert file_system.get_folders()[0].get_files()[0].get_file_size() == 10 def test_create_file(): @@ -92,6 +92,6 @@ def test_serialisation(): assert len(file_system.get_folders()[0].get_files()) is 1 serialised_file_sys = file_system.model_dump_json() - deserialised_file_sys = FileSystem().model_validate_json(serialised_file_sys) + deserialised_file_sys = FileSystem.model_validate_json(serialised_file_sys) assert file_system == deserialised_file_sys diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py index 669be62d..ed4a4ad5 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py @@ -11,13 +11,13 @@ def test_file_type(): def test_get_file_size(): """Tests that the file size is being returned properly.""" file = FileSystemFile(item_name="test", item_size=1.5) - assert file.get_file_size() is 1.5 + assert file.get_file_size() == 1.5 def test_serialisation(): """Test to check that the object serialisation works correctly.""" file = FileSystemFile(item_name="test", item_size=1.5, file_type=FileSystemFileType.DOC) serialised_file = file.model_dump_json() - deserialised_file = FileSystemFile(item_name="test").model_validate_json(serialised_file) + deserialised_file = FileSystemFile.model_validate_json(serialised_file) assert file == deserialised_file diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py index f9ba80f0..871b4e94 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py @@ -10,11 +10,11 @@ def test_adding_removing_file(): file = FileSystemFile(item_name="test_file", item_size=10, file_type=FileSystemFileType.DOC) folder.add_file(file) - assert folder.get_folder_size() is 10 + assert folder.get_folder_size() == 10 assert len(folder.get_files()) is 1 folder.remove_file(file) - assert folder.get_folder_size() is 0 + assert folder.get_folder_size() == 0 assert len(folder.get_files()) is 0 @@ -27,7 +27,7 @@ def test_get_file_by_id(): folder.add_file(file) folder.add_file(file2) - assert folder.get_folder_size() is 20 + assert folder.get_folder_size() == 20 assert len(folder.get_files()) is 2 assert folder.get_file(file_id=file.uuid) is file @@ -54,6 +54,6 @@ def test_serialisation(): serialised_folder = folder.model_dump_json() - deserialised_folder = FileSystemFolder(item_name="test").model_validate_json(serialised_folder) + deserialised_folder = FileSystemFolder.model_validate_json(serialised_folder) assert folder == deserialised_folder From 554619e4b40a6789b3446ceda9fb94192f260941 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 7 Aug 2023 14:49:59 +0100 Subject: [PATCH 066/980] #1714: conver file and folder lists to dicts + fixing and adding a few more tests --- .../simulator/file_system/file_system.py | 64 +++++++++++++------ .../file_system/file_system_folder.py | 30 ++++++--- .../_file_system/test_file_system.py | 50 ++++++++++++--- .../_file_system/test_file_system_file.py | 2 +- .../_file_system/test_file_system_folder.py | 18 +++++- .../_primaite/_simulator/test_core.py | 4 +- 6 files changed, 128 insertions(+), 40 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index f8ae9d67..ce6eefb2 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -1,16 +1,19 @@ from random import choice -from typing import Dict, List, Optional +from typing import Dict, Optional +from primaite import getLogger from primaite.simulator.core import SimComponent from primaite.simulator.file_system.file_system_file import FileSystemFile from primaite.simulator.file_system.file_system_file_type import FileSystemFileType from primaite.simulator.file_system.file_system_folder import FileSystemFolder +_LOGGER = getLogger(__name__) + class FileSystem(SimComponent): """Class that contains all the simulation File System.""" - folders: List[FileSystemFolder] = [] + folders: Dict = {} """List containing all the folders in the file system.""" def describe_state(self) -> Dict: @@ -21,7 +24,7 @@ class FileSystem(SimComponent): """ pass - def get_folders(self) -> List[FileSystemFolder]: + def get_folders(self) -> Dict: """Returns the list of folders.""" return self.folders @@ -48,6 +51,9 @@ class FileSystem(SimComponent): :param: file_type: The type of the file :type: Optional[FileSystemFileType] + :param: folder: The folder to add the file to + :type: folder: Optional[FileSystemFolder] + :param: folder_uuid: The uuid of the folder to add the file to :type: folder_uuid: Optional[str] """ @@ -75,16 +81,21 @@ class FileSystem(SimComponent): # add file to root folder file = FileSystemFile(item_name=file_name, item_size=file_size, file_type=file_type) folder.add_file(file) - self.folders.append(folder) + self.folders[folder.uuid] = folder return file def create_folder( self, folder_name: str, ) -> FileSystemFolder: - """Creates a FileSystemFolder and adds it to the list of folders.""" + """ + Creates a FileSystemFolder and adds it to the list of folders. + + :param: folder_name: The name of the folder + :type: folder_name: str + """ folder = FileSystemFolder(item_name=folder_name) - self.folders.append(folder) + self.folders[folder.uuid] = folder return folder def delete_file(self, file: Optional[FileSystemFile] = None): @@ -93,13 +104,10 @@ class FileSystem(SimComponent): :param file: The file to delete :type file: Optional[FileSystemFile] - - :param file_id: The UUID of the file item to delete - :type file_id: Optional[str] """ # iterate through folders to delete the item with the matching uuid - for folder in self.folders: - folder.remove_file(file=file) + for key in self.folders: + self.get_folder_by_id(key).remove_file(file) def delete_folder(self, folder: FileSystemFolder): """ @@ -108,7 +116,13 @@ class FileSystem(SimComponent): :param folder: The folder to remove :type folder: FileSystemFolder """ - self.folders.remove(folder) + if folder is None or not isinstance(folder, FileSystemFolder): + raise Exception(f"Invalid folder: {folder}") + + if self.folders.get(folder.uuid): + del self.folders[folder.uuid] + else: + _LOGGER.debug(f"File with UUID {folder.uuid} was not found.") def move_file(self, file: FileSystemFile, src_folder: FileSystemFolder, target_folder: FileSystemFolder): """ @@ -170,8 +184,8 @@ class FileSystem(SimComponent): def get_file_by_id(self, file_id: str) -> FileSystemFile: """Checks if the file exists in any file system folders.""" - for folder in self.folders: - file = folder.get_file(file_id=file_id) + for key in self.folders: + file = self.folders[key].get_file(file_id=file_id) if file is not None: return file @@ -181,12 +195,26 @@ class FileSystem(SimComponent): :return: Returns the first FileSydtemFolder with a matching name """ - return next((f for f in self.folders if f.get_folder_name() == folder_name), None) + matching_folder = None + for key in self.folders: + if self.folders[key].get_folder_name() == folder_name: + matching_folder = self.folders[key] + break + return matching_folder def get_folder_by_id(self, folder_id: str) -> FileSystemFolder: - """Checks if the folder exists.""" - return next((f for f in self.folders if f.uuid == folder_id), None) + """ + Checks if the folder exists. + + :param: folder_id: The id of the folder to find + :type: folder_id: str + """ + return self.folders[folder_id] def get_random_file_type(self) -> FileSystemFileType: - """Returns a random FileSystemFileTypeEnum.""" + """ + Returns a random FileSystemFileTypeEnum. + + :return: A random file type Enum + """ return choice(list(FileSystemFileType)) diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py index a381e57d..d6ac3ef1 100644 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -1,13 +1,16 @@ -from typing import Dict, List, Optional +from typing import Dict, Optional +from primaite import getLogger from primaite.simulator.file_system.file_system_file import FileSystemFile from primaite.simulator.file_system.file_system_item_abc import FileSystemItem +_LOGGER = getLogger(__name__) + class FileSystemFolder(FileSystemItem): """Simulation FileSystemFolder.""" - files: List[FileSystemFile] = [] + files: Dict = {} """List of files stored in the folder.""" is_quarantined: bool = False @@ -21,20 +24,23 @@ class FileSystemFolder(FileSystemItem): """Returns the item_size of the folder.""" return self.item_size - def get_files(self) -> List[FileSystemFile]: - """Returns the list of files the folder contains.""" + def get_files(self) -> Dict: + """Returns the files dictionary.""" return self.files def get_file(self, file_id: str) -> FileSystemFile: """Return a FileSystemFile with the matching id.""" - return next((f for f in self.files if f.uuid == file_id), None) + return self.files[file_id] def add_file(self, file: FileSystemFile): """Adds a file to the folder list.""" + if file is None or not isinstance(file, FileSystemFile): + raise Exception(f"Invalid file: {file}") + self.item_size += file.get_file_size() # add to list - self.files.append(file) + self.files[file.uuid] = file def remove_file(self, file: Optional[FileSystemFile]): """ @@ -45,10 +51,16 @@ class FileSystemFolder(FileSystemItem): :param: file: The file to remove :type: Optional[FileSystemFile] """ - self.files.remove(file) + if file is None or not isinstance(file, FileSystemFile): + raise Exception(f"Invalid file: {file}") - # remove folder size from folder - self.item_size -= file.get_file_size() + if self.files.get(file.uuid): + del self.files[file.uuid] + + # remove folder size from folder + self.item_size -= file.get_file_size() + else: + _LOGGER.debug(f"File with UUID {file.uuid} was not found.") def quarantine(self): """Quarantines the File System Folder.""" diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index f4c1ccda..e0a6a2d9 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -1,4 +1,5 @@ from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.file_system.file_system_folder import FileSystemFolder def test_create_folder_and_file(): @@ -7,10 +8,11 @@ def test_create_folder_and_file(): folder = file_system.create_folder(folder_name="test_folder") assert len(file_system.get_folders()) is 1 - file_system.create_file(file_name="test_file", file_size=10, folder_uuid=folder.uuid) - assert len(file_system.get_folders()[0].get_files()) is 1 - assert file_system.get_folders()[0].get_files()[0].get_file_name() is "test_file" - assert file_system.get_folders()[0].get_files()[0].get_file_size() == 10 + file = file_system.create_file(file_name="test_file", file_size=10, folder_uuid=folder.uuid) + assert len(file_system.get_folder_by_id(folder.uuid).get_files()) is 1 + + assert file_system.get_file_by_id(file.uuid).get_file_name() is "test_file" + assert file_system.get_file_by_id(file.uuid).get_file_size() == 10 def test_create_file(): @@ -19,7 +21,7 @@ def test_create_file(): file = file_system.create_file(file_name="test_file", file_size=10) assert len(file_system.get_folders()) is 1 - assert file_system.get_folders()[0].get_file(file.uuid) is file + assert file_system.get_folder_by_name("root").get_file(file.uuid) is file def test_delete_file(): @@ -28,11 +30,31 @@ def test_delete_file(): file = file_system.create_file(file_name="test_file", file_size=10) assert len(file_system.get_folders()) is 1 - assert file_system.get_folders()[0].get_file(file.uuid) is file + + folder_id = list(file_system.get_folders().keys())[0] + folder = file_system.get_folder_by_id(folder_id) + assert folder.get_file(file.uuid) is file file_system.delete_file(file=file) assert len(file_system.get_folders()) is 1 - assert len(file_system.get_folders()[0].get_files()) is 0 + assert len(file_system.get_folder_by_id(folder.uuid).get_files()) is 0 + + +def test_delete_non_existent_file(): + """Tests deleting a non existent file.""" + file_system = FileSystem() + + file = file_system.create_file(file_name="test_file", file_size=10) + not_added_file = file_system.create_file(file_name="test_file", file_size=10) + assert len(file_system.get_folders()) is 1 + + folder_id = list(file_system.get_folders().keys())[0] + folder = file_system.get_folder_by_id(folder_id) + assert folder.get_file(file.uuid) is file + + file_system.delete_file(file=not_added_file) + assert len(file_system.get_folders()) is 1 + assert len(file_system.get_folder_by_id(folder.uuid).get_files()) is 1 def test_delete_folder(): @@ -44,6 +66,16 @@ def test_delete_folder(): assert len(file_system.get_folders()) is 0 +def test_deleting_a_non_existent_folder(): + file_system = FileSystem() + folder = file_system.create_folder(folder_name="test_folder") + not_added_folder = FileSystemFolder(item_name="fake_folder") + assert len(file_system.get_folders()) is 1 + + file_system.delete_folder(not_added_folder) + assert len(file_system.get_folders()) is 1 + + def test_move_file(): """Tests the file move function.""" file_system = FileSystem() @@ -89,9 +121,9 @@ def test_serialisation(): assert len(file_system.get_folders()) is 1 file_system.create_file(file_name="test_file", file_size=10, folder_uuid=folder.uuid) - assert len(file_system.get_folders()[0].get_files()) is 1 + assert file_system.get_folder_by_id(folder.uuid) is folder serialised_file_sys = file_system.model_dump_json() deserialised_file_sys = FileSystem.model_validate_json(serialised_file_sys) - assert file_system == deserialised_file_sys + assert file_system.model_dump_json() == deserialised_file_sys.model_dump_json() diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py index ed4a4ad5..51f4ce1b 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py @@ -20,4 +20,4 @@ def test_serialisation(): serialised_file = file.model_dump_json() deserialised_file = FileSystemFile.model_validate_json(serialised_file) - assert file == deserialised_file + assert file.model_dump_json() == deserialised_file.model_dump_json() diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py index 871b4e94..c56d2917 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py @@ -18,6 +18,22 @@ def test_adding_removing_file(): assert len(folder.get_files()) is 0 +def test_remove_non_existent_file(): + """Test the removing of a file that does not exist.""" + folder = FileSystemFolder(item_name="test") + + file = FileSystemFile(item_name="test_file", item_size=10, file_type=FileSystemFileType.DOC) + not_added_file = FileSystemFile(item_name="fake_file", item_size=10, file_type=FileSystemFileType.DOC) + + folder.add_file(file) + assert folder.get_folder_size() == 10 + assert len(folder.get_files()) is 1 + + folder.remove_file(not_added_file) + assert folder.get_folder_size() == 10 + assert len(folder.get_files()) is 1 + + def test_get_file_by_id(): """Test to make sure that the correct file is returned.""" folder = FileSystemFolder(item_name="test") @@ -56,4 +72,4 @@ def test_serialisation(): deserialised_folder = FileSystemFolder.model_validate_json(serialised_folder) - assert folder == deserialised_folder + assert folder.model_dump_json() == deserialised_folder.model_dump_json() diff --git a/tests/unit_tests/_primaite/_simulator/test_core.py b/tests/unit_tests/_primaite/_simulator/test_core.py index 00f29791..4e2df757 100644 --- a/tests/unit_tests/_primaite/_simulator/test_core.py +++ b/tests/unit_tests/_primaite/_simulator/test_core.py @@ -42,8 +42,8 @@ class TestIsolatedSimComponent: return {} comp = TestComponent(name="computer", size=(5, 10)) - dump = comp.model_dump() - assert dump["name"] is "computer" + dump = comp.model_dump_json() + assert comp == TestComponent.model_validate_json(dump) def test_apply_action(self): """Validate that we can override apply_action behaviour and it updates the state of the component.""" From a4c193cd34f8593e52e36d1a6a7c7f0ec1738092 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 7 Aug 2023 16:20:55 +0100 Subject: [PATCH 067/980] #1714: apply recommended changes with removing get methods and using the properties directly --- src/primaite/simulator/core.py | 2 +- .../simulator/file_system/file_system.py | 20 ++--- .../simulator/file_system/file_system_file.py | 26 ++---- .../file_system/file_system_folder.py | 22 +---- .../file_system/file_system_item_abc.py | 8 +- .../_file_system/test_file_system.py | 84 +++++++++---------- .../_file_system/test_file_system_file.py | 12 +-- .../_file_system/test_file_system_folder.py | 44 +++++----- 8 files changed, 96 insertions(+), 122 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 84b03498..5f8ad57c 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -10,7 +10,7 @@ class SimComponent(BaseModel): """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" uuid: str - "The component UUID." + """The component UUID.""" def __init__(self, **kwargs): if not kwargs.get("uuid"): diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index ce6eefb2..3290570e 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -31,7 +31,7 @@ class FileSystem(SimComponent): def create_file( self, file_name: str, - file_size: Optional[float] = None, + size: Optional[float] = None, file_type: Optional[FileSystemFileType] = None, folder: Optional[FileSystemFolder] = None, folder_uuid: Optional[str] = None, @@ -39,14 +39,14 @@ class FileSystem(SimComponent): """ Creates a FileSystemFile and adds it to the list of files. - If no file_size or file_type are provided, one will be chosen randomly. + If no size or file_type are provided, one will be chosen randomly. If no folder_uuid or folder is provided, a new folder will be created. :param: file_name: The file name :type: file_name: str - :param: file_size: The size the file takes on disk. - :type: file_size: Optional[float] + :param: size: The size the file takes on disk. + :type: size: Optional[float] :param: file_type: The type of the file :type: Optional[FileSystemFileType] @@ -69,17 +69,17 @@ class FileSystem(SimComponent): folder = self.get_folder_by_id(folder_uuid) if folder is not None: - file = FileSystemFile(item_name=file_name, item_size=file_size, file_type=file_type) + file = FileSystemFile(name=file_name, size=size, file_type=file_type) folder.add_file(file=file) else: # check if a "root" folder exists folder = self.get_folder_by_name("root") if folder is None: # create a root folder - folder = FileSystemFolder(item_name="root") + folder = FileSystemFolder(name="root") # add file to root folder - file = FileSystemFile(item_name=file_name, item_size=file_size, file_type=file_type) + file = FileSystemFile(name=file_name, size=size, file_type=file_type) folder.add_file(file) self.folders[folder.uuid] = folder return file @@ -94,7 +94,7 @@ class FileSystem(SimComponent): :param: folder_name: The name of the folder :type: folder_name: str """ - folder = FileSystemFolder(item_name=folder_name) + folder = FileSystemFolder(name=folder_name) self.folders[folder.uuid] = folder return folder @@ -185,7 +185,7 @@ class FileSystem(SimComponent): def get_file_by_id(self, file_id: str) -> FileSystemFile: """Checks if the file exists in any file system folders.""" for key in self.folders: - file = self.folders[key].get_file(file_id=file_id) + file = self.folders[key].get_file_by_id(file_id=file_id) if file is not None: return file @@ -197,7 +197,7 @@ class FileSystem(SimComponent): """ matching_folder = None for key in self.folders: - if self.folders[key].get_folder_name() == folder_name: + if self.folders[key].name == folder_name: matching_folder = self.folders[key] break return matching_folder diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py index efb1ae93..2de2084b 100644 --- a/src/primaite/simulator/file_system/file_system_file.py +++ b/src/primaite/simulator/file_system/file_system_file.py @@ -15,17 +15,17 @@ class FileSystemFile(FileSystemItem): """ Initialise FileSystemFile class. - :param item_name: The name of the file. - :type item_name: str + :param name: The name of the file. + :type name: str :param file_type: The FileSystemFileType of the file :type file_type: Optional[FileSystemFileType] - :param item_size: The size of the FileSystemItem - :type item_size: Optional[float] + :param size: The size of the FileSystemItem + :type size: Optional[float] """ # set random file type if none provided - if kwargs.get("item_name") is None: + if kwargs.get("name") is None: raise Exception("File name not provided.") # set random file type if none provided @@ -33,23 +33,11 @@ class FileSystemFile(FileSystemItem): kwargs["file_type"] = choice(list(FileSystemFileType)) # set random file size if none provided - if kwargs.get("item_size") is None: - kwargs["item_size"] = float(randint(1, file_type_sizes_KB[kwargs["file_type"]])) + if kwargs.get("size") is None: + kwargs["size"] = float(randint(1, file_type_sizes_KB[kwargs["file_type"]])) super().__init__(**kwargs) - def get_file_name(self) -> str: - """Returns the name of the file.""" - return self.item_name - - def get_file_size(self) -> float: - """Returns the size of the file system item.""" - return self.item_size - - def get_file_type(self) -> FileSystemFileType: - """Returns the FileSystemFileType of the file.""" - return self.file_type - def describe_state(self) -> Dict: """ Get the current state of the FileSystemFile as a dict. diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py index d6ac3ef1..79e19189 100644 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -16,31 +16,18 @@ class FileSystemFolder(FileSystemItem): is_quarantined: bool = False """Flag that marks the folder as quarantined if true.""" - def get_folder_name(self) -> str: - """Returns the item_name of the folder.""" - return self.item_name - - def get_folder_size(self) -> float: - """Returns the item_size of the folder.""" - return self.item_size - - def get_files(self) -> Dict: - """Returns the files dictionary.""" - return self.files - - def get_file(self, file_id: str) -> FileSystemFile: + def get_file_by_id(self, file_id: str) -> FileSystemFile: """Return a FileSystemFile with the matching id.""" - return self.files[file_id] + return self.files.get(file_id) def add_file(self, file: FileSystemFile): """Adds a file to the folder list.""" if file is None or not isinstance(file, FileSystemFile): raise Exception(f"Invalid file: {file}") - self.item_size += file.get_file_size() - # add to list self.files[file.uuid] = file + self.size += file.size def remove_file(self, file: Optional[FileSystemFile]): """ @@ -57,8 +44,7 @@ class FileSystemFolder(FileSystemItem): if self.files.get(file.uuid): del self.files[file.uuid] - # remove folder size from folder - self.item_size -= file.get_file_size() + self.size -= file.size else: _LOGGER.debug(f"File with UUID {file.uuid} was not found.") diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py index a1258665..0594cc35 100644 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -6,11 +6,11 @@ from primaite.simulator.core import SimComponent class FileSystemItem(SimComponent): """Abstract base class for FileSystemItems used in the file system simulation.""" - item_size: float = 0 - """The size the item takes up on disk.""" + name: str + """The name of the FileSystemItem.""" - item_name: str - """The name of the file system item.""" + size: float = 0 + """The size the item takes up on disk.""" def describe_state(self) -> Dict: """Returns the state of the FileSystemItem.""" diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index e0a6a2d9..5bebf487 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -6,121 +6,121 @@ def test_create_folder_and_file(): """Test creating a folder and a file.""" file_system = FileSystem() folder = file_system.create_folder(folder_name="test_folder") - assert len(file_system.get_folders()) is 1 + assert len(file_system.folders) is 1 - file = file_system.create_file(file_name="test_file", file_size=10, folder_uuid=folder.uuid) - assert len(file_system.get_folder_by_id(folder.uuid).get_files()) is 1 + file = file_system.create_file(file_name="test_file", size=10, folder_uuid=folder.uuid) + assert len(file_system.get_folder_by_id(folder.uuid).files) is 1 - assert file_system.get_file_by_id(file.uuid).get_file_name() is "test_file" - assert file_system.get_file_by_id(file.uuid).get_file_size() == 10 + assert file_system.get_file_by_id(file.uuid).name is "test_file" + assert file_system.get_file_by_id(file.uuid).size == 10 def test_create_file(): """Tests that creating a file without a folder creates a folder and sets that as the file's parent.""" file_system = FileSystem() - file = file_system.create_file(file_name="test_file", file_size=10) - assert len(file_system.get_folders()) is 1 - assert file_system.get_folder_by_name("root").get_file(file.uuid) is file + file = file_system.create_file(file_name="test_file", size=10) + assert len(file_system.folders) is 1 + assert file_system.get_folder_by_name("root").get_file_by_id(file.uuid) is file def test_delete_file(): """Tests that a file can be deleted.""" file_system = FileSystem() - file = file_system.create_file(file_name="test_file", file_size=10) - assert len(file_system.get_folders()) is 1 + file = file_system.create_file(file_name="test_file", size=10) + assert len(file_system.folders) is 1 - folder_id = list(file_system.get_folders().keys())[0] + folder_id = list(file_system.folders.keys())[0] folder = file_system.get_folder_by_id(folder_id) - assert folder.get_file(file.uuid) is file + assert folder.get_file_by_id(file.uuid) is file file_system.delete_file(file=file) - assert len(file_system.get_folders()) is 1 - assert len(file_system.get_folder_by_id(folder.uuid).get_files()) is 0 + assert len(file_system.folders) is 1 + assert len(file_system.get_folder_by_id(folder.uuid).files) is 0 def test_delete_non_existent_file(): """Tests deleting a non existent file.""" file_system = FileSystem() - file = file_system.create_file(file_name="test_file", file_size=10) - not_added_file = file_system.create_file(file_name="test_file", file_size=10) - assert len(file_system.get_folders()) is 1 + file = file_system.create_file(file_name="test_file", size=10) + not_added_file = file_system.create_file(file_name="test_file", size=10) + assert len(file_system.folders) is 1 - folder_id = list(file_system.get_folders().keys())[0] + folder_id = list(file_system.folders.keys())[0] folder = file_system.get_folder_by_id(folder_id) - assert folder.get_file(file.uuid) is file + assert folder.get_file_by_id(file.uuid) is file file_system.delete_file(file=not_added_file) - assert len(file_system.get_folders()) is 1 - assert len(file_system.get_folder_by_id(folder.uuid).get_files()) is 1 + assert len(file_system.folders) is 1 + assert len(file_system.get_folder_by_id(folder.uuid).files) is 1 def test_delete_folder(): file_system = FileSystem() folder = file_system.create_folder(folder_name="test_folder") - assert len(file_system.get_folders()) is 1 + assert len(file_system.folders) is 1 file_system.delete_folder(folder) - assert len(file_system.get_folders()) is 0 + assert len(file_system.folders) is 0 def test_deleting_a_non_existent_folder(): file_system = FileSystem() folder = file_system.create_folder(folder_name="test_folder") - not_added_folder = FileSystemFolder(item_name="fake_folder") - assert len(file_system.get_folders()) is 1 + not_added_folder = FileSystemFolder(name="fake_folder") + assert len(file_system.folders) is 1 file_system.delete_folder(not_added_folder) - assert len(file_system.get_folders()) is 1 + assert len(file_system.folders) is 1 def test_move_file(): """Tests the file move function.""" file_system = FileSystem() src_folder = file_system.create_folder(folder_name="test_folder_1") - assert len(file_system.get_folders()) is 1 + assert len(file_system.folders) is 1 target_folder = file_system.create_folder(folder_name="test_folder_2") - assert len(file_system.get_folders()) is 2 + assert len(file_system.folders) is 2 - file = file_system.create_file(file_name="test_file", file_size=10, folder_uuid=src_folder.uuid) - assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 1 - assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 0 + file = file_system.create_file(file_name="test_file", size=10, folder_uuid=src_folder.uuid) + assert len(file_system.get_folder_by_id(src_folder.uuid).files) is 1 + assert len(file_system.get_folder_by_id(target_folder.uuid).files) is 0 file_system.move_file(file=file, src_folder=src_folder, target_folder=target_folder) - assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 0 - assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 1 + assert len(file_system.get_folder_by_id(src_folder.uuid).files) is 0 + assert len(file_system.get_folder_by_id(target_folder.uuid).files) is 1 def test_copy_file(): """Tests the file copy function.""" file_system = FileSystem() src_folder = file_system.create_folder(folder_name="test_folder_1") - assert len(file_system.get_folders()) is 1 + assert len(file_system.folders) is 1 target_folder = file_system.create_folder(folder_name="test_folder_2") - assert len(file_system.get_folders()) is 2 + assert len(file_system.folders) is 2 - file = file_system.create_file(file_name="test_file", file_size=10, folder_uuid=src_folder.uuid) - assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 1 - assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 0 + file = file_system.create_file(file_name="test_file", size=10, folder_uuid=src_folder.uuid) + assert len(file_system.get_folder_by_id(src_folder.uuid).files) is 1 + assert len(file_system.get_folder_by_id(target_folder.uuid).files) is 0 file_system.copy_file(file=file, src_folder=src_folder, target_folder=target_folder) - assert len(file_system.get_folder_by_id(src_folder.uuid).get_files()) is 1 - assert len(file_system.get_folder_by_id(target_folder.uuid).get_files()) is 1 + assert len(file_system.get_folder_by_id(src_folder.uuid).files) is 1 + assert len(file_system.get_folder_by_id(target_folder.uuid).files) is 1 def test_serialisation(): """Test to check that the object serialisation works correctly.""" file_system = FileSystem() folder = file_system.create_folder(folder_name="test_folder") - assert len(file_system.get_folders()) is 1 + assert len(file_system.folders) is 1 - file_system.create_file(file_name="test_file", file_size=10, folder_uuid=folder.uuid) + file_system.create_file(file_name="test_file", size=10, folder_uuid=folder.uuid) assert file_system.get_folder_by_id(folder.uuid) is folder serialised_file_sys = file_system.model_dump_json() diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py index 51f4ce1b..629b9bb9 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py @@ -4,19 +4,19 @@ from primaite.simulator.file_system.file_system_file_type import FileSystemFileT def test_file_type(): """Tests tha the FileSystemFile type is set correctly.""" - file = FileSystemFile(item_name="test", file_type=FileSystemFileType.DOC) - assert file.get_file_type() is FileSystemFileType.DOC + file = FileSystemFile(name="test", file_type=FileSystemFileType.DOC) + assert file.file_type is FileSystemFileType.DOC -def test_get_file_size(): +def test_get_size(): """Tests that the file size is being returned properly.""" - file = FileSystemFile(item_name="test", item_size=1.5) - assert file.get_file_size() == 1.5 + file = FileSystemFile(name="test", size=1.5) + assert file.size == 1.5 def test_serialisation(): """Test to check that the object serialisation works correctly.""" - file = FileSystemFile(item_name="test", item_size=1.5, file_type=FileSystemFileType.DOC) + file = FileSystemFile(name="test", size=1.5, file_type=FileSystemFileType.DOC) serialised_file = file.model_dump_json() deserialised_file = FileSystemFile.model_validate_json(serialised_file) diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py index c56d2917..1940e886 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py @@ -5,53 +5,53 @@ from primaite.simulator.file_system.file_system_folder import FileSystemFolder def test_adding_removing_file(): """Test the adding and removing of a file from a folder.""" - folder = FileSystemFolder(item_name="test") + folder = FileSystemFolder(name="test") - file = FileSystemFile(item_name="test_file", item_size=10, file_type=FileSystemFileType.DOC) + file = FileSystemFile(name="test_file", size=10, file_type=FileSystemFileType.DOC) folder.add_file(file) - assert folder.get_folder_size() == 10 - assert len(folder.get_files()) is 1 + assert folder.size == 10 + assert len(folder.files) is 1 folder.remove_file(file) - assert folder.get_folder_size() == 0 - assert len(folder.get_files()) is 0 + assert folder.size == 0 + assert len(folder.files) is 0 def test_remove_non_existent_file(): """Test the removing of a file that does not exist.""" - folder = FileSystemFolder(item_name="test") + folder = FileSystemFolder(name="test") - file = FileSystemFile(item_name="test_file", item_size=10, file_type=FileSystemFileType.DOC) - not_added_file = FileSystemFile(item_name="fake_file", item_size=10, file_type=FileSystemFileType.DOC) + file = FileSystemFile(name="test_file", size=10, file_type=FileSystemFileType.DOC) + not_added_file = FileSystemFile(name="fake_file", size=10, file_type=FileSystemFileType.DOC) folder.add_file(file) - assert folder.get_folder_size() == 10 - assert len(folder.get_files()) is 1 + assert folder.size == 10 + assert len(folder.files) is 1 folder.remove_file(not_added_file) - assert folder.get_folder_size() == 10 - assert len(folder.get_files()) is 1 + assert folder.size == 10 + assert len(folder.files) is 1 def test_get_file_by_id(): """Test to make sure that the correct file is returned.""" - folder = FileSystemFolder(item_name="test") + folder = FileSystemFolder(name="test") - file = FileSystemFile(item_name="test_file", item_size=10, file_type=FileSystemFileType.DOC) - file2 = FileSystemFile(item_name="test_file_2", item_size=10, file_type=FileSystemFileType.DOC) + file = FileSystemFile(name="test_file", size=10, file_type=FileSystemFileType.DOC) + file2 = FileSystemFile(name="test_file_2", size=10, file_type=FileSystemFileType.DOC) folder.add_file(file) folder.add_file(file2) - assert folder.get_folder_size() == 20 - assert len(folder.get_files()) is 2 + assert folder.size == 20 + assert len(folder.files) is 2 - assert folder.get_file(file_id=file.uuid) is file + assert folder.get_file_by_id(file_id=file.uuid) is file def test_folder_quarantine_state(): """Tests the changing of folder quarantine status.""" - folder = FileSystemFolder(item_name="test") + folder = FileSystemFolder(name="test") assert folder.quarantine_status() is False @@ -64,8 +64,8 @@ def test_folder_quarantine_state(): def test_serialisation(): """Test to check that the object serialisation works correctly.""" - folder = FileSystemFolder(item_name="test") - file = FileSystemFile(item_name="test_file", item_size=10, file_type=FileSystemFileType.DOC) + folder = FileSystemFolder(name="test") + file = FileSystemFile(name="test_file", size=10, file_type=FileSystemFileType.DOC) folder.add_file(file) serialised_folder = folder.model_dump_json() From 700950b85627506728ebbdb83c5ed7e2bdc85255 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 7 Aug 2023 15:38:15 +0000 Subject: [PATCH 068/980] Apply suggestions from code review --- src/primaite/simulator/file_system/file_system_file.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py index 2de2084b..b3358372 100644 --- a/src/primaite/simulator/file_system/file_system_file.py +++ b/src/primaite/simulator/file_system/file_system_file.py @@ -25,8 +25,7 @@ class FileSystemFile(FileSystemItem): :type size: Optional[float] """ # set random file type if none provided - if kwargs.get("name") is None: - raise Exception("File name not provided.") + # set random file type if none provided if kwargs.get("file_type") is None: From 7eb0bb428fc26eb487a50ae496b3b2b8f4640eb2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 7 Aug 2023 17:24:14 +0100 Subject: [PATCH 069/980] Update code based on PR comments. --- src/primaite/simulator/core.py | 38 ++++++++++++++++++--- src/primaite/simulator/domain/account.py | 20 +++++------ src/primaite/simulator/domain/controller.py | 16 +++++---- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 17e09f85..fa5cd6c7 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -21,7 +21,7 @@ class ActionPermissionValidator(ABC): @abstractmethod def __call__(self, request: List[str], context: Dict) -> bool: - """TODO.""" + """Use the request and context paramters to decide whether the action should be permitted.""" pass @@ -52,6 +52,10 @@ class Action: turning it off, then the SimComponent should have a turn_off(self) method that does not need to accept any args. Then, this Action will be given something like ``func = lambda request, context: self.turn_off()``. + ``validator`` is an instance of a subclass of `ActionPermissionValidator`. This is essentially a callable that + accepts `request` and `context` and returns a boolean to represent whether the permission is granted to perform + the action. + :param func: Function that performs the request. :type func: Callable[[List[str], Dict], None] :param validator: Function that checks if the request is authenticated given the context. @@ -62,14 +66,28 @@ class Action: class ActionManager: - """TODO.""" + """ + ActionManager is used by `SimComponent` instances to keep track of actions. + + Its main purpose is to be a lookup from action name to action function and corresponding validation function. This + class is responsible for providing a consistent API for processing actions as well as helpful error messages. + """ def __init__(self) -> None: - """TODO.""" + """Initialise ActionManager with an empty action lookup.""" self.actions: Dict[str, Action] = {} def process_request(self, request: List[str], context: Dict) -> None: - """Process action request.""" + """Process an action request. + + :param request: A list of strings which specify what action to take. The first string must be one of the allowed + actions, i.e. it must be a key of self.actions. The subsequent strings in the list are passed as parameters + to the action function. + :type request: List[str] + :param context: Dictionary of additional information necessary to process or validate the request. + :type context: Dict + :raises RuntimeError: If the request parameter does not have a valid action identifier as the first item. + """ action_key = request[0] if action_key not in self.actions: @@ -90,6 +108,18 @@ class ActionManager: action.func(action_options, context) def add_action(self, name: str, action: Action) -> None: + """Add an action to this action manager. + + :param name: The string associated to this action. + :type name: str + :param action: Action object. + :type action: Action + """ + if name in self.actions: + msg = f"Attempted to register an action but the action name {name} is already taken." + _LOGGER.error(msg) + raise RuntimeError(msg) + self.actions[name] = action diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py index 086022e6..2d726624 100644 --- a/src/primaite/simulator/domain/account.py +++ b/src/primaite/simulator/domain/account.py @@ -11,25 +11,25 @@ _LOGGER = getLogger(__name__) class AccountType(Enum): """Whether the account is intended for a user to log in or for a service to use.""" - service = 1 + SERVICE = 1 "Service accounts are used to grant permissions to software on nodes to perform actions" - user = 2 + USER = 2 "User accounts are used to allow agents to log in and perform actions" class AccountStatus(Enum): """Whether the account is active.""" - enabled = 1 - disabled = 2 + ENABLED = 1 + DISABLED = 2 class PasswordPolicyLevel(Enum): """Complexity requirements for account passwords.""" - low = 1 - medium = 2 - high = 3 + LOW = 1 + MEDIUM = 2 + HIGH = 3 class Account(SimComponent): @@ -47,7 +47,7 @@ class Account(SimComponent): "Account password." account_type: AccountType "Account Type, currently this can be service account (used by apps) or user account." - status: AccountStatus = AccountStatus.disabled + status: AccountStatus = AccountStatus.DISABLED def describe_state(self) -> Dict: """Describe state for agent observations.""" @@ -55,11 +55,11 @@ class Account(SimComponent): def enable(self): """Set the status to enabled.""" - self.status = AccountStatus.enabled + self.status = AccountStatus.ENABLED def disable(self): """Set the status to disabled.""" - self.status = AccountStatus.disabled + self.status = AccountStatus.DISABLED def log_on(self) -> None: """TODO.""" diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index e4a73b4e..cc8063d6 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -47,7 +47,11 @@ class GroupMembershipValidator(ActionPermissionValidator): """Permit actions based on group membership.""" def __init__(self, allowed_groups: List[AccountGroup]) -> None: - """TODO.""" + """Store a list of groups that should be granted permission. + + :param allowed_groups: List of AccountGroups that are permitted to perform some action. + :type allowed_groups: List[AccountGroup] + """ self.allowed_groups = allowed_groups def __call__(self, request: List[str], context: Dict) -> bool: @@ -64,7 +68,7 @@ class DomainController(SimComponent): """Main object for controlling the domain.""" # owned objects - accounts: List[Account] = [] + accounts: Dict[str, Account] = {} groups: Final[List[AccountGroup]] = list(AccountGroup) domain_group_membership: Dict[Literal[AccountGroup.domain_admin, AccountGroup.domain_user], List[Account]] = {} @@ -73,10 +77,10 @@ class DomainController(SimComponent): ] = {} # references to non-owned objects. Not sure if all are needed here. - nodes: List[temp_node] = [] - applications: List[temp_application] = [] - folders: List[temp_folder] = [] - files: List[temp_file] = [] + nodes: Dict[str, temp_node] = {} + applications: Dict[str, temp_application] = {} + folders: List[temp_folder] = {} + files: List[temp_file] = {} def _register_account(self, account: Account) -> None: """TODO.""" From 139d7397320528a7a7474a4f171c6173b538024e Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 7 Aug 2023 19:33:52 +0100 Subject: [PATCH 070/980] #1706 - Tidies up the sysLog ARPCache, and ICMP classes and integrated them into the Node. Tidied up the base implementation of SoftwareManager and SessionManager. Tidies up the public API for Services and Applications. Added the SwitchPort and Switch classes. Added a basic test in test_frame_transmission.py that tests sending a frame from one node to another across a multi-switch network. --- src/primaite/__init__.py | 2 + src/primaite/simulator/__init__.py | 4 + .../simulator/network/hardware/base.py | 621 +++++++++++++----- .../icmp.py => network/nodes/switch.py} | 0 .../system/applications/application.py | 9 +- src/primaite/simulator/system/arp_cache.py | 30 - .../simulator/system/core/__init__.py | 0 .../system/{ => core}/packet_capture.py | 13 +- .../simulator/system/core/session_manager.py | 177 +++++ .../simulator/system/core/software_manager.py | 99 +++ .../simulator/system/{ => core}/sys_log.py | 10 +- .../simulator/system/processes/process.py | 3 +- .../simulator/system/services/service.py | 8 +- src/primaite/simulator/system/software.py | 48 +- .../network/test_frame_transmission.py | 38 +- 15 files changed, 846 insertions(+), 216 deletions(-) rename src/primaite/simulator/{system/services/icmp.py => network/nodes/switch.py} (100%) delete mode 100644 src/primaite/simulator/system/arp_cache.py create mode 100644 src/primaite/simulator/system/core/__init__.py rename src/primaite/simulator/system/{ => core}/packet_capture.py (82%) create mode 100644 src/primaite/simulator/system/core/session_manager.py create mode 100644 src/primaite/simulator/system/core/software_manager.py rename src/primaite/simulator/system/{ => core}/sys_log.py (90%) diff --git a/src/primaite/__init__.py b/src/primaite/__init__.py index ad157c9c..9a7ba596 100644 --- a/src/primaite/__init__.py +++ b/src/primaite/__init__.py @@ -16,6 +16,8 @@ from platformdirs import PlatformDirs with open(Path(__file__).parent.resolve() / "VERSION", "r") as file: __version__ = file.readline().strip() +_PRIMAITE_ROOT: Path = Path(__file__).parent + class _PrimaitePaths: """ diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index e69de29b..5b65ad40 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -0,0 +1,4 @@ +from primaite import _PRIMAITE_ROOT + +TEMP_SIM_OUTPUT = _PRIMAITE_ROOT.parent.parent / "simulation_output" +"A path at the repo root dir to use temporarily for sim output testing while in dev." diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 138c444c..739fb933 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -13,8 +13,10 @@ from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader -from primaite.simulator.system.packet_capture import PacketCapture -from primaite.simulator.system.sys_log import SysLog +from primaite.simulator.system.core.packet_capture import PacketCapture +from primaite.simulator.system.core.session_manager import SessionManager +from primaite.simulator.system.core.software_manager import SoftwareManager +from primaite.simulator.system.core.sys_log import SysLog _LOGGER = getLogger(__name__) @@ -103,8 +105,8 @@ class NIC(SimComponent): kwargs["ip_address"] = IPv4Address(kwargs["ip_address"]) if not isinstance(kwargs["gateway"], IPv4Address): kwargs["gateway"] = IPv4Address(kwargs["gateway"]) - if "mac_address" not in kwargs: - kwargs["mac_address"] = generate_mac_address() + if "mac_address" not in kwargs: + kwargs["mac_address"] = generate_mac_address() super().__init__(**kwargs) if self.ip_address == self.gateway: @@ -163,9 +165,9 @@ class NIC(SimComponent): """ if not self.connected_link: if self.connected_link != link: - _LOGGER.info(f"NIC {self} connected to Link") # TODO: Inform the Node that a link has been connected self.connected_link = link + _LOGGER.info(f"NIC {self} connected to Link {link}") else: _LOGGER.warning(f"Cannot connect link to NIC ({self.mac_address}) as it is already connected") else: @@ -254,23 +256,155 @@ class NIC(SimComponent): return f"{self.mac_address}/{self.ip_address}" +class SwitchPort(SimComponent): + """ + Models a switch port in a network switch device. + + :param mac_address: The MAC address of the SwitchPort. Defaults to a randomly set MAC address. + :param speed: The speed of the SwitchPort in Mbps (default is 100 Mbps). + :param mtu: The Maximum Transmission Unit (MTU) of the SwitchPort in Bytes, representing the largest data packet + size it can handle without fragmentation (default is 1500 B). + """ + + port_num: int = 1 + mac_address: str + "The MAC address of the SwitchPort. Defaults to a randomly set MAC address." + speed: int = 100 + "The speed of the SwitchPort in Mbps. Default is 100 Mbps." + mtu: int = 1500 + "The Maximum Transmission Unit (MTU) of the SwitchPort in Bytes. Default is 1500 B" + connected_node: Optional[Switch] = None + "The Node to which the SwitchPort is connected." + connected_link: Optional[Link] = None + "The Link to which the SwitchPort is connected." + enabled: bool = False + "Indicates whether the SwitchPort is enabled." + pcap: Optional[PacketCapture] = None + + def __init__(self, **kwargs): + """The SwitchPort constructor.""" + if "mac_address" not in kwargs: + kwargs["mac_address"] = generate_mac_address() + super().__init__(**kwargs) + + def enable(self): + """Attempt to enable the SwitchPort.""" + if not self.enabled: + if self.connected_node: + if self.connected_node.operating_state == NodeOperatingState.ON: + self.enabled = True + _LOGGER.info(f"SwitchPort {self} enabled") + self.pcap = PacketCapture(hostname=self.connected_node.hostname) + if self.connected_link: + self.connected_link.endpoint_up() + else: + _LOGGER.info(f"SwitchPort {self} cannot be enabled as the endpoint is not turned on") + else: + msg = f"SwitchPort {self} cannot be enabled as it is not connected to a Node" + _LOGGER.error(msg) + raise NetworkError(msg) + + def disable(self): + """Disable the SwitchPort.""" + if self.enabled: + self.enabled = False + _LOGGER.info(f"SwitchPort {self} disabled") + if self.connected_link: + self.connected_link.endpoint_down() + + def connect_link(self, link: Link): + """ + Connect the SwitchPort to a link. + + :param link: The link to which the SwitchPort is connected. + :raise NetworkError: When an attempt to connect a Link is made while the SwitchPort has a connected Link. + """ + if not self.connected_link: + if self.connected_link != link: + # TODO: Inform the Switch that a link has been connected + self.connected_link = link + _LOGGER.info(f"SwitchPort {self} connected to Link {link}") + self.enable() + else: + _LOGGER.warning(f"Cannot connect link to SwitchPort ({self.mac_address}) as it is already connected") + else: + msg = f"Cannot connect link to SwitchPort ({self.mac_address}) as it already has a connection" + _LOGGER.error(msg) + raise NetworkError(msg) + + def disconnect_link(self): + """Disconnect the SwitchPort from the connected Link.""" + if self.connected_link.endpoint_a == self: + self.connected_link.endpoint_a = None + if self.connected_link.endpoint_b == self: + self.connected_link.endpoint_b = None + self.connected_link = None + + def send_frame(self, frame: Frame) -> bool: + """ + Send a network frame from the SwitchPort to the connected link. + + :param frame: The network frame to be sent. + """ + if self.enabled: + self.pcap.capture(frame) + self.connected_link.transmit_frame(sender_nic=self, frame=frame) + return True + else: + # Cannot send Frame as the SwitchPort is not enabled + return False + + def receive_frame(self, frame: Frame) -> bool: + """ + Receive a network frame from the connected link if the SwitchPort is enabled. + + The Frame is passed to the Node. + + :param frame: The network frame being received. + """ + if self.enabled: + frame.decrement_ttl() + self.pcap.capture(frame) + self.connected_node.forward_frame(frame=frame, incoming_port=self) + return True + else: + return False + + def describe_state(self) -> Dict: + """ + Get the current state of the SwitchPort as a dict. + + :return: A dict containing the current state of the SwitchPort. + """ + pass + + def apply_action(self, action: str): + """ + Apply an action to the SwitchPort. + + :param action: The action to be applied. + :type action: str + """ + pass + + def __str__(self) -> str: + return f"{self.mac_address}" + + class Link(SimComponent): """ - Represents a network link between two network interface cards (NICs). + Represents a network link between NIC<-->, NIC<-->SwitchPort, or SwitchPort<-->SwitchPort. - :param endpoint_a: The first NIC connected to the Link. - :type endpoint_a: NIC - :param endpoint_b: The second NIC connected to the Link. - :type endpoint_b: NIC + :param endpoint_a: The first NIC or SwitchPort connected to the Link. + :param endpoint_b: The second NIC or SwitchPort connected to the Link. :param bandwidth: The bandwidth of the Link in Mbps (default is 100 Mbps). - :type bandwidth: int """ - endpoint_a: NIC - "The first NIC connected to the Link." - endpoint_b: NIC - "The second NIC connected to the Link." - bandwidth: int = 100 + endpoint_a: Union[NIC, SwitchPort] + "The first NIC or SwitchPort connected to the Link." + endpoint_b: Union[NIC, SwitchPort] + "The second NIC or SwitchPort connected to the Link." + bandwidth: float = 100.0 "The bandwidth of the Link in Mbps (default is 100 Mbps)." current_load: float = 0.0 "The current load on the link in Mbps." @@ -284,7 +418,7 @@ class Link(SimComponent): :raises ValueError: If endpoint_a and endpoint_b are the same NIC. """ if kwargs["endpoint_a"] == kwargs["endpoint_b"]: - msg = "endpoint_a and endpoint_b cannot be the same NIC" + msg = "endpoint_a and endpoint_b cannot be the same NIC or SwitchPort" _LOGGER.error(msg) raise ValueError(msg) super().__init__(**kwargs) @@ -292,6 +426,11 @@ class Link(SimComponent): self.endpoint_b.connect_link(self) self.endpoint_up() + @property + def current_load_percent(self) -> str: + """Get the current load formatted as a percentage string.""" + return f"{self.current_load / self.bandwidth:.5f}%" + def endpoint_up(self): """Let the Link know and endpoint has been brought up.""" if self.up: @@ -318,25 +457,30 @@ class Link(SimComponent): return self.current_load + frame_size_Mbits <= self.bandwidth return False - def transmit_frame(self, sender_nic: NIC, frame: Frame) -> bool: + def transmit_frame(self, sender_nic: Union[NIC, SwitchPort], frame: Frame) -> bool: """ - Send a network frame from one NIC to another connected NIC. + Send a network frame from one NIC or SwitchPort to another connected NIC or SwitchPort. - :param sender_nic: The NIC sending the frame. + :param sender_nic: The NIC or SwitchPort sending the frame. :param frame: The network frame to be sent. :return: True if the Frame can be sent, otherwise False. """ if self._can_transmit(frame): - receiver_nic = self.endpoint_a - if receiver_nic == sender_nic: - receiver_nic = self.endpoint_b + receiver = self.endpoint_a + if receiver == sender_nic: + receiver = self.endpoint_b frame_size = frame.size_Mbits - sent = receiver_nic.receive_frame(frame) + sent = receiver.receive_frame(frame) if sent: # Frame transmitted successfully # Load the frame size on the link self.current_load += frame_size - _LOGGER.info(f"Added {frame_size:.3f} Mbits to {self}, current load {self.current_load:.3f} Mbits") + ( + _LOGGER.info( + f"Added {frame_size:.3f} Mbits to {self}, current load {self.current_load:.3f} Mbits " + f"({self.current_load_percent})" + ) + ) return True # Received NIC disabled, reply @@ -345,7 +489,7 @@ class Link(SimComponent): _LOGGER.info(f"Cannot transmit frame as {self} is at capacity") return False - def reset_component_for_episode(self): + def reset_component_for_episode(self, episode: int): """ Link reset function. @@ -356,7 +500,7 @@ class Link(SimComponent): def describe_state(self) -> Dict: """ - Get the current state of the Libk as a dict. + Get the current state of the Link as a dict. :return: A dict containing the current state of the Link. """ @@ -375,108 +519,23 @@ class Link(SimComponent): return f"{self.endpoint_a}<-->{self.endpoint_b}" -class NodeOperatingState(Enum): - """Enumeration of Node Operating States.""" - - OFF = 0 - "The node is powered off." - ON = 1 - "The node is powered on." - SHUTTING_DOWN = 2 - "The node is in the process of shutting down." - BOOTING = 3 - "The node is in the process of booting up." - - -class Node(SimComponent): +class ARPCache: """ - A basic Node class. + The ARPCache (Address Resolution Protocol) class. - :param hostname: The node hostname on the network. - :param operating_state: The node operating state. + Responsible for maintaining a mapping between IP addresses and MAC addresses (ARP cache) for the network. It + provides methods for looking up, adding, and removing entries, and for processing ARPPackets. """ - hostname: str - "The node hostname on the network." - operating_state: NodeOperatingState = NodeOperatingState.OFF - "The hardware state of the node." - nics: Dict[str, NIC] = {} - "The NICs on the node." - - accounts: Dict = {} - "All accounts on the node." - applications: Dict = {} - "All applications on the node." - services: Dict = {} - "All services on the node." - processes: Dict = {} - "All processes on the node." - file_system: Any = None - "The nodes file system." - arp_cache: Dict[IPv4Address, ARPEntry] = {} - "The ARP cache." - sys_log: Optional[SysLog] = None - - revealed_to_red: bool = False - "Informs whether the node has been revealed to a red agent." - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.sys_log = SysLog(self.hostname) - - def turn_on(self): - """Turn on the Node.""" - if self.operating_state == NodeOperatingState.OFF: - self.operating_state = NodeOperatingState.ON - self.sys_log.info("Turned on") - for nic in self.nics.values(): - nic.enable() - - def turn_off(self): - """Turn off the Node.""" - if self.operating_state == NodeOperatingState.ON: - for nic in self.nics.values(): - nic.disable() - self.operating_state = NodeOperatingState.OFF - self.sys_log.info("Turned off") - - def connect_nic(self, nic: NIC): + def __init__(self, sys_log: "SysLog"): """ - Connect a NIC. + Initialize an ARP (Address Resolution Protocol) cache. - :param nic: The NIC to connect. - :raise NetworkError: If the NIC is already connected. + :param sys_log: The nodes sys log. """ - if nic.uuid not in self.nics: - self.nics[nic.uuid] = nic - nic.connected_node = self - self.sys_log.info(f"Connected NIC {nic}") - if self.operating_state == NodeOperatingState.ON: - nic.enable() - else: - msg = f"Cannot connect NIC {nic} as it is already connected" - self.sys_log.logger.error(msg) - _LOGGER.error(msg) - raise NetworkError(msg) - - def disconnect_nic(self, nic: Union[NIC, str]): - """ - Disconnect a NIC. - - :param nic: The NIC to Disconnect. - :raise NetworkError: If the NIC is not connected. - """ - if isinstance(nic, str): - nic = self.nics.get(nic) - if nic or nic.uuid in self.nics: - self.nics.pop(nic.uuid) - nic.disable() - self.sys_log.info(f"Disconnected NIC {nic}") - else: - msg = f"Cannot disconnect NIC {nic} as it is not connected" - self.sys_log.logger.error(msg) - _LOGGER.error(msg) - raise NetworkError(msg) + self.sys_log: "SysLog" = sys_log + self.arp: Dict[IPv4Address, ARPEntry] = {} + self.nics: Dict[str, "NIC"] = {} def _add_arp_cache_entry(self, ip_address: IPv4Address, mac_address: str, nic: NIC): """ @@ -488,7 +547,7 @@ class Node(SimComponent): """ self.sys_log.info(f"Adding ARP cache entry for {mac_address}/{ip_address} via NIC {nic}") arp_entry = ARPEntry(mac_address=mac_address, nic_uuid=nic.uuid) - self.arp_cache[ip_address] = arp_entry + self.arp[ip_address] = arp_entry def _remove_arp_cache_entry(self, ip_address: IPv4Address): """ @@ -496,37 +555,44 @@ class Node(SimComponent): :param ip_address: The IP address to be removed from the cache. """ - if ip_address in self.arp_cache: - del self.arp_cache[ip_address] + if ip_address in self.arp: + del self.arp[ip_address] - def _get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: + def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: """ Get the MAC address associated with an IP address. :param ip_address: The IP address to look up in the cache. :return: The MAC address associated with the IP address, or None if not found. """ - arp_entry = self.arp_cache.get(ip_address) + arp_entry = self.arp.get(ip_address) if arp_entry: return arp_entry.mac_address - def _get_arp_cache_nic(self, ip_address: IPv4Address) -> Optional[NIC]: + def get_arp_cache_nic(self, ip_address: IPv4Address) -> Optional[NIC]: """ Get the NIC associated with an IP address. :param ip_address: The IP address to look up in the cache. :return: The NIC associated with the IP address, or None if not found. """ - arp_entry = self.arp_cache.get(ip_address) + arp_entry = self.arp.get(ip_address) if arp_entry: return self.nics[arp_entry.nic_uuid] - def _clear_arp_cache(self): - """Clear the entire ARP cache.""" - self.arp_cache.clear() + def clear_arp_cache(self): + """Clear the entire ARP cache, removing all stored entries.""" + self.arp.clear() - def _send_arp_request(self, target_ip_address: Union[IPv4Address, str]): - """Perform a standard ARP request for a given target IP address.""" + def send_arp_request(self, target_ip_address: Union[IPv4Address, str]): + """ + Perform a standard ARP request for a given target IP address. + + Broadcasts the request through all enabled NICs to determine the MAC address corresponding to the target IP + address. + + :param target_ip_address: The target IP address to send an ARP request for. + """ for nic in self.nics.values(): if nic.enabled: self.sys_log.info(f"Sending ARP request from NIC {nic} for ip {target_ip_address}") @@ -547,12 +613,13 @@ class Node(SimComponent): def process_arp_packet(self, from_nic: NIC, arp_packet: ARPPacket): """ - Process an ARP packet. + Process a received ARP packet, handling both ARP requests and responses. - # TODO: This will become a service that sits on the Node. + If an ARP request is received for the local IP, a response is sent back. + If an ARP response is received, the ARP cache is updated with the new entry. - :param from_nic: The NIC the arp packet was received at. - :param arp_packet:The ARP packet to process. + :param from_nic: The NIC that received the ARP packet. + :param arp_packet: The ARP packet to be processed. """ if arp_packet.request: self.sys_log.info( @@ -581,7 +648,7 @@ class Node(SimComponent): src_mac_addr=arp_packet.sender_mac_addr, dst_mac_addr=arp_packet.target_mac_addr ) frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) - self.send_frame(frame) + from_nic.send_frame(frame) else: self.sys_log.info(f"Ignoring ARP request for {arp_packet.target_ip}") else: @@ -592,18 +659,34 @@ class Node(SimComponent): ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic ) + +class ICMP: + """ + The ICMP (Internet Control Message Protocol) class. + + Provides functionalities for managing and handling ICMP packets, including echo requests and replies. + """ + + def __init__(self, sys_log: SysLog, arp_cache: ARPCache): + """ + Initialize the ICMP (Internet Control Message Protocol) service. + + :param sys_log: The system log to store system messages and information. + :param arp_cache: The ARP cache for resolving IP to MAC address mappings. + """ + self.sys_log: SysLog = sys_log + self.arp: ARPCache = arp_cache + def process_icmp(self, frame: Frame): """ - Process an ICMP packet. + Process an ICMP packet, including handling echo requests and replies. - # TODO: This will become a service that sits on the Node. - - :param frame: The Frame containing the icmp packet to process. + :param frame: The Frame containing the ICMP packet to process. """ if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: self.sys_log.info(f"Received echo request from {frame.ip.src_ip}") - target_mac_address = self._get_arp_cache_mac_address(frame.ip.src_ip) - src_nic = self._get_arp_cache_nic(frame.ip.src_ip) + target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip) + src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip) tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) # Network Layer @@ -617,19 +700,28 @@ class Node(SimComponent): sequence=frame.icmp.sequence + 1, ) frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet) - self.sys_log.info(f"Sending echo reply to {frame.ip.src_ip}") + self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip}") src_nic.send_frame(frame) elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: self.sys_log.info(f"Received echo reply from {frame.ip.src_ip}") - def _ping( + def ping( self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None ) -> Tuple[int, Union[int, None]]: - nic = self._get_arp_cache_nic(target_ip_address) + """ + Send an ICMP echo request (ping) to a target IP address and manage the sequence and identifier. + + :param target_ip_address: The target IP address to send the ping. + :param sequence: The sequence number of the echo request. Defaults to 0. + :param identifier: An optional identifier for the ICMP packet. If None, a default will be used. + :return: A tuple containing the next sequence number and the identifier, or (0, None) if the target IP address + was not found in the ARP cache. + """ + nic = self.arp.get_arp_cache_nic(target_ip_address) if nic: sequence += 1 - target_mac_address = self._get_arp_cache_mac_address(target_ip_address) - src_nic = self._get_arp_cache_nic(target_ip_address) + target_mac_address = self.arp.get_arp_cache_mac_address(target_ip_address) + src_nic = self.arp.get_arp_cache_nic(target_ip_address) tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) # Network Layer @@ -647,17 +739,143 @@ class Node(SimComponent): return sequence, icmp_packet.identifier else: self.sys_log.info(f"No entry in ARP cache for {target_ip_address}") - self._send_arp_request(target_ip_address) + self.arp.send_arp_request(target_ip_address) return 0, None + +class NodeOperatingState(Enum): + """Enumeration of Node Operating States.""" + + OFF = 0 + "The node is powered off." + ON = 1 + "The node is powered on." + SHUTTING_DOWN = 2 + "The node is in the process of shutting down." + BOOTING = 3 + "The node is in the process of booting up." + + +class Node(SimComponent): + """ + A basic Node class that represents a node on the network. + + This class manages the state of the node, including the NICs (Network Interface Cards), accounts, applications, + services, processes, file system, and various managers like ARP, ICMP, SessionManager, and SoftwareManager. + + :param hostname: The node hostname on the network. + :param operating_state: The node operating state, either ON or OFF. + """ + + hostname: str + "The node hostname on the network." + operating_state: NodeOperatingState = NodeOperatingState.OFF + "The hardware state of the node." + nics: Dict[str, NIC] = {} + "The NICs on the node." + + accounts: Dict = {} + "All accounts on the node." + applications: Dict = {} + "All applications on the node." + services: Dict = {} + "All services on the node." + processes: Dict = {} + "All processes on the node." + file_system: Any = None + "The nodes file system." + sys_log: SysLog + arp: ARPCache + icmp: ICMP + session_manager: SessionManager + software_manager: SoftwareManager + + revealed_to_red: bool = False + "Informs whether the node has been revealed to a red agent." + + def __init__(self, **kwargs): + """ + Initialize the Node with various components and managers. + + This method initializes the ARP cache, ICMP handler, session manager, and software manager if they are not + provided. + """ + if not kwargs.get("sys_log"): + kwargs["sys_log"] = SysLog(kwargs["hostname"]) + if not kwargs.get("arp_cache"): + kwargs["arp"] = ARPCache(sys_log=kwargs.get("sys_log")) + if not kwargs.get("icmp"): + kwargs["icmp"] = ICMP(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp")) + if not kwargs.get("session_manager"): + kwargs["session_manager"] = SessionManager(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp")) + if not kwargs.get("software_manager"): + kwargs["software_manager"] = SoftwareManager( + sys_log=kwargs.get("sys_log"), session_manager=kwargs.get("session_manager") + ) + super().__init__(**kwargs) + self.arp.nics = self.nics + + def turn_on(self): + """Turn on the Node, enabling its NICs if it is in the OFF state.""" + if self.operating_state == NodeOperatingState.OFF: + self.operating_state = NodeOperatingState.ON + self.sys_log.info("Turned on") + for nic in self.nics.values(): + nic.enable() + + def turn_off(self): + """Turn off the Node, disabling its NICs if it is in the ON state.""" + if self.operating_state == NodeOperatingState.ON: + for nic in self.nics.values(): + nic.disable() + self.operating_state = NodeOperatingState.OFF + self.sys_log.info("Turned off") + + def connect_nic(self, nic: NIC): + """ + Connect a NIC (Network Interface Card) to the node. + + :param nic: The NIC to connect. + :raise NetworkError: If the NIC is already connected. + """ + if nic.uuid not in self.nics: + self.nics[nic.uuid] = nic + nic.connected_node = self + self.sys_log.info(f"Connected NIC {nic}") + if self.operating_state == NodeOperatingState.ON: + nic.enable() + else: + msg = f"Cannot connect NIC {nic} as it is already connected" + self.sys_log.logger.error(msg) + _LOGGER.error(msg) + raise NetworkError(msg) + + def disconnect_nic(self, nic: Union[NIC, str]): + """ + Disconnect a NIC (Network Interface Card) from the node. + + :param nic: The NIC to Disconnect, or its UUID. + :raise NetworkError: If the NIC is not connected. + """ + if isinstance(nic, str): + nic = self.nics.get(nic) + if nic or nic.uuid in self.nics: + self.nics.pop(nic.uuid) + nic.disable() + self.sys_log.info(f"Disconnected NIC {nic}") + else: + msg = f"Cannot disconnect NIC {nic} as it is not connected" + self.sys_log.logger.error(msg) + _LOGGER.error(msg) + raise NetworkError(msg) + def ping(self, target_ip_address: Union[IPv4Address, str], pings: int = 4) -> bool: """ - Ping an IP address. - - Performs a standard ICMP echo request/response four times. + Ping an IP address, performing a standard ICMP echo request/response. :param target_ip_address: The target IP address to ping. - :return: True if successful, otherwise False. + :param pings: The number of pings to attempt, default is 4. + :return: True if the ping is successful, otherwise False. """ if not isinstance(target_ip_address, IPv4Address): target_ip_address = IPv4Address(target_ip_address) @@ -665,7 +883,7 @@ class Node(SimComponent): self.sys_log.info(f"Attempting to ping {target_ip_address}") sequence, identifier = 0, None while sequence < pings: - sequence, identifier = self._ping(target_ip_address, sequence, identifier) + sequence, identifier = self.icmp.ping(target_ip_address, sequence, identifier) return True self.sys_log.info("Ping failed as the node is turned off") return False @@ -681,20 +899,101 @@ class Node(SimComponent): def receive_frame(self, frame: Frame, from_nic: NIC): """ - Receive a Frame from the connected NIC. + Receive a Frame from the connected NIC and process it. - The Frame is passed to up to the SessionManager. + Depending on the protocol, the frame is passed to the appropriate handler such as ARP or ICMP, or up to the + SessionManager if no code manager exists. :param frame: The Frame being received. + :param from_nic: The NIC that received the frame. """ if frame.ip.protocol == IPProtocol.TCP: if frame.tcp.src_port == Port.ARP: - self.process_arp_packet(from_nic=from_nic, arp_packet=frame.arp) + self.arp.process_arp_packet(from_nic=from_nic, arp_packet=frame.arp) elif frame.ip.protocol == IPProtocol.UDP: pass elif frame.ip.protocol == IPProtocol.ICMP: - self.process_icmp(frame=frame) + self.icmp.process_icmp(frame=frame) def describe_state(self) -> Dict: - """Describe the state of a Node.""" + """ + Describe the state of the Node. + + :return: A dictionary representing the state of the node. + """ pass + + +class Switch(Node): + """A class representing a Layer 2 network switch.""" + + num_ports: int = 24 + "The number of ports on the switch." + switch_ports: Dict[int, SwitchPort] = {} + "The SwitchPorts on the switch." + dst_mac_table: Dict[str, SwitchPort] = {} + "A MAC address table mapping destination MAC addresses to corresponding SwitchPorts." + + def describe_state(self) -> Dict: + """TODO.""" + pass + + def __init__(self, **kwargs): + super().__init__(**kwargs) + if not self.switch_ports: + self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)} + for port_num, port in self.switch_ports.items(): + port.connected_node = self + port.port_num = port_num + + def _add_mac_table_entry(self, mac_address: str, switch_port: SwitchPort): + mac_table_port = self.dst_mac_table.get(mac_address) + if not mac_table_port: + self.dst_mac_table[mac_address] = switch_port + self.sys_log.info(f"Added MAC table entry: Port {switch_port.port_num} -> {mac_address}") + else: + if mac_table_port != switch_port: + self.dst_mac_table.pop(mac_address) + self.sys_log.info(f"Removed MAC table entry: Port {mac_table_port.port_num} -> {mac_address}") + self._add_mac_table_entry(mac_address, switch_port) + + def forward_frame(self, frame: Frame, incoming_port: SwitchPort): + """ + Forward a frame to the appropriate port based on the destination MAC address. + + :param frame: The Frame to be forwarded. + :param incoming_port: The port number from which the frame was received. + """ + src_mac = frame.ethernet.src_mac_addr + dst_mac = frame.ethernet.dst_mac_addr + self._add_mac_table_entry(src_mac, incoming_port) + + outgoing_port = self.dst_mac_table.get(dst_mac) + if outgoing_port or dst_mac != "ff:ff:ff:ff:ff:ff": + outgoing_port.send_frame(frame) + else: + # If the destination MAC is not in the table, flood to all ports except incoming + for port in self.switch_ports.values(): + if port != incoming_port: + port.send_frame(frame) + + def disconnect_link_from_port(self, link: Link, port_number: int): + """ + Disconnect a given link from the specified port number on the switch. + + :param link: The Link object to be disconnected. + :param port_number: The port number on the switch from where the link should be disconnected. + :raise NetworkError: When an invalid port number is provided or the link does not match the connection. + """ + port = self.switch_ports.get(port_number) + if port is None: + msg = f"Invalid port number {port_number} on the switch" + _LOGGER.error(msg) + raise NetworkError(msg) + + if port.connected_link != link: + msg = f"The link does not match the connection at port number {port_number}" + _LOGGER.error(msg) + raise NetworkError(msg) + + port.disconnect_link() diff --git a/src/primaite/simulator/system/services/icmp.py b/src/primaite/simulator/network/nodes/switch.py similarity index 100% rename from src/primaite/simulator/system/services/icmp.py rename to src/primaite/simulator/network/nodes/switch.py diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 31a645b5..f9c5827d 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -1,6 +1,6 @@ from abc import abstractmethod from enum import Enum -from typing import Any, List, Dict, Set +from typing import Any, Dict, List, Set from primaite.simulator.system.software import IOSoftware @@ -22,6 +22,7 @@ class Application(IOSoftware): Applications are user-facing programs that may perform input/output operations. """ + operating_state: ApplicationOperatingState "The current operating state of the Application." execution_control_status: str @@ -61,9 +62,9 @@ class Application(IOSoftware): """ pass - def send(self, payload: Any) -> bool: + def send(self, payload: Any, session_id: str, **kwargs) -> bool: """ - Sends a payload to the SessionManager + Sends a payload to the SessionManager. The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. @@ -73,7 +74,7 @@ class Application(IOSoftware): """ pass - def receive(self, payload: Any) -> bool: + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ Receives a payload from the SessionManager. diff --git a/src/primaite/simulator/system/arp_cache.py b/src/primaite/simulator/system/arp_cache.py deleted file mode 100644 index 1fb830ab..00000000 --- a/src/primaite/simulator/system/arp_cache.py +++ /dev/null @@ -1,30 +0,0 @@ -from ipaddress import IPv4Address - -from pydantic import BaseModel - - -class ARPCacheService(BaseModel): - def __init__(self, node): - super().__init__() - self.node = node - - def _add_arp_cache_entry(self, ip_address: IPv4Address, mac_address: str, nic: NIC): - ... - - def _remove_arp_cache_entry(self, ip_address: IPv4Address): - ... - - def _get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: - ... - - def _get_arp_cache_nic(self, ip_address: IPv4Address) -> Optional[NIC]: - ... - - def _clear_arp_cache(self): - ... - - def _send_arp_request(self, target_ip_address: Union[IPv4Address, str]): - ... - - def process_arp_packet(self, from_nic: NIC, arp_packet: ARPPacket): - ... \ No newline at end of file diff --git a/src/primaite/simulator/system/core/__init__.py b/src/primaite/simulator/system/core/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py similarity index 82% rename from src/primaite/simulator/system/packet_capture.py rename to src/primaite/simulator/system/core/packet_capture.py index c05b6db9..7741416d 100644 --- a/src/primaite/simulator/system/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -1,5 +1,8 @@ import logging from pathlib import Path +from typing import Optional + +from primaite.simulator import TEMP_SIM_OUTPUT class _JSONFilter(logging.Filter): @@ -17,7 +20,7 @@ class PacketCapture: The PCAPs are logged to: //__pcap.log """ - def __init__(self, hostname: str, ip_address: str): + def __init__(self, hostname: str, ip_address: Optional[str] = None): """ Initialize the PacketCapture process. @@ -40,7 +43,7 @@ class PacketCapture: log_format = "%(message)s" file_handler.setFormatter(logging.Formatter(log_format)) - logger_name = f"{self.hostname}_{self.ip_address}_pcap" + logger_name = f"{self.hostname}_{self.ip_address}_pcap" if self.ip_address else f"{self.hostname}_pcap" self.logger = logging.getLogger(logger_name) self.logger.setLevel(60) # Custom log level > CRITICAL to prevent any unwanted standard DEBUG-CRITICAL logs self.logger.addHandler(file_handler) @@ -49,9 +52,11 @@ class PacketCapture: def _get_log_path(self) -> Path: """Get the path for the log file.""" - root = Path(__file__).parent.parent.parent.parent.parent.parent / "simulation_output" / self.hostname + root = TEMP_SIM_OUTPUT / self.hostname root.mkdir(exist_ok=True, parents=True) - return root / f"{self.hostname}_{self.ip_address}_pcap.log" + if self.ip_address: + return root / f"{self.hostname}_{self.ip_address}_pcap.log" + return root / f"{self.hostname}_pcap.log" def capture(self, frame): # noqa - I'll have a circular import and cant use if TYPE_CHECKING ;( """ diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py new file mode 100644 index 00000000..96d6251d --- /dev/null +++ b/src/primaite/simulator/system/core/session_manager.py @@ -0,0 +1,177 @@ +from __future__ import annotations + +from ipaddress import IPv4Address +from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING + +from primaite.simulator.core import SimComponent +from primaite.simulator.network.transmission.data_link_layer import Frame +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port + +if TYPE_CHECKING: + from primaite.simulator.network.hardware.base import ARPCache + from primaite.simulator.system.core.software_manager import SoftwareManager + from primaite.simulator.system.core.sys_log import SysLog + + +class Session(SimComponent): + """ + Models a network session. + + Encapsulates information related to communication between two network endpoints, including the protocol, + source and destination IPs and ports. + + :param protocol: The IP protocol used in the session. + :param src_ip: The source IP address. + :param dst_ip: The destination IP address. + :param src_port: The source port number (optional). + :param dst_port: The destination port number (optional). + :param connected: A flag indicating whether the session is connected. + """ + + protocol: IPProtocol + src_ip: IPv4Address + dst_ip: IPv4Address + src_port: Optional[Port] + dst_port: Optional[Port] + connected: bool = False + + @classmethod + def from_session_key( + cls, session_key: Tuple[IPProtocol, IPv4Address, IPv4Address, Optional[Port], Optional[Port]] + ) -> Session: + """ + Create a Session instance from a session key tuple. + + :param session_key: Tuple containing the session details. + :return: A Session instance. + """ + protocol, src_ip, dst_ip, src_port, dst_port = session_key + return Session(protocol=protocol, src_ip=src_ip, dst_ip=dst_ip, src_port=src_port, dst_port=dst_port) + + def describe_state(self) -> Dict: + """ + Describes the current state of the session as a dictionary. + + :return: A dictionary containing the current state of the session. + """ + pass + + +class SessionManager: + """ + Manages network sessions, including session creation, lookup, and communication with other components. + + :param sys_log: A reference to the system log component. + :param arp_cache: A reference to the ARP cache component. + """ + + def __init__(self, sys_log: SysLog, arp_cache: "ARPCache"): + self.sessions_by_key: Dict[ + Tuple[IPProtocol, IPv4Address, IPv4Address, Optional[Port], Optional[Port]], Session + ] = {} + self.sessions_by_uuid: Dict[str, Session] = {} + self.sys_log: SysLog = sys_log + self.software_manager: SoftwareManager = None # Noqa + self.arp_cache: "ARPCache" = arp_cache + + def describe_state(self) -> Dict: + """ + Describes the current state of the session manager as a dictionary. + + :return: A dictionary containing the current state of the session manager. + """ + pass + + @staticmethod + def _get_session_key( + frame: Frame, from_source: bool = True + ) -> Tuple[IPProtocol, IPv4Address, IPv4Address, Optional[Port], Optional[Port]]: + """ + Extracts the session key from the given frame. + + The session key is a tuple containing the following elements: + - IPProtocol: The transport protocol (e.g. TCP, UDP, ICMP). + - IPv4Address: The source IP address. + - IPv4Address: The destination IP address. + - Optional[Port]: The source port number (if applicable). + - Optional[Port]: The destination port number (if applicable). + + :param frame: The network frame from which to extract the session key. + :param from_source: A flag to indicate if the key should be extracted from the source or destination. + :return: A tuple containing the session key. + """ + protocol = frame.ip.protocol + src_ip = frame.ip.src_ip + dst_ip = frame.ip.dst_ip + if protocol == IPProtocol.TCP: + if from_source: + src_port = frame.tcp.src_port + dst_port = frame.tcp.dst_port + else: + dst_port = frame.tcp.src_port + src_port = frame.tcp.dst_port + elif protocol == IPProtocol.UDP: + if from_source: + src_port = frame.udp.src_port + dst_port = frame.udp.dst_port + else: + dst_port = frame.udp.src_port + src_port = frame.udp.dst_port + else: + src_port = None + dst_port = None + return protocol, src_ip, dst_ip, src_port, dst_port + + def receive_payload_from_software_manager(self, payload: Any, session_id: Optional[int] = None): + """ + Receive a payload from the SoftwareManager. + + If no session_id, a Session is established. Once established, the payload is sent to ``send_payload_to_nic``. + + :param payload: The payload to be sent. + :param session_id: The Session ID the payload is to originate from. Optional. If None, one will be created. + """ + # TODO: Implement session creation and + + self.send_payload_to_nic(payload, session_id) + + def send_payload_to_software_manager(self, payload: Any, session_id: int): + """ + Send a payload to the software manager. + + :param payload: The payload to be sent. + :param session_id: The Session ID the payload originates from. + """ + self.software_manager.receive_payload_from_session_manger() + + def send_payload_to_nic(self, payload: Any, session_id: int): + """ + Send a payload across the Network. + + Takes a payload and a session_id. Builds a Frame and sends it across the network via a NIC. + + :param payload: The payload to be sent. + :param session_id: The Session ID the payload originates from + """ + # TODO: Implement frame construction and sent to NIC. + pass + + def receive_payload_from_nic(self, frame: Frame): + """ + Receive a Frame from the NIC. + + Extract the session key using the _get_session_key method, and forward the payload to the appropriate + session. If the session does not exist, a new one is created. + + :param frame: The frame being received. + """ + session_key = self._get_session_key(frame) + session = self.sessions_by_key.get(session_key) + if not session: + # Create new session + session = Session.from_session_key(session_key) + self.sessions_by_key[session_key] = session + self.sessions_by_uuid[session.uuid] = session + self.software_manager.receive_payload_from_session_manger(payload=frame, session=session) + # TODO: Implement the frame deconstruction and send to SoftwareManager. diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py new file mode 100644 index 00000000..411fb6e9 --- /dev/null +++ b/src/primaite/simulator/system/core/software_manager.py @@ -0,0 +1,99 @@ +from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING, Union + +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.core.session_manager import Session +from primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.system.services.service import Service +from primaite.simulator.system.software import SoftwareType + +if TYPE_CHECKING: + from primaite.simulator.system.core.session_manager import SessionManager + from primaite.simulator.system.core.sys_log import SysLog + + +class SoftwareManager: + """A class that manages all running Services and Applications on a Node and facilitates their communication.""" + + def __init__(self, session_manager: "SessionManager", sys_log: "SysLog"): + """ + Initialize a new instance of SoftwareManager. + + :param session_manager: The session manager handling network communications. + """ + self.session_manager = session_manager + self.services: Dict[str, Service] = {} + self.applications: Dict[str, Application] = {} + self.port_protocol_mapping: Dict[Tuple[Port, IPProtocol], Union[Service, Application]] = {} + self.sys_log: SysLog = sys_log + + def add_service(self, name: str, service: Service, port: Port, protocol: IPProtocol): + """ + Add a Service to the manager. + + :param name: The name of the service. + :param service: The service instance. + :param port: The port used by the service. + :param protocol: The network protocol used by the service. + """ + service.software_manager = self + self.services[name] = service + self.port_protocol_mapping[(port, protocol)] = service + + def add_application(self, name: str, application: Application, port: Port, protocol: IPProtocol): + """ + Add an Application to the manager. + + :param name: The name of the application. + :param application: The application instance. + :param port: The port used by the application. + :param protocol: The network protocol used by the application. + """ + application.software_manager = self + self.applications[name] = application + self.port_protocol_mapping[(port, protocol)] = application + + def send_internal_payload(self, target_software: str, target_software_type: SoftwareType, payload: Any): + """ + Send a payload to a specific service or application. + + :param target_software: The name of the target service or application. + :param target_software_type: The type of software (Service, Application, Process). + :param payload: The data to be sent. + :param receiver_type: The type of the target, either 'service' or 'application'. + """ + if target_software_type is SoftwareType.SERVICE: + receiver = self.services.get(target_software) + elif target_software_type is SoftwareType.APPLICATION: + receiver = self.applications.get(target_software) + else: + raise ValueError(f"Invalid receiver type {target_software_type}") + + if receiver: + receiver.receive_payload(payload) + else: + raise ValueError(f"No {target_software_type.name.lower()} found with the name {target_software}") + + def send_payload_to_session_manger(self, payload: Any, session_id: Optional[int] = None): + """ + Send a payload to the SessionManager. + + :param payload: The payload to be sent. + :param session_id: The Session ID the payload is to originate from. Optional. + """ + self.session_manager.receive_payload_from_software_manager(payload, session_id) + + def receive_payload_from_session_manger(self, payload: Any, session: Session): + """ + Receive a payload from the SessionManager and forward it to the corresponding service or application. + + :param payload: The payload being received. + :param session: The transport session the payload originates from. + """ + # receiver: Optional[Union[Service, Application]] = self.port_protocol_mapping.get((port, protocol), None) + # if receiver: + # receiver.receive_payload(None, payload) + # else: + # raise ValueError(f"No service or application found for port {port} and protocol {protocol}") + pass diff --git a/src/primaite/simulator/system/sys_log.py b/src/primaite/simulator/system/core/sys_log.py similarity index 90% rename from src/primaite/simulator/system/sys_log.py rename to src/primaite/simulator/system/core/sys_log.py index bb2fd7ec..4b858c2e 100644 --- a/src/primaite/simulator/system/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -1,6 +1,8 @@ import logging from pathlib import Path +from primaite.simulator import TEMP_SIM_OUTPUT + class _NotJSONFilter(logging.Filter): def filter(self, record: logging.LogRecord) -> bool: @@ -31,8 +33,10 @@ class SysLog: def _setup_logger(self): """ - Configures the logger for this SysLog instance. The logger is set to the DEBUG level, - and is equipped with a handler that writes to a file and filters out JSON-like messages. + Configures the logger for this SysLog instance. + + The logger is set to the DEBUG level, and is equipped with a handler that writes to a file and filters out + JSON-like messages. """ log_path = self._get_log_path() @@ -54,7 +58,7 @@ class SysLog: :return: Path object representing the location of the log file. """ - root = Path(__file__).parent.parent.parent.parent.parent.parent / "simulation_output" / self.hostname + root = TEMP_SIM_OUTPUT / self.hostname root.mkdir(exist_ok=True, parents=True) return root / f"{self.hostname}_sys.log" diff --git a/src/primaite/simulator/system/processes/process.py b/src/primaite/simulator/system/processes/process.py index 68f3102f..bbd94345 100644 --- a/src/primaite/simulator/system/processes/process.py +++ b/src/primaite/simulator/system/processes/process.py @@ -1,6 +1,6 @@ from abc import abstractmethod from enum import Enum -from typing import List, Dict, Any +from typing import Dict from primaite.simulator.system.software import Software @@ -20,6 +20,7 @@ class Process(Software): Processes are executed by a Node and do not have the ability to performing input/output operations. """ + operating_state: ProcessOperatingState "The current operating state of the Process." diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index a66249ad..c820cef3 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -28,6 +28,7 @@ class Service(IOSoftware): Services are programs that run in the background and may perform input/output operations. """ + operating_state: ServiceOperatingState "The current operating state of the Service." @@ -61,9 +62,9 @@ class Service(IOSoftware): """ pass - def send(self, payload: Any) -> bool: + def send(self, payload: Any, session_id: str, **kwargs) -> bool: """ - Sends a payload to the SessionManager + Sends a payload to the SessionManager. The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. @@ -73,7 +74,7 @@ class Service(IOSoftware): """ pass - def receive(self, payload: Any) -> bool: + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ Receives a payload from the SessionManager. @@ -84,4 +85,3 @@ class Service(IOSoftware): :return: True if successful, False otherwise. """ pass - diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index e5991429..854e7e2b 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -6,6 +6,24 @@ from primaite.simulator.core import SimComponent from primaite.simulator.network.transmission.transport_layer import Port +class SoftwareType(Enum): + """ + An enumeration representing the different types of software within a simulated environment. + + Members: + - APPLICATION: User-facing programs that may perform input/output operations. + - SERVICE: Represents programs that run in the background and may perform input/output operations. + - PROCESS: Software executed by a Node that does not have the ability to performing input/output operations. + """ + + APPLICATION = 1 + "User-facing software that may perform input/output operations." + SERVICE = 2 + "Software that runs in the background and may perform input/output operations." + PROCESS = 3 + "Software executed by a Node that does not have the ability to performing input/output operations." + + class SoftwareHealthState(Enum): """Enumeration of the Software Health States.""" @@ -41,6 +59,7 @@ class Software(SimComponent): This class is intended to be subclassed by specific types of software entities. It outlines the fundamental attributes and behaviors expected of any software in the simulation. """ + name: str "The name of the software." health_state_actual: SoftwareHealthState @@ -100,6 +119,7 @@ class IOSoftware(Software): OSI Model), process them according to their internals, and send a response payload back to the SessionManager if required. """ + installing_count: int = 0 "The number of times the software has been installed. Default is 0." max_sessions: int = 1 @@ -111,26 +131,44 @@ class IOSoftware(Software): ports: Set[Port] "The set of ports to which the software is connected." - def send(self, payload: Any) -> bool: + @abstractmethod + def describe_state(self) -> Dict: """ - Sends a payload to the SessionManager + Describes the current state of the software. + + The specifics of the software's state, including its health, criticality, + and any other pertinent information, should be implemented in subclasses. + + :return: A dictionary containing key-value pairs representing the current state of the software. + :rtype: Dict + """ + pass + + def send(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Sends a payload to the SessionManager. The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. :param payload: The payload to send. - :return: True if successful, False otherwise. + :param session_id: The identifier of the session that the payload is associated with. + :param kwargs: Additional keyword arguments specific to the implementation. + :return: True if the payload was successfully sent, False otherwise. """ pass - def receive(self, payload: Any) -> bool: + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ Receives a payload from the SessionManager. The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. + :param payload: The payload to receive. - :return: True if successful, False otherwise. + :param session_id: The identifier of the session that the payload is associated with. + :param kwargs: Additional keyword arguments specific to the implementation. + :return: True if the payload was successfully received and processed, False otherwise. """ pass diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index 9681e72d..27545edc 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -1,4 +1,4 @@ -from primaite.simulator.network.hardware.base import Link, NIC, Node +from primaite.simulator.network.hardware.base import Link, NIC, Node, Switch def test_node_to_node_ping(): @@ -35,10 +35,40 @@ def test_multi_nic(): node_c.connect_nic(nic_c) node_c.turn_on() - link_a_b1 = Link(endpoint_a=nic_a, endpoint_b=nic_b1) + Link(endpoint_a=nic_a, endpoint_b=nic_b1) - link_b2_c = Link(endpoint_a=nic_b2, endpoint_b=nic_c) + Link(endpoint_a=nic_b2, endpoint_b=nic_c) node_a.ping("192.168.0.11") - node_c.ping("10.0.0.12") \ No newline at end of file + node_c.ping("10.0.0.12") + + +def test_switched_network(): + node_a = Node(hostname="node_a") + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") + node_a.connect_nic(nic_a) + node_a.turn_on() + + node_b = Node(hostname="node_b") + nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") + node_b.connect_nic(nic_b) + node_b.turn_on() + + node_c = Node(hostname="node_c") + nic_c = NIC(ip_address="192.168.0.12", subnet_mask="255.255.255.0", gateway="192.168.0.1") + node_c.connect_nic(nic_c) + node_c.turn_on() + + switch_1 = Switch(hostname="switch_1") + switch_1.turn_on() + + switch_2 = Switch(hostname="switch_2") + switch_2.turn_on() + + Link(endpoint_a=nic_a, endpoint_b=switch_1.switch_ports[1]) + Link(endpoint_a=nic_b, endpoint_b=switch_1.switch_ports[2]) + Link(endpoint_a=switch_1.switch_ports[24], endpoint_b=switch_2.switch_ports[24]) + Link(endpoint_a=nic_c, endpoint_b=switch_2.switch_ports[1]) + + node_a.ping("192.168.0.12") From c8ee409b3b26ad8351fa21f802523baf9755ee12 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 8 Aug 2023 08:29:51 +0100 Subject: [PATCH 071/980] #1714: run precommit --- src/primaite/simulator/file_system/file_system_file.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py index b3358372..5f784072 100644 --- a/src/primaite/simulator/file_system/file_system_file.py +++ b/src/primaite/simulator/file_system/file_system_file.py @@ -26,7 +26,6 @@ class FileSystemFile(FileSystemItem): """ # set random file type if none provided - # set random file type if none provided if kwargs.get("file_type") is None: kwargs["file_type"] = choice(list(FileSystemFileType)) From f854404ba0d3588443d6bfba328bb8ecfb82add1 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 8 Aug 2023 08:41:50 +0100 Subject: [PATCH 072/980] #1714: added file system to changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d66257b5..dd7e3466 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- File System - ability to emulate a node's file system during a simulation + ## [2.0.0] - 2023-07-26 ### Added From c2b783c858e159ceef0596d33d77becfb86c4ce4 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 8 Aug 2023 08:17:40 +0000 Subject: [PATCH 073/980] Apply suggestions from code review --- src/primaite/simulator/file_system/file_system_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py index 5f784072..95c824d6 100644 --- a/src/primaite/simulator/file_system/file_system_file.py +++ b/src/primaite/simulator/file_system/file_system_file.py @@ -32,7 +32,7 @@ class FileSystemFile(FileSystemItem): # set random file size if none provided if kwargs.get("size") is None: - kwargs["size"] = float(randint(1, file_type_sizes_KB[kwargs["file_type"]])) + kwargs["size"] = file_type_sizes_KB[kwargs["file_type"]] super().__init__(**kwargs) From 2f27e02877f8fdd921c8fd510b99fc60951896bb Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 8 Aug 2023 09:53:32 +0100 Subject: [PATCH 074/980] #1714: fix precommit --- src/primaite/simulator/file_system/file_system_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py index 95c824d6..f9fc2e1f 100644 --- a/src/primaite/simulator/file_system/file_system_file.py +++ b/src/primaite/simulator/file_system/file_system_file.py @@ -1,4 +1,4 @@ -from random import choice, randint +from random import choice from typing import Dict from primaite.simulator.file_system.file_system_file_type import file_type_sizes_KB, FileSystemFileType From 9fbc3c91f771fd8dbf96d3ad16633655590a6587 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 8 Aug 2023 20:22:18 +0100 Subject: [PATCH 075/980] #1706 - Finished up the Node and Switch MVP. Added full extensive documentation on what's happening at each step. --- CHANGELOG.md | 7 + docs/_static/four_node_two_switch_network.png | Bin 0 -> 90397 bytes docs/source/simulation.rst | 2 +- .../network/base_hardware.rst | 635 ++++++++++++++++-- .../network/transport_to_data_link_layer.rst | 13 + .../simulator/network/hardware/base.py | 74 +- .../network/{ => hardware}/nodes/__init__.py | 0 .../simulator/network/nodes/switch.py | 0 .../network/test_frame_transmission.py | 58 +- .../network/test_link_connection.py | 4 +- 10 files changed, 702 insertions(+), 91 deletions(-) create mode 100644 docs/_static/four_node_two_switch_network.png rename src/primaite/simulator/network/{ => hardware}/nodes/__init__.py (100%) delete mode 100644 src/primaite/simulator/network/nodes/switch.py diff --git a/CHANGELOG.md b/CHANGELOG.md index dd7e3466..dd8afbce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- Network Hardware - Added base hardware module with NIC, SwitchPort, Node, Switch, and Link. Nodes and Switches have +fundamental services like ARP, ICMP, and PCAP running them by default. +- Network Transmission - Modelled OSI Model layers 1 through to 5 with various classes for creating network frames and +transmitting them from a Service/Application, down through the layers, over the wire, and back up through the layers to +a Service/Application another machine. +- system - Added the core structure of Application, Services, and Components. Also added a SoftwareManager and +SessionManager. - File System - ability to emulate a node's file system during a simulation ## [2.0.0] - 2023-07-26 diff --git a/docs/_static/four_node_two_switch_network.png b/docs/_static/four_node_two_switch_network.png new file mode 100644 index 0000000000000000000000000000000000000000..4283910787c45b0fb9148d92432e19f033d80c85 GIT binary patch literal 90397 zcmeFZcT|+w*ELwSt+oLX6p*Z_Ah}U;6h#maP!!3aAlU+uoM|JH6$z3hDmiB;0~AUI zg+ii&faFX8RTOh>Y5(4L=C4_^zO}xYHE;EzyQ}I6_nxrN-sj$@o?g*Zq1nf>4}-zb zs9sXi#$fi*V=%j7|Jn_o9I0}62md){eo0#cgYo3XVEi9qFq`m^|4$6YLvyw z9fQFz-HorhDhpriHd9wo!fc~|l4~;~;FG;~FX=mBFhVEL-wyY51y}fRkF%=A#XS>$ z{dGW`&t~QVeD9A@RZ_g}-ZwMo<<2zrQewd{Vi#9E%Yy*DBVyUF1CqrJrVCTfc{FE7 zGDh`f{dM1rfwm;?o2}tYmV2Jwo4}r|Af4E)G_@wB1VQzx??}%v;hE zhoXn^7oMxG`^Xczr_V%KSy?(q9wGGa8w}=B=&|Gf zd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374 INFO: Turned on + 2023-08-08 15:50:08,381 INFO: SwitchPort aa:58:fa:66:d7:be enabled + 2023-08-08 15:50:08,383 INFO: SwitchPort 72:d2:1e:88:e9:45 enabled + 2023-08-08 15:50:08,384 INFO: SwitchPort 96:77:39:d1:de:44 enabled + 2023-08-08 15:50:08,411 INFO: Added MAC table entry: Port 6 -> 80:af:f2:f6:58:b7 + 2023-08-08 15:50:08,412 INFO: Added MAC table entry: Port 2 -> 84:20:7c:ec:a5:c6 diff --git a/docs/source/simulation_components/network/transport_to_data_link_layer.rst b/docs/source/simulation_components/network/transport_to_data_link_layer.rst index 9332b57c..4961d337 100644 --- a/docs/source/simulation_components/network/transport_to_data_link_layer.rst +++ b/docs/source/simulation_components/network/transport_to_data_link_layer.rst @@ -55,6 +55,19 @@ PrimAITE-specific metadata required for reinforcement learning (RL) purposes. Data Link Layer (Layer 2) ######################### +**ARPEntry:** Represents an entry in the ARP cache. It consists of the following fields: + + - **mac_address:** The MAC address associated with the IP address. + - **nic_uuid:** The NIC (Network Interface Card) UUID through which the NIC with the IP address is reachable. + +**ARPPacket:** Represents the ARP layer of a network frame, and it includes the following fields: + + - **request:** ARP operation. Set to True for a request and False for a reply. + - **sender_mac_addr:** Sender's MAC address. + - **sender_ip:** Sender's IP address (IPv4 format). + - **target_mac_addr:** Target's MAC address. + - **target_ip:** Target's IP address (IPv4 format). + **EthernetHeader:** Represents the Ethernet layer of a network frame. It includes source and destination MAC addresses. This header is used to identify the physical hardware addresses of devices on a local network. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 739fb933..eb406521 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -6,6 +6,8 @@ from enum import Enum from ipaddress import IPv4Address, IPv4Network from typing import Any, Dict, List, Optional, Tuple, Union +from prettytable import PrettyTable + from primaite import getLogger from primaite.exceptions import NetworkError from primaite.simulator.core import SimComponent @@ -136,22 +138,23 @@ class NIC(SimComponent): if self.connected_node: if self.connected_node.operating_state == NodeOperatingState.ON: self.enabled = True - _LOGGER.info(f"NIC {self} enabled") + self.connected_node.sys_log.info(f"NIC {self} enabled") self.pcap = PacketCapture(hostname=self.connected_node.hostname, ip_address=self.ip_address) if self.connected_link: self.connected_link.endpoint_up() else: - _LOGGER.info(f"NIC {self} cannot be enabled as the endpoint is not turned on") + self.connected_node.sys_log.error(f"NIC {self} cannot be enabled as the endpoint is not turned on") else: - msg = f"NIC {self} cannot be enabled as it is not connected to a Node" - _LOGGER.error(msg) - raise NetworkError(msg) + _LOGGER.error(f"NIC {self} cannot be enabled as it is not connected to a Node") def disable(self): """Disable the NIC.""" if self.enabled: self.enabled = False - _LOGGER.info(f"NIC {self} disabled") + if self.connected_node: + self.connected_node.sys_log.info(f"NIC {self} disabled") + else: + _LOGGER.info(f"NIC {self} disabled") if self.connected_link: self.connected_link.endpoint_down() @@ -161,7 +164,6 @@ class NIC(SimComponent): :param link: The link to which the NIC is connected. :type link: :class:`~primaite.simulator.network.transmission.physical_layer.Link` - :raise NetworkError: When an attempt to connect a Link is made while the NIC has a connected Link. """ if not self.connected_link: if self.connected_link != link: @@ -169,11 +171,9 @@ class NIC(SimComponent): self.connected_link = link _LOGGER.info(f"NIC {self} connected to Link {link}") else: - _LOGGER.warning(f"Cannot connect link to NIC ({self.mac_address}) as it is already connected") + _LOGGER.error(f"Cannot connect Link to NIC ({self.mac_address}) as it is already connected") else: - msg = f"Cannot connect link to NIC ({self.mac_address}) as it already has a connection" - _LOGGER.error(msg) - raise NetworkError(msg) + _LOGGER.error(f"Cannot connect Link to NIC ({self.mac_address}) as it already has a connection") def disconnect_link(self): """Disconnect the NIC from the connected Link.""" @@ -293,12 +293,14 @@ class SwitchPort(SimComponent): if self.connected_node: if self.connected_node.operating_state == NodeOperatingState.ON: self.enabled = True - _LOGGER.info(f"SwitchPort {self} enabled") + self.connected_node.sys_log.info(f"SwitchPort {self} enabled") self.pcap = PacketCapture(hostname=self.connected_node.hostname) if self.connected_link: self.connected_link.endpoint_up() else: - _LOGGER.info(f"SwitchPort {self} cannot be enabled as the endpoint is not turned on") + self.connected_node.sys_log.info( + f"SwitchPort {self} cannot be enabled as the endpoint is not turned on" + ) else: msg = f"SwitchPort {self} cannot be enabled as it is not connected to a Node" _LOGGER.error(msg) @@ -308,7 +310,10 @@ class SwitchPort(SimComponent): """Disable the SwitchPort.""" if self.enabled: self.enabled = False - _LOGGER.info(f"SwitchPort {self} disabled") + if self.connected_node: + self.connected_node.sys_log.info(f"SwitchPort {self} disabled") + else: + _LOGGER.info(f"SwitchPort {self} disabled") if self.connected_link: self.connected_link.endpoint_down() @@ -317,7 +322,6 @@ class SwitchPort(SimComponent): Connect the SwitchPort to a link. :param link: The link to which the SwitchPort is connected. - :raise NetworkError: When an attempt to connect a Link is made while the SwitchPort has a connected Link. """ if not self.connected_link: if self.connected_link != link: @@ -326,11 +330,9 @@ class SwitchPort(SimComponent): _LOGGER.info(f"SwitchPort {self} connected to Link {link}") self.enable() else: - _LOGGER.warning(f"Cannot connect link to SwitchPort ({self.mac_address}) as it is already connected") + _LOGGER.error(f"Cannot connect Link to SwitchPort {self.mac_address} as it is already connected") else: - msg = f"Cannot connect link to SwitchPort ({self.mac_address}) as it already has a connection" - _LOGGER.error(msg) - raise NetworkError(msg) + _LOGGER.error(f"Cannot connect link to SwitchPort {self.mac_address} as it already has a connection") def disconnect_link(self): """Disconnect the SwitchPort from the connected Link.""" @@ -815,16 +817,34 @@ class Node(SimComponent): super().__init__(**kwargs) self.arp.nics = self.nics - def turn_on(self): - """Turn on the Node, enabling its NICs if it is in the OFF state.""" + def show(self): + """Prints a table of the NICs on the Node..""" + from prettytable import PrettyTable + + table = PrettyTable(["MAC Address", "Address", "Default Gateway", "Speed", "Status"]) + + for nic in self.nics.values(): + table.add_row( + [ + nic.mac_address, + f"{nic.ip_address}/{nic.ip_network.prefixlen}", + nic.gateway, + nic.speed, + "Enabled" if nic.enabled else "Disabled", + ] + ) + print(table) + + def power_on(self): + """Power on the Node, enabling its NICs if it is in the OFF state.""" if self.operating_state == NodeOperatingState.OFF: self.operating_state = NodeOperatingState.ON self.sys_log.info("Turned on") for nic in self.nics.values(): nic.enable() - def turn_off(self): - """Turn off the Node, disabling its NICs if it is in the ON state.""" + def power_off(self): + """Power off the Node, disabling its NICs if it is in the ON state.""" if self.operating_state == NodeOperatingState.ON: for nic in self.nics.values(): nic.disable() @@ -934,6 +954,14 @@ class Switch(Node): dst_mac_table: Dict[str, SwitchPort] = {} "A MAC address table mapping destination MAC addresses to corresponding SwitchPorts." + def show(self): + """Prints a table of the SwitchPorts on the Switch.""" + table = PrettyTable(["Port", "MAC Address", "Speed", "Status"]) + + for port_num, port in self.switch_ports.items(): + table.add_row([port_num, port.mac_address, port.speed, "Enabled" if port.enabled else "Disabled"]) + print(table) + def describe_state(self) -> Dict: """TODO.""" pass diff --git a/src/primaite/simulator/network/nodes/__init__.py b/src/primaite/simulator/network/hardware/nodes/__init__.py similarity index 100% rename from src/primaite/simulator/network/nodes/__init__.py rename to src/primaite/simulator/network/hardware/nodes/__init__.py diff --git a/src/primaite/simulator/network/nodes/switch.py b/src/primaite/simulator/network/nodes/switch.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index 27545edc..3840c302 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -2,15 +2,17 @@ from primaite.simulator.network.hardware.base import Link, NIC, Node, Switch def test_node_to_node_ping(): + """Tests two Nodes are able to ping each other.""" + # TODO Add actual checks. Manual check performed for now. node_a = Node(hostname="node_a") nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") node_a.connect_nic(nic_a) - node_a.turn_on() + node_a.power_on() node_b = Node(hostname="node_b") nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") node_b.connect_nic(nic_b) - node_b.turn_on() + node_b.power_on() Link(endpoint_a=nic_a, endpoint_b=nic_b) @@ -18,22 +20,24 @@ def test_node_to_node_ping(): def test_multi_nic(): + """Tests that Nodes with multiple NICs can ping each other and the data go across the correct links.""" + # TODO Add actual checks. Manual check performed for now. node_a = Node(hostname="node_a") nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") node_a.connect_nic(nic_a) - node_a.turn_on() + node_a.power_on() node_b = Node(hostname="node_b") nic_b1 = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") nic_b2 = NIC(ip_address="10.0.0.12", subnet_mask="255.0.0.0", gateway="10.0.0.1") node_b.connect_nic(nic_b1) node_b.connect_nic(nic_b2) - node_b.turn_on() + node_b.power_on() node_c = Node(hostname="node_c") nic_c = NIC(ip_address="10.0.0.13", subnet_mask="255.0.0.0", gateway="10.0.0.1") node_c.connect_nic(nic_c) - node_c.turn_on() + node_c.power_on() Link(endpoint_a=nic_a, endpoint_b=nic_b1) @@ -45,30 +49,38 @@ def test_multi_nic(): def test_switched_network(): - node_a = Node(hostname="node_a") + """Tests a larges network of Nodes and Switches with one node pinging another.""" + # TODO Add actual checks. Manual check performed for now. + pc_a = Node(hostname="pc_a") nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") - node_a.connect_nic(nic_a) - node_a.turn_on() + pc_a.connect_nic(nic_a) + pc_a.power_on() - node_b = Node(hostname="node_b") + pc_b = Node(hostname="pc_b") nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") - node_b.connect_nic(nic_b) - node_b.turn_on() + pc_b.connect_nic(nic_b) + pc_b.power_on() - node_c = Node(hostname="node_c") + pc_c = Node(hostname="pc_c") nic_c = NIC(ip_address="192.168.0.12", subnet_mask="255.255.255.0", gateway="192.168.0.1") - node_c.connect_nic(nic_c) - node_c.turn_on() + pc_c.connect_nic(nic_c) + pc_c.power_on() - switch_1 = Switch(hostname="switch_1") - switch_1.turn_on() + pc_d = Node(hostname="pc_d") + nic_d = NIC(ip_address="192.168.0.13", subnet_mask="255.255.255.0", gateway="192.168.0.1") + pc_d.connect_nic(nic_d) + pc_d.power_on() - switch_2 = Switch(hostname="switch_2") - switch_2.turn_on() + switch_1 = Switch(hostname="switch_1", num_ports=6) + switch_1.power_on() - Link(endpoint_a=nic_a, endpoint_b=switch_1.switch_ports[1]) - Link(endpoint_a=nic_b, endpoint_b=switch_1.switch_ports[2]) - Link(endpoint_a=switch_1.switch_ports[24], endpoint_b=switch_2.switch_ports[24]) - Link(endpoint_a=nic_c, endpoint_b=switch_2.switch_ports[1]) + switch_2 = Switch(hostname="switch_2", num_ports=6) + switch_2.power_on() - node_a.ping("192.168.0.12") + link_nic_a_switch_1 = Link(endpoint_a=nic_a, endpoint_b=switch_1.switch_ports[1]) + link_nic_b_switch_1 = Link(endpoint_a=nic_b, endpoint_b=switch_1.switch_ports[2]) + link_nic_c_switch_2 = Link(endpoint_a=nic_c, endpoint_b=switch_2.switch_ports[1]) + link_nic_d_switch_2 = Link(endpoint_a=nic_d, endpoint_b=switch_2.switch_ports[2]) + link_switch_1_switch_2 = Link(endpoint_a=switch_1.switch_ports[6], endpoint_b=switch_2.switch_ports[6]) + + pc_a.ping("192.168.0.13") diff --git a/tests/integration_tests/network/test_link_connection.py b/tests/integration_tests/network/test_link_connection.py index 50abed77..92909cf6 100644 --- a/tests/integration_tests/network/test_link_connection.py +++ b/tests/integration_tests/network/test_link_connection.py @@ -6,13 +6,13 @@ def test_link_up(): node_a = Node(hostname="node_a") nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") node_a.connect_nic(nic_a) - node_a.turn_on() + node_a.power_on() assert nic_a.enabled node_b = Node(hostname="node_b") nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") node_b.connect_nic(nic_b) - node_b.turn_on() + node_b.power_on() assert nic_b.enabled From a840159460b3fc8ba561abf45dff26dd12a58089 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 8 Aug 2023 20:30:37 +0100 Subject: [PATCH 076/980] #1706 - Fixed the "smart" merging of SimComponent that PyCharm performed. Integrated the Filesystem class into the Node. Added prettytable to deps in pyproject.toml --- pyproject.toml | 1 + src/primaite/simulator/core.py | 8 -------- src/primaite/simulator/network/hardware/base.py | 7 +++++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 74de37df..082ac16f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ dependencies = [ "platformdirs==3.5.1", "plotly==5.15.0", "polars==0.18.4", + "prettytable==3.8.0", "PyYAML==6.0", "stable-baselines3==1.6.2", "tensorflow==2.12.0", diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index b157a994..a48709e0 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -9,9 +9,6 @@ from pydantic import BaseModel, ConfigDict class SimComponent(BaseModel): """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" - uuid: str - """The component UUID.""" - def __init__(self, **kwargs): if not kwargs.get("uuid"): kwargs["uuid"] = str(uuid4()) @@ -21,11 +18,6 @@ class SimComponent(BaseModel): uuid: str "The component UUID." - def __init__(self, **kwargs): - if not kwargs.get("uuid"): - kwargs["uuid"] = str(uuid4()) - super().__init__(**kwargs) - @abstractmethod def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index eb406521..11782abd 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -4,13 +4,14 @@ import re import secrets from enum import Enum from ipaddress import IPv4Address, IPv4Network -from typing import Any, Dict, List, Optional, Tuple, Union +from typing import Dict, List, Optional, Tuple, Union from prettytable import PrettyTable from primaite import getLogger from primaite.exceptions import NetworkError from primaite.simulator.core import SimComponent +from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol @@ -784,7 +785,7 @@ class Node(SimComponent): "All services on the node." processes: Dict = {} "All processes on the node." - file_system: Any = None + file_system: FileSystem "The nodes file system." sys_log: SysLog arp: ARPCache @@ -814,6 +815,8 @@ class Node(SimComponent): kwargs["software_manager"] = SoftwareManager( sys_log=kwargs.get("sys_log"), session_manager=kwargs.get("session_manager") ) + if not kwargs.get("file_system"): + kwargs["file_system"] = FileSystem() super().__init__(**kwargs) self.arp.nics = self.nics From 1de8e0a058d6ee1d633171b154745fc2e9024787 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 9 Aug 2023 09:19:11 +0100 Subject: [PATCH 077/980] Update tests --- .../_simulator/_domain/test_account.py | 2 +- .../_primaite/_simulator/test_core.py | 33 ------------------- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py index d4a57179..aadf1c69 100644 --- a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py +++ b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py @@ -4,7 +4,7 @@ from primaite.simulator.domain.account import Account, AccountType def test_account_serialise(): """Test that an account can be serialised.""" - acct = Account(username="Jake", password="JakePass1!", account_type=AccountType.user) + acct = Account(username="Jake", password="JakePass1!", account_type=AccountType.USER) serialised = acct.model_dump_json() print(serialised) diff --git a/tests/unit_tests/_primaite/_simulator/test_core.py b/tests/unit_tests/_primaite/_simulator/test_core.py index 4e2df757..0d227633 100644 --- a/tests/unit_tests/_primaite/_simulator/test_core.py +++ b/tests/unit_tests/_primaite/_simulator/test_core.py @@ -44,36 +44,3 @@ class TestIsolatedSimComponent: comp = TestComponent(name="computer", size=(5, 10)) dump = comp.model_dump_json() assert comp == TestComponent.model_validate_json(dump) - - def test_apply_action(self): - """Validate that we can override apply_action behaviour and it updates the state of the component.""" - - class TestComponent(SimComponent): - name: str - status: Literal["on", "off"] = "off" - - def describe_state(self) -> Dict: - return {} - - def _possible_actions(self) -> Dict[str, Callable[[List[str]], None]]: - return { - "turn_off": self._turn_off, - "turn_on": self._turn_on, - } - - def _turn_off(self, options: List[str]) -> None: - assert len(options) == 0, "This action does not support options." - self.status = "off" - - def _turn_on(self, options: List[str]) -> None: - assert len(options) == 0, "This action does not support options." - self.status = "on" - - comp = TestComponent(name="computer", status="off") - - assert comp.status == "off" - comp.apply_action(["turn_on"]) - assert comp.status == "on" - - with pytest.raises(ValueError): - comp.apply_action(["do_nothing"]) From be8c2955ced0c41379f5cd98ac4bc3f93006cf47 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 9 Aug 2023 10:26:52 +0100 Subject: [PATCH 078/980] Change Accountstatus to a bool --- src/primaite/simulator/domain/account.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py index 2d726624..79d0de23 100644 --- a/src/primaite/simulator/domain/account.py +++ b/src/primaite/simulator/domain/account.py @@ -17,13 +17,6 @@ class AccountType(Enum): "User accounts are used to allow agents to log in and perform actions" -class AccountStatus(Enum): - """Whether the account is active.""" - - ENABLED = 1 - DISABLED = 2 - - class PasswordPolicyLevel(Enum): """Complexity requirements for account passwords.""" @@ -47,7 +40,7 @@ class Account(SimComponent): "Account password." account_type: AccountType "Account Type, currently this can be service account (used by apps) or user account." - status: AccountStatus = AccountStatus.DISABLED + enabled: bool = True def describe_state(self) -> Dict: """Describe state for agent observations.""" @@ -55,11 +48,11 @@ class Account(SimComponent): def enable(self): """Set the status to enabled.""" - self.status = AccountStatus.ENABLED + self.enabled = True def disable(self): """Set the status to disabled.""" - self.status = AccountStatus.DISABLED + self.enabled = False def log_on(self) -> None: """TODO.""" From 572f457231aa99f81e227d6b9513e58df2f014d9 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 9 Aug 2023 11:19:58 +0100 Subject: [PATCH 079/980] #1714: fixing minor error in test + adding a check for existing uuid when adding file --- .../simulator/file_system/file_system_folder.py | 10 +++++++--- .../_simulator/_file_system/test_file_system.py | 13 +++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py index 79e19189..23f4ca79 100644 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -25,9 +25,13 @@ class FileSystemFolder(FileSystemItem): if file is None or not isinstance(file, FileSystemFile): raise Exception(f"Invalid file: {file}") - # add to list - self.files[file.uuid] = file - self.size += file.size + # check if file with id already exists in folder + if self.get_file_by_id(file.uuid) is not None: + _LOGGER.debug(f"File with id {file.uuid} already exists in folder") + else: + # add to list + self.files[file.uuid] = file + self.size += file.size def remove_file(self, file: Optional[FileSystemFile]): """ diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 5bebf487..348eb440 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -1,4 +1,5 @@ from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.file_system.file_system_file import FileSystemFile from primaite.simulator.file_system.file_system_folder import FileSystemFolder @@ -37,7 +38,7 @@ def test_delete_file(): file_system.delete_file(file=file) assert len(file_system.folders) is 1 - assert len(file_system.get_folder_by_id(folder.uuid).files) is 0 + assert len(folder.files) is 0 def test_delete_non_existent_file(): @@ -45,16 +46,20 @@ def test_delete_non_existent_file(): file_system = FileSystem() file = file_system.create_file(file_name="test_file", size=10) - not_added_file = file_system.create_file(file_name="test_file", size=10) + not_added_file = FileSystemFile(name="not_added") + # folder should be created assert len(file_system.folders) is 1 - + # should only have 1 file in the file system folder_id = list(file_system.folders.keys())[0] folder = file_system.get_folder_by_id(folder_id) + assert len(list(folder.files)) is 1 + assert folder.get_file_by_id(file.uuid) is file + # deleting should not change how many files are in folder file_system.delete_file(file=not_added_file) assert len(file_system.folders) is 1 - assert len(file_system.get_folder_by_id(folder.uuid).files) is 1 + assert len(list(folder.files)) is 1 def test_delete_folder(): From 596bbaacdeb07b942a14118a09aedf452744ad32 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 9 Aug 2023 12:06:06 +0100 Subject: [PATCH 080/980] Change enum strings to uppercase --- src/primaite/simulator/domain/controller.py | 12 ++++++------ .../component_creation/test_permission_system.py | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index 4f09a846..887a065d 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -33,13 +33,13 @@ class temp_file: class AccountGroup(Enum): """Permissions are set at group-level and accounts can belong to these groups.""" - local_user = 1 + LOCAL_USER = 1 "For performing basic actions on a node" - domain_user = 2 + DOMAIN_USER = 2 "For performing basic actions to the domain" - local_admin = 3 + LOCAL_ADMIN = 3 "For full access to actions on a node" - domain_admin = 4 + DOMAIN_ADMIN = 4 "For full access" @@ -71,9 +71,9 @@ class DomainController(SimComponent): accounts: Dict[str, Account] = {} groups: Final[List[AccountGroup]] = list(AccountGroup) - domain_group_membership: Dict[Literal[AccountGroup.domain_admin, AccountGroup.domain_user], List[Account]] = {} + domain_group_membership: Dict[Literal[AccountGroup.DOMAIN_ADMIN, AccountGroup.DOMAIN_USER], List[Account]] = {} local_group_membership: Dict[ - Tuple[temp_node, Literal[AccountGroup.local_admin, AccountGroup.local_user]], List[Account] + Tuple[temp_node, Literal[AccountGroup.LOCAL_ADMIN, AccountGroup.LOCAL_USER]], List[Account] ] = {} # references to non-owned objects. Not sure if all are needed here. diff --git a/tests/integration_tests/component_creation/test_permission_system.py b/tests/integration_tests/component_creation/test_permission_system.py index 93d0267c..6816ba84 100644 --- a/tests/integration_tests/component_creation/test_permission_system.py +++ b/tests/integration_tests/component_creation/test_permission_system.py @@ -34,7 +34,7 @@ def test_group_action_validation() -> None: "create_folder", Action( func=lambda request, context: self.create_folder(request[0]), - validator=GroupMembershipValidator([AccountGroup.local_admin, AccountGroup.domain_admin]), + validator=GroupMembershipValidator([AccountGroup.LOCAL_ADMIN, AccountGroup.DOMAIN_ADMIN]), ), ) @@ -49,14 +49,14 @@ def test_group_action_validation() -> None: self.folders = [x for x in self.folders if x is not folder] # check that the folder is created when a local admin tried to do it - permitted_context = {"request_source": {"agent": "BLUE", "account": "User1", "groups": ["local_admin"]}} + permitted_context = {"request_source": {"agent": "BLUE", "account": "User1", "groups": ["LOCAL_ADMIN"]}} my_node = Node(uuid="0000-0000-1234", name="pc") my_node.apply_action(["create_folder", "memes"], context=permitted_context) assert len(my_node.folders) == 1 assert my_node.folders[0].name == "memes" # check that the number of folders is still 1 even after attempting to create a second one without permissions - invalid_context = {"request_source": {"agent": "BLUE", "account": "User1", "groups": ["local_user", "domain_user"]}} + invalid_context = {"request_source": {"agent": "BLUE", "account": "User1", "groups": ["LOCAL_USER", "DOMAIN_USER"]}} my_node.apply_action(["create_folder", "memes2"], context=invalid_context) assert len(my_node.folders) == 1 assert my_node.folders[0].name == "memes" @@ -97,14 +97,14 @@ def test_hierarchical_action_with_validation() -> None: "disable", Action( func=lambda request, context: self.disable(), - validator=GroupMembershipValidator([AccountGroup.local_admin, AccountGroup.domain_admin]), + validator=GroupMembershipValidator([AccountGroup.LOCAL_ADMIN, AccountGroup.DOMAIN_ADMIN]), ), ) self.action_manager.add_action( "enable", Action( func=lambda request, context: self.enable(), - validator=GroupMembershipValidator([AccountGroup.local_admin, AccountGroup.domain_admin]), + validator=GroupMembershipValidator([AccountGroup.LOCAL_ADMIN, AccountGroup.DOMAIN_ADMIN]), ), ) @@ -164,14 +164,14 @@ def test_hierarchical_action_with_validation() -> None: my_node.install_app("Firefox") non_admin_context = { - "request_source": {"agent": "BLUE", "account": "User1", "groups": ["local_user", "domain_user"]} + "request_source": {"agent": "BLUE", "account": "User1", "groups": ["LOCAL_USER", "DOMAIN_USER"]} } admin_context = { "request_source": { "agent": "BLUE", "account": "User1", - "groups": ["local_admin", "domain_admin", "local_user", "domain_user"], + "groups": ["LOCAL_ADMIN", "DOMAIN_ADMIN", "LOCAL_USER", "DOMAIN_USER"], } } From 51baabb35ba27d318db16478d140e92e6d5cb2cb Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 9 Aug 2023 12:34:56 +0100 Subject: [PATCH 081/980] Update enums to uppercase in docs --- docs/source/simulation_structure.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/simulation_structure.rst b/docs/source/simulation_structure.rst index 479b3e7b..2b213f16 100644 --- a/docs/source/simulation_structure.rst +++ b/docs/source/simulation_structure.rst @@ -49,7 +49,7 @@ snippet demonstrates usage of the ``ActionPermissionValidator``. "reset_factory_settings", Action( func = lambda request, context: self.reset_factory_settings(), - validator = GroupMembershipValidator([AccountGroup.domain_admin]), + validator = GroupMembershipValidator([AccountGroup.DOMAIN_ADMIN]), ), ) @@ -59,7 +59,7 @@ snippet demonstrates usage of the ``ActionPermissionValidator``. phone = Smartphone(name="phone1") # try to wipe the phone as a domain user, this will have no effect - phone.apply_action(["reset_factory_settings"], context={"request_source":{"groups":["domain_user"]}) + phone.apply_action(["reset_factory_settings"], context={"request_source":{"groups":["DOMAIN_USER"]}) # try to wipe the phone as an admin user, this will wipe the phone - phone.apply_action(["reset_factory_settings"], context={"request_source":{"groups":["domain_admin"]}) + phone.apply_action(["reset_factory_settings"], context={"request_source":{"groups":["DOMAIN_ADMIN"]}) From f198a8b94d22ffa5ffd3b74bed6244105c5a8bbb Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 9 Aug 2023 12:36:09 +0100 Subject: [PATCH 082/980] Fix bad merge --- src/primaite/simulator/core.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 779358ec..caba5210 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -126,6 +126,8 @@ class ActionManager: class SimComponent(BaseModel): """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" + model_config = ConfigDict(arbitrary_types_allowed=True, extra=Extra.allow) + uuid: str """The component UUID.""" @@ -133,13 +135,6 @@ class SimComponent(BaseModel): if not kwargs.get("uuid"): kwargs["uuid"] = str(uuid4()) super().__init__(**kwargs) - - model_config = ConfigDict(arbitrary_types_allowed=True, extra=Extra.allow) - uuid: str = str(uuid4()) - "The component UUID." - - def __init__(self, **kwargs) -> None: - super().__init__(**kwargs) self.action_manager: Optional[ActionManager] = None @abstractmethod From cf241366dc413318739b5e12198ea750765c0e3b Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 9 Aug 2023 15:15:45 +0100 Subject: [PATCH 083/980] #1714: apply suggestions for preventing addition of objects with similar uuid --- src/primaite/simulator/file_system/file_system.py | 8 +++++++- src/primaite/simulator/file_system/file_system_folder.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 3290570e..6cdcaca2 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -95,7 +95,13 @@ class FileSystem(SimComponent): :type: folder_name: str """ folder = FileSystemFolder(name=folder_name) - self.folders[folder.uuid] = folder + + if folder.uuid in self.folders: + # iterate until a folder with a non-matching uuid is added + # which is VERY unlikely but it'll be weird if it happens twice + return self.create_folder(folder_name=folder_name) + else: + self.folders[folder.uuid] = folder return folder def delete_file(self, file: Optional[FileSystemFile] = None): diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py index 23f4ca79..62f98029 100644 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -26,7 +26,7 @@ class FileSystemFolder(FileSystemItem): raise Exception(f"Invalid file: {file}") # check if file with id already exists in folder - if self.get_file_by_id(file.uuid) is not None: + if file.uuid in self.files: _LOGGER.debug(f"File with id {file.uuid} already exists in folder") else: # add to list From 34ff9abd7ab8e832e1b3a2cc5e66d193f0846687 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 9 Aug 2023 15:55:28 +0100 Subject: [PATCH 084/980] Apply changes from code review. --- src/primaite/simulator/core.py | 1 + src/primaite/simulator/domain/account.py | 4 ++-- .../unit_tests/_primaite/_simulator/_domain/test_account.py | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index caba5210..8b771cd7 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -127,6 +127,7 @@ class SimComponent(BaseModel): """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" model_config = ConfigDict(arbitrary_types_allowed=True, extra=Extra.allow) + """Configure pydantic to allow arbitrary types and to let the instance have attributes not present in model.""" uuid: str """The component UUID.""" diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py index 79d0de23..e8595afa 100644 --- a/src/primaite/simulator/domain/account.py +++ b/src/primaite/simulator/domain/account.py @@ -55,9 +55,9 @@ class Account(SimComponent): self.enabled = False def log_on(self) -> None: - """TODO.""" + """TODO. Once the accounts are integrated with nodes, populate this accordingly.""" self.num_logons += 1 def log_off(self) -> None: - """TODO.""" + """TODO. Once the accounts are integrated with nodes, populate this accordingly.""" self.num_logoffs += 1 diff --git a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py index aadf1c69..3a2a5903 100644 --- a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py +++ b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py @@ -3,14 +3,14 @@ from primaite.simulator.domain.account import Account, AccountType def test_account_serialise(): - """Test that an account can be serialised.""" - acct = Account(username="Jake", password="JakePass1!", account_type=AccountType.USER) + """Test that an account can be serialised. If pydantic throws error then this test fails.""" + acct = Account(username="Jake", password="JakePass1!", account_type=AccountType.user) serialised = acct.model_dump_json() print(serialised) def test_account_deserialise(): - """Test that an account can be deserialised.""" + """Test that an account can be deserialised. The test fails if pydantic throws an error.""" acct_json = ( '{"uuid":"dfb2bcaa-d3a1-48fd-af3f-c943354622b4","num_logons":0,"num_logoffs":0,"num_group_changes":0,' '"username":"Jake","password":"JakePass1!","account_type":2,"status":2,"action_manager":null}' From b46057841d49db2fc68fbf5d55efff775d8fdd70 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 9 Aug 2023 20:31:42 +0100 Subject: [PATCH 085/980] #1706 - Refactored a bunch of if statements in base.py to improve readability --- .../simulator/network/hardware/base.py | 297 +++++++++--------- 1 file changed, 154 insertions(+), 143 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 11782abd..3b75fedc 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -135,29 +135,33 @@ class NIC(SimComponent): def enable(self): """Attempt to enable the NIC.""" - if not self.enabled: - if self.connected_node: - if self.connected_node.operating_state == NodeOperatingState.ON: - self.enabled = True - self.connected_node.sys_log.info(f"NIC {self} enabled") - self.pcap = PacketCapture(hostname=self.connected_node.hostname, ip_address=self.ip_address) - if self.connected_link: - self.connected_link.endpoint_up() - else: - self.connected_node.sys_log.error(f"NIC {self} cannot be enabled as the endpoint is not turned on") - else: - _LOGGER.error(f"NIC {self} cannot be enabled as it is not connected to a Node") + if self.enabled: + return + if not self.connected_node: + _LOGGER.error(f"NIC {self} cannot be enabled as it is not connected to a Node") + return + if self.connected_node.operating_state != NodeOperatingState.ON: + self.connected_node.sys_log.error(f"NIC {self} cannot be enabled as the endpoint is not turned on") + return + + self.enabled = True + self.connected_node.sys_log.info(f"NIC {self} enabled") + self.pcap = PacketCapture(hostname=self.connected_node.hostname, ip_address=self.ip_address) + if self.connected_link: + self.connected_link.endpoint_up() def disable(self): """Disable the NIC.""" - if self.enabled: - self.enabled = False - if self.connected_node: - self.connected_node.sys_log.info(f"NIC {self} disabled") - else: - _LOGGER.info(f"NIC {self} disabled") - if self.connected_link: - self.connected_link.endpoint_down() + if not self.enabled: + return + + self.enabled = False + if self.connected_node: + self.connected_node.sys_log.info(f"NIC {self} disabled") + else: + _LOGGER.info(f"NIC {self} disabled") + if self.connected_link: + self.connected_link.endpoint_down() def connect_link(self, link: Link): """ @@ -166,15 +170,17 @@ class NIC(SimComponent): :param link: The link to which the NIC is connected. :type link: :class:`~primaite.simulator.network.transmission.physical_layer.Link` """ - if not self.connected_link: - if self.connected_link != link: - # TODO: Inform the Node that a link has been connected - self.connected_link = link - _LOGGER.info(f"NIC {self} connected to Link {link}") - else: - _LOGGER.error(f"Cannot connect Link to NIC ({self.mac_address}) as it is already connected") - else: + if self.connected_link: _LOGGER.error(f"Cannot connect Link to NIC ({self.mac_address}) as it already has a connection") + return + + if self.connected_link == link: + _LOGGER.error(f"Cannot connect Link to NIC ({self.mac_address}) as it is already connected") + return + + # TODO: Inform the Node that a link has been connected + self.connected_link = link + _LOGGER.info(f"NIC {self} connected to Link {link}") def disconnect_link(self): """Disconnect the NIC from the connected Link.""" @@ -214,9 +220,8 @@ class NIC(SimComponent): self.pcap.capture(frame) self.connected_link.transmit_frame(sender_nic=self, frame=frame) return True - else: - # Cannot send Frame as the NIC is not enabled - return False + # Cannot send Frame as the NIC is not enabled + return False def receive_frame(self, frame: Frame) -> bool: """ @@ -233,8 +238,7 @@ class NIC(SimComponent): self.pcap.capture(frame) self.connected_node.receive_frame(frame=frame, from_nic=self) return True - else: - return False + return False def describe_state(self) -> Dict: """ @@ -290,33 +294,34 @@ class SwitchPort(SimComponent): def enable(self): """Attempt to enable the SwitchPort.""" - if not self.enabled: - if self.connected_node: - if self.connected_node.operating_state == NodeOperatingState.ON: - self.enabled = True - self.connected_node.sys_log.info(f"SwitchPort {self} enabled") - self.pcap = PacketCapture(hostname=self.connected_node.hostname) - if self.connected_link: - self.connected_link.endpoint_up() - else: - self.connected_node.sys_log.info( - f"SwitchPort {self} cannot be enabled as the endpoint is not turned on" - ) - else: - msg = f"SwitchPort {self} cannot be enabled as it is not connected to a Node" - _LOGGER.error(msg) - raise NetworkError(msg) + if self.enabled: + return + + if not self.connected_node: + _LOGGER.error(f"SwitchPort {self} cannot be enabled as it is not connected to a Node") + return + + if self.connected_node.operating_state != NodeOperatingState.ON: + self.connected_node.sys_log.info(f"SwitchPort {self} cannot be enabled as the endpoint is not turned on") + return + + self.enabled = True + self.connected_node.sys_log.info(f"SwitchPort {self} enabled") + self.pcap = PacketCapture(hostname=self.connected_node.hostname) + if self.connected_link: + self.connected_link.endpoint_up() def disable(self): """Disable the SwitchPort.""" - if self.enabled: - self.enabled = False - if self.connected_node: - self.connected_node.sys_log.info(f"SwitchPort {self} disabled") - else: - _LOGGER.info(f"SwitchPort {self} disabled") - if self.connected_link: - self.connected_link.endpoint_down() + if not self.enabled: + return + self.enabled = False + if self.connected_node: + self.connected_node.sys_log.info(f"SwitchPort {self} disabled") + else: + _LOGGER.info(f"SwitchPort {self} disabled") + if self.connected_link: + self.connected_link.endpoint_down() def connect_link(self, link: Link): """ @@ -324,16 +329,18 @@ class SwitchPort(SimComponent): :param link: The link to which the SwitchPort is connected. """ - if not self.connected_link: - if self.connected_link != link: - # TODO: Inform the Switch that a link has been connected - self.connected_link = link - _LOGGER.info(f"SwitchPort {self} connected to Link {link}") - self.enable() - else: - _LOGGER.error(f"Cannot connect Link to SwitchPort {self.mac_address} as it is already connected") - else: + if self.connected_link: _LOGGER.error(f"Cannot connect link to SwitchPort {self.mac_address} as it already has a connection") + return + + if self.connected_link == link: + _LOGGER.error(f"Cannot connect Link to SwitchPort {self.mac_address} as it is already connected") + return + + # TODO: Inform the Switch that a link has been connected + self.connected_link = link + _LOGGER.info(f"SwitchPort {self} connected to Link {link}") + self.enable() def disconnect_link(self): """Disconnect the SwitchPort from the connected Link.""" @@ -353,9 +360,8 @@ class SwitchPort(SimComponent): self.pcap.capture(frame) self.connected_link.transmit_frame(sender_nic=self, frame=frame) return True - else: - # Cannot send Frame as the SwitchPort is not enabled - return False + # Cannot send Frame as the SwitchPort is not enabled + return False def receive_frame(self, frame: Frame) -> bool: """ @@ -370,8 +376,7 @@ class SwitchPort(SimComponent): self.pcap.capture(frame) self.connected_node.forward_frame(frame=frame, incoming_port=self) return True - else: - return False + return False def describe_state(self) -> Dict: """ @@ -468,30 +473,27 @@ class Link(SimComponent): :param frame: The network frame to be sent. :return: True if the Frame can be sent, otherwise False. """ - if self._can_transmit(frame): - receiver = self.endpoint_a - if receiver == sender_nic: - receiver = self.endpoint_b - frame_size = frame.size_Mbits - sent = receiver.receive_frame(frame) - if sent: - # Frame transmitted successfully - # Load the frame size on the link - self.current_load += frame_size - ( - _LOGGER.info( - f"Added {frame_size:.3f} Mbits to {self}, current load {self.current_load:.3f} Mbits " - f"({self.current_load_percent})" - ) - ) - return True - # Received NIC disabled, reply - - return False - else: + can_transmit = self._can_transmit(frame) + if not can_transmit: _LOGGER.info(f"Cannot transmit frame as {self} is at capacity") return False + receiver = self.endpoint_a + if receiver == sender_nic: + receiver = self.endpoint_b + frame_size = frame.size_Mbits + + if receiver.receive_frame(frame): + # Frame transmitted successfully + # Load the frame size on the link + self.current_load += frame_size + _LOGGER.info( + f"Added {frame_size:.3f} Mbits to {self}, current load {self.current_load:.3f} Mbits " + f"({self.current_load_percent})" + ) + return True + return False + def reset_component_for_episode(self, episode: int): """ Link reset function. @@ -624,43 +626,48 @@ class ARPCache: :param from_nic: The NIC that received the ARP packet. :param arp_packet: The ARP packet to be processed. """ - if arp_packet.request: - self.sys_log.info( - f"Received ARP request for {arp_packet.target_ip} from " - f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip} " - ) - if arp_packet.target_ip == from_nic.ip_address: - self._add_arp_cache_entry( - ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic - ) - arp_packet = arp_packet.generate_reply(from_nic.mac_address) - self.sys_log.info( - f"Sending ARP reply from {arp_packet.sender_mac_addr}/{arp_packet.sender_ip} " - f"to {arp_packet.target_ip}/{arp_packet.target_mac_addr} " - ) - - tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) - - # Network Layer - ip_packet = IPPacket( - src_ip=arp_packet.sender_ip, - dst_ip=arp_packet.target_ip, - ) - # Data Link Layer - ethernet_header = EthernetHeader( - src_mac_addr=arp_packet.sender_mac_addr, dst_mac_addr=arp_packet.target_mac_addr - ) - frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) - from_nic.send_frame(frame) - else: - self.sys_log.info(f"Ignoring ARP request for {arp_packet.target_ip}") - else: + # ARP Reply + if not arp_packet.request: self.sys_log.info( f"Received ARP response for {arp_packet.sender_ip} from {arp_packet.sender_mac_addr} via NIC {from_nic}" ) self._add_arp_cache_entry( ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic ) + return + + # ARP Request + self.sys_log.info( + f"Received ARP request for {arp_packet.target_ip} from " + f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip} " + ) + + # Unmatched ARP Request + if arp_packet.target_ip != from_nic.ip_address: + self.sys_log.info(f"Ignoring ARP request for {arp_packet.target_ip}") + return + + # Matched ARP request + self._add_arp_cache_entry(ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic) + arp_packet = arp_packet.generate_reply(from_nic.mac_address) + self.sys_log.info( + f"Sending ARP reply from {arp_packet.sender_mac_addr}/{arp_packet.sender_ip} " + f"to {arp_packet.target_ip}/{arp_packet.target_mac_addr} " + ) + + tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) + + # Network Layer + ip_packet = IPPacket( + src_ip=arp_packet.sender_ip, + dst_ip=arp_packet.target_ip, + ) + # Data Link Layer + ethernet_header = EthernetHeader( + src_mac_addr=arp_packet.sender_mac_addr, dst_mac_addr=arp_packet.target_mac_addr + ) + frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) + from_nic.send_frame(frame) class ICMP: @@ -721,30 +728,34 @@ class ICMP: was not found in the ARP cache. """ nic = self.arp.get_arp_cache_nic(target_ip_address) - if nic: - sequence += 1 - target_mac_address = self.arp.get_arp_cache_mac_address(target_ip_address) - src_nic = self.arp.get_arp_cache_nic(target_ip_address) - tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) - - # Network Layer - ip_packet = IPPacket( - src_ip=nic.ip_address, - dst_ip=target_ip_address, - protocol=IPProtocol.ICMP, - ) - # Data Link Layer - ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) - icmp_packet = ICMPPacket(identifier=identifier, sequence=sequence) - frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_packet) - self.sys_log.info(f"Sending echo request to {target_ip_address}") - nic.send_frame(frame) - return sequence, icmp_packet.identifier - else: + # TODO: Eventually this ARP request needs to be done elsewhere. It's not the resonsibility of the + # ping function to handle ARP lookups + # No existing ARP entry + if not nic: self.sys_log.info(f"No entry in ARP cache for {target_ip_address}") self.arp.send_arp_request(target_ip_address) return 0, None + # ARP entry exists + sequence += 1 + target_mac_address = self.arp.get_arp_cache_mac_address(target_ip_address) + src_nic = self.arp.get_arp_cache_nic(target_ip_address) + tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) + + # Network Layer + ip_packet = IPPacket( + src_ip=nic.ip_address, + dst_ip=target_ip_address, + protocol=IPProtocol.ICMP, + ) + # Data Link Layer + ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) + icmp_packet = ICMPPacket(identifier=identifier, sequence=sequence) + frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_packet) + self.sys_log.info(f"Sending echo request to {target_ip_address}") + nic.send_frame(frame) + return sequence, icmp_packet.identifier + class NodeOperatingState(Enum): """Enumeration of Node Operating States.""" From ad81a819498e7083578a304b220c235c15454136 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 9 Aug 2023 20:38:45 +0100 Subject: [PATCH 086/980] #1706 - Applied some code suggestions from the PR --- src/primaite/simulator/network/hardware/base.py | 11 ++++++----- .../integration_tests/network/test_link_connection.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 3b75fedc..d3ea9a41 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -46,6 +46,7 @@ def generate_mac_address(oui: Optional[str] = None) -> str: oui_pattern = re.compile(r"^([0-9A-Fa-f]{2}[:-]){2}[0-9A-Fa-f]{2}$") if not oui_pattern.match(oui): msg = f"Invalid oui. The oui should be in the format xx:xx:xx, where x is a hexadecimal digit, got '{oui}'" + _LOGGER.error(msg) raise ValueError(msg) oui_bytes = [int(chunk, 16) for chunk in oui.split(":")] mac = oui_bytes + random_bytes[len(oui_bytes) :] @@ -401,7 +402,7 @@ class SwitchPort(SimComponent): class Link(SimComponent): """ - Represents a network link between NIC<-->, NIC<-->SwitchPort, or SwitchPort<-->SwitchPort. + Represents a network link between NIC<-->NIC, NIC<-->SwitchPort, or SwitchPort<-->SwitchPort. :param endpoint_a: The first NIC or SwitchPort connected to the Link. :param endpoint_b: The second NIC or SwitchPort connected to the Link. @@ -441,17 +442,17 @@ class Link(SimComponent): def endpoint_up(self): """Let the Link know and endpoint has been brought up.""" - if self.up: + if self.is_up: _LOGGER.info(f"Link {self} up") def endpoint_down(self): """Let the Link know and endpoint has been brought down.""" - if not self.up: + if not self.is_up: self.current_load = 0.0 _LOGGER.info(f"Link {self} down") @property - def up(self) -> bool: + def is_up(self) -> bool: """ Informs whether the link is up. @@ -460,7 +461,7 @@ class Link(SimComponent): return self.endpoint_a.enabled and self.endpoint_b.enabled def _can_transmit(self, frame: Frame) -> bool: - if self.up: + if self.is_up: frame_size_Mbits = frame.size_Mbits # noqa - Leaving it as Mbits as this is how they're expressed return self.current_load + frame_size_Mbits <= self.bandwidth return False diff --git a/tests/integration_tests/network/test_link_connection.py b/tests/integration_tests/network/test_link_connection.py index 92909cf6..e08e40b9 100644 --- a/tests/integration_tests/network/test_link_connection.py +++ b/tests/integration_tests/network/test_link_connection.py @@ -18,4 +18,4 @@ def test_link_up(): link = Link(endpoint_a=nic_a, endpoint_b=nic_b) - assert link.up + assert link.is_up From e24d4b88900a6667df725c4da7f95ac71f92e42e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 10 Aug 2023 09:14:45 +0100 Subject: [PATCH 087/980] Fix typo in test --- tests/unit_tests/_primaite/_simulator/_domain/test_account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py index 3a2a5903..b5632ea7 100644 --- a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py +++ b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py @@ -4,7 +4,7 @@ from primaite.simulator.domain.account import Account, AccountType def test_account_serialise(): """Test that an account can be serialised. If pydantic throws error then this test fails.""" - acct = Account(username="Jake", password="JakePass1!", account_type=AccountType.user) + acct = Account(username="Jake", password="JakePass1!", account_type=AccountType.USER) serialised = acct.model_dump_json() print(serialised) From 9ee0ef2fd65a5414b0619c93d898d2ece321bbc0 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 10 Aug 2023 13:26:51 +0100 Subject: [PATCH 088/980] #1706 - Applied some final changes from PR. Fixed the PCAP log name on SwitchPort so that a pcap file is generated for each port. --- .../network/base_hardware.rst | 2 +- src/primaite/__init__.py | 1 + src/primaite/simulator/__init__.py | 1 + src/primaite/simulator/core.py | 8 ++++---- .../simulator/network/hardware/base.py | 2 +- .../system/applications/application.py | 13 ++++++------ .../simulator/system/core/packet_capture.py | 20 +++++++++++++------ .../simulator/system/services/service.py | 12 +++++------ 8 files changed, 35 insertions(+), 24 deletions(-) diff --git a/docs/source/simulation_components/network/base_hardware.rst b/docs/source/simulation_components/network/base_hardware.rst index 5335091f..452667d2 100644 --- a/docs/source/simulation_components/network/base_hardware.rst +++ b/docs/source/simulation_components/network/base_hardware.rst @@ -324,7 +324,7 @@ This produces: Create Switches *************** -Next, we'll create four six-port switches: +Next, we'll create two six-port switches: .. code-block:: python diff --git a/src/primaite/__init__.py b/src/primaite/__init__.py index 9a7ba596..30fc9ab9 100644 --- a/src/primaite/__init__.py +++ b/src/primaite/__init__.py @@ -17,6 +17,7 @@ with open(Path(__file__).parent.resolve() / "VERSION", "r") as file: __version__ = file.readline().strip() _PRIMAITE_ROOT: Path = Path(__file__).parent +# TODO: Remove once we integrate the simulation into PrimAITE and it uses the primaite session path class _PrimaitePaths: diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index 5b65ad40..1cfe7f49 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -2,3 +2,4 @@ from primaite import _PRIMAITE_ROOT TEMP_SIM_OUTPUT = _PRIMAITE_ROOT.parent.parent / "simulation_output" "A path at the repo root dir to use temporarily for sim output testing while in dev." +# TODO: Remove once we integrate the simulation into PrimAITE and it uses the primaite session path diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index a48709e0..03684474 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -9,15 +9,15 @@ from pydantic import BaseModel, ConfigDict class SimComponent(BaseModel): """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" + model_config = ConfigDict(arbitrary_types_allowed=True) + uuid: str + "The component UUID." + def __init__(self, **kwargs): if not kwargs.get("uuid"): kwargs["uuid"] = str(uuid4()) super().__init__(**kwargs) - model_config = ConfigDict(arbitrary_types_allowed=True) - uuid: str - "The component UUID." - @abstractmethod def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index d3ea9a41..ab5d4943 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -308,7 +308,7 @@ class SwitchPort(SimComponent): self.enabled = True self.connected_node.sys_log.info(f"SwitchPort {self} enabled") - self.pcap = PacketCapture(hostname=self.connected_node.hostname) + self.pcap = PacketCapture(hostname=self.connected_node.hostname, switch_port_number=self.port_num) if self.connected_link: self.connected_link.endpoint_up() diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index f9c5827d..36a7bc85 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -8,12 +8,13 @@ from primaite.simulator.system.software import IOSoftware class ApplicationOperatingState(Enum): """Enumeration of Application Operating States.""" - CLOSED = 0 - "The application is closed or not running." - RUNNING = 1 - "The application is running." - INSTALLING = 3 - "The application is being installed or updated." + +RUNNING = 1 +"The application is running." +CLOSED = 2 +"The application is closed or not running." +INSTALLING = 3 +"The application is being installed or updated." class Application(IOSoftware): diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index 7741416d..c985af1f 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -20,7 +20,7 @@ class PacketCapture: The PCAPs are logged to: //__pcap.log """ - def __init__(self, hostname: str, ip_address: Optional[str] = None): + def __init__(self, hostname: str, ip_address: Optional[str] = None, switch_port_number: Optional[int] = None): """ Initialize the PacketCapture process. @@ -31,6 +31,8 @@ class PacketCapture: "The hostname for which PCAP logs are being recorded." self.ip_address: str = ip_address "The IP address associated with the PCAP logs." + self.switch_port_number = switch_port_number + "The SwitchPort number." self._setup_logger() def _setup_logger(self): @@ -43,20 +45,26 @@ class PacketCapture: log_format = "%(message)s" file_handler.setFormatter(logging.Formatter(log_format)) - logger_name = f"{self.hostname}_{self.ip_address}_pcap" if self.ip_address else f"{self.hostname}_pcap" - self.logger = logging.getLogger(logger_name) + self.logger = logging.getLogger(self._logger_name) self.logger.setLevel(60) # Custom log level > CRITICAL to prevent any unwanted standard DEBUG-CRITICAL logs self.logger.addHandler(file_handler) self.logger.addFilter(_JSONFilter()) + @property + def _logger_name(self) -> str: + """Get PCAP the logger name.""" + if self.ip_address: + return f"{self.hostname}_{self.ip_address}_pcap" + if self.switch_port_number: + return f"{self.hostname}_port-{self.switch_port_number}_pcap" + return f"{self.hostname}_pcap" + def _get_log_path(self) -> Path: """Get the path for the log file.""" root = TEMP_SIM_OUTPUT / self.hostname root.mkdir(exist_ok=True, parents=True) - if self.ip_address: - return root / f"{self.hostname}_{self.ip_address}_pcap.log" - return root / f"{self.hostname}_pcap.log" + return root / f"{self._logger_name}.log" def capture(self, frame): # noqa - I'll have a circular import and cant use if TYPE_CHECKING ;( """ diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index c820cef3..7be5cb78 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -8,17 +8,17 @@ from primaite.simulator.system.software import IOSoftware class ServiceOperatingState(Enum): """Enumeration of Service Operating States.""" - STOPPED = 0 - "The service is not running." RUNNING = 1 "The service is currently running." - RESTARTING = 2 - "The service is in the process of restarting." + STOPPED = 2 + "The service is not running." INSTALLING = 3 "The service is being installed or updated." - PAUSED = 4 + RESTARTING = 4 + "The service is in the process of restarting." + PAUSED = 5 "The service is temporarily paused." - DISABLED = 5 + DISABLED = 6 "The service is disabled and cannot be started." From 49f855c32072cb2df4a74e1be60a3834776b366a Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 10 Aug 2023 13:33:32 +0100 Subject: [PATCH 089/980] #1706 - Synced with Dev --- src/primaite/simulator/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 8b771cd7..7a183588 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -177,7 +177,7 @@ class SimComponent(BaseModel): """ pass - def reset_component_for_episode(self): + def reset_component_for_episode(self, episode: int): """ Reset this component to its original state for a new episode. From c4aacb8c69281cd462bf6824dd9ec2999aea260f Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 11 Aug 2023 15:33:07 +0100 Subject: [PATCH 090/980] #1714: Change file and folder uuid checking to check for file or folder names already existing --- .../simulator/file_system/file_system.py | 23 ++++++++++++++----- .../file_system/file_system_folder.py | 4 ++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 6cdcaca2..d42db3e0 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -69,6 +69,10 @@ class FileSystem(SimComponent): folder = self.get_folder_by_id(folder_uuid) if folder is not None: + # check if file with name already exists + if folder.get_file_by_name(file_name): + raise Exception(f'File with name "{file_name}" already exists.') + file = FileSystemFile(name=file_name, size=size, file_type=file_type) folder.add_file(file=file) else: @@ -94,14 +98,13 @@ class FileSystem(SimComponent): :param: folder_name: The name of the folder :type: folder_name: str """ + # check if folder with name already exists + if self.get_folder_by_name(folder_name): + raise Exception(f'Folder with name "{folder_name}" already exists.') + folder = FileSystemFolder(name=folder_name) - if folder.uuid in self.folders: - # iterate until a folder with a non-matching uuid is added - # which is VERY unlikely but it'll be weird if it happens twice - return self.create_folder(folder_name=folder_name) - else: - self.folders[folder.uuid] = folder + self.folders[folder.uuid] = folder return folder def delete_file(self, file: Optional[FileSystemFile] = None): @@ -155,6 +158,10 @@ class FileSystem(SimComponent): if file is None: raise Exception("File to be moved is None") + # check if file with name already exists + if target_folder.get_file_by_name(file.name): + raise Exception(f'Folder with name "{file.name}" already exists.') + # remove file from src src_folder.remove_file(file) @@ -185,6 +192,10 @@ class FileSystem(SimComponent): if file is None: raise Exception("File to be moved is None") + # check if file with name already exists + if target_folder.get_file_by_name(file.name): + raise Exception(f'Folder with name "{file.name}" already exists.') + # add file to target target_folder.add_file(file) diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py index 62f98029..b0705804 100644 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -20,6 +20,10 @@ class FileSystemFolder(FileSystemItem): """Return a FileSystemFile with the matching id.""" return self.files.get(file_id) + def get_file_by_name(self, file_name: str) -> FileSystemFile: + """Return a FileSystemFile with the matching id.""" + return next((f for f in list(self.files) if f.name == file_name), None) + def add_file(self, file: FileSystemFile): """Adds a file to the folder list.""" if file is None or not isinstance(file, FileSystemFile): From 01fb9e65fec7d4a9a9b3bbd1bc23620e67b67c32 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 15 Aug 2023 11:14:23 +0100 Subject: [PATCH 091/980] Added the DSTL MIT license and updated the license in pyproject.toml --- LICENSE | 15 ++++----------- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/LICENSE b/LICENSE index 3f5e4bb3..93d6f98b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,28 +1,21 @@ -MIT License License +MIT License -MIT License Conditions +Copyright (c) 2023 - 2025 Defence Science and Technology Laboratory UK (https://dstl.gov.uk) -These MIT License conditions confirm the provision of the following artefacts as MIT License by Defence Science and Technology +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - diff --git a/pyproject.toml b/pyproject.toml index 5a28eefd..229d29d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ license = {file = "LICENSE"} requires-python = ">=3.8, <3.11" dynamic = ["version", "readme"] classifiers = [ - "License :: MIT License", + "License :: OSI Approved :: MIT License", "Development Status :: 5 - Production/Stable", "Operating System :: Microsoft :: Windows", "Operating System :: MacOS", From 1a1c3c9344c8089316bc69f8748b068a1ba73c0a Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 15 Aug 2023 11:26:15 +0100 Subject: [PATCH 092/980] Added sphinx docs build pipeline for GitHub pages on release --- .github/workflows/build-sphinx.yml | 60 ++++++++++++++++++++ docs/build-sphinx-docs-to-github-pages.sh | 67 +++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 .github/workflows/build-sphinx.yml create mode 100644 docs/build-sphinx-docs-to-github-pages.sh diff --git a/.github/workflows/build-sphinx.yml b/.github/workflows/build-sphinx.yml new file mode 100644 index 00000000..82da1c6b --- /dev/null +++ b/.github/workflows/build-sphinx.yml @@ -0,0 +1,60 @@ +name: build-sphinx-to-github-pages + +env: + GITHUB_ACTOR: Autonomous-Resilient-Cyber-Defence + GITHUB_REPOSITORY: Autonomous-Resilient-Cyber-Defence/PrimAITE + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}} + +on: + push: + branches: [main] + + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install python dev + run: | + set -x + sudo apt-get update + sudo add-apt-repository ppa:deadsnakes/ppa -y + sudo apt install python${{ matrix.python-version}}-dev -y + + - name: Install Git + run: | + set -x + sudo apt-get install -y git + shell: bash + + - name: Set pip, wheel, setuptools versions + run: | + python -m pip install --upgrade pip==23.0.1 + pip install wheel==0.38.4 --upgrade + pip install setuptools==66 --upgrade + pip install build + + - name: Install PrimAITE for docs autosummary + run: | + set -x + python -m pip install -e .[dev] + + - name: Run build script for Sphinx pages + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + run: | + set -x + bash $PWD/docs/build-sphinx-docs-to-github-pages.sh diff --git a/docs/build-sphinx-docs-to-github-pages.sh b/docs/build-sphinx-docs-to-github-pages.sh new file mode 100644 index 00000000..f1d40647 --- /dev/null +++ b/docs/build-sphinx-docs-to-github-pages.sh @@ -0,0 +1,67 @@ +#!/bin/bash +set -x + +apt-get update +apt-get -y install git rsync python3-sphinx + +pwd ls -lah +export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) + +############## +# BUILD DOCS # +############## + +cd docs +# Python Sphinx, configured with source/conf.py +# See https://www.sphinx-doc.org/ +make clean +make html + +cd .. +####################### +# Update GitHub Pages # +####################### + +git config --global user.name "${GITHUB_ACTOR}" +git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" + +docroot=`mktemp -d` + +rsync -av $PWD/docs/_build/html/ "${docroot}/" + +pushd "${docroot}" + +git init +git remote add deploy "https://token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" +git checkout -b sphinx-docs-github-pages + +# Adds .nojekyll file to the root to signal to GitHub that +# directories that start with an underscore (_) can remain +touch .nojekyll + +# Add README +cat > README.md < Date: Tue, 15 Aug 2023 13:23:25 +0100 Subject: [PATCH 093/980] Create spinx-pipeline --- .github/workflows/spinx-pipeline | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/spinx-pipeline diff --git a/.github/workflows/spinx-pipeline b/.github/workflows/spinx-pipeline new file mode 100644 index 00000000..22f666b0 --- /dev/null +++ b/.github/workflows/spinx-pipeline @@ -0,0 +1,36 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the "dev" branch + push: + branches: [ "dev" ] + pull_request: + branches: [ "dev" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: echo Hello, world! + + # Runs a set of commands using the runners shell + - name: Run a multi-line script + run: | + echo Add other actions to build, + echo test, and deploy your project. From 58048cd0e1c05ce43464e1d2c2e62855a2c4fa3a Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 15 Aug 2023 13:28:02 +0100 Subject: [PATCH 094/980] Dropped sphinx-pipeline --- .github/workflows/spinx-pipeline | 36 -------------------------------- 1 file changed, 36 deletions(-) delete mode 100644 .github/workflows/spinx-pipeline diff --git a/.github/workflows/spinx-pipeline b/.github/workflows/spinx-pipeline deleted file mode 100644 index 22f666b0..00000000 --- a/.github/workflows/spinx-pipeline +++ /dev/null @@ -1,36 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: CI - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the "dev" branch - push: - branches: [ "dev" ] - pull_request: - branches: [ "dev" ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 - - # Runs a single command using the runners shell - - name: Run a one-line script - run: echo Hello, world! - - # Runs a set of commands using the runners shell - - name: Run a multi-line script - run: | - echo Add other actions to build, - echo test, and deploy your project. From 18f57d64187a94a8b689cbf091c2b1176240703b Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 15 Aug 2023 13:56:06 +0100 Subject: [PATCH 095/980] Added PrimAITE_logo_transparent.png file --- PrimAITE_logo_transparent.png | Bin 0 -> 280955 bytes README.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 PrimAITE_logo_transparent.png diff --git a/PrimAITE_logo_transparent.png b/PrimAITE_logo_transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..3e12f643adfda0b1297b306dd8bf92a8fce610f6 GIT binary patch literal 280955 zcmc$F_di?z`~HcL1VQYWiBYSH7`2J5v^A>LVaKL5TbtOiDJ`wNincGKTBTM{u_@Z3 z)Sj)qw~xLbkMG~`{UJH$ksp$CPVVP@UH5fe<noIy6-5Q~&_b+|boD1^_ZL001q( zAeWy+ucoo4)E^farE2UPdj;qj*qc=F&w(TmJx zX1_|5%AC)WaZG6VIrG(f6V09r-IikJUv|@v&rXf#e(6XR(gy>k_JdHN zE0ZfMF#CS0;Hjg2AC||zzwFtv9q-6Knea`FKUFvj$Zp-e`u6Qx236~?b5p0ZbKHXW zohx@P#72l4e-!J%MZtp6dmPcuU|f)DC@HX08m<2D+0`d!wWPS!j2_x891 z!Is6Gibn@Un@7DHzu7$c%Q@#P`ma}mVw6GT^(WkEy}S!H|#f z=gbFF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Z5`Un~ zIHzZoE;yl1@w^QOizTi9flNpC_{Xk_j>~fFNLGP{U3kbp63HGe{V`2S>*{0zt>ArD zgVSuMlH&=;Y-ny^H4v?6i2yg<=U48^2v3OOSm>)oMv4_7-@La;Noo9>l)(_#7Vovc z#b2TxZyyig49z%M9T$_`9{;BfCOV+7W)zX?6h@5ye$feD5Wq@Y|?Vdcu%!9PoWNK7f$=XW4I3T35DTQwjH!e>B^nYu)M^O?wKKgjWj_SlCSH=spA$@7Cy+oEV#9H2X zI2kg9_2)bKK|A$ckXFF#au`#`yG!ufWU3ptp`m;7&mz@Yrse}kb8%cd&VPG0%ojYi zI_jr>YRL5T%{*T`eWKFDV0XCglqMzFDcjXK4%PLrz(z>_O5RPr1cuvFqEJ-Jfy*@L zLAG&uBTWi@(F#-M9Cf|p%e3ez{&KkDiD_dk`m9FNRxYK!9mRlKtCD|r8OI&z;8^Gc zpZobQBi3)8JtkNLRj)Py?m~D_1X&J9@aY~OWH9mKM&{@~`@X}aOmH*Ql2mS`iwqlb zjfEXFCeEb)n$*drjT<$RR zIXJ%aSeU_49Z&%2#9r7sCn%`=`I*3rGZ_o8^|ug=91m4l+0)OV<9|8!cDgqhThMqc zQw8M9(%Ym80S9SyE8k`@yxLtcX7_mg>tu(KV`Y8OMgN~%Su+Pa0XA^V!cY^dfq#a= z++=bQkAXR(SVKH7-?<`eNS@@D!{_xi^7($Q9H(6ul)&S!=>_K(^ssQLcWlZhyjn2Q zR|>YbrsL6tCR>Tc$k1Uf?vosgdt8F#mqF?I0mUJ18z${>F8?8$zSO-bE{Qcd<%qfG zm8+V3@$osqsdGA&+pMeT>&D^{EX*kf|CLVIylmaZ_^SP0BmW_*jA;RV6^kz@CAqA@ z)CJK88t|5$<0m;F$&$u%@2wRVR3WVLjvr=2Gl)3__@BxD`z8^h|JQE_G4UTgfEw Date: Tue, 15 Aug 2023 13:56:38 +0100 Subject: [PATCH 096/980] #1752 - Added dns_client.py and dns_server.py service files - Added new get_install method to software.py --- .../simulator/system/services/dns_client.py | 68 +++++++++++++++++++ .../simulator/system/services/dns_server.py | 64 +++++++++++++++++ src/primaite/simulator/system/software.py | 9 +++ 3 files changed, 141 insertions(+) create mode 100644 src/primaite/simulator/system/services/dns_client.py create mode 100644 src/primaite/simulator/system/services/dns_server.py diff --git a/src/primaite/simulator/system/services/dns_client.py b/src/primaite/simulator/system/services/dns_client.py new file mode 100644 index 00000000..ebbe4058 --- /dev/null +++ b/src/primaite/simulator/system/services/dns_client.py @@ -0,0 +1,68 @@ +from abc import abstractmethod +from ipaddress import IPv4Address +from typing import Any, Dict, List + +from pydantic import BaseModel + + +class DNSClient(BaseModel): + """Represents a DNS Client as a Service.""" + + target_url: str + "The URL/domain name the client requests the IP for." + dns_cache: Dict[str:IPv4Address] = {} + "A dict of known mappings between domain names and IPv4 addresses." + + @abstractmethod + def describe_state(self) -> Dict: + """ + Describes the current state of the software. + + The specifics of the software's state, including its health, criticality, + and any other pertinent information, should be implemented in subclasses. + + :return: A dictionary containing key-value pairs representing the current state of the software. + :rtype: Dict + """ + return {"Operating State": self.operating_state} + + def apply_action(self, action: List[str]) -> None: + """ + Applies a list of actions to the Service. + + :param action: A list of actions to apply. + """ + pass + + def reset_component_for_episode(self): + """ + Resets the Service component for a new episode. + + This method ensures the Service is ready for a new episode, including resetting any + stateful properties or statistics, and clearing any message queues. + """ + pass + + def send(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Sends a payload to the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to send. + :return: True if successful, False otherwise. + """ + pass + + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Receives a payload from the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to receive. + :return: True if successful, False otherwise. + """ + pass diff --git a/src/primaite/simulator/system/services/dns_server.py b/src/primaite/simulator/system/services/dns_server.py new file mode 100644 index 00000000..e7b51f38 --- /dev/null +++ b/src/primaite/simulator/system/services/dns_server.py @@ -0,0 +1,64 @@ +from abc import abstractmethod +from typing import Any, Dict, List + +from pydantic import BaseModel + + +class DNSServer(BaseModel): + """Represents a DNS Server as a Service.""" + + dns_table: dict[str:str] = {"https://google.co.uk": "8.8.8.8"} + + @abstractmethod + def describe_state(self) -> Dict: + """ + Describes the current state of the software. + + The specifics of the software's state, including its health, criticality, + and any other pertinent information, should be implemented in subclasses. + + :return: A dictionary containing key-value pairs representing the current state of the software. + :rtype: Dict + """ + return {"Operating State": self.operating_state} + + def apply_action(self, action: List[str]) -> None: + """ + Applies a list of actions to the Service. + + :param action: A list of actions to apply. + """ + pass + + def reset_component_for_episode(self): + """ + Resets the Service component for a new episode. + + This method ensures the Service is ready for a new episode, including resetting any + stateful properties or statistics, and clearing any message queues. + """ + pass + + def send(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Sends a payload to the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to send. + :return: True if successful, False otherwise. + """ + pass + + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Receives a payload from the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to receive. + :return: True if successful, False otherwise. + """ + pass diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 854e7e2b..4caf6f03 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -109,6 +109,15 @@ class Software(SimComponent): """ pass + @staticmethod + def get_install(): + """ + This method ensures the software has to have a way to install it. + + This can be used by the software manager to install the software. + """ + pass + class IOSoftware(Software): """ From 72cd9fd8e29ed1d6c917f9bc9fad1d2fda5d0da5 Mon Sep 17 00:00:00 2001 From: SunilSamra Date: Wed, 16 Aug 2023 13:00:16 +0100 Subject: [PATCH 097/980] #1752 - Created dns.py protocol file with DNSPacket and DNSRequest and DNSReply packets - Added reset_component logic for dns_server.py and dns_client.py --- .../simulator/network/protocols/dns.py | 113 ++++++++++++++++++ .../simulator/system/services/dns_client.py | 3 +- .../simulator/system/services/dns_server.py | 4 +- 3 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 src/primaite/simulator/network/protocols/dns.py diff --git a/src/primaite/simulator/network/protocols/dns.py b/src/primaite/simulator/network/protocols/dns.py new file mode 100644 index 00000000..fa88652c --- /dev/null +++ b/src/primaite/simulator/network/protocols/dns.py @@ -0,0 +1,113 @@ +from __future__ import annotations + +from ipaddress import IPv4Address +from typing import Optional + +from pydantic import BaseModel + + +class DNSEntry(BaseModel): + """ + Represents an entry in the DNS cache. + + :param domain_name: The domain name which a node would like to access. + :param ip_address: The IP address through which the domain name is reachable. + """ + + domain_name: str + ip_address: IPv4Address + + +class DNSRequest(BaseModel): + """Represents a DNS Request packet of a network frame. + + :param sender_mac_addr: Sender MAC address. + :param sender_ip: Sender IP address. + :param target_mac_addr: Target MAC address. + :param target_ip: Target IP address. + :param domain_name_request: Domain Name Request for IP address. + """ + + sender_mac_addr: str + "Sender MAC address." + sender_ip: IPv4Address + "Sender IP address." + target_mac_addr: Optional[str] = None + "Target MAC address of the DNS Server." + target_ip: IPv4Address + "Target IP address of the DNS Server." + domain_name_request: str + "Domain Name Request for IP address." + + +class DNSReply(BaseModel): + """Represents a DNS Reply packet of a network frame. + + :param sender_mac_addr: Sender MAC address. + :param sender_ip: Sender IP address. + :param target_mac_addr: Target MAC address of DNS Client. + :param target_ip: Target IP address of DNS Client. + :param domain_name_ip_address: IP Address of the Domain Name requested. + """ + + sender_mac_addr: str + "Sender MAC address." + sender_ip: IPv4Address + "Sender IP address." + target_mac_addr: Optional[str] = None + "Target MAC address of the DNS Server." + target_ip: IPv4Address + "Target IP address of the DNS Server." + domain_name_ip_address: IPv4Address + "IP Address of the Domain Name requested." + + +class DNSPacket(BaseModel): + """ + Represents the DNS layer of a network frame. + + :param dns_request: DNS Request packet sent by DNS Client. + :param dns_reply: DNS Reply packet generated by DNS Server. + + :Example: + + >>> dns_request = DNSPacket( + ... dns_request=DNSRequest(sender_mac_addr="aa:bb:cc:dd:ee:ff", sender_ip = IPv4Address("192.168.0.1"), + ... target_ip = IPv4Address("192.168.0.2"), domain_name_request="www.google.co.uk"), + ... dns_reply=None + ... ) + >>> dns_response = DNSPacket( + ... dns_request=DNSRequest(sender_mac_addr="aa:bb:cc:dd:ee:ff", sender_ip = IPv4Address("192.168.0.1"), + ... target_ip = IPv4Address("192.168.0.2"), domain_name_request="www.google.co.uk"), + ... dns_reply=DNSReply(sender_mac_addr="gg:hh:ii:jj:kk:ll", sender_ip = IPv4Address("192.168.0.2"), + ... target_ip = IPv4Address("192.168.0.1"), domain_name_ip_address=IPv4Address("142.250.179.227")) + ... ) + """ + + dns_request: DNSRequest + "DNS Request packet sent by DNS Client." + dns_reply: Optional[DNSReply] = None + "DNS Reply packet generated by DNS Server." + + def generate_reply(self, domain_ip_address: IPv4Address) -> DNSPacket: + """Generate a new DNSPacket to be sent as a response with a DNS Reply packet which contains the IP address. + + :param domain_ip_address: The IP address that was being sought after from the original target domain name. + :return: A new instance of DNSPacket. + """ + return DNSPacket( + dns_request=DNSRequest( + sender_mac_addr=self.dns_request.sender_mac_addr, + sender_ip=self.dns_request.sender_ip, + target_mac_addr=self.dns_request.target_mac_addr, + target_ip=self.dns_request.target_ip, + domain_name_request=self.dns_request.domain_name_request, + ), + dns_reply=DNSReply( + sender_mac_addr=self.dns_request.target_mac_addr, + sender_ip=self.dns_request.target_ip, + target_mac_addr=self.dns_request.sender_mac_addr, + target_ip=self.dns_request.sender_ip, + domain_name_ip_address=domain_ip_address, + ), + ) diff --git a/src/primaite/simulator/system/services/dns_client.py b/src/primaite/simulator/system/services/dns_client.py index ebbe4058..7b080244 100644 --- a/src/primaite/simulator/system/services/dns_client.py +++ b/src/primaite/simulator/system/services/dns_client.py @@ -41,7 +41,8 @@ class DNSClient(BaseModel): This method ensures the Service is ready for a new episode, including resetting any stateful properties or statistics, and clearing any message queues. """ - pass + self.target_url = "" + self.dns_cache = {} def send(self, payload: Any, session_id: str, **kwargs) -> bool: """ diff --git a/src/primaite/simulator/system/services/dns_server.py b/src/primaite/simulator/system/services/dns_server.py index e7b51f38..7eed51b5 100644 --- a/src/primaite/simulator/system/services/dns_server.py +++ b/src/primaite/simulator/system/services/dns_server.py @@ -7,7 +7,7 @@ from pydantic import BaseModel class DNSServer(BaseModel): """Represents a DNS Server as a Service.""" - dns_table: dict[str:str] = {"https://google.co.uk": "8.8.8.8"} + dns_table: dict[str:str] = {} @abstractmethod def describe_state(self) -> Dict: @@ -37,7 +37,7 @@ class DNSServer(BaseModel): This method ensures the Service is ready for a new episode, including resetting any stateful properties or statistics, and clearing any message queues. """ - pass + self.dns_table = {} def send(self, payload: Any, session_id: str, **kwargs) -> bool: """ From ced45d427571cf8a8e78a5af44163c67fdabe8e4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 16 Aug 2023 16:45:52 +0100 Subject: [PATCH 098/980] Connect actions of top-level sim components --- src/primaite/simulator/domain/controller.py | 16 +++++++++- src/primaite/simulator/network/container.py | 23 ++++++++++++++ src/primaite/simulator/sim_container.py | 34 +++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/primaite/simulator/network/container.py create mode 100644 src/primaite/simulator/sim_container.py diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index 887a065d..4e872531 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -1,7 +1,7 @@ from enum import Enum from typing import Dict, Final, List, Literal, Tuple -from primaite.simulator.core import ActionPermissionValidator, SimComponent +from primaite.simulator.core import Action, ActionManager, ActionPermissionValidator, SimComponent from primaite.simulator.domain.account import Account, AccountType @@ -82,6 +82,20 @@ class DomainController(SimComponent): folders: List[temp_folder] = {} files: List[temp_file] = {} + def __init__(self, **kwargs): + super().__init__(**kwargs) + + self.action_manager = ActionManager() + # Action 'account' matches requests like: + # ['account', '', *account_action] + self.action_manager.add_action( + "account", + Action( + func=lambda request, context: self.accounts[request.pop(0)].apply_action(request, context), + validator=GroupMembershipValidator([AccountGroup.DOMAIN_ADMIN]), + ), + ) + def _register_account(self, account: Account) -> None: """TODO.""" ... diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py new file mode 100644 index 00000000..346a089e --- /dev/null +++ b/src/primaite/simulator/network/container.py @@ -0,0 +1,23 @@ +from typing import Dict + +from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent +from primaite.simulator.network.hardware.base import Link, Node + + +class NetworkContainer(SimComponent): + """TODO.""" + + nodes: Dict[str, Node] = {} + links: Dict[str, Link] = {} + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + self.action_manager = ActionManager() + self.action_manager.add_action( + "node", + Action( + func=lambda request, context: self.nodes[request.pop(0)].apply_action(request, context), + validator=AllowAllValidator(), + ), + ) diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py new file mode 100644 index 00000000..6989d2b9 --- /dev/null +++ b/src/primaite/simulator/sim_container.py @@ -0,0 +1,34 @@ +from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent +from primaite.simulator.domain.controller import DomainController + + +class __TempNetwork: + """TODO.""" + + pass + + +class SimulationContainer(SimComponent): + """TODO.""" + + network: __TempNetwork + domain: DomainController + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + self.action_manager = ActionManager() + # pass through network actions to the network objects + self.action_manager.add_action( + "network", + Action( + func=lambda request, context: self.network.apply_action(request, context), validator=AllowAllValidator() + ), + ) + # pass through domain actions to the domain object + self.action_manager.add_action( + "domain", + Action( + func=lambda request, context: self.domain.apply_action(request, context), validator=AllowAllValidator() + ), + ) From 2919be3796e41e1694c1e0e5cdd67b237f529ad7 Mon Sep 17 00:00:00 2001 From: SunilSamra Date: Thu, 17 Aug 2023 14:20:09 +0100 Subject: [PATCH 099/980] #1752 - Added web_browser.py application for DNS modelling --- .../simulator/network/protocols/dns.py | 7 +- .../system/applications/web_browser.py | 76 +++++++++++++++++++ 2 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/primaite/simulator/system/applications/web_browser.py diff --git a/src/primaite/simulator/network/protocols/dns.py b/src/primaite/simulator/network/protocols/dns.py index fa88652c..b8f0d8bd 100644 --- a/src/primaite/simulator/network/protocols/dns.py +++ b/src/primaite/simulator/network/protocols/dns.py @@ -5,17 +5,18 @@ from typing import Optional from pydantic import BaseModel - +""" class DNSEntry(BaseModel): - """ + Represents an entry in the DNS cache. :param domain_name: The domain name which a node would like to access. :param ip_address: The IP address through which the domain name is reachable. - """ + domain_name: str ip_address: IPv4Address +""" class DNSRequest(BaseModel): diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py new file mode 100644 index 00000000..b30f9946 --- /dev/null +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -0,0 +1,76 @@ +from abc import abstractmethod +from ipaddress import IPv4Address +from typing import Any, Dict, List, Optional + +from primaite.simulator.system.applications.application import Application + + +class WebBrowser(Application): + """ + Represents a web browser in the simulation environment. + + The application requests and loads web pages using its domain name and requesting IP addresses using DNS. + """ + + domain_name: str + "The domain name of the webpage." + domain_name_ip_address: Optional[IPv4Address] + "The IP address of the domain name for the webpage." + history: Dict[str] + "A dict that stores all of the previous domain names." + + @abstractmethod + def describe_state(self) -> Dict: + """ + Describes the current state of the software. + + The specifics of the software's state, including its health, criticality, + and any other pertinent information, should be implemented in subclasses. + + :return: A dictionary containing key-value pairs representing the current state of the software. + :rtype: Dict + """ + pass + + def apply_action(self, action: List[str]) -> None: + """ + Applies a list of actions to the Application. + + :param action: A list of actions to apply. + """ + pass + + def reset_component_for_episode(self, episode: int): + """ + Resets the Application component for a new episode. + + This method ensures the Application is ready for a new episode, including resetting any + stateful properties or statistics, and clearing any message queues. + """ + self.domain_name = "" + self.domain_name_ip_address = None + self.history = {} + + def send(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Sends a payload to the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to send. + :return: True if successful, False otherwise. + """ + pass + + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Receives a payload from the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to receive. + :return: True if successful, False otherwise. + """ + pass From 6ca53803cd819334f505f7b2019efd7b67951747 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 17 Aug 2023 15:32:12 +0100 Subject: [PATCH 100/980] Describe state --- .../notebooks/create-simulation.ipynb | 140 +++++++++++++ src/primaite/simulator/core.py | 5 +- src/primaite/simulator/domain/account.py | 23 ++- src/primaite/simulator/domain/controller.py | 13 ++ .../simulator/file_system/file_system.py | 11 +- .../simulator/file_system/file_system_file.py | 14 +- .../file_system/file_system_folder.py | 25 ++- .../file_system/file_system_item_abc.py | 18 +- src/primaite/simulator/network/container.py | 18 ++ .../simulator/network/hardware/base.py | 187 +++++++++++------- src/primaite/simulator/sim_container.py | 37 +++- .../system/applications/application.py | 7 +- .../simulator/system/core/session_manager.py | 14 +- .../simulator/system/processes/process.py | 7 +- .../simulator/system/services/service.py | 7 +- src/primaite/simulator/system/software.py | 27 ++- .../_simulator/test_sim_conatiner.py | 16 ++ 17 files changed, 444 insertions(+), 125 deletions(-) create mode 100644 src/primaite/notebooks/create-simulation.ipynb create mode 100644 tests/unit_tests/_primaite/_simulator/test_sim_conatiner.py diff --git a/src/primaite/notebooks/create-simulation.ipynb b/src/primaite/notebooks/create-simulation.ipynb new file mode 100644 index 00000000..e5fd63b0 --- /dev/null +++ b/src/primaite/notebooks/create-simulation.ipynb @@ -0,0 +1,140 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Build a simulation using the Python API\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Import the Simulation class" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.simulator.sim_container import Simulation\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create an empty simulation. By default this has a network with no nodes or links, and a domain controller with no accounts.\n", + "\n", + "Let's use the simulation's `describe_state()` method to verify that it is empty." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'uuid': '8d5cbb1b-aa9b-4f66-8b23-80d47755df69',\n", + " 'network': {'uuid': 'd3569bc4-eeed-40b1-9c3c-0fe80b9bb11c',\n", + " 'nodes': {},\n", + " 'links': {}},\n", + " 'domain': {'uuid': '4d4024ae-5948-4f07-aed9-d2315891cddc', 'accounts': {}}}" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_sim = Simulation()\n", + "my_sim.describe_state()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Add nodes" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.simulator.network.hardware.base import Node\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'uuid': '8d5cbb1b-aa9b-4f66-8b23-80d47755df69',\n", + " 'network': {'uuid': 'd3569bc4-eeed-40b1-9c3c-0fe80b9bb11c',\n", + " 'nodes': {'5f596f4f-4d34-4d1c-9688-9a105e489444': {'uuid': '5f596f4f-4d34-4d1c-9688-9a105e489444',\n", + " 'hostname': 'primaite_pc',\n", + " 'operating_state': 0,\n", + " 'NICs': {},\n", + " 'file_system': {'uuid': 'dc1e7032-7dba-44d5-aedb-5da75ab1eccc',\n", + " 'folders': {}},\n", + " 'applications': {},\n", + " 'services': {},\n", + " 'process': {}}},\n", + " 'links': {}},\n", + " 'domain': {'uuid': '4d4024ae-5948-4f07-aed9-d2315891cddc', 'accounts': {}}}" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_pc = Node(hostname=\"primaite_pc\",)\n", + "my_sim.network.nodes[my_pc.uuid] = my_pc\n", + "my_sim.describe_state()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 7a183588..2c802c0f 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -147,7 +147,10 @@ class SimComponent(BaseModel): object. If there are objects referenced by this object that are owned by something else, it is not included in this output. """ - return {} + state = { + "uuid": self.uuid, + } + return state def apply_action(self, action: List[str], context: Dict = {}) -> None: """ diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py index e8595afa..e30b7a27 100644 --- a/src/primaite/simulator/domain/account.py +++ b/src/primaite/simulator/domain/account.py @@ -43,8 +43,27 @@ class Account(SimComponent): enabled: bool = True def describe_state(self) -> Dict: - """Describe state for agent observations.""" - return super().describe_state() + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state.update( + { + "num_logons": self.num_logons, + "num_logoffs": self.num_logoffs, + "num_group_changes": self.num_group_changes, + "username": self.username, + "password": self.password, + "account_type": self.account_type, + "enabled": self.enabled, + } + ) + return state def enable(self): """Set the status to enabled.""" diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index 4e872531..f772ab22 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -96,6 +96,19 @@ class DomainController(SimComponent): ), ) + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state.update({"accounts": {uuid: acct.describe_state() for uuid, acct in self.accounts.items()}}) + return state + def _register_account(self, account: Account) -> None: """TODO.""" ... diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index d42db3e0..a5f603fe 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -18,11 +18,16 @@ class FileSystem(SimComponent): def describe_state(self) -> Dict: """ - Get the current state of the FileSystem as a dict. + Produce a dictionary describing the current state of this object. - :return: A dict containing the current state of the FileSystemFile. + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict """ - pass + state = super().describe_state() + state.update({"folders": {uuid: folder for uuid, folder in self.folders.items()}}) + return state def get_folders(self) -> Dict: """Returns the list of folders.""" diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py index f9fc2e1f..4bb6e585 100644 --- a/src/primaite/simulator/file_system/file_system_file.py +++ b/src/primaite/simulator/file_system/file_system_file.py @@ -38,8 +38,16 @@ class FileSystemFile(FileSystemItem): def describe_state(self) -> Dict: """ - Get the current state of the FileSystemFile as a dict. + Produce a dictionary describing the current state of this object. - :return: A dict containing the current state of the FileSystemFile. + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict """ - pass + return { + "uuid": self.uuid, + "name": self.name, + "size": self.size, + "file_type": self.file_type, + } diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py index b0705804..463f3854 100644 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -16,6 +16,23 @@ class FileSystemFolder(FileSystemItem): is_quarantined: bool = False """Flag that marks the folder as quarantined if true.""" + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + return { + "uuid": self.uuid, + "name": self.name, + "size": self.size, + "files": {uuid: file for uuid, file in self.files.items()}, + "is_quarantined": self.is_quarantined, + } + def get_file_by_id(self, file_id: str) -> FileSystemFile: """Return a FileSystemFile with the matching id.""" return self.files.get(file_id) @@ -67,11 +84,3 @@ class FileSystemFolder(FileSystemItem): def quarantine_status(self) -> bool: """Returns true if the folder is being quarantined.""" return self.is_quarantined - - def describe_state(self) -> Dict: - """ - Get the current state of the FileSystemFolder as a dict. - - :return: A dict containing the current state of the FileSystemFile. - """ - pass diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py index 0594cc35..3b368819 100644 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -13,5 +13,19 @@ class FileSystemItem(SimComponent): """The size the item takes up on disk.""" def describe_state(self) -> Dict: - """Returns the state of the FileSystemItem.""" - pass + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state.update( + { + "name": self.name, + "size": self.size, + } + ) + return state diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 346a089e..463d5f91 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -21,3 +21,21 @@ class NetworkContainer(SimComponent): validator=AllowAllValidator(), ), ) + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state.update( + { + "nodes": {uuid: node.describe_state() for uuid, node in self.nodes.items()}, + "links": {uuid: link.describe_state() for uuid, link in self.links.items()}, + } + ) + return state diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index ab5d4943..b731862b 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -125,6 +125,31 @@ class NIC(SimComponent): _LOGGER.error(msg) raise ValueError(msg) + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state.update( + { + "ip_adress": self.ip_address, + "subnet_mask": self.subnet_mask, + "gateway": self.gateway, + "mac_address": self.mac_address, + "speed": self.speed, + "mtu": self.mtu, + "wake_on_lan": self.wake_on_lan, + "dns_servers": self.dns_servers, + "enabled": self.enabled, + } + ) + return state + @property def ip_network(self) -> IPv4Network: """ @@ -241,23 +266,6 @@ class NIC(SimComponent): return True return False - def describe_state(self) -> Dict: - """ - Get the current state of the NIC as a dict. - - :return: A dict containing the current state of the NIC. - """ - pass - - def apply_action(self, action: str): - """ - Apply an action to the NIC. - - :param action: The action to be applied. - :type action: str - """ - pass - def __str__(self) -> str: return f"{self.mac_address}/{self.ip_address}" @@ -293,6 +301,25 @@ class SwitchPort(SimComponent): kwargs["mac_address"] = generate_mac_address() super().__init__(**kwargs) + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state.update( + { + "mac_address": self.mac_address, + "speed": self.speed, + "mtu": self.mtu, + "enabled": self.enabled, + } + ) + def enable(self): """Attempt to enable the SwitchPort.""" if self.enabled: @@ -379,23 +406,6 @@ class SwitchPort(SimComponent): return True return False - def describe_state(self) -> Dict: - """ - Get the current state of the SwitchPort as a dict. - - :return: A dict containing the current state of the SwitchPort. - """ - pass - - def apply_action(self, action: str): - """ - Apply an action to the SwitchPort. - - :param action: The action to be applied. - :type action: str - """ - pass - def __str__(self) -> str: return f"{self.mac_address}" @@ -435,6 +445,26 @@ class Link(SimComponent): self.endpoint_b.connect_link(self) self.endpoint_up() + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state.update( + { + "endpoint_a": self.endpoint_a.uuid, + "endpoint_b": self.endpoint_b.uuid, + "bandwidth": self.bandwidth, + "current_load": self.current_load, + } + ) + return state + @property def current_load_percent(self) -> str: """Get the current load formatted as a percentage string.""" @@ -504,23 +534,6 @@ class Link(SimComponent): """ self.current_load = 0 - def describe_state(self) -> Dict: - """ - Get the current state of the Link as a dict. - - :return: A dict containing the current state of the Link. - """ - pass - - def apply_action(self, action: str): - """ - Apply an action to the Link. - - :param action: The action to be applied. - :type action: str - """ - pass - def __str__(self) -> str: return f"{self.endpoint_a}<-->{self.endpoint_b}" @@ -832,6 +845,30 @@ class Node(SimComponent): super().__init__(**kwargs) self.arp.nics = self.nics + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state.update( + { + "hostname": self.hostname, + "operating_state": self.operating_state.value, + "NICs": {uuid: nic.describe_state() for uuid, nic in self.nics.items()}, + # "switch_ports": {uuid, sp for uuid, sp in self.switch_ports.items()}, + "file_system": self.file_system.describe_state(), + "applications": {uuid: app for uuid, app in self.applications.items()}, + "services": {uuid: svc for uuid, svc in self.services.items()}, + "process": {uuid: proc for uuid, proc in self.processes.items()}, + } + ) + return state + def show(self): """Prints a table of the NICs on the Node..""" from prettytable import PrettyTable @@ -950,14 +987,6 @@ class Node(SimComponent): elif frame.ip.protocol == IPProtocol.ICMP: self.icmp.process_icmp(frame=frame) - def describe_state(self) -> Dict: - """ - Describe the state of the Node. - - :return: A dictionary representing the state of the node. - """ - pass - class Switch(Node): """A class representing a Layer 2 network switch.""" @@ -966,9 +995,17 @@ class Switch(Node): "The number of ports on the switch." switch_ports: Dict[int, SwitchPort] = {} "The SwitchPorts on the switch." - dst_mac_table: Dict[str, SwitchPort] = {} + mac_address_table: Dict[str, SwitchPort] = {} "A MAC address table mapping destination MAC addresses to corresponding SwitchPorts." + def __init__(self, **kwargs): + super().__init__(**kwargs) + if not self.switch_ports: + self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)} + for port_num, port in self.switch_ports.items(): + port.connected_node = self + port.port_num = port_num + def show(self): """Prints a table of the SwitchPorts on the Switch.""" table = PrettyTable(["Port", "MAC Address", "Speed", "Status"]) @@ -978,25 +1015,29 @@ class Switch(Node): print(table) def describe_state(self) -> Dict: - """TODO.""" - pass + """ + Produce a dictionary describing the current state of this object. - def __init__(self, **kwargs): - super().__init__(**kwargs) - if not self.switch_ports: - self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)} - for port_num, port in self.switch_ports.items(): - port.connected_node = self - port.port_num = port_num + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + return { + "uuid": self.uuid, + "num_ports": self.num_ports, # redundant? + "ports": {port_num: port for port_num, port in self.switch_ports.items()}, + "mac_address_table": {mac: port for mac, port in self.mac_address_table.items()}, + } def _add_mac_table_entry(self, mac_address: str, switch_port: SwitchPort): - mac_table_port = self.dst_mac_table.get(mac_address) + mac_table_port = self.mac_address_table.get(mac_address) if not mac_table_port: - self.dst_mac_table[mac_address] = switch_port + self.mac_address_table[mac_address] = switch_port self.sys_log.info(f"Added MAC table entry: Port {switch_port.port_num} -> {mac_address}") else: if mac_table_port != switch_port: - self.dst_mac_table.pop(mac_address) + self.mac_address_table.pop(mac_address) self.sys_log.info(f"Removed MAC table entry: Port {mac_table_port.port_num} -> {mac_address}") self._add_mac_table_entry(mac_address, switch_port) @@ -1011,7 +1052,7 @@ class Switch(Node): dst_mac = frame.ethernet.dst_mac_addr self._add_mac_table_entry(src_mac, incoming_port) - outgoing_port = self.dst_mac_table.get(dst_mac) + outgoing_port = self.mac_address_table.get(dst_mac) if outgoing_port or dst_mac != "ff:ff:ff:ff:ff:ff": outgoing_port.send_frame(frame) else: diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index 6989d2b9..1a37dc18 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -1,20 +1,23 @@ +from typing import Dict + from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent from primaite.simulator.domain.controller import DomainController +from primaite.simulator.network.container import NetworkContainer -class __TempNetwork: +class Simulation(SimComponent): """TODO.""" - pass - - -class SimulationContainer(SimComponent): - """TODO.""" - - network: __TempNetwork + network: NetworkContainer domain: DomainController def __init__(self, **kwargs): + if not kwargs.get("network"): + kwargs["network"] = NetworkContainer() + + if not kwargs.get("domain"): + kwargs["domain"] = DomainController() + super().__init__(**kwargs) self.action_manager = ActionManager() @@ -32,3 +35,21 @@ class SimulationContainer(SimComponent): func=lambda request, context: self.domain.apply_action(request, context), validator=AllowAllValidator() ), ) + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state.update( + { + "network": self.network.describe_state(), + "domain": self.domain.describe_state(), + } + ) + return state diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 36a7bc85..c61afae6 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -36,12 +36,11 @@ class Application(IOSoftware): @abstractmethod def describe_state(self) -> Dict: """ - Describes the current state of the software. + Produce a dictionary describing the current state of this object. - The specifics of the software's state, including its health, criticality, - and any other pertinent information, should be implemented in subclasses. + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - :return: A dictionary containing key-value pairs representing the current state of the software. + :return: Current state of this object and child objects. :rtype: Dict """ pass diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 96d6251d..fe7b06b2 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -51,9 +51,12 @@ class Session(SimComponent): def describe_state(self) -> Dict: """ - Describes the current state of the session as a dictionary. + Produce a dictionary describing the current state of this object. - :return: A dictionary containing the current state of the session. + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict """ pass @@ -77,9 +80,12 @@ class SessionManager: def describe_state(self) -> Dict: """ - Describes the current state of the session manager as a dictionary. + Produce a dictionary describing the current state of this object. - :return: A dictionary containing the current state of the session manager. + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict """ pass diff --git a/src/primaite/simulator/system/processes/process.py b/src/primaite/simulator/system/processes/process.py index bbd94345..8e278aa3 100644 --- a/src/primaite/simulator/system/processes/process.py +++ b/src/primaite/simulator/system/processes/process.py @@ -27,12 +27,11 @@ class Process(Software): @abstractmethod def describe_state(self) -> Dict: """ - Describes the current state of the software. + Produce a dictionary describing the current state of this object. - The specifics of the software's state, including its health, criticality, - and any other pertinent information, should be implemented in subclasses. + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - :return: A dictionary containing key-value pairs representing the current state of the software. + :return: Current state of this object and child objects. :rtype: Dict """ pass diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 7be5cb78..29a787c5 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -35,12 +35,11 @@ class Service(IOSoftware): @abstractmethod def describe_state(self) -> Dict: """ - Describes the current state of the software. + Produce a dictionary describing the current state of this object. - The specifics of the software's state, including its health, criticality, - and any other pertinent information, should be implemented in subclasses. + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - :return: A dictionary containing key-value pairs representing the current state of the software. + :return: Current state of this object and child objects. :rtype: Dict """ pass diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 854e7e2b..5bc08178 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -78,15 +78,25 @@ class Software(SimComponent): @abstractmethod def describe_state(self) -> Dict: """ - Describes the current state of the software. + Produce a dictionary describing the current state of this object. - The specifics of the software's state, including its health, criticality, - and any other pertinent information, should be implemented in subclasses. + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - :return: A dictionary containing key-value pairs representing the current state of the software. + :return: Current state of this object and child objects. :rtype: Dict """ - pass + state = super().describe_state() + state.update( + { + "health_state": self.health_state_actual.name, + "health_state_red_view": self.health_state_visible.name, + "criticality": self.criticality.name, + "patching_count": self.patching_count, + "scanning_count": self.scanning_count, + "revealed_to_red": self.revealed_to_red, + } + ) + return state def apply_action(self, action: List[str]) -> None: """ @@ -134,12 +144,11 @@ class IOSoftware(Software): @abstractmethod def describe_state(self) -> Dict: """ - Describes the current state of the software. + Produce a dictionary describing the current state of this object. - The specifics of the software's state, including its health, criticality, - and any other pertinent information, should be implemented in subclasses. + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - :return: A dictionary containing key-value pairs representing the current state of the software. + :return: Current state of this object and child objects. :rtype: Dict """ pass diff --git a/tests/unit_tests/_primaite/_simulator/test_sim_conatiner.py b/tests/unit_tests/_primaite/_simulator/test_sim_conatiner.py new file mode 100644 index 00000000..4543259d --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/test_sim_conatiner.py @@ -0,0 +1,16 @@ +from primaite.simulator.sim_container import Simulation + + +def test_creating_empty_simulation(): + """Check that no errors occur when trying to setup a simulation without providing parameters""" + empty_sim = Simulation() + + +def test_empty_sim_state(): + """Check that describe_state has the right subcomponents.""" + empty_sim = Simulation() + sim_state = empty_sim.describe_state() + network_state = empty_sim.network.describe_state() + domain_state = empty_sim.domain.describe_state() + assert sim_state["network"] == network_state + assert sim_state["domain"] == domain_state From 01c912c094cfcfdf27609db77cff2a841b64dd17 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 20 Aug 2023 18:38:02 +0100 Subject: [PATCH 101/980] fix type hints and describe state functions --- .../notebooks/create-simulation.ipynb | 400 +++++++++++++++++- src/primaite/simulator/domain/account.py | 2 +- .../simulator/file_system/file_system.py | 4 +- .../simulator/file_system/file_system_file.py | 14 +- .../file_system/file_system_folder.py | 17 +- .../simulator/network/hardware/base.py | 27 +- .../system/applications/application.py | 24 +- .../simulator/system/processes/process.py | 4 +- .../simulator/system/services/service.py | 4 +- src/primaite/simulator/system/software.py | 12 +- 10 files changed, 459 insertions(+), 49 deletions(-) diff --git a/src/primaite/notebooks/create-simulation.ipynb b/src/primaite/notebooks/create-simulation.ipynb index e5fd63b0..86a7f6a2 100644 --- a/src/primaite/notebooks/create-simulation.ipynb +++ b/src/primaite/notebooks/create-simulation.ipynb @@ -40,11 +40,11 @@ { "data": { "text/plain": [ - "{'uuid': '8d5cbb1b-aa9b-4f66-8b23-80d47755df69',\n", - " 'network': {'uuid': 'd3569bc4-eeed-40b1-9c3c-0fe80b9bb11c',\n", + "{'uuid': 'f0c06262-1bd9-49ee-81f8-793fb4a5e58e',\n", + " 'network': {'uuid': '455d6a1a-ca23-4135-b326-3ebf75022a45',\n", " 'nodes': {},\n", " 'links': {}},\n", - " 'domain': {'uuid': '4d4024ae-5948-4f07-aed9-d2315891cddc', 'accounts': {}}}" + " 'domain': {'uuid': '9da912d5-4c07-4df6-94c2-b3630e178912', 'accounts': {}}}" ] }, "execution_count": 2, @@ -81,19 +81,28 @@ { "data": { "text/plain": [ - "{'uuid': '8d5cbb1b-aa9b-4f66-8b23-80d47755df69',\n", - " 'network': {'uuid': 'd3569bc4-eeed-40b1-9c3c-0fe80b9bb11c',\n", - " 'nodes': {'5f596f4f-4d34-4d1c-9688-9a105e489444': {'uuid': '5f596f4f-4d34-4d1c-9688-9a105e489444',\n", + "{'uuid': 'f0c06262-1bd9-49ee-81f8-793fb4a5e58e',\n", + " 'network': {'uuid': '455d6a1a-ca23-4135-b326-3ebf75022a45',\n", + " 'nodes': {'c7c91f06-f128-4891-84a2-83beceea3908': {'uuid': 'c7c91f06-f128-4891-84a2-83beceea3908',\n", " 'hostname': 'primaite_pc',\n", " 'operating_state': 0,\n", " 'NICs': {},\n", - " 'file_system': {'uuid': 'dc1e7032-7dba-44d5-aedb-5da75ab1eccc',\n", + " 'file_system': {'uuid': '04ffd1e8-dea7-47ad-a088-4856df055ed1',\n", + " 'folders': {}},\n", + " 'applications': {},\n", + " 'services': {},\n", + " 'process': {}},\n", + " 'dfcc395a-93ff-4dd5-9684-c80c5885d827': {'uuid': 'dfcc395a-93ff-4dd5-9684-c80c5885d827',\n", + " 'hostname': 'google_server',\n", + " 'operating_state': 0,\n", + " 'NICs': {},\n", + " 'file_system': {'uuid': 'aea8f406-05de-4a02-b65f-972aa1fed70e',\n", " 'folders': {}},\n", " 'applications': {},\n", " 'services': {},\n", " 'process': {}}},\n", " 'links': {}},\n", - " 'domain': {'uuid': '4d4024ae-5948-4f07-aed9-d2315891cddc', 'accounts': {}}}" + " 'domain': {'uuid': '9da912d5-4c07-4df6-94c2-b3630e178912', 'accounts': {}}}" ] }, "execution_count": 4, @@ -103,16 +112,387 @@ ], "source": [ "my_pc = Node(hostname=\"primaite_pc\",)\n", + "my_server = Node(hostname=\"google_server\")\n", + "\n", + "# TODO: when there is a proper function for adding nodes, use it instead of manually adding.\n", + "\n", "my_sim.network.nodes[my_pc.uuid] = my_pc\n", + "my_sim.network.nodes[my_server.uuid] = my_server\n", + "\n", + "my_sim.describe_state()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Connect the nodes" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.simulator.network.hardware.base import NIC, Link, Switch\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-08-20 18:34:59,328: NIC c3:08:90:23:29:cb/130.1.1.1 connected to Link c3:08:90:23:29:cb/130.1.1.1<-->40:4a:3f:2e:ee:2e\n", + "2023-08-20 18:34:59,329: SwitchPort 40:4a:3f:2e:ee:2e connected to Link c3:08:90:23:29:cb/130.1.1.1<-->40:4a:3f:2e:ee:2e\n", + "2023-08-20 18:34:59,331: NIC 69:50:cb:76:22:10/130.1.1.2 connected to Link 69:50:cb:76:22:10/130.1.1.2<-->18:5e:49:ed:21:55\n", + "2023-08-20 18:34:59,331: SwitchPort 18:5e:49:ed:21:55 connected to Link 69:50:cb:76:22:10/130.1.1.2<-->18:5e:49:ed:21:55\n" + ] + } + ], + "source": [ + "my_swtich = Switch(hostname=\"switch1\", num_ports=12)\n", + "\n", + "pc_nic = NIC(ip_address=\"130.1.1.1\", gateway=\"130.1.1.255\", subnet_mask=\"255.255.255.0\")\n", + "my_pc.connect_nic(pc_nic)\n", + "\n", + "\n", + "server_nic = NIC(ip_address=\"130.1.1.2\", gateway=\"130.1.1.255\", subnet_mask=\"255.255.255.0\")\n", + "my_server.connect_nic(server_nic)\n", + "\n", + "\n", + "pc_to_switch = Link(endpoint_a=pc_nic, endpoint_b=my_swtich.switch_ports[1])\n", + "server_to_swtich = Link(endpoint_a=server_nic, endpoint_b=my_swtich.switch_ports[2])\n", + "\n", + "my_sim.network.links[pc_to_switch.uuid] = pc_to_switch\n", + "my_sim.network.links[server_to_swtich.uuid] = server_to_swtich" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'uuid': 'f0c06262-1bd9-49ee-81f8-793fb4a5e58e',\n", + " 'network': {'uuid': '455d6a1a-ca23-4135-b326-3ebf75022a45',\n", + " 'nodes': {'c7c91f06-f128-4891-84a2-83beceea3908': {'uuid': 'c7c91f06-f128-4891-84a2-83beceea3908',\n", + " 'hostname': 'primaite_pc',\n", + " 'operating_state': 0,\n", + " 'NICs': {'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2': {'uuid': 'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2',\n", + " 'ip_adress': '130.1.1.1',\n", + " 'subnet_mask': '255.255.255.0',\n", + " 'gateway': '130.1.1.255',\n", + " 'mac_address': 'c3:08:90:23:29:cb',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'wake_on_lan': False,\n", + " 'dns_servers': [],\n", + " 'enabled': False}},\n", + " 'file_system': {'uuid': '04ffd1e8-dea7-47ad-a088-4856df055ed1',\n", + " 'folders': {}},\n", + " 'applications': {},\n", + " 'services': {},\n", + " 'process': {}},\n", + " 'dfcc395a-93ff-4dd5-9684-c80c5885d827': {'uuid': 'dfcc395a-93ff-4dd5-9684-c80c5885d827',\n", + " 'hostname': 'google_server',\n", + " 'operating_state': 0,\n", + " 'NICs': {'1fd281a0-83ae-49d9-9b40-6aae7b465cab': {'uuid': '1fd281a0-83ae-49d9-9b40-6aae7b465cab',\n", + " 'ip_adress': '130.1.1.2',\n", + " 'subnet_mask': '255.255.255.0',\n", + " 'gateway': '130.1.1.255',\n", + " 'mac_address': '69:50:cb:76:22:10',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'wake_on_lan': False,\n", + " 'dns_servers': [],\n", + " 'enabled': False}},\n", + " 'file_system': {'uuid': 'aea8f406-05de-4a02-b65f-972aa1fed70e',\n", + " 'folders': {}},\n", + " 'applications': {},\n", + " 'services': {},\n", + " 'process': {}}},\n", + " 'links': {'cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9': {'uuid': 'cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9',\n", + " 'endpoint_a': 'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2',\n", + " 'endpoint_b': '4e6abc87-b4b9-4f95-a9a9-59cac130c6ff',\n", + " 'bandwidth': 100.0,\n", + " 'current_load': 0.0},\n", + " '2dab7fc3-470d-44d2-8593-feb8e96d71ae': {'uuid': '2dab7fc3-470d-44d2-8593-feb8e96d71ae',\n", + " 'endpoint_a': '1fd281a0-83ae-49d9-9b40-6aae7b465cab',\n", + " 'endpoint_b': 'e136553f-333e-4abf-b1f3-ce352ffa4630',\n", + " 'bandwidth': 100.0,\n", + " 'current_load': 0.0}}},\n", + " 'domain': {'uuid': '9da912d5-4c07-4df6-94c2-b3630e178912', 'accounts': {}}}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_sim.describe_state()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Add files and folders to nodes\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.simulator.file_system.file_system_file_type import FileSystemFileType\n", + "from primaite.simulator.file_system.file_system_file import FileSystemFile" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "my_pc_downloads_folder = my_pc.file_system.create_folder(\"downloads\")\n", + "my_pc_downloads_folder.add_file(FileSystemFile(name=\"firefox_installer.zip\",file_type=FileSystemFileType.ZIP))" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "FileSystemFile(uuid='3ecf7223-dafd-4973-8c3b-b85af4e177da', name='favicon.ico', size=40.0, file_type=, action_manager=None)" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_server_folder = my_server.file_system.create_folder(\"static\")\n", + "my_server.file_system.create_file(\"favicon.ico\", file_type=FileSystemFileType.PNG)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Add applications to nodes" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.simulator.system.applications.application import Application, ApplicationOperatingState\n", + "from primaite.simulator.system.software import SoftwareHealthState, SoftwareCriticality\n", + "from primaite.simulator.network.transmission.transport_layer import Port\n", + "\n", + "class MSPaint(Application):\n", + " def describe_state(self):\n", + " return super().describe_state()" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "mspaint = MSPaint(name = \"mspaint\", health_state_actual=SoftwareHealthState.GOOD, health_state_visible=SoftwareHealthState.GOOD, criticality=SoftwareCriticality.MEDIUM, ports={Port.HTTP}, operating_state=ApplicationOperatingState.RUNNING,execution_control_status='manual')" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "my_pc.applications[mspaint.uuid] = mspaint" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create a domain account" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.simulator.domain.account import Account, AccountType\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "acct = Account(username=\"admin\", password=\"admin12\", account_type=AccountType.USER)\n", + "my_sim.domain.accounts[acct.uuid] = acct" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'uuid': 'f0c06262-1bd9-49ee-81f8-793fb4a5e58e',\n", + " 'network': {'uuid': '455d6a1a-ca23-4135-b326-3ebf75022a45',\n", + " 'nodes': {'c7c91f06-f128-4891-84a2-83beceea3908': {'uuid': 'c7c91f06-f128-4891-84a2-83beceea3908',\n", + " 'hostname': 'primaite_pc',\n", + " 'operating_state': 0,\n", + " 'NICs': {'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2': {'uuid': 'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2',\n", + " 'ip_adress': '130.1.1.1',\n", + " 'subnet_mask': '255.255.255.0',\n", + " 'gateway': '130.1.1.255',\n", + " 'mac_address': 'c3:08:90:23:29:cb',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'wake_on_lan': False,\n", + " 'dns_servers': [],\n", + " 'enabled': False}},\n", + " 'file_system': {'uuid': '04ffd1e8-dea7-47ad-a088-4856df055ed1',\n", + " 'folders': {'f1fdf2ae-6377-4417-a28a-3edb4058712d': {'uuid': 'f1fdf2ae-6377-4417-a28a-3edb4058712d',\n", + " 'name': 'downloads',\n", + " 'size': 1000.0,\n", + " 'files': {'409b09a3-0d98-4c03-adf2-09190539be45': {'uuid': '409b09a3-0d98-4c03-adf2-09190539be45',\n", + " 'name': 'firefox_installer.zip',\n", + " 'size': 1000.0,\n", + " 'file_type': 'ZIP'}},\n", + " 'is_quarantined': False}}},\n", + " 'applications': {'cddee888-d1b9-4289-8512-bc0a6672c880': {'uuid': 'cddee888-d1b9-4289-8512-bc0a6672c880',\n", + " 'health_state': 'GOOD',\n", + " 'health_state_red_view': 'GOOD',\n", + " 'criticality': 'MEDIUM',\n", + " 'patching_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 1,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'ports': ['HTTP'],\n", + " 'opearting_state': 'RUNNING',\n", + " 'execution_control_status': 'manual',\n", + " 'num_executions': 0,\n", + " 'groups': []}},\n", + " 'services': {},\n", + " 'process': {}},\n", + " 'dfcc395a-93ff-4dd5-9684-c80c5885d827': {'uuid': 'dfcc395a-93ff-4dd5-9684-c80c5885d827',\n", + " 'hostname': 'google_server',\n", + " 'operating_state': 0,\n", + " 'NICs': {'1fd281a0-83ae-49d9-9b40-6aae7b465cab': {'uuid': '1fd281a0-83ae-49d9-9b40-6aae7b465cab',\n", + " 'ip_adress': '130.1.1.2',\n", + " 'subnet_mask': '255.255.255.0',\n", + " 'gateway': '130.1.1.255',\n", + " 'mac_address': '69:50:cb:76:22:10',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'wake_on_lan': False,\n", + " 'dns_servers': [],\n", + " 'enabled': False}},\n", + " 'file_system': {'uuid': 'aea8f406-05de-4a02-b65f-972aa1fed70e',\n", + " 'folders': {'beb5b535-cf6c-431d-94f6-d1097910130d': {'uuid': 'beb5b535-cf6c-431d-94f6-d1097910130d',\n", + " 'name': 'static',\n", + " 'size': 0,\n", + " 'files': {},\n", + " 'is_quarantined': False},\n", + " '6644cd6c-1eca-4fe4-9313-e3481abb895e': {'uuid': '6644cd6c-1eca-4fe4-9313-e3481abb895e',\n", + " 'name': 'root',\n", + " 'size': 40.0,\n", + " 'files': {'3ecf7223-dafd-4973-8c3b-b85af4e177da': {'uuid': '3ecf7223-dafd-4973-8c3b-b85af4e177da',\n", + " 'name': 'favicon.ico',\n", + " 'size': 40.0,\n", + " 'file_type': 'PNG'}},\n", + " 'is_quarantined': False}}},\n", + " 'applications': {},\n", + " 'services': {},\n", + " 'process': {}}},\n", + " 'links': {'cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9': {'uuid': 'cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9',\n", + " 'endpoint_a': 'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2',\n", + " 'endpoint_b': '4e6abc87-b4b9-4f95-a9a9-59cac130c6ff',\n", + " 'bandwidth': 100.0,\n", + " 'current_load': 0.0},\n", + " '2dab7fc3-470d-44d2-8593-feb8e96d71ae': {'uuid': '2dab7fc3-470d-44d2-8593-feb8e96d71ae',\n", + " 'endpoint_a': '1fd281a0-83ae-49d9-9b40-6aae7b465cab',\n", + " 'endpoint_b': 'e136553f-333e-4abf-b1f3-ce352ffa4630',\n", + " 'bandwidth': 100.0,\n", + " 'current_load': 0.0}}},\n", + " 'domain': {'uuid': '9da912d5-4c07-4df6-94c2-b3630e178912',\n", + " 'accounts': {'563a1805-0b32-4ba6-9551-e127e5eb57a8': {'uuid': '563a1805-0b32-4ba6-9551-e127e5eb57a8',\n", + " 'num_logons': 0,\n", + " 'num_logoffs': 0,\n", + " 'num_group_changes': 0,\n", + " 'username': 'admin',\n", + " 'password': 'admin12',\n", + " 'account_type': 'USER',\n", + " 'enabled': True}}}}" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ "my_sim.describe_state()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import json" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'{\"uuid\": \"f0c06262-1bd9-49ee-81f8-793fb4a5e58e\", \"network\": {\"uuid\": \"455d6a1a-ca23-4135-b326-3ebf75022a45\", \"nodes\": {\"c7c91f06-f128-4891-84a2-83beceea3908\": {\"uuid\": \"c7c91f06-f128-4891-84a2-83beceea3908\", \"hostname\": \"primaite_pc\", \"operating_state\": 0, \"NICs\": {\"f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2\": {\"uuid\": \"f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2\", \"ip_adress\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"c3:08:90:23:29:cb\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"04ffd1e8-dea7-47ad-a088-4856df055ed1\", \"folders\": {\"f1fdf2ae-6377-4417-a28a-3edb4058712d\": {\"uuid\": \"f1fdf2ae-6377-4417-a28a-3edb4058712d\", \"name\": \"downloads\", \"size\": 1000.0, \"files\": {\"409b09a3-0d98-4c03-adf2-09190539be45\": {\"uuid\": \"409b09a3-0d98-4c03-adf2-09190539be45\", \"name\": \"firefox_installer.zip\", \"size\": 1000.0, \"file_type\": \"ZIP\"}}, \"is_quarantined\": false}}}, \"applications\": {\"cddee888-d1b9-4289-8512-bc0a6672c880\": {\"uuid\": \"cddee888-d1b9-4289-8512-bc0a6672c880\", \"health_state\": \"GOOD\", \"health_state_red_view\": \"GOOD\", \"criticality\": \"MEDIUM\", \"patching_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 1, \"tcp\": true, \"udp\": true, \"ports\": [\"HTTP\"], \"opearting_state\": \"RUNNING\", \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {}, \"process\": {}}, \"dfcc395a-93ff-4dd5-9684-c80c5885d827\": {\"uuid\": \"dfcc395a-93ff-4dd5-9684-c80c5885d827\", \"hostname\": \"google_server\", \"operating_state\": 0, \"NICs\": {\"1fd281a0-83ae-49d9-9b40-6aae7b465cab\": {\"uuid\": \"1fd281a0-83ae-49d9-9b40-6aae7b465cab\", \"ip_adress\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"69:50:cb:76:22:10\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"aea8f406-05de-4a02-b65f-972aa1fed70e\", \"folders\": {\"beb5b535-cf6c-431d-94f6-d1097910130d\": {\"uuid\": \"beb5b535-cf6c-431d-94f6-d1097910130d\", \"name\": \"static\", \"size\": 0, \"files\": {}, \"is_quarantined\": false}, \"6644cd6c-1eca-4fe4-9313-e3481abb895e\": {\"uuid\": \"6644cd6c-1eca-4fe4-9313-e3481abb895e\", \"name\": \"root\", \"size\": 40.0, \"files\": {\"3ecf7223-dafd-4973-8c3b-b85af4e177da\": {\"uuid\": \"3ecf7223-dafd-4973-8c3b-b85af4e177da\", \"name\": \"favicon.ico\", \"size\": 40.0, \"file_type\": \"PNG\"}}, \"is_quarantined\": false}}}, \"applications\": {}, \"services\": {}, \"process\": {}}}, \"links\": {\"cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9\": {\"uuid\": \"cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9\", \"endpoint_a\": \"f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2\", \"endpoint_b\": \"4e6abc87-b4b9-4f95-a9a9-59cac130c6ff\", \"bandwidth\": 100.0, \"current_load\": 0.0}, \"2dab7fc3-470d-44d2-8593-feb8e96d71ae\": {\"uuid\": \"2dab7fc3-470d-44d2-8593-feb8e96d71ae\", \"endpoint_a\": \"1fd281a0-83ae-49d9-9b40-6aae7b465cab\", \"endpoint_b\": \"e136553f-333e-4abf-b1f3-ce352ffa4630\", \"bandwidth\": 100.0, \"current_load\": 0.0}}}, \"domain\": {\"uuid\": \"9da912d5-4c07-4df6-94c2-b3630e178912\", \"accounts\": {\"563a1805-0b32-4ba6-9551-e127e5eb57a8\": {\"uuid\": \"563a1805-0b32-4ba6-9551-e127e5eb57a8\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": \"USER\", \"enabled\": true}}}}'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d = my_sim.describe_state()\n", + "json.dumps(d)" + ] } ], "metadata": { diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py index e30b7a27..d235c00e 100644 --- a/src/primaite/simulator/domain/account.py +++ b/src/primaite/simulator/domain/account.py @@ -59,7 +59,7 @@ class Account(SimComponent): "num_group_changes": self.num_group_changes, "username": self.username, "password": self.password, - "account_type": self.account_type, + "account_type": self.account_type.name, "enabled": self.enabled, } ) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index a5f603fe..440b7dc5 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -13,7 +13,7 @@ _LOGGER = getLogger(__name__) class FileSystem(SimComponent): """Class that contains all the simulation File System.""" - folders: Dict = {} + folders: Dict[str, FileSystemFolder] = {} """List containing all the folders in the file system.""" def describe_state(self) -> Dict: @@ -26,7 +26,7 @@ class FileSystem(SimComponent): :rtype: Dict """ state = super().describe_state() - state.update({"folders": {uuid: folder for uuid, folder in self.folders.items()}}) + state.update({"folders": {uuid: folder.describe_state() for uuid, folder in self.folders.items()}}) return state def get_folders(self) -> Dict: diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py index 4bb6e585..c25f5973 100644 --- a/src/primaite/simulator/file_system/file_system_file.py +++ b/src/primaite/simulator/file_system/file_system_file.py @@ -45,9 +45,11 @@ class FileSystemFile(FileSystemItem): :return: Current state of this object and child objects. :rtype: Dict """ - return { - "uuid": self.uuid, - "name": self.name, - "size": self.size, - "file_type": self.file_type, - } + state = super().describe_state() + state.update( + { + "uuid": self.uuid, + "file_type": self.file_type.name, + } + ) + return state diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py index 463f3854..4e461a3a 100644 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ b/src/primaite/simulator/file_system/file_system_folder.py @@ -10,7 +10,7 @@ _LOGGER = getLogger(__name__) class FileSystemFolder(FileSystemItem): """Simulation FileSystemFolder.""" - files: Dict = {} + files: Dict[str, FileSystemFile] = {} """List of files stored in the folder.""" is_quarantined: bool = False @@ -25,13 +25,14 @@ class FileSystemFolder(FileSystemItem): :return: Current state of this object and child objects. :rtype: Dict """ - return { - "uuid": self.uuid, - "name": self.name, - "size": self.size, - "files": {uuid: file for uuid, file in self.files.items()}, - "is_quarantined": self.is_quarantined, - } + state = super().describe_state() + state.update( + { + "files": {uuid: file.describe_state() for uuid, file in self.files.items()}, + "is_quarantined": self.is_quarantined, + } + ) + return state def get_file_by_id(self, file_id: str) -> FileSystemFile: """Return a FileSystemFile with the matching id.""" diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index b731862b..28e7693a 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -11,15 +11,19 @@ from prettytable import PrettyTable from primaite import getLogger from primaite.exceptions import NetworkError from primaite.simulator.core import SimComponent +from primaite.simulator.domain.account import Account from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader +from primaite.simulator.system.applications.application import Application from primaite.simulator.system.core.packet_capture import PacketCapture from primaite.simulator.system.core.session_manager import SessionManager from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.system.processes.process import Process +from primaite.simulator.system.services.service import Service _LOGGER = getLogger(__name__) @@ -137,9 +141,9 @@ class NIC(SimComponent): state = super().describe_state() state.update( { - "ip_adress": self.ip_address, - "subnet_mask": self.subnet_mask, - "gateway": self.gateway, + "ip_adress": str(self.ip_address), + "subnet_mask": str(self.subnet_mask), + "gateway": str(self.gateway), "mac_address": self.mac_address, "speed": self.speed, "mtu": self.mtu, @@ -319,6 +323,7 @@ class SwitchPort(SimComponent): "enabled": self.enabled, } ) + return state def enable(self): """Attempt to enable the SwitchPort.""" @@ -802,13 +807,13 @@ class Node(SimComponent): nics: Dict[str, NIC] = {} "The NICs on the node." - accounts: Dict = {} + accounts: Dict[str, Account] = {} "All accounts on the node." - applications: Dict = {} + applications: Dict[str, Application] = {} "All applications on the node." - services: Dict = {} + services: Dict[str, Service] = {} "All services on the node." - processes: Dict = {} + processes: Dict[str, Process] = {} "All processes on the node." file_system: FileSystem "The nodes file system." @@ -862,9 +867,9 @@ class Node(SimComponent): "NICs": {uuid: nic.describe_state() for uuid, nic in self.nics.items()}, # "switch_ports": {uuid, sp for uuid, sp in self.switch_ports.items()}, "file_system": self.file_system.describe_state(), - "applications": {uuid: app for uuid, app in self.applications.items()}, - "services": {uuid: svc for uuid, svc in self.services.items()}, - "process": {uuid: proc for uuid, proc in self.processes.items()}, + "applications": {uuid: app.describe_state() for uuid, app in self.applications.items()}, + "services": {uuid: svc.describe_state() for uuid, svc in self.services.items()}, + "process": {uuid: proc.describe_state() for uuid, proc in self.processes.items()}, } ) return state @@ -1026,7 +1031,7 @@ class Switch(Node): return { "uuid": self.uuid, "num_ports": self.num_ports, # redundant? - "ports": {port_num: port for port_num, port in self.switch_ports.items()}, + "ports": {port_num: port.describe_state() for port_num, port in self.switch_ports.items()}, "mac_address_table": {mac: port for mac, port in self.mac_address_table.items()}, } diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index c61afae6..37748560 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -8,13 +8,12 @@ from primaite.simulator.system.software import IOSoftware class ApplicationOperatingState(Enum): """Enumeration of Application Operating States.""" - -RUNNING = 1 -"The application is running." -CLOSED = 2 -"The application is closed or not running." -INSTALLING = 3 -"The application is being installed or updated." + RUNNING = 1 + "The application is running." + CLOSED = 2 + "The application is closed or not running." + INSTALLING = 3 + "The application is being installed or updated." class Application(IOSoftware): @@ -43,7 +42,16 @@ class Application(IOSoftware): :return: Current state of this object and child objects. :rtype: Dict """ - pass + state = super().describe_state() + state.update( + { + "opearting_state": self.operating_state.name, + "execution_control_status": self.execution_control_status, + "num_executions": self.num_executions, + "groups": list(self.groups), + } + ) + return state def apply_action(self, action: List[str]) -> None: """ diff --git a/src/primaite/simulator/system/processes/process.py b/src/primaite/simulator/system/processes/process.py index 8e278aa3..c4e94845 100644 --- a/src/primaite/simulator/system/processes/process.py +++ b/src/primaite/simulator/system/processes/process.py @@ -34,4 +34,6 @@ class Process(Software): :return: Current state of this object and child objects. :rtype: Dict """ - pass + state = super().describe_state() + state.update({"operating_state": self.operating_state.name}) + return state diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 29a787c5..eafff3f0 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -42,7 +42,9 @@ class Service(IOSoftware): :return: Current state of this object and child objects. :rtype: Dict """ - pass + state = super().describe_state() + state.update({"operating_state": self.operating_state.name}) + return state def apply_action(self, action: List[str]) -> None: """ diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 5bc08178..a2acd9fb 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -151,7 +151,17 @@ class IOSoftware(Software): :return: Current state of this object and child objects. :rtype: Dict """ - pass + state = super().describe_state() + state.update( + { + "installing_count": self.installing_count, + "max_sessions": self.max_sessions, + "tcp": self.tcp, + "udp": self.udp, + "ports": [port.name for port in self.ports], # TODO: not sure if this should be port.name or port.value + } + ) + return state def send(self, payload: Any, session_id: str, **kwargs) -> bool: """ From 3911010777ad09451f8da4b2ac1a72b947f0ff61 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 20 Aug 2023 18:42:58 +0100 Subject: [PATCH 102/980] update notebook --- src/primaite/notebooks/create-simulation.ipynb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/primaite/notebooks/create-simulation.ipynb b/src/primaite/notebooks/create-simulation.ipynb index 86a7f6a2..a3e2d92c 100644 --- a/src/primaite/notebooks/create-simulation.ipynb +++ b/src/primaite/notebooks/create-simulation.ipynb @@ -464,6 +464,13 @@ "my_sim.describe_state()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Verify that the state dictionary contains no non-serialisable objects." + ] + }, { "cell_type": "code", "execution_count": 17, From 7c16a9cdde818093c518844868aecdbb4c38f2e1 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 20 Aug 2023 18:43:21 +0100 Subject: [PATCH 103/980] Update notebook --- .../notebooks/create-simulation.ipynb | 230 +++++------------- 1 file changed, 61 insertions(+), 169 deletions(-) diff --git a/src/primaite/notebooks/create-simulation.ipynb b/src/primaite/notebooks/create-simulation.ipynb index a3e2d92c..b0a140a1 100644 --- a/src/primaite/notebooks/create-simulation.ipynb +++ b/src/primaite/notebooks/create-simulation.ipynb @@ -4,7 +4,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Build a simulation using the Python API\n" + "# Build a simulation using the Python API\n", + "\n", + "Currently, this notbook manipulates the simulation by directly placing objects inside of the attributes of the network and domain. It should be refactored when proper methods exist for adding these objects.\n" ] }, { @@ -40,11 +42,11 @@ { "data": { "text/plain": [ - "{'uuid': 'f0c06262-1bd9-49ee-81f8-793fb4a5e58e',\n", - " 'network': {'uuid': '455d6a1a-ca23-4135-b326-3ebf75022a45',\n", + "{'uuid': '5304ed6d-de4c-408c-ae24-ada32852d196',\n", + " 'network': {'uuid': 'fa17dfe8-81a1-4c7f-8c5b-8c2d3b1e8756',\n", " 'nodes': {},\n", " 'links': {}},\n", - " 'domain': {'uuid': '9da912d5-4c07-4df6-94c2-b3630e178912', 'accounts': {}}}" + " 'domain': {'uuid': '320cbb83-eb1b-4911-a4f0-fc46d8038a8a', 'accounts': {}}}" ] }, "execution_count": 2, @@ -77,39 +79,7 @@ "cell_type": "code", "execution_count": 4, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'uuid': 'f0c06262-1bd9-49ee-81f8-793fb4a5e58e',\n", - " 'network': {'uuid': '455d6a1a-ca23-4135-b326-3ebf75022a45',\n", - " 'nodes': {'c7c91f06-f128-4891-84a2-83beceea3908': {'uuid': 'c7c91f06-f128-4891-84a2-83beceea3908',\n", - " 'hostname': 'primaite_pc',\n", - " 'operating_state': 0,\n", - " 'NICs': {},\n", - " 'file_system': {'uuid': '04ffd1e8-dea7-47ad-a088-4856df055ed1',\n", - " 'folders': {}},\n", - " 'applications': {},\n", - " 'services': {},\n", - " 'process': {}},\n", - " 'dfcc395a-93ff-4dd5-9684-c80c5885d827': {'uuid': 'dfcc395a-93ff-4dd5-9684-c80c5885d827',\n", - " 'hostname': 'google_server',\n", - " 'operating_state': 0,\n", - " 'NICs': {},\n", - " 'file_system': {'uuid': 'aea8f406-05de-4a02-b65f-972aa1fed70e',\n", - " 'folders': {}},\n", - " 'applications': {},\n", - " 'services': {},\n", - " 'process': {}}},\n", - " 'links': {}},\n", - " 'domain': {'uuid': '9da912d5-4c07-4df6-94c2-b3630e178912', 'accounts': {}}}" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_pc = Node(hostname=\"primaite_pc\",)\n", "my_server = Node(hostname=\"google_server\")\n", @@ -117,9 +87,7 @@ "# TODO: when there is a proper function for adding nodes, use it instead of manually adding.\n", "\n", "my_sim.network.nodes[my_pc.uuid] = my_pc\n", - "my_sim.network.nodes[my_server.uuid] = my_server\n", - "\n", - "my_sim.describe_state()" + "my_sim.network.nodes[my_server.uuid] = my_server\n" ] }, { @@ -147,10 +115,10 @@ "name": "stderr", "output_type": "stream", "text": [ - "2023-08-20 18:34:59,328: NIC c3:08:90:23:29:cb/130.1.1.1 connected to Link c3:08:90:23:29:cb/130.1.1.1<-->40:4a:3f:2e:ee:2e\n", - "2023-08-20 18:34:59,329: SwitchPort 40:4a:3f:2e:ee:2e connected to Link c3:08:90:23:29:cb/130.1.1.1<-->40:4a:3f:2e:ee:2e\n", - "2023-08-20 18:34:59,331: NIC 69:50:cb:76:22:10/130.1.1.2 connected to Link 69:50:cb:76:22:10/130.1.1.2<-->18:5e:49:ed:21:55\n", - "2023-08-20 18:34:59,331: SwitchPort 18:5e:49:ed:21:55 connected to Link 69:50:cb:76:22:10/130.1.1.2<-->18:5e:49:ed:21:55\n" + "2023-08-20 18:42:51,310: NIC 5c:b6:26:c0:86:61/130.1.1.1 connected to Link 5c:b6:26:c0:86:61/130.1.1.1<-->01:ef:b1:a3:24:72\n", + "2023-08-20 18:42:51,311: SwitchPort 01:ef:b1:a3:24:72 connected to Link 5c:b6:26:c0:86:61/130.1.1.1<-->01:ef:b1:a3:24:72\n", + "2023-08-20 18:42:51,314: NIC f6:de:1e:63:8e:7f/130.1.1.2 connected to Link f6:de:1e:63:8e:7f/130.1.1.2<-->30:9e:c8:d4:5d:f3\n", + "2023-08-20 18:42:51,315: SwitchPort 30:9e:c8:d4:5d:f3 connected to Link f6:de:1e:63:8e:7f/130.1.1.2<-->30:9e:c8:d4:5d:f3\n" ] } ], @@ -172,74 +140,6 @@ "my_sim.network.links[server_to_swtich.uuid] = server_to_swtich" ] }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'uuid': 'f0c06262-1bd9-49ee-81f8-793fb4a5e58e',\n", - " 'network': {'uuid': '455d6a1a-ca23-4135-b326-3ebf75022a45',\n", - " 'nodes': {'c7c91f06-f128-4891-84a2-83beceea3908': {'uuid': 'c7c91f06-f128-4891-84a2-83beceea3908',\n", - " 'hostname': 'primaite_pc',\n", - " 'operating_state': 0,\n", - " 'NICs': {'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2': {'uuid': 'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2',\n", - " 'ip_adress': '130.1.1.1',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'gateway': '130.1.1.255',\n", - " 'mac_address': 'c3:08:90:23:29:cb',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'wake_on_lan': False,\n", - " 'dns_servers': [],\n", - " 'enabled': False}},\n", - " 'file_system': {'uuid': '04ffd1e8-dea7-47ad-a088-4856df055ed1',\n", - " 'folders': {}},\n", - " 'applications': {},\n", - " 'services': {},\n", - " 'process': {}},\n", - " 'dfcc395a-93ff-4dd5-9684-c80c5885d827': {'uuid': 'dfcc395a-93ff-4dd5-9684-c80c5885d827',\n", - " 'hostname': 'google_server',\n", - " 'operating_state': 0,\n", - " 'NICs': {'1fd281a0-83ae-49d9-9b40-6aae7b465cab': {'uuid': '1fd281a0-83ae-49d9-9b40-6aae7b465cab',\n", - " 'ip_adress': '130.1.1.2',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'gateway': '130.1.1.255',\n", - " 'mac_address': '69:50:cb:76:22:10',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'wake_on_lan': False,\n", - " 'dns_servers': [],\n", - " 'enabled': False}},\n", - " 'file_system': {'uuid': 'aea8f406-05de-4a02-b65f-972aa1fed70e',\n", - " 'folders': {}},\n", - " 'applications': {},\n", - " 'services': {},\n", - " 'process': {}}},\n", - " 'links': {'cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9': {'uuid': 'cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9',\n", - " 'endpoint_a': 'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2',\n", - " 'endpoint_b': '4e6abc87-b4b9-4f95-a9a9-59cac130c6ff',\n", - " 'bandwidth': 100.0,\n", - " 'current_load': 0.0},\n", - " '2dab7fc3-470d-44d2-8593-feb8e96d71ae': {'uuid': '2dab7fc3-470d-44d2-8593-feb8e96d71ae',\n", - " 'endpoint_a': '1fd281a0-83ae-49d9-9b40-6aae7b465cab',\n", - " 'endpoint_b': 'e136553f-333e-4abf-b1f3-ce352ffa4630',\n", - " 'bandwidth': 100.0,\n", - " 'current_load': 0.0}}},\n", - " 'domain': {'uuid': '9da912d5-4c07-4df6-94c2-b3630e178912', 'accounts': {}}}" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_sim.describe_state()" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -249,7 +149,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -259,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -269,16 +169,16 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "FileSystemFile(uuid='3ecf7223-dafd-4973-8c3b-b85af4e177da', name='favicon.ico', size=40.0, file_type=, action_manager=None)" + "FileSystemFile(uuid='253e4606-0f6d-4e57-8db0-6fa7e331ecea', name='favicon.ico', size=40.0, file_type=, action_manager=None)" ] }, - "execution_count": 10, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -297,7 +197,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -305,6 +205,7 @@ "from primaite.simulator.system.software import SoftwareHealthState, SoftwareCriticality\n", "from primaite.simulator.network.transmission.transport_layer import Port\n", "\n", + "# no applications exist yet so we will create our own.\n", "class MSPaint(Application):\n", " def describe_state(self):\n", " return super().describe_state()" @@ -312,7 +213,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -321,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -337,7 +238,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -346,7 +247,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -354,39 +255,46 @@ "my_sim.domain.accounts[acct.uuid] = acct" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Verify that the state dictionary contains no non-serialisable objects." + ] + }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'uuid': 'f0c06262-1bd9-49ee-81f8-793fb4a5e58e',\n", - " 'network': {'uuid': '455d6a1a-ca23-4135-b326-3ebf75022a45',\n", - " 'nodes': {'c7c91f06-f128-4891-84a2-83beceea3908': {'uuid': 'c7c91f06-f128-4891-84a2-83beceea3908',\n", + "{'uuid': '5304ed6d-de4c-408c-ae24-ada32852d196',\n", + " 'network': {'uuid': 'fa17dfe8-81a1-4c7f-8c5b-8c2d3b1e8756',\n", + " 'nodes': {'1fa46446-6681-4e25-a3ba-c4c2cc564630': {'uuid': '1fa46446-6681-4e25-a3ba-c4c2cc564630',\n", " 'hostname': 'primaite_pc',\n", " 'operating_state': 0,\n", - " 'NICs': {'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2': {'uuid': 'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2',\n", + " 'NICs': {'09ca02eb-7733-492c-9eff-f0d6b6ebeeda': {'uuid': '09ca02eb-7733-492c-9eff-f0d6b6ebeeda',\n", " 'ip_adress': '130.1.1.1',\n", " 'subnet_mask': '255.255.255.0',\n", " 'gateway': '130.1.1.255',\n", - " 'mac_address': 'c3:08:90:23:29:cb',\n", + " 'mac_address': '5c:b6:26:c0:86:61',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'wake_on_lan': False,\n", " 'dns_servers': [],\n", " 'enabled': False}},\n", - " 'file_system': {'uuid': '04ffd1e8-dea7-47ad-a088-4856df055ed1',\n", - " 'folders': {'f1fdf2ae-6377-4417-a28a-3edb4058712d': {'uuid': 'f1fdf2ae-6377-4417-a28a-3edb4058712d',\n", + " 'file_system': {'uuid': '8b533e31-04e9-4838-839d-0656ace3e57a',\n", + " 'folders': {'b450c223-872c-4fe0-90cc-9da80973eaad': {'uuid': 'b450c223-872c-4fe0-90cc-9da80973eaad',\n", " 'name': 'downloads',\n", " 'size': 1000.0,\n", - " 'files': {'409b09a3-0d98-4c03-adf2-09190539be45': {'uuid': '409b09a3-0d98-4c03-adf2-09190539be45',\n", + " 'files': {'8160e685-a76f-4171-8a12-3d6b32a9ea16': {'uuid': '8160e685-a76f-4171-8a12-3d6b32a9ea16',\n", " 'name': 'firefox_installer.zip',\n", " 'size': 1000.0,\n", " 'file_type': 'ZIP'}},\n", " 'is_quarantined': False}}},\n", - " 'applications': {'cddee888-d1b9-4289-8512-bc0a6672c880': {'uuid': 'cddee888-d1b9-4289-8512-bc0a6672c880',\n", + " 'applications': {'c82f1064-f35e-466b-88ae-3f61ba0e5161': {'uuid': 'c82f1064-f35e-466b-88ae-3f61ba0e5161',\n", " 'health_state': 'GOOD',\n", " 'health_state_red_view': 'GOOD',\n", " 'criticality': 'MEDIUM',\n", @@ -404,29 +312,29 @@ " 'groups': []}},\n", " 'services': {},\n", " 'process': {}},\n", - " 'dfcc395a-93ff-4dd5-9684-c80c5885d827': {'uuid': 'dfcc395a-93ff-4dd5-9684-c80c5885d827',\n", + " '7f637689-6f91-4026-a685-48a9067f03e8': {'uuid': '7f637689-6f91-4026-a685-48a9067f03e8',\n", " 'hostname': 'google_server',\n", " 'operating_state': 0,\n", - " 'NICs': {'1fd281a0-83ae-49d9-9b40-6aae7b465cab': {'uuid': '1fd281a0-83ae-49d9-9b40-6aae7b465cab',\n", + " 'NICs': {'1abc7272-c516-4463-bd07-1a3cefe39313': {'uuid': '1abc7272-c516-4463-bd07-1a3cefe39313',\n", " 'ip_adress': '130.1.1.2',\n", " 'subnet_mask': '255.255.255.0',\n", " 'gateway': '130.1.1.255',\n", - " 'mac_address': '69:50:cb:76:22:10',\n", + " 'mac_address': 'f6:de:1e:63:8e:7f',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'wake_on_lan': False,\n", " 'dns_servers': [],\n", " 'enabled': False}},\n", - " 'file_system': {'uuid': 'aea8f406-05de-4a02-b65f-972aa1fed70e',\n", - " 'folders': {'beb5b535-cf6c-431d-94f6-d1097910130d': {'uuid': 'beb5b535-cf6c-431d-94f6-d1097910130d',\n", + " 'file_system': {'uuid': 'ac9a6643-8349-4f7a-98c7-a1a9f97ce123',\n", + " 'folders': {'befa5d92-0878-4da2-9dac-f993c0b4a554': {'uuid': 'befa5d92-0878-4da2-9dac-f993c0b4a554',\n", " 'name': 'static',\n", " 'size': 0,\n", " 'files': {},\n", " 'is_quarantined': False},\n", - " '6644cd6c-1eca-4fe4-9313-e3481abb895e': {'uuid': '6644cd6c-1eca-4fe4-9313-e3481abb895e',\n", + " '27383b5e-8884-4ec0-bb50-a5d43e460dfa': {'uuid': '27383b5e-8884-4ec0-bb50-a5d43e460dfa',\n", " 'name': 'root',\n", " 'size': 40.0,\n", - " 'files': {'3ecf7223-dafd-4973-8c3b-b85af4e177da': {'uuid': '3ecf7223-dafd-4973-8c3b-b85af4e177da',\n", + " 'files': {'253e4606-0f6d-4e57-8db0-6fa7e331ecea': {'uuid': '253e4606-0f6d-4e57-8db0-6fa7e331ecea',\n", " 'name': 'favicon.ico',\n", " 'size': 40.0,\n", " 'file_type': 'PNG'}},\n", @@ -434,18 +342,18 @@ " 'applications': {},\n", " 'services': {},\n", " 'process': {}}},\n", - " 'links': {'cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9': {'uuid': 'cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9',\n", - " 'endpoint_a': 'f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2',\n", - " 'endpoint_b': '4e6abc87-b4b9-4f95-a9a9-59cac130c6ff',\n", + " 'links': {'a449b1ff-50d9-4342-861e-44f2d4dfef37': {'uuid': 'a449b1ff-50d9-4342-861e-44f2d4dfef37',\n", + " 'endpoint_a': '09ca02eb-7733-492c-9eff-f0d6b6ebeeda',\n", + " 'endpoint_b': 'ee4557d9-a309-45dd-a6e0-5b572cc70ee5',\n", " 'bandwidth': 100.0,\n", " 'current_load': 0.0},\n", - " '2dab7fc3-470d-44d2-8593-feb8e96d71ae': {'uuid': '2dab7fc3-470d-44d2-8593-feb8e96d71ae',\n", - " 'endpoint_a': '1fd281a0-83ae-49d9-9b40-6aae7b465cab',\n", - " 'endpoint_b': 'e136553f-333e-4abf-b1f3-ce352ffa4630',\n", + " 'ebd7687b-ec69-4f1b-b2ba-86669aa95723': {'uuid': 'ebd7687b-ec69-4f1b-b2ba-86669aa95723',\n", + " 'endpoint_a': '1abc7272-c516-4463-bd07-1a3cefe39313',\n", + " 'endpoint_b': 'dc26b764-a07e-486a-99a4-798c8e0c187a',\n", " 'bandwidth': 100.0,\n", " 'current_load': 0.0}}},\n", - " 'domain': {'uuid': '9da912d5-4c07-4df6-94c2-b3630e178912',\n", - " 'accounts': {'563a1805-0b32-4ba6-9551-e127e5eb57a8': {'uuid': '563a1805-0b32-4ba6-9551-e127e5eb57a8',\n", + " 'domain': {'uuid': '320cbb83-eb1b-4911-a4f0-fc46d8038a8a',\n", + " 'accounts': {'5fdcfb66-84f3-4f0f-a3a7-d0cb0e1a5d51': {'uuid': '5fdcfb66-84f3-4f0f-a3a7-d0cb0e1a5d51',\n", " 'num_logons': 0,\n", " 'num_logoffs': 0,\n", " 'num_group_changes': 0,\n", @@ -455,7 +363,7 @@ " 'enabled': True}}}}" ] }, - "execution_count": 16, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -464,41 +372,25 @@ "my_sim.describe_state()" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Verify that the state dictionary contains no non-serialisable objects." - ] - }, { "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [], - "source": [ - "import json" - ] - }, - { - "cell_type": "code", - "execution_count": 22, + "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'{\"uuid\": \"f0c06262-1bd9-49ee-81f8-793fb4a5e58e\", \"network\": {\"uuid\": \"455d6a1a-ca23-4135-b326-3ebf75022a45\", \"nodes\": {\"c7c91f06-f128-4891-84a2-83beceea3908\": {\"uuid\": \"c7c91f06-f128-4891-84a2-83beceea3908\", \"hostname\": \"primaite_pc\", \"operating_state\": 0, \"NICs\": {\"f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2\": {\"uuid\": \"f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2\", \"ip_adress\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"c3:08:90:23:29:cb\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"04ffd1e8-dea7-47ad-a088-4856df055ed1\", \"folders\": {\"f1fdf2ae-6377-4417-a28a-3edb4058712d\": {\"uuid\": \"f1fdf2ae-6377-4417-a28a-3edb4058712d\", \"name\": \"downloads\", \"size\": 1000.0, \"files\": {\"409b09a3-0d98-4c03-adf2-09190539be45\": {\"uuid\": \"409b09a3-0d98-4c03-adf2-09190539be45\", \"name\": \"firefox_installer.zip\", \"size\": 1000.0, \"file_type\": \"ZIP\"}}, \"is_quarantined\": false}}}, \"applications\": {\"cddee888-d1b9-4289-8512-bc0a6672c880\": {\"uuid\": \"cddee888-d1b9-4289-8512-bc0a6672c880\", \"health_state\": \"GOOD\", \"health_state_red_view\": \"GOOD\", \"criticality\": \"MEDIUM\", \"patching_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 1, \"tcp\": true, \"udp\": true, \"ports\": [\"HTTP\"], \"opearting_state\": \"RUNNING\", \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {}, \"process\": {}}, \"dfcc395a-93ff-4dd5-9684-c80c5885d827\": {\"uuid\": \"dfcc395a-93ff-4dd5-9684-c80c5885d827\", \"hostname\": \"google_server\", \"operating_state\": 0, \"NICs\": {\"1fd281a0-83ae-49d9-9b40-6aae7b465cab\": {\"uuid\": \"1fd281a0-83ae-49d9-9b40-6aae7b465cab\", \"ip_adress\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"69:50:cb:76:22:10\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"aea8f406-05de-4a02-b65f-972aa1fed70e\", \"folders\": {\"beb5b535-cf6c-431d-94f6-d1097910130d\": {\"uuid\": \"beb5b535-cf6c-431d-94f6-d1097910130d\", \"name\": \"static\", \"size\": 0, \"files\": {}, \"is_quarantined\": false}, \"6644cd6c-1eca-4fe4-9313-e3481abb895e\": {\"uuid\": \"6644cd6c-1eca-4fe4-9313-e3481abb895e\", \"name\": \"root\", \"size\": 40.0, \"files\": {\"3ecf7223-dafd-4973-8c3b-b85af4e177da\": {\"uuid\": \"3ecf7223-dafd-4973-8c3b-b85af4e177da\", \"name\": \"favicon.ico\", \"size\": 40.0, \"file_type\": \"PNG\"}}, \"is_quarantined\": false}}}, \"applications\": {}, \"services\": {}, \"process\": {}}}, \"links\": {\"cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9\": {\"uuid\": \"cfbf3c88-c2ac-40f2-9466-a92b99f7cfc9\", \"endpoint_a\": \"f181ea2b-59b6-4724-acf1-a8a7d4e2a1b2\", \"endpoint_b\": \"4e6abc87-b4b9-4f95-a9a9-59cac130c6ff\", \"bandwidth\": 100.0, \"current_load\": 0.0}, \"2dab7fc3-470d-44d2-8593-feb8e96d71ae\": {\"uuid\": \"2dab7fc3-470d-44d2-8593-feb8e96d71ae\", \"endpoint_a\": \"1fd281a0-83ae-49d9-9b40-6aae7b465cab\", \"endpoint_b\": \"e136553f-333e-4abf-b1f3-ce352ffa4630\", \"bandwidth\": 100.0, \"current_load\": 0.0}}}, \"domain\": {\"uuid\": \"9da912d5-4c07-4df6-94c2-b3630e178912\", \"accounts\": {\"563a1805-0b32-4ba6-9551-e127e5eb57a8\": {\"uuid\": \"563a1805-0b32-4ba6-9551-e127e5eb57a8\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": \"USER\", \"enabled\": true}}}}'" + "'{\"uuid\": \"5304ed6d-de4c-408c-ae24-ada32852d196\", \"network\": {\"uuid\": \"fa17dfe8-81a1-4c7f-8c5b-8c2d3b1e8756\", \"nodes\": {\"1fa46446-6681-4e25-a3ba-c4c2cc564630\": {\"uuid\": \"1fa46446-6681-4e25-a3ba-c4c2cc564630\", \"hostname\": \"primaite_pc\", \"operating_state\": 0, \"NICs\": {\"09ca02eb-7733-492c-9eff-f0d6b6ebeeda\": {\"uuid\": \"09ca02eb-7733-492c-9eff-f0d6b6ebeeda\", \"ip_adress\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"5c:b6:26:c0:86:61\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"8b533e31-04e9-4838-839d-0656ace3e57a\", \"folders\": {\"b450c223-872c-4fe0-90cc-9da80973eaad\": {\"uuid\": \"b450c223-872c-4fe0-90cc-9da80973eaad\", \"name\": \"downloads\", \"size\": 1000.0, \"files\": {\"8160e685-a76f-4171-8a12-3d6b32a9ea16\": {\"uuid\": \"8160e685-a76f-4171-8a12-3d6b32a9ea16\", \"name\": \"firefox_installer.zip\", \"size\": 1000.0, \"file_type\": \"ZIP\"}}, \"is_quarantined\": false}}}, \"applications\": {\"c82f1064-f35e-466b-88ae-3f61ba0e5161\": {\"uuid\": \"c82f1064-f35e-466b-88ae-3f61ba0e5161\", \"health_state\": \"GOOD\", \"health_state_red_view\": \"GOOD\", \"criticality\": \"MEDIUM\", \"patching_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 1, \"tcp\": true, \"udp\": true, \"ports\": [\"HTTP\"], \"opearting_state\": \"RUNNING\", \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {}, \"process\": {}}, \"7f637689-6f91-4026-a685-48a9067f03e8\": {\"uuid\": \"7f637689-6f91-4026-a685-48a9067f03e8\", \"hostname\": \"google_server\", \"operating_state\": 0, \"NICs\": {\"1abc7272-c516-4463-bd07-1a3cefe39313\": {\"uuid\": \"1abc7272-c516-4463-bd07-1a3cefe39313\", \"ip_adress\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"f6:de:1e:63:8e:7f\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"ac9a6643-8349-4f7a-98c7-a1a9f97ce123\", \"folders\": {\"befa5d92-0878-4da2-9dac-f993c0b4a554\": {\"uuid\": \"befa5d92-0878-4da2-9dac-f993c0b4a554\", \"name\": \"static\", \"size\": 0, \"files\": {}, \"is_quarantined\": false}, \"27383b5e-8884-4ec0-bb50-a5d43e460dfa\": {\"uuid\": \"27383b5e-8884-4ec0-bb50-a5d43e460dfa\", \"name\": \"root\", \"size\": 40.0, \"files\": {\"253e4606-0f6d-4e57-8db0-6fa7e331ecea\": {\"uuid\": \"253e4606-0f6d-4e57-8db0-6fa7e331ecea\", \"name\": \"favicon.ico\", \"size\": 40.0, \"file_type\": \"PNG\"}}, \"is_quarantined\": false}}}, \"applications\": {}, \"services\": {}, \"process\": {}}}, \"links\": {\"a449b1ff-50d9-4342-861e-44f2d4dfef37\": {\"uuid\": \"a449b1ff-50d9-4342-861e-44f2d4dfef37\", \"endpoint_a\": \"09ca02eb-7733-492c-9eff-f0d6b6ebeeda\", \"endpoint_b\": \"ee4557d9-a309-45dd-a6e0-5b572cc70ee5\", \"bandwidth\": 100.0, \"current_load\": 0.0}, \"ebd7687b-ec69-4f1b-b2ba-86669aa95723\": {\"uuid\": \"ebd7687b-ec69-4f1b-b2ba-86669aa95723\", \"endpoint_a\": \"1abc7272-c516-4463-bd07-1a3cefe39313\", \"endpoint_b\": \"dc26b764-a07e-486a-99a4-798c8e0c187a\", \"bandwidth\": 100.0, \"current_load\": 0.0}}}, \"domain\": {\"uuid\": \"320cbb83-eb1b-4911-a4f0-fc46d8038a8a\", \"accounts\": {\"5fdcfb66-84f3-4f0f-a3a7-d0cb0e1a5d51\": {\"uuid\": \"5fdcfb66-84f3-4f0f-a3a7-d0cb0e1a5d51\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": \"USER\", \"enabled\": true}}}}'" ] }, - "execution_count": 22, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "d = my_sim.describe_state()\n", - "json.dumps(d)" + "import json\n", + "json.dumps(my_sim.describe_state())" ] } ], From a0b258a597bbcc71fe9f2c689a6a268d3de1aeff Mon Sep 17 00:00:00 2001 From: SunilSamra Date: Mon, 21 Aug 2023 09:02:04 +0100 Subject: [PATCH 104/980] #1752 - Added a dns_lookup function to dns_server.py --- .../simulator/system/services/dns_server.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/system/services/dns_server.py b/src/primaite/simulator/system/services/dns_server.py index 7eed51b5..fe9a6123 100644 --- a/src/primaite/simulator/system/services/dns_server.py +++ b/src/primaite/simulator/system/services/dns_server.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import Any, Dict, List +from ipaddress import IPv4Address +from typing import Any, Dict, List, Optional from pydantic import BaseModel @@ -7,7 +8,8 @@ from pydantic import BaseModel class DNSServer(BaseModel): """Represents a DNS Server as a Service.""" - dns_table: dict[str:str] = {} + dns_table: dict[str:IPv4Address] = {} + "A dict of mappings between domain names and IPv4 addresses." @abstractmethod def describe_state(self) -> Dict: @@ -30,6 +32,18 @@ class DNSServer(BaseModel): """ pass + def dns_lookup(self, target_domain: str) -> Optional[IPv4Address]: + """ + Attempts to find the IP address for a domain name. + + :param target_domain: The single domain name requested by a DNS client. + :return ip_address: The IP address of that domain name or None. + """ + if target_domain in self.dns_table: + return self.dns_table[target_domain] + else: + return None + def reset_component_for_episode(self): """ Resets the Service component for a new episode. From 07b740a81e9872a62aa3326520fa50421c2c6186 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 21 Aug 2023 09:49:31 +0100 Subject: [PATCH 105/980] Update docs and changelog. --- CHANGELOG.md | 2 ++ docs/_static/component_relationship.png | Bin 0 -> 82446 bytes docs/source/simulation_structure.rst | 14 +++++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 docs/_static/component_relationship.png diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f3f57fb..2b495c09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ a Service/Application another machine. SessionManager. - Permission System - each action can define criteria that will be used to permit or deny agent actions. - File System - ability to emulate a node's file system during a simulation +- Example notebooks - There is currently 1 jupyter notebook which walks through using PrimAITE + 1. Creating a simulation - this notebook explains how to build up a simulation using the Python package. (WIP) ## [2.0.0] - 2023-07-26 diff --git a/docs/_static/component_relationship.png b/docs/_static/component_relationship.png new file mode 100644 index 0000000000000000000000000000000000000000..c2dd1102d203e7f99081dc1e0f953729aaa2e314 GIT binary patch literal 82446 zcmeFacT|&E*Ebvn+t?5kL8T2AtRRC*FDi;k6B{5^P*9OxLJy9kfT|8aoZz34lol{Z?badwR1BBDJb)3%Mw z3BZ-$Mv^o+gNAo+HaB0Z?`*h7d;z1Ke`!fRd>C=~=uy`==DG%w+*vb$@*O4Z>%v>q z)|urv%8lpo&3_VuDgFK2fu_l=J9dN-Et#)G741C2JGh6KdVHP}E7FGxcv4G#einmS zct$xxIyHZEH0q4{W(q^~0N>5_cAF`zv3AY$3h|QY<9jt~ zTqkam(TNl017p98J7{&o)9mcl$YZE%0OI8c=WY)N}ze-x0zweh1#fvCt1i0EvJr52}w>>PJ zFZ*Bqc3(5la`tcC-Q5RTU=RIxjXx_?yKkbgOJmycjh9Q*g}Pka1pji0u_{JS>(f7=?Dk33yAZ|QsB=MTH<>OQT);1w<;CeFId zKVkRsZCNw_nT5^mzPl}_nrgiZ`zu@X9sQnG@!{Q9zb@A?HNE7|%rGp=l}}h^u@Zx+ zGdwWA+mB2Aj0IvRX}p?Oq}*-WbJ` zvgkHrLOI0}UF|TfT))1vQ%Il_8*U8-cwT+<`VU`du&Jt~;MvAi-@auex>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GujF~dZ|14y{_9?A zgNONCn_={$s(aX$MceESW@laxxnggfya0@2gd5nAYIaZkiZd;A#IIn{LQniRj354r zGyRG){l6V&VlTJ0#S69)`wQSecozrlaY$pN@w&)-jQ fzG`cUb-rZl@bC9f*IP0jJC#!!CsU4Jy!k%>I}r$L literal 0 HcmV?d00001 diff --git a/docs/source/simulation_structure.rst b/docs/source/simulation_structure.rst index 2b213f16..7630ae0f 100644 --- a/docs/source/simulation_structure.rst +++ b/docs/source/simulation_structure.rst @@ -7,11 +7,19 @@ Simulation Structure ==================== The simulation is made up of many smaller components which are related to each other in a tree-like structure. At the -top level, there is an object called the ``SimulationController`` _(doesn't exist yet)_, which has a physical network -and a software controller for managing software and users. +top level, there is the :py:meth:`primaite.simulator.sim_container.Simulation`, which keeps track of the physical network +and a domain controller for managing software and users. -Each node of the simulation 'tree' has responsibility for creating, deleting, and updating its direct descendants. +Each node of the simulation 'tree' has responsibility for creating, deleting, and updating its direct descendants. Also, +when a component's ``describe_state()`` method is called, it will include the state of its descendants. The +``apply_action()`` method can be used to act on a component or one of its descendatnts. The diagram below shows the +relationship between components. +.. image:: _static/component_relationship.png + :width: 500 + :alt: The top level simulation object owns a NetworkContainer and a DomainController. The DomainController has a + list of accounts. The network container has links and nodes. Nodes can own switchports, NICs, FileSystem, + Application, Service, and Process. Actions From 7e64acd36840363be507ea36924d4eeb93f2a07e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 21 Aug 2023 10:04:23 +0100 Subject: [PATCH 106/980] Update container docstrings --- src/primaite/simulator/network/container.py | 3 ++- src/primaite/simulator/sim_container.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 463d5f91..f89ed2d3 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -5,12 +5,13 @@ from primaite.simulator.network.hardware.base import Link, Node class NetworkContainer(SimComponent): - """TODO.""" + """Top level container object representing the physical network.""" nodes: Dict[str, Node] = {} links: Dict[str, Link] = {} def __init__(self, **kwargs): + """Initialise the network.""" super().__init__(**kwargs) self.action_manager = ActionManager() diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index 1a37dc18..50fe412c 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -6,12 +6,13 @@ from primaite.simulator.network.container import NetworkContainer class Simulation(SimComponent): - """TODO.""" + """Top-level simulation object which holds a reference to all other parts of the simulation.""" network: NetworkContainer domain: DomainController def __init__(self, **kwargs): + """Initialise the Simulation.""" if not kwargs.get("network"): kwargs["network"] = NetworkContainer() From 1a13af2f5ec563b5060478bc00c9148105fe5fff Mon Sep 17 00:00:00 2001 From: SunilSamra Date: Mon, 21 Aug 2023 14:11:53 +0100 Subject: [PATCH 107/980] #1752 - Changed DNSReply and DNSResponse to have 1 parameter only --- .../simulator/network/protocols/dns.py | 62 ++----------------- .../network/transmission/data_link_layer.py | 3 + .../simulator/system/services/dns_client.py | 22 +++++-- .../simulator/system/services/dns_server.py | 21 +++++-- 4 files changed, 41 insertions(+), 67 deletions(-) diff --git a/src/primaite/simulator/network/protocols/dns.py b/src/primaite/simulator/network/protocols/dns.py index b8f0d8bd..0afa6405 100644 --- a/src/primaite/simulator/network/protocols/dns.py +++ b/src/primaite/simulator/network/protocols/dns.py @@ -5,38 +5,13 @@ from typing import Optional from pydantic import BaseModel -""" -class DNSEntry(BaseModel): - - Represents an entry in the DNS cache. - - :param domain_name: The domain name which a node would like to access. - :param ip_address: The IP address through which the domain name is reachable. - - - domain_name: str - ip_address: IPv4Address -""" - class DNSRequest(BaseModel): """Represents a DNS Request packet of a network frame. - :param sender_mac_addr: Sender MAC address. - :param sender_ip: Sender IP address. - :param target_mac_addr: Target MAC address. - :param target_ip: Target IP address. :param domain_name_request: Domain Name Request for IP address. """ - sender_mac_addr: str - "Sender MAC address." - sender_ip: IPv4Address - "Sender IP address." - target_mac_addr: Optional[str] = None - "Target MAC address of the DNS Server." - target_ip: IPv4Address - "Target IP address of the DNS Server." domain_name_request: str "Domain Name Request for IP address." @@ -44,21 +19,9 @@ class DNSRequest(BaseModel): class DNSReply(BaseModel): """Represents a DNS Reply packet of a network frame. - :param sender_mac_addr: Sender MAC address. - :param sender_ip: Sender IP address. - :param target_mac_addr: Target MAC address of DNS Client. - :param target_ip: Target IP address of DNS Client. :param domain_name_ip_address: IP Address of the Domain Name requested. """ - sender_mac_addr: str - "Sender MAC address." - sender_ip: IPv4Address - "Sender IP address." - target_mac_addr: Optional[str] = None - "Target MAC address of the DNS Server." - target_ip: IPv4Address - "Target IP address of the DNS Server." domain_name_ip_address: IPv4Address "IP Address of the Domain Name requested." @@ -73,15 +36,12 @@ class DNSPacket(BaseModel): :Example: >>> dns_request = DNSPacket( - ... dns_request=DNSRequest(sender_mac_addr="aa:bb:cc:dd:ee:ff", sender_ip = IPv4Address("192.168.0.1"), - ... target_ip = IPv4Address("192.168.0.2"), domain_name_request="www.google.co.uk"), + ... domain_name_request=DNSRequest(domain_name_request="www.google.co.uk"), ... dns_reply=None ... ) >>> dns_response = DNSPacket( - ... dns_request=DNSRequest(sender_mac_addr="aa:bb:cc:dd:ee:ff", sender_ip = IPv4Address("192.168.0.1"), - ... target_ip = IPv4Address("192.168.0.2"), domain_name_request="www.google.co.uk"), - ... dns_reply=DNSReply(sender_mac_addr="gg:hh:ii:jj:kk:ll", sender_ip = IPv4Address("192.168.0.2"), - ... target_ip = IPv4Address("192.168.0.1"), domain_name_ip_address=IPv4Address("142.250.179.227")) + ... dns_request=DNSRequest(domain_name_request="www.google.co.uk"), + ... dns_reply=DNSReply(domain_name_ip_address=IPv4Address("142.250.179.227")) ... ) """ @@ -97,18 +57,6 @@ class DNSPacket(BaseModel): :return: A new instance of DNSPacket. """ return DNSPacket( - dns_request=DNSRequest( - sender_mac_addr=self.dns_request.sender_mac_addr, - sender_ip=self.dns_request.sender_ip, - target_mac_addr=self.dns_request.target_mac_addr, - target_ip=self.dns_request.target_ip, - domain_name_request=self.dns_request.domain_name_request, - ), - dns_reply=DNSReply( - sender_mac_addr=self.dns_request.target_mac_addr, - sender_ip=self.dns_request.target_ip, - target_mac_addr=self.dns_request.sender_mac_addr, - target_ip=self.dns_request.sender_ip, - domain_name_ip_address=domain_ip_address, - ), + dns_request=DNSRequest(domain_name_request=self.dns_request.domain_name_request), + dns_reply=DNSReply(domain_name_ip_address=domain_ip_address), ) diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index 1b7ccf7d..e01b8d2e 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -5,6 +5,7 @@ from pydantic import BaseModel from primaite import getLogger from primaite.simulator.network.protocols.arp import ARPPacket +from primaite.simulator.network.protocols.dns import DNSPacket from primaite.simulator.network.transmission.network_layer import ICMPPacket, IPPacket, IPProtocol from primaite.simulator.network.transmission.primaite_layer import PrimaiteHeader from primaite.simulator.network.transmission.transport_layer import TCPHeader, UDPHeader @@ -96,6 +97,8 @@ class Frame(BaseModel): "ICMP header." arp: Optional[ARPPacket] = None "ARP packet." + dns: Optional[DNSPacket] = None + "DNS packet." primaite: PrimaiteHeader "PrimAITE header." payload: Optional[Any] = None diff --git a/src/primaite/simulator/system/services/dns_client.py b/src/primaite/simulator/system/services/dns_client.py index 7b080244..ce4a9150 100644 --- a/src/primaite/simulator/system/services/dns_client.py +++ b/src/primaite/simulator/system/services/dns_client.py @@ -4,14 +4,14 @@ from typing import Any, Dict, List from pydantic import BaseModel +from primaite.simulator.network.protocols.dns import DNSPacket, DNSRequest + class DNSClient(BaseModel): """Represents a DNS Client as a Service.""" - target_url: str - "The URL/domain name the client requests the IP for." dns_cache: Dict[str:IPv4Address] = {} - "A dict of known mappings between domain names and IPv4 addresses." + "A dict of known mappings between domain/URLs names and IPv4 addresses." @abstractmethod def describe_state(self) -> Dict: @@ -41,9 +41,16 @@ class DNSClient(BaseModel): This method ensures the Service is ready for a new episode, including resetting any stateful properties or statistics, and clearing any message queues. """ - self.target_url = "" self.dns_cache = {} + def check_domain_is_in_cache(self, target_domain: str, session_id: str): + """Function to check if domain name is in DNS client cache.""" + if target_domain in self.dns_cache: + ip_address = self.dns_cache[target_domain] + self.send(ip_address, session_id) + else: + self.send(target_domain, session_id) + def send(self, payload: Any, session_id: str, **kwargs) -> bool: """ Sends a payload to the SessionManager. @@ -54,7 +61,7 @@ class DNSClient(BaseModel): :param payload: The payload to send. :return: True if successful, False otherwise. """ - pass + DNSPacket(dns_request=DNSRequest(domain_name_request=payload), dns_reply=None) def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ @@ -63,7 +70,10 @@ class DNSClient(BaseModel): The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. - :param payload: The payload to receive. + :param payload: The payload to receive. (receive a DNS packet with dns request and dns reply in, send to web + browser) :return: True if successful, False otherwise. """ + # check DNS packet (dns request, dns reply) here and see if it actually worked + pass diff --git a/src/primaite/simulator/system/services/dns_server.py b/src/primaite/simulator/system/services/dns_server.py index fe9a6123..7ad3bac1 100644 --- a/src/primaite/simulator/system/services/dns_server.py +++ b/src/primaite/simulator/system/services/dns_server.py @@ -4,6 +4,8 @@ from typing import Any, Dict, List, Optional from pydantic import BaseModel +from primaite.simulator.network.protocols.dns import DNSPacket, DNSReply, DNSRequest + class DNSServer(BaseModel): """Represents a DNS Server as a Service.""" @@ -28,7 +30,7 @@ class DNSServer(BaseModel): """ Applies a list of actions to the Service. - :param action: A list of actions to apply. + :param action: A list of actions to apply. (unsure) """ pass @@ -63,7 +65,13 @@ class DNSServer(BaseModel): :param payload: The payload to send. :return: True if successful, False otherwise. """ - pass + ip_addresses = list(self.dns_table.values()) + domain_names = list(self.dns_table.keys()) + index_of_domain = ip_addresses.index(payload) + DNSPacket( + dns_request=DNSRequest(domain_name_request=domain_names[index_of_domain]), + dns_reply=DNSReply(domain_name_ip_address=payload), + ) def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ @@ -72,7 +80,12 @@ class DNSServer(BaseModel): The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. - :param payload: The payload to receive. + :param payload: The payload to receive. (take the domain name and do dns lookup) :return: True if successful, False otherwise. """ - pass + ip_address = self.dns_lookup(payload) + if ip_address is not None: + self.send(ip_address, session_id) + return True + + return False From 550b62f75dc7b5bf29d43808feaf2b62687f0010 Mon Sep 17 00:00:00 2001 From: SunilSamra Date: Mon, 21 Aug 2023 16:09:17 +0100 Subject: [PATCH 108/980] #1752 - Removed unnecessary print statement - Changed docstring on function check_domain_in_cache --- src/primaite/simulator/system/services/dns_client.py | 8 ++++++-- tests/test_seeding_and_deterministic_session.py | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/primaite/simulator/system/services/dns_client.py b/src/primaite/simulator/system/services/dns_client.py index ce4a9150..f99411d2 100644 --- a/src/primaite/simulator/system/services/dns_client.py +++ b/src/primaite/simulator/system/services/dns_client.py @@ -43,8 +43,12 @@ class DNSClient(BaseModel): """ self.dns_cache = {} - def check_domain_is_in_cache(self, target_domain: str, session_id: str): - """Function to check if domain name is in DNS client cache.""" + def check_domain_in_cache(self, target_domain: str, session_id: str): + """Function to check if domain name is in DNS client cache. + + :param target_domain: The domain requested for an IP address. + :param session_id: The ID of the session in order to send the response to the DNS server or application. + """ if target_domain in self.dns_cache: ip_address = self.dns_cache[target_domain] self.send(ip_address, session_id) diff --git a/tests/test_seeding_and_deterministic_session.py b/tests/test_seeding_and_deterministic_session.py index 9500c4a3..aff5496a 100644 --- a/tests/test_seeding_and_deterministic_session.py +++ b/tests/test_seeding_and_deterministic_session.py @@ -45,7 +45,6 @@ def test_seeded_learning(temp_primaite_session): ), "Expected output is based upon a agent that was trained with seed 67890" session.learn() actual_mean_reward_per_episode = session.learn_av_reward_per_episode_dict() - print(actual_mean_reward_per_episode, "THISt") assert actual_mean_reward_per_episode == expected_mean_reward_per_episode From c1ba3b0850e35306b80ee48de430ff472a316caa Mon Sep 17 00:00:00 2001 From: SunilSamra Date: Tue, 22 Aug 2023 21:43:57 +0100 Subject: [PATCH 109/980] #1752 - Added comments to ticket --- src/primaite/simulator/system/services/dns_client.py | 3 +-- src/primaite/simulator/system/services/dns_server.py | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/primaite/simulator/system/services/dns_client.py b/src/primaite/simulator/system/services/dns_client.py index f99411d2..97968407 100644 --- a/src/primaite/simulator/system/services/dns_client.py +++ b/src/primaite/simulator/system/services/dns_client.py @@ -78,6 +78,5 @@ class DNSClient(BaseModel): browser) :return: True if successful, False otherwise. """ - # check DNS packet (dns request, dns reply) here and see if it actually worked - + # check the DNS packet (dns request, dns reply) here and see if it actually worked pass diff --git a/src/primaite/simulator/system/services/dns_server.py b/src/primaite/simulator/system/services/dns_server.py index 7ad3bac1..a2eaf9d9 100644 --- a/src/primaite/simulator/system/services/dns_server.py +++ b/src/primaite/simulator/system/services/dns_server.py @@ -42,7 +42,7 @@ class DNSServer(BaseModel): :return ip_address: The IP address of that domain name or None. """ if target_domain in self.dns_table: - return self.dns_table[target_domain] + self.dns_table[target_domain] else: return None @@ -65,11 +65,9 @@ class DNSServer(BaseModel): :param payload: The payload to send. :return: True if successful, False otherwise. """ - ip_addresses = list(self.dns_table.values()) - domain_names = list(self.dns_table.keys()) - index_of_domain = ip_addresses.index(payload) + # DNS packet will be sent from DNS Server to the DNS client DNSPacket( - dns_request=DNSRequest(domain_name_request=domain_names[index_of_domain]), + dns_request=DNSRequest(domain_name_request=self.dns_table), dns_reply=DNSReply(domain_name_ip_address=payload), ) From 1613bbe27afece0621614b1931daae38848c24e4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 23 Aug 2023 14:41:30 +0100 Subject: [PATCH 110/980] Add methods for adding/removing nodes form network --- .../notebooks/create-simulation.ipynb | 200 +++--------------- src/primaite/simulator/core.py | 22 ++ src/primaite/simulator/network/container.py | 47 +++- 3 files changed, 93 insertions(+), 176 deletions(-) diff --git a/src/primaite/notebooks/create-simulation.ipynb b/src/primaite/notebooks/create-simulation.ipynb index b0a140a1..11d41356 100644 --- a/src/primaite/notebooks/create-simulation.ipynb +++ b/src/primaite/notebooks/create-simulation.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -36,26 +36,12 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'uuid': '5304ed6d-de4c-408c-ae24-ada32852d196',\n", - " 'network': {'uuid': 'fa17dfe8-81a1-4c7f-8c5b-8c2d3b1e8756',\n", - " 'nodes': {},\n", - " 'links': {}},\n", - " 'domain': {'uuid': '320cbb83-eb1b-4911-a4f0-fc46d8038a8a', 'accounts': {}}}" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_sim = Simulation()\n", + "net = my_sim.network\n", "my_sim.describe_state()" ] }, @@ -68,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -77,17 +63,14 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "my_pc = Node(hostname=\"primaite_pc\",)\n", + "net.add_node(my_pc)\n", "my_server = Node(hostname=\"google_server\")\n", - "\n", - "# TODO: when there is a proper function for adding nodes, use it instead of manually adding.\n", - "\n", - "my_sim.network.nodes[my_pc.uuid] = my_pc\n", - "my_sim.network.nodes[my_server.uuid] = my_server\n" + "net.add_node(my_server)\n" ] }, { @@ -99,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -108,22 +91,12 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-08-20 18:42:51,310: NIC 5c:b6:26:c0:86:61/130.1.1.1 connected to Link 5c:b6:26:c0:86:61/130.1.1.1<-->01:ef:b1:a3:24:72\n", - "2023-08-20 18:42:51,311: SwitchPort 01:ef:b1:a3:24:72 connected to Link 5c:b6:26:c0:86:61/130.1.1.1<-->01:ef:b1:a3:24:72\n", - "2023-08-20 18:42:51,314: NIC f6:de:1e:63:8e:7f/130.1.1.2 connected to Link f6:de:1e:63:8e:7f/130.1.1.2<-->30:9e:c8:d4:5d:f3\n", - "2023-08-20 18:42:51,315: SwitchPort 30:9e:c8:d4:5d:f3 connected to Link f6:de:1e:63:8e:7f/130.1.1.2<-->30:9e:c8:d4:5d:f3\n" - ] - } - ], + "outputs": [], "source": [ "my_swtich = Switch(hostname=\"switch1\", num_ports=12)\n", + "net.add_node(my_swtich)\n", "\n", "pc_nic = NIC(ip_address=\"130.1.1.1\", gateway=\"130.1.1.255\", subnet_mask=\"255.255.255.0\")\n", "my_pc.connect_nic(pc_nic)\n", @@ -149,7 +122,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -159,7 +132,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -169,20 +142,9 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "FileSystemFile(uuid='253e4606-0f6d-4e57-8db0-6fa7e331ecea', name='favicon.ico', size=40.0, file_type=, action_manager=None)" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_server_folder = my_server.file_system.create_folder(\"static\")\n", "my_server.file_system.create_file(\"favicon.ico\", file_type=FileSystemFileType.PNG)" @@ -197,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -213,7 +175,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -222,7 +184,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -238,7 +200,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -247,7 +209,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -264,130 +226,18 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'uuid': '5304ed6d-de4c-408c-ae24-ada32852d196',\n", - " 'network': {'uuid': 'fa17dfe8-81a1-4c7f-8c5b-8c2d3b1e8756',\n", - " 'nodes': {'1fa46446-6681-4e25-a3ba-c4c2cc564630': {'uuid': '1fa46446-6681-4e25-a3ba-c4c2cc564630',\n", - " 'hostname': 'primaite_pc',\n", - " 'operating_state': 0,\n", - " 'NICs': {'09ca02eb-7733-492c-9eff-f0d6b6ebeeda': {'uuid': '09ca02eb-7733-492c-9eff-f0d6b6ebeeda',\n", - " 'ip_adress': '130.1.1.1',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'gateway': '130.1.1.255',\n", - " 'mac_address': '5c:b6:26:c0:86:61',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'wake_on_lan': False,\n", - " 'dns_servers': [],\n", - " 'enabled': False}},\n", - " 'file_system': {'uuid': '8b533e31-04e9-4838-839d-0656ace3e57a',\n", - " 'folders': {'b450c223-872c-4fe0-90cc-9da80973eaad': {'uuid': 'b450c223-872c-4fe0-90cc-9da80973eaad',\n", - " 'name': 'downloads',\n", - " 'size': 1000.0,\n", - " 'files': {'8160e685-a76f-4171-8a12-3d6b32a9ea16': {'uuid': '8160e685-a76f-4171-8a12-3d6b32a9ea16',\n", - " 'name': 'firefox_installer.zip',\n", - " 'size': 1000.0,\n", - " 'file_type': 'ZIP'}},\n", - " 'is_quarantined': False}}},\n", - " 'applications': {'c82f1064-f35e-466b-88ae-3f61ba0e5161': {'uuid': 'c82f1064-f35e-466b-88ae-3f61ba0e5161',\n", - " 'health_state': 'GOOD',\n", - " 'health_state_red_view': 'GOOD',\n", - " 'criticality': 'MEDIUM',\n", - " 'patching_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 1,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'ports': ['HTTP'],\n", - " 'opearting_state': 'RUNNING',\n", - " 'execution_control_status': 'manual',\n", - " 'num_executions': 0,\n", - " 'groups': []}},\n", - " 'services': {},\n", - " 'process': {}},\n", - " '7f637689-6f91-4026-a685-48a9067f03e8': {'uuid': '7f637689-6f91-4026-a685-48a9067f03e8',\n", - " 'hostname': 'google_server',\n", - " 'operating_state': 0,\n", - " 'NICs': {'1abc7272-c516-4463-bd07-1a3cefe39313': {'uuid': '1abc7272-c516-4463-bd07-1a3cefe39313',\n", - " 'ip_adress': '130.1.1.2',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'gateway': '130.1.1.255',\n", - " 'mac_address': 'f6:de:1e:63:8e:7f',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'wake_on_lan': False,\n", - " 'dns_servers': [],\n", - " 'enabled': False}},\n", - " 'file_system': {'uuid': 'ac9a6643-8349-4f7a-98c7-a1a9f97ce123',\n", - " 'folders': {'befa5d92-0878-4da2-9dac-f993c0b4a554': {'uuid': 'befa5d92-0878-4da2-9dac-f993c0b4a554',\n", - " 'name': 'static',\n", - " 'size': 0,\n", - " 'files': {},\n", - " 'is_quarantined': False},\n", - " '27383b5e-8884-4ec0-bb50-a5d43e460dfa': {'uuid': '27383b5e-8884-4ec0-bb50-a5d43e460dfa',\n", - " 'name': 'root',\n", - " 'size': 40.0,\n", - " 'files': {'253e4606-0f6d-4e57-8db0-6fa7e331ecea': {'uuid': '253e4606-0f6d-4e57-8db0-6fa7e331ecea',\n", - " 'name': 'favicon.ico',\n", - " 'size': 40.0,\n", - " 'file_type': 'PNG'}},\n", - " 'is_quarantined': False}}},\n", - " 'applications': {},\n", - " 'services': {},\n", - " 'process': {}}},\n", - " 'links': {'a449b1ff-50d9-4342-861e-44f2d4dfef37': {'uuid': 'a449b1ff-50d9-4342-861e-44f2d4dfef37',\n", - " 'endpoint_a': '09ca02eb-7733-492c-9eff-f0d6b6ebeeda',\n", - " 'endpoint_b': 'ee4557d9-a309-45dd-a6e0-5b572cc70ee5',\n", - " 'bandwidth': 100.0,\n", - " 'current_load': 0.0},\n", - " 'ebd7687b-ec69-4f1b-b2ba-86669aa95723': {'uuid': 'ebd7687b-ec69-4f1b-b2ba-86669aa95723',\n", - " 'endpoint_a': '1abc7272-c516-4463-bd07-1a3cefe39313',\n", - " 'endpoint_b': 'dc26b764-a07e-486a-99a4-798c8e0c187a',\n", - " 'bandwidth': 100.0,\n", - " 'current_load': 0.0}}},\n", - " 'domain': {'uuid': '320cbb83-eb1b-4911-a4f0-fc46d8038a8a',\n", - " 'accounts': {'5fdcfb66-84f3-4f0f-a3a7-d0cb0e1a5d51': {'uuid': '5fdcfb66-84f3-4f0f-a3a7-d0cb0e1a5d51',\n", - " 'num_logons': 0,\n", - " 'num_logoffs': 0,\n", - " 'num_group_changes': 0,\n", - " 'username': 'admin',\n", - " 'password': 'admin12',\n", - " 'account_type': 'USER',\n", - " 'enabled': True}}}}" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_sim.describe_state()" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'{\"uuid\": \"5304ed6d-de4c-408c-ae24-ada32852d196\", \"network\": {\"uuid\": \"fa17dfe8-81a1-4c7f-8c5b-8c2d3b1e8756\", \"nodes\": {\"1fa46446-6681-4e25-a3ba-c4c2cc564630\": {\"uuid\": \"1fa46446-6681-4e25-a3ba-c4c2cc564630\", \"hostname\": \"primaite_pc\", \"operating_state\": 0, \"NICs\": {\"09ca02eb-7733-492c-9eff-f0d6b6ebeeda\": {\"uuid\": \"09ca02eb-7733-492c-9eff-f0d6b6ebeeda\", \"ip_adress\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"5c:b6:26:c0:86:61\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"8b533e31-04e9-4838-839d-0656ace3e57a\", \"folders\": {\"b450c223-872c-4fe0-90cc-9da80973eaad\": {\"uuid\": \"b450c223-872c-4fe0-90cc-9da80973eaad\", \"name\": \"downloads\", \"size\": 1000.0, \"files\": {\"8160e685-a76f-4171-8a12-3d6b32a9ea16\": {\"uuid\": \"8160e685-a76f-4171-8a12-3d6b32a9ea16\", \"name\": \"firefox_installer.zip\", \"size\": 1000.0, \"file_type\": \"ZIP\"}}, \"is_quarantined\": false}}}, \"applications\": {\"c82f1064-f35e-466b-88ae-3f61ba0e5161\": {\"uuid\": \"c82f1064-f35e-466b-88ae-3f61ba0e5161\", \"health_state\": \"GOOD\", \"health_state_red_view\": \"GOOD\", \"criticality\": \"MEDIUM\", \"patching_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 1, \"tcp\": true, \"udp\": true, \"ports\": [\"HTTP\"], \"opearting_state\": \"RUNNING\", \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {}, \"process\": {}}, \"7f637689-6f91-4026-a685-48a9067f03e8\": {\"uuid\": \"7f637689-6f91-4026-a685-48a9067f03e8\", \"hostname\": \"google_server\", \"operating_state\": 0, \"NICs\": {\"1abc7272-c516-4463-bd07-1a3cefe39313\": {\"uuid\": \"1abc7272-c516-4463-bd07-1a3cefe39313\", \"ip_adress\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"f6:de:1e:63:8e:7f\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"ac9a6643-8349-4f7a-98c7-a1a9f97ce123\", \"folders\": {\"befa5d92-0878-4da2-9dac-f993c0b4a554\": {\"uuid\": \"befa5d92-0878-4da2-9dac-f993c0b4a554\", \"name\": \"static\", \"size\": 0, \"files\": {}, \"is_quarantined\": false}, \"27383b5e-8884-4ec0-bb50-a5d43e460dfa\": {\"uuid\": \"27383b5e-8884-4ec0-bb50-a5d43e460dfa\", \"name\": \"root\", \"size\": 40.0, \"files\": {\"253e4606-0f6d-4e57-8db0-6fa7e331ecea\": {\"uuid\": \"253e4606-0f6d-4e57-8db0-6fa7e331ecea\", \"name\": \"favicon.ico\", \"size\": 40.0, \"file_type\": \"PNG\"}}, \"is_quarantined\": false}}}, \"applications\": {}, \"services\": {}, \"process\": {}}}, \"links\": {\"a449b1ff-50d9-4342-861e-44f2d4dfef37\": {\"uuid\": \"a449b1ff-50d9-4342-861e-44f2d4dfef37\", \"endpoint_a\": \"09ca02eb-7733-492c-9eff-f0d6b6ebeeda\", \"endpoint_b\": \"ee4557d9-a309-45dd-a6e0-5b572cc70ee5\", \"bandwidth\": 100.0, \"current_load\": 0.0}, \"ebd7687b-ec69-4f1b-b2ba-86669aa95723\": {\"uuid\": \"ebd7687b-ec69-4f1b-b2ba-86669aa95723\", \"endpoint_a\": \"1abc7272-c516-4463-bd07-1a3cefe39313\", \"endpoint_b\": \"dc26b764-a07e-486a-99a4-798c8e0c187a\", \"bandwidth\": 100.0, \"current_load\": 0.0}}}, \"domain\": {\"uuid\": \"320cbb83-eb1b-4911-a4f0-fc46d8038a8a\", \"accounts\": {\"5fdcfb66-84f3-4f0f-a3a7-d0cb0e1a5d51\": {\"uuid\": \"5fdcfb66-84f3-4f0f-a3a7-d0cb0e1a5d51\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": \"USER\", \"enabled\": true}}}}'" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import json\n", "json.dumps(my_sim.describe_state())" diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 2c802c0f..63120ecf 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -137,6 +137,7 @@ class SimComponent(BaseModel): kwargs["uuid"] = str(uuid4()) super().__init__(**kwargs) self.action_manager: Optional[ActionManager] = None + self._parent: Optional["SimComponent"] = None @abstractmethod def describe_state(self) -> Dict: @@ -187,3 +188,24 @@ class SimComponent(BaseModel): Override this method with anything that needs to happen within the component for it to be reset. """ pass + + @property + def parent(self) -> "SimComponent": + """Reference to the parent object which manages this object. + + :return: Parent object. + :rtype: SimComponent + """ + return self._parent + + @parent.setter + def parent(self, new_parent: "SimComponent") -> None: + if self._parent: + msg = f"Overwriting parent of {self}, {self._parent} with {new_parent}" + _LOGGER.warn(msg) + raise RuntimeWarning(msg) + self._parent = new_parent + + @parent.deleter + def parent(self) -> None: + self._parent = None diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index f89ed2d3..be2a3bbb 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -1,8 +1,11 @@ -from typing import Dict +from typing import Any, Dict +from primaite import getLogger from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent from primaite.simulator.network.hardware.base import Link, Node +_LOGGER = getLogger(__name__) + class NetworkContainer(SimComponent): """Top level container object representing the physical network.""" @@ -40,3 +43,45 @@ class NetworkContainer(SimComponent): } ) return state + + def add_node(self, node: Node) -> None: + """ + Add an existing node to the network. + + :param node: Node instance that the network should keep track of. + :type node: Node + """ + if node in self: + _LOGGER.warning(f"Can't add node {node}. It is already in the network.") + self.nodes[node.uuid] = node + node.parent = self + + def remove_node(self, node: Node) -> None: + """ + Remove a node from the network. + + :param node: Node instance that is currently part of the network that should be removed. + :type node: Node + """ + if node not in self: + _LOGGER.warning(f"Can't remove node {node}. It's not in the network.") + del self.nodes[node.uuid] + del node.parent # misleading? + + def connect_nodes(self, node1: Node, node2: Node) -> None: + """TODO.""" + # I think we should not be forcing users to add and remove individual links. + # Clearly if a link exists between two nodes in the network, then the link is also part of the network. + # I'm just not sure how we ought to handle link creation as it requires an unoccupied network device on the node + raise NotImplementedError + + def disconnect_nodes(self, node1: Node, node2: Node) -> None: + """TODO.""" + raise NotImplementedError + + def __contains__(self, item: Any) -> bool: + if isinstance(item, Node): + return item.uuid in self.nodes + elif isinstance(item, Link): + return item.uuid in self.links + raise TypeError("") From 72b019287aef95c014a36b5e1764aba208da7ff6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 23 Aug 2023 14:41:59 +0100 Subject: [PATCH 111/980] Add scratch notebook to gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 60f5f54c..ff86b65f 100644 --- a/.gitignore +++ b/.gitignore @@ -150,3 +150,4 @@ src/primaite/outputs/ # benchmark session outputs benchmark/output +src/primaite/notebooks/scratch.ipynb From a82ffb974717273963482d9162579538dac2ffb8 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 23 Aug 2023 15:44:23 +0100 Subject: [PATCH 112/980] Add notebook outputs back into src control --- .../notebooks/create-simulation.ipynb | 254 ++++++++++++++++-- 1 file changed, 233 insertions(+), 21 deletions(-) diff --git a/src/primaite/notebooks/create-simulation.ipynb b/src/primaite/notebooks/create-simulation.ipynb index 11d41356..e3e7dfb7 100644 --- a/src/primaite/notebooks/create-simulation.ipynb +++ b/src/primaite/notebooks/create-simulation.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -36,9 +36,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'uuid': '95929b6a-1ce4-4c94-966c-6d3246d7caf9',\n", + " 'network': {'uuid': '4b41398e-d768-47c5-80cf-4278cfc35a24',\n", + " 'nodes': {},\n", + " 'links': {}},\n", + " 'domain': {'uuid': '15920e15-6cd1-4a93-b6af-acbcc6f6468e', 'accounts': {}}}" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_sim = Simulation()\n", "net = my_sim.network\n", @@ -54,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -63,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -82,7 +97,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -91,9 +106,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-08-23 15:44:02,059: NIC 1b:8f:94:4f:46:99/130.1.1.1 connected to Link 1b:8f:94:4f:46:99/130.1.1.1<-->ad:3c:77:44:98:27\n", + "2023-08-23 15:44:02,062: SwitchPort ad:3c:77:44:98:27 connected to Link 1b:8f:94:4f:46:99/130.1.1.1<-->ad:3c:77:44:98:27\n", + "2023-08-23 15:44:02,064: NIC 50:f4:6b:9b:a8:74/130.1.1.2 connected to Link 50:f4:6b:9b:a8:74/130.1.1.2<-->fd:b1:68:f9:8f:eb\n", + "2023-08-23 15:44:02,065: SwitchPort fd:b1:68:f9:8f:eb connected to Link 50:f4:6b:9b:a8:74/130.1.1.2<-->fd:b1:68:f9:8f:eb\n" + ] + } + ], "source": [ "my_swtich = Switch(hostname=\"switch1\", num_ports=12)\n", "net.add_node(my_swtich)\n", @@ -122,7 +148,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -132,7 +158,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -142,9 +168,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "FileSystemFile(uuid='f45bffd7-4aa1-4f6f-81ba-85e746abd28b', name='favicon.ico', size=40.0, file_type=, action_manager=None)" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_server_folder = my_server.file_system.create_folder(\"static\")\n", "my_server.file_system.create_file(\"favicon.ico\", file_type=FileSystemFileType.PNG)" @@ -159,7 +196,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -175,7 +212,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -184,7 +221,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -200,7 +237,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -209,7 +246,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -226,18 +263,193 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'uuid': '95929b6a-1ce4-4c94-966c-6d3246d7caf9',\n", + " 'network': {'uuid': '4b41398e-d768-47c5-80cf-4278cfc35a24',\n", + " 'nodes': {'1599c08e-a101-41a7-a86a-4176660c4270': {'uuid': '1599c08e-a101-41a7-a86a-4176660c4270',\n", + " 'hostname': 'primaite_pc',\n", + " 'operating_state': 0,\n", + " 'NICs': {'ab09d298-ac44-40ef-b950-b4ca6268d482': {'uuid': 'ab09d298-ac44-40ef-b950-b4ca6268d482',\n", + " 'ip_adress': '130.1.1.1',\n", + " 'subnet_mask': '255.255.255.0',\n", + " 'gateway': '130.1.1.255',\n", + " 'mac_address': '1b:8f:94:4f:46:99',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'wake_on_lan': False,\n", + " 'dns_servers': [],\n", + " 'enabled': False}},\n", + " 'file_system': {'uuid': '92120387-14cb-426c-98f2-64d64a85f560',\n", + " 'folders': {'6a11bd03-bc59-4da9-8474-639fcb72b9be': {'uuid': '6a11bd03-bc59-4da9-8474-639fcb72b9be',\n", + " 'name': 'downloads',\n", + " 'size': 1000.0,\n", + " 'files': {'194b2029-4723-4cff-b6d7-e647e4fb687d': {'uuid': '194b2029-4723-4cff-b6d7-e647e4fb687d',\n", + " 'name': 'firefox_installer.zip',\n", + " 'size': 1000.0,\n", + " 'file_type': 'ZIP'}},\n", + " 'is_quarantined': False}}},\n", + " 'applications': {'ae49273b-f581-44e7-ae8c-18cc766158e8': {'uuid': 'ae49273b-f581-44e7-ae8c-18cc766158e8',\n", + " 'health_state': 'GOOD',\n", + " 'health_state_red_view': 'GOOD',\n", + " 'criticality': 'MEDIUM',\n", + " 'patching_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 1,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'ports': ['HTTP'],\n", + " 'opearting_state': 'RUNNING',\n", + " 'execution_control_status': 'manual',\n", + " 'num_executions': 0,\n", + " 'groups': []}},\n", + " 'services': {},\n", + " 'process': {}},\n", + " '7231c745-e186-47a2-8f69-006033b38b8f': {'uuid': '7231c745-e186-47a2-8f69-006033b38b8f',\n", + " 'hostname': 'google_server',\n", + " 'operating_state': 0,\n", + " 'NICs': {'d138788b-2a8e-4c5c-aa5d-b5c28758a78a': {'uuid': 'd138788b-2a8e-4c5c-aa5d-b5c28758a78a',\n", + " 'ip_adress': '130.1.1.2',\n", + " 'subnet_mask': '255.255.255.0',\n", + " 'gateway': '130.1.1.255',\n", + " 'mac_address': '50:f4:6b:9b:a8:74',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'wake_on_lan': False,\n", + " 'dns_servers': [],\n", + " 'enabled': False}},\n", + " 'file_system': {'uuid': '85f1d50c-ded7-4160-9a11-1305ab25934b',\n", + " 'folders': {'86c2666e-31da-46a9-a267-4dc87e2620f9': {'uuid': '86c2666e-31da-46a9-a267-4dc87e2620f9',\n", + " 'name': 'static',\n", + " 'size': 0,\n", + " 'files': {},\n", + " 'is_quarantined': False},\n", + " '1a4479df-6f52-428c-b7b9-c026ab24d2a3': {'uuid': '1a4479df-6f52-428c-b7b9-c026ab24d2a3',\n", + " 'name': 'root',\n", + " 'size': 40.0,\n", + " 'files': {'f45bffd7-4aa1-4f6f-81ba-85e746abd28b': {'uuid': 'f45bffd7-4aa1-4f6f-81ba-85e746abd28b',\n", + " 'name': 'favicon.ico',\n", + " 'size': 40.0,\n", + " 'file_type': 'PNG'}},\n", + " 'is_quarantined': False}}},\n", + " 'applications': {},\n", + " 'services': {},\n", + " 'process': {}},\n", + " '384bab1c-aa23-49cf-9c4e-caababcf30a0': {'uuid': '384bab1c-aa23-49cf-9c4e-caababcf30a0',\n", + " 'num_ports': 12,\n", + " 'ports': {1: {'uuid': 'e64847dd-6f19-4f5e-b473-4f9098ca4b9c',\n", + " 'mac_address': 'ad:3c:77:44:98:27',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False},\n", + " 2: {'uuid': 'd65f815d-dc28-4313-a4f0-b918bb026e7c',\n", + " 'mac_address': 'fd:b1:68:f9:8f:eb',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False},\n", + " 3: {'uuid': '8e1d8783-80af-4aad-bc1e-0c5f1d28b9a1',\n", + " 'mac_address': 'bb:ba:58:26:52:2d',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False},\n", + " 4: {'uuid': '3cde63c0-38e4-4faa-88ba-3a958118e2b3',\n", + " 'mac_address': '69:bc:6f:e1:30:32',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False},\n", + " 5: {'uuid': '37e49743-1723-4b0e-a1e5-61d76e230c08',\n", + " 'mac_address': 'd3:a0:8b:92:25:11',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False},\n", + " 6: {'uuid': '3bf0c0c4-27f6-4a90-8279-1f713b46f4bf',\n", + " 'mac_address': '48:88:7c:71:0a:c0',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False},\n", + " 7: {'uuid': '40b0ba34-9e70-448a-8fdf-836a5a71ed8f',\n", + " 'mac_address': '24:81:03:09:c0:be',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False},\n", + " 8: {'uuid': 'cd23d94b-84b8-441c-bd95-4e310682a095',\n", + " 'mac_address': '27:18:c5:47:fd:82',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False},\n", + " 9: {'uuid': '608eb5bd-7875-4b64-a6f8-794e6283a305',\n", + " 'mac_address': '03:dd:34:d2:56:1c',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False},\n", + " 10: {'uuid': '4acb48c6-74be-40d3-b706-64c06c55720b',\n", + " 'mac_address': 'a3:55:83:af:b7:6b',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False},\n", + " 11: {'uuid': '73e989b5-3c2c-4035-8191-47220ea5ca43',\n", + " 'mac_address': '4f:60:84:21:50:6d',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False},\n", + " 12: {'uuid': '961ff733-a07c-433b-9433-8418a3761120',\n", + " 'mac_address': '7a:26:02:14:8d:da',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False}},\n", + " 'mac_address_table': {}}},\n", + " 'links': {'67df55f4-c485-4eed-a4dc-fe6f96f6b2f3': {'uuid': '67df55f4-c485-4eed-a4dc-fe6f96f6b2f3',\n", + " 'endpoint_a': 'ab09d298-ac44-40ef-b950-b4ca6268d482',\n", + " 'endpoint_b': 'e64847dd-6f19-4f5e-b473-4f9098ca4b9c',\n", + " 'bandwidth': 100.0,\n", + " 'current_load': 0.0},\n", + " '4fdb61da-7cc9-43ea-9ee6-7d9853deff72': {'uuid': '4fdb61da-7cc9-43ea-9ee6-7d9853deff72',\n", + " 'endpoint_a': 'd138788b-2a8e-4c5c-aa5d-b5c28758a78a',\n", + " 'endpoint_b': 'd65f815d-dc28-4313-a4f0-b918bb026e7c',\n", + " 'bandwidth': 100.0,\n", + " 'current_load': 0.0}}},\n", + " 'domain': {'uuid': '15920e15-6cd1-4a93-b6af-acbcc6f6468e',\n", + " 'accounts': {'d7f5bd32-5071-4bec-a111-a9f4e1aca45a': {'uuid': 'd7f5bd32-5071-4bec-a111-a9f4e1aca45a',\n", + " 'num_logons': 0,\n", + " 'num_logoffs': 0,\n", + " 'num_group_changes': 0,\n", + " 'username': 'admin',\n", + " 'password': 'admin12',\n", + " 'account_type': 'USER',\n", + " 'enabled': True}}}}" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_sim.describe_state()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'{\"uuid\": \"95929b6a-1ce4-4c94-966c-6d3246d7caf9\", \"network\": {\"uuid\": \"4b41398e-d768-47c5-80cf-4278cfc35a24\", \"nodes\": {\"1599c08e-a101-41a7-a86a-4176660c4270\": {\"uuid\": \"1599c08e-a101-41a7-a86a-4176660c4270\", \"hostname\": \"primaite_pc\", \"operating_state\": 0, \"NICs\": {\"ab09d298-ac44-40ef-b950-b4ca6268d482\": {\"uuid\": \"ab09d298-ac44-40ef-b950-b4ca6268d482\", \"ip_adress\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"1b:8f:94:4f:46:99\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"92120387-14cb-426c-98f2-64d64a85f560\", \"folders\": {\"6a11bd03-bc59-4da9-8474-639fcb72b9be\": {\"uuid\": \"6a11bd03-bc59-4da9-8474-639fcb72b9be\", \"name\": \"downloads\", \"size\": 1000.0, \"files\": {\"194b2029-4723-4cff-b6d7-e647e4fb687d\": {\"uuid\": \"194b2029-4723-4cff-b6d7-e647e4fb687d\", \"name\": \"firefox_installer.zip\", \"size\": 1000.0, \"file_type\": \"ZIP\"}}, \"is_quarantined\": false}}}, \"applications\": {\"ae49273b-f581-44e7-ae8c-18cc766158e8\": {\"uuid\": \"ae49273b-f581-44e7-ae8c-18cc766158e8\", \"health_state\": \"GOOD\", \"health_state_red_view\": \"GOOD\", \"criticality\": \"MEDIUM\", \"patching_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 1, \"tcp\": true, \"udp\": true, \"ports\": [\"HTTP\"], \"opearting_state\": \"RUNNING\", \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {}, \"process\": {}}, \"7231c745-e186-47a2-8f69-006033b38b8f\": {\"uuid\": \"7231c745-e186-47a2-8f69-006033b38b8f\", \"hostname\": \"google_server\", \"operating_state\": 0, \"NICs\": {\"d138788b-2a8e-4c5c-aa5d-b5c28758a78a\": {\"uuid\": \"d138788b-2a8e-4c5c-aa5d-b5c28758a78a\", \"ip_adress\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"50:f4:6b:9b:a8:74\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"85f1d50c-ded7-4160-9a11-1305ab25934b\", \"folders\": {\"86c2666e-31da-46a9-a267-4dc87e2620f9\": {\"uuid\": \"86c2666e-31da-46a9-a267-4dc87e2620f9\", \"name\": \"static\", \"size\": 0, \"files\": {}, \"is_quarantined\": false}, \"1a4479df-6f52-428c-b7b9-c026ab24d2a3\": {\"uuid\": \"1a4479df-6f52-428c-b7b9-c026ab24d2a3\", \"name\": \"root\", \"size\": 40.0, \"files\": {\"f45bffd7-4aa1-4f6f-81ba-85e746abd28b\": {\"uuid\": \"f45bffd7-4aa1-4f6f-81ba-85e746abd28b\", \"name\": \"favicon.ico\", \"size\": 40.0, \"file_type\": \"PNG\"}}, \"is_quarantined\": false}}}, \"applications\": {}, \"services\": {}, \"process\": {}}, \"384bab1c-aa23-49cf-9c4e-caababcf30a0\": {\"uuid\": \"384bab1c-aa23-49cf-9c4e-caababcf30a0\", \"num_ports\": 12, \"ports\": {\"1\": {\"uuid\": \"e64847dd-6f19-4f5e-b473-4f9098ca4b9c\", \"mac_address\": \"ad:3c:77:44:98:27\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"2\": {\"uuid\": \"d65f815d-dc28-4313-a4f0-b918bb026e7c\", \"mac_address\": \"fd:b1:68:f9:8f:eb\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"3\": {\"uuid\": \"8e1d8783-80af-4aad-bc1e-0c5f1d28b9a1\", \"mac_address\": \"bb:ba:58:26:52:2d\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"4\": {\"uuid\": \"3cde63c0-38e4-4faa-88ba-3a958118e2b3\", \"mac_address\": \"69:bc:6f:e1:30:32\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"5\": {\"uuid\": \"37e49743-1723-4b0e-a1e5-61d76e230c08\", \"mac_address\": \"d3:a0:8b:92:25:11\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"6\": {\"uuid\": \"3bf0c0c4-27f6-4a90-8279-1f713b46f4bf\", \"mac_address\": \"48:88:7c:71:0a:c0\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"7\": {\"uuid\": \"40b0ba34-9e70-448a-8fdf-836a5a71ed8f\", \"mac_address\": \"24:81:03:09:c0:be\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"8\": {\"uuid\": \"cd23d94b-84b8-441c-bd95-4e310682a095\", \"mac_address\": \"27:18:c5:47:fd:82\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"9\": {\"uuid\": \"608eb5bd-7875-4b64-a6f8-794e6283a305\", \"mac_address\": \"03:dd:34:d2:56:1c\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"10\": {\"uuid\": \"4acb48c6-74be-40d3-b706-64c06c55720b\", \"mac_address\": \"a3:55:83:af:b7:6b\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"11\": {\"uuid\": \"73e989b5-3c2c-4035-8191-47220ea5ca43\", \"mac_address\": \"4f:60:84:21:50:6d\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"12\": {\"uuid\": \"961ff733-a07c-433b-9433-8418a3761120\", \"mac_address\": \"7a:26:02:14:8d:da\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}}, \"mac_address_table\": {}}}, \"links\": {\"67df55f4-c485-4eed-a4dc-fe6f96f6b2f3\": {\"uuid\": \"67df55f4-c485-4eed-a4dc-fe6f96f6b2f3\", \"endpoint_a\": \"ab09d298-ac44-40ef-b950-b4ca6268d482\", \"endpoint_b\": \"e64847dd-6f19-4f5e-b473-4f9098ca4b9c\", \"bandwidth\": 100.0, \"current_load\": 0.0}, \"4fdb61da-7cc9-43ea-9ee6-7d9853deff72\": {\"uuid\": \"4fdb61da-7cc9-43ea-9ee6-7d9853deff72\", \"endpoint_a\": \"d138788b-2a8e-4c5c-aa5d-b5c28758a78a\", \"endpoint_b\": \"d65f815d-dc28-4313-a4f0-b918bb026e7c\", \"bandwidth\": 100.0, \"current_load\": 0.0}}}, \"domain\": {\"uuid\": \"15920e15-6cd1-4a93-b6af-acbcc6f6468e\", \"accounts\": {\"d7f5bd32-5071-4bec-a111-a9f4e1aca45a\": {\"uuid\": \"d7f5bd32-5071-4bec-a111-a9f4e1aca45a\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": \"USER\", \"enabled\": true}}}}'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import json\n", "json.dumps(my_sim.describe_state())" From 4077eb3a5cfabbfe9800a2249a0a733e160a5a7c Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 24 Aug 2023 10:26:17 +0100 Subject: [PATCH 113/980] Add tests for network node adding/removal --- src/primaite/simulator/network/container.py | 8 +++- .../network/test_network_creation.py | 38 +++++++++++++++++++ .../_simulator/_network/test_container.py | 16 ++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 tests/integration_tests/network/test_network_creation.py create mode 100644 tests/unit_tests/_primaite/_simulator/_network/test_container.py diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index be2a3bbb..5d7e6a47 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -52,7 +52,9 @@ class NetworkContainer(SimComponent): :type node: Node """ if node in self: - _LOGGER.warning(f"Can't add node {node}. It is already in the network.") + msg = f"Can't add node {node}. It is already in the network." + _LOGGER.warning(msg) + raise RuntimeWarning(msg) self.nodes[node.uuid] = node node.parent = self @@ -64,7 +66,9 @@ class NetworkContainer(SimComponent): :type node: Node """ if node not in self: - _LOGGER.warning(f"Can't remove node {node}. It's not in the network.") + msg = f"Can't remove node {node}. It's not in the network." + _LOGGER.warning(msg) + raise RuntimeWarning(msg) del self.nodes[node.uuid] del node.parent # misleading? diff --git a/tests/integration_tests/network/test_network_creation.py b/tests/integration_tests/network/test_network_creation.py new file mode 100644 index 00000000..482c188d --- /dev/null +++ b/tests/integration_tests/network/test_network_creation.py @@ -0,0 +1,38 @@ +import pytest + +from primaite.simulator.network.container import NetworkContainer +from primaite.simulator.network.hardware.base import Node + + +def test_adding_removing_nodes(): + """Check that we can create and add a node to a network.""" + net = NetworkContainer() + n1 = Node(hostname="computer") + net.add_node(n1) + assert n1.parent is net + assert n1 in net + + net.remove_node(n1) + assert n1.parent is None + assert n1 not in net + + +def test_readding_node(): + """Check that warning is raised when readding a node.""" + net = NetworkContainer() + n1 = Node(hostname="computer") + net.add_node(n1) + with pytest.raises(RuntimeWarning): + net.add_node(n1) + assert n1.parent is net + assert n1 in net + + +def test_removing_nonexistent_node(): + """Check that warning is raised when trying to remove a node that is not in the network.""" + net = NetworkContainer() + n1 = Node(hostname="computer") + with pytest.raises(RuntimeWarning): + net.remove_node(n1) + assert n1.parent is None + assert n1 not in net diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py new file mode 100644 index 00000000..2492dc87 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -0,0 +1,16 @@ +import json + +from primaite.simulator.network.container import NetworkContainer + + +def test_creating_container(): + """Check that we can create a network container""" + net = NetworkContainer() + assert net.nodes and net.links + + +def test_describe_state(): + """Check that we can describe network state without raising errors, and that the result is JSON serialisable.""" + net = NetworkContainer() + state = net.describe_state() + json.dumps(state) # if this function call raises an error, the test fails, state was not JSON-serialisable From f38b423886e45dbf5422a1326f5402e453e99034 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 24 Aug 2023 10:27:30 +0100 Subject: [PATCH 114/980] Update comment --- src/primaite/simulator/network/container.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 5d7e6a47..db782744 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -76,7 +76,7 @@ class NetworkContainer(SimComponent): """TODO.""" # I think we should not be forcing users to add and remove individual links. # Clearly if a link exists between two nodes in the network, then the link is also part of the network. - # I'm just not sure how we ought to handle link creation as it requires an unoccupied network device on the node + # I'm just not sure how we ought to handle link creation as it requires an unoccupied interface on the node. raise NotImplementedError def disconnect_nodes(self, node1: Node, node2: Node) -> None: From a818de8f0133fcd5c1eb37b2b12cb83dcb9b3c73 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 24 Aug 2023 12:40:00 +0100 Subject: [PATCH 115/980] Add ability to connect nodes via the network. --- src/primaite/simulator/network/container.py | 48 ++++++++++++++----- .../simulator/network/hardware/base.py | 2 + .../network/test_network_creation.py | 46 +++++++++++++++++- 3 files changed, 84 insertions(+), 12 deletions(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index db782744..432356b8 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -1,8 +1,8 @@ -from typing import Any, Dict +from typing import Any, Dict, Union from primaite import getLogger from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent -from primaite.simulator.network.hardware.base import Link, Node +from primaite.simulator.network.hardware.base import Link, NIC, Node, SwitchPort _LOGGER = getLogger(__name__) @@ -72,16 +72,42 @@ class NetworkContainer(SimComponent): del self.nodes[node.uuid] del node.parent # misleading? - def connect_nodes(self, node1: Node, node2: Node) -> None: - """TODO.""" - # I think we should not be forcing users to add and remove individual links. - # Clearly if a link exists between two nodes in the network, then the link is also part of the network. - # I'm just not sure how we ought to handle link creation as it requires an unoccupied interface on the node. - raise NotImplementedError + def connect_nodes(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> None: + """Connect two nodes on the network by creating a link between an NIC/SwitchPort of each one. - def disconnect_nodes(self, node1: Node, node2: Node) -> None: - """TODO.""" - raise NotImplementedError + :param endpoint_a: The endpoint to which to connect the link on the first node + :type endpoint_a: Union[NIC, SwitchPort] + :param endpoint_b: The endpoint to which to connct the link on the second node + :type endpoint_b: Union[NIC, SwitchPort] + :raises RuntimeError: _description_ + """ + node_a = endpoint_a.parent + node_b = endpoint_b.parent + msg = "" + if node_a not in self: + msg = f"Cannot create a link to {endpoint_a} because the node is not in the network." + if node_b not in self: + msg = f"Cannot create a link to {endpoint_b} because the node is not in the network." + if node_a is node_b: + msg = f"Cannot link {endpoint_a} to {endpoint_b} because they belong to the same node." + if msg: + _LOGGER.error(msg) + raise RuntimeError(msg) + + link = Link(endpoint_a=endpoint_a, endpoint_b=endpoint_b, **kwargs) + self.links[link.uuid] = link + link.parent = self + + def remove_link(self, link: Link) -> None: + """Disconnect a link from the network. + + :param link: The link to be removed + :type link: Link + """ + link.endpoint_a.disconnect_link() + link.endpoint_b.disconnect_link() + del self.links[link.uuid] + del link.parent def __contains__(self, item: Any) -> bool: if isinstance(item, Node): diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 28e7693a..5b49f008 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -918,6 +918,7 @@ class Node(SimComponent): if nic.uuid not in self.nics: self.nics[nic.uuid] = nic nic.connected_node = self + nic.parent = self self.sys_log.info(f"Connected NIC {nic}") if self.operating_state == NodeOperatingState.ON: nic.enable() @@ -938,6 +939,7 @@ class Node(SimComponent): nic = self.nics.get(nic) if nic or nic.uuid in self.nics: self.nics.pop(nic.uuid) + del nic.parent nic.disable() self.sys_log.info(f"Disconnected NIC {nic}") else: diff --git a/tests/integration_tests/network/test_network_creation.py b/tests/integration_tests/network/test_network_creation.py index 482c188d..0ee827be 100644 --- a/tests/integration_tests/network/test_network_creation.py +++ b/tests/integration_tests/network/test_network_creation.py @@ -1,7 +1,7 @@ import pytest from primaite.simulator.network.container import NetworkContainer -from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.base import NIC, Node def test_adding_removing_nodes(): @@ -36,3 +36,47 @@ def test_removing_nonexistent_node(): net.remove_node(n1) assert n1.parent is None assert n1 not in net + + +def test_connecting_nodes(): + """Check that two nodes on the network can be connected.""" + net = NetworkContainer() + n1 = Node(hostname="computer") + n1_nic = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0") + n1.connect_nic(n1_nic) + n2 = Node(hostname="server") + n2_nic = NIC(ip_address="120.30.0.2", gateway="192.168.0.1", subnet_mask="255.255.255.0") + n2.connect_nic(n2_nic) + + net.add_node(n1) + net.add_node(n2) + + net.connect_nodes(n1.nics[n1_nic.uuid], n2.nics[n2_nic.uuid], bandwidth=30) + + assert len(net.links) == 1 + link = list(net.links.values())[0] + assert link in net + assert link.parent is net + + +def test_connecting_node_to_itself(): + net = NetworkContainer() + node = Node(hostname="computer") + nic1 = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0") + node.connect_nic(nic1) + nic2 = NIC(ip_address="120.30.0.2", gateway="192.168.0.1", subnet_mask="255.255.255.0") + node.connect_nic(nic2) + + net.add_node(node) + + with pytest.raises(RuntimeError): + net.connect_nodes(node.nics[nic1.uuid], node.nics[nic2.uuid], bandwidth=30) + + assert node in net + assert nic1.connected_link is None + assert nic2.connected_link is None + assert len(net.links) == 0 + + +def test_disconnecting_nodes(): + ... From 7058c7e9a89e1462d924c0b578f92fb789a051b5 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 24 Aug 2023 12:41:46 +0100 Subject: [PATCH 116/980] Rename networkcontainer to network --- src/primaite/simulator/network/container.py | 2 +- src/primaite/simulator/sim_container.py | 6 +++--- .../network/test_network_creation.py | 12 ++++++------ .../_primaite/_simulator/_network/test_container.py | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 432356b8..0612069c 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -7,7 +7,7 @@ from primaite.simulator.network.hardware.base import Link, NIC, Node, SwitchPort _LOGGER = getLogger(__name__) -class NetworkContainer(SimComponent): +class Network(SimComponent): """Top level container object representing the physical network.""" nodes: Dict[str, Node] = {} diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index 50fe412c..319defe4 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -2,19 +2,19 @@ from typing import Dict from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent from primaite.simulator.domain.controller import DomainController -from primaite.simulator.network.container import NetworkContainer +from primaite.simulator.network.container import Network class Simulation(SimComponent): """Top-level simulation object which holds a reference to all other parts of the simulation.""" - network: NetworkContainer + network: Network domain: DomainController def __init__(self, **kwargs): """Initialise the Simulation.""" if not kwargs.get("network"): - kwargs["network"] = NetworkContainer() + kwargs["network"] = Network() if not kwargs.get("domain"): kwargs["domain"] = DomainController() diff --git a/tests/integration_tests/network/test_network_creation.py b/tests/integration_tests/network/test_network_creation.py index 0ee827be..70b48806 100644 --- a/tests/integration_tests/network/test_network_creation.py +++ b/tests/integration_tests/network/test_network_creation.py @@ -1,12 +1,12 @@ import pytest -from primaite.simulator.network.container import NetworkContainer +from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.base import NIC, Node def test_adding_removing_nodes(): """Check that we can create and add a node to a network.""" - net = NetworkContainer() + net = Network() n1 = Node(hostname="computer") net.add_node(n1) assert n1.parent is net @@ -19,7 +19,7 @@ def test_adding_removing_nodes(): def test_readding_node(): """Check that warning is raised when readding a node.""" - net = NetworkContainer() + net = Network() n1 = Node(hostname="computer") net.add_node(n1) with pytest.raises(RuntimeWarning): @@ -30,7 +30,7 @@ def test_readding_node(): def test_removing_nonexistent_node(): """Check that warning is raised when trying to remove a node that is not in the network.""" - net = NetworkContainer() + net = Network() n1 = Node(hostname="computer") with pytest.raises(RuntimeWarning): net.remove_node(n1) @@ -40,7 +40,7 @@ def test_removing_nonexistent_node(): def test_connecting_nodes(): """Check that two nodes on the network can be connected.""" - net = NetworkContainer() + net = Network() n1 = Node(hostname="computer") n1_nic = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0") n1.connect_nic(n1_nic) @@ -60,7 +60,7 @@ def test_connecting_nodes(): def test_connecting_node_to_itself(): - net = NetworkContainer() + net = Network() node = Node(hostname="computer") nic1 = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0") node.connect_nic(nic1) diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index 2492dc87..5fc308cc 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -1,16 +1,16 @@ import json -from primaite.simulator.network.container import NetworkContainer +from primaite.simulator.network.container import Network def test_creating_container(): """Check that we can create a network container""" - net = NetworkContainer() + net = Network() assert net.nodes and net.links def test_describe_state(): """Check that we can describe network state without raising errors, and that the result is JSON serialisable.""" - net = NetworkContainer() + net = Network() state = net.describe_state() json.dumps(state) # if this function call raises an error, the test fails, state was not JSON-serialisable From 78008e3c6e80199bd5116455e8afb1f2ccecf15b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 24 Aug 2023 12:52:38 +0100 Subject: [PATCH 117/980] Fix container test --- .../unit_tests/_primaite/_simulator/_network/test_container.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index 5fc308cc..290e7cc3 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -6,7 +6,8 @@ from primaite.simulator.network.container import Network def test_creating_container(): """Check that we can create a network container""" net = Network() - assert net.nodes and net.links + assert net.nodes == {} + assert net.links == {} def test_describe_state(): From fec44aef53e25b2ac1a83e851f92a5c212a5daef Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 24 Aug 2023 13:03:16 +0100 Subject: [PATCH 118/980] Rename connect_nodes to connect and fix minor bug --- src/primaite/simulator/network/container.py | 2 +- src/primaite/simulator/network/hardware/base.py | 1 + tests/integration_tests/network/test_network_creation.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 0612069c..1c03358c 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -72,7 +72,7 @@ class Network(SimComponent): del self.nodes[node.uuid] del node.parent # misleading? - def connect_nodes(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> None: + def connect(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> None: """Connect two nodes on the network by creating a link between an NIC/SwitchPort of each one. :param endpoint_a: The endpoint to which to connect the link on the first node diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 5b49f008..fe3b5b15 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1011,6 +1011,7 @@ class Switch(Node): self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)} for port_num, port in self.switch_ports.items(): port.connected_node = self + port.parent = self port.port_num = port_num def show(self): diff --git a/tests/integration_tests/network/test_network_creation.py b/tests/integration_tests/network/test_network_creation.py index 70b48806..418f5e5f 100644 --- a/tests/integration_tests/network/test_network_creation.py +++ b/tests/integration_tests/network/test_network_creation.py @@ -51,7 +51,7 @@ def test_connecting_nodes(): net.add_node(n1) net.add_node(n2) - net.connect_nodes(n1.nics[n1_nic.uuid], n2.nics[n2_nic.uuid], bandwidth=30) + net.connect(n1.nics[n1_nic.uuid], n2.nics[n2_nic.uuid], bandwidth=30) assert len(net.links) == 1 link = list(net.links.values())[0] @@ -70,7 +70,7 @@ def test_connecting_node_to_itself(): net.add_node(node) with pytest.raises(RuntimeError): - net.connect_nodes(node.nics[nic1.uuid], node.nics[nic2.uuid], bandwidth=30) + net.connect(node.nics[nic1.uuid], node.nics[nic2.uuid], bandwidth=30) assert node in net assert nic1.connected_link is None From 05bb0f295b25973a0776d0ab4b7e65c6767ce93f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 24 Aug 2023 13:06:45 +0100 Subject: [PATCH 119/980] Update notebook tutorial on creating a simulation --- .../notebooks/create-simulation.ipynb | 123 +++++++++--------- 1 file changed, 60 insertions(+), 63 deletions(-) diff --git a/src/primaite/notebooks/create-simulation.ipynb b/src/primaite/notebooks/create-simulation.ipynb index e3e7dfb7..baf7bd2c 100644 --- a/src/primaite/notebooks/create-simulation.ipynb +++ b/src/primaite/notebooks/create-simulation.ipynb @@ -42,11 +42,11 @@ { "data": { "text/plain": [ - "{'uuid': '95929b6a-1ce4-4c94-966c-6d3246d7caf9',\n", - " 'network': {'uuid': '4b41398e-d768-47c5-80cf-4278cfc35a24',\n", + "{'uuid': '2ef348c6-32e5-4c5c-83b7-3b82d0b6123b',\n", + " 'network': {'uuid': 'dd2d1a02-d461-4505-8bbd-fd0681750175',\n", " 'nodes': {},\n", " 'links': {}},\n", - " 'domain': {'uuid': '15920e15-6cd1-4a93-b6af-acbcc6f6468e', 'accounts': {}}}" + " 'domain': {'uuid': 'ae0423ee-51fa-41e7-be80-c642b39707f6', 'accounts': {}}}" ] }, "execution_count": 2, @@ -113,10 +113,10 @@ "name": "stderr", "output_type": "stream", "text": [ - "2023-08-23 15:44:02,059: NIC 1b:8f:94:4f:46:99/130.1.1.1 connected to Link 1b:8f:94:4f:46:99/130.1.1.1<-->ad:3c:77:44:98:27\n", - "2023-08-23 15:44:02,062: SwitchPort ad:3c:77:44:98:27 connected to Link 1b:8f:94:4f:46:99/130.1.1.1<-->ad:3c:77:44:98:27\n", - "2023-08-23 15:44:02,064: NIC 50:f4:6b:9b:a8:74/130.1.1.2 connected to Link 50:f4:6b:9b:a8:74/130.1.1.2<-->fd:b1:68:f9:8f:eb\n", - "2023-08-23 15:44:02,065: SwitchPort fd:b1:68:f9:8f:eb connected to Link 50:f4:6b:9b:a8:74/130.1.1.2<-->fd:b1:68:f9:8f:eb\n" + "2023-08-24 13:06:28,617: NIC cc:be:ec:43:a6:4c/130.1.1.1 connected to Link cc:be:ec:43:a6:4c/130.1.1.1<-->79:2b:4a:70:c3:50\n", + "2023-08-24 13:06:28,618: SwitchPort 79:2b:4a:70:c3:50 connected to Link cc:be:ec:43:a6:4c/130.1.1.1<-->79:2b:4a:70:c3:50\n", + "2023-08-24 13:06:28,619: NIC c2:1e:48:e1:a4:ad/130.1.1.2 connected to Link c2:1e:48:e1:a4:ad/130.1.1.2<-->1a:2d:12:38:80:2f\n", + "2023-08-24 13:06:28,620: SwitchPort 1a:2d:12:38:80:2f connected to Link c2:1e:48:e1:a4:ad/130.1.1.2<-->1a:2d:12:38:80:2f\n" ] } ], @@ -132,11 +132,8 @@ "my_server.connect_nic(server_nic)\n", "\n", "\n", - "pc_to_switch = Link(endpoint_a=pc_nic, endpoint_b=my_swtich.switch_ports[1])\n", - "server_to_swtich = Link(endpoint_a=server_nic, endpoint_b=my_swtich.switch_ports[2])\n", - "\n", - "my_sim.network.links[pc_to_switch.uuid] = pc_to_switch\n", - "my_sim.network.links[server_to_swtich.uuid] = server_to_swtich" + "net.connect(pc_nic, my_swtich.switch_ports[1])\n", + "net.connect(server_nic, my_swtich.switch_ports[2])\n" ] }, { @@ -174,7 +171,7 @@ { "data": { "text/plain": [ - "FileSystemFile(uuid='f45bffd7-4aa1-4f6f-81ba-85e746abd28b', name='favicon.ico', size=40.0, file_type=, action_manager=None)" + "FileSystemFile(uuid='7d56a563-ecc0-4011-8c97-240dd6c885c0', name='favicon.ico', size=40.0, file_type=, action_manager=None)" ] }, "execution_count": 9, @@ -269,31 +266,31 @@ { "data": { "text/plain": [ - "{'uuid': '95929b6a-1ce4-4c94-966c-6d3246d7caf9',\n", - " 'network': {'uuid': '4b41398e-d768-47c5-80cf-4278cfc35a24',\n", - " 'nodes': {'1599c08e-a101-41a7-a86a-4176660c4270': {'uuid': '1599c08e-a101-41a7-a86a-4176660c4270',\n", + "{'uuid': '2ef348c6-32e5-4c5c-83b7-3b82d0b6123b',\n", + " 'network': {'uuid': 'dd2d1a02-d461-4505-8bbd-fd0681750175',\n", + " 'nodes': {'2f03b32b-7290-4921-8670-faebe4a19d63': {'uuid': '2f03b32b-7290-4921-8670-faebe4a19d63',\n", " 'hostname': 'primaite_pc',\n", " 'operating_state': 0,\n", - " 'NICs': {'ab09d298-ac44-40ef-b950-b4ca6268d482': {'uuid': 'ab09d298-ac44-40ef-b950-b4ca6268d482',\n", + " 'NICs': {'e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b': {'uuid': 'e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b',\n", " 'ip_adress': '130.1.1.1',\n", " 'subnet_mask': '255.255.255.0',\n", " 'gateway': '130.1.1.255',\n", - " 'mac_address': '1b:8f:94:4f:46:99',\n", + " 'mac_address': 'cc:be:ec:43:a6:4c',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'wake_on_lan': False,\n", " 'dns_servers': [],\n", " 'enabled': False}},\n", - " 'file_system': {'uuid': '92120387-14cb-426c-98f2-64d64a85f560',\n", - " 'folders': {'6a11bd03-bc59-4da9-8474-639fcb72b9be': {'uuid': '6a11bd03-bc59-4da9-8474-639fcb72b9be',\n", + " 'file_system': {'uuid': '0b7206af-3e0a-41b0-8115-ae9e0dbbcd81',\n", + " 'folders': {'c161bc7c-9abd-4666-9b49-2745fdb65ebe': {'uuid': 'c161bc7c-9abd-4666-9b49-2745fdb65ebe',\n", " 'name': 'downloads',\n", " 'size': 1000.0,\n", - " 'files': {'194b2029-4723-4cff-b6d7-e647e4fb687d': {'uuid': '194b2029-4723-4cff-b6d7-e647e4fb687d',\n", + " 'files': {'f807d777-d167-4f37-9f9b-ced634af6ed5': {'uuid': 'f807d777-d167-4f37-9f9b-ced634af6ed5',\n", " 'name': 'firefox_installer.zip',\n", " 'size': 1000.0,\n", " 'file_type': 'ZIP'}},\n", " 'is_quarantined': False}}},\n", - " 'applications': {'ae49273b-f581-44e7-ae8c-18cc766158e8': {'uuid': 'ae49273b-f581-44e7-ae8c-18cc766158e8',\n", + " 'applications': {'ea466b2f-1ed5-49fd-9579-44852bff684d': {'uuid': 'ea466b2f-1ed5-49fd-9579-44852bff684d',\n", " 'health_state': 'GOOD',\n", " 'health_state_red_view': 'GOOD',\n", " 'criticality': 'MEDIUM',\n", @@ -311,29 +308,29 @@ " 'groups': []}},\n", " 'services': {},\n", " 'process': {}},\n", - " '7231c745-e186-47a2-8f69-006033b38b8f': {'uuid': '7231c745-e186-47a2-8f69-006033b38b8f',\n", + " 'e9afc0bc-fb21-48a3-9868-2ede6a3181dc': {'uuid': 'e9afc0bc-fb21-48a3-9868-2ede6a3181dc',\n", " 'hostname': 'google_server',\n", " 'operating_state': 0,\n", - " 'NICs': {'d138788b-2a8e-4c5c-aa5d-b5c28758a78a': {'uuid': 'd138788b-2a8e-4c5c-aa5d-b5c28758a78a',\n", + " 'NICs': {'956ce240-8fb3-4fde-8635-ac4ea601a582': {'uuid': '956ce240-8fb3-4fde-8635-ac4ea601a582',\n", " 'ip_adress': '130.1.1.2',\n", " 'subnet_mask': '255.255.255.0',\n", " 'gateway': '130.1.1.255',\n", - " 'mac_address': '50:f4:6b:9b:a8:74',\n", + " 'mac_address': 'c2:1e:48:e1:a4:ad',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'wake_on_lan': False,\n", " 'dns_servers': [],\n", " 'enabled': False}},\n", - " 'file_system': {'uuid': '85f1d50c-ded7-4160-9a11-1305ab25934b',\n", - " 'folders': {'86c2666e-31da-46a9-a267-4dc87e2620f9': {'uuid': '86c2666e-31da-46a9-a267-4dc87e2620f9',\n", + " 'file_system': {'uuid': 'c3f99c30-b493-4fb6-b13e-d2005d851b59',\n", + " 'folders': {'869eda49-21f2-4fc1-8681-78725cdd5c70': {'uuid': '869eda49-21f2-4fc1-8681-78725cdd5c70',\n", " 'name': 'static',\n", " 'size': 0,\n", " 'files': {},\n", " 'is_quarantined': False},\n", - " '1a4479df-6f52-428c-b7b9-c026ab24d2a3': {'uuid': '1a4479df-6f52-428c-b7b9-c026ab24d2a3',\n", + " '9fbe0e41-0d6a-4142-9c73-9c0de2dbde6e': {'uuid': '9fbe0e41-0d6a-4142-9c73-9c0de2dbde6e',\n", " 'name': 'root',\n", " 'size': 40.0,\n", - " 'files': {'f45bffd7-4aa1-4f6f-81ba-85e746abd28b': {'uuid': 'f45bffd7-4aa1-4f6f-81ba-85e746abd28b',\n", + " 'files': {'7d56a563-ecc0-4011-8c97-240dd6c885c0': {'uuid': '7d56a563-ecc0-4011-8c97-240dd6c885c0',\n", " 'name': 'favicon.ico',\n", " 'size': 40.0,\n", " 'file_type': 'PNG'}},\n", @@ -341,81 +338,81 @@ " 'applications': {},\n", " 'services': {},\n", " 'process': {}},\n", - " '384bab1c-aa23-49cf-9c4e-caababcf30a0': {'uuid': '384bab1c-aa23-49cf-9c4e-caababcf30a0',\n", + " '47814452-ef47-4e6b-9087-796c438d4698': {'uuid': '47814452-ef47-4e6b-9087-796c438d4698',\n", " 'num_ports': 12,\n", - " 'ports': {1: {'uuid': 'e64847dd-6f19-4f5e-b473-4f9098ca4b9c',\n", - " 'mac_address': 'ad:3c:77:44:98:27',\n", + " 'ports': {1: {'uuid': 'b76fe86f-bb92-4346-8e83-217a2fb0bc67',\n", + " 'mac_address': '79:2b:4a:70:c3:50',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False},\n", - " 2: {'uuid': 'd65f815d-dc28-4313-a4f0-b918bb026e7c',\n", - " 'mac_address': 'fd:b1:68:f9:8f:eb',\n", + " 2: {'uuid': '6f8fc6e7-76a4-441a-b7af-441edbdcc6ac',\n", + " 'mac_address': '1a:2d:12:38:80:2f',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False},\n", - " 3: {'uuid': '8e1d8783-80af-4aad-bc1e-0c5f1d28b9a1',\n", - " 'mac_address': 'bb:ba:58:26:52:2d',\n", + " 3: {'uuid': '1aa75a3c-01f1-4293-9894-5396fa412690',\n", + " 'mac_address': 'd1:7b:36:c1:82:c1',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False},\n", - " 4: {'uuid': '3cde63c0-38e4-4faa-88ba-3a958118e2b3',\n", - " 'mac_address': '69:bc:6f:e1:30:32',\n", + " 4: {'uuid': 'fe6c9f44-59d5-403e-973a-6f19fce7b9b9',\n", + " 'mac_address': 'e3:6b:cc:0c:98:9b',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False},\n", - " 5: {'uuid': '37e49743-1723-4b0e-a1e5-61d76e230c08',\n", - " 'mac_address': 'd3:a0:8b:92:25:11',\n", + " 5: {'uuid': 'e9e83e37-8537-4884-98a6-87017540078f',\n", + " 'mac_address': '32:09:c0:4a:f1:20',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False},\n", - " 6: {'uuid': '3bf0c0c4-27f6-4a90-8279-1f713b46f4bf',\n", - " 'mac_address': '48:88:7c:71:0a:c0',\n", + " 6: {'uuid': '747f2cd3-8902-4da8-8829-b0b53fe79735',\n", + " 'mac_address': 'e8:20:0b:04:b8:76',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False},\n", - " 7: {'uuid': '40b0ba34-9e70-448a-8fdf-836a5a71ed8f',\n", - " 'mac_address': '24:81:03:09:c0:be',\n", + " 7: {'uuid': '88ed129e-0ddb-4d29-ba3c-58d81efe240e',\n", + " 'mac_address': '7f:b4:f4:2e:b6:71',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False},\n", - " 8: {'uuid': 'cd23d94b-84b8-441c-bd95-4e310682a095',\n", - " 'mac_address': '27:18:c5:47:fd:82',\n", + " 8: {'uuid': '6c1a4c3c-25d8-46f6-98a8-54073d0ca0d3',\n", + " 'mac_address': 'f6:22:2d:24:b9:71',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False},\n", - " 9: {'uuid': '608eb5bd-7875-4b64-a6f8-794e6283a305',\n", - " 'mac_address': '03:dd:34:d2:56:1c',\n", + " 9: {'uuid': 'b2bfc006-6a6b-4701-a75a-27954592d429',\n", + " 'mac_address': 'b6:a5:92:a5:aa:1b',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False},\n", - " 10: {'uuid': '4acb48c6-74be-40d3-b706-64c06c55720b',\n", - " 'mac_address': 'a3:55:83:af:b7:6b',\n", + " 10: {'uuid': '3c607386-87a2-4d0b-ac04-449416ca5b1f',\n", + " 'mac_address': 'b3:75:7d:ce:88:0a',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False},\n", - " 11: {'uuid': '73e989b5-3c2c-4035-8191-47220ea5ca43',\n", - " 'mac_address': '4f:60:84:21:50:6d',\n", + " 11: {'uuid': '590002c8-27fa-4c31-b17b-7b89dbf8cdf8',\n", + " 'mac_address': 'c0:25:a6:64:52:8e',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False},\n", - " 12: {'uuid': '961ff733-a07c-433b-9433-8418a3761120',\n", - " 'mac_address': '7a:26:02:14:8d:da',\n", + " 12: {'uuid': 'b7e25eed-547a-4c17-8cb9-8b976ce4bbd9',\n", + " 'mac_address': '98:50:96:47:ca:bc',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False}},\n", " 'mac_address_table': {}}},\n", - " 'links': {'67df55f4-c485-4eed-a4dc-fe6f96f6b2f3': {'uuid': '67df55f4-c485-4eed-a4dc-fe6f96f6b2f3',\n", - " 'endpoint_a': 'ab09d298-ac44-40ef-b950-b4ca6268d482',\n", - " 'endpoint_b': 'e64847dd-6f19-4f5e-b473-4f9098ca4b9c',\n", + " 'links': {'a51a4435-20ae-43cf-a151-26e824968b3d': {'uuid': 'a51a4435-20ae-43cf-a151-26e824968b3d',\n", + " 'endpoint_a': 'e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b',\n", + " 'endpoint_b': 'b76fe86f-bb92-4346-8e83-217a2fb0bc67',\n", " 'bandwidth': 100.0,\n", " 'current_load': 0.0},\n", - " '4fdb61da-7cc9-43ea-9ee6-7d9853deff72': {'uuid': '4fdb61da-7cc9-43ea-9ee6-7d9853deff72',\n", - " 'endpoint_a': 'd138788b-2a8e-4c5c-aa5d-b5c28758a78a',\n", - " 'endpoint_b': 'd65f815d-dc28-4313-a4f0-b918bb026e7c',\n", + " 'ae3486e5-f78e-4092-96d1-d7e8176f2b7d': {'uuid': 'ae3486e5-f78e-4092-96d1-d7e8176f2b7d',\n", + " 'endpoint_a': '956ce240-8fb3-4fde-8635-ac4ea601a582',\n", + " 'endpoint_b': '6f8fc6e7-76a4-441a-b7af-441edbdcc6ac',\n", " 'bandwidth': 100.0,\n", " 'current_load': 0.0}}},\n", - " 'domain': {'uuid': '15920e15-6cd1-4a93-b6af-acbcc6f6468e',\n", - " 'accounts': {'d7f5bd32-5071-4bec-a111-a9f4e1aca45a': {'uuid': 'd7f5bd32-5071-4bec-a111-a9f4e1aca45a',\n", + " 'domain': {'uuid': 'ae0423ee-51fa-41e7-be80-c642b39707f6',\n", + " 'accounts': {'917eda28-9a67-4449-bddd-87e2141a3162': {'uuid': '917eda28-9a67-4449-bddd-87e2141a3162',\n", " 'num_logons': 0,\n", " 'num_logoffs': 0,\n", " 'num_group_changes': 0,\n", @@ -442,7 +439,7 @@ { "data": { "text/plain": [ - "'{\"uuid\": \"95929b6a-1ce4-4c94-966c-6d3246d7caf9\", \"network\": {\"uuid\": \"4b41398e-d768-47c5-80cf-4278cfc35a24\", \"nodes\": {\"1599c08e-a101-41a7-a86a-4176660c4270\": {\"uuid\": \"1599c08e-a101-41a7-a86a-4176660c4270\", \"hostname\": \"primaite_pc\", \"operating_state\": 0, \"NICs\": {\"ab09d298-ac44-40ef-b950-b4ca6268d482\": {\"uuid\": \"ab09d298-ac44-40ef-b950-b4ca6268d482\", \"ip_adress\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"1b:8f:94:4f:46:99\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"92120387-14cb-426c-98f2-64d64a85f560\", \"folders\": {\"6a11bd03-bc59-4da9-8474-639fcb72b9be\": {\"uuid\": \"6a11bd03-bc59-4da9-8474-639fcb72b9be\", \"name\": \"downloads\", \"size\": 1000.0, \"files\": {\"194b2029-4723-4cff-b6d7-e647e4fb687d\": {\"uuid\": \"194b2029-4723-4cff-b6d7-e647e4fb687d\", \"name\": \"firefox_installer.zip\", \"size\": 1000.0, \"file_type\": \"ZIP\"}}, \"is_quarantined\": false}}}, \"applications\": {\"ae49273b-f581-44e7-ae8c-18cc766158e8\": {\"uuid\": \"ae49273b-f581-44e7-ae8c-18cc766158e8\", \"health_state\": \"GOOD\", \"health_state_red_view\": \"GOOD\", \"criticality\": \"MEDIUM\", \"patching_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 1, \"tcp\": true, \"udp\": true, \"ports\": [\"HTTP\"], \"opearting_state\": \"RUNNING\", \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {}, \"process\": {}}, \"7231c745-e186-47a2-8f69-006033b38b8f\": {\"uuid\": \"7231c745-e186-47a2-8f69-006033b38b8f\", \"hostname\": \"google_server\", \"operating_state\": 0, \"NICs\": {\"d138788b-2a8e-4c5c-aa5d-b5c28758a78a\": {\"uuid\": \"d138788b-2a8e-4c5c-aa5d-b5c28758a78a\", \"ip_adress\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"50:f4:6b:9b:a8:74\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"85f1d50c-ded7-4160-9a11-1305ab25934b\", \"folders\": {\"86c2666e-31da-46a9-a267-4dc87e2620f9\": {\"uuid\": \"86c2666e-31da-46a9-a267-4dc87e2620f9\", \"name\": \"static\", \"size\": 0, \"files\": {}, \"is_quarantined\": false}, \"1a4479df-6f52-428c-b7b9-c026ab24d2a3\": {\"uuid\": \"1a4479df-6f52-428c-b7b9-c026ab24d2a3\", \"name\": \"root\", \"size\": 40.0, \"files\": {\"f45bffd7-4aa1-4f6f-81ba-85e746abd28b\": {\"uuid\": \"f45bffd7-4aa1-4f6f-81ba-85e746abd28b\", \"name\": \"favicon.ico\", \"size\": 40.0, \"file_type\": \"PNG\"}}, \"is_quarantined\": false}}}, \"applications\": {}, \"services\": {}, \"process\": {}}, \"384bab1c-aa23-49cf-9c4e-caababcf30a0\": {\"uuid\": \"384bab1c-aa23-49cf-9c4e-caababcf30a0\", \"num_ports\": 12, \"ports\": {\"1\": {\"uuid\": \"e64847dd-6f19-4f5e-b473-4f9098ca4b9c\", \"mac_address\": \"ad:3c:77:44:98:27\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"2\": {\"uuid\": \"d65f815d-dc28-4313-a4f0-b918bb026e7c\", \"mac_address\": \"fd:b1:68:f9:8f:eb\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"3\": {\"uuid\": \"8e1d8783-80af-4aad-bc1e-0c5f1d28b9a1\", \"mac_address\": \"bb:ba:58:26:52:2d\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"4\": {\"uuid\": \"3cde63c0-38e4-4faa-88ba-3a958118e2b3\", \"mac_address\": \"69:bc:6f:e1:30:32\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"5\": {\"uuid\": \"37e49743-1723-4b0e-a1e5-61d76e230c08\", \"mac_address\": \"d3:a0:8b:92:25:11\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"6\": {\"uuid\": \"3bf0c0c4-27f6-4a90-8279-1f713b46f4bf\", \"mac_address\": \"48:88:7c:71:0a:c0\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"7\": {\"uuid\": \"40b0ba34-9e70-448a-8fdf-836a5a71ed8f\", \"mac_address\": \"24:81:03:09:c0:be\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"8\": {\"uuid\": \"cd23d94b-84b8-441c-bd95-4e310682a095\", \"mac_address\": \"27:18:c5:47:fd:82\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"9\": {\"uuid\": \"608eb5bd-7875-4b64-a6f8-794e6283a305\", \"mac_address\": \"03:dd:34:d2:56:1c\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"10\": {\"uuid\": \"4acb48c6-74be-40d3-b706-64c06c55720b\", \"mac_address\": \"a3:55:83:af:b7:6b\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"11\": {\"uuid\": \"73e989b5-3c2c-4035-8191-47220ea5ca43\", \"mac_address\": \"4f:60:84:21:50:6d\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"12\": {\"uuid\": \"961ff733-a07c-433b-9433-8418a3761120\", \"mac_address\": \"7a:26:02:14:8d:da\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}}, \"mac_address_table\": {}}}, \"links\": {\"67df55f4-c485-4eed-a4dc-fe6f96f6b2f3\": {\"uuid\": \"67df55f4-c485-4eed-a4dc-fe6f96f6b2f3\", \"endpoint_a\": \"ab09d298-ac44-40ef-b950-b4ca6268d482\", \"endpoint_b\": \"e64847dd-6f19-4f5e-b473-4f9098ca4b9c\", \"bandwidth\": 100.0, \"current_load\": 0.0}, \"4fdb61da-7cc9-43ea-9ee6-7d9853deff72\": {\"uuid\": \"4fdb61da-7cc9-43ea-9ee6-7d9853deff72\", \"endpoint_a\": \"d138788b-2a8e-4c5c-aa5d-b5c28758a78a\", \"endpoint_b\": \"d65f815d-dc28-4313-a4f0-b918bb026e7c\", \"bandwidth\": 100.0, \"current_load\": 0.0}}}, \"domain\": {\"uuid\": \"15920e15-6cd1-4a93-b6af-acbcc6f6468e\", \"accounts\": {\"d7f5bd32-5071-4bec-a111-a9f4e1aca45a\": {\"uuid\": \"d7f5bd32-5071-4bec-a111-a9f4e1aca45a\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": \"USER\", \"enabled\": true}}}}'" + "'{\"uuid\": \"2ef348c6-32e5-4c5c-83b7-3b82d0b6123b\", \"network\": {\"uuid\": \"dd2d1a02-d461-4505-8bbd-fd0681750175\", \"nodes\": {\"2f03b32b-7290-4921-8670-faebe4a19d63\": {\"uuid\": \"2f03b32b-7290-4921-8670-faebe4a19d63\", \"hostname\": \"primaite_pc\", \"operating_state\": 0, \"NICs\": {\"e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b\": {\"uuid\": \"e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b\", \"ip_adress\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"cc:be:ec:43:a6:4c\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"0b7206af-3e0a-41b0-8115-ae9e0dbbcd81\", \"folders\": {\"c161bc7c-9abd-4666-9b49-2745fdb65ebe\": {\"uuid\": \"c161bc7c-9abd-4666-9b49-2745fdb65ebe\", \"name\": \"downloads\", \"size\": 1000.0, \"files\": {\"f807d777-d167-4f37-9f9b-ced634af6ed5\": {\"uuid\": \"f807d777-d167-4f37-9f9b-ced634af6ed5\", \"name\": \"firefox_installer.zip\", \"size\": 1000.0, \"file_type\": \"ZIP\"}}, \"is_quarantined\": false}}}, \"applications\": {\"ea466b2f-1ed5-49fd-9579-44852bff684d\": {\"uuid\": \"ea466b2f-1ed5-49fd-9579-44852bff684d\", \"health_state\": \"GOOD\", \"health_state_red_view\": \"GOOD\", \"criticality\": \"MEDIUM\", \"patching_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 1, \"tcp\": true, \"udp\": true, \"ports\": [\"HTTP\"], \"opearting_state\": \"RUNNING\", \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {}, \"process\": {}}, \"e9afc0bc-fb21-48a3-9868-2ede6a3181dc\": {\"uuid\": \"e9afc0bc-fb21-48a3-9868-2ede6a3181dc\", \"hostname\": \"google_server\", \"operating_state\": 0, \"NICs\": {\"956ce240-8fb3-4fde-8635-ac4ea601a582\": {\"uuid\": \"956ce240-8fb3-4fde-8635-ac4ea601a582\", \"ip_adress\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"c2:1e:48:e1:a4:ad\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"c3f99c30-b493-4fb6-b13e-d2005d851b59\", \"folders\": {\"869eda49-21f2-4fc1-8681-78725cdd5c70\": {\"uuid\": \"869eda49-21f2-4fc1-8681-78725cdd5c70\", \"name\": \"static\", \"size\": 0, \"files\": {}, \"is_quarantined\": false}, \"9fbe0e41-0d6a-4142-9c73-9c0de2dbde6e\": {\"uuid\": \"9fbe0e41-0d6a-4142-9c73-9c0de2dbde6e\", \"name\": \"root\", \"size\": 40.0, \"files\": {\"7d56a563-ecc0-4011-8c97-240dd6c885c0\": {\"uuid\": \"7d56a563-ecc0-4011-8c97-240dd6c885c0\", \"name\": \"favicon.ico\", \"size\": 40.0, \"file_type\": \"PNG\"}}, \"is_quarantined\": false}}}, \"applications\": {}, \"services\": {}, \"process\": {}}, \"47814452-ef47-4e6b-9087-796c438d4698\": {\"uuid\": \"47814452-ef47-4e6b-9087-796c438d4698\", \"num_ports\": 12, \"ports\": {\"1\": {\"uuid\": \"b76fe86f-bb92-4346-8e83-217a2fb0bc67\", \"mac_address\": \"79:2b:4a:70:c3:50\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"2\": {\"uuid\": \"6f8fc6e7-76a4-441a-b7af-441edbdcc6ac\", \"mac_address\": \"1a:2d:12:38:80:2f\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"3\": {\"uuid\": \"1aa75a3c-01f1-4293-9894-5396fa412690\", \"mac_address\": \"d1:7b:36:c1:82:c1\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"4\": {\"uuid\": \"fe6c9f44-59d5-403e-973a-6f19fce7b9b9\", \"mac_address\": \"e3:6b:cc:0c:98:9b\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"5\": {\"uuid\": \"e9e83e37-8537-4884-98a6-87017540078f\", \"mac_address\": \"32:09:c0:4a:f1:20\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"6\": {\"uuid\": \"747f2cd3-8902-4da8-8829-b0b53fe79735\", \"mac_address\": \"e8:20:0b:04:b8:76\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"7\": {\"uuid\": \"88ed129e-0ddb-4d29-ba3c-58d81efe240e\", \"mac_address\": \"7f:b4:f4:2e:b6:71\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"8\": {\"uuid\": \"6c1a4c3c-25d8-46f6-98a8-54073d0ca0d3\", \"mac_address\": \"f6:22:2d:24:b9:71\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"9\": {\"uuid\": \"b2bfc006-6a6b-4701-a75a-27954592d429\", \"mac_address\": \"b6:a5:92:a5:aa:1b\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"10\": {\"uuid\": \"3c607386-87a2-4d0b-ac04-449416ca5b1f\", \"mac_address\": \"b3:75:7d:ce:88:0a\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"11\": {\"uuid\": \"590002c8-27fa-4c31-b17b-7b89dbf8cdf8\", \"mac_address\": \"c0:25:a6:64:52:8e\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"12\": {\"uuid\": \"b7e25eed-547a-4c17-8cb9-8b976ce4bbd9\", \"mac_address\": \"98:50:96:47:ca:bc\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}}, \"mac_address_table\": {}}}, \"links\": {\"a51a4435-20ae-43cf-a151-26e824968b3d\": {\"uuid\": \"a51a4435-20ae-43cf-a151-26e824968b3d\", \"endpoint_a\": \"e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b\", \"endpoint_b\": \"b76fe86f-bb92-4346-8e83-217a2fb0bc67\", \"bandwidth\": 100.0, \"current_load\": 0.0}, \"ae3486e5-f78e-4092-96d1-d7e8176f2b7d\": {\"uuid\": \"ae3486e5-f78e-4092-96d1-d7e8176f2b7d\", \"endpoint_a\": \"956ce240-8fb3-4fde-8635-ac4ea601a582\", \"endpoint_b\": \"6f8fc6e7-76a4-441a-b7af-441edbdcc6ac\", \"bandwidth\": 100.0, \"current_load\": 0.0}}}, \"domain\": {\"uuid\": \"ae0423ee-51fa-41e7-be80-c642b39707f6\", \"accounts\": {\"917eda28-9a67-4449-bddd-87e2141a3162\": {\"uuid\": \"917eda28-9a67-4449-bddd-87e2141a3162\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": \"USER\", \"enabled\": true}}}}'" ] }, "execution_count": 16, From c6f71600fc39c2b58bee837b6ed99db0fbcfec18 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 25 Aug 2023 09:07:32 +0100 Subject: [PATCH 120/980] #1800 - Fixed the ping functionality so that it actually checks for replies and returns True if the right number of replies have been received. - Added the foundations of a Router class along with ACLRule and RouteTableEntry classes. --- .../simulator/network/hardware/base.py | 25 ++++-- .../network/hardware/nodes/router.py | 86 +++++++++++++++++++ .../network/test_frame_transmission.py | 4 +- .../integration_tests/network/test_routing.py | 27 ++++++ 4 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 src/primaite/simulator/network/hardware/nodes/router.py create mode 100644 tests/integration_tests/network/test_routing.py diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 28e7693a..c64b9b67 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -173,6 +173,9 @@ class NIC(SimComponent): if self.connected_node.operating_state != NodeOperatingState.ON: self.connected_node.sys_log.error(f"NIC {self} cannot be enabled as the endpoint is not turned on") return + if not self.connected_link: + _LOGGER.error(f"NIC {self} cannot be enabled as it is not connected to a Link") + return self.enabled = True self.connected_node.sys_log.info(f"NIC {self} enabled") @@ -210,6 +213,7 @@ class NIC(SimComponent): # TODO: Inform the Node that a link has been connected self.connected_link = link + self.enable() _LOGGER.info(f"NIC {self} connected to Link {link}") def disconnect_link(self): @@ -266,8 +270,10 @@ class NIC(SimComponent): frame.decrement_ttl() frame.set_received_timestamp() self.pcap.capture(frame) - self.connected_node.receive_frame(frame=frame, from_nic=self) - return True + # If this destination or is broadcast + if frame.ethernet.dst_mac_addr == self.mac_address or frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": + self.connected_node.receive_frame(frame=frame, from_nic=self) + return True return False def __str__(self) -> str: @@ -688,7 +694,6 @@ class ARPCache: frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) from_nic.send_frame(frame) - class ICMP: """ The ICMP (Internet Control Message Protocol) class. @@ -705,6 +710,8 @@ class ICMP: """ self.sys_log: SysLog = sys_log self.arp: ARPCache = arp_cache + self.request_replies = {} + def process_icmp(self, frame: Frame): """ @@ -733,6 +740,9 @@ class ICMP: src_nic.send_frame(frame) elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: self.sys_log.info(f"Received echo reply from {frame.ip.src_ip}") + if not self.request_replies.get(frame.icmp.identifier): + self.request_replies[frame.icmp.identifier] = 0 + self.request_replies[frame.icmp.identifier] += 1 def ping( self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None @@ -875,7 +885,7 @@ class Node(SimComponent): return state def show(self): - """Prints a table of the NICs on the Node..""" + """Prints a table of the NICs on the Node.""" from prettytable import PrettyTable table = PrettyTable(["MAC Address", "Address", "Default Gateway", "Speed", "Status"]) @@ -898,7 +908,8 @@ class Node(SimComponent): self.operating_state = NodeOperatingState.ON self.sys_log.info("Turned on") for nic in self.nics.values(): - nic.enable() + if nic.connected_link: + nic.enable() def power_off(self): """Power off the Node, disabling its NICs if it is in the ON state.""" @@ -961,7 +972,9 @@ class Node(SimComponent): sequence, identifier = 0, None while sequence < pings: sequence, identifier = self.icmp.ping(target_ip_address, sequence, identifier) - return True + passed = self.icmp.request_replies[identifier] == pings + self.icmp.request_replies.pop(identifier) + return passed self.sys_log.info("Ping failed as the node is turned off") return False diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py new file mode 100644 index 00000000..c5620b88 --- /dev/null +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -0,0 +1,86 @@ +from enum import Enum +from ipaddress import IPv4Address +from typing import Dict, List, Union + +from primaite.simulator.core import SimComponent +from primaite.simulator.network.hardware.base import Node, NIC +from prettytable import PrettyTable + +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port + + +class ACLAction(Enum): + DENY = 0 + PERMIT = 1 + + +class ACLRule(SimComponent): + action: ACLAction + protocol: IPProtocol + src_ip: IPv4Address + src_wildcard: IPv4Address = IPv4Address("0.0.0.0") + src_port: Port + dst_ip: IPv4Address + dst_port: Port + + +class RouteTableEntry(SimComponent): + pass + + +class Router(Node): + num_ports: int + ethernet_ports: Dict[int, NIC] = {} + acl: List = [] + route_table: Dict = {} + + def __init__(self, hostname: str, num_ports: int = 5, **kwargs): + super().__init__(hostname=hostname, num_ports=num_ports, **kwargs) + + for i in range(1, self.num_ports + 1): + nic = NIC(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") + self.connect_nic(nic) + self.ethernet_ports[i] = nic + + def describe_state(self) -> Dict: + pass + + def configure_port( + self, + port: int, + ip_address: Union[IPv4Address, str], + subnet_mask: str + ): + if not isinstance(ip_address, IPv4Address): + ip_address = IPv4Address(ip_address) + nic = self.ethernet_ports[port] + nic.ip_address = ip_address + nic.subnet_mask = subnet_mask + self.sys_log.info(f"Configured port {port} with {ip_address=} {subnet_mask=}") + + def enable_port(self, port: int): + nic = self.ethernet_ports.get(port) + if nic: + nic.enable() + + def disable_port(self, port: int): + nic = self.ethernet_ports.get(port) + if nic: + nic.disable() + + def show(self): + """Prints a table of the NICs on the Node.""" + table = PrettyTable(["Port", "MAC Address", "Address", "Speed", "Status"]) + + for port, nic in self.ethernet_ports.items(): + table.add_row( + [ + port, + nic.mac_address, + f"{nic.ip_address}/{nic.ip_network.prefixlen}", + nic.speed, + "Enabled" if nic.enabled else "Disabled", + ] + ) + print(table) diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index 3840c302..d3d6541a 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -45,7 +45,7 @@ def test_multi_nic(): node_a.ping("192.168.0.11") - node_c.ping("10.0.0.12") + assert node_c.ping("10.0.0.12") def test_switched_network(): @@ -83,4 +83,4 @@ def test_switched_network(): link_nic_d_switch_2 = Link(endpoint_a=nic_d, endpoint_b=switch_2.switch_ports[2]) link_switch_1_switch_2 = Link(endpoint_a=switch_1.switch_ports[6], endpoint_b=switch_2.switch_ports[6]) - pc_a.ping("192.168.0.13") + assert pc_a.ping("192.168.0.13") diff --git a/tests/integration_tests/network/test_routing.py b/tests/integration_tests/network/test_routing.py new file mode 100644 index 00000000..cca48c0d --- /dev/null +++ b/tests/integration_tests/network/test_routing.py @@ -0,0 +1,27 @@ +from primaite.simulator.network.hardware.base import Node, NIC, Link +from primaite.simulator.network.hardware.nodes.router import Router + + +def test_ping_fails_with_no_route(): + """Tests a larges network of Nodes and Switches with one node pinging another.""" + pc_a = Node(hostname="pc_a") + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") + pc_a.connect_nic(nic_a) + pc_a.power_on() + + pc_b = Node(hostname="pc_b") + nic_b = NIC(ip_address="192.168.1.10", subnet_mask="255.255.255.0", gateway="192.168.1.1") + pc_b.connect_nic(nic_b) + pc_b.power_on() + + router_1 = Router(hostname="router_1") + router_1.configure_port(1, "192.168.0.1", "255.255.255.0") + router_1.configure_port(2, "192.168.1.1", "255.255.255.0") + + router_1.power_on() + router_1.show() + + link_nic_a_router_1 = Link(endpoint_a=nic_a, endpoint_b=router_1.ethernet_ports[1]) + link_nic_b_router_1 = Link(endpoint_a=nic_b, endpoint_b=router_1.ethernet_ports[2]) + router_1.power_on() + #assert pc_a.ping("192.168.1.10") \ No newline at end of file From a9e969aa13cc5d824356a451f32fb7ae9d8d4de6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 25 Aug 2023 15:29:53 +0100 Subject: [PATCH 121/980] init work on database --- .../file_system/file_system_file_type.py | 8 ++++ .../simulator/system/services/database.py | 41 +++++++++++++++++++ .../simulator/system/services/service.py | 12 ++++++ 3 files changed, 61 insertions(+) create mode 100644 src/primaite/simulator/system/services/database.py diff --git a/src/primaite/simulator/file_system/file_system_file_type.py b/src/primaite/simulator/file_system/file_system_file_type.py index 7e2d8706..88aeb430 100644 --- a/src/primaite/simulator/file_system/file_system_file_type.py +++ b/src/primaite/simulator/file_system/file_system_file_type.py @@ -87,6 +87,14 @@ class FileSystemFileType(str, Enum): GZ = 31 "Gzip compressed file." + # Database file types + MDF = 32 + "MS SQL Server primary database file" + NDF = 33 + "MS SQL Server secondary database file" + LDF = 34 + "MS SQL Server transaction log" + file_type_sizes_KB = { FileSystemFileType.UNKNOWN: 0, diff --git a/src/primaite/simulator/system/services/database.py b/src/primaite/simulator/system/services/database.py new file mode 100644 index 00000000..29e3f242 --- /dev/null +++ b/src/primaite/simulator/system/services/database.py @@ -0,0 +1,41 @@ +from primaite.simulator.file_system.file_system_file_type import FileSystemFileType +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.system.services.service import Service + + +class DatabaseService(Service): + """TODO.""" + + def __init__(self, parent_node: Node, **kwargs): + super().__init__(**kwargs) + self._setup_files_on_node() + + def _setup_files_on_node( + self, + db_size: int = 1000, + use_secondary_db_file: bool = False, + secondary_db_size: int = 300, + folder_name: str = "database", + ): + """Set up files that are required by the database on the parent host. + + :param db_size: Initial file size of the main database file, defaults to 1000 + :type db_size: int, optional + :param use_secondary_db_file: Whether to use a secondary database file, defaults to False + :type use_secondary_db_file: bool, optional + :param secondary_db_size: Size of the secondary db file, defaults to None + :type secondary_db_size: int, optional + :param folder_name: Name of the folder which will be setup to hold the db files, defaults to "database" + :type folder_name: str, optional + """ + folder = self.parent.file_system.create_folder(folder_name) + self.parent.file_system.create_file("db_primary_store", db_size, FileSystemFileType.MDF, folder=folder) + self.parent.file_system.create_file("db_transaction_log", "1", FileSystemFileType.LDF, folder=folder) + if use_secondary_db_file: + self.parent.file_system.create_file( + "db_secondary_store", secondary_db_size, FileSystemFileType.NDF, folder=folder + ) + + # todo next: + # create session? (maybe not) + # add actions for setting service state to compromised? (probably definitely) diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index eafff3f0..ed2aa23b 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -2,6 +2,7 @@ from abc import abstractmethod from enum import Enum from typing import Any, Dict, List +from primaite.simulator.network.hardware.base import Node from primaite.simulator.system.software import IOSoftware @@ -32,6 +33,17 @@ class Service(IOSoftware): operating_state: ServiceOperatingState "The current operating state of the Service." + @abstractmethod + def __init__(self, parent_node: Node, **kwargs): + """Create the service on a node. + + :param parent_node: The node on which this service runs. + :type parent_node: Node + """ + super().__init__(**kwargs) + self.parent: Node = parent_node + self.parent.software_manager.add_service(self) + @abstractmethod def describe_state(self) -> Dict: """ From ae6e835955136c815eb496efa2bcb2f4329b0af6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 25 Aug 2023 15:58:07 +0100 Subject: [PATCH 122/980] Apply suggestions from code review. --- src/primaite/simulator/network/container.py | 35 +++++++++---------- .../simulator/network/hardware/base.py | 2 +- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 1c03358c..85676034 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -52,11 +52,11 @@ class Network(SimComponent): :type node: Node """ if node in self: - msg = f"Can't add node {node}. It is already in the network." - _LOGGER.warning(msg) - raise RuntimeWarning(msg) + _LOGGER.warning(f"Can't add node {node.uuid}. It is already in the network.") + return self.nodes[node.uuid] = node node.parent = self + _LOGGER.info(f"Added node {node.uuid} to Network {self.uuid}") def remove_node(self, node: Node) -> None: """ @@ -66,11 +66,11 @@ class Network(SimComponent): :type node: Node """ if node not in self: - msg = f"Can't remove node {node}. It's not in the network." - _LOGGER.warning(msg) - raise RuntimeWarning(msg) - del self.nodes[node.uuid] - del node.parent # misleading? + _LOGGER.warning(f"Can't remove node {node.uuid}. It's not in the network.") + return + self.nodes.pop(node.uuid) + node.parent = None + _LOGGER.info(f"Removed node {node.uuid} from network {self.uuid}") def connect(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> None: """Connect two nodes on the network by creating a link between an NIC/SwitchPort of each one. @@ -83,20 +83,18 @@ class Network(SimComponent): """ node_a = endpoint_a.parent node_b = endpoint_b.parent - msg = "" if node_a not in self: - msg = f"Cannot create a link to {endpoint_a} because the node is not in the network." + self.add_node(node_a) if node_b not in self: - msg = f"Cannot create a link to {endpoint_b} because the node is not in the network." + self.add_node(node_b) if node_a is node_b: - msg = f"Cannot link {endpoint_a} to {endpoint_b} because they belong to the same node." - if msg: - _LOGGER.error(msg) - raise RuntimeError(msg) + _LOGGER.warn(f"Cannot link endpoint {endpoint_a} to {endpoint_b} because they belong to the same node.") + return link = Link(endpoint_a=endpoint_a, endpoint_b=endpoint_b, **kwargs) self.links[link.uuid] = link link.parent = self + _LOGGER.info(f"Added link {link.uuid} to connect {endpoint_a} and {endpoint_b}") def remove_link(self, link: Link) -> None: """Disconnect a link from the network. @@ -106,12 +104,13 @@ class Network(SimComponent): """ link.endpoint_a.disconnect_link() link.endpoint_b.disconnect_link() - del self.links[link.uuid] - del link.parent + self.links.pop(link.uuid) + link.parent = None + _LOGGER.info(f"Removed link {link.uuid} from network {self.uuid}.") def __contains__(self, item: Any) -> bool: if isinstance(item, Node): return item.uuid in self.nodes elif isinstance(item, Link): return item.uuid in self.links - raise TypeError("") + return False diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index fe3b5b15..9acdf0b4 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -939,7 +939,7 @@ class Node(SimComponent): nic = self.nics.get(nic) if nic or nic.uuid in self.nics: self.nics.pop(nic.uuid) - del nic.parent + nic.parent = None nic.disable() self.sys_log.info(f"Disconnected NIC {nic}") else: From 6e602aa1514b92dc34ec7324d96bdd58fc72efdb Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 25 Aug 2023 17:56:05 +0100 Subject: [PATCH 123/980] Fix unit tests by removing warning checks --- src/primaite/simulator/core.py | 8 ++--- .../network/test_network_creation.py | 29 ++++++++++++++----- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 63120ecf..b7dfcf72 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -1,6 +1,6 @@ """Core of the PrimAITE Simulator.""" from abc import ABC, abstractmethod -from typing import Callable, Dict, List, Optional +from typing import Callable, Dict, List, Optional, Union from uuid import uuid4 from pydantic import BaseModel, ConfigDict, Extra @@ -199,9 +199,9 @@ class SimComponent(BaseModel): return self._parent @parent.setter - def parent(self, new_parent: "SimComponent") -> None: - if self._parent: - msg = f"Overwriting parent of {self}, {self._parent} with {new_parent}" + def parent(self, new_parent: Union["SimComponent", None]) -> None: + if self._parent and new_parent: + msg = f"Overwriting parent of {self.uuid}. Old parent: {self._parent.uuid}, New parent: {new_parent.uuid}" _LOGGER.warn(msg) raise RuntimeWarning(msg) self._parent = new_parent diff --git a/tests/integration_tests/network/test_network_creation.py b/tests/integration_tests/network/test_network_creation.py index 418f5e5f..356eb1db 100644 --- a/tests/integration_tests/network/test_network_creation.py +++ b/tests/integration_tests/network/test_network_creation.py @@ -22,8 +22,7 @@ def test_readding_node(): net = Network() n1 = Node(hostname="computer") net.add_node(n1) - with pytest.raises(RuntimeWarning): - net.add_node(n1) + net.add_node(n1) assert n1.parent is net assert n1 in net @@ -32,8 +31,7 @@ def test_removing_nonexistent_node(): """Check that warning is raised when trying to remove a node that is not in the network.""" net = Network() n1 = Node(hostname="computer") - with pytest.raises(RuntimeWarning): - net.remove_node(n1) + net.remove_node(n1) assert n1.parent is None assert n1 not in net @@ -69,8 +67,7 @@ def test_connecting_node_to_itself(): net.add_node(node) - with pytest.raises(RuntimeError): - net.connect(node.nics[nic1.uuid], node.nics[nic2.uuid], bandwidth=30) + net.connect(node.nics[nic1.uuid], node.nics[nic2.uuid], bandwidth=30) assert node in net assert nic1.connected_link is None @@ -79,4 +76,22 @@ def test_connecting_node_to_itself(): def test_disconnecting_nodes(): - ... + net = Network() + + n1 = Node(hostname="computer") + n1_nic = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0") + n1.connect_nic(n1_nic) + net.add_node(n1) + + n2 = Node(hostname="server") + n2_nic = NIC(ip_address="120.30.0.2", gateway="192.168.0.1", subnet_mask="255.255.255.0") + n2.connect_nic(n2_nic) + net.add_node(n2) + + net.connect(n1.nics[n1_nic.uuid], n2.nics[n2_nic.uuid], bandwidth=30) + assert len(net.links) == 1 + + link = list(net.links.values())[0] + net.remove_link(link) + assert link not in net + assert len(net.links) == 0 From 319e87d200e81da1b33437c5f545f395ae063028 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 28 Aug 2023 22:34:20 +0100 Subject: [PATCH 124/980] Make changes to the way actions work --- src/primaite/simulator/core.py | 24 ++++++++++++- src/primaite/simulator/domain/controller.py | 24 +++++++------ src/primaite/simulator/network/container.py | 21 +++++++----- src/primaite/simulator/sim_container.py | 34 ++++++++++--------- .../system/applications/application.py | 10 +----- .../simulator/system/services/database.py | 2 ++ .../simulator/system/services/service.py | 12 ------- src/primaite/simulator/system/software.py | 26 +++++++------- 8 files changed, 83 insertions(+), 70 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 63120ecf..7d8999e8 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -136,7 +136,7 @@ class SimComponent(BaseModel): if not kwargs.get("uuid"): kwargs["uuid"] = str(uuid4()) super().__init__(**kwargs) - self.action_manager: Optional[ActionManager] = None + self._action_manager: ActionManager = self._init_action_manager() self._parent: Optional["SimComponent"] = None @abstractmethod @@ -153,6 +153,28 @@ class SimComponent(BaseModel): } return state + def _init_action_manager(self) -> ActionManager: + """ + Initialise the action manager for this component. + + When using a hierarchy of components, the child classes should call the parent class's _init_action_manager and + add additional actions on top of the existing generic ones. + + Example usage for inherited classes: + + ..code::python + + class WebBrowser(Application): + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() # all actions generic to any Application get initialised + am.add_action(...) # initialise any actions specific to the web browser + return am + + :return: Actiona manager object belonging to this sim component. + :rtype: ActionManager + """ + return ActionManager() + def apply_action(self, action: List[str], context: Dict = {}) -> None: """ Apply an action to a simulation component. Action data is passed in as a 'namespaced' list of strings. diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index f772ab22..961ef550 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -85,17 +85,6 @@ class DomainController(SimComponent): def __init__(self, **kwargs): super().__init__(**kwargs) - self.action_manager = ActionManager() - # Action 'account' matches requests like: - # ['account', '', *account_action] - self.action_manager.add_action( - "account", - Action( - func=lambda request, context: self.accounts[request.pop(0)].apply_action(request, context), - validator=GroupMembershipValidator([AccountGroup.DOMAIN_ADMIN]), - ), - ) - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -109,6 +98,19 @@ class DomainController(SimComponent): state.update({"accounts": {uuid: acct.describe_state() for uuid, acct in self.accounts.items()}}) return state + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + # Action 'account' matches requests like: + # ['account', '', *account_action] + am.add_action( + "account", + Action( + func=lambda request, context: self.accounts[request.pop(0)].apply_action(request, context), + validator=GroupMembershipValidator([AccountGroup.DOMAIN_ADMIN]), + ), + ) + return am + def _register_account(self, account: Account) -> None: """TODO.""" ... diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 1c03358c..d04da987 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -17,15 +17,6 @@ class Network(SimComponent): """Initialise the network.""" super().__init__(**kwargs) - self.action_manager = ActionManager() - self.action_manager.add_action( - "node", - Action( - func=lambda request, context: self.nodes[request.pop(0)].apply_action(request, context), - validator=AllowAllValidator(), - ), - ) - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -44,6 +35,18 @@ class Network(SimComponent): ) return state + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + + am.add_action( + "node", + Action( + func=lambda request, context: self.nodes[request.pop(0)].apply_action(request, context), + validator=AllowAllValidator(), + ), + ) + return am + def add_node(self, node: Node) -> None: """ Add an existing node to the network. diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index 319defe4..8f676e6f 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -21,22 +21,6 @@ class Simulation(SimComponent): super().__init__(**kwargs) - self.action_manager = ActionManager() - # pass through network actions to the network objects - self.action_manager.add_action( - "network", - Action( - func=lambda request, context: self.network.apply_action(request, context), validator=AllowAllValidator() - ), - ) - # pass through domain actions to the domain object - self.action_manager.add_action( - "domain", - Action( - func=lambda request, context: self.domain.apply_action(request, context), validator=AllowAllValidator() - ), - ) - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -54,3 +38,21 @@ class Simulation(SimComponent): } ) return state + + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + # pass through network actions to the network objects + am.add_action( + "network", + Action( + func=lambda request, context: self.network.apply_action(request, context), validator=AllowAllValidator() + ), + ) + # pass through domain actions to the domain object + am.add_action( + "domain", + Action( + func=lambda request, context: self.domain.apply_action(request, context), validator=AllowAllValidator() + ), + ) + return am diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 37748560..6a07f00f 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -1,6 +1,6 @@ from abc import abstractmethod from enum import Enum -from typing import Any, Dict, List, Set +from typing import Any, Dict, Set from primaite.simulator.system.software import IOSoftware @@ -53,14 +53,6 @@ class Application(IOSoftware): ) return state - def apply_action(self, action: List[str]) -> None: - """ - Applies a list of actions to the Application. - - :param action: A list of actions to apply. - """ - pass - def reset_component_for_episode(self, episode: int): """ Resets the Application component for a new episode. diff --git a/src/primaite/simulator/system/services/database.py b/src/primaite/simulator/system/services/database.py index 29e3f242..720967e7 100644 --- a/src/primaite/simulator/system/services/database.py +++ b/src/primaite/simulator/system/services/database.py @@ -28,6 +28,8 @@ class DatabaseService(Service): :param folder_name: Name of the folder which will be setup to hold the db files, defaults to "database" :type folder_name: str, optional """ + # note that this parent.file_system.create_folder call in the future will be authenticated by using permissions + # handler. This permission will be granted based on service account given to the database service. folder = self.parent.file_system.create_folder(folder_name) self.parent.file_system.create_file("db_primary_store", db_size, FileSystemFileType.MDF, folder=folder) self.parent.file_system.create_file("db_transaction_log", "1", FileSystemFileType.LDF, folder=folder) diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index ed2aa23b..eafff3f0 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -2,7 +2,6 @@ from abc import abstractmethod from enum import Enum from typing import Any, Dict, List -from primaite.simulator.network.hardware.base import Node from primaite.simulator.system.software import IOSoftware @@ -33,17 +32,6 @@ class Service(IOSoftware): operating_state: ServiceOperatingState "The current operating state of the Service." - @abstractmethod - def __init__(self, parent_node: Node, **kwargs): - """Create the service on a node. - - :param parent_node: The node on which this service runs. - :type parent_node: Node - """ - super().__init__(**kwargs) - self.parent: Node = parent_node - self.parent.software_manager.add_service(self) - @abstractmethod def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index a2acd9fb..8e931cad 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -1,6 +1,6 @@ from abc import abstractmethod from enum import Enum -from typing import Any, Dict, List, Set +from typing import Any, Dict, Set from primaite.simulator.core import SimComponent from primaite.simulator.network.transmission.transport_layer import Port @@ -98,17 +98,6 @@ class Software(SimComponent): ) return state - def apply_action(self, action: List[str]) -> None: - """ - Applies a list of actions to the software. - - The specifics of how these actions are applied should be implemented in subclasses. - - :param action: A list of actions to apply. - :type action: List[str] - """ - pass - def reset_component_for_episode(self, episode: int): """ Resets the software component for a new episode. @@ -119,6 +108,19 @@ class Software(SimComponent): """ pass + def set_health_state(self, health_state: SoftwareHealthState) -> None: + """ + Assign a new health state to this software. + + Note: this should only be possible when the software is currently running, but the software base class has no + operating state, only subclasses do. So subclasses will need to implement this check. TODO: check if this should + be changed so that the base Software class has a running attr. + + :param health_state: New health state to assign to the software + :type health_state: SoftwareHealthState + """ + self.health_state_actual = health_state + class IOSoftware(Software): """ From 1eff41c7861cb6aa53fee877b44762e56c16826f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 29 Aug 2023 11:10:29 +0100 Subject: [PATCH 125/980] Update docs based on new action options --- docs/source/simulation_structure.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/source/simulation_structure.rst b/docs/source/simulation_structure.rst index 7630ae0f..f3ef866c 100644 --- a/docs/source/simulation_structure.rst +++ b/docs/source/simulation_structure.rst @@ -49,16 +49,14 @@ snippet demonstrates usage of the ``ActionPermissionValidator``. name: str apps = [] - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.action_manager = ActionManager() - - self.action_manager.add_action( + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + am.add_action( "reset_factory_settings", Action( func = lambda request, context: self.reset_factory_settings(), validator = GroupMembershipValidator([AccountGroup.DOMAIN_ADMIN]), - ), + ) ) def reset_factory_settings(self): From 7b61322e704b06da9ef797162ba0021df25ed116 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 29 Aug 2023 12:34:41 +0100 Subject: [PATCH 126/980] Add service actions --- src/primaite/simulator/core.py | 7 +- .../simulator/system/services/service.py | 79 +++++++++++++++++-- src/primaite/simulator/system/software.py | 17 +++- 3 files changed, 92 insertions(+), 11 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 7d8999e8..90abb675 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -41,7 +41,9 @@ class Action: the action can be performed or not. """ - def __init__(self, func: Callable[[List[str], Dict], None], validator: ActionPermissionValidator) -> None: + def __init__( + self, func: Callable[[List[str], Dict], None], validator: ActionPermissionValidator = AllowAllValidator() + ) -> None: """ Save the functions that are for this action. @@ -58,7 +60,8 @@ class Action: :param func: Function that performs the request. :type func: Callable[[List[str], Dict], None] - :param validator: Function that checks if the request is authenticated given the context. + :param validator: Function that checks if the request is authenticated given the context. By default, if no + validator is provided, an 'allow all' validator is added which permits all requests. :type validator: ActionPermissionValidator """ self.func: Callable[[List[str], Dict], None] = func diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index eafff3f0..1a36589f 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,7 +1,8 @@ from abc import abstractmethod from enum import Enum -from typing import Any, Dict, List +from typing import Any, Dict +from primaite.simulator.core import Action, ActionManager from primaite.simulator.system.software import IOSoftware @@ -46,13 +47,16 @@ class Service(IOSoftware): state.update({"operating_state": self.operating_state.name}) return state - def apply_action(self, action: List[str]) -> None: - """ - Applies a list of actions to the Service. - - :param action: A list of actions to apply. - """ - pass + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + am.add_action("stop", Action(func=lambda request, context: self.stop())) + am.add_action("start", Action(func=lambda request, context: self.start())) + am.add_action("pause", Action(func=lambda request, context: self.pause())) + am.add_action("resume", Action(func=lambda request, context: self.resume())) + am.add_action("restart", Action(func=lambda request, context: self.restart())) + am.add_action("disable", Action(func=lambda request, context: self.disable())) + am.add_action("enable", Action(func=lambda request, context: self.enable())) + return am def reset_component_for_episode(self, episode: int): """ @@ -86,3 +90,62 @@ class Service(IOSoftware): :return: True if successful, False otherwise. """ pass + + # TODO: validate this state transition model. + # Possibly state transition could be defined more succinctly than a separate function with lots of if statements. + + def stop(self) -> None: + """Stop the service.""" + if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: + self.operating_state = ServiceOperatingState.STOPPED + + def start(self) -> None: + """Start the service.""" + if self.operating_state == ServiceOperatingState.STOPPED: + self.operating_state = ServiceOperatingState.RUNNING + + def pause(self) -> None: + """Pause the service.""" + if self.operating_state == ServiceOperatingState.RUNNING: + self.operating_state = ServiceOperatingState.PAUSED + + def resume(self) -> None: + """Resume paused service.""" + if self.operating_state == ServiceOperatingState.PAUSED: + self.operating_state = ServiceOperatingState.RUNNING + + def restart(self) -> None: + """Restart running service.""" + if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: + self.operating_state = ServiceOperatingState.RESTARTING + self.restart_countdown = 5 # TODO: implement restart duration + + def disable(self) -> None: + """Disable the service.""" + if self.operating_state in [ + ServiceOperatingState.RUNNING, + ServiceOperatingState.STOPPED, + ServiceOperatingState.PAUSED, + ]: + self.operating_state = ServiceOperatingState.DISABLED + + def enable(self) -> None: + """Enable the disabled service.""" + if self.operating_state == ServiceOperatingState.DISABLED: + self.operating_state = ServiceOperatingState.STOPPED + + def apply_timestep(self, timestep: int) -> None: + """ + Apply a single timestep of simulation dynamics to this service. + + In this instance, if any multi-timestep processes are currently occurring (such as restarting or installation), + then they are brought one step closer to being finished. + + :param timestep: The current timestep number. (Amount of time since simulation episode began) + :type timestep: int + """ + super().apply_timestep(timestep) + if self.operating_state == ServiceOperatingState.RESTARTING: + self.restart_countdown -= 1 + if self.restart_countdown <= 0: + self.operating_state = ServiceOperatingState.RUNNING diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 8e931cad..8db0b0c4 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -2,7 +2,7 @@ from abc import abstractmethod from enum import Enum from typing import Any, Dict, Set -from primaite.simulator.core import SimComponent +from primaite.simulator.core import Action, ActionManager, SimComponent from primaite.simulator.network.transmission.transport_layer import Port @@ -98,6 +98,17 @@ class Software(SimComponent): ) return state + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + am.add_action( + "compromise", + Action( + func=lambda request, context: self.set_health_state(SoftwareHealthState.COMPROMISED), + ), + ) + am.add_action("scan", Action(func=lambda request, context: self.scan())) + return am + def reset_component_for_episode(self, episode: int): """ Resets the software component for a new episode. @@ -121,6 +132,10 @@ class Software(SimComponent): """ self.health_state_actual = health_state + def scan(self) -> None: + """Update the observed health status to match the actual health status.""" + self.health_state_visible = self.health_state_actual + class IOSoftware(Software): """ From 94325d1fde9d8da023836ed437252f03cdaae889 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 29 Aug 2023 13:21:34 +0100 Subject: [PATCH 127/980] Add Install method to software. --- .../simulator/network/hardware/base.py | 35 ++++++++++++++++++- .../simulator/system/services/database.py | 21 ++++++----- src/primaite/simulator/system/software.py | 19 +++++++++- tests/integration_tests/system/__init__.py | 0 .../system/test_database_on_node.py | 22 ++++++++++++ .../_primaite/_simulator/_system/__init__.py | 0 .../_simulator/_system/_services/__init__.py | 0 .../_system/_services/test_database.py | 17 +++++++++ 8 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 tests/integration_tests/system/__init__.py create mode 100644 tests/integration_tests/system/test_database_on_node.py create mode 100644 tests/unit_tests/_primaite/_simulator/_system/__init__.py create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/__init__.py create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index fe3b5b15..41e16936 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -4,7 +4,7 @@ import re import secrets from enum import Enum from ipaddress import IPv4Address, IPv4Network -from typing import Dict, List, Optional, Tuple, Union +from typing import Any, Dict, List, Optional, Tuple, Union from prettytable import PrettyTable @@ -994,6 +994,39 @@ class Node(SimComponent): elif frame.ip.protocol == IPProtocol.ICMP: self.icmp.process_icmp(frame=frame) + def install_service(self, service: Service) -> None: + """ + Install a service on this node. + + :param service: Service instance that has not been installed on any node yet. + :type service: Service + """ + if service in self: + _LOGGER.warning(f"Can't add service {service.uuid} to node {self.uuid}. It's already installed.") + return + service.parent = self + service.install() # Perform any additional setup, such as creating files for this service on the node. + _LOGGER.info(f"Added service {service.uuid} to node {self.uuid}") + + def uninstall_service(self, service: Service) -> None: + """Uninstall and completely remove service from this node. + + :param service: Service object that is currently associated with this node. + :type service: Service + """ + if service not in self: + _LOGGER.warning(f"Can't remove service {service.uuid} from node {self.uuid}. It's not installed.") + return + service.uninstall() # Perform additional teardown, such as removing files or restarting the machine. + self.services.pop(service.uuid) + service.parent = None + _LOGGER.info(f"Removed service {service.uuid} from node {self.uuid}") + + def __contains__(self, item: Any) -> bool: + if isinstance(item, Service): + return item.uuid in self.services + return None + class Switch(Node): """A class representing a Layer 2 network switch.""" diff --git a/src/primaite/simulator/system/services/database.py b/src/primaite/simulator/system/services/database.py index 720967e7..0d1de15c 100644 --- a/src/primaite/simulator/system/services/database.py +++ b/src/primaite/simulator/system/services/database.py @@ -1,3 +1,5 @@ +from typing import Dict + from primaite.simulator.file_system.file_system_file_type import FileSystemFileType from primaite.simulator.network.hardware.base import Node from primaite.simulator.system.services.service import Service @@ -6,11 +8,17 @@ from primaite.simulator.system.services.service import Service class DatabaseService(Service): """TODO.""" - def __init__(self, parent_node: Node, **kwargs): - super().__init__(**kwargs) - self._setup_files_on_node() + def describe_state(self) -> Dict: + """TODO.""" + return super().describe_state() - def _setup_files_on_node( + def install(self) -> None: + """Perform first time install on a node, creating necessary files.""" + super().install() + assert isinstance(self.parent, Node), "Database install can only happen after the db service is added to a node" + self._setup_files() + + def _setup_files( self, db_size: int = 1000, use_secondary_db_file: bool = False, @@ -30,6 +38,7 @@ class DatabaseService(Service): """ # note that this parent.file_system.create_folder call in the future will be authenticated by using permissions # handler. This permission will be granted based on service account given to the database service. + self.parent: Node folder = self.parent.file_system.create_folder(folder_name) self.parent.file_system.create_file("db_primary_store", db_size, FileSystemFileType.MDF, folder=folder) self.parent.file_system.create_file("db_transaction_log", "1", FileSystemFileType.LDF, folder=folder) @@ -37,7 +46,3 @@ class DatabaseService(Service): self.parent.file_system.create_file( "db_secondary_store", secondary_db_size, FileSystemFileType.NDF, folder=folder ) - - # todo next: - # create session? (maybe not) - # add actions for setting service state to compromised? (probably definitely) diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 8db0b0c4..17eaee3d 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -1,10 +1,13 @@ from abc import abstractmethod from enum import Enum -from typing import Any, Dict, Set +from typing import Any, Dict, Set, TYPE_CHECKING from primaite.simulator.core import Action, ActionManager, SimComponent from primaite.simulator.network.transmission.transport_layer import Port +if TYPE_CHECKING: + from primaite.simulator.network.hardware.base import Node + class SoftwareType(Enum): """ @@ -132,6 +135,20 @@ class Software(SimComponent): """ self.health_state_actual = health_state + @abstractmethod + def install(self) -> None: + """ + Perform first-time setup of this service on a node. + + This is an abstract class that should be overwritten by specific applications or services. It must be called + after the service is already associate with a node. For example, a service may need to authenticate with a + server during installation, or create files in the node's filesystem. + + :param node: Node on which this software runs. + :type node: Node + """ + parent: "Node" = self.parent # noqa + def scan(self) -> None: """Update the observed health status to match the actual health status.""" self.health_state_visible = self.health_state_actual diff --git a/tests/integration_tests/system/__init__.py b/tests/integration_tests/system/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py new file mode 100644 index 00000000..f295eaf1 --- /dev/null +++ b/tests/integration_tests/system/test_database_on_node.py @@ -0,0 +1,22 @@ +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.database import DatabaseService +from primaite.simulator.system.services.service import ServiceOperatingState +from primaite.simulator.system.software import SoftwareCriticality, SoftwareHealthState + + +def test_installing_database(): + db = DatabaseService( + name="SQL-database", + health_state_actual=SoftwareHealthState.GOOD, + health_state_visible=SoftwareHealthState.GOOD, + criticality=SoftwareCriticality.MEDIUM, + ports=[ + Port.SQL_SERVER, + ], + operating_state=ServiceOperatingState.RUNNING, + ) + + node = Node(hostname="db-server") + + node.install_service(db) diff --git a/tests/unit_tests/_primaite/_simulator/_system/__init__.py b/tests/unit_tests/_primaite/_simulator/_system/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/__init__.py b/tests/unit_tests/_primaite/_simulator/_system/_services/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py new file mode 100644 index 00000000..ea5c1b83 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py @@ -0,0 +1,17 @@ +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.database import DatabaseService +from primaite.simulator.system.services.service import ServiceOperatingState +from primaite.simulator.system.software import SoftwareCriticality, SoftwareHealthState + + +def test_creation(): + db = DatabaseService( + name="SQL-database", + health_state_actual=SoftwareHealthState.GOOD, + health_state_visible=SoftwareHealthState.GOOD, + criticality=SoftwareCriticality.MEDIUM, + ports=[ + Port.SQL_SERVER, + ], + operating_state=ServiceOperatingState.RUNNING, + ) From f0b82cbdfba6070217eee4011c9c14aaab5f6f38 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 29 Aug 2023 14:15:49 +0100 Subject: [PATCH 128/980] Add ability to uninstall service --- .../simulator/file_system/file_system.py | 4 +-- .../simulator/network/hardware/base.py | 1 + .../simulator/system/services/database.py | 31 ++++++++++++++--- src/primaite/simulator/system/software.py | 19 ++++++----- .../system/test_database_on_node.py | 34 +++++++++++++++++++ 5 files changed, 74 insertions(+), 15 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 440b7dc5..1346d3e0 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -1,5 +1,5 @@ from random import choice -from typing import Dict, Optional +from typing import Dict, Optional, Union from primaite import getLogger from primaite.simulator.core import SimComponent @@ -211,7 +211,7 @@ class FileSystem(SimComponent): if file is not None: return file - def get_folder_by_name(self, folder_name: str) -> FileSystemFolder: + def get_folder_by_name(self, folder_name: str) -> Union[FileSystemFolder, None]: """ Returns a the first folder with a matching name. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index a68ff480..e3e38f86 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1004,6 +1004,7 @@ class Node(SimComponent): if service in self: _LOGGER.warning(f"Can't add service {service.uuid} to node {self.uuid}. It's already installed.") return + self.services[service.uuid] = service service.parent = self service.install() # Perform any additional setup, such as creating files for this service on the node. _LOGGER.info(f"Added service {service.uuid} to node {self.uuid}") diff --git a/src/primaite/simulator/system/services/database.py b/src/primaite/simulator/system/services/database.py index 0d1de15c..554455b8 100644 --- a/src/primaite/simulator/system/services/database.py +++ b/src/primaite/simulator/system/services/database.py @@ -12,6 +12,21 @@ class DatabaseService(Service): """TODO.""" return super().describe_state() + def uninstall(self) -> None: + """ + Undo installation procedure. + + This method deletes files created when installing the database, and the database folder if it is empty. + """ + super().uninstall() + node: Node = self.parent + node.file_system.delete_file(self.primary_store) + node.file_system.delete_file(self.transaction_log) + if self.secondary_store: + node.file_system.delete_file(self.secondary_store) + if len(self.folder.files) == 0: + node.file_system.delete_folder(self.folder) + def install(self) -> None: """Perform first time install on a node, creating necessary files.""" super().install() @@ -39,10 +54,16 @@ class DatabaseService(Service): # note that this parent.file_system.create_folder call in the future will be authenticated by using permissions # handler. This permission will be granted based on service account given to the database service. self.parent: Node - folder = self.parent.file_system.create_folder(folder_name) - self.parent.file_system.create_file("db_primary_store", db_size, FileSystemFileType.MDF, folder=folder) - self.parent.file_system.create_file("db_transaction_log", "1", FileSystemFileType.LDF, folder=folder) + self.folder = self.parent.file_system.create_folder(folder_name) + self.primary_store = self.parent.file_system.create_file( + "db_primary_store", db_size, FileSystemFileType.MDF, folder=self.folder + ) + self.transaction_log = self.parent.file_system.create_file( + "db_transaction_log", "1", FileSystemFileType.LDF, folder=self.folder + ) if use_secondary_db_file: - self.parent.file_system.create_file( - "db_secondary_store", secondary_db_size, FileSystemFileType.NDF, folder=folder + self.secondary_store = self.parent.file_system.create_file( + "db_secondary_store", secondary_db_size, FileSystemFileType.NDF, folder=self.folder ) + else: + self.secondary_store = None diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 17eaee3d..1fcdb522 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -1,13 +1,10 @@ from abc import abstractmethod from enum import Enum -from typing import Any, Dict, Set, TYPE_CHECKING +from typing import Any, Dict, Set from primaite.simulator.core import Action, ActionManager, SimComponent from primaite.simulator.network.transmission.transport_layer import Port -if TYPE_CHECKING: - from primaite.simulator.network.hardware.base import Node - class SoftwareType(Enum): """ @@ -143,11 +140,17 @@ class Software(SimComponent): This is an abstract class that should be overwritten by specific applications or services. It must be called after the service is already associate with a node. For example, a service may need to authenticate with a server during installation, or create files in the node's filesystem. - - :param node: Node on which this software runs. - :type node: Node """ - parent: "Node" = self.parent # noqa + pass + + def uninstall(self) -> None: + """Uninstall this service from a node. + + This is an abstract class that should be overwritten by applications or services. It must be called after the + `install` method has already been run on that node. It should undo any installation steps, for example by + deleting files, or contacting a server. + """ + pass def scan(self) -> None: """Update the observed health status to match the actual health status.""" diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index f295eaf1..73d19339 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -20,3 +20,37 @@ def test_installing_database(): node = Node(hostname="db-server") node.install_service(db) + + assert db in node + + file_exists = False + for folder in node.file_system.folders.values(): + for file in folder.files.values(): + if file.name == "db_primary_store": + file_exists = True + break + if file_exists: + break + assert file_exists + + +def test_uninstalling_database(): + db = DatabaseService( + name="SQL-database", + health_state_actual=SoftwareHealthState.GOOD, + health_state_visible=SoftwareHealthState.GOOD, + criticality=SoftwareCriticality.MEDIUM, + ports=[ + Port.SQL_SERVER, + ], + operating_state=ServiceOperatingState.RUNNING, + ) + + node = Node(hostname="db-server") + + node.install_service(db) + + node.uninstall_service(db) + + assert db not in node + assert node.file_system.get_folder_by_name("database") is None From 40d3e04e648d442696636152288c52dde200f389 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 29 Aug 2023 14:33:28 +0100 Subject: [PATCH 129/980] Move init action manager function to the top --- src/primaite/simulator/core.py | 28 +++++++-------- src/primaite/simulator/domain/controller.py | 26 +++++++------- src/primaite/simulator/network/container.py | 24 ++++++------- src/primaite/simulator/sim_container.py | 36 +++++++++---------- .../simulator/system/services/service.py | 22 ++++++------ src/primaite/simulator/system/software.py | 22 ++++++------ 6 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index c12b1ad5..69edd8db 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -142,20 +142,6 @@ class SimComponent(BaseModel): self._action_manager: ActionManager = self._init_action_manager() self._parent: Optional["SimComponent"] = None - @abstractmethod - def describe_state(self) -> Dict: - """ - Return a dictionary describing the state of this object and any objects managed by it. - - This is similar to pydantic ``model_dump()``, but it only outputs information about the objects owned by this - object. If there are objects referenced by this object that are owned by something else, it is not included in - this output. - """ - state = { - "uuid": self.uuid, - } - return state - def _init_action_manager(self) -> ActionManager: """ Initialise the action manager for this component. @@ -178,6 +164,20 @@ class SimComponent(BaseModel): """ return ActionManager() + @abstractmethod + def describe_state(self) -> Dict: + """ + Return a dictionary describing the state of this object and any objects managed by it. + + This is similar to pydantic ``model_dump()``, but it only outputs information about the objects owned by this + object. If there are objects referenced by this object that are owned by something else, it is not included in + this output. + """ + state = { + "uuid": self.uuid, + } + return state + def apply_action(self, action: List[str], context: Dict = {}) -> None: """ Apply an action to a simulation component. Action data is passed in as a 'namespaced' list of strings. diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index 961ef550..b436ca79 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -85,19 +85,6 @@ class DomainController(SimComponent): def __init__(self, **kwargs): super().__init__(**kwargs) - def describe_state(self) -> Dict: - """ - Produce a dictionary describing the current state of this object. - - Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - - :return: Current state of this object and child objects. - :rtype: Dict - """ - state = super().describe_state() - state.update({"accounts": {uuid: acct.describe_state() for uuid, acct in self.accounts.items()}}) - return state - def _init_action_manager(self) -> ActionManager: am = super()._init_action_manager() # Action 'account' matches requests like: @@ -111,6 +98,19 @@ class DomainController(SimComponent): ) return am + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state.update({"accounts": {uuid: acct.describe_state() for uuid, acct in self.accounts.items()}}) + return state + def _register_account(self, account: Account) -> None: """TODO.""" ... diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 95eaeb0c..e0226e6c 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -17,6 +17,18 @@ class Network(SimComponent): """Initialise the network.""" super().__init__(**kwargs) + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + + am.add_action( + "node", + Action( + func=lambda request, context: self.nodes[request.pop(0)].apply_action(request, context), + validator=AllowAllValidator(), + ), + ) + return am + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -35,18 +47,6 @@ class Network(SimComponent): ) return state - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - - am.add_action( - "node", - Action( - func=lambda request, context: self.nodes[request.pop(0)].apply_action(request, context), - validator=AllowAllValidator(), - ), - ) - return am - def add_node(self, node: Node) -> None: """ Add an existing node to the network. diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index 8f676e6f..2a5123f3 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -21,24 +21,6 @@ class Simulation(SimComponent): super().__init__(**kwargs) - def describe_state(self) -> Dict: - """ - Produce a dictionary describing the current state of this object. - - Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - - :return: Current state of this object and child objects. - :rtype: Dict - """ - state = super().describe_state() - state.update( - { - "network": self.network.describe_state(), - "domain": self.domain.describe_state(), - } - ) - return state - def _init_action_manager(self) -> ActionManager: am = super()._init_action_manager() # pass through network actions to the network objects @@ -56,3 +38,21 @@ class Simulation(SimComponent): ), ) return am + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state.update( + { + "network": self.network.describe_state(), + "domain": self.domain.describe_state(), + } + ) + return state diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 1a36589f..7e67d05f 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -33,6 +33,17 @@ class Service(IOSoftware): operating_state: ServiceOperatingState "The current operating state of the Service." + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + am.add_action("stop", Action(func=lambda request, context: self.stop())) + am.add_action("start", Action(func=lambda request, context: self.start())) + am.add_action("pause", Action(func=lambda request, context: self.pause())) + am.add_action("resume", Action(func=lambda request, context: self.resume())) + am.add_action("restart", Action(func=lambda request, context: self.restart())) + am.add_action("disable", Action(func=lambda request, context: self.disable())) + am.add_action("enable", Action(func=lambda request, context: self.enable())) + return am + @abstractmethod def describe_state(self) -> Dict: """ @@ -47,17 +58,6 @@ class Service(IOSoftware): state.update({"operating_state": self.operating_state.name}) return state - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - am.add_action("stop", Action(func=lambda request, context: self.stop())) - am.add_action("start", Action(func=lambda request, context: self.start())) - am.add_action("pause", Action(func=lambda request, context: self.pause())) - am.add_action("resume", Action(func=lambda request, context: self.resume())) - am.add_action("restart", Action(func=lambda request, context: self.restart())) - am.add_action("disable", Action(func=lambda request, context: self.disable())) - am.add_action("enable", Action(func=lambda request, context: self.enable())) - return am - def reset_component_for_episode(self, episode: int): """ Resets the Service component for a new episode. diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 1fcdb522..605a062b 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -75,6 +75,17 @@ class Software(SimComponent): revealed_to_red: bool = False "Indicates if the software has been revealed to red agent, defaults is False." + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + am.add_action( + "compromise", + Action( + func=lambda request, context: self.set_health_state(SoftwareHealthState.COMPROMISED), + ), + ) + am.add_action("scan", Action(func=lambda request, context: self.scan())) + return am + @abstractmethod def describe_state(self) -> Dict: """ @@ -98,17 +109,6 @@ class Software(SimComponent): ) return state - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - am.add_action( - "compromise", - Action( - func=lambda request, context: self.set_health_state(SoftwareHealthState.COMPROMISED), - ), - ) - am.add_action("scan", Action(func=lambda request, context: self.scan())) - return am - def reset_component_for_episode(self, episode: int): """ Resets the software component for a new episode. From 1bf51c7741f1c45dd6846d9bb3ee611aadd02bf1 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 30 Aug 2023 21:38:55 +0100 Subject: [PATCH 130/980] #1800 - Added ACL and routing classes. - Added .show() methods to new router classes to enable inspection of the components as you would a real router. - Removed gateway from the NIC and added default_gateway to Node so that Node has a single default gateway. - Added some routing tests to check that ping can be performed when router between subnets. --- .../simulator/network/hardware/base.py | 146 +++-- .../network/hardware/nodes/router.py | 505 +++++++++++++++++- .../network/test_frame_transmission.py | 21 +- .../network/test_link_connection.py | 9 +- .../network/test_nic_link_connection.py | 3 +- .../integration_tests/network/test_routing.py | 56 +- .../_network/_hardware/nodes/__init__.py | 0 .../_network/_hardware/nodes/test_router.py | 104 ++++ .../_simulator/_network/_hardware/test_nic.py | 14 - 9 files changed, 739 insertions(+), 119 deletions(-) create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/__init__.py create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index c64b9b67..921ebbcd 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -77,12 +77,10 @@ class NIC(SimComponent): ip_address: IPv4Address "The IP address assigned to the NIC for communication on an IP-based network." - subnet_mask: str + subnet_mask: IPv4Address "The subnet mask assigned to the NIC." - gateway: IPv4Address - "The default gateway IP address for forwarding network traffic to other networks. Randomly generated upon creation." mac_address: str - "The MAC address of the NIC. Defaults to a randomly set MAC address." + "The MAC address of the NIC. Defaults to a randomly set MAC address. Randomly generated upon creation." speed: int = 100 "The speed of the NIC in Mbps. Default is 100 Mbps." mtu: int = 1500 @@ -111,16 +109,10 @@ class NIC(SimComponent): """ if not isinstance(kwargs["ip_address"], IPv4Address): kwargs["ip_address"] = IPv4Address(kwargs["ip_address"]) - if not isinstance(kwargs["gateway"], IPv4Address): - kwargs["gateway"] = IPv4Address(kwargs["gateway"]) if "mac_address" not in kwargs: kwargs["mac_address"] = generate_mac_address() super().__init__(**kwargs) - if self.ip_address == self.gateway: - msg = f"NIC ip address {self.ip_address} cannot be the same as the gateway {self.gateway}" - _LOGGER.error(msg) - raise ValueError(msg) if self.ip_network.network_address == self.ip_address: msg = ( f"Failed to set IP address {self.ip_address} and subnet mask {self.subnet_mask} as it is a " @@ -274,6 +266,9 @@ class NIC(SimComponent): if frame.ethernet.dst_mac_addr == self.mac_address or frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": self.connected_node.receive_frame(frame=frame, from_nic=self) return True + else: + self.connected_node.sys_log.info("Dropping frame not for me") + print(frame) return False def __str__(self) -> str: @@ -567,7 +562,21 @@ class ARPCache: self.arp: Dict[IPv4Address, ARPEntry] = {} self.nics: Dict[str, "NIC"] = {} - def _add_arp_cache_entry(self, ip_address: IPv4Address, mac_address: str, nic: NIC): + def show(self): + """Prints a table of ARC Cache.""" + table = PrettyTable(["IP Address", "MAC Address", "Via"]) + table.title = f"{self.sys_log.hostname} ARP Cache" + for ip, arp in self.arp.items(): + table.add_row( + [ + str(ip), + arp.mac_address, + self.nics[arp.nic_uuid].mac_address, + ] + ) + print(table) + + def add_arp_cache_entry(self, ip_address: IPv4Address, mac_address: str, nic: NIC, override: bool = False): """ Add an ARP entry to the cache. @@ -575,9 +584,14 @@ class ARPCache: :param mac_address: The MAC address associated with the IP address. :param nic: The NIC through which the NIC with the IP address is reachable. """ - self.sys_log.info(f"Adding ARP cache entry for {mac_address}/{ip_address} via NIC {nic}") - arp_entry = ARPEntry(mac_address=mac_address, nic_uuid=nic.uuid) - self.arp[ip_address] = arp_entry + for _nic in self.nics.values(): + if _nic.ip_address == ip_address: + return + if override or not self.arp.get(ip_address): + self.sys_log.info(f"Adding ARP cache entry for {mac_address}/{ip_address} via NIC {nic}") + arp_entry = ARPEntry(mac_address=mac_address, nic_uuid=nic.uuid) + + self.arp[ip_address] = arp_entry def _remove_arp_cache_entry(self, ip_address: IPv4Address): """ @@ -607,6 +621,7 @@ class ARPCache: :return: The NIC associated with the IP address, or None if not found. """ arp_entry = self.arp.get(ip_address) + if arp_entry: return self.nics[arp_entry.nic_uuid] @@ -641,6 +656,29 @@ class ARPCache: frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) nic.send_frame(frame) + def send_arp_reply(self, arp_reply: ARPPacket, from_nic: NIC): + """ + Send an ARP reply back through the NIC it came from. + + :param arp_reply: The ARP reply to send. + :param from_nic: The NIC to send the ARP reply from. + """ + self.sys_log.info( + f"Sending ARP reply from {arp_reply.sender_mac_addr}/{arp_reply.sender_ip} " + f"to {arp_reply.target_ip}/{arp_reply.target_mac_addr} " + ) + tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) + + ip_packet = IPPacket( + src_ip=arp_reply.sender_ip, + dst_ip=arp_reply.target_ip, + ) + + ethernet_header = EthernetHeader(src_mac_addr=arp_reply.sender_mac_addr, dst_mac_addr=arp_reply.target_mac_addr) + + frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_reply) + from_nic.send_frame(frame) + def process_arp_packet(self, from_nic: NIC, arp_packet: ARPPacket): """ Process a received ARP packet, handling both ARP requests and responses. @@ -656,7 +694,7 @@ class ARPCache: self.sys_log.info( f"Received ARP response for {arp_packet.sender_ip} from {arp_packet.sender_mac_addr} via NIC {from_nic}" ) - self._add_arp_cache_entry( + self.add_arp_cache_entry( ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic ) return @@ -673,26 +711,13 @@ class ARPCache: return # Matched ARP request - self._add_arp_cache_entry(ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic) + self.add_arp_cache_entry(ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic) arp_packet = arp_packet.generate_reply(from_nic.mac_address) - self.sys_log.info( - f"Sending ARP reply from {arp_packet.sender_mac_addr}/{arp_packet.sender_ip} " - f"to {arp_packet.target_ip}/{arp_packet.target_mac_addr} " - ) + self.send_arp_reply(arp_packet, from_nic) - tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) + def __contains__(self, item) -> bool: + return item in self.arp - # Network Layer - ip_packet = IPPacket( - src_ip=arp_packet.sender_ip, - dst_ip=arp_packet.target_ip, - ) - # Data Link Layer - ethernet_header = EthernetHeader( - src_mac_addr=arp_packet.sender_mac_addr, dst_mac_addr=arp_packet.target_mac_addr - ) - frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) - from_nic.send_frame(frame) class ICMP: """ @@ -712,8 +737,7 @@ class ICMP: self.arp: ARPCache = arp_cache self.request_replies = {} - - def process_icmp(self, frame: Frame): + def process_icmp(self, frame: Frame, from_nic: NIC, is_reattempt: bool = False): """ Process an ICMP packet, including handling echo requests and replies. @@ -722,7 +746,15 @@ class ICMP: if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: self.sys_log.info(f"Received echo request from {frame.ip.src_ip}") target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip) + src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip) + if not src_nic: + print(self.sys_log.hostname) + print(frame.ip.src_ip) + self.arp.show() + self.arp.send_arp_request(frame.ip.src_ip) + self.process_icmp(frame=frame, from_nic=from_nic, is_reattempt=True) + return tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) # Network Layer @@ -737,6 +769,7 @@ class ICMP: ) frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet) self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip}") + src_nic.send_frame(frame) elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: self.sys_log.info(f"Received echo reply from {frame.ip.src_ip}") @@ -745,7 +778,7 @@ class ICMP: self.request_replies[frame.icmp.identifier] += 1 def ping( - self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None + self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None, pings: int = 4 ) -> Tuple[int, Union[int, None]]: """ Send an ICMP echo request (ping) to a target IP address and manage the sequence and identifier. @@ -757,13 +790,21 @@ class ICMP: was not found in the ARP cache. """ nic = self.arp.get_arp_cache_nic(target_ip_address) - # TODO: Eventually this ARP request needs to be done elsewhere. It's not the resonsibility of the + # TODO: Eventually this ARP request needs to be done elsewhere. It's not the responsibility of the # ping function to handle ARP lookups + + # Already tried once and cannot get ARP entry, stop trying + if sequence == -1: + if not nic: + return 4, None + else: + sequence = 0 + # No existing ARP entry if not nic: self.sys_log.info(f"No entry in ARP cache for {target_ip_address}") self.arp.send_arp_request(target_ip_address) - return 0, None + return -1, None # ARP entry exists sequence += 1 @@ -812,6 +853,8 @@ class Node(SimComponent): hostname: str "The node hostname on the network." + default_gateway: Optional[IPv4Address] = None + "The default gateway IP address for forwarding network traffic to other networks." operating_state: NodeOperatingState = NodeOperatingState.OFF "The hardware state of the node." nics: Dict[str, NIC] = {} @@ -843,9 +886,12 @@ class Node(SimComponent): This method initializes the ARP cache, ICMP handler, session manager, and software manager if they are not provided. """ + if kwargs.get("default_gateway"): + if not isinstance(kwargs["default_gateway"], IPv4Address): + kwargs["default_gateway"] = IPv4Address(kwargs["default_gateway"]) if not kwargs.get("sys_log"): kwargs["sys_log"] = SysLog(kwargs["hostname"]) - if not kwargs.get("arp_cache"): + if not kwargs.get("arp"): kwargs["arp"] = ARPCache(sys_log=kwargs.get("sys_log")) if not kwargs.get("icmp"): kwargs["icmp"] = ICMP(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp")) @@ -886,10 +932,8 @@ class Node(SimComponent): def show(self): """Prints a table of the NICs on the Node.""" - from prettytable import PrettyTable - table = PrettyTable(["MAC Address", "Address", "Default Gateway", "Speed", "Status"]) - + table.title = f"{self.hostname} Network Interface Cards" for nic in self.nics.values(): table.add_row( [ @@ -967,13 +1011,18 @@ class Node(SimComponent): """ if not isinstance(target_ip_address, IPv4Address): target_ip_address = IPv4Address(target_ip_address) + if target_ip_address.is_loopback: + self.sys_log.info("Pinging loopback address") + return any(nic.enabled for nic in self.nics.values()) if self.operating_state == NodeOperatingState.ON: self.sys_log.info(f"Attempting to ping {target_ip_address}") sequence, identifier = 0, None while sequence < pings: - sequence, identifier = self.icmp.ping(target_ip_address, sequence, identifier) - passed = self.icmp.request_replies[identifier] == pings - self.icmp.request_replies.pop(identifier) + sequence, identifier = self.icmp.ping(target_ip_address, sequence, identifier, pings) + request_replies = self.icmp.request_replies.get(identifier) + passed = request_replies == pings + if request_replies: + self.icmp.request_replies.pop(identifier) return passed self.sys_log.info("Ping failed as the node is turned off") return False @@ -997,13 +1046,18 @@ class Node(SimComponent): :param frame: The Frame being received. :param from_nic: The NIC that received the frame. """ + if frame.ip: + if frame.ip.src_ip in self.arp: + self.arp.add_arp_cache_entry( + ip_address=frame.ip.src_ip, mac_address=frame.ethernet.src_mac_addr, nic=from_nic + ) if frame.ip.protocol == IPProtocol.TCP: if frame.tcp.src_port == Port.ARP: self.arp.process_arp_packet(from_nic=from_nic, arp_packet=frame.arp) elif frame.ip.protocol == IPProtocol.UDP: pass elif frame.ip.protocol == IPProtocol.ICMP: - self.icmp.process_icmp(frame=frame) + self.icmp.process_icmp(frame=frame, from_nic=from_nic) class Switch(Node): @@ -1027,7 +1081,7 @@ class Switch(Node): def show(self): """Prints a table of the SwitchPorts on the Switch.""" table = PrettyTable(["Port", "MAC Address", "Speed", "Status"]) - + table.title = f"{self.hostname} Switch Ports" for port_num, port in self.switch_ports.items(): table.add_row([port_num, port.mac_address, port.speed, "Enabled" if port.enabled else "Disabled"]) print(table) diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index c5620b88..528e4a73 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -1,63 +1,514 @@ -from enum import Enum -from ipaddress import IPv4Address -from typing import Dict, List, Union +from __future__ import annotations + +from enum import Enum +from ipaddress import IPv4Address, IPv4Network +from typing import Dict, List, Optional, Tuple, Union -from primaite.simulator.core import SimComponent -from primaite.simulator.network.hardware.base import Node, NIC from prettytable import PrettyTable -from primaite.simulator.network.transmission.network_layer import IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.core import SimComponent +from primaite.simulator.network.hardware.base import ARPCache, ICMP, NIC, Node +from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame +from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader +from primaite.simulator.system.core.sys_log import SysLog class ACLAction(Enum): + """Enum for defining the ACL action types.""" + DENY = 0 PERMIT = 1 class ACLRule(SimComponent): - action: ACLAction - protocol: IPProtocol - src_ip: IPv4Address - src_wildcard: IPv4Address = IPv4Address("0.0.0.0") - src_port: Port - dst_ip: IPv4Address - dst_port: Port + def describe_state(self) -> Dict: + pass + + action: ACLAction = ACLAction.DENY + protocol: Optional[IPProtocol] = None + src_ip: Optional[IPv4Address] = None + src_port: Optional[Port] = None + dst_ip: Optional[IPv4Address] = None + dst_port: Optional[Port] = None + + def __str__(self) -> str: + rule_strings = [] + for key, value in self.model_dump(exclude={"uuid", "action_manager"}).items(): + if value is None: + value = "ANY" + if isinstance(value, Enum): + rule_strings.append(f"{key}={value.name}") + else: + rule_strings.append(f"{key}={value}") + return ", ".join(rule_strings) -class RouteTableEntry(SimComponent): - pass +class AccessControlList(SimComponent): + sys_log: SysLog + implicit_action: ACLAction + implicit_rule: ACLRule + max_acl_rules: int = 25 + _acl: List[Optional[ACLRule]] = [None] * 24 + + def __init__(self, **kwargs) -> None: + if not kwargs.get("implicit_action"): + kwargs["implicit_action"] = ACLAction.DENY + if not kwargs.get("max_acl_rules"): + kwargs["max_acl_rules"] = 25 + kwargs["implicit_rule"] = ACLRule(action=kwargs["implicit_action"]) + kwargs["_acl"] = [None] * (kwargs["max_acl_rules"] - 1) + + super().__init__(**kwargs) + + def describe_state(self) -> Dict: + pass + + @property + def acl(self) -> List[Optional[ACLRule]]: + return self._acl + + def add_rule( + self, + action: ACLAction, + protocol: Optional[IPProtocol] = None, + src_ip: Optional[Union[str, IPv4Address]] = None, + src_port: Optional[Port] = None, + dst_ip: Optional[Union[str, IPv4Address]] = None, + dst_port: Optional[Port] = None, + position: int = 0, + ) -> None: + if isinstance(src_ip, str): + src_ip = IPv4Address(src_ip) + if isinstance(dst_ip, str): + dst_ip = IPv4Address(dst_ip) + if 0 <= position < self.max_acl_rules: + self._acl[position] = ACLRule( + action=action, src_ip=src_ip, dst_ip=dst_ip, protocol=protocol, src_port=src_port, dst_port=dst_port + ) + else: + raise ValueError(f"Position {position} is out of bounds.") + + def remove_rule(self, position: int) -> None: + if 0 <= position < self.max_acl_rules: + self._acl[position] = None + else: + raise ValueError(f"Position {position} is out of bounds.") + + def is_permitted( + self, + protocol: IPProtocol, + src_ip: Union[str, IPv4Address], + src_port: Optional[Port], + dst_ip: Union[str, IPv4Address], + dst_port: Optional[Port], + ) -> Tuple[bool, Optional[Union[str, ACLRule]]]: + if not isinstance(src_ip, IPv4Address): + src_ip = IPv4Address(src_ip) + if not isinstance(dst_ip, IPv4Address): + dst_ip = IPv4Address(dst_ip) + for rule in self._acl: + if not rule: + continue + + if ( + (rule.src_ip == src_ip or rule.src_ip is None) + and (rule.dst_ip == dst_ip or rule.dst_ip is None) + and (rule.protocol == protocol or rule.protocol is None) + and (rule.src_port == src_port or rule.src_port is None) + and (rule.dst_port == dst_port or rule.dst_port is None) + ): + return rule.action == ACLAction.PERMIT, rule + + return self.implicit_action == ACLAction.PERMIT, f"Implicit {self.implicit_action.name}" + + def get_relevant_rules( + self, + protocol: IPProtocol, + src_ip: Union[str, IPv4Address], + src_port: Port, + dst_ip: Union[str, IPv4Address], + dst_port: Port, + ) -> List[ACLRule]: + if not isinstance(src_ip, IPv4Address): + src_ip = IPv4Address(src_ip) + if not isinstance(dst_ip, IPv4Address): + dst_ip = IPv4Address(dst_ip) + relevant_rules = [] + for rule in self._acl: + if rule is None: + continue + + if ( + (rule.src_ip == src_ip or rule.src_ip is None) + or (rule.dst_ip == dst_ip or rule.dst_ip is None) + or (rule.protocol == protocol or rule.protocol is None) + or (rule.src_port == src_port or rule.src_port is None) + or (rule.dst_port == dst_port or rule.dst_port is None) + ): + relevant_rules.append(rule) + + return relevant_rules + + def show(self): + """Prints a table of the routes in the RouteTable.""" + """ + action: ACLAction + protocol: Optional[IPProtocol] + src_ip: Optional[IPv4Address] + src_port: Optional[Port] + dst_ip: Optional[IPv4Address] + dst_port: Optional[Port] + """ + table = PrettyTable(["Index", "Action", "Protocol", "Src IP", "Src Port", "Dst IP", "Dst Port"]) + table.title = f"{self.sys_log.hostname} Access Control List" + for index, rule in enumerate(self.acl + [self.implicit_rule]): + if rule: + table.add_row( + [ + index, + rule.action.name if rule.action else "ANY", + rule.protocol.name if rule.protocol else "ANY", + rule.src_ip if rule.src_ip else "ANY", + f"{rule.src_port.value} ({rule.src_port.name})" if rule.src_port else "ANY", + rule.dst_ip if rule.dst_ip else "ANY", + f"{rule.dst_port.value} ({rule.dst_port.name})" if rule.dst_port else "ANY", + ] + ) + print(table) + + +class RouteEntry(SimComponent): + """ + Represents a single entry in a routing table. + + Attributes: + address (IPv4Address): The destination IP address or network address. + subnet_mask (IPv4Address): The subnet mask for the network. + next_hop (IPv4Address): The next hop IP address to which packets should be forwarded. + metric (int): The cost metric for this route. Default is 0.0. + + Example: + >>> entry = RouteEntry( + ... IPv4Address("192.168.1.0"), + ... IPv4Address("255.255.255.0"), + ... IPv4Address("192.168.2.1"), + ... metric=5 + ... ) + """ + + address: IPv4Address + "The destination IP address or network address." + subnet_mask: IPv4Address + "The subnet mask for the network." + next_hop: IPv4Address + "The next hop IP address to which packets should be forwarded." + metric: float = 0.0 + "The cost metric for this route. Default is 0.0." + + def __init__(self, **kwargs): + for key in {"address", "subnet_mask", "next_hop"}: + if not isinstance(kwargs[key], IPv4Address): + kwargs[key] = IPv4Address(kwargs[key]) + super().__init__(**kwargs) + + def describe_state(self) -> Dict: + pass + + +class RouteTable(SimComponent): + """ + Represents a routing table holding multiple route entries. + + Attributes: + routes (List[RouteEntry]): A list of RouteEntry objects. + + Methods: + add_route: Add a route to the routing table. + find_best_route: Find the best route for a given destination IP. + + Example: + >>> rt = RouteTable() + >>> rt.add_route( + ... RouteEntry( + ... IPv4Address("192.168.1.0"), + ... IPv4Address("255.255.255.0"), + ... IPv4Address("192.168.2.1"), + ... metric=5 + ... ) + ... ) + >>> best_route = rt.find_best_route(IPv4Address("192.168.1.34")) + """ + + routes: List[RouteEntry] = [] + sys_log: SysLog + + def describe_state(self) -> Dict: + pass + + def add_route( + self, + address: Union[IPv4Address, str], + subnet_mask: Union[IPv4Address, str], + next_hop: Union[IPv4Address, str], + metric: float = 0.0, + ): + """Add a route to the routing table. + + :param route: A RouteEntry object representing the route. + """ + for key in {address, subnet_mask, next_hop}: + if not isinstance(key, IPv4Address): + key = IPv4Address(key) + route = RouteEntry(address=address, subnet_mask=subnet_mask, next_hop=next_hop, metric=metric) + self.routes.append(route) + + def find_best_route(self, destination_ip: Union[str, IPv4Address]) -> Optional[RouteEntry]: + """ + Find the best route for a given destination IP. + + :param destination_ip: The destination IPv4Address to find the route for. + :return: The best matching RouteEntry, or None if no route matches. + + The algorithm uses Longest Prefix Match and considers metrics to find the best route. + """ + if not isinstance(destination_ip, IPv4Address): + destination_ip = IPv4Address(destination_ip) + best_route = None + longest_prefix = -1 + lowest_metric = float("inf") # Initialise at infinity as any other number we compare to it will be smaller + + for route in self.routes: + route_network = IPv4Network(f"{route.address}/{route.subnet_mask}", strict=False) + prefix_len = route_network.prefixlen + + if destination_ip in route_network: + if prefix_len > longest_prefix or (prefix_len == longest_prefix and route.metric < lowest_metric): + best_route = route + longest_prefix = prefix_len + lowest_metric = route.metric + + return best_route + + def show(self): + """Prints a table of the routes in the RouteTable.""" + table = PrettyTable(["Index", "Address", "Next Hop", "Metric"]) + table.title = f"{self.sys_log.hostname} Route Table" + for index, route in enumerate(self.routes): + network = IPv4Network(f"{route.address}/{route.subnet_mask}") + table.add_row([index, f"{route.address}/{network.prefixlen}", route.next_hop, route.metric]) + print(table) + + +class RouterARPCache(ARPCache): + def __init__(self, sys_log: SysLog, router: Router): + super().__init__(sys_log) + self.router: Router = router + + def process_arp_packet(self, from_nic: NIC, frame: Frame): + """ + Overridden method to process a received ARP packet in a router-specific way. + + :param from_nic: The NIC that received the ARP packet. + :param frame: The original arp frame. + """ + arp_packet = frame.arp + + # ARP Reply + if not arp_packet.request: + for nic in self.router.nics.values(): + if arp_packet.target_ip == nic.ip_address: + # reply to the Router specifically + self.sys_log.info( + f"Received ARP response for {arp_packet.sender_ip} from {arp_packet.sender_mac_addr} via NIC {from_nic}" + ) + self.add_arp_cache_entry( + ip_address=arp_packet.sender_ip, + mac_address=arp_packet.sender_mac_addr, + nic=from_nic, + ) + return + + # Reply for a connected requested + nic = self.get_arp_cache_nic(arp_packet.target_ip) + if nic: + self.sys_log.info(f"Forwarding arp reply for {arp_packet.target_ip}, from {arp_packet.sender_ip}") + arp_packet.sender_mac_addr = nic.mac_address + frame.decrement_ttl() + nic.send_frame(frame) + + # ARP Request + self.sys_log.info( + f"Received ARP request for {arp_packet.target_ip} from " + f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip} " + ) + # Matched ARP request + self.add_arp_cache_entry(ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic) + arp_packet = arp_packet.generate_reply(from_nic.mac_address) + self.send_arp_reply(arp_packet, from_nic) + + # If the target IP matches one of the router's NICs + for nic in self.nics.values(): + if nic.enabled and nic.ip_address == arp_packet.target_ip: + arp_reply = arp_packet.generate_reply(from_nic.mac_address) + self.send_arp_reply(arp_reply, from_nic) + return + + +class RouterICMP(ICMP): + router: Router + + def __init__(self, sys_log: SysLog, arp_cache: ARPCache, router: Router): + super().__init__(sys_log, arp_cache) + self.router = router + + def process_icmp(self, frame: Frame, from_nic: NIC, is_reattempt: bool = False): + if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: + # determine if request is for router interface or whether it needs to be routed + + for nic in self.router.nics.values(): + if nic.ip_address == frame.ip.dst_ip and nic.enabled: + # reply to the request + self.sys_log.info(f"Received echo request from {frame.ip.src_ip}") + target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip) + src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip) + tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) + + # Network Layer + ip_packet = IPPacket(src_ip=nic.ip_address, dst_ip=frame.ip.src_ip, protocol=IPProtocol.ICMP) + # Data Link Layer + ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) + icmp_reply_packet = ICMPPacket( + icmp_type=ICMPType.ECHO_REPLY, + icmp_code=0, + identifier=frame.icmp.identifier, + sequence=frame.icmp.sequence + 1, + ) + frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet) + self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip}") + + src_nic.send_frame(frame) + return + + # Route the frame + self.router.route_frame(frame, from_nic) + elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: + self.sys_log.info(f"Received echo reply from {frame.ip.src_ip}") + if not self.request_replies.get(frame.icmp.identifier): + self.request_replies[frame.icmp.identifier] = 0 + self.request_replies[frame.icmp.identifier] += 1 class Router(Node): num_ports: int ethernet_ports: Dict[int, NIC] = {} - acl: List = [] - route_table: Dict = {} + acl: AccessControlList + route_table: RouteTable + arp: RouterARPCache + icmp: RouterICMP def __init__(self, hostname: str, num_ports: int = 5, **kwargs): + if not kwargs.get("sys_log"): + kwargs["sys_log"] = SysLog(hostname) + if not kwargs.get("acl"): + kwargs["acl"] = AccessControlList(sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY) + if not kwargs.get("route_table"): + kwargs["route_table"] = RouteTable(sys_log=kwargs["sys_log"]) + if not kwargs.get("arp"): + kwargs["arp"] = RouterARPCache(sys_log=kwargs.get("sys_log"), router=self) + if not kwargs.get("icmp"): + kwargs["icmp"] = RouterICMP(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp"), router=self) super().__init__(hostname=hostname, num_ports=num_ports, **kwargs) - for i in range(1, self.num_ports + 1): nic = NIC(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") self.connect_nic(nic) self.ethernet_ports[i] = nic + self.arp.nics = self.nics + self.icmp.arp = self.arp + + def _get_port_of_nic(self, target_nic: NIC) -> Optional[int]: + for port, nic in self.ethernet_ports.items(): + if nic == target_nic: + return port + def describe_state(self) -> Dict: pass - def configure_port( - self, - port: int, - ip_address: Union[IPv4Address, str], - subnet_mask: str - ): + def route_frame(self, frame: Frame, from_nic: NIC, re_attempt: bool = False) -> None: + if not re_attempt: + # Check if src ip is on network of one of the NICs + nic = self.arp.get_arp_cache_nic(frame.ip.dst_ip) + target_mac = self.arp.get_arp_cache_mac_address(frame.ip.dst_ip) + if not nic: + self.arp.send_arp_request(frame.ip.dst_ip) + return self.route_frame(frame=frame, from_nic=from_nic, re_attempt=True) + for nic in self.nics.values(): + if nic.enabled and frame.ip.dst_ip in nic.ip_network: + from_port = self._get_port_of_nic(from_nic) + to_port = self._get_port_of_nic(nic) + self.sys_log.info(f"Routing frame to internally from port {from_port} to port {to_port}") + frame.decrement_ttl() + frame.ethernet.src_mac_addr = nic.mac_address + frame.ethernet.dst_mac_addr = target_mac + nic.send_frame(frame) + return + else: + self.sys_log.info(f"Destination {frame.ip.dst_ip} is unreachable") + + def receive_frame(self, frame: Frame, from_nic: NIC): + """ + Receive a Frame from the connected NIC and process it. + + Depending on the protocol, the frame is passed to the appropriate handler such as ARP or ICMP, or up to the + SessionManager if no code manager exists. + + :param frame: The Frame being received. + :param from_nic: The NIC that received the frame. + """ + route_frame = False + protocol = frame.ip.protocol + src_ip = frame.ip.src_ip + dst_ip = frame.ip.dst_ip + src_port = None + dst_port = None + if frame.ip.protocol == IPProtocol.TCP: + src_port = frame.tcp.src_port + dst_port = frame.tcp.dst_port + elif frame.ip.protocol == IPProtocol.UDP: + src_port = frame.udp.src_port + dst_port = frame.udp.dst_port + + # Check if it's permitted + permitted, rule = self.acl.is_permitted( + protocol=protocol, src_ip=src_ip, src_port=src_port, dst_ip=dst_ip, dst_port=dst_port + ) + if not permitted: + at_port = self._get_port_of_nic(from_nic) + self.sys_log.info(f"Frame blocked at port {at_port} by rule {rule}") + return + if not self.arp.get_arp_cache_nic(src_ip): + self.arp.add_arp_cache_entry(src_ip, frame.ethernet.src_mac_addr, from_nic) + if frame.ip.protocol == IPProtocol.ICMP: + self.icmp.process_icmp(frame=frame, from_nic=from_nic) + else: + if src_port == Port.ARP: + self.arp.process_arp_packet(from_nic=from_nic, frame=frame) + else: + # All other traffic + route_frame = True + if route_frame: + self.route_frame(frame, from_nic) + + def configure_port(self, port: int, ip_address: Union[IPv4Address, str], subnet_mask: Union[IPv4Address, str]): if not isinstance(ip_address, IPv4Address): ip_address = IPv4Address(ip_address) + if not isinstance(subnet_mask, IPv4Address): + subnet_mask = IPv4Address(subnet_mask) nic = self.ethernet_ports[port] nic.ip_address = ip_address nic.subnet_mask = subnet_mask - self.sys_log.info(f"Configured port {port} with {ip_address=} {subnet_mask=}") + self.sys_log.info(f"Configured port {port} with ip_address={ip_address}/{nic.ip_network.prefixlen}") def enable_port(self, port: int): nic = self.ethernet_ports.get(port) @@ -72,7 +523,7 @@ class Router(Node): def show(self): """Prints a table of the NICs on the Node.""" table = PrettyTable(["Port", "MAC Address", "Address", "Speed", "Status"]) - + table.title = f"{self.hostname} Ethernet Interfaces" for port, nic in self.ethernet_ports.items(): table.add_row( [ diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index d3d6541a..34b76060 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -3,14 +3,13 @@ from primaite.simulator.network.hardware.base import Link, NIC, Node, Switch def test_node_to_node_ping(): """Tests two Nodes are able to ping each other.""" - # TODO Add actual checks. Manual check performed for now. node_a = Node(hostname="node_a") - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") node_a.connect_nic(nic_a) node_a.power_on() node_b = Node(hostname="node_b") - nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") + nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") node_b.connect_nic(nic_b) node_b.power_on() @@ -23,19 +22,19 @@ def test_multi_nic(): """Tests that Nodes with multiple NICs can ping each other and the data go across the correct links.""" # TODO Add actual checks. Manual check performed for now. node_a = Node(hostname="node_a") - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") node_a.connect_nic(nic_a) node_a.power_on() node_b = Node(hostname="node_b") - nic_b1 = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") - nic_b2 = NIC(ip_address="10.0.0.12", subnet_mask="255.0.0.0", gateway="10.0.0.1") + nic_b1 = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") + nic_b2 = NIC(ip_address="10.0.0.12", subnet_mask="255.0.0.0") node_b.connect_nic(nic_b1) node_b.connect_nic(nic_b2) node_b.power_on() node_c = Node(hostname="node_c") - nic_c = NIC(ip_address="10.0.0.13", subnet_mask="255.0.0.0", gateway="10.0.0.1") + nic_c = NIC(ip_address="10.0.0.13", subnet_mask="255.0.0.0") node_c.connect_nic(nic_c) node_c.power_on() @@ -52,22 +51,22 @@ def test_switched_network(): """Tests a larges network of Nodes and Switches with one node pinging another.""" # TODO Add actual checks. Manual check performed for now. pc_a = Node(hostname="pc_a") - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") pc_a.connect_nic(nic_a) pc_a.power_on() pc_b = Node(hostname="pc_b") - nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") + nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") pc_b.connect_nic(nic_b) pc_b.power_on() pc_c = Node(hostname="pc_c") - nic_c = NIC(ip_address="192.168.0.12", subnet_mask="255.255.255.0", gateway="192.168.0.1") + nic_c = NIC(ip_address="192.168.0.12", subnet_mask="255.255.255.0") pc_c.connect_nic(nic_c) pc_c.power_on() pc_d = Node(hostname="pc_d") - nic_d = NIC(ip_address="192.168.0.13", subnet_mask="255.255.255.0", gateway="192.168.0.1") + nic_d = NIC(ip_address="192.168.0.13", subnet_mask="255.255.255.0") pc_d.connect_nic(nic_d) pc_d.power_on() diff --git a/tests/integration_tests/network/test_link_connection.py b/tests/integration_tests/network/test_link_connection.py index e08e40b9..ef65f078 100644 --- a/tests/integration_tests/network/test_link_connection.py +++ b/tests/integration_tests/network/test_link_connection.py @@ -4,18 +4,17 @@ from primaite.simulator.network.hardware.base import Link, NIC, Node def test_link_up(): """Tests Nodes, NICs, and Links can all be connected and be in an enabled/up state.""" node_a = Node(hostname="node_a") - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") node_a.connect_nic(nic_a) node_a.power_on() - assert nic_a.enabled node_b = Node(hostname="node_b") - nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") + nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") node_b.connect_nic(nic_b) node_b.power_on() - assert nic_b.enabled - link = Link(endpoint_a=nic_a, endpoint_b=nic_b) + assert nic_a.enabled + assert nic_b.enabled assert link.is_up diff --git a/tests/integration_tests/network/test_nic_link_connection.py b/tests/integration_tests/network/test_nic_link_connection.py index 52a0c735..f051d026 100644 --- a/tests/integration_tests/network/test_nic_link_connection.py +++ b/tests/integration_tests/network/test_nic_link_connection.py @@ -8,7 +8,6 @@ def test_link_fails_with_same_nic(): with pytest.raises(ValueError): nic_a = NIC( ip_address="192.168.1.2", - subnet_mask="255.255.255.0", - gateway="192.168.0.1", + subnet_mask="255.255.255.0" ) Link(endpoint_a=nic_a, endpoint_b=nic_a) diff --git a/tests/integration_tests/network/test_routing.py b/tests/integration_tests/network/test_routing.py index cca48c0d..cb420e22 100644 --- a/tests/integration_tests/network/test_routing.py +++ b/tests/integration_tests/network/test_routing.py @@ -1,27 +1,55 @@ -from primaite.simulator.network.hardware.base import Node, NIC, Link -from primaite.simulator.network.hardware.nodes.router import Router +from typing import Tuple + +import pytest + +from primaite.simulator.network.hardware.base import Link, NIC, Node +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port -def test_ping_fails_with_no_route(): - """Tests a larges network of Nodes and Switches with one node pinging another.""" - pc_a = Node(hostname="pc_a") - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") +@pytest.fixture(scope="function") +def pc_a_pc_b_router_1() -> Tuple[Node, Node, Router]: + pc_a = Node(hostname="pc_a", default_gateway="192.168.0.1") + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") pc_a.connect_nic(nic_a) pc_a.power_on() - pc_b = Node(hostname="pc_b") - nic_b = NIC(ip_address="192.168.1.10", subnet_mask="255.255.255.0", gateway="192.168.1.1") + pc_b = Node(hostname="pc_b", default_gateway="192.168.1.1") + nic_b = NIC(ip_address="192.168.1.10", subnet_mask="255.255.255.0") pc_b.connect_nic(nic_b) pc_b.power_on() router_1 = Router(hostname="router_1") + router_1.power_on() + router_1.configure_port(1, "192.168.0.1", "255.255.255.0") router_1.configure_port(2, "192.168.1.1", "255.255.255.0") - router_1.power_on() - router_1.show() + Link(endpoint_a=nic_a, endpoint_b=router_1.ethernet_ports[1]) + Link(endpoint_a=nic_b, endpoint_b=router_1.ethernet_ports[2]) + router_1.enable_port(1) + router_1.enable_port(2) - link_nic_a_router_1 = Link(endpoint_a=nic_a, endpoint_b=router_1.ethernet_ports[1]) - link_nic_b_router_1 = Link(endpoint_a=nic_b, endpoint_b=router_1.ethernet_ports[2]) - router_1.power_on() - #assert pc_a.ping("192.168.1.10") \ No newline at end of file + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) + + router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + return pc_a, pc_b, router_1 + + +def test_ping_default_gateway(pc_a_pc_b_router_1): + pc_a, pc_b, router_1 = pc_a_pc_b_router_1 + + assert pc_a.ping(pc_a.default_gateway) + + +def test_ping_other_router_port(pc_a_pc_b_router_1): + pc_a, pc_b, router_1 = pc_a_pc_b_router_1 + + assert pc_a.ping(pc_b.default_gateway) + + +def test_host_on_other_subnet(pc_a_pc_b_router_1): + pc_a, pc_b, router_1 = pc_a_pc_b_router_1 + + assert pc_a.ping("192.168.1.10") diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/__init__.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py new file mode 100644 index 00000000..48d0fc06 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py @@ -0,0 +1,104 @@ +from ipaddress import IPv4Address + +from primaite.simulator.network.hardware.nodes.router import AccessControlList, ACLAction, ACLRule +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port + + +def test_add_rule(): + acl = AccessControlList() + acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + src_ip=IPv4Address("192.168.1.1"), + src_port=Port(8080), + dst_ip=IPv4Address("192.168.1.2"), + dst_port=Port(80), + position=1, + ) + assert acl.acl[1].action == ACLAction.PERMIT + assert acl.acl[1].protocol == IPProtocol.TCP + assert acl.acl[1].src_ip == IPv4Address("192.168.1.1") + assert acl.acl[1].src_port == Port(8080) + assert acl.acl[1].dst_ip == IPv4Address("192.168.1.2") + assert acl.acl[1].dst_port == Port(80) + + +def test_remove_rule(): + acl = AccessControlList() + acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + src_ip=IPv4Address("192.168.1.1"), + src_port=Port(8080), + dst_ip=IPv4Address("192.168.1.2"), + dst_port=Port(80), + position=1, + ) + acl.remove_rule(1) + assert not acl.acl[1] + + +def test_rules(): + acl = AccessControlList() + acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + src_ip=IPv4Address("192.168.1.1"), + src_port=Port(8080), + dst_ip=IPv4Address("192.168.1.2"), + dst_port=Port(80), + position=1, + ) + acl.add_rule( + action=ACLAction.DENY, + protocol=IPProtocol.TCP, + src_ip=IPv4Address("192.168.1.3"), + src_port=Port(8080), + dst_ip=IPv4Address("192.168.1.4"), + dst_port=Port(80), + position=2, + ) + assert acl.is_permitted( + protocol=IPProtocol.TCP, + src_ip=IPv4Address("192.168.1.1"), + src_port=Port(8080), + dst_ip=IPv4Address("192.168.1.2"), + dst_port=Port(80), + ) + assert not acl.is_permitted( + protocol=IPProtocol.TCP, + src_ip=IPv4Address("192.168.1.3"), + src_port=Port(8080), + dst_ip=IPv4Address("192.168.1.4"), + dst_port=Port(80), + ) + + +def test_default_rule(): + acl = AccessControlList() + acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + src_ip=IPv4Address("192.168.1.1"), + src_port=Port(8080), + dst_ip=IPv4Address("192.168.1.2"), + dst_port=Port(80), + position=1, + ) + acl.add_rule( + action=ACLAction.DENY, + protocol=IPProtocol.TCP, + src_ip=IPv4Address("192.168.1.3"), + src_port=Port(8080), + dst_ip=IPv4Address("192.168.1.4"), + dst_port=Port(80), + position=2, + ) + assert not acl.is_permitted( + protocol=IPProtocol.UDP, + src_ip=IPv4Address("192.168.1.5"), + src_port=Port(8080), + dst_ip=IPv4Address("192.168.1.12"), + dst_port=Port(80), + ) diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py index dc508508..11873128 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py @@ -32,10 +32,8 @@ def test_nic_ip_address_type_conversion(): nic = NIC( ip_address="192.168.1.2", subnet_mask="255.255.255.0", - gateway="192.168.0.1", ) assert isinstance(nic.ip_address, IPv4Address) - assert isinstance(nic.gateway, IPv4Address) def test_nic_deserialize(): @@ -43,7 +41,6 @@ def test_nic_deserialize(): nic = NIC( ip_address="192.168.1.2", subnet_mask="255.255.255.0", - gateway="192.168.0.1", ) nic_json = nic.model_dump_json() @@ -51,21 +48,10 @@ def test_nic_deserialize(): assert nic == deserialized_nic -def test_nic_ip_address_as_gateway_fails(): - """Tests NIC creation fails if ip address is the same as the gateway.""" - with pytest.raises(ValueError): - NIC( - ip_address="192.168.0.1", - subnet_mask="255.255.255.0", - gateway="192.168.0.1", - ) - - def test_nic_ip_address_as_network_address_fails(): """Tests NIC creation fails if ip address and subnet mask are a network address.""" with pytest.raises(ValueError): NIC( ip_address="192.168.0.0", subnet_mask="255.255.255.0", - gateway="192.168.0.1", ) From 62be66205cdbb91e43b3438eae396b660dff199c Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 31 Aug 2023 10:57:45 +0100 Subject: [PATCH 131/980] Fix unit tests --- .../_primaite/_simulator/_network/_hardware/test_nic.py | 2 +- tests/unit_tests/_primaite/_simulator/test_core.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py index dc508508..c417b5b9 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py @@ -48,7 +48,7 @@ def test_nic_deserialize(): nic_json = nic.model_dump_json() deserialized_nic = NIC.model_validate_json(nic_json) - assert nic == deserialized_nic + assert nic_json == deserialized_nic.model_dump_json() def test_nic_ip_address_as_gateway_fails(): diff --git a/tests/unit_tests/_primaite/_simulator/test_core.py b/tests/unit_tests/_primaite/_simulator/test_core.py index 0d227633..bbb1298f 100644 --- a/tests/unit_tests/_primaite/_simulator/test_core.py +++ b/tests/unit_tests/_primaite/_simulator/test_core.py @@ -43,4 +43,5 @@ class TestIsolatedSimComponent: comp = TestComponent(name="computer", size=(5, 10)) dump = comp.model_dump_json() - assert comp == TestComponent.model_validate_json(dump) + reconstructed = TestComponent.model_validate_json(dump) + assert comp == reconstructed.model_dump_json() From e73d7f49d68e5e6b0e481db098d1e0aa49c044fd Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 31 Aug 2023 11:03:38 +0100 Subject: [PATCH 132/980] #1800 - Fixed routing and processing of ICMP packets in the Router class --- .../simulator/network/hardware/base.py | 9 +- .../network/hardware/nodes/router.py | 171 ++++++++++-------- 2 files changed, 98 insertions(+), 82 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 921ebbcd..4803150d 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -744,14 +744,12 @@ class ICMP: :param frame: The Frame containing the ICMP packet to process. """ if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: - self.sys_log.info(f"Received echo request from {frame.ip.src_ip}") + if not is_reattempt: + self.sys_log.info(f"Received echo request from {frame.ip.src_ip}") target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip) src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip) if not src_nic: - print(self.sys_log.hostname) - print(frame.ip.src_ip) - self.arp.show() self.arp.send_arp_request(frame.ip.src_ip) self.process_icmp(frame=frame, from_nic=from_nic, is_reattempt=True) return @@ -932,14 +930,13 @@ class Node(SimComponent): def show(self): """Prints a table of the NICs on the Node.""" - table = PrettyTable(["MAC Address", "Address", "Default Gateway", "Speed", "Status"]) + table = PrettyTable(["MAC Address", "Address", "Speed", "Status"]) table.title = f"{self.hostname} Network Interface Cards" for nic in self.nics.values(): table.add_row( [ nic.mac_address, f"{nic.ip_address}/{nic.ip_network.prefixlen}", - nic.gateway, nic.speed, "Enabled" if nic.enabled else "Disabled", ] diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 528e4a73..7db92938 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -69,14 +69,14 @@ class AccessControlList(SimComponent): return self._acl def add_rule( - self, - action: ACLAction, - protocol: Optional[IPProtocol] = None, - src_ip: Optional[Union[str, IPv4Address]] = None, - src_port: Optional[Port] = None, - dst_ip: Optional[Union[str, IPv4Address]] = None, - dst_port: Optional[Port] = None, - position: int = 0, + self, + action: ACLAction, + protocol: Optional[IPProtocol] = None, + src_ip: Optional[Union[str, IPv4Address]] = None, + src_port: Optional[Port] = None, + dst_ip: Optional[Union[str, IPv4Address]] = None, + dst_port: Optional[Port] = None, + position: int = 0, ) -> None: if isinstance(src_ip, str): src_ip = IPv4Address(src_ip) @@ -96,12 +96,12 @@ class AccessControlList(SimComponent): raise ValueError(f"Position {position} is out of bounds.") def is_permitted( - self, - protocol: IPProtocol, - src_ip: Union[str, IPv4Address], - src_port: Optional[Port], - dst_ip: Union[str, IPv4Address], - dst_port: Optional[Port], + self, + protocol: IPProtocol, + src_ip: Union[str, IPv4Address], + src_port: Optional[Port], + dst_ip: Union[str, IPv4Address], + dst_port: Optional[Port], ) -> Tuple[bool, Optional[Union[str, ACLRule]]]: if not isinstance(src_ip, IPv4Address): src_ip = IPv4Address(src_ip) @@ -112,23 +112,23 @@ class AccessControlList(SimComponent): continue if ( - (rule.src_ip == src_ip or rule.src_ip is None) - and (rule.dst_ip == dst_ip or rule.dst_ip is None) - and (rule.protocol == protocol or rule.protocol is None) - and (rule.src_port == src_port or rule.src_port is None) - and (rule.dst_port == dst_port or rule.dst_port is None) + (rule.src_ip == src_ip or rule.src_ip is None) + and (rule.dst_ip == dst_ip or rule.dst_ip is None) + and (rule.protocol == protocol or rule.protocol is None) + and (rule.src_port == src_port or rule.src_port is None) + and (rule.dst_port == dst_port or rule.dst_port is None) ): return rule.action == ACLAction.PERMIT, rule return self.implicit_action == ACLAction.PERMIT, f"Implicit {self.implicit_action.name}" def get_relevant_rules( - self, - protocol: IPProtocol, - src_ip: Union[str, IPv4Address], - src_port: Port, - dst_ip: Union[str, IPv4Address], - dst_port: Port, + self, + protocol: IPProtocol, + src_ip: Union[str, IPv4Address], + src_port: Port, + dst_ip: Union[str, IPv4Address], + dst_port: Port, ) -> List[ACLRule]: if not isinstance(src_ip, IPv4Address): src_ip = IPv4Address(src_ip) @@ -140,11 +140,11 @@ class AccessControlList(SimComponent): continue if ( - (rule.src_ip == src_ip or rule.src_ip is None) - or (rule.dst_ip == dst_ip or rule.dst_ip is None) - or (rule.protocol == protocol or rule.protocol is None) - or (rule.src_port == src_port or rule.src_port is None) - or (rule.dst_port == dst_port or rule.dst_port is None) + (rule.src_ip == src_ip or rule.src_ip is None) + or (rule.dst_ip == dst_ip or rule.dst_ip is None) + or (rule.protocol == protocol or rule.protocol is None) + or (rule.src_port == src_port or rule.src_port is None) + or (rule.dst_port == dst_port or rule.dst_port is None) ): relevant_rules.append(rule) @@ -247,11 +247,11 @@ class RouteTable(SimComponent): pass def add_route( - self, - address: Union[IPv4Address, str], - subnet_mask: Union[IPv4Address, str], - next_hop: Union[IPv4Address, str], - metric: float = 0.0, + self, + address: Union[IPv4Address, str], + subnet_mask: Union[IPv4Address, str], + next_hop: Union[IPv4Address, str], + metric: float = 0.0, ): """Add a route to the routing table. @@ -367,36 +367,46 @@ class RouterICMP(ICMP): # determine if request is for router interface or whether it needs to be routed for nic in self.router.nics.values(): - if nic.ip_address == frame.ip.dst_ip and nic.enabled: - # reply to the request - self.sys_log.info(f"Received echo request from {frame.ip.src_ip}") - target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip) - src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip) - tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) + if nic.ip_address == frame.ip.dst_ip: + if nic.enabled: + # reply to the request + if not is_reattempt: + self.sys_log.info(f"Received echo request from {frame.ip.src_ip}") + target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip) + src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip) + tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) - # Network Layer - ip_packet = IPPacket(src_ip=nic.ip_address, dst_ip=frame.ip.src_ip, protocol=IPProtocol.ICMP) - # Data Link Layer - ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) - icmp_reply_packet = ICMPPacket( - icmp_type=ICMPType.ECHO_REPLY, - icmp_code=0, - identifier=frame.icmp.identifier, - sequence=frame.icmp.sequence + 1, - ) - frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet) - self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip}") + # Network Layer + ip_packet = IPPacket(src_ip=nic.ip_address, dst_ip=frame.ip.src_ip, protocol=IPProtocol.ICMP) + # Data Link Layer + ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) + icmp_reply_packet = ICMPPacket( + icmp_type=ICMPType.ECHO_REPLY, + icmp_code=0, + identifier=frame.icmp.identifier, + sequence=frame.icmp.sequence + 1, + ) + frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet) + self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip}") - src_nic.send_frame(frame) + src_nic.send_frame(frame) return # Route the frame self.router.route_frame(frame, from_nic) + elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: - self.sys_log.info(f"Received echo reply from {frame.ip.src_ip}") - if not self.request_replies.get(frame.icmp.identifier): - self.request_replies[frame.icmp.identifier] = 0 - self.request_replies[frame.icmp.identifier] += 1 + for nic in self.router.nics.values(): + if nic.ip_address == frame.ip.dst_ip: + if nic.enabled: + self.sys_log.info(f"Received echo reply from {frame.ip.src_ip}") + if not self.request_replies.get(frame.icmp.identifier): + self.request_replies[frame.icmp.identifier] = 0 + self.request_replies[frame.icmp.identifier] += 1 + + return + # Route the frame + self.router.route_frame(frame, from_nic) class Router(Node): @@ -436,25 +446,34 @@ class Router(Node): pass def route_frame(self, frame: Frame, from_nic: NIC, re_attempt: bool = False) -> None: - if not re_attempt: - # Check if src ip is on network of one of the NICs - nic = self.arp.get_arp_cache_nic(frame.ip.dst_ip) - target_mac = self.arp.get_arp_cache_mac_address(frame.ip.dst_ip) - if not nic: - self.arp.send_arp_request(frame.ip.dst_ip) - return self.route_frame(frame=frame, from_nic=from_nic, re_attempt=True) - for nic in self.nics.values(): - if nic.enabled and frame.ip.dst_ip in nic.ip_network: - from_port = self._get_port_of_nic(from_nic) - to_port = self._get_port_of_nic(nic) - self.sys_log.info(f"Routing frame to internally from port {from_port} to port {to_port}") - frame.decrement_ttl() - frame.ethernet.src_mac_addr = nic.mac_address - frame.ethernet.dst_mac_addr = target_mac - nic.send_frame(frame) - return - else: + # Check if src ip is on network of one of the NICs + nic = self.arp.get_arp_cache_nic(frame.ip.dst_ip) + target_mac = self.arp.get_arp_cache_mac_address(frame.ip.dst_ip) + + if re_attempt and not nic: self.sys_log.info(f"Destination {frame.ip.dst_ip} is unreachable") + return + + if not nic: + self.arp.send_arp_request(frame.ip.dst_ip) + return self.route_frame(frame=frame, from_nic=from_nic, re_attempt=True) + + if not nic.enabled: + # TODO: Add sys_log here + return + + if frame.ip.dst_ip in nic.ip_network: + from_port = self._get_port_of_nic(from_nic) + to_port = self._get_port_of_nic(nic) + self.sys_log.info(f"Routing frame to internally from port {from_port} to port {to_port}") + frame.decrement_ttl() + frame.ethernet.src_mac_addr = nic.mac_address + frame.ethernet.dst_mac_addr = target_mac + nic.send_frame(frame) + return + else: + pass + # TODO: Deal with routing from route tables def receive_frame(self, frame: Frame, from_nic: NIC): """ From 7759c178bbe68c63430181c637a96a06c3c61d48 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 31 Aug 2023 11:20:16 +0100 Subject: [PATCH 133/980] Add logging and service restarting --- .../simulator/network/hardware/base.py | 2 ++ .../simulator/system/services/service.py | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index e3e38f86..2bdb4b55 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1007,6 +1007,7 @@ class Node(SimComponent): self.services[service.uuid] = service service.parent = self service.install() # Perform any additional setup, such as creating files for this service on the node. + self.sys_log.info(f"Installed service {service.name}") _LOGGER.info(f"Added service {service.uuid} to node {self.uuid}") def uninstall_service(self, service: Service) -> None: @@ -1021,6 +1022,7 @@ class Node(SimComponent): service.uninstall() # Perform additional teardown, such as removing files or restarting the machine. self.services.pop(service.uuid) service.parent = None + self.sys_log.info(f"Uninstalled service {service.name}") _LOGGER.info(f"Removed service {service.uuid} from node {self.uuid}") def __contains__(self, item: Any) -> bool: diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 7e67d05f..6932ce4c 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,6 +1,6 @@ from abc import abstractmethod from enum import Enum -from typing import Any, Dict +from typing import Any, Dict, Optional from primaite.simulator.core import Action, ActionManager from primaite.simulator.system.software import IOSoftware @@ -32,6 +32,10 @@ class Service(IOSoftware): operating_state: ServiceOperatingState "The current operating state of the Service." + restart_duration: int = 5 + "How many timesteps does it take to restart this service." + _restart_countdown: Optional[int] = None + "If currently restarting, how many timesteps remain until the restart is finished." def _init_action_manager(self) -> ActionManager: am = super()._init_action_manager() @@ -97,41 +101,43 @@ class Service(IOSoftware): def stop(self) -> None: """Stop the service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: + self.parent.sys_log.info(f"Stopping service {self.name}") self.operating_state = ServiceOperatingState.STOPPED def start(self) -> None: """Start the service.""" if self.operating_state == ServiceOperatingState.STOPPED: + self.parent.sys_log.info(f"Starting service {self.name}") self.operating_state = ServiceOperatingState.RUNNING def pause(self) -> None: """Pause the service.""" if self.operating_state == ServiceOperatingState.RUNNING: + self.parent.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.PAUSED def resume(self) -> None: """Resume paused service.""" if self.operating_state == ServiceOperatingState.PAUSED: + self.parent.sys_log.info(f"Resuming service {self.name}") self.operating_state = ServiceOperatingState.RUNNING def restart(self) -> None: """Restart running service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: + self.parent.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.RESTARTING - self.restart_countdown = 5 # TODO: implement restart duration + self.restart_countdown = self.restarting_duration # TODO: implement restart duration def disable(self) -> None: """Disable the service.""" - if self.operating_state in [ - ServiceOperatingState.RUNNING, - ServiceOperatingState.STOPPED, - ServiceOperatingState.PAUSED, - ]: - self.operating_state = ServiceOperatingState.DISABLED + self.parent.sys_log.info(f"Disabling Application {self.name}") + self.operating_state = ServiceOperatingState.DISABLED def enable(self) -> None: """Enable the disabled service.""" if self.operating_state == ServiceOperatingState.DISABLED: + self.parent.sys_log.info(f"Enabling Application {self.name}") self.operating_state = ServiceOperatingState.STOPPED def apply_timestep(self, timestep: int) -> None: @@ -146,6 +152,6 @@ class Service(IOSoftware): """ super().apply_timestep(timestep) if self.operating_state == ServiceOperatingState.RESTARTING: - self.restart_countdown -= 1 if self.restart_countdown <= 0: self.operating_state = ServiceOperatingState.RUNNING + self.restart_countdown -= 1 From f60f775f03a9a4ef44d4c3e491d0bf5e50a7111d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 31 Aug 2023 11:27:52 +0100 Subject: [PATCH 134/980] Improve logging --- src/primaite/simulator/system/services/service.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 6932ce4c..756f723d 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -2,9 +2,12 @@ from abc import abstractmethod from enum import Enum from typing import Any, Dict, Optional +from primaite import getLogger from primaite.simulator.core import Action, ActionManager from primaite.simulator.system.software import IOSoftware +_LOGGER = getLogger(__name__) + class ServiceOperatingState(Enum): """Enumeration of Service Operating States.""" @@ -95,35 +98,37 @@ class Service(IOSoftware): """ pass - # TODO: validate this state transition model. - # Possibly state transition could be defined more succinctly than a separate function with lots of if statements. - def stop(self) -> None: """Stop the service.""" + _LOGGER.debug(f"Stopping service {self.name}") if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.parent.sys_log.info(f"Stopping service {self.name}") self.operating_state = ServiceOperatingState.STOPPED def start(self) -> None: """Start the service.""" + _LOGGER.debug(f"Starting service {self.name}") if self.operating_state == ServiceOperatingState.STOPPED: self.parent.sys_log.info(f"Starting service {self.name}") self.operating_state = ServiceOperatingState.RUNNING def pause(self) -> None: """Pause the service.""" + _LOGGER.debug(f"Pausing service {self.name}") if self.operating_state == ServiceOperatingState.RUNNING: self.parent.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.PAUSED def resume(self) -> None: """Resume paused service.""" + _LOGGER.debug(f"Resuming service {self.name}") if self.operating_state == ServiceOperatingState.PAUSED: self.parent.sys_log.info(f"Resuming service {self.name}") self.operating_state = ServiceOperatingState.RUNNING def restart(self) -> None: """Restart running service.""" + _LOGGER.debug(f"Restarting service {self.name}") if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.parent.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.RESTARTING @@ -131,11 +136,13 @@ class Service(IOSoftware): def disable(self) -> None: """Disable the service.""" + _LOGGER.debug(f"Disabling service {self.name}") self.parent.sys_log.info(f"Disabling Application {self.name}") self.operating_state = ServiceOperatingState.DISABLED def enable(self) -> None: """Enable the disabled service.""" + _LOGGER.debug(f"Enabling service {self.name}") if self.operating_state == ServiceOperatingState.DISABLED: self.parent.sys_log.info(f"Enabling Application {self.name}") self.operating_state = ServiceOperatingState.STOPPED @@ -153,5 +160,6 @@ class Service(IOSoftware): super().apply_timestep(timestep) if self.operating_state == ServiceOperatingState.RESTARTING: if self.restart_countdown <= 0: + _LOGGER.debug(f"Restarting finished for service {self.name}") self.operating_state = ServiceOperatingState.RUNNING self.restart_countdown -= 1 From bd5aacaf0c33ee56650cf6e11e60f0d7b9d9641e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 31 Aug 2023 11:32:11 +0100 Subject: [PATCH 135/980] Remove todo comments --- src/primaite/simulator/system/services/database.py | 11 +++++++++-- src/primaite/simulator/system/services/service.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/primaite/simulator/system/services/database.py b/src/primaite/simulator/system/services/database.py index 554455b8..23b856f7 100644 --- a/src/primaite/simulator/system/services/database.py +++ b/src/primaite/simulator/system/services/database.py @@ -6,10 +6,17 @@ from primaite.simulator.system.services.service import Service class DatabaseService(Service): - """TODO.""" + """Service loosely modelled on Microsoft SQL Server.""" def describe_state(self) -> Dict: - """TODO.""" + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ return super().describe_state() def uninstall(self) -> None: diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 756f723d..f9cc784d 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -132,7 +132,7 @@ class Service(IOSoftware): if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.parent.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.RESTARTING - self.restart_countdown = self.restarting_duration # TODO: implement restart duration + self.restart_countdown = self.restarting_duration def disable(self) -> None: """Disable the service.""" From 89ad22acebbd39cc6bf7a30808b104f46bd1152b Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 31 Aug 2023 13:35:56 +0100 Subject: [PATCH 136/980] #1800 - Synced with dev. - Added the UC2 network. - Added a Computer class. --- src/primaite/simulator/network/container.py | 29 +++- .../network/hardware/nodes/computer.py | 44 +++++ src/primaite/simulator/network/networks.py | 154 ++++++++++++++++++ 3 files changed, 221 insertions(+), 6 deletions(-) create mode 100644 src/primaite/simulator/network/hardware/nodes/computer.py create mode 100644 src/primaite/simulator/network/networks.py diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 85676034..ac502d84 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, Union +from typing import Any, Dict, Union, Optional from primaite import getLogger from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent @@ -58,6 +58,19 @@ class Network(SimComponent): node.parent = self _LOGGER.info(f"Added node {node.uuid} to Network {self.uuid}") + def get_node_by_hostname(self, hostname: str) -> Optional[Node]: + """ + Get a Node from the Network by its hostname. + + .. note:: Assumes hostnames on the network are unique. + + :param hostname: The Node hostname. + :return: The Node if it exists in the network. + """ + for node in self.nodes.values(): + if node.hostname == hostname: + return node + def remove_node(self, node: Node) -> None: """ Remove a node from the network. @@ -72,7 +85,8 @@ class Network(SimComponent): node.parent = None _LOGGER.info(f"Removed node {node.uuid} from network {self.uuid}") - def connect(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> None: + def connect(self, endpoint_a: Union[Node, NIC, SwitchPort], endpoint_b: Union[Node, NIC, SwitchPort], **kwargs) -> \ + None: """Connect two nodes on the network by creating a link between an NIC/SwitchPort of each one. :param endpoint_a: The endpoint to which to connect the link on the first node @@ -81,16 +95,19 @@ class Network(SimComponent): :type endpoint_b: Union[NIC, SwitchPort] :raises RuntimeError: _description_ """ - node_a = endpoint_a.parent - node_b = endpoint_b.parent + node_a: Node = endpoint_a.parent if not isinstance(endpoint_a, Node) else endpoint_a + node_b: Node = endpoint_b.parent if not isinstance(endpoint_b, Node) else endpoint_b if node_a not in self: self.add_node(node_a) if node_b not in self: self.add_node(node_b) if node_a is node_b: - _LOGGER.warn(f"Cannot link endpoint {endpoint_a} to {endpoint_b} because they belong to the same node.") + _LOGGER.warning(f"Cannot link endpoint {endpoint_a} to {endpoint_b} because they belong to the same node.") return - + if isinstance(endpoint_a, Node) and len(endpoint_a.nics) == 1: + endpoint_a = list(endpoint_a.nics.values())[0] + if isinstance(endpoint_b, Node) and len(endpoint_b.nics) == 1: + endpoint_b = list(endpoint_b.nics.values())[0] link = Link(endpoint_a=endpoint_a, endpoint_b=endpoint_b, **kwargs) self.links[link.uuid] = link link.parent = self diff --git a/src/primaite/simulator/network/hardware/nodes/computer.py b/src/primaite/simulator/network/hardware/nodes/computer.py new file mode 100644 index 00000000..8dfb7540 --- /dev/null +++ b/src/primaite/simulator/network/hardware/nodes/computer.py @@ -0,0 +1,44 @@ +from ipaddress import IPv4Address + +from primaite.simulator.network.hardware.base import Node, NIC + + +class Computer(Node): + """ + A basic computer class. + + Example: + >>> pc_a = Computer( + hostname="pc_a", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1" + ) + >>> pc_a.power_on() + + Instances of computer come 'pre-packaged' with the following: + + * Core Functionality: + * ARP. + * ICMP. + * Packet Capture. + * Sys Log. + * Services: + * DNS Client. + * FTP Client. + * LDAP Client. + * NTP Client. + * Applications: + * Email Client. + * Web Browser. + * Processes: + * Placeholder. + """ + + def __init__(self, **kwargs): + for key in {"ip_address", "subnet_mask", "default_gateway"}: + if key in kwargs: + if not isinstance(kwargs[key], IPv4Address): + kwargs[key] = IPv4Address(kwargs[key]) + super().__init__(**kwargs) + self.connect_nic(NIC(ip_address=kwargs["ip_address"], subnet_mask=kwargs["subnet_mask"])) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py new file mode 100644 index 00000000..0eccefa4 --- /dev/null +++ b/src/primaite/simulator/network/networks.py @@ -0,0 +1,154 @@ +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.base import Switch, NIC +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.router import Router, ACLAction +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port + + +def arcd_uc2_network() -> Network: + """ + Models the ARCD Use Case 2 Network. + + +------------+ + | domain_ | + +------------+ controller | + | | | + | +------------+ + | + | + +------------+ | +------------+ + | | | | | + | client_1 +---------+ | +---------+ web_server | + | | | | | | | + +------------+ | | | +------------+ + +--+---------+ +------------+ +------+--+--+ + | | | | | | + | switch_2 +------+ router_1 +------+ switch_1 | + | | | | | | + +--+------+--+ +------------+ +--+---+--+--+ + +------------+ | | | | | +------------+ + | | | | | | | | database | + | client_2 +---------+ | | | +---------+ _server | + | | | | | | | + +------------+ | | | +------------+ + | +------------+ | | + | | security | | | + +---------+ _suite +---------+ | +------------+ + | | | | backup_ | + +------------+ +------------+ server | + | | + +------------+ + + Example: + >>> network = arcd_uc2_network() + >>> network.get_node_by_hostname("client_1").ping("192.168.1.10") + + """ + network = Network() + + # Router 1 + router_1 = Router(hostname="router_1", num_ports=5) + router_1.power_on() + router_1.configure_port(port=1, ip_address="192.168.1.1", subnet_mask="255.255.255.0") + router_1.configure_port(port=2, ip_address="192.168.10.1", subnet_mask="255.255.255.0") + + # Switch 1 + switch_1 = Switch(hostname="switch_1", num_ports=8) + switch_1.power_on() + network.connect(endpoint_a=router_1.ethernet_ports[1], endpoint_b=switch_1.switch_ports[8]) + router_1.enable_port(1) + + # Switch 2 + switch_2 = Switch(hostname="switch_2", num_ports=8) + switch_2.power_on() + network.connect(endpoint_a=router_1.ethernet_ports[2], endpoint_b=switch_2.switch_ports[8]) + router_1.enable_port(2) + + # Client 1 + client_1 = Computer( + hostname="client_1", + ip_address="192.168.10.21", + subnet_mask="255.255.255.0", + default_gateway="192.168.10.1" + ) + client_1.power_on() + network.connect(endpoint_a=client_1, endpoint_b=switch_2.switch_ports[1]) + + # Client 2 + client_2 = Computer( + hostname="client_2", + ip_address="192.168.10.22", + subnet_mask="255.255.255.0", + default_gateway="192.168.10.1" + ) + client_2.power_on() + network.connect(endpoint_a=client_2, endpoint_b=switch_2.switch_ports[2]) + + # Domain Controller + domain_controller = Computer( + hostname="domain_controller", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1" + ) + domain_controller.power_on() + network.connect(endpoint_a=domain_controller, endpoint_b=switch_1.switch_ports[1]) + + # Web Server + web_server = Computer( + hostname="web_server", + ip_address="192.168.1.12", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1" + ) + web_server.power_on() + network.connect(endpoint_a=web_server, endpoint_b=switch_1.switch_ports[2]) + + # Database Server + database_server = Computer( + hostname="database_server", + ip_address="192.168.1.14", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1" + ) + database_server.power_on() + network.connect(endpoint_a=database_server, endpoint_b=switch_1.switch_ports[3]) + + # Backup Server + backup_server = Computer( + hostname="backup_server", + ip_address="192.168.1.16", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1" + ) + backup_server.power_on() + network.connect(endpoint_a=backup_server, endpoint_b=switch_1.switch_ports[4]) + + # Security Suite + security_suite = Computer( + hostname="security_suite", + ip_address="192.168.1.110", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1" + ) + security_suite.power_on() + network.connect(endpoint_a=security_suite, endpoint_b=switch_1.switch_ports[7]) + security_suite_external_nic = NIC(ip_address="192.168.10.110", subnet_mask="255.255.255.0") + security_suite.connect_nic(security_suite_external_nic) + network.connect(endpoint_a=security_suite_external_nic, endpoint_b=switch_2.switch_ports[7]) + + router_1.acl.add_rule( + action=ACLAction.PERMIT, + src_port=Port.ARP, + dst_port=Port.ARP, + position=22 + ) + + router_1.acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.ICMP, + position=23 + ) + + return network From 61fa83a00d81e8967f13966bab99e898b93552f3 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 31 Aug 2023 14:55:14 +0100 Subject: [PATCH 137/980] Fix failing test --- tests/unit_tests/_primaite/_simulator/test_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/_primaite/_simulator/test_core.py b/tests/unit_tests/_primaite/_simulator/test_core.py index bbb1298f..069e6ea2 100644 --- a/tests/unit_tests/_primaite/_simulator/test_core.py +++ b/tests/unit_tests/_primaite/_simulator/test_core.py @@ -44,4 +44,4 @@ class TestIsolatedSimComponent: comp = TestComponent(name="computer", size=(5, 10)) dump = comp.model_dump_json() reconstructed = TestComponent.model_validate_json(dump) - assert comp == reconstructed.model_dump_json() + assert dump == reconstructed.model_dump_json() From 5111affeebbc8a75becbfa2c31b34eed4a8a9ebc Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 1 Sep 2023 16:58:21 +0100 Subject: [PATCH 138/980] #1800 - Added more docstrings and rst docs. - Extended the .show functionality to enable markdown format too. --- docs/source/simulation.rst | 3 + .../simulation_components/network/network.rst | 114 +++++++++ .../simulation_components/network/router.rst | 73 ++++++ .../simulation_components/network/switch.rst | 8 + src/primaite/simulator/network/container.py | 175 +++++++++++-- .../simulator/network/hardware/base.py | 62 +++-- .../network/hardware/nodes/computer.py | 24 +- .../network/hardware/nodes/router.py | 240 +++++++++++++++--- .../network/hardware/nodes/server.py | 37 +++ src/primaite/simulator/network/networks.py | 103 ++++++-- .../network/transmission/data_link_layer.py | 5 + src/primaite/simulator/system/core/sys_log.py | 17 +- 12 files changed, 753 insertions(+), 108 deletions(-) create mode 100644 docs/source/simulation_components/network/network.rst create mode 100644 docs/source/simulation_components/network/router.rst create mode 100644 docs/source/simulation_components/network/switch.rst create mode 100644 src/primaite/simulator/network/hardware/nodes/server.py diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index a2784628..7e9fe77f 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -18,3 +18,6 @@ Contents simulation_structure simulation_components/network/base_hardware simulation_components/network/transport_to_data_link_layer + simulation_components/network/router + simulation_components/network/switch + simulation_components/network/network diff --git a/docs/source/simulation_components/network/network.rst b/docs/source/simulation_components/network/network.rst new file mode 100644 index 00000000..e5614980 --- /dev/null +++ b/docs/source/simulation_components/network/network.rst @@ -0,0 +1,114 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _about: + +Network +======= + +The ``Network`` class serves as the backbone of the simulation. It offers a framework to manage various network +components such as routers, switches, servers, and clients. This document provides a detailed explanation of how to +effectively use the ``Network`` class. + +Example Usage +------------- + +Below demonstrates how to use the Router node to connect Nodes, and block traffic using ACLs. For this demonstration, +we'll use the following Network that has a client, server, two switches, and a router. + +.. code-block:: text + + +------------+ +------------+ +------------+ +------------+ +------------+ + | | | | | | | | | | + | client_1 +------+ switch_2 +------+ router_1 +------+ switch_1 +------+ server_1 | + | | | | | | | | | | + +------------+ +------------+ +------------+ +------------+ +------------+ + +1. Relevant imports + +.. code-block:: python + + from primaite.simulator.network.container import Network + from primaite.simulator.network.hardware.base import Switch, NIC + from primaite.simulator.network.hardware.nodes.computer import Computer + from primaite.simulator.network.hardware.nodes.router import Router, ACLAction + from primaite.simulator.network.hardware.nodes.server import Server + from primaite.simulator.network.transmission.network_layer import IPProtocol + from primaite.simulator.network.transmission.transport_layer import Port + +2. Create the Network + +.. code-block:: python + + network = Network() + +3. Create and configure the Router + +.. code-block:: python + + router_1 = Router(hostname="router_1", num_ports=3) + router_1.power_on() + router_1.configure_port(port=1, ip_address="192.168.1.1", subnet_mask="255.255.255.0") + router_1.configure_port(port=2, ip_address="192.168.2.1", subnet_mask="255.255.255.0") + +4. Create and configure the two Switches + +.. code-block:: python + + switch_1 = Switch(hostname="switch_1", num_ports=6) + switch_1.power_on() + switch_2 = Switch(hostname="switch_2", num_ports=6) + switch_2.power_on() + +5. Connect the Switches to the Router + +.. code-block:: python + + network.connect(endpoint_a=router_1.ethernet_ports[1], endpoint_b=switch_1.switch_ports[6]) + router_1.enable_port(1) + network.connect(endpoint_a=router_1.ethernet_ports[2], endpoint_b=switch_2.switch_ports[6]) + router_1.enable_port(2) + +6. Create the Client and Server nodes. + +.. code-block:: python + + client_1 = Computer( + hostname="client_1", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.2.1" + ) + client_1.power_on() + server_1 = Server( + hostname="server_1", + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1" + ) + server_1.power_on() + +7. Connect the Client and Server to the relevant Switch + +.. code-block:: python + + network.connect(endpoint_a=switch_2.switch_ports[1], endpoint_b=client_1.ethernet_port[1]) + network.connect(endpoint_a=switch_1.switch_ports[1], endpoint_b=server_1.ethernet_port[1]) + +8. Add ACL rules on the Router to allow ARP and ICMP traffic. + +.. code-block:: python + + router_1.acl.add_rule( + action=ACLAction.PERMIT, + src_port=Port.ARP, + dst_port=Port.ARP, + position=22 + ) + + router_1.acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.ICMP, + position=23 + ) diff --git a/docs/source/simulation_components/network/router.rst b/docs/source/simulation_components/network/router.rst new file mode 100644 index 00000000..aaa589cc --- /dev/null +++ b/docs/source/simulation_components/network/router.rst @@ -0,0 +1,73 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _about: + +Router Module +============= + +The router module contains classes for simulating the functions of a network router. + +Router +------ + +The Router class represents a multi-port network router that can receive, process, and route network packets between its ports and other Nodes + +The router maintains internal state including: + +- RouteTable - Routing table to lookup where to forward packets. +- AccessControlList - Access control rules to block or allow packets. +- ARP cache - MAC address lookups for connected devices. +- ICMP handler - Handles ICMP requests to router interfaces. + +The router receives incoming frames on enabled ports. It processes the frame headers and applies the following logic: + +1. Checks the AccessControlList if the packet is permitted. If blocked, it is dropped. +2. For permitted packets, routes the frame based on: + - ARP cache lookups for destination MAC address. + - ICMP echo requests handled directly. + - RouteTable lookup to forward packet out other ports. +3. Updates ARP cache as it learns new information about the Network. + + + +RouteTable +---------- + +The RouteTable holds RouteEntry objects representing routes. It finds the best route for a destination IP using a metric and the longest prefix match algorithm. + +Routes can be added and looked up based on destination IP address. The RouteTable is used by the Router when forwarding packets between other Nodes. + +AccessControlList +----------------- + +The AccessControlList defines Access Control Rules to block or allow packets. Packets are checked against the rules to determine if they are permitted to be forwarded. + +Rules can be added to deny or permit traffic based on IP, port, and protocol. The ACL is checked by the Router when packets are received. + +Packet Processing +----------------- + +-The Router supports the following protocols and packet types: + +ARP +^^^ + +- Handles both ARP requests and responses. +- Updates ARP cache. +- Proxies ARP replies for connected networks. +- Routes ARP requests. + +ICMP +^^^^ + +- Responds to ICMP echo requests to Router interfaces. +- Routes other ICMP messages based on routes. + +TCP/UDP +^^^^^^^ + +- Forwards packets based on routes like IP. +- Applies ACL rules based on protocol, source/destination IP address, and source/destination port numbers. +- Decrements TTL and drops expired TTL packets. diff --git a/docs/source/simulation_components/network/switch.rst b/docs/source/simulation_components/network/switch.rst new file mode 100644 index 00000000..4b3b24bc --- /dev/null +++ b/docs/source/simulation_components/network/switch.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _about: + +Switch +====== \ No newline at end of file diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index ac502d84..ccb9ce77 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -1,20 +1,41 @@ -from typing import Any, Dict, Union, Optional +from typing import Any, Dict, Union, Optional, List + +import matplotlib.pyplot as plt +import networkx as nx +from networkx import MultiGraph +from prettytable import PrettyTable, MARKDOWN from primaite import getLogger from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent -from primaite.simulator.network.hardware.base import Link, NIC, Node, SwitchPort +from primaite.simulator.network.hardware.base import Link, NIC, Node, SwitchPort, Switch +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.router import Router +from primaite.simulator.network.hardware.nodes.server import Server _LOGGER = getLogger(__name__) class Network(SimComponent): - """Top level container object representing the physical network.""" + """ + Top level container object representing the physical network. + + This class manages nodes, links, and other network components. It also + offers methods for rendering the network topology and gathering states. + + :ivar Dict[str, Node] nodes: Dictionary mapping node UUIDs to Node instances. + :ivar Dict[str, Link] links: Dictionary mapping link UUIDs to Link instances. + """ nodes: Dict[str, Node] = {} links: Dict[str, Link] = {} def __init__(self, **kwargs): - """Initialise the network.""" + """" + Initialise the network. + + Constructs the network and sets up its initial state including + the action manager and an empty MultiGraph for topology representation. + """ super().__init__(**kwargs) self.action_manager = ActionManager() @@ -25,15 +46,112 @@ class Network(SimComponent): validator=AllowAllValidator(), ), ) + self._nx_graph = MultiGraph() + + @property + def routers(self) -> List[Router]: + """The Routers in the Network.""" + return [node for node in self.nodes.values() if isinstance(node, Router)] + + @property + def switches(self) -> List[Switch]: + """The Switches in the Network.""" + return [node for node in self.nodes.values() if isinstance(node, Switch)] + + @property + def computers(self) -> List[Computer]: + """The Computers in the Network.""" + return [node for node in self.nodes.values() if isinstance(node, Computer) and not isinstance(node, Server)] + + @property + def servers(self) -> List[Server]: + """The Servers in the Network.""" + return [node for node in self.nodes.values() if isinstance(node, Server)] + + def show(self, nodes: bool = True, ip_addresses: bool = True, links: bool = True, markdown: bool = False): + """ + Print tables describing the Network. + + Generate and print PrettyTable instances that show details about nodes, + IP addresses, and links in the network. Output can be in Markdown format. + + :param nodes: Include node details in the output. Defaults to True. + :param ip_addresses: Include IP address details in the output. Defaults to True. + :param links: Include link details in the output. Defaults to True. + :param markdown: Use Markdown style in table output. Defaults to False. + """ + nodes_type_map = { + "Router": self.routers, + "Switch": self.switches, + "Server": self.servers, + "Computer": self.computers + } + if nodes: + table = PrettyTable(["Node", "Type", "Operating State"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"Nodes" + for node_type, nodes in nodes_type_map.items(): + for node in nodes: + table.add_row([node.hostname, node_type, node.operating_state.name]) + print(table) + + if ip_addresses: + table = PrettyTable(["Node", "Port", "IP Address", "Subnet Mask", "Default Gateway"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"IP Addresses" + for nodes in nodes_type_map.values(): + for node in nodes: + for i, port in node.ethernet_port.items(): + table.add_row([node.hostname, i, port.ip_address, port.subnet_mask, node.default_gateway]) + print(table) + + if links: + table = PrettyTable(["Endpoint A", "Endpoint B", "is Up", "Bandwidth (MBits)", "Current Load"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"Links" + links = list(self.links.values()) + for nodes in nodes_type_map.values(): + for node in nodes: + for link in links[::-1]: + if node in [link.endpoint_a.parent, link.endpoint_b.parent]: + table.add_row( + [ + link.endpoint_a.parent.hostname, + link.endpoint_b.parent.hostname, + link.is_up, + link.bandwidth, + link.current_load_percent + ] + ) + links.remove(link) + print(table) + + def clear_links(self): + """Clear all the links in the network by resetting their component state for the episode.""" + for link in self.links.values(): + link.reset_component_for_episode() + + def draw(self, seed: int = 123): + """ + Draw the Network using NetworkX and matplotlib.pyplot. + + :param seed: An integer seed for reproducible layouts. Default is 123. + """ + pos = nx.spring_layout(self._nx_graph, seed=seed) + nx.draw(self._nx_graph, pos, with_labels=True) + plt.show() def describe_state(self) -> Dict: """ - Produce a dictionary describing the current state of this object. + Produce a dictionary describing the current state of the Network. - Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - - :return: Current state of this object and child objects. - :rtype: Dict + :return: A dictionary capturing the current state of the Network and its child objects. """ state = super().describe_state() state.update( @@ -48,14 +166,16 @@ class Network(SimComponent): """ Add an existing node to the network. - :param node: Node instance that the network should keep track of. - :type node: Node + .. note:: If the node is already present in the network, a warning is logged. + + :param node: Node instance that should be kept track of by the network. """ if node in self: _LOGGER.warning(f"Can't add node {node.uuid}. It is already in the network.") return self.nodes[node.uuid] = node node.parent = self + self._nx_graph.add_node(node.hostname) _LOGGER.info(f"Added node {node.uuid} to Network {self.uuid}") def get_node_by_hostname(self, hostname: str) -> Optional[Node]: @@ -75,6 +195,8 @@ class Network(SimComponent): """ Remove a node from the network. + .. note:: If the node is not found in the network, a warning is logged. + :param node: Node instance that is currently part of the network that should be removed. :type node: Node """ @@ -85,18 +207,22 @@ class Network(SimComponent): node.parent = None _LOGGER.info(f"Removed node {node.uuid} from network {self.uuid}") - def connect(self, endpoint_a: Union[Node, NIC, SwitchPort], endpoint_b: Union[Node, NIC, SwitchPort], **kwargs) -> \ - None: - """Connect two nodes on the network by creating a link between an NIC/SwitchPort of each one. - - :param endpoint_a: The endpoint to which to connect the link on the first node - :type endpoint_a: Union[NIC, SwitchPort] - :param endpoint_b: The endpoint to which to connct the link on the second node - :type endpoint_b: Union[NIC, SwitchPort] - :raises RuntimeError: _description_ + def connect( + self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs + ) -> None: """ - node_a: Node = endpoint_a.parent if not isinstance(endpoint_a, Node) else endpoint_a - node_b: Node = endpoint_b.parent if not isinstance(endpoint_b, Node) else endpoint_b + Connect two endpoints on the network by creating a link between their NICs/SwitchPorts. + + .. note:: If the nodes owning the endpoints are not already in the network, they are automatically added. + + :param endpoint_a: The first endpoint to connect. + :type endpoint_a: Union[NIC, SwitchPort] + :param endpoint_b: The second endpoint to connect. + :type endpoint_b: Union[NIC, SwitchPort] + :raises RuntimeError: If any validation or runtime checks fail. + """ + node_a: Node = endpoint_a.parent + node_b: Node = endpoint_b.parent if node_a not in self: self.add_node(node_a) if node_b not in self: @@ -104,12 +230,9 @@ class Network(SimComponent): if node_a is node_b: _LOGGER.warning(f"Cannot link endpoint {endpoint_a} to {endpoint_b} because they belong to the same node.") return - if isinstance(endpoint_a, Node) and len(endpoint_a.nics) == 1: - endpoint_a = list(endpoint_a.nics.values())[0] - if isinstance(endpoint_b, Node) and len(endpoint_b.nics) == 1: - endpoint_b = list(endpoint_b.nics.values())[0] link = Link(endpoint_a=endpoint_a, endpoint_b=endpoint_b, **kwargs) self.links[link.uuid] = link + self._nx_graph.add_edge(endpoint_a.parent.hostname, endpoint_b.parent.hostname) link.parent = self _LOGGER.info(f"Added link {link.uuid} to connect {endpoint_a} and {endpoint_b}") diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 9834d439..674020ee 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1,12 +1,13 @@ from __future__ import annotations +import random import re import secrets from enum import Enum from ipaddress import IPv4Address, IPv4Network from typing import Dict, List, Optional, Tuple, Union -from prettytable import PrettyTable +from prettytable import PrettyTable, MARKDOWN from primaite import getLogger from primaite.exceptions import NetworkError @@ -256,7 +257,6 @@ class NIC(SimComponent): The Frame is passed to the Node. :param frame: The network frame being received. - :type frame: :class:`~primaite.simulator.network.osi_layers.Frame` """ if self.enabled: frame.decrement_ttl() @@ -266,9 +266,6 @@ class NIC(SimComponent): if frame.ethernet.dst_mac_addr == self.mac_address or frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": self.connected_node.receive_frame(frame=frame, from_nic=self) return True - else: - self.connected_node.sys_log.info("Dropping frame not for me") - print(frame) return False def __str__(self) -> str: @@ -562,9 +559,12 @@ class ARPCache: self.arp: Dict[IPv4Address, ARPEntry] = {} self.nics: Dict[str, "NIC"] = {} - def show(self): + def show(self, markdown: bool = False): """Prints a table of ARC Cache.""" table = PrettyTable(["IP Address", "MAC Address", "Via"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" table.title = f"{self.sys_log.hostname} ARP Cache" for ip, arp in self.arp.items(): table.add_row( @@ -765,12 +765,22 @@ class ICMP: identifier=frame.icmp.identifier, sequence=frame.icmp.sequence + 1, ) - frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet) + payload = secrets.token_urlsafe(int(32/1.3)) # Standard ICMP 32 bytes size + frame = Frame( + ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet, payload=payload + ) self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip}") src_nic.send_frame(frame) elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: - self.sys_log.info(f"Received echo reply from {frame.ip.src_ip}") + time = frame.transmission_duration() + time_str = f"{time}ms" if time > 0 else "<1ms" + self.sys_log.info( + f"Reply from {frame.ip.src_ip}: " + f"bytes={len(frame.payload)}, " + f"time={time_str}, " + f"TTL={frame.ip.ttl}" + ) if not self.request_replies.get(frame.icmp.identifier): self.request_replies[frame.icmp.identifier] = 0 self.request_replies[frame.icmp.identifier] += 1 @@ -819,8 +829,8 @@ class ICMP: # Data Link Layer ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) icmp_packet = ICMPPacket(identifier=identifier, sequence=sequence) - frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_packet) - self.sys_log.info(f"Sending echo request to {target_ip_address}") + payload = secrets.token_urlsafe(int(32/1.3)) # Standard ICMP 32 bytes size + frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_packet, payload=payload) nic.send_frame(frame) return sequence, icmp_packet.identifier @@ -857,6 +867,8 @@ class Node(SimComponent): "The hardware state of the node." nics: Dict[str, NIC] = {} "The NICs on the node." + ethernet_port: Dict[int, NIC] = {} + "The NICs on the node by port id." accounts: Dict[str, Account] = {} "All accounts on the node." @@ -928,13 +940,17 @@ class Node(SimComponent): ) return state - def show(self): + def show(self, markdown: bool = False): """Prints a table of the NICs on the Node.""" - table = PrettyTable(["MAC Address", "Address", "Speed", "Status"]) + table = PrettyTable(["Port", "MAC Address", "Address", "Speed", "Status"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" table.title = f"{self.hostname} Network Interface Cards" - for nic in self.nics.values(): + for port, nic in self.ethernet_port.items(): table.add_row( [ + port, nic.mac_address, f"{nic.ip_address}/{nic.ip_network.prefixlen}", nic.speed, @@ -969,6 +985,7 @@ class Node(SimComponent): """ if nic.uuid not in self.nics: self.nics[nic.uuid] = nic + self.ethernet_port[len(self.nics)] = nic nic.connected_node = self nic.parent = self self.sys_log.info(f"Connected NIC {nic}") @@ -990,6 +1007,10 @@ class Node(SimComponent): if isinstance(nic, str): nic = self.nics.get(nic) if nic or nic.uuid in self.nics: + for port, _nic in self.ethernet_port.items(): + if nic == _nic: + self.ethernet_port.pop(port) + break self.nics.pop(nic.uuid) nic.parent = None nic.disable() @@ -1014,7 +1035,7 @@ class Node(SimComponent): self.sys_log.info("Pinging loopback address") return any(nic.enabled for nic in self.nics.values()) if self.operating_state == NodeOperatingState.ON: - self.sys_log.info(f"Attempting to ping {target_ip_address}") + self.sys_log.info(f"Pinging {target_ip_address}:") sequence, identifier = 0, None while sequence < pings: sequence, identifier = self.icmp.ping(target_ip_address, sequence, identifier, pings) @@ -1022,8 +1043,14 @@ class Node(SimComponent): passed = request_replies == pings if request_replies: self.icmp.request_replies.pop(identifier) + else: + request_replies = 0 + self.sys_log.info( + f"Ping statistics for {target_ip_address}: " + f"Packets: Sent = {pings}, " + f"Received = {request_replies}, " + f"Lost = {pings-request_replies} ({(pings-request_replies)/pings*100}% loss)") return passed - self.sys_log.info("Ping failed as the node is turned off") return False def send_frame(self, frame: Frame): @@ -1078,9 +1105,12 @@ class Switch(Node): port.parent = self port.port_num = port_num - def show(self): + def show(self, markdown: bool = False): """Prints a table of the SwitchPorts on the Switch.""" table = PrettyTable(["Port", "MAC Address", "Speed", "Status"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" table.title = f"{self.hostname} Switch Ports" for port_num, port in self.switch_ports.items(): table.add_row([port_num, port.mac_address, port.speed, "Enabled" if port.enabled else "Disabled"]) diff --git a/src/primaite/simulator/network/hardware/nodes/computer.py b/src/primaite/simulator/network/hardware/nodes/computer.py index 8dfb7540..110ad385 100644 --- a/src/primaite/simulator/network/hardware/nodes/computer.py +++ b/src/primaite/simulator/network/hardware/nodes/computer.py @@ -5,7 +5,7 @@ from primaite.simulator.network.hardware.base import Node, NIC class Computer(Node): """ - A basic computer class. + A basic Computer class. Example: >>> pc_a = Computer( @@ -19,20 +19,20 @@ class Computer(Node): Instances of computer come 'pre-packaged' with the following: * Core Functionality: - * ARP. - * ICMP. - * Packet Capture. - * Sys Log. + * ARP + * ICMP + * Packet Capture + * Sys Log * Services: - * DNS Client. - * FTP Client. - * LDAP Client. - * NTP Client. + * DNS Client + * FTP Client + * LDAP Client + * NTP Client * Applications: - * Email Client. - * Web Browser. + * Email Client + * Web Browser * Processes: - * Placeholder. + * Placeholder """ def __init__(self, **kwargs): diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 7db92938..b507143b 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -1,10 +1,11 @@ from __future__ import annotations +import secrets from enum import Enum from ipaddress import IPv4Address, IPv4Network from typing import Dict, List, Optional, Tuple, Union -from prettytable import PrettyTable +from prettytable import PrettyTable, MARKDOWN from primaite.simulator.core import SimComponent from primaite.simulator.network.hardware.base import ARPCache, ICMP, NIC, Node @@ -22,8 +23,16 @@ class ACLAction(Enum): class ACLRule(SimComponent): - def describe_state(self) -> Dict: - pass + """ + Represents an Access Control List (ACL) rule. + + :ivar ACLAction action: Action to be performed (Permit/Deny). Default is DENY. + :ivar Optional[IPProtocol] protocol: Network protocol. Default is None. + :ivar Optional[IPv4Address] src_ip: Source IP address. Default is None. + :ivar Optional[Port] src_port: Source port number. Default is None. + :ivar Optional[IPv4Address] dst_ip: Destination IP address. Default is None. + :ivar Optional[Port] dst_port: Destination port number. Default is None. + """ action: ACLAction = ACLAction.DENY protocol: Optional[IPProtocol] = None @@ -43,8 +52,25 @@ class ACLRule(SimComponent): rule_strings.append(f"{key}={value}") return ", ".join(rule_strings) + def describe_state(self) -> Dict: + """ + Describes the current state of the ACLRule. + + :return: A dictionary representing the current state. + """ + pass + class AccessControlList(SimComponent): + """ + Manages a list of ACLRules to filter network traffic. + + :ivar SysLog sys_log: System logging instance. + :ivar ACLAction implicit_action: Default action for rules. + :ivar ACLRule implicit_rule: Implicit ACL rule, created based on implicit_action. + :ivar int max_acl_rules: Maximum number of ACL rules that can be added. Default is 25. + :ivar List[Optional[ACLRule]] _acl: A list containing the ACL rules. + """ sys_log: SysLog implicit_action: ACLAction implicit_rule: ACLRule @@ -62,10 +88,20 @@ class AccessControlList(SimComponent): super().__init__(**kwargs) def describe_state(self) -> Dict: + """ + Describes the current state of the AccessControlList. + + :return: A dictionary representing the current state. + """ pass @property def acl(self) -> List[Optional[ACLRule]]: + """ + Get the list of ACL rules. + + :return: The list of ACL rules. + """ return self._acl def add_rule( @@ -78,6 +114,18 @@ class AccessControlList(SimComponent): dst_port: Optional[Port] = None, position: int = 0, ) -> None: + """ + Add a new ACL rule. + + :param ACLAction action: Action to be performed (Permit/Deny). + :param Optional[IPProtocol] protocol: Network protocol. + :param Optional[Union[str, IPv4Address]] src_ip: Source IP address. + :param Optional[Port] src_port: Source port number. + :param Optional[Union[str, IPv4Address]] dst_ip: Destination IP address. + :param Optional[Port] dst_port: Destination port number. + :param int position: Position in the ACL list to insert the rule. + :raises ValueError: When the position is out of bounds. + """ if isinstance(src_ip, str): src_ip = IPv4Address(src_ip) if isinstance(dst_ip, str): @@ -90,6 +138,12 @@ class AccessControlList(SimComponent): raise ValueError(f"Position {position} is out of bounds.") def remove_rule(self, position: int) -> None: + """ + Remove an ACL rule from a specific position. + + :param int position: The position of the rule to be removed. + :raises ValueError: When the position is out of bounds. + """ if 0 <= position < self.max_acl_rules: self._acl[position] = None else: @@ -103,6 +157,17 @@ class AccessControlList(SimComponent): dst_ip: Union[str, IPv4Address], dst_port: Optional[Port], ) -> Tuple[bool, Optional[Union[str, ACLRule]]]: + """ + Check if a packet with the given properties is permitted through the ACL. + + :param protocol: The protocol of the packet. + :param src_ip: Source IP address of the packet. Accepts string and IPv4Address. + :param src_port: Source port of the packet. Optional. + :param dst_ip: Destination IP address of the packet. Accepts string and IPv4Address. + :param dst_port: Destination port of the packet. Optional. + :return: A tuple with a boolean indicating if the packet is permitted and an optional rule or implicit action + string. + """ if not isinstance(src_ip, IPv4Address): src_ip = IPv4Address(src_ip) if not isinstance(dst_ip, IPv4Address): @@ -130,6 +195,16 @@ class AccessControlList(SimComponent): dst_ip: Union[str, IPv4Address], dst_port: Port, ) -> List[ACLRule]: + """ + Get the list of relevant rules for a packet with given properties. + + :param protocol: The protocol of the packet. + :param src_ip: Source IP address of the packet. Accepts string and IPv4Address. + :param src_port: Source port of the packet. + :param dst_ip: Destination IP address of the packet. Accepts string and IPv4Address. + :param dst_port: Destination port of the packet. + :return: A list of relevant ACLRules. + """ if not isinstance(src_ip, IPv4Address): src_ip = IPv4Address(src_ip) if not isinstance(dst_ip, IPv4Address): @@ -150,17 +225,16 @@ class AccessControlList(SimComponent): return relevant_rules - def show(self): - """Prints a table of the routes in the RouteTable.""" + def show(self, markdown: bool = False): + """ + Display the current ACL rules as a table. + + :param markdown: Whether to display the table in Markdown format. Defaults to False. """ - action: ACLAction - protocol: Optional[IPProtocol] - src_ip: Optional[IPv4Address] - src_port: Optional[Port] - dst_ip: Optional[IPv4Address] - dst_port: Optional[Port] - """ table = PrettyTable(["Index", "Action", "Protocol", "Src IP", "Src Port", "Dst IP", "Dst Port"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" table.title = f"{self.sys_log.hostname} Access Control List" for index, rule in enumerate(self.acl + [self.implicit_rule]): if rule: @@ -213,6 +287,11 @@ class RouteEntry(SimComponent): super().__init__(**kwargs) def describe_state(self) -> Dict: + """ + Describes the current state of the RouteEntry. + + :return: A dictionary representing the current state. + """ pass @@ -220,12 +299,7 @@ class RouteTable(SimComponent): """ Represents a routing table holding multiple route entries. - Attributes: - routes (List[RouteEntry]): A list of RouteEntry objects. - - Methods: - add_route: Add a route to the routing table. - find_best_route: Find the best route for a given destination IP. + :ivar List[RouteEntry] routes: A list of RouteEntry objects. Example: >>> rt = RouteTable() @@ -244,6 +318,11 @@ class RouteTable(SimComponent): sys_log: SysLog def describe_state(self) -> Dict: + """ + Describes the current state of the RouteTable. + + :return: A dictionary representing the current state. + """ pass def add_route( @@ -253,9 +332,13 @@ class RouteTable(SimComponent): next_hop: Union[IPv4Address, str], metric: float = 0.0, ): - """Add a route to the routing table. + """ + Add a route to the routing table. - :param route: A RouteEntry object representing the route. + :param address: The destination address of the route. + :param subnet_mask: The subnet mask of the route. + :param next_hop: The next hop IP for the route. + :param metric: The metric of the route, default is 0.0. """ for key in {address, subnet_mask, next_hop}: if not isinstance(key, IPv4Address): @@ -267,10 +350,10 @@ class RouteTable(SimComponent): """ Find the best route for a given destination IP. - :param destination_ip: The destination IPv4Address to find the route for. - :return: The best matching RouteEntry, or None if no route matches. + This method uses the Longest Prefix Match algorithm and considers metrics to find the best route. - The algorithm uses Longest Prefix Match and considers metrics to find the best route. + :param destination_ip: The destination IP to find the route for. + :return: The best matching RouteEntry, or None if no route matches. """ if not isinstance(destination_ip, IPv4Address): destination_ip = IPv4Address(destination_ip) @@ -290,9 +373,16 @@ class RouteTable(SimComponent): return best_route - def show(self): - """Prints a table of the routes in the RouteTable.""" + def show(self, markdown: bool = False): + """ + Display the current routing table as a table. + + :param markdown: Whether to display the table in Markdown format. Defaults to False. + """ table = PrettyTable(["Index", "Address", "Next Hop", "Metric"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" table.title = f"{self.sys_log.hostname} Route Table" for index, route in enumerate(self.routes): network = IPv4Network(f"{route.address}/{route.subnet_mask}") @@ -301,6 +391,12 @@ class RouteTable(SimComponent): class RouterARPCache(ARPCache): + """ + Inherits from ARPCache and adds router-specific ARP packet processing. + + :ivar SysLog sys_log: A system log for logging messages. + :ivar Router router: The router to which this ARP cache belongs. + """ def __init__(self, sys_log: SysLog, router: Router): super().__init__(sys_log) self.router: Router = router @@ -310,7 +406,7 @@ class RouterARPCache(ARPCache): Overridden method to process a received ARP packet in a router-specific way. :param from_nic: The NIC that received the ARP packet. - :param frame: The original arp frame. + :param frame: The original ARP frame. """ arp_packet = frame.arp @@ -356,6 +452,16 @@ class RouterARPCache(ARPCache): class RouterICMP(ICMP): + """ + A class to represent a router's Internet Control Message Protocol (ICMP) handler. + + :param sys_log: System log for logging network events and errors. + :type sys_log: SysLog + :param arp_cache: The ARP cache for resolving MAC addresses. + :type arp_cache: ARPCache + :param router: The router to which this ICMP handler belongs. + :type router: Router + """ router: Router def __init__(self, sys_log: SysLog, arp_cache: ARPCache, router: Router): @@ -363,6 +469,13 @@ class RouterICMP(ICMP): self.router = router def process_icmp(self, frame: Frame, from_nic: NIC, is_reattempt: bool = False): + """ + Process incoming ICMP frames based on ICMP type. + + :param frame: The incoming frame to process. + :param from_nic: The network interface where the frame is coming from. + :param is_reattempt: Flag to indicate if the process is a reattempt. + """ if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: # determine if request is for router interface or whether it needs to be routed @@ -386,7 +499,10 @@ class RouterICMP(ICMP): identifier=frame.icmp.identifier, sequence=frame.icmp.sequence + 1, ) - frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet) + payload = secrets.token_urlsafe(int(32/1.3)) # Standard ICMP 32 bytes size + frame = Frame( + ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet, payload=payload + ) self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip}") src_nic.send_frame(frame) @@ -399,7 +515,14 @@ class RouterICMP(ICMP): for nic in self.router.nics.values(): if nic.ip_address == frame.ip.dst_ip: if nic.enabled: - self.sys_log.info(f"Received echo reply from {frame.ip.src_ip}") + time = frame.transmission_duration() + time_str = f"{time}ms" if time > 0 else "<1ms" + self.sys_log.info( + f"Reply from {frame.ip.src_ip}: " + f"bytes={len(frame.payload)}, " + f"time={time_str}, " + f"TTL={frame.ip.ttl}" + ) if not self.request_replies.get(frame.icmp.identifier): self.request_replies[frame.icmp.identifier] = 0 self.request_replies[frame.icmp.identifier] += 1 @@ -410,6 +533,13 @@ class RouterICMP(ICMP): class Router(Node): + """ + A class to represent a network router node. + + :ivar str hostname: The name of the router node. + :ivar int num_ports: The number of ports in the router. + :ivar dict kwargs: Optional keyword arguments for SysLog, ACL, RouteTable, RouterARPCache, RouterICMP. + """ num_ports: int ethernet_ports: Dict[int, NIC] = {} acl: AccessControlList @@ -438,14 +568,32 @@ class Router(Node): self.icmp.arp = self.arp def _get_port_of_nic(self, target_nic: NIC) -> Optional[int]: + """ + Retrieve the port number for a given NIC. + + :param target_nic: Target network interface. + :return: The port number if NIC is found, otherwise None. + """ for port, nic in self.ethernet_ports.items(): if nic == target_nic: return port def describe_state(self) -> Dict: + """ + Describes the current state of the Router. + + :return: A dictionary representing the current state. + """ pass def route_frame(self, frame: Frame, from_nic: NIC, re_attempt: bool = False) -> None: + """ + Route a given frame from a source NIC to its destination. + + :param frame: The frame to be routed. + :param from_nic: The source network interface. + :param re_attempt: Flag to indicate if the routing is a reattempt. + """ # Check if src ip is on network of one of the NICs nic = self.arp.get_arp_cache_nic(frame.ip.dst_ip) target_mac = self.arp.get_arp_cache_mac_address(frame.ip.dst_ip) @@ -477,13 +625,10 @@ class Router(Node): def receive_frame(self, frame: Frame, from_nic: NIC): """ - Receive a Frame from the connected NIC and process it. + Receive a frame from a NIC and processes it based on its protocol. - Depending on the protocol, the frame is passed to the appropriate handler such as ARP or ICMP, or up to the - SessionManager if no code manager exists. - - :param frame: The Frame being received. - :param from_nic: The NIC that received the frame. + :param frame: The incoming frame. + :param from_nic: The network interface where the frame is coming from. """ route_frame = False protocol = frame.ip.protocol @@ -520,6 +665,13 @@ class Router(Node): self.route_frame(frame, from_nic) def configure_port(self, port: int, ip_address: Union[IPv4Address, str], subnet_mask: Union[IPv4Address, str]): + """ + Configure the IP settings of a given port. + + :param port: The port to configure. + :param ip_address: The IP address to set. + :param subnet_mask: The subnet mask to set. + """ if not isinstance(ip_address, IPv4Address): ip_address = IPv4Address(ip_address) if not isinstance(subnet_mask, IPv4Address): @@ -530,18 +682,36 @@ class Router(Node): self.sys_log.info(f"Configured port {port} with ip_address={ip_address}/{nic.ip_network.prefixlen}") def enable_port(self, port: int): + """ + Enable a given port on the router. + + :param port: The port to enable. + """ nic = self.ethernet_ports.get(port) if nic: nic.enable() def disable_port(self, port: int): + """ + Disable a given port on the router. + + :param port: The port to disable. + """ nic = self.ethernet_ports.get(port) if nic: nic.disable() - def show(self): + def show(self, markdown: bool = False): + """ + Prints the state of the Ethernet interfaces on the Router. + + :param markdown: Flag to indicate if the output should be in markdown format. + """ """Prints a table of the NICs on the Node.""" table = PrettyTable(["Port", "MAC Address", "Address", "Speed", "Status"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" table.title = f"{self.hostname} Ethernet Interfaces" for port, nic in self.ethernet_ports.items(): table.add_row( diff --git a/src/primaite/simulator/network/hardware/nodes/server.py b/src/primaite/simulator/network/hardware/nodes/server.py new file mode 100644 index 00000000..a3e6f2d7 --- /dev/null +++ b/src/primaite/simulator/network/hardware/nodes/server.py @@ -0,0 +1,37 @@ +from ipaddress import IPv4Address + +from primaite.simulator.network.hardware.base import Node, NIC +from primaite.simulator.network.hardware.nodes.computer import Computer + + +class Server(Computer): + """ + A basic Server class. + + Example: + >>> server_a = Server( + hostname="server_a", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1" + ) + >>> server_a.power_on() + + Instances of Server come 'pre-packaged' with the following: + + * Core Functionality: + * ARP + * ICMP + * Packet Capture + * Sys Log + * Services: + * DNS Client + * FTP Client + * LDAP Client + * NTP Client + * Applications: + * Email Client + * Web Browser + * Processes: + * Placeholder + """ diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 0eccefa4..28e58ca4 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -2,10 +2,80 @@ from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.base import Switch, NIC from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import Router, ACLAction +from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port +def client_server_routed() -> Network: + """ + A basic Client/Server Network routed between subnets. + + +------------+ +------------+ +------------+ +------------+ +------------+ + | | | | | | | | | | + | client_1 +------+ switch_2 +------+ router_1 +------+ switch_1 +------+ server_1 | + | | | | | | | | | | + +------------+ +------------+ +------------+ +------------+ +------------+ + + IP Table: + + """ + network = Network() + + # Router 1 + router_1 = Router(hostname="router_1", num_ports=3) + router_1.power_on() + router_1.configure_port(port=1, ip_address="192.168.1.1", subnet_mask="255.255.255.0") + router_1.configure_port(port=2, ip_address="192.168.2.1", subnet_mask="255.255.255.0") + + # Switch 1 + switch_1 = Switch(hostname="switch_1", num_ports=6) + switch_1.power_on() + network.connect(endpoint_a=router_1.ethernet_ports[1], endpoint_b=switch_1.switch_ports[6]) + router_1.enable_port(1) + + # Switch 2 + switch_2 = Switch(hostname="switch_2", num_ports=6) + switch_2.power_on() + network.connect(endpoint_a=router_1.ethernet_ports[2], endpoint_b=switch_2.switch_ports[6]) + router_1.enable_port(2) + + # Client 1 + client_1 = Computer( + hostname="client_1", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.2.1" + ) + client_1.power_on() + network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) + + # Server 1 + server_1 = Server( + hostname="server_1", + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1" + ) + server_1.power_on() + network.connect(endpoint_b=server_1.ethernet_port[1], endpoint_a=switch_1.switch_ports[1]) + + router_1.acl.add_rule( + action=ACLAction.PERMIT, + src_port=Port.ARP, + dst_port=Port.ARP, + position=22 + ) + + router_1.acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.ICMP, + position=23 + ) + + return network + + def arcd_uc2_network() -> Network: """ Models the ARCD Use Case 2 Network. @@ -40,9 +110,7 @@ def arcd_uc2_network() -> Network: | | +------------+ - Example: - >>> network = arcd_uc2_network() - >>> network.get_node_by_hostname("client_1").ping("192.168.1.10") + """ network = Network() @@ -73,7 +141,7 @@ def arcd_uc2_network() -> Network: default_gateway="192.168.10.1" ) client_1.power_on() - network.connect(endpoint_a=client_1, endpoint_b=switch_2.switch_ports[1]) + network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) # Client 2 client_2 = Computer( @@ -83,60 +151,59 @@ def arcd_uc2_network() -> Network: default_gateway="192.168.10.1" ) client_2.power_on() - network.connect(endpoint_a=client_2, endpoint_b=switch_2.switch_ports[2]) + network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) # Domain Controller - domain_controller = Computer( + domain_controller = Server( hostname="domain_controller", ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" ) domain_controller.power_on() - network.connect(endpoint_a=domain_controller, endpoint_b=switch_1.switch_ports[1]) + network.connect(endpoint_b=domain_controller.ethernet_port[1], endpoint_a=switch_1.switch_ports[1]) # Web Server - web_server = Computer( + web_server = Server( hostname="web_server", ip_address="192.168.1.12", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" ) web_server.power_on() - network.connect(endpoint_a=web_server, endpoint_b=switch_1.switch_ports[2]) + network.connect(endpoint_b=web_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[2]) # Database Server - database_server = Computer( + database_server = Server( hostname="database_server", ip_address="192.168.1.14", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" ) database_server.power_on() - network.connect(endpoint_a=database_server, endpoint_b=switch_1.switch_ports[3]) + network.connect(endpoint_b=database_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[3]) # Backup Server - backup_server = Computer( + backup_server = Server( hostname="backup_server", ip_address="192.168.1.16", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" ) backup_server.power_on() - network.connect(endpoint_a=backup_server, endpoint_b=switch_1.switch_ports[4]) + network.connect(endpoint_b=backup_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[4]) # Security Suite - security_suite = Computer( + security_suite = Server( hostname="security_suite", ip_address="192.168.1.110", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" ) security_suite.power_on() - network.connect(endpoint_a=security_suite, endpoint_b=switch_1.switch_ports[7]) - security_suite_external_nic = NIC(ip_address="192.168.10.110", subnet_mask="255.255.255.0") - security_suite.connect_nic(security_suite_external_nic) - network.connect(endpoint_a=security_suite_external_nic, endpoint_b=switch_2.switch_ports[7]) + network.connect(endpoint_b=security_suite.ethernet_port[1], endpoint_a=switch_1.switch_ports[7]) + security_suite.connect_nic(NIC(ip_address="192.168.10.110", subnet_mask="255.255.255.0")) + network.connect(endpoint_b=security_suite.ethernet_port[2], endpoint_a=switch_2.switch_ports[7]) router_1.acl.add_rule( action=ACLAction.PERMIT, diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index 1b7ccf7d..ddd9fad3 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -124,6 +124,11 @@ class Frame(BaseModel): if not self.received_timestamp: self.received_timestamp = datetime.now() + def transmission_duration(self) -> int: + """The transmission duration in milliseconds.""" + delta = self.received_timestamp - self.sent_timestamp + return int(delta.microseconds / 1000) + @property def size(self) -> float: # noqa - Keep it as MBits as this is how they're expressed """The size of the Frame in Bytes.""" diff --git a/src/primaite/simulator/system/core/sys_log.py b/src/primaite/simulator/system/core/sys_log.py index 4b858c2e..5a7bbbfe 100644 --- a/src/primaite/simulator/system/core/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -1,6 +1,8 @@ import logging from pathlib import Path +from prettytable import PrettyTable, MARKDOWN + from primaite.simulator import TEMP_SIM_OUTPUT @@ -43,7 +45,7 @@ class SysLog: file_handler = logging.FileHandler(filename=log_path) file_handler.setLevel(logging.DEBUG) - log_format = "%(asctime)s %(levelname)s: %(message)s" + log_format = "%(asctime)s::%(levelname)s::%(message)s" file_handler.setFormatter(logging.Formatter(log_format)) self.logger = logging.getLogger(f"{self.hostname}_sys_log") @@ -52,6 +54,19 @@ class SysLog: self.logger.addFilter(_NotJSONFilter()) + def show(self, last_n: int = 10, markdown: bool = False): + table = PrettyTable(["Timestamp", "Level", "Message"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"{self.hostname} Sys Log" + if self._get_log_path().exists(): + with open(self._get_log_path()) as file: + lines = file.readlines() + for line in lines[-last_n:]: + table.add_row(line.strip().split("::")) + print(table) + def _get_log_path(self) -> Path: """ Constructs the path for the log file based on the hostname. From 33b4911cb1d412217ddf8c8fc8b682afaa39c98e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Sep 2023 10:20:06 +0100 Subject: [PATCH 139/980] Move actions to pydantic --- src/primaite/simulator/core.py | 67 ++++++++++++++++------------------ 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 69edd8db..1456d41c 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -1,3 +1,4 @@ +# flake8: noqa """Core of the PrimAITE Simulator.""" from abc import ABC, abstractmethod from typing import Callable, Dict, List, Optional, Union @@ -10,7 +11,7 @@ from primaite import getLogger _LOGGER = getLogger(__name__) -class ActionPermissionValidator(ABC): +class ActionPermissionValidator(BaseModel): """ Base class for action validators. @@ -33,7 +34,7 @@ class AllowAllValidator(ActionPermissionValidator): return True -class Action: +class Action(BaseModel): """ This object stores data related to a single action. @@ -41,34 +42,22 @@ class Action: the action can be performed or not. """ - def __init__( - self, func: Callable[[List[str], Dict], None], validator: ActionPermissionValidator = AllowAllValidator() - ) -> None: - """ - Save the functions that are for this action. - - Here's a description for the intended use of both of these. - - ``func`` is a function that accepts a request and a context dict. Typically this would be a lambda function - that invokes a class method of your SimComponent. For example if the component is a node and the action is for - turning it off, then the SimComponent should have a turn_off(self) method that does not need to accept any args. - Then, this Action will be given something like ``func = lambda request, context: self.turn_off()``. - - ``validator`` is an instance of a subclass of `ActionPermissionValidator`. This is essentially a callable that - accepts `request` and `context` and returns a boolean to represent whether the permission is granted to perform - the action. - - :param func: Function that performs the request. - :type func: Callable[[List[str], Dict], None] - :param validator: Function that checks if the request is authenticated given the context. By default, if no - validator is provided, an 'allow all' validator is added which permits all requests. - :type validator: ActionPermissionValidator - """ - self.func: Callable[[List[str], Dict], None] = func - self.validator: ActionPermissionValidator = validator + func: Callable[[List[str], Dict], None] + """ + ``func`` is a function that accepts a request and a context dict. Typically this would be a lambda function + that invokes a class method of your SimComponent. For example if the component is a node and the action is for + turning it off, then the SimComponent should have a turn_off(self) method that does not need to accept any args. + Then, this Action will be given something like ``func = lambda request, context: self.turn_off()``. + """ + validator: ActionPermissionValidator = AllowAllValidator() + """ + ``validator`` is an instance of `ActionPermissionValidator`. This is essentially a callable that + accepts `request` and `context` and returns a boolean to represent whether the permission is granted to perform + the action. The default validator will allow + """ -class ActionManager: +class ActionManager(BaseModel): """ ActionManager is used by `SimComponent` instances to keep track of actions. @@ -76,9 +65,8 @@ class ActionManager: class is responsible for providing a consistent API for processing actions as well as helpful error messages. """ - def __init__(self) -> None: - """Initialise ActionManager with an empty action lookup.""" - self.actions: Dict[str, Action] = {} + actions: Dict[str, Action] = {} + """maps action verb to an action object.""" def process_request(self, request: List[str], context: Dict) -> None: """Process an action request. @@ -125,6 +113,11 @@ class ActionManager: self.actions[name] = action + def list_actions(self) -> List[List[str]]: + actions = [] + for act_name, act in self.actions.items(): + pass # TODO: + class SimComponent(BaseModel): """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" @@ -178,6 +171,14 @@ class SimComponent(BaseModel): } return state + def possible_actions(self) -> List[List[str]]: + """Enumerate all actions that this component can accept. + + :return: List of all action strings that can be passed to this component. + :rtype: List[Dict[str]] + """ + action_list = ActionManager # TODO: extract possible actions? how to do this neatly? + def apply_action(self, action: List[str], context: Dict = {}) -> None: """ Apply an action to a simulation component. Action data is passed in as a 'namespaced' list of strings. @@ -230,7 +231,3 @@ class SimComponent(BaseModel): _LOGGER.warn(msg) raise RuntimeWarning(msg) self._parent = new_parent - - @parent.deleter - def parent(self) -> None: - self._parent = None From 05959e5408cd6c32b83a5cb407164b7e89ef72ca Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 4 Sep 2023 12:14:24 +0100 Subject: [PATCH 140/980] #1800 - Moved the Switch code to a dedicated switch.py module. - Added more switch tests. - Updated ACL tests to use router acl. - Updated more docs. - Moved the Jupyter notebooks to _package_data and fixed up the setup to move all notebooks to ~/primaite/notebooks/example_notebooks. --- CHANGELOG.md | 10 +- MANIFEST.in | 1 + .../simulation_components/network/network.rst | 3 +- .../simulation_components/network/switch.rst | 8 - src/primaite/notebooks/__init__.py | 34 - src/primaite/setup/reset_demo_notebooks.py | 45 +- .../create-simulation_demo.ipynb} | 0 .../network_simulator_demo.ipynb | 688 ++++++++++++++++++ src/primaite/simulator/network/container.py | 23 +- .../simulator/network/hardware/base.py | 115 +-- .../network/hardware/nodes/computer.py | 2 +- .../network/hardware/nodes/router.py | 101 +-- .../network/hardware/nodes/server.py | 3 - .../network/hardware/nodes/switch.py | 121 +++ src/primaite/simulator/network/networks.py | 67 +- src/primaite/simulator/system/core/sys_log.py | 10 +- .../network/test_frame_transmission.py | 41 +- .../network/test_nic_link_connection.py | 5 +- .../network/test_switched_network.py | 25 + .../nodes/{test_router.py => test_acl.py} | 23 +- 20 files changed, 992 insertions(+), 333 deletions(-) delete mode 100644 docs/source/simulation_components/network/switch.rst delete mode 100644 src/primaite/notebooks/__init__.py rename src/primaite/{notebooks/create-simulation.ipynb => simulator/_package_data/create-simulation_demo.ipynb} (100%) create mode 100644 src/primaite/simulator/_package_data/network_simulator_demo.ipynb create mode 100644 src/primaite/simulator/network/hardware/nodes/switch.py create mode 100644 tests/integration_tests/network/test_switched_network.py rename tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/{test_router.py => test_acl.py} (84%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b495c09..2f2918aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] + + ### Added -- Network Hardware - Added base hardware module with NIC, SwitchPort, Node, Switch, and Link. Nodes and Switches have +- Network Hardware - Added base hardware module with NIC, SwitchPort, Node, and Link. Nodes have fundamental services like ARP, ICMP, and PCAP running them by default. - Network Transmission - Modelled OSI Model layers 1 through to 5 with various classes for creating network frames and transmitting them from a Service/Application, down through the layers, over the wire, and back up through the layers to a Service/Application another machine. +- Introduced `Router` and `Switch` classes to manage networking routes more effectively. + - Added `ACLRule` and `RouteTableEntry` classes as part of the `Router`. +- New `.show()` methods in all network component classes to inspect the state in either plain text or markdown formats. +- Added `Computer` and `Server` class to better differentiate types of network nodes. +- Integrated a new Use Case 2 network into the system. +- New unit tests to verify routing between different subnets using `.ping()`. - system - Added the core structure of Application, Services, and Components. Also added a SoftwareManager and SessionManager. - Permission System - each action can define criteria that will be used to permit or deny agent actions. diff --git a/MANIFEST.in b/MANIFEST.in index 51ae4ddf..2ac7b306 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include src/primaite/setup/_package_data/primaite_config.yaml include src/primaite/config/_package_data/*.yaml +include src/primaite/simulator/_package_data/*.ipynb diff --git a/docs/source/simulation_components/network/network.rst b/docs/source/simulation_components/network/network.rst index e5614980..f4d64b16 100644 --- a/docs/source/simulation_components/network/network.rst +++ b/docs/source/simulation_components/network/network.rst @@ -30,10 +30,11 @@ we'll use the following Network that has a client, server, two switches, and a r .. code-block:: python from primaite.simulator.network.container import Network - from primaite.simulator.network.hardware.base import Switch, NIC + from primaite.simulator.network.hardware.base import NIC from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import Router, ACLAction from primaite.simulator.network.hardware.nodes.server import Server + from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port diff --git a/docs/source/simulation_components/network/switch.rst b/docs/source/simulation_components/network/switch.rst deleted file mode 100644 index 4b3b24bc..00000000 --- a/docs/source/simulation_components/network/switch.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -.. _about: - -Switch -====== \ No newline at end of file diff --git a/src/primaite/notebooks/__init__.py b/src/primaite/notebooks/__init__.py deleted file mode 100644 index bc1dcfcd..00000000 --- a/src/primaite/notebooks/__init__.py +++ /dev/null @@ -1,34 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Contains default jupyter notebooks which demonstrate PrimAITE functionality.""" - -import importlib.util -import os -import subprocess -import sys -from logging import Logger - -from primaite import getLogger, PRIMAITE_PATHS - -_LOGGER: Logger = getLogger(__name__) - - -def start_jupyter_session() -> None: - """ - Starts a new Jupyter notebook session in the app notebooks directory. - - Currently only works on Windows OS. - - .. todo:: Figure out how to get this working for Linux and MacOS too. - """ - if importlib.util.find_spec("jupyter") is not None: - jupyter_cmd = "python3 -m jupyter lab" - if sys.platform == "win32": - jupyter_cmd = "jupyter lab" - - working_dir = os.getcwd() - os.chdir(PRIMAITE_PATHS.user_notebooks_path) - subprocess.Popen(jupyter_cmd) - os.chdir(working_dir) - else: - # Jupyter is not installed - _LOGGER.error("Cannot start jupyter lab as it is not installed") diff --git a/src/primaite/setup/reset_demo_notebooks.py b/src/primaite/setup/reset_demo_notebooks.py index 1f96c90f..a4ee4c4d 100644 --- a/src/primaite/setup/reset_demo_notebooks.py +++ b/src/primaite/setup/reset_demo_notebooks.py @@ -1,35 +1,46 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK import filecmp -import os import shutil from logging import Logger from pathlib import Path -import pkg_resources - from primaite import getLogger, PRIMAITE_PATHS _LOGGER: Logger = getLogger(__name__) +def should_copy_file(src: Path, dest: Path, overwrite_existing: bool) -> bool: + """ + Determine if the file should be copied. + + :param src: The source file Path. + :param dest: The destination file Path. + :param overwrite_existing: A bool to toggle replacing existing edited files on or off. + :return: True if file should be copied, otherwise False. + """ + if not dest.is_file(): + return True + + if overwrite_existing and not filecmp.cmp(src, dest): + return True + + return False + + def run(overwrite_existing: bool = True) -> None: """ - Resets the demo jupyter notebooks in the users app notebooks directory. + Resets the demo Jupyter notebooks in the user's app notebooks directory. :param overwrite_existing: A bool to toggle replacing existing edited notebooks on or off. """ - notebooks_package_data_root = pkg_resources.resource_filename("primaite", "notebooks/_package_data") - for subdir, dirs, files in os.walk(notebooks_package_data_root): - for file in files: - fp = os.path.join(subdir, file) - path_split = os.path.relpath(fp, notebooks_package_data_root).split(os.sep) - target_fp = PRIMAITE_PATHS.user_notebooks_path / Path(*path_split) - target_fp.parent.mkdir(exist_ok=True, parents=True) - copy_file = not target_fp.is_file() + primaite_root = Path(__file__).parent.parent + example_notebooks_user_dir = PRIMAITE_PATHS.user_notebooks_path / "example_notebooks" + example_notebooks_user_dir.mkdir(exist_ok=True, parents=True) - if overwrite_existing and not copy_file: - copy_file = (not filecmp.cmp(fp, target_fp)) and (".ipynb_checkpoints" not in str(target_fp)) + for src_fp in primaite_root.glob("**/*.ipynb"): + dst_fp = example_notebooks_user_dir / src_fp.name - if copy_file: - shutil.copy2(fp, target_fp) - _LOGGER.info(f"Reset example notebook: {target_fp}") + if should_copy_file(src_fp, dst_fp, overwrite_existing): + print(dst_fp) + shutil.copy2(src_fp, dst_fp) + _LOGGER.info(f"Reset example notebook: {dst_fp}") diff --git a/src/primaite/notebooks/create-simulation.ipynb b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb similarity index 100% rename from src/primaite/notebooks/create-simulation.ipynb rename to src/primaite/simulator/_package_data/create-simulation_demo.ipynb diff --git a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb new file mode 100644 index 00000000..252f31fa --- /dev/null +++ b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb @@ -0,0 +1,688 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "03b2013a-b7d1-47ee-b08c-8dab83833720", + "metadata": {}, + "source": [ + "# PrimAITE Router Simulation Demo\n", + "\n", + "This demo uses the ARCD Use Case 2 Network (seen below) to demonstrate the capabilities of the Network simulator in PrimAITE." + ] + }, + { + "cell_type": "raw", + "id": "c8bb5698-e746-4e90-9c2f-efe962acdfa0", + "metadata": {}, + "source": [ + " +------------+\n", + " | domain_ |\n", + " +------------+ controller |\n", + " | | |\n", + " | +------------+\n", + " |\n", + " |\n", + "+------------+ | +------------+\n", + "| | | | |\n", + "| client_1 +---------+ | +---------+ web_server |\n", + "| | | | | | |\n", + "+------------+ | | | +------------+\n", + " +--+---------+ +------------+ +------+--+--+\n", + " | | | | | |\n", + " | switch_2 +------+ router_1 +------+ switch_1 |\n", + " | | | | | |\n", + " +--+------+--+ +------------+ +--+---+--+--+\n", + "+------------+ | | | | | +------------+\n", + "| | | | | | | | database |\n", + "| client_2 +---------+ | | | +---------+ _server |\n", + "| | | | | | |\n", + "+------------+ | | | +------------+\n", + " | +------------+ | |\n", + " | | security | | |\n", + " +---------+ _suite +---------+ | +------------+\n", + " | | | | backup_ |\n", + " +------------+ +------------+ server |\n", + " | |\n", + " +------------+" + ] + }, + { + "cell_type": "markdown", + "id": "415d487c-6457-497d-85d6-99439b3541e7", + "metadata": {}, + "source": [ + "## The Network\n", + "First let's create our network. The network comes 'pre-packaged' with PrimAITE in the `primaite.simulator.network.networks` module.\n", + "\n", + "> ℹ️ You'll see a bunch of logs associated with parts of the Network that aern't an 'electronic' device on the Network and thus don't have a stsrem to log to. Soon these logs are going to be pushed to a Network Logger so we're not clogging up the PrimAITE application logs." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "de57ac8c-5b28-4847-a759-2ceaf5593329", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "from primaite.simulator.network.networks import arcd_uc2_network" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a1e2e4df-67c0-4584-ab27-47e2c7c7fcd2", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network = arcd_uc2_network()" + ] + }, + { + "cell_type": "markdown", + "id": "fb052c56-e9ca-4093-9115-d0c440b5ff53", + "metadata": {}, + "source": [ + "Most of the Network components have a `.show()` function that prints a table of information about that object. We can view the Nodes and Links on the Network by calling `network.show()`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cc199741-ef2e-47f5-b2f0-e20049ccf40f", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.show()" + ] + }, + { + "cell_type": "markdown", + "id": "76d2b7e9-280b-4741-a8b3-a84bed219fac", + "metadata": { + "tags": [] + }, + "source": [ + "## Nodes\n", + "\n", + "Now let's inspect some of the nodes. We can directly access a node on the Network by calling .`get_node_by_hostname`. Like Network, a Node, along with some core services like ARP, have a `.show()` method." + ] + }, + { + "cell_type": "markdown", + "id": "84113002-843e-4cab-b899-667b50f25f6b", + "metadata": {}, + "source": [ + "### Router Nodes\n", + "\n", + "First we'll inspect the Router node and some of it's core services." + ] + }, + { + "cell_type": "markdown", + "id": "bf63a178-eee5-4669-bf64-13aea7ecf6cb", + "metadata": {}, + "source": [ + "Calling `router.show()` displays the Ethernet interfaces on the Router. If you need a table in markdown format, pass `markdown=True`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e76d1854-961e-438c-b40f-77fd9c3abe38", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"router_1\").show()" + ] + }, + { + "cell_type": "markdown", + "id": "e000540c-687c-4254-870c-1d814603bdbf", + "metadata": {}, + "source": [ + "Calling `router.arp.show()` displays the Router ARP Cache." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "92de8b42-92d7-4934-9c12-50bf724c9eb2", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"router_1\").arp.show()" + ] + }, + { + "cell_type": "markdown", + "id": "a9ff7ee8-9482-44de-9039-b684866bdc82", + "metadata": {}, + "source": [ + "Calling `router.acl.show()` displays the Access Control List." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5922282a-d22b-4e55-9176-f3f3654c849f", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"router_1\").acl.show()" + ] + }, + { + "cell_type": "markdown", + "id": "71c87884-f793-4c9f-b004-5b0df86cf585", + "metadata": {}, + "source": [ + "Calling `router.router_table.show()` displays the static routes the Router provides." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "327203be-f475-4727-82a1-e992d3b70ed8", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"router_1\").route_table.show()" + ] + }, + { + "cell_type": "markdown", + "id": "eef561a8-3d39-4c8b-bbc8-e8b10b8ed25f", + "metadata": {}, + "source": [ + "Calling `router.sys_log.show()` displays the Router system log. By default, only the last 10 log entries are displayed, this can be changed by passing `last_n=`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3d0aa004-b10c-445f-aaab-340e0e716c74", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"router_1\").sys_log.show(last_n=10)" + ] + }, + { + "cell_type": "markdown", + "id": "25630c90-c54e-4b5d-8bf4-ad1b0722e126", + "metadata": {}, + "source": [ + "### Switch Nodes\n", + "\n", + "Next we'll inspect the Switch node and some of it's core services." + ] + }, + { + "cell_type": "markdown", + "id": "4879394d-2981-40de-a229-e19b09a34e6e", + "metadata": {}, + "source": [ + "Calling `switch.show()` displays the Switch orts on the Switch." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e7fd439b-5442-4e9d-9e7d-86dacb77f458", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"switch_1\").show()" + ] + }, + { + "cell_type": "markdown", + "id": "beb8dbd6-7250-4ac9-9fa2-d2a9c0e5fd19", + "metadata": { + "tags": [] + }, + "source": [ + "Calling `switch.arp.show()` displays the Switch ARP Cache." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d06e1310-4a77-4315-a59f-cb1b49ca2352", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"switch_1\").arp.show()" + ] + }, + { + "cell_type": "markdown", + "id": "fda75ac3-8123-4234-8f36-86547891d8df", + "metadata": {}, + "source": [ + "Calling `switch.sys_log.show()` displays the Switch system log. By default, only the last 10 log entries are displayed, this can be changed by passing `last_n=`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a0d984b7-a7c1-4bbd-aa5a-9d3caecb08dc", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"switch_1\").sys_log.show()" + ] + }, + { + "cell_type": "markdown", + "id": "2f1d99ad-db4f-4baf-8a35-e1d95f269586", + "metadata": {}, + "source": [ + "### Computer/Server Nodes\n", + "\n", + "Finally, we'll inspect a Computer or Server Node and some of its core services." + ] + }, + { + "cell_type": "markdown", + "id": "c9e2251a-1b47-46e5-840f-7fec3e39c5aa", + "metadata": { + "tags": [] + }, + "source": [ + "Calling `computer.show()` displays the NICs on the Computer/Server." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "656c37f6-b145-42af-9714-8d2886d0eff8", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"security_suite\").show()" + ] + }, + { + "cell_type": "markdown", + "id": "f1097a49-a3da-4d79-a06d-ae8af452918f", + "metadata": {}, + "source": [ + "Calling `computer.arp.show()` displays the Computer/Server ARP Cache." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "66b267d6-2308-486a-b9aa-cb8d3bcf0753", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"security_suite\").arp.show()" + ] + }, + { + "cell_type": "markdown", + "id": "0d1fcad8-5b1a-4d8b-a49f-aa54a95fcaf0", + "metadata": {}, + "source": [ + "Calling `switch.sys_log.show()` displays the Computer/Server system log. By default, only the last 10 log entries are displayed, this can be changed by passing `last_n=`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1b5debe8-ef1b-445d-8fa9-6a45568f21f3", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"security_suite\").sys_log.show()" + ] + }, + { + "cell_type": "markdown", + "id": "fcfa1773-798c-4ada-9318-c3ad928217da", + "metadata": {}, + "source": [ + "## Basic Network Comms Check\n", + "\n", + "We can perform a good old ping to check that Nodes are able to communicate with each other." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "495b7de4-b6ce-41a6-9114-f74752ab4491", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.show(nodes=False, links=False)" + ] + }, + { + "cell_type": "markdown", + "id": "3e13922a-217f-4f4e-99b6-57a07613cade", + "metadata": {}, + "source": [ + "We'll first ping client_1's default gateway." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a38abb71-994e-49e8-8f51-e9a550e95b99", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"client_1\").ping(\"192.168.10.1\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8388e1e9-30e3-4534-8e5a-c6e9144149d2", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"client_1\").sys_log.show(15)" + ] + }, + { + "cell_type": "markdown", + "id": "02c76d5c-d954-49db-912d-cb9c52f46375", + "metadata": {}, + "source": [ + "Next, we'll ping the interface of the 192.168.1.0/24 Network on the Router (port 1)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ff8e976a-c16b-470c-8923-325713a30d6c", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"client_1\").ping(\"192.168.1.1\")" + ] + }, + { + "cell_type": "markdown", + "id": "80280404-a5ab-452f-8a02-771a0d7496b1", + "metadata": {}, + "source": [ + "And finally, we'll ping the web server." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c4163f8d-6a72-410c-9f5c-4f881b7de45e", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"client_1\").ping(\"192.168.1.12\")" + ] + }, + { + "cell_type": "markdown", + "id": "1194c045-ba77-4427-be30-ed7b5b224850", + "metadata": {}, + "source": [ + "To confirm that the ping was received and processed by the web_server, we can view the sys log" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e79a523a-5780-45b6-8798-c434e0e522bd", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"web_server\").sys_log.show()" + ] + }, + { + "cell_type": "markdown", + "id": "5928f6dd-1006-45e3-99f3-8f311a875faa", + "metadata": {}, + "source": [ + "## Advanced Network Usage\n", + "\n", + "We can now use the Network to perform some more advaced things." + ] + }, + { + "cell_type": "markdown", + "id": "5e023ef3-7d18-4006-96ee-042a06a481fc", + "metadata": {}, + "source": [ + "Let's attempt to prevent client_2 from being able to ping the web server. First, we'll confirm that it can ping the server first..." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "603cf913-e261-49da-a7dd-85e1bb6dec56", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"client_2\").ping(\"192.168.1.12\")" + ] + }, + { + "cell_type": "markdown", + "id": "5cf962a4-20e6-44ae-9748-7fc5267ae111", + "metadata": {}, + "source": [ + "If we look at the client_2 sys log we can see that the four ICMP echo requests were sent and four ICMP each replies were received:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e047de00-3de4-4823-b26a-2c8d64c7a663", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"client_2\").sys_log.show()" + ] + }, + { + "cell_type": "markdown", + "id": "bdc4741d-6e3e-4aec-a69c-c2e9653bd02c", + "metadata": {}, + "source": [ + "Now we'll add an ACL to block ICMP from 192.168.10.22" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6db355ae-b99a-441b-a2c4-4ffe78f46bff", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", + "from primaite.simulator.network.transmission.transport_layer import Port\n", + "from primaite.simulator.network.hardware.nodes.router import ACLAction\n", + "network.get_node_by_hostname(\"router_1\").acl.add_rule(\n", + " action=ACLAction.DENY,\n", + " protocol=IPProtocol.ICMP,\n", + " src_ip=\"192.168.10.22\",\n", + " position=1\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a345e000-8842-4827-af96-adc0fbe390fb", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"router_1\").acl.show()" + ] + }, + { + "cell_type": "markdown", + "id": "3a5bfd9f-04cb-493e-a86c-cd268563a262", + "metadata": {}, + "source": [ + "Now we attempt (and fail) to ping the web server" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a4f4ff31-590f-40fb-b13d-efaa8c2720b6", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"client_2\").ping(\"192.168.1.12\")" + ] + }, + { + "cell_type": "markdown", + "id": "83e56497-097b-45cb-964e-b15c72547b38", + "metadata": {}, + "source": [ + "We can check that the ping was actually sent by client_2 by viewing the sys log" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f62b8a4e-fd3b-4059-b108-3d4a0b18f2a0", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"client_2\").sys_log.show()" + ] + }, + { + "cell_type": "markdown", + "id": "c7040311-a879-4620-86a0-55d0774156e5", + "metadata": {}, + "source": [ + "We can check the router sys log to see why the traffic was blocked" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7e53d776-99da-4d2c-a2a7-bd7ce27bff4c", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"router_1\").sys_log.show()" + ] + }, + { + "cell_type": "markdown", + "id": "aba0bc7d-da57-477b-b34a-3688b5aab2c6", + "metadata": {}, + "source": [ + "Now a final check to ensure that client_1 can still ping the web_server." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d542734b-7582-4af7-8254-bda3de50d091", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"client_1\").ping(\"192.168.1.12\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d78e9fe3-02c6-4792-944f-5622e26e0412", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "network.get_node_by_hostname(\"client_1\").sys_log.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.11" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index ccb9ce77..239c98a7 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -1,16 +1,17 @@ -from typing import Any, Dict, Union, Optional, List +from typing import Any, Dict, List, Optional, Union import matplotlib.pyplot as plt import networkx as nx from networkx import MultiGraph -from prettytable import PrettyTable, MARKDOWN +from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent -from primaite.simulator.network.hardware.base import Link, NIC, Node, SwitchPort, Switch +from primaite.simulator.network.hardware.base import Link, NIC, Node, SwitchPort from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import Router from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch _LOGGER = getLogger(__name__) @@ -30,7 +31,7 @@ class Network(SimComponent): links: Dict[str, Link] = {} def __init__(self, **kwargs): - """" + """ Initialise the network. Constructs the network and sets up its initial state including @@ -84,14 +85,14 @@ class Network(SimComponent): "Router": self.routers, "Switch": self.switches, "Server": self.servers, - "Computer": self.computers + "Computer": self.computers, } if nodes: table = PrettyTable(["Node", "Type", "Operating State"]) if markdown: table.set_style(MARKDOWN) table.align = "l" - table.title = f"Nodes" + table.title = "Nodes" for node_type, nodes in nodes_type_map.items(): for node in nodes: table.add_row([node.hostname, node_type, node.operating_state.name]) @@ -102,7 +103,7 @@ class Network(SimComponent): if markdown: table.set_style(MARKDOWN) table.align = "l" - table.title = f"IP Addresses" + table.title = "IP Addresses" for nodes in nodes_type_map.values(): for node in nodes: for i, port in node.ethernet_port.items(): @@ -114,7 +115,7 @@ class Network(SimComponent): if markdown: table.set_style(MARKDOWN) table.align = "l" - table.title = f"Links" + table.title = "Links" links = list(self.links.values()) for nodes in nodes_type_map.values(): for node in nodes: @@ -126,7 +127,7 @@ class Network(SimComponent): link.endpoint_b.parent.hostname, link.is_up, link.bandwidth, - link.current_load_percent + link.current_load_percent, ] ) links.remove(link) @@ -207,9 +208,7 @@ class Network(SimComponent): node.parent = None _LOGGER.info(f"Removed node {node.uuid} from network {self.uuid}") - def connect( - self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs - ) -> None: + def connect(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> None: """ Connect two endpoints on the network by creating a link between their NICs/SwitchPorts. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 674020ee..1193f3ef 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1,13 +1,12 @@ from __future__ import annotations -import random import re import secrets from enum import Enum from ipaddress import IPv4Address, IPv4Network -from typing import Dict, List, Optional, Tuple, Union +from typing import Any, Dict, List, Optional, Tuple, Union -from prettytable import PrettyTable, MARKDOWN +from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.exceptions import NetworkError @@ -289,7 +288,7 @@ class SwitchPort(SimComponent): "The speed of the SwitchPort in Mbps. Default is 100 Mbps." mtu: int = 1500 "The Maximum Transmission Unit (MTU) of the SwitchPort in Bytes. Default is 1500 B" - connected_node: Optional[Switch] = None + connected_node: Optional[Node] = None "The Node to which the SwitchPort is connected." connected_link: Optional[Link] = None "The Link to which the SwitchPort is connected." @@ -715,7 +714,7 @@ class ARPCache: arp_packet = arp_packet.generate_reply(from_nic.mac_address) self.send_arp_reply(arp_packet, from_nic) - def __contains__(self, item) -> bool: + def __contains__(self, item: Any) -> bool: return item in self.arp @@ -765,7 +764,7 @@ class ICMP: identifier=frame.icmp.identifier, sequence=frame.icmp.sequence + 1, ) - payload = secrets.token_urlsafe(int(32/1.3)) # Standard ICMP 32 bytes size + payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size frame = Frame( ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet, payload=payload ) @@ -829,7 +828,7 @@ class ICMP: # Data Link Layer ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) icmp_packet = ICMPPacket(identifier=identifier, sequence=sequence) - payload = secrets.token_urlsafe(int(32/1.3)) # Standard ICMP 32 bytes size + payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_packet, payload=payload) nic.send_frame(frame) return sequence, icmp_packet.identifier @@ -1049,7 +1048,8 @@ class Node(SimComponent): f"Ping statistics for {target_ip_address}: " f"Packets: Sent = {pings}, " f"Received = {request_replies}, " - f"Lost = {pings-request_replies} ({(pings-request_replies)/pings*100}% loss)") + f"Lost = {pings-request_replies} ({(pings-request_replies)/pings*100}% loss)" + ) return passed return False @@ -1084,102 +1084,3 @@ class Node(SimComponent): pass elif frame.ip.protocol == IPProtocol.ICMP: self.icmp.process_icmp(frame=frame, from_nic=from_nic) - - -class Switch(Node): - """A class representing a Layer 2 network switch.""" - - num_ports: int = 24 - "The number of ports on the switch." - switch_ports: Dict[int, SwitchPort] = {} - "The SwitchPorts on the switch." - mac_address_table: Dict[str, SwitchPort] = {} - "A MAC address table mapping destination MAC addresses to corresponding SwitchPorts." - - def __init__(self, **kwargs): - super().__init__(**kwargs) - if not self.switch_ports: - self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)} - for port_num, port in self.switch_ports.items(): - port.connected_node = self - port.parent = self - port.port_num = port_num - - def show(self, markdown: bool = False): - """Prints a table of the SwitchPorts on the Switch.""" - table = PrettyTable(["Port", "MAC Address", "Speed", "Status"]) - if markdown: - table.set_style(MARKDOWN) - table.align = "l" - table.title = f"{self.hostname} Switch Ports" - for port_num, port in self.switch_ports.items(): - table.add_row([port_num, port.mac_address, port.speed, "Enabled" if port.enabled else "Disabled"]) - print(table) - - def describe_state(self) -> Dict: - """ - Produce a dictionary describing the current state of this object. - - Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - - :return: Current state of this object and child objects. - :rtype: Dict - """ - return { - "uuid": self.uuid, - "num_ports": self.num_ports, # redundant? - "ports": {port_num: port.describe_state() for port_num, port in self.switch_ports.items()}, - "mac_address_table": {mac: port for mac, port in self.mac_address_table.items()}, - } - - def _add_mac_table_entry(self, mac_address: str, switch_port: SwitchPort): - mac_table_port = self.mac_address_table.get(mac_address) - if not mac_table_port: - self.mac_address_table[mac_address] = switch_port - self.sys_log.info(f"Added MAC table entry: Port {switch_port.port_num} -> {mac_address}") - else: - if mac_table_port != switch_port: - self.mac_address_table.pop(mac_address) - self.sys_log.info(f"Removed MAC table entry: Port {mac_table_port.port_num} -> {mac_address}") - self._add_mac_table_entry(mac_address, switch_port) - - def forward_frame(self, frame: Frame, incoming_port: SwitchPort): - """ - Forward a frame to the appropriate port based on the destination MAC address. - - :param frame: The Frame to be forwarded. - :param incoming_port: The port number from which the frame was received. - """ - src_mac = frame.ethernet.src_mac_addr - dst_mac = frame.ethernet.dst_mac_addr - self._add_mac_table_entry(src_mac, incoming_port) - - outgoing_port = self.mac_address_table.get(dst_mac) - if outgoing_port or dst_mac != "ff:ff:ff:ff:ff:ff": - outgoing_port.send_frame(frame) - else: - # If the destination MAC is not in the table, flood to all ports except incoming - for port in self.switch_ports.values(): - if port != incoming_port: - port.send_frame(frame) - - def disconnect_link_from_port(self, link: Link, port_number: int): - """ - Disconnect a given link from the specified port number on the switch. - - :param link: The Link object to be disconnected. - :param port_number: The port number on the switch from where the link should be disconnected. - :raise NetworkError: When an invalid port number is provided or the link does not match the connection. - """ - port = self.switch_ports.get(port_number) - if port is None: - msg = f"Invalid port number {port_number} on the switch" - _LOGGER.error(msg) - raise NetworkError(msg) - - if port.connected_link != link: - msg = f"The link does not match the connection at port number {port_number}" - _LOGGER.error(msg) - raise NetworkError(msg) - - port.disconnect_link() diff --git a/src/primaite/simulator/network/hardware/nodes/computer.py b/src/primaite/simulator/network/hardware/nodes/computer.py index 110ad385..2a2e8524 100644 --- a/src/primaite/simulator/network/hardware/nodes/computer.py +++ b/src/primaite/simulator/network/hardware/nodes/computer.py @@ -1,6 +1,6 @@ from ipaddress import IPv4Address -from primaite.simulator.network.hardware.base import Node, NIC +from primaite.simulator.network.hardware.base import NIC, Node class Computer(Node): diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index b507143b..26ba01ae 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -5,7 +5,7 @@ from enum import Enum from ipaddress import IPv4Address, IPv4Network from typing import Dict, List, Optional, Tuple, Union -from prettytable import PrettyTable, MARKDOWN +from prettytable import MARKDOWN, PrettyTable from primaite.simulator.core import SimComponent from primaite.simulator.network.hardware.base import ARPCache, ICMP, NIC, Node @@ -71,6 +71,7 @@ class AccessControlList(SimComponent): :ivar int max_acl_rules: Maximum number of ACL rules that can be added. Default is 25. :ivar List[Optional[ACLRule]] _acl: A list containing the ACL rules. """ + sys_log: SysLog implicit_action: ACLAction implicit_rule: ACLRule @@ -105,14 +106,14 @@ class AccessControlList(SimComponent): return self._acl def add_rule( - self, - action: ACLAction, - protocol: Optional[IPProtocol] = None, - src_ip: Optional[Union[str, IPv4Address]] = None, - src_port: Optional[Port] = None, - dst_ip: Optional[Union[str, IPv4Address]] = None, - dst_port: Optional[Port] = None, - position: int = 0, + self, + action: ACLAction, + protocol: Optional[IPProtocol] = None, + src_ip: Optional[Union[str, IPv4Address]] = None, + src_port: Optional[Port] = None, + dst_ip: Optional[Union[str, IPv4Address]] = None, + dst_port: Optional[Port] = None, + position: int = 0, ) -> None: """ Add a new ACL rule. @@ -150,12 +151,12 @@ class AccessControlList(SimComponent): raise ValueError(f"Position {position} is out of bounds.") def is_permitted( - self, - protocol: IPProtocol, - src_ip: Union[str, IPv4Address], - src_port: Optional[Port], - dst_ip: Union[str, IPv4Address], - dst_port: Optional[Port], + self, + protocol: IPProtocol, + src_ip: Union[str, IPv4Address], + src_port: Optional[Port], + dst_ip: Union[str, IPv4Address], + dst_port: Optional[Port], ) -> Tuple[bool, Optional[Union[str, ACLRule]]]: """ Check if a packet with the given properties is permitted through the ACL. @@ -177,23 +178,23 @@ class AccessControlList(SimComponent): continue if ( - (rule.src_ip == src_ip or rule.src_ip is None) - and (rule.dst_ip == dst_ip or rule.dst_ip is None) - and (rule.protocol == protocol or rule.protocol is None) - and (rule.src_port == src_port or rule.src_port is None) - and (rule.dst_port == dst_port or rule.dst_port is None) + (rule.src_ip == src_ip or rule.src_ip is None) + and (rule.dst_ip == dst_ip or rule.dst_ip is None) + and (rule.protocol == protocol or rule.protocol is None) + and (rule.src_port == src_port or rule.src_port is None) + and (rule.dst_port == dst_port or rule.dst_port is None) ): return rule.action == ACLAction.PERMIT, rule return self.implicit_action == ACLAction.PERMIT, f"Implicit {self.implicit_action.name}" def get_relevant_rules( - self, - protocol: IPProtocol, - src_ip: Union[str, IPv4Address], - src_port: Port, - dst_ip: Union[str, IPv4Address], - dst_port: Port, + self, + protocol: IPProtocol, + src_ip: Union[str, IPv4Address], + src_port: Port, + dst_ip: Union[str, IPv4Address], + dst_port: Port, ) -> List[ACLRule]: """ Get the list of relevant rules for a packet with given properties. @@ -215,11 +216,11 @@ class AccessControlList(SimComponent): continue if ( - (rule.src_ip == src_ip or rule.src_ip is None) - or (rule.dst_ip == dst_ip or rule.dst_ip is None) - or (rule.protocol == protocol or rule.protocol is None) - or (rule.src_port == src_port or rule.src_port is None) - or (rule.dst_port == dst_port or rule.dst_port is None) + (rule.src_ip == src_ip or rule.src_ip is None) + or (rule.dst_ip == dst_ip or rule.dst_ip is None) + or (rule.protocol == protocol or rule.protocol is None) + or (rule.src_port == src_port or rule.src_port is None) + or (rule.dst_port == dst_port or rule.dst_port is None) ): relevant_rules.append(rule) @@ -326,11 +327,11 @@ class RouteTable(SimComponent): pass def add_route( - self, - address: Union[IPv4Address, str], - subnet_mask: Union[IPv4Address, str], - next_hop: Union[IPv4Address, str], - metric: float = 0.0, + self, + address: Union[IPv4Address, str], + subnet_mask: Union[IPv4Address, str], + next_hop: Union[IPv4Address, str], + metric: float = 0.0, ): """ Add a route to the routing table. @@ -397,6 +398,7 @@ class RouterARPCache(ARPCache): :ivar SysLog sys_log: A system log for logging messages. :ivar Router router: The router to which this ARP cache belongs. """ + def __init__(self, sys_log: SysLog, router: Router): super().__init__(sys_log) self.router: Router = router @@ -416,7 +418,8 @@ class RouterARPCache(ARPCache): if arp_packet.target_ip == nic.ip_address: # reply to the Router specifically self.sys_log.info( - f"Received ARP response for {arp_packet.sender_ip} from {arp_packet.sender_mac_addr} via NIC {from_nic}" + f"Received ARP response for {arp_packet.sender_ip} " + f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" ) self.add_arp_cache_entry( ip_address=arp_packet.sender_ip, @@ -462,6 +465,7 @@ class RouterICMP(ICMP): :param router: The router to which this ICMP handler belongs. :type router: Router """ + router: Router def __init__(self, sys_log: SysLog, arp_cache: ARPCache, router: Router): @@ -492,16 +496,22 @@ class RouterICMP(ICMP): # Network Layer ip_packet = IPPacket(src_ip=nic.ip_address, dst_ip=frame.ip.src_ip, protocol=IPProtocol.ICMP) # Data Link Layer - ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) + ethernet_header = EthernetHeader( + src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address + ) icmp_reply_packet = ICMPPacket( icmp_type=ICMPType.ECHO_REPLY, icmp_code=0, identifier=frame.icmp.identifier, sequence=frame.icmp.sequence + 1, ) - payload = secrets.token_urlsafe(int(32/1.3)) # Standard ICMP 32 bytes size + payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size frame = Frame( - ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet, payload=payload + ethernet=ethernet_header, + ip=ip_packet, + tcp=tcp_header, + icmp=icmp_reply_packet, + payload=payload, ) self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip}") @@ -540,6 +550,7 @@ class Router(Node): :ivar int num_ports: The number of ports in the router. :ivar dict kwargs: Optional keyword arguments for SysLog, ACL, RouteTable, RouterARPCache, RouterICMP. """ + num_ports: int ethernet_ports: Dict[int, NIC] = {} acl: AccessControlList @@ -588,12 +599,12 @@ class Router(Node): def route_frame(self, frame: Frame, from_nic: NIC, re_attempt: bool = False) -> None: """ - Route a given frame from a source NIC to its destination. + Route a given frame from a source NIC to its destination. - :param frame: The frame to be routed. - :param from_nic: The source network interface. - :param re_attempt: Flag to indicate if the routing is a reattempt. - """ + :param frame: The frame to be routed. + :param from_nic: The source network interface. + :param re_attempt: Flag to indicate if the routing is a reattempt. + """ # Check if src ip is on network of one of the NICs nic = self.arp.get_arp_cache_nic(frame.ip.dst_ip) target_mac = self.arp.get_arp_cache_mac_address(frame.ip.dst_ip) diff --git a/src/primaite/simulator/network/hardware/nodes/server.py b/src/primaite/simulator/network/hardware/nodes/server.py index a3e6f2d7..b72cc71c 100644 --- a/src/primaite/simulator/network/hardware/nodes/server.py +++ b/src/primaite/simulator/network/hardware/nodes/server.py @@ -1,6 +1,3 @@ -from ipaddress import IPv4Address - -from primaite.simulator.network.hardware.base import Node, NIC from primaite.simulator.network.hardware.nodes.computer import Computer diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/switch.py new file mode 100644 index 00000000..b7cc1242 --- /dev/null +++ b/src/primaite/simulator/network/hardware/nodes/switch.py @@ -0,0 +1,121 @@ +from typing import Dict + +from prettytable import MARKDOWN, PrettyTable + +from primaite import getLogger +from primaite.exceptions import NetworkError +from primaite.links.link import Link +from primaite.simulator.network.hardware.base import Node, SwitchPort +from primaite.simulator.network.transmission.data_link_layer import Frame + +_LOGGER = getLogger(__name__) + + +class Switch(Node): + """ + A class representing a Layer 2 network switch. + + :ivar num_ports: The number of ports on the switch. Default is 24. + """ + + num_ports: int = 24 + "The number of ports on the switch." + switch_ports: Dict[int, SwitchPort] = {} + "The SwitchPorts on the switch." + mac_address_table: Dict[str, SwitchPort] = {} + "A MAC address table mapping destination MAC addresses to corresponding SwitchPorts." + + def __init__(self, **kwargs): + super().__init__(**kwargs) + if not self.switch_ports: + self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)} + for port_num, port in self.switch_ports.items(): + port.connected_node = self + port.parent = self + port.port_num = port_num + + def show(self, markdown: bool = False): + """ + Prints a table of the SwitchPorts on the Switch. + + :param markdown: If True, outputs the table in markdown format. Default is False. + """ + table = PrettyTable(["Port", "MAC Address", "Speed", "Status"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"{self.hostname} Switch Ports" + for port_num, port in self.switch_ports.items(): + table.add_row([port_num, port.mac_address, port.speed, "Enabled" if port.enabled else "Disabled"]) + print(table) + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + """ + return { + "uuid": self.uuid, + "num_ports": self.num_ports, # redundant? + "ports": {port_num: port.describe_state() for port_num, port in self.switch_ports.items()}, + "mac_address_table": {mac: port for mac, port in self.mac_address_table.items()}, + } + + def _add_mac_table_entry(self, mac_address: str, switch_port: SwitchPort): + """ + Private method to add an entry to the MAC address table. + + :param mac_address: MAC address to be added. + :param switch_port: Corresponding SwitchPort object. + """ + mac_table_port = self.mac_address_table.get(mac_address) + if not mac_table_port: + self.mac_address_table[mac_address] = switch_port + self.sys_log.info(f"Added MAC table entry: Port {switch_port.port_num} -> {mac_address}") + else: + if mac_table_port != switch_port: + self.mac_address_table.pop(mac_address) + self.sys_log.info(f"Removed MAC table entry: Port {mac_table_port.port_num} -> {mac_address}") + self._add_mac_table_entry(mac_address, switch_port) + + def forward_frame(self, frame: Frame, incoming_port: SwitchPort): + """ + Forward a frame to the appropriate port based on the destination MAC address. + + :param frame: The Frame to be forwarded. + :param incoming_port: The port number from which the frame was received. + """ + src_mac = frame.ethernet.src_mac_addr + dst_mac = frame.ethernet.dst_mac_addr + self._add_mac_table_entry(src_mac, incoming_port) + + outgoing_port = self.mac_address_table.get(dst_mac) + if outgoing_port or dst_mac != "ff:ff:ff:ff:ff:ff": + outgoing_port.send_frame(frame) + else: + # If the destination MAC is not in the table, flood to all ports except incoming + for port in self.switch_ports.values(): + if port != incoming_port: + port.send_frame(frame) + + def disconnect_link_from_port(self, link: Link, port_number: int): + """ + Disconnect a given link from the specified port number on the switch. + + :param link: The Link object to be disconnected. + :param port_number: The port number on the switch from where the link should be disconnected. + :raise NetworkError: When an invalid port number is provided or the link does not match the connection. + """ + port = self.switch_ports.get(port_number) + if port is None: + msg = f"Invalid port number {port_number} on the switch" + _LOGGER.error(msg) + raise NetworkError(msg) + + if port.connected_link != link: + msg = f"The link does not match the connection at port number {port_number}" + _LOGGER.error(msg) + raise NetworkError(msg) + + port.disconnect_link() diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 28e58ca4..6a50fe3f 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -1,8 +1,9 @@ from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.base import Switch, NIC +from primaite.simulator.network.hardware.base import NIC from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.router import Router, ACLAction +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -42,36 +43,21 @@ def client_server_routed() -> Network: # Client 1 client_1 = Computer( - hostname="client_1", - ip_address="192.168.2.2", - subnet_mask="255.255.255.0", - default_gateway="192.168.2.1" + hostname="client_1", ip_address="192.168.2.2", subnet_mask="255.255.255.0", default_gateway="192.168.2.1" ) client_1.power_on() network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) # Server 1 server_1 = Server( - hostname="server_1", - ip_address="192.168.1.2", - subnet_mask="255.255.255.0", - default_gateway="192.168.1.1" + hostname="server_1", ip_address="192.168.1.2", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" ) server_1.power_on() network.connect(endpoint_b=server_1.ethernet_port[1], endpoint_a=switch_1.switch_ports[1]) - router_1.acl.add_rule( - action=ACLAction.PERMIT, - src_port=Port.ARP, - dst_port=Port.ARP, - position=22 - ) + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) - router_1.acl.add_rule( - action=ACLAction.PERMIT, - protocol=IPProtocol.ICMP, - position=23 - ) + router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) return network @@ -135,20 +121,14 @@ def arcd_uc2_network() -> Network: # Client 1 client_1 = Computer( - hostname="client_1", - ip_address="192.168.10.21", - subnet_mask="255.255.255.0", - default_gateway="192.168.10.1" + hostname="client_1", ip_address="192.168.10.21", subnet_mask="255.255.255.0", default_gateway="192.168.10.1" ) client_1.power_on() network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) # Client 2 client_2 = Computer( - hostname="client_2", - ip_address="192.168.10.22", - subnet_mask="255.255.255.0", - default_gateway="192.168.10.1" + hostname="client_2", ip_address="192.168.10.22", subnet_mask="255.255.255.0", default_gateway="192.168.10.1" ) client_2.power_on() network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) @@ -158,17 +138,14 @@ def arcd_uc2_network() -> Network: hostname="domain_controller", ip_address="192.168.1.10", subnet_mask="255.255.255.0", - default_gateway="192.168.1.1" + default_gateway="192.168.1.1", ) domain_controller.power_on() network.connect(endpoint_b=domain_controller.ethernet_port[1], endpoint_a=switch_1.switch_ports[1]) # Web Server web_server = Server( - hostname="web_server", - ip_address="192.168.1.12", - subnet_mask="255.255.255.0", - default_gateway="192.168.1.1" + hostname="web_server", ip_address="192.168.1.12", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" ) web_server.power_on() network.connect(endpoint_b=web_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[2]) @@ -178,17 +155,14 @@ def arcd_uc2_network() -> Network: hostname="database_server", ip_address="192.168.1.14", subnet_mask="255.255.255.0", - default_gateway="192.168.1.1" + default_gateway="192.168.1.1", ) database_server.power_on() network.connect(endpoint_b=database_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[3]) # Backup Server backup_server = Server( - hostname="backup_server", - ip_address="192.168.1.16", - subnet_mask="255.255.255.0", - default_gateway="192.168.1.1" + hostname="backup_server", ip_address="192.168.1.16", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" ) backup_server.power_on() network.connect(endpoint_b=backup_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[4]) @@ -198,24 +172,15 @@ def arcd_uc2_network() -> Network: hostname="security_suite", ip_address="192.168.1.110", subnet_mask="255.255.255.0", - default_gateway="192.168.1.1" + default_gateway="192.168.1.1", ) security_suite.power_on() network.connect(endpoint_b=security_suite.ethernet_port[1], endpoint_a=switch_1.switch_ports[7]) security_suite.connect_nic(NIC(ip_address="192.168.10.110", subnet_mask="255.255.255.0")) network.connect(endpoint_b=security_suite.ethernet_port[2], endpoint_a=switch_2.switch_ports[7]) - router_1.acl.add_rule( - action=ACLAction.PERMIT, - src_port=Port.ARP, - dst_port=Port.ARP, - position=22 - ) + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) - router_1.acl.add_rule( - action=ACLAction.PERMIT, - protocol=IPProtocol.ICMP, - position=23 - ) + router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) return network diff --git a/src/primaite/simulator/system/core/sys_log.py b/src/primaite/simulator/system/core/sys_log.py index 5a7bbbfe..e07c28aa 100644 --- a/src/primaite/simulator/system/core/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -1,7 +1,7 @@ import logging from pathlib import Path -from prettytable import PrettyTable, MARKDOWN +from prettytable import MARKDOWN, PrettyTable from primaite.simulator import TEMP_SIM_OUTPUT @@ -55,6 +55,14 @@ class SysLog: self.logger.addFilter(_NotJSONFilter()) def show(self, last_n: int = 10, markdown: bool = False): + """ + Print the Node Sys Log as a table. + + Generate and print PrettyTable instance that shows the Nodes Sys Log, with columns Timestamp, Level, + and Massage. + + :param markdown: Use Markdown style in table output. Defaults to False. + """ table = PrettyTable(["Timestamp", "Level", "Message"]) if markdown: table.set_style(MARKDOWN) diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index 34b76060..85717b25 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -1,4 +1,4 @@ -from primaite.simulator.network.hardware.base import Link, NIC, Node, Switch +from primaite.simulator.network.hardware.base import Link, NIC, Node def test_node_to_node_ping(): @@ -20,7 +20,6 @@ def test_node_to_node_ping(): def test_multi_nic(): """Tests that Nodes with multiple NICs can ping each other and the data go across the correct links.""" - # TODO Add actual checks. Manual check performed for now. node_a = Node(hostname="node_a") nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") node_a.connect_nic(nic_a) @@ -45,41 +44,3 @@ def test_multi_nic(): node_a.ping("192.168.0.11") assert node_c.ping("10.0.0.12") - - -def test_switched_network(): - """Tests a larges network of Nodes and Switches with one node pinging another.""" - # TODO Add actual checks. Manual check performed for now. - pc_a = Node(hostname="pc_a") - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") - pc_a.connect_nic(nic_a) - pc_a.power_on() - - pc_b = Node(hostname="pc_b") - nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") - pc_b.connect_nic(nic_b) - pc_b.power_on() - - pc_c = Node(hostname="pc_c") - nic_c = NIC(ip_address="192.168.0.12", subnet_mask="255.255.255.0") - pc_c.connect_nic(nic_c) - pc_c.power_on() - - pc_d = Node(hostname="pc_d") - nic_d = NIC(ip_address="192.168.0.13", subnet_mask="255.255.255.0") - pc_d.connect_nic(nic_d) - pc_d.power_on() - - switch_1 = Switch(hostname="switch_1", num_ports=6) - switch_1.power_on() - - switch_2 = Switch(hostname="switch_2", num_ports=6) - switch_2.power_on() - - link_nic_a_switch_1 = Link(endpoint_a=nic_a, endpoint_b=switch_1.switch_ports[1]) - link_nic_b_switch_1 = Link(endpoint_a=nic_b, endpoint_b=switch_1.switch_ports[2]) - link_nic_c_switch_2 = Link(endpoint_a=nic_c, endpoint_b=switch_2.switch_ports[1]) - link_nic_d_switch_2 = Link(endpoint_a=nic_d, endpoint_b=switch_2.switch_ports[2]) - link_switch_1_switch_2 = Link(endpoint_a=switch_1.switch_ports[6], endpoint_b=switch_2.switch_ports[6]) - - assert pc_a.ping("192.168.0.13") diff --git a/tests/integration_tests/network/test_nic_link_connection.py b/tests/integration_tests/network/test_nic_link_connection.py index f051d026..228099c6 100644 --- a/tests/integration_tests/network/test_nic_link_connection.py +++ b/tests/integration_tests/network/test_nic_link_connection.py @@ -6,8 +6,5 @@ from primaite.simulator.network.hardware.base import Link, NIC def test_link_fails_with_same_nic(): """Tests Link creation fails with endpoint_a and endpoint_b are the same NIC.""" with pytest.raises(ValueError): - nic_a = NIC( - ip_address="192.168.1.2", - subnet_mask="255.255.255.0" - ) + nic_a = NIC(ip_address="192.168.1.2", subnet_mask="255.255.255.0") Link(endpoint_a=nic_a, endpoint_b=nic_a) diff --git a/tests/integration_tests/network/test_switched_network.py b/tests/integration_tests/network/test_switched_network.py new file mode 100644 index 00000000..dc7742f4 --- /dev/null +++ b/tests/integration_tests/network/test_switched_network.py @@ -0,0 +1,25 @@ +from primaite.simulator.network.hardware.base import Link +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch + + +def test_switched_network(): + """Tests a node can ping another node via the switch.""" + client_1 = Computer( + hostname="client_1", ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.0" + ) + client_1.power_on() + + server_1 = Server( + hostname=" server_1", ip_address="192.168.1.11", subnet_mask="255.255.255.0", default_gateway="192.168.1.11" + ) + server_1.power_on() + + switch_1 = Switch(hostname="switch_1", num_ports=6) + switch_1.power_on() + + Link(endpoint_a=client_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[1]) + Link(endpoint_a=server_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[2]) + + assert client_1.ping("192.168.1.11") diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py similarity index 84% rename from tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py rename to tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py index 48d0fc06..99736421 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py @@ -1,12 +1,13 @@ from ipaddress import IPv4Address -from primaite.simulator.network.hardware.nodes.router import AccessControlList, ACLAction, ACLRule +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port def test_add_rule(): - acl = AccessControlList() + router = Router("Router") + acl = router.acl acl.add_rule( action=ACLAction.PERMIT, protocol=IPProtocol.TCP, @@ -25,7 +26,8 @@ def test_add_rule(): def test_remove_rule(): - acl = AccessControlList() + router = Router("Router") + acl = router.acl acl.add_rule( action=ACLAction.PERMIT, protocol=IPProtocol.TCP, @@ -40,7 +42,8 @@ def test_remove_rule(): def test_rules(): - acl = AccessControlList() + router = Router("Router") + acl = router.acl acl.add_rule( action=ACLAction.PERMIT, protocol=IPProtocol.TCP, @@ -59,24 +62,27 @@ def test_rules(): dst_port=Port(80), position=2, ) - assert acl.is_permitted( + is_permitted, rule = acl.is_permitted( protocol=IPProtocol.TCP, src_ip=IPv4Address("192.168.1.1"), src_port=Port(8080), dst_ip=IPv4Address("192.168.1.2"), dst_port=Port(80), ) - assert not acl.is_permitted( + assert is_permitted + is_permitted, rule = acl.is_permitted( protocol=IPProtocol.TCP, src_ip=IPv4Address("192.168.1.3"), src_port=Port(8080), dst_ip=IPv4Address("192.168.1.4"), dst_port=Port(80), ) + assert not is_permitted def test_default_rule(): - acl = AccessControlList() + router = Router("Router") + acl = router.acl acl.add_rule( action=ACLAction.PERMIT, protocol=IPProtocol.TCP, @@ -95,10 +101,11 @@ def test_default_rule(): dst_port=Port(80), position=2, ) - assert not acl.is_permitted( + is_permitted, rule = acl.is_permitted( protocol=IPProtocol.UDP, src_ip=IPv4Address("192.168.1.5"), src_port=Port(8080), dst_ip=IPv4Address("192.168.1.12"), dst_port=Port(80), ) + assert not is_permitted From d9feb67e02553e703b6a278b2aadde1104352eb5 Mon Sep 17 00:00:00 2001 From: Christopher McCarthy Date: Mon, 4 Sep 2023 11:20:40 +0000 Subject: [PATCH 141/980] Apply suggestions from code review --- src/primaite/simulator/network/hardware/nodes/router.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 26ba01ae..fa1a0858 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -81,12 +81,11 @@ class AccessControlList(SimComponent): def __init__(self, **kwargs) -> None: if not kwargs.get("implicit_action"): kwargs["implicit_action"] = ACLAction.DENY - if not kwargs.get("max_acl_rules"): - kwargs["max_acl_rules"] = 25 + kwargs["implicit_rule"] = ACLRule(action=kwargs["implicit_action"]) - kwargs["_acl"] = [None] * (kwargs["max_acl_rules"] - 1) super().__init__(**kwargs) + self._acl = [None] * (self.max_acl_rules - 1) def describe_state(self) -> Dict: """ @@ -145,7 +144,7 @@ class AccessControlList(SimComponent): :param int position: The position of the rule to be removed. :raises ValueError: When the position is out of bounds. """ - if 0 <= position < self.max_acl_rules: + if 0 <= position < self.max_acl_rules - 1: self._acl[position] = None else: raise ValueError(f"Position {position} is out of bounds.") From 3075d1985b20463e7deddcb02462c5f113aef4ff Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 4 Sep 2023 14:58:34 +0100 Subject: [PATCH 142/980] #1800 - Renamed all ip fields so that they're post-fixed with ip_address --- .../network/transport_to_data_link_layer.rst | 12 +- .../network_simulator_demo.ipynb | 2 +- src/primaite/simulator/core.py | 2 +- .../simulator/network/hardware/base.py | 56 +++---- .../network/hardware/nodes/computer.py | 4 - .../network/hardware/nodes/router.py | 140 +++++++++--------- .../simulator/network/protocols/arp.py | 20 +-- .../network/transmission/data_link_layer.py | 4 +- .../network/transmission/network_layer.py | 20 +-- .../simulator/system/core/session_manager.py | 18 +-- .../_network/_hardware/nodes/test_acl.py | 40 ++--- .../_transmission/test_data_link_layer.py | 14 +- 12 files changed, 166 insertions(+), 166 deletions(-) diff --git a/docs/source/simulation_components/network/transport_to_data_link_layer.rst b/docs/source/simulation_components/network/transport_to_data_link_layer.rst index 4961d337..0220ec45 100644 --- a/docs/source/simulation_components/network/transport_to_data_link_layer.rst +++ b/docs/source/simulation_components/network/transport_to_data_link_layer.rst @@ -64,9 +64,9 @@ Data Link Layer (Layer 2) - **request:** ARP operation. Set to True for a request and False for a reply. - **sender_mac_addr:** Sender's MAC address. - - **sender_ip:** Sender's IP address (IPv4 format). + - **sender_ip_address:** Sender's IP address (IPv4 format). - **target_mac_addr:** Target's MAC address. - - **target_ip:** Target's IP address (IPv4 format). + - **target_ip_address:** Target's IP address (IPv4 format). **EthernetHeader:** Represents the Ethernet layer of a network frame. It includes source and destination MAC addresses. This header is used to identify the physical hardware addresses of devices on a local network. @@ -102,8 +102,8 @@ address of 'aa:bb:cc:dd:ee:ff' to port 8080 on the host 10.0.0.10 which has a NI # Network Layer ip_packet = IPPacket( - src_ip="192.168.0.100", - dst_ip="10.0.0.10", + src_ip_address="192.168.0.100", + dst_ip_address="10.0.0.10", protocol=IPProtocol.TCP ) # Data Link Layer @@ -128,8 +128,8 @@ This produces the following ``Frame`` (displayed in json format) "dst_mac_addr": "11:22:33:44:55:66" }, "ip": { - "src_ip": "192.168.0.100", - "dst_ip": "10.0.0.10", + "src_ip_address": "192.168.0.100", + "dst_ip_address": "10.0.0.10", "protocol": "tcp", "ttl": 64, "precedence": 0 diff --git a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb index 252f31fa..b537f54b 100644 --- a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb +++ b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb @@ -554,7 +554,7 @@ "network.get_node_by_hostname(\"router_1\").acl.add_rule(\n", " action=ACLAction.DENY,\n", " protocol=IPProtocol.ICMP,\n", - " src_ip=\"192.168.10.22\",\n", + " src_ip_address=\"192.168.10.22\",\n", " position=1\n", ")" ] diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index b7dfcf72..3e68ed5f 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from typing import Callable, Dict, List, Optional, Union from uuid import uuid4 -from pydantic import BaseModel, ConfigDict, Extra +from pydantic import BaseModel, ConfigDict, Extra, validator from primaite import getLogger diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 1193f3ef..a170506b 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -579,9 +579,13 @@ class ARPCache: """ Add an ARP entry to the cache. + If an entry for the given IP address already exists, the entry is only updated if the `override` parameter is + set to True. + :param ip_address: The IP address to be added to the cache. :param mac_address: The MAC address associated with the IP address. :param nic: The NIC through which the NIC with the IP address is reachable. + :param override: If True, an existing entry for the IP address will be overridden. Default is False. """ for _nic in self.nics.values(): if _nic.ip_address == ip_address: @@ -644,13 +648,13 @@ class ARPCache: # Network Layer ip_packet = IPPacket( - src_ip=nic.ip_address, - dst_ip=target_ip_address, + src_ip_address=nic.ip_address, + dst_ip_address=target_ip_address, ) # Data Link Layer ethernet_header = EthernetHeader(src_mac_addr=nic.mac_address, dst_mac_addr="ff:ff:ff:ff:ff:ff") arp_packet = ARPPacket( - sender_ip=nic.ip_address, sender_mac_addr=nic.mac_address, target_ip=target_ip_address + sender_ip_address=nic.ip_address, sender_mac_addr=nic.mac_address, target_ip_address=target_ip_address ) frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) nic.send_frame(frame) @@ -663,14 +667,14 @@ class ARPCache: :param from_nic: The NIC to send the ARP reply from. """ self.sys_log.info( - f"Sending ARP reply from {arp_reply.sender_mac_addr}/{arp_reply.sender_ip} " - f"to {arp_reply.target_ip}/{arp_reply.target_mac_addr} " + f"Sending ARP reply from {arp_reply.sender_mac_addr}/{arp_reply.sender_ip_address} " + f"to {arp_reply.target_ip_address}/{arp_reply.target_mac_addr} " ) tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) ip_packet = IPPacket( - src_ip=arp_reply.sender_ip, - dst_ip=arp_reply.target_ip, + src_ip_address=arp_reply.sender_ip_address, + dst_ip_address=arp_reply.target_ip_address, ) ethernet_header = EthernetHeader(src_mac_addr=arp_reply.sender_mac_addr, dst_mac_addr=arp_reply.target_mac_addr) @@ -691,26 +695,26 @@ class ARPCache: # ARP Reply if not arp_packet.request: self.sys_log.info( - f"Received ARP response for {arp_packet.sender_ip} from {arp_packet.sender_mac_addr} via NIC {from_nic}" + f"Received ARP response for {arp_packet.sender_ip_address} from {arp_packet.sender_mac_addr} via NIC {from_nic}" ) self.add_arp_cache_entry( - ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic + ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic ) return # ARP Request self.sys_log.info( - f"Received ARP request for {arp_packet.target_ip} from " - f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip} " + f"Received ARP request for {arp_packet.target_ip_address} from " + f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip_address} " ) # Unmatched ARP Request - if arp_packet.target_ip != from_nic.ip_address: - self.sys_log.info(f"Ignoring ARP request for {arp_packet.target_ip}") + if arp_packet.target_ip_address != from_nic.ip_address: + self.sys_log.info(f"Ignoring ARP request for {arp_packet.target_ip_address}") return # Matched ARP request - self.add_arp_cache_entry(ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic) + self.add_arp_cache_entry(ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic) arp_packet = arp_packet.generate_reply(from_nic.mac_address) self.send_arp_reply(arp_packet, from_nic) @@ -744,18 +748,18 @@ class ICMP: """ if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: if not is_reattempt: - self.sys_log.info(f"Received echo request from {frame.ip.src_ip}") - target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip) + self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") + target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip_address) - src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip) + src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip_address) if not src_nic: - self.arp.send_arp_request(frame.ip.src_ip) + self.arp.send_arp_request(frame.ip.src_ip_address) self.process_icmp(frame=frame, from_nic=from_nic, is_reattempt=True) return tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) # Network Layer - ip_packet = IPPacket(src_ip=src_nic.ip_address, dst_ip=frame.ip.src_ip, protocol=IPProtocol.ICMP) + ip_packet = IPPacket(src_ip_address=src_nic.ip_address, dst_ip_address=frame.ip.src_ip_address, protocol=IPProtocol.ICMP) # Data Link Layer ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) icmp_reply_packet = ICMPPacket( @@ -768,14 +772,14 @@ class ICMP: frame = Frame( ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet, payload=payload ) - self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip}") + self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip_address}") src_nic.send_frame(frame) elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: time = frame.transmission_duration() time_str = f"{time}ms" if time > 0 else "<1ms" self.sys_log.info( - f"Reply from {frame.ip.src_ip}: " + f"Reply from {frame.ip.src_ip_address}: " f"bytes={len(frame.payload)}, " f"time={time_str}, " f"TTL={frame.ip.ttl}" @@ -821,8 +825,8 @@ class ICMP: # Network Layer ip_packet = IPPacket( - src_ip=nic.ip_address, - dst_ip=target_ip_address, + src_ip_address=nic.ip_address, + dst_ip_address=target_ip_address, protocol=IPProtocol.ICMP, ) # Data Link Layer @@ -1059,7 +1063,7 @@ class Node(SimComponent): :param frame: The Frame to be sent. """ - nic: NIC = self._get_arp_cache_nic(frame.ip.dst_ip) + nic: NIC = self._get_arp_cache_nic(frame.ip.dst_ip_address) nic.send_frame(frame) def receive_frame(self, frame: Frame, from_nic: NIC): @@ -1073,9 +1077,9 @@ class Node(SimComponent): :param from_nic: The NIC that received the frame. """ if frame.ip: - if frame.ip.src_ip in self.arp: + if frame.ip.src_ip_address in self.arp: self.arp.add_arp_cache_entry( - ip_address=frame.ip.src_ip, mac_address=frame.ethernet.src_mac_addr, nic=from_nic + ip_address=frame.ip.src_ip_address, mac_address=frame.ethernet.src_mac_addr, nic=from_nic ) if frame.ip.protocol == IPProtocol.TCP: if frame.tcp.src_port == Port.ARP: diff --git a/src/primaite/simulator/network/hardware/nodes/computer.py b/src/primaite/simulator/network/hardware/nodes/computer.py index 2a2e8524..a6def4eb 100644 --- a/src/primaite/simulator/network/hardware/nodes/computer.py +++ b/src/primaite/simulator/network/hardware/nodes/computer.py @@ -36,9 +36,5 @@ class Computer(Node): """ def __init__(self, **kwargs): - for key in {"ip_address", "subnet_mask", "default_gateway"}: - if key in kwargs: - if not isinstance(kwargs[key], IPv4Address): - kwargs[key] = IPv4Address(kwargs[key]) super().__init__(**kwargs) self.connect_nic(NIC(ip_address=kwargs["ip_address"], subnet_mask=kwargs["subnet_mask"])) diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 26ba01ae..0dd4aaff 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -28,17 +28,17 @@ class ACLRule(SimComponent): :ivar ACLAction action: Action to be performed (Permit/Deny). Default is DENY. :ivar Optional[IPProtocol] protocol: Network protocol. Default is None. - :ivar Optional[IPv4Address] src_ip: Source IP address. Default is None. + :ivar Optional[IPv4Address] src_ip_address: Source IP address. Default is None. :ivar Optional[Port] src_port: Source port number. Default is None. - :ivar Optional[IPv4Address] dst_ip: Destination IP address. Default is None. + :ivar Optional[IPv4Address] dst_ip_address: Destination IP address. Default is None. :ivar Optional[Port] dst_port: Destination port number. Default is None. """ action: ACLAction = ACLAction.DENY protocol: Optional[IPProtocol] = None - src_ip: Optional[IPv4Address] = None + src_ip_address: Optional[IPv4Address] = None src_port: Optional[Port] = None - dst_ip: Optional[IPv4Address] = None + dst_ip_address: Optional[IPv4Address] = None dst_port: Optional[Port] = None def __str__(self) -> str: @@ -109,9 +109,9 @@ class AccessControlList(SimComponent): self, action: ACLAction, protocol: Optional[IPProtocol] = None, - src_ip: Optional[Union[str, IPv4Address]] = None, + src_ip_address: Optional[Union[str, IPv4Address]] = None, src_port: Optional[Port] = None, - dst_ip: Optional[Union[str, IPv4Address]] = None, + dst_ip_address: Optional[Union[str, IPv4Address]] = None, dst_port: Optional[Port] = None, position: int = 0, ) -> None: @@ -120,20 +120,20 @@ class AccessControlList(SimComponent): :param ACLAction action: Action to be performed (Permit/Deny). :param Optional[IPProtocol] protocol: Network protocol. - :param Optional[Union[str, IPv4Address]] src_ip: Source IP address. + :param Optional[Union[str, IPv4Address]] src_ip_address: Source IP address. :param Optional[Port] src_port: Source port number. - :param Optional[Union[str, IPv4Address]] dst_ip: Destination IP address. + :param Optional[Union[str, IPv4Address]] dst_ip_address: Destination IP address. :param Optional[Port] dst_port: Destination port number. :param int position: Position in the ACL list to insert the rule. :raises ValueError: When the position is out of bounds. """ - if isinstance(src_ip, str): - src_ip = IPv4Address(src_ip) - if isinstance(dst_ip, str): - dst_ip = IPv4Address(dst_ip) + if isinstance(src_ip_address, str): + src_ip_address = IPv4Address(src_ip_address) + if isinstance(dst_ip_address, str): + dst_ip_address = IPv4Address(dst_ip_address) if 0 <= position < self.max_acl_rules: self._acl[position] = ACLRule( - action=action, src_ip=src_ip, dst_ip=dst_ip, protocol=protocol, src_port=src_port, dst_port=dst_port + action=action, src_ip_address=src_ip_address, dst_ip_address=dst_ip_address, protocol=protocol, src_port=src_port, dst_port=dst_port ) else: raise ValueError(f"Position {position} is out of bounds.") @@ -153,33 +153,33 @@ class AccessControlList(SimComponent): def is_permitted( self, protocol: IPProtocol, - src_ip: Union[str, IPv4Address], + src_ip_address: Union[str, IPv4Address], src_port: Optional[Port], - dst_ip: Union[str, IPv4Address], + dst_ip_address: Union[str, IPv4Address], dst_port: Optional[Port], ) -> Tuple[bool, Optional[Union[str, ACLRule]]]: """ Check if a packet with the given properties is permitted through the ACL. :param protocol: The protocol of the packet. - :param src_ip: Source IP address of the packet. Accepts string and IPv4Address. + :param src_ip_address: Source IP address of the packet. Accepts string and IPv4Address. :param src_port: Source port of the packet. Optional. - :param dst_ip: Destination IP address of the packet. Accepts string and IPv4Address. + :param dst_ip_address: Destination IP address of the packet. Accepts string and IPv4Address. :param dst_port: Destination port of the packet. Optional. :return: A tuple with a boolean indicating if the packet is permitted and an optional rule or implicit action string. """ - if not isinstance(src_ip, IPv4Address): - src_ip = IPv4Address(src_ip) - if not isinstance(dst_ip, IPv4Address): - dst_ip = IPv4Address(dst_ip) + if not isinstance(src_ip_address, IPv4Address): + src_ip_address = IPv4Address(src_ip_address) + if not isinstance(dst_ip_address, IPv4Address): + dst_ip_address = IPv4Address(dst_ip_address) for rule in self._acl: if not rule: continue if ( - (rule.src_ip == src_ip or rule.src_ip is None) - and (rule.dst_ip == dst_ip or rule.dst_ip is None) + (rule.src_ip_address == src_ip_address or rule.src_ip_address is None) + and (rule.dst_ip_address == dst_ip_address or rule.dst_ip_address is None) and (rule.protocol == protocol or rule.protocol is None) and (rule.src_port == src_port or rule.src_port is None) and (rule.dst_port == dst_port or rule.dst_port is None) @@ -191,33 +191,33 @@ class AccessControlList(SimComponent): def get_relevant_rules( self, protocol: IPProtocol, - src_ip: Union[str, IPv4Address], + src_ip_address: Union[str, IPv4Address], src_port: Port, - dst_ip: Union[str, IPv4Address], + dst_ip_address: Union[str, IPv4Address], dst_port: Port, ) -> List[ACLRule]: """ Get the list of relevant rules for a packet with given properties. :param protocol: The protocol of the packet. - :param src_ip: Source IP address of the packet. Accepts string and IPv4Address. + :param src_ip_address: Source IP address of the packet. Accepts string and IPv4Address. :param src_port: Source port of the packet. - :param dst_ip: Destination IP address of the packet. Accepts string and IPv4Address. + :param dst_ip_address: Destination IP address of the packet. Accepts string and IPv4Address. :param dst_port: Destination port of the packet. :return: A list of relevant ACLRules. """ - if not isinstance(src_ip, IPv4Address): - src_ip = IPv4Address(src_ip) - if not isinstance(dst_ip, IPv4Address): - dst_ip = IPv4Address(dst_ip) + if not isinstance(src_ip_address, IPv4Address): + src_ip_address = IPv4Address(src_ip_address) + if not isinstance(dst_ip_address, IPv4Address): + dst_ip_address = IPv4Address(dst_ip_address) relevant_rules = [] for rule in self._acl: if rule is None: continue if ( - (rule.src_ip == src_ip or rule.src_ip is None) - or (rule.dst_ip == dst_ip or rule.dst_ip is None) + (rule.src_ip_address == src_ip_address or rule.src_ip_address is None) + or (rule.dst_ip_address == dst_ip_address or rule.dst_ip_address is None) or (rule.protocol == protocol or rule.protocol is None) or (rule.src_port == src_port or rule.src_port is None) or (rule.dst_port == dst_port or rule.dst_port is None) @@ -244,9 +244,9 @@ class AccessControlList(SimComponent): index, rule.action.name if rule.action else "ANY", rule.protocol.name if rule.protocol else "ANY", - rule.src_ip if rule.src_ip else "ANY", + rule.src_ip_address if rule.src_ip_address else "ANY", f"{rule.src_port.value} ({rule.src_port.name})" if rule.src_port else "ANY", - rule.dst_ip if rule.dst_ip else "ANY", + rule.dst_ip_address if rule.dst_ip_address else "ANY", f"{rule.dst_port.value} ({rule.dst_port.name})" if rule.dst_port else "ANY", ] ) @@ -260,7 +260,7 @@ class RouteEntry(SimComponent): Attributes: address (IPv4Address): The destination IP address or network address. subnet_mask (IPv4Address): The subnet mask for the network. - next_hop (IPv4Address): The next hop IP address to which packets should be forwarded. + next_hop_ip_address (IPv4Address): The next hop IP address to which packets should be forwarded. metric (int): The cost metric for this route. Default is 0.0. Example: @@ -276,13 +276,13 @@ class RouteEntry(SimComponent): "The destination IP address or network address." subnet_mask: IPv4Address "The subnet mask for the network." - next_hop: IPv4Address + next_hop_ip_address: IPv4Address "The next hop IP address to which packets should be forwarded." metric: float = 0.0 "The cost metric for this route. Default is 0.0." def __init__(self, **kwargs): - for key in {"address", "subnet_mask", "next_hop"}: + for key in {"address", "subnet_mask", "next_hop_ip_address"}: if not isinstance(kwargs[key], IPv4Address): kwargs[key] = IPv4Address(kwargs[key]) super().__init__(**kwargs) @@ -330,7 +330,7 @@ class RouteTable(SimComponent): self, address: Union[IPv4Address, str], subnet_mask: Union[IPv4Address, str], - next_hop: Union[IPv4Address, str], + next_hop_ip_address: Union[IPv4Address, str], metric: float = 0.0, ): """ @@ -338,13 +338,13 @@ class RouteTable(SimComponent): :param address: The destination address of the route. :param subnet_mask: The subnet mask of the route. - :param next_hop: The next hop IP for the route. + :param next_hop_ip_address: The next hop IP for the route. :param metric: The metric of the route, default is 0.0. """ - for key in {address, subnet_mask, next_hop}: + for key in {address, subnet_mask, next_hop_ip_address}: if not isinstance(key, IPv4Address): key = IPv4Address(key) - route = RouteEntry(address=address, subnet_mask=subnet_mask, next_hop=next_hop, metric=metric) + route = RouteEntry(address=address, subnet_mask=subnet_mask, next_hop_ip_address=next_hop_ip_address, metric=metric) self.routes.append(route) def find_best_route(self, destination_ip: Union[str, IPv4Address]) -> Optional[RouteEntry]: @@ -387,7 +387,7 @@ class RouteTable(SimComponent): table.title = f"{self.sys_log.hostname} Route Table" for index, route in enumerate(self.routes): network = IPv4Network(f"{route.address}/{route.subnet_mask}") - table.add_row([index, f"{route.address}/{network.prefixlen}", route.next_hop, route.metric]) + table.add_row([index, f"{route.address}/{network.prefixlen}", route.next_hop_ip_address, route.metric]) print(table) @@ -415,40 +415,40 @@ class RouterARPCache(ARPCache): # ARP Reply if not arp_packet.request: for nic in self.router.nics.values(): - if arp_packet.target_ip == nic.ip_address: + if arp_packet.target_ip_address == nic.ip_address: # reply to the Router specifically self.sys_log.info( - f"Received ARP response for {arp_packet.sender_ip} " + f"Received ARP response for {arp_packet.sender_ip_address} " f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" ) self.add_arp_cache_entry( - ip_address=arp_packet.sender_ip, + ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic, ) return # Reply for a connected requested - nic = self.get_arp_cache_nic(arp_packet.target_ip) + nic = self.get_arp_cache_nic(arp_packet.target_ip_address) if nic: - self.sys_log.info(f"Forwarding arp reply for {arp_packet.target_ip}, from {arp_packet.sender_ip}") + self.sys_log.info(f"Forwarding arp reply for {arp_packet.target_ip_address}, from {arp_packet.sender_ip_address}") arp_packet.sender_mac_addr = nic.mac_address frame.decrement_ttl() nic.send_frame(frame) # ARP Request self.sys_log.info( - f"Received ARP request for {arp_packet.target_ip} from " - f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip} " + f"Received ARP request for {arp_packet.target_ip_address} from " + f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip_address} " ) # Matched ARP request - self.add_arp_cache_entry(ip_address=arp_packet.sender_ip, mac_address=arp_packet.sender_mac_addr, nic=from_nic) + self.add_arp_cache_entry(ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic) arp_packet = arp_packet.generate_reply(from_nic.mac_address) self.send_arp_reply(arp_packet, from_nic) # If the target IP matches one of the router's NICs for nic in self.nics.values(): - if nic.enabled and nic.ip_address == arp_packet.target_ip: + if nic.enabled and nic.ip_address == arp_packet.target_ip_address: arp_reply = arp_packet.generate_reply(from_nic.mac_address) self.send_arp_reply(arp_reply, from_nic) return @@ -484,17 +484,17 @@ class RouterICMP(ICMP): # determine if request is for router interface or whether it needs to be routed for nic in self.router.nics.values(): - if nic.ip_address == frame.ip.dst_ip: + if nic.ip_address == frame.ip.dst_ip_address: if nic.enabled: # reply to the request if not is_reattempt: - self.sys_log.info(f"Received echo request from {frame.ip.src_ip}") - target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip) - src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip) + self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") + target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip_address) + src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip_address) tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) # Network Layer - ip_packet = IPPacket(src_ip=nic.ip_address, dst_ip=frame.ip.src_ip, protocol=IPProtocol.ICMP) + ip_packet = IPPacket(src_ip_address=nic.ip_address, dst_ip_address=frame.ip.src_ip_address, protocol=IPProtocol.ICMP) # Data Link Layer ethernet_header = EthernetHeader( src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address @@ -513,7 +513,7 @@ class RouterICMP(ICMP): icmp=icmp_reply_packet, payload=payload, ) - self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip}") + self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip_address}") src_nic.send_frame(frame) return @@ -523,12 +523,12 @@ class RouterICMP(ICMP): elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: for nic in self.router.nics.values(): - if nic.ip_address == frame.ip.dst_ip: + if nic.ip_address == frame.ip.dst_ip_address: if nic.enabled: time = frame.transmission_duration() time_str = f"{time}ms" if time > 0 else "<1ms" self.sys_log.info( - f"Reply from {frame.ip.src_ip}: " + f"Reply from {frame.ip.src_ip_address}: " f"bytes={len(frame.payload)}, " f"time={time_str}, " f"TTL={frame.ip.ttl}" @@ -606,22 +606,22 @@ class Router(Node): :param re_attempt: Flag to indicate if the routing is a reattempt. """ # Check if src ip is on network of one of the NICs - nic = self.arp.get_arp_cache_nic(frame.ip.dst_ip) - target_mac = self.arp.get_arp_cache_mac_address(frame.ip.dst_ip) + nic = self.arp.get_arp_cache_nic(frame.ip.dst_ip_address) + target_mac = self.arp.get_arp_cache_mac_address(frame.ip.dst_ip_address) if re_attempt and not nic: - self.sys_log.info(f"Destination {frame.ip.dst_ip} is unreachable") + self.sys_log.info(f"Destination {frame.ip.dst_ip_address} is unreachable") return if not nic: - self.arp.send_arp_request(frame.ip.dst_ip) + self.arp.send_arp_request(frame.ip.dst_ip_address) return self.route_frame(frame=frame, from_nic=from_nic, re_attempt=True) if not nic.enabled: # TODO: Add sys_log here return - if frame.ip.dst_ip in nic.ip_network: + if frame.ip.dst_ip_address in nic.ip_network: from_port = self._get_port_of_nic(from_nic) to_port = self._get_port_of_nic(nic) self.sys_log.info(f"Routing frame to internally from port {from_port} to port {to_port}") @@ -643,8 +643,8 @@ class Router(Node): """ route_frame = False protocol = frame.ip.protocol - src_ip = frame.ip.src_ip - dst_ip = frame.ip.dst_ip + src_ip_address = frame.ip.src_ip_address + dst_ip_address = frame.ip.dst_ip_address src_port = None dst_port = None if frame.ip.protocol == IPProtocol.TCP: @@ -656,14 +656,14 @@ class Router(Node): # Check if it's permitted permitted, rule = self.acl.is_permitted( - protocol=protocol, src_ip=src_ip, src_port=src_port, dst_ip=dst_ip, dst_port=dst_port + protocol=protocol, src_ip_address=src_ip_address, src_port=src_port, dst_ip_address=dst_ip_address, dst_port=dst_port ) if not permitted: at_port = self._get_port_of_nic(from_nic) self.sys_log.info(f"Frame blocked at port {at_port} by rule {rule}") return - if not self.arp.get_arp_cache_nic(src_ip): - self.arp.add_arp_cache_entry(src_ip, frame.ethernet.src_mac_addr, from_nic) + if not self.arp.get_arp_cache_nic(src_ip_address): + self.arp.add_arp_cache_entry(src_ip_address, frame.ethernet.src_mac_addr, from_nic) if frame.ip.protocol == IPProtocol.ICMP: self.icmp.process_icmp(frame=frame, from_nic=from_nic) else: diff --git a/src/primaite/simulator/network/protocols/arp.py b/src/primaite/simulator/network/protocols/arp.py index bae14d28..5e38cc66 100644 --- a/src/primaite/simulator/network/protocols/arp.py +++ b/src/primaite/simulator/network/protocols/arp.py @@ -24,21 +24,21 @@ class ARPPacket(BaseModel): :param request: ARP operation. True if a request, False if a reply. :param sender_mac_addr: Sender MAC address. - :param sender_ip: Sender IP address. + :param sender_ip_address: Sender IP address. :param target_mac_addr: Target MAC address. - :param target_ip: Target IP address. + :param target_ip_address: Target IP address. :Example: >>> arp_request = ARPPacket( ... sender_mac_addr="aa:bb:cc:dd:ee:ff", - ... sender_ip=IPv4Address("192.168.0.1"), - ... target_ip=IPv4Address("192.168.0.2") + ... sender_ip_address=IPv4Address("192.168.0.1"), + ... target_ip_address=IPv4Address("192.168.0.2") ... ) >>> arp_response = ARPPacket( ... sender_mac_addr="aa:bb:cc:dd:ee:ff", - ... sender_ip=IPv4Address("192.168.0.1"), - ... target_ip=IPv4Address("192.168.0.2") + ... sender_ip_address=IPv4Address("192.168.0.1"), + ... target_ip_address=IPv4Address("192.168.0.2") ... ) """ @@ -46,11 +46,11 @@ class ARPPacket(BaseModel): "ARP operation. True if a request, False if a reply." sender_mac_addr: str "Sender MAC address." - sender_ip: IPv4Address + sender_ip_address: IPv4Address "Sender IP address." target_mac_addr: Optional[str] = None "Target MAC address." - target_ip: IPv4Address + target_ip_address: IPv4Address "Target IP address." def generate_reply(self, mac_address: str) -> ARPPacket: @@ -62,8 +62,8 @@ class ARPPacket(BaseModel): """ return ARPPacket( request=False, - sender_ip=self.target_ip, + sender_ip_address=self.target_ip_address, sender_mac_addr=mac_address, - target_ip=self.sender_ip, + target_ip_address=self.sender_ip_address, target_mac_addr=self.sender_mac_addr, ) diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index ddd9fad3..b7986622 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -52,8 +52,8 @@ class Frame(BaseModel): ... dst_mac_addr='11:22:33:44:55:66' ... ), ... ip=IPPacket( - ... src_ip=IPv4Address('192.168.0.1'), - ... dst_ip=IPv4Address('10.0.0.1'), + ... src_ip_address=IPv4Address('192.168.0.1'), + ... dst_ip_address=IPv4Address('10.0.0.1'), ... ), ... tcp=TCPHeader( ... src_port=8080, diff --git a/src/primaite/simulator/network/transmission/network_layer.py b/src/primaite/simulator/network/transmission/network_layer.py index afd1ecef..fd36fbf8 100644 --- a/src/primaite/simulator/network/transmission/network_layer.py +++ b/src/primaite/simulator/network/transmission/network_layer.py @@ -162,8 +162,8 @@ class IPPacket(BaseModel): """ Represents the IP layer of a network frame. - :param src_ip: Source IP address. - :param dst_ip: Destination IP address. + :param src_ip_address: Source IP address. + :param dst_ip_address: Destination IP address. :param protocol: The IP protocol (default is TCP). :param ttl: Time to Live (TTL) for the packet. :param precedence: Precedence level for Quality of Service (QoS). @@ -172,17 +172,17 @@ class IPPacket(BaseModel): >>> from ipaddress import IPv4Address >>> ip_packet = IPPacket( - ... src_ip=IPv4Address('192.168.0.1'), - ... dst_ip=IPv4Address('10.0.0.1'), + ... src_ip_address=IPv4Address('192.168.0.1'), + ... dst_ip_address=IPv4Address('10.0.0.1'), ... protocol=IPProtocol.TCP, ... ttl=64, ... precedence=Precedence.CRITICAL ... ) """ - src_ip: IPv4Address + src_ip_address: IPv4Address "Source IP address." - dst_ip: IPv4Address + dst_ip_address: IPv4Address "Destination IP address." protocol: IPProtocol = IPProtocol.TCP "IPProtocol." @@ -192,8 +192,8 @@ class IPPacket(BaseModel): "Precedence level for Quality of Service (default is Precedence.ROUTINE)." def __init__(self, **kwargs): - if not isinstance(kwargs["src_ip"], IPv4Address): - kwargs["src_ip"] = IPv4Address(kwargs["src_ip"]) - if not isinstance(kwargs["dst_ip"], IPv4Address): - kwargs["dst_ip"] = IPv4Address(kwargs["dst_ip"]) + if not isinstance(kwargs["src_ip_address"], IPv4Address): + kwargs["src_ip_address"] = IPv4Address(kwargs["src_ip_address"]) + if not isinstance(kwargs["dst_ip_address"], IPv4Address): + kwargs["dst_ip_address"] = IPv4Address(kwargs["dst_ip_address"]) super().__init__(**kwargs) diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index fe7b06b2..705210ff 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -22,16 +22,16 @@ class Session(SimComponent): source and destination IPs and ports. :param protocol: The IP protocol used in the session. - :param src_ip: The source IP address. - :param dst_ip: The destination IP address. + :param src_ip_address: The source IP address. + :param dst_ip_address: The destination IP address. :param src_port: The source port number (optional). :param dst_port: The destination port number (optional). :param connected: A flag indicating whether the session is connected. """ protocol: IPProtocol - src_ip: IPv4Address - dst_ip: IPv4Address + src_ip_address: IPv4Address + dst_ip_address: IPv4Address src_port: Optional[Port] dst_port: Optional[Port] connected: bool = False @@ -46,8 +46,8 @@ class Session(SimComponent): :param session_key: Tuple containing the session details. :return: A Session instance. """ - protocol, src_ip, dst_ip, src_port, dst_port = session_key - return Session(protocol=protocol, src_ip=src_ip, dst_ip=dst_ip, src_port=src_port, dst_port=dst_port) + protocol, src_ip_address, dst_ip_address, src_port, dst_port = session_key + return Session(protocol=protocol, src_ip_address=src_ip_address, dst_ip_address=dst_ip_address, src_port=src_port, dst_port=dst_port) def describe_state(self) -> Dict: """ @@ -108,8 +108,8 @@ class SessionManager: :return: A tuple containing the session key. """ protocol = frame.ip.protocol - src_ip = frame.ip.src_ip - dst_ip = frame.ip.dst_ip + src_ip_address = frame.ip.src_ip_address + dst_ip_address = frame.ip.dst_ip_address if protocol == IPProtocol.TCP: if from_source: src_port = frame.tcp.src_port @@ -127,7 +127,7 @@ class SessionManager: else: src_port = None dst_port = None - return protocol, src_ip, dst_ip, src_port, dst_port + return protocol, src_ip_address, dst_ip_address, src_port, dst_port def receive_payload_from_software_manager(self, payload: Any, session_id: Optional[int] = None): """ diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py index 99736421..554cba38 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py @@ -11,17 +11,17 @@ def test_add_rule(): acl.add_rule( action=ACLAction.PERMIT, protocol=IPProtocol.TCP, - src_ip=IPv4Address("192.168.1.1"), + src_ip_address=IPv4Address("192.168.1.1"), src_port=Port(8080), - dst_ip=IPv4Address("192.168.1.2"), + dst_ip_address=IPv4Address("192.168.1.2"), dst_port=Port(80), position=1, ) assert acl.acl[1].action == ACLAction.PERMIT assert acl.acl[1].protocol == IPProtocol.TCP - assert acl.acl[1].src_ip == IPv4Address("192.168.1.1") + assert acl.acl[1].src_ip_address == IPv4Address("192.168.1.1") assert acl.acl[1].src_port == Port(8080) - assert acl.acl[1].dst_ip == IPv4Address("192.168.1.2") + assert acl.acl[1].dst_ip_address == IPv4Address("192.168.1.2") assert acl.acl[1].dst_port == Port(80) @@ -31,9 +31,9 @@ def test_remove_rule(): acl.add_rule( action=ACLAction.PERMIT, protocol=IPProtocol.TCP, - src_ip=IPv4Address("192.168.1.1"), + src_ip_address=IPv4Address("192.168.1.1"), src_port=Port(8080), - dst_ip=IPv4Address("192.168.1.2"), + dst_ip_address=IPv4Address("192.168.1.2"), dst_port=Port(80), position=1, ) @@ -47,34 +47,34 @@ def test_rules(): acl.add_rule( action=ACLAction.PERMIT, protocol=IPProtocol.TCP, - src_ip=IPv4Address("192.168.1.1"), + src_ip_address=IPv4Address("192.168.1.1"), src_port=Port(8080), - dst_ip=IPv4Address("192.168.1.2"), + dst_ip_address=IPv4Address("192.168.1.2"), dst_port=Port(80), position=1, ) acl.add_rule( action=ACLAction.DENY, protocol=IPProtocol.TCP, - src_ip=IPv4Address("192.168.1.3"), + src_ip_address=IPv4Address("192.168.1.3"), src_port=Port(8080), - dst_ip=IPv4Address("192.168.1.4"), + dst_ip_address=IPv4Address("192.168.1.4"), dst_port=Port(80), position=2, ) is_permitted, rule = acl.is_permitted( protocol=IPProtocol.TCP, - src_ip=IPv4Address("192.168.1.1"), + src_ip_address=IPv4Address("192.168.1.1"), src_port=Port(8080), - dst_ip=IPv4Address("192.168.1.2"), + dst_ip_address=IPv4Address("192.168.1.2"), dst_port=Port(80), ) assert is_permitted is_permitted, rule = acl.is_permitted( protocol=IPProtocol.TCP, - src_ip=IPv4Address("192.168.1.3"), + src_ip_address=IPv4Address("192.168.1.3"), src_port=Port(8080), - dst_ip=IPv4Address("192.168.1.4"), + dst_ip_address=IPv4Address("192.168.1.4"), dst_port=Port(80), ) assert not is_permitted @@ -86,26 +86,26 @@ def test_default_rule(): acl.add_rule( action=ACLAction.PERMIT, protocol=IPProtocol.TCP, - src_ip=IPv4Address("192.168.1.1"), + src_ip_address=IPv4Address("192.168.1.1"), src_port=Port(8080), - dst_ip=IPv4Address("192.168.1.2"), + dst_ip_address=IPv4Address("192.168.1.2"), dst_port=Port(80), position=1, ) acl.add_rule( action=ACLAction.DENY, protocol=IPProtocol.TCP, - src_ip=IPv4Address("192.168.1.3"), + src_ip_address=IPv4Address("192.168.1.3"), src_port=Port(8080), - dst_ip=IPv4Address("192.168.1.4"), + dst_ip_address=IPv4Address("192.168.1.4"), dst_port=Port(80), position=2, ) is_permitted, rule = acl.is_permitted( protocol=IPProtocol.UDP, - src_ip=IPv4Address("192.168.1.5"), + src_ip_address=IPv4Address("192.168.1.5"), src_port=Port(8080), - dst_ip=IPv4Address("192.168.1.12"), + dst_ip_address=IPv4Address("192.168.1.12"), dst_port=Port(80), ) assert not is_permitted diff --git a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py index 8a78d1bc..f9b89de5 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py @@ -10,7 +10,7 @@ def test_frame_minimal_instantiation(): """Tests that the minimum frame (TCP SYN) using default values.""" frame = Frame( ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), - ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20"), + ip=IPPacket(src_ip_address="192.168.0.10", dst_ip_address="192.168.0.20"), tcp=TCPHeader( src_port=8080, dst_port=80, @@ -38,7 +38,7 @@ def test_frame_creation_fails_tcp_without_header(): with pytest.raises(ValueError): Frame( ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), - ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.TCP), + ip=IPPacket(src_ip_address="192.168.0.10", dst_ip_address="192.168.0.20", protocol=IPProtocol.TCP), ) @@ -47,7 +47,7 @@ def test_frame_creation_fails_udp_without_header(): with pytest.raises(ValueError): Frame( ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), - ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.UDP), + ip=IPPacket(src_ip_address="192.168.0.10", dst_ip_address="192.168.0.20", protocol=IPProtocol.UDP), ) @@ -56,7 +56,7 @@ def test_frame_creation_fails_tcp_with_udp_header(): with pytest.raises(ValueError): Frame( ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), - ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.TCP), + ip=IPPacket(src_ip_address="192.168.0.10", dst_ip_address="192.168.0.20", protocol=IPProtocol.TCP), udp=UDPHeader(src_port=8080, dst_port=80), ) @@ -66,7 +66,7 @@ def test_frame_creation_fails_udp_with_tcp_header(): with pytest.raises(ValueError): Frame( ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), - ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.UDP), + ip=IPPacket(src_ip_address="192.168.0.10", dst_ip_address="192.168.0.20", protocol=IPProtocol.UDP), udp=TCPHeader(src_port=8080, dst_port=80), ) @@ -75,7 +75,7 @@ def test_icmp_frame_creation(): """Tests Frame creation for ICMP.""" frame = Frame( ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), - ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.ICMP), + ip=IPPacket(src_ip_address="192.168.0.10", dst_ip_address="192.168.0.20", protocol=IPProtocol.ICMP), icmp=ICMPPacket(), ) assert frame @@ -86,5 +86,5 @@ def test_icmp_frame_creation_fails_without_icmp_header(): with pytest.raises(ValueError): Frame( ethernet=EthernetHeader(src_mac_addr="aa:bb:cc:dd:ee:ff", dst_mac_addr="11:22:33:44:55:66"), - ip=IPPacket(src_ip="192.168.0.10", dst_ip="192.168.0.20", protocol=IPProtocol.ICMP), + ip=IPPacket(src_ip_address="192.168.0.10", dst_ip_address="192.168.0.20", protocol=IPProtocol.ICMP), ) From ccad5ba8a319810f1afe7ddd531c929f41b1d5ec Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 4 Sep 2023 16:34:55 +0100 Subject: [PATCH 143/980] #1800 - Ran pre-commit --- src/primaite/simulator/core.py | 2 +- .../simulator/network/hardware/base.py | 15 ++++++--- .../network/hardware/nodes/computer.py | 2 -- .../network/hardware/nodes/router.py | 31 +++++++++++++++---- .../simulator/system/core/session_manager.py | 8 ++++- 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 3e68ed5f..b7dfcf72 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from typing import Callable, Dict, List, Optional, Union from uuid import uuid4 -from pydantic import BaseModel, ConfigDict, Extra, validator +from pydantic import BaseModel, ConfigDict, Extra from primaite import getLogger diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index a170506b..f2feb961 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -654,7 +654,9 @@ class ARPCache: # Data Link Layer ethernet_header = EthernetHeader(src_mac_addr=nic.mac_address, dst_mac_addr="ff:ff:ff:ff:ff:ff") arp_packet = ARPPacket( - sender_ip_address=nic.ip_address, sender_mac_addr=nic.mac_address, target_ip_address=target_ip_address + sender_ip_address=nic.ip_address, + sender_mac_addr=nic.mac_address, + target_ip_address=target_ip_address, ) frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) nic.send_frame(frame) @@ -695,7 +697,8 @@ class ARPCache: # ARP Reply if not arp_packet.request: self.sys_log.info( - f"Received ARP response for {arp_packet.sender_ip_address} from {arp_packet.sender_mac_addr} via NIC {from_nic}" + f"Received ARP response for {arp_packet.sender_ip_address} " + f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" ) self.add_arp_cache_entry( ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic @@ -714,7 +717,9 @@ class ARPCache: return # Matched ARP request - self.add_arp_cache_entry(ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic) + self.add_arp_cache_entry( + ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic + ) arp_packet = arp_packet.generate_reply(from_nic.mac_address) self.send_arp_reply(arp_packet, from_nic) @@ -759,7 +764,9 @@ class ICMP: tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) # Network Layer - ip_packet = IPPacket(src_ip_address=src_nic.ip_address, dst_ip_address=frame.ip.src_ip_address, protocol=IPProtocol.ICMP) + ip_packet = IPPacket( + src_ip_address=src_nic.ip_address, dst_ip_address=frame.ip.src_ip_address, protocol=IPProtocol.ICMP + ) # Data Link Layer ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) icmp_reply_packet = ICMPPacket( diff --git a/src/primaite/simulator/network/hardware/nodes/computer.py b/src/primaite/simulator/network/hardware/nodes/computer.py index a6def4eb..5452666b 100644 --- a/src/primaite/simulator/network/hardware/nodes/computer.py +++ b/src/primaite/simulator/network/hardware/nodes/computer.py @@ -1,5 +1,3 @@ -from ipaddress import IPv4Address - from primaite.simulator.network.hardware.base import NIC, Node diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index a8177e86..a34b83e2 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -132,7 +132,12 @@ class AccessControlList(SimComponent): dst_ip_address = IPv4Address(dst_ip_address) if 0 <= position < self.max_acl_rules: self._acl[position] = ACLRule( - action=action, src_ip_address=src_ip_address, dst_ip_address=dst_ip_address, protocol=protocol, src_port=src_port, dst_port=dst_port + action=action, + src_ip_address=src_ip_address, + dst_ip_address=dst_ip_address, + protocol=protocol, + src_port=src_port, + dst_port=dst_port, ) else: raise ValueError(f"Position {position} is out of bounds.") @@ -343,7 +348,9 @@ class RouteTable(SimComponent): for key in {address, subnet_mask, next_hop_ip_address}: if not isinstance(key, IPv4Address): key = IPv4Address(key) - route = RouteEntry(address=address, subnet_mask=subnet_mask, next_hop_ip_address=next_hop_ip_address, metric=metric) + route = RouteEntry( + address=address, subnet_mask=subnet_mask, next_hop_ip_address=next_hop_ip_address, metric=metric + ) self.routes.append(route) def find_best_route(self, destination_ip: Union[str, IPv4Address]) -> Optional[RouteEntry]: @@ -430,7 +437,9 @@ class RouterARPCache(ARPCache): # Reply for a connected requested nic = self.get_arp_cache_nic(arp_packet.target_ip_address) if nic: - self.sys_log.info(f"Forwarding arp reply for {arp_packet.target_ip_address}, from {arp_packet.sender_ip_address}") + self.sys_log.info( + f"Forwarding arp reply for {arp_packet.target_ip_address}, from {arp_packet.sender_ip_address}" + ) arp_packet.sender_mac_addr = nic.mac_address frame.decrement_ttl() nic.send_frame(frame) @@ -441,7 +450,9 @@ class RouterARPCache(ARPCache): f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip_address} " ) # Matched ARP request - self.add_arp_cache_entry(ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic) + self.add_arp_cache_entry( + ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic + ) arp_packet = arp_packet.generate_reply(from_nic.mac_address) self.send_arp_reply(arp_packet, from_nic) @@ -493,7 +504,11 @@ class RouterICMP(ICMP): tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) # Network Layer - ip_packet = IPPacket(src_ip_address=nic.ip_address, dst_ip_address=frame.ip.src_ip_address, protocol=IPProtocol.ICMP) + ip_packet = IPPacket( + src_ip_address=nic.ip_address, + dst_ip_address=frame.ip.src_ip_address, + protocol=IPProtocol.ICMP, + ) # Data Link Layer ethernet_header = EthernetHeader( src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address @@ -655,7 +670,11 @@ class Router(Node): # Check if it's permitted permitted, rule = self.acl.is_permitted( - protocol=protocol, src_ip_address=src_ip_address, src_port=src_port, dst_ip_address=dst_ip_address, dst_port=dst_port + protocol=protocol, + src_ip_address=src_ip_address, + src_port=src_port, + dst_ip_address=dst_ip_address, + dst_port=dst_port, ) if not permitted: at_port = self._get_port_of_nic(from_nic) diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 705210ff..7f3d22c5 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -47,7 +47,13 @@ class Session(SimComponent): :return: A Session instance. """ protocol, src_ip_address, dst_ip_address, src_port, dst_port = session_key - return Session(protocol=protocol, src_ip_address=src_ip_address, dst_ip_address=dst_ip_address, src_port=src_port, dst_port=dst_port) + return Session( + protocol=protocol, + src_ip_address=src_ip_address, + dst_ip_address=dst_ip_address, + src_port=src_port, + dst_port=dst_port, + ) def describe_state(self) -> Dict: """ From 596ad20cc6fb814e9327804cd8a3e4b29c72892c Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 4 Sep 2023 16:44:29 +0100 Subject: [PATCH 144/980] #1800 - Added better logging and error messages to AccessControlList class. Updated usage of extra following pydantic deprecated warning "`pydantic.config.Extra` is deprecated, use literal values instead (e.g. `extra='allow'`)" --- src/primaite/simulator/core.py | 4 ++-- src/primaite/simulator/network/hardware/nodes/router.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index b7dfcf72..0501bbb2 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from typing import Callable, Dict, List, Optional, Union from uuid import uuid4 -from pydantic import BaseModel, ConfigDict, Extra +from pydantic import BaseModel, ConfigDict from primaite import getLogger @@ -126,7 +126,7 @@ class ActionManager: class SimComponent(BaseModel): """Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator.""" - model_config = ConfigDict(arbitrary_types_allowed=True, extra=Extra.allow) + model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow") """Configure pydantic to allow arbitrary types and to let the instance have attributes not present in model.""" uuid: str diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index a34b83e2..092680a7 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -131,6 +131,8 @@ class AccessControlList(SimComponent): if isinstance(dst_ip_address, str): dst_ip_address = IPv4Address(dst_ip_address) if 0 <= position < self.max_acl_rules: + if self._acl[position]: + self.sys_log.info(f"Overwriting ACL rule at position {position}") self._acl[position] = ACLRule( action=action, src_ip_address=src_ip_address, @@ -140,7 +142,7 @@ class AccessControlList(SimComponent): dst_port=dst_port, ) else: - raise ValueError(f"Position {position} is out of bounds.") + raise ValueError(f"Cannot add ACL rule, position {position} is out of bounds.") def remove_rule(self, position: int) -> None: """ @@ -150,9 +152,11 @@ class AccessControlList(SimComponent): :raises ValueError: When the position is out of bounds. """ if 0 <= position < self.max_acl_rules - 1: + rule = self._acl[position] # noqa self._acl[position] = None + del rule else: - raise ValueError(f"Position {position} is out of bounds.") + raise ValueError(f"Cannot remove ACL rule, position {position} is out of bounds.") def is_permitted( self, From 289f81826637c4760d7f98dca8e17cff70d60204 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Sep 2023 16:11:47 +0000 Subject: [PATCH 145/980] Apply suggestions from code review --- src/primaite/simulator/file_system/file_system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 1346d3e0..e9385644 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -211,7 +211,7 @@ class FileSystem(SimComponent): if file is not None: return file - def get_folder_by_name(self, folder_name: str) -> Union[FileSystemFolder, None]: + def get_folder_by_name(self, folder_name: str) -> Optional[FileSystemFolder]: """ Returns a the first folder with a matching name. From 0892a976fd47b6f49b1ec7ddd008068ae821c3d8 Mon Sep 17 00:00:00 2001 From: Christopher McCarthy Date: Mon, 4 Sep 2023 18:37:05 +0000 Subject: [PATCH 146/980] Apply suggestions from code review --- src/primaite/simulator/file_system/file_system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index e9385644..79159e60 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -1,5 +1,5 @@ from random import choice -from typing import Dict, Optional, Union +from typing import Dict, Optional from primaite import getLogger from primaite.simulator.core import SimComponent From 2b68ed813c595576ff8dc091fdd8f60796467490 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 5 Sep 2023 14:51:04 +0100 Subject: [PATCH 147/980] Make actions more recursive --- src/primaite/simulator/core.py | 39 ++++++++++++++++--- src/primaite/simulator/domain/controller.py | 10 +---- src/primaite/simulator/network/container.py | 8 ++-- .../simulator/network/hardware/base.py | 1 - src/primaite/simulator/sim_container.py | 14 +------ 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index c38a7e2f..e8cd4b98 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -48,6 +48,9 @@ class Action(BaseModel): that invokes a class method of your SimComponent. For example if the component is a node and the action is for turning it off, then the SimComponent should have a turn_off(self) method that does not need to accept any args. Then, this Action will be given something like ``func = lambda request, context: self.turn_off()``. + + ``func`` can also be another action manager, since ActionManager is a callable with a signature that matches what is + expected by ``func``. """ validator: ActionPermissionValidator = AllowAllValidator() """ @@ -68,8 +71,9 @@ class ActionManager(BaseModel): actions: Dict[str, Action] = {} """maps action verb to an action object.""" - def process_request(self, request: List[str], context: Dict) -> None: - """Process an action request. + def __call__(self, request: List[str], context: Dict) -> None: + """ + Process an action request. :param request: A list of strings which specify what action to take. The first string must be one of the allowed actions, i.e. it must be a key of self.actions. The subsequent strings in the list are passed as parameters @@ -99,7 +103,8 @@ class ActionManager(BaseModel): action.func(action_options, context) def add_action(self, name: str, action: Action) -> None: - """Add an action to this action manager. + """ + Add an action to this action manager. :param name: The string associated to this action. :type name: str @@ -113,10 +118,32 @@ class ActionManager(BaseModel): self.actions[name] = action - def list_actions(self) -> List[List[str]]: + def remove_action(self, name: str) -> None: + """ + Remove an action from this manager. + + :param name: name identifier of the action + :type name: str + """ + if name not in self.actions: + msg = f"Attempted to remove action {name} from action manager, but it was not registered." + _LOGGER.error(msg) + raise RuntimeError(msg) + + self.actions.pop(name) + + + def get_action_tree(self) -> List[List[str]]: + """Recursively generate action tree for this component.""" actions = [] for act_name, act in self.actions.items(): - pass # TODO: + if isinstance(act.func, ActionManager): + sub_actions = act.func.get_action_tree() + sub_actions = [[act_name]+a for a in sub_actions] + actions.extend(sub_actions) + else: + actions.append([act_name]) + return actions class SimComponent(BaseModel): @@ -196,7 +223,7 @@ class SimComponent(BaseModel): """ if self.action_manager is None: return - self.action_manager.process_request(action, context) + self.action_manager(action, context) def apply_timestep(self, timestep: int) -> None: """ diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index b436ca79..cd0fe9de 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -46,13 +46,7 @@ class AccountGroup(Enum): class GroupMembershipValidator(ActionPermissionValidator): """Permit actions based on group membership.""" - def __init__(self, allowed_groups: List[AccountGroup]) -> None: - """Store a list of groups that should be granted permission. - - :param allowed_groups: List of AccountGroups that are permitted to perform some action. - :type allowed_groups: List[AccountGroup] - """ - self.allowed_groups = allowed_groups + allowed_groups:List[AccountGroup] def __call__(self, request: List[str], context: Dict) -> bool: """Permit the action if the request comes from an account which belongs to the right group.""" @@ -93,7 +87,7 @@ class DomainController(SimComponent): "account", Action( func=lambda request, context: self.accounts[request.pop(0)].apply_action(request, context), - validator=GroupMembershipValidator([AccountGroup.DOMAIN_ADMIN]), + validator=GroupMembershipValidator(allowed_groups=[AccountGroup.DOMAIN_ADMIN]), ), ) return am diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 4d1afe72..1c7bbec7 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -43,12 +43,12 @@ class Network(SimComponent): def _init_action_manager(self) -> ActionManager: am = super()._init_action_manager() - + self._node_action_manager = ActionManager() am.add_action( "node", Action( - func=lambda request, context: self.nodes[request.pop(0)].apply_action(request, context), - validator=AllowAllValidator(), + func = self._node_action_manager + # func=lambda request, context: self.nodes[request.pop(0)].apply_action(request, context), ), ) return am @@ -182,6 +182,7 @@ class Network(SimComponent): node.parent = self self._nx_graph.add_node(node.hostname) _LOGGER.info(f"Added node {node.uuid} to Network {self.uuid}") + self._node_action_manager.add_action(name = node.uuid, action = Action(func=node._action_manager)) def get_node_by_hostname(self, hostname: str) -> Optional[Node]: """ @@ -211,6 +212,7 @@ class Network(SimComponent): self.nodes.pop(node.uuid) node.parent = None _LOGGER.info(f"Removed node {node.uuid} from network {self.uuid}") + self._node_action_manager.remove_action(name = node.uuid) def connect(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> None: """ diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 101d6b72..a846f7e2 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -135,7 +135,6 @@ class NIC(SimComponent): { "ip_adress": str(self.ip_address), "subnet_mask": str(self.subnet_mask), - "gateway": str(self.gateway), "mac_address": self.mac_address, "speed": self.speed, "mtu": self.mtu, diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index 2a5123f3..d647b0bc 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -24,19 +24,9 @@ class Simulation(SimComponent): def _init_action_manager(self) -> ActionManager: am = super()._init_action_manager() # pass through network actions to the network objects - am.add_action( - "network", - Action( - func=lambda request, context: self.network.apply_action(request, context), validator=AllowAllValidator() - ), - ) + am.add_action("network", Action(func=self.network._action_manager)) # pass through domain actions to the domain object - am.add_action( - "domain", - Action( - func=lambda request, context: self.domain.apply_action(request, context), validator=AllowAllValidator() - ), - ) + am.add_action("domain", Action(func=self.domain._action_manager)) return am def describe_state(self) -> Dict: From ffe1e92664b341e9f74b54f4ffd5db1b4e28d787 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 5 Sep 2023 14:51:25 +0100 Subject: [PATCH 148/980] Make actions more recursive --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ff86b65f..77e74e17 100644 --- a/.gitignore +++ b/.gitignore @@ -151,3 +151,4 @@ src/primaite/outputs/ # benchmark session outputs benchmark/output src/primaite/notebooks/scratch.ipynb +src/primaite/notebooks/scratch.py From 1dccceaf5695a7d025f985ec9f34219143790c2e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 5 Sep 2023 15:53:22 +0100 Subject: [PATCH 149/980] Verify that action tree is starting to work! --- src/primaite/simulator/core.py | 6 ++-- .../simulator/network/hardware/base.py | 32 ++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index e8cd4b98..f6c0b5d9 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -60,6 +60,9 @@ class Action(BaseModel): """ +# TODO: maybe this can be renamed to something like action selector? +# Because there are two ways it's used, to select from a list of action verbs, or to select a child object to which to +# forward the request. class ActionManager(BaseModel): """ ActionManager is used by `SimComponent` instances to keep track of actions. @@ -132,14 +135,13 @@ class ActionManager(BaseModel): self.actions.pop(name) - def get_action_tree(self) -> List[List[str]]: """Recursively generate action tree for this component.""" actions = [] for act_name, act in self.actions.items(): if isinstance(act.func, ActionManager): sub_actions = act.func.get_action_tree() - sub_actions = [[act_name]+a for a in sub_actions] + sub_actions = [[act_name] + a for a in sub_actions] actions.extend(sub_actions) else: actions.append([act_name]) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index a846f7e2..e5f16323 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -10,7 +10,7 @@ from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.exceptions import NetworkError -from primaite.simulator.core import SimComponent +from primaite.simulator.core import Action, ActionManager, SimComponent from primaite.simulator.domain.account import Account from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket @@ -145,6 +145,14 @@ class NIC(SimComponent): ) return state + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + + am.add_action("enable", Action(func=lambda request, context: self.enable())) + am.add_action("disable", Action(func=lambda request, context: self.disable())) + + return am + @property def ip_network(self) -> IPv4Network: """ @@ -925,6 +933,24 @@ class Node(SimComponent): super().__init__(**kwargs) self.arp.nics = self.nics + def _init_action_manager(self) -> ActionManager: + # TODO: I see that this code is really confusing and hard to read right now... I think some of these things will + # need a better name and better documentation. + am = super()._init_action_manager() + # since there are potentially many services, create an action manager that can map service name + self._service_action_manager = ActionManager() + am.add_action("service", Action(func=self._service_action_manager)) + self._process_action_manager = ActionManager() + am.add_action("process", Action(func=self._process_action_manager)) + self._application_action_manager = ActionManager() + am.add_action("application", Action(func=self._application_action_manager)) + self._nic_action_manager = ActionManager() + am.add_action("nic", Action(func=self._nic_action_manager)) + + am.add_action("file_system", Action(func=self.file_system._action_manager)) + + return am + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -1000,6 +1026,7 @@ class Node(SimComponent): self.sys_log.info(f"Connected NIC {nic}") if self.operating_state == NodeOperatingState.ON: nic.enable() + self._nic_action_manager.add_action(nic.uuid, Action(func=nic._action_manager)) else: msg = f"Cannot connect NIC {nic} as it is already connected" self.sys_log.logger.error(msg) @@ -1024,6 +1051,7 @@ class Node(SimComponent): nic.parent = None nic.disable() self.sys_log.info(f"Disconnected NIC {nic}") + self._nic_action_manager.remove_action(nic.uuid) else: msg = f"Cannot disconnect NIC {nic} as it is not connected" self.sys_log.logger.error(msg) @@ -1110,6 +1138,7 @@ class Node(SimComponent): service.install() # Perform any additional setup, such as creating files for this service on the node. self.sys_log.info(f"Installed service {service.name}") _LOGGER.info(f"Added service {service.uuid} to node {self.uuid}") + self._service_action_manager.add_action(service.uuid, Action(func=service._action_manager)) def uninstall_service(self, service: Service) -> None: """Uninstall and completely remove service from this node. @@ -1125,6 +1154,7 @@ class Node(SimComponent): service.parent = None self.sys_log.info(f"Uninstalled service {service.name}") _LOGGER.info(f"Removed service {service.uuid} from node {self.uuid}") + self._service_action_manager.remove_action(service.uuid) def __contains__(self, item: Any) -> bool: if isinstance(item, Service): From c349bb4484dfa39a434e9bb076528b516b6a96d9 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 5 Sep 2023 17:14:47 +0100 Subject: [PATCH 150/980] #1814: initial implementation of data manipulator service --- .../network/transmission/transport_layer.py | 2 + .../simulator/system/core/session_manager.py | 95 +++++++++++++++---- .../simulator/system/core/software_manager.py | 51 ++++++++-- .../red_services/data_manipulator_service.py | 28 ++++++ .../simulator/system/services/service.py | 4 +- src/primaite/simulator/system/software.py | 18 ++-- .../system/test_database_on_node.py | 8 +- .../_system/_services/test_database.py | 4 +- 8 files changed, 163 insertions(+), 47 deletions(-) create mode 100644 src/primaite/simulator/system/services/red_services/data_manipulator_service.py diff --git a/src/primaite/simulator/network/transmission/transport_layer.py b/src/primaite/simulator/network/transmission/transport_layer.py index b95b4a74..d4318baf 100644 --- a/src/primaite/simulator/network/transmission/transport_layer.py +++ b/src/primaite/simulator/network/transmission/transport_layer.py @@ -59,6 +59,8 @@ class Port(Enum): "Alternative port for HTTP (HTTP_ALT) - Often used as an alternative HTTP port for web applications." HTTPS_ALT = 8443 "Alternative port for HTTPS (HTTPS_ALT) - Used in some configurations for secure web traffic." + POSTGRES_SERVER = 5432 + "Postgres SQL Server." class UDPHeader(BaseModel): diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 7f3d22c5..be20a28d 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -1,12 +1,14 @@ from __future__ import annotations from ipaddress import IPv4Address -from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING +from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING, Union + +from prettytable import MARKDOWN, PrettyTable from primaite.simulator.core import SimComponent -from primaite.simulator.network.transmission.data_link_layer import Frame -from primaite.simulator.network.transmission.network_layer import IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame +from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader if TYPE_CHECKING: from primaite.simulator.network.hardware.base import ARPCache @@ -135,7 +137,14 @@ class SessionManager: dst_port = None return protocol, src_ip_address, dst_ip_address, src_port, dst_port - def receive_payload_from_software_manager(self, payload: Any, session_id: Optional[int] = None): + def receive_payload_from_software_manager( + self, + payload: Any, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + session_id: Optional[str] = None, + is_reattempt: bool = False, + ) -> Union[Any, None]: """ Receive a payload from the SoftwareManager. @@ -144,9 +153,50 @@ class SessionManager: :param payload: The payload to be sent. :param session_id: The Session ID the payload is to originate from. Optional. If None, one will be created. """ - # TODO: Implement session creation and + if session_id: + dest_ip_address = self.sessions_by_uuid[session_id].dst_ip_address + dest_port = self.sessions_by_uuid[session_id].dst_port - self.send_payload_to_nic(payload, session_id) + dst_mac_address = self.arp_cache.get_arp_cache_mac_address(dest_ip_address) + + if dst_mac_address: + outbound_nic = self.arp_cache.get_arp_cache_nic(dest_ip_address) + else: + if not is_reattempt: + self.arp_cache.send_arp_request(dest_ip_address) + return self.receive_payload_from_software_manager( + payload=payload, + dest_ip_address=dest_ip_address, + dest_port=dest_port, + session_id=session_id, + is_reattempt=True, + ) + else: + return + + frame = Frame( + ethernet=EthernetHeader(src_mac_addr=outbound_nic.mac_address, dst_mac_addr=dst_mac_address), + ip=IPPacket( + src_ip_address=outbound_nic.ip_address, + dst_ip_address=dest_ip_address, + ), + tcp=TCPHeader( + src_port=dest_port, + dst_port=dest_port, + ), + payload=payload, + ) + + if not session_id: + session_key = self._get_session_key(frame, from_source=True) + session = self.sessions_by_key.get(session_key) + if not session: + # Create new session + session = Session.from_session_key(session_key) + self.sessions_by_key[session_key] = session + self.sessions_by_uuid[session.uuid] = session + + outbound_nic.send_frame(frame) def send_payload_to_software_manager(self, payload: Any, session_id: int): """ @@ -157,18 +207,6 @@ class SessionManager: """ self.software_manager.receive_payload_from_session_manger() - def send_payload_to_nic(self, payload: Any, session_id: int): - """ - Send a payload across the Network. - - Takes a payload and a session_id. Builds a Frame and sends it across the network via a NIC. - - :param payload: The payload to be sent. - :param session_id: The Session ID the payload originates from - """ - # TODO: Implement frame construction and sent to NIC. - pass - def receive_payload_from_nic(self, frame: Frame): """ Receive a Frame from the NIC. @@ -187,3 +225,22 @@ class SessionManager: self.sessions_by_uuid[session.uuid] = session self.software_manager.receive_payload_from_session_manger(payload=frame, session=session) # TODO: Implement the frame deconstruction and send to SoftwareManager. + + def show(self, markdown: bool = False): + """ + Print tables describing the SessionManager. + + Generate and print PrettyTable instances that show details about + session's destination IP Address, destination Ports and the protocol to use. + Output can be in Markdown format. + + :param markdown: Use Markdown style in table output. Defaults to False. + """ + table = PrettyTable(["Destination IP", "Port", "Protocol"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"{self.sys_log.hostname} Session Manager" + for session in self.sessions_by_key.values(): + table.add_row([session.dst_ip_address, session.dst_port.value, session.protocol.name]) + print(table) diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index 411fb6e9..312f6d84 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -1,5 +1,8 @@ +from ipaddress import IPv4Address from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING, Union +from prettytable import MARKDOWN, PrettyTable + from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application @@ -12,6 +15,10 @@ if TYPE_CHECKING: from primaite.simulator.system.core.session_manager import SessionManager from primaite.simulator.system.core.sys_log import SysLog +from typing import Type, TypeVar + +ServiceClass = TypeVar("ServiceClass", bound=Service) + class SoftwareManager: """A class that manages all running Services and Applications on a Node and facilitates their communication.""" @@ -28,18 +35,17 @@ class SoftwareManager: self.port_protocol_mapping: Dict[Tuple[Port, IPProtocol], Union[Service, Application]] = {} self.sys_log: SysLog = sys_log - def add_service(self, name: str, service: Service, port: Port, protocol: IPProtocol): + def add_service(self, service_class: Type[ServiceClass]): """ Add a Service to the manager. - :param name: The name of the service. - :param service: The service instance. - :param port: The port used by the service. - :param protocol: The network protocol used by the service. + :param service_class: The class of the service to add """ + service = service_class(software_manager=self, sys_log=self.sys_log) + service.software_manager = self - self.services[name] = service - self.port_protocol_mapping[(port, protocol)] = service + self.services[service.name] = service + self.port_protocol_mapping[(service.port, service.protocol)] = service def add_application(self, name: str, application: Application, port: Port, protocol: IPProtocol): """ @@ -75,14 +81,24 @@ class SoftwareManager: else: raise ValueError(f"No {target_software_type.name.lower()} found with the name {target_software}") - def send_payload_to_session_manger(self, payload: Any, session_id: Optional[int] = None): + def send_payload_to_session_manager( + self, + payload: Any, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + session_id: Optional[int] = None, + ): """ Send a payload to the SessionManager. :param payload: The payload to be sent. + :param dest_ip_address: The ip address of the payload destination. + :param dest_port: The port of the payload destination. :param session_id: The Session ID the payload is to originate from. Optional. """ - self.session_manager.receive_payload_from_software_manager(payload, session_id) + self.session_manager.receive_payload_from_software_manager( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id + ) def receive_payload_from_session_manger(self, payload: Any, session: Session): """ @@ -97,3 +113,20 @@ class SoftwareManager: # else: # raise ValueError(f"No service or application found for port {port} and protocol {protocol}") pass + + def show(self, markdown: bool = False): + """ + Prints a table of the SwitchPorts on the Switch. + + :param markdown: If True, outputs the table in markdown format. Default is False. + """ + table = PrettyTable(["Name", "Operating State", "Health State", "Port"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"{self.sys_log.hostname} Software Manager" + for service in self.services.values(): + table.add_row( + [service.name, service.operating_state.name, service.health_state_actual.name, service.port.value] + ) + print(table) diff --git a/src/primaite/simulator/system/services/red_services/data_manipulator_service.py b/src/primaite/simulator/system/services/red_services/data_manipulator_service.py new file mode 100644 index 00000000..29f0d3f8 --- /dev/null +++ b/src/primaite/simulator/system/services/red_services/data_manipulator_service.py @@ -0,0 +1,28 @@ +from ipaddress import IPv4Address + +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.software_manager import SoftwareManager +from primaite.simulator.system.services.service import Service + + +class DataManipulatorService(Service): + """ + Red Agent Data Integration Service. + + The Service represents a bot that causes files/folders in the File System to + become corrupted. + """ + + def __init__(self, **kwargs): + kwargs["name"] = "DataManipulatorBot" + kwargs["port"] = Port.POSTGRES_SERVER + kwargs["protocol"] = IPProtocol.TCP + super().__init__(**kwargs) + + def run(self): + """Run the DataManipulatorService actions.""" + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager( + payload="SELECT * FROM users", dest_ip_address=IPv4Address("192.168.1.14"), dest_port=self.port + ) diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index f9cc784d..6a8c9abf 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,4 +1,3 @@ -from abc import abstractmethod from enum import Enum from typing import Any, Dict, Optional @@ -33,7 +32,7 @@ class Service(IOSoftware): Services are programs that run in the background and may perform input/output operations. """ - operating_state: ServiceOperatingState + operating_state: ServiceOperatingState = ServiceOperatingState.STOPPED "The current operating state of the Service." restart_duration: int = 5 "How many timesteps does it take to restart this service." @@ -51,7 +50,6 @@ class Service(IOSoftware): am.add_action("enable", Action(func=lambda request, context: self.enable())) return am - @abstractmethod def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 605a062b..7f206311 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -1,9 +1,10 @@ from abc import abstractmethod from enum import Enum -from typing import Any, Dict, Set +from typing import Any, Dict from primaite.simulator.core import Action, ActionManager, SimComponent from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.sys_log import SysLog class SoftwareType(Enum): @@ -62,11 +63,11 @@ class Software(SimComponent): name: str "The name of the software." - health_state_actual: SoftwareHealthState + health_state_actual: SoftwareHealthState = SoftwareHealthState.GOOD "The actual health state of the software." - health_state_visible: SoftwareHealthState + health_state_visible: SoftwareHealthState = SoftwareHealthState.GOOD "The health state of the software visible to the red agent." - criticality: SoftwareCriticality + criticality: SoftwareCriticality = SoftwareCriticality.LOWEST "The criticality level of the software." patching_count: int = 0 "The count of patches applied to the software, defaults to 0." @@ -74,6 +75,10 @@ class Software(SimComponent): "The count of times the software has been scanned, defaults to 0." revealed_to_red: bool = False "Indicates if the software has been revealed to red agent, defaults is False." + software_manager: Any = None + "An instance of Software Manager that is used by the parent node." + sys_log: SysLog = None + "An instance of SysLog that is used by the parent node." def _init_action_manager(self) -> ActionManager: am = super()._init_action_manager() @@ -132,7 +137,6 @@ class Software(SimComponent): """ self.health_state_actual = health_state - @abstractmethod def install(self) -> None: """ Perform first-time setup of this service on a node. @@ -175,8 +179,8 @@ class IOSoftware(Software): "Indicates if the software uses TCP protocol for communication. Default is True." udp: bool = True "Indicates if the software uses UDP protocol for communication. Default is True." - ports: Set[Port] - "The set of ports to which the software is connected." + port: Port + "The port to which the software is connected." @abstractmethod def describe_state(self) -> Dict: diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 73d19339..058bb590 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -11,9 +11,7 @@ def test_installing_database(): health_state_actual=SoftwareHealthState.GOOD, health_state_visible=SoftwareHealthState.GOOD, criticality=SoftwareCriticality.MEDIUM, - ports=[ - Port.SQL_SERVER, - ], + port=Port.SQL_SERVER, operating_state=ServiceOperatingState.RUNNING, ) @@ -40,9 +38,7 @@ def test_uninstalling_database(): health_state_actual=SoftwareHealthState.GOOD, health_state_visible=SoftwareHealthState.GOOD, criticality=SoftwareCriticality.MEDIUM, - ports=[ - Port.SQL_SERVER, - ], + port=Port.SQL_SERVER, operating_state=ServiceOperatingState.RUNNING, ) diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py index ea5c1b83..ebc5536f 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py @@ -10,8 +10,6 @@ def test_creation(): health_state_actual=SoftwareHealthState.GOOD, health_state_visible=SoftwareHealthState.GOOD, criticality=SoftwareCriticality.MEDIUM, - ports=[ - Port.SQL_SERVER, - ], + port=Port.SQL_SERVER, operating_state=ServiceOperatingState.RUNNING, ) From d503e51c2ddc9945d20de5d487552b21719c8797 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 6 Sep 2023 11:12:03 +0100 Subject: [PATCH 151/980] #1814: Remove hardcoded values + added test + remove unnecessary private parent attribute --- src/primaite/simulator/core.py | 25 ++------------- .../simulator/system/core/software_manager.py | 2 +- .../red_services/data_manipulator_service.py | 18 +++++++---- .../simulator/system/services/service.py | 16 +++++----- .../_services/_red_services/__init__.py | 0 .../test_data_manipulator_service.py | 32 +++++++++++++++++++ 6 files changed, 55 insertions(+), 38 deletions(-) create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/__init__.py create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 5ae7b492..32db95c6 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -1,6 +1,6 @@ """Core of the PrimAITE Simulator.""" from abc import ABC, abstractmethod -from typing import Callable, Dict, List, Optional, Union +from typing import Callable, Dict, List, Optional from uuid import uuid4 from pydantic import BaseModel, ConfigDict @@ -140,7 +140,7 @@ class SimComponent(BaseModel): kwargs["uuid"] = str(uuid4()) super().__init__(**kwargs) self._action_manager: ActionManager = self._init_action_manager() - self._parent: Optional["SimComponent"] = None + self.parent: Optional["SimComponent"] = None def _init_action_manager(self) -> ActionManager: """ @@ -213,24 +213,3 @@ class SimComponent(BaseModel): Override this method with anything that needs to happen within the component for it to be reset. """ pass - - @property - def parent(self) -> "SimComponent": - """Reference to the parent object which manages this object. - - :return: Parent object. - :rtype: SimComponent - """ - return self._parent - - @parent.setter - def parent(self, new_parent: Union["SimComponent", None]) -> None: - if self._parent and new_parent: - msg = f"Overwriting parent of {self.uuid}. Old parent: {self._parent.uuid}, New parent: {new_parent.uuid}" - _LOGGER.warn(msg) - raise RuntimeWarning(msg) - self._parent = new_parent - - @parent.deleter - def parent(self) -> None: - self._parent = None diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index 312f6d84..28e37963 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -39,7 +39,7 @@ class SoftwareManager: """ Add a Service to the manager. - :param service_class: The class of the service to add + :param: service_class: The class of the service to add """ service = service_class(software_manager=self, sys_log=self.sys_log) diff --git a/src/primaite/simulator/system/services/red_services/data_manipulator_service.py b/src/primaite/simulator/system/services/red_services/data_manipulator_service.py index 29f0d3f8..82b9aa1c 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulator_service.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulator_service.py @@ -1,8 +1,8 @@ from ipaddress import IPv4Address +from typing import Any, Optional from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.services.service import Service @@ -20,9 +20,15 @@ class DataManipulatorService(Service): kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) - def run(self): - """Run the DataManipulatorService actions.""" - software_manager: SoftwareManager = self.software_manager - software_manager.send_payload_to_session_manager( - payload="SELECT * FROM users", dest_ip_address=IPv4Address("192.168.1.14"), dest_port=self.port + def start(self, target_ip_address: IPv4Address, payload: Optional[Any] = "DELETE TABLE users", **kwargs): + """ + Run the DataManipulatorService actions. + + :param: target_ip_address: The IP address of the target machine to attack + :param: payload: The payload to send to the target machine + """ + super().start() + + self.software_manager.send_payload_to_session_manager( + payload=payload, dest_ip_address=target_ip_address, dest_port=self.port ) diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 6a8c9abf..b9340103 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -100,49 +100,49 @@ class Service(IOSoftware): """Stop the service.""" _LOGGER.debug(f"Stopping service {self.name}") if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: - self.parent.sys_log.info(f"Stopping service {self.name}") + self.sys_log.info(f"Stopping service {self.name}") self.operating_state = ServiceOperatingState.STOPPED - def start(self) -> None: + def start(self, **kwargs) -> None: """Start the service.""" _LOGGER.debug(f"Starting service {self.name}") if self.operating_state == ServiceOperatingState.STOPPED: - self.parent.sys_log.info(f"Starting service {self.name}") + self.sys_log.info(f"Starting service {self.name}") self.operating_state = ServiceOperatingState.RUNNING def pause(self) -> None: """Pause the service.""" _LOGGER.debug(f"Pausing service {self.name}") if self.operating_state == ServiceOperatingState.RUNNING: - self.parent.sys_log.info(f"Pausing service {self.name}") + self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.PAUSED def resume(self) -> None: """Resume paused service.""" _LOGGER.debug(f"Resuming service {self.name}") if self.operating_state == ServiceOperatingState.PAUSED: - self.parent.sys_log.info(f"Resuming service {self.name}") + self.sys_log.info(f"Resuming service {self.name}") self.operating_state = ServiceOperatingState.RUNNING def restart(self) -> None: """Restart running service.""" _LOGGER.debug(f"Restarting service {self.name}") if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: - self.parent.sys_log.info(f"Pausing service {self.name}") + self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.RESTARTING self.restart_countdown = self.restarting_duration def disable(self) -> None: """Disable the service.""" _LOGGER.debug(f"Disabling service {self.name}") - self.parent.sys_log.info(f"Disabling Application {self.name}") + self.sys_log.info(f"Disabling Application {self.name}") self.operating_state = ServiceOperatingState.DISABLED def enable(self) -> None: """Enable the disabled service.""" _LOGGER.debug(f"Enabling service {self.name}") if self.operating_state == ServiceOperatingState.DISABLED: - self.parent.sys_log.info(f"Enabling Application {self.name}") + self.sys_log.info(f"Enabling Application {self.name}") self.operating_state = ServiceOperatingState.STOPPED def apply_timestep(self, timestep: int) -> None: diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/__init__.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py new file mode 100644 index 00000000..f5b37175 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py @@ -0,0 +1,32 @@ +from ipaddress import IPv4Address + +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.networks import arcd_uc2_network +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.red_services.data_manipulator_service import DataManipulatorService + + +def test_creation(): + network = arcd_uc2_network() + + client_1: Node = network.get_node_by_hostname("client_1") + + client_1.software_manager.add_service(service_class=DataManipulatorService) + + data_manipulator_service: DataManipulatorService = client_1.software_manager.services["DataManipulatorBot"] + + assert data_manipulator_service.name == "DataManipulatorBot" + assert data_manipulator_service.port == Port.POSTGRES_SERVER + assert data_manipulator_service.protocol == IPProtocol.TCP + + # should have no session yet + assert len(client_1.session_manager.sessions_by_uuid) == 0 + + try: + data_manipulator_service.start(target_ip_address=IPv4Address("192.168.1.14")) + except Exception as e: + assert False, f"Test was not supposed to throw exception: {e}" + + # there should be a session after the service is started + assert len(client_1.session_manager.sessions_by_uuid) == 1 From 597c7664bc7027566a1a8d0339c536de72a223e4 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 6 Sep 2023 11:19:30 +0100 Subject: [PATCH 152/980] #1814: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f2918aa..14a53d73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ SessionManager. - File System - ability to emulate a node's file system during a simulation - Example notebooks - There is currently 1 jupyter notebook which walks through using PrimAITE 1. Creating a simulation - this notebook explains how to build up a simulation using the Python package. (WIP) +- Red Agent Services: + - Data Manipulator Bot - A red agent service which sends a payload to a target machine. (By default this payload is a SQL query that breaks a database) ## [2.0.0] - 2023-07-26 From 7c157d27d7858981a533c9eae32ab8276ffb50ed Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 6 Sep 2023 11:35:41 +0100 Subject: [PATCH 153/980] #1800 - Simplified a bunch of stuff in the file system in prep for services and applications. Started adding the database logic. Waiting for the software manager/session manager work from another ticket. --- src/primaite/simulator/__init__.py | 11 +- .../create-simulation_demo.ipynb | 10 +- .../simulator/file_system/file_system.py | 573 ++++++++++++------ .../simulator/file_system/file_system_file.py | 55 -- .../file_system/file_system_file_type.py | 132 ---- .../file_system/file_system_folder.py | 87 --- .../file_system/file_system_item_abc.py | 31 - .../simulator/network/hardware/base.py | 8 +- .../simulator/system/core/packet_capture.py | 4 +- src/primaite/simulator/system/core/sys_log.py | 4 +- .../simulator/system/services/database.py | 26 +- .../system/test_database_on_node.py | 2 +- .../_file_system/test_file_system.py | 177 +++--- .../_file_system/test_file_system_file.py | 16 +- .../_file_system/test_file_system_folder.py | 32 +- 15 files changed, 540 insertions(+), 628 deletions(-) delete mode 100644 src/primaite/simulator/file_system/file_system_file.py delete mode 100644 src/primaite/simulator/file_system/file_system_file_type.py delete mode 100644 src/primaite/simulator/file_system/file_system_folder.py delete mode 100644 src/primaite/simulator/file_system/file_system_item_abc.py diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index 1cfe7f49..8c55542f 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -1,5 +1,14 @@ +from datetime import datetime + from primaite import _PRIMAITE_ROOT -TEMP_SIM_OUTPUT = _PRIMAITE_ROOT.parent.parent / "simulation_output" +SIM_OUTPUT = None "A path at the repo root dir to use temporarily for sim output testing while in dev." # TODO: Remove once we integrate the simulation into PrimAITE and it uses the primaite session path + +if not SIM_OUTPUT: + session_timestamp = datetime.now() + date_dir = session_timestamp.strftime("%Y-%m-%d") + sim_path = session_timestamp.strftime("%Y-%m-%d_%H-%M-%S") + SIM_OUTPUT = _PRIMAITE_ROOT.parent.parent / "simulation_output" / date_dir / sim_path + SIM_OUTPUT.mkdir(exist_ok=True, parents=True) diff --git a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb index baf7bd2c..a2e1550c 100644 --- a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb +++ b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb @@ -149,8 +149,8 @@ "metadata": {}, "outputs": [], "source": [ - "from primaite.simulator.file_system.file_system_file_type import FileSystemFileType\n", - "from primaite.simulator.file_system.file_system_file import FileSystemFile" + "from primaite.simulator.file_system.file_type import FileType\n", + "from primaite.simulator.file_system.file_system import File" ] }, { @@ -160,7 +160,7 @@ "outputs": [], "source": [ "my_pc_downloads_folder = my_pc.file_system.create_folder(\"downloads\")\n", - "my_pc_downloads_folder.add_file(FileSystemFile(name=\"firefox_installer.zip\",file_type=FileSystemFileType.ZIP))" + "my_pc_downloads_folder.add_file(File(name=\"firefox_installer.zip\",file_type=FileType.ZIP))" ] }, { @@ -171,7 +171,7 @@ { "data": { "text/plain": [ - "FileSystemFile(uuid='7d56a563-ecc0-4011-8c97-240dd6c885c0', name='favicon.ico', size=40.0, file_type=, action_manager=None)" + "File(uuid='7d56a563-ecc0-4011-8c97-240dd6c885c0', name='favicon.ico', size=40.0, file_type=, action_manager=None)" ] }, "execution_count": 9, @@ -181,7 +181,7 @@ ], "source": [ "my_server_folder = my_server.file_system.create_folder(\"static\")\n", - "my_server.file_system.create_file(\"favicon.ico\", file_type=FileSystemFileType.PNG)" + "my_server.file_system.create_file(\"favicon.ico\", file_type=FileType.PNG)" ] }, { diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 79159e60..a5744b4b 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -1,242 +1,441 @@ -from random import choice +from __future__ import annotations + +import math +import os.path +from abc import abstractmethod +from pathlib import Path from typing import Dict, Optional +from prettytable import MARKDOWN, PrettyTable + from primaite import getLogger from primaite.simulator.core import SimComponent -from primaite.simulator.file_system.file_system_file import FileSystemFile -from primaite.simulator.file_system.file_system_file_type import FileSystemFileType -from primaite.simulator.file_system.file_system_folder import FileSystemFolder +from primaite.simulator.file_system.file_type import FileType, get_file_type_from_extension +from primaite.simulator.system.core.sys_log import SysLog _LOGGER = getLogger(__name__) -class FileSystem(SimComponent): - """Class that contains all the simulation File System.""" +def convert_size(size_bytes): + """ + Convert a file size from bytes to a string with a more human-readable format. - folders: Dict[str, FileSystemFolder] = {} - """List containing all the folders in the file system.""" + This function takes the size of a file in bytes and converts it to a string representation with appropriate size + units (B, KB, MB, GB, etc.). + + :param size_bytes: The size of the file in bytes. + :return: The human-readable string representation of the file size. + """ + if size_bytes == 0: + return "0 B" + + # Tuple of size units starting from Bytes up to Yottabytes + size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") + + # Calculate the index (i) that will be used to select the appropriate size unit from size_name + i = int(math.floor(math.log(size_bytes, 1024))) + + # Calculate the adjusted size value (s) in terms of the new size unit + p = math.pow(1024, i) + s = round(size_bytes / p, 2) + + return f"{s} {size_name[i]}" + + +class FileSystemItemABC(SimComponent): + """Abstract base class for file system items used in the file system simulation.""" + + name: str + "The name of the FileSystemItemABC." def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. - Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - :return: Current state of this object and child objects. - :rtype: Dict """ state = super().describe_state() - state.update({"folders": {uuid: folder.describe_state() for uuid, folder in self.folders.items()}}) + state.update( + { + "name": self.name, + } + ) return state - def get_folders(self) -> Dict: - """Returns the list of folders.""" - return self.folders + @property + def size_str(self): + return convert_size(self.size) + + +class FileSystem(SimComponent): + """Class that contains all the simulation File System.""" + + folders: Dict[str, Folder] = {} + "List containing all the folders in the file system." + _folders_by_name: Dict[str, Folder] = {} + sys_log: SysLog + sim_root: Path + + def __init__(self, **kwargs): + super().__init__(**kwargs) + # Ensure a default root folder + if not self.folders: + self.create_folder("root") + + @property + def size(self): + return sum(folder.size for folder in self.folders.values()) + + def show(self, markdown: bool = False, full: bool = False): + """Prints a of the FileSystem""" + headers = ["Folder", "Size"] + if full: + headers[0] = "File Path" + table = PrettyTable(headers) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"{self.sys_log.hostname} File System" + for folder in self.folders.values(): + if not full: + table.add_row([folder.name, folder.size_str]) + else: + for file in folder.files.values(): + table.add_row([file.path, file.size_str]) + if full: + print(table.get_string(sortby="File Path")) + else: + print(table.get_string(sortby="Folder")) + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + """ + state = super().describe_state() + state["folders"] = {folder.name: folder.describe_state() for folder in self.folders.values()} + return state + + def create_folder(self, folder_name: str) -> Folder: + """ + Creates a Folder and adds it to the list of folders. + + :param folder_name: The name of the folder. + """ + # check if folder with name already exists + if self.get_folder(folder_name): + raise Exception(f"Cannot create folder as it already exists: {folder_name}") + + folder = Folder(name=folder_name, fs=self) + + self.folders[folder.uuid] = folder + self._folders_by_name[folder.name] = folder + self.sys_log.info(f"Created folder /{folder.name}") + return folder + + def delete_folder(self, folder_name: str): + """ + Deletes a folder, removes it from the folders list and removes any child folders and files. + + :param folder_name: The name of the folder. + """ + if folder_name == "root": + self.sys_log.warning("Cannot delete the root folder.") + return + folder = self._folders_by_name.get(folder_name) + if folder: + for file in folder.files.values(): + self.delete_file(file) + self.folders.pop(folder.uuid) + self._folders_by_name.pop(folder.name) + self.sys_log.info(f"Deleted folder /{folder.name} and its contents") + else: + _LOGGER.debug(f"Cannot delete folder as it does not exist: {folder_name}") def create_file( self, file_name: str, - size: Optional[float] = None, - file_type: Optional[FileSystemFileType] = None, - folder: Optional[FileSystemFolder] = None, - folder_uuid: Optional[str] = None, - ) -> FileSystemFile: + size: Optional[int] = None, + file_type: Optional[FileType] = None, + folder_name: Optional[str] = None, + real: bool = False, + ) -> File: """ - Creates a FileSystemFile and adds it to the list of files. + Creates a File and adds it to the list of files. - If no size or file_type are provided, one will be chosen randomly. - If no folder_uuid or folder is provided, a new folder will be created. - - :param: file_name: The file name - :type: file_name: str - - :param: size: The size the file takes on disk. - :type: size: Optional[float] - - :param: file_type: The type of the file - :type: Optional[FileSystemFileType] - - :param: folder: The folder to add the file to - :type: folder: Optional[FileSystemFolder] - - :param: folder_uuid: The uuid of the folder to add the file to - :type: folder_uuid: Optional[str] + :param file_name: The file name. + :param size: The size the file takes on disk in bytes. + :param file_type: The type of the file. + :param folder_name: The folder to add the file to. + :param real: "Indicates whether the File is actually a real file in the Node sim fs output." """ - file = None - folder = None - if file_type is None: - file_type = self.get_random_file_type() - - # if no folder uuid provided, create a folder and add file to it - if folder_uuid is not None: - # otherwise check for existence and add file - folder = self.get_folder_by_id(folder_uuid) - - if folder is not None: + if folder_name: # check if file with name already exists - if folder.get_file_by_name(file_name): - raise Exception(f'File with name "{file_name}" already exists.') - - file = FileSystemFile(name=file_name, size=size, file_type=file_type) - folder.add_file(file=file) + folder = self._folders_by_name.get(folder_name) + # If not then create it + if not folder: + folder = self.create_folder(folder_name) else: - # check if a "root" folder exists - folder = self.get_folder_by_name("root") - if folder is None: - # create a root folder - folder = FileSystemFolder(name="root") + # Use root folder if folder_name not supplied + folder = self._folders_by_name["root"] - # add file to root folder - file = FileSystemFile(name=file_name, size=size, file_type=file_type) - folder.add_file(file) - self.folders[folder.uuid] = folder + # Create the file and add it to the folder + file = File( + name=file_name, + sim_size=size, + file_type=file_type, + folder=folder, + real=real, + sim_path=self.sim_root if real else None, + ) + folder.add_file(file) + self.sys_log.info(f"Created file /{file.path}") return file - def create_folder( - self, - folder_name: str, - ) -> FileSystemFolder: - """ - Creates a FileSystemFolder and adds it to the list of folders. + def get_file(self, folder_name: str, file_name: str) -> Optional[File]: + folder = self.get_folder(folder_name) + if folder: + return folder.get_file(file_name) + self.fs.sys_log.info(f"file not found /{folder_name}/{file_name}") - :param: folder_name: The name of the folder - :type: folder_name: str - """ - # check if folder with name already exists - if self.get_folder_by_name(folder_name): - raise Exception(f'Folder with name "{folder_name}" already exists.') + def delete_file(self, folder_name: str, file_name: str): + folder = self.get_folder(folder_name) + if folder: + file = folder.get_file(file_name) + if file: + folder.remove_file(file) + self.sys_log.info(f"Deleted file /{file.path}") - folder = FileSystemFolder(name=folder_name) + def move_file(self, src_folder_name: str, src_file_name: str, dst_folder_name): + file = self.get_file(folder_name=src_folder_name, file_name=src_file_name) + if file: + src_folder = file.folder - self.folders[folder.uuid] = folder - return folder + # remove file from src + src_folder.remove_file(file) + dst_folder = self.get_folder(folder_name=dst_folder_name) + if not dst_folder: + dst_folder = self.create_folder(dst_folder_name) + # add file to dst + dst_folder.add_file(file) - def delete_file(self, file: Optional[FileSystemFile] = None): - """ - Deletes a file and removes it from the files list. - - :param file: The file to delete - :type file: Optional[FileSystemFile] - """ - # iterate through folders to delete the item with the matching uuid - for key in self.folders: - self.get_folder_by_id(key).remove_file(file) - - def delete_folder(self, folder: FileSystemFolder): - """ - Deletes a folder, removes it from the folders list and removes any child folders and files. - - :param folder: The folder to remove - :type folder: FileSystemFolder - """ - if folder is None or not isinstance(folder, FileSystemFolder): - raise Exception(f"Invalid folder: {folder}") - - if self.folders.get(folder.uuid): - del self.folders[folder.uuid] - else: - _LOGGER.debug(f"File with UUID {folder.uuid} was not found.") - - def move_file(self, file: FileSystemFile, src_folder: FileSystemFolder, target_folder: FileSystemFolder): - """ - Moves a file from one folder to another. - - can provide - - :param: file: The file to move - :type: file: FileSystemFile - - :param: src_folder: The folder where the file is located - :type: FileSystemFolder - - :param: target_folder: The folder where the file should be moved to - :type: FileSystemFolder - """ - # check that the folders exist - if src_folder is None: - raise Exception("Source folder not provided") - - if target_folder is None: - raise Exception("Target folder not provided") - - if file is None: - raise Exception("File to be moved is None") - - # check if file with name already exists - if target_folder.get_file_by_name(file.name): - raise Exception(f'Folder with name "{file.name}" already exists.') - - # remove file from src - src_folder.remove_file(file) - - # add file to target - target_folder.add_file(file) - - def copy_file(self, file: FileSystemFile, src_folder: FileSystemFolder, target_folder: FileSystemFolder): + def copy_file(self, src_folder_name: str, src_file_name: str, dst_folder_name): """ Copies a file from one folder to another. can provide - :param: file: The file to move - :type: file: FileSystemFile + :param file: The file to move + :type: file: File - :param: src_folder: The folder where the file is located - :type: FileSystemFolder + :param src_folder: The folder where the file is located + :type: Folder - :param: target_folder: The folder where the file should be moved to - :type: FileSystemFolder + :param target_folder: The folder where the file should be moved to + :type: Folder """ - if src_folder is None: - raise Exception("Source folder not provided") + file = self.get_file(folder_name=src_folder_name, file_name=src_file_name) + if file: + dst_folder = self.get_folder(folder_name=dst_folder_name) + if not dst_folder: + dst_folder = self.create_folder(dst_folder_name) + new_file = file.make_copy(dst_folder=dst_folder) + dst_folder.add_file(new_file) - if target_folder is None: - raise Exception("Target folder not provided") - - if file is None: - raise Exception("File to be moved is None") - - # check if file with name already exists - if target_folder.get_file_by_name(file.name): - raise Exception(f'Folder with name "{file.name}" already exists.') - - # add file to target - target_folder.add_file(file) - - def get_file_by_id(self, file_id: str) -> FileSystemFile: - """Checks if the file exists in any file system folders.""" - for key in self.folders: - file = self.folders[key].get_file_by_id(file_id=file_id) - if file is not None: - return file - - def get_folder_by_name(self, folder_name: str) -> Optional[FileSystemFolder]: + def get_folder(self, folder_name: str) -> Optional[Folder]: """ - Returns a the first folder with a matching name. + Get a folder by its name if it exists. - :return: Returns the first FileSydtemFolder with a matching name + :param folder_name: The folder name. + :return: The matching Folder. """ - matching_folder = None - for key in self.folders: - if self.folders[key].name == folder_name: - matching_folder = self.folders[key] - break - return matching_folder + return self._folders_by_name.get(folder_name) - def get_folder_by_id(self, folder_id: str) -> FileSystemFolder: + def get_folder_by_id(self, folder_uuid: str) -> Optional[Folder]: """ - Checks if the folder exists. + Get a folder by its uuid if it exists. - :param: folder_id: The id of the folder to find - :type: folder_id: str + :param folder_uuid: The folder uuid. + :return: The matching Folder. """ - return self.folders[folder_id] + return self.folders.get(folder_uuid) - def get_random_file_type(self) -> FileSystemFileType: - """ - Returns a random FileSystemFileTypeEnum. - :return: A random file type Enum +class Folder(FileSystemItemABC): + """Simulation Folder.""" + + fs: FileSystem + "The FileSystem the Folder is in." + files: Dict[str, File] = {} + "Files stored in the folder." + _files_by_name: Dict[str, File] = {} + "Files by their name as .." + is_quarantined: bool = False + "Flag that marks the folder as quarantined if true." + + def describe_state(self) -> Dict: """ - return choice(list(FileSystemFileType)) + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + """ + state = super().describe_state() + state["files"] = {file.name: file.describe_state() for uuid, file in self.files.items()} + state["is_quarantined"] = self.is_quarantined + return state + + def show(self, markdown: bool = False): + """Prints a of the Folder""" + table = PrettyTable(["File", "Size"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"{self.fs.sys_log.hostname} File System Folder ({self.name})" + for file in self.files.values(): + table.add_row([file.name, file.size_str]) + print(table.get_string(sortby="File")) + + @property + def size(self): + return sum(file.size for file in self.files.values() if file.size is not None) + + def get_file(self, file_name: str) -> Optional[File]: + """ + Get a file by its name. + + File name must be the filename and prefix, like 'memo.docx'. + + :param file_name: The file name. + :return: The matching File. + """ + # TODO: Increment read count? + return self._files_by_name.get(file_name) + + def get_file_by_id(self, file_uuid: str) -> File: + """ + Get a file by its uuid. + + + :param file_uuid: The file uuid. + :return: The matching File. + """ + return self.files.get(file_uuid) + + def add_file(self, file: File): + """Adds a file to the folder list.""" + if file is None or not isinstance(file, File): + raise Exception(f"Invalid file: {file}") + + # check if file with id already exists in folder + if file.uuid in self.files: + _LOGGER.debug(f"File with id {file.uuid} already exists in folder") + else: + # add to list + self.files[file.uuid] = file + self._files_by_name[file.name] = file + file.folder = self + + def remove_file(self, file: Optional[File]): + """ + Removes a file from the folder list. + + The method can take a File object or a file id. + + :param file: The file to remove + :type: Optional[File] + """ + if file is None or not isinstance(file, File): + raise Exception(f"Invalid file: {file}") + + if self.files.get(file.uuid): + self.files.pop(file.uuid) + self._files_by_name.pop(file.name) + else: + _LOGGER.debug(f"File with UUID {file.uuid} was not found.") + + def quarantine(self): + """Quarantines the File System Folder.""" + if not self.is_quarantined: + self.is_quarantined = True + self.fs.sys_log.info(f"Quarantined folder ./{self.name}") + + def unquarantine(self): + """Unquarantine of the File System Folder.""" + if self.is_quarantined: + self.is_quarantined = False + self.fs.sys_log.info(f"Quarantined folder ./{self.name}") + + def quarantine_status(self) -> bool: + """Returns true if the folder is being quarantined.""" + return self.is_quarantined + + +class File(FileSystemItemABC): + """Class that represents a file in the simulation.""" + + folder: Folder + "The Folder the File is in." + file_type: FileType + "The type of File." + sim_size: Optional[int] = None + "The simulated file size." + real: bool = False + "Indicates whether the File is actually a real file in the Node sim fs output." + sim_path: Optional[Path] = None + "The Path if real is True." + + def __init__(self, **kwargs): + """ + Initialise File class. + + :param name: The name of the file. + :param file_type: The FileType of the file + :param size: The size of the FileSystemItemABC + """ + has_extension = "." in kwargs["name"] + + # Attempt to use the file type extension to set/override the FileType + if has_extension: + extension = kwargs["name"].split(".")[-1] + kwargs["file_type"] = get_file_type_from_extension(extension) + else: + # If the file name does not have a extension, override file type to FileType.UNKNOWN + if not kwargs["file_type"]: + kwargs["file_type"] = FileType.UNKNOWN + if kwargs["file_type"] != FileType.UNKNOWN: + kwargs["name"] = f"{kwargs['name']}.{kwargs['file_type'].name.lower()}" + + # set random file size if none provided + if not kwargs.get("sim_size"): + kwargs["sim_size"] = kwargs["file_type"].default_size + super().__init__(**kwargs) + if self.real: + self.sim_path = self.folder.fs.sim_root / self.path + if not self.sim_path.exists(): + self.sim_path.parent.mkdir(exist_ok=True, parents=True) + with open(self.sim_path, mode="a"): + pass + + def make_copy(self, dst_folder: Folder) -> File: + return File(folder=dst_folder, **self.model_dump(exclude={"uuid", "folder"})) + + @property + def path(self): + """The path of the file in the FileSystem.""" + return f"{self.folder.name}/{self.name}" + + @property + def size(self) -> int: + """The file size in Bytes.""" + if self.real: + return os.path.getsize(self.sim_path) + return self.sim_size + + def describe_state(self) -> Dict: + """Produce a dictionary describing the current state of this object.""" + state = super().describe_state() + state["size"] = self.size + state["file_type"] = self.file_type.name + return state diff --git a/src/primaite/simulator/file_system/file_system_file.py b/src/primaite/simulator/file_system/file_system_file.py deleted file mode 100644 index c25f5973..00000000 --- a/src/primaite/simulator/file_system/file_system_file.py +++ /dev/null @@ -1,55 +0,0 @@ -from random import choice -from typing import Dict - -from primaite.simulator.file_system.file_system_file_type import file_type_sizes_KB, FileSystemFileType -from primaite.simulator.file_system.file_system_item_abc import FileSystemItem - - -class FileSystemFile(FileSystemItem): - """Class that represents a file in the simulation.""" - - file_type: FileSystemFileType = None - """The type of the FileSystemFile""" - - def __init__(self, **kwargs): - """ - Initialise FileSystemFile class. - - :param name: The name of the file. - :type name: str - - :param file_type: The FileSystemFileType of the file - :type file_type: Optional[FileSystemFileType] - - :param size: The size of the FileSystemItem - :type size: Optional[float] - """ - # set random file type if none provided - - # set random file type if none provided - if kwargs.get("file_type") is None: - kwargs["file_type"] = choice(list(FileSystemFileType)) - - # set random file size if none provided - if kwargs.get("size") is None: - kwargs["size"] = file_type_sizes_KB[kwargs["file_type"]] - - super().__init__(**kwargs) - - def describe_state(self) -> Dict: - """ - Produce a dictionary describing the current state of this object. - - Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - - :return: Current state of this object and child objects. - :rtype: Dict - """ - state = super().describe_state() - state.update( - { - "uuid": self.uuid, - "file_type": self.file_type.name, - } - ) - return state diff --git a/src/primaite/simulator/file_system/file_system_file_type.py b/src/primaite/simulator/file_system/file_system_file_type.py deleted file mode 100644 index 88aeb430..00000000 --- a/src/primaite/simulator/file_system/file_system_file_type.py +++ /dev/null @@ -1,132 +0,0 @@ -from enum import Enum - - -class FileSystemFileType(str, Enum): - """An enumeration of common file types.""" - - UNKNOWN = 0 - "Unknown file type." - - # Text formats - TXT = 1 - "Plain text file." - DOC = 2 - "Microsoft Word document (.doc)" - DOCX = 3 - "Microsoft Word document (.docx)" - PDF = 4 - "Portable Document Format." - HTML = 5 - "HyperText Markup Language file." - XML = 6 - "Extensible Markup Language file." - CSV = 7 - "Comma-Separated Values file." - - # Spreadsheet formats - XLS = 8 - "Microsoft Excel file (.xls)" - XLSX = 9 - "Microsoft Excel file (.xlsx)" - - # Image formats - JPEG = 10 - "JPEG image file." - PNG = 11 - "PNG image file." - GIF = 12 - "GIF image file." - BMP = 13 - "Bitmap image file." - - # Audio formats - MP3 = 14 - "MP3 audio file." - WAV = 15 - "WAV audio file." - - # Video formats - MP4 = 16 - "MP4 video file." - AVI = 17 - "AVI video file." - MKV = 18 - "MKV video file." - FLV = 19 - "FLV video file." - - # Presentation formats - PPT = 20 - "Microsoft PowerPoint file (.ppt)" - PPTX = 21 - "Microsoft PowerPoint file (.pptx)" - - # Web formats - JS = 22 - "JavaScript file." - CSS = 23 - "Cascading Style Sheets file." - - # Programming languages - PY = 24 - "Python script file." - C = 25 - "C source code file." - CPP = 26 - "C++ source code file." - JAVA = 27 - "Java source code file." - - # Compressed file types - RAR = 28 - "RAR archive file." - ZIP = 29 - "ZIP archive file." - TAR = 30 - "TAR archive file." - GZ = 31 - "Gzip compressed file." - - # Database file types - MDF = 32 - "MS SQL Server primary database file" - NDF = 33 - "MS SQL Server secondary database file" - LDF = 34 - "MS SQL Server transaction log" - - -file_type_sizes_KB = { - FileSystemFileType.UNKNOWN: 0, - FileSystemFileType.TXT: 4, - FileSystemFileType.DOC: 50, - FileSystemFileType.DOCX: 30, - FileSystemFileType.PDF: 100, - FileSystemFileType.HTML: 15, - FileSystemFileType.XML: 10, - FileSystemFileType.CSV: 15, - FileSystemFileType.XLS: 100, - FileSystemFileType.XLSX: 25, - FileSystemFileType.JPEG: 100, - FileSystemFileType.PNG: 40, - FileSystemFileType.GIF: 30, - FileSystemFileType.BMP: 300, - FileSystemFileType.MP3: 5000, - FileSystemFileType.WAV: 25000, - FileSystemFileType.MP4: 25000, - FileSystemFileType.AVI: 50000, - FileSystemFileType.MKV: 50000, - FileSystemFileType.FLV: 15000, - FileSystemFileType.PPT: 200, - FileSystemFileType.PPTX: 100, - FileSystemFileType.JS: 10, - FileSystemFileType.CSS: 5, - FileSystemFileType.PY: 5, - FileSystemFileType.C: 5, - FileSystemFileType.CPP: 10, - FileSystemFileType.JAVA: 10, - FileSystemFileType.RAR: 1000, - FileSystemFileType.ZIP: 1000, - FileSystemFileType.TAR: 1000, - FileSystemFileType.GZ: 800, -} diff --git a/src/primaite/simulator/file_system/file_system_folder.py b/src/primaite/simulator/file_system/file_system_folder.py deleted file mode 100644 index 4e461a3a..00000000 --- a/src/primaite/simulator/file_system/file_system_folder.py +++ /dev/null @@ -1,87 +0,0 @@ -from typing import Dict, Optional - -from primaite import getLogger -from primaite.simulator.file_system.file_system_file import FileSystemFile -from primaite.simulator.file_system.file_system_item_abc import FileSystemItem - -_LOGGER = getLogger(__name__) - - -class FileSystemFolder(FileSystemItem): - """Simulation FileSystemFolder.""" - - files: Dict[str, FileSystemFile] = {} - """List of files stored in the folder.""" - - is_quarantined: bool = False - """Flag that marks the folder as quarantined if true.""" - - def describe_state(self) -> Dict: - """ - Produce a dictionary describing the current state of this object. - - Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - - :return: Current state of this object and child objects. - :rtype: Dict - """ - state = super().describe_state() - state.update( - { - "files": {uuid: file.describe_state() for uuid, file in self.files.items()}, - "is_quarantined": self.is_quarantined, - } - ) - return state - - def get_file_by_id(self, file_id: str) -> FileSystemFile: - """Return a FileSystemFile with the matching id.""" - return self.files.get(file_id) - - def get_file_by_name(self, file_name: str) -> FileSystemFile: - """Return a FileSystemFile with the matching id.""" - return next((f for f in list(self.files) if f.name == file_name), None) - - def add_file(self, file: FileSystemFile): - """Adds a file to the folder list.""" - if file is None or not isinstance(file, FileSystemFile): - raise Exception(f"Invalid file: {file}") - - # check if file with id already exists in folder - if file.uuid in self.files: - _LOGGER.debug(f"File with id {file.uuid} already exists in folder") - else: - # add to list - self.files[file.uuid] = file - self.size += file.size - - def remove_file(self, file: Optional[FileSystemFile]): - """ - Removes a file from the folder list. - - The method can take a FileSystemFile object or a file id. - - :param: file: The file to remove - :type: Optional[FileSystemFile] - """ - if file is None or not isinstance(file, FileSystemFile): - raise Exception(f"Invalid file: {file}") - - if self.files.get(file.uuid): - del self.files[file.uuid] - - self.size -= file.size - else: - _LOGGER.debug(f"File with UUID {file.uuid} was not found.") - - def quarantine(self): - """Quarantines the File System Folder.""" - self.is_quarantined = True - - def end_quarantine(self): - """Ends the quarantine of the File System Folder.""" - self.is_quarantined = False - - def quarantine_status(self) -> bool: - """Returns true if the folder is being quarantined.""" - return self.is_quarantined diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py deleted file mode 100644 index 3b368819..00000000 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ /dev/null @@ -1,31 +0,0 @@ -from typing import Dict - -from primaite.simulator.core import SimComponent - - -class FileSystemItem(SimComponent): - """Abstract base class for FileSystemItems used in the file system simulation.""" - - name: str - """The name of the FileSystemItem.""" - - size: float = 0 - """The size the item takes up on disk.""" - - def describe_state(self) -> Dict: - """ - Produce a dictionary describing the current state of this object. - - Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - - :return: Current state of this object and child objects. - :rtype: Dict - """ - state = super().describe_state() - state.update( - { - "name": self.name, - "size": self.size, - } - ) - return state diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 101d6b72..dcad59f8 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -4,12 +4,14 @@ import re import secrets from enum import Enum from ipaddress import IPv4Address, IPv4Network +from pathlib import Path from typing import Any, Dict, List, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.exceptions import NetworkError +from primaite.simulator import SIM_OUTPUT from primaite.simulator.core import SimComponent from primaite.simulator.domain.account import Account from primaite.simulator.file_system.file_system import FileSystem @@ -890,6 +892,8 @@ class Node(SimComponent): "All processes on the node." file_system: FileSystem "The nodes file system." + root: Path + "Root directory for simulation output." sys_log: SysLog arp: ARPCache icmp: ICMP @@ -921,8 +925,10 @@ class Node(SimComponent): kwargs["software_manager"] = SoftwareManager( sys_log=kwargs.get("sys_log"), session_manager=kwargs.get("session_manager") ) + if not kwargs.get("root"): + kwargs["root"] = SIM_OUTPUT / kwargs["hostname"] if not kwargs.get("file_system"): - kwargs["file_system"] = FileSystem() + kwargs["file_system"] = FileSystem(sys_log=kwargs["sys_log"], sim_root=kwargs["root"] / "fs") super().__init__(**kwargs) self.arp.nics = self.nics diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index c985af1f..f4521096 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -2,7 +2,7 @@ import logging from pathlib import Path from typing import Optional -from primaite.simulator import TEMP_SIM_OUTPUT +from primaite.simulator import SIM_OUTPUT class _JSONFilter(logging.Filter): @@ -62,7 +62,7 @@ class PacketCapture: def _get_log_path(self) -> Path: """Get the path for the log file.""" - root = TEMP_SIM_OUTPUT / self.hostname + root = SIM_OUTPUT / self.hostname root.mkdir(exist_ok=True, parents=True) return root / f"{self._logger_name}.log" diff --git a/src/primaite/simulator/system/core/sys_log.py b/src/primaite/simulator/system/core/sys_log.py index e07c28aa..791e0be8 100644 --- a/src/primaite/simulator/system/core/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -3,7 +3,7 @@ from pathlib import Path from prettytable import MARKDOWN, PrettyTable -from primaite.simulator import TEMP_SIM_OUTPUT +from primaite.simulator import SIM_OUTPUT class _NotJSONFilter(logging.Filter): @@ -81,7 +81,7 @@ class SysLog: :return: Path object representing the location of the log file. """ - root = TEMP_SIM_OUTPUT / self.hostname + root = SIM_OUTPUT / self.hostname root.mkdir(exist_ok=True, parents=True) return root / f"{self.hostname}_sys.log" diff --git a/src/primaite/simulator/system/services/database.py b/src/primaite/simulator/system/services/database.py index 23b856f7..67ee5cc3 100644 --- a/src/primaite/simulator/system/services/database.py +++ b/src/primaite/simulator/system/services/database.py @@ -1,12 +1,15 @@ from typing import Dict -from primaite.simulator.file_system.file_system_file_type import FileSystemFileType +from primaite.simulator.file_system.file_type import FileType from primaite.simulator.network.hardware.base import Node from primaite.simulator.system.services.service import Service class DatabaseService(Service): - """Service loosely modelled on Microsoft SQL Server.""" + """A generic SQL Server Service.""" + + def __init__(self, **kwargs): + super().__init__(**kwargs) def describe_state(self) -> Dict: """ @@ -19,6 +22,10 @@ class DatabaseService(Service): """ return super().describe_state() + @classmethod + def install(cls, node: Node): + + def uninstall(self) -> None: """ Undo installation procedure. @@ -42,19 +49,10 @@ class DatabaseService(Service): def _setup_files( self, - db_size: int = 1000, - use_secondary_db_file: bool = False, - secondary_db_size: int = 300, folder_name: str = "database", ): """Set up files that are required by the database on the parent host. - :param db_size: Initial file size of the main database file, defaults to 1000 - :type db_size: int, optional - :param use_secondary_db_file: Whether to use a secondary database file, defaults to False - :type use_secondary_db_file: bool, optional - :param secondary_db_size: Size of the secondary db file, defaults to None - :type secondary_db_size: int, optional :param folder_name: Name of the folder which will be setup to hold the db files, defaults to "database" :type folder_name: str, optional """ @@ -63,14 +61,14 @@ class DatabaseService(Service): self.parent: Node self.folder = self.parent.file_system.create_folder(folder_name) self.primary_store = self.parent.file_system.create_file( - "db_primary_store", db_size, FileSystemFileType.MDF, folder=self.folder + "db_primary_store", db_size, FileType.MDF, folder=self.folder ) self.transaction_log = self.parent.file_system.create_file( - "db_transaction_log", "1", FileSystemFileType.LDF, folder=self.folder + "db_transaction_log", "1", FileType.LDF, folder=self.folder ) if use_secondary_db_file: self.secondary_store = self.parent.file_system.create_file( - "db_secondary_store", secondary_db_size, FileSystemFileType.NDF, folder=self.folder + "db_secondary_store", secondary_db_size, FileType.NDF, folder=self.folder ) else: self.secondary_store = None diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 73d19339..4ece69e0 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -53,4 +53,4 @@ def test_uninstalling_database(): node.uninstall_service(db) assert db not in node - assert node.file_system.get_folder_by_name("database") is None + assert node.file_system.get_folder("database") is None diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 348eb440..136961e2 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -1,132 +1,137 @@ -from primaite.simulator.file_system.file_system import FileSystem -from primaite.simulator.file_system.file_system_file import FileSystemFile -from primaite.simulator.file_system.file_system_folder import FileSystemFolder +import pytest + +from primaite.simulator.file_system.file_system import File, FileSystem, Folder +from primaite.simulator.file_system.file_type import FileType +from primaite.simulator.network.hardware.base import Node -def test_create_folder_and_file(): +@pytest.fixture(scope="function") +def file_system() -> FileSystem: + return Node(hostname="fs_node").file_system + + +def test_create_folder_and_file(file_system): """Test creating a folder and a file.""" - file_system = FileSystem() - folder = file_system.create_folder(folder_name="test_folder") - assert len(file_system.folders) is 1 + assert len(file_system.folders) == 1 + test_folder = file_system.create_folder(folder_name="test_folder") - file = file_system.create_file(file_name="test_file", size=10, folder_uuid=folder.uuid) - assert len(file_system.get_folder_by_id(folder.uuid).files) is 1 + assert len(file_system.folders) is 2 + file_system.create_file(file_name="test_file.txt", folder_name="test_folder") - assert file_system.get_file_by_id(file.uuid).name is "test_file" - assert file_system.get_file_by_id(file.uuid).size == 10 + assert len(file_system.get_folder("test_folder").files) == 1 + + assert file_system.get_folder("test_folder").get_file("test_file.txt") -def test_create_file(): +def test_create_file_no_folder(file_system): """Tests that creating a file without a folder creates a folder and sets that as the file's parent.""" - file_system = FileSystem() - - file = file_system.create_file(file_name="test_file", size=10) + file = file_system.create_file(file_name="test_file.txt", size=10) assert len(file_system.folders) is 1 - assert file_system.get_folder_by_name("root").get_file_by_id(file.uuid) is file + assert file_system.get_folder("root").get_file("test_file.txt") == file + assert file_system.get_folder("root").get_file("test_file.txt").file_type == FileType.TXT + assert file_system.get_folder("root").get_file("test_file.txt").size == 10 -def test_delete_file(): +def test_create_file_no_extension(file_system): + """Tests that creating a file without an extension sets the file type to FileType.UNKNOWN.""" + file = file_system.create_file(file_name="test_file") + assert len(file_system.folders) is 1 + assert file_system.get_folder("root").get_file("test_file") == file + assert file_system.get_folder("root").get_file("test_file").file_type == FileType.UNKNOWN + assert file_system.get_folder("root").get_file("test_file").size == 0 + + +def test_delete_file(file_system): """Tests that a file can be deleted.""" - file_system = FileSystem() + file_system.create_file(file_name="test_file.txt") + assert len(file_system.folders) == 1 + assert len(file_system.get_folder("root").files) == 1 - file = file_system.create_file(file_name="test_file", size=10) - assert len(file_system.folders) is 1 - - folder_id = list(file_system.folders.keys())[0] - folder = file_system.get_folder_by_id(folder_id) - assert folder.get_file_by_id(file.uuid) is file - - file_system.delete_file(file=file) - assert len(file_system.folders) is 1 - assert len(folder.files) is 0 + file_system.delete_file(folder_name="root", file_name="test_file.txt") + assert len(file_system.folders) == 1 + assert len(file_system.get_folder("root").files) == 0 -def test_delete_non_existent_file(): +def test_delete_non_existent_file(file_system): """Tests deleting a non existent file.""" - file_system = FileSystem() - - file = file_system.create_file(file_name="test_file", size=10) - not_added_file = FileSystemFile(name="not_added") + file_system.create_file(file_name="test_file.txt") # folder should be created - assert len(file_system.folders) is 1 + assert len(file_system.folders) == 1 # should only have 1 file in the file system - folder_id = list(file_system.folders.keys())[0] - folder = file_system.get_folder_by_id(folder_id) - assert len(list(folder.files)) is 1 - - assert folder.get_file_by_id(file.uuid) is file + assert len(file_system.get_folder("root").files) == 1 # deleting should not change how many files are in folder - file_system.delete_file(file=not_added_file) - assert len(file_system.folders) is 1 - assert len(list(folder.files)) is 1 + file_system.delete_file(folder_name="root", file_name="does_not_exist!") + + # should still only be one folder + assert len(file_system.folders) == 1 + # The folder should still have 1 file + assert len(file_system.get_folder("root").files) == 1 -def test_delete_folder(): - file_system = FileSystem() - folder = file_system.create_folder(folder_name="test_folder") - assert len(file_system.folders) is 1 +def test_delete_folder(file_system): + file_system.create_folder(folder_name="test_folder") + assert len(file_system.folders) == 2 - file_system.delete_folder(folder) - assert len(file_system.folders) is 0 + file_system.delete_folder(folder_name="test_folder") + assert len(file_system.folders) == 1 -def test_deleting_a_non_existent_folder(): - file_system = FileSystem() - folder = file_system.create_folder(folder_name="test_folder") - not_added_folder = FileSystemFolder(name="fake_folder") - assert len(file_system.folders) is 1 +def test_deleting_a_non_existent_folder(file_system): + file_system.create_folder(folder_name="test_folder") + assert len(file_system.folders) == 2 - file_system.delete_folder(not_added_folder) - assert len(file_system.folders) is 1 + file_system.delete_folder(folder_name="does not exist!") + assert len(file_system.folders) == 2 -def test_move_file(): +def test_deleting_root_folder_fails(file_system): + assert len(file_system.folders) == 1 + + file_system.delete_folder(folder_name="root") + assert len(file_system.folders) == 1 + + +def test_move_file(file_system): """Tests the file move function.""" - file_system = FileSystem() - src_folder = file_system.create_folder(folder_name="test_folder_1") - assert len(file_system.folders) is 1 + file_system.create_folder(folder_name="src_folder") + file_system.create_folder(folder_name="dst_folder") - target_folder = file_system.create_folder(folder_name="test_folder_2") - assert len(file_system.folders) is 2 + file = file_system.create_file(file_name="test_file.txt", size=10, folder_name="src_folder") + original_uuid = file.uuid - file = file_system.create_file(file_name="test_file", size=10, folder_uuid=src_folder.uuid) - assert len(file_system.get_folder_by_id(src_folder.uuid).files) is 1 - assert len(file_system.get_folder_by_id(target_folder.uuid).files) is 0 + assert len(file_system.get_folder("src_folder").files) == 1 + assert len(file_system.get_folder("dst_folder").files) == 0 - file_system.move_file(file=file, src_folder=src_folder, target_folder=target_folder) + file_system.move_file(src_folder_name="src_folder", src_file_name="test_file.txt", dst_folder_name="dst_folder") - assert len(file_system.get_folder_by_id(src_folder.uuid).files) is 0 - assert len(file_system.get_folder_by_id(target_folder.uuid).files) is 1 + assert len(file_system.get_folder("src_folder").files) == 0 + assert len(file_system.get_folder("dst_folder").files) == 1 + assert file_system.get_file("dst_folder", "test_file.txt").uuid == original_uuid -def test_copy_file(): +def test_copy_file(file_system): """Tests the file copy function.""" - file_system = FileSystem() - src_folder = file_system.create_folder(folder_name="test_folder_1") - assert len(file_system.folders) is 1 + file_system.create_folder(folder_name="src_folder") + file_system.create_folder(folder_name="dst_folder") - target_folder = file_system.create_folder(folder_name="test_folder_2") - assert len(file_system.folders) is 2 + file = file_system.create_file(file_name="test_file.txt", size=10, folder_name="src_folder") + original_uuid = file.uuid - file = file_system.create_file(file_name="test_file", size=10, folder_uuid=src_folder.uuid) - assert len(file_system.get_folder_by_id(src_folder.uuid).files) is 1 - assert len(file_system.get_folder_by_id(target_folder.uuid).files) is 0 + assert len(file_system.get_folder("src_folder").files) == 1 + assert len(file_system.get_folder("dst_folder").files) == 0 - file_system.copy_file(file=file, src_folder=src_folder, target_folder=target_folder) + file_system.copy_file(src_folder_name="src_folder", src_file_name="test_file.txt", dst_folder_name="dst_folder") - assert len(file_system.get_folder_by_id(src_folder.uuid).files) is 1 - assert len(file_system.get_folder_by_id(target_folder.uuid).files) is 1 + assert len(file_system.get_folder("src_folder").files) == 1 + assert len(file_system.get_folder("dst_folder").files) == 1 + assert file_system.get_file("dst_folder", "test_file.txt").uuid != original_uuid -def test_serialisation(): +@pytest.mark.skip(reason="Skipping until we tackle serialisation") +def test_serialisation(file_system): """Test to check that the object serialisation works correctly.""" - file_system = FileSystem() - folder = file_system.create_folder(folder_name="test_folder") - assert len(file_system.folders) is 1 - - file_system.create_file(file_name="test_file", size=10, folder_uuid=folder.uuid) - assert file_system.get_folder_by_id(folder.uuid) is folder + file_system.create_file(file_name="test_file.txt") serialised_file_sys = file_system.model_dump_json() deserialised_file_sys = FileSystem.model_validate_json(serialised_file_sys) diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py index 629b9bb9..981550f3 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py @@ -1,23 +1,23 @@ -from primaite.simulator.file_system.file_system_file import FileSystemFile -from primaite.simulator.file_system.file_system_file_type import FileSystemFileType +from primaite.simulator.file_system.file_system import File +from primaite.simulator.file_system.file_type import FileType def test_file_type(): - """Tests tha the FileSystemFile type is set correctly.""" - file = FileSystemFile(name="test", file_type=FileSystemFileType.DOC) - assert file.file_type is FileSystemFileType.DOC + """Tests tha the File type is set correctly.""" + file = File(name="test", file_type=FileType.DOC) + assert file.file_type is FileType.DOC def test_get_size(): """Tests that the file size is being returned properly.""" - file = FileSystemFile(name="test", size=1.5) + file = File(name="test", size=1.5) assert file.size == 1.5 def test_serialisation(): """Test to check that the object serialisation works correctly.""" - file = FileSystemFile(name="test", size=1.5, file_type=FileSystemFileType.DOC) + file = File(name="test", size=1.5, file_type=FileType.DOC) serialised_file = file.model_dump_json() - deserialised_file = FileSystemFile.model_validate_json(serialised_file) + deserialised_file = File.model_validate_json(serialised_file) assert file.model_dump_json() == deserialised_file.model_dump_json() diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py index 1940e886..72684146 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py @@ -1,13 +1,13 @@ -from primaite.simulator.file_system.file_system_file import FileSystemFile -from primaite.simulator.file_system.file_system_file_type import FileSystemFileType -from primaite.simulator.file_system.file_system_folder import FileSystemFolder +from primaite.simulator.file_system.file_system import File +from primaite.simulator.file_system.file_system_folder import Folder +from primaite.simulator.file_system.file_type import FileType def test_adding_removing_file(): """Test the adding and removing of a file from a folder.""" - folder = FileSystemFolder(name="test") + folder = Folder(name="test") - file = FileSystemFile(name="test_file", size=10, file_type=FileSystemFileType.DOC) + file = File(name="test_file", size=10, file_type=FileType.DOC) folder.add_file(file) assert folder.size == 10 @@ -20,10 +20,10 @@ def test_adding_removing_file(): def test_remove_non_existent_file(): """Test the removing of a file that does not exist.""" - folder = FileSystemFolder(name="test") + folder = Folder(name="test") - file = FileSystemFile(name="test_file", size=10, file_type=FileSystemFileType.DOC) - not_added_file = FileSystemFile(name="fake_file", size=10, file_type=FileSystemFileType.DOC) + file = File(name="test_file", size=10, file_type=FileType.DOC) + not_added_file = File(name="fake_file", size=10, file_type=FileType.DOC) folder.add_file(file) assert folder.size == 10 @@ -36,10 +36,10 @@ def test_remove_non_existent_file(): def test_get_file_by_id(): """Test to make sure that the correct file is returned.""" - folder = FileSystemFolder(name="test") + folder = Folder(name="test") - file = FileSystemFile(name="test_file", size=10, file_type=FileSystemFileType.DOC) - file2 = FileSystemFile(name="test_file_2", size=10, file_type=FileSystemFileType.DOC) + file = File(name="test_file", size=10, file_type=FileType.DOC) + file2 = File(name="test_file_2", size=10, file_type=FileType.DOC) folder.add_file(file) folder.add_file(file2) @@ -51,25 +51,25 @@ def test_get_file_by_id(): def test_folder_quarantine_state(): """Tests the changing of folder quarantine status.""" - folder = FileSystemFolder(name="test") + folder = Folder(name="test") assert folder.quarantine_status() is False folder.quarantine() assert folder.quarantine_status() is True - folder.end_quarantine() + folder.unquarantine() assert folder.quarantine_status() is False def test_serialisation(): """Test to check that the object serialisation works correctly.""" - folder = FileSystemFolder(name="test") - file = FileSystemFile(name="test_file", size=10, file_type=FileSystemFileType.DOC) + folder = Folder(name="test") + file = File(name="test_file", size=10, file_type=FileType.DOC) folder.add_file(file) serialised_folder = folder.model_dump_json() - deserialised_folder = FileSystemFolder.model_validate_json(serialised_folder) + deserialised_folder = Folder.model_validate_json(serialised_folder) assert folder.model_dump_json() == deserialised_folder.model_dump_json() From 4f89adb19aab1055ef01f57635288def5b0466c8 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 6 Sep 2023 12:51:47 +0100 Subject: [PATCH 154/980] Start changing to dict instead of string actions. --- .gitignore | 2 +- src/primaite/notebooks/scratch.ipynb | 194 +++++++++++++++++++++++++++ src/primaite/simulator/core.py | 6 +- 3 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 src/primaite/notebooks/scratch.ipynb diff --git a/.gitignore b/.gitignore index 77e74e17..fd115d62 100644 --- a/.gitignore +++ b/.gitignore @@ -150,5 +150,5 @@ src/primaite/outputs/ # benchmark session outputs benchmark/output -src/primaite/notebooks/scratch.ipynb +# src/primaite/notebooks/scratch.ipynb src/primaite/notebooks/scratch.py diff --git a/src/primaite/notebooks/scratch.ipynb b/src/primaite/notebooks/scratch.ipynb new file mode 100644 index 00000000..50a85e7a --- /dev/null +++ b/src/primaite/notebooks/scratch.ipynb @@ -0,0 +1,194 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.simulator.network.networks import arcd_uc2_network\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-09-05 15:52:13,305: Added node 26e189bb-442e-4f73-ab7a-1c4dd162e986 to Network 16435554-f108-479e-a4de-719f39898d0a\n", + "2023-09-05 15:52:13,307: Added node 9d07f591-1e44-41c9-9d7a-0eecf0c53fa4 to Network 16435554-f108-479e-a4de-719f39898d0a\n", + "2023-09-05 15:52:13,322: NIC d5:3d:df:8d:21:94/192.168.1.1 connected to Link d5:3d:df:8d:21:94/192.168.1.1<-->70:63:71:75:0f:84\n", + "2023-09-05 15:52:13,324: SwitchPort 70:63:71:75:0f:84 connected to Link d5:3d:df:8d:21:94/192.168.1.1<-->70:63:71:75:0f:84\n", + "2023-09-05 15:52:13,326: Link d5:3d:df:8d:21:94/192.168.1.1<-->70:63:71:75:0f:84 up\n", + "2023-09-05 15:52:13,327: Link d5:3d:df:8d:21:94/192.168.1.1<-->70:63:71:75:0f:84 up\n", + "2023-09-05 15:52:13,329: Added link 497f7357-e14e-4f00-b6cd-68286b053496 to connect d5:3d:df:8d:21:94/192.168.1.1 and 70:63:71:75:0f:84\n", + "2023-09-05 15:52:13,333: Added node 9cf37bd7-9f67-47f8-836b-3b5e69dd600c to Network 16435554-f108-479e-a4de-719f39898d0a\n", + "2023-09-05 15:52:13,336: NIC c7:ca:5f:6c:50:c9/192.168.10.1 connected to Link c7:ca:5f:6c:50:c9/192.168.10.1<-->e7:21:66:e4:da:2c\n", + "2023-09-05 15:52:13,338: SwitchPort e7:21:66:e4:da:2c connected to Link c7:ca:5f:6c:50:c9/192.168.10.1<-->e7:21:66:e4:da:2c\n", + "2023-09-05 15:52:13,340: Link c7:ca:5f:6c:50:c9/192.168.10.1<-->e7:21:66:e4:da:2c up\n", + "2023-09-05 15:52:13,341: Link c7:ca:5f:6c:50:c9/192.168.10.1<-->e7:21:66:e4:da:2c up\n", + "2023-09-05 15:52:13,343: Added link b1165845-46af-400d-b408-9f6b0fe4a51a to connect c7:ca:5f:6c:50:c9/192.168.10.1 and e7:21:66:e4:da:2c\n", + "2023-09-05 15:52:13,345: Added node 9c7f4049-30fa-40bd-b0c8-2119bef7936c to Network 16435554-f108-479e-a4de-719f39898d0a\n", + "2023-09-05 15:52:13,347: SwitchPort e9:5c:26:c2:74:a2 connected to Link e9:5c:26:c2:74:a2<-->fb:05:aa:54:2d:3e/192.168.10.21\n", + "2023-09-05 15:52:13,351: Link e9:5c:26:c2:74:a2<-->fb:05:aa:54:2d:3e/192.168.10.21 up\n", + "2023-09-05 15:52:13,353: NIC fb:05:aa:54:2d:3e/192.168.10.21 connected to Link e9:5c:26:c2:74:a2<-->fb:05:aa:54:2d:3e/192.168.10.21\n", + "2023-09-05 15:52:13,354: Link e9:5c:26:c2:74:a2<-->fb:05:aa:54:2d:3e/192.168.10.21 up\n", + "2023-09-05 15:52:13,356: Added link 7d9ade8d-ed9c-4688-8375-18b58102b2a7 to connect e9:5c:26:c2:74:a2 and fb:05:aa:54:2d:3e/192.168.10.21\n", + "2023-09-05 15:52:13,358: Added node 88c26ce5-4243-4247-98a3-315ff54f7ef6 to Network 16435554-f108-479e-a4de-719f39898d0a\n", + "2023-09-05 15:52:13,360: SwitchPort 30:fd:61:15:db:ad connected to Link 30:fd:61:15:db:ad<-->c1:e2:46:a2:cb:b2/192.168.10.22\n", + "2023-09-05 15:52:13,362: Link 30:fd:61:15:db:ad<-->c1:e2:46:a2:cb:b2/192.168.10.22 up\n", + "2023-09-05 15:52:13,363: NIC c1:e2:46:a2:cb:b2/192.168.10.22 connected to Link 30:fd:61:15:db:ad<-->c1:e2:46:a2:cb:b2/192.168.10.22\n", + "2023-09-05 15:52:13,365: Link 30:fd:61:15:db:ad<-->c1:e2:46:a2:cb:b2/192.168.10.22 up\n", + "2023-09-05 15:52:13,367: Added link bcfe4c45-d680-4f72-a90a-9fa57c2a6fba to connect 30:fd:61:15:db:ad and c1:e2:46:a2:cb:b2/192.168.10.22\n", + "2023-09-05 15:52:13,370: Added node d7e5389a-9970-4c47-926c-9069b925e934 to Network 16435554-f108-479e-a4de-719f39898d0a\n", + "2023-09-05 15:52:13,372: SwitchPort 35:0c:3a:21:7c:d1 connected to Link 35:0c:3a:21:7c:d1<-->40:4f:3e:f0:32:66/192.168.1.10\n", + "2023-09-05 15:52:13,375: Link 35:0c:3a:21:7c:d1<-->40:4f:3e:f0:32:66/192.168.1.10 up\n", + "2023-09-05 15:52:13,376: NIC 40:4f:3e:f0:32:66/192.168.1.10 connected to Link 35:0c:3a:21:7c:d1<-->40:4f:3e:f0:32:66/192.168.1.10\n", + "2023-09-05 15:52:13,378: Link 35:0c:3a:21:7c:d1<-->40:4f:3e:f0:32:66/192.168.1.10 up\n", + "2023-09-05 15:52:13,380: Added link 34254262-beeb-4967-b7ff-3480928e47f9 to connect 35:0c:3a:21:7c:d1 and 40:4f:3e:f0:32:66/192.168.1.10\n", + "2023-09-05 15:52:13,386: Added node 02c25642-baa5-49a4-aadd-f5d549696351 to Network 16435554-f108-479e-a4de-719f39898d0a\n", + "2023-09-05 15:52:13,388: SwitchPort a4:ab:83:f0:b5:fe connected to Link a4:ab:83:f0:b5:fe<-->4b:a9:6c:90:ae:8f/192.168.1.12\n", + "2023-09-05 15:52:13,390: Link a4:ab:83:f0:b5:fe<-->4b:a9:6c:90:ae:8f/192.168.1.12 up\n", + "2023-09-05 15:52:13,392: NIC 4b:a9:6c:90:ae:8f/192.168.1.12 connected to Link a4:ab:83:f0:b5:fe<-->4b:a9:6c:90:ae:8f/192.168.1.12\n", + "2023-09-05 15:52:13,393: Link a4:ab:83:f0:b5:fe<-->4b:a9:6c:90:ae:8f/192.168.1.12 up\n", + "2023-09-05 15:52:13,395: Added link 433b0cec-445d-4447-9502-c8727eb14a81 to connect a4:ab:83:f0:b5:fe and 4b:a9:6c:90:ae:8f/192.168.1.12\n", + "2023-09-05 15:52:13,398: Added node 6f89bce8-34e4-4fdf-b860-b34027efa639 to Network 16435554-f108-479e-a4de-719f39898d0a\n", + "2023-09-05 15:52:13,400: SwitchPort c2:9f:42:ec:ea:a0 connected to Link c2:9f:42:ec:ea:a0<-->c7:61:9d:6e:0b:29/192.168.1.14\n", + "2023-09-05 15:52:13,403: Link c2:9f:42:ec:ea:a0<-->c7:61:9d:6e:0b:29/192.168.1.14 up\n", + "2023-09-05 15:52:13,405: NIC c7:61:9d:6e:0b:29/192.168.1.14 connected to Link c2:9f:42:ec:ea:a0<-->c7:61:9d:6e:0b:29/192.168.1.14\n", + "2023-09-05 15:52:13,407: Link c2:9f:42:ec:ea:a0<-->c7:61:9d:6e:0b:29/192.168.1.14 up\n", + "2023-09-05 15:52:13,408: Added link 30b18ea0-ea2b-494a-8a63-d5b4bd703668 to connect c2:9f:42:ec:ea:a0 and c7:61:9d:6e:0b:29/192.168.1.14\n", + "2023-09-05 15:52:13,412: Added node 15eb1a5c-50f4-4681-81f8-7ad457c6b1af to Network 16435554-f108-479e-a4de-719f39898d0a\n", + "2023-09-05 15:52:13,414: SwitchPort 5c:0e:20:b3:65:cb connected to Link 5c:0e:20:b3:65:cb<-->bd:06:4d:19:fb:f2/192.168.1.16\n", + "2023-09-05 15:52:13,417: Link 5c:0e:20:b3:65:cb<-->bd:06:4d:19:fb:f2/192.168.1.16 up\n", + "2023-09-05 15:52:13,419: NIC bd:06:4d:19:fb:f2/192.168.1.16 connected to Link 5c:0e:20:b3:65:cb<-->bd:06:4d:19:fb:f2/192.168.1.16\n", + "2023-09-05 15:52:13,420: Link 5c:0e:20:b3:65:cb<-->bd:06:4d:19:fb:f2/192.168.1.16 up\n", + "2023-09-05 15:52:13,421: Added link deb1ee09-9731-46e2-99fb-1276ca48ccb3 to connect 5c:0e:20:b3:65:cb and bd:06:4d:19:fb:f2/192.168.1.16\n", + "2023-09-05 15:52:13,424: Added node 5c5b1c84-5d06-4319-80c0-ca3adf9ce2c6 to Network 16435554-f108-479e-a4de-719f39898d0a\n", + "2023-09-05 15:52:13,425: SwitchPort e6:fa:f7:9a:d3:8c connected to Link e6:fa:f7:9a:d3:8c<-->37:5b:c5:ac:e5:08/192.168.1.110\n", + "2023-09-05 15:52:13,429: Link e6:fa:f7:9a:d3:8c<-->37:5b:c5:ac:e5:08/192.168.1.110 up\n", + "2023-09-05 15:52:13,430: NIC 37:5b:c5:ac:e5:08/192.168.1.110 connected to Link e6:fa:f7:9a:d3:8c<-->37:5b:c5:ac:e5:08/192.168.1.110\n", + "2023-09-05 15:52:13,432: Link e6:fa:f7:9a:d3:8c<-->37:5b:c5:ac:e5:08/192.168.1.110 up\n", + "2023-09-05 15:52:13,434: Added link cf4ecad7-3b24-4f8f-9de8-01b9f64b270b to connect e6:fa:f7:9a:d3:8c and 37:5b:c5:ac:e5:08/192.168.1.110\n", + "2023-09-05 15:52:13,436::ERROR::primaite.simulator.network.hardware.base::176::NIC 4f:4b:3f:f1:02:c0/192.168.10.110 cannot be enabled as it is not connected to a Link\n", + "2023-09-05 15:52:13,438: SwitchPort 57:0a:35:80:1c:38 connected to Link 57:0a:35:80:1c:38<-->4f:4b:3f:f1:02:c0/192.168.10.110\n", + "2023-09-05 15:52:13,440: Link 57:0a:35:80:1c:38<-->4f:4b:3f:f1:02:c0/192.168.10.110 up\n", + "2023-09-05 15:52:13,441: NIC 4f:4b:3f:f1:02:c0/192.168.10.110 connected to Link 57:0a:35:80:1c:38<-->4f:4b:3f:f1:02:c0/192.168.10.110\n", + "2023-09-05 15:52:13,443: Link 57:0a:35:80:1c:38<-->4f:4b:3f:f1:02:c0/192.168.10.110 up\n", + "2023-09-05 15:52:13,447: Added link 035d9749-1bf6-4bd5-b945-c931f207ffb9 to connect 57:0a:35:80:1c:38 and 4f:4b:3f:f1:02:c0/192.168.10.110\n" + ] + } + ], + "source": [ + "net = arcd_uc2_network()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "act_tree = net._action_manager.get_action_tree()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', 'eb6dfd45-d688-47cf-b061-5f45820a6bc7', 'enable']\n", + "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', 'eb6dfd45-d688-47cf-b061-5f45820a6bc7', 'disable']\n", + "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '2192673d-ad8c-437f-a4d6-0e222ab7e190', 'enable']\n", + "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '2192673d-ad8c-437f-a4d6-0e222ab7e190', 'disable']\n", + "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '3c3fb3d8-c5d1-41aa-8e3e-db1cc0445b0b', 'enable']\n", + "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '3c3fb3d8-c5d1-41aa-8e3e-db1cc0445b0b', 'disable']\n", + "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '29e90915-815f-4505-b957-6f46681950b3', 'enable']\n", + "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '29e90915-815f-4505-b957-6f46681950b3', 'disable']\n", + "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '0915f437-6ed3-4134-b754-7d903c98eb57', 'enable']\n", + "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '0915f437-6ed3-4134-b754-7d903c98eb57', 'disable']\n", + "['node', '9c7f4049-30fa-40bd-b0c8-2119bef7936c', 'nic', '199c9558-6a73-423e-9c69-ced05cd597cb', 'enable']\n", + "['node', '9c7f4049-30fa-40bd-b0c8-2119bef7936c', 'nic', '199c9558-6a73-423e-9c69-ced05cd597cb', 'disable']\n", + "['node', '88c26ce5-4243-4247-98a3-315ff54f7ef6', 'nic', '6f871129-d13e-4c8a-85ff-7102fa1e7b8e', 'enable']\n", + "['node', '88c26ce5-4243-4247-98a3-315ff54f7ef6', 'nic', '6f871129-d13e-4c8a-85ff-7102fa1e7b8e', 'disable']\n", + "['node', 'd7e5389a-9970-4c47-926c-9069b925e934', 'nic', 'b6c15c77-8869-400c-8a47-62856dd27ce6', 'enable']\n", + "['node', 'd7e5389a-9970-4c47-926c-9069b925e934', 'nic', 'b6c15c77-8869-400c-8a47-62856dd27ce6', 'disable']\n", + "['node', '02c25642-baa5-49a4-aadd-f5d549696351', 'nic', '398660cc-20ce-444e-b93e-d45b8b865e10', 'enable']\n", + "['node', '02c25642-baa5-49a4-aadd-f5d549696351', 'nic', '398660cc-20ce-444e-b93e-d45b8b865e10', 'disable']\n", + "['node', '6f89bce8-34e4-4fdf-b860-b34027efa639', 'nic', '43c0f913-a203-4436-8649-ab73363bd8cb', 'enable']\n", + "['node', '6f89bce8-34e4-4fdf-b860-b34027efa639', 'nic', '43c0f913-a203-4436-8649-ab73363bd8cb', 'disable']\n", + "['node', '15eb1a5c-50f4-4681-81f8-7ad457c6b1af', 'nic', '1d42ed40-b6f9-4dba-aa23-10143842aac8', 'enable']\n", + "['node', '15eb1a5c-50f4-4681-81f8-7ad457c6b1af', 'nic', '1d42ed40-b6f9-4dba-aa23-10143842aac8', 'disable']\n", + "['node', '5c5b1c84-5d06-4319-80c0-ca3adf9ce2c6', 'nic', 'f921e45e-5a11-4c87-bfe9-47bdba7d6828', 'enable']\n", + "['node', '5c5b1c84-5d06-4319-80c0-ca3adf9ce2c6', 'nic', 'f921e45e-5a11-4c87-bfe9-47bdba7d6828', 'disable']\n", + "['node', '5c5b1c84-5d06-4319-80c0-ca3adf9ce2c6', 'nic', '0ed5ed4a-e36f-4060-a13d-a7832d391887', 'enable']\n", + "['node', '5c5b1c84-5d06-4319-80c0-ca3adf9ce2c6', 'nic', '0ed5ed4a-e36f-4060-a13d-a7832d391887', 'disable']\n" + ] + } + ], + "source": [ + "for a in act_tree:\n", + " print(a)\n", + "simController.apply_action(\n", + " {\n", + " 'network':'', \n", + " 'node': '26e189bb-442e-4f73-ab7a-1c4dd162e986', \n", + " 'nic': 'eb6dfd45-d688-47cf-b061-5f45820a6bc7', \n", + " 'verb': 'enable', \n", + " 'options':{'...':'...'}\n", + " })\n", + "\n", + "a = {\n", + " 'target_type': 'network',\n", + " 'target_options': {\n", + " 'identifier': '',\n", + " 'target_type': '',\n", + " 'target_options': {\n", + " 'identifier': '',\n", + " \n", + " }\n", + " }\n", + "}\n", + "# ^ do something like this where the requests are k:v pairs instead, have a simple/similar approach " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index f6c0b5d9..0fbc33fd 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -1,7 +1,7 @@ # flake8: noqa """Core of the PrimAITE Simulator.""" from abc import ABC, abstractmethod -from typing import Callable, Dict, List, Optional, Union +from typing import Callable, ClassVar, Dict, List, Optional, Union from uuid import uuid4 from pydantic import BaseModel, ConfigDict @@ -42,7 +42,7 @@ class Action(BaseModel): the action can be performed or not. """ - func: Callable[[List[str], Dict], None] + func: Callable[[Dict], None] """ ``func`` is a function that accepts a request and a context dict. Typically this would be a lambda function that invokes a class method of your SimComponent. For example if the component is a node and the action is for @@ -74,7 +74,7 @@ class ActionManager(BaseModel): actions: Dict[str, Action] = {} """maps action verb to an action object.""" - def __call__(self, request: List[str], context: Dict) -> None: + def __call__(self, request: Dict, context: Dict) -> None: """ Process an action request. From 6b41bec32a2dcb279cd8b2bf02824dafca4d8d9a Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 6 Sep 2023 22:01:51 +0100 Subject: [PATCH 155/980] =?UTF-8?q?#1816=20-=20Added=20the=20final=20piece?= =?UTF-8?q?s=20of=20the=20puzzle=20to=20get=20data=20up=20from=20NIC=20?= =?UTF-8?q?=E2=86=92=20session=20manager=20=E2=86=92=20software=20manager?= =?UTF-8?q?=20=E2=86=92=20service.=20-=20Implemented=20a=20basic=20sim=20D?= =?UTF-8?q?B=20that=20matches=20UC2=20data=20manipulation=20DB=20in=20IY.?= =?UTF-8?q?=20-=20Added=20a=20test=20that=20confirms=20DB=20queries=20can?= =?UTF-8?q?=20be=20sent=20over=20the=20network.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulator/file_system/file_system.py | 24 ++-- .../simulator/network/hardware/base.py | 13 ++- src/primaite/simulator/network/networks.py | 37 ++++++ .../simulator/system/core/packet_capture.py | 8 ++ .../simulator/system/core/session_manager.py | 88 +++++++------- .../simulator/system/core/software_manager.py | 24 ++-- .../simulator/system/services/database.py | 107 +++++++++--------- src/primaite/simulator/system/software.py | 8 +- tests/conftest.py | 10 ++ .../system/test_database_on_node.py | 86 +++++++------- .../_file_system/test_file_system.py | 25 ++-- .../_file_system/test_file_system_file.py | 23 ---- .../_file_system/test_file_system_folder.py | 75 ------------ .../test_data_manipulator_service.py | 2 +- .../_system/_services/test_database.py | 68 +++++++++-- 15 files changed, 300 insertions(+), 298 deletions(-) delete mode 100644 tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py delete mode 100644 tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index a5744b4b..d5e81e1b 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -2,6 +2,7 @@ from __future__ import annotations import math import os.path +import shutil from abc import abstractmethod from pathlib import Path from typing import Dict, Optional @@ -220,22 +221,14 @@ class FileSystem(SimComponent): dst_folder = self.create_folder(dst_folder_name) # add file to dst dst_folder.add_file(file) + if file.real: + old_sim_path = file.sim_path + file.sim_path = file.folder.fs.sim_root / file.path + file.sim_path.parent.mkdir(exist_ok=True) + shutil.move(old_sim_path, file.sim_path) def copy_file(self, src_folder_name: str, src_file_name: str, dst_folder_name): - """ - Copies a file from one folder to another. - can provide - - :param file: The file to move - :type: file: File - - :param src_folder: The folder where the file is located - :type: Folder - - :param target_folder: The folder where the file should be moved to - :type: Folder - """ file = self.get_file(folder_name=src_folder_name, file_name=src_file_name) if file: dst_folder = self.get_folder(folder_name=dst_folder_name) @@ -243,6 +236,9 @@ class FileSystem(SimComponent): dst_folder = self.create_folder(dst_folder_name) new_file = file.make_copy(dst_folder=dst_folder) dst_folder.add_file(new_file) + if file.real: + new_file.sim_path.parent.mkdir(exist_ok=True) + shutil.copy2(file.sim_path, new_file.sim_path) def get_folder(self, folder_name: str) -> Optional[Folder]: """ @@ -419,7 +415,7 @@ class File(FileSystemItemABC): pass def make_copy(self, dst_folder: Folder) -> File: - return File(folder=dst_folder, **self.model_dump(exclude={"uuid", "folder"})) + return File(folder=dst_folder, **self.model_dump(exclude={"uuid", "folder", "sim_path"})) @property def path(self): diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index dcad59f8..832e6a13 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -921,16 +921,19 @@ class Node(SimComponent): kwargs["icmp"] = ICMP(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp")) if not kwargs.get("session_manager"): kwargs["session_manager"] = SessionManager(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp")) - if not kwargs.get("software_manager"): - kwargs["software_manager"] = SoftwareManager( - sys_log=kwargs.get("sys_log"), session_manager=kwargs.get("session_manager") - ) if not kwargs.get("root"): kwargs["root"] = SIM_OUTPUT / kwargs["hostname"] if not kwargs.get("file_system"): kwargs["file_system"] = FileSystem(sys_log=kwargs["sys_log"], sim_root=kwargs["root"] / "fs") + if not kwargs.get("software_manager"): + kwargs["software_manager"] = SoftwareManager( + sys_log=kwargs.get("sys_log"), + session_manager=kwargs.get("session_manager"), + file_system=kwargs.get("file_system") + ) super().__init__(**kwargs) self.arp.nics = self.nics + self.session_manager.software_manager = self.software_manager def describe_state(self) -> Dict: """ @@ -1097,6 +1100,8 @@ class Node(SimComponent): if frame.ip.protocol == IPProtocol.TCP: if frame.tcp.src_port == Port.ARP: self.arp.process_arp_packet(from_nic=from_nic, arp_packet=frame.arp) + else: + self.session_manager.receive_frame(frame) elif frame.ip.protocol == IPProtocol.UDP: pass elif frame.ip.protocol == IPProtocol.ICMP: diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 6a50fe3f..cecb108d 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -6,6 +6,7 @@ from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.database import DatabaseService def client_server_routed() -> Network: @@ -160,6 +161,39 @@ def arcd_uc2_network() -> Network: database_server.power_on() network.connect(endpoint_b=database_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[3]) + ddl = """ + CREATE TABLE IF NOT EXISTS user ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name VARCHAR(50) NOT NULL, + email VARCHAR(50) NOT NULL, + age INT, + city VARCHAR(50), + occupation VARCHAR(50) + );""" + + user_insert_statements = [ + "INSERT INTO user (name, email, age, city, occupation) VALUES ('John Doe', 'johndoe@example.com', 32, 'New York', 'Engineer');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Jane Smith', 'janesmith@example.com', 27, 'Los Angeles', 'Designer');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Bob Johnson', 'bobjohnson@example.com', 45, 'Chicago', 'Manager');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Alice Lee', 'alicelee@example.com', 22, 'San Francisco', 'Student');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('David Kim', 'davidkim@example.com', 38, 'Houston', 'Consultant');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Emily Chen', 'emilychen@example.com', 29, 'Seattle', 'Software Developer');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Frank Wang', 'frankwang@example.com', 55, 'New York', 'Entrepreneur');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Grace Park', 'gracepark@example.com', 31, 'Los Angeles', 'Marketing Specialist');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Henry Wu', 'henrywu@example.com', 40, 'Chicago', 'Accountant');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Isabella Kim', 'isabellakim@example.com', 26, 'San Francisco', 'Graphic Designer');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Jake Lee', 'jakelee@example.com', 33, 'Houston', 'Sales Manager');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Kelly Chen', 'kellychen@example.com', 28, 'Seattle', 'Web Developer');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Lucas Liu', 'lucasliu@example.com', 42, 'New York', 'Lawyer');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Maggie Wang', 'maggiewang@example.com', 30, 'Los Angeles', 'Data Analyst');", + ] + database_server.software_manager.add_service(DatabaseService) + database: DatabaseService = database_server.software_manager.services["Database"] # noqa + database.start() + database._process_sql(ddl) # noqa + for insert_statement in user_insert_statements: + database._process_sql(insert_statement) # noqa + # Backup Server backup_server = Server( hostname="backup_server", ip_address="192.168.1.16", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" @@ -183,4 +217,7 @@ def arcd_uc2_network() -> Network: router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER) + + return network diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index f4521096..79e3630a 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -1,3 +1,4 @@ +import json import logging from pathlib import Path from typing import Optional @@ -51,6 +52,13 @@ class PacketCapture: self.logger.addFilter(_JSONFilter()) + def read(self): + frames = [] + with open(self._get_log_path(), "r") as file: + while line := file.readline(): + frames.append(json.loads(line.rstrip())) + return frames + @property def _logger_name(self) -> str: """Get PCAP the logger name.""" diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index be20a28d..aa73410f 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -32,15 +32,14 @@ class Session(SimComponent): """ protocol: IPProtocol - src_ip_address: IPv4Address - dst_ip_address: IPv4Address + with_ip_address: IPv4Address src_port: Optional[Port] dst_port: Optional[Port] connected: bool = False @classmethod def from_session_key( - cls, session_key: Tuple[IPProtocol, IPv4Address, IPv4Address, Optional[Port], Optional[Port]] + cls, session_key: Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]] ) -> Session: """ Create a Session instance from a session key tuple. @@ -48,11 +47,10 @@ class Session(SimComponent): :param session_key: Tuple containing the session details. :return: A Session instance. """ - protocol, src_ip_address, dst_ip_address, src_port, dst_port = session_key + protocol, with_ip_address, src_port, dst_port = session_key return Session( protocol=protocol, - src_ip_address=src_ip_address, - dst_ip_address=dst_ip_address, + with_ip_address=with_ip_address, src_port=src_port, dst_port=dst_port, ) @@ -99,8 +97,8 @@ class SessionManager: @staticmethod def _get_session_key( - frame: Frame, from_source: bool = True - ) -> Tuple[IPProtocol, IPv4Address, IPv4Address, Optional[Port], Optional[Port]]: + frame: Frame, inbound_frame: bool = True + ) -> Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]]: """ Extracts the session key from the given frame. @@ -112,38 +110,38 @@ class SessionManager: - Optional[Port]: The destination port number (if applicable). :param frame: The network frame from which to extract the session key. - :param from_source: A flag to indicate if the key should be extracted from the source or destination. :return: A tuple containing the session key. """ protocol = frame.ip.protocol - src_ip_address = frame.ip.src_ip_address - dst_ip_address = frame.ip.dst_ip_address + with_ip_address = frame.ip.src_ip_address if protocol == IPProtocol.TCP: - if from_source: + if inbound_frame: src_port = frame.tcp.src_port dst_port = frame.tcp.dst_port else: dst_port = frame.tcp.src_port src_port = frame.tcp.dst_port + with_ip_address = frame.ip.dst_ip_address elif protocol == IPProtocol.UDP: - if from_source: + if inbound_frame: src_port = frame.udp.src_port dst_port = frame.udp.dst_port else: dst_port = frame.udp.src_port src_port = frame.udp.dst_port + with_ip_address = frame.ip.dst_ip_address else: src_port = None dst_port = None - return protocol, src_ip_address, dst_ip_address, src_port, dst_port + return protocol, with_ip_address, src_port, dst_port def receive_payload_from_software_manager( - self, - payload: Any, - dest_ip_address: Optional[IPv4Address] = None, - dest_port: Optional[Port] = None, - session_id: Optional[str] = None, - is_reattempt: bool = False, + self, + payload: Any, + dst_ip_address: Optional[IPv4Address] = None, + dst_port: Optional[Port] = None, + session_id: Optional[str] = None, + is_reattempt: bool = False, ) -> Union[Any, None]: """ Receive a payload from the SoftwareManager. @@ -154,23 +152,21 @@ class SessionManager: :param session_id: The Session ID the payload is to originate from. Optional. If None, one will be created. """ if session_id: - dest_ip_address = self.sessions_by_uuid[session_id].dst_ip_address - dest_port = self.sessions_by_uuid[session_id].dst_port + session = self.sessions_by_uuid[session_id] + dst_ip_address = self.sessions_by_uuid[session_id].with_ip_address + dst_port = self.sessions_by_uuid[session_id].dst_port - dst_mac_address = self.arp_cache.get_arp_cache_mac_address(dest_ip_address) + dst_mac_address = self.arp_cache.get_arp_cache_mac_address(dst_ip_address) if dst_mac_address: - outbound_nic = self.arp_cache.get_arp_cache_nic(dest_ip_address) + outbound_nic = self.arp_cache.get_arp_cache_nic(dst_ip_address) else: if not is_reattempt: - self.arp_cache.send_arp_request(dest_ip_address) + self.arp_cache.send_arp_request(dst_ip_address) return self.receive_payload_from_software_manager( - payload=payload, - dest_ip_address=dest_ip_address, - dest_port=dest_port, - session_id=session_id, - is_reattempt=True, - ) + payload=payload, dst_ip_address=dst_ip_address, dst_port=dst_port, session_id=session_id, + is_reattempt=True + ) else: return @@ -178,17 +174,17 @@ class SessionManager: ethernet=EthernetHeader(src_mac_addr=outbound_nic.mac_address, dst_mac_addr=dst_mac_address), ip=IPPacket( src_ip_address=outbound_nic.ip_address, - dst_ip_address=dest_ip_address, + dst_ip_address=dst_ip_address, ), tcp=TCPHeader( - src_port=dest_port, - dst_port=dest_port, + src_port=dst_port, + dst_port=dst_port, ), payload=payload, ) if not session_id: - session_key = self._get_session_key(frame, from_source=True) + session_key = self._get_session_key(frame, inbound_frame=False) session = self.sessions_by_key.get(session_key) if not session: # Create new session @@ -198,33 +194,25 @@ class SessionManager: outbound_nic.send_frame(frame) - def send_payload_to_software_manager(self, payload: Any, session_id: int): + def receive_frame(self, frame: Frame): """ - Send a payload to the software manager. - - :param payload: The payload to be sent. - :param session_id: The Session ID the payload originates from. - """ - self.software_manager.receive_payload_from_session_manger() - - def receive_payload_from_nic(self, frame: Frame): - """ - Receive a Frame from the NIC. + Receive a Frame. Extract the session key using the _get_session_key method, and forward the payload to the appropriate session. If the session does not exist, a new one is created. :param frame: The frame being received. """ - session_key = self._get_session_key(frame) - session = self.sessions_by_key.get(session_key) + session_key = self._get_session_key(frame, inbound_frame=True) + session: Session = self.sessions_by_key.get(session_key) if not session: # Create new session session = Session.from_session_key(session_key) self.sessions_by_key[session_key] = session self.sessions_by_uuid[session.uuid] = session - self.software_manager.receive_payload_from_session_manger(payload=frame, session=session) - # TODO: Implement the frame deconstruction and send to SoftwareManager. + self.software_manager.receive_payload_from_session_manger( + payload=frame.payload, port=frame.tcp.dst_port, protocol=frame.ip.protocol, session_id=session.uuid + ) def show(self, markdown: bool = False): """ diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index 28e37963..d46cb21c 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -3,6 +3,7 @@ from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING, Union from prettytable import MARKDOWN, PrettyTable +from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application @@ -23,7 +24,7 @@ ServiceClass = TypeVar("ServiceClass", bound=Service) class SoftwareManager: """A class that manages all running Services and Applications on a Node and facilitates their communication.""" - def __init__(self, session_manager: "SessionManager", sys_log: "SysLog"): + def __init__(self, session_manager: "SessionManager", sys_log: SysLog, file_system: FileSystem): """ Initialize a new instance of SoftwareManager. @@ -34,6 +35,7 @@ class SoftwareManager: self.applications: Dict[str, Application] = {} self.port_protocol_mapping: Dict[Tuple[Port, IPProtocol], Union[Service, Application]] = {} self.sys_log: SysLog = sys_log + self.file_system: FileSystem = file_system def add_service(self, service_class: Type[ServiceClass]): """ @@ -41,7 +43,7 @@ class SoftwareManager: :param: service_class: The class of the service to add """ - service = service_class(software_manager=self, sys_log=self.sys_log) + service = service_class(software_manager=self, sys_log=self.sys_log, file_system=self.file_system) service.software_manager = self self.services[service.name] = service @@ -86,7 +88,7 @@ class SoftwareManager: payload: Any, dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = None, - session_id: Optional[int] = None, + session_id: Optional[str] = None, ): """ Send a payload to the SessionManager. @@ -97,21 +99,21 @@ class SoftwareManager: :param session_id: The Session ID the payload is to originate from. Optional. """ self.session_manager.receive_payload_from_software_manager( - payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id - ) + payload=payload, dst_ip_address=dest_ip_address, dst_port=dest_port, session_id=session_id + ) - def receive_payload_from_session_manger(self, payload: Any, session: Session): + def receive_payload_from_session_manger(self, payload: Any, port: Port, protocol: IPProtocol, session_id: str): """ Receive a payload from the SessionManager and forward it to the corresponding service or application. :param payload: The payload being received. :param session: The transport session the payload originates from. """ - # receiver: Optional[Union[Service, Application]] = self.port_protocol_mapping.get((port, protocol), None) - # if receiver: - # receiver.receive_payload(None, payload) - # else: - # raise ValueError(f"No service or application found for port {port} and protocol {protocol}") + receiver: Optional[Union[Service, Application]] = self.port_protocol_mapping.get((port, protocol), None) + if receiver: + receiver.receive(payload=payload, session_id=session_id) + else: + self.sys_log.error(f"No service or application found for port {port} and protocol {protocol}") pass def show(self, markdown: bool = False): diff --git a/src/primaite/simulator/system/services/database.py b/src/primaite/simulator/system/services/database.py index 67ee5cc3..7666597c 100644 --- a/src/primaite/simulator/system/services/database.py +++ b/src/primaite/simulator/system/services/database.py @@ -1,15 +1,61 @@ -from typing import Dict +import sqlite3 +from ipaddress import IPv4Address +from sqlite3 import OperationalError +from typing import Dict, Optional, Any, List, Union -from primaite.simulator.file_system.file_type import FileType -from primaite.simulator.network.hardware.base import Node +from prettytable import PrettyTable, MARKDOWN + +from primaite.simulator.file_system.file_system import File +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.services.service import Service class DatabaseService(Service): """A generic SQL Server Service.""" + backup_server: Optional[IPv4Address] = None + "The IP Address of the server the " def __init__(self, **kwargs): + kwargs["name"] = "Database" + kwargs["port"] = Port.POSTGRES_SERVER + kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) + self._db_file: File + self._create_db_file() + self._conn = sqlite3.connect(self._db_file.sim_path) + self._cursor = self._conn.cursor() + + def tables(self) -> List[str]: + sql = "SELECT name FROM sqlite_master WHERE type='table' AND name != 'sqlite_sequence';" + results = self._process_sql(sql) + return [row[0] for row in results["data"]] + + def show(self, markdown: bool = False): + """Prints a Table names in the Database.""" + table = PrettyTable(["Table"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"{self.file_system.sys_log.hostname} Database" + for row in self.tables(): + table.add_row([row]) + print(table) + + def _create_db_file(self): + self._db_file: File = self.file_system.create_file(folder_name="database", file_name="database.db", real=True) + self.folder = self._db_file.folder + + def _process_sql(self, query: str) -> Dict[str, Union[int, List[Any]]]: + try: + self._cursor.execute(query) + self._conn.commit() + except OperationalError: + # Handle the case where the table does not exist. + return {"status_code": 404, "data": []} + + return {"status_code": 200, "data": self._cursor.fetchall()} def describe_state(self) -> Dict: """ @@ -22,53 +68,12 @@ class DatabaseService(Service): """ return super().describe_state() - @classmethod - def install(cls, node: Node): + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + result = self._process_sql(payload) + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager(payload=result, session_id=session_id) + return result["status_code"] - def uninstall(self) -> None: - """ - Undo installation procedure. - - This method deletes files created when installing the database, and the database folder if it is empty. - """ - super().uninstall() - node: Node = self.parent - node.file_system.delete_file(self.primary_store) - node.file_system.delete_file(self.transaction_log) - if self.secondary_store: - node.file_system.delete_file(self.secondary_store) - if len(self.folder.files) == 0: - node.file_system.delete_folder(self.folder) - - def install(self) -> None: - """Perform first time install on a node, creating necessary files.""" - super().install() - assert isinstance(self.parent, Node), "Database install can only happen after the db service is added to a node" - self._setup_files() - - def _setup_files( - self, - folder_name: str = "database", - ): - """Set up files that are required by the database on the parent host. - - :param folder_name: Name of the folder which will be setup to hold the db files, defaults to "database" - :type folder_name: str, optional - """ - # note that this parent.file_system.create_folder call in the future will be authenticated by using permissions - # handler. This permission will be granted based on service account given to the database service. - self.parent: Node - self.folder = self.parent.file_system.create_folder(folder_name) - self.primary_store = self.parent.file_system.create_file( - "db_primary_store", db_size, FileType.MDF, folder=self.folder - ) - self.transaction_log = self.parent.file_system.create_file( - "db_transaction_log", "1", FileType.LDF, folder=self.folder - ) - if use_secondary_db_file: - self.secondary_store = self.parent.file_system.create_file( - "db_secondary_store", secondary_db_size, FileType.NDF, folder=self.folder - ) - else: - self.secondary_store = None + def send(self, payload: Any, session_id: str, **kwargs) -> bool: + pass diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 7f206311..70c1bbf2 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -1,8 +1,9 @@ from abc import abstractmethod from enum import Enum -from typing import Any, Dict +from typing import Any, Dict, Optional from primaite.simulator.core import Action, ActionManager, SimComponent +from primaite.simulator.file_system.file_system import FileSystem, Folder from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.sys_log import SysLog @@ -79,6 +80,10 @@ class Software(SimComponent): "An instance of Software Manager that is used by the parent node." sys_log: SysLog = None "An instance of SysLog that is used by the parent node." + file_system: FileSystem + "The FileSystem of the Node the Software is installed on." + folder: Optional[Folder] = None + "The folder on the file system the Software uses." def _init_action_manager(self) -> ActionManager: am = super()._init_action_manager() @@ -216,7 +221,6 @@ class IOSoftware(Software): :param kwargs: Additional keyword arguments specific to the implementation. :return: True if the payload was successfully sent, False otherwise. """ - pass def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ diff --git a/tests/conftest.py b/tests/conftest.py index f1c05187..5570e21f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,7 +19,17 @@ ACTION_SPACE_NODE_ACTION_VALUES = 1 _LOGGER = getLogger(__name__) +# PrimAITE v3 stuff +from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.network.hardware.base import Node + +@pytest.fixture(scope="function") +def file_system() -> FileSystem: + return Node(hostname="fs_node").file_system + + +#PrimAITE v2 stuff class TempPrimaiteSession(PrimaiteSession): """ A temporary PrimaiteSession class. diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index ef2a58e4..0d66137b 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -1,52 +1,46 @@ -from primaite.simulator.network.hardware.base import Node -from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.services.database import DatabaseService -from primaite.simulator.system.services.service import ServiceOperatingState -from primaite.simulator.system.software import SoftwareCriticality, SoftwareHealthState +from ipaddress import IPv4Address + +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.networks import arcd_uc2_network +from primaite.simulator.network.transmission.data_link_layer import Frame, EthernetHeader +from primaite.simulator.network.transmission.network_layer import IPPacket, Precedence +from primaite.simulator.network.transmission.transport_layer import TCPHeader, Port -def test_installing_database(): - db = DatabaseService( - name="SQL-database", - health_state_actual=SoftwareHealthState.GOOD, - health_state_visible=SoftwareHealthState.GOOD, - criticality=SoftwareCriticality.MEDIUM, - port=Port.SQL_SERVER, - operating_state=ServiceOperatingState.RUNNING, +def test_database_query_across_the_network(): + """Tests DB query across the network returns HTTP status 200 and date.""" + network = arcd_uc2_network() + + client_1: Computer = network.get_node_by_hostname("client_1") + + client_1.arp.send_arp_request(IPv4Address("192.168.1.14")) + + dst_mac_address = client_1.arp.get_arp_cache_mac_address(IPv4Address("192.168.1.14")) + + outbound_nic = client_1.arp.get_arp_cache_nic(IPv4Address("192.168.1.14")) + client_1.ping("192.168.1.14") + + + frame = Frame( + ethernet=EthernetHeader( + src_mac_addr=client_1.ethernet_port[1].mac_address, + dst_mac_addr=dst_mac_address + ), + ip=IPPacket( + src_ip_address=client_1.ethernet_port[1].ip_address, + dst_ip_address=IPv4Address("192.168.1.14"), + precedence=Precedence.FLASH + ), + tcp=TCPHeader( + src_port=Port.POSTGRES_SERVER, + dst_port=Port.POSTGRES_SERVER + ), + payload="SELECT * FROM user;" ) - node = Node(hostname="db-server") + outbound_nic.send_frame(frame) - node.install_service(db) + client_1_last_payload = outbound_nic.pcap.read()[-1]["payload"] - assert db in node - - file_exists = False - for folder in node.file_system.folders.values(): - for file in folder.files.values(): - if file.name == "db_primary_store": - file_exists = True - break - if file_exists: - break - assert file_exists - - -def test_uninstalling_database(): - db = DatabaseService( - name="SQL-database", - health_state_actual=SoftwareHealthState.GOOD, - health_state_visible=SoftwareHealthState.GOOD, - criticality=SoftwareCriticality.MEDIUM, - port=Port.SQL_SERVER, - operating_state=ServiceOperatingState.RUNNING, - ) - - node = Node(hostname="db-server") - - node.install_service(db) - - node.uninstall_service(db) - - assert db not in node - assert node.file_system.get_folder("database") is None + assert client_1_last_payload["status_code"] == 200 + assert client_1_last_payload["data"] \ No newline at end of file diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 136961e2..d1d78003 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -1,19 +1,13 @@ import pytest -from primaite.simulator.file_system.file_system import File, FileSystem, Folder +from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.file_system.file_type import FileType -from primaite.simulator.network.hardware.base import Node - - -@pytest.fixture(scope="function") -def file_system() -> FileSystem: - return Node(hostname="fs_node").file_system def test_create_folder_and_file(file_system): """Test creating a folder and a file.""" assert len(file_system.folders) == 1 - test_folder = file_system.create_folder(folder_name="test_folder") + file_system.create_folder(folder_name="test_folder") assert len(file_system.folders) is 2 file_system.create_file(file_name="test_file.txt", folder_name="test_folder") @@ -115,7 +109,7 @@ def test_copy_file(file_system): file_system.create_folder(folder_name="src_folder") file_system.create_folder(folder_name="dst_folder") - file = file_system.create_file(file_name="test_file.txt", size=10, folder_name="src_folder") + file = file_system.create_file(file_name="test_file.txt", size=10, folder_name="src_folder", real=True) original_uuid = file.uuid assert len(file_system.get_folder("src_folder").files) == 1 @@ -128,6 +122,19 @@ def test_copy_file(file_system): assert file_system.get_file("dst_folder", "test_file.txt").uuid != original_uuid +def test_folder_quarantine_state(file_system): + """Tests the changing of folder quarantine status.""" + folder = file_system.get_folder("root") + + assert folder.quarantine_status() is False + + folder.quarantine() + assert folder.quarantine_status() is True + + folder.unquarantine() + assert folder.quarantine_status() is False + + @pytest.mark.skip(reason="Skipping until we tackle serialisation") def test_serialisation(file_system): """Test to check that the object serialisation works correctly.""" diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py deleted file mode 100644 index 981550f3..00000000 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_file.py +++ /dev/null @@ -1,23 +0,0 @@ -from primaite.simulator.file_system.file_system import File -from primaite.simulator.file_system.file_type import FileType - - -def test_file_type(): - """Tests tha the File type is set correctly.""" - file = File(name="test", file_type=FileType.DOC) - assert file.file_type is FileType.DOC - - -def test_get_size(): - """Tests that the file size is being returned properly.""" - file = File(name="test", size=1.5) - assert file.size == 1.5 - - -def test_serialisation(): - """Test to check that the object serialisation works correctly.""" - file = File(name="test", size=1.5, file_type=FileType.DOC) - serialised_file = file.model_dump_json() - deserialised_file = File.model_validate_json(serialised_file) - - assert file.model_dump_json() == deserialised_file.model_dump_json() diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py deleted file mode 100644 index 72684146..00000000 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_folder.py +++ /dev/null @@ -1,75 +0,0 @@ -from primaite.simulator.file_system.file_system import File -from primaite.simulator.file_system.file_system_folder import Folder -from primaite.simulator.file_system.file_type import FileType - - -def test_adding_removing_file(): - """Test the adding and removing of a file from a folder.""" - folder = Folder(name="test") - - file = File(name="test_file", size=10, file_type=FileType.DOC) - - folder.add_file(file) - assert folder.size == 10 - assert len(folder.files) is 1 - - folder.remove_file(file) - assert folder.size == 0 - assert len(folder.files) is 0 - - -def test_remove_non_existent_file(): - """Test the removing of a file that does not exist.""" - folder = Folder(name="test") - - file = File(name="test_file", size=10, file_type=FileType.DOC) - not_added_file = File(name="fake_file", size=10, file_type=FileType.DOC) - - folder.add_file(file) - assert folder.size == 10 - assert len(folder.files) is 1 - - folder.remove_file(not_added_file) - assert folder.size == 10 - assert len(folder.files) is 1 - - -def test_get_file_by_id(): - """Test to make sure that the correct file is returned.""" - folder = Folder(name="test") - - file = File(name="test_file", size=10, file_type=FileType.DOC) - file2 = File(name="test_file_2", size=10, file_type=FileType.DOC) - - folder.add_file(file) - folder.add_file(file2) - assert folder.size == 20 - assert len(folder.files) is 2 - - assert folder.get_file_by_id(file_id=file.uuid) is file - - -def test_folder_quarantine_state(): - """Tests the changing of folder quarantine status.""" - folder = Folder(name="test") - - assert folder.quarantine_status() is False - - folder.quarantine() - assert folder.quarantine_status() is True - - folder.unquarantine() - assert folder.quarantine_status() is False - - -def test_serialisation(): - """Test to check that the object serialisation works correctly.""" - folder = Folder(name="test") - file = File(name="test_file", size=10, file_type=FileType.DOC) - folder.add_file(file) - - serialised_folder = folder.model_dump_json() - - deserialised_folder = Folder.model_validate_json(serialised_folder) - - assert folder.model_dump_json() == deserialised_folder.model_dump_json() diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py index f5b37175..9496a50e 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py @@ -29,4 +29,4 @@ def test_creation(): assert False, f"Test was not supposed to throw exception: {e}" # there should be a session after the service is started - assert len(client_1.session_manager.sessions_by_uuid) == 1 + assert len(client_1.session_manager.sessions_by_uuid) == 1 \ No newline at end of file diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py index ebc5536f..acc05d17 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py @@ -1,15 +1,59 @@ -from primaite.simulator.network.transmission.transport_layer import Port +import json + +import pytest + +from primaite.simulator.network.hardware.base import Node from primaite.simulator.system.services.database import DatabaseService -from primaite.simulator.system.services.service import ServiceOperatingState -from primaite.simulator.system.software import SoftwareCriticality, SoftwareHealthState + +DDL = """ +CREATE TABLE IF NOT EXISTS user ( +id INTEGER PRIMARY KEY AUTOINCREMENT, +name VARCHAR(50) NOT NULL, +email VARCHAR(50) NOT NULL, +age INT, +city VARCHAR(50), +occupation VARCHAR(50) +);""" + +USER_INSERT_STATEMENTS = [ + "INSERT INTO user (name, email, age, city, occupation) VALUES ('John Doe', 'johndoe@example.com', 32, 'New York', 'Engineer');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Jane Smith', 'janesmith@example.com', 27, 'Los Angeles', 'Designer');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Bob Johnson', 'bobjohnson@example.com', 45, 'Chicago', 'Manager');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Alice Lee', 'alicelee@example.com', 22, 'San Francisco', 'Student');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('David Kim', 'davidkim@example.com', 38, 'Houston', 'Consultant');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Emily Chen', 'emilychen@example.com', 29, 'Seattle', 'Software Developer');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Frank Wang', 'frankwang@example.com', 55, 'New York', 'Entrepreneur');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Grace Park', 'gracepark@example.com', 31, 'Los Angeles', 'Marketing Specialist');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Henry Wu', 'henrywu@example.com', 40, 'Chicago', 'Accountant');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Isabella Kim', 'isabellakim@example.com', 26, 'San Francisco', 'Graphic Designer');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Jake Lee', 'jakelee@example.com', 33, 'Houston', 'Sales Manager');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Kelly Chen', 'kellychen@example.com', 28, 'Seattle', 'Web Developer');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Lucas Liu', 'lucasliu@example.com', 42, 'New York', 'Lawyer');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Maggie Wang', 'maggiewang@example.com', 30, 'Los Angeles', 'Data Analyst');", +] -def test_creation(): - db = DatabaseService( - name="SQL-database", - health_state_actual=SoftwareHealthState.GOOD, - health_state_visible=SoftwareHealthState.GOOD, - criticality=SoftwareCriticality.MEDIUM, - port=Port.SQL_SERVER, - operating_state=ServiceOperatingState.RUNNING, - ) +@pytest.fixture(scope="function") +def database_server() -> Node: + node = Node(hostname="db_node") + node.software_manager.add_service(DatabaseService) + node.software_manager.services["Database"].start() + return node + + +@pytest.fixture(scope="function") +def database(database_server) -> DatabaseService: + database: DatabaseService = database_server.software_manager.services["Database"] # noqa + database.receive(DDL, None) + for script in USER_INSERT_STATEMENTS: + database.receive(script, None) + return database + + +def test_creation(database_server): + database_server.software_manager.show() + + +def test_db_population(database): + database.show() + assert database.tables() == ["user"] \ No newline at end of file From 2f744af34e16c4ef2359468445f63c7f00b2bdc9 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 6 Sep 2023 22:26:23 +0100 Subject: [PATCH 156/980] =?UTF-8?q?#1816=20-=20Added=20the=20final=20piece?= =?UTF-8?q?s=20of=20the=20puzzle=20to=20get=20data=20up=20from=20NIC=20?= =?UTF-8?q?=E2=86=92=20session=20manager=20=E2=86=92=20software=20manager?= =?UTF-8?q?=20=E2=86=92=20service.=20-=20Implemented=20a=20basic=20sim=20D?= =?UTF-8?q?B=20that=20matches=20UC2=20data=20manipulation=20DB=20in=20IY.?= =?UTF-8?q?=20-=20Added=20a=20test=20that=20confirms=20DB=20queries=20can?= =?UTF-8?q?=20be=20sent=20over=20the=20network.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulator/file_system/file_system.py | 118 +++++++++++++++--- .../simulator/network/hardware/base.py | 2 +- src/primaite/simulator/network/networks.py | 29 +++-- .../simulator/system/core/packet_capture.py | 9 +- .../simulator/system/core/session_manager.py | 27 ++-- .../simulator/system/core/software_manager.py | 3 +- .../simulator/system/services/database.py | 41 ++++-- tests/conftest.py | 2 +- .../system/test_database_on_node.py | 21 ++-- .../test_data_manipulator_service.py | 2 +- .../_system/_services/test_database.py | 2 +- 11 files changed, 180 insertions(+), 76 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index d5e81e1b..b2037729 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -3,7 +3,6 @@ from __future__ import annotations import math import os.path import shutil -from abc import abstractmethod from pathlib import Path from typing import Dict, Optional @@ -17,7 +16,7 @@ from primaite.simulator.system.core.sys_log import SysLog _LOGGER = getLogger(__name__) -def convert_size(size_bytes): +def convert_size(size_bytes: int) -> str: """ Convert a file size from bytes to a string with a more human-readable format. @@ -44,7 +43,11 @@ def convert_size(size_bytes): class FileSystemItemABC(SimComponent): - """Abstract base class for file system items used in the file system simulation.""" + """ + Abstract base class for file system items used in the file system simulation. + + :ivar name: The name of the FileSystemItemABC. + """ name: str "The name of the FileSystemItemABC." @@ -64,7 +67,15 @@ class FileSystemItemABC(SimComponent): return state @property - def size_str(self): + def size_str(self) -> str: + """ + Get the file size in a human-readable string format. + + This property makes use of the :func:`convert_size` function to convert the `self.size` attribute to a string + that is easier to read and understand. + + :return: The human-readable string representation of the file size. + """ return convert_size(self.size) @@ -84,11 +95,21 @@ class FileSystem(SimComponent): self.create_folder("root") @property - def size(self): + def size(self) -> int: + """ + Calculate and return the total size of all folders in the file system. + + :return: The sum of the sizes of all folders in the file system. + """ return sum(folder.size for folder in self.folders.values()) def show(self, markdown: bool = False, full: bool = False): - """Prints a of the FileSystem""" + """ + Prints a table of the FileSystem, displaying either just folders or full files. + + :param markdown: Flag indicating if output should be in markdown format. + :param full: Flag indicating if to show full files. + """ headers = ["Folder", "Size"] if full: headers[0] = "File Path" @@ -171,7 +192,6 @@ class FileSystem(SimComponent): :param folder_name: The folder to add the file to. :param real: "Indicates whether the File is actually a real file in the Node sim fs output." """ - if folder_name: # check if file with name already exists folder = self._folders_by_name.get(folder_name) @@ -196,12 +216,25 @@ class FileSystem(SimComponent): return file def get_file(self, folder_name: str, file_name: str) -> Optional[File]: + """ + Retrieve a file by its name from a specific folder. + + :param folder_name: The name of the folder where the file resides. + :param file_name: The name of the file to be retrieved, including its extension. + :return: An instance of File if it exists, otherwise `None`. + """ folder = self.get_folder(folder_name) if folder: return folder.get_file(file_name) self.fs.sys_log.info(f"file not found /{folder_name}/{file_name}") def delete_file(self, folder_name: str, file_name: str): + """ + Delete a file by its name from a specific folder. + + :param folder_name: The name of the folder containing the file. + :param file_name: The name of the file to be deleted, including its extension. + """ folder = self.get_folder(folder_name) if folder: file = folder.get_file(file_name) @@ -209,7 +242,14 @@ class FileSystem(SimComponent): folder.remove_file(file) self.sys_log.info(f"Deleted file /{file.path}") - def move_file(self, src_folder_name: str, src_file_name: str, dst_folder_name): + def move_file(self, src_folder_name: str, src_file_name: str, dst_folder_name: str): + """ + Move a file from one folder to another. + + :param src_folder_name: The name of the source folder containing the file. + :param src_file_name: The name of the file to be moved. + :param dst_folder_name: The name of the destination folder. + """ file = self.get_file(folder_name=src_folder_name, file_name=src_file_name) if file: src_folder = file.folder @@ -227,8 +267,14 @@ class FileSystem(SimComponent): file.sim_path.parent.mkdir(exist_ok=True) shutil.move(old_sim_path, file.sim_path) - def copy_file(self, src_folder_name: str, src_file_name: str, dst_folder_name): + def copy_file(self, src_folder_name: str, src_file_name: str, dst_folder_name: str): + """ + Copy a file from one folder to another. + :param src_folder_name: The name of the source folder containing the file. + :param src_file_name: The name of the file to be copied. + :param dst_folder_name: The name of the destination folder. + """ file = self.get_file(folder_name=src_folder_name, file_name=src_file_name) if file: dst_folder = self.get_folder(folder_name=dst_folder_name) @@ -283,7 +329,11 @@ class Folder(FileSystemItemABC): return state def show(self, markdown: bool = False): - """Prints a of the Folder""" + """ + Display the contents of the Folder in tabular format. + + :param markdown: Whether to display the table in Markdown format or not. Default is `False`. + """ table = PrettyTable(["File", "Size"]) if markdown: table.set_style(MARKDOWN) @@ -294,7 +344,13 @@ class Folder(FileSystemItemABC): print(table.get_string(sortby="File")) @property - def size(self): + def size(self) -> int: + """ + Calculate and return the total size of all files in the folder. + + :return: The total size of all files in the folder. If no files exist or all have `None` + size, returns 0. + """ return sum(file.size for file in self.files.values() if file.size is not None) def get_file(self, file_name: str) -> Optional[File]: @@ -313,14 +369,19 @@ class Folder(FileSystemItemABC): """ Get a file by its uuid. - :param file_uuid: The file uuid. :return: The matching File. """ return self.files.get(file_uuid) def add_file(self, file: File): - """Adds a file to the folder list.""" + """ + Adds a file to the folder. + + :param File file: The File object to be added to the folder. + :raises Exception: If the provided `file` parameter is None or not an instance of the + `File` class. + """ if file is None or not isinstance(file, File): raise Exception(f"Invalid file: {file}") @@ -340,7 +401,6 @@ class Folder(FileSystemItemABC): The method can take a File object or a file id. :param file: The file to remove - :type: Optional[File] """ if file is None or not isinstance(file, File): raise Exception(f"Invalid file: {file}") @@ -369,7 +429,15 @@ class Folder(FileSystemItemABC): class File(FileSystemItemABC): - """Class that represents a file in the simulation.""" + """ + Class representing a file in the simulation. + + :ivar Folder folder: The folder in which the file resides. + :ivar FileType file_type: The type of the file. + :ivar Optional[int] sim_size: The simulated file size. + :ivar bool real: Indicates if the file is actually a real file in the Node sim fs output. + :ivar Optional[Path] sim_path: The path if the file is real. + """ folder: Folder "The Folder the File is in." @@ -415,16 +483,30 @@ class File(FileSystemItemABC): pass def make_copy(self, dst_folder: Folder) -> File: + """ + Create a copy of the current File object in the given destination folder. + + :param Folder dst_folder: The destination folder for the copied file. + :return: A new File object that is a copy of the current file. + """ return File(folder=dst_folder, **self.model_dump(exclude={"uuid", "folder", "sim_path"})) @property - def path(self): - """The path of the file in the FileSystem.""" + def path(self) -> str: + """ + Get the path of the file in the file system. + + :return: The full path of the file. + """ return f"{self.folder.name}/{self.name}" @property def size(self) -> int: - """The file size in Bytes.""" + """ + Get the size of the file in bytes. + + :return: The size of the file in bytes. + """ if self.real: return os.path.getsize(self.sim_path) return self.sim_size diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 832e6a13..fa1058cf 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -929,7 +929,7 @@ class Node(SimComponent): kwargs["software_manager"] = SoftwareManager( sys_log=kwargs.get("sys_log"), session_manager=kwargs.get("session_manager"), - file_system=kwargs.get("file_system") + file_system=kwargs.get("file_system"), ) super().__init__(**kwargs) self.arp.nics = self.nics diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index cecb108d..c030d907 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -172,20 +172,20 @@ def arcd_uc2_network() -> Network: );""" user_insert_statements = [ - "INSERT INTO user (name, email, age, city, occupation) VALUES ('John Doe', 'johndoe@example.com', 32, 'New York', 'Engineer');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Jane Smith', 'janesmith@example.com', 27, 'Los Angeles', 'Designer');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Bob Johnson', 'bobjohnson@example.com', 45, 'Chicago', 'Manager');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Alice Lee', 'alicelee@example.com', 22, 'San Francisco', 'Student');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('David Kim', 'davidkim@example.com', 38, 'Houston', 'Consultant');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Emily Chen', 'emilychen@example.com', 29, 'Seattle', 'Software Developer');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Frank Wang', 'frankwang@example.com', 55, 'New York', 'Entrepreneur');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Grace Park', 'gracepark@example.com', 31, 'Los Angeles', 'Marketing Specialist');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Henry Wu', 'henrywu@example.com', 40, 'Chicago', 'Accountant');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Isabella Kim', 'isabellakim@example.com', 26, 'San Francisco', 'Graphic Designer');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Jake Lee', 'jakelee@example.com', 33, 'Houston', 'Sales Manager');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Kelly Chen', 'kellychen@example.com', 28, 'Seattle', 'Web Developer');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Lucas Liu', 'lucasliu@example.com', 42, 'New York', 'Lawyer');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Maggie Wang', 'maggiewang@example.com', 30, 'Los Angeles', 'Data Analyst');", + "INSERT INTO user (name, email, age, city, occupation) VALUES ('John Doe', 'johndoe@example.com', 32, 'New York', 'Engineer');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Jane Smith', 'janesmith@example.com', 27, 'Los Angeles', 'Designer');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Bob Johnson', 'bobjohnson@example.com', 45, 'Chicago', 'Manager');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Alice Lee', 'alicelee@example.com', 22, 'San Francisco', 'Student');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('David Kim', 'davidkim@example.com', 38, 'Houston', 'Consultant');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Emily Chen', 'emilychen@example.com', 29, 'Seattle', 'Software Developer');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Frank Wang', 'frankwang@example.com', 55, 'New York', 'Entrepreneur');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Grace Park', 'gracepark@example.com', 31, 'Los Angeles', 'Marketing Specialist');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Henry Wu', 'henrywu@example.com', 40, 'Chicago', 'Accountant');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Isabella Kim', 'isabellakim@example.com', 26, 'San Francisco', 'Graphic Designer');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Jake Lee', 'jakelee@example.com', 33, 'Houston', 'Sales Manager');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Kelly Chen', 'kellychen@example.com', 28, 'Seattle', 'Web Developer');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Lucas Liu', 'lucasliu@example.com', 42, 'New York', 'Lawyer');", # noqa + "INSERT INTO user (name, email, age, city, occupation) VALUES ('Maggie Wang', 'maggiewang@example.com', 30, 'Los Angeles', 'Data Analyst');", # noqa ] database_server.software_manager.add_service(DatabaseService) database: DatabaseService = database_server.software_manager.services["Database"] # noqa @@ -219,5 +219,4 @@ def arcd_uc2_network() -> Network: router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER) - return network diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index 79e3630a..b1e35a77 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -1,7 +1,7 @@ import json import logging from pathlib import Path -from typing import Optional +from typing import Any, Dict, List, Optional from primaite.simulator import SIM_OUTPUT @@ -52,7 +52,12 @@ class PacketCapture: self.logger.addFilter(_JSONFilter()) - def read(self): + def read(self) -> List[Dict[Any]]: + """ + Read packet capture logs and return them as a list of dictionaries. + + :return: List of frames captured, represented as dictionaries. + """ frames = [] with open(self._get_log_path(), "r") as file: while line := file.readline(): diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index aa73410f..71b7dcec 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -38,9 +38,7 @@ class Session(SimComponent): connected: bool = False @classmethod - def from_session_key( - cls, session_key: Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]] - ) -> Session: + def from_session_key(cls, session_key: Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]]) -> Session: """ Create a Session instance from a session key tuple. @@ -97,7 +95,7 @@ class SessionManager: @staticmethod def _get_session_key( - frame: Frame, inbound_frame: bool = True + frame: Frame, inbound_frame: bool = True ) -> Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]]: """ Extracts the session key from the given frame. @@ -136,12 +134,12 @@ class SessionManager: return protocol, with_ip_address, src_port, dst_port def receive_payload_from_software_manager( - self, - payload: Any, - dst_ip_address: Optional[IPv4Address] = None, - dst_port: Optional[Port] = None, - session_id: Optional[str] = None, - is_reattempt: bool = False, + self, + payload: Any, + dst_ip_address: Optional[IPv4Address] = None, + dst_port: Optional[Port] = None, + session_id: Optional[str] = None, + is_reattempt: bool = False, ) -> Union[Any, None]: """ Receive a payload from the SoftwareManager. @@ -164,9 +162,12 @@ class SessionManager: if not is_reattempt: self.arp_cache.send_arp_request(dst_ip_address) return self.receive_payload_from_software_manager( - payload=payload, dst_ip_address=dst_ip_address, dst_port=dst_port, session_id=session_id, - is_reattempt=True - ) + payload=payload, + dst_ip_address=dst_ip_address, + dst_port=dst_port, + session_id=session_id, + is_reattempt=True, + ) else: return diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index d46cb21c..13d4524c 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -7,7 +7,6 @@ from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application -from primaite.simulator.system.core.session_manager import Session from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.services.service import Service from primaite.simulator.system.software import SoftwareType @@ -100,7 +99,7 @@ class SoftwareManager: """ self.session_manager.receive_payload_from_software_manager( payload=payload, dst_ip_address=dest_ip_address, dst_port=dest_port, session_id=session_id - ) + ) def receive_payload_from_session_manger(self, payload: Any, port: Port, protocol: IPProtocol, session_id: str): """ diff --git a/src/primaite/simulator/system/services/database.py b/src/primaite/simulator/system/services/database.py index 7666597c..c02b2872 100644 --- a/src/primaite/simulator/system/services/database.py +++ b/src/primaite/simulator/system/services/database.py @@ -1,9 +1,9 @@ import sqlite3 from ipaddress import IPv4Address from sqlite3 import OperationalError -from typing import Dict, Optional, Any, List, Union +from typing import Any, Dict, List, Optional, Union -from prettytable import PrettyTable, MARKDOWN +from prettytable import MARKDOWN, PrettyTable from primaite.simulator.file_system.file_system import File from primaite.simulator.network.transmission.network_layer import IPProtocol @@ -13,7 +13,12 @@ from primaite.simulator.system.services.service import Service class DatabaseService(Service): - """A generic SQL Server Service.""" + """ + A class for simulating a generic SQL Server service. + + This class inherits from the `Service` class and provides methods to manage and query a SQLite database. + """ + backup_server: Optional[IPv4Address] = None "The IP Address of the server the " @@ -28,12 +33,21 @@ class DatabaseService(Service): self._cursor = self._conn.cursor() def tables(self) -> List[str]: + """ + Get a list of table names present in the database. + + :return: List of table names. + """ sql = "SELECT name FROM sqlite_master WHERE type='table' AND name != 'sqlite_sequence';" results = self._process_sql(sql) return [row[0] for row in results["data"]] def show(self, markdown: bool = False): - """Prints a Table names in the Database.""" + """ + Prints a list of table names in the database using PrettyTable. + + :param markdown: Whether to output the table in Markdown format. + """ table = PrettyTable(["Table"]) if markdown: table.set_style(MARKDOWN) @@ -44,10 +58,17 @@ class DatabaseService(Service): print(table) def _create_db_file(self): + """Creates the Simulation File and sqlite file in the file system.""" self._db_file: File = self.file_system.create_file(folder_name="database", file_name="database.db", real=True) self.folder = self._db_file.folder def _process_sql(self, query: str) -> Dict[str, Union[int, List[Any]]]: + """ + Executes the given SQL query and returns the result. + + :param query: The SQL query to be executed. + :return: Dictionary containing status code and data fetched. + """ try: self._cursor.execute(query) self._conn.commit() @@ -69,11 +90,15 @@ class DatabaseService(Service): return super().describe_state() def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Processes the incoming SQL payload and sends the result back. + + :param payload: The SQL query to be executed. + :param session_id: The session identifier. + :return: The status code of the SQL execution. + """ result = self._process_sql(payload) software_manager: SoftwareManager = self.software_manager software_manager.send_payload_to_session_manager(payload=result, session_id=session_id) - return result["status_code"] - - def send(self, payload: Any, session_id: str, **kwargs) -> bool: - pass + return result["status_code"] == 200 diff --git a/tests/conftest.py b/tests/conftest.py index 5570e21f..9c216a8e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -29,7 +29,7 @@ def file_system() -> FileSystem: return Node(hostname="fs_node").file_system -#PrimAITE v2 stuff +# PrimAITE v2 stuff class TempPrimaiteSession(PrimaiteSession): """ A temporary PrimaiteSession class. diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 0d66137b..7ad11222 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -2,9 +2,9 @@ from ipaddress import IPv4Address from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.networks import arcd_uc2_network -from primaite.simulator.network.transmission.data_link_layer import Frame, EthernetHeader +from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import IPPacket, Precedence -from primaite.simulator.network.transmission.transport_layer import TCPHeader, Port +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader def test_database_query_across_the_network(): @@ -20,22 +20,15 @@ def test_database_query_across_the_network(): outbound_nic = client_1.arp.get_arp_cache_nic(IPv4Address("192.168.1.14")) client_1.ping("192.168.1.14") - frame = Frame( - ethernet=EthernetHeader( - src_mac_addr=client_1.ethernet_port[1].mac_address, - dst_mac_addr=dst_mac_address - ), + ethernet=EthernetHeader(src_mac_addr=client_1.ethernet_port[1].mac_address, dst_mac_addr=dst_mac_address), ip=IPPacket( src_ip_address=client_1.ethernet_port[1].ip_address, dst_ip_address=IPv4Address("192.168.1.14"), - precedence=Precedence.FLASH + precedence=Precedence.FLASH, ), - tcp=TCPHeader( - src_port=Port.POSTGRES_SERVER, - dst_port=Port.POSTGRES_SERVER - ), - payload="SELECT * FROM user;" + tcp=TCPHeader(src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER), + payload="SELECT * FROM user;", ) outbound_nic.send_frame(frame) @@ -43,4 +36,4 @@ def test_database_query_across_the_network(): client_1_last_payload = outbound_nic.pcap.read()[-1]["payload"] assert client_1_last_payload["status_code"] == 200 - assert client_1_last_payload["data"] \ No newline at end of file + assert client_1_last_payload["data"] diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py index 9496a50e..f5b37175 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py @@ -29,4 +29,4 @@ def test_creation(): assert False, f"Test was not supposed to throw exception: {e}" # there should be a session after the service is started - assert len(client_1.session_manager.sessions_by_uuid) == 1 \ No newline at end of file + assert len(client_1.session_manager.sessions_by_uuid) == 1 diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py index acc05d17..f3751f27 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py @@ -56,4 +56,4 @@ def test_creation(database_server): def test_db_population(database): database.show() - assert database.tables() == ["user"] \ No newline at end of file + assert database.tables() == ["user"] From 47dd23311bd951a81e867a5e28186840c891dea9 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 7 Sep 2023 15:45:37 +0100 Subject: [PATCH 157/980] #1752: added more functionality to DNS client and server + tests --- src/primaite/simulator/core.py | 3 + .../simulator/system/core/session_manager.py | 81 +++++------- .../simulator/system/core/software_manager.py | 18 ++- .../simulator/system/services/dns_client.py | 119 +++++++++++++----- .../simulator/system/services/dns_server.py | 118 ++++++++++++----- .../simulator/system/services/service.py | 39 +++++- .../_simulator/_system/_services/test_dns.py | 66 ++++++++++ 7 files changed, 321 insertions(+), 123 deletions(-) create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 32db95c6..ee19abb3 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -192,6 +192,9 @@ class SimComponent(BaseModel): :param action: List describing the action to apply to this object. :type action: List[str] + + :param: context: Dict containing context for actions + :type context: Dict """ if self.action_manager is None: return diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index be20a28d..f8e97442 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -32,27 +32,23 @@ class Session(SimComponent): """ protocol: IPProtocol - src_ip_address: IPv4Address - dst_ip_address: IPv4Address + with_ip_address: IPv4Address src_port: Optional[Port] dst_port: Optional[Port] connected: bool = False @classmethod - def from_session_key( - cls, session_key: Tuple[IPProtocol, IPv4Address, IPv4Address, Optional[Port], Optional[Port]] - ) -> Session: + def from_session_key(cls, session_key: Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]]) -> Session: """ Create a Session instance from a session key tuple. :param session_key: Tuple containing the session details. :return: A Session instance. """ - protocol, src_ip_address, dst_ip_address, src_port, dst_port = session_key + protocol, with_ip_address, src_port, dst_port = session_key return Session( protocol=protocol, - src_ip_address=src_ip_address, - dst_ip_address=dst_ip_address, + with_ip_address=with_ip_address, src_port=src_port, dst_port=dst_port, ) @@ -78,9 +74,7 @@ class SessionManager: """ def __init__(self, sys_log: SysLog, arp_cache: "ARPCache"): - self.sessions_by_key: Dict[ - Tuple[IPProtocol, IPv4Address, IPv4Address, Optional[Port], Optional[Port]], Session - ] = {} + self.sessions_by_key: Dict[Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]], Session] = {} self.sessions_by_uuid: Dict[str, Session] = {} self.sys_log: SysLog = sys_log self.software_manager: SoftwareManager = None # Noqa @@ -99,8 +93,8 @@ class SessionManager: @staticmethod def _get_session_key( - frame: Frame, from_source: bool = True - ) -> Tuple[IPProtocol, IPv4Address, IPv4Address, Optional[Port], Optional[Port]]: + frame: Frame, inbound_frame: bool = True + ) -> Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]]: """ Extracts the session key from the given frame. @@ -112,36 +106,36 @@ class SessionManager: - Optional[Port]: The destination port number (if applicable). :param frame: The network frame from which to extract the session key. - :param from_source: A flag to indicate if the key should be extracted from the source or destination. :return: A tuple containing the session key. """ protocol = frame.ip.protocol - src_ip_address = frame.ip.src_ip_address - dst_ip_address = frame.ip.dst_ip_address + with_ip_address = frame.ip.src_ip_address if protocol == IPProtocol.TCP: - if from_source: + if inbound_frame: src_port = frame.tcp.src_port dst_port = frame.tcp.dst_port else: dst_port = frame.tcp.src_port src_port = frame.tcp.dst_port + with_ip_address = frame.ip.dst_ip_address elif protocol == IPProtocol.UDP: - if from_source: + if inbound_frame: src_port = frame.udp.src_port dst_port = frame.udp.dst_port else: dst_port = frame.udp.src_port src_port = frame.udp.dst_port + with_ip_address = frame.ip.dst_ip_address else: src_port = None dst_port = None - return protocol, src_ip_address, dst_ip_address, src_port, dst_port + return protocol, with_ip_address, src_port, dst_port def receive_payload_from_software_manager( self, payload: Any, - dest_ip_address: Optional[IPv4Address] = None, - dest_port: Optional[Port] = None, + dst_ip_address: Optional[IPv4Address] = None, + dst_port: Optional[Port] = None, session_id: Optional[str] = None, is_reattempt: bool = False, ) -> Union[Any, None]: @@ -154,20 +148,21 @@ class SessionManager: :param session_id: The Session ID the payload is to originate from. Optional. If None, one will be created. """ if session_id: - dest_ip_address = self.sessions_by_uuid[session_id].dst_ip_address - dest_port = self.sessions_by_uuid[session_id].dst_port + session = self.sessions_by_uuid[session_id] + dst_ip_address = self.sessions_by_uuid[session_id].with_ip_address + dst_port = self.sessions_by_uuid[session_id].dst_port - dst_mac_address = self.arp_cache.get_arp_cache_mac_address(dest_ip_address) + dst_mac_address = self.arp_cache.get_arp_cache_mac_address(dst_ip_address) if dst_mac_address: - outbound_nic = self.arp_cache.get_arp_cache_nic(dest_ip_address) + outbound_nic = self.arp_cache.get_arp_cache_nic(dst_ip_address) else: if not is_reattempt: - self.arp_cache.send_arp_request(dest_ip_address) + self.arp_cache.send_arp_request(dst_ip_address) return self.receive_payload_from_software_manager( payload=payload, - dest_ip_address=dest_ip_address, - dest_port=dest_port, + dst_ip_address=dst_ip_address, + dst_port=dst_port, session_id=session_id, is_reattempt=True, ) @@ -178,17 +173,17 @@ class SessionManager: ethernet=EthernetHeader(src_mac_addr=outbound_nic.mac_address, dst_mac_addr=dst_mac_address), ip=IPPacket( src_ip_address=outbound_nic.ip_address, - dst_ip_address=dest_ip_address, + dst_ip_address=dst_ip_address, ), tcp=TCPHeader( - src_port=dest_port, - dst_port=dest_port, + src_port=dst_port, + dst_port=dst_port, ), payload=payload, ) if not session_id: - session_key = self._get_session_key(frame, from_source=True) + session_key = self._get_session_key(frame, inbound_frame=False) session = self.sessions_by_key.get(session_key) if not session: # Create new session @@ -198,33 +193,25 @@ class SessionManager: outbound_nic.send_frame(frame) - def send_payload_to_software_manager(self, payload: Any, session_id: int): + def receive_frame(self, frame: Frame): """ - Send a payload to the software manager. - - :param payload: The payload to be sent. - :param session_id: The Session ID the payload originates from. - """ - self.software_manager.receive_payload_from_session_manger() - - def receive_payload_from_nic(self, frame: Frame): - """ - Receive a Frame from the NIC. + Receive a Frame. Extract the session key using the _get_session_key method, and forward the payload to the appropriate session. If the session does not exist, a new one is created. :param frame: The frame being received. """ - session_key = self._get_session_key(frame) - session = self.sessions_by_key.get(session_key) + session_key = self._get_session_key(frame, inbound_frame=True) + session: Session = self.sessions_by_key.get(session_key) if not session: # Create new session session = Session.from_session_key(session_key) self.sessions_by_key[session_key] = session self.sessions_by_uuid[session.uuid] = session - self.software_manager.receive_payload_from_session_manger(payload=frame, session=session) - # TODO: Implement the frame deconstruction and send to SoftwareManager. + self.software_manager.receive_payload_from_session_manager( + payload=frame.payload, port=frame.tcp.dst_port, protocol=frame.ip.protocol, session_id=session.uuid + ) def show(self, markdown: bool = False): """ diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index 28e37963..71519ac7 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -6,7 +6,6 @@ from prettytable import MARKDOWN, PrettyTable from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application -from primaite.simulator.system.core.session_manager import Session from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.services.service import Service from primaite.simulator.system.software import SoftwareType @@ -86,7 +85,7 @@ class SoftwareManager: payload: Any, dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = None, - session_id: Optional[int] = None, + session_id: Optional[str] = None, ): """ Send a payload to the SessionManager. @@ -97,22 +96,21 @@ class SoftwareManager: :param session_id: The Session ID the payload is to originate from. Optional. """ self.session_manager.receive_payload_from_software_manager( - payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id + payload=payload, dst_ip_address=dest_ip_address, dst_port=dest_port, session_id=session_id ) - def receive_payload_from_session_manger(self, payload: Any, session: Session): + def receive_payload_from_session_manager(self, payload: Any, port: Port, protocol: IPProtocol, session_id: str): """ Receive a payload from the SessionManager and forward it to the corresponding service or application. :param payload: The payload being received. :param session: The transport session the payload originates from. """ - # receiver: Optional[Union[Service, Application]] = self.port_protocol_mapping.get((port, protocol), None) - # if receiver: - # receiver.receive_payload(None, payload) - # else: - # raise ValueError(f"No service or application found for port {port} and protocol {protocol}") - pass + receiver: Optional[Union[Service, Application]] = self.port_protocol_mapping.get((port, protocol), None) + if receiver: + receiver.receive_payload(payload=payload, session_id=session_id) + else: + self.sys_log.error(f"No service or application found for port {port} and protocol {protocol}") def show(self, markdown: bool = False): """ diff --git a/src/primaite/simulator/system/services/dns_client.py b/src/primaite/simulator/system/services/dns_client.py index 97968407..3929065d 100644 --- a/src/primaite/simulator/system/services/dns_client.py +++ b/src/primaite/simulator/system/services/dns_client.py @@ -1,19 +1,26 @@ -from abc import abstractmethod from ipaddress import IPv4Address -from typing import Any, Dict, List - -from pydantic import BaseModel +from typing import Any, Dict, Optional from primaite.simulator.network.protocols.dns import DNSPacket, DNSRequest +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.service import Service -class DNSClient(BaseModel): +class DNSClient(Service): """Represents a DNS Client as a Service.""" - dns_cache: Dict[str:IPv4Address] = {} + dns_cache: Dict[str, IPv4Address] = {} "A dict of known mappings between domain/URLs names and IPv4 addresses." - @abstractmethod + def __init__(self, **kwargs): + kwargs["name"] = "DNSClient" + kwargs["port"] = Port.DNS + # DNS uses UDP by default + # it switches to TCP when the bytes exceed 512 (or 4096) bytes + kwargs["protocol"] = IPProtocol.UDP + super().__init__(**kwargs) + def describe_state(self) -> Dict: """ Describes the current state of the software. @@ -26,57 +33,109 @@ class DNSClient(BaseModel): """ return {"Operating State": self.operating_state} - def apply_action(self, action: List[str]) -> None: - """ - Applies a list of actions to the Service. - - :param action: A list of actions to apply. - """ - pass - - def reset_component_for_episode(self): + def reset_component_for_episode(self, episode: int): """ Resets the Service component for a new episode. This method ensures the Service is ready for a new episode, including resetting any stateful properties or statistics, and clearing any message queues. """ + super().reset_component_for_episode(episode=episode) self.dns_cache = {} - def check_domain_in_cache(self, target_domain: str, session_id: str): + def add_domain_to_cache(self, domain_name: str, ip_address: IPv4Address): + """ + Adds a domain name to the DNS Client cache. + + :param: domain_name: The domain name to save to cache + :param: ip_address: The IP Address to attach the domain name to + """ + self.dns_cache[domain_name] = ip_address + + def check_domain_in_cache( + self, + target_domain: str, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + session_id: Optional[str] = None, + is_reattempt: bool = False, + ) -> bool: """Function to check if domain name is in DNS client cache. - :param target_domain: The domain requested for an IP address. - :param session_id: The ID of the session in order to send the response to the DNS server or application. + :param: target_domain: The domain requested for an IP address. + :param: dest_ip_address: The ip address of the payload destination. + :param: dest_port: The port of the payload destination. + :param: session_id: The Session ID the payload is to originate from. Optional. + :param: is_reattempt: Checks if the request has been reattempted. Default is False. """ - if target_domain in self.dns_cache: - ip_address = self.dns_cache[target_domain] - self.send(ip_address, session_id) - else: - self.send(target_domain, session_id) + # check if the target domain is in the client's DNS cache + payload = DNSPacket(dns_request=DNSRequest(domain_name_request=target_domain)) - def send(self, payload: Any, session_id: str, **kwargs) -> bool: + # check if the domain is already in the DNS cache + if target_domain in self.dns_cache: + return True + else: + # return False if already reattempted + if is_reattempt: + return False + else: + # send a request to check if domain name exists in the DNS Server + self.send(payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id) + # call function again + return self.check_domain_in_cache( + target_domain=target_domain, + dest_ip_address=dest_ip_address, + dest_port=dest_port, + session_id=session_id, + is_reattempt=True, + ) + + def send( + self, + payload: Any, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + session_id: Optional[str] = None, + **kwargs, + ) -> bool: """ Sends a payload to the SessionManager. The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. - :param payload: The payload to send. + :param payload: The payload to be sent. + :param dest_ip_address: The ip address of the payload destination. + :param dest_port: The port of the payload destination. + :param session_id: The Session ID the payload is to originate from. Optional. + :return: True if successful, False otherwise. """ - DNSPacket(dns_request=DNSRequest(domain_name_request=payload), dns_reply=None) + # create DNS request packet + self.software_manager.send_payload_to_session_manager( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id + ) - def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + def receive( + self, + payload: Any, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + session_id: Optional[str] = None, + **kwargs, + ) -> bool: """ Receives a payload from the SessionManager. The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. - :param payload: The payload to receive. (receive a DNS packet with dns request and dns reply in, send to web - browser) + :param payload: The payload to be sent. + :param dest_ip_address: The ip address of the payload destination. + :param dest_port: The port of the payload destination. + :param session_id: The Session ID the payload is to originate from. Optional. :return: True if successful, False otherwise. """ + super().send() # check the DNS packet (dns request, dns reply) here and see if it actually worked pass diff --git a/src/primaite/simulator/system/services/dns_server.py b/src/primaite/simulator/system/services/dns_server.py index a2eaf9d9..3dcd89f9 100644 --- a/src/primaite/simulator/system/services/dns_server.py +++ b/src/primaite/simulator/system/services/dns_server.py @@ -1,19 +1,31 @@ -from abc import abstractmethod from ipaddress import IPv4Address -from typing import Any, Dict, List, Optional +from typing import Any, Dict, Optional -from pydantic import BaseModel +from prettytable import MARKDOWN, PrettyTable -from primaite.simulator.network.protocols.dns import DNSPacket, DNSReply, DNSRequest +from primaite import getLogger +from primaite.simulator.network.protocols.dns import DNSPacket +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.service import Service + +_LOGGER = getLogger(__name__) -class DNSServer(BaseModel): +class DNSServer(Service): """Represents a DNS Server as a Service.""" - dns_table: dict[str:IPv4Address] = {} + dns_table: Dict[str, IPv4Address] = {} "A dict of mappings between domain names and IPv4 addresses." - @abstractmethod + def __init__(self, **kwargs): + kwargs["name"] = "DNSServer" + kwargs["port"] = Port.DNS + # DNS uses UDP by default + # it switches to TCP when the bytes exceed 512 (or 4096) bytes + kwargs["protocol"] = IPProtocol.UDP + super().__init__(**kwargs) + def describe_state(self) -> Dict: """ Describes the current state of the software. @@ -26,15 +38,7 @@ class DNSServer(BaseModel): """ return {"Operating State": self.operating_state} - def apply_action(self, action: List[str]) -> None: - """ - Applies a list of actions to the Service. - - :param action: A list of actions to apply. (unsure) - """ - pass - - def dns_lookup(self, target_domain: str) -> Optional[IPv4Address]: + def dns_lookup(self, target_domain: Any) -> Optional[IPv4Address]: """ Attempts to find the IP address for a domain name. @@ -42,11 +46,23 @@ class DNSServer(BaseModel): :return ip_address: The IP address of that domain name or None. """ if target_domain in self.dns_table: - self.dns_table[target_domain] + return self.dns_table[target_domain] else: return None - def reset_component_for_episode(self): + def dns_register(self, domain_name: str, domain_ip_address: IPv4Address): + """ + Register a domain name and its IP address. + + :param: domain_name: The domain name to register + :type: domain_name: str + + :param: domain_ip_address: The IP address that the domain should route to + :type: domain_ip_address: IPv4Address + """ + self.dns_table[domain_name] = domain_ip_address + + def reset_component_for_episode(self, episode: int): """ Resets the Service component for a new episode. @@ -54,36 +70,78 @@ class DNSServer(BaseModel): stateful properties or statistics, and clearing any message queues. """ self.dns_table = {} + super().reset_component_for_episode(episode=episode) - def send(self, payload: Any, session_id: str, **kwargs) -> bool: + def send( + self, + payload: Any, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + session_id: Optional[str] = None, + **kwargs, + ) -> bool: """ Sends a payload to the SessionManager. The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. - :param payload: The payload to send. + :param: payload: The payload to send. + :param: dest_ip_address: The ip address of the machine that the payload will be sent to + :param: dest_port: The port of the machine that the payload will be sent to + :param: session_id: The id of the session + :return: True if successful, False otherwise. """ - # DNS packet will be sent from DNS Server to the DNS client - DNSPacket( - dns_request=DNSRequest(domain_name_request=self.dns_table), - dns_reply=DNSReply(domain_name_ip_address=payload), - ) + try: + self.software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id) + except Exception as e: + _LOGGER.error(e) + return False - def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + def receive( + self, + payload: Any, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + session_id: Optional[str] = None, + **kwargs, + ) -> bool: """ Receives a payload from the SessionManager. The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. - :param payload: The payload to receive. (take the domain name and do dns lookup) + :param: payload: The payload to send. + :param: dest_ip_address: The ip address of the machine that the payload will be sent to + :param: dest_port: The port of the machine that the payload will be sent to + :param: session_id: The id of the session + :return: True if successful, False otherwise. """ - ip_address = self.dns_lookup(payload) - if ip_address is not None: - self.send(ip_address, session_id) + # The payload should be a DNS packet + if not isinstance(payload, DNSPacket): + _LOGGER.debug(f"{payload} is not a DNSPacket") + return False + # cast payload into a DNS packet + payload: DNSPacket = payload + if payload.dns_request is not None: + # generate a reply with the correct DNS IP address + payload.generate_reply(self.dns_lookup(payload.dns_request.domain_name_request)) + # send reply + self.send(payload, session_id) return True return False + + def show(self, markdown: bool = False): + """Prints a table of DNS Lookup table.""" + table = PrettyTable(["Domain Name", "IP Address"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"{self.sys_log.hostname} DNS Lookup table" + for dns in self.dns_table.items(): + table.add_row([dns[0], dns[1]]) + print(table) diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index b9340103..3011c74d 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,8 +1,10 @@ from enum import Enum +from ipaddress import IPv4Address from typing import Any, Dict, Optional from primaite import getLogger from primaite.simulator.core import Action, ActionManager +from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.software import IOSoftware _LOGGER = getLogger(__name__) @@ -72,29 +74,54 @@ class Service(IOSoftware): """ pass - def send(self, payload: Any, session_id: str, **kwargs) -> bool: + def send( + self, + payload: Any, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + session_id: Optional[str] = None, + **kwargs, + ) -> bool: """ Sends a payload to the SessionManager. The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. - :param payload: The payload to send. + :param: payload: The payload to send. + :param: dest_ip_address: The ip address of the machine that the payload will be sent to + :param: dest_port: The port of the machine that the payload will be sent to + :param: session_id: The id of the session + :return: True if successful, False otherwise. """ - pass + self.software_manager.send_payload_to_session_manager( + payload=payload, dest_ip_address=dest_ip_address, dest_port=self.port, session_id=session_id + ) - def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + def receive( + self, + payload: Any, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + session_id: Optional[str] = None, + **kwargs, + ) -> bool: """ Receives a payload from the SessionManager. The specifics of how the payload is processed and whether a response payload is generated should be implemented in subclasses. - :param payload: The payload to receive. + :param: payload: The payload to send. + :param: dest_ip_address: The ip address of the machine that the payload will be sent to + :param: dest_port: The port of the machine that the payload will be sent to + :param: session_id: The id of the session + :return: True if successful, False otherwise. """ - pass + + pass def stop(self) -> None: """Stop the service.""" diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py new file mode 100644 index 00000000..fdb3426d --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py @@ -0,0 +1,66 @@ +import sys +from ipaddress import IPv4Address + +import pytest + +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.networks import arcd_uc2_network +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.dns_client import DNSClient +from primaite.simulator.system.services.dns_server import DNSServer + + +@pytest.fixture(scope="function") +def dns_server() -> Node: + node = Node(hostname="dns_server") + node.software_manager.add_service(service_class=DNSServer) + node.software_manager.services["DNSServer"].start() + return node + + +@pytest.fixture(scope="function") +def dns_client() -> Node: + node = Node(hostname="dns_client") + node.software_manager.add_service(service_class=DNSClient) + node.software_manager.services["DNSClient"].start() + return node + + +def test_create_dns_server(dns_server): + assert dns_server is not None + dns_server_service: DNSServer = dns_server.software_manager.services["DNSServer"] + assert dns_server_service.name is "DNSServer" + assert dns_server_service.port is Port.DNS + assert dns_server_service.protocol is IPProtocol.UDP + + +def test_create_dns_client(dns_client): + assert dns_client is not None + dns_client_service: DNSClient = dns_client.software_manager.services["DNSClient"] + assert dns_client_service.name is "DNSClient" + assert dns_client_service.port is Port.DNS + assert dns_client_service.protocol is IPProtocol.UDP + + +def test_dns_server_domain_name_registration(dns_server): + """Test to check if the domain name registration works.""" + dns_server_service: DNSServer = dns_server.software_manager.services["DNSServer"] + + # register the web server in the domain controller + dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12")) + + # return none for an unknown domain + assert dns_server_service.dns_lookup("fake-domain.com") is None + assert dns_server_service.dns_lookup("real-domain.com") is not None + + +def test_dns_client_check_domain_in_cache(dns_client): + """Test to make sure that the check_domain_in_cache returns the correct values.""" + dns_client_service: DNSClient = dns_client.software_manager.services["DNSClient"] + + # add a domain to the dns client cache + dns_client_service.add_domain_to_cache("real-domain.com", IPv4Address("192.168.1.12")) + + assert dns_client_service.check_domain_in_cache("fake-domain.com") is False + assert dns_client_service.check_domain_in_cache("real-domain.com") is True From 6f2f23e04f1ba23e2944e2ef1fe22286c447d887 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 7 Sep 2023 15:59:46 +0100 Subject: [PATCH 158/980] #1752: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14a53d73..d9700f83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ SessionManager. 1. Creating a simulation - this notebook explains how to build up a simulation using the Python package. (WIP) - Red Agent Services: - Data Manipulator Bot - A red agent service which sends a payload to a target machine. (By default this payload is a SQL query that breaks a database) +- DNS Services: DNS Client and DNS Server ## [2.0.0] - 2023-07-26 From ceac89e77849e571c0c0ef604d9285990feac692 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 8 Sep 2023 10:15:26 +0100 Subject: [PATCH 159/980] #1816 - DatabaseService now uses the send function when responding. --- .../simulator/system/core/packet_capture.py | 2 +- .../simulator/system/services/database.py | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index b1e35a77..2e5ed008 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -52,7 +52,7 @@ class PacketCapture: self.logger.addFilter(_JSONFilter()) - def read(self) -> List[Dict[Any]]: + def read(self) -> List[Dict[str, Any]]: """ Read packet capture logs and return them as a list of dictionaries. diff --git a/src/primaite/simulator/system/services/database.py b/src/primaite/simulator/system/services/database.py index c02b2872..dc148031 100644 --- a/src/primaite/simulator/system/services/database.py +++ b/src/primaite/simulator/system/services/database.py @@ -95,10 +95,22 @@ class DatabaseService(Service): :param payload: The SQL query to be executed. :param session_id: The session identifier. - :return: The status code of the SQL execution. + :return: True if the Status Code is 200, otherwise False. """ result = self._process_sql(payload) - software_manager: SoftwareManager = self.software_manager - software_manager.send_payload_to_session_manager(payload=result, session_id=session_id) + self.send(payload=result, session_id=session_id) - return result["status_code"] == 200 + return payload["status_code"] == 200 + + def send(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Send a SQL response back down to the SessionManager. + + :param payload: The SQL query results. + :param session_id: The session identifier. + :return: True if the Status Code is 200, otherwise False. + """ + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id) + + return payload["status_code"] == 200 From b1d8666c163798adaf95c05f4b65c1028bbe4289 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 8 Sep 2023 16:50:49 +0100 Subject: [PATCH 160/980] #1816 - Added database client. Installed the database client on the Web Server node in the UC2 network. Updated the integration test to query the DB server using the DB client. --- .../network/internal_frame_processing.rst | 0 .../simulator/file_system/file_type.py | 170 ++++++++++++++++++ .../simulator/network/hardware/base.py | 102 +++++++---- src/primaite/simulator/network/networks.py | 14 +- .../system/applications/application.py | 23 ++- .../system/applications/database_client.py | 83 +++++++++ .../simulator/system/core/software_manager.py | 89 ++++----- .../simulator/system/services/database.py | 58 +++++- .../simulator/system/services/service.py | 7 - tests/conftest.py | 7 + .../system/test_database_on_node.py | 57 +++--- 11 files changed, 478 insertions(+), 132 deletions(-) create mode 100644 docs/source/simulation_components/network/internal_frame_processing.rst create mode 100644 src/primaite/simulator/file_system/file_type.py create mode 100644 src/primaite/simulator/system/applications/database_client.py diff --git a/docs/source/simulation_components/network/internal_frame_processing.rst b/docs/source/simulation_components/network/internal_frame_processing.rst new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/file_system/file_type.py b/src/primaite/simulator/file_system/file_type.py new file mode 100644 index 00000000..140cd0e7 --- /dev/null +++ b/src/primaite/simulator/file_system/file_type.py @@ -0,0 +1,170 @@ +from __future__ import annotations + +from enum import Enum +from random import choice + + +class FileType(Enum): + """An enumeration of common file types.""" + + UNKNOWN = 0 + "Unknown file type." + + # Text formats + TXT = 1 + "Plain text file." + DOC = 2 + "Microsoft Word document (.doc)" + DOCX = 3 + "Microsoft Word document (.docx)" + PDF = 4 + "Portable Document Format." + HTML = 5 + "HyperText Markup Language file." + XML = 6 + "Extensible Markup Language file." + CSV = 7 + "Comma-Separated Values file." + + # Spreadsheet formats + XLS = 8 + "Microsoft Excel file (.xls)" + XLSX = 9 + "Microsoft Excel file (.xlsx)" + + # Image formats + JPEG = 10 + "JPEG image file." + PNG = 11 + "PNG image file." + GIF = 12 + "GIF image file." + BMP = 13 + "Bitmap image file." + + # Audio formats + MP3 = 14 + "MP3 audio file." + WAV = 15 + "WAV audio file." + + # Video formats + MP4 = 16 + "MP4 video file." + AVI = 17 + "AVI video file." + MKV = 18 + "MKV video file." + FLV = 19 + "FLV video file." + + # Presentation formats + PPT = 20 + "Microsoft PowerPoint file (.ppt)" + PPTX = 21 + "Microsoft PowerPoint file (.pptx)" + + # Web formats + JS = 22 + "JavaScript file." + CSS = 23 + "Cascading Style Sheets file." + + # Programming languages + PY = 24 + "Python script file." + C = 25 + "C source code file." + CPP = 26 + "C++ source code file." + JAVA = 27 + "Java source code file." + + # Compressed file types + RAR = 28 + "RAR archive file." + ZIP = 29 + "ZIP archive file." + TAR = 30 + "TAR archive file." + GZ = 31 + "Gzip compressed file." + + # Database file types + DB = 32 + "Generic DB file. Used by sqlite3." + + @classmethod + def _missing_(cls, value): + return cls.UNKNOWN + + @classmethod + def random(cls) -> FileType: + """ + Returns a random FileType. + + :return: A random FileType. + """ + return choice(list(FileType)) + + @property + def default_size(self) -> int: + """ + Get the default size of the FileType in bytes. + + Returns 0 if a default size does not exist. + """ + size = file_type_sizes_bytes[self] + return size if size else 0 + + +def get_file_type_from_extension(file_type_extension: str): + """ + Get a FileType from a file type extension. + + If a matching extension does not exist, FileType.UNKNOWN is returned. + + :param file_type_extension: A file type extension. + :return: A file type extension. + """ + try: + return FileType[file_type_extension.upper()] + except KeyError: + return FileType.UNKNOWN + + +file_type_sizes_bytes = { + FileType.UNKNOWN: 0, + FileType.TXT: 4096, + FileType.DOC: 51200, + FileType.DOCX: 30720, + FileType.PDF: 102400, + FileType.HTML: 15360, + FileType.XML: 10240, + FileType.CSV: 15360, + FileType.XLS: 102400, + FileType.XLSX: 25600, + FileType.JPEG: 102400, + FileType.PNG: 40960, + FileType.GIF: 30720, + FileType.BMP: 307200, + FileType.MP3: 5120000, + FileType.WAV: 25600000, + FileType.MP4: 25600000, + FileType.AVI: 51200000, + FileType.MKV: 51200000, + FileType.FLV: 15360000, + FileType.PPT: 204800, + FileType.PPTX: 102400, + FileType.JS: 10240, + FileType.CSS: 5120, + FileType.PY: 5120, + FileType.C: 5120, + FileType.CPP: 10240, + FileType.JAVA: 10240, + FileType.RAR: 1024000, + FileType.ZIP: 1024000, + FileType.TAR: 1024000, + FileType.GZ: 819200, + FileType.DB: 15360000, +} diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index fa1058cf..efc1e251 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -5,7 +5,7 @@ import secrets from enum import Enum from ipaddress import IPv4Address, IPv4Network from pathlib import Path -from typing import Any, Dict, List, Optional, Tuple, Union +from typing import Any, Dict, List, Literal, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable @@ -959,7 +959,24 @@ class Node(SimComponent): ) return state - def show(self, markdown: bool = False): + def show(self, markdown: bool = False, component: Literal["NIC", "OPEN_PORTS"] = "NIC"): + if component == "NIC": + self._show_nic(markdown) + elif component == "OPEN_PORTS": + self._show_open_ports(markdown) + + def _show_open_ports(self, markdown: bool = False): + """Prints a table of the open ports on the Node.""" + table = PrettyTable(["Port", "Name"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"{self.hostname} Open Ports" + for port in self.software_manager.get_open_ports(): + table.add_row([port.value, port.name]) + print(table) + + def _show_nic(self, markdown: bool = False): """Prints a table of the NICs on the Node.""" table = PrettyTable(["Port", "MAC Address", "Address", "Speed", "Status"]) if markdown: @@ -1048,29 +1065,30 @@ class Node(SimComponent): :param pings: The number of pings to attempt, default is 4. :return: True if the ping is successful, otherwise False. """ - if not isinstance(target_ip_address, IPv4Address): - target_ip_address = IPv4Address(target_ip_address) - if target_ip_address.is_loopback: - self.sys_log.info("Pinging loopback address") - return any(nic.enabled for nic in self.nics.values()) if self.operating_state == NodeOperatingState.ON: - self.sys_log.info(f"Pinging {target_ip_address}:") - sequence, identifier = 0, None - while sequence < pings: - sequence, identifier = self.icmp.ping(target_ip_address, sequence, identifier, pings) - request_replies = self.icmp.request_replies.get(identifier) - passed = request_replies == pings - if request_replies: - self.icmp.request_replies.pop(identifier) - else: - request_replies = 0 - self.sys_log.info( - f"Ping statistics for {target_ip_address}: " - f"Packets: Sent = {pings}, " - f"Received = {request_replies}, " - f"Lost = {pings-request_replies} ({(pings-request_replies)/pings*100}% loss)" - ) - return passed + if not isinstance(target_ip_address, IPv4Address): + target_ip_address = IPv4Address(target_ip_address) + if target_ip_address.is_loopback: + self.sys_log.info("Pinging loopback address") + return any(nic.enabled for nic in self.nics.values()) + if self.operating_state == NodeOperatingState.ON: + self.sys_log.info(f"Pinging {target_ip_address}:") + sequence, identifier = 0, None + while sequence < pings: + sequence, identifier = self.icmp.ping(target_ip_address, sequence, identifier, pings) + request_replies = self.icmp.request_replies.get(identifier) + passed = request_replies == pings + if request_replies: + self.icmp.request_replies.pop(identifier) + else: + request_replies = 0 + self.sys_log.info( + f"Ping statistics for {target_ip_address}: " + f"Packets: Sent = {pings}, " + f"Received = {request_replies}, " + f"Lost = {pings-request_replies} ({(pings-request_replies)/pings*100}% loss)" + ) + return passed return False def send_frame(self, frame: Frame): @@ -1079,7 +1097,8 @@ class Node(SimComponent): :param frame: The Frame to be sent. """ - nic: NIC = self._get_arp_cache_nic(frame.ip.dst_ip_address) + if self.operating_state == NodeOperatingState.ON: + nic: NIC = self._get_arp_cache_nic(frame.ip.dst_ip_address) nic.send_frame(frame) def receive_frame(self, frame: Frame, from_nic: NIC): @@ -1092,20 +1111,27 @@ class Node(SimComponent): :param frame: The Frame being received. :param from_nic: The NIC that received the frame. """ - if frame.ip: - if frame.ip.src_ip_address in self.arp: - self.arp.add_arp_cache_entry( - ip_address=frame.ip.src_ip_address, mac_address=frame.ethernet.src_mac_addr, nic=from_nic - ) - if frame.ip.protocol == IPProtocol.TCP: - if frame.tcp.src_port == Port.ARP: - self.arp.process_arp_packet(from_nic=from_nic, arp_packet=frame.arp) + if self.operating_state == NodeOperatingState.ON: + if frame.ip: + if frame.ip.src_ip_address in self.arp: + self.arp.add_arp_cache_entry( + ip_address=frame.ip.src_ip_address, mac_address=frame.ethernet.src_mac_addr, nic=from_nic + ) + if frame.ip.protocol == IPProtocol.ICMP: + self.icmp.process_icmp(frame=frame, from_nic=from_nic) + return + # Check if the destination port is open on the Node + if frame.tcp.dst_port in self.software_manager.get_open_ports(): + # accept thr frame as the port is open + if frame.tcp.src_port == Port.ARP: + self.arp.process_arp_packet(from_nic=from_nic, arp_packet=frame.arp) + else: + self.session_manager.receive_frame(frame) else: - self.session_manager.receive_frame(frame) - elif frame.ip.protocol == IPProtocol.UDP: - pass - elif frame.ip.protocol == IPProtocol.ICMP: - self.icmp.process_icmp(frame=frame, from_nic=from_nic) + # denied as port closed + self.sys_log.info(f"Ignoring frame for port {frame.tcp.dst_port.value} from {frame.ip.src_ip_address}") + # TODO: do we need to do anything more here? + pass def install_service(self, service: Service) -> None: """ diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index c030d907..a364abea 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -6,6 +6,7 @@ from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database import DatabaseService @@ -149,6 +150,9 @@ def arcd_uc2_network() -> Network: hostname="web_server", ip_address="192.168.1.12", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" ) web_server.power_on() + web_server.software_manager.install(DatabaseClient) + database_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + database_client.run() network.connect(endpoint_b=web_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[2]) # Database Server @@ -187,12 +191,12 @@ def arcd_uc2_network() -> Network: "INSERT INTO user (name, email, age, city, occupation) VALUES ('Lucas Liu', 'lucasliu@example.com', 42, 'New York', 'Lawyer');", # noqa "INSERT INTO user (name, email, age, city, occupation) VALUES ('Maggie Wang', 'maggiewang@example.com', 30, 'Los Angeles', 'Data Analyst');", # noqa ] - database_server.software_manager.add_service(DatabaseService) - database: DatabaseService = database_server.software_manager.services["Database"] # noqa - database.start() - database._process_sql(ddl) # noqa + database_server.software_manager.install(DatabaseService) + database_service: DatabaseService = database_server.software_manager.software["DatabaseService"] # noqa + database_service.start() + database_service._process_sql(ddl) # noqa for insert_statement in user_insert_statements: - database._process_sql(insert_statement) # noqa + database_service._process_sql(insert_statement) # noqa # Backup Server backup_server = Server( diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 6a07f00f..2a3013e1 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -23,9 +23,9 @@ class Application(IOSoftware): Applications are user-facing programs that may perform input/output operations. """ - operating_state: ApplicationOperatingState + operating_state: ApplicationOperatingState = ApplicationOperatingState.CLOSED "The current operating state of the Application." - execution_control_status: str + execution_control_status: str = "manual" "Control status of the application's execution. It could be 'manual' or 'automatic'." num_executions: int = 0 "The number of times the application has been executed. Default is 0." @@ -53,6 +53,25 @@ class Application(IOSoftware): ) return state + def run(self) -> None: + """Open the Application""" + if self.operating_state == ApplicationOperatingState.CLOSED: + self.sys_log.info(f"Running Application {self.name}") + self.operating_state = ApplicationOperatingState.RUNNING + + def close(self) -> None: + """Close the Application""" + if self.operating_state == ApplicationOperatingState.RUNNING: + self.sys_log.info(f"Closed Application{self.name}") + self.operating_state = ApplicationOperatingState.CLOSED + + def install(self) -> None: + """Install Application.""" + super().install() + if self.operating_state == ApplicationOperatingState.CLOSED: + self.sys_log.info(f"Installing Application {self.name}") + self.operating_state = ApplicationOperatingState.INSTALLING + def reset_component_for_episode(self, episode: int): """ Resets the Application component for a new episode. diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py new file mode 100644 index 00000000..38ce3c7f --- /dev/null +++ b/src/primaite/simulator/system/applications/database_client.py @@ -0,0 +1,83 @@ +from ipaddress import IPv4Address +from typing import Any, Dict, Optional + +from prettytable import PrettyTable + +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.core.software_manager import SoftwareManager + + +class DatabaseClient(Application): + server_ip_address: Optional[IPv4Address] = None + connected: bool = False + + def __init__(self, **kwargs): + kwargs["name"] = "DatabaseClient" + kwargs["port"] = Port.POSTGRES_SERVER + kwargs["protocol"] = IPProtocol.TCP + super().__init__(**kwargs) + + def describe_state(self) -> Dict: + return super().describe_state() + + def connect(self, server_ip_address: IPv4Address, password: Optional[str] = None) -> bool: + if not self.connected and self.operating_state.RUNNING: + return self._connect(server_ip_address, password) + + def _connect( + self, server_ip_address: IPv4Address, password: Optional[str] = None, is_reattempt: bool = False + ) -> bool: + if is_reattempt: + if self.connected: + self.sys_log.info(f"DatabaseClient connected to {server_ip_address} authorised") + self.server_ip_address = server_ip_address + return self.connected + else: + self.sys_log.info(f"DatabaseClient connected to {server_ip_address} declined") + payload = {"type": "connect_request", "password": password} + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager( + payload=payload, dest_ip_address=server_ip_address, dest_port=self.port + ) + return self._connect(server_ip_address, password, True) + + def disconnect(self): + if self.connected and self.operating_state.RUNNING: + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager( + payload={"type": "disconnect"}, dest_ip_address=self.server_ip_address, dest_port=self.port + ) + + self.sys_log.info(f"DatabaseClient disconnected from {self.server_ip_address}") + self.server_ip_address = None + + def query(self, sql: str): + if self.connected and self.operating_state.RUNNING: + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager( + payload={"type": "sql", "sql": sql}, dest_ip_address=self.server_ip_address, dest_port=self.port + ) + + def _print_data(self, data: Dict): + """ + Display the contents of the Folder in tabular format. + + :param markdown: Whether to display the table in Markdown format or not. Default is `False`. + """ + table = PrettyTable(list(data.values())[0]) + + table.align = "l" + table.title = f"{self.sys_log.hostname} Database Client" + for row in data.values(): + table.add_row(row.values()) + print(table) + + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + if isinstance(payload, dict) and payload.get("type"): + if payload["type"] == "connect_response": + self.connected = payload["response"] == True + elif payload["type"] == "sql": + self._print_data(payload["data"]) + return True diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index 13d4524c..c3fe29fd 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -1,15 +1,15 @@ from ipaddress import IPv4Address -from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING, Union +from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING, Union from prettytable import MARKDOWN, PrettyTable from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.applications.application import Application, ApplicationOperatingState from primaite.simulator.system.core.sys_log import SysLog -from primaite.simulator.system.services.service import Service -from primaite.simulator.system.software import SoftwareType +from primaite.simulator.system.services.service import Service, ServiceOperatingState +from primaite.simulator.system.software import IOSoftware, SoftwareType if TYPE_CHECKING: from primaite.simulator.system.core.session_manager import SessionManager @@ -17,7 +17,7 @@ if TYPE_CHECKING: from typing import Type, TypeVar -ServiceClass = TypeVar("ServiceClass", bound=Service) +IOSoftwareClass = TypeVar("IOSoftwareClass", bound=IOSoftware) class SoftwareManager: @@ -30,57 +30,55 @@ class SoftwareManager: :param session_manager: The session manager handling network communications. """ self.session_manager = session_manager - self.services: Dict[str, Service] = {} - self.applications: Dict[str, Application] = {} + self.software: Dict[str, Union[Service, Application]] = {} + self._software_class_to_name_map: Dict[Type[IOSoftwareClass], str] = {} self.port_protocol_mapping: Dict[Tuple[Port, IPProtocol], Union[Service, Application]] = {} self.sys_log: SysLog = sys_log self.file_system: FileSystem = file_system - def add_service(self, service_class: Type[ServiceClass]): - """ - Add a Service to the manager. + def get_open_ports(self) -> List[Port]: + open_ports = [Port.ARP] + for software in self.port_protocol_mapping.values(): + if software.operating_state in {ApplicationOperatingState.RUNNING, ServiceOperatingState.RUNNING}: + open_ports.append(software.port) + open_ports.sort(key=lambda port: port.value) + return open_ports - :param: service_class: The class of the service to add - """ - service = service_class(software_manager=self, sys_log=self.sys_log, file_system=self.file_system) + def install(self, software_class: Type[IOSoftwareClass]): + if software_class in self._software_class_to_name_map: + self.sys_log.info(f"Cannot install {software_class} as it is already installed") + return + software = software_class(software_manager=self, sys_log=self.sys_log, file_system=self.file_system) + if isinstance(software, Application): + software.install() + software.software_manager = self + self.software[software.name] = software + self.port_protocol_mapping[(software.port, software.protocol)] = software + self.sys_log.info(f"Installed {software.name}") + if isinstance(software, Application): + software.operating_state = ApplicationOperatingState.CLOSED - service.software_manager = self - self.services[service.name] = service - self.port_protocol_mapping[(service.port, service.protocol)] = service + def uninstall(self, software_name: str): + if software_name in self.software: + software = self.software.pop(software_name) # noqa + del software + self.sys_log.info(f"Deleted {software_name}") + return + self.sys_log.error(f"Cannot uninstall {software_name} as it is not installed") - def add_application(self, name: str, application: Application, port: Port, protocol: IPProtocol): - """ - Add an Application to the manager. - - :param name: The name of the application. - :param application: The application instance. - :param port: The port used by the application. - :param protocol: The network protocol used by the application. - """ - application.software_manager = self - self.applications[name] = application - self.port_protocol_mapping[(port, protocol)] = application - - def send_internal_payload(self, target_software: str, target_software_type: SoftwareType, payload: Any): + def send_internal_payload(self, target_software: str, payload: Any): """ Send a payload to a specific service or application. :param target_software: The name of the target service or application. - :param target_software_type: The type of software (Service, Application, Process). :param payload: The data to be sent. - :param receiver_type: The type of the target, either 'service' or 'application'. """ - if target_software_type is SoftwareType.SERVICE: - receiver = self.services.get(target_software) - elif target_software_type is SoftwareType.APPLICATION: - receiver = self.applications.get(target_software) - else: - raise ValueError(f"Invalid receiver type {target_software_type}") + receiver = self.software.get(target_software) if receiver: receiver.receive_payload(payload) else: - raise ValueError(f"No {target_software_type.name.lower()} found with the name {target_software}") + self.sys_log.error(f"No Service of Application found with the name {target_software}") def send_payload_to_session_manager( self, @@ -121,13 +119,20 @@ class SoftwareManager: :param markdown: If True, outputs the table in markdown format. Default is False. """ - table = PrettyTable(["Name", "Operating State", "Health State", "Port"]) + table = PrettyTable(["Name", "Type", "Operating State", "Health State", "Port"]) if markdown: table.set_style(MARKDOWN) table.align = "l" table.title = f"{self.sys_log.hostname} Software Manager" - for service in self.services.values(): + for software in self.port_protocol_mapping.values(): + software_type = "Service" if isinstance(software, Service) else "Application" table.add_row( - [service.name, service.operating_state.name, service.health_state_actual.name, service.port.value] + [ + software.name, + software_type, + software.operating_state.name, + software.health_state_actual.name, + software.port.value, + ] ) print(table) diff --git a/src/primaite/simulator/system/services/database.py b/src/primaite/simulator/system/services/database.py index dc148031..e34f06fa 100644 --- a/src/primaite/simulator/system/services/database.py +++ b/src/primaite/simulator/system/services/database.py @@ -1,4 +1,5 @@ import sqlite3 +from datetime import datetime from ipaddress import IPv4Address from sqlite3 import OperationalError from typing import Any, Dict, List, Optional, Union @@ -8,8 +9,10 @@ from prettytable import MARKDOWN, PrettyTable from primaite.simulator.file_system.file_system import File from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.session_manager import Session from primaite.simulator.system.core.software_manager import SoftwareManager -from primaite.simulator.system.services.service import Service +from primaite.simulator.system.services.service import Service, ServiceOperatingState +from primaite.simulator.system.software import SoftwareHealthState class DatabaseService(Service): @@ -19,11 +22,11 @@ class DatabaseService(Service): This class inherits from the `Service` class and provides methods to manage and query a SQLite database. """ - backup_server: Optional[IPv4Address] = None - "The IP Address of the server the " + password: Optional[str] = None + connections: Dict[str, datetime] = {} def __init__(self, **kwargs): - kwargs["name"] = "Database" + kwargs["name"] = "DatabaseService" kwargs["port"] = Port.POSTGRES_SERVER kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) @@ -62,6 +65,24 @@ class DatabaseService(Service): self._db_file: File = self.file_system.create_file(folder_name="database", file_name="database.db", real=True) self.folder = self._db_file.folder + def _process_connect( + self, session_id: str, password: Optional[str] = None + ) -> Dict[str, Union[int, Dict[str, bool]]]: + status_code = 500 # Default internal server error + if self.operating_state == ServiceOperatingState.RUNNING: + status_code = 503 # service unavailable + if self.health_state_actual == SoftwareHealthState.GOOD: + if self.password == password: + status_code = 200 # ok + self.connections[session_id] = datetime.now() + self.sys_log.info(f"Connect request for {session_id=} authorised") + else: + status_code = 401 # Unauthorised + self.sys_log.info(f"Connect request for {session_id=} declined") + else: + status_code = 404 # service not found + return {"status_code": status_code, "type": "connect_response", "response": status_code == 200} + def _process_sql(self, query: str) -> Dict[str, Union[int, List[Any]]]: """ Executes the given SQL query and returns the result. @@ -71,12 +92,21 @@ class DatabaseService(Service): """ try: self._cursor.execute(query) + self._conn.commit() except OperationalError: # Handle the case where the table does not exist. return {"status_code": 404, "data": []} - - return {"status_code": 200, "data": self._cursor.fetchall()} + data = [] + description = self._cursor.description + if description: + headers = [] + for header in description: + headers.append(header[0]) + data = self._cursor.fetchall() + if data and headers: + data = {row[0]: {header: value for header, value in zip(headers, row)} for row in data} + return {"status_code": 200, "type": "sql", "data": data} def describe_state(self) -> Dict: """ @@ -97,10 +127,20 @@ class DatabaseService(Service): :param session_id: The session identifier. :return: True if the Status Code is 200, otherwise False. """ - result = self._process_sql(payload) + result = {"status_code": 500, "data": []} + if isinstance(payload, dict) and payload.get("type"): + if payload["type"] == "connect_request": + result = self._process_connect(session_id=session_id, password=payload.get("password")) + elif payload["type"] == "disconnect": + if session_id in self.connections: + self.connections.pop(session_id) + elif payload["type"] == "sql": + if session_id in self.connections: + result = self._process_sql(payload.get("sql")) + else: + result = {"status_code": 401, "type": "sql"} self.send(payload=result, session_id=session_id) - - return payload["status_code"] == 200 + return True def send(self, payload: Any, session_id: str, **kwargs) -> bool: """ diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index b9340103..30b48527 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -98,35 +98,30 @@ class Service(IOSoftware): def stop(self) -> None: """Stop the service.""" - _LOGGER.debug(f"Stopping service {self.name}") if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.sys_log.info(f"Stopping service {self.name}") self.operating_state = ServiceOperatingState.STOPPED def start(self, **kwargs) -> None: """Start the service.""" - _LOGGER.debug(f"Starting service {self.name}") if self.operating_state == ServiceOperatingState.STOPPED: self.sys_log.info(f"Starting service {self.name}") self.operating_state = ServiceOperatingState.RUNNING def pause(self) -> None: """Pause the service.""" - _LOGGER.debug(f"Pausing service {self.name}") if self.operating_state == ServiceOperatingState.RUNNING: self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.PAUSED def resume(self) -> None: """Resume paused service.""" - _LOGGER.debug(f"Resuming service {self.name}") if self.operating_state == ServiceOperatingState.PAUSED: self.sys_log.info(f"Resuming service {self.name}") self.operating_state = ServiceOperatingState.RUNNING def restart(self) -> None: """Restart running service.""" - _LOGGER.debug(f"Restarting service {self.name}") if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.RESTARTING @@ -134,13 +129,11 @@ class Service(IOSoftware): def disable(self) -> None: """Disable the service.""" - _LOGGER.debug(f"Disabling service {self.name}") self.sys_log.info(f"Disabling Application {self.name}") self.operating_state = ServiceOperatingState.DISABLED def enable(self) -> None: """Enable the disabled service.""" - _LOGGER.debug(f"Enabling service {self.name}") if self.operating_state == ServiceOperatingState.DISABLED: self.sys_log.info(f"Enabling Application {self.name}") self.operating_state = ServiceOperatingState.STOPPED diff --git a/tests/conftest.py b/tests/conftest.py index 9c216a8e..35548f2a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,6 +12,8 @@ import pytest from primaite import getLogger from primaite.environment.primaite_env import Primaite from primaite.primaite_session import PrimaiteSession +from primaite.simulator.network.container import Network +from primaite.simulator.network.networks import arcd_uc2_network from tests.mock_and_patch.get_session_path_mock import get_temp_session_path ACTION_SPACE_NODE_VALUES = 1 @@ -24,6 +26,11 @@ from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.hardware.base import Node +@pytest.fixture(scope="function") +def uc2_network() -> Network: + return arcd_uc2_network() + + @pytest.fixture(scope="function") def file_system() -> FileSystem: return Node(hostname="fs_node").file_system diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 7ad11222..7562b29b 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -1,39 +1,38 @@ from ipaddress import IPv4Address -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.networks import arcd_uc2_network -from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame -from primaite.simulator.network.transmission.network_layer import IPPacket, Precedence -from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.services.database import DatabaseService -def test_database_query_across_the_network(): +def test_database_client_server_connection(uc2_network): + web_server: Server = uc2_network.get_node_by_hostname("web_server") + db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + + db_server: Server = uc2_network.get_node_by_hostname("database_server") + db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + + assert len(db_service.connections) == 0 + + assert db_client.connect(server_ip_address=IPv4Address("192.168.1.14")) + assert len(db_service.connections) == 1 + + db_client.disconnect() + assert len(db_service.connections) == 0 + + +def test_database_client_query(uc2_network): """Tests DB query across the network returns HTTP status 200 and date.""" - network = arcd_uc2_network() + web_server: Server = uc2_network.get_node_by_hostname("web_server") + db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] - client_1: Computer = network.get_node_by_hostname("client_1") + db_client.connect(server_ip_address=IPv4Address("192.168.1.14")) - client_1.arp.send_arp_request(IPv4Address("192.168.1.14")) + db_client.query("SELECT * FROM user;") - dst_mac_address = client_1.arp.get_arp_cache_mac_address(IPv4Address("192.168.1.14")) + web_server_nic = web_server.ethernet_port[1] - outbound_nic = client_1.arp.get_arp_cache_nic(IPv4Address("192.168.1.14")) - client_1.ping("192.168.1.14") + web_server_last_payload = web_server_nic.pcap.read()[-1]["payload"] - frame = Frame( - ethernet=EthernetHeader(src_mac_addr=client_1.ethernet_port[1].mac_address, dst_mac_addr=dst_mac_address), - ip=IPPacket( - src_ip_address=client_1.ethernet_port[1].ip_address, - dst_ip_address=IPv4Address("192.168.1.14"), - precedence=Precedence.FLASH, - ), - tcp=TCPHeader(src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER), - payload="SELECT * FROM user;", - ) - - outbound_nic.send_frame(frame) - - client_1_last_payload = outbound_nic.pcap.read()[-1]["payload"] - - assert client_1_last_payload["status_code"] == 200 - assert client_1_last_payload["data"] + assert web_server_last_payload["status_code"] == 200 + assert web_server_last_payload["data"] From 388176b8bddd748c0a0fe9a252201db1ca4b831a Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 11 Sep 2023 09:30:40 +0100 Subject: [PATCH 161/980] #1816 - Added full documentation on the database client/server, and the internal frame processing process --- docs/source/simulation.rst | 1 + .../network/database_client_server.rst | 70 +++++++++++++ .../network/internal_frame_processing.rst | 98 +++++++++++++++++++ .../network/software.rst | 18 ++++ .../simulator/file_system/file_type.py | 5 +- .../simulator/network/hardware/base.py | 1 + src/primaite/simulator/network/networks.py | 2 +- .../system/applications/application.py | 4 +- .../system/applications/database_client.py | 34 +++++++ .../simulator/system/core/software_manager.py | 17 +++- .../{database.py => database_service.py} | 2 - .../system/test_database_on_node.py | 2 +- .../_system/_services/test_database.py | 2 +- 13 files changed, 246 insertions(+), 10 deletions(-) create mode 100644 docs/source/simulation_components/network/database_client_server.rst create mode 100644 docs/source/simulation_components/network/software.rst rename src/primaite/simulator/system/services/{database.py => database_service.py} (98%) diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index 7e9fe77f..ab4530f1 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -21,3 +21,4 @@ Contents simulation_components/network/router simulation_components/network/switch simulation_components/network/network + simulation_components/internal_frame_processing diff --git a/docs/source/simulation_components/network/database_client_server.rst b/docs/source/simulation_components/network/database_client_server.rst new file mode 100644 index 00000000..99bbe25e --- /dev/null +++ b/docs/source/simulation_components/network/database_client_server.rst @@ -0,0 +1,70 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + + +Database Client Server +====================== + +Database Service +---------------- + +The ``DatabaseService`` provides a SQL database server simulation by extending the base Service class. + +Key capabilities +^^^^^^^^^^^^^^^^ + +- Initialises a SQLite database file in the ``Node``'s ``FileSystem`` upon creation. +- Handles connecting clients by maintaining a dictionary of connections mapped to session IDs. +- Authenticates connections using a configurable password. +- Executes SQL queries against the SQLite database. +- Returns query results and status codes back to clients. +- Leverages the Service base class for install/uninstall, status tracking, etc. + +Usage +^^^^^ +- Install on a Node via the ``SoftwareManager`` to start the database service. +- Clients connect, execute queries, and disconnect. +- Service runs on TCP port 5432 by default. + +Implementation +^^^^^^^^^^^^^^ + +- Uses SQLite for persistent storage. +- Creates the database file within the node's file system. +- Manages client connections in a dictionary by session ID. +- Processes SQL queries via the SQLite cursor and connection. +- Returns results and status codes in a standard dictionary format. +- Extends Service class for integration with ``SoftwareManager``. + +Database Client +--------------- + +The DatabaseClient provides a client interface for connecting to the ``DatabaseService``. + +Key features +^^^^^^^^^^^^ + +- Connects to the ``DatabaseService`` via the ``SoftwareManager``. +- Executes SQL queries and retrieves result sets. +- Handles connecting, querying, and disconnecting. +- Provides a simple ``query`` method for running SQL. + + +Usage +^^^^^ + +- Initialise with server IP address and optional password. +- Connect to the ``DatabaseService`` with ``connect``. +- Execute SQL queries via ``query``. +- Retrieve results in a dictionary. +- Disconnect when finished. + +Implementation +^^^^^^^^^^^^^^ + +- Leverages ``SoftwareManager`` for sending payloads over the network. +- Connect and disconnect methods manage sessions. +- Provides easy interface for applications to query database. +- Payloads serialised as dictionaries for transmission. +- Extends base Application class. diff --git a/docs/source/simulation_components/network/internal_frame_processing.rst b/docs/source/simulation_components/network/internal_frame_processing.rst index e69de29b..e173a3ac 100644 --- a/docs/source/simulation_components/network/internal_frame_processing.rst +++ b/docs/source/simulation_components/network/internal_frame_processing.rst @@ -0,0 +1,98 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _about: + +Internal Frame Processing +========================= + +Inbound +------- + +At the NIC +^^^^^^^^^^ +When a Frame is received on the Node's NIC: + +- The NIC checks if it is enabled. If so, it will process the Frame. +- The Frame's received timestamp is set. +- The Frame is captured by the NIC's PacketCapture if configured. +- The NIC decrements the IP Packet's TTL by 1. +- The NIC calls the Node's ``receive_frame`` method, passing itself as the receiving NIC and the Frame. + + +At the Node +^^^^^^^^^^^ + +When ``receive_frame`` is called on the Node: + +- The source IP address is added to the ARP cache if not already present. +- The Frame's protocol is checked: + - If ARP or ICMP, the Frame is passed to that protocol's handler method. + - Otherwise it is passed to the SessionManager's ``receive_frame`` method. + +At the SessionManager +^^^^^^^^^^^^^^^^^^^^^ + +When ``receive_frame`` is called on the SessionManager: + +- It extracts the key session details from the Frame: + - Protocol (TCP, UDP, etc) + - Source IP + - Destination IP + - Source Port + - Destination Port +- It checks if an existing Session matches these details. +- If no match, a new Session is created to represent this exchange. +- The payload and new/existing Session ID are passed to the SoftwareManager's ``receive_payload_from_session_manager`` method. + +At the SoftwareManager +^^^^^^^^^^^^^^^^^^^^^^ + +Inside ``receive_payload_from_session_manager``: + +- The SoftwareManager checks its port/protocol mapping to find which Service or Application is listening on the destination port and protocol. +- The payload and Session ID are forwarded to that receiver Service/Application instance via their ``receive`` method. +- The Service/Application can then process the payload as needed. + +Outbound +-------- + +At the Service/Application +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +When a Service or Application needs to send a payload: + +- It calls the SoftwareManager's ``send_payload_to_session_manager`` method. +- Passes the payload, and either destination IP and destination port for new payloads, or session id for existing sessions. + +At the SoftwareManager +^^^^^^^^^^^^^^^^^^^^^^ + +Inside ``send_payload_to_session_manager``: + +- The SoftwareManager forwards the payload and details through to to the SessionManager's ``receive_payload_from_software_manager`` method. + +At the SessionManager +^^^^^^^^^^^^^^^^^^^^^ + +When ``receive_payload_from_software_manager`` is called: + +- If a Session ID was provided, it looks up the Session. +- Gets the destination MAC address by checking the ARP cache. +- If no Session ID was provided, the destination Port, IP address and Mac Address are used along with the outbound IP Address and Mac Address to create a new Session. +- Calls `send_payload_to_nic`` to construct and send the Frame. + +When ``send_payload_to_nic`` is called: + +- It constructs a new Frame with the payload, using the source NIC's MAC, source IP, destination MAC, etc. +- The outbound NIC is looked up via the ARP cache based on destination IP. +- The constructed Frame is passed to the outbound NIC's ``send_frame`` method. + +At the NIC +^^^^^^^^^^ + +When ``send_frame`` is called: + +- The NIC checks if it is enabled before sending. +- If enabled, it sends the Frame out to the connected Link. diff --git a/docs/source/simulation_components/network/software.rst b/docs/source/simulation_components/network/software.rst new file mode 100644 index 00000000..0dcb1d63 --- /dev/null +++ b/docs/source/simulation_components/network/software.rst @@ -0,0 +1,18 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + + +Software +======== + + + + +Contents +######## + +.. toctree:: + :maxdepth: 8 + + database_client_server diff --git a/src/primaite/simulator/file_system/file_type.py b/src/primaite/simulator/file_system/file_type.py index 140cd0e7..f87cd86f 100644 --- a/src/primaite/simulator/file_system/file_type.py +++ b/src/primaite/simulator/file_system/file_type.py @@ -2,6 +2,7 @@ from __future__ import annotations from enum import Enum from random import choice +from typing import Any class FileType(Enum): @@ -95,7 +96,7 @@ class FileType(Enum): "Generic DB file. Used by sqlite3." @classmethod - def _missing_(cls, value): + def _missing_(cls, value: Any) -> FileType: return cls.UNKNOWN @classmethod @@ -118,7 +119,7 @@ class FileType(Enum): return size if size else 0 -def get_file_type_from_extension(file_type_extension: str): +def get_file_type_from_extension(file_type_extension: str) -> FileType: """ Get a FileType from a file type extension. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index efc1e251..5b9cdf5b 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -960,6 +960,7 @@ class Node(SimComponent): return state def show(self, markdown: bool = False, component: Literal["NIC", "OPEN_PORTS"] = "NIC"): + """A multi-use .show function that accepts either NIC or OPEN_PORTS.""" if component == "NIC": self._show_nic(markdown) elif component == "OPEN_PORTS": diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index a364abea..b9554cb9 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -7,7 +7,7 @@ from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient -from primaite.simulator.system.services.database import DatabaseService +from primaite.simulator.system.services.database_service import DatabaseService def client_server_routed() -> Network: diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 2a3013e1..30efd5b7 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -54,13 +54,13 @@ class Application(IOSoftware): return state def run(self) -> None: - """Open the Application""" + """Open the Application.""" if self.operating_state == ApplicationOperatingState.CLOSED: self.sys_log.info(f"Running Application {self.name}") self.operating_state = ApplicationOperatingState.RUNNING def close(self) -> None: - """Close the Application""" + """Close the Application.""" if self.operating_state == ApplicationOperatingState.RUNNING: self.sys_log.info(f"Closed Application{self.name}") self.operating_state = ApplicationOperatingState.CLOSED diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 38ce3c7f..bbcde00f 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -10,6 +10,15 @@ from primaite.simulator.system.core.software_manager import SoftwareManager class DatabaseClient(Application): + """ + A DatabaseClient application. + + Extends the Application class to provide functionality for connecting, querying, and disconnecting from a + Database Service. It mainly operates over TCP protocol. + + :ivar server_ip_address: The IPv4 address of the Database Service server, defaults to None. + """ + server_ip_address: Optional[IPv4Address] = None connected: bool = False @@ -20,9 +29,21 @@ class DatabaseClient(Application): super().__init__(**kwargs) def describe_state(self) -> Dict: + """ + Describes the current state of the ACLRule. + + :return: A dictionary representing the current state. + """ + pass return super().describe_state() def connect(self, server_ip_address: IPv4Address, password: Optional[str] = None) -> bool: + """ + Connect to a Database Service. + + :param server_ip_address: The IPv4 Address of the Node the Database Service is running on. + :param password: The Database Service password. Is optional and has a default value of None. + """ if not self.connected and self.operating_state.RUNNING: return self._connect(server_ip_address, password) @@ -44,6 +65,7 @@ class DatabaseClient(Application): return self._connect(server_ip_address, password, True) def disconnect(self): + """Disconnect from the Database Service.""" if self.connected and self.operating_state.RUNNING: software_manager: SoftwareManager = self.software_manager software_manager.send_payload_to_session_manager( @@ -54,6 +76,11 @@ class DatabaseClient(Application): self.server_ip_address = None def query(self, sql: str): + """ + Send a query to the Database Service. + + :param sql: The SQL query. + """ if self.connected and self.operating_state.RUNNING: software_manager: SoftwareManager = self.software_manager software_manager.send_payload_to_session_manager( @@ -75,6 +102,13 @@ class DatabaseClient(Application): print(table) def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Receive a payload from the Software Manager. + + :param payload: A payload to receive. + :param session_id: The session id the payload relates to. + :return: True. + """ if isinstance(payload, dict) and payload.get("type"): if payload["type"] == "connect_response": self.connected = payload["response"] == True diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index c3fe29fd..6860ebc2 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -9,7 +9,7 @@ from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application, ApplicationOperatingState from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.services.service import Service, ServiceOperatingState -from primaite.simulator.system.software import IOSoftware, SoftwareType +from primaite.simulator.system.software import IOSoftware if TYPE_CHECKING: from primaite.simulator.system.core.session_manager import SessionManager @@ -37,6 +37,11 @@ class SoftwareManager: self.file_system: FileSystem = file_system def get_open_ports(self) -> List[Port]: + """ + Get a list of open ports. + + :return: A list of all open ports on the Node. + """ open_ports = [Port.ARP] for software in self.port_protocol_mapping.values(): if software.operating_state in {ApplicationOperatingState.RUNNING, ServiceOperatingState.RUNNING}: @@ -45,6 +50,11 @@ class SoftwareManager: return open_ports def install(self, software_class: Type[IOSoftwareClass]): + """ + Install an Application or Service. + + :param software_class: The software class. + """ if software_class in self._software_class_to_name_map: self.sys_log.info(f"Cannot install {software_class} as it is already installed") return @@ -59,6 +69,11 @@ class SoftwareManager: software.operating_state = ApplicationOperatingState.CLOSED def uninstall(self, software_name: str): + """ + Uninstall an Application or Service. + + :param software_name: The software name. + """ if software_name in self.software: software = self.software.pop(software_name) # noqa del software diff --git a/src/primaite/simulator/system/services/database.py b/src/primaite/simulator/system/services/database_service.py similarity index 98% rename from src/primaite/simulator/system/services/database.py rename to src/primaite/simulator/system/services/database_service.py index e34f06fa..d4289c08 100644 --- a/src/primaite/simulator/system/services/database.py +++ b/src/primaite/simulator/system/services/database_service.py @@ -1,6 +1,5 @@ import sqlite3 from datetime import datetime -from ipaddress import IPv4Address from sqlite3 import OperationalError from typing import Any, Dict, List, Optional, Union @@ -9,7 +8,6 @@ from prettytable import MARKDOWN, PrettyTable from primaite.simulator.file_system.file_system import File from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.core.session_manager import Session from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.services.service import Service, ServiceOperatingState from primaite.simulator.system.software import SoftwareHealthState diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 7562b29b..b360907e 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -2,7 +2,7 @@ from ipaddress import IPv4Address from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient -from primaite.simulator.system.services.database import DatabaseService +from primaite.simulator.system.services.database_service import DatabaseService def test_database_client_server_connection(uc2_network): diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py index f3751f27..db33908d 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py @@ -3,7 +3,7 @@ import json import pytest from primaite.simulator.network.hardware.base import Node -from primaite.simulator.system.services.database import DatabaseService +from primaite.simulator.system.services.database_service import DatabaseService DDL = """ CREATE TABLE IF NOT EXISTS user ( From f19dc9892bb30fcc5ea546643339bb596c26d2b4 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 11 Sep 2023 11:31:03 +0100 Subject: [PATCH 162/980] #1816 - Fixed tests. Used node and link added number (id) in observation space. --- src/primaite/simulator/network/container.py | 16 ++++++- .../system/applications/database_client.py | 1 + .../system/test_database_on_node.py | 28 ++++++++++++ .../test_data_manipulator_service.py | 4 +- .../_system/_services/test_database.py | 45 +------------------ 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 4d1afe72..79c7d77b 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -29,6 +29,8 @@ class Network(SimComponent): nodes: Dict[str, Node] = {} links: Dict[str, Link] = {} + _node_id_map: Dict[int, Node] = {} + _link_id_map: Dict[int, Node] = {} def __init__(self, **kwargs): """ @@ -161,8 +163,8 @@ class Network(SimComponent): state = super().describe_state() state.update( { - "nodes": {uuid: node.describe_state() for uuid, node in self.nodes.items()}, - "links": {uuid: link.describe_state() for uuid, link in self.links.items()}, + "nodes": {i for i, node in self._node_id_map.items()}, + "links": {i: link.describe_state() for i, link in self._link_id_map.items()}, } ) return state @@ -179,6 +181,7 @@ class Network(SimComponent): _LOGGER.warning(f"Can't add node {node.uuid}. It is already in the network.") return self.nodes[node.uuid] = node + self._node_id_map[len(self.nodes)] = node node.parent = self self._nx_graph.add_node(node.hostname) _LOGGER.info(f"Added node {node.uuid} to Network {self.uuid}") @@ -209,6 +212,10 @@ class Network(SimComponent): _LOGGER.warning(f"Can't remove node {node.uuid}. It's not in the network.") return self.nodes.pop(node.uuid) + for i, _node in self._node_id_map.items(): + if node == _node: + self._node_id_map.pop(i) + break node.parent = None _LOGGER.info(f"Removed node {node.uuid} from network {self.uuid}") @@ -235,6 +242,7 @@ class Network(SimComponent): return link = Link(endpoint_a=endpoint_a, endpoint_b=endpoint_b, **kwargs) self.links[link.uuid] = link + self._link_id_map[len(self.links)] = link self._nx_graph.add_edge(endpoint_a.parent.hostname, endpoint_b.parent.hostname) link.parent = self _LOGGER.info(f"Added link {link.uuid} to connect {endpoint_a} and {endpoint_b}") @@ -248,6 +256,10 @@ class Network(SimComponent): link.endpoint_a.disconnect_link() link.endpoint_b.disconnect_link() self.links.pop(link.uuid) + for i, _link in self._link_id_map.items(): + if link == _link: + self._link_id_map.pop(i) + break link.parent = None _LOGGER.info(f"Removed link {link.uuid} from network {self.uuid}.") diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index bbcde00f..a866b290 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -57,6 +57,7 @@ class DatabaseClient(Application): return self.connected else: self.sys_log.info(f"DatabaseClient connected to {server_ip_address} declined") + return False payload = {"type": "connect_request", "password": password} software_manager: SoftwareManager = self.software_manager software_manager.send_payload_to_session_manager( diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index b360907e..31e04666 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -21,6 +21,34 @@ def test_database_client_server_connection(uc2_network): assert len(db_service.connections) == 0 +def test_database_client_server_correct_password(uc2_network): + web_server: Server = uc2_network.get_node_by_hostname("web_server") + db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + + db_server: Server = uc2_network.get_node_by_hostname("database_server") + db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + db_service.password = "12345" + + assert len(db_service.connections) == 0 + + assert db_client.connect(server_ip_address=IPv4Address("192.168.1.14"), password="12345") + assert len(db_service.connections) == 1 + + +def test_database_client_server_incorrect_password(uc2_network): + web_server: Server = uc2_network.get_node_by_hostname("web_server") + db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + + db_server: Server = uc2_network.get_node_by_hostname("database_server") + db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + db_service.password = "12345" + + assert len(db_service.connections) == 0 + + assert not db_client.connect(server_ip_address=IPv4Address("192.168.1.14"), password="54321") + assert len(db_service.connections) == 0 + + def test_database_client_query(uc2_network): """Tests DB query across the network returns HTTP status 200 and date.""" web_server: Server = uc2_network.get_node_by_hostname("web_server") diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py index f5b37175..f95081a6 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py @@ -12,9 +12,9 @@ def test_creation(): client_1: Node = network.get_node_by_hostname("client_1") - client_1.software_manager.add_service(service_class=DataManipulatorService) + client_1.software_manager.install(service_class=DataManipulatorService) - data_manipulator_service: DataManipulatorService = client_1.software_manager.services["DataManipulatorBot"] + data_manipulator_service: DataManipulatorService = client_1.software_manager.software["DataManipulatorBot"] assert data_manipulator_service.name == "DataManipulatorBot" assert data_manipulator_service.port == Port.POSTGRES_SERVER diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py index db33908d..d41c63c7 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py @@ -5,55 +5,14 @@ import pytest from primaite.simulator.network.hardware.base import Node from primaite.simulator.system.services.database_service import DatabaseService -DDL = """ -CREATE TABLE IF NOT EXISTS user ( -id INTEGER PRIMARY KEY AUTOINCREMENT, -name VARCHAR(50) NOT NULL, -email VARCHAR(50) NOT NULL, -age INT, -city VARCHAR(50), -occupation VARCHAR(50) -);""" - -USER_INSERT_STATEMENTS = [ - "INSERT INTO user (name, email, age, city, occupation) VALUES ('John Doe', 'johndoe@example.com', 32, 'New York', 'Engineer');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Jane Smith', 'janesmith@example.com', 27, 'Los Angeles', 'Designer');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Bob Johnson', 'bobjohnson@example.com', 45, 'Chicago', 'Manager');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Alice Lee', 'alicelee@example.com', 22, 'San Francisco', 'Student');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('David Kim', 'davidkim@example.com', 38, 'Houston', 'Consultant');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Emily Chen', 'emilychen@example.com', 29, 'Seattle', 'Software Developer');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Frank Wang', 'frankwang@example.com', 55, 'New York', 'Entrepreneur');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Grace Park', 'gracepark@example.com', 31, 'Los Angeles', 'Marketing Specialist');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Henry Wu', 'henrywu@example.com', 40, 'Chicago', 'Accountant');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Isabella Kim', 'isabellakim@example.com', 26, 'San Francisco', 'Graphic Designer');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Jake Lee', 'jakelee@example.com', 33, 'Houston', 'Sales Manager');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Kelly Chen', 'kellychen@example.com', 28, 'Seattle', 'Web Developer');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Lucas Liu', 'lucasliu@example.com', 42, 'New York', 'Lawyer');", - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Maggie Wang', 'maggiewang@example.com', 30, 'Los Angeles', 'Data Analyst');", -] - @pytest.fixture(scope="function") def database_server() -> Node: node = Node(hostname="db_node") - node.software_manager.add_service(DatabaseService) - node.software_manager.services["Database"].start() + node.software_manager.install(DatabaseService) + node.software_manager.software["DatabaseService"].start() return node -@pytest.fixture(scope="function") -def database(database_server) -> DatabaseService: - database: DatabaseService = database_server.software_manager.services["Database"] # noqa - database.receive(DDL, None) - for script in USER_INSERT_STATEMENTS: - database.receive(script, None) - return database - - def test_creation(database_server): database_server.software_manager.show() - - -def test_db_population(database): - database.show() - assert database.tables() == ["user"] From 695b3ceab411ff69a140b01888cfec1f444b3aa3 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 11 Sep 2023 16:15:03 +0100 Subject: [PATCH 163/980] #1816 - Updated the DataManipulationBot to subclass DatabaseClient. Extended logging. Dropped the Link loading logging as it was clogging up the terminal output. --- docs/index.rst | 1 + docs/source/simulation.rst | 3 +- .../simulation_components/network/network.rst | 2 +- .../simulation_components/network/router.rst | 2 +- .../system/data_manipulation_bot.rst | 58 ++++++++++++++ .../database_client_server.rst | 0 .../internal_frame_processing.rst | 2 +- .../{network => system}/software.rst | 1 + src/primaite/simulator/network/container.py | 4 +- .../simulator/network/hardware/base.py | 20 ++--- src/primaite/simulator/network/networks.py | 32 +++++--- .../system/applications/database_client.py | 75 ++++++++++++++----- .../system/services/database_service.py | 11 +-- .../system/services/red_services/__init__.py | 0 .../red_services/data_manipulation_bot.py | 49 ++++++++++++ .../red_services/data_manipulator_service.py | 34 --------- tests/e2e_integration_tests/__init__.py | 0 .../test_uc2_data_manipulation_scenario.py | 25 +++++++ .../system/test_database_on_node.py | 29 +++---- .../_simulator/_network/test_container.py | 3 + .../test_data_manipulation_bot.py | 20 +++++ .../test_data_manipulator_service.py | 32 -------- 22 files changed, 268 insertions(+), 135 deletions(-) create mode 100644 docs/source/simulation_components/system/data_manipulation_bot.rst rename docs/source/simulation_components/{network => system}/database_client_server.rst (100%) rename docs/source/simulation_components/{network => system}/internal_frame_processing.rst (99%) rename docs/source/simulation_components/{network => system}/software.rst (88%) create mode 100644 src/primaite/simulator/system/services/red_services/__init__.py create mode 100644 src/primaite/simulator/system/services/red_services/data_manipulation_bot.py delete mode 100644 src/primaite/simulator/system/services/red_services/data_manipulator_service.py create mode 100644 tests/e2e_integration_tests/__init__.py create mode 100644 tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py delete mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py diff --git a/docs/index.rst b/docs/index.rst index b2c5cfaa..19f95e95 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -98,6 +98,7 @@ Head over to the :ref:`getting-started` page to install and setup PrimAITE! source/getting_started source/about source/config + source/simulation source/primaite_session source/custom_agent PrimAITE API diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index ab4530f1..e5c0d2c8 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -21,4 +21,5 @@ Contents simulation_components/network/router simulation_components/network/switch simulation_components/network/network - simulation_components/internal_frame_processing + simulation_components/system/internal_frame_processing + simulation_components/system/software diff --git a/docs/source/simulation_components/network/network.rst b/docs/source/simulation_components/network/network.rst index f4d64b16..cb6d9392 100644 --- a/docs/source/simulation_components/network/network.rst +++ b/docs/source/simulation_components/network/network.rst @@ -2,7 +2,7 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -.. _about: +.. _network: Network ======= diff --git a/docs/source/simulation_components/network/router.rst b/docs/source/simulation_components/network/router.rst index aaa589cc..2dc81d3b 100644 --- a/docs/source/simulation_components/network/router.rst +++ b/docs/source/simulation_components/network/router.rst @@ -2,7 +2,7 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -.. _about: +.. _router: Router Module ============= diff --git a/docs/source/simulation_components/system/data_manipulation_bot.rst b/docs/source/simulation_components/system/data_manipulation_bot.rst new file mode 100644 index 00000000..c9f8977a --- /dev/null +++ b/docs/source/simulation_components/system/data_manipulation_bot.rst @@ -0,0 +1,58 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + + +DataManipulationBot +=================== + +The ``DataManipulationBot`` class provides functionality to connect to a ``DatabaseService`` and execute malicious SQL statements. + +Overview +-------- + +The bot is intended to simulate a malicious actor carrying out attacks like: + +- Dropping tables +- Deleting records +- Modifying data +On a database server by abusing an application's trusted database connectivity. + +Usage +----- + +- Create an instance and call ``configure`` to set: + - Target database server IP + - Database password (if needed) + - SQL statement payload +- Call ``run`` to connect and execute the statement. + +The bot handles connecting, executing the statement, and disconnecting. + +Example +------- + +.. code-block:: python + + client_1 = Computer( + hostname="client_1", ip_address="192.168.10.21", subnet_mask="255.255.255.0", default_gateway="192.168.10.1" + ) + client_1.power_on() + network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) + client_1.software_manager.install(DataManipulationBot) + data_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] + data_manipulation_bot.configure(server_ip_address=IPv4Address("192.168.1.14"), payload="DROP TABLE IF EXISTS user;") + data_manipulation_bot.run() + +This would connect to the database service at 192.168.1.14, authenticate, and execute the SQL statement to drop the 'users' table. + +Implementation +-------------- + +The bot extends ``DatabaseClient`` and leverages its connectivity. + +- Uses the Application base class for lifecycle management. +- Credentials and target IP set via ``configure``. +- ``run`` handles connecting, executing statement, and disconnecting. +- SQL payload executed via ``query`` method. +- Results in malicious SQL being executed on remote database server. diff --git a/docs/source/simulation_components/network/database_client_server.rst b/docs/source/simulation_components/system/database_client_server.rst similarity index 100% rename from docs/source/simulation_components/network/database_client_server.rst rename to docs/source/simulation_components/system/database_client_server.rst diff --git a/docs/source/simulation_components/network/internal_frame_processing.rst b/docs/source/simulation_components/system/internal_frame_processing.rst similarity index 99% rename from docs/source/simulation_components/network/internal_frame_processing.rst rename to docs/source/simulation_components/system/internal_frame_processing.rst index e173a3ac..9c5356cc 100644 --- a/docs/source/simulation_components/network/internal_frame_processing.rst +++ b/docs/source/simulation_components/system/internal_frame_processing.rst @@ -2,7 +2,7 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -.. _about: +.. _internal_frame_processing: Internal Frame Processing ========================= diff --git a/docs/source/simulation_components/network/software.rst b/docs/source/simulation_components/system/software.rst similarity index 88% rename from docs/source/simulation_components/network/software.rst rename to docs/source/simulation_components/system/software.rst index 0dcb1d63..d0355d3a 100644 --- a/docs/source/simulation_components/network/software.rst +++ b/docs/source/simulation_components/system/software.rst @@ -16,3 +16,4 @@ Contents :maxdepth: 8 database_client_server + data_manipulation_bot diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 79c7d77b..c3a935b8 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -184,7 +184,7 @@ class Network(SimComponent): self._node_id_map[len(self.nodes)] = node node.parent = self self._nx_graph.add_node(node.hostname) - _LOGGER.info(f"Added node {node.uuid} to Network {self.uuid}") + _LOGGER.debug(f"Added node {node.uuid} to Network {self.uuid}") def get_node_by_hostname(self, hostname: str) -> Optional[Node]: """ @@ -245,7 +245,7 @@ class Network(SimComponent): self._link_id_map[len(self.links)] = link self._nx_graph.add_edge(endpoint_a.parent.hostname, endpoint_b.parent.hostname) link.parent = self - _LOGGER.info(f"Added link {link.uuid} to connect {endpoint_a} and {endpoint_b}") + _LOGGER.debug(f"Added link {link.uuid} to connect {endpoint_a} and {endpoint_b}") def remove_link(self, link: Link) -> None: """Disconnect a link from the network. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 5b9cdf5b..bceb385c 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -186,7 +186,7 @@ class NIC(SimComponent): if self.connected_node: self.connected_node.sys_log.info(f"NIC {self} disabled") else: - _LOGGER.info(f"NIC {self} disabled") + _LOGGER.debug(f"NIC {self} disabled") if self.connected_link: self.connected_link.endpoint_down() @@ -208,7 +208,7 @@ class NIC(SimComponent): # TODO: Inform the Node that a link has been connected self.connected_link = link self.enable() - _LOGGER.info(f"NIC {self} connected to Link {link}") + _LOGGER.debug(f"NIC {self} connected to Link {link}") def disconnect_link(self): """Disconnect the NIC from the connected Link.""" @@ -351,7 +351,7 @@ class SwitchPort(SimComponent): if self.connected_node: self.connected_node.sys_log.info(f"SwitchPort {self} disabled") else: - _LOGGER.info(f"SwitchPort {self} disabled") + _LOGGER.debug(f"SwitchPort {self} disabled") if self.connected_link: self.connected_link.endpoint_down() @@ -371,7 +371,7 @@ class SwitchPort(SimComponent): # TODO: Inform the Switch that a link has been connected self.connected_link = link - _LOGGER.info(f"SwitchPort {self} connected to Link {link}") + _LOGGER.debug(f"SwitchPort {self} connected to Link {link}") self.enable() def disconnect_link(self): @@ -477,13 +477,13 @@ class Link(SimComponent): def endpoint_up(self): """Let the Link know and endpoint has been brought up.""" if self.is_up: - _LOGGER.info(f"Link {self} up") + _LOGGER.debug(f"Link {self} up") def endpoint_down(self): """Let the Link know and endpoint has been brought down.""" if not self.is_up: self.current_load = 0.0 - _LOGGER.info(f"Link {self} down") + _LOGGER.debug(f"Link {self} down") @property def is_up(self) -> bool: @@ -510,7 +510,7 @@ class Link(SimComponent): """ can_transmit = self._can_transmit(frame) if not can_transmit: - _LOGGER.info(f"Cannot transmit frame as {self} is at capacity") + _LOGGER.debug(f"Cannot transmit frame as {self} is at capacity") return False receiver = self.endpoint_a @@ -522,7 +522,7 @@ class Link(SimComponent): # Frame transmitted successfully # Load the frame size on the link self.current_load += frame_size - _LOGGER.info( + _LOGGER.debug( f"Added {frame_size:.3f} Mbits to {self}, current load {self.current_load:.3f} Mbits " f"({self.current_load_percent})" ) @@ -1148,7 +1148,7 @@ class Node(SimComponent): service.parent = self service.install() # Perform any additional setup, such as creating files for this service on the node. self.sys_log.info(f"Installed service {service.name}") - _LOGGER.info(f"Added service {service.uuid} to node {self.uuid}") + _LOGGER.debug(f"Added service {service.uuid} to node {self.uuid}") def uninstall_service(self, service: Service) -> None: """Uninstall and completely remove service from this node. @@ -1163,7 +1163,7 @@ class Node(SimComponent): self.services.pop(service.uuid) service.parent = None self.sys_log.info(f"Uninstalled service {service.name}") - _LOGGER.info(f"Removed service {service.uuid} from node {self.uuid}") + _LOGGER.debug(f"Removed service {service.uuid} from node {self.uuid}") def __contains__(self, item: Any) -> bool: if isinstance(item, Service): diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index b9554cb9..ce1ef338 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -1,3 +1,5 @@ +from ipaddress import IPv4Address + from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.base import NIC from primaite.simulator.network.hardware.nodes.computer import Computer @@ -8,6 +10,7 @@ from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database_service import DatabaseService +from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot def client_server_routed() -> Network: @@ -127,6 +130,9 @@ def arcd_uc2_network() -> Network: ) client_1.power_on() network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) + client_1.software_manager.install(DataManipulationBot) + db_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] + db_manipulation_bot.configure(server_ip_address=IPv4Address("192.168.1.14"), payload="DROP TABLE IF EXISTS user;") # Client 2 client_2 = Computer( @@ -145,16 +151,6 @@ def arcd_uc2_network() -> Network: domain_controller.power_on() network.connect(endpoint_b=domain_controller.ethernet_port[1], endpoint_a=switch_1.switch_ports[1]) - # Web Server - web_server = Server( - hostname="web_server", ip_address="192.168.1.12", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" - ) - web_server.power_on() - web_server.software_manager.install(DatabaseClient) - database_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] - database_client.run() - network.connect(endpoint_b=web_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[2]) - # Database Server database_server = Server( hostname="database_server", @@ -194,9 +190,21 @@ def arcd_uc2_network() -> Network: database_server.software_manager.install(DatabaseService) database_service: DatabaseService = database_server.software_manager.software["DatabaseService"] # noqa database_service.start() - database_service._process_sql(ddl) # noqa + database_service._process_sql(ddl, None) # noqa for insert_statement in user_insert_statements: - database_service._process_sql(insert_statement) # noqa + database_service._process_sql(insert_statement, None) # noqa + + # Web Server + web_server = Server( + hostname="web_server", ip_address="192.168.1.12", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + ) + web_server.power_on() + web_server.software_manager.install(DatabaseClient) + database_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + database_client.configure(server_ip_address=IPv4Address("192.168.1.14")) + network.connect(endpoint_b=web_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[2]) + database_client.run() + database_client.connect() # Backup Server backup_server = Server( diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index a866b290..9d59a2f4 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -1,11 +1,12 @@ from ipaddress import IPv4Address from typing import Any, Dict, Optional +from uuid import uuid4 from prettytable import PrettyTable from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.applications.application import Application, ApplicationOperatingState from primaite.simulator.system.core.software_manager import SoftwareManager @@ -20,7 +21,9 @@ class DatabaseClient(Application): """ server_ip_address: Optional[IPv4Address] = None + server_password: Optional[str] = None connected: bool = False + _query_success_tracker: Dict[str, bool] = {} def __init__(self, **kwargs): kwargs["name"] = "DatabaseClient" @@ -37,15 +40,22 @@ class DatabaseClient(Application): pass return super().describe_state() - def connect(self, server_ip_address: IPv4Address, password: Optional[str] = None) -> bool: + def configure(self, server_ip_address: IPv4Address, server_password: Optional[str] = None): """ - Connect to a Database Service. + Configure the DatabaseClient to communicate with a DatabaseService. - :param server_ip_address: The IPv4 Address of the Node the Database Service is running on. - :param password: The Database Service password. Is optional and has a default value of None. + :param server_ip_address: The IP address of the Node the DatabaseService is on. + :param server_password: The password on the DatabaseService. """ + self.server_ip_address = server_ip_address + self.server_password = server_password + self.sys_log.info(f"Configured the {self.name} with {server_ip_address=}, {server_password=}.") + + def connect(self) -> bool: + """Connect to a Database Service.""" if not self.connected and self.operating_state.RUNNING: - return self._connect(server_ip_address, password) + return self._connect(self.server_ip_address, self.server_password) + return False def _connect( self, server_ip_address: IPv4Address, password: Optional[str] = None, is_reattempt: bool = False @@ -75,18 +85,42 @@ class DatabaseClient(Application): self.sys_log.info(f"DatabaseClient disconnected from {self.server_ip_address}") self.server_ip_address = None + self.connected = False - def query(self, sql: str): + def _query(self, sql: str, query_id: str, is_reattempt: bool = False) -> bool: + if is_reattempt: + success = self._query_success_tracker.get(query_id) + if success: + return True + return False + else: + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager( + payload={"type": "sql", "sql": sql, "uuid": query_id}, + dest_ip_address=self.server_ip_address, + dest_port=self.port, + ) + return self._query(sql=sql, query_id=query_id, is_reattempt=True) + + def run(self) -> None: + """Run the DatabaseClient.""" + super().run() + self.operating_state = ApplicationOperatingState.RUNNING + self.connect() + + def query(self, sql: str) -> bool: """ Send a query to the Database Service. :param sql: The SQL query. + :return: True if the query was successful, otherwise False. """ if self.connected and self.operating_state.RUNNING: - software_manager: SoftwareManager = self.software_manager - software_manager.send_payload_to_session_manager( - payload={"type": "sql", "sql": sql}, dest_ip_address=self.server_ip_address, dest_port=self.port - ) + query_id = str(uuid4()) + + # Initialise the tracker of this ID to False + self._query_success_tracker[query_id] = False + return self._query(sql=sql, query_id=query_id) def _print_data(self, data: Dict): """ @@ -94,13 +128,14 @@ class DatabaseClient(Application): :param markdown: Whether to display the table in Markdown format or not. Default is `False`. """ - table = PrettyTable(list(data.values())[0]) + if data: + table = PrettyTable(list(data.values())[0]) - table.align = "l" - table.title = f"{self.sys_log.hostname} Database Client" - for row in data.values(): - table.add_row(row.values()) - print(table) + table.align = "l" + table.title = f"{self.sys_log.hostname} Database Client" + for row in data.values(): + table.add_row(row.values()) + print(table) def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ @@ -114,5 +149,9 @@ class DatabaseClient(Application): if payload["type"] == "connect_response": self.connected = payload["response"] == True elif payload["type"] == "sql": - self._print_data(payload["data"]) + query_id = payload.get("uuid") + status_code = payload.get("status_code") + self._query_success_tracker[query_id] = status_code == 200 + if self._query_success_tracker[query_id]: + self._print_data(payload["data"]) return True diff --git a/src/primaite/simulator/system/services/database_service.py b/src/primaite/simulator/system/services/database_service.py index d4289c08..62120fc7 100644 --- a/src/primaite/simulator/system/services/database_service.py +++ b/src/primaite/simulator/system/services/database_service.py @@ -81,20 +81,21 @@ class DatabaseService(Service): status_code = 404 # service not found return {"status_code": status_code, "type": "connect_response", "response": status_code == 200} - def _process_sql(self, query: str) -> Dict[str, Union[int, List[Any]]]: + def _process_sql(self, query: str, query_id: str) -> Dict[str, Union[int, List[Any]]]: """ Executes the given SQL query and returns the result. :param query: The SQL query to be executed. :return: Dictionary containing status code and data fetched. """ + self.sys_log.info(f"{self.name}: Running {query}") try: self._cursor.execute(query) - self._conn.commit() except OperationalError: # Handle the case where the table does not exist. - return {"status_code": 404, "data": []} + self.sys_log.error(f"{self.name}: Error, query failed") + return {"status_code": 404, "data": {}} data = [] description = self._cursor.description if description: @@ -104,7 +105,7 @@ class DatabaseService(Service): data = self._cursor.fetchall() if data and headers: data = {row[0]: {header: value for header, value in zip(headers, row)} for row in data} - return {"status_code": 200, "type": "sql", "data": data} + return {"status_code": 200, "type": "sql", "data": data, "uuid": query_id} def describe_state(self) -> Dict: """ @@ -134,7 +135,7 @@ class DatabaseService(Service): self.connections.pop(session_id) elif payload["type"] == "sql": if session_id in self.connections: - result = self._process_sql(payload.get("sql")) + result = self._process_sql(query=payload["sql"], query_id=payload["uuid"]) else: result = {"status_code": 401, "type": "sql"} self.send(payload=result, session_id=session_id) diff --git a/src/primaite/simulator/system/services/red_services/__init__.py b/src/primaite/simulator/system/services/red_services/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py new file mode 100644 index 00000000..30643b32 --- /dev/null +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -0,0 +1,49 @@ +from ipaddress import IPv4Address +from typing import Optional + +from primaite.simulator.system.applications.database_client import DatabaseClient + + +class DataManipulationBot(DatabaseClient): + """ + Red Agent Data Integration Service. + + The Service represents a bot that causes files/folders in the File System to + become corrupted. + """ + + server_ip_address: Optional[IPv4Address] = None + payload: Optional[str] = None + server_password: Optional[str] = None + + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.name = "DataManipulationBot" + + def configure( + self, server_ip_address: IPv4Address, server_password: Optional[str] = None, payload: Optional[str] = None + ): + """ + Configure the DataManipulatorBot to communicate with a DatabaseService. + + :param server_ip_address: The IP address of the Node the DatabaseService is on. + :param server_password: The password on the DatabaseService. + :param payload: The data manipulation query payload. + """ + self.server_ip_address = server_ip_address + self.payload = payload + self.server_password = server_password + self.sys_log.info(f"Configured the {self.name} with {server_ip_address=}, {payload=}, {server_password=}.") + + def run(self): + """Run the DataManipulationBot.""" + if self.server_ip_address and self.payload: + self.sys_log.info(f"Attempting to start the {self.name}") + super().run() + if not self.connected: + self.connect() + if self.connected: + self.query(self.payload) + self.sys_log.info(f"{self.name} payload delivered: {self.payload}") + else: + self.sys_log.error(f"Failed to start the {self.name} as it requires both a target_io_address and payload.") diff --git a/src/primaite/simulator/system/services/red_services/data_manipulator_service.py b/src/primaite/simulator/system/services/red_services/data_manipulator_service.py deleted file mode 100644 index 82b9aa1c..00000000 --- a/src/primaite/simulator/system/services/red_services/data_manipulator_service.py +++ /dev/null @@ -1,34 +0,0 @@ -from ipaddress import IPv4Address -from typing import Any, Optional - -from primaite.simulator.network.transmission.network_layer import IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.services.service import Service - - -class DataManipulatorService(Service): - """ - Red Agent Data Integration Service. - - The Service represents a bot that causes files/folders in the File System to - become corrupted. - """ - - def __init__(self, **kwargs): - kwargs["name"] = "DataManipulatorBot" - kwargs["port"] = Port.POSTGRES_SERVER - kwargs["protocol"] = IPProtocol.TCP - super().__init__(**kwargs) - - def start(self, target_ip_address: IPv4Address, payload: Optional[Any] = "DELETE TABLE users", **kwargs): - """ - Run the DataManipulatorService actions. - - :param: target_ip_address: The IP address of the target machine to attack - :param: payload: The payload to send to the target machine - """ - super().start() - - self.software_manager.send_payload_to_session_manager( - payload=payload, dest_ip_address=target_ip_address, dest_port=self.port - ) diff --git a/tests/e2e_integration_tests/__init__.py b/tests/e2e_integration_tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py new file mode 100644 index 00000000..a859e5ff --- /dev/null +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -0,0 +1,25 @@ +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.services.database_service import DatabaseService +from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot + + +def test_data_manipulation(uc2_network): + client_1: Computer = uc2_network.get_node_by_hostname("client_1") + db_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] + + database_server: Server = uc2_network.get_node_by_hostname("database_server") + db_service: DatabaseService = database_server.software_manager.software["DatabaseService"] + + web_server: Server = uc2_network.get_node_by_hostname("web_server") + db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + + # First check that the DB client on the web_server can successfully query the users table on the database + assert db_client.query("SELECT * FROM user;") + + # Now we run the DataManipulationBot + db_manipulation_bot.run() + + # Now check that the DB client on the web_server cannot query the users table on the database + assert not db_client.query("SELECT * FROM user;") diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 31e04666..2a77a31b 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -12,9 +12,6 @@ def test_database_client_server_connection(uc2_network): db_server: Server = uc2_network.get_node_by_hostname("database_server") db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] - assert len(db_service.connections) == 0 - - assert db_client.connect(server_ip_address=IPv4Address("192.168.1.14")) assert len(db_service.connections) == 1 db_client.disconnect() @@ -27,11 +24,14 @@ def test_database_client_server_correct_password(uc2_network): db_server: Server = uc2_network.get_node_by_hostname("database_server") db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + + db_client.disconnect() + + db_client.configure(server_ip_address=IPv4Address("192.168.1.14"), server_password="12345") db_service.password = "12345" - assert len(db_service.connections) == 0 + assert db_client.connect() - assert db_client.connect(server_ip_address=IPv4Address("192.168.1.14"), password="12345") assert len(db_service.connections) == 1 @@ -41,11 +41,12 @@ def test_database_client_server_incorrect_password(uc2_network): db_server: Server = uc2_network.get_node_by_hostname("database_server") db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + + db_client.disconnect() + db_client.configure(server_ip_address=IPv4Address("192.168.1.14"), server_password="54321") db_service.password = "12345" - assert len(db_service.connections) == 0 - - assert not db_client.connect(server_ip_address=IPv4Address("192.168.1.14"), password="54321") + assert not db_client.connect() assert len(db_service.connections) == 0 @@ -53,14 +54,6 @@ def test_database_client_query(uc2_network): """Tests DB query across the network returns HTTP status 200 and date.""" web_server: Server = uc2_network.get_node_by_hostname("web_server") db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + db_client.connect() - db_client.connect(server_ip_address=IPv4Address("192.168.1.14")) - - db_client.query("SELECT * FROM user;") - - web_server_nic = web_server.ethernet_port[1] - - web_server_last_payload = web_server_nic.pcap.read()[-1]["payload"] - - assert web_server_last_payload["status_code"] == 200 - assert web_server_last_payload["data"] + assert db_client.query("SELECT * FROM user;") diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index 290e7cc3..66bd59a9 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -1,5 +1,7 @@ import json +import pytest + from primaite.simulator.network.container import Network @@ -10,6 +12,7 @@ def test_creating_container(): assert net.links == {} +@pytest.mark.skip(reason="Skipping until we tackle serialisation") def test_describe_state(): """Check that we can describe network state without raising errors, and that the result is JSON serialisable.""" net = Network() diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py new file mode 100644 index 00000000..dd785cc1 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py @@ -0,0 +1,20 @@ +from ipaddress import IPv4Address + +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.networks import arcd_uc2_network +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot + + +def test_creation(): + network = arcd_uc2_network() + + client_1: Node = network.get_node_by_hostname("client_1") + + data_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] + + assert data_manipulation_bot.name == "DataManipulationBot" + assert data_manipulation_bot.port == Port.POSTGRES_SERVER + assert data_manipulation_bot.protocol == IPProtocol.TCP + assert data_manipulation_bot.payload == "DROP TABLE IF EXISTS user;" diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py deleted file mode 100644 index f95081a6..00000000 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulator_service.py +++ /dev/null @@ -1,32 +0,0 @@ -from ipaddress import IPv4Address - -from primaite.simulator.network.hardware.base import Node -from primaite.simulator.network.networks import arcd_uc2_network -from primaite.simulator.network.transmission.network_layer import IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.services.red_services.data_manipulator_service import DataManipulatorService - - -def test_creation(): - network = arcd_uc2_network() - - client_1: Node = network.get_node_by_hostname("client_1") - - client_1.software_manager.install(service_class=DataManipulatorService) - - data_manipulator_service: DataManipulatorService = client_1.software_manager.software["DataManipulatorBot"] - - assert data_manipulator_service.name == "DataManipulatorBot" - assert data_manipulator_service.port == Port.POSTGRES_SERVER - assert data_manipulator_service.protocol == IPProtocol.TCP - - # should have no session yet - assert len(client_1.session_manager.sessions_by_uuid) == 0 - - try: - data_manipulator_service.start(target_ip_address=IPv4Address("192.168.1.14")) - except Exception as e: - assert False, f"Test was not supposed to throw exception: {e}" - - # there should be a session after the service is started - assert len(client_1.session_manager.sessions_by_uuid) == 1 From 1a81285b7621a4d3a9399170f646a79e1451c503 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 12 Sep 2023 08:46:07 +0100 Subject: [PATCH 164/980] #1752: Added send+receive functionality for DNS client and server + tests + added simulation_output to gitignore --- .gitignore | 2 + src/primaite/simulator/network/networks.py | 15 +++++ .../simulator/network/protocols/dns.py | 8 +-- .../simulator/system/services/dns_client.py | 55 +++++++++++------- .../simulator/system/services/dns_server.py | 15 ++--- .../system/test_dns_client_server.py | 24 ++++++++ .../_simulator/_system/_services/test_dns.py | 58 +++++++++++++++---- 7 files changed, 129 insertions(+), 48 deletions(-) create mode 100644 tests/integration_tests/system/test_dns_client_server.py diff --git a/.gitignore b/.gitignore index ff86b65f..66d528a8 100644 --- a/.gitignore +++ b/.gitignore @@ -144,9 +144,11 @@ cython_debug/ # IDE .idea/ docs/source/primaite-dependencies.rst +.vscode/ # outputs src/primaite/outputs/ +simulation_output/ # benchmark session outputs benchmark/output diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index ce1ef338..79af75e4 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -10,6 +10,8 @@ from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database_service import DatabaseService +from primaite.simulator.system.services.dns_client import DNSClient +from primaite.simulator.system.services.dns_server import DNSServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot @@ -129,6 +131,7 @@ def arcd_uc2_network() -> Network: hostname="client_1", ip_address="192.168.10.21", subnet_mask="255.255.255.0", default_gateway="192.168.10.1" ) client_1.power_on() + client_1.software_manager.install(DNSClient) network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) client_1.software_manager.install(DataManipulationBot) db_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] @@ -139,6 +142,7 @@ def arcd_uc2_network() -> Network: hostname="client_2", ip_address="192.168.10.22", subnet_mask="255.255.255.0", default_gateway="192.168.10.1" ) client_2.power_on() + client_2.software_manager.install(DNSClient) network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) # Domain Controller @@ -149,6 +153,8 @@ def arcd_uc2_network() -> Network: default_gateway="192.168.1.1", ) domain_controller.power_on() + domain_controller.software_manager.install(DNSServer) + network.connect(endpoint_b=domain_controller.ethernet_port[1], endpoint_a=switch_1.switch_ports[1]) # Database Server @@ -200,12 +206,17 @@ def arcd_uc2_network() -> Network: ) web_server.power_on() web_server.software_manager.install(DatabaseClient) + database_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] database_client.configure(server_ip_address=IPv4Address("192.168.1.14")) network.connect(endpoint_b=web_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[2]) database_client.run() database_client.connect() + # register the web_server to a domain + dns_server_service: DNSServer = domain_controller.software_manager.software["DNSServer"] # noqa + dns_server_service.dns_register("arcd.com", web_server.ip_address) + # Backup Server backup_server = Server( hostname="backup_server", ip_address="192.168.1.16", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" @@ -229,6 +240,10 @@ def arcd_uc2_network() -> Network: router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + # Allow PostgreSQL requests router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER) + # Allow DNS requests + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.DNS, dst_port=Port.DNS) + return network diff --git a/src/primaite/simulator/network/protocols/dns.py b/src/primaite/simulator/network/protocols/dns.py index 0afa6405..e5602c91 100644 --- a/src/primaite/simulator/network/protocols/dns.py +++ b/src/primaite/simulator/network/protocols/dns.py @@ -56,7 +56,7 @@ class DNSPacket(BaseModel): :param domain_ip_address: The IP address that was being sought after from the original target domain name. :return: A new instance of DNSPacket. """ - return DNSPacket( - dns_request=DNSRequest(domain_name_request=self.dns_request.domain_name_request), - dns_reply=DNSReply(domain_name_ip_address=domain_ip_address), - ) + if domain_ip_address is not None: + self.dns_reply = DNSReply(domain_name_ip_address=IPv4Address(domain_ip_address)) + + return self diff --git a/src/primaite/simulator/system/services/dns_client.py b/src/primaite/simulator/system/services/dns_client.py index 3929065d..db01c05c 100644 --- a/src/primaite/simulator/system/services/dns_client.py +++ b/src/primaite/simulator/system/services/dns_client.py @@ -1,11 +1,15 @@ from ipaddress import IPv4Address from typing import Any, Dict, Optional +from primaite import getLogger from primaite.simulator.network.protocols.dns import DNSPacket, DNSRequest from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.services.service import Service +_LOGGER = getLogger(__name__) + class DNSClient(Service): """Represents a DNS Client as a Service.""" @@ -52,15 +56,15 @@ class DNSClient(Service): """ self.dns_cache[domain_name] = ip_address - def check_domain_in_cache( + def check_domain_exists( self, target_domain: str, dest_ip_address: Optional[IPv4Address] = None, - dest_port: Optional[Port] = None, + dest_port: Optional[Port] = Port.DNS, session_id: Optional[str] = None, is_reattempt: bool = False, ) -> bool: - """Function to check if domain name is in DNS client cache. + """Function to check if domain name exists. :param: target_domain: The domain requested for an IP address. :param: dest_ip_address: The ip address of the payload destination. @@ -80,21 +84,26 @@ class DNSClient(Service): return False else: # send a request to check if domain name exists in the DNS Server - self.send(payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id) - # call function again - return self.check_domain_in_cache( - target_domain=target_domain, + self.software_manager.send_payload_to_session_manager( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, - session_id=session_id, - is_reattempt=True, ) + # check if the domain has been added to cache + if self.dns_cache.get(target_domain) is None: + # call function again + return self.check_domain_exists( + target_domain=target_domain, + dest_ip_address=dest_ip_address, + dest_port=dest_port, + session_id=session_id, + is_reattempt=True, + ) + def send( self, payload: Any, - dest_ip_address: Optional[IPv4Address] = None, - dest_port: Optional[Port] = None, session_id: Optional[str] = None, **kwargs, ) -> bool: @@ -112,15 +121,12 @@ class DNSClient(Service): :return: True if successful, False otherwise. """ # create DNS request packet - self.software_manager.send_payload_to_session_manager( - payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id - ) + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id) def receive( self, payload: Any, - dest_ip_address: Optional[IPv4Address] = None, - dest_port: Optional[Port] = None, session_id: Optional[str] = None, **kwargs, ) -> bool: @@ -131,11 +137,18 @@ class DNSClient(Service): is generated should be implemented in subclasses. :param payload: The payload to be sent. - :param dest_ip_address: The ip address of the payload destination. - :param dest_port: The port of the payload destination. :param session_id: The Session ID the payload is to originate from. Optional. :return: True if successful, False otherwise. """ - super().send() - # check the DNS packet (dns request, dns reply) here and see if it actually worked - pass + # The payload should be a DNS packet + if not isinstance(payload, DNSPacket): + _LOGGER.debug(f"{payload} is not a DNSPacket") + return False + # cast payload into a DNS packet + payload: DNSPacket = payload + if payload.dns_reply is not None: + # add the IP address to the client cache + self.dns_cache[payload.dns_request.domain_name_request] = payload.dns_reply.domain_name_ip_address + return True + + return False diff --git a/src/primaite/simulator/system/services/dns_server.py b/src/primaite/simulator/system/services/dns_server.py index 3dcd89f9..b879d515 100644 --- a/src/primaite/simulator/system/services/dns_server.py +++ b/src/primaite/simulator/system/services/dns_server.py @@ -75,8 +75,6 @@ class DNSServer(Service): def send( self, payload: Any, - dest_ip_address: Optional[IPv4Address] = None, - dest_port: Optional[Port] = None, session_id: Optional[str] = None, **kwargs, ) -> bool: @@ -87,14 +85,13 @@ class DNSServer(Service): is generated should be implemented in subclasses. :param: payload: The payload to send. - :param: dest_ip_address: The ip address of the machine that the payload will be sent to - :param: dest_port: The port of the machine that the payload will be sent to :param: session_id: The id of the session :return: True if successful, False otherwise. """ try: self.software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id) + return True except Exception as e: _LOGGER.error(e) return False @@ -102,8 +99,6 @@ class DNSServer(Service): def receive( self, payload: Any, - dest_ip_address: Optional[IPv4Address] = None, - dest_port: Optional[Port] = None, session_id: Optional[str] = None, **kwargs, ) -> bool: @@ -114,11 +109,9 @@ class DNSServer(Service): is generated should be implemented in subclasses. :param: payload: The payload to send. - :param: dest_ip_address: The ip address of the machine that the payload will be sent to - :param: dest_port: The port of the machine that the payload will be sent to :param: session_id: The id of the session - :return: True if successful, False otherwise. + :return: True if DNS request returns a valid IP, otherwise, False """ # The payload should be a DNS packet if not isinstance(payload, DNSPacket): @@ -128,10 +121,10 @@ class DNSServer(Service): payload: DNSPacket = payload if payload.dns_request is not None: # generate a reply with the correct DNS IP address - payload.generate_reply(self.dns_lookup(payload.dns_request.domain_name_request)) + payload = payload.generate_reply(self.dns_lookup(payload.dns_request.domain_name_request)) # send reply self.send(payload, session_id) - return True + return payload.dns_reply is not None return False diff --git a/tests/integration_tests/system/test_dns_client_server.py b/tests/integration_tests/system/test_dns_client_server.py new file mode 100644 index 00000000..77fa6017 --- /dev/null +++ b/tests/integration_tests/system/test_dns_client_server.py @@ -0,0 +1,24 @@ +from ipaddress import IPv4Address + +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.system.services.dns_client import DNSClient +from primaite.simulator.system.services.dns_server import DNSServer + + +def test_dns_client_server(uc2_network): + client_1: Computer = uc2_network.get_node_by_hostname("client_1") + domain_controller: Server = uc2_network.get_node_by_hostname("domain_controller") + + dns_client: DNSClient = client_1.software_manager.software["DNSClient"] + dns_server: DNSServer = domain_controller.software_manager.software["DNSServer"] + + # register a domain to web server + dns_server.dns_register("real-domain.com", IPv4Address("192.168.1.12")) + + dns_server.show() + + dns_client.check_domain_exists(target_domain="real-domain.com", dest_ip_address=IPv4Address("192.168.1.14")) + + # should register the domain in the client cache + assert dns_client.dns_cache.get("real-domain.com") is not None diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py index fdb3426d..943d3265 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py @@ -1,10 +1,9 @@ -import sys from ipaddress import IPv4Address import pytest from primaite.simulator.network.hardware.base import Node -from primaite.simulator.network.networks import arcd_uc2_network +from primaite.simulator.network.protocols.dns import DNSPacket, DNSReply, DNSRequest from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.dns_client import DNSClient @@ -14,22 +13,22 @@ from primaite.simulator.system.services.dns_server import DNSServer @pytest.fixture(scope="function") def dns_server() -> Node: node = Node(hostname="dns_server") - node.software_manager.add_service(service_class=DNSServer) - node.software_manager.services["DNSServer"].start() + node.software_manager.install(software_class=DNSServer) + node.software_manager.software["DNSServer"].start() return node @pytest.fixture(scope="function") def dns_client() -> Node: node = Node(hostname="dns_client") - node.software_manager.add_service(service_class=DNSClient) - node.software_manager.services["DNSClient"].start() + node.software_manager.install(software_class=DNSClient) + node.software_manager.software["DNSClient"].start() return node def test_create_dns_server(dns_server): assert dns_server is not None - dns_server_service: DNSServer = dns_server.software_manager.services["DNSServer"] + dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] assert dns_server_service.name is "DNSServer" assert dns_server_service.port is Port.DNS assert dns_server_service.protocol is IPProtocol.UDP @@ -37,7 +36,7 @@ def test_create_dns_server(dns_server): def test_create_dns_client(dns_client): assert dns_client is not None - dns_client_service: DNSClient = dns_client.software_manager.services["DNSClient"] + dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] assert dns_client_service.name is "DNSClient" assert dns_client_service.port is Port.DNS assert dns_client_service.protocol is IPProtocol.UDP @@ -45,7 +44,7 @@ def test_create_dns_client(dns_client): def test_dns_server_domain_name_registration(dns_server): """Test to check if the domain name registration works.""" - dns_server_service: DNSServer = dns_server.software_manager.services["DNSServer"] + dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] # register the web server in the domain controller dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12")) @@ -57,10 +56,45 @@ def test_dns_server_domain_name_registration(dns_server): def test_dns_client_check_domain_in_cache(dns_client): """Test to make sure that the check_domain_in_cache returns the correct values.""" - dns_client_service: DNSClient = dns_client.software_manager.services["DNSClient"] + dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] # add a domain to the dns client cache dns_client_service.add_domain_to_cache("real-domain.com", IPv4Address("192.168.1.12")) - assert dns_client_service.check_domain_in_cache("fake-domain.com") is False - assert dns_client_service.check_domain_in_cache("real-domain.com") is True + assert dns_client_service.check_domain_exists("fake-domain.com") is False + assert dns_client_service.check_domain_exists("real-domain.com") is True + + +def test_dns_server_receive(dns_server): + """Test to make sure that the DNS Server correctly responds to a DNS Client request.""" + dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] + + # register the web server in the domain controller + dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12")) + + assert ( + dns_server_service.receive(payload=DNSPacket(dns_request=DNSRequest(domain_name_request="fake-domain.com"))) + is False + ) + + assert ( + dns_server_service.receive(payload=DNSPacket(dns_request=DNSRequest(domain_name_request="real-domain.com"))) + is True + ) + + dns_server_service.show() + + +def test_dns_client_receive(dns_client): + """Test to make sure the DNS Client knows how to deal with request responses.""" + dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] + + dns_client_service.receive( + payload=DNSPacket( + dns_request=DNSRequest(domain_name_request="real-domain.com"), + dns_reply=DNSReply(domain_name_ip_address=IPv4Address("192.168.1.12")), + ) + ) + + # domain name should be saved to cache + assert dns_client_service.dns_cache["real-domain.com"] == IPv4Address("192.168.1.12") From fb96ef18c0dfb9a7bf0c9aac3c8e25de559cc55b Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 12 Sep 2023 09:32:28 +0100 Subject: [PATCH 165/980] #1752: remove unnecessary changes --- .../simulator/system/core/session_manager.py | 2 +- src/primaite/simulator/system/services/service.py | 14 +------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index f8e97442..06701546 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -94,7 +94,7 @@ class SessionManager: @staticmethod def _get_session_key( frame: Frame, inbound_frame: bool = True - ) -> Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]]: + ) -> Tuple[IPProtocol, IPv4Address, IPv4Address, Optional[Port], Optional[Port]]: """ Extracts the session key from the given frame. diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index f7f189f1..20b92027 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,10 +1,8 @@ from enum import Enum -from ipaddress import IPv4Address from typing import Any, Dict, Optional from primaite import getLogger from primaite.simulator.core import Action, ActionManager -from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.software import IOSoftware _LOGGER = getLogger(__name__) @@ -77,8 +75,6 @@ class Service(IOSoftware): def send( self, payload: Any, - dest_ip_address: Optional[IPv4Address] = None, - dest_port: Optional[Port] = None, session_id: Optional[str] = None, **kwargs, ) -> bool: @@ -89,21 +85,15 @@ class Service(IOSoftware): is generated should be implemented in subclasses. :param: payload: The payload to send. - :param: dest_ip_address: The ip address of the machine that the payload will be sent to - :param: dest_port: The port of the machine that the payload will be sent to :param: session_id: The id of the session :return: True if successful, False otherwise. """ - self.software_manager.send_payload_to_session_manager( - payload=payload, dest_ip_address=dest_ip_address, dest_port=self.port, session_id=session_id - ) + self.software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id) def receive( self, payload: Any, - dest_ip_address: Optional[IPv4Address] = None, - dest_port: Optional[Port] = None, session_id: Optional[str] = None, **kwargs, ) -> bool: @@ -114,8 +104,6 @@ class Service(IOSoftware): is generated should be implemented in subclasses. :param: payload: The payload to send. - :param: dest_ip_address: The ip address of the machine that the payload will be sent to - :param: dest_port: The port of the machine that the payload will be sent to :param: session_id: The id of the session :return: True if successful, False otherwise. From 275115f4ddc8e4d5db9561969f2b8aada1c43ae3 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 12 Sep 2023 12:12:38 +0000 Subject: [PATCH 166/980] Updated pull_request_template.md --- .azuredevops/pull_request_template.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.azuredevops/pull_request_template.md b/.azuredevops/pull_request_template.md index f7533b37..bd25cdc1 100644 --- a/.azuredevops/pull_request_template.md +++ b/.azuredevops/pull_request_template.md @@ -5,10 +5,12 @@ *How have you tested this (if applicable)?* ## Checklist -- [ ] This PR is linked to a **work item** -- [ ] I have performed **self-review** of the code -- [ ] I have written **tests** for any new functionality added with this PR -- [ ] I have updated the **documentation** if this PR changes or adds functionality -- [ ] I have written/updated **design docs** if this PR implements new functionality -- [ ] I have update the **change log** -- [ ] I have run **pre-commit** checks for code style +- [ ] PR is linked to a **work item** +- [ ] **acceptance criteria** of linked ticket are met +- [ ] performed **self-review** of the code +- [ ] written **tests** for any new functionality added with this PR +- [ ] updated the **documentation** if this PR changes or adds functionality +- [ ] written/updated **design docs** if this PR implements new functionality +- [ ] updated the **change log** +- [ ] ran **pre-commit** checks for code style +- [ ] attended to any **TO-DOs** left in the code From 8b6bc843216c148723cae97de05513b8a2713c01 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 12 Sep 2023 13:37:11 +0100 Subject: [PATCH 167/980] #1752: simplifying the DNS implementation - switch to TCP + fixing the DNS integration test --- src/primaite/simulator/network/hardware/base.py | 3 ++- src/primaite/simulator/network/networks.py | 5 +++++ .../network/transmission/data_link_layer.py | 3 --- .../simulator/system/core/session_manager.py | 6 ++++-- .../simulator/system/services/dns_client.py | 8 +++++--- .../simulator/system/services/dns_server.py | 3 ++- .../system/test_dns_client_server.py | 16 +++++++++++----- .../_simulator/_system/_services/test_dns.py | 4 ++-- 8 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index bceb385c..04262037 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -406,7 +406,8 @@ class SwitchPort(SimComponent): if self.enabled: frame.decrement_ttl() self.pcap.capture(frame) - self.connected_node.forward_frame(frame=frame, incoming_port=self) + connected_node: Node = self.connected_node + connected_node.forward_frame(frame=frame, incoming_port=self) return True return False diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 79af75e4..0b9a2299 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -132,6 +132,8 @@ def arcd_uc2_network() -> Network: ) client_1.power_on() client_1.software_manager.install(DNSClient) + client_1_dns_client_service: DNSServer = client_1.software_manager.software["DNSClient"] # noqa + client_1_dns_client_service.start() network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) client_1.software_manager.install(DataManipulationBot) db_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] @@ -143,6 +145,8 @@ def arcd_uc2_network() -> Network: ) client_2.power_on() client_2.software_manager.install(DNSClient) + client_2_dns_client_service: DNSServer = client_2.software_manager.software["DNSClient"] # noqa + client_2_dns_client_service.start() network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) # Domain Controller @@ -215,6 +219,7 @@ def arcd_uc2_network() -> Network: # register the web_server to a domain dns_server_service: DNSServer = domain_controller.software_manager.software["DNSServer"] # noqa + dns_server_service.start() dns_server_service.dns_register("arcd.com", web_server.ip_address) # Backup Server diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index 5c09210a..b7986622 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -5,7 +5,6 @@ from pydantic import BaseModel from primaite import getLogger from primaite.simulator.network.protocols.arp import ARPPacket -from primaite.simulator.network.protocols.dns import DNSPacket from primaite.simulator.network.transmission.network_layer import ICMPPacket, IPPacket, IPProtocol from primaite.simulator.network.transmission.primaite_layer import PrimaiteHeader from primaite.simulator.network.transmission.transport_layer import TCPHeader, UDPHeader @@ -97,8 +96,6 @@ class Frame(BaseModel): "ICMP header." arp: Optional[ARPPacket] = None "ARP packet." - dns: Optional[DNSPacket] = None - "DNS packet." primaite: PrimaiteHeader "PrimAITE header." payload: Optional[Any] = None diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 06701546..95ece9f9 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -74,7 +74,9 @@ class SessionManager: """ def __init__(self, sys_log: SysLog, arp_cache: "ARPCache"): - self.sessions_by_key: Dict[Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]], Session] = {} + self.sessions_by_key: Dict[ + Tuple[IPProtocol, IPv4Address, IPv4Address, Optional[Port], Optional[Port]], Session + ] = {} self.sessions_by_uuid: Dict[str, Session] = {} self.sys_log: SysLog = sys_log self.software_manager: SoftwareManager = None # Noqa @@ -94,7 +96,7 @@ class SessionManager: @staticmethod def _get_session_key( frame: Frame, inbound_frame: bool = True - ) -> Tuple[IPProtocol, IPv4Address, IPv4Address, Optional[Port], Optional[Port]]: + ) -> Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]]: """ Extracts the session key from the given frame. diff --git a/src/primaite/simulator/system/services/dns_client.py b/src/primaite/simulator/system/services/dns_client.py index db01c05c..d6e4a05b 100644 --- a/src/primaite/simulator/system/services/dns_client.py +++ b/src/primaite/simulator/system/services/dns_client.py @@ -22,7 +22,8 @@ class DNSClient(Service): kwargs["port"] = Port.DNS # DNS uses UDP by default # it switches to TCP when the bytes exceed 512 (or 4096) bytes - kwargs["protocol"] = IPProtocol.UDP + # TCP for now + kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) def describe_state(self) -> Dict: @@ -84,14 +85,15 @@ class DNSClient(Service): return False else: # send a request to check if domain name exists in the DNS Server - self.software_manager.send_payload_to_session_manager( + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager( payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, ) # check if the domain has been added to cache - if self.dns_cache.get(target_domain) is None: + if self.dns_cache.get(target_domain, None) is None: # call function again return self.check_domain_exists( target_domain=target_domain, diff --git a/src/primaite/simulator/system/services/dns_server.py b/src/primaite/simulator/system/services/dns_server.py index b879d515..c36c7034 100644 --- a/src/primaite/simulator/system/services/dns_server.py +++ b/src/primaite/simulator/system/services/dns_server.py @@ -23,7 +23,8 @@ class DNSServer(Service): kwargs["port"] = Port.DNS # DNS uses UDP by default # it switches to TCP when the bytes exceed 512 (or 4096) bytes - kwargs["protocol"] = IPProtocol.UDP + # TCP for now + kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) def describe_state(self) -> Dict: diff --git a/tests/integration_tests/system/test_dns_client_server.py b/tests/integration_tests/system/test_dns_client_server.py index 77fa6017..a4514bad 100644 --- a/tests/integration_tests/system/test_dns_client_server.py +++ b/tests/integration_tests/system/test_dns_client_server.py @@ -4,6 +4,7 @@ from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.system.services.dns_client import DNSClient from primaite.simulator.system.services.dns_server import DNSServer +from primaite.simulator.system.services.service import ServiceOperatingState def test_dns_client_server(uc2_network): @@ -13,12 +14,17 @@ def test_dns_client_server(uc2_network): dns_client: DNSClient = client_1.software_manager.software["DNSClient"] dns_server: DNSServer = domain_controller.software_manager.software["DNSServer"] - # register a domain to web server - dns_server.dns_register("real-domain.com", IPv4Address("192.168.1.12")) + assert dns_client.operating_state == ServiceOperatingState.RUNNING + assert dns_server.operating_state == ServiceOperatingState.RUNNING dns_server.show() - dns_client.check_domain_exists(target_domain="real-domain.com", dest_ip_address=IPv4Address("192.168.1.14")) + # fake domain should not be added to dns cache + dns_client.check_domain_exists( + target_domain="fake-domain.com", dest_ip_address=IPv4Address(domain_controller.ip_address) + ) + assert dns_client.dns_cache.get("fake-domain.com", None) is None - # should register the domain in the client cache - assert dns_client.dns_cache.get("real-domain.com") is not None + # arcd.com is registered in dns server and should be saved to cache + dns_client.check_domain_exists(target_domain="arcd.com", dest_ip_address=IPv4Address(domain_controller.ip_address)) + assert dns_client.dns_cache.get("arcd.com", None) is not None diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py index 943d3265..b4f20539 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py @@ -31,7 +31,7 @@ def test_create_dns_server(dns_server): dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] assert dns_server_service.name is "DNSServer" assert dns_server_service.port is Port.DNS - assert dns_server_service.protocol is IPProtocol.UDP + assert dns_server_service.protocol is IPProtocol.TCP def test_create_dns_client(dns_client): @@ -39,7 +39,7 @@ def test_create_dns_client(dns_client): dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] assert dns_client_service.name is "DNSClient" assert dns_client_service.port is Port.DNS - assert dns_client_service.protocol is IPProtocol.UDP + assert dns_client_service.protocol is IPProtocol.TCP def test_dns_server_domain_name_registration(dns_server): From b0478f4e88de2a8cf8e3239b711647c593177867 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 13 Sep 2023 08:46:22 +0100 Subject: [PATCH 168/980] #1752: added positions to ACL rules for UC2 network to prevent rules being overwritten --- src/primaite/simulator/network/networks.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 0b9a2299..45056a4d 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -246,9 +246,11 @@ def arcd_uc2_network() -> Network: router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) # Allow PostgreSQL requests - router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER) + router_1.acl.add_rule( + action=ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER, position=0 + ) # Allow DNS requests - router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.DNS, dst_port=Port.DNS) + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.DNS, dst_port=Port.DNS, position=1) return network From 98e103a984da2f5152e1e974c6981645da7cbec0 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 13 Sep 2023 09:48:38 +0100 Subject: [PATCH 169/980] #1752: added documentation for DNS Client and Server --- .../system/dns_client_server.rst | 56 +++++++++++++++++++ .../simulation_components/system/software.rst | 1 + 2 files changed, 57 insertions(+) create mode 100644 docs/source/simulation_components/system/dns_client_server.rst diff --git a/docs/source/simulation_components/system/dns_client_server.rst b/docs/source/simulation_components/system/dns_client_server.rst new file mode 100644 index 00000000..776c90b7 --- /dev/null +++ b/docs/source/simulation_components/system/dns_client_server.rst @@ -0,0 +1,56 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +DNS Client Server +====================== + +DNS Server +---------------- +Also known as a DNS Resolver, the ``DNSServer`` provides a DNS Server simulation by extending the base Service class. + +Key capabilities +^^^^^^^^^^^^^^^^ + +- Simulates DNS requests and DNSPacket transfer across a network +- Registers domain names and the IP Address linked to the domain name +- Returns the IP address for a given domain name within a DNS Packet that a DNS Client can read +- Leverages the Service base class for install/uninstall, status tracking, etc. + +Usage +^^^^^ +- Install on a Node via the ``SoftwareManager`` to start the database service. +- Service runs on TCP port 53 by default. (TODO: TCP for now, should be UDP in future) + +Implementation +^^^^^^^^^^^^^^ + +- DNS request and responses use a ``DNSPacket`` object +- Extends Service class for integration with ``SoftwareManager``. + +DNS Client +--------------- + +The DNSClient provides a client interface for connecting to the ``DNSServer``. + +Key features +^^^^^^^^^^^^ + +- Connects to the ``DNSServer`` via the ``SoftwareManager``. +- Executes DNS lookup requests and keeps a cache of known domain name IP addresses. +- Handles connection to DNSServer and querying for domain name IP addresses. + +Usage +^^^^^ + +- Install on a Node via the ``SoftwareManager`` to start the database service. +- Service runs on TCP port 53 by default. (TODO: TCP for now, should be UDP in future) +- Execute domain name checks with ``check_domain_exists``, providing a ``DNSServer`` ``IPv4Address``. +- ``DNSClient`` will automatically add the IP Address of the domain into its cache + +Implementation +^^^^^^^^^^^^^^ + +- Leverages ``SoftwareManager`` for sending payloads over the network. +- Provides easy interface for Nodes to find IP addresses via domain names. +- Extends base Service class. diff --git a/docs/source/simulation_components/system/software.rst b/docs/source/simulation_components/system/software.rst index d0355d3a..275fdaf9 100644 --- a/docs/source/simulation_components/system/software.rst +++ b/docs/source/simulation_components/system/software.rst @@ -17,3 +17,4 @@ Contents database_client_server data_manipulation_bot + dns_client_server From b1e46b4f9ebf3fcb84c0b96acbf4e3e9bdb1f689 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Thu, 14 Sep 2023 20:08:06 +0100 Subject: [PATCH 170/980] #1752: Apply suggestions from PR review --- .../system/applications/web_browser.py | 24 +------------ .../simulator/system/services/dns_client.py | 16 ++++----- .../simulator/system/services/dns_server.py | 34 +++---------------- 3 files changed, 14 insertions(+), 60 deletions(-) diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index b30f9946..78d196b7 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -1,6 +1,5 @@ -from abc import abstractmethod from ipaddress import IPv4Address -from typing import Any, Dict, List, Optional +from typing import Any, Dict, Optional from primaite.simulator.system.applications.application import Application @@ -19,27 +18,6 @@ class WebBrowser(Application): history: Dict[str] "A dict that stores all of the previous domain names." - @abstractmethod - def describe_state(self) -> Dict: - """ - Describes the current state of the software. - - The specifics of the software's state, including its health, criticality, - and any other pertinent information, should be implemented in subclasses. - - :return: A dictionary containing key-value pairs representing the current state of the software. - :rtype: Dict - """ - pass - - def apply_action(self, action: List[str]) -> None: - """ - Applies a list of actions to the Application. - - :param action: A list of actions to apply. - """ - pass - def reset_component_for_episode(self, episode: int): """ Resets the Application component for a new episode. diff --git a/src/primaite/simulator/system/services/dns_client.py b/src/primaite/simulator/system/services/dns_client.py index d6e4a05b..af20d6b8 100644 --- a/src/primaite/simulator/system/services/dns_client.py +++ b/src/primaite/simulator/system/services/dns_client.py @@ -1,5 +1,5 @@ from ipaddress import IPv4Address -from typing import Any, Dict, Optional +from typing import Dict, Optional from primaite import getLogger from primaite.simulator.network.protocols.dns import DNSPacket, DNSRequest @@ -36,7 +36,8 @@ class DNSClient(Service): :return: A dictionary containing key-value pairs representing the current state of the software. :rtype: Dict """ - return {"Operating State": self.operating_state} + state = super().describe_state() + return state def reset_component_for_episode(self, episode: int): """ @@ -45,8 +46,7 @@ class DNSClient(Service): This method ensures the Service is ready for a new episode, including resetting any stateful properties or statistics, and clearing any message queues. """ - super().reset_component_for_episode(episode=episode) - self.dns_cache = {} + pass def add_domain_to_cache(self, domain_name: str, ip_address: IPv4Address): """ @@ -68,8 +68,8 @@ class DNSClient(Service): """Function to check if domain name exists. :param: target_domain: The domain requested for an IP address. - :param: dest_ip_address: The ip address of the payload destination. - :param: dest_port: The port of the payload destination. + :param: dest_ip_address: The ip address of the DNS Server used for domain lookup. + :param: dest_port: The port on the DNS Server which accepts domain lookup requests. Default is Port.DNS. :param: session_id: The Session ID the payload is to originate from. Optional. :param: is_reattempt: Checks if the request has been reattempted. Default is False. """ @@ -105,7 +105,7 @@ class DNSClient(Service): def send( self, - payload: Any, + payload: DNSPacket, session_id: Optional[str] = None, **kwargs, ) -> bool: @@ -128,7 +128,7 @@ class DNSClient(Service): def receive( self, - payload: Any, + payload: DNSPacket, session_id: Optional[str] = None, **kwargs, ) -> bool: diff --git a/src/primaite/simulator/system/services/dns_server.py b/src/primaite/simulator/system/services/dns_server.py index c36c7034..be1145a2 100644 --- a/src/primaite/simulator/system/services/dns_server.py +++ b/src/primaite/simulator/system/services/dns_server.py @@ -37,9 +37,10 @@ class DNSServer(Service): :return: A dictionary containing key-value pairs representing the current state of the software. :rtype: Dict """ - return {"Operating State": self.operating_state} + state = super().describe_state() + return state - def dns_lookup(self, target_domain: Any) -> Optional[IPv4Address]: + def dns_lookup(self, target_domain: str) -> Optional[IPv4Address]: """ Attempts to find the IP address for a domain name. @@ -70,32 +71,7 @@ class DNSServer(Service): This method ensures the Service is ready for a new episode, including resetting any stateful properties or statistics, and clearing any message queues. """ - self.dns_table = {} - super().reset_component_for_episode(episode=episode) - - def send( - self, - payload: Any, - session_id: Optional[str] = None, - **kwargs, - ) -> bool: - """ - Sends a payload to the SessionManager. - - The specifics of how the payload is processed and whether a response payload - is generated should be implemented in subclasses. - - :param: payload: The payload to send. - :param: session_id: The id of the session - - :return: True if successful, False otherwise. - """ - try: - self.software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id) - return True - except Exception as e: - _LOGGER.error(e) - return False + pass def receive( self, @@ -110,7 +86,7 @@ class DNSServer(Service): is generated should be implemented in subclasses. :param: payload: The payload to send. - :param: session_id: The id of the session + :param: session_id: The id of the session. Optional. :return: True if DNS request returns a valid IP, otherwise, False """ From 939de40f1e2a3f5c9fef4784e30d002d9e000352 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 18 Sep 2023 10:25:26 +0100 Subject: [PATCH 171/980] #1752 - Moved dns_server ip address from the NIC to the Node. Updated the arcd_uc2_network so that clients and servers have a dns server. Added sys_log entries for DNSServer and DNSClient. MAde the DNSServer always rend a reply, but for the resolved IP address to be empty if it cannot be resolved. --- .../system/dns_client_server.rst | 8 ++--- .../simulator/network/hardware/base.py | 7 ++-- src/primaite/simulator/network/networks.py | 26 +++++++++++--- .../simulator/network/protocols/dns.py | 5 ++- .../simulator/system/core/software_manager.py | 13 +++++-- .../simulator/system/services/dns_client.py | 36 +++++++++---------- .../simulator/system/services/dns_server.py | 15 +++++--- .../system/test_dns_client_server.py | 6 ++-- 8 files changed, 72 insertions(+), 44 deletions(-) diff --git a/docs/source/simulation_components/system/dns_client_server.rst b/docs/source/simulation_components/system/dns_client_server.rst index 776c90b7..f57f903b 100644 --- a/docs/source/simulation_components/system/dns_client_server.rst +++ b/docs/source/simulation_components/system/dns_client_server.rst @@ -3,10 +3,10 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK DNS Client Server -====================== +================= DNS Server ----------------- +---------- Also known as a DNS Resolver, the ``DNSServer`` provides a DNS Server simulation by extending the base Service class. Key capabilities @@ -29,7 +29,7 @@ Implementation - Extends Service class for integration with ``SoftwareManager``. DNS Client ---------------- +---------- The DNSClient provides a client interface for connecting to the ``DNSServer``. @@ -45,7 +45,7 @@ Usage - Install on a Node via the ``SoftwareManager`` to start the database service. - Service runs on TCP port 53 by default. (TODO: TCP for now, should be UDP in future) -- Execute domain name checks with ``check_domain_exists``, providing a ``DNSServer`` ``IPv4Address``. +- Execute domain name checks with ``check_domain_exists``. - ``DNSClient`` will automatically add the IP Address of the domain into its cache Implementation diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 04262037..dd2130d2 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -5,7 +5,7 @@ import secrets from enum import Enum from ipaddress import IPv4Address, IPv4Network from pathlib import Path -from typing import Any, Dict, List, Literal, Optional, Tuple, Union +from typing import Any, Dict, Literal, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable @@ -89,8 +89,6 @@ class NIC(SimComponent): "The Maximum Transmission Unit (MTU) of the NIC in Bytes. Default is 1500 B" wake_on_lan: bool = False "Indicates if the NIC supports Wake-on-LAN functionality." - dns_servers: List[IPv4Address] = [] - "List of IP addresses of DNS servers used for name resolution." connected_node: Optional[Node] = None "The Node to which the NIC is connected." connected_link: Optional[Link] = None @@ -882,6 +880,8 @@ class Node(SimComponent): "The NICs on the node." ethernet_port: Dict[int, NIC] = {} "The NICs on the node by port id." + dns_server: Optional[IPv4Address] = None + "List of IP addresses of DNS servers used for name resolution." accounts: Dict[str, Account] = {} "All accounts on the node." @@ -931,6 +931,7 @@ class Node(SimComponent): sys_log=kwargs.get("sys_log"), session_manager=kwargs.get("session_manager"), file_system=kwargs.get("file_system"), + dns_server=kwargs.get("dns_server"), ) super().__init__(**kwargs) self.arp.nics = self.nics diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 45056a4d..78d2e68f 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -128,7 +128,11 @@ def arcd_uc2_network() -> Network: # Client 1 client_1 = Computer( - hostname="client_1", ip_address="192.168.10.21", subnet_mask="255.255.255.0", default_gateway="192.168.10.1" + hostname="client_1", + ip_address="192.168.10.21", + subnet_mask="255.255.255.0", + default_gateway="192.168.10.1", + dns_server=IPv4Address("192.168.1.10"), ) client_1.power_on() client_1.software_manager.install(DNSClient) @@ -141,7 +145,11 @@ def arcd_uc2_network() -> Network: # Client 2 client_2 = Computer( - hostname="client_2", ip_address="192.168.10.22", subnet_mask="255.255.255.0", default_gateway="192.168.10.1" + hostname="client_2", + ip_address="192.168.10.22", + subnet_mask="255.255.255.0", + default_gateway="192.168.10.1", + dns_server=IPv4Address("192.168.1.10"), ) client_2.power_on() client_2.software_manager.install(DNSClient) @@ -167,6 +175,7 @@ def arcd_uc2_network() -> Network: ip_address="192.168.1.14", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", + dns_server=IPv4Address("192.168.1.10"), ) database_server.power_on() network.connect(endpoint_b=database_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[3]) @@ -206,7 +215,11 @@ def arcd_uc2_network() -> Network: # Web Server web_server = Server( - hostname="web_server", ip_address="192.168.1.12", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + hostname="web_server", + ip_address="192.168.1.12", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + dns_server=IPv4Address("192.168.1.10"), ) web_server.power_on() web_server.software_manager.install(DatabaseClient) @@ -224,7 +237,11 @@ def arcd_uc2_network() -> Network: # Backup Server backup_server = Server( - hostname="backup_server", ip_address="192.168.1.16", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + hostname="backup_server", + ip_address="192.168.1.16", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + dns_server=IPv4Address("192.168.1.10"), ) backup_server.power_on() network.connect(endpoint_b=backup_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[4]) @@ -235,6 +252,7 @@ def arcd_uc2_network() -> Network: ip_address="192.168.1.110", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", + dns_server=IPv4Address("192.168.1.10"), ) security_suite.power_on() network.connect(endpoint_b=security_suite.ethernet_port[1], endpoint_a=switch_1.switch_ports[7]) diff --git a/src/primaite/simulator/network/protocols/dns.py b/src/primaite/simulator/network/protocols/dns.py index e5602c91..41bf5e0c 100644 --- a/src/primaite/simulator/network/protocols/dns.py +++ b/src/primaite/simulator/network/protocols/dns.py @@ -22,7 +22,7 @@ class DNSReply(BaseModel): :param domain_name_ip_address: IP Address of the Domain Name requested. """ - domain_name_ip_address: IPv4Address + domain_name_ip_address: Optional[IPv4Address] = None "IP Address of the Domain Name requested." @@ -56,7 +56,6 @@ class DNSPacket(BaseModel): :param domain_ip_address: The IP address that was being sought after from the original target domain name. :return: A new instance of DNSPacket. """ - if domain_ip_address is not None: - self.dns_reply = DNSReply(domain_name_ip_address=IPv4Address(domain_ip_address)) + self.dns_reply = DNSReply(domain_name_ip_address=domain_ip_address) return self diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index d5fda1b3..99445bf8 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -23,7 +23,13 @@ IOSoftwareClass = TypeVar("IOSoftwareClass", bound=IOSoftware) class SoftwareManager: """A class that manages all running Services and Applications on a Node and facilitates their communication.""" - def __init__(self, session_manager: "SessionManager", sys_log: SysLog, file_system: FileSystem): + def __init__( + self, + session_manager: "SessionManager", + sys_log: SysLog, + file_system: FileSystem, + dns_server: Optional[IPv4Address], + ): """ Initialize a new instance of SoftwareManager. @@ -35,6 +41,7 @@ class SoftwareManager: self.port_protocol_mapping: Dict[Tuple[Port, IPProtocol], Union[Service, Application]] = {} self.sys_log: SysLog = sys_log self.file_system: FileSystem = file_system + self.dns_server: Optional[IPv4Address] = dns_server def get_open_ports(self) -> List[Port]: """ @@ -58,7 +65,9 @@ class SoftwareManager: if software_class in self._software_class_to_name_map: self.sys_log.info(f"Cannot install {software_class} as it is already installed") return - software = software_class(software_manager=self, sys_log=self.sys_log, file_system=self.file_system) + software = software_class( + software_manager=self, sys_log=self.sys_log, file_system=self.file_system, dns_server=self.dns_server + ) if isinstance(software, Application): software.install() software.software_manager = self diff --git a/src/primaite/simulator/system/services/dns_client.py b/src/primaite/simulator/system/services/dns_client.py index af20d6b8..cf5278af 100644 --- a/src/primaite/simulator/system/services/dns_client.py +++ b/src/primaite/simulator/system/services/dns_client.py @@ -16,6 +16,8 @@ class DNSClient(Service): dns_cache: Dict[str, IPv4Address] = {} "A dict of known mappings between domain/URLs names and IPv4 addresses." + dns_server: Optional[IPv4Address] = None + "The DNS Server the client sends requests to." def __init__(self, **kwargs): kwargs["name"] = "DNSClient" @@ -60,16 +62,12 @@ class DNSClient(Service): def check_domain_exists( self, target_domain: str, - dest_ip_address: Optional[IPv4Address] = None, - dest_port: Optional[Port] = Port.DNS, session_id: Optional[str] = None, is_reattempt: bool = False, ) -> bool: """Function to check if domain name exists. :param: target_domain: The domain requested for an IP address. - :param: dest_ip_address: The ip address of the DNS Server used for domain lookup. - :param: dest_port: The port on the DNS Server which accepts domain lookup requests. Default is Port.DNS. :param: session_id: The Session ID the payload is to originate from. Optional. :param: is_reattempt: Checks if the request has been reattempted. Default is False. """ @@ -78,30 +76,28 @@ class DNSClient(Service): # check if the domain is already in the DNS cache if target_domain in self.dns_cache: + self.sys_log.info( + f"DNS Client: Domain lookup for {target_domain} successful, resolves to {self.dns_cache[target_domain]}" + ) return True else: # return False if already reattempted if is_reattempt: + self.sys_log.info(f"DNS Client: Domain lookup for {target_domain} failed") return False else: # send a request to check if domain name exists in the DNS Server software_manager: SoftwareManager = self.software_manager software_manager.send_payload_to_session_manager( - payload=payload, - dest_ip_address=dest_ip_address, - dest_port=dest_port, + payload=payload, dest_ip_address=self.dns_server, dest_port=Port.DNS ) - # check if the domain has been added to cache - if self.dns_cache.get(target_domain, None) is None: - # call function again - return self.check_domain_exists( - target_domain=target_domain, - dest_ip_address=dest_ip_address, - dest_port=dest_port, - session_id=session_id, - is_reattempt=True, - ) + # recursively re-call the function passing is_reattempt=True + return self.check_domain_exists( + target_domain=target_domain, + session_id=session_id, + is_reattempt=True, + ) def send( self, @@ -125,6 +121,7 @@ class DNSClient(Service): # create DNS request packet software_manager: SoftwareManager = self.software_manager software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id) + return True def receive( self, @@ -150,7 +147,8 @@ class DNSClient(Service): payload: DNSPacket = payload if payload.dns_reply is not None: # add the IP address to the client cache - self.dns_cache[payload.dns_request.domain_name_request] = payload.dns_reply.domain_name_ip_address - return True + if payload.dns_reply.domain_name_ip_address: + self.dns_cache[payload.dns_request.domain_name_request] = payload.dns_reply.domain_name_ip_address + return True return False diff --git a/src/primaite/simulator/system/services/dns_server.py b/src/primaite/simulator/system/services/dns_server.py index be1145a2..c6a9afd3 100644 --- a/src/primaite/simulator/system/services/dns_server.py +++ b/src/primaite/simulator/system/services/dns_server.py @@ -47,10 +47,7 @@ class DNSServer(Service): :param target_domain: The single domain name requested by a DNS client. :return ip_address: The IP address of that domain name or None. """ - if target_domain in self.dns_table: - return self.dns_table[target_domain] - else: - return None + return self.dns_table.get(target_domain) def dns_register(self, domain_name: str, domain_ip_address: IPv4Address): """ @@ -97,11 +94,19 @@ class DNSServer(Service): # cast payload into a DNS packet payload: DNSPacket = payload if payload.dns_request is not None: + self.sys_log.info( + f"DNS Server: Received domain lookup request for {payload.dns_request.domain_name_request} " + f"from session {session_id}" + ) # generate a reply with the correct DNS IP address payload = payload.generate_reply(self.dns_lookup(payload.dns_request.domain_name_request)) + self.sys_log.info( + f"DNS Server: Responding to domain lookup request for {payload.dns_request.domain_name_request} " + f"with ip address: {payload.dns_reply.domain_name_ip_address}" + ) # send reply self.send(payload, session_id) - return payload.dns_reply is not None + return payload.dns_reply.domain_name_ip_address is not None return False diff --git a/tests/integration_tests/system/test_dns_client_server.py b/tests/integration_tests/system/test_dns_client_server.py index a4514bad..640c268a 100644 --- a/tests/integration_tests/system/test_dns_client_server.py +++ b/tests/integration_tests/system/test_dns_client_server.py @@ -20,11 +20,9 @@ def test_dns_client_server(uc2_network): dns_server.show() # fake domain should not be added to dns cache - dns_client.check_domain_exists( - target_domain="fake-domain.com", dest_ip_address=IPv4Address(domain_controller.ip_address) - ) + assert not dns_client.check_domain_exists(target_domain="fake-domain.com") assert dns_client.dns_cache.get("fake-domain.com", None) is None # arcd.com is registered in dns server and should be saved to cache - dns_client.check_domain_exists(target_domain="arcd.com", dest_ip_address=IPv4Address(domain_controller.ip_address)) + assert dns_client.check_domain_exists(target_domain="arcd.com") assert dns_client.dns_cache.get("arcd.com", None) is not None From f91329405812a90c0bbff9deb21d2e3ad61fe9ba Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Mon, 18 Sep 2023 14:20:19 +0100 Subject: [PATCH 172/980] #1916: moved services into their own subdirectories --- src/primaite/simulator/network/networks.py | 6 +++--- src/primaite/simulator/system/services/database/__init__.py | 0 .../system/services/{ => database}/database_service.py | 0 src/primaite/simulator/system/services/dns/__init__.py | 0 .../simulator/system/services/{ => dns}/dns_client.py | 0 .../simulator/system/services/{ => dns}/dns_server.py | 0 .../test_uc2_data_manipulation_scenario.py | 2 +- tests/integration_tests/system/test_database_on_node.py | 2 +- tests/integration_tests/system/test_dns_client_server.py | 6 ++---- .../_primaite/_simulator/_system/_services/test_database.py | 4 +--- .../_primaite/_simulator/_system/_services/test_dns.py | 4 ++-- 11 files changed, 10 insertions(+), 14 deletions(-) create mode 100644 src/primaite/simulator/system/services/database/__init__.py rename src/primaite/simulator/system/services/{ => database}/database_service.py (100%) create mode 100644 src/primaite/simulator/system/services/dns/__init__.py rename src/primaite/simulator/system/services/{ => dns}/dns_client.py (100%) rename src/primaite/simulator/system/services/{ => dns}/dns_server.py (100%) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 78d2e68f..f594c29a 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -9,9 +9,9 @@ from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient -from primaite.simulator.system.services.database_service import DatabaseService -from primaite.simulator.system.services.dns_client import DNSClient -from primaite.simulator.system.services.dns_server import DNSServer +from primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot diff --git a/src/primaite/simulator/system/services/database/__init__.py b/src/primaite/simulator/system/services/database/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/services/database_service.py b/src/primaite/simulator/system/services/database/database_service.py similarity index 100% rename from src/primaite/simulator/system/services/database_service.py rename to src/primaite/simulator/system/services/database/database_service.py diff --git a/src/primaite/simulator/system/services/dns/__init__.py b/src/primaite/simulator/system/services/dns/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/services/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py similarity index 100% rename from src/primaite/simulator/system/services/dns_client.py rename to src/primaite/simulator/system/services/dns/dns_client.py diff --git a/src/primaite/simulator/system/services/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py similarity index 100% rename from src/primaite/simulator/system/services/dns_server.py rename to src/primaite/simulator/system/services/dns/dns_server.py diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index a859e5ff..50998f09 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -1,7 +1,7 @@ from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient -from primaite.simulator.system.services.database_service import DatabaseService +from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 2a77a31b..c69f131c 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -2,7 +2,7 @@ from ipaddress import IPv4Address from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient -from primaite.simulator.system.services.database_service import DatabaseService +from primaite.simulator.system.services.database.database_service import DatabaseService def test_database_client_server_connection(uc2_network): diff --git a/tests/integration_tests/system/test_dns_client_server.py b/tests/integration_tests/system/test_dns_client_server.py index 640c268a..e82d97a4 100644 --- a/tests/integration_tests/system/test_dns_client_server.py +++ b/tests/integration_tests/system/test_dns_client_server.py @@ -1,9 +1,7 @@ -from ipaddress import IPv4Address - from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.system.services.dns_client import DNSClient -from primaite.simulator.system.services.dns_server import DNSServer +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.service import ServiceOperatingState diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py index d41c63c7..7662fbff 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py @@ -1,9 +1,7 @@ -import json - import pytest from primaite.simulator.network.hardware.base import Node -from primaite.simulator.system.services.database_service import DatabaseService +from primaite.simulator.system.services.database.database_service import DatabaseService @pytest.fixture(scope="function") diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py index b4f20539..f501d14a 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py @@ -6,8 +6,8 @@ from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.protocols.dns import DNSPacket, DNSReply, DNSRequest from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.services.dns_client import DNSClient -from primaite.simulator.system.services.dns_server import DNSServer +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer @pytest.fixture(scope="function") From a719389e05aee3f2520685ab9944e718667377c5 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 19 Sep 2023 11:24:42 +0100 Subject: [PATCH 173/980] Add placeholder actions --- src/primaite/notebooks/scratch.ipynb | 345 ++++++++++++------ .../simulator/file_system/file_system.py | 38 +- .../simulator/network/hardware/base.py | 16 +- 3 files changed, 284 insertions(+), 115 deletions(-) diff --git a/src/primaite/notebooks/scratch.ipynb b/src/primaite/notebooks/scratch.ipynb index 50a85e7a..023b7d12 100644 --- a/src/primaite/notebooks/scratch.ipynb +++ b/src/primaite/notebooks/scratch.ipynb @@ -2,83 +2,50 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The autoreload extension is already loaded. To reload it, use:\n", + " %reload_ext autoreload\n" + ] + } + ], "source": [ - "from primaite.simulator.network.networks import arcd_uc2_network\n" + "from primaite.simulator.network.networks import arcd_uc2_network\n", + "%load_ext autoreload\n", + "%autoreload 2" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2023-09-05 15:52:13,305: Added node 26e189bb-442e-4f73-ab7a-1c4dd162e986 to Network 16435554-f108-479e-a4de-719f39898d0a\n", - "2023-09-05 15:52:13,307: Added node 9d07f591-1e44-41c9-9d7a-0eecf0c53fa4 to Network 16435554-f108-479e-a4de-719f39898d0a\n", - "2023-09-05 15:52:13,322: NIC d5:3d:df:8d:21:94/192.168.1.1 connected to Link d5:3d:df:8d:21:94/192.168.1.1<-->70:63:71:75:0f:84\n", - "2023-09-05 15:52:13,324: SwitchPort 70:63:71:75:0f:84 connected to Link d5:3d:df:8d:21:94/192.168.1.1<-->70:63:71:75:0f:84\n", - "2023-09-05 15:52:13,326: Link d5:3d:df:8d:21:94/192.168.1.1<-->70:63:71:75:0f:84 up\n", - "2023-09-05 15:52:13,327: Link d5:3d:df:8d:21:94/192.168.1.1<-->70:63:71:75:0f:84 up\n", - "2023-09-05 15:52:13,329: Added link 497f7357-e14e-4f00-b6cd-68286b053496 to connect d5:3d:df:8d:21:94/192.168.1.1 and 70:63:71:75:0f:84\n", - "2023-09-05 15:52:13,333: Added node 9cf37bd7-9f67-47f8-836b-3b5e69dd600c to Network 16435554-f108-479e-a4de-719f39898d0a\n", - "2023-09-05 15:52:13,336: NIC c7:ca:5f:6c:50:c9/192.168.10.1 connected to Link c7:ca:5f:6c:50:c9/192.168.10.1<-->e7:21:66:e4:da:2c\n", - "2023-09-05 15:52:13,338: SwitchPort e7:21:66:e4:da:2c connected to Link c7:ca:5f:6c:50:c9/192.168.10.1<-->e7:21:66:e4:da:2c\n", - "2023-09-05 15:52:13,340: Link c7:ca:5f:6c:50:c9/192.168.10.1<-->e7:21:66:e4:da:2c up\n", - "2023-09-05 15:52:13,341: Link c7:ca:5f:6c:50:c9/192.168.10.1<-->e7:21:66:e4:da:2c up\n", - "2023-09-05 15:52:13,343: Added link b1165845-46af-400d-b408-9f6b0fe4a51a to connect c7:ca:5f:6c:50:c9/192.168.10.1 and e7:21:66:e4:da:2c\n", - "2023-09-05 15:52:13,345: Added node 9c7f4049-30fa-40bd-b0c8-2119bef7936c to Network 16435554-f108-479e-a4de-719f39898d0a\n", - "2023-09-05 15:52:13,347: SwitchPort e9:5c:26:c2:74:a2 connected to Link e9:5c:26:c2:74:a2<-->fb:05:aa:54:2d:3e/192.168.10.21\n", - "2023-09-05 15:52:13,351: Link e9:5c:26:c2:74:a2<-->fb:05:aa:54:2d:3e/192.168.10.21 up\n", - "2023-09-05 15:52:13,353: NIC fb:05:aa:54:2d:3e/192.168.10.21 connected to Link e9:5c:26:c2:74:a2<-->fb:05:aa:54:2d:3e/192.168.10.21\n", - "2023-09-05 15:52:13,354: Link e9:5c:26:c2:74:a2<-->fb:05:aa:54:2d:3e/192.168.10.21 up\n", - "2023-09-05 15:52:13,356: Added link 7d9ade8d-ed9c-4688-8375-18b58102b2a7 to connect e9:5c:26:c2:74:a2 and fb:05:aa:54:2d:3e/192.168.10.21\n", - "2023-09-05 15:52:13,358: Added node 88c26ce5-4243-4247-98a3-315ff54f7ef6 to Network 16435554-f108-479e-a4de-719f39898d0a\n", - "2023-09-05 15:52:13,360: SwitchPort 30:fd:61:15:db:ad connected to Link 30:fd:61:15:db:ad<-->c1:e2:46:a2:cb:b2/192.168.10.22\n", - "2023-09-05 15:52:13,362: Link 30:fd:61:15:db:ad<-->c1:e2:46:a2:cb:b2/192.168.10.22 up\n", - "2023-09-05 15:52:13,363: NIC c1:e2:46:a2:cb:b2/192.168.10.22 connected to Link 30:fd:61:15:db:ad<-->c1:e2:46:a2:cb:b2/192.168.10.22\n", - "2023-09-05 15:52:13,365: Link 30:fd:61:15:db:ad<-->c1:e2:46:a2:cb:b2/192.168.10.22 up\n", - "2023-09-05 15:52:13,367: Added link bcfe4c45-d680-4f72-a90a-9fa57c2a6fba to connect 30:fd:61:15:db:ad and c1:e2:46:a2:cb:b2/192.168.10.22\n", - "2023-09-05 15:52:13,370: Added node d7e5389a-9970-4c47-926c-9069b925e934 to Network 16435554-f108-479e-a4de-719f39898d0a\n", - "2023-09-05 15:52:13,372: SwitchPort 35:0c:3a:21:7c:d1 connected to Link 35:0c:3a:21:7c:d1<-->40:4f:3e:f0:32:66/192.168.1.10\n", - "2023-09-05 15:52:13,375: Link 35:0c:3a:21:7c:d1<-->40:4f:3e:f0:32:66/192.168.1.10 up\n", - "2023-09-05 15:52:13,376: NIC 40:4f:3e:f0:32:66/192.168.1.10 connected to Link 35:0c:3a:21:7c:d1<-->40:4f:3e:f0:32:66/192.168.1.10\n", - "2023-09-05 15:52:13,378: Link 35:0c:3a:21:7c:d1<-->40:4f:3e:f0:32:66/192.168.1.10 up\n", - "2023-09-05 15:52:13,380: Added link 34254262-beeb-4967-b7ff-3480928e47f9 to connect 35:0c:3a:21:7c:d1 and 40:4f:3e:f0:32:66/192.168.1.10\n", - "2023-09-05 15:52:13,386: Added node 02c25642-baa5-49a4-aadd-f5d549696351 to Network 16435554-f108-479e-a4de-719f39898d0a\n", - "2023-09-05 15:52:13,388: SwitchPort a4:ab:83:f0:b5:fe connected to Link a4:ab:83:f0:b5:fe<-->4b:a9:6c:90:ae:8f/192.168.1.12\n", - "2023-09-05 15:52:13,390: Link a4:ab:83:f0:b5:fe<-->4b:a9:6c:90:ae:8f/192.168.1.12 up\n", - "2023-09-05 15:52:13,392: NIC 4b:a9:6c:90:ae:8f/192.168.1.12 connected to Link a4:ab:83:f0:b5:fe<-->4b:a9:6c:90:ae:8f/192.168.1.12\n", - "2023-09-05 15:52:13,393: Link a4:ab:83:f0:b5:fe<-->4b:a9:6c:90:ae:8f/192.168.1.12 up\n", - "2023-09-05 15:52:13,395: Added link 433b0cec-445d-4447-9502-c8727eb14a81 to connect a4:ab:83:f0:b5:fe and 4b:a9:6c:90:ae:8f/192.168.1.12\n", - "2023-09-05 15:52:13,398: Added node 6f89bce8-34e4-4fdf-b860-b34027efa639 to Network 16435554-f108-479e-a4de-719f39898d0a\n", - "2023-09-05 15:52:13,400: SwitchPort c2:9f:42:ec:ea:a0 connected to Link c2:9f:42:ec:ea:a0<-->c7:61:9d:6e:0b:29/192.168.1.14\n", - "2023-09-05 15:52:13,403: Link c2:9f:42:ec:ea:a0<-->c7:61:9d:6e:0b:29/192.168.1.14 up\n", - "2023-09-05 15:52:13,405: NIC c7:61:9d:6e:0b:29/192.168.1.14 connected to Link c2:9f:42:ec:ea:a0<-->c7:61:9d:6e:0b:29/192.168.1.14\n", - "2023-09-05 15:52:13,407: Link c2:9f:42:ec:ea:a0<-->c7:61:9d:6e:0b:29/192.168.1.14 up\n", - "2023-09-05 15:52:13,408: Added link 30b18ea0-ea2b-494a-8a63-d5b4bd703668 to connect c2:9f:42:ec:ea:a0 and c7:61:9d:6e:0b:29/192.168.1.14\n", - "2023-09-05 15:52:13,412: Added node 15eb1a5c-50f4-4681-81f8-7ad457c6b1af to Network 16435554-f108-479e-a4de-719f39898d0a\n", - "2023-09-05 15:52:13,414: SwitchPort 5c:0e:20:b3:65:cb connected to Link 5c:0e:20:b3:65:cb<-->bd:06:4d:19:fb:f2/192.168.1.16\n", - "2023-09-05 15:52:13,417: Link 5c:0e:20:b3:65:cb<-->bd:06:4d:19:fb:f2/192.168.1.16 up\n", - "2023-09-05 15:52:13,419: NIC bd:06:4d:19:fb:f2/192.168.1.16 connected to Link 5c:0e:20:b3:65:cb<-->bd:06:4d:19:fb:f2/192.168.1.16\n", - "2023-09-05 15:52:13,420: Link 5c:0e:20:b3:65:cb<-->bd:06:4d:19:fb:f2/192.168.1.16 up\n", - "2023-09-05 15:52:13,421: Added link deb1ee09-9731-46e2-99fb-1276ca48ccb3 to connect 5c:0e:20:b3:65:cb and bd:06:4d:19:fb:f2/192.168.1.16\n", - "2023-09-05 15:52:13,424: Added node 5c5b1c84-5d06-4319-80c0-ca3adf9ce2c6 to Network 16435554-f108-479e-a4de-719f39898d0a\n", - "2023-09-05 15:52:13,425: SwitchPort e6:fa:f7:9a:d3:8c connected to Link e6:fa:f7:9a:d3:8c<-->37:5b:c5:ac:e5:08/192.168.1.110\n", - "2023-09-05 15:52:13,429: Link e6:fa:f7:9a:d3:8c<-->37:5b:c5:ac:e5:08/192.168.1.110 up\n", - "2023-09-05 15:52:13,430: NIC 37:5b:c5:ac:e5:08/192.168.1.110 connected to Link e6:fa:f7:9a:d3:8c<-->37:5b:c5:ac:e5:08/192.168.1.110\n", - "2023-09-05 15:52:13,432: Link e6:fa:f7:9a:d3:8c<-->37:5b:c5:ac:e5:08/192.168.1.110 up\n", - "2023-09-05 15:52:13,434: Added link cf4ecad7-3b24-4f8f-9de8-01b9f64b270b to connect e6:fa:f7:9a:d3:8c and 37:5b:c5:ac:e5:08/192.168.1.110\n", - "2023-09-05 15:52:13,436::ERROR::primaite.simulator.network.hardware.base::176::NIC 4f:4b:3f:f1:02:c0/192.168.10.110 cannot be enabled as it is not connected to a Link\n", - "2023-09-05 15:52:13,438: SwitchPort 57:0a:35:80:1c:38 connected to Link 57:0a:35:80:1c:38<-->4f:4b:3f:f1:02:c0/192.168.10.110\n", - "2023-09-05 15:52:13,440: Link 57:0a:35:80:1c:38<-->4f:4b:3f:f1:02:c0/192.168.10.110 up\n", - "2023-09-05 15:52:13,441: NIC 4f:4b:3f:f1:02:c0/192.168.10.110 connected to Link 57:0a:35:80:1c:38<-->4f:4b:3f:f1:02:c0/192.168.10.110\n", - "2023-09-05 15:52:13,443: Link 57:0a:35:80:1c:38<-->4f:4b:3f:f1:02:c0/192.168.10.110 up\n", - "2023-09-05 15:52:13,447: Added link 035d9749-1bf6-4bd5-b945-c931f207ffb9 to connect 57:0a:35:80:1c:38 and 4f:4b:3f:f1:02:c0/192.168.10.110\n" + "2023-09-19 11:04:37,447: Added node 654e2f3e-1017-4f0a-9f77-addc1f652148 to Network f31c099e-6349-4f78-8a35-899443011640\n", + "2023-09-19 11:04:37,449: Added node 5953be77-ab77-43c0-a8bb-a72f94121358 to Network f31c099e-6349-4f78-8a35-899443011640\n", + "2023-09-19 11:04:37,453: Added node 7eeca128-bea5-4046-8b0c-c11a684f5638 to Network f31c099e-6349-4f78-8a35-899443011640\n", + "2023-09-19 11:04:37,457: Added node dc517f9b-699a-423a-8e68-40f45aece537 to Network f31c099e-6349-4f78-8a35-899443011640\n", + "2023-09-19 11:04:37,461: Added node 0b77284b-93c4-4820-91aa-46ef87d95afe to Network f31c099e-6349-4f78-8a35-899443011640\n", + "2023-09-19 11:04:37,467: Added node 5bbb11fb-d9d6-4e44-92e5-42b31a110bc7 to Network f31c099e-6349-4f78-8a35-899443011640\n", + "2023-09-19 11:04:37,469: Added node f6be7556-fdd9-4207-a588-447ccbdb1ee2 to Network f31c099e-6349-4f78-8a35-899443011640\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-09-19 11:04:37,539: Added node 51795116-f673-4c38-9524-525014565ac6 to Network f31c099e-6349-4f78-8a35-899443011640\n", + "2023-09-19 11:04:37,546: Added node 3fc6c09a-2918-4ae6-85ca-e85eeda8bd47 to Network f31c099e-6349-4f78-8a35-899443011640\n", + "2023-09-19 11:04:37,549: Added node 664bd02f-8c85-4766-8144-46944b9160cb to Network f31c099e-6349-4f78-8a35-899443011640\n", + "2023-09-19 11:04:37,552::ERROR::primaite.simulator.network.hardware.base::176::NIC fb:f1:07:56:1a:dc/192.168.10.110 cannot be enabled as it is not connected to a Link\n" ] } ], @@ -86,6 +53,38 @@ "net = arcd_uc2_network()" ] }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "ename": "RecursionError", + "evalue": "maximum recursion depth exceeded while calling a Python object", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mRecursionError\u001b[0m Traceback (most recent call last)", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/IPython/core/formatters.py:708\u001b[0m, in \u001b[0;36mPlainTextFormatter.__call__\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 701\u001b[0m stream \u001b[39m=\u001b[39m StringIO()\n\u001b[1;32m 702\u001b[0m printer \u001b[39m=\u001b[39m pretty\u001b[39m.\u001b[39mRepresentationPrinter(stream, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mverbose,\n\u001b[1;32m 703\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmax_width, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnewline,\n\u001b[1;32m 704\u001b[0m max_seq_length\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmax_seq_length,\n\u001b[1;32m 705\u001b[0m singleton_pprinters\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39msingleton_printers,\n\u001b[1;32m 706\u001b[0m type_pprinters\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mtype_printers,\n\u001b[1;32m 707\u001b[0m deferred_pprinters\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdeferred_printers)\n\u001b[0;32m--> 708\u001b[0m printer\u001b[39m.\u001b[39;49mpretty(obj)\n\u001b[1;32m 709\u001b[0m printer\u001b[39m.\u001b[39mflush()\n\u001b[1;32m 710\u001b[0m \u001b[39mreturn\u001b[39;00m stream\u001b[39m.\u001b[39mgetvalue()\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/IPython/lib/pretty.py:410\u001b[0m, in \u001b[0;36mRepresentationPrinter.pretty\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 407\u001b[0m \u001b[39mreturn\u001b[39;00m meth(obj, \u001b[39mself\u001b[39m, cycle)\n\u001b[1;32m 408\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mcls\u001b[39m \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mobject\u001b[39m \\\n\u001b[1;32m 409\u001b[0m \u001b[39mand\u001b[39;00m \u001b[39mcallable\u001b[39m(\u001b[39mcls\u001b[39m\u001b[39m.\u001b[39m\u001b[39m__dict__\u001b[39m\u001b[39m.\u001b[39mget(\u001b[39m'\u001b[39m\u001b[39m__repr__\u001b[39m\u001b[39m'\u001b[39m)):\n\u001b[0;32m--> 410\u001b[0m \u001b[39mreturn\u001b[39;00m _repr_pprint(obj, \u001b[39mself\u001b[39;49m, cycle)\n\u001b[1;32m 412\u001b[0m \u001b[39mreturn\u001b[39;00m _default_pprint(obj, \u001b[39mself\u001b[39m, cycle)\n\u001b[1;32m 413\u001b[0m \u001b[39mfinally\u001b[39;00m:\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/IPython/lib/pretty.py:778\u001b[0m, in \u001b[0;36m_repr_pprint\u001b[0;34m(obj, p, cycle)\u001b[0m\n\u001b[1;32m 776\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"A pprint that just redirects to the normal repr function.\"\"\"\u001b[39;00m\n\u001b[1;32m 777\u001b[0m \u001b[39m# Find newlines and replace them with p.break_()\u001b[39;00m\n\u001b[0;32m--> 778\u001b[0m output \u001b[39m=\u001b[39m \u001b[39mrepr\u001b[39;49m(obj)\n\u001b[1;32m 779\u001b[0m lines \u001b[39m=\u001b[39m output\u001b[39m.\u001b[39msplitlines()\n\u001b[1;32m 780\u001b[0m \u001b[39mwith\u001b[39;00m p\u001b[39m.\u001b[39mgroup():\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/main.py:859\u001b[0m, in \u001b[0;36mBaseModel.__repr__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 858\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr__\u001b[39m(\u001b[39mself\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m--> 859\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__repr_name__()\u001b[39m}\u001b[39;00m\u001b[39m(\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__repr_str__(\u001b[39m\"\u001b[39;49m\u001b[39m, \u001b[39;49m\u001b[39m\"\u001b[39;49m)\u001b[39m}\u001b[39;00m\u001b[39m)\u001b[39m\u001b[39m'\u001b[39m\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:55\u001b[0m, in \u001b[0;36mRepresentation.__repr_str__\u001b[0;34m(self, join_str)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_str__\u001b[39m(\u001b[39mself\u001b[39m, join_str: \u001b[39mstr\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m---> 55\u001b[0m \u001b[39mreturn\u001b[39;00m join_str\u001b[39m.\u001b[39;49mjoin(\u001b[39mrepr\u001b[39;49m(v) \u001b[39mif\u001b[39;49;00m a \u001b[39mis\u001b[39;49;00m \u001b[39mNone\u001b[39;49;00m \u001b[39melse\u001b[39;49;00m \u001b[39mf\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39m{\u001b[39;49;00ma\u001b[39m}\u001b[39;49;00m\u001b[39m=\u001b[39;49m\u001b[39m{\u001b[39;49;00mv\u001b[39m!r}\u001b[39;49;00m\u001b[39m'\u001b[39;49m \u001b[39mfor\u001b[39;49;00m a, v \u001b[39min\u001b[39;49;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__repr_args__())\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:55\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_str__\u001b[39m(\u001b[39mself\u001b[39m, join_str: \u001b[39mstr\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m---> 55\u001b[0m \u001b[39mreturn\u001b[39;00m join_str\u001b[39m.\u001b[39mjoin(\u001b[39mrepr\u001b[39m(v) \u001b[39mif\u001b[39;00m a \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39melse\u001b[39;00m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00ma\u001b[39m}\u001b[39;00m\u001b[39m=\u001b[39m\u001b[39m{\u001b[39;00mv\u001b[39m!r}\u001b[39;00m\u001b[39m'\u001b[39m \u001b[39mfor\u001b[39;00m a, v \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__repr_args__())\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/main.py:859\u001b[0m, in \u001b[0;36mBaseModel.__repr__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 858\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr__\u001b[39m(\u001b[39mself\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m--> 859\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__repr_name__()\u001b[39m}\u001b[39;00m\u001b[39m(\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__repr_str__(\u001b[39m\"\u001b[39;49m\u001b[39m, \u001b[39;49m\u001b[39m\"\u001b[39;49m)\u001b[39m}\u001b[39;00m\u001b[39m)\u001b[39m\u001b[39m'\u001b[39m\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:55\u001b[0m, in \u001b[0;36mRepresentation.__repr_str__\u001b[0;34m(self, join_str)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_str__\u001b[39m(\u001b[39mself\u001b[39m, join_str: \u001b[39mstr\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m---> 55\u001b[0m \u001b[39mreturn\u001b[39;00m join_str\u001b[39m.\u001b[39;49mjoin(\u001b[39mrepr\u001b[39;49m(v) \u001b[39mif\u001b[39;49;00m a \u001b[39mis\u001b[39;49;00m \u001b[39mNone\u001b[39;49;00m \u001b[39melse\u001b[39;49;00m \u001b[39mf\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39m{\u001b[39;49;00ma\u001b[39m}\u001b[39;49;00m\u001b[39m=\u001b[39;49m\u001b[39m{\u001b[39;49;00mv\u001b[39m!r}\u001b[39;49;00m\u001b[39m'\u001b[39;49m \u001b[39mfor\u001b[39;49;00m a, v \u001b[39min\u001b[39;49;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__repr_args__())\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:55\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_str__\u001b[39m(\u001b[39mself\u001b[39m, join_str: \u001b[39mstr\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m---> 55\u001b[0m \u001b[39mreturn\u001b[39;00m join_str\u001b[39m.\u001b[39mjoin(\u001b[39mrepr\u001b[39m(v) \u001b[39mif\u001b[39;00m a \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39melse\u001b[39;00m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00ma\u001b[39m}\u001b[39;00m\u001b[39m=\u001b[39m\u001b[39m{\u001b[39;00mv\u001b[39m!r}\u001b[39;00m\u001b[39m'\u001b[39m \u001b[39mfor\u001b[39;00m a, v \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__repr_args__())\n", + " \u001b[0;31m[... skipping similar frames: BaseModel.__repr__ at line 859 (589 times), at line 55 (588 times), Representation.__repr_str__ at line 55 (588 times)]\u001b[0m\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:55\u001b[0m, in \u001b[0;36mRepresentation.__repr_str__\u001b[0;34m(self, join_str)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_str__\u001b[39m(\u001b[39mself\u001b[39m, join_str: \u001b[39mstr\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m---> 55\u001b[0m \u001b[39mreturn\u001b[39;00m join_str\u001b[39m.\u001b[39;49mjoin(\u001b[39mrepr\u001b[39;49m(v) \u001b[39mif\u001b[39;49;00m a \u001b[39mis\u001b[39;49;00m \u001b[39mNone\u001b[39;49;00m \u001b[39melse\u001b[39;49;00m \u001b[39mf\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39m{\u001b[39;49;00ma\u001b[39m}\u001b[39;49;00m\u001b[39m=\u001b[39;49m\u001b[39m{\u001b[39;49;00mv\u001b[39m!r}\u001b[39;49;00m\u001b[39m'\u001b[39;49m \u001b[39mfor\u001b[39;49;00m a, v \u001b[39min\u001b[39;49;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__repr_args__())\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:55\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_str__\u001b[39m(\u001b[39mself\u001b[39m, join_str: \u001b[39mstr\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m---> 55\u001b[0m \u001b[39mreturn\u001b[39;00m join_str\u001b[39m.\u001b[39mjoin(\u001b[39mrepr\u001b[39m(v) \u001b[39mif\u001b[39;00m a \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39melse\u001b[39;00m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00ma\u001b[39m}\u001b[39;00m\u001b[39m=\u001b[39m\u001b[39m{\u001b[39;00mv\u001b[39m!r}\u001b[39;00m\u001b[39m'\u001b[39m \u001b[39mfor\u001b[39;00m a, v \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__repr_args__())\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/main.py:859\u001b[0m, in \u001b[0;36mBaseModel.__repr__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 858\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr__\u001b[39m(\u001b[39mself\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m--> 859\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__repr_name__()\u001b[39m}\u001b[39;00m\u001b[39m(\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__repr_str__(\u001b[39m\"\u001b[39m\u001b[39m, \u001b[39m\u001b[39m\"\u001b[39m)\u001b[39m}\u001b[39;00m\u001b[39m)\u001b[39m\u001b[39m'\u001b[39m\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:52\u001b[0m, in \u001b[0;36mRepresentation.__repr_name__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_name__\u001b[39m(\u001b[39mself\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[1;32m 51\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"Name of the instance's class, used in __repr__.\"\"\"\u001b[39;00m\n\u001b[0;32m---> 52\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m\u001b[39m__class__\u001b[39;49m\u001b[39m.\u001b[39;49m\u001b[39m__name__\u001b[39;49m\n", + "\u001b[0;31mRecursionError\u001b[0m: maximum recursion depth exceeded while calling a Python object" + ] + } + ], + "source": [] + }, { "cell_type": "code", "execution_count": 3, @@ -95,6 +94,26 @@ "act_tree = net._action_manager.get_action_tree()" ] }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "115" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(act_tree)" + ] + }, { "cell_type": "code", "execution_count": 5, @@ -104,59 +123,165 @@ "name": "stdout", "output_type": "stream", "text": [ - "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', 'eb6dfd45-d688-47cf-b061-5f45820a6bc7', 'enable']\n", - "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', 'eb6dfd45-d688-47cf-b061-5f45820a6bc7', 'disable']\n", - "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '2192673d-ad8c-437f-a4d6-0e222ab7e190', 'enable']\n", - "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '2192673d-ad8c-437f-a4d6-0e222ab7e190', 'disable']\n", - "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '3c3fb3d8-c5d1-41aa-8e3e-db1cc0445b0b', 'enable']\n", - "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '3c3fb3d8-c5d1-41aa-8e3e-db1cc0445b0b', 'disable']\n", - "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '29e90915-815f-4505-b957-6f46681950b3', 'enable']\n", - "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '29e90915-815f-4505-b957-6f46681950b3', 'disable']\n", - "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '0915f437-6ed3-4134-b754-7d903c98eb57', 'enable']\n", - "['node', '26e189bb-442e-4f73-ab7a-1c4dd162e986', 'nic', '0915f437-6ed3-4134-b754-7d903c98eb57', 'disable']\n", - "['node', '9c7f4049-30fa-40bd-b0c8-2119bef7936c', 'nic', '199c9558-6a73-423e-9c69-ced05cd597cb', 'enable']\n", - "['node', '9c7f4049-30fa-40bd-b0c8-2119bef7936c', 'nic', '199c9558-6a73-423e-9c69-ced05cd597cb', 'disable']\n", - "['node', '88c26ce5-4243-4247-98a3-315ff54f7ef6', 'nic', '6f871129-d13e-4c8a-85ff-7102fa1e7b8e', 'enable']\n", - "['node', '88c26ce5-4243-4247-98a3-315ff54f7ef6', 'nic', '6f871129-d13e-4c8a-85ff-7102fa1e7b8e', 'disable']\n", - "['node', 'd7e5389a-9970-4c47-926c-9069b925e934', 'nic', 'b6c15c77-8869-400c-8a47-62856dd27ce6', 'enable']\n", - "['node', 'd7e5389a-9970-4c47-926c-9069b925e934', 'nic', 'b6c15c77-8869-400c-8a47-62856dd27ce6', 'disable']\n", - "['node', '02c25642-baa5-49a4-aadd-f5d549696351', 'nic', '398660cc-20ce-444e-b93e-d45b8b865e10', 'enable']\n", - "['node', '02c25642-baa5-49a4-aadd-f5d549696351', 'nic', '398660cc-20ce-444e-b93e-d45b8b865e10', 'disable']\n", - "['node', '6f89bce8-34e4-4fdf-b860-b34027efa639', 'nic', '43c0f913-a203-4436-8649-ab73363bd8cb', 'enable']\n", - "['node', '6f89bce8-34e4-4fdf-b860-b34027efa639', 'nic', '43c0f913-a203-4436-8649-ab73363bd8cb', 'disable']\n", - "['node', '15eb1a5c-50f4-4681-81f8-7ad457c6b1af', 'nic', '1d42ed40-b6f9-4dba-aa23-10143842aac8', 'enable']\n", - "['node', '15eb1a5c-50f4-4681-81f8-7ad457c6b1af', 'nic', '1d42ed40-b6f9-4dba-aa23-10143842aac8', 'disable']\n", - "['node', '5c5b1c84-5d06-4319-80c0-ca3adf9ce2c6', 'nic', 'f921e45e-5a11-4c87-bfe9-47bdba7d6828', 'enable']\n", - "['node', '5c5b1c84-5d06-4319-80c0-ca3adf9ce2c6', 'nic', 'f921e45e-5a11-4c87-bfe9-47bdba7d6828', 'disable']\n", - "['node', '5c5b1c84-5d06-4319-80c0-ca3adf9ce2c6', 'nic', '0ed5ed4a-e36f-4060-a13d-a7832d391887', 'enable']\n", - "['node', '5c5b1c84-5d06-4319-80c0-ca3adf9ce2c6', 'nic', '0ed5ed4a-e36f-4060-a13d-a7832d391887', 'disable']\n" + "[['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '9f5dfd4a-2727-466d-b7ab-6d4f18e0ce2b', 'enable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '9f5dfd4a-2727-466d-b7ab-6d4f18e0ce2b', 'disable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '7ba299f5-1d94-4f9d-a286-8fe3b903a581', 'enable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '7ba299f5-1d94-4f9d-a286-8fe3b903a581', 'disable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '022a1240-844d-4099-930d-052e0452472e', 'enable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '022a1240-844d-4099-930d-052e0452472e', 'disable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '829ff3c6-7e0b-4d28-93bf-b6dc2abd8e2a', 'enable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '829ff3c6-7e0b-4d28-93bf-b6dc2abd8e2a', 'disable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', 'ea185a03-8b34-4347-b0d7-ca2ed61303b4', 'enable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', 'ea185a03-8b34-4347-b0d7-ca2ed61303b4', 'disable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'scan'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'checkhash'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'repair'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'restore'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'scan'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'shutdown'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'startup'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'reset'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'scan'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'checkhash'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'repair'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'restore'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'scan'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'shutdown'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'startup'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'reset'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'scan'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'checkhash'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'repair'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'restore'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'scan'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'shutdown'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'startup'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'reset'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'nic', 'b9b3406a-3a46-4ce7-99d2-6eef00c01b17', 'enable'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'nic', 'b9b3406a-3a46-4ce7-99d2-6eef00c01b17', 'disable'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'scan'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'checkhash'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'repair'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'restore'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'scan'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'shutdown'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'startup'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'reset'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'nic', '428b04e5-03e5-4046-8b4e-6ecf9dc25ff7', 'enable'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'nic', '428b04e5-03e5-4046-8b4e-6ecf9dc25ff7', 'disable'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'scan'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'checkhash'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'repair'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'restore'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'scan'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'shutdown'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'startup'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'reset'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'nic', 'bc6c1fd1-4bda-4b98-9d5c-382b77879eee', 'enable'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'nic', 'bc6c1fd1-4bda-4b98-9d5c-382b77879eee', 'disable'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'scan'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'checkhash'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'repair'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'restore'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'scan'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'shutdown'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'startup'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'reset'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'nic', '795ba4b5-a910-444d-b9f8-31944ea4ff17', 'enable'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'nic', '795ba4b5-a910-444d-b9f8-31944ea4ff17', 'disable'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'scan'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'checkhash'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'repair'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'restore'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'scan'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'checkhash'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'repair'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'restore'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'scan'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'checkhash'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'delete'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'repair'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'restore'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'scan'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'shutdown'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'startup'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'reset'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'nic', 'aa5c5909-bf8c-4dce-8664-a74e9454cc4a', 'enable'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'nic', 'aa5c5909-bf8c-4dce-8664-a74e9454cc4a', 'disable'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'scan'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'checkhash'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'repair'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'restore'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'scan'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'shutdown'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'startup'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'reset'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'nic', '21f32886-65e9-40a0-9483-a86e94dc0a3b', 'enable'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'nic', '21f32886-65e9-40a0-9483-a86e94dc0a3b', 'disable'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'scan'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'checkhash'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'repair'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'restore'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'scan'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'shutdown'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'startup'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'reset'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', 'a1287e24-97c6-4007-93ae-c6b5176f4fbe', 'enable'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', 'a1287e24-97c6-4007-93ae-c6b5176f4fbe', 'disable'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', '174b908b-e214-4efa-8837-d84924dad75f', 'enable'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', '174b908b-e214-4efa-8837-d84924dad75f', 'disable'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'scan'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'checkhash'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'repair'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'restore'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'scan'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'shutdown'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'startup'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'reset']]\n" + ] + } + ], + "source": [ + "print(act_tree)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '9f5dfd4a-2727-466d-b7ab-6d4f18e0ce2b', 'enable']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '9f5dfd4a-2727-466d-b7ab-6d4f18e0ce2b', 'disable']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '7ba299f5-1d94-4f9d-a286-8fe3b903a581', 'enable']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '7ba299f5-1d94-4f9d-a286-8fe3b903a581', 'disable']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '022a1240-844d-4099-930d-052e0452472e', 'enable']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '022a1240-844d-4099-930d-052e0452472e', 'disable']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '829ff3c6-7e0b-4d28-93bf-b6dc2abd8e2a', 'enable']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '829ff3c6-7e0b-4d28-93bf-b6dc2abd8e2a', 'disable']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', 'ea185a03-8b34-4347-b0d7-ca2ed61303b4', 'enable']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', 'ea185a03-8b34-4347-b0d7-ca2ed61303b4', 'disable']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'scan']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'checkhash']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'repair']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'restore']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'scan']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'shutdown']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'startup']\n", + "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'reset']\n", + "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'scan']\n", + "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'checkhash']\n", + "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'repair']\n", + "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'restore']\n", + "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'scan']\n", + "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'shutdown']\n", + "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'startup']\n", + "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'reset']\n", + "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'scan']\n", + "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'checkhash']\n", + "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'repair']\n", + "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'restore']\n", + "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'scan']\n", + "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'shutdown']\n", + "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'startup']\n", + "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'reset']\n", + "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'nic', 'b9b3406a-3a46-4ce7-99d2-6eef00c01b17', 'enable']\n", + "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'nic', 'b9b3406a-3a46-4ce7-99d2-6eef00c01b17', 'disable']\n", + "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'scan']\n", + "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'checkhash']\n", + "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'repair']\n", + "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'restore']\n", + "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'scan']\n", + "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'shutdown']\n", + "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'startup']\n", + "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'reset']\n", + "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'nic', '428b04e5-03e5-4046-8b4e-6ecf9dc25ff7', 'enable']\n", + "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'nic', '428b04e5-03e5-4046-8b4e-6ecf9dc25ff7', 'disable']\n", + "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'scan']\n", + "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'checkhash']\n", + "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'repair']\n", + "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'restore']\n", + "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'scan']\n", + "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'shutdown']\n", + "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'startup']\n", + "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'reset']\n", + "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'nic', 'bc6c1fd1-4bda-4b98-9d5c-382b77879eee', 'enable']\n", + "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'nic', 'bc6c1fd1-4bda-4b98-9d5c-382b77879eee', 'disable']\n", + "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'scan']\n", + "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'checkhash']\n", + "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'repair']\n", + "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'restore']\n", + "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'scan']\n", + "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'shutdown']\n", + "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'startup']\n", + "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'reset']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'nic', '795ba4b5-a910-444d-b9f8-31944ea4ff17', 'enable']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'nic', '795ba4b5-a910-444d-b9f8-31944ea4ff17', 'disable']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'scan']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'checkhash']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'repair']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'restore']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'scan']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'checkhash']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'repair']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'restore']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'scan']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'checkhash']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'delete']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'repair']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'restore']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'scan']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'shutdown']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'startup']\n", + "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'reset']\n", + "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'nic', 'aa5c5909-bf8c-4dce-8664-a74e9454cc4a', 'enable']\n", + "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'nic', 'aa5c5909-bf8c-4dce-8664-a74e9454cc4a', 'disable']\n", + "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'scan']\n", + "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'checkhash']\n", + "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'repair']\n", + "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'restore']\n", + "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'scan']\n", + "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'shutdown']\n", + "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'startup']\n", + "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'reset']\n", + "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'nic', '21f32886-65e9-40a0-9483-a86e94dc0a3b', 'enable']\n", + "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'nic', '21f32886-65e9-40a0-9483-a86e94dc0a3b', 'disable']\n", + "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'scan']\n", + "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'checkhash']\n", + "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'repair']\n", + "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'restore']\n", + "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'scan']\n", + "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'shutdown']\n", + "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'startup']\n", + "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'reset']\n", + "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', 'a1287e24-97c6-4007-93ae-c6b5176f4fbe', 'enable']\n", + "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', 'a1287e24-97c6-4007-93ae-c6b5176f4fbe', 'disable']\n", + "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', '174b908b-e214-4efa-8837-d84924dad75f', 'enable']\n", + "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', '174b908b-e214-4efa-8837-d84924dad75f', 'disable']\n", + "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'scan']\n", + "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'checkhash']\n", + "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'repair']\n", + "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'restore']\n", + "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'scan']\n", + "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'shutdown']\n", + "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'startup']\n", + "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'reset']\n" ] } ], "source": [ "for a in act_tree:\n", " print(a)\n", - "simController.apply_action(\n", - " {\n", - " 'network':'', \n", - " 'node': '26e189bb-442e-4f73-ab7a-1c4dd162e986', \n", - " 'nic': 'eb6dfd45-d688-47cf-b061-5f45820a6bc7', \n", - " 'verb': 'enable', \n", - " 'options':{'...':'...'}\n", - " })\n", + "# simController.apply_action(\n", + "# {\n", + "# 'network':'', \n", + "# 'node': '26e189bb-442e-4f73-ab7a-1c4dd162e986', \n", + "# 'nic': 'eb6dfd45-d688-47cf-b061-5f45820a6bc7', \n", + "# 'verb': 'enable', \n", + "# 'options':{'...':'...'}\n", + "# })\n", "\n", - "a = {\n", - " 'target_type': 'network',\n", - " 'target_options': {\n", - " 'identifier': '',\n", - " 'target_type': '',\n", - " 'target_options': {\n", - " 'identifier': '',\n", + "# a = {\n", + "# 'target_type': 'network',\n", + "# 'target_options': {\n", + "# 'identifier': '',\n", + "# 'target_type': '',\n", + "# 'target_options': {\n", + "# 'identifier': '',\n", " \n", - " }\n", - " }\n", - "}\n", - "# ^ do something like this where the requests are k:v pairs instead, have a simple/similar approach " + "# }\n", + "# }\n", + "# }\n", + "# # ^ do something like this where the requests are k:v pairs instead, have a simple/similar approach " ] }, { diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index b2037729..cbe30c96 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -9,7 +9,7 @@ from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable from primaite import getLogger -from primaite.simulator.core import SimComponent +from primaite.simulator.core import Action, ActionManager, SimComponent from primaite.simulator.file_system.file_type import FileType, get_file_type_from_extension from primaite.simulator.system.core.sys_log import SysLog @@ -94,6 +94,17 @@ class FileSystem(SimComponent): if not self.folders: self.create_folder("root") + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + + self._folder_action_manager = ActionManager() + am.add_action("folder", Action(func=self._folder_action_manager)) + + self._file_action_manager = ActionManager() + am.add_action("file", Action(func=self._file_action_manager)) + + return am + @property def size(self) -> int: """ @@ -154,6 +165,7 @@ class FileSystem(SimComponent): self.folders[folder.uuid] = folder self._folders_by_name[folder.name] = folder self.sys_log.info(f"Created folder /{folder.name}") + self._folder_action_manager.add_action(folder.uuid, Action(func=folder._action_manager)) return folder def delete_folder(self, folder_name: str): @@ -172,6 +184,7 @@ class FileSystem(SimComponent): self.folders.pop(folder.uuid) self._folders_by_name.pop(folder.name) self.sys_log.info(f"Deleted folder /{folder.name} and its contents") + self._folder_action_manager.remove_action(folder.uuid) else: _LOGGER.debug(f"Cannot delete folder as it does not exist: {folder_name}") @@ -213,6 +226,7 @@ class FileSystem(SimComponent): ) folder.add_file(file) self.sys_log.info(f"Created file /{file.path}") + self._file_action_manager.add_action(file.uuid, Action(func=file._action_manager)) return file def get_file(self, folder_name: str, file_name: str) -> Optional[File]: @@ -240,6 +254,7 @@ class FileSystem(SimComponent): file = folder.get_file(file_name) if file: folder.remove_file(file) + self._file_action_manager.remove_action(file.uuid) self.sys_log.info(f"Deleted file /{file.path}") def move_file(self, src_folder_name: str, src_file_name: str, dst_folder_name: str): @@ -317,6 +332,16 @@ class Folder(FileSystemItemABC): is_quarantined: bool = False "Flag that marks the folder as quarantined if true." + def _init_action_manager(sekf) -> ActionManager: + am = super()._init_action_manager() + + am.add_action("scan", Action(func=lambda request, context: ...)) # TODO implement action + am.add_action("checkhash", Action(func=lambda request, context: ...)) # TODO implement action + am.add_action("repair", Action(func=lambda request, context: ...)) # TODO implement action + am.add_action("restore", Action(func=lambda request, context: ...)) # TODO implement action + + return am + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -482,6 +507,17 @@ class File(FileSystemItemABC): with open(self.sim_path, mode="a"): pass + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + + am.add_action("scan", Action(func=lambda request, context: ...)) # TODO implement action + am.add_action("checkhash", Action(func=lambda request, context: ...)) # TODO implement action + am.add_action("delete", Action(func=lambda request, context: ...)) # TODO implement action + am.add_action("repair", Action(func=lambda request, context: ...)) # TODO implement action + am.add_action("restore", Action(func=lambda request, context: ...)) # TODO implement action + + return am + def make_copy(self, dst_folder: Folder) -> File: """ Create a copy of the current File object in the given destination folder. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 24844cc3..713c293b 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -951,15 +951,23 @@ class Node(SimComponent): # since there are potentially many services, create an action manager that can map service name self._service_action_manager = ActionManager() am.add_action("service", Action(func=self._service_action_manager)) - self._process_action_manager = ActionManager() - am.add_action("process", Action(func=self._process_action_manager)) - self._application_action_manager = ActionManager() - am.add_action("application", Action(func=self._application_action_manager)) self._nic_action_manager = ActionManager() am.add_action("nic", Action(func=self._nic_action_manager)) am.add_action("file_system", Action(func=self.file_system._action_manager)) + # currently we don't have any applications nor processes, so these will be empty + self._process_action_manager = ActionManager() + am.add_action("process", Action(func=self._process_action_manager)) + self._application_action_manager = ActionManager() + am.add_action("application", Action(func=self._application_action_manager)) + + am.add_action("scan", Action(func=lambda request, context: ...)) # TODO implement OS scan + + am.add_action("shutdown", Action(func=lambda request, context: self.power_off())) + am.add_action("startup", Action(func=lambda request, context: self.power_on())) + am.add_action("reset", Action(func=lambda request, context: ...)) # TODO implement node reset + return am def describe_state(self) -> Dict: From 610517d81705a4179928278f89fa19c5faa3ab44 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 19 Sep 2023 11:28:13 +0100 Subject: [PATCH 174/980] Underscore 'parent' refs to make pydantic happy. Rename attributes like connected_link and connected_node to start with an underscore. This will prevent circular dependency and stack recursion depth error. --- .../simulator/network/hardware/base.py | 102 +++++++++--------- .../network/hardware/nodes/switch.py | 4 +- .../network/test_network_creation.py | 4 +- 3 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 713c293b..73e7b20c 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -89,9 +89,9 @@ class NIC(SimComponent): "The Maximum Transmission Unit (MTU) of the NIC in Bytes. Default is 1500 B" wake_on_lan: bool = False "Indicates if the NIC supports Wake-on-LAN functionality." - connected_node: Optional[Node] = None + _connected_node: Optional[Node] = None "The Node to which the NIC is connected." - connected_link: Optional[Link] = None + _connected_link: Optional[Link] = None "The Link to which the NIC is connected." enabled: bool = False "Indicates whether the NIC is enabled." @@ -166,21 +166,21 @@ class NIC(SimComponent): """Attempt to enable the NIC.""" if self.enabled: return - if not self.connected_node: + if not self._connected_node: _LOGGER.error(f"NIC {self} cannot be enabled as it is not connected to a Node") return - if self.connected_node.operating_state != NodeOperatingState.ON: - self.connected_node.sys_log.error(f"NIC {self} cannot be enabled as the endpoint is not turned on") + if self._connected_node.operating_state != NodeOperatingState.ON: + self._connected_node.sys_log.error(f"NIC {self} cannot be enabled as the endpoint is not turned on") return - if not self.connected_link: + if not self._connected_link: _LOGGER.error(f"NIC {self} cannot be enabled as it is not connected to a Link") return self.enabled = True - self.connected_node.sys_log.info(f"NIC {self} enabled") - self.pcap = PacketCapture(hostname=self.connected_node.hostname, ip_address=self.ip_address) - if self.connected_link: - self.connected_link.endpoint_up() + self._connected_node.sys_log.info(f"NIC {self} enabled") + self.pcap = PacketCapture(hostname=self._connected_node.hostname, ip_address=self.ip_address) + if self._connected_link: + self._connected_link.endpoint_up() def disable(self): """Disable the NIC.""" @@ -188,12 +188,12 @@ class NIC(SimComponent): return self.enabled = False - if self.connected_node: - self.connected_node.sys_log.info(f"NIC {self} disabled") + if self._connected_node: + self._connected_node.sys_log.info(f"NIC {self} disabled") else: _LOGGER.debug(f"NIC {self} disabled") - if self.connected_link: - self.connected_link.endpoint_down() + if self._connected_link: + self._connected_link.endpoint_down() def connect_link(self, link: Link): """ @@ -202,26 +202,26 @@ class NIC(SimComponent): :param link: The link to which the NIC is connected. :type link: :class:`~primaite.simulator.network.transmission.physical_layer.Link` """ - if self.connected_link: + if self._connected_link: _LOGGER.error(f"Cannot connect Link to NIC ({self.mac_address}) as it already has a connection") return - if self.connected_link == link: + if self._connected_link == link: _LOGGER.error(f"Cannot connect Link to NIC ({self.mac_address}) as it is already connected") return # TODO: Inform the Node that a link has been connected - self.connected_link = link + self._connected_link = link self.enable() _LOGGER.debug(f"NIC {self} connected to Link {link}") def disconnect_link(self): """Disconnect the NIC from the connected Link.""" - if self.connected_link.endpoint_a == self: - self.connected_link.endpoint_a = None - if self.connected_link.endpoint_b == self: - self.connected_link.endpoint_b = None - self.connected_link = None + if self._connected_link.endpoint_a == self: + self._connected_link.endpoint_a = None + if self._connected_link.endpoint_b == self: + self._connected_link.endpoint_b = None + self._connected_link = None def add_dns_server(self, ip_address: IPv4Address): """ @@ -251,7 +251,7 @@ class NIC(SimComponent): if self.enabled: frame.set_sent_timestamp() self.pcap.capture(frame) - self.connected_link.transmit_frame(sender_nic=self, frame=frame) + self._connected_link.transmit_frame(sender_nic=self, frame=frame) return True # Cannot send Frame as the NIC is not enabled return False @@ -270,7 +270,7 @@ class NIC(SimComponent): self.pcap.capture(frame) # If this destination or is broadcast if frame.ethernet.dst_mac_addr == self.mac_address or frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": - self.connected_node.receive_frame(frame=frame, from_nic=self) + self._connected_node.receive_frame(frame=frame, from_nic=self) return True return False @@ -295,9 +295,9 @@ class SwitchPort(SimComponent): "The speed of the SwitchPort in Mbps. Default is 100 Mbps." mtu: int = 1500 "The Maximum Transmission Unit (MTU) of the SwitchPort in Bytes. Default is 1500 B" - connected_node: Optional[Node] = None + _connected_node: Optional[Node] = None "The Node to which the SwitchPort is connected." - connected_link: Optional[Link] = None + _connected_link: Optional[Link] = None "The Link to which the SwitchPort is connected." enabled: bool = False "Indicates whether the SwitchPort is enabled." @@ -334,31 +334,31 @@ class SwitchPort(SimComponent): if self.enabled: return - if not self.connected_node: + if not self._connected_node: _LOGGER.error(f"SwitchPort {self} cannot be enabled as it is not connected to a Node") return - if self.connected_node.operating_state != NodeOperatingState.ON: - self.connected_node.sys_log.info(f"SwitchPort {self} cannot be enabled as the endpoint is not turned on") + if self._connected_node.operating_state != NodeOperatingState.ON: + self._connected_node.sys_log.info(f"SwitchPort {self} cannot be enabled as the endpoint is not turned on") return self.enabled = True - self.connected_node.sys_log.info(f"SwitchPort {self} enabled") - self.pcap = PacketCapture(hostname=self.connected_node.hostname, switch_port_number=self.port_num) - if self.connected_link: - self.connected_link.endpoint_up() + self._connected_node.sys_log.info(f"SwitchPort {self} enabled") + self.pcap = PacketCapture(hostname=self._connected_node.hostname, switch_port_number=self.port_num) + if self._connected_link: + self._connected_link.endpoint_up() def disable(self): """Disable the SwitchPort.""" if not self.enabled: return self.enabled = False - if self.connected_node: - self.connected_node.sys_log.info(f"SwitchPort {self} disabled") + if self._connected_node: + self._connected_node.sys_log.info(f"SwitchPort {self} disabled") else: _LOGGER.debug(f"SwitchPort {self} disabled") - if self.connected_link: - self.connected_link.endpoint_down() + if self._connected_link: + self._connected_link.endpoint_down() def connect_link(self, link: Link): """ @@ -366,26 +366,26 @@ class SwitchPort(SimComponent): :param link: The link to which the SwitchPort is connected. """ - if self.connected_link: + if self._connected_link: _LOGGER.error(f"Cannot connect link to SwitchPort {self.mac_address} as it already has a connection") return - if self.connected_link == link: + if self._connected_link == link: _LOGGER.error(f"Cannot connect Link to SwitchPort {self.mac_address} as it is already connected") return # TODO: Inform the Switch that a link has been connected - self.connected_link = link + self._connected_link = link _LOGGER.debug(f"SwitchPort {self} connected to Link {link}") self.enable() def disconnect_link(self): """Disconnect the SwitchPort from the connected Link.""" - if self.connected_link.endpoint_a == self: - self.connected_link.endpoint_a = None - if self.connected_link.endpoint_b == self: - self.connected_link.endpoint_b = None - self.connected_link = None + if self._connected_link.endpoint_a == self: + self._connected_link.endpoint_a = None + if self._connected_link.endpoint_b == self: + self._connected_link.endpoint_b = None + self._connected_link = None def send_frame(self, frame: Frame) -> bool: """ @@ -395,7 +395,7 @@ class SwitchPort(SimComponent): """ if self.enabled: self.pcap.capture(frame) - self.connected_link.transmit_frame(sender_nic=self, frame=frame) + self._connected_link.transmit_frame(sender_nic=self, frame=frame) return True # Cannot send Frame as the SwitchPort is not enabled return False @@ -411,7 +411,7 @@ class SwitchPort(SimComponent): if self.enabled: frame.decrement_ttl() self.pcap.capture(frame) - connected_node: Node = self.connected_node + connected_node: Node = self._connected_node connected_node.forward_frame(frame=frame, incoming_port=self) return True return False @@ -1037,7 +1037,7 @@ class Node(SimComponent): self.operating_state = NodeOperatingState.ON self.sys_log.info("Turned on") for nic in self.nics.values(): - if nic.connected_link: + if nic._connected_link: nic.enable() def power_off(self): @@ -1058,7 +1058,7 @@ class Node(SimComponent): if nic.uuid not in self.nics: self.nics[nic.uuid] = nic self.ethernet_port[len(self.nics)] = nic - nic.connected_node = self + nic._connected_node = self nic.parent = self self.sys_log.info(f"Connected NIC {nic}") if self.operating_state == NodeOperatingState.ON: @@ -1225,7 +1225,7 @@ class Switch(Node): if not self.switch_ports: self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)} for port_num, port in self.switch_ports.items(): - port.connected_node = self + port._connected_node = self port.parent = self port.port_num = port_num @@ -1298,7 +1298,7 @@ class Switch(Node): _LOGGER.error(msg) raise NetworkError(msg) - if port.connected_link != link: + if port._connected_link != link: msg = f"The link does not match the connection at port number {port_number}" _LOGGER.error(msg) raise NetworkError(msg) diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/switch.py index b7cc1242..ac8dabd1 100644 --- a/src/primaite/simulator/network/hardware/nodes/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/switch.py @@ -30,7 +30,7 @@ class Switch(Node): if not self.switch_ports: self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)} for port_num, port in self.switch_ports.items(): - port.connected_node = self + port._connected_node = self port.parent = self port.port_num = port_num @@ -113,7 +113,7 @@ class Switch(Node): _LOGGER.error(msg) raise NetworkError(msg) - if port.connected_link != link: + if port._connected_link != link: msg = f"The link does not match the connection at port number {port_number}" _LOGGER.error(msg) raise NetworkError(msg) diff --git a/tests/integration_tests/network/test_network_creation.py b/tests/integration_tests/network/test_network_creation.py index 356eb1db..91218068 100644 --- a/tests/integration_tests/network/test_network_creation.py +++ b/tests/integration_tests/network/test_network_creation.py @@ -70,8 +70,8 @@ def test_connecting_node_to_itself(): net.connect(node.nics[nic1.uuid], node.nics[nic2.uuid], bandwidth=30) assert node in net - assert nic1.connected_link is None - assert nic2.connected_link is None + assert nic1._connected_link is None + assert nic2._connected_link is None assert len(net.links) == 0 From aa6834ad08d7c4204daa17900712c410269a3707 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 19 Sep 2023 11:41:02 +0100 Subject: [PATCH 175/980] Check service actions work. --- src/primaite/notebooks/scratch.ipynb | 435 ++++++++++-------- .../simulator/network/hardware/base.py | 1 - src/primaite/simulator/system/software.py | 2 +- 3 files changed, 256 insertions(+), 182 deletions(-) diff --git a/src/primaite/notebooks/scratch.ipynb b/src/primaite/notebooks/scratch.ipynb index 023b7d12..f7b29fa4 100644 --- a/src/primaite/notebooks/scratch.ipynb +++ b/src/primaite/notebooks/scratch.ipynb @@ -2,18 +2,9 @@ "cells": [ { "cell_type": "code", - "execution_count": 12, + "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The autoreload extension is already loaded. To reload it, use:\n", - " %reload_ext autoreload\n" - ] - } - ], + "outputs": [], "source": [ "from primaite.simulator.network.networks import arcd_uc2_network\n", "%load_ext autoreload\n", @@ -22,30 +13,24 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2023-09-19 11:04:37,447: Added node 654e2f3e-1017-4f0a-9f77-addc1f652148 to Network f31c099e-6349-4f78-8a35-899443011640\n", - "2023-09-19 11:04:37,449: Added node 5953be77-ab77-43c0-a8bb-a72f94121358 to Network f31c099e-6349-4f78-8a35-899443011640\n", - "2023-09-19 11:04:37,453: Added node 7eeca128-bea5-4046-8b0c-c11a684f5638 to Network f31c099e-6349-4f78-8a35-899443011640\n", - "2023-09-19 11:04:37,457: Added node dc517f9b-699a-423a-8e68-40f45aece537 to Network f31c099e-6349-4f78-8a35-899443011640\n", - "2023-09-19 11:04:37,461: Added node 0b77284b-93c4-4820-91aa-46ef87d95afe to Network f31c099e-6349-4f78-8a35-899443011640\n", - "2023-09-19 11:04:37,467: Added node 5bbb11fb-d9d6-4e44-92e5-42b31a110bc7 to Network f31c099e-6349-4f78-8a35-899443011640\n", - "2023-09-19 11:04:37,469: Added node f6be7556-fdd9-4207-a588-447ccbdb1ee2 to Network f31c099e-6349-4f78-8a35-899443011640\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-09-19 11:04:37,539: Added node 51795116-f673-4c38-9524-525014565ac6 to Network f31c099e-6349-4f78-8a35-899443011640\n", - "2023-09-19 11:04:37,546: Added node 3fc6c09a-2918-4ae6-85ca-e85eeda8bd47 to Network f31c099e-6349-4f78-8a35-899443011640\n", - "2023-09-19 11:04:37,549: Added node 664bd02f-8c85-4766-8144-46944b9160cb to Network f31c099e-6349-4f78-8a35-899443011640\n", - "2023-09-19 11:04:37,552::ERROR::primaite.simulator.network.hardware.base::176::NIC fb:f1:07:56:1a:dc/192.168.10.110 cannot be enabled as it is not connected to a Link\n" + "2023-09-19 11:26:37,748: Added node 9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", + "2023-09-19 11:26:37,750: Added node e0f81131-2c42-4182-99a7-695e9016c518 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", + "2023-09-19 11:26:37,757: Added node 524ebdb4-ed76-4e8e-8cd6-babbf0d02f69 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", + "2023-09-19 11:26:37,762: Added node 1e78d3ae-8eb7-4bb7-830e-dcf7fc000625 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", + "2023-09-19 11:26:37,768: Added node fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", + "2023-09-19 11:26:37,773: Added node 40b4845a-11a7-41a7-9ab7-1fb80b1799b3 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", + "2023-09-19 11:26:37,778: Added node 119850a0-61c2-4050-afd9-709656e65c7b to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", + "2023-09-19 11:26:37,966: Added node f7c983b1-0374-4280-be8f-2eae561dbf08 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", + "2023-09-19 11:26:37,983: Added node 8479b2e0-9f97-47ea-a2e0-483ad604439f to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", + "2023-09-19 11:26:37,991: Added node a2d78848-9e70-4824-bd91-9a6915988e38 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", + "2023-09-19 11:26:37,995::ERROR::primaite.simulator.network.hardware.base::176::NIC 68:3b:a1:83:01:a1/192.168.10.110 cannot be enabled as it is not connected to a Link\n" ] } ], @@ -54,40 +39,116 @@ ] }, { - "cell_type": "code", - "execution_count": 11, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "ename": "RecursionError", - "evalue": "maximum recursion depth exceeded while calling a Python object", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mRecursionError\u001b[0m Traceback (most recent call last)", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/IPython/core/formatters.py:708\u001b[0m, in \u001b[0;36mPlainTextFormatter.__call__\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 701\u001b[0m stream \u001b[39m=\u001b[39m StringIO()\n\u001b[1;32m 702\u001b[0m printer \u001b[39m=\u001b[39m pretty\u001b[39m.\u001b[39mRepresentationPrinter(stream, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mverbose,\n\u001b[1;32m 703\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmax_width, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnewline,\n\u001b[1;32m 704\u001b[0m max_seq_length\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmax_seq_length,\n\u001b[1;32m 705\u001b[0m singleton_pprinters\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39msingleton_printers,\n\u001b[1;32m 706\u001b[0m type_pprinters\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mtype_printers,\n\u001b[1;32m 707\u001b[0m deferred_pprinters\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdeferred_printers)\n\u001b[0;32m--> 708\u001b[0m printer\u001b[39m.\u001b[39;49mpretty(obj)\n\u001b[1;32m 709\u001b[0m printer\u001b[39m.\u001b[39mflush()\n\u001b[1;32m 710\u001b[0m \u001b[39mreturn\u001b[39;00m stream\u001b[39m.\u001b[39mgetvalue()\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/IPython/lib/pretty.py:410\u001b[0m, in \u001b[0;36mRepresentationPrinter.pretty\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 407\u001b[0m \u001b[39mreturn\u001b[39;00m meth(obj, \u001b[39mself\u001b[39m, cycle)\n\u001b[1;32m 408\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mcls\u001b[39m \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mobject\u001b[39m \\\n\u001b[1;32m 409\u001b[0m \u001b[39mand\u001b[39;00m \u001b[39mcallable\u001b[39m(\u001b[39mcls\u001b[39m\u001b[39m.\u001b[39m\u001b[39m__dict__\u001b[39m\u001b[39m.\u001b[39mget(\u001b[39m'\u001b[39m\u001b[39m__repr__\u001b[39m\u001b[39m'\u001b[39m)):\n\u001b[0;32m--> 410\u001b[0m \u001b[39mreturn\u001b[39;00m _repr_pprint(obj, \u001b[39mself\u001b[39;49m, cycle)\n\u001b[1;32m 412\u001b[0m \u001b[39mreturn\u001b[39;00m _default_pprint(obj, \u001b[39mself\u001b[39m, cycle)\n\u001b[1;32m 413\u001b[0m \u001b[39mfinally\u001b[39;00m:\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/IPython/lib/pretty.py:778\u001b[0m, in \u001b[0;36m_repr_pprint\u001b[0;34m(obj, p, cycle)\u001b[0m\n\u001b[1;32m 776\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"A pprint that just redirects to the normal repr function.\"\"\"\u001b[39;00m\n\u001b[1;32m 777\u001b[0m \u001b[39m# Find newlines and replace them with p.break_()\u001b[39;00m\n\u001b[0;32m--> 778\u001b[0m output \u001b[39m=\u001b[39m \u001b[39mrepr\u001b[39;49m(obj)\n\u001b[1;32m 779\u001b[0m lines \u001b[39m=\u001b[39m output\u001b[39m.\u001b[39msplitlines()\n\u001b[1;32m 780\u001b[0m \u001b[39mwith\u001b[39;00m p\u001b[39m.\u001b[39mgroup():\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/main.py:859\u001b[0m, in \u001b[0;36mBaseModel.__repr__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 858\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr__\u001b[39m(\u001b[39mself\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m--> 859\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__repr_name__()\u001b[39m}\u001b[39;00m\u001b[39m(\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__repr_str__(\u001b[39m\"\u001b[39;49m\u001b[39m, \u001b[39;49m\u001b[39m\"\u001b[39;49m)\u001b[39m}\u001b[39;00m\u001b[39m)\u001b[39m\u001b[39m'\u001b[39m\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:55\u001b[0m, in \u001b[0;36mRepresentation.__repr_str__\u001b[0;34m(self, join_str)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_str__\u001b[39m(\u001b[39mself\u001b[39m, join_str: \u001b[39mstr\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m---> 55\u001b[0m \u001b[39mreturn\u001b[39;00m join_str\u001b[39m.\u001b[39;49mjoin(\u001b[39mrepr\u001b[39;49m(v) \u001b[39mif\u001b[39;49;00m a \u001b[39mis\u001b[39;49;00m \u001b[39mNone\u001b[39;49;00m \u001b[39melse\u001b[39;49;00m \u001b[39mf\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39m{\u001b[39;49;00ma\u001b[39m}\u001b[39;49;00m\u001b[39m=\u001b[39;49m\u001b[39m{\u001b[39;49;00mv\u001b[39m!r}\u001b[39;49;00m\u001b[39m'\u001b[39;49m \u001b[39mfor\u001b[39;49;00m a, v \u001b[39min\u001b[39;49;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__repr_args__())\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:55\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_str__\u001b[39m(\u001b[39mself\u001b[39m, join_str: \u001b[39mstr\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m---> 55\u001b[0m \u001b[39mreturn\u001b[39;00m join_str\u001b[39m.\u001b[39mjoin(\u001b[39mrepr\u001b[39m(v) \u001b[39mif\u001b[39;00m a \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39melse\u001b[39;00m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00ma\u001b[39m}\u001b[39;00m\u001b[39m=\u001b[39m\u001b[39m{\u001b[39;00mv\u001b[39m!r}\u001b[39;00m\u001b[39m'\u001b[39m \u001b[39mfor\u001b[39;00m a, v \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__repr_args__())\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/main.py:859\u001b[0m, in \u001b[0;36mBaseModel.__repr__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 858\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr__\u001b[39m(\u001b[39mself\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m--> 859\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__repr_name__()\u001b[39m}\u001b[39;00m\u001b[39m(\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__repr_str__(\u001b[39m\"\u001b[39;49m\u001b[39m, \u001b[39;49m\u001b[39m\"\u001b[39;49m)\u001b[39m}\u001b[39;00m\u001b[39m)\u001b[39m\u001b[39m'\u001b[39m\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:55\u001b[0m, in \u001b[0;36mRepresentation.__repr_str__\u001b[0;34m(self, join_str)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_str__\u001b[39m(\u001b[39mself\u001b[39m, join_str: \u001b[39mstr\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m---> 55\u001b[0m \u001b[39mreturn\u001b[39;00m join_str\u001b[39m.\u001b[39;49mjoin(\u001b[39mrepr\u001b[39;49m(v) \u001b[39mif\u001b[39;49;00m a \u001b[39mis\u001b[39;49;00m \u001b[39mNone\u001b[39;49;00m \u001b[39melse\u001b[39;49;00m \u001b[39mf\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39m{\u001b[39;49;00ma\u001b[39m}\u001b[39;49;00m\u001b[39m=\u001b[39;49m\u001b[39m{\u001b[39;49;00mv\u001b[39m!r}\u001b[39;49;00m\u001b[39m'\u001b[39;49m \u001b[39mfor\u001b[39;49;00m a, v \u001b[39min\u001b[39;49;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__repr_args__())\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:55\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_str__\u001b[39m(\u001b[39mself\u001b[39m, join_str: \u001b[39mstr\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m---> 55\u001b[0m \u001b[39mreturn\u001b[39;00m join_str\u001b[39m.\u001b[39mjoin(\u001b[39mrepr\u001b[39m(v) \u001b[39mif\u001b[39;00m a \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39melse\u001b[39;00m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00ma\u001b[39m}\u001b[39;00m\u001b[39m=\u001b[39m\u001b[39m{\u001b[39;00mv\u001b[39m!r}\u001b[39;00m\u001b[39m'\u001b[39m \u001b[39mfor\u001b[39;00m a, v \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__repr_args__())\n", - " \u001b[0;31m[... skipping similar frames: BaseModel.__repr__ at line 859 (589 times), at line 55 (588 times), Representation.__repr_str__ at line 55 (588 times)]\u001b[0m\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:55\u001b[0m, in \u001b[0;36mRepresentation.__repr_str__\u001b[0;34m(self, join_str)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_str__\u001b[39m(\u001b[39mself\u001b[39m, join_str: \u001b[39mstr\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m---> 55\u001b[0m \u001b[39mreturn\u001b[39;00m join_str\u001b[39m.\u001b[39;49mjoin(\u001b[39mrepr\u001b[39;49m(v) \u001b[39mif\u001b[39;49;00m a \u001b[39mis\u001b[39;49;00m \u001b[39mNone\u001b[39;49;00m \u001b[39melse\u001b[39;49;00m \u001b[39mf\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39m{\u001b[39;49;00ma\u001b[39m}\u001b[39;49;00m\u001b[39m=\u001b[39;49m\u001b[39m{\u001b[39;49;00mv\u001b[39m!r}\u001b[39;49;00m\u001b[39m'\u001b[39;49m \u001b[39mfor\u001b[39;49;00m a, v \u001b[39min\u001b[39;49;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__repr_args__())\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:55\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_str__\u001b[39m(\u001b[39mself\u001b[39m, join_str: \u001b[39mstr\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m---> 55\u001b[0m \u001b[39mreturn\u001b[39;00m join_str\u001b[39m.\u001b[39mjoin(\u001b[39mrepr\u001b[39m(v) \u001b[39mif\u001b[39;00m a \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39melse\u001b[39;00m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00ma\u001b[39m}\u001b[39;00m\u001b[39m=\u001b[39m\u001b[39m{\u001b[39;00mv\u001b[39m!r}\u001b[39;00m\u001b[39m'\u001b[39m \u001b[39mfor\u001b[39;00m a, v \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__repr_args__())\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/main.py:859\u001b[0m, in \u001b[0;36mBaseModel.__repr__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 858\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr__\u001b[39m(\u001b[39mself\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[0;32m--> 859\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__repr_name__()\u001b[39m}\u001b[39;00m\u001b[39m(\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__repr_str__(\u001b[39m\"\u001b[39m\u001b[39m, \u001b[39m\u001b[39m\"\u001b[39m)\u001b[39m}\u001b[39;00m\u001b[39m)\u001b[39m\u001b[39m'\u001b[39m\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.py:52\u001b[0m, in \u001b[0;36mRepresentation.__repr_name__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__repr_name__\u001b[39m(\u001b[39mself\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[1;32m 51\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"Name of the instance's class, used in __repr__.\"\"\"\u001b[39;00m\n\u001b[0;32m---> 52\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m\u001b[39m__class__\u001b[39;49m\u001b[39m.\u001b[39;49m\u001b[39m__name__\u001b[39;49m\n", - "\u001b[0;31mRecursionError\u001b[0m: maximum recursion depth exceeded while calling a Python object" - ] - } - ], - "source": [] + "source": [ + "### set up some services to test if actions are working" + ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "db_serv = net.get_node_by_hostname('database_server')" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.simulator.system.services.database_service import DatabaseService" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "db_svc = DatabaseService(file_system=db_serv.file_system)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-09-19 11:35:45,008: Added service d2090e0c-1080-4a4e-98af-489f2c7b5370 to node 119850a0-61c2-4050-afd9-709656e65c7b\n" + ] + } + ], + "source": [ + "db_serv.install_service(db_svc)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'uuid': '119850a0-61c2-4050-afd9-709656e65c7b',\n", + " 'hostname': 'database_server',\n", + " 'operating_state': 1,\n", + " 'NICs': {'89cbde58-4726-4a8b-8de0-fb5bdcdf615b': {'uuid': '89cbde58-4726-4a8b-8de0-fb5bdcdf615b',\n", + " 'ip_adress': '192.168.1.14',\n", + " 'subnet_mask': '255.255.255.0',\n", + " 'mac_address': '51:46:0d:52:99:9d',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'wake_on_lan': False,\n", + " 'enabled': True}},\n", + " 'file_system': {'uuid': 'af425e71-5437-4de4-b1f2-e7c36d9cff06',\n", + " 'folders': {'root': {'uuid': 'e75401ee-e311-4519-8d63-f1c04376fb18',\n", + " 'name': 'root',\n", + " 'files': {},\n", + " 'is_quarantined': False},\n", + " 'database': {'uuid': '6ff67dbf-69ee-465e-935b-3c557c716702',\n", + " 'name': 'database',\n", + " 'files': {'database.db': {'uuid': '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4',\n", + " 'name': 'database.db',\n", + " 'size': 12288,\n", + " 'file_type': 'DB'}},\n", + " 'is_quarantined': False}}},\n", + " 'applications': {},\n", + " 'services': {'d2090e0c-1080-4a4e-98af-489f2c7b5370': {'uuid': 'd2090e0c-1080-4a4e-98af-489f2c7b5370',\n", + " 'health_state': 'GOOD',\n", + " 'health_state_red_view': 'GOOD',\n", + " 'criticality': 'LOWEST',\n", + " 'patching_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 1,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 5432,\n", + " 'operating_state': 'STOPPED'}},\n", + " 'process': {}}" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "db_serv.describe_state()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -96,16 +157,16 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "115" + "129" ] }, - "execution_count": 4, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -116,14 +177,14 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '9f5dfd4a-2727-466d-b7ab-6d4f18e0ce2b', 'enable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '9f5dfd4a-2727-466d-b7ab-6d4f18e0ce2b', 'disable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '7ba299f5-1d94-4f9d-a286-8fe3b903a581', 'enable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '7ba299f5-1d94-4f9d-a286-8fe3b903a581', 'disable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '022a1240-844d-4099-930d-052e0452472e', 'enable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '022a1240-844d-4099-930d-052e0452472e', 'disable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '829ff3c6-7e0b-4d28-93bf-b6dc2abd8e2a', 'enable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '829ff3c6-7e0b-4d28-93bf-b6dc2abd8e2a', 'disable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', 'ea185a03-8b34-4347-b0d7-ca2ed61303b4', 'enable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', 'ea185a03-8b34-4347-b0d7-ca2ed61303b4', 'disable'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'scan'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'checkhash'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'repair'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'restore'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'scan'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'shutdown'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'startup'], ['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'reset'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'scan'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'checkhash'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'repair'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'restore'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'scan'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'shutdown'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'startup'], ['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'reset'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'scan'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'checkhash'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'repair'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'restore'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'scan'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'shutdown'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'startup'], ['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'reset'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'nic', 'b9b3406a-3a46-4ce7-99d2-6eef00c01b17', 'enable'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'nic', 'b9b3406a-3a46-4ce7-99d2-6eef00c01b17', 'disable'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'scan'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'checkhash'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'repair'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'restore'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'scan'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'shutdown'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'startup'], ['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'reset'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'nic', '428b04e5-03e5-4046-8b4e-6ecf9dc25ff7', 'enable'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'nic', '428b04e5-03e5-4046-8b4e-6ecf9dc25ff7', 'disable'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'scan'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'checkhash'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'repair'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'restore'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'scan'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'shutdown'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'startup'], ['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'reset'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'nic', 'bc6c1fd1-4bda-4b98-9d5c-382b77879eee', 'enable'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'nic', 'bc6c1fd1-4bda-4b98-9d5c-382b77879eee', 'disable'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'scan'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'checkhash'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'repair'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'restore'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'scan'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'shutdown'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'startup'], ['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'reset'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'nic', '795ba4b5-a910-444d-b9f8-31944ea4ff17', 'enable'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'nic', '795ba4b5-a910-444d-b9f8-31944ea4ff17', 'disable'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'scan'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'checkhash'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'repair'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'restore'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'scan'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'checkhash'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'repair'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'restore'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'scan'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'checkhash'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'delete'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'repair'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'restore'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'scan'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'shutdown'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'startup'], ['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'reset'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'nic', 'aa5c5909-bf8c-4dce-8664-a74e9454cc4a', 'enable'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'nic', 'aa5c5909-bf8c-4dce-8664-a74e9454cc4a', 'disable'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'scan'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'checkhash'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'repair'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'restore'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'scan'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'shutdown'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'startup'], ['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'reset'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'nic', '21f32886-65e9-40a0-9483-a86e94dc0a3b', 'enable'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'nic', '21f32886-65e9-40a0-9483-a86e94dc0a3b', 'disable'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'scan'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'checkhash'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'repair'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'restore'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'scan'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'shutdown'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'startup'], ['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'reset'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', 'a1287e24-97c6-4007-93ae-c6b5176f4fbe', 'enable'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', 'a1287e24-97c6-4007-93ae-c6b5176f4fbe', 'disable'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', '174b908b-e214-4efa-8837-d84924dad75f', 'enable'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', '174b908b-e214-4efa-8837-d84924dad75f', 'disable'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'scan'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'checkhash'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'repair'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'restore'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'scan'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'shutdown'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'startup'], ['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'reset']]\n" + "[['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '1b9ef60a-371c-43b9-af56-d0ddb220189e', 'enable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '1b9ef60a-371c-43b9-af56-d0ddb220189e', 'disable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '41e2ffb4-3d19-4824-a665-6f6fa68afcd1', 'enable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '41e2ffb4-3d19-4824-a665-6f6fa68afcd1', 'disable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', 'c61a3021-876b-491b-a3af-4e8955f26fc4', 'enable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', 'c61a3021-876b-491b-a3af-4e8955f26fc4', 'disable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '217f5929-bb4c-4e4d-b564-efd805be5733', 'enable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '217f5929-bb4c-4e4d-b564-efd805be5733', 'disable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '29708cc6-008e-4db1-b50f-cf4f9246c3e2', 'enable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '29708cc6-008e-4db1-b50f-cf4f9246c3e2', 'disable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'scan'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'checkhash'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'repair'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'restore'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'scan'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'shutdown'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'startup'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'reset'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'scan'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'checkhash'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'repair'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'restore'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'scan'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'shutdown'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'startup'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'reset'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'scan'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'checkhash'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'repair'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'restore'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'scan'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'shutdown'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'startup'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'reset'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'nic', '27a09b26-0912-4de1-8fac-afefd06668a7', 'enable'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'nic', '27a09b26-0912-4de1-8fac-afefd06668a7', 'disable'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'scan'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'checkhash'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'repair'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'restore'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'scan'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'shutdown'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'startup'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'reset'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'nic', '34050ee7-c5a0-42c3-9be3-f55d6668443d', 'enable'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'nic', '34050ee7-c5a0-42c3-9be3-f55d6668443d', 'disable'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'scan'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'checkhash'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'repair'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'restore'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'scan'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'shutdown'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'startup'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'reset'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'nic', 'd0748224-7123-48a7-a0ab-1775ad3390e2', 'enable'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'nic', 'd0748224-7123-48a7-a0ab-1775ad3390e2', 'disable'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'scan'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'checkhash'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'repair'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'restore'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'scan'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'shutdown'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'startup'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'reset'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'compromise'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'scan'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'stop'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'start'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'pause'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'resume'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'restart'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'disable'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'enable'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'nic', '89cbde58-4726-4a8b-8de0-fb5bdcdf615b', 'enable'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'nic', '89cbde58-4726-4a8b-8de0-fb5bdcdf615b', 'disable'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'scan'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'checkhash'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'repair'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'restore'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'scan'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'checkhash'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'repair'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'restore'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'scan'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'checkhash'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'delete'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'repair'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'restore'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'scan'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'checkhash'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'delete'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'repair'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'restore'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'scan'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'shutdown'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'startup'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'reset'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'nic', 'c6b8769b-c411-497c-a2e6-b4b46d805d8a', 'enable'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'nic', 'c6b8769b-c411-497c-a2e6-b4b46d805d8a', 'disable'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'scan'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'checkhash'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'repair'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'restore'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'scan'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'shutdown'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'startup'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'reset'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'nic', 'e72aa295-6132-424c-8892-75f4c9999c8e', 'enable'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'nic', 'e72aa295-6132-424c-8892-75f4c9999c8e', 'disable'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'scan'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'checkhash'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'repair'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'restore'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'scan'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'shutdown'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'startup'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'reset'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', '2f3f3ba3-4722-4fe7-9a60-96d55f737c77', 'enable'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', '2f3f3ba3-4722-4fe7-9a60-96d55f737c77', 'disable'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', 'a4e26b3a-981c-4d77-8f39-dcfc88639da7', 'enable'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', 'a4e26b3a-981c-4d77-8f39-dcfc88639da7', 'disable'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'scan'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'checkhash'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'repair'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'restore'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'scan'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'shutdown'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'startup'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'reset']]\n" ] } ], @@ -133,128 +194,142 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '9f5dfd4a-2727-466d-b7ab-6d4f18e0ce2b', 'enable']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '9f5dfd4a-2727-466d-b7ab-6d4f18e0ce2b', 'disable']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '7ba299f5-1d94-4f9d-a286-8fe3b903a581', 'enable']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '7ba299f5-1d94-4f9d-a286-8fe3b903a581', 'disable']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '022a1240-844d-4099-930d-052e0452472e', 'enable']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '022a1240-844d-4099-930d-052e0452472e', 'disable']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '829ff3c6-7e0b-4d28-93bf-b6dc2abd8e2a', 'enable']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', '829ff3c6-7e0b-4d28-93bf-b6dc2abd8e2a', 'disable']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', 'ea185a03-8b34-4347-b0d7-ca2ed61303b4', 'enable']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'nic', 'ea185a03-8b34-4347-b0d7-ca2ed61303b4', 'disable']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'scan']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'checkhash']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'repair']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'file_system', 'folder', '2615763e-d91b-46a5-982b-a21a18d7e02c', 'restore']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'scan']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'shutdown']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'startup']\n", - "['node', '72a46527-b4c6-4a51-a935-06b9a97c51da', 'reset']\n", - "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'scan']\n", - "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'checkhash']\n", - "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'repair']\n", - "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'file_system', 'folder', '7afde692-db6f-4ca7-a806-629daf0d8098', 'restore']\n", - "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'scan']\n", - "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'shutdown']\n", - "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'startup']\n", - "['node', '8efa0ed9-bbe8-4d8a-985a-6e8f281f4527', 'reset']\n", - "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'scan']\n", - "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'checkhash']\n", - "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'repair']\n", - "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'file_system', 'folder', '75cc4623-27c3-49c8-9ce3-220bbaf7e56a', 'restore']\n", - "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'scan']\n", - "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'shutdown']\n", - "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'startup']\n", - "['node', 'f80d3953-2165-48c9-935a-5ce65549f0fd', 'reset']\n", - "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'nic', 'b9b3406a-3a46-4ce7-99d2-6eef00c01b17', 'enable']\n", - "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'nic', 'b9b3406a-3a46-4ce7-99d2-6eef00c01b17', 'disable']\n", - "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'scan']\n", - "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'checkhash']\n", - "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'repair']\n", - "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'file_system', 'folder', '8703d164-fee6-4014-8472-268066bface1', 'restore']\n", - "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'scan']\n", - "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'shutdown']\n", - "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'startup']\n", - "['node', '7d8f5581-f87b-4623-b9e9-87e0a335c5ca', 'reset']\n", - "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'nic', '428b04e5-03e5-4046-8b4e-6ecf9dc25ff7', 'enable']\n", - "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'nic', '428b04e5-03e5-4046-8b4e-6ecf9dc25ff7', 'disable']\n", - "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'scan']\n", - "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'checkhash']\n", - "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'repair']\n", - "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'file_system', 'folder', 'e3296695-9096-4e92-8dcf-fdbc77956983', 'restore']\n", - "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'scan']\n", - "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'shutdown']\n", - "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'startup']\n", - "['node', '520615e4-0e98-4aef-becf-5be9c22a02e8', 'reset']\n", - "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'nic', 'bc6c1fd1-4bda-4b98-9d5c-382b77879eee', 'enable']\n", - "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'nic', 'bc6c1fd1-4bda-4b98-9d5c-382b77879eee', 'disable']\n", - "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'scan']\n", - "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'checkhash']\n", - "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'repair']\n", - "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'file_system', 'folder', 'b7958051-da38-4a00-a4f2-8596fee9904d', 'restore']\n", - "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'scan']\n", - "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'shutdown']\n", - "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'startup']\n", - "['node', '36f21fb5-9c5f-4b03-8797-a925b4a4edb0', 'reset']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'nic', '795ba4b5-a910-444d-b9f8-31944ea4ff17', 'enable']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'nic', '795ba4b5-a910-444d-b9f8-31944ea4ff17', 'disable']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'scan']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'checkhash']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'repair']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', '70edd316-e521-4b09-9b9e-362558422439', 'restore']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'scan']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'checkhash']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'repair']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'folder', 'ee3d96b6-20b3-41d0-bbb1-70e7a7add2c0', 'restore']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'scan']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'checkhash']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'delete']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'repair']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'file_system', 'file', 'deaeb707-de1b-4040-9462-f59941c5afd3', 'restore']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'scan']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'shutdown']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'startup']\n", - "['node', '0b14139f-d0d8-4656-b9de-587c53357d4c', 'reset']\n", - "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'nic', 'aa5c5909-bf8c-4dce-8664-a74e9454cc4a', 'enable']\n", - "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'nic', 'aa5c5909-bf8c-4dce-8664-a74e9454cc4a', 'disable']\n", - "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'scan']\n", - "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'checkhash']\n", - "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'repair']\n", - "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'file_system', 'folder', '4b2f461c-ef93-4910-acc4-006d518c0d6e', 'restore']\n", - "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'scan']\n", - "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'shutdown']\n", - "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'startup']\n", - "['node', '6c5cdd15-fdf8-4695-8462-8b8704ef616b', 'reset']\n", - "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'nic', '21f32886-65e9-40a0-9483-a86e94dc0a3b', 'enable']\n", - "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'nic', '21f32886-65e9-40a0-9483-a86e94dc0a3b', 'disable']\n", - "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'scan']\n", - "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'checkhash']\n", - "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'repair']\n", - "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'file_system', 'folder', '9580a6b2-eeff-400a-948e-e8f3694dada0', 'restore']\n", - "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'scan']\n", - "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'shutdown']\n", - "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'startup']\n", - "['node', 'f8e4eebc-30b7-4d54-bbef-959e456a7649', 'reset']\n", - "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', 'a1287e24-97c6-4007-93ae-c6b5176f4fbe', 'enable']\n", - "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', 'a1287e24-97c6-4007-93ae-c6b5176f4fbe', 'disable']\n", - "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', '174b908b-e214-4efa-8837-d84924dad75f', 'enable']\n", - "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'nic', '174b908b-e214-4efa-8837-d84924dad75f', 'disable']\n", - "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'scan']\n", - "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'checkhash']\n", - "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'repair']\n", - "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'file_system', 'folder', '23d89e95-f6af-428d-809b-68c43c0d098a', 'restore']\n", - "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'scan']\n", - "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'shutdown']\n", - "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'startup']\n", - "['node', '87190295-f369-49f4-ae7e-b5aced13bdf1', 'reset']\n" + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '1b9ef60a-371c-43b9-af56-d0ddb220189e', 'enable']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '1b9ef60a-371c-43b9-af56-d0ddb220189e', 'disable']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '41e2ffb4-3d19-4824-a665-6f6fa68afcd1', 'enable']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '41e2ffb4-3d19-4824-a665-6f6fa68afcd1', 'disable']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', 'c61a3021-876b-491b-a3af-4e8955f26fc4', 'enable']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', 'c61a3021-876b-491b-a3af-4e8955f26fc4', 'disable']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '217f5929-bb4c-4e4d-b564-efd805be5733', 'enable']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '217f5929-bb4c-4e4d-b564-efd805be5733', 'disable']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '29708cc6-008e-4db1-b50f-cf4f9246c3e2', 'enable']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '29708cc6-008e-4db1-b50f-cf4f9246c3e2', 'disable']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'scan']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'checkhash']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'repair']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'restore']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'scan']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'shutdown']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'startup']\n", + "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'reset']\n", + "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'scan']\n", + "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'checkhash']\n", + "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'repair']\n", + "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'restore']\n", + "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'scan']\n", + "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'shutdown']\n", + "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'startup']\n", + "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'reset']\n", + "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'scan']\n", + "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'checkhash']\n", + "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'repair']\n", + "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'restore']\n", + "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'scan']\n", + "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'shutdown']\n", + "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'startup']\n", + "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'reset']\n", + "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'nic', '27a09b26-0912-4de1-8fac-afefd06668a7', 'enable']\n", + "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'nic', '27a09b26-0912-4de1-8fac-afefd06668a7', 'disable']\n", + "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'scan']\n", + "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'checkhash']\n", + "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'repair']\n", + "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'restore']\n", + "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'scan']\n", + "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'shutdown']\n", + "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'startup']\n", + "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'reset']\n", + "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'nic', '34050ee7-c5a0-42c3-9be3-f55d6668443d', 'enable']\n", + "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'nic', '34050ee7-c5a0-42c3-9be3-f55d6668443d', 'disable']\n", + "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'scan']\n", + "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'checkhash']\n", + "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'repair']\n", + "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'restore']\n", + "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'scan']\n", + "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'shutdown']\n", + "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'startup']\n", + "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'reset']\n", + "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'nic', 'd0748224-7123-48a7-a0ab-1775ad3390e2', 'enable']\n", + "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'nic', 'd0748224-7123-48a7-a0ab-1775ad3390e2', 'disable']\n", + "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'scan']\n", + "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'checkhash']\n", + "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'repair']\n", + "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'restore']\n", + "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'scan']\n", + "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'shutdown']\n", + "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'startup']\n", + "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'reset']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'compromise']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'scan']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'stop']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'start']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'pause']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'resume']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'restart']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'disable']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'enable']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'nic', '89cbde58-4726-4a8b-8de0-fb5bdcdf615b', 'enable']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'nic', '89cbde58-4726-4a8b-8de0-fb5bdcdf615b', 'disable']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'scan']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'checkhash']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'repair']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'restore']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'scan']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'checkhash']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'repair']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'restore']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'scan']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'checkhash']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'delete']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'repair']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'restore']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'scan']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'checkhash']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'delete']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'repair']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'restore']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'scan']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'shutdown']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'startup']\n", + "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'reset']\n", + "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'nic', 'c6b8769b-c411-497c-a2e6-b4b46d805d8a', 'enable']\n", + "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'nic', 'c6b8769b-c411-497c-a2e6-b4b46d805d8a', 'disable']\n", + "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'scan']\n", + "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'checkhash']\n", + "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'repair']\n", + "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'restore']\n", + "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'scan']\n", + "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'shutdown']\n", + "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'startup']\n", + "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'reset']\n", + "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'nic', 'e72aa295-6132-424c-8892-75f4c9999c8e', 'enable']\n", + "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'nic', 'e72aa295-6132-424c-8892-75f4c9999c8e', 'disable']\n", + "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'scan']\n", + "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'checkhash']\n", + "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'repair']\n", + "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'restore']\n", + "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'scan']\n", + "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'shutdown']\n", + "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'startup']\n", + "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'reset']\n", + "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', '2f3f3ba3-4722-4fe7-9a60-96d55f737c77', 'enable']\n", + "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', '2f3f3ba3-4722-4fe7-9a60-96d55f737c77', 'disable']\n", + "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', 'a4e26b3a-981c-4d77-8f39-dcfc88639da7', 'enable']\n", + "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', 'a4e26b3a-981c-4d77-8f39-dcfc88639da7', 'disable']\n", + "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'scan']\n", + "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'checkhash']\n", + "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'repair']\n", + "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'restore']\n", + "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'scan']\n", + "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'shutdown']\n", + "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'startup']\n", + "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'reset']\n" ] } ], diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 73e7b20c..c346ddf5 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -139,7 +139,6 @@ class NIC(SimComponent): "speed": self.speed, "mtu": self.mtu, "wake_on_lan": self.wake_on_lan, - "dns_servers": self.dns_servers, "enabled": self.enabled, } ) diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 70c1bbf2..a112eccf 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -204,7 +204,7 @@ class IOSoftware(Software): "max_sessions": self.max_sessions, "tcp": self.tcp, "udp": self.udp, - "ports": [port.name for port in self.ports], # TODO: not sure if this should be port.name or port.value + "port": self.port.value, } ) return state From 898123cb10b80020622e39085d0f084df38a571f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 19 Sep 2023 11:46:02 +0100 Subject: [PATCH 176/980] Stub out more actions --- src/primaite/simulator/file_system/file_system.py | 3 +++ src/primaite/simulator/network/hardware/base.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index cbe30c96..91e98b35 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -339,6 +339,8 @@ class Folder(FileSystemItemABC): am.add_action("checkhash", Action(func=lambda request, context: ...)) # TODO implement action am.add_action("repair", Action(func=lambda request, context: ...)) # TODO implement action am.add_action("restore", Action(func=lambda request, context: ...)) # TODO implement action + am.add_action("delete", Action(func=lambda request, context: ...)) # TODO implement action + am.add_action("corrupt", Action(func=lambda request, context: ...)) # TODO implement action return am @@ -515,6 +517,7 @@ class File(FileSystemItemABC): am.add_action("delete", Action(func=lambda request, context: ...)) # TODO implement action am.add_action("repair", Action(func=lambda request, context: ...)) # TODO implement action am.add_action("restore", Action(func=lambda request, context: ...)) # TODO implement action + am.add_action("corrupt", Action(func=lambda request, context: ...)) # TODO implement action return am diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index c346ddf5..a14d6a6d 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -966,6 +966,8 @@ class Node(SimComponent): am.add_action("shutdown", Action(func=lambda request, context: self.power_off())) am.add_action("startup", Action(func=lambda request, context: self.power_on())) am.add_action("reset", Action(func=lambda request, context: ...)) # TODO implement node reset + am.add_action("logon", Action(func=lambda request, context: ...)) # TODO implement logon action + am.add_action("logoff", Action(func=lambda request, context: ...)) # TODO implement logoff action return am From 3ee5e22b24ee4bd65160815f70c8875d9bc83bde Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 19 Sep 2023 12:48:55 +0100 Subject: [PATCH 177/980] Add router action --- .../network/hardware/nodes/router.py | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 092680a7..53b9b176 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -7,7 +7,7 @@ from typing import Dict, List, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable -from primaite.simulator.core import SimComponent +from primaite.simulator.core import Action, ActionManager, SimComponent from primaite.simulator.network.hardware.base import ARPCache, ICMP, NIC, Node from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol @@ -87,6 +87,36 @@ class AccessControlList(SimComponent): super().__init__(**kwargs) self._acl = [None] * (self.max_acl_rules - 1) + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + + # When the request reaches this action, it should now contain solely positional args for the 'add_rule' action. + # POSITIONAL ARGUMENTS: + # 0: action (str name of an ACLAction) + # 1: protocol (str name of an IPProtocol) + # 2: source ip address (str castable to IPV4Address (e.g. '10.10.1.2')) + # 3: source port (str name of a Port (e.g. "HTTP")) # should we be using value, such as 80 or 443? + # 4: destination ip address (str castable to IPV4Address (e.g. '10.10.1.2')) + # 5: destination port (str name of a Port (e.g. "HTTP")) + # 6: position (int) + am.add_action( + "add_rule", + Action( + func=lambda request, context: self.add_rule( + ACLAction[request[0]], + IPProtocol[request[1]], + IPv4Address[request[2]], + Port[request[3]], + IPv4Address[request[4]], + Port[request[5]], + int(request[6]), + ) + ), + ) + + am.add_action("remove_rule", Action(func=lambda request, context: self.remove_rule(int(request[0])))) + return am + def describe_state(self) -> Dict: """ Describes the current state of the AccessControlList. @@ -596,6 +626,11 @@ class Router(Node): self.arp.nics = self.nics self.icmp.arp = self.arp + def _init_action_manager(self) -> ActionManager: + am = super()._init_action_manager() + am.add_action("acl", Action(func=self.acl._action_manager)) + return am + def _get_port_of_nic(self, target_nic: NIC) -> Optional[int]: """ Retrieve the port number for a given NIC. From d523ccc3cb61b21086bcd1b31b4d5ac3517fc8c6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 19 Sep 2023 14:23:14 +0100 Subject: [PATCH 178/980] Improve docs on action system --- docs/source/action_system.rst | 82 ++++++ docs/source/simulation.rst | 1 + src/primaite/notebooks/scratch.ipynb | 370 +++++++++++++++------------ 3 files changed, 291 insertions(+), 162 deletions(-) create mode 100644 docs/source/action_system.rst diff --git a/docs/source/action_system.rst b/docs/source/action_system.rst new file mode 100644 index 00000000..e79ef348 --- /dev/null +++ b/docs/source/action_system.rst @@ -0,0 +1,82 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +Actions System +============== + +`SimComponent`s in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use `ActionManager` and `Action`. + +Just like other aspects of SimComponent, the actions are not managed centrally for the whole simulation, but instead they are dynamically created and updated based on the nodes, links, and other components that currently exist. This was achieved with the following design decisions: + +- API + An 'action' contains two elements: + 1. `request` - selects which action you want to take on this `SimComponent`. This is formatted as a list of strings such as `['network', 'node', '', 'service', '', 'restart']`. + 2. `context` - optional extra information that can be used to decide how to process the action. This is formatted as a dictionary. For example, if the action requires authentication, the context can include information about the user that initiated the request to decide if their permissions are sufficient. + +- request + The request is a list of strings which help specify who should handle the request. The strings in the request list help ActionManagers traverse the 'ownership tree' of SimComponent. The example given above would be handled in the following way: + 1. `Simulation` receives `['network', 'node', '', 'service', '', 'restart']`. + The first element of the action is `network`, therefore it passes the action down to its network. + 2. `Network` receives `['node', '', 'service', '', 'restart']`. + The first element of the action is `node`, therefore the network looks at the node uuid and passes the action down to the node with that uuid. + 3. `Node` receives `['service', '', 'restart']`. + The first element of the action is `service`, therefore the node looks at the service uuid and passes the rest of the action to the service with that uuid. + 4. `Service` receives `['restart']`. + Since `restart` is a defined action in the service's own ActionManager, the service performs a restart. + +Techincal Detail +================ + +This system was achieved by implementing two classes, :py:class:`primaite.simulator.core.Action`, and :py:class:`primaite.simulator.core.ActionManager`. + +Action +------ + +The `Action` object stores a reference to a method that performs the action, for example a node could have an action that stores a reference to `self.turn_on()`. Techincally, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using `lambda` functions within a component's `self._init_action_manager()` method. Optionally, the `Action` object can also hold a validator that will permit/deny the action depending on context. + +ActionManager +------------- + +The `ActionManager` object stores a mapping between strings and actions. It is responsible for processing the `request` and passing it down the ownership tree. Techincally, the `ActionManager` is itself a callable that accepts `request, context` tuple, and so it can be chained with other action managers. + +A simple example without chaining can be seen in the :py:class:`primaite.simulator.file_system.file_system.File` class. + +.. code-block:: python + + class File(FileSystemItemABC): + ... + def _init_action_manager(self): + ... + action_manager.add_action("scan", Action(func=lambda request, context: self.scan())) + action_manager.add_action("repair", Action(func=lambda request, context: self.repair())) + action_manager.add_action("restore", Action(func=lambda request, context: self.restore())) + +*ellipses (`...`) used to omit code impertinent to this explanation* + +Chaining ActionManagers +----------------------- + +Since the method for performing an action needs to accept `request, context` as parameters, and ActionManager itself is a callable that accepts `request, context` as parameters, it possible to use ActionManager as an action. In fact, that is how PrimAITE deals with traversing the ownership tree. Each time an ActionManager accepts a request, it pops the first elements and uses it to decide to which Action it should send the remaining request. However, the Action could have another ActionManager as it's function, therefore the request will be routed again. Each time the request is passed to a new action manager, the first element is popped. + +An example of how this works is in the :py:class:`primaite.simulator.network.hardware.base.Node` class. + +.. code-block:: python + + class Node(SimComponent): + ... + def _init_action_manager(self): + ... + # a regular action which is processed by the Node itself + action_manager.add_action("turn_on", Action(func=lambda request, context: self.turn_on())) + + # if the Node receives a request where the first word is 'service', it will use a dummy manager called self._service_action_manager to pass on the reqeust to the relevant service. This dummy manager is simply here to map the service UUID that that service's own action manager. This is done because the next string after "service" is always the uuid of that service, so we need an actionmanager to pop that string before sending it onto the relevant service's ActionManager. + self._service_action_manager = ActionManager() + action_manager.add_action("service", Action(func=self._service_action_manager)) + ... + + def install_service(self, service): + self.services[service.uuid] = service + ... + # Here, the service UUID is registered to allow passing actions between the node and the service. + self._service_action_manager.add_action(service.uuid, Action(func=service._action_manager)) diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index e5c0d2c8..8671a2d2 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -23,3 +23,4 @@ Contents simulation_components/network/network simulation_components/system/internal_frame_processing simulation_components/system/software + action_system diff --git a/src/primaite/notebooks/scratch.ipynb b/src/primaite/notebooks/scratch.ipynb index f7b29fa4..1b94c5e4 100644 --- a/src/primaite/notebooks/scratch.ipynb +++ b/src/primaite/notebooks/scratch.ipynb @@ -20,17 +20,17 @@ "name": "stderr", "output_type": "stream", "text": [ - "2023-09-19 11:26:37,748: Added node 9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", - "2023-09-19 11:26:37,750: Added node e0f81131-2c42-4182-99a7-695e9016c518 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", - "2023-09-19 11:26:37,757: Added node 524ebdb4-ed76-4e8e-8cd6-babbf0d02f69 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", - "2023-09-19 11:26:37,762: Added node 1e78d3ae-8eb7-4bb7-830e-dcf7fc000625 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", - "2023-09-19 11:26:37,768: Added node fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", - "2023-09-19 11:26:37,773: Added node 40b4845a-11a7-41a7-9ab7-1fb80b1799b3 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", - "2023-09-19 11:26:37,778: Added node 119850a0-61c2-4050-afd9-709656e65c7b to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", - "2023-09-19 11:26:37,966: Added node f7c983b1-0374-4280-be8f-2eae561dbf08 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", - "2023-09-19 11:26:37,983: Added node 8479b2e0-9f97-47ea-a2e0-483ad604439f to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", - "2023-09-19 11:26:37,991: Added node a2d78848-9e70-4824-bd91-9a6915988e38 to Network f9af7826-619c-4d9c-949c-ec2f4815cb46\n", - "2023-09-19 11:26:37,995::ERROR::primaite.simulator.network.hardware.base::176::NIC 68:3b:a1:83:01:a1/192.168.10.110 cannot be enabled as it is not connected to a Link\n" + "2023-09-19 12:47:23,225: Added node d3242ce1-43b7-40b7-86f3-f0473f1bbaec to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", + "2023-09-19 12:47:23,227: Added node 67a2f88b-448c-416d-9fbd-02629347aabd to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", + "2023-09-19 12:47:23,232: Added node 8d69c19e-69ad-41bd-9525-bdefb680a9e2 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", + "2023-09-19 12:47:23,237: Added node c29ebde3-9748-4a97-b8a0-1673cbd53b62 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", + "2023-09-19 12:47:23,248: Added node f734ac26-40b3-4380-ad37-f8782202a628 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", + "2023-09-19 12:47:23,256: Added node 23785fbc-7d27-4697-bd06-937fcbb63e87 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", + "2023-09-19 12:47:23,262: Added node 1ceaff86-bccd-4a06-81e0-0c616c803eab to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", + "2023-09-19 12:47:23,356: Added node 854b2562-1dc2-4dd4-9e50-8f079ba2971c to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", + "2023-09-19 12:47:23,371: Added node 211e8c06-b3f9-48f1-9627-62a7e81e34d3 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", + "2023-09-19 12:47:23,376: Added node b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", + "2023-09-19 12:47:23,380::ERROR::primaite.simulator.network.hardware.base::175::NIC 84:42:75:c8:10:28/192.168.10.110 cannot be enabled as it is not connected to a Link\n" ] } ], @@ -47,7 +47,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -65,7 +65,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -74,14 +74,14 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2023-09-19 11:35:45,008: Added service d2090e0c-1080-4a4e-98af-489f2c7b5370 to node 119850a0-61c2-4050-afd9-709656e65c7b\n" + "2023-09-19 12:47:26,764: Added service 6a8c0179-3ea6-48c1-bc97-259bb5853118 to node 1ceaff86-bccd-4a06-81e0-0c616c803eab\n" ] } ], @@ -91,37 +91,37 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'uuid': '119850a0-61c2-4050-afd9-709656e65c7b',\n", + "{'uuid': '1ceaff86-bccd-4a06-81e0-0c616c803eab',\n", " 'hostname': 'database_server',\n", " 'operating_state': 1,\n", - " 'NICs': {'89cbde58-4726-4a8b-8de0-fb5bdcdf615b': {'uuid': '89cbde58-4726-4a8b-8de0-fb5bdcdf615b',\n", + " 'NICs': {'4b53abce-74ca-4015-868e-3c7dc2f29117': {'uuid': '4b53abce-74ca-4015-868e-3c7dc2f29117',\n", " 'ip_adress': '192.168.1.14',\n", " 'subnet_mask': '255.255.255.0',\n", - " 'mac_address': '51:46:0d:52:99:9d',\n", + " 'mac_address': '7b:9e:4e:29:2b:ca',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'wake_on_lan': False,\n", " 'enabled': True}},\n", - " 'file_system': {'uuid': 'af425e71-5437-4de4-b1f2-e7c36d9cff06',\n", - " 'folders': {'root': {'uuid': 'e75401ee-e311-4519-8d63-f1c04376fb18',\n", + " 'file_system': {'uuid': '0b831f3b-a3df-40cc-ab5b-21a3f22f4b68',\n", + " 'folders': {'root': {'uuid': 'a388f22b-0a4d-465d-b5f6-e98ff9564483',\n", " 'name': 'root',\n", " 'files': {},\n", " 'is_quarantined': False},\n", - " 'database': {'uuid': '6ff67dbf-69ee-465e-935b-3c557c716702',\n", + " 'database': {'uuid': 'c13d8734-9e01-42f6-84d7-4ea36424663d',\n", " 'name': 'database',\n", - " 'files': {'database.db': {'uuid': '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4',\n", + " 'files': {'database.db': {'uuid': '213ed482-6028-44ff-a6ab-45e5800ac1a1',\n", " 'name': 'database.db',\n", " 'size': 12288,\n", " 'file_type': 'DB'}},\n", " 'is_quarantined': False}}},\n", " 'applications': {},\n", - " 'services': {'d2090e0c-1080-4a4e-98af-489f2c7b5370': {'uuid': 'd2090e0c-1080-4a4e-98af-489f2c7b5370',\n", + " 'services': {'6a8c0179-3ea6-48c1-bc97-259bb5853118': {'uuid': '6a8c0179-3ea6-48c1-bc97-259bb5853118',\n", " 'health_state': 'GOOD',\n", " 'health_state_red_view': 'GOOD',\n", " 'criticality': 'LOWEST',\n", @@ -137,7 +137,7 @@ " 'process': {}}" ] }, - "execution_count": 17, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -148,7 +148,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -157,16 +157,16 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "129" + "175" ] }, - "execution_count": 19, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -177,14 +177,14 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '1b9ef60a-371c-43b9-af56-d0ddb220189e', 'enable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '1b9ef60a-371c-43b9-af56-d0ddb220189e', 'disable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '41e2ffb4-3d19-4824-a665-6f6fa68afcd1', 'enable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '41e2ffb4-3d19-4824-a665-6f6fa68afcd1', 'disable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', 'c61a3021-876b-491b-a3af-4e8955f26fc4', 'enable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', 'c61a3021-876b-491b-a3af-4e8955f26fc4', 'disable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '217f5929-bb4c-4e4d-b564-efd805be5733', 'enable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '217f5929-bb4c-4e4d-b564-efd805be5733', 'disable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '29708cc6-008e-4db1-b50f-cf4f9246c3e2', 'enable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '29708cc6-008e-4db1-b50f-cf4f9246c3e2', 'disable'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'scan'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'checkhash'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'repair'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'restore'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'scan'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'shutdown'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'startup'], ['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'reset'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'scan'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'checkhash'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'repair'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'restore'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'scan'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'shutdown'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'startup'], ['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'reset'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'scan'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'checkhash'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'repair'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'restore'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'scan'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'shutdown'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'startup'], ['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'reset'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'nic', '27a09b26-0912-4de1-8fac-afefd06668a7', 'enable'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'nic', '27a09b26-0912-4de1-8fac-afefd06668a7', 'disable'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'scan'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'checkhash'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'repair'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'restore'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'scan'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'shutdown'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'startup'], ['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'reset'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'nic', '34050ee7-c5a0-42c3-9be3-f55d6668443d', 'enable'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'nic', '34050ee7-c5a0-42c3-9be3-f55d6668443d', 'disable'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'scan'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'checkhash'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'repair'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'restore'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'scan'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'shutdown'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'startup'], ['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'reset'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'nic', 'd0748224-7123-48a7-a0ab-1775ad3390e2', 'enable'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'nic', 'd0748224-7123-48a7-a0ab-1775ad3390e2', 'disable'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'scan'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'checkhash'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'repair'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'restore'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'scan'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'shutdown'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'startup'], ['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'reset'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'compromise'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'scan'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'stop'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'start'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'pause'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'resume'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'restart'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'disable'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'enable'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'nic', '89cbde58-4726-4a8b-8de0-fb5bdcdf615b', 'enable'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'nic', '89cbde58-4726-4a8b-8de0-fb5bdcdf615b', 'disable'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'scan'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'checkhash'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'repair'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'restore'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'scan'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'checkhash'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'repair'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'restore'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'scan'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'checkhash'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'delete'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'repair'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'restore'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'scan'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'checkhash'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'delete'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'repair'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'restore'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'scan'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'shutdown'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'startup'], ['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'reset'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'nic', 'c6b8769b-c411-497c-a2e6-b4b46d805d8a', 'enable'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'nic', 'c6b8769b-c411-497c-a2e6-b4b46d805d8a', 'disable'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'scan'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'checkhash'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'repair'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'restore'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'scan'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'shutdown'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'startup'], ['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'reset'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'nic', 'e72aa295-6132-424c-8892-75f4c9999c8e', 'enable'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'nic', 'e72aa295-6132-424c-8892-75f4c9999c8e', 'disable'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'scan'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'checkhash'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'repair'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'restore'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'scan'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'shutdown'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'startup'], ['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'reset'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', '2f3f3ba3-4722-4fe7-9a60-96d55f737c77', 'enable'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', '2f3f3ba3-4722-4fe7-9a60-96d55f737c77', 'disable'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', 'a4e26b3a-981c-4d77-8f39-dcfc88639da7', 'enable'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', 'a4e26b3a-981c-4d77-8f39-dcfc88639da7', 'disable'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'scan'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'checkhash'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'repair'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'restore'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'scan'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'shutdown'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'startup'], ['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'reset']]\n" + "[['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'cbb4c7b4-d218-41e0-a871-64cf087afbbf', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'cbb4c7b4-d218-41e0-a871-64cf087afbbf', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'b26668a8-3ac4-4a0f-8c85-f7776d773f4b', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'b26668a8-3ac4-4a0f-8c85-f7776d773f4b', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '2cb97c78-2819-48be-8ab1-a938c67731e7', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '2cb97c78-2819-48be-8ab1-a938c67731e7', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'af5fd9d3-de73-4595-a3c5-c79530415a82', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'af5fd9d3-de73-4595-a3c5-c79530415a82', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '5c9195e7-82f9-4486-9747-162fbcc31f93', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '5c9195e7-82f9-4486-9747-162fbcc31f93', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'scan'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'checkhash'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'repair'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'restore'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'delete'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'corrupt'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'scan'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'shutdown'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'startup'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'reset'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'logon'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'logoff'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'acl', 'add_rule'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'acl', 'remove_rule'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'scan'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'checkhash'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'repair'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'restore'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'delete'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'corrupt'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'scan'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'shutdown'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'startup'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'reset'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'logon'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'logoff'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'scan'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'checkhash'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'repair'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'restore'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'delete'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'corrupt'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'scan'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'shutdown'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'startup'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'reset'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'logon'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'logoff'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'nic', '77c037a4-5d66-4275-b34a-3690f0df1fb3', 'enable'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'nic', '77c037a4-5d66-4275-b34a-3690f0df1fb3', 'disable'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'scan'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'checkhash'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'repair'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'restore'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'delete'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'corrupt'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'scan'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'shutdown'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'startup'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'reset'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'logon'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'logoff'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'nic', 'b6bb225c-5782-4374-8e9c-f8ae611c6300', 'enable'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'nic', 'b6bb225c-5782-4374-8e9c-f8ae611c6300', 'disable'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'scan'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'checkhash'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'repair'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'restore'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'delete'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'corrupt'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'scan'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'shutdown'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'startup'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'reset'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'logon'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'logoff'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'nic', 'b6b13073-88ff-4153-ac3d-89475aaa8974', 'enable'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'nic', 'b6b13073-88ff-4153-ac3d-89475aaa8974', 'disable'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'scan'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'checkhash'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'repair'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'restore'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'delete'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'corrupt'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'scan'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'shutdown'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'startup'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'reset'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'logon'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'logoff'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'compromise'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'stop'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'start'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'pause'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'resume'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'restart'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'disable'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'enable'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'nic', '4b53abce-74ca-4015-868e-3c7dc2f29117', 'enable'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'nic', '4b53abce-74ca-4015-868e-3c7dc2f29117', 'disable'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'checkhash'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'repair'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'restore'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'delete'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'corrupt'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'checkhash'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'repair'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'restore'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'delete'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'corrupt'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'checkhash'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'delete'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'repair'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'restore'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'corrupt'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'checkhash'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'delete'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'repair'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'restore'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'corrupt'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'shutdown'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'startup'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'reset'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'logon'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'logoff'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'nic', '229b368c-55f5-463b-bafc-d6a804aa0e85', 'enable'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'nic', '229b368c-55f5-463b-bafc-d6a804aa0e85', 'disable'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'scan'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'checkhash'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'repair'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'restore'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'delete'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'corrupt'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'scan'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'shutdown'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'startup'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'reset'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'logon'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'logoff'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'nic', 'e291339e-d212-4807-b475-e779042de3f5', 'enable'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'nic', 'e291339e-d212-4807-b475-e779042de3f5', 'disable'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'scan'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'checkhash'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'repair'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'restore'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'delete'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'corrupt'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'scan'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'shutdown'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'startup'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'reset'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'logon'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'logoff'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '2b2a29e6-f56f-4328-9376-34d0cdb30d8d', 'enable'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '2b2a29e6-f56f-4328-9376-34d0cdb30d8d', 'disable'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '3b2d0133-9fa0-4872-a449-9f2bb0337b49', 'enable'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '3b2d0133-9fa0-4872-a449-9f2bb0337b49', 'disable'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'scan'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'checkhash'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'repair'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'restore'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'delete'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'corrupt'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'scan'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'shutdown'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'startup'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'reset'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'logon'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'logoff']]\n" ] } ], @@ -194,142 +194,188 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '1b9ef60a-371c-43b9-af56-d0ddb220189e', 'enable']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '1b9ef60a-371c-43b9-af56-d0ddb220189e', 'disable']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '41e2ffb4-3d19-4824-a665-6f6fa68afcd1', 'enable']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '41e2ffb4-3d19-4824-a665-6f6fa68afcd1', 'disable']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', 'c61a3021-876b-491b-a3af-4e8955f26fc4', 'enable']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', 'c61a3021-876b-491b-a3af-4e8955f26fc4', 'disable']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '217f5929-bb4c-4e4d-b564-efd805be5733', 'enable']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '217f5929-bb4c-4e4d-b564-efd805be5733', 'disable']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '29708cc6-008e-4db1-b50f-cf4f9246c3e2', 'enable']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'nic', '29708cc6-008e-4db1-b50f-cf4f9246c3e2', 'disable']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'scan']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'checkhash']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'repair']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'file_system', 'folder', 'aeb786fe-145b-4be5-baba-da1d47cf85e9', 'restore']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'scan']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'shutdown']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'startup']\n", - "['node', '9a63b1cf-1700-4ea9-94fa-4cdefb7f94a4', 'reset']\n", - "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'scan']\n", - "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'checkhash']\n", - "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'repair']\n", - "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'file_system', 'folder', '08438583-8fd3-4239-851d-b851042bd9a4', 'restore']\n", - "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'scan']\n", - "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'shutdown']\n", - "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'startup']\n", - "['node', 'e0f81131-2c42-4182-99a7-695e9016c518', 'reset']\n", - "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'scan']\n", - "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'checkhash']\n", - "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'repair']\n", - "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'file_system', 'folder', 'a2333863-f204-4f10-99ad-5ecadd9e0a3e', 'restore']\n", - "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'scan']\n", - "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'shutdown']\n", - "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'startup']\n", - "['node', '524ebdb4-ed76-4e8e-8cd6-babbf0d02f69', 'reset']\n", - "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'nic', '27a09b26-0912-4de1-8fac-afefd06668a7', 'enable']\n", - "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'nic', '27a09b26-0912-4de1-8fac-afefd06668a7', 'disable']\n", - "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'scan']\n", - "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'checkhash']\n", - "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'repair']\n", - "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'file_system', 'folder', '8e9d5646-e151-4902-91e4-58cf6026dccc', 'restore']\n", - "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'scan']\n", - "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'shutdown']\n", - "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'startup']\n", - "['node', '1e78d3ae-8eb7-4bb7-830e-dcf7fc000625', 'reset']\n", - "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'nic', '34050ee7-c5a0-42c3-9be3-f55d6668443d', 'enable']\n", - "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'nic', '34050ee7-c5a0-42c3-9be3-f55d6668443d', 'disable']\n", - "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'scan']\n", - "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'checkhash']\n", - "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'repair']\n", - "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'file_system', 'folder', 'd2fedd6f-4604-42f8-baa4-125db2a62495', 'restore']\n", - "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'scan']\n", - "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'shutdown']\n", - "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'startup']\n", - "['node', 'fa1bc1f8-8d28-49a2-bf06-bac6ffdeacf5', 'reset']\n", - "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'nic', 'd0748224-7123-48a7-a0ab-1775ad3390e2', 'enable']\n", - "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'nic', 'd0748224-7123-48a7-a0ab-1775ad3390e2', 'disable']\n", - "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'scan']\n", - "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'checkhash']\n", - "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'repair']\n", - "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'file_system', 'folder', '3387bfee-5beb-4a1c-9320-52fddf0a24cb', 'restore']\n", - "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'scan']\n", - "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'shutdown']\n", - "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'startup']\n", - "['node', '40b4845a-11a7-41a7-9ab7-1fb80b1799b3', 'reset']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'compromise']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'scan']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'stop']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'start']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'pause']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'resume']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'restart']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'disable']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'service', 'd2090e0c-1080-4a4e-98af-489f2c7b5370', 'enable']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'nic', '89cbde58-4726-4a8b-8de0-fb5bdcdf615b', 'enable']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'nic', '89cbde58-4726-4a8b-8de0-fb5bdcdf615b', 'disable']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'scan']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'checkhash']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'repair']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', 'e75401ee-e311-4519-8d63-f1c04376fb18', 'restore']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'scan']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'checkhash']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'repair']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'folder', '6ff67dbf-69ee-465e-935b-3c557c716702', 'restore']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'scan']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'checkhash']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'delete']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'repair']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', 'c677e354-e93d-44c1-abe3-e6ab148627e2', 'restore']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'scan']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'checkhash']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'delete']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'repair']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'file_system', 'file', '840c0b5d-e1fb-4500-8769-0a0ea9b1c5f4', 'restore']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'scan']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'shutdown']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'startup']\n", - "['node', '119850a0-61c2-4050-afd9-709656e65c7b', 'reset']\n", - "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'nic', 'c6b8769b-c411-497c-a2e6-b4b46d805d8a', 'enable']\n", - "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'nic', 'c6b8769b-c411-497c-a2e6-b4b46d805d8a', 'disable']\n", - "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'scan']\n", - "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'checkhash']\n", - "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'repair']\n", - "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'file_system', 'folder', 'e1d27b2a-b7a6-4ebf-bbf3-7e23e9e160a4', 'restore']\n", - "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'scan']\n", - "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'shutdown']\n", - "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'startup']\n", - "['node', 'f7c983b1-0374-4280-be8f-2eae561dbf08', 'reset']\n", - "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'nic', 'e72aa295-6132-424c-8892-75f4c9999c8e', 'enable']\n", - "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'nic', 'e72aa295-6132-424c-8892-75f4c9999c8e', 'disable']\n", - "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'scan']\n", - "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'checkhash']\n", - "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'repair']\n", - "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'file_system', 'folder', '91a8fc8b-fbcc-4752-bb08-017d9d266279', 'restore']\n", - "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'scan']\n", - "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'shutdown']\n", - "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'startup']\n", - "['node', '8479b2e0-9f97-47ea-a2e0-483ad604439f', 'reset']\n", - "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', '2f3f3ba3-4722-4fe7-9a60-96d55f737c77', 'enable']\n", - "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', '2f3f3ba3-4722-4fe7-9a60-96d55f737c77', 'disable']\n", - "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', 'a4e26b3a-981c-4d77-8f39-dcfc88639da7', 'enable']\n", - "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'nic', 'a4e26b3a-981c-4d77-8f39-dcfc88639da7', 'disable']\n", - "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'scan']\n", - "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'checkhash']\n", - "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'repair']\n", - "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'file_system', 'folder', '113499d8-b41c-405b-b8c9-44444e87e9d1', 'restore']\n", - "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'scan']\n", - "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'shutdown']\n", - "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'startup']\n", - "['node', 'a2d78848-9e70-4824-bd91-9a6915988e38', 'reset']\n" + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'cbb4c7b4-d218-41e0-a871-64cf087afbbf', 'enable']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'cbb4c7b4-d218-41e0-a871-64cf087afbbf', 'disable']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'b26668a8-3ac4-4a0f-8c85-f7776d773f4b', 'enable']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'b26668a8-3ac4-4a0f-8c85-f7776d773f4b', 'disable']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '2cb97c78-2819-48be-8ab1-a938c67731e7', 'enable']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '2cb97c78-2819-48be-8ab1-a938c67731e7', 'disable']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'af5fd9d3-de73-4595-a3c5-c79530415a82', 'enable']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'af5fd9d3-de73-4595-a3c5-c79530415a82', 'disable']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '5c9195e7-82f9-4486-9747-162fbcc31f93', 'enable']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '5c9195e7-82f9-4486-9747-162fbcc31f93', 'disable']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'scan']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'checkhash']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'repair']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'restore']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'delete']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'corrupt']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'scan']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'shutdown']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'startup']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'reset']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'logon']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'logoff']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'acl', 'add_rule']\n", + "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'acl', 'remove_rule']\n", + "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'scan']\n", + "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'checkhash']\n", + "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'repair']\n", + "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'restore']\n", + "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'delete']\n", + "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'corrupt']\n", + "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'scan']\n", + "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'shutdown']\n", + "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'startup']\n", + "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'reset']\n", + "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'logon']\n", + "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'logoff']\n", + "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'scan']\n", + "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'checkhash']\n", + "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'repair']\n", + "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'restore']\n", + "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'delete']\n", + "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'corrupt']\n", + "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'scan']\n", + "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'shutdown']\n", + "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'startup']\n", + "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'reset']\n", + "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'logon']\n", + "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'logoff']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'nic', '77c037a4-5d66-4275-b34a-3690f0df1fb3', 'enable']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'nic', '77c037a4-5d66-4275-b34a-3690f0df1fb3', 'disable']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'scan']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'checkhash']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'repair']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'restore']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'delete']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'corrupt']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'scan']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'shutdown']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'startup']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'reset']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'logon']\n", + "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'logoff']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'nic', 'b6bb225c-5782-4374-8e9c-f8ae611c6300', 'enable']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'nic', 'b6bb225c-5782-4374-8e9c-f8ae611c6300', 'disable']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'scan']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'checkhash']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'repair']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'restore']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'delete']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'corrupt']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'scan']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'shutdown']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'startup']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'reset']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'logon']\n", + "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'logoff']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'nic', 'b6b13073-88ff-4153-ac3d-89475aaa8974', 'enable']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'nic', 'b6b13073-88ff-4153-ac3d-89475aaa8974', 'disable']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'scan']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'checkhash']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'repair']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'restore']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'delete']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'corrupt']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'scan']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'shutdown']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'startup']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'reset']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'logon']\n", + "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'logoff']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'compromise']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'scan']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'stop']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'start']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'pause']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'resume']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'restart']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'disable']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'enable']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'nic', '4b53abce-74ca-4015-868e-3c7dc2f29117', 'enable']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'nic', '4b53abce-74ca-4015-868e-3c7dc2f29117', 'disable']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'scan']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'checkhash']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'repair']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'restore']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'delete']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'corrupt']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'scan']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'checkhash']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'repair']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'restore']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'delete']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'corrupt']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'scan']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'checkhash']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'delete']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'repair']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'restore']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'corrupt']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'scan']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'checkhash']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'delete']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'repair']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'restore']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'corrupt']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'scan']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'shutdown']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'startup']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'reset']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'logon']\n", + "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'logoff']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'nic', '229b368c-55f5-463b-bafc-d6a804aa0e85', 'enable']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'nic', '229b368c-55f5-463b-bafc-d6a804aa0e85', 'disable']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'scan']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'checkhash']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'repair']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'restore']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'delete']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'corrupt']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'scan']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'shutdown']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'startup']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'reset']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'logon']\n", + "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'logoff']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'nic', 'e291339e-d212-4807-b475-e779042de3f5', 'enable']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'nic', 'e291339e-d212-4807-b475-e779042de3f5', 'disable']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'scan']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'checkhash']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'repair']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'restore']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'delete']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'corrupt']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'scan']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'shutdown']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'startup']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'reset']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'logon']\n", + "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'logoff']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '2b2a29e6-f56f-4328-9376-34d0cdb30d8d', 'enable']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '2b2a29e6-f56f-4328-9376-34d0cdb30d8d', 'disable']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '3b2d0133-9fa0-4872-a449-9f2bb0337b49', 'enable']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '3b2d0133-9fa0-4872-a449-9f2bb0337b49', 'disable']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'scan']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'checkhash']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'repair']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'restore']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'delete']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'corrupt']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'scan']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'shutdown']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'startup']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'reset']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'logon']\n", + "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'logoff']\n" ] } ], From 68f67f13da153f1ebb520d69db889fa287ed5cc7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 19 Sep 2023 15:13:51 +0100 Subject: [PATCH 179/980] Fix formatting on docs for actions. --- docs/source/action_system.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/source/action_system.rst b/docs/source/action_system.rst index e79ef348..b527bff9 100644 --- a/docs/source/action_system.rst +++ b/docs/source/action_system.rst @@ -11,11 +11,13 @@ Just like other aspects of SimComponent, the actions are not managed centrally f - API An 'action' contains two elements: + 1. `request` - selects which action you want to take on this `SimComponent`. This is formatted as a list of strings such as `['network', 'node', '', 'service', '', 'restart']`. 2. `context` - optional extra information that can be used to decide how to process the action. This is formatted as a dictionary. For example, if the action requires authentication, the context can include information about the user that initiated the request to decide if their permissions are sufficient. - request The request is a list of strings which help specify who should handle the request. The strings in the request list help ActionManagers traverse the 'ownership tree' of SimComponent. The example given above would be handled in the following way: + 1. `Simulation` receives `['network', 'node', '', 'service', '', 'restart']`. The first element of the action is `network`, therefore it passes the action down to its network. 2. `Network` receives `['node', '', 'service', '', 'restart']`. @@ -70,7 +72,11 @@ An example of how this works is in the :py:class:`primaite.simulator.network.har # a regular action which is processed by the Node itself action_manager.add_action("turn_on", Action(func=lambda request, context: self.turn_on())) - # if the Node receives a request where the first word is 'service', it will use a dummy manager called self._service_action_manager to pass on the reqeust to the relevant service. This dummy manager is simply here to map the service UUID that that service's own action manager. This is done because the next string after "service" is always the uuid of that service, so we need an actionmanager to pop that string before sending it onto the relevant service's ActionManager. + # if the Node receives a request where the first word is 'service', it will use a dummy manager + # called self._service_action_manager to pass on the reqeust to the relevant service. This dummy + # manager is simply here to map the service UUID that that service's own action manager. This is + # done because the next string after "service" is always the uuid of that service, so we need an + # actionmanager to pop that string before sending it onto the relevant service's ActionManager. self._service_action_manager = ActionManager() action_manager.add_action("service", Action(func=self._service_action_manager)) ... From 93476554a9e09fd68800bafb399f571a6945f790 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 19 Sep 2023 15:17:13 +0100 Subject: [PATCH 180/980] Undo experimental changes to request format --- src/primaite/simulator/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 78e6139f..df9d17ea 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -42,7 +42,7 @@ class Action(BaseModel): the action can be performed or not. """ - func: Callable[[Dict], None] + func: Callable[[List[str], Dict], None] """ ``func`` is a function that accepts a request and a context dict. Typically this would be a lambda function that invokes a class method of your SimComponent. For example if the component is a node and the action is for @@ -74,7 +74,7 @@ class ActionManager(BaseModel): actions: Dict[str, Action] = {} """maps action verb to an action object.""" - def __call__(self, request: Dict, context: Dict) -> None: + def __call__(self, request: Callable[[List[str], Dict], None], context: Dict) -> None: """ Process an action request. From 682091b4ba2fe9df1a6bb651585de4da167d4ece Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 19 Sep 2023 15:30:02 +0100 Subject: [PATCH 181/980] Remove redundant method --- src/primaite/simulator/core.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index df9d17ea..ceba88c9 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -200,14 +200,6 @@ class SimComponent(BaseModel): } return state - def possible_actions(self) -> List[List[str]]: - """Enumerate all actions that this component can accept. - - :return: List of all action strings that can be passed to this component. - :rtype: List[Dict[str]] - """ - action_list = ActionManager # TODO: extract possible actions? how to do this neatly? - def apply_action(self, action: List[str], context: Dict = {}) -> None: """ Apply an action to a simulation component. Action data is passed in as a 'namespaced' list of strings. From 860b3fb8018de91f1f3f1c8a0129d3df51ce2105 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 19 Sep 2023 16:11:42 +0100 Subject: [PATCH 182/980] Add test to new action functionliaty --- src/primaite/simulator/core.py | 4 +- .../test_action_integration.py | 55 +++++++++++++++++++ .../test_permission_system.py | 6 +- 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 tests/integration_tests/component_creation/test_action_integration.py diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index ceba88c9..a292be18 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -218,9 +218,9 @@ class SimComponent(BaseModel): :param: context: Dict containing context for actions :type context: Dict """ - if self.action_manager is None: + if self._action_manager is None: return - self.action_manager(action, context) + self._action_manager(action, context) def apply_timestep(self, timestep: int) -> None: """ diff --git a/tests/integration_tests/component_creation/test_action_integration.py b/tests/integration_tests/component_creation/test_action_integration.py new file mode 100644 index 00000000..eb18110d --- /dev/null +++ b/tests/integration_tests/component_creation/test_action_integration.py @@ -0,0 +1,55 @@ +import pytest + +from primaite.simulator.core import Action +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.sim_container import Simulation +from primaite.simulator.system.services.database_service import DatabaseService + + +def test_passing_actions_down(monkeypatch) -> None: + """Check that an action is passed down correctly to the child component.""" + + sim = Simulation() + + pc1 = Computer(hostname="PC-1", ip_address="10.10.1.1", subnet_mask="255.255.255.0") + pc2 = Computer(hostname="PC-2", ip_address="10.10.1.2", subnet_mask="255.255.255.0") + srv = Server(hostname="WEBSERVER", ip_address="10.10.1.100", subnet_mask="255.255.255.0") + s1 = Switch(hostname="switch1") + + for n in [pc1, pc2, srv, s1]: + sim.network.add_node(n) + + database_service = DatabaseService(file_system=srv.file_system) + srv.install_service(database_service) + + downloads_folder = pc1.file_system.create_folder("downloads") + pc1.file_system.create_file("bermuda_triangle.png", folder_name="downloads") + + sim.network.connect(pc1.ethernet_port[1], s1.switch_ports[1]) + sim.network.connect(pc2.ethernet_port[1], s1.switch_ports[2]) + sim.network.connect(s1.switch_ports[3], srv.ethernet_port[1]) + + # call this method to make sure no errors occur. + sim._action_manager.get_action_tree() + + # patch the action to do something which we can check the result of. + action_invoked = False + + def succeed(): + nonlocal action_invoked + action_invoked = True + + monkeypatch.setitem( + downloads_folder._action_manager.actions, "repair", Action(func=lambda request, context: succeed()) + ) + + assert not action_invoked + + # call the patched method + sim.apply_action( + ["network", "node", pc1.uuid, "file_system", "folder", pc1.file_system.get_folder("downloads").uuid, "repair"] + ) + + assert action_invoked diff --git a/tests/integration_tests/component_creation/test_permission_system.py b/tests/integration_tests/component_creation/test_permission_system.py index 6816ba84..57e0b35a 100644 --- a/tests/integration_tests/component_creation/test_permission_system.py +++ b/tests/integration_tests/component_creation/test_permission_system.py @@ -7,6 +7,7 @@ from primaite.simulator.core import Action, ActionManager, AllowAllValidator, Si from primaite.simulator.domain.controller import AccountGroup, GroupMembershipValidator +@pytest.mark.skip(reason="Action validation is not currently a required feature.") def test_group_action_validation() -> None: """ Check that actions are denied when an unauthorised request is made. @@ -28,9 +29,9 @@ def test_group_action_validation() -> None: def __init__(self, **kwargs): super().__init__(**kwargs) - self.action_manager = ActionManager() + self._action_manager = ActionManager() - self.action_manager.add_action( + self._action_manager.add_action( "create_folder", Action( func=lambda request, context: self.create_folder(request[0]), @@ -62,6 +63,7 @@ def test_group_action_validation() -> None: assert my_node.folders[0].name == "memes" +@pytest.mark.skip(reason="Action validation is not currently a required feature.") def test_hierarchical_action_with_validation() -> None: """ Check that validation works with sub-objects. From 2e76b3f1621d92e971184a46ec0f777673937c52 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Wed, 20 Sep 2023 16:23:35 +0100 Subject: [PATCH 183/980] #1916: FTP client STOR request to FTP server --- src/primaite/simulator/network/networks.py | 72 ++++++--- .../simulator/network/protocols/arp.py | 4 +- .../simulator/network/protocols/dns.py | 4 +- .../simulator/network/protocols/ftp.py | 55 +++++++ .../simulator/network/protocols/packet.py | 12 ++ .../network/transmission/data_link_layer.py | 5 + .../system/services/dns/dns_client.py | 1 + .../system/services/dns/dns_server.py | 1 + .../simulator/system/services/ftp/__init__.py | 0 .../system/services/ftp/ftp_client.py | 150 ++++++++++++++++++ .../system/services/ftp/ftp_server.py | 71 +++++++++ .../system/test_ftp_client_server.py | 59 +++++++ .../_simulator/_system/_services/test_ftp.py | 41 +++++ 13 files changed, 454 insertions(+), 21 deletions(-) create mode 100644 src/primaite/simulator/network/protocols/ftp.py create mode 100644 src/primaite/simulator/network/protocols/packet.py create mode 100644 src/primaite/simulator/system/services/ftp/__init__.py create mode 100644 src/primaite/simulator/system/services/ftp/ftp_client.py create mode 100644 src/primaite/simulator/system/services/ftp/ftp_server.py create mode 100644 tests/integration_tests/system/test_ftp_client_server.py create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index f594c29a..63cb05e0 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -12,6 +12,8 @@ from primaite.simulator.system.applications.database_client import DatabaseClien from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.dns.dns_server import DNSServer +from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.ftp.ftp_server import FTPServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot @@ -136,13 +138,13 @@ def arcd_uc2_network() -> Network: ) client_1.power_on() client_1.software_manager.install(DNSClient) - client_1_dns_client_service: DNSServer = client_1.software_manager.software["DNSClient"] # noqa - client_1_dns_client_service.start() network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) client_1.software_manager.install(DataManipulationBot) db_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] db_manipulation_bot.configure(server_ip_address=IPv4Address("192.168.1.14"), payload="DROP TABLE IF EXISTS user;") + client_1.software_manager.install(FTPClient) + # Client 2 client_2 = Computer( hostname="client_2", @@ -153,10 +155,10 @@ def arcd_uc2_network() -> Network: ) client_2.power_on() client_2.software_manager.install(DNSClient) - client_2_dns_client_service: DNSServer = client_2.software_manager.software["DNSClient"] # noqa - client_2_dns_client_service.start() network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) + client_2.software_manager.install(FTPClient) + # Domain Controller domain_controller = Server( hostname="domain_controller", @@ -191,20 +193,48 @@ def arcd_uc2_network() -> Network: );""" user_insert_statements = [ - "INSERT INTO user (name, email, age, city, occupation) VALUES ('John Doe', 'johndoe@example.com', 32, 'New York', 'Engineer');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Jane Smith', 'janesmith@example.com', 27, 'Los Angeles', 'Designer');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Bob Johnson', 'bobjohnson@example.com', 45, 'Chicago', 'Manager');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Alice Lee', 'alicelee@example.com', 22, 'San Francisco', 'Student');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('David Kim', 'davidkim@example.com', 38, 'Houston', 'Consultant');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Emily Chen', 'emilychen@example.com', 29, 'Seattle', 'Software Developer');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Frank Wang', 'frankwang@example.com', 55, 'New York', 'Entrepreneur');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Grace Park', 'gracepark@example.com', 31, 'Los Angeles', 'Marketing Specialist');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Henry Wu', 'henrywu@example.com', 40, 'Chicago', 'Accountant');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Isabella Kim', 'isabellakim@example.com', 26, 'San Francisco', 'Graphic Designer');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Jake Lee', 'jakelee@example.com', 33, 'Houston', 'Sales Manager');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Kelly Chen', 'kellychen@example.com', 28, 'Seattle', 'Web Developer');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Lucas Liu', 'lucasliu@example.com', 42, 'New York', 'Lawyer');", # noqa - "INSERT INTO user (name, email, age, city, occupation) VALUES ('Maggie Wang', 'maggiewang@example.com', 30, 'Los Angeles', 'Data Analyst');", # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('John Doe', 'johndoe@example.com', 32, 'New York', 'Engineer');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('Jane Smith', 'janesmith@example.com', 27, 'Los Angeles', 'Designer');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('Bob Johnson', 'bobjohnson@example.com', 45, 'Chicago', 'Manager');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('Alice Lee', 'alicelee@example.com', 22, 'San Francisco', 'Student');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('David Kim', 'davidkim@example.com', 38, 'Houston', 'Consultant');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('Emily Chen', 'emilychen@example.com', 29, 'Seattle', 'Software Developer');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('Frank Wang', 'frankwang@example.com', 55, 'New York', 'Entrepreneur');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('Grace Park', 'gracepark@example.com', 31, 'Los Angeles', 'Marketing Specialist');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('Henry Wu', 'henrywu@example.com', 40, 'Chicago', 'Accountant');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('Isabella Kim', 'isabellakim@example.com', 26, 'San Francisco', 'Graphic Designer');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('Jake Lee', 'jakelee@example.com', 33, 'Houston', 'Sales Manager');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('Kelly Chen', 'kellychen@example.com', 28, 'Seattle', 'Web Developer');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('Lucas Liu', 'lucasliu@example.com', 42, 'New York', 'Lawyer');", + # noqa + "INSERT INTO user (name, email, age, city, occupation) " + "VALUES ('Maggie Wang', 'maggiewang@example.com', 30, 'Los Angeles', 'Data Analyst');", + # noqa ] database_server.software_manager.install(DatabaseService) database_service: DatabaseService = database_server.software_manager.software["DatabaseService"] # noqa @@ -232,7 +262,6 @@ def arcd_uc2_network() -> Network: # register the web_server to a domain dns_server_service: DNSServer = domain_controller.software_manager.software["DNSServer"] # noqa - dns_server_service.start() dns_server_service.dns_register("arcd.com", web_server.ip_address) # Backup Server @@ -246,6 +275,8 @@ def arcd_uc2_network() -> Network: backup_server.power_on() network.connect(endpoint_b=backup_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[4]) + backup_server.software_manager.install(FTPServer) + # Security Suite security_suite = Server( hostname="security_suite", @@ -271,4 +302,7 @@ def arcd_uc2_network() -> Network: # Allow DNS requests router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.DNS, dst_port=Port.DNS, position=1) + # Allow FTP requests + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.FTP, dst_port=Port.FTP, position=2) + return network diff --git a/src/primaite/simulator/network/protocols/arp.py b/src/primaite/simulator/network/protocols/arp.py index 5e38cc66..7b3e4509 100644 --- a/src/primaite/simulator/network/protocols/arp.py +++ b/src/primaite/simulator/network/protocols/arp.py @@ -5,6 +5,8 @@ from typing import Optional from pydantic import BaseModel +from primaite.simulator.network.protocols.packet import DataPacket + class ARPEntry(BaseModel): """ @@ -18,7 +20,7 @@ class ARPEntry(BaseModel): nic_uuid: str -class ARPPacket(BaseModel): +class ARPPacket(DataPacket): """ Represents the ARP layer of a network frame. diff --git a/src/primaite/simulator/network/protocols/dns.py b/src/primaite/simulator/network/protocols/dns.py index 41bf5e0c..4f9be51b 100644 --- a/src/primaite/simulator/network/protocols/dns.py +++ b/src/primaite/simulator/network/protocols/dns.py @@ -5,6 +5,8 @@ from typing import Optional from pydantic import BaseModel +from primaite.simulator.network.protocols.packet import DataPacket + class DNSRequest(BaseModel): """Represents a DNS Request packet of a network frame. @@ -26,7 +28,7 @@ class DNSReply(BaseModel): "IP Address of the Domain Name requested." -class DNSPacket(BaseModel): +class DNSPacket(DataPacket): """ Represents the DNS layer of a network frame. diff --git a/src/primaite/simulator/network/protocols/ftp.py b/src/primaite/simulator/network/protocols/ftp.py new file mode 100644 index 00000000..ab277045 --- /dev/null +++ b/src/primaite/simulator/network/protocols/ftp.py @@ -0,0 +1,55 @@ +from enum import Enum +from typing import Any + +from primaite.simulator.network.protocols.packet import DataPacket + + +class FTPCommand(Enum): + """FTP Commands that are allowed.""" + + PORT = "PORT" + """Set a port to be used for the FTP transfer.""" + + STOR = "STOR" + """Copy or put data to the FTP server.""" + + RETR = "RETR" + """Retrieve data from the FTP server.""" + + DELE = "DELE" + """Delete the file in the specified path.""" + + RMD = "RMD" + """Remove the directory in the specified path.""" + + MKD = "MKD" + """Make a directory in the specified path.""" + + LIST = "LIST" + """Return a list of files in the specified path.""" + + QUIT = "QUIT" + """Ends connection between client and server.""" + + +class FTPStatusCode(Enum): + """Status code of the current FTP request.""" + + OK = 200 + """Command successful.""" + + ERROR = 500 + """General error code.""" + + +class FTPPacket(DataPacket): + """Represents an FTP Packet.""" + + ftp_command: FTPCommand + """Command type of the packet.""" + + ftp_command_args: Any + """Arguments for command.""" + + status_code: FTPStatusCode = None + """Status of the response.""" diff --git a/src/primaite/simulator/network/protocols/packet.py b/src/primaite/simulator/network/protocols/packet.py new file mode 100644 index 00000000..1adcc800 --- /dev/null +++ b/src/primaite/simulator/network/protocols/packet.py @@ -0,0 +1,12 @@ +from pydantic import BaseModel + + +class DataPacket(BaseModel): + """Data packet abstract class.""" + + packet_payload_size: float = 0 + """Size of the packet.""" + + def get_packet_size(self) -> float: + """Returns the size of the packet header and payload.""" + return self.packet_payload_size + float(len(self.model_dump_json().encode("utf-8"))) diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index b7986622..fa823a60 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -5,6 +5,7 @@ from pydantic import BaseModel from primaite import getLogger from primaite.simulator.network.protocols.arp import ARPPacket +from primaite.simulator.network.protocols.packet import DataPacket from primaite.simulator.network.transmission.network_layer import ICMPPacket, IPPacket, IPProtocol from primaite.simulator.network.transmission.primaite_layer import PrimaiteHeader from primaite.simulator.network.transmission.transport_layer import TCPHeader, UDPHeader @@ -132,6 +133,10 @@ class Frame(BaseModel): @property def size(self) -> float: # noqa - Keep it as MBits as this is how they're expressed """The size of the Frame in Bytes.""" + # get the payload size if it is a data packet + if isinstance(self.payload, DataPacket): + return self.payload.get_packet_size() + return float(len(self.model_dump_json().encode("utf-8"))) @property diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index cf5278af..56d5d8b4 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -27,6 +27,7 @@ class DNSClient(Service): # TCP for now kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) + self.start() def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/services/dns/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py index c6a9afd3..c3c39595 100644 --- a/src/primaite/simulator/system/services/dns/dns_server.py +++ b/src/primaite/simulator/system/services/dns/dns_server.py @@ -26,6 +26,7 @@ class DNSServer(Service): # TCP for now kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) + self.start() def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/services/ftp/__init__.py b/src/primaite/simulator/system/services/ftp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py new file mode 100644 index 00000000..687e9a12 --- /dev/null +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -0,0 +1,150 @@ +from ipaddress import IPv4Address +from typing import Optional + +from primaite.simulator.file_system.file_system import File +from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.software_manager import SoftwareManager +from primaite.simulator.system.services.service import Service + + +class FTPClient(Service): + """ + A class for simulating an FTP client service. + + This class inherits from the `Service` class and provides methods to emulate FTP + RFC 959: https://datatracker.ietf.org/doc/html/rfc959 + """ + + connected: bool = False + """Keeps track of whether or not the FTP client is connected to an FTP server""" + + def __init__(self, **kwargs): + kwargs["name"] = "FTPClient" + kwargs["port"] = Port.FTP + kwargs["protocol"] = IPProtocol.TCP + super().__init__(**kwargs) + self.start() + + def _connect_to_server( + self, dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = Port.FTP + ) -> bool: + """ + Connects the client to a given FTP server. + + :param: dest_ip_address: IP address of the FTP server the client needs to connect to. Optional. + :type: Optional[IPv4Address] + :param: dest_port: Port of the FTP server the client needs to connect to. Optional. + :type: Optional[Port] + :param: server_password: The password to use when connecting to the FTP server. Optional. + :type: Optional[str] + """ + # normally FTP will choose a random port for the transfer, but using the FTP command port will do for now + + # create FTP packet + payload: FTPPacket = FTPPacket( + ftp_command=FTPCommand.PORT, + ftp_command_args=Port.FTP, + ) + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port + ) + return payload.status_code == FTPStatusCode.OK + + def _disconnect_from_server( + self, + ftp_server_ip_address: Optional[IPv4Address] = None, + ) -> bool: + # send a disconnect request payload to FTP server + # return true if connected successfully else false + self.connected = False + + def _process_response(self, payload: FTPPacket): + """ + Process any FTPPacket responses. + + :param: payload: The FTPPacket payload + :type: FTPPacket + """ + if payload.ftp_command == FTPCommand.PORT: + if payload.status_code == FTPStatusCode.OK: + self.connected = True + + def send_file( + self, + dest_ip_address: IPv4Address, + src_folder_name: str, + src_file_name: str, + dest_folder_name: str, + dest_file_name: str, + dest_port: Optional[Port] = Port.FTP, + is_reattempt: Optional[bool] = False, + ) -> bool: + """Send a file to a target IP address.""" + file_to_transfer: File = self.file_system.get_file(folder_name=src_folder_name, file_name=src_file_name) + if not file_to_transfer: + self.sys_log.error(f"Unable to send file that does not exist: {src_folder_name}/{src_file_name}") + return False + + # check if FTP is currently connected to IP + self.connected = self._connect_to_server( + dest_ip_address=dest_ip_address, + dest_port=dest_port, + ) + + if not self.connected: + if is_reattempt: + return False + + return self.send_file( + src_folder_name=file_to_transfer.folder.name, + src_file_name=file_to_transfer.name, + dest_folder_name=dest_folder_name, + dest_file_name=dest_file_name, + dest_ip_address=dest_ip_address, + dest_port=dest_port, + is_reattempt=True, + ) + else: + # send STOR request + payload: FTPPacket = FTPPacket( + ftp_command=FTPCommand.STOR, + ftp_command_args={ + "dest_folder_name": dest_folder_name, + "dest_file_name": dest_file_name, + "file_size": file_to_transfer.sim_size, + }, + packet_payload_size=file_to_transfer.sim_size, + ) + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port + ) + + if payload.status_code == Port.FTP: + self._disconnect_from_server() + return True + + def request_file( + self, + dest_ip_address: IPv4Address, + src_folder_name: str, + src_file_name: str, + dest_folder_name: str, + dest_file_name: str, + dest_port: Optional[Port] = Port.FTP, + is_reattempt: Optional[bool] = False, + ) -> bool: + """Request a file from a target IP address.""" + pass + + def receive(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> bool: + """Receives a payload from the SessionManager.""" + if not isinstance(payload, FTPPacket): + self.sys_log.error(f"{payload} is not an FTP packet") + return False + + self._process_response(payload=payload) + return True diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py new file mode 100644 index 00000000..ead6d503 --- /dev/null +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -0,0 +1,71 @@ +from typing import Any, Optional + +from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.service import Service + + +class FTPServer(Service): + """ + A class for simulating an FTP server service. + + This class inherits from the `Service` class and provides methods to emulate FTP + RFC 959: https://datatracker.ietf.org/doc/html/rfc959 + """ + + server_password: Optional[str] = None + """Password needed to connect to FTP server. Default is None.""" + + def __init__(self, **kwargs): + kwargs["name"] = "FTPServer" + kwargs["port"] = Port.FTP + kwargs["protocol"] = IPProtocol.TCP + super().__init__(**kwargs) + self.start() + + def _process_ftp_command(self, payload: FTPPacket) -> FTPPacket: + # handle PORT request + if payload.ftp_command == FTPCommand.PORT: + # check that the port is valid + if isinstance(payload.ftp_command_args, Port) and payload.ftp_command_args.value in range(0, 65535): + # return successful connection + payload.status_code = FTPStatusCode.OK + + # handle STOR request + if payload.ftp_command == FTPCommand.STOR: + # check that the file is created in the computed hosting the FTP server + if self._process_store_data(payload=payload): + payload.status_code = FTPStatusCode.OK + + return payload + + def _process_store_data(self, payload: FTPPacket) -> bool: + """Handle the transfer of data from Client to this Server.""" + try: + file_name = payload.ftp_command_args["dest_file_name"] + folder_name = payload.ftp_command_args["dest_folder_name"] + file_size = payload.ftp_command_args["file_size"] + self.file_system.create_file( + file_name=file_name, + folder_name=folder_name, + size=file_size, + ) + self.sys_log.info( + f"Created item in {self.name}: {payload.ftp_command_args['dest_folder_name']}/" + f"{payload.ftp_command_args['dest_file_name']}" + ) + # file should exist + return self.file_system.get_file(file_name=file_name, folder_name=folder_name) is not None + except Exception as e: + self.sys_log.error(f"Unable to store file in {self.name}: {e}") + return False + + def receive(self, payload: Any, session_id: Optional[str] = None, **kwargs) -> bool: + """Receives a payload from the SessionManager.""" + if not isinstance(payload, FTPPacket): + self.sys_log.error(f"{payload} is not an FTP packet") + return False + + self.send(self._process_ftp_command(payload=payload), session_id) + return True diff --git a/tests/integration_tests/system/test_ftp_client_server.py b/tests/integration_tests/system/test_ftp_client_server.py new file mode 100644 index 00000000..e062e0b7 --- /dev/null +++ b/tests/integration_tests/system/test_ftp_client_server.py @@ -0,0 +1,59 @@ +from ipaddress import IPv4Address + +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.ftp.ftp_server import FTPServer +from primaite.simulator.system.services.service import ServiceOperatingState + + +def test_ftp_client_store_file_in_server(uc2_network): + """ + Test checks to see if the client is able to store files in the backup server. + """ + client_1: Computer = uc2_network.get_node_by_hostname("client_1") + backup_server: Server = uc2_network.get_node_by_hostname("backup_server") + + ftp_client: FTPClient = client_1.software_manager.software["FTPClient"] + ftp_server: FTPServer = backup_server.software_manager.software["FTPServer"] + + assert ftp_client.operating_state == ServiceOperatingState.RUNNING + assert ftp_server.operating_state == ServiceOperatingState.RUNNING + + # create file on ftp client + ftp_client.file_system.create_file(file_name="test_file.txt") + + ftp_client.send_file( + src_folder_name="root", + src_file_name="test_file.txt", + dest_folder_name="client_1_backup", + dest_file_name="test_file.txt", + dest_ip_address=backup_server.nics.get(next(iter(backup_server.nics))).ip_address, + ) + + assert ftp_server.file_system.get_file(folder_name="client_1_backup", file_name="test_file.txt") + + +def test_ftp_client_retrieve_file_from_server(uc2_network): + """ + Test checks to see if the client is able to retrieve files from the backup server. + """ + client_1: Computer = uc2_network.get_node_by_hostname("client_1") + backup_server: Server = uc2_network.get_node_by_hostname("backup_server") + + ftp_client: FTPClient = client_1.software_manager.software["FTPClient"] + ftp_server: FTPServer = backup_server.software_manager.software["FTPServer"] + + assert ftp_client.operating_state == ServiceOperatingState.RUNNING + assert ftp_server.operating_state == ServiceOperatingState.RUNNING + + # create file on ftp server + ftp_server.file_system.create_file(file_name="test_file.txt", folder_name="file_share") + + ftp_client.request_file( + src_folder_name="file_share", + src_file_name="test_file.txt", + dest_folder_name="downloads", + dest_file_name="test_file.txt", + dest_ip_address=backup_server.nics.get(next(iter(backup_server.nics))).ip_address, + ) diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py new file mode 100644 index 00000000..64013207 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py @@ -0,0 +1,41 @@ +from ipaddress import IPv4Address + +import pytest + +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.ftp.ftp_server import FTPServer + + +@pytest.fixture(scope="function") +def ftp_server() -> Node: + node = Node(hostname="ftp_server") + node.software_manager.install(software_class=FTPServer) + node.software_manager.software["FTPServer"].start() + return node + + +@pytest.fixture(scope="function") +def ftp_client() -> Node: + node = Node(hostname="ftp_client") + node.software_manager.install(software_class=FTPClient) + node.software_manager.software["FTPClient"].start() + return node + + +def test_create_ftp_server(ftp_server): + assert ftp_server is not None + ftp_server_service: FTPServer = ftp_server.software_manager.software["FTPServer"] + assert ftp_server_service.name is "FTPServer" + assert ftp_server_service.port is Port.FTP + assert ftp_server_service.protocol is IPProtocol.TCP + + +def test_create_ftp_client(ftp_client): + assert ftp_client is not None + ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + assert ftp_client_service.name is "FTPClient" + assert ftp_client_service.port is Port.FTP + assert ftp_client_service.protocol is IPProtocol.TCP From f54f278fca6e71d48c5bf375a03933b8db200891 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 21 Sep 2023 10:13:01 +0100 Subject: [PATCH 184/980] Initialise observations in agent interface --- sandbox.ipynb | 134 ++++++++++++++++++ src/primaite/game/__init__.py | 0 src/primaite/game/actor/__init__.py | 0 src/primaite/game/actor/actions.py | 21 +++ src/primaite/game/actor/interface.py | 32 +++++ src/primaite/game/actor/observations.py | 107 ++++++++++++++ src/primaite/game/actor/rewards.py | 20 +++ src/primaite/game/session.py | 6 + .../simulator/file_system/file_system.py | 16 ++- src/primaite/simulator/network/container.py | 4 +- 10 files changed, 333 insertions(+), 7 deletions(-) create mode 100644 sandbox.ipynb create mode 100644 src/primaite/game/__init__.py create mode 100644 src/primaite/game/actor/__init__.py create mode 100644 src/primaite/game/actor/actions.py create mode 100644 src/primaite/game/actor/interface.py create mode 100644 src/primaite/game/actor/observations.py create mode 100644 src/primaite/game/actor/rewards.py create mode 100644 src/primaite/game/session.py diff --git a/sandbox.ipynb b/sandbox.ipynb new file mode 100644 index 00000000..e7db5f4c --- /dev/null +++ b/sandbox.ipynb @@ -0,0 +1,134 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.simulator.network.networks import arcd_uc2_network\n", + "%load_ext autoreload\n", + "%autoreload 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "net = arcd_uc2_network()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "random_node = list(net.nodes.keys())[0]\n", + "f = net.nodes[random_node].file_system.create_file(file_name=\"testfile\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "f.describe_state()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def test_file_observation():\n", + " from primaite.simulator.sim_container import Simulation\n", + " from primaite.simulator.network.hardware.nodes.computer import Computer\n", + " from primaite.game.actor.observations import FileObservation\n", + "\n", + " sim = Simulation()\n", + " pc = Computer(hostname=\"beep\", ip_address=\"123.123.123.123\", subnet_mask=\"255.255.255.0\")\n", + " sim.network.add_node(pc)\n", + " f = pc.file_system.create_file(file_name=\"dog.png\")\n", + "\n", + " dog_file_obs = FileObservation(where=['network','nodes',pc.uuid,'file_system'])\n", + " print(sim.describe_state())\n", + "test_file_observation()" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'NIC' object has no attribute 'gateway'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/main.py:718\u001b[0m, in \u001b[0;36mBaseModel.__getattr__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 717\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 718\u001b[0m \u001b[39mreturn\u001b[39;00m pydantic_extra[item]\n\u001b[1;32m 719\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m \u001b[39mas\u001b[39;00m exc:\n", + "\u001b[0;31mKeyError\u001b[0m: 'gateway'", + "\nThe above exception was the direct cause of the following exception:\n", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m/home/cade/repos/PrimAITE/test.ipynb Cell 6\u001b[0m line \u001b[0;36m1\n\u001b[1;32m 7\u001b[0m sim\u001b[39m.\u001b[39mnetwork\u001b[39m.\u001b[39madd_node(pc)\n\u001b[1;32m 8\u001b[0m f \u001b[39m=\u001b[39m pc\u001b[39m.\u001b[39mfile_system\u001b[39m.\u001b[39mcreate_file(file_name\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mdog.png\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m---> 10\u001b[0m sim\u001b[39m.\u001b[39;49mdescribe_state()\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/simulator/sim_container.py:54\u001b[0m, in \u001b[0;36mSimulation.describe_state\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 43\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 44\u001b[0m \u001b[39mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[1;32m 45\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[39m:rtype: Dict\u001b[39;00m\n\u001b[1;32m 50\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 51\u001b[0m state \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 52\u001b[0m state\u001b[39m.\u001b[39mupdate(\n\u001b[1;32m 53\u001b[0m {\n\u001b[0;32m---> 54\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mnetwork\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mnetwork\u001b[39m.\u001b[39;49mdescribe_state(),\n\u001b[1;32m 55\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mdomain\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdomain\u001b[39m.\u001b[39mdescribe_state(),\n\u001b[1;32m 56\u001b[0m }\n\u001b[1;32m 57\u001b[0m )\n\u001b[1;32m 58\u001b[0m \u001b[39mreturn\u001b[39;00m state\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/simulator/network/container.py:166\u001b[0m, in \u001b[0;36mNetwork.describe_state\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 158\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 159\u001b[0m \u001b[39mProduce a dictionary describing the current state of the Network.\u001b[39;00m\n\u001b[1;32m 160\u001b[0m \n\u001b[1;32m 161\u001b[0m \u001b[39m:return: A dictionary capturing the current state of the Network and its child objects.\u001b[39;00m\n\u001b[1;32m 162\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 163\u001b[0m state \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 164\u001b[0m state\u001b[39m.\u001b[39mupdate(\n\u001b[1;32m 165\u001b[0m {\n\u001b[0;32m--> 166\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mnodes\u001b[39m\u001b[39m\"\u001b[39m: {uuid:node\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, node \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnodes\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 167\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mlinks\u001b[39m\u001b[39m\"\u001b[39m: {uuid:link\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, link \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mlinks\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 168\u001b[0m }\n\u001b[1;32m 169\u001b[0m )\n\u001b[1;32m 170\u001b[0m \u001b[39mreturn\u001b[39;00m state\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/simulator/network/container.py:166\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 158\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 159\u001b[0m \u001b[39mProduce a dictionary describing the current state of the Network.\u001b[39;00m\n\u001b[1;32m 160\u001b[0m \n\u001b[1;32m 161\u001b[0m \u001b[39m:return: A dictionary capturing the current state of the Network and its child objects.\u001b[39;00m\n\u001b[1;32m 162\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 163\u001b[0m state \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 164\u001b[0m state\u001b[39m.\u001b[39mupdate(\n\u001b[1;32m 165\u001b[0m {\n\u001b[0;32m--> 166\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mnodes\u001b[39m\u001b[39m\"\u001b[39m: {uuid:node\u001b[39m.\u001b[39;49mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, node \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnodes\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 167\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mlinks\u001b[39m\u001b[39m\"\u001b[39m: {uuid:link\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, link \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mlinks\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 168\u001b[0m }\n\u001b[1;32m 169\u001b[0m )\n\u001b[1;32m 170\u001b[0m \u001b[39mreturn\u001b[39;00m state\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/simulator/network/hardware/base.py:954\u001b[0m, in \u001b[0;36mNode.describe_state\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 941\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 942\u001b[0m \u001b[39mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[1;32m 943\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 947\u001b[0m \u001b[39m:rtype: Dict\u001b[39;00m\n\u001b[1;32m 948\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 949\u001b[0m state \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 950\u001b[0m state\u001b[39m.\u001b[39mupdate(\n\u001b[1;32m 951\u001b[0m {\n\u001b[1;32m 952\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mhostname\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mhostname,\n\u001b[1;32m 953\u001b[0m \u001b[39m\"\u001b[39m\u001b[39moperating_state\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39moperating_state\u001b[39m.\u001b[39mvalue,\n\u001b[0;32m--> 954\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mNICs\u001b[39m\u001b[39m\"\u001b[39m: {uuid: nic\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, nic \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnics\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 955\u001b[0m \u001b[39m# \"switch_ports\": {uuid, sp for uuid, sp in self.switch_ports.items()},\u001b[39;00m\n\u001b[1;32m 956\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mfile_system\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfile_system\u001b[39m.\u001b[39mdescribe_state(),\n\u001b[1;32m 957\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mapplications\u001b[39m\u001b[39m\"\u001b[39m: {uuid: app\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, app \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mapplications\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 958\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mservices\u001b[39m\u001b[39m\"\u001b[39m: {uuid: svc\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, svc \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mservices\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 959\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mprocess\u001b[39m\u001b[39m\"\u001b[39m: {uuid: proc\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, proc \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mprocesses\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 960\u001b[0m }\n\u001b[1;32m 961\u001b[0m )\n\u001b[1;32m 962\u001b[0m \u001b[39mreturn\u001b[39;00m state\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/simulator/network/hardware/base.py:954\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 941\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 942\u001b[0m \u001b[39mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[1;32m 943\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 947\u001b[0m \u001b[39m:rtype: Dict\u001b[39;00m\n\u001b[1;32m 948\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 949\u001b[0m state \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 950\u001b[0m state\u001b[39m.\u001b[39mupdate(\n\u001b[1;32m 951\u001b[0m {\n\u001b[1;32m 952\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mhostname\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mhostname,\n\u001b[1;32m 953\u001b[0m \u001b[39m\"\u001b[39m\u001b[39moperating_state\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39moperating_state\u001b[39m.\u001b[39mvalue,\n\u001b[0;32m--> 954\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mNICs\u001b[39m\u001b[39m\"\u001b[39m: {uuid: nic\u001b[39m.\u001b[39;49mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, nic \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnics\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 955\u001b[0m \u001b[39m# \"switch_ports\": {uuid, sp for uuid, sp in self.switch_ports.items()},\u001b[39;00m\n\u001b[1;32m 956\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mfile_system\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfile_system\u001b[39m.\u001b[39mdescribe_state(),\n\u001b[1;32m 957\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mapplications\u001b[39m\u001b[39m\"\u001b[39m: {uuid: app\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, app \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mapplications\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 958\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mservices\u001b[39m\u001b[39m\"\u001b[39m: {uuid: svc\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, svc \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mservices\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 959\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mprocess\u001b[39m\u001b[39m\"\u001b[39m: {uuid: proc\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, proc \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mprocesses\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 960\u001b[0m }\n\u001b[1;32m 961\u001b[0m )\n\u001b[1;32m 962\u001b[0m \u001b[39mreturn\u001b[39;00m state\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/simulator/network/hardware/base.py:138\u001b[0m, in \u001b[0;36mNIC.describe_state\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 125\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 126\u001b[0m \u001b[39mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[1;32m 127\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 131\u001b[0m \u001b[39m:rtype: Dict\u001b[39;00m\n\u001b[1;32m 132\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 133\u001b[0m state \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 134\u001b[0m state\u001b[39m.\u001b[39mupdate(\n\u001b[1;32m 135\u001b[0m {\n\u001b[1;32m 136\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mip_adress\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mstr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mip_address),\n\u001b[1;32m 137\u001b[0m \u001b[39m\"\u001b[39m\u001b[39msubnet_mask\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mstr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39msubnet_mask),\n\u001b[0;32m--> 138\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mgateway\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mstr\u001b[39m(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mgateway),\n\u001b[1;32m 139\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mmac_address\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmac_address,\n\u001b[1;32m 140\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mspeed\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mspeed,\n\u001b[1;32m 141\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mmtu\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmtu,\n\u001b[1;32m 142\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mwake_on_lan\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mwake_on_lan,\n\u001b[1;32m 143\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mdns_servers\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdns_servers,\n\u001b[1;32m 144\u001b[0m \u001b[39m\"\u001b[39m\u001b[39menabled\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39menabled,\n\u001b[1;32m 145\u001b[0m }\n\u001b[1;32m 146\u001b[0m )\n\u001b[1;32m 147\u001b[0m \u001b[39mreturn\u001b[39;00m state\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/main.py:720\u001b[0m, in \u001b[0;36mBaseModel.__getattr__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 718\u001b[0m \u001b[39mreturn\u001b[39;00m pydantic_extra[item]\n\u001b[1;32m 719\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m \u001b[39mas\u001b[39;00m exc:\n\u001b[0;32m--> 720\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mAttributeError\u001b[39;00m(\u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mtype\u001b[39m(\u001b[39mself\u001b[39m)\u001b[39m.\u001b[39m\u001b[39m__name__\u001b[39m\u001b[39m!r}\u001b[39;00m\u001b[39m object has no attribute \u001b[39m\u001b[39m{\u001b[39;00mitem\u001b[39m!r}\u001b[39;00m\u001b[39m'\u001b[39m) \u001b[39mfrom\u001b[39;00m \u001b[39mexc\u001b[39;00m\n\u001b[1;32m 721\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 722\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mhasattr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m\u001b[39m__class__\u001b[39m, item):\n", + "\u001b[0;31mAttributeError\u001b[0m: 'NIC' object has no attribute 'gateway'" + ] + } + ], + "source": [ + "from primaite.simulator.sim_container import Simulation\n", + "from primaite.simulator.network.hardware.nodes.computer import Computer\n", + "from primaite.game.actor.observations import FileObservation\n", + "\n", + "sim = Simulation()\n", + "pc = Computer(hostname=\"beep\", ip_address=\"123.123.123.123\", subnet_mask=\"255.255.255.0\")\n", + "sim.network.add_node(pc)\n", + "f = pc.file_system.create_file(file_name=\"dog.png\")\n", + "\n", + "sim.describe_state()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/primaite/game/__init__.py b/src/primaite/game/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/game/actor/__init__.py b/src/primaite/game/actor/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/game/actor/actions.py b/src/primaite/game/actor/actions.py new file mode 100644 index 00000000..cefd9917 --- /dev/null +++ b/src/primaite/game/actor/actions.py @@ -0,0 +1,21 @@ +from abc import ABC, abstractmethod +from typing import Any, Dict, List + +from pydantic import BaseModel + + +class AbstractAction(BaseModel): + @abstractmethod + def __call__(self, action: Any) -> List[str]: + """_summary_ + + :param action: _description_ + :type action: Any + :return: _description_ + :rtype: List[str] + """ + ... + + +class ActionSpace: + ... diff --git a/src/primaite/game/actor/interface.py b/src/primaite/game/actor/interface.py new file mode 100644 index 00000000..1fe43a32 --- /dev/null +++ b/src/primaite/game/actor/interface.py @@ -0,0 +1,32 @@ +# TODO: remove this comment... This is just here to point out that I've named this 'actor' rather than 'agent' +# That's because I want to point out that this is disctinct from 'agent' in the reinforcement learning sense of the word +# If you disagree, make a comment in the PR review and we can discuss +from abc import ABC, abstractmethod +from typing import Any, Dict, List + +from pydantic import BaseModel + +from primaite.game.actor.actions import ActionSpace +from primaite.game.actor.observations import ObservationSpace +from primaite.game.actor.rewards import RewardFunction + + +class AbstractActor(BaseModel): + """Base class for scripted and RL agents.""" + + ... + + +class AbstractScriptedActor(AbstractActor): + """Base class for actors which generate their own behaviour.""" + + ... + + +class AbstractPuppetActor(AbstractActor): + """Base class for actors controlled via external messages, such as RL policies.""" + + ... + + +# class AbstractRLActor(AbstractPuppetActor): ?? diff --git a/src/primaite/game/actor/observations.py b/src/primaite/game/actor/observations.py new file mode 100644 index 00000000..bcde1c8d --- /dev/null +++ b/src/primaite/game/actor/observations.py @@ -0,0 +1,107 @@ +from abc import ABC, abstractmethod +from typing import Any, Dict, Hashable, List + +from pydantic import BaseModel + + +def access_from_nested_dict(dictionary: Dict, keys: List[Hashable]) -> Any: + """ + Access an item from a deeply dictionary with a list of keys. + + For example, if the dictionary is {1: 'a', 2: {3: {4: 'b'}}}, then the key [2, 3, 4] would return 'b', and the key + [2, 3] would return {4: 'b'}. Raises a KeyError if specified key does not exist at any level of nesting. + + :param dictionary: Deeply nested dictionary + :type dictionary: Dict + :param keys: List of dict keys used to traverse the nested dict. Each item corresponds to one level of depth. + :type keys: List[Hashable] + :return: The value in the dictionary + :rtype: Any + """ + if not keys: + return dictionary + k = keys.pop(0) + try: + return access_from_nested_dict(dictionary[k], keys) + except (TypeError, KeyError): + raise KeyError(f"Cannot find requested key `{k}` in nested dictionary") + + +class AbstractObservation(BaseModel): + @abstractmethod + def __call__(self, state: Dict) -> Any: + """_summary_ + + :param state: _description_ + :type state: Dict + :return: _description_ + :rtype: Any + """ + ... + # receive state dict + + +class FileObservation(AbstractObservation): + where: List[str] + """Store information about where in the simulation state dictionary to find the relevatn information.""" + + def __call__(self, state: Dict) -> Dict: + file_state = access_from_nested_dict(state, self.where) + + +class ObservationSpace: + """Manage the observations of an Actor.""" + + ... + # what this class does: + # keep a list of observations + # create observations for an actor from the config + + +# Example YAML file for agent observation space +""" +arcd_gate: + rl_framework: SB3 + rl_algo: PPO + n_learn_steps: 128 + n_learn_episodes: 1000 + +game_layer: + agents: + - ref: client_1_green_user + type: GREEN + node_ref: client_1 + service: WebBrowser + pol: + - step: 1 + action: START + + - ref: client_1_data_manip_red_bot + node_ref: client_1 + service: DataManipulationBot + execution_definition: + - server_ip_address: 192.168.1.10 + - server_password: + - payload: 'ATTACK' + + pol: + - step: 75 + action: EXECUTE + + + + +simulation: + nodes: + - ref: client_1 + hostname: client_1 + node_type: Computer + ip_address: 192.168.10.100 + services: + - name: DataManipulationBot + links: + endpoint_a: + endpoint_b: 1524552-fgfg4147gdh-25gh4gd +rewards: + +""" diff --git a/src/primaite/game/actor/rewards.py b/src/primaite/game/actor/rewards.py new file mode 100644 index 00000000..1db54176 --- /dev/null +++ b/src/primaite/game/actor/rewards.py @@ -0,0 +1,20 @@ +from abc import ABC, abstractmethod +from typing import Any, Dict, List + +from pydantic import BaseModel + + +class AbstractReward(BaseModel): + def __call__(self, states: List[Dict]) -> float: + """_summary_ + + :param state: _description_ + :type state: Dict + :return: _description_ + :rtype: float + """ + ... + + +class RewardFunction(BaseModel): + ... diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py new file mode 100644 index 00000000..47ef4ce9 --- /dev/null +++ b/src/primaite/game/session.py @@ -0,0 +1,6 @@ +# What do? Be an entry point for using PrimAITE +# 1. parse monoconfig +# 2. craete simulation +# 3. create actors and configure their actions/observations/rewards/ anything else +# 4. Create connection with ARCD GATE +# 5. idk diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index b2037729..a6d2689b 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -3,6 +3,7 @@ from __future__ import annotations import math import os.path import shutil +from enum import Enum from pathlib import Path from typing import Dict, Optional @@ -42,6 +43,14 @@ def convert_size(size_bytes: int) -> str: return f"{s} {size_name[i]}" +class FileSystemItemHealthStatus(Enum): + GOOD = 1 + COMPROMISED = 2 + CORRUPT = 3 + RESTORING = 4 + REPAIRING = 5 + + class FileSystemItemABC(SimComponent): """ Abstract base class for file system items used in the file system simulation. @@ -51,6 +60,7 @@ class FileSystemItemABC(SimComponent): name: str "The name of the FileSystemItemABC." + health_status: FileSystemItemHealthStatus = FileSystemItemHealthStatus.GOOD def describe_state(self) -> Dict: """ @@ -59,11 +69,7 @@ class FileSystemItemABC(SimComponent): :return: Current state of this object and child objects. """ state = super().describe_state() - state.update( - { - "name": self.name, - } - ) + state.update({"name": self.name, "health_status": self.health_status.value}) return state @property diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index c3a935b8..81ddf475 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -163,8 +163,8 @@ class Network(SimComponent): state = super().describe_state() state.update( { - "nodes": {i for i, node in self._node_id_map.items()}, - "links": {i: link.describe_state() for i, link in self._link_id_map.items()}, + "nodes": {uuid: node.describe_state() for uuid, node in self.nodes.items()}, + "links": {uuid: link.describe_state() for uuid, link in self.links.items()}, } ) return state From 53fd4ed82832761b8fd22e8407ddc6297da0b27a Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 21 Sep 2023 10:42:26 +0100 Subject: [PATCH 185/980] Finish File Observation --- sandbox.ipynb | 59 ++++++++++++++++--------- src/primaite/game/actor/observations.py | 15 +++++++ 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/sandbox.ipynb b/sandbox.ipynb index e7db5f4c..06e37664 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -66,26 +66,21 @@ "metadata": {}, "outputs": [ { - "ename": "AttributeError", - "evalue": "'NIC' object has no attribute 'gateway'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/main.py:718\u001b[0m, in \u001b[0;36mBaseModel.__getattr__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 717\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 718\u001b[0m \u001b[39mreturn\u001b[39;00m pydantic_extra[item]\n\u001b[1;32m 719\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m \u001b[39mas\u001b[39;00m exc:\n", - "\u001b[0;31mKeyError\u001b[0m: 'gateway'", - "\nThe above exception was the direct cause of the following exception:\n", - "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m/home/cade/repos/PrimAITE/test.ipynb Cell 6\u001b[0m line \u001b[0;36m1\n\u001b[1;32m 7\u001b[0m sim\u001b[39m.\u001b[39mnetwork\u001b[39m.\u001b[39madd_node(pc)\n\u001b[1;32m 8\u001b[0m f \u001b[39m=\u001b[39m pc\u001b[39m.\u001b[39mfile_system\u001b[39m.\u001b[39mcreate_file(file_name\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mdog.png\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m---> 10\u001b[0m sim\u001b[39m.\u001b[39;49mdescribe_state()\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/simulator/sim_container.py:54\u001b[0m, in \u001b[0;36mSimulation.describe_state\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 43\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 44\u001b[0m \u001b[39mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[1;32m 45\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[39m:rtype: Dict\u001b[39;00m\n\u001b[1;32m 50\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 51\u001b[0m state \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 52\u001b[0m state\u001b[39m.\u001b[39mupdate(\n\u001b[1;32m 53\u001b[0m {\n\u001b[0;32m---> 54\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mnetwork\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mnetwork\u001b[39m.\u001b[39;49mdescribe_state(),\n\u001b[1;32m 55\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mdomain\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdomain\u001b[39m.\u001b[39mdescribe_state(),\n\u001b[1;32m 56\u001b[0m }\n\u001b[1;32m 57\u001b[0m )\n\u001b[1;32m 58\u001b[0m \u001b[39mreturn\u001b[39;00m state\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/simulator/network/container.py:166\u001b[0m, in \u001b[0;36mNetwork.describe_state\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 158\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 159\u001b[0m \u001b[39mProduce a dictionary describing the current state of the Network.\u001b[39;00m\n\u001b[1;32m 160\u001b[0m \n\u001b[1;32m 161\u001b[0m \u001b[39m:return: A dictionary capturing the current state of the Network and its child objects.\u001b[39;00m\n\u001b[1;32m 162\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 163\u001b[0m state \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 164\u001b[0m state\u001b[39m.\u001b[39mupdate(\n\u001b[1;32m 165\u001b[0m {\n\u001b[0;32m--> 166\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mnodes\u001b[39m\u001b[39m\"\u001b[39m: {uuid:node\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, node \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnodes\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 167\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mlinks\u001b[39m\u001b[39m\"\u001b[39m: {uuid:link\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, link \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mlinks\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 168\u001b[0m }\n\u001b[1;32m 169\u001b[0m )\n\u001b[1;32m 170\u001b[0m \u001b[39mreturn\u001b[39;00m state\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/simulator/network/container.py:166\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 158\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 159\u001b[0m \u001b[39mProduce a dictionary describing the current state of the Network.\u001b[39;00m\n\u001b[1;32m 160\u001b[0m \n\u001b[1;32m 161\u001b[0m \u001b[39m:return: A dictionary capturing the current state of the Network and its child objects.\u001b[39;00m\n\u001b[1;32m 162\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 163\u001b[0m state \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 164\u001b[0m state\u001b[39m.\u001b[39mupdate(\n\u001b[1;32m 165\u001b[0m {\n\u001b[0;32m--> 166\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mnodes\u001b[39m\u001b[39m\"\u001b[39m: {uuid:node\u001b[39m.\u001b[39;49mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, node \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnodes\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 167\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mlinks\u001b[39m\u001b[39m\"\u001b[39m: {uuid:link\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, link \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mlinks\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 168\u001b[0m }\n\u001b[1;32m 169\u001b[0m )\n\u001b[1;32m 170\u001b[0m \u001b[39mreturn\u001b[39;00m state\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/simulator/network/hardware/base.py:954\u001b[0m, in \u001b[0;36mNode.describe_state\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 941\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 942\u001b[0m \u001b[39mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[1;32m 943\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 947\u001b[0m \u001b[39m:rtype: Dict\u001b[39;00m\n\u001b[1;32m 948\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 949\u001b[0m state \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 950\u001b[0m state\u001b[39m.\u001b[39mupdate(\n\u001b[1;32m 951\u001b[0m {\n\u001b[1;32m 952\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mhostname\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mhostname,\n\u001b[1;32m 953\u001b[0m \u001b[39m\"\u001b[39m\u001b[39moperating_state\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39moperating_state\u001b[39m.\u001b[39mvalue,\n\u001b[0;32m--> 954\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mNICs\u001b[39m\u001b[39m\"\u001b[39m: {uuid: nic\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, nic \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnics\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 955\u001b[0m \u001b[39m# \"switch_ports\": {uuid, sp for uuid, sp in self.switch_ports.items()},\u001b[39;00m\n\u001b[1;32m 956\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mfile_system\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfile_system\u001b[39m.\u001b[39mdescribe_state(),\n\u001b[1;32m 957\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mapplications\u001b[39m\u001b[39m\"\u001b[39m: {uuid: app\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, app \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mapplications\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 958\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mservices\u001b[39m\u001b[39m\"\u001b[39m: {uuid: svc\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, svc \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mservices\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 959\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mprocess\u001b[39m\u001b[39m\"\u001b[39m: {uuid: proc\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, proc \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mprocesses\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 960\u001b[0m }\n\u001b[1;32m 961\u001b[0m )\n\u001b[1;32m 962\u001b[0m \u001b[39mreturn\u001b[39;00m state\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/simulator/network/hardware/base.py:954\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 941\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 942\u001b[0m \u001b[39mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[1;32m 943\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 947\u001b[0m \u001b[39m:rtype: Dict\u001b[39;00m\n\u001b[1;32m 948\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 949\u001b[0m state \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 950\u001b[0m state\u001b[39m.\u001b[39mupdate(\n\u001b[1;32m 951\u001b[0m {\n\u001b[1;32m 952\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mhostname\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mhostname,\n\u001b[1;32m 953\u001b[0m \u001b[39m\"\u001b[39m\u001b[39moperating_state\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39moperating_state\u001b[39m.\u001b[39mvalue,\n\u001b[0;32m--> 954\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mNICs\u001b[39m\u001b[39m\"\u001b[39m: {uuid: nic\u001b[39m.\u001b[39;49mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, nic \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnics\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 955\u001b[0m \u001b[39m# \"switch_ports\": {uuid, sp for uuid, sp in self.switch_ports.items()},\u001b[39;00m\n\u001b[1;32m 956\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mfile_system\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfile_system\u001b[39m.\u001b[39mdescribe_state(),\n\u001b[1;32m 957\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mapplications\u001b[39m\u001b[39m\"\u001b[39m: {uuid: app\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, app \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mapplications\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 958\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mservices\u001b[39m\u001b[39m\"\u001b[39m: {uuid: svc\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, svc \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mservices\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 959\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mprocess\u001b[39m\u001b[39m\"\u001b[39m: {uuid: proc\u001b[39m.\u001b[39mdescribe_state() \u001b[39mfor\u001b[39;00m uuid, proc \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mprocesses\u001b[39m.\u001b[39mitems()},\n\u001b[1;32m 960\u001b[0m }\n\u001b[1;32m 961\u001b[0m )\n\u001b[1;32m 962\u001b[0m \u001b[39mreturn\u001b[39;00m state\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/simulator/network/hardware/base.py:138\u001b[0m, in \u001b[0;36mNIC.describe_state\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 125\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 126\u001b[0m \u001b[39mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[1;32m 127\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 131\u001b[0m \u001b[39m:rtype: Dict\u001b[39;00m\n\u001b[1;32m 132\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 133\u001b[0m state \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 134\u001b[0m state\u001b[39m.\u001b[39mupdate(\n\u001b[1;32m 135\u001b[0m {\n\u001b[1;32m 136\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mip_adress\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mstr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mip_address),\n\u001b[1;32m 137\u001b[0m \u001b[39m\"\u001b[39m\u001b[39msubnet_mask\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mstr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39msubnet_mask),\n\u001b[0;32m--> 138\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mgateway\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mstr\u001b[39m(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mgateway),\n\u001b[1;32m 139\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mmac_address\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmac_address,\n\u001b[1;32m 140\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mspeed\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mspeed,\n\u001b[1;32m 141\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mmtu\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmtu,\n\u001b[1;32m 142\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mwake_on_lan\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mwake_on_lan,\n\u001b[1;32m 143\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mdns_servers\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdns_servers,\n\u001b[1;32m 144\u001b[0m \u001b[39m\"\u001b[39m\u001b[39menabled\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39menabled,\n\u001b[1;32m 145\u001b[0m }\n\u001b[1;32m 146\u001b[0m )\n\u001b[1;32m 147\u001b[0m \u001b[39mreturn\u001b[39;00m state\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/main.py:720\u001b[0m, in \u001b[0;36mBaseModel.__getattr__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 718\u001b[0m \u001b[39mreturn\u001b[39;00m pydantic_extra[item]\n\u001b[1;32m 719\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m \u001b[39mas\u001b[39;00m exc:\n\u001b[0;32m--> 720\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mAttributeError\u001b[39;00m(\u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mtype\u001b[39m(\u001b[39mself\u001b[39m)\u001b[39m.\u001b[39m\u001b[39m__name__\u001b[39m\u001b[39m!r}\u001b[39;00m\u001b[39m object has no attribute \u001b[39m\u001b[39m{\u001b[39;00mitem\u001b[39m!r}\u001b[39;00m\u001b[39m'\u001b[39m) \u001b[39mfrom\u001b[39;00m \u001b[39mexc\u001b[39;00m\n\u001b[1;32m 721\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 722\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mhasattr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m\u001b[39m__class__\u001b[39m, item):\n", - "\u001b[0;31mAttributeError\u001b[0m: 'NIC' object has no attribute 'gateway'" + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-09-21 10:41:35,339: Added node f03fec1b-927d-4d5a-8de9-1ef426052932 to Network f7400348-31e5-440e-8eb5-42366326d9d1\n" ] + }, + { + "data": { + "text/plain": [ + "{'health_status': 1}" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -98,7 +93,31 @@ "sim.network.add_node(pc)\n", "f = pc.file_system.create_file(file_name=\"dog.png\")\n", "\n", - "sim.describe_state()" + "state = sim.describe_state()\n", + "\n", + "dog_file_obs = FileObservation(where=['network','nodes',pc.uuid,'file_system', 'folders','root','files','dog.png'])\n", + "o = dog_file_obs(state)\n", + "o" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Dict(health_status:Discrete(6))" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dog_file_obs.space" ] }, { diff --git a/src/primaite/game/actor/observations.py b/src/primaite/game/actor/observations.py index bcde1c8d..7303b07b 100644 --- a/src/primaite/game/actor/observations.py +++ b/src/primaite/game/actor/observations.py @@ -3,6 +3,8 @@ from typing import Any, Dict, Hashable, List from pydantic import BaseModel +from gym import spaces + def access_from_nested_dict(dictionary: Dict, keys: List[Hashable]) -> Any: """ @@ -28,6 +30,7 @@ def access_from_nested_dict(dictionary: Dict, keys: List[Hashable]) -> Any: class AbstractObservation(BaseModel): + @abstractmethod def __call__(self, state: Dict) -> Any: """_summary_ @@ -40,6 +43,12 @@ class AbstractObservation(BaseModel): ... # receive state dict + @property + @abstractmethod + def space(self) -> spaces.Space: + """Subclasses must define the shape that they expect""" + ... + class FileObservation(AbstractObservation): where: List[str] @@ -47,6 +56,12 @@ class FileObservation(AbstractObservation): def __call__(self, state: Dict) -> Dict: file_state = access_from_nested_dict(state, self.where) + observation = {'health_status':file_state['health_status']} + return observation + + @property + def space(self) -> spaces.Space: + return spaces.Dict({'health_status':spaces.Discrete(6)}) class ObservationSpace: From 58edb6d3e493600bf1bca47dae76db42164f167a Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Thu, 21 Sep 2023 15:13:30 +0100 Subject: [PATCH 186/980] #1916: Created FTP superclass + working retrieve file method for FTP --- .../simulator/file_system/file_system.py | 2 +- .../system/services/ftp/ftp_client.py | 82 +++++++---- .../system/services/ftp/ftp_server.py | 45 +----- .../system/services/ftp/ftp_service.py | 132 ++++++++++++++++++ .../system/test_ftp_client_server.py | 3 + 5 files changed, 191 insertions(+), 73 deletions(-) create mode 100644 src/primaite/simulator/system/services/ftp/ftp_service.py diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index b2037729..9581a32b 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -226,7 +226,7 @@ class FileSystem(SimComponent): folder = self.get_folder(folder_name) if folder: return folder.get_file(file_name) - self.fs.sys_log.info(f"file not found /{folder_name}/{file_name}") + self.sys_log.info(f"file not found /{folder_name}/{file_name}") def delete_file(self, folder_name: str, file_name: str): """ diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 687e9a12..8e93df1b 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -6,10 +6,10 @@ from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPS from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.software_manager import SoftwareManager -from primaite.simulator.system.services.service import Service +from primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC -class FTPClient(Service): +class FTPClient(FTPServiceABC): """ A class for simulating an FTP client service. @@ -61,17 +61,6 @@ class FTPClient(Service): # return true if connected successfully else false self.connected = False - def _process_response(self, payload: FTPPacket): - """ - Process any FTPPacket responses. - - :param: payload: The FTPPacket payload - :type: FTPPacket - """ - if payload.ftp_command == FTPCommand.PORT: - if payload.status_code == FTPStatusCode.OK: - self.connected = True - def send_file( self, dest_ip_address: IPv4Address, @@ -109,23 +98,13 @@ class FTPClient(Service): ) else: # send STOR request - payload: FTPPacket = FTPPacket( - ftp_command=FTPCommand.STOR, - ftp_command_args={ - "dest_folder_name": dest_folder_name, - "dest_file_name": dest_file_name, - "file_size": file_to_transfer.sim_size, - }, - packet_payload_size=file_to_transfer.sim_size, + return self._send_data( + file=file_to_transfer, + dest_folder_name=dest_folder_name, + dest_file_name=dest_file_name, + dest_ip_address=dest_ip_address, + dest_port=dest_port, ) - software_manager: SoftwareManager = self.software_manager - software_manager.send_payload_to_session_manager( - payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port - ) - - if payload.status_code == Port.FTP: - self._disconnect_from_server() - return True def request_file( self, @@ -138,7 +117,48 @@ class FTPClient(Service): is_reattempt: Optional[bool] = False, ) -> bool: """Request a file from a target IP address.""" - pass + # check if FTP is currently connected to IP + self.connected = self._connect_to_server( + dest_ip_address=dest_ip_address, + dest_port=dest_port, + ) + + if not self.connected: + if is_reattempt: + return False + + return self.request_file( + src_folder_name=src_folder_name, + src_file_name=src_file_name, + dest_folder_name=dest_folder_name, + dest_file_name=dest_file_name, + dest_ip_address=dest_ip_address, + dest_port=dest_port, + is_reattempt=True, + ) + else: + # send retrieve request + payload: FTPPacket = FTPPacket( + ftp_command=FTPCommand.RETR, + ftp_command_args={ + "src_folder_name": src_folder_name, + "src_file_name": src_file_name, + "dest_file_name": dest_file_name, + "dest_folder_name": dest_folder_name, + }, + ) + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port + ) + + # the payload should have ok status code + if payload.status_code == FTPStatusCode.OK: + self.sys_log.info(f"File {src_folder_name}/{src_file_name} found in FTP server.") + return True + else: + self.sys_log.error(f"File {src_folder_name}/{src_file_name} does not exist in FTP server") + return False def receive(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> bool: """Receives a payload from the SessionManager.""" @@ -146,5 +166,5 @@ class FTPClient(Service): self.sys_log.error(f"{payload} is not an FTP packet") return False - self._process_response(payload=payload) + self._process_ftp_command(payload=payload, session_id=session_id) return True diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index ead6d503..c575479a 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -1,12 +1,12 @@ from typing import Any, Optional -from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode +from primaite.simulator.network.protocols.ftp import FTPPacket from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.services.service import Service +from primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC -class FTPServer(Service): +class FTPServer(FTPServiceABC): """ A class for simulating an FTP server service. @@ -24,48 +24,11 @@ class FTPServer(Service): super().__init__(**kwargs) self.start() - def _process_ftp_command(self, payload: FTPPacket) -> FTPPacket: - # handle PORT request - if payload.ftp_command == FTPCommand.PORT: - # check that the port is valid - if isinstance(payload.ftp_command_args, Port) and payload.ftp_command_args.value in range(0, 65535): - # return successful connection - payload.status_code = FTPStatusCode.OK - - # handle STOR request - if payload.ftp_command == FTPCommand.STOR: - # check that the file is created in the computed hosting the FTP server - if self._process_store_data(payload=payload): - payload.status_code = FTPStatusCode.OK - - return payload - - def _process_store_data(self, payload: FTPPacket) -> bool: - """Handle the transfer of data from Client to this Server.""" - try: - file_name = payload.ftp_command_args["dest_file_name"] - folder_name = payload.ftp_command_args["dest_folder_name"] - file_size = payload.ftp_command_args["file_size"] - self.file_system.create_file( - file_name=file_name, - folder_name=folder_name, - size=file_size, - ) - self.sys_log.info( - f"Created item in {self.name}: {payload.ftp_command_args['dest_folder_name']}/" - f"{payload.ftp_command_args['dest_file_name']}" - ) - # file should exist - return self.file_system.get_file(file_name=file_name, folder_name=folder_name) is not None - except Exception as e: - self.sys_log.error(f"Unable to store file in {self.name}: {e}") - return False - def receive(self, payload: Any, session_id: Optional[str] = None, **kwargs) -> bool: """Receives a payload from the SessionManager.""" if not isinstance(payload, FTPPacket): self.sys_log.error(f"{payload} is not an FTP packet") return False - self.send(self._process_ftp_command(payload=payload), session_id) + self.send(self._process_ftp_command(payload=payload, session_id=session_id), session_id) return True diff --git a/src/primaite/simulator/system/services/ftp/ftp_service.py b/src/primaite/simulator/system/services/ftp/ftp_service.py new file mode 100644 index 00000000..6214c510 --- /dev/null +++ b/src/primaite/simulator/system/services/ftp/ftp_service.py @@ -0,0 +1,132 @@ +from abc import ABC +from ipaddress import IPv4Address +from typing import Optional + +from primaite.simulator.file_system.file_system import File +from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.software_manager import SoftwareManager +from primaite.simulator.system.services.service import Service + + +class FTPServiceABC(Service, ABC): + """ + Abstract Base Class for FTP Client and Service. + + Contains shared methods between both classes. + """ + + def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: + # handle PORT request + if payload.ftp_command == FTPCommand.PORT: + # check that the port is valid + if isinstance(payload.ftp_command_args, Port) and payload.ftp_command_args.value in range(0, 65535): + # return successful connection + payload.status_code = FTPStatusCode.OK + + # handle STOR request + if payload.ftp_command == FTPCommand.STOR: + # check that the file is created in the computed hosting the FTP server + if self._store_data(payload=payload): + payload.status_code = FTPStatusCode.OK + + if payload.ftp_command == FTPCommand.RETR: + # check that the file exists in the FTP Server + file: File = self.file_system.get_file( + folder_name=payload.ftp_command_args["src_folder_name"], + file_name=payload.ftp_command_args["src_file_name"], + ) + if file: + payload.status_code = FTPStatusCode.OK + self._send_data( + file=file, + dest_folder_name=payload.ftp_command_args["dest_folder_name"], + dest_file_name=payload.ftp_command_args["dest_file_name"], + session_id=session_id, + ) + + return payload + + def _store_data(self, payload: FTPPacket) -> bool: + """ + Handle the transfer of data. + + :param: payload: The FTP Packet that contains the file data + :type: FTPPacket + """ + try: + file_name = payload.ftp_command_args["dest_file_name"] + folder_name = payload.ftp_command_args["dest_folder_name"] + file_size = payload.ftp_command_args["file_size"] + self.file_system.create_file( + file_name=file_name, + folder_name=folder_name, + size=file_size, + ) + self.sys_log.info( + f"Created item in {self.sys_log.hostname}: {payload.ftp_command_args['dest_folder_name']}/" + f"{payload.ftp_command_args['dest_file_name']}" + ) + # file should exist + return self.file_system.get_file(file_name=file_name, folder_name=folder_name) is not None + except Exception as e: + self.sys_log.error(f"Unable to create file in {self.sys_log.hostname}: {e}") + return False + + def _send_data( + self, + file: File, + dest_folder_name: str, + dest_file_name: str, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + session_id: Optional[str] = None, + ) -> bool: + # send STOR request + payload: FTPPacket = FTPPacket( + ftp_command=FTPCommand.STOR, + ftp_command_args={ + "dest_folder_name": dest_folder_name, + "dest_file_name": dest_file_name, + "file_size": file.sim_size, + }, + packet_payload_size=file.sim_size, + ) + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id + ) + + if payload.status_code == FTPStatusCode.OK: + return True + + return False + + def _retrieve_data(self, payload: FTPPacket, session_id: Optional[str] = None) -> bool: + """ + Handle the transfer of data from Server to Client. + + :param: payload: The FTP Packet that contains the file data + :type: FTPPacket + """ + try: + # find the file + file_name = payload.ftp_command_args["src_file_name"] + folder_name = payload.ftp_command_args["src_folder_name"] + retrieved_file: File = self.file_system.get_file(folder_name=folder_name, file_name=file_name) + + # if file does not exist, return an error + if not retrieved_file: + self.sys_log.error( + f"File {payload.ftp_command_args['dest_folder_name']}/" + f"{payload.ftp_command_args['dest_file_name']} does not exist in {self.sys_log.hostname}" + ) + return False + else: + # send requested data + return self._send_data( + file=retrieved_file, dest_file_name=file_name, dest_folder_name=folder_name, session_id=session_id + ) + except Exception as e: + self.sys_log.error(f"Unable to retrieve file from {self.sys_log.hostname}: {e}") + return False diff --git a/tests/integration_tests/system/test_ftp_client_server.py b/tests/integration_tests/system/test_ftp_client_server.py index e062e0b7..fbbe6011 100644 --- a/tests/integration_tests/system/test_ftp_client_server.py +++ b/tests/integration_tests/system/test_ftp_client_server.py @@ -57,3 +57,6 @@ def test_ftp_client_retrieve_file_from_server(uc2_network): dest_file_name="test_file.txt", dest_ip_address=backup_server.nics.get(next(iter(backup_server.nics))).ip_address, ) + + # client should have retrieved the file + assert ftp_client.file_system.get_file(folder_name="downloads", file_name="test_file.txt") From 2c234ab67abbc18ca0dc22cb28773b2e2ae1c0e6 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Fri, 22 Sep 2023 15:38:01 +0100 Subject: [PATCH 187/980] #1916: Setting up a connected states + added tests + error states for if service is interacted with when not running --- .../simulator/network/protocols/ftp.py | 4 +- .../system/services/ftp/ftp_client.py | 40 +++++++++++++++--- .../system/services/ftp/ftp_server.py | 41 ++++++++++++++++++- .../system/services/ftp/ftp_service.py | 7 ---- .../_simulator/_system/_services/test_ftp.py | 41 +++++++++++++++++++ 5 files changed, 117 insertions(+), 16 deletions(-) diff --git a/src/primaite/simulator/network/protocols/ftp.py b/src/primaite/simulator/network/protocols/ftp.py index ab277045..91080219 100644 --- a/src/primaite/simulator/network/protocols/ftp.py +++ b/src/primaite/simulator/network/protocols/ftp.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import Any +from typing import Any, Optional from primaite.simulator.network.protocols.packet import DataPacket @@ -48,7 +48,7 @@ class FTPPacket(DataPacket): ftp_command: FTPCommand """Command type of the packet.""" - ftp_command_args: Any + ftp_command_args: Optional[Any] = None """Arguments for command.""" status_code: FTPStatusCode = None diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 8e93df1b..0e8f3dce 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -7,6 +7,7 @@ from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC +from primaite.simulator.system.services.service import ServiceOperatingState class FTPClient(FTPServiceABC): @@ -27,6 +28,15 @@ class FTPClient(FTPServiceABC): super().__init__(**kwargs) self.start() + def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: + # if server is down, return error + if self.operating_state != ServiceOperatingState.RUNNING: + payload.status_code = FTPStatusCode.ERROR + return payload + + # process client specific commands, otherwise call super + return super()._process_ftp_command(payload=payload, session_id=session_id, **kwargs) + def _connect_to_server( self, dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = Port.FTP ) -> bool: @@ -54,12 +64,18 @@ class FTPClient(FTPServiceABC): return payload.status_code == FTPStatusCode.OK def _disconnect_from_server( - self, - ftp_server_ip_address: Optional[IPv4Address] = None, + self, dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = Port.FTP ) -> bool: # send a disconnect request payload to FTP server - # return true if connected successfully else false - self.connected = False + payload: FTPPacket = FTPPacket(ftp_command=FTPCommand.QUIT) + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port + ) + if payload.status_code == FTPStatusCode.OK: + self.connected = False + return True + return False def send_file( self, @@ -72,6 +88,10 @@ class FTPClient(FTPServiceABC): is_reattempt: Optional[bool] = False, ) -> bool: """Send a file to a target IP address.""" + # if service is not running, return error + if self.operating_state != ServiceOperatingState.RUNNING: + self.sys_log.error(f"FTPClient not running for {self.sys_log.hostname}") + return False file_to_transfer: File = self.file_system.get_file(folder_name=src_folder_name, file_name=src_file_name) if not file_to_transfer: self.sys_log.error(f"Unable to send file that does not exist: {src_folder_name}/{src_file_name}") @@ -98,7 +118,7 @@ class FTPClient(FTPServiceABC): ) else: # send STOR request - return self._send_data( + self._send_data( file=file_to_transfer, dest_folder_name=dest_folder_name, dest_file_name=dest_file_name, @@ -106,6 +126,9 @@ class FTPClient(FTPServiceABC): dest_port=dest_port, ) + # send disconnect + return self._disconnect_from_server(dest_ip_address=dest_ip_address, dest_port=dest_port) + def request_file( self, dest_ip_address: IPv4Address, @@ -117,6 +140,10 @@ class FTPClient(FTPServiceABC): is_reattempt: Optional[bool] = False, ) -> bool: """Request a file from a target IP address.""" + # if service is not running, return error + if self.operating_state != ServiceOperatingState.RUNNING: + self.sys_log.error(f"FTPClient not running for {self.sys_log.hostname}") + return False # check if FTP is currently connected to IP self.connected = self._connect_to_server( dest_ip_address=dest_ip_address, @@ -152,6 +179,9 @@ class FTPClient(FTPServiceABC): payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port ) + # send disconnect + self._disconnect_from_server(dest_ip_address=dest_ip_address, dest_port=dest_port) + # the payload should have ok status code if payload.status_code == FTPStatusCode.OK: self.sys_log.info(f"File {src_folder_name}/{src_file_name} found in FTP server.") diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index c575479a..6371d53a 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -1,9 +1,12 @@ -from typing import Any, Optional +from ipaddress import IPv4Address +from typing import Any, Dict, Optional -from primaite.simulator.network.protocols.ftp import FTPPacket +from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.session_manager import Session from primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC +from primaite.simulator.system.services.service import ServiceOperatingState class FTPServer(FTPServiceABC): @@ -17,6 +20,9 @@ class FTPServer(FTPServiceABC): server_password: Optional[str] = None """Password needed to connect to FTP server. Default is None.""" + connections: Dict[str, IPv4Address] = {} + """Current active connections to the FTP server.""" + def __init__(self, **kwargs): kwargs["name"] = "FTPServer" kwargs["port"] = Port.FTP @@ -24,6 +30,37 @@ class FTPServer(FTPServiceABC): super().__init__(**kwargs) self.start() + def _get_session_details(self, session_id: str) -> Session: + """ + Returns the Session object from the given session id. + + :param: session_id: ID of the session that needs details retrieved + """ + return self.software_manager.session_manager.sessions_by_uuid[session_id] + + def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: + # if server is down, return error + if self.operating_state != ServiceOperatingState.RUNNING: + payload.status_code = FTPStatusCode.ERROR + return payload + + # process server specific commands, otherwise call super + if payload.ftp_command == FTPCommand.PORT: + # check that the port is valid + if isinstance(payload.ftp_command_args, Port) and payload.ftp_command_args.value in range(0, 65535): + # return successful connection + session_details = self._get_session_details(session_id) + self.connections[session_id] = session_details.with_ip_address + payload.status_code = FTPStatusCode.OK + return payload + + if payload.ftp_command == FTPCommand.QUIT: + session_details = self._get_session_details(session_id) + self.connections.pop(session_id) + payload.status_code = FTPStatusCode.OK + + return super()._process_ftp_command(payload=payload, session_id=session_id, **kwargs) + def receive(self, payload: Any, session_id: Optional[str] = None, **kwargs) -> bool: """Receives a payload from the SessionManager.""" if not isinstance(payload, FTPPacket): diff --git a/src/primaite/simulator/system/services/ftp/ftp_service.py b/src/primaite/simulator/system/services/ftp/ftp_service.py index 6214c510..a41d647c 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_service.py +++ b/src/primaite/simulator/system/services/ftp/ftp_service.py @@ -17,13 +17,6 @@ class FTPServiceABC(Service, ABC): """ def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: - # handle PORT request - if payload.ftp_command == FTPCommand.PORT: - # check that the port is valid - if isinstance(payload.ftp_command_args, Port) and payload.ftp_command_args.value in range(0, 65535): - # return successful connection - payload.status_code = FTPStatusCode.OK - # handle STOR request if payload.ftp_command == FTPCommand.STOR: # check that the file is created in the computed hosting the FTP server diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py index 64013207..ea563a88 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py @@ -3,6 +3,7 @@ from ipaddress import IPv4Address import pytest from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.ftp.ftp_client import FTPClient @@ -39,3 +40,43 @@ def test_create_ftp_client(ftp_client): assert ftp_client_service.name is "FTPClient" assert ftp_client_service.port is Port.FTP assert ftp_client_service.protocol is IPProtocol.TCP + + +def test_ftp_server_store_file(ftp_server): + """Test to make sure the FTP Server knows how to deal with request responses.""" + assert ftp_server.file_system.get_file(folder_name="downloads", file_name="file.txt") is None + + response: FTPPacket = FTPPacket( + ftp_command=FTPCommand.STOR, + ftp_command_args={ + "dest_folder_name": "downloads", + "dest_file_name": "file.txt", + "file_size": 24, + }, + packet_payload_size=24, + ) + + ftp_server_service: FTPServer = ftp_server.software_manager.software["FTPServer"] + ftp_server_service.receive(response) + + assert ftp_server.file_system.get_file(folder_name="downloads", file_name="file.txt") + + +def test_ftp_client_store_file(ftp_client): + """Test to make sure the FTP Client knows how to deal with request responses.""" + assert ftp_client.file_system.get_file(folder_name="downloads", file_name="file.txt") is None + + response: FTPPacket = FTPPacket( + ftp_command=FTPCommand.STOR, + ftp_command_args={ + "dest_folder_name": "downloads", + "dest_file_name": "file.txt", + "file_size": 24, + }, + packet_payload_size=24, + ) + + ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + ftp_client_service.receive(response) + + assert ftp_client.file_system.get_file(folder_name="downloads", file_name="file.txt") From 2520b67889cdfcc2d01d590005203c492c5f1344 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Mon, 25 Sep 2023 14:31:57 +0100 Subject: [PATCH 188/980] #1916: - Added FTP to changelog - Added FTP to documentation - Added documentation in code - Clean up of methods - prevent repeats of the same code --- CHANGELOG.md | 3 +- .../system/ftp_client_server.rst | 62 ++++++++ .../simulation_components/system/software.rst | 1 + .../system/services/ftp/ftp_client.py | 148 ++++++++++++------ .../system/services/ftp/ftp_server.py | 14 +- .../system/services/ftp/ftp_service.py | 51 ++++-- 6 files changed, 215 insertions(+), 64 deletions(-) create mode 100644 docs/source/simulation_components/system/ftp_client_server.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index d9700f83..7147f82b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,8 @@ SessionManager. 1. Creating a simulation - this notebook explains how to build up a simulation using the Python package. (WIP) - Red Agent Services: - Data Manipulator Bot - A red agent service which sends a payload to a target machine. (By default this payload is a SQL query that breaks a database) -- DNS Services: DNS Client and DNS Server +- DNS Services: `DNSClient` and `DNSServer` +- FTP Services: `FTPClient` and `FTPServer` ## [2.0.0] - 2023-07-26 diff --git a/docs/source/simulation_components/system/ftp_client_server.rst b/docs/source/simulation_components/system/ftp_client_server.rst new file mode 100644 index 00000000..084d4a85 --- /dev/null +++ b/docs/source/simulation_components/system/ftp_client_server.rst @@ -0,0 +1,62 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +FTP Client Server +================= + +FTP Server +---------- +Provides a FTP Client-Server simulation by extending the base Service class. + +Key capabilities +^^^^^^^^^^^^^^^^ + +- Simulates FTP requests and FTPPacket transfer across a network +- Allows the emulation of FTP commands between an FTP client and server: + - STOR: stores a file from client to server + - RETR: retrieves a file from the FTP server +- Leverages the Service base class for install/uninstall, status tracking, etc. + +Usage +^^^^^ +- Install on a Node via the ``SoftwareManager`` to start the FTP server service. +- Service runs on FTP (command) port 21 by default. (TODO: look at in depth implementation of FTP PORT command) + +Implementation +^^^^^^^^^^^^^^ + +- FTP request and responses use a ``FTPPacket`` object +- Extends Service class for integration with ``SoftwareManager``. + +FTP Client +---------- + +The ``FTPClient`` provides a client interface for connecting to the ``FTPServer``. + +Key features +^^^^^^^^^^^^ + +- Connects to the ``FTPServer`` via the ``SoftwareManager``. +- Simulates FTP requests and FTPPacket transfer across a network +- Allows the emulation of FTP commands between an FTP client and server: + - PORT: specifies the port that server should connect to on the client (currently only uses ``Port.FTP``) + - STOR: stores a file from client to server + - RETR: retrieves a file from the FTP server + - QUIT: disconnect from server +- Leverages the Service base class for install/uninstall, status tracking, etc. + +Usage +^^^^^ + +- Install on a Node via the ``SoftwareManager`` to start the FTP client service. +- Service runs on FTP (command) port 21 by default. (TODO: look at in depth implementation of FTP PORT command) +- Execute sending a file to the FTP server with ``send_file`` +- Execute retrieving a file from the FTP server with ``request_file`` + +Implementation +^^^^^^^^^^^^^^ + +- Leverages ``SoftwareManager`` for sending payloads over the network. +- Provides easy interface for Nodes to transfer files between each other. +- Extends base Service class. diff --git a/docs/source/simulation_components/system/software.rst b/docs/source/simulation_components/system/software.rst index 275fdaf9..921dfb9e 100644 --- a/docs/source/simulation_components/system/software.rst +++ b/docs/source/simulation_components/system/software.rst @@ -18,3 +18,4 @@ Contents database_client_server data_manipulation_bot dns_client_server + ftp_client_server diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 0e8f3dce..33fe32be 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -19,7 +19,7 @@ class FTPClient(FTPServiceABC): """ connected: bool = False - """Keeps track of whether or not the FTP client is connected to an FTP server""" + """Keeps track of whether or not the FTP client is connected to an FTP server.""" def __init__(self, **kwargs): kwargs["name"] = "FTPClient" @@ -29,7 +29,15 @@ class FTPClient(FTPServiceABC): self.start() def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: - # if server is down, return error + """ + Process the command in the FTP Packet. + + :param: payload: The FTP Packet to process + :type: payload: FTPPacket + :param: session_id: session ID linked to the FTP Packet. Optional. + :type: session_id: Optional[str] + """ + # if client service is down, return error if self.operating_state != ServiceOperatingState.RUNNING: payload.status_code = FTPStatusCode.ERROR return payload @@ -38,20 +46,27 @@ class FTPClient(FTPServiceABC): return super()._process_ftp_command(payload=payload, session_id=session_id, **kwargs) def _connect_to_server( - self, dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = Port.FTP + self, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = Port.FTP, + is_reattempt: Optional[bool] = False, ) -> bool: """ Connects the client to a given FTP server. :param: dest_ip_address: IP address of the FTP server the client needs to connect to. Optional. - :type: Optional[IPv4Address] + :type: dest_ip_address: Optional[IPv4Address] :param: dest_port: Port of the FTP server the client needs to connect to. Optional. - :type: Optional[Port] - :param: server_password: The password to use when connecting to the FTP server. Optional. - :type: Optional[str] + :type: dest_port: Optional[Port] + :param: is_reattempt: Set to True if attempt to connect to FTP Server has been attempted. Default False. + :type: is_reattempt: Optional[bool] """ - # normally FTP will choose a random port for the transfer, but using the FTP command port will do for now + # make sure the service is running before attempting + if self.operating_state != ServiceOperatingState.RUNNING: + self.sys_log.error(f"FTPClient not running for {self.sys_log.hostname}") + return False + # normally FTP will choose a random port for the transfer, but using the FTP command port will do for now # create FTP packet payload: FTPPacket = FTPPacket( ftp_command=FTPCommand.PORT, @@ -61,11 +76,30 @@ class FTPClient(FTPServiceABC): software_manager.send_payload_to_session_manager( payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port ) - return payload.status_code == FTPStatusCode.OK + + if payload.status_code == FTPStatusCode.OK: + return True + else: + if is_reattempt: + # reattempt failed + return False + else: + # try again + self._connect_to_server(dest_ip_address=dest_ip_address, dest_port=dest_port, is_reattempt=True) def _disconnect_from_server( self, dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = Port.FTP ) -> bool: + """ + Connects the client from a given FTP server. + + :param: dest_ip_address: IP address of the FTP server the client needs to disconnect from. Optional. + :type: dest_ip_address: Optional[IPv4Address] + :param: dest_port: Port of the FTP server the client needs to disconnect from. Optional. + :type: dest_port: Optional[Port] + :param: is_reattempt: Set to True if attempt to disconnect from FTP Server has been attempted. Default False. + :type: is_reattempt: Optional[bool] + """ # send a disconnect request payload to FTP server payload: FTPPacket = FTPPacket(ftp_command=FTPCommand.QUIT) software_manager: SoftwareManager = self.software_manager @@ -85,13 +119,32 @@ class FTPClient(FTPServiceABC): dest_folder_name: str, dest_file_name: str, dest_port: Optional[Port] = Port.FTP, - is_reattempt: Optional[bool] = False, ) -> bool: - """Send a file to a target IP address.""" - # if service is not running, return error - if self.operating_state != ServiceOperatingState.RUNNING: - self.sys_log.error(f"FTPClient not running for {self.sys_log.hostname}") - return False + """ + Send a file to a target IP address. + + The function checks if the file exists in the FTP Client host. + The STOR command is then sent to the FTP Server. + + :param: dest_ip_address: The IP address of the machine that hosts the FTP Server. + :type: dest_ip_address: IPv4Address + + :param: src_folder_name: The name of the folder that contains the file to send to the FTP Server. + :type: src_folder_name: str + + :param: src_file_name: The name of the file to send to the FTP Server. + :type: src_file_name: str + + :param: dest_folder_name: The name of the folder where the file will be stored in the FTP Server. + :type: dest_folder_name: str + + :param: dest_file_name: The name of the file to be saved on the FTP Server. + :type: dest_file_name: str + + :param: dest_port: The open port of the machine that hosts the FTP Server. Default is Port.FTP. + :type: dest_port: Optional[Port] + """ + # check if the file to transfer exists on the client file_to_transfer: File = self.file_system.get_file(folder_name=src_folder_name, file_name=src_file_name) if not file_to_transfer: self.sys_log.error(f"Unable to send file that does not exist: {src_folder_name}/{src_file_name}") @@ -104,18 +157,7 @@ class FTPClient(FTPServiceABC): ) if not self.connected: - if is_reattempt: - return False - - return self.send_file( - src_folder_name=file_to_transfer.folder.name, - src_file_name=file_to_transfer.name, - dest_folder_name=dest_folder_name, - dest_file_name=dest_file_name, - dest_ip_address=dest_ip_address, - dest_port=dest_port, - is_reattempt=True, - ) + return False else: # send STOR request self._send_data( @@ -137,13 +179,30 @@ class FTPClient(FTPServiceABC): dest_folder_name: str, dest_file_name: str, dest_port: Optional[Port] = Port.FTP, - is_reattempt: Optional[bool] = False, ) -> bool: - """Request a file from a target IP address.""" - # if service is not running, return error - if self.operating_state != ServiceOperatingState.RUNNING: - self.sys_log.error(f"FTPClient not running for {self.sys_log.hostname}") - return False + """ + Request a file from a target IP address. + + Sends a RETR command to the FTP Server. + + :param: dest_ip_address: The IP address of the machine that hosts the FTP Server. + :type: dest_ip_address: IPv4Address + + :param: src_folder_name: The name of the folder that contains the file to send to the FTP Server. + :type: src_folder_name: str + + :param: src_file_name: The name of the file to send to the FTP Server. + :type: src_file_name: str + + :param: dest_folder_name: The name of the folder where the file will be stored in the FTP Server. + :type: dest_folder_name: str + + :param: dest_file_name: The name of the file to be saved on the FTP Server. + :type: dest_file_name: str + + :param: dest_port: The open port of the machine that hosts the FTP Server. Default is Port.FTP. + :type: dest_port: Optional[Port] + """ # check if FTP is currently connected to IP self.connected = self._connect_to_server( dest_ip_address=dest_ip_address, @@ -151,18 +210,7 @@ class FTPClient(FTPServiceABC): ) if not self.connected: - if is_reattempt: - return False - - return self.request_file( - src_folder_name=src_folder_name, - src_file_name=src_file_name, - dest_folder_name=dest_folder_name, - dest_file_name=dest_file_name, - dest_ip_address=dest_ip_address, - dest_port=dest_port, - is_reattempt=True, - ) + return False else: # send retrieve request payload: FTPPacket = FTPPacket( @@ -191,7 +239,15 @@ class FTPClient(FTPServiceABC): return False def receive(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> bool: - """Receives a payload from the SessionManager.""" + """ + Receives a payload from the SessionManager. + + :param: payload: FTPPacket payload. + :type: payload: FTPPacket + + :param: session_id: ID of the session. Optional. + :type: session_id: Optional[str] + """ if not isinstance(payload, FTPPacket): self.sys_log.error(f"{payload} is not an FTP packet") return False diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 6371d53a..1d028f0b 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -39,23 +39,31 @@ class FTPServer(FTPServiceABC): return self.software_manager.session_manager.sessions_by_uuid[session_id] def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: - # if server is down, return error + """ + Process the command in the FTP Packet. + + :param: payload: The FTP Packet to process + :type: payload: FTPPacket + :param: session_id: session ID linked to the FTP Packet. Optional. + :type: session_id: Optional[str] + """ + # if server service is down, return error if self.operating_state != ServiceOperatingState.RUNNING: payload.status_code = FTPStatusCode.ERROR return payload + session_details = self._get_session_details(session_id) + # process server specific commands, otherwise call super if payload.ftp_command == FTPCommand.PORT: # check that the port is valid if isinstance(payload.ftp_command_args, Port) and payload.ftp_command_args.value in range(0, 65535): # return successful connection - session_details = self._get_session_details(session_id) self.connections[session_id] = session_details.with_ip_address payload.status_code = FTPStatusCode.OK return payload if payload.ftp_command == FTPCommand.QUIT: - session_details = self._get_session_details(session_id) self.connections.pop(session_id) payload.status_code = FTPStatusCode.OK diff --git a/src/primaite/simulator/system/services/ftp/ftp_service.py b/src/primaite/simulator/system/services/ftp/ftp_service.py index a41d647c..f47b8f64 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_service.py +++ b/src/primaite/simulator/system/services/ftp/ftp_service.py @@ -17,6 +17,14 @@ class FTPServiceABC(Service, ABC): """ def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: + """ + Process the command in the FTP Packet. + + :param: payload: The FTP Packet to process + :type: payload: FTPPacket + :param: session_id: session ID linked to the FTP Packet. Optional. + :type: session_id: Optional[str] + """ # handle STOR request if payload.ftp_command == FTPCommand.STOR: # check that the file is created in the computed hosting the FTP server @@ -24,25 +32,14 @@ class FTPServiceABC(Service, ABC): payload.status_code = FTPStatusCode.OK if payload.ftp_command == FTPCommand.RETR: - # check that the file exists in the FTP Server - file: File = self.file_system.get_file( - folder_name=payload.ftp_command_args["src_folder_name"], - file_name=payload.ftp_command_args["src_file_name"], - ) - if file: + if self._retrieve_data(payload=payload, session_id=session_id): payload.status_code = FTPStatusCode.OK - self._send_data( - file=file, - dest_folder_name=payload.ftp_command_args["dest_folder_name"], - dest_file_name=payload.ftp_command_args["dest_file_name"], - session_id=session_id, - ) return payload def _store_data(self, payload: FTPPacket) -> bool: """ - Handle the transfer of data. + Stores the data in the FTP Service's host machine. :param: payload: The FTP Packet that contains the file data :type: FTPPacket @@ -75,6 +72,27 @@ class FTPServiceABC(Service, ABC): dest_port: Optional[Port] = None, session_id: Optional[str] = None, ) -> bool: + """ + Sends data from the host FTP Service's machine to another FTP Service's host machine. + + :param: file: File to send to the target FTP Service. + :type: file: File + + :param: dest_folder_name: The name of the folder where the file will be stored in the FTP Server. + :type: dest_folder_name: str + + :param: dest_file_name: The name of the file to be saved on the FTP Server. + :type: dest_file_name: str + + :param: dest_ip_address: The IP address of the machine that hosts the FTP Server. + :type: dest_ip_address: Optional[IPv4Address] + + :param: dest_port: The open port of the machine that hosts the FTP Server. Default is Port.FTP. + :type: dest_port: Optional[Port] + + :param: session_id: session ID linked to the FTP Packet. Optional. + :type: session_id: Optional[str] + """ # send STOR request payload: FTPPacket = FTPPacket( ftp_command=FTPCommand.STOR, @@ -106,6 +124,8 @@ class FTPServiceABC(Service, ABC): # find the file file_name = payload.ftp_command_args["src_file_name"] folder_name = payload.ftp_command_args["src_folder_name"] + dest_folder_name = payload.ftp_command_args["dest_folder_name"] + dest_file_name = payload.ftp_command_args["dest_file_name"] retrieved_file: File = self.file_system.get_file(folder_name=folder_name, file_name=file_name) # if file does not exist, return an error @@ -118,7 +138,10 @@ class FTPServiceABC(Service, ABC): else: # send requested data return self._send_data( - file=retrieved_file, dest_file_name=file_name, dest_folder_name=folder_name, session_id=session_id + file=retrieved_file, + dest_file_name=dest_file_name, + dest_folder_name=dest_folder_name, + session_id=session_id, ) except Exception as e: self.sys_log.error(f"Unable to retrieve file from {self.sys_log.hostname}: {e}") From 0140fe7c48f9755565a941783f1d98efa4ad8749 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Mon, 25 Sep 2023 15:59:31 +0100 Subject: [PATCH 189/980] #1916: fix a problem with process_ftp_command method --- src/primaite/simulator/system/services/ftp/ftp_server.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 1d028f0b..83c883f1 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -52,7 +52,8 @@ class FTPServer(FTPServiceABC): payload.status_code = FTPStatusCode.ERROR return payload - session_details = self._get_session_details(session_id) + if session_id: + session_details = self._get_session_details(session_id) # process server specific commands, otherwise call super if payload.ftp_command == FTPCommand.PORT: From 9d4e41435d32e757c13990aebd480c82df71b56b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 25 Sep 2023 16:04:04 +0100 Subject: [PATCH 190/980] End-of-day commit --- example_config.yaml | 276 +++++++++++ src/primaite/game/actor/interface.py | 7 +- src/primaite/game/actor/observations.py | 456 +++++++++++++++--- .../simulator/network/hardware/base.py | 8 +- .../network/hardware/nodes/router.py | 21 +- .../simulator/system/services/service.py | 14 +- .../game_layer/test_observations.py | 20 + 7 files changed, 722 insertions(+), 80 deletions(-) create mode 100644 example_config.yaml create mode 100644 tests/integration_tests/game_layer/test_observations.py diff --git a/example_config.yaml b/example_config.yaml new file mode 100644 index 00000000..6c02031a --- /dev/null +++ b/example_config.yaml @@ -0,0 +1,276 @@ +training_config: + rl_framework: SB3 + rl_algo: PPO + n_learn_steps: 128 + n_learn_episodes: 1000 + +game_config: + ports: + - ARP + - DNS + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + + agents: + - ref: client_1_green_user + team: GREEN + team: SCRIPTED_GREEN_ + observation_space: + ... + action_space: + ... + reward_function: + - type: null_reward + # node_ref: client_1 + # service: WebBrowser + # pol: + # - step: 1 + # action: START + + - ref: client_1_data_manipulation_red_bot + team: RED + type: SCRIPTED_RED_ + observation_space: + network: + nodes: + - ref: client_1 + - logon_status + - operating_status + services: + - ref: data_manipulation_bot + - operating_status + - health_status + folders: + files: {} + nics: {} + + action_space: + actions: + - DO_NOTHING + network: + nodes: + - ref: client_1 + actions: + - SCAN + - LOGON + - LOGOFF + services: + - ref: data_manipulation_bot + actions: + - type: COMPROMISE + execution_definition: + server_ip: 192.168.1.14 + payload: "DROP TABLE IF EXISTS user;" + success_rate: 80% + folders: + files: {} + reward_function: null + options: # options specific to this particular agent type, basically args of __init__(self) + start_step: 25 + frequency: 20 + variance: 5 + + + + + - ref: defender + team: blue + type: GATE_RL_AGENT + observation_space: + network: + nodes: + - ref: + action_space: + ... + reward_function: + ... + + + + + +simulation: + network: + nodes: + + - ref: router_1 + type: router + hostname: router_1 + num_ports: 5 + ports: + 1: + ip_address: 192.168.1.1 + subnet_mask: 255.255.255.0 + 2: + ip_address: 192.168.1.1 + subnet_mask: 255.255.255.0 + acl: + 0: + action: PERMIT + src_port: POSTGRES_SERVER + dst_port: POSTGRES_SERVER + 1: + action: PERMIT + src_port: DNS + dst_port: DNS + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + + - ref: switch_1 + type: swtich + hostname: switch_1 + num_ports: 8 + + - ref: switch_2 + type: switch + hostname: switch_2 + num_ports: 8 + + - ref: domain_controller + type: server + hostname: domain_controller + ip_address: 192.168.1.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + services: + - ref: domain_controller_dns_server + type: dns_server + options: + domain_mapping: + - arcd.com: 192.168.1.12 # web server + + + - ref: web_server + type: server + hostname: web_server + ip_address: 192.168.1.12 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.10 + dns_server: 192.168.1.10 + services: + - ref: web_server_database_client + type: database_client + options: + db_server_ip: 192.168.1.14 + + - ref: database_server + type: server + hostname: database_server + ip_address: 192.168.1.14 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - ref: database_service + type: database_service + + + - ref: backup_server + type: node + hostname: backup_server + ip_address: 192.168.1.16 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - ref: backup_service + type: database_backup + + - ref: security_suite + type: server + hostname: security_suite + ip_address: 192.168.1.110 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + nics: + 2: + ip_address: 192.168.10.110 + subnet_mask: 255.255.255.0 + + + - ref: client_1 + type: computer + hostname: client_1 + ip_address: 192.168.10.21. + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + services: + - ref: data_manipulation_bot + type: data_manipulation_bot + - ref: client_1_dns_client + type: dns_client + + - ref: client_2 + type: computer + hostname: client_2 + ip_address: 192.168.10.22 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + services: + - ref: web_browser + type: web_browser + - ref: client_2_dns_client + type: dns_client + + + links: + - ref: router_1___switch_1 + endpoint_a: router_1 + endpoint_a_port: 1 + endpoint_b: switch_1 + endpoint_b_port: 8 + - ref: router_1___switch_2 + endpoint_a: router_1 + endpoint_a_port: 2 + endpoint_b: switch_2 + endpoint_b_port: 8 + - ref: switch_1___domain_controller + endpoint_a: switch_1 + endpoint_a_port: 1 + endpoint_b: domain_controller + endpoint_b_port: 1 + - ref: switch_1___web_server + endpoint_a: switch_1 + endpoint_a_port: 2 + endpoint_b: web_server + endpoint_b_port: 1 + - ref: switch_1___database_server + endpoint_a: switch_1 + endpoint_a_port: 3 + endpoint_b: database_server + endpoint_b_port: 1 + - ref: switch_1___backup_server + endpoint_a: switch_1 + endpoint_a_port: 4 + endpoint_b: backup_server + endpoint_b_port: 1 + - ref: switch_1___security_suite + endpoint_a: switch_1 + endpoint_a_port: 7 + endpoint_b: security_suite + endpoint_b_port: 1 + - ref: switch_2___client_1 + endpoint_a: switch_2 + endpoint_a_port: 1 + endpoint_b: client_1 + endpoint_b_port: 1 + - ref: switch_2___client_2 + endpoint_a: switch_2 + endpoint_a_port: 2 + endpoint_b: client_2 + endpoint_b_port: 1 + - ref: switch_2___security_suite + endpoint_a: switch_2 + endpoint_a_port: 7 + endpoint_b: security_suite + endpoint_b_port: 2 diff --git a/src/primaite/game/actor/interface.py b/src/primaite/game/actor/interface.py index 1fe43a32..d1245e71 100644 --- a/src/primaite/game/actor/interface.py +++ b/src/primaite/game/actor/interface.py @@ -11,10 +11,13 @@ from primaite.game.actor.observations import ObservationSpace from primaite.game.actor.rewards import RewardFunction -class AbstractActor(BaseModel): +class AbstractActor(ABC): """Base class for scripted and RL agents.""" - ... + def __init__(self) -> None: + self.action_space = ActionSpace + self.observation_space = ObservationSpace + self.reward_function = RewardFunction class AbstractScriptedActor(AbstractActor): diff --git a/src/primaite/game/actor/observations.py b/src/primaite/game/actor/observations.py index 7303b07b..4d4796e1 100644 --- a/src/primaite/game/actor/observations.py +++ b/src/primaite/game/actor/observations.py @@ -1,9 +1,16 @@ from abc import ABC, abstractmethod -from typing import Any, Dict, Hashable, List - -from pydantic import BaseModel +from typing import Any, Dict, Hashable, List, Optional from gym import spaces +from pydantic import BaseModel + +from primaite.simulator.sim_container import Simulation + +NOT_PRESENT_IN_STATE = object() +""" +Need an object to return when the sim state does not contain a requested value. Cannot use None because sometimes +the thing requested in the state could equal None. This NOT_PRESENT_IN_STATE is a sentinel for this purpose. +""" def access_from_nested_dict(dictionary: Dict, keys: List[Hashable]) -> Any: @@ -20,19 +27,17 @@ def access_from_nested_dict(dictionary: Dict, keys: List[Hashable]) -> Any: :return: The value in the dictionary :rtype: Any """ - if not keys: + if len(keys) == 0: return dictionary k = keys.pop(0) - try: - return access_from_nested_dict(dictionary[k], keys) - except (TypeError, KeyError): - raise KeyError(f"Cannot find requested key `{k}` in nested dictionary") + if k not in dictionary: + return NOT_PRESENT_IN_STATE + return access_from_nested_dict(dictionary[k], keys) -class AbstractObservation(BaseModel): - +class AbstractObservation(ABC): @abstractmethod - def __call__(self, state: Dict) -> Any: + def observe(self, state: Dict) -> Any: """_summary_ :param state: _description_ @@ -41,7 +46,6 @@ class AbstractObservation(BaseModel): :rtype: Any """ ... - # receive state dict @property @abstractmethod @@ -51,72 +55,396 @@ class AbstractObservation(BaseModel): class FileObservation(AbstractObservation): - where: List[str] - """Store information about where in the simulation state dictionary to find the relevatn information.""" + def __init__(self, where: List[str] = []) -> None: + """ + _summary_ - def __call__(self, state: Dict) -> Dict: + :param where: Store information about where in the simulation state dictionary to find the relevatn information. + Optional. If None, this corresponds that the file does not exist and the observation will be populated with + zeroes. + + A typical location for a file looks like this: + ['network','nodes',,'file_system', 'folders',,'files',] + :type where: Optional[List[str]] + """ + super().__init__() + self.where: List[str] = where + self.default_observation: spaces.Space = {"health_status": 0} + "Default observation is what should be returned when the file doesn't exist, e.g. after it has been deleted." + + def observe(self, state: Dict) -> Dict: + if not self.where: + return self.default_observation file_state = access_from_nested_dict(state, self.where) - observation = {'health_status':file_state['health_status']} - return observation + if file_state is NOT_PRESENT_IN_STATE: + return self.default_observation + return {"health_status": file_state["health_status"]} @property def space(self) -> spaces.Space: - return spaces.Dict({'health_status':spaces.Discrete(6)}) + return spaces.Dict({"health_status": spaces.Discrete(6)}) + + +class ServiceObservation(AbstractObservation): + default_observation: spaces.Space = {"operating_status": 0, "health_status": 0} + "Default observation is what should be returned when the service doesn't exist." + + def __init__(self, where: List[str] = []) -> None: + """ + :param where: Store information about where in the simulation state dictionary to find the relevant information. + Optional. If None, this corresponds that the file does not exist and the observation will be populated with + zeroes. + + A typical location for a service looks like this: + `['network','nodes',,'servics', ]` + :type where: Optional[List[str]] + """ + super().__init__() + self.where: List[str] = where + + def observe(self, state: Dict) -> Dict: + if not self.where: + return self.default_observation + + service_state = access_from_nested_dict(state, self.where) + if service_state is NOT_PRESENT_IN_STATE: + return self.default_observation + return {"operating_status": service_state["operating_status"], "health_status": service_state["health_status"]} + + @property + def space(self) -> spaces.Space: + return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(6)}) + + +class LinkObservation(AbstractObservation): + default_observation: spaces.Space = {"protocols": {"all": {"load": 0}}} + "Default observation is what should be returned when the link doesn't exist." + + def __init__(self, where: List[str] = []) -> None: + """ + :param where: Store information about where in the simulation state dictionary to find the relevant information. + Optional. If None, this corresponds that the file does not exist and the observation will be populated with + zeroes. + + A typical location for a service looks like this: + `['network','nodes',,'servics', ]` + :type where: Optional[List[str]] + """ + super().__init__() + self.where: List[str] = where + + def observe(self, state: Dict) -> Dict: + if not self.where: + return self.default_observation + + link_state = access_from_nested_dict(state, self.where) + if link_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + bandwidth = link_state["bandwidth"] + load = link_state["current_load"] + utilisation_fraction = load / bandwidth + # 0 is UNUSED, 1 is 0%-10%. 2 is 10%-20%. 3 is 20%-30%. And so on... 10 is exactly 100% + utilisation_category = int(utilisation_fraction * 10) + 1 + + # TODO: once the links support separte load per protocol, this needs amendment to reflect that. + return {"protocols": {"all": {"load": utilisation_category}}} + + @property + def space(self) -> spaces.Space: + return spaces.Dict({"protocols": spaces.Dict({"all": spaces.Dict({"load": spaces.Discrete(11)})})}) + + +class FolderObservation(AbstractObservation): + def __init__(self, where: List[str] = [], files: List[FileObservation] = []) -> None: + """Initialise folder Observation, including files inside of the folder. + + :param where: Where in the simulation state dictionary to find the relevant information for this folder. + A typical location for a file looks like this: + ['network','nodes',,'file_system', 'folders',] + :type where: Optional[List[str]] + :param max_files: As size of the space must remain static, define max files that can be in this folder + , defaults to 5 + :type max_files: int, optional + :param file_positions: Defines the positioning within the observation space of particular files. This ensures + that even if new files are created, the existing files will always occupy the same space in the observation + space. The keys must be between 1 and max_files. Providing file_positions will reserve a spot in the + observation space for a file with that name, even if it's temporarily deleted, if it reappears with the same + name, it will take the position defined in this dict. Defaults to {} + :type file_positions: Dict[int, str], optional + """ + super().__init__() + + self.where: List[str] = where + + self.files: List[FileObservation] = files + + self.default_observation = { + "health_status": 0, + "FILES": {i + 1: f.default_observation for i, f in enumerate(self.files)}, + } + + def observe(self, state: Dict) -> Dict: + if not self.where: + return self.default_observation + folder_state = access_from_nested_dict(state, self.where) + if folder_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + health_status = folder_state["health_status"] + + obs = {} + + obs["health_status"] = health_status + obs["FILES"] = {i + 1: file.observe(state) for i, file in enumerate(self.files)} + + return obs + + @property + def space(self) -> spaces.Space: + return spaces.Dict( + { + "health_status": spaces.Discrete(6), + "FILES": spaces.Dict({i + 1: f.space for i, f in enumerate(self.files)}), + } + ) + + +class NicObservation(AbstractObservation): + default_observation: spaces.Space = {"nic_status": 0} + + def __init__(self, where: List[str] = []) -> None: + super.__init__() + self.where: List[str] = where + + def observe(self, state: Dict) -> Dict: + if not self.where: + return self.default_observation + nic_state = access_from_nested_dict(state, self.where) + if nic_state is NOT_PRESENT_IN_STATE: + return self.default_observation + else: + return {"nic_status": 1 if nic_state["enabled"] else 2} + + @property + def space(self) -> spaces.Space: + return spaces.Dict({"nic_status": spaces.Discrete(3)}) + + +class NodeObservation(AbstractObservation): + def __init__( + self, + where: List[str] = [], + services: List[ServiceObservation] = [], + folders: List[FolderObservation] = [], + nics: List[NicObservation] = [], + ) -> None: + """ + Configurable observation for a node in the simulation. + + :param where: Where in the simulation state dictionary for find relevant information for this observation. + A typical location for a node looks like this: + ['network','nodes',]. If empty list, a default null observation will be output, defaults to [] + :type where: List[str], optional + :param services: Mapping between position in observation space and service UUID, defaults to {} + :type services: Dict[int,str], optional + :param max_services: Max number of services that can be presented in observation space for this node, defaults to 2 + :type max_services: int, optional + :param folders: Mapping between position in observation space and folder name, defaults to {} + :type folders: Dict[int,str], optional + :param max_folders: Max number of folders in this node's obs space, defaults to 2 + :type max_folders: int, optional + :param nics: Mapping between position in observation space and NIC UUID, defaults to {} + :type nics: Dict[int,str], optional + :param max_nics: Max number of NICS in this node's obs space, defaults to 5 + :type max_nics: int, optional + """ + super.__init__() + self.where: List[str] = where + + self.services: List[ServiceObservation] = services + self.folders: List[FolderObservation] = folders + self.nics: List[NicObservation] = nics + + self.default_observation: Dict = { + "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, + "FOLDERS": {i + 1: f.default_observation for i, f in enumerate(self.folders)}, + "NICS": {i + 1: n.default_observation for i, n in enumerate(self.nics)}, + "operating_status": 0, + } + + def observe(self, state: Dict) -> Dict: + if not self.where: + return self.default_observation + + node_state = access_from_nested_dict(state, self.where) + if node_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + obs = {} + + obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} + obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} + obs["operating_status"] = node_state["operating_state"] + obs["NICS"] = {i + 1: nic.observe(state) for i, nic in enumerate(self.nics)} + + return obs + + @property + def space(self) -> spaces.Space: + return spaces.Dict( + { + "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), + "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), + "operating_status": spaces.Discrete(0), + "NICS": spaces.Dict({i + 1: nic.space for i, nic in enumerate(self.nics)}), + } + ) + + +class AclObservation(AbstractObservation): + # TODO: should where be optional, and we can use where=None to pad the observation space? + # definitely the current approach does not support tracking files that aren't specified by name, for example + # if a file is created at runtime, we have currently got no way of telling the observation space to track it. + # this needs adding, but not for the MVP. + def __init__( + self, nodes: List[str], ports: List[int], protocols: list[str], where: List[str] = [], num_rules: int = 10 + ) -> None: + super().__init__() + self.where: List[str] = where + self.num_rules: int = num_rules + self.node_to_id: Dict[str, int] = {node: i + 1 for i, node in enumerate(nodes)} + "List of node IP addresses, order in this list determines how they are converted to an ID" + self.port_to_id: Dict[int, int] = {port: i + 1 for i, port in enumerate(ports)} + "List of ports which are part of the game that define the ordering when converting to an ID" + self.protocol_to_id: Dict[str, int] = {protocol: i + 1 for i, protocol in enumerate(protocols)} + "List of protocols which are part of the game, defines ordering when converting to an ID" + self.default_observation: spaces.Space = spaces.Dict( + { + "RULES": spaces.Dict( + { + i + + 1: spaces.Dict( + { + "position": i, + "permission": 0, + "source_node_id": 0, + "source_port": 0, + "dest_node_id": 0, + "dest_port": 0, + "protocol": 0, + } + ) + for i in range(self.num_rules) + } + ) + } + ) + + def observe(self, state: Dict) -> Dict: + if not self.where: + return self.default_observation + acl_state: Dict = access_from_nested_dict(state, self.where) + if acl_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + obs = {} + obs["RULES"] = {} + for i, rule_state in acl_state.items(): + if rule_state is None: + obs["RULES"][i + 1] = { + "position": i, + "permission": 0, + "source_node_id": 0, + "source_port": 0, + "dest_node_id": 0, + "dest_port": 0, + "protocol": 0, + } + else: + obs["RULES"][i + 1] = { + "position": i, + "permission": rule_state["action"], + "source_node_id": self.node_to_id[rule_state["src_ip_address"]], + "source_port": self.port_to_id[rule_state["src_port"]], + "dest_node_id": self.node_to_id[rule_state["dst_ip_address"]], + "dest_port": self.port_to_id[rule_state["dst_port"]], + "protocol": self.protocol_to_id[rule_state["protocol"]], + } + return obs + + @property + def space(self) -> spaces.Space: + return spaces.Dict( + { + "RULE": spaces.Dict( + { + i + + 1: spaces.Dict( + { + "position": spaces.Discrete(self.num_rules), + "permission": spaces.Discrete(3), + "source_node_id": spaces.Discrete(len(self.nodes) + 1), + "source_port": spaces.Discrete(len(self.ports) + 1), + "dest_node_id": spaces.Discrete(len(self.nodes) + 1), + "dest_port": spaces.Discrete(len(self.ports) + 1), + "protocol": spaces.Discrete(len(self.protocols) + 1), + } + ) + for i in range(self.num_rules) + } + ) + } + ) + + +class ICSObservation(AbstractObservation): + def observe(self, state: Dict) -> Any: + return 0 + + @property + def space(self) -> spaces.Space: + return spaces.Discrete(1) class ObservationSpace: - """Manage the observations of an Actor.""" + """ + Manage the observations of an Actor. + + The observation space has the purpose of: + 1. Reading the outputted state from the PrimAITE Simulation. + 2. Selecting parts of the simulation state that are requested by the simulation config + 3. Formatting this information so an actor can use it to make decisions. + """ ... + # what this class does: # keep a list of observations # create observations for an actor from the config + def __init__( + self, + simulation: Simulation, + nodes: List[NodeObservation] = [], + links: List[LinkObservation] = [], + acl: Optional[AclObservation] = None, + ics: Optional[ICSObservation] = None, + ) -> None: + self.simulation: Simulation = simulation + self.parts: Dict[str, AbstractObservation] = {} + self.nodes: List[NodeObservation] = nodes + self.links: List[LinkObservation] = links + self.acl: Optional[AclObservation] = acl + self.ics: Optional[ICSObservation] = ics -# Example YAML file for agent observation space -""" -arcd_gate: - rl_framework: SB3 - rl_algo: PPO - n_learn_steps: 128 - n_learn_episodes: 1000 + def observe(self) -> None: + ... -game_layer: - agents: - - ref: client_1_green_user - type: GREEN - node_ref: client_1 - service: WebBrowser - pol: - - step: 1 - action: START + @property + def space(self) -> None: + ... - - ref: client_1_data_manip_red_bot - node_ref: client_1 - service: DataManipulationBot - execution_definition: - - server_ip_address: 192.168.1.10 - - server_password: - - payload: 'ATTACK' - - pol: - - step: 75 - action: EXECUTE - - - - -simulation: - nodes: - - ref: client_1 - hostname: client_1 - node_type: Computer - ip_address: 192.168.10.100 - services: - - name: DataManipulationBot - links: - endpoint_a: - endpoint_b: 1524552-fgfg4147gdh-25gh4gd -rewards: - -""" + @classmethod + def from_config(self) -> None: + ... diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index a14d6a6d..f5ba8444 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -855,14 +855,14 @@ class ICMP: class NodeOperatingState(Enum): """Enumeration of Node Operating States.""" - OFF = 0 - "The node is powered off." ON = 1 "The node is powered on." - SHUTTING_DOWN = 2 - "The node is in the process of shutting down." + OFF = 2 + "The node is powered off." BOOTING = 3 "The node is in the process of booting up." + SHUTTING_DOWN = 4 + "The node is in the process of shutting down." class Node(SimComponent): diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 53b9b176..7870caab 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -58,7 +58,14 @@ class ACLRule(SimComponent): :return: A dictionary representing the current state. """ - pass + state = super().describe_state() + state["action"] = self.action.value + state["protocol"] = self.protocol.value + state["src_ip_address"] = self.src_ip_address + state["src_port"] = self.src_port.value + state["dst_ip_address"] = self.dst_ip_address + state["dst_port"] = self.dst_port.value + return state class AccessControlList(SimComponent): @@ -123,7 +130,12 @@ class AccessControlList(SimComponent): :return: A dictionary representing the current state. """ - pass + state = super().describe_state() + state["implicit_action"] = self.implicit_action.value + state["implicit_rule"] = self.implicit_rule.describe_state() + state["max_acl_rules"] = self.max_acl_rules + state["acl"] = {i: r.describe_state() if isinstance(r, ACLRule) else None for i, r in enumerate(self._acl)} + return state @property def acl(self) -> List[Optional[ACLRule]]: @@ -648,7 +660,10 @@ class Router(Node): :return: A dictionary representing the current state. """ - pass + state = super().describe_state() + state["num_ports"] = (self.num_ports,) + state["acl"] = (self.acl.describe_state(),) + return state def route_frame(self, frame: Frame, from_nic: NIC, re_attempt: bool = False) -> None: """ diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 20b92027..fb12fc3d 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -15,14 +15,14 @@ class ServiceOperatingState(Enum): "The service is currently running." STOPPED = 2 "The service is not running." - INSTALLING = 3 - "The service is being installed or updated." - RESTARTING = 4 - "The service is in the process of restarting." - PAUSED = 5 + PAUSED = 3 "The service is temporarily paused." - DISABLED = 6 + DISABLED = 4 "The service is disabled and cannot be started." + INSTALLING = 5 + "The service is being installed or updated." + RESTARTING = 6 + "The service is in the process of restarting." class Service(IOSoftware): @@ -60,7 +60,7 @@ class Service(IOSoftware): :rtype: Dict """ state = super().describe_state() - state.update({"operating_state": self.operating_state.name}) + state.update({"operating_state": self.operating_state.value}) return state def reset_component_for_episode(self, episode: int): diff --git a/tests/integration_tests/game_layer/test_observations.py b/tests/integration_tests/game_layer/test_observations.py new file mode 100644 index 00000000..4f778f78 --- /dev/null +++ b/tests/integration_tests/game_layer/test_observations.py @@ -0,0 +1,20 @@ +from gym import spaces + +from primaite.game.actor.observations import FileObservation +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.sim_container import Simulation + + +def test_file_observation(): + sim = Simulation() + pc = Computer(hostname="beep", ip_address="123.123.123.123", subnet_mask="255.255.255.0") + sim.network.add_node(pc) + f = pc.file_system.create_file(file_name="dog.png") + + state = sim.describe_state() + + dog_file_obs = FileObservation( + where=["network", "nodes", pc.uuid, "file_system", "folders", "root", "files", "dog.png"] + ) + assert dog_file_obs(state) == {"health_status": 1} + assert dog_file_obs.space == spaces.Dict({"health_status": spaces.Discrete(6)}) From 493014ca19beec127689aaa9822a2b3719b4905e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 25 Sep 2023 17:57:47 +0100 Subject: [PATCH 191/980] draft yaml parser --- example_config.yaml | 101 +++++++++++------- sandbox.ipynb | 250 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 279 insertions(+), 72 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index 6c02031a..f0957718 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -17,17 +17,26 @@ game_config: - ref: client_1_green_user team: GREEN team: SCRIPTED_GREEN_ - observation_space: - ... + observation_space: null action_space: - ... - reward_function: - - type: null_reward - # node_ref: client_1 - # service: WebBrowser - # pol: - # - step: 1 - # action: START + actions: + - type: DONOTHING + nodes: + - ref: client_2 + actions: + - type: LOGON + - type: LOGOFF + applications: + - ref: client_2_web_browser + actions: + - type: EXECUTE + execution_definition: + target_address: arcd.com + reward_function: null + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 - ref: client_1_data_manipulation_red_bot team: RED @@ -36,38 +45,37 @@ game_config: network: nodes: - ref: client_1 + observations: - logon_status - operating_status services: - ref: data_manipulation_bot + observations: - operating_status - health_status - folders: - files: {} - nics: {} - + folders: {} action_space: actions: - - DO_NOTHING + - type: DO_NOTHING network: nodes: - - ref: client_1 + - ref: client_1 + actions: + - type: SCAN + - type: LOGON + - type: LOGOFF + services: + - ref: data_manipulation_bot actions: - - SCAN - - LOGON - - LOGOFF - services: - - ref: data_manipulation_bot - actions: - - type: COMPROMISE - execution_definition: - server_ip: 192.168.1.14 - payload: "DROP TABLE IF EXISTS user;" - success_rate: 80% - folders: - files: {} + - type: COMPROMISE + execution_definition: + server_ip: 192.168.1.14 + payload: "DROP TABLE IF EXISTS user;" + success_rate: 80% + folders: + files: {} reward_function: null - options: # options specific to this particular agent type, basically args of __init__(self) + agent_settings: # options specific to this particular agent type, basically args of __init__(self) start_step: 25 frequency: 20 variance: 5 @@ -81,11 +89,32 @@ game_config: observation_space: network: nodes: - - ref: + - ref: router_1 #TODO: more sub-options here + - ref: switch_1 + - ref: switch_2 + - ref: domain_controller + - ref: web_server + - ref: database_server + - ref: backup_server + - ref: security_suite + - ref: client_1 + - ref: client_2 + links: + - ref: ... # + acl: ... # + ics: ... # + + action_space: - ... + actions: + - type: DO_NOTHING + network: + nodes: + - ref: router_1 reward_function: - ... + # ... + agent_settings: + # ... @@ -173,7 +202,7 @@ simulation: - ref: backup_server - type: node + type: server hostname: backup_server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 @@ -199,7 +228,7 @@ simulation: - ref: client_1 type: computer hostname: client_1 - ip_address: 192.168.10.21. + ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 @@ -217,7 +246,7 @@ simulation: default_gateway: 192.168.10.1 dns_server: 192.168.1.10 services: - - ref: web_browser + - ref: client_2_web_browser type: web_browser - ref: client_2_dns_client type: dns_client diff --git a/sandbox.ipynb b/sandbox.ipynb index 06e37664..91edb829 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -1,14 +1,31 @@ { "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext autoreload\n", + "%autoreload 2" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "import yaml" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "from primaite.simulator.network.networks import arcd_uc2_network\n", - "%load_ext autoreload\n", - "%autoreload 2" + "from primaite.simulator.network.networks import arcd_uc2_network\n" ] }, { @@ -62,31 +79,13 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-09-21 10:41:35,339: Added node f03fec1b-927d-4d5a-8de9-1ef426052932 to Network f7400348-31e5-440e-8eb5-42366326d9d1\n" - ] - }, - { - "data": { - "text/plain": [ - "{'health_status': 1}" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "from primaite.simulator.sim_container import Simulation\n", "from primaite.simulator.network.hardware.nodes.computer import Computer\n", - "from primaite.game.actor.observations import FileObservation\n", + "from primaite.game.actor.observations import FileObservation, FolderObservation\n", "\n", "sim = Simulation()\n", "pc = Computer(hostname=\"beep\", ip_address=\"123.123.123.123\", subnet_mask=\"255.255.255.0\")\n", @@ -96,28 +95,207 @@ "state = sim.describe_state()\n", "\n", "dog_file_obs = FileObservation(where=['network','nodes',pc.uuid,'file_system', 'folders','root','files','dog.png'])\n", - "o = dog_file_obs(state)\n", - "o" + "root_folder_obs = FolderObservation(where=['network','nodes',pc.uuid,'file_system', 'folders','root'],files=[dog_file_obs])\n", + "print(dog_file_obs(state))\n", + "print(root_folder_obs(state))" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "dog_file_obs.space" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "root_folder_obs.space" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "state" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import yaml" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open('example_config.yaml', 'r') as file:\n", + " conf = yaml.safe_load(file)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "conf['simulation']" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "import yaml\n", + "from primaite.simulator.sim_container import Simulation\n", + "from primaite.simulator.network.hardware.nodes.computer import Computer\n", + "from primaite.simulator.network.hardware.nodes.server import Server\n", + "from primaite.simulator.network.hardware.nodes.switch import Switch\n", + "from primaite.simulator.network.hardware.nodes.router import Router\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 33, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "Dict(health_status:Discrete(6))" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-09-25 17:38:39,385: Added node b5486651-1c6f-449a-8019-6a3641cfb998 to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n", + "2023-09-25 17:38:39,391: Added node 1533c2f7-389e-4e03-95b3-9cf059086490 to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n", + "2023-09-25 17:38:39,395: Added node 6b6c3b24-61d4-46ac-9364-11d726e50ccb to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n", + "2023-09-25 17:38:39,398: Added node a0bee8d0-2ab8-4e29-9a2c-23c6757b240c to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n", + "2023-09-25 17:38:39,401: Added node 7cb2c102-62ba-4859-94f2-5d724de38733 to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n", + "2023-09-25 17:38:39,403: Added node bec38db7-520e-4044-93db-08308278d66f to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n", + "2023-09-25 17:38:39,407: Added node ae0c2253-3ec8-48c3-b5d2-0b37c19c885d to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "3\n", + "3\n" + ] } ], "source": [ - "dog_file_obs.space" + "# import yaml\n", + "\n", + "from primaite.simulator.network.hardware.nodes.router import ACLAction\n", + "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", + "from primaite.simulator.network.transmission.transport_layer import Port\n", + "\n", + "\n", + "class PrimaiteSession:\n", + "\n", + " def __init__(self):\n", + " self.simulation: Simulation\n", + " self.agents = []\n", + "\n", + " @classmethod\n", + " def from_config(cls, cfg_path):\n", + " ref_to_uuid = {}\n", + "\n", + " game = cls()\n", + " with open(cfg_path, 'r') as file:\n", + " conf = yaml.safe_load(file)\n", + " \n", + " #1. create nodes \n", + " sim = Simulation()\n", + " net = sim.network\n", + " nodes_cfg = conf['simulation']['network']['nodes']\n", + " links_cfg = conf['simulation']['network']['links']\n", + " for node_cfg in nodes_cfg:\n", + " ref = node_cfg['ref']\n", + " n_type = node_cfg['type']\n", + " if n_type == 'computer':\n", + " new_node = Computer(hostname = node_cfg['hostname'], \n", + " ip_address = node_cfg['ip_address'], \n", + " subnet_mask = node_cfg['subnet_mask'], \n", + " default_gateway = node_cfg['default_gateway'],\n", + " dns_server = node_cfg['dns_server'])\n", + " elif n_type == 'server':\n", + " new_node = Server(hostname = node_cfg['hostname'], \n", + " ip_address = node_cfg['ip_address'], \n", + " subnet_mask = node_cfg['subnet_mask'], \n", + " default_gateway = node_cfg['default_gateway'],\n", + " dns_server = node_cfg.get('dns_server'))\n", + " elif n_type == 'switch':\n", + " new_node = Switch(hostname = node_cfg['hostname'],\n", + " num_ports = node_cfg.get('num_ports'))\n", + " elif n_type == 'router':\n", + " new_node = Router(hostname=node_cfg['hostname'],\n", + " num_ports = node_cfg.get('num_ports'))\n", + " if 'ports' in node_cfg:\n", + " for port_num, port_cfg in node_cfg['ports'].items():\n", + " new_node.configure_port(port=port_num, \n", + " ip_address=port_cfg['ip_address'],\n", + " subnet_mask=port_cfg['subnet_mask'])\n", + " if 'acl' in node_cfg:\n", + " for r_num, r_cfg in node_cfg['acl'].items():\n", + " new_node.acl.add_rule(\n", + " action = ACLAction[r_cfg['action']],\n", + " src_port = Port[r_cfg.get('port')],\n", + " dst_port = Port[r_cfg.get('port')],\n", + " protocol = IPProtocol[r_cfg.get('protocol')],\n", + " src_ip = r_cfg.get('ip_address'),\n", + " dst_ip = r_cfg.get('ip_address'),\n", + " position = r_num\n", + " )\n", + "\n", + "\n", + " try:\n", + " net.add_node(new_node)\n", + " ref_to_uuid[ref] = new_node.uuid\n", + " except BaseException:\n", + " print(3)\n", + "\n", + "\n", + " #2. start/setup simulation objects\n", + " #3. create agents\n", + " #4. set up agents' actions and observation spaces.\n", + " game.simulation = sim\n", + " return game\n", + "\n", + "s = PrimaiteSession.from_config('example_config.yaml')\n", + "# print(s.simulation.describe_state())" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'uuid': 'ceeb8791-b140-43d0-b59e-c3c3f533309b', 'network': {'uuid': 'ff176601-4e1d-4f89-8db4-33c0598ee105', 'nodes': {'6b9afe70-913b-40ce-9cee-1ee3648e43ce': {'uuid': '6b9afe70-913b-40ce-9cee-1ee3648e43ce', 'hostname': 'client_1', 'operating_state': 2, 'NICs': {'108c797d-32ca-4e93-8476-6b13cda6cf37': {'uuid': '108c797d-32ca-4e93-8476-6b13cda6cf37', 'ip_adress': '192.168.10.21', 'subnet_mask': '255.255.255.0', 'mac_address': 'af:5f:0c:00:d3:63', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': '32062959-b2ed-4d24-b5a9-7e99b7ebfcfe', 'folders': {'root': {'uuid': '8876d59b-d46d-414d-9ae2-5e948f65b175', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, '227d1fb7-fc64-4273-9817-0f32280a0859': {'uuid': '227d1fb7-fc64-4273-9817-0f32280a0859', 'hostname': 'client_2', 'operating_state': 2, 'NICs': {'22119571-b47d-4ffb-998c-62173c670f78': {'uuid': '22119571-b47d-4ffb-998c-62173c670f78', 'ip_adress': '192.168.10.22', 'subnet_mask': '255.255.255.0', 'mac_address': '7c:fe:81:20:96:96', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': '1a6eb561-c7fc-40f0-a288-d56af08c8f0c', 'folders': {'root': {'uuid': 'd129d4a6-5098-41ee-b9b3-033895a2288c', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}}, 'links': {}}, 'domain': {'uuid': 'db0e6d12-7cc6-4828-ba9b-4110e7f14bc2', 'accounts': {}}}\n" + ] + } + ], + "source": [ + "print(s.simulation.describe_state())" ] }, { From f79ed99bd253335d59c82b81a3c48986ecedbdb4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 25 Sep 2023 19:17:57 +0100 Subject: [PATCH 192/980] end of day --- sandbox.ipynb | 78 +++++++++++-------- .../network/hardware/nodes/router.py | 10 +-- 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/sandbox.ipynb b/sandbox.ipynb index 91edb829..96d12bae 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -157,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 44, "metadata": {}, "outputs": [], "source": [ @@ -167,34 +167,33 @@ "from primaite.simulator.network.hardware.nodes.server import Server\n", "from primaite.simulator.network.hardware.nodes.switch import Switch\n", "from primaite.simulator.network.hardware.nodes.router import Router\n", - "\n" + "\n", + "from primaite.simulator.system.applications.database_client import DatabaseClient\n", + "from primaite.simulator.system.services.database_service import DatabaseService\n", + "from primaite.simulator.system.services.dns_client import DNSClient\n", + "from primaite.simulator.system.services.dns_server import DNSServer\n", + "from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot\n" ] }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 42, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2023-09-25 17:38:39,385: Added node b5486651-1c6f-449a-8019-6a3641cfb998 to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n", - "2023-09-25 17:38:39,391: Added node 1533c2f7-389e-4e03-95b3-9cf059086490 to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n", - "2023-09-25 17:38:39,395: Added node 6b6c3b24-61d4-46ac-9364-11d726e50ccb to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n", - "2023-09-25 17:38:39,398: Added node a0bee8d0-2ab8-4e29-9a2c-23c6757b240c to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n", - "2023-09-25 17:38:39,401: Added node 7cb2c102-62ba-4859-94f2-5d724de38733 to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n", - "2023-09-25 17:38:39,403: Added node bec38db7-520e-4044-93db-08308278d66f to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n", - "2023-09-25 17:38:39,407: Added node ae0c2253-3ec8-48c3-b5d2-0b37c19c885d to Network 7c6e4724-1653-4db7-9bd0-44e8e380f1a1\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3\n", - "3\n", - "3\n" + "2023-09-25 19:10:46,253: Added node 3d356af7-15f8-41d4-bb2a-423d5a2e5978 to Network 44950e57-81b0-4964-9b12-223592c785aa\n", + "2023-09-25 19:10:46,254::WARNING::primaite.simulator.network.container::181::Can't add node 3d356af7-15f8-41d4-bb2a-423d5a2e5978. It is already in the network.\n", + "2023-09-25 19:10:46,258: Added node 8a94447a-ccb3-47b2-b7ba-488e631f8246 to Network 44950e57-81b0-4964-9b12-223592c785aa\n", + "2023-09-25 19:10:46,262: Added node 4e3de72a-60ad-416f-abb7-da352a59d13b to Network 44950e57-81b0-4964-9b12-223592c785aa\n", + "2023-09-25 19:10:46,264: Added node 21ae4eed-489f-43a7-af0a-f70000714c79 to Network 44950e57-81b0-4964-9b12-223592c785aa\n", + "2023-09-25 19:10:46,267: Added node c4b7d388-c13e-4f4e-be61-5cf05989da71 to Network 44950e57-81b0-4964-9b12-223592c785aa\n", + "2023-09-25 19:10:46,270: Added node 12dc9e72-fb7c-4a8f-ab79-d7574863fa16 to Network 44950e57-81b0-4964-9b12-223592c785aa\n", + "2023-09-25 19:10:46,273: Added node 37ff728f-64b5-4203-8177-cf27f51dc7c9 to Network 44950e57-81b0-4964-9b12-223592c785aa\n", + "2023-09-25 19:10:46,277: Added node fe9ef0ad-e0d6-48b9-a884-f7c0b95de32a to Network 44950e57-81b0-4964-9b12-223592c785aa\n", + "2023-09-25 19:10:46,281: Added node dfd186b9-7dc7-4d6f-a736-0cce3d22bfb6 to Network 44950e57-81b0-4964-9b12-223592c785aa\n" ] } ], @@ -204,6 +203,7 @@ "from primaite.simulator.network.hardware.nodes.router import ACLAction\n", "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", "from primaite.simulator.network.transmission.transport_layer import Port\n", + "from primaite.simulator.system.services.dns_server import DNSServer\n", "\n", "\n", "class PrimaiteSession:\n", @@ -226,7 +226,7 @@ " nodes_cfg = conf['simulation']['network']['nodes']\n", " links_cfg = conf['simulation']['network']['links']\n", " for node_cfg in nodes_cfg:\n", - " ref = node_cfg['ref']\n", + " node_ref = node_cfg['ref']\n", " n_type = node_cfg['type']\n", " if n_type == 'computer':\n", " new_node = Computer(hostname = node_cfg['hostname'], \n", @@ -253,22 +253,36 @@ " subnet_mask=port_cfg['subnet_mask'])\n", " if 'acl' in node_cfg:\n", " for r_num, r_cfg in node_cfg['acl'].items():\n", + " # excuse the uncommon walrus operator ` := `. It's just here as a shorthand, so that we can do\n", + " # both of these things once: check if a key is defined, access and convert it to a \n", + " # Port/IPProtocol. TODO Refactor\n", " new_node.acl.add_rule(\n", " action = ACLAction[r_cfg['action']],\n", - " src_port = Port[r_cfg.get('port')],\n", - " dst_port = Port[r_cfg.get('port')],\n", - " protocol = IPProtocol[r_cfg.get('protocol')],\n", - " src_ip = r_cfg.get('ip_address'),\n", - " dst_ip = r_cfg.get('ip_address'),\n", + " src_port = None if not (p:=r_cfg.get('src_port')) else Port[p],\n", + " dst_port = None if not (p:=r_cfg.get('dst_port')) else Port[p],\n", + " protocol = None if not (p:=r_cfg.get('protocol')) else IPProtocol[p],\n", + " src_ip_address = r_cfg.get('ip_address'),\n", + " dst_ip_address = r_cfg.get('ip_address'),\n", " position = r_num\n", " )\n", + " if 'services' in node_cfg:\n", + " for service_cfg in node_cfg['services']:\n", + " service_ref = service_cfg['ref']\n", + " service_type = service_cfg['type']\n", + " service_types_mapping = {\n", + " 'dns_server' : DNSServer,\n", + " 'database_client': DatabaseClient,\n", + " 'database_service': DatabaseService,\n", + " # 'database_backup': ,\n", + " 'data_manipulation_bot': DataManipulationBot,\n", + " 'dns_client': DNSClient,\n", + " # 'web_browser'\n", + " }\n", + " if service_type\n", "\n", "\n", - " try:\n", - " net.add_node(new_node)\n", - " ref_to_uuid[ref] = new_node.uuid\n", - " except BaseException:\n", - " print(3)\n", + " net.add_node(new_node)\n", + " ref_to_uuid[node_ref] = new_node.uuid\n", "\n", "\n", " #2. start/setup simulation objects\n", @@ -283,14 +297,14 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 43, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'uuid': 'ceeb8791-b140-43d0-b59e-c3c3f533309b', 'network': {'uuid': 'ff176601-4e1d-4f89-8db4-33c0598ee105', 'nodes': {'6b9afe70-913b-40ce-9cee-1ee3648e43ce': {'uuid': '6b9afe70-913b-40ce-9cee-1ee3648e43ce', 'hostname': 'client_1', 'operating_state': 2, 'NICs': {'108c797d-32ca-4e93-8476-6b13cda6cf37': {'uuid': '108c797d-32ca-4e93-8476-6b13cda6cf37', 'ip_adress': '192.168.10.21', 'subnet_mask': '255.255.255.0', 'mac_address': 'af:5f:0c:00:d3:63', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': '32062959-b2ed-4d24-b5a9-7e99b7ebfcfe', 'folders': {'root': {'uuid': '8876d59b-d46d-414d-9ae2-5e948f65b175', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, '227d1fb7-fc64-4273-9817-0f32280a0859': {'uuid': '227d1fb7-fc64-4273-9817-0f32280a0859', 'hostname': 'client_2', 'operating_state': 2, 'NICs': {'22119571-b47d-4ffb-998c-62173c670f78': {'uuid': '22119571-b47d-4ffb-998c-62173c670f78', 'ip_adress': '192.168.10.22', 'subnet_mask': '255.255.255.0', 'mac_address': '7c:fe:81:20:96:96', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': '1a6eb561-c7fc-40f0-a288-d56af08c8f0c', 'folders': {'root': {'uuid': 'd129d4a6-5098-41ee-b9b3-033895a2288c', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}}, 'links': {}}, 'domain': {'uuid': 'db0e6d12-7cc6-4828-ba9b-4110e7f14bc2', 'accounts': {}}}\n" + "{'uuid': '532b534a-78b7-4630-92f9-626d775ee4e2', 'network': {'uuid': '44950e57-81b0-4964-9b12-223592c785aa', 'nodes': {'3d356af7-15f8-41d4-bb2a-423d5a2e5978': {'uuid': '3d356af7-15f8-41d4-bb2a-423d5a2e5978', 'hostname': 'router_1', 'operating_state': 2, 'NICs': {'c52a1516-3488-4011-95ae-44e77935720d': {'uuid': 'c52a1516-3488-4011-95ae-44e77935720d', 'ip_adress': '192.168.1.1', 'subnet_mask': '255.255.255.0', 'mac_address': '12:75:33:08:ae:04', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}, '075a3387-b3c5-4e30-b7d5-f39b82b1c9d8': {'uuid': '075a3387-b3c5-4e30-b7d5-f39b82b1c9d8', 'ip_adress': '192.168.1.1', 'subnet_mask': '255.255.255.0', 'mac_address': 'ce:67:79:4a:48:90', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}, '3fe76cb7-84fe-4592-b527-be69c06c8064': {'uuid': '3fe76cb7-84fe-4592-b527-be69c06c8064', 'ip_adress': '127.0.0.1', 'subnet_mask': '255.0.0.0', 'mac_address': '83:13:43:3a:e6:de', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}, 'b4ad54f8-8508-4d34-9117-8f194a1076b1': {'uuid': 'b4ad54f8-8508-4d34-9117-8f194a1076b1', 'ip_adress': '127.0.0.1', 'subnet_mask': '255.0.0.0', 'mac_address': '4f:1a:3f:76:c7:2c', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}, '21efd6b1-8b49-4b56-aafe-a3cbdf61e0fb': {'uuid': '21efd6b1-8b49-4b56-aafe-a3cbdf61e0fb', 'ip_adress': '127.0.0.1', 'subnet_mask': '255.0.0.0', 'mac_address': '76:4d:65:e4:0d:11', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': 'df3b627a-76c3-4e60-83ef-81442fbf4643', 'folders': {'root': {'uuid': 'b21a0c20-e852-4d05-a0fe-9158f76f3a98', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}, 'num_ports': (5,), 'acl': ({'uuid': '2fc154d6-9ccf-4c60-b6d3-ac3fcce68fc8', 'implicit_action': 0, 'implicit_rule': {'uuid': '6a5553d0-37a6-4ac5-b5da-38f7926ffe7e', 'action': 0, 'protocol': None, 'src_ip_address': None, 'src_port': None, 'dst_ip_address': None, 'dst_port': None}, 'max_acl_rules': 25, 'acl': {0: {'uuid': '8204a738-6010-44a8-8df3-317d4a03f600', 'action': 1, 'protocol': None, 'src_ip_address': None, 'src_port': 5432, 'dst_ip_address': None, 'dst_port': 5432}, 1: {'uuid': 'af7b39a5-e0ed-4047-b684-0cfbdc14f70b', 'action': 1, 'protocol': None, 'src_ip_address': None, 'src_port': 53, 'dst_ip_address': None, 'dst_port': 53}, 2: None, 3: None, 4: None, 5: None, 6: None, 7: None, 8: None, 9: None, 10: None, 11: None, 12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: None, 19: None, 20: None, 21: None, 22: {'uuid': '4c6320f5-d9f4-4958-9572-d2ebc06ee120', 'action': 1, 'protocol': None, 'src_ip_address': None, 'src_port': 219, 'dst_ip_address': None, 'dst_port': 219}, 23: {'uuid': 'f39796b9-7511-4f23-b8a6-cbf0e87ec51a', 'action': 1, 'protocol': 'icmp', 'src_ip_address': None, 'src_port': None, 'dst_ip_address': None, 'dst_port': None}}},)}, '8a94447a-ccb3-47b2-b7ba-488e631f8246': {'uuid': '8a94447a-ccb3-47b2-b7ba-488e631f8246', 'num_ports': 8, 'ports': {1: {'uuid': '32eb0312-124d-42df-93bc-9cc25eb4b81f', 'mac_address': '1a:4e:83:7a:d7:4b', 'speed': 100, 'mtu': 1500, 'enabled': False}, 2: {'uuid': 'afe7a1b8-bfa6-42a2-b4aa-28187c67f7d3', 'mac_address': '9e:09:af:37:1d:e3', 'speed': 100, 'mtu': 1500, 'enabled': False}, 3: {'uuid': '98f46066-7e05-45cd-920e-54bbb3513fec', 'mac_address': '00:30:02:18:11:52', 'speed': 100, 'mtu': 1500, 'enabled': False}, 4: {'uuid': '65fb27f3-22ca-4bd3-898e-a2fdf49ec3b0', 'mac_address': 'f2:3f:0b:09:50:e1', 'speed': 100, 'mtu': 1500, 'enabled': False}, 5: {'uuid': 'f69c7045-40f7-490f-9c7c-280d0eb4fcd0', 'mac_address': '38:56:f5:dd:0a:a4', 'speed': 100, 'mtu': 1500, 'enabled': False}, 6: {'uuid': '6dbbac83-cd01-45ec-9ad6-352e1afee231', 'mac_address': 'aa:bb:c3:92:05:88', 'speed': 100, 'mtu': 1500, 'enabled': False}, 7: {'uuid': 'a39591ea-d50d-4649-ba90-f5fddd55b61d', 'mac_address': '60:67:46:45:21:cc', 'speed': 100, 'mtu': 1500, 'enabled': False}, 8: {'uuid': '488cdddb-9e5e-4fb1-8e03-cfcfd47b0cb3', 'mac_address': '0f:a0:4f:52:42:5c', 'speed': 100, 'mtu': 1500, 'enabled': False}}, 'mac_address_table': {}}, '4e3de72a-60ad-416f-abb7-da352a59d13b': {'uuid': '4e3de72a-60ad-416f-abb7-da352a59d13b', 'hostname': 'domain_controller', 'operating_state': 2, 'NICs': {'34962c55-cea2-479b-ac1f-61a683c82eb1': {'uuid': '34962c55-cea2-479b-ac1f-61a683c82eb1', 'ip_adress': '192.168.1.10', 'subnet_mask': '255.255.255.0', 'mac_address': '41:a0:d4:22:b9:81', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': 'e3f270c9-2941-4592-892c-5662bbc49e39', 'folders': {'root': {'uuid': '486c9c58-7715-4bfc-a125-ec6ceaef5951', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, '21ae4eed-489f-43a7-af0a-f70000714c79': {'uuid': '21ae4eed-489f-43a7-af0a-f70000714c79', 'hostname': 'web_server', 'operating_state': 2, 'NICs': {'060e96d7-399c-49d1-afcb-d448b3eec2d5': {'uuid': '060e96d7-399c-49d1-afcb-d448b3eec2d5', 'ip_adress': '192.168.1.12', 'subnet_mask': '255.255.255.0', 'mac_address': '7f:e0:b3:05:2c:d4', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': 'e8b1c5c5-f5ce-4d2f-840a-8b56e3fbd06b', 'folders': {'root': {'uuid': '86857c08-f5ed-4c60-98c9-a5c7f0985549', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, 'c4b7d388-c13e-4f4e-be61-5cf05989da71': {'uuid': 'c4b7d388-c13e-4f4e-be61-5cf05989da71', 'hostname': 'database_server', 'operating_state': 2, 'NICs': {'bed479cf-480b-463b-9fff-66e4dd3d23cc': {'uuid': 'bed479cf-480b-463b-9fff-66e4dd3d23cc', 'ip_adress': '192.168.1.14', 'subnet_mask': '255.255.255.0', 'mac_address': 'b4:d7:b6:04:7b:07', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': '9c6f86b8-c14f-4593-8397-e3fe2e88ef66', 'folders': {'root': {'uuid': '1fd374f4-398a-4b98-9295-c2969cb3025c', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, '12dc9e72-fb7c-4a8f-ab79-d7574863fa16': {'uuid': '12dc9e72-fb7c-4a8f-ab79-d7574863fa16', 'hostname': 'backup_server', 'operating_state': 2, 'NICs': {'b299a15c-cf03-4c50-92ed-ac2932472927': {'uuid': 'b299a15c-cf03-4c50-92ed-ac2932472927', 'ip_adress': '192.168.1.16', 'subnet_mask': '255.255.255.0', 'mac_address': '7b:0e:7c:b3:d1:9c', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': '455a7e64-bee9-41e7-80c5-a38a26d3e7db', 'folders': {'root': {'uuid': 'd5f22eda-5f15-4df6-b9c5-5f107a0d7ef0', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, '37ff728f-64b5-4203-8177-cf27f51dc7c9': {'uuid': '37ff728f-64b5-4203-8177-cf27f51dc7c9', 'hostname': 'security_suite', 'operating_state': 2, 'NICs': {'9011d432-dd95-4b0b-b793-2f9d173009da': {'uuid': '9011d432-dd95-4b0b-b793-2f9d173009da', 'ip_adress': '192.168.1.110', 'subnet_mask': '255.255.255.0', 'mac_address': '58:17:29:b0:d2:e4', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': '9bb869b9-7253-4890-92bc-b3f7e5119b6d', 'folders': {'root': {'uuid': '5415d598-e8ad-445d-b573-f4b56e6268e3', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, 'fe9ef0ad-e0d6-48b9-a884-f7c0b95de32a': {'uuid': 'fe9ef0ad-e0d6-48b9-a884-f7c0b95de32a', 'hostname': 'client_1', 'operating_state': 2, 'NICs': {'80e94189-3bd7-45f5-ac04-50974e6db2e1': {'uuid': '80e94189-3bd7-45f5-ac04-50974e6db2e1', 'ip_adress': '192.168.10.21', 'subnet_mask': '255.255.255.0', 'mac_address': 'e1:ce:28:ef:74:76', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': 'e4caeb03-81c1-4c0f-b619-f305ffd35c57', 'folders': {'root': {'uuid': 'b7f5c0c0-e41e-4d79-9ef8-d06e3e601929', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, 'dfd186b9-7dc7-4d6f-a736-0cce3d22bfb6': {'uuid': 'dfd186b9-7dc7-4d6f-a736-0cce3d22bfb6', 'hostname': 'client_2', 'operating_state': 2, 'NICs': {'631bf440-da8f-41f0-947b-fdef122410ec': {'uuid': '631bf440-da8f-41f0-947b-fdef122410ec', 'ip_adress': '192.168.10.22', 'subnet_mask': '255.255.255.0', 'mac_address': '67:da:5c:11:c7:e4', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': 'd4723cc6-32b9-4b21-8eab-3517ceb47130', 'folders': {'root': {'uuid': '2bbf4393-b5b3-4c2d-8b8e-6e6b883cdace', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}}, 'links': {}}, 'domain': {'uuid': '3216790f-d143-47e8-aa8d-8a2f819b34c7', 'accounts': {}}}\n" ] } ], diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 7870caab..2e7681a9 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -60,11 +60,11 @@ class ACLRule(SimComponent): """ state = super().describe_state() state["action"] = self.action.value - state["protocol"] = self.protocol.value - state["src_ip_address"] = self.src_ip_address - state["src_port"] = self.src_port.value - state["dst_ip_address"] = self.dst_ip_address - state["dst_port"] = self.dst_port.value + state["protocol"] = self.protocol.value if self.protocol else None + state["src_ip_address"] = self.src_ip_address if self.src_ip_address else None + state["src_port"] = self.src_port.value if self.src_port else None + state["dst_ip_address"] = self.dst_ip_address if self.dst_ip_address else None + state["dst_port"] = self.dst_port.value if self.dst_port else None return state From fdf66ba3de2c4b5085c55c9834ca9ff32e166c4b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Sep 2023 10:52:14 +0100 Subject: [PATCH 193/980] Make yaml parser work with services --- example_config.yaml | 16 ++-- sandbox.ipynb | 219 ++++++++------------------------------------ 2 files changed, 48 insertions(+), 187 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index f0957718..dd5971a1 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -170,7 +170,7 @@ simulation: default_gateway: 192.168.1.1 services: - ref: domain_controller_dns_server - type: dns_server + type: DNSServer options: domain_mapping: - arcd.com: 192.168.1.12 # web server @@ -185,7 +185,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: web_server_database_client - type: database_client + type: DatabaseClient options: db_server_ip: 192.168.1.14 @@ -198,7 +198,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: database_service - type: database_service + type: DatabaseService - ref: backup_server @@ -210,7 +210,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: backup_service - type: database_backup + type: DatabaseBackup - ref: security_suite type: server @@ -234,9 +234,9 @@ simulation: dns_server: 192.168.1.10 services: - ref: data_manipulation_bot - type: data_manipulation_bot + type: DataManipulationBot - ref: client_1_dns_client - type: dns_client + type: DNSClient - ref: client_2 type: computer @@ -247,9 +247,9 @@ simulation: dns_server: 192.168.1.10 services: - ref: client_2_web_browser - type: web_browser + type: WebBrowser - ref: client_2_dns_client - type: dns_client + type: DNSClient links: diff --git a/sandbox.ipynb b/sandbox.ipynb index 96d12bae..5d611ada 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -12,152 +12,7 @@ }, { "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "import yaml" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from primaite.simulator.network.networks import arcd_uc2_network\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "net = arcd_uc2_network()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "random_node = list(net.nodes.keys())[0]\n", - "f = net.nodes[random_node].file_system.create_file(file_name=\"testfile\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "f.describe_state()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def test_file_observation():\n", - " from primaite.simulator.sim_container import Simulation\n", - " from primaite.simulator.network.hardware.nodes.computer import Computer\n", - " from primaite.game.actor.observations import FileObservation\n", - "\n", - " sim = Simulation()\n", - " pc = Computer(hostname=\"beep\", ip_address=\"123.123.123.123\", subnet_mask=\"255.255.255.0\")\n", - " sim.network.add_node(pc)\n", - " f = pc.file_system.create_file(file_name=\"dog.png\")\n", - "\n", - " dog_file_obs = FileObservation(where=['network','nodes',pc.uuid,'file_system'])\n", - " print(sim.describe_state())\n", - "test_file_observation()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from primaite.simulator.sim_container import Simulation\n", - "from primaite.simulator.network.hardware.nodes.computer import Computer\n", - "from primaite.game.actor.observations import FileObservation, FolderObservation\n", - "\n", - "sim = Simulation()\n", - "pc = Computer(hostname=\"beep\", ip_address=\"123.123.123.123\", subnet_mask=\"255.255.255.0\")\n", - "sim.network.add_node(pc)\n", - "f = pc.file_system.create_file(file_name=\"dog.png\")\n", - "\n", - "state = sim.describe_state()\n", - "\n", - "dog_file_obs = FileObservation(where=['network','nodes',pc.uuid,'file_system', 'folders','root','files','dog.png'])\n", - "root_folder_obs = FolderObservation(where=['network','nodes',pc.uuid,'file_system', 'folders','root'],files=[dog_file_obs])\n", - "print(dog_file_obs(state))\n", - "print(root_folder_obs(state))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "dog_file_obs.space" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "root_folder_obs.space" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "state" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import yaml" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "with open('example_config.yaml', 'r') as file:\n", - " conf = yaml.safe_load(file)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "conf['simulation']" - ] - }, - { - "cell_type": "code", - "execution_count": 44, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -172,39 +27,48 @@ "from primaite.simulator.system.services.database_service import DatabaseService\n", "from primaite.simulator.system.services.dns_client import DNSClient\n", "from primaite.simulator.system.services.dns_server import DNSServer\n", - "from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot\n" + "from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot\n", + "\n", + "\n", + "from primaite.simulator.network.hardware.nodes.router import ACLAction\n", + "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", + "from primaite.simulator.network.transmission.transport_layer import Port\n", + "\n" ] }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2023-09-25 19:10:46,253: Added node 3d356af7-15f8-41d4-bb2a-423d5a2e5978 to Network 44950e57-81b0-4964-9b12-223592c785aa\n", - "2023-09-25 19:10:46,254::WARNING::primaite.simulator.network.container::181::Can't add node 3d356af7-15f8-41d4-bb2a-423d5a2e5978. It is already in the network.\n", - "2023-09-25 19:10:46,258: Added node 8a94447a-ccb3-47b2-b7ba-488e631f8246 to Network 44950e57-81b0-4964-9b12-223592c785aa\n", - "2023-09-25 19:10:46,262: Added node 4e3de72a-60ad-416f-abb7-da352a59d13b to Network 44950e57-81b0-4964-9b12-223592c785aa\n", - "2023-09-25 19:10:46,264: Added node 21ae4eed-489f-43a7-af0a-f70000714c79 to Network 44950e57-81b0-4964-9b12-223592c785aa\n", - "2023-09-25 19:10:46,267: Added node c4b7d388-c13e-4f4e-be61-5cf05989da71 to Network 44950e57-81b0-4964-9b12-223592c785aa\n", - "2023-09-25 19:10:46,270: Added node 12dc9e72-fb7c-4a8f-ab79-d7574863fa16 to Network 44950e57-81b0-4964-9b12-223592c785aa\n", - "2023-09-25 19:10:46,273: Added node 37ff728f-64b5-4203-8177-cf27f51dc7c9 to Network 44950e57-81b0-4964-9b12-223592c785aa\n", - "2023-09-25 19:10:46,277: Added node fe9ef0ad-e0d6-48b9-a884-f7c0b95de32a to Network 44950e57-81b0-4964-9b12-223592c785aa\n", - "2023-09-25 19:10:46,281: Added node dfd186b9-7dc7-4d6f-a736-0cce3d22bfb6 to Network 44950e57-81b0-4964-9b12-223592c785aa\n" + "2023-09-26 10:51:10,388: Added node 48e6cb0b-f351-47f6-b837-df9443f9db26 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", + "2023-09-26 10:51:10,390::WARNING::primaite.simulator.network.container::181::Can't add node 48e6cb0b-f351-47f6-b837-df9443f9db26. It is already in the network.\n", + "2023-09-26 10:51:10,394: Added node 6a969d4d-e0af-402e-b576-2a787505f7c7 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", + "2023-09-26 10:51:10,397: Added node c58e6f17-dbf1-4c6a-9dbf-d60883c6d948 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", + "2023-09-26 10:51:10,401: Added node 7f2a418d-2d0b-4f02-beb3-5703fc5035c8 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", + "2023-09-26 10:51:10,408: Added node 967417fa-2300-4ee1-8ba0-7a4d055d5d30 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", + "2023-09-26 10:51:10,413: Added node 80c1c99b-4c7a-41fb-86f0-b93c35c3b497 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", + "2023-09-26 10:51:10,418: Added node 9a11dd40-9243-4510-9b43-9f247f669ad2 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", + "2023-09-26 10:51:10,424: Added node 81fff4a6-35c8-4933-bb6c-fd8fd49315fe to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", + "2023-09-26 10:51:10,429: Added node 7cc11532-3f65-4c65-a4df-af2c6318a976 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "service type not found DatabaseBackup\n", + "service type not found WebBrowser\n" ] } ], "source": [ "# import yaml\n", "\n", - "from primaite.simulator.network.hardware.nodes.router import ACLAction\n", - "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", - "from primaite.simulator.network.transmission.transport_layer import Port\n", - "from primaite.simulator.system.services.dns_server import DNSServer\n", - "\n", "\n", "class PrimaiteSession:\n", "\n", @@ -270,15 +134,20 @@ " service_ref = service_cfg['ref']\n", " service_type = service_cfg['type']\n", " service_types_mapping = {\n", - " 'dns_server' : DNSServer,\n", - " 'database_client': DatabaseClient,\n", - " 'database_service': DatabaseService,\n", + " 'DNSClient': DNSClient, # key is equal to the 'name' attr of the service class itself.\n", + " 'DNSServer' : DNSServer,\n", + " 'DatabaseClient': DatabaseClient,\n", + " 'DatabaseService': DatabaseService,\n", " # 'database_backup': ,\n", - " 'data_manipulation_bot': DataManipulationBot,\n", - " 'dns_client': DNSClient,\n", + " 'DataManipulationBot': DataManipulationBot,\n", " # 'web_browser'\n", " }\n", - " if service_type\n", + " if service_type in service_types_mapping:\n", + " new_node.software_manager.install(service_types_mapping[service_type])\n", + " service_obj = new_node.software_manager.software[service_type]\n", + " ref_to_uuid[service_ref] = service_obj.uuid\n", + " else:\n", + " print(f\"service type not found {service_type}\")\n", "\n", "\n", " net.add_node(new_node)\n", @@ -297,17 +166,9 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'uuid': '532b534a-78b7-4630-92f9-626d775ee4e2', 'network': {'uuid': '44950e57-81b0-4964-9b12-223592c785aa', 'nodes': {'3d356af7-15f8-41d4-bb2a-423d5a2e5978': {'uuid': '3d356af7-15f8-41d4-bb2a-423d5a2e5978', 'hostname': 'router_1', 'operating_state': 2, 'NICs': {'c52a1516-3488-4011-95ae-44e77935720d': {'uuid': 'c52a1516-3488-4011-95ae-44e77935720d', 'ip_adress': '192.168.1.1', 'subnet_mask': '255.255.255.0', 'mac_address': '12:75:33:08:ae:04', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}, '075a3387-b3c5-4e30-b7d5-f39b82b1c9d8': {'uuid': '075a3387-b3c5-4e30-b7d5-f39b82b1c9d8', 'ip_adress': '192.168.1.1', 'subnet_mask': '255.255.255.0', 'mac_address': 'ce:67:79:4a:48:90', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}, '3fe76cb7-84fe-4592-b527-be69c06c8064': {'uuid': '3fe76cb7-84fe-4592-b527-be69c06c8064', 'ip_adress': '127.0.0.1', 'subnet_mask': '255.0.0.0', 'mac_address': '83:13:43:3a:e6:de', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}, 'b4ad54f8-8508-4d34-9117-8f194a1076b1': {'uuid': 'b4ad54f8-8508-4d34-9117-8f194a1076b1', 'ip_adress': '127.0.0.1', 'subnet_mask': '255.0.0.0', 'mac_address': '4f:1a:3f:76:c7:2c', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}, '21efd6b1-8b49-4b56-aafe-a3cbdf61e0fb': {'uuid': '21efd6b1-8b49-4b56-aafe-a3cbdf61e0fb', 'ip_adress': '127.0.0.1', 'subnet_mask': '255.0.0.0', 'mac_address': '76:4d:65:e4:0d:11', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': 'df3b627a-76c3-4e60-83ef-81442fbf4643', 'folders': {'root': {'uuid': 'b21a0c20-e852-4d05-a0fe-9158f76f3a98', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}, 'num_ports': (5,), 'acl': ({'uuid': '2fc154d6-9ccf-4c60-b6d3-ac3fcce68fc8', 'implicit_action': 0, 'implicit_rule': {'uuid': '6a5553d0-37a6-4ac5-b5da-38f7926ffe7e', 'action': 0, 'protocol': None, 'src_ip_address': None, 'src_port': None, 'dst_ip_address': None, 'dst_port': None}, 'max_acl_rules': 25, 'acl': {0: {'uuid': '8204a738-6010-44a8-8df3-317d4a03f600', 'action': 1, 'protocol': None, 'src_ip_address': None, 'src_port': 5432, 'dst_ip_address': None, 'dst_port': 5432}, 1: {'uuid': 'af7b39a5-e0ed-4047-b684-0cfbdc14f70b', 'action': 1, 'protocol': None, 'src_ip_address': None, 'src_port': 53, 'dst_ip_address': None, 'dst_port': 53}, 2: None, 3: None, 4: None, 5: None, 6: None, 7: None, 8: None, 9: None, 10: None, 11: None, 12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: None, 19: None, 20: None, 21: None, 22: {'uuid': '4c6320f5-d9f4-4958-9572-d2ebc06ee120', 'action': 1, 'protocol': None, 'src_ip_address': None, 'src_port': 219, 'dst_ip_address': None, 'dst_port': 219}, 23: {'uuid': 'f39796b9-7511-4f23-b8a6-cbf0e87ec51a', 'action': 1, 'protocol': 'icmp', 'src_ip_address': None, 'src_port': None, 'dst_ip_address': None, 'dst_port': None}}},)}, '8a94447a-ccb3-47b2-b7ba-488e631f8246': {'uuid': '8a94447a-ccb3-47b2-b7ba-488e631f8246', 'num_ports': 8, 'ports': {1: {'uuid': '32eb0312-124d-42df-93bc-9cc25eb4b81f', 'mac_address': '1a:4e:83:7a:d7:4b', 'speed': 100, 'mtu': 1500, 'enabled': False}, 2: {'uuid': 'afe7a1b8-bfa6-42a2-b4aa-28187c67f7d3', 'mac_address': '9e:09:af:37:1d:e3', 'speed': 100, 'mtu': 1500, 'enabled': False}, 3: {'uuid': '98f46066-7e05-45cd-920e-54bbb3513fec', 'mac_address': '00:30:02:18:11:52', 'speed': 100, 'mtu': 1500, 'enabled': False}, 4: {'uuid': '65fb27f3-22ca-4bd3-898e-a2fdf49ec3b0', 'mac_address': 'f2:3f:0b:09:50:e1', 'speed': 100, 'mtu': 1500, 'enabled': False}, 5: {'uuid': 'f69c7045-40f7-490f-9c7c-280d0eb4fcd0', 'mac_address': '38:56:f5:dd:0a:a4', 'speed': 100, 'mtu': 1500, 'enabled': False}, 6: {'uuid': '6dbbac83-cd01-45ec-9ad6-352e1afee231', 'mac_address': 'aa:bb:c3:92:05:88', 'speed': 100, 'mtu': 1500, 'enabled': False}, 7: {'uuid': 'a39591ea-d50d-4649-ba90-f5fddd55b61d', 'mac_address': '60:67:46:45:21:cc', 'speed': 100, 'mtu': 1500, 'enabled': False}, 8: {'uuid': '488cdddb-9e5e-4fb1-8e03-cfcfd47b0cb3', 'mac_address': '0f:a0:4f:52:42:5c', 'speed': 100, 'mtu': 1500, 'enabled': False}}, 'mac_address_table': {}}, '4e3de72a-60ad-416f-abb7-da352a59d13b': {'uuid': '4e3de72a-60ad-416f-abb7-da352a59d13b', 'hostname': 'domain_controller', 'operating_state': 2, 'NICs': {'34962c55-cea2-479b-ac1f-61a683c82eb1': {'uuid': '34962c55-cea2-479b-ac1f-61a683c82eb1', 'ip_adress': '192.168.1.10', 'subnet_mask': '255.255.255.0', 'mac_address': '41:a0:d4:22:b9:81', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': 'e3f270c9-2941-4592-892c-5662bbc49e39', 'folders': {'root': {'uuid': '486c9c58-7715-4bfc-a125-ec6ceaef5951', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, '21ae4eed-489f-43a7-af0a-f70000714c79': {'uuid': '21ae4eed-489f-43a7-af0a-f70000714c79', 'hostname': 'web_server', 'operating_state': 2, 'NICs': {'060e96d7-399c-49d1-afcb-d448b3eec2d5': {'uuid': '060e96d7-399c-49d1-afcb-d448b3eec2d5', 'ip_adress': '192.168.1.12', 'subnet_mask': '255.255.255.0', 'mac_address': '7f:e0:b3:05:2c:d4', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': 'e8b1c5c5-f5ce-4d2f-840a-8b56e3fbd06b', 'folders': {'root': {'uuid': '86857c08-f5ed-4c60-98c9-a5c7f0985549', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, 'c4b7d388-c13e-4f4e-be61-5cf05989da71': {'uuid': 'c4b7d388-c13e-4f4e-be61-5cf05989da71', 'hostname': 'database_server', 'operating_state': 2, 'NICs': {'bed479cf-480b-463b-9fff-66e4dd3d23cc': {'uuid': 'bed479cf-480b-463b-9fff-66e4dd3d23cc', 'ip_adress': '192.168.1.14', 'subnet_mask': '255.255.255.0', 'mac_address': 'b4:d7:b6:04:7b:07', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': '9c6f86b8-c14f-4593-8397-e3fe2e88ef66', 'folders': {'root': {'uuid': '1fd374f4-398a-4b98-9295-c2969cb3025c', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, '12dc9e72-fb7c-4a8f-ab79-d7574863fa16': {'uuid': '12dc9e72-fb7c-4a8f-ab79-d7574863fa16', 'hostname': 'backup_server', 'operating_state': 2, 'NICs': {'b299a15c-cf03-4c50-92ed-ac2932472927': {'uuid': 'b299a15c-cf03-4c50-92ed-ac2932472927', 'ip_adress': '192.168.1.16', 'subnet_mask': '255.255.255.0', 'mac_address': '7b:0e:7c:b3:d1:9c', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': '455a7e64-bee9-41e7-80c5-a38a26d3e7db', 'folders': {'root': {'uuid': 'd5f22eda-5f15-4df6-b9c5-5f107a0d7ef0', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, '37ff728f-64b5-4203-8177-cf27f51dc7c9': {'uuid': '37ff728f-64b5-4203-8177-cf27f51dc7c9', 'hostname': 'security_suite', 'operating_state': 2, 'NICs': {'9011d432-dd95-4b0b-b793-2f9d173009da': {'uuid': '9011d432-dd95-4b0b-b793-2f9d173009da', 'ip_adress': '192.168.1.110', 'subnet_mask': '255.255.255.0', 'mac_address': '58:17:29:b0:d2:e4', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': '9bb869b9-7253-4890-92bc-b3f7e5119b6d', 'folders': {'root': {'uuid': '5415d598-e8ad-445d-b573-f4b56e6268e3', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, 'fe9ef0ad-e0d6-48b9-a884-f7c0b95de32a': {'uuid': 'fe9ef0ad-e0d6-48b9-a884-f7c0b95de32a', 'hostname': 'client_1', 'operating_state': 2, 'NICs': {'80e94189-3bd7-45f5-ac04-50974e6db2e1': {'uuid': '80e94189-3bd7-45f5-ac04-50974e6db2e1', 'ip_adress': '192.168.10.21', 'subnet_mask': '255.255.255.0', 'mac_address': 'e1:ce:28:ef:74:76', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': 'e4caeb03-81c1-4c0f-b619-f305ffd35c57', 'folders': {'root': {'uuid': 'b7f5c0c0-e41e-4d79-9ef8-d06e3e601929', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}, 'dfd186b9-7dc7-4d6f-a736-0cce3d22bfb6': {'uuid': 'dfd186b9-7dc7-4d6f-a736-0cce3d22bfb6', 'hostname': 'client_2', 'operating_state': 2, 'NICs': {'631bf440-da8f-41f0-947b-fdef122410ec': {'uuid': '631bf440-da8f-41f0-947b-fdef122410ec', 'ip_adress': '192.168.10.22', 'subnet_mask': '255.255.255.0', 'mac_address': '67:da:5c:11:c7:e4', 'speed': 100, 'mtu': 1500, 'wake_on_lan': False, 'enabled': False}}, 'file_system': {'uuid': 'd4723cc6-32b9-4b21-8eab-3517ceb47130', 'folders': {'root': {'uuid': '2bbf4393-b5b3-4c2d-8b8e-6e6b883cdace', 'name': 'root', 'health_status': 1, 'files': {}, 'is_quarantined': False}}}, 'applications': {}, 'services': {}, 'process': {}}}, 'links': {}}, 'domain': {'uuid': '3216790f-d143-47e8-aa8d-8a2f819b34c7', 'accounts': {}}}\n" - ] - } - ], + "outputs": [], "source": [ "print(s.simulation.describe_state())" ] From 92e0110e73de13e022adb8a55c434d9207f28c28 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Sep 2023 11:48:22 +0100 Subject: [PATCH 194/980] yaml parse and connect links --- example_config.yaml | 80 ++++++++++----------- sandbox.ipynb | 74 ++++++++++++++----- src/primaite/simulator/network/container.py | 3 +- 3 files changed, 99 insertions(+), 58 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index dd5971a1..e3871b4a 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -22,12 +22,12 @@ game_config: actions: - type: DONOTHING nodes: - - ref: client_2 + - node_ref: client_2 actions: - type: LOGON - type: LOGOFF applications: - - ref: client_2_web_browser + - application_ref: client_2_web_browser actions: - type: EXECUTE execution_definition: @@ -44,12 +44,12 @@ game_config: observation_space: network: nodes: - - ref: client_1 + - node_ref: client_1 observations: - logon_status - operating_status services: - - ref: data_manipulation_bot + - service_ref: data_manipulation_bot observations: - operating_status - health_status @@ -59,13 +59,13 @@ game_config: - type: DO_NOTHING network: nodes: - - ref: client_1 + - node_ref: client_1 actions: - type: SCAN - type: LOGON - type: LOGOFF services: - - ref: data_manipulation_bot + - service_ref: data_manipulation_bot actions: - type: COMPROMISE execution_definition: @@ -89,18 +89,18 @@ game_config: observation_space: network: nodes: - - ref: router_1 #TODO: more sub-options here - - ref: switch_1 - - ref: switch_2 - - ref: domain_controller - - ref: web_server - - ref: database_server - - ref: backup_server - - ref: security_suite - - ref: client_1 - - ref: client_2 + - node_ref: router_1 #TODO: more sub-options here + - node_ref: switch_1 + - node_ref: switch_2 + - node_ref: domain_controller + - node_ref: web_server + - node_ref: database_server + - node_ref: backup_server + - node_ref: security_suite + - node_ref: client_1 + - node_ref: client_2 links: - - ref: ... # + - link_ref: ... # acl: ... # ics: ... # @@ -110,7 +110,7 @@ game_config: - type: DO_NOTHING network: nodes: - - ref: router_1 + - node_ref: router_1 reward_function: # ... agent_settings: @@ -153,7 +153,7 @@ simulation: protocol: ICMP - ref: switch_1 - type: swtich + type: switch hostname: switch_1 num_ports: 8 @@ -173,7 +173,7 @@ simulation: type: DNSServer options: domain_mapping: - - arcd.com: 192.168.1.12 # web server + arcd.com: 192.168.1.12 # web server - ref: web_server @@ -254,52 +254,52 @@ simulation: links: - ref: router_1___switch_1 - endpoint_a: router_1 + endpoint_a_ref: router_1 endpoint_a_port: 1 - endpoint_b: switch_1 + endpoint_b_ref: switch_1 endpoint_b_port: 8 - ref: router_1___switch_2 - endpoint_a: router_1 + endpoint_a_ref: router_1 endpoint_a_port: 2 - endpoint_b: switch_2 + endpoint_b_ref: switch_2 endpoint_b_port: 8 - ref: switch_1___domain_controller - endpoint_a: switch_1 + endpoint_a_ref: switch_1 endpoint_a_port: 1 - endpoint_b: domain_controller + endpoint_b_ref: domain_controller endpoint_b_port: 1 - ref: switch_1___web_server - endpoint_a: switch_1 + endpoint_a_ref: switch_1 endpoint_a_port: 2 - endpoint_b: web_server + endpoint_b_ref: web_server endpoint_b_port: 1 - ref: switch_1___database_server - endpoint_a: switch_1 + endpoint_a_ref: switch_1 endpoint_a_port: 3 - endpoint_b: database_server + endpoint_b_ref: database_server endpoint_b_port: 1 - ref: switch_1___backup_server - endpoint_a: switch_1 + endpoint_a_ref: switch_1 endpoint_a_port: 4 - endpoint_b: backup_server + endpoint_b_ref: backup_server endpoint_b_port: 1 - ref: switch_1___security_suite - endpoint_a: switch_1 + endpoint_a_ref: switch_1 endpoint_a_port: 7 - endpoint_b: security_suite + endpoint_b_ref: security_suite endpoint_b_port: 1 - ref: switch_2___client_1 - endpoint_a: switch_2 + endpoint_a_ref: switch_2 endpoint_a_port: 1 - endpoint_b: client_1 + endpoint_b_ref: client_1 endpoint_b_port: 1 - ref: switch_2___client_2 - endpoint_a: switch_2 + endpoint_a_ref: switch_2 endpoint_a_port: 2 - endpoint_b: client_2 + endpoint_b_ref: client_2 endpoint_b_port: 1 - ref: switch_2___security_suite - endpoint_a: switch_2 + endpoint_a_ref: switch_2 endpoint_a_port: 7 - endpoint_b: security_suite + endpoint_b_ref: security_suite endpoint_b_port: 2 diff --git a/sandbox.ipynb b/sandbox.ipynb index 5d611ada..aa39c3e9 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -33,28 +33,29 @@ "from primaite.simulator.network.hardware.nodes.router import ACLAction\n", "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", "from primaite.simulator.network.transmission.transport_layer import Port\n", - "\n" + "\n", + "from ipaddress import IPv4Address\n" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2023-09-26 10:51:10,388: Added node 48e6cb0b-f351-47f6-b837-df9443f9db26 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", - "2023-09-26 10:51:10,390::WARNING::primaite.simulator.network.container::181::Can't add node 48e6cb0b-f351-47f6-b837-df9443f9db26. It is already in the network.\n", - "2023-09-26 10:51:10,394: Added node 6a969d4d-e0af-402e-b576-2a787505f7c7 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", - "2023-09-26 10:51:10,397: Added node c58e6f17-dbf1-4c6a-9dbf-d60883c6d948 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", - "2023-09-26 10:51:10,401: Added node 7f2a418d-2d0b-4f02-beb3-5703fc5035c8 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", - "2023-09-26 10:51:10,408: Added node 967417fa-2300-4ee1-8ba0-7a4d055d5d30 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", - "2023-09-26 10:51:10,413: Added node 80c1c99b-4c7a-41fb-86f0-b93c35c3b497 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", - "2023-09-26 10:51:10,418: Added node 9a11dd40-9243-4510-9b43-9f247f669ad2 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", - "2023-09-26 10:51:10,424: Added node 81fff4a6-35c8-4933-bb6c-fd8fd49315fe to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n", - "2023-09-26 10:51:10,429: Added node 7cc11532-3f65-4c65-a4df-af2c6318a976 to Network 7250d818-ec1b-4940-bb87-8e05fea87fe9\n" + "2023-09-26 11:47:11,032: Added node bc149bf5-ccc4-4dcd-b419-629ec44b2c9a to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", + "2023-09-26 11:47:11,035: Added node 9cacbaee-33cc-4423-a6c8-fe3dd75b1f87 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", + "2023-09-26 11:47:11,042: Added node d4444d66-7cc3-4cd4-acbd-202cb9fe37ff to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", + "2023-09-26 11:47:11,045: Added node af170371-e99b-42b7-9525-65ca64522539 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", + "2023-09-26 11:47:11,049: Added node d6218f34-a104-469d-a08b-97329ad84c19 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", + "2023-09-26 11:47:11,052: Added node 831a3803-ae65-4cee-a17e-9c1220035bc9 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", + "2023-09-26 11:47:11,055: Added node 1b935654-065d-4cb9-82d9-d67fe3d3304e to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", + "2023-09-26 11:47:11,059: Added node dd181916-076b-4d8a-ab97-a32052624b09 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", + "2023-09-26 11:47:11,064: Added node 3137ab20-1a3c-49f2-8ee5-c862216b2435 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", + "2023-09-26 11:47:11,067: Added node 6ff8b634-7750-4c6d-8109-abf52514dae5 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n" ] }, { @@ -70,6 +71,11 @@ "# import yaml\n", "\n", "\n", + "from typing import Dict\n", + "from primaite.simulator.network.hardware.base import NIC, Link, Node\n", + "from primaite.simulator.system.services.service import Service\n", + "\n", + "\n", "class PrimaiteSession:\n", "\n", " def __init__(self):\n", @@ -78,7 +84,11 @@ "\n", " @classmethod\n", " def from_config(cls, cfg_path):\n", - " ref_to_uuid = {}\n", + " ref_map_nodes: Dict[str,Node] = {}\n", + " ref_map_services: Dict[str, Service] = {}\n", + " ref_map_links: Dict[str, Link] = {}\n", + " # ref_map_agents: Dict[str, AgentInterface] = {}\n", + "\n", "\n", " game = cls()\n", " with open(cfg_path, 'r') as file:\n", @@ -129,6 +139,8 @@ " dst_ip_address = r_cfg.get('ip_address'),\n", " position = r_num\n", " )\n", + " else:\n", + " print('invalid node type')\n", " if 'services' in node_cfg:\n", " for service_cfg in node_cfg['services']:\n", " service_ref = service_cfg['ref']\n", @@ -144,15 +156,43 @@ " }\n", " if service_type in service_types_mapping:\n", " new_node.software_manager.install(service_types_mapping[service_type])\n", - " service_obj = new_node.software_manager.software[service_type]\n", - " ref_to_uuid[service_ref] = service_obj.uuid\n", + " new_service = new_node.software_manager.software[service_type]\n", + " ref_map_services[service_ref] = new_service\n", " else:\n", " print(f\"service type not found {service_type}\")\n", - "\n", + " # service-dependent options\n", + " if service_type == 'DatabaseClient':\n", + " if 'options' in service_cfg:\n", + " opt = service_cfg['options']\n", + " if 'db_server_ip' in opt:\n", + " new_service.configure(server_ip_address=IPv4Address(opt['db_server_ip']))\n", + " if service_type == 'DNSServer':\n", + " if 'options' in service_cfg:\n", + " opt = service_cfg['options']\n", + " if 'domain_mapping' in opt:\n", + " for domain, ip in opt['domain_mapping'].items():\n", + " new_service.dns_register(domain, ip)\n", + " if 'nics' in node_cfg:\n", + " for nic_num, nic_cfg in node_cfg['nics'].items():\n", + " new_node.connect_nic(NIC(ip_address=nic_cfg['ip_address'], subnet_mask=nic_cfg['subnet_mask']))\n", "\n", " net.add_node(new_node)\n", - " ref_to_uuid[node_ref] = new_node.uuid\n", + " ref_map_nodes[node_ref] = new_node.uuid\n", "\n", + " #2. create links between nodes\n", + " for link_cfg in links_cfg:\n", + " node_a = net.nodes[ref_map_nodes[link_cfg['endpoint_a_ref']]]\n", + " node_b = net.nodes[ref_map_nodes[link_cfg['endpoint_b_ref']]]\n", + " if isinstance(node_a, Switch):\n", + " endpoint_a = node_a.switch_ports[link_cfg['endpoint_a_port']]\n", + " else:\n", + " endpoint_a = node_a.ethernet_port[link_cfg['endpoint_a_port']]\n", + " if isinstance(node_b, Switch):\n", + " endpoint_b = node_b.switch_ports[link_cfg['endpoint_b_port']]\n", + " else:\n", + " endpoint_b = node_b.ethernet_port[link_cfg['endpoint_b_port']]\n", + " new_link = net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b)\n", + " ref_map_links[link_cfg['ref']] = new_link.uuid\n", "\n", " #2. start/setup simulation objects\n", " #3. create agents\n", diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 7ab9b093..66686797 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -221,7 +221,7 @@ class Network(SimComponent): _LOGGER.info(f"Removed node {node.uuid} from network {self.uuid}") self._node_action_manager.remove_action(name=node.uuid) - def connect(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> None: + def connect(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> Optional[Link]: """ Connect two endpoints on the network by creating a link between their NICs/SwitchPorts. @@ -248,6 +248,7 @@ class Network(SimComponent): self._nx_graph.add_edge(endpoint_a.parent.hostname, endpoint_b.parent.hostname) link.parent = self _LOGGER.debug(f"Added link {link.uuid} to connect {endpoint_a} and {endpoint_b}") + return link def remove_link(self, link: Link) -> None: """Disconnect a link from the network. From 79615243e47ad0742d95f41d8f8ebf56de76fc86 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 26 Sep 2023 12:09:41 +0100 Subject: [PATCH 195/980] #1916: Added example usage for FTP --- .../system/ftp_client_server.rst | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/docs/source/simulation_components/system/ftp_client_server.rst b/docs/source/simulation_components/system/ftp_client_server.rst index 084d4a85..0e4aeea3 100644 --- a/docs/source/simulation_components/system/ftp_client_server.rst +++ b/docs/source/simulation_components/system/ftp_client_server.rst @@ -60,3 +60,67 @@ Implementation - Leverages ``SoftwareManager`` for sending payloads over the network. - Provides easy interface for Nodes to transfer files between each other. - Extends base Service class. + + +Example Usage +---------- + +Dependencies +^^^^^^^^^^^^ + +.. code-block:: python + + from ipaddress import IPv4Address + + from primaite.simulator.network.container import Network + from primaite.simulator.network.hardware.nodes.computer import Computer + from primaite.simulator.network.hardware.nodes.server import Server + from primaite.simulator.system.services.ftp.ftp_server import FTPServer + from primaite.simulator.system.services.ftp.ftp_client import FTPClient + +Example peer to peer network +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: python + + net = Network() + + pc1 = Computer(hostname="pc1", ip_address="120.10.10.10", subnet_mask="255.255.255.0") + srv = Server(hostname="srv", ip_address="120.10.10.20", subnet_mask="255.255.255.0") + pc1.power_on() + srv.power_on() + net.connect(pc1.ethernet_port[1], srv.ethernet_port[1]) + +Install the FTP Server +^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: python + + srv.software_manager.install(FTPServer) + pc1.software_manager.install(FTPClient) + client: FTPClient = pc1.software_manager.software['FTPClient'] + ftpserv: FTPServer = srv.software_manager.software['FTPServer'] + +Setting up the FTP Server +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Set up the FTP Server with a file that the client will need to retrieve + +.. code-block:: python + + srv.file_system.create_file('my_file.png') + +Check that file was retrieved +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: python + + client.request_file( + src_folder_name='root', + src_file_name='my_file.png', + dest_folder_name='root', + dest_file_name='test.png', + dest_ip_address=IPv4Address("120.10.10.20") + ) + + print(client.get_file(folder_name="root", file_name="test.png")) From f1346ae278e8659ce0ef4cc15daced2ad88d2ff2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Sep 2023 12:54:56 +0100 Subject: [PATCH 196/980] put in agent parsing skeleton --- example_config.yaml | 6 +-- sandbox.ipynb | 48 +++++++++++++------ src/primaite/game/actor/interface.py | 35 -------------- src/primaite/game/agent/GATE_agents.py | 5 ++ .../game/{actor => agent}/__init__.py | 0 src/primaite/game/{actor => agent}/actions.py | 0 src/primaite/game/agent/interface.py | 35 ++++++++++++++ .../game/{actor => agent}/observations.py | 0 src/primaite/game/{actor => agent}/rewards.py | 0 src/primaite/game/agent/scripted_agents.py | 9 ++++ .../game_layer/test_observations.py | 2 +- 11 files changed, 86 insertions(+), 54 deletions(-) delete mode 100644 src/primaite/game/actor/interface.py create mode 100644 src/primaite/game/agent/GATE_agents.py rename src/primaite/game/{actor => agent}/__init__.py (100%) rename src/primaite/game/{actor => agent}/actions.py (100%) create mode 100644 src/primaite/game/agent/interface.py rename src/primaite/game/{actor => agent}/observations.py (100%) rename src/primaite/game/{actor => agent}/rewards.py (100%) create mode 100644 src/primaite/game/agent/scripted_agents.py diff --git a/example_config.yaml b/example_config.yaml index e3871b4a..79cfccac 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -16,7 +16,7 @@ game_config: agents: - ref: client_1_green_user team: GREEN - team: SCRIPTED_GREEN_ + type: GreenWebBrowsingAgent observation_space: null action_space: actions: @@ -40,7 +40,7 @@ game_config: - ref: client_1_data_manipulation_red_bot team: RED - type: SCRIPTED_RED_ + type: RedDatabaseCorruptingAgent observation_space: network: nodes: @@ -220,7 +220,7 @@ simulation: default_gateway: 192.168.1.1 dns_server: 192.168.1.10 nics: - 2: + 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 diff --git a/sandbox.ipynb b/sandbox.ipynb index aa39c3e9..05efcfa2 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -39,23 +39,23 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2023-09-26 11:47:11,032: Added node bc149bf5-ccc4-4dcd-b419-629ec44b2c9a to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", - "2023-09-26 11:47:11,035: Added node 9cacbaee-33cc-4423-a6c8-fe3dd75b1f87 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", - "2023-09-26 11:47:11,042: Added node d4444d66-7cc3-4cd4-acbd-202cb9fe37ff to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", - "2023-09-26 11:47:11,045: Added node af170371-e99b-42b7-9525-65ca64522539 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", - "2023-09-26 11:47:11,049: Added node d6218f34-a104-469d-a08b-97329ad84c19 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", - "2023-09-26 11:47:11,052: Added node 831a3803-ae65-4cee-a17e-9c1220035bc9 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", - "2023-09-26 11:47:11,055: Added node 1b935654-065d-4cb9-82d9-d67fe3d3304e to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", - "2023-09-26 11:47:11,059: Added node dd181916-076b-4d8a-ab97-a32052624b09 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", - "2023-09-26 11:47:11,064: Added node 3137ab20-1a3c-49f2-8ee5-c862216b2435 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n", - "2023-09-26 11:47:11,067: Added node 6ff8b634-7750-4c6d-8109-abf52514dae5 to Network 2c22989f-8f91-4c61-8be9-1afd733b3e1c\n" + "2023-09-26 12:19:50,895: Added node 0fb262e1-a714-420a-aec7-be37f0deeb75 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", + "2023-09-26 12:19:50,898: Added node 310ca8d7-01e0-401e-b604-705c290e5376 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", + "2023-09-26 12:19:50,900: Added node b3b08f1f-7805-47b2-bdb6-3d83098cd740 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", + "2023-09-26 12:19:50,903: Added node adb37f3e-2307-4123-bff3-01f125883be8 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", + "2023-09-26 12:19:50,906: Added node 1a490716-2ccd-452d-b87e-324d29120b59 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", + "2023-09-26 12:19:50,911: Added node 033460d8-0249-4bdd-aaf0-751b24cc0a1e to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", + "2023-09-26 12:19:50,914: Added node 1e7e4e49-78bf-4031-8372-ee71902720f3 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", + "2023-09-26 12:19:50,916: Added node c9f24a13-e5c8-437b-9234-b0c3f8120e2c to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", + "2023-09-26 12:19:50,920: Added node c881f3ee-2176-493b-a6c2-cad829bf0b6d to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", + "2023-09-26 12:19:50,922: Added node a3ea75d8-bc2c-4713-92a4-2588b4f43ed6 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n" ] }, { @@ -72,9 +72,12 @@ "\n", "\n", "from typing import Dict\n", + "from primaite.game.agent.interface import AbstractAgent\n", "from primaite.simulator.network.hardware.base import NIC, Link, Node\n", "from primaite.simulator.system.services.service import Service\n", "\n", + "from primaite.game.agent.scripted_agents import GreenWebBrowsingAgent, RedDatabaseCorruptingAgent\n", + "from primaite.game.agent.GATE_agents import GATERLAgent\n", "\n", "class PrimaiteSession:\n", "\n", @@ -90,7 +93,7 @@ " # ref_map_agents: Dict[str, AgentInterface] = {}\n", "\n", "\n", - " game = cls()\n", + " session = cls()\n", " with open(cfg_path, 'r') as file:\n", " conf = yaml.safe_load(file)\n", " \n", @@ -177,6 +180,7 @@ " new_node.connect_nic(NIC(ip_address=nic_cfg['ip_address'], subnet_mask=nic_cfg['subnet_mask']))\n", "\n", " net.add_node(new_node)\n", + " new_node.power_on()\n", " ref_map_nodes[node_ref] = new_node.uuid\n", "\n", " #2. create links between nodes\n", @@ -194,11 +198,25 @@ " new_link = net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b)\n", " ref_map_links[link_cfg['ref']] = new_link.uuid\n", "\n", - " #2. start/setup simulation objects\n", + " session.simulation = sim\n", " #3. create agents\n", + " game_cfg = conf['game_config']\n", + " ports_cfg = game_cfg['ports']\n", + " protocols_cfg = game_cfg['protocols']\n", + " agents_cfg = game_cfg['agents']\n", + "\n", + " for agent_cfg in agents_cfg:\n", + " agent_ref = agent_cfg['ref']\n", + " agent_type = agent_cfg['type']\n", + " action_space_cfg = agent_cfg['action_space']\n", + " observation_space_cfg = agent_cfg['observation_space']\n", + " reward_function_cfg = agent_cfg['reward_function']\n", + " if agent_type == 'GreenWebBrowsingAgent':\n", + " new_agent = GreenWebBrowsingAgent()\n", + "\n", + "\n", " #4. set up agents' actions and observation spaces.\n", - " game.simulation = sim\n", - " return game\n", + " return session\n", "\n", "s = PrimaiteSession.from_config('example_config.yaml')\n", "# print(s.simulation.describe_state())" diff --git a/src/primaite/game/actor/interface.py b/src/primaite/game/actor/interface.py deleted file mode 100644 index d1245e71..00000000 --- a/src/primaite/game/actor/interface.py +++ /dev/null @@ -1,35 +0,0 @@ -# TODO: remove this comment... This is just here to point out that I've named this 'actor' rather than 'agent' -# That's because I want to point out that this is disctinct from 'agent' in the reinforcement learning sense of the word -# If you disagree, make a comment in the PR review and we can discuss -from abc import ABC, abstractmethod -from typing import Any, Dict, List - -from pydantic import BaseModel - -from primaite.game.actor.actions import ActionSpace -from primaite.game.actor.observations import ObservationSpace -from primaite.game.actor.rewards import RewardFunction - - -class AbstractActor(ABC): - """Base class for scripted and RL agents.""" - - def __init__(self) -> None: - self.action_space = ActionSpace - self.observation_space = ObservationSpace - self.reward_function = RewardFunction - - -class AbstractScriptedActor(AbstractActor): - """Base class for actors which generate their own behaviour.""" - - ... - - -class AbstractPuppetActor(AbstractActor): - """Base class for actors controlled via external messages, such as RL policies.""" - - ... - - -# class AbstractRLActor(AbstractPuppetActor): ?? diff --git a/src/primaite/game/agent/GATE_agents.py b/src/primaite/game/agent/GATE_agents.py new file mode 100644 index 00000000..5bdfebe4 --- /dev/null +++ b/src/primaite/game/agent/GATE_agents.py @@ -0,0 +1,5 @@ +from primaite.game.agent.interface import AbstractGATEAgent + + +class GATERLAgent(AbstractGATEAgent): + ... diff --git a/src/primaite/game/actor/__init__.py b/src/primaite/game/agent/__init__.py similarity index 100% rename from src/primaite/game/actor/__init__.py rename to src/primaite/game/agent/__init__.py diff --git a/src/primaite/game/actor/actions.py b/src/primaite/game/agent/actions.py similarity index 100% rename from src/primaite/game/actor/actions.py rename to src/primaite/game/agent/actions.py diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py new file mode 100644 index 00000000..b1ade94b --- /dev/null +++ b/src/primaite/game/agent/interface.py @@ -0,0 +1,35 @@ +# TODO: remove this comment... This is just here to point out that I've named this 'actor' rather than 'agent' +# That's because I want to point out that this is disctinct from 'agent' in the reinforcement learning sense of the word +# If you disagree, make a comment in the PR review and we can discuss +from abc import ABC, abstractmethod +from typing import Any, Dict, List, Optional + +from primaite.game.agent.actions import ActionSpace +from primaite.game.agent.observations import ObservationSpace +from primaite.game.agent.rewards import RewardFunction + + +class AbstractAgent(ABC): + """Base class for scripted and RL agents.""" + + def __init__( + self, + action_space: Optional[ActionSpace], + observation_space: Optional[ObservationSpace], + reward_function: Optional[RewardFunction], + ) -> None: + self.action_space: Optional[ActionSpace] = action_space + self.observation_space: Optional[ObservationSpace] = observation_space + self.reward_function: Optional[RewardFunction] = reward_function + + +class AbstractScriptedAgent(AbstractAgent): + """Base class for actors which generate their own behaviour.""" + + ... + + +class AbstractGATEAgent(AbstractAgent): + """Base class for actors controlled via external messages, such as RL policies.""" + + ... diff --git a/src/primaite/game/actor/observations.py b/src/primaite/game/agent/observations.py similarity index 100% rename from src/primaite/game/actor/observations.py rename to src/primaite/game/agent/observations.py diff --git a/src/primaite/game/actor/rewards.py b/src/primaite/game/agent/rewards.py similarity index 100% rename from src/primaite/game/actor/rewards.py rename to src/primaite/game/agent/rewards.py diff --git a/src/primaite/game/agent/scripted_agents.py b/src/primaite/game/agent/scripted_agents.py new file mode 100644 index 00000000..d3becd57 --- /dev/null +++ b/src/primaite/game/agent/scripted_agents.py @@ -0,0 +1,9 @@ +from primaite.game.agent.interface import AbstractScriptedAgent + + +class GreenWebBrowsingAgent(AbstractScriptedAgent): + ... + + +class RedDatabaseCorruptingAgent(AbstractScriptedAgent): + ... diff --git a/tests/integration_tests/game_layer/test_observations.py b/tests/integration_tests/game_layer/test_observations.py index 4f778f78..7f20a938 100644 --- a/tests/integration_tests/game_layer/test_observations.py +++ b/tests/integration_tests/game_layer/test_observations.py @@ -1,6 +1,6 @@ from gym import spaces -from primaite.game.actor.observations import FileObservation +from primaite.game.agent.observations import FileObservation from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.sim_container import Simulation From c096d06bcdf49f10769b320840ca1ee94ddda318 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 26 Sep 2023 15:14:24 +0100 Subject: [PATCH 197/980] #1796: pre installing system software --- .../system/ftp_client_server.rst | 4 ++-- src/primaite/simulator/network/hardware/base.py | 12 ++++++++++++ src/primaite/simulator/network/networks.py | 8 -------- .../_simulator/_system/_services/test_dns.py | 2 -- .../_simulator/_system/_services/test_ftp.py | 2 -- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/source/simulation_components/system/ftp_client_server.rst b/docs/source/simulation_components/system/ftp_client_server.rst index 0e4aeea3..94aef925 100644 --- a/docs/source/simulation_components/system/ftp_client_server.rst +++ b/docs/source/simulation_components/system/ftp_client_server.rst @@ -94,11 +94,11 @@ Example peer to peer network Install the FTP Server ^^^^^^^^^^^^^^^^^^^^^^ +FTP Client should be pre installed on nodes + .. code-block:: python srv.software_manager.install(FTPServer) - pc1.software_manager.install(FTPClient) - client: FTPClient = pc1.software_manager.software['FTPClient'] ftpserv: FTPServer = srv.software_manager.software['FTPServer'] Setting up the FTP Server diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index dd2130d2..00b1f097 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -25,6 +25,8 @@ from primaite.simulator.system.core.session_manager import SessionManager from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.processes.process import Process +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.ftp.ftp_client import FTPClient from primaite.simulator.system.services.service import Service _LOGGER = getLogger(__name__) @@ -937,6 +939,16 @@ class Node(SimComponent): self.arp.nics = self.nics self.session_manager.software_manager = self.software_manager + self._install_system_software() + + def _install_system_software(self): + """Install System Software - software that is usually provided with the OS.""" + # DNS Client + self.software_manager.install(DNSClient) + + # FTP + self.software_manager.install(FTPClient) + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 63cb05e0..6122146b 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -10,9 +10,7 @@ from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database.database_service import DatabaseService -from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.dns.dns_server import DNSServer -from primaite.simulator.system.services.ftp.ftp_client import FTPClient from primaite.simulator.system.services.ftp.ftp_server import FTPServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot @@ -137,14 +135,11 @@ def arcd_uc2_network() -> Network: dns_server=IPv4Address("192.168.1.10"), ) client_1.power_on() - client_1.software_manager.install(DNSClient) network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) client_1.software_manager.install(DataManipulationBot) db_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] db_manipulation_bot.configure(server_ip_address=IPv4Address("192.168.1.14"), payload="DROP TABLE IF EXISTS user;") - client_1.software_manager.install(FTPClient) - # Client 2 client_2 = Computer( hostname="client_2", @@ -154,11 +149,8 @@ def arcd_uc2_network() -> Network: dns_server=IPv4Address("192.168.1.10"), ) client_2.power_on() - client_2.software_manager.install(DNSClient) network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) - client_2.software_manager.install(FTPClient) - # Domain Controller domain_controller = Server( hostname="domain_controller", diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py index f501d14a..d86791cd 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py @@ -21,8 +21,6 @@ def dns_server() -> Node: @pytest.fixture(scope="function") def dns_client() -> Node: node = Node(hostname="dns_client") - node.software_manager.install(software_class=DNSClient) - node.software_manager.software["DNSClient"].start() return node diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py index ea563a88..fce4a487 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py @@ -21,8 +21,6 @@ def ftp_server() -> Node: @pytest.fixture(scope="function") def ftp_client() -> Node: node = Node(hostname="ftp_client") - node.software_manager.install(software_class=FTPClient) - node.software_manager.software["FTPClient"].start() return node From 6202d320a6948b6831bd8801ca79c4b3f3447eaf Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Thu, 28 Sep 2023 12:23:49 +0100 Subject: [PATCH 198/980] #1796: Add ability to create and restore database backups + add more sys log messages + remove the link size checks temporarily --- .../simulator/network/hardware/base.py | 4 +- src/primaite/simulator/network/networks.py | 1 + .../services/database/database_service.py | 101 ++++++++++++++++++ .../system/services/ftp/ftp_client.py | 12 +-- .../system/services/ftp/ftp_server.py | 3 + .../system/services/ftp/ftp_service.py | 9 +- .../system/test_database_on_node.py | 28 +++++ .../system/test_ftp_client_server.py | 4 +- 8 files changed, 146 insertions(+), 16 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 00b1f097..7c08f9fc 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -498,7 +498,9 @@ class Link(SimComponent): def _can_transmit(self, frame: Frame) -> bool: if self.is_up: frame_size_Mbits = frame.size_Mbits # noqa - Leaving it as Mbits as this is how they're expressed - return self.current_load + frame_size_Mbits <= self.bandwidth + # return self.current_load + frame_size_Mbits <= self.bandwidth + # TODO: re add this check once packet size limiting and MTU checks are implemented + return True return False def transmit_frame(self, sender_nic: Union[NIC, SwitchPort], frame: Frame) -> bool: diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 6122146b..f54e1172 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -231,6 +231,7 @@ def arcd_uc2_network() -> Network: database_server.software_manager.install(DatabaseService) database_service: DatabaseService = database_server.software_manager.software["DatabaseService"] # noqa database_service.start() + database_service.configure_backup(backup_server=IPv4Address("192.168.1.16")) database_service._process_sql(ddl, None) # noqa for insert_statement in user_insert_statements: database_service._process_sql(insert_statement, None) # noqa diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 62120fc7..268bd54f 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -1,5 +1,6 @@ import sqlite3 from datetime import datetime +from ipaddress import IPv4Address from sqlite3 import OperationalError from typing import Any, Dict, List, Optional, Union @@ -9,6 +10,7 @@ from primaite.simulator.file_system.file_system import File from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.software_manager import SoftwareManager +from primaite.simulator.system.services.ftp.ftp_client import FTPClient from primaite.simulator.system.services.service import Service, ServiceOperatingState from primaite.simulator.system.software import SoftwareHealthState @@ -23,6 +25,15 @@ class DatabaseService(Service): password: Optional[str] = None connections: Dict[str, datetime] = {} + backup_server: IPv4Address = None + """IP address of the backup server.""" + + latest_backup_directory: str = None + """Directory of latest backup.""" + + latest_backup_file_name: str = None + """File name of latest backup.""" + def __init__(self, **kwargs): kwargs["name"] = "DatabaseService" kwargs["port"] = Port.POSTGRES_SERVER @@ -58,6 +69,96 @@ class DatabaseService(Service): table.add_row([row]) print(table) + def configure_backup(self, backup_server: IPv4Address): + """ + Set up the database backup. + + :param: backup_server_ip: The IP address of the backup server + """ + self.backup_server = backup_server + + def backup_database( + self, backup_directory: Optional[str] = "db_backup", backup_file_name: Optional[str] = None + ) -> bool: + """ + Create a backup of the database to the configured backup server. + + :param: backup_directory: Name of directory where backup will be stored. Optional. + :type: backup_directory: Optional[str] + + :param: backup_file_name: Name of file where backup will be stored. Optional. + :type: backup_file_name: Optional[str] + """ + # check if the backup server was configured + if self.backup_server is None: + self.sys_log.error(f"{self.name} - {self.sys_log.hostname}: not configured.") + return False + + if backup_file_name is None: + backup_file_name = f"{datetime.now().strftime('%d-%m-%Y_%H-%M')}.db" + + software_manager: SoftwareManager = self.software_manager + ftp_client_service: FTPClient = software_manager.software["FTPClient"] + + # send backup copy of database file to FTP server + response = ftp_client_service.send_file( + dest_ip_address=self.backup_server, + src_file_name=self._db_file.name, + src_folder_name=self._db_file.folder.name, + dest_folder_name=backup_directory, + dest_file_name=backup_file_name, + ) + + if response: + self.latest_backup_directory = backup_directory + self.latest_backup_file_name = backup_file_name + return True + + self.sys_log.error("Unable to create database backup.") + return False + + def restore_backup(self, backup_directory: Optional[str] = None, backup_file_name: Optional[str] = None) -> bool: + """ + Restore a backup from backup server. + + :param: backup_directory: Name of directory where backup will be stored. Optional. + :type: backup_directory: Optional[str] + + :param: backup_file_name: Name of file where backup will be stored. Optional. + :type: backup_file_name: Optional[str] + """ + if backup_directory is None: + backup_directory = self.latest_backup_directory + + if backup_file_name is None: + backup_file_name = self.latest_backup_file_name + + software_manager: SoftwareManager = self.software_manager + ftp_client_service: FTPClient = software_manager.software["FTPClient"] + + # retrieve backup file from backup server + response = ftp_client_service.request_file( + src_folder_name=backup_directory, + src_file_name=backup_file_name, + dest_folder_name="downloads", + dest_file_name="database.db", + dest_ip_address=self.backup_server, + ) + + if response: + # replace db file + self.file_system.delete_file(folder_name=self.folder.name, file_name="downloads.db") + + self.file_system.move_file( + src_folder_name="downloads", src_file_name="database.db", dst_folder_name=self.folder.name + ) + self._db_file = self.file_system.get_file(folder_name=self.folder.name, file_name="database.db") + + return self._db_file is not None + + self.sys_log.error("Unable to restore database backup.") + return False + def _create_db_file(self): """Creates the Simulation File and sqlite file in the file system.""" self._db_file: File = self.file_system.create_file(folder_name="database", file_name="database.db", real=True) diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 33fe32be..8359e8a0 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -107,7 +107,7 @@ class FTPClient(FTPServiceABC): payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port ) if payload.status_code == FTPStatusCode.OK: - self.connected = False + self.connected = None return True return False @@ -159,8 +159,9 @@ class FTPClient(FTPServiceABC): if not self.connected: return False else: + self.sys_log.info(f"Sending file {src_folder_name}/{src_file_name} to {str(dest_ip_address)}") # send STOR request - self._send_data( + return self._send_data( file=file_to_transfer, dest_folder_name=dest_folder_name, dest_file_name=dest_file_name, @@ -168,9 +169,6 @@ class FTPClient(FTPServiceABC): dest_port=dest_port, ) - # send disconnect - return self._disconnect_from_server(dest_ip_address=dest_ip_address, dest_port=dest_port) - def request_file( self, dest_ip_address: IPv4Address, @@ -222,14 +220,12 @@ class FTPClient(FTPServiceABC): "dest_folder_name": dest_folder_name, }, ) + self.sys_log.info(f"Requesting file {src_folder_name}/{src_file_name} from {str(dest_ip_address)}") software_manager: SoftwareManager = self.software_manager software_manager.send_payload_to_session_manager( payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port ) - # send disconnect - self._disconnect_from_server(dest_ip_address=dest_ip_address, dest_port=dest_port) - # the payload should have ok status code if payload.status_code == FTPStatusCode.OK: self.sys_log.info(f"File {src_folder_name}/{src_file_name} found in FTP server.") diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 83c883f1..93f8b45b 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -55,6 +55,9 @@ class FTPServer(FTPServiceABC): if session_id: session_details = self._get_session_details(session_id) + if payload.ftp_command is not None: + self.sys_log.info(f"Received FTP {payload.ftp_command.name} command.") + # process server specific commands, otherwise call super if payload.ftp_command == FTPCommand.PORT: # check that the port is valid diff --git a/src/primaite/simulator/system/services/ftp/ftp_service.py b/src/primaite/simulator/system/services/ftp/ftp_service.py index f47b8f64..c6d63751 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_service.py +++ b/src/primaite/simulator/system/services/ftp/ftp_service.py @@ -25,6 +25,9 @@ class FTPServiceABC(Service, ABC): :param: session_id: session ID linked to the FTP Packet. Optional. :type: session_id: Optional[str] """ + if payload.ftp_command is not None: + self.sys_log.info(f"Received FTP {payload.ftp_command.name} command.") + # handle STOR request if payload.ftp_command == FTPCommand.STOR: # check that the file is created in the computed hosting the FTP server @@ -48,11 +51,7 @@ class FTPServiceABC(Service, ABC): file_name = payload.ftp_command_args["dest_file_name"] folder_name = payload.ftp_command_args["dest_folder_name"] file_size = payload.ftp_command_args["file_size"] - self.file_system.create_file( - file_name=file_name, - folder_name=folder_name, - size=file_size, - ) + self.file_system.create_file(file_name=file_name, folder_name=folder_name, size=file_size, real=True) self.sys_log.info( f"Created item in {self.sys_log.hostname}: {payload.ftp_command_args['dest_folder_name']}/" f"{payload.ftp_command_args['dest_file_name']}" diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index c69f131c..38196041 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -3,6 +3,7 @@ from ipaddress import IPv4Address from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.system.services.ftp.ftp_server import FTPServer def test_database_client_server_connection(uc2_network): @@ -57,3 +58,30 @@ def test_database_client_query(uc2_network): db_client.connect() assert db_client.query("SELECT * FROM user;") + + +def test_create_database_backup(uc2_network): + """Run the backup_database method and check if the FTP server has the relevant file.""" + db_server: Server = uc2_network.get_node_by_hostname("database_server") + db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + + # back up should be created + assert db_service.backup_database(backup_file_name="test_file.db") is True + + backup_server: Server = uc2_network.get_node_by_hostname("backup_server") + ftp_server: FTPServer = backup_server.software_manager.software["FTPServer"] + + # backup file should exist in the backup server + assert ftp_server.file_system.get_file(folder_name="db_backup", file_name="test_file.db") is not None + + +def test_restore_backup(uc2_network): + """Run the restore_backup method and check if the backup is properly restored.""" + db_server: Server = uc2_network.get_node_by_hostname("database_server") + db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + + # create a back up + assert db_service.backup_database(backup_file_name="test_file.db") is True + + # back up should be restored + assert db_service.restore_backup(backup_file_name="test_file.db") is True diff --git a/tests/integration_tests/system/test_ftp_client_server.py b/tests/integration_tests/system/test_ftp_client_server.py index fbbe6011..48dc2960 100644 --- a/tests/integration_tests/system/test_ftp_client_server.py +++ b/tests/integration_tests/system/test_ftp_client_server.py @@ -23,7 +23,7 @@ def test_ftp_client_store_file_in_server(uc2_network): # create file on ftp client ftp_client.file_system.create_file(file_name="test_file.txt") - ftp_client.send_file( + assert ftp_client.send_file( src_folder_name="root", src_file_name="test_file.txt", dest_folder_name="client_1_backup", @@ -50,7 +50,7 @@ def test_ftp_client_retrieve_file_from_server(uc2_network): # create file on ftp server ftp_server.file_system.create_file(file_name="test_file.txt", folder_name="file_share") - ftp_client.request_file( + assert ftp_client.request_file( src_folder_name="file_share", src_file_name="test_file.txt", dest_folder_name="downloads", From bca3e6344eab3d7fe310fcb316420afd47e981a7 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Thu, 28 Sep 2023 14:09:32 +0100 Subject: [PATCH 199/980] #1796: documentation --- CHANGELOG.md | 3 +++ .../simulation_components/system/database_client_server.rst | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7147f82b..cc9c26d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,9 @@ SessionManager. - File System - ability to emulate a node's file system during a simulation - Example notebooks - There is currently 1 jupyter notebook which walks through using PrimAITE 1. Creating a simulation - this notebook explains how to build up a simulation using the Python package. (WIP) +- Database: + - `DatabaseClient` and `DatabaseService` created to allow emulation of database actions + - Ability to `backup_database` and `restore_backup` for a `DatabaseService` - Red Agent Services: - Data Manipulator Bot - A red agent service which sends a payload to a target machine. (By default this payload is a SQL query that breaks a database) - DNS Services: `DNSClient` and `DNSServer` diff --git a/docs/source/simulation_components/system/database_client_server.rst b/docs/source/simulation_components/system/database_client_server.rst index 99bbe25e..ef911e0e 100644 --- a/docs/source/simulation_components/system/database_client_server.rst +++ b/docs/source/simulation_components/system/database_client_server.rst @@ -60,6 +60,12 @@ Usage - Retrieve results in a dictionary. - Disconnect when finished. +To create database backups: + +- Configure the backup server the ``DatabaseService`` by providing the Backup server ``IPv4Address`` with ``configure_backup`` +- Create a backup using ``backup_database``. This fails if the backup server is not configured. +- Restore a backup using ``restore_backup``. By default, this uses the database created via ``backup_database``. + Implementation ^^^^^^^^^^^^^^ From 3dc8a0f222636b8f0ee6c9e2703e7077a9765643 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 29 Sep 2023 20:14:42 +0100 Subject: [PATCH 200/980] #1796 - Made the FTP copy real files. Hardcoded the DatabaseService backup folder and filename. Added db restore and final query check to the data manipulation e2e test. --- .../services/database/database_service.py | 39 +++++++++---------- .../system/services/ftp/ftp_client.py | 1 + .../system/services/ftp/ftp_service.py | 10 ++++- .../test_uc2_data_manipulation_scenario.py | 8 ++++ 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 268bd54f..f874b89b 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -41,6 +41,9 @@ class DatabaseService(Service): super().__init__(**kwargs) self._db_file: File self._create_db_file() + self._connect() + + def _connect(self): self._conn = sqlite3.connect(self._db_file.sim_path) self._cursor = self._conn.cursor() @@ -51,8 +54,10 @@ class DatabaseService(Service): :return: List of table names. """ sql = "SELECT name FROM sqlite_master WHERE type='table' AND name != 'sqlite_sequence';" - results = self._process_sql(sql) - return [row[0] for row in results["data"]] + results = self._process_sql(sql, None) + if isinstance(results["data"], dict): + return list(results["data"].keys()) + return [] def show(self, markdown: bool = False): """ @@ -77,9 +82,7 @@ class DatabaseService(Service): """ self.backup_server = backup_server - def backup_database( - self, backup_directory: Optional[str] = "db_backup", backup_file_name: Optional[str] = None - ) -> bool: + def backup_database(self) -> bool: """ Create a backup of the database to the configured backup server. @@ -94,8 +97,7 @@ class DatabaseService(Service): self.sys_log.error(f"{self.name} - {self.sys_log.hostname}: not configured.") return False - if backup_file_name is None: - backup_file_name = f"{datetime.now().strftime('%d-%m-%Y_%H-%M')}.db" + self._conn.close() software_manager: SoftwareManager = self.software_manager ftp_client_service: FTPClient = software_manager.software["FTPClient"] @@ -105,19 +107,19 @@ class DatabaseService(Service): dest_ip_address=self.backup_server, src_file_name=self._db_file.name, src_folder_name=self._db_file.folder.name, - dest_folder_name=backup_directory, - dest_file_name=backup_file_name, + dest_folder_name=str(self.uuid), + dest_file_name="database.db", + real_file_path=self._db_file.sim_path, ) + self._connect() if response: - self.latest_backup_directory = backup_directory - self.latest_backup_file_name = backup_file_name return True self.sys_log.error("Unable to create database backup.") return False - def restore_backup(self, backup_directory: Optional[str] = None, backup_file_name: Optional[str] = None) -> bool: + def restore_backup(self) -> bool: """ Restore a backup from backup server. @@ -127,32 +129,27 @@ class DatabaseService(Service): :param: backup_file_name: Name of file where backup will be stored. Optional. :type: backup_file_name: Optional[str] """ - if backup_directory is None: - backup_directory = self.latest_backup_directory - - if backup_file_name is None: - backup_file_name = self.latest_backup_file_name - software_manager: SoftwareManager = self.software_manager ftp_client_service: FTPClient = software_manager.software["FTPClient"] # retrieve backup file from backup server response = ftp_client_service.request_file( - src_folder_name=backup_directory, - src_file_name=backup_file_name, + src_folder_name=str(self.uuid), + src_file_name="database.db", dest_folder_name="downloads", dest_file_name="database.db", dest_ip_address=self.backup_server, ) if response: + self._conn.close() # replace db file self.file_system.delete_file(folder_name=self.folder.name, file_name="downloads.db") - self.file_system.move_file( src_folder_name="downloads", src_file_name="database.db", dst_folder_name=self.folder.name ) self._db_file = self.file_system.get_file(folder_name=self.folder.name, file_name="database.db") + self._connect() return self._db_file is not None diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 8359e8a0..c22f704b 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -119,6 +119,7 @@ class FTPClient(FTPServiceABC): dest_folder_name: str, dest_file_name: str, dest_port: Optional[Port] = Port.FTP, + real_file_path: Optional[str] = None, ) -> bool: """ Send a file to a target IP address. diff --git a/src/primaite/simulator/system/services/ftp/ftp_service.py b/src/primaite/simulator/system/services/ftp/ftp_service.py index c6d63751..5314b6a3 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_service.py +++ b/src/primaite/simulator/system/services/ftp/ftp_service.py @@ -1,3 +1,4 @@ +import shutil from abc import ABC from ipaddress import IPv4Address from typing import Optional @@ -51,11 +52,17 @@ class FTPServiceABC(Service, ABC): file_name = payload.ftp_command_args["dest_file_name"] folder_name = payload.ftp_command_args["dest_folder_name"] file_size = payload.ftp_command_args["file_size"] - self.file_system.create_file(file_name=file_name, folder_name=folder_name, size=file_size, real=True) + real_file_path = payload.ftp_command_args.get("real_file_path") + is_real = real_file_path is not None + file = self.file_system.create_file( + file_name=file_name, folder_name=folder_name, size=file_size, real=is_real + ) self.sys_log.info( f"Created item in {self.sys_log.hostname}: {payload.ftp_command_args['dest_folder_name']}/" f"{payload.ftp_command_args['dest_file_name']}" ) + if is_real: + shutil.copy(real_file_path, file.sim_path) # file should exist return self.file_system.get_file(file_name=file_name, folder_name=folder_name) is not None except Exception as e: @@ -99,6 +106,7 @@ class FTPServiceABC(Service, ABC): "dest_folder_name": dest_folder_name, "dest_file_name": dest_file_name, "file_size": file.sim_size, + "real_file_path": file.sim_path if file.real else None, }, packet_payload_size=file.sim_size, ) diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index 50998f09..955fa20e 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -15,6 +15,8 @@ def test_data_manipulation(uc2_network): web_server: Server = uc2_network.get_node_by_hostname("web_server") db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + db_service.backup_database() + # First check that the DB client on the web_server can successfully query the users table on the database assert db_client.query("SELECT * FROM user;") @@ -23,3 +25,9 @@ def test_data_manipulation(uc2_network): # Now check that the DB client on the web_server cannot query the users table on the database assert not db_client.query("SELECT * FROM user;") + + # Now restore the database + db_service.restore_backup() + + # Now check that the DB client on the web_server can successfully query the users table on the database + assert db_client.query("SELECT * FROM user;") From 84405d7ed3578f4f99e924149bac52ebc441a55b Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 29 Sep 2023 20:19:26 +0100 Subject: [PATCH 201/980] #1796 - Added docstring to the test_uc2_data_manipulation_scenario.py --- .../e2e_integration_tests/test_uc2_data_manipulation_scenario.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index 955fa20e..13f4d1f3 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -6,6 +6,7 @@ from primaite.simulator.system.services.red_services.data_manipulation_bot impor def test_data_manipulation(uc2_network): + """Tests the UC2 data manipulation scenario end-to-end. Is a work in progress.""" client_1: Computer = uc2_network.get_node_by_hostname("client_1") db_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] From fdebfce406b8e28d1e3efb841d8e2d7ec6124187 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Mon, 2 Oct 2023 12:14:59 +0100 Subject: [PATCH 202/980] #1796: Fix test + making the restore test better --- .../system/test_database_on_node.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 38196041..92056981 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -66,13 +66,13 @@ def test_create_database_backup(uc2_network): db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] # back up should be created - assert db_service.backup_database(backup_file_name="test_file.db") is True + assert db_service.backup_database() is True backup_server: Server = uc2_network.get_node_by_hostname("backup_server") ftp_server: FTPServer = backup_server.software_manager.software["FTPServer"] # backup file should exist in the backup server - assert ftp_server.file_system.get_file(folder_name="db_backup", file_name="test_file.db") is not None + assert ftp_server.file_system.get_file(folder_name=db_service.uuid, file_name="database.db") is not None def test_restore_backup(uc2_network): @@ -81,7 +81,14 @@ def test_restore_backup(uc2_network): db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] # create a back up - assert db_service.backup_database(backup_file_name="test_file.db") is True + assert db_service.backup_database() is True + + # delete database locally + db_service.file_system.delete_file(folder_name="database", file_name="database.db") + + assert db_service.file_system.get_file(folder_name="database", file_name="database.db") is None # back up should be restored - assert db_service.restore_backup(backup_file_name="test_file.db") is True + assert db_service.restore_backup() is True + + assert db_service.file_system.get_file(folder_name="database", file_name="database.db") is not None From 2b617e01a39263a64701f33f99e8773b28c1eac6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 2 Oct 2023 17:21:43 +0100 Subject: [PATCH 203/980] Finalise actions interface --- example_config.yaml | 330 ++++++++++++++-- sandbox.ipynb | 489 ++++++++++++++++++++++-- src/primaite/game/agent/actions.py | 377 +++++++++++++++++- src/primaite/game/agent/interface.py | 46 ++- src/primaite/game/agent/observations.py | 243 +++++++----- src/primaite/game/agent/rewards.py | 25 +- src/primaite/game/session.py | 46 +++ 7 files changed, 1382 insertions(+), 174 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index 79cfccac..8cf401cc 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -27,11 +27,11 @@ game_config: - type: LOGON - type: LOGOFF applications: - - application_ref: client_2_web_browser - actions: - - type: EXECUTE - execution_definition: - target_address: arcd.com + # - application_ref: client_2_web_browser + # actions: + # - type: EXECUTE + # execution_definition: + # target_address: arcd.com reward_function: null agent_settings: start_step: 5 @@ -42,7 +42,8 @@ game_config: team: RED type: RedDatabaseCorruptingAgent observation_space: - network: + type: UC2RedObservation + options: nodes: - node_ref: client_1 observations: @@ -85,13 +86,307 @@ game_config: - ref: defender team: blue - type: GATE_RL_AGENT + type: GATERLAgent observation_space: - network: + type: UC2BlueObservation + options: nodes: - node_ref: router_1 #TODO: more sub-options here - node_ref: switch_1 - node_ref: switch_2 + - node_ref: domain_controller + services: + - service_ref: domain_controller_dns_server + - node_ref: web_server + services: + - service_ref: web_server_database_client + - node_ref: database_server + services: + - service_ref: database_service + folders: + - folder_name: database + files: + - file_name: database.db + - node_ref: backup_server + # services: + # - service_ref: backup_service + - node_ref: security_suite + - node_ref: client_1 + - node_ref: client_2 + links: + - link_ref: router_1___switch_1 + - link_ref: router_1___switch_2 + - link_ref: switch_1___domain_controller + - link_ref: switch_1___web_server + - link_ref: switch_1___database_server + - link_ref: switch_1___backup_server + - link_ref: switch_1___security_suite + - link_ref: switch_2___client_1 + - link_ref: switch_2___client_2 + - link_ref: switch_2___security_suite + acl: + router_node_ref: router_1 + ics: null + + + action_space: + action_list: + - DONOTHING + - NODE_SERVICE_SCAN + - NODE_SERVICE_STOP + # - NODE_SERVICE_START + # - NODE_SERVICE_PAUSE + # - NODE_SERVICE_RESUME + # - NODE_SERVICE_RESTART + # - NODE_SERVICE_DISABLE + # - NODE_SERVICE_ENABLE + # - NODE_FILE_SCAN + # - NODE_FILE_CHECKHASH + # - NODE_FILE_DELETE + # - NODE_FILE_REPAIR + # - NODE_FILE_RESTORE + # - NODE_FOLDER_SCAN + # - NODE_FOLDER_CHECKHASH + # - NODE_FOLDER_REPAIR + # - NODE_FOLDER_RESTORE + # - NODE_OS_SCAN + # - NODE_SHUTDOWN + # - NODE_STARTUP + # - NODE_RESET + # - NETWORK_ACL_ADDRULE + # - NETWORK_ACL_REMOVERULE + # - NETWORK_NIC_ENABLE + - NETWORK_NIC_DISABLE + + action_map: + 0: + - action: DONOTHING + options: {} + # scan webapp service + 1: + - action: NODE_SERVICE_SCAN + options: + - node_id: 2 + - service_id: 1 + # stop webapp service + 2: + - action: NODE_SERVICE_STOP + options: + - node_id: 2 + - service_id: 1 + # start webapp service + 3: + - action: "NODE_SERVICE_START" + options: + - node_id: 2 + - service_id: 1 + 4: + - action: "NODE_SERVICE_PAUSE" + options: + - node_id: 2 + - service_id: 1 + 5: + - action: "NODE_SERVICE_RESUME" + options: + - node_id: 2 + - service_id: 1 + 6: + - action: "NODE_SERVICE_RESTART" + options: + - node_id: 2 + - service_id: 1 + 7: + - action: "NODE_SERVICE_DISABLE" + options: + - node_id: 2 + - service_id: 1 + 8: + - action: "NODE_SERVICE_ENABLE" + options: + - node_id: 2 + - service_id: 1 + 9: + - action: "NODE_FILE_SCAN" + options: + - node_id: 3 + - folder_id: 1 + - file_id: 1 + 10: + - action: "NODE_FILE_CHECKHASH" + options: + - node_id: 3 + - folder_id: 1 + - file_id: 1 + 11: + - action: "NODE_FILE_DELETE" + options: + - node_id: 3 + - folder_id: 1 + - file_id: 1 + 12: + - action: "NODE_FILE_REPAIR" + options: + - node_id: 3 + - folder_id: 1 + - file_id: 1 + 13: + - action: "NODE_FILE_RESTORE" + options: + - node_id: 3 + - folder_id: 1 + - file_id: 1 + 14: + - action: "NODE_FOLDER_SCAN" + options: + - node_id: 3 + - folder_id: 1 + 15: + - action: "NODE_FOLDER_CHECKHASH" + options: + - node_id: 3 + - folder_id: 1 + 16: + - action: "NODE_FOLDER_REPAIR" + options: + - node_id: 3 + - folder_id: 1 + 17: + - action: "NODE_FOLDER_RESTORE" + options: + - node_id: 3 + - folder_id: 1 + 18: + - action: "NODE_OS_SCAN" + options: + - node_id: 3 + 19: + - action: "NODE_SHUTDOWN" + options: + - node_id: 6 + 20: + - action: "NODE_STARTUP" + options: + - node_id: 6 + 21: + - action: "NODE_RESET" + options: + - node_id: 6 + 22: + - action: "NETWORK_ACL_ADDRULE" + options: + - position: 6 + - permission: 2 + - source_node_id: ... + - dest_node_id: ... + - source_port_id: ... + - dest_port_id: ... + - protocol_id: ... + 23: + - action: "NETWORK_ACL_ADDRULE" + options: + - position: 5 + - permission: 2 + - source_node_id: ... + - dest_node_id: ... + - source_port_id: ... + - dest_port_id: ... + - protocol_id: ... + 24: + - action: "NETWORK_ACL_ADDRULE" + options: + - position: 4 + - permission: 2 + - source_node_id: ... + - dest_node_id: ... + - source_port_id: ... + - dest_port_id: ... + - protocol_id: ... + 25: + - action: "NETWORK_ACL_ADDRULE" + options: + - position: 3 + - permission: 2 + - source_node_id: ... + - dest_node_id: ... + - source_port_id: ... + - dest_port_id: ... + - protocol_id: ... + 26: + - action: "NETWORK_ACL_ADDRULE" + options: + - position: 2 + - permission: 2 + - source_node_id: ... + - dest_node_id: ... + - source_port_id: ... + - dest_port_id: ... + - protocol_id: ... + 27: + - action: "NETWORK_ACL_ADDRULE" + options: + - position: 1 + - permission: 2 + - source_node_id: ... + - dest_node_id: ... + - source_port_id: ... + - dest_port_id: ... + - protocol_id: ... + 28: + - action: "NETWORK_ACL_REMOVERULE" + options: + - position: 0 + 29: + - action: "NETWORK_ACL_REMOVERULE" + options: + - position: 1 + 30: + - action: "NETWORK_ACL_REMOVERULE" + options: + - position: 2 + 31: + - action: "NETWORK_ACL_REMOVERULE" + options: + - position: 3 + 32: + - action: "NETWORK_ACL_REMOVERULE" + options: + - position: 4 + 33: + - action: "NETWORK_ACL_REMOVERULE" + options: + - position: 5 + 34: + - action: "NETWORK_ACL_REMOVERULE" + options: + - position: 6 + 35: + - action: "NETWORK_ACL_REMOVERULE" + options: + - position: 7 + 36: + - action: "NETWORK_ACL_REMOVERULE" + options: + - position: 8 + 37: + - action: "NETWORK_ACL_REMOVERULE" + options: + - position: 9 + 38: + - action: "NETWORK_NIC_DISABLE" + options: + - node_id: 6 + - nic_index: 1 + 39: + - action: "NETWORK_NIC_ENABLE" + options: + - node_id: 6 + - nic_index: 1 + + options: + nodes: + - node_ref: router_1 + - node_ref: switch_1 + - node_ref: switch_2 - node_ref: domain_controller - node_ref: web_server - node_ref: database_server @@ -99,18 +394,13 @@ game_config: - node_ref: security_suite - node_ref: client_1 - node_ref: client_2 - links: - - link_ref: ... # - acl: ... # - ics: ... # + max_folders_per_node: 2 + max_files_per_folder: 2 + max_services_per_node: 2 + max_nics_per_node: 8 + max_acl_rules: 10 - action_space: - actions: - - type: DO_NOTHING - network: - nodes: - - node_ref: router_1 reward_function: # ... agent_settings: @@ -175,7 +465,6 @@ simulation: domain_mapping: arcd.com: 192.168.1.12 # web server - - ref: web_server type: server hostname: web_server @@ -200,7 +489,6 @@ simulation: - ref: database_service type: DatabaseService - - ref: backup_server type: server hostname: backup_server @@ -224,7 +512,6 @@ simulation: ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 - - ref: client_1 type: computer hostname: client_1 @@ -251,7 +538,6 @@ simulation: - ref: client_2_dns_client type: DNSClient - links: - ref: router_1___switch_1 endpoint_a_ref: router_1 diff --git a/sandbox.ipynb b/sandbox.ipynb index 05efcfa2..3ff72170 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -2,9 +2,18 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The autoreload extension is already loaded. To reload it, use:\n", + " %reload_ext autoreload\n" + ] + } + ], "source": [ "%load_ext autoreload\n", "%autoreload 2" @@ -12,7 +21,381 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.game.session import PrimaiteSession\n", + "from primaite.simulator.sim_container import Simulation\n", + "from primaite.game.agent.interface import AbstractAgent\n", + "from primaite.simulator.network.networks import arcd_uc2_network\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "sess = PrimaiteSession()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "network = sess.simulation.network" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "from ipaddress import IPv4Address\n", + "\n", + "from primaite.simulator.network.container import Network\n", + "from primaite.simulator.network.hardware.base import NIC\n", + "from primaite.simulator.network.hardware.nodes.computer import Computer\n", + "from primaite.simulator.network.hardware.nodes.router import ACLAction, Router\n", + "from primaite.simulator.network.hardware.nodes.server import Server\n", + "from primaite.simulator.network.hardware.nodes.switch import Switch\n", + "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", + "from primaite.simulator.network.transmission.transport_layer import Port\n", + "from primaite.simulator.system.applications.database_client import DatabaseClient\n", + "from primaite.simulator.system.services.database_service import DatabaseService\n", + "from primaite.simulator.system.services.dns_client import DNSClient\n", + "from primaite.simulator.system.services.dns_server import DNSServer\n", + "from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-10-02 15:10:20,422: Added node 6abb7664-4d17-45ff-a3c7-dbcccffcfd6d to Network 045a3114-4aac-4687-a10e-432cfd138325\n", + "2023-10-02 15:10:20,424: Added node 3edbc521-3c80-47e3-8017-dbc38fb00a73 to Network 045a3114-4aac-4687-a10e-432cfd138325\n", + "2023-10-02 15:10:20,428: Added node 94457fb9-04a1-4dc1-9ff7-b64df0da7424 to Network 045a3114-4aac-4687-a10e-432cfd138325\n", + "2023-10-02 15:10:20,432: Added node 0d311d72-139c-41bf-aef7-fa9b01b124d7 to Network 045a3114-4aac-4687-a10e-432cfd138325\n", + "2023-10-02 15:10:20,439: Added node 6161e785-f377-48de-aa4f-20d3646da635 to Network 045a3114-4aac-4687-a10e-432cfd138325\n", + "2023-10-02 15:10:20,444: Added node 55a9e9f8-ee3a-4c28-9b6d-c0c0d78a3f6a to Network 045a3114-4aac-4687-a10e-432cfd138325\n", + "2023-10-02 15:10:20,447: Added node 2f04ca45-3439-489a-81f7-41cca5ae8adc to Network 045a3114-4aac-4687-a10e-432cfd138325\n", + "2023-10-02 15:10:20,531: Added node 98660c30-8e48-4b96-967a-d62ca71b4d6d to Network 045a3114-4aac-4687-a10e-432cfd138325\n", + "2023-10-02 15:10:20,545: Added node 1a184184-b204-40de-986a-4d7459036dbe to Network 045a3114-4aac-4687-a10e-432cfd138325\n", + "2023-10-02 15:10:20,551: Added node 17b92b9a-6805-4677-85f7-c0c0521a6e25 to Network 045a3114-4aac-4687-a10e-432cfd138325\n", + "2023-10-02 15:10:20,555::ERROR::primaite.simulator.network.hardware.base::175::NIC da:f3:1b:87:24:20/192.168.10.110 cannot be enabled as it is not connected to a Link\n" + ] + } + ], + "source": [ + "router_1 = Router(hostname=\"router_1\", num_ports=5)\n", + "router_1.power_on()\n", + "router_1.configure_port(port=1, ip_address=\"192.168.1.1\", subnet_mask=\"255.255.255.0\")\n", + "router_1.configure_port(port=2, ip_address=\"192.168.10.1\", subnet_mask=\"255.255.255.0\")\n", + "\n", + "# Switch 1\n", + "switch_1 = Switch(hostname=\"switch_1\", num_ports=8)\n", + "switch_1.power_on()\n", + "network.connect(endpoint_a=router_1.ethernet_ports[1], endpoint_b=switch_1.switch_ports[8])\n", + "router_1.enable_port(1)\n", + "\n", + "# Switch 2\n", + "switch_2 = Switch(hostname=\"switch_2\", num_ports=8)\n", + "switch_2.power_on()\n", + "network.connect(endpoint_a=router_1.ethernet_ports[2], endpoint_b=switch_2.switch_ports[8])\n", + "router_1.enable_port(2)\n", + "\n", + "# Client 1\n", + "client_1 = Computer(\n", + " hostname=\"client_1\",\n", + " ip_address=\"192.168.10.21\",\n", + " subnet_mask=\"255.255.255.0\",\n", + " default_gateway=\"192.168.10.1\",\n", + " dns_server=IPv4Address(\"192.168.1.10\"),\n", + ")\n", + "client_1.power_on()\n", + "client_1.software_manager.install(DNSClient)\n", + "client_1_dns_client_service: DNSServer = client_1.software_manager.software[\"DNSClient\"] # noqa\n", + "client_1_dns_client_service.start()\n", + "network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1])\n", + "client_1.software_manager.install(DataManipulationBot)\n", + "db_manipulation_bot: DataManipulationBot = client_1.software_manager.software[\"DataManipulationBot\"]\n", + "db_manipulation_bot.configure(server_ip_address=IPv4Address(\"192.168.1.14\"), payload=\"DROP TABLE IF EXISTS user;\")\n", + "\n", + "# Client 2\n", + "client_2 = Computer(\n", + " hostname=\"client_2\",\n", + " ip_address=\"192.168.10.22\",\n", + " subnet_mask=\"255.255.255.0\",\n", + " default_gateway=\"192.168.10.1\",\n", + " dns_server=IPv4Address(\"192.168.1.10\"),\n", + ")\n", + "client_2.power_on()\n", + "client_2.software_manager.install(DNSClient)\n", + "client_2_dns_client_service: DNSServer = client_2.software_manager.software[\"DNSClient\"] # noqa\n", + "client_2_dns_client_service.start()\n", + "network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2])\n", + "\n", + "# Domain Controller\n", + "domain_controller = Server(\n", + " hostname=\"domain_controller\",\n", + " ip_address=\"192.168.1.10\",\n", + " subnet_mask=\"255.255.255.0\",\n", + " default_gateway=\"192.168.1.1\",\n", + ")\n", + "domain_controller.power_on()\n", + "domain_controller.software_manager.install(DNSServer)\n", + "\n", + "network.connect(endpoint_b=domain_controller.ethernet_port[1], endpoint_a=switch_1.switch_ports[1])\n", + "\n", + "# Database Server\n", + "database_server = Server(\n", + " hostname=\"database_server\",\n", + " ip_address=\"192.168.1.14\",\n", + " subnet_mask=\"255.255.255.0\",\n", + " default_gateway=\"192.168.1.1\",\n", + " dns_server=IPv4Address(\"192.168.1.10\"),\n", + ")\n", + "database_server.power_on()\n", + "network.connect(endpoint_b=database_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[3])\n", + "\n", + "ddl = \"\"\"\n", + "CREATE TABLE IF NOT EXISTS user (\n", + "id INTEGER PRIMARY KEY AUTOINCREMENT,\n", + "name VARCHAR(50) NOT NULL,\n", + "email VARCHAR(50) NOT NULL,\n", + "age INT,\n", + "city VARCHAR(50),\n", + "occupation VARCHAR(50)\n", + ");\"\"\"\n", + "\n", + "user_insert_statements = [\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('John Doe', 'johndoe@example.com', 32, 'New York', 'Engineer');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Jane Smith', 'janesmith@example.com', 27, 'Los Angeles', 'Designer');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Bob Johnson', 'bobjohnson@example.com', 45, 'Chicago', 'Manager');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Alice Lee', 'alicelee@example.com', 22, 'San Francisco', 'Student');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('David Kim', 'davidkim@example.com', 38, 'Houston', 'Consultant');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Emily Chen', 'emilychen@example.com', 29, 'Seattle', 'Software Developer');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Frank Wang', 'frankwang@example.com', 55, 'New York', 'Entrepreneur');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Grace Park', 'gracepark@example.com', 31, 'Los Angeles', 'Marketing Specialist');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Henry Wu', 'henrywu@example.com', 40, 'Chicago', 'Accountant');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Isabella Kim', 'isabellakim@example.com', 26, 'San Francisco', 'Graphic Designer');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Jake Lee', 'jakelee@example.com', 33, 'Houston', 'Sales Manager');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Kelly Chen', 'kellychen@example.com', 28, 'Seattle', 'Web Developer');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Lucas Liu', 'lucasliu@example.com', 42, 'New York', 'Lawyer');\", # noqa\n", + " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Maggie Wang', 'maggiewang@example.com', 30, 'Los Angeles', 'Data Analyst');\", # noqa\n", + "]\n", + "database_server.software_manager.install(DatabaseService)\n", + "database_service: DatabaseService = database_server.software_manager.software[\"DatabaseService\"] # noqa\n", + "database_service.start()\n", + "database_service._process_sql(ddl, None) # noqa\n", + "for insert_statement in user_insert_statements:\n", + " database_service._process_sql(insert_statement, None) # noqa\n", + "\n", + "# Web Server\n", + "web_server = Server(\n", + " hostname=\"web_server\",\n", + " ip_address=\"192.168.1.12\",\n", + " subnet_mask=\"255.255.255.0\",\n", + " default_gateway=\"192.168.1.1\",\n", + " dns_server=IPv4Address(\"192.168.1.10\"),\n", + ")\n", + "web_server.power_on()\n", + "web_server.software_manager.install(DatabaseClient)\n", + "\n", + "database_client: DatabaseClient = web_server.software_manager.software[\"DatabaseClient\"]\n", + "database_client.configure(server_ip_address=IPv4Address(\"192.168.1.14\"))\n", + "network.connect(endpoint_b=web_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[2])\n", + "database_client.run()\n", + "database_client.connect()\n", + "\n", + "# register the web_server to a domain\n", + "dns_server_service: DNSServer = domain_controller.software_manager.software[\"DNSServer\"] # noqa\n", + "dns_server_service.start()\n", + "dns_server_service.dns_register(\"arcd.com\", web_server.ip_address)\n", + "\n", + "# Backup Server\n", + "backup_server = Server(\n", + " hostname=\"backup_server\",\n", + " ip_address=\"192.168.1.16\",\n", + " subnet_mask=\"255.255.255.0\",\n", + " default_gateway=\"192.168.1.1\",\n", + " dns_server=IPv4Address(\"192.168.1.10\"),\n", + ")\n", + "backup_server.power_on()\n", + "network.connect(endpoint_b=backup_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[4])\n", + "\n", + "# Security Suite\n", + "security_suite = Server(\n", + " hostname=\"security_suite\",\n", + " ip_address=\"192.168.1.110\",\n", + " subnet_mask=\"255.255.255.0\",\n", + " default_gateway=\"192.168.1.1\",\n", + " dns_server=IPv4Address(\"192.168.1.10\"),\n", + ")\n", + "security_suite.power_on()\n", + "network.connect(endpoint_b=security_suite.ethernet_port[1], endpoint_a=switch_1.switch_ports[7])\n", + "security_suite.connect_nic(NIC(ip_address=\"192.168.10.110\", subnet_mask=\"255.255.255.0\"))\n", + "network.connect(endpoint_b=security_suite.ethernet_port[2], endpoint_a=switch_2.switch_ports[7])\n", + "\n", + "router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22)\n", + "\n", + "router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23)\n", + "\n", + "# Allow PostgreSQL requests\n", + "router_1.acl.add_rule(\n", + " action=ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER, position=0\n", + ")\n", + "\n", + "# Allow DNS requests\n", + "router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.DNS, dst_port=Port.DNS, position=1)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "node_uuid_list = list(sess.simulation.network.nodes.keys())" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.game.agent.actions import ActionManager" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "actman = ActionManager(sess.simulation, [\"DONOTHING\", \"NODE_SERVICE_SCAN\", \"NODE_SERVICE_STOP\", \"NODE_FOLDER_SCAN\"],node_uuid_list,act_map={\n", + " 0:{\n", + " \"action\": \"DONOTHING\",\n", + " \"options\": {}\n", + " },\n", + " 1:{\n", + " \"action\": \"NODE_SERVICE_SCAN\",\n", + " \"options\": {\"node_id\":0, \"service_id\":0},\n", + " },\n", + " 2:{\n", + " \"action\": \"NODE_SERVICE_SCAN\",\n", + " \"options\": {\"node_id\":1, \"service_id\":0},\n", + " },\n", + " 3:{\n", + " \"action\": \"NODE_FOLDER_SCAN\",\n", + " \"options\": {\"node_id\":4, \"folder_id\":0},\n", + " }\n", + "})" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "act_id, act_options = actman.get_action(3)\n", + "my_trial_act = actman.form_request(action_identifier=act_id, action_options=act_options)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "sess.simulation.apply_action(my_trial_act)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['network',\n", + " 'node',\n", + " '6161e785-f377-48de-aa4f-20d3646da635',\n", + " 'file_system',\n", + " 'folder',\n", + " '5aefe92b-923c-4684-b3bf-e78dd18d4771',\n", + " 'scan']" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_trial_act" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sess.step()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sess.step_counter" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from gym import spaces" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sp = spaces.Tuple( (spaces.MultiDiscrete([3, 2]), spaces.MultiDiscrete([3, 2]), spaces.MultiDiscrete([3, 2]),))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sp.sample()" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -39,40 +422,16 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-09-26 12:19:50,895: Added node 0fb262e1-a714-420a-aec7-be37f0deeb75 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", - "2023-09-26 12:19:50,898: Added node 310ca8d7-01e0-401e-b604-705c290e5376 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", - "2023-09-26 12:19:50,900: Added node b3b08f1f-7805-47b2-bdb6-3d83098cd740 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", - "2023-09-26 12:19:50,903: Added node adb37f3e-2307-4123-bff3-01f125883be8 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", - "2023-09-26 12:19:50,906: Added node 1a490716-2ccd-452d-b87e-324d29120b59 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", - "2023-09-26 12:19:50,911: Added node 033460d8-0249-4bdd-aaf0-751b24cc0a1e to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", - "2023-09-26 12:19:50,914: Added node 1e7e4e49-78bf-4031-8372-ee71902720f3 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", - "2023-09-26 12:19:50,916: Added node c9f24a13-e5c8-437b-9234-b0c3f8120e2c to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", - "2023-09-26 12:19:50,920: Added node c881f3ee-2176-493b-a6c2-cad829bf0b6d to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n", - "2023-09-26 12:19:50,922: Added node a3ea75d8-bc2c-4713-92a4-2588b4f43ed6 to Network 9318bac2-d9f4-4e71-bb4c-09ffc573ed1c\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "service type not found DatabaseBackup\n", - "service type not found WebBrowser\n" - ] - } - ], + "outputs": [], "source": [ "# import yaml\n", "\n", "\n", "from typing import Dict\n", "from primaite.game.agent.interface import AbstractAgent\n", + "from primaite.game.agent.observations import AclObservation, FileObservation, FolderObservation, ICSObservation, LinkObservation, NicObservation, NodeObservation, NullObservation, ServiceObservation, UC2BlueObservation, UC2RedObservation\n", "from primaite.simulator.network.hardware.base import NIC, Link, Node\n", "from primaite.simulator.system.services.service import Service\n", "\n", @@ -130,8 +489,8 @@ " subnet_mask=port_cfg['subnet_mask'])\n", " if 'acl' in node_cfg:\n", " for r_num, r_cfg in node_cfg['acl'].items():\n", - " # excuse the uncommon walrus operator ` := `. It's just here as a shorthand, so that we can do\n", - " # both of these things once: check if a key is defined, access and convert it to a \n", + " # excuse the uncommon walrus operator ` := `. It's just here as a shorthand, to avoid repeating \n", + " # this: 'r_cfg.get('src_port')'\n", " # Port/IPProtocol. TODO Refactor\n", " new_node.acl.add_rule(\n", " action = ACLAction[r_cfg['action']],\n", @@ -211,8 +570,70 @@ " action_space_cfg = agent_cfg['action_space']\n", " observation_space_cfg = agent_cfg['observation_space']\n", " reward_function_cfg = agent_cfg['reward_function']\n", + " \n", + " # CREATE OBSERVATION SPACE\n", + " if observation_space_cfg is None:\n", + " obs_space = NullObservation()\n", + " elif observation_space_cfg['type'] == 'UC2BlueObservation':\n", + " node_obs_list = []\n", + " link_obs_list = []\n", + " \n", + " \n", + " #node ip to index maps ip addresses to node id, as there are potentially multiple nics on a node, there are multiple ip addresses\n", + " node_ip_to_index = {}\n", + " for node_idx, node_cfg in enumerate(nodes_cfg):\n", + " n_ref = node_cfg['ref']\n", + " n_obj = net.nodes[ref_map_nodes[n_ref]]\n", + " for nic_uuid, nic_obj in n_obj.nics.items():\n", + " node_ip_to_index[nic_obj.ip_address] = node_idx + 2\n", + "\n", + " \n", + " \n", + " for node_obs_cfg in observation_space_cfg['options']['nodes']:\n", + " node_ref = node_obs_cfg['node_ref']\n", + " folder_obs_list = []\n", + " service_obs_list = []\n", + " if 'services' in node_obs_cfg:\n", + " for service_obs_cfg in node_obs_cfg['services']:\n", + " service_obs_list.append(ServiceObservation(where=['network','nodes',ref_map_nodes[node_ref],'services',ref_map_services[service_obs_cfg['service_ref']]]))\n", + " if 'folders' in node_obs_cfg:\n", + " for folder_obs_cfg in node_obs_cfg['folders']:\n", + " file_obs_list = []\n", + " if 'files' in folder_obs_cfg:\n", + " for file_obs_cfg in folder_obs_cfg['files']:\n", + " file_obs_list.append(FileObservation(where=['network','nodes',ref_map_nodes[node_ref], 'folders',folder_obs_cfg['folder_name'], 'files', file_obs_cfg['file_name']]))\n", + " folder_obs_list.append(FolderObservation(where=['network','nodes',ref_map_nodes[node_ref], 'folders',folder_obs_cfg['folder_name']], files=file_obs_list))\n", + " nic_obs_list = []\n", + " for nic_uuid in net.nodes[ref_map_nodes[node_obs_cfg['node_ref']]].nics.keys():\n", + " nic_obs_list.append(NicObservation(where=['network','nodes',ref_map_nodes[node_ref],'NICs',nic_uuid]))\n", + " node_obs_list.append(NodeObservation(where=['network','nodes',ref_map_nodes[node_ref]], services=service_obs_list, folders=folder_obs_list,nics=nic_obs_list, logon_status=False))\n", + " for link_obs_cfg in observation_space_cfg['options']['links']:\n", + " link_ref = link_obs_cfg['link_ref']\n", + " link_obs_list.append(LinkObservation(where=['network' ,'links', ref_map_links[link_ref]]))\n", + "\n", + " acl_obs = AclObservation(node_ip_to_id=node_ip_to_index, ports=game_cfg['ports'], protocols=game_cfg['ports'], where=['network','nodes',observation_space_cfg['options']['acl']['router_node_ref']])\n", + " obs_space = UC2BlueObservation(nodes=node_obs_list,links=link_obs_list,acl=acl_obs, ics=ICSObservation())\n", + " elif observation_space_cfg['type'] == 'UC2RedObservation':\n", + " obs_space = UC2RedObservation.from_config(observation_space_cfg['options'], sim=sim)\n", + " else:\n", + " print(\"observation space config not specified correctly.\")\n", + " obs_space = NullObservation()\n", + " \n", + " # CREATE ACTION SPACE\n", + " \n", + "\n", + "\n", + " # CREATE REWARD FUNCTION\n", + "\n", + " # CREATE AGENT\n", " if agent_type == 'GreenWebBrowsingAgent':\n", - " new_agent = GreenWebBrowsingAgent()\n", + " ...\n", + " elif agent_type == 'GATERLAgent':\n", + " ...\n", + " elif agent_type == 'RedDatabaseCorruptingAgent':\n", + " ...\n", + " else:\n", + " print(\"agent type not found\")\n", "\n", "\n", " #4. set up agents' actions and observation spaces.\n", @@ -228,7 +649,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(s.simulation.describe_state())" + "s.agents" ] }, { diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index cefd9917..cb7061fc 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -1,21 +1,374 @@ from abc import ABC, abstractmethod -from typing import Any, Dict, List - -from pydantic import BaseModel +from typing import Any, Dict, List, Optional, Tuple +import itertools -class AbstractAction(BaseModel): +from primaite.simulator.sim_container import Simulation + +from gym import spaces + +class ExecutionDefiniton(ABC): + """ + Converter from actions to simulator requests. + + Allows adding extra data/context that defines in more detail what an action means. + """ + + """ + Examples: + ('node', 'service', 'scan', 2, 0) means scan the first service on node index 2 + -> ['network', 'nodes', , 'services', , 'scan'w] + """ + ... + + +class AbstractAction(ABC): + @abstractmethod - def __call__(self, action: Any) -> List[str]: - """_summary_ - - :param action: _description_ - :type action: Any - :return: _description_ - :rtype: List[str] + def __init__(self, manager:"ActionManager", **kwargs) -> None: """ + Init method for action. + + All action init functions should accept **kwargs as a way of ignoring extra arguments. + + Since many parameters are defined for the action space as a whole (such as max files per folder, max services + per node), we need to pass those options to every action that gets created. To pervent verbosity, these + parameters are just broadcasted to all actions and the actions can pay attention to the ones that apply. + """ + self.name:str = "" + """Human-readable action identifier used for printing, logging, and reporting.""" + self.shape = (0,) + """Tuple describing number of options for each parameter of this action. Can be passed to + gym.spaces.MultiDiscrete to form a valid space.""" + self.manager:ActionManager = manager + + + @abstractmethod + def form_request(self) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" + return [] + + +class DoNothingAction(AbstractAction): + def __init__(self, manager:"ActionManager", **kwargs) -> None: + super().__init__(manager=manager) + self.name = "DONOTHING" + self.shape = (1,) + + def form_request(self) -> List[str]: + return ["do_nothing"] + +class NodeServiceAbstractAction(AbstractAction): + """ + Base class for service actions. + + Any action which applies to a service and uses node_id and service_id as its only two parameters can inherit from + this base class. + """ + @abstractmethod + def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + super().__init__(manager=manager) + self.shape: Tuple[int] = (num_nodes, num_services) + self.verb:str + + def form_request(self, node_id:int, service_id:int) -> List[str]: + node_uuid = self.manager.get_node_uuid_by_idx(node_id) + service_uuid = self.manager.get_service_uuid_by_idx(node_id, service_id) + if node_uuid is None or service_uuid is None: + return ["do_nothing"] + return ['network', 'node', node_uuid, 'services', service_uuid, self.verb] + +class NodeServiceScanAction(NodeServiceAbstractAction): + def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + super().__init__(manager=manager) + self.verb = "scan" + +class NodeServiceStopAction(NodeServiceAbstractAction): + def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + super().__init__(manager=manager) + self.verb = "stop" + +class NodeServiceStartAction(NodeServiceAbstractAction): + def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + super().__init__(manager=manager) + self.verb = "start" + +class NodeServicePauseAction(NodeServiceAbstractAction): + def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + super().__init__(manager=manager) + self.verb = "pause" + +class NodeServiceResumeAction(NodeServiceAbstractAction): + def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + super().__init__(manager=manager) + self.verb = "resume" + +class NodeServiceRestartAction(NodeServiceAbstractAction): + def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + super().__init__(manager=manager) + self.verb = "restart" + +class NodeServiceDisableAction(NodeServiceAbstractAction): + def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + super().__init__(manager=manager) + self.verb = "disable" + +class NodeServiceEnableAction(NodeServiceAbstractAction): + def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + super().__init__(manager=manager) + self.verb = "enable" + + + +class NodeFolderAbstractAction(AbstractAction): + @abstractmethod + def __init__(self, manager:"ActionManager", num_nodes, num_folders, **kwargs) -> None: + super().__init__(manager=manager) + self.shape = (num_nodes, num_folders) + self.verb: str + + def form_request(self, node_id:int, folder_id:int) -> List[str]: + node_uuid = self.manager.get_node_uuid_by_idx(node_id) + folder_uuid = self.manager.get_folder_uuid_by_idx(node_idx=node_id, folder_idx=folder_id) + if node_uuid is None or folder_uuid is None: + return ["do_nothing"] + return ['network', 'node', node_uuid, 'file_system', 'folder', folder_uuid, self.verb] + +class NodeFolderScanAction(NodeFolderAbstractAction): + def __init__(self, manager:"ActionManager", num_nodes, num_folders, **kwargs) -> None: + super().__init__(manager, num_nodes, num_folders, **kwargs) + self.verb:str = "scan" + +class NodeFolderCheckhashAction(NodeFolderAbstractAction): + def __init__(self, manager:"ActionManager", num_nodes, num_folders, **kwargs) -> None: + super().__init__(manager, num_nodes, num_folders, **kwargs) + self.verb:str = "checkhash" + +class NodeFolderRepairAction(NodeFolderAbstractAction): + def __init__(self, manager:"ActionManager", num_nodes, num_folders, **kwargs) -> None: + super().__init__(manager, num_nodes, num_folders, **kwargs) + self.verb:str = "repair" + +class NodeFolderRestoreAction(NodeFolderAbstractAction): + def __init__(self, manager: "ActionManager", num_nodes, num_folders, **kwargs) -> None: + super().__init__(manager, num_nodes, num_folders, **kwargs) + self.verb:str = "restore" + + +class NodeFileAbstractAction(AbstractAction): + @abstractmethod + def __init__(self, manager:"ActionManager", num_nodes:int, num_folders:int, num_files:int, **kwargs) -> None: + super().__init__(manager=manager) + self.shape:Tuple[int] = (num_nodes, num_folders, num_files) + self.verb:str + + def form_request(self, node_id:int, folder_id:int, file_id:int) -> List[str]: + node_uuid = self.manager.get_node_uuid_by_idx(node_id) + folder_uuid = self.manager.get_folder_uuid_by_idx(node_idx=node_id, folder_idx=folder_id) + file_uuid = self.manager.get_file_uuid_by_idx(node_idx=node_id, folder_idx=folder_id, file_idx=file_id) + if node_uuid is None or folder_uuid is None or file_uuid is None: + return ["do_nothing"] + return ['network', 'node', node_uuid, 'file_system', 'folder', folder_uuid, 'files', file_uuid, self.verb] + +class NodeFileScanAction(NodeFileAbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: + super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) + self.verb = "scan" + +class NodeFileCheckhashAction(NodeFileAbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: + super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) + self.verb = "checkhash" + +class NodeFileDeleteAction(NodeFileAbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: + super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) + self.verb = "delete" + +class NodeFileRepairAction(NodeFileAbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: + super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) + self.verb = "repair" + +class NodeFileRestoreAction(NodeFileAbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: + super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) + self.verb = "restore" + +class NodeAbstractAction(AbstractAction): + @abstractmethod + def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: + super().__init__(manager=manager) + self.shape: Tuple[int] = (num_nodes,) + self.verb: str + + def form_request(self, node_id:int) -> List[str]: + node_uuid = self.manager.get_node_uuid_by_idx(node_id) + return ["network", "node", node_uuid, self.verb] + +class NodeOSScanAction(NodeAbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: + super().__init__(manager=manager) + self.verb = 'scan' + +class NodeShutdownAction(NodeAbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: + super().__init__(manager=manager) + self.verb = 'shutdown' + +class NodeStartupAction(NodeAbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: + super().__init__(manager=manager) + self.verb = 'start' + +class NodeResetAction(NodeAbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: + super().__init__(manager=manager) + self.verb = 'reset' + +class NetworkACLAddRuleAction(AbstractAction): + def __init__(self, manager: "ActionManager", **kwargs) -> None: + super().__init__(manager=manager) + num_permissions = 2 + self.shape: Tuple[int] = (max_acl_rules, num_permissions, num_nics, num_nics, num_ports, num_ports, num_protocols) + + + + + + +class ActionManager: + # let the action manager handle the conversion of action spaces into a single discrete integer space. + # + + + # when action space is created, it will take subspaces and generate an action map by enumerating all possibilities, + # BUT, the action map can be provided in the config, in which case it will use that. + + # action map is basically just a mapping between integer and CAOS action (incl. parameter values) + # for example the action map can be: + # 0: DONOTHING + # 1: NODE, FILE, SCAN, NODEID=2, FOLDERID=1, FILEID=0 + # 2: ...... + __act_class_identifiers:Dict[str,type] = { + "DONOTHING": DoNothingAction, + "NODE_SERVICE_SCAN": NodeServiceScanAction, + "NODE_SERVICE_STOP": NodeServiceStopAction, + # "NODE_SERVICE_START": NodeServiceStartAction, + # "NODE_SERVICE_PAUSE": NodeServicePauseAction, + # "NODE_SERVICE_RESUME": NodeServiceResumeAction, + # "NODE_SERVICE_RESTART": NodeServiceRestartAction, + # "NODE_SERVICE_DISABLE": NodeServiceDisableAction, + # "NODE_SERVICE_ENABLE": NodeServiceEnableAction, + # "NODE_FILE_SCAN": NodeFileScanAction, + # "NODE_FILE_CHECKHASH": NodeFileCheckhashAction, + # "NODE_FILE_DELETE": NodeFileDeleteAction, + # "NODE_FILE_REPAIR": NodeFileRepairAction, + # "NODE_FILE_RESTORE": NodeFileRestoreAction, + "NODE_FOLDER_SCAN": NodeFolderScanAction, + # "NODE_FOLDER_CHECKHASH": NodeFolderCheckhashAction, + # "NODE_FOLDER_REPAIR": NodeFolderRepairAction, + # "NODE_FOLDER_RESTORE": NodeFolderRestoreAction, + # "NODE_OS_SCAN": NodeOSScanAction, + # "NODE_SHUTDOWN": NodeShutdownAction, + # "NODE_STARTUP": NodeStartupAction, + # "NODE_RESET": NodeResetAction, + # "NETWORK_ACL_ADDRULE": NetworkACLAddRuleAction, + # "NETWORK_ACL_REMOVERULE": NetworkACLRemoveRuleAction, + # "NETWORK_NIC_ENABLE": NetworkNICEnable, + # "NETWORK_NIC_DISABLE": NetworkNICDisable, + } + + + def __init__(self, + sim:Simulation, + actions:List[str], + node_uuids:List[str], + max_folders_per_node:int = 2, + max_files_per_folder:int = 2, + max_services_per_node:int = 2, + max_nics_per_node:int=8, + max_acl_rules:int=10, + act_map:Optional[Dict[int, Dict]]=None) -> None: + self.sim: Simulation = sim + self.node_uuids:List[str] = node_uuids + + action_args = { + "num_nodes": len(node_uuids), + "num_folders":max_folders_per_node, + "num_files": max_files_per_folder, + "num_services": max_services_per_node, + "num_nics": max_nics_per_node, + "num_acl_rules": max_acl_rules} + self.actions: Dict[str, AbstractAction] = {} + for act_type in actions: + self.actions[act_type] = self.__act_class_identifiers[act_type](self, **action_args) + + self.action_map:Dict[int, Tuple[str, Dict]] = {} + """ + Action mapping that converts an integer to a specific action and parameter choice. + + For example : + {0: ("NODE_SERVICE_SCAN", {node_id:0, service_id:2})} + """ + if act_map is None: + self.action_map = self._enumerate_actions() + else: + self.action_map = {i:(a['action'], a['options']) for i,a in act_map.items()} + # make sure all numbers between 0 and N are represented as dict keys in action map + assert all([i in self.action_map.keys() for i in range(len(self.action_map))]) + + def _enumerate_actions(self,) -> Dict[int, Tuple[AbstractAction, Dict]]: ... + def get_action(self, action: int) -> Tuple[str,Dict]: + """Produce action in CAOS format""" + """the agent chooses an action (as an integer), this is converted into an action in CAOS format""" + """The caos format is basically a action identifier, followed by parameters stored in a dictionary""" + act_identifier, act_options = self.action_map[action] + return act_identifier, act_options -class ActionSpace: + def form_request(self, action_identifier:str, action_options:Dict): + """Take action in CAOS format and use the execution definition to change it into PrimAITE request format""" + act_obj = self.actions[action_identifier] + return act_obj.form_request(**action_options) + + @property + def space(self) -> spaces.Space: + return spaces.Discrete(len(self.action_map)) + + def get_node_uuid_by_idx(self, node_idx): + return self.node_uuids[node_idx] + + def get_folder_uuid_by_idx(self, node_idx, folder_idx) -> Optional[str]: + node_uuid = self.get_node_uuid_by_idx(node_idx) + node = self.sim.network.nodes[node_uuid] + folder_uuids = list(node.file_system.folders.keys()) + return folder_uuids[folder_idx] if len(folder_uuids)>folder_idx else None + + def get_file_uuid_by_idx(self, node_idx, folder_idx, file_idx) -> Optional[str]: + node_uuid = self.get_node_uuid_by_idx(node_idx) + node = self.sim.network.nodes[node_uuid] + folder_uuids = list(node.file_system.folders.keys()) + if len(folder_uuids)<=folder_idx: + return None + folder = node.file_system.folders[folder_uuids[folder_idx]] + file_uuids = list(folder.files.keys()) + return file_uuids[file_idx] if len(file_uuids)>file_idx else None + + def get_service_uuid_by_idx(self, node_idx, service_idx) -> Optional[str]: + node_uuid = self.get_node_uuid_by_idx(node_idx) + node = self.sim.network.nodes[node_uuid] + service_uuids = list(node.services.keys()) + return service_uuids[service_idx] if len(service_uuids)>service_idx else None + + + + + + +class UC2RedActions(AbstractAction): + ... + +class UC2GreenActionSpace(ActionManager): ... diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index b1ade94b..0e682b60 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -2,32 +2,70 @@ # That's because I want to point out that this is disctinct from 'agent' in the reinforcement learning sense of the word # If you disagree, make a comment in the PR review and we can discuss from abc import ABC, abstractmethod -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Optional, Union, TypeAlias +import numpy as np -from primaite.game.agent.actions import ActionSpace +from primaite.game.agent.actions import ActionManager from primaite.game.agent.observations import ObservationSpace from primaite.game.agent.rewards import RewardFunction +ObsType:TypeAlias = Union[Dict, np.ndarray] class AbstractAgent(ABC): """Base class for scripted and RL agents.""" def __init__( self, - action_space: Optional[ActionSpace], + action_space: Optional[ActionManager], observation_space: Optional[ObservationSpace], reward_function: Optional[RewardFunction], ) -> None: - self.action_space: Optional[ActionSpace] = action_space + self.action_space: Optional[ActionManager] = action_space self.observation_space: Optional[ObservationSpace] = observation_space self.reward_function: Optional[RewardFunction] = reward_function + # exection definiton converts CAOS action to Primaite simulator request, sometimes having to enrich the info + # by for example specifying target ip addresses, or converting a node ID into a uuid + self.execution_definition = None + + def get_obs_from_state(self, state:Dict) -> ObsType: + """ + state : dict state directly from simulation.describe_state + output : dict state according to CAOS. + """ + return self.observation_space.observe(state) + + def get_reward_from_state(self, state:Dict) -> float: + return self.reward_function.calculate(state) + + @abstractmethod + def get_action(self, obs:ObsType, reward:float=None): + # in RL agent, this method will send CAOS observation to GATE RL agent, then receive a int 1-40, + # then use a bespoke conversion to take 1-40 int back into CAOS action + return ('NODE', 'SERVICE', 'SCAN', '', '') + + @abstractmethod + def format_request(self, action) -> List[str]: + # this will take something like APPLICATION.EXECUTE and add things like target_ip_address in simulator. + # therefore the execution definition needs to be a mapping from CAOS into SIMULATOR + """Format action into format expected by the simulator, and apply execution definition if applicable.""" + return ['network', 'nodes', '', 'file_system', 'folder', 'root', 'scan'] + + + + class AbstractScriptedAgent(AbstractAgent): """Base class for actors which generate their own behaviour.""" ... +class RandomAgent(AbstractScriptedAgent): + """Agent that ignores its observation and acts completely at random.""" + + def get_action(self, obs:ObsType, reward:float=None): + return self.action_space.space.sample() + class AbstractGATEAgent(AbstractAgent): """Base class for actors controlled via external messages, such as RL policies.""" diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 4d4796e1..f919a723 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -55,7 +55,7 @@ class AbstractObservation(ABC): class FileObservation(AbstractObservation): - def __init__(self, where: List[str] = []) -> None: + def __init__(self, where: Optional[List[str]] = None) -> None: """ _summary_ @@ -68,12 +68,12 @@ class FileObservation(AbstractObservation): :type where: Optional[List[str]] """ super().__init__() - self.where: List[str] = where + self.where: Optional[List[str]] = where self.default_observation: spaces.Space = {"health_status": 0} "Default observation is what should be returned when the file doesn't exist, e.g. after it has been deleted." def observe(self, state: Dict) -> Dict: - if not self.where: + if self.where is None: return self.default_observation file_state = access_from_nested_dict(state, self.where) if file_state is NOT_PRESENT_IN_STATE: @@ -89,21 +89,21 @@ class ServiceObservation(AbstractObservation): default_observation: spaces.Space = {"operating_status": 0, "health_status": 0} "Default observation is what should be returned when the service doesn't exist." - def __init__(self, where: List[str] = []) -> None: + def __init__(self, where: Optional[List[str]] = None) -> None: """ :param where: Store information about where in the simulation state dictionary to find the relevant information. Optional. If None, this corresponds that the file does not exist and the observation will be populated with zeroes. A typical location for a service looks like this: - `['network','nodes',,'servics', ]` + `['network','nodes',,'services', ]` :type where: Optional[List[str]] """ super().__init__() - self.where: List[str] = where + self.where: Optional[List[str]] = where def observe(self, state: Dict) -> Dict: - if not self.where: + if self.where is None: return self.default_observation service_state = access_from_nested_dict(state, self.where) @@ -120,7 +120,7 @@ class LinkObservation(AbstractObservation): default_observation: spaces.Space = {"protocols": {"all": {"load": 0}}} "Default observation is what should be returned when the link doesn't exist." - def __init__(self, where: List[str] = []) -> None: + def __init__(self, where: Optional[List[str]] = None) -> None: """ :param where: Store information about where in the simulation state dictionary to find the relevant information. Optional. If None, this corresponds that the file does not exist and the observation will be populated with @@ -131,10 +131,10 @@ class LinkObservation(AbstractObservation): :type where: Optional[List[str]] """ super().__init__() - self.where: List[str] = where + self.where: Optional[List[str]] = where def observe(self, state: Dict) -> Dict: - if not self.where: + if self.where is None: return self.default_observation link_state = access_from_nested_dict(state, self.where) @@ -156,7 +156,7 @@ class LinkObservation(AbstractObservation): class FolderObservation(AbstractObservation): - def __init__(self, where: List[str] = [], files: List[FileObservation] = []) -> None: + def __init__(self, where: Optional[List[str]] = None, files: List[FileObservation] = []) -> None: """Initialise folder Observation, including files inside of the folder. :param where: Where in the simulation state dictionary to find the relevant information for this folder. @@ -175,7 +175,7 @@ class FolderObservation(AbstractObservation): """ super().__init__() - self.where: List[str] = where + self.where: Optional[List[str]] = where self.files: List[FileObservation] = files @@ -185,7 +185,7 @@ class FolderObservation(AbstractObservation): } def observe(self, state: Dict) -> Dict: - if not self.where: + if self.where is None: return self.default_observation folder_state = access_from_nested_dict(state, self.where) if folder_state is NOT_PRESENT_IN_STATE: @@ -213,12 +213,12 @@ class FolderObservation(AbstractObservation): class NicObservation(AbstractObservation): default_observation: spaces.Space = {"nic_status": 0} - def __init__(self, where: List[str] = []) -> None: - super.__init__() - self.where: List[str] = where + def __init__(self, where: Optional[List[str]] = None) -> None: + super().__init__() + self.where: Optional[List[str]] = where def observe(self, state: Dict) -> Dict: - if not self.where: + if self.where is None: return self.default_observation nic_state = access_from_nested_dict(state, self.where) if nic_state is NOT_PRESENT_IN_STATE: @@ -234,10 +234,11 @@ class NicObservation(AbstractObservation): class NodeObservation(AbstractObservation): def __init__( self, - where: List[str] = [], + where: Optional[List[str]] = None, services: List[ServiceObservation] = [], folders: List[FolderObservation] = [], nics: List[NicObservation] = [], + logon_status:bool=False ) -> None: """ Configurable observation for a node in the simulation. @@ -259,12 +260,13 @@ class NodeObservation(AbstractObservation): :param max_nics: Max number of NICS in this node's obs space, defaults to 5 :type max_nics: int, optional """ - super.__init__() - self.where: List[str] = where + super().__init__() + self.where: Optional[List[str]] = where self.services: List[ServiceObservation] = services self.folders: List[FolderObservation] = folders self.nics: List[NicObservation] = nics + self.logon_status:bool=logon_status self.default_observation: Dict = { "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, @@ -272,9 +274,11 @@ class NodeObservation(AbstractObservation): "NICS": {i + 1: n.default_observation for i, n in enumerate(self.nics)}, "operating_status": 0, } + if self.logon_status: + self.default_observation['logon_status']=0 def observe(self, state: Dict) -> Dict: - if not self.where: + if self.where is None: return self.default_observation node_state = access_from_nested_dict(state, self.where) @@ -288,18 +292,24 @@ class NodeObservation(AbstractObservation): obs["operating_status"] = node_state["operating_state"] obs["NICS"] = {i + 1: nic.observe(state) for i, nic in enumerate(self.nics)} + if self.logon_status: + obs['logon_status'] = 0 + return obs @property def space(self) -> spaces.Space: - return spaces.Dict( - { - "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), - "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), - "operating_status": spaces.Discrete(0), - "NICS": spaces.Dict({i + 1: nic.space for i, nic in enumerate(self.nics)}), - } - ) + space_shape = { + "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), + "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), + "operating_status": spaces.Discrete(5), + "NICS": spaces.Dict({i + 1: nic.space for i, nic in enumerate(self.nics)}), + } + if self.logon_status: + space_shape['logon_status'] = spaces.Discrete(3) + + return spaces.Dict(space_shape) + class AclObservation(AbstractObservation): @@ -308,41 +318,33 @@ class AclObservation(AbstractObservation): # if a file is created at runtime, we have currently got no way of telling the observation space to track it. # this needs adding, but not for the MVP. def __init__( - self, nodes: List[str], ports: List[int], protocols: list[str], where: List[str] = [], num_rules: int = 10 + self, node_ip_to_id: Dict[str,int], ports: List[int], protocols: list[str], where: Optional[List[str]] = None, num_rules: int = 10 ) -> None: super().__init__() - self.where: List[str] = where + self.where: Optional[List[str]] = where self.num_rules: int = num_rules - self.node_to_id: Dict[str, int] = {node: i + 1 for i, node in enumerate(nodes)} + self.node_to_id: Dict[str, int] = node_ip_to_id "List of node IP addresses, order in this list determines how they are converted to an ID" - self.port_to_id: Dict[int, int] = {port: i + 1 for i, port in enumerate(ports)} + self.port_to_id: Dict[int, int] = {port: i + 2 for i, port in enumerate(ports)} "List of ports which are part of the game that define the ordering when converting to an ID" - self.protocol_to_id: Dict[str, int] = {protocol: i + 1 for i, protocol in enumerate(protocols)} + self.protocol_to_id: Dict[str, int] = {protocol: i + 2 for i, protocol in enumerate(protocols)} "List of protocols which are part of the game, defines ordering when converting to an ID" - self.default_observation: spaces.Space = spaces.Dict( - { - "RULES": spaces.Dict( - { - i - + 1: spaces.Dict( - { - "position": i, - "permission": 0, - "source_node_id": 0, - "source_port": 0, - "dest_node_id": 0, - "dest_port": 0, - "protocol": 0, - } - ) - for i in range(self.num_rules) - } - ) + self.default_observation: Dict = { + "RULES": {i+ 1:{ + "position": i, + "permission": 0, + "source_node_id": 0, + "source_port": 0, + "dest_node_id": 0, + "dest_port": 0, + "protocol": 0, + } + for i in range(self.num_rules) } - ) + } def observe(self, state: Dict) -> Dict: - if not self.where: + if self.where is None: return self.default_observation acl_state: Dict = access_from_nested_dict(state, self.where) if acl_state is NOT_PRESENT_IN_STATE: @@ -379,16 +381,16 @@ class AclObservation(AbstractObservation): { "RULE": spaces.Dict( { - i - + 1: spaces.Dict( + i + 1: spaces.Dict( { "position": spaces.Discrete(self.num_rules), "permission": spaces.Discrete(3), - "source_node_id": spaces.Discrete(len(self.nodes) + 1), - "source_port": spaces.Discrete(len(self.ports) + 1), - "dest_node_id": spaces.Discrete(len(self.nodes) + 1), - "dest_port": spaces.Discrete(len(self.ports) + 1), - "protocol": spaces.Discrete(len(self.protocols) + 1), + # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) + "source_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), + "source_port": spaces.Discrete(len(self.port_to_id) + 2), + "dest_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), + "dest_port": spaces.Discrete(len(self.port_to_id) + 2), + "protocol": spaces.Discrete(len(self.protocol_to_id) + 2), } ) for i in range(self.num_rules) @@ -398,14 +400,96 @@ class AclObservation(AbstractObservation): ) -class ICSObservation(AbstractObservation): - def observe(self, state: Dict) -> Any: - return 0 + + +class NullObservation(AbstractObservation): + def __init__(self, where:Optional[List[str]]=None): + self.default_observation: Dict = {} + + def observe(self, state: Dict) -> Dict: + return {} @property def space(self) -> spaces.Space: - return spaces.Discrete(1) + return spaces.Dict({}) +class ICSObservation(NullObservation): pass + + +class UC2BlueObservation(AbstractObservation): + def __init__( + self, + nodes: List[NodeObservation], + links: List[LinkObservation], + acl: AclObservation, + ics: ICSObservation, + where:Optional[List[str]] = None, + ) -> None: + super().__init__() + self.where: Optional[List[str]] = where + + self.nodes: List[NodeObservation] = nodes + self.links: List[LinkObservation] = links + self.acl: AclObservation = acl + self.ics: ICSObservation = ics + + self.default_observation : Dict = { + "NODES": {i+1: n.default_observation for i,n in enumerate(self.nodes)}, + "LINKS": {i+1: l.default_observation for i,l in enumerate(self.links)}, + "ACL": self.acl.default_observation, + "ICS": self.ics.default_observation, + } + + def observe(self, state:Dict) -> Dict: + if self.where is None: + return self.default_observation + + obs = {} + + obs['NODES'] = {i + 1: node.observe(state) for i, node in enumerate(self.nodes)} + obs['LINKS'] = {i + 1: link.observe(state) for i, link in enumerate(self.links)} + obs['ACL'] = {self.acl.observe(state)} + obs['ICS'] = {self.ics.observe(state)} + + return obs + + @property + def space(self) -> spaces.Space: + return spaces.Dict({ + "NODES": spaces.Dict({i+1: node.space for i, node in enumerate(self.nodes)}), + "LINKS": spaces.Dict({i+1: link.space for i, link in enumerate(self.links)}), + "ACL": self.acl.space, + "ICS": self.ics.space, + }) + + @classmethod + def from_config(cls, config:Dict, sim:Simulation): + nodes = ... + links = ... + acl = ... + ics = ... + new = cls(nodes=nodes, links=links, acl=acl, ics=ics, where=['network']) + return new + + +class UC2RedObservation(AbstractObservation): + def __init__(self, nodes:List[NodeObservation], where:Optional[List[str]] = None) -> None: + super().__init__() + self.where:Optional[List[str]] = where + self.nodes: List[NodeObservation] = nodes + + self.default_observation=...#TODO + + def observe(self, state: Dict) -> Any: + return super().observe(state) + + @property + def space(self) -> spaces.Space: + ... #TODO + + @classmethod + def from_config(cls, config: Dict, sim:Simulation): + ... #TODO class ObservationSpace: """ @@ -422,29 +506,12 @@ class ObservationSpace: # what this class does: # keep a list of observations # create observations for an actor from the config - def __init__( - self, - simulation: Simulation, - nodes: List[NodeObservation] = [], - links: List[LinkObservation] = [], - acl: Optional[AclObservation] = None, - ics: Optional[ICSObservation] = None, - ) -> None: - self.simulation: Simulation = simulation - self.parts: Dict[str, AbstractObservation] = {} + def __init__(self, observation:AbstractObservation) -> None: + self.obs: AbstractObservation = observation - self.nodes: List[NodeObservation] = nodes - self.links: List[LinkObservation] = links - self.acl: Optional[AclObservation] = acl - self.ics: Optional[ICSObservation] = ics - - def observe(self) -> None: - ... + def observe(self, state) -> Dict: + return self.obs.observe(state) @property def space(self) -> None: - ... - - @classmethod - def from_config(self) -> None: - ... + return self.obs.space diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 1db54176..ec778176 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -1,20 +1,17 @@ from abc import ABC, abstractmethod from typing import Any, Dict, List -from pydantic import BaseModel - - -class AbstractReward(BaseModel): - def __call__(self, states: List[Dict]) -> float: - """_summary_ - - :param state: _description_ - :type state: Dict - :return: _description_ - :rtype: float - """ +class AbstractReward(): + def __init__(self): ... + def calculate(self, state:Dict) -> float: + return 0.3 -class RewardFunction(BaseModel): - ... + +class RewardFunction(): + def __init__(self, reward_function:AbstractReward): + self.reward: AbstractReward = reward_function + + def calculate(self, state:Dict) -> float: + return self.reward.calculate(state) diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 47ef4ce9..fcd8b4b3 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -4,3 +4,49 @@ # 3. create actors and configure their actions/observations/rewards/ anything else # 4. Create connection with ARCD GATE # 5. idk + +from primaite.simulator.sim_container import Simulation +from primaite.game.agent.interface import AbstractAgent + +from typing import List + +class PrimaiteSession: + def __init__(self): + self.simulation: Simulation = Simulation() + self.agents:List[AbstractAgent] = [] + self.step_counter:int = 0 + self.episode_counter:int = 0 + + + def step(self): + # currently designed with assumption that all agents act once per step in order + + + for agent in self.agents: + # 3. primaite session asks simulation to provide initial state + # 4. primate session gives state to all agents + # 5. primaite session asks agents to produce an action based on most recent state + sim_state = self.simulation.describe_state() + + # 6. each agent takes most recent state and converts it to CAOS observation + agent_obs = agent.get_obs_from_state(sim_state) + + # 7. meanwhile each agent also takes state and calculates reward + agent_reward = agent.get_reward_from_state(sim_state) + + # 8. each agent takes observation and applies decision rule to observation to create CAOS + # action(such as random, rulebased, or send to GATE) (therefore, converting CAOS action + # to discrete(40) is only necessary for purposes of RL learning, therefore that bit of + # code should live inside of the GATE agent subclass) + # gets action in CAOS format + agent_action = agent.get_action(agent_obs, agent_reward) + # 9. CAOS action is converted into request (extra information might be needed to enrich + # the request, this is what the execution definition is there for) + agent_request = agent.format_request(agent_action) + + # 10. primaite session receives the action from the agents and asks the simulation to apply each + self.simulation.apply_action(agent_request) + + self.simulation.apply_timestep(self.step_counter) + self.step_counter += 1 + From 4b5a73bd3241fd863dd92d841d6e71a32a27ecf0 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 3 Oct 2023 14:59:48 +0100 Subject: [PATCH 204/980] #1943: web server + client + tests + a few improvements to syslogging --- .../simulator/network/hardware/base.py | 10 +- .../network/hardware/nodes/computer.py | 19 +++ .../network/hardware/nodes/router.py | 2 + .../network/hardware/nodes/switch.py | 2 + src/primaite/simulator/network/networks.py | 9 +- .../simulator/network/protocols/http.py | 61 ++++++++ .../simulator/network/protocols/packet.py | 5 + .../system/applications/application.py | 12 -- .../system/applications/database_client.py | 34 ++++- .../system/applications/web_browser.py | 114 ++++++++++++--- .../simulator/system/core/session_manager.py | 2 +- .../simulator/system/core/software_manager.py | 4 +- .../services/database/database_service.py | 4 +- .../system/services/dns/dns_client.py | 30 ++-- .../system/services/dns/dns_server.py | 4 +- .../system/services/ftp/ftp_client.py | 78 +++++++--- .../system/services/ftp/ftp_server.py | 12 +- .../system/services/ftp/ftp_service.py | 33 ++++- .../red_services/data_manipulation_bot.py | 8 +- .../simulator/system/services/service.py | 17 ++- .../system/services/web_server/__init__.py | 0 .../services/web_server/web_server_service.py | 136 ++++++++++++++++++ src/primaite/simulator/system/software.py | 33 ++++- .../system/test_web_client_server.py | 19 +++ 24 files changed, 536 insertions(+), 112 deletions(-) create mode 100644 src/primaite/simulator/network/protocols/http.py create mode 100644 src/primaite/simulator/system/services/web_server/__init__.py create mode 100644 src/primaite/simulator/system/services/web_server/web_server_service.py create mode 100644 tests/integration_tests/system/test_web_client_server.py diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index dd2130d2..4263f835 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -714,7 +714,9 @@ class ARPCache: # Unmatched ARP Request if arp_packet.target_ip_address != from_nic.ip_address: - self.sys_log.info(f"Ignoring ARP request for {arp_packet.target_ip_address}") + self.sys_log.info( + f"Ignoring ARP request for {arp_packet.target_ip_address}. Current IP address is {from_nic.ip_address}" + ) return # Matched ARP request @@ -937,6 +939,12 @@ class Node(SimComponent): self.arp.nics = self.nics self.session_manager.software_manager = self.software_manager + self._install_system_software() + + def _install_system_software(self): + """Install System Software - software that is usually provided with the OS.""" + pass + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. diff --git a/src/primaite/simulator/network/hardware/nodes/computer.py b/src/primaite/simulator/network/hardware/nodes/computer.py index 5452666b..61c62a5f 100644 --- a/src/primaite/simulator/network/hardware/nodes/computer.py +++ b/src/primaite/simulator/network/hardware/nodes/computer.py @@ -1,4 +1,8 @@ from primaite.simulator.network.hardware.base import NIC, Node +from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.ftp.ftp_server import FTPServer class Computer(Node): @@ -36,3 +40,18 @@ class Computer(Node): def __init__(self, **kwargs): super().__init__(**kwargs) self.connect_nic(NIC(ip_address=kwargs["ip_address"], subnet_mask=kwargs["subnet_mask"])) + self._install_system_software() + + def _install_system_software(self): + """Install System Software - software that is usually provided with the OS.""" + # DNS Client + self.software_manager.install(DNSClient) + + # FTP + self.software_manager.install(FTPClient) + self.software_manager.install(FTPServer) + + # Web Browser + self.software_manager.install(WebBrowser) + + super()._install_system_software() diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 092680a7..90eb5935 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -596,6 +596,8 @@ class Router(Node): self.arp.nics = self.nics self.icmp.arp = self.arp + self._install_system_software() + def _get_port_of_nic(self, target_nic: NIC) -> Optional[int]: """ Retrieve the port number for a given NIC. diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/switch.py index b7cc1242..8b3fe5cd 100644 --- a/src/primaite/simulator/network/hardware/nodes/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/switch.py @@ -34,6 +34,8 @@ class Switch(Node): port.parent = self port.port_num = port_num + self._install_system_software() + def show(self, markdown: bool = False): """ Prints a table of the SwitchPorts on the Switch. diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 63cb05e0..1ddeb82f 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -13,8 +13,8 @@ from primaite.simulator.system.services.database.database_service import Databas from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.ftp.ftp_client import FTPClient -from primaite.simulator.system.services.ftp.ftp_server import FTPServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot +from primaite.simulator.system.services.web_server.web_server_service import WebServerService def client_server_routed() -> Network: @@ -260,6 +260,8 @@ def arcd_uc2_network() -> Network: database_client.run() database_client.connect() + web_server.software_manager.install(WebServerService) + # register the web_server to a domain dns_server_service: DNSServer = domain_controller.software_manager.software["DNSServer"] # noqa dns_server_service.dns_register("arcd.com", web_server.ip_address) @@ -275,8 +277,6 @@ def arcd_uc2_network() -> Network: backup_server.power_on() network.connect(endpoint_b=backup_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[4]) - backup_server.software_manager.install(FTPServer) - # Security Suite security_suite = Server( hostname="security_suite", @@ -305,4 +305,7 @@ def arcd_uc2_network() -> Network: # Allow FTP requests router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.FTP, dst_port=Port.FTP, position=2) + # Open port 80 for web server + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.HTTP, dst_port=Port.HTTP, position=3) + return network diff --git a/src/primaite/simulator/network/protocols/http.py b/src/primaite/simulator/network/protocols/http.py new file mode 100644 index 00000000..4be0ed88 --- /dev/null +++ b/src/primaite/simulator/network/protocols/http.py @@ -0,0 +1,61 @@ +from enum import Enum + +from primaite.simulator.network.protocols.packet import DataPacket + + +class HTTPRequestMethod(Enum): + """Enum list of HTTP Request methods that can be handled by the simulation.""" + + GET = "GET" + """HTTP GET Method. Requests using GET should only retrieve data.""" + + HEAD = "HEAD" + """Asks for a response identical to a GET request, but without the response body.""" + + POST = "POST" + """Submit an entity to the specified resource, often causing a change in state or side effects on the server.""" + + PUT = "PUT" + """Replace all current representations of the target resource with the request payload.""" + + DELETE = "DELETE" + """Delete the specified resource.""" + + PATCH = "PATCH" + """Apply partial modifications to a resource.""" + + +class HTTPStatusCode(Enum): + """List of available HTTP Statuses.""" + + OK = 200 + """request has succeeded.""" + + BAD_REQUEST = 400 + """Payload cannot be parsed.""" + + UNAUTHORIZED = 401 + """Auth required.""" + + METHOD_NOT_ALLOWED = 405 + """Method is not supported by server.""" + + INTERNAL_SERVER_ERROR = 500 + """Error on the server side.""" + + +class HTTPRequestPacket(DataPacket): + """Class that represents an HTTP Request Packet.""" + + request_method: HTTPRequestMethod + """The HTTP Request method.""" + + request_url: str + """URL of request.""" + + +class HTTPResponsePacket(DataPacket): + """Class that reprensents an HTTP Response Packet.""" + + status_code: HTTPStatusCode = None + """Status code of the HTTP response.""" diff --git a/src/primaite/simulator/network/protocols/packet.py b/src/primaite/simulator/network/protocols/packet.py index 1adcc800..3c99aa68 100644 --- a/src/primaite/simulator/network/protocols/packet.py +++ b/src/primaite/simulator/network/protocols/packet.py @@ -1,9 +1,14 @@ +from typing import Any + from pydantic import BaseModel class DataPacket(BaseModel): """Data packet abstract class.""" + payload: Any = None + """Payload content of the packet.""" + packet_payload_size: float = 0 """Size of the packet.""" diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 30efd5b7..69b64aac 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -81,18 +81,6 @@ class Application(IOSoftware): """ pass - def send(self, payload: Any, session_id: str, **kwargs) -> bool: - """ - Sends a payload to the SessionManager. - - The specifics of how the payload is processed and whether a response payload - is generated should be implemented in subclasses. - - :param payload: The payload to send. - :return: True if successful, False otherwise. - """ - pass - def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ Receives a payload from the SessionManager. diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 9d59a2f4..d021cb78 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -49,7 +49,7 @@ class DatabaseClient(Application): """ self.server_ip_address = server_ip_address self.server_password = server_password - self.sys_log.info(f"Configured the {self.name} with {server_ip_address=}, {server_password=}.") + self.sys_log.info(f"{self.name}: Configured the {self.name} with {server_ip_address=}, {server_password=}.") def connect(self) -> bool: """Connect to a Database Service.""" @@ -60,13 +60,25 @@ class DatabaseClient(Application): def _connect( self, server_ip_address: IPv4Address, password: Optional[str] = None, is_reattempt: bool = False ) -> bool: + """ + Connects the DatabaseClient to the DatabaseServer. + + :param: server_ip_address: IP address of the database server + :type: server_ip_address: IPv4Address + + :param: password: Password used to connect to the database server. Optional. + :type: password: Optional[str] + + :param: is_reattempt: True if the connect request has been reattempted. Default False + :type: is_reattempt: Optional[bool] + """ if is_reattempt: if self.connected: - self.sys_log.info(f"DatabaseClient connected to {server_ip_address} authorised") + self.sys_log.info(f"{self.name}: DatabaseClient connected to {server_ip_address} authorised") self.server_ip_address = server_ip_address return self.connected else: - self.sys_log.info(f"DatabaseClient connected to {server_ip_address} declined") + self.sys_log.info(f"{self.name}: DatabaseClient connected to {server_ip_address} declined") return False payload = {"type": "connect_request", "password": password} software_manager: SoftwareManager = self.software_manager @@ -83,15 +95,29 @@ class DatabaseClient(Application): payload={"type": "disconnect"}, dest_ip_address=self.server_ip_address, dest_port=self.port ) - self.sys_log.info(f"DatabaseClient disconnected from {self.server_ip_address}") + self.sys_log.info(f"{self.name}: DatabaseClient disconnected from {self.server_ip_address}") self.server_ip_address = None self.connected = False def _query(self, sql: str, query_id: str, is_reattempt: bool = False) -> bool: + """ + Send a query to the connected database server. + + :param: sql: SQL query to send to the database server. + :type: sql: str + + :param: query_id: ID of the query, used as reference + :type: query_id: str + + :param: is_reattempt: True if the query request has been reattempted. Default False + :type: is_reattempt: Optional[bool] + """ if is_reattempt: success = self._query_success_tracker.get(query_id) if success: + self.sys_log.info(f"{self.name}: Query successful {sql}") return True + self.sys_log.info(f"{self.name}: Unable to run query {sql}") return False else: software_manager: SoftwareManager = self.software_manager diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 78d196b7..9d2c31b1 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -1,7 +1,12 @@ from ipaddress import IPv4Address -from typing import Any, Dict, Optional +from typing import Dict, Optional +from urllib.parse import urlparse +from primaite.simulator.network.protocols.http import HTTPRequestMethod, HTTPRequestPacket, HTTPResponsePacket +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.services.dns.dns_client import DNSClient class WebBrowser(Application): @@ -11,12 +16,29 @@ class WebBrowser(Application): The application requests and loads web pages using its domain name and requesting IP addresses using DNS. """ - domain_name: str - "The domain name of the webpage." - domain_name_ip_address: Optional[IPv4Address] + domain_name_ip_address: Optional[IPv4Address] = None "The IP address of the domain name for the webpage." - history: Dict[str] - "A dict that stores all of the previous domain names." + + latest_response: HTTPResponsePacket = None + """Keeps track of the latest HTTP response.""" + + def __init__(self, **kwargs): + kwargs["name"] = "WebBrowser" + kwargs["protocol"] = IPProtocol.TCP + # default for web is port 80 + if kwargs.get("port") is None: + kwargs["port"] = Port.HTTP + + super().__init__(**kwargs) + self.run() + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of the WebBrowser. + + :return: A dictionary capturing the current state of the WebBrowser and its child objects. + """ + pass def reset_component_for_episode(self, episode: int): """ @@ -25,30 +47,84 @@ class WebBrowser(Application): This method ensures the Application is ready for a new episode, including resetting any stateful properties or statistics, and clearing any message queues. """ - self.domain_name = "" self.domain_name_ip_address = None - self.history = {} + self.latest_response = None - def send(self, payload: Any, session_id: str, **kwargs) -> bool: + def get_webpage(self, url: str) -> bool: + """ + Retrieve the webpage. + + This should send a request to the web server which also requests for a list of users + + :param: url: The address of the web page the browser requests + :type: url: str + """ + # reset latest response + self.latest_response = None + + try: + parsed_url = urlparse(url) + except Exception: + self.sys_log.error(f"{url} is not a valid URL") + return False + + # get the IP address of the domain name via DNS + dns_client: DNSClient = self.software_manager.software["DNSClient"] + + domain_exists = dns_client.check_domain_exists(target_domain=parsed_url.hostname) + + # if domain does not exist, the request fails + if not domain_exists: + return False + + # set current domain name IP address + self.domain_name_ip_address = dns_client.dns_cache[parsed_url.hostname] + + # create HTTPRequest payload + payload = HTTPRequestPacket(request_method=HTTPRequestMethod.GET, request_url=url) + + # send request + return self.send( + payload=payload, + dest_ip_address=self.domain_name_ip_address, + dest_port=parsed_url.port if parsed_url.port else Port.HTTP, + ) + + def send( + self, + payload: HTTPRequestPacket, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = Port.HTTP, + session_id: Optional[str] = None, + **kwargs, + ) -> bool: """ Sends a payload to the SessionManager. - The specifics of how the payload is processed and whether a response payload - is generated should be implemented in subclasses. + :param payload: The payload to be sent. + :param dest_ip_address: The ip address of the payload destination. + :param dest_port: The port of the payload destination. + :param session_id: The Session ID the payload is to originate from. Optional. - :param payload: The payload to send. :return: True if successful, False otherwise. """ - pass + self.sys_log.info(f"{self.name}: Sending HTTP {payload.request_method.name} {payload.request_url}") - def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + return super().send( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, **kwargs + ) + + def receive(self, payload: HTTPResponsePacket, session_id: Optional[str] = None, **kwargs) -> bool: """ Receives a payload from the SessionManager. - The specifics of how the payload is processed and whether a response payload - is generated should be implemented in subclasses. - - :param payload: The payload to receive. + :param payload: The payload to be sent. + :param session_id: The Session ID the payload is to originate from. Optional. :return: True if successful, False otherwise. """ - pass + if not isinstance(payload, HTTPResponsePacket): + self.sys_log.error(f"{self.name} received a packet that is not an HTTPResponsePacket") + return False + self.sys_log.info(f"{self.name}: Received HTTP {payload.status_code.value}") + self.latest_response = payload + return True diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 95ece9f9..360b5e73 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -193,7 +193,7 @@ class SessionManager: self.sessions_by_key[session_key] = session self.sessions_by_uuid[session.uuid] = session - outbound_nic.send_frame(frame) + return outbound_nic.send_frame(frame) def receive_frame(self, frame: Frame): """ diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index 99445bf8..973b17b4 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -110,7 +110,7 @@ class SoftwareManager: dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = None, session_id: Optional[str] = None, - ): + ) -> bool: """ Send a payload to the SessionManager. @@ -119,7 +119,7 @@ class SoftwareManager: :param dest_port: The port of the payload destination. :param session_id: The Session ID the payload is to originate from. Optional. """ - self.session_manager.receive_payload_from_software_manager( + return self.session_manager.receive_payload_from_software_manager( payload=payload, dst_ip_address=dest_ip_address, dst_port=dest_port, session_id=session_id ) diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 62120fc7..73365de6 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -73,10 +73,10 @@ class DatabaseService(Service): if self.password == password: status_code = 200 # ok self.connections[session_id] = datetime.now() - self.sys_log.info(f"Connect request for {session_id=} authorised") + self.sys_log.info(f"{self.name}: Connect request for {session_id=} authorised") else: status_code = 401 # Unauthorised - self.sys_log.info(f"Connect request for {session_id=} declined") + self.sys_log.info(f"{self.name}: Connect request for {session_id=} declined") else: status_code = 404 # service not found return {"status_code": status_code, "type": "connect_response", "response": status_code == 200} diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 56d5d8b4..620a9a32 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -78,13 +78,14 @@ class DNSClient(Service): # check if the domain is already in the DNS cache if target_domain in self.dns_cache: self.sys_log.info( - f"DNS Client: Domain lookup for {target_domain} successful, resolves to {self.dns_cache[target_domain]}" + f"{self.name}: Domain lookup for {target_domain} successful," + f"resolves to {self.dns_cache[target_domain]}" ) return True else: # return False if already reattempted if is_reattempt: - self.sys_log.info(f"DNS Client: Domain lookup for {target_domain} failed") + self.sys_log.info(f"{self.name}: Domain lookup for {target_domain} failed") return False else: # send a request to check if domain name exists in the DNS Server @@ -104,14 +105,13 @@ class DNSClient(Service): self, payload: DNSPacket, session_id: Optional[str] = None, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, **kwargs, ) -> bool: """ Sends a payload to the SessionManager. - The specifics of how the payload is processed and whether a response payload - is generated should be implemented in subclasses. - :param payload: The payload to be sent. :param dest_ip_address: The ip address of the payload destination. :param dest_port: The port of the payload destination. @@ -119,10 +119,11 @@ class DNSClient(Service): :return: True if successful, False otherwise. """ - # create DNS request packet - software_manager: SoftwareManager = self.software_manager - software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id) - return True + self.sys_log.info(f"{self.name}: Sending DNS request to resolve {payload.dns_request.domain_name_request}") + + return super().send( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, **kwargs + ) def receive( self, @@ -133,9 +134,6 @@ class DNSClient(Service): """ Receives a payload from the SessionManager. - The specifics of how the payload is processed and whether a response payload - is generated should be implemented in subclasses. - :param payload: The payload to be sent. :param session_id: The Session ID the payload is to originate from. Optional. :return: True if successful, False otherwise. @@ -144,12 +142,16 @@ class DNSClient(Service): if not isinstance(payload, DNSPacket): _LOGGER.debug(f"{payload} is not a DNSPacket") return False - # cast payload into a DNS packet - payload: DNSPacket = payload + if payload.dns_reply is not None: # add the IP address to the client cache if payload.dns_reply.domain_name_ip_address: + self.sys_log.info( + f"{self.name}: Resolved domain name {payload.dns_request.domain_name_request} " + f"to {payload.dns_reply.domain_name_ip_address}" + ) self.dns_cache[payload.dns_request.domain_name_request] = payload.dns_reply.domain_name_ip_address return True + self.sys_log.error(f"Failed to resolve domain name {payload.dns_request.domain_name_request}") return False diff --git a/src/primaite/simulator/system/services/dns/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py index c3c39595..90a350c8 100644 --- a/src/primaite/simulator/system/services/dns/dns_server.py +++ b/src/primaite/simulator/system/services/dns/dns_server.py @@ -96,13 +96,13 @@ class DNSServer(Service): payload: DNSPacket = payload if payload.dns_request is not None: self.sys_log.info( - f"DNS Server: Received domain lookup request for {payload.dns_request.domain_name_request} " + f"{self.name}: Received domain lookup request for {payload.dns_request.domain_name_request} " f"from session {session_id}" ) # generate a reply with the correct DNS IP address payload = payload.generate_reply(self.dns_lookup(payload.dns_request.domain_name_request)) self.sys_log.info( - f"DNS Server: Responding to domain lookup request for {payload.dns_request.domain_name_request} " + f"{self.name}: Responding to domain lookup request for {payload.dns_request.domain_name_request} " f"with ip address: {payload.dns_reply.domain_name_ip_address}" ) # send reply diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 33fe32be..4986d3a1 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -39,9 +39,12 @@ class FTPClient(FTPServiceABC): """ # if client service is down, return error if self.operating_state != ServiceOperatingState.RUNNING: + self.sys_log.error("FTP Client is not running") payload.status_code = FTPStatusCode.ERROR return payload + self.sys_log.info(f"{self.name}: Received FTP {payload.ftp_command.name} {payload.ftp_command_args}") + # process client specific commands, otherwise call super return super()._process_ftp_command(payload=payload, session_id=session_id, **kwargs) @@ -49,6 +52,7 @@ class FTPClient(FTPServiceABC): self, dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = Port.FTP, + session_id: Optional[str] = None, is_reattempt: Optional[bool] = False, ) -> bool: """ @@ -72,20 +76,27 @@ class FTPClient(FTPServiceABC): ftp_command=FTPCommand.PORT, ftp_command_args=Port.FTP, ) - software_manager: SoftwareManager = self.software_manager - software_manager.send_payload_to_session_manager( - payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port - ) - if payload.status_code == FTPStatusCode.OK: - return True - else: - if is_reattempt: - # reattempt failed - return False + if self.send(payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id): + if payload.status_code == FTPStatusCode.OK: + self.sys_log.info( + f"{self.name}: Successfully connected to FTP Server " + f"{dest_ip_address} via port {payload.ftp_command_args.value}" + ) + return True else: - # try again - self._connect_to_server(dest_ip_address=dest_ip_address, dest_port=dest_port, is_reattempt=True) + if is_reattempt: + # reattempt failed + self.sys_log.info( + f"{self.name}: Unable to connect to FTP Server " + f"{dest_ip_address} via port {payload.ftp_command_args.value}" + ) + return False + else: + # try again + self._connect_to_server( + dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, is_reattempt=True + ) def _disconnect_from_server( self, dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = Port.FTP @@ -119,6 +130,7 @@ class FTPClient(FTPServiceABC): dest_folder_name: str, dest_file_name: str, dest_port: Optional[Port] = Port.FTP, + session_id: Optional[str] = None, ) -> bool: """ Send a file to a target IP address. @@ -143,6 +155,9 @@ class FTPClient(FTPServiceABC): :param: dest_port: The open port of the machine that hosts the FTP Server. Default is Port.FTP. :type: dest_port: Optional[Port] + + :param: session_id: The id of the session + :type: session_id: Optional[str] """ # check if the file to transfer exists on the client file_to_transfer: File = self.file_system.get_file(folder_name=src_folder_name, file_name=src_file_name) @@ -151,10 +166,7 @@ class FTPClient(FTPServiceABC): return False # check if FTP is currently connected to IP - self.connected = self._connect_to_server( - dest_ip_address=dest_ip_address, - dest_port=dest_port, - ) + self.connected = self._connect_to_server(dest_ip_address=dest_ip_address, dest_port=dest_port) if not self.connected: return False @@ -166,6 +178,7 @@ class FTPClient(FTPServiceABC): dest_file_name=dest_file_name, dest_ip_address=dest_ip_address, dest_port=dest_port, + session_id=session_id, ) # send disconnect @@ -204,10 +217,7 @@ class FTPClient(FTPServiceABC): :type: dest_port: Optional[Port] """ # check if FTP is currently connected to IP - self.connected = self._connect_to_server( - dest_ip_address=dest_ip_address, - dest_port=dest_port, - ) + self.connected = self._connect_to_server(dest_ip_address=dest_ip_address, dest_port=dest_port) if not self.connected: return False @@ -232,12 +242,36 @@ class FTPClient(FTPServiceABC): # the payload should have ok status code if payload.status_code == FTPStatusCode.OK: - self.sys_log.info(f"File {src_folder_name}/{src_file_name} found in FTP server.") + self.sys_log.info(f"{self.name}: File {src_folder_name}/{src_file_name} found in FTP server.") return True else: - self.sys_log.error(f"File {src_folder_name}/{src_file_name} does not exist in FTP server") + self.sys_log.error(f"{self.name}: File {src_folder_name}/{src_file_name} does not exist in FTP server") return False + def send( + self, + payload: FTPPacket, + session_id: Optional[str] = None, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + **kwargs, + ) -> bool: + """ + Sends a payload to the SessionManager. + + :param payload: The payload to be sent. + :param dest_ip_address: The ip address of the payload destination. + :param dest_port: The port of the payload destination. + :param session_id: The Session ID the payload is to originate from. Optional. + + :return: True if successful, False otherwise. + """ + self.sys_log.info(f"{self.name}: Sending FTP {payload.ftp_command.name} {payload.ftp_command_args}") + + return super().send( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, **kwargs + ) + def receive(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> bool: """ Receives a payload from the SessionManager. diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 83c883f1..af0728eb 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -4,7 +4,6 @@ from typing import Any, Dict, Optional from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.core.session_manager import Session from primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC from primaite.simulator.system.services.service import ServiceOperatingState @@ -30,14 +29,6 @@ class FTPServer(FTPServiceABC): super().__init__(**kwargs) self.start() - def _get_session_details(self, session_id: str) -> Session: - """ - Returns the Session object from the given session id. - - :param: session_id: ID of the session that needs details retrieved - """ - return self.software_manager.session_manager.sessions_by_uuid[session_id] - def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: """ Process the command in the FTP Packet. @@ -50,8 +41,11 @@ class FTPServer(FTPServiceABC): # if server service is down, return error if self.operating_state != ServiceOperatingState.RUNNING: payload.status_code = FTPStatusCode.ERROR + self.sys_log.error("FTP Server not running") return payload + self.sys_log.info(f"{self.name}: Received FTP {payload.ftp_command.name} {payload.ftp_command_args}") + if session_id: session_details = self._get_session_details(session_id) diff --git a/src/primaite/simulator/system/services/ftp/ftp_service.py b/src/primaite/simulator/system/services/ftp/ftp_service.py index f47b8f64..b35b7e9e 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_service.py +++ b/src/primaite/simulator/system/services/ftp/ftp_service.py @@ -5,7 +5,6 @@ from typing import Optional from primaite.simulator.file_system.file_system import File from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.services.service import Service @@ -54,7 +53,7 @@ class FTPServiceABC(Service, ABC): size=file_size, ) self.sys_log.info( - f"Created item in {self.sys_log.hostname}: {payload.ftp_command_args['dest_folder_name']}/" + f"{self.name}: Created item in {self.sys_log.hostname}: {payload.ftp_command_args['dest_folder_name']}/" f"{payload.ftp_command_args['dest_file_name']}" ) # file should exist @@ -103,12 +102,12 @@ class FTPServiceABC(Service, ABC): }, packet_payload_size=file.sim_size, ) - software_manager: SoftwareManager = self.software_manager - software_manager.send_payload_to_session_manager( + self.sys_log.info(f"{self.name}: Sending file {file.folder.name}/{file.name}") + response = self.send( payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id ) - if payload.status_code == FTPStatusCode.OK: + if response and payload.status_code == FTPStatusCode.OK: return True return False @@ -146,3 +145,27 @@ class FTPServiceABC(Service, ABC): except Exception as e: self.sys_log.error(f"Unable to retrieve file from {self.sys_log.hostname}: {e}") return False + + def send( + self, + payload: FTPPacket, + session_id: Optional[str] = None, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + **kwargs, + ) -> bool: + """ + Sends a payload to the SessionManager. + + :param payload: The payload to be sent. + :param dest_ip_address: The ip address of the payload destination. + :param dest_port: The port of the payload destination. + :param session_id: The Session ID the payload is to originate from. Optional. + + :return: True if successful, False otherwise. + """ + self.sys_log.info(f"{self.name}: Sending FTP {payload.ftp_command.name} {payload.ftp_command_args}") + + return super().send( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, **kwargs + ) diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index 30643b32..996e6790 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -33,12 +33,14 @@ class DataManipulationBot(DatabaseClient): self.server_ip_address = server_ip_address self.payload = payload self.server_password = server_password - self.sys_log.info(f"Configured the {self.name} with {server_ip_address=}, {payload=}, {server_password=}.") + self.sys_log.info( + f"{self.name}: Configured the {self.name} with {server_ip_address=}, {payload=}, {server_password=}." + ) def run(self): """Run the DataManipulationBot.""" if self.server_ip_address and self.payload: - self.sys_log.info(f"Attempting to start the {self.name}") + self.sys_log.info(f"{self.name}: Attempting to start the {self.name}") super().run() if not self.connected: self.connect() @@ -46,4 +48,4 @@ class DataManipulationBot(DatabaseClient): self.query(self.payload) self.sys_log.info(f"{self.name} payload delivered: {self.payload}") else: - self.sys_log.error(f"Failed to start the {self.name} as it requires both a target_io_address and payload.") + self.sys_log.error(f"Failed to start the {self.name} as it requires both a target_ip_address and payload.") diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 20b92027..d79487a3 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,8 +1,10 @@ from enum import Enum +from ipaddress import IPv4Address from typing import Any, Dict, Optional from primaite import getLogger from primaite.simulator.core import Action, ActionManager +from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.software import IOSoftware _LOGGER = getLogger(__name__) @@ -76,20 +78,23 @@ class Service(IOSoftware): self, payload: Any, session_id: Optional[str] = None, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, **kwargs, ) -> bool: """ Sends a payload to the SessionManager. - The specifics of how the payload is processed and whether a response payload - is generated should be implemented in subclasses. - - :param: payload: The payload to send. - :param: session_id: The id of the session + :param payload: The payload to be sent. + :param dest_ip_address: The ip address of the payload destination. + :param dest_port: The port of the payload destination. + :param session_id: The Session ID the payload is to originate from. Optional. :return: True if successful, False otherwise. """ - self.software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id) + return super().send( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, **kwargs + ) def receive( self, diff --git a/src/primaite/simulator/system/services/web_server/__init__.py b/src/primaite/simulator/system/services/web_server/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/services/web_server/web_server_service.py b/src/primaite/simulator/system/services/web_server/web_server_service.py new file mode 100644 index 00000000..276cb57f --- /dev/null +++ b/src/primaite/simulator/system/services/web_server/web_server_service.py @@ -0,0 +1,136 @@ +from ipaddress import IPv4Address +from typing import Any, Optional + +from primaite.simulator.network.protocols.http import ( + HTTPRequestMethod, + HTTPRequestPacket, + HTTPResponsePacket, + HTTPStatusCode, +) +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.services.service import Service + + +class WebServerService(Service): + """Class used to represent a Web Server Service in simulation.""" + + def __init__(self, **kwargs): + kwargs["name"] = "WebServer" + kwargs["protocol"] = IPProtocol.TCP + # default for web is port 80 + if kwargs.get("port") is None: + kwargs["port"] = Port.HTTP + + super().__init__(**kwargs) + self._install_web_files() + self.start() + + def _install_web_files(self): + """ + Installs the files hosted by the web service. + + This is usually HTML, CSS, JS or PHP files requested by browsers to display the webpage. + """ + # index HTML main file + self.file_system.create_file(file_name="index.html", folder_name="primaite", real=True) + + def _process_http_request(self, payload: HTTPRequestPacket, session_id: Optional[str] = None) -> bool: + """ + Parse the HTTPRequestPacket. + + :param: payload: Payload containing th HTTPRequestPacket + :type: payload: HTTPRequestPacket + + :param: session_id: Session id of the http request + :type: session_id: Optional[str] + """ + response = HTTPResponsePacket() + + self.sys_log.info(f"{self.name}: Received HTTP {payload.request_method.name} {payload.request_url}") + + # check the type of HTTP request + if payload.request_method == HTTPRequestMethod.GET: + response = self._handle_get_request(payload=payload) + + elif payload.request_method == HTTPRequestMethod.POST: + pass + + else: + # send a method not allowed response + response.status_code = HTTPStatusCode.METHOD_NOT_ALLOWED + + # send response to web client + self.send(payload=response, session_id=session_id) + + # return true if response is OK + return response.status_code == HTTPStatusCode.OK + + def _handle_get_request(self, payload: HTTPRequestPacket) -> HTTPResponsePacket: + """ + Handle a GET HTTP request. + + :param: payload: HTTP request payload + :type: payload: HTTPRequestPacket + """ + response = HTTPResponsePacket(status_code=HTTPStatusCode.BAD_REQUEST, payload=payload) + try: + # get data from DatabaseServer + db_client: DatabaseClient = self.software_manager.software["DatabaseClient"] + # get all users + if db_client.query("SELECT * FROM user;"): + # query succeeded + response.status_code = HTTPStatusCode.OK + + return response + except Exception: + # something went wrong on the server + response.status_code = HTTPStatusCode.INTERNAL_SERVER_ERROR + return response + + def send( + self, + payload: HTTPResponsePacket, + session_id: Optional[str] = None, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + **kwargs, + ) -> bool: + """ + Sends a payload to the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param: payload: The payload to send. + :param: session_id: The id of the session + :param dest_ip_address: The ip address of the payload destination. + :param dest_port: The port of the payload destination. + + :return: True if successful, False otherwise. + """ + self.sys_log.info(f"{self.name}: Sending HTTP Response {payload.status_code}") + + return super().send( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, **kwargs + ) + + def receive( + self, + payload: Any, + session_id: Optional[str] = None, + **kwargs, + ) -> bool: + """ + Receives a payload from the SessionManager. + + :param: payload: The payload to send. + :param: session_id: The id of the session. Optional. + """ + # check if the payload is an HTTPPacket + if not isinstance(payload, HTTPRequestPacket): + self.sys_log.error("Payload is not an HTTPPacket") + return False + + return self._process_http_request(payload=payload, session_id=session_id) diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 70c1bbf2..e8defd11 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -1,10 +1,12 @@ from abc import abstractmethod from enum import Enum +from ipaddress import IPv4Address from typing import Any, Dict, Optional from primaite.simulator.core import Action, ActionManager, SimComponent from primaite.simulator.file_system.file_system import FileSystem, Folder from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.session_manager import Session from primaite.simulator.system.core.sys_log import SysLog @@ -96,6 +98,14 @@ class Software(SimComponent): am.add_action("scan", Action(func=lambda request, context: self.scan())) return am + def _get_session_details(self, session_id: str) -> Session: + """ + Returns the Session object from the given session id. + + :param: session_id: ID of the session that needs details retrieved + """ + return self.software_manager.session_manager.sessions_by_uuid[session_id] + @abstractmethod def describe_state(self) -> Dict: """ @@ -209,18 +219,27 @@ class IOSoftware(Software): ) return state - def send(self, payload: Any, session_id: str, **kwargs) -> bool: + def send( + self, + payload: Any, + session_id: Optional[str] = None, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: Optional[Port] = None, + **kwargs, + ) -> bool: """ Sends a payload to the SessionManager. - The specifics of how the payload is processed and whether a response payload - is generated should be implemented in subclasses. + :param payload: The payload to be sent. + :param dest_ip_address: The ip address of the payload destination. + :param dest_port: The port of the payload destination. + :param session_id: The Session ID the payload is to originate from. Optional. - :param payload: The payload to send. - :param session_id: The identifier of the session that the payload is associated with. - :param kwargs: Additional keyword arguments specific to the implementation. - :return: True if the payload was successfully sent, False otherwise. + :return: True if successful, False otherwise. """ + return self.software_manager.send_payload_to_session_manager( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id + ) def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py new file mode 100644 index 00000000..fee51297 --- /dev/null +++ b/tests/integration_tests/system/test_web_client_server.py @@ -0,0 +1,19 @@ +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.protocols.http import HTTPStatusCode +from primaite.simulator.system.applications.application import ApplicationOperatingState +from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.service import ServiceOperatingState + + +def test_web_page_get_request(uc2_network): + """Test to see if the client retrieves the correct web files.""" + client_1: Computer = uc2_network.get_node_by_hostname("client_1") + web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] + web_client.run() + assert web_client.operating_state == ApplicationOperatingState.RUNNING + + assert web_client.get_webpage("http://arcd.com/index.html") is True + + # latest reponse should have status code 200 + assert web_client.latest_response is not None + assert web_client.latest_response.status_code == HTTPStatusCode.OK From 82da21b0737b194eb1a53438faa9a4c7f3c7f5f2 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 3 Oct 2023 16:56:35 +0100 Subject: [PATCH 205/980] \#1943: - changelog added - added documentation + example of using web server + web browser - extended web server so that it also accepts ip addresses - web server can differentiate between a normal page request and one that propagates into a DB request - rename WebServerService -> WebServer --- CHANGELOG.md | 1 + .../system/ftp_client_server.rst | 2 +- .../simulation_components/system/software.rst | 1 + .../web_browser_and_web_server_service.rst | 110 ++++++++++++++++++ src/primaite/simulator/network/networks.py | 4 +- .../system/applications/web_browser.py | 16 ++- .../system/services/dns/dns_client.py | 5 + .../services/web_server/web_server_service.py | 18 ++- .../system/test_web_client_server.py | 39 ++++++- 9 files changed, 180 insertions(+), 16 deletions(-) create mode 100644 docs/source/simulation_components/system/web_browser_and_web_server_service.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index 7147f82b..5d73f454 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ SessionManager. - Data Manipulator Bot - A red agent service which sends a payload to a target machine. (By default this payload is a SQL query that breaks a database) - DNS Services: `DNSClient` and `DNSServer` - FTP Services: `FTPClient` and `FTPServer` +- HTTP Services: `WebBrowser` to simulate a web client and `WebServer` ## [2.0.0] - 2023-07-26 diff --git a/docs/source/simulation_components/system/ftp_client_server.rst b/docs/source/simulation_components/system/ftp_client_server.rst index 0e4aeea3..f6011de2 100644 --- a/docs/source/simulation_components/system/ftp_client_server.rst +++ b/docs/source/simulation_components/system/ftp_client_server.rst @@ -63,7 +63,7 @@ Implementation Example Usage ----------- +------------- Dependencies ^^^^^^^^^^^^ diff --git a/docs/source/simulation_components/system/software.rst b/docs/source/simulation_components/system/software.rst index 921dfb9e..b2985393 100644 --- a/docs/source/simulation_components/system/software.rst +++ b/docs/source/simulation_components/system/software.rst @@ -19,3 +19,4 @@ Contents data_manipulation_bot dns_client_server ftp_client_server + web_browser_and_web_server_service diff --git a/docs/source/simulation_components/system/web_browser_and_web_server_service.rst b/docs/source/simulation_components/system/web_browser_and_web_server_service.rst new file mode 100644 index 00000000..a02ac621 --- /dev/null +++ b/docs/source/simulation_components/system/web_browser_and_web_server_service.rst @@ -0,0 +1,110 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +Web Browser and Web Server Service +================================== + +Web Server Service +------------------ +Provides a Web Server simulation by extending the base Service class. + +Key capabilities +^^^^^^^^^^^^^^^^ + +- Simulates a web server with the capability to also request data from a database +- Allows the emulation of HTTP requests between client (e.g. a web browser) and server + - GET request sends a get all users request to the database server and returns an HTTP 200 status if the database is responsive +- Leverages the Service base class for install/uninstall, status tracking, etc. + +Usage +^^^^^ +- Install on a Node via the ``SoftwareManager`` to start the `WebServer`. +- Service runs on HTTP port 80 by default. (TODO: HTTPS) + +Implementation +^^^^^^^^^^^^^^ + +- HTTP request uses a ``HTTPRequestPacket`` object +- HTTP reaponse uses a ``HTTPResponsePacket`` object +- Extends Service class for integration with ``SoftwareManager``. + +Web Browser (Web Client) +------------------------ + +The ``WebBrowser`` provides a client interface for connecting to the ``WebServer``. + +Key features +^^^^^^^^^^^^ + +- Connects to the ``WebServer`` via the ``SoftwareManager``. +- Simulates HTTP requests and HTTP packet transfer across a network +- Allows the emulation of HTTP requests between client and server: + - Automatically uses ``DNSClient`` to resolve domain names + - GET: performs an HTTP GET request from client to server +- Leverages the Service base class for install/uninstall, status tracking, etc. + +Usage +^^^^^ + +- Install on a Node via the ``SoftwareManager`` to start the ``WebBrowser``. +- Service runs on HTTP port 80 by default. (TODO: HTTPS) +- Execute sending an HTTP GET request with ``get_webpage`` + +Implementation +^^^^^^^^^^^^^^ + +- Leverages ``SoftwareManager`` for sending payloads over the network. +- Provides easy interface for making HTTP requests between an HTTP client and server. +- Extends base Service class. + + +Example Usage +------------- + +Dependencies +^^^^^^^^^^^^ + +.. code-block:: python + + from primaite.simulator.network.container import Network + from primaite.simulator.network.hardware.nodes.computer import Computer + from primaite.simulator.network.hardware.nodes.server import Server + from primaite.simulator.system.applications.web_browser import WebBrowser + from primaite.simulator.system.services.web_server.web_server_service import WebServer + +Example peer to peer network +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: python + + net = Network() + + pc1 = Computer(hostname="pc1", ip_address="192.168.1.50", subnet_mask="255.255.255.0") + srv = Server(hostname="srv", ip_address="192.168.1.10", subnet_mask="255.255.255.0") + pc1.power_on() + srv.power_on() + net.connect(pc1.ethernet_port[1], srv.ethernet_port[1]) + +Install the Web Server +^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: python + + # web browser is automatically installed in computer nodes + # IRL this is usually included with an OS + client: WebBrowser = pc1.software_manager.software['WebBrowser'] + + # install web server + srv.software_manager.install(WebServer) + webserv: WebServer = srv.software_manager.software['WebServer'] + +Open the web page +^^^^^^^^^^^^^^^^^ + +Using a domain name to connect to a website requires setting up DNS Servers. For this example, it is possible to use the IP address directly + +.. code-block:: python + + # check that the get request succeeded + print(client.get_webpage("http://192.168.1.10")) # should be True diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 1ddeb82f..4f9aebdc 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -14,7 +14,7 @@ from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.ftp.ftp_client import FTPClient from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot -from primaite.simulator.system.services.web_server.web_server_service import WebServerService +from primaite.simulator.system.services.web_server.web_server_service import WebServer def client_server_routed() -> Network: @@ -260,7 +260,7 @@ def arcd_uc2_network() -> Network: database_client.run() database_client.connect() - web_server.software_manager.install(WebServerService) + web_server.software_manager.install(WebServer) # register the web_server to a domain dns_server_service: DNSServer = domain_controller.software_manager.software["DNSServer"] # noqa diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 9d2c31b1..69de333e 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -74,11 +74,17 @@ class WebBrowser(Application): domain_exists = dns_client.check_domain_exists(target_domain=parsed_url.hostname) # if domain does not exist, the request fails - if not domain_exists: - return False - - # set current domain name IP address - self.domain_name_ip_address = dns_client.dns_cache[parsed_url.hostname] + if domain_exists: + # set current domain name IP address + self.domain_name_ip_address = dns_client.dns_cache[parsed_url.hostname] + else: + # check if url is an ip address + try: + self.domain_name_ip_address = IPv4Address(parsed_url.hostname) + except Exception: + # unable to deal with this request + self.sys_log.error(f"{self.name}: Unable to resolve URL {url}") + return False # create HTTPRequest payload payload = HTTPRequestPacket(request_method=HTTPRequestMethod.GET, request_url=url) diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 620a9a32..266ac4f6 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -72,6 +72,11 @@ class DNSClient(Service): :param: session_id: The Session ID the payload is to originate from. Optional. :param: is_reattempt: Checks if the request has been reattempted. Default is False. """ + # check if DNS server is configured + if self.dns_server is None: + self.sys_log.error(f"{self.name}: DNS Server is not configured") + return False + # check if the target domain is in the client's DNS cache payload = DNSPacket(dns_request=DNSRequest(domain_name_request=target_domain)) diff --git a/src/primaite/simulator/system/services/web_server/web_server_service.py b/src/primaite/simulator/system/services/web_server/web_server_service.py index 276cb57f..68624930 100644 --- a/src/primaite/simulator/system/services/web_server/web_server_service.py +++ b/src/primaite/simulator/system/services/web_server/web_server_service.py @@ -1,5 +1,6 @@ from ipaddress import IPv4Address from typing import Any, Optional +from urllib.parse import urlparse from primaite.simulator.network.protocols.http import ( HTTPRequestMethod, @@ -13,7 +14,7 @@ from primaite.simulator.system.applications.database_client import DatabaseClien from primaite.simulator.system.services.service import Service -class WebServerService(Service): +class WebServer(Service): """Class used to represent a Web Server Service in simulation.""" def __init__(self, **kwargs): @@ -76,13 +77,20 @@ class WebServerService(Service): """ response = HTTPResponsePacket(status_code=HTTPStatusCode.BAD_REQUEST, payload=payload) try: - # get data from DatabaseServer - db_client: DatabaseClient = self.software_manager.software["DatabaseClient"] - # get all users - if db_client.query("SELECT * FROM user;"): + parsed_url = urlparse(payload.request_url) + + if parsed_url.path is None or len(parsed_url.path) < 1: # query succeeded response.status_code = HTTPStatusCode.OK + if parsed_url.path.startswith("/users"): + # get data from DatabaseServer + db_client: DatabaseClient = self.software_manager.software["DatabaseClient"] + # get all users + if db_client.query("SELECT * FROM user;"): + # query succeeded + response.status_code = HTTPStatusCode.OK + return response except Exception: # something went wrong on the server diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py index fee51297..8b6f4072 100644 --- a/tests/integration_tests/system/test_web_client_server.py +++ b/tests/integration_tests/system/test_web_client_server.py @@ -1,18 +1,51 @@ from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.http import HTTPStatusCode from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.service import ServiceOperatingState -def test_web_page_get_request(uc2_network): - """Test to see if the client retrieves the correct web files.""" +def test_web_page_home_page(uc2_network): + """Test to see if the browser is able to open the main page of the web server.""" client_1: Computer = uc2_network.get_node_by_hostname("client_1") web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] web_client.run() assert web_client.operating_state == ApplicationOperatingState.RUNNING - assert web_client.get_webpage("http://arcd.com/index.html") is True + assert web_client.get_webpage("http://arcd.com/") is True + + # latest reponse should have status code 200 + assert web_client.latest_response is not None + assert web_client.latest_response.status_code == HTTPStatusCode.OK + + +def test_web_page_get_users_page_request_with_domain_name(uc2_network): + """Test to see if the client can handle requests with domain names""" + client_1: Computer = uc2_network.get_node_by_hostname("client_1") + web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] + web_client.run() + assert web_client.operating_state == ApplicationOperatingState.RUNNING + + assert web_client.get_webpage("http://arcd.com/users/") is True + + # latest reponse should have status code 200 + assert web_client.latest_response is not None + assert web_client.latest_response.status_code == HTTPStatusCode.OK + + +def test_web_page_get_users_page_request_with_ip_address(uc2_network): + """Test to see if the client can handle requests that use ip_address.""" + client_1: Computer = uc2_network.get_node_by_hostname("client_1") + web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] + web_client.run() + + web_server: Server = uc2_network.get_node_by_hostname("web_server") + web_server_ip = web_server.nics.get(next(iter(web_server.nics))).ip_address + + assert web_client.operating_state == ApplicationOperatingState.RUNNING + + assert web_client.get_webpage(f"http://{web_server_ip}/users/") is True # latest reponse should have status code 200 assert web_client.latest_response is not None From fabd4fd5ddd957ff8abfa3a9d361d04d743fb490 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 4 Oct 2023 09:07:04 +0100 Subject: [PATCH 206/980] Add ACL Action to game layer --- src/primaite/game/agent/actions.py | 48 ++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index cb7061fc..6c4ae3b2 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -227,11 +227,39 @@ class NodeResetAction(NodeAbstractAction): self.verb = 'reset' class NetworkACLAddRuleAction(AbstractAction): - def __init__(self, manager: "ActionManager", **kwargs) -> None: + def __init__(self, + manager: "ActionManager", + target_router_uuid:str, + max_acl_rules:int, + num_ips:int, + num_ports:int, + num_protocols:int, + **kwargs) -> None: super().__init__(manager=manager) num_permissions = 2 - self.shape: Tuple[int] = (max_acl_rules, num_permissions, num_nics, num_nics, num_ports, num_ports, num_protocols) + self.shape: Tuple[int] = (max_acl_rules, num_permissions, num_ips, num_ips, num_ports, num_ports, num_protocols) + self.target_router_uuid:str = target_router_uuid + def form_request(self, position, permission, source_ip_idx, dest_ip_idx, source_port_idx, dest_port_idx, protocol_idx) -> List[str]: + protocol = self.manager.get_internet_protocol_by_idx(protocol_idx) + src_ip = self.manager.get_ip_address_by_idx(source_ip_idx) + src_port = self.manager.get_port_by_idx(source_port_idx) + dst_ip = self.manager.get_ip_address_by_idx(dest_ip_idx) + dst_port = self.manager.get_port_by_idx(dest_port_idx) + return [ + 'network', + 'node', + self.target_router_uuid, + 'acl', + 'add_rule', + permission, + protocol, + src_ip, + src_port, + dst_ip, + dst_port, + position + ] @@ -289,9 +317,14 @@ class ActionManager: max_services_per_node:int = 2, max_nics_per_node:int=8, max_acl_rules:int=10, + protocols:List[str]=['TCP','UDP','ICMP'], + ports:List[str]=['HTTP','DNS','ARP','FTP'], + ip_address_list:Optional[List[str]]=None, act_map:Optional[Dict[int, Dict]]=None) -> None: self.sim: Simulation = sim self.node_uuids:List[str] = node_uuids + self.protocols:List[str] = protocols + self.ports:List[str] = ports action_args = { "num_nodes": len(node_uuids), @@ -299,7 +332,10 @@ class ActionManager: "num_files": max_files_per_folder, "num_services": max_services_per_node, "num_nics": max_nics_per_node, - "num_acl_rules": max_acl_rules} + "num_acl_rules": max_acl_rules, + "num_protocols": len(self.protocols), + "num_ports": len(self.protocols), + "num_ips":} self.actions: Dict[str, AbstractAction] = {} for act_type in actions: self.actions[act_type] = self.__act_class_identifiers[act_type](self, **action_args) @@ -362,8 +398,14 @@ class ActionManager: service_uuids = list(node.services.keys()) return service_uuids[service_idx] if len(service_uuids)>service_idx else None + def get_internet_protocol_by_idx(self, protocol_idx:int) -> str: + # protocol = self.manager.get_internet_protocol_by_idx(protocol_idx) + # src_ip = self.manager.get_ip_address_by_idx(source_ip_idx) + # src_port = self.manager.get_port_by_idx(source_port_idx) + # dst_ip = self.manager.get_ip_address_by_idx(dest_ip_idx) + # dst_port = self.manager.get_port_by_idx(dest_port_idx) From 97f0267539c67e847f416d5de46629edd23cac21 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Wed, 4 Oct 2023 11:33:18 +0100 Subject: [PATCH 207/980] #1796: apply PR suggestions + fix tests --- CHANGELOG.md | 2 +- .../system/database_client_server.rst | 2 +- .../simulator/network/hardware/base.py | 8 +------- .../network/hardware/nodes/computer.py | 13 ++++++++++++ .../services/database/database_service.py | 20 ++----------------- .../system/services/ftp/ftp_client.py | 9 ++++++--- .../_simulator/_system/_services/test_dns.py | 10 ++++++++-- .../_simulator/_system/_services/test_ftp.py | 10 ++++++++-- 8 files changed, 40 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc9c26d1..a5bc08f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ SessionManager. 1. Creating a simulation - this notebook explains how to build up a simulation using the Python package. (WIP) - Database: - `DatabaseClient` and `DatabaseService` created to allow emulation of database actions - - Ability to `backup_database` and `restore_backup` for a `DatabaseService` + - Ability for `DatabaseService` to backup its data to another server via FTP and restore data from backup - Red Agent Services: - Data Manipulator Bot - A red agent service which sends a payload to a target machine. (By default this payload is a SQL query that breaks a database) - DNS Services: `DNSClient` and `DNSServer` diff --git a/docs/source/simulation_components/system/database_client_server.rst b/docs/source/simulation_components/system/database_client_server.rst index ef911e0e..32568477 100644 --- a/docs/source/simulation_components/system/database_client_server.rst +++ b/docs/source/simulation_components/system/database_client_server.rst @@ -62,7 +62,7 @@ Usage To create database backups: -- Configure the backup server the ``DatabaseService`` by providing the Backup server ``IPv4Address`` with ``configure_backup`` +- Configure the backup server on the ``DatabaseService`` by providing the Backup server ``IPv4Address`` with ``configure_backup`` - Create a backup using ``backup_database``. This fails if the backup server is not configured. - Restore a backup using ``restore_backup``. By default, this uses the database created via ``backup_database``. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 7c08f9fc..2725ab1a 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -25,8 +25,6 @@ from primaite.simulator.system.core.session_manager import SessionManager from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.processes.process import Process -from primaite.simulator.system.services.dns.dns_client import DNSClient -from primaite.simulator.system.services.ftp.ftp_client import FTPClient from primaite.simulator.system.services.service import Service _LOGGER = getLogger(__name__) @@ -945,11 +943,7 @@ class Node(SimComponent): def _install_system_software(self): """Install System Software - software that is usually provided with the OS.""" - # DNS Client - self.software_manager.install(DNSClient) - - # FTP - self.software_manager.install(FTPClient) + pass def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/network/hardware/nodes/computer.py b/src/primaite/simulator/network/hardware/nodes/computer.py index 5452666b..3ceb5291 100644 --- a/src/primaite/simulator/network/hardware/nodes/computer.py +++ b/src/primaite/simulator/network/hardware/nodes/computer.py @@ -1,4 +1,6 @@ from primaite.simulator.network.hardware.base import NIC, Node +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.ftp.ftp_client import FTPClient class Computer(Node): @@ -36,3 +38,14 @@ class Computer(Node): def __init__(self, **kwargs): super().__init__(**kwargs) self.connect_nic(NIC(ip_address=kwargs["ip_address"], subnet_mask=kwargs["subnet_mask"])) + self._install_system_software() + + def _install_system_software(self): + """Install System Software - software that is usually provided with the OS.""" + # DNS Client + self.software_manager.install(DNSClient) + + # FTP + self.software_manager.install(FTPClient) + + super()._install_system_software() diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index f874b89b..0a6de8c3 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -83,15 +83,7 @@ class DatabaseService(Service): self.backup_server = backup_server def backup_database(self) -> bool: - """ - Create a backup of the database to the configured backup server. - - :param: backup_directory: Name of directory where backup will be stored. Optional. - :type: backup_directory: Optional[str] - - :param: backup_file_name: Name of file where backup will be stored. Optional. - :type: backup_file_name: Optional[str] - """ + """Create a backup of the database to the configured backup server.""" # check if the backup server was configured if self.backup_server is None: self.sys_log.error(f"{self.name} - {self.sys_log.hostname}: not configured.") @@ -120,15 +112,7 @@ class DatabaseService(Service): return False def restore_backup(self) -> bool: - """ - Restore a backup from backup server. - - :param: backup_directory: Name of directory where backup will be stored. Optional. - :type: backup_directory: Optional[str] - - :param: backup_file_name: Name of file where backup will be stored. Optional. - :type: backup_file_name: Optional[str] - """ + """Restore a backup from backup server.""" software_manager: SoftwareManager = self.software_manager ftp_client_service: FTPClient = software_manager.software["FTPClient"] diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index c22f704b..648b2494 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -107,7 +107,7 @@ class FTPClient(FTPServiceABC): payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port ) if payload.status_code == FTPStatusCode.OK: - self.connected = None + self.connected = False return True return False @@ -162,13 +162,16 @@ class FTPClient(FTPServiceABC): else: self.sys_log.info(f"Sending file {src_folder_name}/{src_file_name} to {str(dest_ip_address)}") # send STOR request - return self._send_data( + if self._send_data( file=file_to_transfer, dest_folder_name=dest_folder_name, dest_file_name=dest_file_name, dest_ip_address=dest_ip_address, dest_port=dest_port, - ) + ): + return self._disconnect_from_server(dest_ip_address=dest_ip_address, dest_port=dest_port) + + return False def request_file( self, diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py index d86791cd..31718387 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py @@ -3,6 +3,8 @@ from ipaddress import IPv4Address import pytest from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.dns import DNSPacket, DNSReply, DNSRequest from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -12,7 +14,9 @@ from primaite.simulator.system.services.dns.dns_server import DNSServer @pytest.fixture(scope="function") def dns_server() -> Node: - node = Node(hostname="dns_server") + node = Server( + hostname="dns_server", ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + ) node.software_manager.install(software_class=DNSServer) node.software_manager.software["DNSServer"].start() return node @@ -20,7 +24,9 @@ def dns_server() -> Node: @pytest.fixture(scope="function") def dns_client() -> Node: - node = Node(hostname="dns_client") + node = Computer( + hostname="dns_client", ip_address="192.168.1.11", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + ) return node diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py index fce4a487..3ccb0c99 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py @@ -3,6 +3,8 @@ from ipaddress import IPv4Address import pytest from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -12,7 +14,9 @@ from primaite.simulator.system.services.ftp.ftp_server import FTPServer @pytest.fixture(scope="function") def ftp_server() -> Node: - node = Node(hostname="ftp_server") + node = Server( + hostname="ftp_server", ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + ) node.software_manager.install(software_class=FTPServer) node.software_manager.software["FTPServer"].start() return node @@ -20,7 +24,9 @@ def ftp_server() -> Node: @pytest.fixture(scope="function") def ftp_client() -> Node: - node = Node(hostname="ftp_client") + node = Computer( + hostname="ftp_client", ip_address="192.168.1.11", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + ) return node From be6b904db9540fc55bf51ba645bc3804c7f0c12a Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Thu, 5 Oct 2023 16:24:48 +0100 Subject: [PATCH 208/980] - Fixed FTP client server infinite recursion - ftp server and clients can be installed on the same node, this could cause a loop of requests - fixed tests broken by merged with dev --- .../system/services/ftp/ftp_client.py | 30 +++--------- .../system/services/ftp/ftp_server.py | 14 +++++- .../simulator/system/services/service.py | 46 +------------------ .../services/web_server/web_server_service.py | 5 +- .../_simulator/_system/_services/test_dns.py | 6 ++- .../_simulator/_system/_services/test_ftp.py | 3 +- 6 files changed, 30 insertions(+), 74 deletions(-) diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 4575f985..b2a1e8bf 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -97,6 +97,9 @@ class FTPClient(FTPServiceABC): self._connect_to_server( dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, is_reattempt=True ) + else: + self.sys_log.error(f"{self.name}: Unable to send FTPPacket") + return False def _disconnect_from_server( self, dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = Port.FTP @@ -247,30 +250,6 @@ class FTPClient(FTPServiceABC): self.sys_log.error(f"{self.name}: File {src_folder_name}/{src_file_name} does not exist in FTP server") return False - def send( - self, - payload: FTPPacket, - session_id: Optional[str] = None, - dest_ip_address: Optional[IPv4Address] = None, - dest_port: Optional[Port] = None, - **kwargs, - ) -> bool: - """ - Sends a payload to the SessionManager. - - :param payload: The payload to be sent. - :param dest_ip_address: The ip address of the payload destination. - :param dest_port: The port of the payload destination. - :param session_id: The Session ID the payload is to originate from. Optional. - - :return: True if successful, False otherwise. - """ - self.sys_log.info(f"{self.name}: Sending FTP {payload.ftp_command.name} {payload.ftp_command_args}") - - return super().send( - payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, **kwargs - ) - def receive(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> bool: """ Receives a payload from the SessionManager. @@ -285,5 +264,8 @@ class FTPClient(FTPServiceABC): self.sys_log.error(f"{payload} is not an FTP packet") return False + if payload.status_code is None: + return False + self._process_ftp_command(payload=payload, session_id=session_id) return True diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 62358ff2..d93150e0 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -38,9 +38,11 @@ class FTPServer(FTPServiceABC): :param: session_id: session ID linked to the FTP Packet. Optional. :type: session_id: Optional[str] """ + # error code by default + payload.status_code = FTPStatusCode.ERROR + # if server service is down, return error if self.operating_state != ServiceOperatingState.RUNNING: - payload.status_code = FTPStatusCode.ERROR self.sys_log.error("FTP Server not running") return payload @@ -61,9 +63,13 @@ class FTPServer(FTPServiceABC): payload.status_code = FTPStatusCode.OK return payload + self.sys_log.error(f"Invalid Port {payload.ftp_command_args}") + return payload + if payload.ftp_command == FTPCommand.QUIT: self.connections.pop(session_id) payload.status_code = FTPStatusCode.OK + return payload return super()._process_ftp_command(payload=payload, session_id=session_id, **kwargs) @@ -73,5 +79,11 @@ class FTPServer(FTPServiceABC): self.sys_log.error(f"{payload} is not an FTP packet") return False + """ + Usually + """ + if payload.status_code is not None: + return False + self.send(self._process_ftp_command(payload=payload, session_id=session_id), session_id) return True diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index d79487a3..aa1d5031 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,10 +1,8 @@ from enum import Enum -from ipaddress import IPv4Address -from typing import Any, Dict, Optional +from typing import Dict, Optional from primaite import getLogger from primaite.simulator.core import Action, ActionManager -from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.software import IOSoftware _LOGGER = getLogger(__name__) @@ -74,48 +72,6 @@ class Service(IOSoftware): """ pass - def send( - self, - payload: Any, - session_id: Optional[str] = None, - dest_ip_address: Optional[IPv4Address] = None, - dest_port: Optional[Port] = None, - **kwargs, - ) -> bool: - """ - Sends a payload to the SessionManager. - - :param payload: The payload to be sent. - :param dest_ip_address: The ip address of the payload destination. - :param dest_port: The port of the payload destination. - :param session_id: The Session ID the payload is to originate from. Optional. - - :return: True if successful, False otherwise. - """ - return super().send( - payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, **kwargs - ) - - def receive( - self, - payload: Any, - session_id: Optional[str] = None, - **kwargs, - ) -> bool: - """ - Receives a payload from the SessionManager. - - The specifics of how the payload is processed and whether a response payload - is generated should be implemented in subclasses. - - :param: payload: The payload to send. - :param: session_id: The id of the session - - :return: True if successful, False otherwise. - """ - - pass - def stop(self) -> None: """Stop the service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: diff --git a/src/primaite/simulator/system/services/web_server/web_server_service.py b/src/primaite/simulator/system/services/web_server/web_server_service.py index 68624930..59686388 100644 --- a/src/primaite/simulator/system/services/web_server/web_server_service.py +++ b/src/primaite/simulator/system/services/web_server/web_server_service.py @@ -78,12 +78,13 @@ class WebServer(Service): response = HTTPResponsePacket(status_code=HTTPStatusCode.BAD_REQUEST, payload=payload) try: parsed_url = urlparse(payload.request_url) + path = parsed_url.path.strip("/") - if parsed_url.path is None or len(parsed_url.path) < 1: + if len(path) < 1: # query succeeded response.status_code = HTTPStatusCode.OK - if parsed_url.path.startswith("/users"): + if path.startswith("users"): # get data from DatabaseServer db_client: DatabaseClient = self.software_manager.software["DatabaseClient"] # get all users diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py index 31718387..dc6df5d4 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py @@ -25,7 +25,11 @@ def dns_server() -> Node: @pytest.fixture(scope="function") def dns_client() -> Node: node = Computer( - hostname="dns_client", ip_address="192.168.1.11", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + hostname="dns_client", + ip_address="192.168.1.11", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + dns_server=IPv4Address("192.168.1.10"), ) return node diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py index 3ccb0c99..d382b8dd 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py @@ -5,7 +5,7 @@ import pytest from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket +from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.ftp.ftp_client import FTPClient @@ -78,6 +78,7 @@ def test_ftp_client_store_file(ftp_client): "file_size": 24, }, packet_payload_size=24, + status_code=FTPStatusCode.OK, ) ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] From 2a8df074b963cefe37f47141af861b6f3ef85238 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 6 Oct 2023 10:36:29 +0100 Subject: [PATCH 209/980] Add network action --- example_config.yaml | 56 ++-- src/primaite/game/agent/actions.py | 385 ++++++++++++++++++--------- src/primaite/game/agent/interface.py | 24 +- src/primaite/game/session.py | 289 +++++++++++++++++++- 4 files changed, 574 insertions(+), 180 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index 8cf401cc..b47355c3 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -131,32 +131,36 @@ game_config: action_space: action_list: - - DONOTHING - - NODE_SERVICE_SCAN - - NODE_SERVICE_STOP - # - NODE_SERVICE_START - # - NODE_SERVICE_PAUSE - # - NODE_SERVICE_RESUME - # - NODE_SERVICE_RESTART - # - NODE_SERVICE_DISABLE - # - NODE_SERVICE_ENABLE - # - NODE_FILE_SCAN - # - NODE_FILE_CHECKHASH - # - NODE_FILE_DELETE - # - NODE_FILE_REPAIR - # - NODE_FILE_RESTORE - # - NODE_FOLDER_SCAN - # - NODE_FOLDER_CHECKHASH - # - NODE_FOLDER_REPAIR - # - NODE_FOLDER_RESTORE - # - NODE_OS_SCAN - # - NODE_SHUTDOWN - # - NODE_STARTUP - # - NODE_RESET - # - NETWORK_ACL_ADDRULE - # - NETWORK_ACL_REMOVERULE - # - NETWORK_NIC_ENABLE - - NETWORK_NIC_DISABLE + - type: DONOTHING + - type: NODE_SERVICE_SCAN + - type: NODE_SERVICE_STOP + - type: NODE_SERVICE_START + - type: NODE_SERVICE_PAUSE + - type: NODE_SERVICE_RESUME + - type: NODE_SERVICE_RESTART + - type: NODE_SERVICE_DISABLE + - type: NODE_SERVICE_ENABLE + - type: NODE_FILE_SCAN + - type: NODE_FILE_CHECKHASH + - type: NODE_FILE_DELETE + - type: NODE_FILE_REPAIR + - type: NODE_FILE_RESTORE + - type: NODE_FOLDER_SCAN + - type: NODE_FOLDER_CHECKHASH + - type: NODE_FOLDER_REPAIR + - type: NODE_FOLDER_RESTORE + - type: NODE_OS_SCAN + - type: NODE_SHUTDOWN + - type: NODE_STARTUP + - type: NODE_RESET + - type: NETWORK_ACL_ADDRULE + options: + target_router_ref: router_1 + - type: NETWORK_ACL_REMOVERULE + options: + target_router_ref: router_1 + - type: NETWORK_NIC_ENABLE + - type: NETWORK_NIC_DISABLE action_map: 0: diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 6c4ae3b2..f6f96161 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -1,12 +1,13 @@ +import itertools from abc import ABC, abstractmethod from typing import Any, Dict, List, Optional, Tuple -import itertools - - -from primaite.simulator.sim_container import Simulation from gym import spaces +from primaite.game.session import PrimaiteSession +from primaite.simulator.sim_container import Simulation + + class ExecutionDefiniton(ABC): """ Converter from actions to simulator requests. @@ -23,9 +24,8 @@ class ExecutionDefiniton(ABC): class AbstractAction(ABC): - @abstractmethod - def __init__(self, manager:"ActionManager", **kwargs) -> None: + def __init__(self, manager: "ActionManager", **kwargs) -> None: """ Init method for action. @@ -35,13 +35,12 @@ class AbstractAction(ABC): per node), we need to pass those options to every action that gets created. To pervent verbosity, these parameters are just broadcasted to all actions and the actions can pay attention to the ones that apply. """ - self.name:str = "" + self.name: str = "" """Human-readable action identifier used for printing, logging, and reporting.""" - self.shape = (0,) - """Tuple describing number of options for each parameter of this action. Can be passed to - gym.spaces.MultiDiscrete to form a valid space.""" - self.manager:ActionManager = manager - + self.shape: Dict[str, int] = {} + """Dictionary describing the number of options for each parameter of this action. The keys of this dict must + align with the keyword args of the form_request method.""" + self.manager: ActionManager = manager @abstractmethod def form_request(self) -> List[str]: @@ -50,14 +49,20 @@ class AbstractAction(ABC): class DoNothingAction(AbstractAction): - def __init__(self, manager:"ActionManager", **kwargs) -> None: + def __init__(self, manager: "ActionManager", **kwargs) -> None: super().__init__(manager=manager) self.name = "DONOTHING" - self.shape = (1,) + self.shape: Dict[str, int] = { + "dummy": 1, + } + # This action does not accept any parameters, therefore it technically has a gymnasium shape of Discrete(1), + # i.e. a choice between one option. To make enumerating this action easier, we are adding a 'dummy' paramter + # with one option. This just aids the Action Manager to enumerate all possibilities. def form_request(self) -> List[str]: return ["do_nothing"] + class NodeServiceAbstractAction(AbstractAction): """ Base class for service actions. @@ -65,211 +70,284 @@ class NodeServiceAbstractAction(AbstractAction): Any action which applies to a service and uses node_id and service_id as its only two parameters can inherit from this base class. """ - @abstractmethod - def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: - super().__init__(manager=manager) - self.shape: Tuple[int] = (num_nodes, num_services) - self.verb:str - def form_request(self, node_id:int, service_id:int) -> List[str]: + @abstractmethod + def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: + super().__init__(manager=manager) + self.shape: Dict[str, int] = {"node_id": num_nodes, "service_id": num_services} + self.verb: str + + def form_request(self, node_id: int, service_id: int) -> List[str]: node_uuid = self.manager.get_node_uuid_by_idx(node_id) service_uuid = self.manager.get_service_uuid_by_idx(node_id, service_id) if node_uuid is None or service_uuid is None: return ["do_nothing"] - return ['network', 'node', node_uuid, 'services', service_uuid, self.verb] + return ["network", "node", node_uuid, "services", service_uuid, self.verb] + class NodeServiceScanAction(NodeServiceAbstractAction): - def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: super().__init__(manager=manager) self.verb = "scan" + class NodeServiceStopAction(NodeServiceAbstractAction): - def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: super().__init__(manager=manager) self.verb = "stop" + class NodeServiceStartAction(NodeServiceAbstractAction): - def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: super().__init__(manager=manager) self.verb = "start" + class NodeServicePauseAction(NodeServiceAbstractAction): - def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: super().__init__(manager=manager) self.verb = "pause" + class NodeServiceResumeAction(NodeServiceAbstractAction): - def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: super().__init__(manager=manager) self.verb = "resume" + class NodeServiceRestartAction(NodeServiceAbstractAction): - def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: super().__init__(manager=manager) self.verb = "restart" + class NodeServiceDisableAction(NodeServiceAbstractAction): - def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: super().__init__(manager=manager) self.verb = "disable" + class NodeServiceEnableAction(NodeServiceAbstractAction): - def __init__(self, manager:"ActionManager", num_nodes, num_services, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: super().__init__(manager=manager) self.verb = "enable" - class NodeFolderAbstractAction(AbstractAction): @abstractmethod - def __init__(self, manager:"ActionManager", num_nodes, num_folders, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes, num_folders, **kwargs) -> None: super().__init__(manager=manager) - self.shape = (num_nodes, num_folders) + self.shape: Dict[str, int] = {"node_id": num_nodes, "folder_id": num_folders} self.verb: str - def form_request(self, node_id:int, folder_id:int) -> List[str]: + def form_request(self, node_id: int, folder_id: int) -> List[str]: node_uuid = self.manager.get_node_uuid_by_idx(node_id) folder_uuid = self.manager.get_folder_uuid_by_idx(node_idx=node_id, folder_idx=folder_id) if node_uuid is None or folder_uuid is None: return ["do_nothing"] - return ['network', 'node', node_uuid, 'file_system', 'folder', folder_uuid, self.verb] + return ["network", "node", node_uuid, "file_system", "folder", folder_uuid, self.verb] + class NodeFolderScanAction(NodeFolderAbstractAction): - def __init__(self, manager:"ActionManager", num_nodes, num_folders, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes, num_folders, **kwargs) -> None: super().__init__(manager, num_nodes, num_folders, **kwargs) - self.verb:str = "scan" + self.verb: str = "scan" + class NodeFolderCheckhashAction(NodeFolderAbstractAction): - def __init__(self, manager:"ActionManager", num_nodes, num_folders, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes, num_folders, **kwargs) -> None: super().__init__(manager, num_nodes, num_folders, **kwargs) - self.verb:str = "checkhash" + self.verb: str = "checkhash" + class NodeFolderRepairAction(NodeFolderAbstractAction): - def __init__(self, manager:"ActionManager", num_nodes, num_folders, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes, num_folders, **kwargs) -> None: super().__init__(manager, num_nodes, num_folders, **kwargs) - self.verb:str = "repair" + self.verb: str = "repair" + class NodeFolderRestoreAction(NodeFolderAbstractAction): def __init__(self, manager: "ActionManager", num_nodes, num_folders, **kwargs) -> None: super().__init__(manager, num_nodes, num_folders, **kwargs) - self.verb:str = "restore" + self.verb: str = "restore" class NodeFileAbstractAction(AbstractAction): @abstractmethod - def __init__(self, manager:"ActionManager", num_nodes:int, num_folders:int, num_files:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager=manager) - self.shape:Tuple[int] = (num_nodes, num_folders, num_files) - self.verb:str + self.shape: Dict[str, int] = {"node_id": num_nodes, "folder_id": num_folders, "file_id": num_files} + self.verb: str - def form_request(self, node_id:int, folder_id:int, file_id:int) -> List[str]: + def form_request(self, node_id: int, folder_id: int, file_id: int) -> List[str]: node_uuid = self.manager.get_node_uuid_by_idx(node_id) folder_uuid = self.manager.get_folder_uuid_by_idx(node_idx=node_id, folder_idx=folder_id) file_uuid = self.manager.get_file_uuid_by_idx(node_idx=node_id, folder_idx=folder_id, file_idx=file_id) if node_uuid is None or folder_uuid is None or file_uuid is None: return ["do_nothing"] - return ['network', 'node', node_uuid, 'file_system', 'folder', folder_uuid, 'files', file_uuid, self.verb] + return ["network", "node", node_uuid, "file_system", "folder", folder_uuid, "files", file_uuid, self.verb] + class NodeFileScanAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) self.verb = "scan" + class NodeFileCheckhashAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) self.verb = "checkhash" + class NodeFileDeleteAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) self.verb = "delete" + class NodeFileRepairAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) self.verb = "repair" + class NodeFileRestoreAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) self.verb = "restore" + class NodeAbstractAction(AbstractAction): @abstractmethod def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager) - self.shape: Tuple[int] = (num_nodes,) + self.shape: Dict[str, int] = {"node_id": num_nodes} self.verb: str - def form_request(self, node_id:int) -> List[str]: + def form_request(self, node_id: int) -> List[str]: node_uuid = self.manager.get_node_uuid_by_idx(node_id) return ["network", "node", node_uuid, self.verb] + class NodeOSScanAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager) - self.verb = 'scan' + self.verb = "scan" + class NodeShutdownAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager) - self.verb = 'shutdown' + self.verb = "shutdown" + class NodeStartupAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager) - self.verb = 'start' + self.verb = "start" + class NodeResetAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager) - self.verb = 'reset' + self.verb = "reset" + class NetworkACLAddRuleAction(AbstractAction): - def __init__(self, - manager: "ActionManager", - target_router_uuid:str, - max_acl_rules:int, - num_ips:int, - num_ports:int, - num_protocols:int, - **kwargs) -> None: + def __init__( + self, + manager: "ActionManager", + target_router_uuid: str, + max_acl_rules: int, + num_ips: int, + num_ports: int, + num_protocols: int, + **kwargs, + ) -> None: super().__init__(manager=manager) num_permissions = 2 - self.shape: Tuple[int] = (max_acl_rules, num_permissions, num_ips, num_ips, num_ports, num_ports, num_protocols) - self.target_router_uuid:str = target_router_uuid + self.shape: Dict[str, int] = { + "position": max_acl_rules, + "permission": num_permissions, + "source_ip_idx": num_ips, + "dest_ip_idx": num_ips, + "source_port_idx": num_ports, + "dest_port_idx": num_ports, + "protocol_idx": num_protocols, + } + self.target_router_uuid: str = target_router_uuid - def form_request(self, position, permission, source_ip_idx, dest_ip_idx, source_port_idx, dest_port_idx, protocol_idx) -> List[str]: + def form_request( + self, position, permission, source_ip_idx, dest_ip_idx, source_port_idx, dest_port_idx, protocol_idx + ) -> List[str]: protocol = self.manager.get_internet_protocol_by_idx(protocol_idx) src_ip = self.manager.get_ip_address_by_idx(source_ip_idx) src_port = self.manager.get_port_by_idx(source_port_idx) dst_ip = self.manager.get_ip_address_by_idx(dest_ip_idx) dst_port = self.manager.get_port_by_idx(dest_port_idx) return [ - 'network', - 'node', + "network", + "node", self.target_router_uuid, - 'acl', - 'add_rule', + "acl", + "add_rule", permission, protocol, src_ip, src_port, dst_ip, dst_port, - position + position, ] +class NetworkACLRemoveRuleAction(AbstractAction): + def __init__(self, manager: "ActionManager", target_router_uuid: str, max_acl_rules: int, **kwargs) -> None: + super().__init__(manager=manager) + self.shape: Dict[str, int] = {"position": max_acl_rules} + self.target_router_uuid: str = target_router_uuid + def form_request(self, position: int) -> List[str]: + return ["network", "node", self.target_router_uuid, "acl", "remove_rule", position] + + +class NetworkNICEnableAction(AbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: + super().__init__(manager=manager) + self.shape: Dict[str, int] = {"node_id": num_nodes, "nic_id": max_nics_per_node} + + def form_request(self, node_id: int, nic_id: int) -> List[str]: + return [ + "network", + "node", + self.manager.get_node_uuid_by_idx(node_idx=node_id), + "nic", + self.manager.get_nic_uuid_by_idx(node_idx=node_id, nic_idx=nic_id), + "enable", + ] + + +class NetworkNICDisableAction(AbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: + super().__init__(manager=manager) + self.shape: Dict[str, int] = {"node_id": num_nodes, "nic_id": max_nics_per_node} + + def form_request(self, node_id: int, nic_id: int) -> List[str]: + return [ + "network", + "node", + self.manager.get_node_uuid_by_idx(node_idx=node_id), + "nic", + self.manager.get_nic_uuid_by_idx(node_idx=node_id, nic_idx=nic_id), + "disable", + ] class ActionManager: # let the action manager handle the conversion of action spaces into a single discrete integer space. # - # when action space is created, it will take subspaces and generate an action map by enumerating all possibilities, # BUT, the action map can be provided in the config, in which case it will use that. @@ -278,69 +356,83 @@ class ActionManager: # 0: DONOTHING # 1: NODE, FILE, SCAN, NODEID=2, FOLDERID=1, FILEID=0 # 2: ...... - __act_class_identifiers:Dict[str,type] = { + __act_class_identifiers: Dict[str, type] = { "DONOTHING": DoNothingAction, "NODE_SERVICE_SCAN": NodeServiceScanAction, "NODE_SERVICE_STOP": NodeServiceStopAction, - # "NODE_SERVICE_START": NodeServiceStartAction, - # "NODE_SERVICE_PAUSE": NodeServicePauseAction, - # "NODE_SERVICE_RESUME": NodeServiceResumeAction, - # "NODE_SERVICE_RESTART": NodeServiceRestartAction, - # "NODE_SERVICE_DISABLE": NodeServiceDisableAction, - # "NODE_SERVICE_ENABLE": NodeServiceEnableAction, - # "NODE_FILE_SCAN": NodeFileScanAction, - # "NODE_FILE_CHECKHASH": NodeFileCheckhashAction, - # "NODE_FILE_DELETE": NodeFileDeleteAction, - # "NODE_FILE_REPAIR": NodeFileRepairAction, - # "NODE_FILE_RESTORE": NodeFileRestoreAction, + "NODE_SERVICE_START": NodeServiceStartAction, + "NODE_SERVICE_PAUSE": NodeServicePauseAction, + "NODE_SERVICE_RESUME": NodeServiceResumeAction, + "NODE_SERVICE_RESTART": NodeServiceRestartAction, + "NODE_SERVICE_DISABLE": NodeServiceDisableAction, + "NODE_SERVICE_ENABLE": NodeServiceEnableAction, + "NODE_FILE_SCAN": NodeFileScanAction, + "NODE_FILE_CHECKHASH": NodeFileCheckhashAction, + "NODE_FILE_DELETE": NodeFileDeleteAction, + "NODE_FILE_REPAIR": NodeFileRepairAction, + "NODE_FILE_RESTORE": NodeFileRestoreAction, "NODE_FOLDER_SCAN": NodeFolderScanAction, - # "NODE_FOLDER_CHECKHASH": NodeFolderCheckhashAction, - # "NODE_FOLDER_REPAIR": NodeFolderRepairAction, - # "NODE_FOLDER_RESTORE": NodeFolderRestoreAction, - # "NODE_OS_SCAN": NodeOSScanAction, - # "NODE_SHUTDOWN": NodeShutdownAction, - # "NODE_STARTUP": NodeStartupAction, - # "NODE_RESET": NodeResetAction, - # "NETWORK_ACL_ADDRULE": NetworkACLAddRuleAction, - # "NETWORK_ACL_REMOVERULE": NetworkACLRemoveRuleAction, - # "NETWORK_NIC_ENABLE": NetworkNICEnable, - # "NETWORK_NIC_DISABLE": NetworkNICDisable, + "NODE_FOLDER_CHECKHASH": NodeFolderCheckhashAction, + "NODE_FOLDER_REPAIR": NodeFolderRepairAction, + "NODE_FOLDER_RESTORE": NodeFolderRestoreAction, + "NODE_OS_SCAN": NodeOSScanAction, + "NODE_SHUTDOWN": NodeShutdownAction, + "NODE_STARTUP": NodeStartupAction, + "NODE_RESET": NodeResetAction, + "NETWORK_ACL_ADDRULE": NetworkACLAddRuleAction, + "NETWORK_ACL_REMOVERULE": NetworkACLRemoveRuleAction, + "NETWORK_NIC_ENABLE": NetworkNICEnableAction, + "NETWORK_NIC_DISABLE": NetworkNICDisableAction, } + def __init__( + self, + session: PrimaiteSession, # reference to session for looking up stuff + actions: List[str], # stores list of actions available to agent + node_uuids: List[str], # allows mapping index to node + max_folders_per_node: int = 2, # allows calculating shape + max_files_per_folder: int = 2, # allows calculating shape + max_services_per_node: int = 2, # allows calculating shape + max_nics_per_node: int = 8, # allows calculating shape + max_acl_rules: int = 10, # allows calculating shape + protocols: List[str] = ["TCP", "UDP", "ICMP"], # allow mapping index to protocol + ports: List[str] = ["HTTP", "DNS", "ARP", "FTP"], # allow mapping index to port + ip_address_list: Optional[List[str]] = None, # to allow us to map an index to an ip address. + act_map: Optional[Dict[int, Dict]] = None, # allows restricting set of possible actions + ) -> None: + self.session: PrimaiteSession = session + self.sim: Simulation = self.session.simulation + self.node_uuids: List[str] = node_uuids + self.protocols: List[str] = protocols + self.ports: List[str] = ports - def __init__(self, - sim:Simulation, - actions:List[str], - node_uuids:List[str], - max_folders_per_node:int = 2, - max_files_per_folder:int = 2, - max_services_per_node:int = 2, - max_nics_per_node:int=8, - max_acl_rules:int=10, - protocols:List[str]=['TCP','UDP','ICMP'], - ports:List[str]=['HTTP','DNS','ARP','FTP'], - ip_address_list:Optional[List[str]]=None, - act_map:Optional[Dict[int, Dict]]=None) -> None: - self.sim: Simulation = sim - self.node_uuids:List[str] = node_uuids - self.protocols:List[str] = protocols - self.ports:List[str] = ports + self.ip_address_list: List[str] + if ip_address_list is not None: + self.ip_address_list = ip_address_list + else: + self.ip_address_list = [] + for node_uuid in self.node_uuids: + node_obj = self.sim.network.nodes[node_uuid] + nics = node_obj.nics + for nic_uuid, nic_obj in nics.items(): + self.ip_address_list.append(nic_obj.ip_address) action_args = { "num_nodes": len(node_uuids), - "num_folders":max_folders_per_node, + "num_folders": max_folders_per_node, "num_files": max_files_per_folder, "num_services": max_services_per_node, "num_nics": max_nics_per_node, "num_acl_rules": max_acl_rules, "num_protocols": len(self.protocols), "num_ports": len(self.protocols), - "num_ips":} + "num_ips": len(self.ip_address_list), + } self.actions: Dict[str, AbstractAction] = {} for act_type in actions: self.actions[act_type] = self.__act_class_identifiers[act_type](self, **action_args) - self.action_map:Dict[int, Tuple[str, Dict]] = {} + self.action_map: Dict[int, Tuple[str, Dict]] = {} """ Action mapping that converts an integer to a specific action and parameter choice. @@ -350,21 +442,30 @@ class ActionManager: if act_map is None: self.action_map = self._enumerate_actions() else: - self.action_map = {i:(a['action'], a['options']) for i,a in act_map.items()} + self.action_map = {i: (a["action"], a["options"]) for i, a in act_map.items()} # make sure all numbers between 0 and N are represented as dict keys in action map assert all([i in self.action_map.keys() for i in range(len(self.action_map))]) - def _enumerate_actions(self,) -> Dict[int, Tuple[AbstractAction, Dict]]: - ... + def _enumerate_actions( + self, + ) -> Dict[int, Tuple[AbstractAction, Dict]]: + all_action_possibilities = [] + for action in self.actions.values(): + param_names = (list(action.shape.keys()),) + num_possibilities = list(action.shape.values()) + possibilities = [range(n) for n in num_possibilities] - def get_action(self, action: int) -> Tuple[str,Dict]: + itertools.product(action.shape.values()) + all_action_possibilities.append((action, {})) + + def get_action(self, action: int) -> Tuple[str, Dict]: """Produce action in CAOS format""" """the agent chooses an action (as an integer), this is converted into an action in CAOS format""" """The caos format is basically a action identifier, followed by parameters stored in a dictionary""" act_identifier, act_options = self.action_map[action] return act_identifier, act_options - def form_request(self, action_identifier:str, action_options:Dict): + def form_request(self, action_identifier: str, action_options: Dict): """Take action in CAOS format and use the execution definition to change it into PrimAITE request format""" act_obj = self.actions[action_identifier] return act_obj.form_request(**action_options) @@ -380,37 +481,57 @@ class ActionManager: node_uuid = self.get_node_uuid_by_idx(node_idx) node = self.sim.network.nodes[node_uuid] folder_uuids = list(node.file_system.folders.keys()) - return folder_uuids[folder_idx] if len(folder_uuids)>folder_idx else None + return folder_uuids[folder_idx] if len(folder_uuids) > folder_idx else None def get_file_uuid_by_idx(self, node_idx, folder_idx, file_idx) -> Optional[str]: node_uuid = self.get_node_uuid_by_idx(node_idx) node = self.sim.network.nodes[node_uuid] folder_uuids = list(node.file_system.folders.keys()) - if len(folder_uuids)<=folder_idx: + if len(folder_uuids) <= folder_idx: return None folder = node.file_system.folders[folder_uuids[folder_idx]] file_uuids = list(folder.files.keys()) - return file_uuids[file_idx] if len(file_uuids)>file_idx else None + return file_uuids[file_idx] if len(file_uuids) > file_idx else None def get_service_uuid_by_idx(self, node_idx, service_idx) -> Optional[str]: node_uuid = self.get_node_uuid_by_idx(node_idx) node = self.sim.network.nodes[node_uuid] service_uuids = list(node.services.keys()) - return service_uuids[service_idx] if len(service_uuids)>service_idx else None + return service_uuids[service_idx] if len(service_uuids) > service_idx else None - def get_internet_protocol_by_idx(self, protocol_idx:int) -> str: + def get_internet_protocol_by_idx(self, protocol_idx: int) -> str: + return self.protocols[protocol_idx] + def get_ip_address_by_idx(self, ip_idx: int) -> str: + return self.ip_address_list[ip_idx] - # protocol = self.manager.get_internet_protocol_by_idx(protocol_idx) - # src_ip = self.manager.get_ip_address_by_idx(source_ip_idx) - # src_port = self.manager.get_port_by_idx(source_port_idx) - # dst_ip = self.manager.get_ip_address_by_idx(dest_ip_idx) - # dst_port = self.manager.get_port_by_idx(dest_port_idx) + def get_port_by_idx(self, port_idx: int) -> str: + return self.ports[port_idx] + def get_nic_uuid_by_idx(self, node_idx: int, nic_idx: int) -> str: + node_uuid = self.get_node_uuid_by_idx(node_idx) + node_obj = self.sim.network.nodes[node_uuid] + nics = list(node_obj.nics.keys()) + if len(nics) <= nic_idx: + return None + return nics[nic_idx] + @classmethod + def from_config(cls, session: PrimaiteSession, cfg: Dict) -> "ActionManager": + obj = cls( + session=session, + actions=cfg["action_list"], + node_uuids=cfg["options"]["nodes"], + max_folders_per_node=cfg["options"]["max_folders_per_node"], + max_files_per_folder=cfg["options"]["max_files_per_folder"], + max_services_per_node=cfg["options"]["max_services_per_node"], + max_nics_per_node=cfg["options"]["max_nics_per_node"], + max_acl_rules=cfg["options"]["max_acl_rules"], + max_X=cfg["options"]["max_X"], + protocols=session.options.ports, + ports=session.options.protocols, + ip_address_list=None, + act_map=cfg["action_map"], + ) -class UC2RedActions(AbstractAction): - ... - -class UC2GreenActionSpace(ActionManager): - ... + return obj diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 0e682b60..528c0b1a 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -2,14 +2,16 @@ # That's because I want to point out that this is disctinct from 'agent' in the reinforcement learning sense of the word # If you disagree, make a comment in the PR review and we can discuss from abc import ABC, abstractmethod -from typing import Any, Dict, List, Optional, Union, TypeAlias +from typing import Any, Dict, List, Optional, TypeAlias, Union + import numpy as np from primaite.game.agent.actions import ActionManager from primaite.game.agent.observations import ObservationSpace from primaite.game.agent.rewards import RewardFunction -ObsType:TypeAlias = Union[Dict, np.ndarray] +ObsType: TypeAlias = Union[Dict, np.ndarray] + class AbstractAgent(ABC): """Base class for scripted and RL agents.""" @@ -28,31 +30,28 @@ class AbstractAgent(ABC): # by for example specifying target ip addresses, or converting a node ID into a uuid self.execution_definition = None - def get_obs_from_state(self, state:Dict) -> ObsType: + def convert_state_to_obs(self, state: Dict) -> ObsType: """ state : dict state directly from simulation.describe_state output : dict state according to CAOS. """ return self.observation_space.observe(state) - def get_reward_from_state(self, state:Dict) -> float: + def calculate_reward_from_state(self, state: Dict) -> float: return self.reward_function.calculate(state) @abstractmethod - def get_action(self, obs:ObsType, reward:float=None): - # in RL agent, this method will send CAOS observation to GATE RL agent, then receive a int 1-40, + def get_action(self, obs: ObsType, reward: float = None): + # in RL agent, this method will send CAOS observation to GATE RL agent, then receive a int 0-39, # then use a bespoke conversion to take 1-40 int back into CAOS action - return ('NODE', 'SERVICE', 'SCAN', '', '') + return ("NODE", "SERVICE", "SCAN", "", "") @abstractmethod def format_request(self, action) -> List[str]: # this will take something like APPLICATION.EXECUTE and add things like target_ip_address in simulator. # therefore the execution definition needs to be a mapping from CAOS into SIMULATOR """Format action into format expected by the simulator, and apply execution definition if applicable.""" - return ['network', 'nodes', '', 'file_system', 'folder', 'root', 'scan'] - - - + return ["network", "nodes", "", "file_system", "folder", "root", "scan"] class AbstractScriptedAgent(AbstractAgent): @@ -60,10 +59,11 @@ class AbstractScriptedAgent(AbstractAgent): ... + class RandomAgent(AbstractScriptedAgent): """Agent that ignores its observation and acts completely at random.""" - def get_action(self, obs:ObsType, reward:float=None): + def get_action(self, obs: ObsType, reward: float = None): return self.action_space.space.sample() diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index fcd8b4b3..0f88b322 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -5,23 +5,58 @@ # 4. Create connection with ARCD GATE # 5. idk -from primaite.simulator.sim_container import Simulation -from primaite.game.agent.interface import AbstractAgent +from ipaddress import IPv4Address +from typing import Dict, List + +from pydantic import BaseModel + +from primaite.game.agent.actions import ActionManager +from primaite.game.agent.interface import AbstractAgent +from primaite.game.agent.observations import ( + AclObservation, + FileObservation, + FolderObservation, + ICSObservation, + LinkObservation, + NicObservation, + NodeObservation, + NullObservation, + ServiceObservation, + UC2BlueObservation, + UC2RedObservation, +) +from primaite.simulator.network.hardware.base import Link, NIC, Node +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.sim_container import Simulation +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.services.database_service import DatabaseService +from primaite.simulator.system.services.dns_client import DNSClient +from primaite.simulator.system.services.dns_server import DNSServer +from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot +from primaite.simulator.system.services.service import Service + + +class PrimaiteSessionOptions(BaseModel): + ports: List[str] + protocols: List[str] -from typing import List class PrimaiteSession: def __init__(self): self.simulation: Simulation = Simulation() - self.agents:List[AbstractAgent] = [] - self.step_counter:int = 0 - self.episode_counter:int = 0 - + self.agents: List[AbstractAgent] = [] + self.step_counter: int = 0 + self.episode_counter: int = 0 + self.options: PrimaiteSessionOptions def step(self): # currently designed with assumption that all agents act once per step in order - for agent in self.agents: # 3. primaite session asks simulation to provide initial state # 4. primate session gives state to all agents @@ -29,10 +64,10 @@ class PrimaiteSession: sim_state = self.simulation.describe_state() # 6. each agent takes most recent state and converts it to CAOS observation - agent_obs = agent.get_obs_from_state(sim_state) + agent_obs = agent.convert_state_to_obs(sim_state) # 7. meanwhile each agent also takes state and calculates reward - agent_reward = agent.get_reward_from_state(sim_state) + agent_reward = agent.calculate_reward_from_state(sim_state) # 8. each agent takes observation and applies decision rule to observation to create CAOS # action(such as random, rulebased, or send to GATE) (therefore, converting CAOS action @@ -50,3 +85,237 @@ class PrimaiteSession: self.simulation.apply_timestep(self.step_counter) self.step_counter += 1 + @classmethod + def from_config(cls, cfg: dict) -> "PrimaiteSession": + sess = cls() + sim = sess.simulation + net = sim.network + + ref_map_nodes: Dict[str, Node] = {} + ref_map_services: Dict[str, Service] = {} + ref_map_links: Dict[str, Link] = {} + + nodes_cfg = cfg["simulation"]["network"]["nodes"] + links_cfg = cfg["simulation"]["network"]["links"] + for node_cfg in nodes_cfg: + node_ref = node_cfg["ref"] + n_type = node_cfg["type"] + if n_type == "computer": + new_node = Computer( + hostname=node_cfg["hostname"], + ip_address=node_cfg["ip_address"], + subnet_mask=node_cfg["subnet_mask"], + default_gateway=node_cfg["default_gateway"], + dns_server=node_cfg["dns_server"], + ) + elif n_type == "server": + new_node = Server( + hostname=node_cfg["hostname"], + ip_address=node_cfg["ip_address"], + subnet_mask=node_cfg["subnet_mask"], + default_gateway=node_cfg["default_gateway"], + dns_server=node_cfg.get("dns_server"), + ) + elif n_type == "switch": + new_node = Switch(hostname=node_cfg["hostname"], num_ports=node_cfg.get("num_ports")) + elif n_type == "router": + new_node = Router(hostname=node_cfg["hostname"], num_ports=node_cfg.get("num_ports")) + if "ports" in node_cfg: + for port_num, port_cfg in node_cfg["ports"].items(): + new_node.configure_port( + port=port_num, ip_address=port_cfg["ip_address"], subnet_mask=port_cfg["subnet_mask"] + ) + if "acl" in node_cfg: + for r_num, r_cfg in node_cfg["acl"].items(): + # excuse the uncommon walrus operator ` := `. It's just here as a shorthand, to avoid repeating + # this: 'r_cfg.get('src_port')' + # Port/IPProtocol. TODO Refactor + new_node.acl.add_rule( + action=ACLAction[r_cfg["action"]], + src_port=None if not (p := r_cfg.get("src_port")) else Port[p], + dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], + protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], + src_ip_address=r_cfg.get("ip_address"), + dst_ip_address=r_cfg.get("ip_address"), + position=r_num, + ) + else: + print("invalid node type") + if "services" in node_cfg: + for service_cfg in node_cfg["services"]: + service_ref = service_cfg["ref"] + service_type = service_cfg["type"] + service_types_mapping = { + "DNSClient": DNSClient, # key is equal to the 'name' attr of the service class itself. + "DNSServer": DNSServer, + "DatabaseClient": DatabaseClient, + "DatabaseService": DatabaseService, + # 'database_backup': , + "DataManipulationBot": DataManipulationBot, + # 'web_browser' + } + if service_type in service_types_mapping: + new_node.software_manager.install(service_types_mapping[service_type]) + new_service = new_node.software_manager.software[service_type] + ref_map_services[service_ref] = new_service + else: + print(f"service type not found {service_type}") + # service-dependent options + if service_type == "DatabaseClient": + if "options" in service_cfg: + opt = service_cfg["options"] + if "db_server_ip" in opt: + new_service.configure(server_ip_address=IPv4Address(opt["db_server_ip"])) + if service_type == "DNSServer": + if "options" in service_cfg: + opt = service_cfg["options"] + if "domain_mapping" in opt: + for domain, ip in opt["domain_mapping"].items(): + new_service.dns_register(domain, ip) + if "nics" in node_cfg: + for nic_num, nic_cfg in node_cfg["nics"].items(): + new_node.connect_nic(NIC(ip_address=nic_cfg["ip_address"], subnet_mask=nic_cfg["subnet_mask"])) + + net.add_node(new_node) + new_node.power_on() + ref_map_nodes[node_ref] = new_node.uuid + + # 2. create links between nodes + for link_cfg in links_cfg: + node_a = net.nodes[ref_map_nodes[link_cfg["endpoint_a_ref"]]] + node_b = net.nodes[ref_map_nodes[link_cfg["endpoint_b_ref"]]] + if isinstance(node_a, Switch): + endpoint_a = node_a.switch_ports[link_cfg["endpoint_a_port"]] + else: + endpoint_a = node_a.ethernet_port[link_cfg["endpoint_a_port"]] + if isinstance(node_b, Switch): + endpoint_b = node_b.switch_ports[link_cfg["endpoint_b_port"]] + else: + endpoint_b = node_b.ethernet_port[link_cfg["endpoint_b_port"]] + new_link = net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b) + ref_map_links[link_cfg["ref"]] = new_link.uuid + + # 3. create agents + game_cfg = cfg["game_config"] + ports_cfg = game_cfg["ports"] + protocols_cfg = game_cfg["protocols"] + agents_cfg = game_cfg["agents"] + + for agent_cfg in agents_cfg: + agent_ref = agent_cfg["ref"] + agent_type = agent_cfg["type"] + action_space_cfg = agent_cfg["action_space"] + observation_space_cfg = agent_cfg["observation_space"] + reward_function_cfg = agent_cfg["reward_function"] + + # CREATE OBSERVATION SPACE + if observation_space_cfg is None: + obs_space = NullObservation() + elif observation_space_cfg["type"] == "UC2BlueObservation": + node_obs_list = [] + link_obs_list = [] + + # node ip to index maps ip addresses to node id, as there are potentially multiple nics on a node, there are multiple ip addresses + node_ip_to_index = {} + for node_idx, node_cfg in enumerate(nodes_cfg): + n_ref = node_cfg["ref"] + n_obj = net.nodes[ref_map_nodes[n_ref]] + for nic_uuid, nic_obj in n_obj.nics.items(): + node_ip_to_index[nic_obj.ip_address] = node_idx + 2 + + for node_obs_cfg in observation_space_cfg["options"]["nodes"]: + node_ref = node_obs_cfg["node_ref"] + folder_obs_list = [] + service_obs_list = [] + if "services" in node_obs_cfg: + for service_obs_cfg in node_obs_cfg["services"]: + service_obs_list.append( + ServiceObservation( + where=[ + "network", + "nodes", + ref_map_nodes[node_ref], + "services", + ref_map_services[service_obs_cfg["service_ref"]], + ] + ) + ) + if "folders" in node_obs_cfg: + for folder_obs_cfg in node_obs_cfg["folders"]: + file_obs_list = [] + if "files" in folder_obs_cfg: + for file_obs_cfg in folder_obs_cfg["files"]: + file_obs_list.append( + FileObservation( + where=[ + "network", + "nodes", + ref_map_nodes[node_ref], + "folders", + folder_obs_cfg["folder_name"], + "files", + file_obs_cfg["file_name"], + ] + ) + ) + folder_obs_list.append( + FolderObservation( + where=[ + "network", + "nodes", + ref_map_nodes[node_ref], + "folders", + folder_obs_cfg["folder_name"], + ], + files=file_obs_list, + ) + ) + nic_obs_list = [] + for nic_uuid in net.nodes[ref_map_nodes[node_obs_cfg["node_ref"]]].nics.keys(): + nic_obs_list.append( + NicObservation(where=["network", "nodes", ref_map_nodes[node_ref], "NICs", nic_uuid]) + ) + node_obs_list.append( + NodeObservation( + where=["network", "nodes", ref_map_nodes[node_ref]], + services=service_obs_list, + folders=folder_obs_list, + nics=nic_obs_list, + logon_status=False, + ) + ) + for link_obs_cfg in observation_space_cfg["options"]["links"]: + link_ref = link_obs_cfg["link_ref"] + link_obs_list.append(LinkObservation(where=["network", "links", ref_map_links[link_ref]])) + + acl_obs = AclObservation( + node_ip_to_id=node_ip_to_index, + ports=game_cfg["ports"], + protocols=game_cfg["ports"], + where=["network", "nodes", observation_space_cfg["options"]["acl"]["router_node_ref"]], + ) + obs_space = UC2BlueObservation( + nodes=node_obs_list, links=link_obs_list, acl=acl_obs, ics=ICSObservation() + ) + elif observation_space_cfg["type"] == "UC2RedObservation": + obs_space = UC2RedObservation.from_config(observation_space_cfg["options"], sim=sim) + else: + print("observation space config not specified correctly.") + obs_space = NullObservation() + + # CREATE ACTION SPACE + action_space = ActionManager.from_config(sess, action_space_cfg) + + # CREATE REWARD FUNCTION + + # CREATE AGENT + if agent_type == "GreenWebBrowsingAgent": + ... + elif agent_type == "GATERLAgent": + ... + elif agent_type == "RedDatabaseCorruptingAgent": + ... + else: + print("agent type not found") + + return sess From 853bb9eecc30af1215b738c9096674048a0a69df Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Fri, 6 Oct 2023 12:10:57 +0100 Subject: [PATCH 210/980] #1943: unit tests + refactoring HTTP -> Http --- .../web_browser_and_web_server_service.rst | 4 +- src/primaite/simulator/network/networks.py | 2 +- .../simulator/network/protocols/http.py | 15 +++-- .../system/applications/web_browser.py | 14 ++-- .../{web_server_service.py => web_server.py} | 42 ++++++------ .../system/test_web_client_server.py | 8 +-- .../_system/_applications/__init__.py | 0 .../_system/_applications/test_web_browser.py | 39 +++++++++++ .../_system/_services/test_web_server.py | 64 +++++++++++++++++++ 9 files changed, 147 insertions(+), 41 deletions(-) rename src/primaite/simulator/system/services/web_server/{web_server_service.py => web_server.py} (78%) create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_applications/__init__.py create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py diff --git a/docs/source/simulation_components/system/web_browser_and_web_server_service.rst b/docs/source/simulation_components/system/web_browser_and_web_server_service.rst index a02ac621..d2bde80e 100644 --- a/docs/source/simulation_components/system/web_browser_and_web_server_service.rst +++ b/docs/source/simulation_components/system/web_browser_and_web_server_service.rst @@ -25,8 +25,8 @@ Usage Implementation ^^^^^^^^^^^^^^ -- HTTP request uses a ``HTTPRequestPacket`` object -- HTTP reaponse uses a ``HTTPResponsePacket`` object +- HTTP request uses a ``HttpRequestPacket`` object +- HTTP response uses a ``HttpResponsePacket`` object - Extends Service class for integration with ``SoftwareManager``. Web Browser (Web Client) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 23a7ab1a..e465e08a 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -12,7 +12,7 @@ from primaite.simulator.system.applications.database_client import DatabaseClien from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot -from primaite.simulator.system.services.web_server.web_server_service import WebServer +from primaite.simulator.system.services.web_server.web_server import WebServer def client_server_routed() -> Network: diff --git a/src/primaite/simulator/network/protocols/http.py b/src/primaite/simulator/network/protocols/http.py index 4be0ed88..2dba2614 100644 --- a/src/primaite/simulator/network/protocols/http.py +++ b/src/primaite/simulator/network/protocols/http.py @@ -3,7 +3,7 @@ from enum import Enum from primaite.simulator.network.protocols.packet import DataPacket -class HTTPRequestMethod(Enum): +class HttpRequestMethod(Enum): """Enum list of HTTP Request methods that can be handled by the simulation.""" GET = "GET" @@ -25,7 +25,7 @@ class HTTPRequestMethod(Enum): """Apply partial modifications to a resource.""" -class HTTPStatusCode(Enum): +class HttpStatusCode(Enum): """List of available HTTP Statuses.""" OK = 200 @@ -37,6 +37,9 @@ class HTTPStatusCode(Enum): UNAUTHORIZED = 401 """Auth required.""" + NOT_FOUND = 404 + """Item not found in server.""" + METHOD_NOT_ALLOWED = 405 """Method is not supported by server.""" @@ -44,18 +47,18 @@ class HTTPStatusCode(Enum): """Error on the server side.""" -class HTTPRequestPacket(DataPacket): +class HttpRequestPacket(DataPacket): """Class that represents an HTTP Request Packet.""" - request_method: HTTPRequestMethod + request_method: HttpRequestMethod """The HTTP Request method.""" request_url: str """URL of request.""" -class HTTPResponsePacket(DataPacket): +class HttpResponsePacket(DataPacket): """Class that reprensents an HTTP Response Packet.""" - status_code: HTTPStatusCode = None + status_code: HttpStatusCode = None """Status code of the HTTP response.""" diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 69de333e..4f6b81c1 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -2,7 +2,7 @@ from ipaddress import IPv4Address from typing import Dict, Optional from urllib.parse import urlparse -from primaite.simulator.network.protocols.http import HTTPRequestMethod, HTTPRequestPacket, HTTPResponsePacket +from primaite.simulator.network.protocols.http import HttpRequestMethod, HttpRequestPacket, HttpResponsePacket from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application @@ -19,7 +19,7 @@ class WebBrowser(Application): domain_name_ip_address: Optional[IPv4Address] = None "The IP address of the domain name for the webpage." - latest_response: HTTPResponsePacket = None + latest_response: HttpResponsePacket = None """Keeps track of the latest HTTP response.""" def __init__(self, **kwargs): @@ -87,7 +87,7 @@ class WebBrowser(Application): return False # create HTTPRequest payload - payload = HTTPRequestPacket(request_method=HTTPRequestMethod.GET, request_url=url) + payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url=url) # send request return self.send( @@ -98,7 +98,7 @@ class WebBrowser(Application): def send( self, - payload: HTTPRequestPacket, + payload: HttpRequestPacket, dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = Port.HTTP, session_id: Optional[str] = None, @@ -120,7 +120,7 @@ class WebBrowser(Application): payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, **kwargs ) - def receive(self, payload: HTTPResponsePacket, session_id: Optional[str] = None, **kwargs) -> bool: + def receive(self, payload: HttpResponsePacket, session_id: Optional[str] = None, **kwargs) -> bool: """ Receives a payload from the SessionManager. @@ -128,8 +128,8 @@ class WebBrowser(Application): :param session_id: The Session ID the payload is to originate from. Optional. :return: True if successful, False otherwise. """ - if not isinstance(payload, HTTPResponsePacket): - self.sys_log.error(f"{self.name} received a packet that is not an HTTPResponsePacket") + if not isinstance(payload, HttpResponsePacket): + self.sys_log.error(f"{self.name} received a packet that is not an HttpResponsePacket") return False self.sys_log.info(f"{self.name}: Received HTTP {payload.status_code.value}") self.latest_response = payload diff --git a/src/primaite/simulator/system/services/web_server/web_server_service.py b/src/primaite/simulator/system/services/web_server/web_server.py similarity index 78% rename from src/primaite/simulator/system/services/web_server/web_server_service.py rename to src/primaite/simulator/system/services/web_server/web_server.py index 59686388..4566f3b3 100644 --- a/src/primaite/simulator/system/services/web_server/web_server_service.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -3,10 +3,10 @@ from typing import Any, Optional from urllib.parse import urlparse from primaite.simulator.network.protocols.http import ( - HTTPRequestMethod, - HTTPRequestPacket, - HTTPResponsePacket, - HTTPStatusCode, + HttpRequestMethod, + HttpRequestPacket, + HttpResponsePacket, + HttpStatusCode, ) from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -37,52 +37,52 @@ class WebServer(Service): # index HTML main file self.file_system.create_file(file_name="index.html", folder_name="primaite", real=True) - def _process_http_request(self, payload: HTTPRequestPacket, session_id: Optional[str] = None) -> bool: + def _process_http_request(self, payload: HttpRequestPacket, session_id: Optional[str] = None) -> bool: """ - Parse the HTTPRequestPacket. + Parse the HttpRequestPacket. - :param: payload: Payload containing th HTTPRequestPacket - :type: payload: HTTPRequestPacket + :param: payload: Payload containing th HttpRequestPacket + :type: payload: HttpRequestPacket :param: session_id: Session id of the http request :type: session_id: Optional[str] """ - response = HTTPResponsePacket() + response = HttpResponsePacket() self.sys_log.info(f"{self.name}: Received HTTP {payload.request_method.name} {payload.request_url}") # check the type of HTTP request - if payload.request_method == HTTPRequestMethod.GET: + if payload.request_method == HttpRequestMethod.GET: response = self._handle_get_request(payload=payload) - elif payload.request_method == HTTPRequestMethod.POST: + elif payload.request_method == HttpRequestMethod.POST: pass else: # send a method not allowed response - response.status_code = HTTPStatusCode.METHOD_NOT_ALLOWED + response.status_code = HttpStatusCode.METHOD_NOT_ALLOWED # send response to web client self.send(payload=response, session_id=session_id) # return true if response is OK - return response.status_code == HTTPStatusCode.OK + return response.status_code == HttpStatusCode.OK - def _handle_get_request(self, payload: HTTPRequestPacket) -> HTTPResponsePacket: + def _handle_get_request(self, payload: HttpRequestPacket) -> HttpResponsePacket: """ Handle a GET HTTP request. :param: payload: HTTP request payload - :type: payload: HTTPRequestPacket + :type: payload: HttpRequestPacket """ - response = HTTPResponsePacket(status_code=HTTPStatusCode.BAD_REQUEST, payload=payload) + response = HttpResponsePacket(status_code=HttpStatusCode.NOT_FOUND, payload=payload) try: parsed_url = urlparse(payload.request_url) path = parsed_url.path.strip("/") if len(path) < 1: # query succeeded - response.status_code = HTTPStatusCode.OK + response.status_code = HttpStatusCode.OK if path.startswith("users"): # get data from DatabaseServer @@ -90,17 +90,17 @@ class WebServer(Service): # get all users if db_client.query("SELECT * FROM user;"): # query succeeded - response.status_code = HTTPStatusCode.OK + response.status_code = HttpStatusCode.OK return response except Exception: # something went wrong on the server - response.status_code = HTTPStatusCode.INTERNAL_SERVER_ERROR + response.status_code = HttpStatusCode.INTERNAL_SERVER_ERROR return response def send( self, - payload: HTTPResponsePacket, + payload: HttpResponsePacket, session_id: Optional[str] = None, dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = None, @@ -138,7 +138,7 @@ class WebServer(Service): :param: session_id: The id of the session. Optional. """ # check if the payload is an HTTPPacket - if not isinstance(payload, HTTPRequestPacket): + if not isinstance(payload, HttpRequestPacket): self.sys_log.error("Payload is not an HTTPPacket") return False diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py index 8b6f4072..f4546cbf 100644 --- a/tests/integration_tests/system/test_web_client_server.py +++ b/tests/integration_tests/system/test_web_client_server.py @@ -1,6 +1,6 @@ from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.protocols.http import HTTPStatusCode +from primaite.simulator.network.protocols.http import HttpStatusCode from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.service import ServiceOperatingState @@ -17,7 +17,7 @@ def test_web_page_home_page(uc2_network): # latest reponse should have status code 200 assert web_client.latest_response is not None - assert web_client.latest_response.status_code == HTTPStatusCode.OK + assert web_client.latest_response.status_code == HttpStatusCode.OK def test_web_page_get_users_page_request_with_domain_name(uc2_network): @@ -31,7 +31,7 @@ def test_web_page_get_users_page_request_with_domain_name(uc2_network): # latest reponse should have status code 200 assert web_client.latest_response is not None - assert web_client.latest_response.status_code == HTTPStatusCode.OK + assert web_client.latest_response.status_code == HttpStatusCode.OK def test_web_page_get_users_page_request_with_ip_address(uc2_network): @@ -49,4 +49,4 @@ def test_web_page_get_users_page_request_with_ip_address(uc2_network): # latest reponse should have status code 200 assert web_client.latest_response is not None - assert web_client.latest_response.status_code == HTTPStatusCode.OK + assert web_client.latest_response.status_code == HttpStatusCode.OK diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/__init__.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py new file mode 100644 index 00000000..b2724369 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py @@ -0,0 +1,39 @@ +import pytest + +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.protocols.http import HttpResponsePacket, HttpStatusCode +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.web_browser import WebBrowser + + +@pytest.fixture(scope="function") +def web_client() -> Computer: + node = Computer( + hostname="web_client", ip_address="192.168.1.11", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + ) + return node + + +def test_create_web_client(web_client): + assert web_client is not None + web_browser: WebBrowser = web_client.software_manager.software["WebBrowser"] + assert web_browser.name is "WebBrowser" + assert web_browser.port is Port.HTTP + assert web_browser.protocol is IPProtocol.TCP + + +def test_receive_invalid_payload(web_client): + web_browser: WebBrowser = web_client.software_manager.software["WebBrowser"] + + assert web_browser.receive(payload={}) is False + + +def test_receive_payload(web_client): + payload = HttpResponsePacket(status_code=HttpStatusCode.OK) + web_browser: WebBrowser = web_client.software_manager.software["WebBrowser"] + assert web_browser.latest_response is None + + web_browser.receive(payload=payload) + + assert web_browser.latest_response is not None diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py new file mode 100644 index 00000000..e6f0b9d9 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py @@ -0,0 +1,64 @@ +import pytest + +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.protocols.http import ( + HttpRequestMethod, + HttpRequestPacket, + HttpResponsePacket, + HttpStatusCode, +) +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.web_server.web_server import WebServer + + +@pytest.fixture(scope="function") +def web_server() -> Server: + node = Server( + hostname="web_server", ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + ) + node.software_manager.install(software_class=WebServer) + node.software_manager.software["WebServer"].start() + return node + + +def test_create_web_server(web_server): + assert web_server is not None + web_server_service: WebServer = web_server.software_manager.software["WebServer"] + assert web_server_service.name is "WebServer" + assert web_server_service.port is Port.HTTP + assert web_server_service.protocol is IPProtocol.TCP + + +def test_handling_get_request_not_found_path(web_server): + payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url="http://domain.com/fake-path") + + web_server_service: WebServer = web_server.software_manager.software["WebServer"] + + response: HttpResponsePacket = web_server_service._handle_get_request(payload=payload) + assert response.status_code == HttpStatusCode.NOT_FOUND + + +def test_handling_get_request_home_page(web_server): + payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url="http://domain.com/") + + web_server_service: WebServer = web_server.software_manager.software["WebServer"] + + response: HttpResponsePacket = web_server_service._handle_get_request(payload=payload) + assert response.status_code == HttpStatusCode.OK + + +def test_process_http_request_get(web_server): + payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url="http://domain.com/") + + web_server_service: WebServer = web_server.software_manager.software["WebServer"] + + assert web_server_service._process_http_request(payload=payload) is True + + +def test_process_http_request_method_not_allowed(web_server): + payload = HttpRequestPacket(request_method=HttpRequestMethod.DELETE, request_url="http://domain.com/") + + web_server_service: WebServer = web_server.software_manager.software["WebServer"] + + assert web_server_service._process_http_request(payload=payload) is False From 3dea9743c355d61b1fd7b7461abe7a79dc77f822 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 6 Oct 2023 20:32:52 +0100 Subject: [PATCH 211/980] Get primaite session step working --- example_config.yaml | 455 +++++++++++++----------- sandbox.ipynb | 195 ++++++---- src/primaite/game/agent/actions.py | 158 +++++--- src/primaite/game/agent/interface.py | 16 +- src/primaite/game/agent/rewards.py | 17 + src/primaite/game/session.py | 34 +- src/primaite/simulator/sim_container.py | 1 + 7 files changed, 520 insertions(+), 356 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index b47355c3..9c75c92e 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -19,20 +19,28 @@ game_config: type: GreenWebBrowsingAgent observation_space: null action_space: - actions: - - type: DONOTHING - nodes: - - node_ref: client_2 - actions: - - type: LOGON - - type: LOGOFF - applications: - # - application_ref: client_2_web_browser - # actions: - # - type: EXECUTE - # execution_definition: - # target_address: arcd.com - reward_function: null + action_list: + - type: DONOTHING + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com + + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 2 + max_files_per_folder: 2 + max_services_per_node: 2 + max_nics_per_node: 8 + max_acl_rules: 10 + + reward_function: + reward_components: + - type: DUMMY + agent_settings: start_step: 5 frequency: 4 @@ -41,6 +49,7 @@ game_config: - ref: client_1_data_manipulation_red_bot team: RED type: RedDatabaseCorruptingAgent + observation_space: type: UC2RedObservation options: @@ -55,27 +64,56 @@ game_config: - operating_status - health_status folders: {} + action_space: - actions: - - type: DO_NOTHING - network: + action_list: + - type: DONOTHING + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # server_ip: 192.168.1.14 + # payload: "DROP TABLE IF EXISTS user;" + # success_rate: 80% + - type: NODE_FILE_DELETE + - type: NODE_FILE_CORRUPT + # - type: NODE_FOLDER_DELETE + # - type: NODE_FOLDER_CORRUPT + - type: NODE_OS_SCAN + # - type: NODE_LOGON + # - type: NODE_LOGOFF + options: nodes: - node_ref: client_1 - actions: - - type: SCAN - - type: LOGON - - type: LOGOFF - services: - - service_ref: data_manipulation_bot - actions: - - type: COMPROMISE - execution_definition: - server_ip: 192.168.1.14 - payload: "DROP TABLE IF EXISTS user;" - success_rate: 80% - folders: - files: {} - reward_function: null + max_folders_per_node: 2 + max_files_per_folder: 2 + max_services_per_node: 2 + # max_nics_per_node: 8 + # max_acl_rules: 10 + + # actions: + # - type: DO_NOTHING + # network: + # nodes: + # - node_ref: client_1 + # actions: + # - type: SCAN + # - type: LOGON + # - type: LOGOFF + # services: + # - service_ref: data_manipulation_bot + # actions: + # - type: COMPROMISE + # execution_definition: + # server_ip: 192.168.1.14 + # payload: "DROP TABLE IF EXISTS user;" + # success_rate: 80% + # folders: + # files: {} + + reward_function: + reward_components: + - type: DUMMY + agent_settings: # options specific to this particular agent type, basically args of __init__(self) start_step: 25 frequency: 20 @@ -85,8 +123,9 @@ game_config: - ref: defender - team: blue + team: BLUE type: GATERLAgent + observation_space: type: UC2BlueObservation options: @@ -128,7 +167,6 @@ game_config: router_node_ref: router_1 ics: null - action_space: action_list: - type: DONOTHING @@ -164,227 +202,227 @@ game_config: action_map: 0: - - action: DONOTHING + action: DONOTHING options: {} # scan webapp service 1: - - action: NODE_SERVICE_SCAN + action: NODE_SERVICE_SCAN options: - node_id: 2 - service_id: 1 # stop webapp service 2: - - action: NODE_SERVICE_STOP + action: NODE_SERVICE_STOP options: - node_id: 2 - service_id: 1 # start webapp service 3: - - action: "NODE_SERVICE_START" - options: - - node_id: 2 - - service_id: 1 + action: "NODE_SERVICE_START" + options: + - node_id: 2 + - service_id: 1 4: - - action: "NODE_SERVICE_PAUSE" - options: - - node_id: 2 - - service_id: 1 + action: "NODE_SERVICE_PAUSE" + options: + - node_id: 2 + - service_id: 1 5: - - action: "NODE_SERVICE_RESUME" - options: - - node_id: 2 - - service_id: 1 + action: "NODE_SERVICE_RESUME" + options: + - node_id: 2 + - service_id: 1 6: - - action: "NODE_SERVICE_RESTART" - options: - - node_id: 2 - - service_id: 1 + action: "NODE_SERVICE_RESTART" + options: + - node_id: 2 + - service_id: 1 7: - - action: "NODE_SERVICE_DISABLE" - options: - - node_id: 2 - - service_id: 1 + action: "NODE_SERVICE_DISABLE" + options: + - node_id: 2 + - service_id: 1 8: - - action: "NODE_SERVICE_ENABLE" - options: - - node_id: 2 - - service_id: 1 + action: "NODE_SERVICE_ENABLE" + options: + - node_id: 2 + - service_id: 1 9: - - action: "NODE_FILE_SCAN" - options: - - node_id: 3 - - folder_id: 1 - - file_id: 1 + action: "NODE_FILE_SCAN" + options: + - node_id: 3 + - folder_id: 1 + - file_id: 1 10: - - action: "NODE_FILE_CHECKHASH" - options: - - node_id: 3 - - folder_id: 1 - - file_id: 1 + action: "NODE_FILE_CHECKHASH" + options: + - node_id: 3 + - folder_id: 1 + - file_id: 1 11: - - action: "NODE_FILE_DELETE" - options: - - node_id: 3 - - folder_id: 1 - - file_id: 1 + action: "NODE_FILE_DELETE" + options: + - node_id: 3 + - folder_id: 1 + - file_id: 1 12: - - action: "NODE_FILE_REPAIR" - options: - - node_id: 3 - - folder_id: 1 - - file_id: 1 + action: "NODE_FILE_REPAIR" + options: + - node_id: 3 + - folder_id: 1 + - file_id: 1 13: - - action: "NODE_FILE_RESTORE" - options: - - node_id: 3 - - folder_id: 1 - - file_id: 1 + action: "NODE_FILE_RESTORE" + options: + - node_id: 3 + - folder_id: 1 + - file_id: 1 14: - - action: "NODE_FOLDER_SCAN" - options: - - node_id: 3 - - folder_id: 1 + action: "NODE_FOLDER_SCAN" + options: + - node_id: 3 + - folder_id: 1 15: - - action: "NODE_FOLDER_CHECKHASH" - options: - - node_id: 3 - - folder_id: 1 + action: "NODE_FOLDER_CHECKHASH" + options: + - node_id: 3 + - folder_id: 1 16: - - action: "NODE_FOLDER_REPAIR" - options: - - node_id: 3 - - folder_id: 1 + action: "NODE_FOLDER_REPAIR" + options: + - node_id: 3 + - folder_id: 1 17: - - action: "NODE_FOLDER_RESTORE" - options: - - node_id: 3 - - folder_id: 1 + action: "NODE_FOLDER_RESTORE" + options: + - node_id: 3 + - folder_id: 1 18: - - action: "NODE_OS_SCAN" - options: - - node_id: 3 + action: "NODE_OS_SCAN" + options: + - node_id: 3 19: - - action: "NODE_SHUTDOWN" - options: - - node_id: 6 + action: "NODE_SHUTDOWN" + options: + - node_id: 6 20: - - action: "NODE_STARTUP" - options: - - node_id: 6 + action: "NODE_STARTUP" + options: + - node_id: 6 21: - - action: "NODE_RESET" - options: - - node_id: 6 + action: "NODE_RESET" + options: + - node_id: 6 22: - - action: "NETWORK_ACL_ADDRULE" - options: - - position: 6 - - permission: 2 - - source_node_id: ... - - dest_node_id: ... - - source_port_id: ... - - dest_port_id: ... - - protocol_id: ... + action: "NETWORK_ACL_ADDRULE" + options: + - position: 6 + - permission: 2 + - source_node_id: ... + - dest_node_id: ... + - source_port_id: ... + - dest_port_id: ... + - protocol_id: ... 23: - - action: "NETWORK_ACL_ADDRULE" - options: - - position: 5 - - permission: 2 - - source_node_id: ... - - dest_node_id: ... - - source_port_id: ... - - dest_port_id: ... - - protocol_id: ... + action: "NETWORK_ACL_ADDRULE" + options: + - position: 5 + - permission: 2 + - source_node_id: ... + - dest_node_id: ... + - source_port_id: ... + - dest_port_id: ... + - protocol_id: ... 24: - - action: "NETWORK_ACL_ADDRULE" - options: - - position: 4 - - permission: 2 - - source_node_id: ... - - dest_node_id: ... - - source_port_id: ... - - dest_port_id: ... - - protocol_id: ... + action: "NETWORK_ACL_ADDRULE" + options: + - position: 4 + - permission: 2 + - source_node_id: ... + - dest_node_id: ... + - source_port_id: ... + - dest_port_id: ... + - protocol_id: ... 25: - - action: "NETWORK_ACL_ADDRULE" - options: - - position: 3 - - permission: 2 - - source_node_id: ... - - dest_node_id: ... - - source_port_id: ... - - dest_port_id: ... - - protocol_id: ... + action: "NETWORK_ACL_ADDRULE" + options: + - position: 3 + - permission: 2 + - source_node_id: ... + - dest_node_id: ... + - source_port_id: ... + - dest_port_id: ... + - protocol_id: ... 26: - - action: "NETWORK_ACL_ADDRULE" - options: - - position: 2 - - permission: 2 - - source_node_id: ... - - dest_node_id: ... - - source_port_id: ... - - dest_port_id: ... - - protocol_id: ... + action: "NETWORK_ACL_ADDRULE" + options: + - position: 2 + - permission: 2 + - source_node_id: ... + - dest_node_id: ... + - source_port_id: ... + - dest_port_id: ... + - protocol_id: ... 27: - - action: "NETWORK_ACL_ADDRULE" - options: - - position: 1 - - permission: 2 - - source_node_id: ... - - dest_node_id: ... - - source_port_id: ... - - dest_port_id: ... - - protocol_id: ... + action: "NETWORK_ACL_ADDRULE" + options: + - position: 1 + - permission: 2 + - source_node_id: ... + - dest_node_id: ... + - source_port_id: ... + - dest_port_id: ... + - protocol_id: ... 28: - - action: "NETWORK_ACL_REMOVERULE" - options: - - position: 0 + action: "NETWORK_ACL_REMOVERULE" + options: + - position: 0 29: - - action: "NETWORK_ACL_REMOVERULE" - options: - - position: 1 + action: "NETWORK_ACL_REMOVERULE" + options: + - position: 1 30: - - action: "NETWORK_ACL_REMOVERULE" - options: - - position: 2 + action: "NETWORK_ACL_REMOVERULE" + options: + - position: 2 31: - - action: "NETWORK_ACL_REMOVERULE" - options: - - position: 3 + action: "NETWORK_ACL_REMOVERULE" + options: + - position: 3 32: - - action: "NETWORK_ACL_REMOVERULE" - options: - - position: 4 + action: "NETWORK_ACL_REMOVERULE" + options: + - position: 4 33: - - action: "NETWORK_ACL_REMOVERULE" - options: - - position: 5 + action: "NETWORK_ACL_REMOVERULE" + options: + - position: 5 34: - - action: "NETWORK_ACL_REMOVERULE" - options: - - position: 6 + action: "NETWORK_ACL_REMOVERULE" + options: + - position: 6 35: - - action: "NETWORK_ACL_REMOVERULE" - options: - - position: 7 + action: "NETWORK_ACL_REMOVERULE" + options: + - position: 7 36: - - action: "NETWORK_ACL_REMOVERULE" - options: - - position: 8 + action: "NETWORK_ACL_REMOVERULE" + options: + - position: 8 37: - - action: "NETWORK_ACL_REMOVERULE" - options: - - position: 9 + action: "NETWORK_ACL_REMOVERULE" + options: + - position: 9 38: - - action: "NETWORK_NIC_DISABLE" - options: - - node_id: 6 - - nic_index: 1 + action: "NETWORK_NIC_DISABLE" + options: + - node_id: 6 + - nic_index: 1 39: - - action: "NETWORK_NIC_ENABLE" - options: - - node_id: 6 - - nic_index: 1 + action: "NETWORK_NIC_ENABLE" + options: + - node_id: 6 + - nic_index: 1 options: nodes: @@ -404,9 +442,10 @@ game_config: max_nics_per_node: 8 max_acl_rules: 10 - reward_function: - # ... + reward_components: + - type: DUMMY + agent_settings: # ... diff --git a/sandbox.ipynb b/sandbox.ipynb index 3ff72170..51849298 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -2,18 +2,9 @@ "cells": [ { "cell_type": "code", - "execution_count": 13, + "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The autoreload extension is already loaded. To reload it, use:\n", - " %reload_ext autoreload\n" - ] - } - ], + "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" @@ -21,28 +12,102 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.game.session import PrimaiteSession\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "import itertools" + ] + }, + { + "cell_type": "code", + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from primaite.game.session import PrimaiteSession\n", "from primaite.simulator.sim_container import Simulation\n", "from primaite.game.agent.interface import AbstractAgent\n", - "from primaite.simulator.network.networks import arcd_uc2_network\n" + "from primaite.simulator.network.networks import arcd_uc2_network\n", + "import yaml\n" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - "sess = PrimaiteSession()" + "with open('example_config.yaml', 'r') as file:\n", + " cfg = yaml.safe_load(file)" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-10-06 19:05:49,548: Added node 387fba92-e5ff-4ead-b525-1872091935ad to Network 35300ca7-ca53-41a4-b617-1f64c7645e52\n", + "2023-10-06 19:05:49,557: Added node a808ea99-5c8b-42c4-8e38-bf406ceb1f87 to Network 35300ca7-ca53-41a4-b617-1f64c7645e52\n", + "2023-10-06 19:05:49,562: Added node 922c77bb-096a-4236-9e1e-a44da15c1718 to Network 35300ca7-ca53-41a4-b617-1f64c7645e52\n", + "2023-10-06 19:05:49,579: Added node f11cc63b-537c-4813-be09-a1f5597dfe14 to Network 35300ca7-ca53-41a4-b617-1f64c7645e52\n", + "2023-10-06 19:05:49,591: Added node a866b811-efa2-41cc-adc0-a4752f40a0b8 to Network 35300ca7-ca53-41a4-b617-1f64c7645e52\n", + "2023-10-06 19:05:49,607: Added node a01c22b8-cdfb-4105-a8d0-c67c53b3d08b to Network 35300ca7-ca53-41a4-b617-1f64c7645e52\n", + "2023-10-06 19:05:49,635: Added node 217074fc-021e-4b19-94db-3bc2d5f15d49 to Network 35300ca7-ca53-41a4-b617-1f64c7645e52\n", + "2023-10-06 19:05:49,641: Added node 28db0167-0621-4fdb-9e2b-65e25a91a101 to Network 35300ca7-ca53-41a4-b617-1f64c7645e52\n", + "2023-10-06 19:05:49,648: Added node e754e649-7ba3-4f80-8621-906255cf8749 to Network 35300ca7-ca53-41a4-b617-1f64c7645e52\n", + "2023-10-06 19:05:49,657: Added node 65508b30-defa-46c8-af44-9f0c4c0ae59d to Network 35300ca7-ca53-41a4-b617-1f64c7645e52\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "service type not found DatabaseBackup\n", + "service type not found WebBrowser\n" + ] + } + ], + "source": [ + "sess = PrimaiteSession.from_config(cfg)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sess.agents" + ] + }, + { + "cell_type": "code", + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -51,7 +116,16 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "sess.step()" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -74,27 +148,9 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-10-02 15:10:20,422: Added node 6abb7664-4d17-45ff-a3c7-dbcccffcfd6d to Network 045a3114-4aac-4687-a10e-432cfd138325\n", - "2023-10-02 15:10:20,424: Added node 3edbc521-3c80-47e3-8017-dbc38fb00a73 to Network 045a3114-4aac-4687-a10e-432cfd138325\n", - "2023-10-02 15:10:20,428: Added node 94457fb9-04a1-4dc1-9ff7-b64df0da7424 to Network 045a3114-4aac-4687-a10e-432cfd138325\n", - "2023-10-02 15:10:20,432: Added node 0d311d72-139c-41bf-aef7-fa9b01b124d7 to Network 045a3114-4aac-4687-a10e-432cfd138325\n", - "2023-10-02 15:10:20,439: Added node 6161e785-f377-48de-aa4f-20d3646da635 to Network 045a3114-4aac-4687-a10e-432cfd138325\n", - "2023-10-02 15:10:20,444: Added node 55a9e9f8-ee3a-4c28-9b6d-c0c0d78a3f6a to Network 045a3114-4aac-4687-a10e-432cfd138325\n", - "2023-10-02 15:10:20,447: Added node 2f04ca45-3439-489a-81f7-41cca5ae8adc to Network 045a3114-4aac-4687-a10e-432cfd138325\n", - "2023-10-02 15:10:20,531: Added node 98660c30-8e48-4b96-967a-d62ca71b4d6d to Network 045a3114-4aac-4687-a10e-432cfd138325\n", - "2023-10-02 15:10:20,545: Added node 1a184184-b204-40de-986a-4d7459036dbe to Network 045a3114-4aac-4687-a10e-432cfd138325\n", - "2023-10-02 15:10:20,551: Added node 17b92b9a-6805-4677-85f7-c0c0521a6e25 to Network 045a3114-4aac-4687-a10e-432cfd138325\n", - "2023-10-02 15:10:20,555::ERROR::primaite.simulator.network.hardware.base::175::NIC da:f3:1b:87:24:20/192.168.10.110 cannot be enabled as it is not connected to a Link\n" - ] - } - ], + "outputs": [], "source": [ "router_1 = Router(hostname=\"router_1\", num_ports=5)\n", "router_1.power_on()\n", @@ -261,7 +317,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -270,7 +326,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -279,7 +335,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -305,7 +361,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -315,7 +371,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -324,26 +380,9 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['network',\n", - " 'node',\n", - " '6161e785-f377-48de-aa4f-20d3646da635',\n", - " 'file_system',\n", - " 'folder',\n", - " '5aefe92b-923c-4684-b3bf-e78dd18d4771',\n", - " 'scan']" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_trial_act" ] @@ -455,8 +494,8 @@ " session = cls()\n", " with open(cfg_path, 'r') as file:\n", " conf = yaml.safe_load(file)\n", - " \n", - " #1. create nodes \n", + "\n", + " #1. create nodes\n", " sim = Simulation()\n", " net = sim.network\n", " nodes_cfg = conf['simulation']['network']['nodes']\n", @@ -465,15 +504,15 @@ " node_ref = node_cfg['ref']\n", " n_type = node_cfg['type']\n", " if n_type == 'computer':\n", - " new_node = Computer(hostname = node_cfg['hostname'], \n", - " ip_address = node_cfg['ip_address'], \n", - " subnet_mask = node_cfg['subnet_mask'], \n", + " new_node = Computer(hostname = node_cfg['hostname'],\n", + " ip_address = node_cfg['ip_address'],\n", + " subnet_mask = node_cfg['subnet_mask'],\n", " default_gateway = node_cfg['default_gateway'],\n", " dns_server = node_cfg['dns_server'])\n", " elif n_type == 'server':\n", - " new_node = Server(hostname = node_cfg['hostname'], \n", - " ip_address = node_cfg['ip_address'], \n", - " subnet_mask = node_cfg['subnet_mask'], \n", + " new_node = Server(hostname = node_cfg['hostname'],\n", + " ip_address = node_cfg['ip_address'],\n", + " subnet_mask = node_cfg['subnet_mask'],\n", " default_gateway = node_cfg['default_gateway'],\n", " dns_server = node_cfg.get('dns_server'))\n", " elif n_type == 'switch':\n", @@ -484,12 +523,12 @@ " num_ports = node_cfg.get('num_ports'))\n", " if 'ports' in node_cfg:\n", " for port_num, port_cfg in node_cfg['ports'].items():\n", - " new_node.configure_port(port=port_num, \n", + " new_node.configure_port(port=port_num,\n", " ip_address=port_cfg['ip_address'],\n", " subnet_mask=port_cfg['subnet_mask'])\n", " if 'acl' in node_cfg:\n", " for r_num, r_cfg in node_cfg['acl'].items():\n", - " # excuse the uncommon walrus operator ` := `. It's just here as a shorthand, to avoid repeating \n", + " # excuse the uncommon walrus operator ` := `. It's just here as a shorthand, to avoid repeating\n", " # this: 'r_cfg.get('src_port')'\n", " # Port/IPProtocol. TODO Refactor\n", " new_node.acl.add_rule(\n", @@ -570,15 +609,15 @@ " action_space_cfg = agent_cfg['action_space']\n", " observation_space_cfg = agent_cfg['observation_space']\n", " reward_function_cfg = agent_cfg['reward_function']\n", - " \n", + "\n", " # CREATE OBSERVATION SPACE\n", " if observation_space_cfg is None:\n", " obs_space = NullObservation()\n", " elif observation_space_cfg['type'] == 'UC2BlueObservation':\n", " node_obs_list = []\n", " link_obs_list = []\n", - " \n", - " \n", + "\n", + "\n", " #node ip to index maps ip addresses to node id, as there are potentially multiple nics on a node, there are multiple ip addresses\n", " node_ip_to_index = {}\n", " for node_idx, node_cfg in enumerate(nodes_cfg):\n", @@ -587,8 +626,8 @@ " for nic_uuid, nic_obj in n_obj.nics.items():\n", " node_ip_to_index[nic_obj.ip_address] = node_idx + 2\n", "\n", - " \n", - " \n", + "\n", + "\n", " for node_obs_cfg in observation_space_cfg['options']['nodes']:\n", " node_ref = node_obs_cfg['node_ref']\n", " folder_obs_list = []\n", @@ -618,9 +657,9 @@ " else:\n", " print(\"observation space config not specified correctly.\")\n", " obs_space = NullObservation()\n", - " \n", + "\n", " # CREATE ACTION SPACE\n", - " \n", + "\n", "\n", "\n", " # CREATE REWARD FUNCTION\n", diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index f6f96161..3f674fbb 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -1,12 +1,14 @@ import itertools from abc import ABC, abstractmethod -from typing import Any, Dict, List, Optional, Tuple +from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING from gym import spaces -from primaite.game.session import PrimaiteSession from primaite.simulator.sim_container import Simulation +if TYPE_CHECKING: + from primaite.game.session import PrimaiteSession + class ExecutionDefiniton(ABC): """ @@ -59,7 +61,7 @@ class DoNothingAction(AbstractAction): # i.e. a choice between one option. To make enumerating this action easier, we are adding a 'dummy' paramter # with one option. This just aids the Action Manager to enumerate all possibilities. - def form_request(self) -> List[str]: + def form_request(self, **kwargs) -> List[str]: return ["do_nothing"] @@ -86,56 +88,56 @@ class NodeServiceAbstractAction(AbstractAction): class NodeServiceScanAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: - super().__init__(manager=manager) + def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "scan" class NodeServiceStopAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: - super().__init__(manager=manager) + def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "stop" class NodeServiceStartAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: - super().__init__(manager=manager) + def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "start" class NodeServicePauseAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: - super().__init__(manager=manager) + def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "pause" class NodeServiceResumeAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: - super().__init__(manager=manager) + def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "resume" class NodeServiceRestartAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: - super().__init__(manager=manager) + def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "restart" class NodeServiceDisableAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: - super().__init__(manager=manager) + def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "disable" class NodeServiceEnableAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: - super().__init__(manager=manager) + def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "enable" class NodeFolderAbstractAction(AbstractAction): @abstractmethod - def __init__(self, manager: "ActionManager", num_nodes, num_folders, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes:int, num_folders:int, **kwargs) -> None: super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes, "folder_id": num_folders} self.verb: str @@ -149,26 +151,26 @@ class NodeFolderAbstractAction(AbstractAction): class NodeFolderScanAction(NodeFolderAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes, num_folders, **kwargs) -> None: - super().__init__(manager, num_nodes, num_folders, **kwargs) + def __init__(self, manager: "ActionManager", num_nodes:int, num_folders:int, **kwargs) -> None: + super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, **kwargs) self.verb: str = "scan" class NodeFolderCheckhashAction(NodeFolderAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes, num_folders, **kwargs) -> None: - super().__init__(manager, num_nodes, num_folders, **kwargs) + def __init__(self, manager: "ActionManager", num_nodes:int, num_folders:int, **kwargs) -> None: + super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, **kwargs) self.verb: str = "checkhash" class NodeFolderRepairAction(NodeFolderAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes, num_folders, **kwargs) -> None: - super().__init__(manager, num_nodes, num_folders, **kwargs) + def __init__(self, manager: "ActionManager", num_nodes:int, num_folders:int, **kwargs) -> None: + super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, **kwargs) self.verb: str = "repair" class NodeFolderRestoreAction(NodeFolderAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes, num_folders, **kwargs) -> None: - super().__init__(manager, num_nodes, num_folders, **kwargs) + def __init__(self, manager: "ActionManager", num_nodes:int, num_folders:int, **kwargs) -> None: + super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, **kwargs) self.verb: str = "restore" @@ -190,34 +192,40 @@ class NodeFileAbstractAction(AbstractAction): class NodeFileScanAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: - super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) + super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) self.verb = "scan" class NodeFileCheckhashAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: - super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) + super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) self.verb = "checkhash" class NodeFileDeleteAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: - super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) + super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) self.verb = "delete" class NodeFileRepairAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: - super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) + super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) self.verb = "repair" class NodeFileRestoreAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: - super().__init__(manager, num_nodes, num_folders, num_files, **kwargs) + super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) self.verb = "restore" +class NodeFileCorruptAction(NodeFileAbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: + super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) + self.verb = "corrupt" + + class NodeAbstractAction(AbstractAction): @abstractmethod def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: @@ -232,25 +240,25 @@ class NodeAbstractAction(AbstractAction): class NodeOSScanAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: - super().__init__(manager=manager) + super().__init__(manager=manager, num_nodes=num_nodes) self.verb = "scan" class NodeShutdownAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: - super().__init__(manager=manager) + super().__init__(manager=manager, num_nodes=num_nodes) self.verb = "shutdown" class NodeStartupAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: - super().__init__(manager=manager) + super().__init__(manager=manager, num_nodes=num_nodes) self.verb = "start" class NodeResetAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: - super().__init__(manager=manager) + super().__init__(manager=manager, num_nodes=num_nodes) self.verb = "reset" @@ -371,6 +379,7 @@ class ActionManager: "NODE_FILE_DELETE": NodeFileDeleteAction, "NODE_FILE_REPAIR": NodeFileRepairAction, "NODE_FILE_RESTORE": NodeFileRestoreAction, + "NODE_FILE_CORRUPT": NodeFileCorruptAction, "NODE_FOLDER_SCAN": NodeFolderScanAction, "NODE_FOLDER_CHECKHASH": NodeFolderCheckhashAction, "NODE_FOLDER_REPAIR": NodeFolderRepairAction, @@ -387,7 +396,7 @@ class ActionManager: def __init__( self, - session: PrimaiteSession, # reference to session for looking up stuff + session: "PrimaiteSession", # reference to session for looking up stuff actions: List[str], # stores list of actions available to agent node_uuids: List[str], # allows mapping index to node max_folders_per_node: int = 2, # allows calculating shape @@ -400,7 +409,7 @@ class ActionManager: ip_address_list: Optional[List[str]] = None, # to allow us to map an index to an ip address. act_map: Optional[Dict[int, Dict]] = None, # allows restricting set of possible actions ) -> None: - self.session: PrimaiteSession = session + self.session: "PrimaiteSession" = session self.sim: Simulation = self.session.simulation self.node_uuids: List[str] = node_uuids self.protocols: List[str] = protocols @@ -417,7 +426,8 @@ class ActionManager: for nic_uuid, nic_obj in nics.items(): self.ip_address_list.append(nic_obj.ip_address) - action_args = { + # action_args are settings which are applied to the action space as a whole. + global_action_args = { "num_nodes": len(node_uuids), "num_folders": max_folders_per_node, "num_files": max_files_per_folder, @@ -427,10 +437,21 @@ class ActionManager: "num_protocols": len(self.protocols), "num_ports": len(self.protocols), "num_ips": len(self.ip_address_list), + "max_acl_rules":max_acl_rules, + "max_nics_per_node": max_nics_per_node, } self.actions: Dict[str, AbstractAction] = {} - for act_type in actions: - self.actions[act_type] = self.__act_class_identifiers[act_type](self, **action_args) + for act_spec in actions: + # each action is provided into the action space config like this: + # - type: ACTION_TYPE + # options: + # option_1: value1 + # option_2: value2 + # where `type` decides which AbstractAction subclass should be used + # and `options` is an optional dict of options to pass to the init method of the action class + act_type = act_spec.get('type') + act_options = act_spec.get('options', {}) + self.actions[act_type] = self.__act_class_identifiers[act_type](self, **global_action_args, **act_options) self.action_map: Dict[int, Tuple[str, Dict]] = {} """ @@ -448,15 +469,41 @@ class ActionManager: def _enumerate_actions( self, - ) -> Dict[int, Tuple[AbstractAction, Dict]]: + ) -> Dict[int, Tuple[str, Dict]]: + """Generate a list of all the possible actions that could be taken. + + This enumerates all actions all combinations of parametes you could choose for those actions. The output + of this function is intended to populate the self.action_map parameter in the situation where the user provides + a list of action types, but doesn't specify any subset of actions that should be made available to the agent. + + The enumeration relies on the Actions' `shape` attribute. + + :return: An action map maps consecutive integers to a combination of Action type and parameter choices. + An example output could be: + {0: ("DONOTHING", {'dummy': 0}), + 1: ("NODE_OS_SCAN", {'node_id': 0}), + 2: ("NODE_OS_SCAN", {'node_id': 1}), + 3: ("NODE_FOLDER_SCAN", {'node_id:0, folder_id:0}), + ... #etc... + } + :rtype: Dict[int, Tuple[AbstractAction, Dict]] + """ all_action_possibilities = [] - for action in self.actions.values(): - param_names = (list(action.shape.keys()),) + for act_name, action in self.actions.items(): + param_names = list(action.shape.keys()) num_possibilities = list(action.shape.values()) possibilities = [range(n) for n in num_possibilities] - itertools.product(action.shape.values()) - all_action_possibilities.append((action, {})) + param_combinations = list(itertools.product(*possibilities)) + all_action_possibilities.extend( + [ + ( + act_name, {param_names[i]:param_combinations[j][i] for i in range(len(param_names))} + ) for j in range(len(param_combinations))] + ) + + return {i:p for i,p in enumerate(all_action_possibilities)} + def get_action(self, action: int) -> Tuple[str, Dict]: """Produce action in CAOS format""" @@ -517,21 +564,16 @@ class ActionManager: return nics[nic_idx] @classmethod - def from_config(cls, session: PrimaiteSession, cfg: Dict) -> "ActionManager": + def from_config(cls, session: "PrimaiteSession", cfg: Dict) -> "ActionManager": obj = cls( session=session, actions=cfg["action_list"], - node_uuids=cfg["options"]["nodes"], - max_folders_per_node=cfg["options"]["max_folders_per_node"], - max_files_per_folder=cfg["options"]["max_files_per_folder"], - max_services_per_node=cfg["options"]["max_services_per_node"], - max_nics_per_node=cfg["options"]["max_nics_per_node"], - max_acl_rules=cfg["options"]["max_acl_rules"], - max_X=cfg["options"]["max_X"], - protocols=session.options.ports, - ports=session.options.protocols, + # node_uuids=cfg["options"]["node_uuids"], + **cfg['options'], + protocols=session.options.protocols, + ports=session.options.ports, ip_address_list=None, - act_map=cfg["action_map"], + act_map=cfg.get("action_map"), ) return obj diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 528c0b1a..4fd52d96 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -2,7 +2,7 @@ # That's because I want to point out that this is disctinct from 'agent' in the reinforcement learning sense of the word # If you disagree, make a comment in the PR review and we can discuss from abc import ABC, abstractmethod -from typing import Any, Dict, List, Optional, TypeAlias, Union +from typing import Any, Dict, List, Optional, Tuple, TypeAlias, Union import numpy as np @@ -41,17 +41,17 @@ class AbstractAgent(ABC): return self.reward_function.calculate(state) @abstractmethod - def get_action(self, obs: ObsType, reward: float = None): + def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: # in RL agent, this method will send CAOS observation to GATE RL agent, then receive a int 0-39, # then use a bespoke conversion to take 1-40 int back into CAOS action - return ("NODE", "SERVICE", "SCAN", "", "") + return ("DO_NOTHING", {} ) - @abstractmethod - def format_request(self, action) -> List[str]: + def format_request(self, action:Tuple[str,Dict], options:Dict[str, int]) -> List[str]: # this will take something like APPLICATION.EXECUTE and add things like target_ip_address in simulator. # therefore the execution definition needs to be a mapping from CAOS into SIMULATOR """Format action into format expected by the simulator, and apply execution definition if applicable.""" - return ["network", "nodes", "", "file_system", "folder", "root", "scan"] + request = self.action_space.form_request(action_identifier=action, action_options=options) + return request class AbstractScriptedAgent(AbstractAgent): @@ -63,8 +63,8 @@ class AbstractScriptedAgent(AbstractAgent): class RandomAgent(AbstractScriptedAgent): """Agent that ignores its observation and acts completely at random.""" - def get_action(self, obs: ObsType, reward: float = None): - return self.action_space.space.sample() + def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: + return self.action_space.get_action(self.action_space.space.sample()) class AbstractGATEAgent(AbstractAgent): diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index ec778176..a4ceb2dd 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -5,13 +5,30 @@ class AbstractReward(): def __init__(self): ... + @abstractmethod def calculate(self, state:Dict) -> float: return 0.3 +class DummyReward(AbstractReward): + + def calculate(self, state: Dict) -> float: + return -0.1 class RewardFunction(): + __rew_class_identifiers:Dict[str,type[AbstractReward]] = { + "DUMMY" : DummyReward + } def __init__(self, reward_function:AbstractReward): self.reward: AbstractReward = reward_function def calculate(self, state:Dict) -> float: return self.reward.calculate(state) + + @classmethod + def from_config(cls, cfg:Dict) -> "RewardFunction": + for rew_component_cfg in cfg['reward_components']: + rew_type = rew_component_cfg['type'] + rew_component = cls.__rew_class_identifiers[rew_type]() + new = cls(reward_function=rew_component) + return new + diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 0f88b322..46e834d6 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -11,7 +11,7 @@ from typing import Dict, List from pydantic import BaseModel from primaite.game.agent.actions import ActionManager -from primaite.game.agent.interface import AbstractAgent +from primaite.game.agent.interface import AbstractAgent, RandomAgent from primaite.game.agent.observations import ( AclObservation, FileObservation, @@ -25,6 +25,7 @@ from primaite.game.agent.observations import ( UC2BlueObservation, UC2RedObservation, ) +from primaite.game.agent.rewards import RewardFunction from primaite.simulator.network.hardware.base import Link, NIC, Node from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router @@ -74,10 +75,10 @@ class PrimaiteSession: # to discrete(40) is only necessary for purposes of RL learning, therefore that bit of # code should live inside of the GATE agent subclass) # gets action in CAOS format - agent_action = agent.get_action(agent_obs, agent_reward) + agent_action, action_options = agent.get_action(agent_obs, agent_reward) # 9. CAOS action is converted into request (extra information might be needed to enrich # the request, this is what the execution definition is there for) - agent_request = agent.format_request(agent_action) + agent_request = agent.format_request(agent_action, action_options) # 10. primaite session receives the action from the agents and asks the simulation to apply each self.simulation.apply_action(agent_request) @@ -88,6 +89,10 @@ class PrimaiteSession: @classmethod def from_config(cls, cfg: dict) -> "PrimaiteSession": sess = cls() + sess.options = PrimaiteSessionOptions( + ports = cfg['game_config']['ports'], + protocols = cfg['game_config']['protocols'], + ) sim = sess.simulation net = sim.network @@ -304,13 +309,33 @@ class PrimaiteSession: obs_space = NullObservation() # CREATE ACTION SPACE + action_space_cfg['options']['node_uuids'] = [] + # if a list of nodes is defined, convert them from node references to node UUIDs + for action_node_option in action_space_cfg.get('options',{}).pop('nodes', {}): + if 'node_ref' in action_node_option: + node_uuid = ref_map_nodes[action_node_option['node_ref']] + action_space_cfg['options']['node_uuids'].append(node_uuid) + # Each action space can potentially have a different list of nodes that it can apply to. Therefore, + # we will pass node_uuids as a part of the action space config. + # However, it's not possible to specify the node uuids directly in the config, as they are generated + # dynamically, so we have to translate node references to uuids before passing this config on. + + if 'action_list' in action_space_cfg: + for action_config in action_space_cfg['action_list']: + if 'options' in action_config: + if 'target_router_ref' in action_config['options']: + _target = action_config['options']['target_router_ref'] + action_config['options']['target_router_uuid'] = ref_map_nodes[_target] + action_space = ActionManager.from_config(sess, action_space_cfg) # CREATE REWARD FUNCTION + rew_function = RewardFunction.from_config(reward_function_cfg) # CREATE AGENT if agent_type == "GreenWebBrowsingAgent": - ... + new_agent = RandomAgent(action_space=action_space, observation_space=obs_space, reward_function=rew_function) + sess.agents.append(new_agent) elif agent_type == "GATERLAgent": ... elif agent_type == "RedDatabaseCorruptingAgent": @@ -318,4 +343,5 @@ class PrimaiteSession: else: print("agent type not found") + return sess diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index d647b0bc..1df5fe12 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -27,6 +27,7 @@ class Simulation(SimComponent): am.add_action("network", Action(func=self.network._action_manager)) # pass through domain actions to the domain object am.add_action("domain", Action(func=self.domain._action_manager)) + am.add_action("do_nothing", Action(func=lambda request, context: ())) return am def describe_state(self) -> Dict: From ccb36f84004134fb361cf7df94806a3a7c099851 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 8 Oct 2023 17:02:54 +0100 Subject: [PATCH 212/980] Change observations to make loading from config better --- example_config.yaml | 41 ++++----- sandbox.ipynb | 112 +++++++++++++++++++++--- src/primaite/game/agent/interface.py | 2 + src/primaite/game/agent/observations.py | 109 +++++++++++++++++++++-- src/primaite/game/session.py | 32 +++++-- 5 files changed, 246 insertions(+), 50 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index 9c75c92e..9f679223 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -17,10 +17,12 @@ game_config: - ref: client_1_green_user team: GREEN type: GreenWebBrowsingAgent - observation_space: null + observation_space: + type: UC2GreenObservation action_space: action_list: - type: DONOTHING + # # - type: NODE_LOGON # - type: NODE_LOGOFF # - type: NODE_APPLICATION_EXECUTE @@ -68,6 +70,7 @@ game_config: action_space: action_list: - type: DONOTHING + #8f:1d:3f:32:1c:d6\n", + "2023-10-08 14:40:34,938: SwitchPort 8f:1d:3f:32:1c:d6 connected to Link be:b1:a2:ce:eb:4c/192.168.1.1<-->8f:1d:3f:32:1c:d6\n", + "2023-10-08 14:40:34,939: Link be:b1:a2:ce:eb:4c/192.168.1.1<-->8f:1d:3f:32:1c:d6 up\n", + "2023-10-08 14:40:34,939: Link be:b1:a2:ce:eb:4c/192.168.1.1<-->8f:1d:3f:32:1c:d6 up\n", + "2023-10-08 14:40:34,940: Added link b8070c26-6ad0-4d7e-aed8-c1bcdcf9b438 to connect be:b1:a2:ce:eb:4c/192.168.1.1 and 8f:1d:3f:32:1c:d6\n", + "2023-10-08 14:40:34,942: NIC dc:48:6c:bd:8b:b1/192.168.1.1 connected to Link dc:48:6c:bd:8b:b1/192.168.1.1<-->b2:14:a5:82:c0:7a\n", + "2023-10-08 14:40:34,943: SwitchPort b2:14:a5:82:c0:7a connected to Link dc:48:6c:bd:8b:b1/192.168.1.1<-->b2:14:a5:82:c0:7a\n", + "2023-10-08 14:40:34,945: Link dc:48:6c:bd:8b:b1/192.168.1.1<-->b2:14:a5:82:c0:7a up\n", + "2023-10-08 14:40:34,946: Link dc:48:6c:bd:8b:b1/192.168.1.1<-->b2:14:a5:82:c0:7a up\n", + "2023-10-08 14:40:34,946: Added link 102f5506-a939-4af7-8ebb-8e173e18283c to connect dc:48:6c:bd:8b:b1/192.168.1.1 and b2:14:a5:82:c0:7a\n", + "2023-10-08 14:40:34,947: SwitchPort 00:9f:54:21:e2:f2 connected to Link 00:9f:54:21:e2:f2<-->68:69:bf:51:6c:c0/192.168.1.10\n", + "2023-10-08 14:40:34,949: Link 00:9f:54:21:e2:f2<-->68:69:bf:51:6c:c0/192.168.1.10 up\n", + "2023-10-08 14:40:34,950: NIC 68:69:bf:51:6c:c0/192.168.1.10 connected to Link 00:9f:54:21:e2:f2<-->68:69:bf:51:6c:c0/192.168.1.10\n", + "2023-10-08 14:40:34,951: Link 00:9f:54:21:e2:f2<-->68:69:bf:51:6c:c0/192.168.1.10 up\n", + "2023-10-08 14:40:34,952: Added link 6136fd05-7a16-4afd-aebd-cdf6e255689b to connect 00:9f:54:21:e2:f2 and 68:69:bf:51:6c:c0/192.168.1.10\n", + "2023-10-08 14:40:34,952: SwitchPort 48:cc:7b:ac:dd:f9 connected to Link 48:cc:7b:ac:dd:f9<-->64:15:7d:f0:cd:ce/192.168.1.12\n", + "2023-10-08 14:40:34,954: Link 48:cc:7b:ac:dd:f9<-->64:15:7d:f0:cd:ce/192.168.1.12 up\n", + "2023-10-08 14:40:34,954: NIC 64:15:7d:f0:cd:ce/192.168.1.12 connected to Link 48:cc:7b:ac:dd:f9<-->64:15:7d:f0:cd:ce/192.168.1.12\n", + "2023-10-08 14:40:34,955: Link 48:cc:7b:ac:dd:f9<-->64:15:7d:f0:cd:ce/192.168.1.12 up\n", + "2023-10-08 14:40:34,956: Added link 02c6f4e4-3674-4189-a5a1-334fa86921f6 to connect 48:cc:7b:ac:dd:f9 and 64:15:7d:f0:cd:ce/192.168.1.12\n", + "2023-10-08 14:40:34,957: SwitchPort e4:e3:bb:bf:9e:04 connected to Link e4:e3:bb:bf:9e:04<-->81:cd:6e:b8:3d:6c/192.168.1.14\n", + "2023-10-08 14:40:34,958: Link e4:e3:bb:bf:9e:04<-->81:cd:6e:b8:3d:6c/192.168.1.14 up\n", + "2023-10-08 14:40:34,959: NIC 81:cd:6e:b8:3d:6c/192.168.1.14 connected to Link e4:e3:bb:bf:9e:04<-->81:cd:6e:b8:3d:6c/192.168.1.14\n", + "2023-10-08 14:40:34,960: Link e4:e3:bb:bf:9e:04<-->81:cd:6e:b8:3d:6c/192.168.1.14 up\n", + "2023-10-08 14:40:34,961: Added link 57e0f89d-265b-4d27-838b-828ae9800688 to connect e4:e3:bb:bf:9e:04 and 81:cd:6e:b8:3d:6c/192.168.1.14\n", + "2023-10-08 14:40:34,962: SwitchPort 71:5f:fc:32:79:9f connected to Link 71:5f:fc:32:79:9f<-->29:fa:41:0b:f5:1b/192.168.1.16\n", + "2023-10-08 14:40:34,964: Link 71:5f:fc:32:79:9f<-->29:fa:41:0b:f5:1b/192.168.1.16 up\n", + "2023-10-08 14:40:34,965: NIC 29:fa:41:0b:f5:1b/192.168.1.16 connected to Link 71:5f:fc:32:79:9f<-->29:fa:41:0b:f5:1b/192.168.1.16\n", + "2023-10-08 14:40:34,966: Link 71:5f:fc:32:79:9f<-->29:fa:41:0b:f5:1b/192.168.1.16 up\n", + "2023-10-08 14:40:34,967: Added link 1f382171-5e0d-4a76-9500-27dc68c3c7ee to connect 71:5f:fc:32:79:9f and 29:fa:41:0b:f5:1b/192.168.1.16\n", + "2023-10-08 14:40:34,968: SwitchPort 66:5d:d0:ba:c1:91 connected to Link 66:5d:d0:ba:c1:91<-->0d:22:07:53:7a:e1/192.168.1.110\n", + "2023-10-08 14:40:34,969: Link 66:5d:d0:ba:c1:91<-->0d:22:07:53:7a:e1/192.168.1.110 up\n", + "2023-10-08 14:40:34,970: NIC 0d:22:07:53:7a:e1/192.168.1.110 connected to Link 66:5d:d0:ba:c1:91<-->0d:22:07:53:7a:e1/192.168.1.110\n", + "2023-10-08 14:40:34,971: Link 66:5d:d0:ba:c1:91<-->0d:22:07:53:7a:e1/192.168.1.110 up\n", + "2023-10-08 14:40:34,972: Added link d8ea175e-50c8-4597-99bf-ac9001b30c77 to connect 66:5d:d0:ba:c1:91 and 0d:22:07:53:7a:e1/192.168.1.110\n", + "2023-10-08 14:40:34,972: SwitchPort 22:f5:91:5a:bb:b1 connected to Link 22:f5:91:5a:bb:b1<-->82:e5:30:d9:0e:85/192.168.10.21\n", + "2023-10-08 14:40:34,974: Link 22:f5:91:5a:bb:b1<-->82:e5:30:d9:0e:85/192.168.10.21 up\n", + "2023-10-08 14:40:34,975: NIC 82:e5:30:d9:0e:85/192.168.10.21 connected to Link 22:f5:91:5a:bb:b1<-->82:e5:30:d9:0e:85/192.168.10.21\n", + "2023-10-08 14:40:34,976: Link 22:f5:91:5a:bb:b1<-->82:e5:30:d9:0e:85/192.168.10.21 up\n", + "2023-10-08 14:40:34,977: Added link 40ba49b9-e334-45ce-93da-a1459b80e9a2 to connect 22:f5:91:5a:bb:b1 and 82:e5:30:d9:0e:85/192.168.10.21\n", + "2023-10-08 14:40:34,978: SwitchPort 70:77:d0:12:cd:a0 connected to Link 70:77:d0:12:cd:a0<-->ef:20:20:d8:9a:11/192.168.10.22\n", + "2023-10-08 14:40:34,980: Link 70:77:d0:12:cd:a0<-->ef:20:20:d8:9a:11/192.168.10.22 up\n", + "2023-10-08 14:40:34,981: NIC ef:20:20:d8:9a:11/192.168.10.22 connected to Link 70:77:d0:12:cd:a0<-->ef:20:20:d8:9a:11/192.168.10.22\n", + "2023-10-08 14:40:34,982: Link 70:77:d0:12:cd:a0<-->ef:20:20:d8:9a:11/192.168.10.22 up\n", + "2023-10-08 14:40:34,982: Added link c36027fe-052f-4eb6-b6c6-10bf817c7ac9 to connect 70:77:d0:12:cd:a0 and ef:20:20:d8:9a:11/192.168.10.22\n", + "2023-10-08 14:40:34,983: SwitchPort 62:da:0d:de:eb:27 connected to Link 62:da:0d:de:eb:27<-->b8:2b:a3:f0:18:b9/192.168.10.110\n", + "2023-10-08 14:40:34,985: Link 62:da:0d:de:eb:27<-->b8:2b:a3:f0:18:b9/192.168.10.110 up\n", + "2023-10-08 14:40:34,986: NIC b8:2b:a3:f0:18:b9/192.168.10.110 connected to Link 62:da:0d:de:eb:27<-->b8:2b:a3:f0:18:b9/192.168.10.110\n", + "2023-10-08 14:40:34,987: Link 62:da:0d:de:eb:27<-->b8:2b:a3:f0:18:b9/192.168.10.110 up\n", + "2023-10-08 14:40:34,988: Added link 9469edcd-6b36-4333-b948-3eeccf24abcb to connect 62:da:0d:de:eb:27 and b8:2b:a3:f0:18:b9/192.168.10.110\n" ] }, { @@ -93,7 +153,9 @@ { "data": { "text/plain": [ - "[]" + "[,\n", + " ,\n", + " ]" ] }, "execution_count": 7, @@ -118,7 +180,33 @@ "cell_type": "code", "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-10-08 14:40:35,046: Stepping primaite session. Step counter: 0\n", + "2023-10-08 14:40:35,047: Sending simulation state to agent client_1_green_user\n", + "2023-10-08 14:40:35,049: Getting agent action\n", + "2023-10-08 14:40:35,050: Formatting agent action DONOTHING\n", + "2023-10-08 14:40:35,051: Sending request to simulation: ['do_nothing']\n", + "2023-10-08 14:40:35,052: Sending simulation state to agent client_1_data_manipulation_red_bot\n" + ] + }, + { + "ename": "AttributeError", + "evalue": "'NoneType' object has no attribute 'observe'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m/home/cade/repos/PrimAITE/sandbox.ipynb Cell 10\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> 1\u001b[0m sess\u001b[39m.\u001b[39;49mstep()\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/session.py:75\u001b[0m, in \u001b[0;36mPrimaiteSession.step\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 72\u001b[0m sim_state \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39msimulation\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 74\u001b[0m \u001b[39m# 6. each agent takes most recent state and converts it to CAOS observation\u001b[39;00m\n\u001b[0;32m---> 75\u001b[0m agent_obs \u001b[39m=\u001b[39m agent\u001b[39m.\u001b[39;49mconvert_state_to_obs(sim_state)\n\u001b[1;32m 77\u001b[0m \u001b[39m# 7. meanwhile each agent also takes state and calculates reward\u001b[39;00m\n\u001b[1;32m 78\u001b[0m agent_reward \u001b[39m=\u001b[39m agent\u001b[39m.\u001b[39mcalculate_reward_from_state(sim_state)\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/interface.py:40\u001b[0m, in \u001b[0;36mAbstractAgent.convert_state_to_obs\u001b[0;34m(self, state)\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mconvert_state_to_obs\u001b[39m(\u001b[39mself\u001b[39m, state: Dict) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m ObsType:\n\u001b[1;32m 36\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 37\u001b[0m \u001b[39m state : dict state directly from simulation.describe_state\u001b[39;00m\n\u001b[1;32m 38\u001b[0m \u001b[39m output : dict state according to CAOS.\u001b[39;00m\n\u001b[1;32m 39\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m---> 40\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mobservation_space\u001b[39m.\u001b[39;49mobserve(state)\n", + "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'observe'" + ] + } + ], "source": [ "sess.step()" ] diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 4fd52d96..6083db6f 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -18,10 +18,12 @@ class AbstractAgent(ABC): def __init__( self, + agent_name: Optional[str], action_space: Optional[ActionManager], observation_space: Optional[ObservationSpace], reward_function: Optional[RewardFunction], ) -> None: + self.agent_name:str = agent_name or "unnamed_agent" self.action_space: Optional[ActionManager] = action_space self.observation_space: Optional[ObservationSpace] = observation_space self.reward_function: Optional[RewardFunction] = reward_function diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index f919a723..21f623fd 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -1,10 +1,13 @@ from abc import ABC, abstractmethod -from typing import Any, Dict, Hashable, List, Optional +from typing import Any, Dict, Hashable, List, Optional, TYPE_CHECKING from gym import spaces from pydantic import BaseModel +from primaite.game.session import PrimaiteSession from primaite.simulator.sim_container import Simulation +if TYPE_CHECKING: + from primaite.game.session import PrimaiteSession NOT_PRESENT_IN_STATE = object() """ @@ -53,6 +56,15 @@ class AbstractObservation(ABC): """Subclasses must define the shape that they expect""" ... + @abstractmethod + @classmethod + def from_config(cls, config:Dict, session:"PrimaiteSession"): + """Create this observation space component form a serialised format. + + The `session` parameter is for a the PrimaiteSession object that spawns this component. During deserialisation, + a subclass of this class may need to translate from a 'reference' to a UUID. + """ + class FileObservation(AbstractObservation): def __init__(self, where: Optional[List[str]] = None) -> None: @@ -84,6 +96,10 @@ class FileObservation(AbstractObservation): def space(self) -> spaces.Space: return spaces.Dict({"health_status": spaces.Discrete(6)}) + @classmethod + def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where=None): + return cls(where=parent_where+["files", config["file_name"]]) + class ServiceObservation(AbstractObservation): default_observation: spaces.Space = {"operating_status": 0, "health_status": 0} @@ -115,6 +131,11 @@ class ServiceObservation(AbstractObservation): def space(self) -> spaces.Space: return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(6)}) + @classmethod + def from_config(cls, config: Dict, session: PrimaiteSession, parent_where:Optional[List[str]]=None): + return cls(where=parent_where+["services",session.ref_map_services[config['service_ref']]]) + + class LinkObservation(AbstractObservation): default_observation: spaces.Space = {"protocols": {"all": {"load": 0}}} @@ -154,6 +175,10 @@ class LinkObservation(AbstractObservation): def space(self) -> spaces.Space: return spaces.Dict({"protocols": spaces.Dict({"all": spaces.Dict({"load": spaces.Discrete(11)})})}) + @classmethod + def from_config(cls, config: Dict, session: "PrimaiteSession"): + return cls(where=['network','links', session.ref_map_links[config['link_ref']]]) + class FolderObservation(AbstractObservation): def __init__(self, where: Optional[List[str]] = None, files: List[FileObservation] = []) -> None: @@ -209,6 +234,15 @@ class FolderObservation(AbstractObservation): } ) + @classmethod + def from_config(cls, config: Dict, session: PrimaiteSession, parent_where:Optional[List[str]]): + where = parent_where + ["folders", config['folder_name']] + + file_configs = config["files"] + files = [FileObservation.from_config(config=f, session=session, parent_where=where) for f in file_configs] + + return cls(where=where,files=files) + class NicObservation(AbstractObservation): default_observation: spaces.Space = {"nic_status": 0} @@ -230,6 +264,10 @@ class NicObservation(AbstractObservation): def space(self) -> spaces.Space: return spaces.Dict({"nic_status": spaces.Discrete(3)}) + @classmethod + def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where:Optional[List[str]]): + return cls(where=parent_where + ["NICs", config["nic_uuid"]]) + class NodeObservation(AbstractObservation): def __init__( @@ -310,6 +348,25 @@ class NodeObservation(AbstractObservation): return spaces.Dict(space_shape) + @classmethod + def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where:Optional[List[str]]= None): + node_uuid = session.ref_map_nodes[config['node_ref']] + if parent_where is None: + where = ["network", "nodes", node_uuid] + else: + where = parent_where + ["nodes", node_uuid] + + svc_configs = config.get('services', {}) + services = [ServiceObservation.from_config(config=c, session=session, parent_where=where) for c in svc_configs] + folder_configs = config.get('folders', {}) + folders = [FolderObservation.from_config(config=c,session=session, parent_where=where) for c in folder_configs] + nic_uuids = session.simulation.network.nodes[node_uuid].nics.keys() + nic_configs = [{'nic_uuid':n for n in nic_uuids }] + nics = [NicObservation.from_config(config=c, session=session, parent_where=where) for c in nic_configs] + logon_status = config.get('logon_status',False) + cls(where=where, services=services, folders=folders, nics=nics, logon_status=logon_status) + return super().from_config(config, session) + class AclObservation(AbstractObservation): @@ -399,6 +456,21 @@ class AclObservation(AbstractObservation): } ) + @classmethod + def from_config(cls, config: Dict, session: "PrimaiteSession") -> "AclObservation": + node_ip_to_idx = {} + for node_idx, node_cfg in enumerate(config['node_order']): + n_ref = node_cfg["node_ref"] + n_obj = session.simulation.network.nodes[session.ref_map_nodes[n_ref]] + for nic_uuid, nic_obj in n_obj.nics.items(): + node_ip_to_idx[nic_obj.ip_address] = node_idx + 2 + + router_uuid = session.ref_map_nodes[config['router_node_ref']] + return cls( + node_ip_to_id=node_ip_to_idx, + ports=session.options.ports, + protocols=session.options.protocols, + where=["network", "nodes", router_uuid]) @@ -413,6 +485,10 @@ class NullObservation(AbstractObservation): def space(self) -> spaces.Space: return spaces.Dict({}) + @classmethod + def from_config(cls, cfg:Dict) -> "NullObservation": + return cls() + class ICSObservation(NullObservation): pass @@ -463,11 +539,18 @@ class UC2BlueObservation(AbstractObservation): }) @classmethod - def from_config(cls, config:Dict, sim:Simulation): - nodes = ... - links = ... - acl = ... - ics = ... + def from_config(cls, config:Dict, sess:"PrimaiteSession"): + node_configs = config["nodes"] + nodes = [NodeObservation.from_config(n) for n in node_configs] + + link_configs = config["links"] + links = [LinkObservation.from_config(l) for l in link_configs] + + acl_config = config["acl"] + acl = AclObservation.from_config(acl_config) + + ics_config = config["ics"] + ics = ICSObservation.from_config(ics_config) new = cls(nodes=nodes, links=links, acl=acl, ics=ics, where=['network']) return new @@ -489,8 +572,11 @@ class UC2RedObservation(AbstractObservation): @classmethod def from_config(cls, config: Dict, sim:Simulation): + ... #TODO +class UC2GreenObservation(NullObservation): pass + class ObservationSpace: """ Manage the observations of an Actor. @@ -515,3 +601,14 @@ class ObservationSpace: @property def space(self) -> None: return self.obs.space + + @classmethod + def from_config(cls, config:Dict, session:"PrimaiteSession") -> "ObservationSpace": + if config['type'] == "UC2BlueObservation": + return cls(UC2BlueObservation(config['options'])) + elif config['type'] == "UC2RedObservation": + return cls(UC2RedObservation(config['options'])) + elif config['type'] == "UC2GreenObservation": + return cls(UC2GreenObservation(config["options"])) + else: + raise ValueError("Observation space type invalid") diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 46e834d6..f0ae05c6 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -23,6 +23,7 @@ from primaite.game.agent.observations import ( NullObservation, ServiceObservation, UC2BlueObservation, + UC2GreenObservation, UC2RedObservation, ) from primaite.game.agent.rewards import RewardFunction @@ -41,6 +42,10 @@ from primaite.simulator.system.services.dns_server import DNSServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.service import Service +from primaite import getLogger + +_LOGGER = getLogger(__name__) + class PrimaiteSessionOptions(BaseModel): ports: List[str] @@ -55,13 +60,19 @@ class PrimaiteSession: self.episode_counter: int = 0 self.options: PrimaiteSessionOptions + self.ref_map_nodes: Dict[str, Node] = {} + self.ref_map_services: Dict[str, Service] = {} + self.ref_map_links: Dict[str, Link] = {} + def step(self): + _LOGGER.debug(f"Stepping primaite session. Step counter: {self.step_counter}") # currently designed with assumption that all agents act once per step in order for agent in self.agents: # 3. primaite session asks simulation to provide initial state # 4. primate session gives state to all agents # 5. primaite session asks agents to produce an action based on most recent state + _LOGGER.debug(f"Sending simulation state to agent {agent.agent_name}") sim_state = self.simulation.describe_state() # 6. each agent takes most recent state and converts it to CAOS observation @@ -75,14 +86,18 @@ class PrimaiteSession: # to discrete(40) is only necessary for purposes of RL learning, therefore that bit of # code should live inside of the GATE agent subclass) # gets action in CAOS format + _LOGGER.debug(f"Getting agent action") agent_action, action_options = agent.get_action(agent_obs, agent_reward) # 9. CAOS action is converted into request (extra information might be needed to enrich # the request, this is what the execution definition is there for) + _LOGGER.debug(f"Formatting agent action {agent_action}") # maybe too many debug log statements agent_request = agent.format_request(agent_action, action_options) # 10. primaite session receives the action from the agents and asks the simulation to apply each + _LOGGER.debug(f"Sending request to simulation: {agent_request}") self.simulation.apply_action(agent_request) + _LOGGER.debug(f"Initiating simulation step {self.step_counter}") self.simulation.apply_timestep(self.step_counter) self.step_counter += 1 @@ -96,9 +111,9 @@ class PrimaiteSession: sim = sess.simulation net = sim.network - ref_map_nodes: Dict[str, Node] = {} - ref_map_services: Dict[str, Service] = {} - ref_map_links: Dict[str, Link] = {} + sess.ref_map_nodes: Dict[str, Node] = {} + sess.ref_map_services: Dict[str, Service] = {} + sess.ref_map_links: Dict[str, Link] = {} nodes_cfg = cfg["simulation"]["network"]["nodes"] links_cfg = cfg["simulation"]["network"]["links"] @@ -304,6 +319,8 @@ class PrimaiteSession: ) elif observation_space_cfg["type"] == "UC2RedObservation": obs_space = UC2RedObservation.from_config(observation_space_cfg["options"], sim=sim) + elif observation_space_cfg["type"] == "UC2GreenObservation": + obs_space = UC2GreenObservation.from_config(observation_space_cfg.get('options',{})) else: print("observation space config not specified correctly.") obs_space = NullObservation() @@ -334,12 +351,15 @@ class PrimaiteSession: # CREATE AGENT if agent_type == "GreenWebBrowsingAgent": - new_agent = RandomAgent(action_space=action_space, observation_space=obs_space, reward_function=rew_function) + # TODO: implement non-random agents and fix this parsing + new_agent = RandomAgent(agent_name=agent_cfg['ref'], action_space=action_space, observation_space=obs_space, reward_function=rew_function) sess.agents.append(new_agent) elif agent_type == "GATERLAgent": - ... + new_agent = RandomAgent(agent_name=agent_cfg['ref'], action_space=action_space, observation_space=obs_space, reward_function=rew_function) + sess.agents.append(new_agent) elif agent_type == "RedDatabaseCorruptingAgent": - ... + new_agent = RandomAgent(agent_name=agent_cfg['ref'], action_space=action_space, observation_space=obs_space, reward_function=rew_function) + sess.agents.append(new_agent) else: print("agent type not found") From 081a3e519a94ada17100bfceac907b8530060002 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 8 Oct 2023 17:57:45 +0100 Subject: [PATCH 213/980] Fix certain observation bugs --- sandbox.ipynb | 167 ++++++++++--------- src/primaite/game/agent/observations.py | 55 ++++--- src/primaite/game/session.py | 203 ++++++++++++------------ 3 files changed, 228 insertions(+), 197 deletions(-) diff --git a/sandbox.ipynb b/sandbox.ipynb index 0191f0ae..b3b3be0d 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -70,66 +70,66 @@ "name": "stderr", "output_type": "stream", "text": [ - "2023-10-08 14:40:34,910: Added node 162d4e70-4aa3-4663-b5cb-1b2127d002c6 to Network 0449bb3a-abb6-418d-b041-8742cddc9c55\n", - "2023-10-08 14:40:34,914: Added node 0f316f2c-f9b9-4972-9fbe-c69900b12c28 to Network 0449bb3a-abb6-418d-b041-8742cddc9c55\n", - "2023-10-08 14:40:34,916: Added node 6ab23b82-7182-48ac-9bbe-8315772bc4ff to Network 0449bb3a-abb6-418d-b041-8742cddc9c55\n", - "2023-10-08 14:40:34,918: Added node 5ebb4df7-b285-44a6-8579-92932206542d to Network 0449bb3a-abb6-418d-b041-8742cddc9c55\n", - "2023-10-08 14:40:34,920: Added node c99b357f-1874-4220-a428-d8b87d7383bb to Network 0449bb3a-abb6-418d-b041-8742cddc9c55\n", - "2023-10-08 14:40:34,924: Added node 5f98cbb1-9045-4f6e-91f7-4eaa78437f11 to Network 0449bb3a-abb6-418d-b041-8742cddc9c55\n", - "2023-10-08 14:40:34,926: Added node 27288000-bbfa-4ef8-a413-3e42cfe2e5d4 to Network 0449bb3a-abb6-418d-b041-8742cddc9c55\n", - "2023-10-08 14:40:34,930: Added node cc54ae23-c46f-4adc-a211-5c32a0f307ad to Network 0449bb3a-abb6-418d-b041-8742cddc9c55\n", - "2023-10-08 14:40:34,933: Added node 91d75e63-31c8-4fac-922c-d008a21b14dc to Network 0449bb3a-abb6-418d-b041-8742cddc9c55\n", - "2023-10-08 14:40:34,935: Added node 6e29546f-ab79-41f6-8b3c-439c03e27ab4 to Network 0449bb3a-abb6-418d-b041-8742cddc9c55\n", - "2023-10-08 14:40:34,937: NIC be:b1:a2:ce:eb:4c/192.168.1.1 connected to Link be:b1:a2:ce:eb:4c/192.168.1.1<-->8f:1d:3f:32:1c:d6\n", - "2023-10-08 14:40:34,938: SwitchPort 8f:1d:3f:32:1c:d6 connected to Link be:b1:a2:ce:eb:4c/192.168.1.1<-->8f:1d:3f:32:1c:d6\n", - "2023-10-08 14:40:34,939: Link be:b1:a2:ce:eb:4c/192.168.1.1<-->8f:1d:3f:32:1c:d6 up\n", - "2023-10-08 14:40:34,939: Link be:b1:a2:ce:eb:4c/192.168.1.1<-->8f:1d:3f:32:1c:d6 up\n", - "2023-10-08 14:40:34,940: Added link b8070c26-6ad0-4d7e-aed8-c1bcdcf9b438 to connect be:b1:a2:ce:eb:4c/192.168.1.1 and 8f:1d:3f:32:1c:d6\n", - "2023-10-08 14:40:34,942: NIC dc:48:6c:bd:8b:b1/192.168.1.1 connected to Link dc:48:6c:bd:8b:b1/192.168.1.1<-->b2:14:a5:82:c0:7a\n", - "2023-10-08 14:40:34,943: SwitchPort b2:14:a5:82:c0:7a connected to Link dc:48:6c:bd:8b:b1/192.168.1.1<-->b2:14:a5:82:c0:7a\n", - "2023-10-08 14:40:34,945: Link dc:48:6c:bd:8b:b1/192.168.1.1<-->b2:14:a5:82:c0:7a up\n", - "2023-10-08 14:40:34,946: Link dc:48:6c:bd:8b:b1/192.168.1.1<-->b2:14:a5:82:c0:7a up\n", - "2023-10-08 14:40:34,946: Added link 102f5506-a939-4af7-8ebb-8e173e18283c to connect dc:48:6c:bd:8b:b1/192.168.1.1 and b2:14:a5:82:c0:7a\n", - "2023-10-08 14:40:34,947: SwitchPort 00:9f:54:21:e2:f2 connected to Link 00:9f:54:21:e2:f2<-->68:69:bf:51:6c:c0/192.168.1.10\n", - "2023-10-08 14:40:34,949: Link 00:9f:54:21:e2:f2<-->68:69:bf:51:6c:c0/192.168.1.10 up\n", - "2023-10-08 14:40:34,950: NIC 68:69:bf:51:6c:c0/192.168.1.10 connected to Link 00:9f:54:21:e2:f2<-->68:69:bf:51:6c:c0/192.168.1.10\n", - "2023-10-08 14:40:34,951: Link 00:9f:54:21:e2:f2<-->68:69:bf:51:6c:c0/192.168.1.10 up\n", - "2023-10-08 14:40:34,952: Added link 6136fd05-7a16-4afd-aebd-cdf6e255689b to connect 00:9f:54:21:e2:f2 and 68:69:bf:51:6c:c0/192.168.1.10\n", - "2023-10-08 14:40:34,952: SwitchPort 48:cc:7b:ac:dd:f9 connected to Link 48:cc:7b:ac:dd:f9<-->64:15:7d:f0:cd:ce/192.168.1.12\n", - "2023-10-08 14:40:34,954: Link 48:cc:7b:ac:dd:f9<-->64:15:7d:f0:cd:ce/192.168.1.12 up\n", - "2023-10-08 14:40:34,954: NIC 64:15:7d:f0:cd:ce/192.168.1.12 connected to Link 48:cc:7b:ac:dd:f9<-->64:15:7d:f0:cd:ce/192.168.1.12\n", - "2023-10-08 14:40:34,955: Link 48:cc:7b:ac:dd:f9<-->64:15:7d:f0:cd:ce/192.168.1.12 up\n", - "2023-10-08 14:40:34,956: Added link 02c6f4e4-3674-4189-a5a1-334fa86921f6 to connect 48:cc:7b:ac:dd:f9 and 64:15:7d:f0:cd:ce/192.168.1.12\n", - "2023-10-08 14:40:34,957: SwitchPort e4:e3:bb:bf:9e:04 connected to Link e4:e3:bb:bf:9e:04<-->81:cd:6e:b8:3d:6c/192.168.1.14\n", - "2023-10-08 14:40:34,958: Link e4:e3:bb:bf:9e:04<-->81:cd:6e:b8:3d:6c/192.168.1.14 up\n", - "2023-10-08 14:40:34,959: NIC 81:cd:6e:b8:3d:6c/192.168.1.14 connected to Link e4:e3:bb:bf:9e:04<-->81:cd:6e:b8:3d:6c/192.168.1.14\n", - "2023-10-08 14:40:34,960: Link e4:e3:bb:bf:9e:04<-->81:cd:6e:b8:3d:6c/192.168.1.14 up\n", - "2023-10-08 14:40:34,961: Added link 57e0f89d-265b-4d27-838b-828ae9800688 to connect e4:e3:bb:bf:9e:04 and 81:cd:6e:b8:3d:6c/192.168.1.14\n", - "2023-10-08 14:40:34,962: SwitchPort 71:5f:fc:32:79:9f connected to Link 71:5f:fc:32:79:9f<-->29:fa:41:0b:f5:1b/192.168.1.16\n", - "2023-10-08 14:40:34,964: Link 71:5f:fc:32:79:9f<-->29:fa:41:0b:f5:1b/192.168.1.16 up\n", - "2023-10-08 14:40:34,965: NIC 29:fa:41:0b:f5:1b/192.168.1.16 connected to Link 71:5f:fc:32:79:9f<-->29:fa:41:0b:f5:1b/192.168.1.16\n", - "2023-10-08 14:40:34,966: Link 71:5f:fc:32:79:9f<-->29:fa:41:0b:f5:1b/192.168.1.16 up\n", - "2023-10-08 14:40:34,967: Added link 1f382171-5e0d-4a76-9500-27dc68c3c7ee to connect 71:5f:fc:32:79:9f and 29:fa:41:0b:f5:1b/192.168.1.16\n", - "2023-10-08 14:40:34,968: SwitchPort 66:5d:d0:ba:c1:91 connected to Link 66:5d:d0:ba:c1:91<-->0d:22:07:53:7a:e1/192.168.1.110\n", - "2023-10-08 14:40:34,969: Link 66:5d:d0:ba:c1:91<-->0d:22:07:53:7a:e1/192.168.1.110 up\n", - "2023-10-08 14:40:34,970: NIC 0d:22:07:53:7a:e1/192.168.1.110 connected to Link 66:5d:d0:ba:c1:91<-->0d:22:07:53:7a:e1/192.168.1.110\n", - "2023-10-08 14:40:34,971: Link 66:5d:d0:ba:c1:91<-->0d:22:07:53:7a:e1/192.168.1.110 up\n", - "2023-10-08 14:40:34,972: Added link d8ea175e-50c8-4597-99bf-ac9001b30c77 to connect 66:5d:d0:ba:c1:91 and 0d:22:07:53:7a:e1/192.168.1.110\n", - "2023-10-08 14:40:34,972: SwitchPort 22:f5:91:5a:bb:b1 connected to Link 22:f5:91:5a:bb:b1<-->82:e5:30:d9:0e:85/192.168.10.21\n", - "2023-10-08 14:40:34,974: Link 22:f5:91:5a:bb:b1<-->82:e5:30:d9:0e:85/192.168.10.21 up\n", - "2023-10-08 14:40:34,975: NIC 82:e5:30:d9:0e:85/192.168.10.21 connected to Link 22:f5:91:5a:bb:b1<-->82:e5:30:d9:0e:85/192.168.10.21\n", - "2023-10-08 14:40:34,976: Link 22:f5:91:5a:bb:b1<-->82:e5:30:d9:0e:85/192.168.10.21 up\n", - "2023-10-08 14:40:34,977: Added link 40ba49b9-e334-45ce-93da-a1459b80e9a2 to connect 22:f5:91:5a:bb:b1 and 82:e5:30:d9:0e:85/192.168.10.21\n", - "2023-10-08 14:40:34,978: SwitchPort 70:77:d0:12:cd:a0 connected to Link 70:77:d0:12:cd:a0<-->ef:20:20:d8:9a:11/192.168.10.22\n", - "2023-10-08 14:40:34,980: Link 70:77:d0:12:cd:a0<-->ef:20:20:d8:9a:11/192.168.10.22 up\n", - "2023-10-08 14:40:34,981: NIC ef:20:20:d8:9a:11/192.168.10.22 connected to Link 70:77:d0:12:cd:a0<-->ef:20:20:d8:9a:11/192.168.10.22\n", - "2023-10-08 14:40:34,982: Link 70:77:d0:12:cd:a0<-->ef:20:20:d8:9a:11/192.168.10.22 up\n", - "2023-10-08 14:40:34,982: Added link c36027fe-052f-4eb6-b6c6-10bf817c7ac9 to connect 70:77:d0:12:cd:a0 and ef:20:20:d8:9a:11/192.168.10.22\n", - "2023-10-08 14:40:34,983: SwitchPort 62:da:0d:de:eb:27 connected to Link 62:da:0d:de:eb:27<-->b8:2b:a3:f0:18:b9/192.168.10.110\n", - "2023-10-08 14:40:34,985: Link 62:da:0d:de:eb:27<-->b8:2b:a3:f0:18:b9/192.168.10.110 up\n", - "2023-10-08 14:40:34,986: NIC b8:2b:a3:f0:18:b9/192.168.10.110 connected to Link 62:da:0d:de:eb:27<-->b8:2b:a3:f0:18:b9/192.168.10.110\n", - "2023-10-08 14:40:34,987: Link 62:da:0d:de:eb:27<-->b8:2b:a3:f0:18:b9/192.168.10.110 up\n", - "2023-10-08 14:40:34,988: Added link 9469edcd-6b36-4333-b948-3eeccf24abcb to connect 62:da:0d:de:eb:27 and b8:2b:a3:f0:18:b9/192.168.10.110\n" + "2023-10-08 17:56:35,831: Added node af2f9c15-ecb4-4b65-b48f-63f12acddb88 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", + "2023-10-08 17:56:35,836: Added node 47158854-0917-4037-a6a2-33dde56a120f to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", + "2023-10-08 17:56:35,840: Added node cba8ce63-8064-4f80-bcfe-95ca65221dfa to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", + "2023-10-08 17:56:35,846: Added node e01e7c2b-02ac-4e2d-b7bb-8bc3b6ea6509 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", + "2023-10-08 17:56:35,857: Added node bd5d85ba-5980-45c7-8b28-020a2cfeba0f to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", + "2023-10-08 17:56:35,863: Added node 39e0e37c-4d72-4c76-93cb-4f9c29651ef4 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", + "2023-10-08 17:56:35,878: Added node 7d1063f9-b5e5-4753-966e-1b630325b266 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", + "2023-10-08 17:56:35,881: Added node d85b6abb-0f9e-4853-af26-c9b410e1cb94 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", + "2023-10-08 17:56:35,884: Added node 63b18888-98aa-4182-a014-02999d095bd0 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", + "2023-10-08 17:56:35,888: Added node f514cf8a-a3f1-46d6-be00-994364241ef4 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", + "2023-10-08 17:56:35,890: NIC 27:a9:09:ed:30:5a/192.168.1.1 connected to Link 27:a9:09:ed:30:5a/192.168.1.1<-->cb:6f:24:8c:7a:20\n", + "2023-10-08 17:56:35,891: SwitchPort cb:6f:24:8c:7a:20 connected to Link 27:a9:09:ed:30:5a/192.168.1.1<-->cb:6f:24:8c:7a:20\n", + "2023-10-08 17:56:35,893: Link 27:a9:09:ed:30:5a/192.168.1.1<-->cb:6f:24:8c:7a:20 up\n", + "2023-10-08 17:56:35,896: Link 27:a9:09:ed:30:5a/192.168.1.1<-->cb:6f:24:8c:7a:20 up\n", + "2023-10-08 17:56:35,897: Added link 41d994cb-2976-4aa2-b306-649cef4deb80 to connect 27:a9:09:ed:30:5a/192.168.1.1 and cb:6f:24:8c:7a:20\n", + "2023-10-08 17:56:35,899: NIC 5c:fa:b1:a4:69:ec/192.168.1.1 connected to Link 5c:fa:b1:a4:69:ec/192.168.1.1<-->68:54:d7:42:04:87\n", + "2023-10-08 17:56:35,900: SwitchPort 68:54:d7:42:04:87 connected to Link 5c:fa:b1:a4:69:ec/192.168.1.1<-->68:54:d7:42:04:87\n", + "2023-10-08 17:56:35,901: Link 5c:fa:b1:a4:69:ec/192.168.1.1<-->68:54:d7:42:04:87 up\n", + "2023-10-08 17:56:35,903: Link 5c:fa:b1:a4:69:ec/192.168.1.1<-->68:54:d7:42:04:87 up\n", + "2023-10-08 17:56:35,904: Added link d582a248-e968-40eb-9d1b-67143d729e0c to connect 5c:fa:b1:a4:69:ec/192.168.1.1 and 68:54:d7:42:04:87\n", + "2023-10-08 17:56:35,905: SwitchPort c6:bd:77:78:4b:5d connected to Link c6:bd:77:78:4b:5d<-->1c:d9:92:e8:d6:3b/192.168.1.10\n", + "2023-10-08 17:56:35,908: Link c6:bd:77:78:4b:5d<-->1c:d9:92:e8:d6:3b/192.168.1.10 up\n", + "2023-10-08 17:56:35,909: NIC 1c:d9:92:e8:d6:3b/192.168.1.10 connected to Link c6:bd:77:78:4b:5d<-->1c:d9:92:e8:d6:3b/192.168.1.10\n", + "2023-10-08 17:56:35,911: Link c6:bd:77:78:4b:5d<-->1c:d9:92:e8:d6:3b/192.168.1.10 up\n", + "2023-10-08 17:56:35,912: Added link 13315780-1fcc-4c85-b94b-ef8f14c88a8a to connect c6:bd:77:78:4b:5d and 1c:d9:92:e8:d6:3b/192.168.1.10\n", + "2023-10-08 17:56:35,913: SwitchPort cd:46:af:c4:33:65 connected to Link cd:46:af:c4:33:65<-->aa:cf:2f:71:13:5b/192.168.1.12\n", + "2023-10-08 17:56:35,916: Link cd:46:af:c4:33:65<-->aa:cf:2f:71:13:5b/192.168.1.12 up\n", + "2023-10-08 17:56:35,917: NIC aa:cf:2f:71:13:5b/192.168.1.12 connected to Link cd:46:af:c4:33:65<-->aa:cf:2f:71:13:5b/192.168.1.12\n", + "2023-10-08 17:56:35,918: Link cd:46:af:c4:33:65<-->aa:cf:2f:71:13:5b/192.168.1.12 up\n", + "2023-10-08 17:56:35,919: Added link 6c2a80f7-f36d-4df6-ac84-d354e5d517dd to connect cd:46:af:c4:33:65 and aa:cf:2f:71:13:5b/192.168.1.12\n", + "2023-10-08 17:56:35,920: SwitchPort 2c:d2:67:ef:68:a8 connected to Link 2c:d2:67:ef:68:a8<-->e1:09:5e:98:ee:a2/192.168.1.14\n", + "2023-10-08 17:56:35,923: Link 2c:d2:67:ef:68:a8<-->e1:09:5e:98:ee:a2/192.168.1.14 up\n", + "2023-10-08 17:56:35,924: NIC e1:09:5e:98:ee:a2/192.168.1.14 connected to Link 2c:d2:67:ef:68:a8<-->e1:09:5e:98:ee:a2/192.168.1.14\n", + "2023-10-08 17:56:35,925: Link 2c:d2:67:ef:68:a8<-->e1:09:5e:98:ee:a2/192.168.1.14 up\n", + "2023-10-08 17:56:35,926: Added link 1cfdd4f2-22be-4e69-8f1f-daef8e18f543 to connect 2c:d2:67:ef:68:a8 and e1:09:5e:98:ee:a2/192.168.1.14\n", + "2023-10-08 17:56:35,927: SwitchPort 9b:13:8c:a0:8c:82 connected to Link 9b:13:8c:a0:8c:82<-->cc:c2:84:03:1c:42/192.168.1.16\n", + "2023-10-08 17:56:35,929: Link 9b:13:8c:a0:8c:82<-->cc:c2:84:03:1c:42/192.168.1.16 up\n", + "2023-10-08 17:56:35,930: NIC cc:c2:84:03:1c:42/192.168.1.16 connected to Link 9b:13:8c:a0:8c:82<-->cc:c2:84:03:1c:42/192.168.1.16\n", + "2023-10-08 17:56:35,932: Link 9b:13:8c:a0:8c:82<-->cc:c2:84:03:1c:42/192.168.1.16 up\n", + "2023-10-08 17:56:35,933: Added link 031111e1-3b05-49ce-bd1f-2cdf77b210f4 to connect 9b:13:8c:a0:8c:82 and cc:c2:84:03:1c:42/192.168.1.16\n", + "2023-10-08 17:56:35,934: SwitchPort a1:70:9e:43:1c:07 connected to Link a1:70:9e:43:1c:07<-->e7:58:3c:ed:f7:37/192.168.1.110\n", + "2023-10-08 17:56:35,937: Link a1:70:9e:43:1c:07<-->e7:58:3c:ed:f7:37/192.168.1.110 up\n", + "2023-10-08 17:56:35,938: NIC e7:58:3c:ed:f7:37/192.168.1.110 connected to Link a1:70:9e:43:1c:07<-->e7:58:3c:ed:f7:37/192.168.1.110\n", + "2023-10-08 17:56:35,939: Link a1:70:9e:43:1c:07<-->e7:58:3c:ed:f7:37/192.168.1.110 up\n", + "2023-10-08 17:56:35,941: Added link f15884e7-0df6-4fa5-bb72-406cb2bdff45 to connect a1:70:9e:43:1c:07 and e7:58:3c:ed:f7:37/192.168.1.110\n", + "2023-10-08 17:56:35,943: SwitchPort a5:da:f2:03:21:e3 connected to Link a5:da:f2:03:21:e3<-->cf:63:9f:62:fe:df/192.168.10.21\n", + "2023-10-08 17:56:35,946: Link a5:da:f2:03:21:e3<-->cf:63:9f:62:fe:df/192.168.10.21 up\n", + "2023-10-08 17:56:35,947: NIC cf:63:9f:62:fe:df/192.168.10.21 connected to Link a5:da:f2:03:21:e3<-->cf:63:9f:62:fe:df/192.168.10.21\n", + "2023-10-08 17:56:35,948: Link a5:da:f2:03:21:e3<-->cf:63:9f:62:fe:df/192.168.10.21 up\n", + "2023-10-08 17:56:35,950: Added link cc6767fa-25de-4daa-bd47-37b49b15a881 to connect a5:da:f2:03:21:e3 and cf:63:9f:62:fe:df/192.168.10.21\n", + "2023-10-08 17:56:35,951: SwitchPort eb:5b:86:14:bd:d1 connected to Link eb:5b:86:14:bd:d1<-->3d:73:a6:62:97:3a/192.168.10.22\n", + "2023-10-08 17:56:35,953: Link eb:5b:86:14:bd:d1<-->3d:73:a6:62:97:3a/192.168.10.22 up\n", + "2023-10-08 17:56:35,954: NIC 3d:73:a6:62:97:3a/192.168.10.22 connected to Link eb:5b:86:14:bd:d1<-->3d:73:a6:62:97:3a/192.168.10.22\n", + "2023-10-08 17:56:35,955: Link eb:5b:86:14:bd:d1<-->3d:73:a6:62:97:3a/192.168.10.22 up\n", + "2023-10-08 17:56:35,958: Added link b29563ed-0636-4188-ba28-52b74a04da27 to connect eb:5b:86:14:bd:d1 and 3d:73:a6:62:97:3a/192.168.10.22\n", + "2023-10-08 17:56:35,959: SwitchPort e3:3a:0b:03:0b:8c connected to Link e3:3a:0b:03:0b:8c<-->d4:ff:37:8d:e4:3d/192.168.10.110\n", + "2023-10-08 17:56:35,961: Link e3:3a:0b:03:0b:8c<-->d4:ff:37:8d:e4:3d/192.168.10.110 up\n", + "2023-10-08 17:56:35,963: NIC d4:ff:37:8d:e4:3d/192.168.10.110 connected to Link e3:3a:0b:03:0b:8c<-->d4:ff:37:8d:e4:3d/192.168.10.110\n", + "2023-10-08 17:56:35,963: Link e3:3a:0b:03:0b:8c<-->d4:ff:37:8d:e4:3d/192.168.10.110 up\n", + "2023-10-08 17:56:35,964: Added link f6fe7757-a8c1-4cdc-a2b2-49d247117903 to connect e3:3a:0b:03:0b:8c and d4:ff:37:8d:e4:3d/192.168.10.110\n" ] }, { @@ -153,9 +153,9 @@ { "data": { "text/plain": [ - "[,\n", - " ,\n", - " ]" + "[,\n", + " ,\n", + " ]" ] }, "execution_count": 7, @@ -185,25 +185,44 @@ "name": "stderr", "output_type": "stream", "text": [ - "2023-10-08 14:40:35,046: Stepping primaite session. Step counter: 0\n", - "2023-10-08 14:40:35,047: Sending simulation state to agent client_1_green_user\n", - "2023-10-08 14:40:35,049: Getting agent action\n", - "2023-10-08 14:40:35,050: Formatting agent action DONOTHING\n", - "2023-10-08 14:40:35,051: Sending request to simulation: ['do_nothing']\n", - "2023-10-08 14:40:35,052: Sending simulation state to agent client_1_data_manipulation_red_bot\n" + "2023-10-08 17:56:36,041: Stepping primaite session. Step counter: 0\n", + "2023-10-08 17:56:36,043: Sending simulation state to agent client_1_green_user\n", + "2023-10-08 17:56:36,045: Getting agent action\n", + "2023-10-08 17:56:36,047: Formatting agent action DONOTHING\n", + "2023-10-08 17:56:36,048: Sending request to simulation: ['do_nothing']\n", + "2023-10-08 17:56:36,050: Sending simulation state to agent client_1_data_manipulation_red_bot\n" ] }, { - "ename": "AttributeError", - "evalue": "'NoneType' object has no attribute 'observe'", + "name": "stdout", + "output_type": "stream", + "text": [ + "[]\n", + "[]\n" + ] + }, + { + "ename": "TypeError", + "evalue": "unhashable type: 'DataManipulationBot'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m/home/cade/repos/PrimAITE/sandbox.ipynb Cell 10\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> 1\u001b[0m sess\u001b[39m.\u001b[39;49mstep()\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/session.py:75\u001b[0m, in \u001b[0;36mPrimaiteSession.step\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 72\u001b[0m sim_state \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39msimulation\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 74\u001b[0m \u001b[39m# 6. each agent takes most recent state and converts it to CAOS observation\u001b[39;00m\n\u001b[0;32m---> 75\u001b[0m agent_obs \u001b[39m=\u001b[39m agent\u001b[39m.\u001b[39;49mconvert_state_to_obs(sim_state)\n\u001b[1;32m 77\u001b[0m \u001b[39m# 7. meanwhile each agent also takes state and calculates reward\u001b[39;00m\n\u001b[1;32m 78\u001b[0m agent_reward \u001b[39m=\u001b[39m agent\u001b[39m.\u001b[39mcalculate_reward_from_state(sim_state)\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/session.py:80\u001b[0m, in \u001b[0;36mPrimaiteSession.step\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 77\u001b[0m sim_state \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39msimulation\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 79\u001b[0m \u001b[39m# 6. each agent takes most recent state and converts it to CAOS observation\u001b[39;00m\n\u001b[0;32m---> 80\u001b[0m agent_obs \u001b[39m=\u001b[39m agent\u001b[39m.\u001b[39;49mconvert_state_to_obs(sim_state)\n\u001b[1;32m 82\u001b[0m \u001b[39m# 7. meanwhile each agent also takes state and calculates reward\u001b[39;00m\n\u001b[1;32m 83\u001b[0m agent_reward \u001b[39m=\u001b[39m agent\u001b[39m.\u001b[39mcalculate_reward_from_state(sim_state)\n", "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/interface.py:40\u001b[0m, in \u001b[0;36mAbstractAgent.convert_state_to_obs\u001b[0;34m(self, state)\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mconvert_state_to_obs\u001b[39m(\u001b[39mself\u001b[39m, state: Dict) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m ObsType:\n\u001b[1;32m 36\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 37\u001b[0m \u001b[39m state : dict state directly from simulation.describe_state\u001b[39;00m\n\u001b[1;32m 38\u001b[0m \u001b[39m output : dict state according to CAOS.\u001b[39;00m\n\u001b[1;32m 39\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m---> 40\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mobservation_space\u001b[39m.\u001b[39;49mobserve(state)\n", - "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'observe'" + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:608\u001b[0m, in \u001b[0;36mObservationSpace.observe\u001b[0;34m(self, state)\u001b[0m\n\u001b[1;32m 607\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mobserve\u001b[39m(\u001b[39mself\u001b[39m, state) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Dict:\n\u001b[0;32m--> 608\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mobs\u001b[39m.\u001b[39;49mobserve(state)\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:571\u001b[0m, in \u001b[0;36mUC2RedObservation.observe\u001b[0;34m(self, state)\u001b[0m\n\u001b[1;32m 568\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdefault_observation\n\u001b[1;32m 570\u001b[0m obs \u001b[39m=\u001b[39m {}\n\u001b[0;32m--> 571\u001b[0m obs[\u001b[39m'\u001b[39m\u001b[39mNODES\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m {i\u001b[39m+\u001b[39m\u001b[39m1\u001b[39m: node\u001b[39m.\u001b[39mobserve(state) \u001b[39mfor\u001b[39;00m i, node \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnodes)}\n\u001b[1;32m 572\u001b[0m \u001b[39mreturn\u001b[39;00m obs\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:571\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 568\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdefault_observation\n\u001b[1;32m 570\u001b[0m obs \u001b[39m=\u001b[39m {}\n\u001b[0;32m--> 571\u001b[0m obs[\u001b[39m'\u001b[39m\u001b[39mNODES\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m {i\u001b[39m+\u001b[39m\u001b[39m1\u001b[39m: node\u001b[39m.\u001b[39;49mobserve(state) \u001b[39mfor\u001b[39;00m i, node \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnodes)}\n\u001b[1;32m 572\u001b[0m \u001b[39mreturn\u001b[39;00m obs\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:328\u001b[0m, in \u001b[0;36mNodeObservation.observe\u001b[0;34m(self, state)\u001b[0m\n\u001b[1;32m 326\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mservices)\n\u001b[1;32m 327\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfolders)\n\u001b[0;32m--> 328\u001b[0m obs[\u001b[39m\"\u001b[39m\u001b[39mSERVICES\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m {i \u001b[39m+\u001b[39m \u001b[39m1\u001b[39m: service\u001b[39m.\u001b[39mobserve(state) \u001b[39mfor\u001b[39;00m i, service \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mservices)}\n\u001b[1;32m 329\u001b[0m obs[\u001b[39m\"\u001b[39m\u001b[39mFOLDERS\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m {i \u001b[39m+\u001b[39m \u001b[39m1\u001b[39m: folder\u001b[39m.\u001b[39mobserve(state) \u001b[39mfor\u001b[39;00m i, folder \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfolders)}\n\u001b[1;32m 330\u001b[0m obs[\u001b[39m\"\u001b[39m\u001b[39moperating_status\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m node_state[\u001b[39m\"\u001b[39m\u001b[39moperating_state\u001b[39m\u001b[39m\"\u001b[39m]\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:328\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 326\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mservices)\n\u001b[1;32m 327\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfolders)\n\u001b[0;32m--> 328\u001b[0m obs[\u001b[39m\"\u001b[39m\u001b[39mSERVICES\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m {i \u001b[39m+\u001b[39m \u001b[39m1\u001b[39m: service\u001b[39m.\u001b[39;49mobserve(state) \u001b[39mfor\u001b[39;00m i, service \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mservices)}\n\u001b[1;32m 329\u001b[0m obs[\u001b[39m\"\u001b[39m\u001b[39mFOLDERS\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m {i \u001b[39m+\u001b[39m \u001b[39m1\u001b[39m: folder\u001b[39m.\u001b[39mobserve(state) \u001b[39mfor\u001b[39;00m i, folder \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfolders)}\n\u001b[1;32m 330\u001b[0m obs[\u001b[39m\"\u001b[39m\u001b[39moperating_status\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m node_state[\u001b[39m\"\u001b[39m\u001b[39moperating_state\u001b[39m\u001b[39m\"\u001b[39m]\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:124\u001b[0m, in \u001b[0;36mServiceObservation.observe\u001b[0;34m(self, state)\u001b[0m\n\u001b[1;32m 121\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mwhere \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 122\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdefault_observation\n\u001b[0;32m--> 124\u001b[0m service_state \u001b[39m=\u001b[39m access_from_nested_dict(state, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mwhere)\n\u001b[1;32m 125\u001b[0m \u001b[39mif\u001b[39;00m service_state \u001b[39mis\u001b[39;00m NOT_PRESENT_IN_STATE:\n\u001b[1;32m 126\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdefault_observation\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:37\u001b[0m, in \u001b[0;36maccess_from_nested_dict\u001b[0;34m(dictionary, keys)\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[39mif\u001b[39;00m k \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m dictionary:\n\u001b[1;32m 36\u001b[0m \u001b[39mreturn\u001b[39;00m NOT_PRESENT_IN_STATE\n\u001b[0;32m---> 37\u001b[0m \u001b[39mreturn\u001b[39;00m access_from_nested_dict(dictionary[k], keys)\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:37\u001b[0m, in \u001b[0;36maccess_from_nested_dict\u001b[0;34m(dictionary, keys)\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[39mif\u001b[39;00m k \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m dictionary:\n\u001b[1;32m 36\u001b[0m \u001b[39mreturn\u001b[39;00m NOT_PRESENT_IN_STATE\n\u001b[0;32m---> 37\u001b[0m \u001b[39mreturn\u001b[39;00m access_from_nested_dict(dictionary[k], keys)\n", + " \u001b[0;31m[... skipping similar frames: access_from_nested_dict at line 37 (1 times)]\u001b[0m\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:37\u001b[0m, in \u001b[0;36maccess_from_nested_dict\u001b[0;34m(dictionary, keys)\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[39mif\u001b[39;00m k \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m dictionary:\n\u001b[1;32m 36\u001b[0m \u001b[39mreturn\u001b[39;00m NOT_PRESENT_IN_STATE\n\u001b[0;32m---> 37\u001b[0m \u001b[39mreturn\u001b[39;00m access_from_nested_dict(dictionary[k], keys)\n", + "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:35\u001b[0m, in \u001b[0;36maccess_from_nested_dict\u001b[0;34m(dictionary, keys)\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[39mreturn\u001b[39;00m dictionary\n\u001b[1;32m 34\u001b[0m k \u001b[39m=\u001b[39m keys\u001b[39m.\u001b[39mpop(\u001b[39m0\u001b[39m)\n\u001b[0;32m---> 35\u001b[0m \u001b[39mif\u001b[39;00m k \u001b[39mnot\u001b[39;49;00m \u001b[39min\u001b[39;49;00m dictionary:\n\u001b[1;32m 36\u001b[0m \u001b[39mreturn\u001b[39;00m NOT_PRESENT_IN_STATE\n\u001b[1;32m 37\u001b[0m \u001b[39mreturn\u001b[39;00m access_from_nested_dict(dictionary[k], keys)\n", + "\u001b[0;31mTypeError\u001b[0m: unhashable type: 'DataManipulationBot'" ] } ], diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 21f623fd..c5b931ee 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -3,7 +3,6 @@ from typing import Any, Dict, Hashable, List, Optional, TYPE_CHECKING from gym import spaces from pydantic import BaseModel -from primaite.game.session import PrimaiteSession from primaite.simulator.sim_container import Simulation if TYPE_CHECKING: @@ -56,8 +55,8 @@ class AbstractObservation(ABC): """Subclasses must define the shape that they expect""" ... - @abstractmethod @classmethod + @abstractmethod def from_config(cls, config:Dict, session:"PrimaiteSession"): """Create this observation space component form a serialised format. @@ -132,7 +131,7 @@ class ServiceObservation(AbstractObservation): return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(6)}) @classmethod - def from_config(cls, config: Dict, session: PrimaiteSession, parent_where:Optional[List[str]]=None): + def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where:Optional[List[str]]=None): return cls(where=parent_where+["services",session.ref_map_services[config['service_ref']]]) @@ -235,7 +234,7 @@ class FolderObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: PrimaiteSession, parent_where:Optional[List[str]]): + def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where:Optional[List[str]]): where = parent_where + ["folders", config['folder_name']] file_configs = config["files"] @@ -324,7 +323,6 @@ class NodeObservation(AbstractObservation): return self.default_observation obs = {} - obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} obs["operating_status"] = node_state["operating_state"] @@ -349,7 +347,7 @@ class NodeObservation(AbstractObservation): return spaces.Dict(space_shape) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where:Optional[List[str]]= None): + def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where:Optional[List[str]]= None) -> "NodeObservation": node_uuid = session.ref_map_nodes[config['node_ref']] if parent_where is None: where = ["network", "nodes", node_uuid] @@ -361,12 +359,10 @@ class NodeObservation(AbstractObservation): folder_configs = config.get('folders', {}) folders = [FolderObservation.from_config(config=c,session=session, parent_where=where) for c in folder_configs] nic_uuids = session.simulation.network.nodes[node_uuid].nics.keys() - nic_configs = [{'nic_uuid':n for n in nic_uuids }] + nic_configs = [{'nic_uuid':n for n in nic_uuids }] if nic_uuids else [] nics = [NicObservation.from_config(config=c, session=session, parent_where=where) for c in nic_configs] logon_status = config.get('logon_status',False) - cls(where=where, services=services, folders=folders, nics=nics, logon_status=logon_status) - return super().from_config(config, session) - + return cls(where=where, services=services, folders=folders, nics=nics, logon_status=logon_status) class AclObservation(AbstractObservation): @@ -486,7 +482,7 @@ class NullObservation(AbstractObservation): return spaces.Dict({}) @classmethod - def from_config(cls, cfg:Dict) -> "NullObservation": + def from_config(cls, config:Dict, session:Optional["PrimaiteSession"]=None) -> "NullObservation": return cls() class ICSObservation(NullObservation): pass @@ -539,15 +535,15 @@ class UC2BlueObservation(AbstractObservation): }) @classmethod - def from_config(cls, config:Dict, sess:"PrimaiteSession"): + def from_config(cls, config:Dict, session:"PrimaiteSession"): node_configs = config["nodes"] - nodes = [NodeObservation.from_config(n) for n in node_configs] + nodes = [NodeObservation.from_config(config=n, session=session) for n in node_configs] link_configs = config["links"] - links = [LinkObservation.from_config(l) for l in link_configs] + links = [LinkObservation.from_config(config=l, session=session) for l in link_configs] acl_config = config["acl"] - acl = AclObservation.from_config(acl_config) + acl = AclObservation.from_config(config=acl_config, session=session) ics_config = config["ics"] ics = ICSObservation.from_config(ics_config) @@ -561,19 +557,30 @@ class UC2RedObservation(AbstractObservation): self.where:Optional[List[str]] = where self.nodes: List[NodeObservation] = nodes - self.default_observation=...#TODO + self.default_observation : Dict = { + "NODES": {i+1: n.default_observation for i,n in enumerate(self.nodes)}, + } - def observe(self, state: Dict) -> Any: - return super().observe(state) + def observe(self, state: Dict) -> Dict: + if self.where is None: + return self.default_observation + + obs = {} + obs['NODES'] = {i+1: node.observe(state) for i, node in enumerate(self.nodes)} + return obs @property def space(self) -> spaces.Space: - ... #TODO + return spaces.Dict({ + "NODES": spaces.Dict({i+1: node.space for i, node in enumerate(self.nodes)}), + }) @classmethod - def from_config(cls, config: Dict, sim:Simulation): + def from_config(cls, config: Dict, session: "PrimaiteSession"): + node_configs = config["nodes"] + nodes = [NodeObservation.from_config(config=cfg, session=session) for cfg in node_configs] + return cls(nodes=nodes, where=["network"]) - ... #TODO class UC2GreenObservation(NullObservation): pass @@ -605,10 +612,10 @@ class ObservationSpace: @classmethod def from_config(cls, config:Dict, session:"PrimaiteSession") -> "ObservationSpace": if config['type'] == "UC2BlueObservation": - return cls(UC2BlueObservation(config['options'])) + return cls(UC2BlueObservation.from_config(config.get('options',{}), session=session)) elif config['type'] == "UC2RedObservation": - return cls(UC2RedObservation(config['options'])) + return cls(UC2RedObservation.from_config(config.get('options',{}), session=session)) elif config['type'] == "UC2GreenObservation": - return cls(UC2GreenObservation(config["options"])) + return cls(UC2GreenObservation.from_config(config.get("options",{}), session=session)) else: raise ValueError("Observation space type invalid") diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index f0ae05c6..4bcf26e4 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -21,6 +21,7 @@ from primaite.game.agent.observations import ( NicObservation, NodeObservation, NullObservation, + ObservationSpace, ServiceObservation, UC2BlueObservation, UC2GreenObservation, @@ -177,7 +178,7 @@ class PrimaiteSession: if service_type in service_types_mapping: new_node.software_manager.install(service_types_mapping[service_type]) new_service = new_node.software_manager.software[service_type] - ref_map_services[service_ref] = new_service + sess.ref_map_services[service_ref] = new_service else: print(f"service type not found {service_type}") # service-dependent options @@ -198,12 +199,12 @@ class PrimaiteSession: net.add_node(new_node) new_node.power_on() - ref_map_nodes[node_ref] = new_node.uuid + sess.ref_map_nodes[node_ref] = new_node.uuid # 2. create links between nodes for link_cfg in links_cfg: - node_a = net.nodes[ref_map_nodes[link_cfg["endpoint_a_ref"]]] - node_b = net.nodes[ref_map_nodes[link_cfg["endpoint_b_ref"]]] + node_a = net.nodes[sess.ref_map_nodes[link_cfg["endpoint_a_ref"]]] + node_b = net.nodes[sess.ref_map_nodes[link_cfg["endpoint_b_ref"]]] if isinstance(node_a, Switch): endpoint_a = node_a.switch_ports[link_cfg["endpoint_a_port"]] else: @@ -213,7 +214,7 @@ class PrimaiteSession: else: endpoint_b = node_b.ethernet_port[link_cfg["endpoint_b_port"]] new_link = net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b) - ref_map_links[link_cfg["ref"]] = new_link.uuid + sess.ref_map_links[link_cfg["ref"]] = new_link.uuid # 3. create agents game_cfg = cfg["game_config"] @@ -229,108 +230,112 @@ class PrimaiteSession: reward_function_cfg = agent_cfg["reward_function"] # CREATE OBSERVATION SPACE - if observation_space_cfg is None: - obs_space = NullObservation() - elif observation_space_cfg["type"] == "UC2BlueObservation": - node_obs_list = [] - link_obs_list = [] + obs_space=ObservationSpace.from_config(observation_space_cfg, sess) - # node ip to index maps ip addresses to node id, as there are potentially multiple nics on a node, there are multiple ip addresses - node_ip_to_index = {} - for node_idx, node_cfg in enumerate(nodes_cfg): - n_ref = node_cfg["ref"] - n_obj = net.nodes[ref_map_nodes[n_ref]] - for nic_uuid, nic_obj in n_obj.nics.items(): - node_ip_to_index[nic_obj.ip_address] = node_idx + 2 + """ + # if observation_space_cfg is None: + # obs_space = NullObservation() + # elif observation_space_cfg["type"] == "UC2BlueObservation": + # node_obs_list = [] + # link_obs_list = [] - for node_obs_cfg in observation_space_cfg["options"]["nodes"]: - node_ref = node_obs_cfg["node_ref"] - folder_obs_list = [] - service_obs_list = [] - if "services" in node_obs_cfg: - for service_obs_cfg in node_obs_cfg["services"]: - service_obs_list.append( - ServiceObservation( - where=[ - "network", - "nodes", - ref_map_nodes[node_ref], - "services", - ref_map_services[service_obs_cfg["service_ref"]], - ] - ) - ) - if "folders" in node_obs_cfg: - for folder_obs_cfg in node_obs_cfg["folders"]: - file_obs_list = [] - if "files" in folder_obs_cfg: - for file_obs_cfg in folder_obs_cfg["files"]: - file_obs_list.append( - FileObservation( - where=[ - "network", - "nodes", - ref_map_nodes[node_ref], - "folders", - folder_obs_cfg["folder_name"], - "files", - file_obs_cfg["file_name"], - ] - ) - ) - folder_obs_list.append( - FolderObservation( - where=[ - "network", - "nodes", - ref_map_nodes[node_ref], - "folders", - folder_obs_cfg["folder_name"], - ], - files=file_obs_list, - ) - ) - nic_obs_list = [] - for nic_uuid in net.nodes[ref_map_nodes[node_obs_cfg["node_ref"]]].nics.keys(): - nic_obs_list.append( - NicObservation(where=["network", "nodes", ref_map_nodes[node_ref], "NICs", nic_uuid]) - ) - node_obs_list.append( - NodeObservation( - where=["network", "nodes", ref_map_nodes[node_ref]], - services=service_obs_list, - folders=folder_obs_list, - nics=nic_obs_list, - logon_status=False, - ) - ) - for link_obs_cfg in observation_space_cfg["options"]["links"]: - link_ref = link_obs_cfg["link_ref"] - link_obs_list.append(LinkObservation(where=["network", "links", ref_map_links[link_ref]])) + # # node ip to index maps ip addresses to node id, as there are potentially multiple nics on a node, there are multiple ip addresses + # node_ip_to_index = {} + # for node_idx, node_cfg in enumerate(nodes_cfg): + # n_ref = node_cfg["ref"] + # n_obj = net.nodes[ref_map_nodes[n_ref]] + # for nic_uuid, nic_obj in n_obj.nics.items(): + # node_ip_to_index[nic_obj.ip_address] = node_idx + 2 - acl_obs = AclObservation( - node_ip_to_id=node_ip_to_index, - ports=game_cfg["ports"], - protocols=game_cfg["ports"], - where=["network", "nodes", observation_space_cfg["options"]["acl"]["router_node_ref"]], - ) - obs_space = UC2BlueObservation( - nodes=node_obs_list, links=link_obs_list, acl=acl_obs, ics=ICSObservation() - ) - elif observation_space_cfg["type"] == "UC2RedObservation": - obs_space = UC2RedObservation.from_config(observation_space_cfg["options"], sim=sim) - elif observation_space_cfg["type"] == "UC2GreenObservation": - obs_space = UC2GreenObservation.from_config(observation_space_cfg.get('options',{})) - else: - print("observation space config not specified correctly.") - obs_space = NullObservation() + # for node_obs_cfg in observation_space_cfg["options"]["nodes"]: + # node_ref = node_obs_cfg["node_ref"] + # folder_obs_list = [] + # service_obs_list = [] + # if "services" in node_obs_cfg: + # for service_obs_cfg in node_obs_cfg["services"]: + # service_obs_list.append( + # ServiceObservation( + # where=[ + # "network", + # "nodes", + # ref_map_nodes[node_ref], + # "services", + # ref_map_services[service_obs_cfg["service_ref"]], + # ] + # ) + # ) + # if "folders" in node_obs_cfg: + # for folder_obs_cfg in node_obs_cfg["folders"]: + # file_obs_list = [] + # if "files" in folder_obs_cfg: + # for file_obs_cfg in folder_obs_cfg["files"]: + # file_obs_list.append( + # FileObservation( + # where=[ + # "network", + # "nodes", + # ref_map_nodes[node_ref], + # "folders", + # folder_obs_cfg["folder_name"], + # "files", + # file_obs_cfg["file_name"], + # ] + # ) + # ) + # folder_obs_list.append( + # FolderObservation( + # where=[ + # "network", + # "nodes", + # ref_map_nodes[node_ref], + # "folders", + # folder_obs_cfg["folder_name"], + # ], + # files=file_obs_list, + # ) + # ) + # nic_obs_list = [] + # for nic_uuid in net.nodes[ref_map_nodes[node_obs_cfg["node_ref"]]].nics.keys(): + # nic_obs_list.append( + # NicObservation(where=["network", "nodes", ref_map_nodes[node_ref], "NICs", nic_uuid]) + # ) + # node_obs_list.append( + # NodeObservation( + # where=["network", "nodes", ref_map_nodes[node_ref]], + # services=service_obs_list, + # folders=folder_obs_list, + # nics=nic_obs_list, + # logon_status=False, + # ) + # ) + # for link_obs_cfg in observation_space_cfg["options"]["links"]: + # link_ref = link_obs_cfg["link_ref"] + # link_obs_list.append(LinkObservation(where=["network", "links", ref_map_links[link_ref]])) + + # acl_obs = AclObservation( + # node_ip_to_id=node_ip_to_index, + # ports=game_cfg["ports"], + # protocols=game_cfg["ports"], + # where=["network", "nodes", observation_space_cfg["options"]["acl"]["router_node_ref"]], + # ) + # obs_space = UC2BlueObservation( + # nodes=node_obs_list, links=link_obs_list, acl=acl_obs, ics=ICSObservation() + # ) + # elif observation_space_cfg["type"] == "UC2RedObservation": + # obs_space = UC2RedObservation.from_config(observation_space_cfg["options"], sim=sim) + # elif observation_space_cfg["type"] == "UC2GreenObservation": + # obs_space = UC2GreenObservation.from_config(observation_space_cfg.get('options',{})) + # else: + # print("observation space config not specified correctly.") + # obs_space = NullObservation() + """ # CREATE ACTION SPACE action_space_cfg['options']['node_uuids'] = [] # if a list of nodes is defined, convert them from node references to node UUIDs for action_node_option in action_space_cfg.get('options',{}).pop('nodes', {}): if 'node_ref' in action_node_option: - node_uuid = ref_map_nodes[action_node_option['node_ref']] + node_uuid = sess.ref_map_nodes[action_node_option['node_ref']] action_space_cfg['options']['node_uuids'].append(node_uuid) # Each action space can potentially have a different list of nodes that it can apply to. Therefore, # we will pass node_uuids as a part of the action space config. @@ -342,7 +347,7 @@ class PrimaiteSession: if 'options' in action_config: if 'target_router_ref' in action_config['options']: _target = action_config['options']['target_router_ref'] - action_config['options']['target_router_uuid'] = ref_map_nodes[_target] + action_config['options']['target_router_uuid'] = sess.ref_map_nodes[_target] action_space = ActionManager.from_config(sess, action_space_cfg) From 2722abe428a42be5d2258e8f4ae06e848c2f424e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 9 Oct 2023 11:49:38 +0100 Subject: [PATCH 214/980] Fix typos and formattig (based on PR Review) --- docs/source/action_system.rst | 28 +++++++++---------- .../simulator/file_system/file_system.py | 2 +- src/primaite/simulator/network/container.py | 5 +--- .../test_action_integration.py | 2 +- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/docs/source/action_system.rst b/docs/source/action_system.rst index b527bff9..ef0fbd40 100644 --- a/docs/source/action_system.rst +++ b/docs/source/action_system.rst @@ -5,27 +5,27 @@ Actions System ============== -`SimComponent`s in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use `ActionManager` and `Action`. +``SimComponent``s in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``ActionManager`` and ``Action``. Just like other aspects of SimComponent, the actions are not managed centrally for the whole simulation, but instead they are dynamically created and updated based on the nodes, links, and other components that currently exist. This was achieved with the following design decisions: - API An 'action' contains two elements: - 1. `request` - selects which action you want to take on this `SimComponent`. This is formatted as a list of strings such as `['network', 'node', '', 'service', '', 'restart']`. - 2. `context` - optional extra information that can be used to decide how to process the action. This is formatted as a dictionary. For example, if the action requires authentication, the context can include information about the user that initiated the request to decide if their permissions are sufficient. + 1. ``request`` - selects which action you want to take on this ``SimComponent``. This is formatted as a list of strings such as `['network', 'node', '', 'service', '', 'restart']`. + 2. ``context`` - optional extra information that can be used to decide how to process the action. This is formatted as a dictionary. For example, if the action requires authentication, the context can include information about the user that initiated the request to decide if their permissions are sufficient. - request The request is a list of strings which help specify who should handle the request. The strings in the request list help ActionManagers traverse the 'ownership tree' of SimComponent. The example given above would be handled in the following way: - 1. `Simulation` receives `['network', 'node', '', 'service', '', 'restart']`. - The first element of the action is `network`, therefore it passes the action down to its network. - 2. `Network` receives `['node', '', 'service', '', 'restart']`. - The first element of the action is `node`, therefore the network looks at the node uuid and passes the action down to the node with that uuid. - 3. `Node` receives `['service', '', 'restart']`. - The first element of the action is `service`, therefore the node looks at the service uuid and passes the rest of the action to the service with that uuid. - 4. `Service` receives `['restart']`. - Since `restart` is a defined action in the service's own ActionManager, the service performs a restart. + 1. ``Simulation`` receives `['network', 'node', '', 'service', '', 'restart']`. + The first element of the action is ``network``, therefore it passes the action down to its network. + 2. ``Network`` receives `['node', '', 'service', '', 'restart']`. + The first element of the action is ``node``, therefore the network looks at the node uuid and passes the action down to the node with that uuid. + 3. ``Node`` receives `['service', '', 'restart']`. + The first element of the action is ``service``, therefore the node looks at the service uuid and passes the rest of the action to the service with that uuid. + 4. ``Service`` receives ``['restart']``. + Since ``restart`` is a defined action in the service's own ActionManager, the service performs a restart. Techincal Detail ================ @@ -35,12 +35,12 @@ This system was achieved by implementing two classes, :py:class:`primaite.simula Action ------ -The `Action` object stores a reference to a method that performs the action, for example a node could have an action that stores a reference to `self.turn_on()`. Techincally, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using `lambda` functions within a component's `self._init_action_manager()` method. Optionally, the `Action` object can also hold a validator that will permit/deny the action depending on context. +The ``Action`` object stores a reference to a method that performs the action, for example a node could have an action that stores a reference to ``self.turn_on()``. Techincally, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using ``lambda`` functions within a component's ``self._init_action_manager()`` method. Optionally, the ``Action`` object can also hold a validator that will permit/deny the action depending on context. ActionManager ------------- -The `ActionManager` object stores a mapping between strings and actions. It is responsible for processing the `request` and passing it down the ownership tree. Techincally, the `ActionManager` is itself a callable that accepts `request, context` tuple, and so it can be chained with other action managers. +The ``ActionManager`` object stores a mapping between strings and actions. It is responsible for processing the ``request`` and passing it down the ownership tree. Techincally, the ``ActionManager`` is itself a callable that accepts `request, context` tuple, and so it can be chained with other action managers. A simple example without chaining can be seen in the :py:class:`primaite.simulator.file_system.file_system.File` class. @@ -54,7 +54,7 @@ A simple example without chaining can be seen in the :py:class:`primaite.simulat action_manager.add_action("repair", Action(func=lambda request, context: self.repair())) action_manager.add_action("restore", Action(func=lambda request, context: self.restore())) -*ellipses (`...`) used to omit code impertinent to this explanation* +*ellipses (``...``) used to omit code impertinent to this explanation* Chaining ActionManagers ----------------------- diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 2c110624..8d981100 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -332,7 +332,7 @@ class Folder(FileSystemItemABC): is_quarantined: bool = False "Flag that marks the folder as quarantined if true." - def _init_action_manager(sekf) -> ActionManager: + def _init_action_manager(self) -> ActionManager: am = super()._init_action_manager() am.add_action("scan", Action(func=lambda request, context: ...)) # TODO implement action diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index f3afad12..e0384b5e 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -48,10 +48,7 @@ class Network(SimComponent): self._node_action_manager = ActionManager() am.add_action( "node", - Action( - func=self._node_action_manager - # func=lambda request, context: self.nodes[request.pop(0)].apply_action(request, context), - ), + Action(func=self._node_action_manager), ) return am diff --git a/tests/integration_tests/component_creation/test_action_integration.py b/tests/integration_tests/component_creation/test_action_integration.py index eb18110d..ef04ec41 100644 --- a/tests/integration_tests/component_creation/test_action_integration.py +++ b/tests/integration_tests/component_creation/test_action_integration.py @@ -5,7 +5,7 @@ from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.sim_container import Simulation -from primaite.simulator.system.services.database_service import DatabaseService +from primaite.simulator.system.services.database.database_service import DatabaseService def test_passing_actions_down(monkeypatch) -> None: From 5a5710c6ae181c1149d41af1b5db1c12db098c0e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 9 Oct 2023 13:24:08 +0100 Subject: [PATCH 215/980] Rename Sim Actions to request --- docs/source/action_system.rst | 40 +- docs/source/simulation_structure.rst | 6 +- src/primaite/notebooks/scratch.ipynb | 353 +----------------- .../create-simulation_demo.ipynb | 254 ++----------- src/primaite/simulator/core.py | 165 ++++---- src/primaite/simulator/domain/controller.py | 16 +- .../simulator/file_system/file_system.py | 54 +-- src/primaite/simulator/network/container.py | 18 +- .../simulator/network/hardware/base.py | 54 +-- .../network/hardware/nodes/router.py | 20 +- src/primaite/simulator/sim_container.py | 14 +- .../simulator/system/services/service.py | 20 +- src/primaite/simulator/system/software.py | 12 +- .../test_action_integration.py | 8 +- .../test_permission_system.py | 44 +-- .../_simulator/_domain/test_account.py | 2 +- 16 files changed, 266 insertions(+), 814 deletions(-) diff --git a/docs/source/action_system.rst b/docs/source/action_system.rst index ef0fbd40..11b74abf 100644 --- a/docs/source/action_system.rst +++ b/docs/source/action_system.rst @@ -5,7 +5,7 @@ Actions System ============== -``SimComponent``s in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``ActionManager`` and ``Action``. +``SimComponent``s in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``RequestManager`` and ``Action``. Just like other aspects of SimComponent, the actions are not managed centrally for the whole simulation, but instead they are dynamically created and updated based on the nodes, links, and other components that currently exist. This was achieved with the following design decisions: @@ -16,7 +16,7 @@ Just like other aspects of SimComponent, the actions are not managed centrally f 2. ``context`` - optional extra information that can be used to decide how to process the action. This is formatted as a dictionary. For example, if the action requires authentication, the context can include information about the user that initiated the request to decide if their permissions are sufficient. - request - The request is a list of strings which help specify who should handle the request. The strings in the request list help ActionManagers traverse the 'ownership tree' of SimComponent. The example given above would be handled in the following way: + The request is a list of strings which help specify who should handle the request. The strings in the request list help RequestManagers traverse the 'ownership tree' of SimComponent. The example given above would be handled in the following way: 1. ``Simulation`` receives `['network', 'node', '', 'service', '', 'restart']`. The first element of the action is ``network``, therefore it passes the action down to its network. @@ -25,22 +25,22 @@ Just like other aspects of SimComponent, the actions are not managed centrally f 3. ``Node`` receives `['service', '', 'restart']`. The first element of the action is ``service``, therefore the node looks at the service uuid and passes the rest of the action to the service with that uuid. 4. ``Service`` receives ``['restart']``. - Since ``restart`` is a defined action in the service's own ActionManager, the service performs a restart. + Since ``restart`` is a defined action in the service's own RequestManager, the service performs a restart. Techincal Detail ================ -This system was achieved by implementing two classes, :py:class:`primaite.simulator.core.Action`, and :py:class:`primaite.simulator.core.ActionManager`. +This system was achieved by implementing two classes, :py:class:`primaite.simulator.core.Action`, and :py:class:`primaite.simulator.core.RequestManager`. Action ------ -The ``Action`` object stores a reference to a method that performs the action, for example a node could have an action that stores a reference to ``self.turn_on()``. Techincally, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using ``lambda`` functions within a component's ``self._init_action_manager()`` method. Optionally, the ``Action`` object can also hold a validator that will permit/deny the action depending on context. +The ``Action`` object stores a reference to a method that performs the action, for example a node could have an action that stores a reference to ``self.turn_on()``. Techincally, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using ``lambda`` functions within a component's ``self._init_request_manager()`` method. Optionally, the ``Action`` object can also hold a validator that will permit/deny the action depending on context. -ActionManager +RequestManager ------------- -The ``ActionManager`` object stores a mapping between strings and actions. It is responsible for processing the ``request`` and passing it down the ownership tree. Techincally, the ``ActionManager`` is itself a callable that accepts `request, context` tuple, and so it can be chained with other action managers. +The ``RequestManager`` object stores a mapping between strings and actions. It is responsible for processing the ``request`` and passing it down the ownership tree. Techincally, the ``RequestManager`` is itself a callable that accepts `request, context` tuple, and so it can be chained with other action managers. A simple example without chaining can be seen in the :py:class:`primaite.simulator.file_system.file_system.File` class. @@ -48,18 +48,18 @@ A simple example without chaining can be seen in the :py:class:`primaite.simulat class File(FileSystemItemABC): ... - def _init_action_manager(self): + def _init_request_manager(self): ... - action_manager.add_action("scan", Action(func=lambda request, context: self.scan())) - action_manager.add_action("repair", Action(func=lambda request, context: self.repair())) - action_manager.add_action("restore", Action(func=lambda request, context: self.restore())) + request_manager.add_action("scan", Action(func=lambda request, context: self.scan())) + request_manager.add_action("repair", Action(func=lambda request, context: self.repair())) + request_manager.add_action("restore", Action(func=lambda request, context: self.restore())) *ellipses (``...``) used to omit code impertinent to this explanation* -Chaining ActionManagers +Chaining RequestManagers ----------------------- -Since the method for performing an action needs to accept `request, context` as parameters, and ActionManager itself is a callable that accepts `request, context` as parameters, it possible to use ActionManager as an action. In fact, that is how PrimAITE deals with traversing the ownership tree. Each time an ActionManager accepts a request, it pops the first elements and uses it to decide to which Action it should send the remaining request. However, the Action could have another ActionManager as it's function, therefore the request will be routed again. Each time the request is passed to a new action manager, the first element is popped. +Since the method for performing an action needs to accept `request, context` as parameters, and RequestManager itself is a callable that accepts `request, context` as parameters, it possible to use RequestManager as an action. In fact, that is how PrimAITE deals with traversing the ownership tree. Each time an RequestManager accepts a request, it pops the first elements and uses it to decide to which Action it should send the remaining request. However, the Action could have another RequestManager as it's function, therefore the request will be routed again. Each time the request is passed to a new action manager, the first element is popped. An example of how this works is in the :py:class:`primaite.simulator.network.hardware.base.Node` class. @@ -67,22 +67,22 @@ An example of how this works is in the :py:class:`primaite.simulator.network.har class Node(SimComponent): ... - def _init_action_manager(self): + def _init_request_manager(self): ... # a regular action which is processed by the Node itself - action_manager.add_action("turn_on", Action(func=lambda request, context: self.turn_on())) + request_manager.add_action("turn_on", Action(func=lambda request, context: self.turn_on())) # if the Node receives a request where the first word is 'service', it will use a dummy manager - # called self._service_action_manager to pass on the reqeust to the relevant service. This dummy + # called self._service_request_manager to pass on the reqeust to the relevant service. This dummy # manager is simply here to map the service UUID that that service's own action manager. This is # done because the next string after "service" is always the uuid of that service, so we need an - # actionmanager to pop that string before sending it onto the relevant service's ActionManager. - self._service_action_manager = ActionManager() - action_manager.add_action("service", Action(func=self._service_action_manager)) + # RequestManager to pop that string before sending it onto the relevant service's RequestManager. + self._service_request_manager = RequestManager() + request_manager.add_action("service", Action(func=self._service_request_manager)) ... def install_service(self, service): self.services[service.uuid] = service ... # Here, the service UUID is registered to allow passing actions between the node and the service. - self._service_action_manager.add_action(service.uuid, Action(func=service._action_manager)) + self._service_request_manager.add_action(service.uuid, Action(func=service._request_manager)) diff --git a/docs/source/simulation_structure.rst b/docs/source/simulation_structure.rst index f3ef866c..20d2d2d3 100644 --- a/docs/source/simulation_structure.rst +++ b/docs/source/simulation_structure.rst @@ -42,15 +42,15 @@ snippet demonstrates usage of the ``ActionPermissionValidator``. .. code:: python - from primaite.simulator.core import Action, ActionManager, SimComponent + from primaite.simulator.core import Action, RequestManager, SimComponent from primaite.simulator.domain.controller import AccountGroup, GroupMembershipValidator class Smartphone(SimComponent): name: str apps = [] - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() am.add_action( "reset_factory_settings", Action( diff --git a/src/primaite/notebooks/scratch.ipynb b/src/primaite/notebooks/scratch.ipynb index 1b94c5e4..4e873460 100644 --- a/src/primaite/notebooks/scratch.ipynb +++ b/src/primaite/notebooks/scratch.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -13,27 +13,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-09-19 12:47:23,225: Added node d3242ce1-43b7-40b7-86f3-f0473f1bbaec to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,227: Added node 67a2f88b-448c-416d-9fbd-02629347aabd to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,232: Added node 8d69c19e-69ad-41bd-9525-bdefb680a9e2 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,237: Added node c29ebde3-9748-4a97-b8a0-1673cbd53b62 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,248: Added node f734ac26-40b3-4380-ad37-f8782202a628 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,256: Added node 23785fbc-7d27-4697-bd06-937fcbb63e87 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,262: Added node 1ceaff86-bccd-4a06-81e0-0c616c803eab to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,356: Added node 854b2562-1dc2-4dd4-9e50-8f079ba2971c to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,371: Added node 211e8c06-b3f9-48f1-9627-62a7e81e34d3 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,376: Added node b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,380::ERROR::primaite.simulator.network.hardware.base::175::NIC 84:42:75:c8:10:28/192.168.10.110 cannot be enabled as it is not connected to a Link\n" - ] - } - ], + "outputs": [], "source": [ "net = arcd_uc2_network()" ] @@ -47,7 +29,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -56,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -65,7 +47,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -74,335 +56,20 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-09-19 12:47:26,764: Added service 6a8c0179-3ea6-48c1-bc97-259bb5853118 to node 1ceaff86-bccd-4a06-81e0-0c616c803eab\n" - ] - } - ], + "outputs": [], "source": [ "db_serv.install_service(db_svc)" ] }, { "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'uuid': '1ceaff86-bccd-4a06-81e0-0c616c803eab',\n", - " 'hostname': 'database_server',\n", - " 'operating_state': 1,\n", - " 'NICs': {'4b53abce-74ca-4015-868e-3c7dc2f29117': {'uuid': '4b53abce-74ca-4015-868e-3c7dc2f29117',\n", - " 'ip_adress': '192.168.1.14',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'mac_address': '7b:9e:4e:29:2b:ca',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'wake_on_lan': False,\n", - " 'enabled': True}},\n", - " 'file_system': {'uuid': '0b831f3b-a3df-40cc-ab5b-21a3f22f4b68',\n", - " 'folders': {'root': {'uuid': 'a388f22b-0a4d-465d-b5f6-e98ff9564483',\n", - " 'name': 'root',\n", - " 'files': {},\n", - " 'is_quarantined': False},\n", - " 'database': {'uuid': 'c13d8734-9e01-42f6-84d7-4ea36424663d',\n", - " 'name': 'database',\n", - " 'files': {'database.db': {'uuid': '213ed482-6028-44ff-a6ab-45e5800ac1a1',\n", - " 'name': 'database.db',\n", - " 'size': 12288,\n", - " 'file_type': 'DB'}},\n", - " 'is_quarantined': False}}},\n", - " 'applications': {},\n", - " 'services': {'6a8c0179-3ea6-48c1-bc97-259bb5853118': {'uuid': '6a8c0179-3ea6-48c1-bc97-259bb5853118',\n", - " 'health_state': 'GOOD',\n", - " 'health_state_red_view': 'GOOD',\n", - " 'criticality': 'LOWEST',\n", - " 'patching_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 1,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 5432,\n", - " 'operating_state': 'STOPPED'}},\n", - " 'process': {}}" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "db_serv.describe_state()" - ] - }, - { - "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "act_tree = net._action_manager.get_action_tree()" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "175" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(act_tree)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'cbb4c7b4-d218-41e0-a871-64cf087afbbf', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'cbb4c7b4-d218-41e0-a871-64cf087afbbf', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'b26668a8-3ac4-4a0f-8c85-f7776d773f4b', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'b26668a8-3ac4-4a0f-8c85-f7776d773f4b', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '2cb97c78-2819-48be-8ab1-a938c67731e7', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '2cb97c78-2819-48be-8ab1-a938c67731e7', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'af5fd9d3-de73-4595-a3c5-c79530415a82', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'af5fd9d3-de73-4595-a3c5-c79530415a82', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '5c9195e7-82f9-4486-9747-162fbcc31f93', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '5c9195e7-82f9-4486-9747-162fbcc31f93', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'scan'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'checkhash'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'repair'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'restore'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'delete'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'corrupt'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'scan'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'shutdown'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'startup'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'reset'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'logon'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'logoff'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'acl', 'add_rule'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'acl', 'remove_rule'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'scan'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'checkhash'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'repair'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'restore'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'delete'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'corrupt'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'scan'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'shutdown'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'startup'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'reset'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'logon'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'logoff'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'scan'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'checkhash'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'repair'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'restore'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'delete'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'corrupt'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'scan'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'shutdown'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'startup'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'reset'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'logon'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'logoff'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'nic', '77c037a4-5d66-4275-b34a-3690f0df1fb3', 'enable'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'nic', '77c037a4-5d66-4275-b34a-3690f0df1fb3', 'disable'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'scan'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'checkhash'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'repair'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'restore'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'delete'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'corrupt'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'scan'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'shutdown'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'startup'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'reset'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'logon'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'logoff'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'nic', 'b6bb225c-5782-4374-8e9c-f8ae611c6300', 'enable'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'nic', 'b6bb225c-5782-4374-8e9c-f8ae611c6300', 'disable'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'scan'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'checkhash'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'repair'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'restore'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'delete'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'corrupt'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'scan'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'shutdown'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'startup'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'reset'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'logon'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'logoff'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'nic', 'b6b13073-88ff-4153-ac3d-89475aaa8974', 'enable'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'nic', 'b6b13073-88ff-4153-ac3d-89475aaa8974', 'disable'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'scan'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'checkhash'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'repair'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'restore'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'delete'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'corrupt'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'scan'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'shutdown'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'startup'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'reset'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'logon'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'logoff'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'compromise'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'stop'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'start'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'pause'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'resume'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'restart'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'disable'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'enable'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'nic', '4b53abce-74ca-4015-868e-3c7dc2f29117', 'enable'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'nic', '4b53abce-74ca-4015-868e-3c7dc2f29117', 'disable'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'checkhash'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'repair'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'restore'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'delete'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'corrupt'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'checkhash'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'repair'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'restore'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'delete'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'corrupt'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'checkhash'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'delete'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'repair'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'restore'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'corrupt'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'checkhash'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'delete'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'repair'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'restore'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'corrupt'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'shutdown'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'startup'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'reset'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'logon'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'logoff'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'nic', '229b368c-55f5-463b-bafc-d6a804aa0e85', 'enable'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'nic', '229b368c-55f5-463b-bafc-d6a804aa0e85', 'disable'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'scan'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'checkhash'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'repair'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'restore'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'delete'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'corrupt'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'scan'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'shutdown'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'startup'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'reset'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'logon'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'logoff'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'nic', 'e291339e-d212-4807-b475-e779042de3f5', 'enable'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'nic', 'e291339e-d212-4807-b475-e779042de3f5', 'disable'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'scan'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'checkhash'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'repair'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'restore'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'delete'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'corrupt'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'scan'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'shutdown'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'startup'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'reset'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'logon'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'logoff'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '2b2a29e6-f56f-4328-9376-34d0cdb30d8d', 'enable'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '2b2a29e6-f56f-4328-9376-34d0cdb30d8d', 'disable'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '3b2d0133-9fa0-4872-a449-9f2bb0337b49', 'enable'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '3b2d0133-9fa0-4872-a449-9f2bb0337b49', 'disable'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'scan'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'checkhash'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'repair'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'restore'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'delete'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'corrupt'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'scan'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'shutdown'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'startup'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'reset'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'logon'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'logoff']]\n" - ] - } - ], - "source": [ - "print(act_tree)" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'cbb4c7b4-d218-41e0-a871-64cf087afbbf', 'enable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'cbb4c7b4-d218-41e0-a871-64cf087afbbf', 'disable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'b26668a8-3ac4-4a0f-8c85-f7776d773f4b', 'enable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'b26668a8-3ac4-4a0f-8c85-f7776d773f4b', 'disable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '2cb97c78-2819-48be-8ab1-a938c67731e7', 'enable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '2cb97c78-2819-48be-8ab1-a938c67731e7', 'disable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'af5fd9d3-de73-4595-a3c5-c79530415a82', 'enable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'af5fd9d3-de73-4595-a3c5-c79530415a82', 'disable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '5c9195e7-82f9-4486-9747-162fbcc31f93', 'enable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '5c9195e7-82f9-4486-9747-162fbcc31f93', 'disable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'scan']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'checkhash']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'repair']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'restore']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'delete']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'corrupt']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'scan']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'shutdown']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'startup']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'reset']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'logon']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'logoff']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'acl', 'add_rule']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'acl', 'remove_rule']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'scan']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'checkhash']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'repair']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'restore']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'delete']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'corrupt']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'scan']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'shutdown']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'startup']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'reset']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'logon']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'logoff']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'scan']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'checkhash']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'repair']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'restore']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'delete']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'corrupt']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'scan']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'shutdown']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'startup']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'reset']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'logon']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'logoff']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'nic', '77c037a4-5d66-4275-b34a-3690f0df1fb3', 'enable']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'nic', '77c037a4-5d66-4275-b34a-3690f0df1fb3', 'disable']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'scan']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'checkhash']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'repair']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'restore']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'delete']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'corrupt']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'scan']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'shutdown']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'startup']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'reset']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'logon']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'logoff']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'nic', 'b6bb225c-5782-4374-8e9c-f8ae611c6300', 'enable']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'nic', 'b6bb225c-5782-4374-8e9c-f8ae611c6300', 'disable']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'scan']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'checkhash']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'repair']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'restore']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'delete']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'corrupt']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'scan']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'shutdown']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'startup']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'reset']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'logon']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'logoff']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'nic', 'b6b13073-88ff-4153-ac3d-89475aaa8974', 'enable']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'nic', 'b6b13073-88ff-4153-ac3d-89475aaa8974', 'disable']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'scan']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'checkhash']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'repair']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'restore']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'delete']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'corrupt']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'scan']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'shutdown']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'startup']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'reset']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'logon']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'logoff']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'compromise']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'scan']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'stop']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'start']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'pause']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'resume']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'restart']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'disable']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'enable']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'nic', '4b53abce-74ca-4015-868e-3c7dc2f29117', 'enable']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'nic', '4b53abce-74ca-4015-868e-3c7dc2f29117', 'disable']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'scan']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'checkhash']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'repair']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'restore']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'delete']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'corrupt']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'scan']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'checkhash']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'repair']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'restore']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'delete']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'corrupt']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'scan']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'checkhash']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'delete']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'repair']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'restore']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'corrupt']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'scan']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'checkhash']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'delete']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'repair']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'restore']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'corrupt']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'scan']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'shutdown']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'startup']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'reset']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'logon']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'logoff']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'nic', '229b368c-55f5-463b-bafc-d6a804aa0e85', 'enable']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'nic', '229b368c-55f5-463b-bafc-d6a804aa0e85', 'disable']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'scan']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'checkhash']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'repair']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'restore']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'delete']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'corrupt']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'scan']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'shutdown']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'startup']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'reset']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'logon']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'logoff']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'nic', 'e291339e-d212-4807-b475-e779042de3f5', 'enable']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'nic', 'e291339e-d212-4807-b475-e779042de3f5', 'disable']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'scan']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'checkhash']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'repair']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'restore']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'delete']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'corrupt']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'scan']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'shutdown']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'startup']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'reset']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'logon']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'logoff']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '2b2a29e6-f56f-4328-9376-34d0cdb30d8d', 'enable']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '2b2a29e6-f56f-4328-9376-34d0cdb30d8d', 'disable']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '3b2d0133-9fa0-4872-a449-9f2bb0337b49', 'enable']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '3b2d0133-9fa0-4872-a449-9f2bb0337b49', 'disable']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'scan']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'checkhash']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'repair']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'restore']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'delete']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'corrupt']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'scan']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'shutdown']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'startup']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'reset']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'logon']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'logoff']\n" - ] - } - ], - "source": [ - "for a in act_tree:\n", - " print(a)\n", - "# simController.apply_action(\n", - "# {\n", - "# 'network':'', \n", - "# 'node': '26e189bb-442e-4f73-ab7a-1c4dd162e986', \n", - "# 'nic': 'eb6dfd45-d688-47cf-b061-5f45820a6bc7', \n", - "# 'verb': 'enable', \n", - "# 'options':{'...':'...'}\n", - "# })\n", - "\n", - "# a = {\n", - "# 'target_type': 'network',\n", - "# 'target_options': {\n", - "# 'identifier': '',\n", - "# 'target_type': '',\n", - "# 'target_options': {\n", - "# 'identifier': '',\n", - " \n", - "# }\n", - "# }\n", - "# }\n", - "# # ^ do something like this where the requests are k:v pairs instead, have a simple/similar approach " + "db_serv.describe_state()" ] }, { diff --git a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb index a2e1550c..d9742b50 100644 --- a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb +++ b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -36,24 +36,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'uuid': '2ef348c6-32e5-4c5c-83b7-3b82d0b6123b',\n", - " 'network': {'uuid': 'dd2d1a02-d461-4505-8bbd-fd0681750175',\n", - " 'nodes': {},\n", - " 'links': {}},\n", - " 'domain': {'uuid': 'ae0423ee-51fa-41e7-be80-c642b39707f6', 'accounts': {}}}" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_sim = Simulation()\n", "net = my_sim.network\n", @@ -69,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -78,7 +63,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -97,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -106,20 +91,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-08-24 13:06:28,617: NIC cc:be:ec:43:a6:4c/130.1.1.1 connected to Link cc:be:ec:43:a6:4c/130.1.1.1<-->79:2b:4a:70:c3:50\n", - "2023-08-24 13:06:28,618: SwitchPort 79:2b:4a:70:c3:50 connected to Link cc:be:ec:43:a6:4c/130.1.1.1<-->79:2b:4a:70:c3:50\n", - "2023-08-24 13:06:28,619: NIC c2:1e:48:e1:a4:ad/130.1.1.2 connected to Link c2:1e:48:e1:a4:ad/130.1.1.2<-->1a:2d:12:38:80:2f\n", - "2023-08-24 13:06:28,620: SwitchPort 1a:2d:12:38:80:2f connected to Link c2:1e:48:e1:a4:ad/130.1.1.2<-->1a:2d:12:38:80:2f\n" - ] - } - ], + "outputs": [], "source": [ "my_swtich = Switch(hostname=\"switch1\", num_ports=12)\n", "net.add_node(my_swtich)\n", @@ -145,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -155,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -165,20 +139,9 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "File(uuid='7d56a563-ecc0-4011-8c97-240dd6c885c0', name='favicon.ico', size=40.0, file_type=, action_manager=None)" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_server_folder = my_server.file_system.create_folder(\"static\")\n", "my_server.file_system.create_file(\"favicon.ico\", file_type=FileType.PNG)" @@ -193,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -209,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -218,7 +181,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -234,7 +197,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -243,7 +206,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -260,193 +223,18 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'uuid': '2ef348c6-32e5-4c5c-83b7-3b82d0b6123b',\n", - " 'network': {'uuid': 'dd2d1a02-d461-4505-8bbd-fd0681750175',\n", - " 'nodes': {'2f03b32b-7290-4921-8670-faebe4a19d63': {'uuid': '2f03b32b-7290-4921-8670-faebe4a19d63',\n", - " 'hostname': 'primaite_pc',\n", - " 'operating_state': 0,\n", - " 'NICs': {'e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b': {'uuid': 'e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b',\n", - " 'ip_adress': '130.1.1.1',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'gateway': '130.1.1.255',\n", - " 'mac_address': 'cc:be:ec:43:a6:4c',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'wake_on_lan': False,\n", - " 'dns_servers': [],\n", - " 'enabled': False}},\n", - " 'file_system': {'uuid': '0b7206af-3e0a-41b0-8115-ae9e0dbbcd81',\n", - " 'folders': {'c161bc7c-9abd-4666-9b49-2745fdb65ebe': {'uuid': 'c161bc7c-9abd-4666-9b49-2745fdb65ebe',\n", - " 'name': 'downloads',\n", - " 'size': 1000.0,\n", - " 'files': {'f807d777-d167-4f37-9f9b-ced634af6ed5': {'uuid': 'f807d777-d167-4f37-9f9b-ced634af6ed5',\n", - " 'name': 'firefox_installer.zip',\n", - " 'size': 1000.0,\n", - " 'file_type': 'ZIP'}},\n", - " 'is_quarantined': False}}},\n", - " 'applications': {'ea466b2f-1ed5-49fd-9579-44852bff684d': {'uuid': 'ea466b2f-1ed5-49fd-9579-44852bff684d',\n", - " 'health_state': 'GOOD',\n", - " 'health_state_red_view': 'GOOD',\n", - " 'criticality': 'MEDIUM',\n", - " 'patching_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 1,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'ports': ['HTTP'],\n", - " 'opearting_state': 'RUNNING',\n", - " 'execution_control_status': 'manual',\n", - " 'num_executions': 0,\n", - " 'groups': []}},\n", - " 'services': {},\n", - " 'process': {}},\n", - " 'e9afc0bc-fb21-48a3-9868-2ede6a3181dc': {'uuid': 'e9afc0bc-fb21-48a3-9868-2ede6a3181dc',\n", - " 'hostname': 'google_server',\n", - " 'operating_state': 0,\n", - " 'NICs': {'956ce240-8fb3-4fde-8635-ac4ea601a582': {'uuid': '956ce240-8fb3-4fde-8635-ac4ea601a582',\n", - " 'ip_adress': '130.1.1.2',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'gateway': '130.1.1.255',\n", - " 'mac_address': 'c2:1e:48:e1:a4:ad',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'wake_on_lan': False,\n", - " 'dns_servers': [],\n", - " 'enabled': False}},\n", - " 'file_system': {'uuid': 'c3f99c30-b493-4fb6-b13e-d2005d851b59',\n", - " 'folders': {'869eda49-21f2-4fc1-8681-78725cdd5c70': {'uuid': '869eda49-21f2-4fc1-8681-78725cdd5c70',\n", - " 'name': 'static',\n", - " 'size': 0,\n", - " 'files': {},\n", - " 'is_quarantined': False},\n", - " '9fbe0e41-0d6a-4142-9c73-9c0de2dbde6e': {'uuid': '9fbe0e41-0d6a-4142-9c73-9c0de2dbde6e',\n", - " 'name': 'root',\n", - " 'size': 40.0,\n", - " 'files': {'7d56a563-ecc0-4011-8c97-240dd6c885c0': {'uuid': '7d56a563-ecc0-4011-8c97-240dd6c885c0',\n", - " 'name': 'favicon.ico',\n", - " 'size': 40.0,\n", - " 'file_type': 'PNG'}},\n", - " 'is_quarantined': False}}},\n", - " 'applications': {},\n", - " 'services': {},\n", - " 'process': {}},\n", - " '47814452-ef47-4e6b-9087-796c438d4698': {'uuid': '47814452-ef47-4e6b-9087-796c438d4698',\n", - " 'num_ports': 12,\n", - " 'ports': {1: {'uuid': 'b76fe86f-bb92-4346-8e83-217a2fb0bc67',\n", - " 'mac_address': '79:2b:4a:70:c3:50',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 2: {'uuid': '6f8fc6e7-76a4-441a-b7af-441edbdcc6ac',\n", - " 'mac_address': '1a:2d:12:38:80:2f',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 3: {'uuid': '1aa75a3c-01f1-4293-9894-5396fa412690',\n", - " 'mac_address': 'd1:7b:36:c1:82:c1',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 4: {'uuid': 'fe6c9f44-59d5-403e-973a-6f19fce7b9b9',\n", - " 'mac_address': 'e3:6b:cc:0c:98:9b',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 5: {'uuid': 'e9e83e37-8537-4884-98a6-87017540078f',\n", - " 'mac_address': '32:09:c0:4a:f1:20',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 6: {'uuid': '747f2cd3-8902-4da8-8829-b0b53fe79735',\n", - " 'mac_address': 'e8:20:0b:04:b8:76',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 7: {'uuid': '88ed129e-0ddb-4d29-ba3c-58d81efe240e',\n", - " 'mac_address': '7f:b4:f4:2e:b6:71',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 8: {'uuid': '6c1a4c3c-25d8-46f6-98a8-54073d0ca0d3',\n", - " 'mac_address': 'f6:22:2d:24:b9:71',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 9: {'uuid': 'b2bfc006-6a6b-4701-a75a-27954592d429',\n", - " 'mac_address': 'b6:a5:92:a5:aa:1b',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 10: {'uuid': '3c607386-87a2-4d0b-ac04-449416ca5b1f',\n", - " 'mac_address': 'b3:75:7d:ce:88:0a',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 11: {'uuid': '590002c8-27fa-4c31-b17b-7b89dbf8cdf8',\n", - " 'mac_address': 'c0:25:a6:64:52:8e',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 12: {'uuid': 'b7e25eed-547a-4c17-8cb9-8b976ce4bbd9',\n", - " 'mac_address': '98:50:96:47:ca:bc',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False}},\n", - " 'mac_address_table': {}}},\n", - " 'links': {'a51a4435-20ae-43cf-a151-26e824968b3d': {'uuid': 'a51a4435-20ae-43cf-a151-26e824968b3d',\n", - " 'endpoint_a': 'e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b',\n", - " 'endpoint_b': 'b76fe86f-bb92-4346-8e83-217a2fb0bc67',\n", - " 'bandwidth': 100.0,\n", - " 'current_load': 0.0},\n", - " 'ae3486e5-f78e-4092-96d1-d7e8176f2b7d': {'uuid': 'ae3486e5-f78e-4092-96d1-d7e8176f2b7d',\n", - " 'endpoint_a': '956ce240-8fb3-4fde-8635-ac4ea601a582',\n", - " 'endpoint_b': '6f8fc6e7-76a4-441a-b7af-441edbdcc6ac',\n", - " 'bandwidth': 100.0,\n", - " 'current_load': 0.0}}},\n", - " 'domain': {'uuid': 'ae0423ee-51fa-41e7-be80-c642b39707f6',\n", - " 'accounts': {'917eda28-9a67-4449-bddd-87e2141a3162': {'uuid': '917eda28-9a67-4449-bddd-87e2141a3162',\n", - " 'num_logons': 0,\n", - " 'num_logoffs': 0,\n", - " 'num_group_changes': 0,\n", - " 'username': 'admin',\n", - " 'password': 'admin12',\n", - " 'account_type': 'USER',\n", - " 'enabled': True}}}}" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_sim.describe_state()" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'{\"uuid\": \"2ef348c6-32e5-4c5c-83b7-3b82d0b6123b\", \"network\": {\"uuid\": \"dd2d1a02-d461-4505-8bbd-fd0681750175\", \"nodes\": {\"2f03b32b-7290-4921-8670-faebe4a19d63\": {\"uuid\": \"2f03b32b-7290-4921-8670-faebe4a19d63\", \"hostname\": \"primaite_pc\", \"operating_state\": 0, \"NICs\": {\"e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b\": {\"uuid\": \"e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b\", \"ip_adress\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"cc:be:ec:43:a6:4c\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"0b7206af-3e0a-41b0-8115-ae9e0dbbcd81\", \"folders\": {\"c161bc7c-9abd-4666-9b49-2745fdb65ebe\": {\"uuid\": \"c161bc7c-9abd-4666-9b49-2745fdb65ebe\", \"name\": \"downloads\", \"size\": 1000.0, \"files\": {\"f807d777-d167-4f37-9f9b-ced634af6ed5\": {\"uuid\": \"f807d777-d167-4f37-9f9b-ced634af6ed5\", \"name\": \"firefox_installer.zip\", \"size\": 1000.0, \"file_type\": \"ZIP\"}}, \"is_quarantined\": false}}}, \"applications\": {\"ea466b2f-1ed5-49fd-9579-44852bff684d\": {\"uuid\": \"ea466b2f-1ed5-49fd-9579-44852bff684d\", \"health_state\": \"GOOD\", \"health_state_red_view\": \"GOOD\", \"criticality\": \"MEDIUM\", \"patching_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 1, \"tcp\": true, \"udp\": true, \"ports\": [\"HTTP\"], \"opearting_state\": \"RUNNING\", \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {}, \"process\": {}}, \"e9afc0bc-fb21-48a3-9868-2ede6a3181dc\": {\"uuid\": \"e9afc0bc-fb21-48a3-9868-2ede6a3181dc\", \"hostname\": \"google_server\", \"operating_state\": 0, \"NICs\": {\"956ce240-8fb3-4fde-8635-ac4ea601a582\": {\"uuid\": \"956ce240-8fb3-4fde-8635-ac4ea601a582\", \"ip_adress\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"c2:1e:48:e1:a4:ad\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"c3f99c30-b493-4fb6-b13e-d2005d851b59\", \"folders\": {\"869eda49-21f2-4fc1-8681-78725cdd5c70\": {\"uuid\": \"869eda49-21f2-4fc1-8681-78725cdd5c70\", \"name\": \"static\", \"size\": 0, \"files\": {}, \"is_quarantined\": false}, \"9fbe0e41-0d6a-4142-9c73-9c0de2dbde6e\": {\"uuid\": \"9fbe0e41-0d6a-4142-9c73-9c0de2dbde6e\", \"name\": \"root\", \"size\": 40.0, \"files\": {\"7d56a563-ecc0-4011-8c97-240dd6c885c0\": {\"uuid\": \"7d56a563-ecc0-4011-8c97-240dd6c885c0\", \"name\": \"favicon.ico\", \"size\": 40.0, \"file_type\": \"PNG\"}}, \"is_quarantined\": false}}}, \"applications\": {}, \"services\": {}, \"process\": {}}, \"47814452-ef47-4e6b-9087-796c438d4698\": {\"uuid\": \"47814452-ef47-4e6b-9087-796c438d4698\", \"num_ports\": 12, \"ports\": {\"1\": {\"uuid\": \"b76fe86f-bb92-4346-8e83-217a2fb0bc67\", \"mac_address\": \"79:2b:4a:70:c3:50\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"2\": {\"uuid\": \"6f8fc6e7-76a4-441a-b7af-441edbdcc6ac\", \"mac_address\": \"1a:2d:12:38:80:2f\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"3\": {\"uuid\": \"1aa75a3c-01f1-4293-9894-5396fa412690\", \"mac_address\": \"d1:7b:36:c1:82:c1\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"4\": {\"uuid\": \"fe6c9f44-59d5-403e-973a-6f19fce7b9b9\", \"mac_address\": \"e3:6b:cc:0c:98:9b\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"5\": {\"uuid\": \"e9e83e37-8537-4884-98a6-87017540078f\", \"mac_address\": \"32:09:c0:4a:f1:20\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"6\": {\"uuid\": \"747f2cd3-8902-4da8-8829-b0b53fe79735\", \"mac_address\": \"e8:20:0b:04:b8:76\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"7\": {\"uuid\": \"88ed129e-0ddb-4d29-ba3c-58d81efe240e\", \"mac_address\": \"7f:b4:f4:2e:b6:71\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"8\": {\"uuid\": \"6c1a4c3c-25d8-46f6-98a8-54073d0ca0d3\", \"mac_address\": \"f6:22:2d:24:b9:71\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"9\": {\"uuid\": \"b2bfc006-6a6b-4701-a75a-27954592d429\", \"mac_address\": \"b6:a5:92:a5:aa:1b\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"10\": {\"uuid\": \"3c607386-87a2-4d0b-ac04-449416ca5b1f\", \"mac_address\": \"b3:75:7d:ce:88:0a\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"11\": {\"uuid\": \"590002c8-27fa-4c31-b17b-7b89dbf8cdf8\", \"mac_address\": \"c0:25:a6:64:52:8e\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"12\": {\"uuid\": \"b7e25eed-547a-4c17-8cb9-8b976ce4bbd9\", \"mac_address\": \"98:50:96:47:ca:bc\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}}, \"mac_address_table\": {}}}, \"links\": {\"a51a4435-20ae-43cf-a151-26e824968b3d\": {\"uuid\": \"a51a4435-20ae-43cf-a151-26e824968b3d\", \"endpoint_a\": \"e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b\", \"endpoint_b\": \"b76fe86f-bb92-4346-8e83-217a2fb0bc67\", \"bandwidth\": 100.0, \"current_load\": 0.0}, \"ae3486e5-f78e-4092-96d1-d7e8176f2b7d\": {\"uuid\": \"ae3486e5-f78e-4092-96d1-d7e8176f2b7d\", \"endpoint_a\": \"956ce240-8fb3-4fde-8635-ac4ea601a582\", \"endpoint_b\": \"6f8fc6e7-76a4-441a-b7af-441edbdcc6ac\", \"bandwidth\": 100.0, \"current_load\": 0.0}}}, \"domain\": {\"uuid\": \"ae0423ee-51fa-41e7-be80-c642b39707f6\", \"accounts\": {\"917eda28-9a67-4449-bddd-87e2141a3162\": {\"uuid\": \"917eda28-9a67-4449-bddd-87e2141a3162\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": \"USER\", \"enabled\": true}}}}'" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import json\n", "json.dumps(my_sim.describe_state())" diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index a292be18..914b798e 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -11,9 +11,9 @@ from primaite import getLogger _LOGGER = getLogger(__name__) -class ActionPermissionValidator(BaseModel): +class RequestPermissionValidator(BaseModel): """ - Base class for action validators. + Base class for request validators. The permissions manager is designed to be generic. So, although in the first instance the permissions are evaluated purely on membership to AccountGroup, this class can support validating permissions based on any @@ -22,130 +22,127 @@ class ActionPermissionValidator(BaseModel): @abstractmethod def __call__(self, request: List[str], context: Dict) -> bool: - """Use the request and context paramters to decide whether the action should be permitted.""" + """Use the request and context paramters to decide whether the request should be permitted.""" pass -class AllowAllValidator(ActionPermissionValidator): - """Always allows the action.""" +class AllowAllValidator(RequestPermissionValidator): + """Always allows the request.""" def __call__(self, request: List[str], context: Dict) -> bool: - """Always allow the action.""" + """Always allow the request.""" return True -class Action(BaseModel): +class RequestType(BaseModel): """ - This object stores data related to a single action. + This object stores data related to a single request type. - This includes the callable that can execute the action request, and the validator that will decide whether - the action can be performed or not. + This includes the callable that can execute the request, and the validator that will decide whether + the request can be performed or not. """ func: Callable[[List[str], Dict], None] """ ``func`` is a function that accepts a request and a context dict. Typically this would be a lambda function - that invokes a class method of your SimComponent. For example if the component is a node and the action is for + that invokes a class method of your SimComponent. For example if the component is a node and the request type is for turning it off, then the SimComponent should have a turn_off(self) method that does not need to accept any args. - Then, this Action will be given something like ``func = lambda request, context: self.turn_off()``. + Then, this request will be given something like ``func = lambda request, context: self.turn_off()``. - ``func`` can also be another action manager, since ActionManager is a callable with a signature that matches what is + ``func`` can also be another request manager, since RequestManager is a callable with a signature that matches what is expected by ``func``. """ - validator: ActionPermissionValidator = AllowAllValidator() + validator: RequestPermissionValidator = AllowAllValidator() """ - ``validator`` is an instance of `ActionPermissionValidator`. This is essentially a callable that + ``validator`` is an instance of ``RequestPermissionValidator``. This is essentially a callable that accepts `request` and `context` and returns a boolean to represent whether the permission is granted to perform - the action. The default validator will allow + the request. The default validator will allow """ -# TODO: maybe this can be renamed to something like action selector? -# Because there are two ways it's used, to select from a list of action verbs, or to select a child object to which to -# forward the request. -class ActionManager(BaseModel): +class RequestManager(BaseModel): """ - ActionManager is used by `SimComponent` instances to keep track of actions. + RequestManager is used by `SimComponent` instances to keep track of requests. - Its main purpose is to be a lookup from action name to action function and corresponding validation function. This - class is responsible for providing a consistent API for processing actions as well as helpful error messages. + Its main purpose is to be a lookup from request name to request function and corresponding validation function. This + class is responsible for providing a consistent API for processing requests as well as helpful error messages. """ - actions: Dict[str, Action] = {} - """maps action verb to an action object.""" + request_types: Dict[str, RequestType] = {} + """maps request name to an RequestType object.""" def __call__(self, request: Callable[[List[str], Dict], None], context: Dict) -> None: """ - Process an action request. + Process an request request. - :param request: A list of strings which specify what action to take. The first string must be one of the allowed - actions, i.e. it must be a key of self.actions. The subsequent strings in the list are passed as parameters - to the action function. + :param request: A list of strings describing the request. The first string must be one of the allowed + request names, i.e. it must be a key of self.request_types. The subsequent strings in the list are passed as + parameters to the request function. :type request: List[str] :param context: Dictionary of additional information necessary to process or validate the request. :type context: Dict - :raises RuntimeError: If the request parameter does not have a valid action identifier as the first item. + :raises RuntimeError: If the request parameter does not have a valid request name as the first item. """ - action_key = request[0] + request_key = request[0] - if action_key not in self.actions: + if request_key not in self.request_types: msg = ( - f"Action request {request} could not be processed because {action_key} is not a valid action", - "within this ActionManager", + f"Request {request} could not be processed because {request_key} is not a valid request name", + "within this RequestManager", ) _LOGGER.error(msg) raise RuntimeError(msg) - action = self.actions[action_key] - action_options = request[1:] + request_type = self.request_types[request_key] + request_options = request[1:] - if not action.validator(action_options, context): - _LOGGER.debug(f"Action request {request} was denied due to insufficient permissions") + if not request_type.validator(request_options, context): + _LOGGER.debug(f"Request {request} was denied due to insufficient permissions") return - action.func(action_options, context) + request_type.func(request_options, context) - def add_action(self, name: str, action: Action) -> None: + def add_request(self, name: str, request_type: RequestType) -> None: """ - Add an action to this action manager. + Add a request type to this request manager. - :param name: The string associated to this action. + :param name: The string associated to this request. :type name: str - :param action: Action object. - :type action: Action + :param request_type: Request type object which contains information about how to resolve request. + :type request_type: RequestType """ - if name in self.actions: - msg = f"Attempted to register an action but the action name {name} is already taken." + if name in self.request_types: + msg = f"Attempted to register a request but the request name {name} is already taken." _LOGGER.error(msg) raise RuntimeError(msg) - self.actions[name] = action + self.request_types[name] = request_type - def remove_action(self, name: str) -> None: + def remove_request(self, name: str) -> None: """ - Remove an action from this manager. + Remove a request from this manager. - :param name: name identifier of the action + :param name: name identifier of the request :type name: str """ - if name not in self.actions: - msg = f"Attempted to remove action {name} from action manager, but it was not registered." + if name not in self.request_types: + msg = f"Attempted to remove request {name} from request manager, but it was not registered." _LOGGER.error(msg) raise RuntimeError(msg) - self.actions.pop(name) + self.request_types.pop(name) - def get_action_tree(self) -> List[List[str]]: - """Recursively generate action tree for this component.""" - actions = [] - for act_name, act in self.actions.items(): - if isinstance(act.func, ActionManager): - sub_actions = act.func.get_action_tree() - sub_actions = [[act_name] + a for a in sub_actions] - actions.extend(sub_actions) + def get_request_types_recursively(self) -> List[List[str]]: + """Recursively generate request tree for this component.""" + requests = [] + for req_name, req in self.request_types.items(): + if isinstance(req.func, RequestManager): + sub_requests = req.func.get_request_types_recursively() + sub_requests = [[req_name] + a for a in sub_requests] + requests.extend(sub_requests) else: - actions.append([act_name]) - return actions + requests.append([req_name]) + return requests class SimComponent(BaseModel): @@ -161,30 +158,30 @@ class SimComponent(BaseModel): if not kwargs.get("uuid"): kwargs["uuid"] = str(uuid4()) super().__init__(**kwargs) - self._action_manager: ActionManager = self._init_action_manager() + self._request_manager: RequestManager = self._init_request_manager() self._parent: Optional["SimComponent"] = None - def _init_action_manager(self) -> ActionManager: + def _init_request_manager(self) -> RequestManager: """ - Initialise the action manager for this component. + Initialise the request manager for this component. - When using a hierarchy of components, the child classes should call the parent class's _init_action_manager and - add additional actions on top of the existing generic ones. + When using a hierarchy of components, the child classes should call the parent class's _init_request_manager and + add additional requests on top of the existing generic ones. Example usage for inherited classes: ..code::python class WebBrowser(Application): - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() # all actions generic to any Application get initialised - am.add_action(...) # initialise any actions specific to the web browser + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() # all requests generic to any Application get initialised + am.add_request(...) # initialise any requests specific to the web browser return am - :return: Actiona manager object belonging to this sim component. - :rtype: ActionManager + :return: Request manager object belonging to this sim component. + :rtype: RequestManager """ - return ActionManager() + return RequestManager() @abstractmethod def describe_state(self) -> Dict: @@ -200,27 +197,27 @@ class SimComponent(BaseModel): } return state - def apply_action(self, action: List[str], context: Dict = {}) -> None: + def apply_request(self, request: List[str], context: Dict = {}) -> None: """ - Apply an action to a simulation component. Action data is passed in as a 'namespaced' list of strings. + Apply a request to a simulation component. Request data is passed in as a 'namespaced' list of strings. - If the list only has one element, the action is intended to be applied directly to this object. If the list has - multiple entries, the action is passed to the child of this object specified by the first one or two entries. + If the list only has one element, the request is intended to be applied directly to this object. If the list has + multiple entries, the request is passed to the child of this object specified by the first one or two entries. This is essentially a namespace. - For example, ["turn_on",] is meant to apply an action of 'turn on' to this component. + For example, ["turn_on",] is meant to apply a request of 'turn on' to this component. However, ["services", "email_client", "turn_on"] is meant to 'turn on' this component's email client service. - :param action: List describing the action to apply to this object. - :type action: List[str] + :param request: List describing the request to apply to this object. + :type request: List[str] - :param: context: Dict containing context for actions + :param: context: Dict containing context for requests :type context: Dict """ - if self._action_manager is None: + if self._request_manager is None: return - self._action_manager(action, context) + self._request_manager(request, context) def apply_timestep(self, timestep: int) -> None: """ diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index cd0fe9de..66900327 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -1,7 +1,7 @@ from enum import Enum from typing import Dict, Final, List, Literal, Tuple -from primaite.simulator.core import Action, ActionManager, ActionPermissionValidator, SimComponent +from primaite.simulator.core import RequestManager, RequestPermissionValidator, RequestType, SimComponent from primaite.simulator.domain.account import Account, AccountType @@ -43,10 +43,10 @@ class AccountGroup(Enum): "For full access" -class GroupMembershipValidator(ActionPermissionValidator): +class GroupMembershipValidator(RequestPermissionValidator): """Permit actions based on group membership.""" - allowed_groups:List[AccountGroup] + allowed_groups: List[AccountGroup] def __call__(self, request: List[str], context: Dict) -> bool: """Permit the action if the request comes from an account which belongs to the right group.""" @@ -79,14 +79,14 @@ class DomainController(SimComponent): def __init__(self, **kwargs): super().__init__(**kwargs) - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() # Action 'account' matches requests like: # ['account', '', *account_action] - am.add_action( + am.add_request( "account", - Action( - func=lambda request, context: self.accounts[request.pop(0)].apply_action(request, context), + RequestType( + func=lambda request, context: self.accounts[request.pop(0)].apply_request(request, context), validator=GroupMembershipValidator(allowed_groups=[AccountGroup.DOMAIN_ADMIN]), ), ) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 8d981100..5da4eca8 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -9,7 +9,7 @@ from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable from primaite import getLogger -from primaite.simulator.core import Action, ActionManager, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file_type import FileType, get_file_type_from_extension from primaite.simulator.system.core.sys_log import SysLog @@ -94,14 +94,14 @@ class FileSystem(SimComponent): if not self.folders: self.create_folder("root") - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() - self._folder_action_manager = ActionManager() - am.add_action("folder", Action(func=self._folder_action_manager)) + self._folder_request_manager = RequestManager() + am.add_request("folder", RequestType(func=self._folder_request_manager)) - self._file_action_manager = ActionManager() - am.add_action("file", Action(func=self._file_action_manager)) + self._file_request_manager = RequestManager() + am.add_request("file", RequestType(func=self._file_request_manager)) return am @@ -165,7 +165,7 @@ class FileSystem(SimComponent): self.folders[folder.uuid] = folder self._folders_by_name[folder.name] = folder self.sys_log.info(f"Created folder /{folder.name}") - self._folder_action_manager.add_action(folder.uuid, Action(func=folder._action_manager)) + self._folder_request_manager.add_request(folder.uuid, RequestType(func=folder._request_manager)) return folder def delete_folder(self, folder_name: str): @@ -184,7 +184,7 @@ class FileSystem(SimComponent): self.folders.pop(folder.uuid) self._folders_by_name.pop(folder.name) self.sys_log.info(f"Deleted folder /{folder.name} and its contents") - self._folder_action_manager.remove_action(folder.uuid) + self._folder_request_manager.remove_request(folder.uuid) else: _LOGGER.debug(f"Cannot delete folder as it does not exist: {folder_name}") @@ -226,7 +226,7 @@ class FileSystem(SimComponent): ) folder.add_file(file) self.sys_log.info(f"Created file /{file.path}") - self._file_action_manager.add_action(file.uuid, Action(func=file._action_manager)) + self._file_request_manager.add_request(file.uuid, RequestType(func=file._request_manager)) return file def get_file(self, folder_name: str, file_name: str) -> Optional[File]: @@ -254,7 +254,7 @@ class FileSystem(SimComponent): file = folder.get_file(file_name) if file: folder.remove_file(file) - self._file_action_manager.remove_action(file.uuid) + self._file_request_manager.remove_request(file.uuid) self.sys_log.info(f"Deleted file /{file.path}") def move_file(self, src_folder_name: str, src_file_name: str, dst_folder_name: str): @@ -332,15 +332,15 @@ class Folder(FileSystemItemABC): is_quarantined: bool = False "Flag that marks the folder as quarantined if true." - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() - am.add_action("scan", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("checkhash", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("repair", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("restore", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("delete", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("corrupt", Action(func=lambda request, context: ...)) # TODO implement action + am.add_request("scan", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("checkhash", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("repair", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("restore", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("delete", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("corrupt", RequestType(func=lambda request, context: ...)) # TODO implement request return am @@ -509,15 +509,15 @@ class File(FileSystemItemABC): with open(self.sim_path, mode="a"): pass - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() - am.add_action("scan", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("checkhash", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("delete", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("repair", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("restore", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("corrupt", Action(func=lambda request, context: ...)) # TODO implement action + am.add_request("scan", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("checkhash", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("delete", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("repair", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("restore", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("corrupt", RequestType(func=lambda request, context: ...)) # TODO implement request return am diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index e0384b5e..bc717641 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -6,7 +6,7 @@ from networkx import MultiGraph from prettytable import MARKDOWN, PrettyTable from primaite import getLogger -from primaite.simulator.core import Action, ActionManager, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import Link, NIC, Node, SwitchPort from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import Router @@ -37,18 +37,18 @@ class Network(SimComponent): Initialise the network. Constructs the network and sets up its initial state including - the action manager and an empty MultiGraph for topology representation. + the request manager and an empty MultiGraph for topology representation. """ super().__init__(**kwargs) self._nx_graph = MultiGraph() - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - self._node_action_manager = ActionManager() - am.add_action( + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() + self._node_request_manager = RequestManager() + am.add_request( "node", - Action(func=self._node_action_manager), + RequestType(func=self._node_request_manager), ) return am @@ -182,7 +182,7 @@ class Network(SimComponent): node.parent = self self._nx_graph.add_node(node.hostname) _LOGGER.info(f"Added node {node.uuid} to Network {self.uuid}") - self._node_action_manager.add_action(name=node.uuid, action=Action(func=node._action_manager)) + self._node_request_manager.add_request(name=node.uuid, request_type=RequestType(func=node._request_manager)) def get_node_by_hostname(self, hostname: str) -> Optional[Node]: """ @@ -216,7 +216,7 @@ class Network(SimComponent): break node.parent = None _LOGGER.info(f"Removed node {node.uuid} from network {self.uuid}") - self._node_action_manager.remove_action(name=node.uuid) + self._node_request_manager.remove_request(name=node.uuid) def connect(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> None: """ diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 2fa917a5..cb3e398b 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -12,7 +12,7 @@ from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.exceptions import NetworkError from primaite.simulator import SIM_OUTPUT -from primaite.simulator.core import Action, ActionManager, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.domain.account import Account from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket @@ -144,11 +144,11 @@ class NIC(SimComponent): ) return state - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() - am.add_action("enable", Action(func=lambda request, context: self.enable())) - am.add_action("disable", Action(func=lambda request, context: self.disable())) + am.add_request("enable", RequestType(func=lambda request, context: self.enable())) + am.add_request("disable", RequestType(func=lambda request, context: self.disable())) return am @@ -946,31 +946,31 @@ class Node(SimComponent): self.session_manager.software_manager = self.software_manager self._install_system_software() - def _init_action_manager(self) -> ActionManager: + def _init_request_manager(self) -> RequestManager: # TODO: I see that this code is really confusing and hard to read right now... I think some of these things will # need a better name and better documentation. - am = super()._init_action_manager() - # since there are potentially many services, create an action manager that can map service name - self._service_action_manager = ActionManager() - am.add_action("service", Action(func=self._service_action_manager)) - self._nic_action_manager = ActionManager() - am.add_action("nic", Action(func=self._nic_action_manager)) + am = super()._init_request_manager() + # since there are potentially many services, create an request manager that can map service name + self._service_request_manager = RequestManager() + am.add_request("service", RequestType(func=self._service_request_manager)) + self._nic_request_manager = RequestManager() + am.add_request("nic", RequestType(func=self._nic_request_manager)) - am.add_action("file_system", Action(func=self.file_system._action_manager)) + am.add_request("file_system", RequestType(func=self.file_system._request_manager)) # currently we don't have any applications nor processes, so these will be empty - self._process_action_manager = ActionManager() - am.add_action("process", Action(func=self._process_action_manager)) - self._application_action_manager = ActionManager() - am.add_action("application", Action(func=self._application_action_manager)) + self._process_request_manager = RequestManager() + am.add_request("process", RequestType(func=self._process_request_manager)) + self._application_request_manager = RequestManager() + am.add_request("application", RequestType(func=self._application_request_manager)) - am.add_action("scan", Action(func=lambda request, context: ...)) # TODO implement OS scan + am.add_request("scan", RequestType(func=lambda request, context: ...)) # TODO implement OS scan - am.add_action("shutdown", Action(func=lambda request, context: self.power_off())) - am.add_action("startup", Action(func=lambda request, context: self.power_on())) - am.add_action("reset", Action(func=lambda request, context: ...)) # TODO implement node reset - am.add_action("logon", Action(func=lambda request, context: ...)) # TODO implement logon action - am.add_action("logoff", Action(func=lambda request, context: ...)) # TODO implement logoff action + am.add_request("shutdown", RequestType(func=lambda request, context: self.power_off())) + am.add_request("startup", RequestType(func=lambda request, context: self.power_on())) + am.add_request("reset", RequestType(func=lambda request, context: ...)) # TODO implement node reset + am.add_request("logon", RequestType(func=lambda request, context: ...)) # TODO implement logon request + am.add_request("logoff", RequestType(func=lambda request, context: ...)) # TODO implement logoff request return am @@ -1071,7 +1071,7 @@ class Node(SimComponent): self.sys_log.info(f"Connected NIC {nic}") if self.operating_state == NodeOperatingState.ON: nic.enable() - self._nic_action_manager.add_action(nic.uuid, Action(func=nic._action_manager)) + self._nic_request_manager.add_request(nic.uuid, RequestType(func=nic._request_manager)) else: msg = f"Cannot connect NIC {nic} as it is already connected" self.sys_log.logger.error(msg) @@ -1096,7 +1096,7 @@ class Node(SimComponent): nic.parent = None nic.disable() self.sys_log.info(f"Disconnected NIC {nic}") - self._nic_action_manager.remove_action(nic.uuid) + self._nic_request_manager.remove_request(nic.uuid) else: msg = f"Cannot disconnect NIC {nic} as it is not connected" self.sys_log.logger.error(msg) @@ -1194,7 +1194,7 @@ class Node(SimComponent): service.install() # Perform any additional setup, such as creating files for this service on the node. self.sys_log.info(f"Installed service {service.name}") _LOGGER.info(f"Added service {service.uuid} to node {self.uuid}") - self._service_action_manager.add_action(service.uuid, Action(func=service._action_manager)) + self._service_request_manager.add_request(service.uuid, RequestType(func=service._request_manager)) def uninstall_service(self, service: Service) -> None: """Uninstall and completely remove service from this node. @@ -1210,7 +1210,7 @@ class Node(SimComponent): service.parent = None self.sys_log.info(f"Uninstalled service {service.name}") _LOGGER.info(f"Removed service {service.uuid} from node {self.uuid}") - self._service_action_manager.remove_action(service.uuid) + self._service_request_manager.remove_request(service.uuid) def __contains__(self, item: Any) -> bool: if isinstance(item, Service): diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 53b9b176..c56bf538 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -7,7 +7,7 @@ from typing import Dict, List, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable -from primaite.simulator.core import Action, ActionManager, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import ARPCache, ICMP, NIC, Node from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol @@ -43,7 +43,7 @@ class ACLRule(SimComponent): def __str__(self) -> str: rule_strings = [] - for key, value in self.model_dump(exclude={"uuid", "action_manager"}).items(): + for key, value in self.model_dump(exclude={"uuid", "request_manager"}).items(): if value is None: value = "ANY" if isinstance(value, Enum): @@ -87,8 +87,8 @@ class AccessControlList(SimComponent): super().__init__(**kwargs) self._acl = [None] * (self.max_acl_rules - 1) - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() # When the request reaches this action, it should now contain solely positional args for the 'add_rule' action. # POSITIONAL ARGUMENTS: @@ -99,9 +99,9 @@ class AccessControlList(SimComponent): # 4: destination ip address (str castable to IPV4Address (e.g. '10.10.1.2')) # 5: destination port (str name of a Port (e.g. "HTTP")) # 6: position (int) - am.add_action( + am.add_request( "add_rule", - Action( + RequestType( func=lambda request, context: self.add_rule( ACLAction[request[0]], IPProtocol[request[1]], @@ -114,7 +114,7 @@ class AccessControlList(SimComponent): ), ) - am.add_action("remove_rule", Action(func=lambda request, context: self.remove_rule(int(request[0])))) + am.add_request("remove_rule", RequestType(func=lambda request, context: self.remove_rule(int(request[0])))) return am def describe_state(self) -> Dict: @@ -626,9 +626,9 @@ class Router(Node): self.arp.nics = self.nics self.icmp.arp = self.arp - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - am.add_action("acl", Action(func=self.acl._action_manager)) + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() + am.add_request("acl", RequestType(func=self.acl._request_manager)) return am def _get_port_of_nic(self, target_nic: NIC) -> Optional[int]: diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index d647b0bc..2e88f3b4 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -1,6 +1,6 @@ from typing import Dict -from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.domain.controller import DomainController from primaite.simulator.network.container import Network @@ -21,12 +21,12 @@ class Simulation(SimComponent): super().__init__(**kwargs) - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - # pass through network actions to the network objects - am.add_action("network", Action(func=self.network._action_manager)) - # pass through domain actions to the domain object - am.add_action("domain", Action(func=self.domain._action_manager)) + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() + # pass through network requests to the network objects + am.add_request("network", RequestType(func=self.network._request_manager)) + # pass through domain requests to the domain object + am.add_request("domain", RequestType(func=self.domain._request_manager)) return am def describe_state(self) -> Dict: diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 20b92027..f48c9449 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -2,7 +2,7 @@ from enum import Enum from typing import Any, Dict, Optional from primaite import getLogger -from primaite.simulator.core import Action, ActionManager +from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.system.software import IOSoftware _LOGGER = getLogger(__name__) @@ -39,15 +39,15 @@ class Service(IOSoftware): _restart_countdown: Optional[int] = None "If currently restarting, how many timesteps remain until the restart is finished." - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - am.add_action("stop", Action(func=lambda request, context: self.stop())) - am.add_action("start", Action(func=lambda request, context: self.start())) - am.add_action("pause", Action(func=lambda request, context: self.pause())) - am.add_action("resume", Action(func=lambda request, context: self.resume())) - am.add_action("restart", Action(func=lambda request, context: self.restart())) - am.add_action("disable", Action(func=lambda request, context: self.disable())) - am.add_action("enable", Action(func=lambda request, context: self.enable())) + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() + am.add_request("stop", RequestType(func=lambda request, context: self.stop())) + am.add_request("start", RequestType(func=lambda request, context: self.start())) + am.add_request("pause", RequestType(func=lambda request, context: self.pause())) + am.add_request("resume", RequestType(func=lambda request, context: self.resume())) + am.add_request("restart", RequestType(func=lambda request, context: self.restart())) + am.add_request("disable", RequestType(func=lambda request, context: self.disable())) + am.add_request("enable", RequestType(func=lambda request, context: self.enable())) return am def describe_state(self) -> Dict: diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index a112eccf..16c614c5 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -2,7 +2,7 @@ from abc import abstractmethod from enum import Enum from typing import Any, Dict, Optional -from primaite.simulator.core import Action, ActionManager, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file_system import FileSystem, Folder from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.sys_log import SysLog @@ -85,15 +85,15 @@ class Software(SimComponent): folder: Optional[Folder] = None "The folder on the file system the Software uses." - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - am.add_action( + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() + am.add_request( "compromise", - Action( + RequestType( func=lambda request, context: self.set_health_state(SoftwareHealthState.COMPROMISED), ), ) - am.add_action("scan", Action(func=lambda request, context: self.scan())) + am.add_request("scan", RequestType(func=lambda request, context: self.scan())) return am @abstractmethod diff --git a/tests/integration_tests/component_creation/test_action_integration.py b/tests/integration_tests/component_creation/test_action_integration.py index ef04ec41..a2be923b 100644 --- a/tests/integration_tests/component_creation/test_action_integration.py +++ b/tests/integration_tests/component_creation/test_action_integration.py @@ -1,6 +1,6 @@ import pytest -from primaite.simulator.core import Action +from primaite.simulator.core import RequestType from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.hardware.nodes.switch import Switch @@ -32,7 +32,7 @@ def test_passing_actions_down(monkeypatch) -> None: sim.network.connect(s1.switch_ports[3], srv.ethernet_port[1]) # call this method to make sure no errors occur. - sim._action_manager.get_action_tree() + sim._request_manager.get_request_types_recursively() # patch the action to do something which we can check the result of. action_invoked = False @@ -42,13 +42,13 @@ def test_passing_actions_down(monkeypatch) -> None: action_invoked = True monkeypatch.setitem( - downloads_folder._action_manager.actions, "repair", Action(func=lambda request, context: succeed()) + downloads_folder._request_manager.request_types, "repair", RequestType(func=lambda request, context: succeed()) ) assert not action_invoked # call the patched method - sim.apply_action( + sim.apply_request( ["network", "node", pc1.uuid, "file_system", "folder", pc1.file_system.get_folder("downloads").uuid, "repair"] ) diff --git a/tests/integration_tests/component_creation/test_permission_system.py b/tests/integration_tests/component_creation/test_permission_system.py index 57e0b35a..bcadebb4 100644 --- a/tests/integration_tests/component_creation/test_permission_system.py +++ b/tests/integration_tests/component_creation/test_permission_system.py @@ -3,7 +3,7 @@ from typing import Dict, List, Literal import pytest -from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent +from primaite.simulator.core import AllowAllValidator, RequestManager, RequestType, SimComponent from primaite.simulator.domain.controller import AccountGroup, GroupMembershipValidator @@ -29,11 +29,11 @@ def test_group_action_validation() -> None: def __init__(self, **kwargs): super().__init__(**kwargs) - self._action_manager = ActionManager() + self._request_manager = RequestManager() - self._action_manager.add_action( + self._request_manager.add_request( "create_folder", - Action( + RequestType( func=lambda request, context: self.create_folder(request[0]), validator=GroupMembershipValidator([AccountGroup.LOCAL_ADMIN, AccountGroup.DOMAIN_ADMIN]), ), @@ -52,13 +52,13 @@ def test_group_action_validation() -> None: # check that the folder is created when a local admin tried to do it permitted_context = {"request_source": {"agent": "BLUE", "account": "User1", "groups": ["LOCAL_ADMIN"]}} my_node = Node(uuid="0000-0000-1234", name="pc") - my_node.apply_action(["create_folder", "memes"], context=permitted_context) + my_node.apply_request(["create_folder", "memes"], context=permitted_context) assert len(my_node.folders) == 1 assert my_node.folders[0].name == "memes" # check that the number of folders is still 1 even after attempting to create a second one without permissions invalid_context = {"request_source": {"agent": "BLUE", "account": "User1", "groups": ["LOCAL_USER", "DOMAIN_USER"]}} - my_node.apply_action(["create_folder", "memes2"], context=invalid_context) + my_node.apply_request(["create_folder", "memes2"], context=invalid_context) assert len(my_node.folders) == 1 assert my_node.folders[0].name == "memes" @@ -79,32 +79,32 @@ def test_hierarchical_action_with_validation() -> None: def __init__(self, **kwargs): super().__init__(**kwargs) - self.action_manager = ActionManager() + self.request_manager = RequestManager() - self.action_manager.add_action( + self.request_manager.add_request( "turn_on", - Action( + RequestType( func=lambda request, context: self.turn_on(), validator=AllowAllValidator(), ), ) - self.action_manager.add_action( + self.request_manager.add_request( "turn_off", - Action( + RequestType( func=lambda request, context: self.turn_off(), validator=AllowAllValidator(), ), ) - self.action_manager.add_action( + self.request_manager.add_request( "disable", - Action( + RequestType( func=lambda request, context: self.disable(), validator=GroupMembershipValidator([AccountGroup.LOCAL_ADMIN, AccountGroup.DOMAIN_ADMIN]), ), ) - self.action_manager.add_action( + self.request_manager.add_request( "enable", - Action( + RequestType( func=lambda request, context: self.enable(), validator=GroupMembershipValidator([AccountGroup.LOCAL_ADMIN, AccountGroup.DOMAIN_ADMIN]), ), @@ -135,11 +135,11 @@ def test_hierarchical_action_with_validation() -> None: def __init__(self, **kwargs): super().__init__(**kwargs) - self.action_manager = ActionManager() + self.request_manager = RequestManager() - self.action_manager.add_action( + self.request_manager.add_request( "apps", - Action( + RequestType( func=lambda request, context: self.send_action_to_app(request.pop(0), request, context), validator=AllowAllValidator(), ), @@ -155,7 +155,7 @@ def test_hierarchical_action_with_validation() -> None: def send_action_to_app(self, app_name: str, options: List[str], context: Dict): for app in self.apps: if app_name == app.name: - app.apply_action(options, context) + app.apply_request(options, context) break else: msg = f"Node has no app with name {app_name}" @@ -178,15 +178,15 @@ def test_hierarchical_action_with_validation() -> None: } # check that a non-admin can't disable this app - my_node.apply_action(["apps", "Chrome", "disable"], non_admin_context) + my_node.apply_request(["apps", "Chrome", "disable"], non_admin_context) assert my_node.apps[0].name == "Chrome" # if failure occurs on this line, the test itself is broken assert my_node.apps[0].state == "off" # check that a non-admin can turn this app on - my_node.apply_action(["apps", "Firefox", "turn_on"], non_admin_context) + my_node.apply_request(["apps", "Firefox", "turn_on"], non_admin_context) assert my_node.apps[1].name == "Firefox" # if failure occurs on this line, the test itself is broken assert my_node.apps[1].state == "on" # check that an admin can disable this app - my_node.apply_action(["apps", "Chrome", "disable"], admin_context) + my_node.apply_request(["apps", "Chrome", "disable"], admin_context) assert my_node.apps[0].state == "disabled" diff --git a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py index b5632ea7..96c34996 100644 --- a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py +++ b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py @@ -13,6 +13,6 @@ def test_account_deserialise(): """Test that an account can be deserialised. The test fails if pydantic throws an error.""" acct_json = ( '{"uuid":"dfb2bcaa-d3a1-48fd-af3f-c943354622b4","num_logons":0,"num_logoffs":0,"num_group_changes":0,' - '"username":"Jake","password":"JakePass1!","account_type":2,"status":2,"action_manager":null}' + '"username":"Jake","password":"JakePass1!","account_type":2,"status":2,"request_manager":null}' ) acct = Account.model_validate_json(acct_json) From 318539fd8f7c442615297f1a400e18d1b45d6441 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Mon, 9 Oct 2023 13:25:12 +0100 Subject: [PATCH 216/980] #1943: apply suggestions from PR + fixing FTP bug + elaborating --- src/primaite/simulator/network/hardware/nodes/computer.py | 2 -- src/primaite/simulator/network/hardware/nodes/router.py | 2 -- src/primaite/simulator/network/hardware/nodes/switch.py | 2 -- src/primaite/simulator/network/networks.py | 2 ++ src/primaite/simulator/network/protocols/ftp.py | 4 ++-- src/primaite/simulator/system/applications/web_browser.py | 4 ++-- src/primaite/simulator/system/services/ftp/ftp_client.py | 6 ++++++ src/primaite/simulator/system/services/ftp/ftp_server.py | 6 +++++- src/primaite/simulator/system/services/ftp/ftp_service.py | 6 ++++++ .../simulator/system/services/web_server/web_server.py | 2 +- 10 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/primaite/simulator/network/hardware/nodes/computer.py b/src/primaite/simulator/network/hardware/nodes/computer.py index 61c62a5f..0480aca9 100644 --- a/src/primaite/simulator/network/hardware/nodes/computer.py +++ b/src/primaite/simulator/network/hardware/nodes/computer.py @@ -2,7 +2,6 @@ from primaite.simulator.network.hardware.base import NIC, Node from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.ftp.ftp_client import FTPClient -from primaite.simulator.system.services.ftp.ftp_server import FTPServer class Computer(Node): @@ -49,7 +48,6 @@ class Computer(Node): # FTP self.software_manager.install(FTPClient) - self.software_manager.install(FTPServer) # Web Browser self.software_manager.install(WebBrowser) diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 90eb5935..092680a7 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -596,8 +596,6 @@ class Router(Node): self.arp.nics = self.nics self.icmp.arp = self.arp - self._install_system_software() - def _get_port_of_nic(self, target_nic: NIC) -> Optional[int]: """ Retrieve the port number for a given NIC. diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/switch.py index 8b3fe5cd..b7cc1242 100644 --- a/src/primaite/simulator/network/hardware/nodes/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/switch.py @@ -34,8 +34,6 @@ class Switch(Node): port.parent = self port.port_num = port_num - self._install_system_software() - def show(self, markdown: bool = False): """ Prints a table of the SwitchPorts on the Switch. diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index e465e08a..be20f89f 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -11,6 +11,7 @@ from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.dns.dns_server import DNSServer +from primaite.simulator.system.services.ftp.ftp_server import FTPServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.web_server.web_server import WebServer @@ -268,6 +269,7 @@ def arcd_uc2_network() -> Network: dns_server=IPv4Address("192.168.1.10"), ) backup_server.power_on() + backup_server.software_manager.install(FTPServer) network.connect(endpoint_b=backup_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[4]) # Security Suite diff --git a/src/primaite/simulator/network/protocols/ftp.py b/src/primaite/simulator/network/protocols/ftp.py index 91080219..9ecc7df8 100644 --- a/src/primaite/simulator/network/protocols/ftp.py +++ b/src/primaite/simulator/network/protocols/ftp.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import Any, Optional +from typing import Any, Optional, Union from primaite.simulator.network.protocols.packet import DataPacket @@ -51,5 +51,5 @@ class FTPPacket(DataPacket): ftp_command_args: Optional[Any] = None """Arguments for command.""" - status_code: FTPStatusCode = None + status_code: Union[FTPStatusCode, None] = None """Status of the response.""" diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 4f6b81c1..c48b785e 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -19,7 +19,7 @@ class WebBrowser(Application): domain_name_ip_address: Optional[IPv4Address] = None "The IP address of the domain name for the webpage." - latest_response: HttpResponsePacket = None + latest_response: Optional[HttpResponsePacket] = None """Keeps track of the latest HTTP response.""" def __init__(self, **kwargs): @@ -38,7 +38,7 @@ class WebBrowser(Application): :return: A dictionary capturing the current state of the WebBrowser and its child objects. """ - pass + return super().describe_state() def reset_component_for_episode(self, episode: int): """ diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index b2a1e8bf..3e286da1 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -264,6 +264,12 @@ class FTPClient(FTPServiceABC): self.sys_log.error(f"{payload} is not an FTP packet") return False + """ + Ignore ftp payload if status code is None. + + This helps prevent an FTP request loop - FTP client and servers can exist on + the same node. + """ if payload.status_code is None: return False diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index d93150e0..23414601 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -80,7 +80,11 @@ class FTPServer(FTPServiceABC): return False """ - Usually + Ignore ftp payload if status code is defined. + + This means that an FTP server has already handled the packet and + prevents an FTP request loop - FTP client and servers can exist on + the same node. """ if payload.status_code is not None: return False diff --git a/src/primaite/simulator/system/services/ftp/ftp_service.py b/src/primaite/simulator/system/services/ftp/ftp_service.py index 61f83be0..f2c01544 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_service.py +++ b/src/primaite/simulator/system/services/ftp/ftp_service.py @@ -76,6 +76,7 @@ class FTPServiceABC(Service, ABC): dest_ip_address: Optional[IPv4Address] = None, dest_port: Optional[Port] = None, session_id: Optional[str] = None, + is_response: bool = False, ) -> bool: """ Sends data from the host FTP Service's machine to another FTP Service's host machine. @@ -97,6 +98,9 @@ class FTPServiceABC(Service, ABC): :param: session_id: session ID linked to the FTP Packet. Optional. :type: session_id: Optional[str] + + :param: is_response: is true if the data being sent is in response to a request. Default False. + :type: is_response: bool """ # send STOR request payload: FTPPacket = FTPPacket( @@ -108,6 +112,7 @@ class FTPServiceABC(Service, ABC): "real_file_path": file.sim_path if file.real else None, }, packet_payload_size=file.sim_size, + status_code=FTPStatusCode.OK if is_response else None, ) self.sys_log.info(f"{self.name}: Sending file {file.folder.name}/{file.name}") response = self.send( @@ -148,6 +153,7 @@ class FTPServiceABC(Service, ABC): dest_file_name=dest_file_name, dest_folder_name=dest_folder_name, session_id=session_id, + is_response=True, ) except Exception as e: self.sys_log.error(f"Unable to retrieve file from {self.sys_log.hostname}: {e}") diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index 4566f3b3..f63d5169 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -35,7 +35,7 @@ class WebServer(Service): This is usually HTML, CSS, JS or PHP files requested by browsers to display the webpage. """ # index HTML main file - self.file_system.create_file(file_name="index.html", folder_name="primaite", real=True) + self.file_system.create_file(file_name="index.html", folder_name="primaite") def _process_http_request(self, payload: HttpRequestPacket, session_id: Optional[str] = None) -> bool: """ From bbf2b09f96b1d11c716c75a3abbb476b5714b842 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Mon, 9 Oct 2023 16:47:36 +0100 Subject: [PATCH 217/980] #1947: Add ability for all simcomponents to be scanned - sets up ability for service, files, folders and nodes to be scanned --- src/primaite/simulator/core.py | 4 ++ .../simulator/system/services/service.py | 50 +++++-------------- src/primaite/simulator/system/software.py | 2 + 3 files changed, 18 insertions(+), 38 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index a292be18..a6fca59d 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -200,6 +200,10 @@ class SimComponent(BaseModel): } return state + def scan(self) -> None: + """Update the visible statuses of the SimComponent.""" + pass + def apply_action(self, action: List[str], context: Dict = {}) -> None: """ Apply an action to a simulation component. Action data is passed in as a 'namespaced' list of strings. diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 20b92027..8f505210 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import Any, Dict, Optional +from typing import Dict, Optional from primaite import getLogger from primaite.simulator.core import Action, ActionManager @@ -34,6 +34,10 @@ class Service(IOSoftware): operating_state: ServiceOperatingState = ServiceOperatingState.STOPPED "The current operating state of the Service." + + visible_operating_state: ServiceOperatingState = ServiceOperatingState.STOPPED + "The visible operating state of the service." + restart_duration: int = 5 "How many timesteps does it take to restart this service." _restart_countdown: Optional[int] = None @@ -41,6 +45,7 @@ class Service(IOSoftware): def _init_action_manager(self) -> ActionManager: am = super()._init_action_manager() + am.add_action("scan", Action(func=lambda request, context: self.scan())) am.add_action("stop", Action(func=lambda request, context: self.stop())) am.add_action("start", Action(func=lambda request, context: self.start())) am.add_action("pause", Action(func=lambda request, context: self.pause())) @@ -72,44 +77,13 @@ class Service(IOSoftware): """ pass - def send( - self, - payload: Any, - session_id: Optional[str] = None, - **kwargs, - ) -> bool: - """ - Sends a payload to the SessionManager. + def scan(self) -> None: + """Update the service visible states.""" + # update parent states + super().scan() - The specifics of how the payload is processed and whether a response payload - is generated should be implemented in subclasses. - - :param: payload: The payload to send. - :param: session_id: The id of the session - - :return: True if successful, False otherwise. - """ - self.software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id) - - def receive( - self, - payload: Any, - session_id: Optional[str] = None, - **kwargs, - ) -> bool: - """ - Receives a payload from the SessionManager. - - The specifics of how the payload is processed and whether a response payload - is generated should be implemented in subclasses. - - :param: payload: The payload to send. - :param: session_id: The id of the session - - :return: True if successful, False otherwise. - """ - - pass + # update the visible operating state + self.visible_operating_state = self.operating_state def stop(self) -> None: """Stop the service.""" diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index a112eccf..e24427b0 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -221,7 +221,9 @@ class IOSoftware(Software): :param kwargs: Additional keyword arguments specific to the implementation. :return: True if the payload was successfully sent, False otherwise. """ + self.software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id, **kwargs) + @abstractmethod def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ Receives a payload from the SessionManager. From f68886d5dfa11f5090a37f35c4049d25dfb23870 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 9 Oct 2023 17:29:50 +0100 Subject: [PATCH 218/980] Fix bugged actions --- example_config.yaml | 202 +++++++++--------- src/primaite/game/agent/actions.py | 118 +++++++--- src/primaite/game/agent/observations.py | 58 ++--- .../network/hardware/nodes/router.py | 10 +- .../network/hardware/nodes/switch.py | 11 +- 5 files changed, 230 insertions(+), 169 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index 9f679223..f7faf589 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -63,8 +63,8 @@ game_config: services: - service_ref: data_manipulation_bot observations: - - operating_status - - health_status + operating_status + health_status folders: {} action_space: @@ -197,221 +197,221 @@ game_config: 1: action: NODE_SERVICE_SCAN options: - - node_id: 2 - - service_id: 1 + node_id: 2 + service_id: 1 # stop webapp service 2: action: NODE_SERVICE_STOP options: - - node_id: 2 - - service_id: 1 + node_id: 2 + service_id: 1 # start webapp service 3: action: "NODE_SERVICE_START" options: - - node_id: 2 - - service_id: 1 + node_id: 2 + service_id: 1 4: action: "NODE_SERVICE_PAUSE" options: - - node_id: 2 - - service_id: 1 + node_id: 2 + service_id: 1 5: action: "NODE_SERVICE_RESUME" options: - - node_id: 2 - - service_id: 1 + node_id: 2 + service_id: 1 6: action: "NODE_SERVICE_RESTART" options: - - node_id: 2 - - service_id: 1 + node_id: 2 + service_id: 1 7: action: "NODE_SERVICE_DISABLE" options: - - node_id: 2 - - service_id: 1 + node_id: 2 + service_id: 1 8: action: "NODE_SERVICE_ENABLE" options: - - node_id: 2 - - service_id: 1 + node_id: 2 + service_id: 1 9: action: "NODE_FILE_SCAN" options: - - node_id: 3 - - folder_id: 1 - - file_id: 1 + node_id: 3 + folder_id: 1 + file_id: 1 10: action: "NODE_FILE_CHECKHASH" options: - - node_id: 3 - - folder_id: 1 - - file_id: 1 + node_id: 3 + folder_id: 1 + file_id: 1 11: action: "NODE_FILE_DELETE" options: - - node_id: 3 - - folder_id: 1 - - file_id: 1 + node_id: 3 + folder_id: 1 + file_id: 1 12: action: "NODE_FILE_REPAIR" options: - - node_id: 3 - - folder_id: 1 - - file_id: 1 + node_id: 3 + folder_id: 1 + file_id: 1 13: action: "NODE_FILE_RESTORE" options: - - node_id: 3 - - folder_id: 1 - - file_id: 1 + node_id: 3 + folder_id: 1 + file_id: 1 14: action: "NODE_FOLDER_SCAN" options: - - node_id: 3 - - folder_id: 1 + node_id: 3 + folder_id: 1 15: action: "NODE_FOLDER_CHECKHASH" options: - - node_id: 3 - - folder_id: 1 + node_id: 3 + folder_id: 1 16: action: "NODE_FOLDER_REPAIR" options: - - node_id: 3 - - folder_id: 1 + node_id: 3 + folder_id: 1 17: action: "NODE_FOLDER_RESTORE" options: - - node_id: 3 - - folder_id: 1 + node_id: 3 + folder_id: 1 18: action: "NODE_OS_SCAN" options: - - node_id: 3 + node_id: 3 19: action: "NODE_SHUTDOWN" options: - - node_id: 6 + node_id: 6 20: action: "NODE_STARTUP" options: - - node_id: 6 + node_id: 6 21: action: "NODE_RESET" options: - - node_id: 6 + node_id: 6 22: action: "NETWORK_ACL_ADDRULE" options: - - position: 6 - - permission: 2 - - source_node_id: ... - - dest_node_id: ... - - source_port_id: ... - - dest_port_id: ... - - protocol_id: ... + position: 1 + permission: 2 + source_ip_id: 7 + dest_ip_id: 1 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 23: action: "NETWORK_ACL_ADDRULE" options: - - position: 5 - - permission: 2 - - source_node_id: ... - - dest_node_id: ... - - source_port_id: ... - - dest_port_id: ... - - protocol_id: ... + position: 1 + permission: 2 + source_ip_id: 8 + dest_ip_id: 1 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 24: action: "NETWORK_ACL_ADDRULE" options: - - position: 4 - - permission: 2 - - source_node_id: ... - - dest_node_id: ... - - source_port_id: ... - - dest_port_id: ... - - protocol_id: ... + position: 1 + permission: 2 + source_ip_id: 7 + dest_ip_id: 3 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 25: action: "NETWORK_ACL_ADDRULE" options: - - position: 3 - - permission: 2 - - source_node_id: ... - - dest_node_id: ... - - source_port_id: ... - - dest_port_id: ... - - protocol_id: ... + position: 1 + permission: 2 + source_ip_id: 8 + dest_ip_id: 3 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 26: action: "NETWORK_ACL_ADDRULE" options: - - position: 2 - - permission: 2 - - source_node_id: ... - - dest_node_id: ... - - source_port_id: ... - - dest_port_id: ... - - protocol_id: ... + position: 1 + permission: 2 + source_ip_id: 7 + dest_ip_id: 4 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 27: action: "NETWORK_ACL_ADDRULE" options: - - position: 1 - - permission: 2 - - source_node_id: ... - - dest_node_id: ... - - source_port_id: ... - - dest_port_id: ... - - protocol_id: ... + position: 1 + permission: 2 + source_ip_id: 8 + dest_ip_id: 4 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 28: action: "NETWORK_ACL_REMOVERULE" options: - - position: 0 + position: 0 29: action: "NETWORK_ACL_REMOVERULE" options: - - position: 1 + position: 1 30: action: "NETWORK_ACL_REMOVERULE" options: - - position: 2 + position: 2 31: action: "NETWORK_ACL_REMOVERULE" options: - - position: 3 + position: 3 32: action: "NETWORK_ACL_REMOVERULE" options: - - position: 4 + position: 4 33: action: "NETWORK_ACL_REMOVERULE" options: - - position: 5 + position: 5 34: action: "NETWORK_ACL_REMOVERULE" options: - - position: 6 + position: 6 35: action: "NETWORK_ACL_REMOVERULE" options: - - position: 7 + position: 7 36: action: "NETWORK_ACL_REMOVERULE" options: - - position: 8 + position: 8 37: action: "NETWORK_ACL_REMOVERULE" options: - - position: 9 + position: 9 38: action: "NETWORK_NIC_DISABLE" options: - - node_id: 6 - - nic_index: 1 + node_id: 6 + nic_id: 1 39: action: "NETWORK_NIC_ENABLE" options: - - node_id: 6 - - nic_index: 1 + node_id: 6 + nic_id: 1 options: nodes: diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 3f674fbb..1e6893ff 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -5,6 +5,8 @@ from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING from gym import spaces from primaite.simulator.sim_container import Simulation +from primaite import getLogger +_LOGGER = getLogger(__name__) if TYPE_CHECKING: from primaite.game.session import PrimaiteSession @@ -253,7 +255,7 @@ class NodeShutdownAction(NodeAbstractAction): class NodeStartupAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes) - self.verb = "start" + self.verb = "startup" class NodeResetAction(NodeAbstractAction): @@ -274,33 +276,73 @@ class NetworkACLAddRuleAction(AbstractAction): **kwargs, ) -> None: super().__init__(manager=manager) - num_permissions = 2 + num_permissions = 3 self.shape: Dict[str, int] = { "position": max_acl_rules, "permission": num_permissions, - "source_ip_idx": num_ips, - "dest_ip_idx": num_ips, - "source_port_idx": num_ports, - "dest_port_idx": num_ports, - "protocol_idx": num_protocols, + "source_ip_id": num_ips, + "dest_ip_id": num_ips, + "source_port_id": num_ports, + "dest_port_id": num_ports, + "protocol_id": num_protocols, } self.target_router_uuid: str = target_router_uuid def form_request( - self, position, permission, source_ip_idx, dest_ip_idx, source_port_idx, dest_port_idx, protocol_idx + self, position, permission, source_ip_id, dest_ip_id, source_port_id, dest_port_id, protocol_id ) -> List[str]: - protocol = self.manager.get_internet_protocol_by_idx(protocol_idx) - src_ip = self.manager.get_ip_address_by_idx(source_ip_idx) - src_port = self.manager.get_port_by_idx(source_port_idx) - dst_ip = self.manager.get_ip_address_by_idx(dest_ip_idx) - dst_port = self.manager.get_port_by_idx(dest_port_idx) + if permission == 0: + permission_str = "UNUSED" + return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS + elif permission == 1: + permission_str = "ALLOW" + elif permission == 2: + permission_str = "DENY" + else: + _LOGGER.warn(f"{self.__class__} received permission {permission}, expected 0 or 1.") + + if protocol_id == 0: + return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS + + if protocol_id == 1: + protocol = "ALL" + else: + protocol = self.manager.get_internet_protocol_by_idx(protocol_id-2) + # subtract 2 to account for UNUSED=0 and ALL=1. + + if source_ip_id in [0,1]: + src_ip = "ALL" + return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS + else: + src_ip = self.manager.get_ip_address_by_idx(source_ip_id-2) + # subtract 2 to account for UNUSED=0, and ALL=1 + + if source_port_id == 1: + src_port = "ALL" + else: + src_port = self.manager.get_port_by_idx(source_port_id-2) + # subtract 2 to account for UNUSED=0, and ALL=1 + + if dest_ip_id in (0,1): + dst_ip = "ALL" + return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS + else: + dst_ip = self.manager.get_ip_address_by_idx(dest_ip_id) + # subtract 2 to account for UNUSED=0, and ALL=1 + + if dest_port_id == 1: + dst_port = "ALL" + else: + dst_port = self.manager.get_port_by_idx(dest_port_id) + # subtract 2 to account for UNUSED=0, and ALL=1 + return [ "network", "node", self.target_router_uuid, "acl", "add_rule", - permission, + permission_str, protocol, src_ip, src_port, @@ -320,36 +362,52 @@ class NetworkACLRemoveRuleAction(AbstractAction): return ["network", "node", self.target_router_uuid, "acl", "remove_rule", position] -class NetworkNICEnableAction(AbstractAction): +class NetworkNICAbstractAction(AbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes, "nic_id": max_nics_per_node} + self.verb: str def form_request(self, node_id: int, nic_id: int) -> List[str]: + node_uuid = self.manager.get_node_uuid_by_idx(node_idx=node_id) + nic_uuid = self.manager.get_nic_uuid_by_idx(node_idx=node_id, nic_idx=nic_id) + if node_uuid is None or nic_uuid is None: + return ["do_nothing"] return [ "network", "node", - self.manager.get_node_uuid_by_idx(node_idx=node_id), + node_uuid, "nic", - self.manager.get_nic_uuid_by_idx(node_idx=node_id, nic_idx=nic_id), - "enable", + nic_uuid, + self.verb, ] -class NetworkNICDisableAction(AbstractAction): +class NetworkNICEnableAction(NetworkNICAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: - super().__init__(manager=manager) - self.shape: Dict[str, int] = {"node_id": num_nodes, "nic_id": max_nics_per_node} + super().__init__(manager=manager, num_nodes=num_nodes, max_nics_per_node=max_nics_per_node, **kwargs) + self.verb = "enable" - def form_request(self, node_id: int, nic_id: int) -> List[str]: - return [ - "network", - "node", - self.manager.get_node_uuid_by_idx(node_idx=node_id), - "nic", - self.manager.get_nic_uuid_by_idx(node_idx=node_id, nic_idx=nic_id), - "disable", - ] + +class NetworkNICDisableAction(NetworkNICAbstractAction): + def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, max_nics_per_node=max_nics_per_node, **kwargs) + self.verb = "disable" + +# class NetworkNICDisableAction(AbstractAction): +# def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: +# super().__init__(manager=manager) +# self.shape: Dict[str, int] = {"node_id": num_nodes, "nic_id": max_nics_per_node} + +# def form_request(self, node_id: int, nic_id: int) -> List[str]: +# return [ +# "network", +# "node", +# self.manager.get_node_uuid_by_idx(node_idx=node_id), +# "nic", +# self.manager.get_nic_uuid_by_idx(node_idx=node_id, nic_idx=nic_id), +# "disable", +# ] class ActionManager: diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index c5b931ee..28c87af1 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from typing import Any, Dict, Hashable, List, Optional, TYPE_CHECKING +from typing import Any, Dict, Hashable, List, Optional, TYPE_CHECKING, Sequence, Tuple from gym import spaces from pydantic import BaseModel @@ -15,7 +15,7 @@ the thing requested in the state could equal None. This NOT_PRESENT_IN_STATE is """ -def access_from_nested_dict(dictionary: Dict, keys: List[Hashable]) -> Any: +def access_from_nested_dict(dictionary: Dict, keys: Sequence[Hashable]) -> Any: """ Access an item from a deeply dictionary with a list of keys. @@ -29,12 +29,13 @@ def access_from_nested_dict(dictionary: Dict, keys: List[Hashable]) -> Any: :return: The value in the dictionary :rtype: Any """ - if len(keys) == 0: + key_list = [*keys] # copy keys to a new list to prevent editing original list + if len(key_list) == 0: return dictionary - k = keys.pop(0) + k = key_list.pop(0) if k not in dictionary: return NOT_PRESENT_IN_STATE - return access_from_nested_dict(dictionary[k], keys) + return access_from_nested_dict(dictionary[k], key_list) class AbstractObservation(ABC): @@ -66,7 +67,7 @@ class AbstractObservation(ABC): class FileObservation(AbstractObservation): - def __init__(self, where: Optional[List[str]] = None) -> None: + def __init__(self, where: Optional[Tuple[str]] = None) -> None: """ _summary_ @@ -79,7 +80,7 @@ class FileObservation(AbstractObservation): :type where: Optional[List[str]] """ super().__init__() - self.where: Optional[List[str]] = where + self.where: Optional[Tuple[str]] = where self.default_observation: spaces.Space = {"health_status": 0} "Default observation is what should be returned when the file doesn't exist, e.g. after it has been deleted." @@ -104,7 +105,7 @@ class ServiceObservation(AbstractObservation): default_observation: spaces.Space = {"operating_status": 0, "health_status": 0} "Default observation is what should be returned when the service doesn't exist." - def __init__(self, where: Optional[List[str]] = None) -> None: + def __init__(self, where: Optional[Tuple[str]] = None) -> None: """ :param where: Store information about where in the simulation state dictionary to find the relevant information. Optional. If None, this corresponds that the file does not exist and the observation will be populated with @@ -115,7 +116,7 @@ class ServiceObservation(AbstractObservation): :type where: Optional[List[str]] """ super().__init__() - self.where: Optional[List[str]] = where + self.where: Optional[Tuple[str]] = where def observe(self, state: Dict) -> Dict: if self.where is None: @@ -124,7 +125,7 @@ class ServiceObservation(AbstractObservation): service_state = access_from_nested_dict(state, self.where) if service_state is NOT_PRESENT_IN_STATE: return self.default_observation - return {"operating_status": service_state["operating_status"], "health_status": service_state["health_status"]} + return {"operating_status": service_state["operating_state"], "health_status": service_state["health_status"]} @property def space(self) -> spaces.Space: @@ -132,7 +133,9 @@ class ServiceObservation(AbstractObservation): @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where:Optional[List[str]]=None): - return cls(where=parent_where+["services",session.ref_map_services[config['service_ref']]]) + return cls( + where=parent_where+["services",session.ref_map_services[config['service_ref']].uuid] + ) @@ -140,7 +143,7 @@ class LinkObservation(AbstractObservation): default_observation: spaces.Space = {"protocols": {"all": {"load": 0}}} "Default observation is what should be returned when the link doesn't exist." - def __init__(self, where: Optional[List[str]] = None) -> None: + def __init__(self, where: Optional[Tuple[str]] = None) -> None: """ :param where: Store information about where in the simulation state dictionary to find the relevant information. Optional. If None, this corresponds that the file does not exist and the observation will be populated with @@ -151,7 +154,7 @@ class LinkObservation(AbstractObservation): :type where: Optional[List[str]] """ super().__init__() - self.where: Optional[List[str]] = where + self.where: Optional[Tuple[str]] = where def observe(self, state: Dict) -> Dict: if self.where is None: @@ -180,7 +183,7 @@ class LinkObservation(AbstractObservation): class FolderObservation(AbstractObservation): - def __init__(self, where: Optional[List[str]] = None, files: List[FileObservation] = []) -> None: + def __init__(self, where: Optional[Tuple[str]] = None, files: List[FileObservation] = []) -> None: """Initialise folder Observation, including files inside of the folder. :param where: Where in the simulation state dictionary to find the relevant information for this folder. @@ -199,7 +202,7 @@ class FolderObservation(AbstractObservation): """ super().__init__() - self.where: Optional[List[str]] = where + self.where: Optional[Tuple[str]] = where self.files: List[FileObservation] = files @@ -246,9 +249,9 @@ class FolderObservation(AbstractObservation): class NicObservation(AbstractObservation): default_observation: spaces.Space = {"nic_status": 0} - def __init__(self, where: Optional[List[str]] = None) -> None: + def __init__(self, where: Optional[Tuple[str]] = None) -> None: super().__init__() - self.where: Optional[List[str]] = where + self.where: Optional[Tuple[str]] = where def observe(self, state: Dict) -> Dict: if self.where is None: @@ -271,7 +274,7 @@ class NicObservation(AbstractObservation): class NodeObservation(AbstractObservation): def __init__( self, - where: Optional[List[str]] = None, + where: Optional[Tuple[str]] = None, services: List[ServiceObservation] = [], folders: List[FolderObservation] = [], nics: List[NicObservation] = [], @@ -298,7 +301,7 @@ class NodeObservation(AbstractObservation): :type max_nics: int, optional """ super().__init__() - self.where: Optional[List[str]] = where + self.where: Optional[Tuple[str]] = where self.services: List[ServiceObservation] = services self.folders: List[FolderObservation] = folders @@ -371,10 +374,10 @@ class AclObservation(AbstractObservation): # if a file is created at runtime, we have currently got no way of telling the observation space to track it. # this needs adding, but not for the MVP. def __init__( - self, node_ip_to_id: Dict[str,int], ports: List[int], protocols: list[str], where: Optional[List[str]] = None, num_rules: int = 10 + self, node_ip_to_id: Dict[str,int], ports: List[int], protocols: list[str], where: Optional[Tuple[str]] = None, num_rules: int = 10 ) -> None: super().__init__() - self.where: Optional[List[str]] = where + self.where: Optional[Tuple[str]] = where self.num_rules: int = num_rules self.node_to_id: Dict[str, int] = node_ip_to_id "List of node IP addresses, order in this list determines how they are converted to an ID" @@ -403,6 +406,8 @@ class AclObservation(AbstractObservation): if acl_state is NOT_PRESENT_IN_STATE: return self.default_observation + + #TODO: what if the ACL has more rules than num of max rules for obs space obs = {} obs["RULES"] = {} for i, rule_state in acl_state.items(): @@ -466,7 +471,7 @@ class AclObservation(AbstractObservation): node_ip_to_id=node_ip_to_idx, ports=session.options.ports, protocols=session.options.protocols, - where=["network", "nodes", router_uuid]) + where=["network", "nodes", router_uuid, "acl", "acl"]) @@ -498,7 +503,7 @@ class UC2BlueObservation(AbstractObservation): where:Optional[List[str]] = None, ) -> None: super().__init__() - self.where: Optional[List[str]] = where + self.where: Optional[Tuple[str]] = where self.nodes: List[NodeObservation] = nodes self.links: List[LinkObservation] = links @@ -517,11 +522,10 @@ class UC2BlueObservation(AbstractObservation): return self.default_observation obs = {} - obs['NODES'] = {i + 1: node.observe(state) for i, node in enumerate(self.nodes)} obs['LINKS'] = {i + 1: link.observe(state) for i, link in enumerate(self.links)} - obs['ACL'] = {self.acl.observe(state)} - obs['ICS'] = {self.ics.observe(state)} + obs['ACL'] = self.acl.observe(state) + obs['ICS'] = self.ics.observe(state) return obs @@ -546,7 +550,7 @@ class UC2BlueObservation(AbstractObservation): acl = AclObservation.from_config(config=acl_config, session=session) ics_config = config["ics"] - ics = ICSObservation.from_config(ics_config) + ics = ICSObservation.from_config(config=ics_config, session=session) new = cls(nodes=nodes, links=links, acl=acl, ics=ics, where=['network']) return new diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 2e7681a9..3691c101 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -111,11 +111,11 @@ class AccessControlList(SimComponent): Action( func=lambda request, context: self.add_rule( ACLAction[request[0]], - IPProtocol[request[1]], - IPv4Address[request[2]], - Port[request[3]], - IPv4Address[request[4]], - Port[request[5]], + None if request[1] is "ALL" else IPProtocol[request[1]], + IPv4Address(request[2]), + None if request[3] is "ALL" else Port[request[3]], + IPv4Address(request[4]), + None if request[5] is "ALL" else Port[request[5]], int(request[6]), ) ), diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/switch.py index ac8dabd1..bb296203 100644 --- a/src/primaite/simulator/network/hardware/nodes/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/switch.py @@ -55,12 +55,11 @@ class Switch(Node): :return: Current state of this object and child objects. """ - return { - "uuid": self.uuid, - "num_ports": self.num_ports, # redundant? - "ports": {port_num: port.describe_state() for port_num, port in self.switch_ports.items()}, - "mac_address_table": {mac: port for mac, port in self.mac_address_table.items()}, - } + state = super().describe_state() + state["ports"] = {port_num: port.describe_state() for port_num, port in self.switch_ports.items()} + state["num_ports"]= self.num_ports # redundant? + state["mac_address_table"]= {mac: port for mac, port in self.mac_address_table.items()} + return state def _add_mac_table_entry(self, mac_address: str, switch_port: SwitchPort): """ From e85c5977d0de4d644865562e289bafb3a9a1c230 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 9 Oct 2023 18:22:30 +0100 Subject: [PATCH 219/980] remove redundant code from sandbox notebook --- sandbox.ipynb | 792 +------------------------------------------------- 1 file changed, 12 insertions(+), 780 deletions(-) diff --git a/sandbox.ipynb b/sandbox.ipynb index b3b3be0d..a2150921 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -2,568 +2,29 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", - "%autoreload 2" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "from primaite.game.session import PrimaiteSession\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ + "%autoreload 2\n", + "from primaite.game.session import PrimaiteSession\n", + "\n", "from primaite import _PRIMAITE_CONFIG, PRIMAITE_PATHS\n", "import logging\n", "_PRIMAITE_CONFIG['log_level']=logging.DEBUG\n", - "print(PRIMAITE_PATHS.app_log_dir_path)" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "import itertools" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ + "print(PRIMAITE_PATHS.app_log_dir_path)\n", + "import itertools\n", "from primaite.game.session import PrimaiteSession\n", "from primaite.simulator.sim_container import Simulation\n", "from primaite.game.agent.interface import AbstractAgent\n", "from primaite.simulator.network.networks import arcd_uc2_network\n", - "import yaml\n" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "with open('example_config.yaml', 'r') as file:\n", - " cfg = yaml.safe_load(file)" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-10-08 17:56:35,831: Added node af2f9c15-ecb4-4b65-b48f-63f12acddb88 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", - "2023-10-08 17:56:35,836: Added node 47158854-0917-4037-a6a2-33dde56a120f to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", - "2023-10-08 17:56:35,840: Added node cba8ce63-8064-4f80-bcfe-95ca65221dfa to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", - "2023-10-08 17:56:35,846: Added node e01e7c2b-02ac-4e2d-b7bb-8bc3b6ea6509 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", - "2023-10-08 17:56:35,857: Added node bd5d85ba-5980-45c7-8b28-020a2cfeba0f to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", - "2023-10-08 17:56:35,863: Added node 39e0e37c-4d72-4c76-93cb-4f9c29651ef4 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", - "2023-10-08 17:56:35,878: Added node 7d1063f9-b5e5-4753-966e-1b630325b266 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", - "2023-10-08 17:56:35,881: Added node d85b6abb-0f9e-4853-af26-c9b410e1cb94 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", - "2023-10-08 17:56:35,884: Added node 63b18888-98aa-4182-a014-02999d095bd0 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", - "2023-10-08 17:56:35,888: Added node f514cf8a-a3f1-46d6-be00-994364241ef4 to Network cbd56fbb-104f-4823-9ee6-f4a968343b31\n", - "2023-10-08 17:56:35,890: NIC 27:a9:09:ed:30:5a/192.168.1.1 connected to Link 27:a9:09:ed:30:5a/192.168.1.1<-->cb:6f:24:8c:7a:20\n", - "2023-10-08 17:56:35,891: SwitchPort cb:6f:24:8c:7a:20 connected to Link 27:a9:09:ed:30:5a/192.168.1.1<-->cb:6f:24:8c:7a:20\n", - "2023-10-08 17:56:35,893: Link 27:a9:09:ed:30:5a/192.168.1.1<-->cb:6f:24:8c:7a:20 up\n", - "2023-10-08 17:56:35,896: Link 27:a9:09:ed:30:5a/192.168.1.1<-->cb:6f:24:8c:7a:20 up\n", - "2023-10-08 17:56:35,897: Added link 41d994cb-2976-4aa2-b306-649cef4deb80 to connect 27:a9:09:ed:30:5a/192.168.1.1 and cb:6f:24:8c:7a:20\n", - "2023-10-08 17:56:35,899: NIC 5c:fa:b1:a4:69:ec/192.168.1.1 connected to Link 5c:fa:b1:a4:69:ec/192.168.1.1<-->68:54:d7:42:04:87\n", - "2023-10-08 17:56:35,900: SwitchPort 68:54:d7:42:04:87 connected to Link 5c:fa:b1:a4:69:ec/192.168.1.1<-->68:54:d7:42:04:87\n", - "2023-10-08 17:56:35,901: Link 5c:fa:b1:a4:69:ec/192.168.1.1<-->68:54:d7:42:04:87 up\n", - "2023-10-08 17:56:35,903: Link 5c:fa:b1:a4:69:ec/192.168.1.1<-->68:54:d7:42:04:87 up\n", - "2023-10-08 17:56:35,904: Added link d582a248-e968-40eb-9d1b-67143d729e0c to connect 5c:fa:b1:a4:69:ec/192.168.1.1 and 68:54:d7:42:04:87\n", - "2023-10-08 17:56:35,905: SwitchPort c6:bd:77:78:4b:5d connected to Link c6:bd:77:78:4b:5d<-->1c:d9:92:e8:d6:3b/192.168.1.10\n", - "2023-10-08 17:56:35,908: Link c6:bd:77:78:4b:5d<-->1c:d9:92:e8:d6:3b/192.168.1.10 up\n", - "2023-10-08 17:56:35,909: NIC 1c:d9:92:e8:d6:3b/192.168.1.10 connected to Link c6:bd:77:78:4b:5d<-->1c:d9:92:e8:d6:3b/192.168.1.10\n", - "2023-10-08 17:56:35,911: Link c6:bd:77:78:4b:5d<-->1c:d9:92:e8:d6:3b/192.168.1.10 up\n", - "2023-10-08 17:56:35,912: Added link 13315780-1fcc-4c85-b94b-ef8f14c88a8a to connect c6:bd:77:78:4b:5d and 1c:d9:92:e8:d6:3b/192.168.1.10\n", - "2023-10-08 17:56:35,913: SwitchPort cd:46:af:c4:33:65 connected to Link cd:46:af:c4:33:65<-->aa:cf:2f:71:13:5b/192.168.1.12\n", - "2023-10-08 17:56:35,916: Link cd:46:af:c4:33:65<-->aa:cf:2f:71:13:5b/192.168.1.12 up\n", - "2023-10-08 17:56:35,917: NIC aa:cf:2f:71:13:5b/192.168.1.12 connected to Link cd:46:af:c4:33:65<-->aa:cf:2f:71:13:5b/192.168.1.12\n", - "2023-10-08 17:56:35,918: Link cd:46:af:c4:33:65<-->aa:cf:2f:71:13:5b/192.168.1.12 up\n", - "2023-10-08 17:56:35,919: Added link 6c2a80f7-f36d-4df6-ac84-d354e5d517dd to connect cd:46:af:c4:33:65 and aa:cf:2f:71:13:5b/192.168.1.12\n", - "2023-10-08 17:56:35,920: SwitchPort 2c:d2:67:ef:68:a8 connected to Link 2c:d2:67:ef:68:a8<-->e1:09:5e:98:ee:a2/192.168.1.14\n", - "2023-10-08 17:56:35,923: Link 2c:d2:67:ef:68:a8<-->e1:09:5e:98:ee:a2/192.168.1.14 up\n", - "2023-10-08 17:56:35,924: NIC e1:09:5e:98:ee:a2/192.168.1.14 connected to Link 2c:d2:67:ef:68:a8<-->e1:09:5e:98:ee:a2/192.168.1.14\n", - "2023-10-08 17:56:35,925: Link 2c:d2:67:ef:68:a8<-->e1:09:5e:98:ee:a2/192.168.1.14 up\n", - "2023-10-08 17:56:35,926: Added link 1cfdd4f2-22be-4e69-8f1f-daef8e18f543 to connect 2c:d2:67:ef:68:a8 and e1:09:5e:98:ee:a2/192.168.1.14\n", - "2023-10-08 17:56:35,927: SwitchPort 9b:13:8c:a0:8c:82 connected to Link 9b:13:8c:a0:8c:82<-->cc:c2:84:03:1c:42/192.168.1.16\n", - "2023-10-08 17:56:35,929: Link 9b:13:8c:a0:8c:82<-->cc:c2:84:03:1c:42/192.168.1.16 up\n", - "2023-10-08 17:56:35,930: NIC cc:c2:84:03:1c:42/192.168.1.16 connected to Link 9b:13:8c:a0:8c:82<-->cc:c2:84:03:1c:42/192.168.1.16\n", - "2023-10-08 17:56:35,932: Link 9b:13:8c:a0:8c:82<-->cc:c2:84:03:1c:42/192.168.1.16 up\n", - "2023-10-08 17:56:35,933: Added link 031111e1-3b05-49ce-bd1f-2cdf77b210f4 to connect 9b:13:8c:a0:8c:82 and cc:c2:84:03:1c:42/192.168.1.16\n", - "2023-10-08 17:56:35,934: SwitchPort a1:70:9e:43:1c:07 connected to Link a1:70:9e:43:1c:07<-->e7:58:3c:ed:f7:37/192.168.1.110\n", - "2023-10-08 17:56:35,937: Link a1:70:9e:43:1c:07<-->e7:58:3c:ed:f7:37/192.168.1.110 up\n", - "2023-10-08 17:56:35,938: NIC e7:58:3c:ed:f7:37/192.168.1.110 connected to Link a1:70:9e:43:1c:07<-->e7:58:3c:ed:f7:37/192.168.1.110\n", - "2023-10-08 17:56:35,939: Link a1:70:9e:43:1c:07<-->e7:58:3c:ed:f7:37/192.168.1.110 up\n", - "2023-10-08 17:56:35,941: Added link f15884e7-0df6-4fa5-bb72-406cb2bdff45 to connect a1:70:9e:43:1c:07 and e7:58:3c:ed:f7:37/192.168.1.110\n", - "2023-10-08 17:56:35,943: SwitchPort a5:da:f2:03:21:e3 connected to Link a5:da:f2:03:21:e3<-->cf:63:9f:62:fe:df/192.168.10.21\n", - "2023-10-08 17:56:35,946: Link a5:da:f2:03:21:e3<-->cf:63:9f:62:fe:df/192.168.10.21 up\n", - "2023-10-08 17:56:35,947: NIC cf:63:9f:62:fe:df/192.168.10.21 connected to Link a5:da:f2:03:21:e3<-->cf:63:9f:62:fe:df/192.168.10.21\n", - "2023-10-08 17:56:35,948: Link a5:da:f2:03:21:e3<-->cf:63:9f:62:fe:df/192.168.10.21 up\n", - "2023-10-08 17:56:35,950: Added link cc6767fa-25de-4daa-bd47-37b49b15a881 to connect a5:da:f2:03:21:e3 and cf:63:9f:62:fe:df/192.168.10.21\n", - "2023-10-08 17:56:35,951: SwitchPort eb:5b:86:14:bd:d1 connected to Link eb:5b:86:14:bd:d1<-->3d:73:a6:62:97:3a/192.168.10.22\n", - "2023-10-08 17:56:35,953: Link eb:5b:86:14:bd:d1<-->3d:73:a6:62:97:3a/192.168.10.22 up\n", - "2023-10-08 17:56:35,954: NIC 3d:73:a6:62:97:3a/192.168.10.22 connected to Link eb:5b:86:14:bd:d1<-->3d:73:a6:62:97:3a/192.168.10.22\n", - "2023-10-08 17:56:35,955: Link eb:5b:86:14:bd:d1<-->3d:73:a6:62:97:3a/192.168.10.22 up\n", - "2023-10-08 17:56:35,958: Added link b29563ed-0636-4188-ba28-52b74a04da27 to connect eb:5b:86:14:bd:d1 and 3d:73:a6:62:97:3a/192.168.10.22\n", - "2023-10-08 17:56:35,959: SwitchPort e3:3a:0b:03:0b:8c connected to Link e3:3a:0b:03:0b:8c<-->d4:ff:37:8d:e4:3d/192.168.10.110\n", - "2023-10-08 17:56:35,961: Link e3:3a:0b:03:0b:8c<-->d4:ff:37:8d:e4:3d/192.168.10.110 up\n", - "2023-10-08 17:56:35,963: NIC d4:ff:37:8d:e4:3d/192.168.10.110 connected to Link e3:3a:0b:03:0b:8c<-->d4:ff:37:8d:e4:3d/192.168.10.110\n", - "2023-10-08 17:56:35,963: Link e3:3a:0b:03:0b:8c<-->d4:ff:37:8d:e4:3d/192.168.10.110 up\n", - "2023-10-08 17:56:35,964: Added link f6fe7757-a8c1-4cdc-a2b2-49d247117903 to connect e3:3a:0b:03:0b:8c and d4:ff:37:8d:e4:3d/192.168.10.110\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "service type not found DatabaseBackup\n", - "service type not found WebBrowser\n" - ] - } - ], - "source": [ - "sess = PrimaiteSession.from_config(cfg)" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[,\n", - " ,\n", - " ]" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "sess.agents" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "network = sess.simulation.network" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-10-08 17:56:36,041: Stepping primaite session. Step counter: 0\n", - "2023-10-08 17:56:36,043: Sending simulation state to agent client_1_green_user\n", - "2023-10-08 17:56:36,045: Getting agent action\n", - "2023-10-08 17:56:36,047: Formatting agent action DONOTHING\n", - "2023-10-08 17:56:36,048: Sending request to simulation: ['do_nothing']\n", - "2023-10-08 17:56:36,050: Sending simulation state to agent client_1_data_manipulation_red_bot\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[]\n", - "[]\n" - ] - }, - { - "ename": "TypeError", - "evalue": "unhashable type: 'DataManipulationBot'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m/home/cade/repos/PrimAITE/sandbox.ipynb Cell 10\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> 1\u001b[0m sess\u001b[39m.\u001b[39;49mstep()\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/session.py:80\u001b[0m, in \u001b[0;36mPrimaiteSession.step\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 77\u001b[0m sim_state \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39msimulation\u001b[39m.\u001b[39mdescribe_state()\n\u001b[1;32m 79\u001b[0m \u001b[39m# 6. each agent takes most recent state and converts it to CAOS observation\u001b[39;00m\n\u001b[0;32m---> 80\u001b[0m agent_obs \u001b[39m=\u001b[39m agent\u001b[39m.\u001b[39;49mconvert_state_to_obs(sim_state)\n\u001b[1;32m 82\u001b[0m \u001b[39m# 7. meanwhile each agent also takes state and calculates reward\u001b[39;00m\n\u001b[1;32m 83\u001b[0m agent_reward \u001b[39m=\u001b[39m agent\u001b[39m.\u001b[39mcalculate_reward_from_state(sim_state)\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/interface.py:40\u001b[0m, in \u001b[0;36mAbstractAgent.convert_state_to_obs\u001b[0;34m(self, state)\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mconvert_state_to_obs\u001b[39m(\u001b[39mself\u001b[39m, state: Dict) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m ObsType:\n\u001b[1;32m 36\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 37\u001b[0m \u001b[39m state : dict state directly from simulation.describe_state\u001b[39;00m\n\u001b[1;32m 38\u001b[0m \u001b[39m output : dict state according to CAOS.\u001b[39;00m\n\u001b[1;32m 39\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m---> 40\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mobservation_space\u001b[39m.\u001b[39;49mobserve(state)\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:608\u001b[0m, in \u001b[0;36mObservationSpace.observe\u001b[0;34m(self, state)\u001b[0m\n\u001b[1;32m 607\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mobserve\u001b[39m(\u001b[39mself\u001b[39m, state) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Dict:\n\u001b[0;32m--> 608\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mobs\u001b[39m.\u001b[39;49mobserve(state)\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:571\u001b[0m, in \u001b[0;36mUC2RedObservation.observe\u001b[0;34m(self, state)\u001b[0m\n\u001b[1;32m 568\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdefault_observation\n\u001b[1;32m 570\u001b[0m obs \u001b[39m=\u001b[39m {}\n\u001b[0;32m--> 571\u001b[0m obs[\u001b[39m'\u001b[39m\u001b[39mNODES\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m {i\u001b[39m+\u001b[39m\u001b[39m1\u001b[39m: node\u001b[39m.\u001b[39mobserve(state) \u001b[39mfor\u001b[39;00m i, node \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnodes)}\n\u001b[1;32m 572\u001b[0m \u001b[39mreturn\u001b[39;00m obs\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:571\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 568\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdefault_observation\n\u001b[1;32m 570\u001b[0m obs \u001b[39m=\u001b[39m {}\n\u001b[0;32m--> 571\u001b[0m obs[\u001b[39m'\u001b[39m\u001b[39mNODES\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m {i\u001b[39m+\u001b[39m\u001b[39m1\u001b[39m: node\u001b[39m.\u001b[39;49mobserve(state) \u001b[39mfor\u001b[39;00m i, node \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mnodes)}\n\u001b[1;32m 572\u001b[0m \u001b[39mreturn\u001b[39;00m obs\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:328\u001b[0m, in \u001b[0;36mNodeObservation.observe\u001b[0;34m(self, state)\u001b[0m\n\u001b[1;32m 326\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mservices)\n\u001b[1;32m 327\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfolders)\n\u001b[0;32m--> 328\u001b[0m obs[\u001b[39m\"\u001b[39m\u001b[39mSERVICES\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m {i \u001b[39m+\u001b[39m \u001b[39m1\u001b[39m: service\u001b[39m.\u001b[39mobserve(state) \u001b[39mfor\u001b[39;00m i, service \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mservices)}\n\u001b[1;32m 329\u001b[0m obs[\u001b[39m\"\u001b[39m\u001b[39mFOLDERS\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m {i \u001b[39m+\u001b[39m \u001b[39m1\u001b[39m: folder\u001b[39m.\u001b[39mobserve(state) \u001b[39mfor\u001b[39;00m i, folder \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfolders)}\n\u001b[1;32m 330\u001b[0m obs[\u001b[39m\"\u001b[39m\u001b[39moperating_status\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m node_state[\u001b[39m\"\u001b[39m\u001b[39moperating_state\u001b[39m\u001b[39m\"\u001b[39m]\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:328\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 326\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mservices)\n\u001b[1;32m 327\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfolders)\n\u001b[0;32m--> 328\u001b[0m obs[\u001b[39m\"\u001b[39m\u001b[39mSERVICES\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m {i \u001b[39m+\u001b[39m \u001b[39m1\u001b[39m: service\u001b[39m.\u001b[39;49mobserve(state) \u001b[39mfor\u001b[39;00m i, service \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mservices)}\n\u001b[1;32m 329\u001b[0m obs[\u001b[39m\"\u001b[39m\u001b[39mFOLDERS\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m {i \u001b[39m+\u001b[39m \u001b[39m1\u001b[39m: folder\u001b[39m.\u001b[39mobserve(state) \u001b[39mfor\u001b[39;00m i, folder \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfolders)}\n\u001b[1;32m 330\u001b[0m obs[\u001b[39m\"\u001b[39m\u001b[39moperating_status\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m node_state[\u001b[39m\"\u001b[39m\u001b[39moperating_state\u001b[39m\u001b[39m\"\u001b[39m]\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:124\u001b[0m, in \u001b[0;36mServiceObservation.observe\u001b[0;34m(self, state)\u001b[0m\n\u001b[1;32m 121\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mwhere \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 122\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdefault_observation\n\u001b[0;32m--> 124\u001b[0m service_state \u001b[39m=\u001b[39m access_from_nested_dict(state, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mwhere)\n\u001b[1;32m 125\u001b[0m \u001b[39mif\u001b[39;00m service_state \u001b[39mis\u001b[39;00m NOT_PRESENT_IN_STATE:\n\u001b[1;32m 126\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdefault_observation\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:37\u001b[0m, in \u001b[0;36maccess_from_nested_dict\u001b[0;34m(dictionary, keys)\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[39mif\u001b[39;00m k \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m dictionary:\n\u001b[1;32m 36\u001b[0m \u001b[39mreturn\u001b[39;00m NOT_PRESENT_IN_STATE\n\u001b[0;32m---> 37\u001b[0m \u001b[39mreturn\u001b[39;00m access_from_nested_dict(dictionary[k], keys)\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:37\u001b[0m, in \u001b[0;36maccess_from_nested_dict\u001b[0;34m(dictionary, keys)\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[39mif\u001b[39;00m k \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m dictionary:\n\u001b[1;32m 36\u001b[0m \u001b[39mreturn\u001b[39;00m NOT_PRESENT_IN_STATE\n\u001b[0;32m---> 37\u001b[0m \u001b[39mreturn\u001b[39;00m access_from_nested_dict(dictionary[k], keys)\n", - " \u001b[0;31m[... skipping similar frames: access_from_nested_dict at line 37 (1 times)]\u001b[0m\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:37\u001b[0m, in \u001b[0;36maccess_from_nested_dict\u001b[0;34m(dictionary, keys)\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[39mif\u001b[39;00m k \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m dictionary:\n\u001b[1;32m 36\u001b[0m \u001b[39mreturn\u001b[39;00m NOT_PRESENT_IN_STATE\n\u001b[0;32m---> 37\u001b[0m \u001b[39mreturn\u001b[39;00m access_from_nested_dict(dictionary[k], keys)\n", - "File \u001b[0;32m~/repos/PrimAITE/src/primaite/game/agent/observations.py:35\u001b[0m, in \u001b[0;36maccess_from_nested_dict\u001b[0;34m(dictionary, keys)\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[39mreturn\u001b[39;00m dictionary\n\u001b[1;32m 34\u001b[0m k \u001b[39m=\u001b[39m keys\u001b[39m.\u001b[39mpop(\u001b[39m0\u001b[39m)\n\u001b[0;32m---> 35\u001b[0m \u001b[39mif\u001b[39;00m k \u001b[39mnot\u001b[39;49;00m \u001b[39min\u001b[39;49;00m dictionary:\n\u001b[1;32m 36\u001b[0m \u001b[39mreturn\u001b[39;00m NOT_PRESENT_IN_STATE\n\u001b[1;32m 37\u001b[0m \u001b[39mreturn\u001b[39;00m access_from_nested_dict(dictionary[k], keys)\n", - "\u001b[0;31mTypeError\u001b[0m: unhashable type: 'DataManipulationBot'" - ] - } - ], - "source": [ - "sess.step()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from ipaddress import IPv4Address\n", - "\n", - "from primaite.simulator.network.container import Network\n", - "from primaite.simulator.network.hardware.base import NIC\n", - "from primaite.simulator.network.hardware.nodes.computer import Computer\n", - "from primaite.simulator.network.hardware.nodes.router import ACLAction, Router\n", - "from primaite.simulator.network.hardware.nodes.server import Server\n", - "from primaite.simulator.network.hardware.nodes.switch import Switch\n", - "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", - "from primaite.simulator.network.transmission.transport_layer import Port\n", - "from primaite.simulator.system.applications.database_client import DatabaseClient\n", - "from primaite.simulator.system.services.database_service import DatabaseService\n", - "from primaite.simulator.system.services.dns_client import DNSClient\n", - "from primaite.simulator.system.services.dns_server import DNSServer\n", - "from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "router_1 = Router(hostname=\"router_1\", num_ports=5)\n", - "router_1.power_on()\n", - "router_1.configure_port(port=1, ip_address=\"192.168.1.1\", subnet_mask=\"255.255.255.0\")\n", - "router_1.configure_port(port=2, ip_address=\"192.168.10.1\", subnet_mask=\"255.255.255.0\")\n", - "\n", - "# Switch 1\n", - "switch_1 = Switch(hostname=\"switch_1\", num_ports=8)\n", - "switch_1.power_on()\n", - "network.connect(endpoint_a=router_1.ethernet_ports[1], endpoint_b=switch_1.switch_ports[8])\n", - "router_1.enable_port(1)\n", - "\n", - "# Switch 2\n", - "switch_2 = Switch(hostname=\"switch_2\", num_ports=8)\n", - "switch_2.power_on()\n", - "network.connect(endpoint_a=router_1.ethernet_ports[2], endpoint_b=switch_2.switch_ports[8])\n", - "router_1.enable_port(2)\n", - "\n", - "# Client 1\n", - "client_1 = Computer(\n", - " hostname=\"client_1\",\n", - " ip_address=\"192.168.10.21\",\n", - " subnet_mask=\"255.255.255.0\",\n", - " default_gateway=\"192.168.10.1\",\n", - " dns_server=IPv4Address(\"192.168.1.10\"),\n", - ")\n", - "client_1.power_on()\n", - "client_1.software_manager.install(DNSClient)\n", - "client_1_dns_client_service: DNSServer = client_1.software_manager.software[\"DNSClient\"] # noqa\n", - "client_1_dns_client_service.start()\n", - "network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1])\n", - "client_1.software_manager.install(DataManipulationBot)\n", - "db_manipulation_bot: DataManipulationBot = client_1.software_manager.software[\"DataManipulationBot\"]\n", - "db_manipulation_bot.configure(server_ip_address=IPv4Address(\"192.168.1.14\"), payload=\"DROP TABLE IF EXISTS user;\")\n", - "\n", - "# Client 2\n", - "client_2 = Computer(\n", - " hostname=\"client_2\",\n", - " ip_address=\"192.168.10.22\",\n", - " subnet_mask=\"255.255.255.0\",\n", - " default_gateway=\"192.168.10.1\",\n", - " dns_server=IPv4Address(\"192.168.1.10\"),\n", - ")\n", - "client_2.power_on()\n", - "client_2.software_manager.install(DNSClient)\n", - "client_2_dns_client_service: DNSServer = client_2.software_manager.software[\"DNSClient\"] # noqa\n", - "client_2_dns_client_service.start()\n", - "network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2])\n", - "\n", - "# Domain Controller\n", - "domain_controller = Server(\n", - " hostname=\"domain_controller\",\n", - " ip_address=\"192.168.1.10\",\n", - " subnet_mask=\"255.255.255.0\",\n", - " default_gateway=\"192.168.1.1\",\n", - ")\n", - "domain_controller.power_on()\n", - "domain_controller.software_manager.install(DNSServer)\n", - "\n", - "network.connect(endpoint_b=domain_controller.ethernet_port[1], endpoint_a=switch_1.switch_ports[1])\n", - "\n", - "# Database Server\n", - "database_server = Server(\n", - " hostname=\"database_server\",\n", - " ip_address=\"192.168.1.14\",\n", - " subnet_mask=\"255.255.255.0\",\n", - " default_gateway=\"192.168.1.1\",\n", - " dns_server=IPv4Address(\"192.168.1.10\"),\n", - ")\n", - "database_server.power_on()\n", - "network.connect(endpoint_b=database_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[3])\n", - "\n", - "ddl = \"\"\"\n", - "CREATE TABLE IF NOT EXISTS user (\n", - "id INTEGER PRIMARY KEY AUTOINCREMENT,\n", - "name VARCHAR(50) NOT NULL,\n", - "email VARCHAR(50) NOT NULL,\n", - "age INT,\n", - "city VARCHAR(50),\n", - "occupation VARCHAR(50)\n", - ");\"\"\"\n", - "\n", - "user_insert_statements = [\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('John Doe', 'johndoe@example.com', 32, 'New York', 'Engineer');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Jane Smith', 'janesmith@example.com', 27, 'Los Angeles', 'Designer');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Bob Johnson', 'bobjohnson@example.com', 45, 'Chicago', 'Manager');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Alice Lee', 'alicelee@example.com', 22, 'San Francisco', 'Student');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('David Kim', 'davidkim@example.com', 38, 'Houston', 'Consultant');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Emily Chen', 'emilychen@example.com', 29, 'Seattle', 'Software Developer');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Frank Wang', 'frankwang@example.com', 55, 'New York', 'Entrepreneur');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Grace Park', 'gracepark@example.com', 31, 'Los Angeles', 'Marketing Specialist');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Henry Wu', 'henrywu@example.com', 40, 'Chicago', 'Accountant');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Isabella Kim', 'isabellakim@example.com', 26, 'San Francisco', 'Graphic Designer');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Jake Lee', 'jakelee@example.com', 33, 'Houston', 'Sales Manager');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Kelly Chen', 'kellychen@example.com', 28, 'Seattle', 'Web Developer');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Lucas Liu', 'lucasliu@example.com', 42, 'New York', 'Lawyer');\", # noqa\n", - " \"INSERT INTO user (name, email, age, city, occupation) VALUES ('Maggie Wang', 'maggiewang@example.com', 30, 'Los Angeles', 'Data Analyst');\", # noqa\n", - "]\n", - "database_server.software_manager.install(DatabaseService)\n", - "database_service: DatabaseService = database_server.software_manager.software[\"DatabaseService\"] # noqa\n", - "database_service.start()\n", - "database_service._process_sql(ddl, None) # noqa\n", - "for insert_statement in user_insert_statements:\n", - " database_service._process_sql(insert_statement, None) # noqa\n", - "\n", - "# Web Server\n", - "web_server = Server(\n", - " hostname=\"web_server\",\n", - " ip_address=\"192.168.1.12\",\n", - " subnet_mask=\"255.255.255.0\",\n", - " default_gateway=\"192.168.1.1\",\n", - " dns_server=IPv4Address(\"192.168.1.10\"),\n", - ")\n", - "web_server.power_on()\n", - "web_server.software_manager.install(DatabaseClient)\n", - "\n", - "database_client: DatabaseClient = web_server.software_manager.software[\"DatabaseClient\"]\n", - "database_client.configure(server_ip_address=IPv4Address(\"192.168.1.14\"))\n", - "network.connect(endpoint_b=web_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[2])\n", - "database_client.run()\n", - "database_client.connect()\n", - "\n", - "# register the web_server to a domain\n", - "dns_server_service: DNSServer = domain_controller.software_manager.software[\"DNSServer\"] # noqa\n", - "dns_server_service.start()\n", - "dns_server_service.dns_register(\"arcd.com\", web_server.ip_address)\n", - "\n", - "# Backup Server\n", - "backup_server = Server(\n", - " hostname=\"backup_server\",\n", - " ip_address=\"192.168.1.16\",\n", - " subnet_mask=\"255.255.255.0\",\n", - " default_gateway=\"192.168.1.1\",\n", - " dns_server=IPv4Address(\"192.168.1.10\"),\n", - ")\n", - "backup_server.power_on()\n", - "network.connect(endpoint_b=backup_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[4])\n", - "\n", - "# Security Suite\n", - "security_suite = Server(\n", - " hostname=\"security_suite\",\n", - " ip_address=\"192.168.1.110\",\n", - " subnet_mask=\"255.255.255.0\",\n", - " default_gateway=\"192.168.1.1\",\n", - " dns_server=IPv4Address(\"192.168.1.10\"),\n", - ")\n", - "security_suite.power_on()\n", - "network.connect(endpoint_b=security_suite.ethernet_port[1], endpoint_a=switch_1.switch_ports[7])\n", - "security_suite.connect_nic(NIC(ip_address=\"192.168.10.110\", subnet_mask=\"255.255.255.0\"))\n", - "network.connect(endpoint_b=security_suite.ethernet_port[2], endpoint_a=switch_2.switch_ports[7])\n", - "\n", - "router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22)\n", - "\n", - "router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23)\n", - "\n", - "# Allow PostgreSQL requests\n", - "router_1.acl.add_rule(\n", - " action=ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER, position=0\n", - ")\n", - "\n", - "# Allow DNS requests\n", - "router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.DNS, dst_port=Port.DNS, position=1)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "node_uuid_list = list(sess.simulation.network.nodes.keys())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from primaite.game.agent.actions import ActionManager" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "actman = ActionManager(sess.simulation, [\"DONOTHING\", \"NODE_SERVICE_SCAN\", \"NODE_SERVICE_STOP\", \"NODE_FOLDER_SCAN\"],node_uuid_list,act_map={\n", - " 0:{\n", - " \"action\": \"DONOTHING\",\n", - " \"options\": {}\n", - " },\n", - " 1:{\n", - " \"action\": \"NODE_SERVICE_SCAN\",\n", - " \"options\": {\"node_id\":0, \"service_id\":0},\n", - " },\n", - " 2:{\n", - " \"action\": \"NODE_SERVICE_SCAN\",\n", - " \"options\": {\"node_id\":1, \"service_id\":0},\n", - " },\n", - " 3:{\n", - " \"action\": \"NODE_FOLDER_SCAN\",\n", - " \"options\": {\"node_id\":4, \"folder_id\":0},\n", - " }\n", - "})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "act_id, act_options = actman.get_action(3)\n", - "my_trial_act = actman.form_request(action_identifier=act_id, action_options=act_options)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sess.simulation.apply_action(my_trial_act)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "my_trial_act" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sess.step()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sess.step_counter" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from gym import spaces" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sp = spaces.Tuple( (spaces.MultiDiscrete([3, 2]), spaces.MultiDiscrete([3, 2]), spaces.MultiDiscrete([3, 2]),))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sp.sample()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ "import yaml\n", - "from primaite.simulator.sim_container import Simulation\n", - "from primaite.simulator.network.hardware.nodes.computer import Computer\n", - "from primaite.simulator.network.hardware.nodes.server import Server\n", - "from primaite.simulator.network.hardware.nodes.switch import Switch\n", - "from primaite.simulator.network.hardware.nodes.router import Router\n", "\n", - "from primaite.simulator.system.applications.database_client import DatabaseClient\n", - "from primaite.simulator.system.services.database_service import DatabaseService\n", - "from primaite.simulator.system.services.dns_client import DNSClient\n", - "from primaite.simulator.system.services.dns_server import DNSServer\n", - "from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot\n", - "\n", - "\n", - "from primaite.simulator.network.hardware.nodes.router import ACLAction\n", - "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", - "from primaite.simulator.network.transmission.transport_layer import Port\n", - "\n", - "from ipaddress import IPv4Address\n" + "with open('example_config.yaml', 'r') as file:\n", + " cfg = yaml.safe_load(file)\n", + "sess = PrimaiteSession.from_config(cfg)\n", + "sess.step()" ] }, { @@ -572,238 +33,9 @@ "metadata": {}, "outputs": [], "source": [ - "# import yaml\n", - "\n", - "\n", - "from typing import Dict\n", - "from primaite.game.agent.interface import AbstractAgent\n", - "from primaite.game.agent.observations import AclObservation, FileObservation, FolderObservation, ICSObservation, LinkObservation, NicObservation, NodeObservation, NullObservation, ServiceObservation, UC2BlueObservation, UC2RedObservation\n", - "from primaite.simulator.network.hardware.base import NIC, Link, Node\n", - "from primaite.simulator.system.services.service import Service\n", - "\n", - "from primaite.game.agent.scripted_agents import GreenWebBrowsingAgent, RedDatabaseCorruptingAgent\n", - "from primaite.game.agent.GATE_agents import GATERLAgent\n", - "\n", - "class PrimaiteSession:\n", - "\n", - " def __init__(self):\n", - " self.simulation: Simulation\n", - " self.agents = []\n", - "\n", - " @classmethod\n", - " def from_config(cls, cfg_path):\n", - " ref_map_nodes: Dict[str,Node] = {}\n", - " ref_map_services: Dict[str, Service] = {}\n", - " ref_map_links: Dict[str, Link] = {}\n", - " # ref_map_agents: Dict[str, AgentInterface] = {}\n", - "\n", - "\n", - " session = cls()\n", - " with open(cfg_path, 'r') as file:\n", - " conf = yaml.safe_load(file)\n", - "\n", - " #1. create nodes\n", - " sim = Simulation()\n", - " net = sim.network\n", - " nodes_cfg = conf['simulation']['network']['nodes']\n", - " links_cfg = conf['simulation']['network']['links']\n", - " for node_cfg in nodes_cfg:\n", - " node_ref = node_cfg['ref']\n", - " n_type = node_cfg['type']\n", - " if n_type == 'computer':\n", - " new_node = Computer(hostname = node_cfg['hostname'],\n", - " ip_address = node_cfg['ip_address'],\n", - " subnet_mask = node_cfg['subnet_mask'],\n", - " default_gateway = node_cfg['default_gateway'],\n", - " dns_server = node_cfg['dns_server'])\n", - " elif n_type == 'server':\n", - " new_node = Server(hostname = node_cfg['hostname'],\n", - " ip_address = node_cfg['ip_address'],\n", - " subnet_mask = node_cfg['subnet_mask'],\n", - " default_gateway = node_cfg['default_gateway'],\n", - " dns_server = node_cfg.get('dns_server'))\n", - " elif n_type == 'switch':\n", - " new_node = Switch(hostname = node_cfg['hostname'],\n", - " num_ports = node_cfg.get('num_ports'))\n", - " elif n_type == 'router':\n", - " new_node = Router(hostname=node_cfg['hostname'],\n", - " num_ports = node_cfg.get('num_ports'))\n", - " if 'ports' in node_cfg:\n", - " for port_num, port_cfg in node_cfg['ports'].items():\n", - " new_node.configure_port(port=port_num,\n", - " ip_address=port_cfg['ip_address'],\n", - " subnet_mask=port_cfg['subnet_mask'])\n", - " if 'acl' in node_cfg:\n", - " for r_num, r_cfg in node_cfg['acl'].items():\n", - " # excuse the uncommon walrus operator ` := `. It's just here as a shorthand, to avoid repeating\n", - " # this: 'r_cfg.get('src_port')'\n", - " # Port/IPProtocol. TODO Refactor\n", - " new_node.acl.add_rule(\n", - " action = ACLAction[r_cfg['action']],\n", - " src_port = None if not (p:=r_cfg.get('src_port')) else Port[p],\n", - " dst_port = None if not (p:=r_cfg.get('dst_port')) else Port[p],\n", - " protocol = None if not (p:=r_cfg.get('protocol')) else IPProtocol[p],\n", - " src_ip_address = r_cfg.get('ip_address'),\n", - " dst_ip_address = r_cfg.get('ip_address'),\n", - " position = r_num\n", - " )\n", - " else:\n", - " print('invalid node type')\n", - " if 'services' in node_cfg:\n", - " for service_cfg in node_cfg['services']:\n", - " service_ref = service_cfg['ref']\n", - " service_type = service_cfg['type']\n", - " service_types_mapping = {\n", - " 'DNSClient': DNSClient, # key is equal to the 'name' attr of the service class itself.\n", - " 'DNSServer' : DNSServer,\n", - " 'DatabaseClient': DatabaseClient,\n", - " 'DatabaseService': DatabaseService,\n", - " # 'database_backup': ,\n", - " 'DataManipulationBot': DataManipulationBot,\n", - " # 'web_browser'\n", - " }\n", - " if service_type in service_types_mapping:\n", - " new_node.software_manager.install(service_types_mapping[service_type])\n", - " new_service = new_node.software_manager.software[service_type]\n", - " ref_map_services[service_ref] = new_service\n", - " else:\n", - " print(f\"service type not found {service_type}\")\n", - " # service-dependent options\n", - " if service_type == 'DatabaseClient':\n", - " if 'options' in service_cfg:\n", - " opt = service_cfg['options']\n", - " if 'db_server_ip' in opt:\n", - " new_service.configure(server_ip_address=IPv4Address(opt['db_server_ip']))\n", - " if service_type == 'DNSServer':\n", - " if 'options' in service_cfg:\n", - " opt = service_cfg['options']\n", - " if 'domain_mapping' in opt:\n", - " for domain, ip in opt['domain_mapping'].items():\n", - " new_service.dns_register(domain, ip)\n", - " if 'nics' in node_cfg:\n", - " for nic_num, nic_cfg in node_cfg['nics'].items():\n", - " new_node.connect_nic(NIC(ip_address=nic_cfg['ip_address'], subnet_mask=nic_cfg['subnet_mask']))\n", - "\n", - " net.add_node(new_node)\n", - " new_node.power_on()\n", - " ref_map_nodes[node_ref] = new_node.uuid\n", - "\n", - " #2. create links between nodes\n", - " for link_cfg in links_cfg:\n", - " node_a = net.nodes[ref_map_nodes[link_cfg['endpoint_a_ref']]]\n", - " node_b = net.nodes[ref_map_nodes[link_cfg['endpoint_b_ref']]]\n", - " if isinstance(node_a, Switch):\n", - " endpoint_a = node_a.switch_ports[link_cfg['endpoint_a_port']]\n", - " else:\n", - " endpoint_a = node_a.ethernet_port[link_cfg['endpoint_a_port']]\n", - " if isinstance(node_b, Switch):\n", - " endpoint_b = node_b.switch_ports[link_cfg['endpoint_b_port']]\n", - " else:\n", - " endpoint_b = node_b.ethernet_port[link_cfg['endpoint_b_port']]\n", - " new_link = net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b)\n", - " ref_map_links[link_cfg['ref']] = new_link.uuid\n", - "\n", - " session.simulation = sim\n", - " #3. create agents\n", - " game_cfg = conf['game_config']\n", - " ports_cfg = game_cfg['ports']\n", - " protocols_cfg = game_cfg['protocols']\n", - " agents_cfg = game_cfg['agents']\n", - "\n", - " for agent_cfg in agents_cfg:\n", - " agent_ref = agent_cfg['ref']\n", - " agent_type = agent_cfg['type']\n", - " action_space_cfg = agent_cfg['action_space']\n", - " observation_space_cfg = agent_cfg['observation_space']\n", - " reward_function_cfg = agent_cfg['reward_function']\n", - "\n", - " # CREATE OBSERVATION SPACE\n", - " if observation_space_cfg is None:\n", - " obs_space = NullObservation()\n", - " elif observation_space_cfg['type'] == 'UC2BlueObservation':\n", - " node_obs_list = []\n", - " link_obs_list = []\n", - "\n", - "\n", - " #node ip to index maps ip addresses to node id, as there are potentially multiple nics on a node, there are multiple ip addresses\n", - " node_ip_to_index = {}\n", - " for node_idx, node_cfg in enumerate(nodes_cfg):\n", - " n_ref = node_cfg['ref']\n", - " n_obj = net.nodes[ref_map_nodes[n_ref]]\n", - " for nic_uuid, nic_obj in n_obj.nics.items():\n", - " node_ip_to_index[nic_obj.ip_address] = node_idx + 2\n", - "\n", - "\n", - "\n", - " for node_obs_cfg in observation_space_cfg['options']['nodes']:\n", - " node_ref = node_obs_cfg['node_ref']\n", - " folder_obs_list = []\n", - " service_obs_list = []\n", - " if 'services' in node_obs_cfg:\n", - " for service_obs_cfg in node_obs_cfg['services']:\n", - " service_obs_list.append(ServiceObservation(where=['network','nodes',ref_map_nodes[node_ref],'services',ref_map_services[service_obs_cfg['service_ref']]]))\n", - " if 'folders' in node_obs_cfg:\n", - " for folder_obs_cfg in node_obs_cfg['folders']:\n", - " file_obs_list = []\n", - " if 'files' in folder_obs_cfg:\n", - " for file_obs_cfg in folder_obs_cfg['files']:\n", - " file_obs_list.append(FileObservation(where=['network','nodes',ref_map_nodes[node_ref], 'folders',folder_obs_cfg['folder_name'], 'files', file_obs_cfg['file_name']]))\n", - " folder_obs_list.append(FolderObservation(where=['network','nodes',ref_map_nodes[node_ref], 'folders',folder_obs_cfg['folder_name']], files=file_obs_list))\n", - " nic_obs_list = []\n", - " for nic_uuid in net.nodes[ref_map_nodes[node_obs_cfg['node_ref']]].nics.keys():\n", - " nic_obs_list.append(NicObservation(where=['network','nodes',ref_map_nodes[node_ref],'NICs',nic_uuid]))\n", - " node_obs_list.append(NodeObservation(where=['network','nodes',ref_map_nodes[node_ref]], services=service_obs_list, folders=folder_obs_list,nics=nic_obs_list, logon_status=False))\n", - " for link_obs_cfg in observation_space_cfg['options']['links']:\n", - " link_ref = link_obs_cfg['link_ref']\n", - " link_obs_list.append(LinkObservation(where=['network' ,'links', ref_map_links[link_ref]]))\n", - "\n", - " acl_obs = AclObservation(node_ip_to_id=node_ip_to_index, ports=game_cfg['ports'], protocols=game_cfg['ports'], where=['network','nodes',observation_space_cfg['options']['acl']['router_node_ref']])\n", - " obs_space = UC2BlueObservation(nodes=node_obs_list,links=link_obs_list,acl=acl_obs, ics=ICSObservation())\n", - " elif observation_space_cfg['type'] == 'UC2RedObservation':\n", - " obs_space = UC2RedObservation.from_config(observation_space_cfg['options'], sim=sim)\n", - " else:\n", - " print(\"observation space config not specified correctly.\")\n", - " obs_space = NullObservation()\n", - "\n", - " # CREATE ACTION SPACE\n", - "\n", - "\n", - "\n", - " # CREATE REWARD FUNCTION\n", - "\n", - " # CREATE AGENT\n", - " if agent_type == 'GreenWebBrowsingAgent':\n", - " ...\n", - " elif agent_type == 'GATERLAgent':\n", - " ...\n", - " elif agent_type == 'RedDatabaseCorruptingAgent':\n", - " ...\n", - " else:\n", - " print(\"agent type not found\")\n", - "\n", - "\n", - " #4. set up agents' actions and observation spaces.\n", - " return session\n", - "\n", - "s = PrimaiteSession.from_config('example_config.yaml')\n", - "# print(s.simulation.describe_state())" + "for i in range(50):\n", + " sess.step()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "s.agents" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From c9bc8fbf3d512f2ba3fecec1ff008ad2e8a57bb3 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 9 Oct 2023 18:33:30 +0100 Subject: [PATCH 220/980] Fix file observation test --- tests/integration_tests/game_layer/test_observations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tests/game_layer/test_observations.py b/tests/integration_tests/game_layer/test_observations.py index 7f20a938..c1f20d78 100644 --- a/tests/integration_tests/game_layer/test_observations.py +++ b/tests/integration_tests/game_layer/test_observations.py @@ -16,5 +16,5 @@ def test_file_observation(): dog_file_obs = FileObservation( where=["network", "nodes", pc.uuid, "file_system", "folders", "root", "files", "dog.png"] ) - assert dog_file_obs(state) == {"health_status": 1} + assert dog_file_obs.observe(state) == {"health_status": 1} assert dog_file_obs.space == spaces.Dict({"health_status": spaces.Discrete(6)}) From 91f06c15f6d52ef821dde93f5ad7ec7d23f95072 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 9 Oct 2023 18:35:30 +0100 Subject: [PATCH 221/980] Fix formatting with precommit --- src/primaite/game/agent/actions.py | 67 +++---- src/primaite/game/agent/interface.py | 6 +- src/primaite/game/agent/observations.py | 185 ++++++++++-------- src/primaite/game/agent/rewards.py | 26 +-- src/primaite/game/session.py | 61 +++--- .../network/hardware/nodes/switch.py | 4 +- 6 files changed, 189 insertions(+), 160 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 1e6893ff..cba90305 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -4,8 +4,9 @@ from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING from gym import spaces -from primaite.simulator.sim_container import Simulation from primaite import getLogger +from primaite.simulator.sim_container import Simulation + _LOGGER = getLogger(__name__) if TYPE_CHECKING: @@ -90,56 +91,56 @@ class NodeServiceAbstractAction(AbstractAction): class NodeServiceScanAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "scan" class NodeServiceStopAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "stop" class NodeServiceStartAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "start" class NodeServicePauseAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "pause" class NodeServiceResumeAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "resume" class NodeServiceRestartAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "restart" class NodeServiceDisableAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "disable" class NodeServiceEnableAction(NodeServiceAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes:int, num_services:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "enable" class NodeFolderAbstractAction(AbstractAction): @abstractmethod - def __init__(self, manager: "ActionManager", num_nodes:int, num_folders:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, **kwargs) -> None: super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes, "folder_id": num_folders} self.verb: str @@ -153,25 +154,25 @@ class NodeFolderAbstractAction(AbstractAction): class NodeFolderScanAction(NodeFolderAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes:int, num_folders:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, **kwargs) self.verb: str = "scan" class NodeFolderCheckhashAction(NodeFolderAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes:int, num_folders:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, **kwargs) self.verb: str = "checkhash" class NodeFolderRepairAction(NodeFolderAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes:int, num_folders:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, **kwargs) self.verb: str = "repair" class NodeFolderRestoreAction(NodeFolderAbstractAction): - def __init__(self, manager: "ActionManager", num_nodes:int, num_folders:int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, **kwargs) self.verb: str = "restore" @@ -293,7 +294,7 @@ class NetworkACLAddRuleAction(AbstractAction): ) -> List[str]: if permission == 0: permission_str = "UNUSED" - return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS + return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS elif permission == 1: permission_str = "ALLOW" elif permission == 2: @@ -302,30 +303,30 @@ class NetworkACLAddRuleAction(AbstractAction): _LOGGER.warn(f"{self.__class__} received permission {permission}, expected 0 or 1.") if protocol_id == 0: - return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS + return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS if protocol_id == 1: protocol = "ALL" else: - protocol = self.manager.get_internet_protocol_by_idx(protocol_id-2) + protocol = self.manager.get_internet_protocol_by_idx(protocol_id - 2) # subtract 2 to account for UNUSED=0 and ALL=1. - if source_ip_id in [0,1]: + if source_ip_id in [0, 1]: src_ip = "ALL" - return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS + return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS else: - src_ip = self.manager.get_ip_address_by_idx(source_ip_id-2) + src_ip = self.manager.get_ip_address_by_idx(source_ip_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 if source_port_id == 1: src_port = "ALL" else: - src_port = self.manager.get_port_by_idx(source_port_id-2) + src_port = self.manager.get_port_by_idx(source_port_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 - if dest_ip_id in (0,1): + if dest_ip_id in (0, 1): dst_ip = "ALL" - return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS + return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS else: dst_ip = self.manager.get_ip_address_by_idx(dest_ip_id) # subtract 2 to account for UNUSED=0, and ALL=1 @@ -394,6 +395,7 @@ class NetworkNICDisableAction(NetworkNICAbstractAction): super().__init__(manager=manager, num_nodes=num_nodes, max_nics_per_node=max_nics_per_node, **kwargs) self.verb = "disable" + # class NetworkNICDisableAction(AbstractAction): # def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: # super().__init__(manager=manager) @@ -495,7 +497,7 @@ class ActionManager: "num_protocols": len(self.protocols), "num_ports": len(self.protocols), "num_ips": len(self.ip_address_list), - "max_acl_rules":max_acl_rules, + "max_acl_rules": max_acl_rules, "max_nics_per_node": max_nics_per_node, } self.actions: Dict[str, AbstractAction] = {} @@ -507,8 +509,8 @@ class ActionManager: # option_2: value2 # where `type` decides which AbstractAction subclass should be used # and `options` is an optional dict of options to pass to the init method of the action class - act_type = act_spec.get('type') - act_options = act_spec.get('options', {}) + act_type = act_spec.get("type") + act_options = act_spec.get("options", {}) self.actions[act_type] = self.__act_class_identifiers[act_type](self, **global_action_args, **act_options) self.action_map: Dict[int, Tuple[str, Dict]] = {} @@ -555,13 +557,12 @@ class ActionManager: param_combinations = list(itertools.product(*possibilities)) all_action_possibilities.extend( [ - ( - act_name, {param_names[i]:param_combinations[j][i] for i in range(len(param_names))} - ) for j in range(len(param_combinations))] - ) - - return {i:p for i,p in enumerate(all_action_possibilities)} + (act_name, {param_names[i]: param_combinations[j][i] for i in range(len(param_names))}) + for j in range(len(param_combinations)) + ] + ) + return {i: p for i, p in enumerate(all_action_possibilities)} def get_action(self, action: int) -> Tuple[str, Dict]: """Produce action in CAOS format""" @@ -627,7 +628,7 @@ class ActionManager: session=session, actions=cfg["action_list"], # node_uuids=cfg["options"]["node_uuids"], - **cfg['options'], + **cfg["options"], protocols=session.options.protocols, ports=session.options.ports, ip_address_list=None, diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 6083db6f..817e59b1 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -23,7 +23,7 @@ class AbstractAgent(ABC): observation_space: Optional[ObservationSpace], reward_function: Optional[RewardFunction], ) -> None: - self.agent_name:str = agent_name or "unnamed_agent" + self.agent_name: str = agent_name or "unnamed_agent" self.action_space: Optional[ActionManager] = action_space self.observation_space: Optional[ObservationSpace] = observation_space self.reward_function: Optional[RewardFunction] = reward_function @@ -46,9 +46,9 @@ class AbstractAgent(ABC): def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: # in RL agent, this method will send CAOS observation to GATE RL agent, then receive a int 0-39, # then use a bespoke conversion to take 1-40 int back into CAOS action - return ("DO_NOTHING", {} ) + return ("DO_NOTHING", {}) - def format_request(self, action:Tuple[str,Dict], options:Dict[str, int]) -> List[str]: + def format_request(self, action: Tuple[str, Dict], options: Dict[str, int]) -> List[str]: # this will take something like APPLICATION.EXECUTE and add things like target_ip_address in simulator. # therefore the execution definition needs to be a mapping from CAOS into SIMULATOR """Format action into format expected by the simulator, and apply execution definition if applicable.""" diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 28c87af1..7b10f957 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -1,10 +1,11 @@ from abc import ABC, abstractmethod -from typing import Any, Dict, Hashable, List, Optional, TYPE_CHECKING, Sequence, Tuple +from typing import Any, Dict, Hashable, List, Optional, Sequence, Tuple, TYPE_CHECKING from gym import spaces from pydantic import BaseModel from primaite.simulator.sim_container import Simulation + if TYPE_CHECKING: from primaite.game.session import PrimaiteSession @@ -29,7 +30,7 @@ def access_from_nested_dict(dictionary: Dict, keys: Sequence[Hashable]) -> Any: :return: The value in the dictionary :rtype: Any """ - key_list = [*keys] # copy keys to a new list to prevent editing original list + key_list = [*keys] # copy keys to a new list to prevent editing original list if len(key_list) == 0: return dictionary k = key_list.pop(0) @@ -58,7 +59,7 @@ class AbstractObservation(ABC): @classmethod @abstractmethod - def from_config(cls, config:Dict, session:"PrimaiteSession"): + def from_config(cls, config: Dict, session: "PrimaiteSession"): """Create this observation space component form a serialised format. The `session` parameter is for a the PrimaiteSession object that spawns this component. During deserialisation, @@ -98,7 +99,7 @@ class FileObservation(AbstractObservation): @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where=None): - return cls(where=parent_where+["files", config["file_name"]]) + return cls(where=parent_where + ["files", config["file_name"]]) class ServiceObservation(AbstractObservation): @@ -132,11 +133,8 @@ class ServiceObservation(AbstractObservation): return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(6)}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where:Optional[List[str]]=None): - return cls( - where=parent_where+["services",session.ref_map_services[config['service_ref']].uuid] - ) - + def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]] = None): + return cls(where=parent_where + ["services", session.ref_map_services[config["service_ref"]].uuid]) class LinkObservation(AbstractObservation): @@ -179,7 +177,7 @@ class LinkObservation(AbstractObservation): @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession"): - return cls(where=['network','links', session.ref_map_links[config['link_ref']]]) + return cls(where=["network", "links", session.ref_map_links[config["link_ref"]]]) class FolderObservation(AbstractObservation): @@ -237,13 +235,13 @@ class FolderObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where:Optional[List[str]]): - where = parent_where + ["folders", config['folder_name']] + def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]]): + where = parent_where + ["folders", config["folder_name"]] file_configs = config["files"] files = [FileObservation.from_config(config=f, session=session, parent_where=where) for f in file_configs] - return cls(where=where,files=files) + return cls(where=where, files=files) class NicObservation(AbstractObservation): @@ -267,7 +265,7 @@ class NicObservation(AbstractObservation): return spaces.Dict({"nic_status": spaces.Discrete(3)}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where:Optional[List[str]]): + def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]]): return cls(where=parent_where + ["NICs", config["nic_uuid"]]) @@ -278,7 +276,7 @@ class NodeObservation(AbstractObservation): services: List[ServiceObservation] = [], folders: List[FolderObservation] = [], nics: List[NicObservation] = [], - logon_status:bool=False + logon_status: bool = False, ) -> None: """ Configurable observation for a node in the simulation. @@ -306,7 +304,7 @@ class NodeObservation(AbstractObservation): self.services: List[ServiceObservation] = services self.folders: List[FolderObservation] = folders self.nics: List[NicObservation] = nics - self.logon_status:bool=logon_status + self.logon_status: bool = logon_status self.default_observation: Dict = { "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, @@ -315,7 +313,7 @@ class NodeObservation(AbstractObservation): "operating_status": 0, } if self.logon_status: - self.default_observation['logon_status']=0 + self.default_observation["logon_status"] = 0 def observe(self, state: Dict) -> Dict: if self.where is None: @@ -332,7 +330,7 @@ class NodeObservation(AbstractObservation): obs["NICS"] = {i + 1: nic.observe(state) for i, nic in enumerate(self.nics)} if self.logon_status: - obs['logon_status'] = 0 + obs["logon_status"] = 0 return obs @@ -345,26 +343,28 @@ class NodeObservation(AbstractObservation): "NICS": spaces.Dict({i + 1: nic.space for i, nic in enumerate(self.nics)}), } if self.logon_status: - space_shape['logon_status'] = spaces.Discrete(3) + space_shape["logon_status"] = spaces.Discrete(3) return spaces.Dict(space_shape) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where:Optional[List[str]]= None) -> "NodeObservation": - node_uuid = session.ref_map_nodes[config['node_ref']] + def from_config( + cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]] = None + ) -> "NodeObservation": + node_uuid = session.ref_map_nodes[config["node_ref"]] if parent_where is None: where = ["network", "nodes", node_uuid] else: where = parent_where + ["nodes", node_uuid] - svc_configs = config.get('services', {}) + svc_configs = config.get("services", {}) services = [ServiceObservation.from_config(config=c, session=session, parent_where=where) for c in svc_configs] - folder_configs = config.get('folders', {}) - folders = [FolderObservation.from_config(config=c,session=session, parent_where=where) for c in folder_configs] + folder_configs = config.get("folders", {}) + folders = [FolderObservation.from_config(config=c, session=session, parent_where=where) for c in folder_configs] nic_uuids = session.simulation.network.nodes[node_uuid].nics.keys() - nic_configs = [{'nic_uuid':n for n in nic_uuids }] if nic_uuids else [] + nic_configs = [{"nic_uuid": n for n in nic_uuids}] if nic_uuids else [] nics = [NicObservation.from_config(config=c, session=session, parent_where=where) for c in nic_configs] - logon_status = config.get('logon_status',False) + logon_status = config.get("logon_status", False) return cls(where=where, services=services, folders=folders, nics=nics, logon_status=logon_status) @@ -374,7 +374,12 @@ class AclObservation(AbstractObservation): # if a file is created at runtime, we have currently got no way of telling the observation space to track it. # this needs adding, but not for the MVP. def __init__( - self, node_ip_to_id: Dict[str,int], ports: List[int], protocols: list[str], where: Optional[Tuple[str]] = None, num_rules: int = 10 + self, + node_ip_to_id: Dict[str, int], + ports: List[int], + protocols: list[str], + where: Optional[Tuple[str]] = None, + num_rules: int = 10, ) -> None: super().__init__() self.where: Optional[Tuple[str]] = where @@ -386,16 +391,18 @@ class AclObservation(AbstractObservation): self.protocol_to_id: Dict[str, int] = {protocol: i + 2 for i, protocol in enumerate(protocols)} "List of protocols which are part of the game, defines ordering when converting to an ID" self.default_observation: Dict = { - "RULES": {i+ 1:{ - "position": i, - "permission": 0, - "source_node_id": 0, - "source_port": 0, - "dest_node_id": 0, - "dest_port": 0, - "protocol": 0, + "RULES": { + i + + 1: { + "position": i, + "permission": 0, + "source_node_id": 0, + "source_port": 0, + "dest_node_id": 0, + "dest_port": 0, + "protocol": 0, } - for i in range(self.num_rules) + for i in range(self.num_rules) } } @@ -406,8 +413,7 @@ class AclObservation(AbstractObservation): if acl_state is NOT_PRESENT_IN_STATE: return self.default_observation - - #TODO: what if the ACL has more rules than num of max rules for obs space + # TODO: what if the ACL has more rules than num of max rules for obs space obs = {} obs["RULES"] = {} for i, rule_state in acl_state.items(): @@ -439,7 +445,8 @@ class AclObservation(AbstractObservation): { "RULE": spaces.Dict( { - i + 1: spaces.Dict( + i + + 1: spaces.Dict( { "position": spaces.Discrete(self.num_rules), "permission": spaces.Discrete(3), @@ -460,23 +467,23 @@ class AclObservation(AbstractObservation): @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession") -> "AclObservation": node_ip_to_idx = {} - for node_idx, node_cfg in enumerate(config['node_order']): + for node_idx, node_cfg in enumerate(config["node_order"]): n_ref = node_cfg["node_ref"] n_obj = session.simulation.network.nodes[session.ref_map_nodes[n_ref]] for nic_uuid, nic_obj in n_obj.nics.items(): node_ip_to_idx[nic_obj.ip_address] = node_idx + 2 - router_uuid = session.ref_map_nodes[config['router_node_ref']] + router_uuid = session.ref_map_nodes[config["router_node_ref"]] return cls( node_ip_to_id=node_ip_to_idx, ports=session.options.ports, protocols=session.options.protocols, - where=["network", "nodes", router_uuid, "acl", "acl"]) - + where=["network", "nodes", router_uuid, "acl", "acl"], + ) class NullObservation(AbstractObservation): - def __init__(self, where:Optional[List[str]]=None): + def __init__(self, where: Optional[List[str]] = None): self.default_observation: Dict = {} def observe(self, state: Dict) -> Dict: @@ -487,20 +494,22 @@ class NullObservation(AbstractObservation): return spaces.Dict({}) @classmethod - def from_config(cls, config:Dict, session:Optional["PrimaiteSession"]=None) -> "NullObservation": + def from_config(cls, config: Dict, session: Optional["PrimaiteSession"] = None) -> "NullObservation": return cls() -class ICSObservation(NullObservation): pass + +class ICSObservation(NullObservation): + pass class UC2BlueObservation(AbstractObservation): def __init__( - self, - nodes: List[NodeObservation], - links: List[LinkObservation], - acl: AclObservation, - ics: ICSObservation, - where:Optional[List[str]] = None, + self, + nodes: List[NodeObservation], + links: List[LinkObservation], + acl: AclObservation, + ics: ICSObservation, + where: Optional[List[str]] = None, ) -> None: super().__init__() self.where: Optional[Tuple[str]] = where @@ -510,36 +519,38 @@ class UC2BlueObservation(AbstractObservation): self.acl: AclObservation = acl self.ics: ICSObservation = ics - self.default_observation : Dict = { - "NODES": {i+1: n.default_observation for i,n in enumerate(self.nodes)}, - "LINKS": {i+1: l.default_observation for i,l in enumerate(self.links)}, + self.default_observation: Dict = { + "NODES": {i + 1: n.default_observation for i, n in enumerate(self.nodes)}, + "LINKS": {i + 1: l.default_observation for i, l in enumerate(self.links)}, "ACL": self.acl.default_observation, "ICS": self.ics.default_observation, } - def observe(self, state:Dict) -> Dict: + def observe(self, state: Dict) -> Dict: if self.where is None: return self.default_observation obs = {} - obs['NODES'] = {i + 1: node.observe(state) for i, node in enumerate(self.nodes)} - obs['LINKS'] = {i + 1: link.observe(state) for i, link in enumerate(self.links)} - obs['ACL'] = self.acl.observe(state) - obs['ICS'] = self.ics.observe(state) + obs["NODES"] = {i + 1: node.observe(state) for i, node in enumerate(self.nodes)} + obs["LINKS"] = {i + 1: link.observe(state) for i, link in enumerate(self.links)} + obs["ACL"] = self.acl.observe(state) + obs["ICS"] = self.ics.observe(state) return obs @property def space(self) -> spaces.Space: - return spaces.Dict({ - "NODES": spaces.Dict({i+1: node.space for i, node in enumerate(self.nodes)}), - "LINKS": spaces.Dict({i+1: link.space for i, link in enumerate(self.links)}), - "ACL": self.acl.space, - "ICS": self.ics.space, - }) + return spaces.Dict( + { + "NODES": spaces.Dict({i + 1: node.space for i, node in enumerate(self.nodes)}), + "LINKS": spaces.Dict({i + 1: link.space for i, link in enumerate(self.links)}), + "ACL": self.acl.space, + "ICS": self.ics.space, + } + ) @classmethod - def from_config(cls, config:Dict, session:"PrimaiteSession"): + def from_config(cls, config: Dict, session: "PrimaiteSession"): node_configs = config["nodes"] nodes = [NodeObservation.from_config(config=n, session=session) for n in node_configs] @@ -551,18 +562,18 @@ class UC2BlueObservation(AbstractObservation): ics_config = config["ics"] ics = ICSObservation.from_config(config=ics_config, session=session) - new = cls(nodes=nodes, links=links, acl=acl, ics=ics, where=['network']) + new = cls(nodes=nodes, links=links, acl=acl, ics=ics, where=["network"]) return new class UC2RedObservation(AbstractObservation): - def __init__(self, nodes:List[NodeObservation], where:Optional[List[str]] = None) -> None: + def __init__(self, nodes: List[NodeObservation], where: Optional[List[str]] = None) -> None: super().__init__() - self.where:Optional[List[str]] = where + self.where: Optional[List[str]] = where self.nodes: List[NodeObservation] = nodes - self.default_observation : Dict = { - "NODES": {i+1: n.default_observation for i,n in enumerate(self.nodes)}, + self.default_observation: Dict = { + "NODES": {i + 1: n.default_observation for i, n in enumerate(self.nodes)}, } def observe(self, state: Dict) -> Dict: @@ -570,14 +581,16 @@ class UC2RedObservation(AbstractObservation): return self.default_observation obs = {} - obs['NODES'] = {i+1: node.observe(state) for i, node in enumerate(self.nodes)} + obs["NODES"] = {i + 1: node.observe(state) for i, node in enumerate(self.nodes)} return obs @property def space(self) -> spaces.Space: - return spaces.Dict({ - "NODES": spaces.Dict({i+1: node.space for i, node in enumerate(self.nodes)}), - }) + return spaces.Dict( + { + "NODES": spaces.Dict({i + 1: node.space for i, node in enumerate(self.nodes)}), + } + ) @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession"): @@ -586,7 +599,9 @@ class UC2RedObservation(AbstractObservation): return cls(nodes=nodes, where=["network"]) -class UC2GreenObservation(NullObservation): pass +class UC2GreenObservation(NullObservation): + pass + class ObservationSpace: """ @@ -603,7 +618,7 @@ class ObservationSpace: # what this class does: # keep a list of observations # create observations for an actor from the config - def __init__(self, observation:AbstractObservation) -> None: + def __init__(self, observation: AbstractObservation) -> None: self.obs: AbstractObservation = observation def observe(self, state) -> Dict: @@ -614,12 +629,12 @@ class ObservationSpace: return self.obs.space @classmethod - def from_config(cls, config:Dict, session:"PrimaiteSession") -> "ObservationSpace": - if config['type'] == "UC2BlueObservation": - return cls(UC2BlueObservation.from_config(config.get('options',{}), session=session)) - elif config['type'] == "UC2RedObservation": - return cls(UC2RedObservation.from_config(config.get('options',{}), session=session)) - elif config['type'] == "UC2GreenObservation": - return cls(UC2GreenObservation.from_config(config.get("options",{}), session=session)) + def from_config(cls, config: Dict, session: "PrimaiteSession") -> "ObservationSpace": + if config["type"] == "UC2BlueObservation": + return cls(UC2BlueObservation.from_config(config.get("options", {}), session=session)) + elif config["type"] == "UC2RedObservation": + return cls(UC2RedObservation.from_config(config.get("options", {}), session=session)) + elif config["type"] == "UC2GreenObservation": + return cls(UC2GreenObservation.from_config(config.get("options", {}), session=session)) else: raise ValueError("Observation space type invalid") diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index a4ceb2dd..18925edc 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -1,34 +1,34 @@ from abc import ABC, abstractmethod from typing import Any, Dict, List -class AbstractReward(): + +class AbstractReward: def __init__(self): ... @abstractmethod - def calculate(self, state:Dict) -> float: + def calculate(self, state: Dict) -> float: return 0.3 -class DummyReward(AbstractReward): +class DummyReward(AbstractReward): def calculate(self, state: Dict) -> float: return -0.1 -class RewardFunction(): - __rew_class_identifiers:Dict[str,type[AbstractReward]] = { - "DUMMY" : DummyReward - } - def __init__(self, reward_function:AbstractReward): + +class RewardFunction: + __rew_class_identifiers: Dict[str, type[AbstractReward]] = {"DUMMY": DummyReward} + + def __init__(self, reward_function: AbstractReward): self.reward: AbstractReward = reward_function - def calculate(self, state:Dict) -> float: + def calculate(self, state: Dict) -> float: return self.reward.calculate(state) @classmethod - def from_config(cls, cfg:Dict) -> "RewardFunction": - for rew_component_cfg in cfg['reward_components']: - rew_type = rew_component_cfg['type'] + def from_config(cls, cfg: Dict) -> "RewardFunction": + for rew_component_cfg in cfg["reward_components"]: + rew_type = rew_component_cfg["type"] rew_component = cls.__rew_class_identifiers[rew_type]() new = cls(reward_function=rew_component) return new - diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 4bcf26e4..7b2225ef 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -10,6 +10,7 @@ from typing import Dict, List from pydantic import BaseModel +from primaite import getLogger from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractAgent, RandomAgent from primaite.game.agent.observations import ( @@ -37,14 +38,12 @@ from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.sim_container import Simulation from primaite.simulator.system.applications.database_client import DatabaseClient -from primaite.simulator.system.services.database_service import DatabaseService -from primaite.simulator.system.services.dns_client import DNSClient -from primaite.simulator.system.services.dns_server import DNSServer +from primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.service import Service -from primaite import getLogger - _LOGGER = getLogger(__name__) @@ -91,7 +90,7 @@ class PrimaiteSession: agent_action, action_options = agent.get_action(agent_obs, agent_reward) # 9. CAOS action is converted into request (extra information might be needed to enrich # the request, this is what the execution definition is there for) - _LOGGER.debug(f"Formatting agent action {agent_action}") # maybe too many debug log statements + _LOGGER.debug(f"Formatting agent action {agent_action}") # maybe too many debug log statements agent_request = agent.format_request(agent_action, action_options) # 10. primaite session receives the action from the agents and asks the simulation to apply each @@ -106,8 +105,8 @@ class PrimaiteSession: def from_config(cls, cfg: dict) -> "PrimaiteSession": sess = cls() sess.options = PrimaiteSessionOptions( - ports = cfg['game_config']['ports'], - protocols = cfg['game_config']['protocols'], + ports=cfg["game_config"]["ports"], + protocols=cfg["game_config"]["protocols"], ) sim = sess.simulation net = sim.network @@ -230,7 +229,7 @@ class PrimaiteSession: reward_function_cfg = agent_cfg["reward_function"] # CREATE OBSERVATION SPACE - obs_space=ObservationSpace.from_config(observation_space_cfg, sess) + obs_space = ObservationSpace.from_config(observation_space_cfg, sess) """ # if observation_space_cfg is None: @@ -331,23 +330,23 @@ class PrimaiteSession: """ # CREATE ACTION SPACE - action_space_cfg['options']['node_uuids'] = [] + action_space_cfg["options"]["node_uuids"] = [] # if a list of nodes is defined, convert them from node references to node UUIDs - for action_node_option in action_space_cfg.get('options',{}).pop('nodes', {}): - if 'node_ref' in action_node_option: - node_uuid = sess.ref_map_nodes[action_node_option['node_ref']] - action_space_cfg['options']['node_uuids'].append(node_uuid) + for action_node_option in action_space_cfg.get("options", {}).pop("nodes", {}): + if "node_ref" in action_node_option: + node_uuid = sess.ref_map_nodes[action_node_option["node_ref"]] + action_space_cfg["options"]["node_uuids"].append(node_uuid) # Each action space can potentially have a different list of nodes that it can apply to. Therefore, # we will pass node_uuids as a part of the action space config. # However, it's not possible to specify the node uuids directly in the config, as they are generated # dynamically, so we have to translate node references to uuids before passing this config on. - if 'action_list' in action_space_cfg: - for action_config in action_space_cfg['action_list']: - if 'options' in action_config: - if 'target_router_ref' in action_config['options']: - _target = action_config['options']['target_router_ref'] - action_config['options']['target_router_uuid'] = sess.ref_map_nodes[_target] + if "action_list" in action_space_cfg: + for action_config in action_space_cfg["action_list"]: + if "options" in action_config: + if "target_router_ref" in action_config["options"]: + _target = action_config["options"]["target_router_ref"] + action_config["options"]["target_router_uuid"] = sess.ref_map_nodes[_target] action_space = ActionManager.from_config(sess, action_space_cfg) @@ -357,16 +356,30 @@ class PrimaiteSession: # CREATE AGENT if agent_type == "GreenWebBrowsingAgent": # TODO: implement non-random agents and fix this parsing - new_agent = RandomAgent(agent_name=agent_cfg['ref'], action_space=action_space, observation_space=obs_space, reward_function=rew_function) + new_agent = RandomAgent( + agent_name=agent_cfg["ref"], + action_space=action_space, + observation_space=obs_space, + reward_function=rew_function, + ) sess.agents.append(new_agent) elif agent_type == "GATERLAgent": - new_agent = RandomAgent(agent_name=agent_cfg['ref'], action_space=action_space, observation_space=obs_space, reward_function=rew_function) + new_agent = RandomAgent( + agent_name=agent_cfg["ref"], + action_space=action_space, + observation_space=obs_space, + reward_function=rew_function, + ) sess.agents.append(new_agent) elif agent_type == "RedDatabaseCorruptingAgent": - new_agent = RandomAgent(agent_name=agent_cfg['ref'], action_space=action_space, observation_space=obs_space, reward_function=rew_function) + new_agent = RandomAgent( + agent_name=agent_cfg["ref"], + action_space=action_space, + observation_space=obs_space, + reward_function=rew_function, + ) sess.agents.append(new_agent) else: print("agent type not found") - return sess diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/switch.py index bb296203..09b53483 100644 --- a/src/primaite/simulator/network/hardware/nodes/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/switch.py @@ -57,8 +57,8 @@ class Switch(Node): """ state = super().describe_state() state["ports"] = {port_num: port.describe_state() for port_num, port in self.switch_ports.items()} - state["num_ports"]= self.num_ports # redundant? - state["mac_address_table"]= {mac: port for mac, port in self.mac_address_table.items()} + state["num_ports"] = self.num_ports # redundant? + state["mac_address_table"] = {mac: port for mac, port in self.mac_address_table.items()} return state def _add_mac_table_entry(self, mac_address: str, switch_port: SwitchPort): From b53c3856dd470e88fb18d8635758d9374398dfea Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 10 Oct 2023 09:48:04 +0100 Subject: [PATCH 222/980] Add GATE wheel temporarily --- example_config.yaml | 8 +- src/primaite/game/agent/GATE_agents.py | 59 ++++++++ src/primaite/game/session.py | 178 +++++++++++------------- src/primaite/utils/start_gate_server.py | 5 + 4 files changed, 149 insertions(+), 101 deletions(-) create mode 100644 src/primaite/utils/start_gate_server.py diff --git a/example_config.yaml b/example_config.yaml index f7faf589..afdf1b0a 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -1,8 +1,12 @@ training_config: rl_framework: SB3 - rl_algo: PPO + rl_algorithm: PPO + seed: 333 + n_learn_episodes: 2 n_learn_steps: 128 - n_learn_episodes: 1000 + n_eval_episodes: 2 + n_eval_steps: 128 + game_config: ports: diff --git a/src/primaite/game/agent/GATE_agents.py b/src/primaite/game/agent/GATE_agents.py index 5bdfebe4..ac1d776b 100644 --- a/src/primaite/game/agent/GATE_agents.py +++ b/src/primaite/game/agent/GATE_agents.py @@ -1,5 +1,64 @@ from primaite.game.agent.interface import AbstractGATEAgent +from arcd_gate.client.gate_client import GATEClient +class GATEMan(GATEClient): + + @property + def rl_framework(self) -> str: + return "SB3" + + @property + def rl_framework(self) -> str: + pass + + @property + def rl_algorithm(self) -> str: + pass + + @property + def seed(self) -> Optional[int]: + return None + + @property + def n_learn_episodes(self) -> int: + return 0 + + @property + def n_learn_steps(self) -> int: + return 0 + + @property + def n_eval_episodes(self) -> int: + return 0 + + @property + def n_eval_steps(self) -> int: + return 0 + + @property + def action_space(self) -> spaces.Space: + pass + + @property + def observation_space(self) -> spaces.Space: + pass + + def step(self, action: ActType) -> Tuple[np.ndarray, float, bool, bool, Dict]: + pass + + def reset(self, *, seed: Optional[int] = None, options: Optional[dict[str, Any]] = None) -> Tuple[np.ndarray, Dict]: + pass + + def close(self): + pass + class GATERLAgent(AbstractGATEAgent): ... + # The communication with GATE needs to be handled by the PrimaiteSession, rather than by individual agents, + # because when we are supporting MARL, the actions form multiple agents will have to be batched + + # For example MultiAgentEnv in Ray allows sending a dict of observations of multiple agents, then it will reply + # with the actions for those agents. + + diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 7b2225ef..7746f78c 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -6,7 +6,9 @@ # 5. idk from ipaddress import IPv4Address -from typing import Dict, List +from typing import Any, Dict, List, Optional, Tuple +from gymnasium.vector.utils import spaces +import numpy as np from pydantic import BaseModel @@ -44,26 +46,101 @@ from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.service import Service +from arcd_gate.client.gate_client import GATEClient, ActType +from numpy import ndarray + _LOGGER = getLogger(__name__) +class PrimaiteGATEClient(GATEClient): + def __init__(self, parent_session:"PrimaiteSession", service_port: int = 50000): + super().__init__(service_port=service_port) + self.parent_session:"PrimaiteSession" + + @property + def rl_framework(self) -> str: + return self.parent_session.training_options.rl_framework + + @property + def rl_algorithm(self) -> str: + return self.parent_session.training_options.rl_algorithm + + @property + def seed(self) -> int | None: + return self.parent_session.training_options.seed + + @property + def n_learn_episodes(self) -> int: + return self.parent_session.training_options.n_learn_episodes + + @property + def n_learn_steps(self) -> int: + return self.parent_session.training_options.n_learn_steps + + @property + def n_eval_episodes(self) -> int: + return self.parent_session.training_options.n_eval_episodes + + @property + def n_eval_steps(self) -> int: + return self.parent_session.training_options.n_eval_steps + + @property + def action_space(self) -> spaces.Space: + return self.parent_session.rl_agent.action_space + + @property + def observation_space(self) -> spaces.Space: + return self.parent_session.rl_agent.observation_space + + def step(self, action: ActType) -> Tuple[ndarray, float, bool, bool, Dict]: + self.parent_session.step() + #TODO: not sure how to go about this. + + def reset(self, *, seed: int | None = None, options: dict[str, Any] | None = None) -> Tuple[ndarray, Dict]: + ... + + def close(self): + ... class PrimaiteSessionOptions(BaseModel): ports: List[str] protocols: List[str] +class TrainingOptions(BaseModel): + rl_framework:str + rl_algorithm:str + seed:Optional[int] + n_learn_episodes:int + n_learn_steps:int + n_eval_episodes:int + n_eval_steps:int + + class PrimaiteSession: def __init__(self): self.simulation: Simulation = Simulation() self.agents: List[AbstractAgent] = [] + self.rl_agent: AbstractAgent + # which of the agents should be used for sending RL data to GATE client? self.step_counter: int = 0 self.episode_counter: int = 0 self.options: PrimaiteSessionOptions + self.training_options: TrainingOptions self.ref_map_nodes: Dict[str, Node] = {} self.ref_map_services: Dict[str, Service] = {} self.ref_map_links: Dict[str, Link] = {} + def start_session(self, opts="TODO..."): + """Commence the session, this gives the gate client control over the simulation/agent loop.""" + ... + + def eval(self, opts="TODO..."): + ... + + + def step(self): _LOGGER.debug(f"Stepping primaite session. Step counter: {self.step_counter}") # currently designed with assumption that all agents act once per step in order @@ -108,6 +185,7 @@ class PrimaiteSession: ports=cfg["game_config"]["ports"], protocols=cfg["game_config"]["protocols"], ) + sess.training_options = TrainingOptions(**cfg['training_config']) sim = sess.simulation net = sim.network @@ -231,104 +309,6 @@ class PrimaiteSession: # CREATE OBSERVATION SPACE obs_space = ObservationSpace.from_config(observation_space_cfg, sess) - """ - # if observation_space_cfg is None: - # obs_space = NullObservation() - # elif observation_space_cfg["type"] == "UC2BlueObservation": - # node_obs_list = [] - # link_obs_list = [] - - # # node ip to index maps ip addresses to node id, as there are potentially multiple nics on a node, there are multiple ip addresses - # node_ip_to_index = {} - # for node_idx, node_cfg in enumerate(nodes_cfg): - # n_ref = node_cfg["ref"] - # n_obj = net.nodes[ref_map_nodes[n_ref]] - # for nic_uuid, nic_obj in n_obj.nics.items(): - # node_ip_to_index[nic_obj.ip_address] = node_idx + 2 - - # for node_obs_cfg in observation_space_cfg["options"]["nodes"]: - # node_ref = node_obs_cfg["node_ref"] - # folder_obs_list = [] - # service_obs_list = [] - # if "services" in node_obs_cfg: - # for service_obs_cfg in node_obs_cfg["services"]: - # service_obs_list.append( - # ServiceObservation( - # where=[ - # "network", - # "nodes", - # ref_map_nodes[node_ref], - # "services", - # ref_map_services[service_obs_cfg["service_ref"]], - # ] - # ) - # ) - # if "folders" in node_obs_cfg: - # for folder_obs_cfg in node_obs_cfg["folders"]: - # file_obs_list = [] - # if "files" in folder_obs_cfg: - # for file_obs_cfg in folder_obs_cfg["files"]: - # file_obs_list.append( - # FileObservation( - # where=[ - # "network", - # "nodes", - # ref_map_nodes[node_ref], - # "folders", - # folder_obs_cfg["folder_name"], - # "files", - # file_obs_cfg["file_name"], - # ] - # ) - # ) - # folder_obs_list.append( - # FolderObservation( - # where=[ - # "network", - # "nodes", - # ref_map_nodes[node_ref], - # "folders", - # folder_obs_cfg["folder_name"], - # ], - # files=file_obs_list, - # ) - # ) - # nic_obs_list = [] - # for nic_uuid in net.nodes[ref_map_nodes[node_obs_cfg["node_ref"]]].nics.keys(): - # nic_obs_list.append( - # NicObservation(where=["network", "nodes", ref_map_nodes[node_ref], "NICs", nic_uuid]) - # ) - # node_obs_list.append( - # NodeObservation( - # where=["network", "nodes", ref_map_nodes[node_ref]], - # services=service_obs_list, - # folders=folder_obs_list, - # nics=nic_obs_list, - # logon_status=False, - # ) - # ) - # for link_obs_cfg in observation_space_cfg["options"]["links"]: - # link_ref = link_obs_cfg["link_ref"] - # link_obs_list.append(LinkObservation(where=["network", "links", ref_map_links[link_ref]])) - - # acl_obs = AclObservation( - # node_ip_to_id=node_ip_to_index, - # ports=game_cfg["ports"], - # protocols=game_cfg["ports"], - # where=["network", "nodes", observation_space_cfg["options"]["acl"]["router_node_ref"]], - # ) - # obs_space = UC2BlueObservation( - # nodes=node_obs_list, links=link_obs_list, acl=acl_obs, ics=ICSObservation() - # ) - # elif observation_space_cfg["type"] == "UC2RedObservation": - # obs_space = UC2RedObservation.from_config(observation_space_cfg["options"], sim=sim) - # elif observation_space_cfg["type"] == "UC2GreenObservation": - # obs_space = UC2GreenObservation.from_config(observation_space_cfg.get('options',{})) - # else: - # print("observation space config not specified correctly.") - # obs_space = NullObservation() - """ - # CREATE ACTION SPACE action_space_cfg["options"]["node_uuids"] = [] # if a list of nodes is defined, convert them from node references to node UUIDs diff --git a/src/primaite/utils/start_gate_server.py b/src/primaite/utils/start_gate_server.py new file mode 100644 index 00000000..53508cd2 --- /dev/null +++ b/src/primaite/utils/start_gate_server.py @@ -0,0 +1,5 @@ +"""Utility script to start the gate server for running PrimAITE in attached mode.""" +from arcd_gate.server.gate_service import GATEService + +service = GATEService() +service.start() From f3451b2fbbb1e6ff0b190fc209869599e37334bf Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 10 Oct 2023 09:50:39 +0100 Subject: [PATCH 223/980] Replace request overwrite error with warning --- src/primaite/simulator/core.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 914b798e..eceddfd5 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -112,9 +112,8 @@ class RequestManager(BaseModel): :type request_type: RequestType """ if name in self.request_types: - msg = f"Attempted to register a request but the request name {name} is already taken." - _LOGGER.error(msg) - raise RuntimeError(msg) + msg = f"Overwriting request type {name}." + _LOGGER.warn(msg) self.request_types[name] = request_type From 56eda38a6ed4689b2ba03fc0e0b687c958309b6b Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 10 Oct 2023 09:52:40 +0100 Subject: [PATCH 224/980] #1947: git merge did not change add_action -> add_request --- docs/source/action_system.rst | 12 ++++++------ docs/source/simulation_structure.rst | 2 +- src/primaite/simulator/system/services/service.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/source/action_system.rst b/docs/source/action_system.rst index 11b74abf..f6d237ba 100644 --- a/docs/source/action_system.rst +++ b/docs/source/action_system.rst @@ -50,9 +50,9 @@ A simple example without chaining can be seen in the :py:class:`primaite.simulat ... def _init_request_manager(self): ... - request_manager.add_action("scan", Action(func=lambda request, context: self.scan())) - request_manager.add_action("repair", Action(func=lambda request, context: self.repair())) - request_manager.add_action("restore", Action(func=lambda request, context: self.restore())) + request_manager.add_request("scan", Action(func=lambda request, context: self.scan())) + request_manager.add_request("repair", Action(func=lambda request, context: self.repair())) + request_manager.add_request("restore", Action(func=lambda request, context: self.restore())) *ellipses (``...``) used to omit code impertinent to this explanation* @@ -70,7 +70,7 @@ An example of how this works is in the :py:class:`primaite.simulator.network.har def _init_request_manager(self): ... # a regular action which is processed by the Node itself - request_manager.add_action("turn_on", Action(func=lambda request, context: self.turn_on())) + request_manager.add_request("turn_on", Action(func=lambda request, context: self.turn_on())) # if the Node receives a request where the first word is 'service', it will use a dummy manager # called self._service_request_manager to pass on the reqeust to the relevant service. This dummy @@ -78,11 +78,11 @@ An example of how this works is in the :py:class:`primaite.simulator.network.har # done because the next string after "service" is always the uuid of that service, so we need an # RequestManager to pop that string before sending it onto the relevant service's RequestManager. self._service_request_manager = RequestManager() - request_manager.add_action("service", Action(func=self._service_request_manager)) + request_manager.add_request("service", Action(func=self._service_request_manager)) ... def install_service(self, service): self.services[service.uuid] = service ... # Here, the service UUID is registered to allow passing actions between the node and the service. - self._service_request_manager.add_action(service.uuid, Action(func=service._request_manager)) + self._service_request_manager.add_request(service.uuid, Action(func=service._request_manager)) diff --git a/docs/source/simulation_structure.rst b/docs/source/simulation_structure.rst index 20d2d2d3..2f0a56e8 100644 --- a/docs/source/simulation_structure.rst +++ b/docs/source/simulation_structure.rst @@ -51,7 +51,7 @@ snippet demonstrates usage of the ``ActionPermissionValidator``. def _init_request_manager(self) -> RequestManager: am = super()._init_request_manager() - am.add_action( + am.add_request( "reset_factory_settings", Action( func = lambda request, context: self.reset_factory_settings(), diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 1befe33e..597c8cbd 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -45,7 +45,7 @@ class Service(IOSoftware): def _init_request_manager(self) -> RequestManager: am = super()._init_request_manager() - am.add_action("scan", RequestType(func=lambda request, context: self.scan())) + am.add_request("scan", RequestType(func=lambda request, context: self.scan())) am.add_request("stop", RequestType(func=lambda request, context: self.stop())) am.add_request("start", RequestType(func=lambda request, context: self.start())) am.add_request("pause", RequestType(func=lambda request, context: self.pause())) From 060bbf050629d10899e2ee4ae8f48b56e3f4f0c3 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 10 Oct 2023 15:14:47 +0100 Subject: [PATCH 225/980] #1947: added ability for files and folders to be scanned, corrupted and repaired --- .../simulator/file_system/file_system.py | 135 ++++++++++++++---- .../simulator/system/services/service.py | 8 +- src/primaite/simulator/system/software.py | 2 + tests/conftest.py | 1 + .../_file_system/test_file_system.py | 36 ++++- .../_system/_services/test_services.py | 80 +++++++++++ 6 files changed, 227 insertions(+), 35 deletions(-) create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 5da4eca8..5653234d 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -3,6 +3,8 @@ from __future__ import annotations import math import os.path import shutil +from abc import abstractmethod +from enum import Enum from pathlib import Path from typing import Dict, Optional @@ -42,6 +44,19 @@ def convert_size(size_bytes: int) -> str: return f"{s} {size_name[i]}" +class FileSystemItemStatus(Enum): + """Status of the FileSystemItem.""" + + GOOD = 0 + """File/Folder is OK.""" + + QUARANTINED = 1 + """File/Folder is quarantined.""" + + CORRUPTED = 2 + """File/Folder is corrupted.""" + + class FileSystemItemABC(SimComponent): """ Abstract base class for file system items used in the file system simulation. @@ -52,6 +67,12 @@ class FileSystemItemABC(SimComponent): name: str "The name of the FileSystemItemABC." + status: FileSystemItemStatus = FileSystemItemStatus.GOOD + "Actual status of the current FileSystemItem" + + visible_status: FileSystemItemStatus = FileSystemItemStatus.GOOD + "Visible status of the current FileSystemItem" + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -78,6 +99,32 @@ class FileSystemItemABC(SimComponent): """ return convert_size(self.size) + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() + am.add_request("scan", RequestType(func=lambda request, context: self.scan())) # TODO implement request + am.add_request("checkhash", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("delete", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("restore", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("repair", RequestType(func=lambda request, context: self.repair())) + am.add_request("corrupt", RequestType(func=lambda request, context: self.corrupt())) + return am + + def scan(self) -> None: + """Update the FileSystemItem states.""" + super().scan() + + self.visible_status = self.status + + @abstractmethod + def repair(self) -> None: + """Repair the FileSystemItem.""" + pass + + @abstractmethod + def corrupt(self) -> None: + """Corrupt the FileSystemItem.""" + pass + class FileSystem(SimComponent): """Class that contains all the simulation File System.""" @@ -329,20 +376,6 @@ class Folder(FileSystemItemABC): "Files stored in the folder." _files_by_name: Dict[str, File] = {} "Files by their name as .." - is_quarantined: bool = False - "Flag that marks the folder as quarantined if true." - - def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() - - am.add_request("scan", RequestType(func=lambda request, context: ...)) # TODO implement request - am.add_request("checkhash", RequestType(func=lambda request, context: ...)) # TODO implement request - am.add_request("repair", RequestType(func=lambda request, context: ...)) # TODO implement request - am.add_request("restore", RequestType(func=lambda request, context: ...)) # TODO implement request - am.add_request("delete", RequestType(func=lambda request, context: ...)) # TODO implement request - am.add_request("corrupt", RequestType(func=lambda request, context: ...)) # TODO implement request - - return am def describe_state(self) -> Dict: """ @@ -440,19 +473,49 @@ class Folder(FileSystemItemABC): def quarantine(self): """Quarantines the File System Folder.""" - if not self.is_quarantined: - self.is_quarantined = True + if self.status != FileSystemItemStatus.QUARANTINED: + self.status = FileSystemItemStatus.QUARANTINED self.fs.sys_log.info(f"Quarantined folder ./{self.name}") def unquarantine(self): """Unquarantine of the File System Folder.""" - if self.is_quarantined: - self.is_quarantined = False + if self.status == FileSystemItemStatus.QUARANTINED: + self.status = FileSystemItemStatus.GOOD self.fs.sys_log.info(f"Quarantined folder ./{self.name}") def quarantine_status(self) -> bool: """Returns true if the folder is being quarantined.""" - return self.is_quarantined + return self.status == FileSystemItemStatus.QUARANTINED + + def repair(self) -> None: + """Repair a corrupted Folder by setting the folder and containing files status to FileSystemItemStatus.GOOD.""" + super().repair() + + # iterate through the files in the folder + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + file.repair() + + # set file status to good if corrupt + if self.status == FileSystemItemStatus.CORRUPTED: + self.status = FileSystemItemStatus.GOOD + + self.fs.sys_log.info(f"Repaired folder {self.name}") + + def corrupt(self) -> None: + """Corrupt a File by setting the folder and containing files status to FileSystemItemStatus.CORRUPTED.""" + super().corrupt() + + # iterate through the files in the folder + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + file.corrupt() + + # set file status to good if corrupt + if self.status == FileSystemItemStatus.GOOD: + self.status = FileSystemItemStatus.CORRUPTED + + self.fs.sys_log.info(f"Corrupted folder {self.name}") class File(FileSystemItemABC): @@ -509,18 +572,6 @@ class File(FileSystemItemABC): with open(self.sim_path, mode="a"): pass - def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() - - am.add_request("scan", RequestType(func=lambda request, context: ...)) # TODO implement request - am.add_request("checkhash", RequestType(func=lambda request, context: ...)) # TODO implement request - am.add_request("delete", RequestType(func=lambda request, context: ...)) # TODO implement request - am.add_request("repair", RequestType(func=lambda request, context: ...)) # TODO implement request - am.add_request("restore", RequestType(func=lambda request, context: ...)) # TODO implement request - am.add_request("corrupt", RequestType(func=lambda request, context: ...)) # TODO implement request - - return am - def make_copy(self, dst_folder: Folder) -> File: """ Create a copy of the current File object in the given destination folder. @@ -556,3 +607,25 @@ class File(FileSystemItemABC): state["size"] = self.size state["file_type"] = self.file_type.name return state + + def repair(self) -> None: + """Repair a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" + super().repair() + + # set file status to good if corrupt + if self.status == FileSystemItemStatus.CORRUPTED: + self.status = FileSystemItemStatus.GOOD + + path = self.folder.name + "/" + self.name + self.folder.fs.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") + + def corrupt(self) -> None: + """Corrupt a File by setting the status to FileSystemItemStatus.CORRUPTED.""" + super().corrupt() + + # set file status to good if corrupt + if self.status == FileSystemItemStatus.GOOD: + self.status = FileSystemItemStatus.CORRUPTED + + path = self.folder.name + "/" + self.name + self.folder.fs.sys_log.info(f"Corrupted file {self.sim_path if self.sim_path else path}") diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 597c8cbd..ca09ae60 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -40,7 +40,7 @@ class Service(IOSoftware): restart_duration: int = 5 "How many timesteps does it take to restart this service." - _restart_countdown: Optional[int] = None + restart_countdown: Optional[int] = None "If currently restarting, how many timesteps remain until the restart is finished." def _init_request_manager(self) -> RequestManager: @@ -65,7 +65,9 @@ class Service(IOSoftware): :rtype: Dict """ state = super().describe_state() - state.update({"operating_state": self.operating_state.name}) + state.update( + {"operating_state": self.operating_state.name, "visible_operating_state": self.visible_operating_state.name} + ) return state def reset_component_for_episode(self, episode: int): @@ -114,7 +116,7 @@ class Service(IOSoftware): if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.RESTARTING - self.restart_countdown = self.restarting_duration + self.restart_countdown = self.restart_duration def disable(self) -> None: """Disable the service.""" diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 33a03c1c..1fafd137 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -173,6 +173,8 @@ class Software(SimComponent): def scan(self) -> None: """Update the observed health status to match the actual health status.""" + super().scan() + self.health_state_visible = self.health_state_actual diff --git a/tests/conftest.py b/tests/conftest.py index 35548f2a..06e55400 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,7 @@ from primaite.environment.primaite_env import Primaite from primaite.primaite_session import PrimaiteSession from primaite.simulator.network.container import Network from primaite.simulator.network.networks import arcd_uc2_network +from primaite.simulator.system.core.sys_log import SysLog from tests.mock_and_patch.get_session_path_mock import get_temp_session_path ACTION_SPACE_NODE_VALUES = 1 diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index d1d78003..539f2874 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -1,6 +1,6 @@ import pytest -from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.file_system.file_system import File, FileSystem, FileSystemItemStatus, Folder from primaite.simulator.file_system.file_type import FileType @@ -135,6 +135,40 @@ def test_folder_quarantine_state(file_system): assert folder.quarantine_status() is False +def test_file_corrupt_repair(file_system): + """Test the ability to corrupt and repair files.""" + folder: Folder = file_system.create_folder(folder_name="test_folder") + file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + file.corrupt() + + assert folder.status == FileSystemItemStatus.GOOD + assert file.status == FileSystemItemStatus.CORRUPTED + + file.repair() + + assert folder.status == FileSystemItemStatus.GOOD + assert file.status == FileSystemItemStatus.GOOD + + +def test_folder_corrupt_repair(file_system): + """Test the ability to corrupt and repair folders.""" + folder: Folder = file_system.create_folder(folder_name="test_folder") + file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + folder.corrupt() + + file = folder.get_file(file_name="test_file.txt") + assert folder.status == FileSystemItemStatus.CORRUPTED + assert file.status == FileSystemItemStatus.CORRUPTED + + folder.repair() + + file = folder.get_file(file_name="test_file.txt") + assert folder.status == FileSystemItemStatus.GOOD + assert file.status == FileSystemItemStatus.GOOD + + @pytest.mark.skip(reason="Skipping until we tackle serialisation") def test_serialisation(file_system): """Test to check that the object serialisation works correctly.""" diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py new file mode 100644 index 00000000..20a3cad5 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py @@ -0,0 +1,80 @@ +from typing import Any + +import pytest + +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.system.services.service import Service, ServiceOperatingState + + +class TestService(Service): + """Test Service class""" + + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + pass + + +@pytest.fixture(scope="function") +def service(file_system) -> TestService: + return TestService( + name="TestService", port=Port.ARP, file_system=file_system, sys_log=SysLog(hostname="test_service") + ) + + +def test_scan(service): + assert service.operating_state == ServiceOperatingState.STOPPED + assert service.visible_operating_state == ServiceOperatingState.STOPPED + + service.start() + assert service.operating_state == ServiceOperatingState.RUNNING + assert service.visible_operating_state == ServiceOperatingState.STOPPED + + service.scan() + assert service.operating_state == ServiceOperatingState.RUNNING + assert service.visible_operating_state == ServiceOperatingState.RUNNING + + +def test_start_service(service): + assert service.operating_state == ServiceOperatingState.STOPPED + service.start() + + assert service.operating_state == ServiceOperatingState.RUNNING + + +def test_stop_service(service): + service.start() + assert service.operating_state == ServiceOperatingState.RUNNING + + service.stop() + assert service.operating_state == ServiceOperatingState.STOPPED + + +def test_pause_and_resume_service(service): + assert service.operating_state == ServiceOperatingState.STOPPED + service.resume() + assert service.operating_state == ServiceOperatingState.STOPPED + + service.start() + service.pause() + assert service.operating_state == ServiceOperatingState.PAUSED + + service.resume() + assert service.operating_state == ServiceOperatingState.RUNNING + + +def test_restart(service): + assert service.operating_state == ServiceOperatingState.STOPPED + service.restart() + assert service.operating_state == ServiceOperatingState.STOPPED + + service.start() + service.restart() + assert service.operating_state == ServiceOperatingState.RESTARTING + + +def test_enable_disable(service): + service.disable() + assert service.operating_state == ServiceOperatingState.DISABLED + + service.enable() + assert service.operating_state == ServiceOperatingState.STOPPED From def2c3699be661656682748677fbcb7a34de5816 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 10 Oct 2023 21:01:09 +0100 Subject: [PATCH 226/980] Add empty obs placeholders --- example_config.yaml | 22 +- sandbox.ipynb | 822 ++++++++++++++++++++++- sandbox.py | 19 + src/primaite/environment/observations.py | 2 +- src/primaite/game/agent/GATE_agents.py | 65 +- src/primaite/game/agent/actions.py | 2 +- src/primaite/game/agent/observations.py | 82 ++- src/primaite/game/session.py | 49 +- src/primaite/transactions/transaction.py | 2 +- 9 files changed, 964 insertions(+), 101 deletions(-) create mode 100644 sandbox.py diff --git a/example_config.yaml b/example_config.yaml index afdf1b0a..a35c82e0 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -12,10 +12,12 @@ game_config: ports: - ARP - DNS + - HTTP - POSTGRES_SERVER protocols: - ICMP - TCP + - UDP agents: - ref: client_1_green_user @@ -111,10 +113,10 @@ game_config: observation_space: type: UC2BlueObservation options: + num_services_per_node: 2 + num_folders_per_node: 2 + num_files_per_folder: 2 nodes: - - node_ref: router_1 #TODO: more sub-options here - - node_ref: switch_1 - - node_ref: switch_2 - node_ref: domain_controller services: - service_ref: domain_controller_dns_server @@ -147,17 +149,23 @@ game_config: - link_ref: switch_2___security_suite acl: router_node_ref: router_1 - node_order: - - node_ref: router_1 - - node_ref: switch_1 - - node_ref: switch_2 + ip_address_order: - node_ref: domain_controller + nic_num: 1 - node_ref: web_server + nic_num: 1 - node_ref: database_server + nic_num: 1 - node_ref: backup_server + nic_num: 1 - node_ref: security_suite + nic_num: 1 - node_ref: client_1 + nic_num: 1 - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 ics: null action_space: diff --git a/sandbox.ipynb b/sandbox.ipynb index a2150921..73c3e682 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -2,9 +2,105 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-10-10 21:00:40,310: Added node f0fb4743-43d5-4741-a0e5-78340a458a11 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", + "2023-10-10 21:00:40,313: Added node 86f4ee9d-386d-4436-96e7-d00dd8bae746 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", + "2023-10-10 21:00:40,316: Added node d2b38f6a-10fe-4d28-86a5-a1d2010c4bea to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", + "2023-10-10 21:00:40,319: Added node 29d55bd4-d59e-4f73-95ad-b430c8716b15 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", + "2023-10-10 21:00:40,323: Added node 5d266f99-03a6-47b3-ab0b-28b8a6813a11 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", + "2023-10-10 21:00:40,333: Added node e4f397c7-eed2-4e69-afaf-ce44664ff1d2 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", + "2023-10-10 21:00:40,338: Added node 19dbb2d4-648b-4387-aa15-99757b513acb to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", + "2023-10-10 21:00:40,344: Added node f508ea65-e660-4b91-8628-5c586075137b to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", + "2023-10-10 21:00:40,350: Added node ffe02a33-7f9c-4fc1-ad3a-791935dbd4c2 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", + "2023-10-10 21:00:40,356: Added node 0ce9efc6-39ae-4d3d-82ad-43be5ac57586 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", + "2023-10-10 21:00:40,360: NIC ba:25:b9:f4:b0:74/192.168.1.1 connected to Link ba:25:b9:f4:b0:74/192.168.1.1<-->3a:25:73:6c:4c:36\n", + "2023-10-10 21:00:40,361: SwitchPort 3a:25:73:6c:4c:36 connected to Link ba:25:b9:f4:b0:74/192.168.1.1<-->3a:25:73:6c:4c:36\n", + "2023-10-10 21:00:40,363: Link ba:25:b9:f4:b0:74/192.168.1.1<-->3a:25:73:6c:4c:36 up\n", + "2023-10-10 21:00:40,364: Link ba:25:b9:f4:b0:74/192.168.1.1<-->3a:25:73:6c:4c:36 up\n", + "2023-10-10 21:00:40,366: Added link eda2befd-9f68-440c-9b20-06838d9e6553 to connect ba:25:b9:f4:b0:74/192.168.1.1 and 3a:25:73:6c:4c:36\n", + "2023-10-10 21:00:40,367: NIC c0:ce:5a:6d:71:73/192.168.1.1 connected to Link c0:ce:5a:6d:71:73/192.168.1.1<-->b2:a4:b3:fc:da:c3\n", + "2023-10-10 21:00:40,368: SwitchPort b2:a4:b3:fc:da:c3 connected to Link c0:ce:5a:6d:71:73/192.168.1.1<-->b2:a4:b3:fc:da:c3\n", + "2023-10-10 21:00:40,370: Link c0:ce:5a:6d:71:73/192.168.1.1<-->b2:a4:b3:fc:da:c3 up\n", + "2023-10-10 21:00:40,370: Link c0:ce:5a:6d:71:73/192.168.1.1<-->b2:a4:b3:fc:da:c3 up\n", + "2023-10-10 21:00:40,372: Added link 0e2a1df6-1c3c-4517-b41f-04a5cefe307c to connect c0:ce:5a:6d:71:73/192.168.1.1 and b2:a4:b3:fc:da:c3\n", + "2023-10-10 21:00:40,373: SwitchPort 72:f3:93:a5:a5:59 connected to Link 72:f3:93:a5:a5:59<-->e1:9b:c0:59:1d:46/192.168.1.10\n", + "2023-10-10 21:00:40,377: Link 72:f3:93:a5:a5:59<-->e1:9b:c0:59:1d:46/192.168.1.10 up\n", + "2023-10-10 21:00:40,379: NIC e1:9b:c0:59:1d:46/192.168.1.10 connected to Link 72:f3:93:a5:a5:59<-->e1:9b:c0:59:1d:46/192.168.1.10\n", + "2023-10-10 21:00:40,380: Link 72:f3:93:a5:a5:59<-->e1:9b:c0:59:1d:46/192.168.1.10 up\n", + "2023-10-10 21:00:40,381: Added link 48c9173d-847b-441f-9f15-f7838cf09083 to connect 72:f3:93:a5:a5:59 and e1:9b:c0:59:1d:46/192.168.1.10\n", + "2023-10-10 21:00:40,382: SwitchPort 67:36:e8:51:35:f2 connected to Link 67:36:e8:51:35:f2<-->3b:a3:b4:ec:a0:2a/192.168.1.12\n", + "2023-10-10 21:00:40,384: Link 67:36:e8:51:35:f2<-->3b:a3:b4:ec:a0:2a/192.168.1.12 up\n", + "2023-10-10 21:00:40,385: NIC 3b:a3:b4:ec:a0:2a/192.168.1.12 connected to Link 67:36:e8:51:35:f2<-->3b:a3:b4:ec:a0:2a/192.168.1.12\n", + "2023-10-10 21:00:40,386: Link 67:36:e8:51:35:f2<-->3b:a3:b4:ec:a0:2a/192.168.1.12 up\n", + "2023-10-10 21:00:40,386: Added link 7259c2a4-44f7-44d9-87de-1a692c98ac58 to connect 67:36:e8:51:35:f2 and 3b:a3:b4:ec:a0:2a/192.168.1.12\n", + "2023-10-10 21:00:40,388: SwitchPort be:56:a8:d3:f9:6c connected to Link be:56:a8:d3:f9:6c<-->99:24:3a:ad:99:5b/192.168.1.14\n", + "2023-10-10 21:00:40,391: Link be:56:a8:d3:f9:6c<-->99:24:3a:ad:99:5b/192.168.1.14 up\n", + "2023-10-10 21:00:40,392: NIC 99:24:3a:ad:99:5b/192.168.1.14 connected to Link be:56:a8:d3:f9:6c<-->99:24:3a:ad:99:5b/192.168.1.14\n", + "2023-10-10 21:00:40,394: Link be:56:a8:d3:f9:6c<-->99:24:3a:ad:99:5b/192.168.1.14 up\n", + "2023-10-10 21:00:40,396: Added link ff3c3f9a-c267-421a-9e2f-bcc11a6fa082 to connect be:56:a8:d3:f9:6c and 99:24:3a:ad:99:5b/192.168.1.14\n", + "2023-10-10 21:00:40,397: SwitchPort 4f:91:78:5a:68:3f connected to Link 4f:91:78:5a:68:3f<-->2b:ff:81:44:7f:61/192.168.1.16\n", + "2023-10-10 21:00:40,399: Link 4f:91:78:5a:68:3f<-->2b:ff:81:44:7f:61/192.168.1.16 up\n", + "2023-10-10 21:00:40,400: NIC 2b:ff:81:44:7f:61/192.168.1.16 connected to Link 4f:91:78:5a:68:3f<-->2b:ff:81:44:7f:61/192.168.1.16\n", + "2023-10-10 21:00:40,401: Link 4f:91:78:5a:68:3f<-->2b:ff:81:44:7f:61/192.168.1.16 up\n", + "2023-10-10 21:00:40,402: Added link b5a2e61c-f14d-45a3-a27e-2451f21229d5 to connect 4f:91:78:5a:68:3f and 2b:ff:81:44:7f:61/192.168.1.16\n", + "2023-10-10 21:00:40,403: SwitchPort 14:8e:63:89:28:f6 connected to Link 14:8e:63:89:28:f6<-->72:ca:83:f9:d0:66/192.168.1.110\n", + "2023-10-10 21:00:40,404: Link 14:8e:63:89:28:f6<-->72:ca:83:f9:d0:66/192.168.1.110 up\n", + "2023-10-10 21:00:40,405: NIC 72:ca:83:f9:d0:66/192.168.1.110 connected to Link 14:8e:63:89:28:f6<-->72:ca:83:f9:d0:66/192.168.1.110\n", + "2023-10-10 21:00:40,406: Link 14:8e:63:89:28:f6<-->72:ca:83:f9:d0:66/192.168.1.110 up\n", + "2023-10-10 21:00:40,407: Added link d0906ccd-5f98-415a-b08e-b8ebfdd3c5a9 to connect 14:8e:63:89:28:f6 and 72:ca:83:f9:d0:66/192.168.1.110\n", + "2023-10-10 21:00:40,409: SwitchPort e5:20:55:91:b5:b9 connected to Link e5:20:55:91:b5:b9<-->27:2f:d1:75:04:f9/192.168.10.21\n", + "2023-10-10 21:00:40,412: Link e5:20:55:91:b5:b9<-->27:2f:d1:75:04:f9/192.168.10.21 up\n", + "2023-10-10 21:00:40,413: NIC 27:2f:d1:75:04:f9/192.168.10.21 connected to Link e5:20:55:91:b5:b9<-->27:2f:d1:75:04:f9/192.168.10.21\n", + "2023-10-10 21:00:40,414: Link e5:20:55:91:b5:b9<-->27:2f:d1:75:04:f9/192.168.10.21 up\n", + "2023-10-10 21:00:40,415: Added link 51f14a80-8fd6-4de9-86a3-9c726c036167 to connect e5:20:55:91:b5:b9 and 27:2f:d1:75:04:f9/192.168.10.21\n", + "2023-10-10 21:00:40,416: SwitchPort 4e:58:c4:9c:0c:6d connected to Link 4e:58:c4:9c:0c:6d<-->2e:f5:71:bb:73:ec/192.168.10.22\n", + "2023-10-10 21:00:40,418: Link 4e:58:c4:9c:0c:6d<-->2e:f5:71:bb:73:ec/192.168.10.22 up\n", + "2023-10-10 21:00:40,420: NIC 2e:f5:71:bb:73:ec/192.168.10.22 connected to Link 4e:58:c4:9c:0c:6d<-->2e:f5:71:bb:73:ec/192.168.10.22\n", + "2023-10-10 21:00:40,420: Link 4e:58:c4:9c:0c:6d<-->2e:f5:71:bb:73:ec/192.168.10.22 up\n", + "2023-10-10 21:00:40,421: Added link 7463a72f-af42-435f-ad98-83bcfe5728a3 to connect 4e:58:c4:9c:0c:6d and 2e:f5:71:bb:73:ec/192.168.10.22\n", + "2023-10-10 21:00:40,423: SwitchPort 66:98:bd:ca:08:b0 connected to Link 66:98:bd:ca:08:b0<-->cf:f7:fc:d1:f4:ae/192.168.10.110\n", + "2023-10-10 21:00:40,425: Link 66:98:bd:ca:08:b0<-->cf:f7:fc:d1:f4:ae/192.168.10.110 up\n", + "2023-10-10 21:00:40,427: NIC cf:f7:fc:d1:f4:ae/192.168.10.110 connected to Link 66:98:bd:ca:08:b0<-->cf:f7:fc:d1:f4:ae/192.168.10.110\n", + "2023-10-10 21:00:40,428: Link 66:98:bd:ca:08:b0<-->cf:f7:fc:d1:f4:ae/192.168.10.110 up\n", + "2023-10-10 21:00:40,430: Added link ff6fd52d-f893-4c0d-99d2-28f10c128043 to connect 66:98:bd:ca:08:b0 and cf:f7:fc:d1:f4:ae/192.168.10.110\n", + "2023-10-10 21:00:40,431: Stepping primaite session. Step counter: 0\n", + "2023-10-10 21:00:40,432: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,433: Getting agent action\n", + "2023-10-10 21:00:40,435: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,436: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,437: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,439: Getting agent action\n", + "2023-10-10 21:00:40,440: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:40,441: Sending request to simulation: ['do_nothing']\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "/home/cade/.local/state/primaite/2.0.0/log\n", + "service type not found DatabaseBackup\n", + "service type not found WebBrowser\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-10-10 21:00:40,443: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,445: Getting agent action\n", + "2023-10-10 21:00:40,447: Formatting agent action NODE_FOLDER_RESTORE\n", + "2023-10-10 21:00:40,449: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,450: Initiating simulation step 0\n" + ] + } + ], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", @@ -14,11 +110,7 @@ "import logging\n", "_PRIMAITE_CONFIG['log_level']=logging.DEBUG\n", "print(PRIMAITE_PATHS.app_log_dir_path)\n", - "import itertools\n", "from primaite.game.session import PrimaiteSession\n", - "from primaite.simulator.sim_container import Simulation\n", - "from primaite.game.agent.interface import AbstractAgent\n", - "from primaite.simulator.network.networks import arcd_uc2_network\n", "import yaml\n", "\n", "with open('example_config.yaml', 'r') as file:\n", @@ -29,13 +121,727 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-10-10 21:00:40,481: Stepping primaite session. Step counter: 1\n", + "2023-10-10 21:00:40,484: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,486: Getting agent action\n", + "2023-10-10 21:00:40,487: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,488: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,489: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,491: Getting agent action\n", + "2023-10-10 21:00:40,493: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:40,494: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,495: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,497: Getting agent action\n", + "2023-10-10 21:00:40,498: Formatting agent action NETWORK_ACL_REMOVERULE\n", + "2023-10-10 21:00:40,499: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 8]\n", + "2023-10-10 21:00:40,500: Initiating simulation step 1\n", + "2023-10-10 21:00:40,502: Stepping primaite session. Step counter: 2\n", + "2023-10-10 21:00:40,503: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,504: Getting agent action\n", + "2023-10-10 21:00:40,505: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,505: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,506: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,508: Getting agent action\n", + "2023-10-10 21:00:40,511: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:40,513: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,513: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,515: Getting agent action\n", + "2023-10-10 21:00:40,516: Formatting agent action NETWORK_ACL_ADDRULE\n", + "2023-10-10 21:00:40,518: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,519: Initiating simulation step 2\n", + "2023-10-10 21:00:40,520: Stepping primaite session. Step counter: 3\n", + "2023-10-10 21:00:40,521: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,522: Getting agent action\n", + "2023-10-10 21:00:40,524: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,525: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,526: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,528: Getting agent action\n", + "2023-10-10 21:00:40,530: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,531: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,533: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,534: Getting agent action\n", + "2023-10-10 21:00:40,535: Formatting agent action NETWORK_ACL_REMOVERULE\n", + "2023-10-10 21:00:40,537: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 1]\n", + "2023-10-10 21:00:40,538: Initiating simulation step 3\n", + "2023-10-10 21:00:40,539: Stepping primaite session. Step counter: 4\n", + "2023-10-10 21:00:40,541: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,543: Getting agent action\n", + "2023-10-10 21:00:40,545: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,546: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,547: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,550: Getting agent action\n", + "2023-10-10 21:00:40,552: Formatting agent action NODE_OS_SCAN\n", + "2023-10-10 21:00:40,554: Sending request to simulation: ['network', 'node', 'ffe02a33-7f9c-4fc1-ad3a-791935dbd4c2', 'scan']\n", + "2023-10-10 21:00:40,555: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,573: Getting agent action\n", + "2023-10-10 21:00:40,575: Formatting agent action NETWORK_ACL_REMOVERULE\n", + "2023-10-10 21:00:40,577: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 2]\n", + "2023-10-10 21:00:40,578: Initiating simulation step 4\n", + "2023-10-10 21:00:40,580: Stepping primaite session. Step counter: 5\n", + "2023-10-10 21:00:40,581: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,583: Getting agent action\n", + "2023-10-10 21:00:40,585: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,586: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,587: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,597: Getting agent action\n", + "2023-10-10 21:00:40,598: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:40,599: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,601: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,603: Getting agent action\n", + "2023-10-10 21:00:40,605: Formatting agent action NETWORK_ACL_REMOVERULE\n", + "2023-10-10 21:00:40,606: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 0]\n", + "2023-10-10 21:00:40,613: Initiating simulation step 5\n", + "2023-10-10 21:00:40,614: Stepping primaite session. Step counter: 6\n", + "2023-10-10 21:00:40,615: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,617: Getting agent action\n", + "2023-10-10 21:00:40,618: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,619: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,620: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,621: Getting agent action\n", + "2023-10-10 21:00:40,623: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:40,624: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,625: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,626: Getting agent action\n", + "2023-10-10 21:00:40,628: Formatting agent action NETWORK_ACL_REMOVERULE\n", + "2023-10-10 21:00:40,629: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 7]\n", + "2023-10-10 21:00:40,630: Initiating simulation step 6\n", + "2023-10-10 21:00:40,631: Stepping primaite session. Step counter: 7\n", + "2023-10-10 21:00:40,631: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,633: Getting agent action\n", + "2023-10-10 21:00:40,634: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,635: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,635: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,636: Getting agent action\n", + "2023-10-10 21:00:40,639: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:40,640: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,642: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,644: Getting agent action\n", + "2023-10-10 21:00:40,645: Formatting agent action NODE_SERVICE_STOP\n", + "2023-10-10 21:00:40,646: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,647: Initiating simulation step 7\n", + "2023-10-10 21:00:40,648: Stepping primaite session. Step counter: 8\n", + "2023-10-10 21:00:40,649: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,651: Getting agent action\n", + "2023-10-10 21:00:40,652: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,652: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,653: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,655: Getting agent action\n", + "2023-10-10 21:00:40,656: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,657: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,659: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,661: Getting agent action\n", + "2023-10-10 21:00:40,662: Formatting agent action NODE_FILE_RESTORE\n", + "2023-10-10 21:00:40,663: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,664: Initiating simulation step 8\n", + "2023-10-10 21:00:40,665: Stepping primaite session. Step counter: 9\n", + "2023-10-10 21:00:40,667: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,668: Getting agent action\n", + "2023-10-10 21:00:40,669: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,670: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,672: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,674: Getting agent action\n", + "2023-10-10 21:00:40,676: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:40,677: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,678: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,679: Getting agent action\n", + "2023-10-10 21:00:40,681: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,682: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,683: Initiating simulation step 9\n", + "2023-10-10 21:00:40,684: Stepping primaite session. Step counter: 10\n", + "2023-10-10 21:00:40,685: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,687: Getting agent action\n", + "2023-10-10 21:00:40,688: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,689: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,690: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,694: Getting agent action\n", + "2023-10-10 21:00:40,696: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:40,697: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,698: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,700: Getting agent action\n", + "2023-10-10 21:00:40,702: Formatting agent action NODE_FILE_SCAN\n", + "2023-10-10 21:00:40,705: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,706: Initiating simulation step 10\n", + "2023-10-10 21:00:40,709: Stepping primaite session. Step counter: 11\n", + "2023-10-10 21:00:40,711: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,713: Getting agent action\n", + "2023-10-10 21:00:40,715: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,716: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,717: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,719: Getting agent action\n", + "2023-10-10 21:00:40,722: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:40,724: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,726: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,728: Getting agent action\n", + "2023-10-10 21:00:40,730: Formatting agent action NODE_SERVICE_START\n", + "2023-10-10 21:00:40,731: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,733: Initiating simulation step 11\n", + "2023-10-10 21:00:40,735: Stepping primaite session. Step counter: 12\n", + "2023-10-10 21:00:40,736: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,738: Getting agent action\n", + "2023-10-10 21:00:40,739: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,740: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,741: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,743: Getting agent action\n", + "2023-10-10 21:00:40,746: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:40,748: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,749: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,752: Getting agent action\n", + "2023-10-10 21:00:40,755: Formatting agent action NETWORK_ACL_ADDRULE\n", + "2023-10-10 21:00:40,758: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'add_rule', 'DENY', 'TCP', IPv4Address('192.168.1.12'), 'ALL', IPv4Address('127.0.0.1'), 'ALL', 1]\n", + "2023-10-10 21:00:40,760: Initiating simulation step 12\n", + "2023-10-10 21:00:40,762: Stepping primaite session. Step counter: 13\n", + "2023-10-10 21:00:40,763: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,766: Getting agent action\n", + "2023-10-10 21:00:40,768: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,769: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,771: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,773: Getting agent action\n", + "2023-10-10 21:00:40,777: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:40,779: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,780: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,782: Getting agent action\n", + "2023-10-10 21:00:40,784: Formatting agent action NODE_SERVICE_RESTART\n", + "2023-10-10 21:00:40,785: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,786: Initiating simulation step 13\n", + "2023-10-10 21:00:40,787: Stepping primaite session. Step counter: 14\n", + "2023-10-10 21:00:40,788: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,790: Getting agent action\n", + "2023-10-10 21:00:40,792: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,794: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,795: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,797: Getting agent action\n", + "2023-10-10 21:00:40,799: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:40,800: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,801: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,803: Getting agent action\n", + "2023-10-10 21:00:40,805: Formatting agent action NODE_SERVICE_DISABLE\n", + "2023-10-10 21:00:40,806: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,807: Initiating simulation step 14\n", + "2023-10-10 21:00:40,808: Stepping primaite session. Step counter: 15\n", + "2023-10-10 21:00:40,809: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,813: Getting agent action\n", + "2023-10-10 21:00:40,815: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,817: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,818: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,821: Getting agent action\n", + "2023-10-10 21:00:40,822: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:40,824: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,828: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,830: Getting agent action\n", + "2023-10-10 21:00:40,832: Formatting agent action NETWORK_NIC_DISABLE\n", + "2023-10-10 21:00:40,833: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,835: Initiating simulation step 15\n", + "2023-10-10 21:00:40,836: Stepping primaite session. Step counter: 16\n", + "2023-10-10 21:00:40,838: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,840: Getting agent action\n", + "2023-10-10 21:00:40,848: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,852: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,856: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,858: Getting agent action\n", + "2023-10-10 21:00:40,863: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:40,868: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,869: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,872: Getting agent action\n", + "2023-10-10 21:00:40,878: Formatting agent action NODE_OS_SCAN\n", + "2023-10-10 21:00:40,883: Sending request to simulation: ['network', 'node', '29d55bd4-d59e-4f73-95ad-b430c8716b15', 'scan']\n", + "2023-10-10 21:00:40,885: Initiating simulation step 16\n", + "2023-10-10 21:00:40,887: Stepping primaite session. Step counter: 17\n", + "2023-10-10 21:00:40,889: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,900: Getting agent action\n", + "2023-10-10 21:00:40,904: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,909: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,911: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,913: Getting agent action\n", + "2023-10-10 21:00:40,915: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:40,917: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,918: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,920: Getting agent action\n", + "2023-10-10 21:00:40,921: Formatting agent action NETWORK_ACL_ADDRULE\n", + "2023-10-10 21:00:40,922: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'add_rule', 'DENY', 'TCP', IPv4Address('192.168.1.10'), 'ALL', IPv4Address('127.0.0.1'), 'ALL', 1]\n", + "2023-10-10 21:00:40,924: Initiating simulation step 17\n", + "2023-10-10 21:00:40,925: Stepping primaite session. Step counter: 18\n", + "2023-10-10 21:00:40,927: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,929: Getting agent action\n", + "2023-10-10 21:00:40,931: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,933: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,934: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,936: Getting agent action\n", + "2023-10-10 21:00:40,938: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:40,940: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,941: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,945: Getting agent action\n", + "2023-10-10 21:00:40,947: Formatting agent action NETWORK_ACL_ADDRULE\n", + "2023-10-10 21:00:40,948: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,949: Initiating simulation step 18\n", + "2023-10-10 21:00:40,951: Stepping primaite session. Step counter: 19\n", + "2023-10-10 21:00:40,952: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,954: Getting agent action\n", + "2023-10-10 21:00:40,955: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,957: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,960: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,962: Getting agent action\n", + "2023-10-10 21:00:40,964: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:40,966: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,967: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,969: Getting agent action\n", + "2023-10-10 21:00:40,971: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,972: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,973: Initiating simulation step 19\n", + "2023-10-10 21:00:40,975: Stepping primaite session. Step counter: 20\n", + "2023-10-10 21:00:40,976: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:40,979: Getting agent action\n", + "2023-10-10 21:00:40,981: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:40,982: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,983: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:40,986: Getting agent action\n", + "2023-10-10 21:00:40,987: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:40,989: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:40,990: Sending simulation state to agent defender\n", + "2023-10-10 21:00:40,992: Getting agent action\n", + "2023-10-10 21:00:40,994: Formatting agent action NETWORK_ACL_ADDRULE\n", + "2023-10-10 21:00:40,996: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'add_rule', 'DENY', 'TCP', IPv4Address('192.168.1.12'), 'ALL', IPv4Address('127.0.0.1'), 'ALL', 1]\n", + "2023-10-10 21:00:40,997: Initiating simulation step 20\n", + "2023-10-10 21:00:40,998: Stepping primaite session. Step counter: 21\n", + "2023-10-10 21:00:41,000: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,001: Getting agent action\n", + "2023-10-10 21:00:41,003: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,004: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,005: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,006: Getting agent action\n", + "2023-10-10 21:00:41,009: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,010: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,011: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,014: Getting agent action\n", + "2023-10-10 21:00:41,016: Formatting agent action NODE_FILE_REPAIR\n", + "2023-10-10 21:00:41,017: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,018: Initiating simulation step 21\n", + "2023-10-10 21:00:41,020: Stepping primaite session. Step counter: 22\n", + "2023-10-10 21:00:41,021: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,023: Getting agent action\n", + "2023-10-10 21:00:41,024: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,025: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,027: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,030: Getting agent action\n", + "2023-10-10 21:00:41,031: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:41,033: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,034: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,036: Getting agent action\n", + "2023-10-10 21:00:41,037: Formatting agent action NODE_FILE_REPAIR\n", + "2023-10-10 21:00:41,038: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,039: Initiating simulation step 22\n", + "2023-10-10 21:00:41,040: Stepping primaite session. Step counter: 23\n", + "2023-10-10 21:00:41,042: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,045: Getting agent action\n", + "2023-10-10 21:00:41,047: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,049: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,050: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,056: Getting agent action\n", + "2023-10-10 21:00:41,065: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:41,067: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,068: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,072: Getting agent action\n", + "2023-10-10 21:00:41,073: Formatting agent action NODE_FOLDER_REPAIR\n", + "2023-10-10 21:00:41,075: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,077: Initiating simulation step 23\n", + "2023-10-10 21:00:41,079: Stepping primaite session. Step counter: 24\n", + "2023-10-10 21:00:41,081: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,083: Getting agent action\n", + "2023-10-10 21:00:41,085: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,086: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,088: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,090: Getting agent action\n", + "2023-10-10 21:00:41,092: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,093: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,095: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,097: Getting agent action\n", + "2023-10-10 21:00:41,099: Formatting agent action NODE_STARTUP\n", + "2023-10-10 21:00:41,100: Sending request to simulation: ['network', 'node', '19dbb2d4-648b-4387-aa15-99757b513acb', 'startup']\n", + "2023-10-10 21:00:41,102: Initiating simulation step 24\n", + "2023-10-10 21:00:41,103: Stepping primaite session. Step counter: 25\n", + "2023-10-10 21:00:41,104: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,107: Getting agent action\n", + "2023-10-10 21:00:41,110: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,112: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,113: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,114: Getting agent action\n", + "2023-10-10 21:00:41,116: Formatting agent action NODE_OS_SCAN\n", + "2023-10-10 21:00:41,118: Sending request to simulation: ['network', 'node', 'ffe02a33-7f9c-4fc1-ad3a-791935dbd4c2', 'scan']\n", + "2023-10-10 21:00:41,120: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,122: Getting agent action\n", + "2023-10-10 21:00:41,124: Formatting agent action NODE_FOLDER_RESTORE\n", + "2023-10-10 21:00:41,126: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,127: Initiating simulation step 25\n", + "2023-10-10 21:00:41,129: Stepping primaite session. Step counter: 26\n", + "2023-10-10 21:00:41,130: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,132: Getting agent action\n", + "2023-10-10 21:00:41,134: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,136: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,137: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,139: Getting agent action\n", + "2023-10-10 21:00:41,141: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,142: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,144: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,145: Getting agent action\n", + "2023-10-10 21:00:41,147: Formatting agent action NODE_STARTUP\n", + "2023-10-10 21:00:41,148: Sending request to simulation: ['network', 'node', '19dbb2d4-648b-4387-aa15-99757b513acb', 'startup']\n", + "2023-10-10 21:00:41,150: Initiating simulation step 26\n", + "2023-10-10 21:00:41,151: Stepping primaite session. Step counter: 27\n", + "2023-10-10 21:00:41,153: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,155: Getting agent action\n", + "2023-10-10 21:00:41,157: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,158: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,160: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,162: Getting agent action\n", + "2023-10-10 21:00:41,164: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,166: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,166: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,169: Getting agent action\n", + "2023-10-10 21:00:41,170: Formatting agent action NODE_SERVICE_START\n", + "2023-10-10 21:00:41,172: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,173: Initiating simulation step 27\n", + "2023-10-10 21:00:41,174: Stepping primaite session. Step counter: 28\n", + "2023-10-10 21:00:41,176: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,177: Getting agent action\n", + "2023-10-10 21:00:41,179: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,181: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,182: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,183: Getting agent action\n", + "2023-10-10 21:00:41,185: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,186: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,187: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,188: Getting agent action\n", + "2023-10-10 21:00:41,190: Formatting agent action NETWORK_NIC_DISABLE\n", + "2023-10-10 21:00:41,191: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,193: Initiating simulation step 28\n", + "2023-10-10 21:00:41,194: Stepping primaite session. Step counter: 29\n", + "2023-10-10 21:00:41,196: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,198: Getting agent action\n", + "2023-10-10 21:00:41,199: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,201: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,201: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,203: Getting agent action\n", + "2023-10-10 21:00:41,204: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,206: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,207: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,208: Getting agent action\n", + "2023-10-10 21:00:41,211: Formatting agent action NETWORK_ACL_REMOVERULE\n", + "2023-10-10 21:00:41,213: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 3]\n", + "2023-10-10 21:00:41,215: Initiating simulation step 29\n", + "2023-10-10 21:00:41,217: Stepping primaite session. Step counter: 30\n", + "2023-10-10 21:00:41,218: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,220: Getting agent action\n", + "2023-10-10 21:00:41,221: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,222: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,223: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,225: Getting agent action\n", + "2023-10-10 21:00:41,227: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,229: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,231: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,232: Getting agent action\n", + "2023-10-10 21:00:41,233: Formatting agent action NETWORK_ACL_ADDRULE\n", + "2023-10-10 21:00:41,235: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'add_rule', 'DENY', 'TCP', IPv4Address('192.168.1.10'), 'ALL', IPv4Address('127.0.0.1'), 'ALL', 1]\n", + "2023-10-10 21:00:41,236: Initiating simulation step 30\n", + "2023-10-10 21:00:41,238: Stepping primaite session. Step counter: 31\n", + "2023-10-10 21:00:41,238: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,240: Getting agent action\n", + "2023-10-10 21:00:41,242: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,244: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,245: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,248: Getting agent action\n", + "2023-10-10 21:00:41,249: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:41,251: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,252: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,254: Getting agent action\n", + "2023-10-10 21:00:41,255: Formatting agent action NODE_FILE_RESTORE\n", + "2023-10-10 21:00:41,256: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,257: Initiating simulation step 31\n", + "2023-10-10 21:00:41,259: Stepping primaite session. Step counter: 32\n", + "2023-10-10 21:00:41,260: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,263: Getting agent action\n", + "2023-10-10 21:00:41,264: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,266: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,267: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,268: Getting agent action\n", + "2023-10-10 21:00:41,269: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,270: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,272: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,273: Getting agent action\n", + "2023-10-10 21:00:41,275: Formatting agent action NODE_FILE_RESTORE\n", + "2023-10-10 21:00:41,277: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,278: Initiating simulation step 32\n", + "2023-10-10 21:00:41,280: Stepping primaite session. Step counter: 33\n", + "2023-10-10 21:00:41,281: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,284: Getting agent action\n", + "2023-10-10 21:00:41,286: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,288: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,289: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,291: Getting agent action\n", + "2023-10-10 21:00:41,293: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,295: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,299: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,301: Getting agent action\n", + "2023-10-10 21:00:41,307: Formatting agent action NETWORK_ACL_REMOVERULE\n", + "2023-10-10 21:00:41,309: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 2]\n", + "2023-10-10 21:00:41,311: Initiating simulation step 33\n", + "2023-10-10 21:00:41,312: Stepping primaite session. Step counter: 34\n", + "2023-10-10 21:00:41,322: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,325: Getting agent action\n", + "2023-10-10 21:00:41,327: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,328: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,339: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,341: Getting agent action\n", + "2023-10-10 21:00:41,343: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,345: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,346: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,348: Getting agent action\n", + "2023-10-10 21:00:41,350: Formatting agent action NODE_FOLDER_CHECKHASH\n", + "2023-10-10 21:00:41,352: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,354: Initiating simulation step 34\n", + "2023-10-10 21:00:41,355: Stepping primaite session. Step counter: 35\n", + "2023-10-10 21:00:41,357: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,359: Getting agent action\n", + "2023-10-10 21:00:41,360: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,362: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,363: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,366: Getting agent action\n", + "2023-10-10 21:00:41,368: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,369: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,370: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,371: Getting agent action\n", + "2023-10-10 21:00:41,373: Formatting agent action NODE_FILE_RESTORE\n", + "2023-10-10 21:00:41,378: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,381: Initiating simulation step 35\n", + "2023-10-10 21:00:41,382: Stepping primaite session. Step counter: 36\n", + "2023-10-10 21:00:41,384: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,386: Getting agent action\n", + "2023-10-10 21:00:41,388: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,389: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,390: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,392: Getting agent action\n", + "2023-10-10 21:00:41,394: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,395: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,397: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,399: Getting agent action\n", + "2023-10-10 21:00:41,401: Formatting agent action NODE_SERVICE_RESUME\n", + "2023-10-10 21:00:41,402: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,403: Initiating simulation step 36\n", + "2023-10-10 21:00:41,405: Stepping primaite session. Step counter: 37\n", + "2023-10-10 21:00:41,406: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,408: Getting agent action\n", + "2023-10-10 21:00:41,409: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,410: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,413: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,415: Getting agent action\n", + "2023-10-10 21:00:41,416: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:41,417: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,418: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,420: Getting agent action\n", + "2023-10-10 21:00:41,422: Formatting agent action NETWORK_ACL_ADDRULE\n", + "2023-10-10 21:00:41,422: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,424: Initiating simulation step 37\n", + "2023-10-10 21:00:41,425: Stepping primaite session. Step counter: 38\n", + "2023-10-10 21:00:41,427: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,429: Getting agent action\n", + "2023-10-10 21:00:41,431: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,432: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,433: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,434: Getting agent action\n", + "2023-10-10 21:00:41,436: Formatting agent action NODE_OS_SCAN\n", + "2023-10-10 21:00:41,438: Sending request to simulation: ['network', 'node', 'ffe02a33-7f9c-4fc1-ad3a-791935dbd4c2', 'scan']\n", + "2023-10-10 21:00:41,440: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,442: Getting agent action\n", + "2023-10-10 21:00:41,444: Formatting agent action NODE_FILE_CHECKHASH\n", + "2023-10-10 21:00:41,449: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,451: Initiating simulation step 38\n", + "2023-10-10 21:00:41,452: Stepping primaite session. Step counter: 39\n", + "2023-10-10 21:00:41,453: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,457: Getting agent action\n", + "2023-10-10 21:00:41,459: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,461: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,462: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,464: Getting agent action\n", + "2023-10-10 21:00:41,465: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,467: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,469: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,472: Getting agent action\n", + "2023-10-10 21:00:41,475: Formatting agent action NODE_SERVICE_SCAN\n", + "2023-10-10 21:00:41,476: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,477: Initiating simulation step 39\n", + "2023-10-10 21:00:41,479: Stepping primaite session. Step counter: 40\n", + "2023-10-10 21:00:41,480: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,482: Getting agent action\n", + "2023-10-10 21:00:41,484: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,486: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,487: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,489: Getting agent action\n", + "2023-10-10 21:00:41,490: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:41,491: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,493: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,495: Getting agent action\n", + "2023-10-10 21:00:41,497: Formatting agent action NETWORK_ACL_REMOVERULE\n", + "2023-10-10 21:00:41,498: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 7]\n", + "2023-10-10 21:00:41,499: Initiating simulation step 40\n", + "2023-10-10 21:00:41,501: Stepping primaite session. Step counter: 41\n", + "2023-10-10 21:00:41,503: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,504: Getting agent action\n", + "2023-10-10 21:00:41,506: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,507: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,509: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,510: Getting agent action\n", + "2023-10-10 21:00:41,513: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:41,514: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,515: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,517: Getting agent action\n", + "2023-10-10 21:00:41,519: Formatting agent action NETWORK_ACL_REMOVERULE\n", + "2023-10-10 21:00:41,520: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 0]\n", + "2023-10-10 21:00:41,521: Initiating simulation step 41\n", + "2023-10-10 21:00:41,522: Stepping primaite session. Step counter: 42\n", + "2023-10-10 21:00:41,523: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,524: Getting agent action\n", + "2023-10-10 21:00:41,527: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,528: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,530: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,532: Getting agent action\n", + "2023-10-10 21:00:41,534: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,535: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,536: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,538: Getting agent action\n", + "2023-10-10 21:00:41,540: Formatting agent action NODE_RESET\n", + "2023-10-10 21:00:41,541: Sending request to simulation: ['network', 'node', '19dbb2d4-648b-4387-aa15-99757b513acb', 'reset']\n", + "2023-10-10 21:00:41,543: Initiating simulation step 42\n", + "2023-10-10 21:00:41,544: Stepping primaite session. Step counter: 43\n", + "2023-10-10 21:00:41,546: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,548: Getting agent action\n", + "2023-10-10 21:00:41,550: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,551: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,552: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,554: Getting agent action\n", + "2023-10-10 21:00:41,555: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,556: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,557: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,559: Getting agent action\n", + "2023-10-10 21:00:41,561: Formatting agent action NODE_FOLDER_RESTORE\n", + "2023-10-10 21:00:41,563: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,565: Initiating simulation step 43\n", + "2023-10-10 21:00:41,566: Stepping primaite session. Step counter: 44\n", + "2023-10-10 21:00:41,567: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,568: Getting agent action\n", + "2023-10-10 21:00:41,569: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,570: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,571: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,574: Getting agent action\n", + "2023-10-10 21:00:41,575: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,577: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,578: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,581: Getting agent action\n", + "2023-10-10 21:00:41,583: Formatting agent action NETWORK_ACL_ADDRULE\n", + "2023-10-10 21:00:41,584: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'add_rule', 'DENY', 'TCP', IPv4Address('192.168.1.12'), 'ALL', IPv4Address('127.0.0.1'), 'ALL', 1]\n", + "2023-10-10 21:00:41,586: Initiating simulation step 44\n", + "2023-10-10 21:00:41,587: Stepping primaite session. Step counter: 45\n", + "2023-10-10 21:00:41,588: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,590: Getting agent action\n", + "2023-10-10 21:00:41,591: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,593: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,594: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,596: Getting agent action\n", + "2023-10-10 21:00:41,598: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,599: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,600: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,602: Getting agent action\n", + "2023-10-10 21:00:41,603: Formatting agent action NETWORK_ACL_REMOVERULE\n", + "2023-10-10 21:00:41,604: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 1]\n", + "2023-10-10 21:00:41,605: Initiating simulation step 45\n", + "2023-10-10 21:00:41,606: Stepping primaite session. Step counter: 46\n", + "2023-10-10 21:00:41,607: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,608: Getting agent action\n", + "2023-10-10 21:00:41,610: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,612: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,613: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,616: Getting agent action\n", + "2023-10-10 21:00:41,617: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,618: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,620: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,621: Getting agent action\n", + "2023-10-10 21:00:41,623: Formatting agent action NETWORK_ACL_ADDRULE\n", + "2023-10-10 21:00:41,624: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'add_rule', 'DENY', 'TCP', IPv4Address('192.168.1.10'), 'ALL', IPv4Address('127.0.0.1'), 'ALL', 1]\n", + "2023-10-10 21:00:41,626: Initiating simulation step 46\n", + "2023-10-10 21:00:41,627: Stepping primaite session. Step counter: 47\n", + "2023-10-10 21:00:41,628: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,630: Getting agent action\n", + "2023-10-10 21:00:41,632: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,634: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,635: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,636: Getting agent action\n", + "2023-10-10 21:00:41,638: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:41,639: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,640: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,642: Getting agent action\n", + "2023-10-10 21:00:41,643: Formatting agent action NETWORK_ACL_ADDRULE\n", + "2023-10-10 21:00:41,644: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,646: Initiating simulation step 47\n", + "2023-10-10 21:00:41,648: Stepping primaite session. Step counter: 48\n", + "2023-10-10 21:00:41,649: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,651: Getting agent action\n", + "2023-10-10 21:00:41,652: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,653: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,654: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,657: Getting agent action\n", + "2023-10-10 21:00:41,658: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:41,661: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,663: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,665: Getting agent action\n", + "2023-10-10 21:00:41,667: Formatting agent action NODE_SERVICE_STOP\n", + "2023-10-10 21:00:41,669: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,670: Initiating simulation step 48\n", + "2023-10-10 21:00:41,672: Stepping primaite session. Step counter: 49\n", + "2023-10-10 21:00:41,674: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,684: Getting agent action\n", + "2023-10-10 21:00:41,687: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,689: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,690: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,701: Getting agent action\n", + "2023-10-10 21:00:41,702: Formatting agent action NODE_FILE_CORRUPT\n", + "2023-10-10 21:00:41,705: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,715: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,718: Getting agent action\n", + "2023-10-10 21:00:41,720: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,734: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,737: Initiating simulation step 49\n", + "2023-10-10 21:00:41,738: Stepping primaite session. Step counter: 50\n", + "2023-10-10 21:00:41,740: Sending simulation state to agent client_1_green_user\n", + "2023-10-10 21:00:41,742: Getting agent action\n", + "2023-10-10 21:00:41,744: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,747: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,750: Sending simulation state to agent client_1_data_manipulation_red_bot\n", + "2023-10-10 21:00:41,753: Getting agent action\n", + "2023-10-10 21:00:41,755: Formatting agent action NODE_FILE_DELETE\n", + "2023-10-10 21:00:41,756: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,758: Sending simulation state to agent defender\n", + "2023-10-10 21:00:41,761: Getting agent action\n", + "2023-10-10 21:00:41,771: Formatting agent action DONOTHING\n", + "2023-10-10 21:00:41,774: Sending request to simulation: ['do_nothing']\n", + "2023-10-10 21:00:41,776: Initiating simulation step 50\n" + ] + } + ], "source": [ "for i in range(50):\n", " sess.step()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/sandbox.py b/sandbox.py new file mode 100644 index 00000000..8114c23a --- /dev/null +++ b/sandbox.py @@ -0,0 +1,19 @@ + +from primaite.game.session import PrimaiteSession + +from primaite import _PRIMAITE_CONFIG, PRIMAITE_PATHS +import logging +_PRIMAITE_CONFIG['log_level']=logging.DEBUG +print(PRIMAITE_PATHS.app_log_dir_path) +import itertools +from primaite.game.session import PrimaiteSession +from primaite.simulator.sim_container import Simulation +from primaite.game.agent.interface import AbstractAgent +from primaite.simulator.network.networks import arcd_uc2_network +import yaml + +with open('example_config.yaml', 'r') as file: + cfg = yaml.safe_load(file) +sess = PrimaiteSession.from_config(cfg) + +sess.start_session() \ No newline at end of file diff --git a/src/primaite/environment/observations.py b/src/primaite/environment/observations.py index be80374b..73b9e998 100644 --- a/src/primaite/environment/observations.py +++ b/src/primaite/environment/observations.py @@ -6,7 +6,7 @@ from logging import Logger from typing import Dict, Final, List, Tuple, TYPE_CHECKING, Union import numpy as np -from gym import spaces +from gymnasium import spaces from primaite.acl.acl_rule import ACLRule from primaite.common.enums import FileSystemState, HardwareState, RulePermissionType, SoftwareState diff --git a/src/primaite/game/agent/GATE_agents.py b/src/primaite/game/agent/GATE_agents.py index ac1d776b..eb3c2987 100644 --- a/src/primaite/game/agent/GATE_agents.py +++ b/src/primaite/game/agent/GATE_agents.py @@ -1,57 +1,9 @@ -from primaite.game.agent.interface import AbstractGATEAgent -from arcd_gate.client.gate_client import GATEClient - - -class GATEMan(GATEClient): - - @property - def rl_framework(self) -> str: - return "SB3" - - @property - def rl_framework(self) -> str: - pass - - @property - def rl_algorithm(self) -> str: - pass - - @property - def seed(self) -> Optional[int]: - return None - - @property - def n_learn_episodes(self) -> int: - return 0 - - @property - def n_learn_steps(self) -> int: - return 0 - - @property - def n_eval_episodes(self) -> int: - return 0 - - @property - def n_eval_steps(self) -> int: - return 0 - - @property - def action_space(self) -> spaces.Space: - pass - - @property - def observation_space(self) -> spaces.Space: - pass - - def step(self, action: ActType) -> Tuple[np.ndarray, float, bool, bool, Dict]: - pass - - def reset(self, *, seed: Optional[int] = None, options: Optional[dict[str, Any]] = None) -> Tuple[np.ndarray, Dict]: - pass - - def close(self): - pass +from typing import Dict, Optional, Tuple +from primaite.game.agent.actions import ActionManager +from primaite.game.agent.interface import AbstractGATEAgent, ObsType +from primaite.game.agent.observations import ObservationSpace +from primaite.game.agent.rewards import RewardFunction +from gymnasium.core import ActType, ObsType class GATERLAgent(AbstractGATEAgent): ... @@ -61,4 +13,9 @@ class GATERLAgent(AbstractGATEAgent): # For example MultiAgentEnv in Ray allows sending a dict of observations of multiple agents, then it will reply # with the actions for those agents. + def __init__(self, agent_name: str | None, action_space: ActionManager | None, observation_space: ObservationSpace | None, reward_function: RewardFunction | None) -> None: + super().__init__(agent_name, action_space, observation_space, reward_function) + self.most_recent_action: ActType + def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: + return self.most_recent_action \ No newline at end of file diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index cba90305..6a1d5bcd 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -2,7 +2,7 @@ import itertools from abc import ABC, abstractmethod from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING -from gym import spaces +from gymnasium import spaces from primaite import getLogger from primaite.simulator.sim_container import Simulation diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 7b10f957..00f98f5c 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -1,10 +1,12 @@ from abc import ABC, abstractmethod from typing import Any, Dict, Hashable, List, Optional, Sequence, Tuple, TYPE_CHECKING -from gym import spaces +from gymnasium import spaces from pydantic import BaseModel from primaite.simulator.sim_container import Simulation +from primaite import getLogger +_LOGGER = getLogger(__name__) if TYPE_CHECKING: from primaite.game.session import PrimaiteSession @@ -181,7 +183,7 @@ class LinkObservation(AbstractObservation): class FolderObservation(AbstractObservation): - def __init__(self, where: Optional[Tuple[str]] = None, files: List[FileObservation] = []) -> None: + def __init__(self, where: Optional[Tuple[str]] = None, files: List[FileObservation] = [], num_files_per_folder:int=2) -> None: """Initialise folder Observation, including files inside of the folder. :param where: Where in the simulation state dictionary to find the relevant information for this folder. @@ -203,6 +205,13 @@ class FolderObservation(AbstractObservation): self.where: Optional[Tuple[str]] = where self.files: List[FileObservation] = files + while len(self.files) < num_files_per_folder: + self.files.append(FileObservation()) + while len(self.files)> num_files_per_folder: + truncated_file = self.files.pop() + msg = f"Too many files in folde observation. Truncating file {truncated_file}" + _LOGGER.warn(msg) + raise UserWarning(msg) self.default_observation = { "health_status": 0, @@ -235,13 +244,13 @@ class FolderObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]]): + def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]], num_files_per_folder:int=2): where = parent_where + ["folders", config["folder_name"]] file_configs = config["files"] files = [FileObservation.from_config(config=f, session=session, parent_where=where) for f in file_configs] - return cls(where=where, files=files) + return cls(where=where, files=files, num_files_per_folder=num_files_per_folder) class NicObservation(AbstractObservation): @@ -277,7 +286,10 @@ class NodeObservation(AbstractObservation): folders: List[FolderObservation] = [], nics: List[NicObservation] = [], logon_status: bool = False, - ) -> None: + num_services_per_node: int = 2, + num_folders_per_node: int = 2, + num_files_per_folder: int = 2 + ) -> None: """ Configurable observation for a node in the simulation. @@ -302,7 +314,24 @@ class NodeObservation(AbstractObservation): self.where: Optional[Tuple[str]] = where self.services: List[ServiceObservation] = services + while len(self.services)num_services_per_node: + truncated_service = self.services.pop() + msg = f"Too many services in Node observation space for node. Truncating service {truncated_service.where}" + _LOGGER.warn(msg) + raise UserWarning(msg) + # truncate service list + self.folders: List[FolderObservation] = folders + while len(self.folders) < num_folders_per_node: + # add an empty folder observation without `where` parameter that will always return default (blank) observations + self.folders.append(FolderObservation()) + while len(self.folders) > num_folders_per_node: + truncated_folder = self.folders.pop() + msg = f"Too many folders in Node observation for node. Truncating service {truncated_folder.where[-1]}" + self.nics: List[NicObservation] = nics self.logon_status: bool = logon_status @@ -349,7 +378,13 @@ class NodeObservation(AbstractObservation): @classmethod def from_config( - cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]] = None + cls, + config: Dict, + session: "PrimaiteSession", + parent_where: Optional[List[str]] = None, + num_services_per_node: int = 2, + num_folders_per_node: int = 2, + num_files_per_folder: int = 2, ) -> "NodeObservation": node_uuid = session.ref_map_nodes[config["node_ref"]] if parent_where is None: @@ -360,12 +395,21 @@ class NodeObservation(AbstractObservation): svc_configs = config.get("services", {}) services = [ServiceObservation.from_config(config=c, session=session, parent_where=where) for c in svc_configs] folder_configs = config.get("folders", {}) - folders = [FolderObservation.from_config(config=c, session=session, parent_where=where) for c in folder_configs] + folders = [FolderObservation.from_config(config=c, session=session, parent_where=where, num_files_per_folder=num_files_per_folder) for c in folder_configs] nic_uuids = session.simulation.network.nodes[node_uuid].nics.keys() nic_configs = [{"nic_uuid": n for n in nic_uuids}] if nic_uuids else [] nics = [NicObservation.from_config(config=c, session=session, parent_where=where) for c in nic_configs] logon_status = config.get("logon_status", False) - return cls(where=where, services=services, folders=folders, nics=nics, logon_status=logon_status) + return cls( + where=where, + services=services, + folders=folders, + nics=nics, + logon_status=logon_status, + num_services_per_node = num_services_per_node, + num_folders_per_node = num_folders_per_node, + num_files_per_folder = num_files_per_folder, + ) class AclObservation(AbstractObservation): @@ -467,11 +511,12 @@ class AclObservation(AbstractObservation): @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession") -> "AclObservation": node_ip_to_idx = {} - for node_idx, node_cfg in enumerate(config["node_order"]): - n_ref = node_cfg["node_ref"] - n_obj = session.simulation.network.nodes[session.ref_map_nodes[n_ref]] - for nic_uuid, nic_obj in n_obj.nics.items(): - node_ip_to_idx[nic_obj.ip_address] = node_idx + 2 + for ip_idx, ip_map_config in enumerate(config["ip_address_order"]): + node_ref = ip_map_config["node_ref"] + nic_num = ip_map_config["nic_num"] + node_obj = session.simulation.network.nodes[session.ref_map_nodes[node_ref]] + nic_obj = node_obj.ethernet_port[nic_num] + node_ip_to_idx[nic_obj.ip_address] = ip_idx + 2 router_uuid = session.ref_map_nodes[config["router_node_ref"]] return cls( @@ -552,7 +597,16 @@ class UC2BlueObservation(AbstractObservation): @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession"): node_configs = config["nodes"] - nodes = [NodeObservation.from_config(config=n, session=session) for n in node_configs] + num_services_per_node = config["num_services_per_node"] + num_folders_per_node = config["num_folders_per_node"] + num_files_per_folder = config["num_files_per_folder"] + nodes = [NodeObservation.from_config( + config=n, + session=session, + num_services_per_node= num_services_per_node, + num_folders_per_node=num_folders_per_node, + num_files_per_folder=num_files_per_folder, + ) for n in node_configs] link_configs = config["links"] links = [LinkObservation.from_config(config=l, session=session) for l in link_configs] diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 7746f78c..d978b848 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -7,12 +7,16 @@ from ipaddress import IPv4Address from typing import Any, Dict, List, Optional, Tuple -from gymnasium.vector.utils import spaces +from gymnasium import spaces +from gymnasium.spaces.utils import flatten, flatten_space, unflatten +from gymnasium.core import ObsType, ActType + import numpy as np from pydantic import BaseModel from primaite import getLogger +from primaite.game.agent.GATE_agents import GATERLAgent from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractAgent, RandomAgent from primaite.game.agent.observations import ( @@ -54,7 +58,7 @@ _LOGGER = getLogger(__name__) class PrimaiteGATEClient(GATEClient): def __init__(self, parent_session:"PrimaiteSession", service_port: int = 50000): super().__init__(service_port=service_port) - self.parent_session:"PrimaiteSession" + self.parent_session:"PrimaiteSession" = parent_session @property def rl_framework(self) -> str: @@ -86,21 +90,33 @@ class PrimaiteGATEClient(GATEClient): @property def action_space(self) -> spaces.Space: - return self.parent_session.rl_agent.action_space + return self.parent_session.rl_agent.action_space.space @property def observation_space(self) -> spaces.Space: - return self.parent_session.rl_agent.observation_space + print("YEEY0") + print(flatten_space(spaces.Dict({}))) + print("YEEY1") + # print(self.parent_session.rl_agent.observation_space.space) + return flatten_space(self.parent_session.rl_agent.observation_space.space) - def step(self, action: ActType) -> Tuple[ndarray, float, bool, bool, Dict]: + def step(self, action: ActType) -> Tuple[ObsType, float, bool, bool, Dict]: + self.parent_session.rl_agent.most_recent_action = action self.parent_session.step() - #TODO: not sure how to go about this. + obs = self.parent_session.rl_agent.observation_space.observe() + obs = flatten(self.parent_session.rl_agent.observation_space.space, obs) + rew = self.parent_session.rl_agent.reward_function.calculate() + term = False + trunc = False + info = {} + return obs, rew, term, trunc, info + def reset(self, *, seed: int | None = None, options: dict[str, Any] | None = None) -> Tuple[ndarray, Dict]: - ... + self.parent_session.reset() def close(self): - ... + self.parent_session.close() class PrimaiteSessionOptions(BaseModel): ports: List[str] @@ -131,15 +147,11 @@ class PrimaiteSession: self.ref_map_nodes: Dict[str, Node] = {} self.ref_map_services: Dict[str, Service] = {} self.ref_map_links: Dict[str, Link] = {} + self.gate_client: PrimaiteGATEClient = PrimaiteGATEClient(self) def start_session(self, opts="TODO..."): """Commence the session, this gives the gate client control over the simulation/agent loop.""" - ... - - def eval(self, opts="TODO..."): - ... - - + self.gate_client.start() def step(self): _LOGGER.debug(f"Stepping primaite session. Step counter: {self.step_counter}") @@ -172,12 +184,18 @@ class PrimaiteSession: # 10. primaite session receives the action from the agents and asks the simulation to apply each _LOGGER.debug(f"Sending request to simulation: {agent_request}") - self.simulation.apply_action(agent_request) + self.simulation.apply_request(agent_request) _LOGGER.debug(f"Initiating simulation step {self.step_counter}") self.simulation.apply_timestep(self.step_counter) self.step_counter += 1 + def reset(self): + pass + + def close(self): + pass + @classmethod def from_config(cls, cfg: dict) -> "PrimaiteSession": sess = cls() @@ -351,6 +369,7 @@ class PrimaiteSession: reward_function=rew_function, ) sess.agents.append(new_agent) + sess.rl_agent = new_agent elif agent_type == "RedDatabaseCorruptingAgent": new_agent = RandomAgent( agent_name=agent_cfg["ref"], diff --git a/src/primaite/transactions/transaction.py b/src/primaite/transactions/transaction.py index 7d5f747c..6b973ca3 100644 --- a/src/primaite/transactions/transaction.py +++ b/src/primaite/transactions/transaction.py @@ -7,7 +7,7 @@ from primaite.common.enums import AgentIdentifier if TYPE_CHECKING: import numpy as np - from gym import spaces + from gymnasium import spaces class Transaction(object): From b84ab84385a20efb50bee35b6145b0104d600fec Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 11 Oct 2023 14:08:55 +0100 Subject: [PATCH 227/980] Fix GATE Client to work successfully with GATE Server --- src/primaite/game/agent/observations.py | 6 +++--- src/primaite/game/session.py | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 00f98f5c..a5a5fc77 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -487,7 +487,7 @@ class AclObservation(AbstractObservation): def space(self) -> spaces.Space: return spaces.Dict( { - "RULE": spaces.Dict( + "RULES": spaces.Dict( { i + 1: spaces.Dict( @@ -532,11 +532,11 @@ class NullObservation(AbstractObservation): self.default_observation: Dict = {} def observe(self, state: Dict) -> Dict: - return {} + return 0 @property def space(self) -> spaces.Space: - return spaces.Dict({}) + return spaces.Discrete(1) @classmethod def from_config(cls, config: Dict, session: Optional["PrimaiteSession"] = None) -> "NullObservation": diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index d978b848..ec6b8e86 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -94,26 +94,27 @@ class PrimaiteGATEClient(GATEClient): @property def observation_space(self) -> spaces.Space: - print("YEEY0") - print(flatten_space(spaces.Dict({}))) - print("YEEY1") - # print(self.parent_session.rl_agent.observation_space.space) return flatten_space(self.parent_session.rl_agent.observation_space.space) def step(self, action: ActType) -> Tuple[ObsType, float, bool, bool, Dict]: self.parent_session.rl_agent.most_recent_action = action self.parent_session.step() - obs = self.parent_session.rl_agent.observation_space.observe() + state = self.parent_session.simulation.describe_state() + obs = self.parent_session.rl_agent.observation_space.observe(state) obs = flatten(self.parent_session.rl_agent.observation_space.space, obs) - rew = self.parent_session.rl_agent.reward_function.calculate() + rew = self.parent_session.rl_agent.reward_function.calculate(state) term = False trunc = False info = {} return obs, rew, term, trunc, info - def reset(self, *, seed: int | None = None, options: dict[str, Any] | None = None) -> Tuple[ndarray, Dict]: + def reset(self, *, seed: int | None = None, options: dict[str, Any] | None = None) -> Tuple[ObsType, Dict]: self.parent_session.reset() + state = self.parent_session.simulation.describe_state() + obs = self.parent_session.rl_agent.observation_space.observe(state) + obs = flatten(self.parent_session.rl_agent.observation_space.space, obs) + return obs, {} def close(self): self.parent_session.close() From 70c1857bbc54414f48e42f065f791a8bec45caae Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 11 Oct 2023 15:49:41 +0100 Subject: [PATCH 228/980] Implement rewards for UC2 (draft) --- example_config.yaml | 13 ++- src/primaite/game/agent/observations.py | 30 +----- src/primaite/game/agent/rewards.py | 123 +++++++++++++++++++++--- src/primaite/game/agent/utils.py | 29 ++++++ 4 files changed, 152 insertions(+), 43 deletions(-) create mode 100644 src/primaite/game/agent/utils.py diff --git a/example_config.yaml b/example_config.yaml index a35c82e0..b700da5c 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -445,7 +445,18 @@ game_config: reward_function: reward_components: - - type: DUMMY + - type: DATABASE_FILE_INTEGRITY + weight: 0.5 + options: + node_ref: database_server + folder_name: database + file_name: database.db + - type: WEB_SERVER_404_PENALTY + weight: 0.5 + options: + node_ref: web_server + service_ref: web_server_database_client + agent_settings: # ... diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index a5a5fc77..ba1e8e66 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -5,41 +5,13 @@ from gymnasium import spaces from pydantic import BaseModel from primaite.simulator.sim_container import Simulation +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE from primaite import getLogger _LOGGER = getLogger(__name__) if TYPE_CHECKING: from primaite.game.session import PrimaiteSession -NOT_PRESENT_IN_STATE = object() -""" -Need an object to return when the sim state does not contain a requested value. Cannot use None because sometimes -the thing requested in the state could equal None. This NOT_PRESENT_IN_STATE is a sentinel for this purpose. -""" - - -def access_from_nested_dict(dictionary: Dict, keys: Sequence[Hashable]) -> Any: - """ - Access an item from a deeply dictionary with a list of keys. - - For example, if the dictionary is {1: 'a', 2: {3: {4: 'b'}}}, then the key [2, 3, 4] would return 'b', and the key - [2, 3] would return {4: 'b'}. Raises a KeyError if specified key does not exist at any level of nesting. - - :param dictionary: Deeply nested dictionary - :type dictionary: Dict - :param keys: List of dict keys used to traverse the nested dict. Each item corresponds to one level of depth. - :type keys: List[Hashable] - :return: The value in the dictionary - :rtype: Any - """ - key_list = [*keys] # copy keys to a new list to prevent editing original list - if len(key_list) == 0: - return dictionary - k = key_list.pop(0) - if k not in dictionary: - return NOT_PRESENT_IN_STATE - return access_from_nested_dict(dictionary[k], key_list) - class AbstractObservation(ABC): @abstractmethod diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 18925edc..b7a4bb24 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -1,34 +1,131 @@ +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE + from abc import ABC, abstractmethod -from typing import Any, Dict, List +from typing import Any, Dict, List, Tuple, TYPE_CHECKING +from primaite import getLogger +_LOGGER = getLogger(__name__) + +if TYPE_CHECKING: + from primaite.game.session import PrimaiteSession class AbstractReward: - def __init__(self): - ... @abstractmethod def calculate(self, state: Dict) -> float: - return 0.3 + return 0.0 + + @abstractmethod + @classmethod + def from_config(cls, config:dict) -> "AbstractReward": + return cls() class DummyReward(AbstractReward): def calculate(self, state: Dict) -> float: - return -0.1 + return 0.0 + + @classmethod + def from_config(cls, config: dict) -> "DummyReward": + return cls() + +class DatabaseFileIntegrity(AbstractReward): + def __init__(self, node_uuid:str, folder_name:str, file_name:str) -> None: + self.location_in_state = ["network", "node", node_uuid, "file_system", ""] + + def calculate(self, state: Dict) -> float: + database_file_state = access_from_nested_dict(state, self.location_in_state) + health_status = database_file_state['health_status'] + if health_status == "corrupted": + return -1 + elif health_status == "good": + return 1 + else: + return 0 + + @classmethod + def from_config(cls, config: Dict, session: "PrimaiteSession") -> "DatabaseFileIntegrity": + node_ref = config.get("node_ref") + folder_name = config.get("folder_name") + file_name = config.get("file_name") + if not (node_ref): + _LOGGER.error(f"{cls.__name__} could not be initialised from config because node_ref parameter was not specified") + return DummyReward() #TODO: better error handling + if not folder_name: + _LOGGER.error(f"{cls.__name__} could not be initialised from config because folder_name parameter was not specified") + return DummyReward() # TODO: better error handling + if not file_name: + _LOGGER.error(f"{cls.__name__} could not be initialised from config because file_name parameter was not specified") + return DummyReward() # TODO: better error handling + node_uuid = session.ref_map_nodes[node_ref].uuid + if not node_uuid: + _LOGGER.error(f"{cls.__name__} could not be initialised from config because the referenced node could not be found in the simulation") + return DummyReward() # TODO: better error handling + + return cls(node_uuid = node_uuid, folder_name=folder_name, file_name=file_name) + +class WebServer404Penalty(AbstractReward): + def __init__(self, node_uuid:str, service_uuid:str) -> None: + self.location_in_state = ['network','node', node_uuid, 'services', service_uuid] + + def calculate(self, state: Dict) -> float: + web_service_state = access_from_nested_dict(state, self.location_in_state) + most_recent_return_code = web_service_state['most_recent_return_code'] + if most_recent_return_code == 200: + return 1 + elif most_recent_return_code == 404: + return -1 + else: + return 0 + + @classmethod + def from_config(cls, config: Dict, session: "PrimaiteSession") -> "WebServer404Penalty": + node_ref = config.get("node_ref") + service_ref = config.get("service_ref") + if not (node_ref and service_ref): + msg = f"{cls.__name__} could not be initialised from config because node_ref and service_ref were not found in reward config." + _LOGGER.warn(msg) + return DummyReward() #TODO: should we error out with incorrect inputs? Probably! + node_uuid = session.ref_map_nodes[node_ref].uuid + service_uuid = session.ref_map_services[service_ref].uuid + if not (node_uuid and service_uuid): + msg = f"{cls.__name__} could not be initialised because node {node_ref} and service {service_ref} were not found in the simulator." + _LOGGER.warn(msg) + return DummyReward() # TODO: consider erroring here as well + + return cls(node_uuid=node_uuid, service_uuid=service_uuid) class RewardFunction: - __rew_class_identifiers: Dict[str, type[AbstractReward]] = {"DUMMY": DummyReward} + __rew_class_identifiers: Dict[str, type[AbstractReward]] = { + "DUMMY": DummyReward, + "DATABASE_FILE_INTEGRITY": DatabaseFileIntegrity, + "WEB_SERVER_404_PENALTY": WebServer404Penalty, + } - def __init__(self, reward_function: AbstractReward): - self.reward: AbstractReward = reward_function + def __init__(self): + self.reward_components: List[Tuple[AbstractReward, float]] = [] + "attribute reward_components keeps track of reward components and the weights assigned to each." + + def regsiter_component(self, component:AbstractReward, weight:float=1.0) -> None: + self.reward_components.append((component, weight)) def calculate(self, state: Dict) -> float: - return self.reward.calculate(state) + total = 0.0 + for comp_and_weight in self.reward_components: + comp = comp_and_weight[0] + weight = comp_and_weight[1] + total += weight * comp.calculate(state=state) + return total @classmethod - def from_config(cls, cfg: Dict) -> "RewardFunction": - for rew_component_cfg in cfg["reward_components"]: + def from_config(cls, config: Dict, session: "PrimaiteSession") -> "RewardFunction": + new = cls() + + for rew_component_cfg in config["reward_components"]: rew_type = rew_component_cfg["type"] - rew_component = cls.__rew_class_identifiers[rew_type]() - new = cls(reward_function=rew_component) + weight = rew_component_cfg["weight"] + rew_class = cls.__rew_class_identifiers[rew_type] + rew_instance = rew_class.from_config(config=rew_component_cfg.get('options',{}), session=session) + new.regsiter_component(component=rew_instance, weight=weight) return new diff --git a/src/primaite/game/agent/utils.py b/src/primaite/game/agent/utils.py new file mode 100644 index 00000000..ad6dbefe --- /dev/null +++ b/src/primaite/game/agent/utils.py @@ -0,0 +1,29 @@ +from typing import Dict, Sequence, Hashable, Any + +NOT_PRESENT_IN_STATE = object() +""" +Need an object to return when the sim state does not contain a requested value. Cannot use None because sometimes +the thing requested in the state could equal None. This NOT_PRESENT_IN_STATE is a sentinel for this purpose. +""" + +def access_from_nested_dict(dictionary: Dict, keys: Sequence[Hashable]) -> Any: + """ + Access an item from a deeply dictionary with a list of keys. + + For example, if the dictionary is {1: 'a', 2: {3: {4: 'b'}}}, then the key [2, 3, 4] would return 'b', and the key + [2, 3] would return {4: 'b'}. Raises a KeyError if specified key does not exist at any level of nesting. + + :param dictionary: Deeply nested dictionary + :type dictionary: Dict + :param keys: List of dict keys used to traverse the nested dict. Each item corresponds to one level of depth. + :type keys: List[Hashable] + :return: The value in the dictionary + :rtype: Any + """ + key_list = [*keys] # copy keys to a new list to prevent editing original list + if len(key_list) == 0: + return dictionary + k = key_list.pop(0) + if k not in dictionary: + return NOT_PRESENT_IN_STATE + return access_from_nested_dict(dictionary[k], key_list) \ No newline at end of file From 565af11dba80efbaa98897425f87678a0591b193 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 12 Oct 2023 09:59:45 +0100 Subject: [PATCH 229/980] Minor fixes to rewards --- src/primaite/game/agent/rewards.py | 16 ++++++++-------- src/primaite/game/session.py | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index b7a4bb24..85da95da 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -15,9 +15,9 @@ class AbstractReward: def calculate(self, state: Dict) -> float: return 0.0 - @abstractmethod @classmethod - def from_config(cls, config:dict) -> "AbstractReward": + @abstractmethod + def from_config(cls, config:dict, session:"PrimaiteSession") -> "AbstractReward": return cls() @@ -26,12 +26,12 @@ class DummyReward(AbstractReward): return 0.0 @classmethod - def from_config(cls, config: dict) -> "DummyReward": + def from_config(cls, config: dict, session:"PrimaiteSession") -> "DummyReward": return cls() class DatabaseFileIntegrity(AbstractReward): def __init__(self, node_uuid:str, folder_name:str, file_name:str) -> None: - self.location_in_state = ["network", "node", node_uuid, "file_system", ""] + self.location_in_state = ["network", "nodes", node_uuid, "file_system", "folders",folder_name, "files", file_name] def calculate(self, state: Dict) -> float: database_file_state = access_from_nested_dict(state, self.location_in_state) @@ -57,7 +57,7 @@ class DatabaseFileIntegrity(AbstractReward): if not file_name: _LOGGER.error(f"{cls.__name__} could not be initialised from config because file_name parameter was not specified") return DummyReward() # TODO: better error handling - node_uuid = session.ref_map_nodes[node_ref].uuid + node_uuid = session.ref_map_nodes[node_ref] if not node_uuid: _LOGGER.error(f"{cls.__name__} could not be initialised from config because the referenced node could not be found in the simulation") return DummyReward() # TODO: better error handling @@ -66,7 +66,7 @@ class DatabaseFileIntegrity(AbstractReward): class WebServer404Penalty(AbstractReward): def __init__(self, node_uuid:str, service_uuid:str) -> None: - self.location_in_state = ['network','node', node_uuid, 'services', service_uuid] + self.location_in_state = ['network','nodes', node_uuid, 'services', service_uuid] def calculate(self, state: Dict) -> float: web_service_state = access_from_nested_dict(state, self.location_in_state) @@ -86,7 +86,7 @@ class WebServer404Penalty(AbstractReward): msg = f"{cls.__name__} could not be initialised from config because node_ref and service_ref were not found in reward config." _LOGGER.warn(msg) return DummyReward() #TODO: should we error out with incorrect inputs? Probably! - node_uuid = session.ref_map_nodes[node_ref].uuid + node_uuid = session.ref_map_nodes[node_ref] service_uuid = session.ref_map_services[service_ref].uuid if not (node_uuid and service_uuid): msg = f"{cls.__name__} could not be initialised because node {node_ref} and service {service_ref} were not found in the simulator." @@ -124,7 +124,7 @@ class RewardFunction: for rew_component_cfg in config["reward_components"]: rew_type = rew_component_cfg["type"] - weight = rew_component_cfg["weight"] + weight = rew_component_cfg.get("weight",1.0) rew_class = cls.__rew_class_identifiers[rew_type] rew_instance = rew_class.from_config(config=rew_component_cfg.get('options',{}), session=session) new.regsiter_component(component=rew_instance, weight=weight) diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index ec6b8e86..406308b9 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -295,7 +295,7 @@ class PrimaiteSession: net.add_node(new_node) new_node.power_on() - sess.ref_map_nodes[node_ref] = new_node.uuid + sess.ref_map_nodes[node_ref] = new_node.uuid # TODO: fix incosistency with service and link. Node gets added by uuid, but service gets reference to object # 2. create links between nodes for link_cfg in links_cfg: @@ -350,7 +350,7 @@ class PrimaiteSession: action_space = ActionManager.from_config(sess, action_space_cfg) # CREATE REWARD FUNCTION - rew_function = RewardFunction.from_config(reward_function_cfg) + rew_function = RewardFunction.from_config(reward_function_cfg, session=sess) # CREATE AGENT if agent_type == "GreenWebBrowsingAgent": From c9e4ba3c7d95c7a8b4208f13e56bb93b7ba9b0c9 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Thu, 12 Oct 2023 11:16:25 +0100 Subject: [PATCH 230/980] #1947: File and Folder hash checks --- .../simulator/file_system/file_system.py | 75 ++++++++++++++++++- .../_file_system/test_file_system.py | 54 +++++++++++++ 2 files changed, 128 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 5653234d..5a089c9b 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -1,5 +1,7 @@ from __future__ import annotations +import hashlib +import json import math import os.path import shutil @@ -73,6 +75,9 @@ class FileSystemItemABC(SimComponent): visible_status: FileSystemItemStatus = FileSystemItemStatus.GOOD "Visible status of the current FileSystemItem" + previous_hash: Optional[str] = None + "Hash of the file contents or the description state" + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -102,7 +107,7 @@ class FileSystemItemABC(SimComponent): def _init_request_manager(self) -> RequestManager: am = super()._init_request_manager() am.add_request("scan", RequestType(func=lambda request, context: self.scan())) # TODO implement request - am.add_request("checkhash", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("checkhash", RequestType(func=lambda request, context: self.checkhash())) am.add_request("delete", RequestType(func=lambda request, context: ...)) # TODO implement request am.add_request("restore", RequestType(func=lambda request, context: ...)) # TODO implement request am.add_request("repair", RequestType(func=lambda request, context: self.repair())) @@ -115,6 +120,17 @@ class FileSystemItemABC(SimComponent): self.visible_status = self.status + @abstractmethod + def check_hash(self) -> bool: + """ + Checks the has of the file to detect any changes. + + For current implementation, any change in file hash means it is compromised. + + Return False if corruption is detected, otherwise True + """ + pass + @abstractmethod def repair(self) -> None: """Repair the FileSystemItem.""" @@ -517,6 +533,30 @@ class Folder(FileSystemItemABC): self.fs.sys_log.info(f"Corrupted folder {self.name}") + def check_hash(self) -> bool: + """ + Runs a :func:`check_hash` on all files in the folder. + + If a file under the folder is corrupted, the whole folder is considered corrupted. + + TODO: For now this will just iterate through the files and run :func:`check_hash` and ignores + any other changes to the folder + + Return False if corruption is detected, otherwise True + """ + # iterate through the files and run a check hash + no_corrupted_files = True + + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + no_corrupted_files = file.check_hash() + + # if one file in the folder is corrupted, set the folder status to corrupted + if not no_corrupted_files: + self.corrupt() + + return no_corrupted_files + class File(FileSystemItemABC): """ @@ -629,3 +669,36 @@ class File(FileSystemItemABC): path = self.folder.name + "/" + self.name self.folder.fs.sys_log.info(f"Corrupted file {self.sim_path if self.sim_path else path}") + + def check_hash(self) -> bool: + """ + Check if the file has been changed. + + If changed, the file is considered corrupted. + + Return False if corruption is detected, otherwise True + """ + current_hash = None + + # if file is real, read the file contents + if self.real: + with open(self.sim_path, "rb") as f: + file_hash = hashlib.blake2b() + while chunk := f.read(8192): + file_hash.update(chunk) + + current_hash = file_hash.hexdigest() + else: + # otherwise get describe_state dict and hash that + current_hash = hashlib.blake2b(json.dumps(self.describe_state(), sort_keys=True).encode()).hexdigest() + + # if the previous hash is None, set the current hash to previous + if self.previous_hash is None: + self.previous_hash = current_hash + + # if the previous hash and current hash do not match, mark file as corrupted + if self.previous_hash is not current_hash: + self.corrupt() + return False + + return True diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 539f2874..5bb4ceda 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -169,6 +169,60 @@ def test_folder_corrupt_repair(file_system): assert file.status == FileSystemItemStatus.GOOD +def test_simulated_file_check_hash(file_system): + file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + assert file.check_hash() is True + + # change simulated file size + file.sim_size = 0 + assert file.check_hash() is False + assert file.status == FileSystemItemStatus.CORRUPTED + + +def test_real_file_check_hash(file_system): + file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder", real=True) + + assert file.check_hash() is True + + # change file content + with open(file.sim_path, "a") as f: + f.write("get hacked scrub lol xD\n") + + assert file.check_hash() is False + assert file.status == FileSystemItemStatus.CORRUPTED + + +def test_simulated_folder_check_hash(file_system): + folder: Folder = file_system.create_folder(folder_name="test_folder") + file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + assert folder.check_hash() is True + + # change simulated file size + file = folder.get_file(file_name="test_file.txt") + file.sim_size = 0 + assert folder.check_hash() is False + assert folder.status == FileSystemItemStatus.CORRUPTED + + +def test_real_folder_check_hash(file_system): + folder: Folder = file_system.create_folder(folder_name="test_folder") + file_system.create_file(file_name="test_file.txt", folder_name="test_folder", real=True) + + assert folder.check_hash() is True + + # change simulated file size + file = folder.get_file(file_name="test_file.txt") + + # change file content + with open(file.sim_path, "a") as f: + f.write("get hacked scrub lol xD\n") + + assert folder.check_hash() is False + assert folder.status == FileSystemItemStatus.CORRUPTED + + @pytest.mark.skip(reason="Skipping until we tackle serialisation") def test_serialisation(file_system): """Test to check that the object serialisation works correctly.""" From 9b5d95cbb9b0ee142a5874ed97fb3e4fcbad839a Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Fri, 13 Oct 2023 10:41:27 +0100 Subject: [PATCH 231/980] #1947: refactor am->rm to align with refactor of ActionManager->RequestManager --- src/primaite/simulator/core.py | 6 ++-- src/primaite/simulator/domain/controller.py | 6 ++-- .../simulator/file_system/file_system.py | 24 ++++++------- src/primaite/simulator/network/container.py | 6 ++-- .../simulator/network/hardware/base.py | 34 +++++++++---------- .../network/hardware/nodes/router.py | 14 ++++---- src/primaite/simulator/sim_container.py | 8 ++--- .../simulator/system/services/service.py | 20 +++++------ src/primaite/simulator/system/software.py | 8 ++--- 9 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index cb3e7390..fb6db3ac 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -173,9 +173,9 @@ class SimComponent(BaseModel): class WebBrowser(Application): def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() # all requests generic to any Application get initialised - am.add_request(...) # initialise any requests specific to the web browser - return am + rm = super()._init_request_manager() # all requests generic to any Application get initialised + rm.add_request(...) # initialise any requests specific to the web browser + return rm :return: Request manager object belonging to this sim component. :rtype: RequestManager diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index 66900327..e9f3b26d 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -80,17 +80,17 @@ class DomainController(SimComponent): super().__init__(**kwargs) def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() + rm = super()._init_request_manager() # Action 'account' matches requests like: # ['account', '', *account_action] - am.add_request( + rm.add_request( "account", RequestType( func=lambda request, context: self.accounts[request.pop(0)].apply_request(request, context), validator=GroupMembershipValidator(allowed_groups=[AccountGroup.DOMAIN_ADMIN]), ), ) - return am + return rm def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 5a089c9b..a821ae40 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -105,14 +105,14 @@ class FileSystemItemABC(SimComponent): return convert_size(self.size) def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() - am.add_request("scan", RequestType(func=lambda request, context: self.scan())) # TODO implement request - am.add_request("checkhash", RequestType(func=lambda request, context: self.checkhash())) - am.add_request("delete", RequestType(func=lambda request, context: ...)) # TODO implement request - am.add_request("restore", RequestType(func=lambda request, context: ...)) # TODO implement request - am.add_request("repair", RequestType(func=lambda request, context: self.repair())) - am.add_request("corrupt", RequestType(func=lambda request, context: self.corrupt())) - return am + rm = super()._init_request_manager() + rm.add_request("scan", RequestType(func=lambda request, context: self.scan())) + rm.add_request("checkhash", RequestType(func=lambda request, context: self.checkhash())) + rm.add_request("delete", RequestType(func=lambda request, context: self.delete())) + rm.add_request("restore", RequestType(func=lambda request, context: self.restore())) + rm.add_request("repair", RequestType(func=lambda request, context: self.repair())) + rm.add_request("corrupt", RequestType(func=lambda request, context: self.corrupt())) + return rm def scan(self) -> None: """Update the FileSystemItem states.""" @@ -158,15 +158,15 @@ class FileSystem(SimComponent): self.create_folder("root") def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() + rm = super()._init_request_manager() self._folder_request_manager = RequestManager() - am.add_request("folder", RequestType(func=self._folder_request_manager)) + rm.add_request("folder", RequestType(func=self._folder_request_manager)) self._file_request_manager = RequestManager() - am.add_request("file", RequestType(func=self._file_request_manager)) + rm.add_request("file", RequestType(func=self._file_request_manager)) - return am + return rm @property def size(self) -> int: diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index bc717641..3516ef96 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -44,13 +44,13 @@ class Network(SimComponent): self._nx_graph = MultiGraph() def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() + rm = super()._init_request_manager() self._node_request_manager = RequestManager() - am.add_request( + rm.add_request( "node", RequestType(func=self._node_request_manager), ) - return am + return rm @property def routers(self) -> List[Router]: diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 5f2699e8..23ad7904 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -145,12 +145,12 @@ class NIC(SimComponent): return state def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() + rm = super()._init_request_manager() - am.add_request("enable", RequestType(func=lambda request, context: self.enable())) - am.add_request("disable", RequestType(func=lambda request, context: self.disable())) + rm.add_request("enable", RequestType(func=lambda request, context: self.enable())) + rm.add_request("disable", RequestType(func=lambda request, context: self.disable())) - return am + return rm @property def ip_network(self) -> IPv4Network: @@ -951,30 +951,30 @@ class Node(SimComponent): def _init_request_manager(self) -> RequestManager: # TODO: I see that this code is really confusing and hard to read right now... I think some of these things will # need a better name and better documentation. - am = super()._init_request_manager() + rm = super()._init_request_manager() # since there are potentially many services, create an request manager that can map service name self._service_request_manager = RequestManager() - am.add_request("service", RequestType(func=self._service_request_manager)) + rm.add_request("service", RequestType(func=self._service_request_manager)) self._nic_request_manager = RequestManager() - am.add_request("nic", RequestType(func=self._nic_request_manager)) + rm.add_request("nic", RequestType(func=self._nic_request_manager)) - am.add_request("file_system", RequestType(func=self.file_system._request_manager)) + rm.add_request("file_system", RequestType(func=self.file_system._request_manager)) # currently we don't have any applications nor processes, so these will be empty self._process_request_manager = RequestManager() - am.add_request("process", RequestType(func=self._process_request_manager)) + rm.add_request("process", RequestType(func=self._process_request_manager)) self._application_request_manager = RequestManager() - am.add_request("application", RequestType(func=self._application_request_manager)) + rm.add_request("application", RequestType(func=self._application_request_manager)) - am.add_request("scan", RequestType(func=lambda request, context: ...)) # TODO implement OS scan + rm.add_request("scan", RequestType(func=lambda request, context: ...)) # TODO implement OS scan - am.add_request("shutdown", RequestType(func=lambda request, context: self.power_off())) - am.add_request("startup", RequestType(func=lambda request, context: self.power_on())) - am.add_request("reset", RequestType(func=lambda request, context: ...)) # TODO implement node reset - am.add_request("logon", RequestType(func=lambda request, context: ...)) # TODO implement logon request - am.add_request("logoff", RequestType(func=lambda request, context: ...)) # TODO implement logoff request + rm.add_request("shutdown", RequestType(func=lambda request, context: self.power_off())) + rm.add_request("startup", RequestType(func=lambda request, context: self.power_on())) + rm.add_request("reset", RequestType(func=lambda request, context: ...)) # TODO implement node reset + rm.add_request("logon", RequestType(func=lambda request, context: ...)) # TODO implement logon request + rm.add_request("logoff", RequestType(func=lambda request, context: ...)) # TODO implement logoff request - return am + return rm def _install_system_software(self): """Install System Software - software that is usually provided with the OS.""" diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index c56bf538..cf7e838f 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -88,7 +88,7 @@ class AccessControlList(SimComponent): self._acl = [None] * (self.max_acl_rules - 1) def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() + rm = super()._init_request_manager() # When the request reaches this action, it should now contain solely positional args for the 'add_rule' action. # POSITIONAL ARGUMENTS: @@ -99,7 +99,7 @@ class AccessControlList(SimComponent): # 4: destination ip address (str castable to IPV4Address (e.g. '10.10.1.2')) # 5: destination port (str name of a Port (e.g. "HTTP")) # 6: position (int) - am.add_request( + rm.add_request( "add_rule", RequestType( func=lambda request, context: self.add_rule( @@ -114,8 +114,8 @@ class AccessControlList(SimComponent): ), ) - am.add_request("remove_rule", RequestType(func=lambda request, context: self.remove_rule(int(request[0])))) - return am + rm.add_request("remove_rule", RequestType(func=lambda request, context: self.remove_rule(int(request[0])))) + return rm def describe_state(self) -> Dict: """ @@ -627,9 +627,9 @@ class Router(Node): self.icmp.arp = self.arp def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() - am.add_request("acl", RequestType(func=self.acl._request_manager)) - return am + rm = super()._init_request_manager() + rm.add_request("acl", RequestType(func=self.acl._request_manager)) + return rm def _get_port_of_nic(self, target_nic: NIC) -> Optional[int]: """ diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index 2e88f3b4..b08a5b6a 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -22,12 +22,12 @@ class Simulation(SimComponent): super().__init__(**kwargs) def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() + rm = super()._init_request_manager() # pass through network requests to the network objects - am.add_request("network", RequestType(func=self.network._request_manager)) + rm.add_request("network", RequestType(func=self.network._request_manager)) # pass through domain requests to the domain object - am.add_request("domain", RequestType(func=self.domain._request_manager)) - return am + rm.add_request("domain", RequestType(func=self.domain._request_manager)) + return rm def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index ca09ae60..82eab7d9 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -44,16 +44,16 @@ class Service(IOSoftware): "If currently restarting, how many timesteps remain until the restart is finished." def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() - am.add_request("scan", RequestType(func=lambda request, context: self.scan())) - am.add_request("stop", RequestType(func=lambda request, context: self.stop())) - am.add_request("start", RequestType(func=lambda request, context: self.start())) - am.add_request("pause", RequestType(func=lambda request, context: self.pause())) - am.add_request("resume", RequestType(func=lambda request, context: self.resume())) - am.add_request("restart", RequestType(func=lambda request, context: self.restart())) - am.add_request("disable", RequestType(func=lambda request, context: self.disable())) - am.add_request("enable", RequestType(func=lambda request, context: self.enable())) - return am + rm = super()._init_request_manager() + rm.add_request("scan", RequestType(func=lambda request, context: self.scan())) + rm.add_request("stop", RequestType(func=lambda request, context: self.stop())) + rm.add_request("start", RequestType(func=lambda request, context: self.start())) + rm.add_request("pause", RequestType(func=lambda request, context: self.pause())) + rm.add_request("resume", RequestType(func=lambda request, context: self.resume())) + rm.add_request("restart", RequestType(func=lambda request, context: self.restart())) + rm.add_request("disable", RequestType(func=lambda request, context: self.disable())) + rm.add_request("enable", RequestType(func=lambda request, context: self.enable())) + return rm def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 1fafd137..e692582e 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -88,15 +88,15 @@ class Software(SimComponent): "The folder on the file system the Software uses." def _init_request_manager(self) -> RequestManager: - am = super()._init_request_manager() - am.add_request( + rm = super()._init_request_manager() + rm.add_request( "compromise", RequestType( func=lambda request, context: self.set_health_state(SoftwareHealthState.COMPROMISED), ), ) - am.add_request("scan", RequestType(func=lambda request, context: self.scan())) - return am + rm.add_request("scan", RequestType(func=lambda request, context: self.scan())) + return rm def _get_session_details(self, session_id: str) -> Session: """ From 4ee2235dd121ae0a5656e44212e489ec861d6494 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Mon, 16 Oct 2023 11:42:56 +0100 Subject: [PATCH 232/980] #1947: temp commit what is done so far --- .../simulator/file_system/file_system.py | 369 ++++++++++++++---- .../system/test_database_on_node.py | 1 + .../_file_system/test_file_system.py | 71 ++++ 3 files changed, 368 insertions(+), 73 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index a821ae40..24abbf18 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -58,6 +58,9 @@ class FileSystemItemStatus(Enum): CORRUPTED = 2 """File/Folder is corrupted.""" + DELETED = 3 + """File/Folder is deleted.""" + class FileSystemItemABC(SimComponent): """ @@ -85,11 +88,10 @@ class FileSystemItemABC(SimComponent): :return: Current state of this object and child objects. """ state = super().describe_state() - state.update( - { - "name": self.name, - } - ) + state["name"] = self.name + state["status"] = self.status.name + state["visible_status"] = self.visible_status.name + state["previous_hash"] = self.previous_hash return state @property @@ -104,16 +106,6 @@ class FileSystemItemABC(SimComponent): """ return convert_size(self.size) - def _init_request_manager(self) -> RequestManager: - rm = super()._init_request_manager() - rm.add_request("scan", RequestType(func=lambda request, context: self.scan())) - rm.add_request("checkhash", RequestType(func=lambda request, context: self.checkhash())) - rm.add_request("delete", RequestType(func=lambda request, context: self.delete())) - rm.add_request("restore", RequestType(func=lambda request, context: self.restore())) - rm.add_request("repair", RequestType(func=lambda request, context: self.repair())) - rm.add_request("corrupt", RequestType(func=lambda request, context: self.corrupt())) - return rm - def scan(self) -> None: """Update the FileSystemItem states.""" super().scan() @@ -129,16 +121,42 @@ class FileSystemItemABC(SimComponent): Return False if corruption is detected, otherwise True """ - pass + # cannot check hash if deleted + if self.status == FileSystemItemStatus.DELETED: + return False @abstractmethod - def repair(self) -> None: - """Repair the FileSystemItem.""" - pass + def repair(self) -> bool: + """ + Repair the FileSystemItem. + + True if successfully repaired. False otherwise. + """ + # cannot repair if deleted + if self.status == FileSystemItemStatus.DELETED: + return False @abstractmethod - def corrupt(self) -> None: - """Corrupt the FileSystemItem.""" + def corrupt(self) -> bool: + """ + Corrupt the FileSystemItem. + + True if successfully corrupted. False otherwise. + """ + # cannot corrupt if deleted + if self.status == FileSystemItemStatus.DELETED: + return False + + def delete(self) -> None: + """ + Delete the FileSystemItem. + + True if successfully deleted. False otherwise. + """ + self.status = FileSystemItemStatus.DELETED + + def restore(self) -> None: + """Restore the file/folder to the state before it got ruined.""" pass @@ -151,6 +169,8 @@ class FileSystem(SimComponent): sys_log: SysLog sim_root: Path + deleted_folders: Dict[str, Folder] = {} + def __init__(self, **kwargs): super().__init__(**kwargs) # Ensure a default root folder @@ -160,14 +180,110 @@ class FileSystem(SimComponent): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() - self._folder_request_manager = RequestManager() + self._folder_request_manager = self._init_folder_request_manager() rm.add_request("folder", RequestType(func=self._folder_request_manager)) - self._file_request_manager = RequestManager() + self._file_request_manager = self._init_file_request_manager() rm.add_request("file", RequestType(func=self._file_request_manager)) return rm + def _init_folder_request_manager(self) -> RequestManager: + rm = RequestManager() + + rm.add_request( + "scan", + RequestType( + func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0], show_deleted=True).scan() + ), + ) + + rm.add_request( + "checkhash", + RequestType(func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]).check_hash()), + ) + + rm.add_request( + "repair", RequestType(func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]).repair()) + ) + + rm.add_request( + "corrupt", + RequestType(func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]).corrupt()), + ) + + rm.add_request( + "delete", RequestType(func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]).delete()) + ) + + rm.add_request( + "restore", + RequestType( + func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0], show_deleted=True).restore() + ), + ) + + return rm + + def _init_file_request_manager(self) -> RequestManager: + rm = RequestManager() + + rm.add_request( + "scan", + RequestType( + func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0], show_deleted=True) + .get_file_by_id(file_uuid=request[1], show_deleted=True) + .scan() + ), + ) + + rm.add_request( + "checkhash", + RequestType( + func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]) + .get_file_by_id(file_uuid=request[1]) + .check_hash() + ), + ) + + rm.add_request( + "repair", + RequestType( + func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]) + .get_file_by_id(file_uuid=request[1]) + .repair() + ), + ) + + rm.add_request( + "corrupt", + RequestType( + func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]) + .get_file_by_id(file_uuid=request[1]) + .corrupt() + ), + ) + + rm.add_request( + "delete", + RequestType( + func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]) + .get_file_by_id(file_uuid=request[1]) + .delete() + ), + ) + + rm.add_request( + "restore", + RequestType( + func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0], show_deleted=True) + .get_file_by_id(file_uuid=request[1], show_deleted=True) + .restore() + ), + ) + + return rm + @property def size(self) -> int: """ @@ -243,7 +359,12 @@ class FileSystem(SimComponent): folder = self._folders_by_name.get(folder_name) if folder: for file in folder.files.values(): - self.delete_file(file) + self.delete_file(folder_name=folder_name, file_name=file.name) + # add to deleted list + folder.delete() + self.deleted_folders[folder.uuid] = folder + + # remove from normal list self.folders.pop(folder.uuid) self._folders_by_name.pop(folder.name) self.sys_log.info(f"Deleted folder /{folder.name} and its contents") @@ -251,6 +372,10 @@ class FileSystem(SimComponent): else: _LOGGER.debug(f"Cannot delete folder as it does not exist: {folder_name}") + def restore_folder(self, folder_id: str): + """TODO.""" + pass + def create_file( self, file_name: str, @@ -364,6 +489,24 @@ class FileSystem(SimComponent): new_file.sim_path.parent.mkdir(exist_ok=True) shutil.copy2(file.sim_path, new_file.sim_path) + def restore_file(self, folder_id: str, file_id: str) -> bool: + """ + Restore a file. + + Checks the current file's status and applies the correct fix for the file. + + :param: folder_id: id of the folder where the file is stored + :type: folder_id: str + + :param: folder_id: id of the file to restore + :type: folder_id: str + """ + folder = self.get_folder_by_id(folder_uuid=folder_id, show_deleted=True) + + if folder: + file = folder.get_file_by_id(file_uuid=file_id, show_deleted=True) + return file.restore() + def get_folder(self, folder_name: str) -> Optional[Folder]: """ Get a folder by its name if it exists. @@ -373,13 +516,19 @@ class FileSystem(SimComponent): """ return self._folders_by_name.get(folder_name) - def get_folder_by_id(self, folder_uuid: str) -> Optional[Folder]: + def get_folder_by_id(self, folder_uuid: str, show_deleted: bool = False) -> Optional[Folder]: """ Get a folder by its uuid if it exists. - :param folder_uuid: The folder uuid. + :param: folder_uuid: The folder uuid. + :param: show_deleted: show deleted folders :return: The matching Folder. """ + deleted_folder = self.deleted_folders.get(folder_uuid) + + if show_deleted and deleted_folder: + return deleted_folder + return self.folders.get(folder_uuid) @@ -393,6 +542,8 @@ class Folder(FileSystemItemABC): _files_by_name: Dict[str, File] = {} "Files by their name as .." + deleted_files: Dict[str, File] = {} + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -401,7 +552,6 @@ class Folder(FileSystemItemABC): """ state = super().describe_state() state["files"] = {file.name: file.describe_state() for uuid, file in self.files.items()} - state["is_quarantined"] = self.is_quarantined return state def show(self, markdown: bool = False): @@ -441,13 +591,19 @@ class Folder(FileSystemItemABC): # TODO: Increment read count? return self._files_by_name.get(file_name) - def get_file_by_id(self, file_uuid: str) -> File: + def get_file_by_id(self, file_uuid: str, show_deleted: bool = False) -> File: """ Get a file by its uuid. - :param file_uuid: The file uuid. + :param: file_uuid: The file uuid. + :param: show_deleted: show deleted files :return: The matching File. """ + deleted_file = self.deleted_files.get(file_uuid) + + if show_deleted and deleted_file: + return deleted_file + return self.files.get(file_uuid) def add_file(self, file: File): @@ -482,6 +638,11 @@ class Folder(FileSystemItemABC): raise Exception(f"Invalid file: {file}") if self.files.get(file.uuid): + # add to deleted list + file.delete() + self.deleted_files[file.uuid] = file + + # remove from normal file list self.files.pop(file.uuid) self._files_by_name.pop(file.name) else: @@ -503,35 +664,16 @@ class Folder(FileSystemItemABC): """Returns true if the folder is being quarantined.""" return self.status == FileSystemItemStatus.QUARANTINED - def repair(self) -> None: - """Repair a corrupted Folder by setting the folder and containing files status to FileSystemItemStatus.GOOD.""" - super().repair() + def scan(self) -> None: + """Update Folder visible status.""" + super().scan() - # iterate through the files in the folder + # update the status of files in folder for file_id in self.files: file = self.get_file_by_id(file_uuid=file_id) - file.repair() + file.scan() - # set file status to good if corrupt - if self.status == FileSystemItemStatus.CORRUPTED: - self.status = FileSystemItemStatus.GOOD - - self.fs.sys_log.info(f"Repaired folder {self.name}") - - def corrupt(self) -> None: - """Corrupt a File by setting the folder and containing files status to FileSystemItemStatus.CORRUPTED.""" - super().corrupt() - - # iterate through the files in the folder - for file_id in self.files: - file = self.get_file_by_id(file_uuid=file_id) - file.corrupt() - - # set file status to good if corrupt - if self.status == FileSystemItemStatus.GOOD: - self.status = FileSystemItemStatus.CORRUPTED - - self.fs.sys_log.info(f"Corrupted folder {self.name}") + self.fs.sys_log.info(f"Scanning folder {self.name} (id: {self.uuid})") def check_hash(self) -> bool: """ @@ -544,6 +686,8 @@ class Folder(FileSystemItemABC): Return False if corruption is detected, otherwise True """ + super().check_hash() + # iterate through the files and run a check hash no_corrupted_files = True @@ -555,8 +699,57 @@ class Folder(FileSystemItemABC): if not no_corrupted_files: self.corrupt() + self.fs.sys_log.info(f"Checking hash of folder {self.name} (id: {self.uuid})") + return no_corrupted_files + def repair(self) -> bool: + """Repair a corrupted Folder by setting the folder and containing files status to FileSystemItemStatus.GOOD.""" + super().repair() + + repaired = False + + # iterate through the files in the folder + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + repaired = file.repair() + + # set file status to good if corrupt + if self.status == FileSystemItemStatus.CORRUPTED: + self.status = FileSystemItemStatus.GOOD + repaired = True + + self.fs.sys_log.info(f"Repaired folder {self.name} (id: {self.uuid})") + return repaired + + def restore(self) -> None: + """TODO.""" + pass + + def delete(self) -> bool: + """TODO.""" + super().delete() + self.fs.sys_log.info(f"Deleted folder {self.name} (id: {self.uuid})") + + def corrupt(self) -> bool: + """Corrupt a File by setting the folder and containing files status to FileSystemItemStatus.CORRUPTED.""" + super().corrupt() + + corrupted = False + + # iterate through the files in the folder + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + corrupted = file.corrupt() + + # set file status to good if corrupt + if self.status == FileSystemItemStatus.GOOD: + self.status = FileSystemItemStatus.CORRUPTED + corrupted = True + + self.fs.sys_log.info(f"Corrupted folder {self.name} (id: {self.uuid})") + return corrupted + class File(FileSystemItemABC): """ @@ -648,27 +841,12 @@ class File(FileSystemItemABC): state["file_type"] = self.file_type.name return state - def repair(self) -> None: - """Repair a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" - super().repair() - - # set file status to good if corrupt - if self.status == FileSystemItemStatus.CORRUPTED: - self.status = FileSystemItemStatus.GOOD + def scan(self) -> None: + """TODO.""" + super().scan() path = self.folder.name + "/" + self.name - self.folder.fs.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") - - def corrupt(self) -> None: - """Corrupt a File by setting the status to FileSystemItemStatus.CORRUPTED.""" - super().corrupt() - - # set file status to good if corrupt - if self.status == FileSystemItemStatus.GOOD: - self.status = FileSystemItemStatus.CORRUPTED - - path = self.folder.name + "/" + self.name - self.folder.fs.sys_log.info(f"Corrupted file {self.sim_path if self.sim_path else path}") + self.folder.fs.sys_log.info(f"Scanning file {self.sim_path if self.sim_path else path}") def check_hash(self) -> bool: """ @@ -702,3 +880,48 @@ class File(FileSystemItemABC): return False return True + + def delete(self) -> None: + """TODO.""" + super().delete() + + path = self.folder.name + "/" + self.name + self.folder.fs.sys_log.info(f"Deleting file {self.sim_path if self.sim_path else path}") + + def repair(self) -> bool: + """Repair a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" + super().repair() + + # set file status to good if corrupt + if self.status == FileSystemItemStatus.CORRUPTED: + self.status = FileSystemItemStatus.GOOD + + path = self.folder.name + "/" + self.name + self.folder.fs.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") + return True + + def restore(self) -> None: + """Restore a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" + super().restore() + + # set file status to good if deleted or corrupt + if self.status in [FileSystemItemStatus.CORRUPTED, FileSystemItemStatus.DELETED]: + self.status = FileSystemItemStatus.GOOD + + path = self.folder.name + "/" + self.name + self.folder.fs.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") + + def corrupt(self) -> bool: + """Corrupt a File by setting the status to FileSystemItemStatus.CORRUPTED.""" + super().corrupt() + + corrupted = False + + # set file status to good if corrupt + if self.status == FileSystemItemStatus.GOOD: + self.status = FileSystemItemStatus.CORRUPTED + corrupted = True + + path = self.folder.name + "/" + self.name + self.folder.fs.sys_log.info(f"Corrupted file {self.sim_path if self.sim_path else path}") + return corrupted diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 92056981..14b579b2 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -1,5 +1,6 @@ from ipaddress import IPv4Address +from primaite.simulator.file_system.file_system import FileSystemItemStatus from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database.database_service import DatabaseService diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 5bb4ceda..4c5d5510 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -44,6 +44,7 @@ def test_delete_file(file_system): file_system.delete_file(folder_name="root", file_name="test_file.txt") assert len(file_system.folders) == 1 assert len(file_system.get_folder("root").files) == 0 + assert len(file_system.get_folder("root").deleted_files) == 1 def test_delete_non_existent_file(file_system): @@ -69,6 +70,7 @@ def test_delete_folder(file_system): file_system.delete_folder(folder_name="test_folder") assert len(file_system.folders) == 1 + assert len(file_system.deleted_folders) == 1 def test_deleting_a_non_existent_folder(file_system): @@ -95,11 +97,13 @@ def test_move_file(file_system): original_uuid = file.uuid assert len(file_system.get_folder("src_folder").files) == 1 + assert len(file_system.get_folder("src_folder").deleted_files) == 0 assert len(file_system.get_folder("dst_folder").files) == 0 file_system.move_file(src_folder_name="src_folder", src_file_name="test_file.txt", dst_folder_name="dst_folder") assert len(file_system.get_folder("src_folder").files) == 0 + assert len(file_system.get_folder("src_folder").deleted_files) == 1 assert len(file_system.get_folder("dst_folder").files) == 1 assert file_system.get_file("dst_folder", "test_file.txt").uuid == original_uuid @@ -169,6 +173,73 @@ def test_folder_corrupt_repair(file_system): assert file.status == FileSystemItemStatus.GOOD +def test_file_scan(file_system): + """Test the ability to update visible status.""" + folder: Folder = file_system.create_folder(folder_name="test_folder") + file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + assert file.status == FileSystemItemStatus.GOOD + assert file.visible_status == FileSystemItemStatus.GOOD + + file.corrupt() + + assert file.status == FileSystemItemStatus.CORRUPTED + assert file.visible_status == FileSystemItemStatus.GOOD + + file.scan() + + assert file.status == FileSystemItemStatus.CORRUPTED + assert file.visible_status == FileSystemItemStatus.CORRUPTED + + +def test_folder_scan(file_system): + """Test the ability to update visible status.""" + folder: Folder = file_system.create_folder(folder_name="test_folder") + file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + assert folder.status == FileSystemItemStatus.GOOD + assert folder.visible_status == FileSystemItemStatus.GOOD + assert file.status == FileSystemItemStatus.GOOD + assert file.visible_status == FileSystemItemStatus.GOOD + + folder.corrupt() + + assert folder.status == FileSystemItemStatus.CORRUPTED + assert folder.visible_status == FileSystemItemStatus.GOOD + assert file.status == FileSystemItemStatus.CORRUPTED + assert file.visible_status == FileSystemItemStatus.GOOD + + folder.scan() + + assert folder.status == FileSystemItemStatus.CORRUPTED + assert folder.visible_status == FileSystemItemStatus.CORRUPTED + assert file.status == FileSystemItemStatus.CORRUPTED + assert file.visible_status == FileSystemItemStatus.CORRUPTED + + +def test_file_delete_restore(file_system): + """Test the ability to delete and restore a file.""" + folder: Folder = file_system.create_folder(folder_name="test_folder") + file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + assert file.status == FileSystemItemStatus.GOOD + assert file.visible_status == FileSystemItemStatus.GOOD + + file_system.delete_file(folder_name=folder.name, file_name=file.name) + + assert folder.get_file(file_name=file.name) is None + assert folder.get_file_by_id(file_uuid=file.uuid, show_deleted=True).status == FileSystemItemStatus.DELETED + + file_system.restore_file(folder_id=folder.uuid, file_id=file.uuid) + + assert file.status == FileSystemItemStatus.GOOD + assert folder.get_file(file_name=file.name) is not None + + +def test_folder_delete_restore(file_system): + pass + + def test_simulated_file_check_hash(file_system): file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") From 0edb9b46a7ed8f01587cfd00e386e201fcc0b7e0 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Wed, 18 Oct 2023 13:21:05 +0100 Subject: [PATCH 233/980] #1947: clean up existing work and clear up some itesm left in TODO --- docs/source/getting_started.rst | 4 +- .../simulator/file_system/file_system.py | 48 +++++++++++-------- .../_file_system/test_file_system.py | 23 --------- 3 files changed, 28 insertions(+), 47 deletions(-) diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 1dbf9dec..0801c79e 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -110,11 +110,9 @@ Clone & Install PrimAITE for Development To be able to extend PrimAITE further, or to build wheels manually before install, clone the repository to a location of your choice: -.. TODO:: Add repo path once we know what it is - .. code-block:: bash - git clone + git clone https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE cd primaite Create and activate your Python virtual environment (venv) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 24abbf18..33781563 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -1,5 +1,6 @@ from __future__ import annotations +import copy import hashlib import json import math @@ -358,8 +359,6 @@ class FileSystem(SimComponent): return folder = self._folders_by_name.get(folder_name) if folder: - for file in folder.files.values(): - self.delete_file(folder_name=folder_name, file_name=file.name) # add to deleted list folder.delete() self.deleted_folders[folder.uuid] = folder @@ -489,7 +488,7 @@ class FileSystem(SimComponent): new_file.sim_path.parent.mkdir(exist_ok=True) shutil.copy2(file.sim_path, new_file.sim_path) - def restore_file(self, folder_id: str, file_id: str) -> bool: + def restore_file(self, folder_id: str, file_id: str): """ Restore a file. @@ -501,11 +500,7 @@ class FileSystem(SimComponent): :param: folder_id: id of the file to restore :type: folder_id: str """ - folder = self.get_folder_by_id(folder_uuid=folder_id, show_deleted=True) - - if folder: - file = folder.get_file_by_id(file_uuid=file_id, show_deleted=True) - return file.restore() + pass def get_folder(self, folder_name: str) -> Optional[Folder]: """ @@ -648,6 +643,16 @@ class Folder(FileSystemItemABC): else: _LOGGER.debug(f"File with UUID {file.uuid} was not found.") + def restore_file(self, file: Optional[File]): + """ + Restores a file. + + The method can take a File object or a file id. + + :param file: The file to remove + """ + pass + def quarantine(self): """Quarantines the File System Folder.""" if self.status != FileSystemItemStatus.QUARANTINED: @@ -726,9 +731,17 @@ class Folder(FileSystemItemABC): """TODO.""" pass - def delete(self) -> bool: - """TODO.""" + def delete(self): + """Deletes the files within the folder and then deletes the folder.""" super().delete() + + # iterate through the files in the folder + files = copy.copy(self.files) + for file_id in files: + file = self.get_file_by_id(file_uuid=file_id) + file.delete() + self.remove_file(file) + self.fs.sys_log.info(f"Deleted folder {self.name} (id: {self.uuid})") def corrupt(self) -> bool: @@ -742,7 +755,7 @@ class Folder(FileSystemItemABC): file = self.get_file_by_id(file_uuid=file_id) corrupted = file.corrupt() - # set file status to good if corrupt + # set file status to corrupt if good if self.status == FileSystemItemStatus.GOOD: self.status = FileSystemItemStatus.CORRUPTED corrupted = True @@ -842,7 +855,7 @@ class File(FileSystemItemABC): return state def scan(self) -> None: - """TODO.""" + """Updates the visible statuses of the file.""" super().scan() path = self.folder.name + "/" + self.name @@ -882,7 +895,7 @@ class File(FileSystemItemABC): return True def delete(self) -> None: - """TODO.""" + """Deletes the file.""" super().delete() path = self.folder.name + "/" + self.name @@ -902,14 +915,7 @@ class File(FileSystemItemABC): def restore(self) -> None: """Restore a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" - super().restore() - - # set file status to good if deleted or corrupt - if self.status in [FileSystemItemStatus.CORRUPTED, FileSystemItemStatus.DELETED]: - self.status = FileSystemItemStatus.GOOD - - path = self.folder.name + "/" + self.name - self.folder.fs.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") + pass def corrupt(self) -> bool: """Corrupt a File by setting the status to FileSystemItemStatus.CORRUPTED.""" diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 4c5d5510..888b8c75 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -217,29 +217,6 @@ def test_folder_scan(file_system): assert file.visible_status == FileSystemItemStatus.CORRUPTED -def test_file_delete_restore(file_system): - """Test the ability to delete and restore a file.""" - folder: Folder = file_system.create_folder(folder_name="test_folder") - file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") - - assert file.status == FileSystemItemStatus.GOOD - assert file.visible_status == FileSystemItemStatus.GOOD - - file_system.delete_file(folder_name=folder.name, file_name=file.name) - - assert folder.get_file(file_name=file.name) is None - assert folder.get_file_by_id(file_uuid=file.uuid, show_deleted=True).status == FileSystemItemStatus.DELETED - - file_system.restore_file(folder_id=folder.uuid, file_id=file.uuid) - - assert file.status == FileSystemItemStatus.GOOD - assert folder.get_file(file_name=file.name) is not None - - -def test_folder_delete_restore(file_system): - pass - - def test_simulated_file_check_hash(file_system): file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") From e0f8c3c5eaf5bc8dea27d58af7160dfcf64d0b5f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 19 Oct 2023 01:56:40 +0100 Subject: [PATCH 234/980] Add documentation --- example_config.yaml | 10 +- src/primaite/game/__init__.py | 1 + src/primaite/game/agent/actions.py | 323 +++++++++++++++++++++++---- src/primaite/game/agent/interface.py | 4 +- src/primaite/game/agent/rewards.py | 74 +++--- src/primaite/game/session.py | 166 +++++++++----- 6 files changed, 445 insertions(+), 133 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index b700da5c..e16411fa 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -2,10 +2,10 @@ training_config: rl_framework: SB3 rl_algorithm: PPO seed: 333 - n_learn_episodes: 2 - n_learn_steps: 128 - n_eval_episodes: 2 - n_eval_steps: 128 + n_learn_episodes: 1 + n_learn_steps: 8 + n_eval_episodes: 0 + n_eval_steps: 8 game_config: @@ -451,6 +451,8 @@ game_config: node_ref: database_server folder_name: database file_name: database.db + + - type: WEB_SERVER_404_PENALTY weight: 0.5 options: diff --git a/src/primaite/game/__init__.py b/src/primaite/game/__init__.py index e69de29b..5d7a721f 100644 --- a/src/primaite/game/__init__.py +++ b/src/primaite/game/__init__.py @@ -0,0 +1 @@ +"""PrimAITE Game Layer.""" diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 6a1d5bcd..4c4aaab4 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -1,6 +1,16 @@ +""" +This module contains the ActionManager class which belongs to the Agent class. + +An agent's action space is made up of a collection of actions. Each action is an instance of a subclass of +AbstractAction. The ActionManager is responsible for: + 1. Creating the action space from a list of action types. + 2. Converting an integer action choice into a specific action and parameter choice. + 3. Converting an action and parameter choice into a request which can be ingested by the PrimAITE simulation. This + ensures that requests conform to the simulator's request format. +""" import itertools from abc import ABC, abstractmethod -from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING +from typing import Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium import spaces @@ -13,22 +23,9 @@ if TYPE_CHECKING: from primaite.game.session import PrimaiteSession -class ExecutionDefiniton(ABC): - """ - Converter from actions to simulator requests. - - Allows adding extra data/context that defines in more detail what an action means. - """ - - """ - Examples: - ('node', 'service', 'scan', 2, 0) means scan the first service on node index 2 - -> ['network', 'nodes', , 'services', , 'scan'w] - """ - ... - - class AbstractAction(ABC): + """Base class for actions.""" + @abstractmethod def __init__(self, manager: "ActionManager", **kwargs) -> None: """ @@ -46,6 +43,8 @@ class AbstractAction(ABC): """Dictionary describing the number of options for each parameter of this action. The keys of this dict must align with the keyword args of the form_request method.""" self.manager: ActionManager = manager + """Reference to the ActionManager which created this action. This is used to access the session and simulation + objects.""" @abstractmethod def form_request(self) -> List[str]: @@ -54,6 +53,8 @@ class AbstractAction(ABC): class DoNothingAction(AbstractAction): + """Action which does nothing. This is here to allow agents to be idle if they choose to.""" + def __init__(self, manager: "ActionManager", **kwargs) -> None: super().__init__(manager=manager) self.name = "DONOTHING" @@ -65,6 +66,7 @@ class DoNothingAction(AbstractAction): # with one option. This just aids the Action Manager to enumerate all possibilities. def form_request(self, **kwargs) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" return ["do_nothing"] @@ -77,12 +79,13 @@ class NodeServiceAbstractAction(AbstractAction): """ @abstractmethod - def __init__(self, manager: "ActionManager", num_nodes, num_services, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes, "service_id": num_services} self.verb: str def form_request(self, node_id: int, service_id: int) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" node_uuid = self.manager.get_node_uuid_by_idx(node_id) service_uuid = self.manager.get_service_uuid_by_idx(node_id, service_id) if node_uuid is None or service_uuid is None: @@ -91,54 +94,77 @@ class NodeServiceAbstractAction(AbstractAction): class NodeServiceScanAction(NodeServiceAbstractAction): + """Action which scans a service.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "scan" class NodeServiceStopAction(NodeServiceAbstractAction): + """Action which stops a service.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "stop" class NodeServiceStartAction(NodeServiceAbstractAction): + """Action which starts a service.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "start" class NodeServicePauseAction(NodeServiceAbstractAction): + """Action which pauses a service.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "pause" class NodeServiceResumeAction(NodeServiceAbstractAction): + """Action which resumes a service.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "resume" class NodeServiceRestartAction(NodeServiceAbstractAction): + """Action which restarts a service.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "restart" class NodeServiceDisableAction(NodeServiceAbstractAction): + """Action which disables a service.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "disable" class NodeServiceEnableAction(NodeServiceAbstractAction): + """Action which enables a service.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) self.verb = "enable" class NodeFolderAbstractAction(AbstractAction): + """ + Base class for folder actions. + + Any action which applies to a folder and uses node_id and folder_id as its only two parameters can inherit from + this base class. + """ + @abstractmethod def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, **kwargs) -> None: super().__init__(manager=manager) @@ -146,6 +172,7 @@ class NodeFolderAbstractAction(AbstractAction): self.verb: str def form_request(self, node_id: int, folder_id: int) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" node_uuid = self.manager.get_node_uuid_by_idx(node_id) folder_uuid = self.manager.get_folder_uuid_by_idx(node_idx=node_id, folder_idx=folder_id) if node_uuid is None or folder_uuid is None: @@ -154,30 +181,44 @@ class NodeFolderAbstractAction(AbstractAction): class NodeFolderScanAction(NodeFolderAbstractAction): + """Action which scans a folder.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, **kwargs) self.verb: str = "scan" class NodeFolderCheckhashAction(NodeFolderAbstractAction): + """Action which checks the hash of a folder.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, **kwargs) self.verb: str = "checkhash" class NodeFolderRepairAction(NodeFolderAbstractAction): + """Action which repairs a folder.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, **kwargs) self.verb: str = "repair" class NodeFolderRestoreAction(NodeFolderAbstractAction): + """Action which restores a folder.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, **kwargs) self.verb: str = "restore" class NodeFileAbstractAction(AbstractAction): + """Abstract base class for file actions. + + Any action which applies to a file and uses node_id, folder_id, and file_id as its only three parameters can inherit + from this base class. + """ + @abstractmethod def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager=manager) @@ -185,6 +226,7 @@ class NodeFileAbstractAction(AbstractAction): self.verb: str def form_request(self, node_id: int, folder_id: int, file_id: int) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" node_uuid = self.manager.get_node_uuid_by_idx(node_id) folder_uuid = self.manager.get_folder_uuid_by_idx(node_idx=node_id, folder_idx=folder_id) file_uuid = self.manager.get_file_uuid_by_idx(node_idx=node_id, folder_idx=folder_id, file_idx=file_id) @@ -194,42 +236,60 @@ class NodeFileAbstractAction(AbstractAction): class NodeFileScanAction(NodeFileAbstractAction): + """Action which scans a file.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) self.verb = "scan" class NodeFileCheckhashAction(NodeFileAbstractAction): + """Action which checks the hash of a file.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) self.verb = "checkhash" class NodeFileDeleteAction(NodeFileAbstractAction): + """Action which deletes a file.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) self.verb = "delete" class NodeFileRepairAction(NodeFileAbstractAction): + """Action which repairs a file.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) self.verb = "repair" class NodeFileRestoreAction(NodeFileAbstractAction): + """Action which restores a file.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) self.verb = "restore" class NodeFileCorruptAction(NodeFileAbstractAction): + """Action which corrupts a file.""" + def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) self.verb = "corrupt" class NodeAbstractAction(AbstractAction): + """ + Abstract base class for node actions. + + Any action which applies to a node and uses node_id as its only parameter can inherit from this base class. + """ + @abstractmethod def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager) @@ -237,35 +297,46 @@ class NodeAbstractAction(AbstractAction): self.verb: str def form_request(self, node_id: int) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" node_uuid = self.manager.get_node_uuid_by_idx(node_id) return ["network", "node", node_uuid, self.verb] class NodeOSScanAction(NodeAbstractAction): + """Action which scans a node's OS.""" + def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes) self.verb = "scan" class NodeShutdownAction(NodeAbstractAction): + """Action which shuts down a node.""" + def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes) self.verb = "shutdown" class NodeStartupAction(NodeAbstractAction): + """Action which starts up a node.""" + def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes) self.verb = "startup" class NodeResetAction(NodeAbstractAction): + """Action which resets a node.""" + def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes) self.verb = "reset" class NetworkACLAddRuleAction(AbstractAction): + """Action which adds a rule to a router's ACL.""" + def __init__( self, manager: "ActionManager", @@ -276,6 +347,21 @@ class NetworkACLAddRuleAction(AbstractAction): num_protocols: int, **kwargs, ) -> None: + """Init method for NetworkACLAddRuleAction. + + :param manager: Reference to the ActionManager which created this action. + :type manager: ActionManager + :param target_router_uuid: UUID of the router to which the ACL rule should be added. + :type target_router_uuid: str + :param max_acl_rules: Maximum number of ACL rules that can be added to the router. + :type max_acl_rules: int + :param num_ips: Number of IP addresses in the simulation. + :type num_ips: int + :param num_ports: Number of ports in the simulation. + :type num_ports: int + :param num_protocols: Number of protocols in the simulation. + :type num_protocols: int + """ super().__init__(manager=manager) num_permissions = 3 self.shape: Dict[str, int] = { @@ -290,8 +376,16 @@ class NetworkACLAddRuleAction(AbstractAction): self.target_router_uuid: str = target_router_uuid def form_request( - self, position, permission, source_ip_id, dest_ip_id, source_port_id, dest_port_id, protocol_id + self, + position: int, + permission: int, + source_ip_id: int, + dest_ip_id: int, + source_port_id: int, + dest_port_id: int, + protocol_id: int, ) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" if permission == 0: permission_str = "UNUSED" return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS @@ -354,22 +448,51 @@ class NetworkACLAddRuleAction(AbstractAction): class NetworkACLRemoveRuleAction(AbstractAction): + """Action which removes a rule from a router's ACL.""" + def __init__(self, manager: "ActionManager", target_router_uuid: str, max_acl_rules: int, **kwargs) -> None: + """Init method for NetworkACLRemoveRuleAction. + + :param manager: Reference to the ActionManager which created this action. + :type manager: ActionManager + :param target_router_uuid: UUID of the router from which the ACL rule should be removed. + :type target_router_uuid: str + :param max_acl_rules: Maximum number of ACL rules that can be added to the router. + :type max_acl_rules: int + """ super().__init__(manager=manager) self.shape: Dict[str, int] = {"position": max_acl_rules} self.target_router_uuid: str = target_router_uuid def form_request(self, position: int) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" return ["network", "node", self.target_router_uuid, "acl", "remove_rule", position] class NetworkNICAbstractAction(AbstractAction): + """ + Abstract base class for NIC actions. + + Any action which applies to a NIC and uses node_id and nic_id as its only two parameters can inherit from this base + class. + """ + def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: + """Init method for NetworkNICAbstractAction. + + :param manager: Reference to the ActionManager which created this action. + :type manager: ActionManager + :param num_nodes: Number of nodes in the simulation. + :type num_nodes: int + :param max_nics_per_node: Maximum number of NICs per node. + :type max_nics_per_node: int + """ super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes, "nic_id": max_nics_per_node} self.verb: str def form_request(self, node_id: int, nic_id: int) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" node_uuid = self.manager.get_node_uuid_by_idx(node_idx=node_id) nic_uuid = self.manager.get_nic_uuid_by_idx(node_idx=node_id, nic_idx=nic_id) if node_uuid is None or nic_uuid is None: @@ -385,45 +508,24 @@ class NetworkNICAbstractAction(AbstractAction): class NetworkNICEnableAction(NetworkNICAbstractAction): + """Action which enables a NIC.""" + def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, max_nics_per_node=max_nics_per_node, **kwargs) self.verb = "enable" class NetworkNICDisableAction(NetworkNICAbstractAction): + """Action which disables a NIC.""" + def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, max_nics_per_node=max_nics_per_node, **kwargs) self.verb = "disable" -# class NetworkNICDisableAction(AbstractAction): -# def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: -# super().__init__(manager=manager) -# self.shape: Dict[str, int] = {"node_id": num_nodes, "nic_id": max_nics_per_node} - -# def form_request(self, node_id: int, nic_id: int) -> List[str]: -# return [ -# "network", -# "node", -# self.manager.get_node_uuid_by_idx(node_idx=node_id), -# "nic", -# self.manager.get_nic_uuid_by_idx(node_idx=node_id, nic_idx=nic_id), -# "disable", -# ] - - class ActionManager: - # let the action manager handle the conversion of action spaces into a single discrete integer space. - # + """Class which manages the action space for an agent.""" - # when action space is created, it will take subspaces and generate an action map by enumerating all possibilities, - # BUT, the action map can be provided in the config, in which case it will use that. - - # action map is basically just a mapping between integer and CAOS action (incl. parameter values) - # for example the action map can be: - # 0: DONOTHING - # 1: NODE, FILE, SCAN, NODEID=2, FOLDERID=1, FILEID=0 - # 2: ...... __act_class_identifiers: Dict[str, type] = { "DONOTHING": DoNothingAction, "NODE_SERVICE_SCAN": NodeServiceScanAction, @@ -453,6 +555,7 @@ class ActionManager: "NETWORK_NIC_ENABLE": NetworkNICEnableAction, "NETWORK_NIC_DISABLE": NetworkNICDisableAction, } + """Dictionary which maps action type strings to the corresponding action class.""" def __init__( self, @@ -469,6 +572,33 @@ class ActionManager: ip_address_list: Optional[List[str]] = None, # to allow us to map an index to an ip address. act_map: Optional[Dict[int, Dict]] = None, # allows restricting set of possible actions ) -> None: + """Init method for ActionManager. + + :param session: Reference to the session to which the agent belongs. + :type session: PrimaiteSession + :param actions: List of action types which should be made available to the agent. + :type actions: List[str] + :param node_uuids: List of node UUIDs that this agent can act on. + :type node_uuids: List[str] + :param max_folders_per_node: Maximum number of folders per node. Used for calculating action shape. + :type max_folders_per_node: int + :param max_files_per_folder: Maximum number of files per folder. Used for calculating action shape. + :type max_files_per_folder: int + :param max_services_per_node: Maximum number of services per node. Used for calculating action shape. + :type max_services_per_node: int + :param max_nics_per_node: Maximum number of NICs per node. Used for calculating action shape. + :type max_nics_per_node: int + :param max_acl_rules: Maximum number of ACL rules per router. Used for calculating action shape. + :type max_acl_rules: int + :param protocols: List of protocols that are available in the simulation. Used for calculating action shape. + :type protocols: List[str] + :param ports: List of ports that are available in the simulation. Used for calculating action shape. + :type ports: List[str] + :param ip_address_list: List of IP addresses that known to this agent. Used for calculating action shape. + :type ip_address_list: Optional[List[str]] + :param act_map: Action map which maps integers to actions. Used for restricting the set of possible actions. + :type act_map: Optional[Dict[int, Dict]] + """ self.session: "PrimaiteSession" = session self.sim: Simulation = self.session.simulation self.node_uuids: List[str] = node_uuids @@ -578,18 +708,48 @@ class ActionManager: @property def space(self) -> spaces.Space: + """Return the gymnasium action space for this agent.""" return spaces.Discrete(len(self.action_map)) - def get_node_uuid_by_idx(self, node_idx): + def get_node_uuid_by_idx(self, node_idx: int) -> str: + """Get the node UUID corresponding to the given index. + + :param node_idx: The index of the node to retrieve. + :type node_idx: int + :return: The node UUID. + :rtype: str + """ return self.node_uuids[node_idx] - def get_folder_uuid_by_idx(self, node_idx, folder_idx) -> Optional[str]: + def get_folder_uuid_by_idx(self, node_idx: int, folder_idx: int) -> Optional[str]: + """Get the folder UUID corresponding to the given node and folder indices. + + :param node_idx: The index of the node. + :type node_idx: int + :param folder_idx: The index of the folder on the node. + :type folder_idx: int + :return: The UUID of the folder. Or None if the node has fewer folders than the given index. + :rtype: Optional[str] + """ + node_uuid = self.get_node_uuid_by_idx(node_idx) node = self.sim.network.nodes[node_uuid] folder_uuids = list(node.file_system.folders.keys()) return folder_uuids[folder_idx] if len(folder_uuids) > folder_idx else None - def get_file_uuid_by_idx(self, node_idx, folder_idx, file_idx) -> Optional[str]: + def get_file_uuid_by_idx(self, node_idx: int, folder_idx: int, file_idx: int) -> Optional[str]: + """Get the file UUID corresponding to the given node, folder, and file indices. + + :param node_idx: The index of the node. + :type node_idx: int + :param folder_idx: The index of the folder on the node. + :type folder_idx: int + :param file_idx: The index of the file in the folder. + :type file_idx: int + :return: The UUID of the file. Or None if the node has fewer folders than the given index, or the folder has + fewer files than the given index. + :rtype: Optional[str] + """ node_uuid = self.get_node_uuid_by_idx(node_idx) node = self.sim.network.nodes[node_uuid] folder_uuids = list(node.file_system.folders.keys()) @@ -599,22 +759,64 @@ class ActionManager: file_uuids = list(folder.files.keys()) return file_uuids[file_idx] if len(file_uuids) > file_idx else None - def get_service_uuid_by_idx(self, node_idx, service_idx) -> Optional[str]: + def get_service_uuid_by_idx(self, node_idx: int, service_idx: int) -> Optional[str]: + """Get the service UUID corresponding to the given node and service indices. + + :param node_idx: The index of the node. + :type node_idx: int + :param service_idx: The index of the service on the node. + :type service_idx: int + :return: The UUID of the service. Or None if the node has fewer services than the given index. + :rtype: Optional[str] + """ node_uuid = self.get_node_uuid_by_idx(node_idx) node = self.sim.network.nodes[node_uuid] service_uuids = list(node.services.keys()) return service_uuids[service_idx] if len(service_uuids) > service_idx else None def get_internet_protocol_by_idx(self, protocol_idx: int) -> str: + """Get the internet protocol corresponding to the given index. + + :param protocol_idx: The index of the protocol to retrieve. + :type protocol_idx: int + :return: The protocol. + :rtype: str + """ return self.protocols[protocol_idx] def get_ip_address_by_idx(self, ip_idx: int) -> str: + """ + Get the IP address corresponding to the given index. + + :param ip_idx: The index of the IP address to retrieve. + :type ip_idx: int + :return: The IP address. + :rtype: str + """ return self.ip_address_list[ip_idx] def get_port_by_idx(self, port_idx: int) -> str: + """ + Get the port corresponding to the given index. + + :param port_idx: The index of the port to retrieve. + :type port_idx: int + :return: The port. + :rtype: str + """ return self.ports[port_idx] def get_nic_uuid_by_idx(self, node_idx: int, nic_idx: int) -> str: + """ + Get the NIC UUID corresponding to the given node and NIC indices. + + :param node_idx: The index of the node. + :type node_idx: int + :param nic_idx: The index of the NIC on the node. + :type nic_idx: int + :return: The NIC UUID. + :rtype: str + """ node_uuid = self.get_node_uuid_by_idx(node_idx) node_obj = self.sim.network.nodes[node_uuid] nics = list(node_obj.nics.keys()) @@ -624,6 +826,31 @@ class ActionManager: @classmethod def from_config(cls, session: "PrimaiteSession", cfg: Dict) -> "ActionManager": + """ + Construct an ActionManager from a config definition. + + The action space config supports the following three sections: + 1. ``action_list`` + ``action_list`` contians a list action components which need to be included in the action space. + Each action component has a ``type`` which maps to a subclass of AbstractAction, and additional options + which will be passed to the action class's __init__ method during initialisation. + 2. ``action_map`` + Since the agent uses a discrete action space which acts as a flattened version of the component-based + action space, action_map provides a mapping between an integer (chosen by the agent) and a meaningful + action and values of parameters. For example action 0 can correspond to do nothing, action 1 can + correspond to "NODE_SERVICE_SCAN" with ``node_id=1`` and ``service_id=1``, action 2 can be " + 3. ``options`` + ``options`` contains a dictionary of options which are passed to the ActionManager's __init__ method. + These options are used to calculate the shape of the action space, and to provide additional information + to the ActionManager which is required to convert the agent's action choice into a CAOS request. + + :param session: The Primaite Session to which the agent belongs. + :type session: PrimaiteSession + :param cfg: The action space config. + :type cfg: Dict + :return: The constructed ActionManager. + :rtype: ActionManager + """ obj = cls( session=session, actions=cfg["action_list"], diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 817e59b1..5f121fcc 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -1,6 +1,4 @@ -# TODO: remove this comment... This is just here to point out that I've named this 'actor' rather than 'agent' -# That's because I want to point out that this is disctinct from 'agent' in the reinforcement learning sense of the word -# If you disagree, make a comment in the PR review and we can discuss +"""Interface for agents.""" from abc import ABC, abstractmethod from typing import Any, Dict, List, Optional, Tuple, TypeAlias, Union diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 85da95da..67e6ee50 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -1,8 +1,9 @@ -from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE - from abc import ABC, abstractmethod from typing import Any, Dict, List, Tuple, TYPE_CHECKING + from primaite import getLogger +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE + _LOGGER = getLogger(__name__) if TYPE_CHECKING: @@ -10,14 +11,13 @@ if TYPE_CHECKING: class AbstractReward: - @abstractmethod def calculate(self, state: Dict) -> float: return 0.0 @classmethod @abstractmethod - def from_config(cls, config:dict, session:"PrimaiteSession") -> "AbstractReward": + def from_config(cls, config: dict, session: "PrimaiteSession") -> "AbstractReward": return cls() @@ -26,16 +26,26 @@ class DummyReward(AbstractReward): return 0.0 @classmethod - def from_config(cls, config: dict, session:"PrimaiteSession") -> "DummyReward": + def from_config(cls, config: dict, session: "PrimaiteSession") -> "DummyReward": return cls() + class DatabaseFileIntegrity(AbstractReward): - def __init__(self, node_uuid:str, folder_name:str, file_name:str) -> None: - self.location_in_state = ["network", "nodes", node_uuid, "file_system", "folders",folder_name, "files", file_name] + def __init__(self, node_uuid: str, folder_name: str, file_name: str) -> None: + self.location_in_state = [ + "network", + "nodes", + node_uuid, + "file_system", + "folders", + folder_name, + "files", + file_name, + ] def calculate(self, state: Dict) -> float: database_file_state = access_from_nested_dict(state, self.location_in_state) - health_status = database_file_state['health_status'] + health_status = database_file_state["health_status"] if health_status == "corrupted": return -1 elif health_status == "good": @@ -48,29 +58,39 @@ class DatabaseFileIntegrity(AbstractReward): node_ref = config.get("node_ref") folder_name = config.get("folder_name") file_name = config.get("file_name") - if not (node_ref): - _LOGGER.error(f"{cls.__name__} could not be initialised from config because node_ref parameter was not specified") - return DummyReward() #TODO: better error handling + if not node_ref: + _LOGGER.error( + f"{cls.__name__} could not be initialised from config because node_ref parameter was not specified" + ) + return DummyReward() # TODO: better error handling if not folder_name: - _LOGGER.error(f"{cls.__name__} could not be initialised from config because folder_name parameter was not specified") - return DummyReward() # TODO: better error handling + _LOGGER.error( + f"{cls.__name__} could not be initialised from config because folder_name parameter was not specified" + ) + return DummyReward() # TODO: better error handling if not file_name: - _LOGGER.error(f"{cls.__name__} could not be initialised from config because file_name parameter was not specified") - return DummyReward() # TODO: better error handling + _LOGGER.error( + f"{cls.__name__} could not be initialised from config because file_name parameter was not specified" + ) + return DummyReward() # TODO: better error handling node_uuid = session.ref_map_nodes[node_ref] if not node_uuid: - _LOGGER.error(f"{cls.__name__} could not be initialised from config because the referenced node could not be found in the simulation") - return DummyReward() # TODO: better error handling + _LOGGER.error( + f"{cls.__name__} could not be initialised from config because the referenced node could not be found in the simulation" + ) + return DummyReward() # TODO: better error handling + + return cls(node_uuid=node_uuid, folder_name=folder_name, file_name=file_name) - return cls(node_uuid = node_uuid, folder_name=folder_name, file_name=file_name) class WebServer404Penalty(AbstractReward): - def __init__(self, node_uuid:str, service_uuid:str) -> None: - self.location_in_state = ['network','nodes', node_uuid, 'services', service_uuid] + def __init__(self, node_uuid: str, service_uuid: str) -> None: + self.location_in_state = ["network", "nodes", node_uuid, "services", service_uuid] def calculate(self, state: Dict) -> float: web_service_state = access_from_nested_dict(state, self.location_in_state) - most_recent_return_code = web_service_state['most_recent_return_code'] + most_recent_return_code = web_service_state["most_recent_return_code"] + # TODO: reward needs to use the current web state. Observation should return web state at the time of last scan. if most_recent_return_code == 200: return 1 elif most_recent_return_code == 404: @@ -85,13 +105,13 @@ class WebServer404Penalty(AbstractReward): if not (node_ref and service_ref): msg = f"{cls.__name__} could not be initialised from config because node_ref and service_ref were not found in reward config." _LOGGER.warn(msg) - return DummyReward() #TODO: should we error out with incorrect inputs? Probably! + return DummyReward() # TODO: should we error out with incorrect inputs? Probably! node_uuid = session.ref_map_nodes[node_ref] service_uuid = session.ref_map_services[service_ref].uuid if not (node_uuid and service_uuid): msg = f"{cls.__name__} could not be initialised because node {node_ref} and service {service_ref} were not found in the simulator." _LOGGER.warn(msg) - return DummyReward() # TODO: consider erroring here as well + return DummyReward() # TODO: consider erroring here as well return cls(node_uuid=node_uuid, service_uuid=service_uuid) @@ -101,13 +121,13 @@ class RewardFunction: "DUMMY": DummyReward, "DATABASE_FILE_INTEGRITY": DatabaseFileIntegrity, "WEB_SERVER_404_PENALTY": WebServer404Penalty, - } + } def __init__(self): self.reward_components: List[Tuple[AbstractReward, float]] = [] "attribute reward_components keeps track of reward components and the weights assigned to each." - def regsiter_component(self, component:AbstractReward, weight:float=1.0) -> None: + def regsiter_component(self, component: AbstractReward, weight: float = 1.0) -> None: self.reward_components.append((component, weight)) def calculate(self, state: Dict) -> float: @@ -124,8 +144,8 @@ class RewardFunction: for rew_component_cfg in config["reward_components"]: rew_type = rew_component_cfg["type"] - weight = rew_component_cfg.get("weight",1.0) + weight = rew_component_cfg.get("weight", 1.0) rew_class = cls.__rew_class_identifiers[rew_type] - rew_instance = rew_class.from_config(config=rew_component_cfg.get('options',{}), session=session) + rew_instance = rew_class.from_config(config=rew_component_cfg.get("options", {}), session=session) new.regsiter_component(component=rew_instance, weight=weight) return new diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 406308b9..f29d03dd 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -1,39 +1,17 @@ -# What do? Be an entry point for using PrimAITE -# 1. parse monoconfig -# 2. craete simulation -# 3. create actors and configure their actions/observations/rewards/ anything else -# 4. Create connection with ARCD GATE -# 5. idk - +"""PrimAITE session - the main entry point to training agents on PrimAITE.""" from ipaddress import IPv4Address from typing import Any, Dict, List, Optional, Tuple + +from arcd_gate.client.gate_client import ActType, GATEClient from gymnasium import spaces -from gymnasium.spaces.utils import flatten, flatten_space, unflatten -from gymnasium.core import ObsType, ActType - -import numpy as np - +from gymnasium.core import ActType, ObsType +from gymnasium.spaces.utils import flatten, flatten_space from pydantic import BaseModel from primaite import getLogger -from primaite.game.agent.GATE_agents import GATERLAgent from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractAgent, RandomAgent -from primaite.game.agent.observations import ( - AclObservation, - FileObservation, - FolderObservation, - ICSObservation, - LinkObservation, - NicObservation, - NodeObservation, - NullObservation, - ObservationSpace, - ServiceObservation, - UC2BlueObservation, - UC2GreenObservation, - UC2RedObservation, -) +from primaite.game.agent.observations import ObservationSpace from primaite.game.agent.rewards import RewardFunction from primaite.simulator.network.hardware.base import Link, NIC, Node from primaite.simulator.network.hardware.nodes.computer import Computer @@ -50,53 +28,75 @@ from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.service import Service -from arcd_gate.client.gate_client import GATEClient, ActType -from numpy import ndarray - _LOGGER = getLogger(__name__) + class PrimaiteGATEClient(GATEClient): - def __init__(self, parent_session:"PrimaiteSession", service_port: int = 50000): + def __init__(self, parent_session: "PrimaiteSession", service_port: int = 50000): + """Create a new GATE client for PrimAITE. + + :param parent_session: The parent session object. + :type parent_session: PrimaiteSession + :param service_port: The port on which the GATE service is running. + :type service_port: int, optional""" super().__init__(service_port=service_port) - self.parent_session:"PrimaiteSession" = parent_session + self.parent_session: "PrimaiteSession" = parent_session @property def rl_framework(self) -> str: + """The reinforcement learning framework to use.""" return self.parent_session.training_options.rl_framework @property def rl_algorithm(self) -> str: + """The reinforcement learning algorithm to use.""" return self.parent_session.training_options.rl_algorithm @property def seed(self) -> int | None: + """The seed to use for the environment's random number generator.""" return self.parent_session.training_options.seed @property def n_learn_episodes(self) -> int: + """The number of episodes in each learning run.""" return self.parent_session.training_options.n_learn_episodes @property def n_learn_steps(self) -> int: + """The number of steps in each learning episode.""" return self.parent_session.training_options.n_learn_steps @property def n_eval_episodes(self) -> int: + """The number of episodes in each evaluation run.""" return self.parent_session.training_options.n_eval_episodes @property def n_eval_steps(self) -> int: + """The number of steps in each evaluation episode.""" return self.parent_session.training_options.n_eval_steps @property def action_space(self) -> spaces.Space: + """The gym action space of the agent.""" return self.parent_session.rl_agent.action_space.space @property def observation_space(self) -> spaces.Space: + """The gymnasium observation space of the agent.""" return flatten_space(self.parent_session.rl_agent.observation_space.space) def step(self, action: ActType) -> Tuple[ObsType, float, bool, bool, Dict]: + """Take a step in the environment. + + This method is called by GATE to advance the simulation by one timestep. + + :param action: The agent's action. + :type action: ActType + :return: The observation, reward, terminal flag, truncated flag, and info dictionary. + :rtype: Tuple[ObsType, float, bool, bool, Dict] + """ self.parent_session.rl_agent.most_recent_action = action self.parent_session.step() state = self.parent_session.simulation.describe_state() @@ -108,8 +108,19 @@ class PrimaiteGATEClient(GATEClient): info = {} return obs, rew, term, trunc, info - def reset(self, *, seed: int | None = None, options: dict[str, Any] | None = None) -> Tuple[ObsType, Dict]: + """Reset the environment. + + This method is called when the environment is initialized and at the end of each episode. + + :param seed: The seed to use for the environment's random number generator. + :type seed: int, optional + :param options: Additional options for the reset. None are used by PrimAITE but this is included for + compatibility with GATE. + :type options: dict[str, Any], optional + :return: The initial observation and an empty info dictionary. + :rtype: Tuple[ObsType, Dict] + """ self.parent_session.reset() state = self.parent_session.simulation.describe_state() obs = self.parent_session.rl_agent.observation_space.observe(state) @@ -117,44 +128,78 @@ class PrimaiteGATEClient(GATEClient): return obs, {} def close(self): + """Close the session, this will stop the gate client and close the simulation.""" self.parent_session.close() + class PrimaiteSessionOptions(BaseModel): + """Global options which are applicable to all of the agents in the game. + + Currently this is used to restrict which ports and protocols exist in the world of the simulation.""" + ports: List[str] protocols: List[str] -class TrainingOptions(BaseModel): - rl_framework:str - rl_algorithm:str - seed:Optional[int] - n_learn_episodes:int - n_learn_steps:int - n_eval_episodes:int - n_eval_steps:int +class TrainingOptions(BaseModel): + """Options for training the RL agent.""" + + rl_framework: str + rl_algorithm: str + seed: Optional[int] + n_learn_episodes: int + n_learn_steps: int + n_eval_episodes: int + n_eval_steps: int class PrimaiteSession: + """ + The main entrypoint for PrimAITE sessions, this coordinates a simulation, agents, and connections to ARCD GATE. + """ + def __init__(self): self.simulation: Simulation = Simulation() + """Simulation object with which the agents will interact.""" self.agents: List[AbstractAgent] = [] + """List of agents.""" self.rl_agent: AbstractAgent - # which of the agents should be used for sending RL data to GATE client? + """The agent from the list which communicates with GATE to perform reinforcement learning.""" self.step_counter: int = 0 + """Current timestep within the episode.""" self.episode_counter: int = 0 + """Current episode number.""" self.options: PrimaiteSessionOptions + """Special options that apply for the entire game.""" self.training_options: TrainingOptions + """Options specific to agent training.""" self.ref_map_nodes: Dict[str, Node] = {} + """Mapping from unique node reference name to node object. Used when parsing config files.""" self.ref_map_services: Dict[str, Service] = {} + """Mapping from human-readable service reference to service object. Used for parsing config files.""" self.ref_map_links: Dict[str, Link] = {} + """Mapping from human-readable link reference to link object. Used when parsing config files.""" self.gate_client: PrimaiteGATEClient = PrimaiteGATEClient(self) + """Reference to a GATE Client object, which will send data to GATE service for training RL agent.""" def start_session(self, opts="TODO..."): - """Commence the session, this gives the gate client control over the simulation/agent loop.""" + """Commence the training session, this gives the GATE client control over the simulation/agent loop.""" self.gate_client.start() def step(self): + """ + Perform one step of the simulation/agent loop. + + This is the main loop of the game. It corresponds to one timestep in the simulation, and one action from each + agent. The steps are as follows: + 1. The simulation state is updated. + 2. The simulation state is sent to each agent. + 3. Each agent converts the state to an observation and calculates a reward. + 4. Each agent chooses an action based on the observation. + 5. Each agent converts the action to a request. + 6. The simulation applies the requests. + """ _LOGGER.debug(f"Stepping primaite session. Step counter: {self.step_counter}") # currently designed with assumption that all agents act once per step in order @@ -192,19 +237,36 @@ class PrimaiteSession: self.step_counter += 1 def reset(self): - pass + """Reset the session, this will reset the simulation.""" + return NotImplemented def close(self): - pass + """Close the session, this will stop the gate client and close the simulation.""" + return NotImplemented @classmethod def from_config(cls, cfg: dict) -> "PrimaiteSession": + """Create a PrimaiteSession object from a config dictionary. + + The config dictionary should have the following top-level keys: + 1. training_config: options for training the RL agent. Used by GATE. + 2. game_config: options for the game itself. Used by PrimaiteSession. + 3. simulation: defines the network topology and the initial state of the simulation. + + The specification for each of the three major areas is described in a separate documentation page. + # TODO: create documentation page and add links to it here. + + :param cfg: The config dictionary. + :type cfg: dict + :return: A PrimaiteSession object. + :rtype: PrimaiteSession + """ sess = cls() sess.options = PrimaiteSessionOptions( ports=cfg["game_config"]["ports"], protocols=cfg["game_config"]["protocols"], ) - sess.training_options = TrainingOptions(**cfg['training_config']) + sess.training_options = TrainingOptions(**cfg["training_config"]) sim = sess.simulation net = sim.network @@ -295,7 +357,11 @@ class PrimaiteSession: net.add_node(new_node) new_node.power_on() - sess.ref_map_nodes[node_ref] = new_node.uuid # TODO: fix incosistency with service and link. Node gets added by uuid, but service gets reference to object + sess.ref_map_nodes[ + node_ref + ] = ( + new_node.uuid + ) # TODO: fix incosistency with service and link. Node gets added by uuid, but service by object # 2. create links between nodes for link_cfg in links_cfg: @@ -314,12 +380,10 @@ class PrimaiteSession: # 3. create agents game_cfg = cfg["game_config"] - ports_cfg = game_cfg["ports"] - protocols_cfg = game_cfg["protocols"] agents_cfg = game_cfg["agents"] for agent_cfg in agents_cfg: - agent_ref = agent_cfg["ref"] + agent_ref = agent_cfg["ref"] # noqa: F841 agent_type = agent_cfg["type"] action_space_cfg = agent_cfg["action_space"] observation_space_cfg = agent_cfg["observation_space"] From 49e78d529114011ce6926f516948ad6978ae194b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 19 Oct 2023 09:36:23 +0100 Subject: [PATCH 235/980] Add docstrings and fix formatting on many things --- sandbox.py | 23 +- src/primaite/game/agent/GATE_agents.py | 16 +- src/primaite/game/agent/actions.py | 13 +- src/primaite/game/agent/interface.py | 45 ++- src/primaite/game/agent/observations.py | 410 ++++++++++++++++++--- src/primaite/game/agent/rewards.py | 142 ++++++- src/primaite/game/agent/scripted_agents.py | 9 +- src/primaite/game/agent/utils.py | 5 +- src/primaite/game/session.py | 28 +- 9 files changed, 600 insertions(+), 91 deletions(-) diff --git a/sandbox.py b/sandbox.py index 8114c23a..ab5e701f 100644 --- a/sandbox.py +++ b/sandbox.py @@ -1,19 +1,22 @@ - -from primaite.game.session import PrimaiteSession +# flake8: noqa +import logging from primaite import _PRIMAITE_CONFIG, PRIMAITE_PATHS -import logging -_PRIMAITE_CONFIG['log_level']=logging.DEBUG +from primaite.game.session import PrimaiteSession + +_PRIMAITE_CONFIG["log_level"] = logging.DEBUG print(PRIMAITE_PATHS.app_log_dir_path) import itertools -from primaite.game.session import PrimaiteSession -from primaite.simulator.sim_container import Simulation -from primaite.game.agent.interface import AbstractAgent -from primaite.simulator.network.networks import arcd_uc2_network + import yaml -with open('example_config.yaml', 'r') as file: +from primaite.game.agent.interface import AbstractAgent +from primaite.game.session import PrimaiteSession +from primaite.simulator.network.networks import arcd_uc2_network +from primaite.simulator.sim_container import Simulation + +with open("example_config.yaml", "r") as file: cfg = yaml.safe_load(file) sess = PrimaiteSession.from_config(cfg) -sess.start_session() \ No newline at end of file +sess.start_session() diff --git a/src/primaite/game/agent/GATE_agents.py b/src/primaite/game/agent/GATE_agents.py index eb3c2987..e50d7831 100644 --- a/src/primaite/game/agent/GATE_agents.py +++ b/src/primaite/game/agent/GATE_agents.py @@ -1,9 +1,13 @@ +# flake8: noqa from typing import Dict, Optional, Tuple + +from gymnasium.core import ActType, ObsType + from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractGATEAgent, ObsType from primaite.game.agent.observations import ObservationSpace from primaite.game.agent.rewards import RewardFunction -from gymnasium.core import ActType, ObsType + class GATERLAgent(AbstractGATEAgent): ... @@ -13,9 +17,15 @@ class GATERLAgent(AbstractGATEAgent): # For example MultiAgentEnv in Ray allows sending a dict of observations of multiple agents, then it will reply # with the actions for those agents. - def __init__(self, agent_name: str | None, action_space: ActionManager | None, observation_space: ObservationSpace | None, reward_function: RewardFunction | None) -> None: + def __init__( + self, + agent_name: str | None, + action_space: ActionManager | None, + observation_space: ObservationSpace | None, + reward_function: RewardFunction | None, + ) -> None: super().__init__(agent_name, action_space, observation_space, reward_function) self.most_recent_action: ActType def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: - return self.most_recent_action \ No newline at end of file + return self.most_recent_action diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 4c4aaab4..0a380487 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -695,14 +695,14 @@ class ActionManager: return {i: p for i, p in enumerate(all_action_possibilities)} def get_action(self, action: int) -> Tuple[str, Dict]: - """Produce action in CAOS format""" + """Produce action in CAOS format.""" """the agent chooses an action (as an integer), this is converted into an action in CAOS format""" """The caos format is basically a action identifier, followed by parameters stored in a dictionary""" act_identifier, act_options = self.action_map[action] return act_identifier, act_options - def form_request(self, action_identifier: str, action_options: Dict): - """Take action in CAOS format and use the execution definition to change it into PrimAITE request format""" + def form_request(self, action_identifier: str, action_options: Dict) -> List[str]: + """Take action in CAOS format and use the execution definition to change it into PrimAITE request format.""" act_obj = self.actions[action_identifier] return act_obj.form_request(**action_options) @@ -712,7 +712,8 @@ class ActionManager: return spaces.Discrete(len(self.action_map)) def get_node_uuid_by_idx(self, node_idx: int) -> str: - """Get the node UUID corresponding to the given index. + """ + Get the node UUID corresponding to the given index. :param node_idx: The index of the node to retrieve. :type node_idx: int @@ -722,7 +723,8 @@ class ActionManager: return self.node_uuids[node_idx] def get_folder_uuid_by_idx(self, node_idx: int, folder_idx: int) -> Optional[str]: - """Get the folder UUID corresponding to the given node and folder indices. + """ + Get the folder UUID corresponding to the given node and folder indices. :param node_idx: The index of the node. :type node_idx: int @@ -731,7 +733,6 @@ class ActionManager: :return: The UUID of the folder. Or None if the node has fewer folders than the given index. :rtype: Optional[str] """ - node_uuid = self.get_node_uuid_by_idx(node_idx) node = self.sim.network.nodes[node_uuid] folder_uuids = list(node.file_system.folders.keys()) diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 5f121fcc..89f27f3f 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -1,6 +1,6 @@ """Interface for agents.""" from abc import ABC, abstractmethod -from typing import Any, Dict, List, Optional, Tuple, TypeAlias, Union +from typing import Dict, List, Optional, Tuple, TypeAlias, Union import numpy as np @@ -21,6 +21,18 @@ class AbstractAgent(ABC): observation_space: Optional[ObservationSpace], reward_function: Optional[RewardFunction], ) -> None: + """ + Initialize an agent. + + :param agent_name: Unique string identifier for the agent, for reporting and multi-agent purposes. + :type agent_name: Optional[str] + :param action_space: Action space for the agent. + :type action_space: Optional[ActionManager] + :param observation_space: Observation space for the agent. + :type observation_space: Optional[ObservationSpace] + :param reward_function: Reward function for the agent. + :type reward_function: Optional[RewardFunction] + """ self.agent_name: str = agent_name or "unnamed_agent" self.action_space: Optional[ActionManager] = action_space self.observation_space: Optional[ObservationSpace] = observation_space @@ -32,16 +44,38 @@ class AbstractAgent(ABC): def convert_state_to_obs(self, state: Dict) -> ObsType: """ + Convert a state from the simulator into an observation for the agent using the observation space. + state : dict state directly from simulation.describe_state output : dict state according to CAOS. """ return self.observation_space.observe(state) def calculate_reward_from_state(self, state: Dict) -> float: + """ + Use the reward function to calculate a reward from the state. + + :param state: State of the environment. + :type state: Dict + :return: Reward from the state. + :rtype: float + """ return self.reward_function.calculate(state) @abstractmethod def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: + """ + Return an action to be taken in the environment. + + Subclasses should implement agent logic here. It should use the observation as input to decide best next action. + + :param obs: Observation of the environment. + :type obs: ObsType + :param reward: Reward from the previous action, defaults to None TODO: should this parameter even be accepted? + :type reward: float, optional + :return: Action to be taken in the environment. + :rtype: Tuple[str, Dict] + """ # in RL agent, this method will send CAOS observation to GATE RL agent, then receive a int 0-39, # then use a bespoke conversion to take 1-40 int back into CAOS action return ("DO_NOTHING", {}) @@ -64,6 +98,15 @@ class RandomAgent(AbstractScriptedAgent): """Agent that ignores its observation and acts completely at random.""" def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: + """Randomly sample an action from the action space. + + :param obs: _description_ + :type obs: ObsType + :param reward: _description_, defaults to None + :type reward: float, optional + :return: _description_ + :rtype: Tuple[str, Dict] + """ return self.action_space.get_action(self.action_space.space.sample()) diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index ba1e8e66..af398fc9 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -1,12 +1,12 @@ +"""Manages the observation space for the agent.""" from abc import ABC, abstractmethod -from typing import Any, Dict, Hashable, List, Optional, Sequence, Tuple, TYPE_CHECKING +from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium import spaces -from pydantic import BaseModel -from primaite.simulator.sim_container import Simulation -from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE from primaite import getLogger +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE + _LOGGER = getLogger(__name__) if TYPE_CHECKING: @@ -14,22 +14,25 @@ if TYPE_CHECKING: class AbstractObservation(ABC): + """Abstract class for an observation space component.""" + @abstractmethod def observe(self, state: Dict) -> Any: - """_summary_ + """ + Return an observation based on the current state of the simulation. - :param state: _description_ + :param state: Simulation state dictionary :type state: Dict - :return: _description_ + :return: Observation :rtype: Any """ - ... + pass @property @abstractmethod def space(self) -> spaces.Space: - """Subclasses must define the shape that they expect""" - ... + """Gymnasium space object describing the observation space.""" + pass @classmethod @abstractmethod @@ -39,12 +42,15 @@ class AbstractObservation(ABC): The `session` parameter is for a the PrimaiteSession object that spawns this component. During deserialisation, a subclass of this class may need to translate from a 'reference' to a UUID. """ + pass class FileObservation(AbstractObservation): + """Observation of a file on a node in the network.""" + def __init__(self, where: Optional[Tuple[str]] = None) -> None: """ - _summary_ + Initialise file observation. :param where: Store information about where in the simulation state dictionary to find the relevatn information. Optional. If None, this corresponds that the file does not exist and the observation will be populated with @@ -60,6 +66,13 @@ class FileObservation(AbstractObservation): "Default observation is what should be returned when the file doesn't exist, e.g. after it has been deleted." def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ if self.where is None: return self.default_observation file_state = access_from_nested_dict(state, self.where) @@ -69,19 +82,38 @@ class FileObservation(AbstractObservation): @property def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape. + + :return: Gymnasium space + :rtype: spaces.Space + """ return spaces.Dict({"health_status": spaces.Discrete(6)}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where=None): + def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where: List[str] = None) -> "FileObservation": + """Create file observation from a config. + + :param config: Dictionary containing the configuration for this file observation. + :type config: Dict + :param session: _description_ + :type session: PrimaiteSession + :param parent_where: _description_, defaults to None + :type parent_where: _type_, optional + :return: _description_ + :rtype: _type_ + """ return cls(where=parent_where + ["files", config["file_name"]]) class ServiceObservation(AbstractObservation): + """Observation of a service in the network.""" + default_observation: spaces.Space = {"operating_status": 0, "health_status": 0} "Default observation is what should be returned when the service doesn't exist." def __init__(self, where: Optional[Tuple[str]] = None) -> None: - """ + """Initialise service observation. + :param where: Store information about where in the simulation state dictionary to find the relevant information. Optional. If None, this corresponds that the file does not exist and the observation will be populated with zeroes. @@ -94,6 +126,13 @@ class ServiceObservation(AbstractObservation): self.where: Optional[Tuple[str]] = where def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ if self.where is None: return self.default_observation @@ -104,19 +143,36 @@ class ServiceObservation(AbstractObservation): @property def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(6)}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]] = None): + def from_config( + cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]] = None + ) -> "ServiceObservation": + """Create service observation from a config. + + :param config: Dictionary containing the configuration for this service observation. + :type config: Dict + :param session: Reference to the PrimaiteSession object that spawned this observation. + :type session: PrimaiteSession + :param parent_where: Where in the simulation state dictionary this service's parent node is located. Optional. + :type parent_where: Optional[List[str]], optional + :return: Constructed service observation + :rtype: ServiceObservation + """ return cls(where=parent_where + ["services", session.ref_map_services[config["service_ref"]].uuid]) class LinkObservation(AbstractObservation): + """Observation of a link in the network.""" + default_observation: spaces.Space = {"protocols": {"all": {"load": 0}}} "Default observation is what should be returned when the link doesn't exist." def __init__(self, where: Optional[Tuple[str]] = None) -> None: - """ + """Initialise link observation. + :param where: Store information about where in the simulation state dictionary to find the relevant information. Optional. If None, this corresponds that the file does not exist and the observation will be populated with zeroes. @@ -129,6 +185,13 @@ class LinkObservation(AbstractObservation): self.where: Optional[Tuple[str]] = where def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ if self.where is None: return self.default_observation @@ -147,15 +210,33 @@ class LinkObservation(AbstractObservation): @property def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape. + + :return: Gymnasium space + :rtype: spaces.Space + """ return spaces.Dict({"protocols": spaces.Dict({"all": spaces.Dict({"load": spaces.Discrete(11)})})}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession"): + def from_config(cls, config: Dict, session: "PrimaiteSession") -> "LinkObservation": + """Create link observation from a config. + + :param config: Dictionary containing the configuration for this link observation. + :type config: Dict + :param session: Reference to the PrimaiteSession object that spawned this observation. + :type session: PrimaiteSession + :return: Constructed link observation + :rtype: LinkObservation + """ return cls(where=["network", "links", session.ref_map_links[config["link_ref"]]]) class FolderObservation(AbstractObservation): - def __init__(self, where: Optional[Tuple[str]] = None, files: List[FileObservation] = [], num_files_per_folder:int=2) -> None: + """Folder observation, including files inside of the folder.""" + + def __init__( + self, where: Optional[Tuple[str]] = None, files: List[FileObservation] = [], num_files_per_folder: int = 2 + ) -> None: """Initialise folder Observation, including files inside of the folder. :param where: Where in the simulation state dictionary to find the relevant information for this folder. @@ -179,7 +260,7 @@ class FolderObservation(AbstractObservation): self.files: List[FileObservation] = files while len(self.files) < num_files_per_folder: self.files.append(FileObservation()) - while len(self.files)> num_files_per_folder: + while len(self.files) > num_files_per_folder: truncated_file = self.files.pop() msg = f"Too many files in folde observation. Truncating file {truncated_file}" _LOGGER.warn(msg) @@ -191,6 +272,13 @@ class FolderObservation(AbstractObservation): } def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ if self.where is None: return self.default_observation folder_state = access_from_nested_dict(state, self.where) @@ -208,6 +296,11 @@ class FolderObservation(AbstractObservation): @property def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape. + + :return: Gymnasium space + :rtype: spaces.Space + """ return spaces.Dict( { "health_status": spaces.Discrete(6), @@ -216,7 +309,26 @@ class FolderObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]], num_files_per_folder:int=2): + def from_config( + cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]], num_files_per_folder: int = 2 + ) -> "FolderObservation": + """Create folder observation from a config. Also creates child file observations. + + :param config: Dictionary containing the configuration for this folder observation. Includes the name of the + folder and the files inside of it. + :type config: Dict + :param session: Reference to the PrimaiteSession object that spawned this observation. + :type session: PrimaiteSession + :param parent_where: Where in the simulation state dictionary to find the information about this folder's + parent node. A typical location for a node ``where`` can be: + ['network','nodes',,'file_system'] + :type parent_where: Optional[List[str]] + :param num_files_per_folder: How many spaces for files are in this folder observation (to preserve static + observation size) , defaults to 2 + :type num_files_per_folder: int, optional + :return: Constructed folder observation + :rtype: FolderObservation + """ where = parent_where + ["folders", config["folder_name"]] file_configs = config["files"] @@ -226,13 +338,30 @@ class FolderObservation(AbstractObservation): class NicObservation(AbstractObservation): + """Observation of a Network Interface Card (NIC) in the network.""" + default_observation: spaces.Space = {"nic_status": 0} def __init__(self, where: Optional[Tuple[str]] = None) -> None: + """Initialise NIC observation. + + :param where: Where in the simulation state dictionary to find the relevant information for this NIC. A typical + example may look like this: + ['network','nodes',,'NICs',] + If None, this denotes that the NIC does not exist and the observation will be populated with zeroes. + :type where: Optional[Tuple[str]], optional + """ super().__init__() self.where: Optional[Tuple[str]] = where def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ if self.where is None: return self.default_observation nic_state = access_from_nested_dict(state, self.where) @@ -243,14 +372,31 @@ class NicObservation(AbstractObservation): @property def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" return spaces.Dict({"nic_status": spaces.Discrete(3)}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]]): + def from_config( + cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]] + ) -> "NicObservation": + """Create NIC observation from a config. + + :param config: Dictionary containing the configuration for this NIC observation. + :type config: Dict + :param session: Reference to the PrimaiteSession object that spawned this observation. + :type session: PrimaiteSession + :param parent_where: Where in the simulation state dictionary to find the information about this NIC's parent + node. A typical location for a node ``where`` can be: ['network','nodes',] + :type parent_where: Optional[List[str]] + :return: Constructed NIC observation + :rtype: NicObservation + """ return cls(where=parent_where + ["NICs", config["nic_uuid"]]) class NodeObservation(AbstractObservation): + """Observation of a node in the network. Includes services, folders and NICs.""" + def __init__( self, where: Optional[Tuple[str]] = None, @@ -260,8 +406,8 @@ class NodeObservation(AbstractObservation): logon_status: bool = False, num_services_per_node: int = 2, num_folders_per_node: int = 2, - num_files_per_folder: int = 2 - ) -> None: + num_files_per_folder: int = 2, + ) -> None: """ Configurable observation for a node in the simulation. @@ -271,7 +417,8 @@ class NodeObservation(AbstractObservation): :type where: List[str], optional :param services: Mapping between position in observation space and service UUID, defaults to {} :type services: Dict[int,str], optional - :param max_services: Max number of services that can be presented in observation space for this node, defaults to 2 + :param max_services: Max number of services that can be presented in observation space for this node + , defaults to 2 :type max_services: int, optional :param folders: Mapping between position in observation space and folder name, defaults to {} :type folders: Dict[int,str], optional @@ -286,10 +433,10 @@ class NodeObservation(AbstractObservation): self.where: Optional[Tuple[str]] = where self.services: List[ServiceObservation] = services - while len(self.services)num_services_per_node: + while len(self.services) > num_services_per_node: truncated_service = self.services.pop() msg = f"Too many services in Node observation space for node. Truncating service {truncated_service.where}" _LOGGER.warn(msg) @@ -297,8 +444,8 @@ class NodeObservation(AbstractObservation): # truncate service list self.folders: List[FolderObservation] = folders + # add empty folder observation without `where` parameter that will always return default (blank) observations while len(self.folders) < num_folders_per_node: - # add an empty folder observation without `where` parameter that will always return default (blank) observations self.folders.append(FolderObservation()) while len(self.folders) > num_folders_per_node: truncated_folder = self.folders.pop() @@ -317,6 +464,13 @@ class NodeObservation(AbstractObservation): self.default_observation["logon_status"] = 0 def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ if self.where is None: return self.default_observation @@ -337,6 +491,7 @@ class NodeObservation(AbstractObservation): @property def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" space_shape = { "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), @@ -358,6 +513,27 @@ class NodeObservation(AbstractObservation): num_folders_per_node: int = 2, num_files_per_folder: int = 2, ) -> "NodeObservation": + """Create node observation from a config. Also creates child service, folder and NIC observations. + + :param config: Dictionary containing the configuration for this node observation. + :type config: Dict + :param session: Reference to the PrimaiteSession object that spawned this observation. + :type session: PrimaiteSession + :param parent_where: Where in the simulation state dictionary to find the information about this node's parent + network. A typical location for it would be: ['network',] + :type parent_where: Optional[List[str]] + :param num_services_per_node: How many spaces for services are in this node observation (to preserve static + observation size) , defaults to 2 + :type num_services_per_node: int, optional + :param num_folders_per_node: How many spaces for folders are in this node observation (to preserve static + observation size) , defaults to 2 + :type num_folders_per_node: int, optional + :param num_files_per_folder: How many spaces for files are in the folder observations (to preserve static + observation size) , defaults to 2 + :type num_files_per_folder: int, optional + :return: Constructed node observation + :rtype: NodeObservation + """ node_uuid = session.ref_map_nodes[config["node_ref"]] if parent_where is None: where = ["network", "nodes", node_uuid] @@ -367,7 +543,12 @@ class NodeObservation(AbstractObservation): svc_configs = config.get("services", {}) services = [ServiceObservation.from_config(config=c, session=session, parent_where=where) for c in svc_configs] folder_configs = config.get("folders", {}) - folders = [FolderObservation.from_config(config=c, session=session, parent_where=where, num_files_per_folder=num_files_per_folder) for c in folder_configs] + folders = [ + FolderObservation.from_config( + config=c, session=session, parent_where=where, num_files_per_folder=num_files_per_folder + ) + for c in folder_configs + ] nic_uuids = session.simulation.network.nodes[node_uuid].nics.keys() nic_configs = [{"nic_uuid": n for n in nic_uuids}] if nic_uuids else [] nics = [NicObservation.from_config(config=c, session=session, parent_where=where) for c in nic_configs] @@ -378,13 +559,15 @@ class NodeObservation(AbstractObservation): folders=folders, nics=nics, logon_status=logon_status, - num_services_per_node = num_services_per_node, - num_folders_per_node = num_folders_per_node, - num_files_per_folder = num_files_per_folder, - ) + num_services_per_node=num_services_per_node, + num_folders_per_node=num_folders_per_node, + num_files_per_folder=num_files_per_folder, + ) class AclObservation(AbstractObservation): + """Observation of an Access Control List (ACL) in the network.""" + # TODO: should where be optional, and we can use where=None to pad the observation space? # definitely the current approach does not support tracking files that aren't specified by name, for example # if a file is created at runtime, we have currently got no way of telling the observation space to track it. @@ -397,6 +580,21 @@ class AclObservation(AbstractObservation): where: Optional[Tuple[str]] = None, num_rules: int = 10, ) -> None: + """Initialise ACL observation. + + :param node_ip_to_id: Mapping between IP address and ID. + :type node_ip_to_id: Dict[str, int] + :param ports: List of ports which are part of the game that define the ordering when converting to an ID + :type ports: List[int] + :param protocols: List of protocols which are part of the game, defines ordering when converting to an ID + :type protocols: list[str] + :param where: Where in the simulation state dictionary to find the relevant information for this ACL. A typical + example may look like this: + ['network','nodes',,'acl','acl'] + :type where: Optional[Tuple[str]], optional + :param num_rules: , defaults to 10 + :type num_rules: int, optional + """ super().__init__() self.where: Optional[Tuple[str]] = where self.num_rules: int = num_rules @@ -423,6 +621,13 @@ class AclObservation(AbstractObservation): } def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ if self.where is None: return self.default_observation acl_state: Dict = access_from_nested_dict(state, self.where) @@ -457,6 +662,11 @@ class AclObservation(AbstractObservation): @property def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape. + + :return: Gymnasium space + :rtype: spaces.Space + """ return spaces.Dict( { "RULES": spaces.Dict( @@ -482,6 +692,15 @@ class AclObservation(AbstractObservation): @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession") -> "AclObservation": + """Generate ACL observation from a config. + + :param config: Dictionary containing the configuration for this ACL observation. + :type config: Dict + :param session: Reference to the PrimaiteSession object that spawned this observation. + :type session: PrimaiteSession + :return: Observation object + :rtype: AclObservation + """ node_ip_to_idx = {} for ip_idx, ip_map_config in enumerate(config["ip_address_order"]): node_ref = ip_map_config["node_ref"] @@ -500,26 +719,44 @@ class AclObservation(AbstractObservation): class NullObservation(AbstractObservation): + """Null observation, returns a single 0 value for the observation space.""" + def __init__(self, where: Optional[List[str]] = None): + """Initialise null observation.""" self.default_observation: Dict = {} def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation.""" return 0 @property def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" return spaces.Discrete(1) @classmethod def from_config(cls, config: Dict, session: Optional["PrimaiteSession"] = None) -> "NullObservation": + """ + Create null observation from a config. + + The parameters are ignored, they are here to match the signature of the other observation classes. + """ return cls() class ICSObservation(NullObservation): + """ICS observation placeholder, currently not implemented so always returns a single 0.""" + pass class UC2BlueObservation(AbstractObservation): + """Container for all observations used by the blue agent in UC2. + + TODO: there's no real need for a UC2 blue container class, we should be able to simply use the observation handler + for the purpose of compiling several observation components. + """ + def __init__( self, nodes: List[NodeObservation], @@ -528,6 +765,20 @@ class UC2BlueObservation(AbstractObservation): ics: ICSObservation, where: Optional[List[str]] = None, ) -> None: + """Initialise UC2 blue observation. + + :param nodes: List of node observations + :type nodes: List[NodeObservation] + :param links: List of link observations + :type links: List[LinkObservation] + :param acl: The Access Control List observation + :type acl: AclObservation + :param ics: The ICS observation + :type ics: ICSObservation + :param where: Where in the simulation state dict to find information. Not used in this particular observation + because it only compiles other observations and doesn't contribute any new information, defaults to None + :type where: Optional[List[str]], optional + """ super().__init__() self.where: Optional[Tuple[str]] = where @@ -544,6 +795,13 @@ class UC2BlueObservation(AbstractObservation): } def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ if self.where is None: return self.default_observation @@ -557,6 +815,12 @@ class UC2BlueObservation(AbstractObservation): @property def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Space + :rtype: spaces.Space + """ return spaces.Dict( { "NODES": spaces.Dict({i + 1: node.space for i, node in enumerate(self.nodes)}), @@ -567,21 +831,34 @@ class UC2BlueObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession"): + def from_config(cls, config: Dict, session: "PrimaiteSession") -> "UC2BlueObservation": + """Create UC2 blue observation from a config. + + :param config: Dictionary containing the configuration for this UC2 blue observation. This includes the nodes, + links, ACL and ICS observations. + :type config: Dict + :param session: Reference to the PrimaiteSession object that spawned this observation. + :type session: PrimaiteSession + :return: Constructed UC2 blue observation + :rtype: UC2BlueObservation + """ node_configs = config["nodes"] num_services_per_node = config["num_services_per_node"] num_folders_per_node = config["num_folders_per_node"] num_files_per_folder = config["num_files_per_folder"] - nodes = [NodeObservation.from_config( - config=n, - session=session, - num_services_per_node= num_services_per_node, - num_folders_per_node=num_folders_per_node, - num_files_per_folder=num_files_per_folder, - ) for n in node_configs] + nodes = [ + NodeObservation.from_config( + config=n, + session=session, + num_services_per_node=num_services_per_node, + num_folders_per_node=num_folders_per_node, + num_files_per_folder=num_files_per_folder, + ) + for n in node_configs + ] link_configs = config["links"] - links = [LinkObservation.from_config(config=l, session=session) for l in link_configs] + links = [LinkObservation.from_config(config=link, session=session) for link in link_configs] acl_config = config["acl"] acl = AclObservation.from_config(config=acl_config, session=session) @@ -593,6 +870,8 @@ class UC2BlueObservation(AbstractObservation): class UC2RedObservation(AbstractObservation): + """Container for all observations used by the red agent in UC2.""" + def __init__(self, nodes: List[NodeObservation], where: Optional[List[str]] = None) -> None: super().__init__() self.where: Optional[List[str]] = where @@ -603,6 +882,7 @@ class UC2RedObservation(AbstractObservation): } def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation.""" if self.where is None: return self.default_observation @@ -612,6 +892,7 @@ class UC2RedObservation(AbstractObservation): @property def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" return spaces.Dict( { "NODES": spaces.Dict({i + 1: node.space for i, node in enumerate(self.nodes)}), @@ -619,43 +900,74 @@ class UC2RedObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession"): + def from_config(cls, config: Dict, session: "PrimaiteSession") -> "UC2RedObservation": + """ + Create UC2 red observation from a config. + + :param config: Dictionary containing the configuration for this UC2 red observation. + :type config: Dict + :param session: Reference to the PrimaiteSession object that spawned this observation. + :type session: PrimaiteSession + """ node_configs = config["nodes"] nodes = [NodeObservation.from_config(config=cfg, session=session) for cfg in node_configs] return cls(nodes=nodes, where=["network"]) class UC2GreenObservation(NullObservation): + """Green agent observation. As the green agent's actions don't depend on the observation, this is empty.""" + pass class ObservationSpace: """ - Manage the observations of an Actor. + Manage the observations of an Agent. The observation space has the purpose of: 1. Reading the outputted state from the PrimAITE Simulation. 2. Selecting parts of the simulation state that are requested by the simulation config - 3. Formatting this information so an actor can use it to make decisions. + 3. Formatting this information so an agent can use it to make decisions. """ - ... + # TODO: Dear code reader: This class currently doesn't do much except hold an observation object. It will be changed + # to have more of it's own behaviour, and it will replace UC2BlueObservation and UC2RedObservation during the next + # refactor. - # what this class does: - # keep a list of observations - # create observations for an actor from the config def __init__(self, observation: AbstractObservation) -> None: + """Initialise observation space. + + :param observation: Observation object + :type observation: AbstractObservation + """ self.obs: AbstractObservation = observation - def observe(self, state) -> Dict: + def observe(self, state: Dict) -> Dict: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + """ return self.obs.observe(state) @property def space(self) -> None: + """Gymnasium space object describing the observation space shape.""" return self.obs.space @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession") -> "ObservationSpace": + """Create observation space from a config. + + :param config: Dictionary containing the configuration for this observation space. + It should contain the key 'type' which selects which observation class to use (from a choice of: + UC2BlueObservation, UC2RedObservation, UC2GreenObservation) + The other key is 'options' which are passed to the constructor of the selected observation class. + :type config: Dict + :param session: Reference to the PrimaiteSession object that spawned this observation. + :type session: PrimaiteSession + """ if config["type"] == "UC2BlueObservation": return cls(UC2BlueObservation.from_config(config.get("options", {}), session=session)) elif config["type"] == "UC2RedObservation": diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 67e6ee50..03c4e2d3 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -1,8 +1,35 @@ -from abc import ABC, abstractmethod -from typing import Any, Dict, List, Tuple, TYPE_CHECKING +""" +Manages the reward function for the agent. + +Each agent is equipped with a RewardFunction, which is made up of a list of reward components. The components are +designed to calculate a reward value based on the current state of the simulation. The overall reward function is a +weighed sum of the components. + +The reward function is typically specified using a config yaml file or a config dictionary. The following example shows +the structure: +```yaml + reward_function: + reward_components: + - type: DATABASE_FILE_INTEGRITY + weight: 0.5 + options: + node_ref: database_server + folder_name: database + file_name: database.db + + + - type: WEB_SERVER_404_PENALTY + weight: 0.5 + options: + node_ref: web_server + service_ref: web_server_database_client +``` +""" +from abc import abstractmethod +from typing import Dict, List, Tuple, TYPE_CHECKING from primaite import getLogger -from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +from primaite.game.agent.utils import access_from_nested_dict _LOGGER = getLogger(__name__) @@ -11,27 +38,60 @@ if TYPE_CHECKING: class AbstractReward: + """Base class for reward function components.""" + @abstractmethod def calculate(self, state: Dict) -> float: + """Calculate the reward for the current state.""" return 0.0 @classmethod @abstractmethod def from_config(cls, config: dict, session: "PrimaiteSession") -> "AbstractReward": + """Create a reward function component from a config dictionary. + + :param config: dict of options for the reward component's constructor + :type config: dict + :param session: Reference to the PrimAITE Session object + :type session: PrimaiteSession + :return: The reward component. + :rtype: AbstractReward + """ return cls() class DummyReward(AbstractReward): + """Dummy reward function component which always returns 0.""" + def calculate(self, state: Dict) -> float: + """Calculate the reward for the current state.""" return 0.0 @classmethod def from_config(cls, config: dict, session: "PrimaiteSession") -> "DummyReward": + """Create a reward function component from a config dictionary. + + :param config: dict of options for the reward component's constructor. Should be empty. + :type config: dict + :param session: Reference to the PrimAITE Session object + :type session: PrimaiteSession + """ return cls() class DatabaseFileIntegrity(AbstractReward): + """Reward function component which rewards the agent for maintaining the integrity of a database file.""" + def __init__(self, node_uuid: str, folder_name: str, file_name: str) -> None: + """Initialise the reward component. + + :param node_uuid: UUID of the node which contains the database file. + :type node_uuid: str + :param folder_name: folder which contains the database file. + :type folder_name: str + :param file_name: name of the database file. + :type file_name: str + """ self.location_in_state = [ "network", "nodes", @@ -44,6 +104,11 @@ class DatabaseFileIntegrity(AbstractReward): ] def calculate(self, state: Dict) -> float: + """Calculate the reward for the current state. + + :param state: The current state of the simulation. + :type state: Dict + """ database_file_state = access_from_nested_dict(state, self.location_in_state) health_status = database_file_state["health_status"] if health_status == "corrupted": @@ -55,6 +120,15 @@ class DatabaseFileIntegrity(AbstractReward): @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession") -> "DatabaseFileIntegrity": + """Create a reward function component from a config dictionary. + + :param config: dict of options for the reward component's constructor + :type config: Dict + :param session: Reference to the PrimAITE Session object + :type session: PrimaiteSession + :return: The reward component. + :rtype: DatabaseFileIntegrity + """ node_ref = config.get("node_ref") folder_name = config.get("folder_name") file_name = config.get("file_name") @@ -76,7 +150,10 @@ class DatabaseFileIntegrity(AbstractReward): node_uuid = session.ref_map_nodes[node_ref] if not node_uuid: _LOGGER.error( - f"{cls.__name__} could not be initialised from config because the referenced node could not be found in the simulation" + ( + f"{cls.__name__} could not be initialised from config because the referenced node could not be " + f"found in the simulation" + ) ) return DummyReward() # TODO: better error handling @@ -84,10 +161,24 @@ class DatabaseFileIntegrity(AbstractReward): class WebServer404Penalty(AbstractReward): + """Reward function component which penalises the agent when the web server returns a 404 error.""" + def __init__(self, node_uuid: str, service_uuid: str) -> None: + """Initialise the reward component. + + :param node_uuid: UUID of the node which contains the web server service. + :type node_uuid: str + :param service_uuid: UUID of the web server service. + :type service_uuid: str + """ self.location_in_state = ["network", "nodes", node_uuid, "services", service_uuid] def calculate(self, state: Dict) -> float: + """Calculate the reward for the current state. + + :param state: The current state of the simulation. + :type state: Dict + """ web_service_state = access_from_nested_dict(state, self.location_in_state) most_recent_return_code = web_service_state["most_recent_return_code"] # TODO: reward needs to use the current web state. Observation should return web state at the time of last scan. @@ -100,16 +191,31 @@ class WebServer404Penalty(AbstractReward): @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession") -> "WebServer404Penalty": + """Create a reward function component from a config dictionary. + + :param config: dict of options for the reward component's constructor + :type config: Dict + :param session: Reference to the PrimAITE Session object + :type session: PrimaiteSession + :return: The reward component. + :rtype: WebServer404Penalty + """ node_ref = config.get("node_ref") service_ref = config.get("service_ref") if not (node_ref and service_ref): - msg = f"{cls.__name__} could not be initialised from config because node_ref and service_ref were not found in reward config." + msg = ( + f"{cls.__name__} could not be initialised from config because node_ref and service_ref were not " + "found in reward config." + ) _LOGGER.warn(msg) return DummyReward() # TODO: should we error out with incorrect inputs? Probably! node_uuid = session.ref_map_nodes[node_ref] service_uuid = session.ref_map_services[service_ref].uuid if not (node_uuid and service_uuid): - msg = f"{cls.__name__} could not be initialised because node {node_ref} and service {service_ref} were not found in the simulator." + msg = ( + f"{cls.__name__} could not be initialised because node {node_ref} and service {service_ref} were not" + " found in the simulator." + ) _LOGGER.warn(msg) return DummyReward() # TODO: consider erroring here as well @@ -117,6 +223,8 @@ class WebServer404Penalty(AbstractReward): class RewardFunction: + """Manages the reward function for the agent.""" + __rew_class_identifiers: Dict[str, type[AbstractReward]] = { "DUMMY": DummyReward, "DATABASE_FILE_INTEGRITY": DatabaseFileIntegrity, @@ -124,13 +232,26 @@ class RewardFunction: } def __init__(self): + """Initialise the reward function object.""" self.reward_components: List[Tuple[AbstractReward, float]] = [] "attribute reward_components keeps track of reward components and the weights assigned to each." def regsiter_component(self, component: AbstractReward, weight: float = 1.0) -> None: + """Add a reward component to the reward function. + + :param component: Instance of a reward component. + :type component: AbstractReward + :param weight: Relative weight of the reward component, defaults to 1.0 + :type weight: float, optional + """ self.reward_components.append((component, weight)) def calculate(self, state: Dict) -> float: + """Calculate the overall reward for the current state. + + :param state: The current state of the simulation. + :type state: Dict + """ total = 0.0 for comp_and_weight in self.reward_components: comp = comp_and_weight[0] @@ -140,6 +261,15 @@ class RewardFunction: @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession") -> "RewardFunction": + """Create a reward function from a config dictionary. + + :param config: dict of options for the reward manager's constructor + :type config: Dict + :param session: Reference to the PrimAITE Session object + :type session: PrimaiteSession + :return: The reward manager. + :rtype: RewardFunction + """ new = cls() for rew_component_cfg in config["reward_components"]: diff --git a/src/primaite/game/agent/scripted_agents.py b/src/primaite/game/agent/scripted_agents.py index d3becd57..3748494b 100644 --- a/src/primaite/game/agent/scripted_agents.py +++ b/src/primaite/game/agent/scripted_agents.py @@ -1,9 +1,14 @@ +"""Agents with predefined behaviours.""" from primaite.game.agent.interface import AbstractScriptedAgent class GreenWebBrowsingAgent(AbstractScriptedAgent): - ... + """Scripted agent which attempts to send web requests to a target node.""" + + raise NotImplementedError class RedDatabaseCorruptingAgent(AbstractScriptedAgent): - ... + """Scripted agent which attempts to corrupt the database of the target node.""" + + raise NotImplementedError diff --git a/src/primaite/game/agent/utils.py b/src/primaite/game/agent/utils.py index ad6dbefe..1314087c 100644 --- a/src/primaite/game/agent/utils.py +++ b/src/primaite/game/agent/utils.py @@ -1,4 +1,4 @@ -from typing import Dict, Sequence, Hashable, Any +from typing import Any, Dict, Hashable, Sequence NOT_PRESENT_IN_STATE = object() """ @@ -6,6 +6,7 @@ Need an object to return when the sim state does not contain a requested value. the thing requested in the state could equal None. This NOT_PRESENT_IN_STATE is a sentinel for this purpose. """ + def access_from_nested_dict(dictionary: Dict, keys: Sequence[Hashable]) -> Any: """ Access an item from a deeply dictionary with a list of keys. @@ -26,4 +27,4 @@ def access_from_nested_dict(dictionary: Dict, keys: Sequence[Hashable]) -> Any: k = key_list.pop(0) if k not in dictionary: return NOT_PRESENT_IN_STATE - return access_from_nested_dict(dictionary[k], key_list) \ No newline at end of file + return access_from_nested_dict(dictionary[k], key_list) diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index f29d03dd..bd5e18d6 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -1,6 +1,6 @@ """PrimAITE session - the main entry point to training agents on PrimAITE.""" from ipaddress import IPv4Address -from typing import Any, Dict, List, Optional, Tuple +from typing import Any, Dict, List, Never, Optional, Tuple from arcd_gate.client.gate_client import ActType, GATEClient from gymnasium import spaces @@ -32,13 +32,17 @@ _LOGGER = getLogger(__name__) class PrimaiteGATEClient(GATEClient): + """Lightweight wrapper around the GATEClient class that allows PrimAITE to message GATE.""" + def __init__(self, parent_session: "PrimaiteSession", service_port: int = 50000): - """Create a new GATE client for PrimAITE. + """ + Create a new GATE client for PrimAITE. :param parent_session: The parent session object. :type parent_session: PrimaiteSession :param service_port: The port on which the GATE service is running. - :type service_port: int, optional""" + :type service_port: int, optional + """ super().__init__(service_port=service_port) self.parent_session: "PrimaiteSession" = parent_session @@ -133,9 +137,11 @@ class PrimaiteGATEClient(GATEClient): class PrimaiteSessionOptions(BaseModel): - """Global options which are applicable to all of the agents in the game. + """ + Global options which are applicable to all of the agents in the game. - Currently this is used to restrict which ports and protocols exist in the world of the simulation.""" + Currently this is used to restrict which ports and protocols exist in the world of the simulation. + """ ports: List[str] protocols: List[str] @@ -154,9 +160,7 @@ class TrainingOptions(BaseModel): class PrimaiteSession: - """ - The main entrypoint for PrimAITE sessions, this coordinates a simulation, agents, and connections to ARCD GATE. - """ + """The main entrypoint for PrimAITE sessions, this manages a simulation, agents, and connections to ARCD GATE.""" def __init__(self): self.simulation: Simulation = Simulation() @@ -183,7 +187,7 @@ class PrimaiteSession: self.gate_client: PrimaiteGATEClient = PrimaiteGATEClient(self) """Reference to a GATE Client object, which will send data to GATE service for training RL agent.""" - def start_session(self, opts="TODO..."): + def start_session(self) -> Never: """Commence the training session, this gives the GATE client control over the simulation/agent loop.""" self.gate_client.start() @@ -221,7 +225,7 @@ class PrimaiteSession: # to discrete(40) is only necessary for purposes of RL learning, therefore that bit of # code should live inside of the GATE agent subclass) # gets action in CAOS format - _LOGGER.debug(f"Getting agent action") + _LOGGER.debug("Getting agent action") agent_action, action_options = agent.get_action(agent_obs, agent_reward) # 9. CAOS action is converted into request (extra information might be needed to enrich # the request, this is what the execution definition is there for) @@ -236,11 +240,11 @@ class PrimaiteSession: self.simulation.apply_timestep(self.step_counter) self.step_counter += 1 - def reset(self): + def reset(self) -> None: """Reset the session, this will reset the simulation.""" return NotImplemented - def close(self): + def close(self) -> None: """Close the session, this will stop the gate client and close the simulation.""" return NotImplemented From 0f24b4a646ae65bc7b1e4afc230133a759dadd06 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 19 Oct 2023 15:34:46 +0100 Subject: [PATCH 236/980] Remove broken import --- src/primaite/game/session.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index bd5e18d6..adb9f7b5 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -1,6 +1,6 @@ """PrimAITE session - the main entry point to training agents on PrimAITE.""" from ipaddress import IPv4Address -from typing import Any, Dict, List, Never, Optional, Tuple +from typing import Any, Dict, List, Optional, Tuple from arcd_gate.client.gate_client import ActType, GATEClient from gymnasium import spaces @@ -187,7 +187,7 @@ class PrimaiteSession: self.gate_client: PrimaiteGATEClient = PrimaiteGATEClient(self) """Reference to a GATE Client object, which will send data to GATE service for training RL agent.""" - def start_session(self) -> Never: + def start_session(self) -> None: """Commence the training session, this gives the GATE client control over the simulation/agent loop.""" self.gate_client.start() From ffc4711afbd2d68caeac872d7544682c755e2aa4 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Fri, 20 Oct 2023 12:58:58 +0100 Subject: [PATCH 237/980] #1947: added test for agent actions + clearing up the implementation of the request managers for filesystem --- .../simulator/file_system/file_system.py | 118 +++------------- tests/conftest.py | 18 ++- .../_file_system/test_file_system_actions.py | 128 ++++++++++++++++++ .../_network/_hardware/test_node_actions.py | 23 ++++ .../_system/_services/test_service_actions.py | 79 +++++++++++ .../_system/_services/test_services.py | 22 +-- 6 files changed, 266 insertions(+), 122 deletions(-) create mode 100644 tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 33781563..1327ad87 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -95,6 +95,18 @@ class FileSystemItemABC(SimComponent): state["previous_hash"] = self.previous_hash return state + def _init_request_manager(self) -> RequestManager: + rm = super()._init_request_manager() + + rm.add_request(name="scan", request_type=RequestType(func=lambda request, context: self.scan())) + rm.add_request(name="checkhash", request_type=RequestType(func=lambda request, context: self.check_hash())) + rm.add_request(name="repair", request_type=RequestType(func=lambda request, context: self.repair())) + rm.add_request(name="restore", request_type=RequestType(func=lambda request, context: self.restore())) + + rm.add_request(name="corrupt", request_type=RequestType(func=lambda request, context: self.corrupt())) + + return rm + @property def size_str(self) -> str: """ @@ -181,110 +193,14 @@ class FileSystem(SimComponent): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() - self._folder_request_manager = self._init_folder_request_manager() + self._folder_request_manager = RequestManager() rm.add_request("folder", RequestType(func=self._folder_request_manager)) - self._file_request_manager = self._init_file_request_manager() + self._file_request_manager = RequestManager() rm.add_request("file", RequestType(func=self._file_request_manager)) return rm - def _init_folder_request_manager(self) -> RequestManager: - rm = RequestManager() - - rm.add_request( - "scan", - RequestType( - func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0], show_deleted=True).scan() - ), - ) - - rm.add_request( - "checkhash", - RequestType(func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]).check_hash()), - ) - - rm.add_request( - "repair", RequestType(func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]).repair()) - ) - - rm.add_request( - "corrupt", - RequestType(func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]).corrupt()), - ) - - rm.add_request( - "delete", RequestType(func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]).delete()) - ) - - rm.add_request( - "restore", - RequestType( - func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0], show_deleted=True).restore() - ), - ) - - return rm - - def _init_file_request_manager(self) -> RequestManager: - rm = RequestManager() - - rm.add_request( - "scan", - RequestType( - func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0], show_deleted=True) - .get_file_by_id(file_uuid=request[1], show_deleted=True) - .scan() - ), - ) - - rm.add_request( - "checkhash", - RequestType( - func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]) - .get_file_by_id(file_uuid=request[1]) - .check_hash() - ), - ) - - rm.add_request( - "repair", - RequestType( - func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]) - .get_file_by_id(file_uuid=request[1]) - .repair() - ), - ) - - rm.add_request( - "corrupt", - RequestType( - func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]) - .get_file_by_id(file_uuid=request[1]) - .corrupt() - ), - ) - - rm.add_request( - "delete", - RequestType( - func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0]) - .get_file_by_id(file_uuid=request[1]) - .delete() - ), - ) - - rm.add_request( - "restore", - RequestType( - func=lambda request, context: self.get_folder_by_id(folder_uuid=request[0], show_deleted=True) - .get_file_by_id(file_uuid=request[1], show_deleted=True) - .restore() - ), - ) - - return rm - @property def size(self) -> int: """ @@ -345,7 +261,9 @@ class FileSystem(SimComponent): self.folders[folder.uuid] = folder self._folders_by_name[folder.name] = folder self.sys_log.info(f"Created folder /{folder.name}") - self._folder_request_manager.add_request(folder.uuid, RequestType(func=folder._request_manager)) + self._folder_request_manager.add_request( + name=folder.uuid, request_type=RequestType(func=folder._request_manager) + ) return folder def delete_folder(self, folder_name: str): @@ -413,7 +331,7 @@ class FileSystem(SimComponent): ) folder.add_file(file) self.sys_log.info(f"Created file /{file.path}") - self._file_request_manager.add_request(file.uuid, RequestType(func=file._request_manager)) + self._file_request_manager.add_request(name=file.uuid, request_type=RequestType(func=file._request_manager)) return file def get_file(self, folder_name: str, file_name: str) -> Optional[File]: diff --git a/tests/conftest.py b/tests/conftest.py index 06e55400..d8c9cc50 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,7 @@ import shutil import tempfile from datetime import datetime from pathlib import Path -from typing import Union +from typing import Any, Union from unittest.mock import patch import pytest @@ -14,7 +14,9 @@ from primaite.environment.primaite_env import Primaite from primaite.primaite_session import PrimaiteSession from primaite.simulator.network.container import Network from primaite.simulator.network.networks import arcd_uc2_network +from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.system.services.service import Service from tests.mock_and_patch.get_session_path_mock import get_temp_session_path ACTION_SPACE_NODE_VALUES = 1 @@ -27,11 +29,25 @@ from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.hardware.base import Node +class TestService(Service): + """Test Service class""" + + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + pass + + @pytest.fixture(scope="function") def uc2_network() -> Network: return arcd_uc2_network() +@pytest.fixture(scope="function") +def service(file_system) -> TestService: + return TestService( + name="TestService", port=Port.ARP, file_system=file_system, sys_log=SysLog(hostname="test_service") + ) + + @pytest.fixture(scope="function") def file_system() -> FileSystem: return Node(hostname="fs_node").file_system diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py new file mode 100644 index 00000000..b0fa2d53 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py @@ -0,0 +1,128 @@ +from typing import Tuple + +import pytest + +from primaite.simulator.file_system.file_system import File, FileSystem, FileSystemItemStatus, Folder + + +@pytest.fixture(scope="function") +def populated_file_system(file_system) -> Tuple[FileSystem, Folder, File]: + """Test that an agent can request a file scan.""" + folder = file_system.create_folder(folder_name="test_folder") + file = file_system.create_file(folder_name="test_folder", file_name="test_file.txt") + + return file_system, folder, file + + +def test_file_scan_request(populated_file_system): + """Test that an agent can request a file scan.""" + fs, folder, file = populated_file_system + + file.corrupt() + assert file.status == FileSystemItemStatus.CORRUPTED + assert file.visible_status == FileSystemItemStatus.GOOD + + fs.apply_request(request=["file", file.uuid, "scan"]) + + assert file.status == FileSystemItemStatus.CORRUPTED + assert file.visible_status == FileSystemItemStatus.CORRUPTED + + +def test_folder_scan_request(populated_file_system): + """Test that an agent can request a folder scan.""" + fs, folder, file = populated_file_system + + folder.corrupt() + assert folder.status == FileSystemItemStatus.CORRUPTED + assert file.status == FileSystemItemStatus.CORRUPTED + assert folder.visible_status == FileSystemItemStatus.GOOD + assert file.visible_status == FileSystemItemStatus.GOOD + + fs.apply_request(request=["folder", folder.uuid, "scan"]) + + assert folder.status == FileSystemItemStatus.CORRUPTED + assert file.status == FileSystemItemStatus.CORRUPTED + assert folder.visible_status == FileSystemItemStatus.CORRUPTED + assert file.visible_status == FileSystemItemStatus.CORRUPTED + + +def test_file_checkhash_request(populated_file_system): + """Test that an agent can request a file hash check.""" + fs, folder, file = populated_file_system + + fs.apply_request(request=["file", file.uuid, "checkhash"]) + + assert file.status == FileSystemItemStatus.GOOD + file.sim_size = 0 + + fs.apply_request(request=["file", file.uuid, "checkhash"]) + + assert file.status == FileSystemItemStatus.CORRUPTED + + +def test_folder_checkhash_request(populated_file_system): + """Test that an agent can request a folder hash check.""" + fs, folder, file = populated_file_system + + fs.apply_request(request=["folder", folder.uuid, "checkhash"]) + + assert folder.status == FileSystemItemStatus.GOOD + file.sim_size = 0 + + fs.apply_request(request=["folder", folder.uuid, "checkhash"]) + assert folder.status == FileSystemItemStatus.CORRUPTED + + +def test_file_repair_request(populated_file_system): + """Test that an agent can request a file repair.""" + fs, folder, file = populated_file_system + + file.corrupt() + assert file.status == FileSystemItemStatus.CORRUPTED + + fs.apply_request(request=["file", file.uuid, "repair"]) + assert file.status == FileSystemItemStatus.GOOD + + +def test_folder_repair_request(populated_file_system): + """Test that an agent can request a folder repair.""" + fs, folder, file = populated_file_system + + folder.corrupt() + assert file.status == FileSystemItemStatus.CORRUPTED + assert folder.status == FileSystemItemStatus.CORRUPTED + + fs.apply_request(request=["folder", folder.uuid, "repair"]) + assert file.status == FileSystemItemStatus.GOOD + assert folder.status == FileSystemItemStatus.GOOD + + +def test_file_restore_request(populated_file_system): + pass + + +def test_folder_restore_request(populated_file_system): + pass + + +def test_file_corrupt_request(populated_file_system): + """Test that an agent can request a file corruption.""" + fs, folder, file = populated_file_system + fs.apply_request(request=["file", file.uuid, "corrupt"]) + assert file.status == FileSystemItemStatus.CORRUPTED + + +def test_folder_corrupt_request(populated_file_system): + """Test that an agent can request a folder corruption.""" + fs, folder, file = populated_file_system + fs.apply_request(request=["folder", folder.uuid, "corrupt"]) + assert file.status == FileSystemItemStatus.CORRUPTED + assert folder.status == FileSystemItemStatus.CORRUPTED + + +def test_file_delete_request(populated_file_system): + pass + + +def test_folder_delete_request(populated_file_system): + pass diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py new file mode 100644 index 00000000..c956682f --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py @@ -0,0 +1,23 @@ +import pytest + +from primaite.simulator.network.hardware.base import Node, NodeOperatingState + + +@pytest.fixture +def node() -> Node: + return Node(hostname="test") + + +def test_node_startup(node): + assert node.operating_state == NodeOperatingState.OFF + node.apply_request(["startup"]) + assert node.operating_state == NodeOperatingState.ON + + +def test_node_shutdown(node): + assert node.operating_state == NodeOperatingState.OFF + node.apply_request(["startup"]) + assert node.operating_state == NodeOperatingState.ON + + node.apply_request(["shutdown"]) + assert node.operating_state == NodeOperatingState.OFF diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py new file mode 100644 index 00000000..64ba764b --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py @@ -0,0 +1,79 @@ +from primaite.simulator.system.services.service import ServiceOperatingState + + +def test_service_scan(service): + """Test that an agent can request a service scan.""" + service.start() + assert service.operating_state == ServiceOperatingState.RUNNING + assert service.visible_operating_state == ServiceOperatingState.STOPPED + + service.apply_request(["scan"]) + assert service.operating_state == ServiceOperatingState.RUNNING + assert service.visible_operating_state == ServiceOperatingState.RUNNING + + +def test_service_stop(service): + """Test that an agent can request to stop a service.""" + service.start() + assert service.operating_state == ServiceOperatingState.RUNNING + + service.apply_request(["stop"]) + assert service.operating_state == ServiceOperatingState.STOPPED + + +def test_service_start(service): + """Test that an agent can request to start a service.""" + assert service.operating_state == ServiceOperatingState.STOPPED + service.apply_request(["start"]) + assert service.operating_state == ServiceOperatingState.RUNNING + + +def test_service_pause(service): + """Test that an agent can request to pause a service.""" + service.start() + assert service.operating_state == ServiceOperatingState.RUNNING + + service.apply_request(["pause"]) + assert service.operating_state == ServiceOperatingState.PAUSED + + +def test_service_resume(service): + """Test that an agent can request to resume a service.""" + service.start() + assert service.operating_state == ServiceOperatingState.RUNNING + + service.apply_request(["pause"]) + assert service.operating_state == ServiceOperatingState.PAUSED + + service.apply_request(["resume"]) + assert service.operating_state == ServiceOperatingState.RUNNING + + +def test_service_restart(service): + """Test that an agent can request to restart a service.""" + service.start() + assert service.operating_state == ServiceOperatingState.RUNNING + + service.apply_request(["restart"]) + assert service.operating_state == ServiceOperatingState.RESTARTING + + +def test_service_disable(service): + """Test that an agent can request to disable a service.""" + service.start() + assert service.operating_state == ServiceOperatingState.RUNNING + + service.apply_request(["disable"]) + assert service.operating_state == ServiceOperatingState.DISABLED + + +def test_service_enable(service): + """Test that an agent can request to enable a service.""" + service.start() + assert service.operating_state == ServiceOperatingState.RUNNING + + service.apply_request(["disable"]) + assert service.operating_state == ServiceOperatingState.DISABLED + + service.apply_request(["enable"]) + assert service.operating_state == ServiceOperatingState.STOPPED diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py index 20a3cad5..24e20776 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py @@ -1,24 +1,4 @@ -from typing import Any - -import pytest - -from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.core.sys_log import SysLog -from primaite.simulator.system.services.service import Service, ServiceOperatingState - - -class TestService(Service): - """Test Service class""" - - def receive(self, payload: Any, session_id: str, **kwargs) -> bool: - pass - - -@pytest.fixture(scope="function") -def service(file_system) -> TestService: - return TestService( - name="TestService", port=Port.ARP, file_system=file_system, sys_log=SysLog(hostname="test_service") - ) +from primaite.simulator.system.services.service import ServiceOperatingState def test_scan(service): From 724beb1a29d065a5a7a9cf93e6f6e0ad3d3b6d85 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Mon, 23 Oct 2023 15:58:37 +0100 Subject: [PATCH 238/980] #1947: folder/file scan now take multiple time steps to complete --- .../simulator/file_system/file_system.py | 79 ++++++++++------- .../simulator/network/hardware/base.py | 1 + .../simulator/system/services/service.py | 27 ++++-- src/primaite/simulator/system/software.py | 2 + .../system/test_database_on_node.py | 1 - .../_file_system/test_file_system.py | 84 ++++++++++++------- .../_file_system/test_file_system_actions.py | 72 ++++++++++------ .../_system/_services/test_service_actions.py | 5 +- .../_system/_services/test_services.py | 14 +++- 9 files changed, 184 insertions(+), 101 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 1327ad87..bddc1f28 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -47,7 +47,7 @@ def convert_size(size_bytes: int) -> str: return f"{s} {size_name[i]}" -class FileSystemItemStatus(Enum): +class FileSystemItemHealthStatus(Enum): """Status of the FileSystemItem.""" GOOD = 0 @@ -73,10 +73,10 @@ class FileSystemItemABC(SimComponent): name: str "The name of the FileSystemItemABC." - status: FileSystemItemStatus = FileSystemItemStatus.GOOD + health_status: FileSystemItemHealthStatus = FileSystemItemHealthStatus.GOOD "Actual status of the current FileSystemItem" - visible_status: FileSystemItemStatus = FileSystemItemStatus.GOOD + visible_health_status: FileSystemItemHealthStatus = FileSystemItemHealthStatus.GOOD "Visible status of the current FileSystemItem" previous_hash: Optional[str] = None @@ -90,8 +90,8 @@ class FileSystemItemABC(SimComponent): """ state = super().describe_state() state["name"] = self.name - state["status"] = self.status.name - state["visible_status"] = self.visible_status.name + state["status"] = self.health_status.name + state["visible_status"] = self.visible_health_status.name state["previous_hash"] = self.previous_hash return state @@ -123,7 +123,7 @@ class FileSystemItemABC(SimComponent): """Update the FileSystemItem states.""" super().scan() - self.visible_status = self.status + self.visible_health_status = self.health_status @abstractmethod def check_hash(self) -> bool: @@ -135,7 +135,7 @@ class FileSystemItemABC(SimComponent): Return False if corruption is detected, otherwise True """ # cannot check hash if deleted - if self.status == FileSystemItemStatus.DELETED: + if self.health_status == FileSystemItemHealthStatus.DELETED: return False @abstractmethod @@ -146,7 +146,7 @@ class FileSystemItemABC(SimComponent): True if successfully repaired. False otherwise. """ # cannot repair if deleted - if self.status == FileSystemItemStatus.DELETED: + if self.health_status == FileSystemItemHealthStatus.DELETED: return False @abstractmethod @@ -157,7 +157,7 @@ class FileSystemItemABC(SimComponent): True if successfully corrupted. False otherwise. """ # cannot corrupt if deleted - if self.status == FileSystemItemStatus.DELETED: + if self.health_status == FileSystemItemHealthStatus.DELETED: return False def delete(self) -> None: @@ -166,7 +166,7 @@ class FileSystemItemABC(SimComponent): True if successfully deleted. False otherwise. """ - self.status = FileSystemItemStatus.DELETED + self.health_status = FileSystemItemHealthStatus.DELETED def restore(self) -> None: """Restore the file/folder to the state before it got ruined.""" @@ -456,6 +456,10 @@ class Folder(FileSystemItemABC): "Files by their name as .." deleted_files: Dict[str, File] = {} + "List of files that have been deleted." + + scan_duration: int = -1 + "How many timesteps to complete a scan." def describe_state(self) -> Dict: """ @@ -465,6 +469,7 @@ class Folder(FileSystemItemABC): """ state = super().describe_state() state["files"] = {file.name: file.describe_state() for uuid, file in self.files.items()} + state["deleted_files"] = {file.name: file.describe_state() for uuid, file in self.deleted_files.items()} return state def show(self, markdown: bool = False): @@ -492,6 +497,21 @@ class Folder(FileSystemItemABC): """ return sum(file.size for file in self.files.values() if file.size is not None) + def apply_timestep(self, timestep: int): + """ + Used to run the actions that last over multiple timesteps. + + :param: timestep: the current timestep. + """ + super().apply_timestep(timestep=timestep) + + # scan files each timestep + if self.scan_duration > -1: + # scan one file per timestep + file = self.get_file_by_id(file_uuid=list(self.files)[self.scan_duration - 1]) + file.scan() + self.scan_duration -= 1 + def get_file(self, file_name: str) -> Optional[File]: """ Get a file by its name. @@ -573,30 +593,31 @@ class Folder(FileSystemItemABC): def quarantine(self): """Quarantines the File System Folder.""" - if self.status != FileSystemItemStatus.QUARANTINED: - self.status = FileSystemItemStatus.QUARANTINED + if self.health_status != FileSystemItemHealthStatus.QUARANTINED: + self.health_status = FileSystemItemHealthStatus.QUARANTINED self.fs.sys_log.info(f"Quarantined folder ./{self.name}") def unquarantine(self): """Unquarantine of the File System Folder.""" - if self.status == FileSystemItemStatus.QUARANTINED: - self.status = FileSystemItemStatus.GOOD + if self.health_status == FileSystemItemHealthStatus.QUARANTINED: + self.health_status = FileSystemItemHealthStatus.GOOD self.fs.sys_log.info(f"Quarantined folder ./{self.name}") def quarantine_status(self) -> bool: """Returns true if the folder is being quarantined.""" - return self.status == FileSystemItemStatus.QUARANTINED + return self.health_status == FileSystemItemHealthStatus.QUARANTINED def scan(self) -> None: """Update Folder visible status.""" super().scan() - # update the status of files in folder - for file_id in self.files: - file = self.get_file_by_id(file_uuid=file_id) - file.scan() - - self.fs.sys_log.info(f"Scanning folder {self.name} (id: {self.uuid})") + if self.scan_duration <= -1: + # scan one file per timestep + self.scan_duration = len(self.files) + self.fs.sys_log.info(f"Scanning folder {self.name} (id: {self.uuid})") + else: + # scan already in progress + self.fs.sys_log.info(f"Scan is already in progress {self.name} (id: {self.uuid})") def check_hash(self) -> bool: """ @@ -638,8 +659,8 @@ class Folder(FileSystemItemABC): repaired = file.repair() # set file status to good if corrupt - if self.status == FileSystemItemStatus.CORRUPTED: - self.status = FileSystemItemStatus.GOOD + if self.health_status == FileSystemItemHealthStatus.CORRUPTED: + self.health_status = FileSystemItemHealthStatus.GOOD repaired = True self.fs.sys_log.info(f"Repaired folder {self.name} (id: {self.uuid})") @@ -674,8 +695,8 @@ class Folder(FileSystemItemABC): corrupted = file.corrupt() # set file status to corrupt if good - if self.status == FileSystemItemStatus.GOOD: - self.status = FileSystemItemStatus.CORRUPTED + if self.health_status == FileSystemItemHealthStatus.GOOD: + self.health_status = FileSystemItemHealthStatus.CORRUPTED corrupted = True self.fs.sys_log.info(f"Corrupted folder {self.name} (id: {self.uuid})") @@ -824,8 +845,8 @@ class File(FileSystemItemABC): super().repair() # set file status to good if corrupt - if self.status == FileSystemItemStatus.CORRUPTED: - self.status = FileSystemItemStatus.GOOD + if self.health_status == FileSystemItemHealthStatus.CORRUPTED: + self.health_status = FileSystemItemHealthStatus.GOOD path = self.folder.name + "/" + self.name self.folder.fs.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") @@ -842,8 +863,8 @@ class File(FileSystemItemABC): corrupted = False # set file status to good if corrupt - if self.status == FileSystemItemStatus.GOOD: - self.status = FileSystemItemStatus.CORRUPTED + if self.health_status == FileSystemItemHealthStatus.GOOD: + self.health_status = FileSystemItemHealthStatus.CORRUPTED corrupted = True path = self.folder.name + "/" + self.name diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 23ad7904..7b8e44ff 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1000,6 +1000,7 @@ class Node(SimComponent): "applications": {uuid: app.describe_state() for uuid, app in self.applications.items()}, "services": {uuid: svc.describe_state() for uuid, svc in self.services.items()}, "process": {uuid: proc.describe_state() for uuid, proc in self.processes.items()}, + "revealed_to_red": self.revealed_to_red, } ) return state diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 82eab7d9..aa2fef5e 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -3,7 +3,7 @@ from typing import Dict, Optional from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType -from primaite.simulator.system.software import IOSoftware +from primaite.simulator.system.software import IOSoftware, SoftwareHealthState _LOGGER = getLogger(__name__) @@ -35,14 +35,17 @@ class Service(IOSoftware): operating_state: ServiceOperatingState = ServiceOperatingState.STOPPED "The current operating state of the Service." - visible_operating_state: ServiceOperatingState = ServiceOperatingState.STOPPED - "The visible operating state of the service." - restart_duration: int = 5 "How many timesteps does it take to restart this service." restart_countdown: Optional[int] = None "If currently restarting, how many timesteps remain until the restart is finished." + def __init__(self, **kwargs): + super().__init__(**kwargs) + + self.health_state_visible = SoftwareHealthState.UNUSED + self.health_state_actual = SoftwareHealthState.UNUSED + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request("scan", RequestType(func=lambda request, context: self.scan())) @@ -65,9 +68,9 @@ class Service(IOSoftware): :rtype: Dict """ state = super().describe_state() - state.update( - {"operating_state": self.operating_state.name, "visible_operating_state": self.visible_operating_state.name} - ) + state["operating_state"] = self.operating_state.name + state["health_state_actual"] = self.health_state_actual + state["health_state_visible"] = self.health_state_visible return state def reset_component_for_episode(self, episode: int): @@ -85,49 +88,56 @@ class Service(IOSoftware): super().scan() # update the visible operating state - self.visible_operating_state = self.operating_state + self.health_state_visible = self.health_state_actual def stop(self) -> None: """Stop the service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.sys_log.info(f"Stopping service {self.name}") self.operating_state = ServiceOperatingState.STOPPED + self.health_state_actual = SoftwareHealthState.UNUSED def start(self, **kwargs) -> None: """Start the service.""" if self.operating_state == ServiceOperatingState.STOPPED: self.sys_log.info(f"Starting service {self.name}") self.operating_state = ServiceOperatingState.RUNNING + self.health_state_actual = SoftwareHealthState.GOOD def pause(self) -> None: """Pause the service.""" if self.operating_state == ServiceOperatingState.RUNNING: self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.PAUSED + self.health_state_actual = SoftwareHealthState.OVERWHELMED def resume(self) -> None: """Resume paused service.""" if self.operating_state == ServiceOperatingState.PAUSED: self.sys_log.info(f"Resuming service {self.name}") self.operating_state = ServiceOperatingState.RUNNING + self.health_state_actual = SoftwareHealthState.GOOD def restart(self) -> None: """Restart running service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.RESTARTING + self.health_state_actual = SoftwareHealthState.OVERWHELMED self.restart_countdown = self.restart_duration def disable(self) -> None: """Disable the service.""" self.sys_log.info(f"Disabling Application {self.name}") self.operating_state = ServiceOperatingState.DISABLED + self.health_state_actual = SoftwareHealthState.OVERWHELMED def enable(self) -> None: """Enable the disabled service.""" if self.operating_state == ServiceOperatingState.DISABLED: self.sys_log.info(f"Enabling Application {self.name}") self.operating_state = ServiceOperatingState.STOPPED + self.health_state_actual = SoftwareHealthState.OVERWHELMED def apply_timestep(self, timestep: int) -> None: """ @@ -144,4 +154,5 @@ class Service(IOSoftware): if self.restart_countdown <= 0: _LOGGER.debug(f"Restarting finished for service {self.name}") self.operating_state = ServiceOperatingState.RUNNING + self.health_state_actual = SoftwareHealthState.GOOD self.restart_countdown -= 1 diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index e692582e..0d25a89f 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -31,6 +31,8 @@ class SoftwareType(Enum): class SoftwareHealthState(Enum): """Enumeration of the Software Health States.""" + UNUSED = 0 + "Unused state." GOOD = 1 "The software is in a good and healthy condition." COMPROMISED = 2 diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 14b579b2..92056981 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -1,6 +1,5 @@ from ipaddress import IPv4Address -from primaite.simulator.file_system.file_system import FileSystemItemStatus from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database.database_service import DatabaseService diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 888b8c75..6cf1df25 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -1,6 +1,6 @@ import pytest -from primaite.simulator.file_system.file_system import File, FileSystem, FileSystemItemStatus, Folder +from primaite.simulator.file_system.file_system import File, FileSystem, FileSystemItemHealthStatus, Folder from primaite.simulator.file_system.file_type import FileType @@ -146,13 +146,13 @@ def test_file_corrupt_repair(file_system): file.corrupt() - assert folder.status == FileSystemItemStatus.GOOD - assert file.status == FileSystemItemStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.GOOD + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED file.repair() - assert folder.status == FileSystemItemStatus.GOOD - assert file.status == FileSystemItemStatus.GOOD + assert folder.health_status == FileSystemItemHealthStatus.GOOD + assert file.health_status == FileSystemItemHealthStatus.GOOD def test_folder_corrupt_repair(file_system): @@ -163,14 +163,14 @@ def test_folder_corrupt_repair(file_system): folder.corrupt() file = folder.get_file(file_name="test_file.txt") - assert folder.status == FileSystemItemStatus.CORRUPTED - assert file.status == FileSystemItemStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED folder.repair() file = folder.get_file(file_name="test_file.txt") - assert folder.status == FileSystemItemStatus.GOOD - assert file.status == FileSystemItemStatus.GOOD + assert folder.health_status == FileSystemItemHealthStatus.GOOD + assert file.health_status == FileSystemItemHealthStatus.GOOD def test_file_scan(file_system): @@ -178,43 +178,63 @@ def test_file_scan(file_system): folder: Folder = file_system.create_folder(folder_name="test_folder") file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") - assert file.status == FileSystemItemStatus.GOOD - assert file.visible_status == FileSystemItemStatus.GOOD + assert file.health_status == FileSystemItemHealthStatus.GOOD + assert file.visible_health_status == FileSystemItemHealthStatus.GOOD file.corrupt() - assert file.status == FileSystemItemStatus.CORRUPTED - assert file.visible_status == FileSystemItemStatus.GOOD + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.visible_health_status == FileSystemItemHealthStatus.GOOD file.scan() - assert file.status == FileSystemItemStatus.CORRUPTED - assert file.visible_status == FileSystemItemStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPTED def test_folder_scan(file_system): """Test the ability to update visible status.""" folder: Folder = file_system.create_folder(folder_name="test_folder") - file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + file_system.create_file(file_name="test_file2.txt", folder_name="test_folder") - assert folder.status == FileSystemItemStatus.GOOD - assert folder.visible_status == FileSystemItemStatus.GOOD - assert file.status == FileSystemItemStatus.GOOD - assert file.visible_status == FileSystemItemStatus.GOOD + file1: File = folder.get_file_by_id(file_uuid=list(folder.files)[1]) + file2: File = folder.get_file_by_id(file_uuid=list(folder.files)[0]) + + assert folder.health_status == FileSystemItemHealthStatus.GOOD + assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD folder.corrupt() - assert folder.status == FileSystemItemStatus.CORRUPTED - assert folder.visible_status == FileSystemItemStatus.GOOD - assert file.status == FileSystemItemStatus.CORRUPTED - assert file.visible_status == FileSystemItemStatus.GOOD + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD folder.scan() - assert folder.status == FileSystemItemStatus.CORRUPTED - assert folder.visible_status == FileSystemItemStatus.CORRUPTED - assert file.status == FileSystemItemStatus.CORRUPTED - assert file.visible_status == FileSystemItemStatus.CORRUPTED + folder.apply_timestep(timestep=0) + + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD + + folder.apply_timestep(timestep=1) + + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + + folder.apply_timestep(timestep=2) + + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPTED def test_simulated_file_check_hash(file_system): @@ -225,7 +245,7 @@ def test_simulated_file_check_hash(file_system): # change simulated file size file.sim_size = 0 assert file.check_hash() is False - assert file.status == FileSystemItemStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED def test_real_file_check_hash(file_system): @@ -238,7 +258,7 @@ def test_real_file_check_hash(file_system): f.write("get hacked scrub lol xD\n") assert file.check_hash() is False - assert file.status == FileSystemItemStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED def test_simulated_folder_check_hash(file_system): @@ -251,7 +271,7 @@ def test_simulated_folder_check_hash(file_system): file = folder.get_file(file_name="test_file.txt") file.sim_size = 0 assert folder.check_hash() is False - assert folder.status == FileSystemItemStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED def test_real_folder_check_hash(file_system): @@ -268,7 +288,7 @@ def test_real_folder_check_hash(file_system): f.write("get hacked scrub lol xD\n") assert folder.check_hash() is False - assert folder.status == FileSystemItemStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED @pytest.mark.skip(reason="Skipping until we tackle serialisation") diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py index b0fa2d53..ed06d2fb 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py @@ -2,7 +2,7 @@ from typing import Tuple import pytest -from primaite.simulator.file_system.file_system import File, FileSystem, FileSystemItemStatus, Folder +from primaite.simulator.file_system.file_system import File, FileSystem, FileSystemItemHealthStatus, Folder @pytest.fixture(scope="function") @@ -19,31 +19,51 @@ def test_file_scan_request(populated_file_system): fs, folder, file = populated_file_system file.corrupt() - assert file.status == FileSystemItemStatus.CORRUPTED - assert file.visible_status == FileSystemItemStatus.GOOD + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.visible_health_status == FileSystemItemHealthStatus.GOOD fs.apply_request(request=["file", file.uuid, "scan"]) - assert file.status == FileSystemItemStatus.CORRUPTED - assert file.visible_status == FileSystemItemStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPTED def test_folder_scan_request(populated_file_system): """Test that an agent can request a folder scan.""" fs, folder, file = populated_file_system + fs.create_file(file_name="test_file2.txt", folder_name="test_folder") + + file1: File = folder.get_file_by_id(file_uuid=list(folder.files)[1]) + file2: File = folder.get_file_by_id(file_uuid=list(folder.files)[0]) folder.corrupt() - assert folder.status == FileSystemItemStatus.CORRUPTED - assert file.status == FileSystemItemStatus.CORRUPTED - assert folder.visible_status == FileSystemItemStatus.GOOD - assert file.visible_status == FileSystemItemStatus.GOOD + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD fs.apply_request(request=["folder", folder.uuid, "scan"]) - assert folder.status == FileSystemItemStatus.CORRUPTED - assert file.status == FileSystemItemStatus.CORRUPTED - assert folder.visible_status == FileSystemItemStatus.CORRUPTED - assert file.visible_status == FileSystemItemStatus.CORRUPTED + folder.apply_timestep(timestep=0) + + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD + + folder.apply_timestep(timestep=1) + + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + + folder.apply_timestep(timestep=2) + + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPTED def test_file_checkhash_request(populated_file_system): @@ -52,12 +72,12 @@ def test_file_checkhash_request(populated_file_system): fs.apply_request(request=["file", file.uuid, "checkhash"]) - assert file.status == FileSystemItemStatus.GOOD + assert file.health_status == FileSystemItemHealthStatus.GOOD file.sim_size = 0 fs.apply_request(request=["file", file.uuid, "checkhash"]) - assert file.status == FileSystemItemStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED def test_folder_checkhash_request(populated_file_system): @@ -66,11 +86,11 @@ def test_folder_checkhash_request(populated_file_system): fs.apply_request(request=["folder", folder.uuid, "checkhash"]) - assert folder.status == FileSystemItemStatus.GOOD + assert folder.health_status == FileSystemItemHealthStatus.GOOD file.sim_size = 0 fs.apply_request(request=["folder", folder.uuid, "checkhash"]) - assert folder.status == FileSystemItemStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED def test_file_repair_request(populated_file_system): @@ -78,10 +98,10 @@ def test_file_repair_request(populated_file_system): fs, folder, file = populated_file_system file.corrupt() - assert file.status == FileSystemItemStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED fs.apply_request(request=["file", file.uuid, "repair"]) - assert file.status == FileSystemItemStatus.GOOD + assert file.health_status == FileSystemItemHealthStatus.GOOD def test_folder_repair_request(populated_file_system): @@ -89,12 +109,12 @@ def test_folder_repair_request(populated_file_system): fs, folder, file = populated_file_system folder.corrupt() - assert file.status == FileSystemItemStatus.CORRUPTED - assert folder.status == FileSystemItemStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED fs.apply_request(request=["folder", folder.uuid, "repair"]) - assert file.status == FileSystemItemStatus.GOOD - assert folder.status == FileSystemItemStatus.GOOD + assert file.health_status == FileSystemItemHealthStatus.GOOD + assert folder.health_status == FileSystemItemHealthStatus.GOOD def test_file_restore_request(populated_file_system): @@ -109,15 +129,15 @@ def test_file_corrupt_request(populated_file_system): """Test that an agent can request a file corruption.""" fs, folder, file = populated_file_system fs.apply_request(request=["file", file.uuid, "corrupt"]) - assert file.status == FileSystemItemStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED def test_folder_corrupt_request(populated_file_system): """Test that an agent can request a folder corruption.""" fs, folder, file = populated_file_system fs.apply_request(request=["folder", folder.uuid, "corrupt"]) - assert file.status == FileSystemItemStatus.CORRUPTED - assert folder.status == FileSystemItemStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED def test_file_delete_request(populated_file_system): diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py index 64ba764b..6b2ee0a7 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py @@ -1,15 +1,16 @@ from primaite.simulator.system.services.service import ServiceOperatingState +from primaite.simulator.system.software import SoftwareHealthState def test_service_scan(service): """Test that an agent can request a service scan.""" service.start() assert service.operating_state == ServiceOperatingState.RUNNING - assert service.visible_operating_state == ServiceOperatingState.STOPPED + assert service.health_state_visible == SoftwareHealthState.UNUSED service.apply_request(["scan"]) assert service.operating_state == ServiceOperatingState.RUNNING - assert service.visible_operating_state == ServiceOperatingState.RUNNING + assert service.health_state_visible == SoftwareHealthState.GOOD def test_service_stop(service): diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py index 24e20776..b32463a2 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py @@ -1,17 +1,18 @@ from primaite.simulator.system.services.service import ServiceOperatingState +from primaite.simulator.system.software import SoftwareHealthState def test_scan(service): assert service.operating_state == ServiceOperatingState.STOPPED - assert service.visible_operating_state == ServiceOperatingState.STOPPED + assert service.health_state_visible == SoftwareHealthState.UNUSED service.start() assert service.operating_state == ServiceOperatingState.RUNNING - assert service.visible_operating_state == ServiceOperatingState.STOPPED + assert service.health_state_visible == SoftwareHealthState.UNUSED service.scan() assert service.operating_state == ServiceOperatingState.RUNNING - assert service.visible_operating_state == ServiceOperatingState.RUNNING + assert service.health_state_visible == SoftwareHealthState.GOOD def test_start_service(service): @@ -51,6 +52,13 @@ def test_restart(service): service.restart() assert service.operating_state == ServiceOperatingState.RESTARTING + timestep = 0 + while service.operating_state == ServiceOperatingState.RESTARTING: + service.apply_timestep(timestep) + timestep += 1 + + assert service.operating_state == ServiceOperatingState.RUNNING + def test_enable_disable(service): service.disable() From 975aa9ffc289271ead984b4b94b06adf7d2011d6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 23 Oct 2023 16:26:34 +0100 Subject: [PATCH 239/980] Minor changes to rewards and services. --- example_config.yaml | 14 +++++++----- src/primaite/game/agent/rewards.py | 13 ++++++----- src/primaite/game/session.py | 22 +++++++++++++++++-- .../system/applications/web_browser.py | 3 ++- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index e16411fa..f3d8dc10 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -2,10 +2,10 @@ training_config: rl_framework: SB3 rl_algorithm: PPO seed: 333 - n_learn_episodes: 1 - n_learn_steps: 8 - n_eval_episodes: 0 - n_eval_steps: 8 + n_learn_episodes: 4 + n_learn_steps: 128 + n_eval_episodes: 1 + n_eval_steps: 128 game_config: @@ -534,6 +534,9 @@ simulation: type: DatabaseClient options: db_server_ip: 192.168.1.14 + - ref: web_server_web_service + type: WebServer + - ref: database_server type: server @@ -589,9 +592,10 @@ simulation: subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 - services: + applications: - ref: client_2_web_browser type: WebBrowser + services: - ref: client_2_dns_client type: DNSClient diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 03c4e2d3..6c408ff9 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -29,7 +29,7 @@ from abc import abstractmethod from typing import Dict, List, Tuple, TYPE_CHECKING from primaite import getLogger -from primaite.game.agent.utils import access_from_nested_dict +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE _LOGGER = getLogger(__name__) @@ -180,14 +180,17 @@ class WebServer404Penalty(AbstractReward): :type state: Dict """ web_service_state = access_from_nested_dict(state, self.location_in_state) - most_recent_return_code = web_service_state["most_recent_return_code"] + if web_service_state is NOT_PRESENT_IN_STATE: + print("error getting web service state") + return 0.0 + most_recent_return_code = web_service_state["last_response_status_code"] # TODO: reward needs to use the current web state. Observation should return web state at the time of last scan. if most_recent_return_code == 200: - return 1 + return 1.0 elif most_recent_return_code == 404: - return -1 + return -1.0 else: - return 0 + return 0.0 @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession") -> "WebServer404Penalty": diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index adb9f7b5..d40d0754 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -21,12 +21,15 @@ from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.sim_container import Simulation +from primaite.simulator.system.applications.application import Application from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.service import Service +from primaite.simulator.system.services.web_server.web_server import WebServer _LOGGER = getLogger(__name__) @@ -182,6 +185,8 @@ class PrimaiteSession: """Mapping from unique node reference name to node object. Used when parsing config files.""" self.ref_map_services: Dict[str, Service] = {} """Mapping from human-readable service reference to service object. Used for parsing config files.""" + self.ref_map_applications: Dict[str, Application] = {} + """Mapping from human-readable application reference to application object. Used for parsing config files.""" self.ref_map_links: Dict[str, Link] = {} """Mapping from human-readable link reference to link object. Used when parsing config files.""" self.gate_client: PrimaiteGATEClient = PrimaiteGATEClient(self) @@ -333,11 +338,11 @@ class PrimaiteSession: "DNSServer": DNSServer, "DatabaseClient": DatabaseClient, "DatabaseService": DatabaseService, - # 'database_backup': , + "WebServer": WebServer, "DataManipulationBot": DataManipulationBot, - # 'web_browser' } if service_type in service_types_mapping: + print(f"installing {service_type} on node {new_node.hostname}") new_node.software_manager.install(service_types_mapping[service_type]) new_service = new_node.software_manager.software[service_type] sess.ref_map_services[service_ref] = new_service @@ -355,6 +360,19 @@ class PrimaiteSession: if "domain_mapping" in opt: for domain, ip in opt["domain_mapping"].items(): new_service.dns_register(domain, ip) + if "applications" in node_cfg: + for application_cfg in node_cfg["applications"]: + application_ref = application_cfg["ref"] + application_type = application_cfg["type"] + application_types_mapping = { + "WebBrowser": WebBrowser, + } + if application_type in application_types_mapping: + new_node.software_manager.install(application_types_mapping[application_type]) + new_application = new_node.software_manager.software[application_type] + sess.ref_map_applications[application_ref] = new_application + else: + print(f"application type not found {application_type}") if "nics" in node_cfg: for nic_num, nic_cfg in node_cfg["nics"].items(): new_node.connect_nic(NIC(ip_address=nic_cfg["ip_address"], subnet_mask=nic_cfg["subnet_mask"])) diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index c48b785e..ea9c3ac3 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -38,7 +38,8 @@ class WebBrowser(Application): :return: A dictionary capturing the current state of the WebBrowser and its child objects. """ - return super().describe_state() + state = super().describe_state() + state["last_response_status_code"] = self.latest_response.status_code if self.latest_response else None def reset_component_for_episode(self, episode: int): """ From d4eee36b7bc921af0791e9b1a4aa062a0b97111d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 23 Oct 2023 17:23:14 +0100 Subject: [PATCH 240/980] Fix software registration for game layer and simulator interface --- example_config.yaml | 2 +- src/primaite/game/agent/observations.py | 2 +- .../simulator/network/hardware/base.py | 36 ++++++++++++++++++- .../system/applications/application.py | 2 +- .../simulator/system/core/software_manager.py | 15 ++++++++ .../system/services/web_server/web_server.py | 20 ++++++++++- src/primaite/simulator/system/software.py | 6 ++-- 7 files changed, 75 insertions(+), 8 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index f3d8dc10..00beaa1e 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -457,7 +457,7 @@ game_config: weight: 0.5 options: node_ref: web_server - service_ref: web_server_database_client + service_ref: web_server_web_service agent_settings: diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index af398fc9..35fe8ac5 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -139,7 +139,7 @@ class ServiceObservation(AbstractObservation): service_state = access_from_nested_dict(state, self.where) if service_state is NOT_PRESENT_IN_STATE: return self.default_observation - return {"operating_status": service_state["operating_state"], "health_status": service_state["health_status"]} + return {"operating_status": service_state["operating_state"], "health_status": service_state["health_state"]} @property def space(self) -> spaces.Space: diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 78ae228e..607e348b 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -938,6 +938,7 @@ class Node(SimComponent): kwargs["file_system"] = FileSystem(sys_log=kwargs["sys_log"], sim_root=kwargs["root"] / "fs") if not kwargs.get("software_manager"): kwargs["software_manager"] = SoftwareManager( + parent_node=self, sys_log=kwargs.get("sys_log"), session_manager=kwargs.get("session_manager"), file_system=kwargs.get("file_system"), @@ -1199,7 +1200,8 @@ class Node(SimComponent): self._service_request_manager.add_request(service.uuid, RequestType(func=service._request_manager)) def uninstall_service(self, service: Service) -> None: - """Uninstall and completely remove service from this node. + """ + Uninstall and completely remove service from this node. :param service: Service object that is currently associated with this node. :type service: Service @@ -1214,6 +1216,38 @@ class Node(SimComponent): _LOGGER.info(f"Removed service {service.uuid} from node {self.uuid}") self._service_request_manager.remove_request(service.uuid) + def install_application(self, application: Application) -> None: + """ + Install an application on this node. + + :param application: Application instance that has not been installed on any node yet. + :type application: Application + """ + if application in self: + _LOGGER.warning(f"Can't add application {application.uuid} to node {self.uuid}. It's already installed.") + return + self.applications[application.uuid] = application + application.parent = self + self.sys_log.info(f"Installed application {application.name}") + _LOGGER.info(f"Added application {application.uuid} to node {self.uuid}") + self._application_request_manager.add_request(application.uuid, RequestType(func=application._request_manager)) + + def uninstall_application(self, application: Application) -> None: + """ + Uninstall and completely remove application from this node. + + :param application: Application object that is currently associated with this node. + :type application: Application + """ + if application not in self: + _LOGGER.warning(f"Can't remove application {application.uuid} from node {self.uuid}. It's not installed.") + return + self.applications.pop(application.uuid) + application.parent = None + self.sys_log.info(f"Uninstalled application {application.name}") + _LOGGER.info(f"Removed application {application.uuid} from node {self.uuid}") + self._application_request_manager.remove_request(application.uuid) + def __contains__(self, item: Any) -> bool: if isinstance(item, Service): return item.uuid in self.services diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 69b64aac..e3da6f01 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -45,7 +45,7 @@ class Application(IOSoftware): state = super().describe_state() state.update( { - "opearting_state": self.operating_state.name, + "opearting_state": self.operating_state.value, "execution_control_status": self.execution_control_status, "num_executions": self.num_executions, "groups": list(self.groups), diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index 973b17b4..8b8fe599 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -14,6 +14,7 @@ from primaite.simulator.system.software import IOSoftware if TYPE_CHECKING: from primaite.simulator.system.core.session_manager import SessionManager from primaite.simulator.system.core.sys_log import SysLog + from primaite.simulator.network.hardware.base import Node from typing import Type, TypeVar @@ -25,6 +26,7 @@ class SoftwareManager: def __init__( self, + parent_node: "Node", session_manager: "SessionManager", sys_log: SysLog, file_system: FileSystem, @@ -35,6 +37,7 @@ class SoftwareManager: :param session_manager: The session manager handling network communications. """ + self.node = parent_node self.session_manager = session_manager self.software: Dict[str, Union[Service, Application]] = {} self._software_class_to_name_map: Dict[Type[IOSoftwareClass], str] = {} @@ -62,6 +65,8 @@ class SoftwareManager: :param software_class: The software class. """ + # TODO: Software manager and node itself both have an install method. Need to refactor to have more logical + # separation of concerns. if software_class in self._software_class_to_name_map: self.sys_log.info(f"Cannot install {software_class} as it is already installed") return @@ -77,6 +82,12 @@ class SoftwareManager: if isinstance(software, Application): software.operating_state = ApplicationOperatingState.CLOSED + # add the software to the node's registry after it has been fully initialized + if isinstance(software, Service): + self.node.install_service(software) + elif isinstance(software, Application): + self.node.install_application(software) + def uninstall(self, software_name: str): """ Uninstall an Application or Service. @@ -85,6 +96,10 @@ class SoftwareManager: """ if software_name in self.software: software = self.software.pop(software_name) # noqa + if isinstance(software, Application): + self.node.uninstall_application(software) + elif isinstance(software, Service): + self.node.uninstall_service(software) del software self.sys_log.info(f"Deleted {software_name}") return diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index f63d5169..5957e4cb 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -1,5 +1,5 @@ from ipaddress import IPv4Address -from typing import Any, Optional +from typing import Any, Dict, Optional from urllib.parse import urlparse from primaite.simulator.network.protocols.http import ( @@ -17,6 +17,23 @@ from primaite.simulator.system.services.service import Service class WebServer(Service): """Class used to represent a Web Server Service in simulation.""" + last_response_status_code: Optional[HttpStatusCode] = None + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state["last_response_status_code"] = ( + self.last_response_status_code.value if self.last_response_status_code else None + ) + return state + def __init__(self, **kwargs): kwargs["name"] = "WebServer" kwargs["protocol"] = IPProtocol.TCP @@ -66,6 +83,7 @@ class WebServer(Service): self.send(payload=response, session_id=session_id) # return true if response is OK + self.last_response_status_code = response.status_code return response.status_code == HttpStatusCode.OK def _handle_get_request(self, payload: HttpRequestPacket) -> HttpResponsePacket: diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 25f764e4..8cd13d1a 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -119,9 +119,9 @@ class Software(SimComponent): state = super().describe_state() state.update( { - "health_state": self.health_state_actual.name, - "health_state_red_view": self.health_state_visible.name, - "criticality": self.criticality.name, + "health_state": self.health_state_actual.value, + "health_state_red_view": self.health_state_visible.value, + "criticality": self.criticality.value, "patching_count": self.patching_count, "scanning_count": self.scanning_count, "revealed_to_red": self.revealed_to_red, From 8b85d5d55bd1f61f099b5c20a8479e2a6df46c63 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 24 Oct 2023 10:11:50 +0100 Subject: [PATCH 241/980] #1947: node startup/shutdown now take multiple timesteps to complete --- .../simulator/file_system/file_system.py | 8 ++- .../simulator/network/hardware/base.py | 68 ++++++++++++++++--- src/primaite/simulator/network/networks.py | 15 ++-- .../network/test_frame_transmission.py | 19 ++---- .../network/test_link_connection.py | 8 +-- .../integration_tests/network/test_routing.py | 11 ++- .../network/test_switched_network.py | 19 ++++-- .../_network/_hardware/test_node_actions.py | 18 +++++ 8 files changed, 121 insertions(+), 45 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index bddc1f28..72ca1b51 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -499,9 +499,13 @@ class Folder(FileSystemItemABC): def apply_timestep(self, timestep: int): """ - Used to run the actions that last over multiple timesteps. + Apply a single timestep of simulation dynamics to this service. - :param: timestep: the current timestep. + In this instance, if any multi-timestep processes are currently occurring (such as scanning), + then they are brought one step closer to being finished. + + :param timestep: The current timestep number. (Amount of time since simulation episode began) + :type timestep: int """ super().apply_timestep(timestep=timestep) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 7b8e44ff..ed7719d7 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -914,6 +914,18 @@ class Node(SimComponent): revealed_to_red: bool = False "Informs whether the node has been revealed to a red agent." + start_up_duration: int = 3 + "Time steps needed for the node to start up." + + start_up_countdown: int = -1 + "Time steps needed until node is booted up." + + shut_down_duration: int = 3 + "Time steps needed for the node to shut down." + + shut_down_countdown: int = -1 + "Time steps needed until node is shut down." + def __init__(self, **kwargs): """ Initialize the Node with various components and managers. @@ -1042,22 +1054,62 @@ class Node(SimComponent): ) print(table) + def apply_timestep(self, timestep: int): + """ + Apply a single timestep of simulation dynamics to this service. + + In this instance, if any multi-timestep processes are currently occurring + (such as starting up or shutting down), then they are brought one step closer to + being finished. + + :param timestep: The current timestep number. (Amount of time since simulation episode began) + :type timestep: int + """ + super().apply_timestep(timestep=timestep) + + # count down to boot up + if self.start_up_countdown > 0: + self.start_up_countdown -= 1 + else: + if self.operating_state == NodeOperatingState.BOOTING: + self.operating_state = NodeOperatingState.ON + self.sys_log.info("Turned on") + for nic in self.nics.values(): + if nic._connected_link: + nic.enable() + + # count down to shut down + if self.shut_down_countdown > 0: + self.shut_down_countdown -= 1 + else: + if self.operating_state == NodeOperatingState.SHUTTING_DOWN: + self.operating_state = NodeOperatingState.OFF + self.sys_log.info("Turned off") + def power_on(self): """Power on the Node, enabling its NICs if it is in the OFF state.""" if self.operating_state == NodeOperatingState.OFF: - self.operating_state = NodeOperatingState.ON - self.sys_log.info("Turned on") - for nic in self.nics.values(): - if nic._connected_link: - nic.enable() + self.operating_state = NodeOperatingState.BOOTING + self.start_up_countdown = self.start_up_duration + + if self.start_up_duration <= 0: + self.operating_state = NodeOperatingState.ON + self.sys_log.info("Turned on") + for nic in self.nics.values(): + if nic._connected_link: + nic.enable() def power_off(self): """Power off the Node, disabling its NICs if it is in the ON state.""" if self.operating_state == NodeOperatingState.ON: for nic in self.nics.values(): nic.disable() - self.operating_state = NodeOperatingState.OFF - self.sys_log.info("Turned off") + self.operating_state = NodeOperatingState.SHUTTING_DOWN + self.shut_down_countdown = self.shut_down_duration + + if self.shut_down_duration >= 0: + self.operating_state = NodeOperatingState.OFF + self.sys_log.info("Turned off") def connect_nic(self, nic: NIC): """ @@ -1135,7 +1187,7 @@ class Node(SimComponent): f"Ping statistics for {target_ip_address}: " f"Packets: Sent = {pings}, " f"Received = {request_replies}, " - f"Lost = {pings-request_replies} ({(pings-request_replies)/pings*100}% loss)" + f"Lost = {pings - request_replies} ({(pings - request_replies) / pings * 100}% loss)" ) return passed return False diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index be20f89f..25d1bd21 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -1,7 +1,7 @@ from ipaddress import IPv4Address from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.base import NIC +from primaite.simulator.network.hardware.base import NIC, NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.server import Server @@ -110,19 +110,19 @@ def arcd_uc2_network() -> Network: network = Network() # Router 1 - router_1 = Router(hostname="router_1", num_ports=5) + router_1 = Router(hostname="router_1", num_ports=5, operating_state=NodeOperatingState.ON) router_1.power_on() router_1.configure_port(port=1, ip_address="192.168.1.1", subnet_mask="255.255.255.0") router_1.configure_port(port=2, ip_address="192.168.10.1", subnet_mask="255.255.255.0") # Switch 1 - switch_1 = Switch(hostname="switch_1", num_ports=8) + switch_1 = Switch(hostname="switch_1", num_ports=8, operating_state=NodeOperatingState.ON) switch_1.power_on() network.connect(endpoint_a=router_1.ethernet_ports[1], endpoint_b=switch_1.switch_ports[8]) router_1.enable_port(1) # Switch 2 - switch_2 = Switch(hostname="switch_2", num_ports=8) + switch_2 = Switch(hostname="switch_2", num_ports=8, operating_state=NodeOperatingState.ON) switch_2.power_on() network.connect(endpoint_a=router_1.ethernet_ports[2], endpoint_b=switch_2.switch_ports[8]) router_1.enable_port(2) @@ -134,6 +134,7 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.10.1", dns_server=IPv4Address("192.168.1.10"), + operating_state=NodeOperatingState.ON, ) client_1.power_on() network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) @@ -148,6 +149,7 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.10.1", dns_server=IPv4Address("192.168.1.10"), + operating_state=NodeOperatingState.ON, ) client_2.power_on() network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) @@ -158,6 +160,7 @@ def arcd_uc2_network() -> Network: ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, ) domain_controller.power_on() domain_controller.software_manager.install(DNSServer) @@ -171,6 +174,7 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.1.1", dns_server=IPv4Address("192.168.1.10"), + operating_state=NodeOperatingState.ON, ) database_server.power_on() network.connect(endpoint_b=database_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[3]) @@ -244,6 +248,7 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.1.1", dns_server=IPv4Address("192.168.1.10"), + operating_state=NodeOperatingState.ON, ) web_server.power_on() web_server.software_manager.install(DatabaseClient) @@ -267,6 +272,7 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.1.1", dns_server=IPv4Address("192.168.1.10"), + operating_state=NodeOperatingState.ON, ) backup_server.power_on() backup_server.software_manager.install(FTPServer) @@ -279,6 +285,7 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.1.1", dns_server=IPv4Address("192.168.1.10"), + operating_state=NodeOperatingState.ON, ) security_suite.power_on() network.connect(endpoint_b=security_suite.ethernet_port[1], endpoint_a=switch_1.switch_ports[7]) diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index 85717b25..7da9fe76 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -1,17 +1,15 @@ -from primaite.simulator.network.hardware.base import Link, NIC, Node +from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState def test_node_to_node_ping(): """Tests two Nodes are able to ping each other.""" - node_a = Node(hostname="node_a") - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") + node_a = Node(hostname="node_a", operating_state=NodeOperatingState.ON) + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON) node_a.connect_nic(nic_a) - node_a.power_on() - node_b = Node(hostname="node_b") + node_b = Node(hostname="node_b", operating_state=NodeOperatingState.ON) nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") node_b.connect_nic(nic_b) - node_b.power_on() Link(endpoint_a=nic_a, endpoint_b=nic_b) @@ -20,22 +18,19 @@ def test_node_to_node_ping(): def test_multi_nic(): """Tests that Nodes with multiple NICs can ping each other and the data go across the correct links.""" - node_a = Node(hostname="node_a") + node_a = Node(hostname="node_a", operating_state=NodeOperatingState.ON) nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") node_a.connect_nic(nic_a) - node_a.power_on() - node_b = Node(hostname="node_b") + node_b = Node(hostname="node_b", operating_state=NodeOperatingState.ON) nic_b1 = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") nic_b2 = NIC(ip_address="10.0.0.12", subnet_mask="255.0.0.0") node_b.connect_nic(nic_b1) node_b.connect_nic(nic_b2) - node_b.power_on() - node_c = Node(hostname="node_c") + node_c = Node(hostname="node_c", operating_state=NodeOperatingState.ON) nic_c = NIC(ip_address="10.0.0.13", subnet_mask="255.0.0.0") node_c.connect_nic(nic_c) - node_c.power_on() Link(endpoint_a=nic_a, endpoint_b=nic_b1) diff --git a/tests/integration_tests/network/test_link_connection.py b/tests/integration_tests/network/test_link_connection.py index ef65f078..0ddf54df 100644 --- a/tests/integration_tests/network/test_link_connection.py +++ b/tests/integration_tests/network/test_link_connection.py @@ -1,17 +1,15 @@ -from primaite.simulator.network.hardware.base import Link, NIC, Node +from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState def test_link_up(): """Tests Nodes, NICs, and Links can all be connected and be in an enabled/up state.""" - node_a = Node(hostname="node_a") + node_a = Node(hostname="node_a", operating_state=NodeOperatingState.ON) nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") node_a.connect_nic(nic_a) - node_a.power_on() - node_b = Node(hostname="node_b") + node_b = Node(hostname="node_b", operating_state=NodeOperatingState.ON) nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") node_b.connect_nic(nic_b) - node_b.power_on() link = Link(endpoint_a=nic_a, endpoint_b=nic_b) diff --git a/tests/integration_tests/network/test_routing.py b/tests/integration_tests/network/test_routing.py index cb420e22..6053c457 100644 --- a/tests/integration_tests/network/test_routing.py +++ b/tests/integration_tests/network/test_routing.py @@ -2,7 +2,7 @@ from typing import Tuple import pytest -from primaite.simulator.network.hardware.base import Link, NIC, Node +from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState from primaite.simulator.network.hardware.nodes.router import ACLAction, Router from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -10,18 +10,15 @@ from primaite.simulator.network.transmission.transport_layer import Port @pytest.fixture(scope="function") def pc_a_pc_b_router_1() -> Tuple[Node, Node, Router]: - pc_a = Node(hostname="pc_a", default_gateway="192.168.0.1") + pc_a = Node(hostname="pc_a", default_gateway="192.168.0.1", operating_state=NodeOperatingState.ON) nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") pc_a.connect_nic(nic_a) - pc_a.power_on() - pc_b = Node(hostname="pc_b", default_gateway="192.168.1.1") + pc_b = Node(hostname="pc_b", default_gateway="192.168.1.1", operating_state=NodeOperatingState.ON) nic_b = NIC(ip_address="192.168.1.10", subnet_mask="255.255.255.0") pc_b.connect_nic(nic_b) - pc_b.power_on() - router_1 = Router(hostname="router_1") - router_1.power_on() + router_1 = Router(hostname="router_1", operating_state=NodeOperatingState.ON) router_1.configure_port(1, "192.168.0.1", "255.255.255.0") router_1.configure_port(2, "192.168.1.1", "255.255.255.0") diff --git a/tests/integration_tests/network/test_switched_network.py b/tests/integration_tests/network/test_switched_network.py index dc7742f4..5b305702 100644 --- a/tests/integration_tests/network/test_switched_network.py +++ b/tests/integration_tests/network/test_switched_network.py @@ -1,4 +1,4 @@ -from primaite.simulator.network.hardware.base import Link +from primaite.simulator.network.hardware.base import Link, NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.hardware.nodes.switch import Switch @@ -7,17 +7,22 @@ from primaite.simulator.network.hardware.nodes.switch import Switch def test_switched_network(): """Tests a node can ping another node via the switch.""" client_1 = Computer( - hostname="client_1", ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.0" + hostname="client_1", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.0", + operating_state=NodeOperatingState.ON, ) - client_1.power_on() server_1 = Server( - hostname=" server_1", ip_address="192.168.1.11", subnet_mask="255.255.255.0", default_gateway="192.168.1.11" + hostname=" server_1", + ip_address="192.168.1.11", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.11", + operating_state=NodeOperatingState.ON, ) - server_1.power_on() - switch_1 = Switch(hostname="switch_1", num_ports=6) - switch_1.power_on() + switch_1 = Switch(hostname="switch_1", num_ports=6, operating_state=NodeOperatingState.ON) Link(endpoint_a=client_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[1]) Link(endpoint_a=server_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[2]) diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py index c956682f..e03e1d28 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py @@ -11,13 +11,31 @@ def node() -> Node: def test_node_startup(node): assert node.operating_state == NodeOperatingState.OFF node.apply_request(["startup"]) + assert node.operating_state == NodeOperatingState.BOOTING + + idx = 0 + while node.operating_state == NodeOperatingState.BOOTING: + node.apply_timestep(timestep=idx) + idx += 1 + assert node.operating_state == NodeOperatingState.ON def test_node_shutdown(node): assert node.operating_state == NodeOperatingState.OFF node.apply_request(["startup"]) + idx = 0 + while node.operating_state == NodeOperatingState.BOOTING: + node.apply_timestep(timestep=idx) + idx += 1 + assert node.operating_state == NodeOperatingState.ON node.apply_request(["shutdown"]) + + idx = 0 + while node.operating_state == NodeOperatingState.SHUTTING_DOWN: + node.apply_timestep(timestep=idx) + idx += 1 + assert node.operating_state == NodeOperatingState.OFF From 1e66795affe13aa9bf24ff9fd62511963e5570d6 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 24 Oct 2023 10:43:00 +0100 Subject: [PATCH 242/980] #1947: remove scan from components that cannot be scanned --- src/primaite/simulator/core.py | 4 ---- src/primaite/simulator/file_system/file_system.py | 13 +++---------- src/primaite/simulator/system/services/service.py | 3 --- src/primaite/simulator/system/software.py | 2 -- 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index fb6db3ac..9ead877e 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -196,10 +196,6 @@ class SimComponent(BaseModel): } return state - def scan(self) -> None: - """Update the visible statuses of the SimComponent.""" - pass - def apply_request(self, request: List[str], context: Dict = {}) -> None: """ Apply a request to a simulation component. Request data is passed in as a 'namespaced' list of strings. diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 72ca1b51..59a00c6f 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -119,12 +119,6 @@ class FileSystemItemABC(SimComponent): """ return convert_size(self.size) - def scan(self) -> None: - """Update the FileSystemItem states.""" - super().scan() - - self.visible_health_status = self.health_status - @abstractmethod def check_hash(self) -> bool: """ @@ -514,6 +508,8 @@ class Folder(FileSystemItemABC): # scan one file per timestep file = self.get_file_by_id(file_uuid=list(self.files)[self.scan_duration - 1]) file.scan() + if file.visible_health_status == FileSystemItemHealthStatus.CORRUPTED: + self.visible_health_status = FileSystemItemHealthStatus.CORRUPTED self.scan_duration -= 1 def get_file(self, file_name: str) -> Optional[File]: @@ -613,8 +609,6 @@ class Folder(FileSystemItemABC): def scan(self) -> None: """Update Folder visible status.""" - super().scan() - if self.scan_duration <= -1: # scan one file per timestep self.scan_duration = len(self.files) @@ -799,10 +793,9 @@ class File(FileSystemItemABC): def scan(self) -> None: """Updates the visible statuses of the file.""" - super().scan() - path = self.folder.name + "/" + self.name self.folder.fs.sys_log.info(f"Scanning file {self.sim_path if self.sim_path else path}") + self.visible_health_status = self.health_status def check_hash(self) -> bool: """ diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index aa2fef5e..24de027c 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -84,9 +84,6 @@ class Service(IOSoftware): def scan(self) -> None: """Update the service visible states.""" - # update parent states - super().scan() - # update the visible operating state self.health_state_visible = self.health_state_actual diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 0d25a89f..cfc0e56f 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -175,8 +175,6 @@ class Software(SimComponent): def scan(self) -> None: """Update the observed health status to match the actual health status.""" - super().scan() - self.health_state_visible = self.health_state_actual From 6b7c483a678f1941f3fa8998f13e010352d04f16 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 24 Oct 2023 11:07:25 +0100 Subject: [PATCH 243/980] Align observations to Common approach --- example_config.yaml | 31 +++++----- src/primaite/game/agent/observations.py | 78 +++++++++++++------------ 2 files changed, 59 insertions(+), 50 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index 00beaa1e..bcc819ae 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -2,10 +2,10 @@ training_config: rl_framework: SB3 rl_algorithm: PPO seed: 333 - n_learn_episodes: 4 - n_learn_steps: 128 - n_eval_episodes: 1 - n_eval_steps: 128 + n_learn_episodes: 1 + n_learn_steps: 8 + n_eval_episodes: 0 + n_eval_steps: 8 game_config: @@ -39,10 +39,10 @@ game_config: options: nodes: - node_ref: client_2 - max_folders_per_node: 2 - max_files_per_folder: 2 - max_services_per_node: 2 - max_nics_per_node: 8 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 max_acl_rules: 10 reward_function: @@ -93,9 +93,9 @@ game_config: options: nodes: - node_ref: client_1 - max_folders_per_node: 2 - max_files_per_folder: 2 - max_services_per_node: 2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 reward_function: reward_components: @@ -113,9 +113,10 @@ game_config: observation_space: type: UC2BlueObservation options: - num_services_per_node: 2 - num_folders_per_node: 2 - num_files_per_folder: 2 + num_services_per_node: 1 + num_folders_per_node: 1 + num_files_per_folder: 1 + num_nics_per_node: 2 nodes: - node_ref: domain_controller services: @@ -148,6 +149,8 @@ game_config: - link_ref: switch_2___client_2 - link_ref: switch_2___security_suite acl: + options: + max_acl_rules: 10 router_node_ref: router_1 ip_address_order: - node_ref: domain_controller diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 35fe8ac5..8eb322bd 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -167,7 +167,7 @@ class ServiceObservation(AbstractObservation): class LinkObservation(AbstractObservation): """Observation of a link in the network.""" - default_observation: spaces.Space = {"protocols": {"all": {"load": 0}}} + default_observation: spaces.Space = {"PROTOCOLS": {"ALL": 0}} "Default observation is what should be returned when the link doesn't exist." def __init__(self, where: Optional[Tuple[str]] = None) -> None: @@ -206,7 +206,7 @@ class LinkObservation(AbstractObservation): utilisation_category = int(utilisation_fraction * 10) + 1 # TODO: once the links support separte load per protocol, this needs amendment to reflect that. - return {"protocols": {"all": {"load": utilisation_category}}} + return {"PROTOCOLS": {"ALL": utilisation_category}} @property def space(self) -> spaces.Space: @@ -215,7 +215,7 @@ class LinkObservation(AbstractObservation): :return: Gymnasium space :rtype: spaces.Space """ - return spaces.Dict({"protocols": spaces.Dict({"all": spaces.Dict({"load": spaces.Discrete(11)})})}) + return spaces.Dict({"PROTOCOLS": spaces.Dict({"ALL": spaces.Discrete(11)})}) @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession") -> "LinkObservation": @@ -264,7 +264,6 @@ class FolderObservation(AbstractObservation): truncated_file = self.files.pop() msg = f"Too many files in folde observation. Truncating file {truncated_file}" _LOGGER.warn(msg) - raise UserWarning(msg) self.default_observation = { "health_status": 0, @@ -407,6 +406,7 @@ class NodeObservation(AbstractObservation): num_services_per_node: int = 2, num_folders_per_node: int = 2, num_files_per_folder: int = 2, + num_nics_per_node: int = 2, ) -> None: """ Configurable observation for a node in the simulation. @@ -440,18 +440,25 @@ class NodeObservation(AbstractObservation): truncated_service = self.services.pop() msg = f"Too many services in Node observation space for node. Truncating service {truncated_service.where}" _LOGGER.warn(msg) - raise UserWarning(msg) # truncate service list self.folders: List[FolderObservation] = folders # add empty folder observation without `where` parameter that will always return default (blank) observations while len(self.folders) < num_folders_per_node: - self.folders.append(FolderObservation()) + self.folders.append(FolderObservation(num_files_per_folder=num_files_per_folder)) while len(self.folders) > num_folders_per_node: truncated_folder = self.folders.pop() msg = f"Too many folders in Node observation for node. Truncating service {truncated_folder.where[-1]}" + _LOGGER.warn(msg) self.nics: List[NicObservation] = nics + while len(self.nics) < num_nics_per_node: + self.nics.append(NicObservation()) + while len(self.nics) > num_nics_per_node: + truncated_nic = self.nics.pop() + msg = f"Too many NICs in Node observation for node. Truncating service {truncated_nic.where[-1]}" + _LOGGER.warn(msg) + self.logon_status: bool = logon_status self.default_observation: Dict = { @@ -512,6 +519,7 @@ class NodeObservation(AbstractObservation): num_services_per_node: int = 2, num_folders_per_node: int = 2, num_files_per_folder: int = 2, + num_nics_per_node: int = 2, ) -> "NodeObservation": """Create node observation from a config. Also creates child service, folder and NIC observations. @@ -562,6 +570,7 @@ class NodeObservation(AbstractObservation): num_services_per_node=num_services_per_node, num_folders_per_node=num_folders_per_node, num_files_per_folder=num_files_per_folder, + num_nics_per_node=num_nics_per_node, ) @@ -605,19 +614,17 @@ class AclObservation(AbstractObservation): self.protocol_to_id: Dict[str, int] = {protocol: i + 2 for i, protocol in enumerate(protocols)} "List of protocols which are part of the game, defines ordering when converting to an ID" self.default_observation: Dict = { - "RULES": { - i - + 1: { - "position": i, - "permission": 0, - "source_node_id": 0, - "source_port": 0, - "dest_node_id": 0, - "dest_port": 0, - "protocol": 0, - } - for i in range(self.num_rules) + i + + 1: { + "position": i, + "permission": 0, + "source_node_id": 0, + "source_port": 0, + "dest_node_id": 0, + "dest_port": 0, + "protocol": 0, } + for i in range(self.num_rules) } def observe(self, state: Dict) -> Dict: @@ -636,10 +643,9 @@ class AclObservation(AbstractObservation): # TODO: what if the ACL has more rules than num of max rules for obs space obs = {} - obs["RULES"] = {} for i, rule_state in acl_state.items(): if rule_state is None: - obs["RULES"][i + 1] = { + obs[i + 1] = { "position": i, "permission": 0, "source_node_id": 0, @@ -649,7 +655,7 @@ class AclObservation(AbstractObservation): "protocol": 0, } else: - obs["RULES"][i + 1] = { + obs[i + 1] = { "position": i, "permission": rule_state["action"], "source_node_id": self.node_to_id[rule_state["src_ip_address"]], @@ -669,24 +675,20 @@ class AclObservation(AbstractObservation): """ return spaces.Dict( { - "RULES": spaces.Dict( + i + + 1: spaces.Dict( { - i - + 1: spaces.Dict( - { - "position": spaces.Discrete(self.num_rules), - "permission": spaces.Discrete(3), - # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) - "source_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), - "source_port": spaces.Discrete(len(self.port_to_id) + 2), - "dest_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), - "dest_port": spaces.Discrete(len(self.port_to_id) + 2), - "protocol": spaces.Discrete(len(self.protocol_to_id) + 2), - } - ) - for i in range(self.num_rules) + "position": spaces.Discrete(self.num_rules), + "permission": spaces.Discrete(3), + # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) + "source_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), + "source_port": spaces.Discrete(len(self.port_to_id) + 2), + "dest_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), + "dest_port": spaces.Discrete(len(self.port_to_id) + 2), + "protocol": spaces.Discrete(len(self.protocol_to_id) + 2), } ) + for i in range(self.num_rules) } ) @@ -701,6 +703,7 @@ class AclObservation(AbstractObservation): :return: Observation object :rtype: AclObservation """ + max_acl_rules = config["options"]["max_acl_rules"] node_ip_to_idx = {} for ip_idx, ip_map_config in enumerate(config["ip_address_order"]): node_ref = ip_map_config["node_ref"] @@ -715,6 +718,7 @@ class AclObservation(AbstractObservation): ports=session.options.ports, protocols=session.options.protocols, where=["network", "nodes", router_uuid, "acl", "acl"], + num_rules=max_acl_rules, ) @@ -846,6 +850,7 @@ class UC2BlueObservation(AbstractObservation): num_services_per_node = config["num_services_per_node"] num_folders_per_node = config["num_folders_per_node"] num_files_per_folder = config["num_files_per_folder"] + num_nics_per_node = config["num_nics_per_node"] nodes = [ NodeObservation.from_config( config=n, @@ -853,6 +858,7 @@ class UC2BlueObservation(AbstractObservation): num_services_per_node=num_services_per_node, num_folders_per_node=num_folders_per_node, num_files_per_folder=num_files_per_folder, + num_nics_per_node=num_nics_per_node, ) for n in node_configs ] From 174de013fbd7b99afe5af662bdfa5e76d38b4aad Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 24 Oct 2023 11:43:25 +0100 Subject: [PATCH 244/980] Align blue actions with common env --- example_config.yaml | 73 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/example_config.yaml b/example_config.yaml index bcc819ae..1e1150d8 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -420,13 +420,84 @@ game_config: 38: action: "NETWORK_NIC_DISABLE" options: - node_id: 6 + node_id: 1 nic_id: 1 39: action: "NETWORK_NIC_ENABLE" + options: + node_id: 1 + nic_id: 1 + 40: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 2 + nic_id: 1 + 41: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 2 + nic_id: 1 + 42: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 3 + nic_id: 1 + 43: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 3 + nic_id: 1 + 44: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 4 + nic_id: 1 + 45: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 4 + nic_id: 1 + 46: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 5 + nic_id: 1 + 47: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 5 + nic_id: 1 + 48: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 5 + nic_id: 2 + 49: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 5 + nic_id: 2 + 50: + action: "NETWORK_NIC_DISABLE" options: node_id: 6 nic_id: 1 + 51: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 6 + nic_id: 1 + 52: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 7 + nic_id: 1 + 53: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 7 + nic_id: 1 + options: nodes: From c4b43c479e634f9b4bd8ea06a8bb131560420c05 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 24 Oct 2023 11:53:21 +0100 Subject: [PATCH 245/980] #1947: remove storing deleted files in a list and banish them to the shadow realm instead --- .../simulator/file_system/file_system.py | 149 ++++++++---------- .../_file_system/test_file_system.py | 49 +++--- .../_file_system/test_file_system_actions.py | 62 +++++--- 3 files changed, 122 insertions(+), 138 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 59a00c6f..55af71c4 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -1,6 +1,5 @@ from __future__ import annotations -import copy import hashlib import json import math @@ -53,14 +52,17 @@ class FileSystemItemHealthStatus(Enum): GOOD = 0 """File/Folder is OK.""" - QUARANTINED = 1 + COMPROMISED = 1 """File/Folder is quarantined.""" - CORRUPTED = 2 + CORRUPT = 2 """File/Folder is corrupted.""" - DELETED = 3 - """File/Folder is deleted.""" + RESTORING = 3 + """File/Folder is in the process of being restored.""" + + REPAIRING = 3 + """File/Folder is in the process of being repaired.""" class FileSystemItemABC(SimComponent): @@ -128,9 +130,7 @@ class FileSystemItemABC(SimComponent): Return False if corruption is detected, otherwise True """ - # cannot check hash if deleted - if self.health_status == FileSystemItemHealthStatus.DELETED: - return False + pass @abstractmethod def repair(self) -> bool: @@ -139,9 +139,7 @@ class FileSystemItemABC(SimComponent): True if successfully repaired. False otherwise. """ - # cannot repair if deleted - if self.health_status == FileSystemItemHealthStatus.DELETED: - return False + pass @abstractmethod def corrupt(self) -> bool: @@ -150,17 +148,7 @@ class FileSystemItemABC(SimComponent): True if successfully corrupted. False otherwise. """ - # cannot corrupt if deleted - if self.health_status == FileSystemItemHealthStatus.DELETED: - return False - - def delete(self) -> None: - """ - Delete the FileSystemItem. - - True if successfully deleted. False otherwise. - """ - self.health_status = FileSystemItemHealthStatus.DELETED + pass def restore(self) -> None: """Restore the file/folder to the state before it got ruined.""" @@ -176,8 +164,6 @@ class FileSystem(SimComponent): sys_log: SysLog sim_root: Path - deleted_folders: Dict[str, Folder] = {} - def __init__(self, **kwargs): super().__init__(**kwargs) # Ensure a default root folder @@ -187,6 +173,11 @@ class FileSystem(SimComponent): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() + rm.add_request( + name="delete", + request_type=RequestType(func=lambda request, context: self.delete_folder_by_id(folder_uuid=request[0])), + ) + self._folder_request_manager = RequestManager() rm.add_request("folder", RequestType(func=self._folder_request_manager)) @@ -271,18 +262,25 @@ class FileSystem(SimComponent): return folder = self._folders_by_name.get(folder_name) if folder: - # add to deleted list - folder.delete() - self.deleted_folders[folder.uuid] = folder - - # remove from normal list + # remove from folder list self.folders.pop(folder.uuid) self._folders_by_name.pop(folder.name) self.sys_log.info(f"Deleted folder /{folder.name} and its contents") self._folder_request_manager.remove_request(folder.uuid) + folder.remove_all_files() + else: _LOGGER.debug(f"Cannot delete folder as it does not exist: {folder_name}") + def delete_folder_by_id(self, folder_uuid: str): + """ + Deletes a folder via its uuid. + + :param: folder_uuid: UUID of the folder to delete + """ + folder = self.get_folder_by_id(folder_uuid=folder_uuid) + self.delete_folder(folder_name=folder.name) + def restore_folder(self, folder_id: str): """TODO.""" pass @@ -423,19 +421,13 @@ class FileSystem(SimComponent): """ return self._folders_by_name.get(folder_name) - def get_folder_by_id(self, folder_uuid: str, show_deleted: bool = False) -> Optional[Folder]: + def get_folder_by_id(self, folder_uuid: str) -> Optional[Folder]: """ Get a folder by its uuid if it exists. :param: folder_uuid: The folder uuid. - :param: show_deleted: show deleted folders :return: The matching Folder. """ - deleted_folder = self.deleted_folders.get(folder_uuid) - - if show_deleted and deleted_folder: - return deleted_folder - return self.folders.get(folder_uuid) @@ -449,12 +441,17 @@ class Folder(FileSystemItemABC): _files_by_name: Dict[str, File] = {} "Files by their name as .." - deleted_files: Dict[str, File] = {} - "List of files that have been deleted." - scan_duration: int = -1 "How many timesteps to complete a scan." + def _init_request_manager(self) -> RequestManager: + rm = super()._init_request_manager() + rm.add_request( + name="delete", + request_type=RequestType(func=lambda request, context: self.remove_file_by_id(file_uuid=request[0])), + ) + return rm + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -463,7 +460,6 @@ class Folder(FileSystemItemABC): """ state = super().describe_state() state["files"] = {file.name: file.describe_state() for uuid, file in self.files.items()} - state["deleted_files"] = {file.name: file.describe_state() for uuid, file in self.deleted_files.items()} return state def show(self, markdown: bool = False): @@ -508,8 +504,8 @@ class Folder(FileSystemItemABC): # scan one file per timestep file = self.get_file_by_id(file_uuid=list(self.files)[self.scan_duration - 1]) file.scan() - if file.visible_health_status == FileSystemItemHealthStatus.CORRUPTED: - self.visible_health_status = FileSystemItemHealthStatus.CORRUPTED + if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: + self.visible_health_status = FileSystemItemHealthStatus.CORRUPT self.scan_duration -= 1 def get_file(self, file_name: str) -> Optional[File]: @@ -524,19 +520,13 @@ class Folder(FileSystemItemABC): # TODO: Increment read count? return self._files_by_name.get(file_name) - def get_file_by_id(self, file_uuid: str, show_deleted: bool = False) -> File: + def get_file_by_id(self, file_uuid: str) -> File: """ Get a file by its uuid. :param: file_uuid: The file uuid. - :param: show_deleted: show deleted files :return: The matching File. """ - deleted_file = self.deleted_files.get(file_uuid) - - if show_deleted and deleted_file: - return deleted_file - return self.files.get(file_uuid) def add_file(self, file: File): @@ -571,16 +561,25 @@ class Folder(FileSystemItemABC): raise Exception(f"Invalid file: {file}") if self.files.get(file.uuid): - # add to deleted list - file.delete() - self.deleted_files[file.uuid] = file - - # remove from normal file list self.files.pop(file.uuid) self._files_by_name.pop(file.name) else: _LOGGER.debug(f"File with UUID {file.uuid} was not found.") + def remove_file_by_id(self, file_uuid: str): + """ + Remove a file using id. + + :param: file_uuid: The UUID of the file to remove. + """ + file = self.get_file_by_id(file_uuid=file_uuid) + self.remove_file(file=file) + + def remove_all_files(self): + """Removes all the files in the folder.""" + self.files = {} + self._files_by_name = {} + def restore_file(self, file: Optional[File]): """ Restores a file. @@ -593,19 +592,15 @@ class Folder(FileSystemItemABC): def quarantine(self): """Quarantines the File System Folder.""" - if self.health_status != FileSystemItemHealthStatus.QUARANTINED: - self.health_status = FileSystemItemHealthStatus.QUARANTINED - self.fs.sys_log.info(f"Quarantined folder ./{self.name}") + pass def unquarantine(self): """Unquarantine of the File System Folder.""" - if self.health_status == FileSystemItemHealthStatus.QUARANTINED: - self.health_status = FileSystemItemHealthStatus.GOOD - self.fs.sys_log.info(f"Quarantined folder ./{self.name}") + pass def quarantine_status(self) -> bool: """Returns true if the folder is being quarantined.""" - return self.health_status == FileSystemItemHealthStatus.QUARANTINED + pass def scan(self) -> None: """Update Folder visible status.""" @@ -657,7 +652,7 @@ class Folder(FileSystemItemABC): repaired = file.repair() # set file status to good if corrupt - if self.health_status == FileSystemItemHealthStatus.CORRUPTED: + if self.health_status == FileSystemItemHealthStatus.CORRUPT: self.health_status = FileSystemItemHealthStatus.GOOD repaired = True @@ -668,21 +663,8 @@ class Folder(FileSystemItemABC): """TODO.""" pass - def delete(self): - """Deletes the files within the folder and then deletes the folder.""" - super().delete() - - # iterate through the files in the folder - files = copy.copy(self.files) - for file_id in files: - file = self.get_file_by_id(file_uuid=file_id) - file.delete() - self.remove_file(file) - - self.fs.sys_log.info(f"Deleted folder {self.name} (id: {self.uuid})") - def corrupt(self) -> bool: - """Corrupt a File by setting the folder and containing files status to FileSystemItemStatus.CORRUPTED.""" + """Corrupt a File by setting the folder and containing files status to FileSystemItemStatus.CORRUPT.""" super().corrupt() corrupted = False @@ -694,7 +676,7 @@ class Folder(FileSystemItemABC): # set file status to corrupt if good if self.health_status == FileSystemItemHealthStatus.GOOD: - self.health_status = FileSystemItemHealthStatus.CORRUPTED + self.health_status = FileSystemItemHealthStatus.CORRUPT corrupted = True self.fs.sys_log.info(f"Corrupted folder {self.name} (id: {self.uuid})") @@ -830,19 +812,12 @@ class File(FileSystemItemABC): return True - def delete(self) -> None: - """Deletes the file.""" - super().delete() - - path = self.folder.name + "/" + self.name - self.folder.fs.sys_log.info(f"Deleting file {self.sim_path if self.sim_path else path}") - def repair(self) -> bool: """Repair a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" super().repair() # set file status to good if corrupt - if self.health_status == FileSystemItemHealthStatus.CORRUPTED: + if self.health_status == FileSystemItemHealthStatus.CORRUPT: self.health_status = FileSystemItemHealthStatus.GOOD path = self.folder.name + "/" + self.name @@ -854,14 +829,14 @@ class File(FileSystemItemABC): pass def corrupt(self) -> bool: - """Corrupt a File by setting the status to FileSystemItemStatus.CORRUPTED.""" + """Corrupt a File by setting the status to FileSystemItemStatus.CORRUPT.""" super().corrupt() corrupted = False # set file status to good if corrupt if self.health_status == FileSystemItemHealthStatus.GOOD: - self.health_status = FileSystemItemHealthStatus.CORRUPTED + self.health_status = FileSystemItemHealthStatus.CORRUPT corrupted = True path = self.folder.name + "/" + self.name diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 6cf1df25..2404f30d 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -44,7 +44,6 @@ def test_delete_file(file_system): file_system.delete_file(folder_name="root", file_name="test_file.txt") assert len(file_system.folders) == 1 assert len(file_system.get_folder("root").files) == 0 - assert len(file_system.get_folder("root").deleted_files) == 1 def test_delete_non_existent_file(file_system): @@ -70,7 +69,6 @@ def test_delete_folder(file_system): file_system.delete_folder(folder_name="test_folder") assert len(file_system.folders) == 1 - assert len(file_system.deleted_folders) == 1 def test_deleting_a_non_existent_folder(file_system): @@ -97,13 +95,11 @@ def test_move_file(file_system): original_uuid = file.uuid assert len(file_system.get_folder("src_folder").files) == 1 - assert len(file_system.get_folder("src_folder").deleted_files) == 0 assert len(file_system.get_folder("dst_folder").files) == 0 file_system.move_file(src_folder_name="src_folder", src_file_name="test_file.txt", dst_folder_name="dst_folder") assert len(file_system.get_folder("src_folder").files) == 0 - assert len(file_system.get_folder("src_folder").deleted_files) == 1 assert len(file_system.get_folder("dst_folder").files) == 1 assert file_system.get_file("dst_folder", "test_file.txt").uuid == original_uuid @@ -126,6 +122,7 @@ def test_copy_file(file_system): assert file_system.get_file("dst_folder", "test_file.txt").uuid != original_uuid +@pytest.mark.skip(reason="Implementation for quarantine not needed yet") def test_folder_quarantine_state(file_system): """Tests the changing of folder quarantine status.""" folder = file_system.get_folder("root") @@ -147,7 +144,7 @@ def test_file_corrupt_repair(file_system): file.corrupt() assert folder.health_status == FileSystemItemHealthStatus.GOOD - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPT file.repair() @@ -163,8 +160,8 @@ def test_folder_corrupt_repair(file_system): folder.corrupt() file = folder.get_file(file_name="test_file.txt") - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert file.health_status == FileSystemItemHealthStatus.CORRUPT folder.repair() @@ -183,13 +180,13 @@ def test_file_scan(file_system): file.corrupt() - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPT assert file.visible_health_status == FileSystemItemHealthStatus.GOOD file.scan() - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED - assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT def test_folder_scan(file_system): @@ -208,7 +205,7 @@ def test_folder_scan(file_system): folder.corrupt() - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD @@ -217,24 +214,24 @@ def test_folder_scan(file_system): folder.apply_timestep(timestep=0) - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED - assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPTED - assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD folder.apply_timestep(timestep=1) - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED - assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPTED - assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPTED - assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT folder.apply_timestep(timestep=2) - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED - assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPTED - assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPTED - assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT def test_simulated_file_check_hash(file_system): @@ -245,7 +242,7 @@ def test_simulated_file_check_hash(file_system): # change simulated file size file.sim_size = 0 assert file.check_hash() is False - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPT def test_real_file_check_hash(file_system): @@ -258,7 +255,7 @@ def test_real_file_check_hash(file_system): f.write("get hacked scrub lol xD\n") assert file.check_hash() is False - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPT def test_simulated_folder_check_hash(file_system): @@ -271,7 +268,7 @@ def test_simulated_folder_check_hash(file_system): file = folder.get_file(file_name="test_file.txt") file.sim_size = 0 assert folder.check_hash() is False - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT def test_real_folder_check_hash(file_system): @@ -288,7 +285,7 @@ def test_real_folder_check_hash(file_system): f.write("get hacked scrub lol xD\n") assert folder.check_hash() is False - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT @pytest.mark.skip(reason="Skipping until we tackle serialisation") diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py index ed06d2fb..23115fd7 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py @@ -19,13 +19,13 @@ def test_file_scan_request(populated_file_system): fs, folder, file = populated_file_system file.corrupt() - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPT assert file.visible_health_status == FileSystemItemHealthStatus.GOOD fs.apply_request(request=["file", file.uuid, "scan"]) - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED - assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT def test_folder_scan_request(populated_file_system): @@ -37,7 +37,7 @@ def test_folder_scan_request(populated_file_system): file2: File = folder.get_file_by_id(file_uuid=list(folder.files)[0]) folder.corrupt() - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD @@ -46,24 +46,24 @@ def test_folder_scan_request(populated_file_system): folder.apply_timestep(timestep=0) - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED - assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPTED - assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD folder.apply_timestep(timestep=1) - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED - assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPTED - assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPTED - assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT folder.apply_timestep(timestep=2) - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED - assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPTED - assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPTED - assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT def test_file_checkhash_request(populated_file_system): @@ -77,7 +77,7 @@ def test_file_checkhash_request(populated_file_system): fs.apply_request(request=["file", file.uuid, "checkhash"]) - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPT def test_folder_checkhash_request(populated_file_system): @@ -90,7 +90,7 @@ def test_folder_checkhash_request(populated_file_system): file.sim_size = 0 fs.apply_request(request=["folder", folder.uuid, "checkhash"]) - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT def test_file_repair_request(populated_file_system): @@ -98,7 +98,7 @@ def test_file_repair_request(populated_file_system): fs, folder, file = populated_file_system file.corrupt() - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPT fs.apply_request(request=["file", file.uuid, "repair"]) assert file.health_status == FileSystemItemHealthStatus.GOOD @@ -109,8 +109,8 @@ def test_folder_repair_request(populated_file_system): fs, folder, file = populated_file_system folder.corrupt() - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT fs.apply_request(request=["folder", folder.uuid, "repair"]) assert file.health_status == FileSystemItemHealthStatus.GOOD @@ -129,20 +129,32 @@ def test_file_corrupt_request(populated_file_system): """Test that an agent can request a file corruption.""" fs, folder, file = populated_file_system fs.apply_request(request=["file", file.uuid, "corrupt"]) - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPT def test_folder_corrupt_request(populated_file_system): """Test that an agent can request a folder corruption.""" fs, folder, file = populated_file_system fs.apply_request(request=["folder", folder.uuid, "corrupt"]) - assert file.health_status == FileSystemItemHealthStatus.CORRUPTED - assert folder.health_status == FileSystemItemHealthStatus.CORRUPTED + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT def test_file_delete_request(populated_file_system): - pass + """Test that an agent can request a file deletion.""" + fs, folder, file = populated_file_system + assert folder.get_file_by_id(file_uuid=file.uuid) is not None + + fs.apply_request(request=["folder", folder.uuid, "delete", file.uuid]) + assert folder.get_file_by_id(file_uuid=file.uuid) is None def test_folder_delete_request(populated_file_system): - pass + """Test that an agent can request a folder deletion.""" + fs, folder, file = populated_file_system + assert folder.get_file_by_id(file_uuid=file.uuid) is not None + assert fs.get_folder_by_id(folder_uuid=folder.uuid) is not None + + fs.apply_request(request=["delete", folder.uuid]) + assert fs.get_folder_by_id(folder_uuid=folder.uuid) is None + assert folder.get_file_by_id(file_uuid=file.uuid) is None From ac23633d820ad656d73dd6e752e0c09a6da0f5ac Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 24 Oct 2023 15:41:39 +0100 Subject: [PATCH 246/980] #1947: Added documentation on how the node initialisation works --- docs/source/action_system.rst | 6 +- .../network/base_hardware.rst | 132 +++++++++++------- .../simulator/network/hardware/base.py | 22 +-- 3 files changed, 99 insertions(+), 61 deletions(-) diff --git a/docs/source/action_system.rst b/docs/source/action_system.rst index f6d237ba..88baf232 100644 --- a/docs/source/action_system.rst +++ b/docs/source/action_system.rst @@ -27,7 +27,7 @@ Just like other aspects of SimComponent, the actions are not managed centrally f 4. ``Service`` receives ``['restart']``. Since ``restart`` is a defined action in the service's own RequestManager, the service performs a restart. -Techincal Detail +Technical Detail ================ This system was achieved by implementing two classes, :py:class:`primaite.simulator.core.Action`, and :py:class:`primaite.simulator.core.RequestManager`. @@ -35,12 +35,12 @@ This system was achieved by implementing two classes, :py:class:`primaite.simula Action ------ -The ``Action`` object stores a reference to a method that performs the action, for example a node could have an action that stores a reference to ``self.turn_on()``. Techincally, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using ``lambda`` functions within a component's ``self._init_request_manager()`` method. Optionally, the ``Action`` object can also hold a validator that will permit/deny the action depending on context. +The ``Action`` object stores a reference to a method that performs the action, for example a node could have an action that stores a reference to ``self.turn_on()``. Technically, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using ``lambda`` functions within a component's ``self._init_request_manager()`` method. Optionally, the ``Action`` object can also hold a validator that will permit/deny the action depending on context. RequestManager ------------- -The ``RequestManager`` object stores a mapping between strings and actions. It is responsible for processing the ``request`` and passing it down the ownership tree. Techincally, the ``RequestManager`` is itself a callable that accepts `request, context` tuple, and so it can be chained with other action managers. +The ``RequestManager`` object stores a mapping between strings and actions. It is responsible for processing the ``request`` and passing it down the ownership tree. Technically, the ``RequestManager`` is itself a callable that accepts `request, context` tuple, and so it can be chained with other action managers. A simple example without chaining can be seen in the :py:class:`primaite.simulator.file_system.file_system.File` class. diff --git a/docs/source/simulation_components/network/base_hardware.rst b/docs/source/simulation_components/network/base_hardware.rst index 452667d2..af4ec26c 100644 --- a/docs/source/simulation_components/network/base_hardware.rst +++ b/docs/source/simulation_components/network/base_hardware.rst @@ -2,20 +2,24 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +############# Base Hardware -============= +############# The physical layer components are models of a NIC (Network Interface Card), SwitchPort, Node, Switch, and a Link. These components allow modelling of layer 1 (physical layer) in the OSI model and the nodes that connect to and transmit across layer 1. +=== NIC -### +=== + The NIC class provides a realistic model of a Network Interface Card. The NIC acts as the interface between a Node and a Link, handling IP and MAC addressing, status, and sending/receiving frames. +---------- Addressing -********** +---------- A NIC has both an IPv4 address and MAC address assigned: @@ -24,8 +28,10 @@ A NIC has both an IPv4 address and MAC address assigned: - **gateway** - The default gateway IP address for routing traffic beyond the local network. - **mac_address** - A unique MAC address assigned to the NIC by the manufacturer. + +------ Status -****** +------ The status of the NIC is represented by: @@ -33,14 +39,17 @@ The status of the NIC is represented by: - **connected_node** - The Node instance the NIC is attached to. - **connected_link** - The Link instance the NIC is wired to. + +-------------- Packet Capture -************** +-------------- - **pcap** - A PacketCapture instance attached to the NIC for capturing all frames sent and received. This allows packet capture and analysis. +------------------------ Sending/Receiving Frames -************************ +------------------------ The NIC can send and receive Frames to/from the connected Link: @@ -50,8 +59,9 @@ The NIC can send and receive Frames to/from the connected Link: This allows a NIC to handle sending, receiving, and forwarding of network traffic at layer 2 of the OSI model. The Frames contain network data encapsulated with various protocol headers. +----------- Basic Usage -*********** +----------- .. code-block:: python @@ -64,8 +74,9 @@ Basic Usage frame = Frame(...) nic1.send_frame(frame) +========== SwitchPort -########## +========== The SwitchPort models a port on a network switch. It has similar attributes and methods to NIC for addressing, status, packet capture, sending/receiving frames, etc. @@ -75,26 +86,47 @@ Key attributes: - **port_num**: The port number on the switch. - **connected_switch**: The switch to which this port belongs. +==== Node -#### +==== The Node class represents a base node that communicates on the Network. +Nodes take more than 1 time step to power on (3 time steps by default). +To create a Node that is already powered on, the Node's operating state can be overriden. +Otherwise, the node ``start_up_duration`` (and ``shut_down_duration``) can be set to 0 if +the node will be powered off or on multiple times. This will still need ``power_on()`` to +be called to turn the node on. + +e.g. + +.. code-block:: python + + active_node = Node(hostname='server1', operating_state=NodeOperatingState.ON) + # node is already on, no need to call power_on() + + + instant_start_node = Node(hostname="client", start_up_duration=0, shut_down_duration=0) + instant_start_node.power_on() # node will still need to be powered on + +------------------ Network Interfaces -****************** +------------------ A Node will typically have one or more NICs attached to it for network connectivity: - **nics** - A dictionary containing the NIC instances attached to the Node. NICs can be added/removed. +------------- Configuration -************* +------------- - **hostname** - Configured hostname of the Node. - **operating_state** - Current operating state like ON or OFF. The NICs will be enabled/disabled based on this. +---------------- Network Services -**************** +---------------- A Node runs various network services and components for handling traffic: @@ -110,8 +142,9 @@ The SysLog records informational, warning, and error events that occur on the No debugging and tracing program execution and network activity for each simulated Node. Other Node services like ARP and ICMP, along with custom Applications, services, and Processes will log to the SysLog. +----------------- Sending/Receiving -***************** +----------------- The Node handles sending and receiving Frames via its attached NICs: @@ -119,8 +152,9 @@ The Node handles sending and receiving Frames via its attached NICs: - **receive_frame()** - Receives a Frame from the network through a NIC. The Node then processes it appropriately based on the protocols and payload. +----------- Basic Usage -*********** +----------- .. code-block:: python @@ -137,15 +171,16 @@ Basic Usage The Node class brings together the NICs, configuration, and services to model a full network node that can send, receive, process, and forward traffic on a simulated network. - +====== Switch -###### +====== The Switch subclass models a network switch. It inherits from Node and acts at layer 2 of the OSI model to forward frames based on MAC addresses. +-------------------------- Inherits Node Capabilities -************************** +-------------------------- Since Switch subclasses Node, it inherits all capabilities from Node like: @@ -154,16 +189,18 @@ Since Switch subclasses Node, it inherits all capabilities from Node like: - **Sending and receiving frames** - **Maintaining system logs** +----- Ports -***** +----- A Switch has multiple ports implemented using SwitchPort instances: - **switch_ports** - A dictionary mapping port numbers to SwitchPort instances. - **num_ports** - The number of ports the Switch has. +---------- Forwarding -********** +---------- A Switch forwards frames between ports based on the destination MAC: @@ -179,21 +216,24 @@ When a frame is received on a SwitchPort: This allows the Switch to dynamically build up a mapping table between MAC addresses and SwitchPorts based on traffic received. If no entry exists for a destination MAC, it floods the frame out all ports. +==== Link -#### +==== The Link class represents a physical link or connection between two network endpoints like NICs or SwitchPorts. +--------- Endpoints -********* +--------- A Link connects two endpoints: - **endpoint_a** - The first endpoint, a NIC or SwitchPort. - **endpoint_b** - The second endpoint, a NIC or SwitchPort. +------------ Transmission -************ +------------ Links transmit Frames between the endpoints: @@ -201,8 +241,9 @@ Links transmit Frames between the endpoints: Uses bandwidth/load properties to determine if transmission is possible. +---------------- Bandwidth & Load -**************** +---------------- - **bandwidth** - The total capacity of the Link in Mbps. - **current_load** - The current bandwidth utilization of the Link in Mbps. @@ -210,16 +251,18 @@ Bandwidth & Load As Frames are sent over the Link, the load increases. The Link tracks if there is enough unused capacity to transmit a Frame based on its size and the current load. +------ Status -****** +------ - **up** - Boolean indicating if the Link is currently up/active based on the endpoint status. - **endpoint_up()/down()** - Notifies the Link when an endpoint goes up or down. This allows the Link to realistically model the connection and transmission characteristics between two endpoints. +======================= Putting it all Together -####################### +======================= We'll now demonstrate how the nodes, NICs, switches, and links connect in a network, including full code examples and syslog extracts to illustrate the step-by-step process. @@ -230,35 +273,33 @@ PC's and two switches. .. image:: ../../../_static/four_node_two_switch_network.png +------------------- Create Nodes & NICs -******************* +------------------- First, we'll create the four nodes, each with a single NIC. .. code-block:: python - pc_a = Node(hostname="pc_a") + from primaite.simulator.network.hardware.base import Node, NodeOperatingState, NIC + + pc_a = Node(hostname="pc_a", operating_state=NodeOperatingState.ON) nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") pc_a.connect_nic(nic_a) - pc_a.power_on() - pc_b = Node(hostname="pc_b") + pc_b = Node(hostname="pc_b", operating_state=NodeOperatingState.ON) nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") pc_b.connect_nic(nic_b) - pc_b.power_on() - pc_c = Node(hostname="pc_c") + pc_c = Node(hostname="pc_c", operating_state=NodeOperatingState.ON) nic_c = NIC(ip_address="192.168.0.12", subnet_mask="255.255.255.0", gateway="192.168.0.1") pc_c.connect_nic(nic_c) - pc_c.power_on() - pc_d = Node(hostname="pc_d") + pc_d = Node(hostname="pc_d", operating_state=NodeOperatingState.ON) nic_d = NIC(ip_address="192.168.0.13", subnet_mask="255.255.255.0", gateway="192.168.0.1") pc_d.connect_nic(nic_d) - pc_d.power_on() - -This produces: +Creating the four nodes results in: **node_a NIC table** @@ -273,7 +314,6 @@ This produces: .. code-block:: 2023-08-08 15:50:08,355 INFO: Connected NIC 80:af:f2:f6:58:b7/192.168.0.10 - 2023-08-08 15:50:08,355 INFO: Turned on **node_b NIC table** @@ -288,7 +328,6 @@ This produces: .. code-block:: 2023-08-08 15:50:08,357 INFO: Connected NIC 98:ad:eb:7c:dc:cb/192.168.0.11 - 2023-08-08 15:50:08,357 INFO: Turned on **node_c NIC table** @@ -303,7 +342,6 @@ This produces: .. code-block:: 2023-08-08 15:50:08,358 INFO: Connected NIC bc:72:82:5d:82:a4/192.168.0.12 - 2023-08-08 15:50:08,358 INFO: Turned on **node_d NIC table** @@ -318,21 +356,19 @@ This produces: .. code-block:: 2023-08-08 15:50:08,359 INFO: Connected NIC 84:20:7c:ec:a5:c6/192.168.0.13 - 2023-08-08 15:50:08,360 INFO: Turned on +--------------- Create Switches -*************** +--------------- Next, we'll create two six-port switches: .. code-block:: python - switch_1 = Switch(hostname="switch_1", num_ports=6) - switch_1.power_on() + switch_1 = Switch(hostname="switch_1", num_ports=6, operating_state=NodeOperatingState.ON) - switch_2 = Switch(hostname="switch_2", num_ports=6) - switch_2.power_on() + switch_2 = Switch(hostname="switch_2", num_ports=6, operating_state=NodeOperatingState.ON) This produces: @@ -384,8 +420,9 @@ This produces: 2023-08-08 15:50:08,374 INFO: Turned on +------------ Create Links -************ +------------ Finally, we'll create the five links that connect the nodes and the switches: @@ -523,8 +560,9 @@ This produces: 2023-08-08 15:50:08,384 INFO: SwitchPort 96:77:39:d1:de:44 enabled +------------ Perform Ping -************ +------------ Now with the network setup and operational, we can perform a ping to confirm that communication between nodes over a switched network is possible. In the below example, we ping 192.168.0.13 (node_d) from node_a: diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index ed7719d7..7099e4c7 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -917,13 +917,13 @@ class Node(SimComponent): start_up_duration: int = 3 "Time steps needed for the node to start up." - start_up_countdown: int = -1 + start_up_countdown: int = 0 "Time steps needed until node is booted up." shut_down_duration: int = 3 "Time steps needed for the node to shut down." - shut_down_countdown: int = -1 + shut_down_countdown: int = 0 "Time steps needed until node is shut down." def __init__(self, **kwargs): @@ -1092,12 +1092,12 @@ class Node(SimComponent): self.operating_state = NodeOperatingState.BOOTING self.start_up_countdown = self.start_up_duration - if self.start_up_duration <= 0: - self.operating_state = NodeOperatingState.ON - self.sys_log.info("Turned on") - for nic in self.nics.values(): - if nic._connected_link: - nic.enable() + if self.start_up_duration <= 0: + self.operating_state = NodeOperatingState.ON + self.sys_log.info("Turned on") + for nic in self.nics.values(): + if nic._connected_link: + nic.enable() def power_off(self): """Power off the Node, disabling its NICs if it is in the ON state.""" @@ -1107,9 +1107,9 @@ class Node(SimComponent): self.operating_state = NodeOperatingState.SHUTTING_DOWN self.shut_down_countdown = self.shut_down_duration - if self.shut_down_duration >= 0: - self.operating_state = NodeOperatingState.OFF - self.sys_log.info("Turned off") + if self.shut_down_duration <= 0: + self.operating_state = NodeOperatingState.OFF + self.sys_log.info("Turned off") def connect_nic(self, nic: NIC): """ From d49d5b292d4eac6c39108a743d1d4607f2f8bcdd Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 24 Oct 2023 15:51:29 +0100 Subject: [PATCH 247/980] Add a bit of documentation --- docs/source/config(v3).rst | 15 ++++ docs/source/high_level_project_structure.rst | 87 ++++++++++++++++++++ example_config.yaml | 8 +- 3 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 docs/source/config(v3).rst create mode 100644 docs/source/high_level_project_structure.rst diff --git a/docs/source/config(v3).rst b/docs/source/config(v3).rst new file mode 100644 index 00000000..eb40015f --- /dev/null +++ b/docs/source/config(v3).rst @@ -0,0 +1,15 @@ +Primaite v3 config +****************** + + + +The YAML file allows configuring a cybersecurity scenario involving a computer network and multiple agents. There are three main sections: training_config, game, and simulation. + +The simulation section describes the simulated network environment with which the agetns interact. + +The game section describes the agents and their capabilities. Each agent has a unique type and is associated with a team (GREEN, RED, or BLUE). Each agent has a configurable observation space, action space, and reward function. + +The training_config section describes the training parameters for the learning agents. This includes the number of episodes, the number of steps per episode, and the number of steps before the agents start learning. The training_config section also describes the learning algorithm used by the agents. The learning algorithm is specified by the name of the algorithm and the hyperparameters for the algorithm. The hyperparameters are specific to each algorithm and are described in the documentation for each algorithm. + +.. only:: comment + This needs a bit of refactoring so I haven't written extensive documentation about the config yet. diff --git a/docs/source/high_level_project_structure.rst b/docs/source/high_level_project_structure.rst new file mode 100644 index 00000000..05716022 --- /dev/null +++ b/docs/source/high_level_project_structure.rst @@ -0,0 +1,87 @@ +Primaite Codebase Documentation +=============================== + +High-level structure +-------------------- +The Primaite codebase consists of two main modules: the agent-training infrastructure and the simulation logic. These modules have been decoupled to allow for flexibility and modularity. The 'game' module acts as an interface between agents and the simulation. + +Simulation +---------- +The simulation module purely simulates a computer network. It has no concept of agents acting, but it can interact with agents by providing a 'state' dictionary (using the SimComponent describe_state() method) and by accepting requests (a list of strings). + +Game layer +---------- + +The game layer is responsible for managing agents and getting them to interface with the simulator correctly. It consists of several components: + +Observations +^^^^^^^^^^^^^^^^^^ + +The ObservationManager is responsible for generating observations from the simulator state dictionary. The data is formatted so it's compatible with Gymnasium.spaces. The ObservationManager is used by the AgentManager to generate observations for each agent. + +Actions +^^^^^^^ + +The ActionManager is responsible for converting actions selected by agents (which comply with Gymnasium.spaces API) into simulation-friendly requests. The ActionManager is used by the AgentManager to take actions for each agent. + +Rewards +^^^^^^^ + +The RewardManager is responsible for calculating rewards based on the state (similar to observations). The RewardManager is used by the AgentManager to calculate rewards for each agent. + +Agents +^^^^^^ + +The AgentManager is responsible for managing agents and their interactions with the simulator. It uses the ObservationManager to generate observations for each agent, the ActionManager to take actions for each agent, and the RewardManager to calculate rewards for each agent. + +PrimaiteSession +^^^^^^^^^^^^^^^ + +PrimaiteSession is the main entry point into Primaite and it allows the simultaneous coordination of a simulation and agents that interact with it. It also sends messages to ARCD GATE to perform reinforcement learning. PrimaiteSession uses the AgentManager to manage agents and their interactions with the simulator. + +Code snippets +------------- +Here's an example of how to create a PrimaiteSession object: + +.. code-block:: python + + from primaite import PrimaiteSession + + session = PrimaiteSession() + +To start the simulation, use the start() method: + +.. code-block:: python + + session.start() + +To stop the simulation, use the stop() method: + +.. code-block:: python + + session.stop() + +To get the current state of the simulation, use the describe_state() method. This is also used as input for generating observations and rewards: + +.. code-block:: python + + state = session.sim.describe_state() + +To get the current observation of an agent, use the get_observation() method: + +.. code-block:: python + + observation = session.get_observation(agent_id) + +To get the current reward of an agent, use the get_reward() method: + +.. code-block:: python + + reward = session.get_reward(agent_id) + +To take an action for an agent, use the take_action() method: + +.. code-block:: python + + action = agent.select_action(observation) + session.take_action(agent_id, action) diff --git a/example_config.yaml b/example_config.yaml index 1e1150d8..ee42cf4f 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -2,10 +2,10 @@ training_config: rl_framework: SB3 rl_algorithm: PPO seed: 333 - n_learn_episodes: 1 - n_learn_steps: 8 - n_eval_episodes: 0 - n_eval_steps: 8 + n_learn_episodes: 20 + n_learn_steps: 128 + n_eval_episodes: 20 + n_eval_steps: 128 game_config: From cb60b6f7851f4e41b94466be90b80be2dca7698b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 24 Oct 2023 17:02:29 +0100 Subject: [PATCH 248/980] Update text in docs --- docs/index.rst | 2 + docs/source/config(v3).rst | 4 +- docs/source/game_layer.rst | 48 +++++++++++ docs/source/high_level_project_structure.rst | 87 -------------------- 4 files changed, 51 insertions(+), 90 deletions(-) create mode 100644 docs/source/game_layer.rst delete mode 100644 docs/source/high_level_project_structure.rst diff --git a/docs/index.rst b/docs/index.rst index 19f95e95..22e880fc 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -98,7 +98,9 @@ Head over to the :ref:`getting-started` page to install and setup PrimAITE! source/getting_started source/about source/config + source/config(v3) source/simulation + source/game_layer source/primaite_session source/custom_agent PrimAITE API diff --git a/docs/source/config(v3).rst b/docs/source/config(v3).rst index eb40015f..0ce8b547 100644 --- a/docs/source/config(v3).rst +++ b/docs/source/config(v3).rst @@ -1,9 +1,7 @@ Primaite v3 config ****************** - - -The YAML file allows configuring a cybersecurity scenario involving a computer network and multiple agents. There are three main sections: training_config, game, and simulation. +PrimAITE uses a single configuration file to define a cybersecurity scenario. This includes the computer network and multiple agents. There are three main sections: training_config, game, and simulation. The simulation section describes the simulated network environment with which the agetns interact. diff --git a/docs/source/game_layer.rst b/docs/source/game_layer.rst new file mode 100644 index 00000000..9e254ac6 --- /dev/null +++ b/docs/source/game_layer.rst @@ -0,0 +1,48 @@ +PrimAITE Game layer +******************* + +The Primaite codebase consists of two main modules: + +* ``simulator``: The simulation logic including the network topology, the network state, and behaviour of various hardware and software classes. +* ``game``: The agent-training infrastructure which helps reinforcement learning agents interface with the simulation. This includes the observation, action, and rewards, for RL agents, but also scripted deterministic agents. The game layer orchestrates all the interactions between modules, including ARCD GATE. + +These two components have been decoupled to allow the agent training code in ARCD GATE to be reused with other simulators. The simulator and game layer communicate using the PrimAITE State API and the PrimAITE Request API. The game layer communicates with ARCD gate using the `Farama Gymnasium Spaces API `_. + +.. + TODO: write up these APIs and link them here. + + +Game layer +---------- + +The game layer is responsible for managing agents and getting them to interface with the simulator correctly. It consists of several components: + +PrimaiteSession +^^^^^^^^^^^^^^^ + +PrimaiteSession is the main entry point into Primaite and it allows the simultaneous coordination of a simulation and agents that interact with it. It also sends messages to ARCD GATE to perform reinforcement learning. PrimaiteSession keeps track of multiple agents of different types. + +Agents +^^^^^^ + +All agents inherit from the AbstractAgent class, which mandates that they have an ObservationManager, ActionManager, and RewardManager. The agent behaviour depends on the type of agent, but there are two main types: +* RL agents action during each step is decided by an RL algorithm which lives inside of ARCD GATE. The agent within PrimAITE just acts to format and forward actions decided by an RL policy. +* Deterministic agents perform all of their decision making within the PrimAITE game layer. They typically have a scripted policy which always performs the same action or a rule-based policy which performs actions based on the current state of the simulation. They can have a stochastic element, and their seed will be settable. + +.. + TODO: add seed to stochastic scripted agents + +Observations +^^^^^^^^^^^^^^^^^^ + +An agent's observations are managed by the ObservationManager class. It generates observations based on the current simulation state dictionary. It also provides the observation space during initial setup. The data is formatted so it's compatible with Gymnasium.spaces. Observation spaces are composed of one or more components which are defined by the AbstractObservation base class. + +Actions +^^^^^^^ + +An agent's actions are managed by the ActionManager. It converts actions selected by agents (which are typically integers chosen from a ``gymnasium.spaces.Discrete`` space) into simulation-friendly requests. It also provides the action space during initial setup. Action spaces are composed of one or more components which are defined by the AbstractAction base class. + +Rewards +^^^^^^^ + +An agent's reward function is managed by the RewardManager. It calculates rewards based on the simulation state (in a way similar to observations). Rewards can be defined as a weighted sum of small reward components. For example, an agents reward can be based on the uptime of a database service plus the loss rate of packets between clients and a web server. The reward components are defined by the AbstractReward base class. diff --git a/docs/source/high_level_project_structure.rst b/docs/source/high_level_project_structure.rst deleted file mode 100644 index 05716022..00000000 --- a/docs/source/high_level_project_structure.rst +++ /dev/null @@ -1,87 +0,0 @@ -Primaite Codebase Documentation -=============================== - -High-level structure --------------------- -The Primaite codebase consists of two main modules: the agent-training infrastructure and the simulation logic. These modules have been decoupled to allow for flexibility and modularity. The 'game' module acts as an interface between agents and the simulation. - -Simulation ----------- -The simulation module purely simulates a computer network. It has no concept of agents acting, but it can interact with agents by providing a 'state' dictionary (using the SimComponent describe_state() method) and by accepting requests (a list of strings). - -Game layer ----------- - -The game layer is responsible for managing agents and getting them to interface with the simulator correctly. It consists of several components: - -Observations -^^^^^^^^^^^^^^^^^^ - -The ObservationManager is responsible for generating observations from the simulator state dictionary. The data is formatted so it's compatible with Gymnasium.spaces. The ObservationManager is used by the AgentManager to generate observations for each agent. - -Actions -^^^^^^^ - -The ActionManager is responsible for converting actions selected by agents (which comply with Gymnasium.spaces API) into simulation-friendly requests. The ActionManager is used by the AgentManager to take actions for each agent. - -Rewards -^^^^^^^ - -The RewardManager is responsible for calculating rewards based on the state (similar to observations). The RewardManager is used by the AgentManager to calculate rewards for each agent. - -Agents -^^^^^^ - -The AgentManager is responsible for managing agents and their interactions with the simulator. It uses the ObservationManager to generate observations for each agent, the ActionManager to take actions for each agent, and the RewardManager to calculate rewards for each agent. - -PrimaiteSession -^^^^^^^^^^^^^^^ - -PrimaiteSession is the main entry point into Primaite and it allows the simultaneous coordination of a simulation and agents that interact with it. It also sends messages to ARCD GATE to perform reinforcement learning. PrimaiteSession uses the AgentManager to manage agents and their interactions with the simulator. - -Code snippets -------------- -Here's an example of how to create a PrimaiteSession object: - -.. code-block:: python - - from primaite import PrimaiteSession - - session = PrimaiteSession() - -To start the simulation, use the start() method: - -.. code-block:: python - - session.start() - -To stop the simulation, use the stop() method: - -.. code-block:: python - - session.stop() - -To get the current state of the simulation, use the describe_state() method. This is also used as input for generating observations and rewards: - -.. code-block:: python - - state = session.sim.describe_state() - -To get the current observation of an agent, use the get_observation() method: - -.. code-block:: python - - observation = session.get_observation(agent_id) - -To get the current reward of an agent, use the get_reward() method: - -.. code-block:: python - - reward = session.get_reward(agent_id) - -To take an action for an agent, use the take_action() method: - -.. code-block:: python - - action = agent.select_action(observation) - session.take_action(agent_id, action) From c9b06e1bfbf0fd3673575a1b1c8988a6d312812f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 24 Oct 2023 17:06:58 +0100 Subject: [PATCH 249/980] Delete sandbox file --- sandbox.ipynb | 869 -------------------------------------------------- 1 file changed, 869 deletions(-) delete mode 100644 sandbox.ipynb diff --git a/sandbox.ipynb b/sandbox.ipynb deleted file mode 100644 index 73c3e682..00000000 --- a/sandbox.ipynb +++ /dev/null @@ -1,869 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-10-10 21:00:40,310: Added node f0fb4743-43d5-4741-a0e5-78340a458a11 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", - "2023-10-10 21:00:40,313: Added node 86f4ee9d-386d-4436-96e7-d00dd8bae746 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", - "2023-10-10 21:00:40,316: Added node d2b38f6a-10fe-4d28-86a5-a1d2010c4bea to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", - "2023-10-10 21:00:40,319: Added node 29d55bd4-d59e-4f73-95ad-b430c8716b15 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", - "2023-10-10 21:00:40,323: Added node 5d266f99-03a6-47b3-ab0b-28b8a6813a11 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", - "2023-10-10 21:00:40,333: Added node e4f397c7-eed2-4e69-afaf-ce44664ff1d2 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", - "2023-10-10 21:00:40,338: Added node 19dbb2d4-648b-4387-aa15-99757b513acb to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", - "2023-10-10 21:00:40,344: Added node f508ea65-e660-4b91-8628-5c586075137b to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", - "2023-10-10 21:00:40,350: Added node ffe02a33-7f9c-4fc1-ad3a-791935dbd4c2 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", - "2023-10-10 21:00:40,356: Added node 0ce9efc6-39ae-4d3d-82ad-43be5ac57586 to Network 301a746b-6521-4ff9-876f-a1ce39678451\n", - "2023-10-10 21:00:40,360: NIC ba:25:b9:f4:b0:74/192.168.1.1 connected to Link ba:25:b9:f4:b0:74/192.168.1.1<-->3a:25:73:6c:4c:36\n", - "2023-10-10 21:00:40,361: SwitchPort 3a:25:73:6c:4c:36 connected to Link ba:25:b9:f4:b0:74/192.168.1.1<-->3a:25:73:6c:4c:36\n", - "2023-10-10 21:00:40,363: Link ba:25:b9:f4:b0:74/192.168.1.1<-->3a:25:73:6c:4c:36 up\n", - "2023-10-10 21:00:40,364: Link ba:25:b9:f4:b0:74/192.168.1.1<-->3a:25:73:6c:4c:36 up\n", - "2023-10-10 21:00:40,366: Added link eda2befd-9f68-440c-9b20-06838d9e6553 to connect ba:25:b9:f4:b0:74/192.168.1.1 and 3a:25:73:6c:4c:36\n", - "2023-10-10 21:00:40,367: NIC c0:ce:5a:6d:71:73/192.168.1.1 connected to Link c0:ce:5a:6d:71:73/192.168.1.1<-->b2:a4:b3:fc:da:c3\n", - "2023-10-10 21:00:40,368: SwitchPort b2:a4:b3:fc:da:c3 connected to Link c0:ce:5a:6d:71:73/192.168.1.1<-->b2:a4:b3:fc:da:c3\n", - "2023-10-10 21:00:40,370: Link c0:ce:5a:6d:71:73/192.168.1.1<-->b2:a4:b3:fc:da:c3 up\n", - "2023-10-10 21:00:40,370: Link c0:ce:5a:6d:71:73/192.168.1.1<-->b2:a4:b3:fc:da:c3 up\n", - "2023-10-10 21:00:40,372: Added link 0e2a1df6-1c3c-4517-b41f-04a5cefe307c to connect c0:ce:5a:6d:71:73/192.168.1.1 and b2:a4:b3:fc:da:c3\n", - "2023-10-10 21:00:40,373: SwitchPort 72:f3:93:a5:a5:59 connected to Link 72:f3:93:a5:a5:59<-->e1:9b:c0:59:1d:46/192.168.1.10\n", - "2023-10-10 21:00:40,377: Link 72:f3:93:a5:a5:59<-->e1:9b:c0:59:1d:46/192.168.1.10 up\n", - "2023-10-10 21:00:40,379: NIC e1:9b:c0:59:1d:46/192.168.1.10 connected to Link 72:f3:93:a5:a5:59<-->e1:9b:c0:59:1d:46/192.168.1.10\n", - "2023-10-10 21:00:40,380: Link 72:f3:93:a5:a5:59<-->e1:9b:c0:59:1d:46/192.168.1.10 up\n", - "2023-10-10 21:00:40,381: Added link 48c9173d-847b-441f-9f15-f7838cf09083 to connect 72:f3:93:a5:a5:59 and e1:9b:c0:59:1d:46/192.168.1.10\n", - "2023-10-10 21:00:40,382: SwitchPort 67:36:e8:51:35:f2 connected to Link 67:36:e8:51:35:f2<-->3b:a3:b4:ec:a0:2a/192.168.1.12\n", - "2023-10-10 21:00:40,384: Link 67:36:e8:51:35:f2<-->3b:a3:b4:ec:a0:2a/192.168.1.12 up\n", - "2023-10-10 21:00:40,385: NIC 3b:a3:b4:ec:a0:2a/192.168.1.12 connected to Link 67:36:e8:51:35:f2<-->3b:a3:b4:ec:a0:2a/192.168.1.12\n", - "2023-10-10 21:00:40,386: Link 67:36:e8:51:35:f2<-->3b:a3:b4:ec:a0:2a/192.168.1.12 up\n", - "2023-10-10 21:00:40,386: Added link 7259c2a4-44f7-44d9-87de-1a692c98ac58 to connect 67:36:e8:51:35:f2 and 3b:a3:b4:ec:a0:2a/192.168.1.12\n", - "2023-10-10 21:00:40,388: SwitchPort be:56:a8:d3:f9:6c connected to Link be:56:a8:d3:f9:6c<-->99:24:3a:ad:99:5b/192.168.1.14\n", - "2023-10-10 21:00:40,391: Link be:56:a8:d3:f9:6c<-->99:24:3a:ad:99:5b/192.168.1.14 up\n", - "2023-10-10 21:00:40,392: NIC 99:24:3a:ad:99:5b/192.168.1.14 connected to Link be:56:a8:d3:f9:6c<-->99:24:3a:ad:99:5b/192.168.1.14\n", - "2023-10-10 21:00:40,394: Link be:56:a8:d3:f9:6c<-->99:24:3a:ad:99:5b/192.168.1.14 up\n", - "2023-10-10 21:00:40,396: Added link ff3c3f9a-c267-421a-9e2f-bcc11a6fa082 to connect be:56:a8:d3:f9:6c and 99:24:3a:ad:99:5b/192.168.1.14\n", - "2023-10-10 21:00:40,397: SwitchPort 4f:91:78:5a:68:3f connected to Link 4f:91:78:5a:68:3f<-->2b:ff:81:44:7f:61/192.168.1.16\n", - "2023-10-10 21:00:40,399: Link 4f:91:78:5a:68:3f<-->2b:ff:81:44:7f:61/192.168.1.16 up\n", - "2023-10-10 21:00:40,400: NIC 2b:ff:81:44:7f:61/192.168.1.16 connected to Link 4f:91:78:5a:68:3f<-->2b:ff:81:44:7f:61/192.168.1.16\n", - "2023-10-10 21:00:40,401: Link 4f:91:78:5a:68:3f<-->2b:ff:81:44:7f:61/192.168.1.16 up\n", - "2023-10-10 21:00:40,402: Added link b5a2e61c-f14d-45a3-a27e-2451f21229d5 to connect 4f:91:78:5a:68:3f and 2b:ff:81:44:7f:61/192.168.1.16\n", - "2023-10-10 21:00:40,403: SwitchPort 14:8e:63:89:28:f6 connected to Link 14:8e:63:89:28:f6<-->72:ca:83:f9:d0:66/192.168.1.110\n", - "2023-10-10 21:00:40,404: Link 14:8e:63:89:28:f6<-->72:ca:83:f9:d0:66/192.168.1.110 up\n", - "2023-10-10 21:00:40,405: NIC 72:ca:83:f9:d0:66/192.168.1.110 connected to Link 14:8e:63:89:28:f6<-->72:ca:83:f9:d0:66/192.168.1.110\n", - "2023-10-10 21:00:40,406: Link 14:8e:63:89:28:f6<-->72:ca:83:f9:d0:66/192.168.1.110 up\n", - "2023-10-10 21:00:40,407: Added link d0906ccd-5f98-415a-b08e-b8ebfdd3c5a9 to connect 14:8e:63:89:28:f6 and 72:ca:83:f9:d0:66/192.168.1.110\n", - "2023-10-10 21:00:40,409: SwitchPort e5:20:55:91:b5:b9 connected to Link e5:20:55:91:b5:b9<-->27:2f:d1:75:04:f9/192.168.10.21\n", - "2023-10-10 21:00:40,412: Link e5:20:55:91:b5:b9<-->27:2f:d1:75:04:f9/192.168.10.21 up\n", - "2023-10-10 21:00:40,413: NIC 27:2f:d1:75:04:f9/192.168.10.21 connected to Link e5:20:55:91:b5:b9<-->27:2f:d1:75:04:f9/192.168.10.21\n", - "2023-10-10 21:00:40,414: Link e5:20:55:91:b5:b9<-->27:2f:d1:75:04:f9/192.168.10.21 up\n", - "2023-10-10 21:00:40,415: Added link 51f14a80-8fd6-4de9-86a3-9c726c036167 to connect e5:20:55:91:b5:b9 and 27:2f:d1:75:04:f9/192.168.10.21\n", - "2023-10-10 21:00:40,416: SwitchPort 4e:58:c4:9c:0c:6d connected to Link 4e:58:c4:9c:0c:6d<-->2e:f5:71:bb:73:ec/192.168.10.22\n", - "2023-10-10 21:00:40,418: Link 4e:58:c4:9c:0c:6d<-->2e:f5:71:bb:73:ec/192.168.10.22 up\n", - "2023-10-10 21:00:40,420: NIC 2e:f5:71:bb:73:ec/192.168.10.22 connected to Link 4e:58:c4:9c:0c:6d<-->2e:f5:71:bb:73:ec/192.168.10.22\n", - "2023-10-10 21:00:40,420: Link 4e:58:c4:9c:0c:6d<-->2e:f5:71:bb:73:ec/192.168.10.22 up\n", - "2023-10-10 21:00:40,421: Added link 7463a72f-af42-435f-ad98-83bcfe5728a3 to connect 4e:58:c4:9c:0c:6d and 2e:f5:71:bb:73:ec/192.168.10.22\n", - "2023-10-10 21:00:40,423: SwitchPort 66:98:bd:ca:08:b0 connected to Link 66:98:bd:ca:08:b0<-->cf:f7:fc:d1:f4:ae/192.168.10.110\n", - "2023-10-10 21:00:40,425: Link 66:98:bd:ca:08:b0<-->cf:f7:fc:d1:f4:ae/192.168.10.110 up\n", - "2023-10-10 21:00:40,427: NIC cf:f7:fc:d1:f4:ae/192.168.10.110 connected to Link 66:98:bd:ca:08:b0<-->cf:f7:fc:d1:f4:ae/192.168.10.110\n", - "2023-10-10 21:00:40,428: Link 66:98:bd:ca:08:b0<-->cf:f7:fc:d1:f4:ae/192.168.10.110 up\n", - "2023-10-10 21:00:40,430: Added link ff6fd52d-f893-4c0d-99d2-28f10c128043 to connect 66:98:bd:ca:08:b0 and cf:f7:fc:d1:f4:ae/192.168.10.110\n", - "2023-10-10 21:00:40,431: Stepping primaite session. Step counter: 0\n", - "2023-10-10 21:00:40,432: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,433: Getting agent action\n", - "2023-10-10 21:00:40,435: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,436: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,437: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,439: Getting agent action\n", - "2023-10-10 21:00:40,440: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:40,441: Sending request to simulation: ['do_nothing']\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/home/cade/.local/state/primaite/2.0.0/log\n", - "service type not found DatabaseBackup\n", - "service type not found WebBrowser\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-10-10 21:00:40,443: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,445: Getting agent action\n", - "2023-10-10 21:00:40,447: Formatting agent action NODE_FOLDER_RESTORE\n", - "2023-10-10 21:00:40,449: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,450: Initiating simulation step 0\n" - ] - } - ], - "source": [ - "%load_ext autoreload\n", - "%autoreload 2\n", - "from primaite.game.session import PrimaiteSession\n", - "\n", - "from primaite import _PRIMAITE_CONFIG, PRIMAITE_PATHS\n", - "import logging\n", - "_PRIMAITE_CONFIG['log_level']=logging.DEBUG\n", - "print(PRIMAITE_PATHS.app_log_dir_path)\n", - "from primaite.game.session import PrimaiteSession\n", - "import yaml\n", - "\n", - "with open('example_config.yaml', 'r') as file:\n", - " cfg = yaml.safe_load(file)\n", - "sess = PrimaiteSession.from_config(cfg)\n", - "sess.step()" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-10-10 21:00:40,481: Stepping primaite session. Step counter: 1\n", - "2023-10-10 21:00:40,484: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,486: Getting agent action\n", - "2023-10-10 21:00:40,487: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,488: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,489: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,491: Getting agent action\n", - "2023-10-10 21:00:40,493: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:40,494: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,495: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,497: Getting agent action\n", - "2023-10-10 21:00:40,498: Formatting agent action NETWORK_ACL_REMOVERULE\n", - "2023-10-10 21:00:40,499: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 8]\n", - "2023-10-10 21:00:40,500: Initiating simulation step 1\n", - "2023-10-10 21:00:40,502: Stepping primaite session. Step counter: 2\n", - "2023-10-10 21:00:40,503: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,504: Getting agent action\n", - "2023-10-10 21:00:40,505: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,505: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,506: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,508: Getting agent action\n", - "2023-10-10 21:00:40,511: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:40,513: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,513: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,515: Getting agent action\n", - "2023-10-10 21:00:40,516: Formatting agent action NETWORK_ACL_ADDRULE\n", - "2023-10-10 21:00:40,518: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,519: Initiating simulation step 2\n", - "2023-10-10 21:00:40,520: Stepping primaite session. Step counter: 3\n", - "2023-10-10 21:00:40,521: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,522: Getting agent action\n", - "2023-10-10 21:00:40,524: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,525: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,526: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,528: Getting agent action\n", - "2023-10-10 21:00:40,530: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,531: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,533: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,534: Getting agent action\n", - "2023-10-10 21:00:40,535: Formatting agent action NETWORK_ACL_REMOVERULE\n", - "2023-10-10 21:00:40,537: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 1]\n", - "2023-10-10 21:00:40,538: Initiating simulation step 3\n", - "2023-10-10 21:00:40,539: Stepping primaite session. Step counter: 4\n", - "2023-10-10 21:00:40,541: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,543: Getting agent action\n", - "2023-10-10 21:00:40,545: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,546: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,547: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,550: Getting agent action\n", - "2023-10-10 21:00:40,552: Formatting agent action NODE_OS_SCAN\n", - "2023-10-10 21:00:40,554: Sending request to simulation: ['network', 'node', 'ffe02a33-7f9c-4fc1-ad3a-791935dbd4c2', 'scan']\n", - "2023-10-10 21:00:40,555: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,573: Getting agent action\n", - "2023-10-10 21:00:40,575: Formatting agent action NETWORK_ACL_REMOVERULE\n", - "2023-10-10 21:00:40,577: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 2]\n", - "2023-10-10 21:00:40,578: Initiating simulation step 4\n", - "2023-10-10 21:00:40,580: Stepping primaite session. Step counter: 5\n", - "2023-10-10 21:00:40,581: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,583: Getting agent action\n", - "2023-10-10 21:00:40,585: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,586: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,587: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,597: Getting agent action\n", - "2023-10-10 21:00:40,598: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:40,599: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,601: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,603: Getting agent action\n", - "2023-10-10 21:00:40,605: Formatting agent action NETWORK_ACL_REMOVERULE\n", - "2023-10-10 21:00:40,606: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 0]\n", - "2023-10-10 21:00:40,613: Initiating simulation step 5\n", - "2023-10-10 21:00:40,614: Stepping primaite session. Step counter: 6\n", - "2023-10-10 21:00:40,615: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,617: Getting agent action\n", - "2023-10-10 21:00:40,618: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,619: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,620: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,621: Getting agent action\n", - "2023-10-10 21:00:40,623: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:40,624: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,625: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,626: Getting agent action\n", - "2023-10-10 21:00:40,628: Formatting agent action NETWORK_ACL_REMOVERULE\n", - "2023-10-10 21:00:40,629: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 7]\n", - "2023-10-10 21:00:40,630: Initiating simulation step 6\n", - "2023-10-10 21:00:40,631: Stepping primaite session. Step counter: 7\n", - "2023-10-10 21:00:40,631: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,633: Getting agent action\n", - "2023-10-10 21:00:40,634: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,635: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,635: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,636: Getting agent action\n", - "2023-10-10 21:00:40,639: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:40,640: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,642: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,644: Getting agent action\n", - "2023-10-10 21:00:40,645: Formatting agent action NODE_SERVICE_STOP\n", - "2023-10-10 21:00:40,646: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,647: Initiating simulation step 7\n", - "2023-10-10 21:00:40,648: Stepping primaite session. Step counter: 8\n", - "2023-10-10 21:00:40,649: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,651: Getting agent action\n", - "2023-10-10 21:00:40,652: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,652: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,653: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,655: Getting agent action\n", - "2023-10-10 21:00:40,656: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,657: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,659: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,661: Getting agent action\n", - "2023-10-10 21:00:40,662: Formatting agent action NODE_FILE_RESTORE\n", - "2023-10-10 21:00:40,663: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,664: Initiating simulation step 8\n", - "2023-10-10 21:00:40,665: Stepping primaite session. Step counter: 9\n", - "2023-10-10 21:00:40,667: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,668: Getting agent action\n", - "2023-10-10 21:00:40,669: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,670: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,672: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,674: Getting agent action\n", - "2023-10-10 21:00:40,676: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:40,677: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,678: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,679: Getting agent action\n", - "2023-10-10 21:00:40,681: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,682: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,683: Initiating simulation step 9\n", - "2023-10-10 21:00:40,684: Stepping primaite session. Step counter: 10\n", - "2023-10-10 21:00:40,685: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,687: Getting agent action\n", - "2023-10-10 21:00:40,688: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,689: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,690: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,694: Getting agent action\n", - "2023-10-10 21:00:40,696: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:40,697: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,698: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,700: Getting agent action\n", - "2023-10-10 21:00:40,702: Formatting agent action NODE_FILE_SCAN\n", - "2023-10-10 21:00:40,705: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,706: Initiating simulation step 10\n", - "2023-10-10 21:00:40,709: Stepping primaite session. Step counter: 11\n", - "2023-10-10 21:00:40,711: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,713: Getting agent action\n", - "2023-10-10 21:00:40,715: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,716: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,717: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,719: Getting agent action\n", - "2023-10-10 21:00:40,722: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:40,724: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,726: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,728: Getting agent action\n", - "2023-10-10 21:00:40,730: Formatting agent action NODE_SERVICE_START\n", - "2023-10-10 21:00:40,731: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,733: Initiating simulation step 11\n", - "2023-10-10 21:00:40,735: Stepping primaite session. Step counter: 12\n", - "2023-10-10 21:00:40,736: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,738: Getting agent action\n", - "2023-10-10 21:00:40,739: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,740: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,741: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,743: Getting agent action\n", - "2023-10-10 21:00:40,746: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:40,748: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,749: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,752: Getting agent action\n", - "2023-10-10 21:00:40,755: Formatting agent action NETWORK_ACL_ADDRULE\n", - "2023-10-10 21:00:40,758: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'add_rule', 'DENY', 'TCP', IPv4Address('192.168.1.12'), 'ALL', IPv4Address('127.0.0.1'), 'ALL', 1]\n", - "2023-10-10 21:00:40,760: Initiating simulation step 12\n", - "2023-10-10 21:00:40,762: Stepping primaite session. Step counter: 13\n", - "2023-10-10 21:00:40,763: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,766: Getting agent action\n", - "2023-10-10 21:00:40,768: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,769: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,771: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,773: Getting agent action\n", - "2023-10-10 21:00:40,777: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:40,779: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,780: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,782: Getting agent action\n", - "2023-10-10 21:00:40,784: Formatting agent action NODE_SERVICE_RESTART\n", - "2023-10-10 21:00:40,785: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,786: Initiating simulation step 13\n", - "2023-10-10 21:00:40,787: Stepping primaite session. Step counter: 14\n", - "2023-10-10 21:00:40,788: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,790: Getting agent action\n", - "2023-10-10 21:00:40,792: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,794: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,795: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,797: Getting agent action\n", - "2023-10-10 21:00:40,799: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:40,800: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,801: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,803: Getting agent action\n", - "2023-10-10 21:00:40,805: Formatting agent action NODE_SERVICE_DISABLE\n", - "2023-10-10 21:00:40,806: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,807: Initiating simulation step 14\n", - "2023-10-10 21:00:40,808: Stepping primaite session. Step counter: 15\n", - "2023-10-10 21:00:40,809: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,813: Getting agent action\n", - "2023-10-10 21:00:40,815: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,817: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,818: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,821: Getting agent action\n", - "2023-10-10 21:00:40,822: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:40,824: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,828: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,830: Getting agent action\n", - "2023-10-10 21:00:40,832: Formatting agent action NETWORK_NIC_DISABLE\n", - "2023-10-10 21:00:40,833: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,835: Initiating simulation step 15\n", - "2023-10-10 21:00:40,836: Stepping primaite session. Step counter: 16\n", - "2023-10-10 21:00:40,838: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,840: Getting agent action\n", - "2023-10-10 21:00:40,848: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,852: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,856: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,858: Getting agent action\n", - "2023-10-10 21:00:40,863: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:40,868: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,869: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,872: Getting agent action\n", - "2023-10-10 21:00:40,878: Formatting agent action NODE_OS_SCAN\n", - "2023-10-10 21:00:40,883: Sending request to simulation: ['network', 'node', '29d55bd4-d59e-4f73-95ad-b430c8716b15', 'scan']\n", - "2023-10-10 21:00:40,885: Initiating simulation step 16\n", - "2023-10-10 21:00:40,887: Stepping primaite session. Step counter: 17\n", - "2023-10-10 21:00:40,889: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,900: Getting agent action\n", - "2023-10-10 21:00:40,904: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,909: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,911: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,913: Getting agent action\n", - "2023-10-10 21:00:40,915: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:40,917: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,918: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,920: Getting agent action\n", - "2023-10-10 21:00:40,921: Formatting agent action NETWORK_ACL_ADDRULE\n", - "2023-10-10 21:00:40,922: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'add_rule', 'DENY', 'TCP', IPv4Address('192.168.1.10'), 'ALL', IPv4Address('127.0.0.1'), 'ALL', 1]\n", - "2023-10-10 21:00:40,924: Initiating simulation step 17\n", - "2023-10-10 21:00:40,925: Stepping primaite session. Step counter: 18\n", - "2023-10-10 21:00:40,927: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,929: Getting agent action\n", - "2023-10-10 21:00:40,931: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,933: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,934: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,936: Getting agent action\n", - "2023-10-10 21:00:40,938: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:40,940: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,941: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,945: Getting agent action\n", - "2023-10-10 21:00:40,947: Formatting agent action NETWORK_ACL_ADDRULE\n", - "2023-10-10 21:00:40,948: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,949: Initiating simulation step 18\n", - "2023-10-10 21:00:40,951: Stepping primaite session. Step counter: 19\n", - "2023-10-10 21:00:40,952: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,954: Getting agent action\n", - "2023-10-10 21:00:40,955: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,957: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,960: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,962: Getting agent action\n", - "2023-10-10 21:00:40,964: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:40,966: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,967: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,969: Getting agent action\n", - "2023-10-10 21:00:40,971: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,972: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,973: Initiating simulation step 19\n", - "2023-10-10 21:00:40,975: Stepping primaite session. Step counter: 20\n", - "2023-10-10 21:00:40,976: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:40,979: Getting agent action\n", - "2023-10-10 21:00:40,981: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:40,982: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,983: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:40,986: Getting agent action\n", - "2023-10-10 21:00:40,987: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:40,989: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:40,990: Sending simulation state to agent defender\n", - "2023-10-10 21:00:40,992: Getting agent action\n", - "2023-10-10 21:00:40,994: Formatting agent action NETWORK_ACL_ADDRULE\n", - "2023-10-10 21:00:40,996: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'add_rule', 'DENY', 'TCP', IPv4Address('192.168.1.12'), 'ALL', IPv4Address('127.0.0.1'), 'ALL', 1]\n", - "2023-10-10 21:00:40,997: Initiating simulation step 20\n", - "2023-10-10 21:00:40,998: Stepping primaite session. Step counter: 21\n", - "2023-10-10 21:00:41,000: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,001: Getting agent action\n", - "2023-10-10 21:00:41,003: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,004: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,005: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,006: Getting agent action\n", - "2023-10-10 21:00:41,009: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,010: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,011: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,014: Getting agent action\n", - "2023-10-10 21:00:41,016: Formatting agent action NODE_FILE_REPAIR\n", - "2023-10-10 21:00:41,017: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,018: Initiating simulation step 21\n", - "2023-10-10 21:00:41,020: Stepping primaite session. Step counter: 22\n", - "2023-10-10 21:00:41,021: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,023: Getting agent action\n", - "2023-10-10 21:00:41,024: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,025: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,027: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,030: Getting agent action\n", - "2023-10-10 21:00:41,031: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:41,033: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,034: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,036: Getting agent action\n", - "2023-10-10 21:00:41,037: Formatting agent action NODE_FILE_REPAIR\n", - "2023-10-10 21:00:41,038: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,039: Initiating simulation step 22\n", - "2023-10-10 21:00:41,040: Stepping primaite session. Step counter: 23\n", - "2023-10-10 21:00:41,042: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,045: Getting agent action\n", - "2023-10-10 21:00:41,047: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,049: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,050: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,056: Getting agent action\n", - "2023-10-10 21:00:41,065: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:41,067: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,068: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,072: Getting agent action\n", - "2023-10-10 21:00:41,073: Formatting agent action NODE_FOLDER_REPAIR\n", - "2023-10-10 21:00:41,075: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,077: Initiating simulation step 23\n", - "2023-10-10 21:00:41,079: Stepping primaite session. Step counter: 24\n", - "2023-10-10 21:00:41,081: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,083: Getting agent action\n", - "2023-10-10 21:00:41,085: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,086: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,088: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,090: Getting agent action\n", - "2023-10-10 21:00:41,092: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,093: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,095: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,097: Getting agent action\n", - "2023-10-10 21:00:41,099: Formatting agent action NODE_STARTUP\n", - "2023-10-10 21:00:41,100: Sending request to simulation: ['network', 'node', '19dbb2d4-648b-4387-aa15-99757b513acb', 'startup']\n", - "2023-10-10 21:00:41,102: Initiating simulation step 24\n", - "2023-10-10 21:00:41,103: Stepping primaite session. Step counter: 25\n", - "2023-10-10 21:00:41,104: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,107: Getting agent action\n", - "2023-10-10 21:00:41,110: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,112: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,113: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,114: Getting agent action\n", - "2023-10-10 21:00:41,116: Formatting agent action NODE_OS_SCAN\n", - "2023-10-10 21:00:41,118: Sending request to simulation: ['network', 'node', 'ffe02a33-7f9c-4fc1-ad3a-791935dbd4c2', 'scan']\n", - "2023-10-10 21:00:41,120: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,122: Getting agent action\n", - "2023-10-10 21:00:41,124: Formatting agent action NODE_FOLDER_RESTORE\n", - "2023-10-10 21:00:41,126: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,127: Initiating simulation step 25\n", - "2023-10-10 21:00:41,129: Stepping primaite session. Step counter: 26\n", - "2023-10-10 21:00:41,130: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,132: Getting agent action\n", - "2023-10-10 21:00:41,134: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,136: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,137: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,139: Getting agent action\n", - "2023-10-10 21:00:41,141: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,142: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,144: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,145: Getting agent action\n", - "2023-10-10 21:00:41,147: Formatting agent action NODE_STARTUP\n", - "2023-10-10 21:00:41,148: Sending request to simulation: ['network', 'node', '19dbb2d4-648b-4387-aa15-99757b513acb', 'startup']\n", - "2023-10-10 21:00:41,150: Initiating simulation step 26\n", - "2023-10-10 21:00:41,151: Stepping primaite session. Step counter: 27\n", - "2023-10-10 21:00:41,153: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,155: Getting agent action\n", - "2023-10-10 21:00:41,157: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,158: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,160: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,162: Getting agent action\n", - "2023-10-10 21:00:41,164: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,166: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,166: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,169: Getting agent action\n", - "2023-10-10 21:00:41,170: Formatting agent action NODE_SERVICE_START\n", - "2023-10-10 21:00:41,172: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,173: Initiating simulation step 27\n", - "2023-10-10 21:00:41,174: Stepping primaite session. Step counter: 28\n", - "2023-10-10 21:00:41,176: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,177: Getting agent action\n", - "2023-10-10 21:00:41,179: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,181: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,182: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,183: Getting agent action\n", - "2023-10-10 21:00:41,185: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,186: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,187: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,188: Getting agent action\n", - "2023-10-10 21:00:41,190: Formatting agent action NETWORK_NIC_DISABLE\n", - "2023-10-10 21:00:41,191: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,193: Initiating simulation step 28\n", - "2023-10-10 21:00:41,194: Stepping primaite session. Step counter: 29\n", - "2023-10-10 21:00:41,196: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,198: Getting agent action\n", - "2023-10-10 21:00:41,199: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,201: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,201: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,203: Getting agent action\n", - "2023-10-10 21:00:41,204: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,206: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,207: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,208: Getting agent action\n", - "2023-10-10 21:00:41,211: Formatting agent action NETWORK_ACL_REMOVERULE\n", - "2023-10-10 21:00:41,213: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 3]\n", - "2023-10-10 21:00:41,215: Initiating simulation step 29\n", - "2023-10-10 21:00:41,217: Stepping primaite session. Step counter: 30\n", - "2023-10-10 21:00:41,218: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,220: Getting agent action\n", - "2023-10-10 21:00:41,221: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,222: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,223: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,225: Getting agent action\n", - "2023-10-10 21:00:41,227: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,229: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,231: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,232: Getting agent action\n", - "2023-10-10 21:00:41,233: Formatting agent action NETWORK_ACL_ADDRULE\n", - "2023-10-10 21:00:41,235: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'add_rule', 'DENY', 'TCP', IPv4Address('192.168.1.10'), 'ALL', IPv4Address('127.0.0.1'), 'ALL', 1]\n", - "2023-10-10 21:00:41,236: Initiating simulation step 30\n", - "2023-10-10 21:00:41,238: Stepping primaite session. Step counter: 31\n", - "2023-10-10 21:00:41,238: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,240: Getting agent action\n", - "2023-10-10 21:00:41,242: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,244: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,245: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,248: Getting agent action\n", - "2023-10-10 21:00:41,249: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:41,251: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,252: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,254: Getting agent action\n", - "2023-10-10 21:00:41,255: Formatting agent action NODE_FILE_RESTORE\n", - "2023-10-10 21:00:41,256: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,257: Initiating simulation step 31\n", - "2023-10-10 21:00:41,259: Stepping primaite session. Step counter: 32\n", - "2023-10-10 21:00:41,260: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,263: Getting agent action\n", - "2023-10-10 21:00:41,264: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,266: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,267: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,268: Getting agent action\n", - "2023-10-10 21:00:41,269: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,270: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,272: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,273: Getting agent action\n", - "2023-10-10 21:00:41,275: Formatting agent action NODE_FILE_RESTORE\n", - "2023-10-10 21:00:41,277: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,278: Initiating simulation step 32\n", - "2023-10-10 21:00:41,280: Stepping primaite session. Step counter: 33\n", - "2023-10-10 21:00:41,281: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,284: Getting agent action\n", - "2023-10-10 21:00:41,286: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,288: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,289: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,291: Getting agent action\n", - "2023-10-10 21:00:41,293: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,295: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,299: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,301: Getting agent action\n", - "2023-10-10 21:00:41,307: Formatting agent action NETWORK_ACL_REMOVERULE\n", - "2023-10-10 21:00:41,309: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 2]\n", - "2023-10-10 21:00:41,311: Initiating simulation step 33\n", - "2023-10-10 21:00:41,312: Stepping primaite session. Step counter: 34\n", - "2023-10-10 21:00:41,322: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,325: Getting agent action\n", - "2023-10-10 21:00:41,327: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,328: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,339: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,341: Getting agent action\n", - "2023-10-10 21:00:41,343: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,345: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,346: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,348: Getting agent action\n", - "2023-10-10 21:00:41,350: Formatting agent action NODE_FOLDER_CHECKHASH\n", - "2023-10-10 21:00:41,352: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,354: Initiating simulation step 34\n", - "2023-10-10 21:00:41,355: Stepping primaite session. Step counter: 35\n", - "2023-10-10 21:00:41,357: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,359: Getting agent action\n", - "2023-10-10 21:00:41,360: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,362: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,363: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,366: Getting agent action\n", - "2023-10-10 21:00:41,368: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,369: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,370: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,371: Getting agent action\n", - "2023-10-10 21:00:41,373: Formatting agent action NODE_FILE_RESTORE\n", - "2023-10-10 21:00:41,378: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,381: Initiating simulation step 35\n", - "2023-10-10 21:00:41,382: Stepping primaite session. Step counter: 36\n", - "2023-10-10 21:00:41,384: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,386: Getting agent action\n", - "2023-10-10 21:00:41,388: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,389: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,390: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,392: Getting agent action\n", - "2023-10-10 21:00:41,394: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,395: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,397: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,399: Getting agent action\n", - "2023-10-10 21:00:41,401: Formatting agent action NODE_SERVICE_RESUME\n", - "2023-10-10 21:00:41,402: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,403: Initiating simulation step 36\n", - "2023-10-10 21:00:41,405: Stepping primaite session. Step counter: 37\n", - "2023-10-10 21:00:41,406: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,408: Getting agent action\n", - "2023-10-10 21:00:41,409: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,410: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,413: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,415: Getting agent action\n", - "2023-10-10 21:00:41,416: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:41,417: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,418: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,420: Getting agent action\n", - "2023-10-10 21:00:41,422: Formatting agent action NETWORK_ACL_ADDRULE\n", - "2023-10-10 21:00:41,422: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,424: Initiating simulation step 37\n", - "2023-10-10 21:00:41,425: Stepping primaite session. Step counter: 38\n", - "2023-10-10 21:00:41,427: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,429: Getting agent action\n", - "2023-10-10 21:00:41,431: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,432: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,433: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,434: Getting agent action\n", - "2023-10-10 21:00:41,436: Formatting agent action NODE_OS_SCAN\n", - "2023-10-10 21:00:41,438: Sending request to simulation: ['network', 'node', 'ffe02a33-7f9c-4fc1-ad3a-791935dbd4c2', 'scan']\n", - "2023-10-10 21:00:41,440: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,442: Getting agent action\n", - "2023-10-10 21:00:41,444: Formatting agent action NODE_FILE_CHECKHASH\n", - "2023-10-10 21:00:41,449: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,451: Initiating simulation step 38\n", - "2023-10-10 21:00:41,452: Stepping primaite session. Step counter: 39\n", - "2023-10-10 21:00:41,453: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,457: Getting agent action\n", - "2023-10-10 21:00:41,459: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,461: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,462: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,464: Getting agent action\n", - "2023-10-10 21:00:41,465: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,467: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,469: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,472: Getting agent action\n", - "2023-10-10 21:00:41,475: Formatting agent action NODE_SERVICE_SCAN\n", - "2023-10-10 21:00:41,476: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,477: Initiating simulation step 39\n", - "2023-10-10 21:00:41,479: Stepping primaite session. Step counter: 40\n", - "2023-10-10 21:00:41,480: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,482: Getting agent action\n", - "2023-10-10 21:00:41,484: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,486: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,487: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,489: Getting agent action\n", - "2023-10-10 21:00:41,490: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:41,491: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,493: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,495: Getting agent action\n", - "2023-10-10 21:00:41,497: Formatting agent action NETWORK_ACL_REMOVERULE\n", - "2023-10-10 21:00:41,498: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 7]\n", - "2023-10-10 21:00:41,499: Initiating simulation step 40\n", - "2023-10-10 21:00:41,501: Stepping primaite session. Step counter: 41\n", - "2023-10-10 21:00:41,503: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,504: Getting agent action\n", - "2023-10-10 21:00:41,506: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,507: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,509: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,510: Getting agent action\n", - "2023-10-10 21:00:41,513: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:41,514: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,515: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,517: Getting agent action\n", - "2023-10-10 21:00:41,519: Formatting agent action NETWORK_ACL_REMOVERULE\n", - "2023-10-10 21:00:41,520: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 0]\n", - "2023-10-10 21:00:41,521: Initiating simulation step 41\n", - "2023-10-10 21:00:41,522: Stepping primaite session. Step counter: 42\n", - "2023-10-10 21:00:41,523: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,524: Getting agent action\n", - "2023-10-10 21:00:41,527: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,528: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,530: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,532: Getting agent action\n", - "2023-10-10 21:00:41,534: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,535: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,536: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,538: Getting agent action\n", - "2023-10-10 21:00:41,540: Formatting agent action NODE_RESET\n", - "2023-10-10 21:00:41,541: Sending request to simulation: ['network', 'node', '19dbb2d4-648b-4387-aa15-99757b513acb', 'reset']\n", - "2023-10-10 21:00:41,543: Initiating simulation step 42\n", - "2023-10-10 21:00:41,544: Stepping primaite session. Step counter: 43\n", - "2023-10-10 21:00:41,546: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,548: Getting agent action\n", - "2023-10-10 21:00:41,550: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,551: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,552: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,554: Getting agent action\n", - "2023-10-10 21:00:41,555: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,556: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,557: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,559: Getting agent action\n", - "2023-10-10 21:00:41,561: Formatting agent action NODE_FOLDER_RESTORE\n", - "2023-10-10 21:00:41,563: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,565: Initiating simulation step 43\n", - "2023-10-10 21:00:41,566: Stepping primaite session. Step counter: 44\n", - "2023-10-10 21:00:41,567: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,568: Getting agent action\n", - "2023-10-10 21:00:41,569: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,570: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,571: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,574: Getting agent action\n", - "2023-10-10 21:00:41,575: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,577: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,578: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,581: Getting agent action\n", - "2023-10-10 21:00:41,583: Formatting agent action NETWORK_ACL_ADDRULE\n", - "2023-10-10 21:00:41,584: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'add_rule', 'DENY', 'TCP', IPv4Address('192.168.1.12'), 'ALL', IPv4Address('127.0.0.1'), 'ALL', 1]\n", - "2023-10-10 21:00:41,586: Initiating simulation step 44\n", - "2023-10-10 21:00:41,587: Stepping primaite session. Step counter: 45\n", - "2023-10-10 21:00:41,588: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,590: Getting agent action\n", - "2023-10-10 21:00:41,591: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,593: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,594: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,596: Getting agent action\n", - "2023-10-10 21:00:41,598: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,599: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,600: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,602: Getting agent action\n", - "2023-10-10 21:00:41,603: Formatting agent action NETWORK_ACL_REMOVERULE\n", - "2023-10-10 21:00:41,604: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'remove_rule', 1]\n", - "2023-10-10 21:00:41,605: Initiating simulation step 45\n", - "2023-10-10 21:00:41,606: Stepping primaite session. Step counter: 46\n", - "2023-10-10 21:00:41,607: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,608: Getting agent action\n", - "2023-10-10 21:00:41,610: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,612: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,613: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,616: Getting agent action\n", - "2023-10-10 21:00:41,617: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,618: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,620: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,621: Getting agent action\n", - "2023-10-10 21:00:41,623: Formatting agent action NETWORK_ACL_ADDRULE\n", - "2023-10-10 21:00:41,624: Sending request to simulation: ['network', 'node', 'f0fb4743-43d5-4741-a0e5-78340a458a11', 'acl', 'add_rule', 'DENY', 'TCP', IPv4Address('192.168.1.10'), 'ALL', IPv4Address('127.0.0.1'), 'ALL', 1]\n", - "2023-10-10 21:00:41,626: Initiating simulation step 46\n", - "2023-10-10 21:00:41,627: Stepping primaite session. Step counter: 47\n", - "2023-10-10 21:00:41,628: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,630: Getting agent action\n", - "2023-10-10 21:00:41,632: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,634: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,635: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,636: Getting agent action\n", - "2023-10-10 21:00:41,638: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:41,639: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,640: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,642: Getting agent action\n", - "2023-10-10 21:00:41,643: Formatting agent action NETWORK_ACL_ADDRULE\n", - "2023-10-10 21:00:41,644: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,646: Initiating simulation step 47\n", - "2023-10-10 21:00:41,648: Stepping primaite session. Step counter: 48\n", - "2023-10-10 21:00:41,649: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,651: Getting agent action\n", - "2023-10-10 21:00:41,652: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,653: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,654: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,657: Getting agent action\n", - "2023-10-10 21:00:41,658: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:41,661: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,663: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,665: Getting agent action\n", - "2023-10-10 21:00:41,667: Formatting agent action NODE_SERVICE_STOP\n", - "2023-10-10 21:00:41,669: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,670: Initiating simulation step 48\n", - "2023-10-10 21:00:41,672: Stepping primaite session. Step counter: 49\n", - "2023-10-10 21:00:41,674: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,684: Getting agent action\n", - "2023-10-10 21:00:41,687: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,689: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,690: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,701: Getting agent action\n", - "2023-10-10 21:00:41,702: Formatting agent action NODE_FILE_CORRUPT\n", - "2023-10-10 21:00:41,705: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,715: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,718: Getting agent action\n", - "2023-10-10 21:00:41,720: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,734: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,737: Initiating simulation step 49\n", - "2023-10-10 21:00:41,738: Stepping primaite session. Step counter: 50\n", - "2023-10-10 21:00:41,740: Sending simulation state to agent client_1_green_user\n", - "2023-10-10 21:00:41,742: Getting agent action\n", - "2023-10-10 21:00:41,744: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,747: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,750: Sending simulation state to agent client_1_data_manipulation_red_bot\n", - "2023-10-10 21:00:41,753: Getting agent action\n", - "2023-10-10 21:00:41,755: Formatting agent action NODE_FILE_DELETE\n", - "2023-10-10 21:00:41,756: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,758: Sending simulation state to agent defender\n", - "2023-10-10 21:00:41,761: Getting agent action\n", - "2023-10-10 21:00:41,771: Formatting agent action DONOTHING\n", - "2023-10-10 21:00:41,774: Sending request to simulation: ['do_nothing']\n", - "2023-10-10 21:00:41,776: Initiating simulation step 50\n" - ] - } - ], - "source": [ - "for i in range(50):\n", - " sess.step()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "venv", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.12" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -} From f861b1897a73a9085a85e0e5a1c450ce0fad9716 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 25 Oct 2023 13:36:55 +0100 Subject: [PATCH 250/980] Remove deprecated code from v2 --- src/primaite/acl/__init__.py | 2 - src/primaite/acl/access_control_list.py | 198 --- src/primaite/acl/acl_rule.py | 87 - src/primaite/agents/__init__.py | 2 - src/primaite/agents/agent_abc.py | 319 ---- src/primaite/agents/hardcoded_abc.py | 118 -- src/primaite/agents/hardcoded_acl.py | 515 ------ src/primaite/agents/hardcoded_node.py | 125 -- src/primaite/agents/rllib.py | 287 ---- src/primaite/agents/sb3.py | 206 --- src/primaite/agents/simple.py | 59 - src/primaite/agents/utils.py | 450 ------ src/primaite/common/__init__.py | 2 - src/primaite/common/custom_typing.py | 8 - src/primaite/common/enums.py | 208 --- src/primaite/common/protocol.py | 47 - src/primaite/common/service.py | 28 - src/primaite/config/__init__.py | 2 - .../lay_down_config_1_DDOS_basic.yaml | 166 -- .../lay_down_config_2_DDOS_basic.yaml | 366 ----- .../lay_down_config_3_DOS_very_basic.yaml | 164 -- .../lay_down_config_5_data_manipulation.yaml | 546 ------- .../training/training_config_main.yaml | 168 -- src/primaite/config/lay_down_config.py | 141 -- src/primaite/config/training_config.py | 438 ----- src/primaite/data_viz/__init__.py | 15 - src/primaite/data_viz/session_plots.py | 73 - src/primaite/environment/__init__.py | 2 - src/primaite/environment/observations.py | 735 --------- src/primaite/environment/primaite_env.py | 1408 ----------------- src/primaite/environment/reward.py | 386 ----- src/primaite/links/__init__.py | 2 - src/primaite/links/link.py | 114 -- src/primaite/nodes/__init__.py | 2 - src/primaite/nodes/active_node.py | 208 --- src/primaite/nodes/node.py | 79 - .../nodes/node_state_instruction_green.py | 94 -- .../nodes/node_state_instruction_red.py | 143 -- src/primaite/nodes/passive_node.py | 42 - src/primaite/nodes/service_node.py | 190 --- src/primaite/pol/__init__.py | 2 - src/primaite/pol/green_pol.py | 264 ---- src/primaite/pol/ier.py | 147 -- src/primaite/pol/red_agent_pol.py | 353 ----- src/primaite/primaite_session.py | 228 --- .../setup/old_installation_clean_up.py | 14 - src/primaite/transactions/__init__.py | 2 - src/primaite/transactions/transaction.py | 102 -- 48 files changed, 9257 deletions(-) delete mode 100644 src/primaite/acl/__init__.py delete mode 100644 src/primaite/acl/access_control_list.py delete mode 100644 src/primaite/acl/acl_rule.py delete mode 100644 src/primaite/agents/__init__.py delete mode 100644 src/primaite/agents/agent_abc.py delete mode 100644 src/primaite/agents/hardcoded_abc.py delete mode 100644 src/primaite/agents/hardcoded_acl.py delete mode 100644 src/primaite/agents/hardcoded_node.py delete mode 100644 src/primaite/agents/rllib.py delete mode 100644 src/primaite/agents/sb3.py delete mode 100644 src/primaite/agents/simple.py delete mode 100644 src/primaite/agents/utils.py delete mode 100644 src/primaite/common/__init__.py delete mode 100644 src/primaite/common/custom_typing.py delete mode 100644 src/primaite/common/enums.py delete mode 100644 src/primaite/common/protocol.py delete mode 100644 src/primaite/common/service.py delete mode 100644 src/primaite/config/__init__.py delete mode 100644 src/primaite/config/_package_data/lay_down/lay_down_config_1_DDOS_basic.yaml delete mode 100644 src/primaite/config/_package_data/lay_down/lay_down_config_2_DDOS_basic.yaml delete mode 100644 src/primaite/config/_package_data/lay_down/lay_down_config_3_DOS_very_basic.yaml delete mode 100644 src/primaite/config/_package_data/lay_down/lay_down_config_5_data_manipulation.yaml delete mode 100644 src/primaite/config/_package_data/training/training_config_main.yaml delete mode 100644 src/primaite/config/lay_down_config.py delete mode 100644 src/primaite/config/training_config.py delete mode 100644 src/primaite/data_viz/__init__.py delete mode 100644 src/primaite/data_viz/session_plots.py delete mode 100644 src/primaite/environment/__init__.py delete mode 100644 src/primaite/environment/observations.py delete mode 100644 src/primaite/environment/primaite_env.py delete mode 100644 src/primaite/environment/reward.py delete mode 100644 src/primaite/links/__init__.py delete mode 100644 src/primaite/links/link.py delete mode 100644 src/primaite/nodes/__init__.py delete mode 100644 src/primaite/nodes/active_node.py delete mode 100644 src/primaite/nodes/node.py delete mode 100644 src/primaite/nodes/node_state_instruction_green.py delete mode 100644 src/primaite/nodes/node_state_instruction_red.py delete mode 100644 src/primaite/nodes/passive_node.py delete mode 100644 src/primaite/nodes/service_node.py delete mode 100644 src/primaite/pol/__init__.py delete mode 100644 src/primaite/pol/green_pol.py delete mode 100644 src/primaite/pol/ier.py delete mode 100644 src/primaite/pol/red_agent_pol.py delete mode 100644 src/primaite/primaite_session.py delete mode 100644 src/primaite/setup/old_installation_clean_up.py delete mode 100644 src/primaite/transactions/__init__.py delete mode 100644 src/primaite/transactions/transaction.py diff --git a/src/primaite/acl/__init__.py b/src/primaite/acl/__init__.py deleted file mode 100644 index 6dc02583..00000000 --- a/src/primaite/acl/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Access Control List. Models firewall functionality.""" diff --git a/src/primaite/acl/access_control_list.py b/src/primaite/acl/access_control_list.py deleted file mode 100644 index 88943f8f..00000000 --- a/src/primaite/acl/access_control_list.py +++ /dev/null @@ -1,198 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""A class that implements the access control list implementation for the network.""" -import logging -from typing import Dict, Final, List, Union - -from primaite.acl.acl_rule import ACLRule -from primaite.common.enums import RulePermissionType - -_LOGGER: Final[logging.Logger] = logging.getLogger(__name__) - - -class AccessControlList: - """Access Control List class.""" - - def __init__(self, implicit_permission: RulePermissionType, max_acl_rules: int) -> None: - """Init.""" - # Implicit ALLOW or DENY firewall spec - self.acl_implicit_permission = implicit_permission - # Implicit rule in ACL list - if self.acl_implicit_permission == RulePermissionType.DENY: - self.acl_implicit_rule = ACLRule(RulePermissionType.DENY, "ANY", "ANY", "ANY", "ANY") - elif self.acl_implicit_permission == RulePermissionType.ALLOW: - self.acl_implicit_rule = ACLRule(RulePermissionType.ALLOW, "ANY", "ANY", "ANY", "ANY") - else: - raise ValueError(f"implicit permission must be ALLOW or DENY, got {self.acl_implicit_permission}") - - # Maximum number of ACL Rules in ACL - self.max_acl_rules: int = max_acl_rules - # A list of ACL Rules - self._acl: List[Union[ACLRule, None]] = [None] * (self.max_acl_rules - 1) - - @property - def acl(self) -> List[Union[ACLRule, None]]: - """Public access method for private _acl.""" - return self._acl + [self.acl_implicit_rule] - - def check_address_match(self, _rule: ACLRule, _source_ip_address: str, _dest_ip_address: str) -> bool: - """Checks for IP address matches. - - :param _rule: The rule object to check - :type _rule: ACLRule - :param _source_ip_address: Source IP address to compare - :type _source_ip_address: str - :param _dest_ip_address: Destination IP address to compare - :type _dest_ip_address: str - :return: True if there is a match, otherwise False. - :rtype: bool - """ - if ( - (_rule.get_source_ip() == _source_ip_address and _rule.get_dest_ip() == _dest_ip_address) - or (_rule.get_source_ip() == "ANY" and _rule.get_dest_ip() == _dest_ip_address) - or (_rule.get_source_ip() == _source_ip_address and _rule.get_dest_ip() == "ANY") - or (_rule.get_source_ip() == "ANY" and _rule.get_dest_ip() == "ANY") - ): - return True - else: - return False - - def is_blocked(self, _source_ip_address: str, _dest_ip_address: str, _protocol: str, _port: str) -> bool: - """ - Checks for rules that block a protocol / port. - - Args: - _source_ip_address: the source IP address to check - _dest_ip_address: the destination IP address to check - _protocol: the protocol to check - _port: the port to check - - Returns: - Indicates block if all conditions are satisfied. - """ - for rule in self.acl: - if isinstance(rule, ACLRule): - if self.check_address_match(rule, _source_ip_address, _dest_ip_address): - if (rule.get_protocol() == _protocol or rule.get_protocol() == "ANY") and ( - str(rule.get_port()) == str(_port) or rule.get_port() == "ANY" - ): - # There's a matching rule. Get the permission - if rule.get_permission() == RulePermissionType.DENY: - return True - elif rule.get_permission() == RulePermissionType.ALLOW: - return False - - # If there has been no rule to allow the IER through, it will return a blocked signal by default - return True - - def add_rule( - self, - _permission: RulePermissionType, - _source_ip: str, - _dest_ip: str, - _protocol: str, - _port: str, - _position: str, - ) -> None: - """ - Adds a new rule. - - Args: - _permission: the permission value (e.g. "ALLOW" or "DENY") - _source_ip: the source IP address - _dest_ip: the destination IP address - _protocol: the protocol - _port: the port - _position: position to insert ACL rule into ACL list (starting from index 1 and NOT 0) - """ - try: - position_index = int(_position) - except TypeError: - _LOGGER.info(f"Position {_position} could not be converted to integer.") - return - - new_rule = ACLRule(_permission, _source_ip, _dest_ip, _protocol, str(_port)) - # Checks position is in correct range - if self.max_acl_rules - 1 > position_index > -1: - try: - _LOGGER.info(f"Position {position_index} is valid.") - # Check to see Agent will not overwrite current ACL in ACL list - if self._acl[position_index] is None: - _LOGGER.info(f"Inserting rule {new_rule} at position {position_index}") - # Adds rule - self._acl[position_index] = new_rule - else: - # Cannot overwrite it - _LOGGER.info(f"Error: inserting rule at non-empty position {position_index}") - return - except Exception: - _LOGGER.info(f"New Rule could NOT be added to list at position {position_index}.") - else: - _LOGGER.info(f"Position {position_index} is an invalid/overwrites implicit firewall rule") - - def remove_rule( - self, _permission: RulePermissionType, _source_ip: str, _dest_ip: str, _protocol: str, _port: str - ) -> None: - """ - Removes a rule. - - Args: - _permission: the permission value (e.g. "ALLOW" or "DENY") - _source_ip: the source IP address - _dest_ip: the destination IP address - _protocol: the protocol - _port: the port - """ - rule_to_delete = ACLRule(_permission, _source_ip, _dest_ip, _protocol, str(_port)) - delete_rule_hash = hash(rule_to_delete) - - for index in range(0, len(self._acl)): - if isinstance(self._acl[index], ACLRule) and hash(self._acl[index]) == delete_rule_hash: - self._acl[index] = None - - def remove_all_rules(self) -> None: - """Removes all rules.""" - for i in range(len(self._acl)): - self._acl[i] = None - - def get_dictionary_hash( - self, _permission: RulePermissionType, _source_ip: str, _dest_ip: str, _protocol: str, _port: str - ) -> int: - """ - Produces a hash value for a rule. - - Args: - _permission: the permission value (e.g. "ALLOW" or "DENY") - _source_ip: the source IP address - _dest_ip: the destination IP address - _protocol: the protocol - _port: the port - - Returns: - Hash value based on rule parameters. - """ - rule = ACLRule(_permission, _source_ip, _dest_ip, _protocol, str(_port)) - hash_value = hash(rule) - return hash_value - - def get_relevant_rules( - self, _source_ip_address: str, _dest_ip_address: str, _protocol: str, _port: str - ) -> Dict[int, ACLRule]: - """Get all ACL rules that relate to the given arguments. - - :param _source_ip_address: the source IP address to check - :param _dest_ip_address: the destination IP address to check - :param _protocol: the protocol to check - :param _port: the port to check - :return: Dictionary of all ACL rules that relate to the given arguments - :rtype: Dict[int, ACLRule] - """ - relevant_rules = {} - for rule in self.acl: - if self.check_address_match(rule, _source_ip_address, _dest_ip_address): - if (rule.get_protocol() == _protocol or rule.get_protocol() == "ANY" or _protocol == "ANY") and ( - str(rule.get_port()) == str(_port) or rule.get_port() == "ANY" or str(_port) == "ANY" - ): - # There's a matching rule. - relevant_rules[self._acl.index(rule)] = rule - - return relevant_rules diff --git a/src/primaite/acl/acl_rule.py b/src/primaite/acl/acl_rule.py deleted file mode 100644 index 9c8deacd..00000000 --- a/src/primaite/acl/acl_rule.py +++ /dev/null @@ -1,87 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""A class that implements an access control list rule.""" -from primaite.common.enums import RulePermissionType - - -class ACLRule: - """Access Control List Rule class.""" - - def __init__( - self, _permission: RulePermissionType, _source_ip: str, _dest_ip: str, _protocol: str, _port: str - ) -> None: - """ - Initialise an ACL Rule. - - :param _permission: The permission (ALLOW or DENY) - :param _source_ip: The source IP address - :param _dest_ip: The destination IP address - :param _protocol: The rule protocol - :param _port: The rule port - """ - self.permission: RulePermissionType = _permission - self.source_ip: str = _source_ip - self.dest_ip: str = _dest_ip - self.protocol: str = _protocol - self.port: str = _port - - def __hash__(self) -> int: - """ - Override the hash function. - - Returns: - Returns hash of core parameters. - """ - return hash( - ( - self.permission, - self.source_ip, - self.dest_ip, - self.protocol, - self.port, - ) - ) - - def get_permission(self) -> str: - """ - Gets the permission attribute. - - Returns: - Returns permission attribute - """ - return self.permission - - def get_source_ip(self) -> str: - """ - Gets the source IP address attribute. - - Returns: - Returns source IP address attribute - """ - return self.source_ip - - def get_dest_ip(self) -> str: - """ - Gets the desintation IP address attribute. - - Returns: - Returns destination IP address attribute - """ - return self.dest_ip - - def get_protocol(self) -> str: - """ - Gets the protocol attribute. - - Returns: - Returns protocol attribute - """ - return self.protocol - - def get_port(self) -> str: - """ - Gets the port attribute. - - Returns: - Returns port attribute - """ - return self.port diff --git a/src/primaite/agents/__init__.py b/src/primaite/agents/__init__.py deleted file mode 100644 index c742daf3..00000000 --- a/src/primaite/agents/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Common interface between RL agents from different libraries and PrimAITE.""" diff --git a/src/primaite/agents/agent_abc.py b/src/primaite/agents/agent_abc.py deleted file mode 100644 index 359790ad..00000000 --- a/src/primaite/agents/agent_abc.py +++ /dev/null @@ -1,319 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -from __future__ import annotations - -import json -from abc import ABC, abstractmethod -from datetime import datetime -from logging import Logger -from pathlib import Path -from typing import Any, Dict, Optional, Union -from uuid import uuid4 - -import primaite -from primaite import getLogger, PRIMAITE_PATHS -from primaite.config import lay_down_config, training_config -from primaite.config.training_config import TrainingConfig -from primaite.data_viz.session_plots import plot_av_reward_per_episode -from primaite.environment.primaite_env import Primaite -from primaite.utils.session_metadata_parser import parse_session_metadata - -_LOGGER: Logger = getLogger(__name__) - - -def get_session_path(session_timestamp: datetime) -> Path: - """ - Get the directory path the session will output to. - - This is set in the format of: - ~/primaite/2.0.0/sessions//_. - - :param session_timestamp: This is the datetime that the session started. - :return: The session directory path. - """ - date_dir = session_timestamp.strftime("%Y-%m-%d") - session_path = session_timestamp.strftime("%Y-%m-%d_%H-%M-%S") - session_path = PRIMAITE_PATHS.user_sessions_path / date_dir / session_path - session_path.mkdir(exist_ok=True, parents=True) - - return session_path - - -class AgentSessionABC(ABC): - """ - An ABC that manages training and/or evaluation of agents in PrimAITE. - - This class cannot be directly instantiated and must be inherited from with all implemented abstract methods - implemented. - """ - - @abstractmethod - def __init__( - self, - training_config_path: Optional[Union[str, Path]] = None, - lay_down_config_path: Optional[Union[str, Path]] = None, - session_path: Optional[Union[str, Path]] = None, - legacy_training_config: bool = False, - legacy_lay_down_config: bool = False, - ) -> None: - """ - Initialise an agent session from config files, or load a previous session. - - If training configuration and laydown configuration are provided with a session path, - the session path will be used. - - :param training_config_path: YAML file containing configurable items defined in - `primaite.config.training_config.TrainingConfig` - :type training_config_path: Union[path, str] - :param lay_down_config_path: YAML file containing configurable items for generating network laydown. - :type lay_down_config_path: Union[path, str] - :param legacy_training_config: True if the training config file is a legacy file from PrimAITE < 2.0, - otherwise False. - :param legacy_lay_down_config: True if the lay_down config file is a legacy file from PrimAITE < 2.0, - otherwise False. - :param session_path: directory path of the session to load - """ - # initialise variables - self._env: Primaite - self._agent = None - self._can_learn: bool = False - self._can_evaluate: bool = False - self.is_eval = False - self.legacy_training_config = legacy_training_config - self.legacy_lay_down_config = legacy_lay_down_config - - self.session_timestamp: datetime = datetime.now() - - # convert session to path - if session_path is not None: - if not isinstance(session_path, Path): - session_path = Path(session_path) - - # if a session path is provided, load it - if not session_path.exists(): - raise Exception(f"Session could not be loaded. Path does not exist: {session_path}") - - # load session - self.load(session_path) - else: - # set training config path - if not isinstance(training_config_path, Path): - training_config_path = Path(training_config_path) - self._training_config_path: Union[Path, str] = training_config_path - self._training_config: TrainingConfig = training_config.load( - self._training_config_path, legacy_file=legacy_training_config - ) - - if not isinstance(lay_down_config_path, Path): - lay_down_config_path = Path(lay_down_config_path) - self._lay_down_config_path: Union[Path, str] = lay_down_config_path - self._lay_down_config: Dict = lay_down_config.load(self._lay_down_config_path, legacy_lay_down_config) - self.sb3_output_verbose_level = self._training_config.sb3_output_verbose_level - - # set random UUID for session - self._uuid = str(uuid4()) - "The session timestamp" - self.session_path = get_session_path(self.session_timestamp) - "The Session path" - - @property - def timestamp_str(self) -> str: - """The session timestamp as a string.""" - return self.session_timestamp.strftime("%Y-%m-%d_%H-%M-%S") - - @property - def learning_path(self) -> Path: - """The learning outputs path.""" - path = self.session_path / "learning" - path.mkdir(exist_ok=True, parents=True) - return path - - @property - def evaluation_path(self) -> Path: - """The evaluation outputs path.""" - path = self.session_path / "evaluation" - path.mkdir(exist_ok=True, parents=True) - return path - - @property - def checkpoints_path(self) -> Path: - """The Session checkpoints path.""" - path = self.learning_path / "checkpoints" - path.mkdir(exist_ok=True, parents=True) - return path - - @property - def uuid(self) -> str: - """The Agent Session UUID.""" - return self._uuid - - def _write_session_metadata_file(self) -> None: - """ - Write the ``session_metadata.json`` file. - - Creates a ``session_metadata.json`` in the ``session_path`` directory - and adds the following key/value pairs: - - - uuid: The UUID assigned to the session upon instantiation. - - start_datetime: The date & time the session started in iso format. - - end_datetime: NULL. - - total_episodes: NULL. - - total_time_steps: NULL. - - env: - - training_config: - - All training config items - - lay_down_config: - - All lay down config items - - """ - metadata_dict = { - "uuid": self.uuid, - "start_datetime": self.session_timestamp.isoformat(), - "end_datetime": None, - "learning": {"total_episodes": None, "total_time_steps": None}, - "evaluation": {"total_episodes": None, "total_time_steps": None}, - "env": { - "training_config": self._training_config.to_dict(json_serializable=True), - "lay_down_config": self._lay_down_config, - }, - } - filepath = self.session_path / "session_metadata.json" - _LOGGER.debug(f"Writing Session Metadata file: {filepath}") - with open(filepath, "w") as file: - json.dump(metadata_dict, file) - _LOGGER.debug("Finished writing session metadata file") - - def _update_session_metadata_file(self) -> None: - """ - Update the ``session_metadata.json`` file. - - Updates the `session_metadata.json`` in the ``session_path`` directory - with the following key/value pairs: - - - end_datetime: The date & time the session ended in iso format. - - total_episodes: The total number of training episodes completed. - - total_time_steps: The total number of training time steps completed. - """ - with open(self.session_path / "session_metadata.json", "r") as file: - metadata_dict = json.load(file) - - metadata_dict["end_datetime"] = datetime.now().isoformat() - if not self.is_eval: - metadata_dict["learning"]["total_episodes"] = self._env.actual_episode_count # noqa - metadata_dict["learning"]["total_time_steps"] = self._env.total_step_count # noqa - else: - metadata_dict["evaluation"]["total_episodes"] = self._env.actual_episode_count # noqa - metadata_dict["evaluation"]["total_time_steps"] = self._env.total_step_count # noqa - - filepath = self.session_path / "session_metadata.json" - _LOGGER.debug(f"Updating Session Metadata file: {filepath}") - with open(filepath, "w") as file: - json.dump(metadata_dict, file) - _LOGGER.debug("Finished updating session metadata file") - - @abstractmethod - def _setup(self) -> None: - _LOGGER.info( - "Welcome to the Primary-level AI Training Environment " f"(PrimAITE) (version: {primaite.__version__})" - ) - _LOGGER.info(f"The output directory for this session is: {self.session_path}") - self._write_session_metadata_file() - self._can_learn = True - self._can_evaluate = False - - @abstractmethod - def _save_checkpoint(self) -> None: - pass - - @abstractmethod - def learn( - self, - **kwargs: Any, - ) -> None: - """ - Train the agent. - - :param kwargs: Any agent-specific key-word args to be passed. - """ - if self._can_learn: - _LOGGER.info("Finished learning") - _LOGGER.debug("Writing transactions") - self._update_session_metadata_file() - self._can_evaluate = True - self.is_eval = False - - @abstractmethod - def evaluate( - self, - **kwargs: Any, - ) -> None: - """ - Evaluate the agent. - - :param kwargs: Any agent-specific key-word args to be passed. - """ - if self._can_evaluate: - self._update_session_metadata_file() - self.is_eval = True - self._plot_av_reward_per_episode(learning_session=False) - _LOGGER.info("Finished evaluation") - - @abstractmethod - def _get_latest_checkpoint(self) -> None: - pass - - def load(self, path: Union[str, Path]) -> None: - """Load an agent from file.""" - md_dict, training_config_path, laydown_config_path = parse_session_metadata(path) - - # set training config path - self._training_config_path: Union[Path, str] = training_config_path - self._training_config: TrainingConfig = training_config.load(self._training_config_path) - self._lay_down_config_path: Union[Path, str] = laydown_config_path - self._lay_down_config: Dict = lay_down_config.load(self._lay_down_config_path) - self.sb3_output_verbose_level = self._training_config.sb3_output_verbose_level - - # set random UUID for session - self._uuid = md_dict["uuid"] - - # set the session path - self.session_path = path - "The Session path" - - @property - def _saved_agent_path(self) -> Path: - file_name = f"{self._training_config.agent_framework}_" f"{self._training_config.agent_identifier}" f".zip" - return self.learning_path / file_name - - @abstractmethod - def save(self) -> None: - """Save the agent.""" - pass - - @abstractmethod - def export(self) -> None: - """Export the agent to transportable file format.""" - pass - - def close(self) -> None: - """Closes the agent.""" - self._env.episode_av_reward_writer.close() # noqa - self._env.transaction_writer.close() # noqa - - def _plot_av_reward_per_episode(self, learning_session: bool = True) -> None: - # self.close() - title = f"PrimAITE Session {self.timestamp_str} " - subtitle = str(self._training_config) - csv_file = f"average_reward_per_episode_{self.timestamp_str}.csv" - image_file = f"average_reward_per_episode_{self.timestamp_str}.png" - if learning_session: - title += "(Learning)" - path = self.learning_path / csv_file - image_path = self.learning_path / image_file - else: - title += "(Evaluation)" - path = self.evaluation_path / csv_file - image_path = self.evaluation_path / image_file - - fig = plot_av_reward_per_episode(path, title, subtitle) - fig.write_image(image_path) - _LOGGER.debug(f"Saved average rewards per episode plot to: {path}") diff --git a/src/primaite/agents/hardcoded_abc.py b/src/primaite/agents/hardcoded_abc.py deleted file mode 100644 index e75edbc5..00000000 --- a/src/primaite/agents/hardcoded_abc.py +++ /dev/null @@ -1,118 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import time -from abc import abstractmethod -from pathlib import Path -from typing import Any, Optional, Union - -import numpy as np - -from primaite import getLogger -from primaite.agents.agent_abc import AgentSessionABC -from primaite.environment.primaite_env import Primaite - -_LOGGER = getLogger(__name__) - - -class HardCodedAgentSessionABC(AgentSessionABC): - """ - An Agent Session ABC for evaluation deterministic agents. - - This class cannot be directly instantiated and must be inherited from with all implemented abstract methods - implemented. - """ - - def __init__( - self, - training_config_path: Optional[Union[str, Path]] = "", - lay_down_config_path: Optional[Union[str, Path]] = "", - session_path: Optional[Union[str, Path]] = None, - ) -> None: - """ - Initialise a hardcoded agent session. - - :param training_config_path: YAML file containing configurable items defined in - `primaite.config.training_config.TrainingConfig` - :type training_config_path: Union[path, str] - :param lay_down_config_path: YAML file containing configurable items for generating network laydown. - :type lay_down_config_path: Union[path, str] - """ - super().__init__(training_config_path, lay_down_config_path, session_path) - self._setup() - - def _setup(self) -> None: - self._env: Primaite = Primaite( - training_config_path=self._training_config_path, - lay_down_config_path=self._lay_down_config_path, - session_path=self.session_path, - timestamp_str=self.timestamp_str, - ) - super()._setup() - self._can_learn = False - self._can_evaluate = True - - def _save_checkpoint(self) -> None: - pass - - def _get_latest_checkpoint(self) -> None: - pass - - def learn( - self, - **kwargs: Any, - ) -> None: - """ - Train the agent. - - :param kwargs: Any agent-specific key-word args to be passed. - """ - _LOGGER.warning("Deterministic agents cannot learn") - - @abstractmethod - def _calculate_action(self, obs: np.ndarray) -> None: - pass - - def evaluate( - self, - **kwargs: Any, - ) -> None: - """ - Evaluate the agent. - - :param kwargs: Any agent-specific key-word args to be passed. - """ - self._env.set_as_eval() # noqa - self.is_eval = True - - time_steps = self._training_config.num_eval_steps - episodes = self._training_config.num_eval_episodes - - obs = self._env.reset() - for episode in range(episodes): - # Reset env and collect initial observation - for step in range(time_steps): - # Calculate action - action = self._calculate_action(obs) - - # Perform the step - obs, reward, done, info = self._env.step(action) - - if done: - break - - # Introduce a delay between steps - time.sleep(self._training_config.time_delay / 1000) - obs = self._env.reset() - self._env.close() - - @classmethod - def load(cls, path: Union[str, Path] = None) -> None: - """Load an agent from file.""" - _LOGGER.warning("Deterministic agents cannot be loaded") - - def save(self) -> None: - """Save the agent.""" - _LOGGER.warning("Deterministic agents cannot be saved") - - def export(self) -> None: - """Export the agent to transportable file format.""" - _LOGGER.warning("Deterministic agents cannot be exported") diff --git a/src/primaite/agents/hardcoded_acl.py b/src/primaite/agents/hardcoded_acl.py deleted file mode 100644 index 2440da06..00000000 --- a/src/primaite/agents/hardcoded_acl.py +++ /dev/null @@ -1,515 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -from typing import Dict, List, Union - -import numpy as np - -from primaite.acl.access_control_list import AccessControlList -from primaite.acl.acl_rule import ACLRule -from primaite.agents.hardcoded_abc import HardCodedAgentSessionABC -from primaite.agents.utils import ( - get_new_action, - get_node_of_ip, - transform_action_acl_enum, - transform_change_obs_readable, -) -from primaite.common.custom_typing import NodeUnion -from primaite.common.enums import HardCodedAgentView -from primaite.nodes.active_node import ActiveNode -from primaite.nodes.service_node import ServiceNode -from primaite.pol.ier import IER - - -class HardCodedACLAgent(HardCodedAgentSessionABC): - """An Agent Session class that implements a deterministic ACL agent.""" - - def _calculate_action(self, obs: np.ndarray) -> int: - if self._training_config.hard_coded_agent_view == HardCodedAgentView.BASIC: - # Basic view action using only the current observation - return self._calculate_action_basic_view(obs) - else: - # full view action using observation space, action - # history and reward feedback - return self._calculate_action_full_view(obs) - - def get_blocked_green_iers( - self, green_iers: Dict[str, IER], acl: AccessControlList, nodes: Dict[str, NodeUnion] - ) -> Dict[str, IER]: - """Get blocked green IERs. - - :param green_iers: Green IERs to check for being - :type green_iers: Dict[str, IER] - :param acl: Firewall rules - :type acl: AccessControlList - :param nodes: Nodes in the network - :type nodes: Dict[str,NodeUnion] - :return: Same as `green_iers` input dict, but filtered to only contain the blocked ones. - :rtype: Dict[str, IER] - """ - blocked_green_iers = {} - - for green_ier_id, green_ier in green_iers.items(): - source_node_id = green_ier.get_source_node_id() - source_node_address = nodes[source_node_id].ip_address - dest_node_id = green_ier.get_dest_node_id() - dest_node_address = nodes[dest_node_id].ip_address - protocol = green_ier.get_protocol() # e.g. 'TCP' - port = green_ier.get_port() - - # Can be blocked by an ACL or by default (no allow rule exists) - if acl.is_blocked(source_node_address, dest_node_address, protocol, port): - blocked_green_iers[green_ier_id] = green_ier - - return blocked_green_iers - - def get_matching_acl_rules_for_ier( - self, ier: IER, acl: AccessControlList, nodes: Dict[str, NodeUnion] - ) -> Dict[int, ACLRule]: - """Get list of ACL rules which are relevant to an IER. - - :param ier: Information Exchange Request to query against the ACL list - :type ier: IER - :param acl: Firewall rules - :type acl: AccessControlList - :param nodes: Nodes in the network - :type nodes: Dict[str,NodeUnion] - :return: _description_ - :rtype: _type_ - """ - source_node_id = ier.get_source_node_id() - source_node_address = nodes[source_node_id].ip_address - dest_node_id = ier.get_dest_node_id() - dest_node_address = nodes[dest_node_id].ip_address - protocol = ier.get_protocol() # e.g. 'TCP' - port = ier.get_port() - matching_rules = acl.get_relevant_rules(source_node_address, dest_node_address, protocol, port) - return matching_rules - - def get_blocking_acl_rules_for_ier( - self, ier: IER, acl: AccessControlList, nodes: Dict[str, NodeUnion] - ) -> Dict[int, ACLRule]: - """ - Get blocking ACL rules for an IER. - - .. warning:: - Can return empty dict but IER can still be blocked by default - (No ALLOW rule, therefore blocked). - - :param ier: Information Exchange Request to query against the ACL list - :type ier: IER - :param acl: Firewall rules - :type acl: AccessControlList - :param nodes: Nodes in the network - :type nodes: Dict[str,NodeUnion] - :return: _description_ - :rtype: _type_ - """ - matching_rules = self.get_matching_acl_rules_for_ier(ier, acl, nodes) - - blocked_rules = {} - for rule_key, rule_value in matching_rules.items(): - if rule_value.get_permission() == "DENY": - blocked_rules[rule_key] = rule_value - - return blocked_rules - - def get_allow_acl_rules_for_ier( - self, ier: IER, acl: AccessControlList, nodes: Dict[str, NodeUnion] - ) -> Dict[int, ACLRule]: - """Get all allowing ACL rules for an IER. - - :param ier: Information Exchange Request to query against the ACL list - :type ier: IER - :param acl: Firewall rules - :type acl: AccessControlList - :param nodes: Nodes in the network - :type nodes: Dict[str,NodeUnion] - :return: _description_ - :rtype: _type_ - """ - matching_rules = self.get_matching_acl_rules_for_ier(ier, acl, nodes) - - allowed_rules = {} - for rule_key, rule_value in matching_rules.items(): - if rule_value.get_permission() == "ALLOW": - allowed_rules[rule_key] = rule_value - - return allowed_rules - - def get_matching_acl_rules( - self, - source_node_id: str, - dest_node_id: str, - protocol: str, - port: str, - acl: AccessControlList, - nodes: Dict[str, Union[ServiceNode, ActiveNode]], - services_list: List[str], - ) -> Dict[int, ACLRule]: - """Filter ACL rules to only those which are relevant to the specified nodes. - - :param source_node_id: Source node - :type source_node_id: str - :param dest_node_id: Destination nodes - :type dest_node_id: str - :param protocol: Network protocol - :type protocol: str - :param port: Network port - :type port: str - :param acl: Access Control list which will be filtered - :type acl: AccessControlList - :param nodes: The environment's node directory. - :type nodes: Dict[str, Union[ServiceNode, ActiveNode]] - :param services_list: List of services registered for the environment. - :type services_list: List[str] - :return: Filtered version of 'acl' - :rtype: Dict[str, ACLRule] - """ - if source_node_id != "ANY": - source_node_address = nodes[str(source_node_id)].ip_address - else: - source_node_address = source_node_id - - if dest_node_id != "ANY": - dest_node_address = nodes[str(dest_node_id)].ip_address - else: - dest_node_address = dest_node_id - - if protocol != "ANY": - protocol = services_list[protocol - 1] # -1 as dont have to account for ANY in list of services - # TODO: This should throw an error because protocol is a string - - matching_rules = acl.get_relevant_rules(source_node_address, dest_node_address, protocol, port) - return matching_rules - - def get_allow_acl_rules( - self, - source_node_id: int, - dest_node_id: str, - protocol: int, - port: str, - acl: AccessControlList, - nodes: Dict[str, NodeUnion], - services_list: List[str], - ) -> Dict[int, ACLRule]: - """List ALLOW rules relating to specified nodes. - - :param source_node_id: Source node id - :type source_node_id: int - :param dest_node_id: Destination node - :type dest_node_id: str - :param protocol: Network protocol - :type protocol: int - :param port: Port - :type port: str - :param acl: Firewall ruleset which is applied to the network - :type acl: AccessControlList - :param nodes: The simulation's node store - :type nodes: Dict[str, NodeUnion] - :param services_list: Services list - :type services_list: List[str] - :return: Filtered ACL Rule directory which includes only those rules which affect the specified source and - desination nodes - :rtype: Dict[str, ACLRule] - """ - matching_rules = self.get_matching_acl_rules( - source_node_id, - dest_node_id, - protocol, - port, - acl, - nodes, - services_list, - ) - - allowed_rules = {} - for rule_key, rule_value in matching_rules.items(): - if rule_value.get_permission() == "ALLOW": - allowed_rules[rule_key] = rule_value - - return allowed_rules - - def get_deny_acl_rules( - self, - source_node_id: int, - dest_node_id: str, - protocol: int, - port: str, - acl: AccessControlList, - nodes: Dict[str, NodeUnion], - services_list: List[str], - ) -> Dict[int, ACLRule]: - """List DENY rules relating to specified nodes. - - :param source_node_id: Source node id - :type source_node_id: int - :param dest_node_id: Destination node - :type dest_node_id: str - :param protocol: Network protocol - :type protocol: int - :param port: Port - :type port: str - :param acl: Firewall ruleset which is applied to the network - :type acl: AccessControlList - :param nodes: The simulation's node store - :type nodes: Dict[str, NodeUnion] - :param services_list: Services list - :type services_list: List[str] - :return: Filtered ACL Rule directory which includes only those rules which affect the specified source and - desination nodes - :rtype: Dict[str, ACLRule] - """ - matching_rules = self.get_matching_acl_rules( - source_node_id, - dest_node_id, - protocol, - port, - acl, - nodes, - services_list, - ) - - allowed_rules = {} - for rule_key, rule_value in matching_rules.items(): - if rule_value.get_permission() == "DENY": - allowed_rules[rule_key] = rule_value - - return allowed_rules - - def _calculate_action_full_view(self, obs: np.ndarray) -> int: - """ - Calculate a good acl-based action for the blue agent to take. - - Knowledge of just the observation space is insufficient for a perfect solution, as we need to know: - - - Which ACL rules already exist, - otherwise: - - The agent would perminently get stuck in a loop of performing the same action over and over. - (best action is to block something, but its already blocked but doesn't know this) - - The agent would be unable to interact with existing rules (e.g. how would it know to delete a rule, - if it doesnt know what rules exist) - - The Green IERs (optional) - It often needs to know which traffic it should be allowing. For example - in the default config one of the green IERs is blocked by default, but it has no way of knowing this - based on the observation space. Additionally, potentially in the future, once a node state - has been fixed (no longer compromised), it needs a way to know it should reallow traffic. - A RL agent can learn what the green IERs are on its own - but the rule based agent cannot easily do this. - - There doesn't seem like there's much that can be done if an Operating or OS State is compromised - - If a service node becomes compromised there's a decision to make - do we block that service? - Pros: It cannot launch an attack on another node, so the node will not be able to be OVERWHELMED - Cons: Will block a green IER, decreasing the reward - We decide to block the service. - - Potentially a better solution (for the reward) would be to block the incomming traffic from compromised - nodes once a service becomes overwhelmed. However currently the ACL action space has no way of reversing - an overwhelmed state, so we don't do this. - - :param obs: current observation from the gym environment - :type obs: np.ndarray - :return: Optimal action to take in the environment (chosen from the discrete action space) - :rtype: int - """ - # obs = convert_to_old_obs(obs) - r_obs = transform_change_obs_readable(obs) - _, _, _, *s = r_obs - - if len(r_obs) == 4: # only 1 service - s = [*s] - - # 1. Check if node is compromised. If so we want to block its outwards services - # a. If it is comprimised check if there's an allow rule we should delete. - # cons: might delete a multi-rule from any source node (ANY -> x) - # b. OPTIONAL (Deny rules not needed): Check if there already exists an existing Deny Rule so not to duplicate - # c. OPTIONAL (no allow rule = blocked): Add a DENY rule - found_action = False - for service_num, service_states in enumerate(s): - for x, service_state in enumerate(service_states): - if service_state == "COMPROMISED": - action_source_id = x + 1 # +1 as 0 is any - action_destination_id = "ANY" - action_protocol = service_num + 1 # +1 as 0 is any - action_port = "ANY" - - allow_rules = self.get_allow_acl_rules( - action_source_id, - action_destination_id, - action_protocol, - action_port, - self._env.acl, - self._env.nodes, - self._env.services_list, - ) - deny_rules = self.get_deny_acl_rules( - action_source_id, - action_destination_id, - action_protocol, - action_port, - self._env.acl, - self._env.nodes, - self._env.services_list, - ) - if len(allow_rules) > 0: - # Check if there's an allow rule we should delete - rule = list(allow_rules.values())[0] - action_decision = "DELETE" - action_permission = "ALLOW" - action_source_ip = rule.get_source_ip() - action_source_id = int(get_node_of_ip(action_source_ip, self._env.nodes)) - action_destination_ip = rule.get_dest_ip() - action_destination_id = int(get_node_of_ip(action_destination_ip, self._env.nodes)) - action_protocol_name = rule.get_protocol() - action_protocol = ( - self._env.services_list.index(action_protocol_name) + 1 - ) # convert name e.g. 'TCP' to index - action_port_name = rule.get_port() - action_port = ( - self._env.ports_list.index(action_port_name) + 1 - ) # convert port name e.g. '80' to index - - found_action = True - break - elif len(deny_rules) > 0: - # TODO OPTIONAL - # If there's already a DENY RULE, that blocks EVERYTHING from the source ip we don't need - # to create another - # Check to see if the DENY rule really blocks everything (ANY) or just a specific rule - continue - else: - # TODO OPTIONAL: Add a DENY rule, optional as by default no allow rule == blocked - action_decision = "CREATE" - action_permission = "DENY" - break - if found_action: - break - - # 2. If NO Node is Comprimised, or the node has already been blocked, check the green IERs and - # add an Allow rule if the green IER is being blocked. - # a. OPTIONAL - NOT IMPLEMENTED (optional as a deny rule does not overwrite an allow rule): - # If there's a DENY rule delete it if: - # - There isn't already a deny rule - # - It doesnt allows a comprimised node to become operational. - # b. Add an ALLOW rule if: - # - There isn't already an allow rule - # - It doesnt allows a comprimised node to become operational - - if not found_action: - # Which Green IERS are blocked - blocked_green_iers = self.get_blocked_green_iers(self._env.green_iers, self._env.acl, self._env.nodes) - for ier_key, ier in blocked_green_iers.items(): - # Which ALLOW rules are allowing this IER (none) - allowing_rules = self.get_allow_acl_rules_for_ier(ier, self._env.acl, self._env.nodes) - - # If there are no blocking rules, it may be being blocked by default - # If there is already an allow rule - node_id_to_check = int(ier.get_source_node_id()) - service_name_to_check = ier.get_protocol() - service_id_to_check = self._env.services_list.index(service_name_to_check) - - # Service state of the the source node in the ier - service_state = s[service_id_to_check][node_id_to_check - 1] - - if len(allowing_rules) == 0 and service_state != "COMPROMISED": - action_decision = "CREATE" - action_permission = "ALLOW" - action_source_id = int(ier.get_source_node_id()) - action_destination_id = int(ier.get_dest_node_id()) - action_protocol_name = ier.get_protocol() - action_protocol = ( - self._env.services_list.index(action_protocol_name) + 1 - ) # convert name e.g. 'TCP' to index - action_port_name = ier.get_port() - action_port = ( - self._env.ports_list.index(action_port_name) + 1 - ) # convert port name e.g. '80' to index - - found_action = True - break - - if found_action: - action = [ - action_decision, - action_permission, - action_source_id, - action_destination_id, - action_protocol, - action_port, - ] - action = transform_action_acl_enum(action) - action = get_new_action(action, self._env.action_dict) - else: - # If no good/useful action has been found, just perform a nothing action - action = ["NONE", "ALLOW", "ANY", "ANY", "ANY", "ANY"] - action = transform_action_acl_enum(action) - action = get_new_action(action, self._env.action_dict) - return action - - def _calculate_action_basic_view(self, obs: np.ndarray) -> int: - """ - Calculate a good acl-based action for the blue agent to take. - - Uses ONLY information from the current observation with NO knowledge - of previous actions taken and NO reward feedback. - - We rely on randomness to select the precise action, as we want to - block all traffic originating from a compromised node, without being - able to tell: - 1. Which ACL rules already exist - 2. Which actions the agent has already tried. - - There is a high probability that the correct rule will not be deleted - before the state becomes overwhelmed. - - Currently, a deny rule does not overwrite an allow rule. The allow - rules must be deleted. - - :param obs: current observation from the gym environment - :type obs: np.ndarray - :return: Optimal action to take in the environment (chosen from the discrete action space) - :rtype: int - """ - action_dict = self._env.action_dict - r_obs = transform_change_obs_readable(obs) - _, o, _, *s = r_obs - - if len(r_obs) == 4: # only 1 service - s = [*s] - - number_of_nodes = len([i for i in o if i != "NONE"]) # number of nodes (not links) - for service_num, service_states in enumerate(s): - comprimised_states = [n for n, i in enumerate(service_states) if i == "COMPROMISED"] - if len(comprimised_states) == 0: - # No states are COMPROMISED, try the next service - continue - - compromised_node = np.random.choice(comprimised_states) + 1 # +1 as 0 would be any - action_decision = "DELETE" - action_permission = "ALLOW" - action_source_ip = compromised_node - # Randomly select a destination ID to block - action_destination_ip = np.random.choice(list(range(1, number_of_nodes + 1)) + ["ANY"]) - action_destination_ip = ( - int(action_destination_ip) if action_destination_ip != "ANY" else action_destination_ip - ) - action_protocol = service_num + 1 # +1 as 0 is any - # Randomly select a port to block - # Bad assumption that number of protocols equals number of ports - # AND no rules exist with an ANY port - action_port = np.random.choice(list(range(1, len(s) + 1))) - - action = [ - action_decision, - action_permission, - action_source_ip, - action_destination_ip, - action_protocol, - action_port, - ] - action = transform_action_acl_enum(action) - action = get_new_action(action, action_dict) - # We can only perform 1 action on each step - return action - - # If no good/useful action has been found, just perform a nothing action - nothing_action = ["NONE", "ALLOW", "ANY", "ANY", "ANY", "ANY"] - nothing_action = transform_action_acl_enum(nothing_action) - nothing_action = get_new_action(nothing_action, action_dict) - return nothing_action diff --git a/src/primaite/agents/hardcoded_node.py b/src/primaite/agents/hardcoded_node.py deleted file mode 100644 index b08d8967..00000000 --- a/src/primaite/agents/hardcoded_node.py +++ /dev/null @@ -1,125 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import numpy as np - -from primaite.agents.hardcoded_abc import HardCodedAgentSessionABC -from primaite.agents.utils import get_new_action, transform_action_node_enum, transform_change_obs_readable - - -class HardCodedNodeAgent(HardCodedAgentSessionABC): - """An Agent Session class that implements a deterministic Node agent.""" - - def _calculate_action(self, obs: np.ndarray) -> int: - """ - Calculate a good node-based action for the blue agent to take. - - :param obs: current observation from the gym environment - :type obs: np.ndarray - :return: Optimal action to take in the environment (chosen from the discrete action space) - :rtype: int - """ - action_dict = self._env.action_dict - r_obs = transform_change_obs_readable(obs) - _, o, os, *s = r_obs - - if len(r_obs) == 4: # only 1 service - s = [*s] - - # Check in order of most important states (order doesn't currently - # matter, but it probably should) - # First see if any OS states are compromised - for x, os_state in enumerate(os): - if os_state == "COMPROMISED": - action_node_id = x + 1 - action_node_property = "OS" - property_action = "PATCHING" - action_service_index = 0 # does nothing isn't relevant for os - action = [ - action_node_id, - action_node_property, - property_action, - action_service_index, - ] - action = transform_action_node_enum(action) - action = get_new_action(action, action_dict) - # We can only perform 1 action on each step - return action - - # Next, see if any Services are compromised - # We fix the compromised state before overwhelemd state, - # If a compromised entry node is fixed before the overwhelmed state is triggered, instruction is ignored - for service_num, service in enumerate(s): - for x, service_state in enumerate(service): - if service_state == "COMPROMISED": - action_node_id = x + 1 - action_node_property = "SERVICE" - property_action = "PATCHING" - action_service_index = service_num - - action = [ - action_node_id, - action_node_property, - property_action, - action_service_index, - ] - action = transform_action_node_enum(action) - action = get_new_action(action, action_dict) - # We can only perform 1 action on each step - return action - - # Next, See if any services are overwhelmed - # perhaps this should be fixed automatically when the compromised PCs issues are also resolved - # Currently there's no reason that an Overwhelmed state cannot be resolved before resolving the compromised PCs - - for service_num, service in enumerate(s): - for x, service_state in enumerate(service): - if service_state == "OVERWHELMED": - action_node_id = x + 1 - action_node_property = "SERVICE" - property_action = "PATCHING" - action_service_index = service_num - - action = [ - action_node_id, - action_node_property, - property_action, - action_service_index, - ] - action = transform_action_node_enum(action) - action = get_new_action(action, action_dict) - # We can only perform 1 action on each step - return action - - # Finally, turn on any off nodes - for x, operating_state in enumerate(o): - if os_state == "OFF": - action_node_id = x + 1 - action_node_property = "OPERATING" - property_action = "ON" # Why reset it when we can just turn it on - action_service_index = 0 # does nothing isn't relevant for operating state - action = [ - action_node_id, - action_node_property, - property_action, - action_service_index, - ] - # TODO: transform_action_node_enum takes only one argument, not sure why two are given here. - action = transform_action_node_enum(action, action_dict) - action = get_new_action(action, action_dict) - # We can only perform 1 action on each step - return action - - # If no good actions, just go with an action that wont do any harm - action_node_id = 1 - action_node_property = "NONE" - property_action = "ON" - action_service_index = 0 - action = [ - action_node_id, - action_node_property, - property_action, - action_service_index, - ] - action = transform_action_node_enum(action) - action = get_new_action(action, action_dict) - - return action diff --git a/src/primaite/agents/rllib.py b/src/primaite/agents/rllib.py deleted file mode 100644 index 96bb0737..00000000 --- a/src/primaite/agents/rllib.py +++ /dev/null @@ -1,287 +0,0 @@ -# # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# from __future__ import annotations - -# import json -# import shutil -# import zipfile -# from datetime import datetime -# from logging import Logger -# from pathlib import Path -# from typing import Any, Callable, Dict, Optional, Union -# from uuid import uuid4 - -# from primaite import getLogger -# from primaite.agents.agent_abc import AgentSessionABC -# from primaite.common.enums import AgentFramework, AgentIdentifier, SessionType -# from primaite.environment.primaite_env import Primaite - -# # from ray.rllib.algorithms import Algorithm -# # from ray.rllib.algorithms.a2c import A2CConfig -# # from ray.rllib.algorithms.ppo import PPOConfig -# # from ray.tune.logger import UnifiedLogger -# # from ray.tune.registry import register_env - - -# # from primaite.exceptions import RLlibAgentError - -# _LOGGER: Logger = getLogger(__name__) - - -# # TODO: verify type of env_config -# def _env_creator(env_config: Dict[str, Any]) -> Primaite: -# return Primaite( -# training_config_path=env_config["training_config_path"], -# lay_down_config_path=env_config["lay_down_config_path"], -# session_path=env_config["session_path"], -# timestamp_str=env_config["timestamp_str"], -# ) - -# # # TODO: verify type hint return type -# # def _custom_log_creator(session_path: Path) -> Callable[[Dict], UnifiedLogger]: -# # logdir = session_path / "ray_results" -# # logdir.mkdir(parents=True, exist_ok=True) - -# # def logger_creator(config: Dict) -> UnifiedLogger: -# # return UnifiedLogger(config, logdir, loggers=None) - -# return logger_creator - - -# # class RLlibAgent(AgentSessionABC): -# # """An AgentSession class that implements a Ray RLlib agent.""" - -# # def __init__( -# # self, -# # training_config_path: Optional[Union[str, Path]] = "", -# # lay_down_config_path: Optional[Union[str, Path]] = "", -# # session_path: Optional[Union[str, Path]] = None, -# # ) -> None: -# # """ -# # Initialise the RLLib Agent training session. - -# # :param training_config_path: YAML file containing configurable items defined in -# # `primaite.config.training_config.TrainingConfig` -# # :type training_config_path: Union[path, str] -# # :param lay_down_config_path: YAML file containing configurable items for generating network laydown. -# # :type lay_down_config_path: Union[path, str] -# # :raises ValueError: If the training config contains a bad value for agent_framework (should be "RLLIB") -# # :raises ValueError: If the training config contains a bad value for agent_identifies (should be `PPO` -# # or `A2C`) -# # """ -# # # TODO: implement RLlib agent loading -# # if session_path is not None: -# # msg = "RLlib agent loading has not been implemented yet" -# # _LOGGER.critical(msg) -# # raise NotImplementedError(msg) - -# # super().__init__(training_config_path, lay_down_config_path) -# # if self._training_config.session_type == SessionType.EVAL: -# # msg = "Cannot evaluate an RLlib agent that hasn't been through training yet." -# # _LOGGER.critical(msg) -# # raise RLlibAgentError(msg) -# # if not self._training_config.agent_framework == AgentFramework.RLLIB: -# # msg = f"Expected RLLIB agent_framework, " f"got {self._training_config.agent_framework}" -# # _LOGGER.error(msg) -# # raise ValueError(msg) -# # self._agent_config_class: Union[PPOConfig, A2CConfig] -# # if self._training_config.agent_identifier == AgentIdentifier.PPO: -# # self._agent_config_class = PPOConfig -# # elif self._training_config.agent_identifier == AgentIdentifier.A2C: -# # self._agent_config_class = A2CConfig -# # else: -# # msg = "Expected PPO or A2C agent_identifier, " f"got {self._training_config.agent_identifier.value}" -# # _LOGGER.error(msg) -# # raise ValueError(msg) -# # self._agent_config: Union[PPOConfig, A2CConfig] - -# # self._current_result: dict -# # self._setup() -# # _LOGGER.debug( -# # f"Created {self.__class__.__name__} using: " -# # f"agent_framework={self._training_config.agent_framework}, " -# # f"agent_identifier=" -# # f"{self._training_config.agent_identifier}, " -# # f"deep_learning_framework=" -# # f"{self._training_config.deep_learning_framework}" -# # ) -# # self._train_agent = None # Required to capture the learning agent to close after eval - -# # def _update_session_metadata_file(self) -> None: -# # """ -# # Update the ``session_metadata.json`` file. - -# # Updates the `session_metadata.json`` in the ``session_path`` directory -# # with the following key/value pairs: - -# # - end_datetime: The date & time the session ended in iso format. -# # - total_episodes: The total number of training episodes completed. -# # - total_time_steps: The total number of training time steps completed. -# # """ -# # with open(self.session_path / "session_metadata.json", "r") as file: -# # metadata_dict = json.load(file) - -# # metadata_dict["end_datetime"] = datetime.now().isoformat() -# # if not self.is_eval: -# # metadata_dict["learning"]["total_episodes"] = self._current_result["episodes_total"] # noqa -# # metadata_dict["learning"]["total_time_steps"] = self._current_result["timesteps_total"] # noqa -# # else: -# # metadata_dict["evaluation"]["total_episodes"] = self._current_result["episodes_total"] # noqa -# # metadata_dict["evaluation"]["total_time_steps"] = self._current_result["timesteps_total"] # noqa - -# # filepath = self.session_path / "session_metadata.json" -# # _LOGGER.debug(f"Updating Session Metadata file: {filepath}") -# # with open(filepath, "w") as file: -# # json.dump(metadata_dict, file) -# # _LOGGER.debug("Finished updating session metadata file") - -# # def _setup(self) -> None: -# # super()._setup() -# # register_env("primaite", _env_creator) -# # self._agent_config = self._agent_config_class() - -# # self._agent_config.environment( -# # env="primaite", -# # env_config=dict( -# # training_config_path=self._training_config_path, -# # lay_down_config_path=self._lay_down_config_path, -# # session_path=self.session_path, -# # timestamp_str=self.timestamp_str, -# # ), -# # ) -# # self._agent_config.seed = self._training_config.seed - -# # self._agent_config.training(train_batch_size=self._training_config.num_train_steps) -# # self._agent_config.framework(framework="tf") - -# # self._agent_config.rollouts( -# # num_rollout_workers=1, -# # num_envs_per_worker=1, -# # horizon=self._training_config.num_train_steps, -# # ) -# # self._agent: Algorithm = self._agent_config.build(logger_creator=_custom_log_creator(self.learning_path)) - -# # def _save_checkpoint(self) -> None: -# # checkpoint_n = self._training_config.checkpoint_every_n_episodes -# # episode_count = self._current_result["episodes_total"] -# # save_checkpoint = False -# # if checkpoint_n: -# # save_checkpoint = episode_count % checkpoint_n == 0 -# # if episode_count and save_checkpoint: -# # self._agent.save(str(self.checkpoints_path)) - -# # def learn( -# # self, -# # **kwargs: Any, -# # ) -> None: -# # """ -# # Evaluate the agent. - -# # :param kwargs: Any agent-specific key-word args to be passed. -# # """ -# # time_steps = self._training_config.num_train_steps -# # episodes = self._training_config.num_train_episodes - -# # _LOGGER.info(f"Beginning learning for {episodes} episodes @" f" {time_steps} time steps...") -# # for i in range(episodes): -# # self._current_result = self._agent.train() -# # self._save_checkpoint() -# # self.save() -# # super().learn() -# # # Done this way as the RLlib eval can only be performed if the session hasn't been stopped -# # if self._training_config.session_type is not SessionType.TRAIN: -# # self._train_agent = self._agent -# # else: -# # self._agent.stop() -# # self._plot_av_reward_per_episode(learning_session=True) - -# # def _unpack_saved_agent_into_eval(self) -> Path: -# # """Unpacks the pre-trained and saved RLlib agent so that it can be reloaded by Ray for eval.""" -# # agent_restore_path = self.evaluation_path / "agent_restore" -# # if agent_restore_path.exists(): -# # shutil.rmtree(agent_restore_path) -# # agent_restore_path.mkdir() -# # with zipfile.ZipFile(self._saved_agent_path, "r") as zip_file: -# # zip_file.extractall(agent_restore_path) -# # return agent_restore_path - -# # def _setup_eval(self): -# # self._can_learn = False -# # self._can_evaluate = True -# # self._agent.restore(str(self._unpack_saved_agent_into_eval())) - -# # def evaluate( -# # self, -# # **kwargs, -# # ): -# # """ -# # Evaluate the agent. - -# # :param kwargs: Any agent-specific key-word args to be passed. -# # """ -# # time_steps = self._training_config.num_eval_steps -# # episodes = self._training_config.num_eval_episodes - -# # self._setup_eval() - -# # self._env: Primaite = Primaite( -# # self._training_config_path, self._lay_down_config_path, self.session_path, self.timestamp_str -# # ) - -# # self._env.set_as_eval() -# # self.is_eval = True -# # if self._training_config.deterministic: -# # deterministic_str = "deterministic" -# # else: -# # deterministic_str = "non-deterministic" -# # _LOGGER.info( -# # f"Beginning {deterministic_str} evaluation for " f"{episodes} episodes @ {time_steps} time steps..." -# # ) -# # for episode in range(episodes): -# # obs = self._env.reset() -# # for step in range(time_steps): -# # action = self._agent.compute_single_action(observation=obs, explore=False) - -# # obs, rewards, done, info = self._env.step(action) - -# # self._env.reset() -# # self._env.close() -# # super().evaluate() -# # # Now we're safe to close the learning agent and write the mean rewards per episode for it -# # if self._training_config.session_type is not SessionType.TRAIN: -# # self._train_agent.stop() -# # self._plot_av_reward_per_episode(learning_session=True) -# # # Perform a clean-up of the unpacked agent -# # if (self.evaluation_path / "agent_restore").exists(): -# # shutil.rmtree((self.evaluation_path / "agent_restore")) - -# # def _get_latest_checkpoint(self) -> None: -# # raise NotImplementedError - -# # @classmethod -# # def load(cls, path: Union[str, Path]) -> RLlibAgent: -# # """Load an agent from file.""" -# # raise NotImplementedError - -# # def save(self, overwrite_existing: bool = True) -> None: -# # """Save the agent.""" -# # # Make temp dir to save in isolation -# # temp_dir = self.learning_path / str(uuid4()) -# # temp_dir.mkdir() - -# # # Save the agent to the temp dir -# # self._agent.save(str(temp_dir)) - -# # # Capture the saved Rllib checkpoint inside the temp directory -# # for file in temp_dir.iterdir(): -# # checkpoint_dir = file -# # break - -# # # Zip the folder -# # shutil.make_archive(str(self._saved_agent_path).replace(".zip", ""), "zip", checkpoint_dir) # noqa - -# # # Drop the temp directory -# # shutil.rmtree(temp_dir) - -# # def export(self) -> None: -# # """Export the agent to transportable file format.""" -# # raise NotImplementedError diff --git a/src/primaite/agents/sb3.py b/src/primaite/agents/sb3.py deleted file mode 100644 index 92c5ee5f..00000000 --- a/src/primaite/agents/sb3.py +++ /dev/null @@ -1,206 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -from __future__ import annotations - -import json -from logging import Logger -from pathlib import Path -from typing import Any, Optional, Union - -import numpy as np -from stable_baselines3 import A2C, PPO -from stable_baselines3.ppo import MlpPolicy as PPOMlp - -from primaite import getLogger -from primaite.agents.agent_abc import AgentSessionABC -from primaite.common.enums import AgentFramework, AgentIdentifier -from primaite.environment.primaite_env import Primaite - -_LOGGER: Logger = getLogger(__name__) - - -class SB3Agent(AgentSessionABC): - """An AgentSession class that implements a Stable Baselines3 agent.""" - - def __init__( - self, - training_config_path: Optional[Union[str, Path]] = None, - lay_down_config_path: Optional[Union[str, Path]] = None, - session_path: Optional[Union[str, Path]] = None, - legacy_training_config: bool = False, - legacy_lay_down_config: bool = False, - ) -> None: - """ - Initialise the SB3 Agent training session. - - :param training_config_path: YAML file containing configurable items defined in - `primaite.config.training_config.TrainingConfig` - :type training_config_path: Union[path, str] - :param lay_down_config_path: YAML file containing configurable items for generating network laydown. - :type lay_down_config_path: Union[path, str] - :param legacy_training_config: True if the training config file is a legacy file from PrimAITE < 2.0, - otherwise False. - :param legacy_lay_down_config: True if the lay_down config file is a legacy file from PrimAITE < 2.0, - otherwise False. - :raises ValueError: If the training config contains an unexpected value for agent_framework (should be "SB3") - :raises ValueError: If the training config contains an unexpected value for agent_identifies (should be `PPO` - or `A2C`) - """ - super().__init__( - training_config_path, lay_down_config_path, session_path, legacy_training_config, legacy_lay_down_config - ) - if not self._training_config.agent_framework == AgentFramework.SB3: - msg = f"Expected SB3 agent_framework, " f"got {self._training_config.agent_framework}" - _LOGGER.error(msg) - raise ValueError(msg) - self._agent_class: Union[PPO, A2C] - if self._training_config.agent_identifier == AgentIdentifier.PPO: - self._agent_class = PPO - elif self._training_config.agent_identifier == AgentIdentifier.A2C: - self._agent_class = A2C - else: - msg = "Expected PPO or A2C agent_identifier, " f"got {self._training_config.agent_identifier}" - _LOGGER.error(msg) - raise ValueError(msg) - - self._tensorboard_log_path = self.learning_path / "tensorboard_logs" - self._tensorboard_log_path.mkdir(parents=True, exist_ok=True) - - _LOGGER.debug( - f"Created {self.__class__.__name__} using: " - f"agent_framework={self._training_config.agent_framework}, " - f"agent_identifier=" - f"{self._training_config.agent_identifier}" - ) - - self.is_eval = False - - self._setup() - - def _setup(self) -> None: - """Set up the SB3 Agent.""" - self._env = Primaite( - training_config_path=self._training_config_path, - lay_down_config_path=self._lay_down_config_path, - session_path=self.session_path, - timestamp_str=self.timestamp_str, - legacy_training_config=self.legacy_training_config, - legacy_lay_down_config=self.legacy_lay_down_config, - ) - - # check if there is a zip file that needs to be loaded - load_file = next(self.session_path.rglob("*.zip"), None) - - if not load_file: - # create a new env and agent - - self._agent = self._agent_class( - PPOMlp, - self._env, - verbose=self.sb3_output_verbose_level, - n_steps=self._training_config.num_train_steps, - tensorboard_log=str(self._tensorboard_log_path), - seed=self._training_config.seed, - ) - else: - # set env values from session metadata - with open(self.session_path / "session_metadata.json", "r") as file: - md_dict = json.load(file) - - # load environment values - if self.is_eval: - # evaluation always starts at 0 - self._env.episode_count = 0 - self._env.total_step_count = 0 - else: - # carry on from previous learning sessions - self._env.episode_count = md_dict["learning"]["total_episodes"] - self._env.total_step_count = md_dict["learning"]["total_time_steps"] - - # load the file - self._agent = self._agent_class.load(load_file, env=self._env) - - # set agent values - self._agent.verbose = self.sb3_output_verbose_level - self._agent.tensorboard_log = self.session_path / "learning/tensorboard_logs" - - super()._setup() - - def _save_checkpoint(self) -> None: - checkpoint_n = self._training_config.checkpoint_every_n_episodes - episode_count = self._env.episode_count - save_checkpoint = False - if checkpoint_n: - save_checkpoint = episode_count % checkpoint_n == 0 - if episode_count and save_checkpoint: - checkpoint_path = self.checkpoints_path / f"sb3ppo_{episode_count}.zip" - self._agent.save(checkpoint_path) - _LOGGER.debug(f"Saved agent checkpoint: {checkpoint_path}") - - def _get_latest_checkpoint(self) -> None: - pass - - def learn( - self, - **kwargs: Any, - ) -> None: - """ - Train the agent. - - :param kwargs: Any agent-specific key-word args to be passed. - """ - time_steps = self._training_config.num_train_steps - episodes = self._training_config.num_train_episodes - self.is_eval = False - _LOGGER.info(f"Beginning learning for {episodes} episodes @" f" {time_steps} time steps...") - for i in range(episodes): - self._agent.learn(total_timesteps=time_steps) - self._save_checkpoint() - self._env._write_av_reward_per_episode() # noqa - self.save() - self._env.close() - super().learn() - - # save agent - self.save() - - self._plot_av_reward_per_episode(learning_session=True) - - def evaluate( - self, - **kwargs: Any, - ) -> None: - """ - Evaluate the agent. - - :param kwargs: Any agent-specific key-word args to be passed. - """ - time_steps = self._training_config.num_eval_steps - episodes = self._training_config.num_eval_episodes - self._env.set_as_eval() - self.is_eval = True - if self._training_config.deterministic: - deterministic_str = "deterministic" - else: - deterministic_str = "non-deterministic" - _LOGGER.info( - f"Beginning {deterministic_str} evaluation for " f"{episodes} episodes @ {time_steps} time steps..." - ) - for episode in range(episodes): - obs = self._env.reset() - - for step in range(time_steps): - action, _states = self._agent.predict(obs, deterministic=self._training_config.deterministic) - if isinstance(action, np.ndarray): - action = np.int64(action) - obs, rewards, done, info = self._env.step(action) - self._env._write_av_reward_per_episode() # noqa - self._env.close() - super().evaluate() - - def save(self) -> None: - """Save the agent.""" - self._agent.save(self._saved_agent_path) - - def export(self) -> None: - """Export the agent to transportable file format.""" - raise NotImplementedError diff --git a/src/primaite/agents/simple.py b/src/primaite/agents/simple.py deleted file mode 100644 index bfdff869..00000000 --- a/src/primaite/agents/simple.py +++ /dev/null @@ -1,59 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -import numpy as np - -from primaite.agents.hardcoded_abc import HardCodedAgentSessionABC -from primaite.agents.utils import get_new_action, transform_action_acl_enum, transform_action_node_enum - - -class RandomAgent(HardCodedAgentSessionABC): - """ - A Random Agent. - - Get a completely random action from the action space. - """ - - def _calculate_action(self, obs: np.ndarray) -> int: - return self._env.action_space.sample() - - -class DummyAgent(HardCodedAgentSessionABC): - """ - A Dummy Agent. - - All action spaces setup so dummy action is always 0 regardless of action type used. - """ - - def _calculate_action(self, obs: np.ndarray) -> int: - return 0 - - -class DoNothingACLAgent(HardCodedAgentSessionABC): - """ - A do nothing ACL agent. - - A valid ACL action that has no effect; does nothing. - """ - - def _calculate_action(self, obs: np.ndarray) -> int: - nothing_action = ["NONE", "ALLOW", "ANY", "ANY", "ANY", "ANY"] - nothing_action = transform_action_acl_enum(nothing_action) - nothing_action = get_new_action(nothing_action, self._env.action_dict) - - return nothing_action - - -class DoNothingNodeAgent(HardCodedAgentSessionABC): - """ - A do nothing Node agent. - - A valid Node action that has no effect; does nothing. - """ - - def _calculate_action(self, obs: np.ndarray) -> int: - nothing_action = [1, "NONE", "ON", 0] - nothing_action = transform_action_node_enum(nothing_action) - nothing_action = get_new_action(nothing_action, self._env.action_dict) - # nothing_action should currently always be 0 - - return nothing_action diff --git a/src/primaite/agents/utils.py b/src/primaite/agents/utils.py deleted file mode 100644 index 08d46294..00000000 --- a/src/primaite/agents/utils.py +++ /dev/null @@ -1,450 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -from typing import Dict, List, Union - -import numpy as np - -from primaite.common.custom_typing import NodeUnion -from primaite.common.enums import ( - HardwareState, - LinkStatus, - NodeHardwareAction, - NodePOLType, - NodeSoftwareAction, - SoftwareState, -) - - -def transform_action_node_readable(action: List[int]) -> List[Union[int, str]]: - """Convert a node action from enumerated format to readable format. - - example: - [1, 3, 1, 0] -> [1, 'SERVICE', 'PATCHING', 0] - - :param action: Agent action, formatted as a list of ints, for more information check out - `primaite.environment.primaite_env.Primaite` - :type action: List[int] - :return: The same action list, but with the encodings translated back into meaningful labels - :rtype: List[Union[int,str]] - """ - action_node_property = NodePOLType(action[1]).name - - if action_node_property == "OPERATING": - property_action = NodeHardwareAction(action[2]).name - elif (action_node_property == "OS" or action_node_property == "SERVICE") and action[2] <= 1: - property_action = NodeSoftwareAction(action[2]).name - else: - property_action = "NONE" - - new_action: list[Union[int, str]] = [action[0], action_node_property, property_action, action[3]] - return new_action - - -def transform_action_acl_readable(action: List[int]) -> List[Union[str, int]]: - """ - Transform an ACL action to a more readable format. - - example: - [0, 1, 2, 5, 0, 1] -> ['NONE', 'ALLOW', 2, 5, 'ANY', 1] - - :param action: Agent action, formatted as a list of ints, for more information check out - `primaite.environment.primaite_env.Primaite` - :type action: List[int] - :return: The same action list, but with the encodings translated back into meaningful labels - :rtype: List[Union[int,str]] - """ - action_decisions = {0: "NONE", 1: "CREATE", 2: "DELETE"} - action_permissions = {0: "DENY", 1: "ALLOW"} - - action_decision = action_decisions[action[0]] - action_permission = action_permissions[action[1]] - - # For IPs, Ports and Protocols, 0 means any, otherwise its just an index - new_action = [action_decision, action_permission] + list(action[2:6]) - for n, val in enumerate(list(action[2:6])): - if val == 0: - new_action[n + 2] = "ANY" - - return new_action - - -def is_valid_node_action(action: List[int]) -> bool: - """ - Is the node action an actual valid action. - - Only uses information about the action to determine if the action has an effect - - Does NOT consider: - - Node ID not valid to perform an operation - e.g. selected node has no service so cannot patch - - Node already being in that state (turning an ON node ON) - - :param action: Agent action, formatted as a list of ints, for more information check out - `primaite.environment.primaite_env.Primaite` - :type action: List[int] - :return: Whether the action is valid - :rtype: bool - """ - action_r = transform_action_node_readable(action) - - node_property = action_r[1] - node_action = action_r[2] - - # print("node property", node_property, "\nnode action", node_action) - - if node_property == "NONE": - return False - if node_action == "NONE": - return False - if node_property == "OPERATING" and node_action == "PATCHING": - # Operating State cannot PATCH - return False - if node_property != "OPERATING" and node_action not in [ - "NONE", - "PATCHING", - ]: - # Software States can only do Nothing or Patch - return False - return True - - -def is_valid_acl_action(action: List[int]) -> bool: - """ - Is the ACL action an actual valid action. - - Only uses information about the action to determine if the action has an effect. - - Does NOT consider: - - Trying to create identical rules - - Trying to create a rule which is a subset of another rule (caused by "ANY") - - :param action: Agent action, formatted as a list of ints, for more information check out - `primaite.environment.primaite_env.Primaite` - :type action: List[int] - :return: Whether the action is valid - :rtype: bool - """ - action_r = transform_action_acl_readable(action) - - action_decision = action_r[0] - action_permission = action_r[1] - action_source_id = action_r[2] - action_destination_id = action_r[3] - - if action_decision == "NONE": - return False - if action_source_id == action_destination_id and action_source_id != "ANY" and action_destination_id != "ANY": - # ACL rule towards itself - return False - if action_permission == "DENY": - # DENY is unnecessary, we can create and delete allow rules instead - # No allow rule = blocked/DENY by feault. ALLOW overrides existing DENY. - return False - - return True - - -def is_valid_acl_action_extra(action: List[int]) -> bool: - """ - Harsher version of valid acl actions, does not allow action. - - :param action: Agent action, formatted as a list of ints, for more information check out - `primaite.environment.primaite_env.Primaite` - :type action: List[int] - :return: Whether the action is valid - :rtype: bool - """ - if is_valid_acl_action(action) is False: - return False - - action_r = transform_action_acl_readable(action) - action_protocol = action_r[4] - action_port = action_r[5] - - # Don't allow protocols or ports to be ANY - # in the future we might want to do the opposite, and only have ANY option for ports and service - if action_protocol == "ANY": - return False - if action_port == "ANY": - return False - - return True - - -def transform_change_obs_readable(obs: np.ndarray) -> List[List[Union[str, int]]]: - """Transform list of transactions to readable list of each observation property. - - example: - np.array([[1,2,1,3],[2,1,1,1]]) -> [[1, 2], ['OFF', 'ON'], ['GOOD', 'GOOD'], ['COMPROMISED', 'GOOD']] - - :param obs: Raw observation from the environment. - :type obs: np.ndarray - :return: The same observation, but the encoded integer values are replaced with readable names. - :rtype: List[List[Union[str, int]]] - """ - ids = [i for i in obs[:, 0]] - operating_states = [HardwareState(i).name for i in obs[:, 1]] - os_states = [SoftwareState(i).name for i in obs[:, 2]] - new_obs = [ids, operating_states, os_states] - - for service in range(4, obs.shape[1]): - # Links bit/s don't have a service state - service_states = [SoftwareState(i).name if i <= 4 else i for i in obs[:, service]] - new_obs.append(service_states) - - return new_obs - - -def transform_obs_readable(obs: np.ndarray) -> List[List[Union[str, int]]]: - """Transform observation to readable format. - - example - np.array([[1,2,1,3],[2,1,1,1]]) -> [[1, 'OFF', 'GOOD', 'COMPROMISED'], [2, 'ON', 'GOOD', 'GOOD']] - - :param obs: Raw observation from the environment. - :type obs: np.ndarray - :return: The same observation, but the encoded integer values are replaced with readable names. - :rtype: List[List[Union[str, int]]] - """ - changed_obs = transform_change_obs_readable(obs) - new_obs = list(zip(*changed_obs)) - # Convert list of tuples to list of lists - new_obs = [list(i) for i in new_obs] - - return new_obs - - -def convert_to_new_obs(obs: np.ndarray, num_nodes: int = 10) -> np.ndarray: - """Convert original gym Box observation space to new multiDiscrete observation space. - - :param obs: observation in the 'old' (NodeLinkTable) format - :type obs: np.ndarray - :param num_nodes: number of nodes in the network, defaults to 10 - :type num_nodes: int, optional - :return: reformatted observation - :rtype: np.ndarray - """ - # Remove ID columns, remove links and flatten to MultiDiscrete observation space - new_obs = obs[:num_nodes, 1:].flatten() - return new_obs - - -def convert_to_old_obs(obs: np.ndarray, num_nodes: int = 10, num_links: int = 10, num_services: int = 1) -> np.ndarray: - """Convert to old observation. - - Links filled with 0's as no information is included in new observation space. - - example: - obs = array([1, 1, 1, 1, 1, 1, 1, 1, 1, ..., 1, 1, 1]) - - new_obs = array([[ 1, 1, 1, 1], - [ 2, 1, 1, 1], - [ 3, 1, 1, 1], - ... - [20, 0, 0, 0]]) - - :param obs: observation in the 'new' (MultiDiscrete) format - :type obs: np.ndarray - :param num_nodes: number of nodes in the network, defaults to 10 - :type num_nodes: int, optional - :param num_links: number of links in the network, defaults to 10 - :type num_links: int, optional - :param num_services: number of services on the network, defaults to 1 - :type num_services: int, optional - :return: 2-d BOX observation space, in the same format as NodeLinkTable - :rtype: np.ndarray - """ - # Convert back to more readable, original format - reshaped_nodes = obs[:-num_links].reshape(num_nodes, num_services + 2) - - # Add empty links back and add node ID back - s = np.zeros( - [reshaped_nodes.shape[0] + num_links, reshaped_nodes.shape[1] + 1], - dtype=np.int64, - ) - s[:, 0] = range(1, num_nodes + num_links + 1) # Adding ID back - s[:num_nodes, 1:] = reshaped_nodes # put values back in - new_obs = s - - # Add links back in - links = obs[-num_links:] - # Links will be added to the last protocol/service slot but they are not specific to that service - new_obs[num_nodes:, -1] = links - - return new_obs - - -def describe_obs_change( - obs1: np.ndarray, obs2: np.ndarray, num_nodes: int = 10, num_links: int = 10, num_services: int = 1 -) -> str: - """Build a string describing the difference between two observations. - - example: - obs_1 = array([[1, 1, 1, 1, 3], [2, 1, 1, 1, 1]]) - obs_2 = array([[1, 1, 1, 1, 1], [2, 1, 1, 1, 1]]) - output = 'ID 1: SERVICE 2 set to GOOD' - - :param obs1: First observation - :type obs1: np.ndarray - :param obs2: Second observation - :type obs2: np.ndarray - :param num_nodes: How many nodes are in the network laydown, defaults to 10 - :type num_nodes: int, optional - :param num_links: How many links are in the network laydown, defaults to 10 - :type num_links: int, optional - :param num_services: How many services are configured for this scenario, defaults to 1 - :type num_services: int, optional - :return: A multi-line string with a human-readable description of the difference. - :rtype: str - """ - obs1 = convert_to_old_obs(obs1, num_nodes, num_links, num_services) - obs2 = convert_to_old_obs(obs2, num_nodes, num_links, num_services) - list_of_changes = [] - for n, row in enumerate(obs1 - obs2): - if row.any() != 0: - relevant_changes = np.where(row != 0, obs2[n], -1) - relevant_changes[0] = obs2[n, 0] # ID is always relevant - is_link = relevant_changes[0] > num_nodes - desc = _describe_obs_change_helper(relevant_changes, is_link) - list_of_changes.append(desc) - - change_string = "\n ".join(list_of_changes) - if len(list_of_changes) > 0: - change_string = "\n " + change_string - return change_string - - -def _describe_obs_change_helper(obs_change: List[int], is_link: bool) -> str: - """ - Helper funcion to describe what has changed. - - example: - [ 1 -1 -1 -1 1] -> "ID 1: Service 1 changed to GOOD" - - Handles multiple changes e.g. 'ID 1: SERVICE 1 changed to PATCHING. SERVICE 2 set to GOOD.' - - :param obs_change: List of integers generated within the `describe_obs_change` function. It should correspond to one - row of the observation table, and have `-1` at locations where the observation hasn't changed, and the new - status where it has changed. - :type obs_change: List[int] - :param is_link: Whether the row of the observation space corresponds to a link. False means it represents a node. - :type is_link: bool - :return: A human-readable description of the difference between the two observation rows. - :rtype: str - """ - # Indexes where a change has occured, not including 0th index - index_changed = [i for i in range(1, len(obs_change)) if obs_change[i] != -1] - # Node pol types, Indexes >= 3 are service nodes - NodePOLTypes = [NodePOLType(i).name if i < 3 else NodePOLType(3).name + " " + str(i - 3) for i in index_changed] - # Account for hardware states, software sattes and links - states = [ - LinkStatus(obs_change[i]).name - if is_link - else HardwareState(obs_change[i]).name - if i == 1 - else SoftwareState(obs_change[i]).name - for i in index_changed - ] - - if not is_link: - desc = f"ID {obs_change[0]}:" - for node_pol_type, state in list(zip(NodePOLTypes, states)): - desc = desc + " " + node_pol_type + " changed to " + state + "." - else: - desc = f"ID {obs_change[0]}: Link traffic changed to {states[0]}." - - return desc - - -def transform_action_node_enum(action: List[Union[str, int]]) -> List[int]: - """Convert a node action from readable string format, to enumerated format. - - example: - [1, 'SERVICE', 'PATCHING', 0] -> [1, 3, 1, 0] - :param action: Action in 'readable' format - :type action: List[Union[str,int]] - :return: Action with verbs encoded as ints - :rtype: List[int] - """ - action_node_id = action[0] - action_node_property = NodePOLType[action[1]].value - - if action[1] == "OPERATING": - property_action = NodeHardwareAction[action[2]].value - elif action[1] == "OS" or action[1] == "SERVICE": - property_action = NodeSoftwareAction[action[2]].value - else: - property_action = 0 - - action_service_index = action[3] - - new_action = [ - action_node_id, - action_node_property, - property_action, - action_service_index, - ] - - return new_action - - -def transform_action_acl_enum(action: List[Union[int, str]]) -> np.ndarray: - """ - Convert acl action from readable str format, to enumerated format. - - :param action: ACL-based action expressed as a list of human-readable ints and strings - :type action: List[Union[int,str]] - :return: The same action but encoded to contain only integers. - :rtype: np.ndarray - """ - action_decisions = {"NONE": 0, "CREATE": 1, "DELETE": 2} - action_permissions = {"DENY": 0, "ALLOW": 1} - - action_decision = action_decisions[action[0]] - action_permission = action_permissions[action[1]] - - # For IPs, Ports and Protocols, ANY has value 0, otherwise its just an index - new_action = [action_decision, action_permission] + list(action[2:6]) - for n, val in enumerate(list(action[2:6])): - if val == "ANY": - new_action[n + 2] = 0 - - new_action = np.array(new_action) - return new_action - - -def get_node_of_ip(ip: str, node_dict: Dict[str, NodeUnion]) -> str: - """Get the node ID of an IP address. - - node_dict: dictionary of nodes where key is ID, and value is the node (can be ontained from env.nodes) - - :param ip: The IP address of the node whose ID is required - :type ip: str - :param node_dict: The environment's node registry dictionary - :type node_dict: Dict[str,NodeUnion] - :return: The key from the registry dict that corresponds to the node with the IP adress provided by `ip` - :rtype: str - """ - for node_key, node_value in node_dict.items(): - node_ip = node_value.ip_address - if node_ip == ip: - return node_key - - -def get_new_action(old_action: np.ndarray, action_dict: Dict[int, List]) -> int: - """ - Get new action (e.g. 32) from old action e.g. [1,1,1,0]. - - Old_action can be either node or acl action type - - :param old_action: Action expressed as a list of choices, eg. [1,1,1,0] - :type old_action: np.ndarray - :param action_dict: Dictionary for translating the multidiscrete actions into the list-based actions. - :type action_dict: Dict[int,List] - :return: Action key correspoinding to the input `old_action` - :rtype: int - """ - for key, val in action_dict.items(): - if list(val) == list(old_action): - return key - # Not all possible actions are included in dict, only valid action are - # if action is not in the dict, its an invalid action so return 0 - return 0 diff --git a/src/primaite/common/__init__.py b/src/primaite/common/__init__.py deleted file mode 100644 index 5770bcbc..00000000 --- a/src/primaite/common/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Objects which are shared between many PrimAITE modules.""" diff --git a/src/primaite/common/custom_typing.py b/src/primaite/common/custom_typing.py deleted file mode 100644 index 4130e71a..00000000 --- a/src/primaite/common/custom_typing.py +++ /dev/null @@ -1,8 +0,0 @@ -from typing import Union - -from primaite.nodes.active_node import ActiveNode -from primaite.nodes.passive_node import PassiveNode -from primaite.nodes.service_node import ServiceNode - -NodeUnion = Union[ActiveNode, PassiveNode, ServiceNode] -"""A Union of ActiveNode, PassiveNode, and ServiceNode.""" diff --git a/src/primaite/common/enums.py b/src/primaite/common/enums.py deleted file mode 100644 index c33e764b..00000000 --- a/src/primaite/common/enums.py +++ /dev/null @@ -1,208 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Enumerations for APE.""" - -from enum import Enum, IntEnum - - -class NodeType(Enum): - """Node type enumeration.""" - - CCTV = 1 - SWITCH = 2 - COMPUTER = 3 - LINK = 4 - MONITOR = 5 - PRINTER = 6 - LOP = 7 - RTU = 8 - ACTUATOR = 9 - SERVER = 10 - - -class Priority(Enum): - """Node priority enumeration.""" - - P1 = 1 - P2 = 2 - P3 = 3 - P4 = 4 - P5 = 5 - - -class HardwareState(Enum): - """Node hardware state enumeration.""" - - NONE = 0 - ON = 1 - OFF = 2 - RESETTING = 3 - SHUTTING_DOWN = 4 - BOOTING = 5 - - -class SoftwareState(Enum): - """Software or Service state enumeration.""" - - NONE = 0 - GOOD = 1 - PATCHING = 2 - COMPROMISED = 3 - OVERWHELMED = 4 - - -class NodePOLType(Enum): - """Node Pattern of Life type enumeration.""" - - NONE = 0 - OPERATING = 1 - OS = 2 - SERVICE = 3 - FILE = 4 - - -class NodePOLInitiator(Enum): - """Node Pattern of Life initiator enumeration.""" - - DIRECT = 1 - IER = 2 - SERVICE = 3 - - -class Protocol(Enum): - """Service protocol enumeration.""" - - LDAP = 0 - FTP = 1 - HTTPS = 2 - SMTP = 3 - RTP = 4 - IPP = 5 - TCP = 6 - NONE = 7 - - -class SessionType(Enum): - """The type of PrimAITE Session to be run.""" - - TRAIN = 1 - "Train an agent" - EVAL = 2 - "Evaluate an agent" - TRAIN_EVAL = 3 - "Train then evaluate an agent" - - -class AgentFramework(Enum): - """The agent algorithm framework/package.""" - - CUSTOM = 0 - "Custom Agent" - SB3 = 1 - "Stable Baselines3" - # RLLIB = 2 - # "Ray RLlib" - - -class DeepLearningFramework(Enum): - """The deep learning framework.""" - - TF = "tf" - "Tensorflow" - TF2 = "tf2" - "Tensorflow 2.x" - TORCH = "torch" - "PyTorch" - - -class AgentIdentifier(Enum): - """The Red Agent algo/class.""" - - A2C = 1 - "Advantage Actor Critic" - PPO = 2 - "Proximal Policy Optimization" - HARDCODED = 3 - "The Hardcoded agents" - DO_NOTHING = 4 - "The DoNothing agents" - RANDOM = 5 - "The RandomAgent" - DUMMY = 6 - "The DummyAgent" - - -class HardCodedAgentView(Enum): - """The view the deterministic hard-coded agent has of the environment.""" - - BASIC = 1 - "The current observation space only" - FULL = 2 - "Full environment view with actions taken and reward feedback" - - -class ActionType(Enum): - """Action type enumeration.""" - - NODE = 0 - ACL = 1 - ANY = 2 - - -# TODO: this is not used anymore, write a ticket to delete it. -class ObservationType(Enum): - """Observation type enumeration.""" - - BOX = 0 - MULTIDISCRETE = 1 - - -class FileSystemState(Enum): - """File System State.""" - - GOOD = 1 - CORRUPT = 2 - DESTROYED = 3 - REPAIRING = 4 - RESTORING = 5 - - -class NodeHardwareAction(Enum): - """Node hardware action.""" - - NONE = 0 - ON = 1 - OFF = 2 - RESET = 3 - - -class NodeSoftwareAction(Enum): - """Node software action.""" - - NONE = 0 - PATCHING = 1 - - -class LinkStatus(Enum): - """Link traffic status.""" - - NONE = 0 - LOW = 1 - MEDIUM = 2 - HIGH = 3 - OVERLOAD = 4 - - -class SB3OutputVerboseLevel(IntEnum): - """The Stable Baselines3 learn/eval output verbosity level.""" - - NONE = 0 - INFO = 1 - DEBUG = 2 - - -class RulePermissionType(Enum): - """Any firewall rule type.""" - - NONE = 0 - DENY = 1 - ALLOW = 2 diff --git a/src/primaite/common/protocol.py b/src/primaite/common/protocol.py deleted file mode 100644 index 6940ba3f..00000000 --- a/src/primaite/common/protocol.py +++ /dev/null @@ -1,47 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""The protocol class.""" - - -class Protocol(object): - """Protocol class.""" - - def __init__(self, _name: str) -> None: - """ - Initialise a protocol. - - :param _name: The name of the protocol - :type _name: str - """ - self.name: str = _name - self.load: int = 0 # bps - - def get_name(self) -> str: - """ - Gets the protocol name. - - Returns: - The protocol name - """ - return self.name - - def get_load(self) -> int: - """ - Gets the protocol load. - - Returns: - The protocol load (bps) - """ - return self.load - - def add_load(self, _load: int) -> None: - """ - Adds load to the protocol. - - Args: - _load: The load to add - """ - self.load += _load - - def clear_load(self) -> None: - """Clears the load on this protocol.""" - self.load = 0 diff --git a/src/primaite/common/service.py b/src/primaite/common/service.py deleted file mode 100644 index 956815e8..00000000 --- a/src/primaite/common/service.py +++ /dev/null @@ -1,28 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""The Service class.""" - -from primaite.common.enums import SoftwareState - - -class Service(object): - """Service class.""" - - def __init__(self, name: str, port: str, software_state: SoftwareState) -> None: - """ - Initialise a service. - - :param name: The service name. - :param port: The service port. - :param software_state: The service SoftwareState. - """ - self.name: str = name - self.port: str = port - self.software_state: SoftwareState = software_state - self.patching_count: int = 0 - - def reduce_patching_count(self) -> None: - """Reduces the patching count for the service.""" - self.patching_count -= 1 - if self.patching_count <= 0: - self.patching_count = 0 - self.software_state = SoftwareState.GOOD diff --git a/src/primaite/config/__init__.py b/src/primaite/config/__init__.py deleted file mode 100644 index 92f5a7d2..00000000 --- a/src/primaite/config/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Configuration parameters for running experiments.""" diff --git a/src/primaite/config/_package_data/lay_down/lay_down_config_1_DDOS_basic.yaml b/src/primaite/config/_package_data/lay_down/lay_down_config_1_DDOS_basic.yaml deleted file mode 100644 index dad0ff4b..00000000 --- a/src/primaite/config/_package_data/lay_down/lay_down_config_1_DDOS_basic.yaml +++ /dev/null @@ -1,166 +0,0 @@ -- item_type: PORTS - ports_list: - - port: '80' -- item_type: SERVICES - service_list: - - name: TCP -- item_type: NODE - node_id: '1' - name: PC1 - node_class: SERVICE - node_type: COMPUTER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.2 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '2' - name: SERVER - node_class: SERVICE - node_type: SERVER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.3 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '3' - name: PC2 - node_class: SERVICE - node_type: COMPUTER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.4 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '4' - name: SWITCH1 - node_class: ACTIVE - node_type: SWITCH - priority: P2 - hardware_state: 'ON' - ip_address: 192.168.1.5 - software_state: GOOD - file_system_state: GOOD -- item_type: NODE - node_id: '5' - name: SWITCH2 - node_class: ACTIVE - node_type: SWITCH - priority: P2 - hardware_state: 'ON' - ip_address: 192.168.1.6 - software_state: GOOD - file_system_state: GOOD -- item_type: NODE - node_id: '6' - name: SWITCH3 - node_class: ACTIVE - node_type: SWITCH - priority: P2 - hardware_state: 'ON' - ip_address: 192.168.1.7 - software_state: GOOD - file_system_state: GOOD -- item_type: LINK - id: '7' - name: link1 - bandwidth: 1000000000 - source: '1' - destination: '4' -- item_type: LINK - id: '8' - name: link2 - bandwidth: 1000000000 - source: '4' - destination: '2' -- item_type: LINK - id: '9' - name: link3 - bandwidth: 1000000000 - source: '2' - destination: '5' -- item_type: LINK - id: '10' - name: link4 - bandwidth: 1000000000 - source: '2' - destination: '6' -- item_type: LINK - id: '11' - name: link5 - bandwidth: 1000000000 - source: '5' - destination: '3' -- item_type: LINK - id: '12' - name: link6 - bandwidth: 1000000000 - source: '6' - destination: '3' -- item_type: GREEN_IER - id: '13' - start_step: 1 - end_step: 128 - load: 100000 - protocol: TCP - port: '80' - source: '3' - destination: '2' - mission_criticality: 5 -- item_type: RED_POL - id: '14' - start_step: 50 - end_step: 50 - targetNodeId: '1' - initiator: DIRECT - type: SERVICE - protocol: TCP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_IER - id: '15' - start_step: 60 - end_step: 100 - load: 1000000 - protocol: TCP - port: '80' - source: '1' - destination: '2' - mission_criticality: 0 -- item_type: RED_POL - id: '16' - start_step: 80 - end_step: 80 - targetNodeId: '2' - initiator: IER - type: SERVICE - protocol: TCP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: ACL_RULE - id: '17' - permission: ALLOW - source: ANY - destination: ANY - protocol: ANY - port: ANY - position: 0 diff --git a/src/primaite/config/_package_data/lay_down/lay_down_config_2_DDOS_basic.yaml b/src/primaite/config/_package_data/lay_down/lay_down_config_2_DDOS_basic.yaml deleted file mode 100644 index e91859d2..00000000 --- a/src/primaite/config/_package_data/lay_down/lay_down_config_2_DDOS_basic.yaml +++ /dev/null @@ -1,366 +0,0 @@ -- item_type: PORTS - ports_list: - - port: '80' -- item_type: SERVICES - service_list: - - name: TCP -- item_type: NODE - node_id: '1' - name: PC1 - node_class: SERVICE - node_type: COMPUTER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.10.11 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '2' - name: PC2 - node_class: SERVICE - node_type: COMPUTER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.10.12 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '3' - name: PC3 - node_class: SERVICE - node_type: COMPUTER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.10.13 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '4' - name: PC4 - node_class: SERVICE - node_type: COMPUTER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.20.14 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '5' - name: SWITCH1 - node_class: ACTIVE - node_type: SWITCH - priority: P2 - hardware_state: 'ON' - ip_address: 192.168.1.2 - software_state: GOOD - file_system_state: GOOD -- item_type: NODE - node_id: '6' - name: IDS - node_class: SERVICE - node_type: SERVER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.4 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '7' - name: SWITCH2 - node_class: ACTIVE - node_type: SWITCH - priority: P2 - hardware_state: 'ON' - ip_address: 192.168.1.3 - software_state: GOOD - file_system_state: GOOD -- item_type: NODE - node_id: '8' - name: LOP1 - node_class: SERVICE - node_type: LOP - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.12 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '9' - name: SERVER1 - node_class: SERVICE - node_type: SERVER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.10.14 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '10' - name: SERVER2 - node_class: SERVICE - node_type: SERVER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.20.15 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: LINK - id: '11' - name: link1 - bandwidth: 1000000000 - source: '1' - destination: '5' -- item_type: LINK - id: '12' - name: link2 - bandwidth: 1000000000 - source: '2' - destination: '5' -- item_type: LINK - id: '13' - name: link3 - bandwidth: 1000000000 - source: '3' - destination: '5' -- item_type: LINK - id: '14' - name: link4 - bandwidth: 1000000000 - source: '4' - destination: '5' -- item_type: LINK - id: '15' - name: link5 - bandwidth: 1000000000 - source: '5' - destination: '6' -- item_type: LINK - id: '16' - name: link6 - bandwidth: 1000000000 - source: '5' - destination: '8' -- item_type: LINK - id: '17' - name: link7 - bandwidth: 1000000000 - source: '6' - destination: '7' -- item_type: LINK - id: '18' - name: link8 - bandwidth: 1000000000 - source: '8' - destination: '7' -- item_type: LINK - id: '19' - name: link9 - bandwidth: 1000000000 - source: '7' - destination: '9' -- item_type: LINK - id: '20' - name: link10 - bandwidth: 1000000000 - source: '7' - destination: '10' -- item_type: GREEN_IER - id: '21' - start_step: 1 - end_step: 128 - load: 100000 - protocol: TCP - port: '80' - source: '1' - destination: '9' - mission_criticality: 2 -- item_type: GREEN_IER - id: '22' - start_step: 1 - end_step: 128 - load: 100000 - protocol: TCP - port: '80' - source: '2' - destination: '9' - mission_criticality: 2 -- item_type: GREEN_IER - id: '23' - start_step: 1 - end_step: 128 - load: 100000 - protocol: TCP - port: '80' - source: '9' - destination: '3' - mission_criticality: 5 -- item_type: GREEN_IER - id: '24' - start_step: 1 - end_step: 128 - load: 100000 - protocol: TCP - port: '80' - source: '4' - destination: '10' - mission_criticality: 2 -- item_type: ACL_RULE - id: '25' - permission: ALLOW - source: 192.168.10.11 - destination: 192.168.10.14 - protocol: TCP - port: 80 - position: 0 -- item_type: ACL_RULE - id: '26' - permission: ALLOW - source: 192.168.10.12 - destination: 192.168.10.14 - protocol: TCP - port: 80 - position: 1 -- item_type: ACL_RULE - id: '27' - permission: ALLOW - source: 192.168.10.13 - destination: 192.168.10.14 - protocol: TCP - port: 80 - position: 2 -- item_type: ACL_RULE - id: '28' - permission: ALLOW - source: 192.168.20.14 - destination: 192.168.20.15 - protocol: TCP - port: 80 - position: 3 -- item_type: ACL_RULE - id: '29' - permission: ALLOW - source: 192.168.10.14 - destination: 192.168.10.13 - protocol: TCP - port: 80 - position: 4 -- item_type: ACL_RULE - id: '30' - permission: DENY - source: 192.168.10.11 - destination: 192.168.20.15 - protocol: TCP - port: 80 - position: 5 -- item_type: ACL_RULE - id: '31' - permission: DENY - source: 192.168.10.12 - destination: 192.168.20.15 - protocol: TCP - port: 80 - position: 6 -- item_type: ACL_RULE - id: '32' - permission: DENY - source: 192.168.10.13 - destination: 192.168.20.15 - protocol: TCP - port: 80 - position: 7 -- item_type: ACL_RULE - id: '33' - permission: DENY - source: 192.168.20.14 - destination: 192.168.10.14 - protocol: TCP - port: 80 - position: 8 -- item_type: RED_POL - id: '34' - start_step: 20 - end_step: 20 - targetNodeId: '1' - initiator: DIRECT - type: SERVICE - protocol: TCP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_POL - id: '35' - start_step: 20 - end_step: 20 - targetNodeId: '2' - initiator: DIRECT - type: SERVICE - protocol: TCP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_IER - id: '36' - start_step: 30 - end_step: 128 - load: 440000000 - protocol: TCP - port: '80' - source: '1' - destination: '9' - mission_criticality: 0 -- item_type: RED_IER - id: '37' - start_step: 30 - end_step: 128 - load: 440000000 - protocol: TCP - port: '80' - source: '2' - destination: '9' - mission_criticality: 0 -- item_type: RED_POL - id: '38' - start_step: 30 - end_step: 30 - targetNodeId: '9' - initiator: IER - type: SERVICE - protocol: TCP - state: OVERWHELMED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA diff --git a/src/primaite/config/_package_data/lay_down/lay_down_config_3_DOS_very_basic.yaml b/src/primaite/config/_package_data/lay_down/lay_down_config_3_DOS_very_basic.yaml deleted file mode 100644 index 453b6abb..00000000 --- a/src/primaite/config/_package_data/lay_down/lay_down_config_3_DOS_very_basic.yaml +++ /dev/null @@ -1,164 +0,0 @@ -- item_type: PORTS - ports_list: - - port: '80' -- item_type: SERVICES - service_list: - - name: TCP -- item_type: NODE - node_id: '1' - name: PC1 - node_class: SERVICE - node_type: COMPUTER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.2 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '2' - name: PC2 - node_class: SERVICE - node_type: COMPUTER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.3 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '3' - name: SWITCH1 - node_class: ACTIVE - node_type: SWITCH - priority: P2 - hardware_state: 'ON' - ip_address: 192.168.1.1 - software_state: GOOD - file_system_state: GOOD -- item_type: NODE - node_id: '4' - name: SERVER1 - node_class: SERVICE - node_type: SERVER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.4 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: LINK - id: '5' - name: link1 - bandwidth: 1000000000 - source: '1' - destination: '3' -- item_type: LINK - id: '6' - name: link2 - bandwidth: 1000000000 - source: '2' - destination: '3' -- item_type: LINK - id: '7' - name: link3 - bandwidth: 1000000000 - source: '3' - destination: '4' -- item_type: GREEN_IER - id: '8' - start_step: 1 - end_step: 256 - load: 10000 - protocol: TCP - port: '80' - source: '1' - destination: '4' - mission_criticality: 1 -- item_type: GREEN_IER - id: '9' - start_step: 1 - end_step: 256 - load: 10000 - protocol: TCP - port: '80' - source: '2' - destination: '4' - mission_criticality: 1 -- item_type: GREEN_IER - id: '10' - start_step: 1 - end_step: 256 - load: 10000 - protocol: TCP - port: '80' - source: '4' - destination: '2' - mission_criticality: 5 -- item_type: ACL_RULE - id: '11' - permission: ALLOW - source: 192.168.1.2 - destination: 192.168.1.4 - protocol: TCP - port: 80 - position: 0 -- item_type: ACL_RULE - id: '12' - permission: ALLOW - source: 192.168.1.3 - destination: 192.168.1.4 - protocol: TCP - port: 80 - position: 1 -- item_type: ACL_RULE - id: '13' - permission: ALLOW - source: 192.168.1.4 - destination: 192.168.1.3 - protocol: TCP - port: 80 - position: 2 -- item_type: RED_POL - id: '14' - start_step: 20 - end_step: 20 - targetNodeId: '1' - initiator: DIRECT - type: SERVICE - protocol: TCP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_IER - id: '15' - start_step: 30 - end_step: 256 - load: 10000000 - protocol: TCP - port: '80' - source: '1' - destination: '4' - mission_criticality: 0 -- item_type: RED_POL - id: '16' - start_step: 40 - end_step: 40 - targetNodeId: '4' - initiator: IER - type: SERVICE - protocol: TCP - state: OVERWHELMED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA diff --git a/src/primaite/config/_package_data/lay_down/lay_down_config_5_data_manipulation.yaml b/src/primaite/config/_package_data/lay_down/lay_down_config_5_data_manipulation.yaml deleted file mode 100644 index 96596514..00000000 --- a/src/primaite/config/_package_data/lay_down/lay_down_config_5_data_manipulation.yaml +++ /dev/null @@ -1,546 +0,0 @@ -- item_type: PORTS - ports_list: - - port: '80' - - port: '1433' - - port: '53' -- item_type: SERVICES - service_list: - - name: TCP - - name: TCP_SQL - - name: UDP -- item_type: NODE - node_id: '1' - name: CLIENT_1 - node_class: SERVICE - node_type: COMPUTER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.10.11 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: UDP - port: '53' - state: GOOD -- item_type: NODE - node_id: '2' - name: CLIENT_2 - node_class: SERVICE - node_type: COMPUTER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.10.12 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: NODE - node_id: '3' - name: SWITCH_1 - node_class: ACTIVE - node_type: SWITCH - priority: P2 - hardware_state: 'ON' - ip_address: 192.168.10.1 - software_state: GOOD - file_system_state: GOOD -- item_type: NODE - node_id: '4' - name: SECURITY_SUITE - node_class: SERVICE - node_type: SERVER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.10 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: UDP - port: '53' - state: GOOD -- item_type: NODE - node_id: '5' - name: MANAGEMENT_CONSOLE - node_class: SERVICE - node_type: SERVER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.12 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: UDP - port: '53' - state: GOOD -- item_type: NODE - node_id: '6' - name: SWITCH_2 - node_class: ACTIVE - node_type: SWITCH - priority: P2 - hardware_state: 'ON' - ip_address: 192.168.2.1 - software_state: GOOD - file_system_state: GOOD -- item_type: NODE - node_id: '7' - name: WEB_SERVER - node_class: SERVICE - node_type: SERVER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.2.10 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: TCP_SQL - port: '1433' - state: GOOD -- item_type: NODE - node_id: '8' - name: DATABASE_SERVER - node_class: SERVICE - node_type: SERVER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.2.14 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: TCP_SQL - port: '1433' - state: GOOD - - name: UDP - port: '53' - state: GOOD -- item_type: NODE - node_id: '9' - name: BACKUP_SERVER - node_class: SERVICE - node_type: SERVER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.2.16 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- item_type: LINK - id: '10' - name: LINK_1 - bandwidth: 1000000000 - source: '1' - destination: '3' -- item_type: LINK - id: '11' - name: LINK_2 - bandwidth: 1000000000 - source: '2' - destination: '3' -- item_type: LINK - id: '12' - name: LINK_3 - bandwidth: 1000000000 - source: '3' - destination: '4' -- item_type: LINK - id: '13' - name: LINK_4 - bandwidth: 1000000000 - source: '3' - destination: '5' -- item_type: LINK - id: '14' - name: LINK_5 - bandwidth: 1000000000 - source: '4' - destination: '6' -- item_type: LINK - id: '15' - name: LINK_6 - bandwidth: 1000000000 - source: '5' - destination: '6' -- item_type: LINK - id: '16' - name: LINK_7 - bandwidth: 1000000000 - source: '6' - destination: '7' -- item_type: LINK - id: '17' - name: LINK_8 - bandwidth: 1000000000 - source: '6' - destination: '8' -- item_type: LINK - id: '18' - name: LINK_9 - bandwidth: 1000000000 - source: '6' - destination: '9' -- item_type: GREEN_IER - id: '19' - start_step: 1 - end_step: 256 - load: 10000 - protocol: TCP - port: '80' - source: '1' - destination: '7' - mission_criticality: 5 -- item_type: GREEN_IER - id: '20' - start_step: 1 - end_step: 256 - load: 10000 - protocol: TCP - port: '80' - source: '7' - destination: '1' - mission_criticality: 5 -- item_type: GREEN_IER - id: '21' - start_step: 1 - end_step: 256 - load: 10000 - protocol: TCP - port: '80' - source: '2' - destination: '7' - mission_criticality: 5 -- item_type: GREEN_IER - id: '22' - start_step: 1 - end_step: 256 - load: 10000 - protocol: TCP - port: '80' - source: '7' - destination: '2' - mission_criticality: 5 -- item_type: GREEN_IER - id: '23' - start_step: 1 - end_step: 256 - load: 5000 - protocol: TCP_SQL - port: '1433' - source: '7' - destination: '8' - mission_criticality: 5 -- item_type: GREEN_IER - id: '24' - start_step: 1 - end_step: 256 - load: 100000 - protocol: TCP_SQL - port: '1433' - source: '8' - destination: '7' - mission_criticality: 5 -- item_type: GREEN_IER - id: '25' - start_step: 1 - end_step: 256 - load: 50000 - protocol: TCP - port: '80' - source: '1' - destination: '9' - mission_criticality: 2 -- item_type: GREEN_IER - id: '26' - start_step: 1 - end_step: 256 - load: 50000 - protocol: TCP - port: '80' - source: '2' - destination: '9' - mission_criticality: 2 -- item_type: GREEN_IER - id: '27' - start_step: 1 - end_step: 256 - load: 5000 - protocol: TCP - port: '80' - source: '5' - destination: '7' - mission_criticality: 1 -- item_type: GREEN_IER - id: '28' - start_step: 1 - end_step: 256 - load: 5000 - protocol: TCP - port: '80' - source: '7' - destination: '5' - mission_criticality: 1 -- item_type: GREEN_IER - id: '29' - start_step: 1 - end_step: 256 - load: 5000 - protocol: TCP - port: '80' - source: '5' - destination: '8' - mission_criticality: 1 -- item_type: GREEN_IER - id: '30' - start_step: 1 - end_step: 256 - load: 5000 - protocol: TCP - port: '80' - source: '8' - destination: '5' - mission_criticality: 1 -- item_type: GREEN_IER - id: '31' - start_step: 1 - end_step: 256 - load: 5000 - protocol: TCP - port: '80' - source: '5' - destination: '9' - mission_criticality: 1 -- item_type: GREEN_IER - id: '32' - start_step: 1 - end_step: 256 - load: 5000 - protocol: TCP - port: '80' - source: '9' - destination: '5' - mission_criticality: 1 -- item_type: ACL_RULE - id: '33' - permission: ALLOW - source: 192.168.10.11 - destination: 192.168.2.10 - protocol: ANY - port: ANY - position: 0 -- item_type: ACL_RULE - id: '34' - permission: ALLOW - source: 192.168.10.11 - destination: 192.168.2.14 - protocol: ANY - port: ANY - position: 1 -- item_type: ACL_RULE - id: '35' - permission: ALLOW - source: 192.168.10.12 - destination: 192.168.2.14 - protocol: ANY - port: ANY - position: 2 -- item_type: ACL_RULE - id: '36' - permission: ALLOW - source: 192.168.10.12 - destination: 192.168.2.10 - protocol: ANY - port: ANY - position: 3 -- item_type: ACL_RULE - id: '37' - permission: ALLOW - source: 192.168.2.10 - destination: 192.168.10.11 - protocol: ANY - port: ANY - position: 4 -- item_type: ACL_RULE - id: '38' - permission: ALLOW - source: 192.168.2.10 - destination: 192.168.10.12 - protocol: ANY - port: ANY - position: 5 -- item_type: ACL_RULE - id: '39' - permission: ALLOW - source: 192.168.2.10 - destination: 192.168.2.14 - protocol: ANY - port: ANY - position: 6 -- item_type: ACL_RULE - id: '40' - permission: ALLOW - source: 192.168.2.14 - destination: 192.168.2.10 - protocol: ANY - port: ANY - position: 7 -- item_type: ACL_RULE - id: '41' - permission: ALLOW - source: 192.168.10.11 - destination: 192.168.2.16 - protocol: ANY - port: ANY - position: 8 -- item_type: ACL_RULE - id: '42' - permission: ALLOW - source: 192.168.10.12 - destination: 192.168.2.16 - protocol: ANY - port: ANY - position: 9 -- item_type: ACL_RULE - id: '43' - permission: ALLOW - source: 192.168.1.12 - destination: 192.168.2.10 - protocol: ANY - port: ANY - position: 10 -- item_type: ACL_RULE - id: '44' - permission: ALLOW - source: 192.168.1.12 - destination: 192.168.2.14 - protocol: ANY - port: ANY - position: 11 -- item_type: ACL_RULE - id: '45' - permission: ALLOW - source: 192.168.1.12 - destination: 192.168.2.16 - protocol: ANY - port: ANY - position: 12 -- item_type: ACL_RULE - id: '46' - permission: ALLOW - source: 192.168.2.10 - destination: 192.168.1.12 - protocol: ANY - port: ANY - position: 13 -- item_type: ACL_RULE - id: '47' - permission: ALLOW - source: 192.168.2.14 - destination: 192.168.1.12 - protocol: ANY - port: ANY - position: 14 -- item_type: ACL_RULE - id: '48' - permission: ALLOW - source: 192.168.2.16 - destination: 192.168.1.12 - protocol: ANY - port: ANY - position: 15 -- item_type: ACL_RULE - id: '49' - permission: DENY - source: ANY - destination: ANY - protocol: ANY - port: ANY - position: 16 -- item_type: RED_POL - id: '50' - start_step: 50 - end_step: 50 - targetNodeId: '1' - initiator: DIRECT - type: SERVICE - protocol: UDP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_IER - id: '51' - start_step: 75 - end_step: 105 - load: 10000 - protocol: UDP - port: '53' - source: '1' - destination: '8' - mission_criticality: 0 -- item_type: RED_POL - id: '52' - start_step: 100 - end_step: 100 - targetNodeId: '8' - initiator: IER - type: SERVICE - protocol: UDP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_POL - id: '53' - start_step: 105 - end_step: 105 - targetNodeId: '8' - initiator: SERVICE - type: FILE - protocol: NA - state: CORRUPT - sourceNodeId: '8' - sourceNodeService: UDP - sourceNodeServiceState: COMPROMISED -- item_type: RED_POL - id: '54' - start_step: 105 - end_step: 105 - targetNodeId: '8' - initiator: SERVICE - type: SERVICE - protocol: TCP_SQL - state: COMPROMISED - sourceNodeId: '8' - sourceNodeService: UDP - sourceNodeServiceState: COMPROMISED -- item_type: RED_POL - id: '55' - start_step: 125 - end_step: 125 - targetNodeId: '7' - initiator: SERVICE - type: SERVICE - protocol: TCP - state: OVERWHELMED - sourceNodeId: '8' - sourceNodeService: TCP_SQL - sourceNodeServiceState: COMPROMISED diff --git a/src/primaite/config/_package_data/training/training_config_main.yaml b/src/primaite/config/_package_data/training/training_config_main.yaml deleted file mode 100644 index db4ed692..00000000 --- a/src/primaite/config/_package_data/training/training_config_main.yaml +++ /dev/null @@ -1,168 +0,0 @@ -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: SB3 - -# Sets which deep learning framework will be used (by RLlib ONLY). -# Default is TF (Tensorflow). -# Options are: -# "TF" (Tensorflow) -# TF2 (Tensorflow 2.X) -# TORCH (PyTorch) -deep_learning_framework: TF2 - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: PPO - -# Sets whether Red Agent POL and IER is randomised. -# Options are: -# True -# False -random_red_agent: False - -# The (integer) seed to be used in random number generation -# Default is None (null) -seed: null - -# Set whether the agent evaluation will be deterministic instead of stochastic -# Options are: -# True -# False -deterministic: False - -# Sets what view of the environment the deterministic hardcoded agent has. The default is BASIC. -# Options are: -# "BASIC" (The current observation space only) -# "FULL" (Full environment view with actions taken and reward feedback) -hard_coded_agent_view: FULL - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: ANY -# observation space -observation_space: - flatten: true - components: - - name: NODE_LINK_TABLE - - name: NODE_STATUSES - - name: LINK_TRAFFIC_LEVELS - - name: ACCESS_CONTROL_LIST - -# Number of episodes for training to run per session -num_train_episodes: 10 - -# Number of time_steps for training per episode -num_train_steps: 256 - -# Number of episodes for evaluation to run per session -num_eval_episodes: 1 - -# Number of time_steps for evaluation per episode -num_eval_steps: 256 - -# Sets how often the agent will save a checkpoint (every n time episodes). -# Set to 0 if no checkpoints are required. Default is 10 -checkpoint_every_n_episodes: 10 - -# Time delay (milliseconds) between steps for CUSTOM agents. -time_delay: 5 - -# Type of session to be run. Options are: -# "TRAIN" (Trains an agent) -# "EVAL" (Evaluates an agent) -# "TRAIN_EVAL" (Trains then evaluates an agent) -session_type: TRAIN_EVAL - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1000000000 - -# Implicit ACL firewall rule at end of ACL list to be the default action (ALLOW or DENY) -implicit_acl_rule: DENY -# Total number of ACL rules allowed in the environment -max_number_acl_rules: 30 - -# The Stable Baselines3 learn/eval output verbosity level: -# Options are: -# "NONE" (No Output) -# "INFO" (Info Messages (such as devices and wrappers used)) -# "DEBUG" (All Messages) -sb3_output_verbose_level: NONE - -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -0.001 -off_should_be_resetting: -0.0005 -on_should_be_off: -0.0002 -on_should_be_resetting: -0.0005 -resetting_should_be_on: -0.0005 -resetting_should_be_off: -0.0002 -resetting: -0.0003 -# Node Software or Service State -good_should_be_patching: 0.0002 -good_should_be_compromised: 0.0005 -good_should_be_overwhelmed: 0.0005 -patching_should_be_good: -0.0005 -patching_should_be_compromised: 0.0002 -patching_should_be_overwhelmed: 0.0002 -patching: -0.0003 -compromised_should_be_good: -0.002 -compromised_should_be_patching: -0.002 -compromised_should_be_overwhelmed: -0.002 -compromised: -0.002 -overwhelmed_should_be_good: -0.002 -overwhelmed_should_be_patching: -0.002 -overwhelmed_should_be_compromised: -0.002 -overwhelmed: -0.002 -# Node File System State -good_should_be_repairing: 0.0002 -good_should_be_restoring: 0.0002 -good_should_be_corrupt: 0.0005 -good_should_be_destroyed: 0.001 -repairing_should_be_good: -0.0005 -repairing_should_be_restoring: 0.0002 -repairing_should_be_corrupt: 0.0002 -repairing_should_be_destroyed: 0.0000 -repairing: -0.0003 -restoring_should_be_good: -0.001 -restoring_should_be_repairing: -0.0002 -restoring_should_be_corrupt: 0.0001 -restoring_should_be_destroyed: 0.0002 -restoring: -0.0006 -corrupt_should_be_good: -0.001 -corrupt_should_be_repairing: -0.001 -corrupt_should_be_restoring: -0.001 -corrupt_should_be_destroyed: 0.0002 -corrupt: -0.001 -destroyed_should_be_good: -0.002 -destroyed_should_be_repairing: -0.002 -destroyed_should_be_restoring: -0.002 -destroyed_should_be_corrupt: -0.002 -destroyed: -0.002 -scanning: -0.0002 -# IER status -red_ier_running: -0.0005 -green_ier_blocked: -0.001 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/src/primaite/config/lay_down_config.py b/src/primaite/config/lay_down_config.py deleted file mode 100644 index fe3e3429..00000000 --- a/src/primaite/config/lay_down_config.py +++ /dev/null @@ -1,141 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -from logging import Logger -from pathlib import Path -from typing import Any, Dict, Final, List, Union - -import yaml - -from primaite import getLogger, PRIMAITE_PATHS - -_LOGGER: Logger = getLogger(__name__) - -_EXAMPLE_LAY_DOWN: Final[Path] = PRIMAITE_PATHS.user_config_path / "example_config" / "lay_down" - - -def convert_legacy_lay_down_config(legacy_config: List[Dict[str, Any]]) -> List[Dict[str, Any]]: - """ - Convert a legacy lay down config to the new format. - - :param legacy_config: A legacy lay down config. - """ - field_conversion_map = { - "itemType": "item_type", - "portsList": "ports_list", - "serviceList": "service_list", - "baseType": "node_class", - "nodeType": "node_type", - "hardwareState": "hardware_state", - "softwareState": "software_state", - "startStep": "start_step", - "endStep": "end_step", - "fileSystemState": "file_system_state", - "ipAddress": "ip_address", - "missionCriticality": "mission_criticality", - } - new_config = [] - for item in legacy_config: - if "itemType" in item: - if item["itemType"] in ["ACTIONS", "STEPS"]: - continue - new_dict = {} - for key in item.keys(): - conversion_key = field_conversion_map.get(key) - if key == "id" and "itemType" in item: - if item["itemType"] == "NODE": - conversion_key = "node_id" - if conversion_key: - new_dict[conversion_key] = item[key] - else: - new_dict[key] = item[key] - new_config.append(new_dict) - return new_config - - -def load(file_path: Union[str, Path], legacy_file: bool = False) -> Dict: - """ - Read in a lay down config yaml file. - - :param file_path: The config file path. - :param legacy_file: True if the config file is legacy format, otherwise False. - :return: The lay down config as a dict. - :raises ValueError: If the file_path does not exist. - """ - if not isinstance(file_path, Path): - file_path = Path(file_path) - if file_path.exists(): - with open(file_path, "r") as file: - config = yaml.safe_load(file) - _LOGGER.debug(f"Loading lay down config file: {file_path}") - if legacy_file: - try: - config = convert_legacy_lay_down_config(config) - except KeyError: - msg = ( - f"Failed to convert lay down config file {file_path} " - f"from legacy format. Attempting to use file as is." - ) - _LOGGER.error(msg) - return config - msg = f"Cannot load the lay down config as it does not exist: {file_path}" - _LOGGER.error(msg) - raise ValueError(msg) - - -def ddos_basic_one_config_path() -> Path: - """ - The path to the example lay_down_config_1_DDOS_basic.yaml file. - - :return: The file path. - """ - path = _EXAMPLE_LAY_DOWN / "lay_down_config_1_DDOS_basic.yaml" - if not path.exists(): - msg = "Example config not found. Please run 'primaite setup'" - _LOGGER.critical(msg) - raise FileNotFoundError(msg) - - return path - - -def ddos_basic_two_config_path() -> Path: - """ - The path to the example lay_down_config_2_DDOS_basic.yaml file. - - :return: The file path. - """ - path = _EXAMPLE_LAY_DOWN / "lay_down_config_2_DDOS_basic.yaml" - if not path.exists(): - msg = "Example config not found. Please run 'primaite setup'" - _LOGGER.critical(msg) - raise FileNotFoundError(msg) - - return path - - -def dos_very_basic_config_path() -> Path: - """ - The path to the example lay_down_config_3_DOS_very_basic.yaml file. - - :return: The file path. - """ - path = _EXAMPLE_LAY_DOWN / "lay_down_config_3_DOS_very_basic.yaml" - if not path.exists(): - msg = "Example config not found. Please run 'primaite setup'" - _LOGGER.critical(msg) - raise FileNotFoundError(msg) - - return path - - -def data_manipulation_config_path() -> Path: - """ - The path to the example lay_down_config_5_data_manipulation.yaml file. - - :return: The file path. - """ - path = _EXAMPLE_LAY_DOWN / "lay_down_config_5_data_manipulation.yaml" - if not path.exists(): - msg = "Example config not found. Please run 'primaite setup'" - _LOGGER.critical(msg) - raise FileNotFoundError(msg) - - return path diff --git a/src/primaite/config/training_config.py b/src/primaite/config/training_config.py deleted file mode 100644 index f81bb6f7..00000000 --- a/src/primaite/config/training_config.py +++ /dev/null @@ -1,438 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -from __future__ import annotations - -from dataclasses import dataclass, field -from logging import Logger -from pathlib import Path -from typing import Any, Dict, Final, Optional, Union - -import yaml - -from primaite import getLogger, PRIMAITE_PATHS -from primaite.common.enums import ( - ActionType, - AgentFramework, - AgentIdentifier, - DeepLearningFramework, - HardCodedAgentView, - RulePermissionType, - SB3OutputVerboseLevel, - SessionType, -) - -_LOGGER: Logger = getLogger(__name__) - -_EXAMPLE_TRAINING: Final[Path] = PRIMAITE_PATHS.user_config_path / "example_config" / "training" - - -def main_training_config_path() -> Path: - """ - The path to the example training_config_main.yaml file. - - :return: The file path. - """ - path = _EXAMPLE_TRAINING / "training_config_main.yaml" - if not path.exists(): - msg = "Example config not found. Please run 'primaite setup'" - _LOGGER.critical(msg) - raise FileNotFoundError(msg) - - return path - - -@dataclass() -class TrainingConfig: - """The Training Config class.""" - - agent_framework: AgentFramework = AgentFramework.SB3 - "The AgentFramework" - - deep_learning_framework: DeepLearningFramework = DeepLearningFramework.TF - "The DeepLearningFramework" - - agent_identifier: AgentIdentifier = AgentIdentifier.PPO - "The AgentIdentifier" - - hard_coded_agent_view: HardCodedAgentView = HardCodedAgentView.FULL - "The view the deterministic hard-coded agent has of the environment" - - random_red_agent: bool = False - "Creates Random Red Agent Attacks" - - action_type: ActionType = ActionType.ANY - "The ActionType to use" - - num_train_episodes: int = 10 - "The number of episodes to train over during an training session" - - num_train_steps: int = 256 - "The number of steps in an episode during an training session" - - num_eval_episodes: int = 1 - "The number of episodes to train over during an evaluation session" - - num_eval_steps: int = 256 - "The number of steps in an episode during an evaluation session" - - checkpoint_every_n_episodes: int = 5 - "The agent will save a checkpoint every n episodes" - - observation_space: dict = field(default_factory=lambda: {"components": [{"name": "NODE_LINK_TABLE"}]}) - "The observation space config dict" - - time_delay: int = 10 - "The delay between steps (ms). Applies to generic agents only" - - # file - session_type: SessionType = SessionType.TRAIN - "The type of PrimAITE session to run" - - load_agent: bool = False - "Determine whether to load an agent from file" - - agent_load_file: Optional[str] = None - "File path and file name of agent if you're loading one in" - - # Environment - observation_space_high_value: int = 1000000000 - "The high value for the observation space" - - sb3_output_verbose_level: SB3OutputVerboseLevel = SB3OutputVerboseLevel.NONE - "Stable Baselines3 learn/eval output verbosity level" - - implicit_acl_rule: RulePermissionType = RulePermissionType.DENY - "ALLOW or DENY implicit firewall rule to go at the end of list of ACL list." - - max_number_acl_rules: int = 30 - "Sets a limit for number of acl rules allowed in the list and environment." - - # Reward values - # Generic - all_ok: float = 0 - - # Node Hardware State - off_should_be_on: float = -0.001 - off_should_be_resetting: float = -0.0005 - on_should_be_off: float = -0.0002 - on_should_be_resetting: float = -0.0005 - resetting_should_be_on: float = -0.0005 - resetting_should_be_off: float = -0.0002 - resetting: float = -0.0003 - - # Node Software or Service State - good_should_be_patching: float = 0.0002 - good_should_be_compromised: float = 0.0005 - good_should_be_overwhelmed: float = 0.0005 - patching_should_be_good: float = -0.0005 - patching_should_be_compromised: float = 0.0002 - patching_should_be_overwhelmed: float = 0.0002 - patching: float = -0.0003 - compromised_should_be_good: float = -0.002 - compromised_should_be_patching: float = -0.002 - compromised_should_be_overwhelmed: float = -0.002 - compromised: float = -0.002 - overwhelmed_should_be_good: float = -0.002 - overwhelmed_should_be_patching: float = -0.002 - overwhelmed_should_be_compromised: float = -0.002 - overwhelmed: float = -0.002 - - # Node File System State - good_should_be_repairing: float = 0.0002 - good_should_be_restoring: float = 0.0002 - good_should_be_corrupt: float = 0.0005 - good_should_be_destroyed: float = 0.001 - repairing_should_be_good: float = -0.0005 - repairing_should_be_restoring: float = 0.0002 - repairing_should_be_corrupt: float = 0.0002 - repairing_should_be_destroyed: float = 0.0000 - repairing: float = -0.0003 - restoring_should_be_good: float = -0.001 - restoring_should_be_repairing: float = -0.0002 - restoring_should_be_corrupt: float = 0.0001 - restoring_should_be_destroyed: float = 0.0002 - restoring: float = -0.0006 - corrupt_should_be_good: float = -0.001 - corrupt_should_be_repairing: float = -0.001 - corrupt_should_be_restoring: float = -0.001 - corrupt_should_be_destroyed: float = 0.0002 - corrupt: float = -0.001 - destroyed_should_be_good: float = -0.002 - destroyed_should_be_repairing: float = -0.002 - destroyed_should_be_restoring: float = -0.002 - destroyed_should_be_corrupt: float = -0.002 - destroyed: float = -0.002 - scanning: float = -0.0002 - - # IER status - red_ier_running: float = -0.0005 - green_ier_blocked: float = -0.001 - - # Patching / Reset durations - os_patching_duration: int = 5 - "The time taken to patch the OS" - - node_reset_duration: int = 5 - "The time taken to reset a node (hardware)" - - node_booting_duration: int = 3 - "The Time taken to turn on the node" - - node_shutdown_duration: int = 2 - "The time taken to turn off the node" - - service_patching_duration: int = 5 - "The time taken to patch a service" - - file_system_repairing_limit: int = 5 - "The time take to repair the file system" - - file_system_restoring_limit: int = 5 - "The time take to restore the file system" - - file_system_scanning_limit: int = 5 - "The time taken to scan the file system" - - deterministic: bool = False - "If true, the training will be deterministic" - - seed: Optional[int] = None - "The random number generator seed to be used while training the agent" - - @classmethod - def from_dict(cls, config_dict: Dict[str, Any]) -> TrainingConfig: - """ - Create an instance of TrainingConfig from a dict. - - :param config_dict: The training config dict. - :return: The instance of TrainingConfig. - """ - field_enum_map = { - "agent_framework": AgentFramework, - "deep_learning_framework": DeepLearningFramework, - "agent_identifier": AgentIdentifier, - "action_type": ActionType, - "session_type": SessionType, - "sb3_output_verbose_level": SB3OutputVerboseLevel, - "hard_coded_agent_view": HardCodedAgentView, - "implicit_acl_rule": RulePermissionType, - } - - # convert the string representation of enums into the actual enum values themselves? - for key, value in field_enum_map.items(): - if key in config_dict: - config_dict[key] = value[config_dict[key]] - - return TrainingConfig(**config_dict) - - def to_dict(self, json_serializable: bool = True) -> Dict: - """ - Serialise the ``TrainingConfig`` as dict. - - :param json_serializable: If True, Enums are converted to their - string name. - :return: The ``TrainingConfig`` as a dict. - """ - data = self.__dict__ - if json_serializable: - data["agent_framework"] = self.agent_framework.name - data["deep_learning_framework"] = self.deep_learning_framework.name - data["agent_identifier"] = self.agent_identifier.name - data["action_type"] = self.action_type.name - data["sb3_output_verbose_level"] = self.sb3_output_verbose_level.name - data["session_type"] = self.session_type.name - data["hard_coded_agent_view"] = self.hard_coded_agent_view.name - data["implicit_acl_rule"] = self.implicit_acl_rule.name - - return data - - def __str__(self) -> str: - obs_str = ",".join([c["name"] for c in self.observation_space["components"]]) - tc = f"{self.agent_framework}, " - # if self.agent_framework is AgentFramework.RLLIB: - # tc += f"{self.deep_learning_framework}, " - tc += f"{self.agent_identifier}, " - if self.agent_identifier is AgentIdentifier.HARDCODED: - tc += f"{self.hard_coded_agent_view}, " - tc += f"{self.action_type}, " - tc += f"observation_space={obs_str}, " - if self.session_type is SessionType.TRAIN: - tc += f"{self.num_train_episodes} episodes @ " - tc += f"{self.num_train_steps} steps" - elif self.session_type is SessionType.EVAL: - tc += f"{self.num_eval_episodes} episodes @ " - tc += f"{self.num_eval_steps} steps" - else: - tc += f"Training: {self.num_eval_episodes} episodes @ " - tc += f"{self.num_eval_steps} steps" - tc += f"Evaluation: {self.num_eval_episodes} episodes @ " - tc += f"{self.num_eval_steps} steps" - return tc - - -def load(file_path: Union[str, Path], legacy_file: bool = False) -> TrainingConfig: - """ - Read in a training config yaml file. - - :param file_path: The config file path. - :param legacy_file: True if the config file is legacy format, otherwise - False. - :return: An instance of - :class:`~primaite.config.training_config.TrainingConfig`. - :raises ValueError: If the file_path does not exist. - :raises TypeError: When the TrainingConfig object cannot be created - using the values from the config file read from ``file_path``. - """ - if not isinstance(file_path, Path): - file_path = Path(file_path) - if file_path.exists(): - with open(file_path, "r") as file: - config = yaml.safe_load(file) - _LOGGER.debug(f"Loading training config file: {file_path}") - if legacy_file: - try: - config = convert_legacy_training_config_dict(config) - - except KeyError as e: - msg = ( - f"Failed to convert training config file {file_path} " - f"from legacy format. Attempting to use file as is." - ) - _LOGGER.error(msg) - raise e - try: - return TrainingConfig.from_dict(config) - except TypeError as e: - msg = f"Error when creating an instance of {TrainingConfig} " f"from the training config file {file_path}" - _LOGGER.critical(msg, exc_info=True) - raise e - msg = f"Cannot load the training config as it does not exist: {file_path}" - _LOGGER.error(msg) - raise ValueError(msg) - - -def convert_legacy_training_config_dict( - legacy_config_dict: Dict[str, Any], - agent_framework: AgentFramework = AgentFramework.SB3, - agent_identifier: AgentIdentifier = AgentIdentifier.PPO, - action_type: ActionType = ActionType.ANY, - num_train_steps: int = 256, - num_eval_steps: int = 256, - num_train_episodes: int = 10, - num_eval_episodes: int = 1, -) -> Dict[str, Any]: - """ - Convert a legacy training config dict to the new format. - - :param legacy_config_dict: A legacy training config dict. - :param agent_framework: The agent framework to use as legacy training - configs don't have agent_framework values. - :param agent_identifier: The red agent identifier to use as legacy - training configs don't have agent_identifier values. - :param action_type: The action space type to set as legacy training configs - don't have action_type values. - :param num_train_steps: The number of train steps to set as legacy training configs - don't have num_train_steps values. - :param num_eval_steps: The number of eval steps to set as legacy training configs - don't have num_eval_steps values. - :param num_train_episodes: The number of train episodes to set as legacy training configs - don't have num_train_episodes values. - :param num_eval_episodes: The number of eval episodes to set as legacy training configs - don't have num_eval_episodes values. - :return: The converted training config dict. - """ - config_dict = { - "agent_framework": agent_framework.name, - "agent_identifier": agent_identifier.name, - "action_type": action_type.name, - "num_train_steps": num_train_steps, - "num_eval_steps": num_eval_steps, - "num_train_episodes": num_train_episodes, - "num_eval_episodes": num_eval_episodes, - "sb3_output_verbose_level": SB3OutputVerboseLevel.INFO.name, - } - session_type_map = {"TRAINING": "TRAIN", "EVALUATION": "EVAL"} - legacy_config_dict["sessionType"] = session_type_map[legacy_config_dict["sessionType"]] - for legacy_key, value in legacy_config_dict.items(): - new_key = _get_new_key_from_legacy(legacy_key) - if new_key: - config_dict[new_key] = value - return config_dict - - -def _get_new_key_from_legacy(legacy_key: str) -> Optional[str]: - """ - Maps legacy training config keys to the new format keys. - - :param legacy_key: A legacy training config key. - :return: The mapped key. - """ - key_mapping = { - "agentIdentifier": None, - "numEpisodes": "num_train_episodes", - "numSteps": "num_train_steps", - "timeDelay": "time_delay", - "configFilename": None, - "sessionType": "session_type", - "loadAgent": "load_agent", - "agentLoadFile": "agent_load_file", - "observationSpaceHighValue": "observation_space_high_value", - "allOk": "all_ok", - "offShouldBeOn": "off_should_be_on", - "offShouldBeResetting": "off_should_be_resetting", - "onShouldBeOff": "on_should_be_off", - "onShouldBeResetting": "on_should_be_resetting", - "resettingShouldBeOn": "resetting_should_be_on", - "resettingShouldBeOff": "resetting_should_be_off", - "resetting": "resetting", - "goodShouldBePatching": "good_should_be_patching", - "goodShouldBeCompromised": "good_should_be_compromised", - "goodShouldBeOverwhelmed": "good_should_be_overwhelmed", - "patchingShouldBeGood": "patching_should_be_good", - "patchingShouldBeCompromised": "patching_should_be_compromised", - "patchingShouldBeOverwhelmed": "patching_should_be_overwhelmed", - "patching": "patching", - "compromisedShouldBeGood": "compromised_should_be_good", - "compromisedShouldBePatching": "compromised_should_be_patching", - "compromisedShouldBeOverwhelmed": "compromised_should_be_overwhelmed", - "compromised": "compromised", - "overwhelmedShouldBeGood": "overwhelmed_should_be_good", - "overwhelmedShouldBePatching": "overwhelmed_should_be_patching", - "overwhelmedShouldBeCompromised": "overwhelmed_should_be_compromised", - "overwhelmed": "overwhelmed", - "goodShouldBeRepairing": "good_should_be_repairing", - "goodShouldBeRestoring": "good_should_be_restoring", - "goodShouldBeCorrupt": "good_should_be_corrupt", - "goodShouldBeDestroyed": "good_should_be_destroyed", - "repairingShouldBeGood": "repairing_should_be_good", - "repairingShouldBeRestoring": "repairing_should_be_restoring", - "repairingShouldBeCorrupt": "repairing_should_be_corrupt", - "repairingShouldBeDestroyed": "repairing_should_be_destroyed", - "repairing": "repairing", - "restoringShouldBeGood": "restoring_should_be_good", - "restoringShouldBeRepairing": "restoring_should_be_repairing", - "restoringShouldBeCorrupt": "restoring_should_be_corrupt", - "restoringShouldBeDestroyed": "restoring_should_be_destroyed", - "restoring": "restoring", - "corruptShouldBeGood": "corrupt_should_be_good", - "corruptShouldBeRepairing": "corrupt_should_be_repairing", - "corruptShouldBeRestoring": "corrupt_should_be_restoring", - "corruptShouldBeDestroyed": "corrupt_should_be_destroyed", - "corrupt": "corrupt", - "destroyedShouldBeGood": "destroyed_should_be_good", - "destroyedShouldBeRepairing": "destroyed_should_be_repairing", - "destroyedShouldBeRestoring": "destroyed_should_be_restoring", - "destroyedShouldBeCorrupt": "destroyed_should_be_corrupt", - "destroyed": "destroyed", - "scanning": "scanning", - "redIerRunning": "red_ier_running", - "greenIerBlocked": "green_ier_blocked", - "osPatchingDuration": "os_patching_duration", - "nodeResetDuration": "node_reset_duration", - "nodeBootingDuration": "node_booting_duration", - "nodeShutdownDuration": "node_shutdown_duration", - "servicePatchingDuration": "service_patching_duration", - "fileSystemRepairingLimit": "file_system_repairing_limit", - "fileSystemRestoringLimit": "file_system_restoring_limit", - "fileSystemScanningLimit": "file_system_scanning_limit", - } - return key_mapping[legacy_key] diff --git a/src/primaite/data_viz/__init__.py b/src/primaite/data_viz/__init__.py deleted file mode 100644 index 260579da..00000000 --- a/src/primaite/data_viz/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Utility to generate plots of sessions metrics after PrimAITE.""" -from enum import Enum - - -class PlotlyTemplate(Enum): - """The built-in plotly templates.""" - - PLOTLY = "plotly" - PLOTLY_WHITE = "plotly_white" - PLOTLY_DARK = "plotly_dark" - GGPLOT2 = "ggplot2" - SEABORN = "seaborn" - SIMPLE_WHITE = "simple_white" - NONE = "none" diff --git a/src/primaite/data_viz/session_plots.py b/src/primaite/data_viz/session_plots.py deleted file mode 100644 index 37750353..00000000 --- a/src/primaite/data_viz/session_plots.py +++ /dev/null @@ -1,73 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -from pathlib import Path -from typing import Dict, Optional, Union - -import plotly.graph_objects as go -import polars as pl -import yaml -from plotly.graph_objs import Figure - -from primaite import PRIMAITE_PATHS - - -def get_plotly_config() -> Dict: - """Get the plotly config from primaite_config.yaml.""" - with open(PRIMAITE_PATHS.app_config_file_path, "r") as file: - primaite_config = yaml.safe_load(file) - return primaite_config["session"]["outputs"]["plots"] - - -def plot_av_reward_per_episode( - av_reward_per_episode_csv: Union[str, Path], - title: Optional[str] = None, - subtitle: Optional[str] = None, -) -> Figure: - """ - Plot the average reward per episode from a csv session output. - - :param av_reward_per_episode_csv: The average reward per episode csv - file path. - :param title: The plot title. This is optional. - :param subtitle: The plot subtitle. This is optional. - :return: The plot as an instance of ``plotly.graph_objs._figure.Figure``. - """ - df = pl.read_csv(av_reward_per_episode_csv) - - if title: - if subtitle: - title = f"{title}
{subtitle}" - else: - if subtitle: - title = subtitle - - config = get_plotly_config() - layout = go.Layout( - autosize=config["size"]["auto_size"], - width=config["size"]["width"], - height=config["size"]["height"], - ) - # Create the line graph with a colored line - fig = go.Figure(layout=layout) - fig.update_layout(template=config["template"]) - fig.add_trace( - go.Scatter( - x=df["Episode"], - y=df["Average Reward"], - mode="lines", - name="Mean Reward per Episode", - ) - ) - - # Set the layout of the graph - fig.update_layout( - xaxis={ - "title": "Episode", - "type": "linear", - "rangeslider": {"visible": config["range_slider"]}, - }, - yaxis={"title": "Average Reward"}, - title=title, - showlegend=False, - ) - - return fig diff --git a/src/primaite/environment/__init__.py b/src/primaite/environment/__init__.py deleted file mode 100644 index f0fd21b9..00000000 --- a/src/primaite/environment/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Gym/Gymnasium environment for RL agents consisting of a simulated computer network.""" diff --git a/src/primaite/environment/observations.py b/src/primaite/environment/observations.py deleted file mode 100644 index 73b9e998..00000000 --- a/src/primaite/environment/observations.py +++ /dev/null @@ -1,735 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Module for handling configurable observation spaces in PrimAITE.""" -import logging -from abc import ABC, abstractmethod -from logging import Logger -from typing import Dict, Final, List, Tuple, TYPE_CHECKING, Union - -import numpy as np -from gymnasium import spaces - -from primaite.acl.acl_rule import ACLRule -from primaite.common.enums import FileSystemState, HardwareState, RulePermissionType, SoftwareState -from primaite.nodes.active_node import ActiveNode -from primaite.nodes.service_node import ServiceNode - -# This dependency is only needed for type hints, -# TYPE_CHECKING is False at runtime and True when typecheckers are performing typechecking -# Therefore, this avoids circular dependency problem. -if TYPE_CHECKING: - from primaite.environment.primaite_env import Primaite - - -_LOGGER: Logger = logging.getLogger(__name__) - - -class AbstractObservationComponent(ABC): - """Represents a part of the PrimAITE observation space.""" - - @abstractmethod - def __init__(self, env: "Primaite") -> None: - """ - Initialise observation component. - - :param env: Primaite training environment. - :type env: Primaite - """ - _LOGGER.info(f"Initialising {self} observation component") - self.env: "Primaite" = env - self.space: spaces.Space - self.current_observation: np.ndarray # type might be too restrictive? - self.structure: List[str] - return NotImplemented - - @abstractmethod - def update(self) -> None: - """Update the observation based on the current state of the environment.""" - self.current_observation = NotImplemented - - @abstractmethod - def generate_structure(self) -> List[str]: - """Return a list of labels for the components of the flattened observation space.""" - return NotImplemented - - -class NodeLinkTable(AbstractObservationComponent): - """ - Table with nodes and links as rows and hardware/software status as cols. - - This will create the observation space formatted as a table of integers. - There is one row per node, followed by one row per link. - The number of columns is 4 plus one per service. They are: - - * node/link ID - * node hardware status / 0 for links - * node operating system status (if active/service) / 0 for links - * node file system status (active/service only) / 0 for links - * node service1 status / traffic load from that service for links - * node service2 status / traffic load from that service for links - * ... - * node serviceN status / traffic load from that service for links - - For example if the environment has 5 nodes, 7 links, and 3 services, the observation space shape will be - ``(12, 7)`` - """ - - _FIXED_PARAMETERS: int = 4 - _MAX_VAL: int = 1_000_000_000 - _DATA_TYPE: type = np.int64 - - def __init__(self, env: "Primaite") -> None: - """ - Initialise a NodeLinkTable observation space component. - - :param env: Training environment. - :type env: Primaite - """ - super().__init__(env) - - # 1. Define the shape of your observation space component - num_items = self.env.num_links + self.env.num_nodes - num_columns = self.env.num_services + self._FIXED_PARAMETERS - observation_shape = (num_items, num_columns) - - # 2. Create Observation space - self.space = spaces.Box( - low=0, - high=self._MAX_VAL, - shape=observation_shape, - dtype=self._DATA_TYPE, - ) - - # 3. Initialise Observation with zeroes - self.current_observation = np.zeros(observation_shape, dtype=self._DATA_TYPE) - - self.structure = self.generate_structure() - - def update(self) -> None: - """ - Update the observation based on current environment state. - - The structure of the observation space is described in :class:`.NodeLinkTable` - """ - item_index = 0 - nodes = self.env.nodes - links = self.env.links - # Do nodes first - for _, node in nodes.items(): - self.current_observation[item_index][0] = int(node.node_id) - self.current_observation[item_index][1] = node.hardware_state.value - if isinstance(node, ActiveNode) or isinstance(node, ServiceNode): - self.current_observation[item_index][2] = node.software_state.value - self.current_observation[item_index][3] = node.file_system_state_observed.value - else: - self.current_observation[item_index][2] = 0 - self.current_observation[item_index][3] = 0 - service_index = 4 - if isinstance(node, ServiceNode): - for service in self.env.services_list: - if node.has_service(service): - self.current_observation[item_index][service_index] = node.get_service_state(service).value - else: - self.current_observation[item_index][service_index] = 0 - service_index += 1 - else: - # Not a service node - for service in self.env.services_list: - self.current_observation[item_index][service_index] = 0 - service_index += 1 - item_index += 1 - - # Now do links - for _, link in links.items(): - self.current_observation[item_index][0] = int(link.get_id()) - self.current_observation[item_index][1] = 0 - self.current_observation[item_index][2] = 0 - self.current_observation[item_index][3] = 0 - protocol_list = link.get_protocol_list() - protocol_index = 0 - for protocol in protocol_list: - self.current_observation[item_index][protocol_index + 4] = protocol.get_load() - protocol_index += 1 - item_index += 1 - - def generate_structure(self) -> List[str]: - """Return a list of labels for the components of the flattened observation space.""" - nodes = self.env.nodes.values() - links = self.env.links.values() - - structure = [] - - for i, node in enumerate(nodes): - node_id = node.node_id - node_labels = [ - f"node_{node_id}_id", - f"node_{node_id}_hardware_status", - f"node_{node_id}_os_status", - f"node_{node_id}_fs_status", - ] - for j, serv in enumerate(self.env.services_list): - node_labels.append(f"node_{node_id}_service_{serv}_status") - - structure.extend(node_labels) - - for i, link in enumerate(links): - link_id = link.id - link_labels = [ - f"link_{link_id}_id", - f"link_{link_id}_n/a", - f"link_{link_id}_n/a", - f"link_{link_id}_n/a", - ] - for j, serv in enumerate(self.env.services_list): - link_labels.append(f"link_{link_id}_service_{serv}_load") - - structure.extend(link_labels) - return structure - - -class NodeStatuses(AbstractObservationComponent): - """ - Flat list of nodes' hardware, OS, file system, and service states. - - The MultiDiscrete observation space can be though of as a one-dimensional vector of discrete states, represented by - integers. - Each node has 3 elements plus 1 per service. It will have the following structure: - .. code-block:: - - [ - node1 hardware state, - node1 OS state, - node1 file system state, - node1 service1 state, - node1 service2 state, - node1 serviceN state (one for each service), - node2 hardware state, - node2 OS state, - node2 file system state, - node2 service1 state, - node2 service2 state, - node2 serviceN state (one for each service), - ... - ] - """ - - _DATA_TYPE: type = np.int64 - - def __init__(self, env: "Primaite") -> None: - """ - Initialise a NodeStatuses observation component. - - :param env: Training environment. - :type env: Primaite - """ - super().__init__(env) - - # 1. Define the shape of your observation space component - node_shape = [ - len(HardwareState) + 1, - len(SoftwareState) + 1, - len(FileSystemState) + 1, - ] - services_shape = [len(SoftwareState) + 1] * self.env.num_services - node_shape = node_shape + services_shape - - shape = node_shape * self.env.num_nodes - # 2. Create Observation space - self.space = spaces.MultiDiscrete(shape) - - # 3. Initialise observation with zeroes - self.current_observation = np.zeros(len(shape), dtype=self._DATA_TYPE) - self.structure = self.generate_structure() - - def update(self) -> None: - """ - Update the observation based on current environment state. - - The structure of the observation space is described in :class:`.NodeStatuses` - """ - obs = [] - for _, node in self.env.nodes.items(): - hardware_state = node.hardware_state.value - software_state = 0 - file_system_state = 0 - service_states = [0] * self.env.num_services - - if isinstance(node, ActiveNode): - software_state = node.software_state.value - file_system_state = node.file_system_state_observed.value - - if isinstance(node, ServiceNode): - for i, service in enumerate(self.env.services_list): - if node.has_service(service): - service_states[i] = node.get_service_state(service).value - obs.extend( - [ - hardware_state, - software_state, - file_system_state, - *service_states, - ] - ) - self.current_observation[:] = obs - - def generate_structure(self) -> List[str]: - """Return a list of labels for the components of the flattened observation space.""" - services = self.env.services_list - - structure = [] - - for _, node in self.env.nodes.items(): - node_id = node.node_id - structure.append(f"node_{node_id}_hardware_state_NONE") - for state in HardwareState: - structure.append(f"node_{node_id}_hardware_state_{state.name}") - structure.append(f"node_{node_id}_software_state_NONE") - for state in SoftwareState: - structure.append(f"node_{node_id}_software_state_{state.name}") - structure.append(f"node_{node_id}_file_system_state_NONE") - for state in FileSystemState: - structure.append(f"node_{node_id}_file_system_state_{state.name}") - for service in services: - structure.append(f"node_{node_id}_service_{service}_state_NONE") - for state in SoftwareState: - structure.append(f"node_{node_id}_service_{service}_state_{state.name}") - return structure - - -class LinkTrafficLevels(AbstractObservationComponent): - """ - Flat list of traffic levels encoded into banded categories. - - For each link, total traffic or traffic per service is encoded into a categorical value. - For example, if ``quantisation_levels=5``, the traffic levels represent these values: - - * 0 = No traffic (0% of bandwidth) - * 1 = No traffic (0%-33% of bandwidth) - * 2 = No traffic (33%-66% of bandwidth) - * 3 = No traffic (66%-100% of bandwidth) - * 4 = No traffic (100% of bandwidth) - - .. note:: - The lowest category always corresponds to no traffic and the highest category to the link being at max capacity. - Any amount of traffic between 0% and 100% (exclusive) is divided evenly into the remaining categories. - - """ - - _DATA_TYPE: type = np.int64 - - def __init__( - self, - env: "Primaite", - combine_service_traffic: bool = False, - quantisation_levels: int = 5, - ) -> None: - """ - Initialise a LinkTrafficLevels observation component. - - :param env: The environment that forms the basis of the observations - :type env: Primaite - :param combine_service_traffic: Whether to consider total traffic on the link, or each protocol individually, - defaults to False - :type combine_service_traffic: bool, optional - :param quantisation_levels: How many bands to consider when converting the traffic amount to a categorical - value, defaults to 5 - :type quantisation_levels: int, optional - """ - if quantisation_levels < 3: - _msg = ( - f"quantisation_levels must be 3 or more because the lowest and highest levels are " - f"reserved for 0% and 100% link utilisation, got {quantisation_levels} instead. " - f"Resetting to default value (5)" - ) - _LOGGER.warning(_msg) - quantisation_levels = 5 - - super().__init__(env) - - self._combine_service_traffic: bool = combine_service_traffic - self._quantisation_levels: int = quantisation_levels - self._entries_per_link: int = 1 - - if not self._combine_service_traffic: - self._entries_per_link = self.env.num_services - - # 1. Define the shape of your observation space component - shape = [self._quantisation_levels] * self.env.num_links * self._entries_per_link - - # 2. Create Observation space - self.space = spaces.MultiDiscrete(shape) - - # 3. Initialise observation with zeroes - self.current_observation = np.zeros(len(shape), dtype=self._DATA_TYPE) - - self.structure = self.generate_structure() - - def update(self) -> None: - """ - Update the observation based on current environment state. - - The structure of the observation space is described in :class:`.LinkTrafficLevels` - """ - obs = [] - for _, link in self.env.links.items(): - bandwidth = link.bandwidth - if self._combine_service_traffic: - loads = [link.get_current_load()] - else: - loads = [protocol.get_load() for protocol in link.protocol_list] - - for load in loads: - if load <= 0: - traffic_level = 0 - elif load >= bandwidth: - traffic_level = self._quantisation_levels - 1 - else: - traffic_level = (load / bandwidth) // (1 / (self._quantisation_levels - 2)) + 1 - - obs.append(int(traffic_level)) - - self.current_observation[:] = obs - - def generate_structure(self) -> List[str]: - """Return a list of labels for the components of the flattened observation space.""" - structure = [] - for _, link in self.env.links.items(): - link_id = link.id - if self._combine_service_traffic: - protocols = ["overall"] - else: - protocols = [protocol.name for protocol in link.protocol_list] - - for p in protocols: - for i in range(self._quantisation_levels): - structure.append(f"link_{link_id}_{p}_traffic_level_{i}") - return structure - - -class AccessControlList(AbstractObservationComponent): - """Flat list of all the Access Control Rules in the Access Control List. - - The MultiDiscrete observation space can be though of as a one-dimensional vector of discrete states, represented by - integers. - - Each ACL Rule has 6 elements. It will have the following structure: - .. code-block:: - [ - acl_rule1 permission, - acl_rule1 source_ip, - acl_rule1 dest_ip, - acl_rule1 protocol, - acl_rule1 port, - acl_rule1 position, - acl_rule2 permission, - acl_rule2 source_ip, - acl_rule2 dest_ip, - acl_rule2 protocol, - acl_rule2 port, - acl_rule2 position, - ... - ] - - - Terms (for ACL Observation Space): - [0, 1, 2] - Permission (0 = NA, 1 = DENY, 2 = ALLOW) - [0, num nodes] - Source IP (0 = NA, 1 = any, then 2 -> x resolving to Node IDs) - [0, num nodes] - Dest IP (0 = NA, 1 = any, then 2 -> x resolving to Node IDs) - [0, num services] - Protocol (0 = NA, 1 = any, then 2 -> x resolving to protocol) - [0, num ports] - Port (0 = NA, 1 = any, then 2 -> x resolving to port) - [0, max acl rules - 1] - Position (0 = NA, 1 = first index, then 2 -> x index resolving to acl rule in acl list) - - NOTE: NA is Non-Applicable - this means the ACL Rule in the list is a NoneType and NOT an ACLRule object. - """ - - _DATA_TYPE: type = np.int64 - - def __init__(self, env: "Primaite") -> None: - """ - Initialise an AccessControlList observation component. - - :param env: The environment that forms the basis of the observations - :type env: Primaite - """ - super().__init__(env) - - # 1. Define the shape of your observation space component - # The NA and ANY types means that there are 2 extra items for Nodes, Services and Ports. - # Number of ACL rules incremented by 1 for positions starting at index 0. - acl_shape = [ - len(RulePermissionType), - len(env.nodes) + 2, - len(env.nodes) + 2, - len(env.services_list) + 2, - len(env.ports_list) + 2, - env.max_number_acl_rules, - ] - shape = acl_shape * self.env.max_number_acl_rules - - # 2. Create Observation space - self.space = spaces.MultiDiscrete(shape) - - # 3. Initialise observation with zeroes - self.current_observation = np.zeros(len(shape), dtype=self._DATA_TYPE) - - self.structure = self.generate_structure() - - def update(self) -> None: - """Update the observation based on current environment state. - - The structure of the observation space is described in :class:`.AccessControlList` - """ - obs = [] - - for index in range(0, len(self.env.acl.acl)): - acl_rule = self.env.acl.acl[index] - if isinstance(acl_rule, ACLRule): - permission = acl_rule.permission - source_ip = acl_rule.source_ip - dest_ip = acl_rule.dest_ip - protocol = acl_rule.protocol - port = acl_rule.port - position = index - # Map each ACL attribute from what it was to an integer to fit the observation space - source_ip_int = None - dest_ip_int = None - if permission == RulePermissionType.DENY: - permission_int = 1 - else: - permission_int = 2 - if source_ip == "ANY": - source_ip_int = 1 - else: - # Map Node ID (+ 1) to source IP address - nodes = list(self.env.nodes.values()) - for node in nodes: - if ( - isinstance(node, ServiceNode) or isinstance(node, ActiveNode) - ) and node.ip_address == source_ip: - source_ip_int = int(node.node_id) + 1 - break - if dest_ip == "ANY": - dest_ip_int = 1 - else: - # Map Node ID (+ 1) to dest IP address - # Index of Nodes start at 1 so + 1 is needed so NA can be added. - nodes = list(self.env.nodes.values()) - for node in nodes: - if ( - isinstance(node, ServiceNode) or isinstance(node, ActiveNode) - ) and node.ip_address == dest_ip: - dest_ip_int = int(node.node_id) + 1 - if protocol == "ANY": - protocol_int = 1 - else: - # Index of protocols and ports start from 0 so + 2 is needed to add NA and ANY - try: - protocol_int = self.env.services_list.index(protocol) + 2 - except AttributeError: - _LOGGER.info(f"Service {protocol} could not be found") - protocol_int = None - if port == "ANY": - port_int = 1 - else: - if port in self.env.ports_list: - port_int = self.env.ports_list.index(port) + 2 - else: - _LOGGER.info(f"Port {port} could not be found.") - port_int = None - # Add to current obs - obs.extend( - [ - permission_int, - source_ip_int, - dest_ip_int, - protocol_int, - port_int, - position, - ] - ) - - else: - # The Nothing or NA representation of 'NONE' ACL rules - obs.extend([0, 0, 0, 0, 0, 0]) - - self.current_observation[:] = obs - - def generate_structure(self) -> List[str]: - """Return a list of labels for the components of the flattened observation space.""" - structure = [] - for acl_rule in self.env.acl.acl: - acl_rule_id = self.env.acl.acl.index(acl_rule) - - for permission in RulePermissionType: - structure.append(f"acl_rule_{acl_rule_id}_permission_{permission.name}") - - structure.append(f"acl_rule_{acl_rule_id}_source_ip_ANY") - for node in self.env.nodes.keys(): - structure.append(f"acl_rule_{acl_rule_id}_source_ip_{node}") - - structure.append(f"acl_rule_{acl_rule_id}_dest_ip_ANY") - for node in self.env.nodes.keys(): - structure.append(f"acl_rule_{acl_rule_id}_dest_ip_{node}") - - structure.append(f"acl_rule_{acl_rule_id}_service_ANY") - for service in self.env.services_list: - structure.append(f"acl_rule_{acl_rule_id}_service_{service}") - - structure.append(f"acl_rule_{acl_rule_id}_port_ANY") - for port in self.env.ports_list: - structure.append(f"acl_rule_{acl_rule_id}_port_{port}") - - return structure - - -class ObservationsHandler: - """ - Component-based observation space handler. - - This allows users to configure observation spaces by mixing and matching components. Each component can also define - further parameters to make them more flexible. - """ - - _REGISTRY: Final[Dict[str, type]] = { - "NODE_LINK_TABLE": NodeLinkTable, - "NODE_STATUSES": NodeStatuses, - "LINK_TRAFFIC_LEVELS": LinkTrafficLevels, - "ACCESS_CONTROL_LIST": AccessControlList, - } - - def __init__(self) -> None: - """Initialise the observation handler.""" - self.registered_obs_components: List[AbstractObservationComponent] = [] - - # internal the observation space (unflattened version of space if flatten=True) - self._space: spaces.Space - # flattened version of the observation space - self._flat_space: spaces.Space - - self._observation: Union[Tuple[np.ndarray], np.ndarray] - # used for transactions and when flatten=true - self._flat_observation: np.ndarray - - def update_obs(self) -> None: - """Fetch fresh information about the environment.""" - current_obs = [] - for obs in self.registered_obs_components: - obs.update() - current_obs.append(obs.current_observation) - - if len(current_obs) == 1: - self._observation = current_obs[0] - else: - self._observation = tuple(current_obs) - self._flat_observation = spaces.flatten(self._space, self._observation) - - def register(self, obs_component: AbstractObservationComponent) -> None: - """ - Add a component for this handler to track. - - :param obs_component: The component to add. - :type obs_component: AbstractObservationComponent - """ - self.registered_obs_components.append(obs_component) - self.update_space() - - def deregister(self, obs_component: AbstractObservationComponent) -> None: - """ - Remove a component from this handler. - - :param obs_component: Which component to remove. It must exist within this object's - ``registered_obs_components`` attribute. - :type obs_component: AbstractObservationComponent - """ - self.registered_obs_components.remove(obs_component) - self.update_space() - - def update_space(self) -> None: - """Rebuild the handler's composite observation space from its components.""" - component_spaces = [] - for obs_comp in self.registered_obs_components: - component_spaces.append(obs_comp.space) - - # if there are multiple components, build a composite tuple space - if len(component_spaces) == 1: - self._space = component_spaces[0] - else: - self._space = spaces.Tuple(component_spaces) - if len(component_spaces) > 0: - self._flat_space = spaces.flatten_space(self._space) - else: - self._flat_space = spaces.Box(0, 1, (0,)) - - @property - def space(self) -> spaces.Space: - """Observation space, return the flattened version if flatten is True.""" - if len(self.registered_obs_components) > 1: - return self._flat_space - else: - return self._space - - @property - def current_observation(self) -> Union[np.ndarray, Tuple[np.ndarray]]: - """Current observation, return the flattened version if flatten is True.""" - if len(self.registered_obs_components) > 1: - return self._flat_observation - else: - return self._observation - - @classmethod - def from_config(cls, env: "Primaite", obs_space_config: dict) -> "ObservationsHandler": - """ - Parse a config dictinary, return a new observation handler populated with new observation component objects. - - The expected format for the config dictionary is: - - .. code-block:: python - - config = { - components: [ - { - "name": "" - }, - { - "name": "" - "options": {"opt1": val1, "opt2": val2} - }, - { - ... - }, - ] - } - - :return: Observation handler - :rtype: primaite.environment.observations.ObservationsHandler - """ - # Instantiate the handler - handler = cls() - - for component_cfg in obs_space_config["components"]: - # Figure out which class can instantiate the desired component - comp_type = component_cfg["name"] - comp_class = cls._REGISTRY[comp_type] - - # Create the component with options from the YAML - options = component_cfg.get("options") or {} - component = comp_class(env, **options) - - handler.register(component) - - handler.update_obs() - return handler - - def describe_structure(self) -> List[str]: - """ - Create a list of names for the features of the obs space. - - The order of labels follows the flattened version of the space. - """ - # as it turns out it's not possible to take the gym flattening function and apply it to our labels so we have - # to fake it. each component has to just hard-code the expected label order after flattening... - - labels = [] - for obs_comp in self.registered_obs_components: - labels.extend(obs_comp.structure) - - return labels diff --git a/src/primaite/environment/primaite_env.py b/src/primaite/environment/primaite_env.py deleted file mode 100644 index a809772f..00000000 --- a/src/primaite/environment/primaite_env.py +++ /dev/null @@ -1,1408 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Main environment module containing the PRIMmary AI Training Evironment (Primaite) class.""" -import copy -import logging -import uuid as uuid -from logging import Logger -from pathlib import Path -from random import choice, randint, sample, uniform -from typing import Any, Dict, Final, List, Tuple, Union - -import networkx as nx -import numpy as np -from gym import Env, spaces -from matplotlib import pyplot as plt - -from primaite import getLogger -from primaite.acl.access_control_list import AccessControlList -from primaite.agents.utils import is_valid_acl_action_extra, is_valid_node_action -from primaite.common.custom_typing import NodeUnion -from primaite.common.enums import ( # AgentFramework, - ActionType, - AgentIdentifier, - FileSystemState, - HardwareState, - NodePOLInitiator, - NodePOLType, - NodeType, - ObservationType, - Priority, - SessionType, - SoftwareState, -) -from primaite.common.service import Service -from primaite.config import training_config -from primaite.config.lay_down_config import load -from primaite.config.training_config import TrainingConfig -from primaite.environment.observations import ObservationsHandler -from primaite.environment.reward import calculate_reward_function -from primaite.links.link import Link -from primaite.nodes.active_node import ActiveNode -from primaite.nodes.node import Node -from primaite.nodes.node_state_instruction_green import NodeStateInstructionGreen -from primaite.nodes.node_state_instruction_red import NodeStateInstructionRed -from primaite.nodes.passive_node import PassiveNode -from primaite.nodes.service_node import ServiceNode -from primaite.pol.green_pol import apply_iers, apply_node_pol -from primaite.pol.ier import IER -from primaite.pol.red_agent_pol import apply_red_agent_iers, apply_red_agent_node_pol -from primaite.transactions.transaction import Transaction -from primaite.utils.session_output_writer import SessionOutputWriter - -_LOGGER: Logger = getLogger(__name__) - - -class Primaite(Env): - """PRIMmary AI Training Evironment (Primaite) class.""" - - # Action Space contants - ACTION_SPACE_NODE_PROPERTY_VALUES: int = 5 - ACTION_SPACE_NODE_ACTION_VALUES: int = 4 - ACTION_SPACE_ACL_ACTION_VALUES: int = 3 - ACTION_SPACE_ACL_PERMISSION_VALUES: int = 2 - - def __init__( - self, - training_config_path: Union[str, Path], - lay_down_config_path: Union[str, Path], - session_path: Path, - timestamp_str: str, - legacy_training_config: bool = False, - legacy_lay_down_config: bool = False, - ) -> None: - """ - The Primaite constructor. - - :param training_config_path: The training config filepath. - :param lay_down_config_path: The lay down config filepath. - :param session_path: The directory path the session is writing to. - :param timestamp_str: The session timestamp in the format: _. - :param legacy_training_config: True if the training config file is a legacy file from PrimAITE < 2.0, - otherwise False. - :param legacy_lay_down_config: True if the lay_down config file is a legacy file from PrimAITE < 2.0, - otherwise False. - """ - self.session_path: Final[Path] = session_path - self.timestamp_str: Final[str] = timestamp_str - self._training_config_path: Union[str, Path] = training_config_path - self._lay_down_config_path: Union[str, Path] = lay_down_config_path - self.legacy_training_config = legacy_training_config - self.legacy_lay_down_config = legacy_lay_down_config - - self.training_config: TrainingConfig = training_config.load(training_config_path, self.legacy_training_config) - _LOGGER.info(f"Using: {str(self.training_config)}") - - # Number of steps in an episode - self.episode_steps: int - if self.training_config.session_type == SessionType.TRAIN: - self.episode_steps = self.training_config.num_train_steps - elif self.training_config.session_type == SessionType.EVAL: - self.episode_steps = self.training_config.num_eval_steps - else: - self.episode_steps = self.training_config.num_train_steps - - super(Primaite, self).__init__() - - # The agent in use - self.agent_identifier: AgentIdentifier = self.training_config.agent_identifier - - # Create a dictionary to hold all the nodes - self.nodes: Dict[str, NodeUnion] = {} - - # Create a dictionary to hold a reference set of nodes - self.nodes_reference: Dict[str, NodeUnion] = {} - - # Create a dictionary to hold all the links - self.links: Dict[str, Link] = {} - - # Create a dictionary to hold a reference set of links - self.links_reference: Dict[str, Link] = {} - - # Create a dictionary to hold all the green IERs (this will come from an external source) - self.green_iers: Dict[str, IER] = {} - self.green_iers_reference: Dict[str, IER] = {} - - # Create a dictionary to hold all the node PoLs (this will come from an external source) - self.node_pol: Dict[str, NodeStateInstructionGreen] = {} - - # Create a dictionary to hold all the red agent IERs (this will come from an external source) - self.red_iers: Dict[str, IER] = {} - - # Create a dictionary to hold all the red agent node PoLs (this will come from an external source) - self.red_node_pol: Dict[str, NodeStateInstructionRed] = {} - - # Create the Access Control List - self.acl: AccessControlList = AccessControlList( - self.training_config.implicit_acl_rule, - self.training_config.max_number_acl_rules, - ) - # Sets limit for number of ACL rules in environment - self.max_number_acl_rules: int = self.training_config.max_number_acl_rules - - # Create a list of services (enums) - self.services_list: List[str] = [] - - # Create a list of ports - self.ports_list: List[str] = [] - - # Create graph (network) - self.network: nx.Graph = nx.MultiGraph() - - # Create a graph (network) reference - self.network_reference: nx.Graph = nx.MultiGraph() - - # Create step count - self.step_count: int = 0 - - self.total_step_count: int = 0 - """The total number of time steps completed.""" - - # Create step info dictionary - self.step_info: Dict[Any] = {} - - # Total reward - self.total_reward: float = 0 - - # Average reward - self.average_reward: float = 0 - - # Episode count - self.episode_count: int = 0 - - # Number of nodes - gets a value by examining the nodes dictionary after it's been populated - self.num_nodes: int = 0 - - # Number of links - gets a value by examining the links dictionary after it's been populated - self.num_links: int = 0 - - # Number of services - gets a value when config is loaded - self.num_services: int = 0 - - # Number of ports - gets a value when config is loaded - self.num_ports: int = 0 - - # The action type - # TODO: confirm type - self.action_type: int = 0 - - # TODO fix up with TrainingConfig - # stores the observation config from the yaml, default is NODE_LINK_TABLE - self.obs_config: dict = {"components": [{"name": "NODE_LINK_TABLE"}]} - if self.training_config.observation_space is not None: - self.obs_config = self.training_config.observation_space - - # Observation Handler manages the user-configurable observation space. - # It will be initialised later. - self.obs_handler: ObservationsHandler - - self._obs_space_description: List[str] = None - "The env observation space description for transactions writing" - - self.lay_down_config = load(self._lay_down_config_path, self.legacy_lay_down_config) - self.load_lay_down_config() - - # Store the node objects as node attributes - # (This is so we can access them as objects) - for node in self.network: - self.network.nodes[node]["self"] = node - - for node in self.network_reference: - self.network_reference.nodes[node]["self"] = node - - self.num_nodes = len(self.nodes) - self.num_links = len(self.links) - - # Visualise in PNG - try: - plt.tight_layout() - nx.draw_networkx(self.network, with_labels=True) - - file_path = session_path / f"network_{timestamp_str}.png" - plt.savefig(file_path, format="PNG") - plt.clf() - except Exception: - _LOGGER.error("Could not save network diagram", exc_info=True) - - # Initiate observation space - self.observation_space: spaces.Space - self.env_obs: np.ndarray - self.observation_space, self.env_obs = self.init_observations() - - # Define Action Space - depends on action space type (Node or ACL) - self.action_dict: Dict[int, List[int]] - self.action_space: spaces.Space - if self.training_config.action_type == ActionType.NODE: - _LOGGER.debug("Action space type NODE selected") - # Terms (for node action space): - # [0, num nodes] - node ID (0 = nothing, node ID) - # [0, 4] - what property it's acting on (0 = nothing, state, SoftwareState, # noqa - # service state, file system state) # noqa - # [0, 3] - action on property (0 = nothing, On / Scan, Off / Repair, Reset / Patch / Restore) # noqa - # [0, num services] - resolves to service ID (0 = nothing, resolves to service) # noqa - self.action_dict = self.create_node_action_dict() - self.action_space = spaces.Discrete(len(self.action_dict)) - elif self.training_config.action_type == ActionType.ACL: - _LOGGER.debug("Action space type ACL selected") - # Terms (for ACL action space): - # [0, 2] - Action (0 = do nothing, 1 = create rule, 2 = delete rule) - # [0, 1] - Permission (0 = DENY, 1 = ALLOW) - # [0, num nodes] - Source IP (0 = any, then 1 -> x resolving to IP addresses) - # [0, num nodes] - Dest IP (0 = any, then 1 -> x resolving to IP addresses) - # [0, num services] - Protocol (0 = any, then 1 -> x resolving to protocol) - # [0, num ports] - Port (0 = any, then 1 -> x resolving to port) - self.action_dict = self.create_acl_action_dict() - self.action_space = spaces.Discrete(len(self.action_dict)) - elif self.training_config.action_type == ActionType.ANY: - _LOGGER.debug("Action space type ANY selected - Node + ACL") - self.action_dict = self.create_node_and_acl_action_dict() - self.action_space = spaces.Discrete(len(self.action_dict)) - else: - _LOGGER.error(f"Invalid action type selected: {self.training_config.action_type}") - - self.episode_av_reward_writer: SessionOutputWriter = SessionOutputWriter( - self, transaction_writer=False, learning_session=True - ) - self.transaction_writer: SessionOutputWriter = SessionOutputWriter( - self, transaction_writer=True, learning_session=True - ) - - self.is_eval = False - - @property - def actual_episode_count(self) -> int: - """Shifts the episode_count by -1 for RLlib learning session.""" - # if self.training_config.agent_framework is AgentFramework.RLLIB and not self.is_eval: - # return self.episode_count - 1 - return self.episode_count - - def set_as_eval(self) -> None: - """Set the writers to write to eval directories.""" - self.episode_av_reward_writer = SessionOutputWriter(self, transaction_writer=False, learning_session=False) - self.transaction_writer = SessionOutputWriter(self, transaction_writer=True, learning_session=False) - self.episode_count = 0 - self.step_count = 0 - self.total_step_count = 0 - self.episode_steps = self.training_config.num_eval_steps - self.is_eval = True - - def _write_av_reward_per_episode(self) -> None: - if self.actual_episode_count > 0: - csv_data = self.actual_episode_count, self.average_reward - self.episode_av_reward_writer.write(csv_data) - - def reset(self) -> np.ndarray: - """ - AI Gym Reset function. - - Returns: - Environment observation space (reset) - """ - self._write_av_reward_per_episode() - self.episode_count += 1 - - # Don't need to reset links, as they are cleared and recalculated every - # step - - # Clear the ACL - self.init_acl() - - # Reset the node statuses and recreate the ACL from config - # Does this for both live and reference nodes - self.reset_environment() - - # Create a random red agent to use for this episode - if self.training_config.random_red_agent: - self._create_random_red_agent() - - # Reset counters and totals - self.total_reward = 0.0 - self.step_count = 0 - self.average_reward = 0.0 - - # Update observations space and return - self.update_environent_obs() - - return self.env_obs - - def step(self, action: int) -> Tuple[np.ndarray, float, bool, Dict]: - """ - AI Gym Step function. - - Args: - action: Action space from agent - - Returns: - env_obs: Observation space - reward: Reward value for this step - done: Indicates episode is complete if True - step_info: Additional information relating to this step - """ - # TEMP - done = False - self.step_count += 1 - self.total_step_count += 1 - - # Need to clear traffic on all links first - for link_key, link_value in self.links.items(): - link_value.clear_traffic() - - for link in self.links_reference.values(): - link.clear_traffic() - - # Create a Transaction (metric) object for this step - transaction = Transaction(self.agent_identifier, self.actual_episode_count, self.step_count) - # Load the initial observation space into the transaction - transaction.obs_space = self.obs_handler._flat_observation - - # Set the transaction obs space description - transaction.obs_space_description = self._obs_space_description - - # Load the action space into the transaction - transaction.action_space = copy.deepcopy(action) - - # 1. Implement Blue Action - self.interpret_action_and_apply(action) - # Take snapshots of nodes and links - self.nodes_post_blue = copy.deepcopy(self.nodes) - self.links_post_blue = copy.deepcopy(self.links) - - # 2. Perform any time-based activities (e.g. a component moving from patching to good) - self.apply_time_based_updates() - - # 3. Apply PoL - apply_node_pol(self.nodes, self.node_pol, self.step_count) # Node PoL - apply_iers( - self.network, - self.nodes, - self.links, - self.green_iers, - self.acl, - self.step_count, - ) # Network PoL - # Take snapshots of nodes and links - self.nodes_post_pol = copy.deepcopy(self.nodes) - self.links_post_pol = copy.deepcopy(self.links) - # Reference - apply_node_pol(self.nodes_reference, self.node_pol, self.step_count) # Node PoL - apply_iers( - self.network_reference, - self.nodes_reference, - self.links_reference, - self.green_iers_reference, - self.acl, - self.step_count, - ) # Network PoL - - # 4. Implement Red Action - apply_red_agent_iers( - self.network, - self.nodes, - self.links, - self.red_iers, - self.acl, - self.step_count, - ) - apply_red_agent_node_pol(self.nodes, self.red_iers, self.red_node_pol, self.step_count) - # Take snapshots of nodes and links - self.nodes_post_red = copy.deepcopy(self.nodes) - self.links_post_red = copy.deepcopy(self.links) - - # 5. Calculate reward signal (for RL) - reward = calculate_reward_function( - self.nodes_post_pol, - self.nodes_post_red, - self.nodes_reference, - self.green_iers, - self.green_iers_reference, - self.red_iers, - self.step_count, - self.training_config, - ) - _LOGGER.debug(f"Episode: {self.actual_episode_count}, " f"Step {self.step_count}, " f"Reward: {reward}") - self.total_reward += reward - if self.step_count == self.episode_steps: - self.average_reward = self.total_reward / self.step_count - if self.training_config.session_type is SessionType.EVAL: - # For evaluation, need to trigger the done value = True when - # step count is reached in order to prevent neverending episode - done = True - _LOGGER.info(f"Episode: {self.actual_episode_count}, " f"Average Reward: {self.average_reward}") - # Load the reward into the transaction - transaction.reward = reward - - # 6. Output Verbose - # self.output_link_status() - - # 7. Update env_obs - self.update_environent_obs() - - # Write transaction to file - if self.actual_episode_count > 0: - self.transaction_writer.write(transaction) - - # Return - return self.env_obs, reward, done, self.step_info - - def close(self) -> None: - """Override parent close and close writers.""" - # Close files if last episode/step - # if self.can_finish: - super().close() - - self.transaction_writer.close() - self.episode_av_reward_writer.close() - - def init_acl(self) -> None: - """Initialise the Access Control List.""" - self.acl.remove_all_rules() - - def output_link_status(self) -> None: - """Output the link status of all links to the console.""" - for link_key, link_value in self.links.items(): - _LOGGER.debug("Link ID: " + link_value.get_id()) - for protocol in link_value.protocol_list: - print(" Protocol: " + protocol.get_name().name + ", Load: " + str(protocol.get_load())) - - def interpret_action_and_apply(self, _action: int) -> None: - """ - Applies agent actions to the nodes and Access Control List. - - Args: - _action: The action space from the agent - """ - # At the moment, actions are only affecting nodes - if self.training_config.action_type == ActionType.NODE: - self.apply_actions_to_nodes(_action) - elif self.training_config.action_type == ActionType.ACL: - self.apply_actions_to_acl(_action) - elif len(self.action_dict[_action]) == 7: # ACL actions in multidiscrete form have len 7 - self.apply_actions_to_acl(_action) - elif len(self.action_dict[_action]) == 4: # Node actions in multdiscrete (array) from have len 4 - self.apply_actions_to_nodes(_action) - else: - logging.error("Invalid action type found") - - def apply_actions_to_nodes(self, _action: int) -> None: - """ - Applies agent actions to the nodes. - - Args: - _action: The action space from the agent - """ - readable_action = self.action_dict[_action] - node_id = readable_action[0] - node_property = readable_action[1] - property_action = readable_action[2] - service_index = readable_action[3] - - # Check that the action is requesting a valid node - try: - node = self.nodes[str(node_id)] - except Exception: - return - - if node_property == 0: - # This is the do nothing action - return - elif node_property == 1: - # This is an action on the node Hardware State - if property_action == 0: - # Do nothing - return - elif property_action == 1: - # Turn on (only applicable if it's OFF, not if it's patching) - if node.hardware_state == HardwareState.OFF: - node.turn_on() - elif property_action == 2: - # Turn off - node.turn_off() - elif property_action == 3: - # Reset (only applicable if it's ON) - if node.hardware_state == HardwareState.ON: - node.reset() - else: - return - elif node_property == 2: - if isinstance(node, ActiveNode) or isinstance(node, ServiceNode): - # This is an action on the node Software State - if property_action == 0: - # Do nothing - return - elif property_action == 1: - # Patch (valid action if it's good or compromised) - node.software_state = SoftwareState.PATCHING - else: - # Node is not of Active or Service Type - return - elif node_property == 3: - # This is an action on a node Service State - if isinstance(node, ServiceNode): - # This is an action on a node Service State - if property_action == 0: - # Do nothing - return - elif property_action == 1: - # Patch (valid action if it's good or compromised) - node.set_service_state(self.services_list[service_index], SoftwareState.PATCHING) - else: - # Node is not of Service Type - return - elif node_property == 4: - # This is an action on a node file system state - if isinstance(node, ActiveNode): - if property_action == 0: - # Do nothing - return - elif property_action == 1: - # Scan - node.start_file_system_scan() - elif property_action == 2: - # Repair - # You cannot repair a destroyed file system - it needs restoring - if node.file_system_state_actual != FileSystemState.DESTROYED: - node.set_file_system_state(FileSystemState.REPAIRING) - elif property_action == 3: - # Restore - node.set_file_system_state(FileSystemState.RESTORING) - else: - # Node is not of Active Type - return - else: - return - - def apply_actions_to_acl(self, _action: int) -> None: - """ - Applies agent actions to the Access Control List [TO DO]. - - Args: - _action: The action space from the agent - """ - # Convert discrete value back to multidiscrete - readable_action = self.action_dict[_action] - - action_decision = readable_action[0] - action_permission = readable_action[1] - action_source_ip = readable_action[2] - action_destination_ip = readable_action[3] - action_protocol = readable_action[4] - action_port = readable_action[5] - acl_rule_position = readable_action[6] - - if action_decision == 0: - # It's decided to do nothing - return - else: - # It's decided to create a new ACL rule or remove an existing rule - # Permission value - if action_permission == 0: - acl_rule_permission = "DENY" - else: - acl_rule_permission = "ALLOW" - # Source IP value - if action_source_ip == 0: - acl_rule_source = "ANY" - else: - node = list(self.nodes.values())[action_source_ip - 1] - if isinstance(node, ServiceNode) or isinstance(node, ActiveNode): - acl_rule_source = node.ip_address - else: - return - # Destination IP value - if action_destination_ip == 0: - acl_rule_destination = "ANY" - else: - node = list(self.nodes.values())[action_destination_ip - 1] - if isinstance(node, ServiceNode) or isinstance(node, ActiveNode): - acl_rule_destination = node.ip_address - else: - return - # Protocol value - if action_protocol == 0: - acl_rule_protocol = "ANY" - else: - acl_rule_protocol = self.services_list[action_protocol - 1] - # Port value - if action_port == 0: - acl_rule_port = "ANY" - else: - acl_rule_port = self.ports_list[action_port - 1] - - # Now add or remove - if action_decision == 1: - # Add the rule - self.acl.add_rule( - acl_rule_permission, - acl_rule_source, - acl_rule_destination, - acl_rule_protocol, - acl_rule_port, - acl_rule_position, - ) - elif action_decision == 2: - # Remove the rule - self.acl.remove_rule( - acl_rule_permission, - acl_rule_source, - acl_rule_destination, - acl_rule_protocol, - acl_rule_port, - ) - else: - return - - def apply_time_based_updates(self) -> None: - """ - Updates anything that needs to count down and then change state. - - e.g. reset / patching status - """ - for node_key, node in self.nodes.items(): - if node.hardware_state == HardwareState.RESETTING: - node.update_resetting_status() - else: - pass - if isinstance(node, ActiveNode) or isinstance(node, ServiceNode): - node.update_file_system_state() - if node.software_state == SoftwareState.PATCHING: - node.update_os_patching_status() - else: - pass - else: - pass - if isinstance(node, ServiceNode): - node.update_services_patching_status() - else: - pass - - for node_key, node in self.nodes_reference.items(): - if node.hardware_state == HardwareState.RESETTING: - node.update_resetting_status() - else: - pass - if isinstance(node, ActiveNode) or isinstance(node, ServiceNode): - node.update_file_system_state() - if node.software_state == SoftwareState.PATCHING: - node.update_os_patching_status() - else: - pass - else: - pass - if isinstance(node, ServiceNode): - node.update_services_patching_status() - else: - pass - - def init_observations(self) -> Tuple[spaces.Space, np.ndarray]: - """ - Create the environment's observation handler. - - :return: The observation space, initial observation (zeroed out array with the correct shape) - :rtype: Tuple[spaces.Space, np.ndarray] - """ - self.obs_handler = ObservationsHandler.from_config(self, self.obs_config) - - if not self._obs_space_description: - self._obs_space_description = self.obs_handler.describe_structure() - - return self.obs_handler.space, self.obs_handler.current_observation - - def update_environent_obs(self) -> None: - """Updates the observation space based on the node and link status.""" - self.obs_handler.update_obs() - self.env_obs = self.obs_handler.current_observation - - def load_lay_down_config(self) -> None: - """Loads config data in order to build the environment configuration.""" - for item in self.lay_down_config: - if item["item_type"] == "NODE": - # Create a node - self.create_node(item) - elif item["item_type"] == "LINK": - # Create a link - self.create_link(item) - elif item["item_type"] == "GREEN_IER": - # Create a Green IER - self.create_green_ier(item) - elif item["item_type"] == "GREEN_POL": - # Create a Green PoL - self.create_green_pol(item) - elif item["item_type"] == "RED_IER": - # Create a Red IER - self.create_red_ier(item) - elif item["item_type"] == "RED_POL": - # Create a Red PoL - self.create_red_pol(item) - elif item["item_type"] == "ACL_RULE": - # Create an ACL rule - self.create_acl_rule(item) - elif item["item_type"] == "SERVICES": - # Create the list of services - self.create_services_list(item) - elif item["item_type"] == "PORTS": - # Create the list of ports - self.create_ports_list(item) - else: - item_type = item["item_type"] - _LOGGER.error(f"Invalid item_type: {item_type}") - pass - - _LOGGER.info("Environment configuration loaded") - print("Environment configuration loaded") - - def create_node(self, item: Dict) -> None: - """ - Creates a node from config data. - - Args: - item: A config data item - """ - # All nodes have these parameters - node_id = item["node_id"] - node_name = item["name"] - node_class = item["node_class"] - node_type = NodeType[item["node_type"]] - node_priority = Priority[item["priority"]] - node_hardware_state = HardwareState[item["hardware_state"]] - - if node_class == "PASSIVE": - node = PassiveNode( - node_id, - node_name, - node_type, - node_priority, - node_hardware_state, - self.training_config, - ) - elif node_class == "ACTIVE": - # Active nodes have IP address, Software State and file system state - node_ip_address = item["ip_address"] - node_software_state = SoftwareState[item["software_state"]] - node_file_system_state = FileSystemState[item["file_system_state"]] - node = ActiveNode( - node_id, - node_name, - node_type, - node_priority, - node_hardware_state, - node_ip_address, - node_software_state, - node_file_system_state, - self.training_config, - ) - elif node_class == "SERVICE": - # Service nodes have IP address, Software State, file system state and list of services - node_ip_address = item["ip_address"] - node_software_state = SoftwareState[item["software_state"]] - node_file_system_state = FileSystemState[item["file_system_state"]] - node = ServiceNode( - node_id, - node_name, - node_type, - node_priority, - node_hardware_state, - node_ip_address, - node_software_state, - node_file_system_state, - self.training_config, - ) - node_services = item["services"] - for service in node_services: - service_protocol = service["name"] - service_port = service["port"] - service_state = SoftwareState[service["state"]] - node.add_service(Service(service_protocol, service_port, service_state)) - else: - # Bad formatting - pass - - # Copy the node for the reference version - node_ref = copy.deepcopy(node) - - # Add node to node dictionary - self.nodes[node_id] = node - - # Add reference node to reference node dictionary - self.nodes_reference[node_id] = node_ref - - # Add node to network - self.network.add_nodes_from([node]) - - # Add node to network (reference) - self.network_reference.add_nodes_from([node_ref]) - - def create_link(self, item: Dict) -> None: - """ - Creates a link from config data. - - Args: - item: A config data item - """ - link_id = item["id"] - link_name = item["name"] - link_bandwidth = item["bandwidth"] - link_source = item["source"] - link_destination = item["destination"] - - source_node: Node = self.nodes[link_source] - dest_node: Node = self.nodes[link_destination] - - # Add link to network - self.network.add_edge(source_node, dest_node, id=link_name) - - # Add link to link dictionary - self.links[link_name] = Link( - link_id, - link_bandwidth, - source_node.name, - dest_node.name, - self.services_list, - ) - - # Reference - source_node_ref: Node = self.nodes_reference[link_source] - dest_node_ref: Node = self.nodes_reference[link_destination] - - # Add link to network (reference) - self.network_reference.add_edge(source_node_ref, dest_node_ref, id=link_name) - - # Add link to link dictionary (reference) - self.links_reference[link_name] = Link( - link_id, - link_bandwidth, - source_node_ref.name, - dest_node_ref.name, - self.services_list, - ) - - def create_green_ier(self, item: Dict) -> None: - """ - Creates a green IER from config data. - - Args: - item: A config data item - """ - ier_id = item["id"] - ier_start_step = item["start_step"] - ier_end_step = item["end_step"] - ier_load = item["load"] - ier_protocol = item["protocol"] - ier_port = item["port"] - ier_source = item["source"] - ier_destination = item["destination"] - ier_mission_criticality = item["mission_criticality"] - - # Create IER and add to green IER dictionary - self.green_iers[ier_id] = IER( - ier_id, - ier_start_step, - ier_end_step, - ier_load, - ier_protocol, - ier_port, - ier_source, - ier_destination, - ier_mission_criticality, - ) - self.green_iers_reference[ier_id] = IER( - ier_id, - ier_start_step, - ier_end_step, - ier_load, - ier_protocol, - ier_port, - ier_source, - ier_destination, - ier_mission_criticality, - ) - - def create_red_ier(self, item: Dict) -> None: - """ - Creates a red IER from config data. - - Args: - item: A config data item - """ - ier_id = item["id"] - ier_start_step = item["start_step"] - ier_end_step = item["end_step"] - ier_load = item["load"] - ier_protocol = item["protocol"] - ier_port = item["port"] - ier_source = item["source"] - ier_destination = item["destination"] - ier_mission_criticality = item["mission_criticality"] - - # Create IER and add to red IER dictionary - self.red_iers[ier_id] = IER( - ier_id, - ier_start_step, - ier_end_step, - ier_load, - ier_protocol, - ier_port, - ier_source, - ier_destination, - ier_mission_criticality, - ) - - def create_green_pol(self, item: Dict) -> None: - """ - Creates a green PoL object from config data. - - Args: - item: A config data item - """ - pol_id = item["id"] - pol_start_step = item["start_step"] - pol_end_step = item["end_step"] - pol_node = item["nodeId"] - pol_type = NodePOLType[item["type"]] - - # State depends on whether this is Operating, Software, file system or Service PoL type - if pol_type == NodePOLType.OPERATING: - pol_state = HardwareState[item["state"]] - pol_protocol = "" - elif pol_type == NodePOLType.FILE: - pol_state = FileSystemState[item["state"]] - pol_protocol = "" - else: - pol_protocol = item["protocol"] - pol_state = SoftwareState[item["state"]] - - self.node_pol[pol_id] = NodeStateInstructionGreen( - pol_id, - pol_start_step, - pol_end_step, - pol_node, - pol_type, - pol_protocol, - pol_state, - ) - - def create_red_pol(self, item: Dict) -> None: - """ - Creates a red PoL object from config data. - - Args: - item: A config data item - """ - pol_id = item["id"] - pol_start_step = item["start_step"] - pol_end_step = item["end_step"] - pol_target_node_id = item["targetNodeId"] - pol_initiator = NodePOLInitiator[item["initiator"]] - pol_type = NodePOLType[item["type"]] - pol_protocol = item["protocol"] - - # State depends on whether this is Operating, Software, file system or Service PoL type - if pol_type == NodePOLType.OPERATING: - pol_state = HardwareState[item["state"]] - elif pol_type == NodePOLType.FILE: - pol_state = FileSystemState[item["state"]] - else: - pol_state = SoftwareState[item["state"]] - - pol_source_node_id = item["sourceNodeId"] - pol_source_node_service = item["sourceNodeService"] - pol_source_node_service_state = item["sourceNodeServiceState"] - - self.red_node_pol[pol_id] = NodeStateInstructionRed( - pol_id, - pol_start_step, - pol_end_step, - pol_target_node_id, - pol_initiator, - pol_type, - pol_protocol, - pol_state, - pol_source_node_id, - pol_source_node_service, - pol_source_node_service_state, - ) - - def create_acl_rule(self, item: Dict) -> None: - """ - Creates an ACL rule from config data. - - Args: - item: A config data item - """ - acl_rule_permission = item["permission"] - acl_rule_source = item["source"] - acl_rule_destination = item["destination"] - acl_rule_protocol = item["protocol"] - acl_rule_port = item["port"] - acl_rule_position = item.get("position") - - self.acl.add_rule( - acl_rule_permission, - acl_rule_source, - acl_rule_destination, - acl_rule_protocol, - acl_rule_port, - acl_rule_position, - ) - - # TODO: confirm typehint using runtime - def create_services_list(self, services: Dict) -> None: - """ - Creates a list of services (enum) from config data. - - Args: - item: A config data item representing the services - """ - service_list = services["service_list"] - - for service in service_list: - service_name = service["name"] - self.services_list.append(service_name) - - # Set the number of services - self.num_services = len(self.services_list) - - def create_ports_list(self, ports: Dict) -> None: - """ - Creates a list of ports from config data. - - Args: - item: A config data item representing the ports - """ - ports_list = ports["ports_list"] - - for port in ports_list: - port_value = port["port"] - self.ports_list.append(port_value) - - # Set the number of ports - self.num_ports = len(self.ports_list) - - # TODO: this is not used anymore, write a ticket to delete it - def get_observation_info(self, observation_info: Dict) -> None: - """ - Extracts observation_info. - - :param observation_info: Config item that defines which type of observation space to use - :type observation_info: str - """ - self.observation_type = ObservationType[observation_info["type"]] - - # TODO: this is not used anymore, write a ticket to delete it. - def get_action_info(self, action_info: Dict) -> None: - """ - Extracts action_info. - - Args: - item: A config data item representing action info - """ - self.action_type = ActionType[action_info["type"]] - - def save_obs_config(self, obs_config: dict) -> None: - """ - Cache the config for the observation space. - - This is necessary as the observation space can't be built while reading the config, - it must be done after all the nodes, links, and services have been initialised. - - :param obs_config: Parsed config relating to the observation space. The format is described in - :py:meth:`primaite.environment.observations.ObservationsHandler.from_config` - :type obs_config: dict - """ - self.obs_config = obs_config - - def reset_environment(self) -> None: - """ - Resets environment. - - Uses config data config data in order to build the environment configuration. - """ - for item in self.lay_down_config: - if item["item_type"] == "NODE": - # Reset a node's state (normal and reference) - self.reset_node(item) - elif item["item_type"] == "ACL_RULE": - # Create an ACL rule (these are cleared on reset, so just need to recreate them) - self.create_acl_rule(item) - else: - # Do nothing (bad formatting or not relevant to reset) - pass - - # Reset the IER status so they are not running initially - # Green IERs - for ier_key, ier_value in self.green_iers.items(): - ier_value.set_is_running(False) - # Red IERs - for ier_key, ier_value in self.red_iers.items(): - ier_value.set_is_running(False) - - def reset_node(self, item: Dict) -> None: - """ - Resets the statuses of a node. - - Args: - item: A config data item - """ - # All nodes have these parameters - node_id = item["node_id"] - node_class = item["node_class"] - node_hardware_state: HardwareState = HardwareState[item["hardware_state"]] - - node: NodeUnion = self.nodes[node_id] - node_ref = self.nodes_reference[node_id] - - # Reset the hardware state (common for all node types) - node.hardware_state = node_hardware_state - node_ref.hardware_state = node_hardware_state - - if node_class == "ACTIVE": - # Active nodes have Software State - node_software_state = SoftwareState[item["software_state"]] - node_file_system_state = FileSystemState[item["file_system_state"]] - node.software_state = node_software_state - node_ref.software_state = node_software_state - node.set_file_system_state(node_file_system_state) - node_ref.set_file_system_state(node_file_system_state) - elif node_class == "SERVICE": - # Service nodes have Software State and list of services - node_software_state = SoftwareState[item["software_state"]] - node_file_system_state = FileSystemState[item["file_system_state"]] - node.software_state = node_software_state - node_ref.software_state = node_software_state - node.set_file_system_state(node_file_system_state) - node_ref.set_file_system_state(node_file_system_state) - # Update service states - node_services = item["services"] - for service in node_services: - service_protocol = service["name"] - service_state = SoftwareState[service["state"]] - # Update node service state - node.set_service_state(service_protocol, service_state) - # Update reference node service state - node_ref.set_service_state(service_protocol, service_state) - else: - # Bad formatting - pass - - def create_node_action_dict(self) -> Dict[int, List[int]]: - """ - Creates a dictionary mapping each possible discrete action to more readable multidiscrete action. - - Note: Only actions that have the potential to change the state exist in the mapping (except for key 0) - - example return: - {0: [1, 0, 0, 0], - 1: [1, 1, 1, 0], - 2: [1, 1, 2, 0], - 3: [1, 1, 3, 0], - 4: [1, 2, 1, 0], - 5: [1, 3, 1, 0], - ... - } - """ - # Terms (for node action space): - # [0, num nodes] - node ID (0 = nothing, node ID) - # [0, 4] - what property it's acting on (0 = nothing, state, SoftwareState, service state, file system state) # noqa - # [0, 3] - action on property (0 = nothing, On / Scan, Off / Repair, Reset / Patch / Restore) # noqa - # [0, num services] - resolves to service ID (0 = nothing, resolves to service) # noqa - # reserve 0 action to be a nothing action - actions = {0: [1, 0, 0, 0]} - action_key = 1 - for node in range(1, self.num_nodes + 1): - # 4 node properties (NONE, OPERATING, OS, SERVICE) - for node_property in range(4): - # Node Actions either: - # (NONE, ON, OFF, RESET) - operating state OR (NONE, PATCH) - OS/service state - # Use MAX to ensure we get them all - for node_action in range(4): - for service_state in range(self.num_services): - action = [node, node_property, node_action, service_state] - # check to see if it's a nothing action (has no effect) - if is_valid_node_action(action): - actions[action_key] = action - action_key += 1 - - return actions - - def create_acl_action_dict(self) -> Dict[int, List[int]]: - """Creates a dictionary mapping each possible discrete action to more readable multidiscrete action.""" - # Terms (for ACL action space): - # [0, 2] - Action (0 = do nothing, 1 = create rule, 2 = delete rule) - # [0, 1] - Permission (0 = DENY, 1 = ALLOW) - # [0, num nodes] - Source IP (0 = any, then 1 -> x resolving to IP addresses) - # [0, num nodes] - Dest IP (0 = any, then 1 -> x resolving to IP addresses) - # [0, num services] - Protocol (0 = any, then 1 -> x resolving to protocol) - # [0, num ports] - Port (0 = any, then 1 -> x resolving to port) - # [0, max acl rules - 1] - Position (0 = first index, then 1 -> x index resolving to acl rule in acl list) - # reserve 0 action to be a nothing action - actions = {0: [0, 0, 0, 0, 0, 0, 0]} - - action_key = 1 - # 3 possible action decisions, 0=NOTHING, 1=CREATE, 2=DELETE - for action_decision in range(3): - # 2 possible action permissions 0 = DENY, 1 = CREATE - for action_permission in range(2): - # Number of nodes + 1 (for any) - for source_ip in range(self.num_nodes + 1): - for dest_ip in range(self.num_nodes + 1): - for protocol in range(self.num_services + 1): - for port in range(self.num_ports + 1): - for position in range(self.max_number_acl_rules - 1): - action = [ - action_decision, - action_permission, - source_ip, - dest_ip, - protocol, - port, - position, - ] - # Check to see if it is an action we want to include as possible - # i.e. not a nothing action - if is_valid_acl_action_extra(action): - actions[action_key] = action - action_key += 1 - - return actions - - def create_node_and_acl_action_dict(self) -> Dict[int, List[int]]: - """ - Create a dictionary mapping each possible discrete action to a more readable mutlidiscrete action. - - The dictionary contains actions of both Node and ACL action types. - """ - node_action_dict = self.create_node_action_dict() - acl_action_dict = self.create_acl_action_dict() - - # Change node keys to not overlap with acl keys - # Only 1 nothing action (key 0) is required, remove the other - new_node_action_dict = {k + len(acl_action_dict) - 1: v for k, v in node_action_dict.items() if k != 0} - - # Combine the Node dict and ACL dict - combined_action_dict = {**acl_action_dict, **new_node_action_dict} - return combined_action_dict - - def _create_random_red_agent(self) -> None: - """Decide on random red agent for the episode to be called in env.reset().""" - # Reset the current red iers and red node pol - self.red_iers = {} - self.red_node_pol = {} - - # Decide how many nodes become compromised - node_list = list(self.nodes.values()) - computers = [node for node in node_list if node.node_type == NodeType.COMPUTER] - max_num_nodes_compromised = len(computers) # only computers can become compromised - # random select between 1 and max_num_nodes_compromised - num_nodes_to_compromise = randint(1, max_num_nodes_compromised) - - # Decide which of the nodes to compromise - nodes_to_be_compromised = sample(computers, num_nodes_to_compromise) - - # choose a random compromise node to be source of attacks - source_node = choice(nodes_to_be_compromised) - - # For each of the nodes to be compromised decide which step they become compromised - max_step_compromised = self.episode_steps // 2 # always compromise in first half of episode - - # Bandwidth for all links - bandwidths = [i.get_bandwidth() for i in list(self.links.values())] - - if len(bandwidths) < 1: - msg = "Random red agent cannot be used on a network without any links" - _LOGGER.error(msg) - raise Exception(msg) - - servers = [node for node in node_list if node.node_type == NodeType.SERVER] - - for n, node in enumerate(nodes_to_be_compromised): - # 1: Use Node PoL to set node to compromised - - _id = str(uuid.uuid4()) - _start_step = randint(2, max_step_compromised + 1) # step compromised - pol_service_name = choice(list(node.services.keys())) - - source_node_service = choice(list(source_node.services.values())) - - red_pol = NodeStateInstructionRed( - _id=_id, - _start_step=_start_step, - _end_step=_start_step, # only run for 1 step - _target_node_id=node.node_id, - _pol_initiator="DIRECT", - _pol_type=NodePOLType["SERVICE"], - pol_protocol=pol_service_name, - _pol_state=SoftwareState.COMPROMISED, - _pol_source_node_id=source_node.node_id, - _pol_source_node_service=source_node_service.name, - _pol_source_node_service_state=source_node_service.software_state, - ) - - self.red_node_pol[_id] = red_pol - - # 2: Launch the attack from compromised node - set the IER - - ier_id = str(uuid.uuid4()) - # Launch the attack after node is compromised, and not right at the end of the episode - ier_start_step = randint(_start_step + 2, int(self.episode_steps * 0.8)) - ier_end_step = self.episode_steps - - # Randomise the load, as a percentage of a random link bandwith - ier_load = uniform(0.4, 0.8) * choice(bandwidths) - ier_protocol = pol_service_name # Same protocol as compromised node - ier_service = node.services[pol_service_name] - ier_port = ier_service.port - ier_mission_criticality = 0 # Red IER will never be important to green agent success - # We choose a node to attack based on the first that applies: - # a. Green IERs, select dest node of the red ier based on dest node of green IER - # b. Attack a random server that doesn't have a DENY acl rule in default config - # c. Attack a random server - possible_ier_destinations = [ - ier.get_dest_node_id() - for ier in list(self.green_iers.values()) - if ier.get_source_node_id() == node.node_id - ] - if len(possible_ier_destinations) < 1: - for server in servers: - if not self.acl.is_blocked( - node.ip_address, - server.ip_address, - ier_service, - ier_port, - ): - possible_ier_destinations.append(server.node_id) - if len(possible_ier_destinations) < 1: - # If still none found choose from all servers - possible_ier_destinations = [server.node_id for server in servers] - ier_dest = choice(possible_ier_destinations) - self.red_iers[ier_id] = IER( - ier_id, - ier_start_step, - ier_end_step, - ier_load, - ier_protocol, - ier_port, - node.node_id, - ier_dest, - ier_mission_criticality, - ) - - overwhelm_pol = red_pol - overwhelm_pol.id = str(uuid.uuid4()) - overwhelm_pol.end_step = self.episode_steps - - # 3: Make sure the targetted node can be set to overwhelmed - with node pol - # # TODO remove duplicate red pol for same targetted service - must take into account start step - - o_pol_id = str(uuid.uuid4()) - o_red_pol = NodeStateInstructionRed( - _id=o_pol_id, - _start_step=ier_start_step, - _end_step=self.episode_steps, - _target_node_id=ier_dest, - _pol_initiator="DIRECT", - _pol_type=NodePOLType["SERVICE"], - pol_protocol=ier_protocol, - _pol_state=SoftwareState.OVERWHELMED, - _pol_source_node_id=source_node.node_id, - _pol_source_node_service=source_node_service.name, - _pol_source_node_service_state=source_node_service.software_state, - ) - self.red_node_pol[o_pol_id] = o_red_pol diff --git a/src/primaite/environment/reward.py b/src/primaite/environment/reward.py deleted file mode 100644 index aa9dc97d..00000000 --- a/src/primaite/environment/reward.py +++ /dev/null @@ -1,386 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Implements reward function.""" -from logging import Logger -from typing import Dict, TYPE_CHECKING, Union - -from primaite import getLogger -from primaite.common.custom_typing import NodeUnion -from primaite.common.enums import FileSystemState, HardwareState, SoftwareState -from primaite.common.service import Service -from primaite.nodes.active_node import ActiveNode -from primaite.nodes.service_node import ServiceNode - -if TYPE_CHECKING: - from primaite.config.training_config import TrainingConfig - from primaite.pol.ier import IER - -_LOGGER: Logger = getLogger(__name__) - - -def calculate_reward_function( - initial_nodes: Dict[str, NodeUnion], - final_nodes: Dict[str, NodeUnion], - reference_nodes: Dict[str, NodeUnion], - green_iers: Dict[str, "IER"], - green_iers_reference: Dict[str, "IER"], - red_iers: Dict[str, "IER"], - step_count: int, - config_values: "TrainingConfig", -) -> float: - """ - Compares the states of the initial and final nodes/links to get a reward. - - Args: - initial_nodes: The nodes before red and blue agents take effect - final_nodes: The nodes after red and blue agents take effect - reference_nodes: The nodes if there had been no red or blue effect - green_iers: The green IERs (should be running) - red_iers: Should be stopeed (ideally) by the blue agent - step_count: current step - config_values: Config values - """ - reward_value: float = 0.0 - - # For each node, compare hardware state, SoftwareState, service states - for node_key, final_node in final_nodes.items(): - initial_node = initial_nodes[node_key] - reference_node = reference_nodes[node_key] - - # Hardware State - reward_value += score_node_operating_state(final_node, initial_node, reference_node, config_values) - - # Software State - if isinstance(final_node, ActiveNode) or isinstance(final_node, ServiceNode): - reward_value += score_node_os_state(final_node, initial_node, reference_node, config_values) - - # Service State - if isinstance(final_node, ServiceNode): - reward_value += score_node_service_state(final_node, initial_node, reference_node, config_values) - - # File System State - if isinstance(final_node, ActiveNode): - reward_value += score_node_file_system(final_node, initial_node, reference_node, config_values) - - # Go through each red IER - penalise if it is running - for ier_key, ier_value in red_iers.items(): - start_step = ier_value.get_start_step() - stop_step = ier_value.get_end_step() - if step_count >= start_step and step_count <= stop_step: - if ier_value.get_is_running(): - reward_value += config_values.red_ier_running - - # Go through each green IER - penalise if it's not running (weighted) - # but only if it's supposed to be running (it's running in reference) - for ier_key, ier_value in green_iers.items(): - reference_ier = green_iers_reference[ier_key] - start_step = ier_value.get_start_step() - stop_step = ier_value.get_end_step() - if step_count >= start_step and step_count <= stop_step: - reference_blocked = not reference_ier.get_is_running() - live_blocked = not ier_value.get_is_running() - ier_reward = config_values.green_ier_blocked * ier_value.get_mission_criticality() - - if live_blocked and not reference_blocked: - reward_value += ier_reward - elif live_blocked and reference_blocked: - _LOGGER.debug( - ( - f"IER {ier_key} is blocked in the reference and live environments. " - f"Penalty of {ier_reward} was NOT applied." - ) - ) - elif not live_blocked and reference_blocked: - _LOGGER.debug( - ( - f"IER {ier_key} is blocked in the reference env but not in the live one. " - f"Penalty of {ier_reward} was NOT applied." - ) - ) - return reward_value - - -def score_node_operating_state( - final_node: NodeUnion, initial_node: NodeUnion, reference_node: NodeUnion, config_values: "TrainingConfig" -) -> float: - """ - Calculates score relating to the hardware state of a node. - - Args: - final_node: The node after red and blue agents take effect - initial_node: The node before red and blue agents take effect - reference_node: The node if there had been no red or blue effect - config_values: Config values - """ - score: float = 0.0 - final_node_operating_state = final_node.hardware_state - reference_node_operating_state = reference_node.hardware_state - - if final_node_operating_state == reference_node_operating_state: - # All is well - we're no different from the reference situation - score += config_values.all_ok - else: - # We're different from the reference situation - # Need to compare reference and final (current) state of node (i.e. at every step) - if reference_node_operating_state == HardwareState.ON: - if final_node_operating_state == HardwareState.OFF: - score += config_values.off_should_be_on - elif final_node_operating_state == HardwareState.RESETTING: - score += config_values.resetting_should_be_on - else: - pass - elif reference_node_operating_state == HardwareState.OFF: - if final_node_operating_state == HardwareState.ON: - score += config_values.on_should_be_off - elif final_node_operating_state == HardwareState.RESETTING: - score += config_values.resetting_should_be_off - else: - pass - elif reference_node_operating_state == HardwareState.RESETTING: - if final_node_operating_state == HardwareState.ON: - score += config_values.on_should_be_resetting - elif final_node_operating_state == HardwareState.OFF: - score += config_values.off_should_be_resetting - elif final_node_operating_state == HardwareState.RESETTING: - score += config_values.resetting - else: - pass - else: - pass - - return score - - -def score_node_os_state( - final_node: Union[ActiveNode, ServiceNode], - initial_node: Union[ActiveNode, ServiceNode], - reference_node: Union[ActiveNode, ServiceNode], - config_values: "TrainingConfig", -) -> float: - """ - Calculates score relating to the Software State of a node. - - Args: - final_node: The node after red and blue agents take effect - initial_node: The node before red and blue agents take effect - reference_node: The node if there had been no red or blue effect - config_values: Config values - """ - score: float = 0.0 - final_node_os_state = final_node.software_state - reference_node_os_state = reference_node.software_state - - if final_node_os_state == reference_node_os_state: - # All is well - we're no different from the reference situation - score += config_values.all_ok - else: - # We're different from the reference situation - # Need to compare reference and final (current) state of node (i.e. at every step) - if reference_node_os_state == SoftwareState.GOOD: - if final_node_os_state == SoftwareState.PATCHING: - score += config_values.patching_should_be_good - elif final_node_os_state == SoftwareState.COMPROMISED: - score += config_values.compromised_should_be_good - else: - pass - elif reference_node_os_state == SoftwareState.PATCHING: - if final_node_os_state == SoftwareState.GOOD: - score += config_values.good_should_be_patching - elif final_node_os_state == SoftwareState.COMPROMISED: - score += config_values.compromised_should_be_patching - elif final_node_os_state == SoftwareState.PATCHING: - score += config_values.patching - else: - pass - elif reference_node_os_state == SoftwareState.COMPROMISED: - if final_node_os_state == SoftwareState.GOOD: - score += config_values.good_should_be_compromised - elif final_node_os_state == SoftwareState.PATCHING: - score += config_values.patching_should_be_compromised - elif final_node_os_state == SoftwareState.COMPROMISED: - score += config_values.compromised - else: - pass - else: - pass - - return score - - -def score_node_service_state( - final_node: ServiceNode, initial_node: ServiceNode, reference_node: ServiceNode, config_values: "TrainingConfig" -) -> float: - """ - Calculates score relating to the service state(s) of a node. - - Args: - final_node: The node after red and blue agents take effect - initial_node: The node before red and blue agents take effect - reference_node: The node if there had been no red or blue effect - config_values: Config values - """ - score: float = 0.0 - final_node_services: Dict[str, Service] = final_node.services - reference_node_services: Dict[str, Service] = reference_node.services - - for service_key, final_service in final_node_services.items(): - reference_service = reference_node_services[service_key] - final_service = final_node_services[service_key] - - if final_service.software_state == reference_service.software_state: - # All is well - we're no different from the reference situation - score += config_values.all_ok - else: - # We're different from the reference situation - # Need to compare reference and final state of node (i.e. at every step) - if reference_service.software_state == SoftwareState.GOOD: - if final_service.software_state == SoftwareState.PATCHING: - score += config_values.patching_should_be_good - elif final_service.software_state == SoftwareState.COMPROMISED: - score += config_values.compromised_should_be_good - elif final_service.software_state == SoftwareState.OVERWHELMED: - score += config_values.overwhelmed_should_be_good - else: - pass - elif reference_service.software_state == SoftwareState.PATCHING: - if final_service.software_state == SoftwareState.GOOD: - score += config_values.good_should_be_patching - elif final_service.software_state == SoftwareState.COMPROMISED: - score += config_values.compromised_should_be_patching - elif final_service.software_state == SoftwareState.OVERWHELMED: - score += config_values.overwhelmed_should_be_patching - elif final_service.software_state == SoftwareState.PATCHING: - score += config_values.patching - else: - pass - elif reference_service.software_state == SoftwareState.COMPROMISED: - if final_service.software_state == SoftwareState.GOOD: - score += config_values.good_should_be_compromised - elif final_service.software_state == SoftwareState.PATCHING: - score += config_values.patching_should_be_compromised - elif final_service.software_state == SoftwareState.COMPROMISED: - score += config_values.compromised - elif final_service.software_state == SoftwareState.OVERWHELMED: - score += config_values.overwhelmed_should_be_compromised - else: - pass - elif reference_service.software_state == SoftwareState.OVERWHELMED: - if final_service.software_state == SoftwareState.GOOD: - score += config_values.good_should_be_overwhelmed - elif final_service.software_state == SoftwareState.PATCHING: - score += config_values.patching_should_be_overwhelmed - elif final_service.software_state == SoftwareState.COMPROMISED: - score += config_values.compromised_should_be_overwhelmed - elif final_service.software_state == SoftwareState.OVERWHELMED: - score += config_values.overwhelmed - else: - pass - else: - pass - - return score - - -def score_node_file_system( - final_node: Union[ActiveNode, ServiceNode], - initial_node: Union[ActiveNode, ServiceNode], - reference_node: Union[ActiveNode, ServiceNode], - config_values: "TrainingConfig", -) -> float: - """ - Calculates score relating to the file system state of a node. - - Args: - final_node: The node after red and blue agents take effect - initial_node: The node before red and blue agents take effect - reference_node: The node if there had been no red or blue effect - """ - score: float = 0.0 - final_node_file_system_state = final_node.file_system_state_actual - reference_node_file_system_state = reference_node.file_system_state_actual - - final_node_scanning_state = final_node.file_system_scanning - reference_node_scanning_state = reference_node.file_system_scanning - - # File System State - if final_node_file_system_state == reference_node_file_system_state: - # All is well - we're no different from the reference situation - score += config_values.all_ok - else: - # We're different from the reference situation - # Need to compare reference and final state of node (i.e. at every step) - if reference_node_file_system_state == FileSystemState.GOOD: - if final_node_file_system_state == FileSystemState.REPAIRING: - score += config_values.repairing_should_be_good - elif final_node_file_system_state == FileSystemState.RESTORING: - score += config_values.restoring_should_be_good - elif final_node_file_system_state == FileSystemState.CORRUPT: - score += config_values.corrupt_should_be_good - elif final_node_file_system_state == FileSystemState.DESTROYED: - score += config_values.destroyed_should_be_good - else: - pass - elif reference_node_file_system_state == FileSystemState.REPAIRING: - if final_node_file_system_state == FileSystemState.GOOD: - score += config_values.good_should_be_repairing - elif final_node_file_system_state == FileSystemState.RESTORING: - score += config_values.restoring_should_be_repairing - elif final_node_file_system_state == FileSystemState.CORRUPT: - score += config_values.corrupt_should_be_repairing - elif final_node_file_system_state == FileSystemState.DESTROYED: - score += config_values.destroyed_should_be_repairing - elif final_node_file_system_state == FileSystemState.REPAIRING: - score += config_values.repairing - else: - pass - elif reference_node_file_system_state == FileSystemState.RESTORING: - if final_node_file_system_state == FileSystemState.GOOD: - score += config_values.good_should_be_restoring - elif final_node_file_system_state == FileSystemState.REPAIRING: - score += config_values.repairing_should_be_restoring - elif final_node_file_system_state == FileSystemState.CORRUPT: - score += config_values.corrupt_should_be_restoring - elif final_node_file_system_state == FileSystemState.DESTROYED: - score += config_values.destroyed_should_be_restoring - elif final_node_file_system_state == FileSystemState.RESTORING: - score += config_values.restoring - else: - pass - elif reference_node_file_system_state == FileSystemState.CORRUPT: - if final_node_file_system_state == FileSystemState.GOOD: - score += config_values.good_should_be_corrupt - elif final_node_file_system_state == FileSystemState.REPAIRING: - score += config_values.repairing_should_be_corrupt - elif final_node_file_system_state == FileSystemState.RESTORING: - score += config_values.restoring_should_be_corrupt - elif final_node_file_system_state == FileSystemState.DESTROYED: - score += config_values.destroyed_should_be_corrupt - elif final_node_file_system_state == FileSystemState.CORRUPT: - score += config_values.corrupt - else: - pass - elif reference_node_file_system_state == FileSystemState.DESTROYED: - if final_node_file_system_state == FileSystemState.GOOD: - score += config_values.good_should_be_destroyed - elif final_node_file_system_state == FileSystemState.REPAIRING: - score += config_values.repairing_should_be_destroyed - elif final_node_file_system_state == FileSystemState.RESTORING: - score += config_values.restoring_should_be_destroyed - elif final_node_file_system_state == FileSystemState.CORRUPT: - score += config_values.corrupt_should_be_destroyed - elif final_node_file_system_state == FileSystemState.DESTROYED: - score += config_values.destroyed - else: - pass - else: - pass - - # Scanning State - if final_node_scanning_state == reference_node_scanning_state: - # All is well - we're no different from the reference situation - score += config_values.all_ok - else: - # We're different from the reference situation - # We're scanning the file system which incurs a penalty (as it slows down systems) - score += config_values.scanning - - return score diff --git a/src/primaite/links/__init__.py b/src/primaite/links/__init__.py deleted file mode 100644 index c91b6951..00000000 --- a/src/primaite/links/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Network connections between nodes in the simulation.""" diff --git a/src/primaite/links/link.py b/src/primaite/links/link.py deleted file mode 100644 index 3830a15b..00000000 --- a/src/primaite/links/link.py +++ /dev/null @@ -1,114 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""The link class.""" -from typing import List - -from primaite.common.protocol import Protocol - - -class Link(object): - """Link class.""" - - def __init__(self, _id: str, _bandwidth: int, _source_node_name: str, _dest_node_name: str, _services: str) -> None: - """ - Initialise a Link within the simulated network. - - :param _id: The IER id - :param _bandwidth: The bandwidth of the link (bps) - :param _source_node_name: The name of the source node - :param _dest_node_name: The name of the destination node - :param _protocols: The protocols to add to the link - """ - self.id: str = _id - self.bandwidth: int = _bandwidth - self.source_node_name: str = _source_node_name - self.dest_node_name: str = _dest_node_name - self.protocol_list: List[Protocol] = [] - - # Add the default protocols - for protocol_name in _services: - self.add_protocol(protocol_name) - - def add_protocol(self, _protocol: str) -> None: - """ - Adds a new protocol to the list of protocols on this link. - - Args: - _protocol: The protocol to be added (enum) - """ - self.protocol_list.append(Protocol(_protocol)) - - def get_id(self) -> str: - """ - Gets link ID. - - Returns: - Link ID - """ - return self.id - - def get_source_node_name(self) -> str: - """ - Gets source node name. - - Returns: - Source node name - """ - return self.source_node_name - - def get_dest_node_name(self) -> str: - """ - Gets destination node name. - - Returns: - Destination node name - """ - return self.dest_node_name - - def get_bandwidth(self) -> int: - """ - Gets bandwidth of link. - - Returns: - Link bandwidth (bps) - """ - return self.bandwidth - - def get_protocol_list(self) -> List[Protocol]: - """ - Gets list of protocols on this link. - - Returns: - List of protocols on this link - """ - return self.protocol_list - - def get_current_load(self) -> int: - """ - Gets current total load on this link. - - Returns: - Total load on this link (bps) - """ - total_load = 0 - for protocol in self.protocol_list: - total_load += protocol.get_load() - return total_load - - def add_protocol_load(self, _protocol: str, _load: int) -> None: - """ - Adds a loading to a protocol on this link. - - Args: - _protocol: The protocol to load - _load: The amount to load (bps) - """ - for protocol in self.protocol_list: - if protocol.get_name() == _protocol: - protocol.add_load(_load) - else: - pass - - def clear_traffic(self) -> None: - """Clears all traffic on this link.""" - for protocol in self.protocol_list: - protocol.clear_load() diff --git a/src/primaite/nodes/__init__.py b/src/primaite/nodes/__init__.py deleted file mode 100644 index 231b8d92..00000000 --- a/src/primaite/nodes/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Nodes represent network hosts in the simulation.""" diff --git a/src/primaite/nodes/active_node.py b/src/primaite/nodes/active_node.py deleted file mode 100644 index 8f472e86..00000000 --- a/src/primaite/nodes/active_node.py +++ /dev/null @@ -1,208 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""An Active Node (i.e. not an actuator).""" -import logging -from typing import Final - -from primaite.common.enums import FileSystemState, HardwareState, NodeType, Priority, SoftwareState -from primaite.config.training_config import TrainingConfig -from primaite.nodes.node import Node - -_LOGGER: Final[logging.Logger] = logging.getLogger(__name__) - - -class ActiveNode(Node): - """Active Node class.""" - - def __init__( - self, - node_id: str, - name: str, - node_type: NodeType, - priority: Priority, - hardware_state: HardwareState, - ip_address: str, - software_state: SoftwareState, - file_system_state: FileSystemState, - config_values: TrainingConfig, - ) -> None: - """ - Initialise an active node. - - :param node_id: The node ID - :param name: The node name - :param node_type: The node type (enum) - :param priority: The node priority (enum) - :param hardware_state: The node Hardware State - :param ip_address: The node IP address - :param software_state: The node Software State - :param file_system_state: The node file system state - :param config_values: The config values - """ - super().__init__(node_id, name, node_type, priority, hardware_state, config_values) - self.ip_address: str = ip_address - # Related to Software - self._software_state: SoftwareState = software_state - self.patching_count: int = 0 - # Related to File System - self.file_system_state_actual: FileSystemState = file_system_state - self.file_system_state_observed: FileSystemState = file_system_state - self.file_system_scanning: bool = False - self.file_system_scanning_count: int = 0 - self.file_system_action_count: int = 0 - - @property - def software_state(self) -> SoftwareState: - """ - Get the software_state. - - :return: The software_state. - """ - return self._software_state - - @software_state.setter - def software_state(self, software_state: SoftwareState) -> None: - """ - Get the software_state. - - :param software_state: Software State. - """ - if self.hardware_state != HardwareState.OFF: - self._software_state = software_state - if software_state == SoftwareState.PATCHING: - self.patching_count = self.config_values.os_patching_duration - else: - _LOGGER.info( - f"The Nodes hardware state is OFF so OS State cannot be " - f"changed. " - f"Node.node_id:{self.node_id}, " - f"Node.hardware_state:{self.hardware_state}, " - f"Node.software_state:{self._software_state}" - ) - - def set_software_state_if_not_compromised(self, software_state: SoftwareState) -> None: - """ - Sets Software State if the node is not compromised. - - Args: - software_state: Software State - """ - if self.hardware_state != HardwareState.OFF: - if self._software_state != SoftwareState.COMPROMISED: - self._software_state = software_state - if software_state == SoftwareState.PATCHING: - self.patching_count = self.config_values.os_patching_duration - else: - _LOGGER.info( - f"The Nodes hardware state is OFF so OS State cannot be changed." - f"Node.node_id:{self.node_id}, " - f"Node.hardware_state:{self.hardware_state}, " - f"Node.software_state:{self._software_state}" - ) - - def update_os_patching_status(self) -> None: - """Updates operating system status based on patching cycle.""" - self.patching_count -= 1 - if self.patching_count <= 0: - self.patching_count = 0 - self._software_state = SoftwareState.GOOD - - def set_file_system_state(self, file_system_state: FileSystemState) -> None: - """ - Sets the file system state (actual and observed). - - Args: - file_system_state: File system state - """ - if self.hardware_state != HardwareState.OFF: - self.file_system_state_actual = file_system_state - - if file_system_state == FileSystemState.REPAIRING: - self.file_system_action_count = self.config_values.file_system_repairing_limit - self.file_system_state_observed = FileSystemState.REPAIRING - elif file_system_state == FileSystemState.RESTORING: - self.file_system_action_count = self.config_values.file_system_restoring_limit - self.file_system_state_observed = FileSystemState.RESTORING - elif file_system_state == FileSystemState.GOOD: - self.file_system_state_observed = FileSystemState.GOOD - else: - _LOGGER.info( - f"The Nodes hardware state is OFF so File System State " - f"cannot be changed. " - f"Node.node_id:{self.node_id}, " - f"Node.hardware_state:{self.hardware_state}, " - f"Node.file_system_state.actual:{self.file_system_state_actual}" - ) - - def set_file_system_state_if_not_compromised(self, file_system_state: FileSystemState) -> None: - """ - Sets the file system state (actual and observed) if not in a compromised state. - - Use for green PoL to prevent it overturning a compromised state - - Args: - file_system_state: File system state - """ - if self.hardware_state != HardwareState.OFF: - if ( - self.file_system_state_actual != FileSystemState.CORRUPT - and self.file_system_state_actual != FileSystemState.DESTROYED - ): - self.file_system_state_actual = file_system_state - - if file_system_state == FileSystemState.REPAIRING: - self.file_system_action_count = self.config_values.file_system_repairing_limit - self.file_system_state_observed = FileSystemState.REPAIRING - elif file_system_state == FileSystemState.RESTORING: - self.file_system_action_count = self.config_values.file_system_restoring_limit - self.file_system_state_observed = FileSystemState.RESTORING - elif file_system_state == FileSystemState.GOOD: - self.file_system_state_observed = FileSystemState.GOOD - else: - _LOGGER.info( - f"The Nodes hardware state is OFF so File System State (if not " - f"compromised) cannot be changed. " - f"Node.node_id:{self.node_id}, " - f"Node.hardware_state:{self.hardware_state}, " - f"Node.file_system_state.actual:{self.file_system_state_actual}" - ) - - def start_file_system_scan(self) -> None: - """Starts a file system scan.""" - self.file_system_scanning = True - self.file_system_scanning_count = self.config_values.file_system_scanning_limit - - def update_file_system_state(self) -> None: - """Updates file system status based on scanning/restore/repair cycle.""" - # Deprecate both the action count (for restoring or reparing) and the scanning count - self.file_system_action_count -= 1 - self.file_system_scanning_count -= 1 - - # Reparing / Restoring updates - if self.file_system_action_count <= 0: - self.file_system_action_count = 0 - if ( - self.file_system_state_actual == FileSystemState.REPAIRING - or self.file_system_state_actual == FileSystemState.RESTORING - ): - self.file_system_state_actual = FileSystemState.GOOD - self.file_system_state_observed = FileSystemState.GOOD - - # Scanning updates - if self.file_system_scanning == True and self.file_system_scanning_count < 0: - self.file_system_state_observed = self.file_system_state_actual - self.file_system_scanning = False - self.file_system_scanning_count = 0 - - def update_resetting_status(self) -> None: - """Updates the reset count & makes software and file state to GOOD.""" - super().update_resetting_status() - if self.resetting_count <= 0: - self.file_system_state_actual = FileSystemState.GOOD - self.software_state = SoftwareState.GOOD - - def update_booting_status(self) -> None: - """Updates the booting software and file state to GOOD.""" - super().update_booting_status() - if self.booting_count <= 0: - self.file_system_state_actual = FileSystemState.GOOD - self.software_state = SoftwareState.GOOD diff --git a/src/primaite/nodes/node.py b/src/primaite/nodes/node.py deleted file mode 100644 index fc4d41d3..00000000 --- a/src/primaite/nodes/node.py +++ /dev/null @@ -1,79 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""The base Node class.""" -from typing import Final - -from primaite.common.enums import HardwareState, NodeType, Priority -from primaite.config.training_config import TrainingConfig - - -class Node: - """Node class.""" - - def __init__( - self, - node_id: str, - name: str, - node_type: NodeType, - priority: Priority, - hardware_state: HardwareState, - config_values: TrainingConfig, - ) -> None: - """ - Initialise a node. - - :param node_id: The node id. - :param name: The name of the node. - :param node_type: The type of the node. - :param priority: The priority of the node. - :param hardware_state: The state of the node. - :param config_values: Config values. - """ - self.node_id: Final[str] = node_id - self.name: Final[str] = name - self.node_type: Final[NodeType] = node_type - self.priority = priority - self.hardware_state: HardwareState = hardware_state - self.resetting_count: int = 0 - self.config_values: TrainingConfig = config_values - self.booting_count: int = 0 - self.shutting_down_count: int = 0 - - def __repr__(self) -> str: - """Returns the name of the node.""" - return self.name - - def turn_on(self) -> None: - """Sets the node state to ON.""" - self.hardware_state = HardwareState.BOOTING - self.booting_count = self.config_values.node_booting_duration - - def turn_off(self) -> None: - """Sets the node state to OFF.""" - self.hardware_state = HardwareState.OFF - self.shutting_down_count = self.config_values.node_shutdown_duration - - def reset(self) -> None: - """Sets the node state to Resetting and starts the reset count.""" - self.hardware_state = HardwareState.RESETTING - self.resetting_count = self.config_values.node_reset_duration - - def update_resetting_status(self) -> None: - """Updates the resetting count.""" - self.resetting_count -= 1 - if self.resetting_count <= 0: - self.resetting_count = 0 - self.hardware_state = HardwareState.ON - - def update_booting_status(self) -> None: - """Updates the booting count.""" - self.booting_count -= 1 - if self.booting_count <= 0: - self.booting_count = 0 - self.hardware_state = HardwareState.ON - - def update_shutdown_status(self) -> None: - """Updates the shutdown count.""" - self.shutting_down_count -= 1 - if self.shutting_down_count <= 0: - self.shutting_down_count = 0 - self.hardware_state = HardwareState.OFF diff --git a/src/primaite/nodes/node_state_instruction_green.py b/src/primaite/nodes/node_state_instruction_green.py deleted file mode 100644 index 6e35d0ec..00000000 --- a/src/primaite/nodes/node_state_instruction_green.py +++ /dev/null @@ -1,94 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Defines node behaviour for Green PoL.""" -from typing import TYPE_CHECKING, Union - -if TYPE_CHECKING: - from primaite.common.enums import FileSystemState, HardwareState, NodePOLType, SoftwareState - - -class NodeStateInstructionGreen(object): - """The Node State Instruction class.""" - - def __init__( - self, - _id: str, - _start_step: int, - _end_step: int, - _node_id: str, - _node_pol_type: "NodePOLType", - _service_name: str, - _state: Union["HardwareState", "SoftwareState", "FileSystemState"], - ) -> None: - """ - Initialise the Node State Instruction. - - :param _id: The node state instruction id - :param _start_step: The start step of the instruction - :param _end_step: The end step of the instruction - :param _node_id: The id of the associated node - :param _node_pol_type: The pattern of life type - :param _service_name: The service name - :param _state: The state (node or service) - """ - self.id = _id - self.start_step = _start_step - self.end_step = _end_step - self.node_id = _node_id - self.node_pol_type: "NodePOLType" = _node_pol_type - self.service_name: str = _service_name # Not used when not a service instruction - # TODO: confirm type of state - self.state: Union["HardwareState", "SoftwareState", "FileSystemState"] = _state - - def get_start_step(self) -> int: - """ - Gets the start step. - - Returns: - The start step - """ - return self.start_step - - def get_end_step(self) -> int: - """ - Gets the end step. - - Returns: - The end step - """ - return self.end_step - - def get_node_id(self) -> str: - """ - Gets the node ID. - - Returns: - The node ID - """ - return self.node_id - - def get_node_pol_type(self) -> "NodePOLType": - """ - Gets the node pattern of life type (enum). - - Returns: - The node pattern of life type (enum) - """ - return self.node_pol_type - - def get_service_name(self) -> str: - """ - Gets the service name. - - Returns: - The service name - """ - return self.service_name - - def get_state(self) -> Union["HardwareState", "SoftwareState", "FileSystemState"]: - """ - Gets the state (node or service). - - Returns: - The state (node or service) - """ - return self.state diff --git a/src/primaite/nodes/node_state_instruction_red.py b/src/primaite/nodes/node_state_instruction_red.py deleted file mode 100644 index eb87924b..00000000 --- a/src/primaite/nodes/node_state_instruction_red.py +++ /dev/null @@ -1,143 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Defines node behaviour for Green PoL.""" -from typing import TYPE_CHECKING, Union - -from primaite.common.enums import NodePOLType - -if TYPE_CHECKING: - from primaite.common.enums import FileSystemState, HardwareState, NodePOLInitiator, SoftwareState - - -class NodeStateInstructionRed: - """The Node State Instruction class.""" - - def __init__( - self, - _id: str, - _start_step: int, - _end_step: int, - _target_node_id: str, - _pol_initiator: "NodePOLInitiator", - _pol_type: NodePOLType, - pol_protocol: str, - _pol_state: Union["HardwareState", "SoftwareState", "FileSystemState"], - _pol_source_node_id: str, - _pol_source_node_service: str, - _pol_source_node_service_state: str, - ) -> None: - """ - Initialise the Node State Instruction for the red agent. - - :param _id: The node state instruction id - :param _start_step: The start step of the instruction - :param _end_step: The end step of the instruction - :param _target_node_id: The id of the associated node - :param -pol_initiator: The way the PoL is applied (DIRECT, IER or SERVICE) - :param _pol_type: The pattern of life type - :param pol_protocol: The pattern of life protocol/service affected - :param _pol_state: The state (node or service) - :param _pol_source_node_id: The source node Id (used for initiator type SERVICE) - :param _pol_source_node_service: The source node service (used for initiator type SERVICE) - :param _pol_source_node_service_state: The source node service state (used for initiator type SERVICE) - """ - self.id: str = _id - self.start_step: int = _start_step - self.end_step: int = _end_step - self.target_node_id: str = _target_node_id - self.initiator: "NodePOLInitiator" = _pol_initiator - self.pol_type: NodePOLType = _pol_type - self.service_name: str = pol_protocol # Not used when not a service instruction - self.state: Union["HardwareState", "SoftwareState", "FileSystemState"] = _pol_state - self.source_node_id: str = _pol_source_node_id - self.source_node_service: str = _pol_source_node_service - self.source_node_service_state = _pol_source_node_service_state - - def get_start_step(self) -> int: - """ - Gets the start step. - - Returns: - The start step - """ - return self.start_step - - def get_end_step(self) -> int: - """ - Gets the end step. - - Returns: - The end step - """ - return self.end_step - - def get_target_node_id(self) -> str: - """ - Gets the node ID. - - Returns: - The node ID - """ - return self.target_node_id - - def get_initiator(self) -> "NodePOLInitiator": - """ - Gets the initiator. - - Returns: - The initiator - """ - return self.initiator - - def get_pol_type(self) -> NodePOLType: - """ - Gets the node pattern of life type (enum). - - Returns: - The node pattern of life type (enum) - """ - return self.pol_type - - def get_service_name(self) -> str: - """ - Gets the service name. - - Returns: - The service name - """ - return self.service_name - - def get_state(self) -> Union["HardwareState", "SoftwareState", "FileSystemState"]: - """ - Gets the state (node or service). - - Returns: - The state (node or service) - """ - return self.state - - def get_source_node_id(self) -> str: - """ - Gets the source node id (used for initiator type SERVICE). - - Returns: - The source node id - """ - return self.source_node_id - - def get_source_node_service(self) -> str: - """ - Gets the source node service (used for initiator type SERVICE). - - Returns: - The source node service - """ - return self.source_node_service - - def get_source_node_service_state(self) -> str: - """ - Gets the source node service state (used for initiator type SERVICE). - - Returns: - The source node service state - """ - return self.source_node_service_state diff --git a/src/primaite/nodes/passive_node.py b/src/primaite/nodes/passive_node.py deleted file mode 100644 index 08dcbfa2..00000000 --- a/src/primaite/nodes/passive_node.py +++ /dev/null @@ -1,42 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""The Passive Node class (i.e. an actuator).""" -from primaite.common.enums import HardwareState, NodeType, Priority -from primaite.config.training_config import TrainingConfig -from primaite.nodes.node import Node - - -class PassiveNode(Node): - """The Passive Node class.""" - - def __init__( - self, - node_id: str, - name: str, - node_type: NodeType, - priority: Priority, - hardware_state: HardwareState, - config_values: TrainingConfig, - ) -> None: - """ - Initialise a passive node. - - :param node_id: The node id. - :param name: The name of the node. - :param node_type: The type of the node. - :param priority: The priority of the node. - :param hardware_state: The state of the node. - :param config_values: Config values. - """ - # Pass through to Super for now - super().__init__(node_id, name, node_type, priority, hardware_state, config_values) - - @property - def ip_address(self) -> str: - """ - Gets the node IP address as an empty string. - - No concept of IP address for passive nodes for now. - - :return: The node IP address. - """ - return "" diff --git a/src/primaite/nodes/service_node.py b/src/primaite/nodes/service_node.py deleted file mode 100644 index b0d42785..00000000 --- a/src/primaite/nodes/service_node.py +++ /dev/null @@ -1,190 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""A Service Node (i.e. not an actuator).""" -import logging -from typing import Dict, Final - -from primaite.common.enums import FileSystemState, HardwareState, NodeType, Priority, SoftwareState -from primaite.common.service import Service -from primaite.config.training_config import TrainingConfig -from primaite.nodes.active_node import ActiveNode - -_LOGGER: Final[logging.Logger] = logging.getLogger(__name__) - - -class ServiceNode(ActiveNode): - """ServiceNode class.""" - - def __init__( - self, - node_id: str, - name: str, - node_type: NodeType, - priority: Priority, - hardware_state: HardwareState, - ip_address: str, - software_state: SoftwareState, - file_system_state: FileSystemState, - config_values: TrainingConfig, - ) -> None: - """ - Initialise a Service Node. - - :param node_id: The node ID - :param name: The node name - :param node_type: The node type (enum) - :param priority: The node priority (enum) - :param hardware_state: The node Hardware State - :param ip_address: The node IP address - :param software_state: The node Software State - :param file_system_state: The node file system state - :param config_values: The config values - """ - super().__init__( - node_id, - name, - node_type, - priority, - hardware_state, - ip_address, - software_state, - file_system_state, - config_values, - ) - self.services: Dict[str, Service] = {} - - def add_service(self, service: Service) -> None: - """ - Adds a service to the node. - - :param service: The service to add - """ - self.services[service.name] = service - - def has_service(self, protocol_name: str) -> bool: - """ - Indicates whether a service is on a node. - - :param protocol_name: The service (protocol)e. - :return: True if service (protocol) is on the node, otherwise False. - """ - for service_key, service_value in self.services.items(): - if service_key == protocol_name: - return True - return False - - def service_running(self, protocol_name: str) -> bool: - """ - Indicates whether a service is in a running state on the node. - - :param protocol_name: The service (protocol) - :return: True if service (protocol) is in a running state on the node, otherwise False. - """ - for service_key, service_value in self.services.items(): - if service_key == protocol_name: - if service_value.software_state != SoftwareState.PATCHING: - return True - else: - return False - return False - - def service_is_overwhelmed(self, protocol_name: str) -> bool: - """ - Indicates whether a service is in an overwhelmed state on the node. - - :param protocol_name: The service (protocol) - :return: True if service (protocol) is in an overwhelmed state on the node, otherwise False. - """ - for service_key, service_value in self.services.items(): - if service_key == protocol_name: - if service_value.software_state == SoftwareState.OVERWHELMED: - return True - else: - return False - return False - - def set_service_state(self, protocol_name: str, software_state: SoftwareState) -> None: - """ - Sets the software_state of a service (protocol) on the node. - - :param protocol_name: The service (protocol). - :param software_state: The software_state. - """ - if self.hardware_state != HardwareState.OFF: - service_key = protocol_name - service_value = self.services.get(service_key) - if service_value: - # Can't set to compromised if you're in a patching state - if ( - software_state == SoftwareState.COMPROMISED - and service_value.software_state != SoftwareState.PATCHING - ) or software_state != SoftwareState.COMPROMISED: - service_value.software_state = software_state - if software_state == SoftwareState.PATCHING: - service_value.patching_count = self.config_values.service_patching_duration - else: - _LOGGER.info( - f"The Nodes hardware state is OFF so the state of a service " - f"cannot be changed. " - f"Node.node_id:{self.node_id}, " - f"Node.hardware_state:{self.hardware_state}, " - f"Node.services[]:{protocol_name}, " - f"Node.services[].software_state:{software_state}" - ) - - def set_service_state_if_not_compromised(self, protocol_name: str, software_state: SoftwareState) -> None: - """ - Sets the software_state of a service (protocol) on the node. - - Done if the software_state is not "compromised". - - :param protocol_name: The service (protocol). - :param software_state: The software_state. - """ - if self.hardware_state != HardwareState.OFF: - service_key = protocol_name - service_value = self.services.get(service_key) - if service_value: - if service_value.software_state != SoftwareState.COMPROMISED: - service_value.software_state = software_state - if software_state == SoftwareState.PATCHING: - service_value.patching_count = self.config_values.service_patching_duration - else: - _LOGGER.info( - f"The Nodes hardware state is OFF so the state of a service " - f"cannot be changed. " - f"Node.node_id:{self.node_id}, " - f"Node.hardware_state:{self.hardware_state}, " - f"Node.services[]:{protocol_name}, " - f"Node.services[].software_state:{software_state}" - ) - - def get_service_state(self, protocol_name: str) -> SoftwareState: - """ - Gets the state of a service. - - :return: The software_state of the service. - """ - service_key = protocol_name - service_value = self.services.get(service_key) - if service_value: - return service_value.software_state - - def update_services_patching_status(self) -> None: - """Updates the patching counter for any service that are patching.""" - for service_key, service_value in self.services.items(): - if service_value.software_state == SoftwareState.PATCHING: - service_value.reduce_patching_count() - - def update_resetting_status(self) -> None: - """Update resetting counter and set software state if it reached 0.""" - super().update_resetting_status() - if self.resetting_count <= 0: - for service in self.services.values(): - service.software_state = SoftwareState.GOOD - - def update_booting_status(self) -> None: - """Update booting counter and set software to good if it reached 0.""" - super().update_booting_status() - if self.booting_count <= 0: - for service in self.services.values(): - service.software_state = SoftwareState.GOOD diff --git a/src/primaite/pol/__init__.py b/src/primaite/pol/__init__.py deleted file mode 100644 index d0d9f616..00000000 --- a/src/primaite/pol/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Pattern of Life- Represents the actions of users on the network.""" diff --git a/src/primaite/pol/green_pol.py b/src/primaite/pol/green_pol.py deleted file mode 100644 index 814aa314..00000000 --- a/src/primaite/pol/green_pol.py +++ /dev/null @@ -1,264 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Implements Pattern of Life on the network (nodes and links).""" -from typing import Dict - -from networkx import MultiGraph, shortest_path - -from primaite.acl.access_control_list import AccessControlList -from primaite.common.custom_typing import NodeUnion -from primaite.common.enums import HardwareState, NodePOLType, NodeType, SoftwareState -from primaite.links.link import Link -from primaite.nodes.active_node import ActiveNode -from primaite.nodes.node_state_instruction_green import NodeStateInstructionGreen -from primaite.nodes.service_node import ServiceNode -from primaite.pol.ier import IER - -_VERBOSE: bool = False - - -def apply_iers( - network: MultiGraph, - nodes: Dict[str, NodeUnion], - links: Dict[str, Link], - iers: Dict[str, IER], - acl: AccessControlList, - step: int, -) -> None: - """ - Applies IERs to the links (link pattern of life). - - Args: - network: The network modelled in the environment - nodes: The nodes within the environment - links: The links within the environment - iers: The IERs to apply to the links - acl: The Access Control List - step: The step number. - """ - if _VERBOSE: - print("Applying IERs") - - # Go through each IER and check the conditions for it being applied - # If everything is in place, apply the IER protocol load to the relevant links - for ier_key, ier_value in iers.items(): - start_step = ier_value.get_start_step() - stop_step = ier_value.get_end_step() - protocol = ier_value.get_protocol() - port = ier_value.get_port() - load = ier_value.get_load() - source_node_id = ier_value.get_source_node_id() - dest_node_id = ier_value.get_dest_node_id() - - # Need to set the running status to false first for all IERs - ier_value.set_is_running(False) - - source_valid = True - dest_valid = True - acl_block = False - - if step >= start_step and step <= stop_step: - # continue -------------------------- - - # Get the source and destination node for this link - source_node = nodes[source_node_id] - dest_node = nodes[dest_node_id] - - # 1. Check the source node situation - # TODO: should be using isinstance rather than checking node type attribute. IE. just because it's a switch - # doesn't mean it has a software state? It could be a PassiveNode or ActiveNode - if source_node.node_type == NodeType.SWITCH: - # It's a switch - if ( - source_node.hardware_state == HardwareState.ON - and source_node.software_state != SoftwareState.PATCHING - ): - source_valid = True - else: - # IER no longer valid - source_valid = False - elif source_node.node_type == NodeType.ACTUATOR: - # It's an actuator - # TO DO - pass - else: - # It's not a switch or an actuator (so active node) - if ( - source_node.hardware_state == HardwareState.ON - and source_node.software_state != SoftwareState.PATCHING - ): - if source_node.has_service(protocol): - if source_node.service_running(protocol) and not source_node.service_is_overwhelmed(protocol): - source_valid = True - else: - source_valid = False - else: - # Do nothing - IER is not valid on this node - # (This shouldn't happen if the IER has been written correctly) - source_valid = False - else: - # Do nothing - IER no longer valid - source_valid = False - - # 2. Check the dest node situation - if dest_node.node_type == NodeType.SWITCH: - # It's a switch - if dest_node.hardware_state == HardwareState.ON and dest_node.software_state != SoftwareState.PATCHING: - dest_valid = True - else: - # IER no longer valid - dest_valid = False - elif dest_node.node_type == NodeType.ACTUATOR: - # It's an actuator - pass - else: - # It's not a switch or an actuator (so active node) - if dest_node.hardware_state == HardwareState.ON and dest_node.software_state != SoftwareState.PATCHING: - if dest_node.has_service(protocol): - if dest_node.service_running(protocol) and not dest_node.service_is_overwhelmed(protocol): - dest_valid = True - else: - dest_valid = False - else: - # Do nothing - IER is not valid on this node - # (This shouldn't happen if the IER has been written correctly) - dest_valid = False - else: - # Do nothing - IER no longer valid - dest_valid = False - - # 3. Check that the ACL doesn't block it - acl_block = acl.is_blocked(source_node.ip_address, dest_node.ip_address, protocol, port) - if acl_block: - if _VERBOSE: - print( - "ACL block on source: " - + source_node.ip_address - + ", dest: " - + dest_node.ip_address - + ", protocol: " - + protocol - + ", port: " - + port - ) - else: - if _VERBOSE: - print("No ACL block") - - # Check whether both the source and destination are valid, and there's no ACL block - if source_valid and dest_valid and not acl_block: - # Load up the link(s) with the traffic - - if _VERBOSE: - print("Source, Dest and ACL valid") - - # Get the shortest path (i.e. nodes) between source and destination - path_node_list = shortest_path(network, source_node, dest_node) - path_node_list_length = len(path_node_list) - path_valid = True - - # We might have a switch in the path, so check all nodes are operational - for node in path_node_list: - if node.hardware_state != HardwareState.ON or node.software_state == SoftwareState.PATCHING: - path_valid = False - - if path_valid: - if _VERBOSE: - print("Applying IER to link(s)") - count = 0 - link_capacity_exceeded = False - - # Check that the link capacity is not exceeded by the new load - while count < path_node_list_length - 1: - # Get the link between the next two nodes - edge_dict = network.get_edge_data(path_node_list[count], path_node_list[count + 1]) - link_id = edge_dict[0].get("id") - link = links[link_id] - # Check whether the new load exceeds the bandwidth - if (link.get_current_load() + load) > link.get_bandwidth(): - link_capacity_exceeded = True - if _VERBOSE: - print("Link capacity exceeded") - pass - count += 1 - - # Check whether the link capacity for any links on this path have been exceeded - if link_capacity_exceeded == False: - # Now apply the new loads to the links - count = 0 - while count < path_node_list_length - 1: - # Get the link between the next two nodes - edge_dict = network.get_edge_data( - path_node_list[count], - path_node_list[count + 1], - ) - link_id = edge_dict[0].get("id") - link = links[link_id] - # Add the load from this IER - link.add_protocol_load(protocol, load) - count += 1 - # This IER is now valid, so set it to running - ier_value.set_is_running(True) - else: - # One of the nodes is not operational - if _VERBOSE: - print("Path not valid - one or more nodes not operational") - pass - - else: - if _VERBOSE: - print("Source, Dest or ACL were not valid") - pass - # ------------------------------------ - else: - # Do nothing - IER no longer valid - pass - - -def apply_node_pol( - nodes: Dict[str, NodeUnion], - node_pol: Dict[str, NodeStateInstructionGreen], - step: int, -) -> None: - """ - Applies node pattern of life. - - Args: - nodes: The nodes within the environment - node_pol: The node pattern of life to apply - step: The step number. - """ - if _VERBOSE: - print("Applying Node PoL") - - for key, node_instruction in node_pol.items(): - start_step = node_instruction.get_start_step() - stop_step = node_instruction.get_end_step() - node_id = node_instruction.get_node_id() - node_pol_type = node_instruction.get_node_pol_type() - service_name = node_instruction.get_service_name() - state = node_instruction.get_state() - - if step >= start_step and step <= stop_step: - # continue -------------------------- - node = nodes[node_id] - - if node_pol_type == NodePOLType.OPERATING: - # Change hardware state - node.hardware_state = state - elif node_pol_type == NodePOLType.OS: - # Change OS state - # Don't allow PoL to fix something that is compromised. Only the Blue agent can do this - if isinstance(node, ActiveNode) or isinstance(node, ServiceNode): - node.set_software_state_if_not_compromised(state) - elif node_pol_type == NodePOLType.SERVICE: - # Change a service state - # Don't allow PoL to fix something that is compromised. Only the Blue agent can do this - if isinstance(node, ServiceNode): - node.set_service_state_if_not_compromised(service_name, state) - else: - # Change the file system status - if isinstance(node, ActiveNode) or isinstance(node, ServiceNode): - node.set_file_system_state_if_not_compromised(state) - else: - # PoL is not valid in this time step - pass diff --git a/src/primaite/pol/ier.py b/src/primaite/pol/ier.py deleted file mode 100644 index b8da28c0..00000000 --- a/src/primaite/pol/ier.py +++ /dev/null @@ -1,147 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -""" -Information Exchange Requirements for APE. - -Used to represent an information flow from source to destination. -""" - - -class IER(object): - """Information Exchange Requirement class.""" - - def __init__( - self, - _id: str, - _start_step: int, - _end_step: int, - _load: int, - _protocol: str, - _port: str, - _source_node_id: str, - _dest_node_id: str, - _mission_criticality: int, - _running: bool = False, - ) -> None: - """ - Initialise an Information Exchange Request. - - :param _id: The IER id - :param _start_step: The step when this IER should start - :param _end_step: The step when this IER should end - :param _load: The load this IER should put on a link (bps) - :param _protocol: The protocol of this IER - :param _port: The port this IER runs on - :param _source_node_id: The source node ID - :param _dest_node_id: The destination node ID - :param _mission_criticality: Criticality of this IER to the mission (0 none, 5 mission critical) - :param _running: Indicates whether the IER is currently running - """ - self.id: str = _id - self.start_step: int = _start_step - self.end_step: int = _end_step - self.source_node_id: str = _source_node_id - self.dest_node_id: str = _dest_node_id - self.load: int = _load - self.protocol: str = _protocol - self.port: str = _port - self.mission_criticality: int = _mission_criticality - self.running: bool = _running - - def get_id(self) -> str: - """ - Gets IER ID. - - Returns: - IER ID - """ - return self.id - - def get_start_step(self) -> int: - """ - Gets IER start step. - - Returns: - IER start step - """ - return self.start_step - - def get_end_step(self) -> int: - """ - Gets IER end step. - - Returns: - IER end step - """ - return self.end_step - - def get_load(self) -> int: - """ - Gets IER load. - - Returns: - IER load - """ - return self.load - - def get_protocol(self) -> str: - """ - Gets IER protocol. - - Returns: - IER protocol - """ - return self.protocol - - def get_port(self) -> str: - """ - Gets IER port. - - Returns: - IER port - """ - return self.port - - def get_source_node_id(self) -> str: - """ - Gets IER source node ID. - - Returns: - IER source node ID - """ - return self.source_node_id - - def get_dest_node_id(self) -> str: - """ - Gets IER destination node ID. - - Returns: - IER destination node ID - """ - return self.dest_node_id - - def get_is_running(self) -> bool: - """ - Informs whether the IER is currently running. - - Returns: - True if running - """ - return self.running - - def set_is_running(self, _value: bool) -> None: - """ - Sets the running state of the IER. - - Args: - _value: running status - """ - self.running = _value - - def get_mission_criticality(self) -> int: - """ - Gets the IER mission criticality (used in the reward function). - - Returns: - Mission criticality value (0 lowest to 5 highest) - """ - return self.mission_criticality diff --git a/src/primaite/pol/red_agent_pol.py b/src/primaite/pol/red_agent_pol.py deleted file mode 100644 index ca1a58da..00000000 --- a/src/primaite/pol/red_agent_pol.py +++ /dev/null @@ -1,353 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Implements POL on the network (nodes and links) resulting from the red agent attack.""" -from typing import Dict - -from networkx import MultiGraph, shortest_path - -from primaite import getLogger -from primaite.acl.access_control_list import AccessControlList -from primaite.common.custom_typing import NodeUnion -from primaite.common.enums import HardwareState, NodePOLInitiator, NodePOLType, NodeType, SoftwareState -from primaite.links.link import Link -from primaite.nodes.active_node import ActiveNode -from primaite.nodes.node_state_instruction_red import NodeStateInstructionRed -from primaite.nodes.service_node import ServiceNode -from primaite.pol.ier import IER - -_LOGGER = getLogger(__name__) - -_VERBOSE: bool = False - - -def apply_red_agent_iers( - network: MultiGraph, - nodes: Dict[str, NodeUnion], - links: Dict[str, Link], - iers: Dict[str, IER], - acl: AccessControlList, - step: int, -) -> None: - """ - Applies IERs to the links (link POL) resulting from red agent attack. - - Args: - network: The network modelled in the environment - nodes: The nodes within the environment - links: The links within the environment - iers: The red agent IERs to apply to the links - acl: The Access Control List - step: The step number. - """ - # Go through each IER and check the conditions for it being applied - # If everything is in place, apply the IER protocol load to the relevant links - for ier_key, ier_value in iers.items(): - start_step = ier_value.get_start_step() - stop_step = ier_value.get_end_step() - protocol = ier_value.get_protocol() - port = ier_value.get_port() - load = ier_value.get_load() - source_node_id = ier_value.get_source_node_id() - dest_node_id = ier_value.get_dest_node_id() - - # Need to set the running status to false first for all IERs - ier_value.set_is_running(False) - - source_valid = True - dest_valid = True - acl_block = False - - if step >= start_step and step <= stop_step: - # continue -------------------------- - - # Get the source and destination node for this link - source_node = nodes[source_node_id] - dest_node = nodes[dest_node_id] - - # 1. Check the source node situation - if source_node.node_type == NodeType.SWITCH: - # It's a switch - if source_node.hardware_state == HardwareState.ON: - source_valid = True - else: - # IER no longer valid - source_valid = False - elif source_node.node_type == NodeType.ACTUATOR: - # It's an actuator - # TO DO - pass - else: - # It's not a switch or an actuator (so active node) - # TODO: this occurs after ruling out the possibility that the node is a switch or an actuator, but it - # could still be a passive/active node, therefore it won't have a hardware_state. The logic here needs - # to change according to duck typing. - if source_node.hardware_state == HardwareState.ON: - if source_node.has_service(protocol): - # Red agents IERs can only be valid if the source service is in a compromised state - if source_node.get_service_state(protocol) == SoftwareState.COMPROMISED: - source_valid = True - else: - source_valid = False - else: - # Do nothing - IER is not valid on this node - # (This shouldn't happen if the IER has been written correctly) - source_valid = False - else: - # Do nothing - IER no longer valid - source_valid = False - - # 2. Check the dest node situation - if dest_node.node_type == NodeType.SWITCH: - # It's a switch - if dest_node.hardware_state == HardwareState.ON: - dest_valid = True - else: - # IER no longer valid - dest_valid = False - elif dest_node.node_type == NodeType.ACTUATOR: - # It's an actuator - pass - else: - # It's not a switch or an actuator (so active node) - if dest_node.hardware_state == HardwareState.ON: - if dest_node.has_service(protocol): - # We don't care what state the destination service is in for an IER - dest_valid = True - else: - # Do nothing - IER is not valid on this node - # (This shouldn't happen if the IER has been written correctly) - dest_valid = False - else: - # Do nothing - IER no longer valid - dest_valid = False - - # 3. Check that the ACL doesn't block it - acl_block = acl.is_blocked(source_node.ip_address, dest_node.ip_address, protocol, port) - if acl_block: - if _VERBOSE: - print( - "ACL block on source: " - + source_node.ip_address - + ", dest: " - + dest_node.ip_address - + ", protocol: " - + protocol - + ", port: " - + port - ) - else: - if _VERBOSE: - print("No ACL block") - - # Check whether both the source and destination are valid, and there's no ACL block - if source_valid and dest_valid and not acl_block: - # Load up the link(s) with the traffic - - if _VERBOSE: - print("Source, Dest and ACL valid") - - # Get the shortest path (i.e. nodes) between source and destination - path_node_list = shortest_path(network, source_node, dest_node) - path_node_list_length = len(path_node_list) - path_valid = True - - # We might have a switch in the path, so check all nodes are operational - # We're assuming here that red agents can get past switches that are patching - for node in path_node_list: - if node.hardware_state != HardwareState.ON: - path_valid = False - - if path_valid: - if _VERBOSE: - print("Applying IER to link(s)") - count = 0 - link_capacity_exceeded = False - - # Check that the link capacity is not exceeded by the new load - while count < path_node_list_length - 1: - # Get the link between the next two nodes - edge_dict = network.get_edge_data(path_node_list[count], path_node_list[count + 1]) - link_id = edge_dict[0].get("id") - link = links[link_id] - # Check whether the new load exceeds the bandwidth - if (link.get_current_load() + load) > link.get_bandwidth(): - link_capacity_exceeded = True - if _VERBOSE: - print("Link capacity exceeded") - pass - count += 1 - - # Check whether the link capacity for any links on this path have been exceeded - if link_capacity_exceeded == False: - # Now apply the new loads to the links - count = 0 - while count < path_node_list_length - 1: - # Get the link between the next two nodes - edge_dict = network.get_edge_data( - path_node_list[count], - path_node_list[count + 1], - ) - link_id = edge_dict[0].get("id") - link = links[link_id] - # Add the load from this IER - link.add_protocol_load(protocol, load) - count += 1 - # This IER is now valid, so set it to running - ier_value.set_is_running(True) - if _VERBOSE: - print("Red IER was allowed to run in step " + str(step)) - else: - # One of the nodes is not operational - if _VERBOSE: - print("Path not valid - one or more nodes not operational") - pass - - else: - if _VERBOSE: - print("Red IER was NOT allowed to run in step " + str(step)) - print("Source, Dest or ACL were not valid") - pass - # ------------------------------------ - else: - # Do nothing - IER no longer valid - pass - - pass - - -def apply_red_agent_node_pol( - nodes: Dict[str, NodeUnion], - iers: Dict[str, IER], - node_pol: Dict[str, NodeStateInstructionRed], - step: int, -) -> None: - """ - Applies node pattern of life. - - Args: - nodes: The nodes within the environment - iers: The red agent IERs - node_pol: The red agent node pattern of life to apply - step: The step number. - """ - if _VERBOSE: - print("Applying Node Red Agent PoL") - - for key, node_instruction in node_pol.items(): - start_step = node_instruction.get_start_step() - stop_step = node_instruction.get_end_step() - target_node_id = node_instruction.get_target_node_id() - initiator = node_instruction.get_initiator() - pol_type = node_instruction.get_pol_type() - service_name = node_instruction.get_service_name() - state = node_instruction.get_state() - source_node_id = node_instruction.get_source_node_id() - source_node_service_name = node_instruction.get_source_node_service() - source_node_service_state_value = node_instruction.get_source_node_service_state() - - passed_checks = False - - if step >= start_step and step <= stop_step: - # continue -------------------------- - target_node: NodeUnion = nodes[target_node_id] - - # check if the initiator type is a str, and if so, cast it as - # NodePOLInitiator - if isinstance(initiator, str): - initiator = NodePOLInitiator[initiator] - - # Based the action taken on the initiator type - if initiator == NodePOLInitiator.DIRECT: - # No conditions required, just apply the change - passed_checks = True - elif initiator == NodePOLInitiator.IER: - # Need to check there is a red IER incoming - passed_checks = is_red_ier_incoming(target_node, iers, pol_type) - elif initiator == NodePOLInitiator.SERVICE: - # Need to check the condition of a service on another node - source_node = nodes[source_node_id] - if source_node.has_service(source_node_service_name): - if ( - source_node.get_service_state(source_node_service_name) - == SoftwareState[source_node_service_state_value] - ): - passed_checks = True - else: - # Do nothing, no matching state value - pass - else: - # Do nothing, service not on this node - pass - else: - _LOGGER.warning("Node Red Agent PoL not allowed - misconfiguration") - - # Only apply the PoL if the checks have passed (based on the initiator type) - if passed_checks: - # Apply the change - if pol_type == NodePOLType.OPERATING: - # Change hardware state - target_node.hardware_state = state - elif pol_type == NodePOLType.OS: - # Change OS state - if isinstance(target_node, ActiveNode) or isinstance(target_node, ServiceNode): - target_node.software_state = state - elif pol_type == NodePOLType.SERVICE: - # Change a service state - if isinstance(target_node, ServiceNode): - target_node.set_service_state(service_name, state) - else: - # Change the file system status - if isinstance(target_node, ActiveNode) or isinstance(target_node, ServiceNode): - target_node.set_file_system_state(state) - else: - _LOGGER.debug("Node Red Agent PoL not allowed - did not pass checks") - else: - # PoL is not valid in this time step - pass - - -def is_red_ier_incoming(node: NodeUnion, iers: Dict[str, IER], node_pol_type: NodePOLType) -> bool: - """Checks if the RED IER is incoming. - - :param node: Destination node of the IER - :type node: NodeUnion - :param iers: Directory of IERs - :type iers: Dict[str,IER] - :param node_pol_type: Type of Pattern-Of-Life - :type node_pol_type: NodePOLType - :return: Whether the RED IER is incoming. - :rtype: bool - """ - node_id = node.node_id - - for ier_key, ier_value in iers.items(): - if ier_value.get_is_running() and ier_value.get_dest_node_id() == node_id: - if ( - node_pol_type == NodePOLType.OPERATING - or node_pol_type == NodePOLType.OS - or node_pol_type == NodePOLType.FILE - ): - # It's looking to change hardware state, file system or SoftwareState, so valid - return True - elif node_pol_type == NodePOLType.SERVICE: - # Check if the service is present on the node and running - ier_protocol = ier_value.get_protocol() - if isinstance(node, ServiceNode): - if node.has_service(ier_protocol): - if node.service_running(ier_protocol): - # Matching service is present and running, so valid - return True - else: - # Service is present, but not running - return False - else: - # Service is not present - return False - else: - # Not a service node - return False - else: - # Shouldn't get here - instruction type is undefined - return False - else: - # The IER destination is not this node, or the IER is not running - return False diff --git a/src/primaite/primaite_session.py b/src/primaite/primaite_session.py deleted file mode 100644 index 7d5b2709..00000000 --- a/src/primaite/primaite_session.py +++ /dev/null @@ -1,228 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Main entry point to PrimAITE. Configure training/evaluation experiments and input/output.""" -from __future__ import annotations - -import json -from pathlib import Path -from typing import Any, Dict, Final, Optional, Tuple, Union - -from primaite import getLogger -from primaite.agents.agent_abc import AgentSessionABC -from primaite.agents.hardcoded_acl import HardCodedACLAgent -from primaite.agents.hardcoded_node import HardCodedNodeAgent - -# from primaite.agents.rllib import RLlibAgent -from primaite.agents.sb3 import SB3Agent -from primaite.agents.simple import DoNothingACLAgent, DoNothingNodeAgent, DummyAgent, RandomAgent -from primaite.common.enums import ActionType, AgentFramework, AgentIdentifier, SessionType -from primaite.config import lay_down_config, training_config -from primaite.config.training_config import TrainingConfig -from primaite.utils.session_metadata_parser import parse_session_metadata -from primaite.utils.session_output_reader import all_transactions_dict, av_rewards_dict - -_LOGGER = getLogger(__name__) - - -class PrimaiteSession: - """ - The PrimaiteSession class. - - Provides a single learning and evaluation entry point for all training and lay down configurations. - """ - - def __init__( - self, - training_config_path: Optional[Union[str, Path]] = "", - lay_down_config_path: Optional[Union[str, Path]] = "", - session_path: Optional[Union[str, Path]] = None, - legacy_training_config: bool = False, - legacy_lay_down_config: bool = False, - ) -> None: - """ - The PrimaiteSession constructor. - - :param training_config_path: YAML file containing configurable items defined in - `primaite.config.training_config.TrainingConfig` - :type training_config_path: Union[path, str] - :param lay_down_config_path: YAML file containing configurable items for generating network laydown. - :type lay_down_config_path: Union[path, str] - :param session_path: directory path of the session to load - :param legacy_training_config: True if the training config file is a legacy file from PrimAITE < 2.0, - otherwise False. - :param legacy_lay_down_config: True if the lay_down config file is a legacy file from PrimAITE < 2.0, - otherwise False. - """ - self._agent_session: AgentSessionABC = None # noqa - self.session_path: Path = session_path # noqa - self.timestamp_str: str = None # noqa - self.learning_path: Path = None # noqa - self.evaluation_path: Path = None # noqa - self.legacy_training_config = legacy_training_config - self.legacy_lay_down_config = legacy_lay_down_config - - # check if session path is provided - if session_path is not None: - # set load_session to true - self.is_load_session = True - if not isinstance(session_path, Path): - session_path = Path(session_path) - - # if a session path is provided, load it - if not session_path.exists(): - raise Exception(f"Session could not be loaded. Path does not exist: {session_path}") - - md_dict, training_config_path, lay_down_config_path = parse_session_metadata(session_path) - - if not isinstance(training_config_path, Path): - training_config_path = Path(training_config_path) - self._training_config_path: Final[Union[Path, str]] = training_config_path - self._training_config: Final[TrainingConfig] = training_config.load( - self._training_config_path, legacy_training_config - ) - - if not isinstance(lay_down_config_path, Path): - lay_down_config_path = Path(lay_down_config_path) - self._lay_down_config_path: Final[Union[Path, str]] = lay_down_config_path - self._lay_down_config: Dict = lay_down_config.load(self._lay_down_config_path, legacy_lay_down_config) # noqa - - def setup(self) -> None: - """Performs the session setup.""" - if self._training_config.agent_framework == AgentFramework.CUSTOM: - _LOGGER.debug(f"PrimaiteSession Setup: Agent Framework = {AgentFramework.CUSTOM}") - if self._training_config.agent_identifier == AgentIdentifier.HARDCODED: - _LOGGER.debug(f"PrimaiteSession Setup: Agent Identifier =" f" {AgentIdentifier.HARDCODED}") - if self._training_config.action_type == ActionType.NODE: - # Deterministic Hardcoded Agent with Node Action Space - self._agent_session = HardCodedNodeAgent( - self._training_config_path, self._lay_down_config_path, self.session_path - ) - - elif self._training_config.action_type == ActionType.ACL: - # Deterministic Hardcoded Agent with ACL Action Space - self._agent_session = HardCodedACLAgent( - self._training_config_path, self._lay_down_config_path, self.session_path - ) - - elif self._training_config.action_type == ActionType.ANY: - # Deterministic Hardcoded Agent with ANY Action Space - raise NotImplementedError - - else: - # Invalid AgentIdentifier ActionType combo - raise ValueError - - elif self._training_config.agent_identifier == AgentIdentifier.DO_NOTHING: - _LOGGER.debug(f"PrimaiteSession Setup: Agent Identifier =" f" {AgentIdentifier.DO_NOTHING}") - if self._training_config.action_type == ActionType.NODE: - self._agent_session = DoNothingNodeAgent( - self._training_config_path, self._lay_down_config_path, self.session_path - ) - - elif self._training_config.action_type == ActionType.ACL: - # Deterministic Hardcoded Agent with ACL Action Space - self._agent_session = DoNothingACLAgent( - self._training_config_path, self._lay_down_config_path, self.session_path - ) - - elif self._training_config.action_type == ActionType.ANY: - # Deterministic Hardcoded Agent with ANY Action Space - raise NotImplementedError - - else: - # Invalid AgentIdentifier ActionType combo - raise ValueError - - elif self._training_config.agent_identifier == AgentIdentifier.RANDOM: - _LOGGER.debug(f"PrimaiteSession Setup: Agent Identifier =" f" {AgentIdentifier.RANDOM}") - self._agent_session = RandomAgent( - self._training_config_path, self._lay_down_config_path, self.session_path - ) - elif self._training_config.agent_identifier == AgentIdentifier.DUMMY: - _LOGGER.debug(f"PrimaiteSession Setup: Agent Identifier =" f" {AgentIdentifier.DUMMY}") - self._agent_session = DummyAgent( - self._training_config_path, self._lay_down_config_path, self.session_path - ) - - else: - # Invalid AgentFramework AgentIdentifier combo - raise ValueError - - elif self._training_config.agent_framework == AgentFramework.SB3: - _LOGGER.debug(f"PrimaiteSession Setup: Agent Framework = {AgentFramework.SB3}") - # Stable Baselines3 Agent - self._agent_session = SB3Agent( - self._training_config_path, - self._lay_down_config_path, - self.session_path, - self.legacy_training_config, - self.legacy_lay_down_config, - ) - - # elif self._training_config.agent_framework == AgentFramework.RLLIB: - # _LOGGER.debug(f"PrimaiteSession Setup: Agent Framework = {AgentFramework.RLLIB}") - # # Ray RLlib Agent - # self._agent_session = RLlibAgent( - # self._training_config_path, self._lay_down_config_path, self.session_path - # ) - - else: - # Invalid AgentFramework - raise ValueError - - self.session_path: Path = self._agent_session.session_path - self.timestamp_str: str = self._agent_session.timestamp_str - self.learning_path: Path = self._agent_session.learning_path - self.evaluation_path: Path = self._agent_session.evaluation_path - - def learn( - self, - **kwargs: Any, - ) -> None: - """ - Train the agent. - - :param kwargs: Any agent-framework specific key word args. - """ - if not self._training_config.session_type == SessionType.EVAL: - self._agent_session.learn(**kwargs) - - def evaluate( - self, - **kwargs: Any, - ) -> None: - """ - Evaluate the agent. - - :param kwargs: Any agent-framework specific key word args. - """ - if not self._training_config.session_type == SessionType.TRAIN: - self._agent_session.evaluate(**kwargs) - - def close(self) -> None: - """Closes the agent.""" - self._agent_session.close() - - def learn_av_reward_per_episode_dict(self) -> Dict[int, float]: - """Get the learn av reward per episode from file.""" - csv_file = f"average_reward_per_episode_{self.timestamp_str}.csv" - return av_rewards_dict(self.learning_path / csv_file) - - def eval_av_reward_per_episode_dict(self) -> Dict[int, float]: - """Get the eval av reward per episode from file.""" - csv_file = f"average_reward_per_episode_{self.timestamp_str}.csv" - return av_rewards_dict(self.evaluation_path / csv_file) - - def learn_all_transactions_dict(self) -> Dict[Tuple[int, int], Dict[str, Any]]: - """Get the learn all transactions from file.""" - csv_file = f"all_transactions_{self.timestamp_str}.csv" - return all_transactions_dict(self.learning_path / csv_file) - - def eval_all_transactions_dict(self) -> Dict[Tuple[int, int], Dict[str, Any]]: - """Get the eval all transactions from file.""" - csv_file = f"all_transactions_{self.timestamp_str}.csv" - return all_transactions_dict(self.evaluation_path / csv_file) - - def metadata_file_as_dict(self) -> Dict[str, Any]: - """Read the session_metadata.json file and return as a dict.""" - with open(self.session_path / "session_metadata.json", "r") as file: - return json.load(file) diff --git a/src/primaite/setup/old_installation_clean_up.py b/src/primaite/setup/old_installation_clean_up.py deleted file mode 100644 index 412aed60..00000000 --- a/src/primaite/setup/old_installation_clean_up.py +++ /dev/null @@ -1,14 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -from primaite import getLogger - -_LOGGER = getLogger(__name__) - - -def run() -> None: - """Perform the full clean-up.""" - pass - - -if __name__ == "__main__": - run() diff --git a/src/primaite/transactions/__init__.py b/src/primaite/transactions/__init__.py deleted file mode 100644 index 505c5080..00000000 --- a/src/primaite/transactions/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Record data of the system's state and agent's observations and actions.""" diff --git a/src/primaite/transactions/transaction.py b/src/primaite/transactions/transaction.py deleted file mode 100644 index 6b973ca3..00000000 --- a/src/primaite/transactions/transaction.py +++ /dev/null @@ -1,102 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""The Transaction class.""" -from datetime import datetime -from typing import List, Optional, Tuple, TYPE_CHECKING, Union - -from primaite.common.enums import AgentIdentifier - -if TYPE_CHECKING: - import numpy as np - from gymnasium import spaces - - -class Transaction(object): - """Transaction class.""" - - def __init__(self, agent_identifier: AgentIdentifier, episode_number: int, step_number: int) -> None: - """ - Transaction constructor. - - :param agent_identifier: An identifier for the agent in use - :param episode_number: The episode number - :param step_number: The step number - """ - self.timestamp: datetime = datetime.now() - "The datetime of the transaction" - self.agent_identifier: AgentIdentifier = agent_identifier - "The agent identifier" - self.episode_number: int = episode_number - "The episode number" - self.step_number: int = step_number - "The step number" - self.obs_space: "spaces.Space" = None - "The observation space (pre)" - self.obs_space_pre: Optional[Union["np.ndarray", Tuple["np.ndarray"]]] = None - "The observation space before any actions are taken" - self.obs_space_post: Optional[Union["np.ndarray", Tuple["np.ndarray"]]] = None - "The observation space after any actions are taken" - self.reward: Optional[float] = None - "The reward value" - self.action_space: Optional[int] = None - "The action space invoked by the agent" - self.obs_space_description: Optional[List[str]] = None - "The env observation space description" - - def as_csv_data(self) -> Tuple[List, List]: - """ - Converts the Transaction to a csv data row and provides a header. - - :return: A tuple consisting of (header, data). - """ - if isinstance(self.action_space, int): - action_length = self.action_space - else: - action_length = self.action_space.size - - # Create the action space headers array - action_header = [] - for x in range(action_length): - action_header.append("AS_" + str(x)) - - # Open up a csv file - header = ["Timestamp", "Episode", "Step", "Reward"] - header = header + action_header + self.obs_space_description - - row = [ - str(self.timestamp), - str(self.episode_number), - str(self.step_number), - str(self.reward), - ] - row = row + _turn_action_space_to_array(self.action_space) + self.obs_space.tolist() - return header, row - - -def _turn_action_space_to_array(action_space: Union[int, List[int]]) -> List[str]: - """ - Turns action space into a string array so it can be saved to csv. - - :param action_space: The action space - :return: The action space as an array of strings - """ - if isinstance(action_space, list): - return [str(i) for i in action_space] - else: - return [str(action_space)] - - -def _turn_obs_space_to_array(obs_space: "np.ndarray", obs_assets: int, obs_features: int) -> List[str]: - """ - Turns observation space into a string array so it can be saved to csv. - - :param obs_space: The observation space - :param obs_assets: The number of assets (i.e. nodes or links) in the observation space - :param obs_features: The number of features associated with the asset - :return: The observation space as an array of strings - """ - return_array = [] - for x in range(obs_assets): - for y in range(obs_features): - return_array.append(str(obs_space[x][y])) - - return return_array From e8e14ae68a11722a9c016881c71ff6eeb38ad016 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 25 Oct 2023 13:56:02 +0100 Subject: [PATCH 251/980] Comment out tests for primaite v2 --- src/primaite/main.py | 16 +- .../legacy_config_1_DDOS_BASIC.yaml | 170 ------ .../legacy_config_2_DDOS_BASIC.yaml | 362 ------------ .../legacy_config_3_DOS_VERY_BASIC.yaml | 166 ------ .../legacy_config_5_DATA_MANIPULATION.yaml | 534 ------------------ .../legacy_training_config.yaml | 92 --- .../new_training_config.yaml | 114 ---- tests/config/obs_tests/laydown.yaml | 103 ---- tests/config/obs_tests/laydown_ACL.yaml | 86 --- .../main_config_ACCESS_CONTROL_LIST.yaml | 106 ---- .../main_config_LINK_TRAFFIC_LEVELS.yaml | 121 ---- .../main_config_NODE_LINK_TABLE.yaml | 118 ---- .../obs_tests/main_config_NODE_STATUSES.yaml | 115 ---- .../obs_tests/main_config_without_obs.yaml | 108 ---- ...ne_node_states_on_off_lay_down_config.yaml | 117 ---- .../one_node_states_on_off_main_config.yaml | 166 ------ .../ppo_not_seeded_training_config.yaml | 162 ------ tests/config/ppo_seeded_training_config.yaml | 161 ------ .../training_config_main_rllib.yaml | 164 ------ .../training_config_main_sb3.yaml | 164 ------ ..._space_fixed_blue_actions_main_config.yaml | 117 ---- .../single_action_space_lay_down_config.yaml | 45 -- .../single_action_space_main_config.yaml | 116 ---- tests/config/test_random_red_main_config.yaml | 164 ------ tests/config/train_episode_step.yaml | 154 ----- tests/conftest.py | 8 +- tests/test_acl.py | 14 +- tests/test_active_node.py | 8 +- tests/test_full_legacy_config_session.py | 1 + tests/test_lay_down_config.py | 15 +- tests/test_observation_space.py | 8 +- tests/test_primaite_session.py | 4 +- tests/test_red_random_agent_behaviour.py | 5 +- tests/test_resetting_node.py | 13 +- tests/test_reward.py | 1 + .../test_seeding_and_deterministic_session.py | 4 +- tests/test_service_node.py | 8 +- tests/test_session_loading.py | 13 +- tests/test_single_action_space.py | 9 +- tests/test_train_eval_episode_steps.py | 4 +- tests/test_training_config.py | 6 +- 41 files changed, 95 insertions(+), 3767 deletions(-) delete mode 100644 tests/config/legacy_conversion/legacy_config_1_DDOS_BASIC.yaml delete mode 100644 tests/config/legacy_conversion/legacy_config_2_DDOS_BASIC.yaml delete mode 100644 tests/config/legacy_conversion/legacy_config_3_DOS_VERY_BASIC.yaml delete mode 100644 tests/config/legacy_conversion/legacy_config_5_DATA_MANIPULATION.yaml delete mode 100644 tests/config/legacy_conversion/legacy_training_config.yaml delete mode 100644 tests/config/legacy_conversion/new_training_config.yaml delete mode 100644 tests/config/obs_tests/laydown.yaml delete mode 100644 tests/config/obs_tests/laydown_ACL.yaml delete mode 100644 tests/config/obs_tests/main_config_ACCESS_CONTROL_LIST.yaml delete mode 100644 tests/config/obs_tests/main_config_LINK_TRAFFIC_LEVELS.yaml delete mode 100644 tests/config/obs_tests/main_config_NODE_LINK_TABLE.yaml delete mode 100644 tests/config/obs_tests/main_config_NODE_STATUSES.yaml delete mode 100644 tests/config/obs_tests/main_config_without_obs.yaml delete mode 100644 tests/config/one_node_states_on_off_lay_down_config.yaml delete mode 100644 tests/config/one_node_states_on_off_main_config.yaml delete mode 100644 tests/config/ppo_not_seeded_training_config.yaml delete mode 100644 tests/config/ppo_seeded_training_config.yaml delete mode 100644 tests/config/session_test/training_config_main_rllib.yaml delete mode 100644 tests/config/session_test/training_config_main_sb3.yaml delete mode 100644 tests/config/single_action_space_fixed_blue_actions_main_config.yaml delete mode 100644 tests/config/single_action_space_lay_down_config.yaml delete mode 100644 tests/config/single_action_space_main_config.yaml delete mode 100644 tests/config/test_random_red_main_config.yaml delete mode 100644 tests/config/train_episode_step.yaml diff --git a/src/primaite/main.py b/src/primaite/main.py index 45cd0d8d..0cbcff0e 100644 --- a/src/primaite/main.py +++ b/src/primaite/main.py @@ -5,7 +5,8 @@ from pathlib import Path from typing import Optional, Union from primaite import getLogger -from primaite.primaite_session import PrimaiteSession + +# from primaite.primaite_session import PrimaiteSession _LOGGER = getLogger(__name__) @@ -31,13 +32,14 @@ def run( :param legacy_lay_down_config: True if the lay_down config file is a legacy file from PrimAITE < 2.0, otherwise False. """ - session = PrimaiteSession( - training_config_path, lay_down_config_path, session_path, legacy_training_config, legacy_lay_down_config - ) + # session = PrimaiteSession( + # training_config_path, lay_down_config_path, session_path, legacy_training_config, legacy_lay_down_config + # ) - session.setup() - session.learn() - session.evaluate() + # session.setup() + # session.learn() + # session.evaluate() + return NotImplemented if __name__ == "__main__": diff --git a/tests/config/legacy_conversion/legacy_config_1_DDOS_BASIC.yaml b/tests/config/legacy_conversion/legacy_config_1_DDOS_BASIC.yaml deleted file mode 100644 index 5db0ff24..00000000 --- a/tests/config/legacy_conversion/legacy_config_1_DDOS_BASIC.yaml +++ /dev/null @@ -1,170 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -- itemType: ACTIONS - type: NODE -- itemType: STEPS - steps: 128 -- itemType: PORTS - portsList: - - port: '80' -- itemType: SERVICES - serviceList: - - name: TCP -- itemType: NODE - id: '1' - name: PC1 - baseType: SERVICE - nodeType: COMPUTER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.1.2 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '2' - name: SERVER - baseType: SERVICE - nodeType: SERVER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.1.3 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '3' - name: PC2 - baseType: SERVICE - nodeType: COMPUTER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.1.4 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '4' - name: SWITCH1 - baseType: ACTIVE - nodeType: SWITCH - priority: P2 - hardwareState: 'ON' - ipAddress: 192.168.1.5 - softwareState: GOOD - fileSystemState: GOOD -- itemType: NODE - id: '5' - name: SWITCH2 - baseType: ACTIVE - nodeType: SWITCH - priority: P2 - hardwareState: 'ON' - ipAddress: 192.168.1.6 - softwareState: GOOD - fileSystemState: GOOD -- itemType: NODE - id: '6' - name: SWITCH3 - baseType: ACTIVE - nodeType: SWITCH - priority: P2 - hardwareState: 'ON' - ipAddress: 192.168.1.7 - softwareState: GOOD - fileSystemState: GOOD -- itemType: LINK - id: '7' - name: link1 - bandwidth: 1000000000 - source: '1' - destination: '4' -- itemType: LINK - id: '8' - name: link2 - bandwidth: 1000000000 - source: '4' - destination: '2' -- itemType: LINK - id: '9' - name: link3 - bandwidth: 1000000000 - source: '2' - destination: '5' -- itemType: LINK - id: '10' - name: link4 - bandwidth: 1000000000 - source: '2' - destination: '6' -- itemType: LINK - id: '11' - name: link5 - bandwidth: 1000000000 - source: '5' - destination: '3' -- itemType: LINK - id: '12' - name: link6 - bandwidth: 1000000000 - source: '6' - destination: '3' -- itemType: GREEN_IER - id: '13' - startStep: 1 - endStep: 128 - load: 100000 - protocol: TCP - port: '80' - source: '3' - destination: '2' - missionCriticality: 5 -- itemType: RED_POL - id: '14' - startStep: 50 - endStep: 50 - targetNodeId: '1' - initiator: DIRECT - type: SERVICE - protocol: TCP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- itemType: RED_IER - id: '15' - startStep: 60 - endStep: 100 - load: 1000000 - protocol: TCP - port: '80' - source: '1' - destination: '2' - missionCriticality: 0 -- itemType: RED_POL - id: '16' - startStep: 80 - endStep: 80 - targetNodeId: '2' - initiator: IER - type: SERVICE - protocol: TCP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- itemType: ACL_RULE - id: '17' - permission: ALLOW - source: ANY - destination: ANY - protocol: ANY - port: ANY diff --git a/tests/config/legacy_conversion/legacy_config_2_DDOS_BASIC.yaml b/tests/config/legacy_conversion/legacy_config_2_DDOS_BASIC.yaml deleted file mode 100644 index 2e791bb1..00000000 --- a/tests/config/legacy_conversion/legacy_config_2_DDOS_BASIC.yaml +++ /dev/null @@ -1,362 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -- itemType: ACTIONS - type: NODE -- itemType: STEPS - steps: 128 -- itemType: PORTS - portsList: - - port: '80' -- itemType: SERVICES - serviceList: - - name: TCP -- itemType: NODE - id: '1' - name: PC1 - baseType: SERVICE - nodeType: COMPUTER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.10.11 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '2' - name: PC2 - baseType: SERVICE - nodeType: COMPUTER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.10.12 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '3' - name: PC3 - baseType: SERVICE - nodeType: COMPUTER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.10.13 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '4' - name: PC4 - baseType: SERVICE - nodeType: COMPUTER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.20.14 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '5' - name: SWITCH1 - baseType: ACTIVE - nodeType: SWITCH - priority: P2 - hardwareState: 'ON' - ipAddress: 192.168.1.2 - softwareState: GOOD - fileSystemState: GOOD -- itemType: NODE - id: '6' - name: IDS - baseType: SERVICE - nodeType: SERVER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.1.4 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '7' - name: SWITCH2 - baseType: ACTIVE - nodeType: SWITCH - priority: P2 - hardwareState: 'ON' - ipAddress: 192.168.1.3 - softwareState: GOOD - fileSystemState: GOOD -- itemType: NODE - id: '8' - name: LOP1 - baseType: SERVICE - nodeType: LOP - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.1.12 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '9' - name: SERVER1 - baseType: SERVICE - nodeType: SERVER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.10.14 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '10' - name: SERVER2 - baseType: SERVICE - nodeType: SERVER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.20.15 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: LINK - id: '11' - name: link1 - bandwidth: 1000000000 - source: '1' - destination: '5' -- itemType: LINK - id: '12' - name: link2 - bandwidth: 1000000000 - source: '2' - destination: '5' -- itemType: LINK - id: '13' - name: link3 - bandwidth: 1000000000 - source: '3' - destination: '5' -- itemType: LINK - id: '14' - name: link4 - bandwidth: 1000000000 - source: '4' - destination: '5' -- itemType: LINK - id: '15' - name: link5 - bandwidth: 1000000000 - source: '5' - destination: '6' -- itemType: LINK - id: '16' - name: link6 - bandwidth: 1000000000 - source: '5' - destination: '8' -- itemType: LINK - id: '17' - name: link7 - bandwidth: 1000000000 - source: '6' - destination: '7' -- itemType: LINK - id: '18' - name: link8 - bandwidth: 1000000000 - source: '8' - destination: '7' -- itemType: LINK - id: '19' - name: link9 - bandwidth: 1000000000 - source: '7' - destination: '9' -- itemType: LINK - id: '20' - name: link10 - bandwidth: 1000000000 - source: '7' - destination: '10' -- itemType: GREEN_IER - id: '21' - startStep: 1 - endStep: 128 - load: 100000 - protocol: TCP - port: '80' - source: '1' - destination: '9' - missionCriticality: 2 -- itemType: GREEN_IER - id: '22' - startStep: 1 - endStep: 128 - load: 100000 - protocol: TCP - port: '80' - source: '2' - destination: '9' - missionCriticality: 2 -- itemType: GREEN_IER - id: '23' - startStep: 1 - endStep: 128 - load: 100000 - protocol: TCP - port: '80' - source: '9' - destination: '3' - missionCriticality: 5 -- itemType: GREEN_IER - id: '24' - startStep: 1 - endStep: 128 - load: 100000 - protocol: TCP - port: '80' - source: '4' - destination: '10' - missionCriticality: 2 -- itemType: ACL_RULE - id: '25' - permission: ALLOW - source: 192.168.10.11 - destination: 192.168.10.14 - protocol: TCP - port: 80 -- itemType: ACL_RULE - id: '26' - permission: ALLOW - source: 192.168.10.12 - destination: 192.168.10.14 - protocol: TCP - port: 80 -- itemType: ACL_RULE - id: '27' - permission: ALLOW - source: 192.168.10.13 - destination: 192.168.10.14 - protocol: TCP - port: 80 -- itemType: ACL_RULE - id: '28' - permission: ALLOW - source: 192.168.20.14 - destination: 192.168.20.15 - protocol: TCP - port: 80 -- itemType: ACL_RULE - id: '29' - permission: ALLOW - source: 192.168.10.14 - destination: 192.168.10.13 - protocol: TCP - port: 80 -- itemType: ACL_RULE - id: '30' - permission: DENY - source: 192.168.10.11 - destination: 192.168.20.15 - protocol: TCP - port: 80 -- itemType: ACL_RULE - id: '31' - permission: DENY - source: 192.168.10.12 - destination: 192.168.20.15 - protocol: TCP - port: 80 -- itemType: ACL_RULE - id: '32' - permission: DENY - source: 192.168.10.13 - destination: 192.168.20.15 - protocol: TCP - port: 80 -- itemType: ACL_RULE - id: '33' - permission: DENY - source: 192.168.20.14 - destination: 192.168.10.14 - protocol: TCP - port: 80 -- itemType: RED_POL - id: '34' - startStep: 20 - endStep: 20 - targetNodeId: '1' - initiator: DIRECT - type: SERVICE - protocol: TCP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- itemType: RED_POL - id: '35' - startStep: 20 - endStep: 20 - targetNodeId: '2' - initiator: DIRECT - type: SERVICE - protocol: TCP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- itemType: RED_IER - id: '36' - startStep: 30 - endStep: 128 - load: 440000000 - protocol: TCP - port: '80' - source: '1' - destination: '9' - missionCriticality: 0 -- itemType: RED_IER - id: '37' - startStep: 30 - endStep: 128 - load: 440000000 - protocol: TCP - port: '80' - source: '2' - destination: '9' - missionCriticality: 0 -- itemType: RED_POL - id: '38' - startStep: 30 - endStep: 30 - targetNodeId: '9' - initiator: IER - type: SERVICE - protocol: TCP - state: OVERWHELMED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA diff --git a/tests/config/legacy_conversion/legacy_config_3_DOS_VERY_BASIC.yaml b/tests/config/legacy_conversion/legacy_config_3_DOS_VERY_BASIC.yaml deleted file mode 100644 index 232dd8c7..00000000 --- a/tests/config/legacy_conversion/legacy_config_3_DOS_VERY_BASIC.yaml +++ /dev/null @@ -1,166 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -- itemType: ACTIONS - type: NODE -- itemType: STEPS - steps: 256 -- itemType: PORTS - portsList: - - port: '80' -- itemType: SERVICES - serviceList: - - name: TCP -- itemType: NODE - id: '1' - name: PC1 - baseType: SERVICE - nodeType: COMPUTER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.1.2 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '2' - name: PC2 - baseType: SERVICE - nodeType: COMPUTER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.1.3 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '3' - name: SWITCH1 - baseType: ACTIVE - nodeType: SWITCH - priority: P2 - hardwareState: 'ON' - ipAddress: 192.168.1.1 - softwareState: GOOD - fileSystemState: GOOD -- itemType: NODE - id: '4' - name: SERVER1 - baseType: SERVICE - nodeType: SERVER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.1.4 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: LINK - id: '5' - name: link1 - bandwidth: 1000000000 - source: '1' - destination: '3' -- itemType: LINK - id: '6' - name: link2 - bandwidth: 1000000000 - source: '2' - destination: '3' -- itemType: LINK - id: '7' - name: link3 - bandwidth: 1000000000 - source: '3' - destination: '4' -- itemType: GREEN_IER - id: '8' - startStep: 1 - endStep: 256 - load: 10000 - protocol: TCP - port: '80' - source: '1' - destination: '4' - missionCriticality: 1 -- itemType: GREEN_IER - id: '9' - startStep: 1 - endStep: 256 - load: 10000 - protocol: TCP - port: '80' - source: '2' - destination: '4' - missionCriticality: 1 -- itemType: GREEN_IER - id: '10' - startStep: 1 - endStep: 256 - load: 10000 - protocol: TCP - port: '80' - source: '4' - destination: '2' - missionCriticality: 5 -- itemType: ACL_RULE - id: '11' - permission: ALLOW - source: 192.168.1.2 - destination: 192.168.1.4 - protocol: TCP - port: 80 -- itemType: ACL_RULE - id: '12' - permission: ALLOW - source: 192.168.1.3 - destination: 192.168.1.4 - protocol: TCP - port: 80 -- itemType: ACL_RULE - id: '13' - permission: ALLOW - source: 192.168.1.4 - destination: 192.168.1.3 - protocol: TCP - port: 80 -- itemType: RED_POL - id: '14' - startStep: 20 - endStep: 20 - targetNodeId: '1' - initiator: DIRECT - type: SERVICE - protocol: TCP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- itemType: RED_IER - id: '15' - startStep: 30 - endStep: 256 - load: 10000000 - protocol: TCP - port: '80' - source: '1' - destination: '4' - missionCriticality: 0 -- itemType: RED_POL - id: '16' - startStep: 40 - endStep: 40 - targetNodeId: '4' - initiator: IER - type: SERVICE - protocol: TCP - state: OVERWHELMED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA diff --git a/tests/config/legacy_conversion/legacy_config_5_DATA_MANIPULATION.yaml b/tests/config/legacy_conversion/legacy_config_5_DATA_MANIPULATION.yaml deleted file mode 100644 index 6aa6a4ef..00000000 --- a/tests/config/legacy_conversion/legacy_config_5_DATA_MANIPULATION.yaml +++ /dev/null @@ -1,534 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -- itemType: ACTIONS - type: NODE -- itemType: STEPS - steps: 256 -- itemType: PORTS - portsList: - - port: '80' - - port: '1433' - - port: '53' -- itemType: SERVICES - serviceList: - - name: TCP - - name: TCP_SQL - - name: UDP -- itemType: NODE - id: '1' - name: CLIENT_1 - baseType: SERVICE - nodeType: COMPUTER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.10.11 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: UDP - port: '53' - state: GOOD -- itemType: NODE - id: '2' - name: CLIENT_2 - baseType: SERVICE - nodeType: COMPUTER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.10.12 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: NODE - id: '3' - name: SWITCH_1 - baseType: ACTIVE - nodeType: SWITCH - priority: P2 - hardwareState: 'ON' - ipAddress: 192.168.10.1 - softwareState: GOOD - fileSystemState: GOOD -- itemType: NODE - id: '4' - name: SECURITY_SUITE - baseType: SERVICE - nodeType: SERVER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.1.10 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: UDP - port: '53' - state: GOOD -- itemType: NODE - id: '5' - name: MANAGEMENT_CONSOLE - baseType: SERVICE - nodeType: SERVER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.1.12 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: UDP - port: '53' - state: GOOD -- itemType: NODE - id: '6' - name: SWITCH_2 - baseType: ACTIVE - nodeType: SWITCH - priority: P2 - hardwareState: 'ON' - ipAddress: 192.168.2.1 - softwareState: GOOD - fileSystemState: GOOD -- itemType: NODE - id: '7' - name: WEB_SERVER - baseType: SERVICE - nodeType: SERVER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.2.10 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: TCP_SQL - port: '1433' - state: GOOD -- itemType: NODE - id: '8' - name: DATABASE_SERVER - baseType: SERVICE - nodeType: SERVER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.2.14 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: TCP_SQL - port: '1433' - state: GOOD - - name: UDP - port: '53' - state: GOOD -- itemType: NODE - id: '9' - name: BACKUP_SERVER - baseType: SERVICE - nodeType: SERVER - priority: P5 - hardwareState: 'ON' - ipAddress: 192.168.2.16 - softwareState: GOOD - fileSystemState: GOOD - services: - - name: TCP - port: '80' - state: GOOD -- itemType: LINK - id: '10' - name: LINK_1 - bandwidth: 1000000000 - source: '1' - destination: '3' -- itemType: LINK - id: '11' - name: LINK_2 - bandwidth: 1000000000 - source: '2' - destination: '3' -- itemType: LINK - id: '12' - name: LINK_3 - bandwidth: 1000000000 - source: '3' - destination: '4' -- itemType: LINK - id: '13' - name: LINK_4 - bandwidth: 1000000000 - source: '3' - destination: '5' -- itemType: LINK - id: '14' - name: LINK_5 - bandwidth: 1000000000 - source: '4' - destination: '6' -- itemType: LINK - id: '15' - name: LINK_6 - bandwidth: 1000000000 - source: '5' - destination: '6' -- itemType: LINK - id: '16' - name: LINK_7 - bandwidth: 1000000000 - source: '6' - destination: '7' -- itemType: LINK - id: '17' - name: LINK_8 - bandwidth: 1000000000 - source: '6' - destination: '8' -- itemType: LINK - id: '18' - name: LINK_9 - bandwidth: 1000000000 - source: '6' - destination: '9' -- itemType: GREEN_IER - id: '19' - startStep: 1 - endStep: 256 - load: 10000 - protocol: TCP - port: '80' - source: '1' - destination: '7' - missionCriticality: 5 -- itemType: GREEN_IER - id: '20' - startStep: 1 - endStep: 256 - load: 10000 - protocol: TCP - port: '80' - source: '7' - destination: '1' - missionCriticality: 5 -- itemType: GREEN_IER - id: '21' - startStep: 1 - endStep: 256 - load: 10000 - protocol: TCP - port: '80' - source: '2' - destination: '7' - missionCriticality: 5 -- itemType: GREEN_IER - id: '22' - startStep: 1 - endStep: 256 - load: 10000 - protocol: TCP - port: '80' - source: '7' - destination: '2' - missionCriticality: 5 -- itemType: GREEN_IER - id: '23' - startStep: 1 - endStep: 256 - load: 5000 - protocol: TCP_SQL - port: '1433' - source: '7' - destination: '8' - missionCriticality: 5 -- itemType: GREEN_IER - id: '24' - startStep: 1 - endStep: 256 - load: 100000 - protocol: TCP_SQL - port: '1433' - source: '8' - destination: '7' - missionCriticality: 5 -- itemType: GREEN_IER - id: '25' - startStep: 1 - endStep: 256 - load: 50000 - protocol: TCP - port: '80' - source: '1' - destination: '9' - missionCriticality: 2 -- itemType: GREEN_IER - id: '26' - startStep: 1 - endStep: 256 - load: 50000 - protocol: TCP - port: '80' - source: '2' - destination: '9' - missionCriticality: 2 -- itemType: GREEN_IER - id: '27' - startStep: 1 - endStep: 256 - load: 5000 - protocol: TCP - port: '80' - source: '5' - destination: '7' - missionCriticality: 1 -- itemType: GREEN_IER - id: '28' - startStep: 1 - endStep: 256 - load: 5000 - protocol: TCP - port: '80' - source: '7' - destination: '5' - missionCriticality: 1 -- itemType: GREEN_IER - id: '29' - startStep: 1 - endStep: 256 - load: 5000 - protocol: TCP - port: '80' - source: '5' - destination: '8' - missionCriticality: 1 -- itemType: GREEN_IER - id: '30' - startStep: 1 - endStep: 256 - load: 5000 - protocol: TCP - port: '80' - source: '8' - destination: '5' - missionCriticality: 1 -- itemType: GREEN_IER - id: '31' - startStep: 1 - endStep: 256 - load: 5000 - protocol: TCP - port: '80' - source: '5' - destination: '9' - missionCriticality: 1 -- itemType: GREEN_IER - id: '32' - startStep: 1 - endStep: 256 - load: 5000 - protocol: TCP - port: '80' - source: '9' - destination: '5' - missionCriticality: 1 -- itemType: ACL_RULE - id: '33' - permission: ALLOW - source: 192.168.10.11 - destination: 192.168.2.10 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '34' - permission: ALLOW - source: 192.168.10.11 - destination: 192.168.2.14 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '35' - permission: ALLOW - source: 192.168.10.12 - destination: 192.168.2.14 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '36' - permission: ALLOW - source: 192.168.10.12 - destination: 192.168.2.10 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '37' - permission: ALLOW - source: 192.168.2.10 - destination: 192.168.10.11 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '38' - permission: ALLOW - source: 192.168.2.10 - destination: 192.168.10.12 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '39' - permission: ALLOW - source: 192.168.2.10 - destination: 192.168.2.14 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '40' - permission: ALLOW - source: 192.168.2.14 - destination: 192.168.2.10 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '41' - permission: ALLOW - source: 192.168.10.11 - destination: 192.168.2.16 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '42' - permission: ALLOW - source: 192.168.10.12 - destination: 192.168.2.16 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '43' - permission: ALLOW - source: 192.168.1.12 - destination: 192.168.2.10 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '44' - permission: ALLOW - source: 192.168.1.12 - destination: 192.168.2.14 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '45' - permission: ALLOW - source: 192.168.1.12 - destination: 192.168.2.16 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '46' - permission: ALLOW - source: 192.168.2.10 - destination: 192.168.1.12 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '47' - permission: ALLOW - source: 192.168.2.14 - destination: 192.168.1.12 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '48' - permission: ALLOW - source: 192.168.2.16 - destination: 192.168.1.12 - protocol: ANY - port: ANY -- itemType: ACL_RULE - id: '49' - permission: DENY - source: ANY - destination: ANY - protocol: ANY - port: ANY -- itemType: RED_POL - id: '50' - startStep: 50 - endStep: 50 - targetNodeId: '1' - initiator: DIRECT - type: SERVICE - protocol: UDP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- itemType: RED_IER - id: '51' - startStep: 75 - endStep: 105 - load: 10000 - protocol: UDP - port: '53' - source: '1' - destination: '8' - missionCriticality: 0 -- itemType: RED_POL - id: '52' - startStep: 100 - endStep: 100 - targetNodeId: '8' - initiator: IER - type: SERVICE - protocol: UDP - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- itemType: RED_POL - id: '53' - startStep: 105 - endStep: 105 - targetNodeId: '8' - initiator: SERVICE - type: FILE - protocol: NA - state: CORRUPT - sourceNodeId: '8' - sourceNodeService: UDP - sourceNodeServiceState: COMPROMISED -- itemType: RED_POL - id: '54' - startStep: 105 - endStep: 105 - targetNodeId: '8' - initiator: SERVICE - type: SERVICE - protocol: TCP_SQL - state: COMPROMISED - sourceNodeId: '8' - sourceNodeService: UDP - sourceNodeServiceState: COMPROMISED -- itemType: RED_POL - id: '55' - startStep: 125 - endStep: 125 - targetNodeId: '7' - initiator: SERVICE - type: SERVICE - protocol: TCP - state: OVERWHELMED - sourceNodeId: '8' - sourceNodeService: TCP_SQL - sourceNodeServiceState: COMPROMISED diff --git a/tests/config/legacy_conversion/legacy_training_config.yaml b/tests/config/legacy_conversion/legacy_training_config.yaml deleted file mode 100644 index 3477e6e0..00000000 --- a/tests/config/legacy_conversion/legacy_training_config.yaml +++ /dev/null @@ -1,92 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Main Config File - -# Generic config values -# Choose one of these (dependent on Agent being trained) -# "STABLE_BASELINES3_PPO" -# "STABLE_BASELINES3_A2C" -# "GENERIC" -agentIdentifier: STABLE_BASELINES3_A2C -# Number of episodes to run per session -numEpisodes: 10 -# Time delay between steps (for generic agents) -timeDelay: 10 -# Filename of the scenario / laydown -configFilename: config_5_DATA_MANIPULATION.yaml -# Type of session to be run (TRAINING or EVALUATION) -sessionType: TRAINING -# Determine whether to load an agent from file -loadAgent: False -# File path and file name of agent if you're loading one in -agentLoadFile: C:\[Path]\[agent_saved_filename.zip] - -# Environment config values -# The high value for the observation space -observationSpaceHighValue: 1000000000 - -# Reward values -# Generic -allOk: 0 -# Node Hardware State -offShouldBeOn: -10 -offShouldBeResetting: -5 -onShouldBeOff: -2 -onShouldBeResetting: -5 -resettingShouldBeOn: -5 -resettingShouldBeOff: -2 -resetting: -3 -# Node Software or Service State -goodShouldBePatching: 2 -goodShouldBeCompromised: 5 -goodShouldBeOverwhelmed: 5 -patchingShouldBeGood: -5 -patchingShouldBeCompromised: 2 -patchingShouldBeOverwhelmed: 2 -patching: -3 -compromisedShouldBeGood: -20 -compromisedShouldBePatching: -20 -compromisedShouldBeOverwhelmed: -20 -compromised: -20 -overwhelmedShouldBeGood: -20 -overwhelmedShouldBePatching: -20 -overwhelmedShouldBeCompromised: -20 -overwhelmed: -20 -# Node File System State -goodShouldBeRepairing: 2 -goodShouldBeRestoring: 2 -goodShouldBeCorrupt: 5 -goodShouldBeDestroyed: 10 -repairingShouldBeGood: -5 -repairingShouldBeRestoring: 2 -repairingShouldBeCorrupt: 2 -repairingShouldBeDestroyed: 0 -repairing: -3 -restoringShouldBeGood: -10 -restoringShouldBeRepairing: -2 -restoringShouldBeCorrupt: 1 -restoringShouldBeDestroyed: 2 -restoring: -6 -corruptShouldBeGood: -10 -corruptShouldBeRepairing: -10 -corruptShouldBeRestoring: -10 -corruptShouldBeDestroyed: 2 -corrupt: -10 -destroyedShouldBeGood: -20 -destroyedShouldBeRepairing: -20 -destroyedShouldBeRestoring: -20 -destroyedShouldBeCorrupt: -20 -destroyed: -20 -scanning: -2 -# IER status -redIerRunning: -5 -greenIerBlocked: -10 - -# Patching / Reset durations -osPatchingDuration: 5 # The time taken to patch the OS -nodeResetDuration: 5 # The time taken to reset a node (hardware) -nodeBootingDuration: 3 # The Time taken to turn on the node -nodeShutdownDuration: 2 # The time taken to turn off the node -servicePatchingDuration: 5 # The time taken to patch a service -fileSystemRepairingLimit: 5 # The time take to repair the file system -fileSystemRestoringLimit: 5 # The time take to restore the file system -fileSystemScanningLimit: 5 # The time taken to scan the file system diff --git a/tests/config/legacy_conversion/new_training_config.yaml b/tests/config/legacy_conversion/new_training_config.yaml deleted file mode 100644 index 1991eb06..00000000 --- a/tests/config/legacy_conversion/new_training_config.yaml +++ /dev/null @@ -1,114 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Main Config File - -# Generic config values - -# Sets which agent algorithm framework will be used: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray[RLlib]) -# "NONE" (Custom Agent) -agent_framework: SB3 - -# Sets which Red Agent algo/class will be used: -# "PPO" (Proximal Policy Optimization) -# "A2C" (Advantage Actor Critic) -# "HARDCODED" (Custom Agent) -# "RANDOM" (Random Action) -agent_identifier: PPO - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: ANY - -# Number of episodes for training to run per session -num_train_episodes: 10 - -# Number of time_steps for training per episode -num_train_steps: 256 - -# Number of episodes for evaluation to run per session -num_eval_episodes: 1 - -# Number of time_steps for evaluation per episode -num_eval_steps: 256 - - -# Time delay between steps (for generic agents) -time_delay: 10 -# Type of session to be run (TRAINING or EVALUATION) -session_type: TRAIN -# Determine whether to load an agent from file -load_agent: False -# File path and file name of agent if you're loading one in -agent_load_file: C:\[Path]\[agent_saved_filename.zip] - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1000000000 - -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -10 -off_should_be_resetting: -5 -on_should_be_off: -2 -on_should_be_resetting: -5 -resetting_should_be_on: -5 -resetting_should_be_off: -2 -resetting: -3 -# Node Software or Service State -good_should_be_patching: 2 -good_should_be_compromised: 5 -good_should_be_overwhelmed: 5 -patching_should_be_good: -5 -patching_should_be_compromised: 2 -patching_should_be_overwhelmed: 2 -patching: -3 -compromised_should_be_good: -20 -compromised_should_be_patching: -20 -compromised_should_be_overwhelmed: -20 -compromised: -20 -overwhelmed_should_be_good: -20 -overwhelmed_should_be_patching: -20 -overwhelmed_should_be_compromised: -20 -overwhelmed: -20 -# Node File System State -good_should_be_repairing: 2 -good_should_be_restoring: 2 -good_should_be_corrupt: 5 -good_should_be_destroyed: 10 -repairing_should_be_good: -5 -repairing_should_be_restoring: 2 -repairing_should_be_corrupt: 2 -repairing_should_be_destroyed: 0 -repairing: -3 -restoring_should_be_good: -10 -restoring_should_be_repairing: -2 -restoring_should_be_corrupt: 1 -restoring_should_be_destroyed: 2 -restoring: -6 -corrupt_should_be_good: -10 -corrupt_should_be_repairing: -10 -corrupt_should_be_restoring: -10 -corrupt_should_be_destroyed: 2 -corrupt: -10 -destroyed_should_be_good: -20 -destroyed_should_be_repairing: -20 -destroyed_should_be_restoring: -20 -destroyed_should_be_corrupt: -20 -destroyed: -20 -scanning: -2 -# IER status -red_ier_running: -5 -green_ier_blocked: -10 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/obs_tests/laydown.yaml b/tests/config/obs_tests/laydown.yaml deleted file mode 100644 index e358d0d2..00000000 --- a/tests/config/obs_tests/laydown.yaml +++ /dev/null @@ -1,103 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -- item_type: PORTS - ports_list: - - port: '80' - - port: '53' -- item_type: SERVICES - service_list: - - name: TCP - - name: UDP - -######################################## -# Nodes -- item_type: NODE - node_id: '1' - name: PC1 - node_class: SERVICE - node_type: COMPUTER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.1 - software_state: COMPROMISED - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: UDP - port: '53' - state: GOOD -- item_type: NODE - node_id: '2' - name: SERVER - node_class: SERVICE - node_type: SERVER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.2 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: UDP - port: '53' - state: OVERWHELMED -- item_type: NODE - node_id: '3' - name: SWITCH1 - node_class: ACTIVE - node_type: SWITCH - priority: P2 - hardware_state: 'ON' - ip_address: 192.168.1.3 - software_state: GOOD - file_system_state: GOOD - -######################################## -# Links -- item_type: LINK - id: '4' - name: link1 - bandwidth: 1000 - source: '1' - destination: '3' -- item_type: LINK - id: '5' - name: link2 - bandwidth: 1000 - source: '3' - destination: '2' - -######################################### -# IERS -- item_type: GREEN_IER - id: '5' - start_step: 0 - end_step: 5 - load: 999 - protocol: TCP - port: '80' - source: '1' - destination: '2' - mission_criticality: 5 - -######################################### -# ACL Rules -- item_type: ACL_RULE - id: '6' - permission: ALLOW - source: 192.168.1.1 - destination: 192.168.1.2 - protocol: TCP - port: 80 - position: 0 -- item_type: ACL_RULE - id: '7' - permission: ALLOW - source: 192.168.1.2 - destination: 192.168.1.1 - protocol: TCP - port: 80 - position: 0 diff --git a/tests/config/obs_tests/laydown_ACL.yaml b/tests/config/obs_tests/laydown_ACL.yaml deleted file mode 100644 index cffd8b1c..00000000 --- a/tests/config/obs_tests/laydown_ACL.yaml +++ /dev/null @@ -1,86 +0,0 @@ -- item_type: PORTS - ports_list: - - port: '80' - - port: '21' -- item_type: SERVICES - service_list: - - name: TCP - - name: FTP - -######################################## -# Nodes -- item_type: NODE - node_id: '1' - name: PC1 - node_class: SERVICE - node_type: COMPUTER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.1 - software_state: COMPROMISED - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: FTP - port: '21' - state: GOOD -- item_type: NODE - node_id: '2' - name: SERVER - node_class: SERVICE - node_type: SERVER - priority: P5 - hardware_state: 'ON' - ip_address: 192.168.1.2 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: GOOD - - name: FTP - port: '21' - state: OVERWHELMED -- item_type: NODE - node_id: '3' - name: SWITCH1 - node_class: ACTIVE - node_type: SWITCH - priority: P2 - hardware_state: 'ON' - ip_address: 192.168.1.3 - software_state: GOOD - file_system_state: GOOD - -######################################## -# Links -- item_type: LINK - id: '4' - name: link1 - bandwidth: 1000 - source: '1' - destination: '3' -- item_type: LINK - id: '5' - name: link2 - bandwidth: 1000 - source: '3' - destination: '2' - -######################################### -# IERS -- item_type: GREEN_IER - id: '5' - start_step: 0 - end_step: 5 - load: 999 - protocol: TCP - port: '80' - source: '1' - destination: '2' - mission_criticality: 5 - -######################################### -# ACL Rules diff --git a/tests/config/obs_tests/main_config_ACCESS_CONTROL_LIST.yaml b/tests/config/obs_tests/main_config_ACCESS_CONTROL_LIST.yaml deleted file mode 100644 index 927c9f44..00000000 --- a/tests/config/obs_tests/main_config_ACCESS_CONTROL_LIST.yaml +++ /dev/null @@ -1,106 +0,0 @@ -# Main Config File - -# Generic config values -# Choose one of these (dependent on Agent being trained) -# "STABLE_BASELINES3_PPO" -# "STABLE_BASELINES3_A2C" -# "GENERIC" -agent_framework: SB3 -agent_identifier: PPO -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: ANY -# Number of episodes for training to run per session -num_train_episodes: 1 -# Number of time_steps for training per episode -num_train_steps: 5 - -# Implicit ACL firewall rule at end of lists to be default action or no rule can be selected (ALLOW or DENY) -implicit_acl_rule: DENY -# Total number of ACL rules allowed in the environment -max_number_acl_rules: 3 - -observation_space: - components: - - name: ACCESS_CONTROL_LIST - -# Time delay between steps (for generic agents) -time_delay: 1 - -# Type of session to be run (TRAINING or EVALUATION) -session_type: TRAIN -# Determine whether to load an agent from file -load_agent: False -# File path and file name of agent if you're loading one in -agent_load_file: C:\[Path]\[agent_saved_filename.zip] - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1_000_000_000 - -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -10 -off_should_be_resetting: -5 -on_should_be_off: -2 -on_should_be_resetting: -5 -resetting_should_be_on: -5 -resetting_should_be_off: -2 -resetting: -3 -# Node Software or Service State -good_should_be_patching: 2 -good_should_be_compromised: 5 -good_should_be_overwhelmed: 5 -patching_should_be_good: -5 -patching_should_be_compromised: 2 -patching_should_be_overwhelmed: 2 -patching: -3 -compromised_should_be_good: -20 -compromised_should_be_patching: -20 -compromised_should_be_overwhelmed: -20 -compromised: -20 -overwhelmed_should_be_good: -20 -overwhelmed_should_be_patching: -20 -overwhelmed_should_be_compromised: -20 -overwhelmed: -20 -# Node File System State -good_should_be_repairing: 2 -good_should_be_restoring: 2 -good_should_be_corrupt: 5 -good_should_be_destroyed: 10 -repairing_should_be_good: -5 -repairing_should_be_restoring: 2 -repairing_should_be_corrupt: 2 -repairing_should_be_destroyed: 0 -repairing: -3 -restoring_should_be_good: -10 -restoring_should_be_repairing: -2 -restoring_should_be_corrupt: 1 -restoring_should_be_destroyed: 2 -restoring: -6 -corrupt_should_be_good: -10 -corrupt_should_be_repairing: -10 -corrupt_should_be_restoring: -10 -corrupt_should_be_destroyed: 2 -corrupt: -10 -destroyed_should_be_good: -20 -destroyed_should_be_repairing: -20 -destroyed_should_be_restoring: -20 -destroyed_should_be_corrupt: -20 -destroyed: -20 -scanning: -2 -# IER status -red_ier_running: -5 -green_ier_blocked: -10 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/obs_tests/main_config_LINK_TRAFFIC_LEVELS.yaml b/tests/config/obs_tests/main_config_LINK_TRAFFIC_LEVELS.yaml deleted file mode 100644 index 805ab31e..00000000 --- a/tests/config/obs_tests/main_config_LINK_TRAFFIC_LEVELS.yaml +++ /dev/null @@ -1,121 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: SB3 - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: A2C - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: ANY -# Number of episodes for training to run per session -num_train_episodes: 1 - -# Number of time_steps for training per episode -num_train_steps: 5 - -observation_space: - components: - - name: LINK_TRAFFIC_LEVELS - options: - combine_service_traffic: false - quantisation_levels: 8 - -# Time delay between steps (for generic agents) -time_delay: 1 - -# Implicit ACL firewall rule at end of lists to be default action or no rule can be selected (ALLOW or DENY) -implicit_acl_rule: ALLOW -# Total number of ACL rules allowed in the environment -max_number_acl_rules: 4 - -# Type of session to be run (TRAINING or EVALUATION) -session_type: TRAIN -# Determine whether to load an agent from file -load_agent: False -# File path and file name of agent if you're loading one in -agent_load_file: C:\[Path]\[agent_saved_filename.zip] - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1_000_000_000 - -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -10 -off_should_be_resetting: -5 -on_should_be_off: -2 -on_should_be_resetting: -5 -resetting_should_be_on: -5 -resetting_should_be_off: -2 -resetting: -3 -# Node Software or Service State -good_should_be_patching: 2 -good_should_be_compromised: 5 -good_should_be_overwhelmed: 5 -patching_should_be_good: -5 -patching_should_be_compromised: 2 -patching_should_be_overwhelmed: 2 -patching: -3 -compromised_should_be_good: -20 -compromised_should_be_patching: -20 -compromised_should_be_overwhelmed: -20 -compromised: -20 -overwhelmed_should_be_good: -20 -overwhelmed_should_be_patching: -20 -overwhelmed_should_be_compromised: -20 -overwhelmed: -20 -# Node File System State -good_should_be_repairing: 2 -good_should_be_restoring: 2 -good_should_be_corrupt: 5 -good_should_be_destroyed: 10 -repairing_should_be_good: -5 -repairing_should_be_restoring: 2 -repairing_should_be_corrupt: 2 -repairing_should_be_destroyed: 0 -repairing: -3 -restoring_should_be_good: -10 -restoring_should_be_repairing: -2 -restoring_should_be_corrupt: 1 -restoring_should_be_destroyed: 2 -restoring: -6 -corrupt_should_be_good: -10 -corrupt_should_be_repairing: -10 -corrupt_should_be_restoring: -10 -corrupt_should_be_destroyed: 2 -corrupt: -10 -destroyed_should_be_good: -20 -destroyed_should_be_repairing: -20 -destroyed_should_be_restoring: -20 -destroyed_should_be_corrupt: -20 -destroyed: -20 -scanning: -2 -# IER status -red_ier_running: -5 -green_ier_blocked: -10 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/obs_tests/main_config_NODE_LINK_TABLE.yaml b/tests/config/obs_tests/main_config_NODE_LINK_TABLE.yaml deleted file mode 100644 index 535558aa..00000000 --- a/tests/config/obs_tests/main_config_NODE_LINK_TABLE.yaml +++ /dev/null @@ -1,118 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: CUSTOM - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: RANDOM - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: ANY -# Number of episodes for training to run per session -num_train_episodes: 1 - -# Number of time_steps for training per episode -num_train_steps: 5 - -observation_space: - components: - - name: NODE_LINK_TABLE - -# Time delay between steps (for generic agents) -time_delay: 1 -# Filename of the scenario / laydown - -# Implicit ACL firewall rule at end of lists to be default action or no rule can be selected (ALLOW or DENY) -implicit_acl_rule: ALLOW -# Total number of ACL rules allowed in the environment -max_number_acl_rules: 4 - -session_type: TRAIN -# Determine whether to load an agent from file -load_agent: False -# File path and file name of agent if you're loading one in -agent_load_file: C:\[Path]\[agent_saved_filename.zip] - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1_000_000_000 - -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -10 -off_should_be_resetting: -5 -on_should_be_off: -2 -on_should_be_resetting: -5 -resetting_should_be_on: -5 -resetting_should_be_off: -2 -resetting: -3 -# Node Software or Service State -good_should_be_patching: 2 -good_should_be_compromised: 5 -good_should_be_overwhelmed: 5 -patching_should_be_good: -5 -patching_should_be_compromised: 2 -patching_should_be_overwhelmed: 2 -patching: -3 -compromised_should_be_good: -20 -compromised_should_be_patching: -20 -compromised_should_be_overwhelmed: -20 -compromised: -20 -overwhelmed_should_be_good: -20 -overwhelmed_should_be_patching: -20 -overwhelmed_should_be_compromised: -20 -overwhelmed: -20 -# Node File System State -good_should_be_repairing: 2 -good_should_be_restoring: 2 -good_should_be_corrupt: 5 -good_should_be_destroyed: 10 -repairing_should_be_good: -5 -repairing_should_be_restoring: 2 -repairing_should_be_corrupt: 2 -repairing_should_be_destroyed: 0 -repairing: -3 -restoring_should_be_good: -10 -restoring_should_be_repairing: -2 -restoring_should_be_corrupt: 1 -restoring_should_be_destroyed: 2 -restoring: -6 -corrupt_should_be_good: -10 -corrupt_should_be_repairing: -10 -corrupt_should_be_restoring: -10 -corrupt_should_be_destroyed: 2 -corrupt: -10 -destroyed_should_be_good: -20 -destroyed_should_be_repairing: -20 -destroyed_should_be_restoring: -20 -destroyed_should_be_corrupt: -20 -destroyed: -20 -scanning: -2 -# IER status -red_ier_running: -5 -green_ier_blocked: -10 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/obs_tests/main_config_NODE_STATUSES.yaml b/tests/config/obs_tests/main_config_NODE_STATUSES.yaml deleted file mode 100644 index d1319c35..00000000 --- a/tests/config/obs_tests/main_config_NODE_STATUSES.yaml +++ /dev/null @@ -1,115 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: CUSTOM - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: RANDOM - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: ANY -# Number of episodes for training to run per session -num_train_episodes: 1 - -# Number of time_steps for training per episode -num_train_steps: 5 - - -observation_space: - components: - - name: NODE_STATUSES - - -# Time delay between steps (for generic agents) -time_delay: 1 - -# Type of session to be run (TRAINING or EVALUATION) -session_type: TRAIN -# Determine whether to load an agent from file -load_agent: False -# File path and file name of agent if you're loading one in -agent_load_file: C:\[Path]\[agent_saved_filename.zip] - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1_000_000_000 - -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -10 -off_should_be_resetting: -5 -on_should_be_off: -2 -on_should_be_resetting: -5 -resetting_should_be_on: -5 -resetting_should_be_off: -2 -resetting: -3 -# Node Software or Service State -good_should_be_patching: 2 -good_should_be_compromised: 5 -good_should_be_overwhelmed: 5 -patching_should_be_good: -5 -patching_should_be_compromised: 2 -patching_should_be_overwhelmed: 2 -patching: -3 -compromised_should_be_good: -20 -compromised_should_be_patching: -20 -compromised_should_be_overwhelmed: -20 -compromised: -20 -overwhelmed_should_be_good: -20 -overwhelmed_should_be_patching: -20 -overwhelmed_should_be_compromised: -20 -overwhelmed: -20 -# Node File System State -good_should_be_repairing: 2 -good_should_be_restoring: 2 -good_should_be_corrupt: 5 -good_should_be_destroyed: 10 -repairing_should_be_good: -5 -repairing_should_be_restoring: 2 -repairing_should_be_corrupt: 2 -repairing_should_be_destroyed: 0 -repairing: -3 -restoring_should_be_good: -10 -restoring_should_be_repairing: -2 -restoring_should_be_corrupt: 1 -restoring_should_be_destroyed: 2 -restoring: -6 -corrupt_should_be_good: -10 -corrupt_should_be_repairing: -10 -corrupt_should_be_restoring: -10 -corrupt_should_be_destroyed: 2 -corrupt: -10 -destroyed_should_be_good: -20 -destroyed_should_be_repairing: -20 -destroyed_should_be_restoring: -20 -destroyed_should_be_corrupt: -20 -destroyed: -20 -scanning: -2 -# IER status -red_ier_running: -5 -green_ier_blocked: -10 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/obs_tests/main_config_without_obs.yaml b/tests/config/obs_tests/main_config_without_obs.yaml deleted file mode 100644 index 26457c84..00000000 --- a/tests/config/obs_tests/main_config_without_obs.yaml +++ /dev/null @@ -1,108 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: CUSTOM - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: RANDOM - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: ANY -# Number of episodes for training to run per session -num_train_episodes: 1 - -# Number of time_steps for training per episode -num_train_steps: 5 -# Time delay between steps (for generic agents) -time_delay: 1 -# Type of session to be run (TRAINING or EVALUATION) -session_type: TRAIN -# Determine whether to load an agent from file -load_agent: False -# File path and file name of agent if you're loading one in -agent_load_file: C:\[Path]\[agent_saved_filename.zip] - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1_000_000_000 -# Implicit ACL firewall rule at end of lists to be default action or no rule can be selected (ALLOW or DENY) -implicit_acl_rule: DENY -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -10 -off_should_be_resetting: -5 -on_should_be_off: -2 -on_should_be_resetting: -5 -resetting_should_be_on: -5 -resetting_should_be_off: -2 -resetting: -3 -# Node Software or Service State -good_should_be_patching: 2 -good_should_be_compromised: 5 -good_should_be_overwhelmed: 5 -patching_should_be_good: -5 -patching_should_be_compromised: 2 -patching_should_be_overwhelmed: 2 -patching: -3 -compromised_should_be_good: -20 -compromised_should_be_patching: -20 -compromised_should_be_overwhelmed: -20 -compromised: -20 -overwhelmed_should_be_good: -20 -overwhelmed_should_be_patching: -20 -overwhelmed_should_be_compromised: -20 -overwhelmed: -20 -# Node File System State -good_should_be_repairing: 2 -good_should_be_restoring: 2 -good_should_be_corrupt: 5 -good_should_be_destroyed: 10 -repairing_should_be_good: -5 -repairing_should_be_restoring: 2 -repairing_should_be_corrupt: 2 -repairing_should_be_destroyed: 0 -repairing: -3 -restoring_should_be_good: -10 -restoring_should_be_repairing: -2 -restoring_should_be_corrupt: 1 -restoring_should_be_destroyed: 2 -restoring: -6 -corrupt_should_be_good: -10 -corrupt_should_be_repairing: -10 -corrupt_should_be_restoring: -10 -corrupt_should_be_destroyed: 2 -corrupt: -10 -destroyed_should_be_good: -20 -destroyed_should_be_repairing: -20 -destroyed_should_be_restoring: -20 -destroyed_should_be_corrupt: -20 -destroyed: -20 -scanning: -2 -# IER status -red_ier_running: -5 -green_ier_blocked: -10 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/one_node_states_on_off_lay_down_config.yaml b/tests/config/one_node_states_on_off_lay_down_config.yaml deleted file mode 100644 index 0f572d8d..00000000 --- a/tests/config/one_node_states_on_off_lay_down_config.yaml +++ /dev/null @@ -1,117 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -- item_type: PORTS - ports_list: - - port: '21' -- item_type: SERVICES - service_list: - - name: ftp -- item_type: NODE - node_id: '1' - name: node - node_class: SERVICE - node_type: COMPUTER - priority: P1 - hardware_state: 'ON' - ip_address: 192.168.0.1 - software_state: GOOD - file_system_state: GOOD - services: - - name: ftp - port: '21' - state: GOOD -- item_type: RED_POL - id: '1' - start_step: 1 - end_step: 3 - targetNodeId: '1' - initiator: DIRECT - type: FILE - protocol: NA - state: CORRUPT - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_POL - id: '2' - start_step: 3 - end_step: 15 - targetNodeId: '1' - initiator: DIRECT - type: FILE - protocol: NA - state: GOOD - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_POL - id: '3' - start_step: 4 - end_step: 6 - targetNodeId: '1' - initiator: DIRECT - type: OPERATING - protocol: NA - state: 'OFF' - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_POL - id: '4' - start_step: 6 - end_step: 15 - targetNodeId: '1' - initiator: DIRECT - type: OPERATING - protocol: NA - state: 'ON' - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_POL - id: '5' - start_step: 7 - end_step: 9 - targetNodeId: '1' - initiator: DIRECT - type: SERVICE - protocol: ftp - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_POL - id: '6' - start_step: 9 - end_step: 15 - targetNodeId: '1' - initiator: DIRECT - type: SERVICE - protocol: ftp - state: GOOD - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_POL - id: '7' - start_step: 10 - end_step: 12 - targetNodeId: '1' - initiator: DIRECT - type: OS - protocol: NA - state: COMPROMISED - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA -- item_type: RED_POL - id: '8' - start_step: 12 - end_step: 15 - targetNodeId: '1' - initiator: DIRECT - type: OS - protocol: NA - state: GOOD - sourceNodeId: NA - sourceNodeService: NA - sourceNodeServiceState: NA diff --git a/tests/config/one_node_states_on_off_main_config.yaml b/tests/config/one_node_states_on_off_main_config.yaml deleted file mode 100644 index 10af7a1f..00000000 --- a/tests/config/one_node_states_on_off_main_config.yaml +++ /dev/null @@ -1,166 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: CUSTOM - -# Sets which deep learning framework will be used (by RLlib ONLY). -# Default is TF (Tensorflow). -# Options are: -# "TF" (Tensorflow) -# TF2 (Tensorflow 2.X) -# TORCH (PyTorch) -deep_learning_framework: TF2 - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: DUMMY - -# Sets whether Red Agent POL and IER is randomised. -# Options are: -# True -# False -random_red_agent: False - -# The (integer) seed to be used in random number generation -# Default is None (null) -seed: null - -# Set whether the agent will be deterministic instead of stochastic -# Options are: -# True -# False -deterministic: False - -# Sets what view of the environment the deterministic hardcoded agent has. The default is BASIC. -# Options are: -# "BASIC" (The current observation space only) -# "FULL" (Full environment view with actions taken and reward feedback) -hard_coded_agent_view: FULL - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: NODE -# observation space -observation_space: - # flatten: true - components: - - name: NODE_LINK_TABLE - # - name: NODE_STATUSES - # - name: LINK_TRAFFIC_LEVELS - - -# Number of episodes for training to run per session -num_train_episodes: 10 - -# Number of time_steps for training per episode -num_train_steps: 256 - -# Number of episodes for evaluation to run per session -num_eval_episodes: 1 - -# Number of time_steps for evaluation per episode -num_eval_steps: 15 - -# Sets how often the agent will save a checkpoint (every n time episodes). -# Set to 0 if no checkpoints are required. Default is 10 -checkpoint_every_n_episodes: 10 - -# Time delay (milliseconds) between steps for CUSTOM agents. -time_delay: 5 - -# Type of session to be run. Options are: -# "TRAIN" (Trains an agent) -# "EVAL" (Evaluates an agent) -# "TRAIN_EVAL" (Trains then evaluates an agent) -session_type: EVAL - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1000000000 - -implicit_acl_rule: DENY -max_number_acl_rules: 10 -# The Stable Baselines3 learn/eval output verbosity level: -# Options are: -# "NONE" (No Output) -# "INFO" (Info Messages (such as devices and wrappers used)) -# "DEBUG" (All Messages) -sb3_output_verbose_level: NONE - -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -10 -off_should_be_resetting: -5 -on_should_be_off: -2 -on_should_be_resetting: -5 -resetting_should_be_on: -5 -resetting_should_be_off: -2 -resetting: -3 -# Node Software or Service State -good_should_be_patching: 2 -good_should_be_compromised: 5 -good_should_be_overwhelmed: 5 -patching_should_be_good: -5 -patching_should_be_compromised: 2 -patching_should_be_overwhelmed: 2 -patching: -3 -compromised_should_be_good: -20 -compromised_should_be_patching: -20 -compromised_should_be_overwhelmed: -20 -compromised: -20 -overwhelmed_should_be_good: -20 -overwhelmed_should_be_patching: -20 -overwhelmed_should_be_compromised: -20 -overwhelmed: -20 -# Node File System State -good_should_be_repairing: 2 -good_should_be_restoring: 2 -good_should_be_corrupt: 5 -good_should_be_destroyed: 10 -repairing_should_be_good: -5 -repairing_should_be_restoring: 2 -repairing_should_be_corrupt: 2 -repairing_should_be_destroyed: 0 -repairing: -3 -restoring_should_be_good: -10 -restoring_should_be_repairing: -2 -restoring_should_be_corrupt: 1 -restoring_should_be_destroyed: 2 -restoring: -6 -corrupt_should_be_good: -10 -corrupt_should_be_repairing: -10 -corrupt_should_be_restoring: -10 -corrupt_should_be_destroyed: 2 -corrupt: -10 -destroyed_should_be_good: -20 -destroyed_should_be_repairing: -20 -destroyed_should_be_restoring: -20 -destroyed_should_be_corrupt: -20 -destroyed: -20 -scanning: -2 -# IER status -red_ier_running: -5 -green_ier_blocked: -10 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/ppo_not_seeded_training_config.yaml b/tests/config/ppo_not_seeded_training_config.yaml deleted file mode 100644 index fac2fe95..00000000 --- a/tests/config/ppo_not_seeded_training_config.yaml +++ /dev/null @@ -1,162 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: SB3 - -# Sets which deep learning framework will be used (by RLlib ONLY). -# Default is TF (Tensorflow). -# Options are: -# "TF" (Tensorflow) -# TF2 (Tensorflow 2.X) -# TORCH (PyTorch) -deep_learning_framework: TF2 - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: PPO - -# Sets whether Red Agent POL and IER is randomised. -# Options are: -# True -# False -random_red_agent: False - -# The (integer) seed to be used in random number generation -# Default is None (null) -seed: None - -# Set whether the agent evaluation will be deterministic instead of stochastic -# Options are: -# True -# False -deterministic: False - -# Sets what view of the environment the deterministic hardcoded agent has. The default is BASIC. -# Options are: -# "BASIC" (The current observation space only) -# "FULL" (Full environment view with actions taken and reward feedback) -hard_coded_agent_view: FULL - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: NODE -# observation space -observation_space: - components: - - name: NODE_LINK_TABLE - # - name: NODE_STATUSES - # - name: LINK_TRAFFIC_LEVELS - # - name: ACCESS_CONTROL_LIST -# Number of episodes to run per session -num_train_episodes: 10 - -# Number of time_steps per episode -num_train_steps: 256 - -# Number of episodes to run per session -num_eval_episodes: 10 - -# Number of time_steps per episode -num_eval_steps: 256 - -# Sets how often the agent will save a checkpoint (every n time episodes). -# Set to 0 if no checkpoints are required. Default is 10 -checkpoint_every_n_episodes: 0 - -# Time delay (milliseconds) between steps for CUSTOM agents. -time_delay: 5 - -# Type of session to be run. Options are: -# "TRAIN" (Trains an agent) -# "EVAL" (Evaluates an agent) -# "TRAIN_EVAL" (Trains then evaluates an agent) -session_type: TRAIN_EVAL - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1000000000 - -# The Stable Baselines3 learn/eval output verbosity level: -# Options are: -# "NONE" (No Output) -# "INFO" (Info Messages (such as devices and wrappers used)) -# "DEBUG" (All Messages) -sb3_output_verbose_level: NONE - -# Reward values -# Generic -all_ok: 0.0000 -# Node Hardware State -off_should_be_on: -0.001 -off_should_be_resetting: -0.0005 -on_should_be_off: -0.0002 -on_should_be_resetting: -0.0005 -resetting_should_be_on: -0.0005 -resetting_should_be_off: -0.0002 -resetting: -0.0003 -# Node Software or Service State -good_should_be_patching: 0.0002 -good_should_be_compromised: 0.0005 -good_should_be_overwhelmed: 0.0005 -patching_should_be_good: -0.0005 -patching_should_be_compromised: 0.0002 -patching_should_be_overwhelmed: 0.0002 -patching: -0.0003 -compromised_should_be_good: -0.002 -compromised_should_be_patching: -0.002 -compromised_should_be_overwhelmed: -0.002 -compromised: -0.002 -overwhelmed_should_be_good: -0.002 -overwhelmed_should_be_patching: -0.002 -overwhelmed_should_be_compromised: -0.002 -overwhelmed: -0.002 -# Node File System State -good_should_be_repairing: 0.0002 -good_should_be_restoring: 0.0002 -good_should_be_corrupt: 0.0005 -good_should_be_destroyed: 0.001 -repairing_should_be_good: -0.0005 -repairing_should_be_restoring: 0.0002 -repairing_should_be_corrupt: 0.0002 -repairing_should_be_destroyed: 0.0000 -repairing: -0.0003 -restoring_should_be_good: -0.001 -restoring_should_be_repairing: -0.0002 -restoring_should_be_corrupt: 0.0001 -restoring_should_be_destroyed: 0.0002 -restoring: -0.0006 -corrupt_should_be_good: -0.001 -corrupt_should_be_repairing: -0.001 -corrupt_should_be_restoring: -0.001 -corrupt_should_be_destroyed: 0.0002 -corrupt: -0.001 -destroyed_should_be_good: -0.002 -destroyed_should_be_repairing: -0.002 -destroyed_should_be_restoring: -0.002 -destroyed_should_be_corrupt: -0.002 -destroyed: -0.002 -scanning: -0.0002 -# IER status -red_ier_running: -0.0005 -green_ier_blocked: -0.001 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/ppo_seeded_training_config.yaml b/tests/config/ppo_seeded_training_config.yaml deleted file mode 100644 index e4d4fe5b..00000000 --- a/tests/config/ppo_seeded_training_config.yaml +++ /dev/null @@ -1,161 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: SB3 - -# Sets which deep learning framework will be used (by RLlib ONLY). -# Default is TF (Tensorflow). -# Options are: -# "TF" (Tensorflow) -# TF2 (Tensorflow 2.X) -# TORCH (PyTorch) -deep_learning_framework: TF2 - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: PPO - -# Sets whether Red Agent POL and IER is randomised. -# Options are: -# True -# False -random_red_agent: False - -# The (integer) seed to be used in random number generation -# Default is None (null) -seed: 67890 - -# Set whether the agent evaluation will be deterministic instead of stochastic -# Options are: -# True -# False -deterministic: True - -# Sets what view of the environment the deterministic hardcoded agent has. The default is BASIC. -# Options are: -# "BASIC" (The current observation space only) -# "FULL" (Full environment view with actions taken and reward feedback) -hard_coded_agent_view: FULL - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: NODE -# observation space -observation_space: - components: - - name: NODE_LINK_TABLE - # - name: NODE_STATUSES - # - name: LINK_TRAFFIC_LEVELS -# Number of episodes to run per session -num_train_episodes: 10 - -# Number of time_steps per episode -num_train_steps: 256 - -# Number of episodes to run per session -num_eval_episodes: 1 - -# Number of time_steps per episode -num_eval_steps: 256 - -# Sets how often the agent will save a checkpoint (every n time episodes). -# Set to 0 if no checkpoints are required. Default is 10 -checkpoint_every_n_episodes: 0 - -# Time delay (milliseconds) between steps for CUSTOM agents. -time_delay: 5 - -# Type of session to be run. Options are: -# "TRAIN" (Trains an agent) -# "EVAL" (Evaluates an agent) -# "TRAIN_EVAL" (Trains then evaluates an agent) -session_type: TRAIN_EVAL - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1000000000 - -# The Stable Baselines3 learn/eval output verbosity level: -# Options are: -# "NONE" (No Output) -# "INFO" (Info Messages (such as devices and wrappers used)) -# "DEBUG" (All Messages) -sb3_output_verbose_level: NONE - -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -10 -off_should_be_resetting: -5 -on_should_be_off: -2 -on_should_be_resetting: -5 -resetting_should_be_on: -5 -resetting_should_be_off: -2 -resetting: -3 -# Node Software or Service State -good_should_be_patching: 2 -good_should_be_compromised: 5 -good_should_be_overwhelmed: 5 -patching_should_be_good: -5 -patching_should_be_compromised: 2 -patching_should_be_overwhelmed: 2 -patching: -3 -compromised_should_be_good: -20 -compromised_should_be_patching: -20 -compromised_should_be_overwhelmed: -20 -compromised: -20 -overwhelmed_should_be_good: -20 -overwhelmed_should_be_patching: -20 -overwhelmed_should_be_compromised: -20 -overwhelmed: -20 -# Node File System State -good_should_be_repairing: 2 -good_should_be_restoring: 2 -good_should_be_corrupt: 5 -good_should_be_destroyed: 10 -repairing_should_be_good: -5 -repairing_should_be_restoring: 2 -repairing_should_be_corrupt: 2 -repairing_should_be_destroyed: 0 -repairing: -3 -restoring_should_be_good: -10 -restoring_should_be_repairing: -2 -restoring_should_be_corrupt: 1 -restoring_should_be_destroyed: 2 -restoring: -6 -corrupt_should_be_good: -10 -corrupt_should_be_repairing: -10 -corrupt_should_be_restoring: -10 -corrupt_should_be_destroyed: 2 -corrupt: -10 -destroyed_should_be_good: -20 -destroyed_should_be_repairing: -20 -destroyed_should_be_restoring: -20 -destroyed_should_be_corrupt: -20 -destroyed: -20 -scanning: -2 -# IER status -red_ier_running: -5 -green_ier_blocked: -10 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/session_test/training_config_main_rllib.yaml b/tests/config/session_test/training_config_main_rllib.yaml deleted file mode 100644 index 374c6ac5..00000000 --- a/tests/config/session_test/training_config_main_rllib.yaml +++ /dev/null @@ -1,164 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: RLLIB - -# Sets which deep learning framework will be used (by RLlib ONLY). -# Default is TF (Tensorflow). -# Options are: -# "TF" (Tensorflow) -# TF2 (Tensorflow 2.X) -# TORCH (PyTorch) -deep_learning_framework: TF2 - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: PPO - -# Sets whether Red Agent POL and IER is randomised. -# Options are: -# True -# False -random_red_agent: False - -# The (integer) seed to be used in random number generation -# Default is None (null) -seed: null - -# Set whether the agent will be deterministic instead of stochastic -# Options are: -# True -# False -deterministic: False - -# Sets what view of the environment the deterministic hardcoded agent has. The default is BASIC. -# Options are: -# "BASIC" (The current observation space only) -# "FULL" (Full environment view with actions taken and reward feedback) -hard_coded_agent_view: FULL - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: NODE -# observation space -observation_space: - # flatten: true - components: - - name: NODE_LINK_TABLE - # - name: NODE_STATUSES - # - name: LINK_TRAFFIC_LEVELS - - -# Number of episodes for training to run per session -num_train_episodes: 10 - -# Number of time_steps for training per episode -num_train_steps: 256 - -# Number of episodes for evaluation to run per session -num_eval_episodes: 3 - -# Number of time_steps for evaluation per episode -num_eval_steps: 256 - -# Sets how often the agent will save a checkpoint (every n time episodes). -# Set to 0 if no checkpoints are required. Default is 10 -checkpoint_every_n_episodes: 10 - -# Time delay (milliseconds) between steps for CUSTOM agents. -time_delay: 5 - -# Type of session to be run. Options are: -# "TRAIN" (Trains an agent) -# "EVAL" (Evaluates an agent) -# "TRAIN_EVAL" (Trains then evaluates an agent) -session_type: TRAIN_EVAL - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1000000000 - -# The Stable Baselines3 learn/eval output verbosity level: -# Options are: -# "NONE" (No Output) -# "INFO" (Info Messages (such as devices and wrappers used)) -# "DEBUG" (All Messages) -sb3_output_verbose_level: NONE - -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -0.001 -off_should_be_resetting: -0.0005 -on_should_be_off: -0.0002 -on_should_be_resetting: -0.0005 -resetting_should_be_on: -0.0005 -resetting_should_be_off: -0.0002 -resetting: -0.0003 -# Node Software or Service State -good_should_be_patching: 0.0002 -good_should_be_compromised: 0.0005 -good_should_be_overwhelmed: 0.0005 -patching_should_be_good: -0.0005 -patching_should_be_compromised: 0.0002 -patching_should_be_overwhelmed: 0.0002 -patching: -0.0003 -compromised_should_be_good: -0.002 -compromised_should_be_patching: -0.002 -compromised_should_be_overwhelmed: -0.002 -compromised: -0.002 -overwhelmed_should_be_good: -0.002 -overwhelmed_should_be_patching: -0.002 -overwhelmed_should_be_compromised: -0.002 -overwhelmed: -0.002 -# Node File System State -good_should_be_repairing: 0.0002 -good_should_be_restoring: 0.0002 -good_should_be_corrupt: 0.0005 -good_should_be_destroyed: 0.001 -repairing_should_be_good: -0.0005 -repairing_should_be_restoring: 0.0002 -repairing_should_be_corrupt: 0.0002 -repairing_should_be_destroyed: 0.0000 -repairing: -0.0003 -restoring_should_be_good: -0.001 -restoring_should_be_repairing: -0.0002 -restoring_should_be_corrupt: 0.0001 -restoring_should_be_destroyed: 0.0002 -restoring: -0.0006 -corrupt_should_be_good: -0.001 -corrupt_should_be_repairing: -0.001 -corrupt_should_be_restoring: -0.001 -corrupt_should_be_destroyed: 0.0002 -corrupt: -0.001 -destroyed_should_be_good: -0.002 -destroyed_should_be_repairing: -0.002 -destroyed_should_be_restoring: -0.002 -destroyed_should_be_corrupt: -0.002 -destroyed: -0.002 -scanning: -0.0002 -# IER status -red_ier_running: -0.0005 -green_ier_blocked: -0.001 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/session_test/training_config_main_sb3.yaml b/tests/config/session_test/training_config_main_sb3.yaml deleted file mode 100644 index 733105ea..00000000 --- a/tests/config/session_test/training_config_main_sb3.yaml +++ /dev/null @@ -1,164 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: SB3 - -# Sets which deep learning framework will be used (by RLlib ONLY). -# Default is TF (Tensorflow). -# Options are: -# "TF" (Tensorflow) -# TF2 (Tensorflow 2.X) -# TORCH (PyTorch) -deep_learning_framework: TF2 - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: PPO - -# Sets whether Red Agent POL and IER is randomised. -# Options are: -# True -# False -random_red_agent: False - -# The (integer) seed to be used in random number generation -# Default is None (null) -seed: null - -# Set whether the agent will be deterministic instead of stochastic -# Options are: -# True -# False -deterministic: False - -# Sets what view of the environment the deterministic hardcoded agent has. The default is BASIC. -# Options are: -# "BASIC" (The current observation space only) -# "FULL" (Full environment view with actions taken and reward feedback) -hard_coded_agent_view: FULL - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: NODE -# observation space -observation_space: - # flatten: true - components: - - name: NODE_LINK_TABLE - # - name: NODE_STATUSES - # - name: LINK_TRAFFIC_LEVELS - - -# Number of episodes for training to run per session -num_train_episodes: 10 - -# Number of time_steps for training per episode -num_train_steps: 256 - -# Number of episodes for evaluation to run per session -num_eval_episodes: 3 - -# Number of time_steps for evaluation per episode -num_eval_steps: 256 - -# Sets how often the agent will save a checkpoint (every n time episodes). -# Set to 0 if no checkpoints are required. Default is 10 -checkpoint_every_n_episodes: 10 - -# Time delay (milliseconds) between steps for CUSTOM agents. -time_delay: 5 - -# Type of session to be run. Options are: -# "TRAIN" (Trains an agent) -# "EVAL" (Evaluates an agent) -# "TRAIN_EVAL" (Trains then evaluates an agent) -session_type: TRAIN_EVAL - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1000000000 - -# The Stable Baselines3 learn/eval output verbosity level: -# Options are: -# "NONE" (No Output) -# "INFO" (Info Messages (such as devices and wrappers used)) -# "DEBUG" (All Messages) -sb3_output_verbose_level: NONE - -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -0.001 -off_should_be_resetting: -0.0005 -on_should_be_off: -0.0002 -on_should_be_resetting: -0.0005 -resetting_should_be_on: -0.0005 -resetting_should_be_off: -0.0002 -resetting: -0.0003 -# Node Software or Service State -good_should_be_patching: 0.0002 -good_should_be_compromised: 0.0005 -good_should_be_overwhelmed: 0.0005 -patching_should_be_good: -0.0005 -patching_should_be_compromised: 0.0002 -patching_should_be_overwhelmed: 0.0002 -patching: -0.0003 -compromised_should_be_good: -0.002 -compromised_should_be_patching: -0.002 -compromised_should_be_overwhelmed: -0.002 -compromised: -0.002 -overwhelmed_should_be_good: -0.002 -overwhelmed_should_be_patching: -0.002 -overwhelmed_should_be_compromised: -0.002 -overwhelmed: -0.002 -# Node File System State -good_should_be_repairing: 0.0002 -good_should_be_restoring: 0.0002 -good_should_be_corrupt: 0.0005 -good_should_be_destroyed: 0.001 -repairing_should_be_good: -0.0005 -repairing_should_be_restoring: 0.0002 -repairing_should_be_corrupt: 0.0002 -repairing_should_be_destroyed: 0.0000 -repairing: -0.0003 -restoring_should_be_good: -0.001 -restoring_should_be_repairing: -0.0002 -restoring_should_be_corrupt: 0.0001 -restoring_should_be_destroyed: 0.0002 -restoring: -0.0006 -corrupt_should_be_good: -0.001 -corrupt_should_be_repairing: -0.001 -corrupt_should_be_restoring: -0.001 -corrupt_should_be_destroyed: 0.0002 -corrupt: -0.001 -destroyed_should_be_good: -0.002 -destroyed_should_be_repairing: -0.002 -destroyed_should_be_restoring: -0.002 -destroyed_should_be_corrupt: -0.002 -destroyed: -0.002 -scanning: -0.0002 -# IER status -red_ier_running: -0.0005 -green_ier_blocked: -0.001 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/single_action_space_fixed_blue_actions_main_config.yaml b/tests/config/single_action_space_fixed_blue_actions_main_config.yaml deleted file mode 100644 index 6210cf3e..00000000 --- a/tests/config/single_action_space_fixed_blue_actions_main_config.yaml +++ /dev/null @@ -1,117 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: CUSTOM - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: RANDOM - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: ANY -# Number of episodes for training to run per session -num_train_episodes: 1 - -# Number of time_steps for training per episode -num_train_steps: 15 - -# Time delay between steps (for generic agents) -time_delay: 1 -# Type of session to be run (TRAINING or EVALUATION) -session_type: EVAL -# Determine whether to load an agent from file -load_agent: False -# File path and file name of agent if you're loading one in -agent_load_file: C:\[Path]\[agent_saved_filename.zip] - -# Implicit ACL firewall rule at end of lists to be default action or no rule can be selected (ALLOW or DENY) -implicit_acl_rule: DENY -# Total number of ACL rules allowed in the environment -max_number_acl_rules: 10 - -observation_space: - components: - - name: ACCESS_CONTROL_LIST - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1000000000 - -# Reward values -# Generic -all_ok: 0 -# Node Operating State -off_should_be_on: -10 -off_should_be_resetting: -5 -on_should_be_off: -2 -on_should_be_resetting: -5 -resetting_should_be_on: -5 -resetting_should_be_off: -2 -resetting: -3 -# Node O/S or Service State -good_should_be_patching: 2 -good_should_be_compromised: 5 -good_should_be_overwhelmed: 5 -patching_should_be_good: -5 -patching_should_be_compromised: 2 -patching_should_be_overwhelmed: 2 -patching: -3 -compromised_should_be_good: -20 -compromised_should_be_patching: -20 -compromised_should_be_overwhelmed: -20 -compromised: -20 -overwhelmed_should_be_good: -20 -overwhelmed_should_be_patching: -20 -overwhelmed_should_be_compromised: -20 -overwhelmed: -20 -# Node File System State -good_should_be_repairing: 2 -good_should_be_restoring: 2 -good_should_be_corrupt: 5 -good_should_be_destroyed: 10 -repairing_should_be_good: -5 -repairing_should_be_restoring: 2 -repairing_should_be_corrupt: 2 -repairing_should_be_destroyed: 0 -repairing: -3 -restoring_should_be_good: -10 -restoring_should_be_repairing: -2 -restoring_should_be_corrupt: 1 -restoring_should_be_destroyed: 2 -restoring: -6 -corrupt_should_be_good: -10 -corrupt_should_be_repairing: -10 -corrupt_should_be_restoring: -10 -corrupt_should_be_destroyed: 2 -corrupt: -10 -destroyed_should_be_good: -20 -destroyed_should_be_repairing: -20 -destroyed_should_be_restoring: -20 -destroyed_should_be_corrupt: -20 -destroyed: -20 -scanning: -2 -# IER status -red_ier_running: -5 -green_ier_blocked: -10 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/single_action_space_lay_down_config.yaml b/tests/config/single_action_space_lay_down_config.yaml deleted file mode 100644 index 9103e2b7..00000000 --- a/tests/config/single_action_space_lay_down_config.yaml +++ /dev/null @@ -1,45 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -- item_type: PORTS - ports_list: - - port: '80' -- item_type: SERVICES - service_list: - - name: TCP -- item_type: NODE - node_id: '1' - name: node - node_class: SERVICE - node_type: COMPUTER - priority: P1 - hardware_state: 'ON' - ip_address: 192.168.0.14 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: COMPROMISED -- item_type: NODE - node_id: '2' - name: server_1 - node_class: SERVICE - node_type: SERVER - priority: P1 - hardware_state: 'ON' - ip_address: 192.168.0.1 - software_state: GOOD - file_system_state: GOOD - services: - - name: TCP - port: '80' - state: COMPROMISED -- item_type: RED_IER - id: '3' - start_step: 2 - end_step: 15 - load: 1000 - protocol: TCP - port: CORRUPT - source: '1' - destination: '2' - mission_criticality: 0 diff --git a/tests/config/single_action_space_main_config.yaml b/tests/config/single_action_space_main_config.yaml deleted file mode 100644 index 67eaf49d..00000000 --- a/tests/config/single_action_space_main_config.yaml +++ /dev/null @@ -1,116 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: CUSTOM - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: RANDOM - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: ANY -# Number of episodes for training to run per session -num_train_episodes: 10 - -# Number of time_steps for training per episode -num_train_steps: 256 - -# Number of episodes for evaluation to run per session -num_eval_episodes: 10 - -# Number of time_steps for evaluation per episode -num_eval_steps: 256 -# Time delay between steps (for generic agents) -time_delay: 1 -# Type of session to be run (TRAINING or EVALUATION) -session_type: EVAL -# Determine whether to load an agent from file -load_agent: False -# File path and file name of agent if you're loading one in -agent_load_file: C:\[Path]\[agent_saved_filename.zip] - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1000000000 - -# Choice whether to have an ALLOW or DENY implicit rule or not (TRUE or FALSE) -implicit_acl_rule: DENY -max_number_acl_rules: 10 -# Reward values -# Generic -all_ok: 0 -# Node Operating State -off_should_be_on: -10 -off_should_be_resetting: -5 -on_should_be_off: -2 -on_should_be_resetting: -5 -resetting_should_be_on: -5 -resetting_should_be_off: -2 -resetting: -3 -# Node O/S or Service State -good_should_be_patching: 2 -good_should_be_compromised: 5 -good_should_be_overwhelmed: 5 -patching_should_be_good: -5 -patching_should_be_compromised: 2 -patching_should_be_overwhelmed: 2 -patching: -3 -compromised_should_be_good: -20 -compromised_should_be_patching: -20 -compromised_should_be_overwhelmed: -20 -compromised: -20 -overwhelmed_should_be_good: -20 -overwhelmed_should_be_patching: -20 -overwhelmed_should_be_compromised: -20 -overwhelmed: -20 -# Node File System State -good_should_be_repairing: 2 -good_should_be_restoring: 2 -good_should_be_corrupt: 5 -good_should_be_destroyed: 10 -repairing_should_be_good: -5 -repairing_should_be_restoring: 2 -repairing_should_be_corrupt: 2 -repairing_should_be_destroyed: 0 -repairing: -3 -restoring_should_be_good: -10 -restoring_should_be_repairing: -2 -restoring_should_be_corrupt: 1 -restoring_should_be_destroyed: 2 -restoring: -6 -corrupt_should_be_good: -10 -corrupt_should_be_repairing: -10 -corrupt_should_be_restoring: -10 -corrupt_should_be_destroyed: 2 -corrupt: -10 -destroyed_should_be_good: -20 -destroyed_should_be_repairing: -20 -destroyed_should_be_restoring: -20 -destroyed_should_be_corrupt: -20 -destroyed: -20 -scanning: -2 -# IER status -red_ier_running: -5 -green_ier_blocked: -10 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/test_random_red_main_config.yaml b/tests/config/test_random_red_main_config.yaml deleted file mode 100644 index 310c9dc6..00000000 --- a/tests/config/test_random_red_main_config.yaml +++ /dev/null @@ -1,164 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: SB3 - -# Sets which deep learning framework will be used (by RLlib ONLY). -# Default is TF (Tensorflow). -# Options are: -# "TF" (Tensorflow) -# TF2 (Tensorflow 2.X) -# TORCH (PyTorch) -deep_learning_framework: TF2 - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: PPO - -# Sets whether Red Agent POL and IER is randomised. -# Options are: -# True -# False -random_red_agent: True - -# The (integer) seed to be used in random number generation -# Default is None (null) -seed: null - -# Set whether the agent will be deterministic instead of stochastic -# Options are: -# True -# False -deterministic: False - -# Sets what view of the environment the deterministic hardcoded agent has. The default is BASIC. -# Options are: -# "BASIC" (The current observation space only) -# "FULL" (Full environment view with actions taken and reward feedback) -hard_coded_agent_view: FULL - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: NODE -# observation space -observation_space: - # flatten: true - components: - - name: NODE_LINK_TABLE - # - name: NODE_STATUSES - # - name: LINK_TRAFFIC_LEVELS - - -# Number of episodes for training to run per session -num_train_episodes: 10 - -# Number of time_steps for training per episode -num_train_steps: 256 - -# Number of episodes for evaluation to run per session -num_eval_episodes: 1 - -# Number of time_steps for evaluation per episode -num_eval_steps: 256 - -# Sets how often the agent will save a checkpoint (every n time episodes). -# Set to 0 if no checkpoints are required. Default is 10 -checkpoint_every_n_episodes: 10 - -# Time delay (milliseconds) between steps for CUSTOM agents. -time_delay: 5 - -# Type of session to be run. Options are: -# "TRAIN" (Trains an agent) -# "EVAL" (Evaluates an agent) -# "TRAIN_EVAL" (Trains then evaluates an agent) -session_type: TRAIN_EVAL - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1000000000 - -# The Stable Baselines3 learn/eval output verbosity level: -# Options are: -# "NONE" (No Output) -# "INFO" (Info Messages (such as devices and wrappers used)) -# "DEBUG" (All Messages) -sb3_output_verbose_level: NONE - -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -0.001 -off_should_be_resetting: -0.0005 -on_should_be_off: -0.0002 -on_should_be_resetting: -0.0005 -resetting_should_be_on: -0.0005 -resetting_should_be_off: -0.0002 -resetting: -0.0003 -# Node Software or Service State -good_should_be_patching: 0.0002 -good_should_be_compromised: 0.0005 -good_should_be_overwhelmed: 0.0005 -patching_should_be_good: -0.0005 -patching_should_be_compromised: 0.0002 -patching_should_be_overwhelmed: 0.0002 -patching: -0.0003 -compromised_should_be_good: -0.002 -compromised_should_be_patching: -0.002 -compromised_should_be_overwhelmed: -0.002 -compromised: -0.002 -overwhelmed_should_be_good: -0.002 -overwhelmed_should_be_patching: -0.002 -overwhelmed_should_be_compromised: -0.002 -overwhelmed: -0.002 -# Node File System State -good_should_be_repairing: 0.0002 -good_should_be_restoring: 0.0002 -good_should_be_corrupt: 0.0005 -good_should_be_destroyed: 0.001 -repairing_should_be_good: -0.0005 -repairing_should_be_restoring: 0.0002 -repairing_should_be_corrupt: 0.0002 -repairing_should_be_destroyed: 0.0000 -repairing: -0.0003 -restoring_should_be_good: -0.001 -restoring_should_be_repairing: -0.0002 -restoring_should_be_corrupt: 0.0001 -restoring_should_be_destroyed: 0.0002 -restoring: -0.0006 -corrupt_should_be_good: -0.001 -corrupt_should_be_repairing: -0.001 -corrupt_should_be_restoring: -0.001 -corrupt_should_be_destroyed: 0.0002 -corrupt: -0.001 -destroyed_should_be_good: -0.002 -destroyed_should_be_repairing: -0.002 -destroyed_should_be_restoring: -0.002 -destroyed_should_be_corrupt: -0.002 -destroyed: -0.002 -scanning: -0.0002 -# IER status -red_ier_running: -0.0005 -green_ier_blocked: -0.001 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/config/train_episode_step.yaml b/tests/config/train_episode_step.yaml deleted file mode 100644 index a86e0f62..00000000 --- a/tests/config/train_episode_step.yaml +++ /dev/null @@ -1,154 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -# Training Config File - -# Sets which agent algorithm framework will be used. -# Options are: -# "SB3" (Stable Baselines3) -# "RLLIB" (Ray RLlib) -# "CUSTOM" (Custom Agent) -agent_framework: SB3 - -# Sets which deep learning framework will be used (by RLlib ONLY). -# Default is TF (Tensorflow). -# Options are: -# "TF" (Tensorflow) -# TF2 (Tensorflow 2.X) -# TORCH (PyTorch) -deep_learning_framework: TF2 - -# Sets which Agent class will be used. -# Options are: -# "A2C" (Advantage Actor Critic coupled with either SB3 or RLLIB agent_framework) -# "PPO" (Proximal Policy Optimization coupled with either SB3 or RLLIB agent_framework) -# "HARDCODED" (The HardCoded agents coupled with an ACL or NODE action_type) -# "DO_NOTHING" (The DoNothing agents coupled with an ACL or NODE action_type) -# "RANDOM" (primaite.agents.simple.RandomAgent) -# "DUMMY" (primaite.agents.simple.DummyAgent) -agent_identifier: PPO - -# Sets whether Red Agent POL and IER is randomised. -# Options are: -# True -# False -random_red_agent: False - -# Sets what view of the environment the deterministic hardcoded agent has. The default is BASIC. -# Options are: -# "BASIC" (The current observation space only) -# "FULL" (Full environment view with actions taken and reward feedback) -hard_coded_agent_view: FULL - -# Sets How the Action Space is defined: -# "NODE" -# "ACL" -# "ANY" node and acl actions -action_type: NODE -# observation space -observation_space: - # flatten: true - components: - - name: NODE_LINK_TABLE - # - name: NODE_STATUSES - # - name: LINK_TRAFFIC_LEVELS - - -# Number of episodes for training to run per session -num_train_episodes: 3 - -# Number of time_steps for training per episode -num_train_steps: 25 - -# Number of episodes for evaluation to run per session -num_eval_episodes: 1 - -# Number of time_steps for evaluation per episode -num_eval_steps: 17 - -# Sets how often the agent will save a checkpoint (every n time episodes). -# Set to 0 if no checkpoints are required. Default is 10 -checkpoint_every_n_episodes: 0 - -# Time delay (milliseconds) between steps for CUSTOM agents. -time_delay: 5 - -# Type of session to be run. Options are: -# "TRAIN" (Trains an agent) -# "EVAL" (Evaluates an agent) -# "TRAIN_EVAL" (Trains then evaluates an agent) -session_type: TRAIN_EVAL - -# Environment config values -# The high value for the observation space -observation_space_high_value: 1000000000 - -# The Stable Baselines3 learn/eval output verbosity level: -# Options are: -# "NONE" (No Output) -# "INFO" (Info Messages (such as devices and wrappers used)) -# "DEBUG" (All Messages) -sb3_output_verbose_level: NONE - -# Reward values -# Generic -all_ok: 0 -# Node Hardware State -off_should_be_on: -10 -off_should_be_resetting: -5 -on_should_be_off: -2 -on_should_be_resetting: -5 -resetting_should_be_on: -5 -resetting_should_be_off: -2 -resetting: -3 -# Node Software or Service State -good_should_be_patching: 2 -good_should_be_compromised: 5 -good_should_be_overwhelmed: 5 -patching_should_be_good: -5 -patching_should_be_compromised: 2 -patching_should_be_overwhelmed: 2 -patching: -3 -compromised_should_be_good: -20 -compromised_should_be_patching: -20 -compromised_should_be_overwhelmed: -20 -compromised: -20 -overwhelmed_should_be_good: -20 -overwhelmed_should_be_patching: -20 -overwhelmed_should_be_compromised: -20 -overwhelmed: -20 -# Node File System State -good_should_be_repairing: 2 -good_should_be_restoring: 2 -good_should_be_corrupt: 5 -good_should_be_destroyed: 10 -repairing_should_be_good: -5 -repairing_should_be_restoring: 2 -repairing_should_be_corrupt: 2 -repairing_should_be_destroyed: 0 -repairing: -3 -restoring_should_be_good: -10 -restoring_should_be_repairing: -2 -restoring_should_be_corrupt: 1 -restoring_should_be_destroyed: 2 -restoring: -6 -corrupt_should_be_good: -10 -corrupt_should_be_repairing: -10 -corrupt_should_be_restoring: -10 -corrupt_should_be_destroyed: 2 -corrupt: -10 -destroyed_should_be_good: -20 -destroyed_should_be_repairing: -20 -destroyed_should_be_restoring: -20 -destroyed_should_be_corrupt: -20 -destroyed: -20 -scanning: -2 -# IER status -red_ier_running: -5 -green_ier_blocked: -10 - -# Patching / Reset durations -os_patching_duration: 5 # The time taken to patch the OS -node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service -file_system_repairing_limit: 5 # The time take to repair the file system -file_system_restoring_limit: 5 # The time take to restore the file system -file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/tests/conftest.py b/tests/conftest.py index d8c9cc50..425acc09 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,8 +10,9 @@ from unittest.mock import patch import pytest from primaite import getLogger -from primaite.environment.primaite_env import Primaite -from primaite.primaite_session import PrimaiteSession + +# from primaite.environment.primaite_env import Primaite +# from primaite.primaite_session import PrimaiteSession from primaite.simulator.network.container import Network from primaite.simulator.network.networks import arcd_uc2_network from primaite.simulator.network.transmission.transport_layer import Port @@ -53,6 +54,7 @@ def file_system() -> FileSystem: return Node(hostname="fs_node").file_system +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 # PrimAITE v2 stuff class TempPrimaiteSession(PrimaiteSession): """ @@ -82,6 +84,7 @@ class TempPrimaiteSession(PrimaiteSession): _LOGGER.debug(f"Deleted temp session directory: {self.session_path}") +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.fixture def temp_primaite_session(request): """ @@ -136,6 +139,7 @@ def temp_primaite_session(request): return TempPrimaiteSession(training_config_path, lay_down_config_path) +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.fixture def temp_session_path() -> Path: """ diff --git a/tests/test_acl.py b/tests/test_acl.py index d8357cf6..a0dfb997 100644 --- a/tests/test_acl.py +++ b/tests/test_acl.py @@ -1,11 +1,12 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK """Used to tes the ACL functions.""" -from primaite.acl.access_control_list import AccessControlList -from primaite.acl.acl_rule import ACLRule -from primaite.common.enums import RulePermissionType +# from primaite.acl.access_control_list import AccessControlList +# from primaite.acl.acl_rule import ACLRule +# from primaite.common.enums import RulePermissionType +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 def test_acl_address_match_1(): """Test that matching IP addresses produce True.""" acl = AccessControlList(RulePermissionType.DENY, 10) @@ -15,6 +16,7 @@ def test_acl_address_match_1(): assert acl.check_address_match(rule, "192.168.1.1", "192.168.1.2") == True +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 def test_acl_address_match_2(): """Test that mismatching IP addresses produce False.""" acl = AccessControlList(RulePermissionType.DENY, 10) @@ -24,6 +26,7 @@ def test_acl_address_match_2(): assert acl.check_address_match(rule, "192.168.1.1", "192.168.1.3") == False +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 def test_acl_address_match_3(): """Test the ANY condition for source IP addresses produce True.""" acl = AccessControlList(RulePermissionType.DENY, 10) @@ -33,6 +36,7 @@ def test_acl_address_match_3(): assert acl.check_address_match(rule, "192.168.1.1", "192.168.1.2") == True +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 def test_acl_address_match_4(): """Test the ANY condition for dest IP addresses produce True.""" acl = AccessControlList(RulePermissionType.DENY, 10) @@ -42,6 +46,7 @@ def test_acl_address_match_4(): assert acl.check_address_match(rule, "192.168.1.1", "192.168.1.2") == True +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 def test_check_acl_block_affirmative(): """Test the block function (affirmative).""" # Create the Access Control List @@ -66,6 +71,7 @@ def test_check_acl_block_affirmative(): assert acl.is_blocked("192.168.1.1", "192.168.1.2", "TCP", "80") == False +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 def test_check_acl_block_negative(): """Test the block function (negative).""" # Create the Access Control List @@ -91,6 +97,7 @@ def test_check_acl_block_negative(): assert acl.is_blocked("192.168.1.1", "192.168.1.2", "TCP", "80") == True +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 def test_rule_hash(): """Test the rule hash.""" # Create the Access Control List @@ -104,6 +111,7 @@ def test_rule_hash(): assert hash_value_local == hash_value_remote +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 def test_delete_rule(): """Adds 3 rules and deletes 1 rule and checks its deletion.""" # Create the Access Control List diff --git a/tests/test_active_node.py b/tests/test_active_node.py index 44d38313..cf532bb8 100644 --- a/tests/test_active_node.py +++ b/tests/test_active_node.py @@ -2,10 +2,11 @@ """Used to test Active Node functions.""" import pytest -from primaite.common.enums import FileSystemState, HardwareState, SoftwareState -from primaite.nodes.active_node import ActiveNode +# from primaite.common.enums import FileSystemState, HardwareState, SoftwareState +# from primaite.nodes.active_node import ActiveNode +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "operating_state, expected_state", [ @@ -36,6 +37,7 @@ def test_os_state_change(operating_state, expected_state): assert active_node.software_state == expected_state +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "operating_state, expected_state", [ @@ -66,6 +68,7 @@ def test_os_state_change_if_not_compromised(operating_state, expected_state): assert active_node.software_state == expected_state +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "operating_state, expected_state", [ @@ -92,6 +95,7 @@ def test_file_system_change(operating_state, expected_state): assert active_node.file_system_state_actual == expected_state +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "operating_state, expected_state", [ diff --git a/tests/test_full_legacy_config_session.py b/tests/test_full_legacy_config_session.py index 066ff72c..ac727a22 100644 --- a/tests/test_full_legacy_config_session.py +++ b/tests/test_full_legacy_config_session.py @@ -6,6 +6,7 @@ from primaite.main import run from tests import TEST_CONFIG_ROOT +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "legacy_file", [ diff --git a/tests/test_lay_down_config.py b/tests/test_lay_down_config.py index 99e66708..83c6063c 100644 --- a/tests/test_lay_down_config.py +++ b/tests/test_lay_down_config.py @@ -2,16 +2,17 @@ import pytest import yaml -from primaite.config.lay_down_config import ( - convert_legacy_lay_down_config, - data_manipulation_config_path, - ddos_basic_one_config_path, - ddos_basic_two_config_path, - dos_very_basic_config_path, -) +# from primaite.config.lay_down_config import ( +# convert_legacy_lay_down_config, +# data_manipulation_config_path, +# ddos_basic_one_config_path, +# ddos_basic_two_config_path, +# dos_very_basic_config_path, +# ) from tests import TEST_CONFIG_ROOT +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "legacy_file, new_path", [ diff --git a/tests/test_observation_space.py b/tests/test_observation_space.py index ff3528e1..b138dd5e 100644 --- a/tests/test_observation_space.py +++ b/tests/test_observation_space.py @@ -4,10 +4,11 @@ import numpy as np import pytest -from primaite.environment.observations import NodeLinkTable, NodeStatuses, ObservationsHandler +# from primaite.environment.observations import NodeLinkTable, NodeStatuses, ObservationsHandler from tests import TEST_CONFIG_ROOT +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "temp_primaite_session", [ @@ -29,6 +30,7 @@ def test_default_obs_space(temp_primaite_session): assert isinstance(components[0], NodeLinkTable) +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "temp_primaite_session", [ @@ -51,6 +53,7 @@ def test_registering_components(temp_primaite_session): assert component not in handler.registered_obs_components +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "temp_primaite_session", [ @@ -140,6 +143,7 @@ class TestNodeLinkTable: ) +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "temp_primaite_session", [ @@ -194,6 +198,7 @@ class TestNodeStatuses: assert np.array_equal(obs, [1, 3, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 0, 0]) +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "temp_primaite_session", [ @@ -240,6 +245,7 @@ class TestLinkTrafficLevels: assert np.array_equal(obs, [6, 0, 6, 0]) +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "temp_primaite_session", [ diff --git a/tests/test_primaite_session.py b/tests/test_primaite_session.py index 6e23b3ac..bf9332a7 100644 --- a/tests/test_primaite_session.py +++ b/tests/test_primaite_session.py @@ -4,12 +4,14 @@ import os import pytest from primaite import getLogger -from primaite.config.lay_down_config import dos_very_basic_config_path + +# from primaite.config.lay_down_config import dos_very_basic_config_path from tests import TEST_CONFIG_ROOT _LOGGER = getLogger(__name__) +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "temp_primaite_session", [ diff --git a/tests/test_red_random_agent_behaviour.py b/tests/test_red_random_agent_behaviour.py index e99f4adb..3f999f9b 100644 --- a/tests/test_red_random_agent_behaviour.py +++ b/tests/test_red_random_agent_behaviour.py @@ -1,11 +1,12 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK import pytest -from primaite.config.lay_down_config import data_manipulation_config_path -from primaite.nodes.node_state_instruction_red import NodeStateInstructionRed +# from primaite.config.lay_down_config import data_manipulation_config_path +# from primaite.nodes.node_state_instruction_red import NodeStateInstructionRed from tests import TEST_CONFIG_ROOT +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "temp_primaite_session", [ diff --git a/tests/test_resetting_node.py b/tests/test_resetting_node.py index d4e27c17..53779c4f 100644 --- a/tests/test_resetting_node.py +++ b/tests/test_resetting_node.py @@ -2,13 +2,14 @@ """Used to test Active Node functions.""" import pytest -from primaite.common.enums import FileSystemState, HardwareState, NodeType, Priority, SoftwareState -from primaite.common.service import Service -from primaite.config.training_config import TrainingConfig -from primaite.nodes.active_node import ActiveNode -from primaite.nodes.service_node import ServiceNode +# from primaite.common.enums import FileSystemState, HardwareState, NodeType, Priority, SoftwareState +# from primaite.common.service import Service +# from primaite.config.training_config import TrainingConfig +# from primaite.nodes.active_node import ActiveNode +# from primaite.nodes.service_node import ServiceNode +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "starting_operating_state, expected_operating_state", [(HardwareState.RESETTING, HardwareState.ON)], @@ -35,6 +36,7 @@ def test_node_resets_correctly(starting_operating_state, expected_operating_stat assert active_node.hardware_state == expected_operating_state +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "operating_state, expected_operating_state", [(HardwareState.BOOTING, HardwareState.ON)], @@ -62,6 +64,7 @@ def test_node_boots_correctly(operating_state, expected_operating_state): assert service_node.hardware_state == expected_operating_state +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "operating_state, expected_operating_state", [(HardwareState.SHUTTING_DOWN, HardwareState.OFF)], diff --git a/tests/test_reward.py b/tests/test_reward.py index 2ac66af1..7a980d32 100644 --- a/tests/test_reward.py +++ b/tests/test_reward.py @@ -7,6 +7,7 @@ from tests import TEST_CONFIG_ROOT _LOGGER = getLogger(__name__) +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "temp_primaite_session", [ diff --git a/tests/test_seeding_and_deterministic_session.py b/tests/test_seeding_and_deterministic_session.py index aff5496a..eed6f4d6 100644 --- a/tests/test_seeding_and_deterministic_session.py +++ b/tests/test_seeding_and_deterministic_session.py @@ -1,10 +1,11 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK import pytest as pytest -from primaite.config.lay_down_config import dos_very_basic_config_path +# from primaite.config.lay_down_config import dos_very_basic_config_path from tests import TEST_CONFIG_ROOT +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "temp_primaite_session", [[TEST_CONFIG_ROOT / "ppo_seeded_training_config.yaml", dos_very_basic_config_path()]], @@ -49,6 +50,7 @@ def test_seeded_learning(temp_primaite_session): assert actual_mean_reward_per_episode == expected_mean_reward_per_episode +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "temp_primaite_session", [[TEST_CONFIG_ROOT / "ppo_seeded_training_config.yaml", dos_very_basic_config_path()]], diff --git a/tests/test_service_node.py b/tests/test_service_node.py index 906bcf55..6b1bd1ee 100644 --- a/tests/test_service_node.py +++ b/tests/test_service_node.py @@ -2,11 +2,12 @@ """Used to test Service Node functions.""" import pytest -from primaite.common.enums import HardwareState, SoftwareState -from primaite.common.service import Service -from primaite.nodes.service_node import ServiceNode +# from primaite.common.enums import HardwareState, SoftwareState +# from primaite.common.service import Service +# from primaite.nodes.service_node import ServiceNode +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "operating_state, expected_state", [ @@ -39,6 +40,7 @@ def test_service_state_change(operating_state, expected_state): assert service_node.get_service_state("TCP") == expected_state +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.mark.parametrize( "operating_state, expected_state", [ diff --git a/tests/test_session_loading.py b/tests/test_session_loading.py index f9990f76..fdec4ede 100644 --- a/tests/test_session_loading.py +++ b/tests/test_session_loading.py @@ -6,14 +6,18 @@ from pathlib import Path from typing import Union from uuid import uuid4 +import pytest from typer.testing import CliRunner from primaite import getLogger -from primaite.agents.sb3 import SB3Agent + +# from primaite.agents.sb3 import SB3Agent from primaite.cli import app -from primaite.common.enums import AgentFramework, AgentIdentifier + +# from primaite.common.enums import AgentFramework, AgentIdentifier from primaite.main import run -from primaite.primaite_session import PrimaiteSession + +# from primaite.primaite_session import PrimaiteSession from primaite.utils.session_output_reader import av_rewards_dict from tests import TEST_ASSETS_ROOT @@ -62,6 +66,7 @@ def copy_session_asset(asset_path: Union[str, Path]) -> str: return copy_path +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 def test_load_sb3_session(): """Test that loading an SB3 agent works.""" test_path = copy_session_asset(TEST_ASSETS_ROOT / "example_sb3_agent_session") @@ -104,6 +109,7 @@ def test_load_sb3_session(): shutil.rmtree(test_path) +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 def test_load_primaite_session(): """Test that loading a Primaite session works.""" test_path = copy_session_asset(TEST_ASSETS_ROOT / "example_sb3_agent_session") @@ -150,6 +156,7 @@ def test_load_primaite_session(): shutil.rmtree(test_path) +@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 def test_run_loading(): """Test loading session via main.run.""" test_path = copy_session_asset(TEST_ASSETS_ROOT / "example_sb3_agent_session") diff --git a/tests/test_single_action_space.py b/tests/test_single_action_space.py index 5d300232..949898cf 100644 --- a/tests/test_single_action_space.py +++ b/tests/test_single_action_space.py @@ -3,12 +3,13 @@ import time import pytest -from primaite.acl.acl_rule import ACLRule -from primaite.common.enums import HardwareState -from primaite.environment.primaite_env import Primaite +# from primaite.acl.acl_rule import ACLRule +# from primaite.common.enums import HardwareState +# from primaite.environment.primaite_env import Primaite from tests import TEST_CONFIG_ROOT +@pytest.skip("Deprecated") def run_generic_set_actions(env: Primaite): """Run against a generic agent with specified blue agent actions.""" # Reset the environment at the start of the episode @@ -47,6 +48,7 @@ def run_generic_set_actions(env: Primaite): # env.close() +@pytest.skip("Deprecated") @pytest.mark.parametrize( "temp_primaite_session", [ @@ -88,6 +90,7 @@ def test_single_action_space_is_valid(temp_primaite_session): assert both_action_spaces +@pytest.skip("Deprecated") @pytest.mark.parametrize( "temp_primaite_session", [ diff --git a/tests/test_train_eval_episode_steps.py b/tests/test_train_eval_episode_steps.py index 1b53fe9d..0be968ae 100644 --- a/tests/test_train_eval_episode_steps.py +++ b/tests/test_train_eval_episode_steps.py @@ -2,12 +2,14 @@ import pytest from primaite import getLogger -from primaite.config.lay_down_config import dos_very_basic_config_path + +# from primaite.config.lay_down_config import dos_very_basic_config_path from tests import TEST_CONFIG_ROOT _LOGGER = getLogger(__name__) +@pytest.skip("Deprecated") @pytest.mark.parametrize( "temp_primaite_session", [[TEST_CONFIG_ROOT / "train_episode_step.yaml", dos_very_basic_config_path()]], diff --git a/tests/test_training_config.py b/tests/test_training_config.py index 58f9c797..e4e3fa32 100644 --- a/tests/test_training_config.py +++ b/tests/test_training_config.py @@ -1,10 +1,12 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +import pytest import yaml -from primaite.config import training_config +# from primaite.config import training_config from tests import TEST_CONFIG_ROOT +@pytest.skip("Deprecated") def test_legacy_lay_down_config_yaml_conversion(): """Tests the conversion of legacy lay down config files.""" legacy_path = TEST_CONFIG_ROOT / "legacy_conversion" / "legacy_training_config.yaml" @@ -22,6 +24,7 @@ def test_legacy_lay_down_config_yaml_conversion(): assert converted_dict[key] == value +@pytest.skip("Deprecated") def test_create_config_values_main_from_file(): """Tests creating an instance of TrainingConfig from file.""" new_path = TEST_CONFIG_ROOT / "legacy_conversion" / "new_training_config.yaml" @@ -29,6 +32,7 @@ def test_create_config_values_main_from_file(): training_config.load(new_path) +@pytest.skip("Deprecated") def test_create_config_values_main_from_legacy_file(): """Tests creating an instance of TrainingConfig from legacy file.""" new_path = TEST_CONFIG_ROOT / "legacy_conversion" / "legacy_training_config.yaml" From 2b8462d38da298b63e391f17994d2fccfac2376f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 25 Oct 2023 17:04:04 +0100 Subject: [PATCH 252/980] Fix link import in v3 code --- src/primaite/simulator/network/hardware/nodes/switch.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/switch.py index 09b53483..fe61509c 100644 --- a/src/primaite/simulator/network/hardware/nodes/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/switch.py @@ -4,8 +4,7 @@ from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.exceptions import NetworkError -from primaite.links.link import Link -from primaite.simulator.network.hardware.base import Node, SwitchPort +from primaite.simulator.network.hardware.base import Link, Node, SwitchPort from primaite.simulator.network.transmission.data_link_layer import Frame _LOGGER = getLogger(__name__) From 1e811148ed597bfe77793af5892f54a00622375f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 25 Oct 2023 17:04:30 +0100 Subject: [PATCH 253/980] Fix dependency versions to align with GATE --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d7e71a28..51ed84f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ ] dependencies = [ - "gym==0.21.0", + "gymnasium==0.28.1", "jupyterlab==3.6.1", "kaleido==0.2.1", "matplotlib==3.7.1", @@ -35,7 +35,7 @@ dependencies = [ "polars==0.18.4", "prettytable==3.8.0", "PyYAML==6.0", - "stable-baselines3==1.6.2", + "stable-baselines3[extra]==2.1.0", "tensorflow==2.12.0", "typer[all]==0.9.0", "pydantic==2.1.1" From c57b5152c01f8d435755370d0ef8b1e02586efda Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 25 Oct 2023 17:08:01 +0100 Subject: [PATCH 254/980] Remove broken tests --- tests/conftest.py | 40 +- .../game_layer/test_observations.py | 2 +- tests/test_acl.py | 174 -------- tests/test_active_node.py | 126 ------ tests/test_full_legacy_config_session.py | 30 -- tests/test_lay_down_config.py | 45 -- tests/test_observation_space.py | 383 ------------------ tests/test_primaite_session.py | 79 ---- tests/test_red_random_agent_behaviour.py | 40 -- tests/test_resetting_node.py | 89 ---- tests/test_reward.py | 54 --- .../test_seeding_and_deterministic_session.py | 66 --- tests/test_service_node.py | 73 ---- tests/test_session_loading.py | 194 --------- tests/test_single_action_space.py | 132 ------ tests/test_train_eval_episode_steps.py | 45 -- tests/test_training_config.py | 40 -- 17 files changed, 21 insertions(+), 1591 deletions(-) delete mode 100644 tests/test_acl.py delete mode 100644 tests/test_active_node.py delete mode 100644 tests/test_full_legacy_config_session.py delete mode 100644 tests/test_lay_down_config.py delete mode 100644 tests/test_observation_space.py delete mode 100644 tests/test_primaite_session.py delete mode 100644 tests/test_red_random_agent_behaviour.py delete mode 100644 tests/test_resetting_node.py delete mode 100644 tests/test_reward.py delete mode 100644 tests/test_seeding_and_deterministic_session.py delete mode 100644 tests/test_service_node.py delete mode 100644 tests/test_session_loading.py delete mode 100644 tests/test_single_action_space.py delete mode 100644 tests/test_train_eval_episode_steps.py delete mode 100644 tests/test_training_config.py diff --git a/tests/conftest.py b/tests/conftest.py index 425acc09..2701955c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -54,37 +54,37 @@ def file_system() -> FileSystem: return Node(hostname="fs_node").file_system -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 # PrimAITE v2 stuff -class TempPrimaiteSession(PrimaiteSession): +@pytest.mark.skip("Deprecated") # TODO: implement a similar test for primaite v3 +class TempPrimaiteSession: # PrimaiteSession): """ A temporary PrimaiteSession class. Uses context manager for deletion of files upon exit. """ - def __init__( - self, - training_config_path: Union[str, Path], - lay_down_config_path: Union[str, Path], - ): - super().__init__(training_config_path, lay_down_config_path) - self.setup() + # def __init__( + # self, + # training_config_path: Union[str, Path], + # lay_down_config_path: Union[str, Path], + # ): + # super().__init__(training_config_path, lay_down_config_path) + # self.setup() - @property - def env(self) -> Primaite: - """Direct access to the env for ease of testing.""" - return self._agent_session._env # noqa + # @property + # def env(self) -> Primaite: + # """Direct access to the env for ease of testing.""" + # return self._agent_session._env # noqa - def __enter__(self): - return self + # def __enter__(self): + # return self - def __exit__(self, type, value, tb): - shutil.rmtree(self.session_path) - _LOGGER.debug(f"Deleted temp session directory: {self.session_path}") + # def __exit__(self, type, value, tb): + # shutil.rmtree(self.session_path) + # _LOGGER.debug(f"Deleted temp session directory: {self.session_path}") -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 +@pytest.mark.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.fixture def temp_primaite_session(request): """ @@ -139,7 +139,7 @@ def temp_primaite_session(request): return TempPrimaiteSession(training_config_path, lay_down_config_path) -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 +@pytest.mark.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.fixture def temp_session_path() -> Path: """ diff --git a/tests/integration_tests/game_layer/test_observations.py b/tests/integration_tests/game_layer/test_observations.py index c1f20d78..97154f62 100644 --- a/tests/integration_tests/game_layer/test_observations.py +++ b/tests/integration_tests/game_layer/test_observations.py @@ -1,4 +1,4 @@ -from gym import spaces +from gymnasium import spaces from primaite.game.agent.observations import FileObservation from primaite.simulator.network.hardware.nodes.computer import Computer diff --git a/tests/test_acl.py b/tests/test_acl.py deleted file mode 100644 index a0dfb997..00000000 --- a/tests/test_acl.py +++ /dev/null @@ -1,174 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Used to tes the ACL functions.""" - -# from primaite.acl.access_control_list import AccessControlList -# from primaite.acl.acl_rule import ACLRule -# from primaite.common.enums import RulePermissionType - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -def test_acl_address_match_1(): - """Test that matching IP addresses produce True.""" - acl = AccessControlList(RulePermissionType.DENY, 10) - - rule = ACLRule(RulePermissionType.ALLOW, "192.168.1.1", "192.168.1.2", "TCP", "80") - - assert acl.check_address_match(rule, "192.168.1.1", "192.168.1.2") == True - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -def test_acl_address_match_2(): - """Test that mismatching IP addresses produce False.""" - acl = AccessControlList(RulePermissionType.DENY, 10) - - rule = ACLRule(RulePermissionType.ALLOW, "192.168.1.1", "192.168.1.2", "TCP", "80") - - assert acl.check_address_match(rule, "192.168.1.1", "192.168.1.3") == False - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -def test_acl_address_match_3(): - """Test the ANY condition for source IP addresses produce True.""" - acl = AccessControlList(RulePermissionType.DENY, 10) - - rule = ACLRule(RulePermissionType.ALLOW, "ANY", "192.168.1.2", "TCP", "80") - - assert acl.check_address_match(rule, "192.168.1.1", "192.168.1.2") == True - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -def test_acl_address_match_4(): - """Test the ANY condition for dest IP addresses produce True.""" - acl = AccessControlList(RulePermissionType.DENY, 10) - - rule = ACLRule(RulePermissionType.ALLOW, "192.168.1.1", "ANY", "TCP", "80") - - assert acl.check_address_match(rule, "192.168.1.1", "192.168.1.2") == True - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -def test_check_acl_block_affirmative(): - """Test the block function (affirmative).""" - # Create the Access Control List - acl = AccessControlList(RulePermissionType.DENY, 10) - - # Create a rule - acl_rule_permission = RulePermissionType.ALLOW - acl_rule_source = "192.168.1.1" - acl_rule_destination = "192.168.1.2" - acl_rule_protocol = "TCP" - acl_rule_port = "80" - acl_position_in_list = "0" - - acl.add_rule( - acl_rule_permission, - acl_rule_source, - acl_rule_destination, - acl_rule_protocol, - acl_rule_port, - acl_position_in_list, - ) - assert acl.is_blocked("192.168.1.1", "192.168.1.2", "TCP", "80") == False - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -def test_check_acl_block_negative(): - """Test the block function (negative).""" - # Create the Access Control List - acl = AccessControlList(RulePermissionType.DENY, 10) - - # Create a rule - acl_rule_permission = RulePermissionType.DENY - acl_rule_source = "192.168.1.1" - acl_rule_destination = "192.168.1.2" - acl_rule_protocol = "TCP" - acl_rule_port = "80" - acl_position_in_list = "0" - - acl.add_rule( - acl_rule_permission, - acl_rule_source, - acl_rule_destination, - acl_rule_protocol, - acl_rule_port, - acl_position_in_list, - ) - - assert acl.is_blocked("192.168.1.1", "192.168.1.2", "TCP", "80") == True - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -def test_rule_hash(): - """Test the rule hash.""" - # Create the Access Control List - acl = AccessControlList(RulePermissionType.DENY, 10) - - rule = ACLRule(RulePermissionType.DENY, "192.168.1.1", "192.168.1.2", "TCP", "80") - hash_value_local = hash(rule) - - hash_value_remote = acl.get_dictionary_hash(RulePermissionType.DENY, "192.168.1.1", "192.168.1.2", "TCP", "80") - - assert hash_value_local == hash_value_remote - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -def test_delete_rule(): - """Adds 3 rules and deletes 1 rule and checks its deletion.""" - # Create the Access Control List - acl = AccessControlList(RulePermissionType.ALLOW, 10) - - # Create a first rule - acl_rule_permission = RulePermissionType.DENY - acl_rule_source = "192.168.1.1" - acl_rule_destination = "192.168.1.2" - acl_rule_protocol = "TCP" - acl_rule_port = "80" - acl_position_in_list = "0" - - acl.add_rule( - acl_rule_permission, - acl_rule_source, - acl_rule_destination, - acl_rule_protocol, - acl_rule_port, - acl_position_in_list, - ) - - # Create a second rule - acl_rule_permission = RulePermissionType.DENY - acl_rule_source = "20" - acl_rule_destination = "30" - acl_rule_protocol = "FTP" - acl_rule_port = "21" - acl_position_in_list = "2" - - acl.add_rule( - acl_rule_permission, - acl_rule_source, - acl_rule_destination, - acl_rule_protocol, - acl_rule_port, - acl_position_in_list, - ) - - # Create a third rule - acl_rule_permission = RulePermissionType.ALLOW - acl_rule_source = "192.168.1.3" - acl_rule_destination = "192.168.1.1" - acl_rule_protocol = "UDP" - acl_rule_port = "60" - acl_position_in_list = "4" - - acl.add_rule( - acl_rule_permission, - acl_rule_source, - acl_rule_destination, - acl_rule_protocol, - acl_rule_port, - acl_position_in_list, - ) - # Remove the second ACL rule added from the list - acl.remove_rule(RulePermissionType.DENY, "20", "30", "FTP", "21") - - assert len(acl.acl) == 10 - assert acl.acl[2] is None diff --git a/tests/test_active_node.py b/tests/test_active_node.py deleted file mode 100644 index cf532bb8..00000000 --- a/tests/test_active_node.py +++ /dev/null @@ -1,126 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Used to test Active Node functions.""" -import pytest - -# from primaite.common.enums import FileSystemState, HardwareState, SoftwareState -# from primaite.nodes.active_node import ActiveNode - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "operating_state, expected_state", - [ - (HardwareState.OFF, SoftwareState.GOOD), - (HardwareState.ON, SoftwareState.OVERWHELMED), - ], -) -def test_os_state_change(operating_state, expected_state): - """ - Test that a node cannot change its Software State. - - When its hardware state is OFF. - """ - active_node = ActiveNode( - 0, - "node", - "COMPUTER", - "1", - operating_state, - "192.168.0.1", - SoftwareState.GOOD, - "GOOD", - 1, - ) - - active_node.software_state = SoftwareState.OVERWHELMED - - assert active_node.software_state == expected_state - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "operating_state, expected_state", - [ - (HardwareState.OFF, SoftwareState.GOOD), - (HardwareState.ON, SoftwareState.OVERWHELMED), - ], -) -def test_os_state_change_if_not_compromised(operating_state, expected_state): - """ - Test that a node cannot change its Software State. - - If not compromised) when its hardware state is OFF. - """ - active_node = ActiveNode( - 0, - "node", - "COMPUTER", - "1", - operating_state, - "192.168.0.1", - SoftwareState.GOOD, - "GOOD", - 1, - ) - - active_node.set_software_state_if_not_compromised(SoftwareState.OVERWHELMED) - - assert active_node.software_state == expected_state - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "operating_state, expected_state", - [ - (HardwareState.OFF, FileSystemState.GOOD), - (HardwareState.ON, FileSystemState.CORRUPT), - ], -) -def test_file_system_change(operating_state, expected_state): - """Test that a node cannot change its file system state when its hardware state is ON.""" - active_node = ActiveNode( - 0, - "node", - "COMPUTER", - "1", - operating_state, - "192.168.0.1", - "COMPROMISED", - FileSystemState.GOOD, - 1, - ) - - active_node.set_file_system_state(FileSystemState.CORRUPT) - - assert active_node.file_system_state_actual == expected_state - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "operating_state, expected_state", - [ - (HardwareState.OFF, FileSystemState.GOOD), - (HardwareState.ON, FileSystemState.CORRUPT), - ], -) -def test_file_system_change_if_not_compromised(operating_state, expected_state): - """ - Test that a node cannot change its file system state. - - If not compromised) when its hardware state is OFF. - """ - active_node = ActiveNode( - 0, - "node", - "COMPUTER", - "1", - operating_state, - "192.168.0.1", - "GOOD", - FileSystemState.GOOD, - 1, - ) - - active_node.set_file_system_state_if_not_compromised(FileSystemState.CORRUPT) - - assert active_node.file_system_state_actual == expected_state diff --git a/tests/test_full_legacy_config_session.py b/tests/test_full_legacy_config_session.py deleted file mode 100644 index ac727a22..00000000 --- a/tests/test_full_legacy_config_session.py +++ /dev/null @@ -1,30 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -import pytest - -from primaite.main import run -from tests import TEST_CONFIG_ROOT - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "legacy_file", - [ - ("legacy_config_1_DDOS_BASIC.yaml"), - ("legacy_config_2_DDOS_BASIC.yaml"), - ("legacy_config_3_DOS_VERY_BASIC.yaml"), - ("legacy_config_5_DATA_MANIPULATION.yaml"), - ], -) -def test_legacy_training_config_run_session(legacy_file): - """Tests using legacy training and lay down config files in PrimAITE session end-to-end.""" - legacy_training_config_path = TEST_CONFIG_ROOT / "legacy_conversion" / "legacy_training_config.yaml" - legacy_lay_down_config_path = TEST_CONFIG_ROOT / "legacy_conversion" / legacy_file - - # Run a PrimAITE session using legacy training and lay down config file paths - run( - legacy_training_config_path, - legacy_lay_down_config_path, - legacy_training_config=True, - legacy_lay_down_config=True, - ) diff --git a/tests/test_lay_down_config.py b/tests/test_lay_down_config.py deleted file mode 100644 index 83c6063c..00000000 --- a/tests/test_lay_down_config.py +++ /dev/null @@ -1,45 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import pytest -import yaml - -# from primaite.config.lay_down_config import ( -# convert_legacy_lay_down_config, -# data_manipulation_config_path, -# ddos_basic_one_config_path, -# ddos_basic_two_config_path, -# dos_very_basic_config_path, -# ) -from tests import TEST_CONFIG_ROOT - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "legacy_file, new_path", - [ - ("legacy_config_1_DDOS_BASIC.yaml", ddos_basic_one_config_path()), - ("legacy_config_2_DDOS_BASIC.yaml", ddos_basic_two_config_path()), - ("legacy_config_3_DOS_VERY_BASIC.yaml", dos_very_basic_config_path()), - ("legacy_config_5_DATA_MANIPULATION.yaml", data_manipulation_config_path()), - ], -) -def test_legacy_lay_down_config_load(legacy_file, new_path): - """Tests converting legacy lay down files into the new format.""" - with open(TEST_CONFIG_ROOT / "legacy_conversion" / legacy_file, "r") as file: - legacy_lay_down_config = yaml.safe_load(file) - - with open(new_path, "r") as file: - new_lay_down_config = yaml.safe_load(file) - - converted_lay_down_config = convert_legacy_lay_down_config(legacy_lay_down_config) - - assert len(converted_lay_down_config) == len(new_lay_down_config) - - for i, new_item in enumerate(new_lay_down_config): - converted_item = converted_lay_down_config[i] - - for key, val in new_item.items(): - if key == "position": - continue - assert key in converted_item - - assert val == converted_item[key] diff --git a/tests/test_observation_space.py b/tests/test_observation_space.py deleted file mode 100644 index b138dd5e..00000000 --- a/tests/test_observation_space.py +++ /dev/null @@ -1,383 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Test env creation and behaviour with different observation spaces.""" - -import numpy as np -import pytest - -# from primaite.environment.observations import NodeLinkTable, NodeStatuses, ObservationsHandler -from tests import TEST_CONFIG_ROOT - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "temp_primaite_session", - [ - [ - TEST_CONFIG_ROOT / "obs_tests/main_config_without_obs.yaml", - TEST_CONFIG_ROOT / "obs_tests/laydown.yaml", - ] - ], - indirect=True, -) -def test_default_obs_space(temp_primaite_session): - """Create environment with no obs space defined in config and check that the default obs space was created.""" - with temp_primaite_session as session: - session.env.update_environent_obs() - - components = session.env.obs_handler.registered_obs_components - - assert len(components) == 1 - assert isinstance(components[0], NodeLinkTable) - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "temp_primaite_session", - [ - [ - TEST_CONFIG_ROOT / "obs_tests/main_config_without_obs.yaml", - TEST_CONFIG_ROOT / "obs_tests/laydown.yaml", - ] - ], - indirect=True, -) -def test_registering_components(temp_primaite_session): - """Test regitering and deregistering a component.""" - with temp_primaite_session as session: - env = session.env - handler = ObservationsHandler() - component = NodeStatuses(env) - handler.register(component) - assert component in handler.registered_obs_components - handler.deregister(component) - assert component not in handler.registered_obs_components - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "temp_primaite_session", - [ - [ - TEST_CONFIG_ROOT / "obs_tests/main_config_NODE_LINK_TABLE.yaml", - TEST_CONFIG_ROOT / "obs_tests/laydown.yaml", - ] - ], - indirect=True, -) -class TestNodeLinkTable: - """Test the NodeLinkTable observation component (in isolation).""" - - def test_obs_shape(self, temp_primaite_session): - """Try creating env with box observation space.""" - with temp_primaite_session as session: - env = session.env - env.update_environent_obs() - - # we have three nodes and two links, with two service - # therefore the box observation space will have: - # * 5 rows (3 nodes + 2 links) - # * 6 columns (four fixed and two for the services) - assert env.env_obs.shape == (5, 6) - - def test_value(self, temp_primaite_session): - """ - Test that the observation is generated correctly. - - The laydown has: - * 3 nodes (2 service nodes and 1 active node) - * 2 services - * 2 links - - Both nodes have both services, and all states are GOOD, therefore the expected observation value is: - - * Node 1: - * 1 (id) - * 1 (good hardware state) - * 3 (compromised OS state) - * 1 (good file system state) - * 1 (good TCP state) - * 1 (good UDP state) - * Node 2: - * 2 (id) - * 1 (good hardware state) - * 1 (good OS state) - * 1 (good file system state) - * 1 (good TCP state) - * 4 (overwhelmed UDP state) - * Node 3 (active node): - * 3 (id) - * 1 (good hardware state) - * 1 (good OS state) - * 1 (good file system state) - * 0 (doesn't have service1) - * 0 (doesn't have service2) - * Link 1: - * 4 (id) - * 0 (n/a hardware state) - * 0 (n/a OS state) - * 0 (n/a file system state) - * 999 (999 traffic for service1) - * 0 (no traffic for service2) - * Link 2: - * 5 (id) - * 0 (good hardware state) - * 0 (good OS state) - * 0 (good file system state) - * 999 (999 traffic service1) - * 0 (no traffic for service2) - """ - with temp_primaite_session as session: - env = session.env - # act = np.asarray([0,]) - obs, reward, done, info = env.step(0) # apply the 'do nothing' action - - assert np.array_equal( - obs, - [ - [1, 1, 3, 1, 1, 1], - [2, 1, 1, 1, 1, 4], - [3, 1, 1, 1, 0, 0], - [4, 0, 0, 0, 999, 0], - [5, 0, 0, 0, 999, 0], - ], - ) - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "temp_primaite_session", - [ - [ - TEST_CONFIG_ROOT / "obs_tests/main_config_NODE_STATUSES.yaml", - TEST_CONFIG_ROOT / "obs_tests/laydown.yaml", - ] - ], - indirect=True, -) -class TestNodeStatuses: - """Test the NodeStatuses observation component (in isolation).""" - - def test_obs_shape(self, temp_primaite_session): - """Try creating env with NodeStatuses as the only component.""" - with temp_primaite_session as session: - env = session.env - assert env.env_obs.shape == (15,) - - def test_values(self, temp_primaite_session): - """ - Test that the hardware and software states are encoded correctly. - - The laydown has: - * one node with a compromised operating system state - * one node with two services, and the second service is overwhelmed. - * all other states are good or null - Therefore, the expected state is: - * node 1: - * hardware = good (1) - * OS = compromised (3) - * file system = good (1) - * service 1 = good (1) - * service 2 = good (1) - * node 2: - * hardware = good (1) - * OS = good (1) - * file system = good (1) - * service 1 = good (1) - * service 2 = overwhelmed (4) - * node 3 (switch): - * hardware = good (1) - * OS = good (1) - * file system = good (1) - * service 1 = n/a (0) - * service 2 = n/a (0) - """ - with temp_primaite_session as session: - env = session.env - obs, _, _, _ = env.step(0) # apply the 'do nothing' action - print(obs) - assert np.array_equal(obs, [1, 3, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 0, 0]) - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "temp_primaite_session", - [ - [ - TEST_CONFIG_ROOT / "obs_tests/main_config_LINK_TRAFFIC_LEVELS.yaml", - TEST_CONFIG_ROOT / "obs_tests/laydown.yaml", - ] - ], - indirect=True, -) -class TestLinkTrafficLevels: - """Test the LinkTrafficLevels observation component (in isolation).""" - - def test_obs_shape(self, temp_primaite_session): - """Try creating env with MultiDiscrete observation space.""" - with temp_primaite_session as session: - env = session.env - env.update_environent_obs() - - # we have two links and two services, so the shape should be 2 * 2 - assert env.env_obs.shape == (2 * 2,) - - def test_values(self, temp_primaite_session): - """ - Test that traffic values are encoded correctly. - - The laydown has: - * two services - * three nodes - * two links - * an IER trying to send 999 bits of data over both links the whole time (via the first service) - * link bandwidth of 1000, therefore the utilisation is 99.9% - """ - with temp_primaite_session as session: - env = session.env - obs, reward, done, info = env.step(0) - obs, reward, done, info = env.step(0) - - # the observation space has combine_service_traffic set to False, so the space has this format: - # [link1_service1, link1_service2, link2_service1, link2_service2] - # we send 999 bits of data via link1 and link2 on service 1. - # therefore the first and third elements should be 6 and all others 0 - # (`7` corresponds to 100% utiilsation and `6` corresponds to 87.5%-100%) - assert np.array_equal(obs, [6, 0, 6, 0]) - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "temp_primaite_session", - [ - [ - TEST_CONFIG_ROOT / "obs_tests/main_config_ACCESS_CONTROL_LIST.yaml", - TEST_CONFIG_ROOT / "obs_tests/laydown_ACL.yaml", - ] - ], - indirect=True, -) -class TestAccessControlList: - """Test the AccessControlList observation component (in isolation).""" - - def test_obs_shape(self, temp_primaite_session): - """Try creating env with MultiDiscrete observation space. - - The laydown has 3 ACL Rules - that is the maximum_acl_rules it can have. - Each ACL Rule in the observation space has 6 different elements: - - 6 * 3 = 18 - """ - with temp_primaite_session as session: - env = session.env - env.update_environent_obs() - - assert env.env_obs.shape == (18,) - - def test_values(self, temp_primaite_session): - """Test that traffic values are encoded correctly. - - The laydown has: - * one ACL IMPLICIT DENY rule - - Therefore, the ACL is full of NAs aka zeros and just 6 non-zero elements representing DENY ANY ANY ANY at - Position 2. - """ - with temp_primaite_session as session: - env = session.env - obs, reward, done, info = env.step(0) - obs, reward, done, info = env.step(0) - - assert np.array_equal(obs, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2]) - - def test_observation_space_with_implicit_rule(self, temp_primaite_session): - """ - Test observation space is what is expected when an agent adds ACLs during an episode. - - At the start of the episode, there is a single implicit DENY rule - In the observation space IMPLICIT DENY: 1,1,1,1,1,0 - 0 shows the rule is the start (when episode began no other rules were created) so this is correct. - - On Step 2, there is an ACL rule added at Position 0: 2,2,3,2,3,0 - - On Step 4, there is a second ACL rule added at POSITION 1: 2,4,2,3,3,1 - - The final observation space should be this: - [2, 2, 3, 2, 3, 0, 2, 4, 2, 3, 3, 1, 1, 1, 1, 1, 1, 2] - - The ACL Rule from Step 2 is added first and has a HIGHER position than the ACL rule from Step 4 - but both come before the IMPLICIT DENY which will ALWAYS be at the end of the ACL List. - """ - # TODO: Refactor this at some point to build a custom ACL Hardcoded - # Agent and then patch the AgentIdentifier Enum class so that it - # has ACL_AGENT. This then allows us to set the agent identified in - # the main config and is a bit cleaner. - - with temp_primaite_session as session: - env = session.env - training_config = env.training_config - for episode in range(0, training_config.num_train_episodes): - for step in range(0, training_config.num_train_steps): - # Do nothing action - action = 0 - if step == 2: - # Action to add the first ACL rule - action = 43 - elif step == 4: - # Action to add the second ACL rule - action = 96 - - # Run the simulation step on the live environment - obs, reward, done, info = env.step(action) - - # Break if done is True - if done: - break - obs = env.env_obs - - assert np.array_equal(obs, [2, 2, 3, 2, 3, 0, 2, 4, 2, 3, 3, 1, 1, 1, 1, 1, 1, 2]) - - def test_observation_space_with_different_positions(self, temp_primaite_session): - """ - Test observation space is what is expected when an agent adds ACLs during an episode. - - At the start of the episode, there is a single implicit DENY rule - In the observation space IMPLICIT DENY: 1,1,1,1,1,0 - 0 shows the rule is the start (when episode began no other rules were created) so this is correct. - - On Step 2, there is an ACL rule added at Position 1: 2,2,3,2,3,1 - - On Step 4 there is a second ACL rule added at Position 0: 2,4,2,3,3,0 - - The final observation space should be this: - [2 , 4, 2, 3, 3, 0, 2, 2, 3, 2, 3, 1, 1, 1, 1, 1, 1, 2] - - The ACL Rule from Step 2 is added before and has a LOWER position than the ACL rule from Step 4 - but both come before the IMPLICIT DENY which will ALWAYS be at the end of the ACL List. - """ - # TODO: Refactor this at some point to build a custom ACL Hardcoded - # Agent and then patch the AgentIdentifier Enum class so that it - # has ACL_AGENT. This then allows us to set the agent identified in - # the main config and is a bit cleaner. - - with temp_primaite_session as session: - env = session.env - training_config = env.training_config - for episode in range(0, training_config.num_train_episodes): - for step in range(0, training_config.num_train_steps): - # Do nothing action - action = 0 - if step == 2: - # Action to add the first ACL rule - action = 44 - elif step == 4: - # Action to add the second ACL rule - action = 95 - # Run the simulation step on the live environment - obs, reward, done, info = env.step(action) - - # Break if done is True - if done: - break - obs = env.env_obs - - assert np.array_equal(obs, [2, 4, 2, 3, 3, 0, 2, 2, 3, 2, 3, 1, 1, 1, 1, 1, 1, 2]) diff --git a/tests/test_primaite_session.py b/tests/test_primaite_session.py deleted file mode 100644 index bf9332a7..00000000 --- a/tests/test_primaite_session.py +++ /dev/null @@ -1,79 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import os - -import pytest - -from primaite import getLogger - -# from primaite.config.lay_down_config import dos_very_basic_config_path -from tests import TEST_CONFIG_ROOT - -_LOGGER = getLogger(__name__) - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "temp_primaite_session", - [ - # [TEST_CONFIG_ROOT / "session_test/training_config_main_rllib.yaml", dos_very_basic_config_path()], - [TEST_CONFIG_ROOT / "session_test/training_config_main_sb3.yaml", dos_very_basic_config_path()], - ], - indirect=True, -) -def test_primaite_session(temp_primaite_session): - """ - Tests the PrimaiteSession class and all of its outputs. - - This test runs for both a Stable Baselines3 agent, and a Ray RLlib agent. - """ - with temp_primaite_session as session: - session_path = session.session_path - assert session_path.exists() - session.learn() - # Learning outputs are saved in session.learning_path - session.evaluate() - # Evaluation outputs are saved in session.evaluation_path - - # If you need to inspect any session outputs, it must be done inside - # the context manager - - # Check that the metadata json file exists - assert (session_path / "session_metadata.json").exists() - - # Check that the network png file exists - assert (session_path / f"network_{session.timestamp_str}.png").exists() - - # Check that the saved agent exists - assert session._agent_session._saved_agent_path.exists() - - # Check that both the transactions and av reward csv files exist - for file in session.learning_path.iterdir(): - if file.suffix == ".csv": - assert "all_transactions" in file.name or "average_reward_per_episode" in file.name - - # Check that both the transactions and av reward csv files exist - for file in session.evaluation_path.iterdir(): - if file.suffix == ".csv": - assert "all_transactions" in file.name or "average_reward_per_episode" in file.name - - # Check that the average reward per episode plots exist - assert (session.learning_path / f"average_reward_per_episode_{session.timestamp_str}.png").exists() - assert (session.evaluation_path / f"average_reward_per_episode_{session.timestamp_str}.png").exists() - - # Check that the metadata has captured the correct number of learning and eval episodes and steps - assert len(session.learn_av_reward_per_episode_dict().keys()) == 10 - assert len(session.learn_all_transactions_dict().keys()) == 10 * 256 - - assert len(session.eval_av_reward_per_episode_dict().keys()) == 3 - assert len(session.eval_all_transactions_dict().keys()) == 3 * 256 - - _LOGGER.debug("Inspecting files in temp session path...") - for dir_path, dir_names, file_names in os.walk(session_path): - for file in file_names: - path = os.path.join(dir_path, file) - file_str = path.split(str(session_path))[-1] - _LOGGER.debug(f" {file_str}") - - # Now that we've exited the context manager, the session.session_path - # directory and its contents are deleted - assert not session_path.exists() diff --git a/tests/test_red_random_agent_behaviour.py b/tests/test_red_random_agent_behaviour.py deleted file mode 100644 index 3f999f9b..00000000 --- a/tests/test_red_random_agent_behaviour.py +++ /dev/null @@ -1,40 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import pytest - -# from primaite.config.lay_down_config import data_manipulation_config_path -# from primaite.nodes.node_state_instruction_red import NodeStateInstructionRed -from tests import TEST_CONFIG_ROOT - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "temp_primaite_session", - [ - [ - TEST_CONFIG_ROOT / "test_random_red_main_config.yaml", - data_manipulation_config_path(), - ] - ], - indirect=True, -) -def test_random_red_agent_behaviour(temp_primaite_session): - """Test that red agent POL is randomised each episode.""" - list_of_node_instructions = [] - - with temp_primaite_session as session: - session.evaluate() - list_of_node_instructions.append(session.env.red_node_pol) - - session.evaluate() - list_of_node_instructions.append(session.env.red_node_pol) - - # compare instructions to make sure that red instructions are truly random - for index, instruction in enumerate(list_of_node_instructions): - for key in list_of_node_instructions[index].keys(): - instruction: NodeStateInstructionRed = list_of_node_instructions[index][key] - print(f"run {index}") - print(f"{key} start step: {instruction.get_start_step()}") - print(f"{key} end step: {instruction.get_end_step()}") - print(f"{key} target node id: {instruction.get_target_node_id()}") - print("") - assert list_of_node_instructions[0].__ne__(list_of_node_instructions[1]) diff --git a/tests/test_resetting_node.py b/tests/test_resetting_node.py deleted file mode 100644 index 53779c4f..00000000 --- a/tests/test_resetting_node.py +++ /dev/null @@ -1,89 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Used to test Active Node functions.""" -import pytest - -# from primaite.common.enums import FileSystemState, HardwareState, NodeType, Priority, SoftwareState -# from primaite.common.service import Service -# from primaite.config.training_config import TrainingConfig -# from primaite.nodes.active_node import ActiveNode -# from primaite.nodes.service_node import ServiceNode - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "starting_operating_state, expected_operating_state", - [(HardwareState.RESETTING, HardwareState.ON)], -) -def test_node_resets_correctly(starting_operating_state, expected_operating_state): - """Tests that a node resets correctly.""" - active_node = ActiveNode( - node_id="0", - name="node", - node_type=NodeType.COMPUTER, - priority=Priority.P1, - hardware_state=starting_operating_state, - ip_address="192.168.0.1", - software_state=SoftwareState.COMPROMISED, - file_system_state=FileSystemState.CORRUPT, - config_values=TrainingConfig(), - ) - - for x in range(5): - active_node.update_resetting_status() - - assert active_node.software_state == SoftwareState.GOOD - assert active_node.file_system_state_actual == FileSystemState.GOOD - assert active_node.hardware_state == expected_operating_state - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "operating_state, expected_operating_state", - [(HardwareState.BOOTING, HardwareState.ON)], -) -def test_node_boots_correctly(operating_state, expected_operating_state): - """Tests that a node boots correctly.""" - service_node = ServiceNode( - node_id=0, - name="node", - node_type="COMPUTER", - priority="1", - hardware_state=operating_state, - ip_address="192.168.0.1", - software_state=SoftwareState.GOOD, - file_system_state="GOOD", - config_values=1, - ) - service_attributes = Service(name="node", port="80", software_state=SoftwareState.COMPROMISED) - service_node.add_service(service_attributes) - - for x in range(5): - service_node.update_booting_status() - - assert service_attributes.software_state == SoftwareState.GOOD - assert service_node.hardware_state == expected_operating_state - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "operating_state, expected_operating_state", - [(HardwareState.SHUTTING_DOWN, HardwareState.OFF)], -) -def test_node_shutdown_correctly(operating_state, expected_operating_state): - """Tests that a node shutdown correctly.""" - active_node = ActiveNode( - node_id=0, - name="node", - node_type="COMPUTER", - priority="1", - hardware_state=operating_state, - ip_address="192.168.0.1", - software_state=SoftwareState.GOOD, - file_system_state="GOOD", - config_values=1, - ) - - for x in range(5): - active_node.update_shutdown_status() - - assert active_node.hardware_state == expected_operating_state diff --git a/tests/test_reward.py b/tests/test_reward.py deleted file mode 100644 index 7a980d32..00000000 --- a/tests/test_reward.py +++ /dev/null @@ -1,54 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import pytest - -from primaite import getLogger -from tests import TEST_CONFIG_ROOT - -_LOGGER = getLogger(__name__) - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "temp_primaite_session", - [ - [ - TEST_CONFIG_ROOT / "one_node_states_on_off_main_config.yaml", - TEST_CONFIG_ROOT / "one_node_states_on_off_lay_down_config.yaml", - ] - ], - indirect=True, -) -def test_rewards_are_being_penalised_at_each_step_function( - temp_primaite_session, -): - """ - Test that hardware state is penalised at each step. - - When the initial state is OFF compared to reference state which is ON. - - The config 'one_node_states_on_off_lay_down_config.yaml' has 15 steps: - On different steps, the laydown config has Pattern of Life (PoLs) which change a state of the node's attribute. - For example, turning the nodes' file system state to CORRUPT from its original state GOOD. - As a result these are the following rewards are activated: - File System State: corrupt_should_be_good = -10 * 2 (on Steps 1 & 2) - Hardware State: off_should_be_on = -10 * 2 (on Steps 4 & 5) - Service State: compromised_should_be_good = -20 * 2 (on Steps 7 & 8) - Software State: compromised_should_be_good = -20 * 2 (on Steps 10 & 11) - - The Pattern of Life (PoLs) last for 2 steps, so the agent is penalised twice. - - Note: This test run inherits from conftest.py where the PrimAITE environment is ran and the blue agent is hard-coded - to do NOTHING on every step. - We use Pattern of Lifes (PoLs) to change the nodes states and display that the agent is being penalised on all steps - where the live network node differs from the network reference node. - - Total Reward: -10 + -10 + -10 + -10 + -20 + -20 + -20 + -20 = -120 - Step Count: 15 - - For the 4 steps where this occurs the average reward is: - Average Reward: -8 (-120 / 15) - """ - with temp_primaite_session as session: - session.evaluate() - ev_rewards = session.eval_av_reward_per_episode_dict() - assert ev_rewards[1] == -8.0 diff --git a/tests/test_seeding_and_deterministic_session.py b/tests/test_seeding_and_deterministic_session.py deleted file mode 100644 index eed6f4d6..00000000 --- a/tests/test_seeding_and_deterministic_session.py +++ /dev/null @@ -1,66 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import pytest as pytest - -# from primaite.config.lay_down_config import dos_very_basic_config_path -from tests import TEST_CONFIG_ROOT - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "temp_primaite_session", - [[TEST_CONFIG_ROOT / "ppo_seeded_training_config.yaml", dos_very_basic_config_path()]], - indirect=True, -) -def test_seeded_learning(temp_primaite_session): - """ - Test running seeded learning produces the same output when ran twice. - - .. note:: - - If this is failing, the hard-coded expected_mean_reward_per_episode - from a pre-trained agent will probably need to be updated. If the - env changes and those changed how this agent is trained, chances are - the mean rewards are going to be different. - - Run the test, but print out the session.learn_av_reward_per_episode() - before comparing it. Then copy the printed dict and replace the - expected_mean_reward_per_episode with those values. The test should - now work. If not, then you've got a bug :). - """ - expected_mean_reward_per_episode = { - 1: -20.7421875, - 2: -19.82421875, - 3: -17.01171875, - 4: -19.08203125, - 5: -21.93359375, - 6: -20.21484375, - 7: -15.546875, - 8: -12.08984375, - 9: -17.59765625, - 10: -14.6875, - } - - with temp_primaite_session as session: - assert ( - session._training_config.seed == 67890 - ), "Expected output is based upon a agent that was trained with seed 67890" - session.learn() - actual_mean_reward_per_episode = session.learn_av_reward_per_episode_dict() - - assert actual_mean_reward_per_episode == expected_mean_reward_per_episode - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "temp_primaite_session", - [[TEST_CONFIG_ROOT / "ppo_seeded_training_config.yaml", dos_very_basic_config_path()]], - indirect=True, -) -def test_deterministic_evaluation(temp_primaite_session): - """Test running deterministic evaluation gives same av eward per episode.""" - with temp_primaite_session as session: - # do stuff - session.learn() - session.evaluate() - eval_mean_reward = session.eval_av_reward_per_episode_dict() - assert len(set(eval_mean_reward.values())) == 1 diff --git a/tests/test_service_node.py b/tests/test_service_node.py deleted file mode 100644 index 6b1bd1ee..00000000 --- a/tests/test_service_node.py +++ /dev/null @@ -1,73 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""Used to test Service Node functions.""" -import pytest - -# from primaite.common.enums import HardwareState, SoftwareState -# from primaite.common.service import Service -# from primaite.nodes.service_node import ServiceNode - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "operating_state, expected_state", - [ - (HardwareState.OFF, SoftwareState.GOOD), - (HardwareState.ON, SoftwareState.OVERWHELMED), - ], -) -def test_service_state_change(operating_state, expected_state): - """ - Test that a node cannot change the state of a running service. - - When its hardware state is OFF. - """ - service_node = ServiceNode( - 0, - "node", - "COMPUTER", - "1", - operating_state, - "192.168.0.1", - "COMPROMISED", - "RESTORING", - 1, - ) - service = Service("TCP", 80, SoftwareState.GOOD) - service_node.add_service(service) - - service_node.set_service_state("TCP", SoftwareState.OVERWHELMED) - - assert service_node.get_service_state("TCP") == expected_state - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.mark.parametrize( - "operating_state, expected_state", - [ - (HardwareState.OFF, SoftwareState.GOOD), - (HardwareState.ON, SoftwareState.OVERWHELMED), - ], -) -def test_service_state_change_if_not_comprised(operating_state, expected_state): - """ - Test that a node cannot change the state of a running service. - - If not compromised when its hardware state is ON. - """ - service_node = ServiceNode( - 0, - "node", - "COMPUTER", - "1", - operating_state, - "192.168.0.1", - "GOOD", - "RESTORING", - 1, - ) - service = Service("TCP", 80, SoftwareState.GOOD) - service_node.add_service(service) - - service_node.set_service_state_if_not_compromised("TCP", SoftwareState.OVERWHELMED) - - assert service_node.get_service_state("TCP") == expected_state diff --git a/tests/test_session_loading.py b/tests/test_session_loading.py deleted file mode 100644 index fdec4ede..00000000 --- a/tests/test_session_loading.py +++ /dev/null @@ -1,194 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import os.path -import shutil -import tempfile -from pathlib import Path -from typing import Union -from uuid import uuid4 - -import pytest -from typer.testing import CliRunner - -from primaite import getLogger - -# from primaite.agents.sb3 import SB3Agent -from primaite.cli import app - -# from primaite.common.enums import AgentFramework, AgentIdentifier -from primaite.main import run - -# from primaite.primaite_session import PrimaiteSession -from primaite.utils.session_output_reader import av_rewards_dict -from tests import TEST_ASSETS_ROOT - -_LOGGER = getLogger(__name__) - -runner = CliRunner() - -sb3_expected_avg_reward_per_episode = { - 10: 0.0, - 11: -0.0011074218750000008, - 12: -0.0010000000000000007, - 13: -0.0016601562500000013, - 14: -0.001400390625000001, - 15: -0.0009863281250000007, - 16: -0.0011855468750000008, - 17: -0.0009511718750000007, - 18: -0.0008789062500000007, - 19: -0.0012226562500000009, - 20: -0.0010292968750000007, -} - -sb3_expected_eval_rewards = -0.0018515625000000014 - - -def copy_session_asset(asset_path: Union[str, Path]) -> str: - """Copies the asset into a temporary test folder.""" - if asset_path is None: - raise Exception("No path provided") - - if isinstance(asset_path, Path): - asset_path = str(os.path.normpath(asset_path)) - - copy_path = str(Path(tempfile.gettempdir()) / "primaite" / str(uuid4())) - - # copy the asset into a temp path - try: - shutil.copytree(asset_path, copy_path) - except Exception as e: - msg = f"Unable to copy directory: {asset_path}" - _LOGGER.error(msg, e) - print(msg, e) - - _LOGGER.debug(f"Copied test asset to: {copy_path}") - - # return the copied assets path - return copy_path - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -def test_load_sb3_session(): - """Test that loading an SB3 agent works.""" - test_path = copy_session_asset(TEST_ASSETS_ROOT / "example_sb3_agent_session") - - loaded_agent = SB3Agent(session_path=test_path) - - # loaded agent should have the same UUID as the previous agent - assert loaded_agent.uuid == "301874d3-2e14-43c2-ba7f-e2b03ad05dde" - assert loaded_agent._training_config.agent_framework == AgentFramework.SB3.name - assert loaded_agent._training_config.agent_identifier == AgentIdentifier.PPO.name - assert loaded_agent._training_config.deterministic - assert loaded_agent._training_config.seed == 12345 - assert str(loaded_agent.session_path) == str(test_path) - - # run another learn session - loaded_agent.learn() - - learn_mean_rewards = av_rewards_dict( - loaded_agent.learning_path / f"average_reward_per_episode_{loaded_agent.timestamp_str}.csv" - ) - - # run is seeded so should have the expected learn value - assert learn_mean_rewards == sb3_expected_avg_reward_per_episode - - # run an evaluation - loaded_agent.evaluate() - - # load the evaluation average reward csv file - eval_mean_reward = av_rewards_dict( - loaded_agent.evaluation_path / f"average_reward_per_episode_{loaded_agent.timestamp_str}.csv" - ) - - # the agent config ran the evaluation in deterministic mode, so should have the same reward value - assert len(set(eval_mean_reward.values())) == 1 - - # the evaluation should be the same as a previous run - assert next(iter(set(eval_mean_reward.values()))) == sb3_expected_eval_rewards - - # delete the test directory - shutil.rmtree(test_path) - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -def test_load_primaite_session(): - """Test that loading a Primaite session works.""" - test_path = copy_session_asset(TEST_ASSETS_ROOT / "example_sb3_agent_session") - - # create loaded session - session = PrimaiteSession(session_path=test_path) - - # run setup on session - session.setup() - - # make sure that the session was loaded correctly - assert session._agent_session.uuid == "301874d3-2e14-43c2-ba7f-e2b03ad05dde" - assert session._agent_session._training_config.agent_framework == AgentFramework.SB3.name - assert session._agent_session._training_config.agent_identifier == AgentIdentifier.PPO.name - assert session._agent_session._training_config.deterministic - assert session._agent_session._training_config.seed == 12345 - assert str(session._agent_session.session_path) == str(test_path) - - # run another learn session - session.learn() - - learn_mean_rewards = av_rewards_dict( - session.learning_path / f"average_reward_per_episode_{session.timestamp_str}.csv" - ) - - # run is seeded so should have the expected learn value - assert learn_mean_rewards == sb3_expected_avg_reward_per_episode - - # run an evaluation - session.evaluate() - - # load the evaluation average reward csv file - eval_mean_reward = av_rewards_dict( - session.evaluation_path / f"average_reward_per_episode_{session.timestamp_str}.csv" - ) - - # the agent config ran the evaluation in deterministic mode, so should have the same reward value - assert len(set(eval_mean_reward.values())) == 1 - - # the evaluation should be the same as a previous run - assert next(iter(set(eval_mean_reward.values()))) == sb3_expected_eval_rewards - - # delete the test directory - shutil.rmtree(test_path) - - -@pytest.skip("Deprecated") # TODO: implement a similar test for primaite v3 -def test_run_loading(): - """Test loading session via main.run.""" - test_path = copy_session_asset(TEST_ASSETS_ROOT / "example_sb3_agent_session") - - # create loaded session - run(session_path=test_path) - - learn_mean_rewards = av_rewards_dict( - next(Path(test_path).rglob("**/learning/average_reward_per_episode_*.csv"), None) - ) - - # run is seeded so should have the expected learn value - assert learn_mean_rewards == sb3_expected_avg_reward_per_episode - - # delete the test directory - shutil.rmtree(test_path) - - -def test_cli(): - """Test loading session via CLI.""" - test_path = copy_session_asset(TEST_ASSETS_ROOT / "example_sb3_agent_session") - result = runner.invoke(app, ["session", "--load", test_path]) - - # cli should work - assert result.exit_code == 0 - - learn_mean_rewards = av_rewards_dict( - next(Path(test_path).rglob("**/learning/average_reward_per_episode_*.csv"), None) - ) - - # run is seeded so should have the expected learn value - assert learn_mean_rewards == sb3_expected_avg_reward_per_episode - - # delete the test directory - shutil.rmtree(test_path) diff --git a/tests/test_single_action_space.py b/tests/test_single_action_space.py deleted file mode 100644 index 949898cf..00000000 --- a/tests/test_single_action_space.py +++ /dev/null @@ -1,132 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import time - -import pytest - -# from primaite.acl.acl_rule import ACLRule -# from primaite.common.enums import HardwareState -# from primaite.environment.primaite_env import Primaite -from tests import TEST_CONFIG_ROOT - - -@pytest.skip("Deprecated") -def run_generic_set_actions(env: Primaite): - """Run against a generic agent with specified blue agent actions.""" - # Reset the environment at the start of the episode - # env.reset() - training_config = env.training_config - for episode in range(0, training_config.num_train_episodes): - for step in range(0, training_config.num_train_steps): - # Send the observation space to the agent to get an action - # TEMP - random action for now - # action = env.blue_agent_action(obs) - action = 0 - # print("Episode:", episode, "\nStep:", step) - if step == 5: - # [1, 1, 2, 1, 1, 1, 1(position)] - # Creates an ACL rule - # Allows traffic from server_1 to node_1 on port FTP - action = 56 - elif step == 7: - # [1, 1, 2, 0] Node Action - # Sets Node 1 Hardware State to OFF - # Does not resolve any service - action = 128 - # Run the simulation step on the live environment - obs, reward, done, info = env.step(action) - - # Break if done is True - if done: - break - - # Introduce a delay between steps - time.sleep(training_config.time_delay / 1000) - - # Reset the environment at the end of the episode - # env.reset() - - # env.close() - - -@pytest.skip("Deprecated") -@pytest.mark.parametrize( - "temp_primaite_session", - [ - [ - TEST_CONFIG_ROOT / "single_action_space_main_config.yaml", - TEST_CONFIG_ROOT / "single_action_space_lay_down_config.yaml", - ] - ], - indirect=True, -) -def test_single_action_space_is_valid(temp_primaite_session): - """Test single action space is valid.""" - # TODO: Refactor this at some point to build a custom ACL Hardcoded - # Agent and then patch the AgentIdentifier Enum class so that it - # has ACL_AGENT. This then allows us to set the agent identified in - # the main config and is a bit cleaner. - with temp_primaite_session as session: - env = session.env - - run_generic_set_actions(env) - # Retrieve the action space dictionary values from environment - env_action_space_dict = env.action_dict.values() - # Flags to check the conditions of the action space - contains_acl_actions = False - contains_node_actions = False - both_action_spaces = False - # Loop through each element of the list (which is every value from the dictionary) - for dict_item in env_action_space_dict: - # Node action detected - if len(dict_item) == 4: - contains_node_actions = True - # Link action detected - elif len(dict_item) == 7: - contains_acl_actions = True - # If both are there then the ANY action type is working - if contains_node_actions and contains_acl_actions: - both_action_spaces = True - # Check condition should be True - assert both_action_spaces - - -@pytest.skip("Deprecated") -@pytest.mark.parametrize( - "temp_primaite_session", - [ - [ - TEST_CONFIG_ROOT / "single_action_space_fixed_blue_actions_main_config.yaml", - TEST_CONFIG_ROOT / "single_action_space_lay_down_config.yaml", - ] - ], - indirect=True, -) -def test_agent_is_executing_actions_from_both_spaces(temp_primaite_session): - """Test to ensure the blue agent is carrying out both kinds of operations (NODE & ACL).""" - # TODO: Refactor this at some point to build a custom ACL Hardcoded - # Agent and then patch the AgentIdentifier Enum class so that it - # has ACL_AGENT. This then allows us to set the agent identified in - # the main config and is a bit cleaner. - with temp_primaite_session as session: - env = session.env - # Run environment with specified fixed blue agent actions only - run_generic_set_actions(env) - # Retrieve hardware state of computer_1 node in laydown config - # Agent turned this off in Step 5 - computer_node_hardware_state = env.nodes["1"].hardware_state - # Retrieve the Access Control List object stored by the environment at the end of the episode - access_control_list = env.acl - # Use the Access Control List object acl object attribute to get dictionary - # Use dictionary.values() to get total list of all items in the dictionary - acl_rules_list = access_control_list.acl - # Length of this list tells you how many items are in the dictionary - # This number is the frequency of Access Control Rules in the environment - # In the scenario, we specified that the agent should create only 1 acl rule - # This 1 rule added to the implicit deny means there should be 2 rules in total. - rules_count = 0 - for rule in acl_rules_list: - if isinstance(rule, ACLRule): - rules_count += 1 - # Therefore these statements below MUST be true - assert computer_node_hardware_state == HardwareState.OFF - assert rules_count == 2 diff --git a/tests/test_train_eval_episode_steps.py b/tests/test_train_eval_episode_steps.py deleted file mode 100644 index 0be968ae..00000000 --- a/tests/test_train_eval_episode_steps.py +++ /dev/null @@ -1,45 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import pytest - -from primaite import getLogger - -# from primaite.config.lay_down_config import dos_very_basic_config_path -from tests import TEST_CONFIG_ROOT - -_LOGGER = getLogger(__name__) - - -@pytest.skip("Deprecated") -@pytest.mark.parametrize( - "temp_primaite_session", - [[TEST_CONFIG_ROOT / "train_episode_step.yaml", dos_very_basic_config_path()]], - indirect=True, -) -def test_eval_steps_differ_from_training(temp_primaite_session): - """Uses PrimaiteSession class to compare number of episodes used for training and evaluation. - - Train_episode_step.yaml main config: - num_train_steps = 25 - num_train_episodes = 3 - num_eval_steps = 17 - num_eval_episodes = 1 - """ - expected_learning_metadata = {"total_episodes": 3, "total_time_steps": 75} - expected_evaluation_metadata = {"total_episodes": 1, "total_time_steps": 17} - - with temp_primaite_session as session: - # Run learning and check episode and step counts - session.learn() - assert session.env.actual_episode_count == expected_learning_metadata["total_episodes"] - assert session.env.total_step_count == expected_learning_metadata["total_time_steps"] - - # Run evaluation and check episode and step counts - session.evaluate() - assert session.env.actual_episode_count == expected_evaluation_metadata["total_episodes"] - assert session.env.total_step_count == expected_evaluation_metadata["total_time_steps"] - - # Load the session_metadata.json file and check that the both the - # learning and evaluation match what is expected above - metadata = session.metadata_file_as_dict() - assert metadata["learning"] == expected_learning_metadata - assert metadata["evaluation"] == expected_evaluation_metadata diff --git a/tests/test_training_config.py b/tests/test_training_config.py deleted file mode 100644 index e4e3fa32..00000000 --- a/tests/test_training_config.py +++ /dev/null @@ -1,40 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import pytest -import yaml - -# from primaite.config import training_config -from tests import TEST_CONFIG_ROOT - - -@pytest.skip("Deprecated") -def test_legacy_lay_down_config_yaml_conversion(): - """Tests the conversion of legacy lay down config files.""" - legacy_path = TEST_CONFIG_ROOT / "legacy_conversion" / "legacy_training_config.yaml" - new_path = TEST_CONFIG_ROOT / "legacy_conversion" / "new_training_config.yaml" - - with open(legacy_path, "r") as file: - legacy_dict = yaml.safe_load(file) - - with open(new_path, "r") as file: - new_dict = yaml.safe_load(file) - - converted_dict = training_config.convert_legacy_training_config_dict(legacy_dict) - - for key, value in new_dict.items(): - assert converted_dict[key] == value - - -@pytest.skip("Deprecated") -def test_create_config_values_main_from_file(): - """Tests creating an instance of TrainingConfig from file.""" - new_path = TEST_CONFIG_ROOT / "legacy_conversion" / "new_training_config.yaml" - - training_config.load(new_path) - - -@pytest.skip("Deprecated") -def test_create_config_values_main_from_legacy_file(): - """Tests creating an instance of TrainingConfig from legacy file.""" - new_path = TEST_CONFIG_ROOT / "legacy_conversion" / "legacy_training_config.yaml" - - training_config.load(new_path, legacy_file=True) From 4872c939ff46e53eaf31e6e67ba045b807343c3d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 25 Oct 2023 17:19:24 +0100 Subject: [PATCH 255/980] Apply suggestions from code review --- docs/source/config(v2).rst | 489 +++++++++++++++++ docs/source/config(v3).rst | 13 - docs/source/config.rst | 500 +----------------- docs/source/game_layer.rst | 12 +- .../simulator/file_system/file_system.py | 1 - 5 files changed, 507 insertions(+), 508 deletions(-) create mode 100644 docs/source/config(v2).rst delete mode 100644 docs/source/config(v3).rst diff --git a/docs/source/config(v2).rst b/docs/source/config(v2).rst new file mode 100644 index 00000000..daf7f90b --- /dev/null +++ b/docs/source/config(v2).rst @@ -0,0 +1,489 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _config: + +The Config Files Explained +========================== + +PrimAITE uses two configuration files for its operation: + +* **The Training Config** + + Used to define the top-level settings of the PrimAITE environment, the reward values, and the session that is to be run. + +* **The Lay Down Config** + + Used to define the low-level settings of a session, including the network laydown, green / red agent information exchange requirements (IERSs) and Access Control Rules. + +Training Config: +******************* + +The Training Config file consists of the following attributes: + +**Generic Config Values** + + +* **agent_framework** [enum] + + This identifies the agent framework to be used to instantiate the agent algorithm. Select from one of the following: + + * NONE - Where a user developed agent is to be used + * SB3 - Stable Baselines3 + * RLLIB - Ray RLlib. + +* **agent_identifier** + + This identifies the agent to use for the session. Select from one of the following: + + * A2C - Advantage Actor Critic + * PPO - Proximal Policy Optimization + * HARDCODED - A custom built deterministic agent + * RANDOM - A Stochastic random agent + + +* **random_red_agent** [bool] + + Determines if the session should be run with a random red agent + +* **action_type** [enum] + + Determines whether a NODE, ACL, or ANY (combined NODE & ACL) action space format is adopted for the session + + +* **OBSERVATION_SPACE** [dict] + + Allows for user to configure observation space by combining one or more observation components. List of available + components is in :py:mod:`primaite.environment.observations`. + + The observation space config item should have a ``components`` key which is a list of components. Each component + config must have a ``name`` key, and can optionally have an ``options`` key. The ``options`` are passed to the + component while it is being initialised. + + This example illustrates the correct format for the observation space config item + + .. code-block:: yaml + + observation_space: + components: + - name: NODE_LINK_TABLE + - name: NODE_STATUSES + - name: LINK_TRAFFIC_LEVELS + - name: ACCESS_CONTROL_LIST + options: + combine_service_traffic : False + quantisation_levels: 99 + + + Currently available components are: + + * :py:mod:`NODE_LINK_TABLE` this does not accept any additional options + * :py:mod:`NODE_STATUSES`, this does not accept any additional options + * :py:mod:`ACCESS_CONTROL_LIST`, this does not accept additional options + * :py:mod:`LINK_TRAFFIC_LEVELS`, this accepts the following options: + + * ``combine_service_traffic`` - whether to consider bandwidth use separately for each network protocol or combine them into a single bandwidth reading (boolean) + * ``quantisation_levels`` - how many discrete bandwidth usage levels to use for encoding. This can be an integer equal to or greater than 3. + + The other configurable item is ``flatten`` which is false by default. When set to true, the observation space is flattened (turned into a 1-D vector). You should use this if your RL agent does not natively support observation space types like ``gym.Spaces.Tuple``. + +* **num_train_episodes** [int] + + This defines the number of episodes that the agent will train for. + + +* **num_train_steps** [int] + + Determines the number of steps to run in each episode of the training session. + + +* **num_eval_episodes** [int] + + This defines the number of episodes that the agent will be evaluated over. + + +* **num_eval_steps** [int] + + Determines the number of steps to run in each episode of the evaluation session. + + +* **time_delay** [int] + + The time delay (in milliseconds) to take between each step when running a GENERIC agent session + + +* **session_type** [text] + + Type of session to be run (TRAINING, EVALUATION, or BOTH) + +* **load_agent** [bool] + + Determine whether to load an agent from file + +* **agent_load_file** [text] + + File path and file name of agent if you're loading one in + +* **observation_space_high_value** [int] + + The high value to use for values in the observation space. This is set to 1000000000 by default, and should not need changing in most cases + +* **implicit_acl_rule** [str] + + Determines which Explicit rule the ACL list has - two options are: DENY or ALLOW. + +* **max_number_acl_rules** [int] + + Sets a limit on how many ACL rules there can be in the ACL list throughout the training session. + +**Reward-Based Config Values** + +Rewards are calculated based on the difference between the current state and reference state (the 'should be' state) of the environment. + +* **Generic [all_ok]** [float] + + The score to give when the current situation (for a given component) is no different from that expected in the baseline (i.e. as though no blue or red agent actions had been undertaken) + +* **Node Hardware State [off_should_be_on]** [float] + + The score to give when the node should be on, but is off + +* **Node Hardware State [off_should_be_resetting]** [float] + + The score to give when the node should be resetting, but is off + +* **Node Hardware State [on_should_be_off]** [float] + + The score to give when the node should be off, but is on + +* **Node Hardware State [on_should_be_resetting]** [float] + + The score to give when the node should be resetting, but is on + +* **Node Hardware State [resetting_should_be_on]** [float] + + The score to give when the node should be on, but is resetting + +* **Node Hardware State [resetting_should_be_off]** [float] + + The score to give when the node should be off, but is resetting + +* **Node Hardware State [resetting]** [float] + + The score to give when the node is resetting + +* **Node Operating System or Service State [good_should_be_patching]** [float] + + The score to give when the state should be patching, but is good + +* **Node Operating System or Service State [good_should_be_compromised]** [float] + + The score to give when the state should be compromised, but is good + +* **Node Operating System or Service State [good_should_be_overwhelmed]** [float] + + The score to give when the state should be overwhelmed, but is good + +* **Node Operating System or Service State [patching_should_be_good]** [float] + + The score to give when the state should be good, but is patching + +* **Node Operating System or Service State [patching_should_be_compromised]** [float] + + The score to give when the state should be compromised, but is patching + +* **Node Operating System or Service State [patching_should_be_overwhelmed]** [float] + + The score to give when the state should be overwhelmed, but is patching + +* **Node Operating System or Service State [patching]** [float] + + The score to give when the state is patching + +* **Node Operating System or Service State [compromised_should_be_good]** [float] + + The score to give when the state should be good, but is compromised + +* **Node Operating System or Service State [compromised_should_be_patching]** [float] + + The score to give when the state should be patching, but is compromised + +* **Node Operating System or Service State [compromised_should_be_overwhelmed]** [float] + + The score to give when the state should be overwhelmed, but is compromised + +* **Node Operating System or Service State [compromised]** [float] + + The score to give when the state is compromised + +* **Node Operating System or Service State [overwhelmed_should_be_good]** [float] + + The score to give when the state should be good, but is overwhelmed + +* **Node Operating System or Service State [overwhelmed_should_be_patching]** [float] + + The score to give when the state should be patching, but is overwhelmed + +* **Node Operating System or Service State [overwhelmed_should_be_compromised]** [float] + + The score to give when the state should be compromised, but is overwhelmed + +* **Node Operating System or Service State [overwhelmed]** [float] + + The score to give when the state is overwhelmed + +* **Node File System State [good_should_be_repairing]** [float] + + The score to give when the state should be repairing, but is good + +* **Node File System State [good_should_be_restoring]** [float] + + The score to give when the state should be restoring, but is good + +* **Node File System State [good_should_be_corrupt]** [float] + + The score to give when the state should be corrupt, but is good + +* **Node File System State [good_should_be_destroyed]** [float] + + The score to give when the state should be destroyed, but is good + +* **Node File System State [repairing_should_be_good]** [float] + + The score to give when the state should be good, but is repairing + +* **Node File System State [repairing_should_be_restoring]** [float] + + The score to give when the state should be restoring, but is repairing + +* **Node File System State [repairing_should_be_corrupt]** [float] + + The score to give when the state should be corrupt, but is repairing + +* **Node File System State [repairing_should_be_destroyed]** [float] + + The score to give when the state should be destroyed, but is repairing + +* **Node File System State [repairing]** [float] + + The score to give when the state is repairing + +* **Node File System State [restoring_should_be_good]** [float] + + The score to give when the state should be good, but is restoring + +* **Node File System State [restoring_should_be_repairing]** [float] + + The score to give when the state should be repairing, but is restoring + +* **Node File System State [restoring_should_be_corrupt]** [float] + + The score to give when the state should be corrupt, but is restoring + +* **Node File System State [restoring_should_be_destroyed]** [float] + + The score to give when the state should be destroyed, but is restoring + +* **Node File System State [restoring]** [float] + + The score to give when the state is restoring + +* **Node File System State [corrupt_should_be_good]** [float] + + The score to give when the state should be good, but is corrupt + +* **Node File System State [corrupt_should_be_repairing]** [float] + + The score to give when the state should be repairing, but is corrupt + +* **Node File System State [corrupt_should_be_restoring]** [float] + + The score to give when the state should be restoring, but is corrupt + +* **Node File System State [corrupt_should_be_destroyed]** [float] + + The score to give when the state should be destroyed, but is corrupt + +* **Node File System State [corrupt]** [float] + + The score to give when the state is corrupt + +* **Node File System State [destroyed_should_be_good]** [float] + + The score to give when the state should be good, but is destroyed + +* **Node File System State [destroyed_should_be_repairing]** [float] + + The score to give when the state should be repairing, but is destroyed + +* **Node File System State [destroyed_should_be_restoring]** [float] + + The score to give when the state should be restoring, but is destroyed + +* **Node File System State [destroyed_should_be_corrupt]** [float] + + The score to give when the state should be corrupt, but is destroyed + +* **Node File System State [destroyed]** [float] + + The score to give when the state is destroyed + +* **Node File System State [scanning]** [float] + + The score to give when the state is scanning + +* **IER Status [red_ier_running]** [float] + + The score to give when a red agent IER is permitted to run + +* **IER Status [green_ier_blocked]** [float] + + The score to give when a green agent IER is prevented from running + +**Patching / Reset Durations** + +* **os_patching_duration** [int] + + The number of steps to take when patching an Operating System + +* **node_reset_duration** [int] + + The number of steps to take when resetting a node's hardware state + +* **service_patching_duration** [int] + + The number of steps to take when patching a service + +* **file_system_repairing_limit** [int]: + + The number of steps to take when repairing the file system + +* **file_system_restoring_limit** [int] + + The number of steps to take when restoring the file system + +* **file_system_scanning_limit** [int] + + The number of steps to take when scanning the file system + +* **deterministic** [bool] + + Set to true if the agent evaluation should be deterministic. Default is ``False`` + +* **seed** [int] + + Seed used in the randomisation in agent training. Default is ``None`` + +The Lay Down Config +******************* + +The lay down config file consists of the following attributes: + + +* **itemType: STEPS** [int] + +* **item_type: PORTS** [int] + + Provides a list of ports modelled in this session + +* **item_type: SERVICES** [freetext] + + Provides a list of services modelled in this session + +* **item_type: NODE** + + Defines a node included in the system laydown being simulated. It should consist of the following attributes: + + * **id** [int]: Unique ID for this YAML item + * **name** [freetext]: Human-readable name of the component + * **node_class** [enum]: Relates to the base type of the node. Can be SERVICE, ACTIVE or PASSIVE. PASSIVE nodes do not have an operating system or services. ACTIVE nodes have an operating system, but no services. SERVICE nodes have both an operating system and one or more services + * **node_type** [enum]: Relates to the component type. Can be one of CCTV, SWITCH, COMPUTER, LINK, MONITOR, PRINTER, LOP, RTU, ACTUATOR or SERVER + * **priority** [enum]: Provides a priority for each node. Can be one of P1, P2, P3, P4 or P5 (which P1 being the highest) + * **hardware_state** [enum]: The initial hardware state of the node. Can be one of ON, OFF or RESETTING + * **ip_address** [IP address]: The IP address of the component in format xxx.xxx.xxx.xxx + * **software_state** [enum]: The intial state of the node operating system. Can be GOOD, PATCHING or COMPROMISED + * **file_system_state** [enum]: The initial state of the node file system. Can be GOOD, CORRUPT, DESTROYED, REPAIRING or RESTORING + * **services**: For each service associated with the node: + + * **name** [freetext]: Free-text name of the service, but must match one of the services defined for the system in the services list + * **port** [int]: Integer value of the port related to this service, but must match one of the ports defined for the system in the ports list + * **state** [enum]: The initial state of the service. Can be one of GOOD, PATCHING, COMPROMISED or OVERWHELMED + +* **item_type: LINK** + + Defines a link included in the system laydown being simulated. It should consist of the following attributes: + + * **id** [int]: Unique ID for this YAML item + * **name** [freetext]: Human-readable name of the component + * **bandwidth** [int]: The bandwidth (in bits/s) of the link + * **source** [int]: The ID of the source node + * **destination** [int]: The ID of the destination node + +* **item_type: GREEN_IER** + + Defines a green agent Information Exchange Requirement (IER). It should consist of: + + * **id** [int]: Unique ID for this YAML item + * **start_step** [int]: The start step (in the episode) for this IER to begin + * **end_step** [int]: The end step (in the episode) for this IER to finish + * **load** [int]: The load (in bits/s) for this IER to apply to links + * **protocol** [freetext]: The protocol to apply to the links. This must match a value in the services list + * **port** [int]: The port that the protocol is running on. This must match a value in the ports list + * **source** [int]: The ID of the source node + * **destination** [int]: The ID of the destination node + * **mission_criticality** [enum]: The mission criticality of this IER (with 5 being highest, 1 lowest) + +* **item_type: RED_IER** + + Defines a red agent Information Exchange Requirement (IER). It should consist of: + + * **id** [int]: Unique ID for this YAML item + * **start_step** [int]: The start step (in the episode) for this IER to begin + * **end_step** [int]: The end step (in the episode) for this IER to finish + * **load** [int]: The load (in bits/s) for this IER to apply to links + * **protocol** [freetext]: The protocol to apply to the links. This must match a value in the services list + * **port** [int]: The port that the protocol is running on. This must match a value in the ports list + * **source** [int]: The ID of the source node + * **destination** [int]: The ID of the destination node + * **mission_criticality** [enum]: Not currently used. Default to 0 + +* **item_type: GREEN_POL** + + Defines a green agent pattern-of-life instruction. It should consist of: + + * **id** [int]: Unique ID for this YAML item + * **start_step** [int]: The start step (in the episode) for this PoL to begin + * **end_step** [int]: Not currently used. Default to same as start step + * **nodeId** [int]: The ID of the node to apply the PoL to + * **type** [enum]: The type of PoL to apply. Can be one of OPERATING, OS or SERVICE + * **protocol** [freetext]: The protocol to be affected if SERVICE type is chosen. Must match a value in the services list + * **state** [enuum]: The state to apply to the node (which represents the PoL change). Can be one of ON, OFF or RESETTING (for node state) or GOOD, PATCHING or COMPROMISED (for Software State) or GOOD, PATCHING, COMPROMISED or OVERWHELMED (for service state) + +* **item_type: RED_POL** + + Defines a red agent pattern-of-life instruction. It should consist of: + + * **id** [int]: Unique ID for this YAML item + * **start_step** [int]: The start step (in the episode) for this PoL to begin + * **end_step** [int]: Not currently used. Default to same as start step + * **targetNodeId** [int]: The ID of the node to apply the PoL to + * **initiator** [enum]: What initiates the PoL. Can be DIRECT, IER or SERVICE + * **type** [enum]: The type of PoL to apply. Can be one of OPERATING, OS or SERVICE + * **protocol** [freetext]: The protocol to be affected if SERVICE type is chosen. Must match a value in the services list + * **state** [enum]: The state to apply to the node (which represents the PoL change). Can be one of ON, OFF or RESETTING (for node state) or GOOD, PATCHING or COMPROMISED (for Software State) or GOOD, PATCHING, COMPROMISED or OVERWHELMED (for service state) or GOOD, CORRUPT, DESTROYED, REPAIRING or RESTORING (for file system state) + * **sourceNodeId** [int] The ID of the source node containing the service to check (used for SERVICE initiator) + * **sourceNodeService** [freetext]: The service on the source node to check (used for SERVICE initiator). Must match a value in the services list for this node + * **sourceNodeServiceState** [enum]: The state of the source node service to check (used for SERVICE initiator). Can be one of GOOD, PATCHING, COMPROMISED or OVERWHELMED + +* **item_type: ACL_RULE** + + Defines an initial Access Control List (ACL) rule. It should consist of: + + * **id** [int]: Unique ID for this YAML item + * **permission** [enum]: Defines either an allow or deny rule. Value must be either DENY or ALLOW + * **source** [IP address]: Defines the source IP address for the rule in xxx.xxx.xxx.xxx format + * **destination** [IP address]: Defines the destination IP address for the rule in xxx.xxx.xxx.xxx format + * **protocol** [freetext]: Defines the protocol for the rule. Must match a value in the services list + * **port** [int]: Defines the port for the rule. Must match a value in the ports list + * **position** [int]: Defines where to place the ACL rule in the list. Lower index or (higher up in the list) means they are checked first. Index starts at 0 (Python indexes). diff --git a/docs/source/config(v3).rst b/docs/source/config(v3).rst deleted file mode 100644 index 0ce8b547..00000000 --- a/docs/source/config(v3).rst +++ /dev/null @@ -1,13 +0,0 @@ -Primaite v3 config -****************** - -PrimAITE uses a single configuration file to define a cybersecurity scenario. This includes the computer network and multiple agents. There are three main sections: training_config, game, and simulation. - -The simulation section describes the simulated network environment with which the agetns interact. - -The game section describes the agents and their capabilities. Each agent has a unique type and is associated with a team (GREEN, RED, or BLUE). Each agent has a configurable observation space, action space, and reward function. - -The training_config section describes the training parameters for the learning agents. This includes the number of episodes, the number of steps per episode, and the number of steps before the agents start learning. The training_config section also describes the learning algorithm used by the agents. The learning algorithm is specified by the name of the algorithm and the hyperparameters for the algorithm. The hyperparameters are specific to each algorithm and are described in the documentation for each algorithm. - -.. only:: comment - This needs a bit of refactoring so I haven't written extensive documentation about the config yet. diff --git a/docs/source/config.rst b/docs/source/config.rst index daf7f90b..0ce8b547 100644 --- a/docs/source/config.rst +++ b/docs/source/config.rst @@ -1,489 +1,13 @@ +Primaite v3 config +****************** + +PrimAITE uses a single configuration file to define a cybersecurity scenario. This includes the computer network and multiple agents. There are three main sections: training_config, game, and simulation. + +The simulation section describes the simulated network environment with which the agetns interact. + +The game section describes the agents and their capabilities. Each agent has a unique type and is associated with a team (GREEN, RED, or BLUE). Each agent has a configurable observation space, action space, and reward function. + +The training_config section describes the training parameters for the learning agents. This includes the number of episodes, the number of steps per episode, and the number of steps before the agents start learning. The training_config section also describes the learning algorithm used by the agents. The learning algorithm is specified by the name of the algorithm and the hyperparameters for the algorithm. The hyperparameters are specific to each algorithm and are described in the documentation for each algorithm. + .. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -.. _config: - -The Config Files Explained -========================== - -PrimAITE uses two configuration files for its operation: - -* **The Training Config** - - Used to define the top-level settings of the PrimAITE environment, the reward values, and the session that is to be run. - -* **The Lay Down Config** - - Used to define the low-level settings of a session, including the network laydown, green / red agent information exchange requirements (IERSs) and Access Control Rules. - -Training Config: -******************* - -The Training Config file consists of the following attributes: - -**Generic Config Values** - - -* **agent_framework** [enum] - - This identifies the agent framework to be used to instantiate the agent algorithm. Select from one of the following: - - * NONE - Where a user developed agent is to be used - * SB3 - Stable Baselines3 - * RLLIB - Ray RLlib. - -* **agent_identifier** - - This identifies the agent to use for the session. Select from one of the following: - - * A2C - Advantage Actor Critic - * PPO - Proximal Policy Optimization - * HARDCODED - A custom built deterministic agent - * RANDOM - A Stochastic random agent - - -* **random_red_agent** [bool] - - Determines if the session should be run with a random red agent - -* **action_type** [enum] - - Determines whether a NODE, ACL, or ANY (combined NODE & ACL) action space format is adopted for the session - - -* **OBSERVATION_SPACE** [dict] - - Allows for user to configure observation space by combining one or more observation components. List of available - components is in :py:mod:`primaite.environment.observations`. - - The observation space config item should have a ``components`` key which is a list of components. Each component - config must have a ``name`` key, and can optionally have an ``options`` key. The ``options`` are passed to the - component while it is being initialised. - - This example illustrates the correct format for the observation space config item - - .. code-block:: yaml - - observation_space: - components: - - name: NODE_LINK_TABLE - - name: NODE_STATUSES - - name: LINK_TRAFFIC_LEVELS - - name: ACCESS_CONTROL_LIST - options: - combine_service_traffic : False - quantisation_levels: 99 - - - Currently available components are: - - * :py:mod:`NODE_LINK_TABLE` this does not accept any additional options - * :py:mod:`NODE_STATUSES`, this does not accept any additional options - * :py:mod:`ACCESS_CONTROL_LIST`, this does not accept additional options - * :py:mod:`LINK_TRAFFIC_LEVELS`, this accepts the following options: - - * ``combine_service_traffic`` - whether to consider bandwidth use separately for each network protocol or combine them into a single bandwidth reading (boolean) - * ``quantisation_levels`` - how many discrete bandwidth usage levels to use for encoding. This can be an integer equal to or greater than 3. - - The other configurable item is ``flatten`` which is false by default. When set to true, the observation space is flattened (turned into a 1-D vector). You should use this if your RL agent does not natively support observation space types like ``gym.Spaces.Tuple``. - -* **num_train_episodes** [int] - - This defines the number of episodes that the agent will train for. - - -* **num_train_steps** [int] - - Determines the number of steps to run in each episode of the training session. - - -* **num_eval_episodes** [int] - - This defines the number of episodes that the agent will be evaluated over. - - -* **num_eval_steps** [int] - - Determines the number of steps to run in each episode of the evaluation session. - - -* **time_delay** [int] - - The time delay (in milliseconds) to take between each step when running a GENERIC agent session - - -* **session_type** [text] - - Type of session to be run (TRAINING, EVALUATION, or BOTH) - -* **load_agent** [bool] - - Determine whether to load an agent from file - -* **agent_load_file** [text] - - File path and file name of agent if you're loading one in - -* **observation_space_high_value** [int] - - The high value to use for values in the observation space. This is set to 1000000000 by default, and should not need changing in most cases - -* **implicit_acl_rule** [str] - - Determines which Explicit rule the ACL list has - two options are: DENY or ALLOW. - -* **max_number_acl_rules** [int] - - Sets a limit on how many ACL rules there can be in the ACL list throughout the training session. - -**Reward-Based Config Values** - -Rewards are calculated based on the difference between the current state and reference state (the 'should be' state) of the environment. - -* **Generic [all_ok]** [float] - - The score to give when the current situation (for a given component) is no different from that expected in the baseline (i.e. as though no blue or red agent actions had been undertaken) - -* **Node Hardware State [off_should_be_on]** [float] - - The score to give when the node should be on, but is off - -* **Node Hardware State [off_should_be_resetting]** [float] - - The score to give when the node should be resetting, but is off - -* **Node Hardware State [on_should_be_off]** [float] - - The score to give when the node should be off, but is on - -* **Node Hardware State [on_should_be_resetting]** [float] - - The score to give when the node should be resetting, but is on - -* **Node Hardware State [resetting_should_be_on]** [float] - - The score to give when the node should be on, but is resetting - -* **Node Hardware State [resetting_should_be_off]** [float] - - The score to give when the node should be off, but is resetting - -* **Node Hardware State [resetting]** [float] - - The score to give when the node is resetting - -* **Node Operating System or Service State [good_should_be_patching]** [float] - - The score to give when the state should be patching, but is good - -* **Node Operating System or Service State [good_should_be_compromised]** [float] - - The score to give when the state should be compromised, but is good - -* **Node Operating System or Service State [good_should_be_overwhelmed]** [float] - - The score to give when the state should be overwhelmed, but is good - -* **Node Operating System or Service State [patching_should_be_good]** [float] - - The score to give when the state should be good, but is patching - -* **Node Operating System or Service State [patching_should_be_compromised]** [float] - - The score to give when the state should be compromised, but is patching - -* **Node Operating System or Service State [patching_should_be_overwhelmed]** [float] - - The score to give when the state should be overwhelmed, but is patching - -* **Node Operating System or Service State [patching]** [float] - - The score to give when the state is patching - -* **Node Operating System or Service State [compromised_should_be_good]** [float] - - The score to give when the state should be good, but is compromised - -* **Node Operating System or Service State [compromised_should_be_patching]** [float] - - The score to give when the state should be patching, but is compromised - -* **Node Operating System or Service State [compromised_should_be_overwhelmed]** [float] - - The score to give when the state should be overwhelmed, but is compromised - -* **Node Operating System or Service State [compromised]** [float] - - The score to give when the state is compromised - -* **Node Operating System or Service State [overwhelmed_should_be_good]** [float] - - The score to give when the state should be good, but is overwhelmed - -* **Node Operating System or Service State [overwhelmed_should_be_patching]** [float] - - The score to give when the state should be patching, but is overwhelmed - -* **Node Operating System or Service State [overwhelmed_should_be_compromised]** [float] - - The score to give when the state should be compromised, but is overwhelmed - -* **Node Operating System or Service State [overwhelmed]** [float] - - The score to give when the state is overwhelmed - -* **Node File System State [good_should_be_repairing]** [float] - - The score to give when the state should be repairing, but is good - -* **Node File System State [good_should_be_restoring]** [float] - - The score to give when the state should be restoring, but is good - -* **Node File System State [good_should_be_corrupt]** [float] - - The score to give when the state should be corrupt, but is good - -* **Node File System State [good_should_be_destroyed]** [float] - - The score to give when the state should be destroyed, but is good - -* **Node File System State [repairing_should_be_good]** [float] - - The score to give when the state should be good, but is repairing - -* **Node File System State [repairing_should_be_restoring]** [float] - - The score to give when the state should be restoring, but is repairing - -* **Node File System State [repairing_should_be_corrupt]** [float] - - The score to give when the state should be corrupt, but is repairing - -* **Node File System State [repairing_should_be_destroyed]** [float] - - The score to give when the state should be destroyed, but is repairing - -* **Node File System State [repairing]** [float] - - The score to give when the state is repairing - -* **Node File System State [restoring_should_be_good]** [float] - - The score to give when the state should be good, but is restoring - -* **Node File System State [restoring_should_be_repairing]** [float] - - The score to give when the state should be repairing, but is restoring - -* **Node File System State [restoring_should_be_corrupt]** [float] - - The score to give when the state should be corrupt, but is restoring - -* **Node File System State [restoring_should_be_destroyed]** [float] - - The score to give when the state should be destroyed, but is restoring - -* **Node File System State [restoring]** [float] - - The score to give when the state is restoring - -* **Node File System State [corrupt_should_be_good]** [float] - - The score to give when the state should be good, but is corrupt - -* **Node File System State [corrupt_should_be_repairing]** [float] - - The score to give when the state should be repairing, but is corrupt - -* **Node File System State [corrupt_should_be_restoring]** [float] - - The score to give when the state should be restoring, but is corrupt - -* **Node File System State [corrupt_should_be_destroyed]** [float] - - The score to give when the state should be destroyed, but is corrupt - -* **Node File System State [corrupt]** [float] - - The score to give when the state is corrupt - -* **Node File System State [destroyed_should_be_good]** [float] - - The score to give when the state should be good, but is destroyed - -* **Node File System State [destroyed_should_be_repairing]** [float] - - The score to give when the state should be repairing, but is destroyed - -* **Node File System State [destroyed_should_be_restoring]** [float] - - The score to give when the state should be restoring, but is destroyed - -* **Node File System State [destroyed_should_be_corrupt]** [float] - - The score to give when the state should be corrupt, but is destroyed - -* **Node File System State [destroyed]** [float] - - The score to give when the state is destroyed - -* **Node File System State [scanning]** [float] - - The score to give when the state is scanning - -* **IER Status [red_ier_running]** [float] - - The score to give when a red agent IER is permitted to run - -* **IER Status [green_ier_blocked]** [float] - - The score to give when a green agent IER is prevented from running - -**Patching / Reset Durations** - -* **os_patching_duration** [int] - - The number of steps to take when patching an Operating System - -* **node_reset_duration** [int] - - The number of steps to take when resetting a node's hardware state - -* **service_patching_duration** [int] - - The number of steps to take when patching a service - -* **file_system_repairing_limit** [int]: - - The number of steps to take when repairing the file system - -* **file_system_restoring_limit** [int] - - The number of steps to take when restoring the file system - -* **file_system_scanning_limit** [int] - - The number of steps to take when scanning the file system - -* **deterministic** [bool] - - Set to true if the agent evaluation should be deterministic. Default is ``False`` - -* **seed** [int] - - Seed used in the randomisation in agent training. Default is ``None`` - -The Lay Down Config -******************* - -The lay down config file consists of the following attributes: - - -* **itemType: STEPS** [int] - -* **item_type: PORTS** [int] - - Provides a list of ports modelled in this session - -* **item_type: SERVICES** [freetext] - - Provides a list of services modelled in this session - -* **item_type: NODE** - - Defines a node included in the system laydown being simulated. It should consist of the following attributes: - - * **id** [int]: Unique ID for this YAML item - * **name** [freetext]: Human-readable name of the component - * **node_class** [enum]: Relates to the base type of the node. Can be SERVICE, ACTIVE or PASSIVE. PASSIVE nodes do not have an operating system or services. ACTIVE nodes have an operating system, but no services. SERVICE nodes have both an operating system and one or more services - * **node_type** [enum]: Relates to the component type. Can be one of CCTV, SWITCH, COMPUTER, LINK, MONITOR, PRINTER, LOP, RTU, ACTUATOR or SERVER - * **priority** [enum]: Provides a priority for each node. Can be one of P1, P2, P3, P4 or P5 (which P1 being the highest) - * **hardware_state** [enum]: The initial hardware state of the node. Can be one of ON, OFF or RESETTING - * **ip_address** [IP address]: The IP address of the component in format xxx.xxx.xxx.xxx - * **software_state** [enum]: The intial state of the node operating system. Can be GOOD, PATCHING or COMPROMISED - * **file_system_state** [enum]: The initial state of the node file system. Can be GOOD, CORRUPT, DESTROYED, REPAIRING or RESTORING - * **services**: For each service associated with the node: - - * **name** [freetext]: Free-text name of the service, but must match one of the services defined for the system in the services list - * **port** [int]: Integer value of the port related to this service, but must match one of the ports defined for the system in the ports list - * **state** [enum]: The initial state of the service. Can be one of GOOD, PATCHING, COMPROMISED or OVERWHELMED - -* **item_type: LINK** - - Defines a link included in the system laydown being simulated. It should consist of the following attributes: - - * **id** [int]: Unique ID for this YAML item - * **name** [freetext]: Human-readable name of the component - * **bandwidth** [int]: The bandwidth (in bits/s) of the link - * **source** [int]: The ID of the source node - * **destination** [int]: The ID of the destination node - -* **item_type: GREEN_IER** - - Defines a green agent Information Exchange Requirement (IER). It should consist of: - - * **id** [int]: Unique ID for this YAML item - * **start_step** [int]: The start step (in the episode) for this IER to begin - * **end_step** [int]: The end step (in the episode) for this IER to finish - * **load** [int]: The load (in bits/s) for this IER to apply to links - * **protocol** [freetext]: The protocol to apply to the links. This must match a value in the services list - * **port** [int]: The port that the protocol is running on. This must match a value in the ports list - * **source** [int]: The ID of the source node - * **destination** [int]: The ID of the destination node - * **mission_criticality** [enum]: The mission criticality of this IER (with 5 being highest, 1 lowest) - -* **item_type: RED_IER** - - Defines a red agent Information Exchange Requirement (IER). It should consist of: - - * **id** [int]: Unique ID for this YAML item - * **start_step** [int]: The start step (in the episode) for this IER to begin - * **end_step** [int]: The end step (in the episode) for this IER to finish - * **load** [int]: The load (in bits/s) for this IER to apply to links - * **protocol** [freetext]: The protocol to apply to the links. This must match a value in the services list - * **port** [int]: The port that the protocol is running on. This must match a value in the ports list - * **source** [int]: The ID of the source node - * **destination** [int]: The ID of the destination node - * **mission_criticality** [enum]: Not currently used. Default to 0 - -* **item_type: GREEN_POL** - - Defines a green agent pattern-of-life instruction. It should consist of: - - * **id** [int]: Unique ID for this YAML item - * **start_step** [int]: The start step (in the episode) for this PoL to begin - * **end_step** [int]: Not currently used. Default to same as start step - * **nodeId** [int]: The ID of the node to apply the PoL to - * **type** [enum]: The type of PoL to apply. Can be one of OPERATING, OS or SERVICE - * **protocol** [freetext]: The protocol to be affected if SERVICE type is chosen. Must match a value in the services list - * **state** [enuum]: The state to apply to the node (which represents the PoL change). Can be one of ON, OFF or RESETTING (for node state) or GOOD, PATCHING or COMPROMISED (for Software State) or GOOD, PATCHING, COMPROMISED or OVERWHELMED (for service state) - -* **item_type: RED_POL** - - Defines a red agent pattern-of-life instruction. It should consist of: - - * **id** [int]: Unique ID for this YAML item - * **start_step** [int]: The start step (in the episode) for this PoL to begin - * **end_step** [int]: Not currently used. Default to same as start step - * **targetNodeId** [int]: The ID of the node to apply the PoL to - * **initiator** [enum]: What initiates the PoL. Can be DIRECT, IER or SERVICE - * **type** [enum]: The type of PoL to apply. Can be one of OPERATING, OS or SERVICE - * **protocol** [freetext]: The protocol to be affected if SERVICE type is chosen. Must match a value in the services list - * **state** [enum]: The state to apply to the node (which represents the PoL change). Can be one of ON, OFF or RESETTING (for node state) or GOOD, PATCHING or COMPROMISED (for Software State) or GOOD, PATCHING, COMPROMISED or OVERWHELMED (for service state) or GOOD, CORRUPT, DESTROYED, REPAIRING or RESTORING (for file system state) - * **sourceNodeId** [int] The ID of the source node containing the service to check (used for SERVICE initiator) - * **sourceNodeService** [freetext]: The service on the source node to check (used for SERVICE initiator). Must match a value in the services list for this node - * **sourceNodeServiceState** [enum]: The state of the source node service to check (used for SERVICE initiator). Can be one of GOOD, PATCHING, COMPROMISED or OVERWHELMED - -* **item_type: ACL_RULE** - - Defines an initial Access Control List (ACL) rule. It should consist of: - - * **id** [int]: Unique ID for this YAML item - * **permission** [enum]: Defines either an allow or deny rule. Value must be either DENY or ALLOW - * **source** [IP address]: Defines the source IP address for the rule in xxx.xxx.xxx.xxx format - * **destination** [IP address]: Defines the destination IP address for the rule in xxx.xxx.xxx.xxx format - * **protocol** [freetext]: Defines the protocol for the rule. Must match a value in the services list - * **port** [int]: Defines the port for the rule. Must match a value in the ports list - * **position** [int]: Defines where to place the ACL rule in the list. Lower index or (higher up in the list) means they are checked first. Index starts at 0 (Python indexes). + This needs a bit of refactoring so I haven't written extensive documentation about the config yet. diff --git a/docs/source/game_layer.rst b/docs/source/game_layer.rst index 9e254ac6..27905c85 100644 --- a/docs/source/game_layer.rst +++ b/docs/source/game_layer.rst @@ -17,15 +17,15 @@ Game layer The game layer is responsible for managing agents and getting them to interface with the simulator correctly. It consists of several components: -PrimaiteSession +PrimAITE Session ^^^^^^^^^^^^^^^ -PrimaiteSession is the main entry point into Primaite and it allows the simultaneous coordination of a simulation and agents that interact with it. It also sends messages to ARCD GATE to perform reinforcement learning. PrimaiteSession keeps track of multiple agents of different types. +``PrimaiteSession`` is the main entry point into Primaite and it allows the simultaneous coordination of a simulation and agents that interact with it. It also sends messages to ARCD GATE to perform reinforcement learning. ``PrimaiteSession`` keeps track of multiple agents of different types. Agents ^^^^^^ -All agents inherit from the AbstractAgent class, which mandates that they have an ObservationManager, ActionManager, and RewardManager. The agent behaviour depends on the type of agent, but there are two main types: +All agents inherit from the :py:class:`primaite.game.agent.interface.AbstractAgent` class, which mandates that they have an ObservationManager, ActionManager, and RewardManager. The agent behaviour depends on the type of agent, but there are two main types: * RL agents action during each step is decided by an RL algorithm which lives inside of ARCD GATE. The agent within PrimAITE just acts to format and forward actions decided by an RL policy. * Deterministic agents perform all of their decision making within the PrimAITE game layer. They typically have a scripted policy which always performs the same action or a rule-based policy which performs actions based on the current state of the simulation. They can have a stochastic element, and their seed will be settable. @@ -35,14 +35,14 @@ All agents inherit from the AbstractAgent class, which mandates that they have a Observations ^^^^^^^^^^^^^^^^^^ -An agent's observations are managed by the ObservationManager class. It generates observations based on the current simulation state dictionary. It also provides the observation space during initial setup. The data is formatted so it's compatible with Gymnasium.spaces. Observation spaces are composed of one or more components which are defined by the AbstractObservation base class. +An agent's observations are managed by the ``ObservationManager`` class. It generates observations based on the current simulation state dictionary. It also provides the observation space during initial setup. The data is formatted so it's compatible with ``Gymnasium.spaces``. Observation spaces are composed of one or more components which are defined by the ``AbstractObservation`` base class. Actions ^^^^^^^ -An agent's actions are managed by the ActionManager. It converts actions selected by agents (which are typically integers chosen from a ``gymnasium.spaces.Discrete`` space) into simulation-friendly requests. It also provides the action space during initial setup. Action spaces are composed of one or more components which are defined by the AbstractAction base class. +An agent's actions are managed by the ``ActionManager``. It converts actions selected by agents (which are typically integers chosen from a ``gymnasium.spaces.Discrete`` space) into simulation-friendly requests. It also provides the action space during initial setup. Action spaces are composed of one or more components which are defined by the ``AbstractAction`` base class. Rewards ^^^^^^^ -An agent's reward function is managed by the RewardManager. It calculates rewards based on the simulation state (in a way similar to observations). Rewards can be defined as a weighted sum of small reward components. For example, an agents reward can be based on the uptime of a database service plus the loss rate of packets between clients and a web server. The reward components are defined by the AbstractReward base class. +An agent's reward function is managed by the ``RewardManager``. It calculates rewards based on the simulation state (in a way similar to observations). Rewards can be defined as a weighted sum of small reward components. For example, an agents reward can be based on the uptime of a database service plus the loss rate of packets between clients and a web server. The reward components are defined by the AbstractReward base class. diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 5d0dbedf..30cda446 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -74,7 +74,6 @@ class FileSystemItemABC(SimComponent): name: str "The name of the FileSystemItemABC." - health_status: FileSystemItemHealthStatus = FileSystemItemHealthStatus.GOOD health_status: FileSystemItemHealthStatus = FileSystemItemHealthStatus.GOOD "Actual status of the current FileSystemItem" From 78a8d2be3e531cd4f6d4872484a64048c9c16882 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 25 Oct 2023 17:57:19 +0100 Subject: [PATCH 256/980] Fix File observation test --- src/primaite/simulator/file_system/file_system.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 30cda446..e4413313 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -92,8 +92,8 @@ class FileSystemItemABC(SimComponent): """ state = super().describe_state() state["name"] = self.name - state["status"] = self.health_status.value - state["visible_status"] = self.visible_health_status.value + state["health_status"] = self.health_status.value + state["visible_health_status"] = self.visible_health_status.value state["previous_hash"] = self.previous_hash return state From 38b71c0c8eef4aa5aefe122a137d6e5eeac5efcb Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 25 Oct 2023 18:06:33 +0100 Subject: [PATCH 257/980] Update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c29c325a..3af5c14c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,12 @@ SessionManager. - FTP Services: `FTPClient` and `FTPServer` - HTTP Services: `WebBrowser` to simulate a web client and `WebServer` +### Removed +- Removed legacy simulation modules: `acl`, `common`, `environment`, `links`, `nodes`, `pol` +- Removed legacy training modules, they are replaced by the new ARCD GATE dependency +- Removed tests for legacy code + + ## [2.0.0] - 2023-07-26 ### Added From 02901a7c99e2bc5bfe7e9bf281c51a8aee746d84 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 25 Oct 2023 19:07:45 +0100 Subject: [PATCH 258/980] Apply suggestions from code review. --- docs/index.rst | 2 +- docs/source/config(v2).rst | 2 ++ src/primaite/game/agent/actions.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 22e880fc..ed66797d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -98,7 +98,7 @@ Head over to the :ref:`getting-started` page to install and setup PrimAITE! source/getting_started source/about source/config - source/config(v3) + source/config(v2) source/simulation source/game_layer source/primaite_session diff --git a/docs/source/config(v2).rst b/docs/source/config(v2).rst index daf7f90b..35233cf5 100644 --- a/docs/source/config(v2).rst +++ b/docs/source/config(v2).rst @@ -7,6 +7,8 @@ The Config Files Explained ========================== +Note: This file describes the config files used in legacy PrimAITE v2.0. This file will be removed soon. + PrimAITE uses two configuration files for its operation: * **The Training Config** diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 0a380487..b06013cd 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -697,7 +697,7 @@ class ActionManager: def get_action(self, action: int) -> Tuple[str, Dict]: """Produce action in CAOS format.""" """the agent chooses an action (as an integer), this is converted into an action in CAOS format""" - """The caos format is basically a action identifier, followed by parameters stored in a dictionary""" + """The CAOS format is basically a action identifier, followed by parameters stored in a dictionary""" act_identifier, act_options = self.action_map[action] return act_identifier, act_options From afa7916db08f03407d40cf372bcd729fec69148a Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 25 Oct 2023 23:32:52 +0100 Subject: [PATCH 259/980] Updates to documentation --- docs/index.rst | 28 +- docs/source/about.rst | 704 ++++++++++++--------------- docs/source/action_system.rst | 88 ---- docs/source/config(v2).rst | 491 ------------------- docs/source/custom_agent.rst | 130 +---- docs/source/getting_started.rst | 60 ++- docs/source/migration_1.2_-_2.0.rst | 57 --- docs/source/primaite_session.rst | 359 +++++++------- docs/source/request_system.rst | 90 ++++ docs/source/simulation.rst | 6 +- docs/source/simulation_structure.rst | 6 +- docs/source/state_system.rst | 31 ++ 12 files changed, 673 insertions(+), 1377 deletions(-) delete mode 100644 docs/source/action_system.rst delete mode 100644 docs/source/config(v2).rst delete mode 100644 docs/source/migration_1.2_-_2.0.rst create mode 100644 docs/source/request_system.rst create mode 100644 docs/source/state_system.rst diff --git a/docs/index.rst b/docs/index.rst index ed66797d..fa877064 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -92,26 +92,34 @@ Head over to the :ref:`getting-started` page to install and setup PrimAITE! .. toctree:: :maxdepth: 8 - :caption: Contents: + :caption: About PrimAITE: + :hidden: + + source/about + source/dependencies + source/glossary + +.. toctree:: + :caption: Usage: :hidden: source/getting_started - source/about - source/config - source/config(v2) + source/primaite_session source/simulation source/game_layer - source/primaite_session source/custom_agent + source/config + +.. toctree:: + :caption: Developer information: + :hidden: + + source/state_system + source/request_system PrimAITE API PrimAITE Tests - source/dependencies - source/glossary - source/migration_1.2_-_2.0 -.. TODO: Add project links once public repo has been created - .. toctree:: :caption: Project Links: :hidden: diff --git a/docs/source/about.rst b/docs/source/about.rst index d12a59de..993dec0c 100644 --- a/docs/source/about.rst +++ b/docs/source/about.rst @@ -7,408 +7,312 @@ About PrimAITE ============== +PrimAITE is a simulation environment for training agents to protect a computer network from cyber attacks. + Features ******** PrimAITE provides the following features: -* A flexible network / system laydown based on the Python networkx framework -* Nodes and links (edges) host Python classes in order to present attributes and methods (and hence, a more representative model of a platform / system) -* A 'green agent' Information Exchange Requirement (IER) function allows the representation of traffic (protocols and loading) on any / all links. Application of IERs is based on the status of node operating systems and services -* A 'green agent' node Pattern-of-Life (PoL) function allows the representation of core behaviours on nodes (e.g. changing the Hardware state, Software State, Service state, or File System state) -* An Access Control List (ACL) function, mimicking the behaviour of a network firewall, is applied across the model, following standard ACL rule format (e.g. DENY/ALLOW, source IP, destination IP, protocol and port). Application of IERs adheres to any ACL restrictions -* Presents an OpenAI Gym interface to the environment, allowing integration with any OpenAI Gym compliant defensive agents -* Red agent activity based on 'red' IERs and 'red' PoL -* Defined reward function for use with RL agents (based on nodes status, and green / red IER success) -* Fully configurable (network / system laydown, IERs, node PoL, ACL, episode step period, episode max steps) and repeatable to suit the training requirements of agents. Therefore, not bound to a representation of any particular platform, system or technology -* Full capture of discrete metrics relating to agent training (full system state, agent actions taken, average reward) -* Networkx provides laydown visualisation capability - -Architecture - Nodes and Links -****************************** - -**Nodes** - -An inheritance model has been adopted in order to model nodes. All nodes have the following base attributes (Class: Node): - -* ID -* Name -* Type (e.g. computer, switch, RTU - enumeration) -* Priority (P1, P2, P3, P4 or P5 - enumeration) -* Hardware State (ON, OFF, RESETTING, SHUTTING_DOWN, BOOTING - enumeration) - -Active Nodes also have the following attributes (Class: Active Node): - -* IP Address -* Software State (GOOD, PATCHING, COMPROMISED - enumeration) -* File System State (GOOD, CORRUPT, DESTROYED, REPAIRING, RESTORING - enumeration) - -Service Nodes also have the following attributes (Class: Service Node): - -* List of Services (where service is composed of service name and port). There is no theoretical limit on the number of services that can be modelled. Services and protocols are currently intrinsically linked (i.e. a service is an application on a node transmitting traffic of this protocol type) -* Service state (GOOD, PATCHING, COMPROMISED, OVERWHELMED - enumeration) - -Passive Nodes are currently not used (but may be employed for non IP-based components such as machinery actuators in future releases). - -**Links** - -Links are modelled both as network edges (networkx) and as Python classes, in order to extend their functionality. Links include the following attributes: - -* ID -* Name -* Bandwidth (bits/s) -* Source node ID -* Destination node ID -* Protocol list (containing the loading of protocols currently running on the link) - -When the simulation runs, IERs are applied to the links in order to model traffic loading, individually assigned to each protocol. This allows green (background) and red agent behaviour to be modelled, and defensive agents to identify suspicious traffic patterns at a protocol / traffic loading level of fidelity. - -Information Exchange Requirements (IERs) -**************************************** - -PrimAITE adopts the concept of Information Exchange Requirements (IERs) to model both green agent (background) and red agent (adversary) behaviour. IERs are used to initiate modelling of traffic loading on the network, and have the following attributes: - -* ID -* Start step (i.e. which step in the training episode should the IER start) -* End step (i.e. which step in the training episode should the IER end) -* Source node ID -* Destination node ID -* Load (bits/s) -* Protocol -* Port -* Running status (i.e. on / off) - -The application of green agent IERs between a source and destination follows a number of rules. Specifically: - -1. Does the current simulation time step fall between IER start and end step -2. Is the source node operational (both physically and at an O/S level), and is the service (protocol / port) associated with the IER (a) present on this node, and (b) in an operational state (i.e. not PATCHING) -3. Is the destination node operational (both physically and at an O/S level), and is the service (protocol / port) associated with the IER (a) present on this node, and (b) in an operational state (i.e. not PATCHING) -4. Are there any Access Control List rules in place that prevent the application of this IER -5. Are all switches in the (OSPF) path between source and destination operational (both physically and at an O/S level) - -For red agent IERs, the application of IERs between a source and destination follows a number of subtly different rules. Specifically: - -1. Does the current simulation time step fall between IER start and end step -2. Is the source node operational, and is the service (protocol / port) associated with the IER (a) present on that node and (b) already in a compromised state -3. Is the destination node operational, and is the service (protocol / port) associated with the IER present on that node -4. Are there any Access Control List rules in place that prevent the application of this IER -5. Are all switches in the (OSPF) path between source and destination operational (both physically and at an O/S level) - -Assuming the rules pass, the IER is applied to all relevant links (based on use of OSPF) between source and destination. - -Node Pattern-of-Life -******************** - -Every node can be impacted (i.e. have a status change applied to it) by either green agent pattern-of-life or red agent pattern-of-life. This is distinct from IERs, and allows for attacks (and defence) to be modelled purely within the confines of a node. - -The status changes that can be made to a node are as follows: - -* All Nodes: - - * Hardware State: - - * ON - * OFF - * RESETTING - when a status of resetting is entered, the node will automatically exit this state after a number of steps (as defined by the nodeResetDuration configuration item) after which it returns to an ON state - * BOOTING - * SHUTTING_DOWN - -* Active Nodes and Service Nodes: - - * Software State: - - * GOOD - * PATCHING - when a status of patching is entered, the node will automatically exit this state after a number of steps (as defined by the osPatchingDuration configuration item) after which it returns to a GOOD state - * COMPROMISED - - * File System State: - - * GOOD - * CORRUPT (can be resolved by repair or restore) - * DESTROYED (can be resolved by restore only) - * REPAIRING - when a status of repairing is entered, the node will automatically exit this state after a number of steps (as defined by the fileSystemRepairingLimit configuration item) after which it returns to a GOOD state - * RESTORING - when a status of repairing is entered, the node will automatically exit this state after a number of steps (as defined by the fileSystemRestoringLimit configuration item) after which it returns to a GOOD state - -* Service Nodes only: - - * Service State (for any associated service): - - * GOOD - * PATCHING - when a status of patching is entered, the service will automatically exit this state after a number of steps (as defined by the servicePatchingDuration configuration item) after which it returns to a GOOD state - * COMPROMISED - * OVERWHELMED - -Red agent pattern-of-life has an additional feature not found in the green pattern-of-life. This is the ability to influence the state of the attributes of a node via a number of different conditions: - - * DIRECT: - - The pattern-of-life described by the configuration file item will be applied regardless of any other conditions in the network. This is particularly useful for direct red agent entry into the network. - - * IER: - - The pattern-of-life described by the configuration file item will be applied to the service on the node, only if there is an IER of the same protocol / service type incoming at the specified timestep. - - * SERVICE: - - The pattern-of-life described by the configuration file item will be applied to the node based on the state of a service. The service can either be on the same node, or a different node within the network. - -Access Control List modelling -***************************** - -An Access Control List (ACL) is modelled to provide the means to manage traffic flows in the system. This will allow defensive agents the means to turn on / off rules, or potentially create new rules, to counter an attack. - -The ACL follows a standard network firewall format. For example: - -.. list-table:: ACL example - :widths: 25 25 25 25 25 - :header-rows: 1 - - * - Permission - - Source IP - - Dest IP - - Protocol - - Port - * - DENY - - 192.168.1.2 - - 192.168.1.3 - - HTTPS - - 443 - * - ALLOW - - 192.168.1.4 - - ANY - - SMTP - - 25 - * - DENY - - ANY - - 192.168.1.5 - - ANY - - ANY - -All ACL rules are considered when applying an IER. Logic follows the order of rules, so a DENY or ALLOW for the same parameters will override an earlier entry. - -Observation Spaces -****************** -The observation space provides the blue agent with information about the current status of nodes and links. - -PrimAITE builds on top of Gym Spaces to create an observation space that is easily configurable for users. It's made up of components which are managed by the :py:class:`primaite.environment.observations.ObservationsHandler`. Each training scenario can define its own observation space, and the user can choose which information to inlude, and how it should be formatted. - -NodeLinkTable component ------------------------ -For example, the :py:class:`primaite.environment.observations.NodeLinkTable` component represents the status of nodes and links as a ``gym.spaces.Box`` with an example format shown below: - -An example observation space is provided below: - -.. list-table:: Observation Space example - :widths: 25 25 25 25 25 25 25 - :header-rows: 1 - - * - - - ID - - Hardware State - - Software State - - File System State - - Service / Protocol A - - Service / Protocol B - * - Node A - - 1 - - 1 - - 1 - - 1 - - 1 - - 1 - * - Node B - - 2 - - 1 - - 3 - - 1 - - 1 - - 1 - * - Node C - - 3 - - 2 - - 1 - - 1 - - 3 - - 2 - * - Link 1 - - 5 - - 0 - - 0 - - 0 - - 0 - - 10000 - * - Link 2 - - 6 - - 0 - - 0 - - 0 - - 0 - - 10000 - * - Link 3 - - 7 - - 0 - - 0 - - 0 - - 5000 - - 0 - -For the nodes, the following values are represented: - -.. code-block:: - - [ - ID - Hardware State (1=ON, 2=OFF, 3=RESETTING, 4=SHUTTING_DOWN, 5=BOOTING) - Operating System State (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) - File System State (0=none, 1=GOOD, 2=CORRUPT, 3=DESTROYED, 4=REPAIRING, 5=RESTORING) - Service1/Protocol1 state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) - Service2/Protocol2 state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) - ] - -(Note that each service available in the network is provided as a column, although not all nodes may utilise all services) - -For the links, the following statuses are represented: - -.. code-block:: - - [ - ID - Hardware State (0=not applicable) - Operating System State (0=not applicable) - File System State (0=not applicable) - Service1/Protocol1 state (Traffic load from this protocol on this link) - Service2/Protocol2 state (Traffic load from this protocol on this link) - ] - -NodeStatus component ----------------------- -This is a MultiDiscrete observation space that can be though of as a one-dimensional vector of discrete states. -The example above would have the following structure: - -.. code-block:: - - [ - node1_info - node2_info - node3_info - ] - -Each ``node_info`` contains the following: - -.. code-block:: - - [ - hardware_state (0=none, 1=ON, 2=OFF, 3=RESETTING, 4=SHUTTING_DOWN, 5=BOOTING) - software_state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) - file_system_state (0=none, 1=GOOD, 2=CORRUPT, 3=DESTROYED, 4=REPAIRING, 5=RESTORING) - service1_state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) - service2_state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) - ] - -In a network with three nodes and two services, the full observation space would have 15 elements. It can be written with ``gym`` notation to indicate the number of discrete options for each of the elements of the observation space. For example: - -.. code-block:: - - gym.spaces.MultiDiscrete([4,5,6,4,4,4,5,6,4,4,4,5,6,4,4]) - -.. note:: - NodeStatus observation component provides information only about nodes. Links are not considered. - -LinkTrafficLevels ------------------ -This component is a MultiDiscrete space showing the traffic flow levels on the links in the network, after applying a threshold to convert it from a continuous to a discrete value. -There are two configurable parameters: -* ``quantisation_levels`` determines how many discrete bins to use for converting the continuous traffic value to discrete (default is 5). -* ``combine_service_traffic`` determines whether to separately output traffic use for each network protocol or whether to combine them into an overall value for the link. (default is ``True``) - -For example, with default parameters and a network with three links, the structure of this component would be: - -.. code-block:: - - [ - link1_status - link2_status - link3_status - ] - -Each ``link_status`` is a number from 0-4 representing the network load in relation to bandwidth. - -.. code-block:: - - 0 = No traffic (0%) - 1 = low traffic (1%-33%) - 2 = medium traffic (33%-66%) - 3 = high traffic (66%-99%) - 4 = max traffic/ overwhelmed (100%) - -Using ``gym`` notation, the shape of the obs space is: ``gym.spaces.MultiDiscrete([5,5,5])``. - - -Action Spaces -************** - -The action space available to the blue agent comes in two types: - - 1. Node-based - 2. Access Control List - 3. Any (Agent can take both node-based and ACL-based actions) - -The choice of action space used during a training session is determined in the config_[name].yaml file. - -**Node-Based** - -The agent is able to influence the status of nodes by switching them off, resetting, or patching operating systems and services. In this instance, the action space is an OpenAI Gym spaces.Discrete type, as follows: - - * Dictionary item {... ,1: [x1, x2, x3,x4] ...} - The placeholders inside the list under the key '1' mean the following: - - * [0, num nodes] - Node ID (0 = nothing, node ID) - * [0, 4] - What property it's acting on (0 = nothing, 1 = state, 2 = SoftwareState, 3 = service state, 4 = file system state) - * [0, 3] - Action on property (0 = nothing, 1 = on / scan, 2 = off / repair, 3 = reset / patch / restore) - * [0, num services] - Resolves to service ID (0 = nothing, resolves to service) - -**Access Control List** - -The blue agent is able to influence the configuration of the Access Control List rule set (which implements a system-wide firewall). In this instance, the action space is an OpenAI spaces.Discrete type, as follows: - - * Dictionary item {... ,1: [x1, x2, x3, x4, x5, x6] ...} - The placeholders inside the list under the key '1' mean the following: - - * [0, 2] - Action (0 = do nothing, 1 = create rule, 2 = delete rule) - * [0, 1] - Permission (0 = DENY, 1 = ALLOW) - * [0, num nodes] - Source IP (0 = any, then 1 -> x resolving to IP addresses) - * [0, num nodes] - Dest IP (0 = any, then 1 -> x resolving to IP addresses) - * [0, num services] - Protocol (0 = any, then 1 -> x resolving to protocol) - * [0, num ports] - Port (0 = any, then 1 -> x resolving to port) - -**ANY** -The agent is able to carry out both **Node-Based** and **Access Control List** operations. - -This means the dictionary will contain key-value pairs in the format of BOTH Node-Based and Access Control List as seen above. - -Rewards -******* - -A reward value is presented back to the blue agent on the conclusion of every step. The reward value is calculated via two methods which combine to give the total value: - - 1. Node and service status - 2. IER status - -**Node and service status** - -On every step, the status of each node is compared against both a reference environment (simulating the situation if the red and blue agents had not impacted the environment) -and the before and after state of the environment. If the comparison against the reference environment shows no difference, then the score provided is "AllOK". If there is a -difference with respect to the reference environment, the before and after states are compared, and a score determined. See :ref:`config` for details of reward values. - -**IER status** - -On every step, the full IER set is examined to determine whether green and red agent IERs are being permitted to run. Any red agent IERs running incur a penalty; any green agent -IERs not permitted to run also incur a penalty. See :ref:`config` for details of reward values. - -Future Enhancements -******************* - -The PrimAITE project has an ambition to include the following enhancements in future releases: - -* Integration with a suitable standardised framework to allow multi-agent integration -* Integration with external threat emulation tools, either using off-line data, or integrating at runtime +* A flexible system for defining network layouts and host configurations +* Highly configurable network hosts, including definition of software, file system, and network interfaces, +* Realistic network traffic simulation, including address and sending packets via internet protocols like TCP, UDP, ICMP, etc. +* Routers with traffic routing and firewall capabilities +* Interfaces with ARCD GATE to allow training of agents +* Simulation of customisable deterministic agents +* Support for multiple agents, each having their own customisable observation space, action space, and reward function definition. + + +Structure +********* + +PrimAITE consists of a simulator and a 'game' layer that allows agents to interact with the simulator. The simulator is built in a modular way where each component such as network hosts, links, networking devices, softwares, etc. are implemented as instances of a base class, meaning they all support the same interface. This allows for standardised configuration using either the Python API or YAML files. +The game layer is built on top of the simulator and it consumes the simulation action/state interface to allow agents to interact with the simulator. The game layer is also responsible for defining the reward function and observation space for the agents. + + +.. + Architecture - Nodes and Links + ****************************** + **Nodes** + An inheritance model has been adopted in order to model nodes. All nodes have the following base attributes (Class: Node): + * ID + * Name + * Type (e.g. computer, switch, RTU - enumeration) + * Priority (P1, P2, P3, P4 or P5 - enumeration) + * Hardware State (ON, OFF, RESETTING, SHUTTING_DOWN, BOOTING - enumeration) + Active Nodes also have the following attributes (Class: Active Node): + * IP Address + * Software State (GOOD, PATCHING, COMPROMISED - enumeration) + * File System State (GOOD, CORRUPT, DESTROYED, REPAIRING, RESTORING - enumeration) + Service Nodes also have the following attributes (Class: Service Node): + * List of Services (where service is composed of service name and port). There is no theoretical limit on the number of services that can be modelled. Services and protocols are currently intrinsically linked (i.e. a service is an application on a node transmitting traffic of this protocol type) + * Service state (GOOD, PATCHING, COMPROMISED, OVERWHELMED - enumeration) + Passive Nodes are currently not used (but may be employed for non IP-based components such as machinery actuators in future releases). + **Links** + Links are modelled both as network edges (networkx) and as Python classes, in order to extend their functionality. Links include the following attributes: + * ID + * Name + * Bandwidth (bits/s) + * Source node ID + * Destination node ID + * Protocol list (containing the loading of protocols currently running on the link) + When the simulation runs, IERs are applied to the links in order to model traffic loading, individually assigned to each protocol. This allows green (background) and red agent behaviour to be modelled, and defensive agents to identify suspicious traffic patterns at a protocol / traffic loading level of fidelity. + Information Exchange Requirements (IERs) + **************************************** + PrimAITE adopts the concept of Information Exchange Requirements (IERs) to model both green agent (background) and red agent (adversary) behaviour. IERs are used to initiate modelling of traffic loading on the network, and have the following attributes: + * ID + * Start step (i.e. which step in the training episode should the IER start) + * End step (i.e. which step in the training episode should the IER end) + * Source node ID + * Destination node ID + * Load (bits/s) + * Protocol + * Port + * Running status (i.e. on / off) + The application of green agent IERs between a source and destination follows a number of rules. Specifically: + 1. Does the current simulation time step fall between IER start and end step + 2. Is the source node operational (both physically and at an O/S level), and is the service (protocol / port) associated with the IER (a) present on this node, and (b) in an operational state (i.e. not PATCHING) + 3. Is the destination node operational (both physically and at an O/S level), and is the service (protocol / port) associated with the IER (a) present on this node, and (b) in an operational state (i.e. not PATCHING) + 4. Are there any Access Control List rules in place that prevent the application of this IER + 5. Are all switches in the (OSPF) path between source and destination operational (both physically and at an O/S level) + For red agent IERs, the application of IERs between a source and destination follows a number of subtly different rules. Specifically: + 1. Does the current simulation time step fall between IER start and end step + 2. Is the source node operational, and is the service (protocol / port) associated with the IER (a) present on that node and (b) already in a compromised state + 3. Is the destination node operational, and is the service (protocol / port) associated with the IER present on that node + 4. Are there any Access Control List rules in place that prevent the application of this IER + 5. Are all switches in the (OSPF) path between source and destination operational (both physically and at an O/S level) + Assuming the rules pass, the IER is applied to all relevant links (based on use of OSPF) between source and destination. + Node Pattern-of-Life + ******************** + Every node can be impacted (i.e. have a status change applied to it) by either green agent pattern-of-life or red agent pattern-of-life. This is distinct from IERs, and allows for attacks (and defence) to be modelled purely within the confines of a node. + The status changes that can be made to a node are as follows: + * All Nodes: + * Hardware State: + * ON + * OFF + * RESETTING - when a status of resetting is entered, the node will automatically exit this state after a number of steps (as defined by the nodeResetDuration configuration item) after which it returns to an ON state + * BOOTING + * SHUTTING_DOWN + * Active Nodes and Service Nodes: + * Software State: + * GOOD + * PATCHING - when a status of patching is entered, the node will automatically exit this state after a number of steps (as defined by the osPatchingDuration configuration item) after which it returns to a GOOD state + * COMPROMISED + * File System State: + * GOOD + * CORRUPT (can be resolved by repair or restore) + * DESTROYED (can be resolved by restore only) + * REPAIRING - when a status of repairing is entered, the node will automatically exit this state after a number of steps (as defined by the fileSystemRepairingLimit configuration item) after which it returns to a GOOD state + * RESTORING - when a status of repairing is entered, the node will automatically exit this state after a number of steps (as defined by the fileSystemRestoringLimit configuration item) after which it returns to a GOOD state + * Service Nodes only: + * Service State (for any associated service): + * GOOD + * PATCHING - when a status of patching is entered, the service will automatically exit this state after a number of steps (as defined by the servicePatchingDuration configuration item) after which it returns to a GOOD state + * COMPROMISED + * OVERWHELMED + Red agent pattern-of-life has an additional feature not found in the green pattern-of-life. This is the ability to influence the state of the attributes of a node via a number of different conditions: + * DIRECT: + The pattern-of-life described by the configuration file item will be applied regardless of any other conditions in the network. This is particularly useful for direct red agent entry into the network. + * IER: + The pattern-of-life described by the configuration file item will be applied to the service on the node, only if there is an IER of the same protocol / service type incoming at the specified timestep. + * SERVICE: + The pattern-of-life described by the configuration file item will be applied to the node based on the state of a service. The service can either be on the same node, or a different node within the network. + Access Control List modelling + ***************************** + An Access Control List (ACL) is modelled to provide the means to manage traffic flows in the system. This will allow defensive agents the means to turn on / off rules, or potentially create new rules, to counter an attack. + The ACL follows a standard network firewall format. For example: + .. list-table:: ACL example + :widths: 25 25 25 25 25 + :header-rows: 1 + * - Permission + - Source IP + - Dest IP + - Protocol + - Port + * - DENY + - 192.168.1.2 + - 192.168.1.3 + - HTTPS + - 443 + * - ALLOW + - 192.168.1.4 + - ANY + - SMTP + - 25 + * - DENY + - ANY + - 192.168.1.5 + - ANY + - ANY + All ACL rules are considered when applying an IER. Logic follows the order of rules, so a DENY or ALLOW for the same parameters will override an earlier entry. + Observation Spaces + ****************** + The observation space provides the blue agent with information about the current status of nodes and links. + PrimAITE builds on top of Gym Spaces to create an observation space that is easily configurable for users. It's made up of components which are managed by the :py:class:`primaite.environment.observations.ObservationsHandler`. Each training scenario can define its own observation space, and the user can choose which information to inlude, and how it should be formatted. + NodeLinkTable component + ----------------------- + For example, the :py:class:`primaite.environment.observations.NodeLinkTable` component represents the status of nodes and links as a ``gym.spaces.Box`` with an example format shown below: + An example observation space is provided below: + .. list-table:: Observation Space example + :widths: 25 25 25 25 25 25 25 + :header-rows: 1 + * - + - ID + - Hardware State + - Software State + - File System State + - Service / Protocol A + - Service / Protocol B + * - Node A + - 1 + - 1 + - 1 + - 1 + - 1 + - 1 + * - Node B + - 2 + - 1 + - 3 + - 1 + - 1 + - 1 + * - Node C + - 3 + - 2 + - 1 + - 1 + - 3 + - 2 + * - Link 1 + - 5 + - 0 + - 0 + - 0 + - 0 + - 10000 + * - Link 2 + - 6 + - 0 + - 0 + - 0 + - 0 + - 10000 + * - Link 3 + - 7 + - 0 + - 0 + - 0 + - 5000 + - 0 + For the nodes, the following values are represented: + .. code-block:: + [ + ID + Hardware State (1=ON, 2=OFF, 3=RESETTING, 4=SHUTTING_DOWN, 5=BOOTING) + Operating System State (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) + File System State (0=none, 1=GOOD, 2=CORRUPT, 3=DESTROYED, 4=REPAIRING, 5=RESTORING) + Service1/Protocol1 state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) + Service2/Protocol2 state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) + ] + (Note that each service available in the network is provided as a column, although not all nodes may utilise all services) + For the links, the following statuses are represented: + .. code-block:: + [ + ID + Hardware State (0=not applicable) + Operating System State (0=not applicable) + File System State (0=not applicable) + Service1/Protocol1 state (Traffic load from this protocol on this link) + Service2/Protocol2 state (Traffic load from this protocol on this link) + ] + NodeStatus component + ---------------------- + This is a MultiDiscrete observation space that can be though of as a one-dimensional vector of discrete states. + The example above would have the following structure: + .. code-block:: + [ + node1_info + node2_info + node3_info + ] + Each ``node_info`` contains the following: + .. code-block:: + [ + hardware_state (0=none, 1=ON, 2=OFF, 3=RESETTING, 4=SHUTTING_DOWN, 5=BOOTING) + software_state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) + file_system_state (0=none, 1=GOOD, 2=CORRUPT, 3=DESTROYED, 4=REPAIRING, 5=RESTORING) + service1_state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) + service2_state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) + ] + In a network with three nodes and two services, the full observation space would have 15 elements. It can be written with ``gym`` notation to indicate the number of discrete options for each of the elements of the observation space. For example: + .. code-block:: + gym.spaces.MultiDiscrete([4,5,6,4,4,4,5,6,4,4,4,5,6,4,4]) + .. note:: + NodeStatus observation component provides information only about nodes. Links are not considered. + LinkTrafficLevels + ----------------- + This component is a MultiDiscrete space showing the traffic flow levels on the links in the network, after applying a threshold to convert it from a continuous to a discrete value. + There are two configurable parameters: + * ``quantisation_levels`` determines how many discrete bins to use for converting the continuous traffic value to discrete (default is 5). + * ``combine_service_traffic`` determines whether to separately output traffic use for each network protocol or whether to combine them into an overall value for the link. (default is ``True``) + For example, with default parameters and a network with three links, the structure of this component would be: + .. code-block:: + [ + link1_status + link2_status + link3_status + ] + Each ``link_status`` is a number from 0-4 representing the network load in relation to bandwidth. + .. code-block:: + 0 = No traffic (0%) + 1 = low traffic (1%-33%) + 2 = medium traffic (33%-66%) + 3 = high traffic (66%-99%) + 4 = max traffic/ overwhelmed (100%) + Using ``gym`` notation, the shape of the obs space is: ``gym.spaces.MultiDiscrete([5,5,5])``. + Action Spaces + ************** + The action space available to the blue agent comes in two types: + 1. Node-based + 2. Access Control List + 3. Any (Agent can take both node-based and ACL-based actions) + The choice of action space used during a training session is determined in the config_[name].yaml file. + **Node-Based** + The agent is able to influence the status of nodes by switching them off, resetting, or patching operating systems and services. In this instance, the action space is an OpenAI Gym spaces.Discrete type, as follows: + * Dictionary item {... ,1: [x1, x2, x3,x4] ...} + The placeholders inside the list under the key '1' mean the following: + * [0, num nodes] - Node ID (0 = nothing, node ID) + * [0, 4] - What property it's acting on (0 = nothing, 1 = state, 2 = SoftwareState, 3 = service state, 4 = file system state) + * [0, 3] - Action on property (0 = nothing, 1 = on / scan, 2 = off / repair, 3 = reset / patch / restore) + * [0, num services] - Resolves to service ID (0 = nothing, resolves to service) + **Access Control List** + The blue agent is able to influence the configuration of the Access Control List rule set (which implements a system-wide firewall). In this instance, the action space is an OpenAI spaces.Discrete type, as follows: + * Dictionary item {... ,1: [x1, x2, x3, x4, x5, x6] ...} + The placeholders inside the list under the key '1' mean the following: + * [0, 2] - Action (0 = do nothing, 1 = create rule, 2 = delete rule) + * [0, 1] - Permission (0 = DENY, 1 = ALLOW) + * [0, num nodes] - Source IP (0 = any, then 1 -> x resolving to IP addresses) + * [0, num nodes] - Dest IP (0 = any, then 1 -> x resolving to IP addresses) + * [0, num services] - Protocol (0 = any, then 1 -> x resolving to protocol) + * [0, num ports] - Port (0 = any, then 1 -> x resolving to port) + **ANY** + The agent is able to carry out both **Node-Based** and **Access Control List** operations. + This means the dictionary will contain key-value pairs in the format of BOTH Node-Based and Access Control List as seen above. + Rewards + ******* + A reward value is presented back to the blue agent on the conclusion of every step. The reward value is calculated via two methods which combine to give the total value: + 1. Node and service status + 2. IER status + **Node and service status** + On every step, the status of each node is compared against both a reference environment (simulating the situation if the red and blue agents had not impacted the environment) + and the before and after state of the environment. If the comparison against the reference environment shows no difference, then the score provided is "AllOK". If there is a + difference with respect to the reference environment, the before and after states are compared, and a score determined. See :ref:`config` for details of reward values. + **IER status** + On every step, the full IER set is examined to determine whether green and red agent IERs are being permitted to run. Any red agent IERs running incur a penalty; any green agent + IERs not permitted to run also incur a penalty. See :ref:`config` for details of reward values. + Future Enhancements + ******************* + The PrimAITE project has an ambition to include the following enhancements in future releases: + * Integration with a suitable standardised framework to allow multi-agent integration + * Integration with external threat emulation tools, either using off-line data, or integrating at runtime diff --git a/docs/source/action_system.rst b/docs/source/action_system.rst deleted file mode 100644 index 88baf232..00000000 --- a/docs/source/action_system.rst +++ /dev/null @@ -1,88 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -Actions System -============== - -``SimComponent``s in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``RequestManager`` and ``Action``. - -Just like other aspects of SimComponent, the actions are not managed centrally for the whole simulation, but instead they are dynamically created and updated based on the nodes, links, and other components that currently exist. This was achieved with the following design decisions: - -- API - An 'action' contains two elements: - - 1. ``request`` - selects which action you want to take on this ``SimComponent``. This is formatted as a list of strings such as `['network', 'node', '', 'service', '', 'restart']`. - 2. ``context`` - optional extra information that can be used to decide how to process the action. This is formatted as a dictionary. For example, if the action requires authentication, the context can include information about the user that initiated the request to decide if their permissions are sufficient. - -- request - The request is a list of strings which help specify who should handle the request. The strings in the request list help RequestManagers traverse the 'ownership tree' of SimComponent. The example given above would be handled in the following way: - - 1. ``Simulation`` receives `['network', 'node', '', 'service', '', 'restart']`. - The first element of the action is ``network``, therefore it passes the action down to its network. - 2. ``Network`` receives `['node', '', 'service', '', 'restart']`. - The first element of the action is ``node``, therefore the network looks at the node uuid and passes the action down to the node with that uuid. - 3. ``Node`` receives `['service', '', 'restart']`. - The first element of the action is ``service``, therefore the node looks at the service uuid and passes the rest of the action to the service with that uuid. - 4. ``Service`` receives ``['restart']``. - Since ``restart`` is a defined action in the service's own RequestManager, the service performs a restart. - -Technical Detail -================ - -This system was achieved by implementing two classes, :py:class:`primaite.simulator.core.Action`, and :py:class:`primaite.simulator.core.RequestManager`. - -Action ------- - -The ``Action`` object stores a reference to a method that performs the action, for example a node could have an action that stores a reference to ``self.turn_on()``. Technically, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using ``lambda`` functions within a component's ``self._init_request_manager()`` method. Optionally, the ``Action`` object can also hold a validator that will permit/deny the action depending on context. - -RequestManager -------------- - -The ``RequestManager`` object stores a mapping between strings and actions. It is responsible for processing the ``request`` and passing it down the ownership tree. Technically, the ``RequestManager`` is itself a callable that accepts `request, context` tuple, and so it can be chained with other action managers. - -A simple example without chaining can be seen in the :py:class:`primaite.simulator.file_system.file_system.File` class. - -.. code-block:: python - - class File(FileSystemItemABC): - ... - def _init_request_manager(self): - ... - request_manager.add_request("scan", Action(func=lambda request, context: self.scan())) - request_manager.add_request("repair", Action(func=lambda request, context: self.repair())) - request_manager.add_request("restore", Action(func=lambda request, context: self.restore())) - -*ellipses (``...``) used to omit code impertinent to this explanation* - -Chaining RequestManagers ------------------------ - -Since the method for performing an action needs to accept `request, context` as parameters, and RequestManager itself is a callable that accepts `request, context` as parameters, it possible to use RequestManager as an action. In fact, that is how PrimAITE deals with traversing the ownership tree. Each time an RequestManager accepts a request, it pops the first elements and uses it to decide to which Action it should send the remaining request. However, the Action could have another RequestManager as it's function, therefore the request will be routed again. Each time the request is passed to a new action manager, the first element is popped. - -An example of how this works is in the :py:class:`primaite.simulator.network.hardware.base.Node` class. - -.. code-block:: python - - class Node(SimComponent): - ... - def _init_request_manager(self): - ... - # a regular action which is processed by the Node itself - request_manager.add_request("turn_on", Action(func=lambda request, context: self.turn_on())) - - # if the Node receives a request where the first word is 'service', it will use a dummy manager - # called self._service_request_manager to pass on the reqeust to the relevant service. This dummy - # manager is simply here to map the service UUID that that service's own action manager. This is - # done because the next string after "service" is always the uuid of that service, so we need an - # RequestManager to pop that string before sending it onto the relevant service's RequestManager. - self._service_request_manager = RequestManager() - request_manager.add_request("service", Action(func=self._service_request_manager)) - ... - - def install_service(self, service): - self.services[service.uuid] = service - ... - # Here, the service UUID is registered to allow passing actions between the node and the service. - self._service_request_manager.add_request(service.uuid, Action(func=service._request_manager)) diff --git a/docs/source/config(v2).rst b/docs/source/config(v2).rst deleted file mode 100644 index 35233cf5..00000000 --- a/docs/source/config(v2).rst +++ /dev/null @@ -1,491 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -.. _config: - -The Config Files Explained -========================== - -Note: This file describes the config files used in legacy PrimAITE v2.0. This file will be removed soon. - -PrimAITE uses two configuration files for its operation: - -* **The Training Config** - - Used to define the top-level settings of the PrimAITE environment, the reward values, and the session that is to be run. - -* **The Lay Down Config** - - Used to define the low-level settings of a session, including the network laydown, green / red agent information exchange requirements (IERSs) and Access Control Rules. - -Training Config: -******************* - -The Training Config file consists of the following attributes: - -**Generic Config Values** - - -* **agent_framework** [enum] - - This identifies the agent framework to be used to instantiate the agent algorithm. Select from one of the following: - - * NONE - Where a user developed agent is to be used - * SB3 - Stable Baselines3 - * RLLIB - Ray RLlib. - -* **agent_identifier** - - This identifies the agent to use for the session. Select from one of the following: - - * A2C - Advantage Actor Critic - * PPO - Proximal Policy Optimization - * HARDCODED - A custom built deterministic agent - * RANDOM - A Stochastic random agent - - -* **random_red_agent** [bool] - - Determines if the session should be run with a random red agent - -* **action_type** [enum] - - Determines whether a NODE, ACL, or ANY (combined NODE & ACL) action space format is adopted for the session - - -* **OBSERVATION_SPACE** [dict] - - Allows for user to configure observation space by combining one or more observation components. List of available - components is in :py:mod:`primaite.environment.observations`. - - The observation space config item should have a ``components`` key which is a list of components. Each component - config must have a ``name`` key, and can optionally have an ``options`` key. The ``options`` are passed to the - component while it is being initialised. - - This example illustrates the correct format for the observation space config item - - .. code-block:: yaml - - observation_space: - components: - - name: NODE_LINK_TABLE - - name: NODE_STATUSES - - name: LINK_TRAFFIC_LEVELS - - name: ACCESS_CONTROL_LIST - options: - combine_service_traffic : False - quantisation_levels: 99 - - - Currently available components are: - - * :py:mod:`NODE_LINK_TABLE` this does not accept any additional options - * :py:mod:`NODE_STATUSES`, this does not accept any additional options - * :py:mod:`ACCESS_CONTROL_LIST`, this does not accept additional options - * :py:mod:`LINK_TRAFFIC_LEVELS`, this accepts the following options: - - * ``combine_service_traffic`` - whether to consider bandwidth use separately for each network protocol or combine them into a single bandwidth reading (boolean) - * ``quantisation_levels`` - how many discrete bandwidth usage levels to use for encoding. This can be an integer equal to or greater than 3. - - The other configurable item is ``flatten`` which is false by default. When set to true, the observation space is flattened (turned into a 1-D vector). You should use this if your RL agent does not natively support observation space types like ``gym.Spaces.Tuple``. - -* **num_train_episodes** [int] - - This defines the number of episodes that the agent will train for. - - -* **num_train_steps** [int] - - Determines the number of steps to run in each episode of the training session. - - -* **num_eval_episodes** [int] - - This defines the number of episodes that the agent will be evaluated over. - - -* **num_eval_steps** [int] - - Determines the number of steps to run in each episode of the evaluation session. - - -* **time_delay** [int] - - The time delay (in milliseconds) to take between each step when running a GENERIC agent session - - -* **session_type** [text] - - Type of session to be run (TRAINING, EVALUATION, or BOTH) - -* **load_agent** [bool] - - Determine whether to load an agent from file - -* **agent_load_file** [text] - - File path and file name of agent if you're loading one in - -* **observation_space_high_value** [int] - - The high value to use for values in the observation space. This is set to 1000000000 by default, and should not need changing in most cases - -* **implicit_acl_rule** [str] - - Determines which Explicit rule the ACL list has - two options are: DENY or ALLOW. - -* **max_number_acl_rules** [int] - - Sets a limit on how many ACL rules there can be in the ACL list throughout the training session. - -**Reward-Based Config Values** - -Rewards are calculated based on the difference between the current state and reference state (the 'should be' state) of the environment. - -* **Generic [all_ok]** [float] - - The score to give when the current situation (for a given component) is no different from that expected in the baseline (i.e. as though no blue or red agent actions had been undertaken) - -* **Node Hardware State [off_should_be_on]** [float] - - The score to give when the node should be on, but is off - -* **Node Hardware State [off_should_be_resetting]** [float] - - The score to give when the node should be resetting, but is off - -* **Node Hardware State [on_should_be_off]** [float] - - The score to give when the node should be off, but is on - -* **Node Hardware State [on_should_be_resetting]** [float] - - The score to give when the node should be resetting, but is on - -* **Node Hardware State [resetting_should_be_on]** [float] - - The score to give when the node should be on, but is resetting - -* **Node Hardware State [resetting_should_be_off]** [float] - - The score to give when the node should be off, but is resetting - -* **Node Hardware State [resetting]** [float] - - The score to give when the node is resetting - -* **Node Operating System or Service State [good_should_be_patching]** [float] - - The score to give when the state should be patching, but is good - -* **Node Operating System or Service State [good_should_be_compromised]** [float] - - The score to give when the state should be compromised, but is good - -* **Node Operating System or Service State [good_should_be_overwhelmed]** [float] - - The score to give when the state should be overwhelmed, but is good - -* **Node Operating System or Service State [patching_should_be_good]** [float] - - The score to give when the state should be good, but is patching - -* **Node Operating System or Service State [patching_should_be_compromised]** [float] - - The score to give when the state should be compromised, but is patching - -* **Node Operating System or Service State [patching_should_be_overwhelmed]** [float] - - The score to give when the state should be overwhelmed, but is patching - -* **Node Operating System or Service State [patching]** [float] - - The score to give when the state is patching - -* **Node Operating System or Service State [compromised_should_be_good]** [float] - - The score to give when the state should be good, but is compromised - -* **Node Operating System or Service State [compromised_should_be_patching]** [float] - - The score to give when the state should be patching, but is compromised - -* **Node Operating System or Service State [compromised_should_be_overwhelmed]** [float] - - The score to give when the state should be overwhelmed, but is compromised - -* **Node Operating System or Service State [compromised]** [float] - - The score to give when the state is compromised - -* **Node Operating System or Service State [overwhelmed_should_be_good]** [float] - - The score to give when the state should be good, but is overwhelmed - -* **Node Operating System or Service State [overwhelmed_should_be_patching]** [float] - - The score to give when the state should be patching, but is overwhelmed - -* **Node Operating System or Service State [overwhelmed_should_be_compromised]** [float] - - The score to give when the state should be compromised, but is overwhelmed - -* **Node Operating System or Service State [overwhelmed]** [float] - - The score to give when the state is overwhelmed - -* **Node File System State [good_should_be_repairing]** [float] - - The score to give when the state should be repairing, but is good - -* **Node File System State [good_should_be_restoring]** [float] - - The score to give when the state should be restoring, but is good - -* **Node File System State [good_should_be_corrupt]** [float] - - The score to give when the state should be corrupt, but is good - -* **Node File System State [good_should_be_destroyed]** [float] - - The score to give when the state should be destroyed, but is good - -* **Node File System State [repairing_should_be_good]** [float] - - The score to give when the state should be good, but is repairing - -* **Node File System State [repairing_should_be_restoring]** [float] - - The score to give when the state should be restoring, but is repairing - -* **Node File System State [repairing_should_be_corrupt]** [float] - - The score to give when the state should be corrupt, but is repairing - -* **Node File System State [repairing_should_be_destroyed]** [float] - - The score to give when the state should be destroyed, but is repairing - -* **Node File System State [repairing]** [float] - - The score to give when the state is repairing - -* **Node File System State [restoring_should_be_good]** [float] - - The score to give when the state should be good, but is restoring - -* **Node File System State [restoring_should_be_repairing]** [float] - - The score to give when the state should be repairing, but is restoring - -* **Node File System State [restoring_should_be_corrupt]** [float] - - The score to give when the state should be corrupt, but is restoring - -* **Node File System State [restoring_should_be_destroyed]** [float] - - The score to give when the state should be destroyed, but is restoring - -* **Node File System State [restoring]** [float] - - The score to give when the state is restoring - -* **Node File System State [corrupt_should_be_good]** [float] - - The score to give when the state should be good, but is corrupt - -* **Node File System State [corrupt_should_be_repairing]** [float] - - The score to give when the state should be repairing, but is corrupt - -* **Node File System State [corrupt_should_be_restoring]** [float] - - The score to give when the state should be restoring, but is corrupt - -* **Node File System State [corrupt_should_be_destroyed]** [float] - - The score to give when the state should be destroyed, but is corrupt - -* **Node File System State [corrupt]** [float] - - The score to give when the state is corrupt - -* **Node File System State [destroyed_should_be_good]** [float] - - The score to give when the state should be good, but is destroyed - -* **Node File System State [destroyed_should_be_repairing]** [float] - - The score to give when the state should be repairing, but is destroyed - -* **Node File System State [destroyed_should_be_restoring]** [float] - - The score to give when the state should be restoring, but is destroyed - -* **Node File System State [destroyed_should_be_corrupt]** [float] - - The score to give when the state should be corrupt, but is destroyed - -* **Node File System State [destroyed]** [float] - - The score to give when the state is destroyed - -* **Node File System State [scanning]** [float] - - The score to give when the state is scanning - -* **IER Status [red_ier_running]** [float] - - The score to give when a red agent IER is permitted to run - -* **IER Status [green_ier_blocked]** [float] - - The score to give when a green agent IER is prevented from running - -**Patching / Reset Durations** - -* **os_patching_duration** [int] - - The number of steps to take when patching an Operating System - -* **node_reset_duration** [int] - - The number of steps to take when resetting a node's hardware state - -* **service_patching_duration** [int] - - The number of steps to take when patching a service - -* **file_system_repairing_limit** [int]: - - The number of steps to take when repairing the file system - -* **file_system_restoring_limit** [int] - - The number of steps to take when restoring the file system - -* **file_system_scanning_limit** [int] - - The number of steps to take when scanning the file system - -* **deterministic** [bool] - - Set to true if the agent evaluation should be deterministic. Default is ``False`` - -* **seed** [int] - - Seed used in the randomisation in agent training. Default is ``None`` - -The Lay Down Config -******************* - -The lay down config file consists of the following attributes: - - -* **itemType: STEPS** [int] - -* **item_type: PORTS** [int] - - Provides a list of ports modelled in this session - -* **item_type: SERVICES** [freetext] - - Provides a list of services modelled in this session - -* **item_type: NODE** - - Defines a node included in the system laydown being simulated. It should consist of the following attributes: - - * **id** [int]: Unique ID for this YAML item - * **name** [freetext]: Human-readable name of the component - * **node_class** [enum]: Relates to the base type of the node. Can be SERVICE, ACTIVE or PASSIVE. PASSIVE nodes do not have an operating system or services. ACTIVE nodes have an operating system, but no services. SERVICE nodes have both an operating system and one or more services - * **node_type** [enum]: Relates to the component type. Can be one of CCTV, SWITCH, COMPUTER, LINK, MONITOR, PRINTER, LOP, RTU, ACTUATOR or SERVER - * **priority** [enum]: Provides a priority for each node. Can be one of P1, P2, P3, P4 or P5 (which P1 being the highest) - * **hardware_state** [enum]: The initial hardware state of the node. Can be one of ON, OFF or RESETTING - * **ip_address** [IP address]: The IP address of the component in format xxx.xxx.xxx.xxx - * **software_state** [enum]: The intial state of the node operating system. Can be GOOD, PATCHING or COMPROMISED - * **file_system_state** [enum]: The initial state of the node file system. Can be GOOD, CORRUPT, DESTROYED, REPAIRING or RESTORING - * **services**: For each service associated with the node: - - * **name** [freetext]: Free-text name of the service, but must match one of the services defined for the system in the services list - * **port** [int]: Integer value of the port related to this service, but must match one of the ports defined for the system in the ports list - * **state** [enum]: The initial state of the service. Can be one of GOOD, PATCHING, COMPROMISED or OVERWHELMED - -* **item_type: LINK** - - Defines a link included in the system laydown being simulated. It should consist of the following attributes: - - * **id** [int]: Unique ID for this YAML item - * **name** [freetext]: Human-readable name of the component - * **bandwidth** [int]: The bandwidth (in bits/s) of the link - * **source** [int]: The ID of the source node - * **destination** [int]: The ID of the destination node - -* **item_type: GREEN_IER** - - Defines a green agent Information Exchange Requirement (IER). It should consist of: - - * **id** [int]: Unique ID for this YAML item - * **start_step** [int]: The start step (in the episode) for this IER to begin - * **end_step** [int]: The end step (in the episode) for this IER to finish - * **load** [int]: The load (in bits/s) for this IER to apply to links - * **protocol** [freetext]: The protocol to apply to the links. This must match a value in the services list - * **port** [int]: The port that the protocol is running on. This must match a value in the ports list - * **source** [int]: The ID of the source node - * **destination** [int]: The ID of the destination node - * **mission_criticality** [enum]: The mission criticality of this IER (with 5 being highest, 1 lowest) - -* **item_type: RED_IER** - - Defines a red agent Information Exchange Requirement (IER). It should consist of: - - * **id** [int]: Unique ID for this YAML item - * **start_step** [int]: The start step (in the episode) for this IER to begin - * **end_step** [int]: The end step (in the episode) for this IER to finish - * **load** [int]: The load (in bits/s) for this IER to apply to links - * **protocol** [freetext]: The protocol to apply to the links. This must match a value in the services list - * **port** [int]: The port that the protocol is running on. This must match a value in the ports list - * **source** [int]: The ID of the source node - * **destination** [int]: The ID of the destination node - * **mission_criticality** [enum]: Not currently used. Default to 0 - -* **item_type: GREEN_POL** - - Defines a green agent pattern-of-life instruction. It should consist of: - - * **id** [int]: Unique ID for this YAML item - * **start_step** [int]: The start step (in the episode) for this PoL to begin - * **end_step** [int]: Not currently used. Default to same as start step - * **nodeId** [int]: The ID of the node to apply the PoL to - * **type** [enum]: The type of PoL to apply. Can be one of OPERATING, OS or SERVICE - * **protocol** [freetext]: The protocol to be affected if SERVICE type is chosen. Must match a value in the services list - * **state** [enuum]: The state to apply to the node (which represents the PoL change). Can be one of ON, OFF or RESETTING (for node state) or GOOD, PATCHING or COMPROMISED (for Software State) or GOOD, PATCHING, COMPROMISED or OVERWHELMED (for service state) - -* **item_type: RED_POL** - - Defines a red agent pattern-of-life instruction. It should consist of: - - * **id** [int]: Unique ID for this YAML item - * **start_step** [int]: The start step (in the episode) for this PoL to begin - * **end_step** [int]: Not currently used. Default to same as start step - * **targetNodeId** [int]: The ID of the node to apply the PoL to - * **initiator** [enum]: What initiates the PoL. Can be DIRECT, IER or SERVICE - * **type** [enum]: The type of PoL to apply. Can be one of OPERATING, OS or SERVICE - * **protocol** [freetext]: The protocol to be affected if SERVICE type is chosen. Must match a value in the services list - * **state** [enum]: The state to apply to the node (which represents the PoL change). Can be one of ON, OFF or RESETTING (for node state) or GOOD, PATCHING or COMPROMISED (for Software State) or GOOD, PATCHING, COMPROMISED or OVERWHELMED (for service state) or GOOD, CORRUPT, DESTROYED, REPAIRING or RESTORING (for file system state) - * **sourceNodeId** [int] The ID of the source node containing the service to check (used for SERVICE initiator) - * **sourceNodeService** [freetext]: The service on the source node to check (used for SERVICE initiator). Must match a value in the services list for this node - * **sourceNodeServiceState** [enum]: The state of the source node service to check (used for SERVICE initiator). Can be one of GOOD, PATCHING, COMPROMISED or OVERWHELMED - -* **item_type: ACL_RULE** - - Defines an initial Access Control List (ACL) rule. It should consist of: - - * **id** [int]: Unique ID for this YAML item - * **permission** [enum]: Defines either an allow or deny rule. Value must be either DENY or ALLOW - * **source** [IP address]: Defines the source IP address for the rule in xxx.xxx.xxx.xxx format - * **destination** [IP address]: Defines the destination IP address for the rule in xxx.xxx.xxx.xxx format - * **protocol** [freetext]: Defines the protocol for the rule. Must match a value in the services list - * **port** [int]: Defines the port for the rule. Must match a value in the ports list - * **position** [int]: Defines where to place the ACL rule in the list. Lower index or (higher up in the list) means they are checked first. Index starts at 0 (Python indexes). diff --git a/docs/source/custom_agent.rst b/docs/source/custom_agent.rst index 040b4b3d..0a08ae74 100644 --- a/docs/source/custom_agent.rst +++ b/docs/source/custom_agent.rst @@ -11,132 +11,4 @@ Integrating a user defined blue agent .. note:: - If you are planning to implement custom RL agents into PrimAITE, you must use the project as a repository. If you install PrimAITE as a python package from wheel, custom agents are not supported. - -PrimAITE has integration with Ray RLLib and StableBaselines3 agents. All agents interface with PrimAITE through an :py:class:`primaite.agents.agent_abc.AgentSessionABC` which provides Input/Output of agent savefiles, as well as capturing and plotting performance metrics during training and evaluation. If you wish to integrate a custom blue agent, it is recommended to create a subclass of the :py:class:`primaite.agents.agent_abc.AgentSessionABC` and implement the ``__init__()``, ``_setup()``, ``_save_checkpoint()``, ``learn()``, ``evaluate()``, ``_get_latest_checkpoint``, ``load()``, and ``save()`` methods. - -Below is a barebones example of a custom agent implementation: - -.. code:: python - - # src/primaite/agents/my_custom_agent.py - - from primaite.agents.agent_abc import AgentSessionABC - from primaite.common.enums import AgentFramework, AgentIdentifier - - class CustomAgent(AgentSessionABC): - def __init__(self, training_config_path, lay_down_config_path): - super().__init__(training_config_path, lay_down_config_path) - assert self._training_config.agent_framework == AgentFramework.CUSTOM - assert self._training_config.agent_identifier == AgentIdentifier.MY_AGENT - self._setup() - - def _setup(self): - super()._setup() - self._env = Primaite( - training_config_path=self._training_config_path, - lay_down_config_path=self._lay_down_config_path, - session_path=self.session_path, - timestamp_str=self.timestamp_str, - ) - self._agent = ... # your code to setup agent - - def _save_checkpoint(self): - checkpoint_num = self._training_config.checkpoint_every_n_episodes - episode_count = self._env.episode_count - save_checkpoint = False - if checkpoint_num: - save_checkpoint = episode_count % checkpoint_num == 0 - # saves checkpoint if the episode count is not 0 and save_checkpoint flag was set to true - if episode_count and save_checkpoint: - ... - # your code to save checkpoint goes here. - # The path should start with self.checkpoints_path and include the episode number. - - def learn(self): - ... - # call your agent's learning function here. - - super().learn() # this will finalise learning and output session metadata - self.save() - - def evaluate(self): - ... - # call your agent's evaluation function here. - - self._env.close() - super().evaluate() - - def _get_latest_checkpoint(self): - ... - # Load an agent from file. - - @classmethod - def load(cls, path): - ... - # Create a CustomAgent object which loads model weights from file. - - def save(self): - ... - # Call your agent's function that saves it to a file - - -You will also need to modify :py:class:`primaite.primaite_session.PrimaiteSession` and :py:mod:`primaite.common.enums` to capture your new agent identifiers. - -.. code-block:: python - :emphasize-lines: 17, 18 - - # src/primaite/common/enums.py - - class AgentIdentifier(Enum): - """The Red Agent algo/class.""" - A2C = 1 - "Advantage Actor Critic" - PPO = 2 - "Proximal Policy Optimization" - HARDCODED = 3 - "The Hardcoded agents" - DO_NOTHING = 4 - "The DoNothing agents" - RANDOM = 5 - "The RandomAgent" - DUMMY = 6 - "The DummyAgent" - CUSTOM_AGENT = 7 - "Your custom agent" - -.. code-block:: python - :emphasize-lines: 3, 11, 12 - - # src/primaite_session.py - - from primaite.agents.my_custom_agent import CustomAgent - - # ... - - def setup(self): - """Performs the session setup.""" - if self._training_config.agent_framework == AgentFramework.CUSTOM: - _LOGGER.debug(f"PrimaiteSession Setup: Agent Framework = {AgentFramework.CUSTOM}") - if self._training_config.agent_identifier == AgentIdentifier.CUSTOM_AGENT: - self._agent_session = CustomAgent(self._training_config_path, self._lay_down_config_path) - if self._training_config.agent_identifier == AgentIdentifier.HARDCODED: - _LOGGER.debug(f"PrimaiteSession Setup: Agent Identifier =" f" {AgentIdentifier.HARDCODED}") - if self._training_config.action_type == ActionType.NODE: - # Deterministic Hardcoded Agent with Node Action Space - self._agent_session = HardCodedNodeAgent(self._training_config_path, self._lay_down_config_path) - -Finally, specify your agent in your training config. - -.. code-block:: yaml - - # ~/primaite/2.0.0/config/path/to/your/config_main.yaml - - # Training Config File - - agent_framework: CUSTOM - agent_identifier: CUSTOM_AGENT - random_red_agent: False - # ... - -Now you can :ref:`run a primaite session` with your custom agent by passing in the custom ``config_main``. + PrimAITE uses ARCD GATE for agent integration. In order to use a custom agent with PrimAITE, you must integrate it with ARCD GATE. Please look at the ARCD GATE documentation for more information. diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 0801c79e..aebabf66 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -11,7 +11,7 @@ Getting Started Pre-Requisites -In order to get **PrimAITE** installed, you will need to have a python version between 3.8 and 3.10 installed. If you don't already have it, this is how to install it: +In order to get **PrimAITE** installed, you will need to have a python version between 3.8 and 3.11 installed. If you don't already have it, this is how to install it: .. code-block:: bash @@ -33,39 +33,36 @@ In order to get **PrimAITE** installed, you will need to have a python version b Install PrimAITE **************** -1. Create a primaite directory in your home directory: - - +1. Create a directory for your PrimAITE project: .. code-block:: bash :caption: Unix - mkdir ~/primaite/2.0.0 + mkdir ~/primaite/3.0.0 .. code-block:: powershell :caption: Windows (Powershell) - mkdir ~\primaite\2.0.0 + mkdir ~\primaite\3.0.0 + 2. Navigate to the primaite directory and create a new python virtual environment (venv) - - .. code-block:: bash :caption: Unix - cd ~/primaite/2.0.0 + cd ~/primaite/3.0.0 python3 -m venv .venv .. code-block:: powershell :caption: Windows (Powershell) - cd ~\primaite\2.0.0 + cd ~\primaite\3.0.0 python3 -m venv .venv attrib +h .venv /s /d # Hides the .venv directory -3. Activate the venv +3. Activate the venv .. code-block:: bash :caption: Unix @@ -78,21 +75,34 @@ Install PrimAITE .\.venv\Scripts\activate -4. Install PrimAITE using pip from PyPi +4. Install PrimAITE from your saved wheel file + +.. code-block:: bash + :caption: Unix + + pip install path/to/your/primaite.whl + +.. code-block:: powershell + :caption: Windows (Powershell) + + pip install path\to\your\primaite.whl + + +5. Install ARCD GATE from wheel file .. code-block:: bash :caption: Unix - pip install primaite + pip install path/to/your/arcd_gate-0.1.0-py3-none-any.whl .. code-block:: powershell :caption: Windows (Powershell) - pip install primaite + pip install path\to\your\arcd_gate-0.1.0-py3-none-any.whl -5. Perform the PrimAITE setup +6. Perform the PrimAITE setup .. code-block:: bash :caption: Unix @@ -110,13 +120,14 @@ Clone & Install PrimAITE for Development To be able to extend PrimAITE further, or to build wheels manually before install, clone the repository to a location of your choice: +1. Clone the repository + .. code-block:: bash git clone https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE cd primaite -Create and activate your Python virtual environment (venv) - +2. Create and activate your Python virtual environment (venv) .. code-block:: bash :caption: Unix @@ -130,8 +141,7 @@ Create and activate your Python virtual environment (venv) python3 -m venv venv .\venv\Scripts\activate -Install PrimAITE with the dev extra - +3. Install PrimAITE with the dev extra .. code-block:: bash :caption: Unix @@ -144,4 +154,16 @@ Install PrimAITE with the dev extra pip install -e .[dev] +4. Install ARCD GATE from wheel file + +.. code-block:: bash + :caption: Unix + + pip install GATE/arcd_gate-0.1.0-py3-none-any.whl + +.. code-block:: powershell + :caption: Windows (Powershell) + + pip install GATE\arcd_gate-0.1.0-py3-none-any.whl + To view the complete list of packages installed during PrimAITE installation, go to the dependencies page (:ref:`Dependencies`). diff --git a/docs/source/migration_1.2_-_2.0.rst b/docs/source/migration_1.2_-_2.0.rst deleted file mode 100644 index c38fcbe9..00000000 --- a/docs/source/migration_1.2_-_2.0.rst +++ /dev/null @@ -1,57 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -v1.2 to v2.0 Migration guide -============================ - -**1. Installing PrimAITE** - - Like before, you can install primaite from the repository by running ``pip install -e .``. But, there is now an additional setup step which does several things, like setting up user directories, copy default configs and notebooks, etc. Once you have installed PrimAITE to your virtual environment, run this command to finalise setup. - - .. code-block:: bash - - primaite setup - -**2. Running a training session** - - In version 1.2 of PrimAITE, the main entry point for training or evaluating agents was the ``src/primaite/main.py`` file. v2.0.0 introduced managed 'sessions' which are responsible for reading configuration files, performing training, and writing outputs. - - ``main.py`` file still runs a training session but it now uses the new `PrimaiteSession`, and it now requires you to provide the path to your config files. - - .. code-block:: bash - - python src/primaite/main.py --tc path/to/training-config.yaml --ldc path/to/laydown-config.yaml - - Alternatively, the session can be invoked via the commandline by running: - - .. code-block:: bash - - primaite session --tc path/to/training-config.yaml --ldc path/to/laydown-config.yaml - -**3. Location of configs** - - In version 1.2, training configs and laydown configs were all stored in the project repository under ``src/primaite/config``. Version 2.0.0 introduced user data directories, and now when you install and setup PrimAITE, config files are stored in your user data location. On Linux/OSX, this is stored in ``~/primaite/2.0.0/config``. On Windows, this is stored in ``C:\Users\\primaite\configs``. Upon first setup, the configs folder is populated with some default yaml files. It is recommended that you store all your custom configuration files here. - -**4. Contents of configs** - - Some things that were previously part of the laydown config are now part of the traning config. - - * Actions - - If you have custom configs which use these, you will need to adapt them by moving the configuration from the laydown config to the training config. - - Also, there are new configurable items in the training config: - - * Observations - * Agent framework - * Agent - * Deep learning framework - * random red agents - * seed - * deterministic - * hard coded agent view - - Each of these items have default values which are designed so that PrimAITE has the same behaviour as it did in 1.2.0, so you do not have to specify them. - - ACL Rules in laydown configs have a new required parameter: ``position``. The lower the position, the higher up in the ACL table the rule will placed. If you have custom laydowns, you will need to go through them and add a position to each ACL_RULE. diff --git a/docs/source/primaite_session.rst b/docs/source/primaite_session.rst index 8ccc9070..472a361f 100644 --- a/docs/source/primaite_session.rst +++ b/docs/source/primaite_session.rst @@ -14,199 +14,200 @@ A PrimAITE session can be ran either with the ``primaite session`` command from (See :func:`primaite.cli.session`), or by calling :func:`primaite.main.run` from a Python terminal or Jupyter Notebook. Both the ``primaite session`` and :func:`primaite.main.run` take a training config and a lay down config as parameters. +.. note:: + 🚧 *UNDER CONSTRUCTION* 🚧 - - -.. code-block:: bash - :caption: Unix CLI - - cd ~/primaite/2.0.0 - source ./.venv/bin/activate - primaite session --tc ./config/my_training_config.yaml --ldc ./config/my_lay_down_config.yaml - -.. code-block:: powershell - :caption: Powershell CLI - - cd ~\primaite\2.0.0 - .\.venv\Scripts\activate - primaite session --tc .\config\my_training_config.yaml --ldc .\config\my_lay_down_config.yaml - - -.. code-block:: python - :caption: Python - - from primaite.main import run - - training_config = - lay_down_config = - run(training_config, lay_down_config) - -When a session is ran, a session output sub-directory is created in the users app sessions directory (``~/primaite/2.0.0/sessions``). -The sub-directory is formatted as such: ``~/primaite/2.0.0/sessions//_/`` - -For example, when running a session at 17:30:00 on 31st January 2023, the session will output to: -``~/primaite/2.0.0/sessions/2023-01-31/2023-01-31_17-30-00/``. - -``primaite session`` can be ran in the terminal/command prompt without arguments. It will use the default configs in the directory ``primaite/config/example_config``. - -To run a PrimAITE session using legacy training or laydown config files, add the ``--legacy-tc`` and/or ``legacy-ldc`` options. - - - -.. code-block:: bash - :caption: Unix CLI - - cd ~/primaite/2.0.0 - source ./.venv/bin/activate - primaite session --tc ./config/my_legacy_training_config.yaml --legacy-tc --ldc ./config/my_legacy_lay_down_config.yaml --legacy-ldc - -.. code-block:: powershell - :caption: Powershell CLI - - cd ~\primaite\2.0.0 - .\.venv\Scripts\activate - primaite session --tc .\config\my_legacy_training_config.yaml --legacy-tc --ldc .\config\my_legacy_lay_down_config.yaml --legacy-ldc - - -.. code-block:: python - :caption: Python - - from primaite.main import run - - training_config = - lay_down_config = - run(training_config, lay_down_config, legacy_training_config=True, legacy_lay_down_config=True) - - - - -Outputs -------- - -PrimAITE produces four types of outputs: - -* Session Metadata -* Results -* Diagrams -* Saved agents (training checkpoints and a final trained agent) - - -**Session Metadata** - -PrimAITE creates a ``session_metadata.json`` file that contains the following metadata: - - * **uuid** - The UUID assigned to the session upon instantiation. - * **start_datetime** - The date & time the session started in iso format. - * **end_datetime** - The date & time the session ended in iso format. - * **learning** - * **total_episodes** - The total number of training episodes completed. - * **total_time_steps** - The total number of training time steps completed. - * **evaluation** - * **total_episodes** - The total number of evaluation episodes completed. - * **total_time_steps** - The total number of evaluation time steps completed. - * **env** - * **training_config** - * **All training config items** - * **lay_down_config** - * **All lay down config items** - - -**Results** - -PrimAITE automatically creates two sets of results from each learning and evaluation session: - -* Average reward per episode - a csv file listing the average reward for each episode of the session. This provides, for example, an indication of the change over a training session of the reward value -* All transactions - a csv file listing the following values for every step of every episode: - - * Timestamp - * Episode number - * Step number - * Reward value - * Action taken (as presented by the blue agent on this step). Individual elements of the action space are presented in the format AS_X - * Initial observation space (what the blue agent observed when it decided its action) - -**Diagrams** - -* For each session, PrimAITE automatically creates a visualisation of the system / network lay down configuration. -* For each learning and evaluation task within the session, PrimAITE automatically plots the average reward per episode using PlotLY and saves it to the learning or evaluation subdirectory in the session directory. - -**Saved agents** - -For each training session, assuming the agent being trained implements the *save()* function and this function is called by the code, PrimAITE automatically saves the agent state. - -**Example Session Directory Structure** - -.. code-block:: text - - ~/ - └── primaite/ - └── 2.0.0/ - └── sessions/ - └── 2023-07-18/ - └── 2023-07-18_11-06-04/ - ├── evaluation/ - │ ├── all_transactions_2023-07-18_11-06-04.csv - │ ├── average_reward_per_episode_2023-07-18_11-06-04.csv - │ └── average_reward_per_episode_2023-07-18_11-06-04.png - ├── learning/ - │ ├── all_transactions_2023-07-18_11-06-04.csv - │ ├── average_reward_per_episode_2023-07-18_11-06-04.csv - │ ├── average_reward_per_episode_2023-07-18_11-06-04.png - │ ├── checkpoints/ - │ │ └── sb3ppo_10.zip - │ ├── SB3_PPO.zip - │ └── tensorboard_logs/ - │ ├── PPO_1/ - │ │ └── events.out.tfevents.1689674765.METD-9PMRFB3.42960.0 - │ ├── PPO_2/ - │ │ └── events.out.tfevents.1689674766.METD-9PMRFB3.42960.1 - │ ├── PPO_3/ - │ │ └── events.out.tfevents.1689674766.METD-9PMRFB3.42960.2 - │ ├── PPO_4/ - │ │ └── events.out.tfevents.1689674767.METD-9PMRFB3.42960.3 - │ ├── PPO_5/ - │ │ └── events.out.tfevents.1689674767.METD-9PMRFB3.42960.4 - │ ├── PPO_6/ - │ │ └── events.out.tfevents.1689674768.METD-9PMRFB3.42960.5 - │ ├── PPO_7/ - │ │ └── events.out.tfevents.1689674768.METD-9PMRFB3.42960.6 - │ ├── PPO_8/ - │ │ └── events.out.tfevents.1689674769.METD-9PMRFB3.42960.7 - │ ├── PPO_9/ - │ │ └── events.out.tfevents.1689674770.METD-9PMRFB3.42960.8 - │ └── PPO_10/ - │ └── events.out.tfevents.1689674770.METD-9PMRFB3.42960.9 - ├── network_2023-07-18_11-06-04.png - └── session_metadata.json - -Loading a session ------------------ - -A previous session can be loaded by providing the **directory** of the previous session to either the ``primaite session`` command from the cli -(See :func:`primaite.cli.session`), or by calling :func:`primaite.main.run` with session_path. - -.. tabs:: - - .. code-tab:: bash +.. + .. code-block:: bash :caption: Unix CLI cd ~/primaite/2.0.0 source ./.venv/bin/activate - primaite session --load "path/to/session" + primaite session --tc ./config/my_training_config.yaml --ldc ./config/my_lay_down_config.yaml - .. code-tab:: bash + .. code-block:: powershell :caption: Powershell CLI cd ~\primaite\2.0.0 .\.venv\Scripts\activate - primaite session --load "path\to\session" + primaite session --tc .\config\my_training_config.yaml --ldc .\config\my_lay_down_config.yaml - .. code-tab:: python + .. code-block:: python :caption: Python from primaite.main import run - run(session_path=) + training_config = + lay_down_config = + run(training_config, lay_down_config) -When PrimAITE runs a loaded session, PrimAITE will output in the provided session directory + When a session is ran, a session output sub-directory is created in the users app sessions directory (``~/primaite/2.0.0/sessions``). + The sub-directory is formatted as such: ``~/primaite/2.0.0/sessions//_/`` + + For example, when running a session at 17:30:00 on 31st January 2023, the session will output to: + ``~/primaite/2.0.0/sessions/2023-01-31/2023-01-31_17-30-00/``. + + ``primaite session`` can be ran in the terminal/command prompt without arguments. It will use the default configs in the directory ``primaite/config/example_config``. + + To run a PrimAITE session using legacy training or laydown config files, add the ``--legacy-tc`` and/or ``legacy-ldc`` options. + + + + .. code-block:: bash + :caption: Unix CLI + + cd ~/primaite/2.0.0 + source ./.venv/bin/activate + primaite session --tc ./config/my_legacy_training_config.yaml --legacy-tc --ldc ./config/my_legacy_lay_down_config.yaml --legacy-ldc + + .. code-block:: powershell + :caption: Powershell CLI + + cd ~\primaite\2.0.0 + .\.venv\Scripts\activate + primaite session --tc .\config\my_legacy_training_config.yaml --legacy-tc --ldc .\config\my_legacy_lay_down_config.yaml --legacy-ldc + + + .. code-block:: python + :caption: Python + + from primaite.main import run + + training_config = + lay_down_config = + run(training_config, lay_down_config, legacy_training_config=True, legacy_lay_down_config=True) + + + + + Outputs + ------- + + PrimAITE produces four types of outputs: + + * Session Metadata + * Results + * Diagrams + * Saved agents (training checkpoints and a final trained agent) + + + **Session Metadata** + + PrimAITE creates a ``session_metadata.json`` file that contains the following metadata: + + * **uuid** - The UUID assigned to the session upon instantiation. + * **start_datetime** - The date & time the session started in iso format. + * **end_datetime** - The date & time the session ended in iso format. + * **learning** + * **total_episodes** - The total number of training episodes completed. + * **total_time_steps** - The total number of training time steps completed. + * **evaluation** + * **total_episodes** - The total number of evaluation episodes completed. + * **total_time_steps** - The total number of evaluation time steps completed. + * **env** + * **training_config** + * **All training config items** + * **lay_down_config** + * **All lay down config items** + + + **Results** + + PrimAITE automatically creates two sets of results from each learning and evaluation session: + + * Average reward per episode - a csv file listing the average reward for each episode of the session. This provides, for example, an indication of the change over a training session of the reward value + * All transactions - a csv file listing the following values for every step of every episode: + + * Timestamp + * Episode number + * Step number + * Reward value + * Action taken (as presented by the blue agent on this step). Individual elements of the action space are presented in the format AS_X + * Initial observation space (what the blue agent observed when it decided its action) + + **Diagrams** + + * For each session, PrimAITE automatically creates a visualisation of the system / network lay down configuration. + * For each learning and evaluation task within the session, PrimAITE automatically plots the average reward per episode using PlotLY and saves it to the learning or evaluation subdirectory in the session directory. + + **Saved agents** + + For each training session, assuming the agent being trained implements the *save()* function and this function is called by the code, PrimAITE automatically saves the agent state. + + **Example Session Directory Structure** + + .. code-block:: text + + ~/ + └── primaite/ + └── 2.0.0/ + └── sessions/ + └── 2023-07-18/ + └── 2023-07-18_11-06-04/ + ├── evaluation/ + │ ├── all_transactions_2023-07-18_11-06-04.csv + │ ├── average_reward_per_episode_2023-07-18_11-06-04.csv + │ └── average_reward_per_episode_2023-07-18_11-06-04.png + ├── learning/ + │ ├── all_transactions_2023-07-18_11-06-04.csv + │ ├── average_reward_per_episode_2023-07-18_11-06-04.csv + │ ├── average_reward_per_episode_2023-07-18_11-06-04.png + │ ├── checkpoints/ + │ │ └── sb3ppo_10.zip + │ ├── SB3_PPO.zip + │ └── tensorboard_logs/ + │ ├── PPO_1/ + │ │ └── events.out.tfevents.1689674765.METD-9PMRFB3.42960.0 + │ ├── PPO_2/ + │ │ └── events.out.tfevents.1689674766.METD-9PMRFB3.42960.1 + │ ├── PPO_3/ + │ │ └── events.out.tfevents.1689674766.METD-9PMRFB3.42960.2 + │ ├── PPO_4/ + │ │ └── events.out.tfevents.1689674767.METD-9PMRFB3.42960.3 + │ ├── PPO_5/ + │ │ └── events.out.tfevents.1689674767.METD-9PMRFB3.42960.4 + │ ├── PPO_6/ + │ │ └── events.out.tfevents.1689674768.METD-9PMRFB3.42960.5 + │ ├── PPO_7/ + │ │ └── events.out.tfevents.1689674768.METD-9PMRFB3.42960.6 + │ ├── PPO_8/ + │ │ └── events.out.tfevents.1689674769.METD-9PMRFB3.42960.7 + │ ├── PPO_9/ + │ │ └── events.out.tfevents.1689674770.METD-9PMRFB3.42960.8 + │ └── PPO_10/ + │ └── events.out.tfevents.1689674770.METD-9PMRFB3.42960.9 + ├── network_2023-07-18_11-06-04.png + └── session_metadata.json + + Loading a session + ----------------- + + A previous session can be loaded by providing the **directory** of the previous session to either the ``primaite session`` command from the cli + (See :func:`primaite.cli.session`), or by calling :func:`primaite.main.run` with session_path. + + .. tabs:: + + .. code-tab:: bash + :caption: Unix CLI + + cd ~/primaite/2.0.0 + source ./.venv/bin/activate + primaite session --load "path/to/session" + + .. code-tab:: bash + :caption: Powershell CLI + + cd ~\primaite\2.0.0 + .\.venv\Scripts\activate + primaite session --load "path\to\session" + + + .. code-tab:: python + :caption: Python + + from primaite.main import run + + run(session_path=) + + When PrimAITE runs a loaded session, PrimAITE will output in the provided session directory diff --git a/docs/source/request_system.rst b/docs/source/request_system.rst new file mode 100644 index 00000000..41d8eec4 --- /dev/null +++ b/docs/source/request_system.rst @@ -0,0 +1,90 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +Request System +============== + +``SimComponent``s in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``RequestManager`` and ``RequestType``. + +Just like other aspects of SimComponent, the request typess are not managed centrally for the whole simulation, but instead they are dynamically created and updated based on the nodes, links, and other components that currently exist. This was achieved in the following way: + +- API + An ``RequestType`` contains two elements: + + 1. ``request`` - selects which action you want to take on this ``SimComponent``. This is formatted as a list of strings such as `['network', 'node', '', 'service', '', 'restart']`. + 2. ``context`` - optional extra information that can be used to decide how to process the request. This is formatted as a dictionary. For example, if the request requires authentication, the context can include information about the user that initiated the request to decide if their permissions are sufficient. + +- request + The request is a list of strings which help specify who should handle the request. The strings in the request list help RequestManagers traverse the 'ownership tree' of SimComponent. The example given above would be handled in the following way: + + 1. ``Simulation`` receives `['network', 'node', '', 'service', '', 'restart']`. + The first element of the request is ``network``, therefore it passes the request down to its network. + 2. ``Network`` receives `['node', '', 'service', '', 'restart']`. + The first element of the request is ``node``, therefore the network looks at the node uuid and passes the request down to the node with that uuid. + 3. ``Node`` receives `['service', '', 'restart']`. + The first element of the request is ``service``, therefore the node looks at the service uuid and passes the rest of the request to the service with that uuid. + 4. ``Service`` receives ``['restart']``. + Since ``restart`` is a defined request type in the service's own RequestManager, the service performs a restart. + +Technical Detail +================ + +This system was achieved by implementing two classes, :py:class:`primaite.simulator.core.RequestType`, and :py:class:`primaite.simulator.core.RequestManager`. + +``RequestType`` +------ + +The ``RequestType`` object stores a reference to a method that executes the request, for example a node could have a request type that stores a reference to ``self.turn_on()``. Technically, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using ``lambda`` functions within a component's ``self._init_request_manager()`` method. Optionally, the ``RequestType`` object can also hold a validator that will permit/deny the request depending on context. + +``RequestManager`` +------------- + +The ``RequestManager`` object stores a mapping between strings and request types. It is responsible for processing the request and passing it down the ownership tree. Technically, the ``RequestManager`` is itself a callable that accepts `request, context` tuple, and so it can be chained with other request managers. + +A simple example without chaining can be seen in the :py:class:`primaite.simulator.file_system.file_system.File` class. + +.. code-block:: python + + class File(FileSystemItemABC): + ... + def _init_request_manager(self): + ... + request_manager.add_request("scan", RequestType(func=lambda request, context: self.scan())) + request_manager.add_request("repair", RequestType(func=lambda request, context: self.repair())) + request_manager.add_request("restore", RequestType(func=lambda request, context: self.restore())) + +*ellipses (``...``) used to omit code impertinent to this explanation* + +Chaining RequestManagers +----------------------- + +A request function needs to be a callable that accepts ``request, context`` as parameters. Since the request manager resolves requests by invoking it with ``request, context`` as parameter, it is possible to use a ``RequestManager`` as a ``RequestType``. + +When a RequestManager accepts a request, it pops the first element and uses it to decide where it should send the remaining request. This is how PrimAITE traverses the ownership tree. If the ``RequestType`` has another ``RequestManager`` as its function, the request will be routed again. Each time the request is passed to a new request manager, the first element is popped. + +An example of how this works is in the :py:class:`primaite.simulator.network.hardware.base.Node` class. + +.. code-block:: python + + class Node(SimComponent): + ... + def _init_request_manager(self): + ... + # a regular action which is processed by the Node itself + request_manager.add_request("turn_on", RequestType(func=lambda request, context: self.turn_on())) + + # if the Node receives a request where the first word is 'service', it will use a dummy manager + # called self._service_request_manager to pass on the reqeust to the relevant service. This dummy + # manager is simply here to map the service UUID that that service's own action manager. This is + # done because the next string after "service" is always the uuid of that service, so we need an + # RequestManager to pop that string before sending it onto the relevant service's RequestManager. + self._service_request_manager = RequestManager() + request_manager.add_request("service", RequestType(func=self._service_request_manager)) + ... + + def install_service(self, service): + self.services[service.uuid] = service + ... + # Here, the service UUID is registered to allow passing actions between the node and the service. + self._service_request_manager.add_request(service.uuid, RequestType(func=service._request_manager)) diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index 8671a2d2..5e259c6f 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -23,4 +23,8 @@ Contents simulation_components/network/network simulation_components/system/internal_frame_processing simulation_components/system/software - action_system + simulation_components/system/data_manipulation_bot + simulation_components/system/database_client_server + simulation_components/system/dns_client_server + simulation_components/system/ftp_client_server + simulation_components/system/web_browser_and_web_server_service diff --git a/docs/source/simulation_structure.rst b/docs/source/simulation_structure.rst index 2f0a56e8..6e0ab5ce 100644 --- a/docs/source/simulation_structure.rst +++ b/docs/source/simulation_structure.rst @@ -12,7 +12,7 @@ and a domain controller for managing software and users. Each node of the simulation 'tree' has responsibility for creating, deleting, and updating its direct descendants. Also, when a component's ``describe_state()`` method is called, it will include the state of its descendants. The -``apply_action()`` method can be used to act on a component or one of its descendatnts. The diagram below shows the +``apply_request()`` method can be used to act on a component or one of its descendatnts. The diagram below shows the relationship between components. .. image:: _static/component_relationship.png @@ -25,9 +25,9 @@ relationship between components. Actions ======= Agents can interact with the simulation by using actions. Actions are standardised with the -:py:class:`primaite.simulation.core.Action` class, which just holds a reference to two special functions. +:py:class:`primaite.simulation.core.RequestType` class, which just holds a reference to two special functions. -1. The action function itself, it must accept a `request` parameters which is a list of strings that describe what the +1. The request function itself, it must accept a `request` parameters which is a list of strings that describe what the action should do. It must also accept a `context` dict which can house additional information surrounding the action. For example, the context will typically include information about which entity intiated the action. 2. A validator function. This function should return a boolean value that decides if the request is permitted or not. diff --git a/docs/source/state_system.rst b/docs/source/state_system.rst new file mode 100644 index 00000000..b8a9624e --- /dev/null +++ b/docs/source/state_system.rst @@ -0,0 +1,31 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +Simulation State +============== + +``SimComponent``s in the simulation have a method called ``describe_state`` which returns a dictionary of the state of the component. This is used to report pertinent data that could impact agent's actions or rewards. For instance, the name and health status of a node is reported, which can be used by a reward function to punish corrupted or compromised nodes and reward healthy nodes. Each ``SimComponent`` reports not only it's own attributes in the state but also that of its child components. I.e. a computer node will report the state of its ``FileSystem``, and the ``FileSystem`` will report the state of its files and folders. This happens by recursively calling childrens' own ``describe_state`` methods. + +The game layer calls ``describe_state`` on the trunk ``SimComponent`` (the top-level parent) and then pass the state to the agents once per simulation step. For this reason, all ``SimComponent``s must have a ``describe_state`` method, and they must all be linked to the trunk ``SimComponent``. + +This code snippet demonstrates how the state information is defined within the ``SimComponent`` class: + +.. code-block:: python + + class Node(SimComponent): + operating_state: NodeOperatingState = NodeOperatingState.OFF + services: Dict[str, Service] = {} + + def describe_state(self) -> Dict: + state = super().describe_state() + state["operating_state"] = self.operating_state.value + state["services"] = {uuid: svc.describe_state() for uuid, svc in self.services.items()} + return state + + class Service(SimComponent): + health_state: ServiceHealthState = ServiceHealthState.GOOD + def describe_state(self) -> Dict: + state = super().describe_state() + state["health_state"] = self.health_state.value + return state From 8783574442e24d31813f208dff94b4431eb21a72 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Fri, 27 Oct 2023 10:17:59 +0100 Subject: [PATCH 260/980] #1961: os scan set up --- .../simulator/file_system/file_system.py | 5 +++ .../simulator/network/hardware/base.py | 34 ++++++++++++++++++- .../simulator/system/services/service.py | 5 --- .../_network/_hardware/test_node_actions.py | 31 +++++++++++++++++ 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 55af71c4..cddd276a 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -231,6 +231,11 @@ class FileSystem(SimComponent): state["folders"] = {folder.name: folder.describe_state() for folder in self.folders.values()} return state + def scan(self): + """Scan all the folders and files in the file system.""" + for folder_id in self.folders: + self.folders[folder_id].scan() + def create_folder(self, folder_name: str) -> Folder: """ Creates a Folder and adds it to the list of folders. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 7099e4c7..153a0a15 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -978,7 +978,7 @@ class Node(SimComponent): self._application_request_manager = RequestManager() rm.add_request("application", RequestType(func=self._application_request_manager)) - rm.add_request("scan", RequestType(func=lambda request, context: ...)) # TODO implement OS scan + rm.add_request("scan", RequestType(func=lambda request, context: self.scan(reveal_to_red=True))) rm.add_request("shutdown", RequestType(func=lambda request, context: self.power_off())) rm.add_request("startup", RequestType(func=lambda request, context: self.power_on())) @@ -986,6 +986,10 @@ class Node(SimComponent): rm.add_request("logon", RequestType(func=lambda request, context: ...)) # TODO implement logon request rm.add_request("logoff", RequestType(func=lambda request, context: ...)) # TODO implement logoff request + self._os_request_manager = RequestManager() + self._os_request_manager.add_request("scan", RequestType(func=lambda request, context: self.scan())) + rm.add_request("os", RequestType(func=self._os_request_manager)) + return rm def _install_system_software(self): @@ -1086,6 +1090,34 @@ class Node(SimComponent): self.operating_state = NodeOperatingState.OFF self.sys_log.info("Turned off") + def scan(self): + """ + Scan the node and all the items within it. + + Scans the: + - Processes + - Services + - Applications + - Folders + - Files + + to the red agent. + """ + # scan processes + for process_id in self.processes: + self.processes[process_id].scan() + + # scan services + for service_id in self.services: + self.services[service_id].scan() + + # scan applications + for application_id in self.applications: + self.applications[application_id].scan() + + # scan file system + self.file_system.scan() + def power_on(self): """Power on the Node, enabling its NICs if it is in the OFF state.""" if self.operating_state == NodeOperatingState.OFF: diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 24de027c..079f1dcf 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -82,11 +82,6 @@ class Service(IOSoftware): """ pass - def scan(self) -> None: - """Update the service visible states.""" - # update the visible operating state - self.health_state_visible = self.health_state_actual - def stop(self) -> None: """Stop the service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py index e03e1d28..de4e0745 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py @@ -1,6 +1,9 @@ import pytest from primaite.simulator.network.hardware.base import Node, NodeOperatingState +from primaite.simulator.system.processes.process import Process +from primaite.simulator.system.services.service import Service +from primaite.simulator.system.software import SoftwareHealthState @pytest.fixture @@ -39,3 +42,31 @@ def test_node_shutdown(node): idx += 1 assert node.operating_state == NodeOperatingState.OFF + + +def test_node_os_scan(node): + """Test OS Scanning.""" + # add process to node + node.processes["process"] = Process(name="process") + node.processes["process"].health_state_actual = SoftwareHealthState.COMPROMISED + assert node.processes["process"].health_state_visible == SoftwareHealthState.GOOD + + # add services to node + service = Service(name="service") + service.health_state_actual = SoftwareHealthState.COMPROMISED + node.install_service(service=service) + + # add application to node + + # add file to node + + # run os scan + node.apply_request(["os", "scan"]) + + # apply time steps + for i in range(20): + node.apply_timestep(timestep=i) + + # should update the state of all items + assert node.processes["process"].health_state_visible == SoftwareHealthState.COMPROMISED + assert service.health_state_visible == SoftwareHealthState.COMPROMISED From 318c9f8c5aa49d116398829ea135d1e10d2107a6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 27 Oct 2023 11:43:11 +0100 Subject: [PATCH 261/980] Fix formatting issues --- docs/source/request_system.rst | 4 ++-- docs/source/state_system.rst | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/request_system.rst b/docs/source/request_system.rst index 41d8eec4..09e46380 100644 --- a/docs/source/request_system.rst +++ b/docs/source/request_system.rst @@ -28,7 +28,7 @@ Just like other aspects of SimComponent, the request typess are not managed cent Since ``restart`` is a defined request type in the service's own RequestManager, the service performs a restart. Technical Detail -================ +---------------- This system was achieved by implementing two classes, :py:class:`primaite.simulator.core.RequestType`, and :py:class:`primaite.simulator.core.RequestManager`. @@ -38,7 +38,7 @@ This system was achieved by implementing two classes, :py:class:`primaite.simula The ``RequestType`` object stores a reference to a method that executes the request, for example a node could have a request type that stores a reference to ``self.turn_on()``. Technically, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using ``lambda`` functions within a component's ``self._init_request_manager()`` method. Optionally, the ``RequestType`` object can also hold a validator that will permit/deny the request depending on context. ``RequestManager`` -------------- +------------------ The ``RequestManager`` object stores a mapping between strings and request types. It is responsible for processing the request and passing it down the ownership tree. Technically, the ``RequestManager`` is itself a callable that accepts `request, context` tuple, and so it can be chained with other request managers. diff --git a/docs/source/state_system.rst b/docs/source/state_system.rst index b8a9624e..de4cd093 100644 --- a/docs/source/state_system.rst +++ b/docs/source/state_system.rst @@ -5,9 +5,9 @@ Simulation State ============== -``SimComponent``s in the simulation have a method called ``describe_state`` which returns a dictionary of the state of the component. This is used to report pertinent data that could impact agent's actions or rewards. For instance, the name and health status of a node is reported, which can be used by a reward function to punish corrupted or compromised nodes and reward healthy nodes. Each ``SimComponent`` reports not only it's own attributes in the state but also that of its child components. I.e. a computer node will report the state of its ``FileSystem``, and the ``FileSystem`` will report the state of its files and folders. This happens by recursively calling childrens' own ``describe_state`` methods. +``SimComponent`` in the simulation have a method called ``describe_state`` which returns a dictionary of the state of the component. This is used to report pertinent data that could impact agent's actions or rewards. For instance, the name and health status of a node is reported, which can be used by a reward function to punish corrupted or compromised nodes and reward healthy nodes. Each ``SimComponent`` reports not only it's own attributes in the state but also that of its child components. I.e. a computer node will report the state of its ``FileSystem``, and the ``FileSystem`` will report the state of its files and folders. This happens by recursively calling childrens' own ``describe_state`` methods. -The game layer calls ``describe_state`` on the trunk ``SimComponent`` (the top-level parent) and then pass the state to the agents once per simulation step. For this reason, all ``SimComponent``s must have a ``describe_state`` method, and they must all be linked to the trunk ``SimComponent``. +The game layer calls ``describe_state`` on the trunk ``SimComponent`` (the top-level parent) and then pass the state to the agents once per simulation step. For this reason, all ``SimComponent`` must have a ``describe_state`` method, and they must all be linked to the trunk ``SimComponent``. This code snippet demonstrates how the state information is defined within the ``SimComponent`` class: From 6ac7dcf9ac5e52ea07217b597def09a99683ae0e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 27 Oct 2023 11:48:22 +0100 Subject: [PATCH 262/980] Update README.md --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1c274a45..9ec8164e 100644 --- a/README.md +++ b/README.md @@ -18,17 +18,13 @@ PrimAITE presents the following features: - Provision of logging to support AI evaluation and metrics gathering; -- Uses the concept of Information Exchange Requirements (IERs) to model background pattern of life and adversarial behaviour; +- Realistic network traffic simulation, including address and sending packets via internet protocols like TCP, UDP, ICMP, and others -- An Access Control List (ACL) function, mimicking the behaviour of a network firewall, is applied across the model, following standard ACL rule format (e.g. DENY/ALLOW, source IP address, destination IP address, protocol and port); +- Routers with traffic routing and firewall capabilities -- Application of IERs to the platform / system laydown adheres to the ACL ruleset; +- Integration with ARCD GATE for agent training -- Presents an OpenAI gym or RLLib interface to the environment, allowing integration with any compliant defensive agents; - -- Full capture of discrete logs relating to agent training (full system state, agent actions taken, instantaneous and average reward for every step of every episode); - -- NetworkX provides laydown visualisation capability. +- Support for multiple agents, each having their own customisable observation space, action space, and reward function definition, and either deterministic or RL-directed behaviour ## Getting Started with PrimAITE @@ -50,6 +46,7 @@ python3 -m venv .venv attrib +h .venv /s /d # Hides the .venv directory .\.venv\Scripts\activate pip install https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/releases/download/v2.0.0/primaite-2.0.0-py3-none-any.whl +pip install GATE/arcd_gate-0.1.0-py3-none-any.whl primaite setup ``` @@ -78,6 +75,7 @@ cd ~/primaite python3 -m venv .venv source .venv/bin/activate pip install https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/releases/download/v2.0.0/primaite-2.0.0-py3-none-any.whl +pip install arcd_gate-0.1.0-py3-none-any.whl primaite setup ``` @@ -122,6 +120,7 @@ source venv/bin/activate ```bash python3 -m pip install -e .[dev] +pip install arcd_gate-0.1.0-py3-none-any.whl ``` #### 6. Perform the PrimAITE setup: From a06629ed0bc8648e34934a1f2028cced69494a46 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 27 Oct 2023 11:48:54 +0100 Subject: [PATCH 263/980] Bump version --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index 227cea21..a6f4248b 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -2.0.0 +3.0.0a1 From d4eb499729f21f524a33f76fcefdcb4524e8442b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 27 Oct 2023 12:20:23 +0100 Subject: [PATCH 264/980] Start fixing up cli and setup --- sandbox.py | 1 - src/primaite/cli.py | 58 ++------------------------------- src/primaite/config/__init__.py | 2 ++ src/primaite/config/load.py | 22 +++++++++++++ 4 files changed, 26 insertions(+), 57 deletions(-) create mode 100644 src/primaite/config/__init__.py create mode 100644 src/primaite/config/load.py diff --git a/sandbox.py b/sandbox.py index ab5e701f..c5c8ae38 100644 --- a/sandbox.py +++ b/sandbox.py @@ -6,7 +6,6 @@ from primaite.game.session import PrimaiteSession _PRIMAITE_CONFIG["log_level"] = logging.DEBUG print(PRIMAITE_PATHS.app_log_dir_path) -import itertools import yaml diff --git a/src/primaite/cli.py b/src/primaite/cli.py index 9bdc414d..ea0247ec 100644 --- a/src/primaite/cli.py +++ b/src/primaite/cli.py @@ -10,7 +10,6 @@ import yaml from typing_extensions import Annotated from primaite import PRIMAITE_PATHS -from primaite.data_viz import PlotlyTemplate app = typer.Typer() @@ -81,14 +80,6 @@ def log_level(level: Annotated[Optional[_LogLevel], typer.Argument()] = None) -> print(f"PrimAITE Log Level: {level}") -@app.command() -def notebooks() -> None: - """Start Jupyter Lab in the users PrimAITE notebooks directory.""" - from primaite.notebooks import start_jupyter_session - - start_jupyter_session() - - @app.command() def version() -> None: """Get the installed PrimAITE version number.""" @@ -97,14 +88,6 @@ def version() -> None: print(primaite.__version__) -@app.command() -def clean_up() -> None: - """Cleans up left over files from previous version installations.""" - from primaite.setup import old_installation_clean_up - - old_installation_clean_up.run() - - @app.command() def setup(overwrite_existing: bool = True) -> None: """ @@ -113,7 +96,7 @@ def setup(overwrite_existing: bool = True) -> None: WARNING: All user-data will be lost. """ from primaite import getLogger - from primaite.setup import old_installation_clean_up, reset_demo_notebooks, reset_example_configs + from primaite.setup import reset_demo_notebooks, reset_example_configs _LOGGER = getLogger(__name__) @@ -130,19 +113,12 @@ def setup(overwrite_existing: bool = True) -> None: _LOGGER.info("Rebuilding the example notebooks...") reset_example_configs.run(overwrite_existing=True) - _LOGGER.info("Performing a clean-up of previous PrimAITE installations...") - old_installation_clean_up.run() - _LOGGER.info("PrimAITE setup complete!") @app.command() def session( - tc: Optional[str] = None, - ldc: Optional[str] = None, - load: Optional[str] = None, - legacy_tc: bool = False, - legacy_ldc: bool = False, + config: Optional[str] = None, ) -> None: """ Run a PrimAITE session. @@ -165,13 +141,8 @@ def session( legacy_ldf: If the lay down config file is a legacy file from PrimAITE < 2.0. """ from primaite.config.lay_down_config import dos_very_basic_config_path - from primaite.config.training_config import main_training_config_path from primaite.main import run - if load is not None: - # run a loaded session - run(session_path=load) - else: # start a new session using tc and ldc if not tc: @@ -186,28 +157,3 @@ def session( legacy_training_config=legacy_tc, legacy_lay_down_config=legacy_ldc, ) - - -@app.command() -def plotly_template(template: Annotated[Optional[PlotlyTemplate], typer.Argument()] = None) -> None: - """ - View or set the plotly template for Session plots. - - To View, simply call: primaite plotly-template - - To set, call: primaite plotly-template - - For example, to set as plotly_dark, call: primaite plotly-template PLOTLY_DARK - """ - if PRIMAITE_PATHS.app_config_file_path.exists(): - with open(PRIMAITE_PATHS.app_config_file_path, "r") as file: - primaite_config = yaml.safe_load(file) - - if template: - primaite_config["session"]["outputs"]["plots"]["template"] = template.value - with open(PRIMAITE_PATHS.app_config_file_path, "w") as file: - yaml.dump(primaite_config, file) - print(f"PrimAITE plotly template: {template.value}") - else: - template = primaite_config["session"]["outputs"]["plots"]["template"] - print(f"PrimAITE plotly template: {template}") diff --git a/src/primaite/config/__init__.py b/src/primaite/config/__init__.py new file mode 100644 index 00000000..92f5a7d2 --- /dev/null +++ b/src/primaite/config/__init__.py @@ -0,0 +1,2 @@ +# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +"""Configuration parameters for running experiments.""" diff --git a/src/primaite/config/load.py b/src/primaite/config/load.py new file mode 100644 index 00000000..77b76299 --- /dev/null +++ b/src/primaite/config/load.py @@ -0,0 +1,22 @@ +from pathlib import Path +from typing import Union + +import yaml + +from primaite import getLogger + +_LOGGER = getLogger(__name__) + + +def load(file_path: Union[str, Path]) -> Dict: + """ + Read a YAML file and return the contents as a dictionary. + + :param file_path: Path to the YAML file. + :type file_path: Union[str, Path] + :return: Config dictionary + :rtype: Dict + """ + + if not isinstance(file_path, Path): + file_path = Path(file_path) From 1ec1b319e5208dbde18a53cc4430051d5bbd54fd Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 27 Oct 2023 12:24:22 +0100 Subject: [PATCH 265/980] Fix formatting in docs --- docs/source/request_system.rst | 2 +- .../simulation_components/system/database_client_server.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/request_system.rst b/docs/source/request_system.rst index 09e46380..cdaf2d99 100644 --- a/docs/source/request_system.rst +++ b/docs/source/request_system.rst @@ -5,7 +5,7 @@ Request System ============== -``SimComponent``s in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``RequestManager`` and ``RequestType``. +``SimComponent`` in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``RequestManager`` and ``RequestType``. Just like other aspects of SimComponent, the request typess are not managed centrally for the whole simulation, but instead they are dynamically created and updated based on the nodes, links, and other components that currently exist. This was achieved in the following way: diff --git a/docs/source/simulation_components/system/database_client_server.rst b/docs/source/simulation_components/system/database_client_server.rst index 32568477..53687f60 100644 --- a/docs/source/simulation_components/system/database_client_server.rst +++ b/docs/source/simulation_components/system/database_client_server.rst @@ -14,7 +14,7 @@ The ``DatabaseService`` provides a SQL database server simulation by extending t Key capabilities ^^^^^^^^^^^^^^^^ -- Initialises a SQLite database file in the ``Node``'s ``FileSystem`` upon creation. +- Initialises a SQLite database file in the ``Node`` 's ``FileSystem`` upon creation. - Handles connecting clients by maintaining a dictionary of connections mapped to session IDs. - Authenticates connections using a configurable password. - Executes SQL queries against the SQLite database. From b81c1739f8e632a0a3e4652e6d8c41aae8145995 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 27 Oct 2023 14:26:52 +0100 Subject: [PATCH 266/980] Fix CLI and Session to work with new classes --- src/primaite/cli.py | 42 ++++++------------- .../config/_package_data/example_config.yaml | 0 src/primaite/config/load.py | 29 +++++++++++-- src/primaite/exceptions.py | 6 --- src/primaite/main.py | 35 +++++----------- src/primaite/utils/start_gate_server.py | 11 ++++- 6 files changed, 58 insertions(+), 65 deletions(-) rename example_config.yaml => src/primaite/config/_package_data/example_config.yaml (100%) diff --git a/src/primaite/cli.py b/src/primaite/cli.py index ea0247ec..43b97022 100644 --- a/src/primaite/cli.py +++ b/src/primaite/cli.py @@ -123,37 +123,19 @@ def session( """ Run a PrimAITE session. - tc: The training config filepath. Optional. If no value is passed then - example default training config is used from: - ~/primaite/2.0.0/config/example_config/training/training_config_main.yaml. - - ldc: The lay down config file path. Optional. If no value is passed then - example default lay down config is used from: - ~/primaite/2.0.0/config/example_config/lay_down/lay_down_config_3_doc_very_basic.yaml. - - load: The directory of a previous session. Optional. If no value is passed, then the session - will use the default training config and laydown config. Inversely, if a training config and laydown config - is passed while a session directory is passed, PrimAITE will load the session and ignore the training config - and laydown config. - - legacy_tc: If the training config file is a legacy file from PrimAITE < 2.0. - - legacy_ldf: If the lay down config file is a legacy file from PrimAITE < 2.0. + :param config: The path to the config file. Optional, if None, the example config will be used. + :type config: Optional[str] """ - from primaite.config.lay_down_config import dos_very_basic_config_path + from threading import Thread + + from primaite.config.load import example_config_path from primaite.main import run + from primaite.utils.start_gate_server import start_gate_server - else: - # start a new session using tc and ldc - if not tc: - tc = main_training_config_path() + server_thread = Thread(target=start_gate_server) + server_thread.start() - if not ldc: - ldc = dos_very_basic_config_path() - - run( - training_config_path=tc, - lay_down_config_path=ldc, - legacy_training_config=legacy_tc, - legacy_lay_down_config=legacy_ldc, - ) + if not config: + config = example_config_path() + print(config) + run(config_path=config) diff --git a/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml similarity index 100% rename from example_config.yaml rename to src/primaite/config/_package_data/example_config.yaml diff --git a/src/primaite/config/load.py b/src/primaite/config/load.py index 77b76299..b01eb129 100644 --- a/src/primaite/config/load.py +++ b/src/primaite/config/load.py @@ -1,12 +1,14 @@ from pathlib import Path -from typing import Union +from typing import Dict, Final, Union import yaml -from primaite import getLogger +from primaite import getLogger, PRIMAITE_PATHS _LOGGER = getLogger(__name__) +_EXAMPLE_CFG: Final[Path] = PRIMAITE_PATHS.user_config_path / "example_config" + def load(file_path: Union[str, Path]) -> Dict: """ @@ -17,6 +19,27 @@ def load(file_path: Union[str, Path]) -> Dict: :return: Config dictionary :rtype: Dict """ - if not isinstance(file_path, Path): file_path = Path(file_path) + if not file_path.exists(): + _LOGGER.error(f"File does not exist: {file_path}") + raise FileNotFoundError(f"File does not exist: {file_path}") + with open(file_path, "r") as file: + config = yaml.safe_load(file) + _LOGGER.debug(f"Loaded config from {file_path}") + return config + + +def example_config_path() -> Path: + """ + Get the path to the example config. + + :return: Path to the example config. + :rtype: Path + """ + path = _EXAMPLE_CFG / "example_config.yaml" + if not path.exists(): + msg = f"Example config does not exist: {path}. Have you run `primaite setup`?" + _LOGGER.error(msg) + raise FileNotFoundError(msg) + return path diff --git a/src/primaite/exceptions.py b/src/primaite/exceptions.py index 025f6d41..6aa140ba 100644 --- a/src/primaite/exceptions.py +++ b/src/primaite/exceptions.py @@ -5,12 +5,6 @@ class PrimaiteError(Exception): pass -class RLlibAgentError(PrimaiteError): - """Raised when there is a generic error with a RLlib agent that is specific to PRimAITE.""" - - pass - - class NetworkError(PrimaiteError): """Raised when an error occurs at the network level.""" diff --git a/src/primaite/main.py b/src/primaite/main.py index 0cbcff0e..831419d4 100644 --- a/src/primaite/main.py +++ b/src/primaite/main.py @@ -5,6 +5,8 @@ from pathlib import Path from typing import Optional, Union from primaite import getLogger +from primaite.config.load import load +from primaite.game.session import PrimaiteSession # from primaite.primaite_session import PrimaiteSession @@ -12,11 +14,7 @@ _LOGGER = getLogger(__name__) def run( - training_config_path: Optional[Union[str, Path]] = "", - lay_down_config_path: Optional[Union[str, Path]] = "", - session_path: Optional[Union[str, Path]] = None, - legacy_training_config: bool = False, - legacy_lay_down_config: bool = False, + config_path: Optional[Union[str, Path]] = "", ) -> None: """ Run the PrimAITE Session. @@ -32,28 +30,17 @@ def run( :param legacy_lay_down_config: True if the lay_down config file is a legacy file from PrimAITE < 2.0, otherwise False. """ - # session = PrimaiteSession( - # training_config_path, lay_down_config_path, session_path, legacy_training_config, legacy_lay_down_config - # ) - - # session.setup() - # session.learn() - # session.evaluate() - return NotImplemented + cfg = load(config_path) + sess = PrimaiteSession.from_config(cfg=cfg) + sess.start_session() if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("--tc") - parser.add_argument("--ldc") - parser.add_argument("--load") + parser.add_argument("--config") args = parser.parse_args() - if args.load: - run(session_path=args.load) - else: - if not args.tc: - _LOGGER.error("Please provide a training config file using the --tc " "argument") - if not args.ldc: - _LOGGER.error("Please provide a lay down config file using the --ldc " "argument") - run(training_config_path=args.tc, lay_down_config_path=args.ldc) + if not args.config: + _LOGGER.error("Please provide a config file using the --config " "argument") + + run(session_path=args.config) diff --git a/src/primaite/utils/start_gate_server.py b/src/primaite/utils/start_gate_server.py index 53508cd2..d91952f2 100644 --- a/src/primaite/utils/start_gate_server.py +++ b/src/primaite/utils/start_gate_server.py @@ -1,5 +1,12 @@ """Utility script to start the gate server for running PrimAITE in attached mode.""" from arcd_gate.server.gate_service import GATEService -service = GATEService() -service.start() + +def start_gate_server(): + """Start the gate server.""" + service = GATEService() + service.start() + + +if __name__ == "__main__": + start_gate_server() From 75d1fd20c3967a8bf481d2fce319ca39fd74192b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 27 Oct 2023 14:41:53 +0100 Subject: [PATCH 267/980] Remove temporary files --- sandbox.py | 21 ------ src/primaite/notebooks/.gitkeep | 0 src/primaite/notebooks/scratch.ipynb | 107 --------------------------- 3 files changed, 128 deletions(-) delete mode 100644 sandbox.py create mode 100644 src/primaite/notebooks/.gitkeep delete mode 100644 src/primaite/notebooks/scratch.ipynb diff --git a/sandbox.py b/sandbox.py deleted file mode 100644 index c5c8ae38..00000000 --- a/sandbox.py +++ /dev/null @@ -1,21 +0,0 @@ -# flake8: noqa -import logging - -from primaite import _PRIMAITE_CONFIG, PRIMAITE_PATHS -from primaite.game.session import PrimaiteSession - -_PRIMAITE_CONFIG["log_level"] = logging.DEBUG -print(PRIMAITE_PATHS.app_log_dir_path) - -import yaml - -from primaite.game.agent.interface import AbstractAgent -from primaite.game.session import PrimaiteSession -from primaite.simulator.network.networks import arcd_uc2_network -from primaite.simulator.sim_container import Simulation - -with open("example_config.yaml", "r") as file: - cfg = yaml.safe_load(file) -sess = PrimaiteSession.from_config(cfg) - -sess.start_session() diff --git a/src/primaite/notebooks/.gitkeep b/src/primaite/notebooks/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/notebooks/scratch.ipynb b/src/primaite/notebooks/scratch.ipynb deleted file mode 100644 index 4e873460..00000000 --- a/src/primaite/notebooks/scratch.ipynb +++ /dev/null @@ -1,107 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from primaite.simulator.network.networks import arcd_uc2_network\n", - "%load_ext autoreload\n", - "%autoreload 2" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "net = arcd_uc2_network()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### set up some services to test if actions are working" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "db_serv = net.get_node_by_hostname('database_server')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from primaite.simulator.system.services.database_service import DatabaseService" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "db_svc = DatabaseService(file_system=db_serv.file_system)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "db_serv.install_service(db_svc)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "db_serv.describe_state()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "venv", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.12" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -} From a37ce051c5659a057176b0c7d3139dedcc0a42a9 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 27 Oct 2023 14:50:31 +0100 Subject: [PATCH 268/980] Add ARCD GATE setup to primaite setup --- src/primaite/cli.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/primaite/cli.py b/src/primaite/cli.py index 43b97022..a5b3be46 100644 --- a/src/primaite/cli.py +++ b/src/primaite/cli.py @@ -95,6 +95,8 @@ def setup(overwrite_existing: bool = True) -> None: WARNING: All user-data will be lost. """ + from arcd_gate.cli import setup as gate_setup + from primaite import getLogger from primaite.setup import reset_demo_notebooks, reset_example_configs @@ -113,6 +115,9 @@ def setup(overwrite_existing: bool = True) -> None: _LOGGER.info("Rebuilding the example notebooks...") reset_example_configs.run(overwrite_existing=True) + _LOGGER.info("Setting up ARCD GATE...") + gate_setup() + _LOGGER.info("PrimAITE setup complete!") From 68b22b6444bae2f46a172e4affe9083992960b5b Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Fri, 27 Oct 2023 17:50:41 +0100 Subject: [PATCH 269/980] #1961: node scanning + applying timestep to all components within node + node revealing to red --- .../simulator/file_system/file_system.py | 58 ++++++++++++-- .../simulator/network/hardware/base.py | 79 ++++++++++++++++++- .../system/applications/application.py | 8 +- src/primaite/simulator/system/software.py | 4 + tests/conftest.py | 18 ++++- .../_network/_hardware/test_node_actions.py | 67 ++++++++++++++-- 6 files changed, 216 insertions(+), 18 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index cddd276a..af76254d 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -84,6 +84,9 @@ class FileSystemItemABC(SimComponent): previous_hash: Optional[str] = None "Hash of the file contents or the description state" + revealed_to_red: bool = False + "If true, the folder/file has been revealed to the red agent." + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -121,6 +124,10 @@ class FileSystemItemABC(SimComponent): """ return convert_size(self.size) + def reveal_to_red(self): + """Reveals the folder/file to the red agent.""" + self.revealed_to_red = True + @abstractmethod def check_hash(self) -> bool: """ @@ -231,11 +238,24 @@ class FileSystem(SimComponent): state["folders"] = {folder.name: folder.describe_state() for folder in self.folders.values()} return state + def apply_timestep(self, timestep: int) -> None: + """Apply time step to FileSystem and its child folders and files.""" + super().apply_timestep(timestep=timestep) + + # apply timestep to folders + for folder_id in self.folders: + self.folders[folder_id].apply_timestep(timestep=timestep) + def scan(self): - """Scan all the folders and files in the file system.""" + """Scan all the folders (and child files) in the file system.""" for folder_id in self.folders: self.folders[folder_id].scan() + def reveal_to_red(self): + """Reveals all the folders (and child files) in the file system to the red agent.""" + for folder_id in self.folders: + self.folders[folder_id].reveal_to_red() + def create_folder(self, folder_name: str) -> Folder: """ Creates a Folder and adds it to the list of folders. @@ -449,6 +469,9 @@ class Folder(FileSystemItemABC): scan_duration: int = -1 "How many timesteps to complete a scan." + red_scan_duration: int = -1 + "How many timesteps to complete reveal to red scan." + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request( @@ -494,7 +517,7 @@ class Folder(FileSystemItemABC): def apply_timestep(self, timestep: int): """ - Apply a single timestep of simulation dynamics to this service. + Apply a single timestep of simulation dynamics to this folder and its files. In this instance, if any multi-timestep processes are currently occurring (such as scanning), then they are brought one step closer to being finished. @@ -505,14 +528,25 @@ class Folder(FileSystemItemABC): super().apply_timestep(timestep=timestep) # scan files each timestep - if self.scan_duration > -1: + if self.scan_duration >= 0: # scan one file per timestep - file = self.get_file_by_id(file_uuid=list(self.files)[self.scan_duration - 1]) + file = self.get_file_by_id(file_uuid=list(self.files)[self.scan_duration]) file.scan() if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: self.visible_health_status = FileSystemItemHealthStatus.CORRUPT self.scan_duration -= 1 + # red scan file at each step + if self.red_scan_duration >= 0: + # scan one file per timestep + file = self.get_file_by_id(file_uuid=list(self.files)[self.red_scan_duration]) + file.reveal_to_red() + self.red_scan_duration -= 1 + + # apply timestep to files in folder + for file_id in self.files: + self.files[file_id].apply_timestep(timestep=timestep) + def get_file(self, file_name: str) -> Optional[File]: """ Get a file by its name. @@ -609,14 +643,26 @@ class Folder(FileSystemItemABC): def scan(self) -> None: """Update Folder visible status.""" - if self.scan_duration <= -1: + if self.scan_duration <= 0: # scan one file per timestep - self.scan_duration = len(self.files) + self.scan_duration = len(self.files) - 1 self.fs.sys_log.info(f"Scanning folder {self.name} (id: {self.uuid})") else: # scan already in progress self.fs.sys_log.info(f"Scan is already in progress {self.name} (id: {self.uuid})") + def reveal_to_red(self): + """Reveals the folders and files to the red agent.""" + super().reveal_to_red() + + if self.red_scan_duration <= 0: + # scan one file per timestep + self.red_scan_duration = len(self.files) - 1 + self.fs.sys_log.info(f"Folder revealed to red agent: {self.name} (id: {self.uuid})") + else: + # scan already in progress + self.fs.sys_log.info(f"Red Agent Scan is already in progress {self.name} (id: {self.uuid})") + def check_hash(self) -> bool: """ Runs a :func:`check_hash` on all files in the folder. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 153a0a15..1858345b 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -978,7 +978,7 @@ class Node(SimComponent): self._application_request_manager = RequestManager() rm.add_request("application", RequestType(func=self._application_request_manager)) - rm.add_request("scan", RequestType(func=lambda request, context: self.scan(reveal_to_red=True))) + rm.add_request("scan", RequestType(func=lambda request, context: self.reveal_to_red())) rm.add_request("shutdown", RequestType(func=lambda request, context: self.power_off())) rm.add_request("startup", RequestType(func=lambda request, context: self.power_on())) @@ -1060,7 +1060,7 @@ class Node(SimComponent): def apply_timestep(self, timestep: int): """ - Apply a single timestep of simulation dynamics to this service. + Apply a single timestep of simulation dynamics to this node. In this instance, if any multi-timestep processes are currently occurring (such as starting up or shutting down), then they are brought one step closer to @@ -1090,7 +1090,20 @@ class Node(SimComponent): self.operating_state = NodeOperatingState.OFF self.sys_log.info("Turned off") - def scan(self): + # apply time step to node components + if self.operating_state == NodeOperatingState.ON: + for process_id in self.processes: + self.processes[process_id].apply_timestep(timestep=timestep) + + for service_id in self.services: + self.services[service_id].apply_timestep(timestep=timestep) + + for application_id in self.applications: + self.applications[application_id].apply_timestep(timestep=timestep) + + self.file_system.apply_timestep(timestep=timestep) + + def scan(self) -> None: """ Scan the node and all the items within it. @@ -1118,6 +1131,34 @@ class Node(SimComponent): # scan file system self.file_system.scan() + def reveal_to_red(self) -> None: + """ + Reveals the node and all the items within it to the red agent. + + Set all the: + - Processes + - Services + - Applications + - Folders + - Files + + `revealed_to_red` to `True`. + """ + # scan processes + for process_id in self.processes: + self.processes[process_id].reveal_to_red() + + # scan services + for service_id in self.services: + self.services[service_id].reveal_to_red() + + # scan applications + for application_id in self.applications: + self.applications[application_id].reveal_to_red() + + # scan file system + self.file_system.reveal_to_red() + def power_on(self): """Power on the Node, enabling its NICs if it is in the OFF state.""" if self.operating_state == NodeOperatingState.OFF: @@ -1299,6 +1340,38 @@ class Node(SimComponent): _LOGGER.info(f"Removed service {service.uuid} from node {self.uuid}") self._service_request_manager.remove_request(service.uuid) + def install_application(self, application: Application) -> None: + """ + Install an application on this node. + + :param application: Application instance that has not been installed on any node yet. + :type application: Application + """ + if application in self: + _LOGGER.warning(f"Can't add application {application.uuid} to node {self.uuid}. It's already installed.") + return + self.applications[application.uuid] = application + application.parent = self + self.sys_log.info(f"Installed application {application.name}") + _LOGGER.info(f"Added application {application.uuid} to node {self.uuid}") + self._application_request_manager.add_request(application.uuid, RequestType(func=application._request_manager)) + + def uninstall_application(self, application: Application) -> None: + """ + Uninstall and completely remove application from this node. + + :param application: Application object that is currently associated with this node. + :type application: Application + """ + if application not in self: + _LOGGER.warning(f"Can't remove application {application.uuid} from node {self.uuid}. It's not installed.") + return + self.applications.pop(application.uuid) + application.parent = None + self.sys_log.info(f"Uninstalled application {application.name}") + _LOGGER.info(f"Removed application {application.uuid} from node {self.uuid}") + self._application_request_manager.remove_request(application.uuid) + def __contains__(self, item: Any) -> bool: if isinstance(item, Service): return item.uuid in self.services diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 69b64aac..893e8c3a 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -2,7 +2,7 @@ from abc import abstractmethod from enum import Enum from typing import Any, Dict, Set -from primaite.simulator.system.software import IOSoftware +from primaite.simulator.system.software import IOSoftware, SoftwareHealthState class ApplicationOperatingState(Enum): @@ -32,6 +32,12 @@ class Application(IOSoftware): groups: Set[str] = set() "The set of groups to which the application belongs." + def __init__(self, **kwargs): + super().__init__(**kwargs) + + self.health_state_visible = SoftwareHealthState.UNUSED + self.health_state_actual = SoftwareHealthState.UNUSED + @abstractmethod def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index cfc0e56f..7527ea40 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -177,6 +177,10 @@ class Software(SimComponent): """Update the observed health status to match the actual health status.""" self.health_state_visible = self.health_state_actual + def reveal_to_red(self) -> None: + """Reveals the software to the red agent.""" + self.revealed_to_red = True + class IOSoftware(Software): """ diff --git a/tests/conftest.py b/tests/conftest.py index d8c9cc50..851a3514 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,9 +4,10 @@ import shutil import tempfile from datetime import datetime from pathlib import Path -from typing import Any, Union +from typing import Any, Dict, Union from unittest.mock import patch +import nodeenv import pytest from primaite import getLogger @@ -15,6 +16,7 @@ from primaite.primaite_session import PrimaiteSession from primaite.simulator.network.container import Network from primaite.simulator.network.networks import arcd_uc2_network from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import Application from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.services.service import Service from tests.mock_and_patch.get_session_path_mock import get_temp_session_path @@ -36,6 +38,13 @@ class TestService(Service): pass +class TestApplication(Application): + """Test Application class""" + + def describe_state(self) -> Dict: + pass + + @pytest.fixture(scope="function") def uc2_network() -> Network: return arcd_uc2_network() @@ -48,6 +57,13 @@ def service(file_system) -> TestService: ) +@pytest.fixture(scope="function") +def application(file_system) -> TestApplication: + return TestApplication( + name="TestApplication", port=Port.ARP, file_system=file_system, sys_log=SysLog(hostname="test_application") + ) + + @pytest.fixture(scope="function") def file_system() -> FileSystem: return Node(hostname="fs_node").file_system diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py index de4e0745..f886b8fe 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py @@ -1,6 +1,8 @@ import pytest +from primaite.simulator.file_system.file_system import File, FileSystemItemHealthStatus, Folder from primaite.simulator.network.hardware.base import Node, NodeOperatingState +from primaite.simulator.system.applications.application import Application from primaite.simulator.system.processes.process import Process from primaite.simulator.system.services.service import Service from primaite.simulator.system.software import SoftwareHealthState @@ -44,21 +46,31 @@ def test_node_shutdown(node): assert node.operating_state == NodeOperatingState.OFF -def test_node_os_scan(node): +def test_node_os_scan(node, service, application): """Test OS Scanning.""" + node.operating_state = NodeOperatingState.ON + # add process to node - node.processes["process"] = Process(name="process") - node.processes["process"].health_state_actual = SoftwareHealthState.COMPROMISED - assert node.processes["process"].health_state_visible == SoftwareHealthState.GOOD + # TODO implement processes # add services to node - service = Service(name="service") service.health_state_actual = SoftwareHealthState.COMPROMISED node.install_service(service=service) + assert service.health_state_visible == SoftwareHealthState.UNUSED # add application to node + application.health_state_actual = SoftwareHealthState.COMPROMISED + node.install_application(application=application) + assert application.health_state_visible == SoftwareHealthState.UNUSED - # add file to node + # add folder and file to node + folder: Folder = node.file_system.create_folder(folder_name="test_folder") + folder.corrupt() + assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD + + file: File = node.file_system.create_file(folder_name="test_folder", file_name="file.txt") + file.corrupt() + assert file.visible_health_status == FileSystemItemHealthStatus.GOOD # run os scan node.apply_request(["os", "scan"]) @@ -68,5 +80,46 @@ def test_node_os_scan(node): node.apply_timestep(timestep=i) # should update the state of all items - assert node.processes["process"].health_state_visible == SoftwareHealthState.COMPROMISED + # TODO assert process.health_state_visible == SoftwareHealthState.COMPROMISED assert service.health_state_visible == SoftwareHealthState.COMPROMISED + assert application.health_state_visible == SoftwareHealthState.COMPROMISED + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_node_red_scan(node, service, application): + """Test revealing to red""" + node.operating_state = NodeOperatingState.ON + + # add process to node + # TODO implement processes + + # add services to node + node.install_service(service=service) + assert service.revealed_to_red is False + + # add application to node + application.health_state_actual = SoftwareHealthState.COMPROMISED + node.install_application(application=application) + assert application.revealed_to_red is False + + # add folder and file to node + folder: Folder = node.file_system.create_folder(folder_name="test_folder") + assert folder.revealed_to_red is False + + file: File = node.file_system.create_file(folder_name="test_folder", file_name="file.txt") + assert file.revealed_to_red is False + + # run os scan + node.apply_request(["scan"]) + + # apply time steps + for i in range(20): + node.apply_timestep(timestep=i) + + # should update the state of all items + # TODO assert process.revealed_to_red is True + assert service.revealed_to_red is True + assert application.revealed_to_red is True + assert folder.revealed_to_red is True + assert file.revealed_to_red is True From 1ddf400d6f37b903c031607c9f83ad1f56957f31 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Fri, 27 Oct 2023 18:28:34 +0100 Subject: [PATCH 270/980] #1961: node resetting --- .../simulator/network/hardware/base.py | 24 +++++++++++++++++- .../_network/_hardware/test_node_actions.py | 25 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 1858345b..945eb345 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -926,6 +926,9 @@ class Node(SimComponent): shut_down_countdown: int = 0 "Time steps needed until node is shut down." + is_resetting: bool = False + "If true, the node will try turning itself off then back on again." + def __init__(self, **kwargs): """ Initialize the Node with various components and managers. @@ -982,7 +985,7 @@ class Node(SimComponent): rm.add_request("shutdown", RequestType(func=lambda request, context: self.power_off())) rm.add_request("startup", RequestType(func=lambda request, context: self.power_on())) - rm.add_request("reset", RequestType(func=lambda request, context: ...)) # TODO implement node reset + rm.add_request("reset", RequestType(func=lambda request, context: self.reset())) # TODO implement node reset rm.add_request("logon", RequestType(func=lambda request, context: ...)) # TODO implement logon request rm.add_request("logoff", RequestType(func=lambda request, context: ...)) # TODO implement logoff request @@ -1090,6 +1093,11 @@ class Node(SimComponent): self.operating_state = NodeOperatingState.OFF self.sys_log.info("Turned off") + # if resetting turn back on + if self.is_resetting: + self.is_resetting = False + self.power_on() + # apply time step to node components if self.operating_state == NodeOperatingState.ON: for process_id in self.processes: @@ -1184,6 +1192,20 @@ class Node(SimComponent): self.operating_state = NodeOperatingState.OFF self.sys_log.info("Turned off") + def reset(self): + """ + Resets the node. + + Powers off the node and sets is_resetting to True. + Applying more timesteps will eventually turn the node back on. + """ + if not self.operating_state.ON: + self.sys_log.error(f"Cannot reset {self.hostname} - node is not turned on.") + else: + self.is_resetting = True + self.sys_log.info(f"Resetting {self.hostname}...") + self.power_off() + def connect_nic(self, nic: NIC): """ Connect a NIC (Network Interface Card) to the node. diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py index f886b8fe..6161bbf6 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py @@ -123,3 +123,28 @@ def test_node_red_scan(node, service, application): assert application.revealed_to_red is True assert folder.revealed_to_red is True assert file.revealed_to_red is True + + +def test_reset_node(node): + """Test that a node can be reset.""" + node.operating_state = NodeOperatingState.ON + + node.apply_request(["reset"]) + assert node.operating_state == NodeOperatingState.SHUTTING_DOWN + + """ + 3 steps to shut down + 2 steps to set up the turning of it back on + 3 steps to turn back on + + 3 + 2 + 3 = 8 + kwik mafs + """ + + for i in range(8): + node.apply_timestep(timestep=i) + + if i == 3: + assert node.operating_state == NodeOperatingState.BOOTING + + assert node.operating_state == NodeOperatingState.ON From 98ca33e9949e5d47fc3f9564a10ea7dd47a7cac0 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Mon, 30 Oct 2023 15:34:13 +0000 Subject: [PATCH 271/980] #1961: scanning no longer happens every timestep - the scan is all done in one timestep after the required timestep countdown is complete --- .../simulator/file_system/file_system.py | 87 +++++++++++++------ .../simulator/network/hardware/base.py | 80 ++++++++++------- .../_file_system/test_file_system.py | 35 ++++++-- .../_file_system/test_file_system_actions.py | 11 +-- .../_network/_hardware/test_node_actions.py | 10 ++- 5 files changed, 150 insertions(+), 73 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index af76254d..4ffe6a6d 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -98,6 +98,7 @@ class FileSystemItemABC(SimComponent): state["status"] = self.health_status.name state["visible_status"] = self.visible_health_status.name state["previous_hash"] = self.previous_hash + state["revealed_to_red"] = self.revealed_to_red return state def _init_request_manager(self) -> RequestManager: @@ -124,10 +125,6 @@ class FileSystemItemABC(SimComponent): """ return convert_size(self.size) - def reveal_to_red(self): - """Reveals the folder/file to the red agent.""" - self.revealed_to_red = True - @abstractmethod def check_hash(self) -> bool: """ @@ -246,15 +243,23 @@ class FileSystem(SimComponent): for folder_id in self.folders: self.folders[folder_id].apply_timestep(timestep=timestep) - def scan(self): - """Scan all the folders (and child files) in the file system.""" - for folder_id in self.folders: - self.folders[folder_id].scan() + def scan(self, instant_scan: bool = False): + """ + Scan all the folders (and child files) in the file system. - def reveal_to_red(self): - """Reveals all the folders (and child files) in the file system to the red agent.""" + :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. + """ for folder_id in self.folders: - self.folders[folder_id].reveal_to_red() + self.folders[folder_id].scan(instant_scan=instant_scan) + + def reveal_to_red(self, instant_scan: bool = False): + """ + Reveals all the folders (and child files) in the file system to the red agent. + + :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. + """ + for folder_id in self.folders: + self.folders[folder_id].reveal_to_red(instant_scan=instant_scan) def create_folder(self, folder_name: str) -> Folder: """ @@ -529,20 +534,25 @@ class Folder(FileSystemItemABC): # scan files each timestep if self.scan_duration >= 0: - # scan one file per timestep - file = self.get_file_by_id(file_uuid=list(self.files)[self.scan_duration]) - file.scan() - if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: - self.visible_health_status = FileSystemItemHealthStatus.CORRUPT self.scan_duration -= 1 + if self.scan_duration == 0: + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + file.scan() + if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: + self.visible_health_status = FileSystemItemHealthStatus.CORRUPT + # red scan file at each step if self.red_scan_duration >= 0: - # scan one file per timestep - file = self.get_file_by_id(file_uuid=list(self.files)[self.red_scan_duration]) - file.reveal_to_red() self.red_scan_duration -= 1 + if self.red_scan_duration == 0: + self.revealed_to_red = True + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + file.reveal_to_red() + # apply timestep to files in folder for file_id in self.files: self.files[file_id].apply_timestep(timestep=timestep) @@ -641,23 +651,44 @@ class Folder(FileSystemItemABC): """Returns true if the folder is being quarantined.""" pass - def scan(self) -> None: - """Update Folder visible status.""" + def scan(self, instant_scan: bool = False) -> None: + """ + Update Folder visible status. + + :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. + """ + if instant_scan: + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + file.scan() + if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: + self.visible_health_status = FileSystemItemHealthStatus.CORRUPT + return + if self.scan_duration <= 0: # scan one file per timestep - self.scan_duration = len(self.files) - 1 + self.scan_duration = len(self.files) self.fs.sys_log.info(f"Scanning folder {self.name} (id: {self.uuid})") else: # scan already in progress self.fs.sys_log.info(f"Scan is already in progress {self.name} (id: {self.uuid})") - def reveal_to_red(self): - """Reveals the folders and files to the red agent.""" - super().reveal_to_red() + def reveal_to_red(self, instant_scan: bool = False): + """ + Reveals the folders and files to the red agent. + + :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. + """ + if instant_scan: + self.revealed_to_red = True + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + file.reveal_to_red() + return if self.red_scan_duration <= 0: # scan one file per timestep - self.red_scan_duration = len(self.files) - 1 + self.red_scan_duration = len(self.files) self.fs.sys_log.info(f"Folder revealed to red agent: {self.name} (id: {self.uuid})") else: # scan already in progress @@ -830,6 +861,10 @@ class File(FileSystemItemABC): self.folder.fs.sys_log.info(f"Scanning file {self.sim_path if self.sim_path else path}") self.visible_health_status = self.health_status + def reveal_to_red(self): + """Reveals the folder/file to the red agent.""" + self.revealed_to_red = True + def check_hash(self) -> bool: """ Check if the file has been changed. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 945eb345..9dc1a2ff 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -929,6 +929,15 @@ class Node(SimComponent): is_resetting: bool = False "If true, the node will try turning itself off then back on again." + node_scan_duration: int = 10 + "How many timesteps until the whole node is scanned. Default 10 time steps." + + node_scan_countdown: int = 0 + "Time steps until scan is complete" + + red_scan_countdown: int = 0 + "Time steps until reveal to red scan is complete." + def __init__(self, **kwargs): """ Initialize the Node with various components and managers. @@ -1098,8 +1107,47 @@ class Node(SimComponent): self.is_resetting = False self.power_on() - # apply time step to node components + # time steps which require the node to be on if self.operating_state == NodeOperatingState.ON: + # node scanning + if self.node_scan_countdown > 0: + self.node_scan_countdown -= 1 + + if self.node_scan_countdown == 0: + # scan everything! + for process_id in self.processes: + self.processes[process_id].scan() + + # scan services + for service_id in self.services: + self.services[service_id].scan() + + # scan applications + for application_id in self.applications: + self.applications[application_id].scan() + + # scan file system + self.file_system.scan(instant_scan=True) + + if self.red_scan_countdown > 0: + self.red_scan_countdown -= 1 + + if self.red_scan_countdown == 0: + # scan processes + for process_id in self.processes: + self.processes[process_id].reveal_to_red() + + # scan services + for service_id in self.services: + self.services[service_id].reveal_to_red() + + # scan applications + for application_id in self.applications: + self.applications[application_id].reveal_to_red() + + # scan file system + self.file_system.reveal_to_red(instant_scan=True) + for process_id in self.processes: self.processes[process_id].apply_timestep(timestep=timestep) @@ -1124,20 +1172,7 @@ class Node(SimComponent): to the red agent. """ - # scan processes - for process_id in self.processes: - self.processes[process_id].scan() - - # scan services - for service_id in self.services: - self.services[service_id].scan() - - # scan applications - for application_id in self.applications: - self.applications[application_id].scan() - - # scan file system - self.file_system.scan() + self.node_scan_countdown = self.node_scan_duration def reveal_to_red(self) -> None: """ @@ -1152,20 +1187,7 @@ class Node(SimComponent): `revealed_to_red` to `True`. """ - # scan processes - for process_id in self.processes: - self.processes[process_id].reveal_to_red() - - # scan services - for service_id in self.services: - self.services[service_id].reveal_to_red() - - # scan applications - for application_id in self.applications: - self.applications[application_id].reveal_to_red() - - # scan file system - self.file_system.reveal_to_red() + self.red_scan_countdown = self.node_scan_duration def power_on(self): """Power on the Node, enabling its NICs if it is in the OFF state.""" diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 2404f30d..12d9b94c 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -215,8 +215,8 @@ def test_folder_scan(file_system): folder.apply_timestep(timestep=0) assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT - assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD folder.apply_timestep(timestep=1) @@ -226,12 +226,33 @@ def test_folder_scan(file_system): assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT - folder.apply_timestep(timestep=2) - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT - assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT - assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT +def test_folder_reveal_to_red_scan(file_system): + """Test the ability to reveal files to red.""" + folder: Folder = file_system.create_folder(folder_name="test_folder") + file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + file_system.create_file(file_name="test_file2.txt", folder_name="test_folder") + + file1: File = folder.get_file_by_id(file_uuid=list(folder.files)[1]) + file2: File = folder.get_file_by_id(file_uuid=list(folder.files)[0]) + + assert folder.revealed_to_red is False + assert file1.revealed_to_red is False + assert file2.revealed_to_red is False + + folder.reveal_to_red() + + folder.apply_timestep(timestep=0) + + assert folder.revealed_to_red is False + assert file1.revealed_to_red is False + assert file2.revealed_to_red is False + + folder.apply_timestep(timestep=1) + + assert folder.revealed_to_red is True + assert file1.revealed_to_red is True + assert file2.revealed_to_red is True def test_simulated_file_check_hash(file_system): diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py index 23115fd7..abfb244a 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py @@ -47,8 +47,8 @@ def test_folder_scan_request(populated_file_system): folder.apply_timestep(timestep=0) assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT - assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD folder.apply_timestep(timestep=1) @@ -58,13 +58,6 @@ def test_folder_scan_request(populated_file_system): assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT - folder.apply_timestep(timestep=2) - - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT - assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT - assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT - def test_file_checkhash_request(populated_file_system): """Test that an agent can request a file hash check.""" diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py index 6161bbf6..3d6eea3b 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py @@ -69,14 +69,16 @@ def test_node_os_scan(node, service, application): assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD file: File = node.file_system.create_file(folder_name="test_folder", file_name="file.txt") + file2: File = node.file_system.create_file(folder_name="test_folder", file_name="file2.txt") file.corrupt() + file2.corrupt() assert file.visible_health_status == FileSystemItemHealthStatus.GOOD # run os scan node.apply_request(["os", "scan"]) # apply time steps - for i in range(20): + for i in range(10): node.apply_timestep(timestep=i) # should update the state of all items @@ -85,6 +87,7 @@ def test_node_os_scan(node, service, application): assert application.health_state_visible == SoftwareHealthState.COMPROMISED assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT def test_node_red_scan(node, service, application): @@ -108,13 +111,15 @@ def test_node_red_scan(node, service, application): assert folder.revealed_to_red is False file: File = node.file_system.create_file(folder_name="test_folder", file_name="file.txt") + file2: File = node.file_system.create_file(folder_name="test_folder", file_name="file2.txt") assert file.revealed_to_red is False + assert file2.revealed_to_red is False # run os scan node.apply_request(["scan"]) # apply time steps - for i in range(20): + for i in range(10): node.apply_timestep(timestep=i) # should update the state of all items @@ -123,6 +128,7 @@ def test_node_red_scan(node, service, application): assert application.revealed_to_red is True assert folder.revealed_to_red is True assert file.revealed_to_red is True + assert file2.revealed_to_red is True def test_reset_node(node): From 11848aa18018c5895ebadfcb6859b1b2025c8b52 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 31 Oct 2023 15:52:44 +0000 Subject: [PATCH 272/980] #1962: keeping track of deleted files --- .../simulator/file_system/file_system.py | 55 +++++++++++++++---- .../_file_system/test_file_system.py | 3 + 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 4ffe6a6d..14a4cf6e 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -154,7 +154,8 @@ class FileSystemItemABC(SimComponent): """ pass - def restore(self) -> None: + @abstractmethod + def restore(self) -> bool: """Restore the file/folder to the state before it got ruined.""" pass @@ -164,6 +165,8 @@ class FileSystem(SimComponent): folders: Dict[str, Folder] = {} "List containing all the folders in the file system." + deleted_folders: Dict[str, Folder] = {} + "List containing all the folders that have been deleted." _folders_by_name: Dict[str, Folder] = {} sys_log: SysLog sim_root: Path @@ -296,9 +299,11 @@ class FileSystem(SimComponent): self.folders.pop(folder.uuid) self._folders_by_name.pop(folder.name) self.sys_log.info(f"Deleted folder /{folder.name} and its contents") - self._folder_request_manager.remove_request(folder.uuid) + + # add to deleted list folder.remove_all_files() + self.deleted_folders[folder.uuid] = folder else: _LOGGER.debug(f"Cannot delete folder as it does not exist: {folder_name}") @@ -381,8 +386,6 @@ class FileSystem(SimComponent): file = folder.get_file(file_name) if file: folder.remove_file(file) - self._file_request_manager.remove_request(file.uuid) - self.sys_log.info(f"Deleted file /{file.path}") def move_file(self, src_folder_name: str, src_file_name: str, dst_folder_name: str): """ @@ -470,6 +473,8 @@ class Folder(FileSystemItemABC): "Files stored in the folder." _files_by_name: Dict[str, File] = {} "Files by their name as .." + deleted_files: Dict[str, File] = {} + "Files that have been deleted." scan_duration: int = -1 "How many timesteps to complete a scan." @@ -612,6 +617,8 @@ class Folder(FileSystemItemABC): if self.files.get(file.uuid): self.files.pop(file.uuid) self._files_by_name.pop(file.name) + self.deleted_files[file.uuid] = file + self.fs.sys_log.info(f"Removed file {file.name} (id: {file.uuid})") else: _LOGGER.debug(f"File with UUID {file.uuid} was not found.") @@ -626,6 +633,9 @@ class Folder(FileSystemItemABC): def remove_all_files(self): """Removes all the files in the folder.""" + for file_id in self.files: + self.deleted_files[file_id] = self.files[file_id] + self.files = {} self._files_by_name = {} @@ -635,7 +645,7 @@ class Folder(FileSystemItemABC): The method can take a File object or a file id. - :param file: The file to remove + :param file: The file to restore """ pass @@ -741,9 +751,24 @@ class Folder(FileSystemItemABC): self.fs.sys_log.info(f"Repaired folder {self.name} (id: {self.uuid})") return repaired - def restore(self) -> None: - """TODO.""" - pass + def restore(self) -> bool: + """Restore a File by setting the folder and containing files status to FileSystemItemStatus.GOOD.""" + super().restore() + + restored = False + + # iterate through the files in the folder + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + restored = file.restore() + + # set file status to corrupt if good + if self.health_status == FileSystemItemHealthStatus.CORRUPT: + self.health_status = FileSystemItemHealthStatus.GOOD + restored = True + + self.fs.sys_log.info(f"Restored folder {self.name} (id: {self.uuid})") + return restored def corrupt(self) -> bool: """Corrupt a File by setting the folder and containing files status to FileSystemItemStatus.CORRUPT.""" @@ -910,9 +935,19 @@ class File(FileSystemItemABC): self.folder.fs.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") return True - def restore(self) -> None: + def restore(self) -> bool: """Restore a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" - pass + super().restore() + + restored = False + + if self.health_status == FileSystemItemHealthStatus.CORRUPT: + self.health_status = FileSystemItemHealthStatus.GOOD + restored = True + + path = self.folder.name + "/" + self.name + self.folder.fs.sys_log.info(f"Restored file {self.sim_path if self.sim_path else path}") + return restored def corrupt(self) -> bool: """Corrupt a File by setting the status to FileSystemItemStatus.CORRUPT.""" diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 12d9b94c..cb398ca9 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -44,6 +44,7 @@ def test_delete_file(file_system): file_system.delete_file(folder_name="root", file_name="test_file.txt") assert len(file_system.folders) == 1 assert len(file_system.get_folder("root").files) == 0 + assert len(file_system.get_folder("root").deleted_files) == 1 def test_delete_non_existent_file(file_system): @@ -70,6 +71,8 @@ def test_delete_folder(file_system): file_system.delete_folder(folder_name="test_folder") assert len(file_system.folders) == 1 + assert len(file_system.deleted_folders) == 1 + def test_deleting_a_non_existent_folder(file_system): file_system.create_folder(folder_name="test_folder") From b67eb1bb3406a03186a62cfb3076890419f86dd8 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Thu, 2 Nov 2023 13:14:08 +0000 Subject: [PATCH 273/980] #1962: separating file system into more managable files --- .../simulator/file_system/file_system.py | 144 +---------------- .../file_system/file_system_item_abc.py | 151 ++++++++++++++++++ 2 files changed, 152 insertions(+), 143 deletions(-) create mode 100644 src/primaite/simulator/file_system/file_system_item_abc.py diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 14a4cf6e..02f3c5e6 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -2,11 +2,8 @@ from __future__ import annotations import hashlib import json -import math import os.path import shutil -from abc import abstractmethod -from enum import Enum from pathlib import Path from typing import Dict, Optional @@ -14,152 +11,13 @@ from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType, SimComponent +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC, FileSystemItemHealthStatus from primaite.simulator.file_system.file_type import FileType, get_file_type_from_extension from primaite.simulator.system.core.sys_log import SysLog _LOGGER = getLogger(__name__) -def convert_size(size_bytes: int) -> str: - """ - Convert a file size from bytes to a string with a more human-readable format. - - This function takes the size of a file in bytes and converts it to a string representation with appropriate size - units (B, KB, MB, GB, etc.). - - :param size_bytes: The size of the file in bytes. - :return: The human-readable string representation of the file size. - """ - if size_bytes == 0: - return "0 B" - - # Tuple of size units starting from Bytes up to Yottabytes - size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") - - # Calculate the index (i) that will be used to select the appropriate size unit from size_name - i = int(math.floor(math.log(size_bytes, 1024))) - - # Calculate the adjusted size value (s) in terms of the new size unit - p = math.pow(1024, i) - s = round(size_bytes / p, 2) - - return f"{s} {size_name[i]}" - - -class FileSystemItemHealthStatus(Enum): - """Status of the FileSystemItem.""" - - GOOD = 0 - """File/Folder is OK.""" - - COMPROMISED = 1 - """File/Folder is quarantined.""" - - CORRUPT = 2 - """File/Folder is corrupted.""" - - RESTORING = 3 - """File/Folder is in the process of being restored.""" - - REPAIRING = 3 - """File/Folder is in the process of being repaired.""" - - -class FileSystemItemABC(SimComponent): - """ - Abstract base class for file system items used in the file system simulation. - - :ivar name: The name of the FileSystemItemABC. - """ - - name: str - "The name of the FileSystemItemABC." - - health_status: FileSystemItemHealthStatus = FileSystemItemHealthStatus.GOOD - "Actual status of the current FileSystemItem" - - visible_health_status: FileSystemItemHealthStatus = FileSystemItemHealthStatus.GOOD - "Visible status of the current FileSystemItem" - - previous_hash: Optional[str] = None - "Hash of the file contents or the description state" - - revealed_to_red: bool = False - "If true, the folder/file has been revealed to the red agent." - - def describe_state(self) -> Dict: - """ - Produce a dictionary describing the current state of this object. - - :return: Current state of this object and child objects. - """ - state = super().describe_state() - state["name"] = self.name - state["status"] = self.health_status.name - state["visible_status"] = self.visible_health_status.name - state["previous_hash"] = self.previous_hash - state["revealed_to_red"] = self.revealed_to_red - return state - - def _init_request_manager(self) -> RequestManager: - rm = super()._init_request_manager() - - rm.add_request(name="scan", request_type=RequestType(func=lambda request, context: self.scan())) - rm.add_request(name="checkhash", request_type=RequestType(func=lambda request, context: self.check_hash())) - rm.add_request(name="repair", request_type=RequestType(func=lambda request, context: self.repair())) - rm.add_request(name="restore", request_type=RequestType(func=lambda request, context: self.restore())) - - rm.add_request(name="corrupt", request_type=RequestType(func=lambda request, context: self.corrupt())) - - return rm - - @property - def size_str(self) -> str: - """ - Get the file size in a human-readable string format. - - This property makes use of the :func:`convert_size` function to convert the `self.size` attribute to a string - that is easier to read and understand. - - :return: The human-readable string representation of the file size. - """ - return convert_size(self.size) - - @abstractmethod - def check_hash(self) -> bool: - """ - Checks the has of the file to detect any changes. - - For current implementation, any change in file hash means it is compromised. - - Return False if corruption is detected, otherwise True - """ - pass - - @abstractmethod - def repair(self) -> bool: - """ - Repair the FileSystemItem. - - True if successfully repaired. False otherwise. - """ - pass - - @abstractmethod - def corrupt(self) -> bool: - """ - Corrupt the FileSystemItem. - - True if successfully corrupted. False otherwise. - """ - pass - - @abstractmethod - def restore(self) -> bool: - """Restore the file/folder to the state before it got ruined.""" - pass - - class FileSystem(SimComponent): """Class that contains all the simulation File System.""" diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py new file mode 100644 index 00000000..8f61c718 --- /dev/null +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -0,0 +1,151 @@ +from __future__ import annotations + +import math +from abc import abstractmethod +from enum import Enum +from typing import Dict, Optional + +from primaite import getLogger +from primaite.simulator.core import RequestManager, RequestType, SimComponent + +_LOGGER = getLogger(__name__) + + +def convert_size(size_bytes: int) -> str: + """ + Convert a file size from bytes to a string with a more human-readable format. + + This function takes the size of a file in bytes and converts it to a string representation with appropriate size + units (B, KB, MB, GB, etc.). + + :param size_bytes: The size of the file in bytes. + :return: The human-readable string representation of the file size. + """ + if size_bytes == 0: + return "0 B" + + # Tuple of size units starting from Bytes up to Yottabytes + size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") + + # Calculate the index (i) that will be used to select the appropriate size unit from size_name + i = int(math.floor(math.log(size_bytes, 1024))) + + # Calculate the adjusted size value (s) in terms of the new size unit + p = math.pow(1024, i) + s = round(size_bytes / p, 2) + + return f"{s} {size_name[i]}" + + +class FileSystemItemHealthStatus(Enum): + """Status of the FileSystemItem.""" + + GOOD = 0 + """File/Folder is OK.""" + + COMPROMISED = 1 + """File/Folder is quarantined.""" + + CORRUPT = 2 + """File/Folder is corrupted.""" + + RESTORING = 3 + """File/Folder is in the process of being restored.""" + + REPAIRING = 3 + """File/Folder is in the process of being repaired.""" + + +class FileSystemItemABC(SimComponent): + """ + Abstract base class for file system items used in the file system simulation. + + :ivar name: The name of the FileSystemItemABC. + """ + + name: str + "The name of the FileSystemItemABC." + + health_status: FileSystemItemHealthStatus = FileSystemItemHealthStatus.GOOD + "Actual status of the current FileSystemItem" + + visible_health_status: FileSystemItemHealthStatus = FileSystemItemHealthStatus.GOOD + "Visible status of the current FileSystemItem" + + previous_hash: Optional[str] = None + "Hash of the file contents or the description state" + + revealed_to_red: bool = False + "If true, the folder/file has been revealed to the red agent." + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + """ + state = super().describe_state() + state["name"] = self.name + state["status"] = self.health_status.name + state["visible_status"] = self.visible_health_status.name + state["previous_hash"] = self.previous_hash + state["revealed_to_red"] = self.revealed_to_red + return state + + def _init_request_manager(self) -> RequestManager: + rm = super()._init_request_manager() + + rm.add_request(name="scan", request_type=RequestType(func=lambda request, context: self.scan())) + rm.add_request(name="checkhash", request_type=RequestType(func=lambda request, context: self.check_hash())) + rm.add_request(name="repair", request_type=RequestType(func=lambda request, context: self.repair())) + rm.add_request(name="restore", request_type=RequestType(func=lambda request, context: self.restore())) + + rm.add_request(name="corrupt", request_type=RequestType(func=lambda request, context: self.corrupt())) + + return rm + + @property + def size_str(self) -> str: + """ + Get the file size in a human-readable string format. + + This property makes use of the :func:`convert_size` function to convert the `self.size` attribute to a string + that is easier to read and understand. + + :return: The human-readable string representation of the file size. + """ + return convert_size(self.size) + + @abstractmethod + def check_hash(self) -> bool: + """ + Checks the has of the file to detect any changes. + + For current implementation, any change in file hash means it is compromised. + + Return False if corruption is detected, otherwise True + """ + pass + + @abstractmethod + def repair(self) -> bool: + """ + Repair the FileSystemItem. + + True if successfully repaired. False otherwise. + """ + pass + + @abstractmethod + def corrupt(self) -> bool: + """ + Corrupt the FileSystemItem. + + True if successfully corrupted. False otherwise. + """ + pass + + @abstractmethod + def restore(self) -> bool: + """Restore the file/folder to the state before it got ruined.""" + pass From b2c3e273b75b11c57e3956a7a1441314e16c871a Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Thu, 2 Nov 2023 15:10:51 +0000 Subject: [PATCH 274/980] #1962: separating file system into more managable files --- src/primaite/simulator/file_system/file.py | 185 +++++ .../simulator/file_system/file_system.py | 661 +++--------------- .../file_system/file_system_item_abc.py | 4 + src/primaite/simulator/file_system/folder.py | 347 +++++++++ .../_simulator/_file_system/test_file.py | 78 +++ .../_file_system/test_file_system.py | 198 +----- .../_file_system/test_file_system_actions.py | 3 +- .../_simulator/_file_system/test_folder.py | 133 ++++ .../_network/_hardware/test_node_actions.py | 3 +- 9 files changed, 841 insertions(+), 771 deletions(-) create mode 100644 src/primaite/simulator/file_system/file.py create mode 100644 src/primaite/simulator/file_system/folder.py create mode 100644 tests/unit_tests/_primaite/_simulator/_file_system/test_file.py create mode 100644 tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py new file mode 100644 index 00000000..0da3c9ab --- /dev/null +++ b/src/primaite/simulator/file_system/file.py @@ -0,0 +1,185 @@ +from __future__ import annotations + +import hashlib +import json +import os.path +from pathlib import Path +from typing import Dict, Optional + +from primaite import getLogger +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC, FileSystemItemHealthStatus +from primaite.simulator.file_system.file_type import FileType, get_file_type_from_extension + +_LOGGER = getLogger(__name__) + + +class File(FileSystemItemABC): + """ + Class representing a file in the simulation. + + :ivar Folder folder: The folder in which the file resides. + :ivar FileType file_type: The type of the file. + :ivar Optional[int] sim_size: The simulated file size. + :ivar bool real: Indicates if the file is actually a real file in the Node sim fs output. + :ivar Optional[Path] sim_path: The path if the file is real. + """ + + folder_id: str + "The id of the Folder the File is in." + folder_name: str + "The name of the Folder the file is in." + file_type: FileType + "The type of File." + sim_size: Optional[int] = None + "The simulated file size." + real: bool = False + "Indicates whether the File is actually a real file in the Node sim fs output." + sim_path: Optional[Path] = None + "The Path if real is True." + sim_root: Optional[Path] = None + "Root path of the simulation." + + def __init__(self, **kwargs): + """ + Initialise File class. + + :param name: The name of the file. + :param file_type: The FileType of the file + :param size: The size of the FileSystemItemABC + """ + has_extension = "." in kwargs["name"] + + # Attempt to use the file type extension to set/override the FileType + if has_extension: + extension = kwargs["name"].split(".")[-1] + kwargs["file_type"] = get_file_type_from_extension(extension) + else: + # If the file name does not have a extension, override file type to FileType.UNKNOWN + if not kwargs["file_type"]: + kwargs["file_type"] = FileType.UNKNOWN + if kwargs["file_type"] != FileType.UNKNOWN: + kwargs["name"] = f"{kwargs['name']}.{kwargs['file_type'].name.lower()}" + + # set random file size if none provided + if not kwargs.get("sim_size"): + kwargs["sim_size"] = kwargs["file_type"].default_size + super().__init__(**kwargs) + if self.real: + self.sim_path = self.sim_root / self.path + if not self.sim_path.exists(): + self.sim_path.parent.mkdir(exist_ok=True, parents=True) + with open(self.sim_path, mode="a"): + pass + + self.sys_log.info(f"Created file /{self.path} (id: {self.uuid})") + + @property + def path(self) -> str: + """ + Get the path of the file in the file system. + + :return: The full path of the file. + """ + return f"{self.folder_name}/{self.name}" + + @property + def size(self) -> int: + """ + Get the size of the file in bytes. + + :return: The size of the file in bytes. + """ + if self.real: + return os.path.getsize(self.sim_path) + return self.sim_size + + def describe_state(self) -> Dict: + """Produce a dictionary describing the current state of this object.""" + state = super().describe_state() + state["size"] = self.size + state["file_type"] = self.file_type.name + return state + + def scan(self) -> None: + """Updates the visible statuses of the file.""" + path = self.folder.name + "/" + self.name + self.sys_log.info(f"Scanning file {self.sim_path if self.sim_path else path}") + self.visible_health_status = self.health_status + + def reveal_to_red(self): + """Reveals the folder/file to the red agent.""" + self.revealed_to_red = True + + def check_hash(self) -> bool: + """ + Check if the file has been changed. + + If changed, the file is considered corrupted. + + Return False if corruption is detected, otherwise True + """ + current_hash = None + + # if file is real, read the file contents + if self.real: + with open(self.sim_path, "rb") as f: + file_hash = hashlib.blake2b() + while chunk := f.read(8192): + file_hash.update(chunk) + + current_hash = file_hash.hexdigest() + else: + # otherwise get describe_state dict and hash that + current_hash = hashlib.blake2b(json.dumps(self.describe_state(), sort_keys=True).encode()).hexdigest() + + # if the previous hash is None, set the current hash to previous + if self.previous_hash is None: + self.previous_hash = current_hash + + # if the previous hash and current hash do not match, mark file as corrupted + if self.previous_hash is not current_hash: + self.corrupt() + return False + + return True + + def repair(self) -> bool: + """Repair a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" + super().repair() + + # set file status to good if corrupt + if self.health_status == FileSystemItemHealthStatus.CORRUPT: + self.health_status = FileSystemItemHealthStatus.GOOD + + path = self.folder.name + "/" + self.name + self.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") + return True + + def restore(self) -> bool: + """Restore a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" + super().restore() + + restored = False + + if self.health_status == FileSystemItemHealthStatus.CORRUPT: + self.health_status = FileSystemItemHealthStatus.GOOD + restored = True + + path = self.folder.name + "/" + self.name + self.sys_log.info(f"Restored file {self.sim_path if self.sim_path else path}") + return restored + + def corrupt(self) -> bool: + """Corrupt a File by setting the status to FileSystemItemStatus.CORRUPT.""" + super().corrupt() + + corrupted = False + + # set file status to good if corrupt + if self.health_status == FileSystemItemHealthStatus.GOOD: + self.health_status = FileSystemItemHealthStatus.CORRUPT + corrupted = True + + path = self.folder.name + "/" + self.name + self.sys_log.info(f"Corrupted file {self.sim_path if self.sim_path else path}") + return corrupted diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 02f3c5e6..16c9992c 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -1,8 +1,5 @@ from __future__ import annotations -import hashlib -import json -import os.path import shutil from pathlib import Path from typing import Dict, Optional @@ -11,8 +8,9 @@ from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType, SimComponent -from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC, FileSystemItemHealthStatus -from primaite.simulator.file_system.file_type import FileType, get_file_type_from_extension +from primaite.simulator.file_system.file import File +from primaite.simulator.file_system.file_type import FileType +from primaite.simulator.file_system.folder import Folder from primaite.simulator.system.core.sys_log import SysLog _LOGGER = getLogger(__name__) @@ -27,7 +25,9 @@ class FileSystem(SimComponent): "List containing all the folders that have been deleted." _folders_by_name: Dict[str, Folder] = {} sys_log: SysLog + "Instance of SysLog used to create system logs." sim_root: Path + "Root path of the simulation." def __init__(self, **kwargs): super().__init__(**kwargs) @@ -86,42 +86,9 @@ class FileSystem(SimComponent): else: print(table.get_string(sortby="Folder")) - def describe_state(self) -> Dict: - """ - Produce a dictionary describing the current state of this object. - - :return: Current state of this object and child objects. - """ - state = super().describe_state() - state["folders"] = {folder.name: folder.describe_state() for folder in self.folders.values()} - return state - - def apply_timestep(self, timestep: int) -> None: - """Apply time step to FileSystem and its child folders and files.""" - super().apply_timestep(timestep=timestep) - - # apply timestep to folders - for folder_id in self.folders: - self.folders[folder_id].apply_timestep(timestep=timestep) - - def scan(self, instant_scan: bool = False): - """ - Scan all the folders (and child files) in the file system. - - :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. - """ - for folder_id in self.folders: - self.folders[folder_id].scan(instant_scan=instant_scan) - - def reveal_to_red(self, instant_scan: bool = False): - """ - Reveals all the folders (and child files) in the file system to the red agent. - - :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. - """ - for folder_id in self.folders: - self.folders[folder_id].reveal_to_red(instant_scan=instant_scan) - + ############################################################### + # Folder methods + ############################################################### def create_folder(self, folder_name: str) -> Folder: """ Creates a Folder and adds it to the list of folders. @@ -132,11 +99,10 @@ class FileSystem(SimComponent): if self.get_folder(folder_name): raise Exception(f"Cannot create folder as it already exists: {folder_name}") - folder = Folder(name=folder_name, fs=self) + folder = Folder(name=folder_name, sys_log=self.sys_log) self.folders[folder.uuid] = folder self._folders_by_name[folder.name] = folder - self.sys_log.info(f"Created folder /{folder.name}") self._folder_request_manager.add_request( name=folder.uuid, request_type=RequestType(func=folder._request_manager) ) @@ -174,9 +140,27 @@ class FileSystem(SimComponent): folder = self.get_folder_by_id(folder_uuid=folder_uuid) self.delete_folder(folder_name=folder.name) - def restore_folder(self, folder_id: str): - """TODO.""" - pass + def get_folder(self, folder_name: str) -> Optional[Folder]: + """ + Get a folder by its name if it exists. + + :param folder_name: The folder name. + :return: The matching Folder. + """ + return self._folders_by_name.get(folder_name) + + def get_folder_by_id(self, folder_uuid: str) -> Optional[Folder]: + """ + Get a folder by its uuid if it exists. + + :param: folder_uuid: The folder uuid. + :return: The matching Folder. + """ + return self.folders.get(folder_uuid) + + ############################################################### + # File methods + ############################################################### def create_file( self, @@ -210,12 +194,14 @@ class FileSystem(SimComponent): name=file_name, sim_size=size, file_type=file_type, - folder=folder, + folder_id=folder.uuid, + folder_name=folder.name, real=real, sim_path=self.sim_root if real else None, + sim_root=self.sim_root, + sys_log=self.sys_log, ) folder.add_file(file) - self.sys_log.info(f"Created file /{file.path}") self._file_request_manager.add_request(name=file.uuid, request_type=RequestType(func=file._request_manager)) return file @@ -266,7 +252,7 @@ class FileSystem(SimComponent): dst_folder.add_file(file) if file.real: old_sim_path = file.sim_path - file.sim_path = file.folder.fs.sim_root / file.path + file.sim_path = file.sim_root / file.path file.sim_path.parent.mkdir(exist_ok=True) shutil.move(old_sim_path, file.sim_path) @@ -280,14 +266,64 @@ class FileSystem(SimComponent): """ file = self.get_file(folder_name=src_folder_name, file_name=src_file_name) if file: + # check that dest folder exists dst_folder = self.get_folder(folder_name=dst_folder_name) if not dst_folder: + # create dest folder dst_folder = self.create_folder(dst_folder_name) - new_file = file.make_copy(dst_folder=dst_folder) - dst_folder.add_file(new_file) + + file_copy = File( + folder_id=dst_folder.uuid, + folder_name=dst_folder.name, + **file.model_dump(exclude={"uuid", "folder_id", "folder_name", "sim_path"}), + ) + dst_folder.add_file(file_copy) + if file.real: - new_file.sim_path.parent.mkdir(exist_ok=True) - shutil.copy2(file.sim_path, new_file.sim_path) + file_copy.sim_path.parent.mkdir(exist_ok=True) + shutil.copy2(file.sim_path, file_copy.sim_path) + else: + self.sys_log.error(f"Unable to copy file. {src_file_name} does not exist.") + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + """ + state = super().describe_state() + state["folders"] = {folder.name: folder.describe_state() for folder in self.folders.values()} + return state + + def apply_timestep(self, timestep: int) -> None: + """Apply time step to FileSystem and its child folders and files.""" + super().apply_timestep(timestep=timestep) + + # apply timestep to folders + for folder_id in self.folders: + self.folders[folder_id].apply_timestep(timestep=timestep) + + def scan(self, instant_scan: bool = False): + """ + Scan all the folders (and child files) in the file system. + + :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. + """ + for folder_id in self.folders: + self.folders[folder_id].scan(instant_scan=instant_scan) + + def reveal_to_red(self, instant_scan: bool = False): + """ + Reveals all the folders (and child files) in the file system to the red agent. + + :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. + """ + for folder_id in self.folders: + self.folders[folder_id].reveal_to_red(instant_scan=instant_scan) + + def restore_folder(self, folder_id: str): + """TODO.""" + pass def restore_file(self, folder_id: str, file_id: str): """ @@ -302,522 +338,3 @@ class FileSystem(SimComponent): :type: folder_id: str """ pass - - def get_folder(self, folder_name: str) -> Optional[Folder]: - """ - Get a folder by its name if it exists. - - :param folder_name: The folder name. - :return: The matching Folder. - """ - return self._folders_by_name.get(folder_name) - - def get_folder_by_id(self, folder_uuid: str) -> Optional[Folder]: - """ - Get a folder by its uuid if it exists. - - :param: folder_uuid: The folder uuid. - :return: The matching Folder. - """ - return self.folders.get(folder_uuid) - - -class Folder(FileSystemItemABC): - """Simulation Folder.""" - - fs: FileSystem - "The FileSystem the Folder is in." - files: Dict[str, File] = {} - "Files stored in the folder." - _files_by_name: Dict[str, File] = {} - "Files by their name as .." - deleted_files: Dict[str, File] = {} - "Files that have been deleted." - - scan_duration: int = -1 - "How many timesteps to complete a scan." - - red_scan_duration: int = -1 - "How many timesteps to complete reveal to red scan." - - def _init_request_manager(self) -> RequestManager: - rm = super()._init_request_manager() - rm.add_request( - name="delete", - request_type=RequestType(func=lambda request, context: self.remove_file_by_id(file_uuid=request[0])), - ) - return rm - - def describe_state(self) -> Dict: - """ - Produce a dictionary describing the current state of this object. - - :return: Current state of this object and child objects. - """ - state = super().describe_state() - state["files"] = {file.name: file.describe_state() for uuid, file in self.files.items()} - return state - - def show(self, markdown: bool = False): - """ - Display the contents of the Folder in tabular format. - - :param markdown: Whether to display the table in Markdown format or not. Default is `False`. - """ - table = PrettyTable(["File", "Size"]) - if markdown: - table.set_style(MARKDOWN) - table.align = "l" - table.title = f"{self.fs.sys_log.hostname} File System Folder ({self.name})" - for file in self.files.values(): - table.add_row([file.name, file.size_str]) - print(table.get_string(sortby="File")) - - @property - def size(self) -> int: - """ - Calculate and return the total size of all files in the folder. - - :return: The total size of all files in the folder. If no files exist or all have `None` - size, returns 0. - """ - return sum(file.size for file in self.files.values() if file.size is not None) - - def apply_timestep(self, timestep: int): - """ - Apply a single timestep of simulation dynamics to this folder and its files. - - In this instance, if any multi-timestep processes are currently occurring (such as scanning), - then they are brought one step closer to being finished. - - :param timestep: The current timestep number. (Amount of time since simulation episode began) - :type timestep: int - """ - super().apply_timestep(timestep=timestep) - - # scan files each timestep - if self.scan_duration >= 0: - self.scan_duration -= 1 - - if self.scan_duration == 0: - for file_id in self.files: - file = self.get_file_by_id(file_uuid=file_id) - file.scan() - if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: - self.visible_health_status = FileSystemItemHealthStatus.CORRUPT - - # red scan file at each step - if self.red_scan_duration >= 0: - self.red_scan_duration -= 1 - - if self.red_scan_duration == 0: - self.revealed_to_red = True - for file_id in self.files: - file = self.get_file_by_id(file_uuid=file_id) - file.reveal_to_red() - - # apply timestep to files in folder - for file_id in self.files: - self.files[file_id].apply_timestep(timestep=timestep) - - def get_file(self, file_name: str) -> Optional[File]: - """ - Get a file by its name. - - File name must be the filename and prefix, like 'memo.docx'. - - :param file_name: The file name. - :return: The matching File. - """ - # TODO: Increment read count? - return self._files_by_name.get(file_name) - - def get_file_by_id(self, file_uuid: str) -> File: - """ - Get a file by its uuid. - - :param: file_uuid: The file uuid. - :return: The matching File. - """ - return self.files.get(file_uuid) - - def add_file(self, file: File): - """ - Adds a file to the folder. - - :param File file: The File object to be added to the folder. - :raises Exception: If the provided `file` parameter is None or not an instance of the - `File` class. - """ - if file is None or not isinstance(file, File): - raise Exception(f"Invalid file: {file}") - - # check if file with id already exists in folder - if file.uuid in self.files: - _LOGGER.debug(f"File with id {file.uuid} already exists in folder") - else: - # add to list - self.files[file.uuid] = file - self._files_by_name[file.name] = file - file.folder = self - - def remove_file(self, file: Optional[File]): - """ - Removes a file from the folder list. - - The method can take a File object or a file id. - - :param file: The file to remove - """ - if file is None or not isinstance(file, File): - raise Exception(f"Invalid file: {file}") - - if self.files.get(file.uuid): - self.files.pop(file.uuid) - self._files_by_name.pop(file.name) - self.deleted_files[file.uuid] = file - self.fs.sys_log.info(f"Removed file {file.name} (id: {file.uuid})") - else: - _LOGGER.debug(f"File with UUID {file.uuid} was not found.") - - def remove_file_by_id(self, file_uuid: str): - """ - Remove a file using id. - - :param: file_uuid: The UUID of the file to remove. - """ - file = self.get_file_by_id(file_uuid=file_uuid) - self.remove_file(file=file) - - def remove_all_files(self): - """Removes all the files in the folder.""" - for file_id in self.files: - self.deleted_files[file_id] = self.files[file_id] - - self.files = {} - self._files_by_name = {} - - def restore_file(self, file: Optional[File]): - """ - Restores a file. - - The method can take a File object or a file id. - - :param file: The file to restore - """ - pass - - def quarantine(self): - """Quarantines the File System Folder.""" - pass - - def unquarantine(self): - """Unquarantine of the File System Folder.""" - pass - - def quarantine_status(self) -> bool: - """Returns true if the folder is being quarantined.""" - pass - - def scan(self, instant_scan: bool = False) -> None: - """ - Update Folder visible status. - - :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. - """ - if instant_scan: - for file_id in self.files: - file = self.get_file_by_id(file_uuid=file_id) - file.scan() - if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: - self.visible_health_status = FileSystemItemHealthStatus.CORRUPT - return - - if self.scan_duration <= 0: - # scan one file per timestep - self.scan_duration = len(self.files) - self.fs.sys_log.info(f"Scanning folder {self.name} (id: {self.uuid})") - else: - # scan already in progress - self.fs.sys_log.info(f"Scan is already in progress {self.name} (id: {self.uuid})") - - def reveal_to_red(self, instant_scan: bool = False): - """ - Reveals the folders and files to the red agent. - - :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. - """ - if instant_scan: - self.revealed_to_red = True - for file_id in self.files: - file = self.get_file_by_id(file_uuid=file_id) - file.reveal_to_red() - return - - if self.red_scan_duration <= 0: - # scan one file per timestep - self.red_scan_duration = len(self.files) - self.fs.sys_log.info(f"Folder revealed to red agent: {self.name} (id: {self.uuid})") - else: - # scan already in progress - self.fs.sys_log.info(f"Red Agent Scan is already in progress {self.name} (id: {self.uuid})") - - def check_hash(self) -> bool: - """ - Runs a :func:`check_hash` on all files in the folder. - - If a file under the folder is corrupted, the whole folder is considered corrupted. - - TODO: For now this will just iterate through the files and run :func:`check_hash` and ignores - any other changes to the folder - - Return False if corruption is detected, otherwise True - """ - super().check_hash() - - # iterate through the files and run a check hash - no_corrupted_files = True - - for file_id in self.files: - file = self.get_file_by_id(file_uuid=file_id) - no_corrupted_files = file.check_hash() - - # if one file in the folder is corrupted, set the folder status to corrupted - if not no_corrupted_files: - self.corrupt() - - self.fs.sys_log.info(f"Checking hash of folder {self.name} (id: {self.uuid})") - - return no_corrupted_files - - def repair(self) -> bool: - """Repair a corrupted Folder by setting the folder and containing files status to FileSystemItemStatus.GOOD.""" - super().repair() - - repaired = False - - # iterate through the files in the folder - for file_id in self.files: - file = self.get_file_by_id(file_uuid=file_id) - repaired = file.repair() - - # set file status to good if corrupt - if self.health_status == FileSystemItemHealthStatus.CORRUPT: - self.health_status = FileSystemItemHealthStatus.GOOD - repaired = True - - self.fs.sys_log.info(f"Repaired folder {self.name} (id: {self.uuid})") - return repaired - - def restore(self) -> bool: - """Restore a File by setting the folder and containing files status to FileSystemItemStatus.GOOD.""" - super().restore() - - restored = False - - # iterate through the files in the folder - for file_id in self.files: - file = self.get_file_by_id(file_uuid=file_id) - restored = file.restore() - - # set file status to corrupt if good - if self.health_status == FileSystemItemHealthStatus.CORRUPT: - self.health_status = FileSystemItemHealthStatus.GOOD - restored = True - - self.fs.sys_log.info(f"Restored folder {self.name} (id: {self.uuid})") - return restored - - def corrupt(self) -> bool: - """Corrupt a File by setting the folder and containing files status to FileSystemItemStatus.CORRUPT.""" - super().corrupt() - - corrupted = False - - # iterate through the files in the folder - for file_id in self.files: - file = self.get_file_by_id(file_uuid=file_id) - corrupted = file.corrupt() - - # set file status to corrupt if good - if self.health_status == FileSystemItemHealthStatus.GOOD: - self.health_status = FileSystemItemHealthStatus.CORRUPT - corrupted = True - - self.fs.sys_log.info(f"Corrupted folder {self.name} (id: {self.uuid})") - return corrupted - - -class File(FileSystemItemABC): - """ - Class representing a file in the simulation. - - :ivar Folder folder: The folder in which the file resides. - :ivar FileType file_type: The type of the file. - :ivar Optional[int] sim_size: The simulated file size. - :ivar bool real: Indicates if the file is actually a real file in the Node sim fs output. - :ivar Optional[Path] sim_path: The path if the file is real. - """ - - folder: Folder - "The Folder the File is in." - file_type: FileType - "The type of File." - sim_size: Optional[int] = None - "The simulated file size." - real: bool = False - "Indicates whether the File is actually a real file in the Node sim fs output." - sim_path: Optional[Path] = None - "The Path if real is True." - - def __init__(self, **kwargs): - """ - Initialise File class. - - :param name: The name of the file. - :param file_type: The FileType of the file - :param size: The size of the FileSystemItemABC - """ - has_extension = "." in kwargs["name"] - - # Attempt to use the file type extension to set/override the FileType - if has_extension: - extension = kwargs["name"].split(".")[-1] - kwargs["file_type"] = get_file_type_from_extension(extension) - else: - # If the file name does not have a extension, override file type to FileType.UNKNOWN - if not kwargs["file_type"]: - kwargs["file_type"] = FileType.UNKNOWN - if kwargs["file_type"] != FileType.UNKNOWN: - kwargs["name"] = f"{kwargs['name']}.{kwargs['file_type'].name.lower()}" - - # set random file size if none provided - if not kwargs.get("sim_size"): - kwargs["sim_size"] = kwargs["file_type"].default_size - super().__init__(**kwargs) - if self.real: - self.sim_path = self.folder.fs.sim_root / self.path - if not self.sim_path.exists(): - self.sim_path.parent.mkdir(exist_ok=True, parents=True) - with open(self.sim_path, mode="a"): - pass - - def make_copy(self, dst_folder: Folder) -> File: - """ - Create a copy of the current File object in the given destination folder. - - :param Folder dst_folder: The destination folder for the copied file. - :return: A new File object that is a copy of the current file. - """ - return File(folder=dst_folder, **self.model_dump(exclude={"uuid", "folder", "sim_path"})) - - @property - def path(self) -> str: - """ - Get the path of the file in the file system. - - :return: The full path of the file. - """ - return f"{self.folder.name}/{self.name}" - - @property - def size(self) -> int: - """ - Get the size of the file in bytes. - - :return: The size of the file in bytes. - """ - if self.real: - return os.path.getsize(self.sim_path) - return self.sim_size - - def describe_state(self) -> Dict: - """Produce a dictionary describing the current state of this object.""" - state = super().describe_state() - state["size"] = self.size - state["file_type"] = self.file_type.name - return state - - def scan(self) -> None: - """Updates the visible statuses of the file.""" - path = self.folder.name + "/" + self.name - self.folder.fs.sys_log.info(f"Scanning file {self.sim_path if self.sim_path else path}") - self.visible_health_status = self.health_status - - def reveal_to_red(self): - """Reveals the folder/file to the red agent.""" - self.revealed_to_red = True - - def check_hash(self) -> bool: - """ - Check if the file has been changed. - - If changed, the file is considered corrupted. - - Return False if corruption is detected, otherwise True - """ - current_hash = None - - # if file is real, read the file contents - if self.real: - with open(self.sim_path, "rb") as f: - file_hash = hashlib.blake2b() - while chunk := f.read(8192): - file_hash.update(chunk) - - current_hash = file_hash.hexdigest() - else: - # otherwise get describe_state dict and hash that - current_hash = hashlib.blake2b(json.dumps(self.describe_state(), sort_keys=True).encode()).hexdigest() - - # if the previous hash is None, set the current hash to previous - if self.previous_hash is None: - self.previous_hash = current_hash - - # if the previous hash and current hash do not match, mark file as corrupted - if self.previous_hash is not current_hash: - self.corrupt() - return False - - return True - - def repair(self) -> bool: - """Repair a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" - super().repair() - - # set file status to good if corrupt - if self.health_status == FileSystemItemHealthStatus.CORRUPT: - self.health_status = FileSystemItemHealthStatus.GOOD - - path = self.folder.name + "/" + self.name - self.folder.fs.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") - return True - - def restore(self) -> bool: - """Restore a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" - super().restore() - - restored = False - - if self.health_status == FileSystemItemHealthStatus.CORRUPT: - self.health_status = FileSystemItemHealthStatus.GOOD - restored = True - - path = self.folder.name + "/" + self.name - self.folder.fs.sys_log.info(f"Restored file {self.sim_path if self.sim_path else path}") - return restored - - def corrupt(self) -> bool: - """Corrupt a File by setting the status to FileSystemItemStatus.CORRUPT.""" - super().corrupt() - - corrupted = False - - # set file status to good if corrupt - if self.health_status == FileSystemItemHealthStatus.GOOD: - self.health_status = FileSystemItemHealthStatus.CORRUPT - corrupted = True - - path = self.folder.name + "/" + self.name - self.folder.fs.sys_log.info(f"Corrupted file {self.sim_path if self.sim_path else path}") - return corrupted diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py index 8f61c718..c0d65139 100644 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -7,6 +7,7 @@ from typing import Dict, Optional from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType, SimComponent +from primaite.simulator.system.core.sys_log import SysLog _LOGGER = getLogger(__name__) @@ -78,6 +79,9 @@ class FileSystemItemABC(SimComponent): revealed_to_red: bool = False "If true, the folder/file has been revealed to the red agent." + sys_log: SysLog + "Used for creating system logs." + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py new file mode 100644 index 00000000..6922cad1 --- /dev/null +++ b/src/primaite/simulator/file_system/folder.py @@ -0,0 +1,347 @@ +from __future__ import annotations + +from typing import Dict, Optional + +from prettytable import MARKDOWN, PrettyTable + +from primaite import getLogger +from primaite.simulator.core import RequestManager, RequestType +from primaite.simulator.file_system.file import File +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC, FileSystemItemHealthStatus + +_LOGGER = getLogger(__name__) + + +class Folder(FileSystemItemABC): + """Simulation Folder.""" + + files: Dict[str, File] = {} + "Files stored in the folder." + _files_by_name: Dict[str, File] = {} + "Files by their name as .." + deleted_files: Dict[str, File] = {} + "Files that have been deleted." + + scan_duration: int = -1 + "How many timesteps to complete a scan." + + red_scan_duration: int = -1 + "How many timesteps to complete reveal to red scan." + + def __init__(self, **kwargs): + """ + Initialise Folder class. + + :param name: The name of the folder. + :param sys_log: The SysLog instance to us to create system logs. + """ + super().__init__(**kwargs) + + self.sys_log.info(f"Created file /{self.name} (id: {self.uuid})") + + def _init_request_manager(self) -> RequestManager: + rm = super()._init_request_manager() + rm.add_request( + name="delete", + request_type=RequestType(func=lambda request, context: self.remove_file_by_id(file_uuid=request[0])), + ) + return rm + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + """ + state = super().describe_state() + state["files"] = {file.name: file.describe_state() for uuid, file in self.files.items()} + return state + + def show(self, markdown: bool = False): + """ + Display the contents of the Folder in tabular format. + + :param markdown: Whether to display the table in Markdown format or not. Default is `False`. + """ + table = PrettyTable(["File", "Size"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"{self.sys_log.hostname} File System Folder ({self.name})" + for file in self.files.values(): + table.add_row([file.name, file.size_str]) + print(table.get_string(sortby="File")) + + @property + def size(self) -> int: + """ + Calculate and return the total size of all files in the folder. + + :return: The total size of all files in the folder. If no files exist or all have `None` + size, returns 0. + """ + return sum(file.size for file in self.files.values() if file.size is not None) + + def apply_timestep(self, timestep: int): + """ + Apply a single timestep of simulation dynamics to this folder and its files. + + In this instance, if any multi-timestep processes are currently occurring (such as scanning), + then they are brought one step closer to being finished. + + :param timestep: The current timestep number. (Amount of time since simulation episode began) + :type timestep: int + """ + super().apply_timestep(timestep=timestep) + + # scan files each timestep + if self.scan_duration >= 0: + self.scan_duration -= 1 + + if self.scan_duration == 0: + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + file.scan() + if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: + self.visible_health_status = FileSystemItemHealthStatus.CORRUPT + + # red scan file at each step + if self.red_scan_duration >= 0: + self.red_scan_duration -= 1 + + if self.red_scan_duration == 0: + self.revealed_to_red = True + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + file.reveal_to_red() + + # apply timestep to files in folder + for file_id in self.files: + self.files[file_id].apply_timestep(timestep=timestep) + + def get_file(self, file_name: str) -> Optional[File]: + """ + Get a file by its name. + + File name must be the filename and prefix, like 'memo.docx'. + + :param file_name: The file name. + :return: The matching File. + """ + # TODO: Increment read count? + return self._files_by_name.get(file_name) + + def get_file_by_id(self, file_uuid: str) -> File: + """ + Get a file by its uuid. + + :param: file_uuid: The file uuid. + :return: The matching File. + """ + return self.files.get(file_uuid) + + def add_file(self, file: File): + """ + Adds a file to the folder. + + :param File file: The File object to be added to the folder. + :raises Exception: If the provided `file` parameter is None or not an instance of the + `File` class. + """ + if file is None or not isinstance(file, File): + raise Exception(f"Invalid file: {file}") + + # check if file with id already exists in folder + if file.uuid in self.files: + _LOGGER.debug(f"File with id {file.uuid} already exists in folder") + else: + # add to list + self.files[file.uuid] = file + self._files_by_name[file.name] = file + file.folder = self + + def remove_file(self, file: Optional[File]): + """ + Removes a file from the folder list. + + The method can take a File object or a file id. + + :param file: The file to remove + """ + if file is None or not isinstance(file, File): + raise Exception(f"Invalid file: {file}") + + if self.files.get(file.uuid): + self.files.pop(file.uuid) + self._files_by_name.pop(file.name) + self.deleted_files[file.uuid] = file + self.sys_log.info(f"Removed file {file.name} (id: {file.uuid})") + else: + _LOGGER.debug(f"File with UUID {file.uuid} was not found.") + + def remove_file_by_id(self, file_uuid: str): + """ + Remove a file using id. + + :param: file_uuid: The UUID of the file to remove. + """ + file = self.get_file_by_id(file_uuid=file_uuid) + self.remove_file(file=file) + + def remove_all_files(self): + """Removes all the files in the folder.""" + for file_id in self.files: + self.deleted_files[file_id] = self.files[file_id] + + self.files = {} + self._files_by_name = {} + + def restore_file(self, file: Optional[File]): + """ + Restores a file. + + The method can take a File object or a file id. + + :param file: The file to restore + """ + pass + + def quarantine(self): + """Quarantines the File System Folder.""" + pass + + def unquarantine(self): + """Unquarantine of the File System Folder.""" + pass + + def quarantine_status(self) -> bool: + """Returns true if the folder is being quarantined.""" + pass + + def scan(self, instant_scan: bool = False) -> None: + """ + Update Folder visible status. + + :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. + """ + if instant_scan: + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + file.scan() + if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: + self.visible_health_status = FileSystemItemHealthStatus.CORRUPT + return + + if self.scan_duration <= 0: + # scan one file per timestep + self.scan_duration = len(self.files) + self.sys_log.info(f"Scanning folder {self.name} (id: {self.uuid})") + else: + # scan already in progress + self.sys_log.info(f"Scan is already in progress {self.name} (id: {self.uuid})") + + def reveal_to_red(self, instant_scan: bool = False): + """ + Reveals the folders and files to the red agent. + + :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. + """ + if instant_scan: + self.revealed_to_red = True + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + file.reveal_to_red() + return + + if self.red_scan_duration <= 0: + # scan one file per timestep + self.red_scan_duration = len(self.files) + self.sys_log.info(f"Folder revealed to red agent: {self.name} (id: {self.uuid})") + else: + # scan already in progress + self.sys_log.info(f"Red Agent Scan is already in progress {self.name} (id: {self.uuid})") + + def check_hash(self) -> bool: + """ + Runs a :func:`check_hash` on all files in the folder. + + If a file under the folder is corrupted, the whole folder is considered corrupted. + + TODO: For now this will just iterate through the files and run :func:`check_hash` and ignores + any other changes to the folder + + Return False if corruption is detected, otherwise True + """ + super().check_hash() + + # iterate through the files and run a check hash + no_corrupted_files = True + + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + no_corrupted_files = file.check_hash() + + # if one file in the folder is corrupted, set the folder status to corrupted + if not no_corrupted_files: + self.corrupt() + + self.sys_log.info(f"Checking hash of folder {self.name} (id: {self.uuid})") + + return no_corrupted_files + + def repair(self) -> bool: + """Repair a corrupted Folder by setting the folder and containing files status to FileSystemItemStatus.GOOD.""" + super().repair() + + repaired = False + + # iterate through the files in the folder + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + repaired = file.repair() + + # set file status to good if corrupt + if self.health_status == FileSystemItemHealthStatus.CORRUPT: + self.health_status = FileSystemItemHealthStatus.GOOD + repaired = True + + self.sys_log.info(f"Repaired folder {self.name} (id: {self.uuid})") + return repaired + + def restore(self) -> bool: + """Restore a File by setting the folder and containing files status to FileSystemItemStatus.GOOD.""" + super().restore() + + restored = False + + # iterate through the files in the folder + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + restored = file.restore() + + # set file status to corrupt if good + if self.health_status == FileSystemItemHealthStatus.CORRUPT: + self.health_status = FileSystemItemHealthStatus.GOOD + restored = True + + self.sys_log.info(f"Restored folder {self.name} (id: {self.uuid})") + return restored + + def corrupt(self) -> bool: + """Corrupt a File by setting the folder and containing files status to FileSystemItemStatus.CORRUPT.""" + super().corrupt() + + corrupted = False + + # iterate through the files in the folder + for file_id in self.files: + file = self.get_file_by_id(file_uuid=file_id) + corrupted = file.corrupt() + + # set file status to corrupt if good + if self.health_status == FileSystemItemHealthStatus.GOOD: + self.health_status = FileSystemItemHealthStatus.CORRUPT + corrupted = True + + self.sys_log.info(f"Corrupted folder {self.name} (id: {self.uuid})") + return corrupted diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py new file mode 100644 index 00000000..174c7726 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py @@ -0,0 +1,78 @@ +from primaite.simulator.file_system.file import File +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus +from primaite.simulator.file_system.file_type import FileType + + +def test_create_file_no_extension(file_system): + """Tests that creating a file without an extension sets the file type to FileType.UNKNOWN.""" + file = file_system.create_file(file_name="test_file") + assert len(file_system.folders) is 1 + assert file_system.get_folder("root").get_file("test_file") == file + assert file_system.get_folder("root").get_file("test_file").file_type == FileType.UNKNOWN + assert file_system.get_folder("root").get_file("test_file").size == 0 + + +def test_file_scan(file_system): + """Test the ability to update visible status.""" + file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + assert file.health_status == FileSystemItemHealthStatus.GOOD + assert file.visible_health_status == FileSystemItemHealthStatus.GOOD + + file.corrupt() + + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + assert file.visible_health_status == FileSystemItemHealthStatus.GOOD + + file.scan() + + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_file_reveal_to_red_scan(file_system): + """Test the ability to reveal files to red.""" + file = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + assert file.revealed_to_red is False + + file.reveal_to_red() + + assert file.revealed_to_red is True + + +def test_simulated_file_check_hash(file_system): + file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + assert file.check_hash() is True + + # change simulated file size + file.sim_size = 0 + assert file.check_hash() is False + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_real_file_check_hash(file_system): + file: File = file_system.create_file(file_name="test_file.txt", real=True) + + assert file.check_hash() is True + + # change file content + with open(file.sim_path, "a") as f: + f.write("get hacked scrub lol xD\n") + + assert file.check_hash() is False + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_file_corrupt_repair(file_system): + """Test the ability to corrupt and repair files.""" + file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + file.corrupt() + + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + + file.repair() + + assert file.health_status == FileSystemItemHealthStatus.GOOD diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index cb398ca9..d26d0a4a 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -1,6 +1,6 @@ import pytest -from primaite.simulator.file_system.file_system import File, FileSystem, FileSystemItemHealthStatus, Folder +from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.file_system.file_type import FileType @@ -26,15 +26,6 @@ def test_create_file_no_folder(file_system): assert file_system.get_folder("root").get_file("test_file.txt").size == 10 -def test_create_file_no_extension(file_system): - """Tests that creating a file without an extension sets the file type to FileType.UNKNOWN.""" - file = file_system.create_file(file_name="test_file") - assert len(file_system.folders) is 1 - assert file_system.get_folder("root").get_file("test_file") == file - assert file_system.get_folder("root").get_file("test_file").file_type == FileType.UNKNOWN - assert file_system.get_folder("root").get_file("test_file").size == 0 - - def test_delete_file(file_system): """Tests that a file can be deleted.""" file_system.create_file(file_name="test_file.txt") @@ -125,193 +116,6 @@ def test_copy_file(file_system): assert file_system.get_file("dst_folder", "test_file.txt").uuid != original_uuid -@pytest.mark.skip(reason="Implementation for quarantine not needed yet") -def test_folder_quarantine_state(file_system): - """Tests the changing of folder quarantine status.""" - folder = file_system.get_folder("root") - - assert folder.quarantine_status() is False - - folder.quarantine() - assert folder.quarantine_status() is True - - folder.unquarantine() - assert folder.quarantine_status() is False - - -def test_file_corrupt_repair(file_system): - """Test the ability to corrupt and repair files.""" - folder: Folder = file_system.create_folder(folder_name="test_folder") - file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") - - file.corrupt() - - assert folder.health_status == FileSystemItemHealthStatus.GOOD - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - - file.repair() - - assert folder.health_status == FileSystemItemHealthStatus.GOOD - assert file.health_status == FileSystemItemHealthStatus.GOOD - - -def test_folder_corrupt_repair(file_system): - """Test the ability to corrupt and repair folders.""" - folder: Folder = file_system.create_folder(folder_name="test_folder") - file_system.create_file(file_name="test_file.txt", folder_name="test_folder") - - folder.corrupt() - - file = folder.get_file(file_name="test_file.txt") - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - - folder.repair() - - file = folder.get_file(file_name="test_file.txt") - assert folder.health_status == FileSystemItemHealthStatus.GOOD - assert file.health_status == FileSystemItemHealthStatus.GOOD - - -def test_file_scan(file_system): - """Test the ability to update visible status.""" - folder: Folder = file_system.create_folder(folder_name="test_folder") - file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") - - assert file.health_status == FileSystemItemHealthStatus.GOOD - assert file.visible_health_status == FileSystemItemHealthStatus.GOOD - - file.corrupt() - - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - assert file.visible_health_status == FileSystemItemHealthStatus.GOOD - - file.scan() - - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT - - -def test_folder_scan(file_system): - """Test the ability to update visible status.""" - folder: Folder = file_system.create_folder(folder_name="test_folder") - file_system.create_file(file_name="test_file.txt", folder_name="test_folder") - file_system.create_file(file_name="test_file2.txt", folder_name="test_folder") - - file1: File = folder.get_file_by_id(file_uuid=list(folder.files)[1]) - file2: File = folder.get_file_by_id(file_uuid=list(folder.files)[0]) - - assert folder.health_status == FileSystemItemHealthStatus.GOOD - assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD - assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD - assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD - - folder.corrupt() - - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD - assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD - assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD - - folder.scan() - - folder.apply_timestep(timestep=0) - - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD - assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD - assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD - - folder.apply_timestep(timestep=1) - - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT - assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT - assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT - - -def test_folder_reveal_to_red_scan(file_system): - """Test the ability to reveal files to red.""" - folder: Folder = file_system.create_folder(folder_name="test_folder") - file_system.create_file(file_name="test_file.txt", folder_name="test_folder") - file_system.create_file(file_name="test_file2.txt", folder_name="test_folder") - - file1: File = folder.get_file_by_id(file_uuid=list(folder.files)[1]) - file2: File = folder.get_file_by_id(file_uuid=list(folder.files)[0]) - - assert folder.revealed_to_red is False - assert file1.revealed_to_red is False - assert file2.revealed_to_red is False - - folder.reveal_to_red() - - folder.apply_timestep(timestep=0) - - assert folder.revealed_to_red is False - assert file1.revealed_to_red is False - assert file2.revealed_to_red is False - - folder.apply_timestep(timestep=1) - - assert folder.revealed_to_red is True - assert file1.revealed_to_red is True - assert file2.revealed_to_red is True - - -def test_simulated_file_check_hash(file_system): - file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") - - assert file.check_hash() is True - - # change simulated file size - file.sim_size = 0 - assert file.check_hash() is False - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - - -def test_real_file_check_hash(file_system): - file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder", real=True) - - assert file.check_hash() is True - - # change file content - with open(file.sim_path, "a") as f: - f.write("get hacked scrub lol xD\n") - - assert file.check_hash() is False - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - - -def test_simulated_folder_check_hash(file_system): - folder: Folder = file_system.create_folder(folder_name="test_folder") - file_system.create_file(file_name="test_file.txt", folder_name="test_folder") - - assert folder.check_hash() is True - - # change simulated file size - file = folder.get_file(file_name="test_file.txt") - file.sim_size = 0 - assert folder.check_hash() is False - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - - -def test_real_folder_check_hash(file_system): - folder: Folder = file_system.create_folder(folder_name="test_folder") - file_system.create_file(file_name="test_file.txt", folder_name="test_folder", real=True) - - assert folder.check_hash() is True - - # change simulated file size - file = folder.get_file(file_name="test_file.txt") - - # change file content - with open(file.sim_path, "a") as f: - f.write("get hacked scrub lol xD\n") - - assert folder.check_hash() is False - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - - @pytest.mark.skip(reason="Skipping until we tackle serialisation") def test_serialisation(file_system): """Test to check that the object serialisation works correctly.""" diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py index abfb244a..d902c935 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py @@ -2,7 +2,8 @@ from typing import Tuple import pytest -from primaite.simulator.file_system.file_system import File, FileSystem, FileSystemItemHealthStatus, Folder +from primaite.simulator.file_system.file_system import File, FileSystem, Folder +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus @pytest.fixture(scope="function") diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py new file mode 100644 index 00000000..9a12dbe9 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py @@ -0,0 +1,133 @@ +import pytest + +from primaite.simulator.file_system.file import File +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus +from primaite.simulator.file_system.folder import Folder + + +@pytest.mark.skip(reason="Implementation for quarantine not needed yet") +def test_folder_quarantine_state(file_system): + """Tests the changing of folder quarantine status.""" + folder = file_system.get_folder("root") + + assert folder.quarantine_status() is False + + folder.quarantine() + assert folder.quarantine_status() is True + + folder.unquarantine() + assert folder.quarantine_status() is False + + +def test_folder_scan(file_system): + """Test the ability to update visible status.""" + folder: Folder = file_system.create_folder(folder_name="test_folder") + file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + file_system.create_file(file_name="test_file2.txt", folder_name="test_folder") + + file1: File = folder.get_file_by_id(file_uuid=list(folder.files)[1]) + file2: File = folder.get_file_by_id(file_uuid=list(folder.files)[0]) + + assert folder.health_status == FileSystemItemHealthStatus.GOOD + assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD + + folder.corrupt() + + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD + + folder.scan() + + folder.apply_timestep(timestep=0) + + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD + + folder.apply_timestep(timestep=1) + + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_folder_reveal_to_red_scan(file_system): + """Test the ability to reveal files to red.""" + folder: Folder = file_system.create_folder(folder_name="test_folder") + file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + file_system.create_file(file_name="test_file2.txt", folder_name="test_folder") + + file1: File = folder.get_file_by_id(file_uuid=list(folder.files)[1]) + file2: File = folder.get_file_by_id(file_uuid=list(folder.files)[0]) + + assert folder.revealed_to_red is False + assert file1.revealed_to_red is False + assert file2.revealed_to_red is False + + folder.reveal_to_red() + + folder.apply_timestep(timestep=0) + + assert folder.revealed_to_red is False + assert file1.revealed_to_red is False + assert file2.revealed_to_red is False + + folder.apply_timestep(timestep=1) + + assert folder.revealed_to_red is True + assert file1.revealed_to_red is True + assert file2.revealed_to_red is True + + +def test_folder_corrupt_repair(file_system): + """Test the ability to corrupt and repair folders.""" + folder: Folder = file_system.create_folder(folder_name="test_folder") + file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + folder.corrupt() + + file = folder.get_file(file_name="test_file.txt") + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + + folder.repair() + + file = folder.get_file(file_name="test_file.txt") + assert folder.health_status == FileSystemItemHealthStatus.GOOD + assert file.health_status == FileSystemItemHealthStatus.GOOD + + +def test_simulated_folder_check_hash(file_system): + folder: Folder = file_system.create_folder(folder_name="test_folder") + file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + assert folder.check_hash() is True + + # change simulated file size + file = folder.get_file(file_name="test_file.txt") + file.sim_size = 0 + assert folder.check_hash() is False + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_real_folder_check_hash(file_system): + folder: Folder = file_system.create_folder(folder_name="test_folder") + file_system.create_file(file_name="test_file.txt", folder_name="test_folder", real=True) + + assert folder.check_hash() is True + + # change simulated file size + file = folder.get_file(file_name="test_file.txt") + + # change file content + with open(file.sim_path, "a") as f: + f.write("get hacked scrub lol xD\n") + + assert folder.check_hash() is False + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py index 3d6eea3b..1216a0cc 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py @@ -1,6 +1,7 @@ import pytest -from primaite.simulator.file_system.file_system import File, FileSystemItemHealthStatus, Folder +from primaite.simulator.file_system.file_system import File, Folder +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus from primaite.simulator.network.hardware.base import Node, NodeOperatingState from primaite.simulator.system.applications.application import Application from primaite.simulator.system.processes.process import Process From 51713bad7492318c7f369d8f47f74bc4630038e9 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Fri, 3 Nov 2023 15:15:18 +0000 Subject: [PATCH 275/980] #1962: split tests into managable files + implement deletion of folders and files + tests --- src/primaite/simulator/file_system/file.py | 56 +++++--- .../simulator/file_system/file_system.py | 74 +++++++++- .../file_system/file_system_item_abc.py | 26 +++- src/primaite/simulator/file_system/folder.py | 120 +++++++++------- .../services/database/database_service.py | 2 +- .../_simulator/_file_system/test_file.py | 12 +- .../_file_system/test_file_actions.py | 89 ++++++++++++ .../_file_system/test_file_system.py | 47 +++++++ .../_file_system/test_file_system_actions.py | 131 +----------------- .../_simulator/_file_system/test_folder.py | 25 +++- .../_file_system/test_folder_actions.py | 103 ++++++++++++++ 11 files changed, 468 insertions(+), 217 deletions(-) create mode 100644 tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py create mode 100644 tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index 0da3c9ab..04502c0f 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -102,15 +102,22 @@ class File(FileSystemItemABC): def scan(self) -> None: """Updates the visible statuses of the file.""" + if self.deleted: + self.sys_log.error(f"Unable to scan deleted file {self.folder_name}/{self.name}") + return + path = self.folder.name + "/" + self.name self.sys_log.info(f"Scanning file {self.sim_path if self.sim_path else path}") self.visible_health_status = self.health_status - def reveal_to_red(self): + def reveal_to_red(self) -> None: """Reveals the folder/file to the red agent.""" + if self.deleted: + self.sys_log.error(f"Unable to reveal deleted file {self.folder_name}/{self.name}") + return self.revealed_to_red = True - def check_hash(self) -> bool: + def check_hash(self) -> None: """ Check if the file has been changed. @@ -118,6 +125,9 @@ class File(FileSystemItemABC): Return False if corruption is detected, otherwise True """ + if self.deleted: + self.sys_log.error(f"Unable to check hash of deleted file {self.folder_name}/{self.name}") + return current_hash = None # if file is real, read the file contents @@ -139,13 +149,12 @@ class File(FileSystemItemABC): # if the previous hash and current hash do not match, mark file as corrupted if self.previous_hash is not current_hash: self.corrupt() - return False - return True - - def repair(self) -> bool: + def repair(self) -> None: """Repair a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" - super().repair() + if self.deleted: + self.sys_log.error(f"Unable to repair deleted file {self.folder_name}/{self.name}") + return # set file status to good if corrupt if self.health_status == FileSystemItemHealthStatus.CORRUPT: @@ -153,33 +162,38 @@ class File(FileSystemItemABC): path = self.folder.name + "/" + self.name self.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") - return True - def restore(self) -> bool: + def restore(self) -> None: """Restore a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" - super().restore() - - restored = False - if self.health_status == FileSystemItemHealthStatus.CORRUPT: self.health_status = FileSystemItemHealthStatus.GOOD - restored = True path = self.folder.name + "/" + self.name self.sys_log.info(f"Restored file {self.sim_path if self.sim_path else path}") - return restored - def corrupt(self) -> bool: + def corrupt(self) -> None: """Corrupt a File by setting the status to FileSystemItemStatus.CORRUPT.""" - super().corrupt() - - corrupted = False + if self.deleted: + self.sys_log.error(f"Unable to corrupt deleted file {self.folder_name}/{self.name}") + return # set file status to good if corrupt if self.health_status == FileSystemItemHealthStatus.GOOD: self.health_status = FileSystemItemHealthStatus.CORRUPT - corrupted = True path = self.folder.name + "/" + self.name self.sys_log.info(f"Corrupted file {self.sim_path if self.sim_path else path}") - return corrupted + + def restore(self) -> bool: + """Determines if the file needs to be repaired or unmarked as deleted.""" + super().restore() + return True + + def delete(self): + """Marks the file as deleted.""" + if self.deleted: + self.sys_log.error(f"Unable to delete an already deleted file {self.folder_name}/{self.name}") + return + + self.deleted = True + self.sys_log.info(f"File deleted {self.folder_name}/{self.name}") diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 16c9992c..7f2d41e5 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -38,9 +38,21 @@ class FileSystem(SimComponent): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() + self._delete_manager = RequestManager() + self._delete_manager.add_request( + name="file", + request_type=RequestType( + func=lambda request, context: self.delete_file_by_id(folder_uuid=request[0], file_uuid=request[1]) + ), + ) + self._delete_manager.add_request( + name="folder", + request_type=RequestType(func=lambda request, context: self.delete_folder_by_id(folder_uuid=request[0])), + ) + rm.add_request( name="delete", - request_type=RequestType(func=lambda request, context: self.delete_folder_by_id(folder_uuid=request[0])), + request_type=RequestType(func=self._delete_manager), ) self._folder_request_manager = RequestManager() @@ -119,15 +131,18 @@ class FileSystem(SimComponent): return folder = self._folders_by_name.get(folder_name) if folder: + # set folder to deleted state + folder.delete() + # remove from folder list self.folders.pop(folder.uuid) self._folders_by_name.pop(folder.name) - self.sys_log.info(f"Deleted folder /{folder.name} and its contents") # add to deleted list folder.remove_all_files() self.deleted_folders[folder.uuid] = folder + self.sys_log.info(f"Deleted folder /{folder.name} and its contents") else: _LOGGER.debug(f"Cannot delete folder as it does not exist: {folder_name}") @@ -216,7 +231,41 @@ class FileSystem(SimComponent): folder = self.get_folder(folder_name) if folder: return folder.get_file(file_name) - self.sys_log.info(f"file not found /{folder_name}/{file_name}") + self.sys_log.info(f"File not found /{folder_name}/{file_name}") + + def get_file_by_id( + self, file_uuid: str, folder_uuid: Optional[str] = None, include_deleted: Optional[bool] = False + ) -> Optional[File]: + """ + Retrieve a file by its uuid from a specific folder. + + :param: file_uuid: The uuid of the folder where the file resides. + :param: folder_uuid: The uuid of the file to be retrieved, including its extension. + :param: include_deleted: If true, the deleted files will also be checked + :return: An instance of File if it exists, otherwise `None`. + """ + folder = self.folders.get(folder_uuid) + + if folder: + return folder.get_file_by_id(file_uuid=file_uuid, include_deleted=include_deleted) + + # iterate through every folder looking for file + file = None + + for folder_id in self.folders: + folder = self.folders.get(folder_id) + res = folder.get_file_by_id(file_uuid=file_uuid, include_deleted=True) + if res: + file = res + + if include_deleted: + for folder_id in self.deleted_folders: + folder = self.deleted_folders.get(folder_id) + res = folder.get_file_by_id(file_uuid=file_uuid, include_deleted=True) + if res: + file = res + + return file def delete_file(self, folder_name: str, file_name: str): """ @@ -231,6 +280,19 @@ class FileSystem(SimComponent): if file: folder.remove_file(file) + def delete_file_by_id(self, folder_uuid: str, file_uuid: str): + """ + Deletes a file via its uuid. + + :param: folder_uuid: UUID of the folder the file belongs to + :param: file_uuid: UUID of the file to delete + """ + folder = self.get_folder_by_id(folder_uuid=folder_uuid) + + if folder: + file = folder.get_file_by_id(file_uuid=file_uuid) + self.delete_file(folder_name=folder.name, file_name=file.name) + def move_file(self, src_folder_name: str, src_file_name: str, dst_folder_name: str): """ Move a file from one folder to another. @@ -277,7 +339,7 @@ class FileSystem(SimComponent): folder_name=dst_folder.name, **file.model_dump(exclude={"uuid", "folder_id", "folder_name", "sim_path"}), ) - dst_folder.add_file(file_copy) + dst_folder.add_file(file_copy, force=True) if file.real: file_copy.sim_path.parent.mkdir(exist_ok=True) @@ -303,6 +365,10 @@ class FileSystem(SimComponent): for folder_id in self.folders: self.folders[folder_id].apply_timestep(timestep=timestep) + ############################################################### + # Agent actions + ############################################################### + def scan(self, instant_scan: bool = False): """ Scan all the folders (and child files) in the file system. diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py index c0d65139..543bb1b7 100644 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -82,6 +82,9 @@ class FileSystemItemABC(SimComponent): sys_log: SysLog "Used for creating system logs." + deleted: bool = False + "If true, the FileSystemItem was deleted." + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -121,7 +124,17 @@ class FileSystemItemABC(SimComponent): return convert_size(self.size) @abstractmethod - def check_hash(self) -> bool: + def scan(self) -> None: + """Scan the folder/file - updates the visible_health_status.""" + pass + + @abstractmethod + def reveal_to_red(self) -> None: + """Reveal the folder/file to the red agent.""" + pass + + @abstractmethod + def check_hash(self) -> None: """ Checks the has of the file to detect any changes. @@ -132,7 +145,7 @@ class FileSystemItemABC(SimComponent): pass @abstractmethod - def repair(self) -> bool: + def repair(self) -> None: """ Repair the FileSystemItem. @@ -141,7 +154,7 @@ class FileSystemItemABC(SimComponent): pass @abstractmethod - def corrupt(self) -> bool: + def corrupt(self) -> None: """ Corrupt the FileSystemItem. @@ -150,6 +163,11 @@ class FileSystemItemABC(SimComponent): pass @abstractmethod - def restore(self) -> bool: + def restore(self) -> None: """Restore the file/folder to the state before it got ruined.""" pass + + @abstractmethod + def delete(self) -> None: + """Mark the file/folder as deleted.""" + self.deleted = True diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 6922cad1..e12d4e12 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -131,34 +131,45 @@ class Folder(FileSystemItemABC): # TODO: Increment read count? return self._files_by_name.get(file_name) - def get_file_by_id(self, file_uuid: str) -> File: + def get_file_by_id(self, file_uuid: str, include_deleted: Optional[bool] = False) -> File: """ Get a file by its uuid. :param: file_uuid: The file uuid. + :param: include_deleted: If true, the deleted files will also be checked :return: The matching File. """ + if include_deleted: + deleted_file = self.deleted_files.get(file_uuid) + + if deleted_file: + return deleted_file + return self.files.get(file_uuid) - def add_file(self, file: File): + def add_file(self, file: File, force: Optional[bool] = False): """ Adds a file to the folder. - :param File file: The File object to be added to the folder. + :param: file: The File object to be added to the folder. + :param: force: Overwrite file - do not check if uuid or name already exists in folder. Default False. :raises Exception: If the provided `file` parameter is None or not an instance of the `File` class. """ if file is None or not isinstance(file, File): raise Exception(f"Invalid file: {file}") - # check if file with id already exists in folder - if file.uuid in self.files: - _LOGGER.debug(f"File with id {file.uuid} already exists in folder") - else: - # add to list - self.files[file.uuid] = file - self._files_by_name[file.name] = file - file.folder = self + # check if file with id or name already exists in folder + if (force is not True) and file.name in self._files_by_name: + raise Exception(f"File with name {file.name} already exists in folder") + + if (force is not True) and file.uuid in self.files: + raise Exception(f"File with uuid {file.uuid} already exists in folder") + + # add to list + self.files[file.uuid] = file + self._files_by_name[file.name] = file + file.folder = self def remove_file(self, file: Optional[File]): """ @@ -175,6 +186,7 @@ class Folder(FileSystemItemABC): self.files.pop(file.uuid) self._files_by_name.pop(file.name) self.deleted_files[file.uuid] = file + file.delete() self.sys_log.info(f"Removed file {file.name} (id: {file.uuid})") else: _LOGGER.debug(f"File with UUID {file.uuid} was not found.") @@ -191,7 +203,9 @@ class Folder(FileSystemItemABC): def remove_all_files(self): """Removes all the files in the folder.""" for file_id in self.files: - self.deleted_files[file_id] = self.files[file_id] + file = self.files.get(file_id) + file.delete() + self.deleted_files[file_id] = file self.files = {} self._files_by_name = {} @@ -224,6 +238,10 @@ class Folder(FileSystemItemABC): :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. """ + if self.deleted: + self.sys_log.error(f"Unable to scan deleted folder {self.name}") + return + if instant_scan: for file_id in self.files: file = self.get_file_by_id(file_uuid=file_id) @@ -246,6 +264,10 @@ class Folder(FileSystemItemABC): :param: instant_scan: If True, the scan is completed instantly and ignores scan duration. Default False. """ + if self.deleted: + self.sys_log.error(f"Unable to reveal deleted folder {self.name}") + return + if instant_scan: self.revealed_to_red = True for file_id in self.files: @@ -261,7 +283,7 @@ class Folder(FileSystemItemABC): # scan already in progress self.sys_log.info(f"Red Agent Scan is already in progress {self.name} (id: {self.uuid})") - def check_hash(self) -> bool: + def check_hash(self) -> None: """ Runs a :func:`check_hash` on all files in the folder. @@ -272,14 +294,18 @@ class Folder(FileSystemItemABC): Return False if corruption is detected, otherwise True """ - super().check_hash() + if self.deleted: + self.sys_log.error(f"Unable to check hash of deleted folder {self.name}") + return # iterate through the files and run a check hash no_corrupted_files = True for file_id in self.files: file = self.get_file_by_id(file_uuid=file_id) - no_corrupted_files = file.check_hash() + file.check_hash() + if file.health_status == FileSystemItemHealthStatus.CORRUPT: + no_corrupted_files = False # if one file in the folder is corrupted, set the folder status to corrupted if not no_corrupted_files: @@ -287,61 +313,53 @@ class Folder(FileSystemItemABC): self.sys_log.info(f"Checking hash of folder {self.name} (id: {self.uuid})") - return no_corrupted_files - - def repair(self) -> bool: + def repair(self) -> None: """Repair a corrupted Folder by setting the folder and containing files status to FileSystemItemStatus.GOOD.""" - super().repair() - - repaired = False + if self.deleted: + self.sys_log.error(f"Unable to repair deleted folder {self.name}") + return # iterate through the files in the folder for file_id in self.files: file = self.get_file_by_id(file_uuid=file_id) - repaired = file.repair() + file.repair() # set file status to good if corrupt if self.health_status == FileSystemItemHealthStatus.CORRUPT: self.health_status = FileSystemItemHealthStatus.GOOD - repaired = True + + self.health_status = FileSystemItemHealthStatus.GOOD self.sys_log.info(f"Repaired folder {self.name} (id: {self.uuid})") - return repaired - def restore(self) -> bool: - """Restore a File by setting the folder and containing files status to FileSystemItemStatus.GOOD.""" - super().restore() + def restore(self) -> None: + """ + If a Folder is corrupted, run a repair on the folder and its child files. - restored = False + If the folder is deleted, restore the folder by setting deleted status to False. + """ + pass - # iterate through the files in the folder - for file_id in self.files: - file = self.get_file_by_id(file_uuid=file_id) - restored = file.restore() - - # set file status to corrupt if good - if self.health_status == FileSystemItemHealthStatus.CORRUPT: - self.health_status = FileSystemItemHealthStatus.GOOD - restored = True - - self.sys_log.info(f"Restored folder {self.name} (id: {self.uuid})") - return restored - - def corrupt(self) -> bool: + def corrupt(self) -> None: """Corrupt a File by setting the folder and containing files status to FileSystemItemStatus.CORRUPT.""" - super().corrupt() - - corrupted = False + if self.deleted: + self.sys_log.error(f"Unable to corrupt deleted folder {self.name}") + return # iterate through the files in the folder for file_id in self.files: file = self.get_file_by_id(file_uuid=file_id) - corrupted = file.corrupt() + file.corrupt() - # set file status to corrupt if good - if self.health_status == FileSystemItemHealthStatus.GOOD: - self.health_status = FileSystemItemHealthStatus.CORRUPT - corrupted = True + # set file status to corrupt + self.health_status = FileSystemItemHealthStatus.CORRUPT self.sys_log.info(f"Corrupted folder {self.name} (id: {self.uuid})") - return corrupted + + def delete(self): + """Marks the file as deleted. Prevents agent actions from occuring.""" + if self.deleted: + self.sys_log.error(f"Unable to delete an already deleted folder {self.name}") + return + + self.deleted = True diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index f7333f97..b04174bf 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -129,7 +129,7 @@ class DatabaseService(Service): self._conn.close() # replace db file self.file_system.delete_file(folder_name=self.folder.name, file_name="downloads.db") - self.file_system.move_file( + self.file_system.copy_file( src_folder_name="downloads", src_file_name="database.db", dst_folder_name=self.folder.name ) self._db_file = self.file_system.get_file(folder_name=self.folder.name, file_name="database.db") diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py index 174c7726..94ccde83 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py @@ -44,24 +44,24 @@ def test_file_reveal_to_red_scan(file_system): def test_simulated_file_check_hash(file_system): file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") - assert file.check_hash() is True - + file.check_hash() + assert file.health_status == FileSystemItemHealthStatus.GOOD # change simulated file size file.sim_size = 0 - assert file.check_hash() is False + file.check_hash() assert file.health_status == FileSystemItemHealthStatus.CORRUPT def test_real_file_check_hash(file_system): file: File = file_system.create_file(file_name="test_file.txt", real=True) - assert file.check_hash() is True - + file.check_hash() + assert file.health_status == FileSystemItemHealthStatus.GOOD # change file content with open(file.sim_path, "a") as f: f.write("get hacked scrub lol xD\n") - assert file.check_hash() is False + file.check_hash() assert file.health_status == FileSystemItemHealthStatus.CORRUPT diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py new file mode 100644 index 00000000..f43c6b22 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py @@ -0,0 +1,89 @@ +from typing import Tuple + +import pytest + +from primaite.simulator.file_system.file_system import File, FileSystem, Folder +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus + + +@pytest.fixture(scope="function") +def populated_file_system(file_system) -> Tuple[FileSystem, Folder, File]: + """Create a file system with a folder and file.""" + folder = file_system.create_folder(folder_name="test_folder") + file = file_system.create_file(folder_name="test_folder", file_name="test_file.txt") + + return file_system, folder, file + + +def test_file_scan_request(populated_file_system): + """Test that an agent can request a file scan.""" + fs, folder, file = populated_file_system + + file.corrupt() + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + assert file.visible_health_status == FileSystemItemHealthStatus.GOOD + + fs.apply_request(request=["file", file.uuid, "scan"]) + + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_file_checkhash_request(populated_file_system): + """Test that an agent can request a file hash check.""" + fs, folder, file = populated_file_system + + fs.apply_request(request=["file", file.uuid, "checkhash"]) + + assert file.health_status == FileSystemItemHealthStatus.GOOD + file.sim_size = 0 + + fs.apply_request(request=["file", file.uuid, "checkhash"]) + + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_file_repair_request(populated_file_system): + """Test that an agent can request a file repair.""" + fs, folder, file = populated_file_system + + file.corrupt() + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + + fs.apply_request(request=["file", file.uuid, "repair"]) + assert file.health_status == FileSystemItemHealthStatus.GOOD + + +def test_file_restore_request(populated_file_system): + pass + + +def test_file_corrupt_request(populated_file_system): + """Test that an agent can request a file corruption.""" + fs, folder, file = populated_file_system + fs.apply_request(request=["file", file.uuid, "corrupt"]) + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_deleted_file_cannot_be_interacted_with(populated_file_system): + """Test that actions cannot affect deleted files.""" + fs, folder, file = populated_file_system + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + + fs.apply_request(request=["file", file.uuid, "corrupt"]) + assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT + assert ( + fs.get_file(folder_name=folder.name, file_name=file.name).visible_health_status + == FileSystemItemHealthStatus.GOOD + ) + + fs.apply_request(request=["delete", "file", folder.uuid, file.uuid]) + assert fs.get_file(folder_name=folder.name, file_name=file.name) is None + + fs.apply_request(request=["file", file.uuid, "repair"]) + fs.apply_request(request=["file", file.uuid, "scan"]) + + file = folder.deleted_files.get(file.uuid) + + assert file.health_status is not FileSystemItemHealthStatus.GOOD + assert file.visible_health_status is not FileSystemItemHealthStatus.CORRUPT diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index d26d0a4a..03c6ad12 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -1,7 +1,9 @@ import pytest +from primaite.simulator.file_system.file import File from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.file_system.file_type import FileType +from primaite.simulator.file_system.folder import Folder def test_create_folder_and_file(file_system): @@ -65,6 +67,34 @@ def test_delete_folder(file_system): assert len(file_system.deleted_folders) == 1 +def test_create_duplicate_folder(file_system): + """Test that creating a duplicate folder throws exception.""" + assert len(file_system.folders) == 1 + file_system.create_folder(folder_name="test_folder") + + assert len(file_system.folders) is 2 + with pytest.raises(Exception): + file_system.create_folder(folder_name="test_folder") + + assert len(file_system.folders) is 2 + + +def test_create_duplicate_file(file_system): + """Test that creating a duplicate file throws exception.""" + assert len(file_system.folders) == 1 + file_system.create_folder(folder_name="test_folder") + + assert len(file_system.folders) is 2 + file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + assert len(file_system.get_folder("test_folder").files) == 1 + + with pytest.raises(Exception): + file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + + assert len(file_system.get_folder("test_folder").files) == 1 + + def test_deleting_a_non_existent_folder(file_system): file_system.create_folder(folder_name="test_folder") assert len(file_system.folders) == 2 @@ -116,6 +146,23 @@ def test_copy_file(file_system): assert file_system.get_file("dst_folder", "test_file.txt").uuid != original_uuid +def test_get_file(file_system): + """Test that files can be retrieved.""" + folder: Folder = file_system.create_folder(folder_name="test_folder") + file1: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + file2: File = file_system.create_file(file_name="test_file2.txt", folder_name="test_folder") + + folder.remove_file(file2) + + assert file_system.get_file_by_id(file_uuid=file1.uuid, folder_uuid=folder.uuid) is not None + assert file_system.get_file_by_id(file_uuid=file2.uuid, folder_uuid=folder.uuid) is None + assert file_system.get_file_by_id(file_uuid=file2.uuid, folder_uuid=folder.uuid, include_deleted=True) is not None + assert file_system.get_file_by_id(file_uuid=file2.uuid, include_deleted=True) is not None + + file_system.delete_folder(folder_name="test_folder") + assert file_system.get_file_by_id(file_uuid=file2.uuid, include_deleted=True) is not None + + @pytest.mark.skip(reason="Skipping until we tackle serialisation") def test_serialisation(file_system): """Test to check that the object serialisation works correctly.""" diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py index d902c935..d6bbd285 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py @@ -8,139 +8,20 @@ from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHe @pytest.fixture(scope="function") def populated_file_system(file_system) -> Tuple[FileSystem, Folder, File]: - """Test that an agent can request a file scan.""" + """Create a file system with a folder and file.""" folder = file_system.create_folder(folder_name="test_folder") file = file_system.create_file(folder_name="test_folder", file_name="test_file.txt") return file_system, folder, file -def test_file_scan_request(populated_file_system): - """Test that an agent can request a file scan.""" - fs, folder, file = populated_file_system - - file.corrupt() - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - assert file.visible_health_status == FileSystemItemHealthStatus.GOOD - - fs.apply_request(request=["file", file.uuid, "scan"]) - - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT - - -def test_folder_scan_request(populated_file_system): - """Test that an agent can request a folder scan.""" - fs, folder, file = populated_file_system - fs.create_file(file_name="test_file2.txt", folder_name="test_folder") - - file1: File = folder.get_file_by_id(file_uuid=list(folder.files)[1]) - file2: File = folder.get_file_by_id(file_uuid=list(folder.files)[0]) - - folder.corrupt() - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD - assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD - assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD - - fs.apply_request(request=["folder", folder.uuid, "scan"]) - - folder.apply_timestep(timestep=0) - - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD - assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD - assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD - - folder.apply_timestep(timestep=1) - - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT - assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT - assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT - - -def test_file_checkhash_request(populated_file_system): - """Test that an agent can request a file hash check.""" - fs, folder, file = populated_file_system - - fs.apply_request(request=["file", file.uuid, "checkhash"]) - - assert file.health_status == FileSystemItemHealthStatus.GOOD - file.sim_size = 0 - - fs.apply_request(request=["file", file.uuid, "checkhash"]) - - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - - -def test_folder_checkhash_request(populated_file_system): - """Test that an agent can request a folder hash check.""" - fs, folder, file = populated_file_system - - fs.apply_request(request=["folder", folder.uuid, "checkhash"]) - - assert folder.health_status == FileSystemItemHealthStatus.GOOD - file.sim_size = 0 - - fs.apply_request(request=["folder", folder.uuid, "checkhash"]) - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - - -def test_file_repair_request(populated_file_system): - """Test that an agent can request a file repair.""" - fs, folder, file = populated_file_system - - file.corrupt() - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - - fs.apply_request(request=["file", file.uuid, "repair"]) - assert file.health_status == FileSystemItemHealthStatus.GOOD - - -def test_folder_repair_request(populated_file_system): - """Test that an agent can request a folder repair.""" - fs, folder, file = populated_file_system - - folder.corrupt() - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - - fs.apply_request(request=["folder", folder.uuid, "repair"]) - assert file.health_status == FileSystemItemHealthStatus.GOOD - assert folder.health_status == FileSystemItemHealthStatus.GOOD - - -def test_file_restore_request(populated_file_system): - pass - - -def test_folder_restore_request(populated_file_system): - pass - - -def test_file_corrupt_request(populated_file_system): - """Test that an agent can request a file corruption.""" - fs, folder, file = populated_file_system - fs.apply_request(request=["file", file.uuid, "corrupt"]) - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - - -def test_folder_corrupt_request(populated_file_system): - """Test that an agent can request a folder corruption.""" - fs, folder, file = populated_file_system - fs.apply_request(request=["folder", folder.uuid, "corrupt"]) - assert file.health_status == FileSystemItemHealthStatus.CORRUPT - assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - - def test_file_delete_request(populated_file_system): """Test that an agent can request a file deletion.""" fs, folder, file = populated_file_system - assert folder.get_file_by_id(file_uuid=file.uuid) is not None + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None - fs.apply_request(request=["folder", folder.uuid, "delete", file.uuid]) - assert folder.get_file_by_id(file_uuid=file.uuid) is None + fs.apply_request(request=["delete", "file", folder.uuid, file.uuid]) + assert fs.get_file(folder_name=folder.name, file_name=file.name) is None def test_folder_delete_request(populated_file_system): @@ -149,6 +30,6 @@ def test_folder_delete_request(populated_file_system): assert folder.get_file_by_id(file_uuid=file.uuid) is not None assert fs.get_folder_by_id(folder_uuid=folder.uuid) is not None - fs.apply_request(request=["delete", folder.uuid]) + fs.apply_request(request=["delete", "folder", folder.uuid]) assert fs.get_folder_by_id(folder_uuid=folder.uuid) is None - assert folder.get_file_by_id(file_uuid=file.uuid) is None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid) is None diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py index 9a12dbe9..56f2f6fb 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py @@ -19,6 +19,20 @@ def test_folder_quarantine_state(file_system): assert folder.quarantine_status() is False +def test_folder_get_file(file_system): + """Test that files can be retrieved from the folder.""" + folder: Folder = file_system.create_folder(folder_name="test_folder") + file1: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + file2: File = file_system.create_file(file_name="test_file2.txt", folder_name="test_folder") + + folder.remove_file(file2) + + assert folder.get_file_by_id(file_uuid=file1.uuid) is not None + assert folder.get_file_by_id(file_uuid=file2.uuid) is None + + assert folder.get_file_by_id(file_uuid=file2.uuid, include_deleted=True) is not None + + def test_folder_scan(file_system): """Test the ability to update visible status.""" folder: Folder = file_system.create_folder(folder_name="test_folder") @@ -107,12 +121,13 @@ def test_simulated_folder_check_hash(file_system): folder: Folder = file_system.create_folder(folder_name="test_folder") file_system.create_file(file_name="test_file.txt", folder_name="test_folder") - assert folder.check_hash() is True + folder.check_hash() + assert folder.health_status == FileSystemItemHealthStatus.GOOD # change simulated file size file = folder.get_file(file_name="test_file.txt") file.sim_size = 0 - assert folder.check_hash() is False + folder.check_hash() assert folder.health_status == FileSystemItemHealthStatus.CORRUPT @@ -120,8 +135,8 @@ def test_real_folder_check_hash(file_system): folder: Folder = file_system.create_folder(folder_name="test_folder") file_system.create_file(file_name="test_file.txt", folder_name="test_folder", real=True) - assert folder.check_hash() is True - + folder.check_hash() + assert folder.health_status == FileSystemItemHealthStatus.GOOD # change simulated file size file = folder.get_file(file_name="test_file.txt") @@ -129,5 +144,5 @@ def test_real_folder_check_hash(file_system): with open(file.sim_path, "a") as f: f.write("get hacked scrub lol xD\n") - assert folder.check_hash() is False + folder.check_hash() assert folder.health_status == FileSystemItemHealthStatus.CORRUPT diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py new file mode 100644 index 00000000..05259320 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py @@ -0,0 +1,103 @@ +from typing import Tuple + +import pytest + +from primaite.simulator.file_system.file_system import File, FileSystem, Folder +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus + + +@pytest.fixture(scope="function") +def populated_file_system(file_system) -> Tuple[FileSystem, Folder, File]: + """Create a file system with a folder and file.""" + folder = file_system.create_folder(folder_name="test_folder") + file = file_system.create_file(folder_name="test_folder", file_name="test_file.txt") + + return file_system, folder, file + + +def test_folder_scan_request(populated_file_system): + """Test that an agent can request a folder scan.""" + fs, folder, file = populated_file_system + fs.create_file(file_name="test_file2.txt", folder_name="test_folder") + + file1: File = folder.get_file_by_id(file_uuid=list(folder.files)[1]) + file2: File = folder.get_file_by_id(file_uuid=list(folder.files)[0]) + + folder.corrupt() + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD + + fs.apply_request(request=["folder", folder.uuid, "scan"]) + + folder.apply_timestep(timestep=0) + + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD + assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD + + folder.apply_timestep(timestep=1) + + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file1.visible_health_status == FileSystemItemHealthStatus.CORRUPT + assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_folder_checkhash_request(populated_file_system): + """Test that an agent can request a folder hash check.""" + fs, folder, file = populated_file_system + + fs.apply_request(request=["folder", folder.uuid, "checkhash"]) + + assert folder.health_status == FileSystemItemHealthStatus.GOOD + file.sim_size = 0 + + fs.apply_request(request=["folder", folder.uuid, "checkhash"]) + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_folder_repair_request(populated_file_system): + """Test that an agent can request a folder repair.""" + fs, folder, file = populated_file_system + + folder.corrupt() + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + + fs.apply_request(request=["folder", folder.uuid, "repair"]) + assert file.health_status == FileSystemItemHealthStatus.GOOD + assert folder.health_status == FileSystemItemHealthStatus.GOOD + + +def test_folder_restore_request(populated_file_system): + pass + + +def test_folder_corrupt_request(populated_file_system): + """Test that an agent can request a folder corruption.""" + fs, folder, file = populated_file_system + fs.apply_request(request=["folder", folder.uuid, "corrupt"]) + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + assert folder.health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_deleted_folder_and_its_files_cannot_be_interacted_with(populated_file_system): + """Test that actions cannot affect deleted folder and its child files.""" + fs, folder, file = populated_file_system + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + + fs.apply_request(request=["file", file.uuid, "corrupt"]) + assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT + + fs.apply_request(request=["delete", "folder", folder.uuid]) + assert fs.get_file(folder_name=folder.name, file_name=file.name) is None + + fs.apply_request(request=["file", file.uuid, "repair"]) + + deleted_folder = fs.deleted_folders.get(folder.uuid) + deleted_file = deleted_folder.deleted_files.get(file.uuid) + + assert deleted_file.health_status is not FileSystemItemHealthStatus.GOOD From e70ceec716e498b32bbc39d35579a82214b285a8 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Mon, 6 Nov 2023 10:22:08 +0000 Subject: [PATCH 276/980] #1962: folder/file restore logic --- src/primaite/simulator/file_system/file.py | 21 +++-- .../simulator/file_system/file_system.py | 78 +++++++++++++++---- src/primaite/simulator/file_system/folder.py | 32 ++++++-- .../_simulator/_file_system/test_file.py | 10 ++- .../_file_system/test_file_system_actions.py | 53 +++++++++++++ 5 files changed, 161 insertions(+), 33 deletions(-) diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index 04502c0f..d9b02e8e 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -163,14 +163,6 @@ class File(FileSystemItemABC): path = self.folder.name + "/" + self.name self.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") - def restore(self) -> None: - """Restore a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" - if self.health_status == FileSystemItemHealthStatus.CORRUPT: - self.health_status = FileSystemItemHealthStatus.GOOD - - path = self.folder.name + "/" + self.name - self.sys_log.info(f"Restored file {self.sim_path if self.sim_path else path}") - def corrupt(self) -> None: """Corrupt a File by setting the status to FileSystemItemStatus.CORRUPT.""" if self.deleted: @@ -184,10 +176,17 @@ class File(FileSystemItemABC): path = self.folder.name + "/" + self.name self.sys_log.info(f"Corrupted file {self.sim_path if self.sim_path else path}") - def restore(self) -> bool: + def restore(self) -> None: """Determines if the file needs to be repaired or unmarked as deleted.""" - super().restore() - return True + if self.deleted: + self.deleted = False + return + + if self.health_status == FileSystemItemHealthStatus.CORRUPT: + self.health_status = FileSystemItemHealthStatus.GOOD + + path = self.folder.name + "/" + self.name + self.sys_log.info(f"Restored file {self.sim_path if self.sim_path else path}") def delete(self): """Marks the file as deleted.""" diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 7f2d41e5..b1688045 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -49,12 +49,27 @@ class FileSystem(SimComponent): name="folder", request_type=RequestType(func=lambda request, context: self.delete_folder_by_id(folder_uuid=request[0])), ) - rm.add_request( name="delete", request_type=RequestType(func=self._delete_manager), ) + self._restore_manager = RequestManager() + self._restore_manager.add_request( + name="file", + request_type=RequestType( + func=lambda request, context: self.restore_file(folder_uuid=request[0], file_uuid=request[1]) + ), + ) + self._restore_manager.add_request( + name="folder", + request_type=RequestType(func=lambda request, context: self.restore_folder(folder_uuid=request[0])), + ) + rm.add_request( + name="restore", + request_type=RequestType(func=self._restore_manager), + ) + self._folder_request_manager = RequestManager() rm.add_request("folder", RequestType(func=self._folder_request_manager)) @@ -164,13 +179,19 @@ class FileSystem(SimComponent): """ return self._folders_by_name.get(folder_name) - def get_folder_by_id(self, folder_uuid: str) -> Optional[Folder]: + def get_folder_by_id(self, folder_uuid: str, include_deleted: bool = False) -> Optional[Folder]: """ Get a folder by its uuid if it exists. :param: folder_uuid: The folder uuid. + :param: include_deleted: If true, the deleted folders will also be checked :return: The matching Folder. """ + if include_deleted: + folder = self.deleted_folders.get(folder_uuid) + if folder: + return folder + return self.folders.get(folder_uuid) ############################################################### @@ -244,7 +265,7 @@ class FileSystem(SimComponent): :param: include_deleted: If true, the deleted files will also be checked :return: An instance of File if it exists, otherwise `None`. """ - folder = self.folders.get(folder_uuid) + folder = self.get_folder_by_id(folder_uuid=folder_uuid, include_deleted=include_deleted) if folder: return folder.get_file_by_id(file_uuid=file_uuid, include_deleted=include_deleted) @@ -291,7 +312,11 @@ class FileSystem(SimComponent): if folder: file = folder.get_file_by_id(file_uuid=file_uuid) - self.delete_file(folder_name=folder.name, file_name=file.name) + + if file: + self.delete_file(folder_name=folder.name, file_name=file.name) + else: + self.sys_log.error(f"Unable to delete file that does not exist. (id: {file_uuid})") def move_file(self, src_folder_name: str, src_file_name: str, dst_folder_name: str): """ @@ -387,20 +412,47 @@ class FileSystem(SimComponent): for folder_id in self.folders: self.folders[folder_id].reveal_to_red(instant_scan=instant_scan) - def restore_folder(self, folder_id: str): - """TODO.""" - pass + def restore_folder(self, folder_uuid: str): + """ + Restore a folder. - def restore_file(self, folder_id: str, file_id: str): + Checks the current folder's status and applies the correct fix for the folder. + + :param: folder_uuid: id of the folder to restore + :type: folder_uuid: str + """ + folder = self.get_folder_by_id(folder_uuid=folder_uuid, include_deleted=True) + + if folder is None: + self.sys_log.error(f"Unable to restore folder with uuid {folder_uuid}. Folder does not exist.") + return + + folder.restore() + self.folders[folder.uuid] = folder + self._folders_by_name[folder.name] = folder + + if folder.deleted: + self.deleted_folders.pop(folder.uuid) + + def restore_file(self, folder_uuid: str, file_uuid: str): """ Restore a file. Checks the current file's status and applies the correct fix for the file. - :param: folder_id: id of the folder where the file is stored - :type: folder_id: str + :param: folder_uuid: id of the folder where the file is stored + :type: folder_uuid: str - :param: folder_id: id of the file to restore - :type: folder_id: str + :param: file_uuid: id of the file to restore + :type: file_uuid: str """ - pass + folder = self.get_folder_by_id(folder_uuid=folder_uuid, include_deleted=True) + + if folder: + file = folder.get_file_by_id(file_uuid=file_uuid, include_deleted=True) + + if file is None: + self.sys_log.error(f"Unable to restore file with uuid {file_uuid}. File does not exist.") + return + + folder.restore_file(file_uuid=file_uuid) diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index e12d4e12..f19f4efa 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -210,15 +210,24 @@ class Folder(FileSystemItemABC): self.files = {} self._files_by_name = {} - def restore_file(self, file: Optional[File]): + def restore_file(self, file_uuid: str): """ Restores a file. - The method can take a File object or a file id. - - :param file: The file to restore + :param file_uuid: The id of the file to restore """ - pass + # if the file was not deleted, run a repair + file = self.get_file_by_id(file_uuid=file_uuid, include_deleted=True) + if not file: + self.sys_log.error(f"Unable to restore file with uuid {file_uuid}. File does not exist.") + return + + file.restore() + self.files[file.uuid] = file + self._files_by_name[file.name] = file + + if file.deleted: + self.deleted_files.pop(file_uuid) def quarantine(self): """Quarantines the File System Folder.""" @@ -338,7 +347,18 @@ class Folder(FileSystemItemABC): If the folder is deleted, restore the folder by setting deleted status to False. """ - pass + # repair all files + for file_id in self.files: + self.restore_file(file_uuid=file_id) + + deleted_files = self.deleted_files.copy() + for file_id in deleted_files: + self.restore_file(file_uuid=file_id) + + if self.deleted: + self.deleted = False + elif self.health_status == FileSystemItemHealthStatus.CORRUPT: + self.health_status = FileSystemItemHealthStatus.GOOD def corrupt(self) -> None: """Corrupt a File by setting the folder and containing files status to FileSystemItemStatus.CORRUPT.""" diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py index 94ccde83..32efe029 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py @@ -65,14 +65,18 @@ def test_real_file_check_hash(file_system): assert file.health_status == FileSystemItemHealthStatus.CORRUPT -def test_file_corrupt_repair(file_system): +def test_file_corrupt_repair_restore(file_system): """Test the ability to corrupt and repair files.""" file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") file.corrupt() - assert file.health_status == FileSystemItemHealthStatus.CORRUPT file.repair() - + assert file.health_status == FileSystemItemHealthStatus.GOOD + + file.corrupt() + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + + file.restore() assert file.health_status == FileSystemItemHealthStatus.GOOD diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py index d6bbd285..81616420 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py @@ -33,3 +33,56 @@ def test_folder_delete_request(populated_file_system): fs.apply_request(request=["delete", "folder", folder.uuid]) assert fs.get_folder_by_id(folder_uuid=folder.uuid) is None assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid) is None + + +def test_file_restore_request(populated_file_system): + """Test that an agent can request that a file can be restored.""" + fs, folder, file = populated_file_system + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid) is not None + + fs.apply_request(request=["delete", "file", folder.uuid, file.uuid]) + assert fs.get_file(folder_name=folder.name, file_name=file.name) is None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is True + + fs.apply_request(request=["restore", "file", folder.uuid, file.uuid]) + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + assert fs.get_file(folder_name=folder.name, file_name=file.name).deleted is False + + fs.apply_request(request=["file", file.uuid, "corrupt"]) + assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT + + fs.apply_request(request=["restore", "file", folder.uuid, file.uuid]) + assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.GOOD + + +def test_folder_restore_request(populated_file_system): + """Test that an agent can request that a folder can be restored.""" + fs, folder, file = populated_file_system + assert fs.get_folder_by_id(folder_uuid=folder.uuid) is not None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid) is not None + + # delete folder + fs.apply_request(request=["delete", "folder", folder.uuid]) + assert fs.get_folder(folder_name=folder.name) is None + assert fs.get_folder_by_id(folder_uuid=folder.uuid, include_deleted=True).deleted is True + + assert fs.get_file(folder_name=folder.name, file_name=file.name) is None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is True + + # restore folder + fs.apply_request(request=["restore", "folder", folder.uuid]) + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + assert fs.get_file(folder_name=folder.name, file_name=file.name).deleted is False + + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is False + + # corrupt folder + fs.apply_request(request=["folder", folder.uuid, "corrupt"]) + assert fs.get_folder(folder_name=folder.name).health_status == FileSystemItemHealthStatus.CORRUPT + assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT + + # restore folder + fs.apply_request(request=["restore", "folder", folder.uuid]) + assert fs.get_folder(folder_name=folder.name).health_status == FileSystemItemHealthStatus.GOOD + assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.GOOD From 535c1b19ab27f9dea48006b349e7ce28812867eb Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Mon, 6 Nov 2023 11:12:06 +0000 Subject: [PATCH 277/980] #1962: attempt to make the timestep actions look neater + adding logic that allows restoring a folder take multiple timesteps --- src/primaite/simulator/file_system/folder.py | 96 +++++++++++++------ .../_file_system/test_file_system_actions.py | 36 ++++++- .../_simulator/_file_system/test_folder.py | 2 + .../_file_system/test_folder_actions.py | 1 + 4 files changed, 104 insertions(+), 31 deletions(-) diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index f19f4efa..67e93e16 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -22,11 +22,23 @@ class Folder(FileSystemItemABC): deleted_files: Dict[str, File] = {} "Files that have been deleted." - scan_duration: int = -1 - "How many timesteps to complete a scan." + scan_duration: int = 3 + "How many timesteps to complete a scan. Default 3 timesteps" - red_scan_duration: int = -1 - "How many timesteps to complete reveal to red scan." + scan_countdown: int = 0 + "Time steps needed until scan completion." + + red_scan_duration: int = 3 + "How many timesteps to complete reveal to red scan. Default 3 timesteps" + + red_scan_countdown: int = 0 + "Time steps needed until red scan completion." + + restore_duration: int = 3 + "How many timesteps to complete a restore. Default 3 timesteps" + + restore_countdown: int = 0 + "Time steps needed until restore completion." def __init__(self, **kwargs): """ @@ -55,6 +67,7 @@ class Folder(FileSystemItemABC): """ state = super().describe_state() state["files"] = {file.name: file.describe_state() for uuid, file in self.files.items()} + state["deleted_files"] = {file.name: file.describe_state() for uuid, file in self.deleted_files.items()} return state def show(self, markdown: bool = False): @@ -94,30 +107,57 @@ class Folder(FileSystemItemABC): """ super().apply_timestep(timestep=timestep) - # scan files each timestep - if self.scan_duration >= 0: - self.scan_duration -= 1 + self._scan_timestep() - if self.scan_duration == 0: + self._reveal_to_red_timestep() + + self._restoring_timestep() + + # apply timestep to files in folder + for file_id in self.files: + self.files[file_id].apply_timestep(timestep=timestep) + + def _scan_timestep(self) -> None: + """Apply the scan action timestep.""" + if self.scan_countdown >= 0: + self.scan_countdown -= 1 + + if self.scan_countdown == 0: for file_id in self.files: file = self.get_file_by_id(file_uuid=file_id) file.scan() if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: self.visible_health_status = FileSystemItemHealthStatus.CORRUPT - # red scan file at each step - if self.red_scan_duration >= 0: - self.red_scan_duration -= 1 + def _reveal_to_red_timestep(self) -> None: + """Apply reveal to red timestep.""" + if self.red_scan_countdown >= 0: + self.red_scan_countdown -= 1 - if self.red_scan_duration == 0: + if self.red_scan_countdown == 0: self.revealed_to_red = True for file_id in self.files: file = self.get_file_by_id(file_uuid=file_id) file.reveal_to_red() - # apply timestep to files in folder - for file_id in self.files: - self.files[file_id].apply_timestep(timestep=timestep) + def _restoring_timestep(self) -> None: + """Apply restoring timestep.""" + if self.restore_countdown >= 0: + self.restore_countdown -= 1 + + if self.restore_countdown == 0: + # repair all files + for file_id in self.files: + self.restore_file(file_uuid=file_id) + + deleted_files = self.deleted_files.copy() + for file_id in deleted_files: + self.restore_file(file_uuid=file_id) + + if self.deleted: + self.deleted = False + elif self.health_status in [FileSystemItemHealthStatus.CORRUPT, FileSystemItemHealthStatus.RESTORING]: + self.health_status = FileSystemItemHealthStatus.GOOD def get_file(self, file_name: str) -> Optional[File]: """ @@ -259,9 +299,9 @@ class Folder(FileSystemItemABC): self.visible_health_status = FileSystemItemHealthStatus.CORRUPT return - if self.scan_duration <= 0: + if self.scan_countdown <= 0: # scan one file per timestep - self.scan_duration = len(self.files) + self.scan_countdown = self.scan_duration self.sys_log.info(f"Scanning folder {self.name} (id: {self.uuid})") else: # scan already in progress @@ -284,9 +324,9 @@ class Folder(FileSystemItemABC): file.reveal_to_red() return - if self.red_scan_duration <= 0: + if self.red_scan_countdown <= 0: # scan one file per timestep - self.red_scan_duration = len(self.files) + self.red_scan_countdown = self.red_scan_duration self.sys_log.info(f"Folder revealed to red agent: {self.name} (id: {self.uuid})") else: # scan already in progress @@ -347,18 +387,16 @@ class Folder(FileSystemItemABC): If the folder is deleted, restore the folder by setting deleted status to False. """ - # repair all files - for file_id in self.files: - self.restore_file(file_uuid=file_id) - - deleted_files = self.deleted_files.copy() - for file_id in deleted_files: - self.restore_file(file_uuid=file_id) - if self.deleted: self.deleted = False - elif self.health_status == FileSystemItemHealthStatus.CORRUPT: - self.health_status = FileSystemItemHealthStatus.GOOD + + if self.restore_countdown <= 0: + self.restore_countdown = self.restore_duration + self.health_status = FileSystemItemHealthStatus.RESTORING + self.sys_log.info(f"Restoring folder: {self.name} (id: {self.uuid})") + else: + # scan already in progress + self.sys_log.info(f"Folder restoration already in progress {self.name} (id: {self.uuid})") def corrupt(self) -> None: """Corrupt a File by setting the folder and containing files status to FileSystemItemStatus.CORRUPT.""" diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py index 81616420..29642a8d 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py @@ -71,7 +71,25 @@ def test_folder_restore_request(populated_file_system): # restore folder fs.apply_request(request=["restore", "folder", folder.uuid]) + fs.apply_timestep(timestep=0) + assert fs.get_folder(folder_name=folder.name) is not None + assert ( + fs.get_folder_by_id(folder_uuid=folder.uuid, include_deleted=True).health_status + == FileSystemItemHealthStatus.RESTORING + ) + assert fs.get_folder_by_id(folder_uuid=folder.uuid, include_deleted=True).deleted is False + + assert fs.get_file(folder_name=folder.name, file_name=file.name) is None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is True + + fs.apply_timestep(timestep=1) + fs.apply_timestep(timestep=2) + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + assert ( + fs.get_file(folder_name=folder.name, file_name=file.name).health_status + is not FileSystemItemHealthStatus.RESTORING + ) assert fs.get_file(folder_name=folder.name, file_name=file.name).deleted is False assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None @@ -84,5 +102,19 @@ def test_folder_restore_request(populated_file_system): # restore folder fs.apply_request(request=["restore", "folder", folder.uuid]) - assert fs.get_folder(folder_name=folder.name).health_status == FileSystemItemHealthStatus.GOOD - assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.GOOD + fs.apply_timestep(timestep=0) + assert fs.get_folder(folder_name=folder.name).health_status == FileSystemItemHealthStatus.RESTORING + assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT + + fs.apply_timestep(timestep=1) + fs.apply_timestep(timestep=2) + + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + assert ( + fs.get_file(folder_name=folder.name, file_name=file.name).health_status + is not FileSystemItemHealthStatus.RESTORING + ) + assert fs.get_file(folder_name=folder.name, file_name=file.name).deleted is False + + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is False diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py index 56f2f6fb..bada2dab 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py @@ -64,6 +64,7 @@ def test_folder_scan(file_system): assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD folder.apply_timestep(timestep=1) + folder.apply_timestep(timestep=2) assert folder.health_status == FileSystemItemHealthStatus.CORRUPT assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT @@ -93,6 +94,7 @@ def test_folder_reveal_to_red_scan(file_system): assert file2.revealed_to_red is False folder.apply_timestep(timestep=1) + folder.apply_timestep(timestep=2) assert folder.revealed_to_red is True assert file1.revealed_to_red is True diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py index 05259320..9be4d5d1 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py @@ -39,6 +39,7 @@ def test_folder_scan_request(populated_file_system): assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD folder.apply_timestep(timestep=1) + folder.apply_timestep(timestep=2) assert folder.health_status == FileSystemItemHealthStatus.CORRUPT assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT From eba10ae5ef3ebab0d95629b9fb34edc6a89f936a Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Mon, 6 Nov 2023 11:56:44 +0000 Subject: [PATCH 278/980] #1962: clean up tests + improve the show command which shows the folders and files in file system --- .../simulator/file_system/file_system.py | 16 ++-- src/primaite/simulator/file_system/folder.py | 4 +- .../_file_system/test_file_actions.py | 18 +++- .../_file_system/test_file_system.py | 26 ++++++ .../_file_system/test_file_system_actions.py | 87 +------------------ .../_file_system/test_folder_actions.py | 63 +++++++++++++- 6 files changed, 121 insertions(+), 93 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index b1688045..41f02270 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -94,7 +94,7 @@ class FileSystem(SimComponent): :param markdown: Flag indicating if output should be in markdown format. :param full: Flag indicating if to show full files. """ - headers = ["Folder", "Size"] + headers = ["Folder", "Size", "Deleted"] if full: headers[0] = "File Path" table = PrettyTable(headers) @@ -102,12 +102,17 @@ class FileSystem(SimComponent): table.set_style(MARKDOWN) table.align = "l" table.title = f"{self.sys_log.hostname} File System" - for folder in self.folders.values(): + folders = {**self.folders, **self.deleted_folders} + for folder in folders.values(): if not full: - table.add_row([folder.name, folder.size_str]) + table.add_row([folder.name, folder.size_str, folder.deleted]) else: - for file in folder.files.values(): - table.add_row([file.path, file.size_str]) + files = {**folder.files, **folder.deleted_files} + if not files: + table.add_row([folder.name, folder.size_str, folder.deleted]) + else: + for file in files.values(): + table.add_row([file.path, file.size_str, file.deleted]) if full: print(table.get_string(sortby="File Path")) else: @@ -380,6 +385,7 @@ class FileSystem(SimComponent): """ state = super().describe_state() state["folders"] = {folder.name: folder.describe_state() for folder in self.folders.values()} + state["deleted_folders"] = {folder.name: folder.describe_state() for folder in self.deleted_folders.values()} return state def apply_timestep(self, timestep: int) -> None: diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 67e93e16..f0d55ef8 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -76,13 +76,13 @@ class Folder(FileSystemItemABC): :param markdown: Whether to display the table in Markdown format or not. Default is `False`. """ - table = PrettyTable(["File", "Size"]) + table = PrettyTable(["File", "Size", "Deleted"]) if markdown: table.set_style(MARKDOWN) table.align = "l" table.title = f"{self.sys_log.hostname} File System Folder ({self.name})" for file in self.files.values(): - table.add_row([file.name, file.size_str]) + table.add_row([file.name, file.size_str, file.deleted]) print(table.get_string(sortby="File")) @property diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py index f43c6b22..44354325 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py @@ -55,7 +55,23 @@ def test_file_repair_request(populated_file_system): def test_file_restore_request(populated_file_system): - pass + """Test that an agent can request that a file can be restored.""" + fs, folder, file = populated_file_system + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid) is not None + + fs.apply_request(request=["delete", "file", folder.uuid, file.uuid]) + assert fs.get_file(folder_name=folder.name, file_name=file.name) is None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is True + + fs.apply_request(request=["restore", "file", folder.uuid, file.uuid]) + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + assert fs.get_file(folder_name=folder.name, file_name=file.name).deleted is False + + fs.apply_request(request=["file", file.uuid, "corrupt"]) + assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT + + fs.apply_request(request=["restore", "file", folder.uuid, file.uuid]) + assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.GOOD def test_file_corrupt_request(populated_file_system): diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 03c6ad12..86baa1f8 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -18,6 +18,8 @@ def test_create_folder_and_file(file_system): assert file_system.get_folder("test_folder").get_file("test_file.txt") + file_system.show(full=True) + def test_create_file_no_folder(file_system): """Tests that creating a file without a folder creates a folder and sets that as the file's parent.""" @@ -27,6 +29,8 @@ def test_create_file_no_folder(file_system): assert file_system.get_folder("root").get_file("test_file.txt").file_type == FileType.TXT assert file_system.get_folder("root").get_file("test_file.txt").size == 10 + file_system.show(full=True) + def test_delete_file(file_system): """Tests that a file can be deleted.""" @@ -39,6 +43,8 @@ def test_delete_file(file_system): assert len(file_system.get_folder("root").files) == 0 assert len(file_system.get_folder("root").deleted_files) == 1 + file_system.show(full=True) + def test_delete_non_existent_file(file_system): """Tests deleting a non existent file.""" @@ -56,6 +62,8 @@ def test_delete_non_existent_file(file_system): # The folder should still have 1 file assert len(file_system.get_folder("root").files) == 1 + file_system.show(full=True) + def test_delete_folder(file_system): file_system.create_folder(folder_name="test_folder") @@ -66,6 +74,8 @@ def test_delete_folder(file_system): assert len(file_system.deleted_folders) == 1 + file_system.show(full=True) + def test_create_duplicate_folder(file_system): """Test that creating a duplicate folder throws exception.""" @@ -78,6 +88,8 @@ def test_create_duplicate_folder(file_system): assert len(file_system.folders) is 2 + file_system.show(full=True) + def test_create_duplicate_file(file_system): """Test that creating a duplicate file throws exception.""" @@ -94,6 +106,8 @@ def test_create_duplicate_file(file_system): assert len(file_system.get_folder("test_folder").files) == 1 + file_system.show(full=True) + def test_deleting_a_non_existent_folder(file_system): file_system.create_folder(folder_name="test_folder") @@ -102,6 +116,8 @@ def test_deleting_a_non_existent_folder(file_system): file_system.delete_folder(folder_name="does not exist!") assert len(file_system.folders) == 2 + file_system.show(full=True) + def test_deleting_root_folder_fails(file_system): assert len(file_system.folders) == 1 @@ -109,6 +125,8 @@ def test_deleting_root_folder_fails(file_system): file_system.delete_folder(folder_name="root") assert len(file_system.folders) == 1 + file_system.show(full=True) + def test_move_file(file_system): """Tests the file move function.""" @@ -127,6 +145,8 @@ def test_move_file(file_system): assert len(file_system.get_folder("dst_folder").files) == 1 assert file_system.get_file("dst_folder", "test_file.txt").uuid == original_uuid + file_system.show(full=True) + def test_copy_file(file_system): """Tests the file copy function.""" @@ -145,6 +165,8 @@ def test_copy_file(file_system): assert len(file_system.get_folder("dst_folder").files) == 1 assert file_system.get_file("dst_folder", "test_file.txt").uuid != original_uuid + file_system.show(full=True) + def test_get_file(file_system): """Test that files can be retrieved.""" @@ -162,6 +184,8 @@ def test_get_file(file_system): file_system.delete_folder(folder_name="test_folder") assert file_system.get_file_by_id(file_uuid=file2.uuid, include_deleted=True) is not None + file_system.show(full=True) + @pytest.mark.skip(reason="Skipping until we tackle serialisation") def test_serialisation(file_system): @@ -172,3 +196,5 @@ def test_serialisation(file_system): deserialised_file_sys = FileSystem.model_validate_json(serialised_file_sys) assert file_system.model_dump_json() == deserialised_file_sys.model_dump_json() + + file_system.show(full=True) diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py index 29642a8d..30c0938e 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py @@ -23,6 +23,8 @@ def test_file_delete_request(populated_file_system): fs.apply_request(request=["delete", "file", folder.uuid, file.uuid]) assert fs.get_file(folder_name=folder.name, file_name=file.name) is None + fs.show(full=True) + def test_folder_delete_request(populated_file_system): """Test that an agent can request a folder deletion.""" @@ -34,87 +36,4 @@ def test_folder_delete_request(populated_file_system): assert fs.get_folder_by_id(folder_uuid=folder.uuid) is None assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid) is None - -def test_file_restore_request(populated_file_system): - """Test that an agent can request that a file can be restored.""" - fs, folder, file = populated_file_system - assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid) is not None - - fs.apply_request(request=["delete", "file", folder.uuid, file.uuid]) - assert fs.get_file(folder_name=folder.name, file_name=file.name) is None - assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is True - - fs.apply_request(request=["restore", "file", folder.uuid, file.uuid]) - assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None - assert fs.get_file(folder_name=folder.name, file_name=file.name).deleted is False - - fs.apply_request(request=["file", file.uuid, "corrupt"]) - assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT - - fs.apply_request(request=["restore", "file", folder.uuid, file.uuid]) - assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.GOOD - - -def test_folder_restore_request(populated_file_system): - """Test that an agent can request that a folder can be restored.""" - fs, folder, file = populated_file_system - assert fs.get_folder_by_id(folder_uuid=folder.uuid) is not None - assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid) is not None - - # delete folder - fs.apply_request(request=["delete", "folder", folder.uuid]) - assert fs.get_folder(folder_name=folder.name) is None - assert fs.get_folder_by_id(folder_uuid=folder.uuid, include_deleted=True).deleted is True - - assert fs.get_file(folder_name=folder.name, file_name=file.name) is None - assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is True - - # restore folder - fs.apply_request(request=["restore", "folder", folder.uuid]) - fs.apply_timestep(timestep=0) - assert fs.get_folder(folder_name=folder.name) is not None - assert ( - fs.get_folder_by_id(folder_uuid=folder.uuid, include_deleted=True).health_status - == FileSystemItemHealthStatus.RESTORING - ) - assert fs.get_folder_by_id(folder_uuid=folder.uuid, include_deleted=True).deleted is False - - assert fs.get_file(folder_name=folder.name, file_name=file.name) is None - assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is True - - fs.apply_timestep(timestep=1) - fs.apply_timestep(timestep=2) - - assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None - assert ( - fs.get_file(folder_name=folder.name, file_name=file.name).health_status - is not FileSystemItemHealthStatus.RESTORING - ) - assert fs.get_file(folder_name=folder.name, file_name=file.name).deleted is False - - assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None - assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is False - - # corrupt folder - fs.apply_request(request=["folder", folder.uuid, "corrupt"]) - assert fs.get_folder(folder_name=folder.name).health_status == FileSystemItemHealthStatus.CORRUPT - assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT - - # restore folder - fs.apply_request(request=["restore", "folder", folder.uuid]) - fs.apply_timestep(timestep=0) - assert fs.get_folder(folder_name=folder.name).health_status == FileSystemItemHealthStatus.RESTORING - assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT - - fs.apply_timestep(timestep=1) - fs.apply_timestep(timestep=2) - - assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None - assert ( - fs.get_file(folder_name=folder.name, file_name=file.name).health_status - is not FileSystemItemHealthStatus.RESTORING - ) - assert fs.get_file(folder_name=folder.name, file_name=file.name).deleted is False - - assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None - assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is False + fs.show(full=True) diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py index 9be4d5d1..86db147a 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py @@ -74,7 +74,68 @@ def test_folder_repair_request(populated_file_system): def test_folder_restore_request(populated_file_system): - pass + """Test that an agent can request that a folder can be restored.""" + fs, folder, file = populated_file_system + assert fs.get_folder_by_id(folder_uuid=folder.uuid) is not None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid) is not None + + # delete folder + fs.apply_request(request=["delete", "folder", folder.uuid]) + assert fs.get_folder(folder_name=folder.name) is None + assert fs.get_folder_by_id(folder_uuid=folder.uuid, include_deleted=True).deleted is True + + assert fs.get_file(folder_name=folder.name, file_name=file.name) is None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is True + + # restore folder + fs.apply_request(request=["restore", "folder", folder.uuid]) + fs.apply_timestep(timestep=0) + assert fs.get_folder(folder_name=folder.name) is not None + assert ( + fs.get_folder_by_id(folder_uuid=folder.uuid, include_deleted=True).health_status + == FileSystemItemHealthStatus.RESTORING + ) + assert fs.get_folder_by_id(folder_uuid=folder.uuid, include_deleted=True).deleted is False + + assert fs.get_file(folder_name=folder.name, file_name=file.name) is None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is True + + fs.apply_timestep(timestep=1) + fs.apply_timestep(timestep=2) + + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + assert ( + fs.get_file(folder_name=folder.name, file_name=file.name).health_status + is not FileSystemItemHealthStatus.RESTORING + ) + assert fs.get_file(folder_name=folder.name, file_name=file.name).deleted is False + + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is False + + # corrupt folder + fs.apply_request(request=["folder", folder.uuid, "corrupt"]) + assert fs.get_folder(folder_name=folder.name).health_status == FileSystemItemHealthStatus.CORRUPT + assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT + + # restore folder + fs.apply_request(request=["restore", "folder", folder.uuid]) + fs.apply_timestep(timestep=0) + assert fs.get_folder(folder_name=folder.name).health_status == FileSystemItemHealthStatus.RESTORING + assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT + + fs.apply_timestep(timestep=1) + fs.apply_timestep(timestep=2) + + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + assert ( + fs.get_file(folder_name=folder.name, file_name=file.name).health_status + is not FileSystemItemHealthStatus.RESTORING + ) + assert fs.get_file(folder_name=folder.name, file_name=file.name).deleted is False + + assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None + assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is False def test_folder_corrupt_request(populated_file_system): From e0d694a7362767f13279db28a9f1759f6cace502 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 7 Nov 2023 14:00:08 +0000 Subject: [PATCH 279/980] #2025: added GATE installation as part of pipeline --- .azure/azure-ci-build-pipeline.yaml | 11 +++++++++++ src/primaite/game/agent/observations.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 9070270a..2b1af5f4 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -81,6 +81,17 @@ stages: displayName: 'Install PrimAITE' condition: eq( variables['Agent.OS'], 'Windows_NT' ) + - script: | + GATE_WHEEL=$(ls ./GATE/arcd_gate*.whl) + python -m pip install GATE_WHEEL[dev] + displayName: 'Install GATE' + condition: or(eq( variables['Agent.OS'], 'Linux' ), eq( variables['Agent.OS'], 'Darwin' )) + + - script: | + forfiles /p GATE\ /m *.whl /c "cmd /c python -m pip install @file[dev]" + displayName: 'Install GATE' + condition: eq( variables['Agent.OS'], 'Windows_NT' ) + - script: | primaite setup displayName: 'Perform PrimAITE Setup' diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 8eb322bd..a3bafeea 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -585,7 +585,7 @@ class AclObservation(AbstractObservation): self, node_ip_to_id: Dict[str, int], ports: List[int], - protocols: list[str], + protocols: List[str], where: Optional[Tuple[str]] = None, num_rules: int = 10, ) -> None: From d4679bb0e3f42bdcca5b5172ed1a91e787c3f262 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Tue, 7 Nov 2023 14:09:22 +0000 Subject: [PATCH 280/980] #2025: Missing character for GATE path --- .azure/azure-ci-build-pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 2b1af5f4..efeba284 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -83,7 +83,7 @@ stages: - script: | GATE_WHEEL=$(ls ./GATE/arcd_gate*.whl) - python -m pip install GATE_WHEEL[dev] + python -m pip install $GATE_WHEEL[dev] displayName: 'Install GATE' condition: or(eq( variables['Agent.OS'], 'Linux' ), eq( variables['Agent.OS'], 'Darwin' )) From be4a4678770e51899a3919aeae2d3c903f6d5d04 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Wed, 8 Nov 2023 10:48:41 +0000 Subject: [PATCH 281/980] #1962: revert pulling from src --- src/primaite/cli.py | 10 ++--- src/primaite/game/agent/GATE_agents.py | 8 ++-- src/primaite/game/agent/actions.py | 4 +- src/primaite/game/agent/interface.py | 6 +-- src/primaite/game/agent/observations.py | 4 +- src/primaite/game/agent/rewards.py | 4 +- src/primaite/game/agent/scripted_agents.py | 2 +- src/primaite/game/session.py | 42 +++++++++---------- src/primaite/main.py | 6 +-- src/primaite/simulator/domain/account.py | 2 +- src/primaite/simulator/domain/controller.py | 4 +- src/primaite/simulator/file_system/file.py | 4 +- .../simulator/file_system/file_system.py | 10 ++--- .../file_system/file_system_item_abc.py | 4 +- src/primaite/simulator/file_system/folder.py | 6 +-- src/primaite/simulator/network/container.py | 12 +++--- .../simulator/network/hardware/base.py | 32 +++++++------- .../network/hardware/nodes/computer.py | 8 ++-- .../network/hardware/nodes/router.py | 12 +++--- .../network/hardware/nodes/server.py | 2 +- .../network/hardware/nodes/switch.py | 6 +-- src/primaite/simulator/network/networks.py | 28 ++++++------- .../simulator/network/protocols/arp.py | 2 +- .../simulator/network/protocols/dns.py | 2 +- .../simulator/network/protocols/ftp.py | 2 +- .../simulator/network/protocols/http.py | 2 +- .../network/transmission/data_link_layer.py | 12 +++--- src/primaite/simulator/sim_container.py | 6 +-- .../system/applications/application.py | 2 +- .../system/applications/database_client.py | 8 ++-- .../system/applications/web_browser.py | 10 ++--- .../simulator/system/core/packet_capture.py | 2 +- .../simulator/system/core/session_manager.py | 14 +++---- .../simulator/system/core/software_manager.py | 20 ++++----- src/primaite/simulator/system/core/sys_log.py | 2 +- .../simulator/system/processes/process.py | 2 +- .../services/database/database_service.py | 14 +++---- .../system/services/dns/dns_client.py | 10 ++--- .../system/services/dns/dns_server.py | 8 ++-- .../system/services/ftp/ftp_client.py | 14 +++---- .../system/services/ftp/ftp_server.py | 10 ++--- .../system/services/ftp/ftp_service.py | 8 ++-- .../red_services/data_manipulation_bot.py | 2 +- .../simulator/system/services/service.py | 4 +- .../system/services/web_server/web_server.py | 10 ++--- src/primaite/simulator/system/software.py | 10 ++--- src/primaite/utils/package_data.py | 2 +- src/primaite/utils/session_output_writer.py | 4 +- tests/conftest.py | 24 +++++------ .../test_uc2_data_manipulation_scenario.py | 10 ++--- .../test_action_integration.py | 12 +++--- .../test_permission_system.py | 4 +- .../game_layer/test_observations.py | 6 +-- .../network/test_frame_transmission.py | 2 +- .../network/test_link_connection.py | 2 +- .../network/test_network_creation.py | 4 +- .../network/test_nic_link_connection.py | 2 +- .../integration_tests/network/test_routing.py | 8 ++-- .../network/test_switched_network.py | 8 ++-- .../system/test_database_on_node.py | 8 ++-- .../system/test_dns_client_server.py | 10 ++--- .../system/test_ftp_client_server.py | 10 ++--- .../system/test_web_client_server.py | 12 +++--- .../_simulator/_domain/test_account.py | 2 +- .../_simulator/_file_system/test_file.py | 6 +-- .../_file_system/test_file_actions.py | 8 ++-- .../_file_system/test_file_system.py | 4 +- .../_file_system/test_file_system_actions.py | 6 +-- .../_simulator/_file_system/test_folder.py | 6 +-- .../_file_system/test_folder_actions.py | 8 ++-- .../_network/_hardware/nodes/test_acl.py | 6 +-- .../_simulator/_network/_hardware/test_nic.py | 2 +- .../_network/_hardware/test_node.py | 2 +- .../_network/_hardware/test_node_actions.py | 10 ++--- .../_transmission/test_data_link_layer.py | 8 ++-- .../_transmission/test_network_layer.py | 2 +- .../_simulator/_network/test_container.py | 2 +- .../_system/_applications/test_web_browser.py | 10 ++--- .../test_data_manipulation_bot.py | 10 ++--- .../_system/_services/test_database.py | 4 +- .../_simulator/_system/_services/test_dns.py | 16 +++---- .../_simulator/_system/_services/test_ftp.py | 16 +++---- .../_system/_services/test_service_actions.py | 4 +- .../_system/_services/test_services.py | 4 +- .../_system/_services/test_web_server.py | 10 ++--- .../_primaite/_simulator/test_core.py | 2 +- .../_simulator/test_sim_conatiner.py | 2 +- 87 files changed, 335 insertions(+), 335 deletions(-) diff --git a/src/primaite/cli.py b/src/primaite/cli.py index bc4aad39..a5b3be46 100644 --- a/src/primaite/cli.py +++ b/src/primaite/cli.py @@ -29,7 +29,7 @@ def reset_notebooks(overwrite: bool = True) -> None: :param overwrite: If True, will overwrite existing demo notebooks. """ - from src.primaite.setup import reset_demo_notebooks + from primaite.setup import reset_demo_notebooks reset_demo_notebooks.run(overwrite) @@ -98,7 +98,7 @@ def setup(overwrite_existing: bool = True) -> None: from arcd_gate.cli import setup as gate_setup from primaite import getLogger - from src.primaite.setup import reset_demo_notebooks, reset_example_configs + from primaite.setup import reset_demo_notebooks, reset_example_configs _LOGGER = getLogger(__name__) @@ -133,9 +133,9 @@ def session( """ from threading import Thread - from src.primaite.config.load import example_config_path - from src.primaite.main import run - from src.primaite.utils.start_gate_server import start_gate_server + from primaite.config.load import example_config_path + from primaite.main import run + from primaite.utils.start_gate_server import start_gate_server server_thread = Thread(target=start_gate_server) server_thread.start() diff --git a/src/primaite/game/agent/GATE_agents.py b/src/primaite/game/agent/GATE_agents.py index ad52edfc..e50d7831 100644 --- a/src/primaite/game/agent/GATE_agents.py +++ b/src/primaite/game/agent/GATE_agents.py @@ -3,10 +3,10 @@ from typing import Dict, Optional, Tuple from gymnasium.core import ActType, ObsType -from src.primaite.game.agent.actions import ActionManager -from src.primaite.game.agent.interface import AbstractGATEAgent, ObsType -from src.primaite.game.agent.observations import ObservationSpace -from src.primaite.game.agent.rewards import RewardFunction +from primaite.game.agent.actions import ActionManager +from primaite.game.agent.interface import AbstractGATEAgent, ObsType +from primaite.game.agent.observations import ObservationSpace +from primaite.game.agent.rewards import RewardFunction class GATERLAgent(AbstractGATEAgent): diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 9daa09ee..b06013cd 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -15,12 +15,12 @@ from typing import Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium import spaces from primaite import getLogger -from src.primaite.simulator.sim_container import Simulation +from primaite.simulator.sim_container import Simulation _LOGGER = getLogger(__name__) if TYPE_CHECKING: - from src.primaite.game.session import PrimaiteSession + from primaite.game.session import PrimaiteSession class AbstractAction(ABC): diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index affed19c..89f27f3f 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -4,9 +4,9 @@ from typing import Dict, List, Optional, Tuple, TypeAlias, Union import numpy as np -from src.primaite.game.agent.actions import ActionManager -from src.primaite.game.agent.observations import ObservationSpace -from src.primaite.game.agent.rewards import RewardFunction +from primaite.game.agent.actions import ActionManager +from primaite.game.agent.observations import ObservationSpace +from primaite.game.agent.rewards import RewardFunction ObsType: TypeAlias = Union[Dict, np.ndarray] diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index fe43afb2..a3bafeea 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -5,12 +5,12 @@ from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium import spaces from primaite import getLogger -from src.primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE _LOGGER = getLogger(__name__) if TYPE_CHECKING: - from src.primaite.game.session import PrimaiteSession + from primaite.game.session import PrimaiteSession class AbstractObservation(ABC): diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 72a39fee..6c408ff9 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -29,12 +29,12 @@ from abc import abstractmethod from typing import Dict, List, Tuple, TYPE_CHECKING from primaite import getLogger -from src.primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE _LOGGER = getLogger(__name__) if TYPE_CHECKING: - from src.primaite.game.session import PrimaiteSession + from primaite.game.session import PrimaiteSession class AbstractReward: diff --git a/src/primaite/game/agent/scripted_agents.py b/src/primaite/game/agent/scripted_agents.py index aa1faefc..3748494b 100644 --- a/src/primaite/game/agent/scripted_agents.py +++ b/src/primaite/game/agent/scripted_agents.py @@ -1,5 +1,5 @@ """Agents with predefined behaviours.""" -from src.primaite.game.agent.interface import AbstractScriptedAgent +from primaite.game.agent.interface import AbstractScriptedAgent class GreenWebBrowsingAgent(AbstractScriptedAgent): diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index e791a0b9..d40d0754 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -9,27 +9,27 @@ from gymnasium.spaces.utils import flatten, flatten_space from pydantic import BaseModel from primaite import getLogger -from src.primaite.game.agent.actions import ActionManager -from src.primaite.game.agent.interface import AbstractAgent, RandomAgent -from src.primaite.game.agent.observations import ObservationSpace -from src.primaite.game.agent.rewards import RewardFunction -from src.primaite.simulator.network.hardware.base import Link, NIC, Node -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.network.hardware.nodes.router import ACLAction, Router -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.network.hardware.nodes.switch import Switch -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.sim_container import Simulation -from src.primaite.simulator.system.applications.application import Application -from src.primaite.simulator.system.applications.database_client import DatabaseClient -from src.primaite.simulator.system.applications.web_browser import WebBrowser -from src.primaite.simulator.system.services.database.database_service import DatabaseService -from src.primaite.simulator.system.services.dns.dns_client import DNSClient -from src.primaite.simulator.system.services.dns.dns_server import DNSServer -from src.primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot -from src.primaite.simulator.system.services.service import Service -from src.primaite.simulator.system.services.web_server.web_server import WebServer +from primaite.game.agent.actions import ActionManager +from primaite.game.agent.interface import AbstractAgent, RandomAgent +from primaite.game.agent.observations import ObservationSpace +from primaite.game.agent.rewards import RewardFunction +from primaite.simulator.network.hardware.base import Link, NIC, Node +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.sim_container import Simulation +from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer +from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot +from primaite.simulator.system.services.service import Service +from primaite.simulator.system.services.web_server.web_server import WebServer _LOGGER = getLogger(__name__) diff --git a/src/primaite/main.py b/src/primaite/main.py index 9f84598c..831419d4 100644 --- a/src/primaite/main.py +++ b/src/primaite/main.py @@ -5,10 +5,10 @@ from pathlib import Path from typing import Optional, Union from primaite import getLogger -from src.primaite.config.load import load -from src.primaite.game.session import PrimaiteSession +from primaite.config.load import load +from primaite.game.session import PrimaiteSession -# from src.primaite.primaite_session import PrimaiteSession +# from primaite.primaite_session import PrimaiteSession _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py index c7b06ff2..d235c00e 100644 --- a/src/primaite/simulator/domain/account.py +++ b/src/primaite/simulator/domain/account.py @@ -3,7 +3,7 @@ from enum import Enum from typing import Dict from primaite import getLogger -from src.primaite.simulator.core import SimComponent +from primaite.simulator.core import SimComponent _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index aac9010b..e9f3b26d 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -1,8 +1,8 @@ from enum import Enum from typing import Dict, Final, List, Literal, Tuple -from src.primaite.simulator.core import RequestManager, RequestPermissionValidator, RequestType, SimComponent -from src.primaite.simulator.domain.account import Account, AccountType +from primaite.simulator.core import RequestManager, RequestPermissionValidator, RequestType, SimComponent +from primaite.simulator.domain.account import Account, AccountType # placeholder while these objects don't yet exist diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index baa70667..d9b02e8e 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -7,8 +7,8 @@ from pathlib import Path from typing import Dict, Optional from primaite import getLogger -from src.primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC, FileSystemItemHealthStatus -from src.primaite.simulator.file_system.file_type import FileType, get_file_type_from_extension +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC, FileSystemItemHealthStatus +from primaite.simulator.file_system.file_type import FileType, get_file_type_from_extension _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index be7375b1..41f02270 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -7,11 +7,11 @@ from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable from primaite import getLogger -from src.primaite.simulator.core import RequestManager, RequestType, SimComponent -from src.primaite.simulator.file_system.file import File -from src.primaite.simulator.file_system.file_type import FileType -from src.primaite.simulator.file_system.folder import Folder -from src.primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.core import RequestManager, RequestType, SimComponent +from primaite.simulator.file_system.file import File +from primaite.simulator.file_system.file_type import FileType +from primaite.simulator.file_system.folder import Folder +from primaite.simulator.system.core.sys_log import SysLog _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py index cad3aeaa..fbe5f4b3 100644 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -6,8 +6,8 @@ from enum import Enum from typing import Dict, Optional from primaite import getLogger -from src.primaite.simulator.core import RequestManager, RequestType, SimComponent -from src.primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.core import RequestManager, RequestType, SimComponent +from primaite.simulator.system.core.sys_log import SysLog _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 82af255b..f0d55ef8 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -5,9 +5,9 @@ from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable from primaite import getLogger -from src.primaite.simulator.core import RequestManager, RequestType -from src.primaite.simulator.file_system.file import File -from src.primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC, FileSystemItemHealthStatus +from primaite.simulator.core import RequestManager, RequestType +from primaite.simulator.file_system.file import File +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC, FileSystemItemHealthStatus _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index d50e4b95..9fbafc29 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -6,12 +6,12 @@ from networkx import MultiGraph from prettytable import MARKDOWN, PrettyTable from primaite import getLogger -from src.primaite.simulator.core import RequestManager, RequestType, SimComponent -from src.primaite.simulator.network.hardware.base import Link, NIC, Node, SwitchPort -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.network.hardware.nodes.router import Router -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.core import RequestManager, RequestType, SimComponent +from primaite.simulator.network.hardware.base import Link, NIC, Node, SwitchPort +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.router import Router +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 43ec2363..537cebb2 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -10,22 +10,22 @@ from typing import Any, Dict, Literal, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable from primaite import getLogger -from src.primaite.exceptions import NetworkError -from src.primaite.simulator import SIM_OUTPUT -from src.primaite.simulator.core import RequestManager, RequestType, SimComponent -from src.primaite.simulator.domain.account import Account -from src.primaite.simulator.file_system.file_system import FileSystem -from src.primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket -from src.primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame -from src.primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port, TCPHeader -from src.primaite.simulator.system.applications.application import Application -from src.primaite.simulator.system.core.packet_capture import PacketCapture -from src.primaite.simulator.system.core.session_manager import SessionManager -from src.primaite.simulator.system.core.software_manager import SoftwareManager -from src.primaite.simulator.system.core.sys_log import SysLog -from src.primaite.simulator.system.processes.process import Process -from src.primaite.simulator.system.services.service import Service +from primaite.exceptions import NetworkError +from primaite.simulator import SIM_OUTPUT +from primaite.simulator.core import RequestManager, RequestType, SimComponent +from primaite.simulator.domain.account import Account +from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket +from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame +from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader +from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.core.packet_capture import PacketCapture +from primaite.simulator.system.core.session_manager import SessionManager +from primaite.simulator.system.core.software_manager import SoftwareManager +from primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.system.processes.process import Process +from primaite.simulator.system.services.service import Service _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/network/hardware/nodes/computer.py b/src/primaite/simulator/network/hardware/nodes/computer.py index f378ba04..0480aca9 100644 --- a/src/primaite/simulator/network/hardware/nodes/computer.py +++ b/src/primaite/simulator/network/hardware/nodes/computer.py @@ -1,7 +1,7 @@ -from src.primaite.simulator.network.hardware.base import NIC, Node -from src.primaite.simulator.system.applications.web_browser import WebBrowser -from src.primaite.simulator.system.services.dns.dns_client import DNSClient -from src.primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.network.hardware.base import NIC, Node +from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.ftp.ftp_client import FTPClient class Computer(Node): diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 4761291b..c2a38aba 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -7,12 +7,12 @@ from typing import Dict, List, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable -from src.primaite.simulator.core import RequestManager, RequestType, SimComponent -from src.primaite.simulator.network.hardware.base import ARPCache, ICMP, NIC, Node -from src.primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame -from src.primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port, TCPHeader -from src.primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.core import RequestManager, RequestType, SimComponent +from primaite.simulator.network.hardware.base import ARPCache, ICMP, NIC, Node +from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame +from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader +from primaite.simulator.system.core.sys_log import SysLog class ACLAction(Enum): diff --git a/src/primaite/simulator/network/hardware/nodes/server.py b/src/primaite/simulator/network/hardware/nodes/server.py index 529692a3..b72cc71c 100644 --- a/src/primaite/simulator/network/hardware/nodes/server.py +++ b/src/primaite/simulator/network/hardware/nodes/server.py @@ -1,4 +1,4 @@ -from src.primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.computer import Computer class Server(Computer): diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/switch.py index fd4614ff..fe61509c 100644 --- a/src/primaite/simulator/network/hardware/nodes/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/switch.py @@ -3,9 +3,9 @@ from typing import Dict from prettytable import MARKDOWN, PrettyTable from primaite import getLogger -from src.primaite.exceptions import NetworkError -from src.primaite.simulator.network.hardware.base import Link, Node, SwitchPort -from src.primaite.simulator.network.transmission.data_link_layer import Frame +from primaite.exceptions import NetworkError +from primaite.simulator.network.hardware.base import Link, Node, SwitchPort +from primaite.simulator.network.transmission.data_link_layer import Frame _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index d698f491..25d1bd21 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -1,19 +1,19 @@ from ipaddress import IPv4Address -from src.primaite.simulator.network.container import Network -from src.primaite.simulator.network.hardware.base import NIC, NodeOperatingState -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.network.hardware.nodes.router import ACLAction, Router -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.network.hardware.nodes.switch import Switch -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.applications.database_client import DatabaseClient -from src.primaite.simulator.system.services.database.database_service import DatabaseService -from src.primaite.simulator.system.services.dns.dns_server import DNSServer -from src.primaite.simulator.system.services.ftp.ftp_server import FTPServer -from src.primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot -from src.primaite.simulator.system.services.web_server.web_server import WebServer +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.base import NIC, NodeOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.system.services.dns.dns_server import DNSServer +from primaite.simulator.system.services.ftp.ftp_server import FTPServer +from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot +from primaite.simulator.system.services.web_server.web_server import WebServer def client_server_routed() -> Network: diff --git a/src/primaite/simulator/network/protocols/arp.py b/src/primaite/simulator/network/protocols/arp.py index bd5e90e4..7b3e4509 100644 --- a/src/primaite/simulator/network/protocols/arp.py +++ b/src/primaite/simulator/network/protocols/arp.py @@ -5,7 +5,7 @@ from typing import Optional from pydantic import BaseModel -from src.primaite.simulator.network.protocols.packet import DataPacket +from primaite.simulator.network.protocols.packet import DataPacket class ARPEntry(BaseModel): diff --git a/src/primaite/simulator/network/protocols/dns.py b/src/primaite/simulator/network/protocols/dns.py index 4fd9ac68..4f9be51b 100644 --- a/src/primaite/simulator/network/protocols/dns.py +++ b/src/primaite/simulator/network/protocols/dns.py @@ -5,7 +5,7 @@ from typing import Optional from pydantic import BaseModel -from src.primaite.simulator.network.protocols.packet import DataPacket +from primaite.simulator.network.protocols.packet import DataPacket class DNSRequest(BaseModel): diff --git a/src/primaite/simulator/network/protocols/ftp.py b/src/primaite/simulator/network/protocols/ftp.py index 46d2e3b0..9ecc7df8 100644 --- a/src/primaite/simulator/network/protocols/ftp.py +++ b/src/primaite/simulator/network/protocols/ftp.py @@ -1,7 +1,7 @@ from enum import Enum from typing import Any, Optional, Union -from src.primaite.simulator.network.protocols.packet import DataPacket +from primaite.simulator.network.protocols.packet import DataPacket class FTPCommand(Enum): diff --git a/src/primaite/simulator/network/protocols/http.py b/src/primaite/simulator/network/protocols/http.py index e29b4cbf..2dba2614 100644 --- a/src/primaite/simulator/network/protocols/http.py +++ b/src/primaite/simulator/network/protocols/http.py @@ -1,6 +1,6 @@ from enum import Enum -from src.primaite.simulator.network.protocols.packet import DataPacket +from primaite.simulator.network.protocols.packet import DataPacket class HttpRequestMethod(Enum): diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index 9fa940df..fa823a60 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -4,12 +4,12 @@ from typing import Any, Optional from pydantic import BaseModel from primaite import getLogger -from src.primaite.simulator.network.protocols.arp import ARPPacket -from src.primaite.simulator.network.protocols.packet import DataPacket -from src.primaite.simulator.network.transmission.network_layer import ICMPPacket, IPPacket, IPProtocol -from src.primaite.simulator.network.transmission.primaite_layer import PrimaiteHeader -from src.primaite.simulator.network.transmission.transport_layer import TCPHeader, UDPHeader -from src.primaite.simulator.network.utils import convert_bytes_to_megabits +from primaite.simulator.network.protocols.arp import ARPPacket +from primaite.simulator.network.protocols.packet import DataPacket +from primaite.simulator.network.transmission.network_layer import ICMPPacket, IPPacket, IPProtocol +from primaite.simulator.network.transmission.primaite_layer import PrimaiteHeader +from primaite.simulator.network.transmission.transport_layer import TCPHeader, UDPHeader +from primaite.simulator.network.utils import convert_bytes_to_megabits _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index af3449a8..8e820ec8 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -1,8 +1,8 @@ from typing import Dict -from src.primaite.simulator.core import RequestManager, RequestType, SimComponent -from src.primaite.simulator.domain.controller import DomainController -from src.primaite.simulator.network.container import Network +from primaite.simulator.core import RequestManager, RequestType, SimComponent +from primaite.simulator.domain.controller import DomainController +from primaite.simulator.network.container import Network class Simulation(SimComponent): diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index b1ecf680..db323cf6 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -2,7 +2,7 @@ from abc import abstractmethod from enum import Enum from typing import Any, Dict, Set -from src.primaite.simulator.system.software import IOSoftware, SoftwareHealthState +from primaite.simulator.system.software import IOSoftware, SoftwareHealthState class ApplicationOperatingState(Enum): diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index f8a9912a..d021cb78 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -4,10 +4,10 @@ from uuid import uuid4 from prettytable import PrettyTable -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.applications.application import Application, ApplicationOperatingState -from src.primaite.simulator.system.core.software_manager import SoftwareManager +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import Application, ApplicationOperatingState +from primaite.simulator.system.core.software_manager import SoftwareManager class DatabaseClient(Application): diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index eb65cea1..ea9c3ac3 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -2,11 +2,11 @@ from ipaddress import IPv4Address from typing import Dict, Optional from urllib.parse import urlparse -from src.primaite.simulator.network.protocols.http import HttpRequestMethod, HttpRequestPacket, HttpResponsePacket -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.applications.application import Application -from src.primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.network.protocols.http import HttpRequestMethod, HttpRequestPacket, HttpResponsePacket +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.services.dns.dns_client import DNSClient class WebBrowser(Application): diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index 4368a8d7..2e5ed008 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -3,7 +3,7 @@ import logging from pathlib import Path from typing import Any, Dict, List, Optional -from src.primaite.simulator import SIM_OUTPUT +from primaite.simulator import SIM_OUTPUT class _JSONFilter(logging.Filter): diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 1f073041..360b5e73 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -5,15 +5,15 @@ from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING, Union from prettytable import MARKDOWN, PrettyTable -from src.primaite.simulator.core import SimComponent -from src.primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame -from src.primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port, TCPHeader +from primaite.simulator.core import SimComponent +from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame +from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader if TYPE_CHECKING: - from src.primaite.simulator.network.hardware.base import ARPCache - from src.primaite.simulator.system.core.software_manager import SoftwareManager - from src.primaite.simulator.system.core.sys_log import SysLog + from primaite.simulator.network.hardware.base import ARPCache + from primaite.simulator.system.core.software_manager import SoftwareManager + from primaite.simulator.system.core.sys_log import SysLog class Session(SimComponent): diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index ef4eca6c..8b8fe599 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -3,18 +3,18 @@ from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING, Union from prettytable import MARKDOWN, PrettyTable -from src.primaite.simulator.file_system.file_system import FileSystem -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.applications.application import Application, ApplicationOperatingState -from src.primaite.simulator.system.core.sys_log import SysLog -from src.primaite.simulator.system.services.service import Service, ServiceOperatingState -from src.primaite.simulator.system.software import IOSoftware +from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import Application, ApplicationOperatingState +from primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.system.services.service import Service, ServiceOperatingState +from primaite.simulator.system.software import IOSoftware if TYPE_CHECKING: - from src.primaite.simulator.system.core.session_manager import SessionManager - from src.primaite.simulator.system.core.sys_log import SysLog - from src.primaite.simulator.network.hardware.base import Node + from primaite.simulator.system.core.session_manager import SessionManager + from primaite.simulator.system.core.sys_log import SysLog + from primaite.simulator.network.hardware.base import Node from typing import Type, TypeVar diff --git a/src/primaite/simulator/system/core/sys_log.py b/src/primaite/simulator/system/core/sys_log.py index 3ea12758..791e0be8 100644 --- a/src/primaite/simulator/system/core/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -3,7 +3,7 @@ from pathlib import Path from prettytable import MARKDOWN, PrettyTable -from src.primaite.simulator import SIM_OUTPUT +from primaite.simulator import SIM_OUTPUT class _NotJSONFilter(logging.Filter): diff --git a/src/primaite/simulator/system/processes/process.py b/src/primaite/simulator/system/processes/process.py index 7c4da425..c4e94845 100644 --- a/src/primaite/simulator/system/processes/process.py +++ b/src/primaite/simulator/system/processes/process.py @@ -2,7 +2,7 @@ from abc import abstractmethod from enum import Enum from typing import Dict -from src.primaite.simulator.system.software import Software +from primaite.simulator.system.software import Software class ProcessOperatingState(Enum): diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 07eebb36..b04174bf 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -6,13 +6,13 @@ from typing import Any, Dict, List, Optional, Union from prettytable import MARKDOWN, PrettyTable -from src.primaite.simulator.file_system.file_system import File -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.core.software_manager import SoftwareManager -from src.primaite.simulator.system.services.ftp.ftp_client import FTPClient -from src.primaite.simulator.system.services.service import Service, ServiceOperatingState -from src.primaite.simulator.system.software import SoftwareHealthState +from primaite.simulator.file_system.file_system import File +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.software_manager import SoftwareManager +from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.service import Service, ServiceOperatingState +from primaite.simulator.system.software import SoftwareHealthState class DatabaseService(Service): diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 0d09a0dd..266ac4f6 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -2,11 +2,11 @@ from ipaddress import IPv4Address from typing import Dict, Optional from primaite import getLogger -from src.primaite.simulator.network.protocols.dns import DNSPacket, DNSRequest -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.core.software_manager import SoftwareManager -from src.primaite.simulator.system.services.service import Service +from primaite.simulator.network.protocols.dns import DNSPacket, DNSRequest +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.software_manager import SoftwareManager +from primaite.simulator.system.services.service import Service _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/system/services/dns/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py index b1548bb6..90a350c8 100644 --- a/src/primaite/simulator/system/services/dns/dns_server.py +++ b/src/primaite/simulator/system/services/dns/dns_server.py @@ -4,10 +4,10 @@ from typing import Any, Dict, Optional from prettytable import MARKDOWN, PrettyTable from primaite import getLogger -from src.primaite.simulator.network.protocols.dns import DNSPacket -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.services.service import Service +from primaite.simulator.network.protocols.dns import DNSPacket +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.service import Service _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 221f5f7a..3e286da1 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -1,13 +1,13 @@ from ipaddress import IPv4Address from typing import Optional -from src.primaite.simulator.file_system.file_system import File -from src.primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.core.software_manager import SoftwareManager -from src.primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC -from src.primaite.simulator.system.services.service import ServiceOperatingState +from primaite.simulator.file_system.file_system import File +from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.software_manager import SoftwareManager +from primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC +from primaite.simulator.system.services.service import ServiceOperatingState class FTPClient(FTPServiceABC): diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 2f8603d2..23414601 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -1,11 +1,11 @@ from ipaddress import IPv4Address from typing import Any, Dict, Optional -from src.primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC -from src.primaite.simulator.system.services.service import ServiceOperatingState +from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC +from primaite.simulator.system.services.service import ServiceOperatingState class FTPServer(FTPServiceABC): diff --git a/src/primaite/simulator/system/services/ftp/ftp_service.py b/src/primaite/simulator/system/services/ftp/ftp_service.py index 393263a4..f2c01544 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_service.py +++ b/src/primaite/simulator/system/services/ftp/ftp_service.py @@ -3,10 +3,10 @@ from abc import ABC from ipaddress import IPv4Address from typing import Optional -from src.primaite.simulator.file_system.file_system import File -from src.primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.services.service import Service +from primaite.simulator.file_system.file_system import File +from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.service import Service class FTPServiceABC(Service, ABC): diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index 379a9dad..996e6790 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -1,7 +1,7 @@ from ipaddress import IPv4Address from typing import Optional -from src.primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.applications.database_client import DatabaseClient class DataManipulationBot(DatabaseClient): diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 35a22d94..e2b04c15 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -2,8 +2,8 @@ from enum import Enum from typing import Dict, Optional from primaite import getLogger -from src.primaite.simulator.core import RequestManager, RequestType -from src.primaite.simulator.system.software import IOSoftware, SoftwareHealthState +from primaite.simulator.core import RequestManager, RequestType +from primaite.simulator.system.software import IOSoftware, SoftwareHealthState _LOGGER = getLogger(__name__) diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index e696800c..5957e4cb 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -2,16 +2,16 @@ from ipaddress import IPv4Address from typing import Any, Dict, Optional from urllib.parse import urlparse -from src.primaite.simulator.network.protocols.http import ( +from primaite.simulator.network.protocols.http import ( HttpRequestMethod, HttpRequestPacket, HttpResponsePacket, HttpStatusCode, ) -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.applications.database_client import DatabaseClient -from src.primaite.simulator.system.services.service import Service +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.services.service import Service class WebServer(Service): diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 379b2335..f2627557 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -3,11 +3,11 @@ from enum import Enum from ipaddress import IPv4Address from typing import Any, Dict, Optional -from src.primaite.simulator.core import RequestManager, RequestType, SimComponent -from src.primaite.simulator.file_system.file_system import FileSystem, Folder -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.core.session_manager import Session -from src.primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.core import RequestManager, RequestType, SimComponent +from primaite.simulator.file_system.file_system import FileSystem, Folder +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.session_manager import Session +from primaite.simulator.system.core.sys_log import SysLog class SoftwareType(Enum): diff --git a/src/primaite/utils/package_data.py b/src/primaite/utils/package_data.py index b2e0f006..ac41e8bc 100644 --- a/src/primaite/utils/package_data.py +++ b/src/primaite/utils/package_data.py @@ -16,7 +16,7 @@ def get_file_path(path: str) -> Path: :Example: - >>> from src.primaite.utils.package_data import get_file_path + >>> from primaite.utils.package_data import get_file_path >>> main_env_config = get_file_path("config/_package_data/training_config_main.yaml") diff --git a/src/primaite/utils/session_output_writer.py b/src/primaite/utils/session_output_writer.py index c3ecfcb2..0eb18038 100644 --- a/src/primaite/utils/session_output_writer.py +++ b/src/primaite/utils/session_output_writer.py @@ -4,13 +4,13 @@ from logging import Logger from typing import Final, List, Tuple, TYPE_CHECKING, Union from primaite import getLogger -from src.primaite.transactions.transaction import Transaction +from primaite.transactions.transaction import Transaction if TYPE_CHECKING: from io import TextIOWrapper from pathlib import Path - from src.primaite.environment.primaite_env import Primaite + from primaite.environment.primaite_env import Primaite _LOGGER: Logger = getLogger(__name__) diff --git a/tests/conftest.py b/tests/conftest.py index 34b7191f..dc749cfc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,14 +12,14 @@ import pytest from primaite import getLogger -# from src.primaite.environment.primaite_env import Primaite -# from src.primaite.primaite_session import PrimaiteSession -from src.primaite.simulator.network.container import Network -from src.primaite.simulator.network.networks import arcd_uc2_network -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.applications.application import Application -from src.primaite.simulator.system.core.sys_log import SysLog -from src.primaite.simulator.system.services.service import Service +# from primaite.environment.primaite_env import Primaite +# from primaite.primaite_session import PrimaiteSession +from primaite.simulator.network.container import Network +from primaite.simulator.network.networks import arcd_uc2_network +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.system.services.service import Service from tests.mock_and_patch.get_session_path_mock import get_temp_session_path ACTION_SPACE_NODE_VALUES = 1 @@ -28,8 +28,8 @@ ACTION_SPACE_NODE_ACTION_VALUES = 1 _LOGGER = getLogger(__name__) # PrimAITE v3 stuff -from src.primaite.simulator.file_system.file_system import FileSystem -from src.primaite.simulator.network.hardware.base import Node +from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.network.hardware.base import Node class TestService(Service): @@ -121,8 +121,8 @@ def temp_primaite_session(request): .. code:: python - from src.primaite.config.lay_down_config import dos_very_basic_config_path - from src.primaite.config.training_config import main_training_config_path + from primaite.config.lay_down_config import dos_very_basic_config_path + from primaite.config.training_config import main_training_config_path @pytest.mark.parametrize( "temp_primaite_session", [ diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index 5fa652b2..13f4d1f3 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -1,8 +1,8 @@ -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.system.applications.database_client import DatabaseClient -from src.primaite.simulator.system.services.database.database_service import DatabaseService -from src.primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot def test_data_manipulation(uc2_network): diff --git a/tests/integration_tests/component_creation/test_action_integration.py b/tests/integration_tests/component_creation/test_action_integration.py index 110a5254..a2be923b 100644 --- a/tests/integration_tests/component_creation/test_action_integration.py +++ b/tests/integration_tests/component_creation/test_action_integration.py @@ -1,11 +1,11 @@ import pytest -from src.primaite.simulator.core import RequestType -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.network.hardware.nodes.switch import Switch -from src.primaite.simulator.sim_container import Simulation -from src.primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.core import RequestType +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.sim_container import Simulation +from primaite.simulator.system.services.database.database_service import DatabaseService def test_passing_actions_down(monkeypatch) -> None: diff --git a/tests/integration_tests/component_creation/test_permission_system.py b/tests/integration_tests/component_creation/test_permission_system.py index 8026a01f..bcadebb4 100644 --- a/tests/integration_tests/component_creation/test_permission_system.py +++ b/tests/integration_tests/component_creation/test_permission_system.py @@ -3,8 +3,8 @@ from typing import Dict, List, Literal import pytest -from src.primaite.simulator.core import AllowAllValidator, RequestManager, RequestType, SimComponent -from src.primaite.simulator.domain.controller import AccountGroup, GroupMembershipValidator +from primaite.simulator.core import AllowAllValidator, RequestManager, RequestType, SimComponent +from primaite.simulator.domain.controller import AccountGroup, GroupMembershipValidator @pytest.mark.skip(reason="Action validation is not currently a required feature.") diff --git a/tests/integration_tests/game_layer/test_observations.py b/tests/integration_tests/game_layer/test_observations.py index 1f1e9ac1..97154f62 100644 --- a/tests/integration_tests/game_layer/test_observations.py +++ b/tests/integration_tests/game_layer/test_observations.py @@ -1,8 +1,8 @@ from gymnasium import spaces -from src.primaite.game.agent.observations import FileObservation -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.sim_container import Simulation +from primaite.game.agent.observations import FileObservation +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.sim_container import Simulation def test_file_observation(): diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index 9b77dd89..7da9fe76 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -1,4 +1,4 @@ -from src.primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState +from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState def test_node_to_node_ping(): diff --git a/tests/integration_tests/network/test_link_connection.py b/tests/integration_tests/network/test_link_connection.py index 7f95ae23..0ddf54df 100644 --- a/tests/integration_tests/network/test_link_connection.py +++ b/tests/integration_tests/network/test_link_connection.py @@ -1,4 +1,4 @@ -from src.primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState +from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState def test_link_up(): diff --git a/tests/integration_tests/network/test_network_creation.py b/tests/integration_tests/network/test_network_creation.py index 25fa179c..91218068 100644 --- a/tests/integration_tests/network/test_network_creation.py +++ b/tests/integration_tests/network/test_network_creation.py @@ -1,7 +1,7 @@ import pytest -from src.primaite.simulator.network.container import Network -from src.primaite.simulator.network.hardware.base import NIC, Node +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.base import NIC, Node def test_adding_removing_nodes(): diff --git a/tests/integration_tests/network/test_nic_link_connection.py b/tests/integration_tests/network/test_nic_link_connection.py index d6c56acc..228099c6 100644 --- a/tests/integration_tests/network/test_nic_link_connection.py +++ b/tests/integration_tests/network/test_nic_link_connection.py @@ -1,6 +1,6 @@ import pytest -from src.primaite.simulator.network.hardware.base import Link, NIC +from primaite.simulator.network.hardware.base import Link, NIC def test_link_fails_with_same_nic(): diff --git a/tests/integration_tests/network/test_routing.py b/tests/integration_tests/network/test_routing.py index 506c895f..6053c457 100644 --- a/tests/integration_tests/network/test_routing.py +++ b/tests/integration_tests/network/test_routing.py @@ -2,10 +2,10 @@ from typing import Tuple import pytest -from src.primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState -from src.primaite.simulator.network.hardware.nodes.router import ACLAction, Router -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port @pytest.fixture(scope="function") diff --git a/tests/integration_tests/network/test_switched_network.py b/tests/integration_tests/network/test_switched_network.py index 44333e52..5b305702 100644 --- a/tests/integration_tests/network/test_switched_network.py +++ b/tests/integration_tests/network/test_switched_network.py @@ -1,7 +1,7 @@ -from src.primaite.simulator.network.hardware.base import Link, NodeOperatingState -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.hardware.base import Link, NodeOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch def test_switched_network(): diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 0bf95e51..92056981 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -1,9 +1,9 @@ from ipaddress import IPv4Address -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.system.applications.database_client import DatabaseClient -from src.primaite.simulator.system.services.database.database_service import DatabaseService -from src.primaite.simulator.system.services.ftp.ftp_server import FTPServer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.system.services.ftp.ftp_server import FTPServer def test_database_client_server_connection(uc2_network): diff --git a/tests/integration_tests/system/test_dns_client_server.py b/tests/integration_tests/system/test_dns_client_server.py index dd317ef1..e82d97a4 100644 --- a/tests/integration_tests/system/test_dns_client_server.py +++ b/tests/integration_tests/system/test_dns_client_server.py @@ -1,8 +1,8 @@ -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.system.services.dns.dns_client import DNSClient -from src.primaite.simulator.system.services.dns.dns_server import DNSServer -from src.primaite.simulator.system.services.service import ServiceOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer +from primaite.simulator.system.services.service import ServiceOperatingState def test_dns_client_server(uc2_network): diff --git a/tests/integration_tests/system/test_ftp_client_server.py b/tests/integration_tests/system/test_ftp_client_server.py index 1ea86bd4..48dc2960 100644 --- a/tests/integration_tests/system/test_ftp_client_server.py +++ b/tests/integration_tests/system/test_ftp_client_server.py @@ -1,10 +1,10 @@ from ipaddress import IPv4Address -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.system.services.ftp.ftp_client import FTPClient -from src.primaite.simulator.system.services.ftp.ftp_server import FTPServer -from src.primaite.simulator.system.services.service import ServiceOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.ftp.ftp_server import FTPServer +from primaite.simulator.system.services.service import ServiceOperatingState def test_ftp_client_store_file_in_server(uc2_network): diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py index d4f4a187..f4546cbf 100644 --- a/tests/integration_tests/system/test_web_client_server.py +++ b/tests/integration_tests/system/test_web_client_server.py @@ -1,9 +1,9 @@ -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.network.protocols.http import HttpStatusCode -from src.primaite.simulator.system.applications.application import ApplicationOperatingState -from src.primaite.simulator.system.applications.web_browser import WebBrowser -from src.primaite.simulator.system.services.service import ServiceOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.protocols.http import HttpStatusCode +from primaite.simulator.system.applications.application import ApplicationOperatingState +from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.service import ServiceOperatingState def test_web_page_home_page(uc2_network): diff --git a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py index 92f3cfd9..96c34996 100644 --- a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py +++ b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py @@ -1,5 +1,5 @@ """Test the account module of the simulator.""" -from src.primaite.simulator.domain.account import Account, AccountType +from primaite.simulator.domain.account import Account, AccountType def test_account_serialise(): diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py index ef4b1456..32efe029 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file.py @@ -1,6 +1,6 @@ -from src.primaite.simulator.file_system.file import File -from src.primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus -from src.primaite.simulator.file_system.file_type import FileType +from primaite.simulator.file_system.file import File +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus +from primaite.simulator.file_system.file_type import FileType def test_create_file_no_extension(file_system): diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py index a46fd4f9..aa8faa90 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py @@ -2,10 +2,10 @@ from typing import Tuple import pytest -from src.primaite.simulator.file_system.file import File -from src.primaite.simulator.file_system.file_system import FileSystem -from src.primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus -from src.primaite.simulator.file_system.folder import Folder +from primaite.simulator.file_system.file import File +from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus +from primaite.simulator.file_system.folder import Folder @pytest.fixture(scope="function") diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 4d712436..4defc80c 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -1,7 +1,7 @@ import pytest -from src.primaite.simulator.file_system.file_system import FileSystem -from src.primaite.simulator.file_system.file_type import FileType +from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.file_system.file_type import FileType def test_create_folder_and_file(file_system): diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py index 0070c218..1c8513f9 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py @@ -2,9 +2,9 @@ from typing import Tuple import pytest -from src.primaite.simulator.file_system.file import File -from src.primaite.simulator.file_system.file_system import FileSystem -from src.primaite.simulator.file_system.folder import Folder +from primaite.simulator.file_system.file import File +from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.file_system.folder import Folder @pytest.fixture(scope="function") diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py index 5b586e03..bada2dab 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder.py @@ -1,8 +1,8 @@ import pytest -from src.primaite.simulator.file_system.file import File -from src.primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus -from src.primaite.simulator.file_system.folder import Folder +from primaite.simulator.file_system.file import File +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus +from primaite.simulator.file_system.folder import Folder @pytest.mark.skip(reason="Implementation for quarantine not needed yet") diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py index e058d280..efa74e1f 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py @@ -2,10 +2,10 @@ from typing import Tuple import pytest -from src.primaite.simulator.file_system.file import File -from src.primaite.simulator.file_system.file_system import FileSystem -from src.primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus -from src.primaite.simulator.file_system.folder import Folder +from primaite.simulator.file_system.file import File +from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus +from primaite.simulator.file_system.folder import Folder @pytest.fixture(scope="function") diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py index ac1aee2f..554cba38 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py @@ -1,8 +1,8 @@ from ipaddress import IPv4Address -from src.primaite.simulator.network.hardware.nodes.router import ACLAction, Router -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port def test_add_rule(): diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py index ea2dca0b..1bf2cdbb 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py @@ -3,7 +3,7 @@ from ipaddress import IPv4Address import pytest -from src.primaite.simulator.network.hardware.base import generate_mac_address, NIC +from primaite.simulator.network.hardware.base import generate_mac_address, NIC def test_mac_address_generation(): diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node.py index ef2088b1..0e5fb4c7 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node.py @@ -3,7 +3,7 @@ from ipaddress import IPv4Address import pytest -from src.primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.base import Node def test_node_creation(): diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py index 7f4b3f49..5fe5df16 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py @@ -1,10 +1,10 @@ import pytest -from src.primaite.simulator.file_system.file import File -from src.primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus -from src.primaite.simulator.file_system.folder import Folder -from src.primaite.simulator.network.hardware.base import Node, NodeOperatingState -from src.primaite.simulator.system.software import SoftwareHealthState +from primaite.simulator.file_system.file import File +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus +from primaite.simulator.file_system.folder import Folder +from primaite.simulator.network.hardware.base import Node, NodeOperatingState +from primaite.simulator.system.software import SoftwareHealthState @pytest.fixture diff --git a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py index 35603fd0..f9b89de5 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py @@ -1,9 +1,9 @@ import pytest -from src.primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame -from src.primaite.simulator.network.transmission.network_layer import ICMPPacket, IPPacket, IPProtocol, Precedence -from src.primaite.simulator.network.transmission.primaite_layer import AgentSource, DataStatus -from src.primaite.simulator.network.transmission.transport_layer import Port, TCPFlags, TCPHeader, UDPHeader +from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame +from primaite.simulator.network.transmission.network_layer import ICMPPacket, IPPacket, IPProtocol, Precedence +from primaite.simulator.network.transmission.primaite_layer import AgentSource, DataStatus +from primaite.simulator.network.transmission.transport_layer import Port, TCPFlags, TCPHeader, UDPHeader def test_frame_minimal_instantiation(): diff --git a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py index 64a88ea5..a7189452 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py @@ -1,6 +1,6 @@ import pytest -from src.primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType +from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType def test_icmp_minimal_header_creation(): diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index 65dd884f..66bd59a9 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -2,7 +2,7 @@ import json import pytest -from src.primaite.simulator.network.container import Network +from primaite.simulator.network.container import Network def test_creating_container(): diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py index 2f78b476..b2724369 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py @@ -1,10 +1,10 @@ import pytest -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.network.protocols.http import HttpResponsePacket, HttpStatusCode -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.protocols.http import HttpResponsePacket, HttpStatusCode +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.web_browser import WebBrowser @pytest.fixture(scope="function") diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py index 0eca1794..dd785cc1 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py @@ -1,10 +1,10 @@ from ipaddress import IPv4Address -from src.primaite.simulator.network.hardware.base import Node -from src.primaite.simulator.network.networks import arcd_uc2_network -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.networks import arcd_uc2_network +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot def test_creation(): diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py index 2beef740..7662fbff 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py @@ -1,7 +1,7 @@ import pytest -from src.primaite.simulator.network.hardware.base import Node -from src.primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.system.services.database.database_service import DatabaseService @pytest.fixture(scope="function") diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py index 20306a1a..dc6df5d4 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py @@ -2,14 +2,14 @@ from ipaddress import IPv4Address import pytest -from src.primaite.simulator.network.hardware.base import Node -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.network.protocols.dns import DNSPacket, DNSReply, DNSRequest -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.services.dns.dns_client import DNSClient -from src.primaite.simulator.system.services.dns.dns_server import DNSServer +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.protocols.dns import DNSPacket, DNSReply, DNSRequest +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer @pytest.fixture(scope="function") diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py index d2e4f321..d382b8dd 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py @@ -2,14 +2,14 @@ from ipaddress import IPv4Address import pytest -from src.primaite.simulator.network.hardware.base import Node -from src.primaite.simulator.network.hardware.nodes.computer import Computer -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.services.ftp.ftp_client import FTPClient -from src.primaite.simulator.system.services.ftp.ftp_server import FTPServer +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.ftp.ftp_server import FTPServer @pytest.fixture(scope="function") diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py index 9f64c8d6..6b2ee0a7 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py @@ -1,5 +1,5 @@ -from src.primaite.simulator.system.services.service import ServiceOperatingState -from src.primaite.simulator.system.software import SoftwareHealthState +from primaite.simulator.system.services.service import ServiceOperatingState +from primaite.simulator.system.software import SoftwareHealthState def test_service_scan(service): diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py index ba27e6cc..b32463a2 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py @@ -1,5 +1,5 @@ -from src.primaite.simulator.system.services.service import ServiceOperatingState -from src.primaite.simulator.system.software import SoftwareHealthState +from primaite.simulator.system.services.service import ServiceOperatingState +from primaite.simulator.system.software import SoftwareHealthState def test_scan(service): diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py index 4a5c488a..e6f0b9d9 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py @@ -1,15 +1,15 @@ import pytest -from src.primaite.simulator.network.hardware.nodes.server import Server -from src.primaite.simulator.network.protocols.http import ( +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.protocols.http import ( HttpRequestMethod, HttpRequestPacket, HttpResponsePacket, HttpStatusCode, ) -from src.primaite.simulator.network.transmission.network_layer import IPProtocol -from src.primaite.simulator.network.transmission.transport_layer import Port -from src.primaite.simulator.system.services.web_server.web_server import WebServer +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.web_server.web_server import WebServer @pytest.fixture(scope="function") diff --git a/tests/unit_tests/_primaite/_simulator/test_core.py b/tests/unit_tests/_primaite/_simulator/test_core.py index 2e801816..069e6ea2 100644 --- a/tests/unit_tests/_primaite/_simulator/test_core.py +++ b/tests/unit_tests/_primaite/_simulator/test_core.py @@ -3,7 +3,7 @@ from typing import Callable, Dict, List, Literal, Tuple import pytest from pydantic import ValidationError -from src.primaite.simulator.core import SimComponent +from primaite.simulator.core import SimComponent class TestIsolatedSimComponent: diff --git a/tests/unit_tests/_primaite/_simulator/test_sim_conatiner.py b/tests/unit_tests/_primaite/_simulator/test_sim_conatiner.py index 98a204ca..4543259d 100644 --- a/tests/unit_tests/_primaite/_simulator/test_sim_conatiner.py +++ b/tests/unit_tests/_primaite/_simulator/test_sim_conatiner.py @@ -1,4 +1,4 @@ -from src.primaite.simulator.sim_container import Simulation +from primaite.simulator.sim_container import Simulation def test_creating_empty_simulation(): From 6e1f9bd63d65039b780fd997940a51fec1153ef9 Mon Sep 17 00:00:00 2001 From: "Czar.Echavez" Date: Wed, 8 Nov 2023 13:00:07 +0000 Subject: [PATCH 282/980] #1962: add gate installation for docs build pipeline --- .azure/azure-build-deploy-docs-pipeline.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.azure/azure-build-deploy-docs-pipeline.yml b/.azure/azure-build-deploy-docs-pipeline.yml index 0f44b0c8..f60840a7 100644 --- a/.azure/azure-build-deploy-docs-pipeline.yml +++ b/.azure/azure-build-deploy-docs-pipeline.yml @@ -27,7 +27,18 @@ jobs: - script: | pip install -e .[dev] - displayName: 'Install Yawning-Titan for docs autosummary' + displayName: 'Install PrimAITE for docs autosummary' + + - script: | + GATE_WHEEL=$(ls ./GATE/arcd_gate*.whl) + python -m pip install $GATE_WHEEL[dev] + displayName: 'Install GATE' + condition: or(eq( variables['Agent.OS'], 'Linux' ), eq( variables['Agent.OS'], 'Darwin' )) + + - script: | + forfiles /p GATE\ /m *.whl /c "cmd /c python -m pip install @file[dev]" + displayName: 'Install GATE' + condition: eq( variables['Agent.OS'], 'Windows_NT' ) - script: | primaite setup From 23fd9c3839288a9839d0dc3327aac769a4c201f1 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 13 Nov 2023 15:55:14 +0000 Subject: [PATCH 283/980] #1859 - Started giving the red agent some 'intelligence' and a sense of a state. Changed Application.run to .execute. --- src/primaite/game/agent/GATE_agents.py | 8 +- src/primaite/game/agent/interface.py | 2 + src/primaite/game/science.py | 16 +++ src/primaite/game/session.py | 4 +- .../system/applications/application.py | 4 + .../system/applications/database_client.py | 8 +- .../system/applications/web_browser.py | 2 +- .../red_services/data_manipulation_bot.py | 134 +++++++++++++++--- tests/conftest.py | 1 - .../system/test_web_client_server.py | 6 +- 10 files changed, 151 insertions(+), 34 deletions(-) create mode 100644 src/primaite/game/science.py diff --git a/src/primaite/game/agent/GATE_agents.py b/src/primaite/game/agent/GATE_agents.py index e50d7831..e4ee16ca 100644 --- a/src/primaite/game/agent/GATE_agents.py +++ b/src/primaite/game/agent/GATE_agents.py @@ -19,10 +19,10 @@ class GATERLAgent(AbstractGATEAgent): def __init__( self, - agent_name: str | None, - action_space: ActionManager | None, - observation_space: ObservationSpace | None, - reward_function: RewardFunction | None, + agent_name: Optional[str], + action_space: Optional[ActionManager], + observation_space: Optional[ObservationSpace], + reward_function: Optional[RewardFunction], ) -> None: super().__init__(agent_name, action_space, observation_space, reward_function) self.most_recent_action: ActType diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 89f27f3f..78d18a68 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -109,6 +109,8 @@ class RandomAgent(AbstractScriptedAgent): """ return self.action_space.get_action(self.action_space.space.sample()) +class DataManipulationAgent(AbstractScriptedAgent): + pass class AbstractGATEAgent(AbstractAgent): """Base class for actors controlled via external messages, such as RL policies.""" diff --git a/src/primaite/game/science.py b/src/primaite/game/science.py new file mode 100644 index 00000000..f6215127 --- /dev/null +++ b/src/primaite/game/science.py @@ -0,0 +1,16 @@ +from random import random + + +def simulate_trial(p_of_success: float): + """ + Simulates the outcome of a single trial in a Bernoulli process. + + This function returns True with a probability 'p_of_success', simulating a success outcome in a single + trial of a Bernoulli process. When this function is executed multiple times, the set of outcomes follows + a binomial distribution. This is useful in scenarios where one needs to model or simulate events that + have two possible outcomes (success or failure) with a fixed probability of success. + + :param p_of_success: The probability of success in a single trial, ranging from 0 to 1. + :returns: True if the trial is successful (with probability 'p_of_success'); otherwise, False. + """ + return random() < p_of_success diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index d40d0754..9c2bb6b7 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -60,7 +60,7 @@ class PrimaiteGATEClient(GATEClient): return self.parent_session.training_options.rl_algorithm @property - def seed(self) -> int | None: + def seed(self) -> Optional[int]: """The seed to use for the environment's random number generator.""" return self.parent_session.training_options.seed @@ -115,7 +115,7 @@ class PrimaiteGATEClient(GATEClient): info = {} return obs, rew, term, trunc, info - def reset(self, *, seed: int | None = None, options: dict[str, Any] | None = None) -> Tuple[ObsType, Dict]: + def reset(self, *, seed: Optional[int] = None, options: Optional[Dict[str, Any]] = None) -> Tuple[ObsType, Dict]: """Reset the environment. This method is called when the environment is initialized and at the end of each episode. diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index db323cf6..7f79ac2b 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -65,6 +65,10 @@ class Application(IOSoftware): self.sys_log.info(f"Running Application {self.name}") self.operating_state = ApplicationOperatingState.RUNNING + def _application_loop(self): + """THe main application loop.""" + pass + def close(self) -> None: """Close the Application.""" if self.operating_state == ApplicationOperatingState.RUNNING: diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index d021cb78..28e826fd 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -128,11 +128,11 @@ class DatabaseClient(Application): ) return self._query(sql=sql, query_id=query_id, is_reattempt=True) - def run(self) -> None: + def execute(self) -> None: """Run the DatabaseClient.""" - super().run() - self.operating_state = ApplicationOperatingState.RUNNING - self.connect() + super().execute() + if self.operating_state == ApplicationOperatingState.RUNNING: + self.connect() def query(self, sql: str) -> bool: """ diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index ea9c3ac3..6799358d 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -30,7 +30,7 @@ class WebBrowser(Application): kwargs["port"] = Port.HTTP super().__init__(**kwargs) - self.run() + self.execute() def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index 996e6790..aec7bbd8 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -1,27 +1,46 @@ +from enum import IntEnum from ipaddress import IPv4Address from typing import Optional +from primaite.game.science import simulate_trial +from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.database_client import DatabaseClient +class DataManipulationAttackStage(IntEnum): + """ + Enumeration representing different stages of a data manipulation attack. + + This enumeration defines the various stages a data manipulation attack can be in during its lifecycle in the + simulation. Each stage represents a specific phase in the attack process. + """ + NOT_STARTED = 0 + "Indicates that the attack has not started yet." + LOGON = 1 + "The stage where logon procedures are simulated." + PORT_SCAN = 2 + "Represents the stage of performing a horizontal port scan on the target." + ATTACKING = 3 + "Stage of actively attacking the target." + COMPLETE = 4 + "Indicates the attack has been successfully completed." + FAILED = 5 + "Signifies that the attack has failed." + + class DataManipulationBot(DatabaseClient): - """ - Red Agent Data Integration Service. - - The Service represents a bot that causes files/folders in the File System to - become corrupted. - """ - + """A bot that simulates a script which performs a SQL injection attack.""" server_ip_address: Optional[IPv4Address] = None payload: Optional[str] = None server_password: Optional[str] = None + attack_stage: DataManipulationAttackStage = DataManipulationAttackStage.NOT_STARTED def __init__(self, **kwargs): super().__init__(**kwargs) self.name = "DataManipulationBot" def configure( - self, server_ip_address: IPv4Address, server_password: Optional[str] = None, payload: Optional[str] = None + self, server_ip_address: IPv4Address, server_password: Optional[str] = None, payload: Optional[str] = None ): """ Configure the DataManipulatorBot to communicate with a DatabaseService. @@ -37,15 +56,92 @@ class DataManipulationBot(DatabaseClient): f"{self.name}: Configured the {self.name} with {server_ip_address=}, {payload=}, {server_password=}." ) - def run(self): - """Run the DataManipulationBot.""" - if self.server_ip_address and self.payload: - self.sys_log.info(f"{self.name}: Attempting to start the {self.name}") - super().run() - if not self.connected: - self.connect() - if self.connected: - self.query(self.payload) - self.sys_log.info(f"{self.name} payload delivered: {self.payload}") + def _logon(self): + """ + Simulate the logon process as the initial stage of the attack. + + Advances the attack stage to `LOGON` if successful. + """ + if self.attack_stage == DataManipulationAttackStage.NOT_STARTED: + # Bypass this stage as we're not dealing with logon for now + self.sys_log.info(f"{self.name}: ") + self.attack_stage = DataManipulationAttackStage.LOGON + + def _perform_port_scan(self, p_of_success: Optional[float] = 0.1): + """ + Perform a simulated port scan to check for open SQL ports. + + Advances the attack stage to `PORT_SCAN` if successful. + + :param p_of_success: Probability of successful port scan, by default 0.1. + """ + if self.attack_stage == DataManipulationAttackStage.LOGON: + # perform a port scan to identify that the SQL port is open on the server + if simulate_trial(p_of_success): + self.sys_log.info(f"{self.name}: Performing port scan") + # perform the port scan + port_is_open = True # Temporary; later we can implement NMAP port scan. + if port_is_open: + self.sys_log.info(f"{self.name}: ") + self.attack_stage = DataManipulationAttackStage.PORT_SCAN + + def _perform_data_manipulation(self, p_of_success: Optional[float] = 0.1): + """ + Execute the data manipulation attack on the target. + + Advances the attack stage to `COMPLETE` if successful, or 'FAILED' if unsuccessful. + + :param p_of_success: Probability of successfully performing data manipulation, by default 0.1. + """ + if self.attack_stage == DataManipulationAttackStage.PORT_SCAN: + # perform the actual data manipulation attack + if simulate_trial(p_of_success): + + self.sys_log.info(f"{self.name}: Performing port scan") + # perform the attack + if not self.connected: + self.connect() + if self.connected: + self.query(self.payload) + self.sys_log.info(f"{self.name} payload delivered: {self.payload}") + attack_successful = True + if attack_successful: + self.sys_log.info(f"{self.name}: Performing port scan") + self.attack_stage = DataManipulationAttackStage.COMPLETE + else: + self.sys_log.info(f"{self.name}: Performing port scan") + self.attack_stage = DataManipulationAttackStage.FAILED + + def execute(self): + """ + Execute the Data Manipulation Bot + + Calls the parent classes execute method before starting the application loop. + """ + super().execute() + self._application_loop() + + def _application_loop(self): + """ + The main application loop of the bot, handling the attack process. + + This is the core loop where the bot sequentially goes through the stages of the attack. + """ + + if self.operating_state != ApplicationOperatingState.RUNNING: + return + if self.server_ip_address and self.payload and self.operating_state: + self.sys_log.info(f"{self.name}: Running") + self._logon() + self._perform_port_scan() + self._perform_data_manipulation() else: - self.sys_log.error(f"Failed to start the {self.name} as it requires both a target_ip_address and payload.") + self.sys_log.error(f"{self.name}: Failed to start as it requires both a target_ip_address and payload.") + + def apply_timestep(self, timestep: int) -> None: + """ + Apply a timestep to the bot, triggering the application loop. + + :param timestep: The timestep value to update the bot's state. + """ + self._application_loop() diff --git a/tests/conftest.py b/tests/conftest.py index dc749cfc..c046ca0d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,7 +7,6 @@ from pathlib import Path from typing import Any, Dict, Union from unittest.mock import patch -import nodeenv import pytest from primaite import getLogger diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py index f4546cbf..e36cff2b 100644 --- a/tests/integration_tests/system/test_web_client_server.py +++ b/tests/integration_tests/system/test_web_client_server.py @@ -10,7 +10,7 @@ def test_web_page_home_page(uc2_network): """Test to see if the browser is able to open the main page of the web server.""" client_1: Computer = uc2_network.get_node_by_hostname("client_1") web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] - web_client.run() + web_client.execute() assert web_client.operating_state == ApplicationOperatingState.RUNNING assert web_client.get_webpage("http://arcd.com/") is True @@ -24,7 +24,7 @@ def test_web_page_get_users_page_request_with_domain_name(uc2_network): """Test to see if the client can handle requests with domain names""" client_1: Computer = uc2_network.get_node_by_hostname("client_1") web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] - web_client.run() + web_client.execute() assert web_client.operating_state == ApplicationOperatingState.RUNNING assert web_client.get_webpage("http://arcd.com/users/") is True @@ -38,7 +38,7 @@ def test_web_page_get_users_page_request_with_ip_address(uc2_network): """Test to see if the client can handle requests that use ip_address.""" client_1: Computer = uc2_network.get_node_by_hostname("client_1") web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] - web_client.run() + web_client.execute() web_server: Server = uc2_network.get_node_by_hostname("web_server") web_server_ip = web_server.nics.get(next(iter(web_server.nics))).ip_address From 21c06dbea1d3eb60ed90f7a1228973711b15fdf7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 13 Nov 2023 16:04:25 +0000 Subject: [PATCH 284/980] Remove GATE-related code. --- .azure/azure-build-deploy-docs-pipeline.yml | 11 -- .azure/azure-ci-build-pipeline.yaml | 11 -- README.md | 3 - src/primaite/game/agent/GATE_agents.py | 31 ------ src/primaite/game/agent/interface.py | 8 +- src/primaite/game/session.py | 115 +------------------- src/primaite/utils/start_gate_server.py | 12 -- 7 files changed, 3 insertions(+), 188 deletions(-) delete mode 100644 src/primaite/game/agent/GATE_agents.py delete mode 100644 src/primaite/utils/start_gate_server.py diff --git a/.azure/azure-build-deploy-docs-pipeline.yml b/.azure/azure-build-deploy-docs-pipeline.yml index f60840a7..d9926ba7 100644 --- a/.azure/azure-build-deploy-docs-pipeline.yml +++ b/.azure/azure-build-deploy-docs-pipeline.yml @@ -29,17 +29,6 @@ jobs: pip install -e .[dev] displayName: 'Install PrimAITE for docs autosummary' - - script: | - GATE_WHEEL=$(ls ./GATE/arcd_gate*.whl) - python -m pip install $GATE_WHEEL[dev] - displayName: 'Install GATE' - condition: or(eq( variables['Agent.OS'], 'Linux' ), eq( variables['Agent.OS'], 'Darwin' )) - - - script: | - forfiles /p GATE\ /m *.whl /c "cmd /c python -m pip install @file[dev]" - displayName: 'Install GATE' - condition: eq( variables['Agent.OS'], 'Windows_NT' ) - - script: | primaite setup displayName: 'Perform PrimAITE Setup' diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index efeba284..9070270a 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -81,17 +81,6 @@ stages: displayName: 'Install PrimAITE' condition: eq( variables['Agent.OS'], 'Windows_NT' ) - - script: | - GATE_WHEEL=$(ls ./GATE/arcd_gate*.whl) - python -m pip install $GATE_WHEEL[dev] - displayName: 'Install GATE' - condition: or(eq( variables['Agent.OS'], 'Linux' ), eq( variables['Agent.OS'], 'Darwin' )) - - - script: | - forfiles /p GATE\ /m *.whl /c "cmd /c python -m pip install @file[dev]" - displayName: 'Install GATE' - condition: eq( variables['Agent.OS'], 'Windows_NT' ) - - script: | primaite setup displayName: 'Perform PrimAITE Setup' diff --git a/README.md b/README.md index 9ec8164e..7fc41681 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,6 @@ python3 -m venv .venv attrib +h .venv /s /d # Hides the .venv directory .\.venv\Scripts\activate pip install https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/releases/download/v2.0.0/primaite-2.0.0-py3-none-any.whl -pip install GATE/arcd_gate-0.1.0-py3-none-any.whl primaite setup ``` @@ -75,7 +74,6 @@ cd ~/primaite python3 -m venv .venv source .venv/bin/activate pip install https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/releases/download/v2.0.0/primaite-2.0.0-py3-none-any.whl -pip install arcd_gate-0.1.0-py3-none-any.whl primaite setup ``` @@ -120,7 +118,6 @@ source venv/bin/activate ```bash python3 -m pip install -e .[dev] -pip install arcd_gate-0.1.0-py3-none-any.whl ``` #### 6. Perform the PrimAITE setup: diff --git a/src/primaite/game/agent/GATE_agents.py b/src/primaite/game/agent/GATE_agents.py deleted file mode 100644 index e50d7831..00000000 --- a/src/primaite/game/agent/GATE_agents.py +++ /dev/null @@ -1,31 +0,0 @@ -# flake8: noqa -from typing import Dict, Optional, Tuple - -from gymnasium.core import ActType, ObsType - -from primaite.game.agent.actions import ActionManager -from primaite.game.agent.interface import AbstractGATEAgent, ObsType -from primaite.game.agent.observations import ObservationSpace -from primaite.game.agent.rewards import RewardFunction - - -class GATERLAgent(AbstractGATEAgent): - ... - # The communication with GATE needs to be handled by the PrimaiteSession, rather than by individual agents, - # because when we are supporting MARL, the actions form multiple agents will have to be batched - - # For example MultiAgentEnv in Ray allows sending a dict of observations of multiple agents, then it will reply - # with the actions for those agents. - - def __init__( - self, - agent_name: str | None, - action_space: ActionManager | None, - observation_space: ObservationSpace | None, - reward_function: RewardFunction | None, - ) -> None: - super().__init__(agent_name, action_space, observation_space, reward_function) - self.most_recent_action: ActType - - def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: - return self.most_recent_action diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 89f27f3f..e3b98777 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -76,7 +76,7 @@ class AbstractAgent(ABC): :return: Action to be taken in the environment. :rtype: Tuple[str, Dict] """ - # in RL agent, this method will send CAOS observation to GATE RL agent, then receive a int 0-39, + # in RL agent, this method will send CAOS observation to RL agent, then receive a int 0-39, # then use a bespoke conversion to take 1-40 int back into CAOS action return ("DO_NOTHING", {}) @@ -108,9 +108,3 @@ class RandomAgent(AbstractScriptedAgent): :rtype: Tuple[str, Dict] """ return self.action_space.get_action(self.action_space.space.sample()) - - -class AbstractGATEAgent(AbstractAgent): - """Base class for actors controlled via external messages, such as RL policies.""" - - ... diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index d40d0754..459d9668 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -1,11 +1,7 @@ """PrimAITE session - the main entry point to training agents on PrimAITE.""" from ipaddress import IPv4Address -from typing import Any, Dict, List, Optional, Tuple +from typing import Dict, List, Optional -from arcd_gate.client.gate_client import ActType, GATEClient -from gymnasium import spaces -from gymnasium.core import ActType, ObsType -from gymnasium.spaces.utils import flatten, flatten_space from pydantic import BaseModel from primaite import getLogger @@ -34,111 +30,6 @@ from primaite.simulator.system.services.web_server.web_server import WebServer _LOGGER = getLogger(__name__) -class PrimaiteGATEClient(GATEClient): - """Lightweight wrapper around the GATEClient class that allows PrimAITE to message GATE.""" - - def __init__(self, parent_session: "PrimaiteSession", service_port: int = 50000): - """ - Create a new GATE client for PrimAITE. - - :param parent_session: The parent session object. - :type parent_session: PrimaiteSession - :param service_port: The port on which the GATE service is running. - :type service_port: int, optional - """ - super().__init__(service_port=service_port) - self.parent_session: "PrimaiteSession" = parent_session - - @property - def rl_framework(self) -> str: - """The reinforcement learning framework to use.""" - return self.parent_session.training_options.rl_framework - - @property - def rl_algorithm(self) -> str: - """The reinforcement learning algorithm to use.""" - return self.parent_session.training_options.rl_algorithm - - @property - def seed(self) -> int | None: - """The seed to use for the environment's random number generator.""" - return self.parent_session.training_options.seed - - @property - def n_learn_episodes(self) -> int: - """The number of episodes in each learning run.""" - return self.parent_session.training_options.n_learn_episodes - - @property - def n_learn_steps(self) -> int: - """The number of steps in each learning episode.""" - return self.parent_session.training_options.n_learn_steps - - @property - def n_eval_episodes(self) -> int: - """The number of episodes in each evaluation run.""" - return self.parent_session.training_options.n_eval_episodes - - @property - def n_eval_steps(self) -> int: - """The number of steps in each evaluation episode.""" - return self.parent_session.training_options.n_eval_steps - - @property - def action_space(self) -> spaces.Space: - """The gym action space of the agent.""" - return self.parent_session.rl_agent.action_space.space - - @property - def observation_space(self) -> spaces.Space: - """The gymnasium observation space of the agent.""" - return flatten_space(self.parent_session.rl_agent.observation_space.space) - - def step(self, action: ActType) -> Tuple[ObsType, float, bool, bool, Dict]: - """Take a step in the environment. - - This method is called by GATE to advance the simulation by one timestep. - - :param action: The agent's action. - :type action: ActType - :return: The observation, reward, terminal flag, truncated flag, and info dictionary. - :rtype: Tuple[ObsType, float, bool, bool, Dict] - """ - self.parent_session.rl_agent.most_recent_action = action - self.parent_session.step() - state = self.parent_session.simulation.describe_state() - obs = self.parent_session.rl_agent.observation_space.observe(state) - obs = flatten(self.parent_session.rl_agent.observation_space.space, obs) - rew = self.parent_session.rl_agent.reward_function.calculate(state) - term = False - trunc = False - info = {} - return obs, rew, term, trunc, info - - def reset(self, *, seed: int | None = None, options: dict[str, Any] | None = None) -> Tuple[ObsType, Dict]: - """Reset the environment. - - This method is called when the environment is initialized and at the end of each episode. - - :param seed: The seed to use for the environment's random number generator. - :type seed: int, optional - :param options: Additional options for the reset. None are used by PrimAITE but this is included for - compatibility with GATE. - :type options: dict[str, Any], optional - :return: The initial observation and an empty info dictionary. - :rtype: Tuple[ObsType, Dict] - """ - self.parent_session.reset() - state = self.parent_session.simulation.describe_state() - obs = self.parent_session.rl_agent.observation_space.observe(state) - obs = flatten(self.parent_session.rl_agent.observation_space.space, obs) - return obs, {} - - def close(self): - """Close the session, this will stop the gate client and close the simulation.""" - self.parent_session.close() - - class PrimaiteSessionOptions(BaseModel): """ Global options which are applicable to all of the agents in the game. @@ -189,12 +80,10 @@ class PrimaiteSession: """Mapping from human-readable application reference to application object. Used for parsing config files.""" self.ref_map_links: Dict[str, Link] = {} """Mapping from human-readable link reference to link object. Used when parsing config files.""" - self.gate_client: PrimaiteGATEClient = PrimaiteGATEClient(self) - """Reference to a GATE Client object, which will send data to GATE service for training RL agent.""" def start_session(self) -> None: """Commence the training session, this gives the GATE client control over the simulation/agent loop.""" - self.gate_client.start() + raise NotImplementedError def step(self): """ diff --git a/src/primaite/utils/start_gate_server.py b/src/primaite/utils/start_gate_server.py deleted file mode 100644 index d91952f2..00000000 --- a/src/primaite/utils/start_gate_server.py +++ /dev/null @@ -1,12 +0,0 @@ -"""Utility script to start the gate server for running PrimAITE in attached mode.""" -from arcd_gate.server.gate_service import GATEService - - -def start_gate_server(): - """Start the gate server.""" - service = GATEService() - service.start() - - -if __name__ == "__main__": - start_gate_server() From 707f2b59af1f1039957952ff2fbccfe78b74edaa Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 13 Nov 2023 16:08:39 +0000 Subject: [PATCH 285/980] Add SB3 RL agent --- src/primaite/game/policy/__init__.py | 0 src/primaite/game/policy/policy.py | 58 ++++++++++++++++++ src/primaite/game/policy/sb3.py | 89 ++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 src/primaite/game/policy/__init__.py create mode 100644 src/primaite/game/policy/policy.py create mode 100644 src/primaite/game/policy/sb3.py diff --git a/src/primaite/game/policy/__init__.py b/src/primaite/game/policy/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/game/policy/policy.py b/src/primaite/game/policy/policy.py new file mode 100644 index 00000000..8d5a9a08 --- /dev/null +++ b/src/primaite/game/policy/policy.py @@ -0,0 +1,58 @@ +from abc import ABC, abstractclassmethod, abstractmethod +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from primaite.game.session import PrimaiteSession + + +class PolicyABC(ABC): + """Base class for reinforcement learning agents.""" + + @abstractmethod + def __init__(self, session: "PrimaiteSession") -> None: + """Initialize a reinforcement learning agent.""" + self.session: "PrimaiteSession" = session + pass + + @abstractmethod + def learn( + self, + ) -> None: + """Train the agent.""" + pass + + @abstractmethod + def eval( + self, + ) -> None: + """Evaluate the agent.""" + pass + + @abstractmethod + def save( + self, + ) -> None: + """Save the agent.""" + pass + + @abstractmethod + def load( + self, + ) -> None: + """Load agent from a file.""" + pass + + def close( + self, + ) -> None: + """Close the agent.""" + pass + + @abstractclassmethod + def from_config( + cls, + ) -> "PolicyABC": + """Create an agent from a config file.""" + pass + + # saving checkpoints logic will be handled here, it will invoke 'save' method which is implemented by the subclass diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/game/policy/sb3.py new file mode 100644 index 00000000..9c6b49ae --- /dev/null +++ b/src/primaite/game/policy/sb3.py @@ -0,0 +1,89 @@ +from typing import Literal, TYPE_CHECKING, Union + +from stable_baselines3 import A2C, PPO +from stable_baselines3.a2c import MlpPolicy as A2C_MLP +from stable_baselines3.ppo import MlpPolicy as PPO_MLP + +from primaite.game.policy.policy import PolicyABC + +if TYPE_CHECKING: + from primaite.game.session import PrimaiteSession + + +class SB3Policy(PolicyABC): + """Single agent RL policy using stable baselines 3.""" + + def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"]): + """Initialize a stable baselines 3 policy.""" + super().__init__(session=session) + + self._agent_class: type[Union[PPO, A2C]] + if algorithm == "PPO": + self._agent_class = PPO + policy = PPO_MLP + elif algorithm == "A2C": + self._agent_class = A2C + policy = A2C_MLP + else: + raise ValueError(f"Unknown algorithm `{algorithm}` for stable_baselines3 policy") + self._agent = self._agent_class( + policy=policy, + env=self.session.env, + n_steps=..., + seed=..., + ) # TODO: populate values once I figure out how to get them from the config / session + + def learn( + self, + ) -> None: + """Train the agent.""" + time_steps = 9999 # TODO: populate values once I figure out how to get them from the config / session + episodes = 10 # TODO: populate values once I figure out how to get them from the config / session + for i in range(episodes): + self._agent.learn(total_timesteps=time_steps) + self._save_checkpoint() + pass + + def eval( + self, + ) -> None: + """Evaluate the agent.""" + time_steps = 9999 # TODO: populate values once I figure out how to get them from the config / session + num_episodes = 10 # TODO: populate values once I figure out how to get them from the config / session + deterministic = True # TODO: populate values once I figure out how to get them from the config / session + + for episode in range(num_episodes): + obs = self.session.env.reset() + for step in range(time_steps): + action, _states = self._agent.predict(obs, deterministic=deterministic) + obs, rewards, truncated, terminated, info = self.session.env.step(action) + + def save( + self, + ) -> None: + """Save the agent.""" + savepath = ( + "temp/path/to/save.pth" # TODO: populate values once I figure out how to get them from the config / session + ) + self._agent.save(savepath) + pass + + def load( + self, + ) -> None: + """Load agent from a checkpoint.""" + self._agent_class.load("temp/path/to/save.pth", env=self.session.env) + pass + + def close( + self, + ) -> None: + """Close the agent.""" + pass + + @classmethod + def from_config( + self, + ) -> "SB3Policy": + """Create an agent from config file.""" + pass From 08e88e52b0bb5961a67bfc1d11f9930681e511a6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 13 Nov 2023 16:35:35 +0000 Subject: [PATCH 286/980] Begin implementing training loop in session --- src/primaite/game/policy/sb3.py | 1 + src/primaite/game/session.py | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/game/policy/sb3.py index 9c6b49ae..151e860d 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/game/policy/sb3.py @@ -52,6 +52,7 @@ class SB3Policy(PolicyABC): num_episodes = 10 # TODO: populate values once I figure out how to get them from the config / session deterministic = True # TODO: populate values once I figure out how to get them from the config / session + # TODO: consider moving this loop to the session, only if this makes sense for RAY RLLIB for episode in range(num_episodes): obs = self.session.env.reset() for step in range(time_steps): diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 459d9668..a088d05e 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -9,6 +9,7 @@ from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractAgent, RandomAgent from primaite.game.agent.observations import ObservationSpace from primaite.game.agent.rewards import RewardFunction +from primaite.game.policy.policy import PolicyABC from primaite.simulator.network.hardware.base import Link, NIC, Node from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router @@ -59,31 +60,51 @@ class PrimaiteSession: def __init__(self): self.simulation: Simulation = Simulation() """Simulation object with which the agents will interact.""" + self.agents: List[AbstractAgent] = [] """List of agents.""" - self.rl_agent: AbstractAgent - """The agent from the list which communicates with GATE to perform reinforcement learning.""" + + # self.rl_agent: AbstractAgent + # """The agent from the list which communicates with GATE to perform reinforcement learning.""" + self.step_counter: int = 0 """Current timestep within the episode.""" + self.episode_counter: int = 0 """Current episode number.""" + self.options: PrimaiteSessionOptions """Special options that apply for the entire game.""" + self.training_options: TrainingOptions """Options specific to agent training.""" + self.policy: PolicyABC + """The reinforcement learning policy.""" + self.ref_map_nodes: Dict[str, Node] = {} """Mapping from unique node reference name to node object. Used when parsing config files.""" + self.ref_map_services: Dict[str, Service] = {} """Mapping from human-readable service reference to service object. Used for parsing config files.""" + self.ref_map_applications: Dict[str, Application] = {} """Mapping from human-readable application reference to application object. Used for parsing config files.""" + self.ref_map_links: Dict[str, Link] = {} """Mapping from human-readable link reference to link object. Used when parsing config files.""" def start_session(self) -> None: """Commence the training session, this gives the GATE client control over the simulation/agent loop.""" - raise NotImplementedError + # n_learn_steps = self.training_options.n_learn_steps + n_learn_episodes = self.training_options.n_learn_episodes + # n_eval_steps = self.training_options.n_eval_steps + n_eval_episodes = self.training_options.n_eval_episodes + if n_learn_episodes > 0: + self.policy.learn() + + if n_eval_episodes > 0: + self.policy.eval() def step(self): """ From 1cb54da2dd91e2067a8214eaa7290ad3819667e1 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 13 Nov 2023 17:12:50 +0000 Subject: [PATCH 287/980] Remove more GATE stuff --- src/primaite/cli.py | 11 ------ .../config/_package_data/example_config.yaml | 2 +- src/primaite/game/policy/policy.py | 8 +--- src/primaite/game/policy/sb3.py | 39 ++++++------------- src/primaite/game/session.py | 9 +++-- 5 files changed, 19 insertions(+), 50 deletions(-) diff --git a/src/primaite/cli.py b/src/primaite/cli.py index a5b3be46..0f17525e 100644 --- a/src/primaite/cli.py +++ b/src/primaite/cli.py @@ -95,8 +95,6 @@ def setup(overwrite_existing: bool = True) -> None: WARNING: All user-data will be lost. """ - from arcd_gate.cli import setup as gate_setup - from primaite import getLogger from primaite.setup import reset_demo_notebooks, reset_example_configs @@ -115,9 +113,6 @@ def setup(overwrite_existing: bool = True) -> None: _LOGGER.info("Rebuilding the example notebooks...") reset_example_configs.run(overwrite_existing=True) - _LOGGER.info("Setting up ARCD GATE...") - gate_setup() - _LOGGER.info("PrimAITE setup complete!") @@ -131,14 +126,8 @@ def session( :param config: The path to the config file. Optional, if None, the example config will be used. :type config: Optional[str] """ - from threading import Thread - from primaite.config.load import example_config_path from primaite.main import run - from primaite.utils.start_gate_server import start_gate_server - - server_thread = Thread(target=start_gate_server) - server_thread.start() if not config: config = example_config_path() diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index ee42cf4f..676028bb 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -108,7 +108,7 @@ game_config: - ref: defender team: BLUE - type: GATERLAgent + type: idk??? observation_space: type: UC2BlueObservation diff --git a/src/primaite/game/policy/policy.py b/src/primaite/game/policy/policy.py index 8d5a9a08..404d6f31 100644 --- a/src/primaite/game/policy/policy.py +++ b/src/primaite/game/policy/policy.py @@ -15,16 +15,12 @@ class PolicyABC(ABC): pass @abstractmethod - def learn( - self, - ) -> None: + def learn(self, n_episodes: int, n_time_steps: int) -> None: """Train the agent.""" pass @abstractmethod - def eval( - self, - ) -> None: + def eval(self, n_episodes: int, n_time_steps: int, deterministic: bool) -> None: """Evaluate the agent.""" pass diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/game/policy/sb3.py index 151e860d..2d9da1db 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/game/policy/sb3.py @@ -33,35 +33,24 @@ class SB3Policy(PolicyABC): seed=..., ) # TODO: populate values once I figure out how to get them from the config / session - def learn( - self, - ) -> None: + def learn(self, n_episodes: int, n_time_steps: int) -> None: """Train the agent.""" - time_steps = 9999 # TODO: populate values once I figure out how to get them from the config / session - episodes = 10 # TODO: populate values once I figure out how to get them from the config / session - for i in range(episodes): - self._agent.learn(total_timesteps=time_steps) + # TODO: consider moving this loop to the session, only if this makes sense for RAY RLLIB + for i in range(n_episodes): + self._agent.learn(total_timesteps=n_time_steps) self._save_checkpoint() pass - def eval( - self, - ) -> None: + def eval(self, n_episodes: int, n_time_steps: int, deterministic: bool) -> None: """Evaluate the agent.""" - time_steps = 9999 # TODO: populate values once I figure out how to get them from the config / session - num_episodes = 10 # TODO: populate values once I figure out how to get them from the config / session - deterministic = True # TODO: populate values once I figure out how to get them from the config / session - # TODO: consider moving this loop to the session, only if this makes sense for RAY RLLIB - for episode in range(num_episodes): + for episode in range(n_episodes): obs = self.session.env.reset() - for step in range(time_steps): + for step in range(n_time_steps): action, _states = self._agent.predict(obs, deterministic=deterministic) obs, rewards, truncated, terminated, info = self.session.env.step(action) - def save( - self, - ) -> None: + def save(self) -> None: """Save the agent.""" savepath = ( "temp/path/to/save.pth" # TODO: populate values once I figure out how to get them from the config / session @@ -69,22 +58,16 @@ class SB3Policy(PolicyABC): self._agent.save(savepath) pass - def load( - self, - ) -> None: + def load(self) -> None: """Load agent from a checkpoint.""" self._agent_class.load("temp/path/to/save.pth", env=self.session.env) pass - def close( - self, - ) -> None: + def close(self) -> None: """Close the agent.""" pass @classmethod - def from_config( - self, - ) -> "SB3Policy": + def from_config(self) -> "SB3Policy": """Create an agent from config file.""" pass diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index a088d05e..9d241932 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -96,15 +96,16 @@ class PrimaiteSession: def start_session(self) -> None: """Commence the training session, this gives the GATE client control over the simulation/agent loop.""" - # n_learn_steps = self.training_options.n_learn_steps + n_learn_steps = self.training_options.n_learn_steps n_learn_episodes = self.training_options.n_learn_episodes - # n_eval_steps = self.training_options.n_eval_steps + n_eval_steps = self.training_options.n_eval_steps n_eval_episodes = self.training_options.n_eval_episodes + deterministic_eval = True # TODO: get this value from config if n_learn_episodes > 0: - self.policy.learn() + self.policy.learn(n_episodes=n_learn_episodes, n_time_steps=n_learn_steps) if n_eval_episodes > 0: - self.policy.eval() + self.policy.eval(n_episodes=n_eval_episodes, n_time_steps=n_eval_steps, deterministic=deterministic_eval) def step(self): """ From 2ee820339779de50eb69e97c1e11f8261eaa3359 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Mon, 13 Nov 2023 17:39:27 +0000 Subject: [PATCH 288/980] #2041: NTP server initial commits --- .../simulator/network/protocols/ntp.py | 34 +++++++++++ .../simulator/system/services/ntp/__init__.py | 0 .../system/services/ntp/ntp_server.py | 56 +++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/primaite/simulator/network/protocols/ntp.py create mode 100644 src/primaite/simulator/system/services/ntp/__init__.py create mode 100644 src/primaite/simulator/system/services/ntp/ntp_server.py diff --git a/src/primaite/simulator/network/protocols/ntp.py b/src/primaite/simulator/network/protocols/ntp.py new file mode 100644 index 00000000..f14dab73 --- /dev/null +++ b/src/primaite/simulator/network/protocols/ntp.py @@ -0,0 +1,34 @@ +from __future__ import annotations + +from ipaddress import IPv4Address +from typing import Optional + +from pydantic import BaseModel + +from primaite.simulator.network.protocols.packet import DataPacket + + +class NTPRequest(BaseModel): + """Represents a NTP Request packet.""" + + pass + + +class NTPReply(BaseModel): + """Represents a NTP Reply packet.""" + + pass + + +class NTPPacket(DataPacket): + """ + Represents the NTP layer of a network frame. + + :param ntp_request: NTPRequest packet from NTP client. + :param ntp_reply: NTPReply packet from NTP Server. + """ + + ntp_request: NTPRequest + "NTP Request packet sent by NTP Client." + ntp_reply: Optional[NTPReply] = None + "NTP Reply packet generated by NTP Server." diff --git a/src/primaite/simulator/system/services/ntp/__init__.py b/src/primaite/simulator/system/services/ntp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py new file mode 100644 index 00000000..914dd1c3 --- /dev/null +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -0,0 +1,56 @@ +from ipaddress import IPv4Address +from typing import Any, Dict, Optional + +from primaite import getLogger +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.service import Service + +_LOGGER = getLogger(__name__) + +class NTPServer(Service): + """Represents a NTP server as a service""" + + def __init__(self, **kwargs): + kwargs["name"] = "NTPServer" + kwargs["port"] = Port.NTP + kwargs["protocol"] = IPProtocol.UDP + super().__init__(**kwargs) + self.start() + + def describe_state(self) -> Dict: + """ + Describes the current state of the software. + + The specifics of the software's state, including its health, criticality, + and any other pertinent information, should be implemented in subclasses. + + :return: A dictionary containing key-value pairs representing the current + state of the software. + :rtype: Dict + """ + state = super().describe_state() + return state + + def reset_component_for_episode(self, episode: int): + """ + Resets the Service component for a new episode. + + This method ensures the Service is ready for a new episode, including + resetting any stateful properties or statistics, and clearing any message + queues. + """ + pass + + def receive( + self, + payload: Any, + session_id: Optional[str] = None, + **kwargs, + ) -> bool: + """Receives a request from NTPClient""" + pass + + def send(self): + """Sends time data to NTPClient""" + pass From 764d9561bd3ef45520b9bd6ec50614d244e00e78 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Mon, 13 Nov 2023 17:40:25 +0000 Subject: [PATCH 289/980] #2042: NTP client initial commit --- .../system/services/ntp/ntp_client.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/primaite/simulator/system/services/ntp/ntp_client.py diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py new file mode 100644 index 00000000..edae9af6 --- /dev/null +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -0,0 +1,50 @@ +from ipaddress import IPv4Address +from typing import Dict, Optional +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.service import Service + + +from primaite import getLogger + +_LOGGER = getLogger(__name__) + + +class NTPClient(Service): + """Represents a NTP client as a service""" + + ntp_server: Optional[IPv4Address] = None + "The NTP server the client sends requests to." + + def __init__(self, **kwargs): + kwargs["name"] = "NTPClient" + kwargs["port"] = Port.NTP + kwargs["protocol"] = IPProtocol.UDP + super().__init__(**kwargs) + self.start() + + def describe_state(self) -> Dict: + """ + Describes the current state of the software. + + The specifics of the software's state, including its health, criticality, + and any other pertinent information, should be implemented in subclasses. + + :return: A dictionary containing key-value pairs representing the current state of the software. + :rtype: Dict + """ + state = super().describe_state() + return state + + def reset_component_for_episode(self, episode: int): + """ + Resets the Service component for a new episode. + + This method ensures the Service is ready for a new episode, including resetting any + stateful properties or statistics, and clearing any message queues. + """ + pass + + def receive(self): + """Receives time data from server""" + pass From e6ead6e53248695f0699eb63a83dcada0d154b67 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 14 Nov 2023 15:10:07 +0000 Subject: [PATCH 290/980] Update agent interface to work better with envs --- .../config/_package_data/example_config.yaml | 8 +- src/primaite/game/agent/interface.py | 70 ++++++-- src/primaite/game/agent/observations.py | 11 +- src/primaite/game/agent/rewards.py | 6 +- src/primaite/game/policy/policy.py | 69 +++++--- src/primaite/game/policy/sb3.py | 15 +- src/primaite/game/session.py | 158 +++++++++++++----- 7 files changed, 240 insertions(+), 97 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 676028bb..0c39333c 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -4,8 +4,12 @@ training_config: seed: 333 n_learn_episodes: 20 n_learn_steps: 128 - n_eval_episodes: 20 + n_eval_episodes: 5 n_eval_steps: 128 + deterministic_eval: false + n_agents: 1 + agent_references: + - defender game_config: @@ -108,7 +112,7 @@ game_config: - ref: defender team: BLUE - type: idk??? + type: RLAgent observation_space: type: UC2BlueObservation diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index e3b98777..75d209ce 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -1,15 +1,13 @@ """Interface for agents.""" from abc import ABC, abstractmethod -from typing import Dict, List, Optional, Tuple, TypeAlias, Union +from typing import Dict, List, Optional, Tuple -import numpy as np +from gymnasium.core import ActType, ObsType from primaite.game.agent.actions import ActionManager -from primaite.game.agent.observations import ObservationSpace +from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction -ObsType: TypeAlias = Union[Dict, np.ndarray] - class AbstractAgent(ABC): """Base class for scripted and RL agents.""" @@ -18,7 +16,7 @@ class AbstractAgent(ABC): self, agent_name: Optional[str], action_space: Optional[ActionManager], - observation_space: Optional[ObservationSpace], + observation_space: Optional[ObservationManager], reward_function: Optional[RewardFunction], ) -> None: """ @@ -34,24 +32,24 @@ class AbstractAgent(ABC): :type reward_function: Optional[RewardFunction] """ self.agent_name: str = agent_name or "unnamed_agent" - self.action_space: Optional[ActionManager] = action_space - self.observation_space: Optional[ObservationSpace] = observation_space + self.action_manager: Optional[ActionManager] = action_space + self.observation_manager: Optional[ObservationManager] = observation_space self.reward_function: Optional[RewardFunction] = reward_function # exection definiton converts CAOS action to Primaite simulator request, sometimes having to enrich the info # by for example specifying target ip addresses, or converting a node ID into a uuid self.execution_definition = None - def convert_state_to_obs(self, state: Dict) -> ObsType: + def update_observation(self, state: Dict) -> ObsType: """ Convert a state from the simulator into an observation for the agent using the observation space. state : dict state directly from simulation.describe_state output : dict state according to CAOS. """ - return self.observation_space.observe(state) + return self.observation_manager.update(state) - def calculate_reward_from_state(self, state: Dict) -> float: + def update_reward(self, state: Dict) -> float: """ Use the reward function to calculate a reward from the state. @@ -60,10 +58,10 @@ class AbstractAgent(ABC): :return: Reward from the state. :rtype: float """ - return self.reward_function.calculate(state) + return self.reward_function.update(state) @abstractmethod - def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: + def get_action(self, obs: ObsType, reward: float = 0.0) -> Tuple[str, Dict]: """ Return an action to be taken in the environment. @@ -84,7 +82,7 @@ class AbstractAgent(ABC): # this will take something like APPLICATION.EXECUTE and add things like target_ip_address in simulator. # therefore the execution definition needs to be a mapping from CAOS into SIMULATOR """Format action into format expected by the simulator, and apply execution definition if applicable.""" - request = self.action_space.form_request(action_identifier=action, action_options=options) + request = self.action_manager.form_request(action_identifier=action, action_options=options) return request @@ -97,7 +95,7 @@ class AbstractScriptedAgent(AbstractAgent): class RandomAgent(AbstractScriptedAgent): """Agent that ignores its observation and acts completely at random.""" - def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: + def get_action(self, obs: ObsType, reward: float = 0.0) -> Tuple[str, Dict]: """Randomly sample an action from the action space. :param obs: _description_ @@ -107,4 +105,44 @@ class RandomAgent(AbstractScriptedAgent): :return: _description_ :rtype: Tuple[str, Dict] """ - return self.action_space.get_action(self.action_space.space.sample()) + return self.action_manager.get_action(self.action_manager.space.sample()) + + +class ProxyAgent(AbstractAgent): + """Agent that sends observations to an RL model and receives actions from that model.""" + + def __init__( + self, + agent_name: Optional[str], + action_space: Optional[ActionManager], + observation_space: Optional[ObservationManager], + reward_function: Optional[RewardFunction], + ) -> None: + super().__init__( + agent_name=agent_name, + action_space=action_space, + observation_space=observation_space, + reward_function=reward_function, + ) + self.most_recent_action: ActType + + def get_action(self, obs: ObsType, reward: float = 0.0) -> Tuple[str, Dict]: + """ + Return the agent's most recent action, formatted in CAOS format. + + :param obs: Observation for the agent. Not used by ProxyAgents, but required by the interface. + :type obs: ObsType + :param reward: Reward value for the agent. Not used by ProxyAgents, defaults to None. + :type reward: float, optional + :return: Action to be taken in CAOS format. + :rtype: Tuple[str, Dict] + """ + return self.action_manager.get_action(self.most_recent_action) + + def store_action(self, action: ActType): + """ + Store the most recent action taken by the agent. + + The environment is responsible for calling this method when it receives an action from the agent policy. + """ + self.most_recent_action = action diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index a3bafeea..a74771c0 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -3,6 +3,7 @@ from abc import ABC, abstractmethod from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium import spaces +from gymnasium.core import ObsType from primaite import getLogger from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE @@ -926,7 +927,7 @@ class UC2GreenObservation(NullObservation): pass -class ObservationSpace: +class ObservationManager: """ Manage the observations of an Agent. @@ -947,15 +948,17 @@ class ObservationSpace: :type observation: AbstractObservation """ self.obs: AbstractObservation = observation + self.current_observation: ObsType - def observe(self, state: Dict) -> Dict: + def update(self, state: Dict) -> Dict: """ Generate observation based on the current state of the simulation. :param state: Simulation state dictionary :type state: Dict """ - return self.obs.observe(state) + self.current_observation = self.obs.observe(state) + return self.current_observation @property def space(self) -> None: @@ -963,7 +966,7 @@ class ObservationSpace: return self.obs.space @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "ObservationSpace": + def from_config(cls, config: Dict, session: "PrimaiteSession") -> "ObservationManager": """Create observation space from a config. :param config: Dictionary containing the configuration for this observation space. diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 6c408ff9..49d56e67 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -238,6 +238,7 @@ class RewardFunction: """Initialise the reward function object.""" self.reward_components: List[Tuple[AbstractReward, float]] = [] "attribute reward_components keeps track of reward components and the weights assigned to each." + self.current_reward: float def regsiter_component(self, component: AbstractReward, weight: float = 1.0) -> None: """Add a reward component to the reward function. @@ -249,7 +250,7 @@ class RewardFunction: """ self.reward_components.append((component, weight)) - def calculate(self, state: Dict) -> float: + def update(self, state: Dict) -> float: """Calculate the overall reward for the current state. :param state: The current state of the simulation. @@ -260,7 +261,8 @@ class RewardFunction: comp = comp_and_weight[0] weight = comp_and_weight[1] total += weight * comp.calculate(state=state) - return total + self.current_reward = total + return self.current_reward @classmethod def from_config(cls, config: Dict, session: "PrimaiteSession") -> "RewardFunction": diff --git a/src/primaite/game/policy/policy.py b/src/primaite/game/policy/policy.py index 404d6f31..5669a4ff 100644 --- a/src/primaite/game/policy/policy.py +++ b/src/primaite/game/policy/policy.py @@ -1,18 +1,47 @@ -from abc import ABC, abstractclassmethod, abstractmethod -from typing import TYPE_CHECKING +"""Base class and common logic for RL policies.""" +from abc import ABC, abstractmethod +from typing import Any, Dict, TYPE_CHECKING if TYPE_CHECKING: - from primaite.game.session import PrimaiteSession + from primaite.game.session import PrimaiteSession, TrainingOptions class PolicyABC(ABC): """Base class for reinforcement learning agents.""" + _registry: Dict[str, type["PolicyABC"]] = {} + """ + Registry of policy types, keyed by name. + + Automatically populated when PolicyABC subclasses are defined. Used for defining from_config. + """ + + def __init_subclass__(cls, name: str, **kwargs: Any) -> None: + """ + Register a policy subclass. + + :param name: Identifier used by from_config to create an instance of the policy. + :type name: str + :raises ValueError: When attempting to create a policy with a duplicate name. + """ + super().__init_subclass__(**kwargs) + if name in cls._registry: + raise ValueError(f"Duplicate policy name {name}") + cls._registry[name] = cls + return + @abstractmethod def __init__(self, session: "PrimaiteSession") -> None: - """Initialize a reinforcement learning agent.""" + """ + Initialize a reinforcement learning policy. + + :param session: The session context. + :type session: PrimaiteSession + :param agents: The agents to train. + :type agents: List[RLAgent] + """ self.session: "PrimaiteSession" = session - pass + """Reference to the session.""" @abstractmethod def learn(self, n_episodes: int, n_time_steps: int) -> None: @@ -25,30 +54,30 @@ class PolicyABC(ABC): pass @abstractmethod - def save( - self, - ) -> None: + def save(self) -> None: """Save the agent.""" pass @abstractmethod - def load( - self, - ) -> None: + def load(self) -> None: """Load agent from a file.""" pass - def close( - self, - ) -> None: + def close(self) -> None: """Close the agent.""" pass - @abstractclassmethod - def from_config( - cls, - ) -> "PolicyABC": - """Create an agent from a config file.""" - pass + @classmethod + def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "PolicyABC": + """ + Create an RL policy from a config by calling the relevant subclass's from_config method. + + Subclasses should not call super().from_config(), they should just handle creation form config. + """ + # Assume that basically the contents of training_config are passed into here. + # I should really define a config schema class using pydantic. + + PolicyType = cls._registry[config.rl_framework] + return PolicyType.from_config() # saving checkpoints logic will be handled here, it will invoke 'save' method which is implemented by the subclass diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/game/policy/sb3.py index 2d9da1db..73df1b98 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/game/policy/sb3.py @@ -1,4 +1,5 @@ -from typing import Literal, TYPE_CHECKING, Union +"""Stable baselines 3 policy.""" +from typing import Literal, Optional, TYPE_CHECKING, Union from stable_baselines3 import A2C, PPO from stable_baselines3.a2c import MlpPolicy as A2C_MLP @@ -7,13 +8,13 @@ from stable_baselines3.ppo import MlpPolicy as PPO_MLP from primaite.game.policy.policy import PolicyABC if TYPE_CHECKING: - from primaite.game.session import PrimaiteSession + from primaite.game.session import PrimaiteSession, TrainingOptions class SB3Policy(PolicyABC): """Single agent RL policy using stable baselines 3.""" - def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"]): + def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): """Initialize a stable baselines 3 policy.""" super().__init__(session=session) @@ -29,8 +30,8 @@ class SB3Policy(PolicyABC): self._agent = self._agent_class( policy=policy, env=self.session.env, - n_steps=..., - seed=..., + n_steps=128, # this is not the number of steps in an episode, but the number of steps in a batch + seed=seed, ) # TODO: populate values once I figure out how to get them from the config / session def learn(self, n_episodes: int, n_time_steps: int) -> None: @@ -68,6 +69,6 @@ class SB3Policy(PolicyABC): pass @classmethod - def from_config(self) -> "SB3Policy": + def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "SB3Policy": """Create an agent from config file.""" - pass + return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 9d241932..5556dd87 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -1,13 +1,15 @@ """PrimAITE session - the main entry point to training agents on PrimAITE.""" from ipaddress import IPv4Address -from typing import Dict, List, Optional +from typing import Any, Dict, List, Literal, Optional, SupportsFloat, Tuple +import gymnasium +from gymnasium.core import ActType, ObsType from pydantic import BaseModel from primaite import getLogger from primaite.game.agent.actions import ActionManager -from primaite.game.agent.interface import AbstractAgent, RandomAgent -from primaite.game.agent.observations import ObservationSpace +from primaite.game.agent.interface import AbstractAgent, ProxyAgent, RandomAgent +from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction from primaite.game.policy.policy import PolicyABC from primaite.simulator.network.hardware.base import Link, NIC, Node @@ -31,6 +33,58 @@ from primaite.simulator.system.services.web_server.web_server import WebServer _LOGGER = getLogger(__name__) +class PrimaiteEnv(gymnasium.Env): + """ + Thin wrapper env to provide agents with a gymnasium API. + + This is always a single agent environment since gymnasium is a single agent API. Therefore, we can make some + assumptions about the agent list always having a list of length 1. + """ + + def __init__(self, session: "PrimaiteSession", agents: List[ProxyAgent]): + """Initialise the environment.""" + super().__init__() + self.session: "PrimaiteSession" = session + self.agent: ProxyAgent = agents[0] + + def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, dict[str, Any]]: + """Perform a step in the environment.""" + # make ProxyAgent store the action chosen my the RL policy + self.agent.store_action(action) + # apply_agent_actions accesses the action we just stored + self.session.apply_agent_actions() + self.session.advance_timestep() + state = self.session.get_sim_state() + self.session.update_agents(state) + + next_obs = self.agent.observation_manager.current_observation + reward = self.agent.reward_function.current_reward + terminated = False + truncated = ... + info = {} + + return next_obs, reward, terminated, truncated, info + + def reset(self, seed: Optional[int] = None) -> tuple[ObsType, dict[str, Any]]: + """Reset the environment.""" + self.session.reset() + state = self.session.get_sim_state() + self.session.update_agents(state) + next_obs = self.agent.observation_manager.current_observation + info = {} + return next_obs, info + + @property + def action_space(self) -> gymnasium.Space: + """Return the action space of the environment.""" + return self.agent.action_manager.action_space + + @property + def observation_space(self) -> gymnasium.Space: + """Return the observation space of the environment.""" + return self.agent.observation_manager.observation_space + + class PrimaiteSessionOptions(BaseModel): """ Global options which are applicable to all of the agents in the game. @@ -45,28 +99,29 @@ class PrimaiteSessionOptions(BaseModel): class TrainingOptions(BaseModel): """Options for training the RL agent.""" - rl_framework: str - rl_algorithm: str + rl_framework: Literal["SB3", "RLLIB"] + rl_algorithm: Literal["PPO", "A2C"] seed: Optional[int] n_learn_episodes: int n_learn_steps: int - n_eval_episodes: int - n_eval_steps: int + n_eval_episodes: int = 0 + n_eval_steps: Optional[int] = None + deterministic_eval: bool + n_agents: int + agent_references: List[str] class PrimaiteSession: - """The main entrypoint for PrimAITE sessions, this manages a simulation, agents, and connections to ARCD GATE.""" + """The main entrypoint for PrimAITE sessions, this manages a simulation, agents, and environments.""" def __init__(self): + """Initialise a PrimaiteSession object.""" self.simulation: Simulation = Simulation() """Simulation object with which the agents will interact.""" self.agents: List[AbstractAgent] = [] """List of agents.""" - # self.rl_agent: AbstractAgent - # """The agent from the list which communicates with GATE to perform reinforcement learning.""" - self.step_counter: int = 0 """Current timestep within the episode.""" @@ -94,8 +149,10 @@ class PrimaiteSession: self.ref_map_links: Dict[str, Link] = {} """Mapping from human-readable link reference to link object. Used when parsing config files.""" + # self.env: + def start_session(self) -> None: - """Commence the training session, this gives the GATE client control over the simulation/agent loop.""" + """Commence the training session.""" n_learn_steps = self.training_options.n_learn_steps n_learn_episodes = self.training_options.n_learn_episodes n_eval_steps = self.training_options.n_eval_steps @@ -119,40 +176,47 @@ class PrimaiteSession: 4. Each agent chooses an action based on the observation. 5. Each agent converts the action to a request. 6. The simulation applies the requests. + + Warning: This method should only be used with scripted agents. For RL agents, the environment that the agent + interacts with should implement a step method that calls methods used by this method. For example, if using a + single-agent gym, make sure to update the ProxyAgent's action with the action before calling + ``self.apply_agent_actions()``. """ _LOGGER.debug(f"Stepping primaite session. Step counter: {self.step_counter}") - # currently designed with assumption that all agents act once per step in order + # Get the current state of the simulation + sim_state = self.get_sim_state() + + # Update agents' observations and rewards based on the current state + self.update_agents(sim_state) + + # Apply all actions to simulation as requests + self.apply_agent_actions() + + # Advance timestep + self.advance_timestep() + + def get_sim_state(self) -> Dict: + """Get the current state of the simulation.""" + return self.simulation.describe_state() + + def update_agents(self, state: Dict) -> None: + """Update agents' observations and rewards based on the current state.""" for agent in self.agents: - # 3. primaite session asks simulation to provide initial state - # 4. primate session gives state to all agents - # 5. primaite session asks agents to produce an action based on most recent state - _LOGGER.debug(f"Sending simulation state to agent {agent.agent_name}") - sim_state = self.simulation.describe_state() + agent.update_observation(state) + agent.update_reward(state) - # 6. each agent takes most recent state and converts it to CAOS observation - agent_obs = agent.convert_state_to_obs(sim_state) + def apply_agent_actions(self) -> None: + """Apply all actions to simulation as requests.""" + for agent in self.agents: + obs = agent.observation_manager.current_observation + rew = agent.reward_function.current_reward + action_choice, options = agent.get_action(obs, rew) + request = agent.format_request(action_choice, options) + self.simulation.apply_request(request) - # 7. meanwhile each agent also takes state and calculates reward - agent_reward = agent.calculate_reward_from_state(sim_state) - - # 8. each agent takes observation and applies decision rule to observation to create CAOS - # action(such as random, rulebased, or send to GATE) (therefore, converting CAOS action - # to discrete(40) is only necessary for purposes of RL learning, therefore that bit of - # code should live inside of the GATE agent subclass) - # gets action in CAOS format - _LOGGER.debug("Getting agent action") - agent_action, action_options = agent.get_action(agent_obs, agent_reward) - # 9. CAOS action is converted into request (extra information might be needed to enrich - # the request, this is what the execution definition is there for) - _LOGGER.debug(f"Formatting agent action {agent_action}") # maybe too many debug log statements - agent_request = agent.format_request(agent_action, action_options) - - # 10. primaite session receives the action from the agents and asks the simulation to apply each - _LOGGER.debug(f"Sending request to simulation: {agent_request}") - self.simulation.apply_request(agent_request) - - _LOGGER.debug(f"Initiating simulation step {self.step_counter}") + def advance_timestep(self) -> None: + """Advance timestep.""" self.simulation.apply_timestep(self.step_counter) self.step_counter += 1 @@ -161,7 +225,7 @@ class PrimaiteSession: return NotImplemented def close(self) -> None: - """Close the session, this will stop the gate client and close the simulation.""" + """Close the session, this will stop the env and close the simulation.""" return NotImplemented @classmethod @@ -169,7 +233,7 @@ class PrimaiteSession: """Create a PrimaiteSession object from a config dictionary. The config dictionary should have the following top-level keys: - 1. training_config: options for training the RL agent. Used by GATE. + 1. training_config: options for training the RL agent. 2. game_config: options for the game itself. Used by PrimaiteSession. 3. simulation: defines the network topology and the initial state of the simulation. @@ -323,7 +387,7 @@ class PrimaiteSession: reward_function_cfg = agent_cfg["reward_function"] # CREATE OBSERVATION SPACE - obs_space = ObservationSpace.from_config(observation_space_cfg, sess) + obs_space = ObservationManager.from_config(observation_space_cfg, sess) # CREATE ACTION SPACE action_space_cfg["options"]["node_uuids"] = [] @@ -359,15 +423,14 @@ class PrimaiteSession: reward_function=rew_function, ) sess.agents.append(new_agent) - elif agent_type == "GATERLAgent": - new_agent = RandomAgent( + elif agent_type == "RLAgent": + new_agent = ProxyAgent( agent_name=agent_cfg["ref"], action_space=action_space, observation_space=obs_space, reward_function=rew_function, ) sess.agents.append(new_agent) - sess.rl_agent = new_agent elif agent_type == "RedDatabaseCorruptingAgent": new_agent = RandomAgent( agent_name=agent_cfg["ref"], @@ -379,4 +442,7 @@ class PrimaiteSession: else: print("agent type not found") + # CREATE POLICY + sess.policy = PolicyABC.from_config(sess.training_options) + return sess From f32048712880d3951404656c10bdb1c86fd55a47 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 14 Nov 2023 15:13:05 +0000 Subject: [PATCH 291/980] #2041: Implement NTP protocol for server --- .../simulator/network/protocols/ntp.py | 18 +++++++--- .../system/services/ntp/ntp_server.py | 36 ++++++++++++++++--- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/primaite/simulator/network/protocols/ntp.py b/src/primaite/simulator/network/protocols/ntp.py index f14dab73..89a26961 100644 --- a/src/primaite/simulator/network/protocols/ntp.py +++ b/src/primaite/simulator/network/protocols/ntp.py @@ -2,22 +2,22 @@ from __future__ import annotations from ipaddress import IPv4Address from typing import Optional - from pydantic import BaseModel - from primaite.simulator.network.protocols.packet import DataPacket +from datetime import datetime class NTPRequest(BaseModel): """Represents a NTP Request packet.""" - pass + ntp_client: IPv4Address = None class NTPReply(BaseModel): """Represents a NTP Reply packet.""" - pass + ntp_datetime: datetime + "NTP datetime object set by NTP Server." class NTPPacket(DataPacket): @@ -31,4 +31,12 @@ class NTPPacket(DataPacket): ntp_request: NTPRequest "NTP Request packet sent by NTP Client." ntp_reply: Optional[NTPReply] = None - "NTP Reply packet generated by NTP Server." + + def generate_reply(self, time: datetime) -> NTPPacket: + """ Generate a NTPPacket containing the time in a NTPReply object + + :param time: datetime object representing the time from the NTP server. + :return: A new NTPPacket object. + """ + self.ntp_reply = NTPReply(time) + return self diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index 914dd1c3..50a582a4 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -2,12 +2,15 @@ from ipaddress import IPv4Address from typing import Any, Dict, Optional from primaite import getLogger +from primaite.simulator.network.protocols.ntp import NTPPacket from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.service import Service +from datetime import datetime _LOGGER = getLogger(__name__) + class NTPServer(Service): """Represents a NTP server as a service""" @@ -48,9 +51,32 @@ class NTPServer(Service): session_id: Optional[str] = None, **kwargs, ) -> bool: - """Receives a request from NTPClient""" - pass + """Receives a request from NTPClient. - def send(self): - """Sends time data to NTPClient""" - pass + Check that request has a valid IP address. + + :param payload: The payload to send. + :param session_id: Id of the session (Optional). + + :return: True if valid NTP request else False. + """ + if not (isinstance(payload, NTPPacket) and + payload.ntp_request.ntp_client): + _LOGGER.debug(f"{payload} is not a NTPPacket") + return False + payload: NTPPacket = payload + if payload.ntp_request.ntp_client: + self.sys_log.info( + f"{self.name}: Received request for {payload.ntp_request.ntp_client} " + f"from session {session_id}" + ) + # generate a reply with the current time + time = datetime.now() + payload = payload.generate_reply(time) + self.sys_log.info( + f"{self.name}: Responding to NTP request for {payload.ntp_request.ntp_client} " + f"with current time: {time}" + ) + # send reply + self.send(payload, session_id) + return True From 195e8a4e84507eb30125b57160fb7b7038648260 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 14 Nov 2023 15:13:28 +0000 Subject: [PATCH 292/980] #2042: Implement NTP protocol for client --- .../system/services/ntp/ntp_client.py | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index edae9af6..d1fe7bbf 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -1,5 +1,6 @@ from ipaddress import IPv4Address from typing import Dict, Optional +from primaite.simulator.network.protocols.ntp import NTPPacket from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.service import Service @@ -45,6 +46,48 @@ class NTPClient(Service): """ pass - def receive(self): - """Receives time data from server""" - pass + def send( + self, + payload: NTPPacket, + session_id: Optional[str] = None, + dest_ip_address: Optional[IPv4Address] = None, + dest_port: [Port] = Port.NTP, + **kwargs, + ) -> bool: + """Requests NTP data from NTP server. + + :param payload: The payload to be sent. + :param session_id: The Session ID the payload is to originate from. Optional. + :param dest_ip_address: The ip address of the payload destination. + :param dest_port: The port of the payload destination. + + :return: True if successful, False otherwise. + """ + self.sys_log.info(f"{self.name}: Sending NTP request {payload.ntp_request.ntp_client}") + + return super().send( + payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, **kwargs + ) + + def receive( + self, + payload: NTPPacket, + session_id: Optional[str] = None, + **kwargs, + ): + """Receives time data from server + + :param payload: The payload to be sent. + :param session_id: The Session ID the payload is to originate from. Optional. + :return: True if successful, False otherwise. + """ + if not (isinstance(payload, NTPPacket) and + payload.ntp_request.ntp_client): + _LOGGER.debug(f"{payload} is not a NTPPacket") + return False + + # XXX: compare received datetime with current time. Log error if differ by more than x ms? + if payload.ntp_reply.ntp_datetime: + self.sys_log.info( + f"{self.name}: Received time update from NTP server{payload.ntp_reply.ntp_datetime}") + return True From d31fce202cbada0504b37fa30581578e80da6125 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 15 Nov 2023 10:57:56 +0000 Subject: [PATCH 293/980] #2041: pre-commit changes. --- .../simulator/network/protocols/ntp.py | 6 ++++-- .../system/services/ntp/ntp_server.py | 19 ++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/primaite/simulator/network/protocols/ntp.py b/src/primaite/simulator/network/protocols/ntp.py index 89a26961..286c5664 100644 --- a/src/primaite/simulator/network/protocols/ntp.py +++ b/src/primaite/simulator/network/protocols/ntp.py @@ -1,10 +1,12 @@ from __future__ import annotations +from datetime import datetime from ipaddress import IPv4Address from typing import Optional + from pydantic import BaseModel + from primaite.simulator.network.protocols.packet import DataPacket -from datetime import datetime class NTPRequest(BaseModel): @@ -33,7 +35,7 @@ class NTPPacket(DataPacket): ntp_reply: Optional[NTPReply] = None def generate_reply(self, time: datetime) -> NTPPacket: - """ Generate a NTPPacket containing the time in a NTPReply object + """Generate a NTPPacket containing the time in a NTPReply object. :param time: datetime object representing the time from the NTP server. :return: A new NTPPacket object. diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index 50a582a4..d4be6924 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -1,4 +1,4 @@ -from ipaddress import IPv4Address +from datetime import datetime from typing import Any, Dict, Optional from primaite import getLogger @@ -6,13 +6,12 @@ from primaite.simulator.network.protocols.ntp import NTPPacket from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.service import Service -from datetime import datetime _LOGGER = getLogger(__name__) class NTPServer(Service): - """Represents a NTP server as a service""" + """Represents a NTP server as a service.""" def __init__(self, **kwargs): kwargs["name"] = "NTPServer" @@ -46,10 +45,10 @@ class NTPServer(Service): pass def receive( - self, - payload: Any, - session_id: Optional[str] = None, - **kwargs, + self, + payload: Any, + session_id: Optional[str] = None, + **kwargs, ) -> bool: """Receives a request from NTPClient. @@ -60,15 +59,13 @@ class NTPServer(Service): :return: True if valid NTP request else False. """ - if not (isinstance(payload, NTPPacket) and - payload.ntp_request.ntp_client): + if not (isinstance(payload, NTPPacket) and payload.ntp_request.ntp_client): _LOGGER.debug(f"{payload} is not a NTPPacket") return False payload: NTPPacket = payload if payload.ntp_request.ntp_client: self.sys_log.info( - f"{self.name}: Received request for {payload.ntp_request.ntp_client} " - f"from session {session_id}" + f"{self.name}: Received request for {payload.ntp_request.ntp_client} " f"from session {session_id}" ) # generate a reply with the current time time = datetime.now() From 9deb130d10bc699931bcdae141075d5d68cf2d00 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 15 Nov 2023 10:58:24 +0000 Subject: [PATCH 294/980] #2042: pre-commit changes --- .../system/services/ntp/ntp_client.py | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index d1fe7bbf..0e3646ae 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -1,18 +1,17 @@ from ipaddress import IPv4Address from typing import Dict, Optional + +from primaite import getLogger from primaite.simulator.network.protocols.ntp import NTPPacket from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.service import Service - -from primaite import getLogger - _LOGGER = getLogger(__name__) class NTPClient(Service): - """Represents a NTP client as a service""" + """Represents a NTP client as a service.""" ntp_server: Optional[IPv4Address] = None "The NTP server the client sends requests to." @@ -47,12 +46,12 @@ class NTPClient(Service): pass def send( - self, - payload: NTPPacket, - session_id: Optional[str] = None, - dest_ip_address: Optional[IPv4Address] = None, - dest_port: [Port] = Port.NTP, - **kwargs, + self, + payload: NTPPacket, + session_id: Optional[str] = None, + dest_ip_address: IPv4Address = ntp_server, + dest_port: [Port] = Port.NTP, + **kwargs, ) -> bool: """Requests NTP data from NTP server. @@ -74,20 +73,18 @@ class NTPClient(Service): payload: NTPPacket, session_id: Optional[str] = None, **kwargs, - ): - """Receives time data from server + ) -> bool: + """Receives time data from server. :param payload: The payload to be sent. :param session_id: The Session ID the payload is to originate from. Optional. :return: True if successful, False otherwise. """ - if not (isinstance(payload, NTPPacket) and - payload.ntp_request.ntp_client): + if not (isinstance(payload, NTPPacket) and payload.ntp_request.ntp_client): _LOGGER.debug(f"{payload} is not a NTPPacket") return False # XXX: compare received datetime with current time. Log error if differ by more than x ms? if payload.ntp_reply.ntp_datetime: - self.sys_log.info( - f"{self.name}: Received time update from NTP server{payload.ntp_reply.ntp_datetime}") + self.sys_log.info(f"{self.name}: Received time update from NTP server{payload.ntp_reply.ntp_datetime}") return True From c8f2f193bd609a665f847f926beeebca55bf10b2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 15 Nov 2023 12:52:18 +0000 Subject: [PATCH 295/980] Implement agent training with sb3 --- .../config/_package_data/example_config.yaml | 2 +- src/primaite/game/policy/__init__.py | 3 ++ src/primaite/game/policy/policy.py | 10 +++--- src/primaite/game/policy/sb3.py | 9 +++-- src/primaite/game/session.py | 34 +++++++++++++------ 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 0c39333c..17e5f5a5 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -112,7 +112,7 @@ game_config: - ref: defender team: BLUE - type: RLAgent + type: ProxyAgent observation_space: type: UC2BlueObservation diff --git a/src/primaite/game/policy/__init__.py b/src/primaite/game/policy/__init__.py index e69de29b..29196112 100644 --- a/src/primaite/game/policy/__init__.py +++ b/src/primaite/game/policy/__init__.py @@ -0,0 +1,3 @@ +from primaite.game.policy.sb3 import SB3Policy + +__all__ = ["SB3Policy"] diff --git a/src/primaite/game/policy/policy.py b/src/primaite/game/policy/policy.py index 5669a4ff..4c8dc447 100644 --- a/src/primaite/game/policy/policy.py +++ b/src/primaite/game/policy/policy.py @@ -16,7 +16,7 @@ class PolicyABC(ABC): Automatically populated when PolicyABC subclasses are defined. Used for defining from_config. """ - def __init_subclass__(cls, name: str, **kwargs: Any) -> None: + def __init_subclass__(cls, identifier: str, **kwargs: Any) -> None: """ Register a policy subclass. @@ -25,9 +25,9 @@ class PolicyABC(ABC): :raises ValueError: When attempting to create a policy with a duplicate name. """ super().__init_subclass__(**kwargs) - if name in cls._registry: - raise ValueError(f"Duplicate policy name {name}") - cls._registry[name] = cls + if identifier in cls._registry: + raise ValueError(f"Duplicate policy name {identifier}") + cls._registry[identifier] = cls return @abstractmethod @@ -78,6 +78,6 @@ class PolicyABC(ABC): # I should really define a config schema class using pydantic. PolicyType = cls._registry[config.rl_framework] - return PolicyType.from_config() + return PolicyType.from_config(config=config, session=session) # saving checkpoints logic will be handled here, it will invoke 'save' method which is implemented by the subclass diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/game/policy/sb3.py index 73df1b98..391b3115 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/game/policy/sb3.py @@ -1,6 +1,7 @@ """Stable baselines 3 policy.""" from typing import Literal, Optional, TYPE_CHECKING, Union +import numpy as np from stable_baselines3 import A2C, PPO from stable_baselines3.a2c import MlpPolicy as A2C_MLP from stable_baselines3.ppo import MlpPolicy as PPO_MLP @@ -11,7 +12,7 @@ if TYPE_CHECKING: from primaite.game.session import PrimaiteSession, TrainingOptions -class SB3Policy(PolicyABC): +class SB3Policy(PolicyABC, identifier="SB3"): """Single agent RL policy using stable baselines 3.""" def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): @@ -39,16 +40,18 @@ class SB3Policy(PolicyABC): # TODO: consider moving this loop to the session, only if this makes sense for RAY RLLIB for i in range(n_episodes): self._agent.learn(total_timesteps=n_time_steps) - self._save_checkpoint() + # self._save_checkpoint() pass def eval(self, n_episodes: int, n_time_steps: int, deterministic: bool) -> None: """Evaluate the agent.""" # TODO: consider moving this loop to the session, only if this makes sense for RAY RLLIB for episode in range(n_episodes): - obs = self.session.env.reset() + obs, info = self.session.env.reset() for step in range(n_time_steps): action, _states = self._agent.predict(obs, deterministic=deterministic) + if isinstance(action, np.ndarray): + action = np.int64(action) obs, rewards, truncated, terminated, info = self.session.env.step(action) def save(self) -> None: diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 5556dd87..8017d0d4 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -33,7 +33,7 @@ from primaite.simulator.system.services.web_server.web_server import WebServer _LOGGER = getLogger(__name__) -class PrimaiteEnv(gymnasium.Env): +class PrimaiteGymEnv(gymnasium.Env): """ Thin wrapper env to provide agents with a gymnasium API. @@ -57,10 +57,10 @@ class PrimaiteEnv(gymnasium.Env): state = self.session.get_sim_state() self.session.update_agents(state) - next_obs = self.agent.observation_manager.current_observation + next_obs = self._get_obs() reward = self.agent.reward_function.current_reward terminated = False - truncated = ... + truncated = False info = {} return next_obs, reward, terminated, truncated, info @@ -70,19 +70,25 @@ class PrimaiteEnv(gymnasium.Env): self.session.reset() state = self.session.get_sim_state() self.session.update_agents(state) - next_obs = self.agent.observation_manager.current_observation + next_obs = self._get_obs() info = {} return next_obs, info @property def action_space(self) -> gymnasium.Space: """Return the action space of the environment.""" - return self.agent.action_manager.action_space + return self.agent.action_manager.space @property def observation_space(self) -> gymnasium.Space: """Return the observation space of the environment.""" - return self.agent.observation_manager.observation_space + return gymnasium.spaces.flatten_space(self.agent.observation_manager.space) + + def _get_obs(self) -> ObsType: + """Return the current observation.""" + unflat_space = self.agent.observation_manager.space + unflat_obs = self.agent.observation_manager.current_observation + return gymnasium.spaces.flatten(unflat_space, unflat_obs) class PrimaiteSessionOptions(BaseModel): @@ -122,6 +128,9 @@ class PrimaiteSession: self.agents: List[AbstractAgent] = [] """List of agents.""" + self.rl_agents: List[ProxyAgent] = [] + """Subset of agent list including only the reinforcement learning agents.""" + self.step_counter: int = 0 """Current timestep within the episode.""" @@ -149,7 +158,8 @@ class PrimaiteSession: self.ref_map_links: Dict[str, Link] = {} """Mapping from human-readable link reference to link object. Used when parsing config files.""" - # self.env: + self.env: PrimaiteGymEnv + """The environment that the agent can consume. Could be PrimaiteEnv.""" def start_session(self) -> None: """Commence the training session.""" @@ -423,7 +433,7 @@ class PrimaiteSession: reward_function=rew_function, ) sess.agents.append(new_agent) - elif agent_type == "RLAgent": + elif agent_type == "ProxyAgent": new_agent = ProxyAgent( agent_name=agent_cfg["ref"], action_space=action_space, @@ -431,6 +441,7 @@ class PrimaiteSession: reward_function=rew_function, ) sess.agents.append(new_agent) + sess.rl_agents.append(new_agent) elif agent_type == "RedDatabaseCorruptingAgent": new_agent = RandomAgent( agent_name=agent_cfg["ref"], @@ -442,7 +453,10 @@ class PrimaiteSession: else: print("agent type not found") - # CREATE POLICY - sess.policy = PolicyABC.from_config(sess.training_options) + # CREATE ENVIRONMENT + sess.env = PrimaiteGymEnv(session=sess, agents=sess.rl_agents) + + # CREATE POLICY + sess.policy = PolicyABC.from_config(sess.training_options, session=sess) return sess From 6182b53bfd6858d8c33d70ad8adfa1f8ca2dbabb Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 15 Nov 2023 14:49:44 +0000 Subject: [PATCH 296/980] Fix incorrect number of steps per episode --- src/primaite/__init__.py | 1 + .../config/_package_data/example_config.yaml | 5 +- src/primaite/game/policy/sb3.py | 30 ++++----- src/primaite/game/session.py | 65 +++++++++++++++---- 4 files changed, 69 insertions(+), 32 deletions(-) diff --git a/src/primaite/__init__.py b/src/primaite/__init__.py index 30fc9ab9..789517f7 100644 --- a/src/primaite/__init__.py +++ b/src/primaite/__init__.py @@ -133,6 +133,7 @@ def _get_primaite_config() -> Dict: "DEBUG": logging.DEBUG, "INFO": logging.INFO, "WARN": logging.WARN, + "WARNING": logging.WARN, "ERROR": logging.ERROR, "CRITICAL": logging.CRITICAL, } diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 17e5f5a5..dca9620f 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -2,10 +2,9 @@ training_config: rl_framework: SB3 rl_algorithm: PPO seed: 333 - n_learn_episodes: 20 - n_learn_steps: 128 + n_learn_steps: 2560 n_eval_episodes: 5 - n_eval_steps: 128 + max_steps_per_episode: 128 deterministic_eval: false n_agents: 1 agent_references: diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/game/policy/sb3.py index 391b3115..ff710944 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/game/policy/sb3.py @@ -1,9 +1,9 @@ """Stable baselines 3 policy.""" from typing import Literal, Optional, TYPE_CHECKING, Union -import numpy as np from stable_baselines3 import A2C, PPO from stable_baselines3.a2c import MlpPolicy as A2C_MLP +from stable_baselines3.common.evaluation import evaluate_policy from stable_baselines3.ppo import MlpPolicy as PPO_MLP from primaite.game.policy.policy import PolicyABC @@ -33,26 +33,22 @@ class SB3Policy(PolicyABC, identifier="SB3"): env=self.session.env, n_steps=128, # this is not the number of steps in an episode, but the number of steps in a batch seed=seed, - ) # TODO: populate values once I figure out how to get them from the config / session + ) - def learn(self, n_episodes: int, n_time_steps: int) -> None: + def learn(self, n_time_steps: int) -> None: """Train the agent.""" - # TODO: consider moving this loop to the session, only if this makes sense for RAY RLLIB - for i in range(n_episodes): - self._agent.learn(total_timesteps=n_time_steps) - # self._save_checkpoint() - pass + self._agent.learn(total_timesteps=n_time_steps) - def eval(self, n_episodes: int, n_time_steps: int, deterministic: bool) -> None: + def eval(self, n_episodes: int, deterministic: bool) -> None: """Evaluate the agent.""" - # TODO: consider moving this loop to the session, only if this makes sense for RAY RLLIB - for episode in range(n_episodes): - obs, info = self.session.env.reset() - for step in range(n_time_steps): - action, _states = self._agent.predict(obs, deterministic=deterministic) - if isinstance(action, np.ndarray): - action = np.int64(action) - obs, rewards, truncated, terminated, info = self.session.env.step(action) + reward_data = evaluate_policy( + self._agent, + self.session.env, + n_eval_episodes=n_episodes, + deterministic=deterministic, + return_episode_rewards=True, + ) + print(reward_data) def save(self) -> None: """Save the agent.""" diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 8017d0d4..e85328ef 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -1,7 +1,9 @@ """PrimAITE session - the main entry point to training agents on PrimAITE.""" +from enum import Enum from ipaddress import IPv4Address from typing import Any, Dict, List, Literal, Optional, SupportsFloat, Tuple +import enlighten import gymnasium from gymnasium.core import ActType, ObsType from pydantic import BaseModel @@ -30,6 +32,8 @@ from primaite.simulator.system.services.red_services.data_manipulation_bot impor from primaite.simulator.system.services.service import Service from primaite.simulator.system.services.web_server.web_server import WebServer +progress_bar_manager = enlighten.get_manager() + _LOGGER = getLogger(__name__) @@ -60,7 +64,7 @@ class PrimaiteGymEnv(gymnasium.Env): next_obs = self._get_obs() reward = self.agent.reward_function.current_reward terminated = False - truncated = False + truncated = self.session.calculate_truncated() info = {} return next_obs, reward, terminated, truncated, info @@ -108,15 +112,22 @@ class TrainingOptions(BaseModel): rl_framework: Literal["SB3", "RLLIB"] rl_algorithm: Literal["PPO", "A2C"] seed: Optional[int] - n_learn_episodes: int n_learn_steps: int - n_eval_episodes: int = 0 - n_eval_steps: Optional[int] = None + n_eval_episodes: Optional[int] = None + max_steps_per_episode: int deterministic_eval: bool n_agents: int agent_references: List[str] +class SessionMode(Enum): + """Helper to keep track of the current session mode.""" + + TRAIN = "train" + EVAL = "eval" + MANUAL = "manual" + + class PrimaiteSession: """The main entrypoint for PrimAITE sessions, this manages a simulation, agents, and environments.""" @@ -161,18 +172,31 @@ class PrimaiteSession: self.env: PrimaiteGymEnv """The environment that the agent can consume. Could be PrimaiteEnv.""" + self.training_progress_bar: Optional[enlighten.Counter] = None + """training steps counter""" + + self.eval_progress_bar: Optional[enlighten.Counter] = None + """evaluation episodes counter""" + + self.mode: SessionMode = SessionMode.MANUAL + def start_session(self) -> None: """Commence the training session.""" + self.mode = SessionMode.TRAIN + self.training_progress_bar = progress_bar_manager.counter( + total=self.training_options.n_learn_steps, desc="Training steps" + ) n_learn_steps = self.training_options.n_learn_steps - n_learn_episodes = self.training_options.n_learn_episodes - n_eval_steps = self.training_options.n_eval_steps n_eval_episodes = self.training_options.n_eval_episodes - deterministic_eval = True # TODO: get this value from config - if n_learn_episodes > 0: - self.policy.learn(n_episodes=n_learn_episodes, n_time_steps=n_learn_steps) + deterministic_eval = self.training_options.deterministic_eval + self.policy.learn(n_time_steps=n_learn_steps) + self.mode = SessionMode.EVAL if n_eval_episodes > 0: - self.policy.eval(n_episodes=n_eval_episodes, n_time_steps=n_eval_steps, deterministic=deterministic_eval) + self.eval_progress_bar = progress_bar_manager.counter(total=n_eval_episodes, desc="Evaluation episodes") + self.policy.eval(n_episodes=n_eval_episodes, deterministic=deterministic_eval) + + self.mode = SessionMode.MANUAL def step(self): """ @@ -227,12 +251,29 @@ class PrimaiteSession: def advance_timestep(self) -> None: """Advance timestep.""" - self.simulation.apply_timestep(self.step_counter) self.step_counter += 1 + _LOGGER.debug(f"Advancing timestep to {self.step_counter} ") + self.simulation.apply_timestep(self.step_counter) + + if self.training_progress_bar and self.mode == SessionMode.TRAIN: + self.training_progress_bar.update() + + def calculate_truncated(self) -> bool: + """Calculate whether the episode is truncated.""" + current_step = self.step_counter + max_steps = self.training_options.max_steps_per_episode + if current_step >= max_steps: + return True + return False def reset(self) -> None: """Reset the session, this will reset the simulation.""" - return NotImplemented + self.episode_counter += 1 + self.step_counter = 0 + _LOGGER.debug(f"Restting primaite session, episode = {self.episode_counter}") + self.simulation.reset_component_for_episode(self.episode_counter) + if self.eval_progress_bar and self.mode == SessionMode.EVAL: + self.eval_progress_bar.update() def close(self) -> None: """Close the session, this will stop the env and close the simulation.""" From 0c544a9a263d7fb05d1ab16bc1647946043ea2f3 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 15 Nov 2023 15:58:10 +0000 Subject: [PATCH 297/980] #2042: Add support for apply_timestep() --- .../simulator/network/protocols/ntp.py | 2 +- .../system/services/ntp/ntp_client.py | 36 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/primaite/simulator/network/protocols/ntp.py b/src/primaite/simulator/network/protocols/ntp.py index 286c5664..e201a770 100644 --- a/src/primaite/simulator/network/protocols/ntp.py +++ b/src/primaite/simulator/network/protocols/ntp.py @@ -12,7 +12,7 @@ from primaite.simulator.network.protocols.packet import DataPacket class NTPRequest(BaseModel): """Represents a NTP Request packet.""" - ntp_client: IPv4Address = None + ntp_client: Optional[IPv4Address] = None class NTPReply(BaseModel): diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index 0e3646ae..e305970a 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -2,10 +2,10 @@ from ipaddress import IPv4Address from typing import Dict, Optional from primaite import getLogger -from primaite.simulator.network.protocols.ntp import NTPPacket +from primaite.simulator.network.protocols.ntp import NTPPacket, NTPRequest from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.services.service import Service +from primaite.simulator.system.services.service import Service, ServiceOperatingState _LOGGER = getLogger(__name__) @@ -13,6 +13,7 @@ _LOGGER = getLogger(__name__) class NTPClient(Service): """Represents a NTP client as a service.""" + ip_addr: Optional[IPv4Address] = None ntp_server: Optional[IPv4Address] = None "The NTP server the client sends requests to." @@ -30,7 +31,8 @@ class NTPClient(Service): The specifics of the software's state, including its health, criticality, and any other pertinent information, should be implemented in subclasses. - :return: A dictionary containing key-value pairs representing the current state of the software. + :return: A dictionary containing key-value pairs representing the current state + of the software. :rtype: Dict """ state = super().describe_state() @@ -65,7 +67,11 @@ class NTPClient(Service): self.sys_log.info(f"{self.name}: Sending NTP request {payload.ntp_request.ntp_client}") return super().send( - payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, **kwargs + payload=payload, + dest_ip_address=dest_ip_address, + dest_port=dest_port, + session_id=session_id, + **kwargs, ) def receive( @@ -86,5 +92,25 @@ class NTPClient(Service): # XXX: compare received datetime with current time. Log error if differ by more than x ms? if payload.ntp_reply.ntp_datetime: - self.sys_log.info(f"{self.name}: Received time update from NTP server{payload.ntp_reply.ntp_datetime}") + self.sys_log.info( + f"{self.name}: Received time \ + update from NTP server{payload.ntp_reply.ntp_datetime}" + ) return True + + def apply_timestep(self, timestep: int) -> None: + """ + For each timestep request the time tfrom the NTP server. + + In this instance, if any multi-timestep processes are currently + occurring (such as restarting or installation), then they are brought one step closer to + being finished. + + :param timestep: The current timestep number. (Amount of time since simulation episode began) + :type timestep: int + """ + super().apply_timestep(timestep) + if self.operating_state == ServiceOperatingState.RUNNING: + # request time from server + ntp_request = NTPPacket(NTPRequest()) + self.send(ntp_request) From 64e8b3bceaa5ef75208791757d24f01c85b27db7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 15 Nov 2023 16:04:16 +0000 Subject: [PATCH 298/980] Add basic primaite session e2e tests --- .../assets/configs/bad_primaite_session.yaml | 725 +++++++++++++++++ .../configs/eval_only_primaite_session.yaml | 729 ++++++++++++++++++ .../assets/configs/test_primaite_session.yaml | 729 ++++++++++++++++++ .../configs/train_only_primaite_session.yaml | 729 ++++++++++++++++++ tests/conftest.py | 104 +-- .../test_primaite_session.py | 51 ++ 6 files changed, 2981 insertions(+), 86 deletions(-) create mode 100644 tests/assets/configs/bad_primaite_session.yaml create mode 100644 tests/assets/configs/eval_only_primaite_session.yaml create mode 100644 tests/assets/configs/test_primaite_session.yaml create mode 100644 tests/assets/configs/train_only_primaite_session.yaml create mode 100644 tests/e2e_integration_tests/test_primaite_session.py diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml new file mode 100644 index 00000000..752d98a5 --- /dev/null +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -0,0 +1,725 @@ +training_config: + rl_framework: SB3 + rl_algorithm: PPO + se3ed: 333 + n_learn_steps: 2560 + n_eval_episodes: 5 + + + +game_config: + ports: + - ARP + - DNS + - HTTP + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + - UDP + + agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com + + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 + + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot + observations: + operating_status + health_status + folders: {} + + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com + + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 + + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot + observations: + operating_status + health_status + folders: {} + + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com + + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 + + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot + observations: + operating_status + health_status + folders: {} + + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com + + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 + + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot + observations: + operating_status + health_status + folders: {} + + action_space: + action_list: + - type: DONOTHING + # FileSystem: # PrimAITE v2 stuff -@pytest.mark.skip("Deprecated") # TODO: implement a similar test for primaite v3 -class TempPrimaiteSession: # PrimaiteSession): +class TempPrimaiteSession(PrimaiteSession): """ A temporary PrimaiteSession class. Uses context manager for deletion of files upon exit. """ - # def __init__( - # self, - # training_config_path: Union[str, Path], - # lay_down_config_path: Union[str, Path], - # ): - # super().__init__(training_config_path, lay_down_config_path) - # self.setup() + @classmethod + def from_config(cls, config_path: Union[str, Path]) -> "TempPrimaiteSession": + """Create a temporary PrimaiteSession object from a config file.""" + config_path = Path(config_path) + with open(config_path, "r") as f: + config = yaml.safe_load(f) - # @property - # def env(self) -> Primaite: - # """Direct access to the env for ease of testing.""" - # return self._agent_session._env # noqa + return super().from_config(cfg=config) - # def __enter__(self): - # return self + def __enter__(self): + return self - # def __exit__(self, type, value, tb): - # shutil.rmtree(self.session_path) - # _LOGGER.debug(f"Deleted temp session directory: {self.session_path}") + def __exit__(self, type, value, tb): + pass -@pytest.mark.skip("Deprecated") # TODO: implement a similar test for primaite v3 @pytest.fixture -def temp_primaite_session(request): - """ - Provides a temporary PrimaiteSession instance. +def temp_primaite_session(request) -> TempPrimaiteSession: + """Create a temporary PrimaiteSession object.""" - It's temporary as it uses a temporary directory as the session path. - - To use this fixture you need to: - - - parametrize your test function with: - - - "temp_primaite_session" - - [[path to training config, path to lay down config]] - - Include the temp_primaite_session fixture as a param in your test - function. - - use the temp_primaite_session as a context manager assigning is the - name 'session'. - - .. code:: python - - from primaite.config.lay_down_config import dos_very_basic_config_path - from primaite.config.training_config import main_training_config_path - @pytest.mark.parametrize( - "temp_primaite_session", - [ - [main_training_config_path(), dos_very_basic_config_path()] - ], - indirect=True - ) - def test_primaite_session(temp_primaite_session): - with temp_primaite_session as session: - # Learning outputs are saved in session.learning_path - session.learn() - - # Evaluation outputs are saved in session.evaluation_path - session.evaluate() - - # To ensure that all files are written, you must call .close() - session.close() - - # If you need to inspect any session outputs, it must be done - # inside the context manager - - # Now that we've exited the context manager, the - # session.session_path directory and its contents are deleted - """ - training_config_path = request.param[0] - lay_down_config_path = request.param[1] - with patch("primaite.agents.agent_abc.get_session_path", get_temp_session_path) as mck: - mck.session_timestamp = datetime.now() - - return TempPrimaiteSession(training_config_path, lay_down_config_path) - - -@pytest.mark.skip("Deprecated") # TODO: implement a similar test for primaite v3 -@pytest.fixture -def temp_session_path() -> Path: - """ - Get a temp directory session path the test session will output to. - - :return: The session directory path. - """ - session_timestamp = datetime.now() - date_dir = session_timestamp.strftime("%Y-%m-%d") - session_path = session_timestamp.strftime("%Y-%m-%d_%H-%M-%S") - session_path = Path(tempfile.gettempdir()) / "_primaite" / date_dir / session_path - session_path.mkdir(exist_ok=True, parents=True) - - return session_path + config_path = request.param[0] + return TempPrimaiteSession.from_config(config_path=config_path) diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py new file mode 100644 index 00000000..5e1da4ff --- /dev/null +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -0,0 +1,51 @@ +import pytest + +from tests.conftest import TempPrimaiteSession + +CFG_PATH = "tests/assets/configs/test_primaite_session.yaml" +TRAINING_ONLY_PATH = "tests/assets/configs/train_only_primaite_session.yaml" +EVAL_ONLY_PATH = "tests/assets/configs/eval_only_primaite_session.yaml" + + +class TestPrimaiteSession: + @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) + def test_creating_session(self, temp_primaite_session): + """Check that creating a session from config works.""" + with temp_primaite_session as session: + if not isinstance(session, TempPrimaiteSession): + raise AssertionError + + assert session is not None + assert session.simulation + assert len(session.agents) == 3 + assert len(session.rl_agents) == 1 + + assert session.policy + assert session.env + + assert session.simulation.network + assert len(session.simulation.network.nodes) == 10 + + @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) + def test_start_session(self, temp_primaite_session): + """Make sure you can go all the way through the session without errors.""" + with temp_primaite_session as session: + session: TempPrimaiteSession + session.start_session() + # TODO: check that env was closed, that the model was saved, etc. + + @pytest.mark.parametrize("temp_primaite_session", [[TRAINING_ONLY_PATH]], indirect=True) + def test_training_only_session(self, temp_primaite_session): + """Check that you can run a training-only session.""" + with temp_primaite_session as session: + session: TempPrimaiteSession + session.start_session() + # TODO: include checks that the model was trained, e.g. that the loss changed and checkpoints were saved? + + @pytest.mark.parametrize("temp_primaite_session", [[EVAL_ONLY_PATH]], indirect=True) + def test_eval_only_session(self, temp_primaite_session): + """Check that you can load a model and run an eval-only session.""" + with temp_primaite_session as session: + session: TempPrimaiteSession + session.start_session() + # TODO: include checks that the model was loaded and that the eval-only session ran From 4cc7ba152244ed1d171b192a7d096a0ad20dac9c Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 15 Nov 2023 16:59:56 +0000 Subject: [PATCH 299/980] Add ability to save sb3 final model --- src/primaite/game/io.py | 54 ++++++++++++++++++++++++++++++ src/primaite/game/policy/policy.py | 3 +- src/primaite/game/policy/sb3.py | 16 +++++---- src/primaite/game/session.py | 15 +++++++++ 4 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 src/primaite/game/io.py diff --git a/src/primaite/game/io.py b/src/primaite/game/io.py new file mode 100644 index 00000000..76d5ed1c --- /dev/null +++ b/src/primaite/game/io.py @@ -0,0 +1,54 @@ +from datetime import datetime +from pathlib import Path +from typing import Optional + +from pydantic import BaseModel + +from primaite import PRIMAITE_PATHS + + +class SessionIOSettings(BaseModel): + """Schema for session IO settings.""" + + save_final_model: bool = True + """Whether to save the final model right at the end of training.""" + save_checkpoints: bool = False + """Whether to save a checkpoint model every `checkpoint_interval` episodes""" + checkpoint_interval: int = 10 + """How often to save a checkpoint model (if save_checkpoints is True).""" + save_logs: bool = True + """Whether to save logs""" + save_transactions: bool = True + """Whether to save transactions, If true, the session path will have a transactions folder.""" + save_tensorboard_logs: bool = False + """Whether to save tensorboard logs. If true, the session path will have a tenorboard_logs folder.""" + + +class SessionIO: + """ + Class for managing session IO. + + Currently it's handling path generation, but could expand to handle loading, transaction, tensorboard, and so on. + """ + + def __init__(self, settings: SessionIOSettings = SessionIOSettings()) -> None: + self.settings = settings + self.session_path = self.generate_session_path() + + def generate_session_path(self, timestamp: Optional[datetime] = None) -> Path: + """Create a folder for the session and return the path to it.""" + if timestamp is None: + timestamp = datetime.now() + date_str = timestamp.strftime("%Y-%m-%d") + time_str = timestamp.strftime("%H-%M-%S") + session_path = PRIMAITE_PATHS.user_sessions_path / date_str / time_str + session_path.mkdir(exist_ok=True, parents=True) + return session_path + + def generate_model_save_path(self, agent_name: str) -> Path: + """Return the path where the final model will be saved (excluding filename extension).""" + return self.session_path / "checkpoints" / f"{agent_name}_final" + + def generate_checkpoint_save_path(self, agent_name: str, episode: int) -> Path: + """Return the path where the checkpoint model will be saved (excluding filename extension).""" + return self.session_path / "checkpoints" / f"{agent_name}_checkpoint_{episode}.pt" diff --git a/src/primaite/game/policy/policy.py b/src/primaite/game/policy/policy.py index 4c8dc447..6a2381c1 100644 --- a/src/primaite/game/policy/policy.py +++ b/src/primaite/game/policy/policy.py @@ -1,5 +1,6 @@ """Base class and common logic for RL policies.""" from abc import ABC, abstractmethod +from pathlib import Path from typing import Any, Dict, TYPE_CHECKING if TYPE_CHECKING: @@ -54,7 +55,7 @@ class PolicyABC(ABC): pass @abstractmethod - def save(self) -> None: + def save(self, save_path: Path) -> None: """Save the agent.""" pass diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/game/policy/sb3.py index ff710944..1be4f915 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/game/policy/sb3.py @@ -1,4 +1,5 @@ """Stable baselines 3 policy.""" +from pathlib import Path from typing import Literal, Optional, TYPE_CHECKING, Union from stable_baselines3 import A2C, PPO @@ -50,12 +51,15 @@ class SB3Policy(PolicyABC, identifier="SB3"): ) print(reward_data) - def save(self) -> None: - """Save the agent.""" - savepath = ( - "temp/path/to/save.pth" # TODO: populate values once I figure out how to get them from the config / session - ) - self._agent.save(savepath) + def save(self, save_path: Path) -> None: + """ + Save the current policy parameters. + + Warning: The recommended way to save model checkpoints is to use a callback within the `learn()` method. Please + refer to https://stable-baselines3.readthedocs.io/en/master/guide/callbacks.html for more information. + Therefore, this method is only used to save the final model. + """ + self._agent.save(save_path) pass def load(self) -> None: diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index e85328ef..37c34da9 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -13,6 +13,7 @@ from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractAgent, ProxyAgent, RandomAgent from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction +from primaite.game.io import SessionIO, SessionIOSettings from primaite.game.policy.policy import PolicyABC from primaite.simulator.network.hardware.base import Link, NIC, Node from primaite.simulator.network.hardware.nodes.computer import Computer @@ -179,6 +180,10 @@ class PrimaiteSession: """evaluation episodes counter""" self.mode: SessionMode = SessionMode.MANUAL + """Current session mode.""" + + self.io_manager = SessionIO() + """IO manager for the session.""" def start_session(self) -> None: """Commence the training session.""" @@ -190,6 +195,7 @@ class PrimaiteSession: n_eval_episodes = self.training_options.n_eval_episodes deterministic_eval = self.training_options.deterministic_eval self.policy.learn(n_time_steps=n_learn_steps) + self.save_models() self.mode = SessionMode.EVAL if n_eval_episodes > 0: @@ -198,6 +204,11 @@ class PrimaiteSession: self.mode = SessionMode.MANUAL + def save_models(self) -> None: + """Save the RL models.""" + save_path = self.io_manager.generate_model_save_path("temp_model_name") + self.policy.save(save_path) + def step(self): """ Perform one step of the simulation/agent loop. @@ -500,4 +511,8 @@ class PrimaiteSession: # CREATE POLICY sess.policy = PolicyABC.from_config(sess.training_options, session=sess) + # READ IO SETTINGS + io_settings = cfg.get("io_settings", {}) + sess.io_manager.settings = SessionIO(settings=SessionIOSettings(**io_settings)) + return sess From 1c5ff66d26599834f75c7cbc402fdf4f05a041c8 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Thu, 16 Nov 2023 13:26:30 +0000 Subject: [PATCH 300/980] Pass execution definition from config to agent --- .../config/_package_data/example_config.yaml | 4 ++++ src/primaite/game/agent/interface.py | 15 +++++++++++++-- src/primaite/game/session.py | 9 +++++++-- .../simulator/system/applications/web_browser.py | 3 +++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index ee42cf4f..f034f9ea 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -58,6 +58,10 @@ game_config: team: RED type: RedDatabaseCorruptingAgent + execution_definition: + port_scan_p_of_success: 0.1 + data_manipulation_p_of_success: 0.1 + observation_space: type: UC2RedObservation options: diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 78d18a68..d04b298e 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -3,6 +3,7 @@ from abc import ABC, abstractmethod from typing import Dict, List, Optional, Tuple, TypeAlias, Union import numpy as np +from pydantic import BaseModel from primaite.game.agent.actions import ActionManager from primaite.game.agent.observations import ObservationSpace @@ -11,6 +12,11 @@ from primaite.game.agent.rewards import RewardFunction ObsType: TypeAlias = Union[Dict, np.ndarray] +class AgentExecutionDefinition(BaseModel): + port_scan_p_of_success: float = 0.1 + data_manipulation_p_of_success: float = 0.1 + + class AbstractAgent(ABC): """Base class for scripted and RL agents.""" @@ -20,6 +26,7 @@ class AbstractAgent(ABC): action_space: Optional[ActionManager], observation_space: Optional[ObservationSpace], reward_function: Optional[RewardFunction], + execution_definition: Optional[AgentExecutionDefinition] ) -> None: """ Initialize an agent. @@ -40,7 +47,7 @@ class AbstractAgent(ABC): # exection definiton converts CAOS action to Primaite simulator request, sometimes having to enrich the info # by for example specifying target ip addresses, or converting a node ID into a uuid - self.execution_definition = None + self.execution_definition = execution_definition or AgentExecutionDefinition() def convert_state_to_obs(self, state: Dict) -> ObsType: """ @@ -110,7 +117,11 @@ class RandomAgent(AbstractScriptedAgent): return self.action_space.get_action(self.action_space.space.sample()) class DataManipulationAgent(AbstractScriptedAgent): - pass + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: + return self.action_space.get_action(self.action_space.space.sample()) class AbstractGATEAgent(AbstractAgent): """Base class for actors controlled via external messages, such as RL policies.""" diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 9c2bb6b7..082ed281 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -10,7 +10,7 @@ from pydantic import BaseModel from primaite import getLogger from primaite.game.agent.actions import ActionManager -from primaite.game.agent.interface import AbstractAgent, RandomAgent +from primaite.game.agent.interface import AbstractAgent, RandomAgent, DataManipulationAgent, AgentExecutionDefinition from primaite.game.agent.observations import ObservationSpace from primaite.game.agent.rewards import RewardFunction from primaite.simulator.network.hardware.base import Link, NIC, Node @@ -438,6 +438,8 @@ class PrimaiteSession: # CREATE REWARD FUNCTION rew_function = RewardFunction.from_config(reward_function_cfg, session=sess) + execution_definition = AgentExecutionDefinition(**agent_cfg.get("execution_definition", {})) + # CREATE AGENT if agent_type == "GreenWebBrowsingAgent": # TODO: implement non-random agents and fix this parsing @@ -446,6 +448,7 @@ class PrimaiteSession: action_space=action_space, observation_space=obs_space, reward_function=rew_function, + execution_definition=execution_definition, ) sess.agents.append(new_agent) elif agent_type == "GATERLAgent": @@ -454,15 +457,17 @@ class PrimaiteSession: action_space=action_space, observation_space=obs_space, reward_function=rew_function, + execution_definition=execution_definition, ) sess.agents.append(new_agent) sess.rl_agent = new_agent elif agent_type == "RedDatabaseCorruptingAgent": - new_agent = RandomAgent( + new_agent = DataManipulationAgent( agent_name=agent_cfg["ref"], action_space=action_space, observation_space=obs_space, reward_function=rew_function, + execution_definition=execution_definition, ) sess.agents.append(new_agent) else: diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 6799358d..964e1ce4 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -135,3 +135,6 @@ class WebBrowser(Application): self.sys_log.info(f"{self.name}: Received HTTP {payload.status_code.value}") self.latest_response = payload return True + + def execute(self): + pass From 829500a60f70da63a0c9b2eba30d24f45c523393 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 16 Nov 2023 14:37:37 +0000 Subject: [PATCH 301/980] Get sb3 checkpoints saving during training --- .../config/_package_data/example_config.yaml | 6 ++++- src/primaite/game/io.py | 4 ++-- src/primaite/game/policy/policy.py | 4 ++-- src/primaite/game/policy/sb3.py | 19 +++++++++++----- src/primaite/game/session.py | 22 ++++++++++++------- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index dca9620f..e0ff9276 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -2,7 +2,7 @@ training_config: rl_framework: SB3 rl_algorithm: PPO seed: 333 - n_learn_steps: 2560 + n_learn_episodes: 25 n_eval_episodes: 5 max_steps_per_episode: 128 deterministic_eval: false @@ -10,6 +10,10 @@ training_config: agent_references: - defender +io_settings: + save_checkpoints: true + checkpoint_interval: 5 + game_config: ports: diff --git a/src/primaite/game/io.py b/src/primaite/game/io.py index 76d5ed1c..e613316d 100644 --- a/src/primaite/game/io.py +++ b/src/primaite/game/io.py @@ -32,8 +32,8 @@ class SessionIO: """ def __init__(self, settings: SessionIOSettings = SessionIOSettings()) -> None: - self.settings = settings - self.session_path = self.generate_session_path() + self.settings: SessionIOSettings = settings + self.session_path: Path = self.generate_session_path() def generate_session_path(self, timestamp: Optional[datetime] = None) -> Path: """Create a folder for the session and return the path to it.""" diff --git a/src/primaite/game/policy/policy.py b/src/primaite/game/policy/policy.py index 6a2381c1..a7052367 100644 --- a/src/primaite/game/policy/policy.py +++ b/src/primaite/game/policy/policy.py @@ -45,12 +45,12 @@ class PolicyABC(ABC): """Reference to the session.""" @abstractmethod - def learn(self, n_episodes: int, n_time_steps: int) -> None: + def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: """Train the agent.""" pass @abstractmethod - def eval(self, n_episodes: int, n_time_steps: int, deterministic: bool) -> None: + def eval(self, n_episodes: int, timesteps_per_episode: int, deterministic: bool) -> None: """Evaluate the agent.""" pass diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/game/policy/sb3.py index 1be4f915..10f22e05 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/game/policy/sb3.py @@ -4,6 +4,7 @@ from typing import Literal, Optional, TYPE_CHECKING, Union from stable_baselines3 import A2C, PPO from stable_baselines3.a2c import MlpPolicy as A2C_MLP +from stable_baselines3.common.callbacks import CheckpointCallback from stable_baselines3.common.evaluation import evaluate_policy from stable_baselines3.ppo import MlpPolicy as PPO_MLP @@ -36,9 +37,17 @@ class SB3Policy(PolicyABC, identifier="SB3"): seed=seed, ) - def learn(self, n_time_steps: int) -> None: + def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: """Train the agent.""" - self._agent.learn(total_timesteps=n_time_steps) + if self.session.io_manager.settings.save_checkpoints: + checkpoint_callback = CheckpointCallback( + save_freq=timesteps_per_episode * self.session.io_manager.settings.checkpoint_interval, + save_path=self.session.io_manager.generate_model_save_path("sb3"), + name_prefix="sb3_model", + ) + else: + checkpoint_callback = None + self._agent.learn(total_timesteps=n_episodes * timesteps_per_episode, callback=checkpoint_callback) def eval(self, n_episodes: int, deterministic: bool) -> None: """Evaluate the agent.""" @@ -60,12 +69,10 @@ class SB3Policy(PolicyABC, identifier="SB3"): Therefore, this method is only used to save the final model. """ self._agent.save(save_path) - pass - def load(self) -> None: + def load(self, model_path: Path) -> None: """Load agent from a checkpoint.""" - self._agent_class.load("temp/path/to/save.pth", env=self.session.env) - pass + self._agent = self._agent_class.load(model_path, env=self.session.env) def close(self) -> None: """Close the agent.""" diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 37c34da9..a2e83cbb 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -112,11 +112,12 @@ class TrainingOptions(BaseModel): rl_framework: Literal["SB3", "RLLIB"] rl_algorithm: Literal["PPO", "A2C"] - seed: Optional[int] - n_learn_steps: int + n_learn_episodes: int n_eval_episodes: Optional[int] = None max_steps_per_episode: int + # checkpoint_freq: Optional[int] = None deterministic_eval: bool + seed: Optional[int] n_agents: int agent_references: List[str] @@ -188,13 +189,18 @@ class PrimaiteSession: def start_session(self) -> None: """Commence the training session.""" self.mode = SessionMode.TRAIN - self.training_progress_bar = progress_bar_manager.counter( - total=self.training_options.n_learn_steps, desc="Training steps" - ) - n_learn_steps = self.training_options.n_learn_steps + n_learn_episodes = self.training_options.n_learn_episodes n_eval_episodes = self.training_options.n_eval_episodes + max_steps_per_episode = self.training_options.max_steps_per_episode + self.training_progress_bar = progress_bar_manager.counter( + total=n_learn_episodes * max_steps_per_episode, desc="Training steps" + ) + deterministic_eval = self.training_options.deterministic_eval - self.policy.learn(n_time_steps=n_learn_steps) + self.policy.learn( + n_episodes=n_learn_episodes, + timesteps_per_episode=max_steps_per_episode, + ) self.save_models() self.mode = SessionMode.EVAL @@ -513,6 +519,6 @@ class PrimaiteSession: # READ IO SETTINGS io_settings = cfg.get("io_settings", {}) - sess.io_manager.settings = SessionIO(settings=SessionIOSettings(**io_settings)) + sess.io_manager = SessionIO(settings=SessionIOSettings(**io_settings)) return sess From 7ee2c4220a6eb80e0ed00e9a1000ab32df19aa60 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Thu, 16 Nov 2023 15:04:01 +0000 Subject: [PATCH 302/980] #2042: ntp_client test --- .../system/services/ntp/ntp_client.py | 6 ++++- .../system/test_ntp_client_server.py | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/integration_tests/system/test_ntp_client_server.py diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index e305970a..123de7cc 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -100,7 +100,7 @@ class NTPClient(Service): def apply_timestep(self, timestep: int) -> None: """ - For each timestep request the time tfrom the NTP server. + For each timestep request the time from the NTP server. In this instance, if any multi-timestep processes are currently occurring (such as restarting or installation), then they are brought one step closer to @@ -114,3 +114,7 @@ class NTPClient(Service): # request time from server ntp_request = NTPPacket(NTPRequest()) self.send(ntp_request) + return True + else: + self.sys_log.debug(f"{self.name} ntp client not running") + return False diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py new file mode 100644 index 00000000..5d301d2b --- /dev/null +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -0,0 +1,25 @@ +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.protocols.ntp import NTPPacket +from primaite.simulator.system.services.ntp.ntp_client import NTPClient +from primaite.simulator.system.services.ntp.ntp_server import NTPServer +from primaite.simulator.system.services.service import ServiceOperatingState + +# Define one node to be an NTP server and another node to be a NTP Client. + + +def test_ntp_client_server(network): + server: Server = network.get_node_by_hostname("ntp_server") + client: Computer = network.get_node_by_hostname("ntp_client") + + ntp_server: NTPServer = server.software_manager.software["NTP_Server"] + ntp_client: NTPClient = client.software_manager.software["NTP_Client"] + + assert ntp_server.operating_state == ServiceOperatingState.RUNNING + assert ntp_client.operating_state == ServiceOperatingState.RUNNING + + ntp_client.send(payload=NTPPacket()) + assert ntp_server.receive() is True + assert ntp_client.receive() is True + + assert ntp_client.apply_timestep(1) is True From 7545c25a467c5768c3516e774c702a659c172f48 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 16 Nov 2023 15:11:03 +0000 Subject: [PATCH 303/980] Make pytest patch with temporary session dir --- src/primaite/__init__.py | 36 +++++++++---------- .../configs/eval_only_primaite_session.yaml | 2 +- .../assets/configs/test_primaite_session.yaml | 2 +- .../configs/train_only_primaite_session.yaml | 2 +- tests/conftest.py | 14 ++++---- tests/mock_and_patch/get_session_path_mock.py | 2 +- 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/primaite/__init__.py b/src/primaite/__init__.py index 789517f7..28245d33 100644 --- a/src/primaite/__init__.py +++ b/src/primaite/__init__.py @@ -29,6 +29,15 @@ class _PrimaitePaths: def __init__(self) -> None: self._dirs: Final[PlatformDirs] = PlatformDirs(appname="primaite", version=__version__) + self.user_home_path = self.generate_user_home_path() + self.user_sessions_path = self.generate_user_sessions_path() + self.user_config_path = self.generate_user_config_path() + self.user_notebooks_path = self.generate_user_notebooks_path() + self.app_home_path = self.generate_app_home_path() + self.app_config_dir_path = self.generate_app_config_dir_path() + self.app_config_file_path = self.generate_app_config_file_path() + self.app_log_dir_path = self.generate_app_log_dir_path() + self.app_log_file_path = self.generate_app_log_file_path() def _get_dirs_properties(self) -> List[str]: class_items = self.__class__.__dict__.items() @@ -43,55 +52,47 @@ class _PrimaitePaths: for p in self._get_dirs_properties(): getattr(self, p) - @property - def user_home_path(self) -> Path: + def generate_user_home_path(self) -> Path: """The PrimAITE user home path.""" path = Path.home() / "primaite" / __version__ path.mkdir(exist_ok=True, parents=True) return path - @property - def user_sessions_path(self) -> Path: + def generate_user_sessions_path(self) -> Path: """The PrimAITE user sessions path.""" path = self.user_home_path / "sessions" path.mkdir(exist_ok=True, parents=True) return path - @property - def user_config_path(self) -> Path: + def generate_user_config_path(self) -> Path: """The PrimAITE user config path.""" path = self.user_home_path / "config" path.mkdir(exist_ok=True, parents=True) return path - @property - def user_notebooks_path(self) -> Path: + def generate_user_notebooks_path(self) -> Path: """The PrimAITE user notebooks path.""" path = self.user_home_path / "notebooks" path.mkdir(exist_ok=True, parents=True) return path - @property - def app_home_path(self) -> Path: + def generate_app_home_path(self) -> Path: """The PrimAITE app home path.""" path = self._dirs.user_data_path path.mkdir(exist_ok=True, parents=True) return path - @property - def app_config_dir_path(self) -> Path: + def generate_app_config_dir_path(self) -> Path: """The PrimAITE app config directory path.""" path = self._dirs.user_config_path path.mkdir(exist_ok=True, parents=True) return path - @property - def app_config_file_path(self) -> Path: + def generate_app_config_file_path(self) -> Path: """The PrimAITE app config file path.""" return self.app_config_dir_path / "primaite_config.yaml" - @property - def app_log_dir_path(self) -> Path: + def generate_app_log_dir_path(self) -> Path: """The PrimAITE app log directory path.""" if sys.platform == "win32": path = self.app_home_path / "logs" @@ -100,8 +101,7 @@ class _PrimaitePaths: path.mkdir(exist_ok=True, parents=True) return path - @property - def app_log_file_path(self) -> Path: + def generate_app_log_file_path(self) -> Path: """The PrimAITE app log file path.""" return self.app_log_dir_path / "primaite.log" diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index 2ab7a2cc..1c9104d1 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -2,7 +2,7 @@ training_config: rl_framework: SB3 rl_algorithm: PPO seed: 333 - n_learn_steps: 0 + n_learn_episodes: 0 n_eval_episodes: 5 max_steps_per_episode: 128 deterministic_eval: false diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index dca9620f..201528eb 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -2,7 +2,7 @@ training_config: rl_framework: SB3 rl_algorithm: PPO seed: 333 - n_learn_steps: 2560 + n_learn_episodes: 10 n_eval_episodes: 5 max_steps_per_episode: 128 deterministic_eval: false diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index 5f0cfc77..1ed10212 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -2,7 +2,7 @@ training_config: rl_framework: SB3 rl_algorithm: PPO seed: 333 - n_learn_steps: 2560 + n_learn_episodes: 10 n_eval_episodes: 0 max_steps_per_episode: 128 deterministic_eval: false diff --git a/tests/conftest.py b/tests/conftest.py index 60b69a1e..fe450213 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,7 +5,6 @@ import tempfile from datetime import datetime from pathlib import Path from typing import Any, Dict, Union -from unittest.mock import patch import nodeenv import pytest @@ -22,13 +21,15 @@ from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.services.service import Service -from tests.mock_and_patch.get_session_path_mock import get_temp_session_path +from tests.mock_and_patch.get_session_path_mock import temp_user_sessions_path ACTION_SPACE_NODE_VALUES = 1 ACTION_SPACE_NODE_ACTION_VALUES = 1 _LOGGER = getLogger(__name__) +from primaite import PRIMAITE_PATHS + # PrimAITE v3 stuff from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.hardware.base import Node @@ -97,8 +98,9 @@ class TempPrimaiteSession(PrimaiteSession): @pytest.fixture -def temp_primaite_session(request) -> TempPrimaiteSession: +def temp_primaite_session(request, monkeypatch) -> TempPrimaiteSession: """Create a temporary PrimaiteSession object.""" - - config_path = request.param[0] - return TempPrimaiteSession.from_config(config_path=config_path) + with monkeypatch.context() as m: + m.setattr(PRIMAITE_PATHS, "user_sessions_path", temp_user_sessions_path()) + config_path = request.param[0] + return TempPrimaiteSession.from_config(config_path=config_path) diff --git a/tests/mock_and_patch/get_session_path_mock.py b/tests/mock_and_patch/get_session_path_mock.py index 16c4a274..06fe5893 100644 --- a/tests/mock_and_patch/get_session_path_mock.py +++ b/tests/mock_and_patch/get_session_path_mock.py @@ -9,7 +9,7 @@ from primaite import getLogger _LOGGER = getLogger(__name__) -def get_temp_session_path(session_timestamp: datetime) -> Path: +def temp_user_sessions_path() -> Path: """ Get a temp directory session path the test session will output to. From 13c49bf3eaeca21c737f68b745351d59b1098f8e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 16 Nov 2023 15:19:14 +0000 Subject: [PATCH 304/980] Fix session path monkeypatch --- tests/conftest.py | 7 +++---- tests/e2e_integration_tests/test_primaite_session.py | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index fe450213..6a65b12f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -100,7 +100,6 @@ class TempPrimaiteSession(PrimaiteSession): @pytest.fixture def temp_primaite_session(request, monkeypatch) -> TempPrimaiteSession: """Create a temporary PrimaiteSession object.""" - with monkeypatch.context() as m: - m.setattr(PRIMAITE_PATHS, "user_sessions_path", temp_user_sessions_path()) - config_path = request.param[0] - return TempPrimaiteSession.from_config(config_path=config_path) + monkeypatch.setattr(PRIMAITE_PATHS, "user_sessions_path", temp_user_sessions_path()) + config_path = request.param[0] + return TempPrimaiteSession.from_config(config_path=config_path) diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index 5e1da4ff..c6179e9a 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -40,6 +40,8 @@ class TestPrimaiteSession: with temp_primaite_session as session: session: TempPrimaiteSession session.start_session() + for i in range(100): + print(session.io_manager.generate_session_path()) # TODO: include checks that the model was trained, e.g. that the loss changed and checkpoints were saved? @pytest.mark.parametrize("temp_primaite_session", [[EVAL_ONLY_PATH]], indirect=True) From 0b9bdedebd719849038ed6736598d8bd09b321ff Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 16 Nov 2023 15:28:38 +0000 Subject: [PATCH 305/980] Fix typehints --- src/primaite/game/agent/rewards.py | 4 ++-- src/primaite/game/policy/policy.py | 4 ++-- src/primaite/game/policy/sb3.py | 4 ++-- src/primaite/game/session.py | 4 ++-- tests/e2e_integration_tests/test_primaite_session.py | 2 -- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 49d56e67..da1331b0 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -26,7 +26,7 @@ the structure: ``` """ from abc import abstractmethod -from typing import Dict, List, Tuple, TYPE_CHECKING +from typing import Dict, List, Tuple, Type, TYPE_CHECKING from primaite import getLogger from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE @@ -228,7 +228,7 @@ class WebServer404Penalty(AbstractReward): class RewardFunction: """Manages the reward function for the agent.""" - __rew_class_identifiers: Dict[str, type[AbstractReward]] = { + __rew_class_identifiers: Dict[str, Type[AbstractReward]] = { "DUMMY": DummyReward, "DATABASE_FILE_INTEGRITY": DatabaseFileIntegrity, "WEB_SERVER_404_PENALTY": WebServer404Penalty, diff --git a/src/primaite/game/policy/policy.py b/src/primaite/game/policy/policy.py index a7052367..249c3b52 100644 --- a/src/primaite/game/policy/policy.py +++ b/src/primaite/game/policy/policy.py @@ -1,7 +1,7 @@ """Base class and common logic for RL policies.""" from abc import ABC, abstractmethod from pathlib import Path -from typing import Any, Dict, TYPE_CHECKING +from typing import Any, Dict, Type, TYPE_CHECKING if TYPE_CHECKING: from primaite.game.session import PrimaiteSession, TrainingOptions @@ -10,7 +10,7 @@ if TYPE_CHECKING: class PolicyABC(ABC): """Base class for reinforcement learning agents.""" - _registry: Dict[str, type["PolicyABC"]] = {} + _registry: Dict[str, Type["PolicyABC"]] = {} """ Registry of policy types, keyed by name. diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/game/policy/sb3.py index 10f22e05..bb35775a 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/game/policy/sb3.py @@ -1,6 +1,6 @@ """Stable baselines 3 policy.""" from pathlib import Path -from typing import Literal, Optional, TYPE_CHECKING, Union +from typing import Literal, Optional, Type, TYPE_CHECKING, Union from stable_baselines3 import A2C, PPO from stable_baselines3.a2c import MlpPolicy as A2C_MLP @@ -21,7 +21,7 @@ class SB3Policy(PolicyABC, identifier="SB3"): """Initialize a stable baselines 3 policy.""" super().__init__(session=session) - self._agent_class: type[Union[PPO, A2C]] + self._agent_class: Type[Union[PPO, A2C]] if algorithm == "PPO": self._agent_class = PPO policy = PPO_MLP diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index a2e83cbb..88c1e061 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -52,7 +52,7 @@ class PrimaiteGymEnv(gymnasium.Env): self.session: "PrimaiteSession" = session self.agent: ProxyAgent = agents[0] - def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, dict[str, Any]]: + def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: """Perform a step in the environment.""" # make ProxyAgent store the action chosen my the RL policy self.agent.store_action(action) @@ -70,7 +70,7 @@ class PrimaiteGymEnv(gymnasium.Env): return next_obs, reward, terminated, truncated, info - def reset(self, seed: Optional[int] = None) -> tuple[ObsType, dict[str, Any]]: + def reset(self, seed: Optional[int] = None) -> Tuple[ObsType, Dict[str, Any]]: """Reset the environment.""" self.session.reset() state = self.session.get_sim_state() diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index c6179e9a..5e1da4ff 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -40,8 +40,6 @@ class TestPrimaiteSession: with temp_primaite_session as session: session: TempPrimaiteSession session.start_session() - for i in range(100): - print(session.io_manager.generate_session_path()) # TODO: include checks that the model was trained, e.g. that the loss changed and checkpoints were saved? @pytest.mark.parametrize("temp_primaite_session", [[EVAL_ONLY_PATH]], indirect=True) From e52d1fbd4500195a6bd0df9935a24ca3ec0291f5 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 16 Nov 2023 15:29:48 +0000 Subject: [PATCH 306/980] Add enlighten dependency --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 51ed84f2..1e074c25 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,8 @@ dependencies = [ "stable-baselines3[extra]==2.1.0", "tensorflow==2.12.0", "typer[all]==0.9.0", - "pydantic==2.1.1" + "pydantic==2.1.1", + "enlighten==1.12.2" ] [tool.setuptools.dynamic] From 0861663cc1617cc38f056d8f64a64d4ac4313ca5 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 16 Nov 2023 15:40:49 +0000 Subject: [PATCH 307/980] Add agent loading --- src/primaite/cli.py | 3 ++- src/primaite/game/session.py | 5 ++++- src/primaite/main.py | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/primaite/cli.py b/src/primaite/cli.py index 0f17525e..81ab2792 100644 --- a/src/primaite/cli.py +++ b/src/primaite/cli.py @@ -119,6 +119,7 @@ def setup(overwrite_existing: bool = True) -> None: @app.command() def session( config: Optional[str] = None, + agent_load_file: Optional[str] = None, ) -> None: """ Run a PrimAITE session. @@ -132,4 +133,4 @@ def session( if not config: config = example_config_path() print(config) - run(config_path=config) + run(config_path=config, agent_load_path=agent_load_file) diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 88c1e061..f265b7d9 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -1,6 +1,7 @@ """PrimAITE session - the main entry point to training agents on PrimAITE.""" from enum import Enum from ipaddress import IPv4Address +from pathlib import Path from typing import Any, Dict, List, Literal, Optional, SupportsFloat, Tuple import enlighten @@ -297,7 +298,7 @@ class PrimaiteSession: return NotImplemented @classmethod - def from_config(cls, cfg: dict) -> "PrimaiteSession": + def from_config(cls, cfg: dict, agent_load_path: Optional[str] = None) -> "PrimaiteSession": """Create a PrimaiteSession object from a config dictionary. The config dictionary should have the following top-level keys: @@ -516,6 +517,8 @@ class PrimaiteSession: # CREATE POLICY sess.policy = PolicyABC.from_config(sess.training_options, session=sess) + if agent_load_path: + sess.policy.load(Path(agent_load_path)) # READ IO SETTINGS io_settings = cfg.get("io_settings", {}) diff --git a/src/primaite/main.py b/src/primaite/main.py index 831419d4..1699fe51 100644 --- a/src/primaite/main.py +++ b/src/primaite/main.py @@ -15,6 +15,7 @@ _LOGGER = getLogger(__name__) def run( config_path: Optional[Union[str, Path]] = "", + agent_load_path: Optional[Union[str, Path]] = None, ) -> None: """ Run the PrimAITE Session. @@ -31,7 +32,7 @@ def run( otherwise False. """ cfg = load(config_path) - sess = PrimaiteSession.from_config(cfg=cfg) + sess = PrimaiteSession.from_config(cfg=cfg, agent_load_path=agent_load_path) sess.start_session() From ba580b00b41324343c31e1ccc4f4767ffc8c26a2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 16 Nov 2023 16:14:50 +0000 Subject: [PATCH 308/980] Improve config validation and fix tests --- src/primaite/game/io.py | 6 +++++- src/primaite/game/session.py | 8 ++++++-- tests/assets/configs/test_primaite_session.yaml | 4 ++++ .../e2e_integration_tests/test_primaite_session.py | 13 ++++++++++++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/primaite/game/io.py b/src/primaite/game/io.py index e613316d..d510d108 100644 --- a/src/primaite/game/io.py +++ b/src/primaite/game/io.py @@ -2,7 +2,7 @@ from datetime import datetime from pathlib import Path from typing import Optional -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict from primaite import PRIMAITE_PATHS @@ -10,6 +10,8 @@ from primaite import PRIMAITE_PATHS class SessionIOSettings(BaseModel): """Schema for session IO settings.""" + model_config = ConfigDict(extra="forbid") + save_final_model: bool = True """Whether to save the final model right at the end of training.""" save_checkpoints: bool = False @@ -34,6 +36,8 @@ class SessionIO: def __init__(self, settings: SessionIOSettings = SessionIOSettings()) -> None: self.settings: SessionIOSettings = settings self.session_path: Path = self.generate_session_path() + # warning TODO: must be careful not to re-initialise sessionIO because it will create a new path each time it's + # possible refactor needed def generate_session_path(self, timestamp: Optional[datetime] = None) -> Path: """Create a folder for the session and return the path to it.""" diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index f265b7d9..655e2459 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -7,7 +7,7 @@ from typing import Any, Dict, List, Literal, Optional, SupportsFloat, Tuple import enlighten import gymnasium from gymnasium.core import ActType, ObsType -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict from primaite import getLogger from primaite.game.agent.actions import ActionManager @@ -104,6 +104,8 @@ class PrimaiteSessionOptions(BaseModel): Currently this is used to restrict which ports and protocols exist in the world of the simulation. """ + model_config = ConfigDict(extra="forbid") + ports: List[str] protocols: List[str] @@ -111,6 +113,8 @@ class PrimaiteSessionOptions(BaseModel): class TrainingOptions(BaseModel): """Options for training the RL agent.""" + model_config = ConfigDict(extra="forbid") + rl_framework: Literal["SB3", "RLLIB"] rl_algorithm: Literal["PPO", "A2C"] n_learn_episodes: int @@ -522,6 +526,6 @@ class PrimaiteSession: # READ IO SETTINGS io_settings = cfg.get("io_settings", {}) - sess.io_manager = SessionIO(settings=SessionIOSettings(**io_settings)) + sess.io_manager.settings = SessionIOSettings(**io_settings) return sess diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 201528eb..9445cd2b 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -10,6 +10,10 @@ training_config: agent_references: - defender +io_settings: + save_checkpoints: true + checkpoint_interval: 5 + game_config: ports: diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index 5e1da4ff..3ef5b6da 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -32,7 +32,18 @@ class TestPrimaiteSession: with temp_primaite_session as session: session: TempPrimaiteSession session.start_session() - # TODO: check that env was closed, that the model was saved, etc. + + session_path = session.io_manager.session_path + assert session_path.exists() + print(list(session_path.glob("*"))) + checkpoint_dir = session_path / "checkpoints" / "sb3_final" + assert checkpoint_dir.exists() + checkpoint_1 = checkpoint_dir / "sb3_model_640_steps.zip" + checkpoint_2 = checkpoint_dir / "sb3_model_1280_steps.zip" + checkpoint_3 = checkpoint_dir / "sb3_model_1920_steps.zip" + assert checkpoint_1.exists() + assert checkpoint_2.exists() + assert not checkpoint_3.exists() @pytest.mark.parametrize("temp_primaite_session", [[TRAINING_ONLY_PATH]], indirect=True) def test_training_only_session(self, temp_primaite_session): From 5bda952ead90e566593681eefdfa9d223c84af3a Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 17 Nov 2023 10:20:26 +0000 Subject: [PATCH 309/980] Fix sim output --- src/primaite/game/io.py | 5 ++++ src/primaite/game/session.py | 9 +++--- src/primaite/simulator/__init__.py | 30 +++++++++++++------ .../simulator/network/hardware/base.py | 2 +- .../simulator/system/core/packet_capture.py | 2 +- src/primaite/simulator/system/core/sys_log.py | 3 +- 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/primaite/game/io.py b/src/primaite/game/io.py index d510d108..e0b849c9 100644 --- a/src/primaite/game/io.py +++ b/src/primaite/game/io.py @@ -5,6 +5,7 @@ from typing import Optional from pydantic import BaseModel, ConfigDict from primaite import PRIMAITE_PATHS +from primaite.simulator import SIM_OUTPUT class SessionIOSettings(BaseModel): @@ -36,6 +37,10 @@ class SessionIO: def __init__(self, settings: SessionIOSettings = SessionIOSettings()) -> None: self.settings: SessionIOSettings = settings self.session_path: Path = self.generate_session_path() + + # set global SIM_OUTPUT path + SIM_OUTPUT.path = self.session_path / "simulation_output" + # warning TODO: must be careful not to re-initialise sessionIO because it will create a new path each time it's # possible refactor needed diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 655e2459..a2c04980 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -324,6 +324,11 @@ class PrimaiteSession: protocols=cfg["game_config"]["protocols"], ) sess.training_options = TrainingOptions(**cfg["training_config"]) + + # READ IO SETTINGS (this sets the global session path as well) # TODO: GLOBAL SIDE EFFECTS... + io_settings = cfg.get("io_settings", {}) + sess.io_manager.settings = SessionIOSettings(**io_settings) + sim = sess.simulation net = sim.network @@ -524,8 +529,4 @@ class PrimaiteSession: if agent_load_path: sess.policy.load(Path(agent_load_path)) - # READ IO SETTINGS - io_settings = cfg.get("io_settings", {}) - sess.io_manager.settings = SessionIOSettings(**io_settings) - return sess diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index 8c55542f..19c86e28 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -1,14 +1,26 @@ +"""Warning: SIM_OUTPUT is a mutable global variable for the simulation output directory.""" from datetime import datetime +from pathlib import Path from primaite import _PRIMAITE_ROOT -SIM_OUTPUT = None -"A path at the repo root dir to use temporarily for sim output testing while in dev." -# TODO: Remove once we integrate the simulation into PrimAITE and it uses the primaite session path +__all__ = ["SIM_OUTPUT"] -if not SIM_OUTPUT: - session_timestamp = datetime.now() - date_dir = session_timestamp.strftime("%Y-%m-%d") - sim_path = session_timestamp.strftime("%Y-%m-%d_%H-%M-%S") - SIM_OUTPUT = _PRIMAITE_ROOT.parent.parent / "simulation_output" / date_dir / sim_path - SIM_OUTPUT.mkdir(exist_ok=True, parents=True) + +class __SimOutput: + def __init__(self): + self._path: Path = ( + _PRIMAITE_ROOT.parent.parent / "simulation_output" / datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + ) + + @property + def path(self) -> Path: + return self._path + + @path.setter + def path(self, new_path: Path) -> None: + self._path = new_path + self._path.mkdir(exist_ok=True, parents=True) + + +SIM_OUTPUT = __SimOutput() diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 537cebb2..29d3a05c 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -957,7 +957,7 @@ class Node(SimComponent): if not kwargs.get("session_manager"): kwargs["session_manager"] = SessionManager(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp")) if not kwargs.get("root"): - kwargs["root"] = SIM_OUTPUT / kwargs["hostname"] + kwargs["root"] = SIM_OUTPUT.path / kwargs["hostname"] if not kwargs.get("file_system"): kwargs["file_system"] = FileSystem(sys_log=kwargs["sys_log"], sim_root=kwargs["root"] / "fs") if not kwargs.get("software_manager"): diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index 2e5ed008..c2faeb10 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -75,7 +75,7 @@ class PacketCapture: def _get_log_path(self) -> Path: """Get the path for the log file.""" - root = SIM_OUTPUT / self.hostname + root = SIM_OUTPUT.path / self.hostname root.mkdir(exist_ok=True, parents=True) return root / f"{self._logger_name}.log" diff --git a/src/primaite/simulator/system/core/sys_log.py b/src/primaite/simulator/system/core/sys_log.py index 791e0be8..7ac6df85 100644 --- a/src/primaite/simulator/system/core/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -41,7 +41,6 @@ class SysLog: JSON-like messages. """ log_path = self._get_log_path() - file_handler = logging.FileHandler(filename=log_path) file_handler.setLevel(logging.DEBUG) @@ -81,7 +80,7 @@ class SysLog: :return: Path object representing the location of the log file. """ - root = SIM_OUTPUT / self.hostname + root = SIM_OUTPUT.path / self.hostname root.mkdir(exist_ok=True, parents=True) return root / f"{self.hostname}_sys.log" From 6e5e1e6456a11124c147e1ad75297a3db16676ab Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 17 Nov 2023 11:38:29 +0000 Subject: [PATCH 310/980] Begin rllib --- pyproject.toml | 3 ++- src/primaite/game/policy/rllib.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/primaite/game/policy/rllib.py diff --git a/pyproject.toml b/pyproject.toml index 1e074c25..2f8cb803 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,8 @@ dependencies = [ "tensorflow==2.12.0", "typer[all]==0.9.0", "pydantic==2.1.1", - "enlighten==1.12.2" + "enlighten==1.12.2", + "ray[rllib] == 2.8.0, < 3" ] [tool.setuptools.dynamic] diff --git a/src/primaite/game/policy/rllib.py b/src/primaite/game/policy/rllib.py new file mode 100644 index 00000000..721a7500 --- /dev/null +++ b/src/primaite/game/policy/rllib.py @@ -0,0 +1,18 @@ + + +from typing import Literal, Optional, Type, TYPE_CHECKING, Union + +from primaite.game.policy import PolicyABC + +if TYPE_CHECKING: + from primaite.game.session import PrimaiteSession, TrainingOptions + +from ray.rllib + + +class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): + """Single agent RL policy using Ray RLLib.""" + + def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): + super().__init__(session=session) + From c5b4ae45be8c13162f98113dc52553d40cfb4668 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 17 Nov 2023 11:40:36 +0000 Subject: [PATCH 311/980] Remove problematic progress bars --- pyproject.toml | 1 - src/primaite/game/session.py | 18 ------------------ 2 files changed, 19 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1e074c25..92f78ec0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,6 @@ dependencies = [ "tensorflow==2.12.0", "typer[all]==0.9.0", "pydantic==2.1.1", - "enlighten==1.12.2" ] [tool.setuptools.dynamic] diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index a2c04980..ad0537e8 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -4,7 +4,6 @@ from ipaddress import IPv4Address from pathlib import Path from typing import Any, Dict, List, Literal, Optional, SupportsFloat, Tuple -import enlighten import gymnasium from gymnasium.core import ActType, ObsType from pydantic import BaseModel, ConfigDict @@ -34,8 +33,6 @@ from primaite.simulator.system.services.red_services.data_manipulation_bot impor from primaite.simulator.system.services.service import Service from primaite.simulator.system.services.web_server.web_server import WebServer -progress_bar_manager = enlighten.get_manager() - _LOGGER = getLogger(__name__) @@ -179,12 +176,6 @@ class PrimaiteSession: self.env: PrimaiteGymEnv """The environment that the agent can consume. Could be PrimaiteEnv.""" - self.training_progress_bar: Optional[enlighten.Counter] = None - """training steps counter""" - - self.eval_progress_bar: Optional[enlighten.Counter] = None - """evaluation episodes counter""" - self.mode: SessionMode = SessionMode.MANUAL """Current session mode.""" @@ -197,9 +188,6 @@ class PrimaiteSession: n_learn_episodes = self.training_options.n_learn_episodes n_eval_episodes = self.training_options.n_eval_episodes max_steps_per_episode = self.training_options.max_steps_per_episode - self.training_progress_bar = progress_bar_manager.counter( - total=n_learn_episodes * max_steps_per_episode, desc="Training steps" - ) deterministic_eval = self.training_options.deterministic_eval self.policy.learn( @@ -210,7 +198,6 @@ class PrimaiteSession: self.mode = SessionMode.EVAL if n_eval_episodes > 0: - self.eval_progress_bar = progress_bar_manager.counter(total=n_eval_episodes, desc="Evaluation episodes") self.policy.eval(n_episodes=n_eval_episodes, deterministic=deterministic_eval) self.mode = SessionMode.MANUAL @@ -277,9 +264,6 @@ class PrimaiteSession: _LOGGER.debug(f"Advancing timestep to {self.step_counter} ") self.simulation.apply_timestep(self.step_counter) - if self.training_progress_bar and self.mode == SessionMode.TRAIN: - self.training_progress_bar.update() - def calculate_truncated(self) -> bool: """Calculate whether the episode is truncated.""" current_step = self.step_counter @@ -294,8 +278,6 @@ class PrimaiteSession: self.step_counter = 0 _LOGGER.debug(f"Restting primaite session, episode = {self.episode_counter}") self.simulation.reset_component_for_episode(self.episode_counter) - if self.eval_progress_bar and self.mode == SessionMode.EVAL: - self.eval_progress_bar.update() def close(self) -> None: """Close the session, this will stop the env and close the simulation.""" From 227e73602f8468523da60e8fe983622959d9ae92 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Fri, 17 Nov 2023 11:51:19 +0000 Subject: [PATCH 312/980] Pass execution definition from config to agent --- src/primaite/game/agent/interface.py | 37 ++++++++++++++++++- src/primaite/game/session.py | 2 +- .../red_services/data_manipulation_bot.py | 10 +++-- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index d04b298e..c591c554 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -1,6 +1,6 @@ """Interface for agents.""" from abc import ABC, abstractmethod -from typing import Dict, List, Optional, Tuple, TypeAlias, Union +from typing import Dict, List, Optional, Tuple, TYPE_CHECKING, TypeAlias, Union import numpy as np from pydantic import BaseModel @@ -8,13 +8,21 @@ from pydantic import BaseModel from primaite.game.agent.actions import ActionManager from primaite.game.agent.observations import ObservationSpace from primaite.game.agent.rewards import RewardFunction +from primaite.simulator.network.hardware.base import Node + +if TYPE_CHECKING: + from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot ObsType: TypeAlias = Union[Dict, np.ndarray] class AgentExecutionDefinition(BaseModel): + """Additional configuration for agents.""" + port_scan_p_of_success: float = 0.1 + "The probability of a port scan succeeding." data_manipulation_p_of_success: float = 0.1 + "The probability of data manipulation succeeding." class AbstractAgent(ABC): @@ -26,7 +34,7 @@ class AbstractAgent(ABC): action_space: Optional[ActionManager], observation_space: Optional[ObservationSpace], reward_function: Optional[RewardFunction], - execution_definition: Optional[AgentExecutionDefinition] + execution_definition: Optional[AgentExecutionDefinition], ) -> None: """ Initialize an agent. @@ -116,13 +124,38 @@ class RandomAgent(AbstractScriptedAgent): """ return self.action_space.get_action(self.action_space.space.sample()) + class DataManipulationAgent(AbstractScriptedAgent): + """Agent that uses a DataManipulationBot to perform an SQL injection attack.""" + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + # get node ids that are part of the agent's observation space + node_ids: List[str] = [n.where[-1] for n in self.observation_space.obs.nodes] + # get all nodes from their ids + nodes: List[Node] = [n for n_id, n in self.action_space.sim.network.nodes.items() if n_id in node_ids] + + # get execution definition for data manipulation bots + for node in nodes: + bot_sw: Optional["DataManipulationBot"] = node.software_manager.software.get("DataManipulationBot") + + if bot_sw is not None: + bot_sw.execution_definition = self.execution_definition + def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: + """Randomly sample an action from the action space. + + :param obs: _description_ + :type obs: ObsType + :param reward: _description_, defaults to None + :type reward: float, optional + :return: _description_ + :rtype: Tuple[str, Dict] + """ return self.action_space.get_action(self.action_space.space.sample()) + class AbstractGATEAgent(AbstractAgent): """Base class for actors controlled via external messages, such as RL policies.""" diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 082ed281..5f3fb7b9 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -10,7 +10,7 @@ from pydantic import BaseModel from primaite import getLogger from primaite.game.agent.actions import ActionManager -from primaite.game.agent.interface import AbstractAgent, RandomAgent, DataManipulationAgent, AgentExecutionDefinition +from primaite.game.agent.interface import AbstractAgent, AgentExecutionDefinition, DataManipulationAgent, RandomAgent from primaite.game.agent.observations import ObservationSpace from primaite.game.agent.rewards import RewardFunction from primaite.simulator.network.hardware.base import Link, NIC, Node diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index aec7bbd8..35ea413a 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -2,6 +2,7 @@ from enum import IntEnum from ipaddress import IPv4Address from typing import Optional +from primaite.game.agent.interface import AgentExecutionDefinition from primaite.game.science import simulate_trial from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.database_client import DatabaseClient @@ -14,6 +15,7 @@ class DataManipulationAttackStage(IntEnum): This enumeration defines the various stages a data manipulation attack can be in during its lifecycle in the simulation. Each stage represents a specific phase in the attack process. """ + NOT_STARTED = 0 "Indicates that the attack has not started yet." LOGON = 1 @@ -30,17 +32,19 @@ class DataManipulationAttackStage(IntEnum): class DataManipulationBot(DatabaseClient): """A bot that simulates a script which performs a SQL injection attack.""" + server_ip_address: Optional[IPv4Address] = None payload: Optional[str] = None server_password: Optional[str] = None attack_stage: DataManipulationAttackStage = DataManipulationAttackStage.NOT_STARTED + execution_definition: AgentExecutionDefinition = AgentExecutionDefinition() def __init__(self, **kwargs): super().__init__(**kwargs) self.name = "DataManipulationBot" def configure( - self, server_ip_address: IPv4Address, server_password: Optional[str] = None, payload: Optional[str] = None + self, server_ip_address: IPv4Address, server_password: Optional[str] = None, payload: Optional[str] = None ): """ Configure the DataManipulatorBot to communicate with a DatabaseService. @@ -96,7 +100,6 @@ class DataManipulationBot(DatabaseClient): if self.attack_stage == DataManipulationAttackStage.PORT_SCAN: # perform the actual data manipulation attack if simulate_trial(p_of_success): - self.sys_log.info(f"{self.name}: Performing port scan") # perform the attack if not self.connected: @@ -114,7 +117,7 @@ class DataManipulationBot(DatabaseClient): def execute(self): """ - Execute the Data Manipulation Bot + Execute the Data Manipulation Bot. Calls the parent classes execute method before starting the application loop. """ @@ -127,7 +130,6 @@ class DataManipulationBot(DatabaseClient): This is the core loop where the bot sequentially goes through the stages of the attack. """ - if self.operating_state != ApplicationOperatingState.RUNNING: return if self.server_ip_address and self.payload and self.operating_state: From 622c6931d8df352f7fd96b0a1ea58ec3323db98e Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 17 Nov 2023 12:07:46 +0000 Subject: [PATCH 313/980] #2041: Create test network + extra test --- .../system/test_ntp_client_server.py | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index 5d301d2b..61c8740b 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -1,3 +1,8 @@ +from ipaddress import IPv4Address + +import pytest + +from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.ntp import NTPPacket @@ -5,10 +10,41 @@ from primaite.simulator.system.services.ntp.ntp_client import NTPClient from primaite.simulator.system.services.ntp.ntp_server import NTPServer from primaite.simulator.system.services.service import ServiceOperatingState +# Create simple network for testing + + +def create_ntp_network() -> Network: + """ + +------------+ +------------+ + | ntp | | ntp | + | client_1 +------------+ server_1 | + | | | | + +------------+ +------------+ + + """ + + network = Network() + ntp_server = Server( + hostname="ntp_server", ip_address="192.168.1.2", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + ) + ntp_server.power_on() + + ntp_client = Computer( + hostname="ntp_client", ip_address="192.168.1.3", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + ) + ntp_client.power_on() + network.connect(endpoint_b=ntp_server.ethernet_port[1], endpoint_a=ntp_client.ethernet_port[1]) + + +# @pytest.fixture() +# def create_network(): +# return create_ntp_network() + # Define one node to be an NTP server and another node to be a NTP Client. -def test_ntp_client_server(network): +def test_ntp_client_server(): + network = create_ntp_network() server: Server = network.get_node_by_hostname("ntp_server") client: Computer = network.get_node_by_hostname("ntp_client") @@ -23,3 +59,24 @@ def test_ntp_client_server(network): assert ntp_client.receive() is True assert ntp_client.apply_timestep(1) is True + + +# Test ntp client behaviour when ntp server is unavailable. +def test_ntp_server_failure(): + network = create_ntp_network() + server: Server = network.get_node_by_hostname("ntp_server") + client: Computer = network.get_node_by_hostname("ntp_client") + + ntp_server: NTPServer = server.software_manager.software["NTP_Server"] + ntp_client: NTPClient = client.software_manager.software["NTP_Client"] + + assert ntp_client.operating_state == ServiceOperatingState.RUNNING + + # Turn off ntp server. + ntp_server.stop() + assert ntp_server.operating_state == ServiceOperatingState.STOPPED + assert ntp_client.receive() is False + + # Restart ntp server. + ntp_server.start() + assert ntp_server.operating_state == ServiceOperatingState.RUNNING From 6081f02caa68982a0c19dbee235ff91bfcea5ff6 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 17 Nov 2023 12:41:53 +0000 Subject: [PATCH 314/980] #2041: Add missing return statement --- tests/integration_tests/system/test_ntp_client_server.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index 61c8740b..0e3567ae 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -35,6 +35,8 @@ def create_ntp_network() -> Network: ntp_client.power_on() network.connect(endpoint_b=ntp_server.ethernet_port[1], endpoint_a=ntp_client.ethernet_port[1]) + return network + # @pytest.fixture() # def create_network(): From dbecc681dc47f916f5c181fa72d1b95e5852b2cc Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 17 Nov 2023 12:59:06 +0000 Subject: [PATCH 315/980] #2041: Install NTPServer and NTPClient. --- tests/integration_tests/system/test_ntp_client_server.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index 0e3567ae..dc487164 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -28,11 +28,13 @@ def create_ntp_network() -> Network: hostname="ntp_server", ip_address="192.168.1.2", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" ) ntp_server.power_on() + ntp_server.software_manager.install(NTPServer) ntp_client = Computer( hostname="ntp_client", ip_address="192.168.1.3", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" ) ntp_client.power_on() + ntp_client.software_manager.install(NTPClient) network.connect(endpoint_b=ntp_server.ethernet_port[1], endpoint_a=ntp_client.ethernet_port[1]) return network From d28bd0d1c36217489c75d0663d3c3c0091776bcd Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 17 Nov 2023 14:19:36 +0000 Subject: [PATCH 316/980] #2041: Fix names --- tests/integration_tests/system/test_ntp_client_server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index dc487164..e859faf4 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -52,8 +52,8 @@ def test_ntp_client_server(): server: Server = network.get_node_by_hostname("ntp_server") client: Computer = network.get_node_by_hostname("ntp_client") - ntp_server: NTPServer = server.software_manager.software["NTP_Server"] - ntp_client: NTPClient = client.software_manager.software["NTP_Client"] + ntp_server: NTPServer = server.software_manager.software["NTPServer"] + ntp_client: NTPClient = client.software_manager.software["NTPClient"] assert ntp_server.operating_state == ServiceOperatingState.RUNNING assert ntp_client.operating_state == ServiceOperatingState.RUNNING From 3fb7bce3ce547a1d139f297ef5e4a20f8d028d00 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 17 Nov 2023 17:57:57 +0000 Subject: [PATCH 317/980] Get RLLib to stop crashing. --- .../config/_package_data/example_config.yaml | 2 +- src/primaite/game/environment.py | 67 +++++++++++++++ src/primaite/game/policy/__init__.py | 3 +- src/primaite/game/policy/rllib.py | 81 ++++++++++++++++++- src/primaite/game/session.py | 62 +------------- 5 files changed, 149 insertions(+), 66 deletions(-) create mode 100644 src/primaite/game/environment.py diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index e0ff9276..c581ae49 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -1,5 +1,5 @@ training_config: - rl_framework: SB3 + rl_framework: RLLIB_single_agent rl_algorithm: PPO seed: 333 n_learn_episodes: 25 diff --git a/src/primaite/game/environment.py b/src/primaite/game/environment.py new file mode 100644 index 00000000..b88a8202 --- /dev/null +++ b/src/primaite/game/environment.py @@ -0,0 +1,67 @@ +from typing import Any, Dict, List, Optional, SupportsFloat, Tuple, TYPE_CHECKING + +import gymnasium +from gymnasium.core import ActType, ObsType + +from primaite.game.agent.interface import ProxyAgent + +if TYPE_CHECKING: + from primaite.game.session import PrimaiteSession + + +class PrimaiteGymEnv(gymnasium.Env): + """ + Thin wrapper env to provide agents with a gymnasium API. + + This is always a single agent environment since gymnasium is a single agent API. Therefore, we can make some + assumptions about the agent list always having a list of length 1. + """ + + def __init__(self, session: "PrimaiteSession", agents: List[ProxyAgent]): + """Initialise the environment.""" + super().__init__() + self.session: "PrimaiteSession" = session + self.agent: ProxyAgent = agents[0] + + def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: + """Perform a step in the environment.""" + # make ProxyAgent store the action chosen my the RL policy + self.agent.store_action(action) + # apply_agent_actions accesses the action we just stored + self.session.apply_agent_actions() + self.session.advance_timestep() + state = self.session.get_sim_state() + self.session.update_agents(state) + + next_obs = self._get_obs() + reward = self.agent.reward_function.current_reward + terminated = False + truncated = self.session.calculate_truncated() + info = {} + + return next_obs, reward, terminated, truncated, info + + def reset(self, seed: Optional[int] = None) -> Tuple[ObsType, Dict[str, Any]]: + """Reset the environment.""" + self.session.reset() + state = self.session.get_sim_state() + self.session.update_agents(state) + next_obs = self._get_obs() + info = {} + return next_obs, info + + @property + def action_space(self) -> gymnasium.Space: + """Return the action space of the environment.""" + return self.agent.action_manager.space + + @property + def observation_space(self) -> gymnasium.Space: + """Return the observation space of the environment.""" + return gymnasium.spaces.flatten_space(self.agent.observation_manager.space) + + def _get_obs(self) -> ObsType: + """Return the current observation.""" + unflat_space = self.agent.observation_manager.space + unflat_obs = self.agent.observation_manager.current_observation + return gymnasium.spaces.flatten(unflat_space, unflat_obs) diff --git a/src/primaite/game/policy/__init__.py b/src/primaite/game/policy/__init__.py index 29196112..9c0e4199 100644 --- a/src/primaite/game/policy/__init__.py +++ b/src/primaite/game/policy/__init__.py @@ -1,3 +1,4 @@ +from primaite.game.policy.rllib import RaySingleAgentPolicy from primaite.game.policy.sb3 import SB3Policy -__all__ = ["SB3Policy"] +__all__ = ["SB3Policy", "RaySingleAgentPolicy"] diff --git a/src/primaite/game/policy/rllib.py b/src/primaite/game/policy/rllib.py index 721a7500..6e9e1096 100644 --- a/src/primaite/game/policy/rllib.py +++ b/src/primaite/game/policy/rllib.py @@ -1,13 +1,20 @@ +from pathlib import Path +from typing import Dict, List, Literal, Optional, SupportsFloat, Tuple, Type, TYPE_CHECKING, Union +import gymnasium +from gymnasium.core import ActType, ObsType -from typing import Literal, Optional, Type, TYPE_CHECKING, Union - -from primaite.game.policy import PolicyABC +from primaite.game.environment import PrimaiteGymEnv +from primaite.game.policy.policy import PolicyABC if TYPE_CHECKING: + from primaite.game.agent.interface import ProxyAgent from primaite.game.session import PrimaiteSession, TrainingOptions -from ray.rllib +import ray +from ray.rllib.algorithms import Algorithm, ppo +from ray.rllib.algorithms.ppo import PPOConfig +from ray.tune.registry import register_env class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): @@ -15,4 +22,70 @@ class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): super().__init__(session=session) + ray.init() + class RayPrimaiteGym(gymnasium.Env): + def __init__(self, env_config: Dict) -> None: + self.action_space = session.env.action_space + self.observation_space = session.env.observation_space + + def reset(self, *, seed: int = None, options: dict = None) -> Tuple[ObsType, Dict]: + obs, info = session.env.reset() + return obs, info + + def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict]: + obs, reward, terminated, truncated, info = session.env.step(action) + return obs, reward, terminated, truncated, info + + ray.shutdown() + ray.init() + + config = { + "env": RayPrimaiteGym, + "env_config": {}, + "disable_env_checking": True, + "num_rollout_workers": 0, + } + + self._algo = ppo.PPO(config=config) + + # self._agent_config = (PPOConfig() + # .update_from_dict({ + # "num_gpus":0, + # "num_workers":0, + # "batch_mode":"complete_episodes", + # "framework":"torch", + # }) + # .environment( + # env="primaite", + # env_config={"session": session, "agents": session.rl_agents,}, + # # disable_env_checking=True + # ) + # # .rollouts(num_rollout_workers=0, + # # num_envs_per_worker=0) + # # .framework("tf2") + # .evaluation(evaluation_num_workers=0) + # ) + + # self._agent:Algorithm = self._agent_config.build(use_copy=False) + + def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: + """Train the agent.""" + + for ep in range(n_episodes): + res = self._algo.train() + print(f"Episode {ep} complete, reward: {res['episode_reward_mean']}") + + def eval(self, n_episodes: int, deterministic: bool) -> None: + raise NotImplementedError + + def save(self, save_path: Path) -> None: + raise NotImplementedError + + def load(self, model_path: Path) -> None: + raise NotImplementedError + + @classmethod + def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "RaySingleAgentPolicy": + """Create a policy from a config.""" + return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index a2c04980..aae26fab 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -5,7 +5,6 @@ from pathlib import Path from typing import Any, Dict, List, Literal, Optional, SupportsFloat, Tuple import enlighten -import gymnasium from gymnasium.core import ActType, ObsType from pydantic import BaseModel, ConfigDict @@ -14,6 +13,7 @@ from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractAgent, ProxyAgent, RandomAgent from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction +from primaite.game.environment import PrimaiteGymEnv from primaite.game.io import SessionIO, SessionIOSettings from primaite.game.policy.policy import PolicyABC from primaite.simulator.network.hardware.base import Link, NIC, Node @@ -39,64 +39,6 @@ progress_bar_manager = enlighten.get_manager() _LOGGER = getLogger(__name__) -class PrimaiteGymEnv(gymnasium.Env): - """ - Thin wrapper env to provide agents with a gymnasium API. - - This is always a single agent environment since gymnasium is a single agent API. Therefore, we can make some - assumptions about the agent list always having a list of length 1. - """ - - def __init__(self, session: "PrimaiteSession", agents: List[ProxyAgent]): - """Initialise the environment.""" - super().__init__() - self.session: "PrimaiteSession" = session - self.agent: ProxyAgent = agents[0] - - def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: - """Perform a step in the environment.""" - # make ProxyAgent store the action chosen my the RL policy - self.agent.store_action(action) - # apply_agent_actions accesses the action we just stored - self.session.apply_agent_actions() - self.session.advance_timestep() - state = self.session.get_sim_state() - self.session.update_agents(state) - - next_obs = self._get_obs() - reward = self.agent.reward_function.current_reward - terminated = False - truncated = self.session.calculate_truncated() - info = {} - - return next_obs, reward, terminated, truncated, info - - def reset(self, seed: Optional[int] = None) -> Tuple[ObsType, Dict[str, Any]]: - """Reset the environment.""" - self.session.reset() - state = self.session.get_sim_state() - self.session.update_agents(state) - next_obs = self._get_obs() - info = {} - return next_obs, info - - @property - def action_space(self) -> gymnasium.Space: - """Return the action space of the environment.""" - return self.agent.action_manager.space - - @property - def observation_space(self) -> gymnasium.Space: - """Return the observation space of the environment.""" - return gymnasium.spaces.flatten_space(self.agent.observation_manager.space) - - def _get_obs(self) -> ObsType: - """Return the current observation.""" - unflat_space = self.agent.observation_manager.space - unflat_obs = self.agent.observation_manager.current_observation - return gymnasium.spaces.flatten(unflat_space, unflat_obs) - - class PrimaiteSessionOptions(BaseModel): """ Global options which are applicable to all of the agents in the game. @@ -115,7 +57,7 @@ class TrainingOptions(BaseModel): model_config = ConfigDict(extra="forbid") - rl_framework: Literal["SB3", "RLLIB"] + rl_framework: Literal["SB3", "RLLIB_single_agent"] rl_algorithm: Literal["PPO", "A2C"] n_learn_episodes: int n_eval_episodes: Optional[int] = None From 9d0a98b22122e8f8b4c000ad84d613acf45252f8 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 17 Nov 2023 20:30:07 +0000 Subject: [PATCH 318/980] Apply suggestions from code review --- src/primaite/game/policy/sb3.py | 4 ---- tests/assets/configs/bad_primaite_session.yaml | 2 +- tests/e2e_integration_tests/test_primaite_session.py | 6 ++++++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/game/policy/sb3.py index bb35775a..a4870054 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/game/policy/sb3.py @@ -74,10 +74,6 @@ class SB3Policy(PolicyABC, identifier="SB3"): """Load agent from a checkpoint.""" self._agent = self._agent_class.load(model_path, env=self.session.env) - def close(self) -> None: - """Close the agent.""" - pass - @classmethod def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "SB3Policy": """Create an agent from config file.""" diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 752d98a5..80567aea 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -1,7 +1,7 @@ training_config: rl_framework: SB3 rl_algorithm: PPO - se3ed: 333 + se3ed: 333 # Purposeful typo to check that error is raised with bad configuration. n_learn_steps: 2560 n_eval_episodes: 5 diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index 3ef5b6da..b6122bad 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -1,3 +1,4 @@ +import pydantic import pytest from tests.conftest import TempPrimaiteSession @@ -5,6 +6,7 @@ from tests.conftest import TempPrimaiteSession CFG_PATH = "tests/assets/configs/test_primaite_session.yaml" TRAINING_ONLY_PATH = "tests/assets/configs/train_only_primaite_session.yaml" EVAL_ONLY_PATH = "tests/assets/configs/eval_only_primaite_session.yaml" +MISCONFIGURED_PATH = "tests/assets/configs/bad_primaite_session.yaml" class TestPrimaiteSession: @@ -60,3 +62,7 @@ class TestPrimaiteSession: session: TempPrimaiteSession session.start_session() # TODO: include checks that the model was loaded and that the eval-only session ran + + def test_error_thrown_on_bad_configuration(self): + with pytest.raises(pydantic.ValidationError): + session = TempPrimaiteSession.from_config(MISCONFIGURED_PATH) From 77f3806ba733d7764dc71093e834069a93a357b5 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sat, 18 Nov 2023 03:40:08 +0000 Subject: [PATCH 319/980] Remove real database in favour of simulated --- .../system/data_manipulation_bot.rst | 2 +- .../config/_package_data/example_config.yaml | 2 +- src/primaite/simulator/network/networks.py | 2 +- .../system/applications/database_client.py | 22 +--- .../services/database/database_service.py | 115 ++++++------------ .../system/services/web_server/web_server.py | 2 +- .../test_uc2_data_manipulation_scenario.py | 6 +- .../system/test_database_on_node.py | 2 +- .../test_data_manipulation_bot.py | 2 +- 9 files changed, 53 insertions(+), 102 deletions(-) diff --git a/docs/source/simulation_components/system/data_manipulation_bot.rst b/docs/source/simulation_components/system/data_manipulation_bot.rst index c9f8977a..489f8ae5 100644 --- a/docs/source/simulation_components/system/data_manipulation_bot.rst +++ b/docs/source/simulation_components/system/data_manipulation_bot.rst @@ -41,7 +41,7 @@ Example network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) client_1.software_manager.install(DataManipulationBot) data_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] - data_manipulation_bot.configure(server_ip_address=IPv4Address("192.168.1.14"), payload="DROP TABLE IF EXISTS user;") + data_manipulation_bot.configure(server_ip_address=IPv4Address("192.168.1.14"), payload="DELETE") data_manipulation_bot.run() This would connect to the database service at 192.168.1.14, authenticate, and execute the SQL statement to drop the 'users' table. diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index ee42cf4f..ddf9d923 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -81,7 +81,7 @@ game_config: # options: # execution_definition: # server_ip: 192.168.1.14 - # payload: "DROP TABLE IF EXISTS user;" + # payload: "DELETE" # success_rate: 80% - type: NODE_FILE_DELETE - type: NODE_FILE_CORRUPT diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 25d1bd21..c0f9a07e 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -140,7 +140,7 @@ def arcd_uc2_network() -> Network: network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) client_1.software_manager.install(DataManipulationBot) db_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] - db_manipulation_bot.configure(server_ip_address=IPv4Address("192.168.1.14"), payload="DROP TABLE IF EXISTS user;") + db_manipulation_bot.configure(server_ip_address=IPv4Address("192.168.1.14"), payload="DELETE") # Client 2 client_2 = Computer( diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index d021cb78..37f89371 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -2,13 +2,14 @@ from ipaddress import IPv4Address from typing import Any, Dict, Optional from uuid import uuid4 -from prettytable import PrettyTable - +from primaite import getLogger from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application, ApplicationOperatingState from primaite.simulator.system.core.software_manager import SoftwareManager +_LOGGER = getLogger(__name__) + class DatabaseClient(Application): """ @@ -148,21 +149,6 @@ class DatabaseClient(Application): self._query_success_tracker[query_id] = False return self._query(sql=sql, query_id=query_id) - def _print_data(self, data: Dict): - """ - Display the contents of the Folder in tabular format. - - :param markdown: Whether to display the table in Markdown format or not. Default is `False`. - """ - if data: - table = PrettyTable(list(data.values())[0]) - - table.align = "l" - table.title = f"{self.sys_log.hostname} Database Client" - for row in data.values(): - table.add_row(row.values()) - print(table) - def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ Receive a payload from the Software Manager. @@ -179,5 +165,5 @@ class DatabaseClient(Application): status_code = payload.get("status_code") self._query_success_tracker[query_id] = status_code == 200 if self._query_success_tracker[query_id]: - self._print_data(payload["data"]) + _LOGGER.debug(f"Received payload {payload}") return True diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index b04174bf..d7277e1e 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -1,10 +1,6 @@ -import sqlite3 from datetime import datetime from ipaddress import IPv4Address -from sqlite3 import OperationalError -from typing import Any, Dict, List, Optional, Union - -from prettytable import MARKDOWN, PrettyTable +from typing import Any, Dict, List, Literal, Optional, Union from primaite.simulator.file_system.file_system import File from primaite.simulator.network.transmission.network_layer import IPProtocol @@ -19,7 +15,7 @@ class DatabaseService(Service): """ A class for simulating a generic SQL Server service. - This class inherits from the `Service` class and provides methods to manage and query a SQLite database. + This class inherits from the `Service` class and provides methods to simulate a SQL database. """ password: Optional[str] = None @@ -41,38 +37,6 @@ class DatabaseService(Service): super().__init__(**kwargs) self._db_file: File self._create_db_file() - self._connect() - - def _connect(self): - self._conn = sqlite3.connect(self._db_file.sim_path) - self._cursor = self._conn.cursor() - - def tables(self) -> List[str]: - """ - Get a list of table names present in the database. - - :return: List of table names. - """ - sql = "SELECT name FROM sqlite_master WHERE type='table' AND name != 'sqlite_sequence';" - results = self._process_sql(sql, None) - if isinstance(results["data"], dict): - return list(results["data"].keys()) - return [] - - def show(self, markdown: bool = False): - """ - Prints a list of table names in the database using PrettyTable. - - :param markdown: Whether to output the table in Markdown format. - """ - table = PrettyTable(["Table"]) - if markdown: - table.set_style(MARKDOWN) - table.align = "l" - table.title = f"{self.file_system.sys_log.hostname} Database" - for row in self.tables(): - table.add_row([row]) - print(table) def configure_backup(self, backup_server: IPv4Address): """ @@ -89,8 +53,6 @@ class DatabaseService(Service): self.sys_log.error(f"{self.name} - {self.sys_log.hostname}: not configured.") return False - self._conn.close() - software_manager: SoftwareManager = self.software_manager ftp_client_service: FTPClient = software_manager.software["FTPClient"] @@ -98,12 +60,10 @@ class DatabaseService(Service): response = ftp_client_service.send_file( dest_ip_address=self.backup_server, src_file_name=self._db_file.name, - src_folder_name=self._db_file.folder.name, + src_folder_name=self.folder.name, dest_folder_name=str(self.uuid), dest_file_name="database.db", - real_file_path=self._db_file.sim_path, ) - self._connect() if response: return True @@ -125,25 +85,29 @@ class DatabaseService(Service): dest_ip_address=self.backup_server, ) - if response: - self._conn.close() - # replace db file - self.file_system.delete_file(folder_name=self.folder.name, file_name="downloads.db") - self.file_system.copy_file( - src_folder_name="downloads", src_file_name="database.db", dst_folder_name=self.folder.name - ) - self._db_file = self.file_system.get_file(folder_name=self.folder.name, file_name="database.db") - self._connect() + if not response: + self.sys_log.error("Unable to restore database backup.") + return False - return self._db_file is not None + # replace db file + self.file_system.delete_file(folder_name=self.folder.name, file_name="downloads.db") + self.file_system.copy_file( + src_folder_name="downloads", src_file_name="database.db", dst_folder_name=self.folder.name + ) + self._db_file = self.file_system.get_file(folder_name=self.folder.name, file_name="database.db") - self.sys_log.error("Unable to restore database backup.") - return False + if self._db_file is None: + self.sys_log.error("Copying database backup failed.") + return False + + self.set_health_state(SoftwareHealthState.GOOD) + + return True def _create_db_file(self): """Creates the Simulation File and sqlite file in the file system.""" - self._db_file: File = self.file_system.create_file(folder_name="database", file_name="database.db", real=True) - self.folder = self._db_file.folder + self._db_file: File = self.file_system.create_file(folder_name="database", file_name="database.db") + self.folder = self.file_system.get_folder_by_id(self._db_file.folder_id) def _process_connect( self, session_id: str, password: Optional[str] = None @@ -163,31 +127,32 @@ class DatabaseService(Service): status_code = 404 # service not found return {"status_code": status_code, "type": "connect_response", "response": status_code == 200} - def _process_sql(self, query: str, query_id: str) -> Dict[str, Union[int, List[Any]]]: + def _process_sql(self, query: Literal["SELECT", "DELETE"], query_id: str) -> Dict[str, Union[int, List[Any]]]: """ Executes the given SQL query and returns the result. + Possible queries: + - SELECT : returns the data + - DELETE : deletes the data + :param query: The SQL query to be executed. :return: Dictionary containing status code and data fetched. """ self.sys_log.info(f"{self.name}: Running {query}") - try: - self._cursor.execute(query) - self._conn.commit() - except OperationalError: - # Handle the case where the table does not exist. - self.sys_log.error(f"{self.name}: Error, query failed") - return {"status_code": 404, "data": {}} - data = [] - description = self._cursor.description - if description: - headers = [] - for header in description: - headers.append(header[0]) - data = self._cursor.fetchall() - if data and headers: - data = {row[0]: {header: value for header, value in zip(headers, row)} for row in data} - return {"status_code": 200, "type": "sql", "data": data, "uuid": query_id} + if query == "SELECT": + if self.health_state_actual == SoftwareHealthState.GOOD: + return {"status_code": 200, "type": "sql", "data": True, "uuid": query_id} + else: + return {"status_code": 404, "data": False} + elif query == "DELETE": + if self.health_state_actual == SoftwareHealthState.GOOD: + self.health_state_actual = SoftwareHealthState.COMPROMISED + return {"status_code": 200, "type": "sql", "data": False, "uuid": query_id} + else: + return {"status_code": 404, "data": False} + else: + # Invalid query + return {"status_code": 500, "data": False} def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index 5957e4cb..cb1a4738 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -106,7 +106,7 @@ class WebServer(Service): # get data from DatabaseServer db_client: DatabaseClient = self.software_manager.software["DatabaseClient"] # get all users - if db_client.query("SELECT * FROM user;"): + if db_client.query("SELECT"): # query succeeded response.status_code = HttpStatusCode.OK diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index 13f4d1f3..81bbfc96 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -19,16 +19,16 @@ def test_data_manipulation(uc2_network): db_service.backup_database() # First check that the DB client on the web_server can successfully query the users table on the database - assert db_client.query("SELECT * FROM user;") + assert db_client.query("SELECT") # Now we run the DataManipulationBot db_manipulation_bot.run() # Now check that the DB client on the web_server cannot query the users table on the database - assert not db_client.query("SELECT * FROM user;") + assert not db_client.query("SELECT") # Now restore the database db_service.restore_backup() # Now check that the DB client on the web_server can successfully query the users table on the database - assert db_client.query("SELECT * FROM user;") + assert db_client.query("SELECT") diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 92056981..027fae4a 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -57,7 +57,7 @@ def test_database_client_query(uc2_network): db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] db_client.connect() - assert db_client.query("SELECT * FROM user;") + assert db_client.query("SELECT") def test_create_database_backup(uc2_network): diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py index dd785cc1..113ebeb4 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py @@ -17,4 +17,4 @@ def test_creation(): assert data_manipulation_bot.name == "DataManipulationBot" assert data_manipulation_bot.port == Port.POSTGRES_SERVER assert data_manipulation_bot.protocol == IPProtocol.TCP - assert data_manipulation_bot.payload == "DROP TABLE IF EXISTS user;" + assert data_manipulation_bot.payload == "DELETE" From fdb48c0ded89a832ab9373b802ac4a955ef0dbf4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sat, 18 Nov 2023 03:46:24 +0000 Subject: [PATCH 320/980] Update docs for Database --- .../system/database_client_server.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/source/simulation_components/system/database_client_server.rst b/docs/source/simulation_components/system/database_client_server.rst index 53687f60..4bef335b 100644 --- a/docs/source/simulation_components/system/database_client_server.rst +++ b/docs/source/simulation_components/system/database_client_server.rst @@ -14,10 +14,10 @@ The ``DatabaseService`` provides a SQL database server simulation by extending t Key capabilities ^^^^^^^^^^^^^^^^ -- Initialises a SQLite database file in the ``Node`` 's ``FileSystem`` upon creation. +- Creates a database file in the ``Node`` 's ``FileSystem`` upon creation. - Handles connecting clients by maintaining a dictionary of connections mapped to session IDs. - Authenticates connections using a configurable password. -- Executes SQL queries against the SQLite database. +- Simulates ``SELECT`` and ``DELETE`` SQL queries. - Returns query results and status codes back to clients. - Leverages the Service base class for install/uninstall, status tracking, etc. @@ -30,10 +30,9 @@ Usage Implementation ^^^^^^^^^^^^^^ -- Uses SQLite for persistent storage. - Creates the database file within the node's file system. - Manages client connections in a dictionary by session ID. -- Processes SQL queries via the SQLite cursor and connection. +- Processes SQL queries. - Returns results and status codes in a standard dictionary format. - Extends Service class for integration with ``SoftwareManager``. From 7e0e8a476817118005307fa129f025a00cad0360 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Mon, 20 Nov 2023 10:38:01 +0000 Subject: [PATCH 321/980] Pass agent settings from config to agent --- .../config/_package_data/example_config.yaml | 14 +++++++------ src/primaite/game/agent/interface.py | 21 +++++++++++++++++++ src/primaite/game/session.py | 12 ++++++++++- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index f034f9ea..700a45fd 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -50,9 +50,10 @@ game_config: - type: DUMMY agent_settings: - start_step: 5 - frequency: 4 - variance: 3 + start_settings: + start_step: 5 + frequency: 4 + variance: 3 - ref: client_1_data_manipulation_red_bot team: RED @@ -106,9 +107,10 @@ game_config: - type: DUMMY agent_settings: # options specific to this particular agent type, basically args of __init__(self) - start_step: 25 - frequency: 20 - variance: 5 + start_settings: + start_step: 25 + frequency: 20 + variance: 5 - ref: defender team: BLUE diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index c591c554..70eb1980 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -25,6 +25,24 @@ class AgentExecutionDefinition(BaseModel): "The probability of data manipulation succeeding." +class AgentStartSettings(BaseModel): + """Configuration values for when an agent starts performing actions.""" + + start_step: int = 5 + "The timestep at which an agent begins performing it's actions" + frequency: int = 5 + "The number of timesteps to wait between performing actions" + variance: int = 0 + "The amount the frequency can randomly change to" + + +class AgentSettings(BaseModel): + """Settings for configuring the operation of an agent.""" + + start_settings: Optional[AgentStartSettings] = None + "Configuration for when an agent begins performing it's actions" + + class AbstractAgent(ABC): """Base class for scripted and RL agents.""" @@ -35,6 +53,7 @@ class AbstractAgent(ABC): observation_space: Optional[ObservationSpace], reward_function: Optional[RewardFunction], execution_definition: Optional[AgentExecutionDefinition], + agent_settings: Optional[AgentSettings], ) -> None: """ Initialize an agent. @@ -57,6 +76,8 @@ class AbstractAgent(ABC): # by for example specifying target ip addresses, or converting a node ID into a uuid self.execution_definition = execution_definition or AgentExecutionDefinition() + self.agent_settings = agent_settings or AgentSettings() + def convert_state_to_obs(self, state: Dict) -> ObsType: """ Convert a state from the simulator into an observation for the agent using the observation space. diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 5f3fb7b9..9701fec9 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -10,7 +10,13 @@ from pydantic import BaseModel from primaite import getLogger from primaite.game.agent.actions import ActionManager -from primaite.game.agent.interface import AbstractAgent, AgentExecutionDefinition, DataManipulationAgent, RandomAgent +from primaite.game.agent.interface import ( + AbstractAgent, + AgentExecutionDefinition, + AgentSettings, + DataManipulationAgent, + RandomAgent, +) from primaite.game.agent.observations import ObservationSpace from primaite.game.agent.rewards import RewardFunction from primaite.simulator.network.hardware.base import Link, NIC, Node @@ -439,6 +445,7 @@ class PrimaiteSession: rew_function = RewardFunction.from_config(reward_function_cfg, session=sess) execution_definition = AgentExecutionDefinition(**agent_cfg.get("execution_definition", {})) + agent_settings = AgentSettings(**agent_cfg.get("agent_settings", {})) # CREATE AGENT if agent_type == "GreenWebBrowsingAgent": @@ -449,6 +456,7 @@ class PrimaiteSession: observation_space=obs_space, reward_function=rew_function, execution_definition=execution_definition, + agent_settings=agent_settings, ) sess.agents.append(new_agent) elif agent_type == "GATERLAgent": @@ -458,6 +466,7 @@ class PrimaiteSession: observation_space=obs_space, reward_function=rew_function, execution_definition=execution_definition, + agent_settings=agent_settings, ) sess.agents.append(new_agent) sess.rl_agent = new_agent @@ -468,6 +477,7 @@ class PrimaiteSession: observation_space=obs_space, reward_function=rew_function, execution_definition=execution_definition, + agent_settings=agent_settings, ) sess.agents.append(new_agent) else: From 95ad55a78369f92776e46a95cf5fce421d27f194 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Mon, 20 Nov 2023 18:04:49 +0000 Subject: [PATCH 322/980] #2041: change deprecated logger levels. --- src/primaite/simulator/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 9ead877e..5ec816bb 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -113,7 +113,7 @@ class RequestManager(BaseModel): """ if name in self.request_types: msg = f"Overwriting request type {name}." - _LOGGER.warn(msg) + _LOGGER.warning(msg) self.request_types[name] = request_type @@ -248,6 +248,6 @@ class SimComponent(BaseModel): def parent(self, new_parent: Union["SimComponent", None]) -> None: if self._parent and new_parent: msg = f"Overwriting parent of {self.uuid}. Old parent: {self._parent.uuid}, New parent: {new_parent.uuid}" - _LOGGER.warn(msg) + _LOGGER.warning(msg) raise RuntimeWarning(msg) self._parent = new_parent From b0b37f9da5ce255acfa246c6609adcea725763be Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Mon, 20 Nov 2023 18:06:50 +0000 Subject: [PATCH 323/980] #2042: ntp_client test fixes. --- src/primaite/simulator/system/services/ntp/ntp_client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index 123de7cc..3e73eee7 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -89,8 +89,7 @@ class NTPClient(Service): if not (isinstance(payload, NTPPacket) and payload.ntp_request.ntp_client): _LOGGER.debug(f"{payload} is not a NTPPacket") return False - - # XXX: compare received datetime with current time. Log error if differ by more than x ms? + print(f">>>>>>>>>>>>>>>>>> payload.ntp_reply.ntp_datetime {payload.ntp_reply.ntp_datetime}") if payload.ntp_reply.ntp_datetime: self.sys_log.info( f"{self.name}: Received time \ @@ -112,8 +111,9 @@ class NTPClient(Service): super().apply_timestep(timestep) if self.operating_state == ServiceOperatingState.RUNNING: # request time from server - ntp_request = NTPPacket(NTPRequest()) - self.send(ntp_request) + ntp_request = NTPRequest(ntp_client=self.ip_addr) + ntp_server_packet = NTPPacket(ntp_request=ntp_request) + self.send(payload=ntp_server_packet) return True else: self.sys_log.debug(f"{self.name} ntp client not running") From f7215847d414f947c921602044b8bc0e25b03a06 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Mon, 20 Nov 2023 18:08:55 +0000 Subject: [PATCH 324/980] #2041: ntp_server test fixes. --- .../simulator/network/protocols/ntp.py | 4 ++-- .../system/services/ntp/ntp_server.py | 8 ++++--- .../system/test_ntp_client_server.py | 21 ++++++++++++------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/primaite/simulator/network/protocols/ntp.py b/src/primaite/simulator/network/protocols/ntp.py index e201a770..df5ce0c1 100644 --- a/src/primaite/simulator/network/protocols/ntp.py +++ b/src/primaite/simulator/network/protocols/ntp.py @@ -34,11 +34,11 @@ class NTPPacket(DataPacket): "NTP Request packet sent by NTP Client." ntp_reply: Optional[NTPReply] = None - def generate_reply(self, time: datetime) -> NTPPacket: + def generate_reply(self, ntp_server_time: datetime) -> NTPPacket: """Generate a NTPPacket containing the time in a NTPReply object. :param time: datetime object representing the time from the NTP server. :return: A new NTPPacket object. """ - self.ntp_reply = NTPReply(time) + self.ntp_reply = NTPReply(ntp_datetime=ntp_server_time) return self diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index d4be6924..337869a4 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -50,7 +50,8 @@ class NTPServer(Service): session_id: Optional[str] = None, **kwargs, ) -> bool: - """Receives a request from NTPClient. + """ + Receives a request from NTPClient. Check that request has a valid IP address. @@ -75,5 +76,6 @@ class NTPServer(Service): f"with current time: {time}" ) # send reply - self.send(payload, session_id) - return True + if self.send(payload, session_id): + return True + return False diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index e859faf4..545683f3 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -5,7 +5,7 @@ import pytest from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.protocols.ntp import NTPPacket +from primaite.simulator.network.protocols.ntp import NTPPacket, NTPRequest from primaite.simulator.system.services.ntp.ntp_client import NTPClient from primaite.simulator.system.services.ntp.ntp_server import NTPServer from primaite.simulator.system.services.service import ServiceOperatingState @@ -58,9 +58,11 @@ def test_ntp_client_server(): assert ntp_server.operating_state == ServiceOperatingState.RUNNING assert ntp_client.operating_state == ServiceOperatingState.RUNNING - ntp_client.send(payload=NTPPacket()) - assert ntp_server.receive() is True - assert ntp_client.receive() is True + ntp_request = NTPRequest(ntp_client="192.168.1.3") + ntp_packet = NTPPacket(ntp_request=ntp_request) + ntp_client.send(payload=ntp_packet) + assert ntp_server.receive(payload=ntp_packet) is True + assert ntp_client.receive(payload=ntp_packet) is True assert ntp_client.apply_timestep(1) is True @@ -71,15 +73,20 @@ def test_ntp_server_failure(): server: Server = network.get_node_by_hostname("ntp_server") client: Computer = network.get_node_by_hostname("ntp_client") - ntp_server: NTPServer = server.software_manager.software["NTP_Server"] - ntp_client: NTPClient = client.software_manager.software["NTP_Client"] + ntp_server: NTPServer = server.software_manager.software["NTPServer"] + ntp_client: NTPClient = client.software_manager.software["NTPClient"] assert ntp_client.operating_state == ServiceOperatingState.RUNNING # Turn off ntp server. ntp_server.stop() assert ntp_server.operating_state == ServiceOperatingState.STOPPED - assert ntp_client.receive() is False + # And request a time update. + ntp_request = NTPRequest(ntp_client="192.168.1.3") + ntp_packet = NTPPacket(ntp_request=ntp_request) + ntp_client.send(payload=ntp_packet) + assert ntp_server.receive(payload=ntp_packet) is False + assert ntp_client.receive(payload=ntp_packet) is False # Restart ntp server. ntp_server.start() From 813a1f356e9fac0afcd627145150bdb43484deac Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 21 Nov 2023 11:15:07 +0000 Subject: [PATCH 325/980] #2042: Remove debug statement --- src/primaite/simulator/system/services/ntp/ntp_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index 3e73eee7..99bc7584 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -89,7 +89,6 @@ class NTPClient(Service): if not (isinstance(payload, NTPPacket) and payload.ntp_request.ntp_client): _LOGGER.debug(f"{payload} is not a NTPPacket") return False - print(f">>>>>>>>>>>>>>>>>> payload.ntp_reply.ntp_datetime {payload.ntp_reply.ntp_datetime}") if payload.ntp_reply.ntp_datetime: self.sys_log.info( f"{self.name}: Received time \ From 4f0f758ce9b19387cf79ca989fd023792b1a8b35 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 21 Nov 2023 11:16:34 +0000 Subject: [PATCH 326/980] #2041: Correct return value from receive() --- src/primaite/simulator/system/services/ntp/ntp_server.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index 337869a4..238f4f84 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -76,6 +76,5 @@ class NTPServer(Service): f"with current time: {time}" ) # send reply - if self.send(payload, session_id): - return True - return False + self.send(payload, session_id) + return True From 60d94bf4b56f45c2e60a57ce9b2dce663d37feda Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 21 Nov 2023 11:17:38 +0000 Subject: [PATCH 327/980] #2041: Remove test --- .../system/test_ntp_client_server.py | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index 545683f3..8059defa 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -40,10 +40,6 @@ def create_ntp_network() -> Network: return network -# @pytest.fixture() -# def create_network(): -# return create_ntp_network() - # Define one node to be an NTP server and another node to be a NTP Client. @@ -67,27 +63,28 @@ def test_ntp_client_server(): assert ntp_client.apply_timestep(1) is True +# TODO: Disabled until a service such as NTP can introspect to see if it's running. # Test ntp client behaviour when ntp server is unavailable. -def test_ntp_server_failure(): - network = create_ntp_network() - server: Server = network.get_node_by_hostname("ntp_server") - client: Computer = network.get_node_by_hostname("ntp_client") +# def test_ntp_server_failure(): +# network = create_ntp_network() +# server: Server = network.get_node_by_hostname("ntp_server") +# client: Computer = network.get_node_by_hostname("ntp_client") - ntp_server: NTPServer = server.software_manager.software["NTPServer"] - ntp_client: NTPClient = client.software_manager.software["NTPClient"] +# ntp_server: NTPServer = server.software_manager.software["NTPServer"] +# ntp_client: NTPClient = client.software_manager.software["NTPClient"] - assert ntp_client.operating_state == ServiceOperatingState.RUNNING +# assert ntp_client.operating_state == ServiceOperatingState.RUNNING - # Turn off ntp server. - ntp_server.stop() - assert ntp_server.operating_state == ServiceOperatingState.STOPPED - # And request a time update. - ntp_request = NTPRequest(ntp_client="192.168.1.3") - ntp_packet = NTPPacket(ntp_request=ntp_request) - ntp_client.send(payload=ntp_packet) - assert ntp_server.receive(payload=ntp_packet) is False - assert ntp_client.receive(payload=ntp_packet) is False +# # Turn off ntp server. +# ntp_server.stop() +# assert ntp_server.operating_state == ServiceOperatingState.STOPPED +# # And request a time update. +# ntp_request = NTPRequest(ntp_client="192.168.1.3") +# ntp_packet = NTPPacket(ntp_request=ntp_request) +# ntp_client.send(payload=ntp_packet) +# assert ntp_server.receive(payload=ntp_packet) is False +# assert ntp_client.receive(payload=ntp_packet) is False - # Restart ntp server. - ntp_server.start() - assert ntp_server.operating_state == ServiceOperatingState.RUNNING +# # Restart ntp server. +# ntp_server.start() +# assert ntp_server.operating_state == ServiceOperatingState.RUNNING From 2975aa882774c3b5979072646de64c243ab880b4 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Tue, 21 Nov 2023 11:42:01 +0000 Subject: [PATCH 328/980] Execute data manipulation bots from agent --- src/primaite/game/agent/interface.py | 38 ++++++++++++++++++- src/primaite/game/session.py | 4 +- .../system/applications/database_client.py | 2 +- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 70eb1980..94878947 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -24,6 +24,20 @@ class AgentExecutionDefinition(BaseModel): data_manipulation_p_of_success: float = 0.1 "The probability of data manipulation succeeding." + @classmethod + def from_config(cls, config: Optional[Dict]) -> "AgentExecutionDefinition": + """Construct an AgentExecutionDefinition from a config dictionary. + + :param config: A dict of options for the execution definition. + :type config: Dict + :return: The execution definition. + :rtype: AgentExecutionDefinition + """ + if config is None: + return cls() + + return cls(**config) + class AgentStartSettings(BaseModel): """Configuration values for when an agent starts performing actions.""" @@ -42,6 +56,20 @@ class AgentSettings(BaseModel): start_settings: Optional[AgentStartSettings] = None "Configuration for when an agent begins performing it's actions" + @classmethod + def from_config(cls, config: Optional[Dict]) -> "AgentSettings": + """Construct agent settings from a config dictionary. + + :param config: A dict of options for the agent settings. + :type config: Dict + :return: The agent settings. + :rtype: AgentSettings + """ + if config is None: + return cls() + + return cls(**config) + class AbstractAgent(ABC): """Base class for scripted and RL agents.""" @@ -149,6 +177,8 @@ class RandomAgent(AbstractScriptedAgent): class DataManipulationAgent(AbstractScriptedAgent): """Agent that uses a DataManipulationBot to perform an SQL injection attack.""" + data_manipulation_bots: List["DataManipulationBot"] = [] + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -163,6 +193,7 @@ class DataManipulationAgent(AbstractScriptedAgent): if bot_sw is not None: bot_sw.execution_definition = self.execution_definition + self.data_manipulation_bots.append(bot_sw) def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: """Randomly sample an action from the action space. @@ -174,7 +205,12 @@ class DataManipulationAgent(AbstractScriptedAgent): :return: _description_ :rtype: Tuple[str, Dict] """ - return self.action_space.get_action(self.action_space.space.sample()) + # TODO: Move this to the appropriate place + # return self.action_space.get_action(self.action_space.space.sample()) + for bot in self.data_manipulation_bots: + bot.execute() + + return ("DONOTHING", {"dummy": 0}) class AbstractGATEAgent(AbstractAgent): diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 9701fec9..1b086c35 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -444,8 +444,8 @@ class PrimaiteSession: # CREATE REWARD FUNCTION rew_function = RewardFunction.from_config(reward_function_cfg, session=sess) - execution_definition = AgentExecutionDefinition(**agent_cfg.get("execution_definition", {})) - agent_settings = AgentSettings(**agent_cfg.get("agent_settings", {})) + execution_definition = AgentExecutionDefinition.from_config(agent_cfg.get("execution_definition")) + agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) # CREATE AGENT if agent_type == "GreenWebBrowsingAgent": diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 28e826fd..e15249e3 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -130,7 +130,7 @@ class DatabaseClient(Application): def execute(self) -> None: """Run the DatabaseClient.""" - super().execute() + # super().execute() if self.operating_state == ApplicationOperatingState.RUNNING: self.connect() From d8154bbebd4e6d98aaf6cf51628be1b176ad00b8 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Tue, 21 Nov 2023 11:43:47 +0000 Subject: [PATCH 329/980] Add tests for data manipulation bot attack stages --- .../test_data_manipulation_bot.py | 61 +++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py index dd785cc1..5127254c 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py @@ -1,20 +1,73 @@ from ipaddress import IPv4Address +import pytest + from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.networks import arcd_uc2_network from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot +from primaite.simulator.system.services.red_services.data_manipulation_bot import ( + DataManipulationAttackStage, + DataManipulationBot, +) -def test_creation(): +@pytest.fixture(scope="function") +def dm_client() -> Node: network = arcd_uc2_network() + return network.get_node_by_hostname("client_1") - client_1: Node = network.get_node_by_hostname("client_1") - data_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] +@pytest.fixture +def dm_bot(dm_client) -> DataManipulationBot: + return dm_client.software_manager.software["DataManipulationBot"] + + +def test_create_dm_bot(dm_client): + data_manipulation_bot: DataManipulationBot = dm_client.software_manager.software["DataManipulationBot"] assert data_manipulation_bot.name == "DataManipulationBot" assert data_manipulation_bot.port == Port.POSTGRES_SERVER assert data_manipulation_bot.protocol == IPProtocol.TCP assert data_manipulation_bot.payload == "DROP TABLE IF EXISTS user;" + + +def test_dm_bot_logon(dm_bot): + dm_bot.attack_stage = DataManipulationAttackStage.NOT_STARTED + + dm_bot._logon() + + assert dm_bot.attack_stage == DataManipulationAttackStage.LOGON + + +def test_dm_bot_perform_port_scan_no_success(dm_bot): + dm_bot.attack_stage = DataManipulationAttackStage.LOGON + + dm_bot._perform_port_scan(p_of_success=0.0) + + assert dm_bot.attack_stage == DataManipulationAttackStage.LOGON + + +def test_dm_bot_perform_port_scan_success(dm_bot): + dm_bot.attack_stage = DataManipulationAttackStage.LOGON + + dm_bot._perform_port_scan(p_of_success=1.0) + + assert dm_bot.attack_stage == DataManipulationAttackStage.PORT_SCAN + + +def test_dm_bot_perform_data_manipulation_no_success(dm_bot): + dm_bot.attack_stage = DataManipulationAttackStage.PORT_SCAN + + dm_bot._perform_data_manipulation(p_of_success=0.0) + + assert dm_bot.attack_stage == DataManipulationAttackStage.PORT_SCAN + + +def test_dm_bot_perform_data_manipulation_success(dm_bot): + dm_bot.attack_stage = DataManipulationAttackStage.PORT_SCAN + + dm_bot._perform_data_manipulation(p_of_success=1.0) + + assert dm_bot.attack_stage in (DataManipulationAttackStage.COMPLETE, DataManipulationAttackStage.FAILED) + assert dm_bot.connected From 243f2dd938e335c048d16f63a292e24876e7a141 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 21 Nov 2023 12:11:30 +0000 Subject: [PATCH 330/980] #2041: Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3af5c14c..a6dd0f6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ SessionManager. - DNS Services: `DNSClient` and `DNSServer` - FTP Services: `FTPClient` and `FTPServer` - HTTP Services: `WebBrowser` to simulate a web client and `WebServer` +- NTP Services: `NTPClient` and `NTPServer` ### Removed - Removed legacy simulation modules: `acl`, `common`, `environment`, `links`, `nodes`, `pol` From 48af0229637726c9fc953ecf54b2329947151a1a Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Tue, 21 Nov 2023 13:41:38 +0000 Subject: [PATCH 331/980] Run agent at configured timesteps --- src/primaite/game/agent/interface.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 94878947..d2479b38 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -1,4 +1,5 @@ """Interface for agents.""" +import random from abc import ABC, abstractmethod from typing import Dict, List, Optional, Tuple, TYPE_CHECKING, TypeAlias, Union @@ -178,10 +179,13 @@ class DataManipulationAgent(AbstractScriptedAgent): """Agent that uses a DataManipulationBot to perform an SQL injection attack.""" data_manipulation_bots: List["DataManipulationBot"] = [] + next_execution_timestep: int = 0 def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + self.next_execution_timestep = self.agent_settings.start_settings.start_step + # get node ids that are part of the agent's observation space node_ids: List[str] = [n.where[-1] for n in self.observation_space.obs.nodes] # get all nodes from their ids @@ -207,10 +211,19 @@ class DataManipulationAgent(AbstractScriptedAgent): """ # TODO: Move this to the appropriate place # return self.action_space.get_action(self.action_space.space.sample()) + + timestep = self.action_space.session.step_counter + + if timestep < self.next_execution_timestep: + return "DONOTHING", {"dummy": 0} + + var = random.randint(-self.agent_settings.start_settings.variance, self.agent_settings.start_settings.variance) + self.next_execution_timestep = timestep + self.agent_settings.start_settings.frequency + var + for bot in self.data_manipulation_bots: bot.execute() - return ("DONOTHING", {"dummy": 0}) + return "DONOTHING", {"dummy": 0} class AbstractGATEAgent(AbstractAgent): From aa65c53a95ad33b356a588ed054b9e0a0dfaf3cc Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Tue, 21 Nov 2023 15:09:51 +0000 Subject: [PATCH 332/980] Pass probability of success through to functions --- .../system/services/red_services/data_manipulation_bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index 35ea413a..5e4e2d3f 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -135,8 +135,8 @@ class DataManipulationBot(DatabaseClient): if self.server_ip_address and self.payload and self.operating_state: self.sys_log.info(f"{self.name}: Running") self._logon() - self._perform_port_scan() - self._perform_data_manipulation() + self._perform_port_scan(p_of_success=self.execution_definition.port_scan_p_of_success) + self._perform_data_manipulation(p_of_success=self.execution_definition.data_manipulation_p_of_success) else: self.sys_log.error(f"{self.name}: Failed to start as it requires both a target_ip_address and payload.") From eb2e37429a1ccfb74f998e3a6f907c80e2a4de13 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 21 Nov 2023 17:24:24 +0000 Subject: [PATCH 333/980] #2042: Add time attribute --- .../system/services/ntp/ntp_client.py | 3 ++ .../system/test_ntp_client_server.py | 43 ++++++++++--------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index 99bc7584..81ec031c 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -1,3 +1,4 @@ +from datetime import datetime from ipaddress import IPv4Address from typing import Dict, Optional @@ -16,6 +17,7 @@ class NTPClient(Service): ip_addr: Optional[IPv4Address] = None ntp_server: Optional[IPv4Address] = None "The NTP server the client sends requests to." + time: Optional[datetime] = None def __init__(self, **kwargs): kwargs["name"] = "NTPClient" @@ -94,6 +96,7 @@ class NTPClient(Service): f"{self.name}: Received time \ update from NTP server{payload.ntp_reply.ntp_datetime}" ) + self.time = payload.ntp_reply.ntp_datetime return True def apply_timestep(self, timestep: int) -> None: diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index 8059defa..48db0cbb 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -53,38 +53,39 @@ def test_ntp_client_server(): assert ntp_server.operating_state == ServiceOperatingState.RUNNING assert ntp_client.operating_state == ServiceOperatingState.RUNNING + assert ntp_client.time is None ntp_request = NTPRequest(ntp_client="192.168.1.3") ntp_packet = NTPPacket(ntp_request=ntp_request) ntp_client.send(payload=ntp_packet) assert ntp_server.receive(payload=ntp_packet) is True assert ntp_client.receive(payload=ntp_packet) is True - + assert ntp_client.time is not None assert ntp_client.apply_timestep(1) is True -# TODO: Disabled until a service such as NTP can introspect to see if it's running. # Test ntp client behaviour when ntp server is unavailable. -# def test_ntp_server_failure(): -# network = create_ntp_network() -# server: Server = network.get_node_by_hostname("ntp_server") -# client: Computer = network.get_node_by_hostname("ntp_client") +@pytest.mark.skip(reason="NTP needs to know if underly node is RUNNING") +def test_ntp_server_failure(): + network = create_ntp_network() + server: Server = network.get_node_by_hostname("ntp_server") + client: Computer = network.get_node_by_hostname("ntp_client") -# ntp_server: NTPServer = server.software_manager.software["NTPServer"] -# ntp_client: NTPClient = client.software_manager.software["NTPClient"] + ntp_server: NTPServer = server.software_manager.software["NTPServer"] + ntp_client: NTPClient = client.software_manager.software["NTPClient"] -# assert ntp_client.operating_state == ServiceOperatingState.RUNNING + assert ntp_client.operating_state == ServiceOperatingState.RUNNING -# # Turn off ntp server. -# ntp_server.stop() -# assert ntp_server.operating_state == ServiceOperatingState.STOPPED -# # And request a time update. -# ntp_request = NTPRequest(ntp_client="192.168.1.3") -# ntp_packet = NTPPacket(ntp_request=ntp_request) -# ntp_client.send(payload=ntp_packet) -# assert ntp_server.receive(payload=ntp_packet) is False -# assert ntp_client.receive(payload=ntp_packet) is False + # Turn off ntp server. + ntp_server.stop() + assert ntp_server.operating_state == ServiceOperatingState.STOPPED + # And request a time update. + ntp_request = NTPRequest(ntp_client="192.168.1.3") + ntp_packet = NTPPacket(ntp_request=ntp_request) + ntp_client.send(payload=ntp_packet) + assert ntp_server.receive(payload=ntp_packet) is False + assert ntp_client.receive(payload=ntp_packet) is False -# # Restart ntp server. -# ntp_server.start() -# assert ntp_server.operating_state == ServiceOperatingState.RUNNING + # Restart ntp server. + ntp_server.start() + assert ntp_server.operating_state == ServiceOperatingState.RUNNING From 984d165364b7399277ccc9b3991190344683ac8a Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 21 Nov 2023 17:24:50 +0000 Subject: [PATCH 334/980] #2041: Fix long line --- src/primaite/simulator/system/services/ntp/ntp_server.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index 238f4f84..13bc04ee 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -66,7 +66,8 @@ class NTPServer(Service): payload: NTPPacket = payload if payload.ntp_request.ntp_client: self.sys_log.info( - f"{self.name}: Received request for {payload.ntp_request.ntp_client} " f"from session {session_id}" + f"{self.name}: Received request for {payload.ntp_request.ntp_client} \ + from session {session_id}" ) # generate a reply with the current time time = datetime.now() From dd7c2b05f830e132a40265299dca93fe28699e6f Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 22 Nov 2023 08:54:39 +0000 Subject: [PATCH 335/980] #2041: Add RST doc --- .../system/ntp_client_server.rst | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 docs/source/simulation_components/system/ntp_client_server.rst diff --git a/docs/source/simulation_components/system/ntp_client_server.rst b/docs/source/simulation_components/system/ntp_client_server.rst new file mode 100644 index 00000000..671126fb --- /dev/null +++ b/docs/source/simulation_components/system/ntp_client_server.rst @@ -0,0 +1,54 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +NTP Client Server +================= + +NTP Server +---------- +The ``NTPServer`` provides a NTP Server simulation by extending the base Service class. + +NTP Client +---------- +The ``NTPClient`` provides a NTP Client simulation by extending the base Service class. + +Key capabilities +^^^^^^^^^^^^^^^^ + +- Simulates NTP requests and NTPPacket transfer across a network +- Leverages the Service base class for install/uninstall, status tracking, etc. + +Usage +^^^^^ +- Install on a Node via the ``SoftwareManager`` to start the database service. +- Service runs on TCP port 123 by default. + +Implementation +^^^^^^^^^^^^^^ + +- NTP request and responses use a ``NTPPacket`` object +- Extends Service class for integration with ``SoftwareManager``. + +NTP Client +---------- + +The NTPClient provides a client interface for connecting to the ``NTPServer``. + +Key features +^^^^^^^^^^^^ + +- Connects to the ``NTPServer`` via the ``SoftwareManager``. + +Usage +^^^^^ + +- Install on a Node via the ``SoftwareManager`` to start the database service. +- Service runs on TCP port 123 by default. + +Implementation +^^^^^^^^^^^^^^ + +- Leverages ``SoftwareManager`` for sending payloads over the network. +- Provides easy interface for Nodes to find IP addresses via domain names. +- Extends base Service class. From afd64e467403824cd7c2db80eec02cfd58a5fe46 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 22 Nov 2023 11:59:25 +0000 Subject: [PATCH 336/980] Separate game, environment, and session --- .../config/_package_data/example_config.yaml | 2 +- src/primaite/game/agent/actions.py | 8 +- src/primaite/game/agent/observations.py | 28 ++-- src/primaite/game/agent/rewards.py | 12 +- src/primaite/game/environment.py | 6 +- src/primaite/game/{session.py => game.py} | 152 ++++-------------- src/primaite/game/policy/policy.py | 8 +- src/primaite/game/policy/rllib.py | 21 ++- src/primaite/game/policy/sb3.py | 6 +- src/primaite/main.py | 4 +- .../notebooks/train_rllib_single_agent.ipynb | 129 +++++++++++++++ src/primaite/session/__init__.py | 0 src/primaite/{game => session}/io.py | 0 src/primaite/session/session.py | 92 +++++++++++ tests/conftest.py | 4 +- 15 files changed, 304 insertions(+), 168 deletions(-) rename src/primaite/game/{session.py => game.py} (78%) create mode 100644 src/primaite/notebooks/train_rllib_single_agent.ipynb create mode 100644 src/primaite/session/__init__.py rename src/primaite/{game => session}/io.py (100%) create mode 100644 src/primaite/session/session.py diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 3d918f2b..443b0efe 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -2,7 +2,7 @@ training_config: rl_framework: RLLIB_single_agent rl_algorithm: PPO seed: 333 - n_learn_episodes: 25 + n_learn_episodes: 1 n_eval_episodes: 5 max_steps_per_episode: 128 deterministic_eval: false diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index b06013cd..c8095aa5 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -20,7 +20,7 @@ from primaite.simulator.sim_container import Simulation _LOGGER = getLogger(__name__) if TYPE_CHECKING: - from primaite.game.session import PrimaiteSession + from primaite.game.game import PrimaiteGame class AbstractAction(ABC): @@ -559,7 +559,7 @@ class ActionManager: def __init__( self, - session: "PrimaiteSession", # reference to session for looking up stuff + session: "PrimaiteGame", # reference to session for looking up stuff actions: List[str], # stores list of actions available to agent node_uuids: List[str], # allows mapping index to node max_folders_per_node: int = 2, # allows calculating shape @@ -599,7 +599,7 @@ class ActionManager: :param act_map: Action map which maps integers to actions. Used for restricting the set of possible actions. :type act_map: Optional[Dict[int, Dict]] """ - self.session: "PrimaiteSession" = session + self.session: "PrimaiteGame" = session self.sim: Simulation = self.session.simulation self.node_uuids: List[str] = node_uuids self.protocols: List[str] = protocols @@ -826,7 +826,7 @@ class ActionManager: return nics[nic_idx] @classmethod - def from_config(cls, session: "PrimaiteSession", cfg: Dict) -> "ActionManager": + def from_config(cls, session: "PrimaiteGame", cfg: Dict) -> "ActionManager": """ Construct an ActionManager from a config definition. diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index a74771c0..f57ec10d 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -11,7 +11,7 @@ from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_ST _LOGGER = getLogger(__name__) if TYPE_CHECKING: - from primaite.game.session import PrimaiteSession + from primaite.game.game import PrimaiteGame class AbstractObservation(ABC): @@ -37,7 +37,7 @@ class AbstractObservation(ABC): @classmethod @abstractmethod - def from_config(cls, config: Dict, session: "PrimaiteSession"): + def from_config(cls, config: Dict, session: "PrimaiteGame"): """Create this observation space component form a serialised format. The `session` parameter is for a the PrimaiteSession object that spawns this component. During deserialisation, @@ -91,7 +91,7 @@ class FileObservation(AbstractObservation): return spaces.Dict({"health_status": spaces.Discrete(6)}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where: List[str] = None) -> "FileObservation": + def from_config(cls, config: Dict, session: "PrimaiteGame", parent_where: List[str] = None) -> "FileObservation": """Create file observation from a config. :param config: Dictionary containing the configuration for this file observation. @@ -149,7 +149,7 @@ class ServiceObservation(AbstractObservation): @classmethod def from_config( - cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]] = None + cls, config: Dict, session: "PrimaiteGame", parent_where: Optional[List[str]] = None ) -> "ServiceObservation": """Create service observation from a config. @@ -219,7 +219,7 @@ class LinkObservation(AbstractObservation): return spaces.Dict({"PROTOCOLS": spaces.Dict({"ALL": spaces.Discrete(11)})}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "LinkObservation": + def from_config(cls, config: Dict, session: "PrimaiteGame") -> "LinkObservation": """Create link observation from a config. :param config: Dictionary containing the configuration for this link observation. @@ -310,7 +310,7 @@ class FolderObservation(AbstractObservation): @classmethod def from_config( - cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]], num_files_per_folder: int = 2 + cls, config: Dict, session: "PrimaiteGame", parent_where: Optional[List[str]], num_files_per_folder: int = 2 ) -> "FolderObservation": """Create folder observation from a config. Also creates child file observations. @@ -376,9 +376,7 @@ class NicObservation(AbstractObservation): return spaces.Dict({"nic_status": spaces.Discrete(3)}) @classmethod - def from_config( - cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]] - ) -> "NicObservation": + def from_config(cls, config: Dict, session: "PrimaiteGame", parent_where: Optional[List[str]]) -> "NicObservation": """Create NIC observation from a config. :param config: Dictionary containing the configuration for this NIC observation. @@ -515,7 +513,7 @@ class NodeObservation(AbstractObservation): def from_config( cls, config: Dict, - session: "PrimaiteSession", + session: "PrimaiteGame", parent_where: Optional[List[str]] = None, num_services_per_node: int = 2, num_folders_per_node: int = 2, @@ -694,7 +692,7 @@ class AclObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "AclObservation": + def from_config(cls, config: Dict, session: "PrimaiteGame") -> "AclObservation": """Generate ACL observation from a config. :param config: Dictionary containing the configuration for this ACL observation. @@ -740,7 +738,7 @@ class NullObservation(AbstractObservation): return spaces.Discrete(1) @classmethod - def from_config(cls, config: Dict, session: Optional["PrimaiteSession"] = None) -> "NullObservation": + def from_config(cls, config: Dict, session: Optional["PrimaiteGame"] = None) -> "NullObservation": """ Create null observation from a config. @@ -836,7 +834,7 @@ class UC2BlueObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "UC2BlueObservation": + def from_config(cls, config: Dict, session: "PrimaiteGame") -> "UC2BlueObservation": """Create UC2 blue observation from a config. :param config: Dictionary containing the configuration for this UC2 blue observation. This includes the nodes, @@ -907,7 +905,7 @@ class UC2RedObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "UC2RedObservation": + def from_config(cls, config: Dict, session: "PrimaiteGame") -> "UC2RedObservation": """ Create UC2 red observation from a config. @@ -966,7 +964,7 @@ class ObservationManager: return self.obs.space @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "ObservationManager": + def from_config(cls, config: Dict, session: "PrimaiteGame") -> "ObservationManager": """Create observation space from a config. :param config: Dictionary containing the configuration for this observation space. diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index da1331b0..60c3678c 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -34,7 +34,7 @@ from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_ST _LOGGER = getLogger(__name__) if TYPE_CHECKING: - from primaite.game.session import PrimaiteSession + from primaite.game.game import PrimaiteGame class AbstractReward: @@ -47,7 +47,7 @@ class AbstractReward: @classmethod @abstractmethod - def from_config(cls, config: dict, session: "PrimaiteSession") -> "AbstractReward": + def from_config(cls, config: dict, session: "PrimaiteGame") -> "AbstractReward": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor @@ -68,7 +68,7 @@ class DummyReward(AbstractReward): return 0.0 @classmethod - def from_config(cls, config: dict, session: "PrimaiteSession") -> "DummyReward": + def from_config(cls, config: dict, session: "PrimaiteGame") -> "DummyReward": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor. Should be empty. @@ -119,7 +119,7 @@ class DatabaseFileIntegrity(AbstractReward): return 0 @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "DatabaseFileIntegrity": + def from_config(cls, config: Dict, session: "PrimaiteGame") -> "DatabaseFileIntegrity": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor @@ -193,7 +193,7 @@ class WebServer404Penalty(AbstractReward): return 0.0 @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "WebServer404Penalty": + def from_config(cls, config: Dict, session: "PrimaiteGame") -> "WebServer404Penalty": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor @@ -265,7 +265,7 @@ class RewardFunction: return self.current_reward @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "RewardFunction": + def from_config(cls, config: Dict, session: "PrimaiteGame") -> "RewardFunction": """Create a reward function from a config dictionary. :param config: dict of options for the reward manager's constructor diff --git a/src/primaite/game/environment.py b/src/primaite/game/environment.py index b88a8202..36f808bb 100644 --- a/src/primaite/game/environment.py +++ b/src/primaite/game/environment.py @@ -6,7 +6,7 @@ from gymnasium.core import ActType, ObsType from primaite.game.agent.interface import ProxyAgent if TYPE_CHECKING: - from primaite.game.session import PrimaiteSession + from primaite.game.game import PrimaiteGame class PrimaiteGymEnv(gymnasium.Env): @@ -17,10 +17,10 @@ class PrimaiteGymEnv(gymnasium.Env): assumptions about the agent list always having a list of length 1. """ - def __init__(self, session: "PrimaiteSession", agents: List[ProxyAgent]): + def __init__(self, session: "PrimaiteGame", agents: List[ProxyAgent]): """Initialise the environment.""" super().__init__() - self.session: "PrimaiteSession" = session + self.session: "PrimaiteGame" = session self.agent: ProxyAgent = agents[0] def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: diff --git a/src/primaite/game/session.py b/src/primaite/game/game.py similarity index 78% rename from src/primaite/game/session.py rename to src/primaite/game/game.py index c4195925..7dd50924 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/game.py @@ -1,11 +1,7 @@ """PrimAITE session - the main entry point to training agents on PrimAITE.""" -from enum import Enum from ipaddress import IPv4Address -from pathlib import Path -from typing import Any, Dict, List, Literal, Optional, SupportsFloat, Tuple +from typing import Dict, List -import gymnasium -from gymnasium.core import ActType, ObsType from pydantic import BaseModel, ConfigDict from primaite import getLogger @@ -13,9 +9,6 @@ from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractAgent, ProxyAgent, RandomAgent from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction -from primaite.game.environment import PrimaiteGymEnv -from primaite.game.io import SessionIO, SessionIOSettings -from primaite.game.policy.policy import PolicyABC from primaite.simulator.network.hardware.base import Link, NIC, Node from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router @@ -37,7 +30,7 @@ from primaite.simulator.system.services.web_server.web_server import WebServer _LOGGER = getLogger(__name__) -class PrimaiteSessionOptions(BaseModel): +class PrimaiteGameOptions(BaseModel): """ Global options which are applicable to all of the agents in the game. @@ -46,37 +39,17 @@ class PrimaiteSessionOptions(BaseModel): model_config = ConfigDict(extra="forbid") + max_episode_length: int = 256 ports: List[str] protocols: List[str] -class TrainingOptions(BaseModel): - """Options for training the RL agent.""" +class PrimaiteGame: + """ + Primaite game encapsulates the simulation and agents which interact with it. - model_config = ConfigDict(extra="forbid") - - rl_framework: Literal["SB3", "RLLIB_single_agent"] - rl_algorithm: Literal["PPO", "A2C"] - n_learn_episodes: int - n_eval_episodes: Optional[int] = None - max_steps_per_episode: int - # checkpoint_freq: Optional[int] = None - deterministic_eval: bool - seed: Optional[int] - n_agents: int - agent_references: List[str] - - -class SessionMode(Enum): - """Helper to keep track of the current session mode.""" - - TRAIN = "train" - EVAL = "eval" - MANUAL = "manual" - - -class PrimaiteSession: - """The main entrypoint for PrimAITE sessions, this manages a simulation, agents, and environments.""" + Provides main logic loop for the game. However, it does not provide policy training, or a gymnasium environment. + """ def __init__(self): """Initialise a PrimaiteSession object.""" @@ -95,15 +68,9 @@ class PrimaiteSession: self.episode_counter: int = 0 """Current episode number.""" - self.options: PrimaiteSessionOptions + self.options: PrimaiteGameOptions """Special options that apply for the entire game.""" - self.training_options: TrainingOptions - """Options specific to agent training.""" - - self.policy: PolicyABC - """The reinforcement learning policy.""" - self.ref_map_nodes: Dict[str, Node] = {} """Mapping from unique node reference name to node object. Used when parsing config files.""" @@ -116,40 +83,6 @@ class PrimaiteSession: self.ref_map_links: Dict[str, Link] = {} """Mapping from human-readable link reference to link object. Used when parsing config files.""" - self.env: PrimaiteGymEnv - """The environment that the agent can consume. Could be PrimaiteEnv.""" - - self.mode: SessionMode = SessionMode.MANUAL - """Current session mode.""" - - self.io_manager = SessionIO() - """IO manager for the session.""" - - def start_session(self) -> None: - """Commence the training session.""" - self.mode = SessionMode.TRAIN - n_learn_episodes = self.training_options.n_learn_episodes - n_eval_episodes = self.training_options.n_eval_episodes - max_steps_per_episode = self.training_options.max_steps_per_episode - - deterministic_eval = self.training_options.deterministic_eval - self.policy.learn( - n_episodes=n_learn_episodes, - timesteps_per_episode=max_steps_per_episode, - ) - self.save_models() - - self.mode = SessionMode.EVAL - if n_eval_episodes > 0: - self.policy.eval(n_episodes=n_eval_episodes, deterministic=deterministic_eval) - - self.mode = SessionMode.MANUAL - - def save_models(self) -> None: - """Save the RL models.""" - save_path = self.io_manager.generate_model_save_path("temp_model_name") - self.policy.save(save_path) - def step(self): """ Perform one step of the simulation/agent loop. @@ -210,7 +143,7 @@ class PrimaiteSession: def calculate_truncated(self) -> bool: """Calculate whether the episode is truncated.""" current_step = self.step_counter - max_steps = self.training_options.max_steps_per_episode + max_steps = self.options.max_episode_length if current_step >= max_steps: return True return False @@ -227,8 +160,8 @@ class PrimaiteSession: return NotImplemented @classmethod - def from_config(cls, cfg: dict, agent_load_path: Optional[str] = None) -> "PrimaiteSession": - """Create a PrimaiteSession object from a config dictionary. + def from_config(cls, cfg: Dict) -> "PrimaiteGame": + """Create a PrimaiteGame object from a config dictionary. The config dictionary should have the following top-level keys: 1. training_config: options for training the RL agent. @@ -243,23 +176,16 @@ class PrimaiteSession: :return: A PrimaiteSession object. :rtype: PrimaiteSession """ - sess = cls() - sess.options = PrimaiteSessionOptions( - ports=cfg["game_config"]["ports"], - protocols=cfg["game_config"]["protocols"], - ) - sess.training_options = TrainingOptions(**cfg["training_config"]) + game = cls() + game.options = PrimaiteGameOptions(cfg["game"]) - # READ IO SETTINGS (this sets the global session path as well) # TODO: GLOBAL SIDE EFFECTS... - io_settings = cfg.get("io_settings", {}) - sess.io_manager.settings = SessionIOSettings(**io_settings) - - sim = sess.simulation + # 1. create simulation + sim = game.simulation net = sim.network - sess.ref_map_nodes: Dict[str, Node] = {} - sess.ref_map_services: Dict[str, Service] = {} - sess.ref_map_links: Dict[str, Link] = {} + game.ref_map_nodes: Dict[str, Node] = {} + game.ref_map_services: Dict[str, Service] = {} + game.ref_map_links: Dict[str, Link] = {} nodes_cfg = cfg["simulation"]["network"]["nodes"] links_cfg = cfg["simulation"]["network"]["links"] @@ -323,7 +249,7 @@ class PrimaiteSession: print(f"installing {service_type} on node {new_node.hostname}") new_node.software_manager.install(service_types_mapping[service_type]) new_service = new_node.software_manager.software[service_type] - sess.ref_map_services[service_ref] = new_service + game.ref_map_services[service_ref] = new_service else: print(f"service type not found {service_type}") # service-dependent options @@ -348,7 +274,7 @@ class PrimaiteSession: if application_type in application_types_mapping: new_node.software_manager.install(application_types_mapping[application_type]) new_application = new_node.software_manager.software[application_type] - sess.ref_map_applications[application_ref] = new_application + game.ref_map_applications[application_ref] = new_application else: print(f"application type not found {application_type}") if "nics" in node_cfg: @@ -357,7 +283,7 @@ class PrimaiteSession: net.add_node(new_node) new_node.power_on() - sess.ref_map_nodes[ + game.ref_map_nodes[ node_ref ] = ( new_node.uuid @@ -365,8 +291,8 @@ class PrimaiteSession: # 2. create links between nodes for link_cfg in links_cfg: - node_a = net.nodes[sess.ref_map_nodes[link_cfg["endpoint_a_ref"]]] - node_b = net.nodes[sess.ref_map_nodes[link_cfg["endpoint_b_ref"]]] + node_a = net.nodes[game.ref_map_nodes[link_cfg["endpoint_a_ref"]]] + node_b = net.nodes[game.ref_map_nodes[link_cfg["endpoint_b_ref"]]] if isinstance(node_a, Switch): endpoint_a = node_a.switch_ports[link_cfg["endpoint_a_port"]] else: @@ -376,7 +302,7 @@ class PrimaiteSession: else: endpoint_b = node_b.ethernet_port[link_cfg["endpoint_b_port"]] new_link = net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b) - sess.ref_map_links[link_cfg["ref"]] = new_link.uuid + game.ref_map_links[link_cfg["ref"]] = new_link.uuid # 3. create agents game_cfg = cfg["game_config"] @@ -390,14 +316,14 @@ class PrimaiteSession: reward_function_cfg = agent_cfg["reward_function"] # CREATE OBSERVATION SPACE - obs_space = ObservationManager.from_config(observation_space_cfg, sess) + obs_space = ObservationManager.from_config(observation_space_cfg, game) # CREATE ACTION SPACE action_space_cfg["options"]["node_uuids"] = [] # if a list of nodes is defined, convert them from node references to node UUIDs for action_node_option in action_space_cfg.get("options", {}).pop("nodes", {}): if "node_ref" in action_node_option: - node_uuid = sess.ref_map_nodes[action_node_option["node_ref"]] + node_uuid = game.ref_map_nodes[action_node_option["node_ref"]] action_space_cfg["options"]["node_uuids"].append(node_uuid) # Each action space can potentially have a different list of nodes that it can apply to. Therefore, # we will pass node_uuids as a part of the action space config. @@ -409,12 +335,12 @@ class PrimaiteSession: if "options" in action_config: if "target_router_ref" in action_config["options"]: _target = action_config["options"]["target_router_ref"] - action_config["options"]["target_router_uuid"] = sess.ref_map_nodes[_target] + action_config["options"]["target_router_uuid"] = game.ref_map_nodes[_target] - action_space = ActionManager.from_config(sess, action_space_cfg) + action_space = ActionManager.from_config(game, action_space_cfg) # CREATE REWARD FUNCTION - rew_function = RewardFunction.from_config(reward_function_cfg, session=sess) + rew_function = RewardFunction.from_config(reward_function_cfg, session=game) # CREATE AGENT if agent_type == "GreenWebBrowsingAgent": @@ -425,7 +351,7 @@ class PrimaiteSession: observation_space=obs_space, reward_function=rew_function, ) - sess.agents.append(new_agent) + game.agents.append(new_agent) elif agent_type == "ProxyAgent": new_agent = ProxyAgent( agent_name=agent_cfg["ref"], @@ -433,8 +359,8 @@ class PrimaiteSession: observation_space=obs_space, reward_function=rew_function, ) - sess.agents.append(new_agent) - sess.rl_agents.append(new_agent) + game.agents.append(new_agent) + game.rl_agents.append(new_agent) elif agent_type == "RedDatabaseCorruptingAgent": new_agent = RandomAgent( agent_name=agent_cfg["ref"], @@ -442,16 +368,8 @@ class PrimaiteSession: observation_space=obs_space, reward_function=rew_function, ) - sess.agents.append(new_agent) + game.agents.append(new_agent) else: print("agent type not found") - # CREATE ENVIRONMENT - sess.env = PrimaiteGymEnv(session=sess, agents=sess.rl_agents) - - # CREATE POLICY - sess.policy = PolicyABC.from_config(sess.training_options, session=sess) - if agent_load_path: - sess.policy.load(Path(agent_load_path)) - - return sess + return game diff --git a/src/primaite/game/policy/policy.py b/src/primaite/game/policy/policy.py index 249c3b52..10af44b1 100644 --- a/src/primaite/game/policy/policy.py +++ b/src/primaite/game/policy/policy.py @@ -4,7 +4,7 @@ from pathlib import Path from typing import Any, Dict, Type, TYPE_CHECKING if TYPE_CHECKING: - from primaite.game.session import PrimaiteSession, TrainingOptions + from primaite.game.game import PrimaiteGame, TrainingOptions class PolicyABC(ABC): @@ -32,7 +32,7 @@ class PolicyABC(ABC): return @abstractmethod - def __init__(self, session: "PrimaiteSession") -> None: + def __init__(self, session: "PrimaiteGame") -> None: """ Initialize a reinforcement learning policy. @@ -41,7 +41,7 @@ class PolicyABC(ABC): :param agents: The agents to train. :type agents: List[RLAgent] """ - self.session: "PrimaiteSession" = session + self.session: "PrimaiteGame" = session """Reference to the session.""" @abstractmethod @@ -69,7 +69,7 @@ class PolicyABC(ABC): pass @classmethod - def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "PolicyABC": + def from_config(cls, config: "TrainingOptions", session: "PrimaiteGame") -> "PolicyABC": """ Create an RL policy from a config by calling the relevant subclass's from_config method. diff --git a/src/primaite/game/policy/rllib.py b/src/primaite/game/policy/rllib.py index 6e9e1096..7828ccc7 100644 --- a/src/primaite/game/policy/rllib.py +++ b/src/primaite/game/policy/rllib.py @@ -1,26 +1,23 @@ from pathlib import Path -from typing import Dict, List, Literal, Optional, SupportsFloat, Tuple, Type, TYPE_CHECKING, Union +from typing import Dict, Literal, Optional, SupportsFloat, Tuple, TYPE_CHECKING import gymnasium from gymnasium.core import ActType, ObsType -from primaite.game.environment import PrimaiteGymEnv from primaite.game.policy.policy import PolicyABC if TYPE_CHECKING: - from primaite.game.agent.interface import ProxyAgent - from primaite.game.session import PrimaiteSession, TrainingOptions + from primaite.game.game import PrimaiteGame + from primaite.session.session import TrainingOptions import ray -from ray.rllib.algorithms import Algorithm, ppo -from ray.rllib.algorithms.ppo import PPOConfig -from ray.tune.registry import register_env +from ray.rllib.algorithms import ppo class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): """Single agent RL policy using Ray RLLib.""" - def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): + def __init__(self, session: "PrimaiteGame", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): super().__init__(session=session) ray.init() @@ -71,21 +68,23 @@ class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: """Train the agent.""" - for ep in range(n_episodes): res = self._algo.train() print(f"Episode {ep} complete, reward: {res['episode_reward_mean']}") def eval(self, n_episodes: int, deterministic: bool) -> None: + """Evaluate the agent.""" raise NotImplementedError def save(self, save_path: Path) -> None: - raise NotImplementedError + """Save the policy to a file.""" + self._algo.save(save_path) def load(self, model_path: Path) -> None: + """Load policy parameters from a file.""" raise NotImplementedError @classmethod - def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "RaySingleAgentPolicy": + def from_config(cls, config: "TrainingOptions", session: "PrimaiteGame") -> "RaySingleAgentPolicy": """Create a policy from a config.""" return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/game/policy/sb3.py index a4870054..de14ed0c 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/game/policy/sb3.py @@ -11,13 +11,13 @@ from stable_baselines3.ppo import MlpPolicy as PPO_MLP from primaite.game.policy.policy import PolicyABC if TYPE_CHECKING: - from primaite.game.session import PrimaiteSession, TrainingOptions + from primaite.game.game import PrimaiteGame, TrainingOptions class SB3Policy(PolicyABC, identifier="SB3"): """Single agent RL policy using stable baselines 3.""" - def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): + def __init__(self, session: "PrimaiteGame", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): """Initialize a stable baselines 3 policy.""" super().__init__(session=session) @@ -75,6 +75,6 @@ class SB3Policy(PolicyABC, identifier="SB3"): self._agent = self._agent_class.load(model_path, env=self.session.env) @classmethod - def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "SB3Policy": + def from_config(cls, config: "TrainingOptions", session: "PrimaiteGame") -> "SB3Policy": """Create an agent from config file.""" return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) diff --git a/src/primaite/main.py b/src/primaite/main.py index 1699fe51..5bc76ca2 100644 --- a/src/primaite/main.py +++ b/src/primaite/main.py @@ -6,7 +6,7 @@ from typing import Optional, Union from primaite import getLogger from primaite.config.load import load -from primaite.game.session import PrimaiteSession +from primaite.game.game import PrimaiteGame # from primaite.primaite_session import PrimaiteSession @@ -32,7 +32,7 @@ def run( otherwise False. """ cfg = load(config_path) - sess = PrimaiteSession.from_config(cfg=cfg, agent_load_path=agent_load_path) + sess = PrimaiteGame.from_config(cfg=cfg, agent_load_path=agent_load_path) sess.start_session() diff --git a/src/primaite/notebooks/train_rllib_single_agent.ipynb b/src/primaite/notebooks/train_rllib_single_agent.ipynb new file mode 100644 index 00000000..3b608a52 --- /dev/null +++ b/src/primaite/notebooks/train_rllib_single_agent.ipynb @@ -0,0 +1,129 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/cade/repos/PrimAITE/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n", + "2023-11-18 09:06:45,876\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", + "2023-11-18 09:06:48,446\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", + "2023-11-18 09:06:48,692\tWARNING __init__.py:10 -- PG has/have been moved to `rllib_contrib` and will no longer be maintained by the RLlib team. You can still use it/them normally inside RLlib util Ray 2.8, but from Ray 2.9 on, all `rllib_contrib` algorithms will no longer be part of the core repo, and will therefore have to be installed separately with pinned dependencies for e.g. ray[rllib] and other packages! See https://github.com/ray-project/ray/tree/master/rllib_contrib#rllib-contrib for more information on the RLlib contrib effort.\n" + ] + } + ], + "source": [ + "from primaite.game.game import PrimaiteGame\n", + "from primaite.game.environment import PrimaiteGymEnv\n", + "import yaml" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.config.load import example_config_path" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "installing DNSServer on node domain_controller\n", + "installing DatabaseClient on node web_server\n", + "installing WebServer on node web_server\n", + "installing DatabaseService on node database_server\n", + "service type not found DatabaseBackup\n", + "installing DataManipulationBot on node client_1\n", + "installing DNSClient on node client_1\n", + "installing DNSClient on node client_2\n" + ] + } + ], + "source": [ + "with open(example_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + "\n", + "sess = PrimaiteGame.from_config(cfg)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "sess.env = PrimaiteGymEnv(session=sess, agents=sess.rl_agents)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "env = sess.env" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "env" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/primaite/session/__init__.py b/src/primaite/session/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/game/io.py b/src/primaite/session/io.py similarity index 100% rename from src/primaite/game/io.py rename to src/primaite/session/io.py diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py new file mode 100644 index 00000000..d7bc3f99 --- /dev/null +++ b/src/primaite/session/session.py @@ -0,0 +1,92 @@ +from enum import Enum +from typing import Dict, List, Literal, Optional + +from pydantic import BaseModel, ConfigDict + +from primaite.game.environment import PrimaiteGymEnv + +# from primaite.game.game import PrimaiteGame +from primaite.game.policy.policy import PolicyABC +from primaite.session.io import SessionIO, SessionIOSettings + + +class TrainingOptions(BaseModel): + """Options for training the RL agent.""" + + model_config = ConfigDict(extra="forbid") + + rl_framework: Literal["SB3", "RLLIB_single_agent"] + rl_algorithm: Literal["PPO", "A2C"] + n_learn_episodes: int + n_eval_episodes: Optional[int] = None + max_steps_per_episode: int + # checkpoint_freq: Optional[int] = None + deterministic_eval: bool + seed: Optional[int] + n_agents: int + agent_references: List[str] + + +class SessionMode(Enum): + """Helper to keep track of the current session mode.""" + + TRAIN = "train" + EVAL = "eval" + MANUAL = "manual" + + +class PrimaiteSession: + """The main entrypoint for PrimAITE sessions, this manages a simulation, policy training, and environments.""" + + def __init__(self): + """Initialise PrimaiteSession object.""" + self.training_options: TrainingOptions + """Options specific to agent training.""" + + self.mode: SessionMode = SessionMode.MANUAL + """Current session mode.""" + + self.env: PrimaiteGymEnv + """The environment that the agent can consume. Could be PrimaiteEnv.""" + + self.policy: PolicyABC + """The reinforcement learning policy.""" + + self.io_manager = SessionIO() + """IO manager for the session.""" + + def start_session(self) -> None: + """Commence the training/eval session.""" + self.mode = SessionMode.TRAIN + n_learn_episodes = self.training_options.n_learn_episodes + n_eval_episodes = self.training_options.n_eval_episodes + max_steps_per_episode = self.training_options.max_steps_per_episode + + deterministic_eval = self.training_options.deterministic_eval + self.policy.learn( + n_episodes=n_learn_episodes, + timesteps_per_episode=max_steps_per_episode, + ) + self.save_models() + + self.mode = SessionMode.EVAL + if n_eval_episodes > 0: + self.policy.eval(n_episodes=n_eval_episodes, deterministic=deterministic_eval) + + self.mode = SessionMode.MANUAL + + def save_models(self) -> None: + """Save the RL models.""" + save_path = self.io_manager.generate_model_save_path("temp_model_name") + self.policy.save(save_path) + + @classmethod + def from_config(cls, cfg: Dict, agent_load_path: Optional[str] = None) -> "PrimaiteSession": + """Create a PrimaiteSession object from a config dictionary.""" + sess = cls() + + sess.training_options = TrainingOptions(**cfg["training_config"]) + + # READ IO SETTINGS (this sets the global session path as well) # TODO: GLOBAL SIDE EFFECTS... + io_settings = cfg.get("io_settings", {}) + sess.io_manager.settings = SessionIOSettings(**io_settings) diff --git a/tests/conftest.py b/tests/conftest.py index 6a65b12f..24001ffc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,7 +11,7 @@ import pytest import yaml from primaite import getLogger -from primaite.game.session import PrimaiteSession +from primaite.game.game import PrimaiteGame # from primaite.environment.primaite_env import Primaite # from primaite.primaite_session import PrimaiteSession @@ -74,7 +74,7 @@ def file_system() -> FileSystem: # PrimAITE v2 stuff -class TempPrimaiteSession(PrimaiteSession): +class TempPrimaiteSession(PrimaiteGame): """ A temporary PrimaiteSession class. From 1138644a4b3f7ea3ceb5cc261687e7726dd770a4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 22 Nov 2023 12:59:33 +0000 Subject: [PATCH 337/980] Update to make things work with new layout --- .../config/_package_data/example_config.yaml | 993 +++++++++--------- src/primaite/game/environment.py | 26 +- src/primaite/game/game.py | 5 +- .../notebooks/train_rllib_single_agent.ipynb | 54 +- 4 files changed, 514 insertions(+), 564 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 443b0efe..f167dc2f 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -15,7 +15,8 @@ io_settings: checkpoint_interval: 5 -game_config: +game: + max_episode_length: 256 ports: - ARP - DNS @@ -26,523 +27,523 @@ game_config: - TCP - UDP - agents: - - ref: client_1_green_user - team: GREEN - type: GreenWebBrowsingAgent - observation_space: - type: UC2GreenObservation - action_space: - action_list: - - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com - options: - nodes: - - node_ref: client_2 - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 - reward_function: - reward_components: - - type: DUMMY + reward_function: + reward_components: + - type: DUMMY - agent_settings: - start_step: 5 - frequency: 4 - variance: 3 + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 - - ref: client_1_data_manipulation_red_bot - team: RED - type: RedDatabaseCorruptingAgent + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: - - node_ref: client_1 + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot observations: - - logon_status - - operating_status - services: - - service_ref: data_manipulation_bot - observations: - operating_status - health_status - folders: {} + operating_status + health_status + folders: {} - action_space: - action_list: - - type: DONOTHING - # Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: @@ -28,24 +26,24 @@ class PrimaiteGymEnv(gymnasium.Env): # make ProxyAgent store the action chosen my the RL policy self.agent.store_action(action) # apply_agent_actions accesses the action we just stored - self.session.apply_agent_actions() - self.session.advance_timestep() - state = self.session.get_sim_state() - self.session.update_agents(state) + self.game.apply_agent_actions() + self.game.advance_timestep() + state = self.game.get_sim_state() + self.game.update_agents(state) next_obs = self._get_obs() reward = self.agent.reward_function.current_reward terminated = False - truncated = self.session.calculate_truncated() + truncated = self.game.calculate_truncated() info = {} return next_obs, reward, terminated, truncated, info def reset(self, seed: Optional[int] = None) -> Tuple[ObsType, Dict[str, Any]]: """Reset the environment.""" - self.session.reset() - state = self.session.get_sim_state() - self.session.update_agents(state) + self.game.reset() + state = self.game.get_sim_state() + self.game.update_agents(state) next_obs = self._get_obs() info = {} return next_obs, info diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 7dd50924..e260285f 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -177,7 +177,7 @@ class PrimaiteGame: :rtype: PrimaiteSession """ game = cls() - game.options = PrimaiteGameOptions(cfg["game"]) + game.options = PrimaiteGameOptions(**cfg["game"]) # 1. create simulation sim = game.simulation @@ -305,8 +305,7 @@ class PrimaiteGame: game.ref_map_links[link_cfg["ref"]] = new_link.uuid # 3. create agents - game_cfg = cfg["game_config"] - agents_cfg = game_cfg["agents"] + agents_cfg = cfg["agents"] for agent_cfg in agents_cfg: agent_ref = agent_cfg["ref"] # noqa: F841 diff --git a/src/primaite/notebooks/train_rllib_single_agent.ipynb b/src/primaite/notebooks/train_rllib_single_agent.ipynb index 3b608a52..709e6e6f 100644 --- a/src/primaite/notebooks/train_rllib_single_agent.ipynb +++ b/src/primaite/notebooks/train_rllib_single_agent.ipynb @@ -4,19 +4,7 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/cade/repos/PrimAITE/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n", - "2023-11-18 09:06:45,876\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", - "2023-11-18 09:06:48,446\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", - "2023-11-18 09:06:48,692\tWARNING __init__.py:10 -- PG has/have been moved to `rllib_contrib` and will no longer be maintained by the RLlib team. You can still use it/them normally inside RLlib util Ray 2.8, but from Ray 2.9 on, all `rllib_contrib` algorithms will no longer be part of the core repo, and will therefore have to be installed separately with pinned dependencies for e.g. ray[rllib] and other packages! See https://github.com/ray-project/ray/tree/master/rllib_contrib#rllib-contrib for more information on the RLlib contrib effort.\n" - ] - } - ], + "outputs": [], "source": [ "from primaite.game.game import PrimaiteGame\n", "from primaite.game.environment import PrimaiteGymEnv\n", @@ -56,7 +44,7 @@ "with open(example_config_path(), 'r') as f:\n", " cfg = yaml.safe_load(f)\n", "\n", - "sess = PrimaiteGame.from_config(cfg)" + "game = PrimaiteGame.from_config(cfg)" ] }, { @@ -65,44 +53,8 @@ "metadata": {}, "outputs": [], "source": [ - "sess.env = PrimaiteGymEnv(session=sess, agents=sess.rl_agents)" + "gym = PrimaiteGymEnv(game=game, agents=game.rl_agents)" ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "env = sess.env" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "env" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From b81dd26b713f82d422b09bc666fc046626437760 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 22 Nov 2023 13:12:08 +0000 Subject: [PATCH 338/980] Add Ray env class --- src/primaite/game/environment.py | 24 ++++++++-- ...agent.ipynb => training_example_sb3.ipynb} | 47 +++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) rename src/primaite/notebooks/{train_rllib_single_agent.ipynb => training_example_sb3.ipynb} (68%) diff --git a/src/primaite/game/environment.py b/src/primaite/game/environment.py index 57846b99..d540bd02 100644 --- a/src/primaite/game/environment.py +++ b/src/primaite/game/environment.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Optional, SupportsFloat, Tuple +from typing import Any, Dict, Optional, SupportsFloat, Tuple import gymnasium from gymnasium.core import ActType, ObsType @@ -15,11 +15,11 @@ class PrimaiteGymEnv(gymnasium.Env): assumptions about the agent list always having a list of length 1. """ - def __init__(self, game: PrimaiteGame, agents: List[ProxyAgent]): + def __init__(self, game: PrimaiteGame): """Initialise the environment.""" super().__init__() self.game: "PrimaiteGame" = game - self.agent: ProxyAgent = agents[0] + self.agent: ProxyAgent = self.game.rl_agents[0] def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: """Perform a step in the environment.""" @@ -63,3 +63,21 @@ class PrimaiteGymEnv(gymnasium.Env): unflat_space = self.agent.observation_manager.space unflat_obs = self.agent.observation_manager.current_observation return gymnasium.spaces.flatten(unflat_space, unflat_obs) + + +class PrimaiteRayEnv(gymnasium.Env): + """Ray wrapper that accepts a single `env_config` parameter in init function for compatibility with Ray.""" + + def __init__(self, env_config: Dict) -> None: + """Initialise the environment.""" + self.env = PrimaiteGymEnv(game=env_config["game"]) + self.action_space = self.env.action_space + self.observation_space = self.env.observation_space + + def reset(self, *, seed: int = None, options: dict = None) -> Tuple[ObsType, Dict]: + """Reset the environment.""" + return self.env.reset(seed=seed) + + def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict]: + """Perform a step in the environment.""" + return self.env.step(action) diff --git a/src/primaite/notebooks/train_rllib_single_agent.ipynb b/src/primaite/notebooks/training_example_sb3.ipynb similarity index 68% rename from src/primaite/notebooks/train_rllib_single_agent.ipynb rename to src/primaite/notebooks/training_example_sb3.ipynb index 709e6e6f..e4033a79 100644 --- a/src/primaite/notebooks/train_rllib_single_agent.ipynb +++ b/src/primaite/notebooks/training_example_sb3.ipynb @@ -55,6 +55,53 @@ "source": [ "gym = PrimaiteGymEnv(game=game, agents=game.rl_agents)" ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "from stable_baselines3 import PPO" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "model = PPO('MlpPolicy', gym)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model.learn(total_timesteps=1000)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "model.save(\"deleteme\")" + ] } ], "metadata": { From 9070fb44d4451b36226bd48af6e10a8fe92d5dd6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 22 Nov 2023 13:26:29 +0000 Subject: [PATCH 339/980] Check that ray single agent training works --- src/primaite/game/environment.py | 9 +- .../training_example_ray_single_agent.ipynb | 129 ++++++++++++++++++ 2 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 src/primaite/notebooks/training_example_ray_single_agent.ipynb diff --git a/src/primaite/game/environment.py b/src/primaite/game/environment.py index d540bd02..8ddcb88a 100644 --- a/src/primaite/game/environment.py +++ b/src/primaite/game/environment.py @@ -68,8 +68,13 @@ class PrimaiteGymEnv(gymnasium.Env): class PrimaiteRayEnv(gymnasium.Env): """Ray wrapper that accepts a single `env_config` parameter in init function for compatibility with Ray.""" - def __init__(self, env_config: Dict) -> None: - """Initialise the environment.""" + def __init__(self, env_config: Dict[str, PrimaiteGame]) -> None: + """Initialise the environment. + + :param env_config: A dictionary containing the environment configuration. It must contain a single key, `game` + which is the PrimaiteGame instance. + :type env_config: Dict[str, PrimaiteGame] + """ self.env = PrimaiteGymEnv(game=env_config["game"]) self.action_space = self.env.action_space self.observation_space = self.env.observation_space diff --git a/src/primaite/notebooks/training_example_ray_single_agent.ipynb b/src/primaite/notebooks/training_example_ray_single_agent.ipynb new file mode 100644 index 00000000..f47722f5 --- /dev/null +++ b/src/primaite/notebooks/training_example_ray_single_agent.ipynb @@ -0,0 +1,129 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.game.game import PrimaiteGame\n", + "import yaml\n", + "from primaite.config.load import example_config_path\n", + "\n", + "from primaite.game.environment import PrimaiteRayEnv" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(example_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + "\n", + "game = PrimaiteGame.from_config(cfg)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gym = PrimaiteRayEnv({\"game\":game})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import ray\n", + "from ray.rllib.algorithms import ppo" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ray.shutdown()\n", + "ray.init()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "env_config = {\"game\":game}\n", + "config = {\n", + " \"env\" : PrimaiteRayEnv,\n", + " \"env_config\" : env_config,\n", + " \"disable_env_checking\": True,\n", + " \"num_rollout_workers\": 0,\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "algo = ppo.PPO(config=config)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for i in range(5):\n", + " result = algo.train()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "algo.save(\"temp/deleteme\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 3f76e095214a4fbf44e96cb5c05913250cb2c25a Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 22 Nov 2023 14:13:50 +0000 Subject: [PATCH 340/980] #2042: remove apply_timestep() return value --- .../simulator/system/services/ntp/ntp_client.py | 9 +++------ .../system/test_ntp_client_server.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index 81ec031c..51df5010 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -66,6 +66,7 @@ class NTPClient(Service): :return: True if successful, False otherwise. """ + self.ip_addr = payload.ntp_request.ntp_client self.sys_log.info(f"{self.name}: Sending NTP request {payload.ntp_request.ntp_client}") return super().send( @@ -92,10 +93,7 @@ class NTPClient(Service): _LOGGER.debug(f"{payload} is not a NTPPacket") return False if payload.ntp_reply.ntp_datetime: - self.sys_log.info( - f"{self.name}: Received time \ - update from NTP server{payload.ntp_reply.ntp_datetime}" - ) + self.sys_log.info(f"{self.name}: Received time update from NTP server{payload.ntp_reply.ntp_datetime}") self.time = payload.ntp_reply.ntp_datetime return True @@ -110,13 +108,12 @@ class NTPClient(Service): :param timestep: The current timestep number. (Amount of time since simulation episode began) :type timestep: int """ + self.sys_log.info(f"{self.name} apply_timestep: IP address: {self.ip_addr}") super().apply_timestep(timestep) if self.operating_state == ServiceOperatingState.RUNNING: # request time from server ntp_request = NTPRequest(ntp_client=self.ip_addr) ntp_server_packet = NTPPacket(ntp_request=ntp_request) self.send(payload=ntp_server_packet) - return True else: self.sys_log.debug(f"{self.name} ntp client not running") - return False diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index 48db0cbb..95394e84 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -1,4 +1,5 @@ from ipaddress import IPv4Address +from time import sleep import pytest @@ -61,11 +62,17 @@ def test_ntp_client_server(): assert ntp_server.receive(payload=ntp_packet) is True assert ntp_client.receive(payload=ntp_packet) is True assert ntp_client.time is not None - assert ntp_client.apply_timestep(1) is True + first_time = ntp_client.time + sleep(0.1) + ntp_client.apply_timestep(1) # Check time advances + ntp_server.receive(payload=ntp_packet) + ntp_client.receive(payload=ntp_packet) + second_time = ntp_client.time + assert first_time != second_time # Test ntp client behaviour when ntp server is unavailable. -@pytest.mark.skip(reason="NTP needs to know if underly node is RUNNING") +@pytest.mark.skip(reason="NTP needs to know if underlying node is RUNNING") def test_ntp_server_failure(): network = create_ntp_network() server: Server = network.get_node_by_hostname("ntp_server") From 006a37d2686a8f44c20a1291d50c70581c95b3f7 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 22 Nov 2023 14:40:44 +0000 Subject: [PATCH 341/980] #2042: extract code into request_time() method. --- .../simulator/system/services/ntp/ntp_client.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index 51df5010..38ef820b 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -93,10 +93,19 @@ class NTPClient(Service): _LOGGER.debug(f"{payload} is not a NTPPacket") return False if payload.ntp_reply.ntp_datetime: - self.sys_log.info(f"{self.name}: Received time update from NTP server{payload.ntp_reply.ntp_datetime}") + self.sys_log.info( + f"{self.name}: \ + Received time update from NTP server{payload.ntp_reply.ntp_datetime}" + ) self.time = payload.ntp_reply.ntp_datetime return True + def request_time(self) -> None: + """Send request to ntp_server.""" + ntp_request = NTPRequest(ntp_client=self.ip_addr) + ntp_server_packet = NTPPacket(ntp_request=ntp_request) + self.send(payload=ntp_server_packet) + def apply_timestep(self, timestep: int) -> None: """ For each timestep request the time from the NTP server. @@ -112,8 +121,6 @@ class NTPClient(Service): super().apply_timestep(timestep) if self.operating_state == ServiceOperatingState.RUNNING: # request time from server - ntp_request = NTPRequest(ntp_client=self.ip_addr) - ntp_server_packet = NTPPacket(ntp_request=ntp_request) - self.send(payload=ntp_server_packet) + self.request_time() else: self.sys_log.debug(f"{self.name} ntp client not running") From 061e5081871a7f9143769b545ca6de8a44f8c158 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Wed, 22 Nov 2023 16:24:17 +0000 Subject: [PATCH 342/980] Add repeat option to data manipulation bot --- .../red_services/data_manipulation_bot.py | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index 5e4e2d3f..eae3f0e3 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -38,13 +38,19 @@ class DataManipulationBot(DatabaseClient): server_password: Optional[str] = None attack_stage: DataManipulationAttackStage = DataManipulationAttackStage.NOT_STARTED execution_definition: AgentExecutionDefinition = AgentExecutionDefinition() + repeat: bool = False + "Whether to repeat attacking once finished." def __init__(self, **kwargs): super().__init__(**kwargs) self.name = "DataManipulationBot" def configure( - self, server_ip_address: IPv4Address, server_password: Optional[str] = None, payload: Optional[str] = None + self, + server_ip_address: IPv4Address, + server_password: Optional[str] = None, + payload: Optional[str] = None, + repeat: bool = False, ): """ Configure the DataManipulatorBot to communicate with a DatabaseService. @@ -52,12 +58,15 @@ class DataManipulationBot(DatabaseClient): :param server_ip_address: The IP address of the Node the DatabaseService is on. :param server_password: The password on the DatabaseService. :param payload: The data manipulation query payload. + :param repeat: Whether to repeat attacking once finished. """ self.server_ip_address = server_ip_address self.payload = payload self.server_password = server_password + self.repeat = repeat self.sys_log.info( - f"{self.name}: Configured the {self.name} with {server_ip_address=}, {payload=}, {server_password=}." + f"{self.name}: Configured the {self.name} with {server_ip_address=}, {payload=}, {server_password=}, " + f"{repeat=}." ) def _logon(self): @@ -100,7 +109,7 @@ class DataManipulationBot(DatabaseClient): if self.attack_stage == DataManipulationAttackStage.PORT_SCAN: # perform the actual data manipulation attack if simulate_trial(p_of_success): - self.sys_log.info(f"{self.name}: Performing port scan") + self.sys_log.info(f"{self.name}: Performing data manipulation") # perform the attack if not self.connected: self.connect() @@ -109,10 +118,10 @@ class DataManipulationBot(DatabaseClient): self.sys_log.info(f"{self.name} payload delivered: {self.payload}") attack_successful = True if attack_successful: - self.sys_log.info(f"{self.name}: Performing port scan") + self.sys_log.info(f"{self.name}: Data manipulation successful") self.attack_stage = DataManipulationAttackStage.COMPLETE else: - self.sys_log.info(f"{self.name}: Performing port scan") + self.sys_log.info(f"{self.name}: Data manipulation failed") self.attack_stage = DataManipulationAttackStage.FAILED def execute(self): @@ -137,6 +146,12 @@ class DataManipulationBot(DatabaseClient): self._logon() self._perform_port_scan(p_of_success=self.execution_definition.port_scan_p_of_success) self._perform_data_manipulation(p_of_success=self.execution_definition.data_manipulation_p_of_success) + + if self.repeat and self.attack_stage in ( + DataManipulationAttackStage.COMPLETE, + DataManipulationAttackStage.FAILED, + ): + self.attack_stage = DataManipulationAttackStage.NOT_STARTED else: self.sys_log.error(f"{self.name}: Failed to start as it requires both a target_ip_address and payload.") From 1fd5298fc56cf5b6b1f0cb155d8463bc1e25f145 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 22 Nov 2023 20:22:34 +0000 Subject: [PATCH 343/980] Fix multi agent system --- .../example_config_2_rl_agents.yaml | 1164 +++++++++++++++++ src/primaite/game/environment.py | 76 +- .../training_example_ray_multi_agent.ipynb | 127 ++ 3 files changed, 1366 insertions(+), 1 deletion(-) create mode 100644 src/primaite/config/_package_data/example_config_2_rl_agents.yaml create mode 100644 src/primaite/notebooks/training_example_ray_multi_agent.ipynb diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml new file mode 100644 index 00000000..9450c419 --- /dev/null +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -0,0 +1,1164 @@ +training_config: + rl_framework: RLLIB_single_agent + rl_algorithm: PPO + seed: 333 + n_learn_episodes: 1 + n_eval_episodes: 5 + max_steps_per_episode: 256 + deterministic_eval: false + n_agents: 1 + agent_references: + - defender + +io_settings: + save_checkpoints: true + checkpoint_interval: 5 + + +game: + max_episode_length: 256 + ports: + - ARP + - DNS + - HTTP + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + - UDP + +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com + + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 + + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot + observations: + operating_status + health_status + folders: {} + + action_space: + action_list: + - type: DONOTHING + # Tuple[ObsType, SupportsFloat, bool, bool, Dict]: """Perform a step in the environment.""" return self.env.step(action) + + +class PrimaiteRayMARLEnv(MultiAgentEnv): + """Ray Environment that inherits from MultiAgentEnv to allow training MARL systems.""" + + def __init__(self, env_config: Optional[Dict] = None) -> None: + """Initialise the environment. + + :param env_config: A dictionary containing the environment configuration. It must contain a single key, `game` + which is the PrimaiteGame instance. + :type env_config: Dict[str, PrimaiteGame] + """ + self.game: PrimaiteGame = env_config["game"] + """Reference to the primaite game""" + self.agents: Final[Dict[str, ProxyAgent]] = {agent.agent_name: agent for agent in self.game.rl_agents} + """List of all possible agents in the environment. This list should not change!""" + self._agent_ids = list(self.agents.keys()) + + self.terminateds = set() + self.truncateds = set() + self.observation_space = gymnasium.spaces.Dict( + {name: agent.observation_manager.space for name, agent in self.agents.items()} + ) + self.action_space = gymnasium.spaces.Dict( + {name: agent.action_manager.space for name, agent in self.agents.items()} + ) + super().__init__() + + def reset(self, *, seed: int = None, options: dict = None) -> Tuple[ObsType, Dict]: + """Reset the environment.""" + self.game.reset() + state = self.game.get_sim_state() + self.game.update_agents(state) + next_obs = self._get_obs() + info = {} + return next_obs, info + + def step( + self, actions: Dict[str, ActType] + ) -> Tuple[Dict[str, ObsType], Dict[str, SupportsFloat], Dict[str, bool], Dict[str, bool], Dict]: + """Perform a step in the environment. Adherent to Ray MultiAgentEnv step API. + + :param actions: Dict of actions. The key is agent identifier and the value is a gymnasium action instance. + :type actions: Dict[str, ActType] + :return: Observations, rewards, terminateds, truncateds, and info. Each one is a dictionary keyed by agent + identifier. + :rtype: Tuple[Dict[str,ObsType], Dict[str, SupportsFloat], Dict[str,bool], Dict[str,bool], Dict] + """ + # 1. Perform actions + for agent_name, action in actions.items(): + self.agents[agent_name].store_action(action) + self.game.apply_agent_actions() + + # 2. Advance timestep + self.game.advance_timestep() + + # 3. Get next observations + state = self.game.get_sim_state() + self.game.update_agents(state) + next_obs = self._get_obs() + + # 4. Get rewards + rewards = {name: agent.reward_function.current_reward for name, agent in self.agents.items()} + terminateds = {name: False for name, _ in self.agents.items()} + truncateds = {name: self.game.calculate_truncated() for name, _ in self.agents.items()} + infos = {} + terminateds["__all__"] = len(self.terminateds) == len(self.agents) + truncateds["__all__"] = self.game.calculate_truncated() + return next_obs, rewards, terminateds, truncateds, infos + + def _get_obs(self) -> Dict[str, ObsType]: + """Return the current observation.""" + return {name: agent.observation_manager.current_observation for name, agent in self.agents.items()} diff --git a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb new file mode 100644 index 00000000..9f916af9 --- /dev/null +++ b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb @@ -0,0 +1,127 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.game.game import PrimaiteGame\n", + "import yaml\n", + "from primaite.config.load import example_config_path\n", + "\n", + "from primaite.game.environment import PrimaiteRayEnv" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(example_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + "\n", + "game = PrimaiteGame.from_config(cfg)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# gym = PrimaiteRayEnv({\"game\":game})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import ray\n", + "from ray import air, tune\n", + "from ray.rllib.algorithms.ppo import PPOConfig" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ray.shutdown()\n", + "ray.init()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.game.environment import PrimaiteRayMARLEnv\n", + "\n", + "\n", + "env_config = {\"game\":game}\n", + "config = (\n", + " PPOConfig()\n", + " .environment(env=PrimaiteRayMARLEnv, env_config={\"game\":game})\n", + " .rollouts(num_rollout_workers=0)\n", + " .multi_agent(\n", + " policies={agent.agent_name for agent in game.rl_agents},\n", + " policy_mapping_fn=lambda agent_id, episode, worker, **kw: agent_id,\n", + " )\n", + " .training(train_batch_size=128)\n", + " )\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tune.Tuner(\n", + " \"PPO\",\n", + " run_config=air.RunConfig(\n", + " stop={\"training_iteration\": 128},\n", + " checkpoint_config=air.CheckpointConfig(\n", + " checkpoint_frequency=10,\n", + " ),\n", + " ),\n", + " param_space=config\n", + ").fit()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 14ae8be5e2705a17e9cff45560499ae0c1fa6706 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 23 Nov 2023 00:54:19 +0000 Subject: [PATCH 344/980] Update session after it was split from game --- src/primaite/game/policy/policy.py | 10 ++- src/primaite/game/policy/rllib.py | 66 +++++-------------- src/primaite/game/policy/sb3.py | 6 +- src/primaite/main.py | 10 +-- .../training_example_ray_multi_agent.ipynb | 4 +- .../training_example_ray_single_agent.ipynb | 8 ++- .../notebooks/training_example_sb3.ipynb | 50 ++++---------- src/primaite/{game => session}/environment.py | 0 src/primaite/session/session.py | 35 ++++++++-- 9 files changed, 76 insertions(+), 113 deletions(-) rename src/primaite/{game => session}/environment.py (100%) diff --git a/src/primaite/game/policy/policy.py b/src/primaite/game/policy/policy.py index 10af44b1..984466d1 100644 --- a/src/primaite/game/policy/policy.py +++ b/src/primaite/game/policy/policy.py @@ -4,7 +4,7 @@ from pathlib import Path from typing import Any, Dict, Type, TYPE_CHECKING if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame, TrainingOptions + from primaite.session.session import PrimaiteSession, TrainingOptions class PolicyABC(ABC): @@ -32,7 +32,7 @@ class PolicyABC(ABC): return @abstractmethod - def __init__(self, session: "PrimaiteGame") -> None: + def __init__(self, session: "PrimaiteSession") -> None: """ Initialize a reinforcement learning policy. @@ -41,7 +41,7 @@ class PolicyABC(ABC): :param agents: The agents to train. :type agents: List[RLAgent] """ - self.session: "PrimaiteGame" = session + self.session: "PrimaiteSession" = session """Reference to the session.""" @abstractmethod @@ -69,7 +69,7 @@ class PolicyABC(ABC): pass @classmethod - def from_config(cls, config: "TrainingOptions", session: "PrimaiteGame") -> "PolicyABC": + def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "PolicyABC": """ Create an RL policy from a config by calling the relevant subclass's from_config method. @@ -80,5 +80,3 @@ class PolicyABC(ABC): PolicyType = cls._registry[config.rl_framework] return PolicyType.from_config(config=config, session=session) - - # saving checkpoints logic will be handled here, it will invoke 'save' method which is implemented by the subclass diff --git a/src/primaite/game/policy/rllib.py b/src/primaite/game/policy/rllib.py index 7828ccc7..f45b9fd6 100644 --- a/src/primaite/game/policy/rllib.py +++ b/src/primaite/game/policy/rllib.py @@ -1,14 +1,11 @@ from pathlib import Path -from typing import Dict, Literal, Optional, SupportsFloat, Tuple, TYPE_CHECKING - -import gymnasium -from gymnasium.core import ActType, ObsType +from typing import Literal, Optional, TYPE_CHECKING from primaite.game.policy.policy import PolicyABC +from primaite.session.environment import PrimaiteRayEnv if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame - from primaite.session.session import TrainingOptions + from primaite.session.session import PrimaiteSession, TrainingOptions import ray from ray.rllib.algorithms import ppo @@ -17,64 +14,33 @@ from ray.rllib.algorithms import ppo class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): """Single agent RL policy using Ray RLLib.""" - def __init__(self, session: "PrimaiteGame", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): + def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): super().__init__(session=session) - ray.init() - - class RayPrimaiteGym(gymnasium.Env): - def __init__(self, env_config: Dict) -> None: - self.action_space = session.env.action_space - self.observation_space = session.env.observation_space - - def reset(self, *, seed: int = None, options: dict = None) -> Tuple[ObsType, Dict]: - obs, info = session.env.reset() - return obs, info - - def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict]: - obs, reward, terminated, truncated, info = session.env.step(action) - return obs, reward, terminated, truncated, info - - ray.shutdown() - ray.init() config = { - "env": RayPrimaiteGym, - "env_config": {}, + "env": PrimaiteRayEnv, + "env_config": {"game": session.game}, "disable_env_checking": True, "num_rollout_workers": 0, } + ray.shutdown() + ray.init() + self._algo = ppo.PPO(config=config) - # self._agent_config = (PPOConfig() - # .update_from_dict({ - # "num_gpus":0, - # "num_workers":0, - # "batch_mode":"complete_episodes", - # "framework":"torch", - # }) - # .environment( - # env="primaite", - # env_config={"session": session, "agents": session.rl_agents,}, - # # disable_env_checking=True - # ) - # # .rollouts(num_rollout_workers=0, - # # num_envs_per_worker=0) - # # .framework("tf2") - # .evaluation(evaluation_num_workers=0) - # ) - - # self._agent:Algorithm = self._agent_config.build(use_copy=False) - def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: """Train the agent.""" for ep in range(n_episodes): - res = self._algo.train() - print(f"Episode {ep} complete, reward: {res['episode_reward_mean']}") + self._algo.train() def eval(self, n_episodes: int, deterministic: bool) -> None: """Evaluate the agent.""" - raise NotImplementedError + for ep in range(n_episodes): + obs, info = self.session.env.reset() + for step in range(self.session.game.options.max_episode_length): + action = self._algo.compute_single_action(observation=obs, explore=False) + obs, rew, term, trunc, info = self.session.env.step(action) def save(self, save_path: Path) -> None: """Save the policy to a file.""" @@ -85,6 +51,6 @@ class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): raise NotImplementedError @classmethod - def from_config(cls, config: "TrainingOptions", session: "PrimaiteGame") -> "RaySingleAgentPolicy": + def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "RaySingleAgentPolicy": """Create a policy from a config.""" return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/game/policy/sb3.py index de14ed0c..64eebfc7 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/game/policy/sb3.py @@ -11,13 +11,13 @@ from stable_baselines3.ppo import MlpPolicy as PPO_MLP from primaite.game.policy.policy import PolicyABC if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame, TrainingOptions + from primaite.session.session import PrimaiteSession, TrainingOptions class SB3Policy(PolicyABC, identifier="SB3"): """Single agent RL policy using stable baselines 3.""" - def __init__(self, session: "PrimaiteGame", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): + def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): """Initialize a stable baselines 3 policy.""" super().__init__(session=session) @@ -75,6 +75,6 @@ class SB3Policy(PolicyABC, identifier="SB3"): self._agent = self._agent_class.load(model_path, env=self.session.env) @classmethod - def from_config(cls, config: "TrainingOptions", session: "PrimaiteGame") -> "SB3Policy": + def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "SB3Policy": """Create an agent from config file.""" return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) diff --git a/src/primaite/main.py b/src/primaite/main.py index 5bc76ca2..b63227a7 100644 --- a/src/primaite/main.py +++ b/src/primaite/main.py @@ -5,8 +5,8 @@ from pathlib import Path from typing import Optional, Union from primaite import getLogger -from primaite.config.load import load -from primaite.game.game import PrimaiteGame +from primaite.config.load import example_config_path, load +from primaite.session.session import PrimaiteSession # from primaite.primaite_session import PrimaiteSession @@ -32,7 +32,7 @@ def run( otherwise False. """ cfg = load(config_path) - sess = PrimaiteGame.from_config(cfg=cfg, agent_load_path=agent_load_path) + sess = PrimaiteSession.from_config(cfg=cfg, agent_load_path=agent_load_path) sess.start_session() @@ -42,6 +42,6 @@ if __name__ == "__main__": args = parser.parse_args() if not args.config: - _LOGGER.error("Please provide a config file using the --config " "argument") + args.config = example_config_path() - run(session_path=args.config) + run(args.config) diff --git a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb index 9f916af9..d31d53cc 100644 --- a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb @@ -10,7 +10,7 @@ "import yaml\n", "from primaite.config.load import example_config_path\n", "\n", - "from primaite.game.environment import PrimaiteRayEnv" + "from primaite.session.environment import PrimaiteRayEnv" ] }, { @@ -61,7 +61,7 @@ "metadata": {}, "outputs": [], "source": [ - "from primaite.game.environment import PrimaiteRayMARLEnv\n", + "from primaite.session.environment import PrimaiteRayMARLEnv\n", "\n", "\n", "env_config = {\"game\":game}\n", diff --git a/src/primaite/notebooks/training_example_ray_single_agent.ipynb b/src/primaite/notebooks/training_example_ray_single_agent.ipynb index f47722f5..9b935346 100644 --- a/src/primaite/notebooks/training_example_ray_single_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_single_agent.ipynb @@ -10,7 +10,7 @@ "import yaml\n", "from primaite.config.load import example_config_path\n", "\n", - "from primaite.game.environment import PrimaiteRayEnv" + "from primaite.session.environment import PrimaiteRayEnv" ] }, { @@ -102,7 +102,11 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "from primaite.config.load import example_config_path\n", + "from primaite.main import run\n", + "run(example_config_path())" + ] } ], "metadata": { diff --git a/src/primaite/notebooks/training_example_sb3.ipynb b/src/primaite/notebooks/training_example_sb3.ipynb index e4033a79..e5085c5e 100644 --- a/src/primaite/notebooks/training_example_sb3.ipynb +++ b/src/primaite/notebooks/training_example_sb3.ipynb @@ -2,18 +2,18 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from primaite.game.game import PrimaiteGame\n", - "from primaite.game.environment import PrimaiteGymEnv\n", + "from primaite.session.environment import PrimaiteGymEnv\n", "import yaml" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -22,24 +22,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "installing DNSServer on node domain_controller\n", - "installing DatabaseClient on node web_server\n", - "installing WebServer on node web_server\n", - "installing DatabaseService on node database_server\n", - "service type not found DatabaseBackup\n", - "installing DataManipulationBot on node client_1\n", - "installing DNSClient on node client_1\n", - "installing DNSClient on node client_2\n" - ] - } - ], + "outputs": [], "source": [ "with open(example_config_path(), 'r') as f:\n", " cfg = yaml.safe_load(f)\n", @@ -49,16 +34,16 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "gym = PrimaiteGymEnv(game=game, agents=game.rl_agents)" + "gym = PrimaiteGymEnv(game=game)" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -67,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -76,27 +61,16 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "model.learn(total_timesteps=1000)\n" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ diff --git a/src/primaite/game/environment.py b/src/primaite/session/environment.py similarity index 100% rename from src/primaite/game/environment.py rename to src/primaite/session/environment.py diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py index d7bc3f99..9f567a95 100644 --- a/src/primaite/session/session.py +++ b/src/primaite/session/session.py @@ -1,12 +1,14 @@ from enum import Enum -from typing import Dict, List, Literal, Optional +from pathlib import Path +from typing import Dict, List, Literal, Optional, Union from pydantic import BaseModel, ConfigDict -from primaite.game.environment import PrimaiteGymEnv +from primaite.game.game import PrimaiteGame # from primaite.game.game import PrimaiteGame from primaite.game.policy.policy import PolicyABC +from primaite.session.environment import PrimaiteGymEnv, PrimaiteRayEnv, PrimaiteRayMARLEnv from primaite.session.io import SessionIO, SessionIOSettings @@ -15,7 +17,7 @@ class TrainingOptions(BaseModel): model_config = ConfigDict(extra="forbid") - rl_framework: Literal["SB3", "RLLIB_single_agent"] + rl_framework: Literal["SB3", "RLLIB_single_agent", "RLLIB_multi_agent"] rl_algorithm: Literal["PPO", "A2C"] n_learn_episodes: int n_eval_episodes: Optional[int] = None @@ -38,7 +40,7 @@ class SessionMode(Enum): class PrimaiteSession: """The main entrypoint for PrimAITE sessions, this manages a simulation, policy training, and environments.""" - def __init__(self): + def __init__(self, game: PrimaiteGame): """Initialise PrimaiteSession object.""" self.training_options: TrainingOptions """Options specific to agent training.""" @@ -46,8 +48,8 @@ class PrimaiteSession: self.mode: SessionMode = SessionMode.MANUAL """Current session mode.""" - self.env: PrimaiteGymEnv - """The environment that the agent can consume. Could be PrimaiteEnv.""" + self.env: Union[PrimaiteGymEnv, PrimaiteRayEnv, PrimaiteRayMARLEnv] + """The environment that the RL algorithm can consume.""" self.policy: PolicyABC """The reinforcement learning policy.""" @@ -55,6 +57,9 @@ class PrimaiteSession: self.io_manager = SessionIO() """IO manager for the session.""" + self.game: PrimaiteGame = game + """Primaite Game object for managing main simulation loop and agents.""" + def start_session(self) -> None: """Commence the training/eval session.""" self.mode = SessionMode.TRAIN @@ -83,10 +88,26 @@ class PrimaiteSession: @classmethod def from_config(cls, cfg: Dict, agent_load_path: Optional[str] = None) -> "PrimaiteSession": """Create a PrimaiteSession object from a config dictionary.""" - sess = cls() + game = PrimaiteGame.from_config(cfg) + + sess = cls(game=game) sess.training_options = TrainingOptions(**cfg["training_config"]) # READ IO SETTINGS (this sets the global session path as well) # TODO: GLOBAL SIDE EFFECTS... io_settings = cfg.get("io_settings", {}) sess.io_manager.settings = SessionIOSettings(**io_settings) + + # CREATE ENVIRONMENT + if sess.training_options.rl_framework == "RLLIB_single_agent": + sess.env = PrimaiteRayEnv(env_config={"game": game}) + elif sess.training_options.rl_framework == "RLLIB_multi_agent": + sess.env = PrimaiteRayMARLEnv(env_config={"game": game}) + elif sess.training_options.rl_framework == "SB3": + sess.env = PrimaiteGymEnv(game=game) + + sess.policy = PolicyABC.from_config(sess.training_options, session=sess) + if agent_load_path: + sess.policy.load(Path(agent_load_path)) + + return sess From 8a2279c6cb2de3638abba30f259e5111c9d3bbee Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 23 Nov 2023 01:40:27 +0000 Subject: [PATCH 345/980] Update end to end tests after session changes --- .../training_example_ray_single_agent.ipynb | 11 - .../assets/configs/bad_primaite_session.yaml | 992 +++++++++--------- .../configs/eval_only_primaite_session.yaml | 992 +++++++++--------- .../assets/configs/test_primaite_session.yaml | 992 +++++++++--------- .../configs/train_only_primaite_session.yaml | 992 +++++++++--------- tests/conftest.py | 3 +- .../test_rllib_multi_agent_environment.py | 43 + .../test_rllib_single_agent_environment.py | 38 + .../environments/test_sb3_environment.py | 27 + .../test_primaite_session.py | 10 +- 10 files changed, 2099 insertions(+), 2001 deletions(-) create mode 100644 tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py create mode 100644 tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py create mode 100644 tests/e2e_integration_tests/environments/test_sb3_environment.py diff --git a/src/primaite/notebooks/training_example_ray_single_agent.ipynb b/src/primaite/notebooks/training_example_ray_single_agent.ipynb index 9b935346..8ee16d41 100644 --- a/src/primaite/notebooks/training_example_ray_single_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_single_agent.ipynb @@ -96,17 +96,6 @@ "source": [ "algo.save(\"temp/deleteme\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from primaite.config.load import example_config_path\n", - "from primaite.main import run\n", - "run(example_config_path())" - ] } ], "metadata": { diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 80567aea..b5e43ab3 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -7,7 +7,7 @@ training_config: -game_config: +game: ports: - ARP - DNS @@ -18,523 +18,523 @@ game_config: - TCP - UDP - agents: - - ref: client_1_green_user - team: GREEN - type: GreenWebBrowsingAgent - observation_space: - type: UC2GreenObservation - action_space: - action_list: - - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com - options: - nodes: - - node_ref: client_2 - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 - reward_function: - reward_components: - - type: DUMMY + reward_function: + reward_components: + - type: DUMMY - agent_settings: - start_step: 5 - frequency: 4 - variance: 3 + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 - - ref: client_1_data_manipulation_red_bot - team: RED - type: RedDatabaseCorruptingAgent + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: - - node_ref: client_1 + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot observations: - - logon_status - - operating_status - services: - - service_ref: data_manipulation_bot - observations: - operating_status - health_status - folders: {} + operating_status + health_status + folders: {} - action_space: - action_list: - - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com - options: - nodes: - - node_ref: client_2 - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 - reward_function: - reward_components: - - type: DUMMY + reward_function: + reward_components: + - type: DUMMY - agent_settings: - start_step: 5 - frequency: 4 - variance: 3 + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 - - ref: client_1_data_manipulation_red_bot - team: RED - type: RedDatabaseCorruptingAgent + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: - - node_ref: client_1 + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot observations: - - logon_status - - operating_status - services: - - service_ref: data_manipulation_bot - observations: - operating_status - health_status - folders: {} + operating_status + health_status + folders: {} - action_space: - action_list: - - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com - options: - nodes: - - node_ref: client_2 - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 - reward_function: - reward_components: - - type: DUMMY + reward_function: + reward_components: + - type: DUMMY - agent_settings: - start_step: 5 - frequency: 4 - variance: 3 + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 - - ref: client_1_data_manipulation_red_bot - team: RED - type: RedDatabaseCorruptingAgent + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: - - node_ref: client_1 + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot observations: - - logon_status - - operating_status - services: - - service_ref: data_manipulation_bot - observations: - operating_status - health_status - folders: {} + operating_status + health_status + folders: {} - action_space: - action_list: - - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com - options: - nodes: - - node_ref: client_2 - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 - reward_function: - reward_components: - - type: DUMMY + reward_function: + reward_components: + - type: DUMMY - agent_settings: - start_step: 5 - frequency: 4 - variance: 3 + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 - - ref: client_1_data_manipulation_red_bot - team: RED - type: RedDatabaseCorruptingAgent + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: - - node_ref: client_1 + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot observations: - - logon_status - - operating_status - services: - - service_ref: data_manipulation_bot - observations: - operating_status - health_status - folders: {} + operating_status + health_status + folders: {} - action_space: - action_list: - - type: DONOTHING - # FileSystem: # PrimAITE v2 stuff -class TempPrimaiteSession(PrimaiteGame): +class TempPrimaiteSession(PrimaiteSession): """ A temporary PrimaiteSession class. diff --git a/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py b/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py new file mode 100644 index 00000000..0cf245b4 --- /dev/null +++ b/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py @@ -0,0 +1,43 @@ +import ray +import yaml +from ray import air, tune +from ray.rllib.algorithms.ppo import PPOConfig + +from primaite.config.load import example_config_path +from primaite.game.game import PrimaiteGame +from primaite.session.environment import PrimaiteRayMARLEnv + + +def test_rllib_multi_agent_compatibility(): + """Test that the PrimaiteRayEnv class can be used with a multi agent RLLIB system.""" + + with open(example_config_path(), "r") as f: + cfg = yaml.safe_load(f) + + game = PrimaiteGame.from_config(cfg) + + ray.shutdown() + ray.init() + + env_config = {"game": game} + config = ( + PPOConfig() + .environment(env=PrimaiteRayMARLEnv, env_config={"game": game}) + .rollouts(num_rollout_workers=0) + .multi_agent( + policies={agent.agent_name for agent in game.rl_agents}, + policy_mapping_fn=lambda agent_id, episode, worker, **kw: agent_id, + ) + .training(train_batch_size=128) + ) + + tune.Tuner( + "PPO", + run_config=air.RunConfig( + stop={"training_iteration": 128}, + checkpoint_config=air.CheckpointConfig( + checkpoint_frequency=10, + ), + ), + param_space=config, + ).fit() diff --git a/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py b/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py new file mode 100644 index 00000000..ce23501a --- /dev/null +++ b/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py @@ -0,0 +1,38 @@ +import tempfile +from pathlib import Path + +import ray +import yaml +from ray.rllib.algorithms import ppo + +from primaite.config.load import example_config_path +from primaite.game.game import PrimaiteGame +from primaite.session.environment import PrimaiteRayEnv + + +def test_rllib_single_agent_compatibility(): + """Test that the PrimaiteRayEnv class can be used with a single agent RLLIB system.""" + with open(example_config_path(), "r") as f: + cfg = yaml.safe_load(f) + + game = PrimaiteGame.from_config(cfg) + + ray.shutdown() + ray.init() + + env_config = {"game": game} + config = { + "env": PrimaiteRayEnv, + "env_config": env_config, + "disable_env_checking": True, + "num_rollout_workers": 0, + } + + algo = ppo.PPO(config=config) + + for i in range(5): + result = algo.train() + + save_file = Path(tempfile.gettempdir()) / "ray/" + algo.save(save_file) + assert save_file.exists() diff --git a/tests/e2e_integration_tests/environments/test_sb3_environment.py b/tests/e2e_integration_tests/environments/test_sb3_environment.py new file mode 100644 index 00000000..3907ff50 --- /dev/null +++ b/tests/e2e_integration_tests/environments/test_sb3_environment.py @@ -0,0 +1,27 @@ +"""Test that we can create a primaite environment and train sb3 agent with no crash.""" +import tempfile +from pathlib import Path + +import yaml +from stable_baselines3 import PPO + +from primaite.config.load import example_config_path +from primaite.game.game import PrimaiteGame +from primaite.session.environment import PrimaiteGymEnv + + +def test_sb3_compatibility(): + """Test that the Gymnasium environment can be used with an SB3 agent.""" + with open(example_config_path(), "r") as f: + cfg = yaml.safe_load(f) + + game = PrimaiteGame.from_config(cfg) + gym = PrimaiteGymEnv(game=game) + model = PPO("MlpPolicy", gym) + + model.learn(total_timesteps=1000) + + save_path = Path(tempfile.gettempdir()) / "model.zip" + model.save(save_path) + + assert (save_path).exists() diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index b6122bad..68672b51 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -18,15 +18,15 @@ class TestPrimaiteSession: raise AssertionError assert session is not None - assert session.simulation - assert len(session.agents) == 3 - assert len(session.rl_agents) == 1 + assert session.game.simulation + assert len(session.game.agents) == 3 + assert len(session.game.rl_agents) == 1 assert session.policy assert session.env - assert session.simulation.network - assert len(session.simulation.network.nodes) == 10 + assert session.game.simulation.network + assert len(session.game.simulation.network.nodes) == 10 @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) def test_start_session(self, temp_primaite_session): From f1f516c51a4c842d10eb82ec81fc61c38e075bdd Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 23 Nov 2023 02:51:31 +0000 Subject: [PATCH 346/980] Add multi agent session test --- src/primaite/game/policy/rllib.py | 51 +- tests/assets/configs/multi_agent_session.yaml | 1166 +++++++++++++++++ .../test_primaite_session.py | 7 + 3 files changed, 1223 insertions(+), 1 deletion(-) create mode 100644 tests/assets/configs/multi_agent_session.yaml diff --git a/src/primaite/game/policy/rllib.py b/src/primaite/game/policy/rllib.py index f45b9fd6..fcebf40d 100644 --- a/src/primaite/game/policy/rllib.py +++ b/src/primaite/game/policy/rllib.py @@ -2,13 +2,15 @@ from pathlib import Path from typing import Literal, Optional, TYPE_CHECKING from primaite.game.policy.policy import PolicyABC -from primaite.session.environment import PrimaiteRayEnv +from primaite.session.environment import PrimaiteRayEnv, PrimaiteRayMARLEnv if TYPE_CHECKING: from primaite.session.session import PrimaiteSession, TrainingOptions import ray +from ray import air, tune from ray.rllib.algorithms import ppo +from ray.rllib.algorithms.ppo import PPOConfig class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): @@ -54,3 +56,50 @@ class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "RaySingleAgentPolicy": """Create a policy from a config.""" return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) + + +class RayMultiAgentPolicy(PolicyABC, identifier="RLLIB_multi_agent"): + """Mutli agent RL policy using Ray RLLib.""" + + def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO"], seed: Optional[int] = None): + """Initialise multi agent policy wrapper.""" + super().__init__(session=session) + + self.config = ( + PPOConfig() + .environment(env=PrimaiteRayMARLEnv, env_config={"game": session.game}) + .rollouts(num_rollout_workers=0) + .multi_agent( + policies={agent.agent_name for agent in session.game.rl_agents}, + policy_mapping_fn=lambda agent_id, episode, worker, **kw: agent_id, + ) + .training(train_batch_size=128) + ) + + def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: + """Train the agent.""" + tune.Tuner( + "PPO", + run_config=air.RunConfig( + stop={"training_iteration": n_episodes * timesteps_per_episode}, + checkpoint_config=air.CheckpointConfig(checkpoint_frequency=10), + ), + param_space=self.config, + ).fit() + + def load(self, model_path: Path) -> None: + """Load policy paramters from a file.""" + return NotImplemented + + def eval(self, n_episodes: int, deterministic: bool) -> None: + """Evaluate trained policy.""" + return NotImplemented + + def save(self, save_path: Path) -> None: + """Save policy parameters to a file.""" + return NotImplemented + + @classmethod + def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "RayMultiAgentPolicy": + """Create policy from config.""" + return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml new file mode 100644 index 00000000..9d71e093 --- /dev/null +++ b/tests/assets/configs/multi_agent_session.yaml @@ -0,0 +1,1166 @@ +training_config: + rl_framework: RLLIB_multi_agent + rl_algorithm: PPO + seed: 333 + n_learn_episodes: 2 + n_eval_episodes: 1 + max_steps_per_episode: 128 + deterministic_eval: false + n_agents: 1 + agent_references: #not used :( + - defender1 + - defender2 + +io_settings: + save_checkpoints: true + checkpoint_interval: 5 + + +game: + max_episode_length: 128 + ports: + - ARP + - DNS + - HTTP + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + - UDP + +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com + + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 + + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot + observations: + operating_status + health_status + folders: {} + + action_space: + action_list: + - type: DONOTHING + # Date: Thu, 23 Nov 2023 03:07:39 +0000 Subject: [PATCH 347/980] Update doc page on primaite session. --- docs/source/primaite_session.rst | 215 +++---------------------------- 1 file changed, 18 insertions(+), 197 deletions(-) diff --git a/docs/source/primaite_session.rst b/docs/source/primaite_session.rst index 472a361f..a0b53c7d 100644 --- a/docs/source/primaite_session.rst +++ b/docs/source/primaite_session.rst @@ -7,207 +7,28 @@ Run a PrimAITE Session ====================== +``PrimaiteSession`` allows the user to train or evaluate an RL agent on the primaite simulation with just a config file, +no code required. It manages the lifecycle of a training or evaluation session, including the setup of the environment, +policy, simulator, agents, and IO. + +If you want finer control over the RL policy, you can interface with the :py:module::`primaite.session.environment` +module directly without running a session. + + + Run --- -A PrimAITE session can be ran either with the ``primaite session`` command from the cli +A PrimAITE session can started either with the ``primaite session`` command from the cli (See :func:`primaite.cli.session`), or by calling :func:`primaite.main.run` from a Python terminal or Jupyter Notebook. -Both the ``primaite session`` and :func:`primaite.main.run` take a training config and a lay down config as parameters. -.. note:: - 🚧 *UNDER CONSTRUCTION* 🚧 +There are two parameters that can be specified: + - ``--config``: The path to the config file to use. If not specified, the default config file is used. + - ``--agent-load-file``: The path to the pre-trained agent to load. If not specified, a new agent is created. -.. - .. code-block:: bash - :caption: Unix CLI +Outputs +------- - cd ~/primaite/2.0.0 - source ./.venv/bin/activate - primaite session --tc ./config/my_training_config.yaml --ldc ./config/my_lay_down_config.yaml - - .. code-block:: powershell - :caption: Powershell CLI - - cd ~\primaite\2.0.0 - .\.venv\Scripts\activate - primaite session --tc .\config\my_training_config.yaml --ldc .\config\my_lay_down_config.yaml - - - .. code-block:: python - :caption: Python - - from primaite.main import run - - training_config = - lay_down_config = - run(training_config, lay_down_config) - - When a session is ran, a session output sub-directory is created in the users app sessions directory (``~/primaite/2.0.0/sessions``). - The sub-directory is formatted as such: ``~/primaite/2.0.0/sessions//_/`` - - For example, when running a session at 17:30:00 on 31st January 2023, the session will output to: - ``~/primaite/2.0.0/sessions/2023-01-31/2023-01-31_17-30-00/``. - - ``primaite session`` can be ran in the terminal/command prompt without arguments. It will use the default configs in the directory ``primaite/config/example_config``. - - To run a PrimAITE session using legacy training or laydown config files, add the ``--legacy-tc`` and/or ``legacy-ldc`` options. - - - - .. code-block:: bash - :caption: Unix CLI - - cd ~/primaite/2.0.0 - source ./.venv/bin/activate - primaite session --tc ./config/my_legacy_training_config.yaml --legacy-tc --ldc ./config/my_legacy_lay_down_config.yaml --legacy-ldc - - .. code-block:: powershell - :caption: Powershell CLI - - cd ~\primaite\2.0.0 - .\.venv\Scripts\activate - primaite session --tc .\config\my_legacy_training_config.yaml --legacy-tc --ldc .\config\my_legacy_lay_down_config.yaml --legacy-ldc - - - .. code-block:: python - :caption: Python - - from primaite.main import run - - training_config = - lay_down_config = - run(training_config, lay_down_config, legacy_training_config=True, legacy_lay_down_config=True) - - - - - Outputs - ------- - - PrimAITE produces four types of outputs: - - * Session Metadata - * Results - * Diagrams - * Saved agents (training checkpoints and a final trained agent) - - - **Session Metadata** - - PrimAITE creates a ``session_metadata.json`` file that contains the following metadata: - - * **uuid** - The UUID assigned to the session upon instantiation. - * **start_datetime** - The date & time the session started in iso format. - * **end_datetime** - The date & time the session ended in iso format. - * **learning** - * **total_episodes** - The total number of training episodes completed. - * **total_time_steps** - The total number of training time steps completed. - * **evaluation** - * **total_episodes** - The total number of evaluation episodes completed. - * **total_time_steps** - The total number of evaluation time steps completed. - * **env** - * **training_config** - * **All training config items** - * **lay_down_config** - * **All lay down config items** - - - **Results** - - PrimAITE automatically creates two sets of results from each learning and evaluation session: - - * Average reward per episode - a csv file listing the average reward for each episode of the session. This provides, for example, an indication of the change over a training session of the reward value - * All transactions - a csv file listing the following values for every step of every episode: - - * Timestamp - * Episode number - * Step number - * Reward value - * Action taken (as presented by the blue agent on this step). Individual elements of the action space are presented in the format AS_X - * Initial observation space (what the blue agent observed when it decided its action) - - **Diagrams** - - * For each session, PrimAITE automatically creates a visualisation of the system / network lay down configuration. - * For each learning and evaluation task within the session, PrimAITE automatically plots the average reward per episode using PlotLY and saves it to the learning or evaluation subdirectory in the session directory. - - **Saved agents** - - For each training session, assuming the agent being trained implements the *save()* function and this function is called by the code, PrimAITE automatically saves the agent state. - - **Example Session Directory Structure** - - .. code-block:: text - - ~/ - └── primaite/ - └── 2.0.0/ - └── sessions/ - └── 2023-07-18/ - └── 2023-07-18_11-06-04/ - ├── evaluation/ - │ ├── all_transactions_2023-07-18_11-06-04.csv - │ ├── average_reward_per_episode_2023-07-18_11-06-04.csv - │ └── average_reward_per_episode_2023-07-18_11-06-04.png - ├── learning/ - │ ├── all_transactions_2023-07-18_11-06-04.csv - │ ├── average_reward_per_episode_2023-07-18_11-06-04.csv - │ ├── average_reward_per_episode_2023-07-18_11-06-04.png - │ ├── checkpoints/ - │ │ └── sb3ppo_10.zip - │ ├── SB3_PPO.zip - │ └── tensorboard_logs/ - │ ├── PPO_1/ - │ │ └── events.out.tfevents.1689674765.METD-9PMRFB3.42960.0 - │ ├── PPO_2/ - │ │ └── events.out.tfevents.1689674766.METD-9PMRFB3.42960.1 - │ ├── PPO_3/ - │ │ └── events.out.tfevents.1689674766.METD-9PMRFB3.42960.2 - │ ├── PPO_4/ - │ │ └── events.out.tfevents.1689674767.METD-9PMRFB3.42960.3 - │ ├── PPO_5/ - │ │ └── events.out.tfevents.1689674767.METD-9PMRFB3.42960.4 - │ ├── PPO_6/ - │ │ └── events.out.tfevents.1689674768.METD-9PMRFB3.42960.5 - │ ├── PPO_7/ - │ │ └── events.out.tfevents.1689674768.METD-9PMRFB3.42960.6 - │ ├── PPO_8/ - │ │ └── events.out.tfevents.1689674769.METD-9PMRFB3.42960.7 - │ ├── PPO_9/ - │ │ └── events.out.tfevents.1689674770.METD-9PMRFB3.42960.8 - │ └── PPO_10/ - │ └── events.out.tfevents.1689674770.METD-9PMRFB3.42960.9 - ├── network_2023-07-18_11-06-04.png - └── session_metadata.json - - Loading a session - ----------------- - - A previous session can be loaded by providing the **directory** of the previous session to either the ``primaite session`` command from the cli - (See :func:`primaite.cli.session`), or by calling :func:`primaite.main.run` with session_path. - - .. tabs:: - - .. code-tab:: bash - :caption: Unix CLI - - cd ~/primaite/2.0.0 - source ./.venv/bin/activate - primaite session --load "path/to/session" - - .. code-tab:: bash - :caption: Powershell CLI - - cd ~\primaite\2.0.0 - .\.venv\Scripts\activate - primaite session --load "path\to\session" - - - .. code-tab:: python - :caption: Python - - from primaite.main import run - - run(session_path=) - - When PrimAITE runs a loaded session, PrimAITE will output in the provided session directory +Running a session creates a session outputs directory in your user data foler. The format looks like this: +``~/primaite/3.0.0/sessions/YYYY-MM-DD/HH-MM-SS/``. This folders contains simulation sys logs generated by each node, +and the saved agent checkpoints, and final model. From 8584fa8f5163863795ee714a4180424b83b2cd11 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Thu, 23 Nov 2023 10:04:52 +0000 Subject: [PATCH 348/980] # 2041: Minor test changes --- src/primaite/simulator/system/services/ntp/ntp_client.py | 4 ++-- src/primaite/simulator/system/services/ntp/ntp_server.py | 4 ++-- tests/integration_tests/system/test_ntp_client_server.py | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index 38ef820b..2b2c725a 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -100,9 +100,9 @@ class NTPClient(Service): self.time = payload.ntp_reply.ntp_datetime return True - def request_time(self) -> None: + def request_time(self, ip_address: IPv4Address = ip_addr) -> None: """Send request to ntp_server.""" - ntp_request = NTPRequest(ntp_client=self.ip_addr) + ntp_request = NTPRequest(ntp_client=ip_address) ntp_server_packet = NTPPacket(ntp_request=ntp_request) self.send(payload=ntp_server_packet) diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index 13bc04ee..6d76c1ed 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -1,5 +1,5 @@ from datetime import datetime -from typing import Any, Dict, Optional +from typing import Dict, Optional from primaite import getLogger from primaite.simulator.network.protocols.ntp import NTPPacket @@ -46,7 +46,7 @@ class NTPServer(Service): def receive( self, - payload: Any, + payload: NTPPacket, session_id: Optional[str] = None, **kwargs, ) -> bool: diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index 95394e84..54e54a5b 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -58,7 +58,9 @@ def test_ntp_client_server(): ntp_request = NTPRequest(ntp_client="192.168.1.3") ntp_packet = NTPPacket(ntp_request=ntp_request) - ntp_client.send(payload=ntp_packet) + # ntp_client.send(payload=ntp_packet) + ntp_client.request_time("192.168.1.3") + assert ntp_server.receive(payload=ntp_packet) is True assert ntp_client.receive(payload=ntp_packet) is True assert ntp_client.time is not None From efeaa4c1cc13edd9c128e4dc47aa52d5ec586cde Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 23 Nov 2023 15:31:06 +0000 Subject: [PATCH 349/980] #2034 - Implemented the Simulation reset functionality by doing a deepcopy of the Simulation object inside the PrimaiteSession upon instantiation. Added a test that uninstalls a service before performing a reset then checks that the service reappears. --- src/primaite/game/session.py | 8 ++++++- .../simulator/system/core/software_manager.py | 10 +++++++- tests/conftest.py | 5 ---- .../test_primaite_session.py | 23 +++++++++++++++---- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index ad0537e8..572dbecb 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -1,4 +1,5 @@ """PrimAITE session - the main entry point to training agents on PrimAITE.""" +from copy import deepcopy from enum import Enum from ipaddress import IPv4Address from pathlib import Path @@ -140,6 +141,9 @@ class PrimaiteSession: self.simulation: Simulation = Simulation() """Simulation object with which the agents will interact.""" + self._simulation_initial_state = deepcopy(self.simulation) + """The Simulation original state (deepcopy of the original Simulation).""" + self.agents: List[AbstractAgent] = [] """List of agents.""" @@ -277,7 +281,7 @@ class PrimaiteSession: self.episode_counter += 1 self.step_counter = 0 _LOGGER.debug(f"Restting primaite session, episode = {self.episode_counter}") - self.simulation.reset_component_for_episode(self.episode_counter) + self.simulation = self._simulation_initial_state def close(self) -> None: """Close the session, this will stop the env and close the simulation.""" @@ -511,4 +515,6 @@ class PrimaiteSession: if agent_load_path: sess.policy.load(Path(agent_load_path)) + sess._simulation_initial_state = deepcopy(sess.simulation) # noqa + return sess diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index 8b8fe599..21a121c1 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -100,8 +100,16 @@ class SoftwareManager: self.node.uninstall_application(software) elif isinstance(software, Service): self.node.uninstall_service(software) + for key, value in self.port_protocol_mapping.items(): + if value.name == software_name: + self.port_protocol_mapping.pop(key) + break + for key, value in self._software_class_to_name_map.items(): + if value == software_name: + self._software_class_to_name_map.pop(key) + break del software - self.sys_log.info(f"Deleted {software_name}") + self.sys_log.info(f"Uninstalled {software_name}") return self.sys_log.error(f"Cannot uninstall {software_name} as it is not installed") diff --git a/tests/conftest.py b/tests/conftest.py index 6a65b12f..419a6128 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,12 +1,7 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -import datetime -import shutil -import tempfile -from datetime import datetime from pathlib import Path from typing import Any, Dict, Union -import nodeenv import pytest import yaml diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index b6122bad..6839a190 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -1,12 +1,13 @@ import pydantic import pytest +from tests import TEST_ASSETS_ROOT from tests.conftest import TempPrimaiteSession -CFG_PATH = "tests/assets/configs/test_primaite_session.yaml" -TRAINING_ONLY_PATH = "tests/assets/configs/train_only_primaite_session.yaml" -EVAL_ONLY_PATH = "tests/assets/configs/eval_only_primaite_session.yaml" -MISCONFIGURED_PATH = "tests/assets/configs/bad_primaite_session.yaml" +CFG_PATH = TEST_ASSETS_ROOT / "configs/test_primaite_session.yaml" +TRAINING_ONLY_PATH = TEST_ASSETS_ROOT / "configs/train_only_primaite_session.yaml" +EVAL_ONLY_PATH = TEST_ASSETS_ROOT / "configs/eval_only_primaite_session.yaml" +MISCONFIGURED_PATH = TEST_ASSETS_ROOT / "configs/bad_primaite_session.yaml" class TestPrimaiteSession: @@ -66,3 +67,17 @@ class TestPrimaiteSession: def test_error_thrown_on_bad_configuration(self): with pytest.raises(pydantic.ValidationError): session = TempPrimaiteSession.from_config(MISCONFIGURED_PATH) + + @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) + def test_session_sim_reset(self, temp_primaite_session): + with temp_primaite_session as session: + session: TempPrimaiteSession + client_1 = session.simulation.network.get_node_by_hostname("client_1") + client_1.software_manager.uninstall("DataManipulationBot") + + assert "DataManipulationBot" not in client_1.software_manager.software + + session.reset() + client_1 = session.simulation.network.get_node_by_hostname("client_1") + + assert "DataManipulationBot" in client_1.software_manager.software From 76939fb8e80275789c8de868076d75c2934cfe67 Mon Sep 17 00:00:00 2001 From: Christopher McCarthy Date: Thu, 23 Nov 2023 15:45:22 +0000 Subject: [PATCH 350/980] Apply suggestions from code review --- src/primaite/game/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 572dbecb..a7df1161 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -281,7 +281,7 @@ class PrimaiteSession: self.episode_counter += 1 self.step_counter = 0 _LOGGER.debug(f"Restting primaite session, episode = {self.episode_counter}") - self.simulation = self._simulation_initial_state + self.simulation = copy.deepcopy(self._simulation_initial_state) def close(self) -> None: """Close the session, this will stop the env and close the simulation.""" From c93705867f28d2b68e3e98888a5de1cb424bc890 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Thu, 23 Nov 2023 15:53:47 +0000 Subject: [PATCH 351/980] Move configuration from agent to data manipulation bot --- .../config/_package_data/example_config.yaml | 14 +++--- src/primaite/game/agent/interface.py | 43 ------------------- src/primaite/game/session.py | 22 +++++----- .../red_services/data_manipulation_bot.py | 11 ++++- 4 files changed, 25 insertions(+), 65 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 700a45fd..274da7aa 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -59,10 +59,6 @@ game_config: team: RED type: RedDatabaseCorruptingAgent - execution_definition: - port_scan_p_of_success: 0.1 - data_manipulation_p_of_success: 0.1 - observation_space: type: UC2RedObservation options: @@ -83,11 +79,6 @@ game_config: - type: DONOTHING # "AgentExecutionDefinition": - """Construct an AgentExecutionDefinition from a config dictionary. - - :param config: A dict of options for the execution definition. - :type config: Dict - :return: The execution definition. - :rtype: AgentExecutionDefinition - """ - if config is None: - return cls() - - return cls(**config) - - class AgentStartSettings(BaseModel): """Configuration values for when an agent starts performing actions.""" @@ -81,7 +57,6 @@ class AbstractAgent(ABC): action_space: Optional[ActionManager], observation_space: Optional[ObservationSpace], reward_function: Optional[RewardFunction], - execution_definition: Optional[AgentExecutionDefinition], agent_settings: Optional[AgentSettings], ) -> None: """ @@ -100,11 +75,6 @@ class AbstractAgent(ABC): self.action_space: Optional[ActionManager] = action_space self.observation_space: Optional[ObservationSpace] = observation_space self.reward_function: Optional[RewardFunction] = reward_function - - # exection definiton converts CAOS action to Primaite simulator request, sometimes having to enrich the info - # by for example specifying target ip addresses, or converting a node ID into a uuid - self.execution_definition = execution_definition or AgentExecutionDefinition() - self.agent_settings = agent_settings or AgentSettings() def convert_state_to_obs(self, state: Dict) -> ObsType: @@ -186,19 +156,6 @@ class DataManipulationAgent(AbstractScriptedAgent): self.next_execution_timestep = self.agent_settings.start_settings.start_step - # get node ids that are part of the agent's observation space - node_ids: List[str] = [n.where[-1] for n in self.observation_space.obs.nodes] - # get all nodes from their ids - nodes: List[Node] = [n for n_id, n in self.action_space.sim.network.nodes.items() if n_id in node_ids] - - # get execution definition for data manipulation bots - for node in nodes: - bot_sw: Optional["DataManipulationBot"] = node.software_manager.software.get("DataManipulationBot") - - if bot_sw is not None: - bot_sw.execution_definition = self.execution_definition - self.data_manipulation_bots.append(bot_sw) - def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: """Randomly sample an action from the action space. diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 1b086c35..f675e33c 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -10,13 +10,7 @@ from pydantic import BaseModel from primaite import getLogger from primaite.game.agent.actions import ActionManager -from primaite.game.agent.interface import ( - AbstractAgent, - AgentExecutionDefinition, - AgentSettings, - DataManipulationAgent, - RandomAgent, -) +from primaite.game.agent.interface import AbstractAgent, AgentSettings, DataManipulationAgent, RandomAgent from primaite.game.agent.observations import ObservationSpace from primaite.game.agent.rewards import RewardFunction from primaite.simulator.network.hardware.base import Link, NIC, Node @@ -366,6 +360,16 @@ class PrimaiteSession: if "domain_mapping" in opt: for domain, ip in opt["domain_mapping"].items(): new_service.dns_register(domain, ip) + if service_type == "DataManipulationBot": + if "options" in service_cfg: + opt = service_cfg["options"] + new_service.configure( + server_ip_address=opt.get("server_ip"), + payload=opt.get("payload"), + port_scan_p_of_success=float(opt.get("port_scan_p_of_success", "0.1")), + data_manipulation_p_of_success=float(opt.get("data_manipulation_p_of_success", "0.1")), + ) + if "applications" in node_cfg: for application_cfg in node_cfg["applications"]: application_ref = application_cfg["ref"] @@ -444,7 +448,6 @@ class PrimaiteSession: # CREATE REWARD FUNCTION rew_function = RewardFunction.from_config(reward_function_cfg, session=sess) - execution_definition = AgentExecutionDefinition.from_config(agent_cfg.get("execution_definition")) agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) # CREATE AGENT @@ -455,7 +458,6 @@ class PrimaiteSession: action_space=action_space, observation_space=obs_space, reward_function=rew_function, - execution_definition=execution_definition, agent_settings=agent_settings, ) sess.agents.append(new_agent) @@ -465,7 +467,6 @@ class PrimaiteSession: action_space=action_space, observation_space=obs_space, reward_function=rew_function, - execution_definition=execution_definition, agent_settings=agent_settings, ) sess.agents.append(new_agent) @@ -476,7 +477,6 @@ class PrimaiteSession: action_space=action_space, observation_space=obs_space, reward_function=rew_function, - execution_definition=execution_definition, agent_settings=agent_settings, ) sess.agents.append(new_agent) diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index eae3f0e3..e3f5b95d 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -2,7 +2,6 @@ from enum import IntEnum from ipaddress import IPv4Address from typing import Optional -from primaite.game.agent.interface import AgentExecutionDefinition from primaite.game.science import simulate_trial from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.database_client import DatabaseClient @@ -36,8 +35,10 @@ class DataManipulationBot(DatabaseClient): server_ip_address: Optional[IPv4Address] = None payload: Optional[str] = None server_password: Optional[str] = None + port_scan_p_of_success: float = 0.1 + data_manipulation_p_of_success: float = 0.1 + attack_stage: DataManipulationAttackStage = DataManipulationAttackStage.NOT_STARTED - execution_definition: AgentExecutionDefinition = AgentExecutionDefinition() repeat: bool = False "Whether to repeat attacking once finished." @@ -50,6 +51,8 @@ class DataManipulationBot(DatabaseClient): server_ip_address: IPv4Address, server_password: Optional[str] = None, payload: Optional[str] = None, + port_scan_p_of_success: float = 0.1, + data_manipulation_p_of_success: float = 0.1, repeat: bool = False, ): """ @@ -58,11 +61,15 @@ class DataManipulationBot(DatabaseClient): :param server_ip_address: The IP address of the Node the DatabaseService is on. :param server_password: The password on the DatabaseService. :param payload: The data manipulation query payload. + :param port_scan_p_of_success: The probability of success for the port scan stage. + :param data_manipulation_p_of_success: The probability of success for the data manipulation stage. :param repeat: Whether to repeat attacking once finished. """ self.server_ip_address = server_ip_address self.payload = payload self.server_password = server_password + self.port_scan_p_of_success = port_scan_p_of_success + self.data_manipulation_p_of_success = data_manipulation_p_of_success self.repeat = repeat self.sys_log.info( f"{self.name}: Configured the {self.name} with {server_ip_address=}, {payload=}, {server_password=}, " From 87dde6ee0bfcad3e3993b1e968de8b63790a2a49 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Thu, 23 Nov 2023 15:55:58 +0000 Subject: [PATCH 352/980] #2042: Test tidying changes. --- .../system/services/ntp/ntp_client.py | 16 ++++++++++++++-- .../system/test_ntp_client_server.py | 19 ++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index 2b2c725a..c75e639d 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -15,6 +15,7 @@ class NTPClient(Service): """Represents a NTP client as a service.""" ip_addr: Optional[IPv4Address] = None + "The IP address of the NTP client" ntp_server: Optional[IPv4Address] = None "The NTP server the client sends requests to." time: Optional[datetime] = None @@ -26,6 +27,17 @@ class NTPClient(Service): super().__init__(**kwargs) self.start() + def configure(self, ntp_server_ip_address: IPv4Address, ntp_client_ip_address: IPv4Address) -> None: + """ + Set the IP address for the NTP server. + + :param ntp_server_ip_address: IPv4 address of NTP server. + :param ntp_client_ip_Address: IPv4 address of NTP client. + """ + self.ip_addr = ntp_client_ip_address + self.ntp_server = ntp_server_ip_address + self.sys_log.info(f"{self.name}: ip_addr: {self.ip_addr}, ntp_server: {self.ntp_server}") + def describe_state(self) -> Dict: """ Describes the current state of the software. @@ -100,9 +112,9 @@ class NTPClient(Service): self.time = payload.ntp_reply.ntp_datetime return True - def request_time(self, ip_address: IPv4Address = ip_addr) -> None: + def request_time(self) -> None: """Send request to ntp_server.""" - ntp_request = NTPRequest(ntp_client=ip_address) + ntp_request = NTPRequest(ntp_client=self.ip_addr) ntp_server_packet = NTPPacket(ntp_request=ntp_request) self.send(payload=ntp_server_packet) diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index 54e54a5b..dec6c0f7 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -36,6 +36,7 @@ def create_ntp_network() -> Network: ) ntp_client.power_on() ntp_client.software_manager.install(NTPClient) + network.connect(endpoint_b=ntp_server.ethernet_port[1], endpoint_a=ntp_client.ethernet_port[1]) return network @@ -54,21 +55,25 @@ def test_ntp_client_server(): assert ntp_server.operating_state == ServiceOperatingState.RUNNING assert ntp_client.operating_state == ServiceOperatingState.RUNNING + ntp_client.configure( + ntp_server_ip_address=IPv4Address("192.168.1.2"), ntp_client_ip_address=IPv4Address("192.168.1.3") + ) + assert ntp_client.time is None - ntp_request = NTPRequest(ntp_client="192.168.1.3") - ntp_packet = NTPPacket(ntp_request=ntp_request) + # ntp_request = NTPRequest(ntp_client="192.168.1.3") + # ntp_packet = NTPPacket(ntp_request=ntp_request) # ntp_client.send(payload=ntp_packet) - ntp_client.request_time("192.168.1.3") + ntp_client.request_time() - assert ntp_server.receive(payload=ntp_packet) is True - assert ntp_client.receive(payload=ntp_packet) is True + # assert ntp_server.receive(payload=ntp_packet) is True + # assert ntp_client.receive(payload=ntp_packet) is True assert ntp_client.time is not None first_time = ntp_client.time sleep(0.1) ntp_client.apply_timestep(1) # Check time advances - ntp_server.receive(payload=ntp_packet) - ntp_client.receive(payload=ntp_packet) + # ntp_server.receive(payload=ntp_packet) + # ntp_client.receive(payload=ntp_packet) second_time = ntp_client.time assert first_time != second_time From 5f1a5af1b45eccf5154f35e0143282dc3491e089 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Thu, 23 Nov 2023 16:06:19 +0000 Subject: [PATCH 353/980] Add data manipulation bot action manager --- .../config/_package_data/example_config.yaml | 8 +-- src/primaite/game/agent/actions.py | 49 +++++++++++++++++++ src/primaite/game/agent/interface.py | 27 +++++----- .../red_services/data_manipulation_bot.py | 8 +++ .../test_data_manipulation_bot.py | 2 - 5 files changed, 76 insertions(+), 18 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 274da7aa..aff54d62 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -78,12 +78,12 @@ game_config: action_list: - type: DONOTHING # None: + super().__init__(manager=manager) + self.shape: Dict[str, int] = {"node_id": num_nodes, "application_id": num_applications} + self.verb: str + + def form_request(self, node_id: int, application_id: int) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" + node_uuid = self.manager.get_node_uuid_by_idx(node_id) + application_uuid = self.manager.get_application_uuid_by_idx(node_id, application_id) + if node_uuid is None or application_uuid is None: + return ["do_nothing"] + return ["network", "node", node_uuid, "application", application_uuid, self.verb] + + +class NodeApplicationExecuteAction(NodeApplicationAbstractAction): + """Action which executes an application.""" + + def __init__(self, manager: "ActionManager", num_nodes: int, num_applications: int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_applications=num_applications) + self.verb = "execute" + + class NodeFolderAbstractAction(AbstractAction): """ Base class for folder actions. @@ -536,6 +567,7 @@ class ActionManager: "NODE_SERVICE_RESTART": NodeServiceRestartAction, "NODE_SERVICE_DISABLE": NodeServiceDisableAction, "NODE_SERVICE_ENABLE": NodeServiceEnableAction, + "NODE_APPLICATION_EXECUTE": NodeApplicationExecuteAction, "NODE_FILE_SCAN": NodeFileScanAction, "NODE_FILE_CHECKHASH": NodeFileCheckhashAction, "NODE_FILE_DELETE": NodeFileDeleteAction, @@ -565,6 +597,7 @@ class ActionManager: max_folders_per_node: int = 2, # allows calculating shape max_files_per_folder: int = 2, # allows calculating shape max_services_per_node: int = 2, # allows calculating shape + max_applications_per_node: int = 10, # allows calculating shape max_nics_per_node: int = 8, # allows calculating shape max_acl_rules: int = 10, # allows calculating shape protocols: List[str] = ["TCP", "UDP", "ICMP"], # allow mapping index to protocol @@ -622,6 +655,7 @@ class ActionManager: "num_folders": max_folders_per_node, "num_files": max_files_per_folder, "num_services": max_services_per_node, + "num_applications": max_applications_per_node, "num_nics": max_nics_per_node, "num_acl_rules": max_acl_rules, "num_protocols": len(self.protocols), @@ -775,6 +809,21 @@ class ActionManager: service_uuids = list(node.services.keys()) return service_uuids[service_idx] if len(service_uuids) > service_idx else None + def get_application_uuid_by_idx(self, node_idx: int, application_idx: int) -> Optional[str]: + """Get the application UUID corresponding to the given node and service indices. + + :param node_idx: The index of the node. + :type node_idx: int + :param application_idx: The index of the service on the node. + :type application_idx: int + :return: The UUID of the service. Or None if the node has fewer services than the given index. + :rtype: Optional[str] + """ + node_uuid = self.get_node_uuid_by_idx(node_idx) + node = self.sim.network.nodes[node_uuid] + application_uuids = list(node.applications.keys()) + return application_uuids[application_idx] if len(application_uuids) > application_idx else None + def get_internet_protocol_by_idx(self, protocol_idx: int) -> str: """Get the internet protocol corresponding to the given index. diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 5e73a423..33932df2 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -154,7 +154,17 @@ class DataManipulationAgent(AbstractScriptedAgent): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.next_execution_timestep = self.agent_settings.start_settings.start_step + self._set_next_execution_timestep(self.agent_settings.start_settings.start_step) + + def _set_next_execution_timestep(self, timestep: int) -> None: + """Set the next execution timestep with a configured random variance. + + :param timestep: The timestep to add variance to. + """ + random_timestep_increment = random.randint( + -self.agent_settings.start_settings.variance, self.agent_settings.start_settings.variance + ) + self.next_execution_timestep = timestep + random_timestep_increment def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: """Randomly sample an action from the action space. @@ -166,21 +176,14 @@ class DataManipulationAgent(AbstractScriptedAgent): :return: _description_ :rtype: Tuple[str, Dict] """ - # TODO: Move this to the appropriate place - # return self.action_space.get_action(self.action_space.space.sample()) + current_timestep = self.action_space.session.step_counter - timestep = self.action_space.session.step_counter - - if timestep < self.next_execution_timestep: + if current_timestep < self.next_execution_timestep: return "DONOTHING", {"dummy": 0} - var = random.randint(-self.agent_settings.start_settings.variance, self.agent_settings.start_settings.variance) - self.next_execution_timestep = timestep + self.agent_settings.start_settings.frequency + var + self._set_next_execution_timestep(current_timestep + self.agent_settings.start_settings.frequency) - for bot in self.data_manipulation_bots: - bot.execute() - - return "DONOTHING", {"dummy": 0} + return "NODE_APPLICATION_EXECUTE", {"node_id": 0, "application_id": 0} class AbstractGATEAgent(AbstractAgent): diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index e3f5b95d..f4b31cb1 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -3,6 +3,7 @@ from ipaddress import IPv4Address from typing import Optional from primaite.game.science import simulate_trial +from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.database_client import DatabaseClient @@ -46,6 +47,13 @@ class DataManipulationBot(DatabaseClient): super().__init__(**kwargs) self.name = "DataManipulationBot" + def _init_request_manager(self) -> RequestManager: + rm = super()._init_request_manager() + + rm.add_request(name="execute", request_type=RequestType(func=self.execute)) + + return rm + def configure( self, server_ip_address: IPv4Address, diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py index 5127254c..04e23e84 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py @@ -1,5 +1,3 @@ -from ipaddress import IPv4Address - import pytest from primaite.simulator.network.hardware.base import Node From 47112aafcf0b9a207440febf649ed39ec2f43bbf Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Thu, 23 Nov 2023 16:19:39 +0000 Subject: [PATCH 354/980] #2068: Removed references to ARCD GATE --- CHANGELOG.md | 2 +- README.md | 2 -- docs/source/about.rst | 1 - docs/source/custom_agent.rst | 2 +- docs/source/game_layer.rst | 8 ++++---- docs/source/getting_started.rst | 30 +----------------------------- 6 files changed, 7 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3af5c14c..a2044858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,7 @@ SessionManager. ### Removed - Removed legacy simulation modules: `acl`, `common`, `environment`, `links`, `nodes`, `pol` -- Removed legacy training modules, they are replaced by the new ARCD GATE dependency +- Removed legacy training modules - Removed tests for legacy code diff --git a/README.md b/README.md index 7fc41681..ec335108 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,6 @@ PrimAITE presents the following features: - Routers with traffic routing and firewall capabilities -- Integration with ARCD GATE for agent training - - Support for multiple agents, each having their own customisable observation space, action space, and reward function definition, and either deterministic or RL-directed behaviour ## Getting Started with PrimAITE diff --git a/docs/source/about.rst b/docs/source/about.rst index 993dec0c..56c8b551 100644 --- a/docs/source/about.rst +++ b/docs/source/about.rst @@ -18,7 +18,6 @@ PrimAITE provides the following features: * Highly configurable network hosts, including definition of software, file system, and network interfaces, * Realistic network traffic simulation, including address and sending packets via internet protocols like TCP, UDP, ICMP, etc. * Routers with traffic routing and firewall capabilities -* Interfaces with ARCD GATE to allow training of agents * Simulation of customisable deterministic agents * Support for multiple agents, each having their own customisable observation space, action space, and reward function definition. diff --git a/docs/source/custom_agent.rst b/docs/source/custom_agent.rst index 0a08ae74..7a9d83c1 100644 --- a/docs/source/custom_agent.rst +++ b/docs/source/custom_agent.rst @@ -11,4 +11,4 @@ Integrating a user defined blue agent .. note:: - PrimAITE uses ARCD GATE for agent integration. In order to use a custom agent with PrimAITE, you must integrate it with ARCD GATE. Please look at the ARCD GATE documentation for more information. + TBA diff --git a/docs/source/game_layer.rst b/docs/source/game_layer.rst index 27905c85..18b42e7b 100644 --- a/docs/source/game_layer.rst +++ b/docs/source/game_layer.rst @@ -4,9 +4,9 @@ PrimAITE Game layer The Primaite codebase consists of two main modules: * ``simulator``: The simulation logic including the network topology, the network state, and behaviour of various hardware and software classes. -* ``game``: The agent-training infrastructure which helps reinforcement learning agents interface with the simulation. This includes the observation, action, and rewards, for RL agents, but also scripted deterministic agents. The game layer orchestrates all the interactions between modules, including ARCD GATE. +* ``game``: The agent-training infrastructure which helps reinforcement learning agents interface with the simulation. This includes the observation, action, and rewards, for RL agents, but also scripted deterministic agents. The game layer orchestrates all the interactions between modules. -These two components have been decoupled to allow the agent training code in ARCD GATE to be reused with other simulators. The simulator and game layer communicate using the PrimAITE State API and the PrimAITE Request API. The game layer communicates with ARCD gate using the `Farama Gymnasium Spaces API `_. + The simulator and game layer communicate using the PrimAITE State API and the PrimAITE Request API. .. TODO: write up these APIs and link them here. @@ -20,13 +20,13 @@ The game layer is responsible for managing agents and getting them to interface PrimAITE Session ^^^^^^^^^^^^^^^ -``PrimaiteSession`` is the main entry point into Primaite and it allows the simultaneous coordination of a simulation and agents that interact with it. It also sends messages to ARCD GATE to perform reinforcement learning. ``PrimaiteSession`` keeps track of multiple agents of different types. +``PrimaiteSession`` is the main entry point into Primaite and it allows the simultaneous coordination of a simulation and agents that interact with it. ``PrimaiteSession`` keeps track of multiple agents of different types. Agents ^^^^^^ All agents inherit from the :py:class:`primaite.game.agent.interface.AbstractAgent` class, which mandates that they have an ObservationManager, ActionManager, and RewardManager. The agent behaviour depends on the type of agent, but there are two main types: -* RL agents action during each step is decided by an RL algorithm which lives inside of ARCD GATE. The agent within PrimAITE just acts to format and forward actions decided by an RL policy. +* RL agents action during each step is decided by an appropriate RL algorithm. The agent within PrimAITE just acts to format and forward actions decided by an RL policy. * Deterministic agents perform all of their decision making within the PrimAITE game layer. They typically have a scripted policy which always performs the same action or a rule-based policy which performs actions based on the current state of the simulation. They can have a stochastic element, and their seed will be settable. .. diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index aebabf66..a800ee56 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -87,22 +87,7 @@ Install PrimAITE pip install path\to\your\primaite.whl - -5. Install ARCD GATE from wheel file - - -.. code-block:: bash - :caption: Unix - - pip install path/to/your/arcd_gate-0.1.0-py3-none-any.whl - -.. code-block:: powershell - :caption: Windows (Powershell) - - pip install path\to\your\arcd_gate-0.1.0-py3-none-any.whl - - -6. Perform the PrimAITE setup +5. Perform the PrimAITE setup .. code-block:: bash :caption: Unix @@ -153,17 +138,4 @@ of your choice: pip install -e .[dev] - -4. Install ARCD GATE from wheel file - -.. code-block:: bash - :caption: Unix - - pip install GATE/arcd_gate-0.1.0-py3-none-any.whl - -.. code-block:: powershell - :caption: Windows (Powershell) - - pip install GATE\arcd_gate-0.1.0-py3-none-any.whl - To view the complete list of packages installed during PrimAITE installation, go to the dependencies page (:ref:`Dependencies`). From 3894a9615d7ee856a7e9c946565f8700f1acfd3a Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Thu, 23 Nov 2023 17:42:26 +0000 Subject: [PATCH 355/980] #2068: Replace refs to OpenAI Gym with Gymnasium --- docs/index.rst | 10 +++++----- docs/source/about.rst | 5 +++-- docs/source/glossary.rst | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index fa877064..2dfc8a65 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -30,7 +30,7 @@ PrimAITE incorporates the following features: - Uses the concept of Information Exchange Requirements (IERs) to model background pattern of life and adversarial behaviour; - An Access Control List (ACL) function, mimicking the behaviour of a network firewall, is applied across the model, following standard ACL rule format (e.g. DENY/ALLOW, source IP address, destination IP address, protocol and port); - Application of traffic to the links of the platform / system laydown adheres to the ACL ruleset; -- Presents both an OpenAI gym and Ray RLLib interface to the environment, allowing integration with any compliant defensive agents; +- Presents both a Gymnasium and Ray RLLib interface to the environment, allowing integration with any compliant defensive agents; - Allows for the saving and loading of trained defensive agents; - Stochastic adversarial agent behaviour; - Full capture of discrete logs relating to agent training or evaluation (system state, agent actions taken, instantaneous and average reward for every step of every episode); @@ -40,18 +40,18 @@ PrimAITE incorporates the following features: Architecture ^^^^^^^^^^^^ -PrimAITE is a Python application and is therefore Operating System agnostic. The OpenAI gym and Ray RLLib frameworks are employed to provide an interface and source for AI agents. Configuration of PrimAITE is achieved via included YAML files which support full control over the platform / system laydown being modelled, background pattern of life, adversarial (red agent) behaviour, and step and episode count. NetworkX based nodes and links host Python classes to present attributes and methods, and hence a more representative platform / system can be modelled within the simulation. +PrimAITE is a Python application and is therefore Operating System agnostic. The Gymnasium and Ray RLLib frameworks are employed to provide an interface and source for AI agents. Configuration of PrimAITE is achieved via included YAML files which support full control over the platform / system laydown being modelled, background pattern of life, adversarial (red agent) behaviour, and step and episode count. NetworkX based nodes and links host Python classes to present attributes and methods, and hence a more representative platform / system can be modelled within the simulation. Training & Evaluation Capability ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -PrimAITE provides a training and evaluation capability to AI agents in the context of cyber-attack, via its OpenAI Gym and RLLib compliant interface. Scenarios can be constructed to reflect platform / system laydowns consisting of any configuration of nodes (e.g. PCs, servers, switches etc.) and network links between them. All nodes can be configured to model services (and their status) and the traffic loading between them over the network links. Traffic loading is broken down into a per service granularity, relating directly to a protocol (e.g. Service A would be configured as a TCP service, and TCP traffic then flows between instances of Service A under the direction of a tailored IER). Highlights of PrimAITE’s training and evaluation capability are: +PrimAITE provides a training and evaluation capability to AI agents in the context of cyber-attack, via its Gymnasium and RLLib compliant interface. Scenarios can be constructed to reflect platform / system laydowns consisting of any configuration of nodes (e.g. PCs, servers, switches etc.) and network links between them. All nodes can be configured to model services (and their status) and the traffic loading between them over the network links. Traffic loading is broken down into a per service granularity, relating directly to a protocol (e.g. Service A would be configured as a TCP service, and TCP traffic then flows between instances of Service A under the direction of a tailored IER). Highlights of PrimAITE’s training and evaluation capability are: - The scenario is not bound to a representation of any platform, system, or technology; - Fully configurable (network / system laydown, IERs, node pattern-of-life, ACL, number of episodes, steps per episode) and repeatable to suit the requirements of AI agents; -- Can integrate with any OpenAI Gym or RLLib compliant AI agent. +- Can integrate with any Gymnasium or RLLib compliant AI agent. Use of PrimAITE default scenarios within ARCD is supported by a “Use Case Profile” tailored to the scenario. @@ -75,7 +75,7 @@ Logs are available in CSV format and provide coverage of the above data for ever What is PrimAITE built with --------------------------- -* `OpenAI's Gym `_ is used as the basis for AI blue agent interaction with the PrimAITE environment +* `Gymnasium `_ is used as the basis for AI blue agent interaction with the PrimAITE environment * `Networkx `_ is used as the underlying data structure used for the PrimAITE environment * `Stable Baselines 3 `_ is used as a default source of RL algorithms (although PrimAITE is not limited to SB3 agents) * `Ray RLlib `_ is used as an additional source of RL algorithms diff --git a/docs/source/about.rst b/docs/source/about.rst index 56c8b551..32b54eee 100644 --- a/docs/source/about.rst +++ b/docs/source/about.rst @@ -18,6 +18,7 @@ PrimAITE provides the following features: * Highly configurable network hosts, including definition of software, file system, and network interfaces, * Realistic network traffic simulation, including address and sending packets via internet protocols like TCP, UDP, ICMP, etc. * Routers with traffic routing and firewall capabilities +* Interfaces with ARCD GATE to allow training of agents * Simulation of customisable deterministic agents * Support for multiple agents, each having their own customisable observation space, action space, and reward function definition. @@ -147,7 +148,7 @@ The game layer is built on top of the simulator and it consumes the simulation a Observation Spaces ****************** The observation space provides the blue agent with information about the current status of nodes and links. - PrimAITE builds on top of Gym Spaces to create an observation space that is easily configurable for users. It's made up of components which are managed by the :py:class:`primaite.environment.observations.ObservationsHandler`. Each training scenario can define its own observation space, and the user can choose which information to inlude, and how it should be formatted. + PrimAITE builds on top of Gymnasium Spaces to create an observation space that is easily configurable for users. It's made up of components which are managed by the :py:class:`primaite.environment.observations.ObservationsHandler`. Each training scenario can define its own observation space, and the user can choose which information to inlude, and how it should be formatted. NodeLinkTable component ----------------------- For example, the :py:class:`primaite.environment.observations.NodeLinkTable` component represents the status of nodes and links as a ``gym.spaces.Box`` with an example format shown below: @@ -278,7 +279,7 @@ The game layer is built on top of the simulator and it consumes the simulation a 3. Any (Agent can take both node-based and ACL-based actions) The choice of action space used during a training session is determined in the config_[name].yaml file. **Node-Based** - The agent is able to influence the status of nodes by switching them off, resetting, or patching operating systems and services. In this instance, the action space is an OpenAI Gym spaces.Discrete type, as follows: + The agent is able to influence the status of nodes by switching them off, resetting, or patching operating systems and services. In this instance, the action space is an Gymnasium spaces.Discrete type, as follows: * Dictionary item {... ,1: [x1, x2, x3,x4] ...} The placeholders inside the list under the key '1' mean the following: * [0, num nodes] - Node ID (0 = nothing, node ID) diff --git a/docs/source/glossary.rst b/docs/source/glossary.rst index 8340d559..4c0869f2 100644 --- a/docs/source/glossary.rst +++ b/docs/source/glossary.rst @@ -74,8 +74,8 @@ Glossary Laydown The laydown is a file which defines the training scenario. It contains the network topology, firewall rules, services, protocols, and details about green and red agent behaviours. - Gym - PrimAITE uses the Gym reinforcement learning framework API to create a training environment and interface with RL agents. Gym defines a common way of creating observations, actions, and rewards. + Gymnasium + PrimAITE uses the Gymnasium reinforcement learning framework API to create a training environment and interface with RL agents. Gymnasium defines a common way of creating observations, actions, and rewards. User app home PrimAITE supports upgrading software version while retaining user data. The user data directory is where configs, notebooks, and results are stored, this location is `~/primaite` on linux/darwin and `C:\Users\\primaite\` on Windows. From 3dfd7a2e14149e525dae930f5bde51dc82ba3a89 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Thu, 23 Nov 2023 17:57:51 +0000 Subject: [PATCH 356/980] #2068: Fix malformed Windows path --- docs/source/glossary.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/glossary.rst b/docs/source/glossary.rst index 4c0869f2..67fd7aaa 100644 --- a/docs/source/glossary.rst +++ b/docs/source/glossary.rst @@ -78,4 +78,4 @@ Glossary PrimAITE uses the Gymnasium reinforcement learning framework API to create a training environment and interface with RL agents. Gymnasium defines a common way of creating observations, actions, and rewards. User app home - PrimAITE supports upgrading software version while retaining user data. The user data directory is where configs, notebooks, and results are stored, this location is `~/primaite` on linux/darwin and `C:\Users\\primaite\` on Windows. + PrimAITE supports upgrading software version while retaining user data. The user data directory is where configs, notebooks, and results are stored, this location is `~/primaite` on linux/darwin and `C:\\Users\\\\primaite\\` on Windows. From bd6c27244c349940a0ec8fa21ca7845786071301 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 23 Nov 2023 19:49:03 +0000 Subject: [PATCH 357/980] #2064: Edited services and applications to handle when they are shut down --- src/primaite/simulator/network/container.py | 11 +++++ .../simulator/network/hardware/base.py | 40 +++++++++++------- .../network/hardware/node_operating_state.py | 14 +++++++ .../simulator/network/protocols/ftp.py | 3 ++ .../system/applications/web_browser.py | 21 ++++++++-- .../system/services/ftp/ftp_client.py | 8 ++-- .../system/services/ftp/ftp_server.py | 3 ++ .../simulator/system/services/service.py | 23 +++++++++- .../system/services/web_server/web_server.py | 3 ++ src/primaite/simulator/system/software.py | 6 ++- tests/conftest.py | 7 ++++ .../system/test_ftp_client_server.py | 37 ++++++++++++++++ .../system/test_service_on_node.py | 42 +++++++++++++++++++ .../system/test_web_client_server.py | 30 ++++++++++++- .../_simulator/_system/_services/test_ftp.py | 14 +++++-- 15 files changed, 232 insertions(+), 30 deletions(-) create mode 100644 src/primaite/simulator/network/hardware/node_operating_state.py create mode 100644 tests/integration_tests/system/test_service_on_node.py diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 9fbafc29..a356549a 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -52,6 +52,17 @@ class Network(SimComponent): ) return rm + def apply_timestep(self, timestep: int) -> None: + """Apply a timestep evolution to this the network and its nodes and links.""" + super().apply_timestep(timestep=timestep) + # apply timestep to nodes + for node_id in self.nodes: + self.nodes[node_id].apply_timestep(timestep=timestep) + + # apply timestep to links + for link_id in self.links: + self.links[link_id].apply_timestep(timestep=timestep) + @property def routers(self) -> List[Router]: """The Routers in the Network.""" diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 29d3a05c..ebf669eb 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -2,7 +2,6 @@ from __future__ import annotations import re import secrets -from enum import Enum from ipaddress import IPv4Address, IPv4Network from pathlib import Path from typing import Any, Dict, Literal, Optional, Tuple, Union @@ -15,6 +14,7 @@ from primaite.simulator import SIM_OUTPUT from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.domain.account import Account from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol @@ -856,19 +856,6 @@ class ICMP: return sequence, icmp_packet.identifier -class NodeOperatingState(Enum): - """Enumeration of Node Operating States.""" - - ON = 1 - "The node is powered on." - OFF = 2 - "The node is powered off." - BOOTING = 3 - "The node is in the process of booting up." - SHUTTING_DOWN = 4 - "The node is in the process of shutting down." - - class Node(SimComponent): """ A basic Node class that represents a node on the network. @@ -1090,18 +1077,21 @@ class Node(SimComponent): else: if self.operating_state == NodeOperatingState.BOOTING: self.operating_state = NodeOperatingState.ON - self.sys_log.info("Turned on") + self.sys_log.info(f"{self.hostname}: Turned on") for nic in self.nics.values(): if nic._connected_link: nic.enable() + self._start_up_actions() + # count down to shut down if self.shut_down_countdown > 0: self.shut_down_countdown -= 1 else: if self.operating_state == NodeOperatingState.SHUTTING_DOWN: self.operating_state = NodeOperatingState.OFF - self.sys_log.info("Turned off") + self.sys_log.info(f"{self.hostname}: Turned off") + self._shut_down_actions() # if resetting turn back on if self.is_resetting: @@ -1418,6 +1408,24 @@ class Node(SimComponent): _LOGGER.info(f"Removed application {application.uuid} from node {self.uuid}") self._application_request_manager.remove_request(application.uuid) + def _shut_down_actions(self): + """Actions to perform when the node is shut down.""" + # Turn off all the services in the node + for service_id in self.services: + self.services[service_id].stop() + + # Turn off all the applications in the node + for app_id in self.applications: + self.applications[app_id].close() + + # Turn off all processes in the node + # for process_id in self.processes: + # self.processes[process_id] + + def _start_up_actions(self): + """Actions to perform when the node is starting up.""" + pass + def __contains__(self, item: Any) -> bool: if isinstance(item, Service): return item.uuid in self.services diff --git a/src/primaite/simulator/network/hardware/node_operating_state.py b/src/primaite/simulator/network/hardware/node_operating_state.py new file mode 100644 index 00000000..1fd1225f --- /dev/null +++ b/src/primaite/simulator/network/hardware/node_operating_state.py @@ -0,0 +1,14 @@ +from enum import Enum + + +class NodeOperatingState(Enum): + """Enumeration of Node Operating States.""" + + ON = 1 + "The node is powered on." + OFF = 2 + "The node is powered off." + BOOTING = 3 + "The node is in the process of booting up." + SHUTTING_DOWN = 4 + "The node is in the process of shutting down." diff --git a/src/primaite/simulator/network/protocols/ftp.py b/src/primaite/simulator/network/protocols/ftp.py index 9ecc7df8..0fd3fe43 100644 --- a/src/primaite/simulator/network/protocols/ftp.py +++ b/src/primaite/simulator/network/protocols/ftp.py @@ -35,6 +35,9 @@ class FTPCommand(Enum): class FTPStatusCode(Enum): """Status code of the current FTP request.""" + NOT_FOUND = 14 + """Destination not found.""" + OK = 200 """Command successful.""" diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index ea9c3ac3..bb9552d8 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -2,7 +2,12 @@ from ipaddress import IPv4Address from typing import Dict, Optional from urllib.parse import urlparse -from primaite.simulator.network.protocols.http import HttpRequestMethod, HttpRequestPacket, HttpResponsePacket +from primaite.simulator.network.protocols.http import ( + HttpRequestMethod, + HttpRequestPacket, + HttpResponsePacket, + HttpStatusCode, +) from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application @@ -61,7 +66,7 @@ class WebBrowser(Application): :type: url: str """ # reset latest response - self.latest_response = None + self.latest_response = HttpResponsePacket(status_code=HttpStatusCode.NOT_FOUND) try: parsed_url = urlparse(url) @@ -91,11 +96,19 @@ class WebBrowser(Application): payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url=url) # send request - return self.send( + if self.send( payload=payload, dest_ip_address=self.domain_name_ip_address, dest_port=parsed_url.port if parsed_url.port else Port.HTTP, - ) + ): + self.sys_log.info( + f"{self.name}: Received HTTP {payload.request_method.name} " + f"Response {payload.request_url} - {self.latest_response.status_code.value}" + ) + return self.latest_response.status_code is HttpStatusCode.OK + else: + self.sys_log.error(f"Error sending Http Packet {str(payload)}") + return False def send( self, diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 3e286da1..649b9b50 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -72,10 +72,7 @@ class FTPClient(FTPServiceABC): # normally FTP will choose a random port for the transfer, but using the FTP command port will do for now # create FTP packet - payload: FTPPacket = FTPPacket( - ftp_command=FTPCommand.PORT, - ftp_command_args=Port.FTP, - ) + payload: FTPPacket = FTPPacket(ftp_command=FTPCommand.PORT, ftp_command_args=Port.FTP) if self.send(payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id): if payload.status_code == FTPStatusCode.OK: @@ -271,7 +268,10 @@ class FTPClient(FTPServiceABC): the same node. """ if payload.status_code is None: + self.sys_log.error(f"FTP Server could not be found - Error Code: {payload.status_code.value}") return False + self.sys_log.info(f"{self.name}: Received FTP Response {payload.ftp_command.name} {payload.status_code.value}") + self._process_ftp_command(payload=payload, session_id=session_id) return True diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 23414601..bc21dec3 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -89,5 +89,8 @@ class FTPServer(FTPServiceABC): if payload.status_code is not None: return False + if not super().receive(payload=payload, session_id=session_id, **kwargs): + return False + self.send(self._process_ftp_command(payload=payload, session_id=session_id), session_id) return True diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index e2b04c15..3a1a4c9d 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,8 +1,9 @@ from enum import Enum -from typing import Dict, Optional +from typing import Any, Dict, Optional from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.system.software import IOSoftware, SoftwareHealthState _LOGGER = getLogger(__name__) @@ -40,6 +41,21 @@ class Service(IOSoftware): restart_countdown: Optional[int] = None "If currently restarting, how many timesteps remain until the restart is finished." + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Receives a payload from the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + + :param payload: The payload to receive. + :param session_id: The identifier of the session that the payload is associated with. + :param kwargs: Additional keyword arguments specific to the implementation. + :return: True if the payload was successfully received and processed, False otherwise. + """ + return super().receive(payload=payload, session_id=session_id, **kwargs) + def __init__(self, **kwargs): super().__init__(**kwargs) @@ -91,6 +107,11 @@ class Service(IOSoftware): def start(self, **kwargs) -> None: """Start the service.""" + # cant start the service if the node it is on is off + if self.software_manager and self.software_manager.node.operating_state is not NodeOperatingState.ON: + self.sys_log.error(f"Unable to start service. {self.software_manager.node.hostname} is not turned on.") + return + if self.operating_state == ServiceOperatingState.STOPPED: self.sys_log.info(f"Starting service {self.name}") self.operating_state = ServiceOperatingState.RUNNING diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index cb1a4738..76176cd8 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -160,4 +160,7 @@ class WebServer(Service): self.sys_log.error("Payload is not an HTTPPacket") return False + if not super().receive(payload=payload, session_id=session_id, **kwargs): + return False + return self._process_http_request(payload=payload, session_id=session_id) diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index f2627557..c29bec20 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -5,6 +5,7 @@ from typing import Any, Dict, Optional from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file_system import FileSystem, Folder +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.session_manager import Session from primaite.simulator.system.core.sys_log import SysLog @@ -261,4 +262,7 @@ class IOSoftware(Software): :param kwargs: Additional keyword arguments specific to the implementation. :return: True if the payload was successfully received and processed, False otherwise. """ - pass + # return false if node that software is on is off + if self.software_manager and self.software_manager.node.operating_state is NodeOperatingState.OFF: + return False + return True diff --git a/tests/conftest.py b/tests/conftest.py index 6a65b12f..4cc36e6b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,6 +17,7 @@ from primaite.game.session import PrimaiteSession # from primaite.primaite_session import PrimaiteSession from primaite.simulator.network.container import Network from primaite.simulator.network.networks import arcd_uc2_network +from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application from primaite.simulator.system.core.sys_log import SysLog @@ -38,6 +39,12 @@ from primaite.simulator.network.hardware.base import Node class TestService(Service): """Test Service class""" + def __init__(self, **kwargs): + kwargs["name"] = "TestService" + kwargs["port"] = Port.HTTP + kwargs["protocol"] = IPProtocol.TCP + super().__init__(**kwargs) + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: pass diff --git a/tests/integration_tests/system/test_ftp_client_server.py b/tests/integration_tests/system/test_ftp_client_server.py index 48dc2960..d8968b2d 100644 --- a/tests/integration_tests/system/test_ftp_client_server.py +++ b/tests/integration_tests/system/test_ftp_client_server.py @@ -60,3 +60,40 @@ def test_ftp_client_retrieve_file_from_server(uc2_network): # client should have retrieved the file assert ftp_client.file_system.get_file(folder_name="downloads", file_name="test_file.txt") + + +def test_ftp_client_tries_to_connect_to_offline_server(uc2_network): + """Test checks to make sure that the client can't do anything when the server is offline.""" + client_1: Computer = uc2_network.get_node_by_hostname("client_1") + backup_server: Server = uc2_network.get_node_by_hostname("backup_server") + + ftp_client: FTPClient = client_1.software_manager.software["FTPClient"] + ftp_server: FTPServer = backup_server.software_manager.software["FTPServer"] + + assert ftp_client.operating_state == ServiceOperatingState.RUNNING + assert ftp_server.operating_state == ServiceOperatingState.RUNNING + + # create file on ftp server + ftp_server.file_system.create_file(file_name="test_file.txt", folder_name="file_share") + + backup_server.power_off() + + for i in range(backup_server.shut_down_duration + 1): + uc2_network.apply_timestep(timestep=i) + + assert ftp_client.operating_state == ServiceOperatingState.RUNNING + assert ftp_server.operating_state == ServiceOperatingState.STOPPED + + assert ( + ftp_client.request_file( + src_folder_name="file_share", + src_file_name="test_file.txt", + dest_folder_name="downloads", + dest_file_name="test_file.txt", + dest_ip_address=backup_server.nics.get(next(iter(backup_server.nics))).ip_address, + ) + is False + ) + + # client should have retrieved the file + assert ftp_client.file_system.get_file(folder_name="downloads", file_name="test_file.txt") is None diff --git a/tests/integration_tests/system/test_service_on_node.py b/tests/integration_tests/system/test_service_on_node.py new file mode 100644 index 00000000..e596dcd8 --- /dev/null +++ b/tests/integration_tests/system/test_service_on_node.py @@ -0,0 +1,42 @@ +from typing import Tuple + +import pytest +from conftest import TestService + +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.system.services.service import Service, ServiceOperatingState + + +@pytest.fixture(scope="function") +def service_on_node() -> Tuple[Server, Service]: + server = Server( + hostname="server", ip_address="192.168.0.1", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON + ) + server.software_manager.install(TestService) + + service = server.software_manager.software["TestService"] + service.start() + + return server, service + + +def test_server_turns_off_service(service_on_node): + """Check that the service is turned off when the server is turned off""" + server, service = service_on_node + + assert server.operating_state is NodeOperatingState.ON + assert service.operating_state is ServiceOperatingState.RUNNING + + server.power_off() + + for i in range(server.shut_down_duration + 1): + server.apply_timestep(timestep=i) + + assert server.operating_state is NodeOperatingState.OFF + assert service.operating_state is ServiceOperatingState.STOPPED + + +def test_server_turns_on_service(service_on_node): + """Check that turning on the server turns on service.""" + pass diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py index f4546cbf..f3995c84 100644 --- a/tests/integration_tests/system/test_web_client_server.py +++ b/tests/integration_tests/system/test_web_client_server.py @@ -1,3 +1,4 @@ +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.http import HttpStatusCode @@ -47,6 +48,33 @@ def test_web_page_get_users_page_request_with_ip_address(uc2_network): assert web_client.get_webpage(f"http://{web_server_ip}/users/") is True - # latest reponse should have status code 200 + # latest response should have status code 200 assert web_client.latest_response is not None assert web_client.latest_response.status_code == HttpStatusCode.OK + + +def test_web_page_request_from_shut_down_server(uc2_network): + """Test to see that the web server does not respond when the server is off.""" + client_1: Computer = uc2_network.get_node_by_hostname("client_1") + web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] + web_client.run() + + web_server: Server = uc2_network.get_node_by_hostname("web_server") + + assert web_client.operating_state == ApplicationOperatingState.RUNNING + + assert web_client.get_webpage("http://arcd.com/users/") is True + + # latest response should have status code 200 + assert web_client.latest_response.status_code == HttpStatusCode.OK + + web_server.power_off() + + for i in range(web_server.shut_down_duration + 1): + uc2_network.apply_timestep(timestep=i) + + # node should be off + assert web_server.operating_state is NodeOperatingState.OFF + + assert web_client.get_webpage("http://arcd.com/users/") is False + assert web_client.latest_response.status_code == HttpStatusCode.NOT_FOUND diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py index d382b8dd..9957b6f6 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py @@ -3,6 +3,7 @@ from ipaddress import IPv4Address import pytest from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode @@ -15,17 +16,24 @@ from primaite.simulator.system.services.ftp.ftp_server import FTPServer @pytest.fixture(scope="function") def ftp_server() -> Node: node = Server( - hostname="ftp_server", ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + hostname="ftp_server", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, ) node.software_manager.install(software_class=FTPServer) - node.software_manager.software["FTPServer"].start() return node @pytest.fixture(scope="function") def ftp_client() -> Node: node = Computer( - hostname="ftp_client", ip_address="192.168.1.11", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + hostname="ftp_client", + ip_address="192.168.1.11", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, ) return node From dfe07ad92650c63d7478eea73881d9d88c35b4b0 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 23 Nov 2023 21:25:52 +0000 Subject: [PATCH 358/980] #2034 - Fixed deepcopy reference issue --- src/primaite/game/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index a7df1161..1167f3d4 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -281,7 +281,7 @@ class PrimaiteSession: self.episode_counter += 1 self.step_counter = 0 _LOGGER.debug(f"Restting primaite session, episode = {self.episode_counter}") - self.simulation = copy.deepcopy(self._simulation_initial_state) + self.simulation = deepcopy(self._simulation_initial_state) def close(self) -> None: """Close the session, this will stop the env and close the simulation.""" From f0fc6518a0edbb1685825acc5173393b626f8a73 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 23 Nov 2023 21:48:11 +0000 Subject: [PATCH 359/980] #2064: add handling of offline service to dns, ftp and database --- .../services/database/database_service.py | 3 ++ .../system/services/dns/dns_server.py | 4 ++ .../system/services/ftp/ftp_server.py | 4 +- .../system/services/web_server/web_server.py | 6 +-- src/primaite/simulator/system/software.py | 3 +- .../system/test_database_on_node.py | 30 ++++++++++++++- .../system/test_dns_client_server.py | 37 +++++++++++++++++++ .../_simulator/_system/_services/test_dns.py | 8 +++- 8 files changed, 86 insertions(+), 9 deletions(-) diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index d7277e1e..e3adb8e1 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -173,6 +173,9 @@ class DatabaseService(Service): :param session_id: The session identifier. :return: True if the Status Code is 200, otherwise False. """ + if not super().receive(payload=payload, session_id=session_id, **kwargs): + return False + result = {"status_code": 500, "data": []} if isinstance(payload, dict) and payload.get("type"): if payload["type"] == "connect_request": diff --git a/src/primaite/simulator/system/services/dns/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py index 90a350c8..2c8f3003 100644 --- a/src/primaite/simulator/system/services/dns/dns_server.py +++ b/src/primaite/simulator/system/services/dns/dns_server.py @@ -88,10 +88,14 @@ class DNSServer(Service): :return: True if DNS request returns a valid IP, otherwise, False """ + if not super().receive(payload=payload, session_id=session_id, **kwargs): + return False + # The payload should be a DNS packet if not isinstance(payload, DNSPacket): _LOGGER.debug(f"{payload} is not a DNSPacket") return False + # cast payload into a DNS packet payload: DNSPacket = payload if payload.dns_request is not None: diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index bc21dec3..cd128339 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -86,10 +86,10 @@ class FTPServer(FTPServiceABC): prevents an FTP request loop - FTP client and servers can exist on the same node. """ - if payload.status_code is not None: + if not super().receive(payload=payload, session_id=session_id, **kwargs): return False - if not super().receive(payload=payload, session_id=session_id, **kwargs): + if payload.status_code is not None: return False self.send(self._process_ftp_command(payload=payload, session_id=session_id), session_id) diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index 76176cd8..63df2f7d 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -155,12 +155,12 @@ class WebServer(Service): :param: payload: The payload to send. :param: session_id: The id of the session. Optional. """ + if not super().receive(payload=payload, session_id=session_id, **kwargs): + return False + # check if the payload is an HTTPPacket if not isinstance(payload, HttpRequestPacket): self.sys_log.error("Payload is not an HTTPPacket") return False - if not super().receive(payload=payload, session_id=session_id, **kwargs): - return False - return self._process_http_request(payload=payload, session_id=session_id) diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index c29bec20..830e3d79 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -3,7 +3,7 @@ from enum import Enum from ipaddress import IPv4Address from typing import Any, Dict, Optional -from primaite.simulator.core import RequestManager, RequestType, SimComponent +from primaite.simulator.core import _LOGGER, RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file_system import FileSystem, Folder from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.transmission.transport_layer import Port @@ -264,5 +264,6 @@ class IOSoftware(Software): """ # return false if node that software is on is off if self.software_manager and self.software_manager.node.operating_state is NodeOperatingState.OFF: + _LOGGER.debug(f"{self.name} Error: {self.software_manager.node.hostname} is not online.") return False return True diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 027fae4a..ef2b2956 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -1,9 +1,11 @@ from ipaddress import IPv4Address +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.ftp.ftp_server import FTPServer +from primaite.simulator.system.services.service import ServiceOperatingState def test_database_client_server_connection(uc2_network): @@ -55,7 +57,8 @@ def test_database_client_query(uc2_network): """Tests DB query across the network returns HTTP status 200 and date.""" web_server: Server = uc2_network.get_node_by_hostname("web_server") db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] - db_client.connect() + + assert db_client.connected assert db_client.query("SELECT") @@ -92,3 +95,28 @@ def test_restore_backup(uc2_network): assert db_service.restore_backup() is True assert db_service.file_system.get_file(folder_name="database", file_name="database.db") is not None + + +def test_database_client_cannot_query_offline_database_server(uc2_network): + """Tests DB query across the network returns HTTP status 404 when db server is offline.""" + db_server: Server = uc2_network.get_node_by_hostname("database_server") + db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + + assert db_server.operating_state is NodeOperatingState.ON + assert db_service.operating_state is ServiceOperatingState.RUNNING + + web_server: Server = uc2_network.get_node_by_hostname("web_server") + db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + assert db_client.connected + + assert db_client.query("SELECT") is True + + db_server.power_off() + + for i in range(db_server.shut_down_duration + 1): + uc2_network.apply_timestep(timestep=i) + + assert db_server.operating_state is NodeOperatingState.OFF + assert db_service.operating_state is ServiceOperatingState.STOPPED + + assert db_client.query("SELECT") is False diff --git a/tests/integration_tests/system/test_dns_client_server.py b/tests/integration_tests/system/test_dns_client_server.py index e82d97a4..81a223ef 100644 --- a/tests/integration_tests/system/test_dns_client_server.py +++ b/tests/integration_tests/system/test_dns_client_server.py @@ -1,3 +1,4 @@ +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.system.services.dns.dns_client import DNSClient @@ -24,3 +25,39 @@ def test_dns_client_server(uc2_network): # arcd.com is registered in dns server and should be saved to cache assert dns_client.check_domain_exists(target_domain="arcd.com") assert dns_client.dns_cache.get("arcd.com", None) is not None + + assert len(dns_client.dns_cache) == 1 + + +def test_dns_client_requests_offline_dns_server(uc2_network): + client_1: Computer = uc2_network.get_node_by_hostname("client_1") + domain_controller: Server = uc2_network.get_node_by_hostname("domain_controller") + + dns_client: DNSClient = client_1.software_manager.software["DNSClient"] + dns_server: DNSServer = domain_controller.software_manager.software["DNSServer"] + + assert dns_client.operating_state == ServiceOperatingState.RUNNING + assert dns_server.operating_state == ServiceOperatingState.RUNNING + + dns_server.show() + + # arcd.com is registered in dns server + assert dns_client.check_domain_exists(target_domain="arcd.com") + assert dns_client.dns_cache.get("arcd.com", None) is not None + + assert len(dns_client.dns_cache) == 1 + dns_client.dns_cache = {} + + domain_controller.power_off() + + for i in range(domain_controller.shut_down_duration + 1): + uc2_network.apply_timestep(timestep=i) + + assert domain_controller.operating_state == NodeOperatingState.OFF + assert dns_server.operating_state == ServiceOperatingState.STOPPED + + # this time it should not cache because dns server is not online + assert dns_client.check_domain_exists(target_domain="arcd.com") is False + assert dns_client.dns_cache.get("arcd.com", None) is None + + assert len(dns_client.dns_cache) == 0 diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py index dc6df5d4..469c8548 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py @@ -3,6 +3,7 @@ from ipaddress import IPv4Address import pytest from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.dns import DNSPacket, DNSReply, DNSRequest @@ -15,10 +16,13 @@ from primaite.simulator.system.services.dns.dns_server import DNSServer @pytest.fixture(scope="function") def dns_server() -> Node: node = Server( - hostname="dns_server", ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + hostname="dns_server", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, ) node.software_manager.install(software_class=DNSServer) - node.software_manager.software["DNSServer"].start() return node From 2ce03e0262a781741fa3cf6bbf5a4aacdf18bcc9 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 23 Nov 2023 22:10:53 +0000 Subject: [PATCH 360/980] #2064: turn on everything when node is turned on --- .../simulator/network/hardware/base.py | 12 ++- .../system/applications/application.py | 5 + .../red_services/data_manipulation_bot.py | 13 ++- tests/conftest.py | 6 ++ .../test_uc2_data_manipulation_scenario.py | 1 + .../system/test_app_service_on_node.py | 95 +++++++++++++++++++ .../system/test_service_on_node.py | 42 -------- 7 files changed, 126 insertions(+), 48 deletions(-) create mode 100644 tests/integration_tests/system/test_app_service_on_node.py delete mode 100644 tests/integration_tests/system/test_service_on_node.py diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index ebf669eb..ad101f1d 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1424,7 +1424,17 @@ class Node(SimComponent): def _start_up_actions(self): """Actions to perform when the node is starting up.""" - pass + # Turn on all the services in the node + for service_id in self.services: + self.services[service_id].start() + + # Turn on all the applications in the node + for app_id in self.applications: + self.applications[app_id].run() + + # Turn off all processes in the node + # for process_id in self.processes: + # self.processes[process_id] def __contains__(self, item: Any) -> bool: if isinstance(item, Service): diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index db323cf6..fb65354f 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -2,6 +2,7 @@ from abc import abstractmethod from enum import Enum from typing import Any, Dict, Set +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.system.software import IOSoftware, SoftwareHealthState @@ -61,6 +62,10 @@ class Application(IOSoftware): def run(self) -> None: """Open the Application.""" + if self.software_manager and self.software_manager.node.operating_state is not NodeOperatingState.ON: + self.sys_log.error(f"Unable to run application. {self.software_manager.node.hostname} is not turned on.") + return + if self.operating_state == ApplicationOperatingState.CLOSED: self.sys_log.info(f"Running Application {self.name}") self.operating_state = ApplicationOperatingState.RUNNING diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index 996e6790..f6662762 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -42,10 +42,13 @@ class DataManipulationBot(DatabaseClient): if self.server_ip_address and self.payload: self.sys_log.info(f"{self.name}: Attempting to start the {self.name}") super().run() - if not self.connected: - self.connect() - if self.connected: - self.query(self.payload) - self.sys_log.info(f"{self.name} payload delivered: {self.payload}") else: self.sys_log.error(f"Failed to start the {self.name} as it requires both a target_ip_address and payload.") + + def attack(self): + """Run the datab manipulation attack.""" + if not self.connected: + self.connect() + if self.connected: + self.query(self.payload) + self.sys_log.info(f"{self.name} payload delivered: {self.payload}") diff --git a/tests/conftest.py b/tests/conftest.py index 4cc36e6b..d39e96e0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -52,6 +52,12 @@ class TestService(Service): class TestApplication(Application): """Test Application class""" + def __init__(self, **kwargs): + kwargs["name"] = "TestApplication" + kwargs["port"] = Port.HTTP + kwargs["protocol"] = IPProtocol.TCP + super().__init__(**kwargs) + def describe_state(self) -> Dict: pass diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index 81bbfc96..fe7bab5f 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -23,6 +23,7 @@ def test_data_manipulation(uc2_network): # Now we run the DataManipulationBot db_manipulation_bot.run() + db_manipulation_bot.attack() # Now check that the DB client on the web_server cannot query the users table on the database assert not db_client.query("SELECT") diff --git a/tests/integration_tests/system/test_app_service_on_node.py b/tests/integration_tests/system/test_app_service_on_node.py new file mode 100644 index 00000000..cbcb4ff6 --- /dev/null +++ b/tests/integration_tests/system/test_app_service_on_node.py @@ -0,0 +1,95 @@ +from typing import Tuple + +import pytest +from conftest import TestApplication, TestService + +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.system.applications.application import Application, ApplicationOperatingState +from primaite.simulator.system.services.service import Service, ServiceOperatingState + + +@pytest.fixture(scope="function") +def populated_node() -> Tuple[Application, Server, Service]: + server = Server( + hostname="server", ip_address="192.168.0.1", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON + ) + server.software_manager.install(TestService) + server.software_manager.install(TestApplication) + + app = server.software_manager.software["TestApplication"] + app.run() + service = server.software_manager.software["TestService"] + service.start() + + return app, server, service + + +def test_server_turns_off_service(populated_node): + """Check that the service is turned off when the server is turned off""" + app, server, service = populated_node + + assert server.operating_state is NodeOperatingState.ON + assert service.operating_state is ServiceOperatingState.RUNNING + assert app.operating_state is ApplicationOperatingState.RUNNING + + server.power_off() + + for i in range(server.shut_down_duration + 1): + server.apply_timestep(timestep=i) + + assert server.operating_state is NodeOperatingState.OFF + assert service.operating_state is ServiceOperatingState.STOPPED + assert app.operating_state is ApplicationOperatingState.CLOSED + + +def test_service_cannot_be_turned_on_when_server_is_off(populated_node): + """Check that the service cannot be started when the server is off.""" + app, server, service = populated_node + + assert server.operating_state is NodeOperatingState.ON + assert service.operating_state is ServiceOperatingState.RUNNING + assert app.operating_state is ApplicationOperatingState.RUNNING + + server.power_off() + + for i in range(server.shut_down_duration + 1): + server.apply_timestep(timestep=i) + + assert server.operating_state is NodeOperatingState.OFF + assert service.operating_state is ServiceOperatingState.STOPPED + assert app.operating_state is ApplicationOperatingState.CLOSED + + service.start() + app.run() + + assert server.operating_state is NodeOperatingState.OFF + assert service.operating_state is ServiceOperatingState.STOPPED + assert app.operating_state is ApplicationOperatingState.CLOSED + + +def test_server_turns_on_service(populated_node): + """Check that turning on the server turns on service.""" + app, server, service = populated_node + + assert server.operating_state is NodeOperatingState.ON + assert service.operating_state is ServiceOperatingState.RUNNING + assert app.operating_state is ApplicationOperatingState.RUNNING + + server.power_off() + + for i in range(server.shut_down_duration + 1): + server.apply_timestep(timestep=i) + + assert server.operating_state is NodeOperatingState.OFF + assert service.operating_state is ServiceOperatingState.STOPPED + assert app.operating_state is ApplicationOperatingState.CLOSED + + server.power_on() + + for i in range(server.start_up_duration + 1): + server.apply_timestep(timestep=i) + + assert server.operating_state is NodeOperatingState.ON + assert service.operating_state is ServiceOperatingState.RUNNING + assert app.operating_state is ApplicationOperatingState.RUNNING diff --git a/tests/integration_tests/system/test_service_on_node.py b/tests/integration_tests/system/test_service_on_node.py deleted file mode 100644 index e596dcd8..00000000 --- a/tests/integration_tests/system/test_service_on_node.py +++ /dev/null @@ -1,42 +0,0 @@ -from typing import Tuple - -import pytest -from conftest import TestService - -from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.system.services.service import Service, ServiceOperatingState - - -@pytest.fixture(scope="function") -def service_on_node() -> Tuple[Server, Service]: - server = Server( - hostname="server", ip_address="192.168.0.1", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON - ) - server.software_manager.install(TestService) - - service = server.software_manager.software["TestService"] - service.start() - - return server, service - - -def test_server_turns_off_service(service_on_node): - """Check that the service is turned off when the server is turned off""" - server, service = service_on_node - - assert server.operating_state is NodeOperatingState.ON - assert service.operating_state is ServiceOperatingState.RUNNING - - server.power_off() - - for i in range(server.shut_down_duration + 1): - server.apply_timestep(timestep=i) - - assert server.operating_state is NodeOperatingState.OFF - assert service.operating_state is ServiceOperatingState.STOPPED - - -def test_server_turns_on_service(service_on_node): - """Check that turning on the server turns on service.""" - pass From 8aa743188f60fa95756d1076e8fa5415e89d8dc8 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 23 Nov 2023 22:28:08 +0000 Subject: [PATCH 361/980] #2064: fix layout of test so it passes in pipeline --- tests/conftest.py | 10 ++++++++++ .../system/test_app_service_on_node.py | 7 +++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d39e96e0..168ef3e8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -74,6 +74,11 @@ def service(file_system) -> TestService: ) +@pytest.fixture(scope="function") +def service_class(): + return TestService + + @pytest.fixture(scope="function") def application(file_system) -> TestApplication: return TestApplication( @@ -81,6 +86,11 @@ def application(file_system) -> TestApplication: ) +@pytest.fixture(scope="function") +def application_class(): + return TestApplication + + @pytest.fixture(scope="function") def file_system() -> FileSystem: return Node(hostname="fs_node").file_system diff --git a/tests/integration_tests/system/test_app_service_on_node.py b/tests/integration_tests/system/test_app_service_on_node.py index cbcb4ff6..7777a810 100644 --- a/tests/integration_tests/system/test_app_service_on_node.py +++ b/tests/integration_tests/system/test_app_service_on_node.py @@ -1,7 +1,6 @@ from typing import Tuple import pytest -from conftest import TestApplication, TestService from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.server import Server @@ -10,12 +9,12 @@ from primaite.simulator.system.services.service import Service, ServiceOperating @pytest.fixture(scope="function") -def populated_node() -> Tuple[Application, Server, Service]: +def populated_node(service_class, application_class) -> Tuple[Application, Server, Service]: server = Server( hostname="server", ip_address="192.168.0.1", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON ) - server.software_manager.install(TestService) - server.software_manager.install(TestApplication) + server.software_manager.install(service_class) + server.software_manager.install(application_class) app = server.software_manager.software["TestApplication"] app.run() From bd109a7cfc3fdbd1a5454fa6b7c6cc714f753e33 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 24 Nov 2023 09:14:55 +0000 Subject: [PATCH 362/980] Complete session->game rename refactor --- src/primaite/game/agent/actions.py | 24 +++--- src/primaite/game/agent/observations.py | 106 ++++++++++++------------ src/primaite/game/agent/rewards.py | 38 ++++----- src/primaite/game/game.py | 20 ++--- 4 files changed, 94 insertions(+), 94 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index c8095aa5..35468098 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -43,7 +43,7 @@ class AbstractAction(ABC): """Dictionary describing the number of options for each parameter of this action. The keys of this dict must align with the keyword args of the form_request method.""" self.manager: ActionManager = manager - """Reference to the ActionManager which created this action. This is used to access the session and simulation + """Reference to the ActionManager which created this action. This is used to access the game and simulation objects.""" @abstractmethod @@ -559,7 +559,7 @@ class ActionManager: def __init__( self, - session: "PrimaiteGame", # reference to session for looking up stuff + game: "PrimaiteGame", # reference to game for information lookup actions: List[str], # stores list of actions available to agent node_uuids: List[str], # allows mapping index to node max_folders_per_node: int = 2, # allows calculating shape @@ -574,8 +574,8 @@ class ActionManager: ) -> None: """Init method for ActionManager. - :param session: Reference to the session to which the agent belongs. - :type session: PrimaiteSession + :param game: Reference to the game to which the agent belongs. + :type game: PrimaiteGame :param actions: List of action types which should be made available to the agent. :type actions: List[str] :param node_uuids: List of node UUIDs that this agent can act on. @@ -599,8 +599,8 @@ class ActionManager: :param act_map: Action map which maps integers to actions. Used for restricting the set of possible actions. :type act_map: Optional[Dict[int, Dict]] """ - self.session: "PrimaiteGame" = session - self.sim: Simulation = self.session.simulation + self.game: "PrimaiteGame" = game + self.sim: Simulation = self.game.simulation self.node_uuids: List[str] = node_uuids self.protocols: List[str] = protocols self.ports: List[str] = ports @@ -826,7 +826,7 @@ class ActionManager: return nics[nic_idx] @classmethod - def from_config(cls, session: "PrimaiteGame", cfg: Dict) -> "ActionManager": + def from_config(cls, game: "PrimaiteGame", cfg: Dict) -> "ActionManager": """ Construct an ActionManager from a config definition. @@ -845,20 +845,20 @@ class ActionManager: These options are used to calculate the shape of the action space, and to provide additional information to the ActionManager which is required to convert the agent's action choice into a CAOS request. - :param session: The Primaite Session to which the agent belongs. - :type session: PrimaiteSession + :param game: The Primaite Game to which the agent belongs. + :type game: PrimaiteGame :param cfg: The action space config. :type cfg: Dict :return: The constructed ActionManager. :rtype: ActionManager """ obj = cls( - session=session, + game=game, actions=cfg["action_list"], # node_uuids=cfg["options"]["node_uuids"], **cfg["options"], - protocols=session.options.protocols, - ports=session.options.ports, + protocols=game.options.protocols, + ports=game.options.ports, ip_address_list=None, act_map=cfg.get("action_map"), ) diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index f57ec10d..14fb2fa7 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -37,10 +37,10 @@ class AbstractObservation(ABC): @classmethod @abstractmethod - def from_config(cls, config: Dict, session: "PrimaiteGame"): + def from_config(cls, config: Dict, game: "PrimaiteGame"): """Create this observation space component form a serialised format. - The `session` parameter is for a the PrimaiteSession object that spawns this component. During deserialisation, + The `game` parameter is for a the PrimaiteGame object that spawns this component. During deserialisation, a subclass of this class may need to translate from a 'reference' to a UUID. """ pass @@ -91,13 +91,13 @@ class FileObservation(AbstractObservation): return spaces.Dict({"health_status": spaces.Discrete(6)}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteGame", parent_where: List[str] = None) -> "FileObservation": + def from_config(cls, config: Dict, game: "PrimaiteGame", parent_where: List[str] = None) -> "FileObservation": """Create file observation from a config. :param config: Dictionary containing the configuration for this file observation. :type config: Dict - :param session: _description_ - :type session: PrimaiteSession + :param game: _description_ + :type game: PrimaiteGame :param parent_where: _description_, defaults to None :type parent_where: _type_, optional :return: _description_ @@ -149,20 +149,20 @@ class ServiceObservation(AbstractObservation): @classmethod def from_config( - cls, config: Dict, session: "PrimaiteGame", parent_where: Optional[List[str]] = None + cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]] = None ) -> "ServiceObservation": """Create service observation from a config. :param config: Dictionary containing the configuration for this service observation. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :param parent_where: Where in the simulation state dictionary this service's parent node is located. Optional. :type parent_where: Optional[List[str]], optional :return: Constructed service observation :rtype: ServiceObservation """ - return cls(where=parent_where + ["services", session.ref_map_services[config["service_ref"]].uuid]) + return cls(where=parent_where + ["services", game.ref_map_services[config["service_ref"]].uuid]) class LinkObservation(AbstractObservation): @@ -219,17 +219,17 @@ class LinkObservation(AbstractObservation): return spaces.Dict({"PROTOCOLS": spaces.Dict({"ALL": spaces.Discrete(11)})}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteGame") -> "LinkObservation": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "LinkObservation": """Create link observation from a config. :param config: Dictionary containing the configuration for this link observation. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :return: Constructed link observation :rtype: LinkObservation """ - return cls(where=["network", "links", session.ref_map_links[config["link_ref"]]]) + return cls(where=["network", "links", game.ref_map_links[config["link_ref"]]]) class FolderObservation(AbstractObservation): @@ -310,15 +310,15 @@ class FolderObservation(AbstractObservation): @classmethod def from_config( - cls, config: Dict, session: "PrimaiteGame", parent_where: Optional[List[str]], num_files_per_folder: int = 2 + cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]], num_files_per_folder: int = 2 ) -> "FolderObservation": """Create folder observation from a config. Also creates child file observations. :param config: Dictionary containing the configuration for this folder observation. Includes the name of the folder and the files inside of it. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :param parent_where: Where in the simulation state dictionary to find the information about this folder's parent node. A typical location for a node ``where`` can be: ['network','nodes',,'file_system'] @@ -332,7 +332,7 @@ class FolderObservation(AbstractObservation): where = parent_where + ["folders", config["folder_name"]] file_configs = config["files"] - files = [FileObservation.from_config(config=f, session=session, parent_where=where) for f in file_configs] + files = [FileObservation.from_config(config=f, game=game, parent_where=where) for f in file_configs] return cls(where=where, files=files, num_files_per_folder=num_files_per_folder) @@ -376,13 +376,13 @@ class NicObservation(AbstractObservation): return spaces.Dict({"nic_status": spaces.Discrete(3)}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteGame", parent_where: Optional[List[str]]) -> "NicObservation": + def from_config(cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]]) -> "NicObservation": """Create NIC observation from a config. :param config: Dictionary containing the configuration for this NIC observation. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :param parent_where: Where in the simulation state dictionary to find the information about this NIC's parent node. A typical location for a node ``where`` can be: ['network','nodes',] :type parent_where: Optional[List[str]] @@ -513,7 +513,7 @@ class NodeObservation(AbstractObservation): def from_config( cls, config: Dict, - session: "PrimaiteGame", + game: "PrimaiteGame", parent_where: Optional[List[str]] = None, num_services_per_node: int = 2, num_folders_per_node: int = 2, @@ -524,8 +524,8 @@ class NodeObservation(AbstractObservation): :param config: Dictionary containing the configuration for this node observation. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :param parent_where: Where in the simulation state dictionary to find the information about this node's parent network. A typical location for it would be: ['network',] :type parent_where: Optional[List[str]] @@ -541,24 +541,24 @@ class NodeObservation(AbstractObservation): :return: Constructed node observation :rtype: NodeObservation """ - node_uuid = session.ref_map_nodes[config["node_ref"]] + node_uuid = game.ref_map_nodes[config["node_ref"]] if parent_where is None: where = ["network", "nodes", node_uuid] else: where = parent_where + ["nodes", node_uuid] svc_configs = config.get("services", {}) - services = [ServiceObservation.from_config(config=c, session=session, parent_where=where) for c in svc_configs] + services = [ServiceObservation.from_config(config=c, game=game, parent_where=where) for c in svc_configs] folder_configs = config.get("folders", {}) folders = [ FolderObservation.from_config( - config=c, session=session, parent_where=where, num_files_per_folder=num_files_per_folder + config=c, game=game, parent_where=where, num_files_per_folder=num_files_per_folder ) for c in folder_configs ] - nic_uuids = session.simulation.network.nodes[node_uuid].nics.keys() + nic_uuids = game.simulation.network.nodes[node_uuid].nics.keys() nic_configs = [{"nic_uuid": n for n in nic_uuids}] if nic_uuids else [] - nics = [NicObservation.from_config(config=c, session=session, parent_where=where) for c in nic_configs] + nics = [NicObservation.from_config(config=c, game=game, parent_where=where) for c in nic_configs] logon_status = config.get("logon_status", False) return cls( where=where, @@ -692,13 +692,13 @@ class AclObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteGame") -> "AclObservation": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "AclObservation": """Generate ACL observation from a config. :param config: Dictionary containing the configuration for this ACL observation. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :return: Observation object :rtype: AclObservation """ @@ -707,15 +707,15 @@ class AclObservation(AbstractObservation): for ip_idx, ip_map_config in enumerate(config["ip_address_order"]): node_ref = ip_map_config["node_ref"] nic_num = ip_map_config["nic_num"] - node_obj = session.simulation.network.nodes[session.ref_map_nodes[node_ref]] + node_obj = game.simulation.network.nodes[game.ref_map_nodes[node_ref]] nic_obj = node_obj.ethernet_port[nic_num] node_ip_to_idx[nic_obj.ip_address] = ip_idx + 2 - router_uuid = session.ref_map_nodes[config["router_node_ref"]] + router_uuid = game.ref_map_nodes[config["router_node_ref"]] return cls( node_ip_to_id=node_ip_to_idx, - ports=session.options.ports, - protocols=session.options.protocols, + ports=game.options.ports, + protocols=game.options.protocols, where=["network", "nodes", router_uuid, "acl", "acl"], num_rules=max_acl_rules, ) @@ -738,7 +738,7 @@ class NullObservation(AbstractObservation): return spaces.Discrete(1) @classmethod - def from_config(cls, config: Dict, session: Optional["PrimaiteGame"] = None) -> "NullObservation": + def from_config(cls, config: Dict, game: Optional["PrimaiteGame"] = None) -> "NullObservation": """ Create null observation from a config. @@ -834,14 +834,14 @@ class UC2BlueObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteGame") -> "UC2BlueObservation": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "UC2BlueObservation": """Create UC2 blue observation from a config. :param config: Dictionary containing the configuration for this UC2 blue observation. This includes the nodes, links, ACL and ICS observations. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :return: Constructed UC2 blue observation :rtype: UC2BlueObservation """ @@ -853,7 +853,7 @@ class UC2BlueObservation(AbstractObservation): nodes = [ NodeObservation.from_config( config=n, - session=session, + game=game, num_services_per_node=num_services_per_node, num_folders_per_node=num_folders_per_node, num_files_per_folder=num_files_per_folder, @@ -863,13 +863,13 @@ class UC2BlueObservation(AbstractObservation): ] link_configs = config["links"] - links = [LinkObservation.from_config(config=link, session=session) for link in link_configs] + links = [LinkObservation.from_config(config=link, game=game) for link in link_configs] acl_config = config["acl"] - acl = AclObservation.from_config(config=acl_config, session=session) + acl = AclObservation.from_config(config=acl_config, game=game) ics_config = config["ics"] - ics = ICSObservation.from_config(config=ics_config, session=session) + ics = ICSObservation.from_config(config=ics_config, game=game) new = cls(nodes=nodes, links=links, acl=acl, ics=ics, where=["network"]) return new @@ -905,17 +905,17 @@ class UC2RedObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteGame") -> "UC2RedObservation": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "UC2RedObservation": """ Create UC2 red observation from a config. :param config: Dictionary containing the configuration for this UC2 red observation. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame """ node_configs = config["nodes"] - nodes = [NodeObservation.from_config(config=cfg, session=session) for cfg in node_configs] + nodes = [NodeObservation.from_config(config=cfg, game=game) for cfg in node_configs] return cls(nodes=nodes, where=["network"]) @@ -964,7 +964,7 @@ class ObservationManager: return self.obs.space @classmethod - def from_config(cls, config: Dict, session: "PrimaiteGame") -> "ObservationManager": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "ObservationManager": """Create observation space from a config. :param config: Dictionary containing the configuration for this observation space. @@ -972,14 +972,14 @@ class ObservationManager: UC2BlueObservation, UC2RedObservation, UC2GreenObservation) The other key is 'options' which are passed to the constructor of the selected observation class. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame """ if config["type"] == "UC2BlueObservation": - return cls(UC2BlueObservation.from_config(config.get("options", {}), session=session)) + return cls(UC2BlueObservation.from_config(config.get("options", {}), game=game)) elif config["type"] == "UC2RedObservation": - return cls(UC2RedObservation.from_config(config.get("options", {}), session=session)) + return cls(UC2RedObservation.from_config(config.get("options", {}), game=game)) elif config["type"] == "UC2GreenObservation": - return cls(UC2GreenObservation.from_config(config.get("options", {}), session=session)) + return cls(UC2GreenObservation.from_config(config.get("options", {}), game=game)) else: raise ValueError("Observation space type invalid") diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 60c3678c..8a1c2da4 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -47,13 +47,13 @@ class AbstractReward: @classmethod @abstractmethod - def from_config(cls, config: dict, session: "PrimaiteGame") -> "AbstractReward": + def from_config(cls, config: dict, game: "PrimaiteGame") -> "AbstractReward": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor :type config: dict - :param session: Reference to the PrimAITE Session object - :type session: PrimaiteSession + :param game: Reference to the PrimAITE Game object + :type game: PrimaiteGame :return: The reward component. :rtype: AbstractReward """ @@ -68,13 +68,13 @@ class DummyReward(AbstractReward): return 0.0 @classmethod - def from_config(cls, config: dict, session: "PrimaiteGame") -> "DummyReward": + def from_config(cls, config: dict, game: "PrimaiteGame") -> "DummyReward": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor. Should be empty. :type config: dict - :param session: Reference to the PrimAITE Session object - :type session: PrimaiteSession + :param game: Reference to the PrimAITE Game object + :type game: PrimaiteGame """ return cls() @@ -119,13 +119,13 @@ class DatabaseFileIntegrity(AbstractReward): return 0 @classmethod - def from_config(cls, config: Dict, session: "PrimaiteGame") -> "DatabaseFileIntegrity": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "DatabaseFileIntegrity": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor :type config: Dict - :param session: Reference to the PrimAITE Session object - :type session: PrimaiteSession + :param game: Reference to the PrimAITE Game object + :type game: PrimaiteGame :return: The reward component. :rtype: DatabaseFileIntegrity """ @@ -147,7 +147,7 @@ class DatabaseFileIntegrity(AbstractReward): f"{cls.__name__} could not be initialised from config because file_name parameter was not specified" ) return DummyReward() # TODO: better error handling - node_uuid = session.ref_map_nodes[node_ref] + node_uuid = game.ref_map_nodes[node_ref] if not node_uuid: _LOGGER.error( ( @@ -193,13 +193,13 @@ class WebServer404Penalty(AbstractReward): return 0.0 @classmethod - def from_config(cls, config: Dict, session: "PrimaiteGame") -> "WebServer404Penalty": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "WebServer404Penalty": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor :type config: Dict - :param session: Reference to the PrimAITE Session object - :type session: PrimaiteSession + :param game: Reference to the PrimAITE Game object + :type game: PrimaiteGame :return: The reward component. :rtype: WebServer404Penalty """ @@ -212,8 +212,8 @@ class WebServer404Penalty(AbstractReward): ) _LOGGER.warn(msg) return DummyReward() # TODO: should we error out with incorrect inputs? Probably! - node_uuid = session.ref_map_nodes[node_ref] - service_uuid = session.ref_map_services[service_ref].uuid + node_uuid = game.ref_map_nodes[node_ref] + service_uuid = game.ref_map_services[service_ref].uuid if not (node_uuid and service_uuid): msg = ( f"{cls.__name__} could not be initialised because node {node_ref} and service {service_ref} were not" @@ -265,13 +265,13 @@ class RewardFunction: return self.current_reward @classmethod - def from_config(cls, config: Dict, session: "PrimaiteGame") -> "RewardFunction": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "RewardFunction": """Create a reward function from a config dictionary. :param config: dict of options for the reward manager's constructor :type config: Dict - :param session: Reference to the PrimAITE Session object - :type session: PrimaiteSession + :param game: Reference to the PrimAITE Game object + :type game: PrimaiteGame :return: The reward manager. :rtype: RewardFunction """ @@ -281,6 +281,6 @@ class RewardFunction: rew_type = rew_component_cfg["type"] weight = rew_component_cfg.get("weight", 1.0) rew_class = cls.__rew_class_identifiers[rew_type] - rew_instance = rew_class.from_config(config=rew_component_cfg.get("options", {}), session=session) + rew_instance = rew_class.from_config(config=rew_component_cfg.get("options", {}), game=game) new.regsiter_component(component=rew_instance, weight=weight) return new diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index e260285f..fa17b94b 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -1,4 +1,4 @@ -"""PrimAITE session - the main entry point to training agents on PrimAITE.""" +"""PrimAITE game - Encapsulates the simulation and agents.""" from ipaddress import IPv4Address from typing import Dict, List @@ -52,7 +52,7 @@ class PrimaiteGame: """ def __init__(self): - """Initialise a PrimaiteSession object.""" + """Initialise a PrimaiteGame object.""" self.simulation: Simulation = Simulation() """Simulation object with which the agents will interact.""" @@ -101,7 +101,7 @@ class PrimaiteGame: single-agent gym, make sure to update the ProxyAgent's action with the action before calling ``self.apply_agent_actions()``. """ - _LOGGER.debug(f"Stepping primaite session. Step counter: {self.step_counter}") + _LOGGER.debug(f"Stepping. Step counter: {self.step_counter}") # Get the current state of the simulation sim_state = self.get_sim_state() @@ -149,14 +149,14 @@ class PrimaiteGame: return False def reset(self) -> None: - """Reset the session, this will reset the simulation.""" + """Reset the game, this will reset the simulation.""" self.episode_counter += 1 self.step_counter = 0 - _LOGGER.debug(f"Restting primaite session, episode = {self.episode_counter}") + _LOGGER.debug(f"Restting primaite game, episode = {self.episode_counter}") self.simulation.reset_component_for_episode(self.episode_counter) def close(self) -> None: - """Close the session, this will stop the env and close the simulation.""" + """Close the game, this will close the simulation.""" return NotImplemented @classmethod @@ -165,7 +165,7 @@ class PrimaiteGame: The config dictionary should have the following top-level keys: 1. training_config: options for training the RL agent. - 2. game_config: options for the game itself. Used by PrimaiteSession. + 2. game_config: options for the game itself. Used by PrimaiteGame. 3. simulation: defines the network topology and the initial state of the simulation. The specification for each of the three major areas is described in a separate documentation page. @@ -173,8 +173,8 @@ class PrimaiteGame: :param cfg: The config dictionary. :type cfg: dict - :return: A PrimaiteSession object. - :rtype: PrimaiteSession + :return: A PrimaiteGame object. + :rtype: PrimaiteGame """ game = cls() game.options = PrimaiteGameOptions(**cfg["game"]) @@ -339,7 +339,7 @@ class PrimaiteGame: action_space = ActionManager.from_config(game, action_space_cfg) # CREATE REWARD FUNCTION - rew_function = RewardFunction.from_config(reward_function_cfg, session=game) + rew_function = RewardFunction.from_config(reward_function_cfg, game=game) # CREATE AGENT if agent_type == "GreenWebBrowsingAgent": From 50c9ef16cbca4757a493e67bf4632fe1c984a55d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 24 Nov 2023 09:18:18 +0000 Subject: [PATCH 363/980] Move policy module into session --- src/primaite/game/policy/__init__.py | 4 ---- src/primaite/session/policy/__init__.py | 4 ++++ src/primaite/{game => session}/policy/policy.py | 0 src/primaite/{game => session}/policy/rllib.py | 2 +- src/primaite/{game => session}/policy/sb3.py | 2 +- src/primaite/session/session.py | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 src/primaite/game/policy/__init__.py create mode 100644 src/primaite/session/policy/__init__.py rename src/primaite/{game => session}/policy/policy.py (100%) rename src/primaite/{game => session}/policy/rllib.py (98%) rename src/primaite/{game => session}/policy/sb3.py (98%) diff --git a/src/primaite/game/policy/__init__.py b/src/primaite/game/policy/__init__.py deleted file mode 100644 index 9c0e4199..00000000 --- a/src/primaite/game/policy/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from primaite.game.policy.rllib import RaySingleAgentPolicy -from primaite.game.policy.sb3 import SB3Policy - -__all__ = ["SB3Policy", "RaySingleAgentPolicy"] diff --git a/src/primaite/session/policy/__init__.py b/src/primaite/session/policy/__init__.py new file mode 100644 index 00000000..811c7a54 --- /dev/null +++ b/src/primaite/session/policy/__init__.py @@ -0,0 +1,4 @@ +from primaite.session.policy.rllib import RaySingleAgentPolicy +from primaite.session.policy.sb3 import SB3Policy + +__all__ = ["SB3Policy", "RaySingleAgentPolicy"] diff --git a/src/primaite/game/policy/policy.py b/src/primaite/session/policy/policy.py similarity index 100% rename from src/primaite/game/policy/policy.py rename to src/primaite/session/policy/policy.py diff --git a/src/primaite/game/policy/rllib.py b/src/primaite/session/policy/rllib.py similarity index 98% rename from src/primaite/game/policy/rllib.py rename to src/primaite/session/policy/rllib.py index fcebf40d..7ba3edd0 100644 --- a/src/primaite/game/policy/rllib.py +++ b/src/primaite/session/policy/rllib.py @@ -1,8 +1,8 @@ from pathlib import Path from typing import Literal, Optional, TYPE_CHECKING -from primaite.game.policy.policy import PolicyABC from primaite.session.environment import PrimaiteRayEnv, PrimaiteRayMARLEnv +from primaite.session.policy.policy import PolicyABC if TYPE_CHECKING: from primaite.session.session import PrimaiteSession, TrainingOptions diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/session/policy/sb3.py similarity index 98% rename from src/primaite/game/policy/sb3.py rename to src/primaite/session/policy/sb3.py index 64eebfc7..051e2770 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/session/policy/sb3.py @@ -8,7 +8,7 @@ from stable_baselines3.common.callbacks import CheckpointCallback from stable_baselines3.common.evaluation import evaluate_policy from stable_baselines3.ppo import MlpPolicy as PPO_MLP -from primaite.game.policy.policy import PolicyABC +from primaite.session.policy.policy import PolicyABC if TYPE_CHECKING: from primaite.session.session import PrimaiteSession, TrainingOptions diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py index 9f567a95..80b63ba7 100644 --- a/src/primaite/session/session.py +++ b/src/primaite/session/session.py @@ -5,12 +5,12 @@ from typing import Dict, List, Literal, Optional, Union from pydantic import BaseModel, ConfigDict from primaite.game.game import PrimaiteGame - -# from primaite.game.game import PrimaiteGame -from primaite.game.policy.policy import PolicyABC from primaite.session.environment import PrimaiteGymEnv, PrimaiteRayEnv, PrimaiteRayMARLEnv from primaite.session.io import SessionIO, SessionIOSettings +# from primaite.game.game import PrimaiteGame +from primaite.session.policy.policy import PolicyABC + class TrainingOptions(BaseModel): """Options for training the RL agent.""" From b13a9d3daf34f38992b19f7854cbbf0eeb3e2723 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Fri, 24 Nov 2023 09:25:55 +0000 Subject: [PATCH 364/980] Add application execution action for data manipulation bot --- .../config/_package_data/example_config.yaml | 9 ++++++--- src/primaite/game/agent/actions.py | 7 +++---- src/primaite/game/session.py | 14 ++++++++++++++ .../system/applications/database_client.py | 2 +- .../services/red_services/data_manipulation_bot.py | 2 +- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index aff54d62..8ea1c83c 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -67,8 +67,8 @@ game_config: observations: - logon_status - operating_status - services: - - service_ref: data_manipulation_bot + applications: + - application_ref: data_manipulation_bot observations: operating_status health_status @@ -89,6 +89,8 @@ game_config: options: nodes: - node_ref: client_1 + applications: + - application_ref: data_manipulation_bot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -650,7 +652,7 @@ simulation: subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 - services: + applications: - ref: data_manipulation_bot type: DataManipulationBot options: @@ -658,6 +660,7 @@ simulation: data_manipulation_p_of_success: 0.1 payload: "DROP TABLE IF EXISTS user;" server_ip: 192.168.1.14 + services: - ref: client_1_dns_client type: DNSClient diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 0c78dac7..64d89722 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -594,6 +594,7 @@ class ActionManager: session: "PrimaiteSession", # reference to session for looking up stuff actions: List[str], # stores list of actions available to agent node_uuids: List[str], # allows mapping index to node + application_uuids: List[List[str]], # allows mapping index to application max_folders_per_node: int = 2, # allows calculating shape max_files_per_folder: int = 2, # allows calculating shape max_services_per_node: int = 2, # allows calculating shape @@ -635,6 +636,7 @@ class ActionManager: self.session: "PrimaiteSession" = session self.sim: Simulation = self.session.simulation self.node_uuids: List[str] = node_uuids + self.application_uuids: List[List[str]] = application_uuids self.protocols: List[str] = protocols self.ports: List[str] = ports @@ -819,10 +821,7 @@ class ActionManager: :return: The UUID of the service. Or None if the node has fewer services than the given index. :rtype: Optional[str] """ - node_uuid = self.get_node_uuid_by_idx(node_idx) - node = self.sim.network.nodes[node_uuid] - application_uuids = list(node.applications.keys()) - return application_uuids[application_idx] if len(application_uuids) > application_idx else None + return self.application_uuids[node_idx][application_idx] def get_internet_protocol_by_idx(self, protocol_idx: int) -> str: """Get the internet protocol corresponding to the given index. diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index f675e33c..cc4036ef 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -426,11 +426,25 @@ class PrimaiteSession: # CREATE ACTION SPACE action_space_cfg["options"]["node_uuids"] = [] + action_space_cfg["options"]["application_uuids"] = [] + # if a list of nodes is defined, convert them from node references to node UUIDs for action_node_option in action_space_cfg.get("options", {}).pop("nodes", {}): if "node_ref" in action_node_option: node_uuid = sess.ref_map_nodes[action_node_option["node_ref"]] action_space_cfg["options"]["node_uuids"].append(node_uuid) + + if "applications" in action_node_option: + node_application_uuids = [] + for application_option in action_node_option["applications"]: + # TODO: remove inconsistency with the above nodes + application_uuid = sess.ref_map_applications[application_option["application_ref"]].uuid + node_application_uuids.append(application_uuid) + + action_space_cfg["options"]["application_uuids"].append(node_application_uuids) + else: + action_space_cfg["options"]["application_uuids"].append([]) + # Each action space can potentially have a different list of nodes that it can apply to. Therefore, # we will pass node_uuids as a part of the action space config. # However, it's not possible to specify the node uuids directly in the config, as they are generated diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index e15249e3..9d85221e 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -141,7 +141,7 @@ class DatabaseClient(Application): :param sql: The SQL query. :return: True if the query was successful, otherwise False. """ - if self.connected and self.operating_state.RUNNING: + if self.connected and self.operating_state == ApplicationOperatingState.RUNNING: query_id = str(uuid4()) # Initialise the tracker of this ID to False diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index f4b31cb1..0ec64950 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -50,7 +50,7 @@ class DataManipulationBot(DatabaseClient): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() - rm.add_request(name="execute", request_type=RequestType(func=self.execute)) + rm.add_request(name="execute", request_type=RequestType(func=lambda request, context: self.execute())) return rm From 6754dbf54166d52d248f3b3218bd46138ec56bc1 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 24 Nov 2023 09:28:50 +0000 Subject: [PATCH 365/980] Remove GATE and fix a few spelling mistakes. --- docs/source/primaite_session.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/primaite_session.rst b/docs/source/primaite_session.rst index a0b53c7d..f3ef0399 100644 --- a/docs/source/primaite_session.rst +++ b/docs/source/primaite_session.rst @@ -19,7 +19,7 @@ module directly without running a session. Run --- -A PrimAITE session can started either with the ``primaite session`` command from the cli +A PrimAITE session can be started either with the ``primaite session`` command from the cli (See :func:`primaite.cli.session`), or by calling :func:`primaite.main.run` from a Python terminal or Jupyter Notebook. There are two parameters that can be specified: @@ -29,6 +29,6 @@ There are two parameters that can be specified: Outputs ------- -Running a session creates a session outputs directory in your user data foler. The format looks like this: -``~/primaite/3.0.0/sessions/YYYY-MM-DD/HH-MM-SS/``. This folders contains simulation sys logs generated by each node, -and the saved agent checkpoints, and final model. +Running a session creates a session output directory in your user data folder. The filepath looks like this: +``~/primaite/3.0.0/sessions/YYYY-MM-DD/HH-MM-SS/``. This folder contains the simulation sys logs generated by each node, +the saved agent checkpoints, and final model. From abba1ef86b26928cda91f147cc6cba61097c4c2f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 24 Nov 2023 09:37:26 +0000 Subject: [PATCH 366/980] Remove hardcoded checkpoint frequency in rllib --- src/primaite/session/policy/rllib.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/primaite/session/policy/rllib.py b/src/primaite/session/policy/rllib.py index 7ba3edd0..be181797 100644 --- a/src/primaite/session/policy/rllib.py +++ b/src/primaite/session/policy/rllib.py @@ -78,17 +78,18 @@ class RayMultiAgentPolicy(PolicyABC, identifier="RLLIB_multi_agent"): def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: """Train the agent.""" + checkpoint_freq = self.session.io_manager.settings.checkpoint_interval tune.Tuner( "PPO", run_config=air.RunConfig( stop={"training_iteration": n_episodes * timesteps_per_episode}, - checkpoint_config=air.CheckpointConfig(checkpoint_frequency=10), + checkpoint_config=air.CheckpointConfig(checkpoint_frequency=checkpoint_freq), ), param_space=self.config, ).fit() def load(self, model_path: Path) -> None: - """Load policy paramters from a file.""" + """Load policy parameters from a file.""" return NotImplemented def eval(self, n_episodes: int, deterministic: bool) -> None: From 92dabe59f7d31a270d7e4b937e3075eeb114f913 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Fri, 24 Nov 2023 10:04:19 +0000 Subject: [PATCH 367/980] Fix data manipulation bot configuration --- src/primaite/game/session.py | 26 +++++++++++-------- .../red_services/data_manipulation_bot.py | 4 +-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index cc4036ef..286de498 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -331,6 +331,7 @@ class PrimaiteSession: print("invalid node type") if "services" in node_cfg: for service_cfg in node_cfg["services"]: + new_service = None service_ref = service_cfg["ref"] service_type = service_cfg["type"] service_types_mapping = { @@ -339,7 +340,6 @@ class PrimaiteSession: "DatabaseClient": DatabaseClient, "DatabaseService": DatabaseService, "WebServer": WebServer, - "DataManipulationBot": DataManipulationBot, } if service_type in service_types_mapping: print(f"installing {service_type} on node {new_node.hostname}") @@ -360,22 +360,15 @@ class PrimaiteSession: if "domain_mapping" in opt: for domain, ip in opt["domain_mapping"].items(): new_service.dns_register(domain, ip) - if service_type == "DataManipulationBot": - if "options" in service_cfg: - opt = service_cfg["options"] - new_service.configure( - server_ip_address=opt.get("server_ip"), - payload=opt.get("payload"), - port_scan_p_of_success=float(opt.get("port_scan_p_of_success", "0.1")), - data_manipulation_p_of_success=float(opt.get("data_manipulation_p_of_success", "0.1")), - ) if "applications" in node_cfg: for application_cfg in node_cfg["applications"]: + new_application = None application_ref = application_cfg["ref"] application_type = application_cfg["type"] application_types_mapping = { "WebBrowser": WebBrowser, + "DataManipulationBot": DataManipulationBot, } if application_type in application_types_mapping: new_node.software_manager.install(application_types_mapping[application_type]) @@ -383,6 +376,16 @@ class PrimaiteSession: sess.ref_map_applications[application_ref] = new_application else: print(f"application type not found {application_type}") + + if application_type == "DataManipulationBot": + if "options" in application_cfg: + opt = application_cfg["options"] + new_application.configure( + server_ip_address=opt.get("server_ip"), + payload=opt.get("payload"), + port_scan_p_of_success=float(opt.get("port_scan_p_of_success", "0.1")), + data_manipulation_p_of_success=float(opt.get("data_manipulation_p_of_success", "0.1")), + ) if "nics" in node_cfg: for nic_num, nic_cfg in node_cfg["nics"].items(): new_node.connect_nic(NIC(ip_address=nic_cfg["ip_address"], subnet_mask=nic_cfg["subnet_mask"])) @@ -437,7 +440,8 @@ class PrimaiteSession: if "applications" in action_node_option: node_application_uuids = [] for application_option in action_node_option["applications"]: - # TODO: remove inconsistency with the above nodes + # TODO: fix inconsistency with node uuids and application uuids. The node object get added to + # node_uuid, whereas here the application gets added by uuid. application_uuid = sess.ref_map_applications[application_option["application_ref"]].uuid node_application_uuids.append(application_uuid) diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index 0ec64950..2b0bed30 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -159,8 +159,8 @@ class DataManipulationBot(DatabaseClient): if self.server_ip_address and self.payload and self.operating_state: self.sys_log.info(f"{self.name}: Running") self._logon() - self._perform_port_scan(p_of_success=self.execution_definition.port_scan_p_of_success) - self._perform_data_manipulation(p_of_success=self.execution_definition.data_manipulation_p_of_success) + self._perform_port_scan(p_of_success=self.port_scan_p_of_success) + self._perform_data_manipulation(p_of_success=self.data_manipulation_p_of_success) if self.repeat and self.attack_stage in ( DataManipulationAttackStage.COMPLETE, From 178d911be005fc7f888d1aa1e679d6268a66cda3 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Fri, 24 Nov 2023 10:05:36 +0000 Subject: [PATCH 368/980] Update data manipulation bot --- .../system/data_manipulation_bot.rst | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/source/simulation_components/system/data_manipulation_bot.rst b/docs/source/simulation_components/system/data_manipulation_bot.rst index c9f8977a..e93c4e54 100644 --- a/docs/source/simulation_components/system/data_manipulation_bot.rst +++ b/docs/source/simulation_components/system/data_manipulation_bot.rst @@ -8,6 +8,8 @@ DataManipulationBot The ``DataManipulationBot`` class provides functionality to connect to a ``DatabaseService`` and execute malicious SQL statements. +The bot is controlled by a ``DataManipulationAgent``. + Overview -------- @@ -16,15 +18,25 @@ The bot is intended to simulate a malicious actor carrying out attacks like: - Dropping tables - Deleting records - Modifying data + On a database server by abusing an application's trusted database connectivity. +The bot performs attacks in the following stages to simulate the real pattern of an attack: + +- Logon - *The bot gains access to the node.* +- Port Scan - *The bot finds accessible database servers on the network.* +- Attacking - *The bot delivers the payload to the discovered database servers.* + +Each of these stages has a random, configurable probability of succeeding. The bot can also be configured to repeat the attack once complete. + Usage ----- - Create an instance and call ``configure`` to set: - - Target database server IP - - Database password (if needed) - - SQL statement payload + - Target database server IP + - Database password (if needed) + - SQL statement payload + - Probabilities for succeeding each of the above attack stages - Call ``run`` to connect and execute the statement. The bot handles connecting, executing the statement, and disconnecting. @@ -52,7 +64,7 @@ Implementation The bot extends ``DatabaseClient`` and leverages its connectivity. - Uses the Application base class for lifecycle management. -- Credentials and target IP set via ``configure``. +- Credentials, target IP and other options set via ``configure``. - ``run`` handles connecting, executing statement, and disconnecting. - SQL payload executed via ``query`` method. - Results in malicious SQL being executed on remote database server. From d8975078b32b72bff5b36bb2c209ff327cab1d54 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 24 Nov 2023 10:50:10 +0000 Subject: [PATCH 369/980] Fix game reset test. --- tests/e2e_integration_tests/test_primaite_session.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index 17d8a4d1..5ca99cfc 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -79,12 +79,12 @@ class TestPrimaiteSession: def test_session_sim_reset(self, temp_primaite_session): with temp_primaite_session as session: session: TempPrimaiteSession - client_1 = session.simulation.network.get_node_by_hostname("client_1") + client_1 = session.game.simulation.network.get_node_by_hostname("client_1") client_1.software_manager.uninstall("DataManipulationBot") assert "DataManipulationBot" not in client_1.software_manager.software - session.reset() - client_1 = session.simulation.network.get_node_by_hostname("client_1") + session.game.reset() + client_1 = session.game.simulation.network.get_node_by_hostname("client_1") assert "DataManipulationBot" in client_1.software_manager.software From ff8b773c102243549d66eeaa357fa56df9be4094 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Fri, 24 Nov 2023 11:10:34 +0000 Subject: [PATCH 370/980] Database Manipulation Bot bug fixes --- .../config/_package_data/example_config.yaml | 2 +- src/primaite/game/agent/interface.py | 4 +- src/primaite/simulator/network/networks.py | 7 ++- .../system/applications/database_client.py | 4 +- .../red_services/data_manipulation_bot.py | 8 +-- .../assets/configs/bad_primaite_session.yaml | 51 ++++++++++++------- .../configs/eval_only_primaite_session.yaml | 45 +++++++++------- .../assets/configs/test_primaite_session.yaml | 41 ++++++++------- .../configs/train_only_primaite_session.yaml | 45 +++++++++------- 9 files changed, 124 insertions(+), 83 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 270760f5..af872a01 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -665,7 +665,7 @@ simulation: options: port_scan_p_of_success: 0.1 data_manipulation_p_of_success: 0.1 - payload: "DROP TABLE IF EXISTS user;" + payload: "DELETE" server_ip: 192.168.1.14 services: - ref: client_1_dns_client diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index ff0986a8..38116987 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -58,7 +58,7 @@ class AbstractAgent(ABC): action_space: Optional[ActionManager], observation_space: Optional[ObservationManager], reward_function: Optional[RewardFunction], - agent_settings: Optional[AgentSettings], + agent_settings: Optional[AgentSettings] = None, ) -> None: """ Initialize an agent. @@ -217,7 +217,7 @@ class DataManipulationAgent(AbstractScriptedAgent): :return: _description_ :rtype: Tuple[str, Dict] """ - current_timestep = self.action_space.session.step_counter + current_timestep = self.action_manager.session.step_counter if current_timestep < self.next_execution_timestep: return "DONOTHING", {"dummy": 0} diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index c0f9a07e..ea767b54 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -140,7 +140,12 @@ def arcd_uc2_network() -> Network: network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) client_1.software_manager.install(DataManipulationBot) db_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] - db_manipulation_bot.configure(server_ip_address=IPv4Address("192.168.1.14"), payload="DELETE") + db_manipulation_bot.configure( + server_ip_address=IPv4Address("192.168.1.14"), + payload="DELETE", + port_scan_p_of_success=1.0, + data_manipulation_p_of_success=1.0, + ) # Client 2 client_2 = Computer( diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index a5c213cd..da2299c4 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -129,9 +129,9 @@ class DatabaseClient(Application): ) return self._query(sql=sql, query_id=query_id, is_reattempt=True) - def execute(self) -> None: + def run(self) -> None: """Run the DatabaseClient.""" - super().execute() + super().run() if self.operating_state == ApplicationOperatingState.RUNNING: self.connect() diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index 2b0bed30..17b89386 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -50,7 +50,7 @@ class DataManipulationBot(DatabaseClient): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() - rm.add_request(name="execute", request_type=RequestType(func=lambda request, context: self.execute())) + rm.add_request(name="execute", request_type=RequestType(func=lambda request, context: self.run())) return rm @@ -139,13 +139,13 @@ class DataManipulationBot(DatabaseClient): self.sys_log.info(f"{self.name}: Data manipulation failed") self.attack_stage = DataManipulationAttackStage.FAILED - def execute(self): + def run(self): """ - Execute the Data Manipulation Bot. + Run the Data Manipulation Bot. Calls the parent classes execute method before starting the application loop. """ - super().execute() + super().run() self._application_loop() def _application_loop(self): diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 80567aea..6344eac0 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -2,9 +2,17 @@ training_config: rl_framework: SB3 rl_algorithm: PPO se3ed: 333 # Purposeful typo to check that error is raised with bad configuration. - n_learn_steps: 2560 + n_learn_episodes: 25 n_eval_episodes: 5 + max_steps_per_episode: 128 + deterministic_eval: false + n_agents: 1 + agent_references: + - defender +io_settings: + save_checkpoints: true + checkpoint_interval: 5 game_config: @@ -49,9 +57,10 @@ game_config: - type: DUMMY agent_settings: - start_step: 5 - frequency: 4 - variance: 3 + start_settings: + start_step: 5 + frequency: 4 + variance: 3 - ref: client_1_data_manipulation_red_bot team: RED @@ -65,8 +74,8 @@ game_config: observations: - logon_status - operating_status - services: - - service_ref: data_manipulation_bot + applications: + - application_ref: data_manipulation_bot observations: operating_status health_status @@ -76,22 +85,19 @@ game_config: action_list: - type: DONOTHING # Date: Fri, 24 Nov 2023 11:21:25 +0000 Subject: [PATCH 371/980] #2068: Remove duplicated index entries. --- docs/source/simulation.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index 5e259c6f..e5c0d2c8 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -23,8 +23,3 @@ Contents simulation_components/network/network simulation_components/system/internal_frame_processing simulation_components/system/software - simulation_components/system/data_manipulation_bot - simulation_components/system/database_client_server - simulation_components/system/dns_client_server - simulation_components/system/ftp_client_server - simulation_components/system/web_browser_and_web_server_service From dfb08b8cf31ba15801f1a1770a4df1cf46617638 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 24 Nov 2023 11:52:33 +0000 Subject: [PATCH 372/980] #1859 - DB query now returns false if the query isn't ran due to the node being off --- src/primaite/game/agent/interface.py | 5 +---- .../simulator/system/applications/database_client.py | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 38116987..b321b17c 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -1,9 +1,8 @@ """Interface for agents.""" import random from abc import ABC, abstractmethod -from typing import Dict, List, Optional, Tuple, TYPE_CHECKING, TypeAlias, Union +from typing import Dict, List, Optional, Tuple, TYPE_CHECKING -import numpy as np from gymnasium.core import ActType, ObsType from pydantic import BaseModel @@ -14,8 +13,6 @@ from primaite.game.agent.rewards import RewardFunction if TYPE_CHECKING: from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot -ObsType: TypeAlias = Union[Dict, np.ndarray] - class AgentStartSettings(BaseModel): """Configuration values for when an agent starts performing actions.""" diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index da2299c4..3c4f1b75 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -148,6 +148,7 @@ class DatabaseClient(Application): # Initialise the tracker of this ID to False self._query_success_tracker[query_id] = False return self._query(sql=sql, query_id=query_id) + return False def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ From 64c7dd3c84394e3f5831d55d22939ddb3c9b0b71 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 24 Nov 2023 12:03:46 +0000 Subject: [PATCH 373/980] Skip slow tests for now. --- .../environments/test_rllib_multi_agent_environment.py | 2 ++ .../environments/test_rllib_single_agent_environment.py | 2 ++ tests/e2e_integration_tests/test_primaite_session.py | 1 + 3 files changed, 5 insertions(+) diff --git a/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py b/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py index 0cf245b4..3934ce5b 100644 --- a/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py +++ b/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py @@ -1,3 +1,4 @@ +import pytest import ray import yaml from ray import air, tune @@ -8,6 +9,7 @@ from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteRayMARLEnv +@pytest.mark.skip(reason="Slow, reenable later") def test_rllib_multi_agent_compatibility(): """Test that the PrimaiteRayEnv class can be used with a multi agent RLLIB system.""" diff --git a/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py b/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py index ce23501a..2b12ad98 100644 --- a/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py +++ b/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py @@ -1,6 +1,7 @@ import tempfile from pathlib import Path +import pytest import ray import yaml from ray.rllib.algorithms import ppo @@ -10,6 +11,7 @@ from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteRayEnv +@pytest.mark.skip(reason="Slow, reenable later") def test_rllib_single_agent_compatibility(): """Test that the PrimaiteRayEnv class can be used with a single agent RLLIB system.""" with open(example_config_path(), "r") as f: diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index 5ca99cfc..086e9af8 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -65,6 +65,7 @@ class TestPrimaiteSession: session.start_session() # TODO: include checks that the model was loaded and that the eval-only session ran + @pytest.mark.skip(reason="Slow, reenable later") @pytest.mark.parametrize("temp_primaite_session", [[MULTI_AGENT_PATH]], indirect=True) def test_multi_agent_session(self, temp_primaite_session): """Check that we can run a training session with a multi agent system.""" From e609f8eb50e935515a0d63ad85e9321404f8fd98 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 24 Nov 2023 14:56:17 +0000 Subject: [PATCH 374/980] Fix misconfiguration in uc2 config and session --- .../config/_package_data/example_config.yaml | 18 +++++++++-- src/primaite/game/session.py | 31 ++++++++++++++++--- .../assets/configs/bad_primaite_session.yaml | 18 +++++++++-- .../configs/eval_only_primaite_session.yaml | 18 +++++++++-- .../assets/configs/test_primaite_session.yaml | 18 +++++++++-- .../configs/train_only_primaite_session.yaml | 18 +++++++++-- 6 files changed, 102 insertions(+), 19 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index af872a01..6455272c 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -560,7 +560,7 @@ simulation: ip_address: 192.168.1.1 subnet_mask: 255.255.255.0 2: - ip_address: 192.168.1.1 + ip_address: 192.168.10.1 subnet_mask: 255.255.255.0 acl: 0: @@ -571,6 +571,14 @@ simulation: action: PERMIT src_port: DNS dst_port: DNS + 2: + action: PERMIT + src_port: FTP + dst_port: FTP + 3: + action: PERMIT + src_port: HTTP + dst_port: HTTP 22: action: PERMIT src_port: ARP @@ -607,7 +615,7 @@ simulation: hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.10 + default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - ref: web_server_database_client @@ -628,6 +636,10 @@ simulation: services: - ref: database_service type: DatabaseService + options: + backup_server_ip: 192.168.1.16 + - ref: database_ftp_client + type: FTPClient - ref: backup_server type: server @@ -638,7 +650,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: backup_service - type: DatabaseBackup + type: FTPServer - ref: security_suite type: server diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index 7856cc9f..f0dcdd61 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -16,7 +16,7 @@ from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction from primaite.game.io import SessionIO, SessionIOSettings from primaite.game.policy.policy import PolicyABC -from primaite.simulator.network.hardware.base import Link, NIC, Node +from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.server import Server @@ -30,6 +30,8 @@ from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.dns.dns_server import DNSServer +from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.ftp.ftp_server import FTPServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.service import Service from primaite.simulator.system.services.web_server.web_server import WebServer @@ -334,6 +336,7 @@ class PrimaiteSession: subnet_mask=node_cfg["subnet_mask"], default_gateway=node_cfg["default_gateway"], dns_server=node_cfg["dns_server"], + operating_state=NodeOperatingState.ON, ) elif n_type == "server": new_node = Server( @@ -342,16 +345,26 @@ class PrimaiteSession: subnet_mask=node_cfg["subnet_mask"], default_gateway=node_cfg["default_gateway"], dns_server=node_cfg.get("dns_server"), + operating_state=NodeOperatingState.ON, ) elif n_type == "switch": - new_node = Switch(hostname=node_cfg["hostname"], num_ports=node_cfg.get("num_ports")) + new_node = Switch( + hostname=node_cfg["hostname"], + num_ports=node_cfg.get("num_ports"), + operating_state=NodeOperatingState.ON, + ) elif n_type == "router": - new_node = Router(hostname=node_cfg["hostname"], num_ports=node_cfg.get("num_ports")) + new_node = Router( + hostname=node_cfg["hostname"], + num_ports=node_cfg.get("num_ports"), + operating_state=NodeOperatingState.ON, + ) if "ports" in node_cfg: for port_num, port_cfg in node_cfg["ports"].items(): new_node.configure_port( port=port_num, ip_address=port_cfg["ip_address"], subnet_mask=port_cfg["subnet_mask"] ) + # new_node.enable_port(port_num) if "acl" in node_cfg: for r_num, r_cfg in node_cfg["acl"].items(): # excuse the uncommon walrus operator ` := `. It's just here as a shorthand, to avoid repeating @@ -379,6 +392,8 @@ class PrimaiteSession: "DatabaseClient": DatabaseClient, "DatabaseService": DatabaseService, "WebServer": WebServer, + "FTPClient": FTPClient, + "FTPServer": FTPServer, } if service_type in service_types_mapping: print(f"installing {service_type} on node {new_node.hostname}") @@ -399,6 +414,12 @@ class PrimaiteSession: if "domain_mapping" in opt: for domain, ip in opt["domain_mapping"].items(): new_service.dns_register(domain, ip) + if service_type == "DatabaseService": + if "options" in service_cfg: + opt = service_cfg["options"] + if "backup_server_ip" in opt: + new_service.configure_backup(backup_server=IPv4Address(opt["backup_server_ip"])) + new_service.start() if "applications" in node_cfg: for application_cfg in node_cfg["applications"]: @@ -435,7 +456,7 @@ class PrimaiteSession: node_ref ] = ( new_node.uuid - ) # TODO: fix incosistency with service and link. Node gets added by uuid, but service by object + ) # TODO: fix inconsistency with service and link. Node gets added by uuid, but service by object # 2. create links between nodes for link_cfg in links_cfg: @@ -451,6 +472,8 @@ class PrimaiteSession: endpoint_b = node_b.ethernet_port[link_cfg["endpoint_b_port"]] new_link = net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b) sess.ref_map_links[link_cfg["ref"]] = new_link.uuid + # endpoint_a.enable() + # endpoint_b.enable() # 3. create agents game_cfg = cfg["game_config"] diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 6344eac0..4d8e4669 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -560,7 +560,7 @@ simulation: ip_address: 192.168.1.1 subnet_mask: 255.255.255.0 2: - ip_address: 192.168.1.1 + ip_address: 192.168.10.1 subnet_mask: 255.255.255.0 acl: 0: @@ -571,6 +571,14 @@ simulation: action: PERMIT src_port: DNS dst_port: DNS + 2: + action: PERMIT + src_port: FTP + dst_port: FTP + 3: + action: PERMIT + src_port: HTTP + dst_port: HTTP 22: action: PERMIT src_port: ARP @@ -607,7 +615,7 @@ simulation: hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.10 + default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - ref: web_server_database_client @@ -628,6 +636,10 @@ simulation: services: - ref: database_service type: DatabaseService + options: + backup_server_ip: 192.168.1.16 + - ref: database_ftp_client + type: FTPClient - ref: backup_server type: server @@ -638,7 +650,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: backup_service - type: DatabaseBackup + type: FTPServer - ref: security_suite type: server diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index aa8c8b1f..27a18d9f 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -560,7 +560,7 @@ simulation: ip_address: 192.168.1.1 subnet_mask: 255.255.255.0 2: - ip_address: 192.168.1.1 + ip_address: 192.168.10.1 subnet_mask: 255.255.255.0 acl: 0: @@ -571,6 +571,14 @@ simulation: action: PERMIT src_port: DNS dst_port: DNS + 2: + action: PERMIT + src_port: FTP + dst_port: FTP + 3: + action: PERMIT + src_port: HTTP + dst_port: HTTP 22: action: PERMIT src_port: ARP @@ -607,7 +615,7 @@ simulation: hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.10 + default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - ref: web_server_database_client @@ -628,6 +636,10 @@ simulation: services: - ref: database_service type: DatabaseService + options: + backup_server_ip: 192.168.1.16 + - ref: database_ftp_client + type: FTPClient - ref: backup_server type: server @@ -638,7 +650,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: backup_service - type: DatabaseBackup + type: FTPServer - ref: security_suite type: server diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 8133c5d9..64be5488 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -560,7 +560,7 @@ simulation: ip_address: 192.168.1.1 subnet_mask: 255.255.255.0 2: - ip_address: 192.168.1.1 + ip_address: 192.168.10.1 subnet_mask: 255.255.255.0 acl: 0: @@ -571,6 +571,14 @@ simulation: action: PERMIT src_port: DNS dst_port: DNS + 2: + action: PERMIT + src_port: FTP + dst_port: FTP + 3: + action: PERMIT + src_port: HTTP + dst_port: HTTP 22: action: PERMIT src_port: ARP @@ -607,7 +615,7 @@ simulation: hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.10 + default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - ref: web_server_database_client @@ -628,6 +636,10 @@ simulation: services: - ref: database_service type: DatabaseService + options: + backup_server_ip: 192.168.1.16 + - ref: database_ftp_client + type: FTPClient - ref: backup_server type: server @@ -638,7 +650,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: backup_service - type: DatabaseBackup + type: FTPServer - ref: security_suite type: server diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index f1e317d3..4cfe4df4 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -560,7 +560,7 @@ simulation: ip_address: 192.168.1.1 subnet_mask: 255.255.255.0 2: - ip_address: 192.168.1.1 + ip_address: 192.168.10.1 subnet_mask: 255.255.255.0 acl: 0: @@ -571,6 +571,14 @@ simulation: action: PERMIT src_port: DNS dst_port: DNS + 2: + action: PERMIT + src_port: FTP + dst_port: FTP + 3: + action: PERMIT + src_port: HTTP + dst_port: HTTP 22: action: PERMIT src_port: ARP @@ -607,7 +615,7 @@ simulation: hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.10 + default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - ref: web_server_database_client @@ -628,6 +636,10 @@ simulation: services: - ref: database_service type: DatabaseService + options: + backup_server_ip: 192.168.1.16 + - ref: database_ftp_client + type: FTPClient - ref: backup_server type: server @@ -638,7 +650,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: backup_service - type: DatabaseBackup + type: FTPServer - ref: security_suite type: server From e6f75f8b320f188475782b5564cc3f0bcc3413fe Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Fri, 24 Nov 2023 15:15:24 +0000 Subject: [PATCH 375/980] Improve data manipulation bot documentation --- .../system/data_manipulation_bot.rst | 76 ++++++++++++++++++- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/docs/source/simulation_components/system/data_manipulation_bot.rst b/docs/source/simulation_components/system/data_manipulation_bot.rst index 03f2208b..eeae0b0a 100644 --- a/docs/source/simulation_components/system/data_manipulation_bot.rst +++ b/docs/source/simulation_components/system/data_manipulation_bot.rst @@ -8,8 +8,6 @@ DataManipulationBot The ``DataManipulationBot`` class provides functionality to connect to a ``DatabaseService`` and execute malicious SQL statements. -The bot is controlled by a ``DataManipulationAgent``. - Overview -------- @@ -23,11 +21,11 @@ On a database server by abusing an application's trusted database connectivity. The bot performs attacks in the following stages to simulate the real pattern of an attack: -- Logon - *The bot gains access to the node.* +- Logon - *The bot gains credentials and accesses the node.* - Port Scan - *The bot finds accessible database servers on the network.* - Attacking - *The bot delivers the payload to the discovered database servers.* -Each of these stages has a random, configurable probability of succeeding. The bot can also be configured to repeat the attack once complete. +Each of these stages has a random, configurable probability of succeeding (by default 10%). The bot can also be configured to repeat the attack once complete. Usage ----- @@ -41,6 +39,8 @@ Usage The bot handles connecting, executing the statement, and disconnecting. +In a simulation, the bot can be controlled by using ``DataManipulationAgent`` which calls ``run`` on the bot at configured timesteps. + Example ------- @@ -58,6 +58,74 @@ Example This would connect to the database service at 192.168.1.14, authenticate, and execute the SQL statement to drop the 'users' table. +Example with ``DataManipulationAgent`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +If not using the data manipulation bot manually, it needs to be used with a data manipulation agent. Below is an example section of configuration file for setting up a simulation with data manipulation bot and agent. + +.. code-block:: yaml + + game_config: + # ... + agents: + - ref: data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + applications: + - application_ref: data_manipulation_bot + observations: + operating_status + health_status + folders: {} + + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_ref: client_1 + applications: + - application_ref: data_manipulation_bot + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_settings: + start_step: 25 + frequency: 20 + variance: 5 + # ... + + simulation: + network: + nodes: + - ref: client_1 + type: computer + # ... additional configuration here + applications: + - ref: data_manipulation_bot + type: DataManipulationBot + options: + port_scan_p_of_success: 0.1 + data_manipulation_p_of_success: 0.1 + payload: "DELETE" + server_ip: 192.168.1.14 + Implementation -------------- From c5cfbb825a275398d56799253b11cc3656d20777 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Fri, 24 Nov 2023 15:15:45 +0000 Subject: [PATCH 376/980] Fix database client connect method --- src/primaite/simulator/system/applications/database_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 3c4f1b75..b24b6062 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -54,7 +54,7 @@ class DatabaseClient(Application): def connect(self) -> bool: """Connect to a Database Service.""" - if not self.connected and self.operating_state.RUNNING: + if not self.connected and self.operating_state == ApplicationOperatingState.RUNNING: return self._connect(self.server_ip_address, self.server_password) return False From b7b718f25d142a53526876b20fbdeb9abc47ab06 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 24 Nov 2023 15:15:56 +0000 Subject: [PATCH 377/980] #2064: added a method that checks if the class can perform actions and added it where necessary + tests everywhere --- src/primaite/game/agent/observations.py | 2 +- .../system/applications/application.py | 33 +++++- .../system/applications/database_client.py | 23 +++- .../system/applications/web_browser.py | 3 + .../services/database/database_service.py | 8 ++ .../system/services/dns/dns_client.py | 10 +- .../system/services/dns/dns_server.py | 6 + .../simulator/system/services/service.py | 23 +++- src/primaite/simulator/system/software.py | 25 +++- .../system/test_application_on_node.py | 110 ++++++++++++++++++ ...ice_on_node.py => test_service_on_node.py} | 60 +++++++--- .../system/test_web_client_server.py | 22 ++++ .../_simulator/_system/_services/test_dns.py | 41 +++++++ ...sim_conatiner.py => test_sim_container.py} | 0 14 files changed, 328 insertions(+), 38 deletions(-) create mode 100644 tests/integration_tests/system/test_application_on_node.py rename tests/integration_tests/system/{test_app_service_on_node.py => test_service_on_node.py} (64%) rename tests/unit_tests/_primaite/_simulator/{test_sim_conatiner.py => test_sim_container.py} (100%) diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index a74771c0..dcb03d00 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -263,7 +263,7 @@ class FolderObservation(AbstractObservation): self.files.append(FileObservation()) while len(self.files) > num_files_per_folder: truncated_file = self.files.pop() - msg = f"Too many files in folde observation. Truncating file {truncated_file}" + msg = f"Too many files in folder observation. Truncating file {truncated_file}" _LOGGER.warn(msg) self.default_observation = { diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index fb65354f..d2f9772d 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -2,9 +2,11 @@ from abc import abstractmethod from enum import Enum from typing import Any, Dict, Set -from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite import getLogger from primaite.simulator.system.software import IOSoftware, SoftwareHealthState +_LOGGER = getLogger(__name__) + class ApplicationOperatingState(Enum): """Enumeration of Application Operating States.""" @@ -52,7 +54,7 @@ class Application(IOSoftware): state = super().describe_state() state.update( { - "opearting_state": self.operating_state.value, + "operating_state": self.operating_state.value, "execution_control_status": self.execution_control_status, "num_executions": self.num_executions, "groups": list(self.groups), @@ -60,10 +62,28 @@ class Application(IOSoftware): ) return state + def _can_perform_action(self) -> bool: + """ + Checks if the application can perform actions. + + This is done by checking if the application is operating properly or the node it is installed + in is operational. + + Returns true if the software can perform actions. + """ + if not super()._can_perform_action(): + return False + + if self.operating_state is not self.operating_state.RUNNING: + # service is not running + _LOGGER.error(f"Cannot perform action: {self.name} is {self.operating_state.name}") + return False + + return True + def run(self) -> None: """Open the Application.""" - if self.software_manager and self.software_manager.node.operating_state is not NodeOperatingState.ON: - self.sys_log.error(f"Unable to run application. {self.software_manager.node.hostname} is not turned on.") + if not super()._can_perform_action(): return if self.operating_state == ApplicationOperatingState.CLOSED: @@ -78,6 +98,9 @@ class Application(IOSoftware): def install(self) -> None: """Install Application.""" + if self._can_perform_action(): + return + super().install() if self.operating_state == ApplicationOperatingState.CLOSED: self.sys_log.info(f"Installing Application {self.name}") @@ -102,4 +125,4 @@ class Application(IOSoftware): :param payload: The payload to receive. :return: True if successful, False otherwise. """ - pass + return super().receive(payload=payload, session_id=session_id, **kwargs) diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 37f89371..9cb87bf6 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -54,7 +54,10 @@ class DatabaseClient(Application): def connect(self) -> bool: """Connect to a Database Service.""" - if not self.connected and self.operating_state.RUNNING: + if not self._can_perform_action(): + return False + + if not self.connected: return self._connect(self.server_ip_address, self.server_password) return False @@ -135,19 +138,31 @@ class DatabaseClient(Application): self.operating_state = ApplicationOperatingState.RUNNING self.connect() - def query(self, sql: str) -> bool: + def query(self, sql: str, is_reattempt: bool = False) -> bool: """ Send a query to the Database Service. - :param sql: The SQL query. + :param: sql: The SQL query. + :param: is_reattempt: If true, the action has been reattempted. :return: True if the query was successful, otherwise False. """ - if self.connected and self.operating_state.RUNNING: + if not self._can_perform_action(): + return False + + if self.connected: query_id = str(uuid4()) # Initialise the tracker of this ID to False self._query_success_tracker[query_id] = False return self._query(sql=sql, query_id=query_id) + else: + if is_reattempt: + return False + + if not self.connect(): + return False + + self.query(sql=sql, is_reattempt=True) def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index bb9552d8..71e30c7f 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -65,6 +65,9 @@ class WebBrowser(Application): :param: url: The address of the web page the browser requests :type: url: str """ + if not self._can_perform_action(): + return False + # reset latest response self.latest_response = HttpResponsePacket(status_code=HttpStatusCode.NOT_FOUND) diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index e3adb8e1..740ed4fd 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -48,6 +48,10 @@ class DatabaseService(Service): def backup_database(self) -> bool: """Create a backup of the database to the configured backup server.""" + # check if this action can be performed + if not self._can_perform_action(): + return False + # check if the backup server was configured if self.backup_server is None: self.sys_log.error(f"{self.name} - {self.sys_log.hostname}: not configured.") @@ -73,6 +77,10 @@ class DatabaseService(Service): def restore_backup(self) -> bool: """Restore a backup from backup server.""" + # check if this action can be performed + if not self._can_perform_action(): + return False + software_manager: SoftwareManager = self.software_manager ftp_client_service: FTPClient = software_manager.software["FTPClient"] diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 266ac4f6..a0965009 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -1,5 +1,5 @@ from ipaddress import IPv4Address -from typing import Dict, Optional +from typing import Dict, Optional, Union from primaite import getLogger from primaite.simulator.network.protocols.dns import DNSPacket, DNSRequest @@ -51,13 +51,16 @@ class DNSClient(Service): """ pass - def add_domain_to_cache(self, domain_name: str, ip_address: IPv4Address): + def add_domain_to_cache(self, domain_name: str, ip_address: IPv4Address) -> Union[bool, None]: """ Adds a domain name to the DNS Client cache. :param: domain_name: The domain name to save to cache :param: ip_address: The IP Address to attach the domain name to """ + if not self._can_perform_action(): + return False + self.dns_cache[domain_name] = ip_address def check_domain_exists( @@ -72,6 +75,9 @@ class DNSClient(Service): :param: session_id: The Session ID the payload is to originate from. Optional. :param: is_reattempt: Checks if the request has been reattempted. Default is False. """ + if not self._can_perform_action(): + return False + # check if DNS server is configured if self.dns_server is None: self.sys_log.error(f"{self.name}: DNS Server is not configured") diff --git a/src/primaite/simulator/system/services/dns/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py index 2c8f3003..b6d4961f 100644 --- a/src/primaite/simulator/system/services/dns/dns_server.py +++ b/src/primaite/simulator/system/services/dns/dns_server.py @@ -48,6 +48,9 @@ class DNSServer(Service): :param target_domain: The single domain name requested by a DNS client. :return ip_address: The IP address of that domain name or None. """ + if not self._can_perform_action(): + return + return self.dns_table.get(target_domain) def dns_register(self, domain_name: str, domain_ip_address: IPv4Address): @@ -60,6 +63,9 @@ class DNSServer(Service): :param: domain_ip_address: The IP address that the domain should route to :type: domain_ip_address: IPv4Address """ + if not self._can_perform_action(): + return + self.dns_table[domain_name] = domain_ip_address def reset_component_for_episode(self, episode: int): diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 3a1a4c9d..04a4603a 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -3,7 +3,6 @@ from typing import Any, Dict, Optional from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType -from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.system.software import IOSoftware, SoftwareHealthState _LOGGER = getLogger(__name__) @@ -41,6 +40,25 @@ class Service(IOSoftware): restart_countdown: Optional[int] = None "If currently restarting, how many timesteps remain until the restart is finished." + def _can_perform_action(self) -> bool: + """ + Checks if the service can perform actions. + + This is done by checking if the service is operating properly or the node it is installed + in is operational. + + Returns true if the software can perform actions. + """ + if not super()._can_perform_action(): + return False + + if self.operating_state is not self.operating_state.RUNNING: + # service is not running + _LOGGER.error(f"Cannot perform action: {self.name} is {self.operating_state.name}") + return False + + return True + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ Receives a payload from the SessionManager. @@ -108,8 +126,7 @@ class Service(IOSoftware): def start(self, **kwargs) -> None: """Start the service.""" # cant start the service if the node it is on is off - if self.software_manager and self.software_manager.node.operating_state is not NodeOperatingState.ON: - self.sys_log.error(f"Unable to start service. {self.software_manager.node.hostname} is not turned on.") + if not super()._can_perform_action(): return if self.operating_state == ServiceOperatingState.STOPPED: diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 830e3d79..5564bd48 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -226,6 +226,21 @@ class IOSoftware(Software): ) return state + @abstractmethod + def _can_perform_action(self) -> bool: + """ + Checks if the software can perform actions. + + This is done by checking if the software is operating properly or the node it is installed + in is operational. + + Returns true if the software can perform actions. + """ + if self.software_manager and self.software_manager.node.operating_state is NodeOperatingState.OFF: + _LOGGER.debug(f"{self.name} Error: {self.software_manager.node.hostname} is not online.") + return False + return True + def send( self, payload: Any, @@ -244,6 +259,9 @@ class IOSoftware(Software): :return: True if successful, False otherwise. """ + if not self._can_perform_action(): + return False + return self.software_manager.send_payload_to_session_manager( payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id ) @@ -262,8 +280,5 @@ class IOSoftware(Software): :param kwargs: Additional keyword arguments specific to the implementation. :return: True if the payload was successfully received and processed, False otherwise. """ - # return false if node that software is on is off - if self.software_manager and self.software_manager.node.operating_state is NodeOperatingState.OFF: - _LOGGER.debug(f"{self.name} Error: {self.software_manager.node.hostname} is not online.") - return False - return True + # return false if not allowed to perform actions + return self._can_perform_action() diff --git a/tests/integration_tests/system/test_application_on_node.py b/tests/integration_tests/system/test_application_on_node.py new file mode 100644 index 00000000..7ac7b492 --- /dev/null +++ b/tests/integration_tests/system/test_application_on_node.py @@ -0,0 +1,110 @@ +from typing import Tuple + +import pytest + +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.system.applications.application import Application, ApplicationOperatingState + + +@pytest.fixture(scope="function") +def populated_node(application_class) -> Tuple[Application, Computer]: + computer: Computer = Computer( + hostname="test_computer", + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, + ) + computer.software_manager.install(application_class) + + app = computer.software_manager.software["TestApplication"] + app.run() + + return app, computer + + +def test_service_on_offline_node(application_class): + """Test to check that the service cannot be interacted with when node it is on is off.""" + computer: Computer = Computer( + hostname="test_computer", + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, + ) + computer.software_manager.install(application_class) + + app: Application = computer.software_manager.software["TestApplication"] + + computer.power_off() + + for i in range(computer.shut_down_duration + 1): + computer.apply_timestep(timestep=i) + + assert computer.operating_state is NodeOperatingState.OFF + assert app.operating_state is ApplicationOperatingState.CLOSED + + app.run() + assert app.operating_state is ApplicationOperatingState.CLOSED + + +def test_server_turns_off_service(populated_node): + """Check that the service is turned off when the server is turned off""" + app, computer = populated_node + + assert computer.operating_state is NodeOperatingState.ON + assert app.operating_state is ApplicationOperatingState.RUNNING + + computer.power_off() + + for i in range(computer.shut_down_duration + 1): + computer.apply_timestep(timestep=i) + + assert computer.operating_state is NodeOperatingState.OFF + assert app.operating_state is ApplicationOperatingState.CLOSED + + +def test_service_cannot_be_turned_on_when_server_is_off(populated_node): + """Check that the service cannot be started when the server is off.""" + app, computer = populated_node + + assert computer.operating_state is NodeOperatingState.ON + assert app.operating_state is ApplicationOperatingState.RUNNING + + computer.power_off() + + for i in range(computer.shut_down_duration + 1): + computer.apply_timestep(timestep=i) + + assert computer.operating_state is NodeOperatingState.OFF + assert app.operating_state is ApplicationOperatingState.CLOSED + + app.run() + + assert computer.operating_state is NodeOperatingState.OFF + assert app.operating_state is ApplicationOperatingState.CLOSED + + +def test_server_turns_on_service(populated_node): + """Check that turning on the server turns on service.""" + app, computer = populated_node + + assert computer.operating_state is NodeOperatingState.ON + assert app.operating_state is ApplicationOperatingState.RUNNING + + computer.power_off() + + for i in range(computer.shut_down_duration + 1): + computer.apply_timestep(timestep=i) + + assert computer.operating_state is NodeOperatingState.OFF + assert app.operating_state is ApplicationOperatingState.CLOSED + + computer.power_on() + + for i in range(computer.start_up_duration + 1): + computer.apply_timestep(timestep=i) + + assert computer.operating_state is NodeOperatingState.ON + assert app.operating_state is ApplicationOperatingState.RUNNING diff --git a/tests/integration_tests/system/test_app_service_on_node.py b/tests/integration_tests/system/test_service_on_node.py similarity index 64% rename from tests/integration_tests/system/test_app_service_on_node.py rename to tests/integration_tests/system/test_service_on_node.py index 7777a810..b23df58b 100644 --- a/tests/integration_tests/system/test_app_service_on_node.py +++ b/tests/integration_tests/system/test_service_on_node.py @@ -3,34 +3,66 @@ from typing import Tuple import pytest from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.system.applications.application import Application, ApplicationOperatingState from primaite.simulator.system.services.service import Service, ServiceOperatingState @pytest.fixture(scope="function") -def populated_node(service_class, application_class) -> Tuple[Application, Server, Service]: +def populated_node( + service_class, +) -> Tuple[Server, Service]: server = Server( hostname="server", ip_address="192.168.0.1", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON ) server.software_manager.install(service_class) - server.software_manager.install(application_class) - app = server.software_manager.software["TestApplication"] - app.run() service = server.software_manager.software["TestService"] service.start() - return app, server, service + return server, service + + +def test_service_on_offline_node(service_class): + """Test to check that the service cannot be interacted with when node it is on is off.""" + computer: Computer = Computer( + hostname="test_computer", + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, + ) + computer.software_manager.install(service_class) + + service: Service = computer.software_manager.software["TestService"] + + computer.power_off() + + for i in range(computer.shut_down_duration + 1): + computer.apply_timestep(timestep=i) + + assert computer.operating_state is NodeOperatingState.OFF + assert service.operating_state is ServiceOperatingState.STOPPED + + service.start() + assert service.operating_state is ServiceOperatingState.STOPPED + + service.resume() + assert service.operating_state is ServiceOperatingState.STOPPED + + service.restart() + assert service.operating_state is ServiceOperatingState.STOPPED + + service.pause() + assert service.operating_state is ServiceOperatingState.STOPPED def test_server_turns_off_service(populated_node): """Check that the service is turned off when the server is turned off""" - app, server, service = populated_node + server, service = populated_node assert server.operating_state is NodeOperatingState.ON assert service.operating_state is ServiceOperatingState.RUNNING - assert app.operating_state is ApplicationOperatingState.RUNNING server.power_off() @@ -39,16 +71,14 @@ def test_server_turns_off_service(populated_node): assert server.operating_state is NodeOperatingState.OFF assert service.operating_state is ServiceOperatingState.STOPPED - assert app.operating_state is ApplicationOperatingState.CLOSED def test_service_cannot_be_turned_on_when_server_is_off(populated_node): """Check that the service cannot be started when the server is off.""" - app, server, service = populated_node + server, service = populated_node assert server.operating_state is NodeOperatingState.ON assert service.operating_state is ServiceOperatingState.RUNNING - assert app.operating_state is ApplicationOperatingState.RUNNING server.power_off() @@ -57,23 +87,19 @@ def test_service_cannot_be_turned_on_when_server_is_off(populated_node): assert server.operating_state is NodeOperatingState.OFF assert service.operating_state is ServiceOperatingState.STOPPED - assert app.operating_state is ApplicationOperatingState.CLOSED service.start() - app.run() assert server.operating_state is NodeOperatingState.OFF assert service.operating_state is ServiceOperatingState.STOPPED - assert app.operating_state is ApplicationOperatingState.CLOSED def test_server_turns_on_service(populated_node): """Check that turning on the server turns on service.""" - app, server, service = populated_node + server, service = populated_node assert server.operating_state is NodeOperatingState.ON assert service.operating_state is ServiceOperatingState.RUNNING - assert app.operating_state is ApplicationOperatingState.RUNNING server.power_off() @@ -82,7 +108,6 @@ def test_server_turns_on_service(populated_node): assert server.operating_state is NodeOperatingState.OFF assert service.operating_state is ServiceOperatingState.STOPPED - assert app.operating_state is ApplicationOperatingState.CLOSED server.power_on() @@ -91,4 +116,3 @@ def test_server_turns_on_service(populated_node): assert server.operating_state is NodeOperatingState.ON assert service.operating_state is ServiceOperatingState.RUNNING - assert app.operating_state is ApplicationOperatingState.RUNNING diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py index f3995c84..8f87ef27 100644 --- a/tests/integration_tests/system/test_web_client_server.py +++ b/tests/integration_tests/system/test_web_client_server.py @@ -78,3 +78,25 @@ def test_web_page_request_from_shut_down_server(uc2_network): assert web_client.get_webpage("http://arcd.com/users/") is False assert web_client.latest_response.status_code == HttpStatusCode.NOT_FOUND + + +def test_web_page_request_from_closed_web_browser(uc2_network): + client_1: Computer = uc2_network.get_node_by_hostname("client_1") + web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] + web_client.run() + + web_server: Server = uc2_network.get_node_by_hostname("web_server") + + assert web_client.operating_state == ApplicationOperatingState.RUNNING + + assert web_client.get_webpage("http://arcd.com/users/") is True + + # latest response should have status code 200 + assert web_client.latest_response.status_code == HttpStatusCode.OK + + web_client.close() + + # node should be off + assert web_client.operating_state is ApplicationOperatingState.CLOSED + + assert web_client.get_webpage("http://arcd.com/users/") is False diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py index 469c8548..2b4082d9 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py @@ -11,6 +11,7 @@ from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.dns.dns_server import DNSServer +from primaite.simulator.system.services.service import ServiceOperatingState @pytest.fixture(scope="function") @@ -54,6 +55,44 @@ def test_create_dns_client(dns_client): assert dns_client_service.protocol is IPProtocol.TCP +def test_dns_client_add_domain_to_cache_when_not_running(dns_client): + dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] + assert dns_client.operating_state is NodeOperatingState.OFF + assert dns_client_service.operating_state is ServiceOperatingState.STOPPED + + assert ( + dns_client_service.add_domain_to_cache(domain_name="test.com", ip_address=IPv4Address("192.168.1.100")) is False + ) + + assert dns_client_service.dns_cache.get("test.com") is None + + +def test_dns_client_check_domain_exists_when_not_running(dns_client): + dns_client.operating_state = NodeOperatingState.ON + dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] + dns_client_service.start() + + assert dns_client.operating_state is NodeOperatingState.ON + assert dns_client_service.operating_state is ServiceOperatingState.RUNNING + + assert ( + dns_client_service.add_domain_to_cache(domain_name="test.com", ip_address=IPv4Address("192.168.1.100")) + is not False + ) + + assert dns_client_service.check_domain_exists("test.com") is True + + dns_client.power_off() + + for i in range(dns_client.shut_down_duration + 1): + dns_client.apply_timestep(timestep=i) + + assert dns_client.operating_state is NodeOperatingState.OFF + assert dns_client_service.operating_state is ServiceOperatingState.STOPPED + + assert dns_client_service.check_domain_exists("test.com") is False + + def test_dns_server_domain_name_registration(dns_server): """Test to check if the domain name registration works.""" dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] @@ -68,7 +107,9 @@ def test_dns_server_domain_name_registration(dns_server): def test_dns_client_check_domain_in_cache(dns_client): """Test to make sure that the check_domain_in_cache returns the correct values.""" + dns_client.operating_state = NodeOperatingState.ON dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] + dns_client_service.start() # add a domain to the dns client cache dns_client_service.add_domain_to_cache("real-domain.com", IPv4Address("192.168.1.12")) diff --git a/tests/unit_tests/_primaite/_simulator/test_sim_conatiner.py b/tests/unit_tests/_primaite/_simulator/test_sim_container.py similarity index 100% rename from tests/unit_tests/_primaite/_simulator/test_sim_conatiner.py rename to tests/unit_tests/_primaite/_simulator/test_sim_container.py From 355cbedbae9d17d33ae0d099d41d65709cd9d2ac Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 24 Nov 2023 15:17:08 +0000 Subject: [PATCH 378/980] #2068: Further typo and formatting changes. --- docs/source/game_layer.rst | 1 + docs/source/request_system.rst | 6 +++--- .../system/data_manipulation_bot.rst | 4 +++- .../system/database_client_server.rst | 9 +-------- docs/source/state_system.rst | 4 ++-- src/primaite/exceptions.py | 2 +- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/docs/source/game_layer.rst b/docs/source/game_layer.rst index 18b42e7b..cdae17dd 100644 --- a/docs/source/game_layer.rst +++ b/docs/source/game_layer.rst @@ -26,6 +26,7 @@ Agents ^^^^^^ All agents inherit from the :py:class:`primaite.game.agent.interface.AbstractAgent` class, which mandates that they have an ObservationManager, ActionManager, and RewardManager. The agent behaviour depends on the type of agent, but there are two main types: + * RL agents action during each step is decided by an appropriate RL algorithm. The agent within PrimAITE just acts to format and forward actions decided by an RL policy. * Deterministic agents perform all of their decision making within the PrimAITE game layer. They typically have a scripted policy which always performs the same action or a rule-based policy which performs actions based on the current state of the simulation. They can have a stochastic element, and their seed will be settable. diff --git a/docs/source/request_system.rst b/docs/source/request_system.rst index cdaf2d99..1b06e2d9 100644 --- a/docs/source/request_system.rst +++ b/docs/source/request_system.rst @@ -5,12 +5,12 @@ Request System ============== -``SimComponent`` in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``RequestManager`` and ``RequestType``. +``SimComponent`` objects in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``RequestManager`` and ``RequestType``. -Just like other aspects of SimComponent, the request typess are not managed centrally for the whole simulation, but instead they are dynamically created and updated based on the nodes, links, and other components that currently exist. This was achieved in the following way: +Just like other aspects of SimComponent, the request types are not managed centrally for the whole simulation, but instead they are dynamically created and updated based on the nodes, links, and other components that currently exist. This was achieved in the following way: - API - An ``RequestType`` contains two elements: + A ``RequestType`` contains two elements: 1. ``request`` - selects which action you want to take on this ``SimComponent``. This is formatted as a list of strings such as `['network', 'node', '', 'service', '', 'restart']`. 2. ``context`` - optional extra information that can be used to decide how to process the request. This is formatted as a dictionary. For example, if the request requires authentication, the context can include information about the user that initiated the request to decide if their permissions are sufficient. diff --git a/docs/source/simulation_components/system/data_manipulation_bot.rst b/docs/source/simulation_components/system/data_manipulation_bot.rst index c9f8977a..810da3a0 100644 --- a/docs/source/simulation_components/system/data_manipulation_bot.rst +++ b/docs/source/simulation_components/system/data_manipulation_bot.rst @@ -16,15 +16,17 @@ The bot is intended to simulate a malicious actor carrying out attacks like: - Dropping tables - Deleting records - Modifying data -On a database server by abusing an application's trusted database connectivity. +on a database server by abusing an application's trusted database connectivity. Usage ----- - Create an instance and call ``configure`` to set: + - Target database server IP - Database password (if needed) - SQL statement payload + - Call ``run`` to connect and execute the statement. The bot handles connecting, executing the statement, and disconnecting. diff --git a/docs/source/simulation_components/system/database_client_server.rst b/docs/source/simulation_components/system/database_client_server.rst index 53687f60..0cbbddb1 100644 --- a/docs/source/simulation_components/system/database_client_server.rst +++ b/docs/source/simulation_components/system/database_client_server.rst @@ -17,8 +17,6 @@ Key capabilities - Initialises a SQLite database file in the ``Node`` 's ``FileSystem`` upon creation. - Handles connecting clients by maintaining a dictionary of connections mapped to session IDs. - Authenticates connections using a configurable password. -- Executes SQL queries against the SQLite database. -- Returns query results and status codes back to clients. - Leverages the Service base class for install/uninstall, status tracking, etc. Usage @@ -33,7 +31,6 @@ Implementation - Uses SQLite for persistent storage. - Creates the database file within the node's file system. - Manages client connections in a dictionary by session ID. -- Processes SQL queries via the SQLite cursor and connection. - Returns results and status codes in a standard dictionary format. - Extends Service class for integration with ``SoftwareManager``. @@ -46,17 +43,14 @@ Key features ^^^^^^^^^^^^ - Connects to the ``DatabaseService`` via the ``SoftwareManager``. +- Handles connecting and disconnecting. - Executes SQL queries and retrieves result sets. -- Handles connecting, querying, and disconnecting. -- Provides a simple ``query`` method for running SQL. - Usage ^^^^^ - Initialise with server IP address and optional password. - Connect to the ``DatabaseService`` with ``connect``. -- Execute SQL queries via ``query``. - Retrieve results in a dictionary. - Disconnect when finished. @@ -71,6 +65,5 @@ Implementation - Leverages ``SoftwareManager`` for sending payloads over the network. - Connect and disconnect methods manage sessions. -- Provides easy interface for applications to query database. - Payloads serialised as dictionaries for transmission. - Extends base Application class. diff --git a/docs/source/state_system.rst b/docs/source/state_system.rst index de4cd093..860c9827 100644 --- a/docs/source/state_system.rst +++ b/docs/source/state_system.rst @@ -5,9 +5,9 @@ Simulation State ============== -``SimComponent`` in the simulation have a method called ``describe_state`` which returns a dictionary of the state of the component. This is used to report pertinent data that could impact agent's actions or rewards. For instance, the name and health status of a node is reported, which can be used by a reward function to punish corrupted or compromised nodes and reward healthy nodes. Each ``SimComponent`` reports not only it's own attributes in the state but also that of its child components. I.e. a computer node will report the state of its ``FileSystem``, and the ``FileSystem`` will report the state of its files and folders. This happens by recursively calling childrens' own ``describe_state`` methods. +``SimComponent`` objects in the simulation have a method called ``describe_state`` which return a dictionary of the state of the component. This is used to report pertinent data that could impact an agent's actions or rewards. For instance, the name and health status of a node is reported, which can be used by a reward function to punish corrupted or compromised nodes and reward healthy nodes. Each ``SimComponent`` object reports not only its own attributes in the state but also those of its child components. I.e. a computer node will report the state of its ``FileSystem`` and the ``FileSystem`` will report the state of its files and folders. This happens by recursively calling the childrens' own ``describe_state`` methods. -The game layer calls ``describe_state`` on the trunk ``SimComponent`` (the top-level parent) and then pass the state to the agents once per simulation step. For this reason, all ``SimComponent`` must have a ``describe_state`` method, and they must all be linked to the trunk ``SimComponent``. +The game layer calls ``describe_state`` on the trunk ``SimComponent`` (the top-level parent) and then passes the state to the agents once per simulation step. For this reason, all ``SimComponent`` objetcs must have a ``describe_state`` method, and they must all be linked to the trunk ``SimComponent``. This code snippet demonstrates how the state information is defined within the ``SimComponent`` class: diff --git a/src/primaite/exceptions.py b/src/primaite/exceptions.py index 6aa140ba..ad9e6e5b 100644 --- a/src/primaite/exceptions.py +++ b/src/primaite/exceptions.py @@ -1,6 +1,6 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK class PrimaiteError(Exception): - """The root PrimAITe Error.""" + """The root PrimAITE Error.""" pass From 76b3a5ab6fd89eeb9ea0169a0a27f825b90c9fb3 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 24 Nov 2023 15:43:52 +0000 Subject: [PATCH 379/980] #2068: Updated version --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index a6f4248b..dcc86c22 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0a1 +3.0.0b2dev From 2ce27080a603e31e6b1de802f88fa761aafcf155 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 24 Nov 2023 15:48:13 +0000 Subject: [PATCH 380/980] #2068: Remove reference to ARCD GATE --- docs/source/about.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/about.rst b/docs/source/about.rst index 32b54eee..e8befbaf 100644 --- a/docs/source/about.rst +++ b/docs/source/about.rst @@ -18,7 +18,6 @@ PrimAITE provides the following features: * Highly configurable network hosts, including definition of software, file system, and network interfaces, * Realistic network traffic simulation, including address and sending packets via internet protocols like TCP, UDP, ICMP, etc. * Routers with traffic routing and firewall capabilities -* Interfaces with ARCD GATE to allow training of agents * Simulation of customisable deterministic agents * Support for multiple agents, each having their own customisable observation space, action space, and reward function definition. From e62ca22cb7d45fe7fa8b03d582b3c3f8fc66f676 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Fri, 24 Nov 2023 15:53:07 +0000 Subject: [PATCH 381/980] Fix data manipulation bot tests --- .../red_services/data_manipulation_bot.py | 20 +++++++++---------- .../test_data_manipulation_bot.py | 2 ++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index 17b89386..6db9e1aa 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -128,16 +128,16 @@ class DataManipulationBot(DatabaseClient): # perform the attack if not self.connected: self.connect() - if self.connected: - self.query(self.payload) - self.sys_log.info(f"{self.name} payload delivered: {self.payload}") - attack_successful = True - if attack_successful: - self.sys_log.info(f"{self.name}: Data manipulation successful") - self.attack_stage = DataManipulationAttackStage.COMPLETE - else: - self.sys_log.info(f"{self.name}: Data manipulation failed") - self.attack_stage = DataManipulationAttackStage.FAILED + if self.connected: + self.query(self.payload) + self.sys_log.info(f"{self.name} payload delivered: {self.payload}") + attack_successful = True + if attack_successful: + self.sys_log.info(f"{self.name}: Data manipulation successful") + self.attack_stage = DataManipulationAttackStage.COMPLETE + else: + self.sys_log.info(f"{self.name}: Data manipulation failed") + self.attack_stage = DataManipulationAttackStage.FAILED def run(self): """ diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py index 8a78beae..936f7c5c 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py @@ -4,6 +4,7 @@ from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.networks import arcd_uc2_network from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.services.red_services.data_manipulation_bot import ( DataManipulationAttackStage, DataManipulationBot, @@ -64,6 +65,7 @@ def test_dm_bot_perform_data_manipulation_no_success(dm_bot): def test_dm_bot_perform_data_manipulation_success(dm_bot): dm_bot.attack_stage = DataManipulationAttackStage.PORT_SCAN + dm_bot.operating_state = ApplicationOperatingState.RUNNING dm_bot._perform_data_manipulation(p_of_success=1.0) From 08c1b3cfb99ceae8aefbecf2331b868393ff1f59 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Fri, 24 Nov 2023 15:56:04 +0000 Subject: [PATCH 382/980] Fix code style issues --- src/primaite/game/science.py | 2 +- src/primaite/simulator/system/applications/application.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/game/science.py b/src/primaite/game/science.py index f6215127..19a86237 100644 --- a/src/primaite/game/science.py +++ b/src/primaite/game/science.py @@ -1,7 +1,7 @@ from random import random -def simulate_trial(p_of_success: float): +def simulate_trial(p_of_success: float) -> bool: """ Simulates the outcome of a single trial in a Bernoulli process. diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 7f79ac2b..9a58c98a 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -66,7 +66,7 @@ class Application(IOSoftware): self.operating_state = ApplicationOperatingState.RUNNING def _application_loop(self): - """THe main application loop.""" + """The main application loop.""" pass def close(self) -> None: From afce6ca5159db196e50997207c3e4a637712e925 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Fri, 24 Nov 2023 16:04:11 +0000 Subject: [PATCH 383/980] Update changelog for data manipulator bot & agent --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3af5c14c..9ddd0398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,8 @@ SessionManager. - `DatabaseClient` and `DatabaseService` created to allow emulation of database actions - Ability for `DatabaseService` to backup its data to another server via FTP and restore data from backup - Red Agent Services: - - Data Manipulator Bot - A red agent service which sends a payload to a target machine. (By default this payload is a SQL query that breaks a database) + - Data Manipulator Bot - A red agent service which sends a payload to a target machine. (By default this payload is a SQL query that breaks a database). The attack runs in stages with a random, configurable probability of succeeding. + - `DataManipulationAgent` runs the Data Manipulator Bot according to a configured start step, frequency and variance. - DNS Services: `DNSClient` and `DNSServer` - FTP Services: `FTPClient` and `FTPServer` - HTTP Services: `WebBrowser` to simulate a web client and `WebServer` From cbdaa6c44418ba5d34c2221313054785defdf978 Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Fri, 24 Nov 2023 16:32:04 +0000 Subject: [PATCH 384/980] Move data manipulation agent into individual file --- .../game/agent/data_manipulation_agent.py | 0 .../game/agent/data_manipulation_bot.py | 48 +++++++++++++++++++ src/primaite/game/agent/interface.py | 44 +---------------- src/primaite/game/session.py | 3 +- 4 files changed, 51 insertions(+), 44 deletions(-) create mode 100644 src/primaite/game/agent/data_manipulation_agent.py create mode 100644 src/primaite/game/agent/data_manipulation_bot.py diff --git a/src/primaite/game/agent/data_manipulation_agent.py b/src/primaite/game/agent/data_manipulation_agent.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/game/agent/data_manipulation_bot.py b/src/primaite/game/agent/data_manipulation_bot.py new file mode 100644 index 00000000..51221154 --- /dev/null +++ b/src/primaite/game/agent/data_manipulation_bot.py @@ -0,0 +1,48 @@ +import random +from typing import Dict, List, Tuple + +from gymnasium.core import ObsType + +from primaite.game.agent.interface import AbstractScriptedAgent +from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot + + +class DataManipulationAgent(AbstractScriptedAgent): + """Agent that uses a DataManipulationBot to perform an SQL injection attack.""" + + data_manipulation_bots: List["DataManipulationBot"] = [] + next_execution_timestep: int = 0 + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self._set_next_execution_timestep(self.agent_settings.start_settings.start_step) + + def _set_next_execution_timestep(self, timestep: int) -> None: + """Set the next execution timestep with a configured random variance. + + :param timestep: The timestep to add variance to. + """ + random_timestep_increment = random.randint( + -self.agent_settings.start_settings.variance, self.agent_settings.start_settings.variance + ) + self.next_execution_timestep = timestep + random_timestep_increment + + def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: + """Randomly sample an action from the action space. + + :param obs: _description_ + :type obs: ObsType + :param reward: _description_, defaults to None + :type reward: float, optional + :return: _description_ + :rtype: Tuple[str, Dict] + """ + current_timestep = self.action_manager.session.step_counter + + if current_timestep < self.next_execution_timestep: + return "DONOTHING", {"dummy": 0} + + self._set_next_execution_timestep(current_timestep + self.agent_settings.start_settings.frequency) + + return "NODE_APPLICATION_EXECUTE", {"node_id": 0, "application_id": 0} diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index b321b17c..6e783725 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -1,5 +1,4 @@ """Interface for agents.""" -import random from abc import ABC, abstractmethod from typing import Dict, List, Optional, Tuple, TYPE_CHECKING @@ -11,7 +10,7 @@ from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction if TYPE_CHECKING: - from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot + pass class AgentStartSettings(BaseModel): @@ -183,47 +182,6 @@ class ProxyAgent(AbstractAgent): self.most_recent_action = action -class DataManipulationAgent(AbstractScriptedAgent): - """Agent that uses a DataManipulationBot to perform an SQL injection attack.""" - - data_manipulation_bots: List["DataManipulationBot"] = [] - next_execution_timestep: int = 0 - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - self._set_next_execution_timestep(self.agent_settings.start_settings.start_step) - - def _set_next_execution_timestep(self, timestep: int) -> None: - """Set the next execution timestep with a configured random variance. - - :param timestep: The timestep to add variance to. - """ - random_timestep_increment = random.randint( - -self.agent_settings.start_settings.variance, self.agent_settings.start_settings.variance - ) - self.next_execution_timestep = timestep + random_timestep_increment - - def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: - """Randomly sample an action from the action space. - - :param obs: _description_ - :type obs: ObsType - :param reward: _description_, defaults to None - :type reward: float, optional - :return: _description_ - :rtype: Tuple[str, Dict] - """ - current_timestep = self.action_manager.session.step_counter - - if current_timestep < self.next_execution_timestep: - return "DONOTHING", {"dummy": 0} - - self._set_next_execution_timestep(current_timestep + self.agent_settings.start_settings.frequency) - - return "NODE_APPLICATION_EXECUTE", {"node_id": 0, "application_id": 0} - - class AbstractGATEAgent(AbstractAgent): """Base class for actors controlled via external messages, such as RL policies.""" diff --git a/src/primaite/game/session.py b/src/primaite/game/session.py index f0dcdd61..095458b7 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/session.py @@ -11,7 +11,8 @@ from pydantic import BaseModel, ConfigDict from primaite import getLogger from primaite.game.agent.actions import ActionManager -from primaite.game.agent.interface import AbstractAgent, AgentSettings, DataManipulationAgent, ProxyAgent, RandomAgent +from primaite.game.agent.data_manipulation_bot import DataManipulationAgent +from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent, RandomAgent from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction from primaite.game.io import SessionIO, SessionIOSettings From cd49f1eb85c49c43af1c9521df8e0af85705f113 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Sat, 25 Nov 2023 13:19:32 +0000 Subject: [PATCH 385/980] #2064: Apply PR suggestions --- .../system/services/dns/dns_client.py | 1 + .../red_services/data_manipulation_bot.py | 2 +- .../system/test_ftp_client_server.py | 20 +++++++++---------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index a0965009..2c3716e9 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -62,6 +62,7 @@ class DNSClient(Service): return False self.dns_cache[domain_name] = ip_address + return True def check_domain_exists( self, diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index f6662762..8dc2eeab 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -46,7 +46,7 @@ class DataManipulationBot(DatabaseClient): self.sys_log.error(f"Failed to start the {self.name} as it requires both a target_ip_address and payload.") def attack(self): - """Run the datab manipulation attack.""" + """Run the data manipulation attack.""" if not self.connected: self.connect() if self.connected: diff --git a/tests/integration_tests/system/test_ftp_client_server.py b/tests/integration_tests/system/test_ftp_client_server.py index d8968b2d..b2cdbc06 100644 --- a/tests/integration_tests/system/test_ftp_client_server.py +++ b/tests/integration_tests/system/test_ftp_client_server.py @@ -15,10 +15,10 @@ def test_ftp_client_store_file_in_server(uc2_network): backup_server: Server = uc2_network.get_node_by_hostname("backup_server") ftp_client: FTPClient = client_1.software_manager.software["FTPClient"] - ftp_server: FTPServer = backup_server.software_manager.software["FTPServer"] + ftp_server_service: FTPServer = backup_server.software_manager.software["FTPServer"] assert ftp_client.operating_state == ServiceOperatingState.RUNNING - assert ftp_server.operating_state == ServiceOperatingState.RUNNING + assert ftp_server_service.operating_state == ServiceOperatingState.RUNNING # create file on ftp client ftp_client.file_system.create_file(file_name="test_file.txt") @@ -31,7 +31,7 @@ def test_ftp_client_store_file_in_server(uc2_network): dest_ip_address=backup_server.nics.get(next(iter(backup_server.nics))).ip_address, ) - assert ftp_server.file_system.get_file(folder_name="client_1_backup", file_name="test_file.txt") + assert ftp_server_service.file_system.get_file(folder_name="client_1_backup", file_name="test_file.txt") def test_ftp_client_retrieve_file_from_server(uc2_network): @@ -42,13 +42,13 @@ def test_ftp_client_retrieve_file_from_server(uc2_network): backup_server: Server = uc2_network.get_node_by_hostname("backup_server") ftp_client: FTPClient = client_1.software_manager.software["FTPClient"] - ftp_server: FTPServer = backup_server.software_manager.software["FTPServer"] + ftp_server_service: FTPServer = backup_server.software_manager.software["FTPServer"] assert ftp_client.operating_state == ServiceOperatingState.RUNNING - assert ftp_server.operating_state == ServiceOperatingState.RUNNING + assert ftp_server_service.operating_state == ServiceOperatingState.RUNNING # create file on ftp server - ftp_server.file_system.create_file(file_name="test_file.txt", folder_name="file_share") + ftp_server_service.file_system.create_file(file_name="test_file.txt", folder_name="file_share") assert ftp_client.request_file( src_folder_name="file_share", @@ -68,13 +68,13 @@ def test_ftp_client_tries_to_connect_to_offline_server(uc2_network): backup_server: Server = uc2_network.get_node_by_hostname("backup_server") ftp_client: FTPClient = client_1.software_manager.software["FTPClient"] - ftp_server: FTPServer = backup_server.software_manager.software["FTPServer"] + ftp_server_service: FTPServer = backup_server.software_manager.software["FTPServer"] assert ftp_client.operating_state == ServiceOperatingState.RUNNING - assert ftp_server.operating_state == ServiceOperatingState.RUNNING + assert ftp_server_service.operating_state == ServiceOperatingState.RUNNING # create file on ftp server - ftp_server.file_system.create_file(file_name="test_file.txt", folder_name="file_share") + ftp_server_service.file_system.create_file(file_name="test_file.txt", folder_name="file_share") backup_server.power_off() @@ -82,7 +82,7 @@ def test_ftp_client_tries_to_connect_to_offline_server(uc2_network): uc2_network.apply_timestep(timestep=i) assert ftp_client.operating_state == ServiceOperatingState.RUNNING - assert ftp_server.operating_state == ServiceOperatingState.STOPPED + assert ftp_server_service.operating_state == ServiceOperatingState.STOPPED assert ( ftp_client.request_file( From ece9b14d6365c73b4278320c605e4f85113d613d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 26 Nov 2023 23:29:14 +0000 Subject: [PATCH 386/980] Resolve merge conflicts --- docs/source/primaite_session.rst | 215 +-- pyproject.toml | 1 + .../config/_package_data/example_config.yaml | 983 +++++++------- .../example_config_2_rl_agents.yaml | 1164 +++++++++++++++++ src/primaite/game/agent/actions.py | 26 +- .../game/agent/data_manipulation_bot.py | 2 +- src/primaite/game/agent/observations.py | 110 +- src/primaite/game/agent/rewards.py | 40 +- src/primaite/game/{session.py => game.py} | 238 +--- src/primaite/game/policy/__init__.py | 3 - src/primaite/main.py | 8 +- .../training_example_ray_multi_agent.ipynb | 127 ++ .../training_example_ray_single_agent.ipynb | 122 ++ .../notebooks/training_example_sb3.ipynb | 102 ++ src/primaite/notebooks/uc2_demo.ipynb | 306 +++++ src/primaite/session/__init__.py | 0 src/primaite/session/environment.py | 162 +++ src/primaite/{game => session}/io.py | 0 src/primaite/session/policy/__init__.py | 4 + .../{game => session}/policy/policy.py | 4 +- src/primaite/session/policy/rllib.py | 106 ++ src/primaite/{game => session}/policy/sb3.py | 4 +- src/primaite/session/session.py | 113 ++ .../assets/configs/bad_primaite_session.yaml | 1003 +++++++------- .../configs/eval_only_primaite_session.yaml | 1002 +++++++------- tests/assets/configs/multi_agent_session.yaml | 1156 ++++++++++++++++ .../assets/configs/test_primaite_session.yaml | 999 +++++++------- .../configs/train_only_primaite_session.yaml | 1003 +++++++------- tests/conftest.py | 3 +- .../test_rllib_multi_agent_environment.py | 45 + .../test_rllib_single_agent_environment.py | 40 + .../environments/test_sb3_environment.py | 27 + .../test_primaite_session.py | 24 +- 33 files changed, 6074 insertions(+), 3068 deletions(-) create mode 100644 src/primaite/config/_package_data/example_config_2_rl_agents.yaml rename src/primaite/game/{session.py => game.py} (71%) delete mode 100644 src/primaite/game/policy/__init__.py create mode 100644 src/primaite/notebooks/training_example_ray_multi_agent.ipynb create mode 100644 src/primaite/notebooks/training_example_ray_single_agent.ipynb create mode 100644 src/primaite/notebooks/training_example_sb3.ipynb create mode 100644 src/primaite/notebooks/uc2_demo.ipynb create mode 100644 src/primaite/session/__init__.py create mode 100644 src/primaite/session/environment.py rename src/primaite/{game => session}/io.py (100%) create mode 100644 src/primaite/session/policy/__init__.py rename src/primaite/{game => session}/policy/policy.py (93%) create mode 100644 src/primaite/session/policy/rllib.py rename src/primaite/{game => session}/policy/sb3.py (96%) create mode 100644 src/primaite/session/session.py create mode 100644 tests/assets/configs/multi_agent_session.yaml create mode 100644 tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py create mode 100644 tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py create mode 100644 tests/e2e_integration_tests/environments/test_sb3_environment.py diff --git a/docs/source/primaite_session.rst b/docs/source/primaite_session.rst index 472a361f..f3ef0399 100644 --- a/docs/source/primaite_session.rst +++ b/docs/source/primaite_session.rst @@ -7,207 +7,28 @@ Run a PrimAITE Session ====================== +``PrimaiteSession`` allows the user to train or evaluate an RL agent on the primaite simulation with just a config file, +no code required. It manages the lifecycle of a training or evaluation session, including the setup of the environment, +policy, simulator, agents, and IO. + +If you want finer control over the RL policy, you can interface with the :py:module::`primaite.session.environment` +module directly without running a session. + + + Run --- -A PrimAITE session can be ran either with the ``primaite session`` command from the cli +A PrimAITE session can be started either with the ``primaite session`` command from the cli (See :func:`primaite.cli.session`), or by calling :func:`primaite.main.run` from a Python terminal or Jupyter Notebook. -Both the ``primaite session`` and :func:`primaite.main.run` take a training config and a lay down config as parameters. -.. note:: - 🚧 *UNDER CONSTRUCTION* 🚧 +There are two parameters that can be specified: + - ``--config``: The path to the config file to use. If not specified, the default config file is used. + - ``--agent-load-file``: The path to the pre-trained agent to load. If not specified, a new agent is created. -.. - .. code-block:: bash - :caption: Unix CLI +Outputs +------- - cd ~/primaite/2.0.0 - source ./.venv/bin/activate - primaite session --tc ./config/my_training_config.yaml --ldc ./config/my_lay_down_config.yaml - - .. code-block:: powershell - :caption: Powershell CLI - - cd ~\primaite\2.0.0 - .\.venv\Scripts\activate - primaite session --tc .\config\my_training_config.yaml --ldc .\config\my_lay_down_config.yaml - - - .. code-block:: python - :caption: Python - - from primaite.main import run - - training_config = - lay_down_config = - run(training_config, lay_down_config) - - When a session is ran, a session output sub-directory is created in the users app sessions directory (``~/primaite/2.0.0/sessions``). - The sub-directory is formatted as such: ``~/primaite/2.0.0/sessions//_/`` - - For example, when running a session at 17:30:00 on 31st January 2023, the session will output to: - ``~/primaite/2.0.0/sessions/2023-01-31/2023-01-31_17-30-00/``. - - ``primaite session`` can be ran in the terminal/command prompt without arguments. It will use the default configs in the directory ``primaite/config/example_config``. - - To run a PrimAITE session using legacy training or laydown config files, add the ``--legacy-tc`` and/or ``legacy-ldc`` options. - - - - .. code-block:: bash - :caption: Unix CLI - - cd ~/primaite/2.0.0 - source ./.venv/bin/activate - primaite session --tc ./config/my_legacy_training_config.yaml --legacy-tc --ldc ./config/my_legacy_lay_down_config.yaml --legacy-ldc - - .. code-block:: powershell - :caption: Powershell CLI - - cd ~\primaite\2.0.0 - .\.venv\Scripts\activate - primaite session --tc .\config\my_legacy_training_config.yaml --legacy-tc --ldc .\config\my_legacy_lay_down_config.yaml --legacy-ldc - - - .. code-block:: python - :caption: Python - - from primaite.main import run - - training_config = - lay_down_config = - run(training_config, lay_down_config, legacy_training_config=True, legacy_lay_down_config=True) - - - - - Outputs - ------- - - PrimAITE produces four types of outputs: - - * Session Metadata - * Results - * Diagrams - * Saved agents (training checkpoints and a final trained agent) - - - **Session Metadata** - - PrimAITE creates a ``session_metadata.json`` file that contains the following metadata: - - * **uuid** - The UUID assigned to the session upon instantiation. - * **start_datetime** - The date & time the session started in iso format. - * **end_datetime** - The date & time the session ended in iso format. - * **learning** - * **total_episodes** - The total number of training episodes completed. - * **total_time_steps** - The total number of training time steps completed. - * **evaluation** - * **total_episodes** - The total number of evaluation episodes completed. - * **total_time_steps** - The total number of evaluation time steps completed. - * **env** - * **training_config** - * **All training config items** - * **lay_down_config** - * **All lay down config items** - - - **Results** - - PrimAITE automatically creates two sets of results from each learning and evaluation session: - - * Average reward per episode - a csv file listing the average reward for each episode of the session. This provides, for example, an indication of the change over a training session of the reward value - * All transactions - a csv file listing the following values for every step of every episode: - - * Timestamp - * Episode number - * Step number - * Reward value - * Action taken (as presented by the blue agent on this step). Individual elements of the action space are presented in the format AS_X - * Initial observation space (what the blue agent observed when it decided its action) - - **Diagrams** - - * For each session, PrimAITE automatically creates a visualisation of the system / network lay down configuration. - * For each learning and evaluation task within the session, PrimAITE automatically plots the average reward per episode using PlotLY and saves it to the learning or evaluation subdirectory in the session directory. - - **Saved agents** - - For each training session, assuming the agent being trained implements the *save()* function and this function is called by the code, PrimAITE automatically saves the agent state. - - **Example Session Directory Structure** - - .. code-block:: text - - ~/ - └── primaite/ - └── 2.0.0/ - └── sessions/ - └── 2023-07-18/ - └── 2023-07-18_11-06-04/ - ├── evaluation/ - │ ├── all_transactions_2023-07-18_11-06-04.csv - │ ├── average_reward_per_episode_2023-07-18_11-06-04.csv - │ └── average_reward_per_episode_2023-07-18_11-06-04.png - ├── learning/ - │ ├── all_transactions_2023-07-18_11-06-04.csv - │ ├── average_reward_per_episode_2023-07-18_11-06-04.csv - │ ├── average_reward_per_episode_2023-07-18_11-06-04.png - │ ├── checkpoints/ - │ │ └── sb3ppo_10.zip - │ ├── SB3_PPO.zip - │ └── tensorboard_logs/ - │ ├── PPO_1/ - │ │ └── events.out.tfevents.1689674765.METD-9PMRFB3.42960.0 - │ ├── PPO_2/ - │ │ └── events.out.tfevents.1689674766.METD-9PMRFB3.42960.1 - │ ├── PPO_3/ - │ │ └── events.out.tfevents.1689674766.METD-9PMRFB3.42960.2 - │ ├── PPO_4/ - │ │ └── events.out.tfevents.1689674767.METD-9PMRFB3.42960.3 - │ ├── PPO_5/ - │ │ └── events.out.tfevents.1689674767.METD-9PMRFB3.42960.4 - │ ├── PPO_6/ - │ │ └── events.out.tfevents.1689674768.METD-9PMRFB3.42960.5 - │ ├── PPO_7/ - │ │ └── events.out.tfevents.1689674768.METD-9PMRFB3.42960.6 - │ ├── PPO_8/ - │ │ └── events.out.tfevents.1689674769.METD-9PMRFB3.42960.7 - │ ├── PPO_9/ - │ │ └── events.out.tfevents.1689674770.METD-9PMRFB3.42960.8 - │ └── PPO_10/ - │ └── events.out.tfevents.1689674770.METD-9PMRFB3.42960.9 - ├── network_2023-07-18_11-06-04.png - └── session_metadata.json - - Loading a session - ----------------- - - A previous session can be loaded by providing the **directory** of the previous session to either the ``primaite session`` command from the cli - (See :func:`primaite.cli.session`), or by calling :func:`primaite.main.run` with session_path. - - .. tabs:: - - .. code-tab:: bash - :caption: Unix CLI - - cd ~/primaite/2.0.0 - source ./.venv/bin/activate - primaite session --load "path/to/session" - - .. code-tab:: bash - :caption: Powershell CLI - - cd ~\primaite\2.0.0 - .\.venv\Scripts\activate - primaite session --load "path\to\session" - - - .. code-tab:: python - :caption: Python - - from primaite.main import run - - run(session_path=) - - When PrimAITE runs a loaded session, PrimAITE will output in the provided session directory +Running a session creates a session output directory in your user data folder. The filepath looks like this: +``~/primaite/3.0.0/sessions/YYYY-MM-DD/HH-MM-SS/``. This folder contains the simulation sys logs generated by each node, +the saved agent checkpoints, and final model. diff --git a/pyproject.toml b/pyproject.toml index 92f78ec0..3e5b959a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,7 @@ dependencies = [ "tensorflow==2.12.0", "typer[all]==0.9.0", "pydantic==2.1.1", + "ray[rllib] == 2.8.0, < 3" ] [tool.setuptools.dynamic] diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 6455272c..d9896b01 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -1,8 +1,8 @@ training_config: - rl_framework: SB3 + rl_framework: RLLIB_single_agent rl_algorithm: PPO seed: 333 - n_learn_episodes: 25 + n_learn_episodes: 1 n_eval_episodes: 5 max_steps_per_episode: 128 deterministic_eval: false @@ -15,7 +15,8 @@ io_settings: checkpoint_interval: 5 -game_config: +game: + max_episode_length: 256 ports: - ARP - DNS @@ -26,522 +27,504 @@ game_config: - TCP - UDP - agents: - - ref: client_1_green_user - team: GREEN - type: GreenWebBrowsingAgent - observation_space: - type: UC2GreenObservation - action_space: - action_list: - - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com - options: - nodes: - - node_ref: client_2 - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 - reward_function: - reward_components: - - type: DUMMY + reward_function: + reward_components: + - type: DUMMY - agent_settings: - start_settings: - start_step: 5 - frequency: 4 - variance: 3 + agent_settings: + start_settings: + start_step: 5 + frequency: 4 + variance: 3 - - ref: client_1_data_manipulation_red_bot - team: RED - type: RedDatabaseCorruptingAgent + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: + observation_space: + type: UC2RedObservation + options: + nodes: {} + + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_ref: client_1 + applications: + - application_ref: data_manipulation_bot + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 + + - ref: defender + team: BLUE + type: ProxyAgent + + observation_space: + type: UC2BlueObservation + options: + num_services_per_node: 1 + num_folders_per_node: 1 + num_files_per_folder: 1 + num_nics_per_node: 2 + nodes: + - node_ref: domain_controller + services: + - service_ref: domain_controller_dns_server + - node_ref: web_server + services: + - service_ref: web_server_database_client + - node_ref: database_server + services: + - service_ref: database_service + folders: + - folder_name: database + files: + - file_name: database.db + - node_ref: backup_server + # services: + # - service_ref: backup_service + - node_ref: security_suite + - node_ref: client_1 + - node_ref: client_2 + links: + - link_ref: router_1___switch_1 + - link_ref: router_1___switch_2 + - link_ref: switch_1___domain_controller + - link_ref: switch_1___web_server + - link_ref: switch_1___database_server + - link_ref: switch_1___backup_server + - link_ref: switch_1___security_suite + - link_ref: switch_2___client_1 + - link_ref: switch_2___client_2 + - link_ref: switch_2___security_suite + acl: + options: + max_acl_rules: 10 + router_node_ref: router_1 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 - node_ref: client_1 - observations: - - logon_status - - operating_status - applications: - - application_ref: data_manipulation_bot - observations: - operating_status - health_status - folders: {} + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 + ics: null - action_space: - action_list: - - type: DONOTHING - # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com + + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_step: 5 + frequency: 4 + variance: 3 + + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: + type: UC2RedObservation + options: + nodes: + - node_ref: client_1 + observations: + - logon_status + - operating_status + services: + - service_ref: data_manipulation_bot + observations: + operating_status + health_status + folders: {} + + action_space: + action_list: + - type: DONOTHING + # None: """Init method for ActionManager. - :param session: Reference to the session to which the agent belongs. - :type session: PrimaiteSession + :param game: Reference to the game to which the agent belongs. + :type game: PrimaiteGame :param actions: List of action types which should be made available to the agent. :type actions: List[str] :param node_uuids: List of node UUIDs that this agent can act on. @@ -633,8 +633,8 @@ class ActionManager: :param act_map: Action map which maps integers to actions. Used for restricting the set of possible actions. :type act_map: Optional[Dict[int, Dict]] """ - self.session: "PrimaiteSession" = session - self.sim: Simulation = self.session.simulation + self.game: "PrimaiteGame" = game + self.sim: Simulation = self.game.simulation self.node_uuids: List[str] = node_uuids self.application_uuids: List[List[str]] = application_uuids self.protocols: List[str] = protocols @@ -874,7 +874,7 @@ class ActionManager: return nics[nic_idx] @classmethod - def from_config(cls, session: "PrimaiteSession", cfg: Dict) -> "ActionManager": + def from_config(cls, game: "PrimaiteGame", cfg: Dict) -> "ActionManager": """ Construct an ActionManager from a config definition. @@ -893,20 +893,20 @@ class ActionManager: These options are used to calculate the shape of the action space, and to provide additional information to the ActionManager which is required to convert the agent's action choice into a CAOS request. - :param session: The Primaite Session to which the agent belongs. - :type session: PrimaiteSession + :param game: The Primaite Game to which the agent belongs. + :type game: PrimaiteGame :param cfg: The action space config. :type cfg: Dict :return: The constructed ActionManager. :rtype: ActionManager """ obj = cls( - session=session, + game=game, actions=cfg["action_list"], # node_uuids=cfg["options"]["node_uuids"], **cfg["options"], - protocols=session.options.protocols, - ports=session.options.ports, + protocols=game.options.protocols, + ports=game.options.ports, ip_address_list=None, act_map=cfg.get("action_map"), ) diff --git a/src/primaite/game/agent/data_manipulation_bot.py b/src/primaite/game/agent/data_manipulation_bot.py index 51221154..8237ce06 100644 --- a/src/primaite/game/agent/data_manipulation_bot.py +++ b/src/primaite/game/agent/data_manipulation_bot.py @@ -38,7 +38,7 @@ class DataManipulationAgent(AbstractScriptedAgent): :return: _description_ :rtype: Tuple[str, Dict] """ - current_timestep = self.action_manager.session.step_counter + current_timestep = self.action_manager.game.step_counter if current_timestep < self.next_execution_timestep: return "DONOTHING", {"dummy": 0} diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index a74771c0..14fb2fa7 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -11,7 +11,7 @@ from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_ST _LOGGER = getLogger(__name__) if TYPE_CHECKING: - from primaite.game.session import PrimaiteSession + from primaite.game.game import PrimaiteGame class AbstractObservation(ABC): @@ -37,10 +37,10 @@ class AbstractObservation(ABC): @classmethod @abstractmethod - def from_config(cls, config: Dict, session: "PrimaiteSession"): + def from_config(cls, config: Dict, game: "PrimaiteGame"): """Create this observation space component form a serialised format. - The `session` parameter is for a the PrimaiteSession object that spawns this component. During deserialisation, + The `game` parameter is for a the PrimaiteGame object that spawns this component. During deserialisation, a subclass of this class may need to translate from a 'reference' to a UUID. """ pass @@ -91,13 +91,13 @@ class FileObservation(AbstractObservation): return spaces.Dict({"health_status": spaces.Discrete(6)}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession", parent_where: List[str] = None) -> "FileObservation": + def from_config(cls, config: Dict, game: "PrimaiteGame", parent_where: List[str] = None) -> "FileObservation": """Create file observation from a config. :param config: Dictionary containing the configuration for this file observation. :type config: Dict - :param session: _description_ - :type session: PrimaiteSession + :param game: _description_ + :type game: PrimaiteGame :param parent_where: _description_, defaults to None :type parent_where: _type_, optional :return: _description_ @@ -149,20 +149,20 @@ class ServiceObservation(AbstractObservation): @classmethod def from_config( - cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]] = None + cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]] = None ) -> "ServiceObservation": """Create service observation from a config. :param config: Dictionary containing the configuration for this service observation. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :param parent_where: Where in the simulation state dictionary this service's parent node is located. Optional. :type parent_where: Optional[List[str]], optional :return: Constructed service observation :rtype: ServiceObservation """ - return cls(where=parent_where + ["services", session.ref_map_services[config["service_ref"]].uuid]) + return cls(where=parent_where + ["services", game.ref_map_services[config["service_ref"]].uuid]) class LinkObservation(AbstractObservation): @@ -219,17 +219,17 @@ class LinkObservation(AbstractObservation): return spaces.Dict({"PROTOCOLS": spaces.Dict({"ALL": spaces.Discrete(11)})}) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "LinkObservation": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "LinkObservation": """Create link observation from a config. :param config: Dictionary containing the configuration for this link observation. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :return: Constructed link observation :rtype: LinkObservation """ - return cls(where=["network", "links", session.ref_map_links[config["link_ref"]]]) + return cls(where=["network", "links", game.ref_map_links[config["link_ref"]]]) class FolderObservation(AbstractObservation): @@ -310,15 +310,15 @@ class FolderObservation(AbstractObservation): @classmethod def from_config( - cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]], num_files_per_folder: int = 2 + cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]], num_files_per_folder: int = 2 ) -> "FolderObservation": """Create folder observation from a config. Also creates child file observations. :param config: Dictionary containing the configuration for this folder observation. Includes the name of the folder and the files inside of it. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :param parent_where: Where in the simulation state dictionary to find the information about this folder's parent node. A typical location for a node ``where`` can be: ['network','nodes',,'file_system'] @@ -332,7 +332,7 @@ class FolderObservation(AbstractObservation): where = parent_where + ["folders", config["folder_name"]] file_configs = config["files"] - files = [FileObservation.from_config(config=f, session=session, parent_where=where) for f in file_configs] + files = [FileObservation.from_config(config=f, game=game, parent_where=where) for f in file_configs] return cls(where=where, files=files, num_files_per_folder=num_files_per_folder) @@ -376,15 +376,13 @@ class NicObservation(AbstractObservation): return spaces.Dict({"nic_status": spaces.Discrete(3)}) @classmethod - def from_config( - cls, config: Dict, session: "PrimaiteSession", parent_where: Optional[List[str]] - ) -> "NicObservation": + def from_config(cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]]) -> "NicObservation": """Create NIC observation from a config. :param config: Dictionary containing the configuration for this NIC observation. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :param parent_where: Where in the simulation state dictionary to find the information about this NIC's parent node. A typical location for a node ``where`` can be: ['network','nodes',] :type parent_where: Optional[List[str]] @@ -515,7 +513,7 @@ class NodeObservation(AbstractObservation): def from_config( cls, config: Dict, - session: "PrimaiteSession", + game: "PrimaiteGame", parent_where: Optional[List[str]] = None, num_services_per_node: int = 2, num_folders_per_node: int = 2, @@ -526,8 +524,8 @@ class NodeObservation(AbstractObservation): :param config: Dictionary containing the configuration for this node observation. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :param parent_where: Where in the simulation state dictionary to find the information about this node's parent network. A typical location for it would be: ['network',] :type parent_where: Optional[List[str]] @@ -543,24 +541,24 @@ class NodeObservation(AbstractObservation): :return: Constructed node observation :rtype: NodeObservation """ - node_uuid = session.ref_map_nodes[config["node_ref"]] + node_uuid = game.ref_map_nodes[config["node_ref"]] if parent_where is None: where = ["network", "nodes", node_uuid] else: where = parent_where + ["nodes", node_uuid] svc_configs = config.get("services", {}) - services = [ServiceObservation.from_config(config=c, session=session, parent_where=where) for c in svc_configs] + services = [ServiceObservation.from_config(config=c, game=game, parent_where=where) for c in svc_configs] folder_configs = config.get("folders", {}) folders = [ FolderObservation.from_config( - config=c, session=session, parent_where=where, num_files_per_folder=num_files_per_folder + config=c, game=game, parent_where=where, num_files_per_folder=num_files_per_folder ) for c in folder_configs ] - nic_uuids = session.simulation.network.nodes[node_uuid].nics.keys() + nic_uuids = game.simulation.network.nodes[node_uuid].nics.keys() nic_configs = [{"nic_uuid": n for n in nic_uuids}] if nic_uuids else [] - nics = [NicObservation.from_config(config=c, session=session, parent_where=where) for c in nic_configs] + nics = [NicObservation.from_config(config=c, game=game, parent_where=where) for c in nic_configs] logon_status = config.get("logon_status", False) return cls( where=where, @@ -694,13 +692,13 @@ class AclObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "AclObservation": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "AclObservation": """Generate ACL observation from a config. :param config: Dictionary containing the configuration for this ACL observation. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :return: Observation object :rtype: AclObservation """ @@ -709,15 +707,15 @@ class AclObservation(AbstractObservation): for ip_idx, ip_map_config in enumerate(config["ip_address_order"]): node_ref = ip_map_config["node_ref"] nic_num = ip_map_config["nic_num"] - node_obj = session.simulation.network.nodes[session.ref_map_nodes[node_ref]] + node_obj = game.simulation.network.nodes[game.ref_map_nodes[node_ref]] nic_obj = node_obj.ethernet_port[nic_num] node_ip_to_idx[nic_obj.ip_address] = ip_idx + 2 - router_uuid = session.ref_map_nodes[config["router_node_ref"]] + router_uuid = game.ref_map_nodes[config["router_node_ref"]] return cls( node_ip_to_id=node_ip_to_idx, - ports=session.options.ports, - protocols=session.options.protocols, + ports=game.options.ports, + protocols=game.options.protocols, where=["network", "nodes", router_uuid, "acl", "acl"], num_rules=max_acl_rules, ) @@ -740,7 +738,7 @@ class NullObservation(AbstractObservation): return spaces.Discrete(1) @classmethod - def from_config(cls, config: Dict, session: Optional["PrimaiteSession"] = None) -> "NullObservation": + def from_config(cls, config: Dict, game: Optional["PrimaiteGame"] = None) -> "NullObservation": """ Create null observation from a config. @@ -836,14 +834,14 @@ class UC2BlueObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "UC2BlueObservation": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "UC2BlueObservation": """Create UC2 blue observation from a config. :param config: Dictionary containing the configuration for this UC2 blue observation. This includes the nodes, links, ACL and ICS observations. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame :return: Constructed UC2 blue observation :rtype: UC2BlueObservation """ @@ -855,7 +853,7 @@ class UC2BlueObservation(AbstractObservation): nodes = [ NodeObservation.from_config( config=n, - session=session, + game=game, num_services_per_node=num_services_per_node, num_folders_per_node=num_folders_per_node, num_files_per_folder=num_files_per_folder, @@ -865,13 +863,13 @@ class UC2BlueObservation(AbstractObservation): ] link_configs = config["links"] - links = [LinkObservation.from_config(config=link, session=session) for link in link_configs] + links = [LinkObservation.from_config(config=link, game=game) for link in link_configs] acl_config = config["acl"] - acl = AclObservation.from_config(config=acl_config, session=session) + acl = AclObservation.from_config(config=acl_config, game=game) ics_config = config["ics"] - ics = ICSObservation.from_config(config=ics_config, session=session) + ics = ICSObservation.from_config(config=ics_config, game=game) new = cls(nodes=nodes, links=links, acl=acl, ics=ics, where=["network"]) return new @@ -907,17 +905,17 @@ class UC2RedObservation(AbstractObservation): ) @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "UC2RedObservation": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "UC2RedObservation": """ Create UC2 red observation from a config. :param config: Dictionary containing the configuration for this UC2 red observation. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame """ node_configs = config["nodes"] - nodes = [NodeObservation.from_config(config=cfg, session=session) for cfg in node_configs] + nodes = [NodeObservation.from_config(config=cfg, game=game) for cfg in node_configs] return cls(nodes=nodes, where=["network"]) @@ -966,7 +964,7 @@ class ObservationManager: return self.obs.space @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "ObservationManager": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "ObservationManager": """Create observation space from a config. :param config: Dictionary containing the configuration for this observation space. @@ -974,14 +972,14 @@ class ObservationManager: UC2BlueObservation, UC2RedObservation, UC2GreenObservation) The other key is 'options' which are passed to the constructor of the selected observation class. :type config: Dict - :param session: Reference to the PrimaiteSession object that spawned this observation. - :type session: PrimaiteSession + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame """ if config["type"] == "UC2BlueObservation": - return cls(UC2BlueObservation.from_config(config.get("options", {}), session=session)) + return cls(UC2BlueObservation.from_config(config.get("options", {}), game=game)) elif config["type"] == "UC2RedObservation": - return cls(UC2RedObservation.from_config(config.get("options", {}), session=session)) + return cls(UC2RedObservation.from_config(config.get("options", {}), game=game)) elif config["type"] == "UC2GreenObservation": - return cls(UC2GreenObservation.from_config(config.get("options", {}), session=session)) + return cls(UC2GreenObservation.from_config(config.get("options", {}), game=game)) else: raise ValueError("Observation space type invalid") diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index da1331b0..8a1c2da4 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -34,7 +34,7 @@ from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_ST _LOGGER = getLogger(__name__) if TYPE_CHECKING: - from primaite.game.session import PrimaiteSession + from primaite.game.game import PrimaiteGame class AbstractReward: @@ -47,13 +47,13 @@ class AbstractReward: @classmethod @abstractmethod - def from_config(cls, config: dict, session: "PrimaiteSession") -> "AbstractReward": + def from_config(cls, config: dict, game: "PrimaiteGame") -> "AbstractReward": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor :type config: dict - :param session: Reference to the PrimAITE Session object - :type session: PrimaiteSession + :param game: Reference to the PrimAITE Game object + :type game: PrimaiteGame :return: The reward component. :rtype: AbstractReward """ @@ -68,13 +68,13 @@ class DummyReward(AbstractReward): return 0.0 @classmethod - def from_config(cls, config: dict, session: "PrimaiteSession") -> "DummyReward": + def from_config(cls, config: dict, game: "PrimaiteGame") -> "DummyReward": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor. Should be empty. :type config: dict - :param session: Reference to the PrimAITE Session object - :type session: PrimaiteSession + :param game: Reference to the PrimAITE Game object + :type game: PrimaiteGame """ return cls() @@ -119,13 +119,13 @@ class DatabaseFileIntegrity(AbstractReward): return 0 @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "DatabaseFileIntegrity": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "DatabaseFileIntegrity": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor :type config: Dict - :param session: Reference to the PrimAITE Session object - :type session: PrimaiteSession + :param game: Reference to the PrimAITE Game object + :type game: PrimaiteGame :return: The reward component. :rtype: DatabaseFileIntegrity """ @@ -147,7 +147,7 @@ class DatabaseFileIntegrity(AbstractReward): f"{cls.__name__} could not be initialised from config because file_name parameter was not specified" ) return DummyReward() # TODO: better error handling - node_uuid = session.ref_map_nodes[node_ref] + node_uuid = game.ref_map_nodes[node_ref] if not node_uuid: _LOGGER.error( ( @@ -193,13 +193,13 @@ class WebServer404Penalty(AbstractReward): return 0.0 @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "WebServer404Penalty": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "WebServer404Penalty": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor :type config: Dict - :param session: Reference to the PrimAITE Session object - :type session: PrimaiteSession + :param game: Reference to the PrimAITE Game object + :type game: PrimaiteGame :return: The reward component. :rtype: WebServer404Penalty """ @@ -212,8 +212,8 @@ class WebServer404Penalty(AbstractReward): ) _LOGGER.warn(msg) return DummyReward() # TODO: should we error out with incorrect inputs? Probably! - node_uuid = session.ref_map_nodes[node_ref] - service_uuid = session.ref_map_services[service_ref].uuid + node_uuid = game.ref_map_nodes[node_ref] + service_uuid = game.ref_map_services[service_ref].uuid if not (node_uuid and service_uuid): msg = ( f"{cls.__name__} could not be initialised because node {node_ref} and service {service_ref} were not" @@ -265,13 +265,13 @@ class RewardFunction: return self.current_reward @classmethod - def from_config(cls, config: Dict, session: "PrimaiteSession") -> "RewardFunction": + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "RewardFunction": """Create a reward function from a config dictionary. :param config: dict of options for the reward manager's constructor :type config: Dict - :param session: Reference to the PrimAITE Session object - :type session: PrimaiteSession + :param game: Reference to the PrimAITE Game object + :type game: PrimaiteGame :return: The reward manager. :rtype: RewardFunction """ @@ -281,6 +281,6 @@ class RewardFunction: rew_type = rew_component_cfg["type"] weight = rew_component_cfg.get("weight", 1.0) rew_class = cls.__rew_class_identifiers[rew_type] - rew_instance = rew_class.from_config(config=rew_component_cfg.get("options", {}), session=session) + rew_instance = rew_class.from_config(config=rew_component_cfg.get("options", {}), game=game) new.regsiter_component(component=rew_instance, weight=weight) return new diff --git a/src/primaite/game/session.py b/src/primaite/game/game.py similarity index 71% rename from src/primaite/game/session.py rename to src/primaite/game/game.py index 095458b7..ae60bbc1 100644 --- a/src/primaite/game/session.py +++ b/src/primaite/game/game.py @@ -1,12 +1,8 @@ -"""PrimAITE session - the main entry point to training agents on PrimAITE.""" +"""PrimAITE game - Encapsulates the simulation and agents.""" from copy import deepcopy -from enum import Enum from ipaddress import IPv4Address -from pathlib import Path -from typing import Any, Dict, List, Literal, Optional, SupportsFloat, Tuple +from typing import Dict, List -import gymnasium -from gymnasium.core import ActType, ObsType from pydantic import BaseModel, ConfigDict from primaite import getLogger @@ -15,8 +11,6 @@ from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent, RandomAgent from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction -from primaite.game.io import SessionIO, SessionIOSettings -from primaite.game.policy.policy import PolicyABC from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router @@ -40,65 +34,7 @@ from primaite.simulator.system.services.web_server.web_server import WebServer _LOGGER = getLogger(__name__) -class PrimaiteGymEnv(gymnasium.Env): - """ - Thin wrapper env to provide agents with a gymnasium API. - - This is always a single agent environment since gymnasium is a single agent API. Therefore, we can make some - assumptions about the agent list always having a list of length 1. - """ - - def __init__(self, session: "PrimaiteSession", agents: List[ProxyAgent]): - """Initialise the environment.""" - super().__init__() - self.session: "PrimaiteSession" = session - self.agent: ProxyAgent = agents[0] - - def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: - """Perform a step in the environment.""" - # make ProxyAgent store the action chosen my the RL policy - self.agent.store_action(action) - # apply_agent_actions accesses the action we just stored - self.session.apply_agent_actions() - self.session.advance_timestep() - state = self.session.get_sim_state() - self.session.update_agents(state) - - next_obs = self._get_obs() - reward = self.agent.reward_function.current_reward - terminated = False - truncated = self.session.calculate_truncated() - info = {} - - return next_obs, reward, terminated, truncated, info - - def reset(self, seed: Optional[int] = None) -> Tuple[ObsType, Dict[str, Any]]: - """Reset the environment.""" - self.session.reset() - state = self.session.get_sim_state() - self.session.update_agents(state) - next_obs = self._get_obs() - info = {} - return next_obs, info - - @property - def action_space(self) -> gymnasium.Space: - """Return the action space of the environment.""" - return self.agent.action_manager.space - - @property - def observation_space(self) -> gymnasium.Space: - """Return the observation space of the environment.""" - return gymnasium.spaces.flatten_space(self.agent.observation_manager.space) - - def _get_obs(self) -> ObsType: - """Return the current observation.""" - unflat_space = self.agent.observation_manager.space - unflat_obs = self.agent.observation_manager.current_observation - return gymnasium.spaces.flatten(unflat_space, unflat_obs) - - -class PrimaiteSessionOptions(BaseModel): +class PrimaiteGameOptions(BaseModel): """ Global options which are applicable to all of the agents in the game. @@ -107,40 +43,20 @@ class PrimaiteSessionOptions(BaseModel): model_config = ConfigDict(extra="forbid") + max_episode_length: int = 256 ports: List[str] protocols: List[str] -class TrainingOptions(BaseModel): - """Options for training the RL agent.""" +class PrimaiteGame: + """ + Primaite game encapsulates the simulation and agents which interact with it. - model_config = ConfigDict(extra="forbid") - - rl_framework: Literal["SB3", "RLLIB"] - rl_algorithm: Literal["PPO", "A2C"] - n_learn_episodes: int - n_eval_episodes: Optional[int] = None - max_steps_per_episode: int - # checkpoint_freq: Optional[int] = None - deterministic_eval: bool - seed: Optional[int] - n_agents: int - agent_references: List[str] - - -class SessionMode(Enum): - """Helper to keep track of the current session mode.""" - - TRAIN = "train" - EVAL = "eval" - MANUAL = "manual" - - -class PrimaiteSession: - """The main entrypoint for PrimAITE sessions, this manages a simulation, agents, and environments.""" + Provides main logic loop for the game. However, it does not provide policy training, or a gymnasium environment. + """ def __init__(self): - """Initialise a PrimaiteSession object.""" + """Initialise a PrimaiteGame object.""" self.simulation: Simulation = Simulation() """Simulation object with which the agents will interact.""" @@ -159,15 +75,9 @@ class PrimaiteSession: self.episode_counter: int = 0 """Current episode number.""" - self.options: PrimaiteSessionOptions + self.options: PrimaiteGameOptions """Special options that apply for the entire game.""" - self.training_options: TrainingOptions - """Options specific to agent training.""" - - self.policy: PolicyABC - """The reinforcement learning policy.""" - self.ref_map_nodes: Dict[str, Node] = {} """Mapping from unique node reference name to node object. Used when parsing config files.""" @@ -180,40 +90,6 @@ class PrimaiteSession: self.ref_map_links: Dict[str, Link] = {} """Mapping from human-readable link reference to link object. Used when parsing config files.""" - self.env: PrimaiteGymEnv - """The environment that the agent can consume. Could be PrimaiteEnv.""" - - self.mode: SessionMode = SessionMode.MANUAL - """Current session mode.""" - - self.io_manager = SessionIO() - """IO manager for the session.""" - - def start_session(self) -> None: - """Commence the training session.""" - self.mode = SessionMode.TRAIN - n_learn_episodes = self.training_options.n_learn_episodes - n_eval_episodes = self.training_options.n_eval_episodes - max_steps_per_episode = self.training_options.max_steps_per_episode - - deterministic_eval = self.training_options.deterministic_eval - self.policy.learn( - n_episodes=n_learn_episodes, - timesteps_per_episode=max_steps_per_episode, - ) - self.save_models() - - self.mode = SessionMode.EVAL - if n_eval_episodes > 0: - self.policy.eval(n_episodes=n_eval_episodes, deterministic=deterministic_eval) - - self.mode = SessionMode.MANUAL - - def save_models(self) -> None: - """Save the RL models.""" - save_path = self.io_manager.generate_model_save_path("temp_model_name") - self.policy.save(save_path) - def step(self): """ Perform one step of the simulation/agent loop. @@ -232,7 +108,7 @@ class PrimaiteSession: single-agent gym, make sure to update the ProxyAgent's action with the action before calling ``self.apply_agent_actions()``. """ - _LOGGER.debug(f"Stepping primaite session. Step counter: {self.step_counter}") + _LOGGER.debug(f"Stepping. Step counter: {self.step_counter}") # Get the current state of the simulation sim_state = self.get_sim_state() @@ -274,29 +150,29 @@ class PrimaiteSession: def calculate_truncated(self) -> bool: """Calculate whether the episode is truncated.""" current_step = self.step_counter - max_steps = self.training_options.max_steps_per_episode + max_steps = self.options.max_episode_length if current_step >= max_steps: return True return False def reset(self) -> None: - """Reset the session, this will reset the simulation.""" + """Reset the game, this will reset the simulation.""" self.episode_counter += 1 self.step_counter = 0 - _LOGGER.debug(f"Restting primaite session, episode = {self.episode_counter}") + _LOGGER.debug(f"Resetting primaite game, episode = {self.episode_counter}") self.simulation = deepcopy(self._simulation_initial_state) def close(self) -> None: - """Close the session, this will stop the env and close the simulation.""" + """Close the game, this will close the simulation.""" return NotImplemented @classmethod - def from_config(cls, cfg: dict, agent_load_path: Optional[str] = None) -> "PrimaiteSession": - """Create a PrimaiteSession object from a config dictionary. + def from_config(cls, cfg: Dict) -> "PrimaiteGame": + """Create a PrimaiteGame object from a config dictionary. The config dictionary should have the following top-level keys: 1. training_config: options for training the RL agent. - 2. game_config: options for the game itself. Used by PrimaiteSession. + 2. game_config: options for the game itself. Used by PrimaiteGame. 3. simulation: defines the network topology and the initial state of the simulation. The specification for each of the three major areas is described in a separate documentation page. @@ -304,26 +180,19 @@ class PrimaiteSession: :param cfg: The config dictionary. :type cfg: dict - :return: A PrimaiteSession object. - :rtype: PrimaiteSession + :return: A PrimaiteGame object. + :rtype: PrimaiteGame """ - sess = cls() - sess.options = PrimaiteSessionOptions( - ports=cfg["game_config"]["ports"], - protocols=cfg["game_config"]["protocols"], - ) - sess.training_options = TrainingOptions(**cfg["training_config"]) + game = cls() + game.options = PrimaiteGameOptions(**cfg["game"]) - # READ IO SETTINGS (this sets the global session path as well) # TODO: GLOBAL SIDE EFFECTS... - io_settings = cfg.get("io_settings", {}) - sess.io_manager.settings = SessionIOSettings(**io_settings) - - sim = sess.simulation + # 1. create simulation + sim = game.simulation net = sim.network - sess.ref_map_nodes: Dict[str, Node] = {} - sess.ref_map_services: Dict[str, Service] = {} - sess.ref_map_links: Dict[str, Link] = {} + game.ref_map_nodes: Dict[str, Node] = {} + game.ref_map_services: Dict[str, Service] = {} + game.ref_map_links: Dict[str, Link] = {} nodes_cfg = cfg["simulation"]["network"]["nodes"] links_cfg = cfg["simulation"]["network"]["links"] @@ -400,7 +269,7 @@ class PrimaiteSession: print(f"installing {service_type} on node {new_node.hostname}") new_node.software_manager.install(service_types_mapping[service_type]) new_service = new_node.software_manager.software[service_type] - sess.ref_map_services[service_ref] = new_service + game.ref_map_services[service_ref] = new_service else: print(f"service type not found {service_type}") # service-dependent options @@ -434,7 +303,7 @@ class PrimaiteSession: if application_type in application_types_mapping: new_node.software_manager.install(application_types_mapping[application_type]) new_application = new_node.software_manager.software[application_type] - sess.ref_map_applications[application_ref] = new_application + game.ref_map_applications[application_ref] = new_application else: print(f"application type not found {application_type}") @@ -442,7 +311,7 @@ class PrimaiteSession: if "options" in application_cfg: opt = application_cfg["options"] new_application.configure( - server_ip_address=opt.get("server_ip"), + server_ip_address=IPv4Address(opt.get("server_ip")), payload=opt.get("payload"), port_scan_p_of_success=float(opt.get("port_scan_p_of_success", "0.1")), data_manipulation_p_of_success=float(opt.get("data_manipulation_p_of_success", "0.1")), @@ -453,7 +322,7 @@ class PrimaiteSession: net.add_node(new_node) new_node.power_on() - sess.ref_map_nodes[ + game.ref_map_nodes[ node_ref ] = ( new_node.uuid @@ -461,8 +330,8 @@ class PrimaiteSession: # 2. create links between nodes for link_cfg in links_cfg: - node_a = net.nodes[sess.ref_map_nodes[link_cfg["endpoint_a_ref"]]] - node_b = net.nodes[sess.ref_map_nodes[link_cfg["endpoint_b_ref"]]] + node_a = net.nodes[game.ref_map_nodes[link_cfg["endpoint_a_ref"]]] + node_b = net.nodes[game.ref_map_nodes[link_cfg["endpoint_b_ref"]]] if isinstance(node_a, Switch): endpoint_a = node_a.switch_ports[link_cfg["endpoint_a_port"]] else: @@ -472,13 +341,10 @@ class PrimaiteSession: else: endpoint_b = node_b.ethernet_port[link_cfg["endpoint_b_port"]] new_link = net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b) - sess.ref_map_links[link_cfg["ref"]] = new_link.uuid - # endpoint_a.enable() - # endpoint_b.enable() + game.ref_map_links[link_cfg["ref"]] = new_link.uuid # 3. create agents - game_cfg = cfg["game_config"] - agents_cfg = game_cfg["agents"] + agents_cfg = cfg["agents"] for agent_cfg in agents_cfg: agent_ref = agent_cfg["ref"] # noqa: F841 @@ -488,7 +354,7 @@ class PrimaiteSession: reward_function_cfg = agent_cfg["reward_function"] # CREATE OBSERVATION SPACE - obs_space = ObservationManager.from_config(observation_space_cfg, sess) + obs_space = ObservationManager.from_config(observation_space_cfg, game) # CREATE ACTION SPACE action_space_cfg["options"]["node_uuids"] = [] @@ -497,7 +363,7 @@ class PrimaiteSession: # if a list of nodes is defined, convert them from node references to node UUIDs for action_node_option in action_space_cfg.get("options", {}).pop("nodes", {}): if "node_ref" in action_node_option: - node_uuid = sess.ref_map_nodes[action_node_option["node_ref"]] + node_uuid = game.ref_map_nodes[action_node_option["node_ref"]] action_space_cfg["options"]["node_uuids"].append(node_uuid) if "applications" in action_node_option: @@ -505,7 +371,7 @@ class PrimaiteSession: for application_option in action_node_option["applications"]: # TODO: fix inconsistency with node uuids and application uuids. The node object get added to # node_uuid, whereas here the application gets added by uuid. - application_uuid = sess.ref_map_applications[application_option["application_ref"]].uuid + application_uuid = game.ref_map_applications[application_option["application_ref"]].uuid node_application_uuids.append(application_uuid) action_space_cfg["options"]["application_uuids"].append(node_application_uuids) @@ -522,12 +388,12 @@ class PrimaiteSession: if "options" in action_config: if "target_router_ref" in action_config["options"]: _target = action_config["options"]["target_router_ref"] - action_config["options"]["target_router_uuid"] = sess.ref_map_nodes[_target] + action_config["options"]["target_router_uuid"] = game.ref_map_nodes[_target] - action_space = ActionManager.from_config(sess, action_space_cfg) + action_space = ActionManager.from_config(game, action_space_cfg) # CREATE REWARD FUNCTION - rew_function = RewardFunction.from_config(reward_function_cfg, session=sess) + rew_function = RewardFunction.from_config(reward_function_cfg, game=game) agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) @@ -541,7 +407,7 @@ class PrimaiteSession: reward_function=rew_function, agent_settings=agent_settings, ) - sess.agents.append(new_agent) + game.agents.append(new_agent) elif agent_type == "ProxyAgent": new_agent = ProxyAgent( agent_name=agent_cfg["ref"], @@ -549,8 +415,8 @@ class PrimaiteSession: observation_space=obs_space, reward_function=rew_function, ) - sess.agents.append(new_agent) - sess.rl_agents.append(new_agent) + game.agents.append(new_agent) + game.rl_agents.append(new_agent) elif agent_type == "RedDatabaseCorruptingAgent": new_agent = DataManipulationAgent( agent_name=agent_cfg["ref"], @@ -559,18 +425,10 @@ class PrimaiteSession: reward_function=rew_function, agent_settings=agent_settings, ) - sess.agents.append(new_agent) + game.agents.append(new_agent) else: print("agent type not found") - # CREATE ENVIRONMENT - sess.env = PrimaiteGymEnv(session=sess, agents=sess.rl_agents) + game._simulation_initial_state = deepcopy(game.simulation) # noqa - # CREATE POLICY - sess.policy = PolicyABC.from_config(sess.training_options, session=sess) - if agent_load_path: - sess.policy.load(Path(agent_load_path)) - - sess._simulation_initial_state = deepcopy(sess.simulation) # noqa - - return sess + return game diff --git a/src/primaite/game/policy/__init__.py b/src/primaite/game/policy/__init__.py deleted file mode 100644 index 29196112..00000000 --- a/src/primaite/game/policy/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from primaite.game.policy.sb3 import SB3Policy - -__all__ = ["SB3Policy"] diff --git a/src/primaite/main.py b/src/primaite/main.py index 1699fe51..b63227a7 100644 --- a/src/primaite/main.py +++ b/src/primaite/main.py @@ -5,8 +5,8 @@ from pathlib import Path from typing import Optional, Union from primaite import getLogger -from primaite.config.load import load -from primaite.game.session import PrimaiteSession +from primaite.config.load import example_config_path, load +from primaite.session.session import PrimaiteSession # from primaite.primaite_session import PrimaiteSession @@ -42,6 +42,6 @@ if __name__ == "__main__": args = parser.parse_args() if not args.config: - _LOGGER.error("Please provide a config file using the --config " "argument") + args.config = example_config_path() - run(session_path=args.config) + run(args.config) diff --git a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb new file mode 100644 index 00000000..d31d53cc --- /dev/null +++ b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb @@ -0,0 +1,127 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.game.game import PrimaiteGame\n", + "import yaml\n", + "from primaite.config.load import example_config_path\n", + "\n", + "from primaite.session.environment import PrimaiteRayEnv" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(example_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + "\n", + "game = PrimaiteGame.from_config(cfg)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# gym = PrimaiteRayEnv({\"game\":game})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import ray\n", + "from ray import air, tune\n", + "from ray.rllib.algorithms.ppo import PPOConfig" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ray.shutdown()\n", + "ray.init()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.session.environment import PrimaiteRayMARLEnv\n", + "\n", + "\n", + "env_config = {\"game\":game}\n", + "config = (\n", + " PPOConfig()\n", + " .environment(env=PrimaiteRayMARLEnv, env_config={\"game\":game})\n", + " .rollouts(num_rollout_workers=0)\n", + " .multi_agent(\n", + " policies={agent.agent_name for agent in game.rl_agents},\n", + " policy_mapping_fn=lambda agent_id, episode, worker, **kw: agent_id,\n", + " )\n", + " .training(train_batch_size=128)\n", + " )\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tune.Tuner(\n", + " \"PPO\",\n", + " run_config=air.RunConfig(\n", + " stop={\"training_iteration\": 128},\n", + " checkpoint_config=air.CheckpointConfig(\n", + " checkpoint_frequency=10,\n", + " ),\n", + " ),\n", + " param_space=config\n", + ").fit()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/primaite/notebooks/training_example_ray_single_agent.ipynb b/src/primaite/notebooks/training_example_ray_single_agent.ipynb new file mode 100644 index 00000000..8ee16d41 --- /dev/null +++ b/src/primaite/notebooks/training_example_ray_single_agent.ipynb @@ -0,0 +1,122 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.game.game import PrimaiteGame\n", + "import yaml\n", + "from primaite.config.load import example_config_path\n", + "\n", + "from primaite.session.environment import PrimaiteRayEnv" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(example_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + "\n", + "game = PrimaiteGame.from_config(cfg)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gym = PrimaiteRayEnv({\"game\":game})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import ray\n", + "from ray.rllib.algorithms import ppo" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ray.shutdown()\n", + "ray.init()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "env_config = {\"game\":game}\n", + "config = {\n", + " \"env\" : PrimaiteRayEnv,\n", + " \"env_config\" : env_config,\n", + " \"disable_env_checking\": True,\n", + " \"num_rollout_workers\": 0,\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "algo = ppo.PPO(config=config)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for i in range(5):\n", + " result = algo.train()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "algo.save(\"temp/deleteme\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/primaite/notebooks/training_example_sb3.ipynb b/src/primaite/notebooks/training_example_sb3.ipynb new file mode 100644 index 00000000..e5085c5e --- /dev/null +++ b/src/primaite/notebooks/training_example_sb3.ipynb @@ -0,0 +1,102 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.game.game import PrimaiteGame\n", + "from primaite.session.environment import PrimaiteGymEnv\n", + "import yaml" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.config.load import example_config_path" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(example_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + "\n", + "game = PrimaiteGame.from_config(cfg)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gym = PrimaiteGymEnv(game=game)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from stable_baselines3 import PPO" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "model = PPO('MlpPolicy', gym)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "model.learn(total_timesteps=1000)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "model.save(\"deleteme\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb new file mode 100644 index 00000000..3950ef10 --- /dev/null +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -0,0 +1,306 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/cade/repos/PrimAITE/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n", + "2023-11-26 23:25:47,985\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", + "2023-11-26 23:25:51,213\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", + "2023-11-26 23:25:51,491\tWARNING __init__.py:10 -- PG has/have been moved to `rllib_contrib` and will no longer be maintained by the RLlib team. You can still use it/them normally inside RLlib util Ray 2.8, but from Ray 2.9 on, all `rllib_contrib` algorithms will no longer be part of the core repo, and will therefore have to be installed separately with pinned dependencies for e.g. ray[rllib] and other packages! See https://github.com/ray-project/ray/tree/master/rllib_contrib#rllib-contrib for more information on the RLlib contrib effort.\n" + ] + } + ], + "source": [ + "from primaite.session.session import PrimaiteSession\n", + "from primaite.game.game import PrimaiteGame\n", + "from primaite.config.load import example_config_path\n", + "\n", + "from primaite.simulator.system.services.database.database_service import DatabaseService\n", + "\n", + "import yaml" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-11-26 23:25:51,579::ERROR::primaite.simulator.network.hardware.base::175::NIC a9:92:0a:5e:1b:e4/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-11-26 23:25:51,580::ERROR::primaite.simulator.network.hardware.base::175::NIC ef:03:23:af:3c:19/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-11-26 23:25:51,581::ERROR::primaite.simulator.network.hardware.base::175::NIC ae:cf:83:2f:94:17/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-11-26 23:25:51,582::ERROR::primaite.simulator.network.hardware.base::175::NIC 4c:b2:99:e2:4a:5d/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-11-26 23:25:51,583::ERROR::primaite.simulator.network.hardware.base::175::NIC b9:eb:f9:c2:17:2f/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-11-26 23:25:51,590::ERROR::primaite.simulator.network.hardware.base::175::NIC cb:df:ca:54:be:01/192.168.1.10 cannot be enabled as it is not connected to a Link\n", + "2023-11-26 23:25:51,595::ERROR::primaite.simulator.network.hardware.base::175::NIC 6e:32:12:da:4d:0d/192.168.1.12 cannot be enabled as it is not connected to a Link\n", + "2023-11-26 23:25:51,600::ERROR::primaite.simulator.network.hardware.base::175::NIC 58:6e:9b:a7:68:49/192.168.1.14 cannot be enabled as it is not connected to a Link\n", + "2023-11-26 23:25:51,604::ERROR::primaite.simulator.network.hardware.base::175::NIC 33:db:a6:40:dd:a3/192.168.1.16 cannot be enabled as it is not connected to a Link\n", + "2023-11-26 23:25:51,608::ERROR::primaite.simulator.network.hardware.base::175::NIC 72:aa:2b:c0:4c:5f/192.168.1.110 cannot be enabled as it is not connected to a Link\n", + "2023-11-26 23:25:51,610::ERROR::primaite.simulator.network.hardware.base::175::NIC 11:d7:0e:90:d9:a4/192.168.10.110 cannot be enabled as it is not connected to a Link\n", + "2023-11-26 23:25:51,614::ERROR::primaite.simulator.network.hardware.base::175::NIC 86:2b:a4:e5:4d:0f/192.168.10.21 cannot be enabled as it is not connected to a Link\n", + "2023-11-26 23:25:51,631::ERROR::primaite.simulator.network.hardware.base::175::NIC af:ad:8f:84:f1:db/192.168.10.22 cannot be enabled as it is not connected to a Link\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "installing DNSServer on node domain_controller\n", + "installing DatabaseClient on node web_server\n", + "installing WebServer on node web_server\n", + "installing DatabaseService on node database_server\n", + "installing FTPClient on node database_server\n", + "installing FTPServer on node backup_server\n", + "installing DNSClient on node client_1\n", + "installing DNSClient on node client_2\n" + ] + } + ], + "source": [ + "\n", + "with open(example_config_path(),'r') as cfgfile:\n", + " cfg = yaml.safe_load(cfgfile)\n", + "game = PrimaiteGame.from_config(cfg)\n", + "net = game.simulation.network\n", + "database_server = net.get_node_by_hostname('database_server')\n", + "web_server = net.get_node_by_hostname('web_server')\n", + "client_1 = net.get_node_by_hostname('client_1')\n", + "\n", + "db_service = database_server.software_manager.software[\"DatabaseService\"]\n", + "db_client = web_server.software_manager.software[\"DatabaseClient\"]\n", + "# db_client.run()\n", + "db_manipulation_bot = client_1.software_manager.software[\"DataManipulationBot\"]\n", + "db_manipulation_bot.port_scan_p_of_success=1.0\n", + "db_manipulation_bot.data_manipulation_p_of_success=1.0\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "db_client.run()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "db_service.backup_database()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "db_client.query(\"SELECT\")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "db_manipulation_bot.run()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "db_client.query(\"SELECT\")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "db_service.restore_backup()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "db_client.query(\"SELECT\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "db_manipulation_bot.run()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "client_1.ping(database_server.ethernet_port[1].ip_address)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "from pydantic import validate_call, BaseModel" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "class A(BaseModel):\n", + " x:int\n", + "\n", + " @validate_call\n", + " def increase_x(self, by:int) -> None:\n", + " self.x += 1" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "my_a = A(x=3)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "ename": "ValidationError", + "evalue": "1 validation error for increase_x\n0\n Input should be a valid integer, got a number with a fractional part [type=int_from_float, input_value=3.2, input_type=float]\n For further information visit https://errors.pydantic.dev/2.1/v/int_from_float", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValidationError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m/home/cade/repos/PrimAITE/src/primaite/notebooks/uc2_demo.ipynb Cell 15\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> 1\u001b[0m my_a\u001b[39m.\u001b[39;49mincrease_x(\u001b[39m3.2\u001b[39;49m)\n", + "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_validate_call.py:91\u001b[0m, in \u001b[0;36mValidateCallWrapper.__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 90\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__call__\u001b[39m(\u001b[39mself\u001b[39m, \u001b[39m*\u001b[39margs: Any, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: Any) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Any:\n\u001b[0;32m---> 91\u001b[0m res \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__pydantic_validator__\u001b[39m.\u001b[39;49mvalidate_python(pydantic_core\u001b[39m.\u001b[39;49mArgsKwargs(args, kwargs))\n\u001b[1;32m 92\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__return_pydantic_validator__:\n\u001b[1;32m 93\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__return_pydantic_validator__\u001b[39m.\u001b[39mvalidate_python(res)\n", + "\u001b[0;31mValidationError\u001b[0m: 1 validation error for increase_x\n0\n Input should be a valid integer, got a number with a fractional part [type=int_from_float, input_value=3.2, input_type=float]\n For further information visit https://errors.pydantic.dev/2.1/v/int_from_float" + ] + } + ], + "source": [ + "my_a.increase_x(3.2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/primaite/session/__init__.py b/src/primaite/session/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py new file mode 100644 index 00000000..db24db60 --- /dev/null +++ b/src/primaite/session/environment.py @@ -0,0 +1,162 @@ +from typing import Any, Dict, Final, Optional, SupportsFloat, Tuple + +import gymnasium +from gymnasium.core import ActType, ObsType +from ray.rllib.env.multi_agent_env import MultiAgentEnv + +from primaite.game.agent.interface import ProxyAgent +from primaite.game.game import PrimaiteGame + + +class PrimaiteGymEnv(gymnasium.Env): + """ + Thin wrapper env to provide agents with a gymnasium API. + + This is always a single agent environment since gymnasium is a single agent API. Therefore, we can make some + assumptions about the agent list always having a list of length 1. + """ + + def __init__(self, game: PrimaiteGame): + """Initialise the environment.""" + super().__init__() + self.game: "PrimaiteGame" = game + self.agent: ProxyAgent = self.game.rl_agents[0] + + def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: + """Perform a step in the environment.""" + # make ProxyAgent store the action chosen my the RL policy + self.agent.store_action(action) + # apply_agent_actions accesses the action we just stored + self.game.apply_agent_actions() + self.game.advance_timestep() + state = self.game.get_sim_state() + self.game.update_agents(state) + + next_obs = self._get_obs() + reward = self.agent.reward_function.current_reward + terminated = False + truncated = self.game.calculate_truncated() + info = {} + + return next_obs, reward, terminated, truncated, info + + def reset(self, seed: Optional[int] = None) -> Tuple[ObsType, Dict[str, Any]]: + """Reset the environment.""" + self.game.reset() + state = self.game.get_sim_state() + self.game.update_agents(state) + next_obs = self._get_obs() + info = {} + return next_obs, info + + @property + def action_space(self) -> gymnasium.Space: + """Return the action space of the environment.""" + return self.agent.action_manager.space + + @property + def observation_space(self) -> gymnasium.Space: + """Return the observation space of the environment.""" + return gymnasium.spaces.flatten_space(self.agent.observation_manager.space) + + def _get_obs(self) -> ObsType: + """Return the current observation.""" + unflat_space = self.agent.observation_manager.space + unflat_obs = self.agent.observation_manager.current_observation + return gymnasium.spaces.flatten(unflat_space, unflat_obs) + + +class PrimaiteRayEnv(gymnasium.Env): + """Ray wrapper that accepts a single `env_config` parameter in init function for compatibility with Ray.""" + + def __init__(self, env_config: Dict[str, PrimaiteGame]) -> None: + """Initialise the environment. + + :param env_config: A dictionary containing the environment configuration. It must contain a single key, `game` + which is the PrimaiteGame instance. + :type env_config: Dict[str, PrimaiteGame] + """ + self.env = PrimaiteGymEnv(game=env_config["game"]) + self.action_space = self.env.action_space + self.observation_space = self.env.observation_space + + def reset(self, *, seed: int = None, options: dict = None) -> Tuple[ObsType, Dict]: + """Reset the environment.""" + return self.env.reset(seed=seed) + + def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict]: + """Perform a step in the environment.""" + return self.env.step(action) + + +class PrimaiteRayMARLEnv(MultiAgentEnv): + """Ray Environment that inherits from MultiAgentEnv to allow training MARL systems.""" + + def __init__(self, env_config: Optional[Dict] = None) -> None: + """Initialise the environment. + + :param env_config: A dictionary containing the environment configuration. It must contain a single key, `game` + which is the PrimaiteGame instance. + :type env_config: Dict[str, PrimaiteGame] + """ + self.game: PrimaiteGame = env_config["game"] + """Reference to the primaite game""" + self.agents: Final[Dict[str, ProxyAgent]] = {agent.agent_name: agent for agent in self.game.rl_agents} + """List of all possible agents in the environment. This list should not change!""" + self._agent_ids = list(self.agents.keys()) + + self.terminateds = set() + self.truncateds = set() + self.observation_space = gymnasium.spaces.Dict( + {name: agent.observation_manager.space for name, agent in self.agents.items()} + ) + self.action_space = gymnasium.spaces.Dict( + {name: agent.action_manager.space for name, agent in self.agents.items()} + ) + super().__init__() + + def reset(self, *, seed: int = None, options: dict = None) -> Tuple[ObsType, Dict]: + """Reset the environment.""" + self.game.reset() + state = self.game.get_sim_state() + self.game.update_agents(state) + next_obs = self._get_obs() + info = {} + return next_obs, info + + def step( + self, actions: Dict[str, ActType] + ) -> Tuple[Dict[str, ObsType], Dict[str, SupportsFloat], Dict[str, bool], Dict[str, bool], Dict]: + """Perform a step in the environment. Adherent to Ray MultiAgentEnv step API. + + :param actions: Dict of actions. The key is agent identifier and the value is a gymnasium action instance. + :type actions: Dict[str, ActType] + :return: Observations, rewards, terminateds, truncateds, and info. Each one is a dictionary keyed by agent + identifier. + :rtype: Tuple[Dict[str,ObsType], Dict[str, SupportsFloat], Dict[str,bool], Dict[str,bool], Dict] + """ + # 1. Perform actions + for agent_name, action in actions.items(): + self.agents[agent_name].store_action(action) + self.game.apply_agent_actions() + + # 2. Advance timestep + self.game.advance_timestep() + + # 3. Get next observations + state = self.game.get_sim_state() + self.game.update_agents(state) + next_obs = self._get_obs() + + # 4. Get rewards + rewards = {name: agent.reward_function.current_reward for name, agent in self.agents.items()} + terminateds = {name: False for name, _ in self.agents.items()} + truncateds = {name: self.game.calculate_truncated() for name, _ in self.agents.items()} + infos = {} + terminateds["__all__"] = len(self.terminateds) == len(self.agents) + truncateds["__all__"] = self.game.calculate_truncated() + return next_obs, rewards, terminateds, truncateds, infos + + def _get_obs(self) -> Dict[str, ObsType]: + """Return the current observation.""" + return {name: agent.observation_manager.current_observation for name, agent in self.agents.items()} diff --git a/src/primaite/game/io.py b/src/primaite/session/io.py similarity index 100% rename from src/primaite/game/io.py rename to src/primaite/session/io.py diff --git a/src/primaite/session/policy/__init__.py b/src/primaite/session/policy/__init__.py new file mode 100644 index 00000000..811c7a54 --- /dev/null +++ b/src/primaite/session/policy/__init__.py @@ -0,0 +1,4 @@ +from primaite.session.policy.rllib import RaySingleAgentPolicy +from primaite.session.policy.sb3 import SB3Policy + +__all__ = ["SB3Policy", "RaySingleAgentPolicy"] diff --git a/src/primaite/game/policy/policy.py b/src/primaite/session/policy/policy.py similarity index 93% rename from src/primaite/game/policy/policy.py rename to src/primaite/session/policy/policy.py index 249c3b52..984466d1 100644 --- a/src/primaite/game/policy/policy.py +++ b/src/primaite/session/policy/policy.py @@ -4,7 +4,7 @@ from pathlib import Path from typing import Any, Dict, Type, TYPE_CHECKING if TYPE_CHECKING: - from primaite.game.session import PrimaiteSession, TrainingOptions + from primaite.session.session import PrimaiteSession, TrainingOptions class PolicyABC(ABC): @@ -80,5 +80,3 @@ class PolicyABC(ABC): PolicyType = cls._registry[config.rl_framework] return PolicyType.from_config(config=config, session=session) - - # saving checkpoints logic will be handled here, it will invoke 'save' method which is implemented by the subclass diff --git a/src/primaite/session/policy/rllib.py b/src/primaite/session/policy/rllib.py new file mode 100644 index 00000000..be181797 --- /dev/null +++ b/src/primaite/session/policy/rllib.py @@ -0,0 +1,106 @@ +from pathlib import Path +from typing import Literal, Optional, TYPE_CHECKING + +from primaite.session.environment import PrimaiteRayEnv, PrimaiteRayMARLEnv +from primaite.session.policy.policy import PolicyABC + +if TYPE_CHECKING: + from primaite.session.session import PrimaiteSession, TrainingOptions + +import ray +from ray import air, tune +from ray.rllib.algorithms import ppo +from ray.rllib.algorithms.ppo import PPOConfig + + +class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): + """Single agent RL policy using Ray RLLib.""" + + def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): + super().__init__(session=session) + + config = { + "env": PrimaiteRayEnv, + "env_config": {"game": session.game}, + "disable_env_checking": True, + "num_rollout_workers": 0, + } + + ray.shutdown() + ray.init() + + self._algo = ppo.PPO(config=config) + + def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: + """Train the agent.""" + for ep in range(n_episodes): + self._algo.train() + + def eval(self, n_episodes: int, deterministic: bool) -> None: + """Evaluate the agent.""" + for ep in range(n_episodes): + obs, info = self.session.env.reset() + for step in range(self.session.game.options.max_episode_length): + action = self._algo.compute_single_action(observation=obs, explore=False) + obs, rew, term, trunc, info = self.session.env.step(action) + + def save(self, save_path: Path) -> None: + """Save the policy to a file.""" + self._algo.save(save_path) + + def load(self, model_path: Path) -> None: + """Load policy parameters from a file.""" + raise NotImplementedError + + @classmethod + def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "RaySingleAgentPolicy": + """Create a policy from a config.""" + return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) + + +class RayMultiAgentPolicy(PolicyABC, identifier="RLLIB_multi_agent"): + """Mutli agent RL policy using Ray RLLib.""" + + def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO"], seed: Optional[int] = None): + """Initialise multi agent policy wrapper.""" + super().__init__(session=session) + + self.config = ( + PPOConfig() + .environment(env=PrimaiteRayMARLEnv, env_config={"game": session.game}) + .rollouts(num_rollout_workers=0) + .multi_agent( + policies={agent.agent_name for agent in session.game.rl_agents}, + policy_mapping_fn=lambda agent_id, episode, worker, **kw: agent_id, + ) + .training(train_batch_size=128) + ) + + def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: + """Train the agent.""" + checkpoint_freq = self.session.io_manager.settings.checkpoint_interval + tune.Tuner( + "PPO", + run_config=air.RunConfig( + stop={"training_iteration": n_episodes * timesteps_per_episode}, + checkpoint_config=air.CheckpointConfig(checkpoint_frequency=checkpoint_freq), + ), + param_space=self.config, + ).fit() + + def load(self, model_path: Path) -> None: + """Load policy parameters from a file.""" + return NotImplemented + + def eval(self, n_episodes: int, deterministic: bool) -> None: + """Evaluate trained policy.""" + return NotImplemented + + def save(self, save_path: Path) -> None: + """Save policy parameters to a file.""" + return NotImplemented + + @classmethod + def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "RayMultiAgentPolicy": + """Create policy from config.""" + return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) diff --git a/src/primaite/game/policy/sb3.py b/src/primaite/session/policy/sb3.py similarity index 96% rename from src/primaite/game/policy/sb3.py rename to src/primaite/session/policy/sb3.py index a4870054..051e2770 100644 --- a/src/primaite/game/policy/sb3.py +++ b/src/primaite/session/policy/sb3.py @@ -8,10 +8,10 @@ from stable_baselines3.common.callbacks import CheckpointCallback from stable_baselines3.common.evaluation import evaluate_policy from stable_baselines3.ppo import MlpPolicy as PPO_MLP -from primaite.game.policy.policy import PolicyABC +from primaite.session.policy.policy import PolicyABC if TYPE_CHECKING: - from primaite.game.session import PrimaiteSession, TrainingOptions + from primaite.session.session import PrimaiteSession, TrainingOptions class SB3Policy(PolicyABC, identifier="SB3"): diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py new file mode 100644 index 00000000..80b63ba7 --- /dev/null +++ b/src/primaite/session/session.py @@ -0,0 +1,113 @@ +from enum import Enum +from pathlib import Path +from typing import Dict, List, Literal, Optional, Union + +from pydantic import BaseModel, ConfigDict + +from primaite.game.game import PrimaiteGame +from primaite.session.environment import PrimaiteGymEnv, PrimaiteRayEnv, PrimaiteRayMARLEnv +from primaite.session.io import SessionIO, SessionIOSettings + +# from primaite.game.game import PrimaiteGame +from primaite.session.policy.policy import PolicyABC + + +class TrainingOptions(BaseModel): + """Options for training the RL agent.""" + + model_config = ConfigDict(extra="forbid") + + rl_framework: Literal["SB3", "RLLIB_single_agent", "RLLIB_multi_agent"] + rl_algorithm: Literal["PPO", "A2C"] + n_learn_episodes: int + n_eval_episodes: Optional[int] = None + max_steps_per_episode: int + # checkpoint_freq: Optional[int] = None + deterministic_eval: bool + seed: Optional[int] + n_agents: int + agent_references: List[str] + + +class SessionMode(Enum): + """Helper to keep track of the current session mode.""" + + TRAIN = "train" + EVAL = "eval" + MANUAL = "manual" + + +class PrimaiteSession: + """The main entrypoint for PrimAITE sessions, this manages a simulation, policy training, and environments.""" + + def __init__(self, game: PrimaiteGame): + """Initialise PrimaiteSession object.""" + self.training_options: TrainingOptions + """Options specific to agent training.""" + + self.mode: SessionMode = SessionMode.MANUAL + """Current session mode.""" + + self.env: Union[PrimaiteGymEnv, PrimaiteRayEnv, PrimaiteRayMARLEnv] + """The environment that the RL algorithm can consume.""" + + self.policy: PolicyABC + """The reinforcement learning policy.""" + + self.io_manager = SessionIO() + """IO manager for the session.""" + + self.game: PrimaiteGame = game + """Primaite Game object for managing main simulation loop and agents.""" + + def start_session(self) -> None: + """Commence the training/eval session.""" + self.mode = SessionMode.TRAIN + n_learn_episodes = self.training_options.n_learn_episodes + n_eval_episodes = self.training_options.n_eval_episodes + max_steps_per_episode = self.training_options.max_steps_per_episode + + deterministic_eval = self.training_options.deterministic_eval + self.policy.learn( + n_episodes=n_learn_episodes, + timesteps_per_episode=max_steps_per_episode, + ) + self.save_models() + + self.mode = SessionMode.EVAL + if n_eval_episodes > 0: + self.policy.eval(n_episodes=n_eval_episodes, deterministic=deterministic_eval) + + self.mode = SessionMode.MANUAL + + def save_models(self) -> None: + """Save the RL models.""" + save_path = self.io_manager.generate_model_save_path("temp_model_name") + self.policy.save(save_path) + + @classmethod + def from_config(cls, cfg: Dict, agent_load_path: Optional[str] = None) -> "PrimaiteSession": + """Create a PrimaiteSession object from a config dictionary.""" + game = PrimaiteGame.from_config(cfg) + + sess = cls(game=game) + + sess.training_options = TrainingOptions(**cfg["training_config"]) + + # READ IO SETTINGS (this sets the global session path as well) # TODO: GLOBAL SIDE EFFECTS... + io_settings = cfg.get("io_settings", {}) + sess.io_manager.settings = SessionIOSettings(**io_settings) + + # CREATE ENVIRONMENT + if sess.training_options.rl_framework == "RLLIB_single_agent": + sess.env = PrimaiteRayEnv(env_config={"game": game}) + elif sess.training_options.rl_framework == "RLLIB_multi_agent": + sess.env = PrimaiteRayMARLEnv(env_config={"game": game}) + elif sess.training_options.rl_framework == "SB3": + sess.env = PrimaiteGymEnv(game=game) + + sess.policy = PolicyABC.from_config(sess.training_options, session=sess) + if agent_load_path: + sess.policy.load(Path(agent_load_path)) + + return sess diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 4d8e4669..9070f246 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -2,20 +2,12 @@ training_config: rl_framework: SB3 rl_algorithm: PPO se3ed: 333 # Purposeful typo to check that error is raised with bad configuration. - n_learn_episodes: 25 + n_learn_steps: 2560 n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: - - defender - -io_settings: - save_checkpoints: true - checkpoint_interval: 5 -game_config: + +game: ports: - ARP - DNS @@ -26,522 +18,499 @@ game_config: - TCP - UDP - agents: - - ref: client_1_green_user - team: GREEN - type: GreenWebBrowsingAgent - observation_space: - type: UC2GreenObservation - action_space: - action_list: - - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 - options: - nodes: - - node_ref: client_2 - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + reward_function: + reward_components: + - type: DUMMY - reward_function: - reward_components: - - type: DUMMY + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 - agent_settings: - start_settings: - start_step: 5 - frequency: 4 - variance: 3 + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent - - ref: client_1_data_manipulation_red_bot - team: RED - type: RedDatabaseCorruptingAgent + observation_space: + type: UC2RedObservation + options: + nodes: {} - observation_space: - type: UC2RedObservation - options: - nodes: + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + - type: NODE_FILE_DELETE + - type: NODE_FILE_CORRUPT + - type: NODE_OS_SCAN + options: + nodes: + - node_ref: client_1 + applications: + - application_ref: data_manipulation_bot + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 + + - ref: defender + team: BLUE + type: ProxyAgent + + observation_space: + type: UC2BlueObservation + options: + num_services_per_node: 1 + num_folders_per_node: 1 + num_files_per_folder: 1 + num_nics_per_node: 2 + nodes: + - node_ref: domain_controller + services: + - service_ref: domain_controller_dns_server + - node_ref: web_server + services: + - service_ref: web_server_database_client + - node_ref: database_server + services: + - service_ref: database_service + folders: + - folder_name: database + files: + - file_name: database.db + - node_ref: backup_server + # services: + # - service_ref: backup_service + - node_ref: security_suite + - node_ref: client_1 + - node_ref: client_2 + links: + - link_ref: router_1___switch_1 + - link_ref: router_1___switch_2 + - link_ref: switch_1___domain_controller + - link_ref: switch_1___web_server + - link_ref: switch_1___database_server + - link_ref: switch_1___backup_server + - link_ref: switch_1___security_suite + - link_ref: switch_2___client_1 + - link_ref: switch_2___client_2 + - link_ref: switch_2___security_suite + acl: + options: + max_acl_rules: 10 + router_node_ref: router_1 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 - node_ref: client_1 - observations: - - logon_status - - operating_status - applications: - - application_ref: data_manipulation_bot - observations: - operating_status - health_status - folders: {} + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 + ics: null - action_space: - action_list: - - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com - options: - nodes: - - node_ref: client_2 - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 - reward_function: - reward_components: - - type: DUMMY + reward_function: + reward_components: + - type: DUMMY - agent_settings: - start_settings: - start_step: 5 - frequency: 4 - variance: 3 + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 - - ref: client_1_data_manipulation_red_bot - team: RED - type: RedDatabaseCorruptingAgent + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: + observation_space: + type: UC2RedObservation + options: + nodes: {} + + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + - type: NODE_FILE_DELETE + - type: NODE_FILE_CORRUPT + - type: NODE_OS_SCAN + options: + nodes: + - node_ref: client_1 + applications: + - application_ref: data_manipulation_bot + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + reward_function: + reward_components: + - type: DUMMY + + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 + + - ref: defender + team: BLUE + type: ProxyAgent + + observation_space: + type: UC2BlueObservation + options: + num_services_per_node: 1 + num_folders_per_node: 1 + num_files_per_folder: 1 + num_nics_per_node: 2 + nodes: + - node_ref: domain_controller + services: + - service_ref: domain_controller_dns_server + - node_ref: web_server + services: + - service_ref: web_server_database_client + - node_ref: database_server + services: + - service_ref: database_service + folders: + - folder_name: database + files: + - file_name: database.db + - node_ref: backup_server + # services: + # - service_ref: backup_service + - node_ref: security_suite + - node_ref: client_1 + - node_ref: client_2 + links: + - link_ref: router_1___switch_1 + - link_ref: router_1___switch_2 + - link_ref: switch_1___domain_controller + - link_ref: switch_1___web_server + - link_ref: switch_1___database_server + - link_ref: switch_1___backup_server + - link_ref: switch_1___security_suite + - link_ref: switch_2___client_1 + - link_ref: switch_2___client_2 + - link_ref: switch_2___security_suite + acl: + options: + max_acl_rules: 10 + router_node_ref: router_1 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 - node_ref: client_1 - observations: - - logon_status - - operating_status - applications: - - application_ref: data_manipulation_bot - observations: - operating_status - health_status - folders: {} + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 + ics: null - action_space: - action_list: - - type: DONOTHING - # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com + + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 + + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: + type: UC2RedObservation + options: + nodes: {} + + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + - type: NODE_FILE_DELETE + - type: NODE_FILE_CORRUPT + - type: NODE_OS_SCAN + options: + nodes: + - node_ref: client_1 + applications: + - application_ref: data_manipulation_bot + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 + + - ref: defender1 + team: BLUE + type: ProxyAgent + + observation_space: + type: UC2BlueObservation + options: + num_services_per_node: 1 + num_folders_per_node: 1 + num_files_per_folder: 1 + num_nics_per_node: 2 + nodes: + - node_ref: domain_controller + services: + - service_ref: domain_controller_dns_server + - node_ref: web_server + services: + - service_ref: web_server_database_client + - node_ref: database_server + services: + - service_ref: database_service + folders: + - folder_name: database + files: + - file_name: database.db + - node_ref: backup_server + # services: + # - service_ref: backup_service + - node_ref: security_suite + - node_ref: client_1 + - node_ref: client_2 + links: + - link_ref: router_1___switch_1 + - link_ref: router_1___switch_2 + - link_ref: switch_1___domain_controller + - link_ref: switch_1___web_server + - link_ref: switch_1___database_server + - link_ref: switch_1___backup_server + - link_ref: switch_1___security_suite + - link_ref: switch_2___client_1 + - link_ref: switch_2___client_2 + - link_ref: switch_2___security_suite + acl: + options: + max_acl_rules: 10 + router_node_ref: router_1 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 + - node_ref: client_1 + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 + ics: null + + action_space: + action_list: + - type: DONOTHING + - type: NODE_SERVICE_SCAN + - type: NODE_SERVICE_STOP + - type: NODE_SERVICE_START + - type: NODE_SERVICE_PAUSE + - type: NODE_SERVICE_RESUME + - type: NODE_SERVICE_RESTART + - type: NODE_SERVICE_DISABLE + - type: NODE_SERVICE_ENABLE + - type: NODE_FILE_SCAN + - type: NODE_FILE_CHECKHASH + - type: NODE_FILE_DELETE + - type: NODE_FILE_REPAIR + - type: NODE_FILE_RESTORE + - type: NODE_FOLDER_SCAN + - type: NODE_FOLDER_CHECKHASH + - type: NODE_FOLDER_REPAIR + - type: NODE_FOLDER_RESTORE + - type: NODE_OS_SCAN + - type: NODE_SHUTDOWN + - type: NODE_STARTUP + - type: NODE_RESET + - type: NETWORK_ACL_ADDRULE + options: + target_router_ref: router_1 + - type: NETWORK_ACL_REMOVERULE + options: + target_router_ref: router_1 + - type: NETWORK_NIC_ENABLE + - type: NETWORK_NIC_DISABLE + + action_map: + 0: + action: DONOTHING + options: {} + # scan webapp service + 1: + action: NODE_SERVICE_SCAN + options: + node_id: 2 + service_id: 1 + # stop webapp service + 2: + action: NODE_SERVICE_STOP + options: + node_id: 2 + service_id: 1 + # start webapp service + 3: + action: "NODE_SERVICE_START" + options: + node_id: 2 + service_id: 1 + 4: + action: "NODE_SERVICE_PAUSE" + options: + node_id: 2 + service_id: 1 + 5: + action: "NODE_SERVICE_RESUME" + options: + node_id: 2 + service_id: 1 + 6: + action: "NODE_SERVICE_RESTART" + options: + node_id: 2 + service_id: 1 + 7: + action: "NODE_SERVICE_DISABLE" + options: + node_id: 2 + service_id: 1 + 8: + action: "NODE_SERVICE_ENABLE" + options: + node_id: 2 + service_id: 1 + 9: + action: "NODE_FILE_SCAN" + options: + node_id: 3 + folder_id: 1 + file_id: 1 + 10: + action: "NODE_FILE_CHECKHASH" + options: + node_id: 3 + folder_id: 1 + file_id: 1 + 11: + action: "NODE_FILE_DELETE" + options: + node_id: 3 + folder_id: 1 + file_id: 1 + 12: + action: "NODE_FILE_REPAIR" + options: + node_id: 3 + folder_id: 1 + file_id: 1 + 13: + action: "NODE_FILE_RESTORE" + options: + node_id: 3 + folder_id: 1 + file_id: 1 + 14: + action: "NODE_FOLDER_SCAN" + options: + node_id: 3 + folder_id: 1 + 15: + action: "NODE_FOLDER_CHECKHASH" + options: + node_id: 3 + folder_id: 1 + 16: + action: "NODE_FOLDER_REPAIR" + options: + node_id: 3 + folder_id: 1 + 17: + action: "NODE_FOLDER_RESTORE" + options: + node_id: 3 + folder_id: 1 + 18: + action: "NODE_OS_SCAN" + options: + node_id: 3 + 19: + action: "NODE_SHUTDOWN" + options: + node_id: 6 + 20: + action: "NODE_STARTUP" + options: + node_id: 6 + 21: + action: "NODE_RESET" + options: + node_id: 6 + 22: + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 7 + dest_ip_id: 1 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 + 23: + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 8 + dest_ip_id: 1 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 + 24: + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 7 + dest_ip_id: 3 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 25: + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 8 + dest_ip_id: 3 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 26: + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 7 + dest_ip_id: 4 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 27: + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 8 + dest_ip_id: 4 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 28: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 0 + 29: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 1 + 30: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 2 + 31: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 3 + 32: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 4 + 33: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 5 + 34: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 6 + 35: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 7 + 36: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 8 + 37: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 9 + 38: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 1 + nic_id: 1 + 39: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 1 + nic_id: 1 + 40: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 2 + nic_id: 1 + 41: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 2 + nic_id: 1 + 42: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 3 + nic_id: 1 + 43: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 3 + nic_id: 1 + 44: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 4 + nic_id: 1 + 45: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 4 + nic_id: 1 + 46: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 5 + nic_id: 1 + 47: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 5 + nic_id: 1 + 48: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 5 + nic_id: 2 + 49: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 5 + nic_id: 2 + 50: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 6 + nic_id: 1 + 51: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 6 + nic_id: 1 + 52: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 7 + nic_id: 1 + 53: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 7 + nic_id: 1 + + + options: + nodes: + - node_ref: router_1 + - node_ref: switch_1 + - node_ref: switch_2 + - node_ref: domain_controller + - node_ref: web_server + - node_ref: database_server + - node_ref: backup_server + - node_ref: security_suite + - node_ref: client_1 + - node_ref: client_2 + max_folders_per_node: 2 + max_files_per_folder: 2 + max_services_per_node: 2 + max_nics_per_node: 8 + max_acl_rules: 10 + + reward_function: + reward_components: + - type: DATABASE_FILE_INTEGRITY + weight: 0.5 + options: + node_ref: database_server + folder_name: database + file_name: database.db + + + - type: WEB_SERVER_404_PENALTY + weight: 0.5 + options: + node_ref: web_server + service_ref: web_server_web_service + + + agent_settings: + # ... + + - ref: defender2 + team: BLUE + type: ProxyAgent + + observation_space: + type: UC2BlueObservation + options: + num_services_per_node: 1 + num_folders_per_node: 1 + num_files_per_folder: 1 + num_nics_per_node: 2 + nodes: + - node_ref: domain_controller + services: + - service_ref: domain_controller_dns_server + - node_ref: web_server + services: + - service_ref: web_server_database_client + - node_ref: database_server + services: + - service_ref: database_service + folders: + - folder_name: database + files: + - file_name: database.db + - node_ref: backup_server + # services: + # - service_ref: backup_service + - node_ref: security_suite + - node_ref: client_1 + - node_ref: client_2 + links: + - link_ref: router_1___switch_1 + - link_ref: router_1___switch_2 + - link_ref: switch_1___domain_controller + - link_ref: switch_1___web_server + - link_ref: switch_1___database_server + - link_ref: switch_1___backup_server + - link_ref: switch_1___security_suite + - link_ref: switch_2___client_1 + - link_ref: switch_2___client_2 + - link_ref: switch_2___security_suite + acl: + options: + max_acl_rules: 10 + router_node_ref: router_1 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 + - node_ref: client_1 + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 + ics: null + + action_space: + action_list: + - type: DONOTHING + - type: NODE_SERVICE_SCAN + - type: NODE_SERVICE_STOP + - type: NODE_SERVICE_START + - type: NODE_SERVICE_PAUSE + - type: NODE_SERVICE_RESUME + - type: NODE_SERVICE_RESTART + - type: NODE_SERVICE_DISABLE + - type: NODE_SERVICE_ENABLE + - type: NODE_FILE_SCAN + - type: NODE_FILE_CHECKHASH + - type: NODE_FILE_DELETE + - type: NODE_FILE_REPAIR + - type: NODE_FILE_RESTORE + - type: NODE_FOLDER_SCAN + - type: NODE_FOLDER_CHECKHASH + - type: NODE_FOLDER_REPAIR + - type: NODE_FOLDER_RESTORE + - type: NODE_OS_SCAN + - type: NODE_SHUTDOWN + - type: NODE_STARTUP + - type: NODE_RESET + - type: NETWORK_ACL_ADDRULE + options: + target_router_ref: router_1 + - type: NETWORK_ACL_REMOVERULE + options: + target_router_ref: router_1 + - type: NETWORK_NIC_ENABLE + - type: NETWORK_NIC_DISABLE + + action_map: + 0: + action: DONOTHING + options: {} + # scan webapp service + 1: + action: NODE_SERVICE_SCAN + options: + node_id: 2 + service_id: 1 + # stop webapp service + 2: + action: NODE_SERVICE_STOP + options: + node_id: 2 + service_id: 1 + # start webapp service + 3: + action: "NODE_SERVICE_START" + options: + node_id: 2 + service_id: 1 + 4: + action: "NODE_SERVICE_PAUSE" + options: + node_id: 2 + service_id: 1 + 5: + action: "NODE_SERVICE_RESUME" + options: + node_id: 2 + service_id: 1 + 6: + action: "NODE_SERVICE_RESTART" + options: + node_id: 2 + service_id: 1 + 7: + action: "NODE_SERVICE_DISABLE" + options: + node_id: 2 + service_id: 1 + 8: + action: "NODE_SERVICE_ENABLE" + options: + node_id: 2 + service_id: 1 + 9: + action: "NODE_FILE_SCAN" + options: + node_id: 3 + folder_id: 1 + file_id: 1 + 10: + action: "NODE_FILE_CHECKHASH" + options: + node_id: 3 + folder_id: 1 + file_id: 1 + 11: + action: "NODE_FILE_DELETE" + options: + node_id: 3 + folder_id: 1 + file_id: 1 + 12: + action: "NODE_FILE_REPAIR" + options: + node_id: 3 + folder_id: 1 + file_id: 1 + 13: + action: "NODE_FILE_RESTORE" + options: + node_id: 3 + folder_id: 1 + file_id: 1 + 14: + action: "NODE_FOLDER_SCAN" + options: + node_id: 3 + folder_id: 1 + 15: + action: "NODE_FOLDER_CHECKHASH" + options: + node_id: 3 + folder_id: 1 + 16: + action: "NODE_FOLDER_REPAIR" + options: + node_id: 3 + folder_id: 1 + 17: + action: "NODE_FOLDER_RESTORE" + options: + node_id: 3 + folder_id: 1 + 18: + action: "NODE_OS_SCAN" + options: + node_id: 3 + 19: + action: "NODE_SHUTDOWN" + options: + node_id: 6 + 20: + action: "NODE_STARTUP" + options: + node_id: 6 + 21: + action: "NODE_RESET" + options: + node_id: 6 + 22: + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 7 + dest_ip_id: 1 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 + 23: + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 8 + dest_ip_id: 1 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 + 24: + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 7 + dest_ip_id: 3 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 25: + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 8 + dest_ip_id: 3 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 26: + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 7 + dest_ip_id: 4 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 27: + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 8 + dest_ip_id: 4 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 28: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 0 + 29: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 1 + 30: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 2 + 31: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 3 + 32: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 4 + 33: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 5 + 34: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 6 + 35: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 7 + 36: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 8 + 37: + action: "NETWORK_ACL_REMOVERULE" + options: + position: 9 + 38: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 1 + nic_id: 1 + 39: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 1 + nic_id: 1 + 40: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 2 + nic_id: 1 + 41: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 2 + nic_id: 1 + 42: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 3 + nic_id: 1 + 43: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 3 + nic_id: 1 + 44: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 4 + nic_id: 1 + 45: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 4 + nic_id: 1 + 46: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 5 + nic_id: 1 + 47: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 5 + nic_id: 1 + 48: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 5 + nic_id: 2 + 49: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 5 + nic_id: 2 + 50: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 6 + nic_id: 1 + 51: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 6 + nic_id: 1 + 52: + action: "NETWORK_NIC_DISABLE" + options: + node_id: 7 + nic_id: 1 + 53: + action: "NETWORK_NIC_ENABLE" + options: + node_id: 7 + nic_id: 1 + + + options: + nodes: + - node_ref: router_1 + - node_ref: switch_1 + - node_ref: switch_2 + - node_ref: domain_controller + - node_ref: web_server + - node_ref: database_server + - node_ref: backup_server + - node_ref: security_suite + - node_ref: client_1 + - node_ref: client_2 + max_folders_per_node: 2 + max_files_per_folder: 2 + max_services_per_node: 2 + max_nics_per_node: 8 + max_acl_rules: 10 + + reward_function: + reward_components: + - type: DATABASE_FILE_INTEGRITY + weight: 0.5 + options: + node_ref: database_server + folder_name: database + file_name: database.db + + + - type: WEB_SERVER_404_PENALTY + weight: 0.5 + options: + node_ref: web_server + service_ref: web_server_web_service + + + agent_settings: + # ... + + + + + +simulation: + network: + nodes: + + - ref: router_1 + type: router + hostname: router_1 + num_ports: 5 + ports: + 1: + ip_address: 192.168.1.1 + subnet_mask: 255.255.255.0 + 2: + ip_address: 192.168.1.1 + subnet_mask: 255.255.255.0 + acl: + 0: + action: PERMIT + src_port: POSTGRES_SERVER + dst_port: POSTGRES_SERVER + 1: + action: PERMIT + src_port: DNS + dst_port: DNS + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + + - ref: switch_1 + type: switch + hostname: switch_1 + num_ports: 8 + + - ref: switch_2 + type: switch + hostname: switch_2 + num_ports: 8 + + - ref: domain_controller + type: server + hostname: domain_controller + ip_address: 192.168.1.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + services: + - ref: domain_controller_dns_server + type: DNSServer + options: + domain_mapping: + arcd.com: 192.168.1.12 # web server + + - ref: web_server + type: server + hostname: web_server + ip_address: 192.168.1.12 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.10 + dns_server: 192.168.1.10 + services: + - ref: web_server_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 + - ref: web_server_web_service + type: WebServer + + + - ref: database_server + type: server + hostname: database_server + ip_address: 192.168.1.14 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - ref: database_service + type: DatabaseService + + - ref: backup_server + type: server + hostname: backup_server + ip_address: 192.168.1.16 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - ref: backup_service + type: DatabaseBackup + + - ref: security_suite + type: server + hostname: security_suite + ip_address: 192.168.1.110 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + nics: + 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot + ip_address: 192.168.10.110 + subnet_mask: 255.255.255.0 + + - ref: client_1 + type: computer + hostname: client_1 + ip_address: 192.168.10.21 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + applications: + - ref: data_manipulation_bot + type: DataManipulationBot + options: + port_scan_p_of_success: 0.1 + data_manipulation_p_of_success: 0.1 + payload: "DELETE" + server_ip: 192.168.1.14 + services: + - ref: client_1_dns_client + type: DNSClient + + - ref: client_2 + type: computer + hostname: client_2 + ip_address: 192.168.10.22 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + applications: + - ref: client_2_web_browser + type: WebBrowser + services: + - ref: client_2_dns_client + type: DNSClient + + links: + - ref: router_1___switch_1 + endpoint_a_ref: router_1 + endpoint_a_port: 1 + endpoint_b_ref: switch_1 + endpoint_b_port: 8 + - ref: router_1___switch_2 + endpoint_a_ref: router_1 + endpoint_a_port: 2 + endpoint_b_ref: switch_2 + endpoint_b_port: 8 + - ref: switch_1___domain_controller + endpoint_a_ref: switch_1 + endpoint_a_port: 1 + endpoint_b_ref: domain_controller + endpoint_b_port: 1 + - ref: switch_1___web_server + endpoint_a_ref: switch_1 + endpoint_a_port: 2 + endpoint_b_ref: web_server + endpoint_b_port: 1 + - ref: switch_1___database_server + endpoint_a_ref: switch_1 + endpoint_a_port: 3 + endpoint_b_ref: database_server + endpoint_b_port: 1 + - ref: switch_1___backup_server + endpoint_a_ref: switch_1 + endpoint_a_port: 4 + endpoint_b_ref: backup_server + endpoint_b_port: 1 + - ref: switch_1___security_suite + endpoint_a_ref: switch_1 + endpoint_a_port: 7 + endpoint_b_ref: security_suite + endpoint_b_port: 1 + - ref: switch_2___client_1 + endpoint_a_ref: switch_2 + endpoint_a_port: 1 + endpoint_b_ref: client_1 + endpoint_b_port: 1 + - ref: switch_2___client_2 + endpoint_a_ref: switch_2 + endpoint_a_port: 2 + endpoint_b_ref: client_2 + endpoint_b_port: 1 + - ref: switch_2___security_suite + endpoint_a_ref: switch_2 + endpoint_a_port: 7 + endpoint_b_ref: security_suite + endpoint_b_port: 2 diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 64be5488..d7e94cb6 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -15,7 +15,7 @@ io_settings: checkpoint_interval: 5 -game_config: +game: ports: - ARP - DNS @@ -26,522 +26,507 @@ game_config: - TCP - UDP - agents: - - ref: client_1_green_user - team: GREEN - type: GreenWebBrowsingAgent - observation_space: - type: UC2GreenObservation - action_space: - action_list: - - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com - options: - nodes: - - node_ref: client_2 - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 - reward_function: - reward_components: - - type: DUMMY + reward_function: + reward_components: + - type: DUMMY - agent_settings: - start_settings: - start_step: 5 - frequency: 4 - variance: 3 + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 - - ref: client_1_data_manipulation_red_bot - team: RED - type: RedDatabaseCorruptingAgent + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: + observation_space: + type: UC2RedObservation + options: + nodes: {} + + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + - type: NODE_FILE_DELETE + - type: NODE_FILE_CORRUPT + - type: NODE_OS_SCAN + options: + nodes: + - node_ref: client_1 + applications: + - application_ref: data_manipulation_bot + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 + + - ref: defender + team: BLUE + type: ProxyAgent + + observation_space: + type: UC2BlueObservation + options: + num_services_per_node: 1 + num_folders_per_node: 1 + num_files_per_folder: 1 + num_nics_per_node: 2 + nodes: + - node_ref: domain_controller + services: + - service_ref: domain_controller_dns_server + - node_ref: web_server + services: + - service_ref: web_server_database_client + - node_ref: database_server + services: + - service_ref: database_service + folders: + - folder_name: database + files: + - file_name: database.db + - node_ref: backup_server + # services: + # - service_ref: backup_service + - node_ref: security_suite + - node_ref: client_1 + - node_ref: client_2 + links: + - link_ref: router_1___switch_1 + - link_ref: router_1___switch_2 + - link_ref: switch_1___domain_controller + - link_ref: switch_1___web_server + - link_ref: switch_1___database_server + - link_ref: switch_1___backup_server + - link_ref: switch_1___security_suite + - link_ref: switch_2___client_1 + - link_ref: switch_2___client_2 + - link_ref: switch_2___security_suite + acl: + options: + max_acl_rules: 10 + router_node_ref: router_1 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 - node_ref: client_1 - observations: - - logon_status - - operating_status - applications: - - application_ref: data_manipulation_bot - observations: - operating_status - health_status - folders: {} + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 + ics: null - action_space: - action_list: - - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com +agents: + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + # + # - type: NODE_LOGON + # - type: NODE_LOGOFF + # - type: NODE_APPLICATION_EXECUTE + # options: + # execution_definition: + # target_address: arcd.com - options: - nodes: - - node_ref: client_2 - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + options: + nodes: + - node_ref: client_2 + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_nics_per_node: 2 + max_acl_rules: 10 - reward_function: - reward_components: - - type: DUMMY + reward_function: + reward_components: + - type: DUMMY - agent_settings: - start_settings: - start_step: 5 - frequency: 4 - variance: 3 + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 - - ref: client_1_data_manipulation_red_bot - team: RED - type: RedDatabaseCorruptingAgent + - ref: client_1_data_manipulation_red_bot + team: RED + type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: + observation_space: + type: UC2RedObservation + options: + nodes: {} + + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + - type: NODE_FILE_DELETE + - type: NODE_FILE_CORRUPT + - type: NODE_OS_SCAN + options: + nodes: + - node_ref: client_1 + applications: + - application_ref: data_manipulation_bot + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 + + - ref: defender + team: BLUE + type: ProxyAgent + + observation_space: + type: UC2BlueObservation + options: + num_services_per_node: 1 + num_folders_per_node: 1 + num_files_per_folder: 1 + num_nics_per_node: 2 + nodes: + - node_ref: domain_controller + services: + - service_ref: domain_controller_dns_server + - node_ref: web_server + services: + - service_ref: web_server_database_client + - node_ref: database_server + services: + - service_ref: database_service + folders: + - folder_name: database + files: + - file_name: database.db + - node_ref: backup_server + # services: + # - service_ref: backup_service + - node_ref: security_suite + - node_ref: client_1 + - node_ref: client_2 + links: + - link_ref: router_1___switch_1 + - link_ref: router_1___switch_2 + - link_ref: switch_1___domain_controller + - link_ref: switch_1___web_server + - link_ref: switch_1___database_server + - link_ref: switch_1___backup_server + - link_ref: switch_1___security_suite + - link_ref: switch_2___client_1 + - link_ref: switch_2___client_2 + - link_ref: switch_2___security_suite + acl: + options: + max_acl_rules: 10 + router_node_ref: router_1 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 - node_ref: client_1 - observations: - - logon_status - - operating_status - applications: - - application_ref: data_manipulation_bot - observations: - operating_status - health_status - folders: {} + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 + ics: null - action_space: - action_list: - - type: DONOTHING - # Date: Mon, 27 Nov 2023 11:38:03 +0000 Subject: [PATCH 387/980] #2064: documentation EVERYWHERE --- CHANGELOG.md | 1 + .../network/base_hardware.rst | 62 ++++++++++++++++++- .../system/data_manipulation_bot.rst | 7 ++- .../system/ftp_client_server.rst | 17 +++-- .../simulation_components/system/software.rst | 39 ++++++++++-- .../simulator/network/hardware/base.py | 2 + .../system/services/dns/dns_client.py | 4 +- .../system/test_application_on_node.py | 11 ++++ .../system/test_service_on_node.py | 11 ++++ 9 files changed, 141 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3af5c14c..068c2332 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ SessionManager. - DNS Services: `DNSClient` and `DNSServer` - FTP Services: `FTPClient` and `FTPServer` - HTTP Services: `WebBrowser` to simulate a web client and `WebServer` +- Fixed an issue where the services were still able to run even though the node the service is installed on is turned off ### Removed - Removed legacy simulation modules: `acl`, `common`, `environment`, `links`, `nodes`, `pol` diff --git a/docs/source/simulation_components/network/base_hardware.rst b/docs/source/simulation_components/network/base_hardware.rst index af4ec26c..ae922105 100644 --- a/docs/source/simulation_components/network/base_hardware.rst +++ b/docs/source/simulation_components/network/base_hardware.rst @@ -109,6 +109,67 @@ e.g. instant_start_node = Node(hostname="client", start_up_duration=0, shut_down_duration=0) instant_start_node.power_on() # node will still need to be powered on +.. _Node Start up and Shut down: + +--------------------------- +Node Start up and Shut down +--------------------------- + +Nodes are powered on and off over multiple timesteps. By default, the node ``start_up_duration`` and ``shut_down_duration`` is 3 timesteps. + +Example code where a node is turned on: + +.. code-block:: python + + from primaite.simulator.network.hardware.base import Node + from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState + + node = Node(hostname="pc_a") + + assert node.operating_state is NodeOperatingState.OFF # By default, node is instantiated in an OFF state + + node.power_on() # power on the node + + assert node.operating_state is NodeOperatingState.BOOTING # node is booting up + + for i in range(node.start_up_duration + 1): + # apply timestep until the node start up duration + node.apply_timestep(timestep=i) + + assert node.operating_state is NodeOperatingState.ON # node is in ON state + + +If the node needs to be instantiated in an on state: + + +.. code-block:: python + + from primaite.simulator.network.hardware.base import Node + from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState + + node = Node(hostname="pc_a", operating_state=NodeOperatingState.ON) + + assert node.operating_state is NodeOperatingState.ON # node is in ON state + +Setting ``start_up_duration`` and/or ``shut_down_duration`` to ``0`` will allow for the ``power_on`` and ``power_off`` methods to be completed instantly without applying timesteps: + +.. code-block:: python + + from primaite.simulator.network.hardware.base import Node + from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState + + node = Node(hostname="pc_a", start_up_duration=0, shut_down_duration=0) + + assert node.operating_state is NodeOperatingState.OFF # node is in OFF state + + node.power_on() + + assert node.operating_state is NodeOperatingState.ON # node is in ON state + + node.power_off() + + assert node.operating_state is NodeOperatingState.OFF # node is in OFF state + ------------------ Network Interfaces ------------------ @@ -357,7 +418,6 @@ Creating the four nodes results in: 2023-08-08 15:50:08,359 INFO: Connected NIC 84:20:7c:ec:a5:c6/192.168.0.13 - --------------- Create Switches --------------- diff --git a/docs/source/simulation_components/system/data_manipulation_bot.rst b/docs/source/simulation_components/system/data_manipulation_bot.rst index 489f8ae5..cc120f70 100644 --- a/docs/source/simulation_components/system/data_manipulation_bot.rst +++ b/docs/source/simulation_components/system/data_manipulation_bot.rst @@ -35,9 +35,12 @@ Example .. code-block:: python client_1 = Computer( - hostname="client_1", ip_address="192.168.10.21", subnet_mask="255.255.255.0", default_gateway="192.168.10.1" + hostname="client_1", + ip_address="192.168.10.21", + subnet_mask="255.255.255.0", + default_gateway="192.168.10.1" + operating_state=NodeOperatingState.ON # initialise the computer in an ON state ) - client_1.power_on() network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) client_1.software_manager.install(DataManipulationBot) data_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] diff --git a/docs/source/simulation_components/system/ftp_client_server.rst b/docs/source/simulation_components/system/ftp_client_server.rst index 306bc039..899af161 100644 --- a/docs/source/simulation_components/system/ftp_client_server.rst +++ b/docs/source/simulation_components/system/ftp_client_server.rst @@ -77,6 +77,7 @@ Dependencies from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.system.services.ftp.ftp_server import FTPServer from primaite.simulator.system.services.ftp.ftp_client import FTPClient + from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState Example peer to peer network ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,10 +86,18 @@ Example peer to peer network net = Network() - pc1 = Computer(hostname="pc1", ip_address="120.10.10.10", subnet_mask="255.255.255.0") - srv = Server(hostname="srv", ip_address="120.10.10.20", subnet_mask="255.255.255.0") - pc1.power_on() - srv.power_on() + pc1 = Computer( + hostname="pc1", + ip_address="120.10.10.10", + subnet_mask="255.255.255.0", + operating_state=NodeOperatingState.ON # initialise the computer in an ON state + ) + srv = Server( + hostname="srv", + ip_address="120.10.10.20", + subnet_mask="255.255.255.0", + operating_state=NodeOperatingState.ON # initialise the server in an ON state + ) net.connect(pc1.ethernet_port[1], srv.ethernet_port[1]) Install the FTP Server diff --git a/docs/source/simulation_components/system/software.rst b/docs/source/simulation_components/system/software.rst index b2985393..1e5a0b6b 100644 --- a/docs/source/simulation_components/system/software.rst +++ b/docs/source/simulation_components/system/software.rst @@ -6,14 +6,45 @@ Software ======== +------------- +Base Software +------------- + +All software which inherits ``IOSoftware`` installed on a node will not work unless the node has been turned on. + +See :ref:`Node Start up and Shut down` + +.. code-block:: python + + from primaite.simulator.network.hardware.base import Node + from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState + from primaite.simulator.system.services.service import ServiceOperatingState + from primaite.simulator.system.services.web_server.web_server import WebServer + + node = Node(hostname="pc_a", start_up_duration=0, shut_down_duration=0) + + node.power_on() + assert node.operating_state is NodeOperatingState.ON + + node.software_manager.install(WebServer) + + web_server: WebServer = node.software_manager.software["WebServer"] + assert web_server.operating_state is ServiceOperatingState.RUNNING # service is immediately ran after install + + node.power_off() + assert node.operating_state is NodeOperatingState.OFF + assert web_server.operating_state is ServiceOperatingState.STOPPED # service stops when node is powered off + + node.power_on() + assert node.operating_state is NodeOperatingState.ON + assert web_server.operating_state is ServiceOperatingState.RUNNING # service turned back on when node is powered on - -Contents -######## +Services, Processes and Applications: +##################################### .. toctree:: - :maxdepth: 8 + :maxdepth: 2 database_client_server data_manipulation_bot diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index ad101f1d..81272547 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1187,6 +1187,7 @@ class Node(SimComponent): self.start_up_countdown = self.start_up_duration if self.start_up_duration <= 0: + self._start_up_actions() self.operating_state = NodeOperatingState.ON self.sys_log.info("Turned on") for nic in self.nics.values(): @@ -1202,6 +1203,7 @@ class Node(SimComponent): self.shut_down_countdown = self.shut_down_duration if self.shut_down_duration <= 0: + self._shut_down_actions() self.operating_state = NodeOperatingState.OFF self.sys_log.info("Turned off") diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 2c3716e9..47196d15 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -1,5 +1,5 @@ from ipaddress import IPv4Address -from typing import Dict, Optional, Union +from typing import Dict, Optional from primaite import getLogger from primaite.simulator.network.protocols.dns import DNSPacket, DNSRequest @@ -51,7 +51,7 @@ class DNSClient(Service): """ pass - def add_domain_to_cache(self, domain_name: str, ip_address: IPv4Address) -> Union[bool, None]: + def add_domain_to_cache(self, domain_name: str, ip_address: IPv4Address) -> bool: """ Adds a domain name to the DNS Client cache. diff --git a/tests/integration_tests/system/test_application_on_node.py b/tests/integration_tests/system/test_application_on_node.py index 7ac7b492..cce586da 100644 --- a/tests/integration_tests/system/test_application_on_node.py +++ b/tests/integration_tests/system/test_application_on_node.py @@ -108,3 +108,14 @@ def test_server_turns_on_service(populated_node): assert computer.operating_state is NodeOperatingState.ON assert app.operating_state is ApplicationOperatingState.RUNNING + + computer.start_up_duration = 0 + computer.shut_down_duration = 0 + + computer.power_off() + assert computer.operating_state is NodeOperatingState.OFF + assert app.operating_state is ApplicationOperatingState.CLOSED + + computer.power_on() + assert computer.operating_state is NodeOperatingState.ON + assert app.operating_state is ApplicationOperatingState.RUNNING diff --git a/tests/integration_tests/system/test_service_on_node.py b/tests/integration_tests/system/test_service_on_node.py index b23df58b..9480c358 100644 --- a/tests/integration_tests/system/test_service_on_node.py +++ b/tests/integration_tests/system/test_service_on_node.py @@ -116,3 +116,14 @@ def test_server_turns_on_service(populated_node): assert server.operating_state is NodeOperatingState.ON assert service.operating_state is ServiceOperatingState.RUNNING + + server.start_up_duration = 0 + server.shut_down_duration = 0 + + server.power_off() + assert server.operating_state is NodeOperatingState.OFF + assert service.operating_state is ServiceOperatingState.STOPPED + + server.power_on() + assert server.operating_state is NodeOperatingState.ON + assert service.operating_state is ServiceOperatingState.RUNNING From 43fee236001a53a1a68c30f50e745192ee8d67e1 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 27 Nov 2023 11:55:58 +0000 Subject: [PATCH 388/980] Fix incorrect order in session from config --- src/primaite/session/session.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py index 80b63ba7..3919902a 100644 --- a/src/primaite/session/session.py +++ b/src/primaite/session/session.py @@ -88,16 +88,16 @@ class PrimaiteSession: @classmethod def from_config(cls, cfg: Dict, agent_load_path: Optional[str] = None) -> "PrimaiteSession": """Create a PrimaiteSession object from a config dictionary.""" + # READ IO SETTINGS (this sets the global session path as well) # TODO: GLOBAL SIDE EFFECTS... + io_settings = cfg.get("io_settings", {}) + io_manager = SessionIO(SessionIOSettings(**io_settings)) + game = PrimaiteGame.from_config(cfg) sess = cls(game=game) - + sess.io_manager = io_manager sess.training_options = TrainingOptions(**cfg["training_config"]) - # READ IO SETTINGS (this sets the global session path as well) # TODO: GLOBAL SIDE EFFECTS... - io_settings = cfg.get("io_settings", {}) - sess.io_manager.settings = SessionIOSettings(**io_settings) - # CREATE ENVIRONMENT if sess.training_options.rl_framework == "RLLIB_single_agent": sess.env = PrimaiteRayEnv(env_config={"game": game}) From 89cbc0835221f4172ae469aa9c7229b3ee8b4cb4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 27 Nov 2023 13:28:11 +0000 Subject: [PATCH 389/980] Apply suggestions from code review --- src/primaite/game/agent/actions.py | 54 +++++++++---------- .../game/agent/data_manipulation_agent.py | 0 src/primaite/game/agent/interface.py | 23 +++++--- .../red_services/data_manipulation_bot.py | 6 +-- .../test_data_manipulation_bot.py | 2 +- 5 files changed, 47 insertions(+), 38 deletions(-) delete mode 100644 src/primaite/game/agent/data_manipulation_agent.py diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 6c6cf7b2..ea992485 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -82,7 +82,7 @@ class NodeServiceAbstractAction(AbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes, "service_id": num_services} - self.verb: str + self.verb: str # define but don't initialise: defends against children classes not defining this def form_request(self, node_id: int, service_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" @@ -98,7 +98,7 @@ class NodeServiceScanAction(NodeServiceAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) - self.verb = "scan" + self.verb: str = "scan" class NodeServiceStopAction(NodeServiceAbstractAction): @@ -106,7 +106,7 @@ class NodeServiceStopAction(NodeServiceAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) - self.verb = "stop" + self.verb: str = "stop" class NodeServiceStartAction(NodeServiceAbstractAction): @@ -114,7 +114,7 @@ class NodeServiceStartAction(NodeServiceAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) - self.verb = "start" + self.verb: str = "start" class NodeServicePauseAction(NodeServiceAbstractAction): @@ -122,7 +122,7 @@ class NodeServicePauseAction(NodeServiceAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) - self.verb = "pause" + self.verb: str = "pause" class NodeServiceResumeAction(NodeServiceAbstractAction): @@ -130,7 +130,7 @@ class NodeServiceResumeAction(NodeServiceAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) - self.verb = "resume" + self.verb: str = "resume" class NodeServiceRestartAction(NodeServiceAbstractAction): @@ -138,7 +138,7 @@ class NodeServiceRestartAction(NodeServiceAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) - self.verb = "restart" + self.verb: str = "restart" class NodeServiceDisableAction(NodeServiceAbstractAction): @@ -146,7 +146,7 @@ class NodeServiceDisableAction(NodeServiceAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) - self.verb = "disable" + self.verb: str = "disable" class NodeServiceEnableAction(NodeServiceAbstractAction): @@ -154,7 +154,7 @@ class NodeServiceEnableAction(NodeServiceAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) - self.verb = "enable" + self.verb: str = "enable" class NodeApplicationAbstractAction(AbstractAction): @@ -169,7 +169,7 @@ class NodeApplicationAbstractAction(AbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_applications: int, **kwargs) -> None: super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes, "application_id": num_applications} - self.verb: str + self.verb: str # define but don't initialise: defends against children classes not defining this def form_request(self, node_id: int, application_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" @@ -185,7 +185,7 @@ class NodeApplicationExecuteAction(NodeApplicationAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_applications: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_applications=num_applications) - self.verb = "execute" + self.verb: str = "execute" class NodeFolderAbstractAction(AbstractAction): @@ -200,7 +200,7 @@ class NodeFolderAbstractAction(AbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, **kwargs) -> None: super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes, "folder_id": num_folders} - self.verb: str + self.verb: str # define but don't initialise: defends against children classes not defining this def form_request(self, node_id: int, folder_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" @@ -254,7 +254,7 @@ class NodeFileAbstractAction(AbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes, "folder_id": num_folders, "file_id": num_files} - self.verb: str + self.verb: str # define but don't initialise: defends against children classes not defining this def form_request(self, node_id: int, folder_id: int, file_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" @@ -271,7 +271,7 @@ class NodeFileScanAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) - self.verb = "scan" + self.verb: str = "scan" class NodeFileCheckhashAction(NodeFileAbstractAction): @@ -279,7 +279,7 @@ class NodeFileCheckhashAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) - self.verb = "checkhash" + self.verb: str = "checkhash" class NodeFileDeleteAction(NodeFileAbstractAction): @@ -287,7 +287,7 @@ class NodeFileDeleteAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) - self.verb = "delete" + self.verb: str = "delete" class NodeFileRepairAction(NodeFileAbstractAction): @@ -295,7 +295,7 @@ class NodeFileRepairAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) - self.verb = "repair" + self.verb: str = "repair" class NodeFileRestoreAction(NodeFileAbstractAction): @@ -303,7 +303,7 @@ class NodeFileRestoreAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) - self.verb = "restore" + self.verb: str = "restore" class NodeFileCorruptAction(NodeFileAbstractAction): @@ -311,7 +311,7 @@ class NodeFileCorruptAction(NodeFileAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_folders: int, num_files: int, **kwargs) -> None: super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) - self.verb = "corrupt" + self.verb: str = "corrupt" class NodeAbstractAction(AbstractAction): @@ -325,7 +325,7 @@ class NodeAbstractAction(AbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes} - self.verb: str + self.verb: str # define but don't initialise: defends against children classes not defining this def form_request(self, node_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" @@ -338,7 +338,7 @@ class NodeOSScanAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes) - self.verb = "scan" + self.verb: str = "scan" class NodeShutdownAction(NodeAbstractAction): @@ -346,7 +346,7 @@ class NodeShutdownAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes) - self.verb = "shutdown" + self.verb: str = "shutdown" class NodeStartupAction(NodeAbstractAction): @@ -354,7 +354,7 @@ class NodeStartupAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes) - self.verb = "startup" + self.verb: str = "startup" class NodeResetAction(NodeAbstractAction): @@ -362,7 +362,7 @@ class NodeResetAction(NodeAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes) - self.verb = "reset" + self.verb: str = "reset" class NetworkACLAddRuleAction(AbstractAction): @@ -520,7 +520,7 @@ class NetworkNICAbstractAction(AbstractAction): """ super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes, "nic_id": max_nics_per_node} - self.verb: str + self.verb: str # define but don't initialise: defends against children classes not defining this def form_request(self, node_id: int, nic_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" @@ -543,7 +543,7 @@ class NetworkNICEnableAction(NetworkNICAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, max_nics_per_node=max_nics_per_node, **kwargs) - self.verb = "enable" + self.verb: str = "enable" class NetworkNICDisableAction(NetworkNICAbstractAction): @@ -551,7 +551,7 @@ class NetworkNICDisableAction(NetworkNICAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, max_nics_per_node=max_nics_per_node, **kwargs) - self.verb = "disable" + self.verb: str = "disable" class ActionManager: diff --git a/src/primaite/game/agent/data_manipulation_agent.py b/src/primaite/game/agent/data_manipulation_agent.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 6e783725..fbbe5473 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from typing import Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium.core import ActType, ObsType -from pydantic import BaseModel +from pydantic import BaseModel, model_validator from primaite.game.agent.actions import ActionManager from primaite.game.agent.observations import ObservationManager @@ -23,6 +23,21 @@ class AgentStartSettings(BaseModel): variance: int = 0 "The amount the frequency can randomly change to" + @model_validator(mode="after") + def check_variance_lt_frequency(self) -> "AgentStartSettings": + """ + Make sure variance is equal to or lower than frequency. + + This is because the calculation for the next execution time is now + (frequency +- variance). If variance were + greater than frequency, sometimes the bracketed term would be negative and the attack would never happen again. + """ + if self.variance > self.frequency: + raise ValueError( + f"Agent start settings error: variance must be lower than frequency " + f"{self.variance=}, {self.frequency=}" + ) + return self + class AgentSettings(BaseModel): """Settings for configuring the operation of an agent.""" @@ -180,9 +195,3 @@ class ProxyAgent(AbstractAgent): The environment is responsible for calling this method when it receives an action from the agent policy. """ self.most_recent_action = action - - -class AbstractGATEAgent(AbstractAgent): - """Base class for actors controlled via external messages, such as RL policies.""" - - ... diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index 6db9e1aa..b0b34396 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -24,7 +24,7 @@ class DataManipulationAttackStage(IntEnum): "Represents the stage of performing a horizontal port scan on the target." ATTACKING = 3 "Stage of actively attacking the target." - COMPLETE = 4 + SUCCEEDED = 4 "Indicates the attack has been successfully completed." FAILED = 5 "Signifies that the attack has failed." @@ -134,7 +134,7 @@ class DataManipulationBot(DatabaseClient): attack_successful = True if attack_successful: self.sys_log.info(f"{self.name}: Data manipulation successful") - self.attack_stage = DataManipulationAttackStage.COMPLETE + self.attack_stage = DataManipulationAttackStage.SUCCEEDED else: self.sys_log.info(f"{self.name}: Data manipulation failed") self.attack_stage = DataManipulationAttackStage.FAILED @@ -163,7 +163,7 @@ class DataManipulationBot(DatabaseClient): self._perform_data_manipulation(p_of_success=self.data_manipulation_p_of_success) if self.repeat and self.attack_stage in ( - DataManipulationAttackStage.COMPLETE, + DataManipulationAttackStage.SUCCEEDED, DataManipulationAttackStage.FAILED, ): self.attack_stage = DataManipulationAttackStage.NOT_STARTED diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py index 936f7c5c..3b1e4aa4 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py @@ -69,5 +69,5 @@ def test_dm_bot_perform_data_manipulation_success(dm_bot): dm_bot._perform_data_manipulation(p_of_success=1.0) - assert dm_bot.attack_stage in (DataManipulationAttackStage.COMPLETE, DataManipulationAttackStage.FAILED) + assert dm_bot.attack_stage in (DataManipulationAttackStage.SUCCEEDED, DataManipulationAttackStage.FAILED) assert dm_bot.connected From 4d4a578555f2452c85faa72e2b40b85cd4489542 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 27 Nov 2023 13:47:59 +0000 Subject: [PATCH 390/980] #1859 - Integrated the runtime execution for web client. Added in the webclient application execution action. Now fixing http status code issues. --- .../config/_package_data/example_config.yaml | 28 +++++++++---------- src/primaite/game/game.py | 5 +++- src/primaite/session/environment.py | 2 +- src/primaite/simulator/network/networks.py | 2 ++ .../simulator/network/protocols/http.py | 4 +-- .../system/applications/database_client.py | 4 +-- .../system/applications/web_browser.py | 15 ++++++++-- .../system/services/web_server/web_server.py | 4 ++- .../system/test_web_client_server.py | 11 ++++---- 9 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 3cea2f29..b68861e1 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -1,5 +1,5 @@ training_config: - rl_framework: RLLIB_single_agent + rl_framework: SB3 rl_algorithm: PPO seed: 333 n_learn_episodes: 1 @@ -36,22 +36,16 @@ agents: action_space: action_list: - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com - + - type: NODE_APPLICATION_EXECUTE options: nodes: - node_ref: client_2 + applications: + - application_ref: client_2_web_browser max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + max_applications_per_node: 1 reward_function: reward_components: @@ -549,19 +543,19 @@ simulation: ip_address: 192.168.10.1 subnet_mask: 255.255.255.0 acl: - 0: + 18: action: PERMIT src_port: POSTGRES_SERVER dst_port: POSTGRES_SERVER - 1: + 19: action: PERMIT src_port: DNS dst_port: DNS - 2: + 20: action: PERMIT src_port: FTP dst_port: FTP - 3: + 21: action: PERMIT src_port: HTTP dst_port: HTTP @@ -679,10 +673,14 @@ simulation: applications: - ref: client_2_web_browser type: WebBrowser + options: + target_url: http://arcd.com/users/ services: - ref: client_2_dns_client type: DNSClient + + links: - ref: router_1___switch_1 endpoint_a_ref: router_1 diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index ae60bbc1..48615ca6 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -316,6 +316,10 @@ class PrimaiteGame: port_scan_p_of_success=float(opt.get("port_scan_p_of_success", "0.1")), data_manipulation_p_of_success=float(opt.get("data_manipulation_p_of_success", "0.1")), ) + elif application_type == "WebBrowser": + if "options" in application_cfg: + opt = application_cfg["options"] + new_application.target_url = opt.get("target_url") if "nics" in node_cfg: for nic_num, nic_cfg in node_cfg["nics"].items(): new_node.connect_nic(NIC(ip_address=nic_cfg["ip_address"], subnet_mask=nic_cfg["subnet_mask"])) @@ -377,7 +381,6 @@ class PrimaiteGame: action_space_cfg["options"]["application_uuids"].append(node_application_uuids) else: action_space_cfg["options"]["application_uuids"].append([]) - # Each action space can potentially have a different list of nodes that it can apply to. Therefore, # we will pass node_uuids as a part of the action space config. # However, it's not possible to specify the node uuids directly in the config, as they are generated diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index db24db60..a5fdade9 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -37,7 +37,7 @@ class PrimaiteGymEnv(gymnasium.Env): terminated = False truncated = self.game.calculate_truncated() info = {} - + print(f"Episode: {self.game.episode_counter}, Step: {self.game.step_counter}, Reward: {reward}") return next_obs, reward, terminated, truncated, info def reset(self, seed: Optional[int] = None) -> Tuple[ObsType, Dict[str, Any]]: diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index ea767b54..446e5649 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -157,6 +157,8 @@ def arcd_uc2_network() -> Network: operating_state=NodeOperatingState.ON, ) client_2.power_on() + web_browser = client_2.software_manager["WebBrowser"] + web_browser.target_url = "http://arcd.com/users/" network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) # Domain Controller diff --git a/src/primaite/simulator/network/protocols/http.py b/src/primaite/simulator/network/protocols/http.py index 2dba2614..b88916a9 100644 --- a/src/primaite/simulator/network/protocols/http.py +++ b/src/primaite/simulator/network/protocols/http.py @@ -1,4 +1,4 @@ -from enum import Enum +from enum import Enum, IntEnum from primaite.simulator.network.protocols.packet import DataPacket @@ -25,7 +25,7 @@ class HttpRequestMethod(Enum): """Apply partial modifications to a resource.""" -class HttpStatusCode(Enum): +class HttpStatusCode(IntEnum): """List of available HTTP Statuses.""" OK = 200 diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index b24b6062..37236e69 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -75,11 +75,11 @@ class DatabaseClient(Application): """ if is_reattempt: if self.connected: - self.sys_log.info(f"{self.name}: DatabaseClient connected to {server_ip_address} authorised") + self.sys_log.info(f"{self.name}: DatabaseClient connection to {server_ip_address} authorised") self.server_ip_address = server_ip_address return self.connected else: - self.sys_log.info(f"{self.name}: DatabaseClient connected to {server_ip_address} declined") + self.sys_log.info(f"{self.name}: DatabaseClient connection to {server_ip_address} declined") return False payload = {"type": "connect_request", "password": password} software_manager: SoftwareManager = self.software_manager diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index ea9c3ac3..0a9c7fc3 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -2,6 +2,7 @@ from ipaddress import IPv4Address from typing import Dict, Optional from urllib.parse import urlparse +from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.network.protocols.http import HttpRequestMethod, HttpRequestPacket, HttpResponsePacket from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -16,6 +17,8 @@ class WebBrowser(Application): The application requests and loads web pages using its domain name and requesting IP addresses using DNS. """ + target_url: Optional[str] = None + domain_name_ip_address: Optional[IPv4Address] = None "The IP address of the domain name for the webpage." @@ -32,6 +35,14 @@ class WebBrowser(Application): super().__init__(**kwargs) self.run() + def _init_request_manager(self) -> RequestManager: + rm = super()._init_request_manager() + rm.add_request( + name="execute", request_type=RequestType(func=lambda request, context: self.get_webpage()) # noqa + ) + + return rm + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of the WebBrowser. @@ -51,7 +62,7 @@ class WebBrowser(Application): self.domain_name_ip_address = None self.latest_response = None - def get_webpage(self, url: str) -> bool: + def get_webpage(self) -> bool: """ Retrieve the webpage. @@ -60,6 +71,7 @@ class WebBrowser(Application): :param: url: The address of the web page the browser requests :type: url: str """ + url = self.target_url # reset latest response self.latest_response = None @@ -71,7 +83,6 @@ class WebBrowser(Application): # get the IP address of the domain name via DNS dns_client: DNSClient = self.software_manager.software["DNSClient"] - domain_exists = dns_client.check_domain_exists(target_domain=parsed_url.hostname) # if domain does not exist, the request fails diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index cb1a4738..5dda82d5 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -29,8 +29,9 @@ class WebServer(Service): :rtype: Dict """ state = super().describe_state() + state["last_response_status_code"] = ( - self.last_response_status_code.value if self.last_response_status_code else None + self.last_response_status_code.value if isinstance(self.last_response_status_code, HttpStatusCode) else None ) return state @@ -84,6 +85,7 @@ class WebServer(Service): # return true if response is OK self.last_response_status_code = response.status_code + print(self.last_response_status_code) return response.status_code == HttpStatusCode.OK def _handle_get_request(self, payload: HttpRequestPacket) -> HttpResponsePacket: diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py index f4546cbf..991d6282 100644 --- a/tests/integration_tests/system/test_web_client_server.py +++ b/tests/integration_tests/system/test_web_client_server.py @@ -3,7 +3,6 @@ from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.http import HttpStatusCode from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.web_browser import WebBrowser -from primaite.simulator.system.services.service import ServiceOperatingState def test_web_page_home_page(uc2_network): @@ -11,9 +10,10 @@ def test_web_page_home_page(uc2_network): client_1: Computer = uc2_network.get_node_by_hostname("client_1") web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] web_client.run() + web_client.target_url = "http://arcd.com/" assert web_client.operating_state == ApplicationOperatingState.RUNNING - assert web_client.get_webpage("http://arcd.com/") is True + assert web_client.get_webpage() is True # latest reponse should have status code 200 assert web_client.latest_response is not None @@ -27,7 +27,7 @@ def test_web_page_get_users_page_request_with_domain_name(uc2_network): web_client.run() assert web_client.operating_state == ApplicationOperatingState.RUNNING - assert web_client.get_webpage("http://arcd.com/users/") is True + assert web_client.get_webpage() is True # latest reponse should have status code 200 assert web_client.latest_response is not None @@ -41,11 +41,12 @@ def test_web_page_get_users_page_request_with_ip_address(uc2_network): web_client.run() web_server: Server = uc2_network.get_node_by_hostname("web_server") - web_server_ip = web_server.nics.get(next(iter(web_server.nics))).ip_address + web_server_ip = web_server.nics.get(next(iter(web_server.nics))).ip_address + web_client.target_url = f"http://{web_server_ip}/users/" assert web_client.operating_state == ApplicationOperatingState.RUNNING - assert web_client.get_webpage(f"http://{web_server_ip}/users/") is True + assert web_client.get_webpage() is True # latest reponse should have status code 200 assert web_client.latest_response is not None From 6fd37a609ac663da8795238ac41a094e993f85b5 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Mon, 27 Nov 2023 14:38:59 +0000 Subject: [PATCH 391/980] #2068: code review comments. --- docs/index.rst | 1 - docs/source/about.rst | 4 ++-- docs/source/custom_agent.rst | 14 -------------- 3 files changed, 2 insertions(+), 17 deletions(-) delete mode 100644 docs/source/custom_agent.rst diff --git a/docs/index.rst b/docs/index.rst index 2dfc8a65..9eae8adc 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -107,7 +107,6 @@ Head over to the :ref:`getting-started` page to install and setup PrimAITE! source/primaite_session source/simulation source/game_layer - source/custom_agent source/config .. toctree:: diff --git a/docs/source/about.rst b/docs/source/about.rst index e8befbaf..3f905933 100644 --- a/docs/source/about.rst +++ b/docs/source/about.rst @@ -278,7 +278,7 @@ The game layer is built on top of the simulator and it consumes the simulation a 3. Any (Agent can take both node-based and ACL-based actions) The choice of action space used during a training session is determined in the config_[name].yaml file. **Node-Based** - The agent is able to influence the status of nodes by switching them off, resetting, or patching operating systems and services. In this instance, the action space is an Gymnasium spaces.Discrete type, as follows: + The agent is able to influence the status of nodes by switching them off, resetting, or patching operating systems and services. In this instance, the action space is a Gymnasium spaces.Discrete type, as follows: * Dictionary item {... ,1: [x1, x2, x3,x4] ...} The placeholders inside the list under the key '1' mean the following: * [0, num nodes] - Node ID (0 = nothing, node ID) @@ -286,7 +286,7 @@ The game layer is built on top of the simulator and it consumes the simulation a * [0, 3] - Action on property (0 = nothing, 1 = on / scan, 2 = off / repair, 3 = reset / patch / restore) * [0, num services] - Resolves to service ID (0 = nothing, resolves to service) **Access Control List** - The blue agent is able to influence the configuration of the Access Control List rule set (which implements a system-wide firewall). In this instance, the action space is an OpenAI spaces.Discrete type, as follows: + The blue agent is able to influence the configuration of the Access Control List rule set (which implements a system-wide firewall). In this instance, the action space is an Gymnasium spaces.Discrete type, as follows: * Dictionary item {... ,1: [x1, x2, x3, x4, x5, x6] ...} The placeholders inside the list under the key '1' mean the following: * [0, 2] - Action (0 = do nothing, 1 = create rule, 2 = delete rule) diff --git a/docs/source/custom_agent.rst b/docs/source/custom_agent.rst deleted file mode 100644 index 7a9d83c1..00000000 --- a/docs/source/custom_agent.rst +++ /dev/null @@ -1,14 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -Custom Agents -============= - - -Integrating a user defined blue agent -************************************* - -.. note:: - - TBA From ae5046b8fb94d1a8c787f870fa461489c5d98fef Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 27 Nov 2023 17:05:12 +0000 Subject: [PATCH 392/980] #1859 - As disccused --- src/primaite/game/agent/actions.py | 11 ++-- src/primaite/game/agent/observations.py | 2 +- src/primaite/game/agent/rewards.py | 3 +- src/primaite/game/game.py | 56 +++++++++++++------ .../simulator/network/hardware/base.py | 3 + .../system/applications/web_browser.py | 7 +++ .../system/services/web_server/web_server.py | 29 +++++++++- 7 files changed, 83 insertions(+), 28 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index ea992485..62e56c6e 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -634,7 +634,6 @@ class ActionManager: :type act_map: Optional[Dict[int, Dict]] """ self.game: "PrimaiteGame" = game - self.sim: Simulation = self.game.simulation self.node_uuids: List[str] = node_uuids self.application_uuids: List[List[str]] = application_uuids self.protocols: List[str] = protocols @@ -646,7 +645,7 @@ class ActionManager: else: self.ip_address_list = [] for node_uuid in self.node_uuids: - node_obj = self.sim.network.nodes[node_uuid] + node_obj = self.game.simulation.network.nodes[node_uuid] nics = node_obj.nics for nic_uuid, nic_obj in nics.items(): self.ip_address_list.append(nic_obj.ip_address) @@ -770,7 +769,7 @@ class ActionManager: :rtype: Optional[str] """ node_uuid = self.get_node_uuid_by_idx(node_idx) - node = self.sim.network.nodes[node_uuid] + node = self.game.simulation.network.nodes[node_uuid] folder_uuids = list(node.file_system.folders.keys()) return folder_uuids[folder_idx] if len(folder_uuids) > folder_idx else None @@ -788,7 +787,7 @@ class ActionManager: :rtype: Optional[str] """ node_uuid = self.get_node_uuid_by_idx(node_idx) - node = self.sim.network.nodes[node_uuid] + node = self.game.simulation.network.nodes[node_uuid] folder_uuids = list(node.file_system.folders.keys()) if len(folder_uuids) <= folder_idx: return None @@ -807,7 +806,7 @@ class ActionManager: :rtype: Optional[str] """ node_uuid = self.get_node_uuid_by_idx(node_idx) - node = self.sim.network.nodes[node_uuid] + node = self.game.simulation.network.nodes[node_uuid] service_uuids = list(node.services.keys()) return service_uuids[service_idx] if len(service_uuids) > service_idx else None @@ -867,7 +866,7 @@ class ActionManager: :rtype: str """ node_uuid = self.get_node_uuid_by_idx(node_idx) - node_obj = self.sim.network.nodes[node_uuid] + node_obj = self.game.simulation.network.nodes[node_uuid] nics = list(node_obj.nics.keys()) if len(nics) <= nic_idx: return None diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 14fb2fa7..823d65d7 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -162,7 +162,7 @@ class ServiceObservation(AbstractObservation): :return: Constructed service observation :rtype: ServiceObservation """ - return cls(where=parent_where + ["services", game.ref_map_services[config["service_ref"]].uuid]) + return cls(where=parent_where + ["services", game.ref_map_services[config["service_ref"]]]) class LinkObservation(AbstractObservation): diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 8a1c2da4..7cca9116 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -25,6 +25,7 @@ the structure: service_ref: web_server_database_client ``` """ +import json from abc import abstractmethod from typing import Dict, List, Tuple, Type, TYPE_CHECKING @@ -213,7 +214,7 @@ class WebServer404Penalty(AbstractReward): _LOGGER.warn(msg) return DummyReward() # TODO: should we error out with incorrect inputs? Probably! node_uuid = game.ref_map_nodes[node_ref] - service_uuid = game.ref_map_services[service_ref].uuid + service_uuid = game.ref_map_services[service_ref] if not (node_uuid and service_uuid): msg = ( f"{cls.__name__} could not be initialised because node {node_ref} and service {service_ref} were not" diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 48615ca6..147ed499 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -59,8 +59,9 @@ class PrimaiteGame: """Initialise a PrimaiteGame object.""" self.simulation: Simulation = Simulation() """Simulation object with which the agents will interact.""" + print(f"Hello, welcome to PrimaiteGame. This is the ID of the ORIGINAL simulation {id(self.simulation)}") - self._simulation_initial_state = deepcopy(self.simulation) + self._simulation_initial_state = None """The Simulation original state (deepcopy of the original Simulation).""" self.agents: List[AbstractAgent] = [] @@ -78,16 +79,16 @@ class PrimaiteGame: self.options: PrimaiteGameOptions """Special options that apply for the entire game.""" - self.ref_map_nodes: Dict[str, Node] = {} + self.ref_map_nodes: Dict[str, str] = {} """Mapping from unique node reference name to node object. Used when parsing config files.""" - self.ref_map_services: Dict[str, Service] = {} + self.ref_map_services: Dict[str, str] = {} """Mapping from human-readable service reference to service object. Used for parsing config files.""" - self.ref_map_applications: Dict[str, Application] = {} + self.ref_map_applications: Dict[str, str] = {} """Mapping from human-readable application reference to application object. Used for parsing config files.""" - self.ref_map_links: Dict[str, Link] = {} + self.ref_map_links: Dict[str, str] = {} """Mapping from human-readable link reference to link object. Used when parsing config files.""" def step(self): @@ -161,6 +162,33 @@ class PrimaiteGame: self.step_counter = 0 _LOGGER.debug(f"Resetting primaite game, episode = {self.episode_counter}") self.simulation = deepcopy(self._simulation_initial_state) + self._reset_components_for_episode() + print("Reset") + + def _reset_components_for_episode(self): + print("Performing full reset for episode") + for node in self.simulation.network.nodes.values(): + print(f"Resetting Node: {node.hostname}") + node.reset_component_for_episode(self.episode_counter) + + # reset Node NIC + + # Reset Node Services + + # Reset Node Applications + print(f"Resetting Software...") + for application in node.software_manager.software.values(): + print(f"Resetting {application.name}") + if isinstance(application, WebBrowser): + application.do_this() + + # Reset Node FileSystem + # Reset Node FileSystemFolder's + # Reset Node FileSystemFile's + + # Reset Router + + # Reset Links def close(self) -> None: """Close the game, this will close the simulation.""" @@ -190,10 +218,6 @@ class PrimaiteGame: sim = game.simulation net = sim.network - game.ref_map_nodes: Dict[str, Node] = {} - game.ref_map_services: Dict[str, Service] = {} - game.ref_map_links: Dict[str, Link] = {} - nodes_cfg = cfg["simulation"]["network"]["nodes"] links_cfg = cfg["simulation"]["network"]["links"] for node_cfg in nodes_cfg: @@ -269,7 +293,7 @@ class PrimaiteGame: print(f"installing {service_type} on node {new_node.hostname}") new_node.software_manager.install(service_types_mapping[service_type]) new_service = new_node.software_manager.software[service_type] - game.ref_map_services[service_ref] = new_service + game.ref_map_services[service_ref] = new_service.uuid else: print(f"service type not found {service_type}") # service-dependent options @@ -303,7 +327,7 @@ class PrimaiteGame: if application_type in application_types_mapping: new_node.software_manager.install(application_types_mapping[application_type]) new_application = new_node.software_manager.software[application_type] - game.ref_map_applications[application_ref] = new_application + game.ref_map_applications[application_ref] = new_application.uuid else: print(f"application type not found {application_type}") @@ -326,11 +350,7 @@ class PrimaiteGame: net.add_node(new_node) new_node.power_on() - game.ref_map_nodes[ - node_ref - ] = ( - new_node.uuid - ) # TODO: fix inconsistency with service and link. Node gets added by uuid, but service by object + game.ref_map_nodes[node_ref] = new_node.uuid # 2. create links between nodes for link_cfg in links_cfg: @@ -375,7 +395,7 @@ class PrimaiteGame: for application_option in action_node_option["applications"]: # TODO: fix inconsistency with node uuids and application uuids. The node object get added to # node_uuid, whereas here the application gets added by uuid. - application_uuid = game.ref_map_applications[application_option["application_ref"]].uuid + application_uuid = game.ref_map_applications[application_option["application_ref"]] node_application_uuids.append(application_uuid) action_space_cfg["options"]["application_uuids"].append(node_application_uuids) @@ -433,5 +453,7 @@ class PrimaiteGame: print("agent type not found") game._simulation_initial_state = deepcopy(game.simulation) # noqa + web_server = game.simulation.network.get_node_by_hostname("web_server").software_manager.software["WebServer"] + print(f"And this is the ID of the original WebServer {id(web_server)}") return game diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 29d3a05c..0717f813 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1005,6 +1005,9 @@ class Node(SimComponent): return rm + def reset_component_for_episode(self, episode: int): + self._init_request_manager() + def _install_system_software(self): """Install System Software - software that is usually provided with the OS.""" pass diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 0a9c7fc3..ef9ac0e7 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -43,6 +43,13 @@ class WebBrowser(Application): return rm + def do_this(self): + self._init_request_manager() + print(f"Resetting WebBrowser for episode") + + def reset_component_for_episode(self, episode: int): + pass + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of the WebBrowser. diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index 5dda82d5..86a4e4f1 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -17,7 +17,16 @@ from primaite.simulator.system.services.service import Service class WebServer(Service): """Class used to represent a Web Server Service in simulation.""" - last_response_status_code: Optional[HttpStatusCode] = None + _last_response_status_code: Optional[HttpStatusCode] = None + + @property + def last_response_status_code(self) -> HttpStatusCode: + return self._last_response_status_code + + @last_response_status_code.setter + def last_response_status_code(self, val: Any): + print(f"val: {val}, type: {type(val)}") + self._last_response_status_code = val def describe_state(self) -> Dict: """ @@ -29,10 +38,17 @@ class WebServer(Service): :rtype: Dict """ state = super().describe_state() - state["last_response_status_code"] = ( self.last_response_status_code.value if isinstance(self.last_response_status_code, HttpStatusCode) else None ) + + print( + f"" + f"Printing state from Webserver describe func: " + f"val={state['last_response_status_code']}, " + f"type={type(state['last_response_status_code'])}, " + f"Service obj ID={id(self)}" + ) return state def __init__(self, **kwargs): @@ -85,7 +101,14 @@ class WebServer(Service): # return true if response is OK self.last_response_status_code = response.status_code - print(self.last_response_status_code) + + print( + f"" + f"Printing state from Webserver http request func: " + f"val={self.last_response_status_code}, " + f"type={type(self.last_response_status_code)}, " + f"Service obj ID={id(self)}" + ) return response.status_code == HttpStatusCode.OK def _handle_get_request(self, payload: HttpRequestPacket) -> HttpResponsePacket: From 58e9033a4c8729290e56d9d2b601ab291521b65c Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 27 Nov 2023 23:01:56 +0000 Subject: [PATCH 393/980] #1859 - First pass at an implementation of the full reset method. Will now start testing... --- src/primaite/game/agent/actions.py | 1 - src/primaite/game/agent/rewards.py | 1 - src/primaite/game/game.py | 42 +--- src/primaite/simulator/core.py | 20 +- src/primaite/simulator/domain/account.py | 13 ++ src/primaite/simulator/file_system/file.py | 12 ++ .../simulator/file_system/file_system.py | 30 +++ .../file_system/file_system_item_abc.py | 5 + src/primaite/simulator/file_system/folder.py | 38 ++++ src/primaite/simulator/network/container.py | 14 ++ .../simulator/network/hardware/base.py | 195 ++++++++---------- .../network/hardware/nodes/router.py | 31 +++ src/primaite/simulator/sim_container.py | 10 +- .../system/applications/application.py | 15 +- .../system/applications/database_client.py | 7 + .../system/applications/web_browser.py | 23 +-- .../simulator/system/core/packet_capture.py | 9 +- .../simulator/system/core/session_manager.py | 5 + src/primaite/simulator/system/core/sys_log.py | 7 +- .../simulator/system/processes/process.py | 6 + .../services/database/database_service.py | 17 ++ .../system/services/dns/dns_client.py | 20 +- .../system/services/dns/dns_server.py | 14 +- .../simulator/system/services/service.py | 15 +- .../system/services/web_server/web_server.py | 21 +- src/primaite/simulator/system/software.py | 29 ++- 26 files changed, 360 insertions(+), 240 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 62e56c6e..c70d4d66 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -15,7 +15,6 @@ from typing import Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium import spaces from primaite import getLogger -from primaite.simulator.sim_container import Simulation _LOGGER = getLogger(__name__) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 7cca9116..3466114c 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -25,7 +25,6 @@ the structure: service_ref: web_server_database_client ``` """ -import json from abc import abstractmethod from typing import Dict, List, Tuple, Type, TYPE_CHECKING diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 147ed499..38e9d5fc 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -1,5 +1,4 @@ """PrimAITE game - Encapsulates the simulation and agents.""" -from copy import deepcopy from ipaddress import IPv4Address from typing import Dict, List @@ -11,7 +10,7 @@ from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent, RandomAgent from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction -from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState +from primaite.simulator.network.hardware.base import NIC, NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.server import Server @@ -19,7 +18,6 @@ from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.sim_container import Simulation -from primaite.simulator.system.applications.application import Application from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.database.database_service import DatabaseService @@ -28,7 +26,6 @@ from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.ftp.ftp_client import FTPClient from primaite.simulator.system.services.ftp.ftp_server import FTPServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot -from primaite.simulator.system.services.service import Service from primaite.simulator.system.services.web_server.web_server import WebServer _LOGGER = getLogger(__name__) @@ -59,10 +56,6 @@ class PrimaiteGame: """Initialise a PrimaiteGame object.""" self.simulation: Simulation = Simulation() """Simulation object with which the agents will interact.""" - print(f"Hello, welcome to PrimaiteGame. This is the ID of the ORIGINAL simulation {id(self.simulation)}") - - self._simulation_initial_state = None - """The Simulation original state (deepcopy of the original Simulation).""" self.agents: List[AbstractAgent] = [] """List of agents.""" @@ -161,34 +154,7 @@ class PrimaiteGame: self.episode_counter += 1 self.step_counter = 0 _LOGGER.debug(f"Resetting primaite game, episode = {self.episode_counter}") - self.simulation = deepcopy(self._simulation_initial_state) - self._reset_components_for_episode() - print("Reset") - - def _reset_components_for_episode(self): - print("Performing full reset for episode") - for node in self.simulation.network.nodes.values(): - print(f"Resetting Node: {node.hostname}") - node.reset_component_for_episode(self.episode_counter) - - # reset Node NIC - - # Reset Node Services - - # Reset Node Applications - print(f"Resetting Software...") - for application in node.software_manager.software.values(): - print(f"Resetting {application.name}") - if isinstance(application, WebBrowser): - application.do_this() - - # Reset Node FileSystem - # Reset Node FileSystemFolder's - # Reset Node FileSystemFile's - - # Reset Router - - # Reset Links + self.simulation.reset_component_for_episode(episode=self.episode_counter) def close(self) -> None: """Close the game, this will close the simulation.""" @@ -452,8 +418,6 @@ class PrimaiteGame: else: print("agent type not found") - game._simulation_initial_state = deepcopy(game.simulation) # noqa - web_server = game.simulation.network.get_node_by_hostname("web_server").software_manager.software["WebServer"] - print(f"And this is the ID of the original WebServer {id(web_server)}") + game.simulation.set_original_state() return game diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 9ead877e..18a470cd 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -153,6 +153,8 @@ class SimComponent(BaseModel): uuid: str """The component UUID.""" + _original_state: Dict = {} + def __init__(self, **kwargs): if not kwargs.get("uuid"): kwargs["uuid"] = str(uuid4()) @@ -160,6 +162,16 @@ class SimComponent(BaseModel): self._request_manager: RequestManager = self._init_request_manager() self._parent: Optional["SimComponent"] = None + # @abstractmethod + def set_original_state(self): + """Sets the original state.""" + pass + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + for key, value in self._original_state.items(): + self.__setattr__(key, value) + def _init_request_manager(self) -> RequestManager: """ Initialise the request manager for this component. @@ -227,14 +239,6 @@ class SimComponent(BaseModel): """ pass - def reset_component_for_episode(self, episode: int): - """ - Reset this component to its original state for a new episode. - - Override this method with anything that needs to happen within the component for it to be reset. - """ - pass - @property def parent(self) -> "SimComponent": """Reference to the parent object which manages this object. diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py index d235c00e..1402a474 100644 --- a/src/primaite/simulator/domain/account.py +++ b/src/primaite/simulator/domain/account.py @@ -42,6 +42,19 @@ class Account(SimComponent): "Account Type, currently this can be service account (used by apps) or user account." enabled: bool = True + def set_original_state(self): + """Sets the original state.""" + vals_to_include = { + "num_logons", + "num_logoffs", + "num_group_changes", + "username", + "password", + "account_type", + "enabled", + } + self._original_state = self.model_dump(include=vals_to_include) + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index d9b02e8e..8f0abb3c 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -73,6 +73,18 @@ class File(FileSystemItemABC): self.sys_log.info(f"Created file /{self.path} (id: {self.uuid})") + self.set_original_state() + + def set_original_state(self): + """Sets the original state.""" + super().set_original_state() + vals_to_include = {"folder_id", "folder_name", "file_type", "sim_size", "real", "sim_path", "sim_root"} + self._original_state.update(self.model_dump(include=vals_to_include)) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + super().reset_component_for_episode(episode) + @property def path(self) -> str: """ diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 41f02270..dc6f01a3 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -35,6 +35,36 @@ class FileSystem(SimComponent): if not self.folders: self.create_folder("root") + def set_original_state(self): + """Sets the original state.""" + for folder in self.folders.values(): + folder.set_original_state() + super().set_original_state() + # Capture a list of all 'original' file uuids + self._original_state["original_folder_uuids"] = list(self.folders.keys()) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + # Move any 'original' folder that have been deleted back to folders + original_folder_uuids = self._original_state.pop("original_folder_uuids") + for uuid in original_folder_uuids: + if uuid in self.deleted_folders: + self.folders[uuid] = self.deleted_folders.pop(uuid) + + # Clear any other deleted folders that aren't original (have been created by agent) + self.deleted_folders.clear() + + # Now clear all non-original folders created by agent + current_folder_uuids = list(self.folders.keys()) + for uuid in current_folder_uuids: + if uuid not in original_folder_uuids: + self.folders.pop(uuid) + + # Now reset all remaining folders + for folder in self.folders.values(): + folder.reset_component_for_episode(episode) + super().reset_component_for_episode(episode) + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py index fbe5f4b3..86cd1ee7 100644 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -85,6 +85,11 @@ class FileSystemItemABC(SimComponent): deleted: bool = False "If true, the FileSystemItem was deleted." + def set_original_state(self): + """Sets the original state.""" + vals_to_keep = {"name", "health_status", "visible_health_status", "previous_hash", "revealed_to_red"} + self._original_state = self.model_dump(include=vals_to_keep) + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index f0d55ef8..8e577097 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -51,6 +51,44 @@ class Folder(FileSystemItemABC): self.sys_log.info(f"Created file /{self.name} (id: {self.uuid})") + def set_original_state(self): + """Sets the original state.""" + for file in self.files.values(): + file.set_original_state() + super().set_original_state() + vals_to_include = { + "scan_duration", + "scan_countdown", + "red_scan_duration", + "red_scan_countdown", + "restore_duration", + "restore_countdown", + } + self._original_state.update(self.model_dump(include=vals_to_include)) + self._original_state["original_file_uuids"] = list(self.files.keys()) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + # Move any 'original' file that have been deleted back to files + original_file_uuids = self._original_state.pop("original_file_uuids") + for uuid in original_file_uuids: + if uuid in self.deleted_files: + self.files[uuid] = self.deleted_files.pop(uuid) + + # Clear any other deleted files that aren't original (have been created by agent) + self.deleted_files.clear() + + # Now clear all non-original files created by agent + current_file_uuids = list(self.files.keys()) + for uuid in current_file_uuids: + if uuid not in original_file_uuids: + self.files.pop(uuid) + + # Now reset all remaining files + for file in self.files.values(): + file.reset_component_for_episode(episode) + super().reset_component_for_episode(episode) + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request( diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 9fbafc29..cab983c7 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -43,6 +43,20 @@ class Network(SimComponent): self._nx_graph = MultiGraph() + def set_original_state(self): + """Sets the original state.""" + for node in self.nodes.values(): + node.set_original_state() + for link in self.links.values(): + link.set_original_state() + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + for node in self.nodes.values(): + node.reset_component_for_episode(episode) + for link in self.links.values(): + link.reset_component_for_episode(episode) + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() self._node_request_manager = RequestManager() diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 0717f813..2863dd22 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -121,6 +121,20 @@ class NIC(SimComponent): _LOGGER.error(msg) raise ValueError(msg) + self.set_original_state() + + def set_original_state(self): + """Sets the original state.""" + vals_to_include = {"ip_address", "subnet_mask", "mac_address", "speed", "mtu", "wake_on_lan", "enabled"} + self._original_state = self.model_dump(include=vals_to_include) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + super().reset_component_for_episode(episode) + if episode and self.pcap: + self.pcap.current_episode = episode + self.pcap.setup_logger() + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -308,6 +322,14 @@ class SwitchPort(SimComponent): kwargs["mac_address"] = generate_mac_address() super().__init__(**kwargs) + self.set_original_state() + + def set_original_state(self): + """Sets the original state.""" + vals_to_include = {"port_num", "mac_address", "speed", "mtu", "enabled"} + self._original_state = self.model_dump(include=vals_to_include) + super().set_original_state() + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -454,6 +476,14 @@ class Link(SimComponent): self.endpoint_b.connect_link(self) self.endpoint_up() + self.set_original_state() + + def set_original_state(self): + """Sets the original state.""" + vals_to_include = {"bandwidth", "current_load"} + self._original_state = self.model_dump(include=vals_to_include) + super().set_original_state() + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -536,15 +566,6 @@ class Link(SimComponent): return True return False - def reset_component_for_episode(self, episode: int): - """ - Link reset function. - - Reset: - - returns the link current_load to 0. - """ - self.current_load = 0 - def __str__(self) -> str: return f"{self.endpoint_a}<-->{self.endpoint_b}" @@ -584,6 +605,10 @@ class ARPCache: ) print(table) + def clear(self): + """Clears the arp cache.""" + self.arp.clear() + def add_arp_cache_entry(self, ip_address: IPv4Address, mac_address: str, nic: NIC, override: bool = False): """ Add an ARP entry to the cache. @@ -756,6 +781,10 @@ class ICMP: self.arp: ARPCache = arp_cache self.request_replies = {} + def clear(self): + """Clears the ICMP request replies tracker.""" + self.request_replies.clear() + def process_icmp(self, frame: Frame, from_nic: NIC, is_reattempt: bool = False): """ Process an ICMP packet, including handling echo requests and replies. @@ -972,6 +1001,55 @@ class Node(SimComponent): self.arp.nics = self.nics self.session_manager.software_manager = self.software_manager self._install_system_software() + self.set_original_state() + + def set_original_state(self): + """Sets the original state.""" + for software in self.software_manager.software.values(): + software.set_original_state() + + for nic in self.nics.values(): + nic.set_original_state() + + vals_to_include = { + "hostname", + "default_gateway", + "operating_state", + "revealed_to_red", + "start_up_duration", + "start_up_countdown", + "shut_down_duration", + "shut_down_countdown", + "is_resetting", + "node_scan_duration", + "node_scan_countdown", + "red_scan_countdown", + } + self._original_state = self.model_dump(include=vals_to_include) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + # Reset ARP Cache + self.arp.clear() + + # Reset ICMP + self.icmp.clear() + + # Reset Session Manager + self.session_manager.clear() + + for software in self.software_manager.software.values(): + software.reset_component_for_episode(episode) + + # Reset all Nics + for nic in self.nics.values(): + nic.reset_component_for_episode(episode) + + if episode and self.sys_log: + self.sys_log.current_episode = episode + self.sys_log.setup_logger() + + super().reset_component_for_episode(episode) def _init_request_manager(self) -> RequestManager: # TODO: I see that this code is really confusing and hard to read right now... I think some of these things will @@ -1005,9 +1083,6 @@ class Node(SimComponent): return rm - def reset_component_for_episode(self, episode: int): - self._init_request_manager() - def _install_system_software(self): """Install System Software - software that is usually provided with the OS.""" pass @@ -1425,99 +1500,3 @@ class Node(SimComponent): if isinstance(item, Service): return item.uuid in self.services return None - - -class Switch(Node): - """A class representing a Layer 2 network switch.""" - - num_ports: int = 24 - "The number of ports on the switch." - switch_ports: Dict[int, SwitchPort] = {} - "The SwitchPorts on the switch." - mac_address_table: Dict[str, SwitchPort] = {} - "A MAC address table mapping destination MAC addresses to corresponding SwitchPorts." - - def __init__(self, **kwargs): - super().__init__(**kwargs) - if not self.switch_ports: - self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)} - for port_num, port in self.switch_ports.items(): - port._connected_node = self - port.parent = self - port.port_num = port_num - - def show(self): - """Prints a table of the SwitchPorts on the Switch.""" - table = PrettyTable(["Port", "MAC Address", "Speed", "Status"]) - - for port_num, port in self.switch_ports.items(): - table.add_row([port_num, port.mac_address, port.speed, "Enabled" if port.enabled else "Disabled"]) - print(table) - - def describe_state(self) -> Dict: - """ - Produce a dictionary describing the current state of this object. - - Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - - :return: Current state of this object and child objects. - :rtype: Dict - """ - return { - "uuid": self.uuid, - "num_ports": self.num_ports, # redundant? - "ports": {port_num: port.describe_state() for port_num, port in self.switch_ports.items()}, - "mac_address_table": {mac: port for mac, port in self.mac_address_table.items()}, - } - - def _add_mac_table_entry(self, mac_address: str, switch_port: SwitchPort): - mac_table_port = self.mac_address_table.get(mac_address) - if not mac_table_port: - self.mac_address_table[mac_address] = switch_port - self.sys_log.info(f"Added MAC table entry: Port {switch_port.port_num} -> {mac_address}") - else: - if mac_table_port != switch_port: - self.mac_address_table.pop(mac_address) - self.sys_log.info(f"Removed MAC table entry: Port {mac_table_port.port_num} -> {mac_address}") - self._add_mac_table_entry(mac_address, switch_port) - - def forward_frame(self, frame: Frame, incoming_port: SwitchPort): - """ - Forward a frame to the appropriate port based on the destination MAC address. - - :param frame: The Frame to be forwarded. - :param incoming_port: The port number from which the frame was received. - """ - src_mac = frame.ethernet.src_mac_addr - dst_mac = frame.ethernet.dst_mac_addr - self._add_mac_table_entry(src_mac, incoming_port) - - outgoing_port = self.mac_address_table.get(dst_mac) - if outgoing_port or dst_mac != "ff:ff:ff:ff:ff:ff": - outgoing_port.send_frame(frame) - else: - # If the destination MAC is not in the table, flood to all ports except incoming - for port in self.switch_ports.values(): - if port != incoming_port: - port.send_frame(frame) - - def disconnect_link_from_port(self, link: Link, port_number: int): - """ - Disconnect a given link from the specified port number on the switch. - - :param link: The Link object to be disconnected. - :param port_number: The port number on the switch from where the link should be disconnected. - :raise NetworkError: When an invalid port number is provided or the link does not match the connection. - """ - port = self.switch_ports.get(port_number) - if port is None: - msg = f"Invalid port number {port_number} on the switch" - _LOGGER.error(msg) - raise NetworkError(msg) - - if port._connected_link != link: - msg = f"The link does not match the connection at port number {port_number}" - _LOGGER.error(msg) - raise NetworkError(msg) - - port.disconnect_link() diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index c2a38aba..8e03cfa3 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -52,6 +52,11 @@ class ACLRule(SimComponent): rule_strings.append(f"{key}={value}") return ", ".join(rule_strings) + def set_original_state(self): + """Sets the original state.""" + vals_to_keep = {"action", "protocol", "src_ip_address", "src_port", "dst_ip_address", "dst_port"} + self._original_state = self.model_dump(include=vals_to_keep, exclude_none=True) + def describe_state(self) -> Dict: """ Describes the current state of the ACLRule. @@ -93,6 +98,18 @@ class AccessControlList(SimComponent): super().__init__(**kwargs) self._acl = [None] * (self.max_acl_rules - 1) + self.set_original_state() + + def set_original_state(self): + """Sets the original state.""" + self.implicit_rule.set_original_state() + vals_to_keep = {"implicit_action", "max_acl_rules", "acl"} + self._original_state = self.model_dump(include=vals_to_keep, exclude_none=True) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + self.implicit_rule.reset_component_for_episode(episode) + super().reset_component_for_episode(episode) def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() @@ -638,6 +655,20 @@ class Router(Node): self.arp.nics = self.nics self.icmp.arp = self.arp + self.set_original_state() + + def set_original_state(self): + """Sets the original state.""" + self.acl.set_original_state() + vals_to_include = {"num_ports", "route_table"} + self._original_state = self.model_dump(include=vals_to_include) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + self.arp.clear() + self.acl.reset_component_for_episode(episode) + super().reset_component_for_episode(episode) + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request("acl", RequestType(func=self.acl._request_manager)) diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index 8e820ec8..c529ed04 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -9,7 +9,7 @@ class Simulation(SimComponent): """Top-level simulation object which holds a reference to all other parts of the simulation.""" network: Network - domain: DomainController + # domain: DomainController def __init__(self, **kwargs): """Initialise the Simulation.""" @@ -21,6 +21,14 @@ class Simulation(SimComponent): super().__init__(**kwargs) + def set_original_state(self): + """Sets the original state.""" + self.network.set_original_state() + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + self.network.reset_component_for_episode(episode) + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() # pass through network requests to the network objects diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 9a58c98a..c69f745d 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -38,6 +38,12 @@ class Application(IOSoftware): self.health_state_visible = SoftwareHealthState.UNUSED self.health_state_actual = SoftwareHealthState.UNUSED + def set_original_state(self): + """Sets the original state.""" + super().set_original_state() + vals_to_include = {"operating_state", "execution_control_status", "num_executions", "groups"} + self._original_state.update(self.model_dump(include=vals_to_include)) + @abstractmethod def describe_state(self) -> Dict: """ @@ -82,15 +88,6 @@ class Application(IOSoftware): self.sys_log.info(f"Installing Application {self.name}") self.operating_state = ApplicationOperatingState.INSTALLING - def reset_component_for_episode(self, episode: int): - """ - Resets the Application component for a new episode. - - This method ensures the Application is ready for a new episode, including resetting any - stateful properties or statistics, and clearing any message queues. - """ - pass - def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ Receives a payload from the SessionManager. diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 37236e69..12dfc0ac 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -31,6 +31,13 @@ class DatabaseClient(Application): kwargs["port"] = Port.POSTGRES_SERVER kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) + self.set_original_state() + + def set_original_state(self): + """Sets the original state.""" + super().set_original_state() + vals_to_include = {"server_ip_address", "server_password", "connected"} + self._original_state.update(self.model_dump(include=vals_to_include)) def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index ef9ac0e7..32dd9cd2 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -33,8 +33,15 @@ class WebBrowser(Application): kwargs["port"] = Port.HTTP super().__init__(**kwargs) + self.set_original_state() self.run() + def set_original_state(self): + """Sets the original state.""" + super().set_original_state() + vals_to_include = {"target_url", "domain_name_ip_address", "latest_response"} + self._original_state.update(self.model_dump(include=vals_to_include)) + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request( @@ -43,13 +50,6 @@ class WebBrowser(Application): return rm - def do_this(self): - self._init_request_manager() - print(f"Resetting WebBrowser for episode") - - def reset_component_for_episode(self, episode: int): - pass - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of the WebBrowser. @@ -60,14 +60,7 @@ class WebBrowser(Application): state["last_response_status_code"] = self.latest_response.status_code if self.latest_response else None def reset_component_for_episode(self, episode: int): - """ - Resets the Application component for a new episode. - - This method ensures the Application is ready for a new episode, including resetting any - stateful properties or statistics, and clearing any message queues. - """ - self.domain_name_ip_address = None - self.latest_response = None + """Reset the original state of the SimComponent.""" def get_webpage(self) -> bool: """ diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index c2faeb10..1539e024 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -34,9 +34,12 @@ class PacketCapture: "The IP address associated with the PCAP logs." self.switch_port_number = switch_port_number "The SwitchPort number." - self._setup_logger() - def _setup_logger(self): + self.current_episode: int = 1 + + self.setup_logger() + + def setup_logger(self): """Set up the logger configuration.""" log_path = self._get_log_path() @@ -75,7 +78,7 @@ class PacketCapture: def _get_log_path(self) -> Path: """Get the path for the log file.""" - root = SIM_OUTPUT.path / self.hostname + root = SIM_OUTPUT.path / f"episode_{self.current_episode}" / self.hostname root.mkdir(exist_ok=True, parents=True) return root / f"{self._logger_name}.log" diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 360b5e73..8658f155 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -93,6 +93,11 @@ class SessionManager: """ pass + def clear(self): + """Clears the sessions.""" + self.sessions_by_key.clear() + self.sessions_by_uuid.clear() + @staticmethod def _get_session_key( frame: Frame, inbound_frame: bool = True diff --git a/src/primaite/simulator/system/core/sys_log.py b/src/primaite/simulator/system/core/sys_log.py index 7ac6df85..41ce8fee 100644 --- a/src/primaite/simulator/system/core/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -31,9 +31,10 @@ class SysLog: :param hostname: The hostname associated with the system logs being recorded. """ self.hostname = hostname - self._setup_logger() + self.current_episode: int = 1 + self.setup_logger() - def _setup_logger(self): + def setup_logger(self): """ Configures the logger for this SysLog instance. @@ -80,7 +81,7 @@ class SysLog: :return: Path object representing the location of the log file. """ - root = SIM_OUTPUT.path / self.hostname + root = SIM_OUTPUT.path / f"episode_{self.current_episode}" / self.hostname root.mkdir(exist_ok=True, parents=True) return root / f"{self.hostname}_sys.log" diff --git a/src/primaite/simulator/system/processes/process.py b/src/primaite/simulator/system/processes/process.py index c4e94845..ad9af335 100644 --- a/src/primaite/simulator/system/processes/process.py +++ b/src/primaite/simulator/system/processes/process.py @@ -24,6 +24,12 @@ class Process(Software): operating_state: ProcessOperatingState "The current operating state of the Process." + def set_original_state(self): + """Sets the original state.""" + super().set_original_state() + vals_to_include = {"operating_state"} + self._original_state.update(self.model_dump(include=vals_to_include)) + @abstractmethod def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index d7277e1e..616cbedd 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -38,6 +38,23 @@ class DatabaseService(Service): self._db_file: File self._create_db_file() + def set_original_state(self): + """Sets the original state.""" + super().set_original_state() + vals_to_include = { + "password", + "connections", + "backup_server", + "latest_backup_directory", + "latest_backup_file_name", + } + self._original_state.update(self.model_dump(include=vals_to_include)) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + self.connections.clear() + super().reset_component_for_episode(episode) + def configure_backup(self, backup_server: IPv4Address): """ Set up the database backup. diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 266ac4f6..c6c3e09a 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -29,6 +29,17 @@ class DNSClient(Service): super().__init__(**kwargs) self.start() + def set_original_state(self): + """Sets the original state.""" + super().set_original_state() + vals_to_include = {"dns_server"} + self._original_state.update(self.model_dump(include=vals_to_include)) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + self.dns_cache.clear() + super().reset_component_for_episode(episode) + def describe_state(self) -> Dict: """ Describes the current state of the software. @@ -42,15 +53,6 @@ class DNSClient(Service): state = super().describe_state() return state - def reset_component_for_episode(self, episode: int): - """ - Resets the Service component for a new episode. - - This method ensures the Service is ready for a new episode, including resetting any - stateful properties or statistics, and clearing any message queues. - """ - pass - def add_domain_to_cache(self, domain_name: str, ip_address: IPv4Address): """ Adds a domain name to the DNS Client cache. diff --git a/src/primaite/simulator/system/services/dns/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py index 90a350c8..bbeaa62c 100644 --- a/src/primaite/simulator/system/services/dns/dns_server.py +++ b/src/primaite/simulator/system/services/dns/dns_server.py @@ -28,6 +28,11 @@ class DNSServer(Service): super().__init__(**kwargs) self.start() + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + self.dns_table.clear() + super().reset_component_for_episode(episode) + def describe_state(self) -> Dict: """ Describes the current state of the software. @@ -62,15 +67,6 @@ class DNSServer(Service): """ self.dns_table[domain_name] = domain_ip_address - def reset_component_for_episode(self, episode: int): - """ - Resets the Service component for a new episode. - - This method ensures the Service is ready for a new episode, including resetting any - stateful properties or statistics, and clearing any message queues. - """ - pass - def receive( self, payload: Any, diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index e2b04c15..d519da8e 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -46,6 +46,12 @@ class Service(IOSoftware): self.health_state_visible = SoftwareHealthState.UNUSED self.health_state_actual = SoftwareHealthState.UNUSED + def set_original_state(self): + """Sets the original state.""" + super().set_original_state() + vals_to_include = {"operating_state", "restart_duration", "restart_countdown"} + self._original_state.update(self.model_dump(include=vals_to_include)) + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request("scan", RequestType(func=lambda request, context: self.scan())) @@ -73,15 +79,6 @@ class Service(IOSoftware): state["health_state_visible"] = self.health_state_visible return state - def reset_component_for_episode(self, episode: int): - """ - Resets the Service component for a new episode. - - This method ensures the Service is ready for a new episode, including resetting any - stateful properties or statistics, and clearing any message queues. - """ - pass - def stop(self) -> None: """Stop the service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index 86a4e4f1..754aa22f 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -19,8 +19,14 @@ class WebServer(Service): _last_response_status_code: Optional[HttpStatusCode] = None + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + self._last_response_status_code = None + super().reset_component_for_episode(episode) + @property def last_response_status_code(self) -> HttpStatusCode: + """The latest http response code.""" return self._last_response_status_code @last_response_status_code.setter @@ -41,14 +47,6 @@ class WebServer(Service): state["last_response_status_code"] = ( self.last_response_status_code.value if isinstance(self.last_response_status_code, HttpStatusCode) else None ) - - print( - f"" - f"Printing state from Webserver describe func: " - f"val={state['last_response_status_code']}, " - f"type={type(state['last_response_status_code'])}, " - f"Service obj ID={id(self)}" - ) return state def __init__(self, **kwargs): @@ -102,13 +100,6 @@ class WebServer(Service): # return true if response is OK self.last_response_status_code = response.status_code - print( - f"" - f"Printing state from Webserver http request func: " - f"val={self.last_response_status_code}, " - f"type={type(self.last_response_status_code)}, " - f"Service obj ID={id(self)}" - ) return response.status_code == HttpStatusCode.OK def _handle_get_request(self, payload: HttpRequestPacket) -> HttpResponsePacket: diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index f2627557..413da959 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -89,6 +89,19 @@ class Software(SimComponent): folder: Optional[Folder] = None "The folder on the file system the Software uses." + def set_original_state(self): + """Sets the original state.""" + vals_to_include = { + "name", + "health_state_actual", + "health_state_visible", + "criticality", + "patching_count", + "scanning_count", + "revealed_to_red", + } + self._original_state = self.model_dump(include=vals_to_include) + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request( @@ -131,16 +144,6 @@ class Software(SimComponent): ) return state - def reset_component_for_episode(self, episode: int): - """ - Resets the software component for a new episode. - - This method should ensure the software is ready for a new episode, including resetting any - stateful properties or statistics, and clearing any message queues. The specifics of what constitutes a - "reset" should be implemented in subclasses. - """ - pass - def set_health_state(self, health_state: SoftwareHealthState) -> None: """ Assign a new health state to this software. @@ -203,6 +206,12 @@ class IOSoftware(Software): port: Port "The port to which the software is connected." + def set_original_state(self): + """Sets the original state.""" + super().set_original_state() + vals_to_include = {"installing_count", "max_sessions", "tcp", "udp", "port"} + self._original_state.update(self.model_dump(include=vals_to_include)) + @abstractmethod def describe_state(self) -> Dict: """ From 39dfbb741f53fbd43c25e43cd7c5dcbad153c29e Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 28 Nov 2023 00:21:41 +0000 Subject: [PATCH 394/980] #1859 - Made some fixes to resets. Still an issue with the Router reset. --- src/primaite/simulator/network/hardware/base.py | 1 + .../simulator/network/hardware/nodes/router.py | 4 ++++ .../simulator/system/services/dns/dns_server.py | 11 +++++++++++ .../system/services/web_server/web_server.py | 3 +-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 2863dd22..09e2b12f 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -134,6 +134,7 @@ class NIC(SimComponent): if episode and self.pcap: self.pcap.current_episode = episode self.pcap.setup_logger() + self.enable() def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 8e03cfa3..1bf2ea2f 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -667,6 +667,10 @@ class Router(Node): """Reset the original state of the SimComponent.""" self.arp.clear() self.acl.reset_component_for_episode(episode) + for i, nic in self.ethernet_ports.items(): + nic.reset_component_for_episode(episode) + self.enable_port(i) + super().reset_component_for_episode(episode) def _init_request_manager(self) -> RequestManager: diff --git a/src/primaite/simulator/system/services/dns/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py index bbeaa62c..3b1f3bf6 100644 --- a/src/primaite/simulator/system/services/dns/dns_server.py +++ b/src/primaite/simulator/system/services/dns/dns_server.py @@ -28,10 +28,21 @@ class DNSServer(Service): super().__init__(**kwargs) self.start() + def set_original_state(self): + """Sets the original state.""" + super().set_original_state() + vals_to_include = {"dns_table"} + self._original_state["dns_table_orig"] = self.model_dump(include=vals_to_include)["dns_table"] + def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" + print("dns reset") + print("DNSServer original state", self._original_state) self.dns_table.clear() + for key, value in self._original_state["dns_table_orig"].items(): + self.dns_table[key] = value super().reset_component_for_episode(episode) + self.show() def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index 754aa22f..56f47195 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -31,7 +31,6 @@ class WebServer(Service): @last_response_status_code.setter def last_response_status_code(self, val: Any): - print(f"val: {val}, type: {type(val)}") self._last_response_status_code = val def describe_state(self) -> Dict: @@ -47,6 +46,7 @@ class WebServer(Service): state["last_response_status_code"] = ( self.last_response_status_code.value if isinstance(self.last_response_status_code, HttpStatusCode) else None ) + print(state) return state def __init__(self, **kwargs): @@ -99,7 +99,6 @@ class WebServer(Service): # return true if response is OK self.last_response_status_code = response.status_code - return response.status_code == HttpStatusCode.OK def _handle_get_request(self, payload: HttpRequestPacket) -> HttpResponsePacket: From 37663c941d4ba4345216548e6f47fc0d58abf987 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 28 Nov 2023 00:51:48 +0000 Subject: [PATCH 395/980] #1859 - Added route table reset, still not working --- .../network/hardware/nodes/router.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 1bf2ea2f..667cf2bf 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -354,6 +354,11 @@ class RouteEntry(SimComponent): kwargs[key] = IPv4Address(kwargs[key]) super().__init__(**kwargs) + def set_original_state(self): + """Sets the original state.""" + vals_to_include = {"address", "subnet_mask", "next_hop_ip_address", "metric"} + self._original_values = self.model_dump(include=vals_to_include) + def describe_state(self) -> Dict: """ Describes the current state of the RouteEntry. @@ -385,6 +390,18 @@ class RouteTable(SimComponent): routes: List[RouteEntry] = [] sys_log: SysLog + def set_original_state(self): + """Sets the original state.""" + """Sets the original state.""" + super().set_original_state() + self._original_state["routes_orig"] = self.routes + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + self.routes.clear() + self.routes = self._original_state["routes_orig"] + super().reset_component_for_episode(episode) + def describe_state(self) -> Dict: """ Describes the current state of the RouteTable. @@ -660,13 +677,15 @@ class Router(Node): def set_original_state(self): """Sets the original state.""" self.acl.set_original_state() - vals_to_include = {"num_ports", "route_table"} + self.route_table.set_original_state() + vals_to_include = {"num_ports"} self._original_state = self.model_dump(include=vals_to_include) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" self.arp.clear() self.acl.reset_component_for_episode(episode) + self.route_table.reset_component_for_episode(episode) for i, nic in self.ethernet_ports.items(): nic.reset_component_for_episode(episode) self.enable_port(i) @@ -765,6 +784,7 @@ class Router(Node): dst_ip_address=dst_ip_address, dst_port=dst_port, ) + if not permitted: at_port = self._get_port_of_nic(from_nic) self.sys_log.info(f"Frame blocked at port {at_port} by rule {rule}") From 517f99b04b9e8c2792ad70768a5e3bfa65f9e88a Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 28 Nov 2023 09:45:45 +0000 Subject: [PATCH 396/980] #1859 - Added the call to file system reset --- src/primaite/simulator/network/hardware/base.py | 7 +++++++ src/primaite/simulator/network/hardware/nodes/router.py | 1 + 2 files changed, 8 insertions(+) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 09e2b12f..cb159b8b 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1009,6 +1009,8 @@ class Node(SimComponent): for software in self.software_manager.software.values(): software.set_original_state() + self.file_system.set_original_state() + for nic in self.nics.values(): nic.set_original_state() @@ -1039,13 +1041,18 @@ class Node(SimComponent): # Reset Session Manager self.session_manager.clear() + # Reset software for software in self.software_manager.software.values(): software.reset_component_for_episode(episode) + # Reset File System + self.file_system.reset_component_for_episode(episode) + # Reset all Nics for nic in self.nics.values(): nic.reset_component_for_episode(episode) + # if episode and self.sys_log: self.sys_log.current_episode = episode self.sys_log.setup_logger() diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 667cf2bf..34b92a07 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -818,6 +818,7 @@ class Router(Node): nic.ip_address = ip_address nic.subnet_mask = subnet_mask self.sys_log.info(f"Configured port {port} with ip_address={ip_address}/{nic.ip_network.prefixlen}") + self.set_original_state() def enable_port(self, port: int): """ From b0399195bbddfce87d6b9c032462c2944a920232 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 27 Nov 2023 22:20:44 +0000 Subject: [PATCH 397/980] Fix software manager usage in uc2 network func --- src/primaite/simulator/network/networks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 446e5649..b7bd2e95 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -157,7 +157,7 @@ def arcd_uc2_network() -> Network: operating_state=NodeOperatingState.ON, ) client_2.power_on() - web_browser = client_2.software_manager["WebBrowser"] + web_browser = client_2.software_manager.software["WebBrowser"] web_browser.target_url = "http://arcd.com/users/" network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) From 3df3e113d1320b1eed9d7f76a3591a80d7e68c02 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 27 Nov 2023 22:24:30 +0000 Subject: [PATCH 398/980] Change data manipulation test to use the right func --- .../e2e_integration_tests/test_uc2_data_manipulation_scenario.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index fe7bab5f..81bbfc96 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -23,7 +23,6 @@ def test_data_manipulation(uc2_network): # Now we run the DataManipulationBot db_manipulation_bot.run() - db_manipulation_bot.attack() # Now check that the DB client on the web_server cannot query the users table on the database assert not db_client.query("SELECT") From 2de1d02c48805efaed3dfd26d21d56fcc12a7263 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 27 Nov 2023 22:55:00 +0000 Subject: [PATCH 399/980] Fix app install logic --- src/primaite/simulator/system/applications/application.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 4fe7a5e1..898e5917 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -108,9 +108,6 @@ class Application(IOSoftware): def install(self) -> None: """Install Application.""" - if self._can_perform_action(): - return - super().install() if self.operating_state == ApplicationOperatingState.CLOSED: self.sys_log.info(f"Installing Application {self.name}") From 9a4855e7bd448aeebcaccbf6980cea4c7d60c933 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 28 Nov 2023 11:58:09 +0000 Subject: [PATCH 400/980] #1859 - Added the call to file system reset --- src/primaite/simulator/file_system/file.py | 2 ++ .../simulator/file_system/file_system.py | 9 +++++++-- src/primaite/simulator/file_system/folder.py | 2 ++ .../simulator/network/hardware/base.py | 11 +++++++++- .../network/hardware/nodes/router.py | 3 ++- .../system/applications/database_client.py | 6 ++++++ .../system/applications/web_browser.py | 6 ++++++ .../services/database/database_service.py | 2 ++ .../system/services/dns/dns_client.py | 11 ++-------- .../system/services/dns/dns_server.py | 5 ++--- .../system/services/ftp/ftp_client.py | 12 +++++++++++ .../system/services/ftp/ftp_server.py | 13 ++++++++++++ .../red_services/data_manipulation_bot.py | 20 +++++++++++++++++++ .../system/services/web_server/web_server.py | 20 +++++++++---------- 14 files changed, 95 insertions(+), 27 deletions(-) diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index 8f0abb3c..f0984f89 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -77,12 +77,14 @@ class File(FileSystemItemABC): def set_original_state(self): """Sets the original state.""" + print(f"Setting File ({self.path}) original state on node {self.sys_log.hostname}") super().set_original_state() vals_to_include = {"folder_id", "folder_name", "file_type", "sim_size", "real", "sim_path", "sim_root"} self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" + print(f"Resetting File ({self.path}) state on node {self.sys_log.hostname}") super().reset_component_for_episode(episode) @property diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index dc6f01a3..a6876786 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -37,15 +37,20 @@ class FileSystem(SimComponent): def set_original_state(self): """Sets the original state.""" + print(f"Setting FileSystem original state on node {self.sys_log.hostname}") for folder in self.folders.values(): folder.set_original_state() - super().set_original_state() # Capture a list of all 'original' file uuids - self._original_state["original_folder_uuids"] = list(self.folders.keys()) + original_keys = list(self.folders.keys()) + vals_to_include = {"sim_root"} + self._original_state.update(self.model_dump(include=vals_to_include)) + self._original_state["original_folder_uuids"] = original_keys def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" + print(f"Resetting FileSystem state on node {self.sys_log.hostname}") # Move any 'original' folder that have been deleted back to folders + print(self._original_state) original_folder_uuids = self._original_state.pop("original_folder_uuids") for uuid in original_folder_uuids: if uuid in self.deleted_folders: diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 8e577097..24dbdd79 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -53,6 +53,7 @@ class Folder(FileSystemItemABC): def set_original_state(self): """Sets the original state.""" + print(f"Setting Folder ({self.name}) original state on node {self.sys_log.hostname}") for file in self.files.values(): file.set_original_state() super().set_original_state() @@ -69,6 +70,7 @@ class Folder(FileSystemItemABC): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" + print(f"Resetting Folder ({self.name}) state on node {self.sys_log.hostname}") # Move any 'original' file that have been deleted back to files original_file_uuids = self._original_state.pop("original_file_uuids") for uuid in original_file_uuids: diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index c6ee373e..b72fde54 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -993,6 +993,7 @@ class Node(SimComponent): def set_original_state(self): """Sets the original state.""" + print(f"Setting node original state for {self.hostname}") for software in self.software_manager.software.values(): software.set_original_state() @@ -1019,6 +1020,7 @@ class Node(SimComponent): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" + print(f"Resetting node state for {self.hostname}") # Reset ARP Cache self.arp.clear() @@ -1031,6 +1033,10 @@ class Node(SimComponent): # Reset software for software in self.software_manager.software.values(): software.reset_component_for_episode(episode) + if isinstance(software, Service): + software.start() + elif isinstance(software, Application): + software.run() # Reset File System self.file_system.reset_component_for_episode(episode) @@ -1039,13 +1045,16 @@ class Node(SimComponent): for nic in self.nics.values(): nic.reset_component_for_episode(episode) - # if episode and self.sys_log: self.sys_log.current_episode = episode self.sys_log.setup_logger() super().reset_component_for_episode(episode) + self.power_on() + for nic in self.nics.values(): + nic.enable() + def _init_request_manager(self) -> RequestManager: # TODO: I see that this code is really confusing and hard to read right now... I think some of these things will # need a better name and better documentation. diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 34b92a07..0017215a 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -678,8 +678,9 @@ class Router(Node): """Sets the original state.""" self.acl.set_original_state() self.route_table.set_original_state() + super().set_original_state() vals_to_include = {"num_ports"} - self._original_state = self.model_dump(include=vals_to_include) + self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 37f85b28..92f7e76d 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -35,10 +35,16 @@ class DatabaseClient(Application): def set_original_state(self): """Sets the original state.""" + print(f"Setting DatabaseClient WebServer original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = {"server_ip_address", "server_password", "connected"} self._original_state.update(self.model_dump(include=vals_to_include)) + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + print(f"Resetting DataBaseClient state on node {self.software_manager.node.hostname}") + super().reset_component_for_episode(episode) + def describe_state(self) -> Dict: """ Describes the current state of the ACLRule. diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index bf304d7b..88560240 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -43,10 +43,16 @@ class WebBrowser(Application): def set_original_state(self): """Sets the original state.""" + print(f"Setting WebBrowser original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = {"target_url", "domain_name_ip_address", "latest_response"} self._original_state.update(self.model_dump(include=vals_to_include)) + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + print(f"Resetting WebBrowser state on node {self.software_manager.node.hostname}") + super().reset_component_for_episode(episode) + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request( diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 45e469fb..925d1df0 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -40,6 +40,7 @@ class DatabaseService(Service): def set_original_state(self): """Sets the original state.""" + print(f"Setting DatabaseService original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = { "password", @@ -52,6 +53,7 @@ class DatabaseService(Service): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" + print("Resetting DatabaseService original state on node {self.software_manager.node.hostname}") self.connections.clear() super().reset_component_for_episode(episode) diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 3d425bfa..147387ae 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -31,12 +31,14 @@ class DNSClient(Service): def set_original_state(self): """Sets the original state.""" + print(f"Setting DNSClient original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = {"dns_server"} self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" + print(f"Resetting DNSClient state on node {self.software_manager.node.hostname}") self.dns_cache.clear() super().reset_component_for_episode(episode) @@ -53,15 +55,6 @@ class DNSClient(Service): state = super().describe_state() return state - def reset_component_for_episode(self, episode: int): - """ - Resets the Service component for a new episode. - - This method ensures the Service is ready for a new episode, including resetting any - stateful properties or statistics, and clearing any message queues. - """ - pass - def add_domain_to_cache(self, domain_name: str, ip_address: IPv4Address) -> bool: """ Adds a domain name to the DNS Client cache. diff --git a/src/primaite/simulator/system/services/dns/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py index 30278ab1..7842a07e 100644 --- a/src/primaite/simulator/system/services/dns/dns_server.py +++ b/src/primaite/simulator/system/services/dns/dns_server.py @@ -30,19 +30,18 @@ class DNSServer(Service): def set_original_state(self): """Sets the original state.""" + print(f"Setting DNSServer original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = {"dns_table"} self._original_state["dns_table_orig"] = self.model_dump(include=vals_to_include)["dns_table"] def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print("dns reset") - print("DNSServer original state", self._original_state) + print(f"Resetting DNSServer state on node {self.software_manager.node.hostname}") self.dns_table.clear() for key, value in self._original_state["dns_table_orig"].items(): self.dns_table[key] = value super().reset_component_for_episode(episode) - self.show() def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 649b9b50..011b597f 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -28,6 +28,18 @@ class FTPClient(FTPServiceABC): super().__init__(**kwargs) self.start() + def set_original_state(self): + """Sets the original state.""" + print(f"Setting FTPClient original state on node {self.software_manager.node.hostname}") + super().set_original_state() + vals_to_include = {"connected"} + self._original_state.update(self.model_dump(include=vals_to_include)) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + print(f"Resetting FTPClient state on node {self.software_manager.node.hostname}") + super().reset_component_for_episode(episode) + def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: """ Process the command in the FTP Packet. diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index cd128339..811a8939 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -29,6 +29,19 @@ class FTPServer(FTPServiceABC): super().__init__(**kwargs) self.start() + def set_original_state(self): + """Sets the original state.""" + print(f"Setting FTPServer original state on node {self.software_manager.node.hostname}") + super().set_original_state() + vals_to_include = {"server_password"} + self._original_state.update(self.model_dump(include=vals_to_include)) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + print(f"Resetting FTPServer state on node {self.software_manager.node.hostname}") + self.connections.clear() + super().reset_component_for_episode(episode) + def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: """ Process the command in the FTP Packet. diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index b0b34396..75cdee85 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -47,6 +47,26 @@ class DataManipulationBot(DatabaseClient): super().__init__(**kwargs) self.name = "DataManipulationBot" + def set_original_state(self): + """Sets the original state.""" + print(f"Setting DataManipulationBot original state on node {self.software_manager.node.hostname}") + super().set_original_state() + vals_to_include = { + "server_ip_address", + "payload", + "server_password", + "port_scan_p_of_success", + "data_manipulation_p_of_success", + "attack_stage", + "repeat", + } + self._original_state.update(self.model_dump(include=vals_to_include)) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + print(f"Resetting DataManipulationBot state on node {self.software_manager.node.hostname}") + super().reset_component_for_episode(episode) + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index becbf9f9..f34bba37 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -17,22 +17,20 @@ from primaite.simulator.system.services.service import Service class WebServer(Service): """Class used to represent a Web Server Service in simulation.""" - _last_response_status_code: Optional[HttpStatusCode] = None + last_response_status_code: Optional[HttpStatusCode] = None + + def set_original_state(self): + """Sets the original state.""" + print(f"Setting WebServer original state on node {self.software_manager.node.hostname}") + super().set_original_state() + vals_to_include = {"last_response_status_code"} + self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - self._last_response_status_code = None + print(f"Resetting WebServer state on node {self.software_manager.node.hostname}") super().reset_component_for_episode(episode) - @property - def last_response_status_code(self) -> HttpStatusCode: - """The latest http response code.""" - return self._last_response_status_code - - @last_response_status_code.setter - def last_response_status_code(self, val: Any): - self._last_response_status_code = val - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. From 2eeb896099145167f493825f893598535439f7af Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 28 Nov 2023 12:16:04 +0000 Subject: [PATCH 401/980] #2085 - Dump describe_state output to JSON file. --- src/primaite/game/game.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 38e9d5fc..4e896987 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -1,4 +1,6 @@ """PrimAITE game - Encapsulates the simulation and agents.""" +import json +from datetime import datetime from ipaddress import IPv4Address from typing import Dict, List @@ -10,6 +12,7 @@ from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent, RandomAgent from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction +from primaite.session.io import generate_session_path from primaite.simulator.network.hardware.base import NIC, NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router @@ -107,6 +110,13 @@ class PrimaiteGame: # Get the current state of the simulation sim_state = self.get_sim_state() + # Create state suitable for dumping to JSON file. + dump_state = {self.episode_counter: {self.step_counter: sim_state}} + json_path = generate_session_path(datetime.now()) / "describe_state.json" + # Dump to file + with open(json_path, "a") as f: + json.dump(dump_state, f) + # Update agents' observations and rewards based on the current state self.update_agents(sim_state) From e63727fa3ad0fcd58e1943abe65f1acd521da158 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 28 Nov 2023 14:12:01 +0000 Subject: [PATCH 402/980] #2058 - Fix up log file path --- src/primaite/__init__.py | 5 +++++ src/primaite/game/game.py | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/primaite/__init__.py b/src/primaite/__init__.py index 28245d33..1e5fe925 100644 --- a/src/primaite/__init__.py +++ b/src/primaite/__init__.py @@ -38,6 +38,7 @@ class _PrimaitePaths: self.app_config_file_path = self.generate_app_config_file_path() self.app_log_dir_path = self.generate_app_log_dir_path() self.app_log_file_path = self.generate_app_log_file_path() + self.episode_steps_log_file_path = self.generate_episode_step_log_file_path() def _get_dirs_properties(self) -> List[str]: class_items = self.__class__.__dict__.items() @@ -105,6 +106,10 @@ class _PrimaitePaths: """The PrimAITE app log file path.""" return self.app_log_dir_path / "primaite.log" + def generate_episode_step_log_file_path(self) -> Path: + """The PrimAITE app episode step log file path.""" + return self.app_log_dir_path / "epi_step.json" + def __repr__(self) -> str: properties_str = ", ".join([f"{p}='{getattr(self, p)}'" for p in self._get_dirs_properties()]) return f"{self.__class__.__name__}({properties_str})" diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 4e896987..3409100e 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -1,18 +1,17 @@ """PrimAITE game - Encapsulates the simulation and agents.""" import json -from datetime import datetime +import os from ipaddress import IPv4Address from typing import Dict, List from pydantic import BaseModel, ConfigDict -from primaite import getLogger +from primaite import getLogger, PRIMAITE_PATHS from primaite.game.agent.actions import ActionManager from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent, RandomAgent from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction -from primaite.session.io import generate_session_path from primaite.simulator.network.hardware.base import NIC, NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router @@ -112,10 +111,10 @@ class PrimaiteGame: # Create state suitable for dumping to JSON file. dump_state = {self.episode_counter: {self.step_counter: sim_state}} - json_path = generate_session_path(datetime.now()) / "describe_state.json" # Dump to file - with open(json_path, "a") as f: - json.dump(dump_state, f) + if os.path.isfile(PRIMAITE_PATHS.episode_steps_log_file_path): + with open(PRIMAITE_PATHS.episode_steps_log_file_path, "a") as f: + json.dump(dump_state, f) # Update agents' observations and rewards based on the current state self.update_agents(sim_state) From 94f8a45a4dcaa162cb73ba9d04bfd6718e57b8ec Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 28 Nov 2023 15:29:13 +0000 Subject: [PATCH 403/980] #1859 - Re-ordered the node reset function --- .../simulator/network/hardware/base.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index b72fde54..825df37d 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1021,6 +1021,8 @@ class Node(SimComponent): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" print(f"Resetting node state for {self.hostname}") + super().reset_component_for_episode(episode) + # Reset ARP Cache self.arp.clear() @@ -1030,17 +1032,11 @@ class Node(SimComponent): # Reset Session Manager self.session_manager.clear() - # Reset software - for software in self.software_manager.software.values(): - software.reset_component_for_episode(episode) - if isinstance(software, Service): - software.start() - elif isinstance(software, Application): - software.run() - # Reset File System self.file_system.reset_component_for_episode(episode) + self.power_on() + # Reset all Nics for nic in self.nics.values(): nic.reset_component_for_episode(episode) @@ -1049,9 +1045,14 @@ class Node(SimComponent): self.sys_log.current_episode = episode self.sys_log.setup_logger() - super().reset_component_for_episode(episode) + # Reset software + for software in self.software_manager.software.values(): + software.reset_component_for_episode(episode) + if isinstance(software, Service): + software.start() + elif isinstance(software, Application): + software.run() - self.power_on() for nic in self.nics.values(): nic.enable() From 19d534395be056a5896c6e45c82fb05cac256fea Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 29 Nov 2023 01:28:40 +0000 Subject: [PATCH 404/980] #2084: beginning the introduction of code coverage + adding tests to try to meet the 80% code coverage target --- .azure/azure-ci-build-pipeline.yaml | 4 +- .../simulator/file_system/file_system.py | 7 +- src/primaite/simulator/file_system/folder.py | 7 +- .../system/services/ftp/ftp_client.py | 7 +- .../system/services/ftp/ftp_server.py | 10 +- tests/conftest.py | 34 ++++- .../environments/test_sb3_environment.py | 2 + .../test_primaite_session.py | 1 + .../network/test_link_connection.py | 6 + .../system/test_dns_client_server.py | 50 +++++-- .../system/test_ftp_client_server.py | 70 +++++---- .../system/test_web_client_server.py | 135 ++++++++++-------- .../test_web_client_server_and_database.py | 106 ++++++++++++++ .../_file_system/test_file_system.py | 32 +++++ .../_system/_applications/test_web_browser.py | 51 +++++-- .../{test_dns.py => test_dns_client.py} | 61 +------- .../_system/_services/test_dns_server.py | 64 +++++++++ .../_system/_services/test_ftp_client.py | 50 +++++++ .../{test_ftp.py => test_ftp_server.py} | 58 ++++---- 19 files changed, 533 insertions(+), 222 deletions(-) create mode 100644 tests/integration_tests/system/test_web_client_server_and_database.py rename tests/unit_tests/_primaite/_simulator/_system/_services/{test_dns.py => test_dns_client.py} (65%) create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py rename tests/unit_tests/_primaite/_simulator/_system/_services/{test_ftp.py => test_ftp_server.py} (63%) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 9070270a..49d76937 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -86,5 +86,5 @@ stages: displayName: 'Perform PrimAITE Setup' - script: | - pytest -n auto - displayName: 'Run tests' + pytest -n auto --cov=src --cov-report=html:coverage_report --cov-fail-under=80 + displayName: 'Run tests and code coverage' diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index dc6f01a3..d61b62d4 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -49,7 +49,10 @@ class FileSystem(SimComponent): original_folder_uuids = self._original_state.pop("original_folder_uuids") for uuid in original_folder_uuids: if uuid in self.deleted_folders: - self.folders[uuid] = self.deleted_folders.pop(uuid) + folder = self.deleted_folders[uuid] + self.deleted_folders.pop(uuid) + self.folders[uuid] = folder + self._folders_by_name[folder.name] = folder # Clear any other deleted folders that aren't original (have been created by agent) self.deleted_folders.clear() @@ -58,7 +61,9 @@ class FileSystem(SimComponent): current_folder_uuids = list(self.folders.keys()) for uuid in current_folder_uuids: if uuid not in original_folder_uuids: + folder = self.folders[uuid] self.folders.pop(uuid) + self._folders_by_name.pop(folder.name) # Now reset all remaining folders for folder in self.folders.values(): diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 8e577097..a4907299 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -73,7 +73,10 @@ class Folder(FileSystemItemABC): original_file_uuids = self._original_state.pop("original_file_uuids") for uuid in original_file_uuids: if uuid in self.deleted_files: - self.files[uuid] = self.deleted_files.pop(uuid) + file = self.deleted_files[uuid] + self.deleted_files.pop(uuid) + self.files[uuid] = file + self._files_by_name[file.name] = file # Clear any other deleted files that aren't original (have been created by agent) self.deleted_files.clear() @@ -82,7 +85,9 @@ class Folder(FileSystemItemABC): current_file_uuids = list(self.files.keys()) for uuid in current_file_uuids: if uuid not in original_file_uuids: + file = self.files[uuid] self.files.pop(uuid) + self._files_by_name.pop(file.name) # Now reset all remaining files for file in self.files.values(): diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 649b9b50..b73eec7e 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -7,7 +7,6 @@ from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC -from primaite.simulator.system.services.service import ServiceOperatingState class FTPClient(FTPServiceABC): @@ -38,8 +37,7 @@ class FTPClient(FTPServiceABC): :type: session_id: Optional[str] """ # if client service is down, return error - if self.operating_state != ServiceOperatingState.RUNNING: - self.sys_log.error("FTP Client is not running") + if not self._can_perform_action(): payload.status_code = FTPStatusCode.ERROR return payload @@ -66,8 +64,7 @@ class FTPClient(FTPServiceABC): :type: is_reattempt: Optional[bool] """ # make sure the service is running before attempting - if self.operating_state != ServiceOperatingState.RUNNING: - self.sys_log.error(f"FTPClient not running for {self.sys_log.hostname}") + if not self._can_perform_action(): return False # normally FTP will choose a random port for the transfer, but using the FTP command port will do for now diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index cd128339..c40aaa5a 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -5,7 +5,6 @@ from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPS from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC -from primaite.simulator.system.services.service import ServiceOperatingState class FTPServer(FTPServiceABC): @@ -42,8 +41,7 @@ class FTPServer(FTPServiceABC): payload.status_code = FTPStatusCode.ERROR # if server service is down, return error - if self.operating_state != ServiceOperatingState.RUNNING: - self.sys_log.error("FTP Server not running") + if not self._can_perform_action(): return payload self.sys_log.info(f"{self.name}: Received FTP {payload.ftp_command.name} {payload.ftp_command_args}") @@ -79,6 +77,9 @@ class FTPServer(FTPServiceABC): self.sys_log.error(f"{payload} is not an FTP packet") return False + if not super().receive(payload=payload, session_id=session_id, **kwargs): + return False + """ Ignore ftp payload if status code is defined. @@ -86,9 +87,6 @@ class FTPServer(FTPServiceABC): prevents an FTP request loop - FTP client and servers can exist on the same node. """ - if not super().receive(payload=payload, session_id=session_id, **kwargs): - return False - if payload.status_code is not None: return False diff --git a/tests/conftest.py b/tests/conftest.py index c0d05455..8a1f885c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK from pathlib import Path -from typing import Any, Dict, Union +from typing import Any, Dict, Tuple, Union import pytest import yaml @@ -12,6 +12,9 @@ from primaite.session.session import PrimaiteSession # from primaite.environment.primaite_env import Primaite # from primaite.primaite_session import PrimaiteSession from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.networks import arcd_uc2_network from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -29,7 +32,7 @@ from primaite import PRIMAITE_PATHS # PrimAITE v3 stuff from primaite.simulator.file_system.file_system import FileSystem -from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.base import Link, Node class TestService(Service): @@ -122,3 +125,30 @@ def temp_primaite_session(request, monkeypatch) -> TempPrimaiteSession: monkeypatch.setattr(PRIMAITE_PATHS, "user_sessions_path", temp_user_sessions_path()) config_path = request.param[0] return TempPrimaiteSession.from_config(config_path=config_path) + + +@pytest.fixture(scope="function") +def client_server() -> Tuple[Computer, Server]: + # Create Computer + computer: Computer = Computer( + hostname="test_computer", + ip_address="192.168.0.1", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, + ) + + # Create Server + server = Server( + hostname="server", ip_address="192.168.0.2", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON + ) + + # Connect Computer and Server + computer_nic = computer.nics[next(iter(computer.nics))] + server_nic = server.nics[next(iter(server.nics))] + link = Link(endpoint_a=computer_nic, endpoint_b=server_nic) + + # Should be linked + assert link.is_up + + return computer, server diff --git a/tests/e2e_integration_tests/environments/test_sb3_environment.py b/tests/e2e_integration_tests/environments/test_sb3_environment.py index 3907ff50..c1c028a2 100644 --- a/tests/e2e_integration_tests/environments/test_sb3_environment.py +++ b/tests/e2e_integration_tests/environments/test_sb3_environment.py @@ -2,6 +2,7 @@ import tempfile from pathlib import Path +import pytest import yaml from stable_baselines3 import PPO @@ -10,6 +11,7 @@ from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteGymEnv +@pytest.mark.skip(reason="no way of currently testing this") def test_sb3_compatibility(): """Test that the Gymnasium environment can be used with an SB3 agent.""" with open(example_config_path(), "r") as f: diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index 086e9af8..d0dce118 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -11,6 +11,7 @@ MISCONFIGURED_PATH = TEST_ASSETS_ROOT / "configs/bad_primaite_session.yaml" MULTI_AGENT_PATH = TEST_ASSETS_ROOT / "configs/multi_agent_session.yaml" +@pytest.mark.skip(reason="no way of currently testing this") class TestPrimaiteSession: @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) def test_creating_session(self, temp_primaite_session): diff --git a/tests/integration_tests/network/test_link_connection.py b/tests/integration_tests/network/test_link_connection.py index 0ddf54df..c6aeac24 100644 --- a/tests/integration_tests/network/test_link_connection.py +++ b/tests/integration_tests/network/test_link_connection.py @@ -16,3 +16,9 @@ def test_link_up(): assert nic_a.enabled assert nic_b.enabled assert link.is_up + + +def test_ping_between_computer_and_server(client_server): + computer, server = client_server + + assert computer.ping(target_ip_address=server.nics[next(iter(server.nics))].ip_address) diff --git a/tests/integration_tests/system/test_dns_client_server.py b/tests/integration_tests/system/test_dns_client_server.py index 81a223ef..70657112 100644 --- a/tests/integration_tests/system/test_dns_client_server.py +++ b/tests/integration_tests/system/test_dns_client_server.py @@ -1,3 +1,8 @@ +from ipaddress import IPv4Address +from typing import Tuple + +import pytest + from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server @@ -6,12 +11,31 @@ from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.service import ServiceOperatingState -def test_dns_client_server(uc2_network): - client_1: Computer = uc2_network.get_node_by_hostname("client_1") - domain_controller: Server = uc2_network.get_node_by_hostname("domain_controller") +@pytest.fixture(scope="function") +def dns_client_and_dns_server(client_server) -> Tuple[DNSClient, Computer, DNSServer, Server]: + computer, server = client_server - dns_client: DNSClient = client_1.software_manager.software["DNSClient"] - dns_server: DNSServer = domain_controller.software_manager.software["DNSServer"] + # Install DNS Client on computer + computer.software_manager.install(DNSClient) + dns_client: DNSClient = computer.software_manager.software["DNSClient"] + dns_client.start() + # set server as DNS Server + dns_client.dns_server = IPv4Address(server.nics.get(next(iter(server.nics))).ip_address) + + # Install DNS Server on server + server.software_manager.install(DNSServer) + dns_server: DNSServer = server.software_manager.software["DNSServer"] + dns_server.start() + # register arcd.com as a domain + dns_server.dns_register( + domain_name="arcd.com", domain_ip_address=IPv4Address(server.nics.get(next(iter(server.nics))).ip_address) + ) + + return dns_client, computer, dns_server, server + + +def test_dns_client_server(dns_client_and_dns_server): + dns_client, computer, dns_server, server = dns_client_and_dns_server assert dns_client.operating_state == ServiceOperatingState.RUNNING assert dns_server.operating_state == ServiceOperatingState.RUNNING @@ -29,12 +53,8 @@ def test_dns_client_server(uc2_network): assert len(dns_client.dns_cache) == 1 -def test_dns_client_requests_offline_dns_server(uc2_network): - client_1: Computer = uc2_network.get_node_by_hostname("client_1") - domain_controller: Server = uc2_network.get_node_by_hostname("domain_controller") - - dns_client: DNSClient = client_1.software_manager.software["DNSClient"] - dns_server: DNSServer = domain_controller.software_manager.software["DNSServer"] +def test_dns_client_requests_offline_dns_server(dns_client_and_dns_server): + dns_client, computer, dns_server, server = dns_client_and_dns_server assert dns_client.operating_state == ServiceOperatingState.RUNNING assert dns_server.operating_state == ServiceOperatingState.RUNNING @@ -48,12 +68,12 @@ def test_dns_client_requests_offline_dns_server(uc2_network): assert len(dns_client.dns_cache) == 1 dns_client.dns_cache = {} - domain_controller.power_off() + server.power_off() - for i in range(domain_controller.shut_down_duration + 1): - uc2_network.apply_timestep(timestep=i) + for i in range(server.shut_down_duration + 1): + server.apply_timestep(timestep=i) - assert domain_controller.operating_state == NodeOperatingState.OFF + assert server.operating_state == NodeOperatingState.OFF assert dns_server.operating_state == ServiceOperatingState.STOPPED # this time it should not cache because dns server is not online diff --git a/tests/integration_tests/system/test_ftp_client_server.py b/tests/integration_tests/system/test_ftp_client_server.py index b2cdbc06..32ea7f2b 100644 --- a/tests/integration_tests/system/test_ftp_client_server.py +++ b/tests/integration_tests/system/test_ftp_client_server.py @@ -1,4 +1,7 @@ from ipaddress import IPv4Address +from typing import Tuple + +import pytest from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server @@ -7,18 +10,31 @@ from primaite.simulator.system.services.ftp.ftp_server import FTPServer from primaite.simulator.system.services.service import ServiceOperatingState -def test_ftp_client_store_file_in_server(uc2_network): +@pytest.fixture(scope="function") +def ftp_client_and_ftp_server(client_server) -> Tuple[FTPClient, Computer, FTPServer, Server]: + computer, server = client_server + + # Install FTP Client service on computer + computer.software_manager.install(FTPClient) + ftp_client: FTPClient = computer.software_manager.software["FTPClient"] + ftp_client.start() + + # Install FTP Server service on server + server.software_manager.install(FTPServer) + ftp_server: FTPServer = server.software_manager.software["FTPServer"] + ftp_server.start() + + return ftp_client, computer, ftp_server, server + + +def test_ftp_client_store_file_in_server(ftp_client_and_ftp_server): """ Test checks to see if the client is able to store files in the backup server. """ - client_1: Computer = uc2_network.get_node_by_hostname("client_1") - backup_server: Server = uc2_network.get_node_by_hostname("backup_server") - - ftp_client: FTPClient = client_1.software_manager.software["FTPClient"] - ftp_server_service: FTPServer = backup_server.software_manager.software["FTPServer"] + ftp_client, computer, ftp_server, server = ftp_client_and_ftp_server assert ftp_client.operating_state == ServiceOperatingState.RUNNING - assert ftp_server_service.operating_state == ServiceOperatingState.RUNNING + assert ftp_server.operating_state == ServiceOperatingState.RUNNING # create file on ftp client ftp_client.file_system.create_file(file_name="test_file.txt") @@ -28,61 +44,53 @@ def test_ftp_client_store_file_in_server(uc2_network): src_file_name="test_file.txt", dest_folder_name="client_1_backup", dest_file_name="test_file.txt", - dest_ip_address=backup_server.nics.get(next(iter(backup_server.nics))).ip_address, + dest_ip_address=server.nics.get(next(iter(server.nics))).ip_address, ) - assert ftp_server_service.file_system.get_file(folder_name="client_1_backup", file_name="test_file.txt") + assert ftp_server.file_system.get_file(folder_name="client_1_backup", file_name="test_file.txt") -def test_ftp_client_retrieve_file_from_server(uc2_network): +def test_ftp_client_retrieve_file_from_server(ftp_client_and_ftp_server): """ Test checks to see if the client is able to retrieve files from the backup server. """ - client_1: Computer = uc2_network.get_node_by_hostname("client_1") - backup_server: Server = uc2_network.get_node_by_hostname("backup_server") - - ftp_client: FTPClient = client_1.software_manager.software["FTPClient"] - ftp_server_service: FTPServer = backup_server.software_manager.software["FTPServer"] + ftp_client, computer, ftp_server, server = ftp_client_and_ftp_server assert ftp_client.operating_state == ServiceOperatingState.RUNNING - assert ftp_server_service.operating_state == ServiceOperatingState.RUNNING + assert ftp_server.operating_state == ServiceOperatingState.RUNNING # create file on ftp server - ftp_server_service.file_system.create_file(file_name="test_file.txt", folder_name="file_share") + ftp_server.file_system.create_file(file_name="test_file.txt", folder_name="file_share") assert ftp_client.request_file( src_folder_name="file_share", src_file_name="test_file.txt", dest_folder_name="downloads", dest_file_name="test_file.txt", - dest_ip_address=backup_server.nics.get(next(iter(backup_server.nics))).ip_address, + dest_ip_address=server.nics.get(next(iter(server.nics))).ip_address, ) # client should have retrieved the file assert ftp_client.file_system.get_file(folder_name="downloads", file_name="test_file.txt") -def test_ftp_client_tries_to_connect_to_offline_server(uc2_network): +def test_ftp_client_tries_to_connect_to_offline_server(ftp_client_and_ftp_server): """Test checks to make sure that the client can't do anything when the server is offline.""" - client_1: Computer = uc2_network.get_node_by_hostname("client_1") - backup_server: Server = uc2_network.get_node_by_hostname("backup_server") - - ftp_client: FTPClient = client_1.software_manager.software["FTPClient"] - ftp_server_service: FTPServer = backup_server.software_manager.software["FTPServer"] + ftp_client, computer, ftp_server, server = ftp_client_and_ftp_server assert ftp_client.operating_state == ServiceOperatingState.RUNNING - assert ftp_server_service.operating_state == ServiceOperatingState.RUNNING + assert ftp_server.operating_state == ServiceOperatingState.RUNNING # create file on ftp server - ftp_server_service.file_system.create_file(file_name="test_file.txt", folder_name="file_share") + ftp_server.file_system.create_file(file_name="test_file.txt", folder_name="file_share") - backup_server.power_off() + server.power_off() - for i in range(backup_server.shut_down_duration + 1): - uc2_network.apply_timestep(timestep=i) + for i in range(server.shut_down_duration + 1): + server.apply_timestep(timestep=i) assert ftp_client.operating_state == ServiceOperatingState.RUNNING - assert ftp_server_service.operating_state == ServiceOperatingState.STOPPED + assert ftp_server.operating_state == ServiceOperatingState.STOPPED assert ( ftp_client.request_file( @@ -90,7 +98,7 @@ def test_ftp_client_tries_to_connect_to_offline_server(uc2_network): src_file_name="test_file.txt", dest_folder_name="downloads", dest_file_name="test_file.txt", - dest_ip_address=backup_server.nics.get(next(iter(backup_server.nics))).ip_address, + dest_ip_address=server.nics.get(next(iter(server.nics))).ip_address, ) is False ) diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py index f2cc5b5d..41982805 100644 --- a/tests/integration_tests/system/test_web_client_server.py +++ b/tests/integration_tests/system/test_web_client_server.py @@ -1,103 +1,118 @@ +from typing import Tuple + +import pytest + from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.http import HttpStatusCode from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer +from primaite.simulator.system.services.web_server.web_server import WebServer -def test_web_page_home_page(uc2_network): - """Test to see if the browser is able to open the main page of the web server.""" - client_1: Computer = uc2_network.get_node_by_hostname("client_1") - web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] - web_client.run() - web_client.target_url = "http://arcd.com/" - assert web_client.operating_state == ApplicationOperatingState.RUNNING +@pytest.fixture(scope="function") +def web_client_and_web_server(client_server) -> Tuple[WebBrowser, Computer, WebServer, Server]: + computer, server = client_server - assert web_client.get_webpage() is True + # Install Web Browser on computer + computer.software_manager.install(WebBrowser) + web_browser: WebBrowser = computer.software_manager.software["WebBrowser"] + web_browser.run() - # latest reponse should have status code 200 - assert web_client.latest_response is not None - assert web_client.latest_response.status_code == HttpStatusCode.OK + # Install DNS Client service on computer + computer.software_manager.install(DNSClient) + dns_client: DNSClient = computer.software_manager.software["DNSClient"] + # set dns server + dns_client.dns_server = server.nics[next(iter(server.nics))].ip_address + + # Install Web Server service on server + server.software_manager.install(WebServer) + web_server_service: WebServer = server.software_manager.software["WebServer"] + web_server_service.start() + + # Install DNS Server service on server + server.software_manager.install(DNSServer) + dns_server: DNSServer = server.software_manager.software["DNSServer"] + # register arcd.com to DNS + dns_server.dns_register(domain_name="arcd.com", domain_ip_address=server.nics[next(iter(server.nics))].ip_address) + + return web_browser, computer, web_server_service, server -def test_web_page_get_users_page_request_with_domain_name(uc2_network): +def test_web_page_get_users_page_request_with_domain_name(web_client_and_web_server): """Test to see if the client can handle requests with domain names""" - client_1: Computer = uc2_network.get_node_by_hostname("client_1") - web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] - web_client.run() - assert web_client.operating_state == ApplicationOperatingState.RUNNING + web_browser_app, computer, web_server_service, server = web_client_and_web_server - assert web_client.get_webpage() is True + web_server_ip = server.nics.get(next(iter(server.nics))).ip_address + web_browser_app.target_url = f"http://arcd.com/" + assert web_browser_app.operating_state == ApplicationOperatingState.RUNNING - # latest reponse should have status code 200 - assert web_client.latest_response is not None - assert web_client.latest_response.status_code == HttpStatusCode.OK + assert web_browser_app.get_webpage() is True + + # latest response should have status code 200 + assert web_browser_app.latest_response is not None + assert web_browser_app.latest_response.status_code == HttpStatusCode.OK -def test_web_page_get_users_page_request_with_ip_address(uc2_network): +def test_web_page_get_users_page_request_with_ip_address(web_client_and_web_server): """Test to see if the client can handle requests that use ip_address.""" - client_1: Computer = uc2_network.get_node_by_hostname("client_1") - web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] - web_client.run() + web_browser_app, computer, web_server_service, server = web_client_and_web_server - web_server: Server = uc2_network.get_node_by_hostname("web_server") + web_server_ip = server.nics.get(next(iter(server.nics))).ip_address + web_browser_app.target_url = f"http://{web_server_ip}/" + assert web_browser_app.operating_state == ApplicationOperatingState.RUNNING - web_server_ip = web_server.nics.get(next(iter(web_server.nics))).ip_address - web_client.target_url = f"http://{web_server_ip}/users/" - assert web_client.operating_state == ApplicationOperatingState.RUNNING - - assert web_client.get_webpage() is True + assert web_browser_app.get_webpage() is True # latest response should have status code 200 - assert web_client.latest_response is not None - assert web_client.latest_response.status_code == HttpStatusCode.OK + assert web_browser_app.latest_response is not None + assert web_browser_app.latest_response.status_code == HttpStatusCode.OK -def test_web_page_request_from_shut_down_server(uc2_network): +def test_web_page_request_from_shut_down_server(web_client_and_web_server): """Test to see that the web server does not respond when the server is off.""" - client_1: Computer = uc2_network.get_node_by_hostname("client_1") - web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] - web_client.run() + web_browser_app, computer, web_server_service, server = web_client_and_web_server - web_server: Server = uc2_network.get_node_by_hostname("web_server") + web_server_ip = server.nics.get(next(iter(server.nics))).ip_address + web_browser_app.target_url = f"http://arcd.com/" + assert web_browser_app.operating_state == ApplicationOperatingState.RUNNING - assert web_client.operating_state == ApplicationOperatingState.RUNNING - - assert web_client.get_webpage("http://arcd.com/users/") is True + assert web_browser_app.get_webpage() is True # latest response should have status code 200 - assert web_client.latest_response.status_code == HttpStatusCode.OK + assert web_browser_app.latest_response is not None + assert web_browser_app.latest_response.status_code == HttpStatusCode.OK - web_server.power_off() + server.power_off() - for i in range(web_server.shut_down_duration + 1): - uc2_network.apply_timestep(timestep=i) + server.power_off() + + for i in range(server.shut_down_duration + 1): + server.apply_timestep(timestep=i) # node should be off - assert web_server.operating_state is NodeOperatingState.OFF + assert server.operating_state is NodeOperatingState.OFF - assert web_client.get_webpage("http://arcd.com/users/") is False - assert web_client.latest_response.status_code == HttpStatusCode.NOT_FOUND + assert web_browser_app.get_webpage() is False + assert web_browser_app.latest_response.status_code == HttpStatusCode.NOT_FOUND -def test_web_page_request_from_closed_web_browser(uc2_network): - client_1: Computer = uc2_network.get_node_by_hostname("client_1") - web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] - web_client.run() +def test_web_page_request_from_closed_web_browser(web_client_and_web_server): + web_browser_app, computer, web_server_service, server = web_client_and_web_server - web_server: Server = uc2_network.get_node_by_hostname("web_server") - - assert web_client.operating_state == ApplicationOperatingState.RUNNING - - assert web_client.get_webpage("http://arcd.com/users/") is True + assert web_browser_app.operating_state == ApplicationOperatingState.RUNNING + web_browser_app.target_url = f"http://arcd.com/" + assert web_browser_app.get_webpage() is True # latest response should have status code 200 - assert web_client.latest_response.status_code == HttpStatusCode.OK + assert web_browser_app.latest_response.status_code == HttpStatusCode.OK - web_client.close() + web_browser_app.close() # node should be off - assert web_client.operating_state is ApplicationOperatingState.CLOSED + assert web_browser_app.operating_state is ApplicationOperatingState.CLOSED - assert web_client.get_webpage("http://arcd.com/users/") is False + assert web_browser_app.get_webpage() is False diff --git a/tests/integration_tests/system/test_web_client_server_and_database.py b/tests/integration_tests/system/test_web_client_server_and_database.py new file mode 100644 index 00000000..d7b5603d --- /dev/null +++ b/tests/integration_tests/system/test_web_client_server_and_database.py @@ -0,0 +1,106 @@ +from ipaddress import IPv4Address +from typing import Tuple + +import pytest + +from primaite.simulator.network.hardware.base import Link +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer +from primaite.simulator.system.services.web_server.web_server import WebServer + + +@pytest.fixture(scope="function") +def web_client_web_server_database() -> Tuple[Computer, Server, Server]: + # Create Computer + computer: Computer = Computer( + hostname="test_computer", + ip_address="192.168.0.1", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, + ) + + # Create Web Server + web_server = Server( + hostname="web_server", + ip_address="192.168.0.2", + subnet_mask="255.255.255.0", + operating_state=NodeOperatingState.ON, + ) + + # Create Database Server + db_server = Server( + hostname="db_server", + ip_address="192.168.0.3", + subnet_mask="255.255.255.0", + operating_state=NodeOperatingState.ON, + ) + + # Get the NICs + computer_nic = computer.nics[next(iter(computer.nics))] + server_nic = web_server.nics[next(iter(web_server.nics))] + db_server_nic = db_server.nics[next(iter(db_server.nics))] + + # Connect Computer and Server + link_computer_server = Link(endpoint_a=computer_nic, endpoint_b=server_nic) + # Should be linked + assert link_computer_server.is_up + + # Connect database server and web server + link_server_db = Link(endpoint_a=server_nic, endpoint_b=db_server_nic) + # Should be linked + assert link_computer_server.is_up + assert link_server_db.is_up + + # Install DatabaseService on db server + db_server.software_manager.install(DatabaseService) + db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + db_service.start() + + # Install Web Browser on computer + computer.software_manager.install(WebBrowser) + web_browser: WebBrowser = computer.software_manager.software["WebBrowser"] + web_browser.run() + + # Install DNS Client service on computer + computer.software_manager.install(DNSClient) + dns_client: DNSClient = computer.software_manager.software["DNSClient"] + # set dns server + dns_client.dns_server = web_server.nics[next(iter(web_server.nics))].ip_address + + # Install Web Server service on web server + web_server.software_manager.install(WebServer) + web_server_service: WebServer = web_server.software_manager.software["WebServer"] + web_server_service.start() + + # Install DNS Server service on web server + web_server.software_manager.install(DNSServer) + dns_server: DNSServer = web_server.software_manager.software["DNSServer"] + # register arcd.com to DNS + dns_server.dns_register( + domain_name="arcd.com", domain_ip_address=web_server.nics[next(iter(web_server.nics))].ip_address + ) + + # Install DatabaseClient service on web server + web_server.software_manager.install(DatabaseClient) + db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + db_client.server_ip_address = IPv4Address(db_server_nic.ip_address) # set IP address of Database Server + db_client.run() + assert db_client.connect() + + return computer, web_server, db_server + + +@pytest.mark.skip(reason="waiting for a way to set this up correctly") +def test_web_client_requests_users(web_client_web_server_database): + computer, web_server, db_server = web_client_web_server_database + + web_browser: WebBrowser = computer.software_manager.software["WebBrowser"] + + web_browser.get_webpage() diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 4defc80c..9366d173 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -185,6 +185,38 @@ def test_get_file(file_system): file_system.show(full=True) +def test_reset_file_system(file_system): + # file and folder that existed originally + file_system.create_file(file_name="test_file.zip") + file_system.create_folder(folder_name="test_folder") + file_system.set_original_state() + + # create a new file + file_system.create_file(file_name="new_file.txt") + + # create a new folder + file_system.create_folder(folder_name="new_folder") + + # delete the file that existed originally + file_system.delete_file(folder_name="root", file_name="test_file.zip") + assert file_system.get_file(folder_name="root", file_name="test_file.zip") is None + + # delete the folder that existed originally + file_system.delete_folder(folder_name="test_folder") + assert file_system.get_folder(folder_name="test_folder") is None + + # reset + file_system.reset_component_for_episode(episode=1) + + # deleted original file and folder should be back + assert file_system.get_file(folder_name="root", file_name="test_file.zip") + assert file_system.get_folder(folder_name="test_folder") + + # new file and folder should be removed + assert file_system.get_file(folder_name="root", file_name="new_file.txt") is None + assert file_system.get_folder(folder_name="new_folder") is None + + @pytest.mark.skip(reason="Skipping until we tackle serialisation") def test_serialisation(file_system): """Test to check that the object serialisation works correctly.""" diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py index b2724369..83426409 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py @@ -1,39 +1,66 @@ +from typing import Tuple + import pytest +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.protocols.http import HttpResponsePacket, HttpStatusCode from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.web_browser import WebBrowser @pytest.fixture(scope="function") -def web_client() -> Computer: - node = Computer( - hostname="web_client", ip_address="192.168.1.11", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" +def web_browser() -> WebBrowser: + computer = Computer( + hostname="web_client", + ip_address="192.168.1.11", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, ) - return node + # Web Browser should be pre-installed in computer + web_browser: WebBrowser = computer.software_manager.software["WebBrowser"] + web_browser.run() + assert web_browser.operating_state is ApplicationOperatingState.RUNNING + return web_browser -def test_create_web_client(web_client): - assert web_client is not None - web_browser: WebBrowser = web_client.software_manager.software["WebBrowser"] +def test_create_web_client(): + computer = Computer( + hostname="web_client", + ip_address="192.168.1.11", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, + ) + # Web Browser should be pre-installed in computer + web_browser: WebBrowser = computer.software_manager.software["WebBrowser"] assert web_browser.name is "WebBrowser" assert web_browser.port is Port.HTTP assert web_browser.protocol is IPProtocol.TCP -def test_receive_invalid_payload(web_client): - web_browser: WebBrowser = web_client.software_manager.software["WebBrowser"] - +def test_receive_invalid_payload(web_browser): assert web_browser.receive(payload={}) is False -def test_receive_payload(web_client): +def test_receive_payload(web_browser): payload = HttpResponsePacket(status_code=HttpStatusCode.OK) - web_browser: WebBrowser = web_client.software_manager.software["WebBrowser"] assert web_browser.latest_response is None web_browser.receive(payload=payload) assert web_browser.latest_response is not None + + +def test_invalid_target_url(web_browser): + # none value target url + web_browser.target_url = None + assert web_browser.get_webpage() is False + + +def test_non_existent_target_url(web_browser): + web_browser.target_url = "http://192.168.255.255" + assert web_browser.get_webpage() is False diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py similarity index 65% rename from tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py rename to tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py index 2b4082d9..71517855 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py @@ -5,28 +5,13 @@ import pytest from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.dns import DNSPacket, DNSReply, DNSRequest from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.dns.dns_client import DNSClient -from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.service import ServiceOperatingState -@pytest.fixture(scope="function") -def dns_server() -> Node: - node = Server( - hostname="dns_server", - ip_address="192.168.1.10", - subnet_mask="255.255.255.0", - default_gateway="192.168.1.1", - operating_state=NodeOperatingState.ON, - ) - node.software_manager.install(software_class=DNSServer) - return node - - @pytest.fixture(scope="function") def dns_client() -> Node: node = Computer( @@ -39,14 +24,6 @@ def dns_client() -> Node: return node -def test_create_dns_server(dns_server): - assert dns_server is not None - dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] - assert dns_server_service.name is "DNSServer" - assert dns_server_service.port is Port.DNS - assert dns_server_service.protocol is IPProtocol.TCP - - def test_create_dns_client(dns_client): assert dns_client is not None dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] @@ -93,18 +70,6 @@ def test_dns_client_check_domain_exists_when_not_running(dns_client): assert dns_client_service.check_domain_exists("test.com") is False -def test_dns_server_domain_name_registration(dns_server): - """Test to check if the domain name registration works.""" - dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] - - # register the web server in the domain controller - dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12")) - - # return none for an unknown domain - assert dns_server_service.dns_lookup("fake-domain.com") is None - assert dns_server_service.dns_lookup("real-domain.com") is not None - - def test_dns_client_check_domain_in_cache(dns_client): """Test to make sure that the check_domain_in_cache returns the correct values.""" dns_client.operating_state = NodeOperatingState.ON @@ -118,26 +83,6 @@ def test_dns_client_check_domain_in_cache(dns_client): assert dns_client_service.check_domain_exists("real-domain.com") is True -def test_dns_server_receive(dns_server): - """Test to make sure that the DNS Server correctly responds to a DNS Client request.""" - dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] - - # register the web server in the domain controller - dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12")) - - assert ( - dns_server_service.receive(payload=DNSPacket(dns_request=DNSRequest(domain_name_request="fake-domain.com"))) - is False - ) - - assert ( - dns_server_service.receive(payload=DNSPacket(dns_request=DNSRequest(domain_name_request="real-domain.com"))) - is True - ) - - dns_server_service.show() - - def test_dns_client_receive(dns_client): """Test to make sure the DNS Client knows how to deal with request responses.""" dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] @@ -151,3 +96,9 @@ def test_dns_client_receive(dns_client): # domain name should be saved to cache assert dns_client_service.dns_cache["real-domain.com"] == IPv4Address("192.168.1.12") + + +def test_dns_client_receive_non_dns_payload(dns_client): + dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] + + assert dns_client_service.receive(payload=None) is False diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py new file mode 100644 index 00000000..5b65dfc2 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py @@ -0,0 +1,64 @@ +from ipaddress import IPv4Address + +import pytest + +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.protocols.dns import DNSPacket, DNSRequest +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.dns.dns_server import DNSServer + + +@pytest.fixture(scope="function") +def dns_server() -> Node: + node = Server( + hostname="dns_server", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, + ) + node.software_manager.install(software_class=DNSServer) + return node + + +def test_create_dns_server(dns_server): + assert dns_server is not None + dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] + assert dns_server_service.name is "DNSServer" + assert dns_server_service.port is Port.DNS + assert dns_server_service.protocol is IPProtocol.TCP + + +def test_dns_server_domain_name_registration(dns_server): + """Test to check if the domain name registration works.""" + dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] + + # register the web server in the domain controller + dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12")) + + # return none for an unknown domain + assert dns_server_service.dns_lookup("fake-domain.com") is None + assert dns_server_service.dns_lookup("real-domain.com") is not None + + +def test_dns_server_receive(dns_server): + """Test to make sure that the DNS Server correctly responds to a DNS Client request.""" + dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] + + # register the web server in the domain controller + dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12")) + + assert ( + dns_server_service.receive(payload=DNSPacket(dns_request=DNSRequest(domain_name_request="fake-domain.com"))) + is False + ) + + assert ( + dns_server_service.receive(payload=DNSPacket(dns_request=DNSRequest(domain_name_request="real-domain.com"))) + is True + ) + + dns_server_service.show() diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py new file mode 100644 index 00000000..c079ebc4 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py @@ -0,0 +1,50 @@ +import pytest + +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.ftp.ftp_client import FTPClient + + +@pytest.fixture(scope="function") +def ftp_client() -> Node: + node = Computer( + hostname="ftp_client", + ip_address="192.168.1.11", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, + ) + return node + + +def test_create_ftp_client(ftp_client): + assert ftp_client is not None + ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + assert ftp_client_service.name is "FTPClient" + assert ftp_client_service.port is Port.FTP + assert ftp_client_service.protocol is IPProtocol.TCP + + +def test_ftp_client_store_file(ftp_client): + """Test to make sure the FTP Client knows how to deal with request responses.""" + assert ftp_client.file_system.get_file(folder_name="downloads", file_name="file.txt") is None + + response: FTPPacket = FTPPacket( + ftp_command=FTPCommand.STOR, + ftp_command_args={ + "dest_folder_name": "downloads", + "dest_file_name": "file.txt", + "file_size": 24, + }, + packet_payload_size=24, + status_code=FTPStatusCode.OK, + ) + + ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + ftp_client_service.receive(response) + + assert ftp_client.file_system.get_file(folder_name="downloads", file_name="file.txt") diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py similarity index 63% rename from tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py rename to tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py index 9957b6f6..0c849106 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py @@ -1,16 +1,13 @@ -from ipaddress import IPv4Address - import pytest from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.services.ftp.ftp_client import FTPClient from primaite.simulator.system.services.ftp.ftp_server import FTPServer +from primaite.simulator.system.services.service import ServiceOperatingState @pytest.fixture(scope="function") @@ -26,18 +23,6 @@ def ftp_server() -> Node: return node -@pytest.fixture(scope="function") -def ftp_client() -> Node: - node = Computer( - hostname="ftp_client", - ip_address="192.168.1.11", - subnet_mask="255.255.255.0", - default_gateway="192.168.1.1", - operating_state=NodeOperatingState.ON, - ) - return node - - def test_create_ftp_server(ftp_server): assert ftp_server is not None ftp_server_service: FTPServer = ftp_server.software_manager.software["FTPServer"] @@ -46,14 +31,6 @@ def test_create_ftp_server(ftp_server): assert ftp_server_service.protocol is IPProtocol.TCP -def test_create_ftp_client(ftp_client): - assert ftp_client is not None - ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] - assert ftp_client_service.name is "FTPClient" - assert ftp_client_service.port is Port.FTP - assert ftp_client_service.protocol is IPProtocol.TCP - - def test_ftp_server_store_file(ftp_server): """Test to make sure the FTP Server knows how to deal with request responses.""" assert ftp_server.file_system.get_file(folder_name="downloads", file_name="file.txt") is None @@ -74,10 +51,28 @@ def test_ftp_server_store_file(ftp_server): assert ftp_server.file_system.get_file(folder_name="downloads", file_name="file.txt") -def test_ftp_client_store_file(ftp_client): - """Test to make sure the FTP Client knows how to deal with request responses.""" - assert ftp_client.file_system.get_file(folder_name="downloads", file_name="file.txt") is None +def test_ftp_server_should_send_error_if_port_arg_is_invalid(ftp_server): + """Should fail if the port command receives an invalid port.""" + payload: FTPPacket = FTPPacket( + ftp_command=FTPCommand.PORT, + ftp_command_args=None, + packet_payload_size=24, + ) + ftp_server_service: FTPServer = ftp_server.software_manager.software["FTPServer"] + assert ftp_server_service._process_ftp_command(payload=payload).status_code is FTPStatusCode.ERROR + + +def test_ftp_server_receives_non_ftp_packet(ftp_server): + """Receive should return false if the service receives a non ftp packet.""" + response: FTPPacket = None + + ftp_server_service: FTPServer = ftp_server.software_manager.software["FTPServer"] + assert ftp_server_service.receive(response) is False + + +def test_offline_ftp_server_receives_request(ftp_server): + """Receive should return false if the service is stopped.""" response: FTPPacket = FTPPacket( ftp_command=FTPCommand.STOR, ftp_command_args={ @@ -86,10 +81,9 @@ def test_ftp_client_store_file(ftp_client): "file_size": 24, }, packet_payload_size=24, - status_code=FTPStatusCode.OK, ) - ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] - ftp_client_service.receive(response) - - assert ftp_client.file_system.get_file(folder_name="downloads", file_name="file.txt") + ftp_server_service: FTPServer = ftp_server.software_manager.software["FTPServer"] + ftp_server_service.stop() + assert ftp_server_service.operating_state is ServiceOperatingState.STOPPED + assert ftp_server_service.receive(response) is False From 957702fa5db703b442e820ad19e52a4d3290b3cd Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 29 Nov 2023 10:10:23 +0000 Subject: [PATCH 405/980] #2085: Remove JSON file handling --- src/primaite/game/game.py | 11 +---------- src/primaite/session/environment.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 3409100e..38e9d5fc 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -1,12 +1,10 @@ """PrimAITE game - Encapsulates the simulation and agents.""" -import json -import os from ipaddress import IPv4Address from typing import Dict, List from pydantic import BaseModel, ConfigDict -from primaite import getLogger, PRIMAITE_PATHS +from primaite import getLogger from primaite.game.agent.actions import ActionManager from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent, RandomAgent @@ -109,13 +107,6 @@ class PrimaiteGame: # Get the current state of the simulation sim_state = self.get_sim_state() - # Create state suitable for dumping to JSON file. - dump_state = {self.episode_counter: {self.step_counter: sim_state}} - # Dump to file - if os.path.isfile(PRIMAITE_PATHS.episode_steps_log_file_path): - with open(PRIMAITE_PATHS.episode_steps_log_file_path, "a") as f: - json.dump(dump_state, f) - # Update agents' observations and rewards based on the current state self.update_agents(sim_state) diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index a5fdade9..913038f9 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -1,9 +1,11 @@ +import os from typing import Any, Dict, Final, Optional, SupportsFloat, Tuple import gymnasium from gymnasium.core import ActType, ObsType from ray.rllib.env.multi_agent_env import MultiAgentEnv +from primaite import PRIMAITE_PATHS from primaite.game.agent.interface import ProxyAgent from primaite.game.game import PrimaiteGame @@ -30,6 +32,17 @@ class PrimaiteGymEnv(gymnasium.Env): self.game.apply_agent_actions() self.game.advance_timestep() state = self.game.get_sim_state() + + # Create state suitable for dumping to file. + dump_state = {self.game.episode_counter: {self.game.step_counter: state}} + + # Dump to file + if os.path.isfile(PRIMAITE_PATHS.episode_steps_log_file_path): + with open(PRIMAITE_PATHS.episode_steps_log_file_path, "a", encoding="utf-8") as f: + f.write(str(dump_state)) + f.write("\n=================\n") + f.flush() + self.game.update_agents(state) next_obs = self._get_obs() From 3ab911f6af57bffb6f0ae3019267340dd5f4eeef Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 29 Nov 2023 11:41:02 +0000 Subject: [PATCH 406/980] #2085: Change output file type --- src/primaite/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/__init__.py b/src/primaite/__init__.py index 1e5fe925..a143b9b9 100644 --- a/src/primaite/__init__.py +++ b/src/primaite/__init__.py @@ -108,7 +108,7 @@ class _PrimaitePaths: def generate_episode_step_log_file_path(self) -> Path: """The PrimAITE app episode step log file path.""" - return self.app_log_dir_path / "epi_step.json" + return self.app_log_dir_path / "epi_step.log" def __repr__(self) -> str: properties_str = ", ".join([f"{p}='{getattr(self, p)}'" for p in self._get_dirs_properties()]) From bf73cc2eb7daf6b4e2a13b43eac6aff3980a9629 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 29 Nov 2023 13:45:34 +0000 Subject: [PATCH 407/980] #1859 - Re-ordered the node reset function again --- src/primaite/simulator/network/container.py | 16 ++++++++++++++++ src/primaite/simulator/network/hardware/base.py | 12 ------------ .../system/applications/database_client.py | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 7ef55c3c..1ee384f3 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -12,6 +12,8 @@ from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import Router from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.services.service import Service _LOGGER = getLogger(__name__) @@ -56,6 +58,20 @@ class Network(SimComponent): node.reset_component_for_episode(episode) for link in self.links.values(): link.reset_component_for_episode(episode) + + for node in self.nodes.values(): + node.power_on() + + # Reset software + for software in node.software_manager.software.values(): + software.reset_component_for_episode(episode) + if isinstance(software, Service): + software.start() + elif isinstance(software, Application): + software.run() + + for nic in node.nics.values(): + nic.enable() def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 825df37d..9fb007ff 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1035,8 +1035,6 @@ class Node(SimComponent): # Reset File System self.file_system.reset_component_for_episode(episode) - self.power_on() - # Reset all Nics for nic in self.nics.values(): nic.reset_component_for_episode(episode) @@ -1045,16 +1043,6 @@ class Node(SimComponent): self.sys_log.current_episode = episode self.sys_log.setup_logger() - # Reset software - for software in self.software_manager.software.values(): - software.reset_component_for_episode(episode) - if isinstance(software, Service): - software.start() - elif isinstance(software, Application): - software.run() - - for nic in self.nics.values(): - nic.enable() def _init_request_manager(self) -> RequestManager: # TODO: I see that this code is really confusing and hard to read right now... I think some of these things will diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 92f7e76d..b1743fad 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -37,13 +37,14 @@ class DatabaseClient(Application): """Sets the original state.""" print(f"Setting DatabaseClient WebServer original state on node {self.software_manager.node.hostname}") super().set_original_state() - vals_to_include = {"server_ip_address", "server_password", "connected"} + vals_to_include = {"server_ip_address", "server_password", "connected", "_query_success_tracker"} self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" print(f"Resetting DataBaseClient state on node {self.software_manager.node.hostname}") super().reset_component_for_episode(episode) + self._query_success_tracker.clear() def describe_state(self) -> Dict: """ From 05d62a956d6e03631f70f9789477d2eb2faf4349 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 29 Nov 2023 13:18:38 +0000 Subject: [PATCH 408/980] Fix software reset issues --- sandbox.py | 72 +++++++++++++++++++ src/primaite/simulator/file_system/file.py | 4 +- .../simulator/file_system/file_system.py | 5 +- src/primaite/simulator/file_system/folder.py | 4 +- src/primaite/simulator/network/container.py | 8 +-- .../simulator/network/hardware/base.py | 6 +- .../system/applications/database_client.py | 6 +- .../system/applications/web_browser.py | 7 +- .../services/database/database_service.py | 5 +- .../system/services/dns/dns_client.py | 3 +- .../system/services/dns/dns_server.py | 3 +- .../system/services/ftp/ftp_client.py | 7 +- .../system/services/ftp/ftp_server.py | 7 +- .../red_services/data_manipulation_bot.py | 7 +- .../system/services/web_server/web_server.py | 7 +- 15 files changed, 119 insertions(+), 32 deletions(-) create mode 100644 sandbox.py diff --git a/sandbox.py b/sandbox.py new file mode 100644 index 00000000..b08f15b1 --- /dev/null +++ b/sandbox.py @@ -0,0 +1,72 @@ +from primaite.config.load import example_config_path, load +from primaite.session.session import PrimaiteSession +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.dns.dns_client import DNSClient + +cfg = load(example_config_path()) +session = PrimaiteSession.from_config(cfg) +network = session.game.simulation.network + +dc = network.get_node_by_hostname("domain_controller") +router = network.get_node_by_hostname("router_1") +client_1 = network.get_node_by_hostname("client_1") +client_2 = network.get_node_by_hostname("client_2") +switch_1 = network.get_node_by_hostname("switch_1") +switch_2 = network.get_node_by_hostname("switch_2") +web_server = network.get_node_by_hostname("web_server") + +dns_server = dc.software_manager.software["DNSServer"] +dns_client: DNSClient = client_2.software_manager.software["DNSClient"] +web_db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] +web_browser: WebBrowser = client_2.software_manager.software["WebBrowser"] + +# print("before calling get webpage") +# router.acl.show() +# dns_server.show() +# client_2.arp.show() +# router.arp.show() +# print() + +# print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) +# print("after calling get webpage") +# router.acl.show() +# dns_server.show() +# client_2.arp.show() +# router.arp.show() +# print() +# print("reset") +# print() +# print("im gonna reset") +# print() + +# web_db_client.connect() +# web_db_client.run() +# web_browser.run() +# print("client_2", client_2.operating_state) +# print("web_browser", web_browser.operating_state) +# print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) +session.game.reset() +print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) +session.game.reset() +print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) +session.game.reset() +print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) +session.game.reset() +print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) +# print() +# +# print("before calling get webpage") +# router.acl.show() +# dns_server.show() +# client_2.arp.show() +# router.arp.show() +# print() +# +# print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) +# print("after calling get webpage") +# router.acl.show() +# dns_server.show() +# client_2.arp.show() +# router.arp.show() +# print() diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index f0984f89..608a1d78 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -77,14 +77,14 @@ class File(FileSystemItemABC): def set_original_state(self): """Sets the original state.""" - print(f"Setting File ({self.path}) original state on node {self.sys_log.hostname}") + _LOGGER.debug(f"Setting File ({self.path}) original state on node {self.sys_log.hostname}") super().set_original_state() vals_to_include = {"folder_id", "folder_name", "file_type", "sim_size", "real", "sim_path", "sim_root"} self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print(f"Resetting File ({self.path}) state on node {self.sys_log.hostname}") + _LOGGER.debug(f"Resetting File ({self.path}) state on node {self.sys_log.hostname}") super().reset_component_for_episode(episode) @property diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index a6876786..31a3c5a0 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -37,7 +37,7 @@ class FileSystem(SimComponent): def set_original_state(self): """Sets the original state.""" - print(f"Setting FileSystem original state on node {self.sys_log.hostname}") + _LOGGER.debug(f"Setting FileSystem original state on node {self.sys_log.hostname}") for folder in self.folders.values(): folder.set_original_state() # Capture a list of all 'original' file uuids @@ -48,9 +48,8 @@ class FileSystem(SimComponent): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print(f"Resetting FileSystem state on node {self.sys_log.hostname}") + _LOGGER.debug(f"Resetting FileSystem state on node {self.sys_log.hostname}") # Move any 'original' folder that have been deleted back to folders - print(self._original_state) original_folder_uuids = self._original_state.pop("original_folder_uuids") for uuid in original_folder_uuids: if uuid in self.deleted_folders: diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 24dbdd79..c45dd8c5 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -53,7 +53,7 @@ class Folder(FileSystemItemABC): def set_original_state(self): """Sets the original state.""" - print(f"Setting Folder ({self.name}) original state on node {self.sys_log.hostname}") + _LOGGER.debug(f"Setting Folder ({self.name}) original state on node {self.sys_log.hostname}") for file in self.files.values(): file.set_original_state() super().set_original_state() @@ -70,7 +70,7 @@ class Folder(FileSystemItemABC): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print(f"Resetting Folder ({self.name}) state on node {self.sys_log.hostname}") + _LOGGER.debug(f"Resetting Folder ({self.name}) state on node {self.sys_log.hostname}") # Move any 'original' file that have been deleted back to files original_file_uuids = self._original_state.pop("original_file_uuids") for uuid in original_file_uuids: diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 1ee384f3..97b62f95 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -58,21 +58,19 @@ class Network(SimComponent): node.reset_component_for_episode(episode) for link in self.links.values(): link.reset_component_for_episode(episode) - + for node in self.nodes.values(): node.power_on() + for nic in node.nics.values(): + nic.enable() # Reset software for software in node.software_manager.software.values(): - software.reset_component_for_episode(episode) if isinstance(software, Service): software.start() elif isinstance(software, Application): software.run() - for nic in node.nics.values(): - nic.enable() - def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() self._node_request_manager = RequestManager() diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 9fb007ff..04c76c6b 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -993,7 +993,6 @@ class Node(SimComponent): def set_original_state(self): """Sets the original state.""" - print(f"Setting node original state for {self.hostname}") for software in self.software_manager.software.values(): software.set_original_state() @@ -1020,7 +1019,6 @@ class Node(SimComponent): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print(f"Resetting node state for {self.hostname}") super().reset_component_for_episode(episode) # Reset ARP Cache @@ -1039,11 +1037,13 @@ class Node(SimComponent): for nic in self.nics.values(): nic.reset_component_for_episode(episode) + for software in self.software_manager.software.values(): + software.reset_component_for_episode(episode) + if episode and self.sys_log: self.sys_log.current_episode = episode self.sys_log.setup_logger() - def _init_request_manager(self) -> RequestManager: # TODO: I see that this code is really confusing and hard to read right now... I think some of these things will # need a better name and better documentation. diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index b1743fad..7b63d26e 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -35,14 +35,14 @@ class DatabaseClient(Application): def set_original_state(self): """Sets the original state.""" - print(f"Setting DatabaseClient WebServer original state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Setting DatabaseClient WebServer original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = {"server_ip_address", "server_password", "connected", "_query_success_tracker"} self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print(f"Resetting DataBaseClient state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Resetting DataBaseClient state on node {self.software_manager.node.hostname}") super().reset_component_for_episode(episode) self._query_success_tracker.clear() @@ -195,4 +195,6 @@ class DatabaseClient(Application): self._query_success_tracker[query_id] = status_code == 200 if self._query_success_tracker[query_id]: _LOGGER.debug(f"Received payload {payload}") + else: + self.connected = False return True diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 88560240..8f12df4e 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -2,6 +2,7 @@ from ipaddress import IPv4Address from typing import Dict, Optional from urllib.parse import urlparse +from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.network.protocols.http import ( HttpRequestMethod, @@ -14,6 +15,8 @@ from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application from primaite.simulator.system.services.dns.dns_client import DNSClient +_LOGGER = getLogger(__name__) + class WebBrowser(Application): """ @@ -43,14 +46,14 @@ class WebBrowser(Application): def set_original_state(self): """Sets the original state.""" - print(f"Setting WebBrowser original state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Setting WebBrowser original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = {"target_url", "domain_name_ip_address", "latest_response"} self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print(f"Resetting WebBrowser state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Resetting WebBrowser state on node {self.software_manager.node.hostname}") super().reset_component_for_episode(episode) def _init_request_manager(self) -> RequestManager: diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 925d1df0..f9621ba5 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -2,6 +2,7 @@ from datetime import datetime from ipaddress import IPv4Address from typing import Any, Dict, List, Literal, Optional, Union +from primaite import getLogger from primaite.simulator.file_system.file_system import File from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -10,6 +11,8 @@ from primaite.simulator.system.services.ftp.ftp_client import FTPClient from primaite.simulator.system.services.service import Service, ServiceOperatingState from primaite.simulator.system.software import SoftwareHealthState +_LOGGER = getLogger(__name__) + class DatabaseService(Service): """ @@ -40,7 +43,7 @@ class DatabaseService(Service): def set_original_state(self): """Sets the original state.""" - print(f"Setting DatabaseService original state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Setting DatabaseService original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = { "password", diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 147387ae..2d3879ff 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -31,14 +31,13 @@ class DNSClient(Service): def set_original_state(self): """Sets the original state.""" - print(f"Setting DNSClient original state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Setting DNSClient original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = {"dns_server"} self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print(f"Resetting DNSClient state on node {self.software_manager.node.hostname}") self.dns_cache.clear() super().reset_component_for_episode(episode) diff --git a/src/primaite/simulator/system/services/dns/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py index 7842a07e..8decf7e9 100644 --- a/src/primaite/simulator/system/services/dns/dns_server.py +++ b/src/primaite/simulator/system/services/dns/dns_server.py @@ -30,14 +30,13 @@ class DNSServer(Service): def set_original_state(self): """Sets the original state.""" - print(f"Setting DNSServer original state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Setting DNSServer original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = {"dns_table"} self._original_state["dns_table_orig"] = self.model_dump(include=vals_to_include)["dns_table"] def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print(f"Resetting DNSServer state on node {self.software_manager.node.hostname}") self.dns_table.clear() for key, value in self._original_state["dns_table_orig"].items(): self.dns_table[key] = value diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 011b597f..23d52342 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -1,6 +1,7 @@ from ipaddress import IPv4Address from typing import Optional +from primaite import getLogger from primaite.simulator.file_system.file_system import File from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode from primaite.simulator.network.transmission.network_layer import IPProtocol @@ -9,6 +10,8 @@ from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC from primaite.simulator.system.services.service import ServiceOperatingState +_LOGGER = getLogger(__name__) + class FTPClient(FTPServiceABC): """ @@ -30,14 +33,14 @@ class FTPClient(FTPServiceABC): def set_original_state(self): """Sets the original state.""" - print(f"Setting FTPClient original state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Setting FTPClient original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = {"connected"} self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print(f"Resetting FTPClient state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Resetting FTPClient state on node {self.software_manager.node.hostname}") super().reset_component_for_episode(episode) def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 811a8939..44d0455f 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -1,12 +1,15 @@ from ipaddress import IPv4Address from typing import Any, Dict, Optional +from primaite import getLogger from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.ftp.ftp_service import FTPServiceABC from primaite.simulator.system.services.service import ServiceOperatingState +_LOGGER = getLogger(__name__) + class FTPServer(FTPServiceABC): """ @@ -31,14 +34,14 @@ class FTPServer(FTPServiceABC): def set_original_state(self): """Sets the original state.""" - print(f"Setting FTPServer original state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Setting FTPServer original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = {"server_password"} self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print(f"Resetting FTPServer state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Resetting FTPServer state on node {self.software_manager.node.hostname}") self.connections.clear() super().reset_component_for_episode(episode) diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index 75cdee85..44a56cf1 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -2,11 +2,14 @@ from enum import IntEnum from ipaddress import IPv4Address from typing import Optional +from primaite import getLogger from primaite.game.science import simulate_trial from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.database_client import DatabaseClient +_LOGGER = getLogger(__name__) + class DataManipulationAttackStage(IntEnum): """ @@ -49,7 +52,7 @@ class DataManipulationBot(DatabaseClient): def set_original_state(self): """Sets the original state.""" - print(f"Setting DataManipulationBot original state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Setting DataManipulationBot original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = { "server_ip_address", @@ -64,7 +67,7 @@ class DataManipulationBot(DatabaseClient): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print(f"Resetting DataManipulationBot state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Resetting DataManipulationBot state on node {self.software_manager.node.hostname}") super().reset_component_for_episode(episode) def _init_request_manager(self) -> RequestManager: diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index f34bba37..bff29a47 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -2,6 +2,7 @@ from ipaddress import IPv4Address from typing import Any, Dict, Optional from urllib.parse import urlparse +from primaite import getLogger from primaite.simulator.network.protocols.http import ( HttpRequestMethod, HttpRequestPacket, @@ -13,6 +14,8 @@ from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.service import Service +_LOGGER = getLogger(__name__) + class WebServer(Service): """Class used to represent a Web Server Service in simulation.""" @@ -21,14 +24,14 @@ class WebServer(Service): def set_original_state(self): """Sets the original state.""" - print(f"Setting WebServer original state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Setting WebServer original state on node {self.software_manager.node.hostname}") super().set_original_state() vals_to_include = {"last_response_status_code"} self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print(f"Resetting WebServer state on node {self.software_manager.node.hostname}") + _LOGGER.debug(f"Resetting WebServer state on node {self.software_manager.node.hostname}") super().reset_component_for_episode(episode) def describe_state(self) -> Dict: From a16116a688dc66c3a68efe671769c1c314eb899b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 29 Nov 2023 13:22:15 +0000 Subject: [PATCH 409/980] Fix file system reset error --- src/primaite/simulator/file_system/file_system.py | 2 +- src/primaite/simulator/file_system/folder.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 31a3c5a0..25a584c4 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -50,7 +50,7 @@ class FileSystem(SimComponent): """Reset the original state of the SimComponent.""" _LOGGER.debug(f"Resetting FileSystem state on node {self.sys_log.hostname}") # Move any 'original' folder that have been deleted back to folders - original_folder_uuids = self._original_state.pop("original_folder_uuids") + original_folder_uuids = self._original_state["original_folder_uuids"] for uuid in original_folder_uuids: if uuid in self.deleted_folders: self.folders[uuid] = self.deleted_folders.pop(uuid) diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index c45dd8c5..8fca4368 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -72,7 +72,7 @@ class Folder(FileSystemItemABC): """Reset the original state of the SimComponent.""" _LOGGER.debug(f"Resetting Folder ({self.name}) state on node {self.sys_log.hostname}") # Move any 'original' file that have been deleted back to files - original_file_uuids = self._original_state.pop("original_file_uuids") + original_file_uuids = self._original_state["original_file_uuids"] for uuid in original_file_uuids: if uuid in self.deleted_files: self.files[uuid] = self.deleted_files.pop(uuid) From ac2f7ba757b3313e054cdc802d841539cc922ee0 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 29 Nov 2023 14:33:52 +0000 Subject: [PATCH 410/980] Fix web browser tests. --- src/primaite/simulator/system/applications/web_browser.py | 4 ++-- tests/e2e_integration_tests/test_primaite_session.py | 4 ++++ tests/integration_tests/system/test_web_client_server.py | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 8f12df4e..1531314d 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -76,7 +76,7 @@ class WebBrowser(Application): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - def get_webpage(self) -> bool: + def get_webpage(self, url: Optional[str] = None) -> bool: """ Retrieve the webpage. @@ -85,7 +85,7 @@ class WebBrowser(Application): :param: url: The address of the web page the browser requests :type: url: str """ - url = self.target_url + url = url or self.target_url if not self._can_perform_action(): return False diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index 086e9af8..f2b6aa3f 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -76,6 +76,10 @@ class TestPrimaiteSession: with pytest.raises(pydantic.ValidationError): session = TempPrimaiteSession.from_config(MISCONFIGURED_PATH) + @pytest.mark.skip( + reason="Currently software cannot be dynamically created/destroyed during simulation. Therefore, " + "reset doesn't implement software restore." + ) @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) def test_session_sim_reset(self, temp_primaite_session): with temp_primaite_session as session: diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py index f2cc5b5d..3ee1e3ed 100644 --- a/tests/integration_tests/system/test_web_client_server.py +++ b/tests/integration_tests/system/test_web_client_server.py @@ -27,10 +27,11 @@ def test_web_page_get_users_page_request_with_domain_name(uc2_network): web_client: WebBrowser = client_1.software_manager.software["WebBrowser"] web_client.run() assert web_client.operating_state == ApplicationOperatingState.RUNNING + web_client.target_url = "http://arcd.com/users/" assert web_client.get_webpage() is True - # latest reponse should have status code 200 + # latest response should have status code 200 assert web_client.latest_response is not None assert web_client.latest_response.status_code == HttpStatusCode.OK From b2a52b2ec032a9482b8a75c0099229c33bc52247 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 29 Nov 2023 16:31:21 +0000 Subject: [PATCH 411/980] #2084: created a fixture that we can use to test things at a non end to end level --- src/primaite/simulator/network/networks.py | 12 ++- .../system/services/ftp/ftp_client.py | 5 +- tests/conftest.py | 82 +++++++++++++++++++ .../network/test_network_creation.py | 22 +++++ .../_system/_services/test_ftp_client.py | 72 ++++++++++++++++ 5 files changed, 190 insertions(+), 3 deletions(-) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index b7bd2e95..0b6fe8d4 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -51,14 +51,22 @@ def client_server_routed() -> Network: # Client 1 client_1 = Computer( - hostname="client_1", ip_address="192.168.2.2", subnet_mask="255.255.255.0", default_gateway="192.168.2.1" + hostname="client_1", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.2.1", + operating_state=NodeOperatingState.ON, ) client_1.power_on() network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) # Server 1 server_1 = Server( - hostname="server_1", ip_address="192.168.1.2", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + hostname="server_1", + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, ) server_1.power_on() network.connect(endpoint_b=server_1.ethernet_port[1], endpoint_a=switch_1.switch_ports[1]) diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index b73eec7e..263d09b4 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -264,8 +264,11 @@ class FTPClient(FTPServiceABC): This helps prevent an FTP request loop - FTP client and servers can exist on the same node. """ + if not self._can_perform_action(): + return False + if payload.status_code is None: - self.sys_log.error(f"FTP Server could not be found - Error Code: {payload.status_code.value}") + self.sys_log.error(f"FTP Server could not be found - Error Code: {FTPStatusCode.NOT_FOUND.value}") return False self.sys_log.info(f"{self.name}: Received FTP Response {payload.ftp_command.name} {payload.status_code.value}") diff --git a/tests/conftest.py b/tests/conftest.py index 8a1f885c..55db53c5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,7 +14,9 @@ from primaite.session.session import PrimaiteSession from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.network.networks import arcd_uc2_network from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -152,3 +154,83 @@ def client_server() -> Tuple[Computer, Server]: assert link.is_up return computer, server + + +@pytest.fixture(scope="function") +def example_network() -> Network: + """ + Create the network used for testing. + + Should only contain the nodes and links. + This would act as the base network and services and applications are installed in the relevant test file, + + -------------- -------------- + | client_1 |----- ----| server_1 | + -------------- | -------------- ------------ -------------- | -------------- + ------| switch_1 |------| router |------| switch_2 |------ + -------------- | -------------- ------------ -------------- | -------------- + | client_2 |---- ----| server_2 | + -------------- -------------- + """ + network = Network() + + # Router 1 + router_1 = Router(hostname="router_1", num_ports=5, operating_state=NodeOperatingState.ON) + router_1.configure_port(port=1, ip_address="192.168.1.1", subnet_mask="255.255.255.0") + router_1.configure_port(port=2, ip_address="192.168.10.1", subnet_mask="255.255.255.0") + + # Switch 1 + switch_1 = Switch(hostname="switch_1", num_ports=8, operating_state=NodeOperatingState.ON) + network.connect(endpoint_a=router_1.ethernet_ports[1], endpoint_b=switch_1.switch_ports[8]) + router_1.enable_port(1) + + # Switch 2 + switch_2 = Switch(hostname="switch_2", num_ports=8, operating_state=NodeOperatingState.ON) + network.connect(endpoint_a=router_1.ethernet_ports[2], endpoint_b=switch_2.switch_ports[8]) + router_1.enable_port(2) + + # Client 1 + client_1 = Computer( + hostname="client_1", + ip_address="192.168.10.21", + subnet_mask="255.255.255.0", + default_gateway="192.168.10.1", + operating_state=NodeOperatingState.ON, + ) + network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) + + # Client 2 + client_2 = Computer( + hostname="client_2", + ip_address="192.168.10.22", + subnet_mask="255.255.255.0", + default_gateway="192.168.10.1", + operating_state=NodeOperatingState.ON, + ) + network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) + + # Domain Controller + server_1 = Server( + hostname="server_1", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, + ) + + network.connect(endpoint_b=server_1.ethernet_port[1], endpoint_a=switch_1.switch_ports[1]) + + # Database Server + server_2 = Server( + hostname="server_2", + ip_address="192.168.1.14", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, + ) + network.connect(endpoint_b=server_2.ethernet_port[1], endpoint_a=switch_1.switch_ports[3]) + + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) + router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + + return network diff --git a/tests/integration_tests/network/test_network_creation.py b/tests/integration_tests/network/test_network_creation.py index 91218068..0af44dbb 100644 --- a/tests/integration_tests/network/test_network_creation.py +++ b/tests/integration_tests/network/test_network_creation.py @@ -2,6 +2,28 @@ import pytest from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.base import NIC, Node +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.networks import client_server_routed + + +def test_network(example_network): + network: Network = example_network + client_1: Computer = network.get_node_by_hostname("client_1") + client_2: Computer = network.get_node_by_hostname("client_2") + server_1: Server = network.get_node_by_hostname("server_1") + server_2: Server = network.get_node_by_hostname("server_2") + + assert client_1.ping(client_2.ethernet_port[1].ip_address) + assert client_2.ping(client_1.ethernet_port[1].ip_address) + + assert server_1.ping(server_2.ethernet_port[1].ip_address) + assert server_2.ping(server_1.ethernet_port[1].ip_address) + + assert client_1.ping(server_1.ethernet_port[1].ip_address) + assert client_2.ping(server_1.ethernet_port[1].ip_address) + assert client_1.ping(server_2.ethernet_port[1].ip_address) + assert client_2.ping(server_2.ethernet_port[1].ip_address) def test_adding_removing_nodes(): diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py index c079ebc4..1d7355a2 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py @@ -1,3 +1,5 @@ +from ipaddress import IPv4Address + import pytest from primaite.simulator.network.hardware.base import Node @@ -7,6 +9,7 @@ from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPS from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.service import ServiceOperatingState @pytest.fixture(scope="function") @@ -48,3 +51,72 @@ def test_ftp_client_store_file(ftp_client): ftp_client_service.receive(response) assert ftp_client.file_system.get_file(folder_name="downloads", file_name="file.txt") + + +def test_ftp_should_not_process_commands_if_service_not_running(ftp_client): + """Method _process_ftp_command should return false if service is not running.""" + payload: FTPPacket = FTPPacket( + ftp_command=FTPCommand.PORT, + ftp_command_args=Port.FTP, + status_code=FTPStatusCode.OK, + ) + + ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + ftp_client_service.stop() + assert ftp_client_service.operating_state is ServiceOperatingState.STOPPED + assert ftp_client_service._process_ftp_command(payload=payload).status_code is FTPStatusCode.ERROR + + +def test_ftp_tries_to_senf_file__that_does_not_exist(ftp_client): + """Method send_file should return false if no file to send.""" + assert ftp_client.file_system.get_file(folder_name="root", file_name="test.txt") is None + + ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + assert ftp_client_service.operating_state is ServiceOperatingState.RUNNING + assert ( + ftp_client_service.send_file( + dest_ip_address=IPv4Address("192.168.1.1"), + src_folder_name="root", + src_file_name="test.txt", + dest_folder_name="root", + dest_file_name="text.txt", + ) + is False + ) + + +def test_offline_ftp_client_receives_request(ftp_client): + """Receive should return false if the node the ftp client is installed on is offline.""" + ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + ftp_client.power_off() + + for i in range(ftp_client.shut_down_duration + 1): + ftp_client.apply_timestep(timestep=i) + + assert ftp_client.operating_state is NodeOperatingState.OFF + assert ftp_client_service.operating_state is ServiceOperatingState.STOPPED + + payload: FTPPacket = FTPPacket( + ftp_command=FTPCommand.PORT, + ftp_command_args=Port.FTP, + status_code=FTPStatusCode.OK, + ) + + assert ftp_client_service.receive(payload=payload) is False + + +def test_receive_should_fail_if_payload_is_not_ftp(ftp_client): + """Receive should return false if the node the ftp client is installed on is not an FTPPacket.""" + ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + assert ftp_client_service.receive(payload=None) is False + + +def test_receive_should_ignore_payload_with_none_status_code(ftp_client): + """Receive should ignore payload with no set status code to prevent infinite send/receive loops.""" + payload: FTPPacket = FTPPacket( + ftp_command=FTPCommand.PORT, + ftp_command_args=Port.FTP, + status_code=None, + ) + ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + assert ftp_client_service.receive(payload=payload) is False From 9d39458ef39cea3a33608bf66d5096eb917d6b1d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 29 Nov 2023 22:30:12 +0000 Subject: [PATCH 412/980] Deleted sandbox.py --- sandbox.py | 72 ------------------------------------------------------ 1 file changed, 72 deletions(-) delete mode 100644 sandbox.py diff --git a/sandbox.py b/sandbox.py deleted file mode 100644 index b08f15b1..00000000 --- a/sandbox.py +++ /dev/null @@ -1,72 +0,0 @@ -from primaite.config.load import example_config_path, load -from primaite.session.session import PrimaiteSession -from primaite.simulator.system.applications.database_client import DatabaseClient -from primaite.simulator.system.applications.web_browser import WebBrowser -from primaite.simulator.system.services.dns.dns_client import DNSClient - -cfg = load(example_config_path()) -session = PrimaiteSession.from_config(cfg) -network = session.game.simulation.network - -dc = network.get_node_by_hostname("domain_controller") -router = network.get_node_by_hostname("router_1") -client_1 = network.get_node_by_hostname("client_1") -client_2 = network.get_node_by_hostname("client_2") -switch_1 = network.get_node_by_hostname("switch_1") -switch_2 = network.get_node_by_hostname("switch_2") -web_server = network.get_node_by_hostname("web_server") - -dns_server = dc.software_manager.software["DNSServer"] -dns_client: DNSClient = client_2.software_manager.software["DNSClient"] -web_db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] -web_browser: WebBrowser = client_2.software_manager.software["WebBrowser"] - -# print("before calling get webpage") -# router.acl.show() -# dns_server.show() -# client_2.arp.show() -# router.arp.show() -# print() - -# print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) -# print("after calling get webpage") -# router.acl.show() -# dns_server.show() -# client_2.arp.show() -# router.arp.show() -# print() -# print("reset") -# print() -# print("im gonna reset") -# print() - -# web_db_client.connect() -# web_db_client.run() -# web_browser.run() -# print("client_2", client_2.operating_state) -# print("web_browser", web_browser.operating_state) -# print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) -session.game.reset() -print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) -session.game.reset() -print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) -session.game.reset() -print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) -session.game.reset() -print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) -# print() -# -# print("before calling get webpage") -# router.acl.show() -# dns_server.show() -# client_2.arp.show() -# router.arp.show() -# print() -# -# print("can get webpage", client_2.software_manager.software["WebBrowser"].get_webpage()) -# print("after calling get webpage") -# router.acl.show() -# dns_server.show() -# client_2.arp.show() -# router.arp.show() -# print() From 7c1ffb5ba16f0cecfa1300693329f2fc16a49d6f Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 30 Nov 2023 13:48:57 +0000 Subject: [PATCH 413/980] #2084: change all instances of retrieving software from software['software_name'] to software.get() + adding some tests for describe state --- .../simulation_components/system/data_manipulation_bot.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/simulation_components/system/data_manipulation_bot.rst b/docs/source/simulation_components/system/data_manipulation_bot.rst index 5180974f..e9cfde71 100644 --- a/docs/source/simulation_components/system/data_manipulation_bot.rst +++ b/docs/source/simulation_components/system/data_manipulation_bot.rst @@ -54,7 +54,7 @@ Example ) network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) client_1.software_manager.install(DataManipulationBot) - data_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] + data_manipulation_bot: DataManipulationBot = client_1.software_manager.software.get("DataManipulationBot") data_manipulation_bot.configure(server_ip_address=IPv4Address("192.168.1.14"), payload="DELETE") data_manipulation_bot.run() From 3cf21e4015ece84c50584352b0b02beeec74a3b4 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 30 Nov 2023 13:49:37 +0000 Subject: [PATCH 414/980] #2084: change all instances of retrieving software from software['software_name'] to software.get() + adding some tests for describe state --- .../simulation_components/system/software.rst | 2 +- src/primaite/simulator/domain/account.py | 2 +- src/primaite/simulator/network/networks.py | 10 +- .../system/applications/database_client.py | 5 +- .../system/applications/web_browser.py | 2 +- .../services/database/database_service.py | 4 +- .../simulator/system/services/service.py | 4 +- .../system/services/web_server/web_server.py | 2 +- tests/conftest.py | 2 +- .../environments/test_sb3_environment.py | 2 +- .../test_primaite_session.py | 2 +- .../test_uc2_data_manipulation_scenario.py | 6 +- .../system/test_application_on_node.py | 4 +- .../system/test_database_on_node.py | 24 ++-- .../system/test_dns_client_server.py | 4 +- .../system/test_ftp_client_server.py | 4 +- .../system/test_service_on_node.py | 4 +- .../system/test_web_client_server.py | 8 +- .../test_web_client_server_and_database.py | 14 +- .../_simulator/_domain/test_account.py | 134 +++++++++++++++++- .../_simulator/_network/test_container.py | 66 +++++++-- .../_applications/test_database_client.py | 122 ++++++++++++++++ .../_system/_applications/test_web_browser.py | 4 +- .../test_data_manipulation_bot.py | 4 +- .../_system/_services/test_database.py | 2 +- .../_system/_services/test_dns_client.py | 12 +- .../_system/_services/test_dns_server.py | 6 +- .../_system/_services/test_ftp_client.py | 14 +- .../_system/_services/test_ftp_server.py | 10 +- .../_system/_services/test_web_server.py | 12 +- 30 files changed, 394 insertions(+), 97 deletions(-) create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py diff --git a/docs/source/simulation_components/system/software.rst b/docs/source/simulation_components/system/software.rst index 1e5a0b6b..cd6b0aa3 100644 --- a/docs/source/simulation_components/system/software.rst +++ b/docs/source/simulation_components/system/software.rst @@ -28,7 +28,7 @@ See :ref:`Node Start up and Shut down` node.software_manager.install(WebServer) - web_server: WebServer = node.software_manager.software["WebServer"] + web_server: WebServer = node.software_manager.software.get("WebServer") assert web_server.operating_state is ServiceOperatingState.RUNNING # service is immediately ran after install node.power_off() diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py index 1402a474..d9dad06a 100644 --- a/src/primaite/simulator/domain/account.py +++ b/src/primaite/simulator/domain/account.py @@ -72,7 +72,7 @@ class Account(SimComponent): "num_group_changes": self.num_group_changes, "username": self.username, "password": self.password, - "account_type": self.account_type.name, + "account_type": self.account_type.value, "enabled": self.enabled, } ) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 0b6fe8d4..4cd9c8d3 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -147,7 +147,7 @@ def arcd_uc2_network() -> Network: client_1.power_on() network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) client_1.software_manager.install(DataManipulationBot) - db_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] + db_manipulation_bot: DataManipulationBot = client_1.software_manager.software.get("DataManipulationBot") db_manipulation_bot.configure( server_ip_address=IPv4Address("192.168.1.14"), payload="DELETE", @@ -165,7 +165,7 @@ def arcd_uc2_network() -> Network: operating_state=NodeOperatingState.ON, ) client_2.power_on() - web_browser = client_2.software_manager.software["WebBrowser"] + web_browser = client_2.software_manager.software.get("WebBrowser") web_browser.target_url = "http://arcd.com/users/" network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) @@ -249,7 +249,7 @@ def arcd_uc2_network() -> Network: # noqa ] database_server.software_manager.install(DatabaseService) - database_service: DatabaseService = database_server.software_manager.software["DatabaseService"] # noqa + database_service: DatabaseService = database_server.software_manager.software.get("DatabaseService") # noqa database_service.start() database_service.configure_backup(backup_server=IPv4Address("192.168.1.16")) database_service._process_sql(ddl, None) # noqa @@ -268,7 +268,7 @@ def arcd_uc2_network() -> Network: web_server.power_on() web_server.software_manager.install(DatabaseClient) - database_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + database_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") database_client.configure(server_ip_address=IPv4Address("192.168.1.14")) network.connect(endpoint_b=web_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[2]) database_client.run() @@ -277,7 +277,7 @@ def arcd_uc2_network() -> Network: web_server.software_manager.install(WebServer) # register the web_server to a domain - dns_server_service: DNSServer = domain_controller.software_manager.software["DNSServer"] # noqa + dns_server_service: DNSServer = domain_controller.software_manager.software.get("DNSServer") # noqa dns_server_service.dns_register("arcd.com", web_server.ip_address) # Backup Server diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 7b63d26e..8c43c0b7 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -107,7 +107,7 @@ class DatabaseClient(Application): def disconnect(self): """Disconnect from the Database Service.""" - if self.connected and self.operating_state.RUNNING: + if self.connected and self.operating_state is ApplicationOperatingState.RUNNING: software_manager: SoftwareManager = self.software_manager software_manager.send_payload_to_session_manager( payload={"type": "disconnect"}, dest_ip_address=self.server_ip_address, dest_port=self.port @@ -186,6 +186,9 @@ class DatabaseClient(Application): :param session_id: The session id the payload relates to. :return: True. """ + if not self._can_perform_action(): + return False + if isinstance(payload, dict) and payload.get("type"): if payload["type"] == "connect_response": self.connected = payload["response"] == True diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 1531314d..7533f6f3 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -99,7 +99,7 @@ class WebBrowser(Application): return False # get the IP address of the domain name via DNS - dns_client: DNSClient = self.software_manager.software["DNSClient"] + dns_client: DNSClient = self.software_manager.software.get("DNSClient") domain_exists = dns_client.check_domain_exists(target_domain=parsed_url.hostname) # if domain does not exist, the request fails diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index f9621ba5..6a7c80ca 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -80,7 +80,7 @@ class DatabaseService(Service): return False software_manager: SoftwareManager = self.software_manager - ftp_client_service: FTPClient = software_manager.software["FTPClient"] + ftp_client_service: FTPClient = software_manager.software.get("FTPClient") # send backup copy of database file to FTP server response = ftp_client_service.send_file( @@ -104,7 +104,7 @@ class DatabaseService(Service): return False software_manager: SoftwareManager = self.software_manager - ftp_client_service: FTPClient = software_manager.software["FTPClient"] + ftp_client_service: FTPClient = software_manager.software.get("FTPClient") # retrieve backup file from backup server response = ftp_client_service.request_file( diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 6d6cda86..e60b7700 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -109,8 +109,8 @@ class Service(IOSoftware): """ state = super().describe_state() state["operating_state"] = self.operating_state.value - state["health_state_actual"] = self.health_state_actual - state["health_state_visible"] = self.health_state_visible + state["health_state_actual"] = self.health_state_actual.value + state["health_state_visible"] = self.health_state_visible.value return state def stop(self) -> None: diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index bff29a47..e63b875a 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -120,7 +120,7 @@ class WebServer(Service): if path.startswith("users"): # get data from DatabaseServer - db_client: DatabaseClient = self.software_manager.software["DatabaseClient"] + db_client: DatabaseClient = self.software_manager.software.get("DatabaseClient") # get all users if db_client.query("SELECT"): # query succeeded diff --git a/tests/conftest.py b/tests/conftest.py index 55db53c5..c81e4b98 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -228,7 +228,7 @@ def example_network() -> Network: default_gateway="192.168.1.1", operating_state=NodeOperatingState.ON, ) - network.connect(endpoint_b=server_2.ethernet_port[1], endpoint_a=switch_1.switch_ports[3]) + network.connect(endpoint_b=server_2.ethernet_port[1], endpoint_a=switch_1.switch_ports[2]) router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) diff --git a/tests/e2e_integration_tests/environments/test_sb3_environment.py b/tests/e2e_integration_tests/environments/test_sb3_environment.py index c1c028a2..91cf5c1e 100644 --- a/tests/e2e_integration_tests/environments/test_sb3_environment.py +++ b/tests/e2e_integration_tests/environments/test_sb3_environment.py @@ -11,7 +11,7 @@ from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteGymEnv -@pytest.mark.skip(reason="no way of currently testing this") +# @pytest.mark.skip(reason="no way of currently testing this") def test_sb3_compatibility(): """Test that the Gymnasium environment can be used with an SB3 agent.""" with open(example_config_path(), "r") as f: diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index ed10ca24..7785e4ae 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -11,7 +11,7 @@ MISCONFIGURED_PATH = TEST_ASSETS_ROOT / "configs/bad_primaite_session.yaml" MULTI_AGENT_PATH = TEST_ASSETS_ROOT / "configs/multi_agent_session.yaml" -@pytest.mark.skip(reason="no way of currently testing this") +# @pytest.mark.skip(reason="no way of currently testing this") class TestPrimaiteSession: @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) def test_creating_session(self, temp_primaite_session): diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index 81bbfc96..0dc2c031 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -8,13 +8,13 @@ from primaite.simulator.system.services.red_services.data_manipulation_bot impor def test_data_manipulation(uc2_network): """Tests the UC2 data manipulation scenario end-to-end. Is a work in progress.""" client_1: Computer = uc2_network.get_node_by_hostname("client_1") - db_manipulation_bot: DataManipulationBot = client_1.software_manager.software["DataManipulationBot"] + db_manipulation_bot: DataManipulationBot = client_1.software_manager.software.get("DataManipulationBot") database_server: Server = uc2_network.get_node_by_hostname("database_server") - db_service: DatabaseService = database_server.software_manager.software["DatabaseService"] + db_service: DatabaseService = database_server.software_manager.software.get("DatabaseService") web_server: Server = uc2_network.get_node_by_hostname("web_server") - db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") db_service.backup_database() diff --git a/tests/integration_tests/system/test_application_on_node.py b/tests/integration_tests/system/test_application_on_node.py index cce586da..46be5e55 100644 --- a/tests/integration_tests/system/test_application_on_node.py +++ b/tests/integration_tests/system/test_application_on_node.py @@ -18,7 +18,7 @@ def populated_node(application_class) -> Tuple[Application, Computer]: ) computer.software_manager.install(application_class) - app = computer.software_manager.software["TestApplication"] + app = computer.software_manager.software.get("TestApplication") app.run() return app, computer @@ -35,7 +35,7 @@ def test_service_on_offline_node(application_class): ) computer.software_manager.install(application_class) - app: Application = computer.software_manager.software["TestApplication"] + app: Application = computer.software_manager.software.get("TestApplication") computer.power_off() diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index ef2b2956..98c8c87b 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -10,10 +10,10 @@ from primaite.simulator.system.services.service import ServiceOperatingState def test_database_client_server_connection(uc2_network): web_server: Server = uc2_network.get_node_by_hostname("web_server") - db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") db_server: Server = uc2_network.get_node_by_hostname("database_server") - db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService") assert len(db_service.connections) == 1 @@ -23,10 +23,10 @@ def test_database_client_server_connection(uc2_network): def test_database_client_server_correct_password(uc2_network): web_server: Server = uc2_network.get_node_by_hostname("web_server") - db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") db_server: Server = uc2_network.get_node_by_hostname("database_server") - db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService") db_client.disconnect() @@ -40,10 +40,10 @@ def test_database_client_server_correct_password(uc2_network): def test_database_client_server_incorrect_password(uc2_network): web_server: Server = uc2_network.get_node_by_hostname("web_server") - db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") db_server: Server = uc2_network.get_node_by_hostname("database_server") - db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService") db_client.disconnect() db_client.configure(server_ip_address=IPv4Address("192.168.1.14"), server_password="54321") @@ -56,7 +56,7 @@ def test_database_client_server_incorrect_password(uc2_network): def test_database_client_query(uc2_network): """Tests DB query across the network returns HTTP status 200 and date.""" web_server: Server = uc2_network.get_node_by_hostname("web_server") - db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") assert db_client.connected @@ -66,13 +66,13 @@ def test_database_client_query(uc2_network): def test_create_database_backup(uc2_network): """Run the backup_database method and check if the FTP server has the relevant file.""" db_server: Server = uc2_network.get_node_by_hostname("database_server") - db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService") # back up should be created assert db_service.backup_database() is True backup_server: Server = uc2_network.get_node_by_hostname("backup_server") - ftp_server: FTPServer = backup_server.software_manager.software["FTPServer"] + ftp_server: FTPServer = backup_server.software_manager.software.get("FTPServer") # backup file should exist in the backup server assert ftp_server.file_system.get_file(folder_name=db_service.uuid, file_name="database.db") is not None @@ -81,7 +81,7 @@ def test_create_database_backup(uc2_network): def test_restore_backup(uc2_network): """Run the restore_backup method and check if the backup is properly restored.""" db_server: Server = uc2_network.get_node_by_hostname("database_server") - db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService") # create a back up assert db_service.backup_database() is True @@ -100,13 +100,13 @@ def test_restore_backup(uc2_network): def test_database_client_cannot_query_offline_database_server(uc2_network): """Tests DB query across the network returns HTTP status 404 when db server is offline.""" db_server: Server = uc2_network.get_node_by_hostname("database_server") - db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService") assert db_server.operating_state is NodeOperatingState.ON assert db_service.operating_state is ServiceOperatingState.RUNNING web_server: Server = uc2_network.get_node_by_hostname("web_server") - db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") assert db_client.connected assert db_client.query("SELECT") is True diff --git a/tests/integration_tests/system/test_dns_client_server.py b/tests/integration_tests/system/test_dns_client_server.py index 70657112..a54bf23f 100644 --- a/tests/integration_tests/system/test_dns_client_server.py +++ b/tests/integration_tests/system/test_dns_client_server.py @@ -17,14 +17,14 @@ def dns_client_and_dns_server(client_server) -> Tuple[DNSClient, Computer, DNSSe # Install DNS Client on computer computer.software_manager.install(DNSClient) - dns_client: DNSClient = computer.software_manager.software["DNSClient"] + dns_client: DNSClient = computer.software_manager.software.get("DNSClient") dns_client.start() # set server as DNS Server dns_client.dns_server = IPv4Address(server.nics.get(next(iter(server.nics))).ip_address) # Install DNS Server on server server.software_manager.install(DNSServer) - dns_server: DNSServer = server.software_manager.software["DNSServer"] + dns_server: DNSServer = server.software_manager.software.get("DNSServer") dns_server.start() # register arcd.com as a domain dns_server.dns_register( diff --git a/tests/integration_tests/system/test_ftp_client_server.py b/tests/integration_tests/system/test_ftp_client_server.py index 32ea7f2b..1a6a8f41 100644 --- a/tests/integration_tests/system/test_ftp_client_server.py +++ b/tests/integration_tests/system/test_ftp_client_server.py @@ -16,12 +16,12 @@ def ftp_client_and_ftp_server(client_server) -> Tuple[FTPClient, Computer, FTPSe # Install FTP Client service on computer computer.software_manager.install(FTPClient) - ftp_client: FTPClient = computer.software_manager.software["FTPClient"] + ftp_client: FTPClient = computer.software_manager.software.get("FTPClient") ftp_client.start() # Install FTP Server service on server server.software_manager.install(FTPServer) - ftp_server: FTPServer = server.software_manager.software["FTPServer"] + ftp_server: FTPServer = server.software_manager.software.get("FTPServer") ftp_server.start() return ftp_client, computer, ftp_server, server diff --git a/tests/integration_tests/system/test_service_on_node.py b/tests/integration_tests/system/test_service_on_node.py index 9480c358..aab1e4da 100644 --- a/tests/integration_tests/system/test_service_on_node.py +++ b/tests/integration_tests/system/test_service_on_node.py @@ -17,7 +17,7 @@ def populated_node( ) server.software_manager.install(service_class) - service = server.software_manager.software["TestService"] + service = server.software_manager.software.get("TestService") service.start() return server, service @@ -34,7 +34,7 @@ def test_service_on_offline_node(service_class): ) computer.software_manager.install(service_class) - service: Service = computer.software_manager.software["TestService"] + service: Service = computer.software_manager.software.get("TestService") computer.power_off() diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py index 41982805..b3d2e891 100644 --- a/tests/integration_tests/system/test_web_client_server.py +++ b/tests/integration_tests/system/test_web_client_server.py @@ -19,23 +19,23 @@ def web_client_and_web_server(client_server) -> Tuple[WebBrowser, Computer, WebS # Install Web Browser on computer computer.software_manager.install(WebBrowser) - web_browser: WebBrowser = computer.software_manager.software["WebBrowser"] + web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser") web_browser.run() # Install DNS Client service on computer computer.software_manager.install(DNSClient) - dns_client: DNSClient = computer.software_manager.software["DNSClient"] + dns_client: DNSClient = computer.software_manager.software.get("DNSClient") # set dns server dns_client.dns_server = server.nics[next(iter(server.nics))].ip_address # Install Web Server service on server server.software_manager.install(WebServer) - web_server_service: WebServer = server.software_manager.software["WebServer"] + web_server_service: WebServer = server.software_manager.software.get("WebServer") web_server_service.start() # Install DNS Server service on server server.software_manager.install(DNSServer) - dns_server: DNSServer = server.software_manager.software["DNSServer"] + dns_server: DNSServer = server.software_manager.software.get("DNSServer") # register arcd.com to DNS dns_server.dns_register(domain_name="arcd.com", domain_ip_address=server.nics[next(iter(server.nics))].ip_address) diff --git a/tests/integration_tests/system/test_web_client_server_and_database.py b/tests/integration_tests/system/test_web_client_server_and_database.py index d7b5603d..17458968 100644 --- a/tests/integration_tests/system/test_web_client_server_and_database.py +++ b/tests/integration_tests/system/test_web_client_server_and_database.py @@ -60,28 +60,28 @@ def web_client_web_server_database() -> Tuple[Computer, Server, Server]: # Install DatabaseService on db server db_server.software_manager.install(DatabaseService) - db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService") db_service.start() # Install Web Browser on computer computer.software_manager.install(WebBrowser) - web_browser: WebBrowser = computer.software_manager.software["WebBrowser"] + web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser") web_browser.run() # Install DNS Client service on computer computer.software_manager.install(DNSClient) - dns_client: DNSClient = computer.software_manager.software["DNSClient"] + dns_client: DNSClient = computer.software_manager.software.get("DNSClient") # set dns server dns_client.dns_server = web_server.nics[next(iter(web_server.nics))].ip_address # Install Web Server service on web server web_server.software_manager.install(WebServer) - web_server_service: WebServer = web_server.software_manager.software["WebServer"] + web_server_service: WebServer = web_server.software_manager.software.get("WebServer") web_server_service.start() # Install DNS Server service on web server web_server.software_manager.install(DNSServer) - dns_server: DNSServer = web_server.software_manager.software["DNSServer"] + dns_server: DNSServer = web_server.software_manager.software.get("DNSServer") # register arcd.com to DNS dns_server.dns_register( domain_name="arcd.com", domain_ip_address=web_server.nics[next(iter(web_server.nics))].ip_address @@ -89,7 +89,7 @@ def web_client_web_server_database() -> Tuple[Computer, Server, Server]: # Install DatabaseClient service on web server web_server.software_manager.install(DatabaseClient) - db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") db_client.server_ip_address = IPv4Address(db_server_nic.ip_address) # set IP address of Database Server db_client.run() assert db_client.connect() @@ -101,6 +101,6 @@ def web_client_web_server_database() -> Tuple[Computer, Server, Server]: def test_web_client_requests_users(web_client_web_server_database): computer, web_server, db_server = web_client_web_server_database - web_browser: WebBrowser = computer.software_manager.software["WebBrowser"] + web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser") web_browser.get_webpage() diff --git a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py index 96c34996..01ad3871 100644 --- a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py +++ b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py @@ -1,18 +1,140 @@ """Test the account module of the simulator.""" +import pytest + from primaite.simulator.domain.account import Account, AccountType -def test_account_serialise(): +@pytest.fixture(scope="function") +def account() -> Account: + acct = Account(username="Jake", password="totally_hashed_password", account_type=AccountType.USER) + acct.set_original_state() + return acct + + +def test_original_state(account): + """Test the original state - see if it resets properly""" + account.log_on() + account.log_off() + account.disable() + + state = account.describe_state() + assert state["num_logons"] is 1 + assert state["num_logoffs"] is 1 + assert state["num_group_changes"] is 0 + assert state["username"] is "Jake" + assert state["password"] is "totally_hashed_password" + assert state["account_type"] is AccountType.USER.value + assert state["enabled"] is False + + account.reset_component_for_episode(episode=1) + state = account.describe_state() + assert state["num_logons"] is 0 + assert state["num_logoffs"] is 0 + assert state["num_group_changes"] is 0 + assert state["username"] is "Jake" + assert state["password"] is "totally_hashed_password" + assert state["account_type"] is AccountType.USER.value + assert state["enabled"] is True + + account.log_on() + account.log_off() + account.disable() + account.set_original_state() + + account.log_on() + state = account.describe_state() + assert state["num_logons"] is 2 + + account.reset_component_for_episode(episode=2) + state = account.describe_state() + assert state["num_logons"] is 1 + assert state["num_logoffs"] is 1 + assert state["num_group_changes"] is 0 + assert state["username"] is "Jake" + assert state["password"] is "totally_hashed_password" + assert state["account_type"] is AccountType.USER.value + assert state["enabled"] is False + + +def test_enable(account): + """Should enable the account.""" + account.enabled = False + account.enable() + assert account.enabled is True + + +def test_disable(account): + """Should disable the account.""" + account.enabled = True + account.disable() + assert account.enabled is False + + +def test_log_on_increments(account): + """Should increase the log on value by 1.""" + account.num_logons = 0 + account.log_on() + assert account.num_logons is 1 + + +def test_log_off_increments(account): + """Should increase the log on value by 1.""" + account.num_logoffs = 0 + account.log_off() + assert account.num_logoffs is 1 + + +def test_account_serialise(account): """Test that an account can be serialised. If pydantic throws error then this test fails.""" - acct = Account(username="Jake", password="JakePass1!", account_type=AccountType.USER) - serialised = acct.model_dump_json() + serialised = account.model_dump_json() print(serialised) -def test_account_deserialise(): +def test_account_deserialise(account): """Test that an account can be deserialised. The test fails if pydantic throws an error.""" acct_json = ( '{"uuid":"dfb2bcaa-d3a1-48fd-af3f-c943354622b4","num_logons":0,"num_logoffs":0,"num_group_changes":0,' - '"username":"Jake","password":"JakePass1!","account_type":2,"status":2,"request_manager":null}' + '"username":"Jake","password":"totally_hashed_password","account_type":2,"status":2,"request_manager":null}' ) - acct = Account.model_validate_json(acct_json) + assert Account.model_validate_json(acct_json) + + +def test_describe_state(account): + state = account.describe_state() + assert state["num_logons"] is 0 + assert state["num_logoffs"] is 0 + assert state["num_group_changes"] is 0 + assert state["username"] is "Jake" + assert state["password"] is "totally_hashed_password" + assert state["account_type"] is AccountType.USER.value + assert state["enabled"] is True + + account.log_on() + state = account.describe_state() + assert state["num_logons"] is 1 + assert state["num_logoffs"] is 0 + assert state["num_group_changes"] is 0 + assert state["username"] is "Jake" + assert state["password"] is "totally_hashed_password" + assert state["account_type"] is AccountType.USER.value + assert state["enabled"] is True + + account.log_off() + state = account.describe_state() + assert state["num_logons"] is 1 + assert state["num_logoffs"] is 1 + assert state["num_group_changes"] is 0 + assert state["username"] is "Jake" + assert state["password"] is "totally_hashed_password" + assert state["account_type"] is AccountType.USER.value + assert state["enabled"] is True + + account.disable() + state = account.describe_state() + assert state["num_logons"] is 1 + assert state["num_logoffs"] is 1 + assert state["num_group_changes"] is 0 + assert state["username"] is "Jake" + assert state["password"] is "totally_hashed_password" + assert state["account_type"] is AccountType.USER.value + assert state["enabled"] is False diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index 66bd59a9..92b3a91b 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -3,6 +3,64 @@ import json import pytest from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.services.database.database_service import DatabaseService + + +@pytest.fixture(scope="function") +def network(example_network) -> Network: + assert len(example_network.routers) is 1 + assert len(example_network.switches) is 2 + assert len(example_network.computers) is 2 + assert len(example_network.servers) is 2 + + example_network.set_original_state() + + return example_network + + +def test_describe_state(example_network): + """Test that describe state works.""" + state = example_network.describe_state() + + assert len(state["nodes"]) is 7 + assert len(state["links"]) is 6 + + +def test_reset_network(example_network): + """ + Test that the network is properly reset. + + TODO: make sure that once implemented - any installed/uninstalled services, processes, apps, + etc are also removed/reinstalled + + """ + state_before = example_network.describe_state() + + client_1: Computer = example_network.get_node_by_hostname("client_1") + server_1: Computer = example_network.get_node_by_hostname("server_1") + + assert client_1.operating_state is NodeOperatingState.ON + assert server_1.operating_state is NodeOperatingState.ON + + client_1.power_off() + assert client_1.operating_state is NodeOperatingState.SHUTTING_DOWN + + server_1.power_off() + assert server_1.operating_state is NodeOperatingState.SHUTTING_DOWN + + assert example_network.describe_state() is not state_before + + example_network.reset_component_for_episode(episode=1) + + assert client_1.operating_state is NodeOperatingState.ON + assert server_1.operating_state is NodeOperatingState.ON + + assert json.dumps(example_network.describe_state(), sort_keys=True, indent=2) == json.dumps( + state_before, sort_keys=True, indent=2 + ) def test_creating_container(): @@ -10,11 +68,3 @@ def test_creating_container(): net = Network() assert net.nodes == {} assert net.links == {} - - -@pytest.mark.skip(reason="Skipping until we tackle serialisation") -def test_describe_state(): - """Check that we can describe network state without raising errors, and that the result is JSON serialisable.""" - net = Network() - state = net.describe_state() - json.dumps(state) # if this function call raises an error, the test fails, state was not JSON-serialisable diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py new file mode 100644 index 00000000..59d44561 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py @@ -0,0 +1,122 @@ +from ipaddress import IPv4Address +from typing import Tuple, Union + +import pytest + +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.system.applications.application import ApplicationOperatingState +from primaite.simulator.system.applications.database_client import DatabaseClient + + +@pytest.fixture(scope="function") +def database_client_on_computer() -> Tuple[DatabaseClient, Computer]: + computer = Computer( + hostname="db_node", ip_address="192.168.0.1", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON + ) + computer.software_manager.install(DatabaseClient) + + database_client: DatabaseClient = computer.software_manager.software.get("DatabaseClient") + database_client.configure(server_ip_address=IPv4Address("192.168.0.1")) + database_client.run() + return database_client, computer + + +def test_creation(database_client_on_computer): + database_client, computer = database_client_on_computer + database_client.describe_state() + + +def test_connect_when_client_is_closed(database_client_on_computer): + """Database client should not connect when it is not running.""" + database_client, computer = database_client_on_computer + + database_client.close() + assert database_client.operating_state is ApplicationOperatingState.CLOSED + + assert database_client.connect() is False + + +def test_connect_to_database_fails_on_reattempt(database_client_on_computer): + """Database client should return False when the attempt to connect fails.""" + database_client, computer = database_client_on_computer + + database_client.connected = False + assert database_client._connect(server_ip_address=IPv4Address("192.168.0.1"), is_reattempt=True) is False + + +def test_disconnect_when_client_is_closed(database_client_on_computer): + """Database client disconnect should not do anything when it is not running.""" + database_client, computer = database_client_on_computer + + database_client.connected = True + assert database_client.server_ip_address is not None + + database_client.close() + assert database_client.operating_state is ApplicationOperatingState.CLOSED + + database_client.disconnect() + + assert database_client.connected is True + assert database_client.server_ip_address is not None + + +def test_disconnect(database_client_on_computer): + """Database client should set connected to False and remove the database server ip address.""" + database_client, computer = database_client_on_computer + + database_client.connected = True + + assert database_client.operating_state is ApplicationOperatingState.RUNNING + assert database_client.server_ip_address is not None + + database_client.disconnect() + + assert database_client.connected is False + assert database_client.server_ip_address is None + + +def test_query_when_client_is_closed(database_client_on_computer): + """Database client should return False when it is not running.""" + database_client, computer = database_client_on_computer + + database_client.close() + assert database_client.operating_state is ApplicationOperatingState.CLOSED + + assert database_client.query(sql="test") is False + + +def test_query_failed_reattempt(database_client_on_computer): + """Database client query should return False if the reattempt fails.""" + database_client, computer = database_client_on_computer + + def return_false(): + return False + + database_client.connect = return_false + + database_client.connected = False + assert database_client.query(sql="test", is_reattempt=True) is False + + +def test_query_fail_to_connect(database_client_on_computer): + """Database client query should return False if the connect attempt fails.""" + database_client, computer = database_client_on_computer + + def return_false(): + return False + + database_client.connect = return_false + database_client.connected = False + + assert database_client.query(sql="test") is False + + +def test_client_receives_response_when_closed(database_client_on_computer): + """Database client receive should return False when it is closed.""" + database_client, computer = database_client_on_computer + + database_client.close() + assert database_client.operating_state is ApplicationOperatingState.CLOSED + + database_client.receive(payload={}, session_id="") diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py index 83426409..dc8f7419 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py @@ -21,7 +21,7 @@ def web_browser() -> WebBrowser: operating_state=NodeOperatingState.ON, ) # Web Browser should be pre-installed in computer - web_browser: WebBrowser = computer.software_manager.software["WebBrowser"] + web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser") web_browser.run() assert web_browser.operating_state is ApplicationOperatingState.RUNNING return web_browser @@ -36,7 +36,7 @@ def test_create_web_client(): operating_state=NodeOperatingState.ON, ) # Web Browser should be pre-installed in computer - web_browser: WebBrowser = computer.software_manager.software["WebBrowser"] + web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser") assert web_browser.name is "WebBrowser" assert web_browser.port is Port.HTTP assert web_browser.protocol is IPProtocol.TCP diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py index 3b1e4aa4..2c4826bf 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py @@ -19,11 +19,11 @@ def dm_client() -> Node: @pytest.fixture def dm_bot(dm_client) -> DataManipulationBot: - return dm_client.software_manager.software["DataManipulationBot"] + return dm_client.software_manager.software.get("DataManipulationBot") def test_create_dm_bot(dm_client): - data_manipulation_bot: DataManipulationBot = dm_client.software_manager.software["DataManipulationBot"] + data_manipulation_bot: DataManipulationBot = dm_client.software_manager.software.get("DataManipulationBot") assert data_manipulation_bot.name == "DataManipulationBot" assert data_manipulation_bot.port == Port.POSTGRES_SERVER diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py index 7662fbff..4d96b584 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py @@ -8,7 +8,7 @@ from primaite.simulator.system.services.database.database_service import Databas def database_server() -> Node: node = Node(hostname="db_node") node.software_manager.install(DatabaseService) - node.software_manager.software["DatabaseService"].start() + node.software_manager.software.get("DatabaseService").start() return node diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py index 71517855..2bcb512d 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py @@ -26,14 +26,14 @@ def dns_client() -> Node: def test_create_dns_client(dns_client): assert dns_client is not None - dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] + dns_client_service: DNSClient = dns_client.software_manager.software.get("DNSClient") assert dns_client_service.name is "DNSClient" assert dns_client_service.port is Port.DNS assert dns_client_service.protocol is IPProtocol.TCP def test_dns_client_add_domain_to_cache_when_not_running(dns_client): - dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] + dns_client_service: DNSClient = dns_client.software_manager.software.get("DNSClient") assert dns_client.operating_state is NodeOperatingState.OFF assert dns_client_service.operating_state is ServiceOperatingState.STOPPED @@ -46,7 +46,7 @@ def test_dns_client_add_domain_to_cache_when_not_running(dns_client): def test_dns_client_check_domain_exists_when_not_running(dns_client): dns_client.operating_state = NodeOperatingState.ON - dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] + dns_client_service: DNSClient = dns_client.software_manager.software.get("DNSClient") dns_client_service.start() assert dns_client.operating_state is NodeOperatingState.ON @@ -73,7 +73,7 @@ def test_dns_client_check_domain_exists_when_not_running(dns_client): def test_dns_client_check_domain_in_cache(dns_client): """Test to make sure that the check_domain_in_cache returns the correct values.""" dns_client.operating_state = NodeOperatingState.ON - dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] + dns_client_service: DNSClient = dns_client.software_manager.software.get("DNSClient") dns_client_service.start() # add a domain to the dns client cache @@ -85,7 +85,7 @@ def test_dns_client_check_domain_in_cache(dns_client): def test_dns_client_receive(dns_client): """Test to make sure the DNS Client knows how to deal with request responses.""" - dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] + dns_client_service: DNSClient = dns_client.software_manager.software.get("DNSClient") dns_client_service.receive( payload=DNSPacket( @@ -99,6 +99,6 @@ def test_dns_client_receive(dns_client): def test_dns_client_receive_non_dns_payload(dns_client): - dns_client_service: DNSClient = dns_client.software_manager.software["DNSClient"] + dns_client_service: DNSClient = dns_client.software_manager.software.get("DNSClient") assert dns_client_service.receive(payload=None) is False diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py index 5b65dfc2..eb042c92 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py @@ -26,7 +26,7 @@ def dns_server() -> Node: def test_create_dns_server(dns_server): assert dns_server is not None - dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] + dns_server_service: DNSServer = dns_server.software_manager.software.get("DNSServer") assert dns_server_service.name is "DNSServer" assert dns_server_service.port is Port.DNS assert dns_server_service.protocol is IPProtocol.TCP @@ -34,7 +34,7 @@ def test_create_dns_server(dns_server): def test_dns_server_domain_name_registration(dns_server): """Test to check if the domain name registration works.""" - dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] + dns_server_service: DNSServer = dns_server.software_manager.software.get("DNSServer") # register the web server in the domain controller dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12")) @@ -46,7 +46,7 @@ def test_dns_server_domain_name_registration(dns_server): def test_dns_server_receive(dns_server): """Test to make sure that the DNS Server correctly responds to a DNS Client request.""" - dns_server_service: DNSServer = dns_server.software_manager.software["DNSServer"] + dns_server_service: DNSServer = dns_server.software_manager.software.get("DNSServer") # register the web server in the domain controller dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12")) diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py index 1d7355a2..134f82bd 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py @@ -26,7 +26,7 @@ def ftp_client() -> Node: def test_create_ftp_client(ftp_client): assert ftp_client is not None - ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient") assert ftp_client_service.name is "FTPClient" assert ftp_client_service.port is Port.FTP assert ftp_client_service.protocol is IPProtocol.TCP @@ -47,7 +47,7 @@ def test_ftp_client_store_file(ftp_client): status_code=FTPStatusCode.OK, ) - ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient") ftp_client_service.receive(response) assert ftp_client.file_system.get_file(folder_name="downloads", file_name="file.txt") @@ -61,7 +61,7 @@ def test_ftp_should_not_process_commands_if_service_not_running(ftp_client): status_code=FTPStatusCode.OK, ) - ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient") ftp_client_service.stop() assert ftp_client_service.operating_state is ServiceOperatingState.STOPPED assert ftp_client_service._process_ftp_command(payload=payload).status_code is FTPStatusCode.ERROR @@ -71,7 +71,7 @@ def test_ftp_tries_to_senf_file__that_does_not_exist(ftp_client): """Method send_file should return false if no file to send.""" assert ftp_client.file_system.get_file(folder_name="root", file_name="test.txt") is None - ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient") assert ftp_client_service.operating_state is ServiceOperatingState.RUNNING assert ( ftp_client_service.send_file( @@ -87,7 +87,7 @@ def test_ftp_tries_to_senf_file__that_does_not_exist(ftp_client): def test_offline_ftp_client_receives_request(ftp_client): """Receive should return false if the node the ftp client is installed on is offline.""" - ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient") ftp_client.power_off() for i in range(ftp_client.shut_down_duration + 1): @@ -107,7 +107,7 @@ def test_offline_ftp_client_receives_request(ftp_client): def test_receive_should_fail_if_payload_is_not_ftp(ftp_client): """Receive should return false if the node the ftp client is installed on is not an FTPPacket.""" - ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient") assert ftp_client_service.receive(payload=None) is False @@ -118,5 +118,5 @@ def test_receive_should_ignore_payload_with_none_status_code(ftp_client): ftp_command_args=Port.FTP, status_code=None, ) - ftp_client_service: FTPClient = ftp_client.software_manager.software["FTPClient"] + ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient") assert ftp_client_service.receive(payload=payload) is False diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py index 0c849106..2b26c932 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py @@ -25,7 +25,7 @@ def ftp_server() -> Node: def test_create_ftp_server(ftp_server): assert ftp_server is not None - ftp_server_service: FTPServer = ftp_server.software_manager.software["FTPServer"] + ftp_server_service: FTPServer = ftp_server.software_manager.software.get("FTPServer") assert ftp_server_service.name is "FTPServer" assert ftp_server_service.port is Port.FTP assert ftp_server_service.protocol is IPProtocol.TCP @@ -45,7 +45,7 @@ def test_ftp_server_store_file(ftp_server): packet_payload_size=24, ) - ftp_server_service: FTPServer = ftp_server.software_manager.software["FTPServer"] + ftp_server_service: FTPServer = ftp_server.software_manager.software.get("FTPServer") ftp_server_service.receive(response) assert ftp_server.file_system.get_file(folder_name="downloads", file_name="file.txt") @@ -59,7 +59,7 @@ def test_ftp_server_should_send_error_if_port_arg_is_invalid(ftp_server): packet_payload_size=24, ) - ftp_server_service: FTPServer = ftp_server.software_manager.software["FTPServer"] + ftp_server_service: FTPServer = ftp_server.software_manager.software.get("FTPServer") assert ftp_server_service._process_ftp_command(payload=payload).status_code is FTPStatusCode.ERROR @@ -67,7 +67,7 @@ def test_ftp_server_receives_non_ftp_packet(ftp_server): """Receive should return false if the service receives a non ftp packet.""" response: FTPPacket = None - ftp_server_service: FTPServer = ftp_server.software_manager.software["FTPServer"] + ftp_server_service: FTPServer = ftp_server.software_manager.software.get("FTPServer") assert ftp_server_service.receive(response) is False @@ -83,7 +83,7 @@ def test_offline_ftp_server_receives_request(ftp_server): packet_payload_size=24, ) - ftp_server_service: FTPServer = ftp_server.software_manager.software["FTPServer"] + ftp_server_service: FTPServer = ftp_server.software_manager.software.get("FTPServer") ftp_server_service.stop() assert ftp_server_service.operating_state is ServiceOperatingState.STOPPED assert ftp_server_service.receive(response) is False diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py index e6f0b9d9..bbccda27 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py @@ -18,13 +18,13 @@ def web_server() -> Server: hostname="web_server", ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" ) node.software_manager.install(software_class=WebServer) - node.software_manager.software["WebServer"].start() + node.software_manager.software.get("WebServer").start() return node def test_create_web_server(web_server): assert web_server is not None - web_server_service: WebServer = web_server.software_manager.software["WebServer"] + web_server_service: WebServer = web_server.software_manager.software.get("WebServer") assert web_server_service.name is "WebServer" assert web_server_service.port is Port.HTTP assert web_server_service.protocol is IPProtocol.TCP @@ -33,7 +33,7 @@ def test_create_web_server(web_server): def test_handling_get_request_not_found_path(web_server): payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url="http://domain.com/fake-path") - web_server_service: WebServer = web_server.software_manager.software["WebServer"] + web_server_service: WebServer = web_server.software_manager.software.get("WebServer") response: HttpResponsePacket = web_server_service._handle_get_request(payload=payload) assert response.status_code == HttpStatusCode.NOT_FOUND @@ -42,7 +42,7 @@ def test_handling_get_request_not_found_path(web_server): def test_handling_get_request_home_page(web_server): payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url="http://domain.com/") - web_server_service: WebServer = web_server.software_manager.software["WebServer"] + web_server_service: WebServer = web_server.software_manager.software.get("WebServer") response: HttpResponsePacket = web_server_service._handle_get_request(payload=payload) assert response.status_code == HttpStatusCode.OK @@ -51,7 +51,7 @@ def test_handling_get_request_home_page(web_server): def test_process_http_request_get(web_server): payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url="http://domain.com/") - web_server_service: WebServer = web_server.software_manager.software["WebServer"] + web_server_service: WebServer = web_server.software_manager.software.get("WebServer") assert web_server_service._process_http_request(payload=payload) is True @@ -59,6 +59,6 @@ def test_process_http_request_get(web_server): def test_process_http_request_method_not_allowed(web_server): payload = HttpRequestPacket(request_method=HttpRequestMethod.DELETE, request_url="http://domain.com/") - web_server_service: WebServer = web_server.software_manager.software["WebServer"] + web_server_service: WebServer = web_server.software_manager.software.get("WebServer") assert web_server_service._process_http_request(payload=payload) is False From d9de57757f85a021634d61bde26ef35561fe1bfd Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 30 Nov 2023 15:47:31 +0000 Subject: [PATCH 415/980] #2084: more tests + remove concurrency in test to make sure coverage works --- .azure/azure-ci-build-pipeline.yaml | 2 +- src/primaite/simulator/network/utils.py | 2 + .../_network/_hardware/nodes/test_switch.py | 17 +++++ .../_simulator/_network/test_container.py | 63 ++++++++++++++++--- .../_simulator/_network/test_utils.py | 11 ++++ 5 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_switch.py create mode 100644 tests/unit_tests/_primaite/_simulator/_network/test_utils.py diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 49d76937..6951e350 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -86,5 +86,5 @@ stages: displayName: 'Perform PrimAITE Setup' - script: | - pytest -n auto --cov=src --cov-report=html:coverage_report --cov-fail-under=80 + pytest --cov=src --cov-report=html:coverage_report --cov-fail-under=80 displayName: 'Run tests and code coverage' diff --git a/src/primaite/simulator/network/utils.py b/src/primaite/simulator/network/utils.py index 496f5e13..33085bd6 100644 --- a/src/primaite/simulator/network/utils.py +++ b/src/primaite/simulator/network/utils.py @@ -5,6 +5,8 @@ def convert_bytes_to_megabits(B: Union[int, float]) -> float: # noqa - Keep it """ Convert Bytes (file size) to Megabits (data transfer). + Technically Mebibits - but for simplicity sake, we'll call it megabit + :param B: The file size in Bytes. :return: File bits to transfer in Megabits. """ diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_switch.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_switch.py new file mode 100644 index 00000000..d2d0e52c --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_switch.py @@ -0,0 +1,17 @@ +import pytest + +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.switch import Switch + + +@pytest.fixture(scope="function") +def switch() -> Switch: + switch: Switch = Switch(hostname="switch_1", num_ports=8, operating_state=NodeOperatingState.ON) + switch.show() + return switch + + +def test_describe_state(switch): + state = switch.describe_state() + assert len(state.get("ports")) is 8 + assert state.get("num_ports") is 8 diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index 92b3a91b..021d6777 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -3,6 +3,7 @@ import json import pytest from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.base import Link, Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.system.applications.database_client import DatabaseClient @@ -17,19 +18,20 @@ def network(example_network) -> Network: assert len(example_network.servers) is 2 example_network.set_original_state() + example_network.show() return example_network -def test_describe_state(example_network): +def test_describe_state(network): """Test that describe state works.""" - state = example_network.describe_state() + state = network.describe_state() assert len(state["nodes"]) is 7 assert len(state["links"]) is 6 -def test_reset_network(example_network): +def test_reset_network(network): """ Test that the network is properly reset. @@ -37,10 +39,10 @@ def test_reset_network(example_network): etc are also removed/reinstalled """ - state_before = example_network.describe_state() + state_before = network.describe_state() - client_1: Computer = example_network.get_node_by_hostname("client_1") - server_1: Computer = example_network.get_node_by_hostname("server_1") + client_1: Computer = network.get_node_by_hostname("client_1") + server_1: Computer = network.get_node_by_hostname("server_1") assert client_1.operating_state is NodeOperatingState.ON assert server_1.operating_state is NodeOperatingState.ON @@ -51,14 +53,14 @@ def test_reset_network(example_network): server_1.power_off() assert server_1.operating_state is NodeOperatingState.SHUTTING_DOWN - assert example_network.describe_state() is not state_before + assert network.describe_state() is not state_before - example_network.reset_component_for_episode(episode=1) + network.reset_component_for_episode(episode=1) assert client_1.operating_state is NodeOperatingState.ON assert server_1.operating_state is NodeOperatingState.ON - assert json.dumps(example_network.describe_state(), sort_keys=True, indent=2) == json.dumps( + assert json.dumps(network.describe_state(), sort_keys=True, indent=2) == json.dumps( state_before, sort_keys=True, indent=2 ) @@ -68,3 +70,46 @@ def test_creating_container(): net = Network() assert net.nodes == {} assert net.links == {} + net.show() + + +def test_apply_timestep_to_nodes(network): + """Calling apply_timestep on the network should apply to the nodes within it.""" + client_1: Computer = network.get_node_by_hostname("client_1") + assert client_1.operating_state is NodeOperatingState.ON + + client_1.power_off() + + for i in range(client_1.shut_down_duration + 1): + network.apply_timestep(timestep=i) + + assert client_1.operating_state is NodeOperatingState.OFF + + +def test_removing_node_that_does_not_exist(network): + """Node that does not exist on network should not affect existing nodes.""" + assert len(network.nodes) is 7 + + network.remove_node(Node(hostname="new_node")) + assert len(network.nodes) is 7 + + +def test_remove_node(network): + """Remove node should remove the correct node.""" + assert len(network.nodes) is 7 + + client_1: Computer = network.get_node_by_hostname("client_1") + network.remove_node(client_1) + + assert network.get_node_by_hostname("client_1") is None + assert len(network.nodes) is 6 + + +def test_remove_link(network): + """Remove link should remove the correct link.""" + assert len(network.links) is 6 + link: Link = network.links.get(next(iter(network.links))) + + network.remove_link(link) + assert len(network.links) is 5 + assert network.links.get(link.uuid) is None diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_utils.py b/tests/unit_tests/_primaite/_simulator/_network/test_utils.py new file mode 100644 index 00000000..a0c1da45 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/test_utils.py @@ -0,0 +1,11 @@ +from primaite.simulator.network.utils import convert_bytes_to_megabits, convert_megabits_to_bytes + + +def test_convert_bytes_to_megabits(): + assert round(convert_bytes_to_megabits(B=131072), 5) == float(1) + assert round(convert_bytes_to_megabits(B=69420), 5) == float(0.52963) + + +def test_convert_megabits_to_bytes(): + assert round(convert_megabits_to_bytes(Mbits=1), 5) == float(131072) + assert round(convert_megabits_to_bytes(Mbits=float(0.52963)), 5) == float(69419.66336) From 5cd69f343f26570f4709da4377e911e8e3b4f100 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Thu, 30 Nov 2023 16:11:44 +0000 Subject: [PATCH 416/980] #2085: generate time based log files --- src/primaite/__init__.py | 10 +++++++--- src/primaite/session/environment.py | 12 ++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/primaite/__init__.py b/src/primaite/__init__.py index a143b9b9..c58f0103 100644 --- a/src/primaite/__init__.py +++ b/src/primaite/__init__.py @@ -1,4 +1,5 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +import datetime as datetime import logging import logging.config import shutil @@ -38,7 +39,7 @@ class _PrimaitePaths: self.app_config_file_path = self.generate_app_config_file_path() self.app_log_dir_path = self.generate_app_log_dir_path() self.app_log_file_path = self.generate_app_log_file_path() - self.episode_steps_log_file_path = self.generate_episode_step_log_file_path() + self.episode_log_file_path = self.generate_episode_log_file_path() def _get_dirs_properties(self) -> List[str]: class_items = self.__class__.__dict__.items() @@ -106,9 +107,12 @@ class _PrimaitePaths: """The PrimAITE app log file path.""" return self.app_log_dir_path / "primaite.log" - def generate_episode_step_log_file_path(self) -> Path: + def generate_episode_log_file_path(self) -> Path: """The PrimAITE app episode step log file path.""" - return self.app_log_dir_path / "epi_step.log" + date_string = datetime.datetime.now().strftime("%Y-%m-%dT%H-%M-%S") + self.episode_log_dir_path = self.app_log_dir_path / date_string + self.episode_log_dir_path.mkdir(exist_ok=True, parents=True) + return self.episode_log_dir_path / "episode.log" def __repr__(self) -> str: properties_str = ", ".join([f"{p}='{getattr(self, p)}'" for p in self._get_dirs_properties()]) diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 913038f9..1471e683 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -1,4 +1,4 @@ -import os +# import os from typing import Any, Dict, Final, Optional, SupportsFloat, Tuple import gymnasium @@ -37,11 +37,11 @@ class PrimaiteGymEnv(gymnasium.Env): dump_state = {self.game.episode_counter: {self.game.step_counter: state}} # Dump to file - if os.path.isfile(PRIMAITE_PATHS.episode_steps_log_file_path): - with open(PRIMAITE_PATHS.episode_steps_log_file_path, "a", encoding="utf-8") as f: - f.write(str(dump_state)) - f.write("\n=================\n") - f.flush() + # if os.path.isfile(PRIMAITE_PATHS.episode_steps_log_file_path): + with open(PRIMAITE_PATHS.episode_log_file_path, "a", encoding="utf-8") as f: + f.write(str(dump_state)) + f.write("\n=================\n") + f.flush() self.game.update_agents(state) From 423436c3adb3e9c71a7ef00e6edad51e398427e0 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 30 Nov 2023 16:32:31 +0000 Subject: [PATCH 417/980] #2084: testing webbrowser requesting database service user data via web server --- .../system/applications/database_client.py | 3 +- tests/conftest.py | 14 +++--- .../test_web_client_server_and_database.py | 46 ++++++++++--------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 8c43c0b7..f57246fc 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -73,7 +73,8 @@ class DatabaseClient(Application): if not self.connected: return self._connect(self.server_ip_address, self.server_password) - return False + # already connected + return True def _connect( self, server_ip_address: IPv4Address, password: Optional[str] = None, is_reattempt: bool = False diff --git a/tests/conftest.py b/tests/conftest.py index c81e4b98..1ab07dd8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -164,13 +164,13 @@ def example_network() -> Network: Should only contain the nodes and links. This would act as the base network and services and applications are installed in the relevant test file, - -------------- -------------- - | client_1 |----- ----| server_1 | - -------------- | -------------- ------------ -------------- | -------------- - ------| switch_1 |------| router |------| switch_2 |------ - -------------- | -------------- ------------ -------------- | -------------- - | client_2 |---- ----| server_2 | - -------------- -------------- + -------------- -------------- + | client_1 |----- ----| server_1 | + -------------- | -------------- -------------- -------------- | -------------- + ------| switch_1 |------| router_1 |------| switch_2 |------ + -------------- | -------------- -------------- -------------- | -------------- + | client_2 |---- ----| server_2 | + -------------- -------------- """ network = Network() diff --git a/tests/integration_tests/system/test_web_client_server_and_database.py b/tests/integration_tests/system/test_web_client_server_and_database.py index 17458968..a4ef3d52 100644 --- a/tests/integration_tests/system/test_web_client_server_and_database.py +++ b/tests/integration_tests/system/test_web_client_server_and_database.py @@ -6,7 +6,9 @@ import pytest from primaite.simulator.network.hardware.base import Link from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.database.database_service import DatabaseService @@ -16,31 +18,30 @@ from primaite.simulator.system.services.web_server.web_server import WebServer @pytest.fixture(scope="function") -def web_client_web_server_database() -> Tuple[Computer, Server, Server]: - # Create Computer - computer: Computer = Computer( - hostname="test_computer", - ip_address="192.168.0.1", - subnet_mask="255.255.255.0", - default_gateway="192.168.1.1", - operating_state=NodeOperatingState.ON, +def web_client_web_server_database(example_network) -> Tuple[Computer, Server, Server]: + # add rules to network router + router_1: Router = example_network.get_node_by_hostname("router_1") + router_1.acl.add_rule( + action=ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER, position=0 ) + # Allow DNS requests + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.DNS, dst_port=Port.DNS, position=1) + + # Allow FTP requests + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.FTP, dst_port=Port.FTP, position=2) + + # Open port 80 for web server + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.HTTP, dst_port=Port.HTTP, position=3) + + # Create Computer + computer: Computer = example_network.get_node_by_hostname("client_1") + # Create Web Server - web_server = Server( - hostname="web_server", - ip_address="192.168.0.2", - subnet_mask="255.255.255.0", - operating_state=NodeOperatingState.ON, - ) + web_server: Server = example_network.get_node_by_hostname("server_1") # Create Database Server - db_server = Server( - hostname="db_server", - ip_address="192.168.0.3", - subnet_mask="255.255.255.0", - operating_state=NodeOperatingState.ON, - ) + db_server = example_network.get_node_by_hostname("server_2") # Get the NICs computer_nic = computer.nics[next(iter(computer.nics))] @@ -66,6 +67,7 @@ def web_client_web_server_database() -> Tuple[Computer, Server, Server]: # Install Web Browser on computer computer.software_manager.install(WebBrowser) web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser") + web_browser.target_url = "http://arcd.com/users/" web_browser.run() # Install DNS Client service on computer @@ -92,15 +94,15 @@ def web_client_web_server_database() -> Tuple[Computer, Server, Server]: db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") db_client.server_ip_address = IPv4Address(db_server_nic.ip_address) # set IP address of Database Server db_client.run() + assert dns_client.check_domain_exists("arcd.com") assert db_client.connect() return computer, web_server, db_server -@pytest.mark.skip(reason="waiting for a way to set this up correctly") def test_web_client_requests_users(web_client_web_server_database): computer, web_server, db_server = web_client_web_server_database web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser") - web_browser.get_webpage() + assert web_browser.get_webpage() From 9d4e564e0e47bf878ea5a3d83562178af73aa0f3 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 30 Nov 2023 18:32:03 +0000 Subject: [PATCH 418/980] #2084: upload reports --- .azure/azure-ci-build-pipeline.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 6951e350..0b02626c 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -86,5 +86,14 @@ stages: displayName: 'Perform PrimAITE Setup' - script: | - pytest --cov=src --cov-report=html:coverage_report --cov-fail-under=80 + pytest --cov=src --cov-report=html:coverage_report --cov-report=xml --cov-fail-under=80 displayName: 'Run tests and code coverage' + + - task: PublishCodeCoverageResults@1 + displayName: 'Publish coverage report' + condition: succeededOrFailed() + inputs: + codeCoverageTool: Cobertura + summaryFileLocation: 'coverage.xml' + reportDirectory: 'coverage_report' + failIfCoverageEmpty: true From bfb631f88ccf8ce7983e5cb1ed295b199a310363 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 30 Nov 2023 18:45:27 +0000 Subject: [PATCH 419/980] #2084: upload reports - use default htmlcov location --- .azure/azure-ci-build-pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 0b02626c..12a454fa 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -86,7 +86,7 @@ stages: displayName: 'Perform PrimAITE Setup' - script: | - pytest --cov=src --cov-report=html:coverage_report --cov-report=xml --cov-fail-under=80 + pytest --cov=src --cov-report=html --cov-report=xml --cov-fail-under=80 displayName: 'Run tests and code coverage' - task: PublishCodeCoverageResults@1 From d60250e1b870db09eb6fc0c9433a992b9ae6efc0 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 30 Nov 2023 19:21:11 +0000 Subject: [PATCH 420/980] #2084: upload reports - azure cannot find things --- .azure/azure-ci-build-pipeline.yaml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 12a454fa..04d35ab2 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -6,6 +6,18 @@ trigger: - bugfix/* - release/* +pr: + autoCancel: true # automatically cancel PR if new push made + drafts: true # get triggered when doing drafts + branches: + include: + - main + - dev + - feature/* + - hotfix/* + - bugfix/* + - release/* + parameters: # https://stackoverflow.com/a/70046417 - name: matrix @@ -94,6 +106,6 @@ stages: condition: succeededOrFailed() inputs: codeCoverageTool: Cobertura - summaryFileLocation: 'coverage.xml' - reportDirectory: 'coverage_report' + summaryFileLocation: './coverage.xml' + reportDirectory: './coverage_report' failIfCoverageEmpty: true From 4572afac6926c7024d75400f313d7518526848e1 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 30 Nov 2023 19:34:18 +0000 Subject: [PATCH 421/980] #2084: upload reports - debug --- .azure/azure-ci-build-pipeline.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 04d35ab2..ef8f984b 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -101,6 +101,10 @@ stages: pytest --cov=src --cov-report=html --cov-report=xml --cov-fail-under=80 displayName: 'Run tests and code coverage' + + - script: pwd + - script: ls + - task: PublishCodeCoverageResults@1 displayName: 'Publish coverage report' condition: succeededOrFailed() From 4c1bb7d786ee71475fa269960d1574856db193b7 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 30 Nov 2023 19:43:23 +0000 Subject: [PATCH 422/980] #2084: upload reports - debug --- .azure/azure-ci-build-pipeline.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index ef8f984b..777a4e50 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -64,6 +64,9 @@ stages: versionSpec: ${{ item.py }} displayName: 'Use Python ${{ item.py }}' + - script: pwd + - script: ls + - script: | python -m pip install pre-commit pre-commit install @@ -101,10 +104,6 @@ stages: pytest --cov=src --cov-report=html --cov-report=xml --cov-fail-under=80 displayName: 'Run tests and code coverage' - - - script: pwd - - script: ls - - task: PublishCodeCoverageResults@1 displayName: 'Publish coverage report' condition: succeededOrFailed() From 5b5021362696b3355ec8031aa681e87c21279a9b Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 30 Nov 2023 19:58:35 +0000 Subject: [PATCH 423/980] #2084: upload reports - debug --- .azure/azure-ci-build-pipeline.yaml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 777a4e50..45df6539 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -64,9 +64,6 @@ stages: versionSpec: ${{ item.py }} displayName: 'Use Python ${{ item.py }}' - - script: pwd - - script: ls - - script: | python -m pip install pre-commit pre-commit install @@ -103,12 +100,3 @@ stages: - script: | pytest --cov=src --cov-report=html --cov-report=xml --cov-fail-under=80 displayName: 'Run tests and code coverage' - - - task: PublishCodeCoverageResults@1 - displayName: 'Publish coverage report' - condition: succeededOrFailed() - inputs: - codeCoverageTool: Cobertura - summaryFileLocation: './coverage.xml' - reportDirectory: './coverage_report' - failIfCoverageEmpty: true From c2f7d737f786494620f96deda065ed36df837a3f Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 30 Nov 2023 21:11:35 +0000 Subject: [PATCH 424/980] #2084: missed change to logger --- src/primaite/game/agent/actions.py | 2 +- src/primaite/game/agent/observations.py | 8 ++++---- src/primaite/game/agent/rewards.py | 4 ++-- src/primaite/simulator/core.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index c70d4d66..8eed3ba4 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -424,7 +424,7 @@ class NetworkACLAddRuleAction(AbstractAction): elif permission == 2: permission_str = "DENY" else: - _LOGGER.warn(f"{self.__class__} received permission {permission}, expected 0 or 1.") + _LOGGER.warning(f"{self.__class__} received permission {permission}, expected 0 or 1.") if protocol_id == 0: return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 93fd81b8..767514b4 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -264,7 +264,7 @@ class FolderObservation(AbstractObservation): while len(self.files) > num_files_per_folder: truncated_file = self.files.pop() msg = f"Too many files in folder observation. Truncating file {truncated_file}" - _LOGGER.warn(msg) + _LOGGER.warning(msg) self.default_observation = { "health_status": 0, @@ -438,7 +438,7 @@ class NodeObservation(AbstractObservation): while len(self.services) > num_services_per_node: truncated_service = self.services.pop() msg = f"Too many services in Node observation space for node. Truncating service {truncated_service.where}" - _LOGGER.warn(msg) + _LOGGER.warning(msg) # truncate service list self.folders: List[FolderObservation] = folders @@ -448,7 +448,7 @@ class NodeObservation(AbstractObservation): while len(self.folders) > num_folders_per_node: truncated_folder = self.folders.pop() msg = f"Too many folders in Node observation for node. Truncating service {truncated_folder.where[-1]}" - _LOGGER.warn(msg) + _LOGGER.warning(msg) self.nics: List[NicObservation] = nics while len(self.nics) < num_nics_per_node: @@ -456,7 +456,7 @@ class NodeObservation(AbstractObservation): while len(self.nics) > num_nics_per_node: truncated_nic = self.nics.pop() msg = f"Too many NICs in Node observation for node. Truncating service {truncated_nic.where[-1]}" - _LOGGER.warn(msg) + _LOGGER.warning(msg) self.logon_status: bool = logon_status diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 3466114c..ca6d8a12 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -210,7 +210,7 @@ class WebServer404Penalty(AbstractReward): f"{cls.__name__} could not be initialised from config because node_ref and service_ref were not " "found in reward config." ) - _LOGGER.warn(msg) + _LOGGER.warning(msg) return DummyReward() # TODO: should we error out with incorrect inputs? Probably! node_uuid = game.ref_map_nodes[node_ref] service_uuid = game.ref_map_services[service_ref] @@ -219,7 +219,7 @@ class WebServer404Penalty(AbstractReward): f"{cls.__name__} could not be initialised because node {node_ref} and service {service_ref} were not" " found in the simulator." ) - _LOGGER.warn(msg) + _LOGGER.warning(msg) return DummyReward() # TODO: consider erroring here as well return cls(node_uuid=node_uuid, service_uuid=service_uuid) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 18a470cd..5e1953e2 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -113,7 +113,7 @@ class RequestManager(BaseModel): """ if name in self.request_types: msg = f"Overwriting request type {name}." - _LOGGER.warn(msg) + _LOGGER.warning(msg) self.request_types[name] = request_type @@ -252,6 +252,6 @@ class SimComponent(BaseModel): def parent(self, new_parent: Union["SimComponent", None]) -> None: if self._parent and new_parent: msg = f"Overwriting parent of {self.uuid}. Old parent: {self._parent.uuid}, New parent: {new_parent.uuid}" - _LOGGER.warn(msg) + _LOGGER.warning(msg) raise RuntimeWarning(msg) self._parent = new_parent From 3eb9a5ef1c21552c48037ee49bb4c1e2bd1ca5ad Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 09:13:17 +0000 Subject: [PATCH 425/980] #2084: publish coverage report --- .azure/azure-ci-build-pipeline.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 45df6539..b9a80fc4 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -100,3 +100,11 @@ stages: - script: | pytest --cov=src --cov-report=html --cov-report=xml --cov-fail-under=80 displayName: 'Run tests and code coverage' + + - task: PublishCodeCoverageResults@1 + displayName: 'Publish coverage report' + inputs: + codeCoverageTool: Cobertura + summaryFileLocation: './coverage.xml' + reportDirectory: './htmlcov' + failIfCoverageEmpty: true From a073038ec09de444b081edce41916c5e740f660d Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 1 Dec 2023 09:52:31 +0000 Subject: [PATCH 426/980] #2085: Get enum value data --- src/primaite/session/environment.py | 11 ++++++----- src/primaite/simulator/system/services/service.py | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 1471e683..bb7028d8 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -1,4 +1,4 @@ -# import os +import json from typing import Any, Dict, Final, Optional, SupportsFloat, Tuple import gymnasium @@ -34,14 +34,15 @@ class PrimaiteGymEnv(gymnasium.Env): state = self.game.get_sim_state() # Create state suitable for dumping to file. - dump_state = {self.game.episode_counter: {self.game.step_counter: state}} + # dump_state = {self.game.episode_counter: {self.game.step_counter: state}} # Dump to file # if os.path.isfile(PRIMAITE_PATHS.episode_steps_log_file_path): with open(PRIMAITE_PATHS.episode_log_file_path, "a", encoding="utf-8") as f: - f.write(str(dump_state)) - f.write("\n=================\n") - f.flush() + # f.write(str(dump_state)) + # f.write("\n=================\n") + # f.flush() + json.dump(state, f) self.game.update_agents(state) diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 6d6cda86..e60b7700 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -109,8 +109,8 @@ class Service(IOSoftware): """ state = super().describe_state() state["operating_state"] = self.operating_state.value - state["health_state_actual"] = self.health_state_actual - state["health_state_visible"] = self.health_state_visible + state["health_state_actual"] = self.health_state_actual.value + state["health_state_visible"] = self.health_state_visible.value return state def stop(self) -> None: From f1c706631f44f53db7701f9c153bbb5e94383230 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 10:02:12 +0000 Subject: [PATCH 427/980] #2084: publish coverage report --- .azure/azure-ci-build-pipeline.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index b9a80fc4..05de0050 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -105,6 +105,7 @@ stages: displayName: 'Publish coverage report' inputs: codeCoverageTool: Cobertura - summaryFileLocation: './coverage.xml' - reportDirectory: './htmlcov' + summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage.xml + pathToSources: $(System.DefaultWorkingDirectory)/src/ + reportDirectory: $(System.DefaultWorkingDirectory)/htmlcov/ failIfCoverageEmpty: true From 4ad93b09617c39da7bf7b8bac684fc9dd054a5f1 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 10:32:48 +0000 Subject: [PATCH 428/980] #2084: publish coverage report + more verbose test output --- .azure/azure-ci-build-pipeline.yaml | 11 +++++++++-- .gitignore | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 05de0050..58d5454e 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -98,14 +98,21 @@ stages: displayName: 'Perform PrimAITE Setup' - script: | - pytest --cov=src --cov-report=html --cov-report=xml --cov-fail-under=80 + pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:coverage.xml --cov-report html:src/coverage/html displayName: 'Run tests and code coverage' + - task: PublishTestResults@2 + condition: succeededOrFailed() + inputs: + testRunner: JUnit + testResultsFiles: 'junit/**.xml' + testRunTitle: 'Publish test results' + - task: PublishCodeCoverageResults@1 displayName: 'Publish coverage report' inputs: codeCoverageTool: Cobertura summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage.xml pathToSources: $(System.DefaultWorkingDirectory)/src/ - reportDirectory: $(System.DefaultWorkingDirectory)/htmlcov/ + reportDirectory: $(System.DefaultWorkingDirectory)/src/coverage/html/ failIfCoverageEmpty: true diff --git a/.gitignore b/.gitignore index f6231bac..ef842c6e 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports +junit/ htmlcov/ .tox/ .nox/ From 3642e87eda51f2317a15dad7908d78f2b5246a10 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 1 Dec 2023 11:07:57 +0000 Subject: [PATCH 429/980] Remove distracting debug print statements --- src/primaite/session/policy/sb3.py | 3 +-- .../simulator/system/services/database/database_service.py | 2 +- .../simulator/system/services/web_server/web_server.py | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/primaite/session/policy/sb3.py b/src/primaite/session/policy/sb3.py index 051e2770..254baf4d 100644 --- a/src/primaite/session/policy/sb3.py +++ b/src/primaite/session/policy/sb3.py @@ -51,14 +51,13 @@ class SB3Policy(PolicyABC, identifier="SB3"): def eval(self, n_episodes: int, deterministic: bool) -> None: """Evaluate the agent.""" - reward_data = evaluate_policy( + _ = evaluate_policy( self._agent, self.session.env, n_eval_episodes=n_episodes, deterministic=deterministic, return_episode_rewards=True, ) - print(reward_data) def save(self, save_path: Path) -> None: """ diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index f9621ba5..bba4e777 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -56,7 +56,7 @@ class DatabaseService(Service): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - print("Resetting DatabaseService original state on node {self.software_manager.node.hostname}") + _LOGGER.debug("Resetting DatabaseService original state on node {self.software_manager.node.hostname}") self.connections.clear() super().reset_component_for_episode(episode) diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index bff29a47..e5f3dccc 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -47,7 +47,6 @@ class WebServer(Service): state["last_response_status_code"] = ( self.last_response_status_code.value if isinstance(self.last_response_status_code, HttpStatusCode) else None ) - print(state) return state def __init__(self, **kwargs): From 74b8f58b365e784999abc29e8735fe618bdf01ab Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 11:22:30 +0000 Subject: [PATCH 430/980] #2084: debug pipeline --- .azure/azure-ci-build-pipeline.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 58d5454e..3b46302a 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -108,6 +108,14 @@ stages: testResultsFiles: 'junit/**.xml' testRunTitle: 'Publish test results' + - script: | + pwd && ls + displayName: 'debug root' + + - script: | + cd src && pwd && ls + displayName: 'debug src' + - task: PublishCodeCoverageResults@1 displayName: 'Publish coverage report' inputs: From 6430a7588d57c57211a3920d8f377de3abed2dec Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 11:38:34 +0000 Subject: [PATCH 431/980] #2084: debug pipeline --- .azure/azure-ci-build-pipeline.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 3b46302a..fa0fec5b 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -109,13 +109,17 @@ stages: testRunTitle: 'Publish test results' - script: | - pwd && ls + echo '$(System.DefaultWorkingDirectory)' && pwd && ls displayName: 'debug root' - script: | cd src && pwd && ls displayName: 'debug src' + - script: | + cd src/coverage/html && pwd && ls + displayName: 'debug src/coverage/html' + - task: PublishCodeCoverageResults@1 displayName: 'Publish coverage report' inputs: From 738aeed0a5eff9e0ee6eadcdc564f7f4efe83d29 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 12:05:12 +0000 Subject: [PATCH 432/980] #2084: debug pipeline --- .azure/azure-ci-build-pipeline.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index fa0fec5b..dffa5aa5 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -113,11 +113,11 @@ stages: displayName: 'debug root' - script: | - cd src && pwd && ls + cd $(System.DefaultWorkingDirectory)/src && pwd && ls displayName: 'debug src' - script: | - cd src/coverage/html && pwd && ls + cd $(System.DefaultWorkingDirectory)/src/coverage/html && pwd && ls displayName: 'debug src/coverage/html' - task: PublishCodeCoverageResults@1 From 1dbea3041a7f77e4ed523e1ea8887cfbf56c2120 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 12:46:12 +0000 Subject: [PATCH 433/980] #2084: add files + remove extra slash --- .azure/azure-ci-build-pipeline.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index dffa5aa5..72d5427a 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -126,5 +126,6 @@ stages: codeCoverageTool: Cobertura summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage.xml pathToSources: $(System.DefaultWorkingDirectory)/src/ - reportDirectory: $(System.DefaultWorkingDirectory)/src/coverage/html/ + reportDirectory: $(System.DefaultWorkingDirectory)/src/coverage/html + additionalCodeCoverageFiles: $(System.DefaultWorkingDirectory)/src/coverage/html/*.* failIfCoverageEmpty: true From c21a52d3f7d09a880d880ce9440307aae2d12fa3 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 13:26:27 +0000 Subject: [PATCH 434/980] #2084: debug pipeline --- .azure/azure-ci-build-pipeline.yaml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 72d5427a..b919383e 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -113,12 +113,8 @@ stages: displayName: 'debug root' - script: | - cd $(System.DefaultWorkingDirectory)/src && pwd && ls - displayName: 'debug src' - - - script: | - cd $(System.DefaultWorkingDirectory)/src/coverage/html && pwd && ls - displayName: 'debug src/coverage/html' + cd $(System.DefaultWorkingDirectory)/htmlcov && pwd && ls + displayName: 'debug htmlcov' - task: PublishCodeCoverageResults@1 displayName: 'Publish coverage report' @@ -126,6 +122,6 @@ stages: codeCoverageTool: Cobertura summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage.xml pathToSources: $(System.DefaultWorkingDirectory)/src/ - reportDirectory: $(System.DefaultWorkingDirectory)/src/coverage/html - additionalCodeCoverageFiles: $(System.DefaultWorkingDirectory)/src/coverage/html/*.* + reportDirectory: $(System.DefaultWorkingDirectory)/htmlcov + additionalCodeCoverageFiles: $(System.DefaultWorkingDirectory)/htmlcov/*.* failIfCoverageEmpty: true From 4f57403751a2e491dc8dbc07286f40d89d35d623 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 13:52:06 +0000 Subject: [PATCH 435/980] #2084: debug pipeline --- .azure/azure-ci-build-pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index b919383e..850568f6 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -98,7 +98,7 @@ stages: displayName: 'Perform PrimAITE Setup' - script: | - pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:coverage.xml --cov-report html:src/coverage/html + pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:coverage.xml --cov-report html displayName: 'Run tests and code coverage' - task: PublishTestResults@2 From 656cb03b16b9b0bcbbf4a3389799bd116da42b06 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 14:34:42 +0000 Subject: [PATCH 436/980] #2084: print content of coverage.xml --- .azure/azure-ci-build-pipeline.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 850568f6..bddcc86c 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -116,6 +116,10 @@ stages: cd $(System.DefaultWorkingDirectory)/htmlcov && pwd && ls displayName: 'debug htmlcov' + - script: | + cat $(System.DefaultWorkingDirectory)/coverage.xml + displayName: 'debug coverage file' + - task: PublishCodeCoverageResults@1 displayName: 'Publish coverage report' inputs: From d6fedf007919de30be1d7ee3ab4aa1606d341ef0 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 14:58:22 +0000 Subject: [PATCH 437/980] #2084: maybe pointing to different source might help --- .azure/azure-ci-build-pipeline.yaml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index bddcc86c..147b8c14 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -108,24 +108,12 @@ stages: testResultsFiles: 'junit/**.xml' testRunTitle: 'Publish test results' - - script: | - echo '$(System.DefaultWorkingDirectory)' && pwd && ls - displayName: 'debug root' - - - script: | - cd $(System.DefaultWorkingDirectory)/htmlcov && pwd && ls - displayName: 'debug htmlcov' - - - script: | - cat $(System.DefaultWorkingDirectory)/coverage.xml - displayName: 'debug coverage file' - - task: PublishCodeCoverageResults@1 displayName: 'Publish coverage report' inputs: codeCoverageTool: Cobertura summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage.xml - pathToSources: $(System.DefaultWorkingDirectory)/src/ + pathToSources: $(System.DefaultWorkingDirectory)/ reportDirectory: $(System.DefaultWorkingDirectory)/htmlcov additionalCodeCoverageFiles: $(System.DefaultWorkingDirectory)/htmlcov/*.* failIfCoverageEmpty: true From 321d1f7219d134e18e98db584e8273f7c06385d6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 1 Dec 2023 14:58:34 +0000 Subject: [PATCH 438/980] Fix rllib marl problems --- .gitignore | 1 + .../example_config_2_rl_agents.yaml | 108 +- .../training_example_ray_multi_agent.ipynb | 44 +- .../training_example_ray_single_agent.ipynb | 969 ++++++++++++++++-- src/primaite/session/environment.py | 21 +- src/primaite/session/policy/rllib.py | 15 +- 6 files changed, 989 insertions(+), 169 deletions(-) diff --git a/.gitignore b/.gitignore index f6231bac..a6404ac6 100644 --- a/.gitignore +++ b/.gitignore @@ -154,3 +154,4 @@ simulation_output/ benchmark/output # src/primaite/notebooks/scratch.ipynb src/primaite/notebooks/scratch.py +sandbox.py diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index 9450c419..b811bfa5 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -1,14 +1,10 @@ training_config: - rl_framework: RLLIB_single_agent - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 1 - n_eval_episodes: 5 - max_steps_per_episode: 256 - deterministic_eval: false - n_agents: 1 + rl_framework: RLLIB_multi_agent + # rl_framework: SB3 + n_agents: 2 agent_references: - - defender + - defender_1 + - defender_2 io_settings: save_checkpoints: true @@ -36,31 +32,26 @@ agents: action_space: action_list: - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com - + - type: NODE_APPLICATION_EXECUTE options: nodes: - node_ref: client_2 + applications: + - application_ref: client_2_web_browser max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 + max_applications_per_node: 1 reward_function: reward_components: - type: DUMMY agent_settings: - start_step: 5 - frequency: 4 - variance: 3 + start_settings: + start_step: 5 + frequency: 4 + variance: 3 - ref: client_1_data_manipulation_red_bot team: RED @@ -69,38 +60,20 @@ agents: observation_space: type: UC2RedObservation options: - nodes: - - node_ref: client_1 - observations: - - logon_status - - operating_status - services: - - service_ref: data_manipulation_bot - observations: - operating_status - health_status - folders: {} + nodes: {} action_space: action_list: - type: DONOTHING - #\n", + "

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Python version:3.10.12
Ray version:2.8.0
\n", + "\n", + "
\n", + "\n" + ], + "text/plain": [ + "RayContext(dashboard_url='', python_version='3.10.12', ray_version='2.8.0', ray_commit='105355bd253d6538ed34d331f6a4bdf0e38ace3a', protocol_version=None)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ray.init(local_mode=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "env_config = {\"cfg\":cfg}\n", "\n", - "game = PrimaiteGame.from_config(cfg)" + "config = (\n", + " PPOConfig()\n", + " .environment(env=PrimaiteRayEnv, env_config=env_config, disable_env_checking=True)\n", + " .rollouts(num_rollout_workers=0,)\n", + " .training(train_batch_size=128)\n", + ")\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + ":job_id:01000000\n", + ":task_name:bundle_reservation_check_func\n", + ":actor_name:PPO\n", + "2023-12-01 14:53:17,868::ERROR::primaite.simulator.network.hardware.base::190::NIC 3e:e9:64:e8:cf:89/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:17,869::ERROR::primaite.simulator.network.hardware.base::190::NIC 74:17:08:49:f5:30/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:17,870::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:17,871::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:17,872::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:17,875: Added node 1c94cb0c-b62c-43eb-b5d3-4a5d1937f845 to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", + "2023-12-01 14:53:17,878: Added node 3197ef0c-0ce8-4b63-bde8-91e7f95d59ef to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", + "2023-12-01 14:53:17,884: Added node 835b8e76-0b1e-4112-9897-0808a87fd9de to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", + "2023-12-01 14:53:17,888::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,889: Added service 6a19bda9-7f0e-4f77-a5bc-b473d3418df0 to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", + "2023-12-01 14:53:17,890::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,891: Added service 6fc138ff-e698-4c4d-82ca-0aa990df6669 to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", + "2023-12-01 14:53:17,893: Added application 601f573a-5480-492d-8508-4b1ccc45100f to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", + "2023-12-01 14:53:17,895::ERROR::primaite.simulator.network.hardware.base::190::NIC fd:19:e4:d5:6e:c8/192.168.1.10 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:17,896::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,898: Added service 901a736f-8fd0-49e9-9369-ef1da8a6a5a4 to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", + "2023-12-01 14:53:17,900::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,903: Added service e240939c-b017-4e67-b161-8e5d96cbe061 to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", + "2023-12-01 14:53:17,905: Added application dada880f-ec1f-4ed3-a4b6-3f8c68a6c750 to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", + "2023-12-01 14:53:17,906::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,908: Added service d2201c7b-418c-49f7-bed0-c93f520f0352 to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", + "2023-12-01 14:53:17,909: Added node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", + "2023-12-01 14:53:17,912::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,914: Added service 2c843f1e-643a-40d3-9477-8870926f49e8 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", + "2023-12-01 14:53:17,916::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,918: Added service b52910ee-66d7-4006-8044-fb27a95cc00f to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", + "2023-12-01 14:53:17,920: Added application dd11b7fb-a31a-418d-bfdb-fb862c0c38b2 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", + "2023-12-01 14:53:17,922::ERROR::primaite.simulator.network.hardware.base::190::NIC b9:01:34:d2:50:53/192.168.1.12 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:17,923::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,926: Added service a1d7a58a-df23-4ea0-934f-b4f397f252e5 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", + "2023-12-01 14:53:17,927::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,928: Added service 742f59a4-369e-4a31-a95e-19adb9115cb7 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", + "2023-12-01 14:53:17,930: Added application 5a93e02b-5485-46ad-9c61-4f32d4673ec3 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", + "2023-12-01 14:53:17,934: Added application 040a27ae-8c65-47fd-a60b-7c72a46e7806 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", + "2023-12-01 14:53:17,936::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,938: Added service f6241fbe-524e-4e94-8e94-232bcd8d0914 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", + "2023-12-01 14:53:17,939: Added node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036 to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", + "2023-12-01 14:53:17,941::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,942: Added service f69c460a-5385-4244-8582-508f806e52e4 to node 2f002450-027d-4791-832b-01327350d7e7\n", + "2023-12-01 14:53:17,943::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,944: Added service f36088c4-0817-47a2-bd4d-1162fee46b63 to node 2f002450-027d-4791-832b-01327350d7e7\n", + "2023-12-01 14:53:17,946: Added application 4de6ebfd-46ae-419f-b36e-3b2b079eff9d to node 2f002450-027d-4791-832b-01327350d7e7\n", + "2023-12-01 14:53:17,949::ERROR::primaite.simulator.network.hardware.base::190::NIC 70:fb:95:ae:8b:e9/192.168.1.14 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:17,951::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,953: Added service 5a01c753-1c0b-4f9e-8cf9-bdab8e1151e7 to node 2f002450-027d-4791-832b-01327350d7e7\n", + "2023-12-01 14:53:17,954::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,956: Added service 8f28720e-4374-4fe5-9b30-f2b3943691ff to node 2f002450-027d-4791-832b-01327350d7e7\n", + "2023-12-01 14:53:17,957: Added application 500d5dc5-1bca-4904-8b2a-8d5f3c4db978 to node 2f002450-027d-4791-832b-01327350d7e7\n", + "2023-12-01 14:53:17,958::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,960: Added service a5e5963e-c071-4715-9042-5e5887e26f3a to node 2f002450-027d-4791-832b-01327350d7e7\n", + "2023-12-01 14:53:17,962::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,967: Added service 82dd1118-3e3c-4f72-8e62-3217e72b0360 to node 2f002450-027d-4791-832b-01327350d7e7\n", + "2023-12-01 14:53:17,969: Added node 2f002450-027d-4791-832b-01327350d7e7 to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", + "2023-12-01 14:53:17,972::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,973: Added service d8d2c796-cae8-4d6b-acd1-76a30fb3dd87 to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", + "2023-12-01 14:53:17,974::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,975: Added service bd319940-2ad7-456b-88e9-a49b1c994edd to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", + "2023-12-01 14:53:17,977: Added application d30f9307-d8d5-41f0-b74d-94b878b3023a to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", + "2023-12-01 14:53:17,978::ERROR::primaite.simulator.network.hardware.base::190::NIC e8:c5:48:91:62:fe/192.168.1.16 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:17,980::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,983: Added service e926ebb1-6d91-4400-94f3-7dfab8e82eab to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", + "2023-12-01 14:53:17,985::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,987: Added service af73e5f5-c754-4936-9018-37ef69140ced to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", + "2023-12-01 14:53:17,988: Added application 13fd868b-e730-486f-ab83-e1bf2446e504 to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", + "2023-12-01 14:53:17,989::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:17,991: Added service ab453a9d-62dc-4437-b0dc-c9d587962a0b to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", + "2023-12-01 14:53:17,992: Added node 858361fa-1b42-4456-b184-59fa44b0c89b to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", + "2023-12-01 14:53:17,995::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,003: Added service d9b44dbd-f153-4f3c-b03d-b6441a917834 to node 7c47bb4e-deea-4c23-910d-6ba524f73bbc\n", + "2023-12-01 14:53:18,005::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,006: Added service c3da251b-500a-40dd-8c25-e26a35b5b767 to node 7c47bb4e-deea-4c23-910d-6ba524f73bbc\n", + "2023-12-01 14:53:18,008: Added application 8f692912-fb57-40bb-ad56-d38970d34430 to node 7c47bb4e-deea-4c23-910d-6ba524f73bbc\n", + "2023-12-01 14:53:18,010::ERROR::primaite.simulator.network.hardware.base::190::NIC a3:59:d7:fe:28:08/192.168.1.110 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,011::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + ":job_id:01000000\n", + ":task_name:bundle_reservation_check_func\n", + ":actor_name:PPO\n", + "installing DNSServer on node domain_controller\n", + "installing DatabaseClient on node web_server\n", + "installing WebServer on node web_server\n", + "installing DatabaseService on node database_server\n", + "installing FTPClient on node database_server\n", + "installing FTPServer on node backup_server\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-12-01 14:53:18,013: Added service be9a1ad7-252b-47c7-ae20-e8202cb890ab to node 7c47bb4e-deea-4c23-910d-6ba524f73bbc\n", + "2023-12-01 14:53:18,020::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,022: Added service c5d5b514-cd30-4c7d-a4b7-b16fce71ccac to node 7c47bb4e-deea-4c23-910d-6ba524f73bbc\n", + "2023-12-01 14:53:18,024: Added application 918b8a5e-e339-4cb1-bb8b-ca2f3ec34372 to node 7c47bb4e-deea-4c23-910d-6ba524f73bbc\n", + "2023-12-01 14:53:18,026::ERROR::primaite.simulator.network.hardware.base::190::NIC c9:b5:db:9d:71:4d/192.168.10.110 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,027: Added node 7c47bb4e-deea-4c23-910d-6ba524f73bbc to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", + "2023-12-01 14:53:18,040::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,042: Added service 66ca1dd3-0997-427b-8663-402141122e75 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", + "2023-12-01 14:53:18,044::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,045: Added service f87b344d-8a8e-4d9d-a341-df5d3bb538ba to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", + "2023-12-01 14:53:18,047: Added application ab20f1e3-e567-4d02-9e16-febcd57c2630 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", + "2023-12-01 14:53:18,057::ERROR::primaite.simulator.network.hardware.base::190::NIC f5:2e:2d:55:76:d3/192.168.10.21 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,058::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,060: Added service 640815d4-878f-4dff-a607-08887b9045a7 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", + "2023-12-01 14:53:18,061::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,063: Added service 655735a9-6db2-41df-b462-f8c14ea53e35 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", + "2023-12-01 14:53:18,072: Added application 84fc60ba-b67e-4b72-86d1-d247fa7e31f7 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", + "2023-12-01 14:53:18,074::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,075: Added service 8f83391f-a59b-4bdb-8fe7-7fe7e19bf1e9 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", + "2023-12-01 14:53:18,077: Added application 75147ae5-cdce-4ac0-a884-fb9bd8f96387 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", + "2023-12-01 14:53:18,078: Added node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", + "2023-12-01 14:53:18,084::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,086: Added service 02915c59-69e2-4248-9e46-16d627460448 to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", + "2023-12-01 14:53:18,087::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,088: Added service 3ec73168-2bad-41cd-b872-7747487410c5 to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", + "2023-12-01 14:53:18,089: Added application 2acc2c11-7eed-4382-b596-389a52b42915 to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", + "2023-12-01 14:53:18,090::ERROR::primaite.simulator.network.hardware.base::190::NIC 18:f5:a0:7f:c8:60/192.168.10.22 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,091::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,093: Added service 99ae3de9-6a18-45b7-b52e-929b2be8b69b to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", + "2023-12-01 14:53:18,093::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,095: Added service 80932931-e76e-4b98-8d05-3998f3a23a75 to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", + "2023-12-01 14:53:18,096: Added application 267775b8-36ad-4627-a5d3-dfd42ba5ecbf to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", + "2023-12-01 14:53:18,098::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", + "2023-12-01 14:53:18,100: Added service b5c7f3cb-d928-433d-8b07-a6a778337c27 to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", + "2023-12-01 14:53:18,102: Added application a3f18b82-33be-4659-96cb-2f069c3a2aa4 to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", + "2023-12-01 14:53:18,103: Added node d8a6abb1-8929-490f-a997-5e3dcb452027 to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", + "2023-12-01 14:53:18,148::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,151::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,153::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,154::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,155::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,155::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,156::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,157::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,159::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,163::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,165::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,167::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "installing DNSClient on node client_1\n", + "installing DNSClient on node client_2\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + ":actor_name:PPO\n", + "2023-12-01 14:53:18,581::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,582::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,583::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,585::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,586::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,588::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,590::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,591::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,593::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,602::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,604::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:18,604::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + ":actor_name:PPO\n", + "Episode: 1, Step: 1, Reward: 0.5\n", + "Episode: 1, Step: 2, Reward: 0.5\n", + "Episode: 1, Step: 3, Reward: 0.5\n", + "Episode: 1, Step: 4, Reward: 0.5\n", + "Episode: 1, Step: 5, Reward: 0.5\n", + "Episode: 1, Step: 6, Reward: 0.5\n", + "Episode: 1, Step: 7, Reward: 0.5\n", + "Episode: 1, Step: 8, Reward: 0.5\n", + "Episode: 1, Step: 9, Reward: 0.5\n", + "Episode: 1, Step: 10, Reward: 0.5\n", + "Episode: 1, Step: 11, Reward: 0.5\n", + "Episode: 1, Step: 12, Reward: 0.5\n", + "Episode: 1, Step: 13, Reward: 0.5\n", + "Episode: 1, Step: 14, Reward: 0.5\n", + "Episode: 1, Step: 15, Reward: 0.5\n", + "Episode: 1, Step: 16, Reward: 0.5\n", + "Episode: 1, Step: 17, Reward: 0.5\n", + "Episode: 1, Step: 18, Reward: 0.5\n", + "Episode: 1, Step: 19, Reward: 0.5\n", + "Episode: 1, Step: 20, Reward: 0.5\n", + "Episode: 1, Step: 21, Reward: 0.5\n", + "Episode: 1, Step: 22, Reward: 0.5\n", + "Episode: 1, Step: 23, Reward: 0.5\n", + "Episode: 1, Step: 24, Reward: 0.5\n", + "Episode: 1, Step: 25, Reward: 0.5\n", + "Episode: 1, Step: 26, Reward: 0.5\n", + "Episode: 1, Step: 27, Reward: 0.5\n", + "Episode: 1, Step: 28, Reward: 0.5\n", + "Episode: 1, Step: 29, Reward: 0.5\n", + "Episode: 1, Step: 30, Reward: 0.5\n", + "Episode: 1, Step: 31, Reward: 0.5\n", + "Episode: 1, Step: 32, Reward: 0.5\n", + "Episode: 1, Step: 33, Reward: 0.5\n", + "Episode: 1, Step: 34, Reward: 0.5\n", + "Episode: 1, Step: 35, Reward: 0.5\n", + "Episode: 1, Step: 36, Reward: 0.5\n", + "Episode: 1, Step: 37, Reward: 0.5\n", + "Episode: 1, Step: 38, Reward: 0.5\n", + "Episode: 1, Step: 39, Reward: 0.5\n", + "Episode: 1, Step: 40, Reward: 0.5\n", + "Episode: 1, Step: 41, Reward: 0.5\n", + "Episode: 1, Step: 42, Reward: 0.5\n", + "Episode: 1, Step: 43, Reward: 0.5\n", + "Episode: 1, Step: 44, Reward: 0.5\n", + "Episode: 1, Step: 45, Reward: 0.5\n", + "Episode: 1, Step: 46, Reward: 0.5\n", + "Episode: 1, Step: 47, Reward: 0.5\n", + "Episode: 1, Step: 48, Reward: 0.5\n", + "Episode: 1, Step: 49, Reward: 0.5\n", + "Episode: 1, Step: 50, Reward: 0.5\n", + "Episode: 1, Step: 51, Reward: 0.5\n", + "Episode: 1, Step: 52, Reward: 0.5\n", + "Episode: 1, Step: 53, Reward: 0.5\n", + "Episode: 1, Step: 54, Reward: 0.5\n", + "Episode: 1, Step: 55, Reward: 0.5\n", + "Episode: 1, Step: 56, Reward: 0.5\n", + "Episode: 1, Step: 57, Reward: 0.5\n", + "Episode: 1, Step: 58, Reward: 0.5\n", + "Episode: 1, Step: 59, Reward: 0.5\n", + "Episode: 1, Step: 60, Reward: 0.5\n", + "Episode: 1, Step: 61, Reward: 0.5\n", + "Episode: 1, Step: 62, Reward: 0.5\n", + "Episode: 1, Step: 63, Reward: 0.5\n", + "Episode: 1, Step: 64, Reward: 0.5\n", + "Episode: 1, Step: 65, Reward: 0.5\n", + "Episode: 1, Step: 66, Reward: 0.5\n", + "Episode: 1, Step: 67, Reward: 0.5\n", + "Episode: 1, Step: 68, Reward: 0.5\n", + "Episode: 1, Step: 69, Reward: 0.5\n", + "Episode: 1, Step: 70, Reward: 0.5\n", + "Episode: 1, Step: 71, Reward: 0.5\n", + "Episode: 1, Step: 72, Reward: 0.5\n", + "Episode: 1, Step: 73, Reward: 0.5\n", + "Episode: 1, Step: 74, Reward: 0.5\n", + "Episode: 1, Step: 75, Reward: 0.5\n", + "Episode: 1, Step: 76, Reward: 0.5\n", + "Episode: 1, Step: 77, Reward: 0.5\n", + "Episode: 1, Step: 78, Reward: 0.5\n", + "Episode: 1, Step: 79, Reward: 0.5\n", + "Episode: 1, Step: 80, Reward: 0.5\n", + "Episode: 1, Step: 81, Reward: 0.5\n", + "Episode: 1, Step: 82, Reward: 0.5\n", + "Episode: 1, Step: 83, Reward: 0.5\n", + "Episode: 1, Step: 84, Reward: 0.5\n", + "Episode: 1, Step: 85, Reward: 0.5\n", + "Episode: 1, Step: 86, Reward: 0.5\n", + "Episode: 1, Step: 87, Reward: 0.5\n", + "Episode: 1, Step: 88, Reward: 0.5\n", + "Episode: 1, Step: 89, Reward: 0.5\n", + "Episode: 1, Step: 90, Reward: 0.5\n", + "Episode: 1, Step: 91, Reward: 0.5\n", + "Episode: 1, Step: 92, Reward: 0.5\n", + "Episode: 1, Step: 93, Reward: 0.5\n", + "Episode: 1, Step: 94, Reward: 0.5\n", + "Episode: 1, Step: 95, Reward: 0.5\n", + "Episode: 1, Step: 96, Reward: 0.5\n", + "Episode: 1, Step: 97, Reward: 0.5\n", + "Episode: 1, Step: 98, Reward: 0.5\n", + "Episode: 1, Step: 99, Reward: 0.5\n", + "Episode: 1, Step: 100, Reward: 0.5\n", + "Episode: 1, Step: 101, Reward: 0.5\n", + "Episode: 1, Step: 102, Reward: 0.5\n", + "Episode: 1, Step: 103, Reward: 0.5\n", + "Episode: 1, Step: 104, Reward: 0.5\n", + "Episode: 1, Step: 105, Reward: 0.5\n", + "Episode: 1, Step: 106, Reward: 0.5\n", + "Episode: 1, Step: 107, Reward: 0.5\n", + "Episode: 1, Step: 108, Reward: 0.5\n", + "Episode: 1, Step: 109, Reward: 0.5\n", + "Episode: 1, Step: 110, Reward: 0.5\n", + "Episode: 1, Step: 111, Reward: 0.5\n", + "Episode: 1, Step: 112, Reward: 0.5\n", + "Episode: 1, Step: 113, Reward: 0.5\n", + "Episode: 1, Step: 114, Reward: 0.5\n", + "Episode: 1, Step: 115, Reward: 0.5\n", + "Episode: 1, Step: 116, Reward: 0.5\n", + "Episode: 1, Step: 117, Reward: 0.5\n", + "Episode: 1, Step: 118, Reward: 0.5\n", + "Episode: 1, Step: 119, Reward: 0.5\n", + "Episode: 1, Step: 120, Reward: 0.5\n", + "Episode: 1, Step: 121, Reward: 0.5\n", + "Episode: 1, Step: 122, Reward: 0.5\n", + "Episode: 1, Step: 123, Reward: 0.5\n", + "Episode: 1, Step: 124, Reward: 0.5\n", + "Episode: 1, Step: 125, Reward: 0.5\n", + "Episode: 1, Step: 126, Reward: 0.5\n", + "Episode: 1, Step: 127, Reward: 0.5\n", + "Episode: 1, Step: 128, Reward: 0.5\n", + "Episode: 1, Step: 129, Reward: 0.5\n", + "\n", + "Episode: 1, Step: 130, Reward: 0.5\n", + "Episode: 1, Step: 131, Reward: 0.5\n", + "Episode: 1, Step: 132, Reward: 0.5\n", + "Episode: 1, Step: 133, Reward: 0.5\n", + "Episode: 1, Step: 134, Reward: 0.5\n", + "Episode: 1, Step: 135, Reward: 0.5\n", + "Episode: 1, Step: 136, Reward: 0.5\n", + "Episode: 1, Step: 137, Reward: 0.5\n", + "Episode: 1, Step: 138, Reward: 0.5\n", + "Episode: 1, Step: 139, Reward: 0.5\n", + "Episode: 1, Step: 140, Reward: 0.5\n", + "Episode: 1, Step: 141, Reward: 0.5\n", + "Episode: 1, Step: 142, Reward: 0.5\n", + "Episode: 1, Step: 143, Reward: 0.5\n", + "Episode: 1, Step: 144, Reward: 0.5\n", + "Episode: 1, Step: 145, Reward: 0.5\n", + "Episode: 1, Step: 146, Reward: 0.5\n", + "Episode: 1, Step: 147, Reward: 0.5\n", + "Episode: 1, Step: 148, Reward: 0.5\n", + "Episode: 1, Step: 149, Reward: 0.5\n", + "Episode: 1, Step: 150, Reward: 0.5\n", + "Episode: 1, Step: 151, Reward: 0.5\n", + "Episode: 1, Step: 152, Reward: 0.5\n", + "Episode: 1, Step: 153, Reward: 0.5\n", + "Episode: 1, Step: 154, Reward: 0.5\n", + "Episode: 1, Step: 155, Reward: 0.5\n", + "Episode: 1, Step: 156, Reward: 0.5\n", + "Episode: 1, Step: 157, Reward: 0.5\n", + "Episode: 1, Step: 158, Reward: 0.5\n", + "Episode: 1, Step: 159, Reward: 0.5\n", + "Episode: 1, Step: 160, Reward: 0.5\n", + "Episode: 1, Step: 161, Reward: 0.5\n", + "Episode: 1, Step: 162, Reward: 0.5\n", + "Episode: 1, Step: 163, Reward: 0.5\n", + "Episode: 1, Step: 164, Reward: 0.5\n", + "Episode: 1, Step: 165, Reward: 0.5\n", + "Episode: 1, Step: 166, Reward: 0.5\n", + "Episode: 1, Step: 167, Reward: 0.5\n", + "Episode: 1, Step: 168, Reward: 0.5\n", + "Episode: 1, Step: 169, Reward: 0.5\n", + "Episode: 1, Step: 170, Reward: 0.5\n", + "Episode: 1, Step: 171, Reward: 0.5\n", + "Episode: 1, Step: 172, Reward: 0.5\n", + "Episode: 1, Step: 173, Reward: 0.5\n", + "Episode: 1, Step: 174, Reward: 0.5\n", + "Episode: 1, Step: 175, Reward: 0.5\n", + "Episode: 1, Step: 176, Reward: 0.5\n", + "Episode: 1, Step: 177, Reward: 0.5\n", + "Episode: 1, Step: 178, Reward: 0.5\n", + "Episode: 1, Step: 179, Reward: 0.5\n", + "Episode: 1, Step: 180, Reward: 0.5\n", + "Episode: 1, Step: 181, Reward: 0.5\n", + "Episode: 1, Step: 182, Reward: 0.5\n", + "Episode: 1, Step: 183, Reward: 0.5\n", + "Episode: 1, Step: 184, Reward: 0.5\n", + "Episode: 1, Step: 185, Reward: 0.5\n", + "Episode: 1, Step: 186, Reward: 0.5\n", + "Episode: 1, Step: 187, Reward: 0.5\n", + "Episode: 1, Step: 188, Reward: 0.5\n", + "Episode: 1, Step: 189, Reward: 0.5\n", + "Episode: 1, Step: 190, Reward: 0.5\n", + "Episode: 1, Step: 191, Reward: 0.5\n", + "Episode: 1, Step: 192, Reward: 0.5\n", + "Episode: 1, Step: 193, Reward: 0.5\n", + "Episode: 1, Step: 194, Reward: 0.5\n", + "Episode: 1, Step: 195, Reward: 0.5\n", + "Episode: 1, Step: 196, Reward: 0.5\n", + "Episode: 1, Step: 197, Reward: 0.5\n", + "Episode: 1, Step: 198, Reward: 0.5\n", + "Episode: 1, Step: 199, Reward: 0.5\n", + "Episode: 1, Step: 200, Reward: 0.5\n", + "Episode: 1, Step: 201, Reward: 0.5\n", + "Episode: 1, Step: 202, Reward: 0.5\n", + "Episode: 1, Step: 203, Reward: 0.5\n", + "Episode: 1, Step: 204, Reward: 0.5\n", + "Episode: 1, Step: 205, Reward: 0.5\n", + "Episode: 1, Step: 206, Reward: 0.5\n", + "Episode: 1, Step: 207, Reward: 0.5\n", + "Episode: 1, Step: 208, Reward: 0.5\n", + "Episode: 1, Step: 209, Reward: 0.5\n", + "Episode: 1, Step: 210, Reward: 0.5\n", + "Episode: 1, Step: 211, Reward: 0.5\n", + "Episode: 1, Step: 212, Reward: 0.5\n", + "Episode: 1, Step: 213, Reward: 0.5\n", + "Episode: 1, Step: 214, Reward: 0.5\n", + "Episode: 1, Step: 215, Reward: 0.5\n", + "Episode: 1, Step: 216, Reward: 0.5\n", + "Episode: 1, Step: 217, Reward: 0.5\n", + "Episode: 1, Step: 218, Reward: 0.5\n", + "Episode: 1, Step: 219, Reward: 0.5\n", + "Episode: 1, Step: 220, Reward: 0.5\n", + "Episode: 1, Step: 221, Reward: 0.5\n", + "Episode: 1, Step: 222, Reward: 0.5\n", + "Episode: 1, Step: 223, Reward: 0.5\n", + "Episode: 1, Step: 224, Reward: 0.5\n", + "Episode: 1, Step: 225, Reward: 0.5\n", + "Episode: 1, Step: 226, Reward: 0.5\n", + "Episode: 1, Step: 227, Reward: 0.5\n", + "Episode: 1, Step: 228, Reward: 0.5\n", + "Episode: 1, Step: 229, Reward: 0.5\n", + "Episode: 1, Step: 230, Reward: 0.5\n", + "Episode: 1, Step: 231, Reward: 0.5\n", + "Episode: 1, Step: 232, Reward: 0.5\n", + "Episode: 1, Step: 233, Reward: 0.5\n", + "Episode: 1, Step: 234, Reward: 0.5\n", + "Episode: 1, Step: 235, Reward: 0.5\n", + "Episode: 1, Step: 236, Reward: 0.5\n", + "Episode: 1, Step: 237, Reward: 0.5\n", + "Episode: 1, Step: 238, Reward: 0.5\n", + "Episode: 1, Step: 239, Reward: 0.5\n", + "Episode: 1, Step: 240, Reward: 0.5\n", + "Episode: 1, Step: 241, Reward: 0.5\n", + "Episode: 1, Step: 242, Reward: 0.5\n", + "Episode: 1, Step: 243, Reward: 0.5\n", + "Episode: 1, Step: 244, Reward: 0.5\n", + "Episode: 1, Step: 245, Reward: 0.5\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-12-01 14:53:21,247::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:21,248::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:21,249::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:21,251::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:21,252::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:21,254::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:21,256::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:21,259::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:21,262::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:21,292::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:21,293::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:21,294::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Episode: 1, Step: 246, Reward: 0.5\n", + "Episode: 1, Step: 247, Reward: 0.5\n", + "Episode: 1, Step: 248, Reward: 0.5\n", + "Episode: 1, Step: 249, Reward: 0.5\n", + "Episode: 1, Step: 250, Reward: 0.5\n", + "Episode: 1, Step: 251, Reward: 0.5\n", + "Episode: 1, Step: 252, Reward: 0.5\n", + "Episode: 1, Step: 253, Reward: 0.5\n", + "Episode: 1, Step: 254, Reward: 0.5\n", + "Episode: 1, Step: 255, Reward: 0.5\n", + "Episode: 1, Step: 256, Reward: 0.5\n", + "Episode: 2, Step: 1, Reward: 0.5\n", + "Episode: 2, Step: 2, Reward: 0.5\n", + "Episode: 2, Step: 3, Reward: 0.5\n", + "Episode: 2, Step: 4, Reward: 0.5\n", + "Episode: 2, Step: 5, Reward: 0.5\n", + "Episode: 2, Step: 6, Reward: 0.5\n", + "Episode: 2, Step: 7, Reward: 0.5\n", + "Episode: 2, Step: 8, Reward: 0.5\n", + "Episode: 2, Step: 9, Reward: 0.5\n", + "Episode: 2, Step: 10, Reward: 0.5\n", + "Episode: 2, Step: 11, Reward: 0.5\n", + "Episode: 2, Step: 12, Reward: 0.5\n", + "Episode: 2, Step: 13, Reward: 0.5\n", + "Episode: 2, Step: 14, Reward: 0.5\n", + "Episode: 2, Step: 15, Reward: 0.5\n", + "Episode: 2, Step: 16, Reward: 0.5\n", + "Episode: 2, Step: 17, Reward: 0.5\n", + "Episode: 2, Step: 18, Reward: 0.5\n", + "Episode: 2, Step: 19, Reward: 0.5\n", + "Episode: 2, Step: 20, Reward: 0.5\n", + "Episode: 2, Step: 21, Reward: 0.5\n", + "Episode: 2, Step: 22, Reward: 0.5\n", + "Episode: 2, Step: 23, Reward: 0.5\n", + "Episode: 2, Step: 24, Reward: 0.5\n", + "Episode: 2, Step: 25, Reward: 0.5\n", + "Episode: 2, Step: 26, Reward: 0.5\n", + "Episode: 2, Step: 27, Reward: 0.5\n", + "Episode: 2, Step: 28, Reward: 0.5\n", + "Episode: 2, Step: 29, Reward: 0.5\n", + "Episode: 2, Step: 30, Reward: 0.5\n", + "Episode: 2, Step: 31, Reward: 0.5\n", + "Episode: 2, Step: 32, Reward: 0.5\n", + "Episode: 2, Step: 33, Reward: 0.5\n", + "Episode: 2, Step: 34, Reward: 0.5\n", + "Episode: 2, Step: 35, Reward: 0.5\n", + "Episode: 2, Step: 36, Reward: 0.5\n", + "Episode: 2, Step: 37, Reward: 0.5\n", + "Episode: 2, Step: 38, Reward: 0.5\n", + "Episode: 2, Step: 39, Reward: 0.5\n", + "Episode: 2, Step: 40, Reward: 0.5\n", + "Episode: 2, Step: 41, Reward: 0.5\n", + "Episode: 2, Step: 42, Reward: 0.5\n", + "Episode: 2, Step: 43, Reward: 0.5\n", + "Episode: 2, Step: 44, Reward: 0.5\n", + "Episode: 2, Step: 45, Reward: 0.5\n", + "Episode: 2, Step: 46, Reward: 0.5\n", + "Episode: 2, Step: 47, Reward: 0.5\n", + "Episode: 2, Step: 48, Reward: 0.5\n", + "Episode: 2, Step: 49, Reward: 0.5\n", + "Episode: 2, Step: 50, Reward: 0.5\n", + "Episode: 2, Step: 51, Reward: 0.5\n", + "Episode: 2, Step: 52, Reward: 0.5\n", + "Episode: 2, Step: 53, Reward: 0.5\n", + "Episode: 2, Step: 54, Reward: 0.5\n", + "Episode: 2, Step: 55, Reward: 0.5\n", + "Episode: 2, Step: 56, Reward: 0.5\n", + "Episode: 2, Step: 57, Reward: 0.5\n", + "Episode: 2, Step: 58, Reward: 0.5\n", + "Episode: 2, Step: 59, Reward: 0.5\n", + "Episode: 2, Step: 60, Reward: 0.5\n", + "Episode: 2, Step: 61, Reward: 0.5\n", + "Episode: 2, Step: 62, Reward: 0.5\n", + "Episode: 2, Step: 63, Reward: 0.5\n", + "Episode: 2, Step: 64, Reward: 0.5\n", + "Episode: 2, Step: 65, Reward: 0.5\n", + "Episode: 2, Step: 66, Reward: 0.5\n", + "Episode: 2, Step: 67, Reward: 0.5\n", + "Episode: 2, Step: 68, Reward: 0.5\n", + "Episode: 2, Step: 69, Reward: 0.5\n", + "Episode: 2, Step: 70, Reward: 0.5\n", + "Episode: 2, Step: 71, Reward: 0.5\n", + "Episode: 2, Step: 72, Reward: 0.5\n", + "Episode: 2, Step: 73, Reward: 0.5\n", + "Episode: 2, Step: 74, Reward: 0.5\n", + "Episode: 2, Step: 75, Reward: 0.5\n", + "Episode: 2, Step: 76, Reward: 0.5\n", + "Episode: 2, Step: 77, Reward: 0.5\n", + "Episode: 2, Step: 78, Reward: 0.5\n", + "Episode: 2, Step: 79, Reward: 0.5\n", + "Episode: 2, Step: 80, Reward: 0.5\n", + "Episode: 2, Step: 81, Reward: 0.5\n", + "Episode: 2, Step: 82, Reward: 0.5\n", + "Episode: 2, Step: 83, Reward: 0.5\n", + "Episode: 2, Step: 84, Reward: 0.5\n", + "Episode: 2, Step: 85, Reward: 0.5\n", + "Episode: 2, Step: 86, Reward: 0.5\n", + "Episode: 2, Step: 87, Reward: 0.5\n", + "Episode: 2, Step: 88, Reward: 0.5\n", + "Episode: 2, Step: 89, Reward: 0.5\n", + "Episode: 2, Step: 90, Reward: 0.5\n", + "Episode: 2, Step: 91, Reward: 0.5\n", + "Episode: 2, Step: 92, Reward: 0.5\n", + "Episode: 2, Step: 93, Reward: 0.5\n", + "Episode: 2, Step: 94, Reward: 0.5\n", + "Episode: 2, Step: 95, Reward: 0.5\n", + "Episode: 2, Step: 96, Reward: 0.5\n", + "Episode: 2, Step: 97, Reward: 0.5\n", + "Episode: 2, Step: 98, Reward: 0.5\n", + "Episode: 2, Step: 99, Reward: 0.5\n", + "Episode: 2, Step: 100, Reward: 0.5\n", + "Episode: 2, Step: 101, Reward: 0.5\n", + "Episode: 2, Step: 102, Reward: 0.5\n", + "Episode: 2, Step: 103, Reward: 0.5\n", + "Episode: 2, Step: 104, Reward: 0.5\n", + "Episode: 2, Step: 105, Reward: 0.5\n", + "Episode: 2, Step: 106, Reward: 0.5\n", + "Episode: 2, Step: 107, Reward: 0.5\n", + "Episode: 2, Step: 108, Reward: 0.5\n", + "Episode: 2, Step: 109, Reward: 0.5\n", + "Episode: 2, Step: 110, Reward: 0.5\n", + "Episode: 2, Step: 111, Reward: 0.5\n", + "Episode: 2, Step: 112, Reward: 0.5\n", + "Episode: 2, Step: 113, Reward: 0.5\n", + "Episode: 2, Step: 114, Reward: 0.5\n", + "Episode: 2, Step: 115, Reward: 0.5\n", + "Episode: 2, Step: 116, Reward: 0.5\n", + "Episode: 2, Step: 117, Reward: 0.5\n", + "Episode: 2, Step: 118, Reward: 0.5\n", + "Episode: 2, Step: 119, Reward: 0.5\n", + "Episode: 2, Step: 120, Reward: 0.5\n", + "Episode: 2, Step: 121, Reward: 0.5\n", + "Episode: 2, Step: 122, Reward: 0.5\n", + "Episode: 2, Step: 123, Reward: 0.5\n", + "Episode: 2, Step: 124, Reward: 0.5\n", + "Episode: 2, Step: 125, Reward: 0.5\n", + "Episode: 2, Step: 126, Reward: 0.5\n", + "Episode: 2, Step: 127, Reward: 0.5\n", + "Episode: 2, Step: 128, Reward: 0.5\n", + "Episode: 2, Step: 129, Reward: 0.5\n", + "Episode: 2, Step: 130, Reward: 0.5\n", + "Episode: 2, Step: 131, Reward: 0.5\n", + "Episode: 2, Step: 132, Reward: 0.5\n", + "Episode: 2, Step: 133, Reward: 0.5\n", + "Episode: 2, Step: 134, Reward: 0.5\n", + "Episode: 2, Step: 135, Reward: 0.5\n", + "Episode: 2, Step: 136, Reward: 0.5\n", + "Episode: 2, Step: 137, Reward: 0.5\n", + "Episode: 2, Step: 138, Reward: 0.5\n", + "Episode: 2, Step: 139, Reward: 0.5\n", + "Episode: 2, Step: 140, Reward: 0.5\n", + "Episode: 2, Step: 141, Reward: 0.5\n", + "Episode: 2, Step: 142, Reward: 0.5\n", + "Episode: 2, Step: 143, Reward: 0.5\n", + "Episode: 2, Step: 144, Reward: 0.5\n", + "Episode: 2, Step: 145, Reward: 0.5\n", + "Episode: 2, Step: 146, Reward: 0.5\n", + "Episode: 2, Step: 147, Reward: 0.5\n", + "Episode: 2, Step: 148, Reward: 0.5\n", + "Episode: 2, Step: 149, Reward: 0.5\n", + "Episode: 2, Step: 150, Reward: 0.5\n", + "Episode: 2, Step: 151, Reward: 0.5\n", + "Episode: 2, Step: 152, Reward: 0.5\n", + "Episode: 2, Step: 153, Reward: 0.5\n", + "Episode: 2, Step: 154, Reward: 0.5\n", + "Episode: 2, Step: 155, Reward: 0.5\n", + "Episode: 2, Step: 156, Reward: 0.5\n", + "Episode: 2, Step: 157, Reward: 0.5\n", + "Episode: 2, Step: 158, Reward: 0.5\n", + "Episode: 2, Step: 159, Reward: 0.5\n", + "Episode: 2, Step: 160, Reward: 0.5\n", + "Episode: 2, Step: 161, Reward: 0.5\n", + "Episode: 2, Step: 162, Reward: 0.5\n", + "Episode: 2, Step: 163, Reward: 0.5\n", + "Episode: 2, Step: 164, Reward: 0.5\n", + "Episode: 2, Step: 165, Reward: 0.5\n", + "Episode: 2, Step: 166, Reward: 0.5\n", + "Episode: 2, Step: 167, Reward: 0.5\n", + "Episode: 2, Step: 168, Reward: 0.5\n", + "Episode: 2, Step: 169, Reward: 0.5\n", + "Episode: 2, Step: 170, Reward: 0.5\n", + "Episode: 2, Step: 171, Reward: 0.5\n", + "Episode: 2, Step: 172, Reward: 0.5\n", + "Episode: 2, Step: 173, Reward: 0.5\n", + "Episode: 2, Step: 174, Reward: 0.5\n", + "Episode: 2, Step: 175, Reward: 0.5\n", + "Episode: 2, Step: 176, Reward: 0.5\n", + "Episode: 2, Step: 177, Reward: 0.5\n", + "Episode: 2, Step: 178, Reward: 0.5\n", + "Episode: 2, Step: 179, Reward: 0.5\n", + "Episode: 2, Step: 180, Reward: 0.5\n", + "Episode: 2, Step: 181, Reward: 0.5\n", + "Episode: 2, Step: 182, Reward: 0.5\n", + "Episode: 2, Step: 183, Reward: 0.5\n", + "Episode: 2, Step: 184, Reward: 0.5\n", + "Episode: 2, Step: 185, Reward: 0.5\n", + "Episode: 2, Step: 186, Reward: 0.5\n", + "Episode: 2, Step: 187, Reward: 0.5\n", + "Episode: 2, Step: 188, Reward: 0.5\n", + "Episode: 2, Step: 189, Reward: 0.5\n", + "Episode: 2, Step: 190, Reward: 0.5\n", + "Episode: 2, Step: 191, Reward: 0.5\n", + "Episode: 2, Step: 192, Reward: 0.5\n", + "Episode: 2, Step: 193, Reward: 0.5\n", + "Episode: 2, Step: 194, Reward: 0.5\n", + "Episode: 2, Step: 195, Reward: 0.5\n", + "Episode: 2, Step: 196, Reward: 0.5\n", + "Episode: 2, Step: 197, Reward: 0.5\n", + "Episode: 2, Step: 198, Reward: 0.5\n", + "Episode: 2, Step: 199, Reward: 0.5\n", + "Episode: 2, Step: 200, Reward: 0.5\n", + "Episode: 2, Step: 201, Reward: 0.5\n", + "Episode: 2, Step: 202, Reward: 0.5\n", + "Episode: 2, Step: 203, Reward: 0.5\n", + "Episode: 2, Step: 204, Reward: 0.5\n", + "Episode: 2, Step: 205, Reward: 0.5\n", + "Episode: 2, Step: 206, Reward: 0.5\n", + "Episode: 2, Step: 207, Reward: 0.5\n", + "Episode: 2, Step: 208, Reward: 0.5\n", + "Episode: 2, Step: 209, Reward: 0.5\n", + "Episode: 2, Step: 210, Reward: 0.5\n", + "Episode: 2, Step: 211, Reward: 0.5\n", + "Episode: 2, Step: 212, Reward: 0.5\n", + "Episode: 2, Step: 213, Reward: 0.5\n", + "Episode: 2, Step: 214, Reward: 0.5\n", + "Episode: 2, Step: 215, Reward: 0.5\n", + "Episode: 2, Step: 216, Reward: 0.5\n", + "Episode: 2, Step: 217, Reward: 0.5\n", + "Episode: 2, Step: 218, Reward: 0.5\n", + "Episode: 2, Step: 219, Reward: 0.5\n", + "Episode: 2, Step: 220, Reward: 0.5\n", + "Episode: 2, Step: 221, Reward: 0.5\n", + "Episode: 2, Step: 222, Reward: 0.5\n", + "Episode: 2, Step: 223, Reward: 0.5\n", + "Episode: 2, Step: 224, Reward: 0.5\n", + "Episode: 2, Step: 225, Reward: 0.5\n", + "Episode: 2, Step: 226, Reward: 0.5\n", + "Episode: 2, Step: 227, Reward: 0.5\n", + "Episode: 2, Step: 228, Reward: 0.5\n", + "Episode: 2, Step: 229, Reward: 0.5\n", + "Episode: 2, Step: 230, Reward: 0.5\n", + "Episode: 2, Step: 231, Reward: 0.5\n", + "Episode: 2, Step: 232, Reward: 0.5\n", + "Episode: 2, Step: 233, Reward: 0.5\n", + "Episode: 2, Step: 234, Reward: 0.5\n", + "Episode: 2, Step: 235, Reward: 0.5\n", + "Episode: 2, Step: 236, Reward: 0.5\n", + "Episode: 2, Step: 237, Reward: 0.5\n", + "Episode: 2, Step: 238, Reward: 0.5\n", + "Episode: 2, Step: 239, Reward: 0.5\n", + "Episode: 2, Step: 240, Reward: 0.5\n", + "Episode: 2, Step: 241, Reward: 0.5\n", + "Episode: 2, Step: 242, Reward: 0.5\n", + "Episode: 2, Step: 243, Reward: 0.5\n", + "Episode: 2, Step: 244, Reward: 0.5\n", + "Episode: 2, Step: 245, Reward: 0.5\n", + "Episode: 2, Step: 246, Reward: 0.5\n", + "Episode: 2, Step: 247, Reward: 0.5\n", + "Episode: 2, Step: 248, Reward: 0.5\n", + "Episode: 2, Step: 249, Reward: 0.5\n", + "Episode: 2, Step: 250, Reward: 0.5\n", + "Episode: 2, Step: 251, Reward: 0.5\n", + "Episode: 2, Step: 252, Reward: 0.5\n", + "Episode: 2, Step: 253, Reward: 0.5\n", + "Episode: 2, Step: 254, Reward: 0.5\n", + "Episode: 2, Step: 255, Reward: 0.5\n", + "Episode: 2, Step: 256, Reward: 0.5\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-12-01 14:53:24,371::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:24,373::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:24,375::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:24,375::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:24,376::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:24,377::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:24,379::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:24,380::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:24,381::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:24,402::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:24,404::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", + "2023-12-01 14:53:24,406::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Episode: 3, Step: 1, Reward: 0.5\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-12-01 14:53:24,878\tINFO storage.py:563 -- Checkpoint successfully created at: Checkpoint(filesystem=local, path=/home/cade/ray_results/PPO_2023-12-01_14-53-17/PPO_PrimaiteRayEnv_5cbc4_00000_0_2023-12-01_14-53-17/checkpoint_000000)\n", + "2023-12-01 14:53:25,098\tINFO tune.py:1047 -- Total run time: 7.37 seconds (7.31 seconds for the tuning loop).\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "ResultGrid<[\n", + " Result(\n", + " metrics={'custom_metrics': {}, 'episode_media': {}, 'info': {'learner': {'__all__': {'num_agent_steps_trained': 128.0, 'num_env_steps_trained': 128.0, 'total_loss': 9.403312460581462}, 'default_policy': {'total_loss': 9.403312460581462, 'policy_loss': -0.06894568807135025, 'vf_loss': 9.469796816507975, 'vf_loss_unclipped': 416.65203653971355, 'vf_explained_var': 0.0007335106531778971, 'entropy': 3.864323592185974, 'mean_kl_loss': 0.012305201259247648, 'default_optimizer_lr': 4.999999999999999e-05, 'curr_lr': 5e-05, 'curr_entropy_coeff': 0.0, 'curr_kl_coeff': 0.20000000298023224}}, 'num_env_steps_sampled': 512, 'num_env_steps_trained': 0, 'num_agent_steps_sampled': 512, 'num_agent_steps_trained': 0}, 'sampler_results': {'episode_reward_max': 128.0, 'episode_reward_min': 128.0, 'episode_reward_mean': 128.0, 'episode_len_mean': 256.0, 'episode_media': {}, 'episodes_this_iter': 1, 'policy_reward_min': {}, 'policy_reward_max': {}, 'policy_reward_mean': {}, 'custom_metrics': {}, 'hist_stats': {'episode_reward': [128.0, 128.0], 'episode_lengths': [256, 256]}, 'sampler_perf': {'mean_raw_obs_processing_ms': 0.8607522543689299, 'mean_inference_ms': 2.1271821797748984, 'mean_action_processing_ms': 0.15329866429338604, 'mean_env_wait_ms': 6.184263571370873, 'mean_env_render_ms': 0.0}, 'num_faulty_episodes': 0, 'connector_metrics': {'ObsPreprocessorConnector_ms': 0.010561943054199219, 'StateBufferConnector_ms': 0.004971027374267578, 'ViewRequirementAgentConnector_ms': 0.29495954513549805}}, 'episode_reward_max': 128.0, 'episode_reward_min': 128.0, 'episode_reward_mean': 128.0, 'episode_len_mean': 256.0, 'episodes_this_iter': 1, 'policy_reward_min': {}, 'policy_reward_max': {}, 'policy_reward_mean': {}, 'hist_stats': {'episode_reward': [128.0, 128.0], 'episode_lengths': [256, 256]}, 'sampler_perf': {'mean_raw_obs_processing_ms': 0.8607522543689299, 'mean_inference_ms': 2.1271821797748984, 'mean_action_processing_ms': 0.15329866429338604, 'mean_env_wait_ms': 6.184263571370873, 'mean_env_render_ms': 0.0}, 'num_faulty_episodes': 0, 'connector_metrics': {'ObsPreprocessorConnector_ms': 0.010561943054199219, 'StateBufferConnector_ms': 0.004971027374267578, 'ViewRequirementAgentConnector_ms': 0.29495954513549805}, 'num_healthy_workers': 0, 'num_in_flight_async_reqs': 0, 'num_remote_worker_restarts': 0, 'num_agent_steps_sampled': 512, 'num_agent_steps_trained': 0, 'num_env_steps_sampled': 512, 'num_env_steps_trained': 0, 'num_env_steps_sampled_this_iter': 128, 'num_env_steps_trained_this_iter': 0, 'num_env_steps_sampled_throughput_per_sec': 85.63165451744611, 'num_env_steps_trained_throughput_per_sec': 0.0, 'num_steps_trained_this_iter': 0, 'agent_timesteps_total': 512, 'timers': {'training_iteration_time_ms': 1530.574, 'sample_time_ms': 1196.582, 'synch_weights_time_ms': 1.912}, 'counters': {'num_env_steps_sampled': 512, 'num_env_steps_trained': 0, 'num_agent_steps_sampled': 512, 'num_agent_steps_trained': 0}, 'perf': {'cpu_util_percent': 55.25, 'ram_util_percent': 58.8}},\n", + " path='/home/cade/ray_results/PPO_2023-12-01_14-53-17/PPO_PrimaiteRayEnv_5cbc4_00000_0_2023-12-01_14-53-17',\n", + " filesystem='local',\n", + " checkpoint=Checkpoint(filesystem=local, path=/home/cade/ray_results/PPO_2023-12-01_14-53-17/PPO_PrimaiteRayEnv_5cbc4_00000_0_2023-12-01_14-53-17/checkpoint_000000)\n", + " )\n", + "]>" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "gym = PrimaiteRayEnv({\"game\":game})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ray\n", - "from ray.rllib.algorithms import ppo" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ray.shutdown()\n", - "ray.init()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "env_config = {\"game\":game}\n", - "config = {\n", - " \"env\" : PrimaiteRayEnv,\n", - " \"env_config\" : env_config,\n", - " \"disable_env_checking\": True,\n", - " \"num_rollout_workers\": 0,\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "algo = ppo.PPO(config=config)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "for i in range(5):\n", - " result = algo.train()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "algo.save(\"temp/deleteme\")" + "tune.Tuner(\n", + " \"PPO\",\n", + " run_config=air.RunConfig(\n", + " stop={\"timesteps_total\": 512}\n", + " ),\n", + " param_space=config\n", + ").fit()\n" ] } ], diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index a5fdade9..87cf4f2d 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -69,14 +69,15 @@ class PrimaiteGymEnv(gymnasium.Env): class PrimaiteRayEnv(gymnasium.Env): """Ray wrapper that accepts a single `env_config` parameter in init function for compatibility with Ray.""" - def __init__(self, env_config: Dict[str, PrimaiteGame]) -> None: + def __init__(self, env_config: Dict) -> None: """Initialise the environment. :param env_config: A dictionary containing the environment configuration. It must contain a single key, `game` which is the PrimaiteGame instance. :type env_config: Dict[str, PrimaiteGame] """ - self.env = PrimaiteGymEnv(game=env_config["game"]) + self.env = PrimaiteGymEnv(game=PrimaiteGame.from_config(env_config["cfg"])) + self.env.game.episode_counter -= 1 self.action_space = self.env.action_space self.observation_space = self.env.observation_space @@ -92,14 +93,14 @@ class PrimaiteRayEnv(gymnasium.Env): class PrimaiteRayMARLEnv(MultiAgentEnv): """Ray Environment that inherits from MultiAgentEnv to allow training MARL systems.""" - def __init__(self, env_config: Optional[Dict] = None) -> None: + def __init__(self, env_config: Dict) -> None: """Initialise the environment. :param env_config: A dictionary containing the environment configuration. It must contain a single key, `game` which is the PrimaiteGame instance. :type env_config: Dict[str, PrimaiteGame] """ - self.game: PrimaiteGame = env_config["game"] + self.game: PrimaiteGame = PrimaiteGame.from_config(env_config["cfg"]) """Reference to the primaite game""" self.agents: Final[Dict[str, ProxyAgent]] = {agent.agent_name: agent for agent in self.game.rl_agents} """List of all possible agents in the environment. This list should not change!""" @@ -108,7 +109,10 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): self.terminateds = set() self.truncateds = set() self.observation_space = gymnasium.spaces.Dict( - {name: agent.observation_manager.space for name, agent in self.agents.items()} + { + name: gymnasium.spaces.flatten_space(agent.observation_manager.space) + for name, agent in self.agents.items() + } ) self.action_space = gymnasium.spaces.Dict( {name: agent.action_manager.space for name, agent in self.agents.items()} @@ -159,4 +163,9 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): def _get_obs(self) -> Dict[str, ObsType]: """Return the current observation.""" - return {name: agent.observation_manager.current_observation for name, agent in self.agents.items()} + obs = {} + for name, agent in self.agents.items(): + unflat_space = agent.observation_manager.space + unflat_obs = agent.observation_manager.current_observation + obs[name] = gymnasium.spaces.flatten(unflat_space, unflat_obs) + return obs diff --git a/src/primaite/session/policy/rllib.py b/src/primaite/session/policy/rllib.py index be181797..ca69a2a8 100644 --- a/src/primaite/session/policy/rllib.py +++ b/src/primaite/session/policy/rllib.py @@ -12,6 +12,10 @@ from ray import air, tune from ray.rllib.algorithms import ppo from ray.rllib.algorithms.ppo import PPOConfig +from primaite import getLogger + +_LOGGER = getLogger(__name__) + class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): """Single agent RL policy using Ray RLLib.""" @@ -19,7 +23,7 @@ class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): super().__init__(session=session) - config = { + self.config = { "env": PrimaiteRayEnv, "env_config": {"game": session.game}, "disable_env_checking": True, @@ -29,12 +33,13 @@ class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): ray.shutdown() ray.init() - self._algo = ppo.PPO(config=config) - def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: """Train the agent.""" - for ep in range(n_episodes): - self._algo.train() + self.config["training_iterations"] = n_episodes * timesteps_per_episode + self.config["train_batch_size"] = 128 + self._algo = ppo.PPO(config=self.config) + _LOGGER.info("Starting RLLIB training session") + self._algo.train() def eval(self, n_episodes: int, deterministic: bool) -> None: """Evaluate the agent.""" From 294f57c292dfbbdacc95b91f927c9fa9a99a0862 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 15:08:42 +0000 Subject: [PATCH 439/980] #2084: find paths with wildcard --- .azure/azure-ci-build-pipeline.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 147b8c14..4724cc87 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -98,7 +98,7 @@ stages: displayName: 'Perform PrimAITE Setup' - script: | - pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:coverage.xml --cov-report html + pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:coverage.xml --cov-report html --cov-report term --cov-fail-under=80 displayName: 'Run tests and code coverage' - task: PublishTestResults@2 @@ -112,8 +112,8 @@ stages: displayName: 'Publish coverage report' inputs: codeCoverageTool: Cobertura - summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage.xml - pathToSources: $(System.DefaultWorkingDirectory)/ - reportDirectory: $(System.DefaultWorkingDirectory)/htmlcov - additionalCodeCoverageFiles: $(System.DefaultWorkingDirectory)/htmlcov/*.* + summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml' + pathToSources: '$(System.DefaultWorkingDirectory)/src' + reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov' + additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/**/htmlcov/*.*' failIfCoverageEmpty: true From 6598c66da159ea446f02dc8a5a24830b43b6ba8a Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 15:18:38 +0000 Subject: [PATCH 440/980] #2084: i hope no one is keeping an eye on these atrocious commit messages --- .azure/azure-ci-build-pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 4724cc87..00b977db 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -98,7 +98,7 @@ stages: displayName: 'Perform PrimAITE Setup' - script: | - pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:coverage.xml --cov-report html --cov-report term --cov-fail-under=80 + pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term --cov-fail-under=80 displayName: 'Run tests and code coverage' - task: PublishTestResults@2 From f0327da9b6d4e523346546c5871d42547099e07a Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 15:33:43 +0000 Subject: [PATCH 441/980] #2084: remove 80% requirement - causes tests to fail --- .azure/azure-ci-build-pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 00b977db..4c5afed8 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -98,7 +98,7 @@ stages: displayName: 'Perform PrimAITE Setup' - script: | - pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term --cov-fail-under=80 + pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term displayName: 'Run tests and code coverage' - task: PublishTestResults@2 From eeedea2eff30eb458763c503a45b9827bcc2c928 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 1 Dec 2023 15:36:07 +0000 Subject: [PATCH 442/980] Make more friendly user outputs when training SB3 --- .../config/_package_data/example_config.yaml | 4 +- src/primaite/game/agent/rewards.py | 1 + src/primaite/game/game.py | 13 +- .../training_example_ray_multi_agent.ipynb | 83 +- .../training_example_ray_single_agent.ipynb | 909 +----------------- src/primaite/session/environment.py | 5 +- src/primaite/session/session.py | 1 + src/primaite/simulator/core.py | 2 +- src/primaite/simulator/network/container.py | 2 +- .../simulator/network/hardware/base.py | 4 +- 10 files changed, 96 insertions(+), 928 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index b68861e1..7d5b50d6 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -655,8 +655,8 @@ simulation: - ref: data_manipulation_bot type: DataManipulationBot options: - port_scan_p_of_success: 0.1 - data_manipulation_p_of_success: 0.1 + port_scan_p_of_success: 0.8 + data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 services: diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 3466114c..71945a24 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -239,6 +239,7 @@ class RewardFunction: self.reward_components: List[Tuple[AbstractReward, float]] = [] "attribute reward_components keeps track of reward components and the weights assigned to each." self.current_reward: float + self.total_reward: float = 0.0 def regsiter_component(self, component: AbstractReward, weight: float = 1.0) -> None: """Add a reward component to the reward function. diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 38e9d5fc..a36cbea9 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -125,6 +125,7 @@ class PrimaiteGame: for agent in self.agents: agent.update_observation(state) agent.update_reward(state) + agent.reward_function.total_reward += agent.reward_function.current_reward def apply_agent_actions(self) -> None: """Apply all actions to simulation as requests.""" @@ -155,6 +156,8 @@ class PrimaiteGame: self.step_counter = 0 _LOGGER.debug(f"Resetting primaite game, episode = {self.episode_counter}") self.simulation.reset_component_for_episode(episode=self.episode_counter) + for agent in self.agents: + agent.reward_function.total_reward = 0.0 def close(self) -> None: """Close the game, this will close the simulation.""" @@ -240,7 +243,7 @@ class PrimaiteGame: position=r_num, ) else: - print("invalid node type") + _LOGGER.warning(f"invalid node type {n_type} in config") if "services" in node_cfg: for service_cfg in node_cfg["services"]: new_service = None @@ -256,12 +259,12 @@ class PrimaiteGame: "FTPServer": FTPServer, } if service_type in service_types_mapping: - print(f"installing {service_type} on node {new_node.hostname}") + _LOGGER.debug(f"installing {service_type} on node {new_node.hostname}") new_node.software_manager.install(service_types_mapping[service_type]) new_service = new_node.software_manager.software[service_type] game.ref_map_services[service_ref] = new_service.uuid else: - print(f"service type not found {service_type}") + _LOGGER.warning(f"service type not found {service_type}") # service-dependent options if service_type == "DatabaseClient": if "options" in service_cfg: @@ -295,7 +298,7 @@ class PrimaiteGame: new_application = new_node.software_manager.software[application_type] game.ref_map_applications[application_ref] = new_application.uuid else: - print(f"application type not found {application_type}") + _LOGGER.warning(f"application type not found {application_type}") if application_type == "DataManipulationBot": if "options" in application_cfg: @@ -416,7 +419,7 @@ class PrimaiteGame: ) game.agents.append(new_agent) else: - print("agent type not found") + _LOGGER.warning(f"agent type {agent_type} not found") game.simulation.set_original_state() diff --git a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb index 3d5d7ba6..cd9ecfe7 100644 --- a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb @@ -1,5 +1,21 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Train a Multi agent system using RLLIB\n", + "\n", + "This notebook will demonstrate how to use the `PrimaiteRayMARLEnv` to train a very basic system with two PPO agents." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### First, Import packages and read our config file." + ] + }, { "cell_type": "code", "execution_count": null, @@ -8,30 +24,28 @@ "source": [ "from primaite.game.game import PrimaiteGame\n", "import yaml\n", - "from primaite.config.load import example_config_path\n", "\n", - "from primaite.session.environment import PrimaiteRayEnv" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "with open('/home/cade/repos/PrimAITE/src/primaite/config/_package_data/example_config_2_rl_agents.yaml', 'r') as f:\n", - " cfg = yaml.safe_load(f)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ + "from primaite.session.environment import PrimaiteRayEnv\n", + "from primaite import PRIMAITE_PATHS\n", + "\n", "import ray\n", "from ray import air, tune\n", - "from ray.rllib.algorithms.ppo import PPOConfig" + "from ray.rllib.algorithms.ppo import PPOConfig\n", + "from primaite.session.environment import PrimaiteRayMARLEnv\n", + "\n", + "# If you get an error saying this config file doesn't exist, you may need to run `primaite setup` in your command line\n", + "# to copy the files to your user data path.\n", + "with open(PRIMAITE_PATHS.user_config_path / 'example_config/example_config_2_rl_agents.yaml', 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + "\n", + "ray.init(local_mode=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Create a Ray algorithm config which accepts our two agents" ] }, { @@ -40,13 +54,10 @@ "metadata": {}, "outputs": [], "source": [ - "from primaite.session.environment import PrimaiteRayMARLEnv\n", - "\n", - "\n", "config = (\n", " PPOConfig()\n", " .multi_agent(\n", - " policies={'defender_1','defender_2'},\n", + " policies={'defender_1','defender_2'}, # These names are the same as the agents defined in the example config.\n", " policy_mapping_fn=lambda agent_id, episode, worker, **kw: agent_id,\n", " )\n", " .environment(env=PrimaiteRayMARLEnv, env_config={\"cfg\":cfg})#, disable_env_checking=True)\n", @@ -55,6 +66,14 @@ " )\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Set training parameters and start the training\n", + "This example will save outputs to a default Ray directory and use mostly default settings." + ] + }, { "cell_type": "code", "execution_count": null, @@ -69,20 +88,6 @@ " param_space=config\n", ").fit()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/src/primaite/notebooks/training_example_ray_single_agent.ipynb b/src/primaite/notebooks/training_example_ray_single_agent.ipynb index ebd35d61..a89b29e4 100644 --- a/src/primaite/notebooks/training_example_ray_single_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_single_agent.ipynb @@ -1,18 +1,18 @@ { "cells": [ { - "cell_type": "code", - "execution_count": 1, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-12-01 14:53:13,421\tWARNING __init__.py:10 -- PG has/have been moved to `rllib_contrib` and will no longer be maintained by the RLlib team. You can still use it/them normally inside RLlib util Ray 2.8, but from Ray 2.9 on, all `rllib_contrib` algorithms will no longer be part of the core repo, and will therefore have to be installed separately with pinned dependencies for e.g. ray[rllib] and other packages! See https://github.com/ray-project/ray/tree/master/rllib_contrib#rllib-contrib for more information on the RLlib contrib effort.\n" - ] - } - ], + "source": [ + "## Train a Single agent system using RLLib\n", + "This notebook will demonstrate how to use PrimaiteRayEnv to train a basic PPO agent." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "from primaite.game.game import PrimaiteGame\n", "import yaml\n", @@ -22,86 +22,26 @@ "from ray.rllib.algorithms import ppo\n", "from ray import air, tune\n", "import ray\n", - "from ray.rllib.algorithms.ppo import PPOConfig" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ + "from ray.rllib.algorithms.ppo import PPOConfig\n", + "\n", + "# If you get an error saying this config file doesn't exist, you may need to run `primaite setup` in your command line\n", + "# to copy the files to your user data path.\n", "with open(example_config_path(), 'r') as f:\n", - " cfg = yaml.safe_load(f)\n" + " cfg = yaml.safe_load(f)\n", + "\n", + "ray.init(local_mode=True)\n" ] }, { - "cell_type": "code", - "execution_count": 3, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-12-01 14:53:16,276\tINFO worker.py:1673 -- Started a local Ray instance.\n" - ] - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9a775bf48837443dbdc6a3da9e9831f5", - "version_major": 2, - "version_minor": 0 - }, - "text/html": [ - "
\n", - "
\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Python version:3.10.12
Ray version:2.8.0
\n", - "\n", - "
\n", - "
\n" - ], - "text/plain": [ - "RayContext(dashboard_url='', python_version='3.10.12', ray_version='2.8.0', ray_commit='105355bd253d6538ed34d331f6a4bdf0e38ace3a', protocol_version=None)" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ - "ray.init(local_mode=True)" + "#### Create a Ray algorithm and pass it our config." ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -110,808 +50,23 @@ "config = (\n", " PPOConfig()\n", " .environment(env=PrimaiteRayEnv, env_config=env_config, disable_env_checking=True)\n", - " .rollouts(num_rollout_workers=0,)\n", + " .rollouts(num_rollout_workers=0)\n", " .training(train_batch_size=128)\n", ")\n" ] }, { - "cell_type": "code", - "execution_count": 5, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - ":job_id:01000000\n", - ":task_name:bundle_reservation_check_func\n", - ":actor_name:PPO\n", - "2023-12-01 14:53:17,868::ERROR::primaite.simulator.network.hardware.base::190::NIC 3e:e9:64:e8:cf:89/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:17,869::ERROR::primaite.simulator.network.hardware.base::190::NIC 74:17:08:49:f5:30/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:17,870::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:17,871::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:17,872::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:17,875: Added node 1c94cb0c-b62c-43eb-b5d3-4a5d1937f845 to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", - "2023-12-01 14:53:17,878: Added node 3197ef0c-0ce8-4b63-bde8-91e7f95d59ef to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", - "2023-12-01 14:53:17,884: Added node 835b8e76-0b1e-4112-9897-0808a87fd9de to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", - "2023-12-01 14:53:17,888::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,889: Added service 6a19bda9-7f0e-4f77-a5bc-b473d3418df0 to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", - "2023-12-01 14:53:17,890::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,891: Added service 6fc138ff-e698-4c4d-82ca-0aa990df6669 to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", - "2023-12-01 14:53:17,893: Added application 601f573a-5480-492d-8508-4b1ccc45100f to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", - "2023-12-01 14:53:17,895::ERROR::primaite.simulator.network.hardware.base::190::NIC fd:19:e4:d5:6e:c8/192.168.1.10 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:17,896::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,898: Added service 901a736f-8fd0-49e9-9369-ef1da8a6a5a4 to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", - "2023-12-01 14:53:17,900::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,903: Added service e240939c-b017-4e67-b161-8e5d96cbe061 to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", - "2023-12-01 14:53:17,905: Added application dada880f-ec1f-4ed3-a4b6-3f8c68a6c750 to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", - "2023-12-01 14:53:17,906::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,908: Added service d2201c7b-418c-49f7-bed0-c93f520f0352 to node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae\n", - "2023-12-01 14:53:17,909: Added node 7a31b3ca-b51d-4332-b9fb-ba5194ac5bae to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", - "2023-12-01 14:53:17,912::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,914: Added service 2c843f1e-643a-40d3-9477-8870926f49e8 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", - "2023-12-01 14:53:17,916::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,918: Added service b52910ee-66d7-4006-8044-fb27a95cc00f to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", - "2023-12-01 14:53:17,920: Added application dd11b7fb-a31a-418d-bfdb-fb862c0c38b2 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", - "2023-12-01 14:53:17,922::ERROR::primaite.simulator.network.hardware.base::190::NIC b9:01:34:d2:50:53/192.168.1.12 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:17,923::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,926: Added service a1d7a58a-df23-4ea0-934f-b4f397f252e5 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", - "2023-12-01 14:53:17,927::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,928: Added service 742f59a4-369e-4a31-a95e-19adb9115cb7 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", - "2023-12-01 14:53:17,930: Added application 5a93e02b-5485-46ad-9c61-4f32d4673ec3 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", - "2023-12-01 14:53:17,934: Added application 040a27ae-8c65-47fd-a60b-7c72a46e7806 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", - "2023-12-01 14:53:17,936::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,938: Added service f6241fbe-524e-4e94-8e94-232bcd8d0914 to node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036\n", - "2023-12-01 14:53:17,939: Added node 9b8bcb44-ec5a-42bc-a4a5-90d240f77036 to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", - "2023-12-01 14:53:17,941::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,942: Added service f69c460a-5385-4244-8582-508f806e52e4 to node 2f002450-027d-4791-832b-01327350d7e7\n", - "2023-12-01 14:53:17,943::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,944: Added service f36088c4-0817-47a2-bd4d-1162fee46b63 to node 2f002450-027d-4791-832b-01327350d7e7\n", - "2023-12-01 14:53:17,946: Added application 4de6ebfd-46ae-419f-b36e-3b2b079eff9d to node 2f002450-027d-4791-832b-01327350d7e7\n", - "2023-12-01 14:53:17,949::ERROR::primaite.simulator.network.hardware.base::190::NIC 70:fb:95:ae:8b:e9/192.168.1.14 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:17,951::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,953: Added service 5a01c753-1c0b-4f9e-8cf9-bdab8e1151e7 to node 2f002450-027d-4791-832b-01327350d7e7\n", - "2023-12-01 14:53:17,954::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,956: Added service 8f28720e-4374-4fe5-9b30-f2b3943691ff to node 2f002450-027d-4791-832b-01327350d7e7\n", - "2023-12-01 14:53:17,957: Added application 500d5dc5-1bca-4904-8b2a-8d5f3c4db978 to node 2f002450-027d-4791-832b-01327350d7e7\n", - "2023-12-01 14:53:17,958::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,960: Added service a5e5963e-c071-4715-9042-5e5887e26f3a to node 2f002450-027d-4791-832b-01327350d7e7\n", - "2023-12-01 14:53:17,962::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,967: Added service 82dd1118-3e3c-4f72-8e62-3217e72b0360 to node 2f002450-027d-4791-832b-01327350d7e7\n", - "2023-12-01 14:53:17,969: Added node 2f002450-027d-4791-832b-01327350d7e7 to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", - "2023-12-01 14:53:17,972::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,973: Added service d8d2c796-cae8-4d6b-acd1-76a30fb3dd87 to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", - "2023-12-01 14:53:17,974::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,975: Added service bd319940-2ad7-456b-88e9-a49b1c994edd to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", - "2023-12-01 14:53:17,977: Added application d30f9307-d8d5-41f0-b74d-94b878b3023a to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", - "2023-12-01 14:53:17,978::ERROR::primaite.simulator.network.hardware.base::190::NIC e8:c5:48:91:62:fe/192.168.1.16 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:17,980::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,983: Added service e926ebb1-6d91-4400-94f3-7dfab8e82eab to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", - "2023-12-01 14:53:17,985::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,987: Added service af73e5f5-c754-4936-9018-37ef69140ced to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", - "2023-12-01 14:53:17,988: Added application 13fd868b-e730-486f-ab83-e1bf2446e504 to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", - "2023-12-01 14:53:17,989::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:17,991: Added service ab453a9d-62dc-4437-b0dc-c9d587962a0b to node 858361fa-1b42-4456-b184-59fa44b0c89b\n", - "2023-12-01 14:53:17,992: Added node 858361fa-1b42-4456-b184-59fa44b0c89b to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", - "2023-12-01 14:53:17,995::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,003: Added service d9b44dbd-f153-4f3c-b03d-b6441a917834 to node 7c47bb4e-deea-4c23-910d-6ba524f73bbc\n", - "2023-12-01 14:53:18,005::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,006: Added service c3da251b-500a-40dd-8c25-e26a35b5b767 to node 7c47bb4e-deea-4c23-910d-6ba524f73bbc\n", - "2023-12-01 14:53:18,008: Added application 8f692912-fb57-40bb-ad56-d38970d34430 to node 7c47bb4e-deea-4c23-910d-6ba524f73bbc\n", - "2023-12-01 14:53:18,010::ERROR::primaite.simulator.network.hardware.base::190::NIC a3:59:d7:fe:28:08/192.168.1.110 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,011::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - ":job_id:01000000\n", - ":task_name:bundle_reservation_check_func\n", - ":actor_name:PPO\n", - "installing DNSServer on node domain_controller\n", - "installing DatabaseClient on node web_server\n", - "installing WebServer on node web_server\n", - "installing DatabaseService on node database_server\n", - "installing FTPClient on node database_server\n", - "installing FTPServer on node backup_server\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-12-01 14:53:18,013: Added service be9a1ad7-252b-47c7-ae20-e8202cb890ab to node 7c47bb4e-deea-4c23-910d-6ba524f73bbc\n", - "2023-12-01 14:53:18,020::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,022: Added service c5d5b514-cd30-4c7d-a4b7-b16fce71ccac to node 7c47bb4e-deea-4c23-910d-6ba524f73bbc\n", - "2023-12-01 14:53:18,024: Added application 918b8a5e-e339-4cb1-bb8b-ca2f3ec34372 to node 7c47bb4e-deea-4c23-910d-6ba524f73bbc\n", - "2023-12-01 14:53:18,026::ERROR::primaite.simulator.network.hardware.base::190::NIC c9:b5:db:9d:71:4d/192.168.10.110 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,027: Added node 7c47bb4e-deea-4c23-910d-6ba524f73bbc to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", - "2023-12-01 14:53:18,040::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,042: Added service 66ca1dd3-0997-427b-8663-402141122e75 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", - "2023-12-01 14:53:18,044::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,045: Added service f87b344d-8a8e-4d9d-a341-df5d3bb538ba to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", - "2023-12-01 14:53:18,047: Added application ab20f1e3-e567-4d02-9e16-febcd57c2630 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", - "2023-12-01 14:53:18,057::ERROR::primaite.simulator.network.hardware.base::190::NIC f5:2e:2d:55:76:d3/192.168.10.21 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,058::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,060: Added service 640815d4-878f-4dff-a607-08887b9045a7 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", - "2023-12-01 14:53:18,061::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,063: Added service 655735a9-6db2-41df-b462-f8c14ea53e35 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", - "2023-12-01 14:53:18,072: Added application 84fc60ba-b67e-4b72-86d1-d247fa7e31f7 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", - "2023-12-01 14:53:18,074::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,075: Added service 8f83391f-a59b-4bdb-8fe7-7fe7e19bf1e9 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", - "2023-12-01 14:53:18,077: Added application 75147ae5-cdce-4ac0-a884-fb9bd8f96387 to node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f\n", - "2023-12-01 14:53:18,078: Added node fee76ed0-ed6a-4ee2-bf2a-27de9bbfa17f to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", - "2023-12-01 14:53:18,084::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,086: Added service 02915c59-69e2-4248-9e46-16d627460448 to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", - "2023-12-01 14:53:18,087::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,088: Added service 3ec73168-2bad-41cd-b872-7747487410c5 to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", - "2023-12-01 14:53:18,089: Added application 2acc2c11-7eed-4382-b596-389a52b42915 to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", - "2023-12-01 14:53:18,090::ERROR::primaite.simulator.network.hardware.base::190::NIC 18:f5:a0:7f:c8:60/192.168.10.22 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,091::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,093: Added service 99ae3de9-6a18-45b7-b52e-929b2be8b69b to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", - "2023-12-01 14:53:18,093::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,095: Added service 80932931-e76e-4b98-8d05-3998f3a23a75 to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", - "2023-12-01 14:53:18,096: Added application 267775b8-36ad-4627-a5d3-dfd42ba5ecbf to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", - "2023-12-01 14:53:18,098::WARNING::primaite.simulator.core::116::Overwriting request type scan.\n", - "2023-12-01 14:53:18,100: Added service b5c7f3cb-d928-433d-8b07-a6a778337c27 to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", - "2023-12-01 14:53:18,102: Added application a3f18b82-33be-4659-96cb-2f069c3a2aa4 to node d8a6abb1-8929-490f-a997-5e3dcb452027\n", - "2023-12-01 14:53:18,103: Added node d8a6abb1-8929-490f-a997-5e3dcb452027 to Network 07a10762-942f-409d-b36f-ea2ab7ddb136\n", - "2023-12-01 14:53:18,148::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,151::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,153::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,154::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,155::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,155::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,156::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,157::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,159::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,163::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,165::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,167::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "installing DNSClient on node client_1\n", - "installing DNSClient on node client_2\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - ":actor_name:PPO\n", - "2023-12-01 14:53:18,581::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,582::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,583::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,585::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,586::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,588::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,590::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,591::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,593::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,602::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,604::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:18,604::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - ":actor_name:PPO\n", - "Episode: 1, Step: 1, Reward: 0.5\n", - "Episode: 1, Step: 2, Reward: 0.5\n", - "Episode: 1, Step: 3, Reward: 0.5\n", - "Episode: 1, Step: 4, Reward: 0.5\n", - "Episode: 1, Step: 5, Reward: 0.5\n", - "Episode: 1, Step: 6, Reward: 0.5\n", - "Episode: 1, Step: 7, Reward: 0.5\n", - "Episode: 1, Step: 8, Reward: 0.5\n", - "Episode: 1, Step: 9, Reward: 0.5\n", - "Episode: 1, Step: 10, Reward: 0.5\n", - "Episode: 1, Step: 11, Reward: 0.5\n", - "Episode: 1, Step: 12, Reward: 0.5\n", - "Episode: 1, Step: 13, Reward: 0.5\n", - "Episode: 1, Step: 14, Reward: 0.5\n", - "Episode: 1, Step: 15, Reward: 0.5\n", - "Episode: 1, Step: 16, Reward: 0.5\n", - "Episode: 1, Step: 17, Reward: 0.5\n", - "Episode: 1, Step: 18, Reward: 0.5\n", - "Episode: 1, Step: 19, Reward: 0.5\n", - "Episode: 1, Step: 20, Reward: 0.5\n", - "Episode: 1, Step: 21, Reward: 0.5\n", - "Episode: 1, Step: 22, Reward: 0.5\n", - "Episode: 1, Step: 23, Reward: 0.5\n", - "Episode: 1, Step: 24, Reward: 0.5\n", - "Episode: 1, Step: 25, Reward: 0.5\n", - "Episode: 1, Step: 26, Reward: 0.5\n", - "Episode: 1, Step: 27, Reward: 0.5\n", - "Episode: 1, Step: 28, Reward: 0.5\n", - "Episode: 1, Step: 29, Reward: 0.5\n", - "Episode: 1, Step: 30, Reward: 0.5\n", - "Episode: 1, Step: 31, Reward: 0.5\n", - "Episode: 1, Step: 32, Reward: 0.5\n", - "Episode: 1, Step: 33, Reward: 0.5\n", - "Episode: 1, Step: 34, Reward: 0.5\n", - "Episode: 1, Step: 35, Reward: 0.5\n", - "Episode: 1, Step: 36, Reward: 0.5\n", - "Episode: 1, Step: 37, Reward: 0.5\n", - "Episode: 1, Step: 38, Reward: 0.5\n", - "Episode: 1, Step: 39, Reward: 0.5\n", - "Episode: 1, Step: 40, Reward: 0.5\n", - "Episode: 1, Step: 41, Reward: 0.5\n", - "Episode: 1, Step: 42, Reward: 0.5\n", - "Episode: 1, Step: 43, Reward: 0.5\n", - "Episode: 1, Step: 44, Reward: 0.5\n", - "Episode: 1, Step: 45, Reward: 0.5\n", - "Episode: 1, Step: 46, Reward: 0.5\n", - "Episode: 1, Step: 47, Reward: 0.5\n", - "Episode: 1, Step: 48, Reward: 0.5\n", - "Episode: 1, Step: 49, Reward: 0.5\n", - "Episode: 1, Step: 50, Reward: 0.5\n", - "Episode: 1, Step: 51, Reward: 0.5\n", - "Episode: 1, Step: 52, Reward: 0.5\n", - "Episode: 1, Step: 53, Reward: 0.5\n", - "Episode: 1, Step: 54, Reward: 0.5\n", - "Episode: 1, Step: 55, Reward: 0.5\n", - "Episode: 1, Step: 56, Reward: 0.5\n", - "Episode: 1, Step: 57, Reward: 0.5\n", - "Episode: 1, Step: 58, Reward: 0.5\n", - "Episode: 1, Step: 59, Reward: 0.5\n", - "Episode: 1, Step: 60, Reward: 0.5\n", - "Episode: 1, Step: 61, Reward: 0.5\n", - "Episode: 1, Step: 62, Reward: 0.5\n", - "Episode: 1, Step: 63, Reward: 0.5\n", - "Episode: 1, Step: 64, Reward: 0.5\n", - "Episode: 1, Step: 65, Reward: 0.5\n", - "Episode: 1, Step: 66, Reward: 0.5\n", - "Episode: 1, Step: 67, Reward: 0.5\n", - "Episode: 1, Step: 68, Reward: 0.5\n", - "Episode: 1, Step: 69, Reward: 0.5\n", - "Episode: 1, Step: 70, Reward: 0.5\n", - "Episode: 1, Step: 71, Reward: 0.5\n", - "Episode: 1, Step: 72, Reward: 0.5\n", - "Episode: 1, Step: 73, Reward: 0.5\n", - "Episode: 1, Step: 74, Reward: 0.5\n", - "Episode: 1, Step: 75, Reward: 0.5\n", - "Episode: 1, Step: 76, Reward: 0.5\n", - "Episode: 1, Step: 77, Reward: 0.5\n", - "Episode: 1, Step: 78, Reward: 0.5\n", - "Episode: 1, Step: 79, Reward: 0.5\n", - "Episode: 1, Step: 80, Reward: 0.5\n", - "Episode: 1, Step: 81, Reward: 0.5\n", - "Episode: 1, Step: 82, Reward: 0.5\n", - "Episode: 1, Step: 83, Reward: 0.5\n", - "Episode: 1, Step: 84, Reward: 0.5\n", - "Episode: 1, Step: 85, Reward: 0.5\n", - "Episode: 1, Step: 86, Reward: 0.5\n", - "Episode: 1, Step: 87, Reward: 0.5\n", - "Episode: 1, Step: 88, Reward: 0.5\n", - "Episode: 1, Step: 89, Reward: 0.5\n", - "Episode: 1, Step: 90, Reward: 0.5\n", - "Episode: 1, Step: 91, Reward: 0.5\n", - "Episode: 1, Step: 92, Reward: 0.5\n", - "Episode: 1, Step: 93, Reward: 0.5\n", - "Episode: 1, Step: 94, Reward: 0.5\n", - "Episode: 1, Step: 95, Reward: 0.5\n", - "Episode: 1, Step: 96, Reward: 0.5\n", - "Episode: 1, Step: 97, Reward: 0.5\n", - "Episode: 1, Step: 98, Reward: 0.5\n", - "Episode: 1, Step: 99, Reward: 0.5\n", - "Episode: 1, Step: 100, Reward: 0.5\n", - "Episode: 1, Step: 101, Reward: 0.5\n", - "Episode: 1, Step: 102, Reward: 0.5\n", - "Episode: 1, Step: 103, Reward: 0.5\n", - "Episode: 1, Step: 104, Reward: 0.5\n", - "Episode: 1, Step: 105, Reward: 0.5\n", - "Episode: 1, Step: 106, Reward: 0.5\n", - "Episode: 1, Step: 107, Reward: 0.5\n", - "Episode: 1, Step: 108, Reward: 0.5\n", - "Episode: 1, Step: 109, Reward: 0.5\n", - "Episode: 1, Step: 110, Reward: 0.5\n", - "Episode: 1, Step: 111, Reward: 0.5\n", - "Episode: 1, Step: 112, Reward: 0.5\n", - "Episode: 1, Step: 113, Reward: 0.5\n", - "Episode: 1, Step: 114, Reward: 0.5\n", - "Episode: 1, Step: 115, Reward: 0.5\n", - "Episode: 1, Step: 116, Reward: 0.5\n", - "Episode: 1, Step: 117, Reward: 0.5\n", - "Episode: 1, Step: 118, Reward: 0.5\n", - "Episode: 1, Step: 119, Reward: 0.5\n", - "Episode: 1, Step: 120, Reward: 0.5\n", - "Episode: 1, Step: 121, Reward: 0.5\n", - "Episode: 1, Step: 122, Reward: 0.5\n", - "Episode: 1, Step: 123, Reward: 0.5\n", - "Episode: 1, Step: 124, Reward: 0.5\n", - "Episode: 1, Step: 125, Reward: 0.5\n", - "Episode: 1, Step: 126, Reward: 0.5\n", - "Episode: 1, Step: 127, Reward: 0.5\n", - "Episode: 1, Step: 128, Reward: 0.5\n", - "Episode: 1, Step: 129, Reward: 0.5\n", - "\n", - "Episode: 1, Step: 130, Reward: 0.5\n", - "Episode: 1, Step: 131, Reward: 0.5\n", - "Episode: 1, Step: 132, Reward: 0.5\n", - "Episode: 1, Step: 133, Reward: 0.5\n", - "Episode: 1, Step: 134, Reward: 0.5\n", - "Episode: 1, Step: 135, Reward: 0.5\n", - "Episode: 1, Step: 136, Reward: 0.5\n", - "Episode: 1, Step: 137, Reward: 0.5\n", - "Episode: 1, Step: 138, Reward: 0.5\n", - "Episode: 1, Step: 139, Reward: 0.5\n", - "Episode: 1, Step: 140, Reward: 0.5\n", - "Episode: 1, Step: 141, Reward: 0.5\n", - "Episode: 1, Step: 142, Reward: 0.5\n", - "Episode: 1, Step: 143, Reward: 0.5\n", - "Episode: 1, Step: 144, Reward: 0.5\n", - "Episode: 1, Step: 145, Reward: 0.5\n", - "Episode: 1, Step: 146, Reward: 0.5\n", - "Episode: 1, Step: 147, Reward: 0.5\n", - "Episode: 1, Step: 148, Reward: 0.5\n", - "Episode: 1, Step: 149, Reward: 0.5\n", - "Episode: 1, Step: 150, Reward: 0.5\n", - "Episode: 1, Step: 151, Reward: 0.5\n", - "Episode: 1, Step: 152, Reward: 0.5\n", - "Episode: 1, Step: 153, Reward: 0.5\n", - "Episode: 1, Step: 154, Reward: 0.5\n", - "Episode: 1, Step: 155, Reward: 0.5\n", - "Episode: 1, Step: 156, Reward: 0.5\n", - "Episode: 1, Step: 157, Reward: 0.5\n", - "Episode: 1, Step: 158, Reward: 0.5\n", - "Episode: 1, Step: 159, Reward: 0.5\n", - "Episode: 1, Step: 160, Reward: 0.5\n", - "Episode: 1, Step: 161, Reward: 0.5\n", - "Episode: 1, Step: 162, Reward: 0.5\n", - "Episode: 1, Step: 163, Reward: 0.5\n", - "Episode: 1, Step: 164, Reward: 0.5\n", - "Episode: 1, Step: 165, Reward: 0.5\n", - "Episode: 1, Step: 166, Reward: 0.5\n", - "Episode: 1, Step: 167, Reward: 0.5\n", - "Episode: 1, Step: 168, Reward: 0.5\n", - "Episode: 1, Step: 169, Reward: 0.5\n", - "Episode: 1, Step: 170, Reward: 0.5\n", - "Episode: 1, Step: 171, Reward: 0.5\n", - "Episode: 1, Step: 172, Reward: 0.5\n", - "Episode: 1, Step: 173, Reward: 0.5\n", - "Episode: 1, Step: 174, Reward: 0.5\n", - "Episode: 1, Step: 175, Reward: 0.5\n", - "Episode: 1, Step: 176, Reward: 0.5\n", - "Episode: 1, Step: 177, Reward: 0.5\n", - "Episode: 1, Step: 178, Reward: 0.5\n", - "Episode: 1, Step: 179, Reward: 0.5\n", - "Episode: 1, Step: 180, Reward: 0.5\n", - "Episode: 1, Step: 181, Reward: 0.5\n", - "Episode: 1, Step: 182, Reward: 0.5\n", - "Episode: 1, Step: 183, Reward: 0.5\n", - "Episode: 1, Step: 184, Reward: 0.5\n", - "Episode: 1, Step: 185, Reward: 0.5\n", - "Episode: 1, Step: 186, Reward: 0.5\n", - "Episode: 1, Step: 187, Reward: 0.5\n", - "Episode: 1, Step: 188, Reward: 0.5\n", - "Episode: 1, Step: 189, Reward: 0.5\n", - "Episode: 1, Step: 190, Reward: 0.5\n", - "Episode: 1, Step: 191, Reward: 0.5\n", - "Episode: 1, Step: 192, Reward: 0.5\n", - "Episode: 1, Step: 193, Reward: 0.5\n", - "Episode: 1, Step: 194, Reward: 0.5\n", - "Episode: 1, Step: 195, Reward: 0.5\n", - "Episode: 1, Step: 196, Reward: 0.5\n", - "Episode: 1, Step: 197, Reward: 0.5\n", - "Episode: 1, Step: 198, Reward: 0.5\n", - "Episode: 1, Step: 199, Reward: 0.5\n", - "Episode: 1, Step: 200, Reward: 0.5\n", - "Episode: 1, Step: 201, Reward: 0.5\n", - "Episode: 1, Step: 202, Reward: 0.5\n", - "Episode: 1, Step: 203, Reward: 0.5\n", - "Episode: 1, Step: 204, Reward: 0.5\n", - "Episode: 1, Step: 205, Reward: 0.5\n", - "Episode: 1, Step: 206, Reward: 0.5\n", - "Episode: 1, Step: 207, Reward: 0.5\n", - "Episode: 1, Step: 208, Reward: 0.5\n", - "Episode: 1, Step: 209, Reward: 0.5\n", - "Episode: 1, Step: 210, Reward: 0.5\n", - "Episode: 1, Step: 211, Reward: 0.5\n", - "Episode: 1, Step: 212, Reward: 0.5\n", - "Episode: 1, Step: 213, Reward: 0.5\n", - "Episode: 1, Step: 214, Reward: 0.5\n", - "Episode: 1, Step: 215, Reward: 0.5\n", - "Episode: 1, Step: 216, Reward: 0.5\n", - "Episode: 1, Step: 217, Reward: 0.5\n", - "Episode: 1, Step: 218, Reward: 0.5\n", - "Episode: 1, Step: 219, Reward: 0.5\n", - "Episode: 1, Step: 220, Reward: 0.5\n", - "Episode: 1, Step: 221, Reward: 0.5\n", - "Episode: 1, Step: 222, Reward: 0.5\n", - "Episode: 1, Step: 223, Reward: 0.5\n", - "Episode: 1, Step: 224, Reward: 0.5\n", - "Episode: 1, Step: 225, Reward: 0.5\n", - "Episode: 1, Step: 226, Reward: 0.5\n", - "Episode: 1, Step: 227, Reward: 0.5\n", - "Episode: 1, Step: 228, Reward: 0.5\n", - "Episode: 1, Step: 229, Reward: 0.5\n", - "Episode: 1, Step: 230, Reward: 0.5\n", - "Episode: 1, Step: 231, Reward: 0.5\n", - "Episode: 1, Step: 232, Reward: 0.5\n", - "Episode: 1, Step: 233, Reward: 0.5\n", - "Episode: 1, Step: 234, Reward: 0.5\n", - "Episode: 1, Step: 235, Reward: 0.5\n", - "Episode: 1, Step: 236, Reward: 0.5\n", - "Episode: 1, Step: 237, Reward: 0.5\n", - "Episode: 1, Step: 238, Reward: 0.5\n", - "Episode: 1, Step: 239, Reward: 0.5\n", - "Episode: 1, Step: 240, Reward: 0.5\n", - "Episode: 1, Step: 241, Reward: 0.5\n", - "Episode: 1, Step: 242, Reward: 0.5\n", - "Episode: 1, Step: 243, Reward: 0.5\n", - "Episode: 1, Step: 244, Reward: 0.5\n", - "Episode: 1, Step: 245, Reward: 0.5\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-12-01 14:53:21,247::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:21,248::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:21,249::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:21,251::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:21,252::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:21,254::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:21,256::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:21,259::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:21,262::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:21,292::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:21,293::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:21,294::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Episode: 1, Step: 246, Reward: 0.5\n", - "Episode: 1, Step: 247, Reward: 0.5\n", - "Episode: 1, Step: 248, Reward: 0.5\n", - "Episode: 1, Step: 249, Reward: 0.5\n", - "Episode: 1, Step: 250, Reward: 0.5\n", - "Episode: 1, Step: 251, Reward: 0.5\n", - "Episode: 1, Step: 252, Reward: 0.5\n", - "Episode: 1, Step: 253, Reward: 0.5\n", - "Episode: 1, Step: 254, Reward: 0.5\n", - "Episode: 1, Step: 255, Reward: 0.5\n", - "Episode: 1, Step: 256, Reward: 0.5\n", - "Episode: 2, Step: 1, Reward: 0.5\n", - "Episode: 2, Step: 2, Reward: 0.5\n", - "Episode: 2, Step: 3, Reward: 0.5\n", - "Episode: 2, Step: 4, Reward: 0.5\n", - "Episode: 2, Step: 5, Reward: 0.5\n", - "Episode: 2, Step: 6, Reward: 0.5\n", - "Episode: 2, Step: 7, Reward: 0.5\n", - "Episode: 2, Step: 8, Reward: 0.5\n", - "Episode: 2, Step: 9, Reward: 0.5\n", - "Episode: 2, Step: 10, Reward: 0.5\n", - "Episode: 2, Step: 11, Reward: 0.5\n", - "Episode: 2, Step: 12, Reward: 0.5\n", - "Episode: 2, Step: 13, Reward: 0.5\n", - "Episode: 2, Step: 14, Reward: 0.5\n", - "Episode: 2, Step: 15, Reward: 0.5\n", - "Episode: 2, Step: 16, Reward: 0.5\n", - "Episode: 2, Step: 17, Reward: 0.5\n", - "Episode: 2, Step: 18, Reward: 0.5\n", - "Episode: 2, Step: 19, Reward: 0.5\n", - "Episode: 2, Step: 20, Reward: 0.5\n", - "Episode: 2, Step: 21, Reward: 0.5\n", - "Episode: 2, Step: 22, Reward: 0.5\n", - "Episode: 2, Step: 23, Reward: 0.5\n", - "Episode: 2, Step: 24, Reward: 0.5\n", - "Episode: 2, Step: 25, Reward: 0.5\n", - "Episode: 2, Step: 26, Reward: 0.5\n", - "Episode: 2, Step: 27, Reward: 0.5\n", - "Episode: 2, Step: 28, Reward: 0.5\n", - "Episode: 2, Step: 29, Reward: 0.5\n", - "Episode: 2, Step: 30, Reward: 0.5\n", - "Episode: 2, Step: 31, Reward: 0.5\n", - "Episode: 2, Step: 32, Reward: 0.5\n", - "Episode: 2, Step: 33, Reward: 0.5\n", - "Episode: 2, Step: 34, Reward: 0.5\n", - "Episode: 2, Step: 35, Reward: 0.5\n", - "Episode: 2, Step: 36, Reward: 0.5\n", - "Episode: 2, Step: 37, Reward: 0.5\n", - "Episode: 2, Step: 38, Reward: 0.5\n", - "Episode: 2, Step: 39, Reward: 0.5\n", - "Episode: 2, Step: 40, Reward: 0.5\n", - "Episode: 2, Step: 41, Reward: 0.5\n", - "Episode: 2, Step: 42, Reward: 0.5\n", - "Episode: 2, Step: 43, Reward: 0.5\n", - "Episode: 2, Step: 44, Reward: 0.5\n", - "Episode: 2, Step: 45, Reward: 0.5\n", - "Episode: 2, Step: 46, Reward: 0.5\n", - "Episode: 2, Step: 47, Reward: 0.5\n", - "Episode: 2, Step: 48, Reward: 0.5\n", - "Episode: 2, Step: 49, Reward: 0.5\n", - "Episode: 2, Step: 50, Reward: 0.5\n", - "Episode: 2, Step: 51, Reward: 0.5\n", - "Episode: 2, Step: 52, Reward: 0.5\n", - "Episode: 2, Step: 53, Reward: 0.5\n", - "Episode: 2, Step: 54, Reward: 0.5\n", - "Episode: 2, Step: 55, Reward: 0.5\n", - "Episode: 2, Step: 56, Reward: 0.5\n", - "Episode: 2, Step: 57, Reward: 0.5\n", - "Episode: 2, Step: 58, Reward: 0.5\n", - "Episode: 2, Step: 59, Reward: 0.5\n", - "Episode: 2, Step: 60, Reward: 0.5\n", - "Episode: 2, Step: 61, Reward: 0.5\n", - "Episode: 2, Step: 62, Reward: 0.5\n", - "Episode: 2, Step: 63, Reward: 0.5\n", - "Episode: 2, Step: 64, Reward: 0.5\n", - "Episode: 2, Step: 65, Reward: 0.5\n", - "Episode: 2, Step: 66, Reward: 0.5\n", - "Episode: 2, Step: 67, Reward: 0.5\n", - "Episode: 2, Step: 68, Reward: 0.5\n", - "Episode: 2, Step: 69, Reward: 0.5\n", - "Episode: 2, Step: 70, Reward: 0.5\n", - "Episode: 2, Step: 71, Reward: 0.5\n", - "Episode: 2, Step: 72, Reward: 0.5\n", - "Episode: 2, Step: 73, Reward: 0.5\n", - "Episode: 2, Step: 74, Reward: 0.5\n", - "Episode: 2, Step: 75, Reward: 0.5\n", - "Episode: 2, Step: 76, Reward: 0.5\n", - "Episode: 2, Step: 77, Reward: 0.5\n", - "Episode: 2, Step: 78, Reward: 0.5\n", - "Episode: 2, Step: 79, Reward: 0.5\n", - "Episode: 2, Step: 80, Reward: 0.5\n", - "Episode: 2, Step: 81, Reward: 0.5\n", - "Episode: 2, Step: 82, Reward: 0.5\n", - "Episode: 2, Step: 83, Reward: 0.5\n", - "Episode: 2, Step: 84, Reward: 0.5\n", - "Episode: 2, Step: 85, Reward: 0.5\n", - "Episode: 2, Step: 86, Reward: 0.5\n", - "Episode: 2, Step: 87, Reward: 0.5\n", - "Episode: 2, Step: 88, Reward: 0.5\n", - "Episode: 2, Step: 89, Reward: 0.5\n", - "Episode: 2, Step: 90, Reward: 0.5\n", - "Episode: 2, Step: 91, Reward: 0.5\n", - "Episode: 2, Step: 92, Reward: 0.5\n", - "Episode: 2, Step: 93, Reward: 0.5\n", - "Episode: 2, Step: 94, Reward: 0.5\n", - "Episode: 2, Step: 95, Reward: 0.5\n", - "Episode: 2, Step: 96, Reward: 0.5\n", - "Episode: 2, Step: 97, Reward: 0.5\n", - "Episode: 2, Step: 98, Reward: 0.5\n", - "Episode: 2, Step: 99, Reward: 0.5\n", - "Episode: 2, Step: 100, Reward: 0.5\n", - "Episode: 2, Step: 101, Reward: 0.5\n", - "Episode: 2, Step: 102, Reward: 0.5\n", - "Episode: 2, Step: 103, Reward: 0.5\n", - "Episode: 2, Step: 104, Reward: 0.5\n", - "Episode: 2, Step: 105, Reward: 0.5\n", - "Episode: 2, Step: 106, Reward: 0.5\n", - "Episode: 2, Step: 107, Reward: 0.5\n", - "Episode: 2, Step: 108, Reward: 0.5\n", - "Episode: 2, Step: 109, Reward: 0.5\n", - "Episode: 2, Step: 110, Reward: 0.5\n", - "Episode: 2, Step: 111, Reward: 0.5\n", - "Episode: 2, Step: 112, Reward: 0.5\n", - "Episode: 2, Step: 113, Reward: 0.5\n", - "Episode: 2, Step: 114, Reward: 0.5\n", - "Episode: 2, Step: 115, Reward: 0.5\n", - "Episode: 2, Step: 116, Reward: 0.5\n", - "Episode: 2, Step: 117, Reward: 0.5\n", - "Episode: 2, Step: 118, Reward: 0.5\n", - "Episode: 2, Step: 119, Reward: 0.5\n", - "Episode: 2, Step: 120, Reward: 0.5\n", - "Episode: 2, Step: 121, Reward: 0.5\n", - "Episode: 2, Step: 122, Reward: 0.5\n", - "Episode: 2, Step: 123, Reward: 0.5\n", - "Episode: 2, Step: 124, Reward: 0.5\n", - "Episode: 2, Step: 125, Reward: 0.5\n", - "Episode: 2, Step: 126, Reward: 0.5\n", - "Episode: 2, Step: 127, Reward: 0.5\n", - "Episode: 2, Step: 128, Reward: 0.5\n", - "Episode: 2, Step: 129, Reward: 0.5\n", - "Episode: 2, Step: 130, Reward: 0.5\n", - "Episode: 2, Step: 131, Reward: 0.5\n", - "Episode: 2, Step: 132, Reward: 0.5\n", - "Episode: 2, Step: 133, Reward: 0.5\n", - "Episode: 2, Step: 134, Reward: 0.5\n", - "Episode: 2, Step: 135, Reward: 0.5\n", - "Episode: 2, Step: 136, Reward: 0.5\n", - "Episode: 2, Step: 137, Reward: 0.5\n", - "Episode: 2, Step: 138, Reward: 0.5\n", - "Episode: 2, Step: 139, Reward: 0.5\n", - "Episode: 2, Step: 140, Reward: 0.5\n", - "Episode: 2, Step: 141, Reward: 0.5\n", - "Episode: 2, Step: 142, Reward: 0.5\n", - "Episode: 2, Step: 143, Reward: 0.5\n", - "Episode: 2, Step: 144, Reward: 0.5\n", - "Episode: 2, Step: 145, Reward: 0.5\n", - "Episode: 2, Step: 146, Reward: 0.5\n", - "Episode: 2, Step: 147, Reward: 0.5\n", - "Episode: 2, Step: 148, Reward: 0.5\n", - "Episode: 2, Step: 149, Reward: 0.5\n", - "Episode: 2, Step: 150, Reward: 0.5\n", - "Episode: 2, Step: 151, Reward: 0.5\n", - "Episode: 2, Step: 152, Reward: 0.5\n", - "Episode: 2, Step: 153, Reward: 0.5\n", - "Episode: 2, Step: 154, Reward: 0.5\n", - "Episode: 2, Step: 155, Reward: 0.5\n", - "Episode: 2, Step: 156, Reward: 0.5\n", - "Episode: 2, Step: 157, Reward: 0.5\n", - "Episode: 2, Step: 158, Reward: 0.5\n", - "Episode: 2, Step: 159, Reward: 0.5\n", - "Episode: 2, Step: 160, Reward: 0.5\n", - "Episode: 2, Step: 161, Reward: 0.5\n", - "Episode: 2, Step: 162, Reward: 0.5\n", - "Episode: 2, Step: 163, Reward: 0.5\n", - "Episode: 2, Step: 164, Reward: 0.5\n", - "Episode: 2, Step: 165, Reward: 0.5\n", - "Episode: 2, Step: 166, Reward: 0.5\n", - "Episode: 2, Step: 167, Reward: 0.5\n", - "Episode: 2, Step: 168, Reward: 0.5\n", - "Episode: 2, Step: 169, Reward: 0.5\n", - "Episode: 2, Step: 170, Reward: 0.5\n", - "Episode: 2, Step: 171, Reward: 0.5\n", - "Episode: 2, Step: 172, Reward: 0.5\n", - "Episode: 2, Step: 173, Reward: 0.5\n", - "Episode: 2, Step: 174, Reward: 0.5\n", - "Episode: 2, Step: 175, Reward: 0.5\n", - "Episode: 2, Step: 176, Reward: 0.5\n", - "Episode: 2, Step: 177, Reward: 0.5\n", - "Episode: 2, Step: 178, Reward: 0.5\n", - "Episode: 2, Step: 179, Reward: 0.5\n", - "Episode: 2, Step: 180, Reward: 0.5\n", - "Episode: 2, Step: 181, Reward: 0.5\n", - "Episode: 2, Step: 182, Reward: 0.5\n", - "Episode: 2, Step: 183, Reward: 0.5\n", - "Episode: 2, Step: 184, Reward: 0.5\n", - "Episode: 2, Step: 185, Reward: 0.5\n", - "Episode: 2, Step: 186, Reward: 0.5\n", - "Episode: 2, Step: 187, Reward: 0.5\n", - "Episode: 2, Step: 188, Reward: 0.5\n", - "Episode: 2, Step: 189, Reward: 0.5\n", - "Episode: 2, Step: 190, Reward: 0.5\n", - "Episode: 2, Step: 191, Reward: 0.5\n", - "Episode: 2, Step: 192, Reward: 0.5\n", - "Episode: 2, Step: 193, Reward: 0.5\n", - "Episode: 2, Step: 194, Reward: 0.5\n", - "Episode: 2, Step: 195, Reward: 0.5\n", - "Episode: 2, Step: 196, Reward: 0.5\n", - "Episode: 2, Step: 197, Reward: 0.5\n", - "Episode: 2, Step: 198, Reward: 0.5\n", - "Episode: 2, Step: 199, Reward: 0.5\n", - "Episode: 2, Step: 200, Reward: 0.5\n", - "Episode: 2, Step: 201, Reward: 0.5\n", - "Episode: 2, Step: 202, Reward: 0.5\n", - "Episode: 2, Step: 203, Reward: 0.5\n", - "Episode: 2, Step: 204, Reward: 0.5\n", - "Episode: 2, Step: 205, Reward: 0.5\n", - "Episode: 2, Step: 206, Reward: 0.5\n", - "Episode: 2, Step: 207, Reward: 0.5\n", - "Episode: 2, Step: 208, Reward: 0.5\n", - "Episode: 2, Step: 209, Reward: 0.5\n", - "Episode: 2, Step: 210, Reward: 0.5\n", - "Episode: 2, Step: 211, Reward: 0.5\n", - "Episode: 2, Step: 212, Reward: 0.5\n", - "Episode: 2, Step: 213, Reward: 0.5\n", - "Episode: 2, Step: 214, Reward: 0.5\n", - "Episode: 2, Step: 215, Reward: 0.5\n", - "Episode: 2, Step: 216, Reward: 0.5\n", - "Episode: 2, Step: 217, Reward: 0.5\n", - "Episode: 2, Step: 218, Reward: 0.5\n", - "Episode: 2, Step: 219, Reward: 0.5\n", - "Episode: 2, Step: 220, Reward: 0.5\n", - "Episode: 2, Step: 221, Reward: 0.5\n", - "Episode: 2, Step: 222, Reward: 0.5\n", - "Episode: 2, Step: 223, Reward: 0.5\n", - "Episode: 2, Step: 224, Reward: 0.5\n", - "Episode: 2, Step: 225, Reward: 0.5\n", - "Episode: 2, Step: 226, Reward: 0.5\n", - "Episode: 2, Step: 227, Reward: 0.5\n", - "Episode: 2, Step: 228, Reward: 0.5\n", - "Episode: 2, Step: 229, Reward: 0.5\n", - "Episode: 2, Step: 230, Reward: 0.5\n", - "Episode: 2, Step: 231, Reward: 0.5\n", - "Episode: 2, Step: 232, Reward: 0.5\n", - "Episode: 2, Step: 233, Reward: 0.5\n", - "Episode: 2, Step: 234, Reward: 0.5\n", - "Episode: 2, Step: 235, Reward: 0.5\n", - "Episode: 2, Step: 236, Reward: 0.5\n", - "Episode: 2, Step: 237, Reward: 0.5\n", - "Episode: 2, Step: 238, Reward: 0.5\n", - "Episode: 2, Step: 239, Reward: 0.5\n", - "Episode: 2, Step: 240, Reward: 0.5\n", - "Episode: 2, Step: 241, Reward: 0.5\n", - "Episode: 2, Step: 242, Reward: 0.5\n", - "Episode: 2, Step: 243, Reward: 0.5\n", - "Episode: 2, Step: 244, Reward: 0.5\n", - "Episode: 2, Step: 245, Reward: 0.5\n", - "Episode: 2, Step: 246, Reward: 0.5\n", - "Episode: 2, Step: 247, Reward: 0.5\n", - "Episode: 2, Step: 248, Reward: 0.5\n", - "Episode: 2, Step: 249, Reward: 0.5\n", - "Episode: 2, Step: 250, Reward: 0.5\n", - "Episode: 2, Step: 251, Reward: 0.5\n", - "Episode: 2, Step: 252, Reward: 0.5\n", - "Episode: 2, Step: 253, Reward: 0.5\n", - "Episode: 2, Step: 254, Reward: 0.5\n", - "Episode: 2, Step: 255, Reward: 0.5\n", - "Episode: 2, Step: 256, Reward: 0.5\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-12-01 14:53:24,371::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:24,373::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:24,375::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:24,375::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:24,376::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:24,377::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:24,379::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:24,380::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:24,381::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:24,402::ERROR::primaite.simulator.network.hardware.base::190::NIC 36:ad:98:49:2d:a7/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:24,404::ERROR::primaite.simulator.network.hardware.base::190::NIC c4:0e:cf:36:55:de/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-12-01 14:53:24,406::ERROR::primaite.simulator.network.hardware.base::190::NIC ec:6e:b6:5c:8a:e7/127.0.0.1 cannot be enabled as it is not connected to a Link\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Episode: 3, Step: 1, Reward: 0.5\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-12-01 14:53:24,878\tINFO storage.py:563 -- Checkpoint successfully created at: Checkpoint(filesystem=local, path=/home/cade/ray_results/PPO_2023-12-01_14-53-17/PPO_PrimaiteRayEnv_5cbc4_00000_0_2023-12-01_14-53-17/checkpoint_000000)\n", - "2023-12-01 14:53:25,098\tINFO tune.py:1047 -- Total run time: 7.37 seconds (7.31 seconds for the tuning loop).\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n" - ] - }, - { - "data": { - "text/plain": [ - "ResultGrid<[\n", - " Result(\n", - " metrics={'custom_metrics': {}, 'episode_media': {}, 'info': {'learner': {'__all__': {'num_agent_steps_trained': 128.0, 'num_env_steps_trained': 128.0, 'total_loss': 9.403312460581462}, 'default_policy': {'total_loss': 9.403312460581462, 'policy_loss': -0.06894568807135025, 'vf_loss': 9.469796816507975, 'vf_loss_unclipped': 416.65203653971355, 'vf_explained_var': 0.0007335106531778971, 'entropy': 3.864323592185974, 'mean_kl_loss': 0.012305201259247648, 'default_optimizer_lr': 4.999999999999999e-05, 'curr_lr': 5e-05, 'curr_entropy_coeff': 0.0, 'curr_kl_coeff': 0.20000000298023224}}, 'num_env_steps_sampled': 512, 'num_env_steps_trained': 0, 'num_agent_steps_sampled': 512, 'num_agent_steps_trained': 0}, 'sampler_results': {'episode_reward_max': 128.0, 'episode_reward_min': 128.0, 'episode_reward_mean': 128.0, 'episode_len_mean': 256.0, 'episode_media': {}, 'episodes_this_iter': 1, 'policy_reward_min': {}, 'policy_reward_max': {}, 'policy_reward_mean': {}, 'custom_metrics': {}, 'hist_stats': {'episode_reward': [128.0, 128.0], 'episode_lengths': [256, 256]}, 'sampler_perf': {'mean_raw_obs_processing_ms': 0.8607522543689299, 'mean_inference_ms': 2.1271821797748984, 'mean_action_processing_ms': 0.15329866429338604, 'mean_env_wait_ms': 6.184263571370873, 'mean_env_render_ms': 0.0}, 'num_faulty_episodes': 0, 'connector_metrics': {'ObsPreprocessorConnector_ms': 0.010561943054199219, 'StateBufferConnector_ms': 0.004971027374267578, 'ViewRequirementAgentConnector_ms': 0.29495954513549805}}, 'episode_reward_max': 128.0, 'episode_reward_min': 128.0, 'episode_reward_mean': 128.0, 'episode_len_mean': 256.0, 'episodes_this_iter': 1, 'policy_reward_min': {}, 'policy_reward_max': {}, 'policy_reward_mean': {}, 'hist_stats': {'episode_reward': [128.0, 128.0], 'episode_lengths': [256, 256]}, 'sampler_perf': {'mean_raw_obs_processing_ms': 0.8607522543689299, 'mean_inference_ms': 2.1271821797748984, 'mean_action_processing_ms': 0.15329866429338604, 'mean_env_wait_ms': 6.184263571370873, 'mean_env_render_ms': 0.0}, 'num_faulty_episodes': 0, 'connector_metrics': {'ObsPreprocessorConnector_ms': 0.010561943054199219, 'StateBufferConnector_ms': 0.004971027374267578, 'ViewRequirementAgentConnector_ms': 0.29495954513549805}, 'num_healthy_workers': 0, 'num_in_flight_async_reqs': 0, 'num_remote_worker_restarts': 0, 'num_agent_steps_sampled': 512, 'num_agent_steps_trained': 0, 'num_env_steps_sampled': 512, 'num_env_steps_trained': 0, 'num_env_steps_sampled_this_iter': 128, 'num_env_steps_trained_this_iter': 0, 'num_env_steps_sampled_throughput_per_sec': 85.63165451744611, 'num_env_steps_trained_throughput_per_sec': 0.0, 'num_steps_trained_this_iter': 0, 'agent_timesteps_total': 512, 'timers': {'training_iteration_time_ms': 1530.574, 'sample_time_ms': 1196.582, 'synch_weights_time_ms': 1.912}, 'counters': {'num_env_steps_sampled': 512, 'num_env_steps_trained': 0, 'num_agent_steps_sampled': 512, 'num_agent_steps_trained': 0}, 'perf': {'cpu_util_percent': 55.25, 'ram_util_percent': 58.8}},\n", - " path='/home/cade/ray_results/PPO_2023-12-01_14-53-17/PPO_PrimaiteRayEnv_5cbc4_00000_0_2023-12-01_14-53-17',\n", - " filesystem='local',\n", - " checkpoint=Checkpoint(filesystem=local, path=/home/cade/ray_results/PPO_2023-12-01_14-53-17/PPO_PrimaiteRayEnv_5cbc4_00000_0_2023-12-01_14-53-17/checkpoint_000000)\n", - " )\n", - "]>" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], + "source": [ + "#### Set training parameters and start the training" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "tune.Tuner(\n", " \"PPO\",\n", diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 87cf4f2d..4f4bb829 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -37,11 +37,14 @@ class PrimaiteGymEnv(gymnasium.Env): terminated = False truncated = self.game.calculate_truncated() info = {} - print(f"Episode: {self.game.episode_counter}, Step: {self.game.step_counter}, Reward: {reward}") return next_obs, reward, terminated, truncated, info def reset(self, seed: Optional[int] = None) -> Tuple[ObsType, Dict[str, Any]]: """Reset the environment.""" + print( + f"Resetting environment, episode {self.game.episode_counter}, " + "avg. reward: {self.game.rl_agents[0].reward_function.total_reward}" + ) self.game.reset() state = self.game.get_sim_state() self.game.update_agents(state) diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py index 3919902a..3c8b40bd 100644 --- a/src/primaite/session/session.py +++ b/src/primaite/session/session.py @@ -62,6 +62,7 @@ class PrimaiteSession: def start_session(self) -> None: """Commence the training/eval session.""" + print("Staring Primaite Session") self.mode = SessionMode.TRAIN n_learn_episodes = self.training_options.n_learn_episodes n_eval_episodes = self.training_options.n_eval_episodes diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 18a470cd..08779d96 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -113,7 +113,7 @@ class RequestManager(BaseModel): """ if name in self.request_types: msg = f"Overwriting request type {name}." - _LOGGER.warn(msg) + _LOGGER.debug(msg) self.request_types[name] = request_type diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 97b62f95..e1780448 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -220,7 +220,7 @@ class Network(SimComponent): self._node_id_map[len(self.nodes)] = node node.parent = self self._nx_graph.add_node(node.hostname) - _LOGGER.info(f"Added node {node.uuid} to Network {self.uuid}") + _LOGGER.debug(f"Added node {node.uuid} to Network {self.uuid}") self._node_request_manager.add_request(name=node.uuid, request_type=RequestType(func=node._request_manager)) def get_node_by_hostname(self, hostname: str) -> Optional[Node]: diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 04c76c6b..a310a3f5 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -181,13 +181,13 @@ class NIC(SimComponent): if self.enabled: return if not self._connected_node: - _LOGGER.error(f"NIC {self} cannot be enabled as it is not connected to a Node") + _LOGGER.debug(f"NIC {self} cannot be enabled as it is not connected to a Node") return if self._connected_node.operating_state != NodeOperatingState.ON: self._connected_node.sys_log.error(f"NIC {self} cannot be enabled as the endpoint is not turned on") return if not self._connected_link: - _LOGGER.error(f"NIC {self} cannot be enabled as it is not connected to a Link") + _LOGGER.debug(f"NIC {self} cannot be enabled as it is not connected to a Link") return self.enabled = True From 3e3fd89618bd12a9d7ce2e0216d2e930bb4205c9 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 1 Dec 2023 15:41:10 +0000 Subject: [PATCH 443/980] Minor string fix --- src/primaite/session/environment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 4f4bb829..c2f19f36 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -43,7 +43,7 @@ class PrimaiteGymEnv(gymnasium.Env): """Reset the environment.""" print( f"Resetting environment, episode {self.game.episode_counter}, " - "avg. reward: {self.game.rl_agents[0].reward_function.total_reward}" + f"avg. reward: {self.game.rl_agents[0].reward_function.total_reward}" ) self.game.reset() state = self.game.get_sim_state() From 9a8350fd8f7b81525144ac6d18280a08b9a91cae Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 15:49:20 +0000 Subject: [PATCH 444/980] #2084: artifact the report --- .azure/azure-ci-build-pipeline.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 4c5afed8..61b4cfc3 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -98,7 +98,7 @@ stages: displayName: 'Perform PrimAITE Setup' - script: | - pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term + pytest -v tests/unit_tests --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term displayName: 'Run tests and code coverage' - task: PublishTestResults@2 @@ -108,12 +108,15 @@ stages: testResultsFiles: 'junit/**.xml' testRunTitle: 'Publish test results' + - publish: $(System.DefaultWorkingDirectory)/**/htmlcov/ + artifact: coverage_report + - task: PublishCodeCoverageResults@1 displayName: 'Publish coverage report' inputs: codeCoverageTool: Cobertura summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml' pathToSources: '$(System.DefaultWorkingDirectory)/src' - reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov' + reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov/' additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/**/htmlcov/*.*' failIfCoverageEmpty: true From 8a4978cf9625f82ee2cacd4843a8fc6df2c56a08 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 15:59:34 +0000 Subject: [PATCH 445/980] #2084: remove 80% requirement - causes tests to fail --- .azure/azure-ci-build-pipeline.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 61b4cfc3..2dffe61a 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -108,7 +108,7 @@ stages: testResultsFiles: 'junit/**.xml' testRunTitle: 'Publish test results' - - publish: $(System.DefaultWorkingDirectory)/**/htmlcov/ + - publish: $(System.DefaultWorkingDirectory)/htmlcov/ artifact: coverage_report - task: PublishCodeCoverageResults@1 @@ -117,6 +117,6 @@ stages: codeCoverageTool: Cobertura summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml' pathToSources: '$(System.DefaultWorkingDirectory)/src' - reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov/' - additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/**/htmlcov/*.*' + # reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov/' + # additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/**/htmlcov/*.*' failIfCoverageEmpty: true From 88f74d9eec9a6ea703eaaea88c2cb742d620a86e Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 16:08:02 +0000 Subject: [PATCH 446/980] #2084: remove debugs and comment out the uploading of report --- .azure/azure-ci-build-pipeline.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 2dffe61a..a59c5593 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -98,7 +98,7 @@ stages: displayName: 'Perform PrimAITE Setup' - script: | - pytest -v tests/unit_tests --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term + pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term displayName: 'Run tests and code coverage' - task: PublishTestResults@2 @@ -115,7 +115,7 @@ stages: displayName: 'Publish coverage report' inputs: codeCoverageTool: Cobertura - summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml' + summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml' pathToSources: '$(System.DefaultWorkingDirectory)/src' # reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov/' # additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/**/htmlcov/*.*' From af8401440d7d7dfc2da6dc39f3b5deb5d5c46030 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Dec 2023 16:29:05 +0000 Subject: [PATCH 447/980] #2084: using v2 publish codecov --- .azure/azure-ci-build-pipeline.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index a59c5593..11d53d73 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -111,12 +111,9 @@ stages: - publish: $(System.DefaultWorkingDirectory)/htmlcov/ artifact: coverage_report - - task: PublishCodeCoverageResults@1 + - task: PublishCodeCoverageResults@2 displayName: 'Publish coverage report' inputs: codeCoverageTool: Cobertura summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml' - pathToSources: '$(System.DefaultWorkingDirectory)/src' - # reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov/' - # additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/**/htmlcov/*.*' failIfCoverageEmpty: true From cc04efb31db63f57869c0ce833f30134639f930a Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 1 Dec 2023 16:37:58 +0000 Subject: [PATCH 448/980] #2085 - Added step metadata json file dumps to the environments. Fixed serialization issues in the Switch and ACLRule classes. --- docs/source/primaite_session.rst | 4 +- src/primaite/session/environment.py | 47 ++++++++++++++----- .../network/hardware/nodes/router.py | 4 +- .../network/hardware/nodes/switch.py | 2 +- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/docs/source/primaite_session.rst b/docs/source/primaite_session.rst index f3ef0399..706397b6 100644 --- a/docs/source/primaite_session.rst +++ b/docs/source/primaite_session.rst @@ -31,4 +31,6 @@ Outputs Running a session creates a session output directory in your user data folder. The filepath looks like this: ``~/primaite/3.0.0/sessions/YYYY-MM-DD/HH-MM-SS/``. This folder contains the simulation sys logs generated by each node, -the saved agent checkpoints, and final model. +the saved agent checkpoints, and final model. The folder also contains a .json file for each episode step that +contains the action, reward, and simulation state. These can be found in +``~/primaite/3.0.0/sessions/YYYY-MM-DD/HH-MM-SS/simulation_output/episode_/step_metadata/step_.json`` diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 3c164878..9c86aee0 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -5,9 +5,9 @@ import gymnasium from gymnasium.core import ActType, ObsType from ray.rllib.env.multi_agent_env import MultiAgentEnv -from primaite import PRIMAITE_PATHS from primaite.game.agent.interface import ProxyAgent from primaite.game.game import PrimaiteGame +from primaite.simulator import SIM_OUTPUT class PrimaiteGymEnv(gymnasium.Env): @@ -33,17 +33,6 @@ class PrimaiteGymEnv(gymnasium.Env): self.game.advance_timestep() state = self.game.get_sim_state() - # Create state suitable for dumping to file. - # dump_state = {self.game.episode_counter: {self.game.step_counter: state}} - - # Dump to file - # if os.path.isfile(PRIMAITE_PATHS.episode_steps_log_file_path): - with open(PRIMAITE_PATHS.episode_log_file_path, "a", encoding="utf-8") as f: - # f.write(str(dump_state)) - # f.write("\n=================\n") - # f.flush() - json.dump(state, f) - self.game.update_agents(state) next_obs = self._get_obs() @@ -51,9 +40,26 @@ class PrimaiteGymEnv(gymnasium.Env): terminated = False truncated = self.game.calculate_truncated() info = {} + self._write_step_metadata_json(action, state, reward) print(f"Episode: {self.game.episode_counter}, Step: {self.game.step_counter}, Reward: {reward}") return next_obs, reward, terminated, truncated, info + def _write_step_metadata_json(self, action: int, state: Dict, reward: int): + output_dir = SIM_OUTPUT.path / f"episode_{self.game.episode_counter}" / "step_metadata" + + output_dir.mkdir(parents=True, exist_ok=True) + path = output_dir / f"step_{self.game.step_counter}.json" + + data = { + "episode": self.game.episode_counter, + "step": self.game.step_counter, + "action": int(action), + "reward": int(reward), + "state": state, + } + with open(path, "w") as file: + json.dump(data, file) + def reset(self, seed: Optional[int] = None) -> Tuple[ObsType, Dict[str, Any]]: """Reset the environment.""" self.game.reset() @@ -173,8 +179,25 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): infos = {} terminateds["__all__"] = len(self.terminateds) == len(self.agents) truncateds["__all__"] = self.game.calculate_truncated() + self._write_step_metadata_json(actions, state, rewards) return next_obs, rewards, terminateds, truncateds, infos + def _write_step_metadata_json(self, actions: Dict, state: Dict, rewards: Dict): + output_dir = SIM_OUTPUT.path / f"episode_{self.game.episode_counter}" / "step_metadata" + + output_dir.mkdir(parents=True, exist_ok=True) + path = output_dir / f"step_{self.game.step_counter}.json" + + data = { + "episode": self.game.episode_counter, + "step": self.game.step_counter, + "actions": {agent_name: int(action) for agent_name, action in actions.items()}, + "reward": rewards, + "state": state, + } + with open(path, "w") as file: + json.dump(data, file) + def _get_obs(self) -> Dict[str, ObsType]: """Return the current observation.""" obs = {} diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 0017215a..0234934d 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -66,9 +66,9 @@ class ACLRule(SimComponent): state = super().describe_state() state["action"] = self.action.value state["protocol"] = self.protocol.value if self.protocol else None - state["src_ip_address"] = self.src_ip_address if self.src_ip_address else None + state["src_ip_address"] = str(self.src_ip_address) if self.src_ip_address else None state["src_port"] = self.src_port.value if self.src_port else None - state["dst_ip_address"] = self.dst_ip_address if self.dst_ip_address else None + state["dst_ip_address"] = str(self.dst_ip_address) if self.dst_ip_address else None state["dst_port"] = self.dst_port.value if self.dst_port else None return state diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/switch.py index fe61509c..92999b88 100644 --- a/src/primaite/simulator/network/hardware/nodes/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/switch.py @@ -57,7 +57,7 @@ class Switch(Node): state = super().describe_state() state["ports"] = {port_num: port.describe_state() for port_num, port in self.switch_ports.items()} state["num_ports"] = self.num_ports # redundant? - state["mac_address_table"] = {mac: port for mac, port in self.mac_address_table.items()} + state["mac_address_table"] = {mac: port.port_num for mac, port in self.mac_address_table.items()} return state def _add_mac_table_entry(self, mac_address: str, switch_port: SwitchPort): From 31c4287f469051f5763535dcc1d1f429e1be93fc Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Sat, 2 Dec 2023 01:05:13 +0000 Subject: [PATCH 449/980] #2084: applying github example fix to pipeline --- .azure/azure-ci-build-pipeline.yaml | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 11d53d73..be46466b 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -97,6 +97,12 @@ stages: primaite setup displayName: 'Perform PrimAITE Setup' + - task: UseDotNet@2 + displayName: 'Install dotnet dependencies' + inputs: + packageType: 'sdk' + version: '2.1.x' + - script: | pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term displayName: 'Run tests and code coverage' @@ -111,9 +117,25 @@ stages: - publish: $(System.DefaultWorkingDirectory)/htmlcov/ artifact: coverage_report + # - task: PublishCodeCoverageResults@2 + # displayName: 'Publish coverage report' + # inputs: + # codeCoverageTool: Cobertura + # summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml' + # failIfCoverageEmpty: true + - task: PublishCodeCoverageResults@2 - displayName: 'Publish coverage report' + displayName: 'Install code coverage upload dependencies' + # We only want the dependencies - this azure task is borked https://github.com/microsoft/azure-pipelines-tasks/issues/17756 + # ref: https://github.com/microsoft/azure-pipelines-tasks/issues/17756#issuecomment-1585620675 + condition: eq('true', 'false') # THIS WILL NEVER RUN ONCE TASK DECLARATION IS NEEDED TO DOWNLOAD IT SOURCES inputs: - codeCoverageTool: Cobertura summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml' - failIfCoverageEmpty: true + + - task: CmdLine@2 + displayName: Publish Code Coverage + env: { 'SYSTEM_ACCESSTOKEN': $(System.AccessToken) } #access token is needed to upload report to azure pipeline tabs + inputs: + script: | + mkdir /home/vsts/work/_temp/cobertura + "$(Dotnet_Root)/dotnet"dotnet `find /home/vsts/work/_tasks/ -name CoveragePublisher.Console.dll` '$(System.DefaultWorkingDirectory)/coverage.xml' --reportDirectory /home/vsts/work/_temp/cobertura From 6ecb47f5aedb4c521e40261f8cd34821332bfb5a Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Sat, 2 Dec 2023 01:19:38 +0000 Subject: [PATCH 450/980] #2084: debug coverage file --- .azure/azure-ci-build-pipeline.yaml | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index be46466b..0e150a50 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -104,7 +104,7 @@ stages: version: '2.1.x' - script: | - pytest -v tests/ --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term + pytest -v --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term displayName: 'Run tests and code coverage' - task: PublishTestResults@2 @@ -124,18 +124,18 @@ stages: # summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml' # failIfCoverageEmpty: true - - task: PublishCodeCoverageResults@2 - displayName: 'Install code coverage upload dependencies' - # We only want the dependencies - this azure task is borked https://github.com/microsoft/azure-pipelines-tasks/issues/17756 - # ref: https://github.com/microsoft/azure-pipelines-tasks/issues/17756#issuecomment-1585620675 - condition: eq('true', 'false') # THIS WILL NEVER RUN ONCE TASK DECLARATION IS NEEDED TO DOWNLOAD IT SOURCES - inputs: - summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml' + # - task: PublishCodeCoverageResults@2 + # displayName: 'Install code coverage upload dependencies' + # # We only want the dependencies - this azure task is borked https://github.com/microsoft/azure-pipelines-tasks/issues/17756 + # # ref: https://github.com/microsoft/azure-pipelines-tasks/issues/17756#issuecomment-1585620675 + # condition: eq('true', 'false') # THIS WILL NEVER RUN ONCE TASK DECLARATION IS NEEDED TO DOWNLOAD IT SOURCES + # inputs: + # summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml' - - task: CmdLine@2 - displayName: Publish Code Coverage - env: { 'SYSTEM_ACCESSTOKEN': $(System.AccessToken) } #access token is needed to upload report to azure pipeline tabs - inputs: - script: | - mkdir /home/vsts/work/_temp/cobertura - "$(Dotnet_Root)/dotnet"dotnet `find /home/vsts/work/_tasks/ -name CoveragePublisher.Console.dll` '$(System.DefaultWorkingDirectory)/coverage.xml' --reportDirectory /home/vsts/work/_temp/cobertura + # - task: CmdLine@2 + # displayName: Publish Code Coverage + # env: { 'SYSTEM_ACCESSTOKEN': $(System.AccessToken) } #access token is needed to upload report to azure pipeline tabs + # inputs: + # script: | + # mkdir /home/vsts/work/_temp/cobertura + # "$(Dotnet_Root)/dotnet" `find /home/vsts/work/_tasks/ -name CoveragePublisher.Console.dll` '$(System.DefaultWorkingDirectory)/coverage.xml' --reportDirectory /home/vsts/work/_temp/cobertura From 47287ad1eb2d326e74a2381e51bd8e1bb5a6ed15 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Sat, 2 Dec 2023 13:44:39 +0000 Subject: [PATCH 451/980] #2084: fixing 0% coverage --- .azure/azure-ci-build-pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 0e150a50..5759e70e 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -104,7 +104,7 @@ stages: version: '2.1.x' - script: | - pytest -v --cov=src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term + pytest -v --cov=$(System.DefaultWorkingDirectory)/src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term displayName: 'Run tests and code coverage' - task: PublishTestResults@2 From 2123fbb8f4476c5365a2bc2366f13db29be64672 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Sat, 2 Dec 2023 14:17:34 +0000 Subject: [PATCH 452/980] #2084: more debugging --- .azure/azure-ci-build-pipeline.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 5759e70e..36704ac0 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -104,7 +104,9 @@ stages: version: '2.1.x' - script: | - pytest -v --cov=$(System.DefaultWorkingDirectory)/src/ -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-report xml:$(System.DefaultWorkingDirectory)/coverage.xml --cov-report html:$(System.DefaultWorkingDirectory)/htmlcov --cov-report term + coverage run -m pytest tests/unit_tests + coverage xml -o coverage.xml -i + coverage html -d htmlcov -i displayName: 'Run tests and code coverage' - task: PublishTestResults@2 @@ -117,6 +119,12 @@ stages: - publish: $(System.DefaultWorkingDirectory)/htmlcov/ artifact: coverage_report + - task: PublishCodeCoverageResults@1 + inputs: + codeCoverageTool: Cobertura + summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml' + reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov' + # - task: PublishCodeCoverageResults@2 # displayName: 'Publish coverage report' # inputs: From e48f0a6d68d249502149c448881d77512b9abff2 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Sat, 2 Dec 2023 14:41:45 +0000 Subject: [PATCH 453/980] #2084: more debugging --- .azure/azure-ci-build-pipeline.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 36704ac0..cb76b5b1 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -56,7 +56,9 @@ stages: pool: vmImage: ${{ item.img }} - condition: or( eq(variables['Build.Reason'], 'PullRequest'), ${{ item.every_time }} ) +# TODO: dont forget to undo +# condition: or( eq(variables['Build.Reason'], 'PullRequest'), ${{ item.every_time }} ) + condition: ${{ item.every_time }} steps: - task: UsePythonVersion@0 @@ -119,11 +121,11 @@ stages: - publish: $(System.DefaultWorkingDirectory)/htmlcov/ artifact: coverage_report - - task: PublishCodeCoverageResults@1 + - task: PublishCodeCoverageResults@2 inputs: codeCoverageTool: Cobertura summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml' - reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov' + # reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov' # - task: PublishCodeCoverageResults@2 # displayName: 'Publish coverage report' From 7b21f390c0fcbb864d00435eb8fb5b83d55a2fa8 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Sat, 2 Dec 2023 15:31:36 +0000 Subject: [PATCH 454/980] #2084: more debugging --- .azure/azure-ci-build-pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index cb76b5b1..3e2237d3 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -106,7 +106,7 @@ stages: version: '2.1.x' - script: | - coverage run -m pytest tests/unit_tests + coverage run -m pytest -v -o junit_family=xunit2 --junitxml=junit/test-results.xml coverage xml -o coverage.xml -i coverage html -d htmlcov -i displayName: 'Run tests and code coverage' From 060a46e251a23c73f9b6280eef696250ec448873 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Sat, 2 Dec 2023 18:44:27 +0000 Subject: [PATCH 455/980] #2084: more debugging --- .azure/azure-ci-build-pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 3e2237d3..77cae6fc 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -106,7 +106,7 @@ stages: version: '2.1.x' - script: | - coverage run -m pytest -v -o junit_family=xunit2 --junitxml=junit/test-results.xml + coverage run -m --source=primaite pytest -v -o junit_family=xunit2 --junitxml=junit/test-results.xml coverage xml -o coverage.xml -i coverage html -d htmlcov -i displayName: 'Run tests and code coverage' From 53f43dde0d623cf2c4bdae2ba21531e877993cce Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Sat, 2 Dec 2023 19:07:10 +0000 Subject: [PATCH 456/980] #2084: cleaning up --- .azure/azure-ci-build-pipeline.yaml | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 77cae6fc..239369f5 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -56,9 +56,7 @@ stages: pool: vmImage: ${{ item.img }} -# TODO: dont forget to undo -# condition: or( eq(variables['Build.Reason'], 'PullRequest'), ${{ item.every_time }} ) - condition: ${{ item.every_time }} + condition: or( eq(variables['Build.Reason'], 'PullRequest'), ${{ item.every_time }} ) steps: - task: UsePythonVersion@0 @@ -122,30 +120,7 @@ stages: artifact: coverage_report - task: PublishCodeCoverageResults@2 + condition: ${{ item.every_time }} # should only be run once inputs: codeCoverageTool: Cobertura summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml' - # reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov' - - # - task: PublishCodeCoverageResults@2 - # displayName: 'Publish coverage report' - # inputs: - # codeCoverageTool: Cobertura - # summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml' - # failIfCoverageEmpty: true - - # - task: PublishCodeCoverageResults@2 - # displayName: 'Install code coverage upload dependencies' - # # We only want the dependencies - this azure task is borked https://github.com/microsoft/azure-pipelines-tasks/issues/17756 - # # ref: https://github.com/microsoft/azure-pipelines-tasks/issues/17756#issuecomment-1585620675 - # condition: eq('true', 'false') # THIS WILL NEVER RUN ONCE TASK DECLARATION IS NEEDED TO DOWNLOAD IT SOURCES - # inputs: - # summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml' - - # - task: CmdLine@2 - # displayName: Publish Code Coverage - # env: { 'SYSTEM_ACCESSTOKEN': $(System.AccessToken) } #access token is needed to upload report to azure pipeline tabs - # inputs: - # script: | - # mkdir /home/vsts/work/_temp/cobertura - # "$(Dotnet_Root)/dotnet" `find /home/vsts/work/_tasks/ -name CoveragePublisher.Console.dll` '$(System.DefaultWorkingDirectory)/coverage.xml' --reportDirectory /home/vsts/work/_temp/cobertura From 1cc00203816b029a3594359df3126f237698a7f7 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Sat, 2 Dec 2023 19:38:45 +0000 Subject: [PATCH 457/980] #2084: only upload copy of html report once --- .azure/azure-ci-build-pipeline.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 239369f5..221bedd5 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -117,9 +117,12 @@ stages: testRunTitle: 'Publish test results' - publish: $(System.DefaultWorkingDirectory)/htmlcov/ + # publish the html report - so we can debug the coverage if needed + condition: ${{ item.every_time }} # should only be run once artifact: coverage_report - task: PublishCodeCoverageResults@2 + # publish the code coverage so it can be viewed in the run coverage page condition: ${{ item.every_time }} # should only be run once inputs: codeCoverageTool: Cobertura From 1d5337153ba050b9a2900e75d4e465ae6b41d12d Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Sat, 2 Dec 2023 19:46:04 +0000 Subject: [PATCH 458/980] #2084: fix pr autocancel --- .azure/azure-ci-build-pipeline.yaml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 221bedd5..8a944c7f 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -7,17 +7,8 @@ trigger: - release/* pr: - autoCancel: true # automatically cancel PR if new push made - drafts: true # get triggered when doing drafts - branches: - include: - - main - - dev - - feature/* - - hotfix/* - - bugfix/* - - release/* - + autoCancel: true + drafts: false parameters: # https://stackoverflow.com/a/70046417 - name: matrix From 534d4f96f3b89b8ff6e5ed4930b93293108f9b27 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 4 Dec 2023 08:58:03 +0000 Subject: [PATCH 459/980] #2084: add coverage fail condition --- .azure/azure-ci-build-pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 8a944c7f..26559889 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -95,7 +95,7 @@ stages: version: '2.1.x' - script: | - coverage run -m --source=primaite pytest -v -o junit_family=xunit2 --junitxml=junit/test-results.xml + coverage run -m --source=primaite pytest -v -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-fail-under=80 coverage xml -o coverage.xml -i coverage html -d htmlcov -i displayName: 'Run tests and code coverage' From 8f063aa339cdc7567e4be36b9e23a2fadb0d99e4 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 4 Dec 2023 09:07:42 +0000 Subject: [PATCH 460/980] #2084: apply previous PR suggestions --- .../_primaite/_simulator/_network/test_container.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index 021d6777..e348838e 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -53,7 +53,7 @@ def test_reset_network(network): server_1.power_off() assert server_1.operating_state is NodeOperatingState.SHUTTING_DOWN - assert network.describe_state() is not state_before + assert network.describe_state() != state_before network.reset_component_for_episode(episode=1) @@ -79,12 +79,16 @@ def test_apply_timestep_to_nodes(network): assert client_1.operating_state is NodeOperatingState.ON client_1.power_off() + assert client_1.operating_state is NodeOperatingState.SHUTTING_DOWN for i in range(client_1.shut_down_duration + 1): network.apply_timestep(timestep=i) assert client_1.operating_state is NodeOperatingState.OFF + network.apply_timestep(client_1.shut_down_duration + 2) + assert client_1.operating_state is NodeOperatingState.OFF + def test_removing_node_that_does_not_exist(network): """Node that does not exist on network should not affect existing nodes.""" From de5fead9a475ccfb99d775dfa3858cf871263206 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Dec 2023 09:14:20 +0000 Subject: [PATCH 461/980] Add docpage for config --- docs/source/config.rst | 79 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/docs/source/config.rst b/docs/source/config.rst index 0ce8b547..34147578 100644 --- a/docs/source/config.rst +++ b/docs/source/config.rst @@ -1,13 +1,80 @@ Primaite v3 config ****************** -PrimAITE uses a single configuration file to define a cybersecurity scenario. This includes the computer network and multiple agents. There are three main sections: training_config, game, and simulation. +PrimAITE uses a single configuration file to define everything needed to train and evaluate an RL policy in a custom cybersecurity scenario. This includes the configuration of the network, the scripted or trained agents that interact with the network, as well as settings that define how to perform training in Stable Baselines 3 or Ray RLLib. +The entire config is used by the ``PrimaiteSession`` object for users who wish to let PrimAITE handle the agent definition and training. If you wish to define custom agents and control the training loop yourself, you can use the config with the ``PrimaiteGame``, and ``PrimaiteGymEnv`` objects instead. That way, only the network configuration and agent setup parts of the config are used, and the training section is ignored. -The simulation section describes the simulated network environment with which the agetns interact. +Configurable items +================== -The game section describes the agents and their capabilities. Each agent has a unique type and is associated with a team (GREEN, RED, or BLUE). Each agent has a configurable observation space, action space, and reward function. +``training_config`` +------------------- +This section allows selecting which training framework and algorithm to use, and set some training hyperparameters. -The training_config section describes the training parameters for the learning agents. This includes the number of episodes, the number of steps per episode, and the number of steps before the agents start learning. The training_config section also describes the learning algorithm used by the agents. The learning algorithm is specified by the name of the algorithm and the hyperparameters for the algorithm. The hyperparameters are specific to each algorithm and are described in the documentation for each algorithm. +``io_settings`` +--------------- +This section configures how the ``PrimaiteSession`` saves data. -.. only:: comment - This needs a bit of refactoring so I haven't written extensive documentation about the config yet. +``game`` +-------- +This section defines high-level settings that apply across the game, currently it's used to help shape the action and observation spaces by restricting which ports and internet protocols should be considered. Here, users can also set the maximum number of steps in an episode. + +``agents`` +---------- +Agents can be scripted (deterministic and stochastic), or controlled by a reinforcement learning algorithm. Not to be confused with an RL agent, the term agent here is used to refer to an entity that sends requests to the simulated network. In this part of the config, each agent's action space, observation space, and reward function can be defined. All three are defined in a modular way. + +**type**: Specifies which class should be used for the agent. ``ProxyAgent`` is used for agents that receive instructions from an RL algorithm. Scripted agents like ``RedDatabaseCorruptingAgent`` and ``GreenWebBrowsingAgent`` generate their own behaviour. + +**team:**: Specifies if the agent is malicious (RED), benign (GREEN), or defensive (BLUE). Currently this value is not used for anything. + +**observation space:** + * ``type``: selects which python class from the ``primaite.game.agent.observation`` module is used for the overall observation structure. + * ``options``: allows configuring the chosen observation type. The ``UC2BlueObservation`` should be used for RL Agents. + * ``num_services_per_node``, ``num_folders_per_node``, ``num_files_per_folder``, ``num_nics_per_node`` all define the shape of the observation space. The size and shape of the obs space must remain constant, but the number of files, folders, ACL rules, and other components can change within an episode. Therefore padding is performed and these options set the size of the obs space. + * ``nodes``: list of nodes that will be present in this agent's observation space. The ``node_ref`` relates to the human-readable unique reference defined later in the ``simulation`` part of the config. Each node can also be configured with services, and files that should be monitored. + * ``links``: list of links that will be present in this agent's observation space. The ``link_ref`` relates to the human-readable unique reference defined later in the ``simulation`` part of the config. + * ``acl``: configure how the agent reads the access control list on the router in the simulation. ``router_node_ref`` is for selecting which router's ACL table should be used. ``ip_address_order`` sets the encoding of ip addresses as integers within the observation space. + +**action space:** +The action space is configured to be made up of individual action types. Once configured, the agent can select an action type and some optional action parameters at every step. For example: The ``NODE_SERVICE_SCAN`` action takes the parameters ``node_id`` and ``service_id``. + +Description of configurable items: + * ``action_list``: a list of action modules. The options are listed in the ``primaite.game.agent.actions`` module. + * ``action_map``: (optional). Restricts the possible combinations of action type / action parameter values to reduce the overall size of the action space. By default, every possible combination of actions and parameters will be assigned an integer for the agent's ``MultiDiscrete`` action space. Instead, the action_map allows you to list the actions corresponding to each integer in the ``MultiDiscrete`` space. + * ``options``: Options that apply too all action components. + * ``nodes``: list the nodes that the agent can act on, the order of this list defines the mapping between nodes and ``node_id`` integers. + * ``max_folders_per_node``, ``max_files_per_folder``, ``max_services_per_node``, ``max_nics_per_node``, ``max_acl_rules`` all are used to define the size of the action space. + +**reward function:** +Similar to action space, this is defined as a list of components. + +Description of configurable items: + * ``reward_components`` a list of reward components from the ``primaite.game.agent.reward`` module. + * ``weight``: relative importance of this reward component. The total reward for a step is a weighted sum of all reward components. + * ``options``: list of options passed to the reward component during initialisation, the exact options required depend on the reward component. + +**agent_settings**: +Settings passed to the agent during initialisation. These depend on the agent class. + +``simulation`` +-------------- +In this section the network layout is defined. This part of the config follows a hierarchical structure. Almost every component defines a ``ref`` field which acts as a human-readable unique identifier, used by other parts of the config, such as agents. + +At the top level of the network are ``nodes`` and ``links``. + +**nodes:** + * ``type``: one of ``router``, ``switch``, ``computer``, or ``server``, this affects what other sub-options should be defined. + * ``hostname`` - a non-unique name used for logging and outputs. + * ``num_ports`` (optional, routers and switches only): number of network interfaces present on the device. + * ``ports`` (optional, routers and switches only): configuration for each network interface, including IP address and subnet mask. + * ``acl`` (Router only): Define the ACL rules at each index of the ACL on the router. the possible options are: ``action`` (PERMIT or DENY), ``src_port``, ``dst_port``, ``protocol``, ``src_ip``, ``dst_ip``. Any options left blank default to none which usually means that it will apply across all options. For example leaving ``src_ip`` blank will apply the rule to all IP addresses. + * ``services`` (computers and servers only): a list of services to install on the node. They must define a ``ref``, ``type``, and ``options`` that depend on which ``type`` was selected. + * ``applications`` (computer and servers only): Similar to services. A list of application to install on the node. + * ``nics`` (computers and servers only): If the node has multiple networking devices, the second, third, fourth, etc... must be defined here with an ``ip_address`` and ``subnet_mask``. + +**links:** + * ``ref``: unique identifier for this link + * ``endpoint_a_ref``: Reference to the node at the first end of the link + * ``endpoint_a_port``: The ethernet port or switch port index of the second node + * ``endpoint_b_ref``: Reference to the node at the second end of the link + * ``endpoint_b_port``: The ethernet port or switch port index on the second node From ba3d37316b93e7c5815054db9bdd291f593511b3 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Dec 2023 09:21:47 +0000 Subject: [PATCH 462/980] Apply suggestions from review --- src/primaite/game/agent/rewards.py | 2 +- src/primaite/notebooks/training_example_ray_multi_agent.ipynb | 2 +- src/primaite/session/session.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index b7a5e9be..9b3dfb80 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -238,7 +238,7 @@ class RewardFunction: """Initialise the reward function object.""" self.reward_components: List[Tuple[AbstractReward, float]] = [] "attribute reward_components keeps track of reward components and the weights assigned to each." - self.current_reward: float + self.current_reward: float = 0.0 self.total_reward: float = 0.0 def regsiter_component(self, component: AbstractReward, weight: float = 1.0) -> None: diff --git a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb index cd9ecfe7..0d4b6d0e 100644 --- a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb @@ -83,7 +83,7 @@ "tune.Tuner(\n", " \"PPO\",\n", " run_config=air.RunConfig(\n", - " stop={\"timesteps_total\": 511},\n", + " stop={\"timesteps_total\": 512},\n", " ),\n", " param_space=config\n", ").fit()" diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py index 3c8b40bd..ef462d83 100644 --- a/src/primaite/session/session.py +++ b/src/primaite/session/session.py @@ -62,7 +62,7 @@ class PrimaiteSession: def start_session(self) -> None: """Commence the training/eval session.""" - print("Staring Primaite Session") + print("Starting Primaite Session") self.mode = SessionMode.TRAIN n_learn_episodes = self.training_options.n_learn_episodes n_eval_episodes = self.training_options.n_eval_episodes From 9fa6f0b7aba2cb7432b46db9d95c144199eb76c1 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Dec 2023 10:16:29 +0000 Subject: [PATCH 463/980] Formatting improvements in cfg doc page --- docs/source/config.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/config.rst b/docs/source/config.rst index 34147578..f4452c7e 100644 --- a/docs/source/config.rst +++ b/docs/source/config.rst @@ -25,7 +25,7 @@ Agents can be scripted (deterministic and stochastic), or controlled by a reinfo **type**: Specifies which class should be used for the agent. ``ProxyAgent`` is used for agents that receive instructions from an RL algorithm. Scripted agents like ``RedDatabaseCorruptingAgent`` and ``GreenWebBrowsingAgent`` generate their own behaviour. -**team:**: Specifies if the agent is malicious (RED), benign (GREEN), or defensive (BLUE). Currently this value is not used for anything. +**team**: Specifies if the agent is malicious (RED), benign (GREEN), or defensive (BLUE). Currently this value is not used for anything. **observation space:** * ``type``: selects which python class from the ``primaite.game.agent.observation`` module is used for the overall observation structure. @@ -40,7 +40,7 @@ The action space is configured to be made up of individual action types. Once co Description of configurable items: * ``action_list``: a list of action modules. The options are listed in the ``primaite.game.agent.actions`` module. - * ``action_map``: (optional). Restricts the possible combinations of action type / action parameter values to reduce the overall size of the action space. By default, every possible combination of actions and parameters will be assigned an integer for the agent's ``MultiDiscrete`` action space. Instead, the action_map allows you to list the actions corresponding to each integer in the ``MultiDiscrete`` space. + * ``action_map``: (optional). Restricts the possible combinations of action type / action parameter values to reduce the overall size of the action space. By default, every possible combination of actions and parameters will be assigned an integer for the agent's ``MultiDiscrete`` action space. Instead, the ``action_map`` allows you to list the actions corresponding to each integer in the ``MultiDiscrete`` space. * ``options``: Options that apply too all action components. * ``nodes``: list the nodes that the agent can act on, the order of this list defines the mapping between nodes and ``node_id`` integers. * ``max_folders_per_node``, ``max_files_per_folder``, ``max_services_per_node``, ``max_nics_per_node``, ``max_acl_rules`` all are used to define the size of the action space. From a5c4f7797d34416fb7bec946a59843fdcbc2ba31 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Dec 2023 10:42:20 +0000 Subject: [PATCH 464/980] Make saving step metadata optional --- src/primaite/config/_package_data/example_config.yaml | 1 + .../config/_package_data/example_config_2_rl_agents.yaml | 1 + src/primaite/game/game.py | 9 +++++++++ src/primaite/session/environment.py | 6 ++++-- src/primaite/session/io.py | 2 ++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 7d5b50d6..24f9945d 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -13,6 +13,7 @@ training_config: io_settings: save_checkpoints: true checkpoint_interval: 5 + save_step_metadata: false game: diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index b811bfa5..9c2acaae 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -9,6 +9,7 @@ training_config: io_settings: save_checkpoints: true checkpoint_interval: 5 + save_step_metadata: false game: diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index a36cbea9..8c32f41d 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -10,6 +10,7 @@ from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent, RandomAgent from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction +from primaite.session.io import SessionIO, SessionIOSettings from primaite.simulator.network.hardware.base import NIC, NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router @@ -84,6 +85,9 @@ class PrimaiteGame: self.ref_map_links: Dict[str, str] = {} """Mapping from human-readable link reference to link object. Used when parsing config files.""" + self.save_step_metadata: bool = False + """Whether to save the RL agents' action, environment state, and other data at every single step.""" + def step(self): """ Perform one step of the simulation/agent loop. @@ -180,8 +184,13 @@ class PrimaiteGame: :return: A PrimaiteGame object. :rtype: PrimaiteGame """ + io_settings = cfg.get("io_settings", {}) + _ = SessionIO(SessionIOSettings(**io_settings)) + # Instantiating this ensures that the game saves to the correct output dir even without being part of a session + game = cls() game.options = PrimaiteGameOptions(**cfg["game"]) + game.save_step_metadata = cfg.get("io_settings", {}).get("save_step_metadata") or False # 1. create simulation sim = game.simulation diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index dfee9a2f..3d43e338 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -40,7 +40,8 @@ class PrimaiteGymEnv(gymnasium.Env): terminated = False truncated = self.game.calculate_truncated() info = {} - self._write_step_metadata_json(action, state, reward) + if self.game.save_step_metadata: + self._write_step_metadata_json(action, state, reward) print(f"Episode: {self.game.episode_counter}, Step: {self.game.step_counter}, Reward: {reward}") return next_obs, reward, terminated, truncated, info @@ -183,7 +184,8 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): infos = {} terminateds["__all__"] = len(self.terminateds) == len(self.agents) truncateds["__all__"] = self.game.calculate_truncated() - self._write_step_metadata_json(actions, state, rewards) + if self.game.save_step_metadata: + self._write_step_metadata_json(actions, state, rewards) return next_obs, rewards, terminateds, truncateds, infos def _write_step_metadata_json(self, actions: Dict, state: Dict, rewards: Dict): diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index e0b849c9..0d80a385 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -25,6 +25,8 @@ class SessionIOSettings(BaseModel): """Whether to save transactions, If true, the session path will have a transactions folder.""" save_tensorboard_logs: bool = False """Whether to save tensorboard logs. If true, the session path will have a tenorboard_logs folder.""" + save_step_metadata: bool = False + """Whether to save the RL agents' action, environment state, and other data at every single step.""" class SessionIO: From 01b9e661ce94c1f959f1f8b866616fdafa496afd Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Dec 2023 10:45:33 +0000 Subject: [PATCH 465/980] Clean up print statements. --- src/primaite/session/environment.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 3d43e338..ca71a0c0 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -42,7 +42,6 @@ class PrimaiteGymEnv(gymnasium.Env): info = {} if self.game.save_step_metadata: self._write_step_metadata_json(action, state, reward) - print(f"Episode: {self.game.episode_counter}, Step: {self.game.step_counter}, Reward: {reward}") return next_obs, reward, terminated, truncated, info def _write_step_metadata_json(self, action: int, state: Dict, reward: int): From 30b0f12a8dac8c02cbf8b6154fc43b24078edf28 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Dec 2023 11:34:17 +0000 Subject: [PATCH 466/980] Allow cancelling jobs --- .azure/azure-ci-build-pipeline.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 26559889..fe1cc58e 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -44,10 +44,11 @@ stages: jobs: - ${{ each item in parameters.matrix }}: - job: ${{ item.job_name }} + timeoutInMinutes: 90 + cancelTimeoutInMinutes: 1 pool: vmImage: ${{ item.img }} - - condition: or( eq(variables['Build.Reason'], 'PullRequest'), ${{ item.every_time }} ) + condition: and(succeeded(), or( eq(variables['Build.Reason'], 'PullRequest'), ${{ item.every_time }} )) steps: - task: UsePythonVersion@0 From 75f732dacfadcdb5a2902f25f43460f18a0f721c Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Dec 2023 13:08:13 +0000 Subject: [PATCH 467/980] bump version to 3.0.0b2 --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index dcc86c22..2aa4d8f0 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0b2dev +3.0.0b2 From 12ede2329b48e3225acef5fb86030a54eacfa91d Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 6 Dec 2023 16:41:10 +0000 Subject: [PATCH 468/980] 2041: Add network config and pytest fixture --- .../system/test_ntp_client_server.py | 45 +++++++------------ 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index dec6c0f7..ed5e6962 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -1,5 +1,6 @@ from ipaddress import IPv4Address from time import sleep +from typing import Tuple import pytest @@ -14,7 +15,8 @@ from primaite.simulator.system.services.service import ServiceOperatingState # Create simple network for testing -def create_ntp_network() -> Network: +@pytest.fixture(scope="function") +def create_ntp_network(client_server) -> Tuple[NTPClient, Computer, NTPServer, Server]: """ +------------+ +------------+ | ntp | | ntp | @@ -23,32 +25,26 @@ def create_ntp_network() -> Network: +------------+ +------------+ """ + client, server = client_server - network = Network() - ntp_server = Server( - hostname="ntp_server", ip_address="192.168.1.2", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" - ) - ntp_server.power_on() - ntp_server.software_manager.install(NTPServer) + server.power_on() + server.software_manager.install(NTPServer) + ntp_server: NTPServer = server.software_manager.software.get("NTPServer") + ntp_server.start() - ntp_client = Computer( - hostname="ntp_client", ip_address="192.168.1.3", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" - ) - ntp_client.power_on() - ntp_client.software_manager.install(NTPClient) + client.power_on() + client.software_manager.install(NTPClient) + ntp_client: NTPClient = client.software_manager.software.get("NTPClient") + ntp_client.start() - network.connect(endpoint_b=ntp_server.ethernet_port[1], endpoint_a=ntp_client.ethernet_port[1]) - - return network + return ntp_client, client, ntp_server, server # Define one node to be an NTP server and another node to be a NTP Client. -def test_ntp_client_server(): - network = create_ntp_network() - server: Server = network.get_node_by_hostname("ntp_server") - client: Computer = network.get_node_by_hostname("ntp_client") +def test_ntp_client_server(create_ntp_network): + ntp_client, client, ntp_server, server = create_ntp_network ntp_server: NTPServer = server.software_manager.software["NTPServer"] ntp_client: NTPClient = client.software_manager.software["NTPClient"] @@ -56,24 +52,15 @@ def test_ntp_client_server(): assert ntp_server.operating_state == ServiceOperatingState.RUNNING assert ntp_client.operating_state == ServiceOperatingState.RUNNING ntp_client.configure( - ntp_server_ip_address=IPv4Address("192.168.1.2"), ntp_client_ip_address=IPv4Address("192.168.1.3") + ntp_server_ip_address=IPv4Address("192.168.0.2"), ntp_client_ip_address=IPv4Address("192.168.0.1") ) assert ntp_client.time is None - - # ntp_request = NTPRequest(ntp_client="192.168.1.3") - # ntp_packet = NTPPacket(ntp_request=ntp_request) - # ntp_client.send(payload=ntp_packet) ntp_client.request_time() - - # assert ntp_server.receive(payload=ntp_packet) is True - # assert ntp_client.receive(payload=ntp_packet) is True assert ntp_client.time is not None first_time = ntp_client.time sleep(0.1) ntp_client.apply_timestep(1) # Check time advances - # ntp_server.receive(payload=ntp_packet) - # ntp_client.receive(payload=ntp_packet) second_time = ntp_client.time assert first_time != second_time From 50a6e17fabfd6c20eb0f5ab63b01e7f3377144b5 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 6 Dec 2023 16:42:28 +0000 Subject: [PATCH 469/980] 2041: Make NTP work with TCP transport layer --- src/primaite/game/agent/actions.py | 2 +- src/primaite/game/game.py | 4 ++++ .../simulator/system/services/ntp/ntp_client.py | 10 +++++----- .../simulator/system/services/ntp/ntp_server.py | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 8eed3ba4..893b12b4 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -601,7 +601,7 @@ class ActionManager: max_nics_per_node: int = 8, # allows calculating shape max_acl_rules: int = 10, # allows calculating shape protocols: List[str] = ["TCP", "UDP", "ICMP"], # allow mapping index to protocol - ports: List[str] = ["HTTP", "DNS", "ARP", "FTP"], # allow mapping index to port + ports: List[str] = ["HTTP", "DNS", "ARP", "FTP", "NTP"], # allow mapping index to port ip_address_list: Optional[List[str]] = None, # to allow us to map an index to an ip address. act_map: Optional[Dict[int, Dict]] = None, # allows restricting set of possible actions ) -> None: diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index a36cbea9..edfe058d 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -25,6 +25,8 @@ from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.ftp.ftp_client import FTPClient from primaite.simulator.system.services.ftp.ftp_server import FTPServer +from primaite.simulator.system.services.ntp.ntp_client import NTPClient +from primaite.simulator.system.services.ntp.ntp_server import NTPServer from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.web_server.web_server import WebServer @@ -257,6 +259,8 @@ class PrimaiteGame: "WebServer": WebServer, "FTPClient": FTPClient, "FTPServer": FTPServer, + "NTPClient": NTPClient, + "NTPServer": NTPServer, } if service_type in service_types_mapping: _LOGGER.debug(f"installing {service_type} on node {new_node.hostname}") diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index c75e639d..f9cf29d4 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -23,7 +23,7 @@ class NTPClient(Service): def __init__(self, **kwargs): kwargs["name"] = "NTPClient" kwargs["port"] = Port.NTP - kwargs["protocol"] = IPProtocol.UDP + kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) self.start() @@ -65,7 +65,7 @@ class NTPClient(Service): self, payload: NTPPacket, session_id: Optional[str] = None, - dest_ip_address: IPv4Address = ntp_server, + dest_ip_address: IPv4Address = None, dest_port: [Port] = Port.NTP, **kwargs, ) -> bool: @@ -79,8 +79,6 @@ class NTPClient(Service): :return: True if successful, False otherwise. """ self.ip_addr = payload.ntp_request.ntp_client - self.sys_log.info(f"{self.name}: Sending NTP request {payload.ntp_request.ntp_client}") - return super().send( payload=payload, dest_ip_address=dest_ip_address, @@ -101,6 +99,8 @@ class NTPClient(Service): :param session_id: The Session ID the payload is to originate from. Optional. :return: True if successful, False otherwise. """ + self.sys_log.info(f"{self.name}: Receiving NTP request from {payload.ntp_request.ntp_client}") + if not (isinstance(payload, NTPPacket) and payload.ntp_request.ntp_client): _LOGGER.debug(f"{payload} is not a NTPPacket") return False @@ -116,7 +116,7 @@ class NTPClient(Service): """Send request to ntp_server.""" ntp_request = NTPRequest(ntp_client=self.ip_addr) ntp_server_packet = NTPPacket(ntp_request=ntp_request) - self.send(payload=ntp_server_packet) + self.send(payload=ntp_server_packet, dest_ip_address=self.ntp_server) def apply_timestep(self, timestep: int) -> None: """ diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index 6d76c1ed..400c397f 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -16,7 +16,7 @@ class NTPServer(Service): def __init__(self, **kwargs): kwargs["name"] = "NTPServer" kwargs["port"] = Port.NTP - kwargs["protocol"] = IPProtocol.UDP + kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) self.start() @@ -60,6 +60,7 @@ class NTPServer(Service): :return: True if valid NTP request else False. """ + self.sys_log.info(f"{self.name} received request from {payload.ntp_request.ntp_client}") if not (isinstance(payload, NTPPacket) and payload.ntp_request.ntp_client): _LOGGER.debug(f"{payload} is not a NTPPacket") return False From 385a4997ce289afdc27e8ae318d7db9fa0e851c3 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 7 Dec 2023 10:35:50 +0000 Subject: [PATCH 470/980] New parameter for publishing code coverage --- .azure/azure-ci-build-pipeline.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index fe1cc58e..f962a628 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -18,26 +18,32 @@ parameters: py: '3.8' img: 'ubuntu-latest' every_time: false + publish_coverage: false - job_name: 'UbuntuPython310' py: '3.10' img: 'ubuntu-latest' every_time: true + publish_coverage: true - job_name: 'WindowsPython38' py: '3.8' img: 'windows-latest' every_time: false + publish_coverage: false - job_name: 'WindowsPython310' py: '3.10' img: 'windows-latest' every_time: false + publish_coverage: false - job_name: 'MacOSPython38' py: '3.8' img: 'macOS-latest' every_time: false + publish_coverage: false - job_name: 'MacOSPython310' py: '3.10' img: 'macOS-latest' every_time: false + publish_coverage: false stages: - stage: Test @@ -110,12 +116,12 @@ stages: - publish: $(System.DefaultWorkingDirectory)/htmlcov/ # publish the html report - so we can debug the coverage if needed - condition: ${{ item.every_time }} # should only be run once + condition: ${{ item.publish_coverage }} # should only be run once artifact: coverage_report - task: PublishCodeCoverageResults@2 # publish the code coverage so it can be viewed in the run coverage page - condition: ${{ item.every_time }} # should only be run once + condition: ${{ item.publish_coverage }} # should only be run once inputs: codeCoverageTool: Cobertura summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml' From 44ada941e62cb1be63a832d6a9578349e6a1bec7 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Thu, 7 Dec 2023 14:22:27 +0000 Subject: [PATCH 471/980] 2041: Reinstate test for ntp_server failure --- .../system/test_ntp_client_server.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index ed5e6962..97b2fe30 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -66,27 +66,27 @@ def test_ntp_client_server(create_ntp_network): # Test ntp client behaviour when ntp server is unavailable. -@pytest.mark.skip(reason="NTP needs to know if underlying node is RUNNING") -def test_ntp_server_failure(): - network = create_ntp_network() - server: Server = network.get_node_by_hostname("ntp_server") - client: Computer = network.get_node_by_hostname("ntp_client") +def test_ntp_server_failure(create_ntp_network): + ntp_client, client, ntp_server, server = create_ntp_network ntp_server: NTPServer = server.software_manager.software["NTPServer"] ntp_client: NTPClient = client.software_manager.software["NTPClient"] assert ntp_client.operating_state == ServiceOperatingState.RUNNING + assert ntp_client.operating_state == ServiceOperatingState.RUNNING + ntp_client.configure( + ntp_server_ip_address=IPv4Address("192.168.0.2"), ntp_client_ip_address=IPv4Address("192.168.0.1") + ) # Turn off ntp server. ntp_server.stop() assert ntp_server.operating_state == ServiceOperatingState.STOPPED # And request a time update. - ntp_request = NTPRequest(ntp_client="192.168.1.3") - ntp_packet = NTPPacket(ntp_request=ntp_request) - ntp_client.send(payload=ntp_packet) - assert ntp_server.receive(payload=ntp_packet) is False - assert ntp_client.receive(payload=ntp_packet) is False + ntp_client.request_time() + assert ntp_client.time is None # Restart ntp server. ntp_server.start() assert ntp_server.operating_state == ServiceOperatingState.RUNNING + ntp_client.request_time() + assert ntp_client.time is not None From 094e89fff15a073207a43a8422a7fef23669544c Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 8 Dec 2023 14:54:29 +0000 Subject: [PATCH 472/980] #2059: Renamed Red service to red application and moved the datamanipulation bot to the red application folder --- src/primaite/game/agent/data_manipulation_bot.py | 2 +- src/primaite/game/game.py | 3 ++- src/primaite/simulator/network/networks.py | 2 +- .../red_services => applications/red_applications}/__init__.py | 0 .../red_applications}/data_manipulation_bot.py | 0 .../test_uc2_data_manipulation_scenario.py | 2 +- .../_red_applications}/__init__.py | 0 .../_red_applications}/test_data_manipulation_bot.py | 2 +- 8 files changed, 6 insertions(+), 5 deletions(-) rename src/primaite/simulator/system/{services/red_services => applications/red_applications}/__init__.py (100%) rename src/primaite/simulator/system/{services/red_services => applications/red_applications}/data_manipulation_bot.py (100%) rename tests/unit_tests/_primaite/_simulator/_system/{_services/_red_services => _applications/_red_applications}/__init__.py (100%) rename tests/unit_tests/_primaite/_simulator/_system/{_services/_red_services => _applications/_red_applications}/test_data_manipulation_bot.py (96%) diff --git a/src/primaite/game/agent/data_manipulation_bot.py b/src/primaite/game/agent/data_manipulation_bot.py index 8237ce06..791c362d 100644 --- a/src/primaite/game/agent/data_manipulation_bot.py +++ b/src/primaite/game/agent/data_manipulation_bot.py @@ -4,7 +4,7 @@ from typing import Dict, List, Tuple from gymnasium.core import ObsType from primaite.game.agent.interface import AbstractScriptedAgent -from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot +from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot class DataManipulationAgent(AbstractScriptedAgent): diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 8c32f41d..b6b815f1 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -20,13 +20,13 @@ from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.sim_container import Simulation from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.ftp.ftp_client import FTPClient from primaite.simulator.system.services.ftp.ftp_server import FTPServer -from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.web_server.web_server import WebServer _LOGGER = getLogger(__name__) @@ -314,6 +314,7 @@ class PrimaiteGame: opt = application_cfg["options"] new_application.configure( server_ip_address=IPv4Address(opt.get("server_ip")), + server_password=opt.get("server_password"), payload=opt.get("payload"), port_scan_p_of_success=float(opt.get("port_scan_p_of_success", "0.1")), data_manipulation_p_of_success=float(opt.get("data_manipulation_p_of_success", "0.1")), diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 4cd9c8d3..61ec7baf 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -9,10 +9,10 @@ from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.ftp.ftp_server import FTPServer -from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.web_server.web_server import WebServer diff --git a/src/primaite/simulator/system/services/red_services/__init__.py b/src/primaite/simulator/system/applications/red_applications/__init__.py similarity index 100% rename from src/primaite/simulator/system/services/red_services/__init__.py rename to src/primaite/simulator/system/applications/red_applications/__init__.py diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py similarity index 100% rename from src/primaite/simulator/system/services/red_services/data_manipulation_bot.py rename to src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index 0dc2c031..5206561b 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -1,8 +1,8 @@ from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.database.database_service import DatabaseService -from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot def test_data_manipulation(uc2_network): diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/__init__.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/__init__.py similarity index 100% rename from tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/__init__.py rename to tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/__init__.py diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_data_manipulation_bot.py similarity index 96% rename from tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py rename to tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_data_manipulation_bot.py index 2c4826bf..b0ff0467 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/_red_services/test_data_manipulation_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_data_manipulation_bot.py @@ -5,7 +5,7 @@ from primaite.simulator.network.networks import arcd_uc2_network from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import ApplicationOperatingState -from primaite.simulator.system.services.red_services.data_manipulation_bot import ( +from primaite.simulator.system.applications.red_applications.data_manipulation_bot import ( DataManipulationAttackStage, DataManipulationBot, ) From cd5ed48b007c0b4e8304dd75f861698b488337bb Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 8 Dec 2023 17:07:57 +0000 Subject: [PATCH 473/980] #2059: implementing the service connections limit --- src/primaite/simulator/network/networks.py | 4 +- .../system/applications/database_client.py | 109 ++++++++++------ .../red_applications/data_manipulation_bot.py | 4 +- .../services/database/database_service.py | 61 ++++++--- .../system/services/ftp/ftp_server.py | 13 +- .../simulator/system/services/service.py | 72 ++++++++++- src/primaite/simulator/system/software.py | 2 +- .../system/test_database_on_node.py | 121 +++++++++++++----- .../test_data_manipulation_bot.py | 2 +- .../_applications/test_database_client.py | 19 +-- 10 files changed, 280 insertions(+), 127 deletions(-) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 61ec7baf..630846b3 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -252,9 +252,9 @@ def arcd_uc2_network() -> Network: database_service: DatabaseService = database_server.software_manager.software.get("DatabaseService") # noqa database_service.start() database_service.configure_backup(backup_server=IPv4Address("192.168.1.16")) - database_service._process_sql(ddl, None) # noqa + database_service._process_sql(ddl, None, None) # noqa for insert_statement in user_insert_statements: - database_service._process_sql(insert_statement, None) # noqa + database_service._process_sql(insert_statement, None, None) # noqa # Web Server web_server = Server( diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index f57246fc..9d7bfcaa 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -23,7 +23,7 @@ class DatabaseClient(Application): server_ip_address: Optional[IPv4Address] = None server_password: Optional[str] = None - connected: bool = False + connections: Dict[str, Dict] = {} _query_success_tracker: Dict[str, bool] = {} def __init__(self, **kwargs): @@ -66,18 +66,24 @@ class DatabaseClient(Application): self.server_password = server_password self.sys_log.info(f"{self.name}: Configured the {self.name} with {server_ip_address=}, {server_password=}.") - def connect(self) -> bool: + def connect(self, connection_id: Optional[str] = None) -> bool: """Connect to a Database Service.""" if not self._can_perform_action(): return False - if not self.connected: - return self._connect(self.server_ip_address, self.server_password) - # already connected - return True + if not connection_id: + connection_id = str(uuid4()) + + return self._connect( + server_ip_address=self.server_ip_address, password=self.server_password, connection_id=connection_id + ) def _connect( - self, server_ip_address: IPv4Address, password: Optional[str] = None, is_reattempt: bool = False + self, + server_ip_address: IPv4Address, + connection_id: Optional[str] = None, + password: Optional[str] = None, + is_reattempt: bool = False, ) -> bool: """ Connects the DatabaseClient to the DatabaseServer. @@ -92,33 +98,58 @@ class DatabaseClient(Application): :type: is_reattempt: Optional[bool] """ if is_reattempt: - if self.connected: - self.sys_log.info(f"{self.name}: DatabaseClient connection to {server_ip_address} authorised") + if self.connections.get(connection_id): + self.sys_log.info( + f"{self.name} {connection_id=}: DatabaseClient connection to {server_ip_address} authorised" + ) self.server_ip_address = server_ip_address - return self.connected + return True else: - self.sys_log.info(f"{self.name}: DatabaseClient connection to {server_ip_address} declined") + self.sys_log.info( + f"{self.name} {connection_id=}: DatabaseClient connection to {server_ip_address} declined" + ) return False - payload = {"type": "connect_request", "password": password} + payload = { + "type": "connect_request", + "password": password, + "connection_id": connection_id, + } software_manager: SoftwareManager = self.software_manager software_manager.send_payload_to_session_manager( payload=payload, dest_ip_address=server_ip_address, dest_port=self.port ) - return self._connect(server_ip_address, password, True) + return self._connect( + server_ip_address=server_ip_address, password=password, connection_id=connection_id, is_reattempt=True + ) - def disconnect(self): + def disconnect(self, connection_id: Optional[str] = None) -> bool: """Disconnect from the Database Service.""" - if self.connected and self.operating_state is ApplicationOperatingState.RUNNING: - software_manager: SoftwareManager = self.software_manager - software_manager.send_payload_to_session_manager( - payload={"type": "disconnect"}, dest_ip_address=self.server_ip_address, dest_port=self.port - ) + if not self._can_perform_action(): + self.sys_log.error(f"Unable to disconnect - {self.name} is {self.operating_state.name}") + return False - self.sys_log.info(f"{self.name}: DatabaseClient disconnected from {self.server_ip_address}") - self.server_ip_address = None - self.connected = False + # if there are no connections - nothing to disconnect + if not len(self.connections): + self.sys_log.error(f"Unable to disconnect - {self.name} has no active connections.") + return False - def _query(self, sql: str, query_id: str, is_reattempt: bool = False) -> bool: + # if no connection provided, disconnect the first connection + if not connection_id: + connection_id = list(self.connections.keys())[0] + + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager( + payload={"type": "disconnect", "connection_id": connection_id}, + dest_ip_address=self.server_ip_address, + dest_port=self.port, + ) + self.connections.pop(connection_id) + + self.sys_log.info( + f"{self.name}: DatabaseClient disconnected connection {connection_id} from {self.server_ip_address}" + ) + + def _query(self, sql: str, query_id: str, connection_id: str, is_reattempt: bool = False) -> bool: """ Send a query to the connected database server. @@ -141,11 +172,11 @@ class DatabaseClient(Application): else: software_manager: SoftwareManager = self.software_manager software_manager.send_payload_to_session_manager( - payload={"type": "sql", "sql": sql, "uuid": query_id}, + payload={"type": "sql", "sql": sql, "uuid": query_id, "connection_id": connection_id}, dest_ip_address=self.server_ip_address, dest_port=self.port, ) - return self._query(sql=sql, query_id=query_id, is_reattempt=True) + return self._query(sql=sql, query_id=query_id, connection_id=connection_id, is_reattempt=True) def run(self) -> None: """Run the DatabaseClient.""" @@ -153,7 +184,7 @@ class DatabaseClient(Application): if self.operating_state == ApplicationOperatingState.RUNNING: self.connect() - def query(self, sql: str, is_reattempt: bool = False) -> bool: + def query(self, sql: str, connection_id: Optional[str] = None) -> bool: """ Send a query to the Database Service. @@ -164,20 +195,17 @@ class DatabaseClient(Application): if not self._can_perform_action(): return False - if self.connected: - query_id = str(uuid4()) + if connection_id is None: + connection_id = str(uuid4()) + + if not self.connections.get(connection_id): + if not self.connect(connection_id=connection_id): + return False # Initialise the tracker of this ID to False - self._query_success_tracker[query_id] = False - return self._query(sql=sql, query_id=query_id) - else: - if is_reattempt: - return False - - if not self.connect(): - return False - - self.query(sql=sql, is_reattempt=True) + uuid = str(uuid4()) + self._query_success_tracker[uuid] = False + return self._query(sql=sql, query_id=uuid, connection_id=connection_id) def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ @@ -192,13 +220,12 @@ class DatabaseClient(Application): if isinstance(payload, dict) and payload.get("type"): if payload["type"] == "connect_response": - self.connected = payload["response"] == True + if payload["response"] is True: + self.connections[payload.get("connection_id")] = payload elif payload["type"] == "sql": query_id = payload.get("uuid") status_code = payload.get("status_code") self._query_success_tracker[query_id] = status_code == 200 if self._query_success_tracker[query_id]: _LOGGER.debug(f"Received payload {payload}") - else: - self.connected = False return True diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index 44a56cf1..87959e9b 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -149,9 +149,9 @@ class DataManipulationBot(DatabaseClient): if simulate_trial(p_of_success): self.sys_log.info(f"{self.name}: Performing data manipulation") # perform the attack - if not self.connected: + if not len(self.connections): self.connect() - if self.connected: + if len(self.connections): self.query(self.payload) self.sys_log.info(f"{self.name} payload delivered: {self.payload}") attack_successful = True diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 61cf1560..70a4e6cc 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -1,4 +1,3 @@ -from datetime import datetime from ipaddress import IPv4Address from typing import Any, Dict, List, Literal, Optional, Union @@ -22,7 +21,6 @@ class DatabaseService(Service): """ password: Optional[str] = None - connections: Dict[str, datetime] = {} backup_server: IPv4Address = None """IP address of the backup server.""" @@ -140,7 +138,7 @@ class DatabaseService(Service): self.folder = self.file_system.get_folder_by_id(self._db_file.folder_id) def _process_connect( - self, session_id: str, password: Optional[str] = None + self, connection_id: str, password: Optional[str] = None ) -> Dict[str, Union[int, Dict[str, bool]]]: status_code = 500 # Default internal server error if self.operating_state == ServiceOperatingState.RUNNING: @@ -148,16 +146,27 @@ class DatabaseService(Service): if self.health_state_actual == SoftwareHealthState.GOOD: if self.password == password: status_code = 200 # ok - self.connections[session_id] = datetime.now() - self.sys_log.info(f"{self.name}: Connect request for {session_id=} authorised") + # try to create connection + if not self.add_connection(connection_id=connection_id): + status_code = 500 + self.sys_log.info(f"{self.name}: Connect request for {connection_id=} declined") + else: + self.sys_log.info(f"{self.name}: Connect request for {connection_id=} authorised") else: status_code = 401 # Unauthorised - self.sys_log.info(f"{self.name}: Connect request for {session_id=} declined") + self.sys_log.info(f"{self.name}: Connect request for {connection_id=} declined") else: status_code = 404 # service not found - return {"status_code": status_code, "type": "connect_response", "response": status_code == 200} + return { + "status_code": status_code, + "type": "connect_response", + "response": status_code == 200, + "connection_id": connection_id, + } - def _process_sql(self, query: Literal["SELECT", "DELETE"], query_id: str) -> Dict[str, Union[int, List[Any]]]: + def _process_sql( + self, query: Literal["SELECT", "DELETE"], query_id: str, connection_id: Optional[str] = None + ) -> Dict[str, Union[int, List[Any]]]: """ Executes the given SQL query and returns the result. @@ -169,15 +178,28 @@ class DatabaseService(Service): :return: Dictionary containing status code and data fetched. """ self.sys_log.info(f"{self.name}: Running {query}") + if query == "SELECT": if self.health_state_actual == SoftwareHealthState.GOOD: - return {"status_code": 200, "type": "sql", "data": True, "uuid": query_id} + return { + "status_code": 200, + "type": "sql", + "data": True, + "uuid": query_id, + "connection_id": connection_id, + } else: return {"status_code": 404, "data": False} elif query == "DELETE": if self.health_state_actual == SoftwareHealthState.GOOD: self.health_state_actual = SoftwareHealthState.COMPROMISED - return {"status_code": 200, "type": "sql", "data": False, "uuid": query_id} + return { + "status_code": 200, + "type": "sql", + "data": False, + "uuid": query_id, + "connection_id": connection_id, + } else: return {"status_code": 404, "data": False} else: @@ -207,15 +229,24 @@ class DatabaseService(Service): return False result = {"status_code": 500, "data": []} + + # if server service is down, return error + if not self._can_perform_action(): + return False + if isinstance(payload, dict) and payload.get("type"): if payload["type"] == "connect_request": - result = self._process_connect(session_id=session_id, password=payload.get("password")) + result = self._process_connect( + connection_id=payload.get("connection_id"), password=payload.get("password") + ) elif payload["type"] == "disconnect": - if session_id in self.connections: - self.connections.pop(session_id) + if payload["connection_id"] in self.connections: + self.remove_connection(connection_id=payload["connection_id"]) elif payload["type"] == "sql": - if session_id in self.connections: - result = self._process_sql(query=payload["sql"], query_id=payload["uuid"]) + if payload.get("connection_id") in self.connections: + result = self._process_sql( + query=payload["sql"], query_id=payload["uuid"], connection_id=payload["connection_id"] + ) else: result = {"status_code": 401, "type": "sql"} self.send(payload=result, session_id=session_id) diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 0278b616..6e6c1a48 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -1,5 +1,4 @@ -from ipaddress import IPv4Address -from typing import Any, Dict, Optional +from typing import Any, Optional from primaite import getLogger from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode @@ -21,9 +20,6 @@ class FTPServer(FTPServiceABC): server_password: Optional[str] = None """Password needed to connect to FTP server. Default is None.""" - connections: Dict[str, IPv4Address] = {} - """Current active connections to the FTP server.""" - def __init__(self, **kwargs): kwargs["name"] = "FTPServer" kwargs["port"] = Port.FTP @@ -62,9 +58,6 @@ class FTPServer(FTPServiceABC): self.sys_log.info(f"{self.name}: Received FTP {payload.ftp_command.name} {payload.ftp_command_args}") - if session_id: - session_details = self._get_session_details(session_id) - if payload.ftp_command is not None: self.sys_log.info(f"Received FTP {payload.ftp_command.name} command.") @@ -73,7 +66,7 @@ class FTPServer(FTPServiceABC): # check that the port is valid if isinstance(payload.ftp_command_args, Port) and payload.ftp_command_args.value in range(0, 65535): # return successful connection - self.connections[session_id] = session_details.with_ip_address + self.add_connection(connection_id=session_id, session_id=session_id) payload.status_code = FTPStatusCode.OK return payload @@ -81,7 +74,7 @@ class FTPServer(FTPServiceABC): return payload if payload.ftp_command == FTPCommand.QUIT: - self.connections.pop(session_id) + self.remove_connection(connection_id=session_id) payload.status_code = FTPStatusCode.OK return payload diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index e60b7700..52187e51 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,3 +1,5 @@ +import copy +from datetime import datetime from enum import Enum from typing import Any, Dict, Optional @@ -40,6 +42,15 @@ class Service(IOSoftware): restart_countdown: Optional[int] = None "If currently restarting, how many timesteps remain until the restart is finished." + _connections: Dict[str, Dict] = {} + "Active connections to the Service." + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + self.health_state_visible = SoftwareHealthState.UNUSED + self.health_state_actual = SoftwareHealthState.UNUSED + def _can_perform_action(self) -> bool: """ Checks if the service can perform actions. @@ -74,12 +85,6 @@ class Service(IOSoftware): """ return super().receive(payload=payload, session_id=session_id, **kwargs) - def __init__(self, **kwargs): - super().__init__(**kwargs) - - self.health_state_visible = SoftwareHealthState.UNUSED - self.health_state_actual = SoftwareHealthState.UNUSED - def set_original_state(self): """Sets the original state.""" super().set_original_state() @@ -98,6 +103,11 @@ class Service(IOSoftware): rm.add_request("enable", RequestType(func=lambda request, context: self.enable())) return rm + @property + def connections(self) -> Dict[str, Dict]: + """Return the public version of connections.""" + return copy.copy(self._connections) + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -113,6 +123,56 @@ class Service(IOSoftware): state["health_state_visible"] = self.health_state_visible.value return state + def add_connection(self, connection_id: str, session_id: Optional[str] = None) -> bool: + """ + Create a new connection to this service. + + Returns true if connection successfully created + + :param: connection_id: UUID of the connection to create + :type: string + """ + # if over or at capacity, set to overwhelmed + if len(self._connections) >= self.max_sessions: + self.health_state_actual = SoftwareHealthState.OVERWHELMED + self.sys_log.error(f"{self.name}: Connect request for {connection_id=} declined. Service is at capacity.") + return False + else: + # if service was previously overwhelmed, set to good because there is enough space for connections + if self.health_state_actual == SoftwareHealthState.OVERWHELMED: + self.health_state_actual = SoftwareHealthState.GOOD + + # check that connection already doesn't exist + if not self._connections.get(connection_id): + session_details = None + if session_id: + session_details = self._get_session_details(session_id) + self._connections[connection_id] = { + "ip_address": session_details.with_ip_address if session_details else None, + "time": datetime.now(), + } + self.sys_log.info(f"{self.name}: Connect request for {connection_id=} authorised") + return True + # connection with given id already exists + self.sys_log.error( + f"{self.name}: Connect request for {connection_id=} declined. Connection already exists." + ) + return False + + def remove_connection(self, connection_id: str) -> bool: + """ + Remove a connection from this service. + + Returns true if connection successfully removed + + :param: connection_id: UUID of the connection to create + :type: string + """ + if self._connections.get(connection_id): + self._connections.pop(connection_id) + self.sys_log.info(f"{self.name}: Connection {connection_id=} closed.") + return True + def stop(self) -> None: """Stop the service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 87802a7b..8746bdf3 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -198,7 +198,7 @@ class IOSoftware(Software): installing_count: int = 0 "The number of times the software has been installed. Default is 0." - max_sessions: int = 1 + max_sessions: int = 100 "The maximum number of sessions that the software can handle simultaneously. Default is 0." tcp: bool = True "Indicates if the software uses TCP protocol for communication. Default is True." diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index 98c8c87b..daa125ca 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -1,6 +1,9 @@ from ipaddress import IPv4Address +from typing import Tuple -from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +import pytest + +from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database.database_service import DatabaseService @@ -8,57 +11,109 @@ from primaite.simulator.system.services.ftp.ftp_server import FTPServer from primaite.simulator.system.services.service import ServiceOperatingState -def test_database_client_server_connection(uc2_network): - web_server: Server = uc2_network.get_node_by_hostname("web_server") - db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") +@pytest.fixture(scope="function") +def peer_to_peer() -> Tuple[Node, Node]: + node_a = Node(hostname="node_a", operating_state=NodeOperatingState.ON) + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON) + node_a.connect_nic(nic_a) + node_a.software_manager.get_open_ports() - db_server: Server = uc2_network.get_node_by_hostname("database_server") - db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService") + node_b = Node(hostname="node_b", operating_state=NodeOperatingState.ON) + nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") + node_b.connect_nic(nic_b) + Link(endpoint_a=nic_a, endpoint_b=nic_b) + + assert node_a.ping("192.168.0.11") + + node_a.software_manager.install(DatabaseClient) + node_a.software_manager.software["DatabaseClient"].configure(server_ip_address=IPv4Address("192.168.0.11")) + node_a.software_manager.software["DatabaseClient"].run() + + node_b.software_manager.install(DatabaseService) + database_service: DatabaseService = node_b.software_manager.software["DatabaseService"] # noqa + database_service.start() + return node_a, node_b + + +@pytest.fixture(scope="function") +def peer_to_peer_secure_db() -> Tuple[Node, Node]: + node_a = Node(hostname="node_a", operating_state=NodeOperatingState.ON) + nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON) + node_a.connect_nic(nic_a) + node_a.software_manager.get_open_ports() + + node_b = Node(hostname="node_b", operating_state=NodeOperatingState.ON) + nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") + node_b.connect_nic(nic_b) + + Link(endpoint_a=nic_a, endpoint_b=nic_b) + + assert node_a.ping("192.168.0.11") + + node_a.software_manager.install(DatabaseClient) + node_a.software_manager.software["DatabaseClient"].configure(server_ip_address=IPv4Address("192.168.0.11")) + node_a.software_manager.software["DatabaseClient"].run() + + node_b.software_manager.install(DatabaseService) + database_service: DatabaseService = node_b.software_manager.software["DatabaseService"] # noqa + database_service.password = "12345" + database_service.start() + return node_a, node_b + + +def test_database_client_server_connection(peer_to_peer): + node_a, node_b = peer_to_peer + + db_client: DatabaseClient = node_a.software_manager.software["DatabaseClient"] + + db_service: DatabaseService = node_b.software_manager.software["DatabaseService"] + + db_client.connect() + assert len(db_client.connections) == 1 assert len(db_service.connections) == 1 db_client.disconnect() + assert len(db_client.connections) == 0 assert len(db_service.connections) == 0 -def test_database_client_server_correct_password(uc2_network): - web_server: Server = uc2_network.get_node_by_hostname("web_server") - db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") +def test_database_client_server_correct_password(peer_to_peer_secure_db): + node_a, node_b = peer_to_peer_secure_db - db_server: Server = uc2_network.get_node_by_hostname("database_server") - db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService") + db_client: DatabaseClient = node_a.software_manager.software["DatabaseClient"] - db_client.disconnect() - - db_client.configure(server_ip_address=IPv4Address("192.168.1.14"), server_password="12345") - db_service.password = "12345" - - assert db_client.connect() + db_service: DatabaseService = node_b.software_manager.software["DatabaseService"] + db_client.configure(server_ip_address=IPv4Address("192.168.0.11"), server_password="12345") + db_client.connect() + assert len(db_client.connections) == 1 assert len(db_service.connections) == 1 -def test_database_client_server_incorrect_password(uc2_network): - web_server: Server = uc2_network.get_node_by_hostname("web_server") - db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") +def test_database_client_server_incorrect_password(peer_to_peer_secure_db): + node_a, node_b = peer_to_peer_secure_db - db_server: Server = uc2_network.get_node_by_hostname("database_server") - db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService") + db_client: DatabaseClient = node_a.software_manager.software["DatabaseClient"] - db_client.disconnect() - db_client.configure(server_ip_address=IPv4Address("192.168.1.14"), server_password="54321") - db_service.password = "12345" + db_service: DatabaseService = node_b.software_manager.software["DatabaseService"] - assert not db_client.connect() + # should fail + db_client.connect() + assert len(db_client.connections) == 0 + assert len(db_service.connections) == 0 + + db_client.configure(server_ip_address=IPv4Address("192.168.0.11"), server_password="wrongpass") + db_client.connect() + assert len(db_client.connections) == 0 assert len(db_service.connections) == 0 def test_database_client_query(uc2_network): """Tests DB query across the network returns HTTP status 200 and date.""" web_server: Server = uc2_network.get_node_by_hostname("web_server") - db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") - - assert db_client.connected + db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + db_client.connect() assert db_client.query("SELECT") @@ -66,13 +121,13 @@ def test_database_client_query(uc2_network): def test_create_database_backup(uc2_network): """Run the backup_database method and check if the FTP server has the relevant file.""" db_server: Server = uc2_network.get_node_by_hostname("database_server") - db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService") + db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] # back up should be created assert db_service.backup_database() is True backup_server: Server = uc2_network.get_node_by_hostname("backup_server") - ftp_server: FTPServer = backup_server.software_manager.software.get("FTPServer") + ftp_server: FTPServer = backup_server.software_manager.software["FTPServer"] # backup file should exist in the backup server assert ftp_server.file_system.get_file(folder_name=db_service.uuid, file_name="database.db") is not None @@ -81,7 +136,7 @@ def test_create_database_backup(uc2_network): def test_restore_backup(uc2_network): """Run the restore_backup method and check if the backup is properly restored.""" db_server: Server = uc2_network.get_node_by_hostname("database_server") - db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService") + db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] # create a back up assert db_service.backup_database() is True @@ -107,7 +162,7 @@ def test_database_client_cannot_query_offline_database_server(uc2_network): web_server: Server = uc2_network.get_node_by_hostname("web_server") db_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") - assert db_client.connected + assert len(db_client.connections) assert db_client.query("SELECT") is True diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_data_manipulation_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_data_manipulation_bot.py index b0ff0467..2ca67119 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_data_manipulation_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_data_manipulation_bot.py @@ -70,4 +70,4 @@ def test_dm_bot_perform_data_manipulation_success(dm_bot): dm_bot._perform_data_manipulation(p_of_success=1.0) assert dm_bot.attack_stage in (DataManipulationAttackStage.SUCCEEDED, DataManipulationAttackStage.FAILED) - assert dm_bot.connected + assert len(dm_bot.connections) diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py index 59d44561..15d28d4b 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py @@ -1,5 +1,6 @@ from ipaddress import IPv4Address from typing import Tuple, Union +from uuid import uuid4 import pytest @@ -65,15 +66,14 @@ def test_disconnect(database_client_on_computer): """Database client should set connected to False and remove the database server ip address.""" database_client, computer = database_client_on_computer - database_client.connected = True + database_client.connections[uuid4()] = {} assert database_client.operating_state is ApplicationOperatingState.RUNNING assert database_client.server_ip_address is not None database_client.disconnect() - assert database_client.connected is False - assert database_client.server_ip_address is None + assert len(database_client.connections) == 0 def test_query_when_client_is_closed(database_client_on_computer): @@ -86,19 +86,6 @@ def test_query_when_client_is_closed(database_client_on_computer): assert database_client.query(sql="test") is False -def test_query_failed_reattempt(database_client_on_computer): - """Database client query should return False if the reattempt fails.""" - database_client, computer = database_client_on_computer - - def return_false(): - return False - - database_client.connect = return_false - - database_client.connected = False - assert database_client.query(sql="test", is_reattempt=True) is False - - def test_query_fail_to_connect(database_client_on_computer): """Database client query should return False if the connect attempt fails.""" database_client, computer = database_client_on_computer From 4f79d2ad36abd5e25aca33e09577dd3669aa098b Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 12 Dec 2023 17:01:03 +0000 Subject: [PATCH 474/980] #2059: moved connection handling from Service to IOSoftware + changes that now utilise connections from IOSoftware + dos bot attacking now works + tests --- .../system/applications/database_client.py | 10 +- .../red_applications/data_manipulation_bot.py | 5 +- .../applications/red_applications/dos_bot.py | 184 ++++++++++++++++++ .../services/database/database_service.py | 7 +- .../system/services/ftp/ftp_client.py | 24 +-- .../system/services/ftp/ftp_server.py | 2 +- .../simulator/system/services/service.py | 60 ------ src/primaite/simulator/system/software.py | 63 ++++++ .../test_dos_bot_and_server.py | 107 ++++++++++ .../_red_applications/test_dos_bot.py | 90 +++++++++ .../_applications/test_database_client.py | 13 +- .../_system/_services/test_services.py | 33 ++++ 12 files changed, 510 insertions(+), 88 deletions(-) create mode 100644 src/primaite/simulator/system/applications/red_applications/dos_bot.py create mode 100644 tests/integration_tests/system/red_applications/test_dos_bot_and_server.py create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 9d7bfcaa..fbeefe6a 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -5,7 +5,7 @@ from uuid import uuid4 from primaite import getLogger from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.applications.application import Application, ApplicationOperatingState +from primaite.simulator.system.applications.application import Application from primaite.simulator.system.core.software_manager import SoftwareManager _LOGGER = getLogger(__name__) @@ -23,7 +23,6 @@ class DatabaseClient(Application): server_ip_address: Optional[IPv4Address] = None server_password: Optional[str] = None - connections: Dict[str, Dict] = {} _query_success_tracker: Dict[str, bool] = {} def __init__(self, **kwargs): @@ -143,7 +142,7 @@ class DatabaseClient(Application): dest_ip_address=self.server_ip_address, dest_port=self.port, ) - self.connections.pop(connection_id) + self.remove_connection(connection_id=connection_id) self.sys_log.info( f"{self.name}: DatabaseClient disconnected connection {connection_id} from {self.server_ip_address}" @@ -181,8 +180,6 @@ class DatabaseClient(Application): def run(self) -> None: """Run the DatabaseClient.""" super().run() - if self.operating_state == ApplicationOperatingState.RUNNING: - self.connect() def query(self, sql: str, connection_id: Optional[str] = None) -> bool: """ @@ -221,7 +218,8 @@ class DatabaseClient(Application): if isinstance(payload, dict) and payload.get("type"): if payload["type"] == "connect_response": if payload["response"] is True: - self.connections[payload.get("connection_id")] = payload + # add connection + self.add_connection(connection_id=payload.get("connection_id"), session_id=session_id) elif payload["type"] == "sql": query_id = payload.get("uuid") status_code = payload.get("status_code") diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index 87959e9b..a1429e51 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -5,7 +5,6 @@ from typing import Optional from primaite import getLogger from primaite.game.science import simulate_trial from primaite.simulator.core import RequestManager, RequestType -from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.database_client import DatabaseClient _LOGGER = getLogger(__name__) @@ -177,9 +176,9 @@ class DataManipulationBot(DatabaseClient): This is the core loop where the bot sequentially goes through the stages of the attack. """ - if self.operating_state != ApplicationOperatingState.RUNNING: + if not self._can_perform_action(): return - if self.server_ip_address and self.payload and self.operating_state: + if self.server_ip_address and self.payload: self.sys_log.info(f"{self.name}: Running") self._logon() self._perform_port_scan(p_of_success=self.port_scan_p_of_success) diff --git a/src/primaite/simulator/system/applications/red_applications/dos_bot.py b/src/primaite/simulator/system/applications/red_applications/dos_bot.py new file mode 100644 index 00000000..e6c643ee --- /dev/null +++ b/src/primaite/simulator/system/applications/red_applications/dos_bot.py @@ -0,0 +1,184 @@ +from enum import IntEnum +from ipaddress import IPv4Address +from typing import Optional + +from primaite import getLogger +from primaite.game.science import simulate_trial +from primaite.simulator.core import RequestManager, RequestType +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.applications.database_client import DatabaseClient + +_LOGGER = getLogger(__name__) + + +class DoSAttackStage(IntEnum): + """Enum representing the different stages of a Denial of Service attack.""" + + NOT_STARTED = 0 + "Attack not yet started." + + PORT_SCAN = 1 + "Attack is in discovery stage - checking if provided ip and port are open." + + ATTACKING = 2 + "Denial of Service attack is in progress." + + COMPLETED = 3 + "Attack is completed." + + +class DoSBot(DatabaseClient, Application): + """A bot that simulates a Denial of Service attack.""" + + target_ip_address: Optional[IPv4Address] = None + """IP address of the target service.""" + + target_port: Optional[Port] = None + """Port of the target service.""" + + payload: Optional[str] = None + """Payload to deliver to the target service as part of the denial of service attack.""" + + repeat: bool = False + """If true, the Denial of Service bot will keep performing the attack.""" + + attack_stage: DoSAttackStage = DoSAttackStage.NOT_STARTED + """Current stage of the DoS kill chain.""" + + port_scan_p_of_success: float = 0.1 + """Probability of port scanning being sucessful.""" + + dos_intensity: float = 0.25 + """How much of the max sessions will be used by the DoS when attacking.""" + + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.name = "DoSBot" + self.max_sessions = 1000 # override normal max sessions + + def set_original_state(self): + """Set the original state of the Denial of Service Bot.""" + _LOGGER.debug(f"Setting {self.name} original state on node {self.software_manager.node.hostname}") + super().set_original_state() + vals_to_include = { + "target_ip_address", + "target_port", + "payload", + "repeat", + "attack_stage", + "max_sessions", + "port_scan_p_of_success", + "dos_intensity", + } + self._original_state.update(self.model_dump(include=vals_to_include)) + + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + _LOGGER.debug(f"Resetting {self.name} state on node {self.software_manager.node.hostname}") + super().reset_component_for_episode(episode) + + def _init_request_manager(self) -> RequestManager: + rm = super()._init_request_manager() + + rm.add_request(name="execute", request_type=RequestType(func=lambda request, context: self.run())) + + return rm + + def configure( + self, + target_ip_address: IPv4Address, + target_port: Optional[Port] = Port.POSTGRES_SERVER, + payload: Optional[str] = None, + repeat: bool = False, + max_sessions: int = 1000, + ): + """ + Configure the Denial of Service bot. + + :param: target_ip_address: The IP address of the Node containing the target service. + :param: target_port: The port of the target service. Optional - Default is `Port.HTTP` + :param: payload: The payload the DoS Bot will throw at the target service. Optional - Default is `None` + :param: repeat: If True, the bot will maintain the attack. Optional - Default is `True` + :param: max_sessions: The maximum number of sessions the DoS bot will attack with. Optional - Default is 1000 + """ + self.target_ip_address = target_ip_address + self.target_port = target_port + self.payload = payload + self.repeat = repeat + self.max_sessions = max_sessions + self.sys_log.info( + f"{self.name}: Configured the {self.name} with {target_ip_address=}, {target_port=}, {payload=}, {repeat=}." + ) + + def run(self): + """Run the Denial of Service Bot.""" + super().run() + self._application_loop() + + def _application_loop(self): + """ + The main application loop for the Denial of Service bot. + + The loop goes through the stages of a DoS attack. + """ + if not self._can_perform_action(): + return + + # DoS bot cannot do anything without a target + if not self.target_ip_address or not self.target_port: + self.sys_log.error( + f"{self.name} is not properly configured. {self.target_ip_address=}, {self.target_port=}" + ) + return + + self.clear_connections() + self._perform_port_scan(p_of_success=self.port_scan_p_of_success) + self._perform_dos() + + if self.repeat and self.attack_stage is DoSAttackStage.ATTACKING: + self.attack_stage = DoSAttackStage.NOT_STARTED + else: + self.attack_stage = DoSAttackStage.COMPLETED + + def _perform_port_scan(self, p_of_success: Optional[float] = 0.1): + """ + Perform a simulated port scan to check for open SQL ports. + + Advances the attack stage to `PORT_SCAN` if successful. + + :param p_of_success: Probability of successful port scan, by default 0.1. + """ + if self.attack_stage == DoSAttackStage.NOT_STARTED: + # perform a port scan to identify that the SQL port is open on the server + if simulate_trial(p_of_success): + self.sys_log.info(f"{self.name}: Performing port scan") + # perform the port scan + port_is_open = True # Temporary; later we can implement NMAP port scan. + if port_is_open: + self.sys_log.info(f"{self.name}: ") + self.attack_stage = DoSAttackStage.PORT_SCAN + + def _perform_dos(self): + """ + Perform the Denial of Service attack. + + DoSBot does this by clogging up the available connections to a service. + """ + if not self.attack_stage == DoSAttackStage.PORT_SCAN: + return + self.attack_stage = DoSAttackStage.ATTACKING + self.server_ip_address = self.target_ip_address + self.port = self.target_port + + dos_sessions = int(float(self.max_sessions) * self.dos_intensity) + for i in range(dos_sessions): + self.connect() + + def apply_timestep(self, timestep: int) -> None: + """ + Apply a timestep to the bot, iterate through the application loop. + + :param timestep: The timestep value to update the bot's state. + """ + self._application_loop() diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 70a4e6cc..7d313068 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -45,7 +45,7 @@ class DatabaseService(Service): super().set_original_state() vals_to_include = { "password", - "connections", + "_connections", "backup_server", "latest_backup_directory", "latest_backup_file_name", @@ -55,7 +55,7 @@ class DatabaseService(Service): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" _LOGGER.debug("Resetting DatabaseService original state on node {self.software_manager.node.hostname}") - self.connections.clear() + self.clear_connections() super().reset_component_for_episode(episode) def configure_backup(self, backup_server: IPv4Address): @@ -225,9 +225,6 @@ class DatabaseService(Service): :param session_id: The session identifier. :return: True if the Status Code is 200, otherwise False. """ - if not super().receive(payload=payload, session_id=session_id, **kwargs): - return False - result = {"status_code": 500, "data": []} # if server service is down, return error diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 52655fa4..7faa5d32 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -20,9 +20,6 @@ class FTPClient(FTPServiceABC): RFC 959: https://datatracker.ietf.org/doc/html/rfc959 """ - connected: bool = False - """Keeps track of whether or not the FTP client is connected to an FTP server.""" - def __init__(self, **kwargs): kwargs["name"] = "FTPClient" kwargs["port"] = Port.FTP @@ -129,10 +126,7 @@ class FTPClient(FTPServiceABC): software_manager.send_payload_to_session_manager( payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port ) - if payload.status_code == FTPStatusCode.OK: - self.connected = False - return True - return False + return payload.status_code == FTPStatusCode.OK def send_file( self, @@ -179,9 +173,9 @@ class FTPClient(FTPServiceABC): return False # check if FTP is currently connected to IP - self.connected = self._connect_to_server(dest_ip_address=dest_ip_address, dest_port=dest_port) + self._connect_to_server(dest_ip_address=dest_ip_address, dest_port=dest_port) - if not self.connected: + if not len(self.connections): return False else: self.sys_log.info(f"Sending file {src_folder_name}/{src_file_name} to {str(dest_ip_address)}") @@ -230,9 +224,9 @@ class FTPClient(FTPServiceABC): :type: dest_port: Optional[Port] """ # check if FTP is currently connected to IP - self.connected = self._connect_to_server(dest_ip_address=dest_ip_address, dest_port=dest_port) + self._connect_to_server(dest_ip_address=dest_ip_address, dest_port=dest_port) - if not self.connected: + if not len(self.connections): return False else: # send retrieve request @@ -286,6 +280,14 @@ class FTPClient(FTPServiceABC): self.sys_log.error(f"FTP Server could not be found - Error Code: {FTPStatusCode.NOT_FOUND.value}") return False + # if PORT succeeded, add the connection as an active connection list + if payload.ftp_command is FTPCommand.PORT and payload.status_code is FTPStatusCode.OK: + self.add_connection(connection_id=session_id, session_id=session_id) + + # if QUIT succeeded, remove the session from active connection list + if payload.ftp_command is FTPCommand.QUIT and payload.status_code is FTPStatusCode.OK: + self.remove_connection(connection_id=session_id) + self.sys_log.info(f"{self.name}: Received FTP Response {payload.ftp_command.name} {payload.status_code.value}") self._process_ftp_command(payload=payload, session_id=session_id) diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 6e6c1a48..585690b6 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -37,7 +37,7 @@ class FTPServer(FTPServiceABC): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" _LOGGER.debug(f"Resetting FTPServer state on node {self.software_manager.node.hostname}") - self.connections.clear() + self.clear_connections() super().reset_component_for_episode(episode) def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 52187e51..3155a4bd 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,5 +1,3 @@ -import copy -from datetime import datetime from enum import Enum from typing import Any, Dict, Optional @@ -42,9 +40,6 @@ class Service(IOSoftware): restart_countdown: Optional[int] = None "If currently restarting, how many timesteps remain until the restart is finished." - _connections: Dict[str, Dict] = {} - "Active connections to the Service." - def __init__(self, **kwargs): super().__init__(**kwargs) @@ -103,11 +98,6 @@ class Service(IOSoftware): rm.add_request("enable", RequestType(func=lambda request, context: self.enable())) return rm - @property - def connections(self) -> Dict[str, Dict]: - """Return the public version of connections.""" - return copy.copy(self._connections) - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -123,56 +113,6 @@ class Service(IOSoftware): state["health_state_visible"] = self.health_state_visible.value return state - def add_connection(self, connection_id: str, session_id: Optional[str] = None) -> bool: - """ - Create a new connection to this service. - - Returns true if connection successfully created - - :param: connection_id: UUID of the connection to create - :type: string - """ - # if over or at capacity, set to overwhelmed - if len(self._connections) >= self.max_sessions: - self.health_state_actual = SoftwareHealthState.OVERWHELMED - self.sys_log.error(f"{self.name}: Connect request for {connection_id=} declined. Service is at capacity.") - return False - else: - # if service was previously overwhelmed, set to good because there is enough space for connections - if self.health_state_actual == SoftwareHealthState.OVERWHELMED: - self.health_state_actual = SoftwareHealthState.GOOD - - # check that connection already doesn't exist - if not self._connections.get(connection_id): - session_details = None - if session_id: - session_details = self._get_session_details(session_id) - self._connections[connection_id] = { - "ip_address": session_details.with_ip_address if session_details else None, - "time": datetime.now(), - } - self.sys_log.info(f"{self.name}: Connect request for {connection_id=} authorised") - return True - # connection with given id already exists - self.sys_log.error( - f"{self.name}: Connect request for {connection_id=} declined. Connection already exists." - ) - return False - - def remove_connection(self, connection_id: str) -> bool: - """ - Remove a connection from this service. - - Returns true if connection successfully removed - - :param: connection_id: UUID of the connection to create - :type: string - """ - if self._connections.get(connection_id): - self._connections.pop(connection_id) - self.sys_log.info(f"{self.name}: Connection {connection_id=} closed.") - return True - def stop(self) -> None: """Stop the service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 8746bdf3..b393ffd8 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -1,4 +1,6 @@ +import copy from abc import abstractmethod +from datetime import datetime from enum import Enum from ipaddress import IPv4Address from typing import Any, Dict, Optional @@ -206,6 +208,8 @@ class IOSoftware(Software): "Indicates if the software uses UDP protocol for communication. Default is True." port: Port "The port to which the software is connected." + _connections: Dict[str, Dict] = {} + "Active connections." def set_original_state(self): """Sets the original state.""" @@ -250,6 +254,65 @@ class IOSoftware(Software): return False return True + @property + def connections(self) -> Dict[str, Dict]: + """Return the public version of connections.""" + return copy.copy(self._connections) + + def add_connection(self, connection_id: str, session_id: Optional[str] = None) -> bool: + """ + Create a new connection to this service. + + Returns true if connection successfully created + + :param: connection_id: UUID of the connection to create + :type: string + """ + # if over or at capacity, set to overwhelmed + if len(self._connections) >= self.max_sessions: + self.health_state_actual = SoftwareHealthState.OVERWHELMED + self.sys_log.error(f"{self.name}: Connect request for {connection_id=} declined. Service is at capacity.") + return False + else: + # if service was previously overwhelmed, set to good because there is enough space for connections + if self.health_state_actual == SoftwareHealthState.OVERWHELMED: + self.health_state_actual = SoftwareHealthState.GOOD + + # check that connection already doesn't exist + if not self._connections.get(connection_id): + session_details = None + if session_id: + session_details = self._get_session_details(session_id) + self._connections[connection_id] = { + "ip_address": session_details.with_ip_address if session_details else None, + "time": datetime.now(), + } + self.sys_log.info(f"{self.name}: Connect request for {connection_id=} authorised") + return True + # connection with given id already exists + self.sys_log.error( + f"{self.name}: Connect request for {connection_id=} declined. Connection already exists." + ) + return False + + def remove_connection(self, connection_id: str) -> bool: + """ + Remove a connection from this service. + + Returns true if connection successfully removed + + :param: connection_id: UUID of the connection to create + :type: string + """ + if self.connections.get(connection_id): + self._connections.pop(connection_id) + self.sys_log.info(f"{self.name}: Connection {connection_id=} closed.") + return True + + def clear_connections(self): + """Clears all the connections from the software.""" + self._connections = {} + def send( self, payload: Any, diff --git a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py new file mode 100644 index 00000000..2828cc25 --- /dev/null +++ b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py @@ -0,0 +1,107 @@ +from ipaddress import IPv4Address +from typing import Tuple + +import pytest + +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import ApplicationOperatingState +from primaite.simulator.system.applications.red_applications.dos_bot import DoSAttackStage, DoSBot +from primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.system.software import SoftwareHealthState + + +@pytest.fixture(scope="function") +def dos_bot_and_db_server(client_server) -> Tuple[DoSBot, Computer, DatabaseService, Server]: + computer, server = client_server + + # Install DoSBot on computer + computer.software_manager.install(DoSBot) + + dos_bot: DoSBot = computer.software_manager.software.get("DoSBot") + dos_bot.configure( + target_ip_address=IPv4Address(server.nics.get(next(iter(server.nics))).ip_address), + target_port=Port.POSTGRES_SERVER, + ) + + # Install FTP Server service on server + server.software_manager.install(DatabaseService) + db_server_service: DatabaseService = server.software_manager.software.get("DatabaseService") + db_server_service.start() + + return dos_bot, computer, db_server_service, server + + +def test_repeating_dos_attack(dos_bot_and_db_server): + dos_bot, computer, db_server_service, server = dos_bot_and_db_server + + assert db_server_service.health_state_actual is SoftwareHealthState.GOOD + + dos_bot.port_scan_p_of_success = 1 + dos_bot.repeat = True + dos_bot.run() + + assert len(dos_bot.connections) == db_server_service.max_sessions + assert len(db_server_service.connections) == db_server_service.max_sessions + assert len(dos_bot.connections) == db_server_service.max_sessions + + assert dos_bot.attack_stage is DoSAttackStage.NOT_STARTED + assert db_server_service.health_state_actual is SoftwareHealthState.OVERWHELMED + + db_server_service.clear_connections() + db_server_service.health_state_actual = SoftwareHealthState.GOOD + assert len(db_server_service.connections) == 0 + + computer.apply_timestep(timestep=1) + server.apply_timestep(timestep=1) + + assert len(dos_bot.connections) == db_server_service.max_sessions + assert len(db_server_service.connections) == db_server_service.max_sessions + assert len(dos_bot.connections) == db_server_service.max_sessions + + assert dos_bot.attack_stage is DoSAttackStage.NOT_STARTED + assert db_server_service.health_state_actual is SoftwareHealthState.OVERWHELMED + + +def test_non_repeating_dos_attack(dos_bot_and_db_server): + dos_bot, computer, db_server_service, server = dos_bot_and_db_server + + assert db_server_service.health_state_actual is SoftwareHealthState.GOOD + + dos_bot.port_scan_p_of_success = 1 + dos_bot.repeat = False + dos_bot.run() + + assert len(dos_bot.connections) == db_server_service.max_sessions + assert len(db_server_service.connections) == db_server_service.max_sessions + assert len(dos_bot.connections) == db_server_service.max_sessions + + assert dos_bot.attack_stage is DoSAttackStage.COMPLETED + assert db_server_service.health_state_actual is SoftwareHealthState.OVERWHELMED + + db_server_service.clear_connections() + db_server_service.health_state_actual = SoftwareHealthState.GOOD + assert len(db_server_service.connections) == 0 + + computer.apply_timestep(timestep=1) + server.apply_timestep(timestep=1) + + assert len(dos_bot.connections) == 0 + assert len(db_server_service.connections) == 0 + assert len(dos_bot.connections) == 0 + + assert dos_bot.attack_stage is DoSAttackStage.COMPLETED + assert db_server_service.health_state_actual is SoftwareHealthState.GOOD + + +def test_dos_bot_database_service_connection(dos_bot_and_db_server): + dos_bot, computer, db_server_service, server = dos_bot_and_db_server + + dos_bot.operating_state = ApplicationOperatingState.RUNNING + dos_bot.attack_stage = DoSAttackStage.PORT_SCAN + dos_bot._perform_dos() + + assert len(dos_bot.connections) == db_server_service.max_sessions + assert len(db_server_service.connections) == db_server_service.max_sessions + assert len(dos_bot.connections) == db_server_service.max_sessions diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py new file mode 100644 index 00000000..71489171 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py @@ -0,0 +1,90 @@ +from ipaddress import IPv4Address + +import pytest + +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import ApplicationOperatingState +from primaite.simulator.system.applications.red_applications.dos_bot import DoSAttackStage, DoSBot + + +@pytest.fixture(scope="function") +def dos_bot() -> DoSBot: + computer = Computer( + hostname="compromised_pc", + ip_address="192.168.0.1", + subnet_mask="255.255.255.0", + operating_state=NodeOperatingState.ON, + ) + + computer.software_manager.install(DoSBot) + + dos_bot: DoSBot = computer.software_manager.software.get("DoSBot") + dos_bot.configure(target_ip_address=IPv4Address("192.168.0.1")) + dos_bot.set_original_state() + return dos_bot + + +def test_dos_bot_creation(dos_bot): + """Test that the DoS bot is installed on a node.""" + assert dos_bot is not None + + +def test_dos_bot_reset(dos_bot): + assert dos_bot.target_ip_address == IPv4Address("192.168.0.1") + assert dos_bot.target_port is Port.POSTGRES_SERVER + assert dos_bot.payload is None + assert dos_bot.repeat is False + + dos_bot.configure( + target_ip_address=IPv4Address("192.168.1.1"), target_port=Port.HTTP, payload="payload", repeat=True + ) + + # should reset the relevant items + dos_bot.reset_component_for_episode(episode=0) + assert dos_bot.target_ip_address == IPv4Address("192.168.0.1") + assert dos_bot.target_port is Port.POSTGRES_SERVER + assert dos_bot.payload is None + assert dos_bot.repeat is False + + dos_bot.configure( + target_ip_address=IPv4Address("192.168.1.1"), target_port=Port.HTTP, payload="payload", repeat=True + ) + dos_bot.set_original_state() + dos_bot.reset_component_for_episode(episode=1) + # should reset to the configured value + assert dos_bot.target_ip_address == IPv4Address("192.168.1.1") + assert dos_bot.target_port is Port.HTTP + assert dos_bot.payload == "payload" + assert dos_bot.repeat is True + + +def test_dos_bot_cannot_run_when_node_offline(dos_bot): + dos_bot_node: Computer = dos_bot.parent + assert dos_bot_node.operating_state is NodeOperatingState.ON + + dos_bot_node.power_off() + + for i in range(dos_bot_node.shut_down_duration + 1): + dos_bot_node.apply_timestep(timestep=i) + + assert dos_bot_node.operating_state is NodeOperatingState.OFF + + dos_bot._application_loop() + + # assert not run + assert dos_bot.attack_stage is DoSAttackStage.NOT_STARTED + + +def test_dos_bot_not_configured(dos_bot): + dos_bot.target_ip_address = None + + dos_bot.operating_state = ApplicationOperatingState.RUNNING + dos_bot._application_loop() + + +def test_dos_bot_perform_port_scan(dos_bot): + dos_bot._perform_port_scan(p_of_success=1) + + assert dos_bot.attack_stage is DoSAttackStage.PORT_SCAN diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py index 15d28d4b..204b356f 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py @@ -63,10 +63,11 @@ def test_disconnect_when_client_is_closed(database_client_on_computer): def test_disconnect(database_client_on_computer): - """Database client should set connected to False and remove the database server ip address.""" + """Database client should remove the connection.""" database_client, computer = database_client_on_computer - database_client.connections[uuid4()] = {} + database_client._connections[str(uuid4())] = {"item": True} + assert len(database_client.connections) == 1 assert database_client.operating_state is ApplicationOperatingState.RUNNING assert database_client.server_ip_address is not None @@ -75,6 +76,14 @@ def test_disconnect(database_client_on_computer): assert len(database_client.connections) == 0 + uuid = str(uuid4()) + database_client._connections[uuid] = {"item": True} + assert len(database_client.connections) == 1 + + database_client.disconnect(connection_id=uuid) + + assert len(database_client.connections) == 0 + def test_query_when_client_is_closed(database_client_on_computer): """Database client should return False when it is not running.""" diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py index b32463a2..016cf011 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py @@ -1,3 +1,5 @@ +from uuid import uuid4 + from primaite.simulator.system.services.service import ServiceOperatingState from primaite.simulator.system.software import SoftwareHealthState @@ -66,3 +68,34 @@ def test_enable_disable(service): service.enable() assert service.operating_state == ServiceOperatingState.STOPPED + + +def test_overwhelm_service(service): + service.max_sessions = 2 + service.start() + + uuid = str(uuid4()) + assert service.add_connection(connection_id=uuid) # should be true + assert service.health_state_actual is SoftwareHealthState.GOOD + + assert not service.add_connection(connection_id=uuid) # fails because connection already exists + assert service.health_state_actual is SoftwareHealthState.GOOD + + assert service.add_connection(connection_id=str(uuid4())) # succeed + assert service.health_state_actual is SoftwareHealthState.GOOD + + assert not service.add_connection(connection_id=str(uuid4())) # fail because at capacity + assert service.health_state_actual is SoftwareHealthState.OVERWHELMED + + +def test_create_and_remove_connections(service): + service.start() + uuid = str(uuid4()) + + assert service.add_connection(connection_id=uuid) # should be true + assert len(service.connections) == 1 + assert service.health_state_actual is SoftwareHealthState.GOOD + + assert service.remove_connection(connection_id=uuid) # should be true + assert len(service.connections) == 0 + assert service.health_state_actual is SoftwareHealthState.GOOD From e620771c8d5524e481f2a1d4d291076fac0dd633 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 12 Dec 2023 17:08:11 +0000 Subject: [PATCH 475/980] 2041: Remove IP address from NTP client (review comment) --- .../system/services/ntp/ntp_client.py | 16 ++++-------- .../system/services/ntp/ntp_server.py | 25 ++++++------------- .../system/test_ntp_client_server.py | 8 ++---- 3 files changed, 15 insertions(+), 34 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index f9cf29d4..e3cd21cf 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -14,8 +14,6 @@ _LOGGER = getLogger(__name__) class NTPClient(Service): """Represents a NTP client as a service.""" - ip_addr: Optional[IPv4Address] = None - "The IP address of the NTP client" ntp_server: Optional[IPv4Address] = None "The NTP server the client sends requests to." time: Optional[datetime] = None @@ -27,16 +25,15 @@ class NTPClient(Service): super().__init__(**kwargs) self.start() - def configure(self, ntp_server_ip_address: IPv4Address, ntp_client_ip_address: IPv4Address) -> None: + def configure(self, ntp_server_ip_address: IPv4Address) -> None: """ Set the IP address for the NTP server. :param ntp_server_ip_address: IPv4 address of NTP server. :param ntp_client_ip_Address: IPv4 address of NTP client. """ - self.ip_addr = ntp_client_ip_address self.ntp_server = ntp_server_ip_address - self.sys_log.info(f"{self.name}: ip_addr: {self.ip_addr}, ntp_server: {self.ntp_server}") + self.sys_log.info(f"{self.name}: ntp_server: {self.ntp_server}") def describe_state(self) -> Dict: """ @@ -78,7 +75,6 @@ class NTPClient(Service): :return: True if successful, False otherwise. """ - self.ip_addr = payload.ntp_request.ntp_client return super().send( payload=payload, dest_ip_address=dest_ip_address, @@ -99,9 +95,7 @@ class NTPClient(Service): :param session_id: The Session ID the payload is to originate from. Optional. :return: True if successful, False otherwise. """ - self.sys_log.info(f"{self.name}: Receiving NTP request from {payload.ntp_request.ntp_client}") - - if not (isinstance(payload, NTPPacket) and payload.ntp_request.ntp_client): + if not isinstance(payload, NTPPacket): _LOGGER.debug(f"{payload} is not a NTPPacket") return False if payload.ntp_reply.ntp_datetime: @@ -114,7 +108,7 @@ class NTPClient(Service): def request_time(self) -> None: """Send request to ntp_server.""" - ntp_request = NTPRequest(ntp_client=self.ip_addr) + ntp_request = NTPRequest() ntp_server_packet = NTPPacket(ntp_request=ntp_request) self.send(payload=ntp_server_packet, dest_ip_address=self.ntp_server) @@ -129,7 +123,7 @@ class NTPClient(Service): :param timestep: The current timestep number. (Amount of time since simulation episode began) :type timestep: int """ - self.sys_log.info(f"{self.name} apply_timestep: IP address: {self.ip_addr}") + self.sys_log.info(f"{self.name} apply_timestep") super().apply_timestep(timestep) if self.operating_state == ServiceOperatingState.RUNNING: # request time from server diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index 400c397f..0a66384a 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -60,23 +60,14 @@ class NTPServer(Service): :return: True if valid NTP request else False. """ - self.sys_log.info(f"{self.name} received request from {payload.ntp_request.ntp_client}") - if not (isinstance(payload, NTPPacket) and payload.ntp_request.ntp_client): + if not (isinstance(payload, NTPPacket)): _LOGGER.debug(f"{payload} is not a NTPPacket") return False payload: NTPPacket = payload - if payload.ntp_request.ntp_client: - self.sys_log.info( - f"{self.name}: Received request for {payload.ntp_request.ntp_client} \ - from session {session_id}" - ) - # generate a reply with the current time - time = datetime.now() - payload = payload.generate_reply(time) - self.sys_log.info( - f"{self.name}: Responding to NTP request for {payload.ntp_request.ntp_client} " - f"with current time: {time}" - ) - # send reply - self.send(payload, session_id) - return True + + # generate a reply with the current time + time = datetime.now() + payload = payload.generate_reply(time) + # send reply + self.send(payload, session_id) + return True diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index 97b2fe30..c30fd5bc 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -51,9 +51,7 @@ def test_ntp_client_server(create_ntp_network): assert ntp_server.operating_state == ServiceOperatingState.RUNNING assert ntp_client.operating_state == ServiceOperatingState.RUNNING - ntp_client.configure( - ntp_server_ip_address=IPv4Address("192.168.0.2"), ntp_client_ip_address=IPv4Address("192.168.0.1") - ) + ntp_client.configure(ntp_server_ip_address=IPv4Address("192.168.0.2")) assert ntp_client.time is None ntp_client.request_time() @@ -74,9 +72,7 @@ def test_ntp_server_failure(create_ntp_network): assert ntp_client.operating_state == ServiceOperatingState.RUNNING assert ntp_client.operating_state == ServiceOperatingState.RUNNING - ntp_client.configure( - ntp_server_ip_address=IPv4Address("192.168.0.2"), ntp_client_ip_address=IPv4Address("192.168.0.1") - ) + ntp_client.configure(ntp_server_ip_address=IPv4Address("192.168.0.2")) # Turn off ntp server. ntp_server.stop() From f0be77c79b6f2118489b972fcd443d934b650129 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 12 Dec 2023 17:20:31 +0000 Subject: [PATCH 476/980] #2059: configure missing configurable items --- .../system/applications/red_applications/dos_bot.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/system/applications/red_applications/dos_bot.py b/src/primaite/simulator/system/applications/red_applications/dos_bot.py index e6c643ee..84e0abb2 100644 --- a/src/primaite/simulator/system/applications/red_applications/dos_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/dos_bot.py @@ -49,7 +49,7 @@ class DoSBot(DatabaseClient, Application): port_scan_p_of_success: float = 0.1 """Probability of port scanning being sucessful.""" - dos_intensity: float = 0.25 + dos_intensity: float = 1 """How much of the max sessions will be used by the DoS when attacking.""" def __init__(self, **kwargs): @@ -91,6 +91,8 @@ class DoSBot(DatabaseClient, Application): target_port: Optional[Port] = Port.POSTGRES_SERVER, payload: Optional[str] = None, repeat: bool = False, + port_scan_p_of_success: float = 0.1, + dos_intensity: float = 1, max_sessions: int = 1000, ): """ @@ -100,15 +102,21 @@ class DoSBot(DatabaseClient, Application): :param: target_port: The port of the target service. Optional - Default is `Port.HTTP` :param: payload: The payload the DoS Bot will throw at the target service. Optional - Default is `None` :param: repeat: If True, the bot will maintain the attack. Optional - Default is `True` + :param: port_scan_p_of_success: The chance of the port scan being sucessful. Optional - Default is 0.1 (10%) + :param: dos_intensity: The intensity of the DoS attack. + Multiplied with the application's max session - Default is 1.0 :param: max_sessions: The maximum number of sessions the DoS bot will attack with. Optional - Default is 1000 """ self.target_ip_address = target_ip_address self.target_port = target_port self.payload = payload self.repeat = repeat + self.port_scan_p_of_success = port_scan_p_of_success + self.dos_intensity = dos_intensity self.max_sessions = max_sessions self.sys_log.info( - f"{self.name}: Configured the {self.name} with {target_ip_address=}, {target_port=}, {payload=}, {repeat=}." + f"{self.name}: Configured the {self.name} with {target_ip_address=}, {target_port=}, {payload=}, " + f"{repeat=}, {port_scan_p_of_success=}, {dos_intensity=}, {max_sessions=}." ) def run(self): From f7b5c8ae2fda6cd7311bb4052bdfd515f6402e4f Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 13 Dec 2023 10:34:52 +0000 Subject: [PATCH 477/980] 2041: Remove NTPRequest class (review comment) --- src/primaite/simulator/network/protocols/ntp.py | 9 --------- src/primaite/simulator/system/services/ntp/ntp_client.py | 6 +++--- tests/integration_tests/system/test_ntp_client_server.py | 2 +- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/primaite/simulator/network/protocols/ntp.py b/src/primaite/simulator/network/protocols/ntp.py index df5ce0c1..55353265 100644 --- a/src/primaite/simulator/network/protocols/ntp.py +++ b/src/primaite/simulator/network/protocols/ntp.py @@ -1,7 +1,6 @@ from __future__ import annotations from datetime import datetime -from ipaddress import IPv4Address from typing import Optional from pydantic import BaseModel @@ -9,12 +8,6 @@ from pydantic import BaseModel from primaite.simulator.network.protocols.packet import DataPacket -class NTPRequest(BaseModel): - """Represents a NTP Request packet.""" - - ntp_client: Optional[IPv4Address] = None - - class NTPReply(BaseModel): """Represents a NTP Reply packet.""" @@ -30,8 +23,6 @@ class NTPPacket(DataPacket): :param ntp_reply: NTPReply packet from NTP Server. """ - ntp_request: NTPRequest - "NTP Request packet sent by NTP Client." ntp_reply: Optional[NTPReply] = None def generate_reply(self, ntp_server_time: datetime) -> NTPPacket: diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index e3cd21cf..e8c3d0cb 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -3,7 +3,7 @@ from ipaddress import IPv4Address from typing import Dict, Optional from primaite import getLogger -from primaite.simulator.network.protocols.ntp import NTPPacket, NTPRequest +from primaite.simulator.network.protocols.ntp import NTPPacket from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.service import Service, ServiceOperatingState @@ -108,8 +108,8 @@ class NTPClient(Service): def request_time(self) -> None: """Send request to ntp_server.""" - ntp_request = NTPRequest() - ntp_server_packet = NTPPacket(ntp_request=ntp_request) + ntp_server_packet = NTPPacket() + self.send(payload=ntp_server_packet, dest_ip_address=self.ntp_server) def apply_timestep(self, timestep: int) -> None: diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index c30fd5bc..d58e3372 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -7,7 +7,7 @@ import pytest from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.protocols.ntp import NTPPacket, NTPRequest +from primaite.simulator.network.protocols.ntp import NTPPacket from primaite.simulator.system.services.ntp.ntp_client import NTPClient from primaite.simulator.system.services.ntp.ntp_server import NTPServer from primaite.simulator.system.services.service import ServiceOperatingState From 592e1a3610c2849e8873a9e372a6774ef9b95df7 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 13 Dec 2023 11:56:25 +0000 Subject: [PATCH 478/980] #2059: apply suggestions from PR + adding another test that checks for dos affecting green agent --- .../applications/red_applications/dos_bot.py | 4 +- .../services/database/database_service.py | 4 + .../simulator/system/services/service.py | 2 +- .../test_dos_bot_and_server.py | 75 ++++++++++++++++++- 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/primaite/simulator/system/applications/red_applications/dos_bot.py b/src/primaite/simulator/system/applications/red_applications/dos_bot.py index 84e0abb2..dfc48dd3 100644 --- a/src/primaite/simulator/system/applications/red_applications/dos_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/dos_bot.py @@ -49,7 +49,7 @@ class DoSBot(DatabaseClient, Application): port_scan_p_of_success: float = 0.1 """Probability of port scanning being sucessful.""" - dos_intensity: float = 1 + dos_intensity: float = 1.0 """How much of the max sessions will be used by the DoS when attacking.""" def __init__(self, **kwargs): @@ -92,7 +92,7 @@ class DoSBot(DatabaseClient, Application): payload: Optional[str] = None, repeat: bool = False, port_scan_p_of_success: float = 0.1, - dos_intensity: float = 1, + dos_intensity: float = 1.0, max_sessions: int = 1000, ): """ diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 7d313068..6f333091 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -143,6 +143,10 @@ class DatabaseService(Service): status_code = 500 # Default internal server error if self.operating_state == ServiceOperatingState.RUNNING: status_code = 503 # service unavailable + if self.health_state_actual == SoftwareHealthState.OVERWHELMED: + self.sys_log.error( + f"{self.name}: Connect request for {connection_id=} declined. Service is at capacity." + ) if self.health_state_actual == SoftwareHealthState.GOOD: if self.password == password: status_code = 200 # ok diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 3155a4bd..d45ef3a6 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -58,7 +58,7 @@ class Service(IOSoftware): if not super()._can_perform_action(): return False - if self.operating_state is not self.operating_state.RUNNING: + if self.operating_state is not ServiceOperatingState.RUNNING: # service is not running _LOGGER.error(f"Cannot perform action: {self.name} is {self.operating_state.name}") return False diff --git a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py index 2828cc25..85028d75 100644 --- a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py +++ b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py @@ -3,10 +3,13 @@ from typing import Tuple import pytest +from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import ApplicationOperatingState +from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.red_applications.dos_bot import DoSAttackStage, DoSBot from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.software import SoftwareHealthState @@ -25,7 +28,7 @@ def dos_bot_and_db_server(client_server) -> Tuple[DoSBot, Computer, DatabaseServ target_port=Port.POSTGRES_SERVER, ) - # Install FTP Server service on server + # Install DB Server service on server server.software_manager.install(DatabaseService) db_server_service: DatabaseService = server.software_manager.software.get("DatabaseService") db_server_service.start() @@ -33,6 +36,43 @@ def dos_bot_and_db_server(client_server) -> Tuple[DoSBot, Computer, DatabaseServ return dos_bot, computer, db_server_service, server +@pytest.fixture(scope="function") +def dos_bot_db_server_green_client(example_network) -> Network: + network: Network = example_network + + router_1: Router = example_network.get_node_by_hostname("router_1") + router_1.acl.add_rule( + action=ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER, position=0 + ) + + client_1: Computer = network.get_node_by_hostname("client_1") + client_2: Computer = network.get_node_by_hostname("client_2") + server: Server = network.get_node_by_hostname("server_1") + + # install DoS bot on client 1 + client_1.software_manager.install(DoSBot) + + dos_bot: DoSBot = client_1.software_manager.software.get("DoSBot") + dos_bot.configure( + target_ip_address=IPv4Address(server.nics.get(next(iter(server.nics))).ip_address), + target_port=Port.POSTGRES_SERVER, + ) + + # install db server service on server + server.software_manager.install(DatabaseService) + db_server_service: DatabaseService = server.software_manager.software.get("DatabaseService") + db_server_service.start() + + # Install DB client (green) on client 2 + client_2.software_manager.install(DatabaseClient) + + database_client: DatabaseClient = client_2.software_manager.software.get("DatabaseClient") + database_client.configure(server_ip_address=IPv4Address("192.168.0.1")) + database_client.run() + + return network + + def test_repeating_dos_attack(dos_bot_and_db_server): dos_bot, computer, db_server_service, server = dos_bot_and_db_server @@ -105,3 +145,36 @@ def test_dos_bot_database_service_connection(dos_bot_and_db_server): assert len(dos_bot.connections) == db_server_service.max_sessions assert len(db_server_service.connections) == db_server_service.max_sessions assert len(dos_bot.connections) == db_server_service.max_sessions + + +def test_dos_blocks_green_agent_connection(dos_bot_db_server_green_client): + network: Network = dos_bot_db_server_green_client + + client_1: Computer = network.get_node_by_hostname("client_1") + dos_bot: DoSBot = client_1.software_manager.software.get("DoSBot") + + client_2: Computer = network.get_node_by_hostname("client_2") + green_db_client: DatabaseClient = client_2.software_manager.software.get("DatabaseClient") + + server: Server = network.get_node_by_hostname("server_1") + db_server_service: DatabaseService = server.software_manager.software.get("DatabaseService") + + assert db_server_service.health_state_actual is SoftwareHealthState.GOOD + + dos_bot.port_scan_p_of_success = 1 + dos_bot.repeat = False + dos_bot.run() + + # DoS bot fills up connection of db server service + assert len(dos_bot.connections) == db_server_service.max_sessions + assert len(db_server_service.connections) == db_server_service.max_sessions + assert len(dos_bot.connections) == db_server_service.max_sessions + assert len(green_db_client.connections) == 0 + + assert dos_bot.attack_stage is DoSAttackStage.COMPLETED + # db server service is overwhelmed + assert db_server_service.health_state_actual is SoftwareHealthState.OVERWHELMED + + # green agent tries to connect but fails because service is overwhelmed + assert green_db_client.connect() is False + assert len(green_db_client.connections) == 0 From 1ec7df11701949cfe408d0b766b45227d36fa199 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 14 Dec 2023 11:19:32 +0000 Subject: [PATCH 479/980] Change describe_state to use names instead of uuids --- src/primaite/simulator/domain/controller.py | 2 +- src/primaite/simulator/network/container.py | 18 ++++++++++++++++-- .../simulator/network/hardware/base.py | 19 ++++++++++++------- .../network/hardware/nodes/switch.py | 1 + .../simulator/system/processes/process.py | 2 +- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index e9f3b26d..bc428743 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -102,7 +102,7 @@ class DomainController(SimComponent): :rtype: Dict """ state = super().describe_state() - state.update({"accounts": {uuid: acct.describe_state() for uuid, acct in self.accounts.items()}}) + state.update({"accounts": {acct.username: acct.describe_state() for acct in self.accounts.values()}}) return state def _register_account(self, account: Account) -> None: diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index e1780448..8d8709d3 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -199,10 +199,24 @@ class Network(SimComponent): state = super().describe_state() state.update( { - "nodes": {uuid: node.describe_state() for uuid, node in self.nodes.items()}, - "links": {uuid: link.describe_state() for uuid, link in self.links.items()}, + "nodes": {node.hostname: node.describe_state() for node in self.nodes.values()}, + "links": {}, } ) + # Update the links one-by-one. The key is a 4-tuple of `hostname_a, port_a, hostname_b, port_b` + for uuid, link in self.links.items(): + node_a = link.endpoint_a._connected_node + node_b = link.endpoint_b._connected_node + hostname_a = node_a.hostname if node_a else None + hostname_b = node_b.hostname if node_b else None + port_a = link.endpoint_a._port_num_on_node + port_b = link.endpoint_b._port_num_on_node + state["links"][uuid] = link.describe_state() + state["links"][uuid]["hostname_a"] = hostname_a + state["links"][uuid]["hostname_b"] = hostname_b + state["links"][uuid]["port_a"] = port_a + state["links"][uuid]["port_b"] = port_b + return state def add_node(self, node: Node) -> None: diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index a310a3f5..ad3d73aa 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -91,6 +91,8 @@ class NIC(SimComponent): "Indicates if the NIC supports Wake-on-LAN functionality." _connected_node: Optional[Node] = None "The Node to which the NIC is connected." + _port_num_on_node: Optional[int] = None + "Which port number is assigned on this NIC" _connected_link: Optional[Link] = None "The Link to which the NIC is connected." enabled: bool = False @@ -148,7 +150,7 @@ class NIC(SimComponent): state = super().describe_state() state.update( { - "ip_adress": str(self.ip_address), + "ip_address": str(self.ip_address), "subnet_mask": str(self.subnet_mask), "mac_address": self.mac_address, "speed": self.speed, @@ -311,6 +313,8 @@ class SwitchPort(SimComponent): "The Maximum Transmission Unit (MTU) of the SwitchPort in Bytes. Default is 1500 B" _connected_node: Optional[Node] = None "The Node to which the SwitchPort is connected." + _port_num_on_node: Optional[int] = None + "The port num on the connected node." _connected_link: Optional[Link] = None "The Link to which the SwitchPort is connected." enabled: bool = False @@ -497,8 +501,8 @@ class Link(SimComponent): state = super().describe_state() state.update( { - "endpoint_a": self.endpoint_a.uuid, - "endpoint_b": self.endpoint_b.uuid, + "endpoint_a": self.endpoint_a.uuid, # TODO: consider if using UUID is the best way to do this + "endpoint_b": self.endpoint_b.uuid, # TODO: consider if using UUID is the best way to do this "bandwidth": self.bandwidth, "current_load": self.current_load, } @@ -1094,12 +1098,12 @@ class Node(SimComponent): { "hostname": self.hostname, "operating_state": self.operating_state.value, - "NICs": {uuid: nic.describe_state() for uuid, nic in self.nics.items()}, + "NICs": {eth_num: nic.describe_state() for eth_num, nic in self.ethernet_port.items()}, # "switch_ports": {uuid, sp for uuid, sp in self.switch_ports.items()}, "file_system": self.file_system.describe_state(), - "applications": {uuid: app.describe_state() for uuid, app in self.applications.items()}, - "services": {uuid: svc.describe_state() for uuid, svc in self.services.items()}, - "process": {uuid: proc.describe_state() for uuid, proc in self.processes.items()}, + "applications": {app.name: app.describe_state() for app in self.applications.values()}, + "services": {svc.name: svc.describe_state() for svc in self.services.values()}, + "process": {proc.name: proc.describe_state() for proc in self.processes.values()}, "revealed_to_red": self.revealed_to_red, } ) @@ -1316,6 +1320,7 @@ class Node(SimComponent): self.nics[nic.uuid] = nic self.ethernet_port[len(self.nics)] = nic nic._connected_node = self + nic._port_num_on_node = len(self.nics) nic.parent = self self.sys_log.info(f"Connected NIC {nic}") if self.operating_state == NodeOperatingState.ON: diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/switch.py index 92999b88..fffae6e2 100644 --- a/src/primaite/simulator/network/hardware/nodes/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/switch.py @@ -30,6 +30,7 @@ class Switch(Node): self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)} for port_num, port in self.switch_ports.items(): port._connected_node = self + port._port_num_on_node = port_num port.parent = self port.port_num = port_num diff --git a/src/primaite/simulator/system/processes/process.py b/src/primaite/simulator/system/processes/process.py index ad9af335..b753e3ad 100644 --- a/src/primaite/simulator/system/processes/process.py +++ b/src/primaite/simulator/system/processes/process.py @@ -41,5 +41,5 @@ class Process(Software): :rtype: Dict """ state = super().describe_state() - state.update({"operating_state": self.operating_state.name}) + state.update({"operating_state": self.operating_state.value}) return state From 6a80f4cc77d287892780b4d074c432989a8a0970 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 14 Dec 2023 14:04:43 +0000 Subject: [PATCH 480/980] Make game layer work with new state api --- .gitignore | 1 + .../config/_package_data/example_config.yaml | 28 ++++---- src/primaite/game/agent/observations.py | 46 ++++++------ src/primaite/game/agent/rewards.py | 71 ++++++------------- .../assets/configs/bad_primaite_session.yaml | 28 ++++---- .../configs/eval_only_primaite_session.yaml | 35 ++++----- tests/assets/configs/multi_agent_session.yaml | 63 ++++++++-------- .../assets/configs/test_primaite_session.yaml | 37 ++++------ .../configs/train_only_primaite_session.yaml | 30 ++++---- .../game_layer/test_observations.py | 2 +- 10 files changed, 145 insertions(+), 196 deletions(-) diff --git a/.gitignore b/.gitignore index 892751d9..8be60770 100644 --- a/.gitignore +++ b/.gitignore @@ -156,3 +156,4 @@ benchmark/output # src/primaite/notebooks/scratch.ipynb src/primaite/notebooks/scratch.py sandbox.py +sandbox.ipynb diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 24f9945d..db0bca74 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -105,25 +105,25 @@ agents: num_files_per_folder: 1 num_nics_per_node: 2 nodes: - - node_ref: domain_controller + - node_hostname: domain_controller services: - - service_ref: domain_controller_dns_server - - node_ref: web_server + - service_name: DNSServer + - node_hostname: web_server services: - - service_ref: web_server_database_client - - node_ref: database_server + - service_name: web_server_database_client + - node_hostname: database_server services: - - service_ref: database_service + - service_name: database_service folders: - folder_name: database files: - file_name: database.db - - node_ref: backup_server + - node_hostname: backup_server # services: # - service_ref: backup_service - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 links: - link_ref: router_1___switch_1 - link_ref: router_1___switch_2 @@ -138,7 +138,7 @@ agents: acl: options: max_acl_rules: 10 - router_node_ref: router_1 + router_hostname: router_1 ip_address_order: - node_ref: domain_controller nic_num: 1 @@ -509,7 +509,7 @@ agents: - type: DATABASE_FILE_INTEGRITY weight: 0.5 options: - node_ref: database_server + node_hostname: database_server folder_name: database file_name: database.db @@ -517,8 +517,8 @@ agents: - type: WEB_SERVER_404_PENALTY weight: 0.5 options: - node_ref: web_server - service_ref: web_server_web_service + node_hostname: web_server + service_name: web_server_web_service agent_settings: diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 767514b4..ac091b77 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -40,8 +40,7 @@ class AbstractObservation(ABC): def from_config(cls, config: Dict, game: "PrimaiteGame"): """Create this observation space component form a serialised format. - The `game` parameter is for a the PrimaiteGame object that spawns this component. During deserialisation, - a subclass of this class may need to translate from a 'reference' to a UUID. + The `game` parameter is for a the PrimaiteGame object that spawns this component. """ pass @@ -53,12 +52,12 @@ class FileObservation(AbstractObservation): """ Initialise file observation. - :param where: Store information about where in the simulation state dictionary to find the relevatn information. + :param where: Store information about where in the simulation state dictionary to find the relevant information. Optional. If None, this corresponds that the file does not exist and the observation will be populated with zeroes. A typical location for a file looks like this: - ['network','nodes',,'file_system', 'folders',,'files',] + ['network','nodes',,'file_system', 'folders',,'files',] :type where: Optional[List[str]] """ super().__init__() @@ -120,7 +119,7 @@ class ServiceObservation(AbstractObservation): zeroes. A typical location for a service looks like this: - `['network','nodes',,'services', ]` + `['network','nodes',,'services', ]` :type where: Optional[List[str]] """ super().__init__() @@ -162,7 +161,7 @@ class ServiceObservation(AbstractObservation): :return: Constructed service observation :rtype: ServiceObservation """ - return cls(where=parent_where + ["services", game.ref_map_services[config["service_ref"]]]) + return cls(where=parent_where + ["services", config["service_name"]]) class LinkObservation(AbstractObservation): @@ -179,7 +178,7 @@ class LinkObservation(AbstractObservation): zeroes. A typical location for a service looks like this: - `['network','nodes',,'servics', ]` + `['network','nodes',,'servics', ]` :type where: Optional[List[str]] """ super().__init__() @@ -242,7 +241,7 @@ class FolderObservation(AbstractObservation): :param where: Where in the simulation state dictionary to find the relevant information for this folder. A typical location for a file looks like this: - ['network','nodes',,'file_system', 'folders',] + ['network','nodes',,'file_system', 'folders',] :type where: Optional[List[str]] :param max_files: As size of the space must remain static, define max files that can be in this folder , defaults to 5 @@ -321,7 +320,7 @@ class FolderObservation(AbstractObservation): :type game: PrimaiteGame :param parent_where: Where in the simulation state dictionary to find the information about this folder's parent node. A typical location for a node ``where`` can be: - ['network','nodes',,'file_system'] + ['network','nodes',,'file_system'] :type parent_where: Optional[List[str]] :param num_files_per_folder: How many spaces for files are in this folder observation (to preserve static observation size) , defaults to 2 @@ -347,7 +346,7 @@ class NicObservation(AbstractObservation): :param where: Where in the simulation state dictionary to find the relevant information for this NIC. A typical example may look like this: - ['network','nodes',,'NICs',] + ['network','nodes',,'NICs',] If None, this denotes that the NIC does not exist and the observation will be populated with zeroes. :type where: Optional[Tuple[str]], optional """ @@ -384,12 +383,12 @@ class NicObservation(AbstractObservation): :param game: Reference to the PrimaiteGame object that spawned this observation. :type game: PrimaiteGame :param parent_where: Where in the simulation state dictionary to find the information about this NIC's parent - node. A typical location for a node ``where`` can be: ['network','nodes',] + node. A typical location for a node ``where`` can be: ['network','nodes',] :type parent_where: Optional[List[str]] :return: Constructed NIC observation :rtype: NicObservation """ - return cls(where=parent_where + ["NICs", config["nic_uuid"]]) + return cls(where=parent_where + ["NICs", config["nic_num"]]) class NodeObservation(AbstractObservation): @@ -412,9 +411,9 @@ class NodeObservation(AbstractObservation): :param where: Where in the simulation state dictionary for find relevant information for this observation. A typical location for a node looks like this: - ['network','nodes',]. If empty list, a default null observation will be output, defaults to [] + ['network','nodes',]. If empty list, a default null observation will be output, defaults to [] :type where: List[str], optional - :param services: Mapping between position in observation space and service UUID, defaults to {} + :param services: Mapping between position in observation space and service name, defaults to {} :type services: Dict[int,str], optional :param max_services: Max number of services that can be presented in observation space for this node , defaults to 2 @@ -423,7 +422,7 @@ class NodeObservation(AbstractObservation): :type folders: Dict[int,str], optional :param max_folders: Max number of folders in this node's obs space, defaults to 2 :type max_folders: int, optional - :param nics: Mapping between position in observation space and NIC UUID, defaults to {} + :param nics: Mapping between position in observation space and NIC idx, defaults to {} :type nics: Dict[int,str], optional :param max_nics: Max number of NICS in this node's obs space, defaults to 5 :type max_nics: int, optional @@ -541,11 +540,11 @@ class NodeObservation(AbstractObservation): :return: Constructed node observation :rtype: NodeObservation """ - node_uuid = game.ref_map_nodes[config["node_ref"]] + node_hostname = config["node_hostname"] if parent_where is None: - where = ["network", "nodes", node_uuid] + where = ["network", "nodes", node_hostname] else: - where = parent_where + ["nodes", node_uuid] + where = parent_where + ["nodes", node_hostname] svc_configs = config.get("services", {}) services = [ServiceObservation.from_config(config=c, game=game, parent_where=where) for c in svc_configs] @@ -556,8 +555,8 @@ class NodeObservation(AbstractObservation): ) for c in folder_configs ] - nic_uuids = game.simulation.network.nodes[node_uuid].nics.keys() - nic_configs = [{"nic_uuid": n for n in nic_uuids}] if nic_uuids else [] + # create some configs for the NIC observation in the format {"nic_num":1}, {"nic_num":2}, {"nic_num":3}, etc. + nic_configs = [{"nic_num": i for i in range(num_nics_per_node)}] nics = [NicObservation.from_config(config=c, game=game, parent_where=where) for c in nic_configs] logon_status = config.get("logon_status", False) return cls( @@ -598,7 +597,7 @@ class AclObservation(AbstractObservation): :type protocols: list[str] :param where: Where in the simulation state dictionary to find the relevant information for this ACL. A typical example may look like this: - ['network','nodes',,'acl','acl'] + ['network','nodes',,'acl','acl'] :type where: Optional[Tuple[str]], optional :param num_rules: , defaults to 10 :type num_rules: int, optional @@ -711,12 +710,12 @@ class AclObservation(AbstractObservation): nic_obj = node_obj.ethernet_port[nic_num] node_ip_to_idx[nic_obj.ip_address] = ip_idx + 2 - router_uuid = game.ref_map_nodes[config["router_node_ref"]] + router_hostname = config["router_hostname"] return cls( node_ip_to_id=node_ip_to_idx, ports=game.options.ports, protocols=game.options.protocols, - where=["network", "nodes", router_uuid, "acl", "acl"], + where=["network", "nodes", router_hostname, "acl", "acl"], num_rules=max_acl_rules, ) @@ -846,6 +845,7 @@ class UC2BlueObservation(AbstractObservation): :rtype: UC2BlueObservation """ node_configs = config["nodes"] + num_services_per_node = config["num_services_per_node"] num_folders_per_node = config["num_folders_per_node"] num_files_per_folder = config["num_files_per_folder"] diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 9b3dfb80..e2c7d6fc 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -82,11 +82,11 @@ class DummyReward(AbstractReward): class DatabaseFileIntegrity(AbstractReward): """Reward function component which rewards the agent for maintaining the integrity of a database file.""" - def __init__(self, node_uuid: str, folder_name: str, file_name: str) -> None: + def __init__(self, node_hostname: str, folder_name: str, file_name: str) -> None: """Initialise the reward component. - :param node_uuid: UUID of the node which contains the database file. - :type node_uuid: str + :param node_hostname: Hostname of the node which contains the database file. + :type node_hostname: str :param folder_name: folder which contains the database file. :type folder_name: str :param file_name: name of the database file. @@ -95,7 +95,7 @@ class DatabaseFileIntegrity(AbstractReward): self.location_in_state = [ "network", "nodes", - node_uuid, + node_hostname, "file_system", "folders", folder_name, @@ -129,49 +129,29 @@ class DatabaseFileIntegrity(AbstractReward): :return: The reward component. :rtype: DatabaseFileIntegrity """ - node_ref = config.get("node_ref") + node_hostname = config.get("node_hostname") folder_name = config.get("folder_name") file_name = config.get("file_name") - if not node_ref: - _LOGGER.error( - f"{cls.__name__} could not be initialised from config because node_ref parameter was not specified" - ) - return DummyReward() # TODO: better error handling - if not folder_name: - _LOGGER.error( - f"{cls.__name__} could not be initialised from config because folder_name parameter was not specified" - ) - return DummyReward() # TODO: better error handling - if not file_name: - _LOGGER.error( - f"{cls.__name__} could not be initialised from config because file_name parameter was not specified" - ) - return DummyReward() # TODO: better error handling - node_uuid = game.ref_map_nodes[node_ref] - if not node_uuid: - _LOGGER.error( - ( - f"{cls.__name__} could not be initialised from config because the referenced node could not be " - f"found in the simulation" - ) - ) - return DummyReward() # TODO: better error handling + if not node_hostname and folder_name and file_name: + msg = f"{cls.__name__} could not be initialised with parameters {config}" + _LOGGER.error(msg) + raise ValueError(msg) - return cls(node_uuid=node_uuid, folder_name=folder_name, file_name=file_name) + return cls(node_hostname=node_hostname, folder_name=folder_name, file_name=file_name) class WebServer404Penalty(AbstractReward): """Reward function component which penalises the agent when the web server returns a 404 error.""" - def __init__(self, node_uuid: str, service_uuid: str) -> None: + def __init__(self, node_hostname: str, service_name: str) -> None: """Initialise the reward component. - :param node_uuid: UUID of the node which contains the web server service. - :type node_uuid: str - :param service_uuid: UUID of the web server service. - :type service_uuid: str + :param node_hostname: Hostname of the node which contains the web server service. + :type node_hostname: str + :param service_node: Name of the web server service. + :type service_node: str """ - self.location_in_state = ["network", "nodes", node_uuid, "services", service_uuid] + self.location_in_state = ["network", "nodes", node_hostname, "services", service_name] def calculate(self, state: Dict) -> float: """Calculate the reward for the current state. @@ -203,26 +183,17 @@ class WebServer404Penalty(AbstractReward): :return: The reward component. :rtype: WebServer404Penalty """ - node_ref = config.get("node_ref") - service_ref = config.get("service_ref") - if not (node_ref and service_ref): + node_hostname = config.get("node_hostname") + service_name = config.get("service_name") + if not (node_hostname and service_name): msg = ( f"{cls.__name__} could not be initialised from config because node_ref and service_ref were not " "found in reward config." ) _LOGGER.warning(msg) - return DummyReward() # TODO: should we error out with incorrect inputs? Probably! - node_uuid = game.ref_map_nodes[node_ref] - service_uuid = game.ref_map_services[service_ref] - if not (node_uuid and service_uuid): - msg = ( - f"{cls.__name__} could not be initialised because node {node_ref} and service {service_ref} were not" - " found in the simulator." - ) - _LOGGER.warning(msg) - return DummyReward() # TODO: consider erroring here as well + raise ValueError(msg) - return cls(node_uuid=node_uuid, service_uuid=service_uuid) + return cls(node_hostname=node_hostname, service_name=service_name) class RewardFunction: diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 9070f246..478cbfae 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -93,25 +93,25 @@ agents: num_files_per_folder: 1 num_nics_per_node: 2 nodes: - - node_ref: domain_controller + - node_hostname: domain_controller services: - - service_ref: domain_controller_dns_server - - node_ref: web_server + - service_name: domain_controller_dns_server + - node_hostname: web_server services: - - service_ref: web_server_database_client - - node_ref: database_server + - service_name: web_server_database_client + - node_hostname: database_server services: - - service_ref: database_service + - service_name: database_service folders: - folder_name: database files: - file_name: database.db - - node_ref: backup_server + - node_hostname: backup_server # services: # - service_ref: backup_service - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 links: - link_ref: router_1___switch_1 - link_ref: router_1___switch_2 @@ -126,7 +126,7 @@ agents: acl: options: max_acl_rules: 10 - router_node_ref: router_1 + router_hostname: router_1 ip_address_order: - node_ref: domain_controller nic_num: 1 @@ -497,7 +497,7 @@ agents: - type: DATABASE_FILE_INTEGRITY weight: 0.5 options: - node_ref: database_server + node_hostname: database_server folder_name: database file_name: database.db @@ -505,8 +505,8 @@ agents: - type: WEB_SERVER_404_PENALTY weight: 0.5 options: - node_ref: web_server - service_ref: web_server_web_service + node_hostname: web_server + service_name: web_server_web_service agent_settings: diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index e67f6606..ec6bfb63 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -31,13 +31,6 @@ agents: action_space: action_list: - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com options: nodes: @@ -104,25 +97,25 @@ agents: num_files_per_folder: 1 num_nics_per_node: 2 nodes: - - node_ref: domain_controller + - node_hostname: domain_controller services: - - service_ref: domain_controller_dns_server - - node_ref: web_server + - service_name: domain_controller_dns_server + - node_hostname: web_server services: - - service_ref: web_server_database_client - - node_ref: database_server + - service_name: web_server_database_client + - node_hostname: database_server services: - - service_ref: database_service + - service_name: database_service folders: - folder_name: database files: - file_name: database.db - - node_ref: backup_server + - node_hostname: backup_server # services: # - service_ref: backup_service - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 links: - link_ref: router_1___switch_1 - link_ref: router_1___switch_2 @@ -137,7 +130,7 @@ agents: acl: options: max_acl_rules: 10 - router_node_ref: router_1 + router_hostname: router_1 ip_address_order: - node_ref: domain_controller nic_num: 1 @@ -508,7 +501,7 @@ agents: - type: DATABASE_FILE_INTEGRITY weight: 0.5 options: - node_ref: database_server + node_hostname: database_server folder_name: database file_name: database.db @@ -516,8 +509,8 @@ agents: - type: WEB_SERVER_404_PENALTY weight: 0.5 options: - node_ref: web_server - service_ref: web_server_web_service + node_hostname: web_server + service_name: web_server_web_service agent_settings: diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 220ca21e..3671b809 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -37,13 +37,6 @@ agents: action_space: action_list: - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com options: nodes: @@ -111,25 +104,25 @@ agents: num_files_per_folder: 1 num_nics_per_node: 2 nodes: - - node_ref: domain_controller + - node_hostname: domain_controller services: - - service_ref: domain_controller_dns_server - - node_ref: web_server + - service_name: domain_controller_dns_server + - node_hostname: web_server services: - - service_ref: web_server_database_client - - node_ref: database_server + - service_name: web_server_database_client + - node_hostname: database_server services: - - service_ref: database_service + - service_name: database_service folders: - folder_name: database files: - file_name: database.db - - node_ref: backup_server + - node_hostname: backup_server # services: # - service_ref: backup_service - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 links: - link_ref: router_1___switch_1 - link_ref: router_1___switch_2 @@ -144,7 +137,7 @@ agents: acl: options: max_acl_rules: 10 - router_node_ref: router_1 + router_hostname: router_1 ip_address_order: - node_ref: domain_controller nic_num: 1 @@ -515,7 +508,7 @@ agents: - type: DATABASE_FILE_INTEGRITY weight: 0.5 options: - node_ref: database_server + node_hostname: database_server folder_name: database file_name: database.db @@ -523,8 +516,8 @@ agents: - type: WEB_SERVER_404_PENALTY weight: 0.5 options: - node_ref: web_server - service_ref: web_server_web_service + node_hostname: web_server + service_name: web_server_web_service agent_settings: @@ -542,25 +535,25 @@ agents: num_files_per_folder: 1 num_nics_per_node: 2 nodes: - - node_ref: domain_controller + - node_hostname: domain_controller services: - - service_ref: domain_controller_dns_server - - node_ref: web_server + - service_name: domain_controller_dns_server + - node_hostname: web_server services: - - service_ref: web_server_database_client - - node_ref: database_server + - service_name: web_server_database_client + - node_hostname: database_server services: - - service_ref: database_service + - service_name: database_service folders: - folder_name: database files: - file_name: database.db - - node_ref: backup_server + - node_hostname: backup_server # services: # - service_ref: backup_service - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 links: - link_ref: router_1___switch_1 - link_ref: router_1___switch_2 @@ -575,7 +568,7 @@ agents: acl: options: max_acl_rules: 10 - router_node_ref: router_1 + router_hostname: router_1 ip_address_order: - node_ref: domain_controller nic_num: 1 @@ -946,7 +939,7 @@ agents: - type: DATABASE_FILE_INTEGRITY weight: 0.5 options: - node_ref: database_server + node_hostname: database_server folder_name: database file_name: database.db @@ -954,8 +947,8 @@ agents: - type: WEB_SERVER_404_PENALTY weight: 0.5 options: - node_ref: web_server - service_ref: web_server_web_service + node_hostname: web_server + service_name: web_server_web_service agent_settings: diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index d7e94cb6..cc198a64 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -35,13 +35,6 @@ agents: action_space: action_list: - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com options: nodes: @@ -109,25 +102,25 @@ agents: num_files_per_folder: 1 num_nics_per_node: 2 nodes: - - node_ref: domain_controller + - node_hostname: domain_controller services: - - service_ref: domain_controller_dns_server - - node_ref: web_server + - service_name: domain_controller_dns_server + - node_hostname: web_server services: - - service_ref: web_server_database_client - - node_ref: database_server + - service_name: web_server_database_client + - node_hostname: database_server services: - - service_ref: database_service + - service_name: database_service folders: - folder_name: database files: - file_name: database.db - - node_ref: backup_server + - node_hostname: backup_server # services: - # - service_ref: backup_service - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + # - service_name: backup_service + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 links: - link_ref: router_1___switch_1 - link_ref: router_1___switch_2 @@ -142,7 +135,7 @@ agents: acl: options: max_acl_rules: 10 - router_node_ref: router_1 + router_hostname: router_1 ip_address_order: - node_ref: domain_controller nic_num: 1 @@ -513,7 +506,7 @@ agents: - type: DATABASE_FILE_INTEGRITY weight: 0.5 options: - node_ref: database_server + node_hostname: database_server folder_name: database file_name: database.db @@ -521,8 +514,8 @@ agents: - type: WEB_SERVER_404_PENALTY weight: 0.5 options: - node_ref: web_server - service_ref: web_server_web_service + node_hostname: web_server + service_name: web_server_web_service agent_settings: diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index b89349c0..ebef7f6a 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -105,25 +105,23 @@ agents: num_files_per_folder: 1 num_nics_per_node: 2 nodes: - - node_ref: domain_controller + - node_hostname: domain_controller services: - - service_ref: domain_controller_dns_server - - node_ref: web_server + - service_name: domain_controller_dns_server + - node_hostname: web_server services: - - service_ref: web_server_database_client - - node_ref: database_server + - service_name: web_server_database_client + - node_hostname: database_server services: - - service_ref: database_service + - service_name: database_service folders: - folder_name: database files: - file_name: database.db - - node_ref: backup_server - # services: - # - service_ref: backup_service - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: backup_server + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 links: - link_ref: router_1___switch_1 - link_ref: router_1___switch_2 @@ -138,7 +136,7 @@ agents: acl: options: max_acl_rules: 10 - router_node_ref: router_1 + router_hostname: router_1 ip_address_order: - node_ref: domain_controller nic_num: 1 @@ -509,7 +507,7 @@ agents: - type: DATABASE_FILE_INTEGRITY weight: 0.5 options: - node_ref: database_server + node_hostname: database_server folder_name: database file_name: database.db @@ -517,8 +515,8 @@ agents: - type: WEB_SERVER_404_PENALTY weight: 0.5 options: - node_ref: web_server - service_ref: web_server_web_service + node_hostname: web_server + service_name: web_service agent_settings: diff --git a/tests/integration_tests/game_layer/test_observations.py b/tests/integration_tests/game_layer/test_observations.py index 97154f62..07f3d25c 100644 --- a/tests/integration_tests/game_layer/test_observations.py +++ b/tests/integration_tests/game_layer/test_observations.py @@ -14,7 +14,7 @@ def test_file_observation(): state = sim.describe_state() dog_file_obs = FileObservation( - where=["network", "nodes", pc.uuid, "file_system", "folders", "root", "files", "dog.png"] + where=["network", "nodes", pc.hostname, "file_system", "folders", "root", "files", "dog.png"] ) assert dog_file_obs.observe(state) == {"health_status": 1} assert dog_file_obs.space == spaces.Dict({"health_status": spaces.Discrete(6)}) From 0cfd525ab8c2a1a5c4c4ef1c05ec14119f1d6a39 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 15 Dec 2023 10:14:35 +0000 Subject: [PATCH 481/980] 2041: change comparison operator in test --- tests/integration_tests/system/test_ntp_client_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index d58e3372..f626322f 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -60,7 +60,7 @@ def test_ntp_client_server(create_ntp_network): sleep(0.1) ntp_client.apply_timestep(1) # Check time advances second_time = ntp_client.time - assert first_time != second_time + assert first_time < second_time # Test ntp client behaviour when ntp server is unavailable. From 2d892d4a5acd88e2031ddffa3d336e461169e02c Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 15 Dec 2023 10:52:46 +0000 Subject: [PATCH 482/980] 2041: Tidy up test comments --- tests/integration_tests/system/test_ntp_client_server.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index f626322f..b7839479 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -13,6 +13,7 @@ from primaite.simulator.system.services.ntp.ntp_server import NTPServer from primaite.simulator.system.services.service import ServiceOperatingState # Create simple network for testing +# Define one node to be an NTP server and another node to be a NTP Client. @pytest.fixture(scope="function") @@ -40,9 +41,6 @@ def create_ntp_network(client_server) -> Tuple[NTPClient, Computer, NTPServer, S return ntp_client, client, ntp_server, server -# Define one node to be an NTP server and another node to be a NTP Client. - - def test_ntp_client_server(create_ntp_network): ntp_client, client, ntp_server, server = create_ntp_network From 495d847a71ddf29164952f927df6139a00a85003 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Dec 2023 13:04:18 +0000 Subject: [PATCH 483/980] Use service and app name for node software requests --- .../simulator/network/hardware/base.py | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index ad3d73aa..95c8e570 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1441,14 +1441,14 @@ class Node(SimComponent): :type service: Service """ if service in self: - _LOGGER.warning(f"Can't add service {service.uuid} to node {self.uuid}. It's already installed.") + _LOGGER.warning(f"Can't add service {service.name} to node {self.hostname}. It's already installed.") return self.services[service.uuid] = service service.parent = self service.install() # Perform any additional setup, such as creating files for this service on the node. self.sys_log.info(f"Installed service {service.name}") - _LOGGER.info(f"Added service {service.uuid} to node {self.uuid}") - self._service_request_manager.add_request(service.uuid, RequestType(func=service._request_manager)) + _LOGGER.info(f"Added service {service.name} to node {self.hostname}") + self._service_request_manager.add_request(service.name, RequestType(func=service._request_manager)) def uninstall_service(self, service: Service) -> None: """ @@ -1458,14 +1458,14 @@ class Node(SimComponent): :type service: Service """ if service not in self: - _LOGGER.warning(f"Can't remove service {service.uuid} from node {self.uuid}. It's not installed.") + _LOGGER.warning(f"Can't remove service {service.name} from node {self.hostname}. It's not installed.") return service.uninstall() # Perform additional teardown, such as removing files or restarting the machine. self.services.pop(service.uuid) service.parent = None self.sys_log.info(f"Uninstalled service {service.name}") - _LOGGER.info(f"Removed service {service.uuid} from node {self.uuid}") - self._service_request_manager.remove_request(service.uuid) + _LOGGER.info(f"Removed service {service.name} from node {self.hostname}") + self._service_request_manager.remove_request(service.name) def install_application(self, application: Application) -> None: """ @@ -1475,13 +1475,15 @@ class Node(SimComponent): :type application: Application """ if application in self: - _LOGGER.warning(f"Can't add application {application.uuid} to node {self.uuid}. It's already installed.") + _LOGGER.warning( + f"Can't add application {application.name} to node {self.hostname}. It's already installed." + ) return self.applications[application.uuid] = application application.parent = self self.sys_log.info(f"Installed application {application.name}") - _LOGGER.info(f"Added application {application.uuid} to node {self.uuid}") - self._application_request_manager.add_request(application.uuid, RequestType(func=application._request_manager)) + _LOGGER.info(f"Added application {application.name} to node {self.hostname}") + self._application_request_manager.add_request(application.name, RequestType(func=application._request_manager)) def uninstall_application(self, application: Application) -> None: """ @@ -1491,13 +1493,15 @@ class Node(SimComponent): :type application: Application """ if application not in self: - _LOGGER.warning(f"Can't remove application {application.uuid} from node {self.uuid}. It's not installed.") + _LOGGER.warning( + f"Can't remove application {application.name} from node {self.hostname}. It's not installed." + ) return self.applications.pop(application.uuid) application.parent = None self.sys_log.info(f"Uninstalled application {application.name}") - _LOGGER.info(f"Removed application {application.uuid} from node {self.uuid}") - self._application_request_manager.remove_request(application.uuid) + _LOGGER.info(f"Removed application {application.name} from node {self.hostname}") + self._application_request_manager.remove_request(application.name) def _shut_down_actions(self): """Actions to perform when the node is shut down.""" From 7a1abb1ef835ab4956b3d6af28711068f130c1a6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Dec 2023 13:09:50 +0000 Subject: [PATCH 484/980] Minor fixes based on code review --- src/primaite/game/agent/observations.py | 2 +- src/primaite/game/agent/rewards.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index ac091b77..928aebfd 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -346,7 +346,7 @@ class NicObservation(AbstractObservation): :param where: Where in the simulation state dictionary to find the relevant information for this NIC. A typical example may look like this: - ['network','nodes',,'NICs',] + ['network','nodes',,'NICs',] If None, this denotes that the NIC does not exist and the observation will be populated with zeroes. :type where: Optional[Tuple[str]], optional """ diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index e2c7d6fc..da51d94f 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -132,7 +132,7 @@ class DatabaseFileIntegrity(AbstractReward): node_hostname = config.get("node_hostname") folder_name = config.get("folder_name") file_name = config.get("file_name") - if not node_hostname and folder_name and file_name: + if not (node_hostname and folder_name and file_name): msg = f"{cls.__name__} could not be initialised with parameters {config}" _LOGGER.error(msg) raise ValueError(msg) @@ -148,8 +148,8 @@ class WebServer404Penalty(AbstractReward): :param node_hostname: Hostname of the node which contains the web server service. :type node_hostname: str - :param service_node: Name of the web server service. - :type service_node: str + :param service_name: Name of the web server service. + :type service_name: str """ self.location_in_state = ["network", "nodes", node_hostname, "services", service_name] From a798d262b86eeefc90566dc3b85a55407f824ee3 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 18 Dec 2023 14:03:47 +0000 Subject: [PATCH 485/980] use names instead of uuids for requests --- .../config/_package_data/example_config.yaml | 128 ++++++----- src/primaite/game/agent/actions.py | 209 ++++++++++-------- src/primaite/game/agent/observations.py | 2 +- src/primaite/game/agent/rewards.py | 1 - src/primaite/game/game.py | 33 +-- .../simulator/file_system/file_system.py | 4 +- src/primaite/simulator/network/container.py | 2 +- .../simulator/network/hardware/base.py | 11 +- 8 files changed, 201 insertions(+), 189 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index db0bca74..83a6de73 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -40,9 +40,9 @@ agents: - type: NODE_APPLICATION_EXECUTE options: nodes: - - node_ref: client_2 + - node_name: client_2 applications: - - application_ref: client_2_web_browser + - application_name: WebBrowser max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -76,9 +76,9 @@ agents: - type: NODE_OS_SCAN options: nodes: - - node_ref: client_1 + - node_name: client_1 applications: - - application_ref: data_manipulation_bot + - application_name: DataManipulationBot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -110,17 +110,15 @@ agents: - service_name: DNSServer - node_hostname: web_server services: - - service_name: web_server_database_client + - service_name: DatabaseClient - node_hostname: database_server services: - - service_name: database_service + - service_name: DatabaseService folders: - folder_name: database files: - file_name: database.db - node_hostname: backup_server - # services: - # - service_ref: backup_service - node_hostname: security_suite - node_hostname: client_1 - node_hostname: client_2 @@ -140,21 +138,21 @@ agents: max_acl_rules: 10 router_hostname: router_1 ip_address_order: - - node_ref: domain_controller + - node_hostname: domain_controller nic_num: 1 - - node_ref: web_server + - node_hostname: web_server nic_num: 1 - - node_ref: database_server + - node_hostname: database_server nic_num: 1 - - node_ref: backup_server + - node_hostname: backup_server nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 1 - - node_ref: client_1 + - node_hostname: client_1 nic_num: 1 - - node_ref: client_2 + - node_hostname: client_2 nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 2 ics: null @@ -184,10 +182,10 @@ agents: - type: NODE_RESET - type: NETWORK_ACL_ADDRULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_ACL_REMOVERULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -407,97 +405,105 @@ agents: 38: action: "NETWORK_NIC_DISABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 39: action: "NETWORK_NIC_ENABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 40: action: "NETWORK_NIC_DISABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 41: action: "NETWORK_NIC_ENABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 42: action: "NETWORK_NIC_DISABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 43: action: "NETWORK_NIC_ENABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 44: action: "NETWORK_NIC_DISABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 45: action: "NETWORK_NIC_ENABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 46: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 47: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 48: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 49: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 50: action: "NETWORK_NIC_DISABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 51: action: "NETWORK_NIC_ENABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 52: action: "NETWORK_NIC_DISABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 53: action: "NETWORK_NIC_ENABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 options: nodes: - - node_ref: router_1 - - node_ref: switch_1 - - node_ref: switch_2 - - node_ref: domain_controller - - node_ref: web_server - - node_ref: database_server - - node_ref: backup_server - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + # - node_name: router_1 + # - node_name: switch_1 + # - node_name: switch_2 + - node_name: domain_controller + - node_name: web_server + applications: + - application_name: DatabaseClient + services: + - service_name: WebServer + - node_name: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - node_name: backup_server + - node_name: security_suite + - node_name: client_1 + - node_name: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 @@ -518,7 +524,7 @@ agents: weight: 0.5 options: node_hostname: web_server - service_name: web_server_web_service + service_name: WebServer agent_settings: diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 8eed3ba4..ff063dbd 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -33,7 +33,7 @@ class AbstractAction(ABC): All action init functions should accept **kwargs as a way of ignoring extra arguments. Since many parameters are defined for the action space as a whole (such as max files per folder, max services - per node), we need to pass those options to every action that gets created. To pervent verbosity, these + per node), we need to pass those options to every action that gets created. To prevent verbosity, these parameters are just broadcasted to all actions and the actions can pay attention to the ones that apply. """ self.name: str = "" @@ -85,11 +85,11 @@ class NodeServiceAbstractAction(AbstractAction): def form_request(self, node_id: int, service_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" - node_uuid = self.manager.get_node_uuid_by_idx(node_id) - service_uuid = self.manager.get_service_uuid_by_idx(node_id, service_id) - if node_uuid is None or service_uuid is None: + node_name = self.manager.get_node_name_by_idx(node_id) + service_name = self.manager.get_service_name_by_idx(node_id, service_id) + if node_name is None or service_name is None: return ["do_nothing"] - return ["network", "node", node_uuid, "services", service_uuid, self.verb] + return ["network", "node", node_name, "services", service_name, self.verb] class NodeServiceScanAction(NodeServiceAbstractAction): @@ -172,11 +172,11 @@ class NodeApplicationAbstractAction(AbstractAction): def form_request(self, node_id: int, application_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" - node_uuid = self.manager.get_node_uuid_by_idx(node_id) - application_uuid = self.manager.get_application_uuid_by_idx(node_id, application_id) - if node_uuid is None or application_uuid is None: + node_name = self.manager.get_node_name_by_idx(node_id) + application_name = self.manager.get_application_name_by_idx(node_id, application_id) + if node_name is None or application_name is None: return ["do_nothing"] - return ["network", "node", node_uuid, "application", application_uuid, self.verb] + return ["network", "node", node_name, "application", application_name, self.verb] class NodeApplicationExecuteAction(NodeApplicationAbstractAction): @@ -203,11 +203,11 @@ class NodeFolderAbstractAction(AbstractAction): def form_request(self, node_id: int, folder_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" - node_uuid = self.manager.get_node_uuid_by_idx(node_id) - folder_uuid = self.manager.get_folder_uuid_by_idx(node_idx=node_id, folder_idx=folder_id) - if node_uuid is None or folder_uuid is None: + node_name = self.manager.get_node_name_by_idx(node_id) + folder_name = self.manager.get_folder_name_by_idx(node_idx=node_id, folder_idx=folder_id) + if node_name is None or folder_name is None: return ["do_nothing"] - return ["network", "node", node_uuid, "file_system", "folder", folder_uuid, self.verb] + return ["network", "node", node_name, "file_system", "folder", folder_name, self.verb] class NodeFolderScanAction(NodeFolderAbstractAction): @@ -257,12 +257,12 @@ class NodeFileAbstractAction(AbstractAction): def form_request(self, node_id: int, folder_id: int, file_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" - node_uuid = self.manager.get_node_uuid_by_idx(node_id) - folder_uuid = self.manager.get_folder_uuid_by_idx(node_idx=node_id, folder_idx=folder_id) - file_uuid = self.manager.get_file_uuid_by_idx(node_idx=node_id, folder_idx=folder_id, file_idx=file_id) - if node_uuid is None or folder_uuid is None or file_uuid is None: + node_name = self.manager.get_node_name_by_idx(node_id) + folder_name = self.manager.get_folder_name_by_idx(node_idx=node_id, folder_idx=folder_id) + file_name = self.manager.get_file_name_by_idx(node_idx=node_id, folder_idx=folder_id, file_idx=file_id) + if node_name is None or folder_name is None or file_name is None: return ["do_nothing"] - return ["network", "node", node_uuid, "file_system", "folder", folder_uuid, "files", file_uuid, self.verb] + return ["network", "node", node_name, "file_system", "folder", folder_name, "files", file_name, self.verb] class NodeFileScanAction(NodeFileAbstractAction): @@ -328,8 +328,8 @@ class NodeAbstractAction(AbstractAction): def form_request(self, node_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" - node_uuid = self.manager.get_node_uuid_by_idx(node_id) - return ["network", "node", node_uuid, self.verb] + node_name = self.manager.get_node_name_by_idx(node_id) + return ["network", "node", node_name, self.verb] class NodeOSScanAction(NodeAbstractAction): @@ -370,7 +370,7 @@ class NetworkACLAddRuleAction(AbstractAction): def __init__( self, manager: "ActionManager", - target_router_uuid: str, + target_router_hostname: str, max_acl_rules: int, num_ips: int, num_ports: int, @@ -381,8 +381,8 @@ class NetworkACLAddRuleAction(AbstractAction): :param manager: Reference to the ActionManager which created this action. :type manager: ActionManager - :param target_router_uuid: UUID of the router to which the ACL rule should be added. - :type target_router_uuid: str + :param target_router_name: hostname of the router to which the ACL rule should be added. + :type target_router_name: str :param max_acl_rules: Maximum number of ACL rules that can be added to the router. :type max_acl_rules: int :param num_ips: Number of IP addresses in the simulation. @@ -403,7 +403,7 @@ class NetworkACLAddRuleAction(AbstractAction): "dest_port_id": num_ports, "protocol_id": num_protocols, } - self.target_router_uuid: str = target_router_uuid + self.target_router_name: str = target_router_hostname def form_request( self, @@ -464,7 +464,7 @@ class NetworkACLAddRuleAction(AbstractAction): return [ "network", "node", - self.target_router_uuid, + self.target_router_name, "acl", "add_rule", permission_str, @@ -480,23 +480,23 @@ class NetworkACLAddRuleAction(AbstractAction): class NetworkACLRemoveRuleAction(AbstractAction): """Action which removes a rule from a router's ACL.""" - def __init__(self, manager: "ActionManager", target_router_uuid: str, max_acl_rules: int, **kwargs) -> None: + def __init__(self, manager: "ActionManager", target_router_hostname: str, max_acl_rules: int, **kwargs) -> None: """Init method for NetworkACLRemoveRuleAction. :param manager: Reference to the ActionManager which created this action. :type manager: ActionManager - :param target_router_uuid: UUID of the router from which the ACL rule should be removed. - :type target_router_uuid: str + :param target_router_name: Hostname of the router from which the ACL rule should be removed. + :type target_router_name: str :param max_acl_rules: Maximum number of ACL rules that can be added to the router. :type max_acl_rules: int """ super().__init__(manager=manager) self.shape: Dict[str, int] = {"position": max_acl_rules} - self.target_router_uuid: str = target_router_uuid + self.target_router_name: str = target_router_hostname def form_request(self, position: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" - return ["network", "node", self.target_router_uuid, "acl", "remove_rule", position] + return ["network", "node", self.target_router_name, "acl", "remove_rule", position] class NetworkNICAbstractAction(AbstractAction): @@ -523,16 +523,16 @@ class NetworkNICAbstractAction(AbstractAction): def form_request(self, node_id: int, nic_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" - node_uuid = self.manager.get_node_uuid_by_idx(node_idx=node_id) - nic_uuid = self.manager.get_nic_uuid_by_idx(node_idx=node_id, nic_idx=nic_id) - if node_uuid is None or nic_uuid is None: + node_name = self.manager.get_node_name_by_idx(node_idx=node_id) + nic_num = self.manager.get_nic_num_by_idx(node_idx=node_id, nic_idx=nic_id) + if node_name is None or nic_num is None: return ["do_nothing"] return [ "network", "node", - node_uuid, + node_name, "nic", - nic_uuid, + nic_num, self.verb, ] @@ -592,12 +592,11 @@ class ActionManager: self, game: "PrimaiteGame", # reference to game for information lookup actions: List[str], # stores list of actions available to agent - node_uuids: List[str], # allows mapping index to node - application_uuids: List[List[str]], # allows mapping index to application + nodes: List[Dict], # extra configuration for each node max_folders_per_node: int = 2, # allows calculating shape max_files_per_folder: int = 2, # allows calculating shape max_services_per_node: int = 2, # allows calculating shape - max_applications_per_node: int = 10, # allows calculating shape + max_applications_per_node: int = 2, # allows calculating shape max_nics_per_node: int = 8, # allows calculating shape max_acl_rules: int = 10, # allows calculating shape protocols: List[str] = ["TCP", "UDP", "ICMP"], # allow mapping index to protocol @@ -633,8 +632,60 @@ class ActionManager: :type act_map: Optional[Dict[int, Dict]] """ self.game: "PrimaiteGame" = game - self.node_uuids: List[str] = node_uuids - self.application_uuids: List[List[str]] = application_uuids + self.node_names: List[str] = [n["node_name"] for n in nodes] + """List of node names in this action space. The list order is the mapping between node index and node name.""" + self.application_names: List[List[str]] = [] + """ + List of applications per node. The list order gives the two-index mapping between (node_id, app_id) to app name. + The first index corresponds to node id, the second index is the app id on that particular node. + For instance, self.application_names[0][2] is the name of the third application on the first node. + """ + self.service_names: List[List[str]] = [] + """ + List of services per node. The list order gives the two-index mapping between (node_id, svc_id) to svc name. + The first index corresponds to node id, the second index is the service id on that particular node. + For instance, self.service_names[0][2] is the name of the third service on the first node. + """ + self.folder_names: List[List[str]] = [] + """ + List of folders per node. The list order gives the two-index mapping between (node_id, folder_id) to folder + name. The first index corresponds to node id, the second index is the folder id on that particular node. + For instance, self.folder_names[0][2] is the name of the third folder on the first node. + """ + self.file_names: List[List[List[str]]] = [] + """ + List of files per folder per node. The list order gives the three-index mapping between + (node_id, folder_id, file_id) to file name. The first index corresponds to node id, the second index is the + folder id on that particular node, and the third index is the file id in that particular folder. + For instance, self.file_names[0][2][1] is the name of the second file in the third folder on the first node. + """ + + # Populate lists of apps, services, files, folders, etc on nodes. + for n in nodes: + app_list = [a["application_name"] for a in n.get("applications", [])] + while len(app_list) < max_applications_per_node: + app_list.append(None) + self.application_names.append(app_list) + + svc_list = [s["service_name"] for s in n.get("services", [])] + while len(svc_list) < max_services_per_node: + svc_list.append(None) + self.service_names.append(svc_list) + + folder_list = [f["folder_name"] for f in n.get("folders", [])] + while len(folder_list) < max_folders_per_node: + folder_list.append(None) + self.folder_names.append(folder_list) + + file_sublist = [] + for folder in n.get("folders", [{"files": []}]): + file_list = [f["file_name"] for f in folder.get("files", [])] + while len(file_list) < max_files_per_folder: + file_list.append(None) + file_sublist.append(file_list) + while len(file_sublist) < max_folders_per_node: + file_sublist.append([None] * max_files_per_folder) + self.file_names.append(file_sublist) self.protocols: List[str] = protocols self.ports: List[str] = ports @@ -643,15 +694,17 @@ class ActionManager: self.ip_address_list = ip_address_list else: self.ip_address_list = [] - for node_uuid in self.node_uuids: - node_obj = self.game.simulation.network.nodes[node_uuid] + for node_name in self.node_names: + node_obj = self.game.simulation.network.get_node_by_hostname(node_name) + if node_obj is None: + continue nics = node_obj.nics for nic_uuid, nic_obj in nics.items(): self.ip_address_list.append(nic_obj.ip_address) # action_args are settings which are applied to the action space as a whole. global_action_args = { - "num_nodes": len(node_uuids), + "num_nodes": len(self.node_names), "num_folders": max_folders_per_node, "num_files": max_files_per_folder, "num_services": max_services_per_node, @@ -696,7 +749,7 @@ class ActionManager: ) -> Dict[int, Tuple[str, Dict]]: """Generate a list of all the possible actions that could be taken. - This enumerates all actions all combinations of parametes you could choose for those actions. The output + This enumerates all actions all combinations of parameters you could choose for those actions. The output of this function is intended to populate the self.action_map parameter in the situation where the user provides a list of action types, but doesn't specify any subset of actions that should be made available to the agent. @@ -745,34 +798,31 @@ class ActionManager: """Return the gymnasium action space for this agent.""" return spaces.Discrete(len(self.action_map)) - def get_node_uuid_by_idx(self, node_idx: int) -> str: + def get_node_name_by_idx(self, node_idx: int) -> str: """ - Get the node UUID corresponding to the given index. + Get the node name corresponding to the given index. :param node_idx: The index of the node to retrieve. :type node_idx: int - :return: The node UUID. + :return: The node hostname. :rtype: str """ - return self.node_uuids[node_idx] + return self.node_names[node_idx] - def get_folder_uuid_by_idx(self, node_idx: int, folder_idx: int) -> Optional[str]: + def get_folder_name_by_idx(self, node_idx: int, folder_idx: int) -> Optional[str]: """ - Get the folder UUID corresponding to the given node and folder indices. + Get the folder name corresponding to the given node and folder indices. :param node_idx: The index of the node. :type node_idx: int :param folder_idx: The index of the folder on the node. :type folder_idx: int - :return: The UUID of the folder. Or None if the node has fewer folders than the given index. + :return: The name of the folder. Or None if the node has fewer folders than the given index. :rtype: Optional[str] """ - node_uuid = self.get_node_uuid_by_idx(node_idx) - node = self.game.simulation.network.nodes[node_uuid] - folder_uuids = list(node.file_system.folders.keys()) - return folder_uuids[folder_idx] if len(folder_uuids) > folder_idx else None + return self.folder_names[node_idx][folder_idx] - def get_file_uuid_by_idx(self, node_idx: int, folder_idx: int, file_idx: int) -> Optional[str]: + def get_file_name_by_idx(self, node_idx: int, folder_idx: int, file_idx: int) -> Optional[str]: """Get the file UUID corresponding to the given node, folder, and file indices. :param node_idx: The index of the node. @@ -781,45 +831,35 @@ class ActionManager: :type folder_idx: int :param file_idx: The index of the file in the folder. :type file_idx: int - :return: The UUID of the file. Or None if the node has fewer folders than the given index, or the folder has + :return: The name of the file. Or None if the node has fewer folders than the given index, or the folder has fewer files than the given index. :rtype: Optional[str] """ - node_uuid = self.get_node_uuid_by_idx(node_idx) - node = self.game.simulation.network.nodes[node_uuid] - folder_uuids = list(node.file_system.folders.keys()) - if len(folder_uuids) <= folder_idx: - return None - folder = node.file_system.folders[folder_uuids[folder_idx]] - file_uuids = list(folder.files.keys()) - return file_uuids[file_idx] if len(file_uuids) > file_idx else None + return self.file_names[node_idx][folder_idx][file_idx] - def get_service_uuid_by_idx(self, node_idx: int, service_idx: int) -> Optional[str]: - """Get the service UUID corresponding to the given node and service indices. + def get_service_name_by_idx(self, node_idx: int, service_idx: int) -> Optional[str]: + """Get the service name corresponding to the given node and service indices. :param node_idx: The index of the node. :type node_idx: int :param service_idx: The index of the service on the node. :type service_idx: int - :return: The UUID of the service. Or None if the node has fewer services than the given index. + :return: The name of the service. Or None if the node has fewer services than the given index. :rtype: Optional[str] """ - node_uuid = self.get_node_uuid_by_idx(node_idx) - node = self.game.simulation.network.nodes[node_uuid] - service_uuids = list(node.services.keys()) - return service_uuids[service_idx] if len(service_uuids) > service_idx else None + return self.service_names[node_idx][service_idx] - def get_application_uuid_by_idx(self, node_idx: int, application_idx: int) -> Optional[str]: - """Get the application UUID corresponding to the given node and service indices. + def get_application_name_by_idx(self, node_idx: int, application_idx: int) -> Optional[str]: + """Get the application name corresponding to the given node and service indices. :param node_idx: The index of the node. :type node_idx: int :param application_idx: The index of the service on the node. :type application_idx: int - :return: The UUID of the service. Or None if the node has fewer services than the given index. + :return: The name of the service. Or None if the node has fewer services than the given index. :rtype: Optional[str] """ - return self.application_uuids[node_idx][application_idx] + return self.application_names[node_idx][application_idx] def get_internet_protocol_by_idx(self, protocol_idx: int) -> str: """Get the internet protocol corresponding to the given index. @@ -853,23 +893,18 @@ class ActionManager: """ return self.ports[port_idx] - def get_nic_uuid_by_idx(self, node_idx: int, nic_idx: int) -> str: + def get_nic_num_by_idx(self, node_idx: int, nic_idx: int) -> int: """ - Get the NIC UUID corresponding to the given node and NIC indices. + Get the NIC number corresponding to the given node and NIC indices. :param node_idx: The index of the node. :type node_idx: int :param nic_idx: The index of the NIC on the node. :type nic_idx: int - :return: The NIC UUID. - :rtype: str + :return: The NIC number. + :rtype: int """ - node_uuid = self.get_node_uuid_by_idx(node_idx) - node_obj = self.game.simulation.network.nodes[node_uuid] - nics = list(node_obj.nics.keys()) - if len(nics) <= nic_idx: - return None - return nics[nic_idx] + return nic_idx + 1 @classmethod def from_config(cls, game: "PrimaiteGame", cfg: Dict) -> "ActionManager": @@ -878,7 +913,7 @@ class ActionManager: The action space config supports the following three sections: 1. ``action_list`` - ``action_list`` contians a list action components which need to be included in the action space. + ``action_list`` contains a list action components which need to be included in the action space. Each action component has a ``type`` which maps to a subclass of AbstractAction, and additional options which will be passed to the action class's __init__ method during initialisation. 2. ``action_map`` diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index ac091b77..b2e88b7c 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -704,7 +704,7 @@ class AclObservation(AbstractObservation): max_acl_rules = config["options"]["max_acl_rules"] node_ip_to_idx = {} for ip_idx, ip_map_config in enumerate(config["ip_address_order"]): - node_ref = ip_map_config["node_ref"] + node_ref = ip_map_config["node_hostname"] nic_num = ip_map_config["nic_num"] node_obj = game.simulation.network.nodes[game.ref_map_nodes[node_ref]] nic_obj = node_obj.ethernet_port[nic_num] diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index e2c7d6fc..7a57bc2f 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -161,7 +161,6 @@ class WebServer404Penalty(AbstractReward): """ web_service_state = access_from_nested_dict(state, self.location_in_state) if web_service_state is NOT_PRESENT_IN_STATE: - print("error getting web service state") return 0.0 most_recent_return_code = web_service_state["last_response_status_code"] # TODO: reward needs to use the current web state. Observation should return web state at the time of last scan. diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index b6b815f1..c0885cd0 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -360,43 +360,12 @@ class PrimaiteGame: obs_space = ObservationManager.from_config(observation_space_cfg, game) # CREATE ACTION SPACE - action_space_cfg["options"]["node_uuids"] = [] - action_space_cfg["options"]["application_uuids"] = [] - - # if a list of nodes is defined, convert them from node references to node UUIDs - for action_node_option in action_space_cfg.get("options", {}).pop("nodes", {}): - if "node_ref" in action_node_option: - node_uuid = game.ref_map_nodes[action_node_option["node_ref"]] - action_space_cfg["options"]["node_uuids"].append(node_uuid) - - if "applications" in action_node_option: - node_application_uuids = [] - for application_option in action_node_option["applications"]: - # TODO: fix inconsistency with node uuids and application uuids. The node object get added to - # node_uuid, whereas here the application gets added by uuid. - application_uuid = game.ref_map_applications[application_option["application_ref"]] - node_application_uuids.append(application_uuid) - - action_space_cfg["options"]["application_uuids"].append(node_application_uuids) - else: - action_space_cfg["options"]["application_uuids"].append([]) - # Each action space can potentially have a different list of nodes that it can apply to. Therefore, - # we will pass node_uuids as a part of the action space config. - # However, it's not possible to specify the node uuids directly in the config, as they are generated - # dynamically, so we have to translate node references to uuids before passing this config on. - - if "action_list" in action_space_cfg: - for action_config in action_space_cfg["action_list"]: - if "options" in action_config: - if "target_router_ref" in action_config["options"]: - _target = action_config["options"]["target_router_ref"] - action_config["options"]["target_router_uuid"] = game.ref_map_nodes[_target] - action_space = ActionManager.from_config(game, action_space_cfg) # CREATE REWARD FUNCTION rew_function = RewardFunction.from_config(reward_function_cfg, game=game) + # OTHER AGENT SETTINGS agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) # CREATE AGENT diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index c2eb0d2d..f5e734cf 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -175,7 +175,7 @@ class FileSystem(SimComponent): self.folders[folder.uuid] = folder self._folders_by_name[folder.name] = folder self._folder_request_manager.add_request( - name=folder.uuid, request_type=RequestType(func=folder._request_manager) + name=folder.name, request_type=RequestType(func=folder._request_manager) ) return folder @@ -282,7 +282,7 @@ class FileSystem(SimComponent): sys_log=self.sys_log, ) folder.add_file(file) - self._file_request_manager.add_request(name=file.uuid, request_type=RequestType(func=file._request_manager)) + self._file_request_manager.add_request(name=file.name, request_type=RequestType(func=file._request_manager)) return file def get_file(self, folder_name: str, file_name: str) -> Optional[File]: diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 8d8709d3..1dadd9e2 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -235,7 +235,7 @@ class Network(SimComponent): node.parent = self self._nx_graph.add_node(node.hostname) _LOGGER.debug(f"Added node {node.uuid} to Network {self.uuid}") - self._node_request_manager.add_request(name=node.uuid, request_type=RequestType(func=node._request_manager)) + self._node_request_manager.add_request(name=node.hostname, request_type=RequestType(func=node._request_manager)) def get_node_by_hostname(self, hostname: str) -> Optional[Node]: """ diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 95c8e570..bbcdfe37 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1318,14 +1318,15 @@ class Node(SimComponent): """ if nic.uuid not in self.nics: self.nics[nic.uuid] = nic - self.ethernet_port[len(self.nics)] = nic + new_nic_num = len(self.nics) + self.ethernet_port[new_nic_num] = nic nic._connected_node = self - nic._port_num_on_node = len(self.nics) + nic._port_num_on_node = new_nic_num nic.parent = self self.sys_log.info(f"Connected NIC {nic}") if self.operating_state == NodeOperatingState.ON: nic.enable() - self._nic_request_manager.add_request(nic.uuid, RequestType(func=nic._request_manager)) + self._nic_request_manager.add_request(new_nic_num, RequestType(func=nic._request_manager)) else: msg = f"Cannot connect NIC {nic} as it is already connected" self.sys_log.logger.error(msg) @@ -1342,15 +1343,17 @@ class Node(SimComponent): if isinstance(nic, str): nic = self.nics.get(nic) if nic or nic.uuid in self.nics: + nic_num = -1 for port, _nic in self.ethernet_port.items(): if nic == _nic: self.ethernet_port.pop(port) + nic_num = port break self.nics.pop(nic.uuid) nic.parent = None nic.disable() self.sys_log.info(f"Disconnected NIC {nic}") - self._nic_request_manager.remove_request(nic.uuid) + self._nic_request_manager.remove_request(nic_num) else: msg = f"Cannot disconnect NIC {nic} as it is not connected" self.sys_log.logger.error(msg) From a1dcfa291bcd700640563b721d51aafaebdec8b7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 21 Dec 2023 09:25:54 +0000 Subject: [PATCH 486/980] Update test configs with new action spec --- .../assets/configs/bad_primaite_session.yaml | 48 +++++----- .../configs/eval_only_primaite_session.yaml | 48 +++++----- tests/assets/configs/multi_agent_session.yaml | 90 +++++++++---------- .../assets/configs/test_primaite_session.yaml | 46 +++++----- .../configs/train_only_primaite_session.yaml | 46 +++++----- .../_file_system/test_file_actions.py | 2 +- 6 files changed, 136 insertions(+), 144 deletions(-) diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 478cbfae..4c1d7ce7 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -29,7 +29,7 @@ agents: - type: DONOTHING options: nodes: - - node_ref: client_2 + - node_hostname: client_2 max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -64,9 +64,9 @@ agents: - type: NODE_OS_SCAN options: nodes: - - node_ref: client_1 + - node_hostname: client_1 applications: - - application_ref: data_manipulation_bot + - application_name: data_manipulation_bot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -107,8 +107,6 @@ agents: files: - file_name: database.db - node_hostname: backup_server - # services: - # - service_ref: backup_service - node_hostname: security_suite - node_hostname: client_1 - node_hostname: client_2 @@ -128,21 +126,21 @@ agents: max_acl_rules: 10 router_hostname: router_1 ip_address_order: - - node_ref: domain_controller + - node_hostname: domain_controller nic_num: 1 - - node_ref: web_server + - node_hostname: web_server nic_num: 1 - - node_ref: database_server + - node_hostname: database_server nic_num: 1 - - node_ref: backup_server + - node_hostname: backup_server nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 1 - - node_ref: client_1 + - node_hostname: client_1 nic_num: 1 - - node_ref: client_2 + - node_hostname: client_2 nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 2 ics: null @@ -172,10 +170,10 @@ agents: - type: NODE_RESET - type: NETWORK_ACL_ADDRULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_ACL_REMOVERULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -476,16 +474,16 @@ agents: options: nodes: - - node_ref: router_1 - - node_ref: switch_1 - - node_ref: switch_2 - - node_ref: domain_controller - - node_ref: web_server - - node_ref: database_server - - node_ref: backup_server - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: router_1 + - node_hostname: switch_1 + - node_hostname: switch_2 + - node_hostname: domain_controller + - node_hostname: web_server + - node_hostname: database_server + - node_hostname: backup_server + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index ec6bfb63..29b7937b 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -34,7 +34,7 @@ agents: options: nodes: - - node_ref: client_2 + - node_name: client_2 max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -69,9 +69,9 @@ agents: - type: NODE_OS_SCAN options: nodes: - - node_ref: client_1 + - node_hostname: client_1 applications: - - application_ref: data_manipulation_bot + - application_name: data_manipulation_bot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -111,8 +111,6 @@ agents: files: - file_name: database.db - node_hostname: backup_server - # services: - # - service_ref: backup_service - node_hostname: security_suite - node_hostname: client_1 - node_hostname: client_2 @@ -132,21 +130,21 @@ agents: max_acl_rules: 10 router_hostname: router_1 ip_address_order: - - node_ref: domain_controller + - node_hostname: domain_controller nic_num: 1 - - node_ref: web_server + - node_hostname: web_server nic_num: 1 - - node_ref: database_server + - node_hostname: database_server nic_num: 1 - - node_ref: backup_server + - node_hostname: backup_server nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 1 - - node_ref: client_1 + - node_hostname: client_1 nic_num: 1 - - node_ref: client_2 + - node_hostname: client_2 nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 2 ics: null @@ -176,10 +174,10 @@ agents: - type: NODE_RESET - type: NETWORK_ACL_ADDRULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_ACL_REMOVERULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -480,16 +478,16 @@ agents: options: nodes: - - node_ref: router_1 - - node_ref: switch_1 - - node_ref: switch_2 - - node_ref: domain_controller - - node_ref: web_server - - node_ref: database_server - - node_ref: backup_server - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: router_1 + - node_hostname: switch_1 + - node_hostname: switch_2 + - node_hostname: domain_controller + - node_hostname: web_server + - node_hostname: database_server + - node_hostname: backup_server + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 3671b809..54727790 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -40,7 +40,7 @@ agents: options: nodes: - - node_ref: client_2 + - node_hostname: client_2 max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -75,9 +75,9 @@ agents: - type: NODE_OS_SCAN options: nodes: - - node_ref: client_1 + - node_hostname: client_1 applications: - - application_ref: data_manipulation_bot + - application_name: data_manipulation_bot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -118,8 +118,6 @@ agents: files: - file_name: database.db - node_hostname: backup_server - # services: - # - service_ref: backup_service - node_hostname: security_suite - node_hostname: client_1 - node_hostname: client_2 @@ -139,21 +137,21 @@ agents: max_acl_rules: 10 router_hostname: router_1 ip_address_order: - - node_ref: domain_controller + - node_hostname: domain_controller nic_num: 1 - - node_ref: web_server + - node_hostname: web_server nic_num: 1 - - node_ref: database_server + - node_hostname: database_server nic_num: 1 - - node_ref: backup_server + - node_hostname: backup_server nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 1 - - node_ref: client_1 + - node_hostname: client_1 nic_num: 1 - - node_ref: client_2 + - node_hostname: client_2 nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 2 ics: null @@ -183,10 +181,10 @@ agents: - type: NODE_RESET - type: NETWORK_ACL_ADDRULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_ACL_REMOVERULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -487,16 +485,16 @@ agents: options: nodes: - - node_ref: router_1 - - node_ref: switch_1 - - node_ref: switch_2 - - node_ref: domain_controller - - node_ref: web_server - - node_ref: database_server - - node_ref: backup_server - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: router_1 + - node_hostname: switch_1 + - node_hostname: switch_2 + - node_hostname: domain_controller + - node_hostname: web_server + - node_hostname: database_server + - node_hostname: backup_server + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 @@ -549,8 +547,6 @@ agents: files: - file_name: database.db - node_hostname: backup_server - # services: - # - service_ref: backup_service - node_hostname: security_suite - node_hostname: client_1 - node_hostname: client_2 @@ -570,21 +566,21 @@ agents: max_acl_rules: 10 router_hostname: router_1 ip_address_order: - - node_ref: domain_controller + - node_hostname: domain_controller nic_num: 1 - - node_ref: web_server + - node_hostname: web_server nic_num: 1 - - node_ref: database_server + - node_hostname: database_server nic_num: 1 - - node_ref: backup_server + - node_hostname: backup_server nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 1 - - node_ref: client_1 + - node_hostname: client_1 nic_num: 1 - - node_ref: client_2 + - node_hostname: client_2 nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 2 ics: null @@ -614,10 +610,10 @@ agents: - type: NODE_RESET - type: NETWORK_ACL_ADDRULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_ACL_REMOVERULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -918,16 +914,16 @@ agents: options: nodes: - - node_ref: router_1 - - node_ref: switch_1 - - node_ref: switch_2 - - node_ref: domain_controller - - node_ref: web_server - - node_ref: database_server - - node_ref: backup_server - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: router_1 + - node_hostname: switch_1 + - node_hostname: switch_2 + - node_hostname: domain_controller + - node_hostname: web_server + - node_hostname: database_server + - node_hostname: backup_server + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index cc198a64..f677b4e0 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -38,7 +38,7 @@ agents: options: nodes: - - node_ref: client_2 + - node_hostname: client_2 max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -73,9 +73,9 @@ agents: - type: NODE_OS_SCAN options: nodes: - - node_ref: client_1 + - node_hostname: client_1 applications: - - application_ref: data_manipulation_bot + - application_hostname: data_manipulation_bot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -137,21 +137,21 @@ agents: max_acl_rules: 10 router_hostname: router_1 ip_address_order: - - node_ref: domain_controller + - node_hostname: domain_controller nic_num: 1 - - node_ref: web_server + - node_hostname: web_server nic_num: 1 - - node_ref: database_server + - node_hostname: database_server nic_num: 1 - - node_ref: backup_server + - node_hostname: backup_server nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 1 - - node_ref: client_1 + - node_hostname: client_1 nic_num: 1 - - node_ref: client_2 + - node_hostname: client_2 nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 2 ics: null @@ -181,10 +181,10 @@ agents: - type: NODE_RESET - type: NETWORK_ACL_ADDRULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_ACL_REMOVERULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -485,16 +485,16 @@ agents: options: nodes: - - node_ref: router_1 - - node_ref: switch_1 - - node_ref: switch_2 - - node_ref: domain_controller - - node_ref: web_server - - node_ref: database_server - - node_ref: backup_server - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: router_1 + - node_hostname: switch_1 + - node_hostname: switch_2 + - node_hostname: domain_controller + - node_hostname: web_server + - node_hostname: database_server + - node_hostname: backup_server + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index ebef7f6a..b788e33f 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -41,7 +41,7 @@ agents: options: nodes: - - node_ref: client_2 + - node_hostname: client_2 max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -76,9 +76,9 @@ agents: - type: NODE_OS_SCAN options: nodes: - - node_ref: client_1 + - node_hostname: client_1 applications: - - application_ref: data_manipulation_bot + - application_name: data_manipulation_bot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -138,21 +138,21 @@ agents: max_acl_rules: 10 router_hostname: router_1 ip_address_order: - - node_ref: domain_controller + - node_hostname: domain_controller nic_num: 1 - - node_ref: web_server + - node_hostname: web_server nic_num: 1 - - node_ref: database_server + - node_hostname: database_server nic_num: 1 - - node_ref: backup_server + - node_hostname: backup_server nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 1 - - node_ref: client_1 + - node_hostname: client_1 nic_num: 1 - - node_ref: client_2 + - node_hostname: client_2 nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 2 ics: null @@ -182,10 +182,10 @@ agents: - type: NODE_RESET - type: NETWORK_ACL_ADDRULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_ACL_REMOVERULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -486,16 +486,16 @@ agents: options: nodes: - - node_ref: router_1 - - node_ref: switch_1 - - node_ref: switch_2 - - node_ref: domain_controller - - node_ref: web_server - - node_ref: database_server - - node_ref: backup_server - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: router_1 + - node_hostname: switch_1 + - node_hostname: switch_2 + - node_hostname: domain_controller + - node_hostname: web_server + - node_hostname: database_server + - node_hostname: backup_server + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py index aa8faa90..8590153a 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py @@ -25,7 +25,7 @@ def test_file_scan_request(populated_file_system): assert file.health_status == FileSystemItemHealthStatus.CORRUPT assert file.visible_health_status == FileSystemItemHealthStatus.GOOD - fs.apply_request(request=["file", file.uuid, "scan"]) + fs.apply_request(request=["file", file.name, "scan"]) assert file.health_status == FileSystemItemHealthStatus.CORRUPT assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT From e33f74e3f2ce174c972f5f3717b1b7a83ddc1aec Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 21 Dec 2023 09:28:14 +0000 Subject: [PATCH 487/980] bump version to 3.0.0b3dev --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index 2aa4d8f0..6da222f2 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0b2 +3.0.0b3dev From 96f8435c5e88c703ef0bb18029c760916cf90ff6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 21 Dec 2023 15:07:41 +0000 Subject: [PATCH 488/980] Add service patch and fix other bugs --- .../config/_package_data/example_config.yaml | 115 +++++++++--------- src/primaite/game/agent/actions.py | 20 ++- src/primaite/game/game.py | 14 ++- src/primaite/simulator/file_system/folder.py | 7 ++ src/primaite/simulator/sim_container.py | 6 + src/primaite/simulator/system/software.py | 33 +++++ 6 files changed, 135 insertions(+), 60 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 24f9945d..a764703b 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -169,6 +169,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE + - type: NODE_SERVICE_PATCH - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -199,111 +200,110 @@ agents: 1: action: NODE_SERVICE_SCAN options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # stop webapp service 2: action: NODE_SERVICE_STOP options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # start webapp service 3: action: "NODE_SERVICE_START" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 4: action: "NODE_SERVICE_PAUSE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 5: action: "NODE_SERVICE_RESUME" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 6: action: "NODE_SERVICE_RESTART" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 7: action: "NODE_SERVICE_DISABLE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 8: action: "NODE_SERVICE_ENABLE" options: - node_id: 2 - service_id: 1 - 9: + node_id: 1 + service_id: 0 + 9: # check database.db file action: "NODE_FILE_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 11: action: "NODE_FILE_DELETE" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 12: action: "NODE_FILE_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 13: - action: "NODE_FILE_RESTORE" + action: "NODE_SERVICE_PATCH" options: - node_id: 3 - folder_id: 1 - file_id: 1 + node_id: 2 + service_id: 0 14: action: "NODE_FOLDER_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 15: action: "NODE_FOLDER_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 16: action: "NODE_FOLDER_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 17: action: "NODE_FOLDER_RESTORE" options: - node_id: 3 + node_id: 2 folder_id: 1 18: action: "NODE_OS_SCAN" options: - node_id: 3 - 19: + node_id: 2 + 19: # shutdown client 1 action: "NODE_SHUTDOWN" options: - node_id: 6 + node_id: 5 20: action: "NODE_STARTUP" options: - node_id: 6 + node_id: 5 21: action: "NODE_RESET" options: - node_id: 6 + node_id: 5 22: action: "NETWORK_ACL_ADDRULE" options: @@ -407,93 +407,94 @@ agents: 38: action: "NETWORK_NIC_DISABLE" options: - node_id: 1 + node_id: 0 nic_id: 1 39: action: "NETWORK_NIC_ENABLE" options: - node_id: 1 + node_id: 0 nic_id: 1 40: action: "NETWORK_NIC_DISABLE" options: - node_id: 2 + node_id: 1 nic_id: 1 41: action: "NETWORK_NIC_ENABLE" options: - node_id: 2 + node_id: 1 nic_id: 1 42: action: "NETWORK_NIC_DISABLE" options: - node_id: 3 + node_id: 2 nic_id: 1 43: action: "NETWORK_NIC_ENABLE" options: - node_id: 3 + node_id: 2 nic_id: 1 44: action: "NETWORK_NIC_DISABLE" options: - node_id: 4 + node_id: 3 nic_id: 1 45: action: "NETWORK_NIC_ENABLE" options: - node_id: 4 + node_id: 3 nic_id: 1 46: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 + node_id: 4 nic_id: 1 47: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 + node_id: 4 nic_id: 1 48: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 + node_id: 4 nic_id: 2 49: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 + node_id: 4 nic_id: 2 50: action: "NETWORK_NIC_DISABLE" options: - node_id: 6 + node_id: 5 nic_id: 1 51: action: "NETWORK_NIC_ENABLE" options: - node_id: 6 + node_id: 5 nic_id: 1 52: action: "NETWORK_NIC_DISABLE" options: - node_id: 7 + node_id: 6 nic_id: 1 53: action: "NETWORK_NIC_ENABLE" options: - node_id: 7 + node_id: 6 nic_id: 1 options: nodes: - - node_ref: router_1 - - node_ref: switch_1 - - node_ref: switch_2 - node_ref: domain_controller - node_ref: web_server + services: + - service_ref: web_server_web_service - node_ref: database_server + services: + - service_ref: database_service - node_ref: backup_server - node_ref: security_suite - node_ref: client_1 diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 8eed3ba4..4c47bfaa 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -89,7 +89,7 @@ class NodeServiceAbstractAction(AbstractAction): service_uuid = self.manager.get_service_uuid_by_idx(node_id, service_id) if node_uuid is None or service_uuid is None: return ["do_nothing"] - return ["network", "node", node_uuid, "services", service_uuid, self.verb] + return ["network", "node", node_uuid, "service", service_uuid, self.verb] class NodeServiceScanAction(NodeServiceAbstractAction): @@ -156,6 +156,14 @@ class NodeServiceEnableAction(NodeServiceAbstractAction): self.verb: str = "enable" +class NodeServicePatchAction(NodeServiceAbstractAction): + """Action which patches a service.""" + + def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) + self.verb: str = "patch" + + class NodeApplicationAbstractAction(AbstractAction): """ Base class for application actions. @@ -262,7 +270,7 @@ class NodeFileAbstractAction(AbstractAction): file_uuid = self.manager.get_file_uuid_by_idx(node_idx=node_id, folder_idx=folder_id, file_idx=file_id) if node_uuid is None or folder_uuid is None or file_uuid is None: return ["do_nothing"] - return ["network", "node", node_uuid, "file_system", "folder", folder_uuid, "files", file_uuid, self.verb] + return ["network", "node", node_uuid, "file_system", "folder", folder_uuid, "file", file_uuid, self.verb] class NodeFileScanAction(NodeFileAbstractAction): @@ -566,6 +574,7 @@ class ActionManager: "NODE_SERVICE_RESTART": NodeServiceRestartAction, "NODE_SERVICE_DISABLE": NodeServiceDisableAction, "NODE_SERVICE_ENABLE": NodeServiceEnableAction, + "NODE_SERVICE_PATCH": NodeServicePatchAction, "NODE_APPLICATION_EXECUTE": NodeApplicationExecuteAction, "NODE_FILE_SCAN": NodeFileScanAction, "NODE_FILE_CHECKHASH": NodeFileCheckhashAction, @@ -594,6 +603,7 @@ class ActionManager: actions: List[str], # stores list of actions available to agent node_uuids: List[str], # allows mapping index to node application_uuids: List[List[str]], # allows mapping index to application + service_uuids: List[List[str]], # allows mapping index to service max_folders_per_node: int = 2, # allows calculating shape max_files_per_folder: int = 2, # allows calculating shape max_services_per_node: int = 2, # allows calculating shape @@ -635,6 +645,7 @@ class ActionManager: self.game: "PrimaiteGame" = game self.node_uuids: List[str] = node_uuids self.application_uuids: List[List[str]] = application_uuids + self.service_uuids: List[List[str]] = service_uuids self.protocols: List[str] = protocols self.ports: List[str] = ports @@ -804,6 +815,11 @@ class ActionManager: :return: The UUID of the service. Or None if the node has fewer services than the given index. :rtype: Optional[str] """ + # if a mapping was specified, use that mapping, otherwise just use the list of all installed services + if self.service_uuids: + if self.service_uuids[node_idx]: + return self.service_uuids[node_idx][service_idx] + node_uuid = self.get_node_uuid_by_idx(node_idx) node = self.game.simulation.network.nodes[node_uuid] service_uuids = list(node.services.keys()) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 8c32f41d..d2db4bea 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -361,6 +361,7 @@ class PrimaiteGame: # CREATE ACTION SPACE action_space_cfg["options"]["node_uuids"] = [] action_space_cfg["options"]["application_uuids"] = [] + action_space_cfg["options"]["service_uuids"] = [] # if a list of nodes is defined, convert them from node references to node UUIDs for action_node_option in action_space_cfg.get("options", {}).pop("nodes", {}): @@ -375,10 +376,21 @@ class PrimaiteGame: # node_uuid, whereas here the application gets added by uuid. application_uuid = game.ref_map_applications[application_option["application_ref"]] node_application_uuids.append(application_uuid) - action_space_cfg["options"]["application_uuids"].append(node_application_uuids) + else: action_space_cfg["options"]["application_uuids"].append([]) + + if "services" in action_node_option: + node_service_uuids = [] + for service_option in action_node_option["services"]: + service_uuid = game.ref_map_services[service_option["service_ref"]] + node_service_uuids.append(service_uuid) + action_space_cfg["options"]["service_uuids"].append(node_service_uuids) + + else: + action_space_cfg["options"]["service_uuids"].append([]) + # Each action space can potentially have a different list of nodes that it can apply to. Therefore, # we will pass node_uuids as a part of the action space config. # However, it's not possible to specify the node uuids directly in the config, as they are generated diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index fd18e154..d4e72f63 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -102,6 +102,11 @@ class Folder(FileSystemItemABC): name="delete", request_type=RequestType(func=lambda request, context: self.remove_file_by_id(file_uuid=request[0])), ) + self._file_request_manager = RequestManager() + rm.add_request( + name="file", + request_type=RequestType(func=lambda request, context: self._file_request_manager), + ) return rm def describe_state(self) -> Dict: @@ -254,6 +259,7 @@ class Folder(FileSystemItemABC): # add to list self.files[file.uuid] = file self._files_by_name[file.name] = file + self._file_request_manager.add_request(file.uuid, RequestType(func=file._request_manager)) file.folder = self def remove_file(self, file: Optional[File]): @@ -273,6 +279,7 @@ class Folder(FileSystemItemABC): self.deleted_files[file.uuid] = file file.delete() self.sys_log.info(f"Removed file {file.name} (id: {file.uuid})") + self._file_request_manager.remove_request(file.uuid) else: _LOGGER.debug(f"File with UUID {file.uuid} was not found.") diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index c529ed04..db8a718c 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -55,3 +55,9 @@ class Simulation(SimComponent): } ) return state + + def apply_timestep(self, timestep: int) -> None: + """Apply a timestep to the simulation.""" + super().apply_timestep(timestep) + self.network.apply_timestep(timestep) + # self.domain.apply_timestep(timestep) diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 87802a7b..048e6fec 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -89,6 +89,10 @@ class Software(SimComponent): "The FileSystem of the Node the Software is installed on." folder: Optional[Folder] = None "The folder on the file system the Software uses." + patching_duration: int = 2 + "The number of ticks it takes to patch the software." + _patching_countdown: Optional[int] = None + "Current number of ticks left to patch the software." def set_original_state(self): """Sets the original state.""" @@ -111,6 +115,12 @@ class Software(SimComponent): func=lambda request, context: self.set_health_state(SoftwareHealthState.COMPROMISED), ), ) + rm.add_request( + "patch", + RequestType( + func=lambda request, context: self.patch(), + ), + ) rm.add_request("scan", RequestType(func=lambda request, context: self.scan())) return rm @@ -181,10 +191,33 @@ class Software(SimComponent): """Update the observed health status to match the actual health status.""" self.health_state_visible = self.health_state_actual + def patch(self) -> None: + """Perform a patch on the software.""" + self._patching_countdown = self.patching_duration + self.set_health_state(SoftwareHealthState.PATCHING) + + def _update_patch_status(self) -> None: + """Update the patch status of the software.""" + self._patching_countdown -= 1 + if self._patching_countdown <= 0: + self.set_health_state(SoftwareHealthState.GOOD) + self._patching_countdown = None + self.patching_count += 1 + def reveal_to_red(self) -> None: """Reveals the software to the red agent.""" self.revealed_to_red = True + def apply_timestep(self, timestep: int) -> None: + """ + Apply a single timestep to the software. + + :param timestep: The current timestep of the simulation. + """ + super().apply_timestep(timestep) + if self.health_state_actual == SoftwareHealthState.PATCHING: + self._update_patch_status() + class IOSoftware(Software): """ From fa585168de384d59fd79c87199ca6b6cbc2eae2d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 21 Dec 2023 15:10:23 +0000 Subject: [PATCH 489/980] update marl config with service patch bugfix --- .../example_config_2_rl_agents.yaml | 230 +++++++++--------- 1 file changed, 116 insertions(+), 114 deletions(-) diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index 9c2acaae..c1e2ea81 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -165,6 +165,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE + - type: NODE_SERVICE_PATCH - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -195,111 +196,110 @@ agents: 1: action: NODE_SERVICE_SCAN options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # stop webapp service 2: action: NODE_SERVICE_STOP options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # start webapp service 3: action: "NODE_SERVICE_START" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 4: action: "NODE_SERVICE_PAUSE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 5: action: "NODE_SERVICE_RESUME" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 6: action: "NODE_SERVICE_RESTART" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 7: action: "NODE_SERVICE_DISABLE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 8: action: "NODE_SERVICE_ENABLE" options: - node_id: 2 - service_id: 1 - 9: + node_id: 1 + service_id: 0 + 9: # check database.db file action: "NODE_FILE_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 11: action: "NODE_FILE_DELETE" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 12: action: "NODE_FILE_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 13: - action: "NODE_FILE_RESTORE" + action: "NODE_SERVICE_PATCH" options: - node_id: 3 - folder_id: 1 - file_id: 1 + node_id: 2 + service_id: 0 14: action: "NODE_FOLDER_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 15: action: "NODE_FOLDER_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 16: action: "NODE_FOLDER_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 17: action: "NODE_FOLDER_RESTORE" options: - node_id: 3 + node_id: 2 folder_id: 1 18: action: "NODE_OS_SCAN" options: - node_id: 3 - 19: + node_id: 2 + 19: # shutdown client 1 action: "NODE_SHUTDOWN" options: - node_id: 6 + node_id: 5 20: action: "NODE_STARTUP" options: - node_id: 6 + node_id: 5 21: action: "NODE_RESET" options: - node_id: 6 + node_id: 5 22: action: "NETWORK_ACL_ADDRULE" options: @@ -403,93 +403,94 @@ agents: 38: action: "NETWORK_NIC_DISABLE" options: - node_id: 1 + node_id: 0 nic_id: 1 39: action: "NETWORK_NIC_ENABLE" options: - node_id: 1 + node_id: 0 nic_id: 1 40: action: "NETWORK_NIC_DISABLE" options: - node_id: 2 + node_id: 1 nic_id: 1 41: action: "NETWORK_NIC_ENABLE" options: - node_id: 2 + node_id: 1 nic_id: 1 42: action: "NETWORK_NIC_DISABLE" options: - node_id: 3 + node_id: 2 nic_id: 1 43: action: "NETWORK_NIC_ENABLE" options: - node_id: 3 + node_id: 2 nic_id: 1 44: action: "NETWORK_NIC_DISABLE" options: - node_id: 4 + node_id: 3 nic_id: 1 45: action: "NETWORK_NIC_ENABLE" options: - node_id: 4 + node_id: 3 nic_id: 1 46: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 + node_id: 4 nic_id: 1 47: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 + node_id: 4 nic_id: 1 48: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 + node_id: 4 nic_id: 2 49: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 + node_id: 4 nic_id: 2 50: action: "NETWORK_NIC_DISABLE" options: - node_id: 6 + node_id: 5 nic_id: 1 51: action: "NETWORK_NIC_ENABLE" options: - node_id: 6 + node_id: 5 nic_id: 1 52: action: "NETWORK_NIC_DISABLE" options: - node_id: 7 + node_id: 6 nic_id: 1 53: action: "NETWORK_NIC_ENABLE" options: - node_id: 7 + node_id: 6 nic_id: 1 options: nodes: - - node_ref: router_1 - - node_ref: switch_1 - - node_ref: switch_2 - node_ref: domain_controller - node_ref: web_server + services: + - service_ref: web_server_web_service - node_ref: database_server + services: + - service_ref: database_service - node_ref: backup_server - node_ref: security_suite - node_ref: client_1 @@ -597,6 +598,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE + - type: NODE_SERVICE_PATCH - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -627,111 +629,110 @@ agents: 1: action: NODE_SERVICE_SCAN options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # stop webapp service 2: action: NODE_SERVICE_STOP options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # start webapp service 3: action: "NODE_SERVICE_START" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 4: action: "NODE_SERVICE_PAUSE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 5: action: "NODE_SERVICE_RESUME" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 6: action: "NODE_SERVICE_RESTART" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 7: action: "NODE_SERVICE_DISABLE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 8: action: "NODE_SERVICE_ENABLE" options: - node_id: 2 - service_id: 1 - 9: + node_id: 1 + service_id: 0 + 9: # check database.db file action: "NODE_FILE_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 11: action: "NODE_FILE_DELETE" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 12: action: "NODE_FILE_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 13: - action: "NODE_FILE_RESTORE" + action: "NODE_SERVICE_PATCH" options: - node_id: 3 - folder_id: 1 - file_id: 1 + node_id: 2 + service_id: 0 14: action: "NODE_FOLDER_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 15: action: "NODE_FOLDER_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 16: action: "NODE_FOLDER_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 17: action: "NODE_FOLDER_RESTORE" options: - node_id: 3 + node_id: 2 folder_id: 1 18: action: "NODE_OS_SCAN" options: - node_id: 3 - 19: + node_id: 2 + 19: # shutdown client 1 action: "NODE_SHUTDOWN" options: - node_id: 6 + node_id: 5 20: action: "NODE_STARTUP" options: - node_id: 6 + node_id: 5 21: action: "NODE_RESET" options: - node_id: 6 + node_id: 5 22: action: "NETWORK_ACL_ADDRULE" options: @@ -835,93 +836,94 @@ agents: 38: action: "NETWORK_NIC_DISABLE" options: - node_id: 1 + node_id: 0 nic_id: 1 39: action: "NETWORK_NIC_ENABLE" options: - node_id: 1 + node_id: 0 nic_id: 1 40: action: "NETWORK_NIC_DISABLE" options: - node_id: 2 + node_id: 1 nic_id: 1 41: action: "NETWORK_NIC_ENABLE" options: - node_id: 2 + node_id: 1 nic_id: 1 42: action: "NETWORK_NIC_DISABLE" options: - node_id: 3 + node_id: 2 nic_id: 1 43: action: "NETWORK_NIC_ENABLE" options: - node_id: 3 + node_id: 2 nic_id: 1 44: action: "NETWORK_NIC_DISABLE" options: - node_id: 4 + node_id: 3 nic_id: 1 45: action: "NETWORK_NIC_ENABLE" options: - node_id: 4 + node_id: 3 nic_id: 1 46: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 + node_id: 4 nic_id: 1 47: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 + node_id: 4 nic_id: 1 48: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 + node_id: 4 nic_id: 2 49: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 + node_id: 4 nic_id: 2 50: action: "NETWORK_NIC_DISABLE" options: - node_id: 6 + node_id: 5 nic_id: 1 51: action: "NETWORK_NIC_ENABLE" options: - node_id: 6 + node_id: 5 nic_id: 1 52: action: "NETWORK_NIC_DISABLE" options: - node_id: 7 + node_id: 6 nic_id: 1 53: action: "NETWORK_NIC_ENABLE" options: - node_id: 7 + node_id: 6 nic_id: 1 options: nodes: - - node_ref: router_1 - - node_ref: switch_1 - - node_ref: switch_2 - node_ref: domain_controller - node_ref: web_server + services: + - service_ref: web_server_web_service - node_ref: database_server + services: + - service_ref: database_service - node_ref: backup_server - node_ref: security_suite - node_ref: client_1 From 2135bdcd103e367f2b535d0f095ba707bbebe488 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 21 Dec 2023 16:08:09 +0000 Subject: [PATCH 490/980] Add unit test --- src/primaite/simulator/sim_container.py | 1 - .../_system/_services/test_service_actions.py | 13 +++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index db8a718c..896861e6 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -60,4 +60,3 @@ class Simulation(SimComponent): """Apply a timestep to the simulation.""" super().apply_timestep(timestep) self.network.apply_timestep(timestep) - # self.domain.apply_timestep(timestep) diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py index 6b2ee0a7..714644e4 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py @@ -78,3 +78,16 @@ def test_service_enable(service): service.apply_request(["enable"]) assert service.operating_state == ServiceOperatingState.STOPPED + + +def test_service_patch(service): + """Test that a service can be patched and that it takes two timesteps to complete.""" + service.start() + assert service.health_state_actual == SoftwareHealthState.GOOD + + service.apply_request(["patch"]) + assert service.health_state_actual == SoftwareHealthState.PATCHING + service.apply_timestep(1) + assert service.health_state_actual == SoftwareHealthState.PATCHING + service.apply_timestep(2) + assert service.health_state_actual == SoftwareHealthState.GOOD From ade5f133d0491398e090cebe8213778183fb3e5b Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 22 Dec 2023 10:31:11 +0000 Subject: [PATCH 491/980] #2139 - Implemented routing --- CHANGELOG.md | 4 + src/primaite/simulator/network/creation.py | 148 ++++++++++++++++++ .../simulator/network/hardware/base.py | 26 +-- .../network/hardware/nodes/router.py | 148 ++++++++++++++---- .../network/hardware/nodes/switch.py | 4 +- .../integration_tests/network/test_routing.py | 93 +++++++++++ 6 files changed, 381 insertions(+), 42 deletions(-) create mode 100644 src/primaite/simulator/network/creation.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 541a39d5..96634b28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,10 @@ SessionManager. - Fixed an issue where the services were still able to run even though the node the service is installed on is turned off - NTP Services: `NTPClient` and `NTPServer` +### Changed +- Integrated the RouteTable into the Routers frame processing. +- Frames are now dropped when their TTL reaches 0 + ### Removed - Removed legacy simulation modules: `acl`, `common`, `environment`, `links`, `nodes`, `pol` - Removed legacy training modules diff --git a/src/primaite/simulator/network/creation.py b/src/primaite/simulator/network/creation.py new file mode 100644 index 00000000..48313a1f --- /dev/null +++ b/src/primaite/simulator/network/creation.py @@ -0,0 +1,148 @@ +from ipaddress import IPv4Address +from typing import Optional + +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port + + +def num_of_switches_required(num_nodes: int, max_switch_ports: int = 24) -> int: + """ + Calculate the minimum number of network switches required to connect a given number of nodes. + + Each switch is assumed to have one port reserved for connecting to a router, reducing the effective + number of ports available for PCs. The function calculates the total number of switches needed + to accommodate all nodes under this constraint. + + :param num_nodes: The total number of nodes that need to be connected in the network. + :param max_switch_ports: The maximum number of ports available on each switch. Defaults to 24. + + :return: The minimum number of switches required to connect all PCs. + + Example: + >>> num_of_switches_required(5) + 1 + >>> num_of_switches_required(24,24) + 2 + >>> num_of_switches_required(48,24) + 3 + >>> num_of_switches_required(25,10) + 3 + """ + # Reduce the effective number of switch ports by 1 to leave space for the router + effective_switch_ports = max_switch_ports - 1 + + # Calculate the number of fully utilised switches and any additional switch for remaining PCs + full_switches = num_nodes // effective_switch_ports + extra_pcs = num_nodes % effective_switch_ports + + # Return the total number of switches required + return full_switches + (1 if extra_pcs > 0 else 0) + + +def create_office_lan( + lan_name: str, + subnet_base: int, + pcs_ip_block_start: int, + num_pcs: int, + network: Optional[Network] = None, + include_router: bool = True, +) -> Network: + """ + Creates a 2-Tier or 3-Tier office local area network (LAN). + + The LAN is configured with a specified number of personal computers (PCs), optionally including a router, + and multiple edge switches to connect them. A core switch is added only if more than one edge switch is required. + The network topology involves edge switches connected either directly to the router in a 2-Tier setup or + to a core switch in a 3-Tier setup. If a router is included, it is connected to the core switch (if present) + and configured with basic access control list (ACL) rules. PCs are distributed across the edge switches. + + + :param str lan_name: The name to be assigned to the LAN. + :param int subnet_base: The subnet base number to be used in the IP addresses. + :param int pcs_ip_block_start: The starting block for assigning IP addresses to PCs. + :param int num_pcs: The number of PCs to be added to the LAN. + :param Optional[Network] network: The network to which the LAN components will be added. If None, a new network is + created. + :param bool include_router: Flag to determine if a router should be included in the LAN. Defaults to True. + :return: The network object with the LAN components added. + :raises ValueError: If pcs_ip_block_start is less than or equal to the number of required switches. + """ + # Initialise the network if not provided + if not network: + network = Network() + + # Calculate the required number of switches + num_of_switches = num_of_switches_required(num_nodes=num_pcs) + effective_switch_ports = 23 # One port less for router connection + if pcs_ip_block_start <= num_of_switches: + raise ValueError(f"pcs_ip_block_start must be greater than the number of required switches {num_of_switches}") + + # Create a core switch if more than one edge switch is needed + if num_of_switches > 1: + core_switch = Switch(hostname=f"switch_core_{lan_name}", start_up_duration=0) + core_switch.power_on() + network.add_node(core_switch) + core_switch_port = 1 + + # Initialise the default gateway to None + default_gateway = None + + # Optionally include a router in the LAN + if include_router: + default_gateway = IPv4Address(f"192.168.{subnet_base}.1") + router = Router(hostname=f"router_{lan_name}", start_up_duration=0) + router.power_on() + router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) + router.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + network.add_node(router) + router.configure_port(port=1, ip_address=default_gateway, subnet_mask="255.255.255.0") + router.enable_port(1) + + # Initialise the first edge switch and connect to the router or core switch + switch_port = 0 + switch_n = 1 + switch = Switch(hostname=f"switch_edge_{switch_n}_{lan_name}", start_up_duration=0) + switch.power_on() + network.add_node(switch) + if num_of_switches > 1: + network.connect(core_switch.switch_ports[core_switch_port], switch.switch_ports[24]) + else: + network.connect(router.ethernet_ports[1], switch.switch_ports[24]) + + # Add PCs to the LAN and connect them to switches + for i in range(1, num_pcs + 1): + # Add a new edge switch if the current one is full + if switch_port == effective_switch_ports: + switch_n += 1 + switch_port = 0 + switch = Switch(hostname=f"switch_edge_{switch_n}_{lan_name}", start_up_duration=0) + switch.power_on() + network.add_node(switch) + # Connect the new switch to the router or core switch + if num_of_switches > 1: + core_switch_port += 1 + network.connect(core_switch.switch_ports[core_switch_port], switch.switch_ports[24]) + else: + network.connect(router.ethernet_ports[1], switch.switch_ports[24]) + + # Create and add a PC to the network + pc = Computer( + hostname=f"pc_{i}_{lan_name}", + ip_address=f"192.168.{subnet_base}.{i+pcs_ip_block_start-1}", + subnet_mask="255.255.255.0", + default_gateway=default_gateway, + start_up_duration=0, + ) + pc.power_on() + network.add_node(pc) + + # Connect the PC to the switch + switch_port += 1 + network.connect(switch.switch_ports[switch_port], pc.ethernet_port[1]) + switch.switch_ports[switch_port].enable() + + return network diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index ad3d73aa..c27378a8 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -4,7 +4,7 @@ import re import secrets from ipaddress import IPv4Address, IPv4Network from pathlib import Path -from typing import Any, Dict, Literal, Optional, Tuple, Union +from typing import Any, Dict, List, Literal, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable @@ -282,6 +282,9 @@ class NIC(SimComponent): """ if self.enabled: frame.decrement_ttl() + if frame.ip and frame.ip.ttl < 1: + self._connected_node.sys_log.info("Frame discarded as TTL limit reached") + return False frame.set_received_timestamp() self.pcap.capture(frame) # If this destination or is broadcast @@ -436,6 +439,9 @@ class SwitchPort(SimComponent): """ if self.enabled: frame.decrement_ttl() + if frame.ip and frame.ip.ttl < 1: + self._connected_node.sys_log.info("Frame discarded as TTL limit reached") + return False self.pcap.capture(frame) connected_node: Node = self._connected_node connected_node.forward_frame(frame=frame, incoming_port=self) @@ -671,7 +677,9 @@ class ARPCache: """Clear the entire ARP cache, removing all stored entries.""" self.arp.clear() - def send_arp_request(self, target_ip_address: Union[IPv4Address, str]): + def send_arp_request( + self, target_ip_address: Union[IPv4Address, str], ignore_networks: Optional[List[IPv4Address]] = None + ): """ Perform a standard ARP request for a given target IP address. @@ -681,7 +689,12 @@ class ARPCache: :param target_ip_address: The target IP address to send an ARP request for. """ for nic in self.nics.values(): - if nic.enabled: + use_nic = True + if ignore_networks: + for ipv4 in ignore_networks: + if ipv4 in nic.ip_network: + use_nic = False + if nic.enabled and use_nic: self.sys_log.info(f"Sending ARP request from NIC {nic} for ip {target_ip_address}") tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) @@ -806,7 +819,6 @@ class ICMP: self.arp.send_arp_request(frame.ip.src_ip_address) self.process_icmp(frame=frame, from_nic=from_nic, is_reattempt=True) return - tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) # Network Layer ip_packet = IPPacket( @@ -821,9 +833,7 @@ class ICMP: sequence=frame.icmp.sequence + 1, ) payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size - frame = Frame( - ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_reply_packet, payload=payload - ) + frame = Frame(ethernet=ethernet_header, ip=ip_packet, icmp=icmp_reply_packet, payload=payload) self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip_address}") src_nic.send_frame(frame) @@ -1447,7 +1457,6 @@ class Node(SimComponent): service.parent = self service.install() # Perform any additional setup, such as creating files for this service on the node. self.sys_log.info(f"Installed service {service.name}") - _LOGGER.info(f"Added service {service.uuid} to node {self.uuid}") self._service_request_manager.add_request(service.uuid, RequestType(func=service._request_manager)) def uninstall_service(self, service: Service) -> None: @@ -1480,7 +1489,6 @@ class Node(SimComponent): self.applications[application.uuid] = application application.parent = self self.sys_log.info(f"Installed application {application.name}") - _LOGGER.info(f"Added application {application.uuid} to node {self.uuid}") self._application_request_manager.add_request(application.uuid, RequestType(func=application._request_manager)) def uninstall_application(self, application: Application) -> None: diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 0234934d..1e3d8022 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -324,11 +324,10 @@ class RouteEntry(SimComponent): """ Represents a single entry in a routing table. - Attributes: - address (IPv4Address): The destination IP address or network address. - subnet_mask (IPv4Address): The subnet mask for the network. - next_hop_ip_address (IPv4Address): The next hop IP address to which packets should be forwarded. - metric (int): The cost metric for this route. Default is 0.0. + :ivar address: The destination IP address or network address. + :ivar subnet_mask: The subnet mask for the network. + :ivar next_hop_ip_address: The next hop IP address to which packets should be forwarded. + :ivar metric: The cost metric for this route. Default is 0.0. Example: >>> entry = RouteEntry( @@ -348,12 +347,6 @@ class RouteEntry(SimComponent): metric: float = 0.0 "The cost metric for this route. Default is 0.0." - def __init__(self, **kwargs): - for key in {"address", "subnet_mask", "next_hop_ip_address"}: - if not isinstance(kwargs[key], IPv4Address): - kwargs[key] = IPv4Address(kwargs[key]) - super().__init__(**kwargs) - def set_original_state(self): """Sets the original state.""" vals_to_include = {"address", "subnet_mask", "next_hop_ip_address", "metric"} @@ -388,6 +381,7 @@ class RouteTable(SimComponent): """ routes: List[RouteEntry] = [] + default_route: Optional[RouteEntry] = None sys_log: SysLog def set_original_state(self): @@ -433,12 +427,35 @@ class RouteTable(SimComponent): ) self.routes.append(route) + def set_default_route_next_hop_ip_address(self, ip_address: IPv4Address): + """ + Sets the next-hop IP address for the default route in a routing table. + + This method checks if a default route (0.0.0.0/0) exists in the routing table. If it does not exist, + the method creates a new default route with the specified next-hop IP address. If a default route already + exists, it updates the next-hop IP address of the existing default route. After setting the next-hop + IP address, the method logs this action. + + :param ip_address: The next-hop IP address to be set for the default route. + """ + if not self.default_route: + self.default_route = RouteEntry( + ip_address=IPv4Address("0.0.0.0"), + subnet_mask=IPv4Address("0.0.0.0"), + next_hop_ip_address=ip_address, + ) + else: + self.default_route.next_hop_ip_address = ip_address + self.sys_log.info(f"Default configured to use {ip_address} as the next-hop") + def find_best_route(self, destination_ip: Union[str, IPv4Address]) -> Optional[RouteEntry]: """ Find the best route for a given destination IP. This method uses the Longest Prefix Match algorithm and considers metrics to find the best route. + If no dedicated route exists but a default route does, then the default route is returned as a last resort. + :param destination_ip: The destination IP to find the route for. :return: The best matching RouteEntry, or None if no route matches. """ @@ -458,6 +475,9 @@ class RouteTable(SimComponent): longest_prefix = prefix_len lowest_metric = route.metric + if not best_route and self.default_route: + best_route = self.default_route + return best_route def show(self, markdown: bool = False): @@ -489,12 +509,26 @@ class RouterARPCache(ARPCache): super().__init__(sys_log) self.router: Router = router - def process_arp_packet(self, from_nic: NIC, frame: Frame): + def process_arp_packet( + self, from_nic: NIC, frame: Frame, route_table: RouteTable, is_reattempt: bool = False + ) -> None: """ - Overridden method to process a received ARP packet in a router-specific way. + Processes a received ARP (Address Resolution Protocol) packet in a router-specific way. + + This method is responsible for handling both ARP requests and responses. It processes ARP packets received on a + Network Interface Card (NIC) and performs actions based on whether the packet is a request or a reply. This + includes updating the ARP cache, forwarding ARP replies, sending ARP requests for unknown destinations, and + handling packet TTL (Time To Live). + + The method first checks if the ARP packet is a request or a reply. For ARP replies, it updates the ARP cache + and forwards the reply if necessary. For ARP requests, it checks if the target IP matches one of the router's + NICs and sends an ARP reply if so. If the destination is not directly connected, it consults the routing table + to find the best route and reattempts ARP request processing if needed. :param from_nic: The NIC that received the ARP packet. - :param frame: The original ARP frame. + :param frame: The frame containing the ARP packet. + :param route_table: The routing table of the router. + :param is_reattempt: Flag to indicate if this is a reattempt of processing the ARP packet, defaults to False. """ arp_packet = frame.arp @@ -522,7 +556,11 @@ class RouterARPCache(ARPCache): ) arp_packet.sender_mac_addr = nic.mac_address frame.decrement_ttl() + if frame.ip and frame.ip.ttl < 1: + self.sys_log.info("Frame discarded as TTL limit reached") + return nic.send_frame(frame) + return # ARP Request self.sys_log.info( @@ -533,16 +571,32 @@ class RouterARPCache(ARPCache): self.add_arp_cache_entry( ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic ) - arp_packet = arp_packet.generate_reply(from_nic.mac_address) - self.send_arp_reply(arp_packet, from_nic) # If the target IP matches one of the router's NICs for nic in self.nics.values(): - if nic.enabled and nic.ip_address == arp_packet.target_ip_address: + if arp_packet.target_ip_address in nic.ip_network: + # if nic.enabled and nic.ip_address == arp_packet.target_ip_address: arp_reply = arp_packet.generate_reply(from_nic.mac_address) self.send_arp_reply(arp_reply, from_nic) return + # Check Route Table + route = route_table.find_best_route(arp_packet.target_ip_address) + if route: + nic = self.get_arp_cache_nic(route.next_hop_ip_address) + + if not nic: + if not is_reattempt: + self.send_arp_request(route.next_hop_ip_address, ignore_networks=[frame.ip.src_ip_address]) + return self.process_arp_packet(from_nic, frame, route_table, is_reattempt=True) + else: + pass + # TODO: destination unavailable/No ARP netry found + else: + arp_reply = arp_packet.generate_reply(from_nic.mac_address) + self.send_arp_reply(arp_reply, from_nic) + return + class RouterICMP(ICMP): """ @@ -613,7 +667,7 @@ class RouterICMP(ICMP): return # Route the frame - self.router.route_frame(frame, from_nic) + self.router.process_frame(frame, from_nic) elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: for nic in self.router.nics.values(): @@ -633,7 +687,7 @@ class RouterICMP(ICMP): return # Route the frame - self.router.route_frame(frame, from_nic) + self.router.process_frame(frame, from_nic) class Router(Node): @@ -720,9 +774,9 @@ class Router(Node): state["acl"] = (self.acl.describe_state(),) return state - def route_frame(self, frame: Frame, from_nic: NIC, re_attempt: bool = False) -> None: + def process_frame(self, frame: Frame, from_nic: NIC, re_attempt: bool = False) -> None: """ - Route a given frame from a source NIC to its destination. + Process a Frame. :param frame: The frame to be routed. :param from_nic: The source network interface. @@ -737,8 +791,10 @@ class Router(Node): return if not nic: - self.arp.send_arp_request(frame.ip.dst_ip_address) - return self.route_frame(frame=frame, from_nic=from_nic, re_attempt=True) + self.arp.send_arp_request( + frame.ip.dst_ip_address, ignore_networks=[frame.ip.src_ip_address, from_nic.ip_address] + ) + return self.process_frame(frame=frame, from_nic=from_nic, re_attempt=True) if not nic.enabled: # TODO: Add sys_log here @@ -747,15 +803,45 @@ class Router(Node): if frame.ip.dst_ip_address in nic.ip_network: from_port = self._get_port_of_nic(from_nic) to_port = self._get_port_of_nic(nic) - self.sys_log.info(f"Routing frame to internally from port {from_port} to port {to_port}") + self.sys_log.info(f"Forwarding frame to internally from port {from_port} to port {to_port}") frame.decrement_ttl() + if frame.ip and frame.ip.ttl < 1: + self.sys_log.info("Frame discarded as TTL limit reached") + return frame.ethernet.src_mac_addr = nic.mac_address frame.ethernet.dst_mac_addr = target_mac nic.send_frame(frame) return else: - pass - # TODO: Deal with routing from route tables + self._route_frame(frame, from_nic) + + def _route_frame(self, frame: Frame, from_nic: NIC, re_attempt: bool = False) -> None: + route = self.route_table.find_best_route(frame.ip.dst_ip_address) + if route: + nic = self.arp.get_arp_cache_nic(route.next_hop_ip_address) + target_mac = self.arp.get_arp_cache_mac_address(route.next_hop_ip_address) + if re_attempt and not nic: + self.sys_log.info(f"Destination {frame.ip.dst_ip_address} is unreachable") + return + + if not nic: + self.arp.send_arp_request(frame.ip.dst_ip_address, ignore_networks=[frame.ip.src_ip_address]) + return self.process_frame(frame=frame, from_nic=from_nic, re_attempt=True) + + if not nic.enabled: + # TODO: Add sys_log here + return + + from_port = self._get_port_of_nic(from_nic) + to_port = self._get_port_of_nic(nic) + self.sys_log.info(f"Routing frame to internally from port {from_port} to port {to_port}") + frame.decrement_ttl() + if frame.ip and frame.ip.ttl < 1: + self.sys_log.info("Frame discarded as TTL limit reached") + return + frame.ethernet.src_mac_addr = nic.mac_address + frame.ethernet.dst_mac_addr = target_mac + nic.send_frame(frame) def receive_frame(self, frame: Frame, from_nic: NIC): """ @@ -764,7 +850,7 @@ class Router(Node): :param frame: The incoming frame. :param from_nic: The network interface where the frame is coming from. """ - route_frame = False + process_frame = False protocol = frame.ip.protocol src_ip_address = frame.ip.src_ip_address dst_ip_address = frame.ip.dst_ip_address @@ -796,12 +882,12 @@ class Router(Node): self.icmp.process_icmp(frame=frame, from_nic=from_nic) else: if src_port == Port.ARP: - self.arp.process_arp_packet(from_nic=from_nic, frame=frame) + self.arp.process_arp_packet(from_nic=from_nic, frame=frame, route_table=self.route_table) else: # All other traffic - route_frame = True - if route_frame: - self.route_frame(frame, from_nic) + process_frame = True + if process_frame: + self.process_frame(frame, from_nic) def configure_port(self, port: int, ip_address: Union[IPv4Address, str], subnet_mask: Union[IPv4Address, str]): """ diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/switch.py index fffae6e2..ead857f2 100644 --- a/src/primaite/simulator/network/hardware/nodes/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/switch.py @@ -90,12 +90,12 @@ class Switch(Node): self._add_mac_table_entry(src_mac, incoming_port) outgoing_port = self.mac_address_table.get(dst_mac) - if outgoing_port or dst_mac != "ff:ff:ff:ff:ff:ff": + if outgoing_port and dst_mac != "ff:ff:ff:ff:ff:ff": outgoing_port.send_frame(frame) else: # If the destination MAC is not in the table, flood to all ports except incoming for port in self.switch_ports.values(): - if port != incoming_port: + if port.enabled and port != incoming_port: port.send_frame(frame) def disconnect_link_from_port(self, link: Link, port_number: int): diff --git a/tests/integration_tests/network/test_routing.py b/tests/integration_tests/network/test_routing.py index 6053c457..3f636eae 100644 --- a/tests/integration_tests/network/test_routing.py +++ b/tests/integration_tests/network/test_routing.py @@ -1,8 +1,11 @@ +from ipaddress import IPv4Address from typing import Tuple import pytest +from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -34,6 +37,69 @@ def pc_a_pc_b_router_1() -> Tuple[Node, Node, Router]: return pc_a, pc_b, router_1 +@pytest.fixture(scope="function") +def multi_hop_network() -> Network: + network = Network() + + # Configure PC A + pc_a = Computer( + hostname="pc_a", + ip_address="192.168.0.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.0.1", + start_up_duration=0, + ) + pc_a.power_on() + network.add_node(pc_a) + + # Configure Router 1 + router_1 = Router(hostname="router_1", start_up_duration=0) + router_1.power_on() + network.add_node(router_1) + + # Configure the connection between PC A and Router 1 port 2 + router_1.configure_port(2, "192.168.0.1", "255.255.255.0") + network.connect(pc_a.ethernet_port[1], router_1.ethernet_ports[2]) + router_1.enable_port(2) + + # Configure Router 1 ACLs + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) + router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + + # Configure PC B + pc_b = Computer( + hostname="pc_b", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.2.1", + start_up_duration=0, + ) + pc_b.power_on() + network.add_node(pc_b) + + # Configure Router 2 + router_2 = Router(hostname="router_2", start_up_duration=0) + router_2.power_on() + network.add_node(router_2) + + # Configure the connection between PC B and Router 2 port 2 + router_2.configure_port(2, "192.168.2.1", "255.255.255.0") + network.connect(pc_b.ethernet_port[1], router_2.ethernet_ports[2]) + router_2.enable_port(2) + + # Configure Router 2 ACLs + router_2.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) + router_2.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + + # Configure the connection between Router 1 port 1 and Router 2 port 1 + router_2.configure_port(1, "192.168.1.2", "255.255.255.252") + router_1.configure_port(1, "192.168.1.1", "255.255.255.252") + network.connect(router_1.ethernet_ports[1], router_2.ethernet_ports[1]) + router_1.enable_port(1) + router_2.enable_port(1) + return network + + def test_ping_default_gateway(pc_a_pc_b_router_1): pc_a, pc_b, router_1 = pc_a_pc_b_router_1 @@ -50,3 +116,30 @@ def test_host_on_other_subnet(pc_a_pc_b_router_1): pc_a, pc_b, router_1 = pc_a_pc_b_router_1 assert pc_a.ping("192.168.1.10") + + +def test_no_route_no_ping(multi_hop_network): + pc_a = multi_hop_network.get_node_by_hostname("pc_a") + pc_b = multi_hop_network.get_node_by_hostname("pc_b") + + assert not pc_a.ping(pc_b.ethernet_port[1].ip_address) + + +def test_with_routes_can_ping(multi_hop_network): + pc_a = multi_hop_network.get_node_by_hostname("pc_a") + pc_b = multi_hop_network.get_node_by_hostname("pc_b") + + router_1: Router = multi_hop_network.get_node_by_hostname("router_1") # noqa + router_2: Router = multi_hop_network.get_node_by_hostname("router_2") # noqa + + # Configure Route from Router 1 to PC B subnet + router_1.route_table.add_route( + address="192.168.2.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.2" + ) + + # Configure Route from Router 2 to PC A subnet + router_2.route_table.add_route( + address="192.168.0.2", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.1" + ) + + assert pc_a.ping(pc_b.ethernet_port[1].ip_address) From 3adf1f9f6aa89927367d298a8f78e1f2a26db443 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 3 Jan 2024 14:49:40 +0000 Subject: [PATCH 492/980] bump version --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index 6da222f2..0fd919fd 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0b3dev +3.0.0b4dev From 48f1d13fd86c39f2b78b6c41dc00b7709a502c3e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 3 Jan 2024 16:23:44 +0000 Subject: [PATCH 493/980] Minor refactor and add comment --- src/primaite/game/agent/actions.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index ff063dbd..9b6b63cc 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -527,14 +527,7 @@ class NetworkNICAbstractAction(AbstractAction): nic_num = self.manager.get_nic_num_by_idx(node_idx=node_id, nic_idx=nic_id) if node_name is None or nic_num is None: return ["do_nothing"] - return [ - "network", - "node", - node_name, - "nic", - nic_num, - self.verb, - ] + return ["network", "node", node_name, "nic", nic_num, self.verb] class NetworkNICEnableAction(NetworkNICAbstractAction): @@ -610,8 +603,8 @@ class ActionManager: :type game: PrimaiteGame :param actions: List of action types which should be made available to the agent. :type actions: List[str] - :param node_uuids: List of node UUIDs that this agent can act on. - :type node_uuids: List[str] + :param nodes: Extra configuration for each node. + :type nodes: Dict :param max_folders_per_node: Maximum number of folders per node. Used for calculating action shape. :type max_folders_per_node: int :param max_files_per_folder: Maximum number of files per folder. Used for calculating action shape. @@ -690,6 +683,13 @@ class ActionManager: self.ports: List[str] = ports self.ip_address_list: List[str] + + # If the user has provided a list of IP addresses, use that. Otherwise, generate a list of IP addresses from + # the nodes in the simulation. + # TODO: refactor. Options: + # 1: This should be pulled out into it's own function for clarity + # 2: The simulation itself should be able to provide a list of IP addresses with its API, rather than having to + # go through the nodes here. if ip_address_list is not None: self.ip_address_list = ip_address_list else: @@ -936,7 +936,6 @@ class ActionManager: obj = cls( game=game, actions=cfg["action_list"], - # node_uuids=cfg["options"]["node_uuids"], **cfg["options"], protocols=game.options.protocols, ports=game.options.ports, From 25c8ec2ec9f085a5b90870b77c90b44167ba9c1e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 3 Jan 2024 18:19:10 +0000 Subject: [PATCH 494/980] Add skeleton for action integration and unit tests --- src/primaite/game/agent/actions.py | 11 +- .../game_layer/test_actions.py | 185 ++++++++++++++++++ tests/unit_tests/_primaite/_game/__init__.py | 0 .../_primaite/_game/_agent/__init__.py | 0 .../_primaite/_game/_agent/test_actions.py | 90 +++++++++ 5 files changed, 281 insertions(+), 5 deletions(-) create mode 100644 tests/integration_tests/game_layer/test_actions.py create mode 100644 tests/unit_tests/_primaite/_game/__init__.py create mode 100644 tests/unit_tests/_primaite/_game/_agent/__init__.py create mode 100644 tests/unit_tests/_primaite/_game/_agent/test_actions.py diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 9b6b63cc..d65cd8d0 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -549,7 +549,7 @@ class NetworkNICDisableAction(NetworkNICAbstractAction): class ActionManager: """Class which manages the action space for an agent.""" - __act_class_identifiers: Dict[str, type] = { + _act_class_identifiers: Dict[str, type] = { "DONOTHING": DoNothingAction, "NODE_SERVICE_SCAN": NodeServiceScanAction, "NODE_SERVICE_STOP": NodeServiceStopAction, @@ -584,7 +584,7 @@ class ActionManager: def __init__( self, game: "PrimaiteGame", # reference to game for information lookup - actions: List[str], # stores list of actions available to agent + actions: List[Dict], # stores list of actions available to agent nodes: List[Dict], # extra configuration for each node max_folders_per_node: int = 2, # allows calculating shape max_files_per_folder: int = 2, # allows calculating shape @@ -601,8 +601,9 @@ class ActionManager: :param game: Reference to the game to which the agent belongs. :type game: PrimaiteGame - :param actions: List of action types which should be made available to the agent. - :type actions: List[str] + :param actions: List of action specs which should be made available to the agent. The keys of each spec are: + 'type' and 'options' for passing any options to the action class's init method + :type actions: List[dict] :param nodes: Extra configuration for each node. :type nodes: Dict :param max_folders_per_node: Maximum number of folders per node. Used for calculating action shape. @@ -728,7 +729,7 @@ class ActionManager: # and `options` is an optional dict of options to pass to the init method of the action class act_type = act_spec.get("type") act_options = act_spec.get("options", {}) - self.actions[act_type] = self.__act_class_identifiers[act_type](self, **global_action_args, **act_options) + self.actions[act_type] = self._act_class_identifiers[act_type](self, **global_action_args, **act_options) self.action_map: Dict[int, Tuple[str, Dict]] = {} """ diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py new file mode 100644 index 00000000..37a680c8 --- /dev/null +++ b/tests/integration_tests/game_layer/test_actions.py @@ -0,0 +1,185 @@ +# Plan for creating integration tests for the actions: +# I need to test that the requests coming out of the actions have the intended effect on the simulation. +# I can do this by creating a simulation, and then running the action on the simulation, and then checking +# the state of the simulation. + +# Steps for creating the integration tests: +# 1. Create a fixture which creates a simulation. +# 2. Create a fixture which creates a game, including a simple agent with some actions. +# 3. Get the agent to perform an action of my choosing. +# 4. Check that the simulation has changed in the way that I expect. +# 5. Repeat for all actions. + +import pytest + +from primaite.game.agent.actions import ActionManager +from primaite.game.agent.interface import ProxyAgent +from primaite.game.agent.observations import ObservationManager +from primaite.game.agent.rewards import RewardFunction +from primaite.game.game import PrimaiteGame +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.sim_container import Simulation +from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer +from primaite.simulator.system.services.web_server.web_server import WebServer + + +def install_stuff_to_sim(sim: Simulation): + """Create a simulation with a three computers, two switches, and a router.""" + + # 0: Pull out the network + network = sim.network + + # 1: Set up network hardware + # 1.1: Configure the router + router = Router(hostname="router", num_ports=3) + router.power_on() + router.configure_port(port=1, ip_address="10.0.1.1", subnet_mask="255.255.255.0") + router.configure_port(port=2, ip_address="10.0.2.1", subnet_mask="255.255.255.0") + + # 1.2: Create and connect switches + switch_1 = Switch(hostname="switch_1", num_ports=6) + switch_1.power_on() + network.connect(endpoint_a=router.ethernet_ports[1], endpoint_b=switch_1.switch_ports[6]) + router.enable_port(1) + switch_2 = Switch(hostname="switch_2", num_ports=6) + switch_2.power_on() + network.connect(endpoint_a=router.ethernet_ports[2], endpoint_b=switch_2.switch_ports[6]) + router.enable_port(2) + + # 1.3: Create and connect computer + client_1 = Computer( + hostname="client_1", + ip_address="10.0.1.2", + subnet_mask="255.255.255.0", + default_gateway="10.0.1.1", + operating_state=NodeOperatingState.ON, + ) + client_1.power_on() + network.connect( + endpoint_a=client_1.ethernet_port[1], + endpoint_b=switch_1.switch_ports[1], + ) + + # 1.4: Create and connect servers + server_1 = Server( + hostname="server_1", + ip_address="10.0.2.2", + subnet_mask="255.255.255.0", + default_gateway="10.0.2.1", + operating_state=NodeOperatingState.ON, + ) + server_1.power_on() + network.connect(endpoint_a=server_1.ethernet_port[1], endpoint_b=switch_2.switch_ports[1]) + + server_2 = Server( + hostname="server_2", + ip_address="10.0.2.3", + subnet_mask="255.255.255.0", + default_gateway="10.0.2.1", + operating_state=NodeOperatingState.ON, + ) + server_2.power_on() + network.connect(endpoint_a=server_2.ethernet_port[1], endpoint_b=switch_2.switch_ports[2]) + + # 2: Configure base ACL + router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) + router.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.DNS, dst_port=Port.DNS, position=1) + router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.HTTP, dst_port=Port.HTTP, position=3) + + # 3: Install server software + server_1.software_manager.install(DNSServer) + dns_service: DNSServer = server_1.software_manager.software.get("DNSServer") # noqa + dns_service.dns_register("example.com", server_2.ip_address) + server_2.software_manager.install(WebServer) + + # 4: Check that client came pre-installed with web browser and dns client + assert isinstance(client_1.software_manager.software.get("WebBrowser"), WebBrowser) + assert isinstance(client_1.software_manager.software.get("DNSClient"), DNSClient) + + # 5: Return the simulation + return sim + + +@pytest.fixture +def game(): + """Create a game with a simple agent that can be controlled by the tests.""" + game = PrimaiteGame() + sim = game.simulation + install_stuff_to_sim(sim) + + actions = [ + {"type": "DONOTHING"}, + {"type": "NODE_SERVICE_SCAN"}, + {"type": "NODE_SERVICE_STOP"}, + {"type": "NODE_SERVICE_START"}, + {"type": "NODE_SERVICE_PAUSE"}, + {"type": "NODE_SERVICE_RESUME"}, + {"type": "NODE_SERVICE_RESTART"}, + {"type": "NODE_SERVICE_DISABLE"}, + {"type": "NODE_SERVICE_ENABLE"}, + {"type": "NODE_APPLICATION_EXECUTE"}, + {"type": "NODE_FILE_SCAN"}, + {"type": "NODE_FILE_CHECKHASH"}, + {"type": "NODE_FILE_DELETE"}, + {"type": "NODE_FILE_REPAIR"}, + {"type": "NODE_FILE_RESTORE"}, + {"type": "NODE_FILE_CORRUPT"}, + {"type": "NODE_FOLDER_SCAN"}, + {"type": "NODE_FOLDER_CHECKHASH"}, + {"type": "NODE_FOLDER_REPAIR"}, + {"type": "NODE_FOLDER_RESTORE"}, + {"type": "NODE_OS_SCAN"}, + {"type": "NODE_SHUTDOWN"}, + {"type": "NODE_STARTUP"}, + {"type": "NODE_RESET"}, + {"type": "NETWORK_ACL_ADDRULE", "options": {"target_router_hostname": "router"}}, + {"type": "NETWORK_ACL_REMOVERULE", "options": {"target_router_hostname": "router"}}, + {"type": "NETWORK_NIC_ENABLE"}, + {"type": "NETWORK_NIC_DISABLE"}, + ] + + action_space = ActionManager( + game=game, + actions=actions, # ALL POSSIBLE ACTIONS + nodes=[ + {"node_name": "client_1", "applications": [{"application_name": "WebBrowser"}]}, + {"node_name": "server_1", "services": [{"service_name": "DNSServer"}]}, + {"node_name": "server_2", "services": [{"service_name": "WebServer"}]}, + ], + max_folders_per_node=2, + max_files_per_folder=2, + max_services_per_node=2, + max_applications_per_node=2, + max_nics_per_node=2, + max_acl_rules=10, + protocols=["TCP", "UDP", "ICMP"], + ports=["HTTP", "DNS", "ARP"], + ip_address_list=["10.0.1.1", "10.0.1.2", "10.0.2.1", "10.0.2.2", "10.0.2.3"], + act_map={}, + ) + observation_space = None + reward_function = None + + test_agent = ProxyAgent( + agent_name="test_agent", + action_space=action_space, + observation_space=observation_space, + reward_function=reward_function, + ) + + game.agents.append(test_agent) + + return game, test_agent + + +def test_test(game): + assert True diff --git a/tests/unit_tests/_primaite/_game/__init__.py b/tests/unit_tests/_primaite/_game/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_game/_agent/__init__.py b/tests/unit_tests/_primaite/_game/_agent/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_game/_agent/test_actions.py b/tests/unit_tests/_primaite/_game/_agent/test_actions.py new file mode 100644 index 00000000..9b641fe2 --- /dev/null +++ b/tests/unit_tests/_primaite/_game/_agent/test_actions.py @@ -0,0 +1,90 @@ +from unittest.mock import Mock + +import pytest + +from primaite.game.agent.actions import ( + ActionManager, + DoNothingAction, + NodeServiceDisableAction, + NodeServiceEnableAction, + NodeServicePauseAction, + NodeServiceRestartAction, + NodeServiceResumeAction, + NodeServiceScanAction, + NodeServiceStartAction, + NodeServiceStopAction, +) + + +def test_do_nothing_action_form_request(): + """Test that the DoNothingAction can form a request and that it is correct.""" + manager = Mock() + + action = DoNothingAction(manager=manager) + + request = action.form_request() + + assert request == ["do_nothing"] + + +@pytest.mark.parametrize( + "action_class, action_verb", + [ + (NodeServiceScanAction, "scan"), + (NodeServiceStopAction, "stop"), + (NodeServiceStartAction, "start"), + (NodeServicePauseAction, "pause"), + (NodeServiceResumeAction, "resume"), + (NodeServiceRestartAction, "restart"), + (NodeServiceDisableAction, "disable"), + (NodeServiceEnableAction, "enable"), + ], +) # flake8: noqa +@pytest.mark.parametrize( + "node_name, service_name, expect_to_do_nothing", + [ + ("pc_1", "chrome", False), + (None, "chrome", True), + ("pc_1", None, True), + (None, None, True), + ], +) # flake8: noqa +def test_service_action_form_request(node_name, service_name, expect_to_do_nothing, action_class, action_verb): + """Test that the ServiceScanAction can form a request and that it is correct.""" + manager: ActionManager = Mock() + manager.get_node_name_by_idx.return_value = node_name + manager.get_service_name_by_idx.return_value = service_name + + action = action_class(manager=manager, num_nodes=1, num_services=1) + + request = action.form_request(node_id=0, service_id=0) + + if expect_to_do_nothing: + assert request == ["do_nothing"] + else: + assert request == ["network", "node", node_name, "services", service_name, action_verb] + + +@pytest.mark.parametrize( + "node_name, service_name, expect_to_do_nothing", + [ + ("pc_1", "chrome", False), + (None, "chrome", True), + ("pc_1", None, True), + (None, None, True), + ], +) # flake8: noqa +def test_service_scan_form_request(node_name, service_name, expect_to_do_nothing): + """Test that the ServiceScanAction can form a request and that it is correct.""" + manager: ActionManager = Mock() + manager.get_node_name_by_idx.return_value = node_name + manager.get_service_name_by_idx.return_value = service_name + + action = NodeServiceScanAction(manager=manager, num_nodes=1, num_services=1) + + request = action.form_request(node_id=0, service_id=0) + + if expect_to_do_nothing: + assert request == ["do_nothing"] + else: + assert request == ["network", "node", node_name, "services", service_name, "scan"] From 528e3b22a9c9549aebc1ae232ed96e8a99773474 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 4 Jan 2024 12:47:35 +0000 Subject: [PATCH 495/980] Add integration tests --- .../system/applications/web_browser.py | 1 + .../game_layer/test_actions.py | 124 ++++++++++++++++-- 2 files changed, 115 insertions(+), 10 deletions(-) diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 7533f6f3..a5738d76 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -72,6 +72,7 @@ class WebBrowser(Application): """ state = super().describe_state() state["last_response_status_code"] = self.latest_response.status_code if self.latest_response else None + return state def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 37a680c8..85660796 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -10,11 +10,13 @@ # 4. Check that the simulation has changed in the way that I expect. # 5. Repeat for all actions. +from typing import Dict, Tuple + import pytest from primaite.game.agent.actions import ActionManager -from primaite.game.agent.interface import ProxyAgent -from primaite.game.agent.observations import ObservationManager +from primaite.game.agent.interface import AbstractAgent, ProxyAgent +from primaite.game.agent.observations import ICSObservation, ObservationManager from primaite.game.agent.rewards import RewardFunction from primaite.game.game import PrimaiteGame from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState @@ -29,6 +31,34 @@ from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.web_server.web_server import WebServer +from primaite.simulator.system.software import SoftwareHealthState + + +class ControlledAgent(AbstractAgent): + """Agent that can be controlled by the tests.""" + + def __init__( + self, + agent_name: str, + action_space: ActionManager, + observation_space: ObservationManager, + reward_function: RewardFunction, + ) -> None: + super().__init__( + agent_name=agent_name, + action_space=action_space, + observation_space=observation_space, + reward_function=reward_function, + ) + self.most_recent_action: Tuple[str, Dict] + + def get_action(self, obs: None, reward: float = 0.0) -> Tuple[str, Dict]: + """Return the agent's most recent action, formatted in CAOS format.""" + return self.most_recent_action + + def store_action(self, action: Tuple[str, Dict]): + """Store the most recent action.""" + self.most_recent_action = action def install_stuff_to_sim(sim: Simulation): @@ -105,12 +135,47 @@ def install_stuff_to_sim(sim: Simulation): assert isinstance(client_1.software_manager.software.get("WebBrowser"), WebBrowser) assert isinstance(client_1.software_manager.software.get("DNSClient"), DNSClient) - # 5: Return the simulation + # 5: Assert that the simulation starts off in the state that we expect + assert len(sim.network.nodes) == 6 + assert len(sim.network.links) == 5 + # 5.1: Assert the router is correctly configured + r = sim.network.routers[0] + for i, acl_rule in enumerate(r.acl.acl): + if i == 1: + assert acl_rule.src_port == acl_rule.dst_port == Port.DNS + elif i == 3: + assert acl_rule.src_port == acl_rule.dst_port == Port.HTTP + elif i == 22: + assert acl_rule.src_port == acl_rule.dst_port == Port.ARP + elif i == 23: + assert acl_rule.protocol == IPProtocol.ICMP + elif i == 24: + ... + else: + assert acl_rule is None + + # 5.2: Assert the client is correctly configured + c: Computer = [node for node in sim.network.nodes.values() if node.hostname == "client_1"][0] + assert c.software_manager.software.get("WebBrowser") is not None + assert c.software_manager.software.get("DNSClient") is not None + assert str(c.ethernet_port[1].ip_address) == "10.0.1.2" + + # 5.3: Assert that server_1 is correctly configured + s1: Server = [node for node in sim.network.nodes.values() if node.hostname == "server_1"][0] + assert str(s1.ethernet_port[1].ip_address) == "10.0.2.2" + assert s1.software_manager.software.get("DNSServer") is not None + + # 5.4: Assert that server_2 is correctly configured + s2: Server = [node for node in sim.network.nodes.values() if node.hostname == "server_2"][0] + assert str(s2.ethernet_port[1].ip_address) == "10.0.2.3" + assert s2.software_manager.software.get("WebServer") is not None + + # 6: Return the simulation return sim @pytest.fixture -def game(): +def game_and_agent(): """Create a game with a simple agent that can be controlled by the tests.""" game = PrimaiteGame() sim = game.simulation @@ -166,10 +231,10 @@ def game(): ip_address_list=["10.0.1.1", "10.0.1.2", "10.0.2.1", "10.0.2.2", "10.0.2.3"], act_map={}, ) - observation_space = None - reward_function = None + observation_space = ObservationManager(ICSObservation()) + reward_function = RewardFunction() - test_agent = ProxyAgent( + test_agent = ControlledAgent( agent_name="test_agent", action_space=action_space, observation_space=observation_space, @@ -178,8 +243,47 @@ def game(): game.agents.append(test_agent) - return game, test_agent + return (game, test_agent) -def test_test(game): - assert True +# def test_test(game_and_agent:Tuple[PrimaiteGame, ProxyAgent]): +# game, agent = game_and_agent + + +def test_do_nothing_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the DoNothingAction can form a request and that it is accepted by the simulation.""" + game, agent = game_and_agent + + action = ("DONOTHING", {}) + agent.store_action(action) + game.step() + + +@pytest.mark.skip(reason="Waiting to merge ticket 2160") +def test_node_service_scan_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """ + Test that the NodeServiceScanAction can form a request and that it is accepted by the simulation. + + The health status of applications is not always updated in the state dict, rather the agent needs to perform a scan. + Therefore, we set the web browser to be corrupted, check the state is still good, then perform a scan, and check + that the state changes to the true value. + """ + game, agent = game_and_agent + + browser = game.simulation.network.get_node_by_hostname("client_1").software_manager.software.get("WebBrowser") + browser.health_state_actual = SoftwareHealthState.COMPROMISED + + state_before = game.get_sim_state() + assert ( + game.get_sim_state()["network"]["nodes"]["client_1"]["applications"]["WebBrowser"]["health_state"] + == SoftwareHealthState.GOOD + ) + action = ("NODE_SERVICE_SCAN", {"node_id": 0, "service_id": 0}) + agent.store_action(action) + game.step() + state_after = game.get_sim_state() + pass + assert ( + game.get_sim_state()["network"]["nodes"]["client_1"]["services"]["WebBrowser"]["health_state"] + == SoftwareHealthState.COMPROMISED + ) From bc367222a843e72e97f35332a7c68dff1721d94f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 4 Jan 2024 12:55:46 +0000 Subject: [PATCH 496/980] Change software describe state keys --- src/primaite/game/agent/observations.py | 5 ++++- src/primaite/simulator/system/software.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 928aebfd..46c9d75c 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -139,7 +139,10 @@ class ServiceObservation(AbstractObservation): service_state = access_from_nested_dict(state, self.where) if service_state is NOT_PRESENT_IN_STATE: return self.default_observation - return {"operating_status": service_state["operating_state"], "health_status": service_state["health_state"]} + return { + "operating_status": service_state["operating_state"], + "health_status": service_state["health_state_visible"], + } @property def space(self) -> spaces.Space: diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index b393ffd8..c3db48fc 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -137,8 +137,8 @@ class Software(SimComponent): state = super().describe_state() state.update( { - "health_state": self.health_state_actual.value, - "health_state_red_view": self.health_state_visible.value, + "health_state_actual": self.health_state_actual.value, + "health_state_visible": self.health_state_visible.value, "criticality": self.criticality.value, "patching_count": self.patching_count, "scanning_count": self.scanning_count, From 4266618ba57346f94c164fa8a7581507713b05d0 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 5 Jan 2024 11:25:57 +0000 Subject: [PATCH 497/980] Make pcap logs and sys logs optional --- CHANGELOG.md | 2 +- .../config/_package_data/example_config.yaml | 2 ++ src/primaite/session/io.py | 9 +++++++-- src/primaite/session/session.py | 2 +- src/primaite/simulator/__init__.py | 6 ++++-- .../simulator/system/core/packet_capture.py | 8 ++++++-- src/primaite/simulator/system/core/sys_log.py | 18 +++++++++++++----- 7 files changed, 34 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccaa411a..9e44efe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] - +- Made packet capture and system logging optional ### Added diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index a764703b..81c9643e 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -14,6 +14,8 @@ io_settings: save_checkpoints: true checkpoint_interval: 5 save_step_metadata: false + save_pcap_logs: true + save_sys_logs: true game: diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index 0d80a385..b4b740e9 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -24,9 +24,13 @@ class SessionIOSettings(BaseModel): save_transactions: bool = True """Whether to save transactions, If true, the session path will have a transactions folder.""" save_tensorboard_logs: bool = False - """Whether to save tensorboard logs. If true, the session path will have a tenorboard_logs folder.""" + """Whether to save tensorboard logs. If true, the session path will have a tensorboard_logs folder.""" save_step_metadata: bool = False """Whether to save the RL agents' action, environment state, and other data at every single step.""" + save_pcap_logs: bool = False + """Whether to save PCAP logs.""" + save_sys_logs: bool = False + """Whether to save system logs.""" class SessionIO: @@ -39,9 +43,10 @@ class SessionIO: def __init__(self, settings: SessionIOSettings = SessionIOSettings()) -> None: self.settings: SessionIOSettings = settings self.session_path: Path = self.generate_session_path() - # set global SIM_OUTPUT path SIM_OUTPUT.path = self.session_path / "simulation_output" + SIM_OUTPUT.save_pcap_logs = self.settings.save_pcap_logs + SIM_OUTPUT.save_sys_logs = self.settings.save_sys_logs # warning TODO: must be careful not to re-initialise sessionIO because it will create a new path each time it's # possible refactor needed diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py index ef462d83..0197ac9d 100644 --- a/src/primaite/session/session.py +++ b/src/primaite/session/session.py @@ -54,7 +54,7 @@ class PrimaiteSession: self.policy: PolicyABC """The reinforcement learning policy.""" - self.io_manager = SessionIO() + self.io_manager: Optional["SessionIO"] = None """IO manager for the session.""" self.game: PrimaiteGame = game diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index 19c86e28..aebd77cf 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -7,11 +7,13 @@ from primaite import _PRIMAITE_ROOT __all__ = ["SIM_OUTPUT"] -class __SimOutput: +class _SimOutput: def __init__(self): self._path: Path = ( _PRIMAITE_ROOT.parent.parent / "simulation_output" / datetime.now().strftime("%Y-%m-%d_%H-%M-%S") ) + self.save_pcap_logs: bool = False + self.save_sys_logs: bool = False @property def path(self) -> Path: @@ -23,4 +25,4 @@ class __SimOutput: self._path.mkdir(exist_ok=True, parents=True) -SIM_OUTPUT = __SimOutput() +SIM_OUTPUT = _SimOutput() diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index 1539e024..bfb6a055 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -41,6 +41,9 @@ class PacketCapture: def setup_logger(self): """Set up the logger configuration.""" + if not SIM_OUTPUT.save_pcap_logs: + return + log_path = self._get_log_path() file_handler = logging.FileHandler(filename=log_path) @@ -88,5 +91,6 @@ class PacketCapture: :param frame: The PCAP frame to capture. """ - msg = frame.model_dump_json() - self.logger.log(level=60, msg=msg) # Log at custom log level > CRITICAL + if SIM_OUTPUT.save_pcap_logs: + msg = frame.model_dump_json() + self.logger.log(level=60, msg=msg) # Log at custom log level > CRITICAL diff --git a/src/primaite/simulator/system/core/sys_log.py b/src/primaite/simulator/system/core/sys_log.py index 41ce8fee..00e6920b 100644 --- a/src/primaite/simulator/system/core/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -41,6 +41,9 @@ class SysLog: The logger is set to the DEBUG level, and is equipped with a handler that writes to a file and filters out JSON-like messages. """ + if not SIM_OUTPUT.save_sys_logs: + return + log_path = self._get_log_path() file_handler = logging.FileHandler(filename=log_path) file_handler.setLevel(logging.DEBUG) @@ -91,7 +94,8 @@ class SysLog: :param msg: The message to be logged. """ - self.logger.debug(msg) + if SIM_OUTPUT.save_sys_logs: + self.logger.debug(msg) def info(self, msg: str): """ @@ -99,7 +103,8 @@ class SysLog: :param msg: The message to be logged. """ - self.logger.info(msg) + if SIM_OUTPUT.save_sys_logs: + self.logger.info(msg) def warning(self, msg: str): """ @@ -107,7 +112,8 @@ class SysLog: :param msg: The message to be logged. """ - self.logger.warning(msg) + if SIM_OUTPUT.save_sys_logs: + self.logger.warning(msg) def error(self, msg: str): """ @@ -115,7 +121,8 @@ class SysLog: :param msg: The message to be logged. """ - self.logger.error(msg) + if SIM_OUTPUT.save_sys_logs: + self.logger.error(msg) def critical(self, msg: str): """ @@ -123,4 +130,5 @@ class SysLog: :param msg: The message to be logged. """ - self.logger.critical(msg) + if SIM_OUTPUT.save_sys_logs: + self.logger.critical(msg) From f75c10aafb40f973d22e666f0ee7538b7e0e8676 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 5 Jan 2024 13:10:49 +0000 Subject: [PATCH 498/980] Make flattening observation spaces optional. --- CHANGELOG.md | 3 +- docs/source/config.rst | 24 +- .../config/_package_data/example_config.yaml | 2 +- src/primaite/game/agent/interface.py | 3 + src/primaite/game/game.py | 1 + .../training_example_ray_single_agent.ipynb | 221 +++++++++++++++++- src/primaite/session/environment.py | 15 +- src/primaite/session/session.py | 4 +- 8 files changed, 259 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e44efe3..c712ef66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -- Made packet capture and system logging optional +- Made packet capture and system logging optional (off by default). To turn on, change the io_settings.save_pcap_logs and io_settings.save_sys_logs settings in the config. +- Made observation space flattening optional (on by default). To turn off for an agent, change the agent_settings.flatten_obs setting in the config. ### Added diff --git a/docs/source/config.rst b/docs/source/config.rst index f4452c7e..23bf6097 100644 --- a/docs/source/config.rst +++ b/docs/source/config.rst @@ -13,7 +13,25 @@ This section allows selecting which training framework and algorithm to use, and ``io_settings`` --------------- -This section configures how the ``PrimaiteSession`` saves data. +This section configures how PrimAITE saves data during simulation and training. + +**save_final_model**: Only used if training with PrimaiteSession, if true, the policy will be saved after the final training iteration. + +**save_checkpoints**: Only used if training with PrimaiteSession, if true, the policy will be saved periodically during training. + +**checkpoint_interval**: Only used if training with PrimaiteSession and if ``save_checkpoints`` is true. Defines how often to save the policy during training. + +**save_logs**: *currently unused*. + +**save_transactions**: *currently unused*. + +**save_tensorboard_logs**: *currently unused*. + +**save_step_metadata**: Whether to save the RL agents' action, environment state, and other data at every single step. + +**save_pcap_logs**: Whether to save pcap files of all network traffic during the simulation. + +**save_sys_logs**: Whether to save system logs from all nodes during the simulation. ``game`` -------- @@ -56,6 +74,10 @@ Description of configurable items: **agent_settings**: Settings passed to the agent during initialisation. These depend on the agent class. +Reinforcement learning agents use the ``ProxyAgent`` class, they accept these agent settings: + +**flatten_obs**: If true, gymnasium flattening will be performed on the observation space before sending to the agent. Set this to true if your agent does not support nested observation spaces. + ``simulation`` -------------- In this section the network layout is defined. This part of the config follows a hierarchical structure. Almost every component defines a ``ref`` field which acts as a human-readable unique identifier, used by other parts of the config, such as agents. diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 81c9643e..2ac23661 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -525,7 +525,7 @@ agents: agent_settings: - # ... + flatten_obs: true diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index fbbe5473..8657fc45 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -44,6 +44,7 @@ class AgentSettings(BaseModel): start_settings: Optional[AgentStartSettings] = None "Configuration for when an agent begins performing it's actions" + flatten_obs: bool = True @classmethod def from_config(cls, config: Optional[Dict]) -> "AgentSettings": @@ -166,6 +167,7 @@ class ProxyAgent(AbstractAgent): action_space: Optional[ActionManager], observation_space: Optional[ObservationManager], reward_function: Optional[RewardFunction], + agent_settings: Optional[AgentSettings] = None, ) -> None: super().__init__( agent_name=agent_name, @@ -174,6 +176,7 @@ class ProxyAgent(AbstractAgent): reward_function=reward_function, ) self.most_recent_action: ActType + self.flatten_obs: bool = agent_settings.flatten_obs def get_action(self, obs: ObsType, reward: float = 0.0) -> Tuple[str, Dict]: """ diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index d2db4bea..586bca79 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -427,6 +427,7 @@ class PrimaiteGame: action_space=action_space, observation_space=obs_space, reward_function=rew_function, + agent_settings=agent_settings, ) game.agents.append(new_agent) game.rl_agents.append(new_agent) diff --git a/src/primaite/notebooks/training_example_ray_single_agent.ipynb b/src/primaite/notebooks/training_example_ray_single_agent.ipynb index a89b29e4..993e81ff 100644 --- a/src/primaite/notebooks/training_example_ray_single_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_single_agent.ipynb @@ -10,9 +10,64 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/cade/repos/PrimAITE/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n", + "2024-01-05 12:46:28,650\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", + "2024-01-05 12:46:31,581\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", + "2024-01-05 12:46:31,903\tWARNING __init__.py:10 -- PG has/have been moved to `rllib_contrib` and will no longer be maintained by the RLlib team. You can still use it/them normally inside RLlib util Ray 2.8, but from Ray 2.9 on, all `rllib_contrib` algorithms will no longer be part of the core repo, and will therefore have to be installed separately with pinned dependencies for e.g. ray[rllib] and other packages! See https://github.com/ray-project/ray/tree/master/rllib_contrib#rllib-contrib for more information on the RLlib contrib effort.\n", + "2024-01-05 12:46:35,016\tINFO worker.py:1673 -- Started a local Ray instance.\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "
\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Python version:3.10.12
Ray version:2.8.0
\n", + "\n", + "
\n", + "
\n" + ], + "text/plain": [ + "RayContext(dashboard_url='', python_version='3.10.12', ray_version='2.8.0', ray_commit='105355bd253d6538ed34d331f6a4bdf0e38ace3a', protocol_version=None)" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from primaite.game.game import PrimaiteGame\n", "import yaml\n", @@ -41,7 +96,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'flatten_obs': False}\n" + ] + } + ], + "source": [ + "print(cfg['agents'][2]['agent_settings'])" + ] + }, + { + "cell_type": "code", + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -64,9 +136,141 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + ":job_id:01000000\n", + ":task_name:bundle_reservation_check_func\n", + ":actor_name:PPO\n", + "2024-01-05 12:46:40,174: Added service 6589f0e3-f427-4382-9e29-1344624bfe33 to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", + "2024-01-05 12:46:40,175: Added service c3299cad-9a05-4fa1-bf6b-3fb82e9c9717 to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", + "2024-01-05 12:46:40,176: Added application 2cba2c28-dc88-4688-b8bc-ac5cf2b7652c to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", + "2024-01-05 12:46:40,178: Added service 23207441-15d6-42f8-bae4-1810bbff7d8b to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", + "2024-01-05 12:46:40,179: Added service 01a61864-52d1-4980-b88c-6bec7ad58c3e to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", + "2024-01-05 12:46:40,180: Added application a51c4db0-028c-440c-845e-43f7a1354544 to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", + "2024-01-05 12:46:40,181: Added service 7beff81f-6083-421b-a212-e02d9eb3ad69 to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", + "2024-01-05 12:46:40,184: Added service e49fd236-0195-4571-a992-af490c2d27c4 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", + "2024-01-05 12:46:40,186: Added service 9fdc6bb7-a338-4a64-b7a3-8467c88f79fd to node 5a8e7052-0094-4104-aedb-beda65db2214\n", + "2024-01-05 12:46:40,188: Added application 3f99407c-1642-47e5-ade5-5106a1b49004 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", + "2024-01-05 12:46:40,189: Added service 0e4c4e77-1bbb-45c3-aa4b-fdfd6c439091 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", + "2024-01-05 12:46:40,190: Added service 711608ae-5f71-4bb7-8c99-95974f28f964 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", + "2024-01-05 12:46:40,191: Added application bfbe2fb3-4d7e-4f07-9454-aee8404ca4b3 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", + "2024-01-05 12:46:40,192: Added application 2cd88860-c7c5-4e64-b07a-4f0c9a0d8324 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", + "2024-01-05 12:46:40,194: Added service 3cafdb32-3a89-4ab4-a22c-00beb29d6e71 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", + "2024-01-05 12:46:40,196: Added service 649ff374-b9b3-4f17-94de-d95472cc94be to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", + "2024-01-05 12:46:40,198: Added service 561374dc-8844-4a71-a577-67659130afaf to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", + "2024-01-05 12:46:40,200: Added application 14eb20b8-ea9e-4027-a9ef-bf438b1f2b5e to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", + "2024-01-05 12:46:40,202: Added service c7721159-10ad-4fd1-9fc7-a4403f89743a to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", + "2024-01-05 12:46:40,203: Added service 907aff5d-c7d3-4d23-ab97-3bdaf92c8707 to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", + "2024-01-05 12:46:40,204: Added application c8a55900-00af-46a7-90b5-bf8591130534 to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", + "2024-01-05 12:46:40,206: Added service 9ae26c20-4c51-4283-b791-3c278c85aaef to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", + "2024-01-05 12:46:40,207: Added service d3f108af-6a58-430b-9fc8-495e7db16968 to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", + "2024-01-05 12:46:40,211: Added service b759a0a5-7fe9-4f29-830e-6c50fe3d5ac0 to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", + "2024-01-05 12:46:40,212: Added service d07213b5-d35b-4343-96ff-76399f80d12c to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", + "2024-01-05 12:46:40,213: Added application f4cb45da-c81c-4fbf-adcf-461ca8728576 to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", + "2024-01-05 12:46:40,215: Added service 44dadb4d-09b2-4569-97ed-18ed5e050437 to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", + "2024-01-05 12:46:40,216: Added service 6c2e121a-fe1e-45fd-b0d4-587c0f6aafba to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", + "2024-01-05 12:46:40,217: Added application e1ed96b9-221a-4a26-8330-1142f7681bf3 to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", + "2024-01-05 12:46:40,218: Added service 4a9b52fb-747f-4921-bd73-2ee17557b2de to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", + "2024-01-05 12:46:40,220: Added service 38f3dfa9-6974-4122-b731-63a9cc3a13b2 to node 0c55c8bd-252b-420e-8ba6-e81091c21ff9\n", + "2024-01-05 12:46:40,220: Added service 5e2b34f4-9ac6-4e9d-b2db-48aac4eeff32 to node 0c55c8bd-252b-420e-8ba6-e81091c21ff9\n", + "2024-01-05 12:46:40,221: Added application 2db51ce9-391f-4e82-acf6-b565819b6c6d to node 0c55c8bd-252b-420e-8ba6-e81091c21ff9\n", + "2024-01-05 12:46:40,223: Added service e33f7cfb-6940-4076-9a2f-5874ba385c57 to node 0c55c8bd-252b-420e-8ba6-e81091c21ff9\n", + "2024-01-05 12:46:40,224: Added service 346687ac-a032-479b-9ccb-ab2df7d5b84b to node 0c55c8bd-252b-420e-8ba6-e81091c21ff9\n", + "2024-01-05 12:46:40,225: Added application 7adcddf8-4d1f-428b-8722-7ce44f1e64d7 to node 0c55c8bd-252b-420e-8ba6-e81091c21ff9\n", + "2024-01-05 12:46:40,229: Added service c498af8f-5648-4340-b117-7dd958d8bccb to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", + "2024-01-05 12:46:40,231: Added service 0218fc4e-fb25-47fb-b03c-9ecfa90986eb to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", + "2024-01-05 12:46:40,232: Added application edfe50af-01ac-45e4-8b96-fdb5ec6d61d7 to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", + "2024-01-05 12:46:40,233: Added service fb4b25f9-4a3f-41ec-a2db-57eac73201a9 to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", + "2024-01-05 12:46:40,234: Added service 062e3e3e-65a4-4a30-ad34-418bdc2f5886 to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", + "2024-01-05 12:46:40,235: Added application 72cdbee1-3ed9-4189-8198-788bfacacb44 to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", + "2024-01-05 12:46:40,236: Added service f5b741a0-25a5-42cb-86e8-e42b2fec7433 to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", + "2024-01-05 12:46:40,237: Added application 3fc736ef-9308-49a6-b63c-559ec878fc30 to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", + "2024-01-05 12:46:40,240: Added service 463f9765-6d2b-427c-9319-f4af92de3815 to node 65549a8a-9788-462b-9a12-883747b73a3b\n", + "2024-01-05 12:46:40,241: Added service c4e6a1fc-7512-45e4-b8c1-60d0913b22d3 to node 65549a8a-9788-462b-9a12-883747b73a3b\n", + "2024-01-05 12:46:40,242: Added application c1f981ba-db6b-4a1e-98a8-d8f0efb0ead9 to node 65549a8a-9788-462b-9a12-883747b73a3b\n", + "2024-01-05 12:46:40,244: Added service 815c2d28-75e5-4ea6-a283-a18b389d4e6e to node 65549a8a-9788-462b-9a12-883747b73a3b\n", + "2024-01-05 12:46:40,246: Added service c9ee86ec-9490-4fd8-8aef-6cab5c9e7c67 to node 65549a8a-9788-462b-9a12-883747b73a3b\n", + "2024-01-05 12:46:40,247: Added application 91763a2f-8135-4fd3-a4cc-81c883d0d33f to node 65549a8a-9788-462b-9a12-883747b73a3b\n", + "2024-01-05 12:46:40,248: Added service c71b0658-1e43-4881-b603-87dbf1c171a2 to node 65549a8a-9788-462b-9a12-883747b73a3b\n", + "2024-01-05 12:46:40,249: Added application 39ad54a1-28cd-4cd9-88d6-32e3f00844ae to node 65549a8a-9788-462b-9a12-883747b73a3b\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + ":job_id:01000000\n", + ":task_name:bundle_reservation_check_func\n", + ":actor_name:PPO\n", + "Resetting environment, episode -1, avg. reward: 0.0\n", + ":actor_name:PPO\n", + "Resetting environment, episode 0, avg. reward: 0.0\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + ":actor_name:PPO\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Resetting environment, episode 1, avg. reward: -101.0\n", + "Resetting environment, episode 2, avg. reward: -126.5\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-01-05 12:46:46,735\tINFO storage.py:563 -- Checkpoint successfully created at: Checkpoint(filesystem=local, path=/home/cade/ray_results/PPO_2024-01-05_12-46-39/PPO_PrimaiteRayEnv_7899c_00000_0_2024-01-05_12-46-40/checkpoint_000000)\n", + "2024-01-05 12:46:46,847\tINFO tune.py:1047 -- Total run time: 6.85 seconds (6.77 seconds for the tuning loop).\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + }, + { + "data": { + "text/plain": [ + "ResultGrid<[\n", + " Result(\n", + " metrics={'custom_metrics': {}, 'episode_media': {}, 'info': {'learner': {'__all__': {'num_agent_steps_trained': 128.0, 'num_env_steps_trained': 128.0, 'total_loss': 9.46448793411255}, 'default_policy': {'total_loss': 9.46448793411255, 'policy_loss': -0.06344481200600664, 'vf_loss': 9.525621096293131, 'vf_loss_unclipped': 509.6841542561849, 'vf_explained_var': 0.004743536313374837, 'entropy': 3.855365761121114, 'mean_kl_loss': 0.011559122211959523, 'default_optimizer_lr': 4.999999999999999e-05, 'curr_lr': 5e-05, 'curr_entropy_coeff': 0.0, 'curr_kl_coeff': 0.20000000298023224}}, 'num_env_steps_sampled': 512, 'num_env_steps_trained': 0, 'num_agent_steps_sampled': 512, 'num_agent_steps_trained': 0}, 'sampler_results': {'episode_reward_max': -101.0, 'episode_reward_min': -126.5, 'episode_reward_mean': -113.75, 'episode_len_mean': 256.0, 'episode_media': {}, 'episodes_this_iter': 1, 'policy_reward_min': {}, 'policy_reward_max': {}, 'policy_reward_mean': {}, 'custom_metrics': {}, 'hist_stats': {'episode_reward': [-101.0, -126.5], 'episode_lengths': [256, 256]}, 'sampler_perf': {'mean_raw_obs_processing_ms': 1.4790121096531605, 'mean_inference_ms': 2.438426005102573, 'mean_action_processing_ms': 0.12985192105746982, 'mean_env_wait_ms': 2.5040151965470656, 'mean_env_render_ms': 0.0}, 'num_faulty_episodes': 0, 'connector_metrics': {'ObsPreprocessorConnector_ms': 1.051938533782959, 'StateBufferConnector_ms': 0.009810924530029297, 'ViewRequirementAgentConnector_ms': 0.46378374099731445}}, 'episode_reward_max': -101.0, 'episode_reward_min': -126.5, 'episode_reward_mean': -113.75, 'episode_len_mean': 256.0, 'episodes_this_iter': 1, 'policy_reward_min': {}, 'policy_reward_max': {}, 'policy_reward_mean': {}, 'hist_stats': {'episode_reward': [-101.0, -126.5], 'episode_lengths': [256, 256]}, 'sampler_perf': {'mean_raw_obs_processing_ms': 1.4790121096531605, 'mean_inference_ms': 2.438426005102573, 'mean_action_processing_ms': 0.12985192105746982, 'mean_env_wait_ms': 2.5040151965470656, 'mean_env_render_ms': 0.0}, 'num_faulty_episodes': 0, 'connector_metrics': {'ObsPreprocessorConnector_ms': 1.051938533782959, 'StateBufferConnector_ms': 0.009810924530029297, 'ViewRequirementAgentConnector_ms': 0.46378374099731445}, 'num_healthy_workers': 0, 'num_in_flight_async_reqs': 0, 'num_remote_worker_restarts': 0, 'num_agent_steps_sampled': 512, 'num_agent_steps_trained': 0, 'num_env_steps_sampled': 512, 'num_env_steps_trained': 0, 'num_env_steps_sampled_this_iter': 128, 'num_env_steps_trained_this_iter': 0, 'num_env_steps_sampled_throughput_per_sec': 57.18780249848288, 'num_env_steps_trained_throughput_per_sec': 0.0, 'num_steps_trained_this_iter': 0, 'agent_timesteps_total': 512, 'timers': {'training_iteration_time_ms': 1392.194, 'sample_time_ms': 995.05, 'synch_weights_time_ms': 1.92}, 'counters': {'num_env_steps_sampled': 512, 'num_env_steps_trained': 0, 'num_agent_steps_sampled': 512, 'num_agent_steps_trained': 0}, 'perf': {'cpu_util_percent': 54.06666666666666, 'ram_util_percent': 53.53333333333334}},\n", + " path='/home/cade/ray_results/PPO_2024-01-05_12-46-39/PPO_PrimaiteRayEnv_7899c_00000_0_2024-01-05_12-46-40',\n", + " filesystem='local',\n", + " checkpoint=Checkpoint(filesystem=local, path=/home/cade/ray_results/PPO_2024-01-05_12-46-39/PPO_PrimaiteRayEnv_7899c_00000_0_2024-01-05_12-46-40/checkpoint_000000)\n", + " )\n", + "]>" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "tune.Tuner(\n", " \"PPO\",\n", @@ -76,6 +280,13 @@ " param_space=config\n", ").fit()\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index ca71a0c0..36ab3f58 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -23,6 +23,7 @@ class PrimaiteGymEnv(gymnasium.Env): super().__init__() self.game: "PrimaiteGame" = game self.agent: ProxyAgent = self.game.rl_agents[0] + self.flatten_obs: bool = False def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: """Perform a step in the environment.""" @@ -81,13 +82,19 @@ class PrimaiteGymEnv(gymnasium.Env): @property def observation_space(self) -> gymnasium.Space: """Return the observation space of the environment.""" - return gymnasium.spaces.flatten_space(self.agent.observation_manager.space) + if self.agent.flatten_obs: + return gymnasium.spaces.flatten_space(self.agent.observation_manager.space) + else: + return self.agent.observation_manager.space def _get_obs(self) -> ObsType: """Return the current observation.""" - unflat_space = self.agent.observation_manager.space - unflat_obs = self.agent.observation_manager.current_observation - return gymnasium.spaces.flatten(unflat_space, unflat_obs) + if not self.agent.flatten_obs: + return self.agent.observation_manager.current_observation + else: + unflat_space = self.agent.observation_manager.space + unflat_obs = self.agent.observation_manager.current_observation + return gymnasium.spaces.flatten(unflat_space, unflat_obs) class PrimaiteRayEnv(gymnasium.Env): diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py index 0197ac9d..5c663cfd 100644 --- a/src/primaite/session/session.py +++ b/src/primaite/session/session.py @@ -101,9 +101,9 @@ class PrimaiteSession: # CREATE ENVIRONMENT if sess.training_options.rl_framework == "RLLIB_single_agent": - sess.env = PrimaiteRayEnv(env_config={"game": game}) + sess.env = PrimaiteRayEnv(env_config={"cfg": cfg}) elif sess.training_options.rl_framework == "RLLIB_multi_agent": - sess.env = PrimaiteRayMARLEnv(env_config={"game": game}) + sess.env = PrimaiteRayMARLEnv(env_config={"cfg": cfg}) elif sess.training_options.rl_framework == "SB3": sess.env = PrimaiteGymEnv(game=game) From d038f63fda3897c6f7169e882938ca47bd62c720 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 5 Jan 2024 13:11:47 +0000 Subject: [PATCH 499/980] Clear notebook output --- .../training_example_ray_single_agent.ipynb | 209 +----------------- 1 file changed, 7 insertions(+), 202 deletions(-) diff --git a/src/primaite/notebooks/training_example_ray_single_agent.ipynb b/src/primaite/notebooks/training_example_ray_single_agent.ipynb index 993e81ff..ea006ae9 100644 --- a/src/primaite/notebooks/training_example_ray_single_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_single_agent.ipynb @@ -10,64 +10,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/cade/repos/PrimAITE/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n", - "2024-01-05 12:46:28,650\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", - "2024-01-05 12:46:31,581\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", - "2024-01-05 12:46:31,903\tWARNING __init__.py:10 -- PG has/have been moved to `rllib_contrib` and will no longer be maintained by the RLlib team. You can still use it/them normally inside RLlib util Ray 2.8, but from Ray 2.9 on, all `rllib_contrib` algorithms will no longer be part of the core repo, and will therefore have to be installed separately with pinned dependencies for e.g. ray[rllib] and other packages! See https://github.com/ray-project/ray/tree/master/rllib_contrib#rllib-contrib for more information on the RLlib contrib effort.\n", - "2024-01-05 12:46:35,016\tINFO worker.py:1673 -- Started a local Ray instance.\n" - ] - }, - { - "data": { - "text/html": [ - "
\n", - "
\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Python version:3.10.12
Ray version:2.8.0
\n", - "\n", - "
\n", - "
\n" - ], - "text/plain": [ - "RayContext(dashboard_url='', python_version='3.10.12', ray_version='2.8.0', ray_commit='105355bd253d6538ed34d331f6a4bdf0e38ace3a', protocol_version=None)" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "from primaite.game.game import PrimaiteGame\n", "import yaml\n", @@ -96,24 +41,16 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'flatten_obs': False}\n" - ] - } - ], + "outputs": [], "source": [ "print(cfg['agents'][2]['agent_settings'])" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -136,141 +73,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - ":job_id:01000000\n", - ":task_name:bundle_reservation_check_func\n", - ":actor_name:PPO\n", - "2024-01-05 12:46:40,174: Added service 6589f0e3-f427-4382-9e29-1344624bfe33 to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", - "2024-01-05 12:46:40,175: Added service c3299cad-9a05-4fa1-bf6b-3fb82e9c9717 to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", - "2024-01-05 12:46:40,176: Added application 2cba2c28-dc88-4688-b8bc-ac5cf2b7652c to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", - "2024-01-05 12:46:40,178: Added service 23207441-15d6-42f8-bae4-1810bbff7d8b to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", - "2024-01-05 12:46:40,179: Added service 01a61864-52d1-4980-b88c-6bec7ad58c3e to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", - "2024-01-05 12:46:40,180: Added application a51c4db0-028c-440c-845e-43f7a1354544 to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", - "2024-01-05 12:46:40,181: Added service 7beff81f-6083-421b-a212-e02d9eb3ad69 to node 6f2396a1-80f4-4822-8d98-42811a89521e\n", - "2024-01-05 12:46:40,184: Added service e49fd236-0195-4571-a992-af490c2d27c4 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", - "2024-01-05 12:46:40,186: Added service 9fdc6bb7-a338-4a64-b7a3-8467c88f79fd to node 5a8e7052-0094-4104-aedb-beda65db2214\n", - "2024-01-05 12:46:40,188: Added application 3f99407c-1642-47e5-ade5-5106a1b49004 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", - "2024-01-05 12:46:40,189: Added service 0e4c4e77-1bbb-45c3-aa4b-fdfd6c439091 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", - "2024-01-05 12:46:40,190: Added service 711608ae-5f71-4bb7-8c99-95974f28f964 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", - "2024-01-05 12:46:40,191: Added application bfbe2fb3-4d7e-4f07-9454-aee8404ca4b3 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", - "2024-01-05 12:46:40,192: Added application 2cd88860-c7c5-4e64-b07a-4f0c9a0d8324 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", - "2024-01-05 12:46:40,194: Added service 3cafdb32-3a89-4ab4-a22c-00beb29d6e71 to node 5a8e7052-0094-4104-aedb-beda65db2214\n", - "2024-01-05 12:46:40,196: Added service 649ff374-b9b3-4f17-94de-d95472cc94be to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", - "2024-01-05 12:46:40,198: Added service 561374dc-8844-4a71-a577-67659130afaf to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", - "2024-01-05 12:46:40,200: Added application 14eb20b8-ea9e-4027-a9ef-bf438b1f2b5e to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", - "2024-01-05 12:46:40,202: Added service c7721159-10ad-4fd1-9fc7-a4403f89743a to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", - "2024-01-05 12:46:40,203: Added service 907aff5d-c7d3-4d23-ab97-3bdaf92c8707 to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", - "2024-01-05 12:46:40,204: Added application c8a55900-00af-46a7-90b5-bf8591130534 to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", - "2024-01-05 12:46:40,206: Added service 9ae26c20-4c51-4283-b791-3c278c85aaef to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", - "2024-01-05 12:46:40,207: Added service d3f108af-6a58-430b-9fc8-495e7db16968 to node 0053cdf7-44aa-4a44-b71c-a0351927e797\n", - "2024-01-05 12:46:40,211: Added service b759a0a5-7fe9-4f29-830e-6c50fe3d5ac0 to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", - "2024-01-05 12:46:40,212: Added service d07213b5-d35b-4343-96ff-76399f80d12c to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", - "2024-01-05 12:46:40,213: Added application f4cb45da-c81c-4fbf-adcf-461ca8728576 to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", - "2024-01-05 12:46:40,215: Added service 44dadb4d-09b2-4569-97ed-18ed5e050437 to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", - "2024-01-05 12:46:40,216: Added service 6c2e121a-fe1e-45fd-b0d4-587c0f6aafba to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", - "2024-01-05 12:46:40,217: Added application e1ed96b9-221a-4a26-8330-1142f7681bf3 to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", - "2024-01-05 12:46:40,218: Added service 4a9b52fb-747f-4921-bd73-2ee17557b2de to node 92240e65-db56-4b90-a1e3-a0e7d0d7e9a6\n", - "2024-01-05 12:46:40,220: Added service 38f3dfa9-6974-4122-b731-63a9cc3a13b2 to node 0c55c8bd-252b-420e-8ba6-e81091c21ff9\n", - "2024-01-05 12:46:40,220: Added service 5e2b34f4-9ac6-4e9d-b2db-48aac4eeff32 to node 0c55c8bd-252b-420e-8ba6-e81091c21ff9\n", - "2024-01-05 12:46:40,221: Added application 2db51ce9-391f-4e82-acf6-b565819b6c6d to node 0c55c8bd-252b-420e-8ba6-e81091c21ff9\n", - "2024-01-05 12:46:40,223: Added service e33f7cfb-6940-4076-9a2f-5874ba385c57 to node 0c55c8bd-252b-420e-8ba6-e81091c21ff9\n", - "2024-01-05 12:46:40,224: Added service 346687ac-a032-479b-9ccb-ab2df7d5b84b to node 0c55c8bd-252b-420e-8ba6-e81091c21ff9\n", - "2024-01-05 12:46:40,225: Added application 7adcddf8-4d1f-428b-8722-7ce44f1e64d7 to node 0c55c8bd-252b-420e-8ba6-e81091c21ff9\n", - "2024-01-05 12:46:40,229: Added service c498af8f-5648-4340-b117-7dd958d8bccb to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", - "2024-01-05 12:46:40,231: Added service 0218fc4e-fb25-47fb-b03c-9ecfa90986eb to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", - "2024-01-05 12:46:40,232: Added application edfe50af-01ac-45e4-8b96-fdb5ec6d61d7 to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", - "2024-01-05 12:46:40,233: Added service fb4b25f9-4a3f-41ec-a2db-57eac73201a9 to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", - "2024-01-05 12:46:40,234: Added service 062e3e3e-65a4-4a30-ad34-418bdc2f5886 to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", - "2024-01-05 12:46:40,235: Added application 72cdbee1-3ed9-4189-8198-788bfacacb44 to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", - "2024-01-05 12:46:40,236: Added service f5b741a0-25a5-42cb-86e8-e42b2fec7433 to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", - "2024-01-05 12:46:40,237: Added application 3fc736ef-9308-49a6-b63c-559ec878fc30 to node 88b3a7a8-bd87-48e3-b74b-5a66d2d770eb\n", - "2024-01-05 12:46:40,240: Added service 463f9765-6d2b-427c-9319-f4af92de3815 to node 65549a8a-9788-462b-9a12-883747b73a3b\n", - "2024-01-05 12:46:40,241: Added service c4e6a1fc-7512-45e4-b8c1-60d0913b22d3 to node 65549a8a-9788-462b-9a12-883747b73a3b\n", - "2024-01-05 12:46:40,242: Added application c1f981ba-db6b-4a1e-98a8-d8f0efb0ead9 to node 65549a8a-9788-462b-9a12-883747b73a3b\n", - "2024-01-05 12:46:40,244: Added service 815c2d28-75e5-4ea6-a283-a18b389d4e6e to node 65549a8a-9788-462b-9a12-883747b73a3b\n", - "2024-01-05 12:46:40,246: Added service c9ee86ec-9490-4fd8-8aef-6cab5c9e7c67 to node 65549a8a-9788-462b-9a12-883747b73a3b\n", - "2024-01-05 12:46:40,247: Added application 91763a2f-8135-4fd3-a4cc-81c883d0d33f to node 65549a8a-9788-462b-9a12-883747b73a3b\n", - "2024-01-05 12:46:40,248: Added service c71b0658-1e43-4881-b603-87dbf1c171a2 to node 65549a8a-9788-462b-9a12-883747b73a3b\n", - "2024-01-05 12:46:40,249: Added application 39ad54a1-28cd-4cd9-88d6-32e3f00844ae to node 65549a8a-9788-462b-9a12-883747b73a3b\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - ":job_id:01000000\n", - ":task_name:bundle_reservation_check_func\n", - ":actor_name:PPO\n", - "Resetting environment, episode -1, avg. reward: 0.0\n", - ":actor_name:PPO\n", - "Resetting environment, episode 0, avg. reward: 0.0\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - ":actor_name:PPO\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Resetting environment, episode 1, avg. reward: -101.0\n", - "Resetting environment, episode 2, avg. reward: -126.5\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-01-05 12:46:46,735\tINFO storage.py:563 -- Checkpoint successfully created at: Checkpoint(filesystem=local, path=/home/cade/ray_results/PPO_2024-01-05_12-46-39/PPO_PrimaiteRayEnv_7899c_00000_0_2024-01-05_12-46-40/checkpoint_000000)\n", - "2024-01-05 12:46:46,847\tINFO tune.py:1047 -- Total run time: 6.85 seconds (6.77 seconds for the tuning loop).\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n" - ] - }, - { - "data": { - "text/plain": [ - "ResultGrid<[\n", - " Result(\n", - " metrics={'custom_metrics': {}, 'episode_media': {}, 'info': {'learner': {'__all__': {'num_agent_steps_trained': 128.0, 'num_env_steps_trained': 128.0, 'total_loss': 9.46448793411255}, 'default_policy': {'total_loss': 9.46448793411255, 'policy_loss': -0.06344481200600664, 'vf_loss': 9.525621096293131, 'vf_loss_unclipped': 509.6841542561849, 'vf_explained_var': 0.004743536313374837, 'entropy': 3.855365761121114, 'mean_kl_loss': 0.011559122211959523, 'default_optimizer_lr': 4.999999999999999e-05, 'curr_lr': 5e-05, 'curr_entropy_coeff': 0.0, 'curr_kl_coeff': 0.20000000298023224}}, 'num_env_steps_sampled': 512, 'num_env_steps_trained': 0, 'num_agent_steps_sampled': 512, 'num_agent_steps_trained': 0}, 'sampler_results': {'episode_reward_max': -101.0, 'episode_reward_min': -126.5, 'episode_reward_mean': -113.75, 'episode_len_mean': 256.0, 'episode_media': {}, 'episodes_this_iter': 1, 'policy_reward_min': {}, 'policy_reward_max': {}, 'policy_reward_mean': {}, 'custom_metrics': {}, 'hist_stats': {'episode_reward': [-101.0, -126.5], 'episode_lengths': [256, 256]}, 'sampler_perf': {'mean_raw_obs_processing_ms': 1.4790121096531605, 'mean_inference_ms': 2.438426005102573, 'mean_action_processing_ms': 0.12985192105746982, 'mean_env_wait_ms': 2.5040151965470656, 'mean_env_render_ms': 0.0}, 'num_faulty_episodes': 0, 'connector_metrics': {'ObsPreprocessorConnector_ms': 1.051938533782959, 'StateBufferConnector_ms': 0.009810924530029297, 'ViewRequirementAgentConnector_ms': 0.46378374099731445}}, 'episode_reward_max': -101.0, 'episode_reward_min': -126.5, 'episode_reward_mean': -113.75, 'episode_len_mean': 256.0, 'episodes_this_iter': 1, 'policy_reward_min': {}, 'policy_reward_max': {}, 'policy_reward_mean': {}, 'hist_stats': {'episode_reward': [-101.0, -126.5], 'episode_lengths': [256, 256]}, 'sampler_perf': {'mean_raw_obs_processing_ms': 1.4790121096531605, 'mean_inference_ms': 2.438426005102573, 'mean_action_processing_ms': 0.12985192105746982, 'mean_env_wait_ms': 2.5040151965470656, 'mean_env_render_ms': 0.0}, 'num_faulty_episodes': 0, 'connector_metrics': {'ObsPreprocessorConnector_ms': 1.051938533782959, 'StateBufferConnector_ms': 0.009810924530029297, 'ViewRequirementAgentConnector_ms': 0.46378374099731445}, 'num_healthy_workers': 0, 'num_in_flight_async_reqs': 0, 'num_remote_worker_restarts': 0, 'num_agent_steps_sampled': 512, 'num_agent_steps_trained': 0, 'num_env_steps_sampled': 512, 'num_env_steps_trained': 0, 'num_env_steps_sampled_this_iter': 128, 'num_env_steps_trained_this_iter': 0, 'num_env_steps_sampled_throughput_per_sec': 57.18780249848288, 'num_env_steps_trained_throughput_per_sec': 0.0, 'num_steps_trained_this_iter': 0, 'agent_timesteps_total': 512, 'timers': {'training_iteration_time_ms': 1392.194, 'sample_time_ms': 995.05, 'synch_weights_time_ms': 1.92}, 'counters': {'num_env_steps_sampled': 512, 'num_env_steps_trained': 0, 'num_agent_steps_sampled': 512, 'num_agent_steps_trained': 0}, 'perf': {'cpu_util_percent': 54.06666666666666, 'ram_util_percent': 53.53333333333334}},\n", - " path='/home/cade/ray_results/PPO_2024-01-05_12-46-39/PPO_PrimaiteRayEnv_7899c_00000_0_2024-01-05_12-46-40',\n", - " filesystem='local',\n", - " checkpoint=Checkpoint(filesystem=local, path=/home/cade/ray_results/PPO_2024-01-05_12-46-39/PPO_PrimaiteRayEnv_7899c_00000_0_2024-01-05_12-46-40/checkpoint_000000)\n", - " )\n", - "]>" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "tune.Tuner(\n", " \"PPO\",\n", From 33f72db1cb61021bc202d19dbbf0ffcdb8230dfc Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 5 Jan 2024 14:03:06 +0000 Subject: [PATCH 500/980] Updated VERSION --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index 6da222f2..9414e127 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0b3dev +3.0.0b4 From ddf7fbf88bce2f95448053eb2152cb5c3d6875c1 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 5 Jan 2024 15:27:10 +0000 Subject: [PATCH 501/980] #2139 - Included a test that tests services over multi-hop routing. Added some PR suggestions around logging. --- .../network/hardware/nodes/router.py | 8 ++-- .../network/hardware/nodes/switch.py | 2 +- .../integration_tests/network/test_routing.py | 40 +++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 1e3d8022..172cc711 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -590,8 +590,8 @@ class RouterARPCache(ARPCache): self.send_arp_request(route.next_hop_ip_address, ignore_networks=[frame.ip.src_ip_address]) return self.process_arp_packet(from_nic, frame, route_table, is_reattempt=True) else: - pass - # TODO: destination unavailable/No ARP netry found + self.sys_log.info("Ignoring ARP request as destination unavailable/No ARP entry found") + return else: arp_reply = arp_packet.generate_reply(from_nic.mac_address) self.send_arp_reply(arp_reply, from_nic) @@ -797,7 +797,7 @@ class Router(Node): return self.process_frame(frame=frame, from_nic=from_nic, re_attempt=True) if not nic.enabled: - # TODO: Add sys_log here + self.sys_log.info(f"Frame dropped as NIC {nic} is not enabled") return if frame.ip.dst_ip_address in nic.ip_network: @@ -829,7 +829,7 @@ class Router(Node): return self.process_frame(frame=frame, from_nic=from_nic, re_attempt=True) if not nic.enabled: - # TODO: Add sys_log here + self.sys_log.info(f"Frame dropped as NIC {nic} is not enabled") return from_port = self._get_port_of_nic(from_nic) diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/switch.py index ead857f2..b394bae0 100644 --- a/src/primaite/simulator/network/hardware/nodes/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/switch.py @@ -90,7 +90,7 @@ class Switch(Node): self._add_mac_table_entry(src_mac, incoming_port) outgoing_port = self.mac_address_table.get(dst_mac) - if outgoing_port and dst_mac != "ff:ff:ff:ff:ff:ff": + if outgoing_port and dst_mac.lower() != "ff:ff:ff:ff:ff:ff": outgoing_port.send_frame(frame) else: # If the destination MAC is not in the table, flood to all ports except incoming diff --git a/tests/integration_tests/network/test_routing.py b/tests/integration_tests/network/test_routing.py index 3f636eae..042debca 100644 --- a/tests/integration_tests/network/test_routing.py +++ b/tests/integration_tests/network/test_routing.py @@ -9,6 +9,8 @@ from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.ntp.ntp_client import NTPClient +from primaite.simulator.system.services.ntp.ntp_server import NTPServer @pytest.fixture(scope="function") @@ -143,3 +145,41 @@ def test_with_routes_can_ping(multi_hop_network): ) assert pc_a.ping(pc_b.ethernet_port[1].ip_address) + + +def test_routing_services(multi_hop_network): + pc_a = multi_hop_network.get_node_by_hostname("pc_a") + + pc_b = multi_hop_network.get_node_by_hostname("pc_b") + + pc_a.software_manager.install(NTPClient) + ntp_client = pc_a.software_manager.software["NTPClient"] + ntp_client.start() + + pc_b.software_manager.install(NTPServer) + pc_b.software_manager.software["NTPServer"].start() + + ntp_client.configure(ntp_server_ip_address=pc_b.ethernet_port[1].ip_address) + + router_1: Router = multi_hop_network.get_node_by_hostname("router_1") # noqa + router_2: Router = multi_hop_network.get_node_by_hostname("router_2") # noqa + + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.NTP, dst_port=Port.NTP, position=21) + router_2.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.NTP, dst_port=Port.NTP, position=21) + + assert ntp_client.time is None + ntp_client.request_time() + assert ntp_client.time is None + + # Configure Route from Router 1 to PC B subnet + router_1.route_table.add_route( + address="192.168.2.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.2" + ) + + # Configure Route from Router 2 to PC A subnet + router_2.route_table.add_route( + address="192.168.0.2", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.1" + ) + + ntp_client.request_time() + assert ntp_client.time is not None From d2d628b67653fff4339d90ec72f88ef3cf693e6e Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 5 Jan 2024 22:11:37 +0000 Subject: [PATCH 502/980] #2139 - Fixed unicast and broadcast functionality properly --- CHANGELOG.md | 8 + .../simulator/network/hardware/base.py | 27 ++- .../network/hardware/nodes/router.py | 45 ++++- .../simulator/system/core/session_manager.py | 83 +++++--- .../simulator/system/core/software_manager.py | 22 ++- src/primaite/simulator/system/software.py | 21 +- .../network/test_broadcast.py | 180 ++++++++++++++++++ 7 files changed, 341 insertions(+), 45 deletions(-) create mode 100644 tests/integration_tests/network/test_broadcast.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 96634b28..60961802 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,10 +38,18 @@ SessionManager. - HTTP Services: `WebBrowser` to simulate a web client and `WebServer` - Fixed an issue where the services were still able to run even though the node the service is installed on is turned off - NTP Services: `NTPClient` and `NTPServer` +- **RouterNIC Class**: Introduced a new class `RouterNIC`, extending the standard `NIC` functionality. This class is specifically designed for router operations, optimizing the processing and routing of network traffic. + - **Custom Layer-3 Processing**: The `RouterNIC` class includes custom handling for network frames, bypassing standard Node NIC's Layer 3 broadcast/unicast checks. This allows for more efficient routing behavior in network scenarios where router-specific frame processing is required. + - **Enhanced Frame Reception**: The `receive_frame` method in `RouterNIC` is tailored to handle frames based on Layer 2 (Ethernet) checks, focusing on MAC address-based routing and broadcast frame acceptance. + ### Changed - Integrated the RouteTable into the Routers frame processing. - Frames are now dropped when their TTL reaches 0 +- **NIC Functionality Update**: Updated the Network Interface Card (`NIC`) functionality to support Layer 3 (L3) broadcasts. + - **Layer 3 Broadcast Handling**: Enhanced the existing `NIC` classes to correctly process and handle Layer 3 broadcasts. This update allows devices using standard NICs to effectively participate in network activities that involve L3 broadcasting. + - **Improved Frame Reception Logic**: The `receive_frame` method of the `NIC` class has been updated to include additional checks and handling for L3 broadcasts, ensuring proper frame processing in a wider range of network scenarios. + ### Removed - Removed legacy simulation modules: `acl`, `common`, `environment`, `links`, `nodes`, `pol` diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index c27378a8..7e6e0a3b 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -274,11 +274,20 @@ class NIC(SimComponent): def receive_frame(self, frame: Frame) -> bool: """ - Receive a network frame from the connected link if the NIC is enabled. + Receive a network frame from the connected link, processing it if the NIC is enabled. - The Frame is passed to the Node. + This method decrements the Time To Live (TTL) of the frame, captures it using PCAP (Packet Capture), and checks + if the frame is either a broadcast or destined for this NIC. If the frame is acceptable, it is passed to the + connected node. The method also handles the discarding of frames with TTL expired and logs this event. - :param frame: The network frame being received. + The frame's reception is based on various conditions: + - If the NIC is disabled, the frame is not processed. + - If the TTL of the frame reaches zero after decrement, it is discarded and logged. + - If the frame is a broadcast or its destination MAC/IP address matches this NIC's, it is accepted. + - All other frames are dropped and logged or printed to the console. + + :param frame: The network frame being received. This should be an instance of the Frame class. + :return: Returns True if the frame is processed and passed to the node, False otherwise. """ if self.enabled: frame.decrement_ttl() @@ -288,7 +297,17 @@ class NIC(SimComponent): frame.set_received_timestamp() self.pcap.capture(frame) # If this destination or is broadcast - if frame.ethernet.dst_mac_addr == self.mac_address or frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": + accept_frame = False + + # Check if it's a broadcast: + if frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": + if frame.ip.dst_ip_address in {self.ip_address, self.ip_network.broadcast_address}: + accept_frame = True + else: + if frame.ethernet.dst_mac_addr == self.mac_address: + accept_frame = True + + if accept_frame: self._connected_node.receive_frame(frame=frame, from_nic=self) return True return False diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 172cc711..473712ea 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -690,6 +690,47 @@ class RouterICMP(ICMP): self.router.process_frame(frame, from_nic) +class RouterNIC(NIC): + """ + A Router-specific Network Interface Card (NIC) that extends the standard NIC functionality. + + This class overrides the standard Node NIC's Layer 3 (L3) broadcast/unicast checks. It is designed + to handle network frames in a manner specific to routers, allowing them to efficiently process + and route network traffic. + """ + + def receive_frame(self, frame: Frame) -> bool: + """ + Receive and process a network frame from the connected link, provided the NIC is enabled. + + This method is tailored for router behavior. It decrements the frame's Time To Live (TTL), checks for TTL + expiration, and captures the frame using PCAP (Packet Capture). The frame is accepted if it is destined for + this NIC's MAC address or is a broadcast frame. + + Key Differences from Standard NIC: + - Does not perform Layer 3 (IP-based) broadcast checks. + - Only checks for Layer 2 (Ethernet) destination MAC address and broadcast frames. + + :param frame: The network frame being received. This should be an instance of the Frame class. + :return: Returns True if the frame is processed and passed to the connected node, False otherwise. + """ + if self.enabled: + frame.decrement_ttl() + if frame.ip and frame.ip.ttl < 1: + self._connected_node.sys_log.info("Frame discarded as TTL limit reached") + return False + frame.set_received_timestamp() + self.pcap.capture(frame) + # If this destination or is broadcast + if frame.ethernet.dst_mac_addr == self.mac_address or frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": + self._connected_node.receive_frame(frame=frame, from_nic=self) + return True + return False + + def __str__(self) -> str: + return f"{self.mac_address}/{self.ip_address}" + + class Router(Node): """ A class to represent a network router node. @@ -700,7 +741,7 @@ class Router(Node): """ num_ports: int - ethernet_ports: Dict[int, NIC] = {} + ethernet_ports: Dict[int, RouterNIC] = {} acl: AccessControlList route_table: RouteTable arp: RouterARPCache @@ -719,7 +760,7 @@ class Router(Node): kwargs["icmp"] = RouterICMP(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp"), router=self) super().__init__(hostname=hostname, num_ports=num_ports, **kwargs) for i in range(1, self.num_ports + 1): - nic = NIC(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") + nic = RouterNIC(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") self.connect_nic(nic) self.ethernet_ports[i] = nic diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 8658f155..a95846a3 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -1,6 +1,6 @@ from __future__ import annotations -from ipaddress import IPv4Address +from ipaddress import IPv4Address, IPv4Network from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING, Union from prettytable import MARKDOWN, PrettyTable @@ -141,41 +141,76 @@ class SessionManager: def receive_payload_from_software_manager( self, payload: Any, - dst_ip_address: Optional[IPv4Address] = None, + dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, dst_port: Optional[Port] = None, session_id: Optional[str] = None, is_reattempt: bool = False, ) -> Union[Any, None]: """ - Receive a payload from the SoftwareManager. + Receive a payload from the SoftwareManager and send it to the appropriate NIC for transmission. - If no session_id, a Session is established. Once established, the payload is sent to ``send_payload_to_nic``. + This method supports both unicast and Layer 3 broadcast transmissions. If `dst_ip_address` is an + IPv4Network, a broadcast is initiated. For unicast, the destination MAC address is resolved via ARP. + A new session is established if `session_id` is not provided, and an existing session is used otherwise. :param payload: The payload to be sent. - :param session_id: The Session ID the payload is to originate from. Optional. If None, one will be created. + :param dst_ip_address: The destination IP address or network for broadcast. Optional. + :param dst_port: The destination port for the TCP packet. Optional. + :param session_id: The Session ID from which the payload originates. Optional. + :param is_reattempt: Flag to indicate if this is a reattempt after an ARP request. Default is False. + :return: The outcome of sending the frame, or None if sending was unsuccessful. """ + is_broadcast = False + outbound_nic = None + dst_mac_address = None + + # Use session details if session_id is provided if session_id: session = self.sessions_by_uuid[session_id] - dst_ip_address = self.sessions_by_uuid[session_id].with_ip_address - dst_port = self.sessions_by_uuid[session_id].dst_port + dst_ip_address = session.with_ip_address + dst_port = session.dst_port - dst_mac_address = self.arp_cache.get_arp_cache_mac_address(dst_ip_address) + # Determine if the payload is for broadcast or unicast - if dst_mac_address: - outbound_nic = self.arp_cache.get_arp_cache_nic(dst_ip_address) + # Handle broadcast transmission + if isinstance(dst_ip_address, IPv4Network): + is_broadcast = True + dst_ip_address = dst_ip_address.broadcast_address + if dst_ip_address: + # Find a suitable NIC for the broadcast + for nic in self.arp_cache.nics.values(): + if dst_ip_address in nic.ip_network and nic.enabled: + dst_mac_address = "ff:ff:ff:ff:ff:ff" + outbound_nic = nic else: - if not is_reattempt: - self.arp_cache.send_arp_request(dst_ip_address) - return self.receive_payload_from_software_manager( - payload=payload, - dst_ip_address=dst_ip_address, - dst_port=dst_port, - session_id=session_id, - is_reattempt=True, - ) - else: - return + # Resolve MAC address for unicast transmission + dst_mac_address = self.arp_cache.get_arp_cache_mac_address(dst_ip_address) + # Resolve outbound NIC for unicast transmission + if dst_mac_address: + outbound_nic = self.arp_cache.get_arp_cache_nic(dst_ip_address) + + # If MAC address not found, initiate ARP request + else: + if not is_reattempt: + self.arp_cache.send_arp_request(dst_ip_address) + # Reattempt payload transmission after ARP request + return self.receive_payload_from_software_manager( + payload=payload, + dst_ip_address=dst_ip_address, + dst_port=dst_port, + session_id=session_id, + is_reattempt=True, + ) + else: + # Return None if reattempt fails + return + + # Check if outbound NIC and destination MAC address are resolved + if not outbound_nic or not dst_mac_address: + return False + + # Construct the frame for transmission frame = Frame( ethernet=EthernetHeader(src_mac_addr=outbound_nic.mac_address, dst_mac_addr=dst_mac_address), ip=IPPacket( @@ -189,15 +224,17 @@ class SessionManager: payload=payload, ) - if not session_id: + # Manage session for unicast transmission + if not (is_broadcast and session_id): session_key = self._get_session_key(frame, inbound_frame=False) session = self.sessions_by_key.get(session_key) if not session: - # Create new session + # Create a new session if it doesn't exist session = Session.from_session_key(session_key) self.sessions_by_key[session_key] = session self.sessions_by_uuid[session.uuid] = session + # Send the frame through the NIC return outbound_nic.send_frame(frame) def receive_frame(self, frame: Frame): diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index 21a121c1..95948a1e 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -1,4 +1,4 @@ -from ipaddress import IPv4Address +from ipaddress import IPv4Address, IPv4Network from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING, Union from prettytable import MARKDOWN, PrettyTable @@ -130,20 +130,28 @@ class SoftwareManager: def send_payload_to_session_manager( self, payload: Any, - dest_ip_address: Optional[IPv4Address] = None, + dest_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, dest_port: Optional[Port] = None, session_id: Optional[str] = None, ) -> bool: """ - Send a payload to the SessionManager. + Sends a payload to the SessionManager for network transmission. + + This method is responsible for initiating the process of sending network payloads. It supports both + unicast and Layer 3 broadcast transmissions. For broadcasts, the destination IP should be specified + as an IPv4Network. :param payload: The payload to be sent. - :param dest_ip_address: The ip address of the payload destination. - :param dest_port: The port of the payload destination. - :param session_id: The Session ID the payload is to originate from. Optional. + :param dest_ip_address: The IP address or network (for broadcasts) of the payload destination. + :param dest_port: The destination port for the payload. Optional. + :param session_id: The Session ID from which the payload originates. Optional. + :return: True if the payload was successfully sent, False otherwise. """ return self.session_manager.receive_payload_from_software_manager( - payload=payload, dst_ip_address=dest_ip_address, dst_port=dest_port, session_id=session_id + payload=payload, + dst_ip_address=dest_ip_address, + dst_port=dest_port, + session_id=session_id, ) def receive_payload_from_session_manager(self, payload: Any, port: Port, protocol: IPProtocol, session_id: str): diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index b393ffd8..d8aed2fb 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -2,8 +2,8 @@ import copy from abc import abstractmethod from datetime import datetime from enum import Enum -from ipaddress import IPv4Address -from typing import Any, Dict, Optional +from ipaddress import IPv4Address, IPv4Network +from typing import Any, Dict, Optional, Union from primaite.simulator.core import _LOGGER, RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file_system import FileSystem, Folder @@ -317,19 +317,22 @@ class IOSoftware(Software): self, payload: Any, session_id: Optional[str] = None, - dest_ip_address: Optional[IPv4Address] = None, + dest_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, dest_port: Optional[Port] = None, **kwargs, ) -> bool: """ - Sends a payload to the SessionManager. + Sends a payload to the SessionManager for network transmission. + + This method is responsible for initiating the process of sending network payloads. It supports both + unicast and Layer 3 broadcast transmissions. For broadcasts, the destination IP should be specified + as an IPv4Network. It delegates the actual sending process to the SoftwareManager. :param payload: The payload to be sent. - :param dest_ip_address: The ip address of the payload destination. - :param dest_port: The port of the payload destination. - :param session_id: The Session ID the payload is to originate from. Optional. - - :return: True if successful, False otherwise. + :param dest_ip_address: The IP address or network (for broadcasts) of the payload destination. + :param dest_port: The destination port for the payload. Optional. + :param session_id: The Session ID from which the payload originates. Optional. + :return: True if the payload was successfully sent, False otherwise. """ if not self._can_perform_action(): return False diff --git a/tests/integration_tests/network/test_broadcast.py b/tests/integration_tests/network/test_broadcast.py new file mode 100644 index 00000000..b9ecb28b --- /dev/null +++ b/tests/integration_tests/network/test_broadcast.py @@ -0,0 +1,180 @@ +from ipaddress import IPv4Address, IPv4Network +from typing import Any, Dict, List, Tuple + +import pytest + +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.services.service import Service + + +class BroadcastService(Service): + """A service for sending broadcast and unicast messages over a network.""" + + def __init__(self, **kwargs): + # Set default service properties for broadcasting + kwargs["name"] = "BroadcastService" + kwargs["port"] = Port.HTTP + kwargs["protocol"] = IPProtocol.TCP + super().__init__(**kwargs) + + def describe_state(self) -> Dict: + # Implement state description for the service + pass + + def unicast(self, ip_address: IPv4Address): + # Send a unicast payload to a specific IP address + super().send( + payload="unicast", + dest_ip_address=ip_address, + dest_port=Port.HTTP, + ) + + def broadcast(self, ip_network: IPv4Network): + # Send a broadcast payload to an entire IP network + super().send( + payload="broadcast", + dest_ip_address=ip_network, + dest_port=Port.HTTP, + ) + + +class BroadcastClient(Application): + """A client application to receive broadcast and unicast messages.""" + + payloads_received: List = [] + + def __init__(self, **kwargs): + # Set default client properties + kwargs["name"] = "BroadcastClient" + kwargs["port"] = Port.HTTP + kwargs["protocol"] = IPProtocol.TCP + super().__init__(**kwargs) + + def describe_state(self) -> Dict: + # Implement state description for the application + pass + + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + # Append received payloads to the list and print a message + self.payloads_received.append(payload) + print(f"Payload: {payload} received on node {self.sys_log.hostname}") + + +@pytest.fixture(scope="function") +def broadcast_network() -> Network: + network = Network() + + client_1 = Computer( + hostname="client_1", + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + client_1.power_on() + client_1.software_manager.install(BroadcastClient) + application_1 = client_1.software_manager.software["BroadcastClient"] + application_1.run() + + client_2 = Computer( + hostname="client_2", + ip_address="192.168.1.3", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + client_2.power_on() + client_2.software_manager.install(BroadcastClient) + application_2 = client_2.software_manager.software["BroadcastClient"] + application_2.run() + + server_1 = Server( + hostname="server_1", + ip_address="192.168.1.1", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + server_1.power_on() + + server_1.software_manager.install(BroadcastService) + service: BroadcastService = server_1.software_manager.software["BroadcastService"] + service.start() + + switch_1 = Switch(hostname="switch_1", num_ports=6, start_up_duration=0) + switch_1.power_on() + + network.connect(endpoint_a=client_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[1]) + network.connect(endpoint_a=client_2.ethernet_port[1], endpoint_b=switch_1.switch_ports[2]) + network.connect(endpoint_a=server_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[3]) + + return network + + +@pytest.fixture(scope="function") +def broadcast_service_and_clients(broadcast_network) -> Tuple[BroadcastService, BroadcastClient, BroadcastClient]: + client_1: BroadcastClient = broadcast_network.get_node_by_hostname("client_1").software_manager.software[ + "BroadcastClient" + ] + client_2: BroadcastClient = broadcast_network.get_node_by_hostname("client_2").software_manager.software[ + "BroadcastClient" + ] + service: BroadcastService = broadcast_network.get_node_by_hostname("server_1").software_manager.software[ + "BroadcastService" + ] + + return service, client_1, client_2 + + +def test_broadcast_correct_subnet(broadcast_service_and_clients): + service, client_1, client_2 = broadcast_service_and_clients + + assert not client_1.payloads_received + assert not client_2.payloads_received + + service.broadcast(IPv4Network("192.168.1.0/24")) + + assert client_1.payloads_received == ["broadcast"] + assert client_2.payloads_received == ["broadcast"] + + +def test_broadcast_incorrect_subnet(broadcast_service_and_clients): + service, client_1, client_2 = broadcast_service_and_clients + + assert not client_1.payloads_received + assert not client_2.payloads_received + + service.broadcast(IPv4Network("192.168.2.0/24")) + + assert not client_1.payloads_received + assert not client_2.payloads_received + + +def test_unicast_correct_address(broadcast_service_and_clients): + service, client_1, client_2 = broadcast_service_and_clients + + assert not client_1.payloads_received + assert not client_2.payloads_received + + service.unicast(IPv4Address("192.168.1.2")) + + assert client_1.payloads_received == ["unicast"] + assert not client_2.payloads_received + + +def test_unicast_incorrect_address(broadcast_service_and_clients): + service, client_1, client_2 = broadcast_service_and_clients + + assert not client_1.payloads_received + assert not client_2.payloads_received + + service.unicast(IPv4Address("192.168.2.2")) + + assert not client_1.payloads_received + assert not client_2.payloads_received From 59d1a6668e21972b4d162e420794e9c595e05699 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 5 Jan 2024 22:19:54 +0000 Subject: [PATCH 503/980] #2139 - Updated the CHANGELOG.md with broadcast entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60961802..e82a1038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,7 +41,7 @@ SessionManager. - **RouterNIC Class**: Introduced a new class `RouterNIC`, extending the standard `NIC` functionality. This class is specifically designed for router operations, optimizing the processing and routing of network traffic. - **Custom Layer-3 Processing**: The `RouterNIC` class includes custom handling for network frames, bypassing standard Node NIC's Layer 3 broadcast/unicast checks. This allows for more efficient routing behavior in network scenarios where router-specific frame processing is required. - **Enhanced Frame Reception**: The `receive_frame` method in `RouterNIC` is tailored to handle frames based on Layer 2 (Ethernet) checks, focusing on MAC address-based routing and broadcast frame acceptance. - +- **Subnet-Wide Broadcasting for Services and Applications**: Implemented the ability for services and applications to conduct broadcasts across an entire IPv4 subnet within the network simulation framework. ### Changed - Integrated the RouteTable into the Routers frame processing. From 8b43f6abe36952bec7c678e4accf3e48f1defa26 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 8 Jan 2024 10:30:38 +0000 Subject: [PATCH 504/980] #2139 - updated docstring in send_arp_request function in base.py --- src/primaite/simulator/network/hardware/base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 7e6e0a3b..54fd1238 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -703,9 +703,15 @@ class ARPCache: Perform a standard ARP request for a given target IP address. Broadcasts the request through all enabled NICs to determine the MAC address corresponding to the target IP - address. + address. This method can be configured to ignore specific networks when sending out ARP requests, + which is useful in environments where certain addresses should not be queried. :param target_ip_address: The target IP address to send an ARP request for. + :param ignore_networks: An optional list of IPv4 addresses representing networks to be excluded from the ARP + request broadcast. Each address in this list indicates a network which will not be queried during the ARP + request process. This is particularly useful in complex network environments where traffic should be + minimized or controlled to specific subnets. It is mainly used by the router to prevent ARP requests being + sent back to their source. """ for nic in self.nics.values(): use_nic = True From 27f70204ed009c9fa18ea6de935c082792caeea7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 8 Jan 2024 13:28:34 +0000 Subject: [PATCH 505/980] Fix minor issues in actions --- src/primaite/game/agent/actions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 47cd2394..d99d3818 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -89,7 +89,7 @@ class NodeServiceAbstractAction(AbstractAction): service_name = self.manager.get_service_name_by_idx(node_id, service_id) if node_name is None or service_name is None: return ["do_nothing"] - return ["network", "node", node_name, "services", service_name, self.verb] + return ["network", "node", node_name, "service", service_name, self.verb] class NodeServiceScanAction(NodeServiceAbstractAction): @@ -460,13 +460,13 @@ class NetworkACLAddRuleAction(AbstractAction): dst_ip = "ALL" return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS else: - dst_ip = self.manager.get_ip_address_by_idx(dest_ip_id) + dst_ip = self.manager.get_ip_address_by_idx(dest_ip_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 if dest_port_id == 1: dst_port = "ALL" else: - dst_port = self.manager.get_port_by_idx(dest_port_id) + dst_port = self.manager.get_port_by_idx(dest_port_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 return [ From 294c8b982f48556c053dceecc19337ca100a4e42 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 8 Jan 2024 13:28:55 +0000 Subject: [PATCH 506/980] Add convenience method for router acl --- src/primaite/simulator/network/hardware/nodes/router.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 0234934d..0e6bc946 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -319,6 +319,15 @@ class AccessControlList(SimComponent): ) print(table) + @property + def num_rules(self) -> int: + """ + Get the number of rules in the ACL. + + :return: The number of rules in the ACL. + """ + return len([rule for rule in self._acl if rule is not None]) + class RouteEntry(SimComponent): """ From 534f84ccd1382cadfdbc3c7017a3e2b0c6597e02 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 8 Jan 2024 13:29:17 +0000 Subject: [PATCH 507/980] Add action tests. --- .../game_layer/test_actions.py | 133 +++++++++++++++--- .../_primaite/_game/_agent/test_actions.py | 4 +- 2 files changed, 118 insertions(+), 19 deletions(-) diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 85660796..b756553e 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -69,17 +69,17 @@ def install_stuff_to_sim(sim: Simulation): # 1: Set up network hardware # 1.1: Configure the router - router = Router(hostname="router", num_ports=3) + router = Router(hostname="router", num_ports=3, operating_state=NodeOperatingState.ON) router.power_on() router.configure_port(port=1, ip_address="10.0.1.1", subnet_mask="255.255.255.0") router.configure_port(port=2, ip_address="10.0.2.1", subnet_mask="255.255.255.0") # 1.2: Create and connect switches - switch_1 = Switch(hostname="switch_1", num_ports=6) + switch_1 = Switch(hostname="switch_1", num_ports=6, operating_state=NodeOperatingState.ON) switch_1.power_on() network.connect(endpoint_a=router.ethernet_ports[1], endpoint_b=switch_1.switch_ports[6]) router.enable_port(1) - switch_2 = Switch(hostname="switch_2", num_ports=6) + switch_2 = Switch(hostname="switch_2", num_ports=6, operating_state=NodeOperatingState.ON) switch_2.power_on() network.connect(endpoint_a=router.ethernet_ports[2], endpoint_b=switch_2.switch_ports[6]) router.enable_port(2) @@ -191,6 +191,7 @@ def game_and_agent(): {"type": "NODE_SERVICE_RESTART"}, {"type": "NODE_SERVICE_DISABLE"}, {"type": "NODE_SERVICE_ENABLE"}, + {"type": "NODE_SERVICE_PATCH"}, {"type": "NODE_APPLICATION_EXECUTE"}, {"type": "NODE_FILE_SCAN"}, {"type": "NODE_FILE_CHECKHASH"}, @@ -259,31 +260,129 @@ def test_do_nothing_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]) game.step() -@pytest.mark.skip(reason="Waiting to merge ticket 2160") +# @pytest.mark.skip(reason="Waiting to merge ticket 2166") def test_node_service_scan_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): """ Test that the NodeServiceScanAction can form a request and that it is accepted by the simulation. The health status of applications is not always updated in the state dict, rather the agent needs to perform a scan. - Therefore, we set the web browser to be corrupted, check the state is still good, then perform a scan, and check + Therefore, we set a service to be compromised, check the state is still good, then perform a scan, and check that the state changes to the true value. """ game, agent = game_and_agent - browser = game.simulation.network.get_node_by_hostname("client_1").software_manager.software.get("WebBrowser") - browser.health_state_actual = SoftwareHealthState.COMPROMISED + # 1: Check that the service starts off in a good state, and that visible state is hidden until first scan + svc = game.simulation.network.get_node_by_hostname("client_1").software_manager.software.get("DNSClient") + assert svc.health_state_actual == SoftwareHealthState.GOOD + assert svc.health_state_visible == SoftwareHealthState.UNUSED - state_before = game.get_sim_state() - assert ( - game.get_sim_state()["network"]["nodes"]["client_1"]["applications"]["WebBrowser"]["health_state"] - == SoftwareHealthState.GOOD - ) + # 2: Scan and check that the visible state is now correct action = ("NODE_SERVICE_SCAN", {"node_id": 0, "service_id": 0}) agent.store_action(action) game.step() - state_after = game.get_sim_state() - pass - assert ( - game.get_sim_state()["network"]["nodes"]["client_1"]["services"]["WebBrowser"]["health_state"] - == SoftwareHealthState.COMPROMISED + assert svc.health_state_actual == SoftwareHealthState.GOOD + assert svc.health_state_visible == SoftwareHealthState.GOOD + + # 3: Corrupt the service and check that the visible state is still good + svc.health_state_actual = SoftwareHealthState.COMPROMISED + assert svc.health_state_visible == SoftwareHealthState.GOOD + + # 4: Scan and check that the visible state is now correct + action = ("NODE_SERVICE_SCAN", {"node_id": 0, "service_id": 0}) + agent.store_action(action) + game.step() + assert svc.health_state_actual == SoftwareHealthState.COMPROMISED + assert svc.health_state_visible == SoftwareHealthState.COMPROMISED + + +def test_node_service_patch_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """ + Test that the NodeServicePatchAction can form a request and that it is accepted by the simulation. + + When you initiate a patch action, the software health state turns to PATCHING, then after a few steps, it goes + to GOOD. + """ + game, agent = game_and_agent + + # 1: Corrupt the service + svc = game.simulation.network.get_node_by_hostname("server_1").software_manager.software.get("DNSServer") + svc.health_state_actual = SoftwareHealthState.COMPROMISED + + # 2: Apply a patch action + action = ("NODE_SERVICE_PATCH", {"node_id": 1, "service_id": 0}) + agent.store_action(action) + game.step() + + # 3: Check that the service is now in the patching state + assert svc.health_state_actual == SoftwareHealthState.PATCHING + + # 4: perform a few do-nothing steps and check that the service is now in the good state + action = ("DONOTHING", {}) + agent.store_action(action) + game.step() + assert svc.health_state_actual == SoftwareHealthState.GOOD + + +def test_network_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """ + Test that the NetworkACLAddRuleAction can form a request and that it is accepted by the simulation. + + The ACL starts off with 4 rules, and we add a rule, and check that the ACL now has 5 rules. + """ + game, agent = game_and_agent + + # 1: Check that traffic is normal and acl starts off with 4 rules. + client_1 = game.simulation.network.get_node_by_hostname("client_1") + server_1 = game.simulation.network.get_node_by_hostname("server_1") + server_2 = game.simulation.network.get_node_by_hostname("server_2") + router = game.simulation.network.get_node_by_hostname("router") + assert router.acl.num_rules == 4 + assert client_1.ping("10.0.2.3") # client_1 can ping server_2 + assert server_2.ping("10.0.1.2") # server_2 can ping client_1 + + # 2: Add a rule to block client 1 from reaching server 2 on router + action = ( + "NETWORK_ACL_ADDRULE", + { + "position": 4, # 4th rule + "permission": 2, # DENY + "source_ip_id": 3, # 10.0.1.2 (client_1) + "dest_ip_id": 6, # 10.0.2.3 (server_2) + "dest_port_id": 1, # ALL + "source_port_id": 1, # ALL + "protocol_id": 1, # ALL + }, ) + agent.store_action(action) + game.step() + + # 3: Check that the ACL now has 5 rules, and that client 1 cannot ping server 2 + assert router.acl.num_rules == 5 + assert not client_1.ping("10.0.2.3") # Cannot ping server_2 + assert client_1.ping("10.0.2.2") # Can ping server_1 + assert not server_2.ping( + "10.0.1.2" + ) # Server 2 can't ping client_1 (although rule is one-way, the ping response is blocked) + + # 4: Add a rule to block server_1 from reaching server_2 on router (this should not affect comms as they are on same subnet) + action = ( + "NETWORK_ACL_ADDRULE", + { + "position": 5, # 5th rule + "permission": 2, # DENY + "source_ip_id": 5, # 10.0.2.2 (server_1) + "dest_ip_id": 6, # 10.0.2.3 (server_2) + "dest_port_id": 1, # ALL + "source_port_id": 1, # ALL + "protocol_id": 1, # ALL + }, + ) + agent.store_action(action) + game.step() + + # 5: Check that the ACL now has 6 rules, but that server_1 can still ping server_2 + assert router.acl.num_rules == 6 + assert server_1.ping("10.0.2.3") # Can ping server_2 + + +# def test_network_acl_removerule_integration() diff --git a/tests/unit_tests/_primaite/_game/_agent/test_actions.py b/tests/unit_tests/_primaite/_game/_agent/test_actions.py index 9b641fe2..b41e22c9 100644 --- a/tests/unit_tests/_primaite/_game/_agent/test_actions.py +++ b/tests/unit_tests/_primaite/_game/_agent/test_actions.py @@ -62,7 +62,7 @@ def test_service_action_form_request(node_name, service_name, expect_to_do_nothi if expect_to_do_nothing: assert request == ["do_nothing"] else: - assert request == ["network", "node", node_name, "services", service_name, action_verb] + assert request == ["network", "node", node_name, "service", service_name, action_verb] @pytest.mark.parametrize( @@ -87,4 +87,4 @@ def test_service_scan_form_request(node_name, service_name, expect_to_do_nothing if expect_to_do_nothing: assert request == ["do_nothing"] else: - assert request == ["network", "node", node_name, "services", service_name, "scan"] + assert request == ["network", "node", node_name, "service", service_name, "scan"] From 7c0ff8e3f06e8d7f56cd78a685a6d292b2f5d757 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 8 Jan 2024 16:24:09 +0000 Subject: [PATCH 508/980] Add acl remove rule integration test. --- .../game_layer/test_actions.py | 100 +++++++++++++++++- 1 file changed, 97 insertions(+), 3 deletions(-) diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index b756553e..2bc3b095 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -128,9 +128,13 @@ def install_stuff_to_sim(sim: Simulation): # 3: Install server software server_1.software_manager.install(DNSServer) dns_service: DNSServer = server_1.software_manager.software.get("DNSServer") # noqa - dns_service.dns_register("example.com", server_2.ip_address) + dns_service.dns_register("www.example.com", server_2.ip_address) server_2.software_manager.install(WebServer) + # 3.1: Ensure that the dns clients are configured correctly + client_1.software_manager.software.get("DNSClient").dns_server = server_1.ethernet_port[1].ip_address + server_2.software_manager.software.get("DNSClient").dns_server = server_1.ethernet_port[1].ip_address + # 4: Check that client came pre-installed with web browser and dns client assert isinstance(client_1.software_manager.software.get("WebBrowser"), WebBrowser) assert isinstance(client_1.software_manager.software.get("DNSClient"), DNSClient) @@ -260,7 +264,7 @@ def test_do_nothing_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]) game.step() -# @pytest.mark.skip(reason="Waiting to merge ticket 2166") +@pytest.mark.skip(reason="Waiting to merge ticket 2166") def test_node_service_scan_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): """ Test that the NodeServiceScanAction can form a request and that it is accepted by the simulation. @@ -385,4 +389,94 @@ def test_network_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Pro assert server_1.ping("10.0.2.3") # Can ping server_2 -# def test_network_acl_removerule_integration() +def test_network_acl_removerule_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the NetworkACLRemoveRuleAction can form a request and that it is accepted by the simulation.""" + game, agent = game_and_agent + + # 1: Check that http traffic is going across the network nicely. + client_1 = game.simulation.network.get_node_by_hostname("client_1") + server_1 = game.simulation.network.get_node_by_hostname("server_1") + router = game.simulation.network.get_node_by_hostname("router") + + browser: WebBrowser = client_1.software_manager.software.get("WebBrowser") + browser.run() + browser.target_url = "http://www.example.com" + assert browser.get_webpage() # check that the browser can access example.com before we block it + + # 2: Remove rule that allows HTTP traffic across the network + action = ( + "NETWORK_ACL_REMOVERULE", + { + "position": 3, # 4th rule + }, + ) + agent.store_action(action) + game.step() + + # 3: Check that the ACL now has 3 rules, and that client 1 cannot access example.com + assert router.acl.num_rules == 3 + assert not browser.get_webpage() + client_1.software_manager.software.get("DNSClient").dns_cache.clear() + assert client_1.ping("10.0.2.2") # pinging still works because ICMP is allowed + assert client_1.ping("10.0.2.3") + + +def test_network_nic_disable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the NetworkNICDisableAction can form a request and that it is accepted by the simulation.""" + game, agent = game_and_agent + + # 1: Check that client_1 can access the network + client_1 = game.simulation.network.get_node_by_hostname("client_1") + server_1 = game.simulation.network.get_node_by_hostname("server_1") + server_2 = game.simulation.network.get_node_by_hostname("server_2") + + browser: WebBrowser = client_1.software_manager.software.get("WebBrowser") + browser.run() + browser.target_url = "http://www.example.com" + assert browser.get_webpage() # check that the browser can access example.com before we block it + + # 2: Disable the NIC on client_1 + action = ( + "NETWORK_NIC_DISABLE", + { + "node_id": 0, # client_1 + "nic_id": 0, # the only nic (eth-1) + }, + ) + agent.store_action(action) + game.step() + + # 3: Check that the NIC is disabled, and that client 1 cannot access example.com + assert client_1.ethernet_port[1].enabled == False + assert not browser.get_webpage() + assert not client_1.ping("10.0.2.2") + assert not client_1.ping("10.0.2.3") + + # 4: check that servers can still communicate + assert server_1.ping("10.0.2.3") + + +def test_network_nic_enable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the NetworkNICEnableAction can form a request and that it is accepted by the simulation.""" + + game, agent = game_and_agent + + # 1: Disable client_1 nic + client_1 = game.simulation.network.get_node_by_hostname("client_1") + client_1.ethernet_port[1].disable() + assert not client_1.ping("10.0.2.2") + + # 2: Use action to enable nic + action = ( + "NETWORK_NIC_ENABLE", + { + "node_id": 0, # client_1 + "nic_id": 0, # the only nic (eth-1) + }, + ) + agent.store_action(action) + game.step() + + # 3: Check that the NIC is enabled, and that client 1 can ping again + assert client_1.ethernet_port[1].enabled == True + assert client_1.ping("10.0.2.3") From 5d89820a159a17b2bdc614f5898c5728a32174ec Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 9 Jan 2024 12:38:01 +0000 Subject: [PATCH 509/980] Apply PR review suggestions --- src/primaite/game/agent/interface.py | 3 ++- src/primaite/session/environment.py | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 8657fc45..01df33de 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -45,6 +45,7 @@ class AgentSettings(BaseModel): start_settings: Optional[AgentStartSettings] = None "Configuration for when an agent begins performing it's actions" flatten_obs: bool = True + "Whether to flatten the observation space before passing it to the agent. True by default." @classmethod def from_config(cls, config: Optional[Dict]) -> "AgentSettings": @@ -176,7 +177,7 @@ class ProxyAgent(AbstractAgent): reward_function=reward_function, ) self.most_recent_action: ActType - self.flatten_obs: bool = agent_settings.flatten_obs + self.flatten_obs: bool = agent_settings.flatten_obs if agent_settings else False def get_action(self, obs: ObsType, reward: float = 0.0) -> Tuple[str, Dict]: """ diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 36ab3f58..6701f183 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -23,7 +23,6 @@ class PrimaiteGymEnv(gymnasium.Env): super().__init__() self.game: "PrimaiteGame" = game self.agent: ProxyAgent = self.game.rl_agents[0] - self.flatten_obs: bool = False def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: """Perform a step in the environment.""" From 82cd8780f9467c760dd3cacc8fdf79dcb21ec035 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 9 Jan 2024 14:03:10 +0000 Subject: [PATCH 510/980] Align Software health state enum with CAOS --- src/primaite/simulator/system/software.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 048e6fec..562c9e0d 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -36,12 +36,12 @@ class SoftwareHealthState(Enum): "Unused state." GOOD = 1 "The software is in a good and healthy condition." - COMPROMISED = 2 - "The software's security has been compromised." - OVERWHELMED = 3 - "he software is overwhelmed and not functioning properly." - PATCHING = 4 + PATCHING = 2 "The software is undergoing patching or updates." + COMPROMISED = 3 + "The software's security has been compromised." + OVERWHELMED = 4 + "he software is overwhelmed and not functioning properly." class SoftwareCriticality(Enum): From 716bd626a5e67715aa9f5360208c5457880250f2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 9 Jan 2024 14:29:23 +0000 Subject: [PATCH 511/980] Hide software health state until scan. --- src/primaite/game/agent/observations.py | 5 ++++- src/primaite/simulator/system/software.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 767514b4..eecf4163 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -140,7 +140,10 @@ class ServiceObservation(AbstractObservation): service_state = access_from_nested_dict(state, self.where) if service_state is NOT_PRESENT_IN_STATE: return self.default_observation - return {"operating_status": service_state["operating_state"], "health_status": service_state["health_state"]} + return { + "operating_status": service_state["operating_state"], + "health_status": service_state["health_state_visible"], + } @property def space(self) -> spaces.Space: diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 048e6fec..d7c1fa4e 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -145,8 +145,8 @@ class Software(SimComponent): state = super().describe_state() state.update( { - "health_state": self.health_state_actual.value, - "health_state_red_view": self.health_state_visible.value, + "health_state_actual": self.health_state_actual.value, + "health_state_visible": self.health_state_visible.value, "criticality": self.criticality.value, "patching_count": self.patching_count, "scanning_count": self.scanning_count, From f2a496893cc49cbe90b3b11fd67443f030d9c269 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 9 Jan 2024 14:33:24 +0000 Subject: [PATCH 512/980] Bump VERSION --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index 9414e127..52f460a5 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0b4 +3.0.0b5dev From daa34385e550dc43e984706faa2df024e74d1ad7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 9 Jan 2024 14:53:15 +0000 Subject: [PATCH 513/980] Add agent reset for episodes --- src/primaite/game/agent/data_manipulation_bot.py | 9 +++++++++ src/primaite/game/agent/interface.py | 4 ++++ src/primaite/game/game.py | 1 + 3 files changed, 14 insertions(+) diff --git a/src/primaite/game/agent/data_manipulation_bot.py b/src/primaite/game/agent/data_manipulation_bot.py index 8237ce06..3b558087 100644 --- a/src/primaite/game/agent/data_manipulation_bot.py +++ b/src/primaite/game/agent/data_manipulation_bot.py @@ -15,6 +15,7 @@ class DataManipulationAgent(AbstractScriptedAgent): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + print("red start step: ", self.agent_settings.start_settings.start_step) self._set_next_execution_timestep(self.agent_settings.start_settings.start_step) @@ -27,6 +28,7 @@ class DataManipulationAgent(AbstractScriptedAgent): -self.agent_settings.start_settings.variance, self.agent_settings.start_settings.variance ) self.next_execution_timestep = timestep + random_timestep_increment + print("next execution red step: ", self.next_execution_timestep) def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: """Randomly sample an action from the action space. @@ -41,8 +43,15 @@ class DataManipulationAgent(AbstractScriptedAgent): current_timestep = self.action_manager.game.step_counter if current_timestep < self.next_execution_timestep: + print("red agent doing nothing") return "DONOTHING", {"dummy": 0} self._set_next_execution_timestep(current_timestep + self.agent_settings.start_settings.frequency) + print("red agent doing an execute") return "NODE_APPLICATION_EXECUTE", {"node_id": 0, "application_id": 0} + + def reset_agent_for_episode(self) -> None: + """Set the next execution timestep when the episode resets.""" + super().reset_agent_for_episode() + self._set_next_execution_timestep(self.agent_settings.start_settings.start_step) diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 8657fc45..8b6dd6d4 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -135,6 +135,10 @@ class AbstractAgent(ABC): request = self.action_manager.form_request(action_identifier=action, action_options=options) return request + def reset_agent_for_episode(self) -> None: + """Agent reset logic should go here.""" + pass + class AbstractScriptedAgent(AbstractAgent): """Base class for actors which generate their own behaviour.""" diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 586bca79..08098754 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -162,6 +162,7 @@ class PrimaiteGame: self.simulation.reset_component_for_episode(episode=self.episode_counter) for agent in self.agents: agent.reward_function.total_reward = 0.0 + agent.reset_agent_for_episode() def close(self) -> None: """Close the game, this will close the simulation.""" From 6fc4e156603b7cb81389765eac7ce4d8dabdcf1d Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 9 Jan 2024 15:18:31 +0000 Subject: [PATCH 514/980] #2151: remove changing of health_state_actual in actions and tests --- .../simulator/system/services/service.py | 14 +-- src/primaite/simulator/system/software.py | 6 +- tests/conftest.py | 2 +- .../_system/_services/test_services.py | 100 +++++++++++++++++- .../_system/_services/test_web_server.py | 7 +- 5 files changed, 110 insertions(+), 19 deletions(-) diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index d45ef3a6..1de52e92 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -43,9 +43,6 @@ class Service(IOSoftware): def __init__(self, **kwargs): super().__init__(**kwargs) - self.health_state_visible = SoftwareHealthState.UNUSED - self.health_state_actual = SoftwareHealthState.UNUSED - def _can_perform_action(self) -> bool: """ Checks if the service can perform actions. @@ -118,7 +115,6 @@ class Service(IOSoftware): if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.sys_log.info(f"Stopping service {self.name}") self.operating_state = ServiceOperatingState.STOPPED - self.health_state_actual = SoftwareHealthState.UNUSED def start(self, **kwargs) -> None: """Start the service.""" @@ -129,42 +125,39 @@ class Service(IOSoftware): if self.operating_state == ServiceOperatingState.STOPPED: self.sys_log.info(f"Starting service {self.name}") self.operating_state = ServiceOperatingState.RUNNING - self.health_state_actual = SoftwareHealthState.GOOD + # set software health state to GOOD if initially set to UNUSED + if self.health_state_actual == SoftwareHealthState.UNUSED: + self.health_state_actual = SoftwareHealthState.GOOD def pause(self) -> None: """Pause the service.""" if self.operating_state == ServiceOperatingState.RUNNING: self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.PAUSED - self.health_state_actual = SoftwareHealthState.OVERWHELMED def resume(self) -> None: """Resume paused service.""" if self.operating_state == ServiceOperatingState.PAUSED: self.sys_log.info(f"Resuming service {self.name}") self.operating_state = ServiceOperatingState.RUNNING - self.health_state_actual = SoftwareHealthState.GOOD def restart(self) -> None: """Restart running service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.RESTARTING - self.health_state_actual = SoftwareHealthState.OVERWHELMED self.restart_countdown = self.restart_duration def disable(self) -> None: """Disable the service.""" self.sys_log.info(f"Disabling Application {self.name}") self.operating_state = ServiceOperatingState.DISABLED - self.health_state_actual = SoftwareHealthState.OVERWHELMED def enable(self) -> None: """Enable the disabled service.""" if self.operating_state == ServiceOperatingState.DISABLED: self.sys_log.info(f"Enabling Application {self.name}") self.operating_state = ServiceOperatingState.STOPPED - self.health_state_actual = SoftwareHealthState.OVERWHELMED def apply_timestep(self, timestep: int) -> None: """ @@ -181,5 +174,4 @@ class Service(IOSoftware): if self.restart_countdown <= 0: _LOGGER.debug(f"Restarting finished for service {self.name}") self.operating_state = ServiceOperatingState.RUNNING - self.health_state_actual = SoftwareHealthState.GOOD self.restart_countdown -= 1 diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 38e1f30b..f41a5a86 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -71,9 +71,9 @@ class Software(SimComponent): name: str "The name of the software." - health_state_actual: SoftwareHealthState = SoftwareHealthState.GOOD + health_state_actual: SoftwareHealthState = SoftwareHealthState.UNUSED "The actual health state of the software." - health_state_visible: SoftwareHealthState = SoftwareHealthState.GOOD + health_state_visible: SoftwareHealthState = SoftwareHealthState.UNUSED "The health state of the software visible to the red agent." criticality: SoftwareCriticality = SoftwareCriticality.LOWEST "The criticality level of the software." @@ -282,7 +282,7 @@ class IOSoftware(Software): Returns true if the software can perform actions. """ - if self.software_manager and self.software_manager.node.operating_state is NodeOperatingState.OFF: + if self.software_manager and self.software_manager.node.operating_state == NodeOperatingState.OFF: _LOGGER.debug(f"{self.name} Error: {self.software_manager.node.hostname} is not online.") return False return True diff --git a/tests/conftest.py b/tests/conftest.py index 1ab07dd8..37289674 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -167,7 +167,7 @@ def example_network() -> Network: -------------- -------------- | client_1 |----- ----| server_1 | -------------- | -------------- -------------- -------------- | -------------- - ------| switch_1 |------| router_1 |------| switch_2 |------ + ------| switch_2 |------| router_1 |------| switch_1 |------ -------------- | -------------- -------------- -------------- | -------------- | client_2 |---- ----| server_2 | -------------- -------------- diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py index 016cf011..2c0671d5 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py @@ -19,55 +19,149 @@ def test_scan(service): def test_start_service(service): assert service.operating_state == ServiceOperatingState.STOPPED + assert service.health_state_actual == SoftwareHealthState.UNUSED service.start() assert service.operating_state == ServiceOperatingState.RUNNING + assert service.health_state_actual == SoftwareHealthState.GOOD def test_stop_service(service): service.start() assert service.operating_state == ServiceOperatingState.RUNNING + assert service.health_state_actual == SoftwareHealthState.GOOD service.stop() assert service.operating_state == ServiceOperatingState.STOPPED + assert service.health_state_actual == SoftwareHealthState.GOOD def test_pause_and_resume_service(service): assert service.operating_state == ServiceOperatingState.STOPPED service.resume() assert service.operating_state == ServiceOperatingState.STOPPED + assert service.health_state_actual == SoftwareHealthState.UNUSED service.start() + assert service.health_state_actual == SoftwareHealthState.GOOD service.pause() assert service.operating_state == ServiceOperatingState.PAUSED + assert service.health_state_actual == SoftwareHealthState.GOOD service.resume() assert service.operating_state == ServiceOperatingState.RUNNING + assert service.health_state_actual == SoftwareHealthState.GOOD def test_restart(service): assert service.operating_state == ServiceOperatingState.STOPPED + assert service.health_state_actual == SoftwareHealthState.UNUSED service.restart() assert service.operating_state == ServiceOperatingState.STOPPED + assert service.health_state_actual == SoftwareHealthState.UNUSED service.start() + assert service.health_state_actual == SoftwareHealthState.GOOD service.restart() assert service.operating_state == ServiceOperatingState.RESTARTING + assert service.health_state_actual == SoftwareHealthState.GOOD timestep = 0 while service.operating_state == ServiceOperatingState.RESTARTING: service.apply_timestep(timestep) + assert service.health_state_actual == SoftwareHealthState.GOOD timestep += 1 assert service.operating_state == ServiceOperatingState.RUNNING + assert service.health_state_actual == SoftwareHealthState.GOOD + + +def test_restart_compromised(service): + assert service.operating_state == ServiceOperatingState.STOPPED + assert service.health_state_actual == SoftwareHealthState.UNUSED + service.restart() + assert service.operating_state == ServiceOperatingState.STOPPED + assert service.health_state_actual == SoftwareHealthState.UNUSED + + service.start() + assert service.health_state_actual == SoftwareHealthState.GOOD + + # compromise the service + service.health_state_actual = SoftwareHealthState.COMPROMISED + + service.restart() + assert service.operating_state == ServiceOperatingState.RESTARTING + assert service.health_state_actual == SoftwareHealthState.COMPROMISED + + """ + Service should be compromised even after reset. + + Only way to remove compromised status is via patching. + """ + + timestep = 0 + while service.operating_state == ServiceOperatingState.RESTARTING: + service.apply_timestep(timestep) + assert service.health_state_actual == SoftwareHealthState.COMPROMISED + timestep += 1 + + assert service.operating_state == ServiceOperatingState.RUNNING + assert service.health_state_actual == SoftwareHealthState.COMPROMISED + + +def test_compromised_service_remains_compromised(service): + """ + Tests that a compromised service stays compromised. + + The only way that the service can be uncompromised is by running patch. + """ + service.start() + assert service.health_state_actual == SoftwareHealthState.GOOD + + service.health_state_actual = SoftwareHealthState.COMPROMISED + + service.stop() + assert service.health_state_actual == SoftwareHealthState.COMPROMISED + + service.start() + assert service.health_state_actual == SoftwareHealthState.COMPROMISED + + service.disable() + assert service.health_state_actual == SoftwareHealthState.COMPROMISED + + service.enable() + assert service.health_state_actual == SoftwareHealthState.COMPROMISED + + service.pause() + assert service.health_state_actual == SoftwareHealthState.COMPROMISED + + service.resume() + assert service.health_state_actual == SoftwareHealthState.COMPROMISED + + +def test_service_patching(service): + service.start() + assert service.health_state_actual == SoftwareHealthState.GOOD + + service.health_state_actual = SoftwareHealthState.COMPROMISED + + service.patch() + assert service.health_state_actual == SoftwareHealthState.PATCHING + + for i in range(service.patching_duration + 1): + service.apply_timestep(i) + + assert service.health_state_actual == SoftwareHealthState.GOOD def test_enable_disable(service): service.disable() assert service.operating_state == ServiceOperatingState.DISABLED + assert service.health_state_actual == SoftwareHealthState.UNUSED service.enable() assert service.operating_state == ServiceOperatingState.STOPPED + assert service.health_state_actual == SoftwareHealthState.UNUSED def test_overwhelm_service(service): @@ -76,13 +170,13 @@ def test_overwhelm_service(service): uuid = str(uuid4()) assert service.add_connection(connection_id=uuid) # should be true - assert service.health_state_actual is SoftwareHealthState.GOOD + assert service.health_state_actual == SoftwareHealthState.GOOD assert not service.add_connection(connection_id=uuid) # fails because connection already exists - assert service.health_state_actual is SoftwareHealthState.GOOD + assert service.health_state_actual == SoftwareHealthState.GOOD assert service.add_connection(connection_id=str(uuid4())) # succeed - assert service.health_state_actual is SoftwareHealthState.GOOD + assert service.health_state_actual == SoftwareHealthState.GOOD assert not service.add_connection(connection_id=str(uuid4())) # fail because at capacity assert service.health_state_actual is SoftwareHealthState.OVERWHELMED diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py index bbccda27..64277356 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py @@ -1,5 +1,6 @@ import pytest +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.http import ( HttpRequestMethod, @@ -15,7 +16,11 @@ from primaite.simulator.system.services.web_server.web_server import WebServer @pytest.fixture(scope="function") def web_server() -> Server: node = Server( - hostname="web_server", ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + hostname="web_server", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, ) node.software_manager.install(software_class=WebServer) node.software_manager.software.get("WebServer").start() From a4d372d3ebe556fca63ebf6beb7f4d6f55c7fe60 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 9 Jan 2024 16:29:40 +0000 Subject: [PATCH 515/980] #2151: utilise set_health_state method instead of directly changing software states --- .../system/applications/application.py | 5 +--- .../services/database/database_service.py | 2 +- .../simulator/system/services/service.py | 2 +- src/primaite/simulator/system/software.py | 4 +-- .../test_dos_bot_and_server.py | 4 +-- .../_network/_hardware/test_node_actions.py | 6 ++-- .../_system/_services/test_services.py | 15 ++++------ .../_simulator/_system/test_software.py | 29 +++++++++++++++++++ 8 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 tests/unit_tests/_primaite/_simulator/_system/test_software.py diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 898e5917..09828b89 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -3,7 +3,7 @@ from enum import Enum from typing import Any, Dict, Set from primaite import getLogger -from primaite.simulator.system.software import IOSoftware, SoftwareHealthState +from primaite.simulator.system.software import IOSoftware _LOGGER = getLogger(__name__) @@ -38,9 +38,6 @@ class Application(IOSoftware): def __init__(self, **kwargs): super().__init__(**kwargs) - self.health_state_visible = SoftwareHealthState.UNUSED - self.health_state_actual = SoftwareHealthState.UNUSED - def set_original_state(self): """Sets the original state.""" super().set_original_state() diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 6f333091..1df1db9e 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -196,7 +196,7 @@ class DatabaseService(Service): return {"status_code": 404, "data": False} elif query == "DELETE": if self.health_state_actual == SoftwareHealthState.GOOD: - self.health_state_actual = SoftwareHealthState.COMPROMISED + self.set_health_state(SoftwareHealthState.COMPROMISED) return { "status_code": 200, "type": "sql", diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 1de52e92..43c85471 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -127,7 +127,7 @@ class Service(IOSoftware): self.operating_state = ServiceOperatingState.RUNNING # set software health state to GOOD if initially set to UNUSED if self.health_state_actual == SoftwareHealthState.UNUSED: - self.health_state_actual = SoftwareHealthState.GOOD + self.set_health_state(SoftwareHealthState.GOOD) def pause(self) -> None: """Pause the service.""" diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index f41a5a86..4072fab1 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -303,13 +303,13 @@ class IOSoftware(Software): """ # if over or at capacity, set to overwhelmed if len(self._connections) >= self.max_sessions: - self.health_state_actual = SoftwareHealthState.OVERWHELMED + self.set_health_state(SoftwareHealthState.OVERWHELMED) self.sys_log.error(f"{self.name}: Connect request for {connection_id=} declined. Service is at capacity.") return False else: # if service was previously overwhelmed, set to good because there is enough space for connections if self.health_state_actual == SoftwareHealthState.OVERWHELMED: - self.health_state_actual = SoftwareHealthState.GOOD + self.set_health_state(SoftwareHealthState.GOOD) # check that connection already doesn't exist if not self._connections.get(connection_id): diff --git a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py index 85028d75..fb768127 100644 --- a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py +++ b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py @@ -90,7 +90,7 @@ def test_repeating_dos_attack(dos_bot_and_db_server): assert db_server_service.health_state_actual is SoftwareHealthState.OVERWHELMED db_server_service.clear_connections() - db_server_service.health_state_actual = SoftwareHealthState.GOOD + db_server_service.set_health_state(SoftwareHealthState.GOOD) assert len(db_server_service.connections) == 0 computer.apply_timestep(timestep=1) @@ -121,7 +121,7 @@ def test_non_repeating_dos_attack(dos_bot_and_db_server): assert db_server_service.health_state_actual is SoftwareHealthState.OVERWHELMED db_server_service.clear_connections() - db_server_service.health_state_actual = SoftwareHealthState.GOOD + db_server_service.set_health_state(SoftwareHealthState.GOOD) assert len(db_server_service.connections) == 0 computer.apply_timestep(timestep=1) diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py index 5fe5df16..b6f7a86d 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py @@ -53,12 +53,12 @@ def test_node_os_scan(node, service, application): # TODO implement processes # add services to node - service.health_state_actual = SoftwareHealthState.COMPROMISED + service.set_health_state(SoftwareHealthState.COMPROMISED) node.install_service(service=service) assert service.health_state_visible == SoftwareHealthState.UNUSED # add application to node - application.health_state_actual = SoftwareHealthState.COMPROMISED + application.set_health_state(SoftwareHealthState.COMPROMISED) node.install_application(application=application) assert application.health_state_visible == SoftwareHealthState.UNUSED @@ -101,7 +101,7 @@ def test_node_red_scan(node, service, application): assert service.revealed_to_red is False # add application to node - application.health_state_actual = SoftwareHealthState.COMPROMISED + application.set_health_state(SoftwareHealthState.COMPROMISED) node.install_application(application=application) assert application.revealed_to_red is False diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py index 2c0671d5..ac36c660 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py @@ -57,12 +57,15 @@ def test_restart(service): assert service.operating_state == ServiceOperatingState.STOPPED assert service.health_state_actual == SoftwareHealthState.UNUSED service.restart() + # Service is STOPPED. Restart will only work if the service was PAUSED or RUNNING assert service.operating_state == ServiceOperatingState.STOPPED assert service.health_state_actual == SoftwareHealthState.UNUSED service.start() + assert service.operating_state == ServiceOperatingState.RUNNING assert service.health_state_actual == SoftwareHealthState.GOOD service.restart() + # Service is RUNNING. Restart should work assert service.operating_state == ServiceOperatingState.RESTARTING assert service.health_state_actual == SoftwareHealthState.GOOD @@ -77,17 +80,11 @@ def test_restart(service): def test_restart_compromised(service): - assert service.operating_state == ServiceOperatingState.STOPPED - assert service.health_state_actual == SoftwareHealthState.UNUSED - service.restart() - assert service.operating_state == ServiceOperatingState.STOPPED - assert service.health_state_actual == SoftwareHealthState.UNUSED - service.start() assert service.health_state_actual == SoftwareHealthState.GOOD # compromise the service - service.health_state_actual = SoftwareHealthState.COMPROMISED + service.set_health_state(SoftwareHealthState.COMPROMISED) service.restart() assert service.operating_state == ServiceOperatingState.RESTARTING @@ -118,7 +115,7 @@ def test_compromised_service_remains_compromised(service): service.start() assert service.health_state_actual == SoftwareHealthState.GOOD - service.health_state_actual = SoftwareHealthState.COMPROMISED + service.set_health_state(SoftwareHealthState.COMPROMISED) service.stop() assert service.health_state_actual == SoftwareHealthState.COMPROMISED @@ -143,7 +140,7 @@ def test_service_patching(service): service.start() assert service.health_state_actual == SoftwareHealthState.GOOD - service.health_state_actual = SoftwareHealthState.COMPROMISED + service.set_health_state(SoftwareHealthState.COMPROMISED) service.patch() assert service.health_state_actual == SoftwareHealthState.PATCHING diff --git a/tests/unit_tests/_primaite/_simulator/_system/test_software.py b/tests/unit_tests/_primaite/_simulator/_system/test_software.py new file mode 100644 index 00000000..e77cd895 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/test_software.py @@ -0,0 +1,29 @@ +from typing import Dict + +import pytest + +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.system.software import Software, SoftwareHealthState + + +class TestSoftware(Software): + def describe_state(self) -> Dict: + pass + + +@pytest.fixture(scope="function") +def software(file_system): + return TestSoftware( + name="TestSoftware", port=Port.ARP, file_system=file_system, sys_log=SysLog(hostname="test_service") + ) + + +def test_software_creation(software): + assert software is not None + + +def test_software_set_health_state(software): + assert software.health_state_actual == SoftwareHealthState.UNUSED + software.set_health_state(SoftwareHealthState.GOOD) + assert software.health_state_actual == SoftwareHealthState.GOOD From e73783f6fa2dc03c5c3274f923ae42460690d561 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 9 Jan 2024 17:10:12 +0000 Subject: [PATCH 516/980] Fixed issue where data manipulation was always executing --- .../services/red_services/data_manipulation_bot.py | 10 ++++++++-- src/primaite/simulator/system/software.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index 44a56cf1..fcd9a3cc 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -73,7 +73,7 @@ class DataManipulationBot(DatabaseClient): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() - rm.add_request(name="execute", request_type=RequestType(func=lambda request, context: self.run())) + rm.add_request(name="execute", request_type=RequestType(func=lambda request, context: self.attack())) return rm @@ -169,6 +169,12 @@ class DataManipulationBot(DatabaseClient): Calls the parent classes execute method before starting the application loop. """ super().run() + + def attack(self): + """Perform the attack steps after opening the application.""" + if not self._can_perform_action(): + _LOGGER.debug("Data manipulation application attempted to execute but it cannot perform actions right now.") + self.run() self._application_loop() def _application_loop(self): @@ -199,4 +205,4 @@ class DataManipulationBot(DatabaseClient): :param timestep: The timestep value to update the bot's state. """ - self._application_loop() + pass diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 048e6fec..ca667f46 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -278,7 +278,7 @@ class IOSoftware(Software): Returns true if the software can perform actions. """ - if self.software_manager and self.software_manager.node.operating_state is NodeOperatingState.OFF: + if self.software_manager and self.software_manager.node.operating_state is not NodeOperatingState.ON: _LOGGER.debug(f"{self.name} Error: {self.software_manager.node.hostname} is not online.") return False return True From b7cc940e9dd1485b4aada9d0f208bb17b3c4bee4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 10 Jan 2024 09:07:51 +0000 Subject: [PATCH 517/980] Remove temporary print statements --- src/primaite/game/agent/data_manipulation_bot.py | 5 ----- src/primaite/game/agent/rewards.py | 1 - 2 files changed, 6 deletions(-) diff --git a/src/primaite/game/agent/data_manipulation_bot.py b/src/primaite/game/agent/data_manipulation_bot.py index 3b558087..7ad45518 100644 --- a/src/primaite/game/agent/data_manipulation_bot.py +++ b/src/primaite/game/agent/data_manipulation_bot.py @@ -15,8 +15,6 @@ class DataManipulationAgent(AbstractScriptedAgent): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - print("red start step: ", self.agent_settings.start_settings.start_step) - self._set_next_execution_timestep(self.agent_settings.start_settings.start_step) def _set_next_execution_timestep(self, timestep: int) -> None: @@ -28,7 +26,6 @@ class DataManipulationAgent(AbstractScriptedAgent): -self.agent_settings.start_settings.variance, self.agent_settings.start_settings.variance ) self.next_execution_timestep = timestep + random_timestep_increment - print("next execution red step: ", self.next_execution_timestep) def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: """Randomly sample an action from the action space. @@ -43,12 +40,10 @@ class DataManipulationAgent(AbstractScriptedAgent): current_timestep = self.action_manager.game.step_counter if current_timestep < self.next_execution_timestep: - print("red agent doing nothing") return "DONOTHING", {"dummy": 0} self._set_next_execution_timestep(current_timestep + self.agent_settings.start_settings.frequency) - print("red agent doing an execute") return "NODE_APPLICATION_EXECUTE", {"node_id": 0, "application_id": 0} def reset_agent_for_episode(self) -> None: diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 9b3dfb80..cb8f8cb1 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -181,7 +181,6 @@ class WebServer404Penalty(AbstractReward): """ web_service_state = access_from_nested_dict(state, self.location_in_state) if web_service_state is NOT_PRESENT_IN_STATE: - print("error getting web service state") return 0.0 most_recent_return_code = web_service_state["last_response_status_code"] # TODO: reward needs to use the current web state. Observation should return web state at the time of last scan. From b6e414bd705615ea2bad75f1376f6c825d4e7004 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 10 Jan 2024 09:14:07 +0000 Subject: [PATCH 518/980] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c712ef66..7a0ef4c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - Made packet capture and system logging optional (off by default). To turn on, change the io_settings.save_pcap_logs and io_settings.save_sys_logs settings in the config. - Made observation space flattening optional (on by default). To turn off for an agent, change the agent_settings.flatten_obs setting in the config. - +- Fixed an issue where the data manipulation attack was triggered at episode start. ### Added - Network Hardware - Added base hardware module with NIC, SwitchPort, Node, and Link. Nodes have From c985b8793dfe4b1a1a9f2c309bd3ce28bce40aec Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 10 Jan 2024 11:58:36 +0000 Subject: [PATCH 519/980] #2151 and #2166: added tests for application being unused + even more tests --- .../system/applications/application.py | 5 +- .../system/services/ftp/ftp_service.py | 6 ++- .../simulator/system/services/service.py | 2 + src/primaite/simulator/system/software.py | 2 +- tests/conftest.py | 5 +- .../system/test_application_on_node.py | 23 +++++---- .../system/test_service_on_node.py | 7 +-- .../_applications/test_application_actions.py | 0 .../_applications/test_applications.py | 50 +++++++++++++++++++ 9 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_applications/test_application_actions.py create mode 100644 tests/unit_tests/_primaite/_simulator/_system/_applications/test_applications.py diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 09828b89..322ac808 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -3,7 +3,7 @@ from enum import Enum from typing import Any, Dict, Set from primaite import getLogger -from primaite.simulator.system.software import IOSoftware +from primaite.simulator.system.software import IOSoftware, SoftwareHealthState _LOGGER = getLogger(__name__) @@ -92,6 +92,9 @@ class Application(IOSoftware): if self.operating_state == ApplicationOperatingState.CLOSED: self.sys_log.info(f"Running Application {self.name}") self.operating_state = ApplicationOperatingState.RUNNING + # set software health state to GOOD if initially set to UNUSED + if self.health_state_actual == SoftwareHealthState.UNUSED: + self.set_health_state(SoftwareHealthState.GOOD) def _application_loop(self): """The main application loop.""" diff --git a/src/primaite/simulator/system/services/ftp/ftp_service.py b/src/primaite/simulator/system/services/ftp/ftp_service.py index f2c01544..276a9d5f 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_service.py +++ b/src/primaite/simulator/system/services/ftp/ftp_service.py @@ -1,7 +1,7 @@ import shutil from abc import ABC from ipaddress import IPv4Address -from typing import Optional +from typing import Dict, Optional from primaite.simulator.file_system.file_system import File from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode @@ -16,6 +16,10 @@ class FTPServiceABC(Service, ABC): Contains shared methods between both classes. """ + def describe_state(self) -> Dict: + """Returns a Dict of the FTPService state.""" + return super().describe_state() + def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: """ Process the command in the FTP Packet. diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 43c85471..162678a0 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,3 +1,4 @@ +from abc import abstractmethod from enum import Enum from typing import Any, Dict, Optional @@ -95,6 +96,7 @@ class Service(IOSoftware): rm.add_request("enable", RequestType(func=lambda request, context: self.enable())) return rm + @abstractmethod def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 4072fab1..8656154c 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -282,7 +282,7 @@ class IOSoftware(Software): Returns true if the software can perform actions. """ - if self.software_manager and self.software_manager.node.operating_state == NodeOperatingState.OFF: + if self.software_manager and self.software_manager.node.operating_state != NodeOperatingState.ON: _LOGGER.debug(f"{self.name} Error: {self.software_manager.node.hostname} is not online.") return False return True diff --git a/tests/conftest.py b/tests/conftest.py index 37289674..c37226a5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -40,6 +40,9 @@ from primaite.simulator.network.hardware.base import Link, Node class TestService(Service): """Test Service class""" + def describe_state(self) -> Dict: + return super().describe_state() + def __init__(self, **kwargs): kwargs["name"] = "TestService" kwargs["port"] = Port.HTTP @@ -60,7 +63,7 @@ class TestApplication(Application): super().__init__(**kwargs) def describe_state(self) -> Dict: - pass + return super().describe_state() @pytest.fixture(scope="function") diff --git a/tests/integration_tests/system/test_application_on_node.py b/tests/integration_tests/system/test_application_on_node.py index 46be5e55..60497f22 100644 --- a/tests/integration_tests/system/test_application_on_node.py +++ b/tests/integration_tests/system/test_application_on_node.py @@ -24,8 +24,8 @@ def populated_node(application_class) -> Tuple[Application, Computer]: return app, computer -def test_service_on_offline_node(application_class): - """Test to check that the service cannot be interacted with when node it is on is off.""" +def test_application_on_offline_node(application_class): + """Test to check that the application cannot be interacted with when node it is on is off.""" computer: Computer = Computer( hostname="test_computer", ip_address="192.168.1.2", @@ -49,8 +49,8 @@ def test_service_on_offline_node(application_class): assert app.operating_state is ApplicationOperatingState.CLOSED -def test_server_turns_off_service(populated_node): - """Check that the service is turned off when the server is turned off""" +def test_server_turns_off_application(populated_node): + """Check that the application is turned off when the server is turned off""" app, computer = populated_node assert computer.operating_state is NodeOperatingState.ON @@ -65,8 +65,8 @@ def test_server_turns_off_service(populated_node): assert app.operating_state is ApplicationOperatingState.CLOSED -def test_service_cannot_be_turned_on_when_server_is_off(populated_node): - """Check that the service cannot be started when the server is off.""" +def test_application_cannot_be_turned_on_when_computer_is_off(populated_node): + """Check that the application cannot be started when the computer is off.""" app, computer = populated_node assert computer.operating_state is NodeOperatingState.ON @@ -86,8 +86,8 @@ def test_service_cannot_be_turned_on_when_server_is_off(populated_node): assert app.operating_state is ApplicationOperatingState.CLOSED -def test_server_turns_on_service(populated_node): - """Check that turning on the server turns on service.""" +def test_computer_runs_applications(populated_node): + """Check that turning on the computer will turn on applications.""" app, computer = populated_node assert computer.operating_state is NodeOperatingState.ON @@ -109,13 +109,14 @@ def test_server_turns_on_service(populated_node): assert computer.operating_state is NodeOperatingState.ON assert app.operating_state is ApplicationOperatingState.RUNNING - computer.start_up_duration = 0 - computer.shut_down_duration = 0 - computer.power_off() + for i in range(computer.start_up_duration + 1): + computer.apply_timestep(timestep=i) assert computer.operating_state is NodeOperatingState.OFF assert app.operating_state is ApplicationOperatingState.CLOSED computer.power_on() + for i in range(computer.start_up_duration + 1): + computer.apply_timestep(timestep=i) assert computer.operating_state is NodeOperatingState.ON assert app.operating_state is ApplicationOperatingState.RUNNING diff --git a/tests/integration_tests/system/test_service_on_node.py b/tests/integration_tests/system/test_service_on_node.py index aab1e4da..9b0084bd 100644 --- a/tests/integration_tests/system/test_service_on_node.py +++ b/tests/integration_tests/system/test_service_on_node.py @@ -117,13 +117,14 @@ def test_server_turns_on_service(populated_node): assert server.operating_state is NodeOperatingState.ON assert service.operating_state is ServiceOperatingState.RUNNING - server.start_up_duration = 0 - server.shut_down_duration = 0 - server.power_off() + for i in range(server.start_up_duration + 1): + server.apply_timestep(timestep=i) assert server.operating_state is NodeOperatingState.OFF assert service.operating_state is ServiceOperatingState.STOPPED server.power_on() + for i in range(server.start_up_duration + 1): + server.apply_timestep(timestep=i) assert server.operating_state is NodeOperatingState.ON assert service.operating_state is ServiceOperatingState.RUNNING diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_application_actions.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_application_actions.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_applications.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_applications.py new file mode 100644 index 00000000..6247a100 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_applications.py @@ -0,0 +1,50 @@ +from primaite.simulator.system.applications.application import ApplicationOperatingState +from primaite.simulator.system.software import SoftwareHealthState + + +def test_scan(application): + assert application.operating_state == ApplicationOperatingState.CLOSED + assert application.health_state_visible == SoftwareHealthState.UNUSED + + application.run() + assert application.operating_state == ApplicationOperatingState.RUNNING + assert application.health_state_visible == SoftwareHealthState.UNUSED + + application.scan() + assert application.operating_state == ApplicationOperatingState.RUNNING + assert application.health_state_visible == SoftwareHealthState.GOOD + + +def test_run_application(application): + assert application.operating_state == ApplicationOperatingState.CLOSED + assert application.health_state_actual == SoftwareHealthState.UNUSED + + application.run() + assert application.operating_state == ApplicationOperatingState.RUNNING + assert application.health_state_actual == SoftwareHealthState.GOOD + + +def test_close_application(application): + application.run() + assert application.operating_state == ApplicationOperatingState.RUNNING + assert application.health_state_actual == SoftwareHealthState.GOOD + + application.close() + assert application.operating_state == ApplicationOperatingState.CLOSED + assert application.health_state_actual == SoftwareHealthState.GOOD + + +def test_application_describe_states(application): + assert application.operating_state == ApplicationOperatingState.CLOSED + assert application.health_state_actual == SoftwareHealthState.UNUSED + + assert SoftwareHealthState.UNUSED.value == application.describe_state().get("health_state_actual") + + application.run() + assert SoftwareHealthState.GOOD.value == application.describe_state().get("health_state_actual") + + application.set_health_state(SoftwareHealthState.COMPROMISED) + assert SoftwareHealthState.COMPROMISED.value == application.describe_state().get("health_state_actual") + + application.patch() + assert SoftwareHealthState.PATCHING.value == application.describe_state().get("health_state_actual") From 66a42ebc6962fde7ebef8166e577716d78a3c392 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 10 Jan 2024 13:06:48 +0000 Subject: [PATCH 520/980] Make database failure based on file status not service status --- .../system/applications/application.py | 2 ++ .../services/database/database_service.py | 20 +++++++++---------- .../system/services/ftp/ftp_service.py | 3 +++ .../_system/_services/test_ftp_client.py | 2 ++ .../_system/_services/test_ftp_server.py | 2 ++ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 898e5917..0ae13228 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -95,6 +95,8 @@ class Application(IOSoftware): if self.operating_state == ApplicationOperatingState.CLOSED: self.sys_log.info(f"Running Application {self.name}") self.operating_state = ApplicationOperatingState.RUNNING + if self.health_state_actual == SoftwareHealthState.UNUSED: + self.health_state_actual = SoftwareHealthState.GOOD def _application_loop(self): """The main application loop.""" diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 61cf1560..89329a17 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -4,6 +4,7 @@ from typing import Any, Dict, List, Literal, Optional, Union from primaite import getLogger from primaite.simulator.file_system.file_system import File +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.software_manager import SoftwareManager @@ -24,7 +25,7 @@ class DatabaseService(Service): password: Optional[str] = None connections: Dict[str, datetime] = {} - backup_server: IPv4Address = None + backup_server_ip: IPv4Address = None """IP address of the backup server.""" latest_backup_directory: str = None @@ -66,7 +67,7 @@ class DatabaseService(Service): :param: backup_server_ip: The IP address of the backup server """ - self.backup_server = backup_server + self.backup_server_ip = backup_server def backup_database(self) -> bool: """Create a backup of the database to the configured backup server.""" @@ -75,7 +76,7 @@ class DatabaseService(Service): return False # check if the backup server was configured - if self.backup_server is None: + if self.backup_server_ip is None: self.sys_log.error(f"{self.name} - {self.sys_log.hostname}: not configured.") return False @@ -84,7 +85,7 @@ class DatabaseService(Service): # send backup copy of database file to FTP server response = ftp_client_service.send_file( - dest_ip_address=self.backup_server, + dest_ip_address=self.backup_server_ip, src_file_name=self._db_file.name, src_folder_name=self.folder.name, dest_folder_name=str(self.uuid), @@ -112,7 +113,7 @@ class DatabaseService(Service): src_file_name="database.db", dest_folder_name="downloads", dest_file_name="database.db", - dest_ip_address=self.backup_server, + dest_ip_address=self.backup_server_ip, ) if not response: @@ -170,16 +171,13 @@ class DatabaseService(Service): """ self.sys_log.info(f"{self.name}: Running {query}") if query == "SELECT": - if self.health_state_actual == SoftwareHealthState.GOOD: + if self._db_file.health_status == FileSystemItemHealthStatus.GOOD: return {"status_code": 200, "type": "sql", "data": True, "uuid": query_id} else: return {"status_code": 404, "data": False} elif query == "DELETE": - if self.health_state_actual == SoftwareHealthState.GOOD: - self.health_state_actual = SoftwareHealthState.COMPROMISED - return {"status_code": 200, "type": "sql", "data": False, "uuid": query_id} - else: - return {"status_code": 404, "data": False} + self._db_file.health_status = FileSystemItemHealthStatus.COMPROMISED + return {"status_code": 200, "type": "sql", "data": False, "uuid": query_id} else: # Invalid query return {"status_code": 500, "data": False} diff --git a/src/primaite/simulator/system/services/ftp/ftp_service.py b/src/primaite/simulator/system/services/ftp/ftp_service.py index f2c01544..8d9bb6fb 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_service.py +++ b/src/primaite/simulator/system/services/ftp/ftp_service.py @@ -52,10 +52,12 @@ class FTPServiceABC(Service, ABC): folder_name = payload.ftp_command_args["dest_folder_name"] file_size = payload.ftp_command_args["file_size"] real_file_path = payload.ftp_command_args.get("real_file_path") + health_status = payload.ftp_command_args["health_status"] is_real = real_file_path is not None file = self.file_system.create_file( file_name=file_name, folder_name=folder_name, size=file_size, real=is_real ) + file.health_status = health_status self.sys_log.info( f"{self.name}: Created item in {self.sys_log.hostname}: {payload.ftp_command_args['dest_folder_name']}/" f"{payload.ftp_command_args['dest_file_name']}" @@ -110,6 +112,7 @@ class FTPServiceABC(Service, ABC): "dest_file_name": dest_file_name, "file_size": file.sim_size, "real_file_path": file.sim_path if file.real else None, + "health_status": file.health_status, }, packet_payload_size=file.sim_size, status_code=FTPStatusCode.OK if is_response else None, diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py index 134f82bd..941a465e 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py @@ -2,6 +2,7 @@ from ipaddress import IPv4Address import pytest +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer @@ -42,6 +43,7 @@ def test_ftp_client_store_file(ftp_client): "dest_folder_name": "downloads", "dest_file_name": "file.txt", "file_size": 24, + "health_status": FileSystemItemHealthStatus.GOOD, }, packet_payload_size=24, status_code=FTPStatusCode.OK, diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py index 2b26c932..137e74d0 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py @@ -1,5 +1,6 @@ import pytest +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.server import Server @@ -41,6 +42,7 @@ def test_ftp_server_store_file(ftp_server): "dest_folder_name": "downloads", "dest_file_name": "file.txt", "file_size": 24, + "health_status": FileSystemItemHealthStatus.GOOD, }, packet_payload_size=24, ) From 1505d087214e724bbcc5661328f79931eb98a1b4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 10 Jan 2024 18:04:48 +0000 Subject: [PATCH 521/980] Fix backup issues and align with Yak --- .../config/_package_data/example_config.yaml | 4 +- src/primaite/game/agent/observations.py | 2 +- src/primaite/session/environment.py | 1 - .../services/database/database_service.py | 44 +++++++++++++------ .../system/services/ftp/ftp_server.py | 3 +- .../red_services/data_manipulation_bot.py | 2 +- .../system/services/web_server/web_server.py | 4 ++ 7 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 2ac23661..ee0eb7ff 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -112,10 +112,8 @@ agents: - service_ref: domain_controller_dns_server - node_ref: web_server services: - - service_ref: web_server_database_client + - service_ref: web_server_web_service - node_ref: database_server - services: - - service_ref: database_service folders: - folder_name: database files: diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index eecf4163..0cb3e8f6 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -555,7 +555,7 @@ class NodeObservation(AbstractObservation): folder_configs = config.get("folders", {}) folders = [ FolderObservation.from_config( - config=c, game=game, parent_where=where, num_files_per_folder=num_files_per_folder + config=c, game=game, parent_where=where + ["file_system"], num_files_per_folder=num_files_per_folder ) for c in folder_configs ] diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 36ab3f58..6701f183 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -23,7 +23,6 @@ class PrimaiteGymEnv(gymnasium.Env): super().__init__() self.game: "PrimaiteGame" = game self.agent: ProxyAgent = self.game.rl_agents[0] - self.flatten_obs: bool = False def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: """Perform a step in the environment.""" diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 89329a17..7c665b9a 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -5,6 +5,7 @@ from typing import Any, Dict, List, Literal, Optional, Union from primaite import getLogger from primaite.simulator.file_system.file_system import File from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus +from primaite.simulator.file_system.folder import Folder from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.software_manager import SoftwareManager @@ -39,7 +40,6 @@ class DatabaseService(Service): kwargs["port"] = Port.POSTGRES_SERVER kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) - self._db_file: File self._create_db_file() def set_original_state(self): @@ -49,7 +49,7 @@ class DatabaseService(Service): vals_to_include = { "password", "connections", - "backup_server", + "backup_server_ip", "latest_backup_directory", "latest_backup_file_name", } @@ -86,8 +86,8 @@ class DatabaseService(Service): # send backup copy of database file to FTP server response = ftp_client_service.send_file( dest_ip_address=self.backup_server_ip, - src_file_name=self._db_file.name, - src_folder_name=self.folder.name, + src_file_name=self.db_file.name, + src_folder_name="database", dest_folder_name=str(self.uuid), dest_file_name="database.db", ) @@ -121,13 +121,10 @@ class DatabaseService(Service): return False # replace db file - self.file_system.delete_file(folder_name=self.folder.name, file_name="downloads.db") - self.file_system.copy_file( - src_folder_name="downloads", src_file_name="database.db", dst_folder_name=self.folder.name - ) - self._db_file = self.file_system.get_file(folder_name=self.folder.name, file_name="database.db") + self.file_system.delete_file(folder_name="database", file_name="downloads.db") + self.file_system.copy_file(src_folder_name="downloads", src_file_name="database.db", dst_folder_name="database") - if self._db_file is None: + if self.db_file is None: self.sys_log.error("Copying database backup failed.") return False @@ -137,8 +134,17 @@ class DatabaseService(Service): def _create_db_file(self): """Creates the Simulation File and sqlite file in the file system.""" - self._db_file: File = self.file_system.create_file(folder_name="database", file_name="database.db") - self.folder = self.file_system.get_folder_by_id(self._db_file.folder_id) + self.file_system.create_file(folder_name="database", file_name="database.db") + + @property + def db_file(self) -> File: + """Returns the database file.""" + return self.file_system.get_file(folder_name="database", file_name="database.db") + + @property + def folder(self) -> Folder: + """Returns the database folder.""" + return self.file_system.get_folder_by_id(self.db_file.folder_id) def _process_connect( self, session_id: str, password: Optional[str] = None @@ -171,12 +177,12 @@ class DatabaseService(Service): """ self.sys_log.info(f"{self.name}: Running {query}") if query == "SELECT": - if self._db_file.health_status == FileSystemItemHealthStatus.GOOD: + if self.db_file.health_status == FileSystemItemHealthStatus.GOOD: return {"status_code": 200, "type": "sql", "data": True, "uuid": query_id} else: return {"status_code": 404, "data": False} elif query == "DELETE": - self._db_file.health_status = FileSystemItemHealthStatus.COMPROMISED + self.db_file.health_status = FileSystemItemHealthStatus.COMPROMISED return {"status_code": 200, "type": "sql", "data": False, "uuid": query_id} else: # Invalid query @@ -231,3 +237,13 @@ class DatabaseService(Service): software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id) return payload["status_code"] == 200 + + def apply_timestep(self, timestep: int) -> None: + """ + Apply a single timestep of simulation dynamics to this service. + + Here at the first step, the database backup is created, in addition to normal service update logic. + """ + if timestep == 1: + self.backup_database() + return super().apply_timestep(timestep) diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 0278b616..87f38597 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -106,5 +106,6 @@ class FTPServer(FTPServiceABC): if payload.status_code is not None: return False - self.send(self._process_ftp_command(payload=payload, session_id=session_id), session_id) + # self.send(self._process_ftp_command(payload=payload, session_id=session_id), session_id) + self._process_ftp_command(payload=payload, session_id=session_id) return True diff --git a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py index fcd9a3cc..48a05a67 100644 --- a/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py +++ b/src/primaite/simulator/system/services/red_services/data_manipulation_bot.py @@ -84,7 +84,7 @@ class DataManipulationBot(DatabaseClient): payload: Optional[str] = None, port_scan_p_of_success: float = 0.1, data_manipulation_p_of_success: float = 0.1, - repeat: bool = False, + repeat: bool = True, ): """ Configure the DataManipulatorBot to communicate with a DatabaseService. diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index afd6cb74..eaea6bb1 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -13,6 +13,7 @@ from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.service import Service +from primaite.simulator.system.software import SoftwareHealthState _LOGGER = getLogger(__name__) @@ -123,7 +124,10 @@ class WebServer(Service): # get all users if db_client.query("SELECT"): # query succeeded + self.set_health_state(SoftwareHealthState.GOOD) response.status_code = HttpStatusCode.OK + else: + self.set_health_state(SoftwareHealthState.COMPROMISED) return response except Exception: From 2d1041e7b3331c4349a8e906fc715e32899f365a Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 10 Jan 2024 18:38:37 +0000 Subject: [PATCH 522/980] Fix final bugs --- src/primaite/game/agent/observations.py | 11 +++++++---- src/primaite/simulator/network/hardware/base.py | 2 +- .../test_uc2_data_manipulation_scenario.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 0cb3e8f6..e5216e4a 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -205,12 +205,15 @@ class LinkObservation(AbstractObservation): bandwidth = link_state["bandwidth"] load = link_state["current_load"] - utilisation_fraction = load / bandwidth - # 0 is UNUSED, 1 is 0%-10%. 2 is 10%-20%. 3 is 20%-30%. And so on... 10 is exactly 100% - utilisation_category = int(utilisation_fraction * 10) + 1 + if load == 0: + utilisation_category = 0 + else: + utilisation_fraction = load / bandwidth + # 0 is UNUSED, 1 is 0%-10%. 2 is 10%-20%. 3 is 20%-30%. And so on... 10 is exactly 100% + utilisation_category = int(utilisation_fraction * 9) + 1 # TODO: once the links support separte load per protocol, this needs amendment to reflect that. - return {"PROTOCOLS": {"ALL": utilisation_category}} + return {"PROTOCOLS": {"ALL": min(utilisation_category, 10)}} @property def space(self) -> spaces.Space: diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index a310a3f5..f41c1ab6 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1271,8 +1271,8 @@ class Node(SimComponent): self.start_up_countdown = self.start_up_duration if self.start_up_duration <= 0: - self._start_up_actions() self.operating_state = NodeOperatingState.ON + self._start_up_actions() self.sys_log.info("Turned on") for nic in self.nics.values(): if nic._connected_link: diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index 0dc2c031..dad6f879 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -22,7 +22,7 @@ def test_data_manipulation(uc2_network): assert db_client.query("SELECT") # Now we run the DataManipulationBot - db_manipulation_bot.run() + db_manipulation_bot.attack() # Now check that the DB client on the web_server cannot query the users table on the database assert not db_client.query("SELECT") From e57c240b9b1d5fa1fff2e52482e9d3895c97f47d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 11 Jan 2024 09:55:09 +0000 Subject: [PATCH 523/980] Apply cosmetic changes based on review. --- src/primaite/simulator/system/applications/application.py | 2 +- src/primaite/simulator/system/services/ftp/ftp_server.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 0ae13228..e15b9f1c 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -96,7 +96,7 @@ class Application(IOSoftware): self.sys_log.info(f"Running Application {self.name}") self.operating_state = ApplicationOperatingState.RUNNING if self.health_state_actual == SoftwareHealthState.UNUSED: - self.health_state_actual = SoftwareHealthState.GOOD + self.set_health_state(SoftwareHealthState.GOOD) def _application_loop(self): """The main application loop.""" diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 87f38597..f176f58b 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -106,6 +106,5 @@ class FTPServer(FTPServiceABC): if payload.status_code is not None: return False - # self.send(self._process_ftp_command(payload=payload, session_id=session_id), session_id) self._process_ftp_command(payload=payload, session_id=session_id) return True From d2a2472e5f08f14eaa20e8ff5e24d0a83be2fde6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 11 Jan 2024 10:49:32 +0000 Subject: [PATCH 524/980] Apply bugfix 2151 --- .../system/applications/application.py | 4 +--- .../system/services/ftp/ftp_service.py | 6 ++++- .../simulator/system/services/service.py | 16 ++++--------- src/primaite/simulator/system/software.py | 6 ++--- tests/conftest.py | 5 +++- .../system/test_application_on_node.py | 23 ++++++++++--------- .../system/test_service_on_node.py | 7 +++--- .../_system/_services/test_web_server.py | 7 +++++- 8 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index e15b9f1c..322ac808 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -38,9 +38,6 @@ class Application(IOSoftware): def __init__(self, **kwargs): super().__init__(**kwargs) - self.health_state_visible = SoftwareHealthState.UNUSED - self.health_state_actual = SoftwareHealthState.UNUSED - def set_original_state(self): """Sets the original state.""" super().set_original_state() @@ -95,6 +92,7 @@ class Application(IOSoftware): if self.operating_state == ApplicationOperatingState.CLOSED: self.sys_log.info(f"Running Application {self.name}") self.operating_state = ApplicationOperatingState.RUNNING + # set software health state to GOOD if initially set to UNUSED if self.health_state_actual == SoftwareHealthState.UNUSED: self.set_health_state(SoftwareHealthState.GOOD) diff --git a/src/primaite/simulator/system/services/ftp/ftp_service.py b/src/primaite/simulator/system/services/ftp/ftp_service.py index 8d9bb6fb..70ba74d7 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_service.py +++ b/src/primaite/simulator/system/services/ftp/ftp_service.py @@ -1,7 +1,7 @@ import shutil from abc import ABC from ipaddress import IPv4Address -from typing import Optional +from typing import Dict, Optional from primaite.simulator.file_system.file_system import File from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode @@ -16,6 +16,10 @@ class FTPServiceABC(Service, ABC): Contains shared methods between both classes. """ + def describe_state(self) -> Dict: + """Returns a Dict of the FTPService state.""" + return super().describe_state() + def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: """ Process the command in the FTP Packet. diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index e60b7700..f10d8776 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -1,3 +1,4 @@ +from abc import abstractmethod from enum import Enum from typing import Any, Dict, Optional @@ -77,9 +78,6 @@ class Service(IOSoftware): def __init__(self, **kwargs): super().__init__(**kwargs) - self.health_state_visible = SoftwareHealthState.UNUSED - self.health_state_actual = SoftwareHealthState.UNUSED - def set_original_state(self): """Sets the original state.""" super().set_original_state() @@ -98,6 +96,7 @@ class Service(IOSoftware): rm.add_request("enable", RequestType(func=lambda request, context: self.enable())) return rm + @abstractmethod def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -118,7 +117,6 @@ class Service(IOSoftware): if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.sys_log.info(f"Stopping service {self.name}") self.operating_state = ServiceOperatingState.STOPPED - self.health_state_actual = SoftwareHealthState.UNUSED def start(self, **kwargs) -> None: """Start the service.""" @@ -129,42 +127,39 @@ class Service(IOSoftware): if self.operating_state == ServiceOperatingState.STOPPED: self.sys_log.info(f"Starting service {self.name}") self.operating_state = ServiceOperatingState.RUNNING - self.health_state_actual = SoftwareHealthState.GOOD + # set software health state to GOOD if initially set to UNUSED + if self.health_state_actual == SoftwareHealthState.UNUSED: + self.set_health_state(SoftwareHealthState.GOOD) def pause(self) -> None: """Pause the service.""" if self.operating_state == ServiceOperatingState.RUNNING: self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.PAUSED - self.health_state_actual = SoftwareHealthState.OVERWHELMED def resume(self) -> None: """Resume paused service.""" if self.operating_state == ServiceOperatingState.PAUSED: self.sys_log.info(f"Resuming service {self.name}") self.operating_state = ServiceOperatingState.RUNNING - self.health_state_actual = SoftwareHealthState.GOOD def restart(self) -> None: """Restart running service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.RESTARTING - self.health_state_actual = SoftwareHealthState.OVERWHELMED self.restart_countdown = self.restart_duration def disable(self) -> None: """Disable the service.""" self.sys_log.info(f"Disabling Application {self.name}") self.operating_state = ServiceOperatingState.DISABLED - self.health_state_actual = SoftwareHealthState.OVERWHELMED def enable(self) -> None: """Enable the disabled service.""" if self.operating_state == ServiceOperatingState.DISABLED: self.sys_log.info(f"Enabling Application {self.name}") self.operating_state = ServiceOperatingState.STOPPED - self.health_state_actual = SoftwareHealthState.OVERWHELMED def apply_timestep(self, timestep: int) -> None: """ @@ -181,5 +176,4 @@ class Service(IOSoftware): if self.restart_countdown <= 0: _LOGGER.debug(f"Restarting finished for service {self.name}") self.operating_state = ServiceOperatingState.RUNNING - self.health_state_actual = SoftwareHealthState.GOOD self.restart_countdown -= 1 diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 7be270c0..a58e4c48 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -69,9 +69,9 @@ class Software(SimComponent): name: str "The name of the software." - health_state_actual: SoftwareHealthState = SoftwareHealthState.GOOD + health_state_actual: SoftwareHealthState = SoftwareHealthState.UNUSED "The actual health state of the software." - health_state_visible: SoftwareHealthState = SoftwareHealthState.GOOD + health_state_visible: SoftwareHealthState = SoftwareHealthState.UNUSED "The health state of the software visible to the red agent." criticality: SoftwareCriticality = SoftwareCriticality.LOWEST "The criticality level of the software." @@ -278,7 +278,7 @@ class IOSoftware(Software): Returns true if the software can perform actions. """ - if self.software_manager and self.software_manager.node.operating_state is not NodeOperatingState.ON: + if self.software_manager and self.software_manager.node.operating_state != NodeOperatingState.ON: _LOGGER.debug(f"{self.name} Error: {self.software_manager.node.hostname} is not online.") return False return True diff --git a/tests/conftest.py b/tests/conftest.py index 1ab07dd8..1400f93b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -40,6 +40,9 @@ from primaite.simulator.network.hardware.base import Link, Node class TestService(Service): """Test Service class""" + def describe_state(self) -> Dict: + return super().describe_state() + def __init__(self, **kwargs): kwargs["name"] = "TestService" kwargs["port"] = Port.HTTP @@ -60,7 +63,7 @@ class TestApplication(Application): super().__init__(**kwargs) def describe_state(self) -> Dict: - pass + return super().describe_state() @pytest.fixture(scope="function") diff --git a/tests/integration_tests/system/test_application_on_node.py b/tests/integration_tests/system/test_application_on_node.py index 46be5e55..3c9afe43 100644 --- a/tests/integration_tests/system/test_application_on_node.py +++ b/tests/integration_tests/system/test_application_on_node.py @@ -24,8 +24,8 @@ def populated_node(application_class) -> Tuple[Application, Computer]: return app, computer -def test_service_on_offline_node(application_class): - """Test to check that the service cannot be interacted with when node it is on is off.""" +def test_application_on_offline_node(application_class): + """Test to check that the application cannot be interacted with when node it is on is off.""" computer: Computer = Computer( hostname="test_computer", ip_address="192.168.1.2", @@ -49,8 +49,8 @@ def test_service_on_offline_node(application_class): assert app.operating_state is ApplicationOperatingState.CLOSED -def test_server_turns_off_service(populated_node): - """Check that the service is turned off when the server is turned off""" +def test_server_turns_off_application(populated_node): + """Check that the application is turned off when the server is turned off""" app, computer = populated_node assert computer.operating_state is NodeOperatingState.ON @@ -65,8 +65,8 @@ def test_server_turns_off_service(populated_node): assert app.operating_state is ApplicationOperatingState.CLOSED -def test_service_cannot_be_turned_on_when_server_is_off(populated_node): - """Check that the service cannot be started when the server is off.""" +def test_application_cannot_be_turned_on_when_server_is_off(populated_node): + """Check that the application cannot be started when the server is off.""" app, computer = populated_node assert computer.operating_state is NodeOperatingState.ON @@ -86,8 +86,8 @@ def test_service_cannot_be_turned_on_when_server_is_off(populated_node): assert app.operating_state is ApplicationOperatingState.CLOSED -def test_server_turns_on_service(populated_node): - """Check that turning on the server turns on service.""" +def test_server_turns_on_application(populated_node): + """Check that turning on the server turns on application.""" app, computer = populated_node assert computer.operating_state is NodeOperatingState.ON @@ -109,13 +109,14 @@ def test_server_turns_on_service(populated_node): assert computer.operating_state is NodeOperatingState.ON assert app.operating_state is ApplicationOperatingState.RUNNING - computer.start_up_duration = 0 - computer.shut_down_duration = 0 - computer.power_off() + for i in range(computer.start_up_duration + 1): + computer.apply_timestep(timestep=i) assert computer.operating_state is NodeOperatingState.OFF assert app.operating_state is ApplicationOperatingState.CLOSED computer.power_on() + for i in range(computer.start_up_duration + 1): + computer.apply_timestep(timestep=i) assert computer.operating_state is NodeOperatingState.ON assert app.operating_state is ApplicationOperatingState.RUNNING diff --git a/tests/integration_tests/system/test_service_on_node.py b/tests/integration_tests/system/test_service_on_node.py index aab1e4da..9b0084bd 100644 --- a/tests/integration_tests/system/test_service_on_node.py +++ b/tests/integration_tests/system/test_service_on_node.py @@ -117,13 +117,14 @@ def test_server_turns_on_service(populated_node): assert server.operating_state is NodeOperatingState.ON assert service.operating_state is ServiceOperatingState.RUNNING - server.start_up_duration = 0 - server.shut_down_duration = 0 - server.power_off() + for i in range(server.start_up_duration + 1): + server.apply_timestep(timestep=i) assert server.operating_state is NodeOperatingState.OFF assert service.operating_state is ServiceOperatingState.STOPPED server.power_on() + for i in range(server.start_up_duration + 1): + server.apply_timestep(timestep=i) assert server.operating_state is NodeOperatingState.ON assert service.operating_state is ServiceOperatingState.RUNNING diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py index bbccda27..64277356 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py @@ -1,5 +1,6 @@ import pytest +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.protocols.http import ( HttpRequestMethod, @@ -15,7 +16,11 @@ from primaite.simulator.system.services.web_server.web_server import WebServer @pytest.fixture(scope="function") def web_server() -> Server: node = Server( - hostname="web_server", ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1" + hostname="web_server", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + operating_state=NodeOperatingState.ON, ) node.software_manager.install(software_class=WebServer) node.software_manager.software.get("WebServer").start() From b11e4c8ccd06f7638f243f8a2fb506ce4792f6d8 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 11 Jan 2024 11:05:00 +0000 Subject: [PATCH 525/980] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a0ef4c7..1c67d16c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Made packet capture and system logging optional (off by default). To turn on, change the io_settings.save_pcap_logs and io_settings.save_sys_logs settings in the config. - Made observation space flattening optional (on by default). To turn off for an agent, change the agent_settings.flatten_obs setting in the config. - Fixed an issue where the data manipulation attack was triggered at episode start. +- Fixed a bug where FTP STOR stored an additional copy on the client machine's filesystem + ### Added - Network Hardware - Added base hardware module with NIC, SwitchPort, Node, and Link. Nodes have From 4d1c0d268e0b5619851fda92baf6b94f1f0c17a8 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 11 Jan 2024 11:05:55 +0000 Subject: [PATCH 526/980] Fix reward data type --- src/primaite/game/agent/rewards.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index cb8f8cb1..30baad6f 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -111,9 +111,9 @@ class DatabaseFileIntegrity(AbstractReward): """ database_file_state = access_from_nested_dict(state, self.location_in_state) health_status = database_file_state["health_status"] - if health_status == "corrupted": + if health_status == 3: return -1 - elif health_status == "good": + elif health_status == 1: return 1 else: return 0 From 63b9bc5bc69a8f125f7d1ecad6378de56a833003 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 11 Jan 2024 11:13:43 +0000 Subject: [PATCH 527/980] 3.0.0b5 --- CHANGELOG.md | 4 ++++ src/primaite/VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c67d16c..227cec69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Made observation space flattening optional (on by default). To turn off for an agent, change the agent_settings.flatten_obs setting in the config. - Fixed an issue where the data manipulation attack was triggered at episode start. - Fixed a bug where FTP STOR stored an additional copy on the client machine's filesystem +- Fixed a bug where the red agent acted to early +- Fixed the order of service health state +- Fixed an issue where starting a node didn't start the services on it + ### Added diff --git a/src/primaite/VERSION b/src/primaite/VERSION index 52f460a5..09fb39d2 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0b5dev +3.0.0b5 From ed5591caf8cf11a3727e27028f670dc915687a4c Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 11 Jan 2024 14:49:36 +0000 Subject: [PATCH 528/980] Minor fix --- src/primaite/game/agent/observations.py | 2 +- src/primaite/game/agent/rewards.py | 2 +- src/primaite/simulator/file_system/folder.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index e5216e4a..cac5b91e 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -79,7 +79,7 @@ class FileObservation(AbstractObservation): file_state = access_from_nested_dict(state, self.where) if file_state is NOT_PRESENT_IN_STATE: return self.default_observation - return {"health_status": file_state["health_status"]} + return {"health_status": file_state["visible_status"]} @property def space(self) -> spaces.Space: diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 30baad6f..8f064be3 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -111,7 +111,7 @@ class DatabaseFileIntegrity(AbstractReward): """ database_file_state = access_from_nested_dict(state, self.location_in_state) health_status = database_file_state["health_status"] - if health_status == 3: + if health_status == 2: return -1 elif health_status == 1: return 1 diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index d4e72f63..237a6341 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -105,7 +105,7 @@ class Folder(FileSystemItemABC): self._file_request_manager = RequestManager() rm.add_request( name="file", - request_type=RequestType(func=lambda request, context: self._file_request_manager), + request_type=RequestType(func=self._file_request_manager), ) return rm From 842e59f5964612213787e21a459368e136276cf3 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 11 Jan 2024 15:40:37 +0000 Subject: [PATCH 529/980] Database patch --- .../simulator/system/services/database/database_service.py | 5 +++++ src/primaite/simulator/system/software.py | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 7c665b9a..1cdd0390 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -247,3 +247,8 @@ class DatabaseService(Service): if timestep == 1: self.backup_database() return super().apply_timestep(timestep) + + def _update_patch_status(self) -> None: + super()._update_patch_status() + if self._patching_countdown is None: + self.restore_backup() diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index a58e4c48..b7c0bd9b 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -193,8 +193,9 @@ class Software(SimComponent): def patch(self) -> None: """Perform a patch on the software.""" - self._patching_countdown = self.patching_duration - self.set_health_state(SoftwareHealthState.PATCHING) + if self.health_state_actual in (SoftwareHealthState.COMPROMISED, SoftwareHealthState.GOOD): + self._patching_countdown = self.patching_duration + self.set_health_state(SoftwareHealthState.PATCHING) def _update_patch_status(self) -> None: """Update the patch status of the software.""" From e0033de7b671eeaea3d56ab4e0b4898ad85f592c Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 12 Jan 2024 14:54:55 +0000 Subject: [PATCH 530/980] Fix folder reset --- src/primaite/simulator/file_system/folder.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 237a6341..027547bb 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -17,8 +17,6 @@ class Folder(FileSystemItemABC): files: Dict[str, File] = {} "Files stored in the folder." - _files_by_name: Dict[str, File] = {} - "Files by their name as .." deleted_files: Dict[str, File] = {} "Files that have been deleted." @@ -78,7 +76,6 @@ class Folder(FileSystemItemABC): file = self.deleted_files[uuid] self.deleted_files.pop(uuid) self.files[uuid] = file - self._files_by_name[file.name] = file # Clear any other deleted files that aren't original (have been created by agent) self.deleted_files.clear() @@ -89,7 +86,6 @@ class Folder(FileSystemItemABC): if uuid not in original_file_uuids: file = self.files[uuid] self.files.pop(uuid) - self._files_by_name.pop(file.name) # Now reset all remaining files for file in self.files.values(): @@ -219,7 +215,10 @@ class Folder(FileSystemItemABC): :return: The matching File. """ # TODO: Increment read count? - return self._files_by_name.get(file_name) + for file in self.files.values(): + if file.name == file_name: + return file + return None def get_file_by_id(self, file_uuid: str, include_deleted: Optional[bool] = False) -> File: """ @@ -250,15 +249,14 @@ class Folder(FileSystemItemABC): raise Exception(f"Invalid file: {file}") # check if file with id or name already exists in folder - if (force is not True) and file.name in self._files_by_name: + if self.get_file(file.name) is not None and not force: raise Exception(f"File with name {file.name} already exists in folder") - if (force is not True) and file.uuid in self.files: + if (file.uuid in self.files) and not force: raise Exception(f"File with uuid {file.uuid} already exists in folder") # add to list self.files[file.uuid] = file - self._files_by_name[file.name] = file self._file_request_manager.add_request(file.uuid, RequestType(func=file._request_manager)) file.folder = self @@ -275,7 +273,6 @@ class Folder(FileSystemItemABC): if self.files.get(file.uuid): self.files.pop(file.uuid) - self._files_by_name.pop(file.name) self.deleted_files[file.uuid] = file file.delete() self.sys_log.info(f"Removed file {file.name} (id: {file.uuid})") @@ -300,7 +297,6 @@ class Folder(FileSystemItemABC): self.deleted_files[file_id] = file self.files = {} - self._files_by_name = {} def restore_file(self, file_uuid: str): """ @@ -316,7 +312,6 @@ class Folder(FileSystemItemABC): file.restore() self.files[file.uuid] = file - self._files_by_name[file.name] = file if file.deleted: self.deleted_files.pop(file_uuid) From 728f80cc2162b5dc1ce7878921dd90e70ca0d740 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 15 Jan 2024 09:48:14 +0000 Subject: [PATCH 531/980] Temporarily disable file delete action --- src/primaite/game/agent/actions.py | 10 ++++++++++ src/primaite/game/agent/rewards.py | 7 +++++++ src/primaite/simulator/file_system/folder.py | 2 +- .../system/services/database/database_service.py | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 4c47bfaa..585e2dfa 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -296,6 +296,16 @@ class NodeFileDeleteAction(NodeFileAbstractAction): super().__init__(manager, num_nodes=num_nodes, num_folders=num_folders, num_files=num_files, **kwargs) self.verb: str = "delete" + def form_request(self, node_id: int, folder_id: int, file_id: int) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" + node_uuid = self.manager.get_node_uuid_by_idx(node_id) + folder_uuid = self.manager.get_folder_uuid_by_idx(node_idx=node_id, folder_idx=folder_id) + file_uuid = self.manager.get_file_uuid_by_idx(node_idx=node_id, folder_idx=folder_id, file_idx=file_id) + if node_uuid is None or folder_uuid is None or file_uuid is None: + return ["do_nothing"] + return ["do_nothing"] + # return ["network", "node", node_uuid, "file_system", "delete", "file", folder_uuid, file_uuid] + class NodeFileRepairAction(NodeFileAbstractAction): """Action which repairs a file.""" diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 8f064be3..6cee127f 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -110,6 +110,13 @@ class DatabaseFileIntegrity(AbstractReward): :type state: Dict """ database_file_state = access_from_nested_dict(state, self.location_in_state) + if database_file_state is NOT_PRESENT_IN_STATE: + _LOGGER.info( + f"Could not calculate {self.__class__} reward because " + "simulation state did not contain enough information." + ) + return 0.0 + health_status = database_file_state["health_status"] if health_status == 2: return -1 diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 027547bb..ab862898 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -276,7 +276,7 @@ class Folder(FileSystemItemABC): self.deleted_files[file.uuid] = file file.delete() self.sys_log.info(f"Removed file {file.name} (id: {file.uuid})") - self._file_request_manager.remove_request(file.uuid) + # self._file_request_manager.remove_request(file.uuid) else: _LOGGER.debug(f"File with UUID {file.uuid} was not found.") diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 1cdd0390..6fcced25 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -84,6 +84,10 @@ class DatabaseService(Service): ftp_client_service: FTPClient = software_manager.software.get("FTPClient") # send backup copy of database file to FTP server + if not self.db_file: + self.sys_log.error("Attempted to backup database file but it doesn't exist.") + return False + response = ftp_client_service.send_file( dest_ip_address=self.backup_server_ip, src_file_name=self.db_file.name, From edc9772d0a4a452256b10b03dd839496738adda5 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 15 Jan 2024 10:10:30 +0000 Subject: [PATCH 532/980] Fix typo in database restore --- .../simulator/system/services/database/database_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 6fcced25..14190dd2 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -125,7 +125,7 @@ class DatabaseService(Service): return False # replace db file - self.file_system.delete_file(folder_name="database", file_name="downloads.db") + self.file_system.delete_file(folder_name="database", file_name="database.db") self.file_system.copy_file(src_folder_name="downloads", src_file_name="database.db", dst_folder_name="database") if self.db_file is None: From 7d218c520115acb611f9de21a55aaea1a1964987 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 15 Jan 2024 10:31:13 +0000 Subject: [PATCH 533/980] bump version --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index 09fb39d2..72f12ef8 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0b5 +3.0.0b6dev From 42d00e04408ed6a6857cdb67d668478eb027a733 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 21 Jan 2024 16:33:51 +0000 Subject: [PATCH 534/980] Fix issue where file deleted flag wouldn't be reset --- .gitignore | 1 + .../simulator/file_system/file_system.py | 17 +++++++---------- .../file_system/file_system_item_abc.py | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 892751d9..1ce2ca9d 100644 --- a/.gitignore +++ b/.gitignore @@ -156,3 +156,4 @@ benchmark/output # src/primaite/notebooks/scratch.ipynb src/primaite/notebooks/scratch.py sandbox.py +sandbox/ diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index c2eb0d2d..149bf083 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -23,7 +23,6 @@ class FileSystem(SimComponent): "List containing all the folders in the file system." deleted_folders: Dict[str, Folder] = {} "List containing all the folders that have been deleted." - _folders_by_name: Dict[str, Folder] = {} sys_log: SysLog "Instance of SysLog used to create system logs." sim_root: Path @@ -56,7 +55,6 @@ class FileSystem(SimComponent): folder = self.deleted_folders[uuid] self.deleted_folders.pop(uuid) self.folders[uuid] = folder - self._folders_by_name[folder.name] = folder # Clear any other deleted folders that aren't original (have been created by agent) self.deleted_folders.clear() @@ -67,7 +65,6 @@ class FileSystem(SimComponent): if uuid not in original_folder_uuids: folder = self.folders[uuid] self.folders.pop(uuid) - self._folders_by_name.pop(folder.name) # Now reset all remaining folders for folder in self.folders.values(): @@ -173,7 +170,6 @@ class FileSystem(SimComponent): folder = Folder(name=folder_name, sys_log=self.sys_log) self.folders[folder.uuid] = folder - self._folders_by_name[folder.name] = folder self._folder_request_manager.add_request( name=folder.uuid, request_type=RequestType(func=folder._request_manager) ) @@ -188,14 +184,13 @@ class FileSystem(SimComponent): if folder_name == "root": self.sys_log.warning("Cannot delete the root folder.") return - folder = self._folders_by_name.get(folder_name) + folder = self.get_folder(folder_name) if folder: # set folder to deleted state folder.delete() # remove from folder list self.folders.pop(folder.uuid) - self._folders_by_name.pop(folder.name) # add to deleted list folder.remove_all_files() @@ -221,7 +216,10 @@ class FileSystem(SimComponent): :param folder_name: The folder name. :return: The matching Folder. """ - return self._folders_by_name.get(folder_name) + for folder in self.folders.values(): + if folder.name == folder_name: + return folder + return None def get_folder_by_id(self, folder_uuid: str, include_deleted: bool = False) -> Optional[Folder]: """ @@ -261,13 +259,13 @@ class FileSystem(SimComponent): """ if folder_name: # check if file with name already exists - folder = self._folders_by_name.get(folder_name) + folder = self.get_folder(folder_name) # If not then create it if not folder: folder = self.create_folder(folder_name) else: # Use root folder if folder_name not supplied - folder = self._folders_by_name["root"] + folder = self.get_folder("root") # Create the file and add it to the folder file = File( @@ -474,7 +472,6 @@ class FileSystem(SimComponent): folder.restore() self.folders[folder.uuid] = folder - self._folders_by_name[folder.name] = folder if folder.deleted: self.deleted_folders.pop(folder.uuid) diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py index 86cd1ee7..c3e1426b 100644 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -87,7 +87,7 @@ class FileSystemItemABC(SimComponent): def set_original_state(self): """Sets the original state.""" - vals_to_keep = {"name", "health_status", "visible_health_status", "previous_hash", "revealed_to_red"} + vals_to_keep = {"name", "health_status", "visible_health_status", "previous_hash", "revealed_to_red", "deleted"} self._original_state = self.model_dump(include=vals_to_keep) def describe_state(self) -> Dict: From 8e19e05f570b57fee370190eb59384bda6adc77f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 21 Jan 2024 17:29:19 +0000 Subject: [PATCH 535/980] Fix acl actions for blue agent. --- .../config/_package_data/example_config.yaml | 60 ++++++++++++------- src/primaite/game/agent/actions.py | 15 ++++- 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index ee0eb7ff..7393f5a3 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -304,63 +304,63 @@ agents: action: "NODE_RESET" options: node_id: 5 - 22: + 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: position: 1 permission: 2 - source_ip_id: 7 - dest_ip_id: 1 + source_ip_id: 7 # client 1 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: + 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 2 permission: 2 - source_ip_id: 8 - dest_ip_id: 1 + source_ip_id: 8 # client 2 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 24: + 24: # block tcp traffic from client 1 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 3 permission: 2 - source_ip_id: 7 - dest_ip_id: 3 + source_ip_id: 7 # client 1 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 25: + 25: # block tcp traffic from client 2 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 4 permission: 2 - source_ip_id: 8 - dest_ip_id: 3 + source_ip_id: 8 # client 2 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 26: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 5 permission: 2 - source_ip_id: 7 - dest_ip_id: 4 + source_ip_id: 7 # client 1 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 27: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 6 permission: 2 - source_ip_id: 8 - dest_ip_id: 4 + source_ip_id: 8 # client 2 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 @@ -504,6 +504,24 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 + - node_ref: client_1 + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 + reward_function: reward_components: diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 585e2dfa..6b15c5f8 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -470,13 +470,13 @@ class NetworkACLAddRuleAction(AbstractAction): dst_ip = "ALL" return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS else: - dst_ip = self.manager.get_ip_address_by_idx(dest_ip_id) + dst_ip = self.manager.get_ip_address_by_idx(dest_ip_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 if dest_port_id == 1: dst_port = "ALL" else: - dst_port = self.manager.get_port_by_idx(dest_port_id) + dst_port = self.manager.get_port_by_idx(dest_port_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 return [ @@ -924,6 +924,15 @@ class ActionManager: :return: The constructed ActionManager. :rtype: ActionManager """ + ip_address_order = cfg["options"].pop("ip_address_order", {}) + ip_address_list = [] + for entry in ip_address_order: + node_ref = entry["node_ref"] + nic_num = entry["nic_num"] + node_obj = game.simulation.network.get_node_by_hostname(node_ref) + ip_address = node_obj.ethernet_port[nic_num].ip_address + ip_address_list.append(ip_address) + obj = cls( game=game, actions=cfg["action_list"], @@ -931,7 +940,7 @@ class ActionManager: **cfg["options"], protocols=game.options.protocols, ports=game.options.ports, - ip_address_list=None, + ip_address_list=ip_address_list or None, act_map=cfg.get("action_map"), ) From 88c1d16f1150734fa3db6c5c303ea322b25f94a6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 23 Jan 2024 14:34:05 +0000 Subject: [PATCH 536/980] Fix Router acl not clearing --- src/primaite/game/game.py | 30 +------ .../network/hardware/nodes/router.py | 79 ++++++++++++++++++- 2 files changed, 80 insertions(+), 29 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 08098754..159f5bbb 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -13,11 +13,9 @@ from primaite.game.agent.rewards import RewardFunction from primaite.session.io import SessionIO, SessionIOSettings from primaite.simulator.network.hardware.base import NIC, NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.router import Router from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.hardware.nodes.switch import Switch -from primaite.simulator.network.transmission.network_layer import IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.sim_container import Simulation from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.web_browser import WebBrowser @@ -227,31 +225,7 @@ class PrimaiteGame: operating_state=NodeOperatingState.ON, ) elif n_type == "router": - new_node = Router( - hostname=node_cfg["hostname"], - num_ports=node_cfg.get("num_ports"), - operating_state=NodeOperatingState.ON, - ) - if "ports" in node_cfg: - for port_num, port_cfg in node_cfg["ports"].items(): - new_node.configure_port( - port=port_num, ip_address=port_cfg["ip_address"], subnet_mask=port_cfg["subnet_mask"] - ) - # new_node.enable_port(port_num) - if "acl" in node_cfg: - for r_num, r_cfg in node_cfg["acl"].items(): - # excuse the uncommon walrus operator ` := `. It's just here as a shorthand, to avoid repeating - # this: 'r_cfg.get('src_port')' - # Port/IPProtocol. TODO Refactor - new_node.acl.add_rule( - action=ACLAction[r_cfg["action"]], - src_port=None if not (p := r_cfg.get("src_port")) else Port[p], - dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], - protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], - src_ip_address=r_cfg.get("ip_address"), - dst_ip_address=r_cfg.get("ip_address"), - position=r_num, - ) + new_node = Router.from_config(node_cfg) else: _LOGGER.warning(f"invalid node type {n_type} in config") if "services" in node_cfg: diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 0234934d..bb923d62 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -9,6 +9,7 @@ from prettytable import MARKDOWN, PrettyTable from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import ARPCache, ICMP, NIC, Node +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader @@ -89,6 +90,8 @@ class AccessControlList(SimComponent): implicit_rule: ACLRule max_acl_rules: int = 25 _acl: List[Optional[ACLRule]] = [None] * 24 + _default_config: dict[int, dict] = {} + """Config dict describing how the ACL list should look at episode start""" def __init__(self, **kwargs) -> None: if not kwargs.get("implicit_action"): @@ -110,6 +113,21 @@ class AccessControlList(SimComponent): """Reset the original state of the SimComponent.""" self.implicit_rule.reset_component_for_episode(episode) super().reset_component_for_episode(episode) + self._reset_rules_to_default() + + def _reset_rules_to_default(self) -> None: + """Clear all ACL rules and set them to the default rules config.""" + self._acl = [None] * (self.max_acl_rules - 1) + for r_num, r_cfg in self._default_config.items(): + self.add_rule( + action=ACLAction[r_cfg["action"]], + src_port=None if not (p := r_cfg.get("src_port")) else Port[p], + dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], + protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], + src_ip_address=r_cfg.get("ip_address"), + dst_ip_address=r_cfg.get("ip_address"), + position=r_num, + ) def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() @@ -391,7 +409,6 @@ class RouteTable(SimComponent): sys_log: SysLog def set_original_state(self): - """Sets the original state.""" """Sets the original state.""" super().set_original_state() self._original_state["routes_orig"] = self.routes @@ -864,3 +881,63 @@ class Router(Node): ] ) print(table) + + @classmethod + def from_config(cls, cfg: dict) -> "Router": + """Create a router based on a config dict. + + Schema: + - hostname (str): unique name for this router. + - num_ports (int, optional): Number of network ports on the router. 8 by default + - ports (dict): Dict with integers from 1 - num_ports as keys. The values should be another dict specifying + ip_address and subnet_mask assigned to that ports (as strings) + - acl (dict): Dict with integers from 1 - max_acl_rules as keys. The key defines the position within the ACL + where the rule will be added (lower number is resolved first). The values should describe valid ACL + Rules as: + - action (str): either PERMIT or DENY + - src_port (str, optional): the named port such as HTTP, HTTPS, or POSTGRES_SERVER + - dst_port (str, optional): the named port such as HTTP, HTTPS, or POSTGRES_SERVER + - protocol (str, optional): the named IP protocol such as ICMP, TCP, or UDP + - src_ip_address (str, optional): IP address octet written in base 10 + - dst_ip_address (str, optional): IP address octet written in base 10 + + Example config: + ``` + { + 'hostname': 'router_1', + 'num_ports': 5, + 'ports': { + 1: { + 'ip_address' : '192.168.1.1', + 'subnet_mask' : '255.255.255.0', + } + }, + 'acl' : { + 21: {'action': 'PERMIT', 'src_port': 'HTTP', dst_port: 'HTTP'}, + 22: {'action': 'PERMIT', 'src_port': 'ARP', 'dst_port': 'ARP'}, + 23: {'action': 'PERMIT', 'protocol': 'ICMP'}, + }, + } + ``` + + :param cfg: Router config adhering to schema described in main docstring body + :type cfg: dict + :return: Configured router. + :rtype: Router + """ + new = Router( + hostname=cfg["hostname"], + num_ports=cfg.get("num_ports"), + operating_state=NodeOperatingState.ON, + ) + if "ports" in cfg: + for port_num, port_cfg in cfg["ports"].items(): + new.configure_port( + port=port_num, + ip_address=port_cfg["ip_address"], + subnet_mask=port_cfg["subnet_mask"], + ) + if "acl" in cfg: + new.acl._default_config = cfg["acl"] # save the config to allow resetting + new.acl._reset_rules_to_default() # read the config and apply rules + return new From 0a65f32adfa47cd84c640f3ae9c1b0aed0bc1b94 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Jan 2024 09:27:08 +0000 Subject: [PATCH 537/980] Fix ACL observations --- src/primaite/game/agent/observations.py | 35 +++++++++++++------ .../network/hardware/nodes/router.py | 12 +++---- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index cac5b91e..b7962827 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -1,5 +1,6 @@ """Manages the observation space for the agent.""" from abc import ABC, abstractmethod +from ipaddress import IPv4Address from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium import spaces @@ -648,10 +649,13 @@ class AclObservation(AbstractObservation): # TODO: what if the ACL has more rules than num of max rules for obs space obs = {} - for i, rule_state in acl_state.items(): + acl_items = dict(acl_state.items()) + i = 1 # don't show rule 0 for compatibility reasons. + while i < self.num_rules + 1: + rule_state = acl_items[i] if rule_state is None: - obs[i + 1] = { - "position": i, + obs[i] = { + "position": i - 1, "permission": 0, "source_node_id": 0, "source_port": 0, @@ -660,15 +664,26 @@ class AclObservation(AbstractObservation): "protocol": 0, } else: - obs[i + 1] = { - "position": i, + src_ip = rule_state["src_ip_address"] + src_node_id = 1 if src_ip is None else self.node_to_id[IPv4Address(src_ip)] + dst_ip = rule_state["dst_ip_address"] + dst_node_ip = 1 if dst_ip is None else self.node_to_id[IPv4Address(dst_ip)] + src_port = rule_state["src_port"] + src_port_id = 1 if src_port is None else self.port_to_id[src_port] + dst_port = rule_state["dst_port"] + dst_port_id = 1 if dst_port is None else self.port_to_id[dst_port] + protocol = rule_state["protocol"] + protocol_id = 1 if protocol is None else self.protocol_to_id[protocol] + obs[i] = { + "position": i - 1, "permission": rule_state["action"], - "source_node_id": self.node_to_id[rule_state["src_ip_address"]], - "source_port": self.port_to_id[rule_state["src_port"]], - "dest_node_id": self.node_to_id[rule_state["dst_ip_address"]], - "dest_port": self.port_to_id[rule_state["dst_port"]], - "protocol": self.protocol_to_id[rule_state["protocol"]], + "source_node_id": src_node_id, + "source_port": src_port_id, + "dest_node_id": dst_node_ip, + "dest_port": dst_port_id, + "protocol": protocol_id, } + i += 1 return obs @property diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index bb923d62..0c5d0ce9 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -19,8 +19,8 @@ from primaite.simulator.system.core.sys_log import SysLog class ACLAction(Enum): """Enum for defining the ACL action types.""" - DENY = 0 PERMIT = 1 + DENY = 2 class ACLRule(SimComponent): @@ -66,11 +66,11 @@ class ACLRule(SimComponent): """ state = super().describe_state() state["action"] = self.action.value - state["protocol"] = self.protocol.value if self.protocol else None + state["protocol"] = self.protocol.name if self.protocol else None state["src_ip_address"] = str(self.src_ip_address) if self.src_ip_address else None - state["src_port"] = self.src_port.value if self.src_port else None + state["src_port"] = self.src_port.name if self.src_port else None state["dst_ip_address"] = str(self.dst_ip_address) if self.dst_ip_address else None - state["dst_port"] = self.dst_port.value if self.dst_port else None + state["dst_port"] = self.dst_port.name if self.dst_port else None return state @@ -733,8 +733,8 @@ class Router(Node): :return: A dictionary representing the current state. """ state = super().describe_state() - state["num_ports"] = (self.num_ports,) - state["acl"] = (self.acl.describe_state(),) + state["num_ports"] = self.num_ports + state["acl"] = self.acl.describe_state() return state def route_frame(self, frame: Frame, from_nic: NIC, re_attempt: bool = False) -> None: From 28acb5dcaed89364bb920591a8d1bd82f51e6da1 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Jan 2024 12:04:09 +0000 Subject: [PATCH 538/980] Populate step info in environment, and finish notebook --- .../config/_package_data/example_config.yaml | 2 +- .../example_config_2_rl_agents.yaml | 2 +- src/primaite/game/game.py | 5 +- .../notebooks/_package_data/uc2_network.png | Bin 0 -> 70887 bytes src/primaite/notebooks/uc2_demo.ipynb | 1038 +++++++++++++---- src/primaite/session/environment.py | 8 +- .../assets/configs/bad_primaite_session.yaml | 2 +- .../configs/eval_only_primaite_session.yaml | 2 +- tests/assets/configs/multi_agent_session.yaml | 2 +- .../assets/configs/test_primaite_session.yaml | 2 +- .../configs/train_only_primaite_session.yaml | 2 +- 11 files changed, 850 insertions(+), 215 deletions(-) create mode 100644 src/primaite/notebooks/_package_data/uc2_network.png diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 7393f5a3..d8cd0099 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -31,7 +31,7 @@ game: - UDP agents: - - ref: client_1_green_user + - ref: client_2_green_user team: GREEN type: GreenWebBrowsingAgent observation_space: diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index c1e2ea81..6aa54487 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -25,7 +25,7 @@ game: - UDP agents: - - ref: client_1_green_user + - ref: client_2_green_user team: GREEN type: GreenWebBrowsingAgent observation_space: diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 159f5bbb..146261f9 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -113,7 +113,7 @@ class PrimaiteGame: self.update_agents(sim_state) # Apply all actions to simulation as requests - self.apply_agent_actions() + agent_actions = self.apply_agent_actions() # noqa # Advance timestep self.advance_timestep() @@ -131,12 +131,15 @@ class PrimaiteGame: def apply_agent_actions(self) -> None: """Apply all actions to simulation as requests.""" + agent_actions = {} for agent in self.agents: obs = agent.observation_manager.current_observation rew = agent.reward_function.current_reward action_choice, options = agent.get_action(obs, rew) + agent_actions[agent.agent_name] = (action_choice, options) request = agent.format_request(action_choice, options) self.simulation.apply_request(request) + return agent_actions def advance_timestep(self) -> None: """Advance timestep.""" diff --git a/src/primaite/notebooks/_package_data/uc2_network.png b/src/primaite/notebooks/_package_data/uc2_network.png new file mode 100644 index 0000000000000000000000000000000000000000..20fa43c996bb7c3bce61778a7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$@;%4HSRqLQvudIQiDIN(pA#NH-7Ffeu3$hsMxh#9=$W7b21%w zUH`rRg6V&*mlpW|dxjt^?7qU6!QbZY{R<2*n6P{%`H)_>D0#{qM@uf7wE83HZ-RreF7e zMsRu<{vVzY->pRQ*pQ11k^YDOfBT z_`pfuH#$^XmGG_3^|zWj1yrIpQD@mppN7A$j#I+c7R_h#XD zR>eyFK1PYz?2K+*&4L^^dd8I0++$f6PfmC;C@WxK%NY&&1+Ozw3!&~)t4bi-UC777 zYPs9EOaRmLV7QK{Gh8%;wV96-$4il6&UV?-S2s2uFs#JTRZ4ark!aPQxG51W_p1eh z$E(V?LU-1d(E*0=Fyq4-S_gwFjN84En#nut+BHDCKTv+tD~Mw@+xY1YhP~PZwPhKf zyv1aSY3sy5*-ZhV@j#REWixlev|(U=&ZIu&{r4qzw{tj{rOC;E?^z$|{P|^(vHJC0 z1#59L*@F?oCsuFzc>vQBihfp4(VNk|++Gd|=Hb>#foyv>7)^cUc4LR^{2lA)xMn2Y zCROU!ScQsXhf(x0Hy=7](_package_data/uc2_network.png)\n", + "\n", + "_(click image to enlarge)_\n", + "\n", + "The red agent deletes the contents of the database. When this happens, the web app cannot fetch data and users navigating to the website get a 404 error.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Network\n", + "\n", + "- The web server has:\n", + " - a web service that replies to user HTTP requests\n", + " - a database client that fetches data for the web service\n", + "- The database server has:\n", + " - a POSTGRES database service\n", + " - a database file which is accessed by the database service\n", + " - FTP client used for backing up the data to the backup_server\n", + "- The backup server has:\n", + " - a copy of the database file in a known good state\n", + " - FTP server that can send the backed up file back to the database server\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Green agent\n", + "\n", + "The green agent is logged onto client 2. It sometimes uses the web browser on client 2 to navigate to `http://arcd.com/users`. The web server replies with a status code 200 if the data is available on the database or 404 if not available." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Red agent\n", + "\n", + "The red agent waits a bit then sends a DELETE query to the database from client 1. If the delete is successful, the database file is flagged as compromised to signal that data is not available." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Blue agent\n", + "\n", + "The blue agent can view the entire network, but the health statuses of components are not updated until a scan is performed. The blue agent should restore the database file from backup after it was compromised. It can also prevent further attacks by blocking client 1 from reaching the database server. This can be done by removing client 1's network connection or adding ACL rules on the router to stop the packets from arriving." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Reinforcement learning details" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Scripted agents:\n", + "### Red\n", + "The red agent sits on client 1 and uses an application called DataManipulationBot whose sole purpose is to send a DELETE query to the database.\n", + "The red agent can choose one of two action each timestep:\n", + "1. do nothing\n", + "2. execute the data manipulation application\n", + "The schedule for selecting when to execute the application is controlled by three parameters:\n", + "- start time\n", + "- frequency\n", + "- variance\n", + "Attacks start at a random timestep between (start_time - variance) and (start_time + variance). After each attack, another is attempted after a random delay between (frequency - variance) and (frequency + variance) timesteps.\n", + "\n", + "The data manipulation app itself has an element of randomness because the attack has a probability of success. The default is 0.8 to succeed with the port scan step and 0.8 to succeed with the attack itself.\n", + "Upon a successful attack, the database file becomes corrupted which incurs a negative reward for the RL defender.\n", + "\n", + "The red agent does not use information about the state of the network to decide its action.\n", + "\n", + "### Green\n", + "The green agent sits on client 2 and uses the web browser application to send requests to the web server. The schedule of the green agent is currently random, meaning it will request webpage with a 50% probability, and do nothing with a 50% probability.\n", + "\n", + "When the green agent is blocked from accessing the data through the webpage, this incurs a negative reward to the RL defender." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Observation Space\n", + "\n", + "The blue agent's observation space is structured as nested dictionary with the following information:\n", + "```\n", + "\n", + "- NODES\n", + " - \n", + " - SERVICES\n", + " - \n", + " - operating_status\n", + " - health_status\n", + " - FOLDERS\n", + " - \n", + " - health_status\n", + " - FILES\n", + " - \n", + " - health_status\n", + " - NICS\n", + " - \n", + " - nic_status\n", + " - operating_status\n", + "- LINKS\n", + " - \n", + " - PROTOCOLS\n", + " - ALL\n", + " - load\n", + "- ACL\n", + " - \n", + " - position\n", + " - permission\n", + " - source_node_id\n", + " - source_port\n", + " - dest_node_id\n", + " - dest_port\n", + " - protocol\n", + "- ICS\n", + "```\n", + "\n", + "### Mappings\n", + "\n", + "The dict keys for `node_id` are in the following order:\n", + "|node_id|node name|\n", + "|--|--|\n", + "|1|domain_controller|\n", + "|2|web_server|\n", + "|3|database_server|\n", + "|4|backup_server|\n", + "|5|security_suite|\n", + "|6|client_1|\n", + "|7|client_2|\n", + "\n", + "Service 1 on node 2 (web_server) corresponds to the Web Server service. Other services are only there for padding to ensure that each node's observation space has the same shape. They are filled with zeroes.\n", + "\n", + "Folder 1 on node 3 corresponds to the database folder. File 1 in that folder corresponds to the database storage file. Other files and folders are only there for padding to ensure that each node's observation space has the same shape. They are filled with zeroes.\n", + "\n", + "The dict keys for `link_id` are in the following order:\n", + "|link_id|endpoint_a|endpoint_b|\n", + "|--|--|--|\n", + "|1|router_1|switch_1|\n", + "|1|router_1|switch_2|\n", + "|1|switch_1|domain_controller|\n", + "|1|switch_1|web_server|\n", + "|1|switch_1|database_server|\n", + "|1|switch_1|backup_server|\n", + "|1|switch_1|security_suite|\n", + "|1|switch_2|client_1|\n", + "|1|switch_2|client_2|\n", + "|1|switch_2|security_suite|\n", + "\n", + "The ACL rules in the observation space appear in the same order that they do in the actual ACL. Though, only the first 10 rules are shown, there are default rules lower down that cannot be changed by the agent. The extra rules just allow the network to function normally, by allowing pings, ARP traffic, etc.\n", + "\n", + "Most nodes have only 1 nic, so the observation for those is placed at NIC index 1 in the observation space. Only the security suite has 2 NICs, the second NIC in the observation space is the one that connects the security suite with swtich_2.\n", + "\n", + "The meaning of the services' operating_state is:\n", + "|operating_state|label|\n", + "|--|--|\n", + "|0|UNUSED|\n", + "|1|RUNNING|\n", + "|2|STOPPED|\n", + "|3|PAUSED|\n", + "|4|DISABLED|\n", + "|5|INSTALLING|\n", + "|6|RESTARTING|\n", + "\n", + "The meaning of the services' health_state is:\n", + "|health_state|label|\n", + "|--|--|\n", + "|0|UNUSED|\n", + "|1|GOOD|\n", + "|2|PATCHING|\n", + "|3|COMPROMISED|\n", + "|4|OVERWHELMED|\n", + "\n", + "The meaning of the files' and folders' health_state is:\n", + "|health_state|label|\n", + "|--|--|\n", + "|0|UNUSED|\n", + "|1|GOOD|\n", + "|2|COMPROMISED|\n", + "|3|CORRUPT|\n", + "|4|RESTORING|\n", + "|5|REPAIRING|\n", + "\n", + "The meaning of the NICs' operating_status is:\n", + "|operating_status|label|\n", + "|--|--|\n", + "|0|UNUSED|\n", + "|1|ENABLED|\n", + "|2|DISABLED|\n", + "\n", + "Link load has the following meaning:\n", + "|load|percent utilisation|\n", + "|--|--|\n", + "|0|exactly 0%|\n", + "|1|0-11%|\n", + "|2|11-22%|\n", + "|3|22-33%|\n", + "|4|33-44%|\n", + "|5|44-55%|\n", + "|6|55-66%|\n", + "|7|66-77%|\n", + "|8|77-88%|\n", + "|9|88-99%|\n", + "|10|exactly 100%|\n", + "\n", + "ACL permission has the following meaning:\n", + "|permission|label|\n", + "|--|--|\n", + "|0|UNUSED|\n", + "|1|ALLOW|\n", + "|2|DENY|\n", + "\n", + "ACL source / destination node ids actually correspond to IP addresses (since ACLs work with IP addresses)\n", + "|source / dest node id|ip_address|label|\n", + "|--|--|--|\n", + "|0| | UNUSED|\n", + "|1| |ALL addresses|\n", + "|2| 192.168.1.10 | domain_controller|\n", + "|3| 192.168.1.12 | web_server \n", + "|4| 192.168.1.14 | database_server|\n", + "|5| 192.168.1.16 | backup_server|\n", + "|6| 192.168.1.110 | security_suite (eth-1)|\n", + "|7| 192.168.10.21 | client_1|\n", + "|8| 192.168.10.22 | client_2|\n", + "|9| 192.168.10.110| security_suite (eth-2)|\n", + "\n", + "ACL source / destination port ids have the following encoding:\n", + "|port id|port number| port use |\n", + "|--|--|--|\n", + "|0||UNUSED|\n", + "|1||ALL|\n", + "|2|219|ARP|\n", + "|3|53|DNS|\n", + "|4|80|HTTP|\n", + "|5|5432|POSTGRES_SERVER|\n", + "\n", + "ACL protocol ids have the following encoding:\n", + "|protocol id|label|\n", + "|--|--|\n", + "|0|UNUSED|\n", + "|1|ALL|\n", + "|2|ICMP|\n", + "|3|TCP|\n", + "|4|UDP|\n", + "\n", + "protocol" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Action Space\n", + "\n", + "The blue agent chooses from a list of 54 pre-defined actions. The full list is defined in the `action_map` in the config. The most important ones are explained here:\n", + "\n", + "- `0`: Do nothing\n", + "- `1`: Scan the web service - this refreshes the health status in the observation space\n", + "- `9`: Scan the database file - this refreshes the health status of the database file\n", + "- `13`: Patch the database service - This triggers the database to restore data from the backup server\n", + "- `19`: Shut down client 1\n", + "- `22`: Block outgoing traffic from client 1\n", + "- `26`: Block TCP traffic from client 1 to the database node\n", + "- `28-37`: Remove ACL rules 1-10\n", + "- `42`: Disconnect client 1 from the network\n", + "\n", + "The other actions will either have no effect or will negatively impact the network, so the blue agent should avoid taking other actions, and learn about these actions." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Reward Function\n", + "\n", + "The blue agent's reward is calculated using two measures:\n", + "1. Whether the database file is in a good state (+1 for good, -1 for corrupted, 0 for any other state)\n", + "2. Whether the green agent's most recent webpage request was successful (+1 for a `200` return code, -1 for a `404` return code and 0 otherwise).\n", + "These two components are averaged to get the final reward.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Demonstration" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "First, load the required modules" + ] + }, { "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/cade/repos/PrimAITE/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n", - "2023-11-26 23:25:47,985\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", - "2023-11-26 23:25:51,213\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", - "2023-11-26 23:25:51,491\tWARNING __init__.py:10 -- PG has/have been moved to `rllib_contrib` and will no longer be maintained by the RLlib team. You can still use it/them normally inside RLlib util Ray 2.8, but from Ray 2.9 on, all `rllib_contrib` algorithms will no longer be part of the core repo, and will therefore have to be installed separately with pinned dependencies for e.g. ray[rllib] and other packages! See https://github.com/ray-project/ray/tree/master/rllib_contrib#rllib-contrib for more information on the RLlib contrib effort.\n" - ] - } - ], + "outputs": [], "source": [ - "from primaite.session.session import PrimaiteSession\n", - "from primaite.game.game import PrimaiteGame\n", - "from primaite.config.load import example_config_path\n", - "\n", - "from primaite.simulator.system.services.database.database_service import DatabaseService\n", - "\n", - "import yaml" + "%load_ext autoreload\n", + "%autoreload 2" ] }, { @@ -36,61 +339,181 @@ "name": "stderr", "output_type": "stream", "text": [ - "2023-11-26 23:25:51,579::ERROR::primaite.simulator.network.hardware.base::175::NIC a9:92:0a:5e:1b:e4/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-11-26 23:25:51,580::ERROR::primaite.simulator.network.hardware.base::175::NIC ef:03:23:af:3c:19/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-11-26 23:25:51,581::ERROR::primaite.simulator.network.hardware.base::175::NIC ae:cf:83:2f:94:17/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-11-26 23:25:51,582::ERROR::primaite.simulator.network.hardware.base::175::NIC 4c:b2:99:e2:4a:5d/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-11-26 23:25:51,583::ERROR::primaite.simulator.network.hardware.base::175::NIC b9:eb:f9:c2:17:2f/127.0.0.1 cannot be enabled as it is not connected to a Link\n", - "2023-11-26 23:25:51,590::ERROR::primaite.simulator.network.hardware.base::175::NIC cb:df:ca:54:be:01/192.168.1.10 cannot be enabled as it is not connected to a Link\n", - "2023-11-26 23:25:51,595::ERROR::primaite.simulator.network.hardware.base::175::NIC 6e:32:12:da:4d:0d/192.168.1.12 cannot be enabled as it is not connected to a Link\n", - "2023-11-26 23:25:51,600::ERROR::primaite.simulator.network.hardware.base::175::NIC 58:6e:9b:a7:68:49/192.168.1.14 cannot be enabled as it is not connected to a Link\n", - "2023-11-26 23:25:51,604::ERROR::primaite.simulator.network.hardware.base::175::NIC 33:db:a6:40:dd:a3/192.168.1.16 cannot be enabled as it is not connected to a Link\n", - "2023-11-26 23:25:51,608::ERROR::primaite.simulator.network.hardware.base::175::NIC 72:aa:2b:c0:4c:5f/192.168.1.110 cannot be enabled as it is not connected to a Link\n", - "2023-11-26 23:25:51,610::ERROR::primaite.simulator.network.hardware.base::175::NIC 11:d7:0e:90:d9:a4/192.168.10.110 cannot be enabled as it is not connected to a Link\n", - "2023-11-26 23:25:51,614::ERROR::primaite.simulator.network.hardware.base::175::NIC 86:2b:a4:e5:4d:0f/192.168.10.21 cannot be enabled as it is not connected to a Link\n", - "2023-11-26 23:25:51,631::ERROR::primaite.simulator.network.hardware.base::175::NIC af:ad:8f:84:f1:db/192.168.10.22 cannot be enabled as it is not connected to a Link\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "installing DNSServer on node domain_controller\n", - "installing DatabaseClient on node web_server\n", - "installing WebServer on node web_server\n", - "installing DatabaseService on node database_server\n", - "installing FTPClient on node database_server\n", - "installing FTPServer on node backup_server\n", - "installing DNSClient on node client_1\n", - "installing DNSClient on node client_2\n" + "/home/cade/repos/PrimAITE/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n", + "2024-01-25 11:19:29,199\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", + "2024-01-25 11:19:31,924\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n" ] } ], "source": [ + "# Imports\n", + "from primaite.config.load import example_config_path\n", + "from primaite.session.environment import PrimaiteGymEnv\n", + "from primaite.game.game import PrimaiteGame\n", + "import yaml\n", + "from pprint import pprint\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Instantiate the environment. We also disable the agent observation flattening.\n", "\n", - "with open(example_config_path(),'r') as cfgfile:\n", - " cfg = yaml.safe_load(cfgfile)\n", - "game = PrimaiteGame.from_config(cfg)\n", - "net = game.simulation.network\n", - "database_server = net.get_node_by_hostname('database_server')\n", - "web_server = net.get_node_by_hostname('web_server')\n", - "client_1 = net.get_node_by_hostname('client_1')\n", - "\n", - "db_service = database_server.software_manager.software[\"DatabaseService\"]\n", - "db_client = web_server.software_manager.software[\"DatabaseClient\"]\n", - "# db_client.run()\n", - "db_manipulation_bot = client_1.software_manager.software[\"DataManipulationBot\"]\n", - "db_manipulation_bot.port_scan_p_of_success=1.0\n", - "db_manipulation_bot.data_manipulation_p_of_success=1.0\n" + "This cell will print the observation when the network is healthy. You should be able to verify Node file and service statuses against the description above." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Resetting environment, episode 0, avg. reward: 0.0\n", + "env created successfully\n", + "{'ACL': {1: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 0,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 2: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 1,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 3: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 2,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 4: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 3,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 5: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 4,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 6: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 5,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 7: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 6,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 8: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 7,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 9: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 8,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 10: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 9,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0}},\n", + " 'ICS': 0,\n", + " 'LINKS': {1: {'PROTOCOLS': {'ALL': 1}},\n", + " 2: {'PROTOCOLS': {'ALL': 1}},\n", + " 3: {'PROTOCOLS': {'ALL': 1}},\n", + " 4: {'PROTOCOLS': {'ALL': 1}},\n", + " 5: {'PROTOCOLS': {'ALL': 1}},\n", + " 6: {'PROTOCOLS': {'ALL': 1}},\n", + " 7: {'PROTOCOLS': {'ALL': 1}},\n", + " 8: {'PROTOCOLS': {'ALL': 1}},\n", + " 9: {'PROTOCOLS': {'ALL': 1}},\n", + " 10: {'PROTOCOLS': {'ALL': 1}}},\n", + " 'NODES': {1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}},\n", + " 'health_status': 1}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}}\n" + ] + } + ], "source": [ - "db_client.run()" + "# create the env\n", + "with open(example_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + "game = PrimaiteGame.from_config(cfg)\n", + "env = PrimaiteGymEnv(game = game)\n", + "# Don't flatten obs as we are not training an agent and we wish to see the dict-formatted observations\n", + "env.agent.flatten_obs = False\n", + "obs, info = env.reset()\n", + "print('env created successfully')\n", + "pprint(obs)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The red agent will start attacking at some point between step 20 and 30.\n", + "\n", + "The red agent has a random chance of failing its attack, so you may need run the following cell multiple times until the reward goes from 1.0 to -1.0." ] }, { @@ -99,18 +522,53 @@ "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 1, Red action: DONOTHING, Blue reward:1.0\n", + "step: 2, Red action: DONOTHING, Blue reward:1.0\n", + "step: 3, Red action: DONOTHING, Blue reward:1.0\n", + "step: 4, Red action: DONOTHING, Blue reward:1.0\n", + "step: 5, Red action: DONOTHING, Blue reward:1.0\n", + "step: 6, Red action: DONOTHING, Blue reward:1.0\n", + "step: 7, Red action: DONOTHING, Blue reward:1.0\n", + "step: 8, Red action: DONOTHING, Blue reward:1.0\n", + "step: 9, Red action: DONOTHING, Blue reward:1.0\n", + "step: 10, Red action: DONOTHING, Blue reward:1.0\n", + "step: 11, Red action: DONOTHING, Blue reward:1.0\n", + "step: 12, Red action: DONOTHING, Blue reward:1.0\n", + "step: 13, Red action: DONOTHING, Blue reward:1.0\n", + "step: 14, Red action: DONOTHING, Blue reward:1.0\n", + "step: 15, Red action: DONOTHING, Blue reward:1.0\n", + "step: 16, Red action: DONOTHING, Blue reward:1.0\n", + "step: 17, Red action: DONOTHING, Blue reward:1.0\n", + "step: 18, Red action: DONOTHING, Blue reward:1.0\n", + "step: 19, Red action: DONOTHING, Blue reward:1.0\n", + "step: 20, Red action: DONOTHING, Blue reward:1.0\n", + "step: 21, Red action: DONOTHING, Blue reward:1.0\n", + "step: 22, Red action: DONOTHING, Blue reward:1.0\n", + "step: 23, Red action: DONOTHING, Blue reward:1.0\n", + "step: 24, Red action: DONOTHING, Blue reward:1.0\n", + "step: 25, Red action: DONOTHING, Blue reward:1.0\n", + "step: 26, Red action: DONOTHING, Blue reward:1.0\n", + "step: 27, Red action: NODE_APPLICATION_EXECUTE, Blue reward:0.0\n", + "step: 28, Red action: DONOTHING, Blue reward:-1.0\n", + "step: 29, Red action: DONOTHING, Blue reward:-1.0\n", + "step: 30, Red action: DONOTHING, Blue reward:-1.0\n" + ] } ], "source": [ - "db_service.backup_database()" + "for step in range(30):\n", + " obs, reward, terminated, truncated, info = env.step(0)\n", + " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}, Blue reward:{reward}\" )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now the reward is -1, let's have a look at blue agent's observation." ] }, { @@ -119,27 +577,110 @@ "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}}, 'health_status': 1}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}\n" + ] } ], "source": [ - "db_client.query(\"SELECT\")" + "pprint(obs['NODES'])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The true statuses of the database file and webapp are not updated. The blue agent needs to perform a scan to see that they have degraded." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 3, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 2}}, 'health_status': 1}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}\n" + ] + } + ], "source": [ - "db_manipulation_bot.run()" + "obs, reward, terminated, truncated, info = env.step(9) # scan database file\n", + "obs, reward, terminated, truncated, info = env.step(1) # scan webapp service\n", + "pprint(obs['NODES'])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now service 1 on node 2 has `health_status = 3`, indicating that the webapp is compromised.\n", + "File 1 in folder 1 on node 3 has `health_status = 2`, indicating that the database file is compromised." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The blue agent can now patch the database to restore the file to a good health status." ] }, { @@ -148,130 +689,221 @@ "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "db_client.query(\"SELECT\")" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "db_service.restore_backup()" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "db_client.query(\"SELECT\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "db_manipulation_bot.run()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "client_1.ping(database_server.ethernet_port[1].ip_address)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [], - "source": [ - "from pydantic import validate_call, BaseModel" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "class A(BaseModel):\n", - " x:int\n", - "\n", - " @validate_call\n", - " def increase_x(self, by:int) -> None:\n", - " self.x += 1" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [], - "source": [ - "my_a = A(x=3)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "ename": "ValidationError", - "evalue": "1 validation error for increase_x\n0\n Input should be a valid integer, got a number with a fractional part [type=int_from_float, input_value=3.2, input_type=float]\n For further information visit https://errors.pydantic.dev/2.1/v/int_from_float", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValidationError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m/home/cade/repos/PrimAITE/src/primaite/notebooks/uc2_demo.ipynb Cell 15\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> 1\u001b[0m my_a\u001b[39m.\u001b[39;49mincrease_x(\u001b[39m3.2\u001b[39;49m)\n", - "File \u001b[0;32m~/repos/PrimAITE/venv/lib/python3.10/site-packages/pydantic/_internal/_validate_call.py:91\u001b[0m, in \u001b[0;36mValidateCallWrapper.__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 90\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__call__\u001b[39m(\u001b[39mself\u001b[39m, \u001b[39m*\u001b[39margs: Any, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: Any) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Any:\n\u001b[0;32m---> 91\u001b[0m res \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__pydantic_validator__\u001b[39m.\u001b[39;49mvalidate_python(pydantic_core\u001b[39m.\u001b[39;49mArgsKwargs(args, kwargs))\n\u001b[1;32m 92\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__return_pydantic_validator__:\n\u001b[1;32m 93\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__return_pydantic_validator__\u001b[39m.\u001b[39mvalidate_python(res)\n", - "\u001b[0;31mValidationError\u001b[0m: 1 validation error for increase_x\n0\n Input should be a valid integer, got a number with a fractional part [type=int_from_float, input_value=3.2, input_type=float]\n For further information visit https://errors.pydantic.dev/2.1/v/int_from_float" + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 33\n", + "Red action: DONOTHING\n", + "Green action: DONOTHING\n", + "Blue reward:-1.0\n" ] } ], "source": [ - "my_a.increase_x(3.2)" + "obs, reward, terminated, truncated, info = env.step(13) # patch the database\n", + "print(f\"step: {env.game.step_counter}\")\n", + "print(f\"Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}\" )\n", + "print(f\"Green action: {info['agent_actions']['client_2_green_user'][0]}\" )\n", + "print(f\"Blue reward:{reward}\" )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The patching takes two steps, so the reward hasn't changed yet. Let's do nothing for another timestep, the reward should improve.\n", + "\n", + "The reward will be 0 as soon as the file finishes restoring. Then, the reward will increase to 1 when the green agent makes a request. (Because the webapp access part of the reward does not update until a successful request is made.)\n", + "\n", + "Run the following cell until the green action is `NODE_APPLICATION_EXECUTE`, then the reward should become 1. If you run it enough times, another red attack will happen and the reward will drop again." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 44\n", + "Red action: DONOTHING\n", + "Green action: NODE_APPLICATION_EXECUTE\n", + "Blue reward:-1.0\n" + ] + } + ], + "source": [ + "obs, reward, terminated, truncated, info = env.step(0) # patch the database\n", + "print(f\"step: {env.game.step_counter}\")\n", + "print(f\"Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}\" )\n", + "print(f\"Green action: {info['agent_actions']['client_2_green_user'][0]}\" )\n", + "print(f\"Blue reward:{reward}\" )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The blue agent can prevent attacks by implementing an ACL rule to stop client_1 from sending POSTGRES traffic to the database. (Let's also patch the database file to get the reward back up.)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 107, Red action: DONOTHING, Blue reward:1.0\n", + "step: 108, Red action: DONOTHING, Blue reward:1.0\n", + "step: 109, Red action: DONOTHING, Blue reward:1.0\n", + "step: 110, Red action: DONOTHING, Blue reward:1.0\n", + "step: 111, Red action: DONOTHING, Blue reward:1.0\n", + "step: 112, Red action: DONOTHING, Blue reward:1.0\n", + "step: 113, Red action: DONOTHING, Blue reward:1.0\n", + "step: 114, Red action: NODE_APPLICATION_EXECUTE, Blue reward:1.0\n", + "step: 115, Red action: DONOTHING, Blue reward:1.0\n", + "step: 116, Red action: DONOTHING, Blue reward:1.0\n", + "step: 117, Red action: DONOTHING, Blue reward:1.0\n", + "step: 118, Red action: DONOTHING, Blue reward:1.0\n", + "step: 119, Red action: DONOTHING, Blue reward:1.0\n", + "step: 120, Red action: DONOTHING, Blue reward:1.0\n", + "step: 121, Red action: DONOTHING, Blue reward:1.0\n", + "step: 122, Red action: DONOTHING, Blue reward:1.0\n", + "step: 123, Red action: DONOTHING, Blue reward:1.0\n", + "step: 124, Red action: DONOTHING, Blue reward:1.0\n", + "step: 125, Red action: DONOTHING, Blue reward:1.0\n", + "step: 126, Red action: DONOTHING, Blue reward:1.0\n", + "step: 127, Red action: DONOTHING, Blue reward:1.0\n", + "step: 128, Red action: DONOTHING, Blue reward:1.0\n", + "step: 129, Red action: DONOTHING, Blue reward:1.0\n", + "step: 130, Red action: DONOTHING, Blue reward:1.0\n", + "step: 131, Red action: DONOTHING, Blue reward:1.0\n", + "step: 132, Red action: DONOTHING, Blue reward:1.0\n", + "step: 133, Red action: DONOTHING, Blue reward:1.0\n", + "step: 134, Red action: NODE_APPLICATION_EXECUTE, Blue reward:1.0\n", + "step: 135, Red action: DONOTHING, Blue reward:1.0\n", + "step: 136, Red action: DONOTHING, Blue reward:1.0\n" + ] + } + ], + "source": [ + "env.step(13) # Patch the database\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}, Blue reward:{reward}\" )\n", + "\n", + "env.step(26) # Block client 1\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}, Blue reward:{reward}\" )\n", + "\n", + "for step in range(30):\n", + " obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", + " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}, Blue reward:{reward}\" )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, even though the red agent executes an attack, the reward stays at 1.0" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's also have a look at the ACL observation to verify our new ACL rule at position 5." + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1: {'position': 0,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 2: {'position': 1,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 3: {'position': 2,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 4: {'position': 3,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 5: {'position': 4,\n", + " 'permission': 2,\n", + " 'source_node_id': 7,\n", + " 'source_port': 1,\n", + " 'dest_node_id': 4,\n", + " 'dest_port': 1,\n", + " 'protocol': 3},\n", + " 6: {'position': 5,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 7: {'position': 6,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 8: {'position': 7,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 9: {'position': 8,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 10: {'position': 9,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0}}" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "obs['ACL']" ] }, { diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 6701f183..a3831bc1 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -29,7 +29,7 @@ class PrimaiteGymEnv(gymnasium.Env): # make ProxyAgent store the action chosen my the RL policy self.agent.store_action(action) # apply_agent_actions accesses the action we just stored - self.game.apply_agent_actions() + agent_actions = self.game.apply_agent_actions() self.game.advance_timestep() state = self.game.get_sim_state() @@ -39,7 +39,7 @@ class PrimaiteGymEnv(gymnasium.Env): reward = self.agent.reward_function.current_reward terminated = False truncated = self.game.calculate_truncated() - info = {} + info = {"agent_actions": agent_actions} # tell us what all the agents did for convenience. if self.game.save_step_metadata: self._write_step_metadata_json(action, state, reward) return next_obs, reward, terminated, truncated, info @@ -172,7 +172,7 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): # 1. Perform actions for agent_name, action in actions.items(): self.agents[agent_name].store_action(action) - self.game.apply_agent_actions() + agent_actions = self.game.apply_agent_actions() # 2. Advance timestep self.game.advance_timestep() @@ -186,7 +186,7 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): rewards = {name: agent.reward_function.current_reward for name, agent in self.agents.items()} terminateds = {name: False for name, _ in self.agents.items()} truncateds = {name: self.game.calculate_truncated() for name, _ in self.agents.items()} - infos = {} + infos = {"agent_actions": agent_actions} terminateds["__all__"] = len(self.terminateds) == len(self.agents) truncateds["__all__"] = self.game.calculate_truncated() if self.game.save_step_metadata: diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 9070f246..e5458670 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -19,7 +19,7 @@ game: - UDP agents: - - ref: client_1_green_user + - ref: client_2_green_user team: GREEN type: GreenWebBrowsingAgent observation_space: diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index e67f6606..767279ce 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -23,7 +23,7 @@ game: - UDP agents: - - ref: client_1_green_user + - ref: client_2_green_user team: GREEN type: GreenWebBrowsingAgent observation_space: diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 220ca21e..6290fa53 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -29,7 +29,7 @@ game: - UDP agents: - - ref: client_1_green_user + - ref: client_2_green_user team: GREEN type: GreenWebBrowsingAgent observation_space: diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index d7e94cb6..89b88475 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -27,7 +27,7 @@ game: - UDP agents: - - ref: client_1_green_user + - ref: client_2_green_user team: GREEN type: GreenWebBrowsingAgent observation_space: diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index b89349c0..b9fa1216 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -23,7 +23,7 @@ game: - UDP agents: - - ref: client_1_green_user + - ref: client_2_green_user team: GREEN type: GreenWebBrowsingAgent observation_space: From 99723b6578d332d49eb739bb51bda1c0d1a5ef99 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Jan 2024 12:33:18 +0000 Subject: [PATCH 539/980] Update notebook with more images. --- .../notebooks/_package_data/uc2_attack.png | Bin 0 -> 112286 bytes src/primaite/notebooks/uc2_demo.ipynb | 6 +++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/primaite/notebooks/_package_data/uc2_attack.png diff --git a/src/primaite/notebooks/_package_data/uc2_attack.png b/src/primaite/notebooks/_package_data/uc2_attack.png new file mode 100644 index 0000000000000000000000000000000000000000..8b8df5ce8ddf74ad717c734cd52945164580f0f7 GIT binary patch literal 112286 zcmeFZ2UJs8-!~e^HjafslwKSW5ET%RUL8b41jIrQ2%$)qUIGLwNQ;URq$?;OU3w@{ zN>D?S7J8J>OCmMY?ESC5f7=f)>uK%(gZmE{ z47OkU!nrFj*q%@rY-h~xyTCh9T|BSAuOo;HS9D>p0AUy`^!(dZ4 zU@*lv7>wgqBGy0|e6Y(}N9!Dn0sWU+oe=}x*>mfHi6;yuE(rZ>^LwS{1K!;2rLC*E zdtw{c{%veUtzV&UhH0NWd(E$JW-#cfp?9?$9ew)52fw)Y@BT8_b>ZsGUFURJZXS;s zyBe=4n#!y1Pg?ymE<$<8|6)VCC$hjEE_Lr&`UvkP8pO!VcR?n!h z9n(sxb98h<41BcLJU12(3CfR`7az|jQuv;j8gAA(gYkmK6u%Qkj{>3`+PC%iiI=(Sr;`2Y~&KO}*q;r}pUcpBsN(`u=Y z7rK~TucFa+Yh%tT_4}q&3(A%0x7)&C$hccSjfR(Jf9dsx;l`A3wNvYe_E&B1Ri&3Z z+&`_b?P!3dCj5Eehwg>A&fpkTiotW)JGC+I`R7AzQIXIM=C_6v+&dp@YGby;ybAcW zIlikO40cT8bk6!(Lq2;wisA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;@2`R(2hLh>EK(8BB_X z!`?+1LVHn?hFXizR3>yA30b@wd3PFW20)s^5GH|gunsgF-Atak1xOmd-ik6M>P$0q zu-kJ>0=8tt%f*@_%!#?L`*Y;WA;GYkpPhoMcA>2WE>>`~1rWY0D3Ae=9rs^$4((iU z>R}*5`94%g#S(nUDPv+%3k8XUHOPOBv-FQ(wZg}XEv z8i^q;0(fmdX2zu>(9A%V-#ia!a_mP1ueO=ls7OVT07VmubmBfgRUH+lxyu@O5X9h7 zO&SkpyU=%(YmP_S!N2*o0?vf~FTuwT0Cbg&`ot4}5u+1)V4phr+@n2#fzt_oU2 z438}^LC7itLr!C8WZwRrSRfhs^;+>AZl{#yruB)zz2l%D@dFOWi8~km60@e9mN|MS z$V)HU{v+|AfI%tMI91 zkKIBR-#vL4-GLNvnu~^8HVwKOV?Ezqqm$J4GD}58MMq|4ho;-{@;WVCPm4aKDWZCg z6<^@v%XoO8%(s`!_@_=fsfX*GuVfg zQc`O&+?Knj7$LdMs;tNW#*8rY!{zSBKU* zCsxO$v2@a4{#vtKZOE=%uYjItYXv$YFK0toyE#TddX0vkLwgoS#L~Qd9pn9g6}&;r z?TE441q(N8WveUJ@Gs0hnSJ{uWn?Ay$)AyxQfjaVbbZTzb;xD+_Ia<5ASvX$)Uw`HaX(`tY=o~qrm2t@Y+W!E>ER9nD literal 0 HcmV?d00001 diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index 7bcfdd29..6a20e3e8 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -55,7 +55,11 @@ "source": [ "## Red agent\n", "\n", - "The red agent waits a bit then sends a DELETE query to the database from client 1. If the delete is successful, the database file is flagged as compromised to signal that data is not available." + "The red agent waits a bit then sends a DELETE query to the database from client 1. If the delete is successful, the database file is flagged as compromised to signal that data is not available.\n", + "\n", + "[](_package_data/uc2_attack.png)\n", + "\n", + "_(click image to enlarge)_" ] }, { From e7aac754a08772f771c4dc895376eb89c453afe1 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Jan 2024 12:38:28 +0000 Subject: [PATCH 540/980] Update the changelog --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 227cec69..cb2f418b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- Fixed a bug where ACL rules were not resetting on episode reset. +- Fixed a bug where blue agent's ACL actions were being applied against the wrong IP addresses +- Fixed a bug where deleted files and folders did not reset correctly on episode reset. +- Fixed a bug where service health status was using the actual health state instead of the visible health state +- Fixed a bug where the database file health status was using the incorrect value for negative rewards +- Fixed a bug preventing file actions from reaching their intended file +- Made database patch correctly take 2 timesteps instead of being immediate +- Made database patch only possible when the software is compromised or good, it's no longer possible when the software is OFF or RESETTING +- Temporarily disable the blue agent file delete action due to crashes. This issue is resolved in another branch that will be merged into dev soon. +- Fix a bug where ACLs were not showing up correctly in the observation space. +- Added a notebook which explains Data manipulation scenario, demonstrates the attack, and shows off blue agent's action space, observation space, and reward function. - Made packet capture and system logging optional (off by default). To turn on, change the io_settings.save_pcap_logs and io_settings.save_sys_logs settings in the config. - Made observation space flattening optional (on by default). To turn off for an agent, change the agent_settings.flatten_obs setting in the config. - Fixed an issue where the data manipulation attack was triggered at episode start. From 73a75c497b612bbacb352373070c7391205d4c73 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Jan 2024 13:13:50 +0000 Subject: [PATCH 541/980] Fix test --- .../network/hardware/nodes/router.py | 21 ++++++++++-- .../assets/configs/bad_primaite_session.yaml | 17 ++++++++++ .../configs/eval_only_primaite_session.yaml | 17 ++++++++++ tests/assets/configs/multi_agent_session.yaml | 34 +++++++++++++++++++ .../assets/configs/test_primaite_session.yaml | 17 ++++++++++ .../configs/train_only_primaite_session.yaml | 17 ++++++++++ .../_simulator/_network/test_container.py | 24 ++++++++++--- 7 files changed, 140 insertions(+), 7 deletions(-) diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 0c5d0ce9..41c14967 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -90,7 +90,7 @@ class AccessControlList(SimComponent): implicit_rule: ACLRule max_acl_rules: int = 25 _acl: List[Optional[ACLRule]] = [None] * 24 - _default_config: dict[int, dict] = {} + _default_config: Dict[int, dict] = {} """Config dict describing how the ACL list should look at episode start""" def __init__(self, **kwargs) -> None: @@ -109,6 +109,21 @@ class AccessControlList(SimComponent): vals_to_keep = {"implicit_action", "max_acl_rules", "acl"} self._original_state = self.model_dump(include=vals_to_keep, exclude_none=True) + for i, rule in enumerate(self._acl): + if not rule: + continue + self._default_config[i] = {"action": rule.action.name} + if rule.src_ip_address: + self._default_config[i]["src_ip"] = str(rule.src_ip_address) + if rule.dst_ip_address: + self._default_config[i]["dst_ip"] = str(rule.dst_ip_address) + if rule.src_port: + self._default_config[i]["src_port"] = rule.src_port.name + if rule.dst_port: + self._default_config[i]["dst_port"] = rule.dst_port.name + if rule.protocol: + self._default_config[i]["protocol"] = rule.protocol.name + def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" self.implicit_rule.reset_component_for_episode(episode) @@ -124,8 +139,8 @@ class AccessControlList(SimComponent): src_port=None if not (p := r_cfg.get("src_port")) else Port[p], dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], - src_ip_address=r_cfg.get("ip_address"), - dst_ip_address=r_cfg.get("ip_address"), + src_ip_address=r_cfg.get("src_ip"), + dst_ip_address=r_cfg.get("dst_ip"), position=r_num, ) diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index e5458670..4a1fc275 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -491,6 +491,23 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 + - node_ref: client_1 + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 reward_function: reward_components: diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index 767279ce..c8ffa23f 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -502,6 +502,23 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 + - node_ref: client_1 + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 reward_function: reward_components: diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 6290fa53..6cd22694 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -509,6 +509,23 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 + - node_ref: client_1 + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 reward_function: reward_components: @@ -940,6 +957,23 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 + - node_ref: client_1 + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 reward_function: reward_components: diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 89b88475..99087798 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -507,6 +507,23 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 + - node_ref: client_1 + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 reward_function: reward_components: diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index b9fa1216..c2842a06 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -503,6 +503,23 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 + ip_address_order: + - node_ref: domain_controller + nic_num: 1 + - node_ref: web_server + nic_num: 1 + - node_ref: database_server + nic_num: 1 + - node_ref: backup_server + nic_num: 1 + - node_ref: security_suite + nic_num: 1 + - node_ref: client_1 + nic_num: 1 + - node_ref: client_2 + nic_num: 1 + - node_ref: security_suite + nic_num: 2 reward_function: reward_components: diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index e348838e..7667a59f 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -10,6 +10,22 @@ from primaite.simulator.system.applications.database_client import DatabaseClien from primaite.simulator.system.services.database.database_service import DatabaseService +def filter_keys_nested_item(data, keys): + stack = [(data, {})] + while stack: + current, filtered = stack.pop() + if isinstance(current, dict): + for k, v in current.items(): + if k in keys: + filtered[k] = filter_keys_nested_item(v, keys) + elif isinstance(v, (dict, list)): + stack.append((v, {})) + elif isinstance(current, list): + for item in current: + stack.append((item, {})) + return filtered + + @pytest.fixture(scope="function") def network(example_network) -> Network: assert len(example_network.routers) is 1 @@ -59,10 +75,10 @@ def test_reset_network(network): assert client_1.operating_state is NodeOperatingState.ON assert server_1.operating_state is NodeOperatingState.ON - - assert json.dumps(network.describe_state(), sort_keys=True, indent=2) == json.dumps( - state_before, sort_keys=True, indent=2 - ) + # don't worry if UUIDs change + a = filter_keys_nested_item(json.dumps(network.describe_state(), sort_keys=True, indent=2), ["uuid"]) + b = filter_keys_nested_item(json.dumps(state_before, sort_keys=True, indent=2), ["uuid"]) + assert a == b def test_creating_container(): From 4b98c1f630feccfde1eb12f5b3cebffef8170345 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Jan 2024 14:43:49 +0000 Subject: [PATCH 542/980] Update uc2 notebook --- src/primaite/notebooks/uc2_demo.ipynb | 115 ++++++++++++++------------ 1 file changed, 60 insertions(+), 55 deletions(-) diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index 6a20e3e8..679e8226 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -345,8 +345,8 @@ "text": [ "/home/cade/repos/PrimAITE/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n", - "2024-01-25 11:19:29,199\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", - "2024-01-25 11:19:31,924\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n" + "2024-01-25 14:43:32,056\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", + "2024-01-25 14:43:35,213\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n" ] } ], @@ -502,6 +502,9 @@ "# create the env\n", "with open(example_config_path(), 'r') as f:\n", " cfg = yaml.safe_load(f)\n", + " # set success probability to 1.0 to avoid rerunning cells.\n", + " cfg['simulation']['network']['nodes'][8]['applications'][0]['options']['data_manipulation_p_of_success'] = 1.0\n", + " cfg['simulation']['network']['nodes'][8]['applications'][0]['options']['port_scan_p_of_success'] = 1.0\n", "game = PrimaiteGame.from_config(cfg)\n", "env = PrimaiteGymEnv(game = game)\n", "# Don't flatten obs as we are not training an agent and we wish to see the dict-formatted observations\n", @@ -515,9 +518,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The red agent will start attacking at some point between step 20 and 30.\n", - "\n", - "The red agent has a random chance of failing its attack, so you may need run the following cell multiple times until the reward goes from 1.0 to -1.0." + "The red agent will start attacking at some point between step 20 and 30. When this happens, the reward will go from 1.0 to 0.0, and to -1.0 when the green agent tries to access the webpage." ] }, { @@ -529,10 +530,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "step: 1, Red action: DONOTHING, Blue reward:1.0\n", - "step: 2, Red action: DONOTHING, Blue reward:1.0\n", - "step: 3, Red action: DONOTHING, Blue reward:1.0\n", - "step: 4, Red action: DONOTHING, Blue reward:1.0\n", + "step: 1, Red action: DONOTHING, Blue reward:0.5\n", + "step: 2, Red action: DONOTHING, Blue reward:0.5\n", + "step: 3, Red action: DONOTHING, Blue reward:0.5\n", + "step: 4, Red action: DONOTHING, Blue reward:0.5\n", "step: 5, Red action: DONOTHING, Blue reward:1.0\n", "step: 6, Red action: DONOTHING, Blue reward:1.0\n", "step: 7, Red action: DONOTHING, Blue reward:1.0\n", @@ -550,20 +551,22 @@ "step: 19, Red action: DONOTHING, Blue reward:1.0\n", "step: 20, Red action: DONOTHING, Blue reward:1.0\n", "step: 21, Red action: DONOTHING, Blue reward:1.0\n", - "step: 22, Red action: DONOTHING, Blue reward:1.0\n", - "step: 23, Red action: DONOTHING, Blue reward:1.0\n", - "step: 24, Red action: DONOTHING, Blue reward:1.0\n", - "step: 25, Red action: DONOTHING, Blue reward:1.0\n", - "step: 26, Red action: DONOTHING, Blue reward:1.0\n", - "step: 27, Red action: NODE_APPLICATION_EXECUTE, Blue reward:0.0\n", + "step: 22, Red action: NODE_APPLICATION_EXECUTE, Blue reward:0.0\n", + "step: 23, Red action: DONOTHING, Blue reward:0.0\n", + "step: 24, Red action: DONOTHING, Blue reward:0.0\n", + "step: 25, Red action: DONOTHING, Blue reward:0.0\n", + "step: 26, Red action: DONOTHING, Blue reward:-1.0\n", + "step: 27, Red action: DONOTHING, Blue reward:-1.0\n", "step: 28, Red action: DONOTHING, Blue reward:-1.0\n", "step: 29, Red action: DONOTHING, Blue reward:-1.0\n", - "step: 30, Red action: DONOTHING, Blue reward:-1.0\n" + "step: 30, Red action: DONOTHING, Blue reward:-1.0\n", + "step: 31, Red action: DONOTHING, Blue reward:-1.0\n", + "step: 32, Red action: DONOTHING, Blue reward:-1.0\n" ] } ], "source": [ - "for step in range(30):\n", + "for step in range(32):\n", " obs, reward, terminated, truncated, info = env.step(0)\n", " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}, Blue reward:{reward}\" )" ] @@ -696,9 +699,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "step: 33\n", + "step: 35\n", "Red action: DONOTHING\n", - "Green action: DONOTHING\n", + "Green action: NODE_APPLICATION_EXECUTE\n", "Blue reward:-1.0\n" ] } @@ -724,17 +727,17 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "step: 44\n", + "step: 36\n", "Red action: DONOTHING\n", "Green action: NODE_APPLICATION_EXECUTE\n", - "Blue reward:-1.0\n" + "Blue reward:0.0\n" ] } ], @@ -755,43 +758,45 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "step: 107, Red action: DONOTHING, Blue reward:1.0\n", - "step: 108, Red action: DONOTHING, Blue reward:1.0\n", - "step: 109, Red action: DONOTHING, Blue reward:1.0\n", - "step: 110, Red action: DONOTHING, Blue reward:1.0\n", - "step: 111, Red action: DONOTHING, Blue reward:1.0\n", - "step: 112, Red action: DONOTHING, Blue reward:1.0\n", - "step: 113, Red action: DONOTHING, Blue reward:1.0\n", - "step: 114, Red action: NODE_APPLICATION_EXECUTE, Blue reward:1.0\n", - "step: 115, Red action: DONOTHING, Blue reward:1.0\n", - "step: 116, Red action: DONOTHING, Blue reward:1.0\n", - "step: 117, Red action: DONOTHING, Blue reward:1.0\n", - "step: 118, Red action: DONOTHING, Blue reward:1.0\n", - "step: 119, Red action: DONOTHING, Blue reward:1.0\n", - "step: 120, Red action: DONOTHING, Blue reward:1.0\n", - "step: 121, Red action: DONOTHING, Blue reward:1.0\n", - "step: 122, Red action: DONOTHING, Blue reward:1.0\n", - "step: 123, Red action: DONOTHING, Blue reward:1.0\n", - "step: 124, Red action: DONOTHING, Blue reward:1.0\n", - "step: 125, Red action: DONOTHING, Blue reward:1.0\n", - "step: 126, Red action: DONOTHING, Blue reward:1.0\n", - "step: 127, Red action: DONOTHING, Blue reward:1.0\n", - "step: 128, Red action: DONOTHING, Blue reward:1.0\n", - "step: 129, Red action: DONOTHING, Blue reward:1.0\n", - "step: 130, Red action: DONOTHING, Blue reward:1.0\n", - "step: 131, Red action: DONOTHING, Blue reward:1.0\n", - "step: 132, Red action: DONOTHING, Blue reward:1.0\n", - "step: 133, Red action: DONOTHING, Blue reward:1.0\n", - "step: 134, Red action: NODE_APPLICATION_EXECUTE, Blue reward:1.0\n", - "step: 135, Red action: DONOTHING, Blue reward:1.0\n", - "step: 136, Red action: DONOTHING, Blue reward:1.0\n" + "step: 37, Red action: DONOTHING, Blue reward:0.0\n", + "step: 38, Red action: DONOTHING, Blue reward:0.0\n", + "step: 39, Red action: DONOTHING, Blue reward:1.0\n", + "step: 40, Red action: DONOTHING, Blue reward:1.0\n", + "step: 41, Red action: DONOTHING, Blue reward:1.0\n", + "step: 42, Red action: DONOTHING, Blue reward:1.0\n", + "step: 43, Red action: DONOTHING, Blue reward:1.0\n", + "step: 44, Red action: DONOTHING, Blue reward:1.0\n", + "step: 45, Red action: DONOTHING, Blue reward:1.0\n", + "step: 46, Red action: NODE_APPLICATION_EXECUTE, Blue reward:1.0\n", + "step: 47, Red action: DONOTHING, Blue reward:1.0\n", + "step: 48, Red action: DONOTHING, Blue reward:1.0\n", + "step: 49, Red action: DONOTHING, Blue reward:1.0\n", + "step: 50, Red action: DONOTHING, Blue reward:1.0\n", + "step: 51, Red action: DONOTHING, Blue reward:1.0\n", + "step: 52, Red action: DONOTHING, Blue reward:1.0\n", + "step: 53, Red action: DONOTHING, Blue reward:1.0\n", + "step: 54, Red action: DONOTHING, Blue reward:1.0\n", + "step: 55, Red action: DONOTHING, Blue reward:1.0\n", + "step: 56, Red action: DONOTHING, Blue reward:1.0\n", + "step: 57, Red action: DONOTHING, Blue reward:1.0\n", + "step: 58, Red action: DONOTHING, Blue reward:1.0\n", + "step: 59, Red action: DONOTHING, Blue reward:1.0\n", + "step: 60, Red action: DONOTHING, Blue reward:1.0\n", + "step: 61, Red action: DONOTHING, Blue reward:1.0\n", + "step: 62, Red action: DONOTHING, Blue reward:1.0\n", + "step: 63, Red action: DONOTHING, Blue reward:1.0\n", + "step: 64, Red action: DONOTHING, Blue reward:1.0\n", + "step: 65, Red action: DONOTHING, Blue reward:1.0\n", + "step: 66, Red action: DONOTHING, Blue reward:1.0\n", + "step: 67, Red action: DONOTHING, Blue reward:1.0\n", + "step: 68, Red action: DONOTHING, Blue reward:1.0\n" ] } ], @@ -823,7 +828,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -901,7 +906,7 @@ " 'protocol': 0}}" ] }, - "execution_count": 24, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } From 7f996ca16acf57c028991af52d79944efde0a2e5 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Jan 2024 14:52:48 +0000 Subject: [PATCH 543/980] Make sure notebook images get copied --- src/primaite/setup/reset_demo_notebooks.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/primaite/setup/reset_demo_notebooks.py b/src/primaite/setup/reset_demo_notebooks.py index a4ee4c4d..bcf89b6a 100644 --- a/src/primaite/setup/reset_demo_notebooks.py +++ b/src/primaite/setup/reset_demo_notebooks.py @@ -44,3 +44,12 @@ def run(overwrite_existing: bool = True) -> None: print(dst_fp) shutil.copy2(src_fp, dst_fp) _LOGGER.info(f"Reset example notebook: {dst_fp}") + + for src_fp in primaite_root.glob("notebooks/_package_data/*"): + dst_fp = example_notebooks_user_dir / "_package_data" / src_fp.name + if should_copy_file(src_fp, dst_fp, overwrite_existing): + if not Path.exists(example_notebooks_user_dir / "_package_data/"): + Path.mkdir(example_notebooks_user_dir / "_package_data/") + print(dst_fp) + shutil.copy2(src_fp, dst_fp) + _LOGGER.info(f"Copied notebook resource to: {dst_fp}") From 5a9eaeb1851c83d42bc69de240d34a137815edba Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Jan 2024 14:59:00 +0000 Subject: [PATCH 544/980] Update the readme --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ec335108..416bd0ec 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Currently, the PrimAITE wheel can only be installed from GitHub. This may change #### Windows (PowerShell) **Prerequisites:** -* Manual install of Python >= 3.8 < 3.11 +* Manual install of Python >= 3.9 < 3.12 **Install:** @@ -56,7 +56,7 @@ primaite session #### Unix **Prerequisites:** -* Manual install of Python >= 3.8 < 3.11 +* Manual install of Python >= 3.9 < 3.12 ``` bash sudo add-apt-repository ppa:deadsnakes/ppa @@ -82,6 +82,7 @@ primaite session ``` + ### Developer Install from Source To make your own changes to PrimAITE, perform the install from source (developer install) @@ -138,3 +139,7 @@ make html cd docs .\make.bat html ``` + + +## Example notebooks +Check out the example notebooks to learn more about how PrimAITE works and how you can use it to train agents. They are automatically copied to your primaite installation directory when you run `primaite setup`. From 0056bfddeea4544bf0b783dfdac1c68e9fd248b8 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Jan 2024 14:59:24 +0000 Subject: [PATCH 545/980] Bump version to 3.0.0b6 --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index 72f12ef8..43662e8c 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0b6dev +3.0.0b6 From 2ba05e73484c5af75b833a17fb4c1b3a9db23339 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Jan 2024 15:17:09 +0000 Subject: [PATCH 546/980] Fixed being unable to specify all addresses in acl rule --- src/primaite/game/agent/actions.py | 18 ++++++++++++------ .../simulator/network/hardware/nodes/router.py | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 6b15c5f8..fa85dbf7 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -453,27 +453,33 @@ class NetworkACLAddRuleAction(AbstractAction): protocol = self.manager.get_internet_protocol_by_idx(protocol_id - 2) # subtract 2 to account for UNUSED=0 and ALL=1. - if source_ip_id in [0, 1]: + if source_ip_id == 0: + return ["do_nothing"] # invalid formulation + elif source_ip_id == 1: src_ip = "ALL" - return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS else: src_ip = self.manager.get_ip_address_by_idx(source_ip_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 - if source_port_id == 1: + if source_port_id == 0: + return ["do_nothing"] # invalid formulation + elif source_port_id == 1: src_port = "ALL" else: src_port = self.manager.get_port_by_idx(source_port_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 - if dest_ip_id in (0, 1): + if source_ip_id == 0: + return ["do_nothing"] # invalid formulation + elif dest_ip_id == 1: dst_ip = "ALL" - return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS else: dst_ip = self.manager.get_ip_address_by_idx(dest_ip_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 - if dest_port_id == 1: + if dest_port_id == 0: + return ["do_nothing"] # invalid formulation + elif dest_port_id == 1: dst_port = "ALL" else: dst_port = self.manager.get_port_by_idx(dest_port_id - 2) diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 41c14967..a17d2ebf 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -162,9 +162,9 @@ class AccessControlList(SimComponent): func=lambda request, context: self.add_rule( ACLAction[request[0]], None if request[1] == "ALL" else IPProtocol[request[1]], - IPv4Address(request[2]), + None if request[2] == "ALL" else IPv4Address(request[2]), None if request[3] == "ALL" else Port[request[3]], - IPv4Address(request[4]), + None if request[4] == "ALL" else IPv4Address(request[4]), None if request[5] == "ALL" else Port[request[5]], int(request[6]), ) From bea72aa6a99cf146bdcd35caf359ee38354fdd26 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 29 Jan 2024 12:28:44 +0000 Subject: [PATCH 547/980] Fix ftp client connection list --- src/primaite/simulator/system/services/ftp/ftp_client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 7faa5d32..39bc57f0 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -89,6 +89,7 @@ class FTPClient(FTPServiceABC): f"{self.name}: Successfully connected to FTP Server " f"{dest_ip_address} via port {payload.ftp_command_args.value}" ) + self.add_connection(connection_id="server_connection", session_id=session_id) return True else: if is_reattempt: From def52f94e3a708898ac815c80d2133a98dc16d4b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 30 Jan 2024 09:56:16 +0000 Subject: [PATCH 548/980] Add docstrings and update typos --- README.md | 4 ++-- src/primaite/simulator/file_system/folder.py | 1 - .../system/services/database/database_service.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 416bd0ec..7dfe15bd 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Currently, the PrimAITE wheel can only be installed from GitHub. This may change #### Windows (PowerShell) **Prerequisites:** -* Manual install of Python >= 3.9 < 3.12 +* Manual install of Python >= 3.8 < 3.12 **Install:** @@ -56,7 +56,7 @@ primaite session #### Unix **Prerequisites:** -* Manual install of Python >= 3.9 < 3.12 +* Manual install of Python >= 3.8 < 3.12 ``` bash sudo add-apt-repository ppa:deadsnakes/ppa diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index ab862898..dae32cd5 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -276,7 +276,6 @@ class Folder(FileSystemItemABC): self.deleted_files[file.uuid] = file file.delete() self.sys_log.info(f"Removed file {file.name} (id: {file.uuid})") - # self._file_request_manager.remove_request(file.uuid) else: _LOGGER.debug(f"File with UUID {file.uuid} was not found.") diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index a7c2bb69..c9c4d6fa 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -151,6 +151,15 @@ class DatabaseService(Service): def _process_connect( self, connection_id: str, password: Optional[str] = None ) -> Dict[str, Union[int, Dict[str, bool]]]: + """Process an incoming connection request. + + :param connection_id: A unique identifier for the connection + :type connection_id: str + :param password: Supplied password. It must match self.password for connection success, defaults to None + :type password: Optional[str], optional + :return: Response to connection request containing success info. + :rtype: Dict[str, Union[int, Dict[str, bool]]] + """ status_code = 500 # Default internal server error if self.operating_state == ServiceOperatingState.RUNNING: status_code = 503 # service unavailable @@ -279,6 +288,7 @@ class DatabaseService(Service): return super().apply_timestep(timestep) def _update_patch_status(self) -> None: + """Perform a database restore when the patching countdown is finished.""" super()._update_patch_status() if self._patching_countdown is None: self.restore_backup() From 9f993dda5746aaea0e19466eeb1045f0ce53cba2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 31 Jan 2024 10:48:40 +0000 Subject: [PATCH 549/980] Fix test config discrepancies --- .../config/_package_data/example_config.yaml | 16 +- src/primaite/game/agent/actions.py | 16 +- .../assets/configs/bad_primaite_session.yaml | 221 +++++---- .../configs/eval_only_primaite_session.yaml | 217 +++++---- tests/assets/configs/multi_agent_session.yaml | 433 +++++++++--------- .../assets/configs/test_primaite_session.yaml | 220 +++++---- .../configs/train_only_primaite_session.yaml | 218 +++++---- 7 files changed, 660 insertions(+), 681 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 68aa9106..7a286931 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -508,21 +508,21 @@ agents: max_nics_per_node: 8 max_acl_rules: 10 ip_address_order: - - node_ref: domain_controller + - node_name: domain_controller nic_num: 1 - - node_ref: web_server + - node_name: web_server nic_num: 1 - - node_ref: database_server + - node_name: database_server nic_num: 1 - - node_ref: backup_server + - node_name: backup_server nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 1 - - node_ref: client_1 + - node_name: client_1 nic_num: 1 - - node_ref: client_2 + - node_name: client_2 nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 2 diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 40c40077..3b1fb926 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -298,13 +298,13 @@ class NodeFileDeleteAction(NodeFileAbstractAction): def form_request(self, node_id: int, folder_id: int, file_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" - node_uuid = self.manager.get_node_uuid_by_idx(node_id) - folder_uuid = self.manager.get_folder_uuid_by_idx(node_idx=node_id, folder_idx=folder_id) - file_uuid = self.manager.get_file_uuid_by_idx(node_idx=node_id, folder_idx=folder_id, file_idx=file_id) - if node_uuid is None or folder_uuid is None or file_uuid is None: + node_name = self.manager.get_node_name_by_idx(node_id) + folder_name = self.manager.get_folder_name_by_idx(node_idx=node_id, folder_idx=folder_id) + file_name = self.manager.get_file_name_by_idx(node_idx=node_id, folder_idx=folder_id, file_idx=file_id) + if node_name is None or folder_name is None or file_name is None: return ["do_nothing"] return ["do_nothing"] - # return ["network", "node", node_uuid, "file_system", "delete", "file", folder_uuid, file_uuid] + # return ["network", "node", node_name, "file_system", "delete", "file", folder_name, file_name] class NodeFileRepairAction(NodeFileAbstractAction): @@ -849,7 +849,7 @@ class ActionManager: return self.folder_names[node_idx][folder_idx] def get_file_name_by_idx(self, node_idx: int, folder_idx: int, file_idx: int) -> Optional[str]: - """Get the file UUID corresponding to the given node, folder, and file indices. + """Get the file name corresponding to the given node, folder, and file indices. :param node_idx: The index of the node. :type node_idx: int @@ -962,9 +962,9 @@ class ActionManager: ip_address_order = cfg["options"].pop("ip_address_order", {}) ip_address_list = [] for entry in ip_address_order: - node_ref = entry["node_ref"] + node_name = entry["node_name"] nic_num = entry["nic_num"] - node_obj = game.simulation.network.get_node_by_hostname(node_ref) + node_obj = game.simulation.network.get_node_by_hostname(node_name) ip_address = node_obj.ethernet_port[nic_num].ip_address ip_address_list.append(ip_address) diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 3e9be3bb..f5d7850c 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -29,7 +29,7 @@ agents: - type: DONOTHING options: nodes: - - node_hostname: client_2 + - node_name: client_2 max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -64,7 +64,7 @@ agents: - type: NODE_OS_SCAN options: nodes: - - node_hostname: client_1 + - node_name: client_1 applications: - application_name: data_manipulation_bot max_folders_per_node: 1 @@ -185,168 +185,167 @@ agents: 1: action: NODE_SERVICE_SCAN options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # stop webapp service 2: action: NODE_SERVICE_STOP options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # start webapp service 3: action: "NODE_SERVICE_START" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 4: action: "NODE_SERVICE_PAUSE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 5: action: "NODE_SERVICE_RESUME" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 6: action: "NODE_SERVICE_RESTART" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 7: action: "NODE_SERVICE_DISABLE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 8: action: "NODE_SERVICE_ENABLE" options: - node_id: 2 - service_id: 1 - 9: + node_id: 1 + service_id: 0 + 9: # check database.db file action: "NODE_FILE_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 11: action: "NODE_FILE_DELETE" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 12: action: "NODE_FILE_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 13: - action: "NODE_FILE_RESTORE" + action: "NODE_SERVICE_PATCH" options: - node_id: 3 - folder_id: 1 - file_id: 1 + node_id: 2 + service_id: 0 14: action: "NODE_FOLDER_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 15: action: "NODE_FOLDER_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 16: action: "NODE_FOLDER_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 17: action: "NODE_FOLDER_RESTORE" options: - node_id: 3 + node_id: 2 folder_id: 1 18: action: "NODE_OS_SCAN" options: - node_id: 3 - 19: + node_id: 2 + 19: # shutdown client 1 action: "NODE_SHUTDOWN" options: - node_id: 6 + node_id: 5 20: action: "NODE_STARTUP" options: - node_id: 6 + node_id: 5 21: action: "NODE_RESET" options: - node_id: 6 - 22: + node_id: 5 + 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: position: 1 permission: 2 - source_ip_id: 7 - dest_ip_id: 1 + source_ip_id: 7 # client 1 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: + 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 2 permission: 2 - source_ip_id: 8 - dest_ip_id: 1 + source_ip_id: 8 # client 2 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 24: + 24: # block tcp traffic from client 1 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 3 permission: 2 - source_ip_id: 7 - dest_ip_id: 3 + source_ip_id: 7 # client 1 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 25: + 25: # block tcp traffic from client 2 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 4 permission: 2 - source_ip_id: 8 - dest_ip_id: 3 + source_ip_id: 8 # client 2 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 26: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 5 permission: 2 - source_ip_id: 7 - dest_ip_id: 4 + source_ip_id: 7 # client 1 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 27: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 6 permission: 2 - source_ip_id: 8 - dest_ip_id: 4 + source_ip_id: 8 # client 2 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 @@ -393,118 +392,116 @@ agents: 38: action: "NETWORK_NIC_DISABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 39: action: "NETWORK_NIC_ENABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 40: action: "NETWORK_NIC_DISABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 41: action: "NETWORK_NIC_ENABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 42: action: "NETWORK_NIC_DISABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 43: action: "NETWORK_NIC_ENABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 44: action: "NETWORK_NIC_DISABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 45: action: "NETWORK_NIC_ENABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 46: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 47: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 48: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 49: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 50: action: "NETWORK_NIC_DISABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 51: action: "NETWORK_NIC_ENABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 52: action: "NETWORK_NIC_DISABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 53: action: "NETWORK_NIC_ENABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 + options: nodes: - - node_hostname: router_1 - - node_hostname: switch_1 - - node_hostname: switch_2 - - node_hostname: domain_controller - - node_hostname: web_server - - node_hostname: database_server - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 + - node_name: domain_controller + - node_name: web_server + - node_name: database_server + - node_name: backup_server + - node_name: security_suite + - node_name: client_1 + - node_name: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 ip_address_order: - - node_ref: domain_controller + - node_name: domain_controller nic_num: 1 - - node_ref: web_server + - node_name: web_server nic_num: 1 - - node_ref: database_server + - node_name: database_server nic_num: 1 - - node_ref: backup_server + - node_name: backup_server nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 1 - - node_ref: client_1 + - node_name: client_1 nic_num: 1 - - node_ref: client_2 + - node_name: client_2 nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 2 reward_function: @@ -622,7 +619,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: backup_service - type: DatabaseBackup + type: FTPServer - ref: security_suite type: server diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index 0c3872b0..b46c2f8d 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -69,7 +69,7 @@ agents: - type: NODE_OS_SCAN options: nodes: - - node_hostname: client_1 + - node_name: client_1 applications: - application_name: data_manipulation_bot max_folders_per_node: 1 @@ -189,168 +189,167 @@ agents: 1: action: NODE_SERVICE_SCAN options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # stop webapp service 2: action: NODE_SERVICE_STOP options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # start webapp service 3: action: "NODE_SERVICE_START" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 4: action: "NODE_SERVICE_PAUSE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 5: action: "NODE_SERVICE_RESUME" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 6: action: "NODE_SERVICE_RESTART" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 7: action: "NODE_SERVICE_DISABLE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 8: action: "NODE_SERVICE_ENABLE" options: - node_id: 2 - service_id: 1 - 9: + node_id: 1 + service_id: 0 + 9: # check database.db file action: "NODE_FILE_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 11: action: "NODE_FILE_DELETE" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 12: action: "NODE_FILE_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 13: - action: "NODE_FILE_RESTORE" + action: "NODE_SERVICE_PATCH" options: - node_id: 3 - folder_id: 1 - file_id: 1 + node_id: 2 + service_id: 0 14: action: "NODE_FOLDER_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 15: action: "NODE_FOLDER_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 16: action: "NODE_FOLDER_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 17: action: "NODE_FOLDER_RESTORE" options: - node_id: 3 + node_id: 2 folder_id: 1 18: action: "NODE_OS_SCAN" options: - node_id: 3 - 19: + node_id: 2 + 19: # shutdown client 1 action: "NODE_SHUTDOWN" options: - node_id: 6 + node_id: 5 20: action: "NODE_STARTUP" options: - node_id: 6 + node_id: 5 21: action: "NODE_RESET" options: - node_id: 6 - 22: + node_id: 5 + 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: position: 1 permission: 2 - source_ip_id: 7 - dest_ip_id: 1 + source_ip_id: 7 # client 1 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: + 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 2 permission: 2 - source_ip_id: 8 - dest_ip_id: 1 + source_ip_id: 8 # client 2 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 24: + 24: # block tcp traffic from client 1 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 3 permission: 2 - source_ip_id: 7 - dest_ip_id: 3 + source_ip_id: 7 # client 1 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 25: + 25: # block tcp traffic from client 2 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 4 permission: 2 - source_ip_id: 8 - dest_ip_id: 3 + source_ip_id: 8 # client 2 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 26: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 5 permission: 2 - source_ip_id: 7 - dest_ip_id: 4 + source_ip_id: 7 # client 1 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 27: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 6 permission: 2 - source_ip_id: 8 - dest_ip_id: 4 + source_ip_id: 8 # client 2 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 @@ -397,118 +396,116 @@ agents: 38: action: "NETWORK_NIC_DISABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 39: action: "NETWORK_NIC_ENABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 40: action: "NETWORK_NIC_DISABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 41: action: "NETWORK_NIC_ENABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 42: action: "NETWORK_NIC_DISABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 43: action: "NETWORK_NIC_ENABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 44: action: "NETWORK_NIC_DISABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 45: action: "NETWORK_NIC_ENABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 46: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 47: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 48: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 49: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 50: action: "NETWORK_NIC_DISABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 51: action: "NETWORK_NIC_ENABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 52: action: "NETWORK_NIC_DISABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 53: action: "NETWORK_NIC_ENABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 + options: nodes: - - node_hostname: router_1 - - node_hostname: switch_1 - - node_hostname: switch_2 - - node_hostname: domain_controller - - node_hostname: web_server - - node_hostname: database_server - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 + - node_name: domain_controller + - node_name: web_server + - node_name: database_server + - node_name: backup_server + - node_name: security_suite + - node_name: client_1 + - node_name: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 ip_address_order: - - node_ref: domain_controller + - node_name: domain_controller nic_num: 1 - - node_ref: web_server + - node_name: web_server nic_num: 1 - - node_ref: database_server + - node_name: database_server nic_num: 1 - - node_ref: backup_server + - node_name: backup_server nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 1 - - node_ref: client_1 + - node_name: client_1 nic_num: 1 - - node_ref: client_2 + - node_name: client_2 nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 2 reward_function: diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 87bcc14f..23bd46c2 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -40,7 +40,7 @@ agents: options: nodes: - - node_hostname: client_2 + - node_name: client_2 max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -75,7 +75,7 @@ agents: - type: NODE_OS_SCAN options: nodes: - - node_hostname: client_1 + - node_name: client_1 applications: - application_name: data_manipulation_bot max_folders_per_node: 1 @@ -196,168 +196,167 @@ agents: 1: action: NODE_SERVICE_SCAN options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # stop webapp service 2: action: NODE_SERVICE_STOP options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # start webapp service 3: action: "NODE_SERVICE_START" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 4: action: "NODE_SERVICE_PAUSE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 5: action: "NODE_SERVICE_RESUME" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 6: action: "NODE_SERVICE_RESTART" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 7: action: "NODE_SERVICE_DISABLE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 8: action: "NODE_SERVICE_ENABLE" options: - node_id: 2 - service_id: 1 - 9: + node_id: 1 + service_id: 0 + 9: # check database.db file action: "NODE_FILE_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 11: action: "NODE_FILE_DELETE" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 12: action: "NODE_FILE_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 13: - action: "NODE_FILE_RESTORE" + action: "NODE_SERVICE_PATCH" options: - node_id: 3 - folder_id: 1 - file_id: 1 + node_id: 2 + service_id: 0 14: action: "NODE_FOLDER_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 15: action: "NODE_FOLDER_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 16: action: "NODE_FOLDER_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 17: action: "NODE_FOLDER_RESTORE" options: - node_id: 3 + node_id: 2 folder_id: 1 18: action: "NODE_OS_SCAN" options: - node_id: 3 - 19: + node_id: 2 + 19: # shutdown client 1 action: "NODE_SHUTDOWN" options: - node_id: 6 + node_id: 5 20: action: "NODE_STARTUP" options: - node_id: 6 + node_id: 5 21: action: "NODE_RESET" options: - node_id: 6 - 22: + node_id: 5 + 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: position: 1 permission: 2 - source_ip_id: 7 - dest_ip_id: 1 + source_ip_id: 7 # client 1 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: + 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 2 permission: 2 - source_ip_id: 8 - dest_ip_id: 1 + source_ip_id: 8 # client 2 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 24: + 24: # block tcp traffic from client 1 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 3 permission: 2 - source_ip_id: 7 - dest_ip_id: 3 + source_ip_id: 7 # client 1 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 25: + 25: # block tcp traffic from client 2 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 4 permission: 2 - source_ip_id: 8 - dest_ip_id: 3 + source_ip_id: 8 # client 2 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 26: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 5 permission: 2 - source_ip_id: 7 - dest_ip_id: 4 + source_ip_id: 7 # client 1 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 27: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 6 permission: 2 - source_ip_id: 8 - dest_ip_id: 4 + source_ip_id: 8 # client 2 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 @@ -404,118 +403,116 @@ agents: 38: action: "NETWORK_NIC_DISABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 39: action: "NETWORK_NIC_ENABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 40: action: "NETWORK_NIC_DISABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 41: action: "NETWORK_NIC_ENABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 42: action: "NETWORK_NIC_DISABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 43: action: "NETWORK_NIC_ENABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 44: action: "NETWORK_NIC_DISABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 45: action: "NETWORK_NIC_ENABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 46: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 47: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 48: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 49: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 50: action: "NETWORK_NIC_DISABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 51: action: "NETWORK_NIC_ENABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 52: action: "NETWORK_NIC_DISABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 53: action: "NETWORK_NIC_ENABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 + options: nodes: - - node_hostname: router_1 - - node_hostname: switch_1 - - node_hostname: switch_2 - - node_hostname: domain_controller - - node_hostname: web_server - - node_hostname: database_server - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 + - node_name: domain_controller + - node_name: web_server + - node_name: database_server + - node_name: backup_server + - node_name: security_suite + - node_name: client_1 + - node_name: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 ip_address_order: - - node_ref: domain_controller + - node_name: domain_controller nic_num: 1 - - node_ref: web_server + - node_name: web_server nic_num: 1 - - node_ref: database_server + - node_name: database_server nic_num: 1 - - node_ref: backup_server + - node_name: backup_server nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 1 - - node_ref: client_1 + - node_name: client_1 nic_num: 1 - - node_ref: client_2 + - node_name: client_2 nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 2 reward_function: @@ -642,168 +639,167 @@ agents: 1: action: NODE_SERVICE_SCAN options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # stop webapp service 2: action: NODE_SERVICE_STOP options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # start webapp service 3: action: "NODE_SERVICE_START" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 4: action: "NODE_SERVICE_PAUSE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 5: action: "NODE_SERVICE_RESUME" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 6: action: "NODE_SERVICE_RESTART" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 7: action: "NODE_SERVICE_DISABLE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 8: action: "NODE_SERVICE_ENABLE" options: - node_id: 2 - service_id: 1 - 9: + node_id: 1 + service_id: 0 + 9: # check database.db file action: "NODE_FILE_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 11: action: "NODE_FILE_DELETE" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 12: action: "NODE_FILE_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 13: - action: "NODE_FILE_RESTORE" + action: "NODE_SERVICE_PATCH" options: - node_id: 3 - folder_id: 1 - file_id: 1 + node_id: 2 + service_id: 0 14: action: "NODE_FOLDER_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 15: action: "NODE_FOLDER_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 16: action: "NODE_FOLDER_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 17: action: "NODE_FOLDER_RESTORE" options: - node_id: 3 + node_id: 2 folder_id: 1 18: action: "NODE_OS_SCAN" options: - node_id: 3 - 19: + node_id: 2 + 19: # shutdown client 1 action: "NODE_SHUTDOWN" options: - node_id: 6 + node_id: 5 20: action: "NODE_STARTUP" options: - node_id: 6 + node_id: 5 21: action: "NODE_RESET" options: - node_id: 6 - 22: + node_id: 5 + 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: position: 1 permission: 2 - source_ip_id: 7 - dest_ip_id: 1 + source_ip_id: 7 # client 1 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: + 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 2 permission: 2 - source_ip_id: 8 - dest_ip_id: 1 + source_ip_id: 8 # client 2 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 24: + 24: # block tcp traffic from client 1 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 3 permission: 2 - source_ip_id: 7 - dest_ip_id: 3 + source_ip_id: 7 # client 1 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 25: + 25: # block tcp traffic from client 2 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 4 permission: 2 - source_ip_id: 8 - dest_ip_id: 3 + source_ip_id: 8 # client 2 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 26: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 5 permission: 2 - source_ip_id: 7 - dest_ip_id: 4 + source_ip_id: 7 # client 1 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 27: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 6 permission: 2 - source_ip_id: 8 - dest_ip_id: 4 + source_ip_id: 8 # client 2 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 @@ -850,118 +846,115 @@ agents: 38: action: "NETWORK_NIC_DISABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 39: action: "NETWORK_NIC_ENABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 40: action: "NETWORK_NIC_DISABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 41: action: "NETWORK_NIC_ENABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 42: action: "NETWORK_NIC_DISABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 43: action: "NETWORK_NIC_ENABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 44: action: "NETWORK_NIC_DISABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 45: action: "NETWORK_NIC_ENABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 46: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 47: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 48: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 49: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 50: action: "NETWORK_NIC_DISABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 51: action: "NETWORK_NIC_ENABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 52: action: "NETWORK_NIC_DISABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 53: action: "NETWORK_NIC_ENABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 options: nodes: - - node_hostname: router_1 - - node_hostname: switch_1 - - node_hostname: switch_2 - - node_hostname: domain_controller - - node_hostname: web_server - - node_hostname: database_server - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 + - node_name: domain_controller + - node_name: web_server + - node_name: database_server + - node_name: backup_server + - node_name: security_suite + - node_name: client_1 + - node_name: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 ip_address_order: - - node_ref: domain_controller + - node_name: domain_controller nic_num: 1 - - node_ref: web_server + - node_name: web_server nic_num: 1 - - node_ref: database_server + - node_name: database_server nic_num: 1 - - node_ref: backup_server + - node_name: backup_server nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 1 - - node_ref: client_1 + - node_name: client_1 nic_num: 1 - - node_ref: client_2 + - node_name: client_2 nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 2 reward_function: diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 84b1c15f..1aa6ad71 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -38,7 +38,7 @@ agents: options: nodes: - - node_hostname: client_2 + - node_name: client_2 max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -73,9 +73,9 @@ agents: - type: NODE_OS_SCAN options: nodes: - - node_hostname: client_1 + - node_name: client_1 applications: - - application_hostname: data_manipulation_bot + - application_name: data_manipulation_bot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -196,168 +196,167 @@ agents: 1: action: NODE_SERVICE_SCAN options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # stop webapp service 2: action: NODE_SERVICE_STOP options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # start webapp service 3: action: "NODE_SERVICE_START" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 4: action: "NODE_SERVICE_PAUSE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 5: action: "NODE_SERVICE_RESUME" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 6: action: "NODE_SERVICE_RESTART" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 7: action: "NODE_SERVICE_DISABLE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 8: action: "NODE_SERVICE_ENABLE" options: - node_id: 2 - service_id: 1 - 9: + node_id: 1 + service_id: 0 + 9: # check database.db file action: "NODE_FILE_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 11: action: "NODE_FILE_DELETE" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 12: action: "NODE_FILE_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 13: - action: "NODE_FILE_RESTORE" + action: "NODE_SERVICE_PATCH" options: - node_id: 3 - folder_id: 1 - file_id: 1 + node_id: 2 + service_id: 0 14: action: "NODE_FOLDER_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 15: action: "NODE_FOLDER_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 16: action: "NODE_FOLDER_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 17: action: "NODE_FOLDER_RESTORE" options: - node_id: 3 + node_id: 2 folder_id: 1 18: action: "NODE_OS_SCAN" options: - node_id: 3 - 19: + node_id: 2 + 19: # shutdown client 1 action: "NODE_SHUTDOWN" options: - node_id: 6 + node_id: 5 20: action: "NODE_STARTUP" options: - node_id: 6 + node_id: 5 21: action: "NODE_RESET" options: - node_id: 6 - 22: + node_id: 5 + 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: position: 1 permission: 2 - source_ip_id: 7 - dest_ip_id: 1 + source_ip_id: 7 # client 1 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: + 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 2 permission: 2 - source_ip_id: 8 - dest_ip_id: 1 + source_ip_id: 8 # client 2 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 24: + 24: # block tcp traffic from client 1 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 3 permission: 2 - source_ip_id: 7 - dest_ip_id: 3 + source_ip_id: 7 # client 1 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 25: + 25: # block tcp traffic from client 2 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 4 permission: 2 - source_ip_id: 8 - dest_ip_id: 3 + source_ip_id: 8 # client 2 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 26: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 5 permission: 2 - source_ip_id: 7 - dest_ip_id: 4 + source_ip_id: 7 # client 1 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 27: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 6 permission: 2 - source_ip_id: 8 - dest_ip_id: 4 + source_ip_id: 8 # client 2 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 @@ -404,118 +403,115 @@ agents: 38: action: "NETWORK_NIC_DISABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 39: action: "NETWORK_NIC_ENABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 40: action: "NETWORK_NIC_DISABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 41: action: "NETWORK_NIC_ENABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 42: action: "NETWORK_NIC_DISABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 43: action: "NETWORK_NIC_ENABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 44: action: "NETWORK_NIC_DISABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 45: action: "NETWORK_NIC_ENABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 46: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 47: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 48: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 49: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 50: action: "NETWORK_NIC_DISABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 51: action: "NETWORK_NIC_ENABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 52: action: "NETWORK_NIC_DISABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 53: action: "NETWORK_NIC_ENABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 options: nodes: - - node_hostname: router_1 - - node_hostname: switch_1 - - node_hostname: switch_2 - - node_hostname: domain_controller - - node_hostname: web_server - - node_hostname: database_server - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 + - node_name: domain_controller + - node_name: web_server + - node_name: database_server + - node_name: backup_server + - node_name: security_suite + - node_name: client_1 + - node_name: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 ip_address_order: - - node_ref: domain_controller + - node_name: domain_controller nic_num: 1 - - node_ref: web_server + - node_name: web_server nic_num: 1 - - node_ref: database_server + - node_name: database_server nic_num: 1 - - node_ref: backup_server + - node_name: backup_server nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 1 - - node_ref: client_1 + - node_name: client_1 nic_num: 1 - - node_ref: client_2 + - node_name: client_2 nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 2 reward_function: diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index 62826cd4..115b6c85 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -41,7 +41,7 @@ agents: options: nodes: - - node_hostname: client_2 + - node_name: client_2 max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -76,7 +76,7 @@ agents: - type: NODE_OS_SCAN options: nodes: - - node_hostname: client_1 + - node_name: client_1 applications: - application_name: data_manipulation_bot max_folders_per_node: 1 @@ -197,168 +197,167 @@ agents: 1: action: NODE_SERVICE_SCAN options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # stop webapp service 2: action: NODE_SERVICE_STOP options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 # start webapp service 3: action: "NODE_SERVICE_START" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 4: action: "NODE_SERVICE_PAUSE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 5: action: "NODE_SERVICE_RESUME" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 6: action: "NODE_SERVICE_RESTART" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 7: action: "NODE_SERVICE_DISABLE" options: - node_id: 2 - service_id: 1 + node_id: 1 + service_id: 0 8: action: "NODE_SERVICE_ENABLE" options: - node_id: 2 - service_id: 1 - 9: + node_id: 1 + service_id: 0 + 9: # check database.db file action: "NODE_FILE_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 11: action: "NODE_FILE_DELETE" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 12: action: "NODE_FILE_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 - file_id: 1 + file_id: 0 13: - action: "NODE_FILE_RESTORE" + action: "NODE_SERVICE_PATCH" options: - node_id: 3 - folder_id: 1 - file_id: 1 + node_id: 2 + service_id: 0 14: action: "NODE_FOLDER_SCAN" options: - node_id: 3 + node_id: 2 folder_id: 1 15: action: "NODE_FOLDER_CHECKHASH" options: - node_id: 3 + node_id: 2 folder_id: 1 16: action: "NODE_FOLDER_REPAIR" options: - node_id: 3 + node_id: 2 folder_id: 1 17: action: "NODE_FOLDER_RESTORE" options: - node_id: 3 + node_id: 2 folder_id: 1 18: action: "NODE_OS_SCAN" options: - node_id: 3 - 19: + node_id: 2 + 19: # shutdown client 1 action: "NODE_SHUTDOWN" options: - node_id: 6 + node_id: 5 20: action: "NODE_STARTUP" options: - node_id: 6 + node_id: 5 21: action: "NODE_RESET" options: - node_id: 6 - 22: + node_id: 5 + 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: position: 1 permission: 2 - source_ip_id: 7 - dest_ip_id: 1 + source_ip_id: 7 # client 1 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: + 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 2 permission: 2 - source_ip_id: 8 - dest_ip_id: 1 + source_ip_id: 8 # client 2 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 24: + 24: # block tcp traffic from client 1 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 3 permission: 2 - source_ip_id: 7 - dest_ip_id: 3 + source_ip_id: 7 # client 1 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 25: + 25: # block tcp traffic from client 2 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 4 permission: 2 - source_ip_id: 8 - dest_ip_id: 3 + source_ip_id: 8 # client 2 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 26: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 5 permission: 2 - source_ip_id: 7 - dest_ip_id: 4 + source_ip_id: 7 # client 1 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 27: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 6 permission: 2 - source_ip_id: 8 - dest_ip_id: 4 + source_ip_id: 8 # client 2 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 @@ -405,118 +404,115 @@ agents: 38: action: "NETWORK_NIC_DISABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 39: action: "NETWORK_NIC_ENABLE" options: - node_id: 1 - nic_id: 1 + node_id: 0 + nic_id: 0 40: action: "NETWORK_NIC_DISABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 41: action: "NETWORK_NIC_ENABLE" options: - node_id: 2 - nic_id: 1 + node_id: 1 + nic_id: 0 42: action: "NETWORK_NIC_DISABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 43: action: "NETWORK_NIC_ENABLE" options: - node_id: 3 - nic_id: 1 + node_id: 2 + nic_id: 0 44: action: "NETWORK_NIC_DISABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 45: action: "NETWORK_NIC_ENABLE" options: - node_id: 4 - nic_id: 1 + node_id: 3 + nic_id: 0 46: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 47: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 1 + node_id: 4 + nic_id: 0 48: action: "NETWORK_NIC_DISABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 49: action: "NETWORK_NIC_ENABLE" options: - node_id: 5 - nic_id: 2 + node_id: 4 + nic_id: 1 50: action: "NETWORK_NIC_DISABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 51: action: "NETWORK_NIC_ENABLE" options: - node_id: 6 - nic_id: 1 + node_id: 5 + nic_id: 0 52: action: "NETWORK_NIC_DISABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 53: action: "NETWORK_NIC_ENABLE" options: - node_id: 7 - nic_id: 1 + node_id: 6 + nic_id: 0 options: nodes: - - node_hostname: router_1 - - node_hostname: switch_1 - - node_hostname: switch_2 - - node_hostname: domain_controller - - node_hostname: web_server - - node_hostname: database_server - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 + - node_name: domain_controller + - node_name: web_server + - node_name: database_server + - node_name: backup_server + - node_name: security_suite + - node_name: client_1 + - node_name: client_2 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 ip_address_order: - - node_ref: domain_controller + - node_name: domain_controller nic_num: 1 - - node_ref: web_server + - node_name: web_server nic_num: 1 - - node_ref: database_server + - node_name: database_server nic_num: 1 - - node_ref: backup_server + - node_name: backup_server nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 1 - - node_ref: client_1 + - node_name: client_1 nic_num: 1 - - node_ref: client_2 + - node_name: client_2 nic_num: 1 - - node_ref: security_suite + - node_name: security_suite nic_num: 2 reward_function: From 6aa6383fb73bdecae063f20f14f4d7204baeb5e8 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 31 Jan 2024 11:44:56 +0000 Subject: [PATCH 550/980] Fix broken test configs --- tests/assets/configs/bad_primaite_session.yaml | 3 ++- tests/assets/configs/eval_only_primaite_session.yaml | 3 ++- tests/assets/configs/multi_agent_session.yaml | 4 +++- tests/assets/configs/test_primaite_session.yaml | 3 ++- tests/assets/configs/train_only_primaite_session.yaml | 3 ++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index f5d7850c..552351b2 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -66,7 +66,7 @@ agents: nodes: - node_name: client_1 applications: - - application_name: data_manipulation_bot + - application_name: DataManipulationBot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -155,6 +155,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE + - type: NODE_SERVICE_PATCH - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index b46c2f8d..d49562c8 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -71,7 +71,7 @@ agents: nodes: - node_name: client_1 applications: - - application_name: data_manipulation_bot + - application_name: DataManipulationBot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -159,6 +159,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE + - type: NODE_SERVICE_PATCH - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 23bd46c2..29f0ae7f 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -77,7 +77,7 @@ agents: nodes: - node_name: client_1 applications: - - application_name: data_manipulation_bot + - application_name: DataManipulationBot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -166,6 +166,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE + - type: NODE_SERVICE_PATCH - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -609,6 +610,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE + - type: NODE_SERVICE_PATCH - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 1aa6ad71..0c70840d 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -75,7 +75,7 @@ agents: nodes: - node_name: client_1 applications: - - application_name: data_manipulation_bot + - application_name: DataManipulationBot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -166,6 +166,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE + - type: NODE_SERVICE_PATCH - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index 115b6c85..0466a5ac 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -78,7 +78,7 @@ agents: nodes: - node_name: client_1 applications: - - application_name: data_manipulation_bot + - application_name: DataManipulationBot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -167,6 +167,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE + - type: NODE_SERVICE_PATCH - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE From d6a83fd1fb33140b3f4b3952069d1c4c3889c606 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 31 Jan 2024 11:55:38 +0000 Subject: [PATCH 551/980] Update action tests to use name, not uuid --- src/primaite/simulator/network/container.py | 6 +++--- .../test_action_integration.py | 4 +--- .../_simulator/_file_system/test_file_actions.py | 16 ++++++++-------- .../_file_system/test_folder_actions.py | 16 ++++++++-------- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 1dadd9e2..8989a60f 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -260,7 +260,7 @@ class Network(SimComponent): :type node: Node """ if node not in self: - _LOGGER.warning(f"Can't remove node {node.uuid}. It's not in the network.") + _LOGGER.warning(f"Can't remove node {node.hostname}. It's not in the network.") return self.nodes.pop(node.uuid) for i, _node in self._node_id_map.items(): @@ -268,8 +268,8 @@ class Network(SimComponent): self._node_id_map.pop(i) break node.parent = None - _LOGGER.info(f"Removed node {node.uuid} from network {self.uuid}") - self._node_request_manager.remove_request(name=node.uuid) + self._node_request_manager.remove_request(name=node.hostname) + _LOGGER.info(f"Removed node {node.hostname} from network {self.uuid}") def connect( self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs diff --git a/tests/integration_tests/component_creation/test_action_integration.py b/tests/integration_tests/component_creation/test_action_integration.py index a2be923b..b506544d 100644 --- a/tests/integration_tests/component_creation/test_action_integration.py +++ b/tests/integration_tests/component_creation/test_action_integration.py @@ -48,8 +48,6 @@ def test_passing_actions_down(monkeypatch) -> None: assert not action_invoked # call the patched method - sim.apply_request( - ["network", "node", pc1.uuid, "file_system", "folder", pc1.file_system.get_folder("downloads").uuid, "repair"] - ) + sim.apply_request(["network", "node", pc1.hostname, "file_system", "folder", "downloads", "repair"]) assert action_invoked diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py index 8590153a..f43652d8 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py @@ -35,12 +35,12 @@ def test_file_checkhash_request(populated_file_system): """Test that an agent can request a file hash check.""" fs, folder, file = populated_file_system - fs.apply_request(request=["file", file.uuid, "checkhash"]) + fs.apply_request(request=["file", file.name, "checkhash"]) assert file.health_status == FileSystemItemHealthStatus.GOOD file.sim_size = 0 - fs.apply_request(request=["file", file.uuid, "checkhash"]) + fs.apply_request(request=["file", file.name, "checkhash"]) assert file.health_status == FileSystemItemHealthStatus.CORRUPT @@ -52,7 +52,7 @@ def test_file_repair_request(populated_file_system): file.corrupt() assert file.health_status == FileSystemItemHealthStatus.CORRUPT - fs.apply_request(request=["file", file.uuid, "repair"]) + fs.apply_request(request=["file", file.name, "repair"]) assert file.health_status == FileSystemItemHealthStatus.GOOD @@ -69,7 +69,7 @@ def test_file_restore_request(populated_file_system): assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None assert fs.get_file(folder_name=folder.name, file_name=file.name).deleted is False - fs.apply_request(request=["file", file.uuid, "corrupt"]) + fs.apply_request(request=["file", file.name, "corrupt"]) assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT fs.apply_request(request=["restore", "file", folder.uuid, file.uuid]) @@ -79,7 +79,7 @@ def test_file_restore_request(populated_file_system): def test_file_corrupt_request(populated_file_system): """Test that an agent can request a file corruption.""" fs, folder, file = populated_file_system - fs.apply_request(request=["file", file.uuid, "corrupt"]) + fs.apply_request(request=["file", file.name, "corrupt"]) assert file.health_status == FileSystemItemHealthStatus.CORRUPT @@ -88,7 +88,7 @@ def test_deleted_file_cannot_be_interacted_with(populated_file_system): fs, folder, file = populated_file_system assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None - fs.apply_request(request=["file", file.uuid, "corrupt"]) + fs.apply_request(request=["file", file.name, "corrupt"]) assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT assert ( fs.get_file(folder_name=folder.name, file_name=file.name).visible_health_status @@ -98,8 +98,8 @@ def test_deleted_file_cannot_be_interacted_with(populated_file_system): fs.apply_request(request=["delete", "file", folder.uuid, file.uuid]) assert fs.get_file(folder_name=folder.name, file_name=file.name) is None - fs.apply_request(request=["file", file.uuid, "repair"]) - fs.apply_request(request=["file", file.uuid, "scan"]) + fs.apply_request(request=["file", file.name, "repair"]) + fs.apply_request(request=["file", file.name, "scan"]) file = folder.deleted_files.get(file.uuid) diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py index efa74e1f..398af0cc 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py @@ -31,7 +31,7 @@ def test_folder_scan_request(populated_file_system): assert file1.visible_health_status == FileSystemItemHealthStatus.GOOD assert file2.visible_health_status == FileSystemItemHealthStatus.GOOD - fs.apply_request(request=["folder", folder.uuid, "scan"]) + fs.apply_request(request=["folder", folder.name, "scan"]) folder.apply_timestep(timestep=0) @@ -53,12 +53,12 @@ def test_folder_checkhash_request(populated_file_system): """Test that an agent can request a folder hash check.""" fs, folder, file = populated_file_system - fs.apply_request(request=["folder", folder.uuid, "checkhash"]) + fs.apply_request(request=["folder", folder.name, "checkhash"]) assert folder.health_status == FileSystemItemHealthStatus.GOOD file.sim_size = 0 - fs.apply_request(request=["folder", folder.uuid, "checkhash"]) + fs.apply_request(request=["folder", folder.name, "checkhash"]) assert folder.health_status == FileSystemItemHealthStatus.CORRUPT @@ -70,7 +70,7 @@ def test_folder_repair_request(populated_file_system): assert file.health_status == FileSystemItemHealthStatus.CORRUPT assert folder.health_status == FileSystemItemHealthStatus.CORRUPT - fs.apply_request(request=["folder", folder.uuid, "repair"]) + fs.apply_request(request=["folder", folder.name, "repair"]) assert file.health_status == FileSystemItemHealthStatus.GOOD assert folder.health_status == FileSystemItemHealthStatus.GOOD @@ -116,7 +116,7 @@ def test_folder_restore_request(populated_file_system): assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is False # corrupt folder - fs.apply_request(request=["folder", folder.uuid, "corrupt"]) + fs.apply_request(request=["folder", folder.name, "corrupt"]) assert fs.get_folder(folder_name=folder.name).health_status == FileSystemItemHealthStatus.CORRUPT assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT @@ -143,7 +143,7 @@ def test_folder_restore_request(populated_file_system): def test_folder_corrupt_request(populated_file_system): """Test that an agent can request a folder corruption.""" fs, folder, file = populated_file_system - fs.apply_request(request=["folder", folder.uuid, "corrupt"]) + fs.apply_request(request=["folder", folder.name, "corrupt"]) assert file.health_status == FileSystemItemHealthStatus.CORRUPT assert folder.health_status == FileSystemItemHealthStatus.CORRUPT @@ -153,13 +153,13 @@ def test_deleted_folder_and_its_files_cannot_be_interacted_with(populated_file_s fs, folder, file = populated_file_system assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None - fs.apply_request(request=["file", file.uuid, "corrupt"]) + fs.apply_request(request=["file", file.name, "corrupt"]) assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT fs.apply_request(request=["delete", "folder", folder.uuid]) assert fs.get_file(folder_name=folder.name, file_name=file.name) is None - fs.apply_request(request=["file", file.uuid, "repair"]) + fs.apply_request(request=["file", file.name, "repair"]) deleted_folder = fs.deleted_folders.get(folder.uuid) deleted_file = deleted_folder.deleted_files.get(file.uuid) From 41a7f838873745467d0e86480406d92327e61c33 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 31 Jan 2024 13:29:46 +0000 Subject: [PATCH 552/980] Add file scan test --- src/primaite/game/agent/actions.py | 2 +- src/primaite/simulator/file_system/folder.py | 2 +- .../game_layer/test_actions.py | 50 ++++++++++++++++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 3b1fb926..dbf1b6a2 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -270,7 +270,7 @@ class NodeFileAbstractAction(AbstractAction): file_name = self.manager.get_file_name_by_idx(node_idx=node_id, folder_idx=folder_id, file_idx=file_id) if node_name is None or folder_name is None or file_name is None: return ["do_nothing"] - return ["network", "node", node_name, "file_system", "folder", folder_name, "files", file_name, self.verb] + return ["network", "node", node_name, "file_system", "folder", folder_name, "file", file_name, self.verb] class NodeFileScanAction(NodeFileAbstractAction): diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index dae32cd5..a93b2927 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -257,7 +257,7 @@ class Folder(FileSystemItemABC): # add to list self.files[file.uuid] = file - self._file_request_manager.add_request(file.uuid, RequestType(func=file._request_manager)) + self._file_request_manager.add_request(file.name, RequestType(func=file._request_manager)) file.folder = self def remove_file(self, file: Optional[File]): diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 2bc3b095..7527151c 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -19,6 +19,7 @@ from primaite.game.agent.interface import AbstractAgent, ProxyAgent from primaite.game.agent.observations import ICSObservation, ObservationManager from primaite.game.agent.rewards import RewardFunction from primaite.game.game import PrimaiteGame +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import ACLAction, Router @@ -62,7 +63,7 @@ class ControlledAgent(AbstractAgent): def install_stuff_to_sim(sim: Simulation): - """Create a simulation with a three computers, two switches, and a router.""" + """Create a simulation with a computer, two servers, two switches, and a router.""" # 0: Pull out the network network = sim.network @@ -139,6 +140,9 @@ def install_stuff_to_sim(sim: Simulation): assert isinstance(client_1.software_manager.software.get("WebBrowser"), WebBrowser) assert isinstance(client_1.software_manager.software.get("DNSClient"), DNSClient) + # 4.1: Create a file on the computer + client_1.file_system.create_file("cat.png", 300, folder_name="downloads") + # 5: Assert that the simulation starts off in the state that we expect assert len(sim.network.nodes) == 6 assert len(sim.network.links) == 5 @@ -221,7 +225,11 @@ def game_and_agent(): game=game, actions=actions, # ALL POSSIBLE ACTIONS nodes=[ - {"node_name": "client_1", "applications": [{"application_name": "WebBrowser"}]}, + { + "node_name": "client_1", + "applications": [{"application_name": "WebBrowser"}], + "folders": [{"folder_name": "downloads", "files": [{"file_name": "cat.png"}]}], + }, {"node_name": "server_1", "services": [{"service_name": "DNSServer"}]}, {"node_name": "server_2", "services": [{"service_name": "WebServer"}]}, ], @@ -480,3 +488,41 @@ def test_network_nic_enable_integration(game_and_agent: Tuple[PrimaiteGame, Prox # 3: Check that the NIC is enabled, and that client 1 can ping again assert client_1.ethernet_port[1].enabled == True assert client_1.ping("10.0.2.3") + + +def test_node_file_scan_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that a when a file is scanned, it's visible health status gets set to the actual health status.""" + + game, agent = game_and_agent + + # 1: assert file is healthy + client_1 = game.simulation.network.get_node_by_hostname("client_1") + file = client_1.file_system.get_file("downloads", "cat.png") + assert file.health_status == FileSystemItemHealthStatus.GOOD + assert file.visible_health_status == FileSystemItemHealthStatus.GOOD + + # 2: perform a scan and make sure nothing has changed + action = ( + "NODE_FILE_SCAN", + { + "node_id": 0, # client_1, + "folder_id": 0, # downloads, + "file_id": 0, # cat.png + }, + ) + agent.store_action(action) + game.step() + + assert file.health_status == FileSystemItemHealthStatus.GOOD + assert file.visible_health_status == FileSystemItemHealthStatus.GOOD + + # 3: Set the file to corrupted, and check that only actual updates, not visible. + file.health_status = FileSystemItemHealthStatus.CORRUPT + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + assert file.visible_health_status == FileSystemItemHealthStatus.GOOD + + # 4: Perform a scan and check that it updates + agent.store_action(action) + game.step() + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT From 83db5b1eb59712cb952462f8e913ec6d56fe0700 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 31 Jan 2024 13:50:20 +0000 Subject: [PATCH 553/980] Fix node file delete action --- src/primaite/game/agent/actions.py | 3 +- .../simulator/file_system/file_system.py | 4 +-- .../game_layer/test_actions.py | 28 +++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index dbf1b6a2..6123da50 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -303,8 +303,7 @@ class NodeFileDeleteAction(NodeFileAbstractAction): file_name = self.manager.get_file_name_by_idx(node_idx=node_id, folder_idx=folder_id, file_idx=file_id) if node_name is None or folder_name is None or file_name is None: return ["do_nothing"] - return ["do_nothing"] - # return ["network", "node", node_name, "file_system", "delete", "file", folder_name, file_name] + return ["network", "node", node_name, "file_system", "delete", "file", folder_name, file_name] class NodeFileRepairAction(NodeFileAbstractAction): diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 48ea587d..2ab3b005 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -78,12 +78,12 @@ class FileSystem(SimComponent): self._delete_manager.add_request( name="file", request_type=RequestType( - func=lambda request, context: self.delete_file_by_id(folder_uuid=request[0], file_uuid=request[1]) + func=lambda request, context: self.delete_file(folder_name=request[0], file_name=request[1]) ), ) self._delete_manager.add_request( name="folder", - request_type=RequestType(func=lambda request, context: self.delete_folder_by_id(folder_uuid=request[0])), + request_type=RequestType(func=lambda request, context: self.delete_folder(folder_name=request[0])), ) rm.add_request( name="delete", diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 7527151c..e771dbd2 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -526,3 +526,31 @@ def test_node_file_scan_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAge game.step() assert file.health_status == FileSystemItemHealthStatus.CORRUPT assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_node_file_delete_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that a file can be deleted by the agent.""" + game, agent = game_and_agent + + # 1: assert the file is there + client_1 = game.simulation.network.get_node_by_hostname("client_1") + file = client_1.file_system.get_file("downloads", "cat.png") + assert file is not None + assert not file.deleted + + # 2: delete the file + action = ( + "NODE_FILE_DELETE", + { + "node_id": 0, # client_1 + "folder_id": 0, # downloads + "file_id": 0, # cat.png + }, + ) + agent.store_action(action) + game.step() + + # 3. Check that the file is not there any more + assert not client_1.file_system.get_file("downloads", "cat.png") + # 3.1 (but with the reference to the original file, we can check that deleted flag is True ) + assert file.deleted From 261423bc78c7ef1cbe18aa83dfadc55ff4f88680 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 31 Jan 2024 13:54:15 +0000 Subject: [PATCH 554/980] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d8706ad..fdb530e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- Refactored actions and observations to be configurable via object name, instead of UUID. - Fixed a bug where ACL rules were not resetting on episode reset. - Fixed a bug where blue agent's ACL actions were being applied against the wrong IP addresses - Fixed a bug where deleted files and folders did not reset correctly on episode reset. From c163fb37ea4389fcace1a79b2f1723ea2c624c78 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 1 Feb 2024 11:19:42 +0000 Subject: [PATCH 555/980] Update request system docs. --- docs/source/request_system.rst | 35 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/docs/source/request_system.rst b/docs/source/request_system.rst index 1b06e2d9..392bc792 100644 --- a/docs/source/request_system.rst +++ b/docs/source/request_system.rst @@ -7,26 +7,29 @@ Request System ``SimComponent`` objects in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``RequestManager`` and ``RequestType``. -Just like other aspects of SimComponent, the request types are not managed centrally for the whole simulation, but instead they are dynamically created and updated based on the nodes, links, and other components that currently exist. This was achieved in the following way: +Just like other aspects of SimComponent, the request types are not managed centrally for the whole simulation, but instead they are dynamically created and updated based on the nodes, links, and other components that currently exist in the simulation. This is achieved in the following way: - API - A ``RequestType`` contains two elements: + When requesting an action within the simulation, these two arguments must be provided: - 1. ``request`` - selects which action you want to take on this ``SimComponent``. This is formatted as a list of strings such as `['network', 'node', '', 'service', '', 'restart']`. + 1. ``request`` - selects which action you want to take on this ``SimComponent``. This is formatted as a list of strings such as `['network', 'node', '', 'service', '', 'restart']`. 2. ``context`` - optional extra information that can be used to decide how to process the request. This is formatted as a dictionary. For example, if the request requires authentication, the context can include information about the user that initiated the request to decide if their permissions are sufficient. -- request +- ``request`` detail The request is a list of strings which help specify who should handle the request. The strings in the request list help RequestManagers traverse the 'ownership tree' of SimComponent. The example given above would be handled in the following way: - 1. ``Simulation`` receives `['network', 'node', '', 'service', '', 'restart']`. + 1. ``Simulation`` receives `['network', 'node', '', 'service', '', 'restart']`. The first element of the request is ``network``, therefore it passes the request down to its network. - 2. ``Network`` receives `['node', '', 'service', '', 'restart']`. - The first element of the request is ``node``, therefore the network looks at the node uuid and passes the request down to the node with that uuid. - 3. ``Node`` receives `['service', '', 'restart']`. - The first element of the request is ``service``, therefore the node looks at the service uuid and passes the rest of the request to the service with that uuid. + 2. ``Network`` receives `['node', '', 'service', '', 'restart']`. + The first element of the request is ``node``, therefore the network looks at the node name and passes the request down to the node with that name. + 3. ``Node`` receives `['service', '', 'restart']`. + The first element of the request is ``service``, therefore the node looks at the service name and passes the rest of the request to the service with that name. 4. ``Service`` receives ``['restart']``. Since ``restart`` is a defined request type in the service's own RequestManager, the service performs a restart. +- ``context`` detail + The context is not used by any of the currently implemented components or requests. + Technical Detail ---------------- @@ -75,16 +78,18 @@ An example of how this works is in the :py:class:`primaite.simulator.network.har request_manager.add_request("turn_on", RequestType(func=lambda request, context: self.turn_on())) # if the Node receives a request where the first word is 'service', it will use a dummy manager - # called self._service_request_manager to pass on the reqeust to the relevant service. This dummy - # manager is simply here to map the service UUID that that service's own action manager. This is - # done because the next string after "service" is always the uuid of that service, so we need an + # called self._service_request_manager to pass on the request to the relevant service. This dummy + # manager is simply here to map the service name that that service's own action manager. This is + # done because the next string after "service" is always the name of that service, so we need an # RequestManager to pop that string before sending it onto the relevant service's RequestManager. self._service_request_manager = RequestManager() request_manager.add_request("service", RequestType(func=self._service_request_manager)) ... def install_service(self, service): - self.services[service.uuid] = service + self.services[service.name] = service ... - # Here, the service UUID is registered to allow passing actions between the node and the service. - self._service_request_manager.add_request(service.uuid, RequestType(func=service._request_manager)) + # Here, the service name is registered to allow passing actions between the node and the service. + self._service_request_manager.add_request(service.name, RequestType(func=service._request_manager)) + +This process is repeated until the request word corresponds to a callable function rather than another ``RequestManager`` . From 9577f212f8a6e55f3ee5d50f4b50e652abf331e0 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 1 Feb 2024 22:19:55 +0000 Subject: [PATCH 556/980] #2248 - Initial crack at getting ARP into a Service. Lots of refactoring has been done. It's a mess at the minute, but I can successfully send an ARP request so committing as a successful point in time --- src/primaite/simulator/__init__.py | 4 +- .../simulator/network/hardware/base.py | 107 +++++++--- .../network/hardware/nodes/router.py | 88 ++++---- .../network/transmission/data_link_layer.py | 4 +- .../simulator/system/core/session_manager.py | 127 ++++++----- .../simulator/system/core/software_manager.py | 12 +- .../simulator/system/services/arp/__init__.py | 0 .../simulator/system/services/arp/arp.py | 201 ++++++++++++++++++ .../simulator/system/services/arp/host_arp.py | 95 +++++++++ src/primaite/simulator/system/software.py | 3 + 10 files changed, 503 insertions(+), 138 deletions(-) create mode 100644 src/primaite/simulator/system/services/arp/__init__.py create mode 100644 src/primaite/simulator/system/services/arp/arp.py create mode 100644 src/primaite/simulator/system/services/arp/host_arp.py diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index aebd77cf..97bcd57b 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -12,8 +12,8 @@ class _SimOutput: self._path: Path = ( _PRIMAITE_ROOT.parent.parent / "simulation_output" / datetime.now().strftime("%Y-%m-%d_%H-%M-%S") ) - self.save_pcap_logs: bool = False - self.save_sys_logs: bool = False + self.save_pcap_logs: bool = True + self.save_sys_logs: bool = True @property def path(self) -> Path: diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 9becde59..4537adc2 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -18,7 +18,7 @@ from primaite.simulator.network.hardware.node_operating_state import NodeOperati from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader, UDPHeader from primaite.simulator.system.applications.application import Application from primaite.simulator.system.core.packet_capture import PacketCapture from primaite.simulator.system.core.session_manager import SessionManager @@ -617,6 +617,7 @@ class ARPCache: self.sys_log: "SysLog" = sys_log self.arp: Dict[IPv4Address, ARPEntry] = {} self.nics: Dict[str, "NIC"] = {} + self.node = None def show(self, markdown: bool = False): """Prints a table of ARC Cache.""" @@ -669,6 +670,36 @@ class ARPCache: if ip_address in self.arp: del self.arp[ip_address] + def get_default_gateway_mac_address(self) -> Optional[str]: + if self.arp.node.default_gateway: + return self.get_arp_cache_mac_address(self.arp.node.default_gateway) + + def get_default_gateway_nic(self) -> Optional[NIC]: + if self.arp.node.default_gateway: + return self.get_arp_cache_nic(self.arp.node.default_gateway) + + def _get_arp_cache_mac_address( + self, ip_address: IPv4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False + ) -> Optional[str]: + arp_entry = self.arp.get(ip_address) + + if arp_entry: + return arp_entry.mac_address + else: + if not is_reattempt: + self.send_arp_request(ip_address) + return self._get_arp_cache_mac_address( + ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt + ) + else: + if self.node.default_gateway: + if not is_default_gateway_attempt: + self.send_arp_request(self.node.default_gateway) + return self._get_arp_cache_mac_address( + ip_address=self.node.default_gateway, is_reattempt=True, is_default_gateway_attempt=True + ) + return None + def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: """ Get the MAC address associated with an IP address. @@ -676,9 +707,29 @@ class ARPCache: :param ip_address: The IP address to look up in the cache. :return: The MAC address associated with the IP address, or None if not found. """ + return self._get_arp_cache_mac_address(ip_address) + + def _get_arp_cache_nic( + self, ip_address: IPv4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False + ) -> Optional[NIC]: arp_entry = self.arp.get(ip_address) + if arp_entry: - return arp_entry.mac_address + return self.nics[arp_entry.nic_uuid] + else: + if not is_reattempt: + self.send_arp_request(ip_address) + return self._get_arp_cache_nic( + ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt + ) + else: + if self.node.default_gateway: + if not is_default_gateway_attempt: + self.send_arp_request(self.node.default_gateway) + return self._get_arp_cache_nic( + ip_address=self.node.default_gateway, is_reattempt=True, is_default_gateway_attempt=True + ) + return None def get_arp_cache_nic(self, ip_address: IPv4Address) -> Optional[NIC]: """ @@ -687,10 +738,7 @@ class ARPCache: :param ip_address: The IP address to look up in the cache. :return: The NIC associated with the IP address, or None if not found. """ - arp_entry = self.arp.get(ip_address) - - if arp_entry: - return self.nics[arp_entry.nic_uuid] + return self._get_arp_cache_nic(ip_address) def clear_arp_cache(self): """Clear the entire ARP cache, removing all stored entries.""" @@ -721,12 +769,11 @@ class ARPCache: use_nic = False if nic.enabled and use_nic: self.sys_log.info(f"Sending ARP request from NIC {nic} for ip {target_ip_address}") - tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) + udp_header = UDPHeader(src_port=Port.ARP, dst_port=Port.ARP) # Network Layer ip_packet = IPPacket( - src_ip_address=nic.ip_address, - dst_ip_address=target_ip_address, + src_ip_address=nic.ip_address, dst_ip_address=target_ip_address, protocol=IPProtocol.UDP ) # Data Link Layer ethernet_header = EthernetHeader(src_mac_addr=nic.mac_address, dst_mac_addr="ff:ff:ff:ff:ff:ff") @@ -735,7 +782,7 @@ class ARPCache: sender_mac_addr=nic.mac_address, target_ip_address=target_ip_address, ) - frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_packet) + frame = Frame(ethernet=ethernet_header, ip=ip_packet, udp=udp_header, payload=arp_packet) nic.send_frame(frame) def send_arp_reply(self, arp_reply: ARPPacket, from_nic: NIC): @@ -888,25 +935,14 @@ class ICMP: was not found in the ARP cache. """ nic = self.arp.get_arp_cache_nic(target_ip_address) - # TODO: Eventually this ARP request needs to be done elsewhere. It's not the responsibility of the - # ping function to handle ARP lookups - # Already tried once and cannot get ARP entry, stop trying - if sequence == -1: - if not nic: - return 4, None - else: - sequence = 0 - - # No existing ARP entry if not nic: - self.sys_log.info(f"No entry in ARP cache for {target_ip_address}") - self.arp.send_arp_request(target_ip_address) - return -1, None + return pings, None # ARP entry exists sequence += 1 target_mac_address = self.arp.get_arp_cache_mac_address(target_ip_address) + src_nic = self.arp.get_arp_cache_nic(target_ip_address) tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) @@ -1026,6 +1062,7 @@ class Node(SimComponent): ) super().__init__(**kwargs) self.arp.nics = self.nics + self.arp.node = self self.session_manager.software_manager = self.software_manager self._install_system_software() self.set_original_state() @@ -1407,7 +1444,9 @@ class Node(SimComponent): self.sys_log.info("Pinging loopback address") return any(nic.enabled for nic in self.nics.values()) if self.operating_state == NodeOperatingState.ON: - self.sys_log.info(f"Pinging {target_ip_address}:") + output = f"Pinging {target_ip_address}:" + self.sys_log.info(output) + print(output) sequence, identifier = 0, None while sequence < pings: sequence, identifier = self.icmp.ping(target_ip_address, sequence, identifier, pings) @@ -1417,12 +1456,14 @@ class Node(SimComponent): self.icmp.request_replies.pop(identifier) else: request_replies = 0 - self.sys_log.info( + output = ( f"Ping statistics for {target_ip_address}: " f"Packets: Sent = {pings}, " f"Received = {request_replies}, " f"Lost = {pings - request_replies} ({(pings - request_replies) / pings * 100}% loss)" ) + self.sys_log.info(output) + print(output) return passed return False @@ -1456,12 +1497,18 @@ class Node(SimComponent): self.icmp.process_icmp(frame=frame, from_nic=from_nic) return # Check if the destination port is open on the Node - if frame.tcp.dst_port in self.software_manager.get_open_ports(): + dst_port = None + if frame.tcp: + dst_port = frame.tcp.dst_port + elif frame.udp: + dst_port = frame.udp.dst_port + if dst_port in self.software_manager.get_open_ports(): # accept thr frame as the port is open - if frame.tcp.src_port == Port.ARP: - self.arp.process_arp_packet(from_nic=from_nic, arp_packet=frame.arp) - else: - self.session_manager.receive_frame(frame) + self.session_manager.receive_frame(frame, from_nic) + # if frame.tcp.src_port == Port.ARP: + # self.arp.process_arp_packet(from_nic=from_nic, arp_packet=frame.arp) + # else: + # self.session_manager.receive_frame(frame) else: # denied as port closed self.sys_log.info(f"Ignoring frame for port {frame.tcp.dst_port.value} from {frame.ip.src_ip_address}") diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 845975ee..ed9a30d4 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -566,33 +566,32 @@ class RouterARPCache(ARPCache): # ARP Reply if not arp_packet.request: - for nic in self.router.nics.values(): - if arp_packet.target_ip_address == nic.ip_address: - # reply to the Router specifically - self.sys_log.info( - f"Received ARP response for {arp_packet.sender_ip_address} " - f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" - ) - self.add_arp_cache_entry( - ip_address=arp_packet.sender_ip_address, - mac_address=arp_packet.sender_mac_addr, - nic=from_nic, - ) - return - - # Reply for a connected requested - nic = self.get_arp_cache_nic(arp_packet.target_ip_address) - if nic: + if arp_packet.target_ip_address == from_nic.ip_address: + # reply to the Router specifically self.sys_log.info( - f"Forwarding arp reply for {arp_packet.target_ip_address}, from {arp_packet.sender_ip_address}" + f"Received ARP response for {arp_packet.sender_ip_address} " + f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" ) - arp_packet.sender_mac_addr = nic.mac_address - frame.decrement_ttl() - if frame.ip and frame.ip.ttl < 1: - self.sys_log.info("Frame discarded as TTL limit reached") - return - nic.send_frame(frame) - return + self.add_arp_cache_entry( + ip_address=arp_packet.sender_ip_address, + mac_address=arp_packet.sender_mac_addr, + nic=from_nic, + ) + return + + # # Reply for a connected requested + # nic = self.get_arp_cache_nic(arp_packet.target_ip_address) + # if nic: + # self.sys_log.info( + # f"Forwarding arp reply for {arp_packet.target_ip_address}, from {arp_packet.sender_ip_address}" + # ) + # arp_packet.sender_mac_addr = nic.mac_address + # frame.decrement_ttl() + # if frame.ip and frame.ip.ttl < 1: + # self.sys_log.info("Frame discarded as TTL limit reached") + # return + # nic.send_frame(frame) + # return # ARP Request self.sys_log.info( @@ -606,28 +605,27 @@ class RouterARPCache(ARPCache): # If the target IP matches one of the router's NICs for nic in self.nics.values(): - if arp_packet.target_ip_address in nic.ip_network: - # if nic.enabled and nic.ip_address == arp_packet.target_ip_address: + if nic.enabled and nic.ip_address == arp_packet.target_ip_address: arp_reply = arp_packet.generate_reply(from_nic.mac_address) self.send_arp_reply(arp_reply, from_nic) return - # Check Route Table - route = route_table.find_best_route(arp_packet.target_ip_address) - if route: - nic = self.get_arp_cache_nic(route.next_hop_ip_address) - - if not nic: - if not is_reattempt: - self.send_arp_request(route.next_hop_ip_address, ignore_networks=[frame.ip.src_ip_address]) - return self.process_arp_packet(from_nic, frame, route_table, is_reattempt=True) - else: - self.sys_log.info("Ignoring ARP request as destination unavailable/No ARP entry found") - return - else: - arp_reply = arp_packet.generate_reply(from_nic.mac_address) - self.send_arp_reply(arp_reply, from_nic) - return + # # Check Route Table + # route = route_table.find_best_route(arp_packet.target_ip_address) + # if route and route != self.router.route_table.default_route: + # nic = self.get_arp_cache_nic(route.next_hop_ip_address) + # + # if not nic: + # if not is_reattempt: + # self.send_arp_request(route.next_hop_ip_address, ignore_networks=[frame.ip.src_ip_address]) + # return self.process_arp_packet(from_nic, frame, route_table, is_reattempt=True) + # else: + # self.sys_log.info("Ignoring ARP request as destination unavailable/No ARP entry found") + # return + # else: + # arp_reply = arp_packet.generate_reply(from_nic.mac_address) + # self.send_arp_reply(arp_reply, from_nic) + # return class RouterICMP(ICMP): @@ -949,13 +947,13 @@ class Router(Node): at_port = self._get_port_of_nic(from_nic) self.sys_log.info(f"Frame blocked at port {at_port} by rule {rule}") return - if not self.arp.get_arp_cache_nic(src_ip_address): - self.arp.add_arp_cache_entry(src_ip_address, frame.ethernet.src_mac_addr, from_nic) + self.arp.add_arp_cache_entry(src_ip_address, frame.ethernet.src_mac_addr, from_nic) if frame.ip.protocol == IPProtocol.ICMP: self.icmp.process_icmp(frame=frame, from_nic=from_nic) else: if src_port == Port.ARP: self.arp.process_arp_packet(from_nic=from_nic, frame=frame, route_table=self.route_table) + return else: # All other traffic process_frame = True diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index fa823a60..6a4e24d8 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -73,7 +73,7 @@ class Frame(BaseModel): msg = "Cannot build a Frame using the TCP IP Protocol without a TCPHeader" _LOGGER.error(msg) raise ValueError(msg) - if kwargs["ip"].protocol == IPProtocol.UDP and not kwargs.get("UDP"): + if kwargs["ip"].protocol == IPProtocol.UDP and not kwargs.get("udp"): msg = "Cannot build a Frame using the UDP IP Protocol without a UDPHeader" _LOGGER.error(msg) raise ValueError(msg) @@ -95,8 +95,6 @@ class Frame(BaseModel): "UDP header." icmp: Optional[ICMPPacket] = None "ICMP header." - arp: Optional[ARPPacket] = None - "ARP packet." primaite: PrimaiteHeader "PrimAITE header." payload: Optional[Any] = None diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index a95846a3..8c305032 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -8,10 +8,10 @@ from prettytable import MARKDOWN, PrettyTable from primaite.simulator.core import SimComponent from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader, UDPHeader if TYPE_CHECKING: - from primaite.simulator.network.hardware.base import ARPCache + from primaite.simulator.network.hardware.base import ARPCache, NIC from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.core.sys_log import SysLog @@ -138,37 +138,19 @@ class SessionManager: dst_port = None return protocol, with_ip_address, src_port, dst_port - def receive_payload_from_software_manager( - self, - payload: Any, - dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, - dst_port: Optional[Port] = None, - session_id: Optional[str] = None, - is_reattempt: bool = False, - ) -> Union[Any, None]: - """ - Receive a payload from the SoftwareManager and send it to the appropriate NIC for transmission. - - This method supports both unicast and Layer 3 broadcast transmissions. If `dst_ip_address` is an - IPv4Network, a broadcast is initiated. For unicast, the destination MAC address is resolved via ARP. - A new session is established if `session_id` is not provided, and an existing session is used otherwise. - - :param payload: The payload to be sent. - :param dst_ip_address: The destination IP address or network for broadcast. Optional. - :param dst_port: The destination port for the TCP packet. Optional. - :param session_id: The Session ID from which the payload originates. Optional. - :param is_reattempt: Flag to indicate if this is a reattempt after an ARP request. Default is False. - :return: The outcome of sending the frame, or None if sending was unsuccessful. - """ + def resolve_outbound_transmission_details( + self, dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, session_id: Optional[str] = None + ) -> Tuple[Optional["NIC"], Optional[str], Optional[IPProtocol], bool]: is_broadcast = False outbound_nic = None dst_mac_address = None + protocol = None # Use session details if session_id is provided if session_id: session = self.sessions_by_uuid[session_id] dst_ip_address = session.with_ip_address - dst_port = session.dst_port + protocol = session.protocol # Determine if the payload is for broadcast or unicast @@ -182,47 +164,81 @@ class SessionManager: if dst_ip_address in nic.ip_network and nic.enabled: dst_mac_address = "ff:ff:ff:ff:ff:ff" outbound_nic = nic + break else: # Resolve MAC address for unicast transmission - dst_mac_address = self.arp_cache.get_arp_cache_mac_address(dst_ip_address) + use_default_gateway = True + for nic in self.arp_cache.nics.values(): + if dst_ip_address in nic.ip_network and nic.enabled: + dst_mac_address = self.arp_cache.get_arp_cache_mac_address(dst_ip_address) + break - # Resolve outbound NIC for unicast transmission - if dst_mac_address: + if dst_ip_address: + use_default_gateway = False outbound_nic = self.arp_cache.get_arp_cache_nic(dst_ip_address) - # If MAC address not found, initiate ARP request - else: - if not is_reattempt: - self.arp_cache.send_arp_request(dst_ip_address) - # Reattempt payload transmission after ARP request - return self.receive_payload_from_software_manager( - payload=payload, - dst_ip_address=dst_ip_address, - dst_port=dst_port, - session_id=session_id, - is_reattempt=True, - ) - else: - # Return None if reattempt fails - return + if use_default_gateway: + dst_mac_address = self.arp_cache.get_default_gateway_mac_address() + outbound_nic = self.arp_cache.get_default_gateway_nic() + return outbound_nic, dst_mac_address, protocol, is_broadcast + + def receive_payload_from_software_manager( + self, + payload: Any, + dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, + dst_port: Optional[Port] = None, + session_id: Optional[str] = None, + ip_protocol: IPProtocol = IPProtocol.TCP, + ) -> Union[Any, None]: + """ + Receive a payload from the SoftwareManager and send it to the appropriate NIC for transmission. + + This method supports both unicast and Layer 3 broadcast transmissions. If `dst_ip_address` is an + IPv4Network, a broadcast is initiated. For unicast, the destination MAC address is resolved via ARP. + A new session is established if `session_id` is not provided, and an existing session is used otherwise. + + :param payload: The payload to be sent. + :param dst_ip_address: The destination IP address or network for broadcast. Optional. + :param dst_port: The destination port for the TCP packet. Optional. + :param session_id: The Session ID from which the payload originates. Optional. + :return: The outcome of sending the frame, or None if sending was unsuccessful. + """ + print(ip_protocol) + outbound_nic, dst_mac_address, protocol, is_broadcast = self.resolve_outbound_transmission_details( + dst_ip_address=dst_ip_address, session_id=session_id + ) + + if protocol: + ip_protocol = protocol + + print(ip_protocol) # Check if outbound NIC and destination MAC address are resolved if not outbound_nic or not dst_mac_address: return False + tcp_header = None + udp_header = None + if ip_protocol == IPProtocol.TCP: + TCPHeader( + src_port=dst_port, + dst_port=dst_port, + ) + elif ip_protocol == IPProtocol: + udp_header = UDPHeader( + src_port=dst_port, + dst_port=dst_port, + ) + # Construct the frame for transmission frame = Frame( ethernet=EthernetHeader(src_mac_addr=outbound_nic.mac_address, dst_mac_addr=dst_mac_address), - ip=IPPacket( - src_ip_address=outbound_nic.ip_address, - dst_ip_address=dst_ip_address, - ), - tcp=TCPHeader( - src_port=dst_port, - dst_port=dst_port, - ), + ip=IPPacket(src_ip_address=outbound_nic.ip_address, dst_ip_address=dst_ip_address, ip_protocol=ip_protocol), + tcp=tcp_header, + udp_header=udp_header, payload=payload, ) + print(frame) # Manage session for unicast transmission if not (is_broadcast and session_id): @@ -237,7 +253,7 @@ class SessionManager: # Send the frame through the NIC return outbound_nic.send_frame(frame) - def receive_frame(self, frame: Frame): + def receive_frame(self, frame: Frame, from_nic: NIC): """ Receive a Frame. @@ -253,8 +269,13 @@ class SessionManager: session = Session.from_session_key(session_key) self.sessions_by_key[session_key] = session self.sessions_by_uuid[session.uuid] = session + dst_port = None + if frame.tcp: + dst_port = frame.tcp.dst_port + elif frame.udp: + dst_port = frame.udp.dst_port self.software_manager.receive_payload_from_session_manager( - payload=frame.payload, port=frame.tcp.dst_port, protocol=frame.ip.protocol, session_id=session.uuid + payload=frame.payload, port=dst_port, protocol=frame.ip.protocol, session_id=session.uuid, from_nic=from_nic ) def show(self, markdown: bool = False): diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index 95948a1e..e1ec6698 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -14,7 +14,7 @@ from primaite.simulator.system.software import IOSoftware if TYPE_CHECKING: from primaite.simulator.system.core.session_manager import SessionManager from primaite.simulator.system.core.sys_log import SysLog - from primaite.simulator.network.hardware.base import Node + from primaite.simulator.network.hardware.base import Node, NIC from typing import Type, TypeVar @@ -52,11 +52,10 @@ class SoftwareManager: :return: A list of all open ports on the Node. """ - open_ports = [Port.ARP] + open_ports = [] for software in self.port_protocol_mapping.values(): if software.operating_state in {ApplicationOperatingState.RUNNING, ServiceOperatingState.RUNNING}: open_ports.append(software.port) - open_ports.sort(key=lambda port: port.value) return open_ports def install(self, software_class: Type[IOSoftwareClass]): @@ -132,6 +131,7 @@ class SoftwareManager: payload: Any, dest_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, dest_port: Optional[Port] = None, + ip_protocol: IPProtocol = IPProtocol.TCP, session_id: Optional[str] = None, ) -> bool: """ @@ -154,7 +154,9 @@ class SoftwareManager: session_id=session_id, ) - def receive_payload_from_session_manager(self, payload: Any, port: Port, protocol: IPProtocol, session_id: str): + def receive_payload_from_session_manager( + self, payload: Any, port: Port, protocol: IPProtocol, session_id: str, from_nic: "NIC" + ): """ Receive a payload from the SessionManager and forward it to the corresponding service or application. @@ -163,7 +165,7 @@ class SoftwareManager: """ receiver: Optional[Union[Service, Application]] = self.port_protocol_mapping.get((port, protocol), None) if receiver: - receiver.receive(payload=payload, session_id=session_id) + receiver.receive(payload=payload, session_id=session_id, from_nic=from_nic) else: self.sys_log.error(f"No service or application found for port {port} and protocol {protocol}") pass diff --git a/src/primaite/simulator/system/services/arp/__init__.py b/src/primaite/simulator/system/services/arp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/services/arp/arp.py b/src/primaite/simulator/system/services/arp/arp.py new file mode 100644 index 00000000..46bc151d --- /dev/null +++ b/src/primaite/simulator/system/services/arp/arp.py @@ -0,0 +1,201 @@ +from __future__ import annotations + +from abc import abstractmethod +from ipaddress import IPv4Address +from typing import Any, Dict, Optional, Tuple, Union + +from prettytable import MARKDOWN, PrettyTable +from pydantic import BaseModel + +from primaite.simulator.network.hardware.base import NIC +from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket +from primaite.simulator.network.protocols.packet import DataPacket +from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame +from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader, UDPHeader +from primaite.simulator.system.services.service import Service + + +class ARP(Service): + arp: Dict[IPv4Address, ARPEntry] = {} + + def __init__(self, **kwargs): + kwargs["name"] = "ARP" + kwargs["port"] = Port.ARP + kwargs["protocol"] = IPProtocol.UDP + super().__init__(**kwargs) + + def describe_state(self) -> Dict: + pass + + def show(self, markdown: bool = False): + """Prints a table of ARC Cache.""" + table = PrettyTable(["IP Address", "MAC Address", "Via"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"{self.sys_log.hostname} ARP Cache" + for ip, arp in self.arp.items(): + table.add_row( + [ + str(ip), + arp.mac_address, + self.software_manager.node.nics[arp.nic_uuid].mac_address, + ] + ) + print(table) + + def clear(self): + """Clears the arp cache.""" + self.arp.clear() + + def add_arp_cache_entry(self, ip_address: IPv4Address, mac_address: str, nic: NIC, override: bool = False): + """ + Add an ARP entry to the cache. + + If an entry for the given IP address already exists, the entry is only updated if the `override` parameter is + set to True. + + :param ip_address: The IP address to be added to the cache. + :param mac_address: The MAC address associated with the IP address. + :param nic: The NIC through which the NIC with the IP address is reachable. + :param override: If True, an existing entry for the IP address will be overridden. Default is False. + """ + for _nic in self.software_manager.node.nics.values(): + if _nic.ip_address == ip_address: + return + if override or not self.arp.get(ip_address): + self.sys_log.info(f"Adding ARP cache entry for {mac_address}/{ip_address} via NIC {nic}") + arp_entry = ARPEntry(mac_address=mac_address, nic_uuid=nic.uuid) + + self.arp[ip_address] = arp_entry + + @abstractmethod + def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: + """ + Get the MAC address associated with an IP address. + + :param ip_address: The IP address to look up in the cache. + :return: The MAC address associated with the IP address, or None if not found. + """ + pass + + @abstractmethod + def get_arp_cache_nic(self, ip_address: IPv4Address) -> Optional[NIC]: + """ + Get the NIC associated with an IP address. + + :param ip_address: The IP address to look up in the cache. + :return: The NIC associated with the IP address, or None if not found. + """ + pass + + def send_arp_request(self, target_ip_address: Union[IPv4Address, str]): + """ + Perform a standard ARP request for a given target IP address. + + Broadcasts the request through all enabled NICs to determine the MAC address corresponding to the target IP + address. This method can be configured to ignore specific networks when sending out ARP requests, + which is useful in environments where certain addresses should not be queried. + + :param target_ip_address: The target IP address to send an ARP request for. + :param ignore_networks: An optional list of IPv4 addresses representing networks to be excluded from the ARP + request broadcast. Each address in this list indicates a network which will not be queried during the ARP + request process. This is particularly useful in complex network environments where traffic should be + minimized or controlled to specific subnets. It is mainly used by the router to prevent ARP requests being + sent back to their source. + """ + vals: Tuple = self.software_manager.session_manager.resolve_outbound_transmission_details(target_ip_address) + outbound_nic, _, _, _ = vals + if outbound_nic: + self.sys_log.info(f"Sending ARP request from NIC {outbound_nic} for ip {target_ip_address}") + arp_packet = ARPPacket( + sender_ip_address=outbound_nic.ip_address, + sender_mac_addr=outbound_nic.mac_address, + target_ip_address=target_ip_address, + ) + self.software_manager.session_manager.receive_payload_from_software_manage( + payload=arp_packet, dst_port=Port.ARP, ip_protocol=self.protocol + ) + else: + print(f"failed for {target_ip_address}") + + def send_arp_reply(self, arp_reply: ARPPacket, from_nic: NIC): + """ + Send an ARP reply back through the NIC it came from. + + :param arp_reply: The ARP reply to send. + :param from_nic: The NIC to send the ARP reply from. + """ + self.sys_log.info( + f"Sending ARP reply from {arp_reply.sender_mac_addr}/{arp_reply.sender_ip_address} " + f"to {arp_reply.target_ip_address}/{arp_reply.target_mac_addr} " + ) + udp_header = UDPHeader(src_port=Port.ARP, dst_port=Port.ARP) + + ip_packet = IPPacket( + src_ip_address=arp_reply.sender_ip_address, + dst_ip_address=arp_reply.target_ip_address, + protocol=IPProtocol.UDP, + ) + + ethernet_header = EthernetHeader(src_mac_addr=arp_reply.sender_mac_addr, dst_mac_addr=arp_reply.target_mac_addr) + + frame = Frame(ethernet=ethernet_header, ip=ip_packet, udp=udp_header, payload=arp_reply) + from_nic.send_frame(frame) + + def process_arp_packet(self, from_nic: NIC, arp_packet: ARPPacket): + """ + Process a received ARP packet, handling both ARP requests and responses. + + If an ARP request is received for the local IP, a response is sent back. + If an ARP response is received, the ARP cache is updated with the new entry. + + :param from_nic: The NIC that received the ARP packet. + :param arp_packet: The ARP packet to be processed. + """ + + # Unmatched ARP Request + if arp_packet.target_ip_address != from_nic.ip_address: + self.sys_log.info( + f"Ignoring ARP request for {arp_packet.target_ip_address}. Current IP address is {from_nic.ip_address}" + ) + return + + # Matched ARP request + self.add_arp_cache_entry( + ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic + ) + arp_packet = arp_packet.generate_reply(from_nic.mac_address) + self.send_arp_reply(arp_packet, from_nic) + + @abstractmethod + def _process_arp_request(self, arp_packet: ARPPacket, from_nic: NIC): + self.sys_log.info( + f"Received ARP request for {arp_packet.target_ip_address} from " + f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip_address} " + ) + + def _process_arp_reply(self, arp_packet: ARPPacket, from_nic: NIC): + self.sys_log.info( + f"Received ARP response for {arp_packet.sender_ip_address} " + f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" + ) + self.add_arp_cache_entry( + ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic + ) + + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + if not isinstance(payload, ARPPacket): + print("failied on payload check", type(payload)) + return False + + from_nic = kwargs.get("from_nic") + if payload.request: + print(from_nic) + self._process_arp_request(arp_packet=payload, from_nic=from_nic) + else: + self._process_arp_reply(arp_packet=payload, from_nic=from_nic) + + def __contains__(self, item: Any) -> bool: + return item in self.arp diff --git a/src/primaite/simulator/system/services/arp/host_arp.py b/src/primaite/simulator/system/services/arp/host_arp.py new file mode 100644 index 00000000..678bedbe --- /dev/null +++ b/src/primaite/simulator/system/services/arp/host_arp.py @@ -0,0 +1,95 @@ +from __future__ import annotations + +from ipaddress import IPv4Address +from typing import Optional + +from primaite.simulator.network.hardware.base import NIC +from primaite.simulator.system.services.arp.arp import ARP, ARPPacket + + +class HostARP(ARP): + def get_default_gateway_mac_address(self) -> Optional[str]: + if self.software_manager.node.default_gateway: + return self.get_arp_cache_mac_address(self.software_manager.node.default_gateway) + + def get_default_gateway_nic(self) -> Optional[NIC]: + if self.software_manager.node.default_gateway: + return self.get_arp_cache_nic(self.software_manager.node.default_gateway) + + def _get_arp_cache_mac_address( + self, ip_address: IPv4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False + ) -> Optional[str]: + arp_entry = self.arp.get(ip_address) + + if arp_entry: + return arp_entry.mac_address + else: + if not is_reattempt: + self.send_arp_request(ip_address) + return self._get_arp_cache_mac_address( + ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt + ) + else: + if self.node.default_gateway: + if not is_default_gateway_attempt: + self.send_arp_request(self.node.default_gateway) + return self._get_arp_cache_mac_address( + ip_address=self.node.default_gateway, is_reattempt=True, is_default_gateway_attempt=True + ) + return None + + def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: + """ + Get the MAC address associated with an IP address. + + :param ip_address: The IP address to look up in the cache. + :return: The MAC address associated with the IP address, or None if not found. + """ + return self._get_arp_cache_mac_address(ip_address) + + def _get_arp_cache_nic( + self, ip_address: IPv4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False + ) -> Optional[NIC]: + arp_entry = self.arp.get(ip_address) + + if arp_entry: + return self.nics[arp_entry.nic_uuid] + else: + if not is_reattempt: + self.send_arp_request(ip_address) + return self._get_arp_cache_nic( + ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt + ) + else: + if self.node.default_gateway: + if not is_default_gateway_attempt: + self.send_arp_request(self.node.default_gateway) + return self._get_arp_cache_nic( + ip_address=self.node.default_gateway, is_reattempt=True, is_default_gateway_attempt=True + ) + return None + + def get_arp_cache_nic(self, ip_address: IPv4Address) -> Optional[NIC]: + """ + Get the NIC associated with an IP address. + + :param ip_address: The IP address to look up in the cache. + :return: The NIC associated with the IP address, or None if not found. + """ + return self._get_arp_cache_nic(ip_address) + + def _process_arp_request(self, arp_packet: ARPPacket, from_nic: NIC): + super()._process_arp_request(arp_packet, from_nic) + # Unmatched ARP Request + if arp_packet.target_ip_address != from_nic.ip_address: + self.sys_log.info( + f"Ignoring ARP request for {arp_packet.target_ip_address}. Current IP address is {from_nic.ip_address}" + ) + return + + # Matched ARP request + self.add_arp_cache_entry( + ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic + ) + arp_packet = arp_packet.generate_reply(from_nic.mac_address) + self.send_arp_reply(arp_packet, from_nic) diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 662db08e..8930fa2f 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -8,6 +8,7 @@ from typing import Any, Dict, Optional, Union from primaite.simulator.core import _LOGGER, RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file_system import FileSystem, Folder from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.session_manager import Session from primaite.simulator.system.core.sys_log import SysLog @@ -242,6 +243,8 @@ class IOSoftware(Software): "Indicates if the software uses UDP protocol for communication. Default is True." port: Port "The port to which the software is connected." + protocol: IPProtocol + "The IP Protocol the Software operates on." _connections: Dict[str, Dict] = {} "Active connections." From 1964ab4635d93134ed8c8e7e631ae2f7ff0d8b59 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 1 Feb 2024 23:05:14 +0000 Subject: [PATCH 557/980] #2248 - Lots more progress. Can now use ARP as a service properly. Also integrated the new ARP into the old ICMP which works. Next step is to more ICMP into services. --- .../simulator/network/hardware/base.py | 79 +++++++++---------- .../simulator/system/core/session_manager.py | 55 ++++++++----- .../simulator/system/core/software_manager.py | 5 ++ .../simulator/system/services/arp/arp.py | 7 +- .../simulator/system/services/arp/host_arp.py | 2 +- 5 files changed, 85 insertions(+), 63 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 4537adc2..0113c2b4 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -18,7 +18,7 @@ from primaite.simulator.network.hardware.node_operating_state import NodeOperati from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader, UDPHeader +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader from primaite.simulator.system.applications.application import Application from primaite.simulator.system.core.packet_capture import PacketCapture from primaite.simulator.system.core.session_manager import SessionManager @@ -761,29 +761,30 @@ class ARPCache: minimized or controlled to specific subnets. It is mainly used by the router to prevent ARP requests being sent back to their source. """ - for nic in self.nics.values(): - use_nic = True - if ignore_networks: - for ipv4 in ignore_networks: - if ipv4 in nic.ip_network: - use_nic = False - if nic.enabled and use_nic: - self.sys_log.info(f"Sending ARP request from NIC {nic} for ip {target_ip_address}") - udp_header = UDPHeader(src_port=Port.ARP, dst_port=Port.ARP) - - # Network Layer - ip_packet = IPPacket( - src_ip_address=nic.ip_address, dst_ip_address=target_ip_address, protocol=IPProtocol.UDP - ) - # Data Link Layer - ethernet_header = EthernetHeader(src_mac_addr=nic.mac_address, dst_mac_addr="ff:ff:ff:ff:ff:ff") - arp_packet = ARPPacket( - sender_ip_address=nic.ip_address, - sender_mac_addr=nic.mac_address, - target_ip_address=target_ip_address, - ) - frame = Frame(ethernet=ethernet_header, ip=ip_packet, udp=udp_header, payload=arp_packet) - nic.send_frame(frame) + pass + # for nic in self.nics.values(): + # use_nic = True + # if ignore_networks: + # for ipv4 in ignore_networks: + # if ipv4 in nic.ip_network: + # use_nic = False + # if nic.enabled and use_nic: + # self.sys_log.info(f"Sending ARP request from NIC {nic} for ip {target_ip_address}") + # udp_header = UDPHeader(src_port=Port.ARP, dst_port=Port.ARP) + # + # # Network Layer + # ip_packet = IPPacket( + # src_ip_address=nic.ip_address, dst_ip_address=target_ip_address, protocol=IPProtocol.UDP + # ) + # # Data Link Layer + # ethernet_header = EthernetHeader(src_mac_addr=nic.mac_address, dst_mac_addr="ff:ff:ff:ff:ff:ff") + # arp_packet = ARPPacket( + # sender_ip_address=nic.ip_address, + # sender_mac_addr=nic.mac_address, + # target_ip_address=target_ip_address, + # ) + # frame = Frame(ethernet=ethernet_header, ip=ip_packet, udp=udp_header, payload=arp_packet) + # nic.send_frame(frame) def send_arp_reply(self, arp_reply: ARPPacket, from_nic: NIC): """ @@ -860,7 +861,7 @@ class ICMP: Provides functionalities for managing and handling ICMP packets, including echo requests and replies. """ - def __init__(self, sys_log: SysLog, arp_cache: ARPCache): + def __init__(self, sys_log: SysLog): """ Initialize the ICMP (Internet Control Message Protocol) service. @@ -868,7 +869,7 @@ class ICMP: :param arp_cache: The ARP cache for resolving IP to MAC address mappings. """ self.sys_log: SysLog = sys_log - self.arp: ARPCache = arp_cache + self.software_manager: SoftwareManager = None ## noqa self.request_replies = {} def clear(self): @@ -884,11 +885,11 @@ class ICMP: if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: if not is_reattempt: self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") - target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip_address) + target_mac_address = self.software_manager.arp.get_arp_cache_mac_address(frame.ip.src_ip_address) - src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip_address) + src_nic = self.software_manager.arp.get_arp_cache_nic(frame.ip.src_ip_address) if not src_nic: - self.arp.send_arp_request(frame.ip.src_ip_address) + self.software_manager.arp.send_arp_request(frame.ip.src_ip_address) self.process_icmp(frame=frame, from_nic=from_nic, is_reattempt=True) return @@ -934,16 +935,16 @@ class ICMP: :return: A tuple containing the next sequence number and the identifier, or (0, None) if the target IP address was not found in the ARP cache. """ - nic = self.arp.get_arp_cache_nic(target_ip_address) + nic = self.software_manager.arp.get_arp_cache_nic(target_ip_address) if not nic: return pings, None # ARP entry exists sequence += 1 - target_mac_address = self.arp.get_arp_cache_mac_address(target_ip_address) + target_mac_address = self.software_manager.arp.get_arp_cache_mac_address(target_ip_address) - src_nic = self.arp.get_arp_cache_nic(target_ip_address) + src_nic = self.software_manager.arp.get_arp_cache_nic(target_ip_address) tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) # Network Layer @@ -998,7 +999,6 @@ class Node(SimComponent): root: Path "Root directory for simulation output." sys_log: SysLog - arp: ARPCache icmp: ICMP session_manager: SessionManager software_manager: SoftwareManager @@ -1042,10 +1042,8 @@ class Node(SimComponent): kwargs["default_gateway"] = IPv4Address(kwargs["default_gateway"]) if not kwargs.get("sys_log"): kwargs["sys_log"] = SysLog(kwargs["hostname"]) - if not kwargs.get("arp"): - kwargs["arp"] = ARPCache(sys_log=kwargs.get("sys_log")) if not kwargs.get("icmp"): - kwargs["icmp"] = ICMP(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp")) + kwargs["icmp"] = ICMP(sys_log=kwargs.get("sys_log")) if not kwargs.get("session_manager"): kwargs["session_manager"] = SessionManager(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp")) if not kwargs.get("root"): @@ -1061,12 +1059,13 @@ class Node(SimComponent): dns_server=kwargs.get("dns_server"), ) super().__init__(**kwargs) - self.arp.nics = self.nics - self.arp.node = self + self.icmp.software_manager = self.software_manager + self.session_manager.node = self self.session_manager.software_manager = self.software_manager self._install_system_software() self.set_original_state() + def set_original_state(self): """Sets the original state.""" for software in self.software_manager.software.values(): @@ -1489,8 +1488,8 @@ class Node(SimComponent): """ if self.operating_state == NodeOperatingState.ON: if frame.ip: - if frame.ip.src_ip_address in self.arp: - self.arp.add_arp_cache_entry( + if frame.ip.src_ip_address in self.software_manager.arp: + self.software_manager.arp.add_arp_cache_entry( ip_address=frame.ip.src_ip_address, mac_address=frame.ethernet.src_mac_addr, nic=from_nic ) if frame.ip.protocol == IPProtocol.ICMP: diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 8c305032..15001806 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -6,6 +6,7 @@ from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING, Union from prettytable import MARKDOWN, PrettyTable from primaite.simulator.core import SimComponent +from primaite.simulator.network.protocols.arp import ARPPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader, UDPHeader @@ -80,7 +81,9 @@ class SessionManager: self.sessions_by_uuid: Dict[str, Session] = {} self.sys_log: SysLog = sys_log self.software_manager: SoftwareManager = None # Noqa - self.arp_cache: "ARPCache" = arp_cache + self.node: Node = None # noqa + + def describe_state(self) -> Dict: """ @@ -138,9 +141,17 @@ class SessionManager: dst_port = None return protocol, with_ip_address, src_port, dst_port + def resolve_outbound_nic(self, dst_ip_address: IPv4Address) -> Optional[NIC]: + for nic in self.node.nics.values(): + if dst_ip_address in nic.ip_network and nic.enabled: + return nic + return self.software_manager.arp.get_default_gateway_nic() + def resolve_outbound_transmission_details( self, dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, session_id: Optional[str] = None ) -> Tuple[Optional["NIC"], Optional[str], Optional[IPProtocol], bool]: + if not isinstance(dst_ip_address, IPv4Address): + dst_ip_address = IPv4Address(dst_ip_address) is_broadcast = False outbound_nic = None dst_mac_address = None @@ -160,7 +171,7 @@ class SessionManager: dst_ip_address = dst_ip_address.broadcast_address if dst_ip_address: # Find a suitable NIC for the broadcast - for nic in self.arp_cache.nics.values(): + for nic in self.node.nics.values(): if dst_ip_address in nic.ip_network and nic.enabled: dst_mac_address = "ff:ff:ff:ff:ff:ff" outbound_nic = nic @@ -168,18 +179,18 @@ class SessionManager: else: # Resolve MAC address for unicast transmission use_default_gateway = True - for nic in self.arp_cache.nics.values(): + for nic in self.node.nics.values(): if dst_ip_address in nic.ip_network and nic.enabled: - dst_mac_address = self.arp_cache.get_arp_cache_mac_address(dst_ip_address) + dst_mac_address = self.software_manager.arp.get_arp_cache_mac_address(dst_ip_address) break if dst_ip_address: use_default_gateway = False - outbound_nic = self.arp_cache.get_arp_cache_nic(dst_ip_address) + outbound_nic = self.software_manager.arp.get_arp_cache_nic(dst_ip_address) if use_default_gateway: - dst_mac_address = self.arp_cache.get_default_gateway_mac_address() - outbound_nic = self.arp_cache.get_default_gateway_nic() + dst_mac_address = self.software_manager.arp.get_default_gateway_mac_address() + outbound_nic = self.software_manager.arp.get_default_gateway_nic() return outbound_nic, dst_mac_address, protocol, is_broadcast def receive_payload_from_software_manager( @@ -203,15 +214,23 @@ class SessionManager: :param session_id: The Session ID from which the payload originates. Optional. :return: The outcome of sending the frame, or None if sending was unsuccessful. """ - print(ip_protocol) - outbound_nic, dst_mac_address, protocol, is_broadcast = self.resolve_outbound_transmission_details( - dst_ip_address=dst_ip_address, session_id=session_id - ) + if isinstance(payload, ARPPacket): + # ARP requests need to be handles differently + if payload.request: + dst_mac_address = "ff:ff:ff:ff:ff:ff" + else: + dst_mac_address = payload.sender_mac_addr + outbound_nic = self.resolve_outbound_nic(payload.target_ip_address) + is_broadcast = payload.request + ip_protocol = IPProtocol.UDP + else: + outbound_nic, dst_mac_address, protocol, is_broadcast = self.resolve_outbound_transmission_details( + dst_ip_address=dst_ip_address, session_id=session_id + ) - if protocol: - ip_protocol = protocol + if protocol: + ip_protocol = protocol - print(ip_protocol) # Check if outbound NIC and destination MAC address are resolved if not outbound_nic or not dst_mac_address: @@ -224,21 +243,21 @@ class SessionManager: src_port=dst_port, dst_port=dst_port, ) - elif ip_protocol == IPProtocol: + elif ip_protocol == IPProtocol.UDP: udp_header = UDPHeader( src_port=dst_port, dst_port=dst_port, ) # Construct the frame for transmission + frame = Frame( ethernet=EthernetHeader(src_mac_addr=outbound_nic.mac_address, dst_mac_addr=dst_mac_address), - ip=IPPacket(src_ip_address=outbound_nic.ip_address, dst_ip_address=dst_ip_address, ip_protocol=ip_protocol), + ip=IPPacket(src_ip_address=outbound_nic.ip_address, dst_ip_address=dst_ip_address, protocol=ip_protocol), tcp=tcp_header, - udp_header=udp_header, + udp=udp_header, payload=payload, ) - print(frame) # Manage session for unicast transmission if not (is_broadcast and session_id): diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index e1ec6698..f23e2f55 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -15,6 +15,7 @@ if TYPE_CHECKING: from primaite.simulator.system.core.session_manager import SessionManager from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.network.hardware.base import Node, NIC + from primaite.simulator.system.services.arp.arp import ARP from typing import Type, TypeVar @@ -46,6 +47,10 @@ class SoftwareManager: self.file_system: FileSystem = file_system self.dns_server: Optional[IPv4Address] = dns_server + @property + def arp(self) -> 'ARP': + return self.software.get("ARP") # noqa + def get_open_ports(self) -> List[Port]: """ Get a list of open ports. diff --git a/src/primaite/simulator/system/services/arp/arp.py b/src/primaite/simulator/system/services/arp/arp.py index 46bc151d..136718c2 100644 --- a/src/primaite/simulator/system/services/arp/arp.py +++ b/src/primaite/simulator/system/services/arp/arp.py @@ -105,8 +105,7 @@ class ARP(Service): minimized or controlled to specific subnets. It is mainly used by the router to prevent ARP requests being sent back to their source. """ - vals: Tuple = self.software_manager.session_manager.resolve_outbound_transmission_details(target_ip_address) - outbound_nic, _, _, _ = vals + outbound_nic = self.software_manager.session_manager.resolve_outbound_nic(target_ip_address) if outbound_nic: self.sys_log.info(f"Sending ARP request from NIC {outbound_nic} for ip {target_ip_address}") arp_packet = ARPPacket( @@ -114,8 +113,8 @@ class ARP(Service): sender_mac_addr=outbound_nic.mac_address, target_ip_address=target_ip_address, ) - self.software_manager.session_manager.receive_payload_from_software_manage( - payload=arp_packet, dst_port=Port.ARP, ip_protocol=self.protocol + self.software_manager.session_manager.receive_payload_from_software_manager( + payload=arp_packet, dst_ip_address=target_ip_address, dst_port=Port.ARP, ip_protocol=self.protocol ) else: print(f"failed for {target_ip_address}") diff --git a/src/primaite/simulator/system/services/arp/host_arp.py b/src/primaite/simulator/system/services/arp/host_arp.py index 678bedbe..8bf3369b 100644 --- a/src/primaite/simulator/system/services/arp/host_arp.py +++ b/src/primaite/simulator/system/services/arp/host_arp.py @@ -53,7 +53,7 @@ class HostARP(ARP): arp_entry = self.arp.get(ip_address) if arp_entry: - return self.nics[arp_entry.nic_uuid] + return self.software_manager.node.nics[arp_entry.nic_uuid] else: if not is_reattempt: self.send_arp_request(ip_address) From 4c6ae135cdf93a2ccc83f94ab578654112001661 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 2 Feb 2024 14:48:49 +0000 Subject: [PATCH 558/980] Fix typos --- src/primaite/game/agent/actions.py | 20 +++++++++---------- src/primaite/game/agent/rewards.py | 4 ++-- .../simulator/network/hardware/base.py | 3 ++- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 6123da50..d5b78a16 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -398,8 +398,8 @@ class NetworkACLAddRuleAction(AbstractAction): :param manager: Reference to the ActionManager which created this action. :type manager: ActionManager - :param target_router_name: hostname of the router to which the ACL rule should be added. - :type target_router_name: str + :param target_router_hostname: hostname of the router to which the ACL rule should be added. + :type target_router_hostname: str :param max_acl_rules: Maximum number of ACL rules that can be added to the router. :type max_acl_rules: int :param num_ips: Number of IP addresses in the simulation. @@ -508,8 +508,8 @@ class NetworkACLRemoveRuleAction(AbstractAction): :param manager: Reference to the ActionManager which created this action. :type manager: ActionManager - :param target_router_name: Hostname of the router from which the ACL rule should be removed. - :type target_router_name: str + :param target_router_hostname: Hostname of the router from which the ACL rule should be removed. + :type target_router_hostname: str :param max_acl_rules: Maximum number of ACL rules that can be added to the router. :type max_acl_rules: int """ @@ -629,7 +629,7 @@ class ActionManager: 'type' and 'options' for passing any options to the action class's init method :type actions: List[dict] :param nodes: Extra configuration for each node. - :type nodes: Dict + :type nodes: List[Dict] :param max_folders_per_node: Maximum number of folders per node. Used for calculating action shape. :type max_folders_per_node: int :param max_files_per_folder: Maximum number of files per folder. Used for calculating action shape. @@ -679,24 +679,24 @@ class ActionManager: """ # Populate lists of apps, services, files, folders, etc on nodes. - for n in nodes: - app_list = [a["application_name"] for a in n.get("applications", [])] + for node in nodes: + app_list = [a["application_name"] for a in node.get("applications", [])] while len(app_list) < max_applications_per_node: app_list.append(None) self.application_names.append(app_list) - svc_list = [s["service_name"] for s in n.get("services", [])] + svc_list = [s["service_name"] for s in node.get("services", [])] while len(svc_list) < max_services_per_node: svc_list.append(None) self.service_names.append(svc_list) - folder_list = [f["folder_name"] for f in n.get("folders", [])] + folder_list = [f["folder_name"] for f in node.get("folders", [])] while len(folder_list) < max_folders_per_node: folder_list.append(None) self.folder_names.append(folder_list) file_sublist = [] - for folder in n.get("folders", [{"files": []}]): + for folder in node.get("folders", [{"files": []}]): file_list = [f["file_name"] for f in folder.get("files", [])] while len(file_list) < max_files_per_folder: file_list.append(None) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 0b292bcb..8944a184 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -218,7 +218,7 @@ class RewardFunction: self.current_reward: float = 0.0 self.total_reward: float = 0.0 - def regsiter_component(self, component: AbstractReward, weight: float = 1.0) -> None: + def register_component(self, component: AbstractReward, weight: float = 1.0) -> None: """Add a reward component to the reward function. :param component: Instance of a reward component. @@ -260,5 +260,5 @@ class RewardFunction: weight = rew_component_cfg.get("weight", 1.0) rew_class = cls.__rew_class_identifiers[rew_type] rew_instance = rew_class.from_config(config=rew_component_cfg.get("options", {}), game=game) - new.regsiter_component(component=rew_instance, weight=weight) + new.register_component(component=rew_instance, weight=weight) return new diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 8e4c1d76..5334021a 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1388,7 +1388,8 @@ class Node(SimComponent): nic.parent = None nic.disable() self.sys_log.info(f"Disconnected NIC {nic}") - self._nic_request_manager.remove_request(nic_num) + if nic_num != -1: + self._nic_request_manager.remove_request(nic_num) else: msg = f"Cannot disconnect NIC {nic} as it is not connected" self.sys_log.logger.error(msg) From 87d9d6da044fab4a1a15182ad4632a6ca384cab2 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 2 Feb 2024 15:35:02 +0000 Subject: [PATCH 559/980] #2248 - Initial work has been done on moving ICMP into services. still tidying up to be done. Need to fix tests too. --- .../simulator/network/hardware/base.py | 174 ++---------------- .../simulator/network/hardware/nodes/host.py | 67 +++++++ .../network/hardware/nodes/router.py | 99 +--------- .../simulator/network/protocols/icmp.py | 114 ++++++++++++ .../network/transmission/data_link_layer.py | 3 +- .../network/transmission/network_layer.py | 104 ----------- .../network/transmission/transport_layer.py | 2 + .../simulator/system/core/session_manager.py | 9 +- .../simulator/system/core/software_manager.py | 15 +- src/primaite/simulator/system/core/sys_log.py | 25 ++- .../simulator/system/services/arp/arp.py | 7 +- .../system/services/icmp/__init__.py | 0 .../simulator/system/services/icmp/icmp.py | 159 ++++++++++++++++ .../system/services/icmp/router_icmp.py | 90 +++++++++ 14 files changed, 495 insertions(+), 373 deletions(-) create mode 100644 src/primaite/simulator/network/hardware/nodes/host.py create mode 100644 src/primaite/simulator/network/protocols/icmp.py create mode 100644 src/primaite/simulator/system/services/icmp/__init__.py create mode 100644 src/primaite/simulator/system/services/icmp/icmp.py create mode 100644 src/primaite/simulator/system/services/icmp/router_icmp.py diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 0113c2b4..7fbaa5f4 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -4,7 +4,7 @@ import re import secrets from ipaddress import IPv4Address, IPv4Network from pathlib import Path -from typing import Any, Dict, List, Literal, Optional, Tuple, Union +from typing import Any, Dict, List, Literal, Optional, Union from prettytable import MARKDOWN, PrettyTable @@ -17,7 +17,7 @@ from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame -from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol +from primaite.simulator.network.transmission.network_layer import IPPacket from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader from primaite.simulator.system.applications.application import Application from primaite.simulator.system.core.packet_capture import PacketCapture @@ -854,113 +854,6 @@ class ARPCache: return item in self.arp -class ICMP: - """ - The ICMP (Internet Control Message Protocol) class. - - Provides functionalities for managing and handling ICMP packets, including echo requests and replies. - """ - - def __init__(self, sys_log: SysLog): - """ - Initialize the ICMP (Internet Control Message Protocol) service. - - :param sys_log: The system log to store system messages and information. - :param arp_cache: The ARP cache for resolving IP to MAC address mappings. - """ - self.sys_log: SysLog = sys_log - self.software_manager: SoftwareManager = None ## noqa - self.request_replies = {} - - def clear(self): - """Clears the ICMP request replies tracker.""" - self.request_replies.clear() - - def process_icmp(self, frame: Frame, from_nic: NIC, is_reattempt: bool = False): - """ - Process an ICMP packet, including handling echo requests and replies. - - :param frame: The Frame containing the ICMP packet to process. - """ - if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: - if not is_reattempt: - self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") - target_mac_address = self.software_manager.arp.get_arp_cache_mac_address(frame.ip.src_ip_address) - - src_nic = self.software_manager.arp.get_arp_cache_nic(frame.ip.src_ip_address) - if not src_nic: - self.software_manager.arp.send_arp_request(frame.ip.src_ip_address) - self.process_icmp(frame=frame, from_nic=from_nic, is_reattempt=True) - return - - # Network Layer - ip_packet = IPPacket( - src_ip_address=src_nic.ip_address, dst_ip_address=frame.ip.src_ip_address, protocol=IPProtocol.ICMP - ) - # Data Link Layer - ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) - icmp_reply_packet = ICMPPacket( - icmp_type=ICMPType.ECHO_REPLY, - icmp_code=0, - identifier=frame.icmp.identifier, - sequence=frame.icmp.sequence + 1, - ) - payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size - frame = Frame(ethernet=ethernet_header, ip=ip_packet, icmp=icmp_reply_packet, payload=payload) - self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip_address}") - - src_nic.send_frame(frame) - elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: - time = frame.transmission_duration() - time_str = f"{time}ms" if time > 0 else "<1ms" - self.sys_log.info( - f"Reply from {frame.ip.src_ip_address}: " - f"bytes={len(frame.payload)}, " - f"time={time_str}, " - f"TTL={frame.ip.ttl}" - ) - if not self.request_replies.get(frame.icmp.identifier): - self.request_replies[frame.icmp.identifier] = 0 - self.request_replies[frame.icmp.identifier] += 1 - - def ping( - self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None, pings: int = 4 - ) -> Tuple[int, Union[int, None]]: - """ - Send an ICMP echo request (ping) to a target IP address and manage the sequence and identifier. - - :param target_ip_address: The target IP address to send the ping. - :param sequence: The sequence number of the echo request. Defaults to 0. - :param identifier: An optional identifier for the ICMP packet. If None, a default will be used. - :return: A tuple containing the next sequence number and the identifier, or (0, None) if the target IP address - was not found in the ARP cache. - """ - nic = self.software_manager.arp.get_arp_cache_nic(target_ip_address) - - if not nic: - return pings, None - - # ARP entry exists - sequence += 1 - target_mac_address = self.software_manager.arp.get_arp_cache_mac_address(target_ip_address) - - src_nic = self.software_manager.arp.get_arp_cache_nic(target_ip_address) - tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) - - # Network Layer - ip_packet = IPPacket( - src_ip_address=nic.ip_address, - dst_ip_address=target_ip_address, - protocol=IPProtocol.ICMP, - ) - # Data Link Layer - ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) - icmp_packet = ICMPPacket(identifier=identifier, sequence=sequence) - payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size - frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, icmp=icmp_packet, payload=payload) - nic.send_frame(frame) - return sequence, icmp_packet.identifier - class Node(SimComponent): """ @@ -999,7 +892,6 @@ class Node(SimComponent): root: Path "Root directory for simulation output." sys_log: SysLog - icmp: ICMP session_manager: SessionManager software_manager: SoftwareManager @@ -1042,8 +934,6 @@ class Node(SimComponent): kwargs["default_gateway"] = IPv4Address(kwargs["default_gateway"]) if not kwargs.get("sys_log"): kwargs["sys_log"] = SysLog(kwargs["hostname"]) - if not kwargs.get("icmp"): - kwargs["icmp"] = ICMP(sys_log=kwargs.get("sys_log")) if not kwargs.get("session_manager"): kwargs["session_manager"] = SessionManager(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp")) if not kwargs.get("root"): @@ -1059,7 +949,6 @@ class Node(SimComponent): dns_server=kwargs.get("dns_server"), ) super().__init__(**kwargs) - self.icmp.software_manager = self.software_manager self.session_manager.node = self self.session_manager.software_manager = self.software_manager self._install_system_software() @@ -1096,12 +985,6 @@ class Node(SimComponent): """Reset the original state of the SimComponent.""" super().reset_component_for_episode(episode) - # Reset ARP Cache - self.arp.clear() - - # Reset ICMP - self.icmp.clear() - # Reset Session Manager self.session_manager.clear() @@ -1436,35 +1319,9 @@ class Node(SimComponent): :param pings: The number of pings to attempt, default is 4. :return: True if the ping is successful, otherwise False. """ - if self.operating_state == NodeOperatingState.ON: - if not isinstance(target_ip_address, IPv4Address): - target_ip_address = IPv4Address(target_ip_address) - if target_ip_address.is_loopback: - self.sys_log.info("Pinging loopback address") - return any(nic.enabled for nic in self.nics.values()) - if self.operating_state == NodeOperatingState.ON: - output = f"Pinging {target_ip_address}:" - self.sys_log.info(output) - print(output) - sequence, identifier = 0, None - while sequence < pings: - sequence, identifier = self.icmp.ping(target_ip_address, sequence, identifier, pings) - request_replies = self.icmp.request_replies.get(identifier) - passed = request_replies == pings - if request_replies: - self.icmp.request_replies.pop(identifier) - else: - request_replies = 0 - output = ( - f"Ping statistics for {target_ip_address}: " - f"Packets: Sent = {pings}, " - f"Received = {request_replies}, " - f"Lost = {pings - request_replies} ({(pings - request_replies) / pings * 100}% loss)" - ) - self.sys_log.info(output) - print(output) - return passed - return False + if not isinstance(target_ip_address, IPv4Address): + target_ip_address = IPv4Address(target_ip_address) + return self.software_manager.icmp.ping(target_ip_address) def send_frame(self, frame: Frame): """ @@ -1492,22 +1349,23 @@ class Node(SimComponent): self.software_manager.arp.add_arp_cache_entry( ip_address=frame.ip.src_ip_address, mac_address=frame.ethernet.src_mac_addr, nic=from_nic ) - if frame.ip.protocol == IPProtocol.ICMP: - self.icmp.process_icmp(frame=frame, from_nic=from_nic) - return + # Check if the destination port is open on the Node dst_port = None if frame.tcp: dst_port = frame.tcp.dst_port elif frame.udp: dst_port = frame.udp.dst_port - if dst_port in self.software_manager.get_open_ports(): - # accept thr frame as the port is open + + accept_frame = False + if frame.icmp or dst_port in self.software_manager.get_open_ports(): + # accept the frame as the port is open or if it's an ICMP frame + accept_frame = True + + # TODO: add internal node firewall check here? + + if accept_frame: self.session_manager.receive_frame(frame, from_nic) - # if frame.tcp.src_port == Port.ARP: - # self.arp.process_arp_packet(from_nic=from_nic, arp_packet=frame.arp) - # else: - # self.session_manager.receive_frame(frame) else: # denied as port closed self.sys_log.info(f"Ignoring frame for port {frame.tcp.dst_port.value} from {frame.ip.src_ip_address}") @@ -1527,7 +1385,6 @@ class Node(SimComponent): self.services[service.uuid] = service service.parent = self service.install() # Perform any additional setup, such as creating files for this service on the node. - self.sys_log.info(f"Installed service {service.name}") self._service_request_manager.add_request(service.uuid, RequestType(func=service._request_manager)) def uninstall_service(self, service: Service) -> None: @@ -1559,7 +1416,6 @@ class Node(SimComponent): return self.applications[application.uuid] = application application.parent = self - self.sys_log.info(f"Installed application {application.name}") self._application_request_manager.add_request(application.uuid, RequestType(func=application._request_manager)) def uninstall_application(self, application: Application) -> None: diff --git a/src/primaite/simulator/network/hardware/nodes/host.py b/src/primaite/simulator/network/hardware/nodes/host.py new file mode 100644 index 00000000..f4fc1586 --- /dev/null +++ b/src/primaite/simulator/network/hardware/nodes/host.py @@ -0,0 +1,67 @@ +from primaite.simulator.network.hardware.base import NIC, Node +from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.arp.host_arp import HostARP +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.icmp.icmp import ICMP +from primaite.simulator.system.services.ntp.ntp_client import NTPClient + + +class Host(Node): + """ + A basic Host class. + + Example: + >>> pc_a = Host( + hostname="pc_a", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1" + ) + >>> pc_a.power_on() + + Instances of computer come 'pre-packaged' with the following: + + * Core Functionality: + * ARP + * ICMP + * Packet Capture + * Sys Log + * Services: + * DNS Client + * FTP Client + * LDAP Client + * NTP Client + * Applications: + * Email Client + * Web Browser + * Processes: + * Placeholder + """ + + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.connect_nic(NIC(ip_address=kwargs["ip_address"], subnet_mask=kwargs["subnet_mask"])) + self._install_system_software() + + def _install_system_software(self): + """Install System Software - software that is usually provided with the OS.""" + # ARP Service + self.software_manager.install(HostARP) + + # ICMP Service + self.software_manager.install(ICMP) + + # DNS Client + self.software_manager.install(DNSClient) + + # FTP Client + self.software_manager.install(FTPClient) + + # NTP Client + self.software_manager.install(NTPClient) + + # Web Browser + self.software_manager.install(WebBrowser) + + super()._install_system_software() diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index ed9a30d4..53277d69 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -8,10 +8,10 @@ from typing import Dict, List, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable from primaite.simulator.core import RequestManager, RequestType, SimComponent -from primaite.simulator.network.hardware.base import ARPCache, ICMP, NIC, Node +from primaite.simulator.network.hardware.base import ARPCache, NIC, Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame -from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol +from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader from primaite.simulator.system.core.sys_log import SysLog @@ -628,96 +628,6 @@ class RouterARPCache(ARPCache): # return -class RouterICMP(ICMP): - """ - A class to represent a router's Internet Control Message Protocol (ICMP) handler. - - :param sys_log: System log for logging network events and errors. - :type sys_log: SysLog - :param arp_cache: The ARP cache for resolving MAC addresses. - :type arp_cache: ARPCache - :param router: The router to which this ICMP handler belongs. - :type router: Router - """ - - router: Router - - def __init__(self, sys_log: SysLog, arp_cache: ARPCache, router: Router): - super().__init__(sys_log, arp_cache) - self.router = router - - def process_icmp(self, frame: Frame, from_nic: NIC, is_reattempt: bool = False): - """ - Process incoming ICMP frames based on ICMP type. - - :param frame: The incoming frame to process. - :param from_nic: The network interface where the frame is coming from. - :param is_reattempt: Flag to indicate if the process is a reattempt. - """ - if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: - # determine if request is for router interface or whether it needs to be routed - - for nic in self.router.nics.values(): - if nic.ip_address == frame.ip.dst_ip_address: - if nic.enabled: - # reply to the request - if not is_reattempt: - self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") - target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip_address) - src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip_address) - tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) - - # Network Layer - ip_packet = IPPacket( - src_ip_address=nic.ip_address, - dst_ip_address=frame.ip.src_ip_address, - protocol=IPProtocol.ICMP, - ) - # Data Link Layer - ethernet_header = EthernetHeader( - src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address - ) - icmp_reply_packet = ICMPPacket( - icmp_type=ICMPType.ECHO_REPLY, - icmp_code=0, - identifier=frame.icmp.identifier, - sequence=frame.icmp.sequence + 1, - ) - payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size - frame = Frame( - ethernet=ethernet_header, - ip=ip_packet, - tcp=tcp_header, - icmp=icmp_reply_packet, - payload=payload, - ) - self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip_address}") - - src_nic.send_frame(frame) - return - - # Route the frame - self.router.process_frame(frame, from_nic) - - elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: - for nic in self.router.nics.values(): - if nic.ip_address == frame.ip.dst_ip_address: - if nic.enabled: - time = frame.transmission_duration() - time_str = f"{time}ms" if time > 0 else "<1ms" - self.sys_log.info( - f"Reply from {frame.ip.src_ip_address}: " - f"bytes={len(frame.payload)}, " - f"time={time_str}, " - f"TTL={frame.ip.ttl}" - ) - if not self.request_replies.get(frame.icmp.identifier): - self.request_replies[frame.icmp.identifier] = 0 - self.request_replies[frame.icmp.identifier] += 1 - - return - # Route the frame - self.router.process_frame(frame, from_nic) class RouterNIC(NIC): @@ -786,9 +696,10 @@ class Router(Node): kwargs["route_table"] = RouteTable(sys_log=kwargs["sys_log"]) if not kwargs.get("arp"): kwargs["arp"] = RouterARPCache(sys_log=kwargs.get("sys_log"), router=self) - if not kwargs.get("icmp"): - kwargs["icmp"] = RouterICMP(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp"), router=self) + # if not kwargs.get("icmp"): + # kwargs["icmp"] = RouterICMP(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp"), router=self) super().__init__(hostname=hostname, num_ports=num_ports, **kwargs) + # TODO: Install RoputerICMP for i in range(1, self.num_ports + 1): nic = RouterNIC(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") self.connect_nic(nic) diff --git a/src/primaite/simulator/network/protocols/icmp.py b/src/primaite/simulator/network/protocols/icmp.py new file mode 100644 index 00000000..9f761393 --- /dev/null +++ b/src/primaite/simulator/network/protocols/icmp.py @@ -0,0 +1,114 @@ +import secrets +from enum import Enum +from typing import Union + +from pydantic import BaseModel, field_validator, validate_call +from pydantic_core.core_schema import FieldValidationInfo + +from primaite import getLogger + +_LOGGER = getLogger(__name__) + + +class ICMPType(Enum): + """Enumeration of common ICMP (Internet Control Message Protocol) types.""" + + ECHO_REPLY = 0 + "Echo Reply message." + DESTINATION_UNREACHABLE = 3 + "Destination Unreachable." + REDIRECT = 5 + "Redirect." + ECHO_REQUEST = 8 + "Echo Request (ping)." + ROUTER_ADVERTISEMENT = 10 + "Router Advertisement." + ROUTER_SOLICITATION = 11 + "Router discovery/selection/solicitation." + TIME_EXCEEDED = 11 + "Time Exceeded." + TIMESTAMP_REQUEST = 13 + "Timestamp Request." + TIMESTAMP_REPLY = 14 + "Timestamp Reply." + + +@validate_call +def get_icmp_type_code_description(icmp_type: ICMPType, icmp_code: int) -> Union[str, None]: + """ + Maps ICMPType and code pairings to their respective description. + + :param icmp_type: An ICMPType. + :param icmp_code: An icmp code. + :return: The icmp type and code pairing description if it exists, otherwise returns None. + """ + icmp_code_descriptions = { + ICMPType.ECHO_REPLY: {0: "Echo reply"}, + ICMPType.DESTINATION_UNREACHABLE: { + 0: "Destination network unreachable", + 1: "Destination host unreachable", + 2: "Destination protocol unreachable", + 3: "Destination port unreachable", + 4: "Fragmentation required", + 5: "Source route failed", + 6: "Destination network unknown", + 7: "Destination host unknown", + 8: "Source host isolated", + 9: "Network administratively prohibited", + 10: "Host administratively prohibited", + 11: "Network unreachable for ToS", + 12: "Host unreachable for ToS", + 13: "Communication administratively prohibited", + 14: "Host Precedence Violation", + 15: "Precedence cutoff in effect", + }, + ICMPType.REDIRECT: { + 0: "Redirect Datagram for the Network", + 1: "Redirect Datagram for the Host", + }, + ICMPType.ECHO_REQUEST: {0: "Echo request"}, + ICMPType.ROUTER_ADVERTISEMENT: {0: "Router Advertisement"}, + ICMPType.ROUTER_SOLICITATION: {0: "Router discovery/selection/solicitation"}, + ICMPType.TIME_EXCEEDED: {0: "TTL expired in transit", 1: "Fragment reassembly time exceeded"}, + ICMPType.TIMESTAMP_REQUEST: {0: "Timestamp Request"}, + ICMPType.TIMESTAMP_REPLY: {0: "Timestamp reply"}, + } + return icmp_code_descriptions[icmp_type].get(icmp_code) + + +class ICMPPacket(BaseModel): + """Models an ICMP Packet.""" + + icmp_type: ICMPType = ICMPType.ECHO_REQUEST + "ICMP Type." + icmp_code: int = 0 + "ICMP Code." + identifier: int + "ICMP identifier (16 bits randomly generated)." + sequence: int = 0 + "ICMP message sequence number." + + def __init__(self, **kwargs): + if not kwargs.get("identifier"): + kwargs["identifier"] = secrets.randbits(16) + super().__init__(**kwargs) + + @field_validator("icmp_code") # noqa + @classmethod + def _icmp_type_must_have_icmp_code(cls, v: int, info: FieldValidationInfo) -> int: + """Validates the icmp_type and icmp_code.""" + icmp_type = info.data["icmp_type"] + if get_icmp_type_code_description(icmp_type, v): + return v + msg = f"No Matching ICMP code for type:{icmp_type.name}, code:{v}" + _LOGGER.error(msg) + raise ValueError(msg) + + def code_description(self) -> str: + """The icmp_code description.""" + description = get_icmp_type_code_description(self.icmp_type, self.icmp_code) + if description: + return description + msg = f"No Matching ICMP code for type:{self.icmp_type.name}, code:{self.icmp_code}" + _LOGGER.error(msg) + raise ValueError(msg) \ No newline at end of file diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index 6a4e24d8..5c25df01 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -5,8 +5,9 @@ from pydantic import BaseModel from primaite import getLogger from primaite.simulator.network.protocols.arp import ARPPacket +from primaite.simulator.network.protocols.icmp import ICMPPacket from primaite.simulator.network.protocols.packet import DataPacket -from primaite.simulator.network.transmission.network_layer import ICMPPacket, IPPacket, IPProtocol +from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol from primaite.simulator.network.transmission.primaite_layer import PrimaiteHeader from primaite.simulator.network.transmission.transport_layer import TCPHeader, UDPHeader from primaite.simulator.network.utils import convert_bytes_to_megabits diff --git a/src/primaite/simulator/network/transmission/network_layer.py b/src/primaite/simulator/network/transmission/network_layer.py index fd36fbf8..b581becd 100644 --- a/src/primaite/simulator/network/transmission/network_layer.py +++ b/src/primaite/simulator/network/transmission/network_layer.py @@ -54,110 +54,6 @@ class Precedence(Enum): "Highest priority level, used for the most critical network control messages, such as routing protocol hellos." -class ICMPType(Enum): - """Enumeration of common ICMP (Internet Control Message Protocol) types.""" - - ECHO_REPLY = 0 - "Echo Reply message." - DESTINATION_UNREACHABLE = 3 - "Destination Unreachable." - REDIRECT = 5 - "Redirect." - ECHO_REQUEST = 8 - "Echo Request (ping)." - ROUTER_ADVERTISEMENT = 10 - "Router Advertisement." - ROUTER_SOLICITATION = 11 - "Router discovery/selection/solicitation." - TIME_EXCEEDED = 11 - "Time Exceeded." - TIMESTAMP_REQUEST = 13 - "Timestamp Request." - TIMESTAMP_REPLY = 14 - "Timestamp Reply." - - -@validate_call -def get_icmp_type_code_description(icmp_type: ICMPType, icmp_code: int) -> Union[str, None]: - """ - Maps ICMPType and code pairings to their respective description. - - :param icmp_type: An ICMPType. - :param icmp_code: An icmp code. - :return: The icmp type and code pairing description if it exists, otherwise returns None. - """ - icmp_code_descriptions = { - ICMPType.ECHO_REPLY: {0: "Echo reply"}, - ICMPType.DESTINATION_UNREACHABLE: { - 0: "Destination network unreachable", - 1: "Destination host unreachable", - 2: "Destination protocol unreachable", - 3: "Destination port unreachable", - 4: "Fragmentation required", - 5: "Source route failed", - 6: "Destination network unknown", - 7: "Destination host unknown", - 8: "Source host isolated", - 9: "Network administratively prohibited", - 10: "Host administratively prohibited", - 11: "Network unreachable for ToS", - 12: "Host unreachable for ToS", - 13: "Communication administratively prohibited", - 14: "Host Precedence Violation", - 15: "Precedence cutoff in effect", - }, - ICMPType.REDIRECT: { - 0: "Redirect Datagram for the Network", - 1: "Redirect Datagram for the Host", - }, - ICMPType.ECHO_REQUEST: {0: "Echo request"}, - ICMPType.ROUTER_ADVERTISEMENT: {0: "Router Advertisement"}, - ICMPType.ROUTER_SOLICITATION: {0: "Router discovery/selection/solicitation"}, - ICMPType.TIME_EXCEEDED: {0: "TTL expired in transit", 1: "Fragment reassembly time exceeded"}, - ICMPType.TIMESTAMP_REQUEST: {0: "Timestamp Request"}, - ICMPType.TIMESTAMP_REPLY: {0: "Timestamp reply"}, - } - return icmp_code_descriptions[icmp_type].get(icmp_code) - - -class ICMPPacket(BaseModel): - """Models an ICMP Packet.""" - - icmp_type: ICMPType = ICMPType.ECHO_REQUEST - "ICMP Type." - icmp_code: int = 0 - "ICMP Code." - identifier: int - "ICMP identifier (16 bits randomly generated)." - sequence: int = 0 - "ICMP message sequence number." - - def __init__(self, **kwargs): - if not kwargs.get("identifier"): - kwargs["identifier"] = secrets.randbits(16) - super().__init__(**kwargs) - - @field_validator("icmp_code") # noqa - @classmethod - def _icmp_type_must_have_icmp_code(cls, v: int, info: FieldValidationInfo) -> int: - """Validates the icmp_type and icmp_code.""" - icmp_type = info.data["icmp_type"] - if get_icmp_type_code_description(icmp_type, v): - return v - msg = f"No Matching ICMP code for type:{icmp_type.name}, code:{v}" - _LOGGER.error(msg) - raise ValueError(msg) - - def code_description(self) -> str: - """The icmp_code description.""" - description = get_icmp_type_code_description(self.icmp_type, self.icmp_code) - if description: - return description - msg = f"No Matching ICMP code for type:{self.icmp_type.name}, code:{self.icmp_code}" - _LOGGER.error(msg) - raise ValueError(msg) - - class IPPacket(BaseModel): """ Represents the IP layer of a network frame. diff --git a/src/primaite/simulator/network/transmission/transport_layer.py b/src/primaite/simulator/network/transmission/transport_layer.py index d4318baf..7c7509ab 100644 --- a/src/primaite/simulator/network/transmission/transport_layer.py +++ b/src/primaite/simulator/network/transmission/transport_layer.py @@ -7,6 +7,8 @@ from pydantic import BaseModel class Port(Enum): """Enumeration of common known TCP/UDP ports used by protocols for operation of network applications.""" + NONE = 0 + "Place holder for a non-port." WOL = 9 "Wake-on-Lan (WOL) - Used to turn or awaken a computer from sleep mode by a network message." FTP_DATA = 20 diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 15001806..c134f56a 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -293,8 +293,15 @@ class SessionManager: dst_port = frame.tcp.dst_port elif frame.udp: dst_port = frame.udp.dst_port + elif frame.icmp: + dst_port = Port.NONE self.software_manager.receive_payload_from_session_manager( - payload=frame.payload, port=dst_port, protocol=frame.ip.protocol, session_id=session.uuid, from_nic=from_nic + payload=frame.payload, + port=dst_port, + protocol=frame.ip.protocol, + session_id=session.uuid, + from_nic=from_nic, + frame=frame ) def show(self, markdown: bool = False): diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index f23e2f55..ac765018 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -4,6 +4,7 @@ from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING, Union from prettytable import MARKDOWN, PrettyTable from primaite.simulator.file_system.file_system import FileSystem +from primaite.simulator.network.transmission.data_link_layer import Frame from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application, ApplicationOperatingState @@ -16,6 +17,7 @@ if TYPE_CHECKING: from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.network.hardware.base import Node, NIC from primaite.simulator.system.services.arp.arp import ARP + from primaite.simulator.system.services.icmp.icmp import ICMP from typing import Type, TypeVar @@ -51,6 +53,10 @@ class SoftwareManager: def arp(self) -> 'ARP': return self.software.get("ARP") # noqa + @property + def icmp(self) -> 'ICMP': + return self.software.get("ICMP") # noqa + def get_open_ports(self) -> List[Port]: """ Get a list of open ports. @@ -160,7 +166,7 @@ class SoftwareManager: ) def receive_payload_from_session_manager( - self, payload: Any, port: Port, protocol: IPProtocol, session_id: str, from_nic: "NIC" + self, payload: Any, port: Port, protocol: IPProtocol, session_id: str, from_nic: "NIC", frame: Frame ): """ Receive a payload from the SessionManager and forward it to the corresponding service or application. @@ -170,7 +176,7 @@ class SoftwareManager: """ receiver: Optional[Union[Service, Application]] = self.port_protocol_mapping.get((port, protocol), None) if receiver: - receiver.receive(payload=payload, session_id=session_id, from_nic=from_nic) + receiver.receive(payload=payload, session_id=session_id, from_nic=from_nic, frame=frame) else: self.sys_log.error(f"No service or application found for port {port} and protocol {protocol}") pass @@ -181,7 +187,7 @@ class SoftwareManager: :param markdown: If True, outputs the table in markdown format. Default is False. """ - table = PrettyTable(["Name", "Type", "Operating State", "Health State", "Port"]) + table = PrettyTable(["Name", "Type", "Operating State", "Health State", "Port", "Protocol"]) if markdown: table.set_style(MARKDOWN) table.align = "l" @@ -194,7 +200,8 @@ class SoftwareManager: software_type, software.operating_state.name, software.health_state_actual.name, - software.port.value, + software.port.value if software.port != Port.NONE else None, + software.protocol.value ] ) print(table) diff --git a/src/primaite/simulator/system/core/sys_log.py b/src/primaite/simulator/system/core/sys_log.py index 00e6920b..414bacef 100644 --- a/src/primaite/simulator/system/core/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -88,47 +88,62 @@ class SysLog: root.mkdir(exist_ok=True, parents=True) return root / f"{self.hostname}_sys.log" - def debug(self, msg: str): + def debug(self, msg: str, to_terminal: bool = False): """ Logs a message with the DEBUG level. :param msg: The message to be logged. + :param to_terminal: If True, prints to the terminal too. """ if SIM_OUTPUT.save_sys_logs: self.logger.debug(msg) + if to_terminal: + print(msg) - def info(self, msg: str): + def info(self, msg: str, to_terminal: bool = False): """ Logs a message with the INFO level. :param msg: The message to be logged. + :param to_terminal: If True, prints to the terminal too. """ if SIM_OUTPUT.save_sys_logs: self.logger.info(msg) + if to_terminal: + print(msg) - def warning(self, msg: str): + def warning(self, msg: str, to_terminal: bool = False): """ Logs a message with the WARNING level. :param msg: The message to be logged. + :param to_terminal: If True, prints to the terminal too. """ if SIM_OUTPUT.save_sys_logs: self.logger.warning(msg) + if to_terminal: + print(msg) - def error(self, msg: str): + def error(self, msg: str, to_terminal: bool = False): """ Logs a message with the ERROR level. :param msg: The message to be logged. + :param to_terminal: If True, prints to the terminal too. """ if SIM_OUTPUT.save_sys_logs: self.logger.error(msg) + if to_terminal: + print(msg) - def critical(self, msg: str): + def critical(self, msg: str, to_terminal: bool = False): """ Logs a message with the CRITICAL level. :param msg: The message to be logged. + :param to_terminal: If True, prints to the terminal too. """ if SIM_OUTPUT.save_sys_logs: self.logger.critical(msg) + if to_terminal: + print(msg) diff --git a/src/primaite/simulator/system/services/arp/arp.py b/src/primaite/simulator/system/services/arp/arp.py index 136718c2..28a2485c 100644 --- a/src/primaite/simulator/system/services/arp/arp.py +++ b/src/primaite/simulator/system/services/arp/arp.py @@ -2,17 +2,15 @@ from __future__ import annotations from abc import abstractmethod from ipaddress import IPv4Address -from typing import Any, Dict, Optional, Tuple, Union +from typing import Any, Dict, Optional, Union from prettytable import MARKDOWN, PrettyTable -from pydantic import BaseModel from primaite.simulator.network.hardware.base import NIC from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket -from primaite.simulator.network.protocols.packet import DataPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader, UDPHeader +from primaite.simulator.network.transmission.transport_layer import Port, UDPHeader from primaite.simulator.system.services.service import Service @@ -191,7 +189,6 @@ class ARP(Service): from_nic = kwargs.get("from_nic") if payload.request: - print(from_nic) self._process_arp_request(arp_packet=payload, from_nic=from_nic) else: self._process_arp_reply(arp_packet=payload, from_nic=from_nic) diff --git a/src/primaite/simulator/system/services/icmp/__init__.py b/src/primaite/simulator/system/services/icmp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/system/services/icmp/icmp.py b/src/primaite/simulator/system/services/icmp/icmp.py new file mode 100644 index 00000000..16dd4f8c --- /dev/null +++ b/src/primaite/simulator/system/services/icmp/icmp.py @@ -0,0 +1,159 @@ +import secrets +from ipaddress import IPv4Address +from typing import Dict, Any, Union, Optional, Tuple + +from primaite import getLogger +from primaite.simulator.network.hardware.base import NIC +from primaite.simulator.network.protocols.icmp import ICMPPacket, ICMPType +from primaite.simulator.network.transmission.data_link_layer import Frame, EthernetHeader +from primaite.simulator.network.transmission.network_layer import IPProtocol, IPPacket +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.service import Service + +_LOGGER = getLogger(__name__) + + +class ICMP(Service): + request_replies: Dict = {} + + def __init__(self, **kwargs): + kwargs["name"] = "ICMP" + kwargs["port"] = Port.NONE + kwargs["protocol"] = IPProtocol.ICMP + super().__init__(**kwargs) + + def describe_state(self) -> Dict: + pass + + def clear(self): + """Clears the ICMP request replies tracker.""" + self.request_replies.clear() + + def _send_icmp_echo_request( + self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None, pings: int = 4 + ) -> Tuple[int, Union[int, None]]: + """ + Send an ICMP echo request (ping) to a target IP address and manage the sequence and identifier. + + :param target_ip_address: The target IP address to send the ping. + :param sequence: The sequence number of the echo request. Defaults to 0. + :param identifier: An optional identifier for the ICMP packet. If None, a default will be used. + :return: A tuple containing the next sequence number and the identifier, or (0, None) if the target IP address + was not found in the ARP cache. + """ + nic = self.software_manager.arp.get_arp_cache_nic(target_ip_address) + + if not nic: + return pings, None + + # ARP entry exists + sequence += 1 + target_mac_address = self.software_manager.arp.get_arp_cache_mac_address(target_ip_address) + + src_nic = self.software_manager.arp.get_arp_cache_nic(target_ip_address) + + # Network Layer + ip_packet = IPPacket( + src_ip_address=nic.ip_address, + dst_ip_address=target_ip_address, + protocol=IPProtocol.ICMP, + ) + # Data Link Layer + ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) + icmp_packet = ICMPPacket(identifier=identifier, sequence=sequence) + payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size + frame = Frame(ethernet=ethernet_header, ip=ip_packet, icmp=icmp_packet, payload=payload) + nic.send_frame(frame) + return sequence, icmp_packet.identifier + + def ping(self, target_ip_address: Union[IPv4Address, str], pings: int = 4) -> bool: + """ + Ping an IP address, performing a standard ICMP echo request/response. + + :param target_ip_address: The target IP address to ping. + :param pings: The number of pings to attempt, default is 4. + :return: True if the ping is successful, otherwise False. + """ + if not self._can_perform_action(): + return False + if target_ip_address.is_loopback: + self.sys_log.info("Pinging loopback address") + return any(nic.enabled for nic in self.nics.values()) + self.sys_log.info(f"Pinging {target_ip_address}:", to_terminal=True) + sequence, identifier = 0, None + while sequence < pings: + sequence, identifier = self._send_icmp_echo_request( + target_ip_address, sequence, identifier, pings + ) + request_replies = self.software_manager.icmp.request_replies.get(identifier) + passed = request_replies == pings + if request_replies: + self.software_manager.icmp.request_replies.pop(identifier) + else: + request_replies = 0 + output = ( + f"Ping statistics for {target_ip_address}: " + f"Packets: Sent = {pings}, " + f"Received = {request_replies}, " + f"Lost = {pings - request_replies} ({(pings - request_replies) / pings * 100}% loss)" + ) + self.sys_log.info(output, to_terminal=True) + + return passed + + def _process_icmp_echo_request(self, frame: Frame, from_nic: NIC, is_reattempt: bool = False): + if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: + if not is_reattempt: + self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") + target_mac_address = self.software_manager.arp.get_arp_cache_mac_address(frame.ip.src_ip_address) + + src_nic = self.software_manager.arp.get_arp_cache_nic(frame.ip.src_ip_address) + if not src_nic: + self.software_manager.arp.send_arp_request(frame.ip.src_ip_address) + self.process_icmp(frame=frame, from_nic=from_nic, is_reattempt=True) + return + + # Network Layer + ip_packet = IPPacket( + src_ip_address=src_nic.ip_address, dst_ip_address=frame.ip.src_ip_address, protocol=IPProtocol.ICMP + ) + # Data Link Layer + ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) + icmp_reply_packet = ICMPPacket( + icmp_type=ICMPType.ECHO_REPLY, + icmp_code=0, + identifier=frame.icmp.identifier, + sequence=frame.icmp.sequence + 1, + ) + payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size + frame = Frame(ethernet=ethernet_header, ip=ip_packet, icmp=icmp_reply_packet, payload=payload) + self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip_address}") + + src_nic.send_frame(frame) + + def _process_icmp_echo_reply(self, frame: Frame, from_nic: NIC, is_reattempt: bool = False): + time = frame.transmission_duration() + time_str = f"{time}ms" if time > 0 else "<1ms" + self.sys_log.info( + f"Reply from {frame.ip.src_ip_address}: " + f"bytes={len(frame.payload)}, " + f"time={time_str}, " + f"TTL={frame.ip.ttl}", + to_terminal=True + ) + if not self.request_replies.get(frame.icmp.identifier): + self.request_replies[frame.icmp.identifier] = 0 + self.request_replies[frame.icmp.identifier] += 1 + + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + frame: Frame = kwargs["frame"] + from_nic = kwargs["from_nic"] + + if not frame.icmp: + return False + + if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: + self._process_icmp_echo_request(frame, from_nic) + elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: + self._process_icmp_echo_reply(frame, from_nic) + return True diff --git a/src/primaite/simulator/system/services/icmp/router_icmp.py b/src/primaite/simulator/system/services/icmp/router_icmp.py new file mode 100644 index 00000000..1def00c4 --- /dev/null +++ b/src/primaite/simulator/system/services/icmp/router_icmp.py @@ -0,0 +1,90 @@ +# class RouterICMP(ICMP): +# """ +# A class to represent a router's Internet Control Message Protocol (ICMP) handler. +# +# :param sys_log: System log for logging network events and errors. +# :type sys_log: SysLog +# :param arp_cache: The ARP cache for resolving MAC addresses. +# :type arp_cache: ARPCache +# :param router: The router to which this ICMP handler belongs. +# :type router: Router +# """ +# +# router: Router +# +# def __init__(self, sys_log: SysLog, arp_cache: ARPCache, router: Router): +# super().__init__(sys_log, arp_cache) +# self.router = router +# +# def process_icmp(self, frame: Frame, from_nic: NIC, is_reattempt: bool = False): +# """ +# Process incoming ICMP frames based on ICMP type. +# +# :param frame: The incoming frame to process. +# :param from_nic: The network interface where the frame is coming from. +# :param is_reattempt: Flag to indicate if the process is a reattempt. +# """ +# if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: +# # determine if request is for router interface or whether it needs to be routed +# +# for nic in self.router.nics.values(): +# if nic.ip_address == frame.ip.dst_ip_address: +# if nic.enabled: +# # reply to the request +# if not is_reattempt: +# self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") +# target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip_address) +# src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip_address) +# tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) +# +# # Network Layer +# ip_packet = IPPacket( +# src_ip_address=nic.ip_address, +# dst_ip_address=frame.ip.src_ip_address, +# protocol=IPProtocol.ICMP, +# ) +# # Data Link Layer +# ethernet_header = EthernetHeader( +# src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address +# ) +# icmp_reply_packet = ICMPPacket( +# icmp_type=ICMPType.ECHO_REPLY, +# icmp_code=0, +# identifier=frame.icmp.identifier, +# sequence=frame.icmp.sequence + 1, +# ) +# payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size +# frame = Frame( +# ethernet=ethernet_header, +# ip=ip_packet, +# tcp=tcp_header, +# icmp=icmp_reply_packet, +# payload=payload, +# ) +# self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip_address}") +# +# src_nic.send_frame(frame) +# return +# +# # Route the frame +# self.router.process_frame(frame, from_nic) +# +# elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: +# for nic in self.router.nics.values(): +# if nic.ip_address == frame.ip.dst_ip_address: +# if nic.enabled: +# time = frame.transmission_duration() +# time_str = f"{time}ms" if time > 0 else "<1ms" +# self.sys_log.info( +# f"Reply from {frame.ip.src_ip_address}: " +# f"bytes={len(frame.payload)}, " +# f"time={time_str}, " +# f"TTL={frame.ip.ttl}" +# ) +# if not self.request_replies.get(frame.icmp.identifier): +# self.request_replies[frame.icmp.identifier] = 0 +# self.request_replies[frame.icmp.identifier] += 1 +# +# return +# # Route the frame +# self.router.process_frame(frame, from_nic) From dc5aeede33436f6ab5762fd3130c8be3f3f7926b Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 2 Feb 2024 16:20:15 +0000 Subject: [PATCH 560/980] #2248 - ICMP now working as a service using the session manager for transmission. Now started to comb through the tests to fix anything up. --- .../simulator/network/hardware/base.py | 256 ------------------ .../network/hardware/nodes/computer.py | 29 +- .../simulator/network/hardware/nodes/host.py | 8 +- .../network/hardware/nodes/router.py | 115 +------- .../network/hardware/nodes/server.py | 13 +- .../simulator/system/core/session_manager.py | 6 +- .../simulator/system/services/arp/host_arp.py | 12 +- .../system/services/arp/router_arp.py | 98 +++++++ .../simulator/system/services/icmp/icmp.py | 168 +++++++----- .../network/test_switched_network.py | 22 +- .../_transmission/test_data_link_layer.py | 3 +- .../_transmission/test_network_layer.py | 2 +- 12 files changed, 241 insertions(+), 491 deletions(-) create mode 100644 src/primaite/simulator/system/services/arp/router_arp.py diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 7fbaa5f4..403d9638 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -599,262 +599,6 @@ class Link(SimComponent): def __str__(self) -> str: return f"{self.endpoint_a}<-->{self.endpoint_b}" - -class ARPCache: - """ - The ARPCache (Address Resolution Protocol) class. - - Responsible for maintaining a mapping between IP addresses and MAC addresses (ARP cache) for the network. It - provides methods for looking up, adding, and removing entries, and for processing ARPPackets. - """ - - def __init__(self, sys_log: "SysLog"): - """ - Initialize an ARP (Address Resolution Protocol) cache. - - :param sys_log: The nodes sys log. - """ - self.sys_log: "SysLog" = sys_log - self.arp: Dict[IPv4Address, ARPEntry] = {} - self.nics: Dict[str, "NIC"] = {} - self.node = None - - def show(self, markdown: bool = False): - """Prints a table of ARC Cache.""" - table = PrettyTable(["IP Address", "MAC Address", "Via"]) - if markdown: - table.set_style(MARKDOWN) - table.align = "l" - table.title = f"{self.sys_log.hostname} ARP Cache" - for ip, arp in self.arp.items(): - table.add_row( - [ - str(ip), - arp.mac_address, - self.nics[arp.nic_uuid].mac_address, - ] - ) - print(table) - - def clear(self): - """Clears the arp cache.""" - self.arp.clear() - - def add_arp_cache_entry(self, ip_address: IPv4Address, mac_address: str, nic: NIC, override: bool = False): - """ - Add an ARP entry to the cache. - - If an entry for the given IP address already exists, the entry is only updated if the `override` parameter is - set to True. - - :param ip_address: The IP address to be added to the cache. - :param mac_address: The MAC address associated with the IP address. - :param nic: The NIC through which the NIC with the IP address is reachable. - :param override: If True, an existing entry for the IP address will be overridden. Default is False. - """ - for _nic in self.nics.values(): - if _nic.ip_address == ip_address: - return - if override or not self.arp.get(ip_address): - self.sys_log.info(f"Adding ARP cache entry for {mac_address}/{ip_address} via NIC {nic}") - arp_entry = ARPEntry(mac_address=mac_address, nic_uuid=nic.uuid) - - self.arp[ip_address] = arp_entry - - def _remove_arp_cache_entry(self, ip_address: IPv4Address): - """ - Remove an ARP entry from the cache. - - :param ip_address: The IP address to be removed from the cache. - """ - if ip_address in self.arp: - del self.arp[ip_address] - - def get_default_gateway_mac_address(self) -> Optional[str]: - if self.arp.node.default_gateway: - return self.get_arp_cache_mac_address(self.arp.node.default_gateway) - - def get_default_gateway_nic(self) -> Optional[NIC]: - if self.arp.node.default_gateway: - return self.get_arp_cache_nic(self.arp.node.default_gateway) - - def _get_arp_cache_mac_address( - self, ip_address: IPv4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False - ) -> Optional[str]: - arp_entry = self.arp.get(ip_address) - - if arp_entry: - return arp_entry.mac_address - else: - if not is_reattempt: - self.send_arp_request(ip_address) - return self._get_arp_cache_mac_address( - ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt - ) - else: - if self.node.default_gateway: - if not is_default_gateway_attempt: - self.send_arp_request(self.node.default_gateway) - return self._get_arp_cache_mac_address( - ip_address=self.node.default_gateway, is_reattempt=True, is_default_gateway_attempt=True - ) - return None - - def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: - """ - Get the MAC address associated with an IP address. - - :param ip_address: The IP address to look up in the cache. - :return: The MAC address associated with the IP address, or None if not found. - """ - return self._get_arp_cache_mac_address(ip_address) - - def _get_arp_cache_nic( - self, ip_address: IPv4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False - ) -> Optional[NIC]: - arp_entry = self.arp.get(ip_address) - - if arp_entry: - return self.nics[arp_entry.nic_uuid] - else: - if not is_reattempt: - self.send_arp_request(ip_address) - return self._get_arp_cache_nic( - ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt - ) - else: - if self.node.default_gateway: - if not is_default_gateway_attempt: - self.send_arp_request(self.node.default_gateway) - return self._get_arp_cache_nic( - ip_address=self.node.default_gateway, is_reattempt=True, is_default_gateway_attempt=True - ) - return None - - def get_arp_cache_nic(self, ip_address: IPv4Address) -> Optional[NIC]: - """ - Get the NIC associated with an IP address. - - :param ip_address: The IP address to look up in the cache. - :return: The NIC associated with the IP address, or None if not found. - """ - return self._get_arp_cache_nic(ip_address) - - def clear_arp_cache(self): - """Clear the entire ARP cache, removing all stored entries.""" - self.arp.clear() - - def send_arp_request( - self, target_ip_address: Union[IPv4Address, str], ignore_networks: Optional[List[IPv4Address]] = None - ): - """ - Perform a standard ARP request for a given target IP address. - - Broadcasts the request through all enabled NICs to determine the MAC address corresponding to the target IP - address. This method can be configured to ignore specific networks when sending out ARP requests, - which is useful in environments where certain addresses should not be queried. - - :param target_ip_address: The target IP address to send an ARP request for. - :param ignore_networks: An optional list of IPv4 addresses representing networks to be excluded from the ARP - request broadcast. Each address in this list indicates a network which will not be queried during the ARP - request process. This is particularly useful in complex network environments where traffic should be - minimized or controlled to specific subnets. It is mainly used by the router to prevent ARP requests being - sent back to their source. - """ - pass - # for nic in self.nics.values(): - # use_nic = True - # if ignore_networks: - # for ipv4 in ignore_networks: - # if ipv4 in nic.ip_network: - # use_nic = False - # if nic.enabled and use_nic: - # self.sys_log.info(f"Sending ARP request from NIC {nic} for ip {target_ip_address}") - # udp_header = UDPHeader(src_port=Port.ARP, dst_port=Port.ARP) - # - # # Network Layer - # ip_packet = IPPacket( - # src_ip_address=nic.ip_address, dst_ip_address=target_ip_address, protocol=IPProtocol.UDP - # ) - # # Data Link Layer - # ethernet_header = EthernetHeader(src_mac_addr=nic.mac_address, dst_mac_addr="ff:ff:ff:ff:ff:ff") - # arp_packet = ARPPacket( - # sender_ip_address=nic.ip_address, - # sender_mac_addr=nic.mac_address, - # target_ip_address=target_ip_address, - # ) - # frame = Frame(ethernet=ethernet_header, ip=ip_packet, udp=udp_header, payload=arp_packet) - # nic.send_frame(frame) - - def send_arp_reply(self, arp_reply: ARPPacket, from_nic: NIC): - """ - Send an ARP reply back through the NIC it came from. - - :param arp_reply: The ARP reply to send. - :param from_nic: The NIC to send the ARP reply from. - """ - self.sys_log.info( - f"Sending ARP reply from {arp_reply.sender_mac_addr}/{arp_reply.sender_ip_address} " - f"to {arp_reply.target_ip_address}/{arp_reply.target_mac_addr} " - ) - tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) - - ip_packet = IPPacket( - src_ip_address=arp_reply.sender_ip_address, - dst_ip_address=arp_reply.target_ip_address, - ) - - ethernet_header = EthernetHeader(src_mac_addr=arp_reply.sender_mac_addr, dst_mac_addr=arp_reply.target_mac_addr) - - frame = Frame(ethernet=ethernet_header, ip=ip_packet, tcp=tcp_header, arp=arp_reply) - from_nic.send_frame(frame) - - def process_arp_packet(self, from_nic: NIC, arp_packet: ARPPacket): - """ - Process a received ARP packet, handling both ARP requests and responses. - - If an ARP request is received for the local IP, a response is sent back. - If an ARP response is received, the ARP cache is updated with the new entry. - - :param from_nic: The NIC that received the ARP packet. - :param arp_packet: The ARP packet to be processed. - """ - # ARP Reply - if not arp_packet.request: - self.sys_log.info( - f"Received ARP response for {arp_packet.sender_ip_address} " - f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" - ) - self.add_arp_cache_entry( - ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic - ) - return - - # ARP Request - self.sys_log.info( - f"Received ARP request for {arp_packet.target_ip_address} from " - f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip_address} " - ) - - # Unmatched ARP Request - if arp_packet.target_ip_address != from_nic.ip_address: - self.sys_log.info( - f"Ignoring ARP request for {arp_packet.target_ip_address}. Current IP address is {from_nic.ip_address}" - ) - return - - # Matched ARP request - self.add_arp_cache_entry( - ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic - ) - arp_packet = arp_packet.generate_reply(from_nic.mac_address) - self.send_arp_reply(arp_packet, from_nic) - - def __contains__(self, item: Any) -> bool: - return item in self.arp - - - class Node(SimComponent): """ A basic Node class that represents a node on the network. diff --git a/src/primaite/simulator/network/hardware/nodes/computer.py b/src/primaite/simulator/network/hardware/nodes/computer.py index 0480aca9..61d3e3ff 100644 --- a/src/primaite/simulator/network/hardware/nodes/computer.py +++ b/src/primaite/simulator/network/hardware/nodes/computer.py @@ -1,10 +1,11 @@ from primaite.simulator.network.hardware.base import NIC, Node +from primaite.simulator.network.hardware.nodes.host import Host from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.ftp.ftp_client import FTPClient -class Computer(Node): +class Computer(Host): """ A basic Computer class. @@ -20,36 +21,16 @@ class Computer(Node): Instances of computer come 'pre-packaged' with the following: * Core Functionality: - * ARP - * ICMP * Packet Capture * Sys Log * Services: + * ARP Service + * ICMP Service * DNS Client * FTP Client - * LDAP Client * NTP Client * Applications: - * Email Client * Web Browser - * Processes: - * Placeholder """ + pass - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.connect_nic(NIC(ip_address=kwargs["ip_address"], subnet_mask=kwargs["subnet_mask"])) - self._install_system_software() - - def _install_system_software(self): - """Install System Software - software that is usually provided with the OS.""" - # DNS Client - self.software_manager.install(DNSClient) - - # FTP - self.software_manager.install(FTPClient) - - # Web Browser - self.software_manager.install(WebBrowser) - - super()._install_system_software() diff --git a/src/primaite/simulator/network/hardware/nodes/host.py b/src/primaite/simulator/network/hardware/nodes/host.py index f4fc1586..b0486538 100644 --- a/src/primaite/simulator/network/hardware/nodes/host.py +++ b/src/primaite/simulator/network/hardware/nodes/host.py @@ -23,20 +23,16 @@ class Host(Node): Instances of computer come 'pre-packaged' with the following: * Core Functionality: - * ARP - * ICMP * Packet Capture * Sys Log * Services: + * ARP Service + * ICMP Service * DNS Client * FTP Client - * LDAP Client * NTP Client * Applications: - * Email Client * Web Browser - * Processes: - * Placeholder """ def __init__(self, **kwargs): diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 53277d69..34eb0423 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -8,7 +8,7 @@ from typing import Dict, List, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable from primaite.simulator.core import RequestManager, RequestType, SimComponent -from primaite.simulator.network.hardware.base import ARPCache, NIC, Node +from primaite.simulator.network.hardware.base import NIC, Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol @@ -528,108 +528,6 @@ class RouteTable(SimComponent): table.add_row([index, f"{route.address}/{network.prefixlen}", route.next_hop_ip_address, route.metric]) print(table) - -class RouterARPCache(ARPCache): - """ - Inherits from ARPCache and adds router-specific ARP packet processing. - - :ivar SysLog sys_log: A system log for logging messages. - :ivar Router router: The router to which this ARP cache belongs. - """ - - def __init__(self, sys_log: SysLog, router: Router): - super().__init__(sys_log) - self.router: Router = router - - def process_arp_packet( - self, from_nic: NIC, frame: Frame, route_table: RouteTable, is_reattempt: bool = False - ) -> None: - """ - Processes a received ARP (Address Resolution Protocol) packet in a router-specific way. - - This method is responsible for handling both ARP requests and responses. It processes ARP packets received on a - Network Interface Card (NIC) and performs actions based on whether the packet is a request or a reply. This - includes updating the ARP cache, forwarding ARP replies, sending ARP requests for unknown destinations, and - handling packet TTL (Time To Live). - - The method first checks if the ARP packet is a request or a reply. For ARP replies, it updates the ARP cache - and forwards the reply if necessary. For ARP requests, it checks if the target IP matches one of the router's - NICs and sends an ARP reply if so. If the destination is not directly connected, it consults the routing table - to find the best route and reattempts ARP request processing if needed. - - :param from_nic: The NIC that received the ARP packet. - :param frame: The frame containing the ARP packet. - :param route_table: The routing table of the router. - :param is_reattempt: Flag to indicate if this is a reattempt of processing the ARP packet, defaults to False. - """ - arp_packet = frame.arp - - # ARP Reply - if not arp_packet.request: - if arp_packet.target_ip_address == from_nic.ip_address: - # reply to the Router specifically - self.sys_log.info( - f"Received ARP response for {arp_packet.sender_ip_address} " - f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" - ) - self.add_arp_cache_entry( - ip_address=arp_packet.sender_ip_address, - mac_address=arp_packet.sender_mac_addr, - nic=from_nic, - ) - return - - # # Reply for a connected requested - # nic = self.get_arp_cache_nic(arp_packet.target_ip_address) - # if nic: - # self.sys_log.info( - # f"Forwarding arp reply for {arp_packet.target_ip_address}, from {arp_packet.sender_ip_address}" - # ) - # arp_packet.sender_mac_addr = nic.mac_address - # frame.decrement_ttl() - # if frame.ip and frame.ip.ttl < 1: - # self.sys_log.info("Frame discarded as TTL limit reached") - # return - # nic.send_frame(frame) - # return - - # ARP Request - self.sys_log.info( - f"Received ARP request for {arp_packet.target_ip_address} from " - f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip_address} " - ) - # Matched ARP request - self.add_arp_cache_entry( - ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic - ) - - # If the target IP matches one of the router's NICs - for nic in self.nics.values(): - if nic.enabled and nic.ip_address == arp_packet.target_ip_address: - arp_reply = arp_packet.generate_reply(from_nic.mac_address) - self.send_arp_reply(arp_reply, from_nic) - return - - # # Check Route Table - # route = route_table.find_best_route(arp_packet.target_ip_address) - # if route and route != self.router.route_table.default_route: - # nic = self.get_arp_cache_nic(route.next_hop_ip_address) - # - # if not nic: - # if not is_reattempt: - # self.send_arp_request(route.next_hop_ip_address, ignore_networks=[frame.ip.src_ip_address]) - # return self.process_arp_packet(from_nic, frame, route_table, is_reattempt=True) - # else: - # self.sys_log.info("Ignoring ARP request as destination unavailable/No ARP entry found") - # return - # else: - # arp_reply = arp_packet.generate_reply(from_nic.mac_address) - # self.send_arp_reply(arp_reply, from_nic) - # return - - - - class RouterNIC(NIC): """ A Router-specific Network Interface Card (NIC) that extends the standard NIC functionality. @@ -684,8 +582,8 @@ class Router(Node): ethernet_ports: Dict[int, RouterNIC] = {} acl: AccessControlList route_table: RouteTable - arp: RouterARPCache - icmp: RouterICMP + # arp: RouterARPCache + # icmp: RouterICMP def __init__(self, hostname: str, num_ports: int = 5, **kwargs): if not kwargs.get("sys_log"): @@ -694,12 +592,13 @@ class Router(Node): kwargs["acl"] = AccessControlList(sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY) if not kwargs.get("route_table"): kwargs["route_table"] = RouteTable(sys_log=kwargs["sys_log"]) - if not kwargs.get("arp"): - kwargs["arp"] = RouterARPCache(sys_log=kwargs.get("sys_log"), router=self) + # if not kwargs.get("arp"): + # kwargs["arp"] = RouterARPCache(sys_log=kwargs.get("sys_log"), router=self) # if not kwargs.get("icmp"): # kwargs["icmp"] = RouterICMP(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp"), router=self) super().__init__(hostname=hostname, num_ports=num_ports, **kwargs) - # TODO: Install RoputerICMP + # TODO: Install RouterICMP + # TODO: Install RouterARP for i in range(1, self.num_ports + 1): nic = RouterNIC(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") self.connect_nic(nic) diff --git a/src/primaite/simulator/network/hardware/nodes/server.py b/src/primaite/simulator/network/hardware/nodes/server.py index b72cc71c..0a2c361f 100644 --- a/src/primaite/simulator/network/hardware/nodes/server.py +++ b/src/primaite/simulator/network/hardware/nodes/server.py @@ -1,7 +1,7 @@ -from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.host import Host -class Server(Computer): +class Server(Host): """ A basic Server class. @@ -17,18 +17,15 @@ class Server(Computer): Instances of Server come 'pre-packaged' with the following: * Core Functionality: - * ARP - * ICMP * Packet Capture * Sys Log * Services: + * ARP Service + * ICMP Service * DNS Client * FTP Client - * LDAP Client * NTP Client * Applications: - * Email Client * Web Browser - * Processes: - * Placeholder """ + pass diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index c134f56a..a748b7df 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -7,6 +7,7 @@ from prettytable import MARKDOWN, PrettyTable from primaite.simulator.core import SimComponent from primaite.simulator.network.protocols.arp import ARPPacket +from primaite.simulator.network.protocols.icmp import ICMPPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader, UDPHeader @@ -200,6 +201,7 @@ class SessionManager: dst_port: Optional[Port] = None, session_id: Optional[str] = None, ip_protocol: IPProtocol = IPProtocol.TCP, + icmp_packet: Optional[ICMPPacket] = None ) -> Union[Any, None]: """ Receive a payload from the SoftwareManager and send it to the appropriate NIC for transmission. @@ -250,16 +252,17 @@ class SessionManager: ) # Construct the frame for transmission - frame = Frame( ethernet=EthernetHeader(src_mac_addr=outbound_nic.mac_address, dst_mac_addr=dst_mac_address), ip=IPPacket(src_ip_address=outbound_nic.ip_address, dst_ip_address=dst_ip_address, protocol=ip_protocol), tcp=tcp_header, udp=udp_header, + icmp=icmp_packet, payload=payload, ) # Manage session for unicast transmission + # TODO: Only create sessions for TCP if not (is_broadcast and session_id): session_key = self._get_session_key(frame, inbound_frame=False) session = self.sessions_by_key.get(session_key) @@ -281,6 +284,7 @@ class SessionManager: :param frame: The frame being received. """ + # TODO: Only create sessions for TCP session_key = self._get_session_key(frame, inbound_frame=True) session: Session = self.sessions_by_key.get(session_key) if not session: diff --git a/src/primaite/simulator/system/services/arp/host_arp.py b/src/primaite/simulator/system/services/arp/host_arp.py index 8bf3369b..f3e70838 100644 --- a/src/primaite/simulator/system/services/arp/host_arp.py +++ b/src/primaite/simulator/system/services/arp/host_arp.py @@ -30,11 +30,11 @@ class HostARP(ARP): ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt ) else: - if self.node.default_gateway: + if self.software_manager.node.default_gateway: if not is_default_gateway_attempt: - self.send_arp_request(self.node.default_gateway) + self.send_arp_request(self.software_manager.node.default_gateway) return self._get_arp_cache_mac_address( - ip_address=self.node.default_gateway, is_reattempt=True, is_default_gateway_attempt=True + ip_address=self.software_manager.node.default_gateway, is_reattempt=True, is_default_gateway_attempt=True ) return None @@ -61,11 +61,11 @@ class HostARP(ARP): ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt ) else: - if self.node.default_gateway: + if self.software_manager.node.default_gateway: if not is_default_gateway_attempt: - self.send_arp_request(self.node.default_gateway) + self.send_arp_request(self.software_manager.node.default_gateway) return self._get_arp_cache_nic( - ip_address=self.node.default_gateway, is_reattempt=True, is_default_gateway_attempt=True + ip_address=self.software_manager.node.default_gateway, is_reattempt=True, is_default_gateway_attempt=True ) return None diff --git a/src/primaite/simulator/system/services/arp/router_arp.py b/src/primaite/simulator/system/services/arp/router_arp.py new file mode 100644 index 00000000..3c32b108 --- /dev/null +++ b/src/primaite/simulator/system/services/arp/router_arp.py @@ -0,0 +1,98 @@ +# class RouterARPCache(ARPCache): +# """ +# Inherits from ARPCache and adds router-specific ARP packet processing. +# +# :ivar SysLog sys_log: A system log for logging messages. +# :ivar Router router: The router to which this ARP cache belongs. +# """ +# +# def __init__(self, sys_log: SysLog, router: Router): +# super().__init__(sys_log) +# self.router: Router = router +# +# def process_arp_packet( +# self, from_nic: NIC, frame: Frame, route_table: RouteTable, is_reattempt: bool = False +# ) -> None: +# """ +# Processes a received ARP (Address Resolution Protocol) packet in a router-specific way. +# +# This method is responsible for handling both ARP requests and responses. It processes ARP packets received on a +# Network Interface Card (NIC) and performs actions based on whether the packet is a request or a reply. This +# includes updating the ARP cache, forwarding ARP replies, sending ARP requests for unknown destinations, and +# handling packet TTL (Time To Live). +# +# The method first checks if the ARP packet is a request or a reply. For ARP replies, it updates the ARP cache +# and forwards the reply if necessary. For ARP requests, it checks if the target IP matches one of the router's +# NICs and sends an ARP reply if so. If the destination is not directly connected, it consults the routing table +# to find the best route and reattempts ARP request processing if needed. +# +# :param from_nic: The NIC that received the ARP packet. +# :param frame: The frame containing the ARP packet. +# :param route_table: The routing table of the router. +# :param is_reattempt: Flag to indicate if this is a reattempt of processing the ARP packet, defaults to False. +# """ +# arp_packet = frame.arp +# +# # ARP Reply +# if not arp_packet.request: +# if arp_packet.target_ip_address == from_nic.ip_address: +# # reply to the Router specifically +# self.sys_log.info( +# f"Received ARP response for {arp_packet.sender_ip_address} " +# f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" +# ) +# self.add_arp_cache_entry( +# ip_address=arp_packet.sender_ip_address, +# mac_address=arp_packet.sender_mac_addr, +# nic=from_nic, +# ) +# return +# +# # # Reply for a connected requested +# # nic = self.get_arp_cache_nic(arp_packet.target_ip_address) +# # if nic: +# # self.sys_log.info( +# # f"Forwarding arp reply for {arp_packet.target_ip_address}, from {arp_packet.sender_ip_address}" +# # ) +# # arp_packet.sender_mac_addr = nic.mac_address +# # frame.decrement_ttl() +# # if frame.ip and frame.ip.ttl < 1: +# # self.sys_log.info("Frame discarded as TTL limit reached") +# # return +# # nic.send_frame(frame) +# # return +# +# # ARP Request +# self.sys_log.info( +# f"Received ARP request for {arp_packet.target_ip_address} from " +# f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip_address} " +# ) +# # Matched ARP request +# self.add_arp_cache_entry( +# ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic +# ) +# +# # If the target IP matches one of the router's NICs +# for nic in self.nics.values(): +# if nic.enabled and nic.ip_address == arp_packet.target_ip_address: +# arp_reply = arp_packet.generate_reply(from_nic.mac_address) +# self.send_arp_reply(arp_reply, from_nic) +# return +# +# # # Check Route Table +# # route = route_table.find_best_route(arp_packet.target_ip_address) +# # if route and route != self.router.route_table.default_route: +# # nic = self.get_arp_cache_nic(route.next_hop_ip_address) +# # +# # if not nic: +# # if not is_reattempt: +# # self.send_arp_request(route.next_hop_ip_address, ignore_networks=[frame.ip.src_ip_address]) +# # return self.process_arp_packet(from_nic, frame, route_table, is_reattempt=True) +# # else: +# # self.sys_log.info("Ignoring ARP request as destination unavailable/No ARP entry found") +# # return +# # else: +# # arp_reply = arp_packet.generate_reply(from_nic.mac_address) +# # self.send_arp_reply(arp_reply, from_nic) +# # return +# diff --git a/src/primaite/simulator/system/services/icmp/icmp.py b/src/primaite/simulator/system/services/icmp/icmp.py index 16dd4f8c..93582350 100644 --- a/src/primaite/simulator/system/services/icmp/icmp.py +++ b/src/primaite/simulator/system/services/icmp/icmp.py @@ -5,8 +5,8 @@ from typing import Dict, Any, Union, Optional, Tuple from primaite import getLogger from primaite.simulator.network.hardware.base import NIC from primaite.simulator.network.protocols.icmp import ICMPPacket, ICMPType -from primaite.simulator.network.transmission.data_link_layer import Frame, EthernetHeader -from primaite.simulator.network.transmission.network_layer import IPProtocol, IPPacket +from primaite.simulator.network.transmission.data_link_layer import Frame +from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.service import Service @@ -14,6 +14,12 @@ _LOGGER = getLogger(__name__) class ICMP(Service): + """ + The Internet Control Message Protocol (ICMP) services. + + Enables the sending and receiving of ICMP messages such as echo requests and replies. This is typically used for + network diagnostics, notably the ping command. + """ request_replies: Dict = {} def __init__(self, **kwargs): @@ -26,53 +32,22 @@ class ICMP(Service): pass def clear(self): - """Clears the ICMP request replies tracker.""" + """ + Clears the ICMP request and reply tracker. + + This is typically used to reset the state of the service, removing all tracked ICMP echo requests and their + corresponding replies. + """ self.request_replies.clear() - def _send_icmp_echo_request( - self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None, pings: int = 4 - ) -> Tuple[int, Union[int, None]]: - """ - Send an ICMP echo request (ping) to a target IP address and manage the sequence and identifier. - - :param target_ip_address: The target IP address to send the ping. - :param sequence: The sequence number of the echo request. Defaults to 0. - :param identifier: An optional identifier for the ICMP packet. If None, a default will be used. - :return: A tuple containing the next sequence number and the identifier, or (0, None) if the target IP address - was not found in the ARP cache. - """ - nic = self.software_manager.arp.get_arp_cache_nic(target_ip_address) - - if not nic: - return pings, None - - # ARP entry exists - sequence += 1 - target_mac_address = self.software_manager.arp.get_arp_cache_mac_address(target_ip_address) - - src_nic = self.software_manager.arp.get_arp_cache_nic(target_ip_address) - - # Network Layer - ip_packet = IPPacket( - src_ip_address=nic.ip_address, - dst_ip_address=target_ip_address, - protocol=IPProtocol.ICMP, - ) - # Data Link Layer - ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) - icmp_packet = ICMPPacket(identifier=identifier, sequence=sequence) - payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size - frame = Frame(ethernet=ethernet_header, ip=ip_packet, icmp=icmp_packet, payload=payload) - nic.send_frame(frame) - return sequence, icmp_packet.identifier - def ping(self, target_ip_address: Union[IPv4Address, str], pings: int = 4) -> bool: """ - Ping an IP address, performing a standard ICMP echo request/response. + Pings a target IP address by sending an ICMP echo request and waiting for a reply. - :param target_ip_address: The target IP address to ping. - :param pings: The number of pings to attempt, default is 4. - :return: True if the ping is successful, otherwise False. + :param target_ip_address: The IP address to be pinged. + :param pings: The number of echo requests to send. Defaults to 4. + :return: True if the ping was successful (i.e., if a reply was received for every request sent), otherwise + False. """ if not self._can_perform_action(): return False @@ -101,37 +76,79 @@ class ICMP(Service): return passed - def _process_icmp_echo_request(self, frame: Frame, from_nic: NIC, is_reattempt: bool = False): - if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: - if not is_reattempt: - self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") - target_mac_address = self.software_manager.arp.get_arp_cache_mac_address(frame.ip.src_ip_address) + def _send_icmp_echo_request( + self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None, pings: int = 4 + ) -> Tuple[int, Union[int, None]]: + """ + Sends an ICMP echo request to a specified target IP address. - src_nic = self.software_manager.arp.get_arp_cache_nic(frame.ip.src_ip_address) - if not src_nic: - self.software_manager.arp.send_arp_request(frame.ip.src_ip_address) - self.process_icmp(frame=frame, from_nic=from_nic, is_reattempt=True) - return + :param target_ip_address: The target IP address for the echo request. + :param sequence: The sequence number of the echo request. + :param identifier: The identifier for the ICMP packet. If None, a default identifier is used. + :param pings: The number of pings to send. Defaults to 4. + :return: A tuple containing the next sequence number and the identifier. + """ + nic = self.software_manager.session_manager.resolve_outbound_nic(target_ip_address) - # Network Layer - ip_packet = IPPacket( - src_ip_address=src_nic.ip_address, dst_ip_address=frame.ip.src_ip_address, protocol=IPProtocol.ICMP + if not nic: + self.sys_log.error( + "Cannot send ICMP echo request as there is no outbound NIC to use. Try configuring the default gateway." ) - # Data Link Layer - ethernet_header = EthernetHeader(src_mac_addr=src_nic.mac_address, dst_mac_addr=target_mac_address) - icmp_reply_packet = ICMPPacket( - icmp_type=ICMPType.ECHO_REPLY, - icmp_code=0, - identifier=frame.icmp.identifier, - sequence=frame.icmp.sequence + 1, + return pings, None + + sequence += 1 + + icmp_packet = ICMPPacket(identifier=identifier, sequence=sequence) + payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size + + self.software_manager.session_manager.receive_payload_from_software_manager( + payload=payload, + dst_ip_address=target_ip_address, + dst_port=self.port, + ip_protocol=self.protocol, + icmp_packet=icmp_packet + ) + return sequence, icmp_packet.identifier + + def _process_icmp_echo_request(self, frame: Frame): + """ + Processes an ICMP echo request received by the service. + + :param frame: The network frame containing the ICMP echo request. + """ + self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") + + nic = self.software_manager.session_manager.resolve_outbound_nic(frame.ip.src_ip_address) + + if not nic: + self.sys_log.error( + "Cannot send ICMP echo reply as there is no outbound NIC to use. Try configuring the default gateway." ) - payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size - frame = Frame(ethernet=ethernet_header, ip=ip_packet, icmp=icmp_reply_packet, payload=payload) - self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip_address}") + return - src_nic.send_frame(frame) + icmp_packet = ICMPPacket( + icmp_type=ICMPType.ECHO_REPLY, + icmp_code=0, + identifier=frame.icmp.identifier, + sequence=frame.icmp.sequence + 1, + ) + payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size + self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip_address}") - def _process_icmp_echo_reply(self, frame: Frame, from_nic: NIC, is_reattempt: bool = False): + self.software_manager.session_manager.receive_payload_from_software_manager( + payload=payload, + dst_ip_address=frame.ip.src_ip_address, + dst_port=self.port, + ip_protocol=self.protocol, + icmp_packet=icmp_packet + ) + + def _process_icmp_echo_reply(self, frame: Frame): + """ + Processes an ICMP echo reply received by the service, logging the reply details. + + :param frame: The network frame containing the ICMP echo reply. + """ time = frame.transmission_duration() time_str = f"{time}ms" if time > 0 else "<1ms" self.sys_log.info( @@ -146,14 +163,21 @@ class ICMP(Service): self.request_replies[frame.icmp.identifier] += 1 def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Processes received data, handling ICMP echo requests and replies. + + :param payload: The payload received. + :param session_id: The session ID associated with the received data. + :param kwargs: Additional keyword arguments. + :return: True if the payload was processed successfully, otherwise False. + """ frame: Frame = kwargs["frame"] - from_nic = kwargs["from_nic"] if not frame.icmp: return False if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: - self._process_icmp_echo_request(frame, from_nic) + self._process_icmp_echo_request(frame) elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: - self._process_icmp_echo_reply(frame, from_nic) + self._process_icmp_echo_reply(frame) return True diff --git a/tests/integration_tests/network/test_switched_network.py b/tests/integration_tests/network/test_switched_network.py index 5b305702..103dda21 100644 --- a/tests/integration_tests/network/test_switched_network.py +++ b/tests/integration_tests/network/test_switched_network.py @@ -1,3 +1,4 @@ +from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.base import Link, NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server @@ -6,25 +7,30 @@ from primaite.simulator.network.hardware.nodes.switch import Switch def test_switched_network(): """Tests a node can ping another node via the switch.""" + network = Network() + client_1 = Computer( hostname="client_1", ip_address="192.168.1.10", subnet_mask="255.255.255.0", - default_gateway="192.168.1.0", - operating_state=NodeOperatingState.ON, + default_gateway="192.168.1.1", + start_up_duration=0, ) + client_1.power_on() server_1 = Server( - hostname=" server_1", + hostname="server_1", ip_address="192.168.1.11", subnet_mask="255.255.255.0", - default_gateway="192.168.1.11", - operating_state=NodeOperatingState.ON, + default_gateway="192.168.1.1", + start_up_duration=0, ) + server_1.power_on() - switch_1 = Switch(hostname="switch_1", num_ports=6, operating_state=NodeOperatingState.ON) + switch_1 = Switch(hostname="switch_1", start_up_duration=0) + switch_1.power_on() - Link(endpoint_a=client_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[1]) - Link(endpoint_a=server_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[2]) + network.connect(endpoint_a=client_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[1]) + network.connect(endpoint_a=server_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[2]) assert client_1.ping("192.168.1.11") diff --git a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py index f9b89de5..1fbbd1c1 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_data_link_layer.py @@ -1,7 +1,8 @@ import pytest +from primaite.simulator.network.protocols.icmp import ICMPPacket from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame -from primaite.simulator.network.transmission.network_layer import ICMPPacket, IPPacket, IPProtocol, Precedence +from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol, Precedence from primaite.simulator.network.transmission.primaite_layer import AgentSource, DataStatus from primaite.simulator.network.transmission.transport_layer import Port, TCPFlags, TCPHeader, UDPHeader diff --git a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py index a7189452..0ea98107 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_transmission/test_network_layer.py @@ -1,6 +1,6 @@ import pytest -from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType +from primaite.simulator.network.protocols.icmp import ICMPPacket, ICMPType def test_icmp_minimal_header_creation(): From cb002d644f872091821d64a8a6bc81c038233bbe Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 2 Feb 2024 16:55:43 +0000 Subject: [PATCH 561/980] #2248 - Tidying up the tests so that they use updated networks --- .../simulator/network/hardware/base.py | 2 +- .../network/transmission/network_layer.py | 9 +-- .../simulator/system/core/session_manager.py | 16 +++-- .../simulator/system/core/software_manager.py | 1 + src/primaite/simulator/system/software.py | 7 ++- tests/conftest.py | 59 ++++++++++++++++--- .../network/test_broadcast.py | 1 + .../network/test_frame_transmission.py | 48 ++++++++++----- .../network/test_link_connection.py | 24 -------- .../network/test_switched_network.py | 30 +--------- 10 files changed, 104 insertions(+), 93 deletions(-) delete mode 100644 tests/integration_tests/network/test_link_connection.py diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 403d9638..69f93f51 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -679,7 +679,7 @@ class Node(SimComponent): if not kwargs.get("sys_log"): kwargs["sys_log"] = SysLog(kwargs["hostname"]) if not kwargs.get("session_manager"): - kwargs["session_manager"] = SessionManager(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp")) + kwargs["session_manager"] = SessionManager(sys_log=kwargs.get("sys_log")) if not kwargs.get("root"): kwargs["root"] = SIM_OUTPUT.path / kwargs["hostname"] if not kwargs.get("file_system"): diff --git a/src/primaite/simulator/network/transmission/network_layer.py b/src/primaite/simulator/network/transmission/network_layer.py index b581becd..38fc1977 100644 --- a/src/primaite/simulator/network/transmission/network_layer.py +++ b/src/primaite/simulator/network/transmission/network_layer.py @@ -1,6 +1,6 @@ import secrets from enum import Enum -from ipaddress import IPv4Address +from ipaddress import IPv4Address, IPv4Network from typing import Union from pydantic import BaseModel, field_validator, validate_call @@ -86,10 +86,3 @@ class IPPacket(BaseModel): "Time to Live (TTL) for the packet." precedence: Precedence = Precedence.ROUTINE "Precedence level for Quality of Service (default is Precedence.ROUTINE)." - - def __init__(self, **kwargs): - if not isinstance(kwargs["src_ip_address"], IPv4Address): - kwargs["src_ip_address"] = IPv4Address(kwargs["src_ip_address"]) - if not isinstance(kwargs["dst_ip_address"], IPv4Address): - kwargs["dst_ip_address"] = IPv4Address(kwargs["dst_ip_address"]) - super().__init__(**kwargs) diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index a748b7df..ce05193f 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -75,7 +75,7 @@ class SessionManager: :param arp_cache: A reference to the ARP cache component. """ - def __init__(self, sys_log: SysLog, arp_cache: "ARPCache"): + def __init__(self, sys_log: SysLog): self.sessions_by_key: Dict[ Tuple[IPProtocol, IPv4Address, IPv4Address, Optional[Port], Optional[Port]], Session ] = {} @@ -150,8 +150,8 @@ class SessionManager: def resolve_outbound_transmission_details( self, dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, session_id: Optional[str] = None - ) -> Tuple[Optional["NIC"], Optional[str], Optional[IPProtocol], bool]: - if not isinstance(dst_ip_address, IPv4Address): + ) -> Tuple[Optional["NIC"], Optional[str], IPv4Address, Optional[IPProtocol], bool]: + if not isinstance(dst_ip_address, (IPv4Address, IPv4Network)): dst_ip_address = IPv4Address(dst_ip_address) is_broadcast = False outbound_nic = None @@ -192,7 +192,7 @@ class SessionManager: if use_default_gateway: dst_mac_address = self.software_manager.arp.get_default_gateway_mac_address() outbound_nic = self.software_manager.arp.get_default_gateway_nic() - return outbound_nic, dst_mac_address, protocol, is_broadcast + return outbound_nic, dst_mac_address, dst_ip_address, protocol, is_broadcast def receive_payload_from_software_manager( self, @@ -226,14 +226,13 @@ class SessionManager: is_broadcast = payload.request ip_protocol = IPProtocol.UDP else: - outbound_nic, dst_mac_address, protocol, is_broadcast = self.resolve_outbound_transmission_details( + vals = self.resolve_outbound_transmission_details( dst_ip_address=dst_ip_address, session_id=session_id ) - + outbound_nic, dst_mac_address, dst_ip_address, protocol, is_broadcast = vals if protocol: ip_protocol = protocol - # Check if outbound NIC and destination MAC address are resolved if not outbound_nic or not dst_mac_address: return False @@ -241,7 +240,7 @@ class SessionManager: tcp_header = None udp_header = None if ip_protocol == IPProtocol.TCP: - TCPHeader( + tcp_header = TCPHeader( src_port=dst_port, dst_port=dst_port, ) @@ -250,7 +249,6 @@ class SessionManager: src_port=dst_port, dst_port=dst_port, ) - # Construct the frame for transmission frame = Frame( ethernet=EthernetHeader(src_mac_addr=outbound_nic.mac_address, dst_mac_addr=dst_mac_address), diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index ac765018..99dc5f38 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -162,6 +162,7 @@ class SoftwareManager: payload=payload, dst_ip_address=dest_ip_address, dst_port=dest_port, + ip_protocol=ip_protocol, session_id=session_id, ) diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 8930fa2f..91629f9a 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -356,6 +356,7 @@ class IOSoftware(Software): session_id: Optional[str] = None, dest_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, dest_port: Optional[Port] = None, + ip_protocol: IPProtocol = IPProtocol.TCP, **kwargs, ) -> bool: """ @@ -375,7 +376,11 @@ class IOSoftware(Software): return False return self.software_manager.send_payload_to_session_manager( - payload=payload, dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id + payload=payload, + dest_ip_address=dest_ip_address, + dest_port=dest_port, + ip_protocol=ip_protocol, + session_id=session_id ) @abstractmethod diff --git a/tests/conftest.py b/tests/conftest.py index c37226a5..8e458878 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -134,31 +134,72 @@ def temp_primaite_session(request, monkeypatch) -> TempPrimaiteSession: @pytest.fixture(scope="function") def client_server() -> Tuple[Computer, Server]: + network = Network() + # Create Computer - computer: Computer = Computer( - hostname="test_computer", - ip_address="192.168.0.1", + computer = Computer( + hostname="computer", + ip_address="192.168.1.2", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", - operating_state=NodeOperatingState.ON, + start_up_duration=0, ) + computer.power_on() # Create Server server = Server( - hostname="server", ip_address="192.168.0.2", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON + hostname="server", + ip_address="192.168.1.3", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, ) + server.power_on() # Connect Computer and Server - computer_nic = computer.nics[next(iter(computer.nics))] - server_nic = server.nics[next(iter(server.nics))] - link = Link(endpoint_a=computer_nic, endpoint_b=server_nic) + network.connect(computer.ethernet_port[1], server.ethernet_port[1]) # Should be linked - assert link.is_up + assert next(iter(network.links.values())).is_up return computer, server +@pytest.fixture(scope="function") +def client_switch_server() -> Tuple[Computer, Switch, Server]: + network = Network() + + # Create Computer + computer = Computer( + hostname="computer", + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + computer.power_on() + + # Create Server + server = Server( + hostname="server", + ip_address="192.168.1.3", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + server.power_on() + + switch = Switch(hostname="switch", start_up_duration=0) + switch.power_on() + + network.connect(endpoint_a=computer.ethernet_port[1], endpoint_b=switch.switch_ports[1]) + network.connect(endpoint_a=server.ethernet_port[1], endpoint_b=switch.switch_ports[2]) + + assert all(link.is_up for link in network.links.values()) + + return computer, switch, server + + @pytest.fixture(scope="function") def example_network() -> Network: """ diff --git a/tests/integration_tests/network/test_broadcast.py b/tests/integration_tests/network/test_broadcast.py index b9ecb28b..5fb0917e 100644 --- a/tests/integration_tests/network/test_broadcast.py +++ b/tests/integration_tests/network/test_broadcast.py @@ -41,6 +41,7 @@ class BroadcastService(Service): payload="broadcast", dest_ip_address=ip_network, dest_port=Port.HTTP, + ip_protocol=self.protocol ) diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index 7da9fe76..527e4b4c 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -1,34 +1,54 @@ -from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.switch import Switch + def test_node_to_node_ping(): - """Tests two Nodes are able to ping each other.""" - node_a = Node(hostname="node_a", operating_state=NodeOperatingState.ON) - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON) - node_a.connect_nic(nic_a) + """Tests two Computers are able to ping each other.""" + network = Network() - node_b = Node(hostname="node_b", operating_state=NodeOperatingState.ON) - nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") - node_b.connect_nic(nic_b) + client_1 = Computer( + hostname="client_1", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + client_1.power_on() - Link(endpoint_a=nic_a, endpoint_b=nic_b) + server_1 = Server( + hostname="server_1", + ip_address="192.168.1.11", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + server_1.power_on() - assert node_a.ping("192.168.0.11") + switch_1 = Switch(hostname="switch_1", start_up_duration=0) + switch_1.power_on() + + network.connect(endpoint_a=client_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[1]) + network.connect(endpoint_a=server_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[2]) + + assert client_1.ping("192.168.1.11") def test_multi_nic(): - """Tests that Nodes with multiple NICs can ping each other and the data go across the correct links.""" - node_a = Node(hostname="node_a", operating_state=NodeOperatingState.ON) + """Tests that Computers with multiple NICs can ping each other and the data go across the correct links.""" + node_a = Computer(hostname="node_a", operating_state=ComputerOperatingState.ON) nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") node_a.connect_nic(nic_a) - node_b = Node(hostname="node_b", operating_state=NodeOperatingState.ON) + node_b = Computer(hostname="node_b", operating_state=ComputerOperatingState.ON) nic_b1 = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") nic_b2 = NIC(ip_address="10.0.0.12", subnet_mask="255.0.0.0") node_b.connect_nic(nic_b1) node_b.connect_nic(nic_b2) - node_c = Node(hostname="node_c", operating_state=NodeOperatingState.ON) + node_c = Computer(hostname="node_c", operating_state=ComputerOperatingState.ON) nic_c = NIC(ip_address="10.0.0.13", subnet_mask="255.0.0.0") node_c.connect_nic(nic_c) diff --git a/tests/integration_tests/network/test_link_connection.py b/tests/integration_tests/network/test_link_connection.py deleted file mode 100644 index c6aeac24..00000000 --- a/tests/integration_tests/network/test_link_connection.py +++ /dev/null @@ -1,24 +0,0 @@ -from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState - - -def test_link_up(): - """Tests Nodes, NICs, and Links can all be connected and be in an enabled/up state.""" - node_a = Node(hostname="node_a", operating_state=NodeOperatingState.ON) - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") - node_a.connect_nic(nic_a) - - node_b = Node(hostname="node_b", operating_state=NodeOperatingState.ON) - nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") - node_b.connect_nic(nic_b) - - link = Link(endpoint_a=nic_a, endpoint_b=nic_b) - - assert nic_a.enabled - assert nic_b.enabled - assert link.is_up - - -def test_ping_between_computer_and_server(client_server): - computer, server = client_server - - assert computer.ping(target_ip_address=server.nics[next(iter(server.nics))].ip_address) diff --git a/tests/integration_tests/network/test_switched_network.py b/tests/integration_tests/network/test_switched_network.py index 103dda21..8a2bd0a2 100644 --- a/tests/integration_tests/network/test_switched_network.py +++ b/tests/integration_tests/network/test_switched_network.py @@ -5,32 +5,8 @@ from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.hardware.nodes.switch import Switch -def test_switched_network(): +def test_switched_network(client_switch_server): """Tests a node can ping another node via the switch.""" - network = Network() + computer, switch, server = client_switch_server - client_1 = Computer( - hostname="client_1", - ip_address="192.168.1.10", - subnet_mask="255.255.255.0", - default_gateway="192.168.1.1", - start_up_duration=0, - ) - client_1.power_on() - - server_1 = Server( - hostname="server_1", - ip_address="192.168.1.11", - subnet_mask="255.255.255.0", - default_gateway="192.168.1.1", - start_up_duration=0, - ) - server_1.power_on() - - switch_1 = Switch(hostname="switch_1", start_up_duration=0) - switch_1.power_on() - - network.connect(endpoint_a=client_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[1]) - network.connect(endpoint_a=server_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[2]) - - assert client_1.ping("192.168.1.11") + assert computer.ping(server.ethernet_port[1].ip_address) From a0253ce6c44566184d805cbfdbdad1cd1de9f0ce Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 2 Feb 2024 17:14:34 +0000 Subject: [PATCH 562/980] #2248 - TSome further fixess to ARP. Also refactored PCAP to log inbound and outbound frames separately --- .../simulator/network/hardware/base.py | 8 +- .../network/hardware/nodes/router.py | 2 +- .../simulator/system/core/packet_capture.py | 59 +++++--- .../simulator/system/core/session_manager.py | 2 +- .../simulator/system/services/arp/arp.py | 140 +++++++++--------- .../simulator/system/services/arp/host_arp.py | 2 +- 6 files changed, 117 insertions(+), 96 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 69f93f51..9edf7518 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -266,7 +266,7 @@ class NIC(SimComponent): """ if self.enabled: frame.set_sent_timestamp() - self.pcap.capture(frame) + self.pcap.capture_outbound(frame) self._connected_link.transmit_frame(sender_nic=self, frame=frame) return True # Cannot send Frame as the NIC is not enabled @@ -295,7 +295,7 @@ class NIC(SimComponent): self._connected_node.sys_log.info("Frame discarded as TTL limit reached") return False frame.set_received_timestamp() - self.pcap.capture(frame) + self.pcap.capture_inbound(frame) # If this destination or is broadcast accept_frame = False @@ -442,7 +442,7 @@ class SwitchPort(SimComponent): :param frame: The network frame to be sent. """ if self.enabled: - self.pcap.capture(frame) + self.pcap.capture_outbound(frame) self._connected_link.transmit_frame(sender_nic=self, frame=frame) return True # Cannot send Frame as the SwitchPort is not enabled @@ -461,7 +461,7 @@ class SwitchPort(SimComponent): if frame.ip and frame.ip.ttl < 1: self._connected_node.sys_log.info("Frame discarded as TTL limit reached") return False - self.pcap.capture(frame) + self.pcap.capture_inbound(frame) connected_node: Node = self._connected_node connected_node.forward_frame(frame=frame, incoming_port=self) return True diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 34eb0423..69717ae6 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -558,7 +558,7 @@ class RouterNIC(NIC): self._connected_node.sys_log.info("Frame discarded as TTL limit reached") return False frame.set_received_timestamp() - self.pcap.capture(frame) + self.pcap.capture_inbound(frame) # If this destination or is broadcast if frame.ethernet.dst_mac_addr == self.mac_address or frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": self._connected_node.receive_frame(frame=frame, from_nic=self) diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index bfb6a055..d3a14d2a 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -35,16 +35,17 @@ class PacketCapture: self.switch_port_number = switch_port_number "The SwitchPort number." + self.inbound_logger = None + self.outbound_logger = None + self.current_episode: int = 1 - self.setup_logger() + self.setup_logger(outbound=False) + self.setup_logger(outbound=True) - def setup_logger(self): + def setup_logger(self, outbound: bool = False): """Set up the logger configuration.""" - if not SIM_OUTPUT.save_pcap_logs: - return - - log_path = self._get_log_path() + log_path = self._get_log_path(outbound) file_handler = logging.FileHandler(filename=log_path) file_handler.setLevel(60) # Custom log level > CRITICAL to prevent any unwanted standard DEBUG-CRITICAL logs @@ -52,11 +53,17 @@ class PacketCapture: log_format = "%(message)s" file_handler.setFormatter(logging.Formatter(log_format)) - self.logger = logging.getLogger(self._logger_name) - self.logger.setLevel(60) # Custom log level > CRITICAL to prevent any unwanted standard DEBUG-CRITICAL logs - self.logger.addHandler(file_handler) + if outbound: + self.outbound_logger = logging.getLogger(self._get_logger_name(outbound)) + logger = self.outbound_logger + else: + self.inbound_logger = logging.getLogger(self._get_logger_name(outbound)) + logger = self.inbound_logger - self.logger.addFilter(_JSONFilter()) + logger.setLevel(60) # Custom log level > CRITICAL to prevent any unwanted standard DEBUG-CRITICAL logs + logger.addHandler(file_handler) + + logger.addFilter(_JSONFilter()) def read(self) -> List[Dict[str, Any]]: """ @@ -70,27 +77,35 @@ class PacketCapture: frames.append(json.loads(line.rstrip())) return frames - @property - def _logger_name(self) -> str: + def _get_logger_name(self, outbound: bool = False) -> str: """Get PCAP the logger name.""" if self.ip_address: - return f"{self.hostname}_{self.ip_address}_pcap" + return f"{self.hostname}_{self.ip_address}_{'outbound' if outbound else 'inbound'}_pcap" if self.switch_port_number: - return f"{self.hostname}_port-{self.switch_port_number}_pcap" - return f"{self.hostname}_pcap" + return f"{self.hostname}_port-{self.switch_port_number}_{'outbound' if outbound else 'inbound'}_pcap" + return f"{self.hostname}_{'outbound' if outbound else 'inbound'}_pcap" - def _get_log_path(self) -> Path: + def _get_log_path(self, outbound: bool = False) -> Path: """Get the path for the log file.""" root = SIM_OUTPUT.path / f"episode_{self.current_episode}" / self.hostname root.mkdir(exist_ok=True, parents=True) - return root / f"{self._logger_name}.log" + return root / f"{self._get_logger_name(outbound)}.log" - def capture(self, frame): # noqa - I'll have a circular import and cant use if TYPE_CHECKING ;( + def capture_inbound(self, frame): # noqa - I'll have a circular import and cant use if TYPE_CHECKING ;( """ - Capture a Frame and log it. + Capture an inbound Frame and log it. :param frame: The PCAP frame to capture. """ - if SIM_OUTPUT.save_pcap_logs: - msg = frame.model_dump_json() - self.logger.log(level=60, msg=msg) # Log at custom log level > CRITICAL + msg = frame.model_dump_json() + self.inbound_logger.log(level=60, msg=msg) # Log at custom log level > CRITICAL + + def capture_outbound(self, frame): # noqa - I'll have a circular import and cant use if TYPE_CHECKING ;( + """ + Capture an inbound Frame and log it. + + :param frame: The PCAP frame to capture. + """ + msg = frame.model_dump_json() + self.outbound_logger.log(level=60, msg=msg) # Log at custom log level > CRITICAL + diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index ce05193f..2120cde3 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -221,7 +221,7 @@ class SessionManager: if payload.request: dst_mac_address = "ff:ff:ff:ff:ff:ff" else: - dst_mac_address = payload.sender_mac_addr + dst_mac_address = payload.target_mac_addr outbound_nic = self.resolve_outbound_nic(payload.target_ip_address) is_broadcast = payload.request ip_protocol = IPProtocol.UDP diff --git a/src/primaite/simulator/system/services/arp/arp.py b/src/primaite/simulator/system/services/arp/arp.py index 28a2485c..c5b30d69 100644 --- a/src/primaite/simulator/system/services/arp/arp.py +++ b/src/primaite/simulator/system/services/arp/arp.py @@ -15,6 +15,12 @@ from primaite.simulator.system.services.service import Service class ARP(Service): + """ + The ARP (Address Resolution Protocol) Service. + + Manages ARP for resolving network layer addresses into link layer addresses. It maintains an ARP cache, + sends ARP requests and replies, and processes incoming ARP packets. + """ arp: Dict[IPv4Address, ARPEntry] = {} def __init__(self, **kwargs): @@ -27,7 +33,11 @@ class ARP(Service): pass def show(self, markdown: bool = False): - """Prints a table of ARC Cache.""" + """ + Prints the current state of the ARP cache in a table format. + + :param markdown: If True, format the output as Markdown. Otherwise, use plain text. + """ table = PrettyTable(["IP Address", "MAC Address", "Via"]) if markdown: table.set_style(MARKDOWN) @@ -71,37 +81,28 @@ class ARP(Service): @abstractmethod def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: """ - Get the MAC address associated with an IP address. + Retrieves the MAC address associated with a given IP address from the ARP cache. - :param ip_address: The IP address to look up in the cache. - :return: The MAC address associated with the IP address, or None if not found. + :param ip_address: The IP address to look up. + :return: The associated MAC address, if found. Otherwise, returns None. """ pass @abstractmethod def get_arp_cache_nic(self, ip_address: IPv4Address) -> Optional[NIC]: """ - Get the NIC associated with an IP address. + Retrieves the NIC associated with a given IP address from the ARP cache. - :param ip_address: The IP address to look up in the cache. - :return: The NIC associated with the IP address, or None if not found. + :param ip_address: The IP address to look up. + :return: The associated NIC, if found. Otherwise, returns None. """ pass def send_arp_request(self, target_ip_address: Union[IPv4Address, str]): """ - Perform a standard ARP request for a given target IP address. + Sends an ARP request to resolve the MAC address of a target IP address. - Broadcasts the request through all enabled NICs to determine the MAC address corresponding to the target IP - address. This method can be configured to ignore specific networks when sending out ARP requests, - which is useful in environments where certain addresses should not be queried. - - :param target_ip_address: The target IP address to send an ARP request for. - :param ignore_networks: An optional list of IPv4 addresses representing networks to be excluded from the ARP - request broadcast. Each address in this list indicates a network which will not be queried during the ARP - request process. This is particularly useful in complex network environments where traffic should be - minimized or controlled to specific subnets. It is mainly used by the router to prevent ARP requests being - sent back to their source. + :param target_ip_address: The target IP address for which the MAC address is being requested. """ outbound_nic = self.software_manager.session_manager.resolve_outbound_nic(target_ip_address) if outbound_nic: @@ -112,68 +113,59 @@ class ARP(Service): target_ip_address=target_ip_address, ) self.software_manager.session_manager.receive_payload_from_software_manager( - payload=arp_packet, dst_ip_address=target_ip_address, dst_port=Port.ARP, ip_protocol=self.protocol + payload=arp_packet, dst_ip_address=target_ip_address, dst_port=self.port, ip_protocol=self.protocol ) else: - print(f"failed for {target_ip_address}") - - def send_arp_reply(self, arp_reply: ARPPacket, from_nic: NIC): - """ - Send an ARP reply back through the NIC it came from. - - :param arp_reply: The ARP reply to send. - :param from_nic: The NIC to send the ARP reply from. - """ - self.sys_log.info( - f"Sending ARP reply from {arp_reply.sender_mac_addr}/{arp_reply.sender_ip_address} " - f"to {arp_reply.target_ip_address}/{arp_reply.target_mac_addr} " - ) - udp_header = UDPHeader(src_port=Port.ARP, dst_port=Port.ARP) - - ip_packet = IPPacket( - src_ip_address=arp_reply.sender_ip_address, - dst_ip_address=arp_reply.target_ip_address, - protocol=IPProtocol.UDP, - ) - - ethernet_header = EthernetHeader(src_mac_addr=arp_reply.sender_mac_addr, dst_mac_addr=arp_reply.target_mac_addr) - - frame = Frame(ethernet=ethernet_header, ip=ip_packet, udp=udp_header, payload=arp_reply) - from_nic.send_frame(frame) - - def process_arp_packet(self, from_nic: NIC, arp_packet: ARPPacket): - """ - Process a received ARP packet, handling both ARP requests and responses. - - If an ARP request is received for the local IP, a response is sent back. - If an ARP response is received, the ARP cache is updated with the new entry. - - :param from_nic: The NIC that received the ARP packet. - :param arp_packet: The ARP packet to be processed. - """ - - # Unmatched ARP Request - if arp_packet.target_ip_address != from_nic.ip_address: - self.sys_log.info( - f"Ignoring ARP request for {arp_packet.target_ip_address}. Current IP address is {from_nic.ip_address}" + self.sys_log.error( + "Cannot send ARP request as there is no outbound NIC to use. Try configuring the default gateway." + ) + + def send_arp_reply(self, arp_reply: ARPPacket): + """ + Sends an ARP reply in response to an ARP request. + + :param arp_reply: The ARP packet containing the reply. + :param from_nic: The NIC from which the ARP reply is sent. + """ + + outbound_nic = self.software_manager.session_manager.resolve_outbound_nic(arp_reply.target_ip_address) + if outbound_nic: + self.sys_log.info( + f"Sending ARP reply from {arp_reply.sender_mac_addr}/{arp_reply.sender_ip_address} " + f"to {arp_reply.target_ip_address}/{arp_reply.target_mac_addr} " + ) + self.software_manager.session_manager.receive_payload_from_software_manager( + payload=arp_reply, + dst_ip_address=arp_reply.target_ip_address, + dst_port=self.port, + ip_protocol=self.protocol + ) + else: + self.sys_log.error( + "Cannot send ARP reply as there is no outbound NIC to use. Try configuring the default gateway." ) - return - # Matched ARP request - self.add_arp_cache_entry( - ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic - ) - arp_packet = arp_packet.generate_reply(from_nic.mac_address) - self.send_arp_reply(arp_packet, from_nic) @abstractmethod def _process_arp_request(self, arp_packet: ARPPacket, from_nic: NIC): + """ + Processes an incoming ARP request. + + :param arp_packet: The ARP packet containing the request. + :param from_nic: The NIC that received the ARP request. + """ self.sys_log.info( f"Received ARP request for {arp_packet.target_ip_address} from " f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip_address} " ) def _process_arp_reply(self, arp_packet: ARPPacket, from_nic: NIC): + """ + Processes an incoming ARP reply. + + :param arp_packet: The ARP packet containing the reply. + :param from_nic: The NIC that received the ARP reply. + """ self.sys_log.info( f"Received ARP response for {arp_packet.sender_ip_address} " f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" @@ -183,6 +175,14 @@ class ARP(Service): ) def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Processes received data, handling ARP packets. + + :param payload: The payload received. + :param session_id: The session ID associated with the received data. + :param kwargs: Additional keyword arguments. + :return: True if the payload was processed successfully, otherwise False. + """ if not isinstance(payload, ARPPacket): print("failied on payload check", type(payload)) return False @@ -194,4 +194,10 @@ class ARP(Service): self._process_arp_reply(arp_packet=payload, from_nic=from_nic) def __contains__(self, item: Any) -> bool: + """ + Checks if an item is in the ARP cache. + + :param item: The item to check. + :return: True if the item is in the cache, otherwise False. + """ return item in self.arp diff --git a/src/primaite/simulator/system/services/arp/host_arp.py b/src/primaite/simulator/system/services/arp/host_arp.py index f3e70838..4d6f7738 100644 --- a/src/primaite/simulator/system/services/arp/host_arp.py +++ b/src/primaite/simulator/system/services/arp/host_arp.py @@ -92,4 +92,4 @@ class HostARP(ARP): ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic ) arp_packet = arp_packet.generate_reply(from_nic.mac_address) - self.send_arp_reply(arp_packet, from_nic) + self.send_arp_reply(arp_packet) From 7bbfd564fb75be750ab8fbf5d228e636d5030016 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 5 Feb 2024 08:44:10 +0000 Subject: [PATCH 563/980] #2248 - Big refactor of base with all Network Interface subclasses created to allow for proper management of ports on devices as it was starting to get messy with the Router. Some routing tests still need fixing as ARP doesn't seem to be working properly --- docs/source/config.rst | 2 +- .../network/base_hardware.rst | 2 +- .../config/_package_data/example_config.yaml | 2 +- .../example_config_2_rl_agents.yaml | 2 +- src/primaite/game/agent/actions.py | 14 +- src/primaite/game/agent/observations.py | 30 +- src/primaite/game/game.py | 19 +- src/primaite/notebooks/uc2_demo.ipynb | 46 +- src/primaite/simulator/core.py | 6 +- src/primaite/simulator/network/container.py | 26 +- src/primaite/simulator/network/creation.py | 12 +- .../simulator/network/hardware/base.py | 854 +++++++++--------- .../hardware/network_interface/__init__.py | 0 .../network_interface/layer_3_interface.py | 9 + .../network_interface/wired/__init__.py | 0 .../wired/router_interface.py | 0 .../network_interface/wireless/__init__.py | 0 .../wireless/wireless_access_point.py | 84 ++ .../wireless/wireless_nic.py | 81 ++ .../simulator/network/hardware/nodes/host.py | 63 -- .../network/hardware/nodes/host/__init__.py | 0 .../hardware/nodes/{ => host}/computer.py | 8 +- .../network/hardware/nodes/host/host_node.py | 354 ++++++++ .../hardware/nodes/{ => host}/server.py | 6 +- .../hardware/nodes/network/__init__.py | 0 .../hardware/nodes/network/network_node.py | 9 + .../hardware/nodes/{ => network}/router.py | 413 ++++++--- .../hardware/nodes/{ => network}/switch.py | 95 +- src/primaite/simulator/network/networks.py | 39 +- .../simulator/network/protocols/arp.py | 5 +- .../simulator/system/core/packet_capture.py | 10 +- .../simulator/system/core/session_manager.py | 76 +- .../simulator/system/core/software_manager.py | 4 +- .../simulator/system/services/arp/arp.py | 83 +- .../simulator/system/services/arp/host_arp.py | 95 -- .../system/services/arp/router_arp.py | 142 ++- .../simulator/system/services/icmp/icmp.py | 13 +- .../system/services/icmp/router_icmp.py | 24 +- src/primaite/utils/validators.py | 40 + .../assets/configs/bad_primaite_session.yaml | 2 +- .../configs/eval_only_primaite_session.yaml | 2 +- tests/assets/configs/multi_agent_session.yaml | 2 +- .../assets/configs/test_primaite_session.yaml | 2 +- .../configs/train_only_primaite_session.yaml | 2 +- tests/conftest.py | 71 +- .../test_uc2_data_manipulation_scenario.py | 4 +- .../test_action_integration.py | 14 +- .../game_layer/test_observations.py | 2 +- .../network/test_broadcast.py | 12 +- .../network/test_frame_transmission.py | 10 +- .../network/test_network_creation.py | 31 +- .../integration_tests/network/test_routing.py | 57 +- .../network/test_switched_network.py | 9 +- .../test_dos_bot_and_server.py | 10 +- .../system/test_application_on_node.py | 2 +- .../system/test_database_on_node.py | 2 +- .../system/test_dns_client_server.py | 8 +- .../system/test_ftp_client_server.py | 11 +- .../system/test_ntp_client_server.py | 6 +- .../system/test_service_on_node.py | 4 +- .../system/test_web_client_server.py | 14 +- .../test_web_client_server_and_database.py | 17 +- .../_network/_hardware/nodes/test_acl.py | 2 +- .../_network/_hardware/nodes/test_switch.py | 2 +- .../_simulator/_network/_hardware/test_nic.py | 8 +- .../_simulator/_network/test_container.py | 4 +- .../_red_applications/test_dos_bot.py | 2 +- .../_applications/test_database_client.py | 4 +- .../_system/_applications/test_web_browser.py | 4 +- .../_system/_services/test_dns_client.py | 2 +- .../_system/_services/test_dns_server.py | 2 +- .../_system/_services/test_ftp_client.py | 2 +- .../_system/_services/test_ftp_server.py | 2 +- .../_system/_services/test_web_server.py | 2 +- 74 files changed, 1806 insertions(+), 1192 deletions(-) create mode 100644 src/primaite/simulator/network/hardware/network_interface/__init__.py create mode 100644 src/primaite/simulator/network/hardware/network_interface/layer_3_interface.py create mode 100644 src/primaite/simulator/network/hardware/network_interface/wired/__init__.py create mode 100644 src/primaite/simulator/network/hardware/network_interface/wired/router_interface.py create mode 100644 src/primaite/simulator/network/hardware/network_interface/wireless/__init__.py create mode 100644 src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py create mode 100644 src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py delete mode 100644 src/primaite/simulator/network/hardware/nodes/host.py create mode 100644 src/primaite/simulator/network/hardware/nodes/host/__init__.py rename src/primaite/simulator/network/hardware/nodes/{ => host}/computer.py (61%) create mode 100644 src/primaite/simulator/network/hardware/nodes/host/host_node.py rename src/primaite/simulator/network/hardware/nodes/{ => host}/server.py (85%) create mode 100644 src/primaite/simulator/network/hardware/nodes/network/__init__.py create mode 100644 src/primaite/simulator/network/hardware/nodes/network/network_node.py rename src/primaite/simulator/network/hardware/nodes/{ => network}/router.py (69%) rename src/primaite/simulator/network/hardware/nodes/{ => network}/switch.py (56%) delete mode 100644 src/primaite/simulator/system/services/arp/host_arp.py create mode 100644 src/primaite/utils/validators.py diff --git a/docs/source/config.rst b/docs/source/config.rst index 23bf6097..575a3139 100644 --- a/docs/source/config.rst +++ b/docs/source/config.rst @@ -92,7 +92,7 @@ At the top level of the network are ``nodes`` and ``links``. * ``acl`` (Router only): Define the ACL rules at each index of the ACL on the router. the possible options are: ``action`` (PERMIT or DENY), ``src_port``, ``dst_port``, ``protocol``, ``src_ip``, ``dst_ip``. Any options left blank default to none which usually means that it will apply across all options. For example leaving ``src_ip`` blank will apply the rule to all IP addresses. * ``services`` (computers and servers only): a list of services to install on the node. They must define a ``ref``, ``type``, and ``options`` that depend on which ``type`` was selected. * ``applications`` (computer and servers only): Similar to services. A list of application to install on the node. - * ``nics`` (computers and servers only): If the node has multiple networking devices, the second, third, fourth, etc... must be defined here with an ``ip_address`` and ``subnet_mask``. + * ``network_interfaces`` (computers and servers only): If the node has multiple networking devices, the second, third, fourth, etc... must be defined here with an ``ip_address`` and ``subnet_mask``. **links:** * ``ref``: unique identifier for this link diff --git a/docs/source/simulation_components/network/base_hardware.rst b/docs/source/simulation_components/network/base_hardware.rst index ae922105..01c68036 100644 --- a/docs/source/simulation_components/network/base_hardware.rst +++ b/docs/source/simulation_components/network/base_hardware.rst @@ -176,7 +176,7 @@ Network Interfaces A Node will typically have one or more NICs attached to it for network connectivity: -- **nics** - A dictionary containing the NIC instances attached to the Node. NICs can be added/removed. +- **network_interfaces** - A dictionary containing the NIC instances attached to the Node. NICs can be added/removed. ------------- Configuration diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index b777060f..db00bad5 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -659,7 +659,7 @@ simulation: subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 - nics: + network_interfaces: 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index 6aa54487..3a6feb68 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -1070,7 +1070,7 @@ simulation: subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 - nics: + network_interfaces: 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 0c78f4c9..fe945678 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -555,7 +555,7 @@ class NetworkNICAbstractAction(AbstractAction): "network", "node", node_uuid, - "nic", + "network_interface", nic_uuid, self.verb, ] @@ -672,8 +672,8 @@ class ActionManager: self.ip_address_list = [] for node_uuid in self.node_uuids: node_obj = self.game.simulation.network.nodes[node_uuid] - nics = node_obj.nics - for nic_uuid, nic_obj in nics.items(): + network_interfaces = node_obj.network_interfaces + for nic_uuid, nic_obj in network_interfaces.items(): self.ip_address_list.append(nic_obj.ip_address) # action_args are settings which are applied to the action space as a whole. @@ -898,10 +898,10 @@ class ActionManager: """ node_uuid = self.get_node_uuid_by_idx(node_idx) node_obj = self.game.simulation.network.nodes[node_uuid] - nics = list(node_obj.nics.keys()) - if len(nics) <= nic_idx: + network_interfaces = list(node_obj.network_interfaces.keys()) + if len(network_interfaces) <= nic_idx: return None - return nics[nic_idx] + return network_interfaces[nic_idx] @classmethod def from_config(cls, game: "PrimaiteGame", cfg: Dict) -> "ActionManager": @@ -936,7 +936,7 @@ class ActionManager: node_ref = entry["node_ref"] nic_num = entry["nic_num"] node_obj = game.simulation.network.get_node_by_hostname(node_ref) - ip_address = node_obj.ethernet_port[nic_num].ip_address + ip_address = node_obj.network_interface[nic_num].ip_address ip_address_list.append(ip_address) obj = cls( diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 1f99987b..8f1c739c 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -406,7 +406,7 @@ class NodeObservation(AbstractObservation): where: Optional[Tuple[str]] = None, services: List[ServiceObservation] = [], folders: List[FolderObservation] = [], - nics: List[NicObservation] = [], + network_interfaces: List[NicObservation] = [], logon_status: bool = False, num_services_per_node: int = 2, num_folders_per_node: int = 2, @@ -429,9 +429,9 @@ class NodeObservation(AbstractObservation): :type folders: Dict[int,str], optional :param max_folders: Max number of folders in this node's obs space, defaults to 2 :type max_folders: int, optional - :param nics: Mapping between position in observation space and NIC idx, defaults to {} - :type nics: Dict[int,str], optional - :param max_nics: Max number of NICS in this node's obs space, defaults to 5 + :param network_interfaces: Mapping between position in observation space and NIC idx, defaults to {} + :type network_interfaces: Dict[int,str], optional + :param max_nics: Max number of network interfaces in this node's obs space, defaults to 5 :type max_nics: int, optional """ super().__init__() @@ -456,11 +456,11 @@ class NodeObservation(AbstractObservation): msg = f"Too many folders in Node observation for node. Truncating service {truncated_folder.where[-1]}" _LOGGER.warning(msg) - self.nics: List[NicObservation] = nics - while len(self.nics) < num_nics_per_node: - self.nics.append(NicObservation()) - while len(self.nics) > num_nics_per_node: - truncated_nic = self.nics.pop() + self.network_interfaces: List[NicObservation] = network_interfaces + while len(self.network_interfaces) < num_nics_per_node: + self.network_interfaces.append(NicObservation()) + while len(self.network_interfaces) > num_nics_per_node: + truncated_nic = self.network_interfaces.pop() msg = f"Too many NICs in Node observation for node. Truncating service {truncated_nic.where[-1]}" _LOGGER.warning(msg) @@ -469,7 +469,7 @@ class NodeObservation(AbstractObservation): self.default_observation: Dict = { "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, "FOLDERS": {i + 1: f.default_observation for i, f in enumerate(self.folders)}, - "NICS": {i + 1: n.default_observation for i, n in enumerate(self.nics)}, + "NETWORK_INTERFACES": {i + 1: n.default_observation for i, n in enumerate(self.network_interfaces)}, "operating_status": 0, } if self.logon_status: @@ -494,7 +494,7 @@ class NodeObservation(AbstractObservation): obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} obs["operating_status"] = node_state["operating_state"] - obs["NICS"] = {i + 1: nic.observe(state) for i, nic in enumerate(self.nics)} + obs["NETWORK_INTERFACES"] = {i + 1: network_interface.observe(state) for i, network_interface in enumerate(self.network_interfaces)} if self.logon_status: obs["logon_status"] = 0 @@ -508,7 +508,7 @@ class NodeObservation(AbstractObservation): "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), "operating_status": spaces.Discrete(5), - "NICS": spaces.Dict({i + 1: nic.space for i, nic in enumerate(self.nics)}), + "NETWORK_INTERFACES": spaces.Dict({i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)}), } if self.logon_status: space_shape["logon_status"] = spaces.Discrete(3) @@ -564,13 +564,13 @@ class NodeObservation(AbstractObservation): ] # create some configs for the NIC observation in the format {"nic_num":1}, {"nic_num":2}, {"nic_num":3}, etc. nic_configs = [{"nic_num": i for i in range(num_nics_per_node)}] - nics = [NicObservation.from_config(config=c, game=game, parent_where=where) for c in nic_configs] + network_interfaces = [NicObservation.from_config(config=c, game=game, parent_where=where) for c in nic_configs] logon_status = config.get("logon_status", False) return cls( where=where, services=services, folders=folders, - nics=nics, + network_interfaces=network_interfaces, logon_status=logon_status, num_services_per_node=num_services_per_node, num_folders_per_node=num_folders_per_node, @@ -728,7 +728,7 @@ class AclObservation(AbstractObservation): node_ref = ip_map_config["node_ref"] nic_num = ip_map_config["nic_num"] node_obj = game.simulation.network.nodes[game.ref_map_nodes[node_ref]] - nic_obj = node_obj.ethernet_port[nic_num] + nic_obj = node_obj.network_interface[nic_num] node_ip_to_idx[nic_obj.ip_address] = ip_idx + 2 router_hostname = config["router_hostname"] diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 89d71f38..60d201f6 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -11,11 +11,12 @@ from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAge from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction from primaite.session.io import SessionIO, SessionIOSettings -from primaite.simulator.network.hardware.base import NIC, NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.router import Router -from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.hardware.base import NodeOperatingState +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.host_node import NIC +from primaite.simulator.network.hardware.nodes.network.router import Router +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.sim_container import Simulation from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot @@ -305,8 +306,8 @@ class PrimaiteGame: if "options" in application_cfg: opt = application_cfg["options"] new_application.target_url = opt.get("target_url") - if "nics" in node_cfg: - for nic_num, nic_cfg in node_cfg["nics"].items(): + if "network_interfaces" in node_cfg: + for nic_num, nic_cfg in node_cfg["network_interfaces"].items(): new_node.connect_nic(NIC(ip_address=nic_cfg["ip_address"], subnet_mask=nic_cfg["subnet_mask"])) net.add_node(new_node) @@ -320,11 +321,11 @@ class PrimaiteGame: if isinstance(node_a, Switch): endpoint_a = node_a.switch_ports[link_cfg["endpoint_a_port"]] else: - endpoint_a = node_a.ethernet_port[link_cfg["endpoint_a_port"]] + endpoint_a = node_a.network_interface[link_cfg["endpoint_a_port"]] if isinstance(node_b, Switch): endpoint_b = node_b.switch_ports[link_cfg["endpoint_b_port"]] else: - endpoint_b = node_b.ethernet_port[link_cfg["endpoint_b_port"]] + endpoint_b = node_b.network_interface[link_cfg["endpoint_b_port"]] new_link = net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b) game.ref_map_links[link_cfg["ref"]] = new_link.uuid diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index 679e8226..9d90963f 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -126,7 +126,7 @@ " - FILES\n", " - \n", " - health_status\n", - " - NICS\n", + " - NETWORK_INTERFACES\n", " - \n", " - nic_status\n", " - operating_status\n", @@ -180,7 +180,7 @@ "\n", "The ACL rules in the observation space appear in the same order that they do in the actual ACL. Though, only the first 10 rules are shown, there are default rules lower down that cannot be changed by the agent. The extra rules just allow the network to function normally, by allowing pings, ARP traffic, etc.\n", "\n", - "Most nodes have only 1 nic, so the observation for those is placed at NIC index 1 in the observation space. Only the security suite has 2 NICs, the second NIC in the observation space is the one that connects the security suite with swtich_2.\n", + "Most nodes have only 1 network_interface, so the observation for those is placed at NIC index 1 in the observation space. Only the security suite has 2 NICs, the second NIC in the observation space is the one that connects the security suite with swtich_2.\n", "\n", "The meaning of the services' operating_state is:\n", "|operating_state|label|\n", @@ -462,37 +462,37 @@ " 10: {'PROTOCOLS': {'ALL': 1}}},\n", " 'NODES': {1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", " 'operating_status': 1},\n", " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", " 'operating_status': 1},\n", " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}},\n", " 'health_status': 1}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1},\n", " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1},\n", " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1},\n", " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1},\n", " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1}}}\n" ] @@ -588,31 +588,31 @@ "output_type": "stream", "text": [ "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", " 'operating_status': 1},\n", " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", " 'operating_status': 1},\n", " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}}, 'health_status': 1}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1},\n", " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1},\n", " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1},\n", " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1},\n", " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1}}\n" ] @@ -639,31 +639,31 @@ "output_type": "stream", "text": [ "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", " 'operating_status': 1},\n", " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 3, 'operating_status': 1}},\n", " 'operating_status': 1},\n", " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 2}}, 'health_status': 1}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1},\n", " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1},\n", " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1},\n", " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1},\n", " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", " 'operating_status': 1}}\n" ] diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 98a7e8db..964dac01 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -4,7 +4,7 @@ from abc import ABC, abstractmethod from typing import Callable, ClassVar, Dict, List, Optional, Union from uuid import uuid4 -from pydantic import BaseModel, ConfigDict +from pydantic import BaseModel, ConfigDict, Field from primaite import getLogger @@ -150,14 +150,12 @@ class SimComponent(BaseModel): model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow") """Configure pydantic to allow arbitrary types and to let the instance have attributes not present in model.""" - uuid: str + uuid: str = Field(default_factory=lambda: str(uuid4())) """The component UUID.""" _original_state: Dict = {} def __init__(self, **kwargs): - if not kwargs.get("uuid"): - kwargs["uuid"] = str(uuid4()) super().__init__(**kwargs) self._request_manager: RequestManager = self._init_request_manager() self._parent: Optional["SimComponent"] = None diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 8d8709d3..df793319 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -7,11 +7,11 @@ from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType, SimComponent -from primaite.simulator.network.hardware.base import Link, NIC, Node, SwitchPort -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.router import Router -from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.hardware.base import Link, Node, WiredNetworkInterface +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.network.router import Router +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.system.applications.application import Application from primaite.simulator.system.services.service import Service @@ -62,8 +62,8 @@ class Network(SimComponent): for node in self.nodes.values(): node.power_on() - for nic in node.nics.values(): - nic.enable() + for network_interface in node.network_interfaces.values(): + network_interface.enable() # Reset software for software in node.software_manager.software.values(): if isinstance(software, Service): @@ -148,7 +148,7 @@ class Network(SimComponent): table.title = "IP Addresses" for nodes in nodes_type_map.values(): for node in nodes: - for i, port in node.ethernet_port.items(): + for i, port in node.network_interface.items(): table.add_row([node.hostname, i, port.ip_address, port.subnet_mask, node.default_gateway]) print(table) @@ -209,8 +209,8 @@ class Network(SimComponent): node_b = link.endpoint_b._connected_node hostname_a = node_a.hostname if node_a else None hostname_b = node_b.hostname if node_b else None - port_a = link.endpoint_a._port_num_on_node - port_b = link.endpoint_b._port_num_on_node + port_a = link.endpoint_a.port_num + port_b = link.endpoint_b.port_num state["links"][uuid] = link.describe_state() state["links"][uuid]["hostname_a"] = hostname_a state["links"][uuid]["hostname_b"] = hostname_b @@ -272,7 +272,7 @@ class Network(SimComponent): self._node_request_manager.remove_request(name=node.uuid) def connect( - self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs + self, endpoint_a: Union[WiredNetworkInterface], endpoint_b: Union[WiredNetworkInterface], **kwargs ) -> Optional[Link]: """ Connect two endpoints on the network by creating a link between their NICs/SwitchPorts. @@ -280,9 +280,9 @@ class Network(SimComponent): .. note:: If the nodes owning the endpoints are not already in the network, they are automatically added. :param endpoint_a: The first endpoint to connect. - :type endpoint_a: Union[NIC, SwitchPort] + :type endpoint_a: WiredNetworkInterface :param endpoint_b: The second endpoint to connect. - :type endpoint_b: Union[NIC, SwitchPort] + :type endpoint_b: WiredNetworkInterface :raises RuntimeError: If any validation or runtime checks fail. """ node_a: Node = endpoint_a.parent diff --git a/src/primaite/simulator/network/creation.py b/src/primaite/simulator/network/creation.py index 48313a1f..370d85da 100644 --- a/src/primaite/simulator/network/creation.py +++ b/src/primaite/simulator/network/creation.py @@ -2,9 +2,9 @@ from ipaddress import IPv4Address from typing import Optional from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.router import ACLAction, Router -from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -111,7 +111,7 @@ def create_office_lan( if num_of_switches > 1: network.connect(core_switch.switch_ports[core_switch_port], switch.switch_ports[24]) else: - network.connect(router.ethernet_ports[1], switch.switch_ports[24]) + network.connect(router.network_interface[1], switch.switch_ports[24]) # Add PCs to the LAN and connect them to switches for i in range(1, num_pcs + 1): @@ -127,7 +127,7 @@ def create_office_lan( core_switch_port += 1 network.connect(core_switch.switch_ports[core_switch_port], switch.switch_ports[24]) else: - network.connect(router.ethernet_ports[1], switch.switch_ports[24]) + network.connect(router.network_interface[1], switch.switch_ports[24]) # Create and add a PC to the network pc = Computer( @@ -142,7 +142,7 @@ def create_office_lan( # Connect the PC to the switch switch_port += 1 - network.connect(switch.switch_ports[switch_port], pc.ethernet_port[1]) + network.connect(switch.switch_ports[switch_port], pc.network_interface[1]) switch.switch_ports[switch_port].enable() return network diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 9edf7518..5299b3dd 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -2,11 +2,14 @@ from __future__ import annotations import re import secrets +from abc import abstractmethod, ABC from ipaddress import IPv4Address, IPv4Network from pathlib import Path -from typing import Any, Dict, List, Literal, Optional, Union +from typing import Any, Literal, Union +from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable +from pydantic import Field, BaseModel from primaite import getLogger from primaite.exceptions import NetworkError @@ -15,10 +18,7 @@ from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.domain.account import Account from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket -from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame -from primaite.simulator.network.transmission.network_layer import IPPacket -from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader +from primaite.simulator.network.transmission.data_link_layer import Frame from primaite.simulator.system.applications.application import Application from primaite.simulator.system.core.packet_capture import PacketCapture from primaite.simulator.system.core.session_manager import SessionManager @@ -26,6 +26,7 @@ from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.processes.process import Process from primaite.simulator.system.services.service import Service +from primaite.utils.validators import IPV4Address _LOGGER = getLogger(__name__) @@ -34,14 +35,6 @@ def generate_mac_address(oui: Optional[str] = None) -> str: """ Generate a random MAC Address. - :Example: - - >>> generate_mac_address() - 'ef:7e:97:c8:a8:ce' - - >>> generate_mac_address(oui='aa:bb:cc') - 'aa:bb:cc:42:ba:41' - :param oui: The Organizationally Unique Identifier (OUI) portion of the MAC address. It should be a string with the first 3 bytes (24 bits) in the format "XX:XX:XX". :raises ValueError: If the 'oui' is not in the correct format (hexadecimal and 6 characters). @@ -55,111 +48,46 @@ def generate_mac_address(oui: Optional[str] = None) -> str: _LOGGER.error(msg) raise ValueError(msg) oui_bytes = [int(chunk, 16) for chunk in oui.split(":")] - mac = oui_bytes + random_bytes[len(oui_bytes) :] + mac = oui_bytes + random_bytes[len(oui_bytes):] else: mac = random_bytes return ":".join(f"{b:02x}" for b in mac) -class NIC(SimComponent): +class NetworkInterface(SimComponent, ABC): """ - Models a Network Interface Card (NIC) in a computer or network device. + A generic Network Interface in a Node on a Network. - :param ip_address: The IPv4 address assigned to the NIC. - :param subnet_mask: The subnet mask assigned to the NIC. - :param gateway: The default gateway IP address for forwarding network traffic to other networks. - :param mac_address: The MAC address of the NIC. Defaults to a randomly set MAC address. - :param speed: The speed of the NIC in Mbps (default is 100 Mbps). - :param mtu: The Maximum Transmission Unit (MTU) of the NIC in Bytes, representing the largest data packet size it - can handle without fragmentation (default is 1500 B). - :param wake_on_lan: Indicates if the NIC supports Wake-on-LAN functionality. - :param dns_servers: List of IP addresses of DNS servers used for name resolution. + This is a base class for specific types of network interfaces, providing common attributes and methods required + for network communication. It defines the fundamental properties that all network interfaces share, such as + MAC address, speed, MTU (maximum transmission unit), and the ability to enable or disable the interface. + + :ivar str mac_address: The MAC address of the network interface. Default to a randomly generated MAC address. + :ivar int speed: The speed of the interface in Mbps. Default is 100 Mbps. + :ivar int mtu: The Maximum Transmission Unit (MTU) of the interface in Bytes. Default is 1500 B. """ - ip_address: IPv4Address - "The IP address assigned to the NIC for communication on an IP-based network." - subnet_mask: IPv4Address - "The subnet mask assigned to the NIC." - mac_address: str - "The MAC address of the NIC. Defaults to a randomly set MAC address. Randomly generated upon creation." + mac_address: str = Field(default_factory=generate_mac_address) + "The MAC address of the interface." + speed: int = 100 - "The speed of the NIC in Mbps. Default is 100 Mbps." + "The speed of the interface in Mbps. Default is 100 Mbps." + mtu: int = 1500 - "The Maximum Transmission Unit (MTU) of the NIC in Bytes. Default is 1500 B" - wake_on_lan: bool = False - "Indicates if the NIC supports Wake-on-LAN functionality." - _connected_node: Optional[Node] = None - "The Node to which the NIC is connected." - _port_num_on_node: Optional[int] = None - "Which port number is assigned on this NIC" - _connected_link: Optional[Link] = None - "The Link to which the NIC is connected." + "The Maximum Transmission Unit (MTU) of the interface in Bytes. Default is 1500 B" + enabled: bool = False - "Indicates whether the NIC is enabled." + "Indicates whether the interface is enabled." + + _connected_node: Optional[Node] = None + "The Node to which the interface is connected." + + port_num: Optional[int] = None + "The port number assigned to this interface on the connected node." + pcap: Optional[PacketCapture] = None - - def __init__(self, **kwargs): - """ - NIC constructor. - - Performs some type conversion the calls ``super().__init__()``. Then performs some checking on the ip_address - and gateway just to check that it's all been configured correctly. - - :raises ValueError: When the ip_address and gateway are the same. And when the ip_address/subnet mask are a - network address. - """ - if not isinstance(kwargs["ip_address"], IPv4Address): - kwargs["ip_address"] = IPv4Address(kwargs["ip_address"]) - if "mac_address" not in kwargs: - kwargs["mac_address"] = generate_mac_address() - super().__init__(**kwargs) - - if self.ip_network.network_address == self.ip_address: - msg = ( - f"Failed to set IP address {self.ip_address} and subnet mask {self.subnet_mask} as it is a " - f"network address {self.ip_network.network_address}" - ) - _LOGGER.error(msg) - raise ValueError(msg) - - self.set_original_state() - - def set_original_state(self): - """Sets the original state.""" - vals_to_include = {"ip_address", "subnet_mask", "mac_address", "speed", "mtu", "wake_on_lan", "enabled"} - self._original_state = self.model_dump(include=vals_to_include) - - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - super().reset_component_for_episode(episode) - if episode and self.pcap: - self.pcap.current_episode = episode - self.pcap.setup_logger() - self.enable() - - def describe_state(self) -> Dict: - """ - Produce a dictionary describing the current state of this object. - - Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - - :return: Current state of this object and child objects. - :rtype: Dict - """ - state = super().describe_state() - state.update( - { - "ip_address": str(self.ip_address), - "subnet_mask": str(self.subnet_mask), - "mac_address": self.mac_address, - "speed": self.speed, - "mtu": self.mtu, - "wake_on_lan": self.wake_on_lan, - "enabled": self.enabled, - } - ) - return state + "A PacketCapture instance for capturing and analysing packets passing through this interface." def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() @@ -169,202 +97,11 @@ class NIC(SimComponent): return rm - @property - def ip_network(self) -> IPv4Network: - """ - Return the IPv4Network of the NIC. - - :return: The IPv4Network from the ip_address/subnet mask. - """ - return IPv4Network(f"{self.ip_address}/{self.subnet_mask}", strict=False) - - def enable(self): - """Attempt to enable the NIC.""" - if self.enabled: - return - if not self._connected_node: - _LOGGER.debug(f"NIC {self} cannot be enabled as it is not connected to a Node") - return - if self._connected_node.operating_state != NodeOperatingState.ON: - self._connected_node.sys_log.error(f"NIC {self} cannot be enabled as the endpoint is not turned on") - return - if not self._connected_link: - _LOGGER.debug(f"NIC {self} cannot be enabled as it is not connected to a Link") - return - - self.enabled = True - self._connected_node.sys_log.info(f"NIC {self} enabled") - self.pcap = PacketCapture(hostname=self._connected_node.hostname, ip_address=self.ip_address) - if self._connected_link: - self._connected_link.endpoint_up() - - def disable(self): - """Disable the NIC.""" - if not self.enabled: - return - - self.enabled = False - if self._connected_node: - self._connected_node.sys_log.info(f"NIC {self} disabled") - else: - _LOGGER.debug(f"NIC {self} disabled") - if self._connected_link: - self._connected_link.endpoint_down() - - def connect_link(self, link: Link): - """ - Connect the NIC to a link. - - :param link: The link to which the NIC is connected. - :type link: :class:`~primaite.simulator.network.transmission.physical_layer.Link` - """ - if self._connected_link: - _LOGGER.error(f"Cannot connect Link to NIC ({self.mac_address}) as it already has a connection") - return - - if self._connected_link == link: - _LOGGER.error(f"Cannot connect Link to NIC ({self.mac_address}) as it is already connected") - return - - # TODO: Inform the Node that a link has been connected - self._connected_link = link - self.enable() - _LOGGER.debug(f"NIC {self} connected to Link {link}") - - def disconnect_link(self): - """Disconnect the NIC from the connected Link.""" - if self._connected_link.endpoint_a == self: - self._connected_link.endpoint_a = None - if self._connected_link.endpoint_b == self: - self._connected_link.endpoint_b = None - self._connected_link = None - - def add_dns_server(self, ip_address: IPv4Address): - """ - Add a DNS server IP address. - - :param ip_address: The IP address of the DNS server to be added. - :type ip_address: ipaddress.IPv4Address - """ - pass - - def remove_dns_server(self, ip_address: IPv4Address): - """ - Remove a DNS server IP Address. - - :param ip_address: The IP address of the DNS server to be removed. - :type ip_address: ipaddress.IPv4Address - """ - pass - - def send_frame(self, frame: Frame) -> bool: - """ - Send a network frame from the NIC to the connected link. - - :param frame: The network frame to be sent. - :type frame: :class:`~primaite.simulator.network.osi_layers.Frame` - """ - if self.enabled: - frame.set_sent_timestamp() - self.pcap.capture_outbound(frame) - self._connected_link.transmit_frame(sender_nic=self, frame=frame) - return True - # Cannot send Frame as the NIC is not enabled - return False - - def receive_frame(self, frame: Frame) -> bool: - """ - Receive a network frame from the connected link, processing it if the NIC is enabled. - - This method decrements the Time To Live (TTL) of the frame, captures it using PCAP (Packet Capture), and checks - if the frame is either a broadcast or destined for this NIC. If the frame is acceptable, it is passed to the - connected node. The method also handles the discarding of frames with TTL expired and logs this event. - - The frame's reception is based on various conditions: - - If the NIC is disabled, the frame is not processed. - - If the TTL of the frame reaches zero after decrement, it is discarded and logged. - - If the frame is a broadcast or its destination MAC/IP address matches this NIC's, it is accepted. - - All other frames are dropped and logged or printed to the console. - - :param frame: The network frame being received. This should be an instance of the Frame class. - :return: Returns True if the frame is processed and passed to the node, False otherwise. - """ - if self.enabled: - frame.decrement_ttl() - if frame.ip and frame.ip.ttl < 1: - self._connected_node.sys_log.info("Frame discarded as TTL limit reached") - return False - frame.set_received_timestamp() - self.pcap.capture_inbound(frame) - # If this destination or is broadcast - accept_frame = False - - # Check if it's a broadcast: - if frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": - if frame.ip.dst_ip_address in {self.ip_address, self.ip_network.broadcast_address}: - accept_frame = True - else: - if frame.ethernet.dst_mac_addr == self.mac_address: - accept_frame = True - - if accept_frame: - self._connected_node.receive_frame(frame=frame, from_nic=self) - return True - return False - - def __str__(self) -> str: - return f"{self.mac_address}/{self.ip_address}" - - -class SwitchPort(SimComponent): - """ - Models a switch port in a network switch device. - - :param mac_address: The MAC address of the SwitchPort. Defaults to a randomly set MAC address. - :param speed: The speed of the SwitchPort in Mbps (default is 100 Mbps). - :param mtu: The Maximum Transmission Unit (MTU) of the SwitchPort in Bytes, representing the largest data packet - size it can handle without fragmentation (default is 1500 B). - """ - - port_num: int = 1 - mac_address: str - "The MAC address of the SwitchPort. Defaults to a randomly set MAC address." - speed: int = 100 - "The speed of the SwitchPort in Mbps. Default is 100 Mbps." - mtu: int = 1500 - "The Maximum Transmission Unit (MTU) of the SwitchPort in Bytes. Default is 1500 B" - _connected_node: Optional[Node] = None - "The Node to which the SwitchPort is connected." - _port_num_on_node: Optional[int] = None - "The port num on the connected node." - _connected_link: Optional[Link] = None - "The Link to which the SwitchPort is connected." - enabled: bool = False - "Indicates whether the SwitchPort is enabled." - pcap: Optional[PacketCapture] = None - - def __init__(self, **kwargs): - """The SwitchPort constructor.""" - if "mac_address" not in kwargs: - kwargs["mac_address"] = generate_mac_address() - super().__init__(**kwargs) - - self.set_original_state() - - def set_original_state(self): - """Sets the original state.""" - vals_to_include = {"port_num", "mac_address", "speed", "mtu", "enabled"} - self._original_state = self.model_dump(include=vals_to_include) - super().set_original_state() - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. - Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. - :return: Current state of this object and child objects. - :rtype: Dict """ state = super().describe_state() state.update( @@ -377,58 +114,135 @@ class SwitchPort(SimComponent): ) return state + def reset_component_for_episode(self, episode: int): + """Reset the original state of the SimComponent.""" + super().reset_component_for_episode(episode) + if episode and self.pcap: + self.pcap.current_episode = episode + self.pcap.setup_logger() + self.enable() + + @abstractmethod def enable(self): - """Attempt to enable the SwitchPort.""" + """Enable the interface.""" + pass + + @abstractmethod + def disable(self): + """Disable the interface.""" + pass + + @abstractmethod + def send_frame(self, frame: Frame) -> bool: + """ + Attempts to send a network frame through the interface. + + :param frame: The network frame to be sent. + :return: A boolean indicating whether the frame was successfully sent. + """ + pass + + @abstractmethod + def receive_frame(self, frame: Frame) -> bool: + """ + Receives a network frame on the interface. + + :param frame: The network frame being received. + :return: A boolean indicating whether the frame was successfully received. + """ + pass + + def __str__(self) -> str: + """ + String representation of the NIC. + + :return: A string combining the port number and the mac address + """ + return f"Port {self.port_num}: {self.mac_address}" + + +class WiredNetworkInterface(NetworkInterface, ABC): + """ + Represents a wired network interface in a network device. + + This abstract base class serves as a foundational blueprint for wired network interfaces, offering core + functionalities and enforcing the implementation of key operational methods such as enabling and disabling the + interface. It encapsulates common attributes and behaviors intrinsic to wired interfaces, including the + management of physical or logical connections to network links and the provision of methods for connecting to and + disconnecting from these links. + + Inherits from: + - NetworkInterface: Provides basic network interface properties and methods. + + + Subclasses of this class are expected to provide concrete implementations for the abstract methods defined here, + tailoring the functionality to the specific requirements of the wired interface types they represent. + """ + + _connected_link: Optional[Link] = None + "The network link to which the network interface is connected." + + def enable(self): + """Attempt to enable the network interface.""" if self.enabled: return if not self._connected_node: - _LOGGER.error(f"SwitchPort {self} cannot be enabled as it is not connected to a Node") + _LOGGER.error(f"Interface {self} cannot be enabled as it is not connected to a Node") return if self._connected_node.operating_state != NodeOperatingState.ON: - self._connected_node.sys_log.info(f"SwitchPort {self} cannot be enabled as the endpoint is not turned on") + self._connected_node.sys_log.info( + f"Interface {self} cannot be enabled as the connected Node is not powered on" + ) return self.enabled = True - self._connected_node.sys_log.info(f"SwitchPort {self} enabled") - self.pcap = PacketCapture(hostname=self._connected_node.hostname, switch_port_number=self.port_num) + self._connected_node.sys_log.info(f"Network Interface {self} enabled") + self.pcap = PacketCapture(hostname=self._connected_node.hostname, interface_num=self.port_num) if self._connected_link: self._connected_link.endpoint_up() def disable(self): - """Disable the SwitchPort.""" + """Disable the network interface.""" if not self.enabled: return self.enabled = False if self._connected_node: - self._connected_node.sys_log.info(f"SwitchPort {self} disabled") + self._connected_node.sys_log.info(f"Network Interface {self} disabled") else: - _LOGGER.debug(f"SwitchPort {self} disabled") + _LOGGER.debug(f"Interface {self} disabled") if self._connected_link: self._connected_link.endpoint_down() def connect_link(self, link: Link): """ - Connect the SwitchPort to a link. + Connect this network interface to a specified link. - :param link: The link to which the SwitchPort is connected. + This method establishes a connection between the network interface and a network link if the network interface is not already + connected. If the network interface is already connected to a link, it logs an error and does not change the existing + connection. + + :param link: The Link instance to connect to this network interface. """ if self._connected_link: - _LOGGER.error(f"Cannot connect link to SwitchPort {self.mac_address} as it already has a connection") + _LOGGER.error(f"Cannot connect Link to network interface {self} as it already has a connection") return if self._connected_link == link: - _LOGGER.error(f"Cannot connect Link to SwitchPort {self.mac_address} as it is already connected") + _LOGGER.error(f"Cannot connect Link to network interface {self} as it is already connected") return - # TODO: Inform the Switch that a link has been connected self._connected_link = link - _LOGGER.debug(f"SwitchPort {self} connected to Link {link}") self.enable() def disconnect_link(self): - """Disconnect the SwitchPort from the connected Link.""" + """ + Disconnect the network interface from its connected Link, if any. + + This method removes the association between the network interface and its connected Link. It updates the connected Link's + endpoints to reflect the disconnection. + """ if self._connected_link.endpoint_a == self: self._connected_link.endpoint_a = None if self._connected_link.endpoint_b == self: @@ -437,38 +251,220 @@ class SwitchPort(SimComponent): def send_frame(self, frame: Frame) -> bool: """ - Send a network frame from the SwitchPort to the connected link. + Attempt to send a network frame through the connected Link. + + This method sends a frame if the NIC is enabled and connected to a link. It captures the frame using PCAP + (if available) and transmits it through the connected link. Returns True if the frame is successfully sent, + False otherwise (e.g., if the Network Interface is disabled). :param frame: The network frame to be sent. + :return: True if the frame is sent, False if the Network Interface is disabled or not connected to a link. """ if self.enabled: + frame.set_sent_timestamp() self.pcap.capture_outbound(frame) self._connected_link.transmit_frame(sender_nic=self, frame=frame) return True - # Cannot send Frame as the SwitchPort is not enabled + # Cannot send Frame as the NIC is not enabled return False + @abstractmethod def receive_frame(self, frame: Frame) -> bool: """ - Receive a network frame from the connected link if the SwitchPort is enabled. - - The Frame is passed to the Node. + Receives a network frame on the network interface. :param frame: The network frame being received. + :return: A boolean indicating whether the frame was successfully received. """ - if self.enabled: - frame.decrement_ttl() - if frame.ip and frame.ip.ttl < 1: - self._connected_node.sys_log.info("Frame discarded as TTL limit reached") - return False - self.pcap.capture_inbound(frame) - connected_node: Node = self._connected_node - connected_node.forward_frame(frame=frame, incoming_port=self) - return True - return False + pass - def __str__(self) -> str: - return f"{self.mac_address}" + +class Layer3Interface(BaseModel, ABC): + """ + Represents a Layer 3 (Network Layer) interface in a network device. + + This class serves as a base for network interfaces that operate at Layer 3 of the OSI model, providing IP + connectivity and subnetting capabilities. It's not meant to be instantiated directly but to be subclassed by + specific types of network interfaces that require IP addressing capabilities. + + :ivar IPV4Address ip_address: The IP address assigned to the interface. This address enables the interface to + participate in IP-based networking, allowing it to send and receive IP packets. + :ivar IPv4Address subnet_mask: The subnet mask assigned to the interface. This mask helps in determining the + network segment that the interface belongs to and is used in IP routing decisions. + """ + ip_address: IPV4Address + "The IP address assigned to the interface for communication on an IP-based network." + + subnet_mask: IPV4Address + "The subnet mask assigned to the interface, defining the network portion and the host portion of the IP address." + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + """ + state = { + "ip_address": str(self.ip_address), + "subnet_mask": str(self.subnet_mask), + } + + return state + + @property + def ip_network(self) -> IPv4Network: + """ + Calculate and return the IPv4Network derived from the NIC's IP address and subnet mask. + + This property constructs an IPv4Network object which represents the whole network that the NIC's IP address + belongs to, based on its subnet mask. It's useful for determining the network range and broadcast address. + + :return: An IPv4Network instance representing the network of this NIC. + """ + return IPv4Network(f"{self.ip_address}/{self.subnet_mask}", strict=False) + + +class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): + """ + Represents an IP wired network interface. + + This interface operates at both the data link layer (Layer 2) and the network layer (Layer 3) of the OSI model, + specifically tailored for IP-based communication. This abstract class serves as a template for creating specific + wired network interfaces that support Internet Protocol (IP) functionalities. + + As this class is an amalgamation of its parent classes without additional attributes or methods, it is recommended + to refer to the documentation of `WiredNetworkInterface` and `Layer3Interface` for detailed information on the + supported operations and functionalities. + + The class inherits from: + - `WiredNetworkInterface`: Provides the functionalities and characteristics of a wired connection, such as + physical link establishment and data transmission over a cable. + - `Layer3Interface`: Enables network layer capabilities, including IP address assignment, routing, and + potentially, Layer 3 protocols like IPsec. + + As an abstract class, `IPWiredNetworkInterface` does not implement specific methods but mandates that any derived + class provides implementations for the functionalities of both `WiredNetworkInterface` and `Layer3Interface`. + This structure is ideal for representing network interfaces in devices that require wired connections and are + capable of IP routing and addressing, such as routers, switches, as well as end-host devices like computers and + servers. + + Derived classes should define specific behaviors and properties of an IP-capable wired network interface, + customizing it for their specific use cases. + """ + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + # Get the state from the WiredNetworkInterface + state = WiredNetworkInterface.describe_state(self) + + # Update the state with information from Layer3Interface + state.update(Layer3Interface.describe_state(self)) + + return state + + def enable(self): + super().enable() + try: + self._connected_node.default_gateway_hello() + except AttributeError: + pass + + + @abstractmethod + def receive_frame(self, frame: Frame) -> bool: + """ + Receives a network frame on the network interface. + + :param frame: The network frame being received. + :return: A boolean indicating whether the frame was successfully received. + """ + pass + + + +class WirelessNetworkInterface(NetworkInterface, ABC): + """ + Represents a wireless network interface in a network device. + + This abstract base class models wireless network interfaces, encapsulating properties and behaviors specific to + wireless connectivity. It provides a framework for managing wireless connections, including signal strength, + security protocols, and other wireless-specific attributes and methods. + + Wireless network interfaces differ from wired ones in their medium of communication, relying on radio frequencies + for data transmission and reception. This class serves as a base for more specific types of wireless interfaces, + such as Wi-Fi adapters or radio network interfaces, ensuring that essential wireless functionality is defined + and standardised. + + Inherits from: + - NetworkInterface: Provides basic network interface properties and methods. + + As an abstract base class, it requires subclasses to implement specific methods related to wireless communication + and may define additional properties and methods specific to wireless technology. + """ + + +class IPWirelessNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): + """ + Represents an IP wireless network interface. + + This interface operates at both the data link layer (Layer 2) and the network layer (Layer 3) of the OSI model, + specifically tailored for IP-based communication over wireless connections. This abstract class provides a + template for creating specific wireless network interfaces that support Internet Protocol (IP) functionalities. + + As this class is a combination of its parent classes without additional attributes or methods, please refer to + the documentation of `WirelessNetworkInterface` and `Layer3Interface` for more details on the supported operations + and functionalities. + + The class inherits from: + - `WirelessNetworkInterface`: Providing the functionalities and characteristics of a wireless connection, such as + managing wireless signal transmission, reception, and associated wireless protocols. + - `Layer3Interface`: Enabling network layer capabilities, including IP address assignment, routing, and + potentially, Layer 3 protocols like IPsec. + + As an abstract class, `IPWirelessNetworkInterface` does not implement specific methods but ensures that any derived + class provides implementations for the functionalities of both `WirelessNetworkInterface` and `Layer3Interface`. + This setup is ideal for representing network interfaces in devices that require wireless connections and are capable + of IP routing and addressing, such as wireless routers, access points, and wireless end-host devices like smartphones + and laptops. + + This class should be extended by concrete classes that define specific behaviors and properties of an IP-capable + wireless network interface. + """ + + @abstractmethod + def enable(self): + """Enable the interface.""" + pass + + @abstractmethod + def disable(self): + """Disable the interface.""" + pass + + @abstractmethod + def send_frame(self, frame: Frame) -> bool: + """ + Attempts to send a network frame through the interface. + + :param frame: The network frame to be sent. + :return: A boolean indicating whether the frame was successfully sent. + """ + pass + + @abstractmethod + def receive_frame(self, frame: Frame) -> bool: + """ + Receives a network frame on the interface. + + :param frame: The network frame being received. + :return: A boolean indicating whether the frame was successfully received. + """ + pass class Link(SimComponent): @@ -480,10 +476,10 @@ class Link(SimComponent): :param bandwidth: The bandwidth of the Link in Mbps (default is 100 Mbps). """ - endpoint_a: Union[NIC, SwitchPort] - "The first NIC or SwitchPort connected to the Link." - endpoint_b: Union[NIC, SwitchPort] - "The second NIC or SwitchPort connected to the Link." + endpoint_a: Union[WiredNetworkInterface] + "The first WiredNetworkInterface connected to the Link." + endpoint_b: Union[WiredNetworkInterface] + "The second WiredNetworkInterface connected to the Link." bandwidth: float = 100.0 "The bandwidth of the Link in Mbps (default is 100 Mbps)." current_load: float = 0.0 @@ -567,7 +563,7 @@ class Link(SimComponent): return True return False - def transmit_frame(self, sender_nic: Union[NIC, SwitchPort], frame: Frame) -> bool: + def transmit_frame(self, sender_nic: Union[WiredNetworkInterface], frame: Frame) -> bool: """ Send a network frame from one NIC or SwitchPort to another connected NIC or SwitchPort. @@ -599,6 +595,7 @@ class Link(SimComponent): def __str__(self) -> str: return f"{self.endpoint_a}<-->{self.endpoint_b}" + class Node(SimComponent): """ A basic Node class that represents a node on the network. @@ -612,14 +609,14 @@ class Node(SimComponent): hostname: str "The node hostname on the network." - default_gateway: Optional[IPv4Address] = None + default_gateway: Optional[IPV4Address] = None "The default gateway IP address for forwarding network traffic to other networks." operating_state: NodeOperatingState = NodeOperatingState.OFF "The hardware state of the node." - nics: Dict[str, NIC] = {} - "The NICs on the node." - ethernet_port: Dict[int, NIC] = {} - "The NICs on the node by port id." + network_interfaces: Dict[str, NetworkInterface] = {} + "The Network Interfaces on the node." + network_interface: Dict[int, NetworkInterface] = {} + "The Network Interfaces on the node by port id." dns_server: Optional[IPv4Address] = None "List of IP addresses of DNS servers used for name resolution." @@ -673,9 +670,6 @@ class Node(SimComponent): This method initializes the ARP cache, ICMP handler, session manager, and software manager if they are not provided. """ - if kwargs.get("default_gateway"): - if not isinstance(kwargs["default_gateway"], IPv4Address): - kwargs["default_gateway"] = IPv4Address(kwargs["default_gateway"]) if not kwargs.get("sys_log"): kwargs["sys_log"] = SysLog(kwargs["hostname"]) if not kwargs.get("session_manager"): @@ -698,6 +692,9 @@ class Node(SimComponent): self._install_system_software() self.set_original_state() + # def model_post_init(self, __context: Any) -> None: + # self._install_system_software() + # self.set_original_state() def set_original_state(self): """Sets the original state.""" @@ -706,8 +703,8 @@ class Node(SimComponent): self.file_system.set_original_state() - for nic in self.nics.values(): - nic.set_original_state() + for network_interface in self.network_interfaces.values(): + network_interface.set_original_state() vals_to_include = { "hostname", @@ -736,8 +733,8 @@ class Node(SimComponent): self.file_system.reset_component_for_episode(episode) # Reset all Nics - for nic in self.nics.values(): - nic.reset_component_for_episode(episode) + for network_interface in self.network_interfaces.values(): + network_interface.reset_component_for_episode(episode) for software in self.software_manager.software.values(): software.reset_component_for_episode(episode) @@ -754,7 +751,7 @@ class Node(SimComponent): self._service_request_manager = RequestManager() rm.add_request("service", RequestType(func=self._service_request_manager)) self._nic_request_manager = RequestManager() - rm.add_request("nic", RequestType(func=self._nic_request_manager)) + rm.add_request("network_interface", RequestType(func=self._nic_request_manager)) rm.add_request("file_system", RequestType(func=self.file_system._request_manager)) @@ -796,8 +793,8 @@ class Node(SimComponent): { "hostname": self.hostname, "operating_state": self.operating_state.value, - "NICs": {eth_num: nic.describe_state() for eth_num, nic in self.ethernet_port.items()}, - # "switch_ports": {uuid, sp for uuid, sp in self.switch_ports.items()}, + "NICs": {eth_num: network_interface.describe_state() for eth_num, network_interface in + self.network_interface.items()}, "file_system": self.file_system.describe_state(), "applications": {app.name: app.describe_state() for app in self.applications.values()}, "services": {svc.name: svc.describe_state() for svc in self.services.values()}, @@ -807,14 +804,12 @@ class Node(SimComponent): ) return state - def show(self, markdown: bool = False, component: Literal["NIC", "OPEN_PORTS"] = "NIC"): - """A multi-use .show function that accepts either NIC or OPEN_PORTS.""" - if component == "NIC": - self._show_nic(markdown) - elif component == "OPEN_PORTS": - self._show_open_ports(markdown) + def show(self, markdown: bool = False): + "Show function that calls both show NIC and show open ports." + self.show_nic(markdown) + self.show_open_ports(markdown) - def _show_open_ports(self, markdown: bool = False): + def show_open_ports(self, markdown: bool = False): """Prints a table of the open ports on the Node.""" table = PrettyTable(["Port", "Name"]) if markdown: @@ -825,21 +820,22 @@ class Node(SimComponent): table.add_row([port.value, port.name]) print(table) - def _show_nic(self, markdown: bool = False): + def show_nic(self, markdown: bool = False): """Prints a table of the NICs on the Node.""" - table = PrettyTable(["Port", "MAC Address", "Address", "Speed", "Status"]) + table = PrettyTable(["Port", "Type", "MAC Address", "Address", "Speed", "Status"]) if markdown: table.set_style(MARKDOWN) table.align = "l" table.title = f"{self.hostname} Network Interface Cards" - for port, nic in self.ethernet_port.items(): + for port, network_interface in self.network_interface.items(): table.add_row( [ port, - nic.mac_address, - f"{nic.ip_address}/{nic.ip_network.prefixlen}", - nic.speed, - "Enabled" if nic.enabled else "Disabled", + network_interface.__name__, + network_interface.mac_address, + f"{network_interface.ip_address}/{network_interface.ip_network.prefixlen}", + network_interface.speed, + "Enabled" if network_interface.enabled else "Disabled", ] ) print(table) @@ -864,9 +860,8 @@ class Node(SimComponent): if self.operating_state == NodeOperatingState.BOOTING: self.operating_state = NodeOperatingState.ON self.sys_log.info(f"{self.hostname}: Turned on") - for nic in self.nics.values(): - if nic._connected_link: - nic.enable() + for network_interface in self.network_interfaces.values(): + network_interface.enable() self._start_up_actions() @@ -975,23 +970,22 @@ class Node(SimComponent): if self.start_up_duration <= 0: self.operating_state = NodeOperatingState.ON self._start_up_actions() - self.sys_log.info("Turned on") - for nic in self.nics.values(): - if nic._connected_link: - nic.enable() + self.sys_log.info("Power on") + for network_interface in self.network_interfaces.values(): + network_interface.enable() def power_off(self): """Power off the Node, disabling its NICs if it is in the ON state.""" if self.operating_state == NodeOperatingState.ON: - for nic in self.nics.values(): - nic.disable() + for network_interface in self.network_interfaces.values(): + network_interface.disable() self.operating_state = NodeOperatingState.SHUTTING_DOWN self.shut_down_countdown = self.shut_down_duration if self.shut_down_duration <= 0: self._shut_down_actions() self.operating_state = NodeOperatingState.OFF - self.sys_log.info("Turned off") + self.sys_log.info("Power off") def reset(self): """ @@ -1000,59 +994,57 @@ class Node(SimComponent): Powers off the node and sets is_resetting to True. Applying more timesteps will eventually turn the node back on. """ - if not self.operating_state.ON: - self.sys_log.error(f"Cannot reset {self.hostname} - node is not turned on.") - else: + if self.operating_state.ON: self.is_resetting = True - self.sys_log.info(f"Resetting {self.hostname}...") + self.sys_log.info(f"Resetting") self.power_off() - def connect_nic(self, nic: NIC): + def connect_nic(self, network_interface: NetworkInterface): """ - Connect a NIC (Network Interface Card) to the node. + Connect a Network Interface to the node. - :param nic: The NIC to connect. + :param network_interface: The NIC to connect. :raise NetworkError: If the NIC is already connected. """ - if nic.uuid not in self.nics: - self.nics[nic.uuid] = nic - self.ethernet_port[len(self.nics)] = nic - nic._connected_node = self - nic._port_num_on_node = len(self.nics) - nic.parent = self - self.sys_log.info(f"Connected NIC {nic}") + if network_interface.uuid not in self.network_interfaces: + self.network_interfaces[network_interface.uuid] = network_interface + self.network_interface[len(self.network_interfaces)] = network_interface + network_interface._connected_node = self + network_interface.port_num = len(self.network_interfaces) + network_interface.parent = self + self.sys_log.info(f"Connected Network Interface {network_interface}") if self.operating_state == NodeOperatingState.ON: - nic.enable() - self._nic_request_manager.add_request(nic.uuid, RequestType(func=nic._request_manager)) + network_interface.enable() + self._nic_request_manager.add_request( + network_interface.uuid, RequestType(func=network_interface._request_manager) + ) else: - msg = f"Cannot connect NIC {nic} as it is already connected" + msg = f"Cannot connect NIC {network_interface} as it is already connected" self.sys_log.logger.error(msg) - _LOGGER.error(msg) raise NetworkError(msg) - def disconnect_nic(self, nic: Union[NIC, str]): + def disconnect_nic(self, network_interface: Union[NetworkInterface, str]): """ Disconnect a NIC (Network Interface Card) from the node. - :param nic: The NIC to Disconnect, or its UUID. + :param network_interface: The NIC to Disconnect, or its UUID. :raise NetworkError: If the NIC is not connected. """ - if isinstance(nic, str): - nic = self.nics.get(nic) - if nic or nic.uuid in self.nics: - for port, _nic in self.ethernet_port.items(): - if nic == _nic: - self.ethernet_port.pop(port) + if isinstance(network_interface, str): + network_interface = self.network_interfaces.get(network_interface) + if network_interface or network_interface.uuid in self.network_interfaces: + for port, _nic in self.network_interface.items(): + if network_interface == _nic: + self.network_interface.pop(port) break - self.nics.pop(nic.uuid) - nic.parent = None - nic.disable() - self.sys_log.info(f"Disconnected NIC {nic}") - self._nic_request_manager.remove_request(nic.uuid) + self.network_interfaces.pop(network_interface.uuid) + network_interface.parent = None + network_interface.disable() + self.sys_log.info(f"Disconnected Network Interface {network_interface}") + self._nic_request_manager.remove_request(network_interface.uuid) else: - msg = f"Cannot disconnect NIC {nic} as it is not connected" + msg = f"Cannot disconnect NIC {network_interface} as it is not connected" self.sys_log.logger.error(msg) - _LOGGER.error(msg) raise NetworkError(msg) def ping(self, target_ip_address: Union[IPv4Address, str], pings: int = 4) -> bool: @@ -1065,56 +1057,32 @@ class Node(SimComponent): """ if not isinstance(target_ip_address, IPv4Address): target_ip_address = IPv4Address(target_ip_address) - return self.software_manager.icmp.ping(target_ip_address) + if self.software_manager.icmp: + return self.software_manager.icmp.ping(target_ip_address, pings) + return False - def send_frame(self, frame: Frame): - """ - Send a Frame from the Node to the connected NIC. - - :param frame: The Frame to be sent. - """ - if self.operating_state == NodeOperatingState.ON: - nic: NIC = self._get_arp_cache_nic(frame.ip.dst_ip_address) - nic.send_frame(frame) - - def receive_frame(self, frame: Frame, from_nic: NIC): + @abstractmethod + def receive_frame(self, frame: Frame, from_network_interface: NetworkInterface): """ Receive a Frame from the connected NIC and process it. - Depending on the protocol, the frame is passed to the appropriate handler such as ARP or ICMP, or up to the - SessionManager if no code manager exists. + This is an abstract implementation of receive_frame with some very basic functionality (ARP population). All + Node subclasses should have their own implementation of receive_frame that first calls super().receive_frame( + ) before implementing its own internal receive_frame logic. :param frame: The Frame being received. - :param from_nic: The NIC that received the frame. + :param from_network_interface: The Network Interface that received the frame. """ if self.operating_state == NodeOperatingState.ON: if frame.ip: - if frame.ip.src_ip_address in self.software_manager.arp: + if self.software_manager.arp: self.software_manager.arp.add_arp_cache_entry( - ip_address=frame.ip.src_ip_address, mac_address=frame.ethernet.src_mac_addr, nic=from_nic + ip_address=frame.ip.src_ip_address, + mac_address=frame.ethernet.src_mac_addr, + network_interface=from_network_interface ) - - # Check if the destination port is open on the Node - dst_port = None - if frame.tcp: - dst_port = frame.tcp.dst_port - elif frame.udp: - dst_port = frame.udp.dst_port - - accept_frame = False - if frame.icmp or dst_port in self.software_manager.get_open_ports(): - # accept the frame as the port is open or if it's an ICMP frame - accept_frame = True - - # TODO: add internal node firewall check here? - - if accept_frame: - self.session_manager.receive_frame(frame, from_nic) - else: - # denied as port closed - self.sys_log.info(f"Ignoring frame for port {frame.tcp.dst_port.value} from {frame.ip.src_ip_address}") - # TODO: do we need to do anything more here? - pass + else: + return def install_service(self, service: Service) -> None: """ diff --git a/src/primaite/simulator/network/hardware/network_interface/__init__.py b/src/primaite/simulator/network/hardware/network_interface/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/network/hardware/network_interface/layer_3_interface.py b/src/primaite/simulator/network/hardware/network_interface/layer_3_interface.py new file mode 100644 index 00000000..fdfd3b26 --- /dev/null +++ b/src/primaite/simulator/network/hardware/network_interface/layer_3_interface.py @@ -0,0 +1,9 @@ +from abc import ABC +from ipaddress import IPv4Network +from typing import Dict + +from pydantic import BaseModel + +from primaite.utils.validators import IPV4Address + + diff --git a/src/primaite/simulator/network/hardware/network_interface/wired/__init__.py b/src/primaite/simulator/network/hardware/network_interface/wired/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/network/hardware/network_interface/wired/router_interface.py b/src/primaite/simulator/network/hardware/network_interface/wired/router_interface.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/network/hardware/network_interface/wireless/__init__.py b/src/primaite/simulator/network/hardware/network_interface/wireless/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py new file mode 100644 index 00000000..f94b7faa --- /dev/null +++ b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py @@ -0,0 +1,84 @@ +from typing import Dict + +from primaite.simulator.network.hardware.base import WirelessNetworkInterface +from primaite.simulator.network.hardware.network_interface.layer_3_interface import Layer3Interface + +from primaite.simulator.network.transmission.data_link_layer import Frame + + +class WirelessAccessPoint(WirelessNetworkInterface, Layer3Interface): + """ + Represents a Wireless Access Point (AP) in a network. + + This class models a Wireless Access Point, a device that allows wireless devices to connect to a wired network + using Wi-Fi or other wireless standards. The Wireless Access Point bridges the wireless and wired segments of + the network, allowing wireless devices to communicate with other devices on the network. + + As an integral component of wireless networking, a Wireless Access Point provides functionalities for network + management, signal broadcasting, security enforcement, and connection handling. It also possesses Layer 3 + capabilities such as IP addressing and subnetting, allowing for network segmentation and routing. + + Inherits from: + - WirelessNetworkInterface: Provides basic properties and methods specific to wireless interfaces. + - Layer3Interface: Provides Layer 3 properties like ip_address and subnet_mask, enabling the device to manage + network traffic and routing. + + This class can be further specialised or extended to support specific features or standards related to wireless + networking, such as different Wi-Fi versions, frequency bands, or advanced security protocols. + """ + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + # Get the state from the WirelessNetworkInterface + state = WirelessNetworkInterface.describe_state(self) + + # Update the state with information from Layer3Interface + state.update(Layer3Interface.describe_state(self)) + + # Update the state with NIC-specific information + state.update( + { + "wake_on_lan": self.wake_on_lan, + } + ) + + return state + + def enable(self): + """Enable the interface.""" + pass + + def disable(self): + """Disable the interface.""" + pass + + def send_frame(self, frame: Frame) -> bool: + """ + Attempts to send a network frame through the interface. + + :param frame: The network frame to be sent. + :return: A boolean indicating whether the frame was successfully sent. + """ + pass + + def receive_frame(self, frame: Frame) -> bool: + """ + Receives a network frame on the interface. + + :param frame: The network frame being received. + :return: A boolean indicating whether the frame was successfully received. + """ + pass + + def __str__(self) -> str: + """ + String representation of the NIC. + + :return: A string combining the port number, MAC address and IP address of the NIC. + """ + return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" \ No newline at end of file diff --git a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py new file mode 100644 index 00000000..12172608 --- /dev/null +++ b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py @@ -0,0 +1,81 @@ +from typing import Dict + +from primaite.simulator.network.hardware.base import WirelessNetworkInterface +from primaite.simulator.network.hardware.network_interface.layer_3_interface import Layer3Interface + +from primaite.simulator.network.transmission.data_link_layer import Frame + + +class WirelessNIC(WirelessNetworkInterface, Layer3Interface): + """ + Represents a Wireless Network Interface Card (Wireless NIC) in a network device. + + This class encapsulates the functionalities and attributes of a wireless NIC, combining the characteristics of a + wireless network interface with Layer 3 features. It is capable of connecting to wireless networks, managing + wireless-specific properties such as signal strength and security protocols, and also handling IP-related + functionalities like IP addressing and subnetting. + + Inherits from: + - WirelessNetworkInterface: Provides basic properties and methods specific to wireless interfaces. + - Layer3Interface: Provides Layer 3 properties like ip_address and subnet_mask, enabling the device to participate + in IP-based networking. + + This class can be extended to include more advanced features or to tailor its behavior for specific types of + wireless networks or protocols. + """ + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + # Get the state from the WirelessNetworkInterface + state = WirelessNetworkInterface.describe_state(self) + + # Update the state with information from Layer3Interface + state.update(Layer3Interface.describe_state(self)) + + # Update the state with NIC-specific information + state.update( + { + "wake_on_lan": self.wake_on_lan, + } + ) + + return state + + def enable(self): + """Enable the interface.""" + pass + + def disable(self): + """Disable the interface.""" + pass + + def send_frame(self, frame: Frame) -> bool: + """ + Attempts to send a network frame through the interface. + + :param frame: The network frame to be sent. + :return: A boolean indicating whether the frame was successfully sent. + """ + pass + + def receive_frame(self, frame: Frame) -> bool: + """ + Receives a network frame on the interface. + + :param frame: The network frame being received. + :return: A boolean indicating whether the frame was successfully received. + """ + pass + + def __str__(self) -> str: + """ + String representation of the NIC. + + :return: A string combining the port number, MAC address and IP address of the NIC. + """ + return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" \ No newline at end of file diff --git a/src/primaite/simulator/network/hardware/nodes/host.py b/src/primaite/simulator/network/hardware/nodes/host.py deleted file mode 100644 index b0486538..00000000 --- a/src/primaite/simulator/network/hardware/nodes/host.py +++ /dev/null @@ -1,63 +0,0 @@ -from primaite.simulator.network.hardware.base import NIC, Node -from primaite.simulator.system.applications.web_browser import WebBrowser -from primaite.simulator.system.services.arp.host_arp import HostARP -from primaite.simulator.system.services.dns.dns_client import DNSClient -from primaite.simulator.system.services.ftp.ftp_client import FTPClient -from primaite.simulator.system.services.icmp.icmp import ICMP -from primaite.simulator.system.services.ntp.ntp_client import NTPClient - - -class Host(Node): - """ - A basic Host class. - - Example: - >>> pc_a = Host( - hostname="pc_a", - ip_address="192.168.1.10", - subnet_mask="255.255.255.0", - default_gateway="192.168.1.1" - ) - >>> pc_a.power_on() - - Instances of computer come 'pre-packaged' with the following: - - * Core Functionality: - * Packet Capture - * Sys Log - * Services: - * ARP Service - * ICMP Service - * DNS Client - * FTP Client - * NTP Client - * Applications: - * Web Browser - """ - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.connect_nic(NIC(ip_address=kwargs["ip_address"], subnet_mask=kwargs["subnet_mask"])) - self._install_system_software() - - def _install_system_software(self): - """Install System Software - software that is usually provided with the OS.""" - # ARP Service - self.software_manager.install(HostARP) - - # ICMP Service - self.software_manager.install(ICMP) - - # DNS Client - self.software_manager.install(DNSClient) - - # FTP Client - self.software_manager.install(FTPClient) - - # NTP Client - self.software_manager.install(NTPClient) - - # Web Browser - self.software_manager.install(WebBrowser) - - super()._install_system_software() diff --git a/src/primaite/simulator/network/hardware/nodes/host/__init__.py b/src/primaite/simulator/network/hardware/nodes/host/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/network/hardware/nodes/computer.py b/src/primaite/simulator/network/hardware/nodes/host/computer.py similarity index 61% rename from src/primaite/simulator/network/hardware/nodes/computer.py rename to src/primaite/simulator/network/hardware/nodes/host/computer.py index 61d3e3ff..dc75df69 100644 --- a/src/primaite/simulator/network/hardware/nodes/computer.py +++ b/src/primaite/simulator/network/hardware/nodes/host/computer.py @@ -1,11 +1,7 @@ -from primaite.simulator.network.hardware.base import NIC, Node -from primaite.simulator.network.hardware.nodes.host import Host -from primaite.simulator.system.applications.web_browser import WebBrowser -from primaite.simulator.system.services.dns.dns_client import DNSClient -from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.network.hardware.nodes.host.host_node import HostNode -class Computer(Host): +class Computer(HostNode): """ A basic Computer class. diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py new file mode 100644 index 00000000..eefee304 --- /dev/null +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -0,0 +1,354 @@ +from __future__ import annotations + +from typing import Dict +from typing import Optional + +from primaite import getLogger +from primaite.simulator.network.hardware.base import IPWiredNetworkInterface +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.transmission.data_link_layer import Frame +from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.core.packet_capture import PacketCapture +from primaite.simulator.system.services.arp.arp import ARP, ARPPacket +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.icmp.icmp import ICMP +from primaite.simulator.system.services.ntp.ntp_client import NTPClient +from primaite.utils.validators import IPV4Address + +_LOGGER = getLogger(__name__) + + +# Lives here due to pydantic circular dependency issue :( +class HostARP(ARP): + """ + The Host ARP Service. + + Extends the ARP service with functionalities specific to a host within the network. It provides mechanisms to + resolve and cache MAC addresses and NICs for given IP addresses, focusing on the host's perspective, including + handling the default gateway. + """ + + def get_default_gateway_mac_address(self) -> Optional[str]: + """ + Retrieves the MAC address of the default gateway from the ARP cache. + + :return: The MAC address of the default gateway if it exists in the ARP cache, otherwise None. + """ + if self.software_manager.node.default_gateway: + return self.get_arp_cache_mac_address(self.software_manager.node.default_gateway) + + def get_default_gateway_network_interface(self) -> Optional[NIC]: + """ + Retrieves the NIC associated with the default gateway from the ARP cache. + + :return: The NIC associated with the default gateway if it exists in the ARP cache, otherwise None. + """ + if self.software_manager.node.default_gateway: + return self.get_arp_cache_network_interface(self.software_manager.node.default_gateway) + + def _get_arp_cache_mac_address( + self, ip_address: IPV4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False + ) -> Optional[str]: + """ + Internal method to retrieve the MAC address associated with an IP address from the ARP cache. + + :param ip_address: The IP address whose MAC address is to be retrieved. + :param is_reattempt: Indicates if this call is a reattempt after a failed initial attempt. + :param is_default_gateway_attempt: Indicates if this call is an attempt to get the default gateway's MAC address. + :return: The MAC address associated with the IP address if found, otherwise None. + """ + arp_entry = self.arp.get(ip_address) + + if arp_entry: + return arp_entry.mac_address + else: + if not is_reattempt: + self.send_arp_request(ip_address) + return self._get_arp_cache_mac_address( + ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt + ) + else: + if self.software_manager.node.default_gateway: + if not is_default_gateway_attempt: + self.send_arp_request(self.software_manager.node.default_gateway) + return self._get_arp_cache_mac_address( + ip_address=self.software_manager.node.default_gateway, is_reattempt=True, + is_default_gateway_attempt=True + ) + return None + + def get_arp_cache_mac_address(self, ip_address: IPV4Address) -> Optional[str]: + """ + Retrieves the MAC address associated with an IP address from the ARP cache. + + :param ip_address: The IP address whose MAC address is to be retrieved. + :return: The MAC address associated with the IP address if found, otherwise None. + """ + return self._get_arp_cache_mac_address(ip_address) + + def _get_arp_cache_network_interface( + self, ip_address: IPV4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False + ) -> Optional[NIC]: + """ + Internal method to retrieve the NIC associated with an IP address from the ARP cache. + + :param ip_address: The IP address whose NIC is to be retrieved. + :param is_reattempt: Indicates if this call is a reattempt after a failed initial attempt. + :param is_default_gateway_attempt: Indicates if this call is an attempt to get the NIC of the default gateway. + :return: The NIC associated with the IP address if found, otherwise None. + """ + arp_entry = self.arp.get(ip_address) + + if arp_entry: + return self.software_manager.node.network_interfaces[arp_entry.network_interface_uuid] + else: + if not is_reattempt: + self.send_arp_request(ip_address) + return self._get_arp_cache_network_interface( + ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt + ) + else: + if self.software_manager.node.default_gateway: + if not is_default_gateway_attempt: + self.send_arp_request(self.software_manager.node.default_gateway) + return self._get_arp_cache_network_interface( + ip_address=self.software_manager.node.default_gateway, is_reattempt=True, + is_default_gateway_attempt=True + ) + return None + + def get_arp_cache_network_interface(self, ip_address: IPV4Address) -> Optional[NIC]: + """ + Retrieves the NIC associated with an IP address from the ARP cache. + + :param ip_address: The IP address whose NIC is to be retrieved. + :return: The NIC associated with the IP address if found, otherwise None. + """ + return self._get_arp_cache_network_interface(ip_address) + + def _process_arp_request(self, arp_packet: ARPPacket, from_network_interface: NIC): + """ + Processes an ARP request. + + Adds a new entry to the ARP cache if the target IP address matches the NIC's IP address and sends an ARP + reply back. + + :param arp_packet: The ARP packet containing the request. + :param from_network_interface: The NIC that received the ARP request. + """ + super()._process_arp_request(arp_packet, from_network_interface) + # Unmatched ARP Request + if arp_packet.target_ip_address != from_network_interface.ip_address: + self.sys_log.info( + f"Ignoring ARP request for {arp_packet.target_ip_address}. Current IP address is {from_network_interface.ip_address}" + ) + return + + # Matched ARP request + self.add_arp_cache_entry( + ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, + network_interface=from_network_interface + ) + arp_packet = arp_packet.generate_reply(from_network_interface.mac_address) + self.send_arp_reply(arp_packet) + + +class NIC(IPWiredNetworkInterface): + """ + Represents a Network Interface Card (NIC) in a Host Node. + + A NIC is a hardware component that provides a computer or other network device with the ability to connect to a + network. It operates at both Layer 2 (Data Link Layer) and Layer 3 (Network Layer) of the OSI model, meaning it + can interpret both MAC addresses and IP addresses. This class combines the functionalities of + WiredNetworkInterface and Layer3Interface, allowing the NIC to manage physical connections and network layer + addressing. + + Inherits from: + - WiredNetworkInterface: Provides properties and methods specific to wired connections, including methods to connect + and disconnect from network links and to manage the enabled/disabled state of the interface. + - Layer3Interface: Provides properties for Layer 3 network configuration, such as IP address and subnet mask. + """ + wake_on_lan: bool = False + "Indicates if the NIC supports Wake-on-LAN functionality." + + def __init__(self, **kwargs): + + super().__init__(**kwargs) + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + # Get the state from the IPWiredNetworkInterface + state = super().describe_state() + + # Update the state with NIC-specific information + state.update( + { + "wake_on_lan": self.wake_on_lan, + } + ) + + return state + + def set_original_state(self): + """Sets the original state.""" + vals_to_include = {"ip_address", "subnet_mask", "mac_address", "speed", "mtu", "wake_on_lan", "enabled"} + self._original_state = self.model_dump(include=vals_to_include) + + def receive_frame(self, frame: Frame) -> bool: + """ + Attempt to receive and process a network frame from the connected Link. + + This method processes a frame if the NIC is enabled. It checks the frame's destination and TTL, captures the + frame using PCAP, and forwards it to the connected Node if valid. Returns True if the frame is processed, + False otherwise (e.g., if the NIC is disabled, or TTL expired). + + :param frame: The network frame being received. + :return: True if the frame is processed and passed to the node, False otherwise. + """ + if self.enabled: + frame.decrement_ttl() + if frame.ip and frame.ip.ttl < 1: + self._connected_node.sys_log.info(f"Frame discarded at {self} as TTL limit reached") + return False + frame.set_received_timestamp() + self.pcap.capture_inbound(frame) + # If this destination or is broadcast + accept_frame = False + + # Check if it's a broadcast: + if frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": + if frame.ip.dst_ip_address in {self.ip_address, self.ip_network.broadcast_address}: + accept_frame = True + else: + if frame.ethernet.dst_mac_addr == self.mac_address: + accept_frame = True + + if accept_frame: + self._connected_node.receive_frame(frame=frame, from_network_interface=self) + return True + return False + + def __str__(self) -> str: + """ + String representation of the NIC. + + :return: A string combining the port number, MAC address and IP address of the NIC. + """ + return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" + + +class HostNode(Node): + """ + Represents a host node in the network. + + Extends the basic functionality of a Node with host-specific services and applications. A host node typically + represents an end-user device in the network, such as a Computer or a Server, and is capable of initiating and + responding to network communications. + + Example: + >>> pc_a = HostNode( + hostname="pc_a", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1" + ) + >>> pc_a.power_on() + + The host comes pre-installed with core functionalities and a suite of services and applications, making it ready + for various network operations and tasks. These include: + + Core Functionality: + ------------------- + + * Packet Capture: Monitors and logs network traffic. + * Sys Log: Logs system events and errors. + + Services: + --------- + + * ARP (Address Resolution Protocol) Service: Resolves IP addresses to MAC addresses. + * ICMP (Internet Control Message Protocol) Service: Handles ICMP operations, such as ping requests. + * DNS (Domain Name System) Client: Resolves domain names to IP addresses. + * FTP (File Transfer Protocol) Client: Enables file transfers between the host and FTP servers. + * NTP (Network Time Protocol) Client: Synchronizes the system clock with NTP servers. + + Applications: + ------------ + + * Web Browser: Provides web browsing capabilities. + """ + network_interfaces: Dict[str, NIC] = {} + "The Network Interfaces on the node." + network_interface: Dict[int, NIC] = {} + "The NICs on the node by port id." + + def __init__(self, ip_address: IPV4Address, subnet_mask: IPV4Address, **kwargs): + super().__init__(**kwargs) + self.connect_nic(NIC(ip_address=ip_address, subnet_mask=subnet_mask)) + + def _install_system_software(self): + """Install System Software - software that is usually provided with the OS.""" + # ARP Service + self.software_manager.install(HostARP) + + # ICMP Service + self.software_manager.install(ICMP) + + # DNS Client + self.software_manager.install(DNSClient) + + # FTP Client + self.software_manager.install(FTPClient) + + # NTP Client + self.software_manager.install(NTPClient) + + # Web Browser + self.software_manager.install(WebBrowser) + + super()._install_system_software() + + def default_gateway_hello(self): + if self.operating_state == NodeOperatingState.ON and self.default_gateway: + self.software_manager.arp.get_default_gateway_mac_address() + + def receive_frame(self, frame: Frame, from_network_interface: NIC): + """ + Receive a Frame from the connected NIC and process it. + + Depending on the protocol, the frame is passed to the appropriate handler such as ARP or ICMP, or up to the + SessionManager if no code manager exists. + + :param frame: The Frame being received. + :param from_network_interface: The NIC that received the frame. + """ + super().receive_frame(frame, from_network_interface) + + # Check if the destination port is open on the Node + dst_port = None + if frame.tcp: + dst_port = frame.tcp.dst_port + elif frame.udp: + dst_port = frame.udp.dst_port + + accept_frame = False + if frame.icmp or dst_port in self.software_manager.get_open_ports(): + # accept the frame as the port is open or if it's an ICMP frame + accept_frame = True + + # TODO: add internal node firewall check here? + + if accept_frame: + self.session_manager.receive_frame(frame, from_network_interface) + else: + # denied as port closed + self.sys_log.info(f"Ignoring frame for port {frame.tcp.dst_port.value} from {frame.ip.src_ip_address}") + # TODO: do we need to do anything more here? + pass diff --git a/src/primaite/simulator/network/hardware/nodes/server.py b/src/primaite/simulator/network/hardware/nodes/host/server.py similarity index 85% rename from src/primaite/simulator/network/hardware/nodes/server.py rename to src/primaite/simulator/network/hardware/nodes/host/server.py index 0a2c361f..148a277f 100644 --- a/src/primaite/simulator/network/hardware/nodes/server.py +++ b/src/primaite/simulator/network/hardware/nodes/host/server.py @@ -1,7 +1,7 @@ -from primaite.simulator.network.hardware.nodes.host import Host +from primaite.simulator.network.hardware.nodes.host.host_node import HostNode -class Server(Host): +class Server(HostNode): """ A basic Server class. @@ -28,4 +28,4 @@ class Server(Host): * Applications: * Web Browser """ - pass + diff --git a/src/primaite/simulator/network/hardware/nodes/network/__init__.py b/src/primaite/simulator/network/hardware/nodes/network/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/simulator/network/hardware/nodes/network/network_node.py b/src/primaite/simulator/network/hardware/nodes/network/network_node.py new file mode 100644 index 00000000..c7a2060b --- /dev/null +++ b/src/primaite/simulator/network/hardware/nodes/network/network_node.py @@ -0,0 +1,9 @@ +from primaite.simulator.network.hardware.base import Node, NetworkInterface +from primaite.simulator.network.transmission.data_link_layer import Frame + + +class NetworkNode(Node): + """""" + + def receive_frame(self, frame: Frame, from_network_interface: NetworkInterface): + pass diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py similarity index 69% rename from src/primaite/simulator/network/hardware/nodes/router.py rename to src/primaite/simulator/network/hardware/nodes/network/router.py index 69717ae6..06464fd9 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1,19 +1,23 @@ from __future__ import annotations -import secrets from enum import Enum from ipaddress import IPv4Address, IPv4Network -from typing import Dict, List, Optional, Tuple, Union +from typing import Dict, Any +from typing import List, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable from primaite.simulator.core import RequestManager, RequestType, SimComponent -from primaite.simulator.network.hardware.base import NIC, Node +from primaite.simulator.network.hardware.base import IPWiredNetworkInterface from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame -from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader +from primaite.simulator.network.hardware.nodes.network.network_node import NetworkNode +from primaite.simulator.network.protocols.arp import ARPPacket +from primaite.simulator.network.transmission.data_link_layer import Frame +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.system.services.arp.arp import ARP +from primaite.simulator.system.services.icmp.icmp import ICMP class ACLAction(Enum): @@ -197,14 +201,14 @@ class AccessControlList(SimComponent): return self._acl def add_rule( - self, - action: ACLAction, - protocol: Optional[IPProtocol] = None, - src_ip_address: Optional[Union[str, IPv4Address]] = None, - src_port: Optional[Port] = None, - dst_ip_address: Optional[Union[str, IPv4Address]] = None, - dst_port: Optional[Port] = None, - position: int = 0, + self, + action: ACLAction, + protocol: Optional[IPProtocol] = None, + src_ip_address: Optional[Union[str, IPv4Address]] = None, + src_port: Optional[Port] = None, + dst_ip_address: Optional[Union[str, IPv4Address]] = None, + dst_port: Optional[Port] = None, + position: int = 0, ) -> None: """ Add a new ACL rule. @@ -251,12 +255,12 @@ class AccessControlList(SimComponent): raise ValueError(f"Cannot remove ACL rule, position {position} is out of bounds.") def is_permitted( - self, - protocol: IPProtocol, - src_ip_address: Union[str, IPv4Address], - src_port: Optional[Port], - dst_ip_address: Union[str, IPv4Address], - dst_port: Optional[Port], + self, + protocol: IPProtocol, + src_ip_address: Union[str, IPv4Address], + src_port: Optional[Port], + dst_ip_address: Union[str, IPv4Address], + dst_port: Optional[Port], ) -> Tuple[bool, Optional[Union[str, ACLRule]]]: """ Check if a packet with the given properties is permitted through the ACL. @@ -278,23 +282,23 @@ class AccessControlList(SimComponent): continue if ( - (rule.src_ip_address == src_ip_address or rule.src_ip_address is None) - and (rule.dst_ip_address == dst_ip_address or rule.dst_ip_address is None) - and (rule.protocol == protocol or rule.protocol is None) - and (rule.src_port == src_port or rule.src_port is None) - and (rule.dst_port == dst_port or rule.dst_port is None) + (rule.src_ip_address == src_ip_address or rule.src_ip_address is None) + and (rule.dst_ip_address == dst_ip_address or rule.dst_ip_address is None) + and (rule.protocol == protocol or rule.protocol is None) + and (rule.src_port == src_port or rule.src_port is None) + and (rule.dst_port == dst_port or rule.dst_port is None) ): return rule.action == ACLAction.PERMIT, rule return self.implicit_action == ACLAction.PERMIT, f"Implicit {self.implicit_action.name}" def get_relevant_rules( - self, - protocol: IPProtocol, - src_ip_address: Union[str, IPv4Address], - src_port: Port, - dst_ip_address: Union[str, IPv4Address], - dst_port: Port, + self, + protocol: IPProtocol, + src_ip_address: Union[str, IPv4Address], + src_port: Port, + dst_ip_address: Union[str, IPv4Address], + dst_port: Port, ) -> List[ACLRule]: """ Get the list of relevant rules for a packet with given properties. @@ -316,11 +320,11 @@ class AccessControlList(SimComponent): continue if ( - (rule.src_ip_address == src_ip_address or rule.src_ip_address is None) - or (rule.dst_ip_address == dst_ip_address or rule.dst_ip_address is None) - or (rule.protocol == protocol or rule.protocol is None) - or (rule.src_port == src_port or rule.src_port is None) - or (rule.dst_port == dst_port or rule.dst_port is None) + (rule.src_ip_address == src_ip_address or rule.src_ip_address is None) + or (rule.dst_ip_address == dst_ip_address or rule.dst_ip_address is None) + or (rule.protocol == protocol or rule.protocol is None) + or (rule.src_port == src_port or rule.src_port is None) + or (rule.dst_port == dst_port or rule.dst_port is None) ): relevant_rules.append(rule) @@ -437,11 +441,11 @@ class RouteTable(SimComponent): pass def add_route( - self, - address: Union[IPv4Address, str], - subnet_mask: Union[IPv4Address, str], - next_hop_ip_address: Union[IPv4Address, str], - metric: float = 0.0, + self, + address: Union[IPv4Address, str], + subnet_mask: Union[IPv4Address, str], + next_hop_ip_address: Union[IPv4Address, str], + metric: float = 0.0, ): """ Add a route to the routing table. @@ -528,7 +532,79 @@ class RouteTable(SimComponent): table.add_row([index, f"{route.address}/{network.prefixlen}", route.next_hop_ip_address, route.metric]) print(table) -class RouterNIC(NIC): + +class RouterARP(ARP): + """ + Inherits from ARPCache and adds router-specific ARP packet processing. + + :ivar SysLog sys_log: A system log for logging messages. + :ivar Router router: The router to which this ARP cache belongs. + """ + router: Optional[Router] = None + + def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: + arp_entry = self.arp.get(ip_address) + + if arp_entry: + return arp_entry.mac_address + return None + + def get_arp_cache_network_interface(self, ip_address: IPv4Address) -> Optional[RouterInterface]: + + arp_entry = self.arp.get(ip_address) + if arp_entry: + return self.software_manager.node.network_interfaces[arp_entry.network_interface_uuid] + for network_interface in self.router.network_interfaces.values(): + if ip_address in network_interface.ip_network: + return network_interface + return None + + def _process_arp_request(self, arp_packet: ARPPacket, from_network_interface: RouterInterface): + super()._process_arp_request(arp_packet, from_network_interface) + + # If the target IP matches one of the router's NICs + for network_interface in self.router.network_interfaces.values(): + if network_interface.enabled and network_interface.ip_address == arp_packet.target_ip_address: + arp_reply = arp_packet.generate_reply(from_network_interface.mac_address) + self.send_arp_reply(arp_reply) + return + + def _process_arp_reply(self, arp_packet: ARPPacket, from_network_interface: RouterInterface): + if arp_packet.target_ip_address == from_network_interface.ip_address: + super()._process_arp_reply(arp_packet, from_network_interface) + + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Processes received data, handling ARP packets. + + :param payload: The payload received. + :param session_id: The session ID associated with the received data. + :param kwargs: Additional keyword arguments. + :return: True if the payload was processed successfully, otherwise False. + """ + if not super().receive(payload, session_id, **kwargs): + return False + + arp_packet: ARPPacket = payload + from_network_interface: RouterInterface = kwargs["from_network_interface"] + + for network_interface in self.router.network_interfaces.values(): + # ARP frame is for this Router + if network_interface.ip_address == arp_packet.target_ip_address: + if payload.request: + self._process_arp_request(arp_packet=arp_packet, from_network_interface=from_network_interface) + else: + self._process_arp_reply(arp_packet=arp_packet, from_network_interface=from_network_interface) + return True + + # ARP frame is not for this router, pass back down to Router to continue routing + frame: Frame = kwargs["frame"] + self.router.process_frame(frame=frame, from_network_interface=from_network_interface) + + return True + + +class RouterNIC(IPWiredNetworkInterface): """ A Router-specific Network Interface Card (NIC) that extends the standard NIC functionality. @@ -561,7 +637,7 @@ class RouterNIC(NIC): self.pcap.capture_inbound(frame) # If this destination or is broadcast if frame.ethernet.dst_mac_addr == self.mac_address or frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": - self._connected_node.receive_frame(frame=frame, from_nic=self) + self._connected_node.receive_frame(frame=frame, from_network_interface=self) return True return False @@ -569,21 +645,63 @@ class RouterNIC(NIC): return f"{self.mac_address}/{self.ip_address}" -class Router(Node): +class RouterInterface(IPWiredNetworkInterface): + """ + Represents a Router Interface. + + Router interfaces are used to connect routers to networks. They can route packets across different networks, + hence have IP addressing information. + + Inherits from: + - WiredNetworkInterface: Provides properties and methods specific to wired connections. + - Layer3Interface: Provides Layer 3 properties like ip_address and subnet_mask. + """ + + def receive_frame(self, frame: Frame) -> bool: + """ + Receives a network frame on the interface. + + :param frame: The network frame being received. + :return: A boolean indicating whether the frame was successfully received. + """ + if self.enabled: + frame.decrement_ttl() + if frame.ip and frame.ip.ttl < 1: + self._connected_node.sys_log.info("Frame discarded as TTL limit reached") + return False + frame.set_received_timestamp() + self.pcap.capture_inbound(frame) + # If this destination or is broadcast + if frame.ethernet.dst_mac_addr == self.mac_address or frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": + self._connected_node.receive_frame(frame=frame, from_network_interface=self) + return True + return False + + def __str__(self) -> str: + """ + String representation of the NIC. + + :return: A string combining the port number, MAC address and IP address of the NIC. + """ + return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" + + +class Router(NetworkNode): """ A class to represent a network router node. :ivar str hostname: The name of the router node. :ivar int num_ports: The number of ports in the router. - :ivar dict kwargs: Optional keyword arguments for SysLog, ACL, RouteTable, RouterARPCache, RouterICMP. + :ivar dict kwargs: Optional keyword arguments for SysLog, ACL, RouteTable, RouterARP, RouterICMP. """ num_ports: int - ethernet_ports: Dict[int, RouterNIC] = {} + network_interfaces: Dict[str, RouterInterface] = {} + "The Router Interfaces on the node." + network_interface: Dict[int, RouterInterface] = {} + "The Router Interfaceson the node by port id." acl: AccessControlList route_table: RouteTable - # arp: RouterARPCache - # icmp: RouterICMP def __init__(self, hostname: str, num_ports: int = 5, **kwargs): if not kwargs.get("sys_log"): @@ -592,23 +710,28 @@ class Router(Node): kwargs["acl"] = AccessControlList(sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY) if not kwargs.get("route_table"): kwargs["route_table"] = RouteTable(sys_log=kwargs["sys_log"]) - # if not kwargs.get("arp"): - # kwargs["arp"] = RouterARPCache(sys_log=kwargs.get("sys_log"), router=self) - # if not kwargs.get("icmp"): - # kwargs["icmp"] = RouterICMP(sys_log=kwargs.get("sys_log"), arp_cache=kwargs.get("arp"), router=self) super().__init__(hostname=hostname, num_ports=num_ports, **kwargs) - # TODO: Install RouterICMP - # TODO: Install RouterARP for i in range(1, self.num_ports + 1): - nic = RouterNIC(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") - self.connect_nic(nic) - self.ethernet_ports[i] = nic + network_interface = RouterInterface(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") + self.connect_nic(network_interface) + self.network_interface[i] = network_interface - self.arp.nics = self.nics - self.icmp.arp = self.arp + self._set_default_acl() self.set_original_state() + + def _install_system_software(self): + """Install System Software - software that is usually provided with the OS.""" + self.software_manager.install(ICMP) + self.software_manager.install(RouterARP) + arp: RouterARP = self.software_manager.arp # noqa + arp.router = self + + def _set_default_acl(self): + self.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) + self.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + def set_original_state(self): """Sets the original state.""" self.acl.set_original_state() @@ -619,11 +742,11 @@ class Router(Node): def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - self.arp.clear() + self.software_manager.arp.clear() self.acl.reset_component_for_episode(episode) self.route_table.reset_component_for_episode(episode) - for i, nic in self.ethernet_ports.items(): - nic.reset_component_for_episode(episode) + for i, network_interface in self.network_interface.items(): + network_interface.reset_component_for_episode(episode) self.enable_port(i) super().reset_component_for_episode(episode) @@ -633,15 +756,15 @@ class Router(Node): rm.add_request("acl", RequestType(func=self.acl._request_manager)) return rm - def _get_port_of_nic(self, target_nic: NIC) -> Optional[int]: + def _get_port_of_nic(self, target_nic: RouterInterface) -> Optional[int]: """ Retrieve the port number for a given NIC. :param target_nic: Target network interface. :return: The port number if NIC is found, otherwise None. """ - for port, nic in self.ethernet_ports.items(): - if nic == target_nic: + for port, network_interface in self.network_interface.items(): + if network_interface == target_nic: return port def describe_state(self) -> Dict: @@ -655,83 +778,98 @@ class Router(Node): state["acl"] = self.acl.describe_state() return state - def process_frame(self, frame: Frame, from_nic: NIC, re_attempt: bool = False) -> None: + def process_frame(self, frame: Frame, from_network_interface: RouterInterface) -> None: """ Process a Frame. :param frame: The frame to be routed. - :param from_nic: The source network interface. - :param re_attempt: Flag to indicate if the routing is a reattempt. + :param from_network_interface: The source network interface. """ - # Check if src ip is on network of one of the NICs - nic = self.arp.get_arp_cache_nic(frame.ip.dst_ip_address) - target_mac = self.arp.get_arp_cache_mac_address(frame.ip.dst_ip_address) + # check if frame is addressed to this Router but has failed to be received by a service of application at the + # receive_frame stage + if frame.ip: + for network_interface in self.network_interfaces.values(): + if network_interface.ip_address == frame.ip.dst_ip_address: + self.sys_log.info(f"Dropping frame destined for this router on an port that isn't open.") + return - if re_attempt and not nic: + network_interface: RouterInterface = self.software_manager.arp.get_arp_cache_network_interface( + frame.ip.dst_ip_address + ) + target_mac = self.software_manager.arp.get_arp_cache_mac_address(frame.ip.dst_ip_address) + self.software_manager.arp.show() + + if not network_interface: self.sys_log.info(f"Destination {frame.ip.dst_ip_address} is unreachable") + # TODO: Send something back to src, is it some sort of ICMP? return - if not nic: - self.arp.send_arp_request( - frame.ip.dst_ip_address, ignore_networks=[frame.ip.src_ip_address, from_nic.ip_address] - ) - return self.process_frame(frame=frame, from_nic=from_nic, re_attempt=True) - - if not nic.enabled: - self.sys_log.info(f"Frame dropped as NIC {nic} is not enabled") + if not network_interface.enabled: + self.sys_log.info(f"Frame dropped as NIC {network_interface} is not enabled") + # TODO: Send something back to src, is it some sort of ICMP? return - if frame.ip.dst_ip_address in nic.ip_network: - from_port = self._get_port_of_nic(from_nic) - to_port = self._get_port_of_nic(nic) + if frame.ip.dst_ip_address in network_interface.ip_network: + from_port = self._get_port_of_nic(from_network_interface) + to_port = self._get_port_of_nic(network_interface) self.sys_log.info(f"Forwarding frame to internally from port {from_port} to port {to_port}") frame.decrement_ttl() if frame.ip and frame.ip.ttl < 1: self.sys_log.info("Frame discarded as TTL limit reached") + # TODO: Send something back to src, is it some sort of ICMP? return - frame.ethernet.src_mac_addr = nic.mac_address + frame.ethernet.src_mac_addr = network_interface.mac_address frame.ethernet.dst_mac_addr = target_mac - nic.send_frame(frame) + network_interface.send_frame(frame) return else: - self._route_frame(frame, from_nic) + self.route_frame(frame, from_network_interface) - def _route_frame(self, frame: Frame, from_nic: NIC, re_attempt: bool = False) -> None: + def route_frame(self, frame: Frame, from_network_interface: RouterInterface) -> None: route = self.route_table.find_best_route(frame.ip.dst_ip_address) if route: - nic = self.arp.get_arp_cache_nic(route.next_hop_ip_address) - target_mac = self.arp.get_arp_cache_mac_address(route.next_hop_ip_address) - if re_attempt and not nic: + network_interface = self.software_managerarp.get_arp_cache_network_interface(route.next_hop_ip_address) + target_mac = self.software_manager.arp.get_arp_cache_mac_address(route.next_hop_ip_address) + if not network_interface: self.sys_log.info(f"Destination {frame.ip.dst_ip_address} is unreachable") + # TODO: Send something back to src, is it some sort of ICMP? return - if not nic: - self.arp.send_arp_request(frame.ip.dst_ip_address, ignore_networks=[frame.ip.src_ip_address]) - return self.process_frame(frame=frame, from_nic=from_nic, re_attempt=True) - - if not nic.enabled: - self.sys_log.info(f"Frame dropped as NIC {nic} is not enabled") + if not network_interface.enabled: + self.sys_log.info(f"Frame dropped as NIC {network_interface} is not enabled") + # TODO: Send something back to src, is it some sort of ICMP? return - from_port = self._get_port_of_nic(from_nic) - to_port = self._get_port_of_nic(nic) + from_port = self._get_port_of_nic(from_network_interface) + to_port = self._get_port_of_nic(network_interface) self.sys_log.info(f"Routing frame to internally from port {from_port} to port {to_port}") frame.decrement_ttl() if frame.ip and frame.ip.ttl < 1: self.sys_log.info("Frame discarded as TTL limit reached") + # TODO: Send something back to src, is it some sort of ICMP? return - frame.ethernet.src_mac_addr = nic.mac_address + frame.ethernet.src_mac_addr = network_interface.mac_address frame.ethernet.dst_mac_addr = target_mac - nic.send_frame(frame) + network_interface.send_frame(frame) - def receive_frame(self, frame: Frame, from_nic: NIC): + def receive_frame(self, frame: Frame, from_network_interface: RouterInterface): """ - Receive a frame from a NIC and processes it based on its protocol. + Receive a frame from a RouterInterface and processes it based on its protocol. :param frame: The incoming frame. - :param from_nic: The network interface where the frame is coming from. + :param from_network_interface: The network interface where the frame is coming from. """ - process_frame = False + + if self.operating_state != NodeOperatingState.ON: + return + + if frame.ip and self.software_manager.arp: + self.software_manager.arp.add_arp_cache_entry( + ip_address=frame.ip.src_ip_address, + mac_address=frame.ethernet.src_mac_addr, + network_interface=from_network_interface + ) + protocol = frame.ip.protocol src_ip_address = frame.ip.src_ip_address dst_ip_address = frame.ip.dst_ip_address @@ -754,21 +892,32 @@ class Router(Node): ) if not permitted: - at_port = self._get_port_of_nic(from_nic) + at_port = self._get_port_of_nic(from_network_interface) self.sys_log.info(f"Frame blocked at port {at_port} by rule {rule}") return - self.arp.add_arp_cache_entry(src_ip_address, frame.ethernet.src_mac_addr, from_nic) - if frame.ip.protocol == IPProtocol.ICMP: - self.icmp.process_icmp(frame=frame, from_nic=from_nic) + + self.software_manager.arp.add_arp_cache_entry( + ip_address=src_ip_address, mac_address=frame.ethernet.src_mac_addr, + network_interface=from_network_interface + ) + + # Check if the destination port is open on the Node + dst_port = None + if frame.tcp: + dst_port = frame.tcp.dst_port + elif frame.udp: + dst_port = frame.udp.dst_port + + send_to_session_manager = False + if ((frame.icmp and dst_ip_address == from_network_interface.ip_address) + or (dst_port in self.software_manager.get_open_ports())): + send_to_session_manager = True + + if send_to_session_manager: + # Port is open on this Router so pass Frame up to session manager first + self.session_manager.receive_frame(frame, from_network_interface) else: - if src_port == Port.ARP: - self.arp.process_arp_packet(from_nic=from_nic, frame=frame, route_table=self.route_table) - return - else: - # All other traffic - process_frame = True - if process_frame: - self.process_frame(frame, from_nic) + self.process_frame(frame, from_network_interface) def configure_port(self, port: int, ip_address: Union[IPv4Address, str], subnet_mask: Union[IPv4Address, str]): """ @@ -782,10 +931,12 @@ class Router(Node): ip_address = IPv4Address(ip_address) if not isinstance(subnet_mask, IPv4Address): subnet_mask = IPv4Address(subnet_mask) - nic = self.ethernet_ports[port] - nic.ip_address = ip_address - nic.subnet_mask = subnet_mask - self.sys_log.info(f"Configured port {port} with ip_address={ip_address}/{nic.ip_network.prefixlen}") + network_interface = self.network_interface[port] + network_interface.ip_address = ip_address + network_interface.subnet_mask = subnet_mask + self.sys_log.info( + f"Configured Network Interface {network_interface}" + ) self.set_original_state() def enable_port(self, port: int): @@ -794,9 +945,9 @@ class Router(Node): :param port: The port to enable. """ - nic = self.ethernet_ports.get(port) - if nic: - nic.enable() + network_interface = self.network_interface.get(port) + if network_interface: + network_interface.enable() def disable_port(self, port: int): """ @@ -804,9 +955,9 @@ class Router(Node): :param port: The port to disable. """ - nic = self.ethernet_ports.get(port) - if nic: - nic.disable() + network_interface = self.network_interface.get(port) + if network_interface: + network_interface.disable() def show(self, markdown: bool = False): """ @@ -820,14 +971,14 @@ class Router(Node): table.set_style(MARKDOWN) table.align = "l" table.title = f"{self.hostname} Ethernet Interfaces" - for port, nic in self.ethernet_ports.items(): + for port, network_interface in self.network_interface.items(): table.add_row( [ port, - nic.mac_address, - f"{nic.ip_address}/{nic.ip_network.prefixlen}", - nic.speed, - "Enabled" if nic.enabled else "Disabled", + network_interface.mac_address, + f"{network_interface.ip_address}/{network_interface.ip_network.prefixlen}", + network_interface.speed, + "Enabled" if network_interface.enabled else "Disabled", ] ) print(table) diff --git a/src/primaite/simulator/network/hardware/nodes/switch.py b/src/primaite/simulator/network/hardware/nodes/network/switch.py similarity index 56% rename from src/primaite/simulator/network/hardware/nodes/switch.py rename to src/primaite/simulator/network/hardware/nodes/network/switch.py index b394bae0..e7d5d616 100644 --- a/src/primaite/simulator/network/hardware/nodes/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/network/switch.py @@ -1,16 +1,93 @@ -from typing import Dict +from __future__ import annotations +from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.exceptions import NetworkError -from primaite.simulator.network.hardware.base import Link, Node, SwitchPort +from primaite.simulator.network.hardware.base import WiredNetworkInterface, NetworkInterface, Link +from primaite.simulator.network.hardware.nodes.network.network_node import NetworkNode from primaite.simulator.network.transmission.data_link_layer import Frame _LOGGER = getLogger(__name__) -class Switch(Node): +class SwitchPort(WiredNetworkInterface): + """ + Represents a Switch Port. + + Switch ports connect devices within the same network. They operate at the data link layer (Layer 2) of the OSI model + and are responsible for receiving and forwarding frames based on MAC addresses. Despite operating at Layer 2, + they are an essential part of network infrastructure, enabling LAN segmentation, bandwidth management, and + the creation of VLANs. + + Inherits from: + - WiredNetworkInterface: Provides properties and methods specific to wired connections. + + Switch ports typically do not have IP addresses assigned to them as they function at Layer 2, but managed switches + can have management IP addresses for remote management and configuration purposes. + """ + _connected_node: Optional[Switch] = None + "The Switch to which the SwitchPort is connected." + + def set_original_state(self): + """Sets the original state.""" + vals_to_include = {"port_num", "mac_address", "speed", "mtu", "enabled"} + self._original_state = self.model_dump(include=vals_to_include) + super().set_original_state() + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + state.update( + { + "mac_address": self.mac_address, + "speed": self.speed, + "mtu": self.mtu, + "enabled": self.enabled, + } + ) + return state + + def send_frame(self, frame: Frame) -> bool: + """ + Attempts to send a network frame through the interface. + + :param frame: The network frame to be sent. + :return: A boolean indicating whether the frame was successfully sent. + """ + if self.enabled: + self.pcap.capture_outbound(frame) + self._connected_link.transmit_frame(sender_nic=self, frame=frame) + return True + # Cannot send Frame as the SwitchPort is not enabled + return False + + def receive_frame(self, frame: Frame) -> bool: + """ + Receives a network frame on the interface. + + :param frame: The network frame being received. + :return: A boolean indicating whether the frame was successfully received. + """ + if self.enabled: + frame.decrement_ttl() + if frame.ip and frame.ip.ttl < 1: + self._connected_node.sys_log.info("Frame discarded as TTL limit reached") + return False + self.pcap.capture_inbound(frame) + self._connected_node.receive_frame(frame=frame, from_network_interface=self) + return True + return False + + +class Switch(NetworkNode): """ A class representing a Layer 2 network switch. @@ -30,7 +107,7 @@ class Switch(Node): self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)} for port_num, port in self.switch_ports.items(): port._connected_node = self - port._port_num_on_node = port_num + port.port_num = port_num port.parent = self port.port_num = port_num @@ -78,16 +155,16 @@ class Switch(Node): self.sys_log.info(f"Removed MAC table entry: Port {mac_table_port.port_num} -> {mac_address}") self._add_mac_table_entry(mac_address, switch_port) - def forward_frame(self, frame: Frame, incoming_port: SwitchPort): + def receive_frame(self, frame: Frame, from_network_interface: SwitchPort): """ Forward a frame to the appropriate port based on the destination MAC address. - :param frame: The Frame to be forwarded. - :param incoming_port: The port number from which the frame was received. + :param frame: The Frame being received. + :param from_network_interface: The SwitchPort that received the frame. """ src_mac = frame.ethernet.src_mac_addr dst_mac = frame.ethernet.dst_mac_addr - self._add_mac_table_entry(src_mac, incoming_port) + self._add_mac_table_entry(src_mac, from_network_interface) outgoing_port = self.mac_address_table.get(dst_mac) if outgoing_port and dst_mac.lower() != "ff:ff:ff:ff:ff:ff": @@ -95,7 +172,7 @@ class Switch(Node): else: # If the destination MAC is not in the table, flood to all ports except incoming for port in self.switch_ports.values(): - if port.enabled and port != incoming_port: + if port.enabled and port != from_network_interface: port.send_frame(frame) def disconnect_link_from_port(self, link: Link, port_number: int): diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 630846b3..1d47fdef 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -1,11 +1,12 @@ from ipaddress import IPv4Address from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.base import NIC, NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.router import ACLAction, Router -from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.hardware.base import NodeOperatingState +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.host_node import NIC +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient @@ -40,13 +41,13 @@ def client_server_routed() -> Network: # Switch 1 switch_1 = Switch(hostname="switch_1", num_ports=6) switch_1.power_on() - network.connect(endpoint_a=router_1.ethernet_ports[1], endpoint_b=switch_1.switch_ports[6]) + network.connect(endpoint_a=router_1.network_interface[1], endpoint_b=switch_1.switch_ports[6]) router_1.enable_port(1) # Switch 2 switch_2 = Switch(hostname="switch_2", num_ports=6) switch_2.power_on() - network.connect(endpoint_a=router_1.ethernet_ports[2], endpoint_b=switch_2.switch_ports[6]) + network.connect(endpoint_a=router_1.network_interface[2], endpoint_b=switch_2.switch_ports[6]) router_1.enable_port(2) # Client 1 @@ -58,7 +59,7 @@ def client_server_routed() -> Network: operating_state=NodeOperatingState.ON, ) client_1.power_on() - network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) + network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.switch_ports[1]) # Server 1 server_1 = Server( @@ -69,7 +70,7 @@ def client_server_routed() -> Network: operating_state=NodeOperatingState.ON, ) server_1.power_on() - network.connect(endpoint_b=server_1.ethernet_port[1], endpoint_a=switch_1.switch_ports[1]) + network.connect(endpoint_b=server_1.network_interface[1], endpoint_a=switch_1.switch_ports[1]) router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) @@ -126,13 +127,13 @@ def arcd_uc2_network() -> Network: # Switch 1 switch_1 = Switch(hostname="switch_1", num_ports=8, operating_state=NodeOperatingState.ON) switch_1.power_on() - network.connect(endpoint_a=router_1.ethernet_ports[1], endpoint_b=switch_1.switch_ports[8]) + network.connect(endpoint_a=router_1.network_interface[1], endpoint_b=switch_1.switch_ports[8]) router_1.enable_port(1) # Switch 2 switch_2 = Switch(hostname="switch_2", num_ports=8, operating_state=NodeOperatingState.ON) switch_2.power_on() - network.connect(endpoint_a=router_1.ethernet_ports[2], endpoint_b=switch_2.switch_ports[8]) + network.connect(endpoint_a=router_1.network_interface[2], endpoint_b=switch_2.switch_ports[8]) router_1.enable_port(2) # Client 1 @@ -145,7 +146,7 @@ def arcd_uc2_network() -> Network: operating_state=NodeOperatingState.ON, ) client_1.power_on() - network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) + network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.switch_ports[1]) client_1.software_manager.install(DataManipulationBot) db_manipulation_bot: DataManipulationBot = client_1.software_manager.software.get("DataManipulationBot") db_manipulation_bot.configure( @@ -167,7 +168,7 @@ def arcd_uc2_network() -> Network: client_2.power_on() web_browser = client_2.software_manager.software.get("WebBrowser") web_browser.target_url = "http://arcd.com/users/" - network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) + network.connect(endpoint_b=client_2.network_interface[1], endpoint_a=switch_2.switch_ports[2]) # Domain Controller domain_controller = Server( @@ -180,7 +181,7 @@ def arcd_uc2_network() -> Network: domain_controller.power_on() domain_controller.software_manager.install(DNSServer) - network.connect(endpoint_b=domain_controller.ethernet_port[1], endpoint_a=switch_1.switch_ports[1]) + network.connect(endpoint_b=domain_controller.network_interface[1], endpoint_a=switch_1.switch_ports[1]) # Database Server database_server = Server( @@ -192,7 +193,7 @@ def arcd_uc2_network() -> Network: operating_state=NodeOperatingState.ON, ) database_server.power_on() - network.connect(endpoint_b=database_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[3]) + network.connect(endpoint_b=database_server.network_interface[1], endpoint_a=switch_1.switch_ports[3]) ddl = """ CREATE TABLE IF NOT EXISTS user ( @@ -270,7 +271,7 @@ def arcd_uc2_network() -> Network: database_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") database_client.configure(server_ip_address=IPv4Address("192.168.1.14")) - network.connect(endpoint_b=web_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[2]) + network.connect(endpoint_b=web_server.network_interface[1], endpoint_a=switch_1.switch_ports[2]) database_client.run() database_client.connect() @@ -291,7 +292,7 @@ def arcd_uc2_network() -> Network: ) backup_server.power_on() backup_server.software_manager.install(FTPServer) - network.connect(endpoint_b=backup_server.ethernet_port[1], endpoint_a=switch_1.switch_ports[4]) + network.connect(endpoint_b=backup_server.network_interface[1], endpoint_a=switch_1.switch_ports[4]) # Security Suite security_suite = Server( @@ -303,9 +304,9 @@ def arcd_uc2_network() -> Network: operating_state=NodeOperatingState.ON, ) security_suite.power_on() - network.connect(endpoint_b=security_suite.ethernet_port[1], endpoint_a=switch_1.switch_ports[7]) + network.connect(endpoint_b=security_suite.network_interface[1], endpoint_a=switch_1.switch_ports[7]) security_suite.connect_nic(NIC(ip_address="192.168.10.110", subnet_mask="255.255.255.0")) - network.connect(endpoint_b=security_suite.ethernet_port[2], endpoint_a=switch_2.switch_ports[7]) + network.connect(endpoint_b=security_suite.network_interface[2], endpoint_a=switch_2.switch_ports[7]) router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) diff --git a/src/primaite/simulator/network/protocols/arp.py b/src/primaite/simulator/network/protocols/arp.py index 7b3e4509..2e44884a 100644 --- a/src/primaite/simulator/network/protocols/arp.py +++ b/src/primaite/simulator/network/protocols/arp.py @@ -13,11 +13,12 @@ class ARPEntry(BaseModel): Represents an entry in the ARP cache. :param mac_address: The MAC address associated with the IP address. - :param nic: The NIC through which the NIC with the IP address is reachable. + :param network_interface_uuid: The UIId of the Network Interface through which the NIC with the IP address is + reachable. """ mac_address: str - nic_uuid: str + network_interface_uuid: str class ARPPacket(DataPacket): diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index d3a14d2a..5d34fd63 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -21,7 +21,7 @@ class PacketCapture: The PCAPs are logged to: //__pcap.log """ - def __init__(self, hostname: str, ip_address: Optional[str] = None, switch_port_number: Optional[int] = None): + def __init__(self, hostname: str, ip_address: Optional[str] = None, interface_num: Optional[int] = None): """ Initialize the PacketCapture process. @@ -32,8 +32,8 @@ class PacketCapture: "The hostname for which PCAP logs are being recorded." self.ip_address: str = ip_address "The IP address associated with the PCAP logs." - self.switch_port_number = switch_port_number - "The SwitchPort number." + self.interface_num = interface_num + "The interface num on the Node." self.inbound_logger = None self.outbound_logger = None @@ -81,8 +81,8 @@ class PacketCapture: """Get PCAP the logger name.""" if self.ip_address: return f"{self.hostname}_{self.ip_address}_{'outbound' if outbound else 'inbound'}_pcap" - if self.switch_port_number: - return f"{self.hostname}_port-{self.switch_port_number}_{'outbound' if outbound else 'inbound'}_pcap" + if self.interface_num: + return f"{self.hostname}_port-{self.interface_num}_{'outbound' if outbound else 'inbound'}_pcap" return f"{self.hostname}_{'outbound' if outbound else 'inbound'}_pcap" def _get_log_path(self, outbound: bool = False) -> Path: diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 2120cde3..eafdac8e 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -13,7 +13,7 @@ from primaite.simulator.network.transmission.network_layer import IPPacket, IPPr from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader, UDPHeader if TYPE_CHECKING: - from primaite.simulator.network.hardware.base import ARPCache, NIC + from primaite.simulator.network.hardware.base import NetworkInterface from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.core.sys_log import SysLog @@ -84,8 +84,6 @@ class SessionManager: self.software_manager: SoftwareManager = None # Noqa self.node: Node = None # noqa - - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -104,7 +102,7 @@ class SessionManager: @staticmethod def _get_session_key( - frame: Frame, inbound_frame: bool = True + frame: Frame, inbound_frame: bool = True ) -> Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]]: """ Extracts the session key from the given frame. @@ -142,19 +140,19 @@ class SessionManager: dst_port = None return protocol, with_ip_address, src_port, dst_port - def resolve_outbound_nic(self, dst_ip_address: IPv4Address) -> Optional[NIC]: - for nic in self.node.nics.values(): - if dst_ip_address in nic.ip_network and nic.enabled: - return nic - return self.software_manager.arp.get_default_gateway_nic() + def resolve_outbound_network_interface(self, dst_ip_address: IPv4Address) -> Optional['NetworkInterface']: + for network_interface in self.node.network_interfaces.values(): + if dst_ip_address in network_interface.ip_network and network_interface.enabled: + return network_interface + return self.software_manager.arp.get_default_gateway_network_interface() def resolve_outbound_transmission_details( - self, dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, session_id: Optional[str] = None - ) -> Tuple[Optional["NIC"], Optional[str], IPv4Address, Optional[IPProtocol], bool]: + self, dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, session_id: Optional[str] = None + ) -> Tuple[Optional['NetworkInterface'], Optional[str], IPv4Address, Optional[IPProtocol], bool]: if not isinstance(dst_ip_address, (IPv4Address, IPv4Network)): dst_ip_address = IPv4Address(dst_ip_address) is_broadcast = False - outbound_nic = None + outbound_network_interface = None dst_mac_address = None protocol = None @@ -172,36 +170,36 @@ class SessionManager: dst_ip_address = dst_ip_address.broadcast_address if dst_ip_address: # Find a suitable NIC for the broadcast - for nic in self.node.nics.values(): - if dst_ip_address in nic.ip_network and nic.enabled: + for network_interface in self.node.network_interfaces.values(): + if dst_ip_address in network_interface.ip_network and network_interface.enabled: dst_mac_address = "ff:ff:ff:ff:ff:ff" - outbound_nic = nic + outbound_network_interface = network_interface break else: # Resolve MAC address for unicast transmission use_default_gateway = True - for nic in self.node.nics.values(): - if dst_ip_address in nic.ip_network and nic.enabled: + for network_interface in self.node.network_interfaces.values(): + if dst_ip_address in network_interface.ip_network and network_interface.enabled: dst_mac_address = self.software_manager.arp.get_arp_cache_mac_address(dst_ip_address) break if dst_ip_address: use_default_gateway = False - outbound_nic = self.software_manager.arp.get_arp_cache_nic(dst_ip_address) + outbound_network_interface = self.software_manager.arp.get_arp_cache_network_interface(dst_ip_address) if use_default_gateway: dst_mac_address = self.software_manager.arp.get_default_gateway_mac_address() - outbound_nic = self.software_manager.arp.get_default_gateway_nic() - return outbound_nic, dst_mac_address, dst_ip_address, protocol, is_broadcast + outbound_network_interface = self.software_manager.arp.get_default_gateway_network_interface() + return outbound_network_interface, dst_mac_address, dst_ip_address, protocol, is_broadcast def receive_payload_from_software_manager( - self, - payload: Any, - dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, - dst_port: Optional[Port] = None, - session_id: Optional[str] = None, - ip_protocol: IPProtocol = IPProtocol.TCP, - icmp_packet: Optional[ICMPPacket] = None + self, + payload: Any, + dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, + dst_port: Optional[Port] = None, + session_id: Optional[str] = None, + ip_protocol: IPProtocol = IPProtocol.TCP, + icmp_packet: Optional[ICMPPacket] = None ) -> Union[Any, None]: """ Receive a payload from the SoftwareManager and send it to the appropriate NIC for transmission. @@ -222,19 +220,19 @@ class SessionManager: dst_mac_address = "ff:ff:ff:ff:ff:ff" else: dst_mac_address = payload.target_mac_addr - outbound_nic = self.resolve_outbound_nic(payload.target_ip_address) + outbound_network_interface = self.resolve_outbound_network_interface(payload.target_ip_address) is_broadcast = payload.request ip_protocol = IPProtocol.UDP else: vals = self.resolve_outbound_transmission_details( dst_ip_address=dst_ip_address, session_id=session_id ) - outbound_nic, dst_mac_address, dst_ip_address, protocol, is_broadcast = vals + outbound_network_interface, dst_mac_address, dst_ip_address, protocol, is_broadcast = vals if protocol: ip_protocol = protocol # Check if outbound NIC and destination MAC address are resolved - if not outbound_nic or not dst_mac_address: + if not outbound_network_interface or not dst_mac_address: return False tcp_header = None @@ -249,10 +247,18 @@ class SessionManager: src_port=dst_port, dst_port=dst_port, ) + # TODO: Only create IP packet if not ARP + # ip_packet = None + # if dst_port != Port.ARP: + # IPPacket( + # src_ip_address=outbound_network_interface.ip_address, + # dst_ip_address=dst_ip_address, + # protocol=ip_protocol + # ) # Construct the frame for transmission frame = Frame( - ethernet=EthernetHeader(src_mac_addr=outbound_nic.mac_address, dst_mac_addr=dst_mac_address), - ip=IPPacket(src_ip_address=outbound_nic.ip_address, dst_ip_address=dst_ip_address, protocol=ip_protocol), + ethernet=EthernetHeader(src_mac_addr=outbound_network_interface.mac_address, dst_mac_addr=dst_mac_address), + ip=IPPacket(src_ip_address=outbound_network_interface.ip_address, dst_ip_address=dst_ip_address, protocol=ip_protocol), tcp=tcp_header, udp=udp_header, icmp=icmp_packet, @@ -271,9 +277,9 @@ class SessionManager: self.sessions_by_uuid[session.uuid] = session # Send the frame through the NIC - return outbound_nic.send_frame(frame) + return outbound_network_interface.send_frame(frame) - def receive_frame(self, frame: Frame, from_nic: NIC): + def receive_frame(self, frame: Frame, from_network_interface: 'NetworkInterface'): """ Receive a Frame. @@ -302,7 +308,7 @@ class SessionManager: port=dst_port, protocol=frame.ip.protocol, session_id=session.uuid, - from_nic=from_nic, + from_network_interface=from_network_interface, frame=frame ) diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index 99dc5f38..53725c18 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -167,7 +167,7 @@ class SoftwareManager: ) def receive_payload_from_session_manager( - self, payload: Any, port: Port, protocol: IPProtocol, session_id: str, from_nic: "NIC", frame: Frame + self, payload: Any, port: Port, protocol: IPProtocol, session_id: str, from_network_interface: "NIC", frame: Frame ): """ Receive a payload from the SessionManager and forward it to the corresponding service or application. @@ -177,7 +177,7 @@ class SoftwareManager: """ receiver: Optional[Union[Service, Application]] = self.port_protocol_mapping.get((port, protocol), None) if receiver: - receiver.receive(payload=payload, session_id=session_id, from_nic=from_nic, frame=frame) + receiver.receive(payload=payload, session_id=session_id, from_network_interface=from_network_interface, frame=frame) else: self.sys_log.error(f"No service or application found for port {port} and protocol {protocol}") pass diff --git a/src/primaite/simulator/system/services/arp/arp.py b/src/primaite/simulator/system/services/arp/arp.py index c5b30d69..6a82432e 100644 --- a/src/primaite/simulator/system/services/arp/arp.py +++ b/src/primaite/simulator/system/services/arp/arp.py @@ -1,17 +1,16 @@ from __future__ import annotations from abc import abstractmethod -from ipaddress import IPv4Address from typing import Any, Dict, Optional, Union from prettytable import MARKDOWN, PrettyTable -from primaite.simulator.network.hardware.base import NIC +from primaite.simulator.network.hardware.base import NetworkInterface from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket -from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame -from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port, UDPHeader +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.service import Service +from primaite.utils.validators import IPV4Address class ARP(Service): @@ -21,7 +20,7 @@ class ARP(Service): Manages ARP for resolving network layer addresses into link layer addresses. It maintains an ARP cache, sends ARP requests and replies, and processes incoming ARP packets. """ - arp: Dict[IPv4Address, ARPEntry] = {} + arp: Dict[IPV4Address, ARPEntry] = {} def __init__(self, **kwargs): kwargs["name"] = "ARP" @@ -30,7 +29,7 @@ class ARP(Service): super().__init__(**kwargs) def describe_state(self) -> Dict: - pass + return super().describe_state() def show(self, markdown: bool = False): """ @@ -48,7 +47,7 @@ class ARP(Service): [ str(ip), arp.mac_address, - self.software_manager.node.nics[arp.nic_uuid].mac_address, + self.software_manager.node.network_interfaces[arp.network_interface_uuid].mac_address, ] ) print(table) @@ -57,7 +56,13 @@ class ARP(Service): """Clears the arp cache.""" self.arp.clear() - def add_arp_cache_entry(self, ip_address: IPv4Address, mac_address: str, nic: NIC, override: bool = False): + def add_arp_cache_entry( + self, + ip_address: IPV4Address, + mac_address: str, + network_interface: NetworkInterface, + override: bool = False + ): """ Add an ARP entry to the cache. @@ -66,20 +71,20 @@ class ARP(Service): :param ip_address: The IP address to be added to the cache. :param mac_address: The MAC address associated with the IP address. - :param nic: The NIC through which the NIC with the IP address is reachable. + :param network_interface: The NIC through which the NIC with the IP address is reachable. :param override: If True, an existing entry for the IP address will be overridden. Default is False. """ - for _nic in self.software_manager.node.nics.values(): - if _nic.ip_address == ip_address: + for _network_interface in self.software_manager.node.network_interfaces.values(): + if _network_interface.ip_address == ip_address: return if override or not self.arp.get(ip_address): - self.sys_log.info(f"Adding ARP cache entry for {mac_address}/{ip_address} via NIC {nic}") - arp_entry = ARPEntry(mac_address=mac_address, nic_uuid=nic.uuid) + self.sys_log.info(f"Adding ARP cache entry for {mac_address}/{ip_address} via NIC {network_interface}") + arp_entry = ARPEntry(mac_address=mac_address, network_interface_uuid=network_interface.uuid) self.arp[ip_address] = arp_entry @abstractmethod - def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: + def get_arp_cache_mac_address(self, ip_address: IPV4Address) -> Optional[str]: """ Retrieves the MAC address associated with a given IP address from the ARP cache. @@ -89,7 +94,7 @@ class ARP(Service): pass @abstractmethod - def get_arp_cache_nic(self, ip_address: IPv4Address) -> Optional[NIC]: + def get_arp_cache_network_interface(self, ip_address: IPV4Address) -> Optional[NetworkInterface]: """ Retrieves the NIC associated with a given IP address from the ARP cache. @@ -98,18 +103,20 @@ class ARP(Service): """ pass - def send_arp_request(self, target_ip_address: Union[IPv4Address, str]): + def send_arp_request(self, target_ip_address: Union[IPV4Address, str]): """ Sends an ARP request to resolve the MAC address of a target IP address. :param target_ip_address: The target IP address for which the MAC address is being requested. """ - outbound_nic = self.software_manager.session_manager.resolve_outbound_nic(target_ip_address) - if outbound_nic: - self.sys_log.info(f"Sending ARP request from NIC {outbound_nic} for ip {target_ip_address}") + outbound_network_interface = self.software_manager.session_manager.resolve_outbound_network_interface( + target_ip_address + ) + if outbound_network_interface: + self.sys_log.info(f"Sending ARP request from NIC {outbound_network_interface} for ip {target_ip_address}") arp_packet = ARPPacket( - sender_ip_address=outbound_nic.ip_address, - sender_mac_addr=outbound_nic.mac_address, + sender_ip_address=outbound_network_interface.ip_address, + sender_mac_addr=outbound_network_interface.mac_address, target_ip_address=target_ip_address, ) self.software_manager.session_manager.receive_payload_from_software_manager( @@ -125,11 +132,13 @@ class ARP(Service): Sends an ARP reply in response to an ARP request. :param arp_reply: The ARP packet containing the reply. - :param from_nic: The NIC from which the ARP reply is sent. + :param from_network_interface: The NIC from which the ARP reply is sent. """ - outbound_nic = self.software_manager.session_manager.resolve_outbound_nic(arp_reply.target_ip_address) - if outbound_nic: + outbound_network_interface = self.software_manager.session_manager.resolve_outbound_network_interface( + arp_reply.target_ip_address + ) + if outbound_network_interface: self.sys_log.info( f"Sending ARP reply from {arp_reply.sender_mac_addr}/{arp_reply.sender_ip_address} " f"to {arp_reply.target_ip_address}/{arp_reply.target_mac_addr} " @@ -147,31 +156,33 @@ class ARP(Service): @abstractmethod - def _process_arp_request(self, arp_packet: ARPPacket, from_nic: NIC): + def _process_arp_request(self, arp_packet: ARPPacket, from_network_interface: NIC): """ Processes an incoming ARP request. :param arp_packet: The ARP packet containing the request. - :param from_nic: The NIC that received the ARP request. + :param from_network_interface: The NIC that received the ARP request. """ self.sys_log.info( f"Received ARP request for {arp_packet.target_ip_address} from " f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip_address} " ) - def _process_arp_reply(self, arp_packet: ARPPacket, from_nic: NIC): + def _process_arp_reply(self, arp_packet: ARPPacket, from_network_interface: NIC): """ Processes an incoming ARP reply. :param arp_packet: The ARP packet containing the reply. - :param from_nic: The NIC that received the ARP reply. + :param from_network_interface: The NIC that received the ARP reply. """ self.sys_log.info( f"Received ARP response for {arp_packet.sender_ip_address} " - f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" + f"from {arp_packet.sender_mac_addr} via Network Interface {from_network_interface}" ) self.add_arp_cache_entry( - ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic + ip_address=arp_packet.sender_ip_address, + mac_address=arp_packet.sender_mac_addr, + network_interface=from_network_interface ) def receive(self, payload: Any, session_id: str, **kwargs) -> bool: @@ -183,15 +194,15 @@ class ARP(Service): :param kwargs: Additional keyword arguments. :return: True if the payload was processed successfully, otherwise False. """ - if not isinstance(payload, ARPPacket): - print("failied on payload check", type(payload)) + if not super().receive(payload, session_id, **kwargs): return False - from_nic = kwargs.get("from_nic") + from_network_interface = kwargs.get("from_network_interface") if payload.request: - self._process_arp_request(arp_packet=payload, from_nic=from_nic) + self._process_arp_request(arp_packet=payload, from_network_interface=from_network_interface) else: - self._process_arp_reply(arp_packet=payload, from_nic=from_nic) + self._process_arp_reply(arp_packet=payload, from_network_interface=from_network_interface) + return True def __contains__(self, item: Any) -> bool: """ diff --git a/src/primaite/simulator/system/services/arp/host_arp.py b/src/primaite/simulator/system/services/arp/host_arp.py deleted file mode 100644 index 4d6f7738..00000000 --- a/src/primaite/simulator/system/services/arp/host_arp.py +++ /dev/null @@ -1,95 +0,0 @@ -from __future__ import annotations - -from ipaddress import IPv4Address -from typing import Optional - -from primaite.simulator.network.hardware.base import NIC -from primaite.simulator.system.services.arp.arp import ARP, ARPPacket - - -class HostARP(ARP): - def get_default_gateway_mac_address(self) -> Optional[str]: - if self.software_manager.node.default_gateway: - return self.get_arp_cache_mac_address(self.software_manager.node.default_gateway) - - def get_default_gateway_nic(self) -> Optional[NIC]: - if self.software_manager.node.default_gateway: - return self.get_arp_cache_nic(self.software_manager.node.default_gateway) - - def _get_arp_cache_mac_address( - self, ip_address: IPv4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False - ) -> Optional[str]: - arp_entry = self.arp.get(ip_address) - - if arp_entry: - return arp_entry.mac_address - else: - if not is_reattempt: - self.send_arp_request(ip_address) - return self._get_arp_cache_mac_address( - ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt - ) - else: - if self.software_manager.node.default_gateway: - if not is_default_gateway_attempt: - self.send_arp_request(self.software_manager.node.default_gateway) - return self._get_arp_cache_mac_address( - ip_address=self.software_manager.node.default_gateway, is_reattempt=True, is_default_gateway_attempt=True - ) - return None - - def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: - """ - Get the MAC address associated with an IP address. - - :param ip_address: The IP address to look up in the cache. - :return: The MAC address associated with the IP address, or None if not found. - """ - return self._get_arp_cache_mac_address(ip_address) - - def _get_arp_cache_nic( - self, ip_address: IPv4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False - ) -> Optional[NIC]: - arp_entry = self.arp.get(ip_address) - - if arp_entry: - return self.software_manager.node.nics[arp_entry.nic_uuid] - else: - if not is_reattempt: - self.send_arp_request(ip_address) - return self._get_arp_cache_nic( - ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt - ) - else: - if self.software_manager.node.default_gateway: - if not is_default_gateway_attempt: - self.send_arp_request(self.software_manager.node.default_gateway) - return self._get_arp_cache_nic( - ip_address=self.software_manager.node.default_gateway, is_reattempt=True, is_default_gateway_attempt=True - ) - return None - - def get_arp_cache_nic(self, ip_address: IPv4Address) -> Optional[NIC]: - """ - Get the NIC associated with an IP address. - - :param ip_address: The IP address to look up in the cache. - :return: The NIC associated with the IP address, or None if not found. - """ - return self._get_arp_cache_nic(ip_address) - - def _process_arp_request(self, arp_packet: ARPPacket, from_nic: NIC): - super()._process_arp_request(arp_packet, from_nic) - # Unmatched ARP Request - if arp_packet.target_ip_address != from_nic.ip_address: - self.sys_log.info( - f"Ignoring ARP request for {arp_packet.target_ip_address}. Current IP address is {from_nic.ip_address}" - ) - return - - # Matched ARP request - self.add_arp_cache_entry( - ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic - ) - arp_packet = arp_packet.generate_reply(from_nic.mac_address) - self.send_arp_reply(arp_packet) diff --git a/src/primaite/simulator/system/services/arp/router_arp.py b/src/primaite/simulator/system/services/arp/router_arp.py index 3c32b108..d9108910 100644 --- a/src/primaite/simulator/system/services/arp/router_arp.py +++ b/src/primaite/simulator/system/services/arp/router_arp.py @@ -1,98 +1,78 @@ -# class RouterARPCache(ARPCache): +# from ipaddress import IPv4Address +# from typing import Optional, Any +# +# from primaite.simulator.network.hardware.nodes.network.router import RouterInterface, Router +# from primaite.simulator.network.protocols.arp import ARPPacket +# from primaite.simulator.network.transmission.data_link_layer import Frame +# from primaite.simulator.system.services.arp.arp import ARP +# +# +# class RouterARP(ARP): # """ # Inherits from ARPCache and adds router-specific ARP packet processing. # # :ivar SysLog sys_log: A system log for logging messages. # :ivar Router router: The router to which this ARP cache belongs. # """ +# router: Router # -# def __init__(self, sys_log: SysLog, router: Router): -# super().__init__(sys_log) -# self.router: Router = router +# def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: +# arp_entry = self.arp.get(ip_address) # -# def process_arp_packet( -# self, from_nic: NIC, frame: Frame, route_table: RouteTable, is_reattempt: bool = False -# ) -> None: -# """ -# Processes a received ARP (Address Resolution Protocol) packet in a router-specific way. +# if arp_entry: +# return arp_entry.mac_address +# return None # -# This method is responsible for handling both ARP requests and responses. It processes ARP packets received on a -# Network Interface Card (NIC) and performs actions based on whether the packet is a request or a reply. This -# includes updating the ARP cache, forwarding ARP replies, sending ARP requests for unknown destinations, and -# handling packet TTL (Time To Live). +# def get_arp_cache_network_interface(self, ip_address: IPv4Address) -> Optional[RouterInterface]: +# arp_entry = self.arp.get(ip_address) +# if arp_entry: +# return self.software_manager.node.network_interfaces[arp_entry.network_interface_uuid] +# return None # -# The method first checks if the ARP packet is a request or a reply. For ARP replies, it updates the ARP cache -# and forwards the reply if necessary. For ARP requests, it checks if the target IP matches one of the router's -# NICs and sends an ARP reply if so. If the destination is not directly connected, it consults the routing table -# to find the best route and reattempts ARP request processing if needed. -# -# :param from_nic: The NIC that received the ARP packet. -# :param frame: The frame containing the ARP packet. -# :param route_table: The routing table of the router. -# :param is_reattempt: Flag to indicate if this is a reattempt of processing the ARP packet, defaults to False. -# """ -# arp_packet = frame.arp -# -# # ARP Reply -# if not arp_packet.request: -# if arp_packet.target_ip_address == from_nic.ip_address: -# # reply to the Router specifically -# self.sys_log.info( -# f"Received ARP response for {arp_packet.sender_ip_address} " -# f"from {arp_packet.sender_mac_addr} via NIC {from_nic}" -# ) -# self.add_arp_cache_entry( -# ip_address=arp_packet.sender_ip_address, -# mac_address=arp_packet.sender_mac_addr, -# nic=from_nic, -# ) -# return -# -# # # Reply for a connected requested -# # nic = self.get_arp_cache_nic(arp_packet.target_ip_address) -# # if nic: -# # self.sys_log.info( -# # f"Forwarding arp reply for {arp_packet.target_ip_address}, from {arp_packet.sender_ip_address}" -# # ) -# # arp_packet.sender_mac_addr = nic.mac_address -# # frame.decrement_ttl() -# # if frame.ip and frame.ip.ttl < 1: -# # self.sys_log.info("Frame discarded as TTL limit reached") -# # return -# # nic.send_frame(frame) -# # return -# -# # ARP Request -# self.sys_log.info( -# f"Received ARP request for {arp_packet.target_ip_address} from " -# f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip_address} " -# ) -# # Matched ARP request +# def _process_arp_request(self, arp_packet: ARPPacket, from_network_interface: RouterInterface): +# super()._process_arp_request(arp_packet, from_network_interface) # self.add_arp_cache_entry( -# ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, nic=from_nic +# ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, +# network_interface=from_network_interface # ) # # # If the target IP matches one of the router's NICs -# for nic in self.nics.values(): -# if nic.enabled and nic.ip_address == arp_packet.target_ip_address: -# arp_reply = arp_packet.generate_reply(from_nic.mac_address) -# self.send_arp_reply(arp_reply, from_nic) +# for network_interface in self.network_interfaces.values(): +# if network_interface.enabled and network_interface.ip_address == arp_packet.target_ip_address: +# arp_reply = arp_packet.generate_reply(from_network_interface.mac_address) +# self.send_arp_reply(arp_reply) # return # -# # # Check Route Table -# # route = route_table.find_best_route(arp_packet.target_ip_address) -# # if route and route != self.router.route_table.default_route: -# # nic = self.get_arp_cache_nic(route.next_hop_ip_address) -# # -# # if not nic: -# # if not is_reattempt: -# # self.send_arp_request(route.next_hop_ip_address, ignore_networks=[frame.ip.src_ip_address]) -# # return self.process_arp_packet(from_nic, frame, route_table, is_reattempt=True) -# # else: -# # self.sys_log.info("Ignoring ARP request as destination unavailable/No ARP entry found") -# # return -# # else: -# # arp_reply = arp_packet.generate_reply(from_nic.mac_address) -# # self.send_arp_reply(arp_reply, from_nic) -# # return +# def _process_arp_reply(self, arp_packet: ARPPacket, from_network_interface: RouterInterface): +# if arp_packet.target_ip_address == from_network_interface.ip_address: +# super()._process_arp_reply(arp_packet, from_network_interface) # +# def receive(self, payload: Any, session_id: str, **kwargs) -> bool: +# """ +# Processes received data, handling ARP packets. +# +# :param payload: The payload received. +# :param session_id: The session ID associated with the received data. +# :param kwargs: Additional keyword arguments. +# :return: True if the payload was processed successfully, otherwise False. +# """ +# if not super().receive(payload, session_id, **kwargs): +# return False +# +# arp_packet: ARPPacket = payload +# from_network_interface: RouterInterface = kwargs["from_network_interface"] +# +# for network_interface in self.network_interfaces.values(): +# # ARP frame is for this Router +# if network_interface.ip_address == arp_packet.target_ip_address: +# if payload.request: +# self._process_arp_request(arp_packet=arp_packet, from_network_interface=from_network_interface) +# else: +# self._process_arp_reply(arp_packet=arp_packet, from_network_interface=from_network_interface) +# return True +# +# # ARP frame is not for this router, pass back down to Router to continue routing +# frame: Frame = kwargs["frame"] +# self.router.process_frame(frame=frame, from_network_interface=from_network_interface) +# +# return True diff --git a/src/primaite/simulator/system/services/icmp/icmp.py b/src/primaite/simulator/system/services/icmp/icmp.py index 93582350..be943c28 100644 --- a/src/primaite/simulator/system/services/icmp/icmp.py +++ b/src/primaite/simulator/system/services/icmp/icmp.py @@ -3,7 +3,6 @@ from ipaddress import IPv4Address from typing import Dict, Any, Union, Optional, Tuple from primaite import getLogger -from primaite.simulator.network.hardware.base import NIC from primaite.simulator.network.protocols.icmp import ICMPPacket, ICMPType from primaite.simulator.network.transmission.data_link_layer import Frame from primaite.simulator.network.transmission.network_layer import IPProtocol @@ -53,7 +52,7 @@ class ICMP(Service): return False if target_ip_address.is_loopback: self.sys_log.info("Pinging loopback address") - return any(nic.enabled for nic in self.nics.values()) + return any(network_interface.enabled for network_interface in self.network_interfaces.values()) self.sys_log.info(f"Pinging {target_ip_address}:", to_terminal=True) sequence, identifier = 0, None while sequence < pings: @@ -88,9 +87,9 @@ class ICMP(Service): :param pings: The number of pings to send. Defaults to 4. :return: A tuple containing the next sequence number and the identifier. """ - nic = self.software_manager.session_manager.resolve_outbound_nic(target_ip_address) + network_interface = self.software_manager.session_manager.resolve_outbound_network_interface(target_ip_address) - if not nic: + if not network_interface: self.sys_log.error( "Cannot send ICMP echo request as there is no outbound NIC to use. Try configuring the default gateway." ) @@ -118,9 +117,11 @@ class ICMP(Service): """ self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") - nic = self.software_manager.session_manager.resolve_outbound_nic(frame.ip.src_ip_address) + network_interface = self.software_manager.session_manager.resolve_outbound_network_interface( + frame.ip.src_ip_address + ) - if not nic: + if not network_interface: self.sys_log.error( "Cannot send ICMP echo reply as there is no outbound NIC to use. Try configuring the default gateway." ) diff --git a/src/primaite/simulator/system/services/icmp/router_icmp.py b/src/primaite/simulator/system/services/icmp/router_icmp.py index 1def00c4..5dcba3f1 100644 --- a/src/primaite/simulator/system/services/icmp/router_icmp.py +++ b/src/primaite/simulator/system/services/icmp/router_icmp.py @@ -16,30 +16,30 @@ # super().__init__(sys_log, arp_cache) # self.router = router # -# def process_icmp(self, frame: Frame, from_nic: NIC, is_reattempt: bool = False): +# def process_icmp(self, frame: Frame, from_network_interface: NIC, is_reattempt: bool = False): # """ # Process incoming ICMP frames based on ICMP type. # # :param frame: The incoming frame to process. -# :param from_nic: The network interface where the frame is coming from. +# :param from_network_interface: The network interface where the frame is coming from. # :param is_reattempt: Flag to indicate if the process is a reattempt. # """ # if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: # # determine if request is for router interface or whether it needs to be routed # -# for nic in self.router.nics.values(): -# if nic.ip_address == frame.ip.dst_ip_address: -# if nic.enabled: +# for network_interface in self.router.network_interfaces.values(): +# if network_interface.ip_address == frame.ip.dst_ip_address: +# if network_interface.enabled: # # reply to the request # if not is_reattempt: # self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") # target_mac_address = self.arp.get_arp_cache_mac_address(frame.ip.src_ip_address) -# src_nic = self.arp.get_arp_cache_nic(frame.ip.src_ip_address) +# src_nic = self.arp.get_arp_cache_network_interface(frame.ip.src_ip_address) # tcp_header = TCPHeader(src_port=Port.ARP, dst_port=Port.ARP) # # # Network Layer # ip_packet = IPPacket( -# src_ip_address=nic.ip_address, +# src_ip_address=network_interface.ip_address, # dst_ip_address=frame.ip.src_ip_address, # protocol=IPProtocol.ICMP, # ) @@ -67,12 +67,12 @@ # return # # # Route the frame -# self.router.process_frame(frame, from_nic) +# self.router.process_frame(frame, from_network_interface) # # elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: -# for nic in self.router.nics.values(): -# if nic.ip_address == frame.ip.dst_ip_address: -# if nic.enabled: +# for network_interface in self.router.network_interfaces.values(): +# if network_interface.ip_address == frame.ip.dst_ip_address: +# if network_interface.enabled: # time = frame.transmission_duration() # time_str = f"{time}ms" if time > 0 else "<1ms" # self.sys_log.info( @@ -87,4 +87,4 @@ # # return # # Route the frame -# self.router.process_frame(frame, from_nic) +# self.router.process_frame(frame, from_network_interface) diff --git a/src/primaite/utils/validators.py b/src/primaite/utils/validators.py new file mode 100644 index 00000000..13cff653 --- /dev/null +++ b/src/primaite/utils/validators.py @@ -0,0 +1,40 @@ +from ipaddress import IPv4Address +from typing import Any, Final + +from pydantic import ( + BeforeValidator, +) +from typing_extensions import Annotated + + +def ipv4_validator(v: Any) -> IPv4Address: + """ + Validate the input and ensure it can be converted to an IPv4Address instance. + + This function takes an input `v`, and if it's not already an instance of IPv4Address, it tries to convert it to one. + If the conversion is successful, the IPv4Address instance is returned. This is useful for ensuring that any input + data is strictly in the format of an IPv4 address. + + :param v: The input value that needs to be validated or converted to IPv4Address. + :return: An instance of IPv4Address. + :raises ValueError: If `v` is not a valid IPv4 address and cannot be converted to an instance of IPv4Address. + """ + if isinstance(v, IPv4Address): + return v + + return IPv4Address(v) + + +# Define a custom type IPV4Address using the typing_extensions.Annotated. +# Annotated is used to attach metadata to type hints. In this case, it's used to associate the ipv4_validator +# with the IPv4Address type, ensuring that any usage of IPV4Address undergoes validation before assignment. +IPV4Address: Final[Annotated] = Annotated[IPv4Address, BeforeValidator(ipv4_validator)] +""" +IPv4Address with with pre-validation and auto-conversion from str using ipv4_validator. + +This type is essentially an IPv4Address from the standard library's ipaddress module, +but with added validation logic. If you use this custom type, the ipv4_validator function +will automatically check and convert the input value to an instance of IPv4Address before +any Pydantic model uses it. This ensures that any field marked with this type is not just +an IPv4Address in form, but also valid according to the rules defined in ipv4_validator. +""" diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index eddb2211..6861f915 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -633,7 +633,7 @@ simulation: subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 - nics: + network_interfaces: 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index 8c273110..eb469ab8 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -637,7 +637,7 @@ simulation: subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 - nics: + network_interfaces: 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index dda645c3..5c8ebffd 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -1092,7 +1092,7 @@ simulation: subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 - nics: + network_interfaces: 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index e86d7f96..d9ca195f 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -642,7 +642,7 @@ simulation: subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 - nics: + network_interfaces: 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index e960c1e9..2f76625f 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -643,7 +643,7 @@ simulation: subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 - nics: + network_interfaces: 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 diff --git a/tests/conftest.py b/tests/conftest.py index 8e458878..0043cad1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,17 +6,15 @@ import pytest import yaml from primaite import getLogger -from primaite.game.game import PrimaiteGame from primaite.session.session import PrimaiteSession # from primaite.environment.primaite_env import Primaite # from primaite.primaite_session import PrimaiteSession from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.router import ACLAction, Router -from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.network.networks import arcd_uc2_network from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -34,7 +32,7 @@ from primaite import PRIMAITE_PATHS # PrimAITE v3 stuff from primaite.simulator.file_system.file_system import FileSystem -from primaite.simulator.network.hardware.base import Link, Node +from primaite.simulator.network.hardware.base import Node class TestService(Service): @@ -157,7 +155,7 @@ def client_server() -> Tuple[Computer, Server]: server.power_on() # Connect Computer and Server - network.connect(computer.ethernet_port[1], server.ethernet_port[1]) + network.connect(computer.network_interface[1], server.network_interface[1]) # Should be linked assert next(iter(network.links.values())).is_up @@ -192,8 +190,8 @@ def client_switch_server() -> Tuple[Computer, Switch, Server]: switch = Switch(hostname="switch", start_up_duration=0) switch.power_on() - network.connect(endpoint_a=computer.ethernet_port[1], endpoint_b=switch.switch_ports[1]) - network.connect(endpoint_a=server.ethernet_port[1], endpoint_b=switch.switch_ports[2]) + network.connect(endpoint_a=computer.network_interface[1], endpoint_b=switch.switch_ports[1]) + network.connect(endpoint_a=server.network_interface[1], endpoint_b=switch.switch_ports[2]) assert all(link.is_up for link in network.links.values()) @@ -219,18 +217,33 @@ def example_network() -> Network: network = Network() # Router 1 - router_1 = Router(hostname="router_1", num_ports=5, operating_state=NodeOperatingState.ON) + router_1 = Router( + hostname="router_1", + start_up_duration=0 + ) + router_1.power_on() router_1.configure_port(port=1, ip_address="192.168.1.1", subnet_mask="255.255.255.0") router_1.configure_port(port=2, ip_address="192.168.10.1", subnet_mask="255.255.255.0") # Switch 1 - switch_1 = Switch(hostname="switch_1", num_ports=8, operating_state=NodeOperatingState.ON) - network.connect(endpoint_a=router_1.ethernet_ports[1], endpoint_b=switch_1.switch_ports[8]) + switch_1 = Switch( + hostname="switch_1", + num_ports=8, + start_up_duration=0 + ) + switch_1.power_on() + + network.connect(endpoint_a=router_1.network_interface[1], endpoint_b=switch_1.switch_ports[8]) router_1.enable_port(1) # Switch 2 - switch_2 = Switch(hostname="switch_2", num_ports=8, operating_state=NodeOperatingState.ON) - network.connect(endpoint_a=router_1.ethernet_ports[2], endpoint_b=switch_2.switch_ports[8]) + switch_2 = Switch( + hostname="switch_2", + num_ports=8, + start_up_duration=0 + ) + switch_2.power_on() + network.connect(endpoint_a=router_1.network_interface[2], endpoint_b=switch_2.switch_ports[8]) router_1.enable_port(2) # Client 1 @@ -239,9 +252,10 @@ def example_network() -> Network: ip_address="192.168.10.21", subnet_mask="255.255.255.0", default_gateway="192.168.10.1", - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) - network.connect(endpoint_b=client_1.ethernet_port[1], endpoint_a=switch_2.switch_ports[1]) + client_1.power_on() + network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.switch_ports[1]) # Client 2 client_2 = Computer( @@ -249,32 +263,37 @@ def example_network() -> Network: ip_address="192.168.10.22", subnet_mask="255.255.255.0", default_gateway="192.168.10.1", - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) - network.connect(endpoint_b=client_2.ethernet_port[1], endpoint_a=switch_2.switch_ports[2]) + client_2.power_on() + network.connect(endpoint_b=client_2.network_interface[1], endpoint_a=switch_2.switch_ports[2]) - # Domain Controller + # Server 1 server_1 = Server( hostname="server_1", ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) + server_1.power_on() + network.connect(endpoint_b=server_1.network_interface[1], endpoint_a=switch_1.switch_ports[1]) - network.connect(endpoint_b=server_1.ethernet_port[1], endpoint_a=switch_1.switch_ports[1]) - - # Database Server + # DServer 2 server_2 = Server( hostname="server_2", ip_address="192.168.1.14", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) - network.connect(endpoint_b=server_2.ethernet_port[1], endpoint_a=switch_1.switch_ports[2]) + server_2.power_on() + network.connect(endpoint_b=server_2.network_interface[1], endpoint_a=switch_1.switch_ports[2]) router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + assert all(link.is_up for link in network.links.values()) + + return network diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index 992ed533..b68a887e 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -1,5 +1,5 @@ -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.database.database_service import DatabaseService diff --git a/tests/integration_tests/component_creation/test_action_integration.py b/tests/integration_tests/component_creation/test_action_integration.py index a2be923b..7d3945a6 100644 --- a/tests/integration_tests/component_creation/test_action_integration.py +++ b/tests/integration_tests/component_creation/test_action_integration.py @@ -1,9 +1,7 @@ -import pytest - from primaite.simulator.core import RequestType -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.sim_container import Simulation from primaite.simulator.system.services.database.database_service import DatabaseService @@ -27,9 +25,9 @@ def test_passing_actions_down(monkeypatch) -> None: downloads_folder = pc1.file_system.create_folder("downloads") pc1.file_system.create_file("bermuda_triangle.png", folder_name="downloads") - sim.network.connect(pc1.ethernet_port[1], s1.switch_ports[1]) - sim.network.connect(pc2.ethernet_port[1], s1.switch_ports[2]) - sim.network.connect(s1.switch_ports[3], srv.ethernet_port[1]) + sim.network.connect(pc1.network_interface[1], s1.switch_ports[1]) + sim.network.connect(pc2.network_interface[1], s1.switch_ports[2]) + sim.network.connect(s1.switch_ports[3], srv.network_interface[1]) # call this method to make sure no errors occur. sim._request_manager.get_request_types_recursively() diff --git a/tests/integration_tests/game_layer/test_observations.py b/tests/integration_tests/game_layer/test_observations.py index 07f3d25c..d1301759 100644 --- a/tests/integration_tests/game_layer/test_observations.py +++ b/tests/integration_tests/game_layer/test_observations.py @@ -1,7 +1,7 @@ from gymnasium import spaces from primaite.game.agent.observations import FileObservation -from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.sim_container import Simulation diff --git a/tests/integration_tests/network/test_broadcast.py b/tests/integration_tests/network/test_broadcast.py index 5fb0917e..2dd9f7b8 100644 --- a/tests/integration_tests/network/test_broadcast.py +++ b/tests/integration_tests/network/test_broadcast.py @@ -4,9 +4,9 @@ from typing import Any, Dict, List, Tuple import pytest from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application @@ -111,9 +111,9 @@ def broadcast_network() -> Network: switch_1 = Switch(hostname="switch_1", num_ports=6, start_up_duration=0) switch_1.power_on() - network.connect(endpoint_a=client_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[1]) - network.connect(endpoint_a=client_2.ethernet_port[1], endpoint_b=switch_1.switch_ports[2]) - network.connect(endpoint_a=server_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[3]) + network.connect(endpoint_a=client_1.network_interface[1], endpoint_b=switch_1.switch_ports[1]) + network.connect(endpoint_a=client_2.network_interface[1], endpoint_b=switch_1.switch_ports[2]) + network.connect(endpoint_a=server_1.network_interface[1], endpoint_b=switch_1.switch_ports[3]) return network diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index 527e4b4c..7beea643 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -1,7 +1,7 @@ from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.switch import Switch @@ -30,8 +30,8 @@ def test_node_to_node_ping(): switch_1 = Switch(hostname="switch_1", start_up_duration=0) switch_1.power_on() - network.connect(endpoint_a=client_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[1]) - network.connect(endpoint_a=server_1.ethernet_port[1], endpoint_b=switch_1.switch_ports[2]) + network.connect(endpoint_a=client_1.network_interface[1], endpoint_b=switch_1.switch_ports[1]) + network.connect(endpoint_a=server_1.network_interface[1], endpoint_b=switch_1.switch_ports[2]) assert client_1.ping("192.168.1.11") diff --git a/tests/integration_tests/network/test_network_creation.py b/tests/integration_tests/network/test_network_creation.py index 0af44dbb..d9792675 100644 --- a/tests/integration_tests/network/test_network_creation.py +++ b/tests/integration_tests/network/test_network_creation.py @@ -1,10 +1,7 @@ -import pytest - from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.base import NIC, Node -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.networks import client_server_routed +from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server def test_network(example_network): @@ -14,16 +11,16 @@ def test_network(example_network): server_1: Server = network.get_node_by_hostname("server_1") server_2: Server = network.get_node_by_hostname("server_2") - assert client_1.ping(client_2.ethernet_port[1].ip_address) - assert client_2.ping(client_1.ethernet_port[1].ip_address) + assert client_1.ping(client_2.network_interface[1].ip_address) + assert client_2.ping(client_1.network_interface[1].ip_address) - assert server_1.ping(server_2.ethernet_port[1].ip_address) - assert server_2.ping(server_1.ethernet_port[1].ip_address) + assert server_1.ping(server_2.network_interface[1].ip_address) + assert server_2.ping(server_1.network_interface[1].ip_address) - assert client_1.ping(server_1.ethernet_port[1].ip_address) - assert client_2.ping(server_1.ethernet_port[1].ip_address) - assert client_1.ping(server_2.ethernet_port[1].ip_address) - assert client_2.ping(server_2.ethernet_port[1].ip_address) + assert client_1.ping(server_1.network_interface[1].ip_address) + assert client_2.ping(server_1.network_interface[1].ip_address) + assert client_1.ping(server_2.network_interface[1].ip_address) + assert client_2.ping(server_2.network_interface[1].ip_address) def test_adding_removing_nodes(): @@ -71,7 +68,7 @@ def test_connecting_nodes(): net.add_node(n1) net.add_node(n2) - net.connect(n1.nics[n1_nic.uuid], n2.nics[n2_nic.uuid], bandwidth=30) + net.connect(n1.network_interfaces[n1_nic.uuid], n2.network_interfaces[n2_nic.uuid], bandwidth=30) assert len(net.links) == 1 link = list(net.links.values())[0] @@ -89,7 +86,7 @@ def test_connecting_node_to_itself(): net.add_node(node) - net.connect(node.nics[nic1.uuid], node.nics[nic2.uuid], bandwidth=30) + net.connect(node.network_interfaces[nic1.uuid], node.network_interfaces[nic2.uuid], bandwidth=30) assert node in net assert nic1._connected_link is None @@ -110,7 +107,7 @@ def test_disconnecting_nodes(): n2.connect_nic(n2_nic) net.add_node(n2) - net.connect(n1.nics[n1_nic.uuid], n2.nics[n2_nic.uuid], bandwidth=30) + net.connect(n1.network_interfaces[n1_nic.uuid], n2.network_interfaces[n2_nic.uuid], bandwidth=30) assert len(net.links) == 1 link = list(net.links.values())[0] diff --git a/tests/integration_tests/network/test_routing.py b/tests/integration_tests/network/test_routing.py index 042debca..02524eab 100644 --- a/tests/integration_tests/network/test_routing.py +++ b/tests/integration_tests/network/test_routing.py @@ -1,12 +1,10 @@ -from ipaddress import IPv4Address from typing import Tuple import pytest from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.ntp.ntp_client import NTPClient @@ -14,28 +12,37 @@ from primaite.simulator.system.services.ntp.ntp_server import NTPServer @pytest.fixture(scope="function") -def pc_a_pc_b_router_1() -> Tuple[Node, Node, Router]: - pc_a = Node(hostname="pc_a", default_gateway="192.168.0.1", operating_state=NodeOperatingState.ON) - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") - pc_a.connect_nic(nic_a) +def pc_a_pc_b_router_1() -> Tuple[Computer, Computer, Router]: + network = Network() + pc_a = Computer( + hostname="pc_a", + ip_address="192.168.0.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.0.1", + start_up_duration=0 + ) + pc_a.power_on() - pc_b = Node(hostname="pc_b", default_gateway="192.168.1.1", operating_state=NodeOperatingState.ON) - nic_b = NIC(ip_address="192.168.1.10", subnet_mask="255.255.255.0") - pc_b.connect_nic(nic_b) + pc_b = Computer( + hostname="pc_b", + ip_address="192.168.1.10", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0 + ) + pc_b.power_on() - router_1 = Router(hostname="router_1", operating_state=NodeOperatingState.ON) + router_1 = Router(hostname="router_1", start_up_duration=0) + router_1.power_on() router_1.configure_port(1, "192.168.0.1", "255.255.255.0") router_1.configure_port(2, "192.168.1.1", "255.255.255.0") - Link(endpoint_a=nic_a, endpoint_b=router_1.ethernet_ports[1]) - Link(endpoint_a=nic_b, endpoint_b=router_1.ethernet_ports[2]) + network.connect(endpoint_a=pc_a.network_interface[1], endpoint_b=router_1.network_interface[1]) + network.connect(endpoint_a=pc_b.network_interface[1], endpoint_b=router_1.network_interface[2]) router_1.enable_port(1) router_1.enable_port(2) - router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) - - router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) return pc_a, pc_b, router_1 @@ -61,7 +68,7 @@ def multi_hop_network() -> Network: # Configure the connection between PC A and Router 1 port 2 router_1.configure_port(2, "192.168.0.1", "255.255.255.0") - network.connect(pc_a.ethernet_port[1], router_1.ethernet_ports[2]) + network.connect(pc_a.network_interface[1], router_1.network_interface[2]) router_1.enable_port(2) # Configure Router 1 ACLs @@ -86,17 +93,15 @@ def multi_hop_network() -> Network: # Configure the connection between PC B and Router 2 port 2 router_2.configure_port(2, "192.168.2.1", "255.255.255.0") - network.connect(pc_b.ethernet_port[1], router_2.ethernet_ports[2]) + network.connect(pc_b.network_interface[1], router_2.network_interface[2]) router_2.enable_port(2) # Configure Router 2 ACLs - router_2.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) - router_2.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) # Configure the connection between Router 1 port 1 and Router 2 port 1 router_2.configure_port(1, "192.168.1.2", "255.255.255.252") router_1.configure_port(1, "192.168.1.1", "255.255.255.252") - network.connect(router_1.ethernet_ports[1], router_2.ethernet_ports[1]) + network.connect(router_1.network_interface[1], router_2.network_interface[1]) router_1.enable_port(1) router_2.enable_port(1) return network @@ -117,14 +122,14 @@ def test_ping_other_router_port(pc_a_pc_b_router_1): def test_host_on_other_subnet(pc_a_pc_b_router_1): pc_a, pc_b, router_1 = pc_a_pc_b_router_1 - assert pc_a.ping("192.168.1.10") + assert pc_a.ping(pc_b.network_interface[1].ip_address) def test_no_route_no_ping(multi_hop_network): pc_a = multi_hop_network.get_node_by_hostname("pc_a") pc_b = multi_hop_network.get_node_by_hostname("pc_b") - assert not pc_a.ping(pc_b.ethernet_port[1].ip_address) + assert not pc_a.ping(pc_b.network_interface[1].ip_address) def test_with_routes_can_ping(multi_hop_network): @@ -144,7 +149,7 @@ def test_with_routes_can_ping(multi_hop_network): address="192.168.0.2", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.1" ) - assert pc_a.ping(pc_b.ethernet_port[1].ip_address) + assert pc_a.ping(pc_b.network_interface[1].ip_address) def test_routing_services(multi_hop_network): @@ -159,7 +164,7 @@ def test_routing_services(multi_hop_network): pc_b.software_manager.install(NTPServer) pc_b.software_manager.software["NTPServer"].start() - ntp_client.configure(ntp_server_ip_address=pc_b.ethernet_port[1].ip_address) + ntp_client.configure(ntp_server_ip_address=pc_b.network_interface[1].ip_address) router_1: Router = multi_hop_network.get_node_by_hostname("router_1") # noqa router_2: Router = multi_hop_network.get_node_by_hostname("router_2") # noqa diff --git a/tests/integration_tests/network/test_switched_network.py b/tests/integration_tests/network/test_switched_network.py index 8a2bd0a2..98f36df6 100644 --- a/tests/integration_tests/network/test_switched_network.py +++ b/tests/integration_tests/network/test_switched_network.py @@ -1,12 +1,5 @@ -from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.base import Link, NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.hardware.nodes.switch import Switch - - def test_switched_network(client_switch_server): """Tests a node can ping another node via the switch.""" computer, switch, server = client_switch_server - assert computer.ping(server.ethernet_port[1].ip_address) + assert computer.ping(server.network_interface[1].ip_address) diff --git a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py index fb768127..ecf2c5ae 100644 --- a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py +++ b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py @@ -4,9 +4,9 @@ from typing import Tuple import pytest from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.router import ACLAction, Router -from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.database_client import DatabaseClient @@ -24,7 +24,7 @@ def dos_bot_and_db_server(client_server) -> Tuple[DoSBot, Computer, DatabaseServ dos_bot: DoSBot = computer.software_manager.software.get("DoSBot") dos_bot.configure( - target_ip_address=IPv4Address(server.nics.get(next(iter(server.nics))).ip_address), + target_ip_address=IPv4Address(server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address), target_port=Port.POSTGRES_SERVER, ) @@ -54,7 +54,7 @@ def dos_bot_db_server_green_client(example_network) -> Network: dos_bot: DoSBot = client_1.software_manager.software.get("DoSBot") dos_bot.configure( - target_ip_address=IPv4Address(server.nics.get(next(iter(server.nics))).ip_address), + target_ip_address=IPv4Address(server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address), target_port=Port.POSTGRES_SERVER, ) diff --git a/tests/integration_tests/system/test_application_on_node.py b/tests/integration_tests/system/test_application_on_node.py index 60497f22..143b2b04 100644 --- a/tests/integration_tests/system/test_application_on_node.py +++ b/tests/integration_tests/system/test_application_on_node.py @@ -3,7 +3,7 @@ from typing import Tuple import pytest from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.system.applications.application import Application, ApplicationOperatingState diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index daa125ca..df47d8ad 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -4,7 +4,7 @@ from typing import Tuple import pytest from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState -from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.ftp.ftp_server import FTPServer diff --git a/tests/integration_tests/system/test_dns_client_server.py b/tests/integration_tests/system/test_dns_client_server.py index a54bf23f..18988043 100644 --- a/tests/integration_tests/system/test_dns_client_server.py +++ b/tests/integration_tests/system/test_dns_client_server.py @@ -4,8 +4,8 @@ from typing import Tuple import pytest from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.service import ServiceOperatingState @@ -20,7 +20,7 @@ def dns_client_and_dns_server(client_server) -> Tuple[DNSClient, Computer, DNSSe dns_client: DNSClient = computer.software_manager.software.get("DNSClient") dns_client.start() # set server as DNS Server - dns_client.dns_server = IPv4Address(server.nics.get(next(iter(server.nics))).ip_address) + dns_client.dns_server = IPv4Address(server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address) # Install DNS Server on server server.software_manager.install(DNSServer) @@ -28,7 +28,7 @@ def dns_client_and_dns_server(client_server) -> Tuple[DNSClient, Computer, DNSSe dns_server.start() # register arcd.com as a domain dns_server.dns_register( - domain_name="arcd.com", domain_ip_address=IPv4Address(server.nics.get(next(iter(server.nics))).ip_address) + domain_name="arcd.com", domain_ip_address=IPv4Address(server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address) ) return dns_client, computer, dns_server, server diff --git a/tests/integration_tests/system/test_ftp_client_server.py b/tests/integration_tests/system/test_ftp_client_server.py index 1a6a8f41..6b46e302 100644 --- a/tests/integration_tests/system/test_ftp_client_server.py +++ b/tests/integration_tests/system/test_ftp_client_server.py @@ -1,10 +1,9 @@ -from ipaddress import IPv4Address from typing import Tuple import pytest -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.system.services.ftp.ftp_client import FTPClient from primaite.simulator.system.services.ftp.ftp_server import FTPServer from primaite.simulator.system.services.service import ServiceOperatingState @@ -44,7 +43,7 @@ def test_ftp_client_store_file_in_server(ftp_client_and_ftp_server): src_file_name="test_file.txt", dest_folder_name="client_1_backup", dest_file_name="test_file.txt", - dest_ip_address=server.nics.get(next(iter(server.nics))).ip_address, + dest_ip_address=server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address, ) assert ftp_server.file_system.get_file(folder_name="client_1_backup", file_name="test_file.txt") @@ -67,7 +66,7 @@ def test_ftp_client_retrieve_file_from_server(ftp_client_and_ftp_server): src_file_name="test_file.txt", dest_folder_name="downloads", dest_file_name="test_file.txt", - dest_ip_address=server.nics.get(next(iter(server.nics))).ip_address, + dest_ip_address=server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address, ) # client should have retrieved the file @@ -98,7 +97,7 @@ def test_ftp_client_tries_to_connect_to_offline_server(ftp_client_and_ftp_server src_file_name="test_file.txt", dest_folder_name="downloads", dest_file_name="test_file.txt", - dest_ip_address=server.nics.get(next(iter(server.nics))).ip_address, + dest_ip_address=server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address, ) is False ) diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index b7839479..92133d50 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -4,10 +4,8 @@ from typing import Tuple import pytest -from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.server import Server -from primaite.simulator.network.protocols.ntp import NTPPacket +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.system.services.ntp.ntp_client import NTPClient from primaite.simulator.system.services.ntp.ntp_server import NTPServer from primaite.simulator.system.services.service import ServiceOperatingState diff --git a/tests/integration_tests/system/test_service_on_node.py b/tests/integration_tests/system/test_service_on_node.py index 9b0084bd..12fed578 100644 --- a/tests/integration_tests/system/test_service_on_node.py +++ b/tests/integration_tests/system/test_service_on_node.py @@ -3,8 +3,8 @@ from typing import Tuple import pytest from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.system.services.service import Service, ServiceOperatingState diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py index b3d2e891..c809f954 100644 --- a/tests/integration_tests/system/test_web_client_server.py +++ b/tests/integration_tests/system/test_web_client_server.py @@ -3,8 +3,8 @@ from typing import Tuple import pytest from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.protocols.http import HttpStatusCode from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.web_browser import WebBrowser @@ -26,7 +26,7 @@ def web_client_and_web_server(client_server) -> Tuple[WebBrowser, Computer, WebS computer.software_manager.install(DNSClient) dns_client: DNSClient = computer.software_manager.software.get("DNSClient") # set dns server - dns_client.dns_server = server.nics[next(iter(server.nics))].ip_address + dns_client.dns_server = server.network_interfaces[next(iter(server.network_interfaces))].ip_address # Install Web Server service on server server.software_manager.install(WebServer) @@ -37,7 +37,7 @@ def web_client_and_web_server(client_server) -> Tuple[WebBrowser, Computer, WebS server.software_manager.install(DNSServer) dns_server: DNSServer = server.software_manager.software.get("DNSServer") # register arcd.com to DNS - dns_server.dns_register(domain_name="arcd.com", domain_ip_address=server.nics[next(iter(server.nics))].ip_address) + dns_server.dns_register(domain_name="arcd.com", domain_ip_address=server.network_interfaces[next(iter(server.network_interfaces))].ip_address) return web_browser, computer, web_server_service, server @@ -46,7 +46,7 @@ def test_web_page_get_users_page_request_with_domain_name(web_client_and_web_ser """Test to see if the client can handle requests with domain names""" web_browser_app, computer, web_server_service, server = web_client_and_web_server - web_server_ip = server.nics.get(next(iter(server.nics))).ip_address + web_server_ip = server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address web_browser_app.target_url = f"http://arcd.com/" assert web_browser_app.operating_state == ApplicationOperatingState.RUNNING @@ -61,7 +61,7 @@ def test_web_page_get_users_page_request_with_ip_address(web_client_and_web_serv """Test to see if the client can handle requests that use ip_address.""" web_browser_app, computer, web_server_service, server = web_client_and_web_server - web_server_ip = server.nics.get(next(iter(server.nics))).ip_address + web_server_ip = server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address web_browser_app.target_url = f"http://{web_server_ip}/" assert web_browser_app.operating_state == ApplicationOperatingState.RUNNING @@ -76,7 +76,7 @@ def test_web_page_request_from_shut_down_server(web_client_and_web_server): """Test to see that the web server does not respond when the server is off.""" web_browser_app, computer, web_server_service, server = web_client_and_web_server - web_server_ip = server.nics.get(next(iter(server.nics))).ip_address + web_server_ip = server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address web_browser_app.target_url = f"http://arcd.com/" assert web_browser_app.operating_state == ApplicationOperatingState.RUNNING diff --git a/tests/integration_tests/system/test_web_client_server_and_database.py b/tests/integration_tests/system/test_web_client_server_and_database.py index a4ef3d52..efb29f41 100644 --- a/tests/integration_tests/system/test_web_client_server_and_database.py +++ b/tests/integration_tests/system/test_web_client_server_and_database.py @@ -4,10 +4,9 @@ from typing import Tuple import pytest from primaite.simulator.network.hardware.base import Link -from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.network.hardware.nodes.router import ACLAction, Router -from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.web_browser import WebBrowser @@ -44,9 +43,9 @@ def web_client_web_server_database(example_network) -> Tuple[Computer, Server, S db_server = example_network.get_node_by_hostname("server_2") # Get the NICs - computer_nic = computer.nics[next(iter(computer.nics))] - server_nic = web_server.nics[next(iter(web_server.nics))] - db_server_nic = db_server.nics[next(iter(db_server.nics))] + computer_nic = computer.network_interfaces[next(iter(computer.network_interfaces))] + server_nic = web_server.network_interfaces[next(iter(web_server.network_interfaces))] + db_server_nic = db_server.network_interfaces[next(iter(db_server.network_interfaces))] # Connect Computer and Server link_computer_server = Link(endpoint_a=computer_nic, endpoint_b=server_nic) @@ -74,7 +73,7 @@ def web_client_web_server_database(example_network) -> Tuple[Computer, Server, S computer.software_manager.install(DNSClient) dns_client: DNSClient = computer.software_manager.software.get("DNSClient") # set dns server - dns_client.dns_server = web_server.nics[next(iter(web_server.nics))].ip_address + dns_client.dns_server = web_server.network_interfaces[next(iter(web_server.network_interfaces))].ip_address # Install Web Server service on web server web_server.software_manager.install(WebServer) @@ -86,7 +85,7 @@ def web_client_web_server_database(example_network) -> Tuple[Computer, Server, S dns_server: DNSServer = web_server.software_manager.software.get("DNSServer") # register arcd.com to DNS dns_server.dns_register( - domain_name="arcd.com", domain_ip_address=web_server.nics[next(iter(web_server.nics))].ip_address + domain_name="arcd.com", domain_ip_address=web_server.network_interfaces[next(iter(web_server.network_interfaces))].ip_address ) # Install DatabaseClient service on web server diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py index 554cba38..428f370c 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py @@ -1,6 +1,6 @@ from ipaddress import IPv4Address -from primaite.simulator.network.hardware.nodes.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_switch.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_switch.py index d2d0e52c..a0f6619c 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_switch.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_switch.py @@ -1,7 +1,7 @@ import pytest from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.hardware.nodes.network.switch import Switch @pytest.fixture(scope="function") diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py index 1bf2cdbb..90b54b78 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py @@ -29,21 +29,21 @@ def test_invalid_oui_mac_address(): def test_nic_ip_address_type_conversion(): """Tests NIC IP and gateway address is converted to IPv4Address is originally a string.""" - nic = NIC( + network_interface = NIC( ip_address="192.168.1.2", subnet_mask="255.255.255.0", ) - assert isinstance(nic.ip_address, IPv4Address) + assert isinstance(network_interface.ip_address, IPv4Address) def test_nic_deserialize(): """Tests NIC serialization and deserialization.""" - nic = NIC( + network_interface = NIC( ip_address="192.168.1.2", subnet_mask="255.255.255.0", ) - nic_json = nic.model_dump_json() + nic_json = network_interface.model_dump_json() deserialized_nic = NIC.model_validate_json(nic_json) assert nic_json == deserialized_nic.model_dump_json() diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index 7667a59f..b56253fb 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -5,9 +5,7 @@ import pytest from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.base import Link, Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer -from primaite.simulator.system.applications.database_client import DatabaseClient -from primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.network.hardware.nodes.host.computer import Computer def filter_keys_nested_item(data, keys): diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py index 71489171..eafa6359 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py @@ -3,7 +3,7 @@ from ipaddress import IPv4Address import pytest from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.red_applications.dos_bot import DoSAttackStage, DoSBot diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py index 204b356f..6fec4555 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py @@ -1,11 +1,11 @@ from ipaddress import IPv4Address -from typing import Tuple, Union +from typing import Tuple from uuid import uuid4 import pytest from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.database_client import DatabaseClient diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py index dc8f7419..9dc7a52e 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py @@ -1,9 +1,7 @@ -from typing import Tuple - import pytest from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.protocols.http import HttpResponsePacket, HttpStatusCode from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py index 2bcb512d..97c1cf4e 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py @@ -4,7 +4,7 @@ import pytest from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.protocols.dns import DNSPacket, DNSReply, DNSRequest from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py index eb042c92..5f5fdcba 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py @@ -4,7 +4,7 @@ import pytest from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.protocols.dns import DNSPacket, DNSRequest from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py index 941a465e..5d900fff 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_client.py @@ -5,7 +5,7 @@ import pytest from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py index 137e74d0..a4fcdff7 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_ftp_server.py @@ -3,7 +3,7 @@ import pytest from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.protocols.ftp import FTPCommand, FTPPacket, FTPStatusCode from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py index 64277356..2e645435 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py @@ -1,7 +1,7 @@ import pytest from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.server import Server +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.protocols.http import ( HttpRequestMethod, HttpRequestPacket, From 5b5b750d4d305ff0844ca4476b398acf7f96eced Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 6 Feb 2024 14:42:59 +0000 Subject: [PATCH 564/980] Add second green agent and make rewards based on webbrowser --- CHANGELOG.md | 1 + .../config/_package_data/example_config.yaml | 68 ++- src/primaite/game/agent/rewards.py | 72 ++- src/primaite/game/game.py | 2 +- src/primaite/notebooks/uc2_demo.ipynb | 449 ++---------------- .../system/applications/web_browser.py | 34 +- .../test_web_client_server_and_database.py | 40 +- 7 files changed, 202 insertions(+), 464 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdb530e2..bc39a2b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- Changed the data manipulation scenario to include a second green agent on client 1. - Refactored actions and observations to be configurable via object name, instead of UUID. - Fixed a bug where ACL rules were not resetting on episode reset. - Fixed a bug where blue agent's ACL actions were being applied against the wrong IP addresses diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 7a286931..700a0c18 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -60,6 +60,31 @@ agents: frequency: 4 variance: 3 + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_1 + applications: + - application_name: WebBrowser + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_applications_per_node: 1 + reward_function: + reward_components: + - type: DUMMY + + + + - ref: client_1_data_manipulation_red_bot team: RED type: RedDatabaseCorruptingAgent @@ -112,7 +137,7 @@ agents: - service_name: DNSServer - node_hostname: web_server services: - - service_name: web_server_web_service + - service_name: WebServer - node_hostname: database_server folders: - folder_name: database @@ -241,25 +266,25 @@ agents: action: "NODE_FILE_SCAN" options: node_id: 2 - folder_id: 1 + folder_id: 0 file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: node_id: 2 - folder_id: 1 + folder_id: 0 file_id: 0 11: action: "NODE_FILE_DELETE" options: node_id: 2 - folder_id: 1 + folder_id: 0 file_id: 0 12: action: "NODE_FILE_REPAIR" options: node_id: 2 - folder_id: 1 + folder_id: 0 file_id: 0 13: action: "NODE_SERVICE_PATCH" @@ -270,22 +295,22 @@ agents: action: "NODE_FOLDER_SCAN" options: node_id: 2 - folder_id: 1 + folder_id: 0 15: action: "NODE_FOLDER_CHECKHASH" options: node_id: 2 - folder_id: 1 + folder_id: 0 16: action: "NODE_FOLDER_REPAIR" options: node_id: 2 - folder_id: 1 + folder_id: 0 17: action: "NODE_FOLDER_RESTORE" options: node_id: 2 - folder_id: 1 + folder_id: 0 18: action: "NODE_OS_SCAN" options: @@ -302,7 +327,7 @@ agents: action: "NODE_RESET" options: node_id: 5 - 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) + 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" action: "NETWORK_ACL_ADDRULE" options: position: 1 @@ -312,7 +337,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) + 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" action: "NETWORK_ACL_ADDRULE" options: position: 2 @@ -497,6 +522,8 @@ agents: - folder_name: database files: - file_name: database.db + services: + - service_name: DatabaseService - node_name: backup_server - node_name: security_suite - node_name: client_1 @@ -529,18 +556,19 @@ agents: reward_function: reward_components: - type: DATABASE_FILE_INTEGRITY - weight: 0.5 + weight: 0.34 options: node_hostname: database_server folder_name: database file_name: database.db - - - - type: WEB_SERVER_404_PENALTY - weight: 0.5 + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.33 options: - node_hostname: web_server - service_name: WebServer + node_hostname: client_1 + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.33 + options: + node_hostname: client_2 agent_settings: @@ -682,6 +710,10 @@ simulation: data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 + - ref: client_1_web_browser + type: WebBrowser + options: + target_url: http://arcd.com/users/ services: - ref: client_1_dns_client type: DNSClient diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 8944a184..1a37b954 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -26,16 +26,13 @@ the structure: ``` """ from abc import abstractmethod -from typing import Dict, List, Tuple, Type, TYPE_CHECKING +from typing import Dict, List, Tuple, Type from primaite import getLogger from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE _LOGGER = getLogger(__name__) -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame - class AbstractReward: """Base class for reward function components.""" @@ -47,13 +44,11 @@ class AbstractReward: @classmethod @abstractmethod - def from_config(cls, config: dict, game: "PrimaiteGame") -> "AbstractReward": + def from_config(cls, config: dict) -> "AbstractReward": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor :type config: dict - :param game: Reference to the PrimAITE Game object - :type game: PrimaiteGame :return: The reward component. :rtype: AbstractReward """ @@ -68,13 +63,11 @@ class DummyReward(AbstractReward): return 0.0 @classmethod - def from_config(cls, config: dict, game: "PrimaiteGame") -> "DummyReward": + def from_config(cls, config: dict) -> "DummyReward": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor. Should be empty. :type config: dict - :param game: Reference to the PrimAITE Game object - :type game: PrimaiteGame """ return cls() @@ -126,13 +119,11 @@ class DatabaseFileIntegrity(AbstractReward): return 0 @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "DatabaseFileIntegrity": + def from_config(cls, config: Dict) -> "DatabaseFileIntegrity": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor :type config: Dict - :param game: Reference to the PrimAITE Game object - :type game: PrimaiteGame :return: The reward component. :rtype: DatabaseFileIntegrity """ @@ -179,13 +170,11 @@ class WebServer404Penalty(AbstractReward): return 0.0 @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "WebServer404Penalty": + def from_config(cls, config: Dict) -> "WebServer404Penalty": """Create a reward function component from a config dictionary. :param config: dict of options for the reward component's constructor :type config: Dict - :param game: Reference to the PrimAITE Game object - :type game: PrimaiteGame :return: The reward component. :rtype: WebServer404Penalty """ @@ -202,6 +191,50 @@ class WebServer404Penalty(AbstractReward): return cls(node_hostname=node_hostname, service_name=service_name) +class WebpageUnavailablePenalty(AbstractReward): + """Penalises the agent when the web browser fails to fetch a webpage.""" + + def __init__(self, node_hostname: str) -> None: + """ + Initialise the reward component. + + :param node_hostname: Hostname of the node which has the web browser. + :type node_hostname: str + """ + self._node = node_hostname + self.location_in_state = ["network", "nodes", node_hostname, "applications", "WebBrowser"] + + def calculate(self, state: Dict) -> float: + """ + Calculate the reward based on current simulation state. + + :param state: The current state of the simulation. + :type state: Dict + """ + web_browser_state = access_from_nested_dict(state, self.location_in_state) + if web_browser_state is NOT_PRESENT_IN_STATE or "history" not in web_browser_state: + _LOGGER.info( + "Web browser reward could not be calculated because the web browser history on node", + f"{self._node} was not reported in the simulation state. Returning 0.0", + ) + return 0.0 # 0 if the web browser cannot be found + if not web_browser_state["history"]: + return 0.0 # 0 if no requests have been attempted yet + outcome = web_browser_state["history"][-1]["outcome"] + if outcome == "PENDING": + return 0.0 # 0 if a request was attempted but not yet resolved + elif outcome == 200: + return 1.0 # 1 for successful request + else: # includes failure codes and SERVER_UNREACHABLE + return -1.0 # -1 for failure + + @classmethod + def from_config(cls, config: dict) -> AbstractReward: + """Build the reward component object from config.""" + node_hostname = config.get("node_hostname") + return cls(node_hostname=node_hostname) + + class RewardFunction: """Manages the reward function for the agent.""" @@ -209,6 +242,7 @@ class RewardFunction: "DUMMY": DummyReward, "DATABASE_FILE_INTEGRITY": DatabaseFileIntegrity, "WEB_SERVER_404_PENALTY": WebServer404Penalty, + "WEBPAGE_UNAVAILABLE_PENALTY": WebpageUnavailablePenalty, } def __init__(self): @@ -243,13 +277,11 @@ class RewardFunction: return self.current_reward @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "RewardFunction": + def from_config(cls, config: Dict) -> "RewardFunction": """Create a reward function from a config dictionary. :param config: dict of options for the reward manager's constructor :type config: Dict - :param game: Reference to the PrimAITE Game object - :type game: PrimaiteGame :return: The reward manager. :rtype: RewardFunction """ @@ -259,6 +291,6 @@ class RewardFunction: rew_type = rew_component_cfg["type"] weight = rew_component_cfg.get("weight", 1.0) rew_class = cls.__rew_class_identifiers[rew_type] - rew_instance = rew_class.from_config(config=rew_component_cfg.get("options", {}), game=game) + rew_instance = rew_class.from_config(config=rew_component_cfg.get("options", {})) new.register_component(component=rew_instance, weight=weight) return new diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 368d899a..8ecb365e 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -345,7 +345,7 @@ class PrimaiteGame: action_space = ActionManager.from_config(game, action_space_cfg) # CREATE REWARD FUNCTION - rew_function = RewardFunction.from_config(reward_function_cfg, game=game) + rew_function = RewardFunction.from_config(reward_function_cfg) # OTHER AGENT SETTINGS agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index 679e8226..4e2e5e30 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -46,7 +46,7 @@ "source": [ "## Green agent\n", "\n", - "The green agent is logged onto client 2. It sometimes uses the web browser on client 2 to navigate to `http://arcd.com/users`. The web server replies with a status code 200 if the data is available on the database or 404 if not available." + "There are green agents is logged onto client 1 and client 2. They use the web browser to navigate to `http://arcd.com/users`. The web server replies with a status code 200 if the data is available on the database or 404 if not available." ] }, { @@ -68,7 +68,7 @@ "source": [ "## Blue agent\n", "\n", - "The blue agent can view the entire network, but the health statuses of components are not updated until a scan is performed. The blue agent should restore the database file from backup after it was compromised. It can also prevent further attacks by blocking client 1 from reaching the database server. This can be done by removing client 1's network connection or adding ACL rules on the router to stop the packets from arriving." + "The blue agent can view the entire network, but the health statuses of components are not updated until a scan is performed. The blue agent should restore the database file from backup after it was compromised. It can also prevent further attacks by blocking client 1 from sending the malicious SQL query to the database server. This can be done by removing implementing an ACL rule on the router." ] }, { @@ -100,9 +100,9 @@ "The red agent does not use information about the state of the network to decide its action.\n", "\n", "### Green\n", - "The green agent sits on client 2 and uses the web browser application to send requests to the web server. The schedule of the green agent is currently random, meaning it will request webpage with a 50% probability, and do nothing with a 50% probability.\n", + "The green agents use the web browser application to send requests to the web server. The schedule of each green agent is currently random, meaning it will request webpage with a 50% probability, and do nothing with a 50% probability.\n", "\n", - "When the green agent is blocked from accessing the data through the webpage, this incurs a negative reward to the RL defender." + "When a green agent is blocked from accessing the data through the webpage, this incurs a negative reward to the RL defender." ] }, { @@ -295,7 +295,7 @@ "- `28-37`: Remove ACL rules 1-10\n", "- `42`: Disconnect client 1 from the network\n", "\n", - "The other actions will either have no effect or will negatively impact the network, so the blue agent should avoid taking other actions, and learn about these actions." + "The other actions will either have no effect or will negatively impact the network, so the blue agent should avoid taking them." ] }, { @@ -306,8 +306,8 @@ "\n", "The blue agent's reward is calculated using two measures:\n", "1. Whether the database file is in a good state (+1 for good, -1 for corrupted, 0 for any other state)\n", - "2. Whether the green agent's most recent webpage request was successful (+1 for a `200` return code, -1 for a `404` return code and 0 otherwise).\n", - "These two components are averaged to get the final reward.\n" + "2. Whether each green agents' most recent webpage request was successful (+1 for a `200` return code, -1 for a `404` return code and 0 otherwise).\n", + "The file status reward and the two green-agent-related reward are averaged to get a total step reward.\n" ] }, { @@ -326,7 +326,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -336,20 +336,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/cade/repos/PrimAITE/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n", - "2024-01-25 14:43:32,056\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", - "2024-01-25 14:43:35,213\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n" - ] - } - ], + "outputs": [], "source": [ "# Imports\n", "from primaite.config.load import example_config_path\n", @@ -370,134 +359,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Resetting environment, episode 0, avg. reward: 0.0\n", - "env created successfully\n", - "{'ACL': {1: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 0,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 2: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 1,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 3: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 2,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 4: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 3,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 5: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 4,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 6: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 5,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 7: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 6,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 8: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 7,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 9: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 8,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 10: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 9,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0}},\n", - " 'ICS': 0,\n", - " 'LINKS': {1: {'PROTOCOLS': {'ALL': 1}},\n", - " 2: {'PROTOCOLS': {'ALL': 1}},\n", - " 3: {'PROTOCOLS': {'ALL': 1}},\n", - " 4: {'PROTOCOLS': {'ALL': 1}},\n", - " 5: {'PROTOCOLS': {'ALL': 1}},\n", - " 6: {'PROTOCOLS': {'ALL': 1}},\n", - " 7: {'PROTOCOLS': {'ALL': 1}},\n", - " 8: {'PROTOCOLS': {'ALL': 1}},\n", - " 9: {'PROTOCOLS': {'ALL': 1}},\n", - " 10: {'PROTOCOLS': {'ALL': 1}}},\n", - " 'NODES': {1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}},\n", - " 'health_status': 1}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1}}}\n" - ] - } - ], + "outputs": [], "source": [ "# create the env\n", "with open(example_config_path(), 'r') as f:\n", @@ -523,48 +387,9 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 1, Red action: DONOTHING, Blue reward:0.5\n", - "step: 2, Red action: DONOTHING, Blue reward:0.5\n", - "step: 3, Red action: DONOTHING, Blue reward:0.5\n", - "step: 4, Red action: DONOTHING, Blue reward:0.5\n", - "step: 5, Red action: DONOTHING, Blue reward:1.0\n", - "step: 6, Red action: DONOTHING, Blue reward:1.0\n", - "step: 7, Red action: DONOTHING, Blue reward:1.0\n", - "step: 8, Red action: DONOTHING, Blue reward:1.0\n", - "step: 9, Red action: DONOTHING, Blue reward:1.0\n", - "step: 10, Red action: DONOTHING, Blue reward:1.0\n", - "step: 11, Red action: DONOTHING, Blue reward:1.0\n", - "step: 12, Red action: DONOTHING, Blue reward:1.0\n", - "step: 13, Red action: DONOTHING, Blue reward:1.0\n", - "step: 14, Red action: DONOTHING, Blue reward:1.0\n", - "step: 15, Red action: DONOTHING, Blue reward:1.0\n", - "step: 16, Red action: DONOTHING, Blue reward:1.0\n", - "step: 17, Red action: DONOTHING, Blue reward:1.0\n", - "step: 18, Red action: DONOTHING, Blue reward:1.0\n", - "step: 19, Red action: DONOTHING, Blue reward:1.0\n", - "step: 20, Red action: DONOTHING, Blue reward:1.0\n", - "step: 21, Red action: DONOTHING, Blue reward:1.0\n", - "step: 22, Red action: NODE_APPLICATION_EXECUTE, Blue reward:0.0\n", - "step: 23, Red action: DONOTHING, Blue reward:0.0\n", - "step: 24, Red action: DONOTHING, Blue reward:0.0\n", - "step: 25, Red action: DONOTHING, Blue reward:0.0\n", - "step: 26, Red action: DONOTHING, Blue reward:-1.0\n", - "step: 27, Red action: DONOTHING, Blue reward:-1.0\n", - "step: 28, Red action: DONOTHING, Blue reward:-1.0\n", - "step: 29, Red action: DONOTHING, Blue reward:-1.0\n", - "step: 30, Red action: DONOTHING, Blue reward:-1.0\n", - "step: 31, Red action: DONOTHING, Blue reward:-1.0\n", - "step: 32, Red action: DONOTHING, Blue reward:-1.0\n" - ] - } - ], + "outputs": [], "source": [ "for step in range(32):\n", " obs, reward, terminated, truncated, info = env.step(0)\n", @@ -580,44 +405,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}}, 'health_status': 1}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1}}\n" - ] - } - ], + "outputs": [], "source": [ "pprint(obs['NODES'])" ] @@ -631,44 +421,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 3, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 2}}, 'health_status': 1}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1}}\n" - ] - } - ], + "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(9) # scan database file\n", "obs, reward, terminated, truncated, info = env.step(1) # scan webapp service\n", @@ -692,24 +447,14 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 35\n", - "Red action: DONOTHING\n", - "Green action: NODE_APPLICATION_EXECUTE\n", - "Blue reward:-1.0\n" - ] - } - ], + "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(13) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", "print(f\"Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}\" )\n", + "print(f\"Green action: {info['agent_actions']['client_1_green_user'][0]}\" )\n", "print(f\"Green action: {info['agent_actions']['client_2_green_user'][0]}\" )\n", "print(f\"Blue reward:{reward}\" )" ] @@ -727,25 +472,15 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 36\n", - "Red action: DONOTHING\n", - "Green action: NODE_APPLICATION_EXECUTE\n", - "Blue reward:0.0\n" - ] - } - ], + "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(0) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", "print(f\"Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}\" )\n", "print(f\"Green action: {info['agent_actions']['client_2_green_user'][0]}\" )\n", + "print(f\"Green action: {info['agent_actions']['client_1_green_user'][0]}\" )\n", "print(f\"Blue reward:{reward}\" )" ] }, @@ -758,48 +493,9 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 37, Red action: DONOTHING, Blue reward:0.0\n", - "step: 38, Red action: DONOTHING, Blue reward:0.0\n", - "step: 39, Red action: DONOTHING, Blue reward:1.0\n", - "step: 40, Red action: DONOTHING, Blue reward:1.0\n", - "step: 41, Red action: DONOTHING, Blue reward:1.0\n", - "step: 42, Red action: DONOTHING, Blue reward:1.0\n", - "step: 43, Red action: DONOTHING, Blue reward:1.0\n", - "step: 44, Red action: DONOTHING, Blue reward:1.0\n", - "step: 45, Red action: DONOTHING, Blue reward:1.0\n", - "step: 46, Red action: NODE_APPLICATION_EXECUTE, Blue reward:1.0\n", - "step: 47, Red action: DONOTHING, Blue reward:1.0\n", - "step: 48, Red action: DONOTHING, Blue reward:1.0\n", - "step: 49, Red action: DONOTHING, Blue reward:1.0\n", - "step: 50, Red action: DONOTHING, Blue reward:1.0\n", - "step: 51, Red action: DONOTHING, Blue reward:1.0\n", - "step: 52, Red action: DONOTHING, Blue reward:1.0\n", - "step: 53, Red action: DONOTHING, Blue reward:1.0\n", - "step: 54, Red action: DONOTHING, Blue reward:1.0\n", - "step: 55, Red action: DONOTHING, Blue reward:1.0\n", - "step: 56, Red action: DONOTHING, Blue reward:1.0\n", - "step: 57, Red action: DONOTHING, Blue reward:1.0\n", - "step: 58, Red action: DONOTHING, Blue reward:1.0\n", - "step: 59, Red action: DONOTHING, Blue reward:1.0\n", - "step: 60, Red action: DONOTHING, Blue reward:1.0\n", - "step: 61, Red action: DONOTHING, Blue reward:1.0\n", - "step: 62, Red action: DONOTHING, Blue reward:1.0\n", - "step: 63, Red action: DONOTHING, Blue reward:1.0\n", - "step: 64, Red action: DONOTHING, Blue reward:1.0\n", - "step: 65, Red action: DONOTHING, Blue reward:1.0\n", - "step: 66, Red action: DONOTHING, Blue reward:1.0\n", - "step: 67, Red action: DONOTHING, Blue reward:1.0\n", - "step: 68, Red action: DONOTHING, Blue reward:1.0\n" - ] - } - ], + "outputs": [], "source": [ "env.step(13) # Patch the database\n", "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}, Blue reward:{reward}\" )\n", @@ -826,101 +522,14 @@ "Let's also have a look at the ACL observation to verify our new ACL rule at position 5." ] }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{1: {'position': 0,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 2: {'position': 1,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 3: {'position': 2,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 4: {'position': 3,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 5: {'position': 4,\n", - " 'permission': 2,\n", - " 'source_node_id': 7,\n", - " 'source_port': 1,\n", - " 'dest_node_id': 4,\n", - " 'dest_port': 1,\n", - " 'protocol': 3},\n", - " 6: {'position': 5,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 7: {'position': 6,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 8: {'position': 7,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 9: {'position': 8,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 10: {'position': 9,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0}}" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "obs['ACL']" - ] - }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "obs['ACL']" + ] } ], "metadata": { diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index a5738d76..bf778031 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -1,7 +1,9 @@ from ipaddress import IPv4Address -from typing import Dict, Optional +from typing import Dict, List, Literal, Optional, Union from urllib.parse import urlparse +from pydantic import BaseModel, ConfigDict + from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.network.protocols.http import ( @@ -33,6 +35,9 @@ class WebBrowser(Application): latest_response: Optional[HttpResponsePacket] = None """Keeps track of the latest HTTP response.""" + history: List["BrowserHistoryItem"] = [] + """Keep a log of visited websites and information about the visit, such as response code.""" + def __init__(self, **kwargs): kwargs["name"] = "WebBrowser" kwargs["protocol"] = IPProtocol.TCP @@ -71,7 +76,7 @@ class WebBrowser(Application): :return: A dictionary capturing the current state of the WebBrowser and its child objects. """ state = super().describe_state() - state["last_response_status_code"] = self.latest_response.status_code if self.latest_response else None + state["history"] = [hist_item.state() for hist_item in self.history] return state def reset_component_for_episode(self, episode: int): @@ -119,7 +124,8 @@ class WebBrowser(Application): # create HTTPRequest payload payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url=url) - # send request + # send request - As part of the self.send call, a response will be received and stored in the + # self.latest_response variable if self.send( payload=payload, dest_ip_address=self.domain_name_ip_address, @@ -129,9 +135,11 @@ class WebBrowser(Application): f"{self.name}: Received HTTP {payload.request_method.name} " f"Response {payload.request_url} - {self.latest_response.status_code.value}" ) + self.history.append(WebBrowser.BrowserHistoryItem(url=url, outcome=self.latest_response.status_code)) return self.latest_response.status_code is HttpStatusCode.OK else: self.sys_log.error(f"Error sending Http Packet {str(payload)}") + self.history.append(WebBrowser.BrowserHistoryItem(url=url, outcome="SERVER_UNREACHABLE")) return False def send( @@ -172,3 +180,23 @@ class WebBrowser(Application): self.sys_log.info(f"{self.name}: Received HTTP {payload.status_code.value}") self.latest_response = payload return True + + class BrowserHistoryItem(BaseModel): + """Simple representation of browser history, used for tracking success of web requests to calculate rewards.""" + + model_config = ConfigDict(extra="forbid") + """Error if incorrect specification.""" + + url: str + """The URL that was attempted to be fetched by the browser""" + + outcome: Union[HttpStatusCode, Literal["PENDING", "SERVER_UNREACHABLE"]] = "PENDING" + """HTTP response code that was received, or PENDING if a response was not yet received.""" + + def state(self) -> Dict: + """Return the contents of this dataclass as a dict for use with describe_state method.""" + if isinstance(self.outcome, HttpStatusCode): + outcome = self.outcome.value + else: + outcome = self.outcome + return {"url": self.url, "outcome": outcome} diff --git a/tests/integration_tests/system/test_web_client_server_and_database.py b/tests/integration_tests/system/test_web_client_server_and_database.py index a4ef3d52..bc6dc7e6 100644 --- a/tests/integration_tests/system/test_web_client_server_and_database.py +++ b/tests/integration_tests/system/test_web_client_server_and_database.py @@ -97,12 +97,48 @@ def web_client_web_server_database(example_network) -> Tuple[Computer, Server, S assert dns_client.check_domain_exists("arcd.com") assert db_client.connect() - return computer, web_server, db_server + return example_network, computer, web_server, db_server def test_web_client_requests_users(web_client_web_server_database): - computer, web_server, db_server = web_client_web_server_database + _, computer, _, _ = web_client_web_server_database web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser") assert web_browser.get_webpage() + + +class TestWebBrowserHistory: + def test_populating_history(self, web_client_web_server_database): + network, computer, _, _ = web_client_web_server_database + + web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser") + assert web_browser.history == [] + web_browser.get_webpage() + assert len(web_browser.history) == 1 + web_browser.get_webpage() + assert len(web_browser.history) == 2 + assert web_browser.history[-1].outcome == 200 + + router = network.get_node_by_hostname("router_1") + router.acl.add_rule(action=ACLAction.DENY, src_port=Port.HTTP, dst_port=Port.HTTP, position=0) + assert not web_browser.get_webpage() + assert len(web_browser.history) == 3 + assert web_browser.history[-1].outcome == 404 + + def test_history_in_state(self, web_client_web_server_database): + network, computer, _, _ = web_client_web_server_database + web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser") + + state = computer.describe_state() + assert "history" in state["applications"]["WebBrowser"] + assert len(state["applications"]["WebBrowser"]["history"]) == 0 + + web_browser.get_webpage() + router = network.get_node_by_hostname("router_1") + router.acl.add_rule(action=ACLAction.DENY, src_port=Port.HTTP, dst_port=Port.HTTP, position=0) + web_browser.get_webpage() + + state = computer.describe_state() + assert state["applications"]["WebBrowser"]["history"][0]["outcome"] == 200 + assert state["applications"]["WebBrowser"]["history"][1]["outcome"] == 404 From 41bc932f524a0e14456f2112bd7013d94e3c5330 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 6 Feb 2024 15:05:44 +0000 Subject: [PATCH 565/980] Add reward test. --- tests/conftest.py | 233 ++++++++++++++++++ .../game_layer/test_actions.py | 228 ----------------- .../game_layer/test_rewards.py | 37 +++ 3 files changed, 270 insertions(+), 228 deletions(-) create mode 100644 tests/integration_tests/game_layer/test_rewards.py diff --git a/tests/conftest.py b/tests/conftest.py index c37226a5..510a9df0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,6 +6,10 @@ import pytest import yaml from primaite import getLogger +from primaite.game.agent.actions import ActionManager +from primaite.game.agent.interface import AbstractAgent +from primaite.game.agent.observations import ICSObservation, ObservationManager +from primaite.game.agent.rewards import RewardFunction from primaite.game.game import PrimaiteGame from primaite.session.session import PrimaiteSession @@ -20,9 +24,14 @@ from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.network.networks import arcd_uc2_network from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.sim_container import Simulation from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.core.sys_log import SysLog +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.service import Service +from primaite.simulator.system.services.web_server.web_server import WebServer from tests.mock_and_patch.get_session_path_mock import temp_user_sessions_path ACTION_SPACE_NODE_VALUES = 1 @@ -237,3 +246,227 @@ def example_network() -> Network: router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) return network + + +class ControlledAgent(AbstractAgent): + """Agent that can be controlled by the tests.""" + + def __init__( + self, + agent_name: str, + action_space: ActionManager, + observation_space: ObservationManager, + reward_function: RewardFunction, + ) -> None: + super().__init__( + agent_name=agent_name, + action_space=action_space, + observation_space=observation_space, + reward_function=reward_function, + ) + self.most_recent_action: Tuple[str, Dict] + + def get_action(self, obs: None, reward: float = 0.0) -> Tuple[str, Dict]: + """Return the agent's most recent action, formatted in CAOS format.""" + return self.most_recent_action + + def store_action(self, action: Tuple[str, Dict]): + """Store the most recent action.""" + self.most_recent_action = action + + +def install_stuff_to_sim(sim: Simulation): + """Create a simulation with a computer, two servers, two switches, and a router.""" + + # 0: Pull out the network + network = sim.network + + # 1: Set up network hardware + # 1.1: Configure the router + router = Router(hostname="router", num_ports=3, operating_state=NodeOperatingState.ON) + router.power_on() + router.configure_port(port=1, ip_address="10.0.1.1", subnet_mask="255.255.255.0") + router.configure_port(port=2, ip_address="10.0.2.1", subnet_mask="255.255.255.0") + + # 1.2: Create and connect switches + switch_1 = Switch(hostname="switch_1", num_ports=6, operating_state=NodeOperatingState.ON) + switch_1.power_on() + network.connect(endpoint_a=router.ethernet_ports[1], endpoint_b=switch_1.switch_ports[6]) + router.enable_port(1) + switch_2 = Switch(hostname="switch_2", num_ports=6, operating_state=NodeOperatingState.ON) + switch_2.power_on() + network.connect(endpoint_a=router.ethernet_ports[2], endpoint_b=switch_2.switch_ports[6]) + router.enable_port(2) + + # 1.3: Create and connect computer + client_1 = Computer( + hostname="client_1", + ip_address="10.0.1.2", + subnet_mask="255.255.255.0", + default_gateway="10.0.1.1", + operating_state=NodeOperatingState.ON, + ) + client_1.power_on() + network.connect( + endpoint_a=client_1.ethernet_port[1], + endpoint_b=switch_1.switch_ports[1], + ) + + # 1.4: Create and connect servers + server_1 = Server( + hostname="server_1", + ip_address="10.0.2.2", + subnet_mask="255.255.255.0", + default_gateway="10.0.2.1", + operating_state=NodeOperatingState.ON, + ) + server_1.power_on() + network.connect(endpoint_a=server_1.ethernet_port[1], endpoint_b=switch_2.switch_ports[1]) + + server_2 = Server( + hostname="server_2", + ip_address="10.0.2.3", + subnet_mask="255.255.255.0", + default_gateway="10.0.2.1", + operating_state=NodeOperatingState.ON, + ) + server_2.power_on() + network.connect(endpoint_a=server_2.ethernet_port[1], endpoint_b=switch_2.switch_ports[2]) + + # 2: Configure base ACL + router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) + router.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.DNS, dst_port=Port.DNS, position=1) + router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.HTTP, dst_port=Port.HTTP, position=3) + + # 3: Install server software + server_1.software_manager.install(DNSServer) + dns_service: DNSServer = server_1.software_manager.software.get("DNSServer") # noqa + dns_service.dns_register("www.example.com", server_2.ip_address) + server_2.software_manager.install(WebServer) + + # 3.1: Ensure that the dns clients are configured correctly + client_1.software_manager.software.get("DNSClient").dns_server = server_1.ethernet_port[1].ip_address + server_2.software_manager.software.get("DNSClient").dns_server = server_1.ethernet_port[1].ip_address + + # 4: Check that client came pre-installed with web browser and dns client + assert isinstance(client_1.software_manager.software.get("WebBrowser"), WebBrowser) + assert isinstance(client_1.software_manager.software.get("DNSClient"), DNSClient) + + # 4.1: Create a file on the computer + client_1.file_system.create_file("cat.png", 300, folder_name="downloads") + + # 5: Assert that the simulation starts off in the state that we expect + assert len(sim.network.nodes) == 6 + assert len(sim.network.links) == 5 + # 5.1: Assert the router is correctly configured + r = sim.network.routers[0] + for i, acl_rule in enumerate(r.acl.acl): + if i == 1: + assert acl_rule.src_port == acl_rule.dst_port == Port.DNS + elif i == 3: + assert acl_rule.src_port == acl_rule.dst_port == Port.HTTP + elif i == 22: + assert acl_rule.src_port == acl_rule.dst_port == Port.ARP + elif i == 23: + assert acl_rule.protocol == IPProtocol.ICMP + elif i == 24: + ... + else: + assert acl_rule is None + + # 5.2: Assert the client is correctly configured + c: Computer = [node for node in sim.network.nodes.values() if node.hostname == "client_1"][0] + assert c.software_manager.software.get("WebBrowser") is not None + assert c.software_manager.software.get("DNSClient") is not None + assert str(c.ethernet_port[1].ip_address) == "10.0.1.2" + + # 5.3: Assert that server_1 is correctly configured + s1: Server = [node for node in sim.network.nodes.values() if node.hostname == "server_1"][0] + assert str(s1.ethernet_port[1].ip_address) == "10.0.2.2" + assert s1.software_manager.software.get("DNSServer") is not None + + # 5.4: Assert that server_2 is correctly configured + s2: Server = [node for node in sim.network.nodes.values() if node.hostname == "server_2"][0] + assert str(s2.ethernet_port[1].ip_address) == "10.0.2.3" + assert s2.software_manager.software.get("WebServer") is not None + + # 6: Return the simulation + return sim + + +@pytest.fixture +def game_and_agent(): + """Create a game with a simple agent that can be controlled by the tests.""" + game = PrimaiteGame() + sim = game.simulation + install_stuff_to_sim(sim) + + actions = [ + {"type": "DONOTHING"}, + {"type": "NODE_SERVICE_SCAN"}, + {"type": "NODE_SERVICE_STOP"}, + {"type": "NODE_SERVICE_START"}, + {"type": "NODE_SERVICE_PAUSE"}, + {"type": "NODE_SERVICE_RESUME"}, + {"type": "NODE_SERVICE_RESTART"}, + {"type": "NODE_SERVICE_DISABLE"}, + {"type": "NODE_SERVICE_ENABLE"}, + {"type": "NODE_SERVICE_PATCH"}, + {"type": "NODE_APPLICATION_EXECUTE"}, + {"type": "NODE_FILE_SCAN"}, + {"type": "NODE_FILE_CHECKHASH"}, + {"type": "NODE_FILE_DELETE"}, + {"type": "NODE_FILE_REPAIR"}, + {"type": "NODE_FILE_RESTORE"}, + {"type": "NODE_FILE_CORRUPT"}, + {"type": "NODE_FOLDER_SCAN"}, + {"type": "NODE_FOLDER_CHECKHASH"}, + {"type": "NODE_FOLDER_REPAIR"}, + {"type": "NODE_FOLDER_RESTORE"}, + {"type": "NODE_OS_SCAN"}, + {"type": "NODE_SHUTDOWN"}, + {"type": "NODE_STARTUP"}, + {"type": "NODE_RESET"}, + {"type": "NETWORK_ACL_ADDRULE", "options": {"target_router_hostname": "router"}}, + {"type": "NETWORK_ACL_REMOVERULE", "options": {"target_router_hostname": "router"}}, + {"type": "NETWORK_NIC_ENABLE"}, + {"type": "NETWORK_NIC_DISABLE"}, + ] + + action_space = ActionManager( + game=game, + actions=actions, # ALL POSSIBLE ACTIONS + nodes=[ + { + "node_name": "client_1", + "applications": [{"application_name": "WebBrowser"}], + "folders": [{"folder_name": "downloads", "files": [{"file_name": "cat.png"}]}], + }, + {"node_name": "server_1", "services": [{"service_name": "DNSServer"}]}, + {"node_name": "server_2", "services": [{"service_name": "WebServer"}]}, + ], + max_folders_per_node=2, + max_files_per_folder=2, + max_services_per_node=2, + max_applications_per_node=2, + max_nics_per_node=2, + max_acl_rules=10, + protocols=["TCP", "UDP", "ICMP"], + ports=["HTTP", "DNS", "ARP"], + ip_address_list=["10.0.1.1", "10.0.1.2", "10.0.2.1", "10.0.2.2", "10.0.2.3"], + act_map={}, + ) + observation_space = ObservationManager(ICSObservation()) + reward_function = RewardFunction() + + test_agent = ControlledAgent( + agent_name="test_agent", + action_space=action_space, + observation_space=observation_space, + reward_function=reward_function, + ) + + game.agents.append(test_agent) + + return (game, test_agent) diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index e771dbd2..c5e09195 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -35,234 +35,6 @@ from primaite.simulator.system.services.web_server.web_server import WebServer from primaite.simulator.system.software import SoftwareHealthState -class ControlledAgent(AbstractAgent): - """Agent that can be controlled by the tests.""" - - def __init__( - self, - agent_name: str, - action_space: ActionManager, - observation_space: ObservationManager, - reward_function: RewardFunction, - ) -> None: - super().__init__( - agent_name=agent_name, - action_space=action_space, - observation_space=observation_space, - reward_function=reward_function, - ) - self.most_recent_action: Tuple[str, Dict] - - def get_action(self, obs: None, reward: float = 0.0) -> Tuple[str, Dict]: - """Return the agent's most recent action, formatted in CAOS format.""" - return self.most_recent_action - - def store_action(self, action: Tuple[str, Dict]): - """Store the most recent action.""" - self.most_recent_action = action - - -def install_stuff_to_sim(sim: Simulation): - """Create a simulation with a computer, two servers, two switches, and a router.""" - - # 0: Pull out the network - network = sim.network - - # 1: Set up network hardware - # 1.1: Configure the router - router = Router(hostname="router", num_ports=3, operating_state=NodeOperatingState.ON) - router.power_on() - router.configure_port(port=1, ip_address="10.0.1.1", subnet_mask="255.255.255.0") - router.configure_port(port=2, ip_address="10.0.2.1", subnet_mask="255.255.255.0") - - # 1.2: Create and connect switches - switch_1 = Switch(hostname="switch_1", num_ports=6, operating_state=NodeOperatingState.ON) - switch_1.power_on() - network.connect(endpoint_a=router.ethernet_ports[1], endpoint_b=switch_1.switch_ports[6]) - router.enable_port(1) - switch_2 = Switch(hostname="switch_2", num_ports=6, operating_state=NodeOperatingState.ON) - switch_2.power_on() - network.connect(endpoint_a=router.ethernet_ports[2], endpoint_b=switch_2.switch_ports[6]) - router.enable_port(2) - - # 1.3: Create and connect computer - client_1 = Computer( - hostname="client_1", - ip_address="10.0.1.2", - subnet_mask="255.255.255.0", - default_gateway="10.0.1.1", - operating_state=NodeOperatingState.ON, - ) - client_1.power_on() - network.connect( - endpoint_a=client_1.ethernet_port[1], - endpoint_b=switch_1.switch_ports[1], - ) - - # 1.4: Create and connect servers - server_1 = Server( - hostname="server_1", - ip_address="10.0.2.2", - subnet_mask="255.255.255.0", - default_gateway="10.0.2.1", - operating_state=NodeOperatingState.ON, - ) - server_1.power_on() - network.connect(endpoint_a=server_1.ethernet_port[1], endpoint_b=switch_2.switch_ports[1]) - - server_2 = Server( - hostname="server_2", - ip_address="10.0.2.3", - subnet_mask="255.255.255.0", - default_gateway="10.0.2.1", - operating_state=NodeOperatingState.ON, - ) - server_2.power_on() - network.connect(endpoint_a=server_2.ethernet_port[1], endpoint_b=switch_2.switch_ports[2]) - - # 2: Configure base ACL - router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) - router.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) - router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.DNS, dst_port=Port.DNS, position=1) - router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.HTTP, dst_port=Port.HTTP, position=3) - - # 3: Install server software - server_1.software_manager.install(DNSServer) - dns_service: DNSServer = server_1.software_manager.software.get("DNSServer") # noqa - dns_service.dns_register("www.example.com", server_2.ip_address) - server_2.software_manager.install(WebServer) - - # 3.1: Ensure that the dns clients are configured correctly - client_1.software_manager.software.get("DNSClient").dns_server = server_1.ethernet_port[1].ip_address - server_2.software_manager.software.get("DNSClient").dns_server = server_1.ethernet_port[1].ip_address - - # 4: Check that client came pre-installed with web browser and dns client - assert isinstance(client_1.software_manager.software.get("WebBrowser"), WebBrowser) - assert isinstance(client_1.software_manager.software.get("DNSClient"), DNSClient) - - # 4.1: Create a file on the computer - client_1.file_system.create_file("cat.png", 300, folder_name="downloads") - - # 5: Assert that the simulation starts off in the state that we expect - assert len(sim.network.nodes) == 6 - assert len(sim.network.links) == 5 - # 5.1: Assert the router is correctly configured - r = sim.network.routers[0] - for i, acl_rule in enumerate(r.acl.acl): - if i == 1: - assert acl_rule.src_port == acl_rule.dst_port == Port.DNS - elif i == 3: - assert acl_rule.src_port == acl_rule.dst_port == Port.HTTP - elif i == 22: - assert acl_rule.src_port == acl_rule.dst_port == Port.ARP - elif i == 23: - assert acl_rule.protocol == IPProtocol.ICMP - elif i == 24: - ... - else: - assert acl_rule is None - - # 5.2: Assert the client is correctly configured - c: Computer = [node for node in sim.network.nodes.values() if node.hostname == "client_1"][0] - assert c.software_manager.software.get("WebBrowser") is not None - assert c.software_manager.software.get("DNSClient") is not None - assert str(c.ethernet_port[1].ip_address) == "10.0.1.2" - - # 5.3: Assert that server_1 is correctly configured - s1: Server = [node for node in sim.network.nodes.values() if node.hostname == "server_1"][0] - assert str(s1.ethernet_port[1].ip_address) == "10.0.2.2" - assert s1.software_manager.software.get("DNSServer") is not None - - # 5.4: Assert that server_2 is correctly configured - s2: Server = [node for node in sim.network.nodes.values() if node.hostname == "server_2"][0] - assert str(s2.ethernet_port[1].ip_address) == "10.0.2.3" - assert s2.software_manager.software.get("WebServer") is not None - - # 6: Return the simulation - return sim - - -@pytest.fixture -def game_and_agent(): - """Create a game with a simple agent that can be controlled by the tests.""" - game = PrimaiteGame() - sim = game.simulation - install_stuff_to_sim(sim) - - actions = [ - {"type": "DONOTHING"}, - {"type": "NODE_SERVICE_SCAN"}, - {"type": "NODE_SERVICE_STOP"}, - {"type": "NODE_SERVICE_START"}, - {"type": "NODE_SERVICE_PAUSE"}, - {"type": "NODE_SERVICE_RESUME"}, - {"type": "NODE_SERVICE_RESTART"}, - {"type": "NODE_SERVICE_DISABLE"}, - {"type": "NODE_SERVICE_ENABLE"}, - {"type": "NODE_SERVICE_PATCH"}, - {"type": "NODE_APPLICATION_EXECUTE"}, - {"type": "NODE_FILE_SCAN"}, - {"type": "NODE_FILE_CHECKHASH"}, - {"type": "NODE_FILE_DELETE"}, - {"type": "NODE_FILE_REPAIR"}, - {"type": "NODE_FILE_RESTORE"}, - {"type": "NODE_FILE_CORRUPT"}, - {"type": "NODE_FOLDER_SCAN"}, - {"type": "NODE_FOLDER_CHECKHASH"}, - {"type": "NODE_FOLDER_REPAIR"}, - {"type": "NODE_FOLDER_RESTORE"}, - {"type": "NODE_OS_SCAN"}, - {"type": "NODE_SHUTDOWN"}, - {"type": "NODE_STARTUP"}, - {"type": "NODE_RESET"}, - {"type": "NETWORK_ACL_ADDRULE", "options": {"target_router_hostname": "router"}}, - {"type": "NETWORK_ACL_REMOVERULE", "options": {"target_router_hostname": "router"}}, - {"type": "NETWORK_NIC_ENABLE"}, - {"type": "NETWORK_NIC_DISABLE"}, - ] - - action_space = ActionManager( - game=game, - actions=actions, # ALL POSSIBLE ACTIONS - nodes=[ - { - "node_name": "client_1", - "applications": [{"application_name": "WebBrowser"}], - "folders": [{"folder_name": "downloads", "files": [{"file_name": "cat.png"}]}], - }, - {"node_name": "server_1", "services": [{"service_name": "DNSServer"}]}, - {"node_name": "server_2", "services": [{"service_name": "WebServer"}]}, - ], - max_folders_per_node=2, - max_files_per_folder=2, - max_services_per_node=2, - max_applications_per_node=2, - max_nics_per_node=2, - max_acl_rules=10, - protocols=["TCP", "UDP", "ICMP"], - ports=["HTTP", "DNS", "ARP"], - ip_address_list=["10.0.1.1", "10.0.1.2", "10.0.2.1", "10.0.2.2", "10.0.2.3"], - act_map={}, - ) - observation_space = ObservationManager(ICSObservation()) - reward_function = RewardFunction() - - test_agent = ControlledAgent( - agent_name="test_agent", - action_space=action_space, - observation_space=observation_space, - reward_function=reward_function, - ) - - game.agents.append(test_agent) - - return (game, test_agent) - - -# def test_test(game_and_agent:Tuple[PrimaiteGame, ProxyAgent]): -# game, agent = game_and_agent - - def test_do_nothing_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): """Test that the DoNothingAction can form a request and that it is accepted by the simulation.""" game, agent = game_and_agent diff --git a/tests/integration_tests/game_layer/test_rewards.py b/tests/integration_tests/game_layer/test_rewards.py new file mode 100644 index 00000000..c084512f --- /dev/null +++ b/tests/integration_tests/game_layer/test_rewards.py @@ -0,0 +1,37 @@ +from primaite.game.agent.rewards import RewardFunction, WebpageUnavailablePenalty +from primaite.simulator.network.hardware.nodes.router import ACLAction, Router +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from tests.conftest import ControlledAgent + + +def test_WebpageUnavailablePenalty(game_and_agent): + """Test that we get the right reward for failing to fetch a website.""" + game, agent = game_and_agent + agent: ControlledAgent + comp = WebpageUnavailablePenalty(node_hostname="client_1") + + agent.reward_function.register_component(comp, 0.7) + action = ("DONOTHING", {}) + agent.store_action(action) + game.step() + + # client 1 has not attempted to fetch webpage yet! + assert agent.reward_function.current_reward == 0.0 + + client_1 = game.simulation.network.get_node_by_hostname("client_1") + browser = client_1.software_manager.software.get("WebBrowser") + browser.run() + browser.target_url = "http://www.example.com" + assert browser.get_webpage() + action = ("DONOTHING", {}) + agent.store_action(action) + game.step() + assert agent.reward_function.current_reward == 0.7 + + router: Router = game.simulation.network.get_node_by_hostname("router") + router.acl.add_rule(action=ACLAction.DENY, protocol=IPProtocol.TCP, src_port=Port.HTTP, dst_port=Port.HTTP) + assert not browser.get_webpage() + agent.store_action(action) + game.step() + assert agent.reward_function.current_reward == -0.7 From e500eccaf7846acdc20f875029ed8a5b8c6aa478 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 6 Feb 2024 16:58:08 +0000 Subject: [PATCH 566/980] Finish upgrading folder actions to work with names instead of uuids & get tests fixed --- .../simulator/file_system/file_system.py | 48 ++++++++++--------- src/primaite/simulator/file_system/folder.py | 24 ++++++---- .../services/database/database_service.py | 4 ++ .../_file_system/test_file_actions.py | 8 ++-- .../_file_system/test_file_system_actions.py | 4 +- .../_file_system/test_folder_actions.py | 8 ++-- 6 files changed, 53 insertions(+), 43 deletions(-) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 2ab3b005..ee80587d 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -94,12 +94,12 @@ class FileSystem(SimComponent): self._restore_manager.add_request( name="file", request_type=RequestType( - func=lambda request, context: self.restore_file(folder_uuid=request[0], file_uuid=request[1]) + func=lambda request, context: self.restore_file(folder_name=request[0], file_name=request[1]) ), ) self._restore_manager.add_request( name="folder", - request_type=RequestType(func=lambda request, context: self.restore_folder(folder_uuid=request[0])), + request_type=RequestType(func=lambda request, context: self.restore_folder(folder_name=request[0])), ) rm.add_request( name="restore", @@ -209,7 +209,7 @@ class FileSystem(SimComponent): folder = self.get_folder_by_id(folder_uuid=folder_uuid) self.delete_folder(folder_name=folder.name) - def get_folder(self, folder_name: str) -> Optional[Folder]: + def get_folder(self, folder_name: str, include_deleted: bool = False) -> Optional[Folder]: """ Get a folder by its name if it exists. @@ -219,9 +219,13 @@ class FileSystem(SimComponent): for folder in self.folders.values(): if folder.name == folder_name: return folder + if include_deleted: + for folder in self.deleted_folders.values(): + if folder.name == folder_name: + return folder return None - def get_folder_by_id(self, folder_uuid: str, include_deleted: bool = False) -> Optional[Folder]: + def get_folder_by_id(self, folder_uuid: str, include_deleted: Optional[bool] = False) -> Optional[Folder]: """ Get a folder by its uuid if it exists. @@ -283,7 +287,7 @@ class FileSystem(SimComponent): self._file_request_manager.add_request(name=file.name, request_type=RequestType(func=file._request_manager)) return file - def get_file(self, folder_name: str, file_name: str) -> Optional[File]: + def get_file(self, folder_name: str, file_name: str, include_deleted: Optional[bool] = False) -> Optional[File]: """ Retrieve a file by its name from a specific folder. @@ -291,9 +295,9 @@ class FileSystem(SimComponent): :param file_name: The name of the file to be retrieved, including its extension. :return: An instance of File if it exists, otherwise `None`. """ - folder = self.get_folder(folder_name) + folder = self.get_folder(folder_name, include_deleted=include_deleted) if folder: - return folder.get_file(file_name) + return folder.get_file(file_name, include_deleted=include_deleted) self.sys_log.info(f"File not found /{folder_name}/{file_name}") def get_file_by_id( @@ -455,46 +459,44 @@ class FileSystem(SimComponent): for folder_id in self.folders: self.folders[folder_id].reveal_to_red(instant_scan=instant_scan) - def restore_folder(self, folder_uuid: str): + def restore_folder(self, folder_name: str): """ Restore a folder. Checks the current folder's status and applies the correct fix for the folder. - :param: folder_uuid: id of the folder to restore + :param: folder_name: name of the folder to restore :type: folder_uuid: str """ - folder = self.get_folder_by_id(folder_uuid=folder_uuid, include_deleted=True) + folder = self.get_folder(folder_name=folder_name, include_deleted=True) if folder is None: - self.sys_log.error(f"Unable to restore folder with uuid {folder_uuid}. Folder does not exist.") + self.sys_log.error(f"Unable to restore folder {folder_name}. Folder is not in deleted folder list.") return + self.deleted_folders.pop(folder.uuid, None) folder.restore() self.folders[folder.uuid] = folder - if folder.deleted: - self.deleted_folders.pop(folder.uuid) - - def restore_file(self, folder_uuid: str, file_uuid: str): + def restore_file(self, folder_name: str, file_name: str): """ Restore a file. Checks the current file's status and applies the correct fix for the file. - :param: folder_uuid: id of the folder where the file is stored - :type: folder_uuid: str + :param: folder_name: name of the folder where the file is stored + :type: folder_name: str - :param: file_uuid: id of the file to restore - :type: file_uuid: str + :param: file_name: name of the file to restore + :type: file_name: str """ - folder = self.get_folder_by_id(folder_uuid=folder_uuid, include_deleted=True) + folder = self.get_folder(folder_name=folder_name) if folder: - file = folder.get_file_by_id(file_uuid=file_uuid, include_deleted=True) + file = folder.get_file(file_name=file_name, include_deleted=True) if file is None: - self.sys_log.error(f"Unable to restore file with uuid {file_uuid}. File does not exist.") + self.sys_log.error(f"Unable to restore file {file_name}. File does not exist.") return - folder.restore_file(file_uuid=file_uuid) + folder.restore_file(file_name=file_name) diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index a93b2927..13fdc597 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -193,19 +193,19 @@ class Folder(FileSystemItemABC): if self.restore_countdown == 0: # repair all files - for file_id in self.files: - self.restore_file(file_uuid=file_id) + for file_id, file in self.files.items(): + self.restore_file(file_name=file.name) deleted_files = self.deleted_files.copy() - for file_id in deleted_files: - self.restore_file(file_uuid=file_id) + for file_id, file in deleted_files.items(): + self.restore_file(file_name=file.name) if self.deleted: self.deleted = False elif self.health_status in [FileSystemItemHealthStatus.CORRUPT, FileSystemItemHealthStatus.RESTORING]: self.health_status = FileSystemItemHealthStatus.GOOD - def get_file(self, file_name: str) -> Optional[File]: + def get_file(self, file_name: str, include_deleted: Optional[bool] = False) -> Optional[File]: """ Get a file by its name. @@ -218,6 +218,10 @@ class Folder(FileSystemItemABC): for file in self.files.values(): if file.name == file_name: return file + if include_deleted: + for file in self.deleted_files.values(): + if file.name == file_name: + return file return None def get_file_by_id(self, file_uuid: str, include_deleted: Optional[bool] = False) -> File: @@ -297,23 +301,23 @@ class Folder(FileSystemItemABC): self.files = {} - def restore_file(self, file_uuid: str): + def restore_file(self, file_name: str): """ Restores a file. - :param file_uuid: The id of the file to restore + :param file_name: The name of the file to restore """ # if the file was not deleted, run a repair - file = self.get_file_by_id(file_uuid=file_uuid, include_deleted=True) + file = self.get_file(file_name=file_name, include_deleted=True) if not file: - self.sys_log.error(f"Unable to restore file with uuid {file_uuid}. File does not exist.") + self.sys_log.error(f"Unable to restore file {file_name}. File does not exist.") return file.restore() self.files[file.uuid] = file if file.deleted: - self.deleted_files.pop(file_uuid) + self.deleted_files.pop(file.uuid) def quarantine(self): """Quarantines the File System Folder.""" diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index c9c4d6fa..d75b4424 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -203,6 +203,10 @@ class DatabaseService(Service): """ self.sys_log.info(f"{self.name}: Running {query}") + if not self.db_file: + self.sys_log.info(f"{self.name}: Failed to run {query} because the database file is missing.") + return {"status_code": 404, "data": False} + if query == "SELECT": if self.db_file.health_status == FileSystemItemHealthStatus.GOOD: return { diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py index f43652d8..658b1b09 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_actions.py @@ -61,18 +61,18 @@ def test_file_restore_request(populated_file_system): fs, folder, file = populated_file_system assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid) is not None - fs.apply_request(request=["delete", "file", folder.uuid, file.uuid]) + fs.apply_request(request=["delete", "file", folder.name, file.name]) assert fs.get_file(folder_name=folder.name, file_name=file.name) is None assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is True - fs.apply_request(request=["restore", "file", folder.uuid, file.uuid]) + fs.apply_request(request=["restore", "file", folder.name, file.name]) assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None assert fs.get_file(folder_name=folder.name, file_name=file.name).deleted is False fs.apply_request(request=["file", file.name, "corrupt"]) assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT - fs.apply_request(request=["restore", "file", folder.uuid, file.uuid]) + fs.apply_request(request=["restore", "file", folder.name, file.name]) assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.GOOD @@ -95,7 +95,7 @@ def test_deleted_file_cannot_be_interacted_with(populated_file_system): == FileSystemItemHealthStatus.GOOD ) - fs.apply_request(request=["delete", "file", folder.uuid, file.uuid]) + fs.apply_request(request=["delete", "file", folder.name, file.name]) assert fs.get_file(folder_name=folder.name, file_name=file.name) is None fs.apply_request(request=["file", file.name, "repair"]) diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py index 1c8513f9..62af93c4 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system_actions.py @@ -21,7 +21,7 @@ def test_file_delete_request(populated_file_system): fs, folder, file = populated_file_system assert fs.get_file(folder_name=folder.name, file_name=file.name) is not None - fs.apply_request(request=["delete", "file", folder.uuid, file.uuid]) + fs.apply_request(request=["delete", "file", folder.name, file.name]) assert fs.get_file(folder_name=folder.name, file_name=file.name) is None fs.show(full=True) @@ -33,7 +33,7 @@ def test_folder_delete_request(populated_file_system): assert folder.get_file_by_id(file_uuid=file.uuid) is not None assert fs.get_folder_by_id(folder_uuid=folder.uuid) is not None - fs.apply_request(request=["delete", "folder", folder.uuid]) + fs.apply_request(request=["delete", "folder", folder.name]) assert fs.get_folder_by_id(folder_uuid=folder.uuid) is None assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid) is None diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py index 398af0cc..6e904f2a 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_folder_actions.py @@ -82,7 +82,7 @@ def test_folder_restore_request(populated_file_system): assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid) is not None # delete folder - fs.apply_request(request=["delete", "folder", folder.uuid]) + fs.apply_request(request=["delete", "folder", folder.name]) assert fs.get_folder(folder_name=folder.name) is None assert fs.get_folder_by_id(folder_uuid=folder.uuid, include_deleted=True).deleted is True @@ -90,7 +90,7 @@ def test_folder_restore_request(populated_file_system): assert fs.get_file_by_id(folder_uuid=folder.uuid, file_uuid=file.uuid, include_deleted=True).deleted is True # restore folder - fs.apply_request(request=["restore", "folder", folder.uuid]) + fs.apply_request(request=["restore", "folder", folder.name]) fs.apply_timestep(timestep=0) assert fs.get_folder(folder_name=folder.name) is not None assert ( @@ -121,7 +121,7 @@ def test_folder_restore_request(populated_file_system): assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT # restore folder - fs.apply_request(request=["restore", "folder", folder.uuid]) + fs.apply_request(request=["restore", "folder", folder.name]) fs.apply_timestep(timestep=0) assert fs.get_folder(folder_name=folder.name).health_status == FileSystemItemHealthStatus.RESTORING assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT @@ -156,7 +156,7 @@ def test_deleted_folder_and_its_files_cannot_be_interacted_with(populated_file_s fs.apply_request(request=["file", file.name, "corrupt"]) assert fs.get_file(folder_name=folder.name, file_name=file.name).health_status == FileSystemItemHealthStatus.CORRUPT - fs.apply_request(request=["delete", "folder", folder.uuid]) + fs.apply_request(request=["delete", "folder", folder.name]) assert fs.get_file(folder_name=folder.name, file_name=file.name) is None fs.apply_request(request=["file", file.name, "repair"]) From c35c060448083d9678fad4c60e0526cb14f09c85 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 6 Feb 2024 17:32:15 +0000 Subject: [PATCH 567/980] Cosmetic changes based on PR feedback --- src/primaite/game/game.py | 8 ++--- src/primaite/notebooks/uc2_demo.ipynb | 4 +-- .../system/applications/web_browser.py | 33 +++++++++++++++---- .../test_web_client_server_and_database.py | 11 +++++-- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 8ecb365e..a2c4e86d 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -345,7 +345,7 @@ class PrimaiteGame: action_space = ActionManager.from_config(game, action_space_cfg) # CREATE REWARD FUNCTION - rew_function = RewardFunction.from_config(reward_function_cfg) + reward_function = RewardFunction.from_config(reward_function_cfg) # OTHER AGENT SETTINGS agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) @@ -357,7 +357,7 @@ class PrimaiteGame: agent_name=agent_cfg["ref"], action_space=action_space, observation_space=obs_space, - reward_function=rew_function, + reward_function=reward_function, agent_settings=agent_settings, ) game.agents.append(new_agent) @@ -366,7 +366,7 @@ class PrimaiteGame: agent_name=agent_cfg["ref"], action_space=action_space, observation_space=obs_space, - reward_function=rew_function, + reward_function=reward_function, agent_settings=agent_settings, ) game.agents.append(new_agent) @@ -376,7 +376,7 @@ class PrimaiteGame: agent_name=agent_cfg["ref"], action_space=action_space, observation_space=obs_space, - reward_function=rew_function, + reward_function=reward_function, agent_settings=agent_settings, ) game.agents.append(new_agent) diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index 4e2e5e30..7454b6c4 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -46,7 +46,7 @@ "source": [ "## Green agent\n", "\n", - "There are green agents is logged onto client 1 and client 2. They use the web browser to navigate to `http://arcd.com/users`. The web server replies with a status code 200 if the data is available on the database or 404 if not available." + "There are green agents logged onto client 1 and client 2. They use the web browser to navigate to `http://arcd.com/users`. The web server replies with a status code 200 if the data is available on the database or 404 if not available." ] }, { @@ -68,7 +68,7 @@ "source": [ "## Blue agent\n", "\n", - "The blue agent can view the entire network, but the health statuses of components are not updated until a scan is performed. The blue agent should restore the database file from backup after it was compromised. It can also prevent further attacks by blocking client 1 from sending the malicious SQL query to the database server. This can be done by removing implementing an ACL rule on the router." + "The blue agent can view the entire network, but the health statuses of components are not updated until a scan is performed. The blue agent should restore the database file from backup after it was compromised. It can also prevent further attacks by blocking client 1 from sending the malicious SQL query to the database server. This can be done by implementing an ACL rule on the router." ] }, { diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index bf778031..eef0ed5d 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -1,5 +1,6 @@ +from enum import Enum from ipaddress import IPv4Address -from typing import Dict, List, Literal, Optional, Union +from typing import Dict, List, Optional from urllib.parse import urlparse from pydantic import BaseModel, ConfigDict @@ -135,11 +136,21 @@ class WebBrowser(Application): f"{self.name}: Received HTTP {payload.request_method.name} " f"Response {payload.request_url} - {self.latest_response.status_code.value}" ) - self.history.append(WebBrowser.BrowserHistoryItem(url=url, outcome=self.latest_response.status_code)) + self.history.append( + WebBrowser.BrowserHistoryItem( + url=url, + status=self.BrowserHistoryItem._HistoryItemStatus.LOADED, + response_code=self.latest_response.status_code, + ) + ) return self.latest_response.status_code is HttpStatusCode.OK else: self.sys_log.error(f"Error sending Http Packet {str(payload)}") - self.history.append(WebBrowser.BrowserHistoryItem(url=url, outcome="SERVER_UNREACHABLE")) + self.history.append( + WebBrowser.BrowserHistoryItem( + url=url, status=self.BrowserHistoryItem._HistoryItemStatus.SERVER_UNREACHABLE + ) + ) return False def send( @@ -190,13 +201,21 @@ class WebBrowser(Application): url: str """The URL that was attempted to be fetched by the browser""" - outcome: Union[HttpStatusCode, Literal["PENDING", "SERVER_UNREACHABLE"]] = "PENDING" + class _HistoryItemStatus(Enum): + NOT_SENT = "NOT_SENT" + PENDING = "PENDING" + SERVER_UNREACHABLE = "SERVER_UNREACHABLE" + LOADED = "LOADED" + + status: _HistoryItemStatus = _HistoryItemStatus.PENDING + + response_code: Optional[HttpStatusCode] = None """HTTP response code that was received, or PENDING if a response was not yet received.""" def state(self) -> Dict: """Return the contents of this dataclass as a dict for use with describe_state method.""" - if isinstance(self.outcome, HttpStatusCode): - outcome = self.outcome.value + if self.status == self._HistoryItemStatus.LOADED: + outcome = self.response_code else: - outcome = self.outcome + outcome = self.status.value return {"url": self.url, "outcome": outcome} diff --git a/tests/integration_tests/system/test_web_client_server_and_database.py b/tests/integration_tests/system/test_web_client_server_and_database.py index bc6dc7e6..2cf43cbd 100644 --- a/tests/integration_tests/system/test_web_client_server_and_database.py +++ b/tests/integration_tests/system/test_web_client_server_and_database.py @@ -3,6 +3,7 @@ from typing import Tuple import pytest +from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.base import Link from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.computer import Computer @@ -18,7 +19,7 @@ from primaite.simulator.system.services.web_server.web_server import WebServer @pytest.fixture(scope="function") -def web_client_web_server_database(example_network) -> Tuple[Computer, Server, Server]: +def web_client_web_server_database(example_network) -> Tuple[Network, Computer, Server, Server]: # add rules to network router router_1: Router = example_network.get_node_by_hostname("router_1") router_1.acl.add_rule( @@ -118,13 +119,17 @@ class TestWebBrowserHistory: assert len(web_browser.history) == 1 web_browser.get_webpage() assert len(web_browser.history) == 2 - assert web_browser.history[-1].outcome == 200 + assert web_browser.history[-1].status == WebBrowser.BrowserHistoryItem._HistoryItemStatus.LOADED + assert web_browser.history[-1].response_code == 200 router = network.get_node_by_hostname("router_1") router.acl.add_rule(action=ACLAction.DENY, src_port=Port.HTTP, dst_port=Port.HTTP, position=0) assert not web_browser.get_webpage() assert len(web_browser.history) == 3 - assert web_browser.history[-1].outcome == 404 + # with current NIC behaviour, even if you block communication, you won't get SERVER_UNREACHABLE because + # application.send always returns true, even if communication fails. we should change what is returned from NICs + assert web_browser.history[-1].status == WebBrowser.BrowserHistoryItem._HistoryItemStatus.LOADED + assert web_browser.history[-1].response_code == 404 def test_history_in_state(self, web_client_web_server_database): network, computer, _, _ = web_client_web_server_database From b7ff520d557f05dcaabb378449d3760a7e87a6c6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 6 Feb 2024 18:58:50 +0000 Subject: [PATCH 568/980] make task fail if tests fail --- .azure/azure-ci-build-pipeline.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index f962a628..dcfbde0e 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -113,6 +113,7 @@ stages: testRunner: JUnit testResultsFiles: 'junit/**.xml' testRunTitle: 'Publish test results' + failTaskOnFailedTests: true - publish: $(System.DefaultWorkingDirectory)/htmlcov/ # publish the html report - so we can debug the coverage if needed From f21ee857a7b416f66e1ffdc84c9e8f032db7b9dd Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 7 Feb 2024 18:09:54 +0000 Subject: [PATCH 569/980] #2258: setting up test that verifies game config parsing --- src/primaite/game/game.py | 41 ++++--- .../configs/basic_switched_network.yaml | 114 ++++++++++++++++++ tests/integration_tests/game_configuration.py | 77 ++++++++++++ 3 files changed, 213 insertions(+), 19 deletions(-) create mode 100644 tests/assets/configs/basic_switched_network.yaml create mode 100644 tests/integration_tests/game_configuration.py diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 368d899a..e0ad0384 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -31,6 +31,23 @@ from primaite.simulator.system.services.web_server.web_server import WebServer _LOGGER = getLogger(__name__) +APPLICATION_TYPES_MAPPING = { + "WebBrowser": WebBrowser, + "DataManipulationBot": DataManipulationBot, +} + +SERVICE_TYPES_MAPPING = { + "DNSClient": DNSClient, + "DNSServer": DNSServer, + "DatabaseClient": DatabaseClient, + "DatabaseService": DatabaseService, + "WebServer": WebServer, + "FTPClient": FTPClient, + "FTPServer": FTPServer, + "NTPClient": NTPClient, + "NTPServer": NTPServer, +} + class PrimaiteGameOptions(BaseModel): """ @@ -238,20 +255,9 @@ class PrimaiteGame: new_service = None service_ref = service_cfg["ref"] service_type = service_cfg["type"] - service_types_mapping = { - "DNSClient": DNSClient, # key is equal to the 'name' attr of the service class itself. - "DNSServer": DNSServer, - "DatabaseClient": DatabaseClient, - "DatabaseService": DatabaseService, - "WebServer": WebServer, - "FTPClient": FTPClient, - "FTPServer": FTPServer, - "NTPClient": NTPClient, - "NTPServer": NTPServer, - } - if service_type in service_types_mapping: + if service_type in SERVICE_TYPES_MAPPING: _LOGGER.debug(f"installing {service_type} on node {new_node.hostname}") - new_node.software_manager.install(service_types_mapping[service_type]) + new_node.software_manager.install(SERVICE_TYPES_MAPPING[service_type]) new_service = new_node.software_manager.software[service_type] game.ref_map_services[service_ref] = new_service.uuid else: @@ -280,12 +286,9 @@ class PrimaiteGame: new_application = None application_ref = application_cfg["ref"] application_type = application_cfg["type"] - application_types_mapping = { - "WebBrowser": WebBrowser, - "DataManipulationBot": DataManipulationBot, - } - if application_type in application_types_mapping: - new_node.software_manager.install(application_types_mapping[application_type]) + + if application_type in APPLICATION_TYPES_MAPPING: + new_node.software_manager.install(APPLICATION_TYPES_MAPPING[application_type]) new_application = new_node.software_manager.software[application_type] game.ref_map_applications[application_ref] = new_application.uuid else: diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml new file mode 100644 index 00000000..f20fedce --- /dev/null +++ b/tests/assets/configs/basic_switched_network.yaml @@ -0,0 +1,114 @@ +training_config: + rl_framework: SB3 + rl_algorithm: PPO + seed: 333 + n_learn_episodes: 1 + n_eval_episodes: 5 + max_steps_per_episode: 128 + deterministic_eval: false + n_agents: 1 + agent_references: + - defender + +io_settings: + save_checkpoints: true + checkpoint_interval: 5 + save_step_metadata: false + save_pcap_logs: true + save_sys_logs: true + + +game: + max_episode_length: 256 + ports: + - ARP + - DNS + - HTTP + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + - UDP + +agents: + - ref: client_2_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_2 + applications: + - application_name: WebBrowser + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_applications_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_settings: + start_step: 5 + frequency: 4 + variance: 3 + +simulation: + network: + nodes: + + - ref: switch_1 + type: switch + hostname: switch_1 + num_ports: 8 + + - ref: client_1 + type: computer + hostname: client_1 + ip_address: 192.168.10.21 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + applications: + - ref: client_1_web_browser + type: WebBrowser + options: + target_url: http://arcd.com/users/ + - ref: data_manipulation_bot + type: DataManipulationBot + options: + port_scan_p_of_success: 0.8 + data_manipulation_p_of_success: 0.8 + payload: "DELETE" + server_ip: 192.168.1.14 + services: + - ref: client_1_dns_client + type: DNSClient + + - ref: client_2 + type: computer + hostname: client_2 + ip_address: 192.168.10.22 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + # pre installed services and applications + + links: + - ref: switch_1___client_1 + endpoint_a_ref: switch_1 + endpoint_a_port: 1 + endpoint_b_ref: client_1 + endpoint_b_port: 1 + - ref: switch_1___client_2 + endpoint_a_ref: switch_1 + endpoint_a_port: 2 + endpoint_b_ref: client_2 + endpoint_b_port: 1 diff --git a/tests/integration_tests/game_configuration.py b/tests/integration_tests/game_configuration.py new file mode 100644 index 00000000..00c94d9e --- /dev/null +++ b/tests/integration_tests/game_configuration.py @@ -0,0 +1,77 @@ +from pathlib import Path +from typing import Union + +import yaml + +from primaite.config.load import example_config_path +from primaite.game.agent.data_manipulation_bot import DataManipulationAgent +from primaite.game.agent.interface import ProxyAgent, RandomAgent +from primaite.game.game import APPLICATION_TYPES_MAPPING, PrimaiteGame, SERVICE_TYPES_MAPPING +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from tests import TEST_ASSETS_ROOT + +BASIC_CONFIG = TEST_ASSETS_ROOT / "configs/basic_switched_network.yaml" + + +def load_config(config_path: Union[str, Path]) -> PrimaiteGame: + """Returns a PrimaiteGame object which loads the contents of a given yaml path.""" + with open(config_path, "r") as f: + cfg = yaml.safe_load(f) + + return PrimaiteGame.from_config(cfg) + + +def test_example_config(): + """Test that the example config can be parsed properly.""" + game = load_config(example_config_path()) + + assert len(game.agents) == 3 # red, blue and green agent + + # green agent + assert game.agents[0].agent_name == "client_2_green_user" + assert isinstance(game.agents[0], RandomAgent) + + # red agent + assert game.agents[1].agent_name == "client_1_data_manipulation_red_bot" + assert isinstance(game.agents[1], DataManipulationAgent) + + # blue agent + assert game.agents[2].agent_name == "defender" + assert isinstance(game.agents[2], ProxyAgent) + + network: Network = game.simulation.network + + assert len(network.nodes) == 10 # 10 nodes in example network + assert len(network.routers) == 1 # 1 router in network + assert len(network.switches) == 2 # 2 switches in network + assert len(network.servers) == 5 # 5 servers in network + + +def test_node_software_install(): + """Test that software can be installed on a node.""" + game = load_config(BASIC_CONFIG) + + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + client_2: Computer = game.simulation.network.get_node_by_hostname("client_2") + + system_software = {DNSClient, FTPClient, WebBrowser} + + # check that system software is installed on client 1 + for software in system_software: + assert client_1.software_manager.software.get(software.__name__) is not None + + # check that system software is installed on client 2 + for software in system_software: + assert client_2.software_manager.software.get(software.__name__) is not None + + # check that applications have been installed on client 1 + for applications in APPLICATION_TYPES_MAPPING: + assert client_1.software_manager.software.get(applications) is not None + + # check that services have been installed on client 1 + # for service in SERVICE_TYPES_MAPPING: + # assert client_1.software_manager.software.get(service) is not None From 5e25fefa14e95abfbee522c84b6ae5471e30e7c1 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 7 Feb 2024 19:44:40 +0000 Subject: [PATCH 570/980] #2248 - Further fixes. All router integration tests now passing. --- .../simulator/network/hardware/base.py | 5 +- .../network/hardware/nodes/host/host_node.py | 31 +- .../network/hardware/nodes/network/router.py | 317 ++++++++++++------ .../simulator/system/core/session_manager.py | 41 ++- .../simulator/system/services/arp/arp.py | 27 +- .../simulator/system/services/icmp/icmp.py | 13 +- .../system/services/ntp/ntp_client.py | 10 +- .../system/services/ntp/ntp_server.py | 8 +- 8 files changed, 315 insertions(+), 137 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 5299b3dd..0bb68147 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -5,7 +5,7 @@ import secrets from abc import abstractmethod, ABC from ipaddress import IPv4Address, IPv4Network from pathlib import Path -from typing import Any, Literal, Union +from typing import Any, Union from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable @@ -370,11 +370,11 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): def enable(self): super().enable() try: + pass self._connected_node.default_gateway_hello() except AttributeError: pass - @abstractmethod def receive_frame(self, frame: Frame) -> bool: """ @@ -386,7 +386,6 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): pass - class WirelessNetworkInterface(NetworkInterface, ABC): """ Represents a wireless network interface in a network device. diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index eefee304..df60edc0 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -63,20 +63,22 @@ class HostARP(ARP): if arp_entry: return arp_entry.mac_address + + if ip_address == self.software_manager.node.default_gateway: + is_reattempt = True + if not is_reattempt: + self.send_arp_request(ip_address) + return self._get_arp_cache_mac_address( + ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt + ) else: - if not is_reattempt: - self.send_arp_request(ip_address) - return self._get_arp_cache_mac_address( - ip_address=ip_address, is_reattempt=True, is_default_gateway_attempt=is_default_gateway_attempt - ) - else: - if self.software_manager.node.default_gateway: - if not is_default_gateway_attempt: - self.send_arp_request(self.software_manager.node.default_gateway) - return self._get_arp_cache_mac_address( - ip_address=self.software_manager.node.default_gateway, is_reattempt=True, - is_default_gateway_attempt=True - ) + if self.software_manager.node.default_gateway: + if not is_default_gateway_attempt: + self.send_arp_request(self.software_manager.node.default_gateway) + return self._get_arp_cache_mac_address( + ip_address=self.software_manager.node.default_gateway, is_reattempt=True, + is_default_gateway_attempt=True + ) return None def get_arp_cache_mac_address(self, ip_address: IPV4Address) -> Optional[str]: @@ -104,6 +106,8 @@ class HostARP(ARP): if arp_entry: return self.software_manager.node.network_interfaces[arp_entry.network_interface_uuid] else: + if ip_address == self.software_manager.node.default_gateway: + is_reattempt = True if not is_reattempt: self.send_arp_request(ip_address) return self._get_arp_cache_network_interface( @@ -147,6 +151,7 @@ class HostARP(ARP): return # Matched ARP request + # TODO: try taking this out self.add_arp_cache_entry( ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, network_interface=from_network_interface diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 06464fd9..dbe3e2c6 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1,23 +1,27 @@ from __future__ import annotations +import secrets from enum import Enum from ipaddress import IPv4Address, IPv4Network from typing import Dict, Any from typing import List, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable +from pydantic import ValidationError from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import IPWiredNetworkInterface from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.network.network_node import NetworkNode from primaite.simulator.network.protocols.arp import ARPPacket +from primaite.simulator.network.protocols.icmp import ICMPType, ICMPPacket from primaite.simulator.network.transmission.data_link_layer import Frame from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.services.arp.arp import ARP from primaite.simulator.system.services.icmp.icmp import ICMP +from primaite.utils.validators import IPV4Address class ACLAction(Enum): @@ -542,64 +546,179 @@ class RouterARP(ARP): """ router: Optional[Router] = None - def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: + def _get_arp_cache_mac_address( + self, ip_address: IPV4Address, is_reattempt: bool = False, is_default_route_attempt: bool = False + ) -> Optional[str]: arp_entry = self.arp.get(ip_address) if arp_entry: return arp_entry.mac_address + + if not is_reattempt: + route = self.router.route_table.find_best_route(ip_address) + if route and route != self.router.route_table.default_route: + self.send_arp_request(route.next_hop_ip_address) + return self._get_arp_cache_mac_address( + ip_address=route.next_hop_ip_address, + is_reattempt=True, + is_default_route_attempt=is_default_route_attempt + ) + else: + if self.router.route_table.default_route: + if not is_default_route_attempt: + self.send_arp_request(self.router.route_table.default_route.next_hop_ip_address) + return self._get_arp_cache_mac_address( + ip_address=self.router.route_table.default_route.next_hop_ip_address, + is_reattempt=True, + is_default_route_attempt=True + ) return None - def get_arp_cache_network_interface(self, ip_address: IPv4Address) -> Optional[RouterInterface]: + def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: + return self._get_arp_cache_mac_address(ip_address) + def _get_arp_cache_network_interface( + self, ip_address: IPV4Address, is_reattempt: bool = False, is_default_route_attempt: bool = False + ) -> Optional[RouterInterface]: arp_entry = self.arp.get(ip_address) if arp_entry: return self.software_manager.node.network_interfaces[arp_entry.network_interface_uuid] + for network_interface in self.router.network_interfaces.values(): if ip_address in network_interface.ip_network: return network_interface + + if not is_reattempt: + route = self.router.route_table.find_best_route(ip_address) + if route and route != self.router.route_table.default_route: + self.send_arp_request(route.next_hop_ip_address) + return self._get_arp_cache_network_interface( + ip_address=route.next_hop_ip_address, + is_reattempt=True, + is_default_route_attempt=is_default_route_attempt + ) + else: + if self.router.route_table.default_route: + if not is_default_route_attempt: + self.send_arp_request(self.router.route_table.default_route.next_hop_ip_address) + return self._get_arp_cache_network_interface( + ip_address=self.router.route_table.default_route.next_hop_ip_address, + is_reattempt=True, + is_default_route_attempt=True + ) return None + + + def get_arp_cache_network_interface(self, ip_address: IPv4Address) -> Optional[RouterInterface]: + + return self._get_arp_cache_network_interface(ip_address) + def _process_arp_request(self, arp_packet: ARPPacket, from_network_interface: RouterInterface): super()._process_arp_request(arp_packet, from_network_interface) # If the target IP matches one of the router's NICs - for network_interface in self.router.network_interfaces.values(): - if network_interface.enabled and network_interface.ip_address == arp_packet.target_ip_address: - arp_reply = arp_packet.generate_reply(from_network_interface.mac_address) - self.send_arp_reply(arp_reply) - return + if from_network_interface.enabled and from_network_interface.ip_address == arp_packet.target_ip_address: + arp_reply = arp_packet.generate_reply(from_network_interface.mac_address) + self.send_arp_reply(arp_reply) + return def _process_arp_reply(self, arp_packet: ARPPacket, from_network_interface: RouterInterface): if arp_packet.target_ip_address == from_network_interface.ip_address: super()._process_arp_reply(arp_packet, from_network_interface) + +class RouterICMP(ICMP): + """ + The Router Internet Control Message Protocol (ICMP) service. + + Extends the ICMP service to provide router-specific functionalities for processing ICMP packets. This class is + responsible for handling ICMP operations such as echo requests and replies in the context of a router. + + Inherits from: + ICMP: Inherits core functionalities for handling ICMP operations, including the processing of echo requests + and replies. + """ + + router: Optional[Router] = None + + def _process_icmp_echo_request(self, frame: Frame, from_network_interface): + """ + Processes an ICMP echo request received by the service. + + :param frame: The network frame containing the ICMP echo request. + """ + self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") + + network_interface = self.software_manager.session_manager.resolve_outbound_network_interface( + frame.ip.src_ip_address + ) + + if not network_interface: + self.sys_log.error( + "Cannot send ICMP echo reply as there is no outbound Network Interface to use. Try configuring the default gateway." + ) + return + + icmp_packet = ICMPPacket( + icmp_type=ICMPType.ECHO_REPLY, + icmp_code=0, + identifier=frame.icmp.identifier, + sequence=frame.icmp.sequence + 1, + ) + payload = secrets.token_urlsafe(int(32 / 1.3)) # Standard ICMP 32 bytes size + self.sys_log.info(f"Sending echo reply to {frame.ip.dst_ip_address}") + + self.software_manager.session_manager.receive_payload_from_software_manager( + payload=payload, + dst_ip_address=frame.ip.src_ip_address, + dst_port=self.port, + ip_protocol=self.protocol, + icmp_packet=icmp_packet + ) + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: """ - Processes received data, handling ARP packets. + Processes received data, specifically handling ICMP echo requests and replies. - :param payload: The payload received. + This method determines the appropriate action based on the packet type and the destination IP address's + association with the router interfaces. + + Initially, it checks if the destination IP address of the ICMP packet corresponds to any router interface. If + the packet is not destined for an enabled interface but still matches a router interface, it is redirected + back to the router for further processing. This ensures proper handling of packets intended for the router + itself or needing to be routed to other destinations. + + :param payload: The payload received, expected to be an ICMP packet. :param session_id: The session ID associated with the received data. - :param kwargs: Additional keyword arguments. - :return: True if the payload was processed successfully, otherwise False. + :param kwargs: Additional keyword arguments, including 'frame' (the received network frame) and + 'from_network_interface' (the router interface that received the frame). + :return: True if the ICMP packet was processed successfully, False otherwise. False indicates either the packet + was not ICMP, the destination IP does not correspond to an enabled router interface (and no further action + was required), or the ICMP packet type is not handled by this method. """ - if not super().receive(payload, session_id, **kwargs): + frame: Frame = kwargs["frame"] + from_network_interface = kwargs["from_network_interface"] + + # Check for the presence of an ICMP payload in the frame. + if not frame.icmp: return False - arp_packet: ARPPacket = payload - from_network_interface: RouterInterface = kwargs["from_network_interface"] + # If the frame's destination IP address corresponds to any router interface, not just enabled ones. + if not self.router.ip_is_router_interface(frame.ip.dst_ip_address): + # If the frame is not for this router, pass it back down to the Router for potential further routing. + self.router.process_frame(frame=frame, from_network_interface=from_network_interface) + return True - for network_interface in self.router.network_interfaces.values(): - # ARP frame is for this Router - if network_interface.ip_address == arp_packet.target_ip_address: - if payload.request: - self._process_arp_request(arp_packet=arp_packet, from_network_interface=from_network_interface) - else: - self._process_arp_reply(arp_packet=arp_packet, from_network_interface=from_network_interface) - return True + # Ensure the destination IP address corresponds to an enabled router interface. + if not self.router.ip_is_router_interface(frame.ip.dst_ip_address, enabled_only=True): + return False - # ARP frame is not for this router, pass back down to Router to continue routing - frame: Frame = kwargs["frame"] - self.router.process_frame(frame=frame, from_network_interface=from_network_interface) + # Process ICMP echo requests and replies. + if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: + self._process_icmp_echo_request(frame, from_network_interface) + elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: + self._process_icmp_echo_reply(frame) return True @@ -720,10 +839,11 @@ class Router(NetworkNode): self.set_original_state() - def _install_system_software(self): """Install System Software - software that is usually provided with the OS.""" - self.software_manager.install(ICMP) + self.software_manager.install(RouterICMP) + icmp: RouterICMP = self.software_manager.icmp # noqa + icmp.router = self self.software_manager.install(RouterARP) arp: RouterARP = self.software_manager.arp # noqa arp.router = self @@ -756,6 +876,15 @@ class Router(NetworkNode): rm.add_request("acl", RequestType(func=self.acl._request_manager)) return rm + def ip_is_router_interface(self, ip_address: IPV4Address, enabled_only: bool = False) -> bool: + for router_interface in self.network_interface.values(): + if router_interface.ip_address == ip_address: + if enabled_only: + return router_interface.enabled + else: + return True + return False + def _get_port_of_nic(self, target_nic: RouterInterface) -> Optional[int]: """ Retrieve the port number for a given NIC. @@ -778,6 +907,61 @@ class Router(NetworkNode): state["acl"] = self.acl.describe_state() return state + def receive_frame(self, frame: Frame, from_network_interface: RouterInterface): + """ + Receive a frame from a RouterInterface and processes it based on its protocol. + + :param frame: The incoming frame. + :param from_network_interface: The network interface where the frame is coming from. + """ + + if self.operating_state != NodeOperatingState.ON: + return + + protocol = frame.ip.protocol + src_ip_address = frame.ip.src_ip_address + dst_ip_address = frame.ip.dst_ip_address + src_port = None + dst_port = None + if frame.ip.protocol == IPProtocol.TCP: + src_port = frame.tcp.src_port + dst_port = frame.tcp.dst_port + elif frame.ip.protocol == IPProtocol.UDP: + src_port = frame.udp.src_port + dst_port = frame.udp.dst_port + + # Check if it's permitted + permitted, rule = self.acl.is_permitted( + protocol=protocol, + src_ip_address=src_ip_address, + src_port=src_port, + dst_ip_address=dst_ip_address, + dst_port=dst_port, + ) + + if not permitted: + at_port = self._get_port_of_nic(from_network_interface) + self.sys_log.info(f"Frame blocked at port {at_port} by rule {rule}") + return + + if frame.ip and self.software_manager.arp: + self.software_manager.arp.add_arp_cache_entry( + ip_address=frame.ip.src_ip_address, + mac_address=frame.ethernet.src_mac_addr, + network_interface=from_network_interface + ) + + send_to_session_manager = False + if ((frame.icmp and self.ip_is_router_interface(dst_ip_address)) + or (dst_port in self.software_manager.get_open_ports())): + send_to_session_manager = True + + if send_to_session_manager: + # Port is open on this Router so pass Frame up to session manager first + self.session_manager.receive_frame(frame, from_network_interface) + else: + self.process_frame(frame, from_network_interface) + def process_frame(self, frame: Frame, from_network_interface: RouterInterface) -> None: """ Process a Frame. @@ -790,14 +974,18 @@ class Router(NetworkNode): if frame.ip: for network_interface in self.network_interfaces.values(): if network_interface.ip_address == frame.ip.dst_ip_address: - self.sys_log.info(f"Dropping frame destined for this router on an port that isn't open.") + self.sys_log.info(f"Dropping frame destined for this router on a port that isn't open.") return network_interface: RouterInterface = self.software_manager.arp.get_arp_cache_network_interface( frame.ip.dst_ip_address ) target_mac = self.software_manager.arp.get_arp_cache_mac_address(frame.ip.dst_ip_address) - self.software_manager.arp.show() + + if not target_mac: + self.sys_log.info(f"Frame dropped as ARP cannot be resolved for {frame.ip.dst_ip_address}") + # TODO: Send something back to src, is it some sort of ICMP? + return if not network_interface: self.sys_log.info(f"Destination {frame.ip.dst_ip_address} is unreachable") @@ -828,7 +1016,7 @@ class Router(NetworkNode): def route_frame(self, frame: Frame, from_network_interface: RouterInterface) -> None: route = self.route_table.find_best_route(frame.ip.dst_ip_address) if route: - network_interface = self.software_managerarp.get_arp_cache_network_interface(route.next_hop_ip_address) + network_interface = self.software_manager.arp.get_arp_cache_network_interface(route.next_hop_ip_address) target_mac = self.software_manager.arp.get_arp_cache_mac_address(route.next_hop_ip_address) if not network_interface: self.sys_log.info(f"Destination {frame.ip.dst_ip_address} is unreachable") @@ -852,73 +1040,6 @@ class Router(NetworkNode): frame.ethernet.dst_mac_addr = target_mac network_interface.send_frame(frame) - def receive_frame(self, frame: Frame, from_network_interface: RouterInterface): - """ - Receive a frame from a RouterInterface and processes it based on its protocol. - - :param frame: The incoming frame. - :param from_network_interface: The network interface where the frame is coming from. - """ - - if self.operating_state != NodeOperatingState.ON: - return - - if frame.ip and self.software_manager.arp: - self.software_manager.arp.add_arp_cache_entry( - ip_address=frame.ip.src_ip_address, - mac_address=frame.ethernet.src_mac_addr, - network_interface=from_network_interface - ) - - protocol = frame.ip.protocol - src_ip_address = frame.ip.src_ip_address - dst_ip_address = frame.ip.dst_ip_address - src_port = None - dst_port = None - if frame.ip.protocol == IPProtocol.TCP: - src_port = frame.tcp.src_port - dst_port = frame.tcp.dst_port - elif frame.ip.protocol == IPProtocol.UDP: - src_port = frame.udp.src_port - dst_port = frame.udp.dst_port - - # Check if it's permitted - permitted, rule = self.acl.is_permitted( - protocol=protocol, - src_ip_address=src_ip_address, - src_port=src_port, - dst_ip_address=dst_ip_address, - dst_port=dst_port, - ) - - if not permitted: - at_port = self._get_port_of_nic(from_network_interface) - self.sys_log.info(f"Frame blocked at port {at_port} by rule {rule}") - return - - self.software_manager.arp.add_arp_cache_entry( - ip_address=src_ip_address, mac_address=frame.ethernet.src_mac_addr, - network_interface=from_network_interface - ) - - # Check if the destination port is open on the Node - dst_port = None - if frame.tcp: - dst_port = frame.tcp.dst_port - elif frame.udp: - dst_port = frame.udp.dst_port - - send_to_session_manager = False - if ((frame.icmp and dst_ip_address == from_network_interface.ip_address) - or (dst_port in self.software_manager.get_open_ports())): - send_to_session_manager = True - - if send_to_session_manager: - # Port is open on this Router so pass Frame up to session manager first - self.session_manager.receive_frame(frame, from_network_interface) - else: - self.process_frame(frame, from_network_interface) - def configure_port(self, port: int, ip_address: Union[IPv4Address, str], subnet_mask: Union[IPv4Address, str]): """ Configure the IP settings of a given port. @@ -936,7 +1057,7 @@ class Router(NetworkNode): network_interface.subnet_mask = subnet_mask self.sys_log.info( f"Configured Network Interface {network_interface}" - ) + ) self.set_original_state() def enable_port(self, port: int): diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index eafdac8e..4ef10a14 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -147,20 +147,34 @@ class SessionManager: return self.software_manager.arp.get_default_gateway_network_interface() def resolve_outbound_transmission_details( - self, dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, session_id: Optional[str] = None - ) -> Tuple[Optional['NetworkInterface'], Optional[str], IPv4Address, Optional[IPProtocol], bool]: - if not isinstance(dst_ip_address, (IPv4Address, IPv4Network)): + self, + dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, + src_port: Optional[Port] = None, + dst_port: Optional[Port] = None, + protocol: Optional[IPProtocol] = None, + session_id: Optional[str] = None + ) -> Tuple[ + Optional['NetworkInterface'], + Optional[str], IPv4Address, + Optional[Port], + Optional[Port], + Optional[IPProtocol], + bool + ]: + if dst_ip_address and not isinstance(dst_ip_address, (IPv4Address, IPv4Network)): dst_ip_address = IPv4Address(dst_ip_address) is_broadcast = False outbound_network_interface = None dst_mac_address = None - protocol = None # Use session details if session_id is provided if session_id: session = self.sessions_by_uuid[session_id] + dst_ip_address = session.with_ip_address protocol = session.protocol + src_port = session.src_port + dst_port = session.dst_port # Determine if the payload is for broadcast or unicast @@ -183,19 +197,20 @@ class SessionManager: dst_mac_address = self.software_manager.arp.get_arp_cache_mac_address(dst_ip_address) break - if dst_ip_address: + if dst_mac_address: use_default_gateway = False outbound_network_interface = self.software_manager.arp.get_arp_cache_network_interface(dst_ip_address) if use_default_gateway: dst_mac_address = self.software_manager.arp.get_default_gateway_mac_address() outbound_network_interface = self.software_manager.arp.get_default_gateway_network_interface() - return outbound_network_interface, dst_mac_address, dst_ip_address, protocol, is_broadcast + return outbound_network_interface, dst_mac_address, dst_ip_address, src_port, dst_port, protocol, is_broadcast def receive_payload_from_software_manager( self, payload: Any, dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, + src_port: Optional[Port] = None, dst_port: Optional[Port] = None, session_id: Optional[str] = None, ip_protocol: IPProtocol = IPProtocol.TCP, @@ -224,10 +239,15 @@ class SessionManager: is_broadcast = payload.request ip_protocol = IPProtocol.UDP else: + vals = self.resolve_outbound_transmission_details( - dst_ip_address=dst_ip_address, session_id=session_id + dst_ip_address=dst_ip_address, + src_port=src_port, + dst_port=dst_port, + protocol=ip_protocol, + session_id=session_id ) - outbound_network_interface, dst_mac_address, dst_ip_address, protocol, is_broadcast = vals + outbound_network_interface, dst_mac_address, dst_ip_address, src_port, dst_port, protocol, is_broadcast = vals if protocol: ip_protocol = protocol @@ -235,6 +255,11 @@ class SessionManager: if not outbound_network_interface or not dst_mac_address: return False + if not (src_port or dst_port): + raise ValueError( + f"Failed to resolve src or dst port. Have you sent the port from the service or application?" + ) + tcp_header = None udp_header = None if ip_protocol == IPProtocol.TCP: diff --git a/src/primaite/simulator/system/services/arp/arp.py b/src/primaite/simulator/system/services/arp/arp.py index 6a82432e..6a04e845 100644 --- a/src/primaite/simulator/system/services/arp/arp.py +++ b/src/primaite/simulator/system/services/arp/arp.py @@ -109,9 +109,24 @@ class ARP(Service): :param target_ip_address: The target IP address for which the MAC address is being requested. """ + if target_ip_address in self.arp: + return + + use_default_gateway = True + for network_interface in self.software_manager.node.network_interfaces.values(): + if target_ip_address in network_interface.ip_network: + use_default_gateway = False + break + + if use_default_gateway: + if self.software_manager.node.default_gateway: + target_ip_address = self.software_manager.node.default_gateway + else: + return + outbound_network_interface = self.software_manager.session_manager.resolve_outbound_network_interface( target_ip_address - ) + ) if outbound_network_interface: self.sys_log.info(f"Sending ARP request from NIC {outbound_network_interface} for ip {target_ip_address}") arp_packet = ARPPacket( @@ -124,7 +139,7 @@ class ARP(Service): ) else: self.sys_log.error( - "Cannot send ARP request as there is no outbound NIC to use. Try configuring the default gateway." + "Cannot send ARP request as there is no outbound Network Interface to use. Try configuring the default gateway." ) def send_arp_reply(self, arp_reply: ARPPacket): @@ -151,12 +166,12 @@ class ARP(Service): ) else: self.sys_log.error( - "Cannot send ARP reply as there is no outbound NIC to use. Try configuring the default gateway." + "Cannot send ARP reply as there is no outbound Network Interface to use. Try configuring the default gateway." ) @abstractmethod - def _process_arp_request(self, arp_packet: ARPPacket, from_network_interface: NIC): + def _process_arp_request(self, arp_packet: ARPPacket, from_network_interface: NetworkInterface): """ Processes an incoming ARP request. @@ -168,7 +183,7 @@ class ARP(Service): f"{arp_packet.sender_mac_addr}/{arp_packet.sender_ip_address} " ) - def _process_arp_reply(self, arp_packet: ARPPacket, from_network_interface: NIC): + def _process_arp_reply(self, arp_packet: ARPPacket, from_network_interface: NetworkInterface): """ Processes an incoming ARP reply. @@ -197,7 +212,7 @@ class ARP(Service): if not super().receive(payload, session_id, **kwargs): return False - from_network_interface = kwargs.get("from_network_interface") + from_network_interface = kwargs["from_network_interface"] if payload.request: self._process_arp_request(arp_packet=payload, from_network_interface=from_network_interface) else: diff --git a/src/primaite/simulator/system/services/icmp/icmp.py b/src/primaite/simulator/system/services/icmp/icmp.py index be943c28..3ff7b21c 100644 --- a/src/primaite/simulator/system/services/icmp/icmp.py +++ b/src/primaite/simulator/system/services/icmp/icmp.py @@ -14,7 +14,7 @@ _LOGGER = getLogger(__name__) class ICMP(Service): """ - The Internet Control Message Protocol (ICMP) services. + The Internet Control Message Protocol (ICMP) service. Enables the sending and receiving of ICMP messages such as echo requests and replies. This is typically used for network diagnostics, notably the ping command. @@ -91,7 +91,7 @@ class ICMP(Service): if not network_interface: self.sys_log.error( - "Cannot send ICMP echo request as there is no outbound NIC to use. Try configuring the default gateway." + "Cannot send ICMP echo request as there is no outbound Network Interface to use. Try configuring the default gateway." ) return pings, None @@ -109,12 +109,14 @@ class ICMP(Service): ) return sequence, icmp_packet.identifier - def _process_icmp_echo_request(self, frame: Frame): + def _process_icmp_echo_request(self, frame: Frame, from_network_interface): """ Processes an ICMP echo request received by the service. :param frame: The network frame containing the ICMP echo request. """ + if frame.ip.dst_ip_address != from_network_interface.ip_address: + return self.sys_log.info(f"Received echo request from {frame.ip.src_ip_address}") network_interface = self.software_manager.session_manager.resolve_outbound_network_interface( @@ -123,7 +125,7 @@ class ICMP(Service): if not network_interface: self.sys_log.error( - "Cannot send ICMP echo reply as there is no outbound NIC to use. Try configuring the default gateway." + "Cannot send ICMP echo reply as there is no outbound Network Interface to use. Try configuring the default gateway." ) return @@ -173,12 +175,13 @@ class ICMP(Service): :return: True if the payload was processed successfully, otherwise False. """ frame: Frame = kwargs["frame"] + from_network_interface = kwargs["from_network_interface"] if not frame.icmp: return False if frame.icmp.icmp_type == ICMPType.ECHO_REQUEST: - self._process_icmp_echo_request(frame) + self._process_icmp_echo_request(frame, from_network_interface) elif frame.icmp.icmp_type == ICMPType.ECHO_REPLY: self._process_icmp_echo_reply(frame) return True diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index e8c3d0cb..dc143895 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -108,9 +108,13 @@ class NTPClient(Service): def request_time(self) -> None: """Send request to ntp_server.""" - ntp_server_packet = NTPPacket() - - self.send(payload=ntp_server_packet, dest_ip_address=self.ntp_server) + self.software_manager.session_manager.receive_payload_from_software_manager( + payload=NTPPacket(), + dst_ip_address=self.ntp_server, + src_port=self.port, + dst_port=self.port, + ip_protocol=self.protocol, + ) def apply_timestep(self, timestep: int) -> None: """ diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index 0a66384a..8e362880 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -69,5 +69,11 @@ class NTPServer(Service): time = datetime.now() payload = payload.generate_reply(time) # send reply - self.send(payload, session_id) + self.software_manager.session_manager.receive_payload_from_software_manager( + payload=payload, + src_port=self.port, + dst_port=self.port, + ip_protocol=self.protocol, + session_id=session_id + ) return True From 0c96fef3ec79d6800f7049a597cbe569e9ac42e9 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 7 Feb 2024 23:05:34 +0000 Subject: [PATCH 571/980] #2248 - All tests (bar the one config file test) now working. Still need to tidy up docstrings and some docs. Almost there --- src/primaite/game/game.py | 4 +- src/primaite/simulator/network/container.py | 3 +- src/primaite/simulator/network/creation.py | 12 ++-- .../simulator/network/hardware/base.py | 23 +++++++- .../network/hardware/nodes/host/host_node.py | 17 +++--- .../network/hardware/nodes/network/router.py | 19 ++++++- .../network/hardware/nodes/network/switch.py | 20 ++++--- src/primaite/simulator/network/networks.py | 54 +++++++++--------- .../system/applications/database_client.py | 5 +- .../system/services/ntp/ntp_client.py | 15 ++--- tests/conftest.py | 29 ++++------ .../environments/__init__.py | 0 .../test_action_integration.py | 6 +- .../network/test_broadcast.py | 6 +- .../network/test_frame_transmission.py | 36 ++++++------ .../network/test_network_creation.py | 48 ++++++---------- .../network/test_nic_link_connection.py | 3 +- .../system/test_database_on_node.py | 51 ++++++++--------- .../system/test_ntp_client_server.py | 8 +-- .../_simulator/_network/_hardware/test_nic.py | 11 ++-- .../_network/_hardware/test_node.py | 10 ---- .../_network/_hardware/test_node_actions.py | 3 +- .../_simulator/_network/test_container.py | 2 +- .../_applications/test_database_client.py | 56 +++++++++++-------- .../_system/_applications/test_web_browser.py | 3 +- .../_system/_services/test_database.py | 4 +- .../_system/_services/test_dns_client.py | 3 +- .../_system/_services/test_dns_server.py | 24 +++++--- .../_system/_services/test_web_server.py | 30 +++++----- 29 files changed, 270 insertions(+), 235 deletions(-) create mode 100644 tests/e2e_integration_tests/environments/__init__.py delete mode 100644 tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node.py diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 60d201f6..c25f64ab 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -319,11 +319,11 @@ class PrimaiteGame: node_a = net.nodes[game.ref_map_nodes[link_cfg["endpoint_a_ref"]]] node_b = net.nodes[game.ref_map_nodes[link_cfg["endpoint_b_ref"]]] if isinstance(node_a, Switch): - endpoint_a = node_a.switch_ports[link_cfg["endpoint_a_port"]] + endpoint_a = node_a.network_interface[link_cfg["endpoint_a_port"]] else: endpoint_a = node_a.network_interface[link_cfg["endpoint_a_port"]] if isinstance(node_b, Switch): - endpoint_b = node_b.switch_ports[link_cfg["endpoint_b_port"]] + endpoint_b = node_b.network_interface[link_cfg["endpoint_b_port"]] else: endpoint_b = node_b.network_interface[link_cfg["endpoint_b_port"]] new_link = net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index df793319..4789134b 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -149,7 +149,8 @@ class Network(SimComponent): for nodes in nodes_type_map.values(): for node in nodes: for i, port in node.network_interface.items(): - table.add_row([node.hostname, i, port.ip_address, port.subnet_mask, node.default_gateway]) + if hasattr(port, "ip_address"): + table.add_row([node.hostname, i, port.ip_address, port.subnet_mask, node.default_gateway]) print(table) if links: diff --git a/src/primaite/simulator/network/creation.py b/src/primaite/simulator/network/creation.py index 370d85da..c1b0d43a 100644 --- a/src/primaite/simulator/network/creation.py +++ b/src/primaite/simulator/network/creation.py @@ -109,9 +109,9 @@ def create_office_lan( switch.power_on() network.add_node(switch) if num_of_switches > 1: - network.connect(core_switch.switch_ports[core_switch_port], switch.switch_ports[24]) + network.connect(core_switch.network_interface[core_switch_port], switch.network_interface[24]) else: - network.connect(router.network_interface[1], switch.switch_ports[24]) + network.connect(router.network_interface[1], switch.network_interface[24]) # Add PCs to the LAN and connect them to switches for i in range(1, num_pcs + 1): @@ -125,9 +125,9 @@ def create_office_lan( # Connect the new switch to the router or core switch if num_of_switches > 1: core_switch_port += 1 - network.connect(core_switch.switch_ports[core_switch_port], switch.switch_ports[24]) + network.connect(core_switch.network_interface[core_switch_port], switch.network_interface[24]) else: - network.connect(router.network_interface[1], switch.switch_ports[24]) + network.connect(router.network_interface[1], switch.network_interface[24]) # Create and add a PC to the network pc = Computer( @@ -142,7 +142,7 @@ def create_office_lan( # Connect the PC to the switch switch_port += 1 - network.connect(switch.switch_ports[switch_port], pc.network_interface[1]) - switch.switch_ports[switch_port].enable() + network.connect(switch.network_interface[switch_port], pc.network_interface[1]) + switch.network_interface[switch_port].enable() return network diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 0bb68147..b7b6d3d4 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -197,6 +197,12 @@ class WiredNetworkInterface(NetworkInterface, ABC): ) return + if not self._connected_link: + self._connected_node.sys_log.info( + f"Interface {self} cannot be enabled as there is no Link connected." + ) + return + self.enabled = True self._connected_node.sys_log.info(f"Network Interface {self} enabled") self.pcap = PacketCapture(hostname=self._connected_node.hostname, interface_num=self.port_num) @@ -351,6 +357,12 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): Derived classes should define specific behaviors and properties of an IP-capable wired network interface, customizing it for their specific use cases. """ + _connected_link: Optional[Link] = None + "The network link to which the network interface is connected." + + def model_post_init(self, __context: Any) -> None: + if self.ip_network.network_address == self.ip_address: + raise ValueError(f"{self.ip_address}/{self.subnet_mask} must not be a network address") def describe_state(self) -> Dict: """ @@ -375,7 +387,7 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): except AttributeError: pass - @abstractmethod + # @abstractmethod def receive_frame(self, frame: Frame) -> bool: """ Receives a network frame on the network interface. @@ -819,6 +831,13 @@ class Node(SimComponent): table.add_row([port.value, port.name]) print(table) + @property + def has_enabled_network_interface(self) -> bool: + for network_interface in self.network_interfaces.values(): + if network_interface.enabled: + return True + return False + def show_nic(self, markdown: bool = False): """Prints a table of the NICs on the Node.""" table = PrettyTable(["Port", "Type", "MAC Address", "Address", "Speed", "Status"]) @@ -830,7 +849,7 @@ class Node(SimComponent): table.add_row( [ port, - network_interface.__name__, + type(network_interface), network_interface.mac_address, f"{network_interface.ip_address}/{network_interface.ip_network.prefixlen}", network_interface.speed, diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index df60edc0..bd13e7e2 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -1,10 +1,10 @@ from __future__ import annotations -from typing import Dict +from typing import Dict, Any from typing import Optional from primaite import getLogger -from primaite.simulator.network.hardware.base import IPWiredNetworkInterface +from primaite.simulator.network.hardware.base import IPWiredNetworkInterface, Link from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.transmission.data_link_layer import Frame @@ -45,7 +45,7 @@ class HostARP(ARP): :return: The NIC associated with the default gateway if it exists in the ARP cache, otherwise None. """ - if self.software_manager.node.default_gateway: + if self.software_manager.node.default_gateway and self.software_manager.node.has_enabled_network_interface: return self.get_arp_cache_network_interface(self.software_manager.node.default_gateway) def _get_arp_cache_mac_address( @@ -175,12 +175,14 @@ class NIC(IPWiredNetworkInterface): and disconnect from network links and to manage the enabled/disabled state of the interface. - Layer3Interface: Provides properties for Layer 3 network configuration, such as IP address and subnet mask. """ + _connected_link: Optional[Link] = None + "The network link to which the network interface is connected." wake_on_lan: bool = False "Indicates if the NIC supports Wake-on-LAN functionality." - def __init__(self, **kwargs): - - super().__init__(**kwargs) + def model_post_init(self, __context: Any) -> None: + if self.ip_network.network_address == self.ip_address: + raise ValueError(f"{self.ip_address}/{self.subnet_mask} must not be a network address") def describe_state(self) -> Dict: """ @@ -353,7 +355,6 @@ class HostNode(Node): if accept_frame: self.session_manager.receive_frame(frame, from_network_interface) else: - # denied as port closed - self.sys_log.info(f"Ignoring frame for port {frame.tcp.dst_port.value} from {frame.ip.src_ip_address}") + self.sys_log.info(f"Ignoring frame from {frame.ip.src_ip_address}") # TODO: do we need to do anything more here? pass diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index dbe3e2c6..e5f4cdcd 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -555,6 +555,14 @@ class RouterARP(ARP): return arp_entry.mac_address if not is_reattempt: + if self.router.ip_is_in_router_interface_subnet(ip_address): + self.send_arp_request(ip_address) + return self._get_arp_cache_mac_address( + ip_address=ip_address, + is_reattempt=True, + is_default_route_attempt=is_default_route_attempt + ) + route = self.router.route_table.find_best_route(ip_address) if route and route != self.router.route_table.default_route: self.send_arp_request(route.next_hop_ip_address) @@ -818,7 +826,7 @@ class Router(NetworkNode): network_interfaces: Dict[str, RouterInterface] = {} "The Router Interfaces on the node." network_interface: Dict[int, RouterInterface] = {} - "The Router Interfaceson the node by port id." + "The Router Interfaces on the node by port id." acl: AccessControlList route_table: RouteTable @@ -885,6 +893,15 @@ class Router(NetworkNode): return True return False + def ip_is_in_router_interface_subnet(self, ip_address: IPV4Address, enabled_only: bool = False) -> bool: + for router_interface in self.network_interface.values(): + if ip_address in router_interface.ip_network: + if enabled_only: + return router_interface.enabled + else: + return True + return False + def _get_port_of_nic(self, target_nic: RouterInterface) -> Optional[int]: """ Retrieve the port number for a given NIC. diff --git a/src/primaite/simulator/network/hardware/nodes/network/switch.py b/src/primaite/simulator/network/hardware/nodes/network/switch.py index e7d5d616..1878aab7 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/network/switch.py @@ -96,16 +96,18 @@ class Switch(NetworkNode): num_ports: int = 24 "The number of ports on the switch." - switch_ports: Dict[int, SwitchPort] = {} - "The SwitchPorts on the switch." + network_interfaces: Dict[str, SwitchPort] = {} + "The SwitchPorts on the Switch." + network_interface: Dict[int, SwitchPort] = {} + "The SwitchPorts on the Switch by port id." mac_address_table: Dict[str, SwitchPort] = {} "A MAC address table mapping destination MAC addresses to corresponding SwitchPorts." def __init__(self, **kwargs): super().__init__(**kwargs) - if not self.switch_ports: - self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)} - for port_num, port in self.switch_ports.items(): + if not self.network_interface: + self.network_interface = {i: SwitchPort() for i in range(1, self.num_ports + 1)} + for port_num, port in self.network_interface.items(): port._connected_node = self port.port_num = port_num port.parent = self @@ -122,7 +124,7 @@ class Switch(NetworkNode): table.set_style(MARKDOWN) table.align = "l" table.title = f"{self.hostname} Switch Ports" - for port_num, port in self.switch_ports.items(): + for port_num, port in self.network_interface.items(): table.add_row([port_num, port.mac_address, port.speed, "Enabled" if port.enabled else "Disabled"]) print(table) @@ -133,7 +135,7 @@ class Switch(NetworkNode): :return: Current state of this object and child objects. """ state = super().describe_state() - state["ports"] = {port_num: port.describe_state() for port_num, port in self.switch_ports.items()} + state["ports"] = {port_num: port.describe_state() for port_num, port in self.network_interface.items()} state["num_ports"] = self.num_ports # redundant? state["mac_address_table"] = {mac: port.port_num for mac, port in self.mac_address_table.items()} return state @@ -171,7 +173,7 @@ class Switch(NetworkNode): outgoing_port.send_frame(frame) else: # If the destination MAC is not in the table, flood to all ports except incoming - for port in self.switch_ports.values(): + for port in self.network_interface.values(): if port.enabled and port != from_network_interface: port.send_frame(frame) @@ -183,7 +185,7 @@ class Switch(NetworkNode): :param port_number: The port number on the switch from where the link should be disconnected. :raise NetworkError: When an invalid port number is provided or the link does not match the connection. """ - port = self.switch_ports.get(port_number) + port = self.network_interface.get(port_number) if port is None: msg = f"Invalid port number {port_number} on the switch" _LOGGER.error(msg) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index 1d47fdef..f830ad70 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -41,13 +41,13 @@ def client_server_routed() -> Network: # Switch 1 switch_1 = Switch(hostname="switch_1", num_ports=6) switch_1.power_on() - network.connect(endpoint_a=router_1.network_interface[1], endpoint_b=switch_1.switch_ports[6]) + network.connect(endpoint_a=router_1.network_interface[1], endpoint_b=switch_1.network_interface[6]) router_1.enable_port(1) # Switch 2 switch_2 = Switch(hostname="switch_2", num_ports=6) switch_2.power_on() - network.connect(endpoint_a=router_1.network_interface[2], endpoint_b=switch_2.switch_ports[6]) + network.connect(endpoint_a=router_1.network_interface[2], endpoint_b=switch_2.network_interface[6]) router_1.enable_port(2) # Client 1 @@ -56,10 +56,10 @@ def client_server_routed() -> Network: ip_address="192.168.2.2", subnet_mask="255.255.255.0", default_gateway="192.168.2.1", - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) client_1.power_on() - network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.switch_ports[1]) + network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1]) # Server 1 server_1 = Server( @@ -67,10 +67,10 @@ def client_server_routed() -> Network: ip_address="192.168.1.2", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) server_1.power_on() - network.connect(endpoint_b=server_1.network_interface[1], endpoint_a=switch_1.switch_ports[1]) + network.connect(endpoint_b=server_1.network_interface[1], endpoint_a=switch_1.network_interface[1]) router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) @@ -119,21 +119,21 @@ def arcd_uc2_network() -> Network: network = Network() # Router 1 - router_1 = Router(hostname="router_1", num_ports=5, operating_state=NodeOperatingState.ON) + router_1 = Router(hostname="router_1", num_ports=5, start_up_duration=0) router_1.power_on() router_1.configure_port(port=1, ip_address="192.168.1.1", subnet_mask="255.255.255.0") router_1.configure_port(port=2, ip_address="192.168.10.1", subnet_mask="255.255.255.0") # Switch 1 - switch_1 = Switch(hostname="switch_1", num_ports=8, operating_state=NodeOperatingState.ON) + switch_1 = Switch(hostname="switch_1", num_ports=8, start_up_duration=0) switch_1.power_on() - network.connect(endpoint_a=router_1.network_interface[1], endpoint_b=switch_1.switch_ports[8]) + network.connect(endpoint_a=router_1.network_interface[1], endpoint_b=switch_1.network_interface[8]) router_1.enable_port(1) # Switch 2 - switch_2 = Switch(hostname="switch_2", num_ports=8, operating_state=NodeOperatingState.ON) + switch_2 = Switch(hostname="switch_2", num_ports=8, start_up_duration=0) switch_2.power_on() - network.connect(endpoint_a=router_1.network_interface[2], endpoint_b=switch_2.switch_ports[8]) + network.connect(endpoint_a=router_1.network_interface[2], endpoint_b=switch_2.network_interface[8]) router_1.enable_port(2) # Client 1 @@ -143,10 +143,10 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.10.1", dns_server=IPv4Address("192.168.1.10"), - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) client_1.power_on() - network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.switch_ports[1]) + network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1]) client_1.software_manager.install(DataManipulationBot) db_manipulation_bot: DataManipulationBot = client_1.software_manager.software.get("DataManipulationBot") db_manipulation_bot.configure( @@ -163,12 +163,12 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.10.1", dns_server=IPv4Address("192.168.1.10"), - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) client_2.power_on() web_browser = client_2.software_manager.software.get("WebBrowser") web_browser.target_url = "http://arcd.com/users/" - network.connect(endpoint_b=client_2.network_interface[1], endpoint_a=switch_2.switch_ports[2]) + network.connect(endpoint_b=client_2.network_interface[1], endpoint_a=switch_2.network_interface[2]) # Domain Controller domain_controller = Server( @@ -176,12 +176,12 @@ def arcd_uc2_network() -> Network: ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) domain_controller.power_on() domain_controller.software_manager.install(DNSServer) - network.connect(endpoint_b=domain_controller.network_interface[1], endpoint_a=switch_1.switch_ports[1]) + network.connect(endpoint_b=domain_controller.network_interface[1], endpoint_a=switch_1.network_interface[1]) # Database Server database_server = Server( @@ -190,10 +190,10 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.1.1", dns_server=IPv4Address("192.168.1.10"), - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) database_server.power_on() - network.connect(endpoint_b=database_server.network_interface[1], endpoint_a=switch_1.switch_ports[3]) + network.connect(endpoint_b=database_server.network_interface[1], endpoint_a=switch_1.network_interface[3]) ddl = """ CREATE TABLE IF NOT EXISTS user ( @@ -264,14 +264,14 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.1.1", dns_server=IPv4Address("192.168.1.10"), - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) web_server.power_on() web_server.software_manager.install(DatabaseClient) database_client: DatabaseClient = web_server.software_manager.software.get("DatabaseClient") database_client.configure(server_ip_address=IPv4Address("192.168.1.14")) - network.connect(endpoint_b=web_server.network_interface[1], endpoint_a=switch_1.switch_ports[2]) + network.connect(endpoint_b=web_server.network_interface[1], endpoint_a=switch_1.network_interface[2]) database_client.run() database_client.connect() @@ -279,7 +279,7 @@ def arcd_uc2_network() -> Network: # register the web_server to a domain dns_server_service: DNSServer = domain_controller.software_manager.software.get("DNSServer") # noqa - dns_server_service.dns_register("arcd.com", web_server.ip_address) + dns_server_service.dns_register("arcd.com", web_server.network_interface[1].ip_address) # Backup Server backup_server = Server( @@ -288,11 +288,11 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.1.1", dns_server=IPv4Address("192.168.1.10"), - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) backup_server.power_on() backup_server.software_manager.install(FTPServer) - network.connect(endpoint_b=backup_server.network_interface[1], endpoint_a=switch_1.switch_ports[4]) + network.connect(endpoint_b=backup_server.network_interface[1], endpoint_a=switch_1.network_interface[4]) # Security Suite security_suite = Server( @@ -301,12 +301,12 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.1.1", dns_server=IPv4Address("192.168.1.10"), - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) security_suite.power_on() - network.connect(endpoint_b=security_suite.network_interface[1], endpoint_a=switch_1.switch_ports[7]) + network.connect(endpoint_b=security_suite.network_interface[1], endpoint_a=switch_1.network_interface[7]) security_suite.connect_nic(NIC(ip_address="192.168.10.110", subnet_mask="255.255.255.0")) - network.connect(endpoint_b=security_suite.network_interface[2], endpoint_a=switch_2.switch_ports[7]) + network.connect(endpoint_b=security_suite.network_interface[2], endpoint_a=switch_2.network_interface[7]) router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index fbeefe6a..5805ed43 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -23,6 +23,7 @@ class DatabaseClient(Application): server_ip_address: Optional[IPv4Address] = None server_password: Optional[str] = None + connected: bool = False _query_success_tracker: Dict[str, bool] = {} def __init__(self, **kwargs): @@ -73,9 +74,10 @@ class DatabaseClient(Application): if not connection_id: connection_id = str(uuid4()) - return self._connect( + self.connected = self._connect( server_ip_address=self.server_ip_address, password=self.server_password, connection_id=connection_id ) + return self.connected def _connect( self, @@ -147,6 +149,7 @@ class DatabaseClient(Application): self.sys_log.info( f"{self.name}: DatabaseClient disconnected connection {connection_id} from {self.server_ip_address}" ) + self.connected = False def _query(self, sql: str, query_id: str, connection_id: str, is_reattempt: bool = False) -> bool: """ diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index dc143895..ddd794ae 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -108,13 +108,14 @@ class NTPClient(Service): def request_time(self) -> None: """Send request to ntp_server.""" - self.software_manager.session_manager.receive_payload_from_software_manager( - payload=NTPPacket(), - dst_ip_address=self.ntp_server, - src_port=self.port, - dst_port=self.port, - ip_protocol=self.protocol, - ) + if self.ntp_server: + self.software_manager.session_manager.receive_payload_from_software_manager( + payload=NTPPacket(), + dst_ip_address=self.ntp_server, + src_port=self.port, + dst_port=self.port, + ip_protocol=self.protocol, + ) def apply_timestep(self, timestep: int) -> None: """ diff --git a/tests/conftest.py b/tests/conftest.py index 0043cad1..b5226a34 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,15 +5,16 @@ from typing import Any, Dict, Tuple, Union import pytest import yaml +from primaite import PRIMAITE_PATHS from primaite import getLogger from primaite.session.session import PrimaiteSession - +from primaite.simulator.file_system.file_system import FileSystem # from primaite.environment.primaite_env import Primaite # from primaite.primaite_session import PrimaiteSession from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.host.computer import Computer -from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.network.networks import arcd_uc2_network from primaite.simulator.network.transmission.network_layer import IPProtocol @@ -28,12 +29,6 @@ ACTION_SPACE_NODE_ACTION_VALUES = 1 _LOGGER = getLogger(__name__) -from primaite import PRIMAITE_PATHS - -# PrimAITE v3 stuff -from primaite.simulator.file_system.file_system import FileSystem -from primaite.simulator.network.hardware.base import Node - class TestService(Service): """Test Service class""" @@ -95,7 +90,7 @@ def application_class(): @pytest.fixture(scope="function") def file_system() -> FileSystem: - return Node(hostname="fs_node").file_system + return Computer(hostname="fs_node", ip_address="192.168.1.2", subnet_mask="255.255.255.0").file_system # PrimAITE v2 stuff @@ -190,8 +185,8 @@ def client_switch_server() -> Tuple[Computer, Switch, Server]: switch = Switch(hostname="switch", start_up_duration=0) switch.power_on() - network.connect(endpoint_a=computer.network_interface[1], endpoint_b=switch.switch_ports[1]) - network.connect(endpoint_a=server.network_interface[1], endpoint_b=switch.switch_ports[2]) + network.connect(endpoint_a=computer.network_interface[1], endpoint_b=switch.network_interface[1]) + network.connect(endpoint_a=server.network_interface[1], endpoint_b=switch.network_interface[2]) assert all(link.is_up for link in network.links.values()) @@ -233,7 +228,7 @@ def example_network() -> Network: ) switch_1.power_on() - network.connect(endpoint_a=router_1.network_interface[1], endpoint_b=switch_1.switch_ports[8]) + network.connect(endpoint_a=router_1.network_interface[1], endpoint_b=switch_1.network_interface[8]) router_1.enable_port(1) # Switch 2 @@ -243,7 +238,7 @@ def example_network() -> Network: start_up_duration=0 ) switch_2.power_on() - network.connect(endpoint_a=router_1.network_interface[2], endpoint_b=switch_2.switch_ports[8]) + network.connect(endpoint_a=router_1.network_interface[2], endpoint_b=switch_2.network_interface[8]) router_1.enable_port(2) # Client 1 @@ -255,7 +250,7 @@ def example_network() -> Network: start_up_duration=0 ) client_1.power_on() - network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.switch_ports[1]) + network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1]) # Client 2 client_2 = Computer( @@ -266,7 +261,7 @@ def example_network() -> Network: start_up_duration=0 ) client_2.power_on() - network.connect(endpoint_b=client_2.network_interface[1], endpoint_a=switch_2.switch_ports[2]) + network.connect(endpoint_b=client_2.network_interface[1], endpoint_a=switch_2.network_interface[2]) # Server 1 server_1 = Server( @@ -277,7 +272,7 @@ def example_network() -> Network: start_up_duration=0 ) server_1.power_on() - network.connect(endpoint_b=server_1.network_interface[1], endpoint_a=switch_1.switch_ports[1]) + network.connect(endpoint_b=server_1.network_interface[1], endpoint_a=switch_1.network_interface[1]) # DServer 2 server_2 = Server( @@ -288,7 +283,7 @@ def example_network() -> Network: start_up_duration=0 ) server_2.power_on() - network.connect(endpoint_b=server_2.network_interface[1], endpoint_a=switch_1.switch_ports[2]) + network.connect(endpoint_b=server_2.network_interface[1], endpoint_a=switch_1.network_interface[2]) router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) diff --git a/tests/e2e_integration_tests/environments/__init__.py b/tests/e2e_integration_tests/environments/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration_tests/component_creation/test_action_integration.py b/tests/integration_tests/component_creation/test_action_integration.py index 7d3945a6..809e7816 100644 --- a/tests/integration_tests/component_creation/test_action_integration.py +++ b/tests/integration_tests/component_creation/test_action_integration.py @@ -25,9 +25,9 @@ def test_passing_actions_down(monkeypatch) -> None: downloads_folder = pc1.file_system.create_folder("downloads") pc1.file_system.create_file("bermuda_triangle.png", folder_name="downloads") - sim.network.connect(pc1.network_interface[1], s1.switch_ports[1]) - sim.network.connect(pc2.network_interface[1], s1.switch_ports[2]) - sim.network.connect(s1.switch_ports[3], srv.network_interface[1]) + sim.network.connect(pc1.network_interface[1], s1.network_interface[1]) + sim.network.connect(pc2.network_interface[1], s1.network_interface[2]) + sim.network.connect(s1.network_interface[3], srv.network_interface[1]) # call this method to make sure no errors occur. sim._request_manager.get_request_types_recursively() diff --git a/tests/integration_tests/network/test_broadcast.py b/tests/integration_tests/network/test_broadcast.py index 2dd9f7b8..d6c52acc 100644 --- a/tests/integration_tests/network/test_broadcast.py +++ b/tests/integration_tests/network/test_broadcast.py @@ -111,9 +111,9 @@ def broadcast_network() -> Network: switch_1 = Switch(hostname="switch_1", num_ports=6, start_up_duration=0) switch_1.power_on() - network.connect(endpoint_a=client_1.network_interface[1], endpoint_b=switch_1.switch_ports[1]) - network.connect(endpoint_a=client_2.network_interface[1], endpoint_b=switch_1.switch_ports[2]) - network.connect(endpoint_a=server_1.network_interface[1], endpoint_b=switch_1.switch_ports[3]) + network.connect(endpoint_a=client_1.network_interface[1], endpoint_b=switch_1.network_interface[1]) + network.connect(endpoint_a=client_2.network_interface[1], endpoint_b=switch_1.network_interface[2]) + network.connect(endpoint_a=server_1.network_interface[1], endpoint_b=switch_1.network_interface[3]) return network diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index 7beea643..5ba4fe13 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -1,5 +1,6 @@ from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.host_node import NIC from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.hardware.nodes.network.switch import Switch @@ -30,32 +31,33 @@ def test_node_to_node_ping(): switch_1 = Switch(hostname="switch_1", start_up_duration=0) switch_1.power_on() - network.connect(endpoint_a=client_1.network_interface[1], endpoint_b=switch_1.switch_ports[1]) - network.connect(endpoint_a=server_1.network_interface[1], endpoint_b=switch_1.switch_ports[2]) + network.connect(endpoint_a=client_1.network_interface[1], endpoint_b=switch_1.network_interface[1]) + network.connect(endpoint_a=server_1.network_interface[1], endpoint_b=switch_1.network_interface[2]) assert client_1.ping("192.168.1.11") def test_multi_nic(): """Tests that Computers with multiple NICs can ping each other and the data go across the correct links.""" - node_a = Computer(hostname="node_a", operating_state=ComputerOperatingState.ON) - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0") - node_a.connect_nic(nic_a) + network = Network() - node_b = Computer(hostname="node_b", operating_state=ComputerOperatingState.ON) - nic_b1 = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") - nic_b2 = NIC(ip_address="10.0.0.12", subnet_mask="255.0.0.0") - node_b.connect_nic(nic_b1) - node_b.connect_nic(nic_b2) + node_a = Computer(hostname="node_a", ip_address="192.168.0.10", subnet_mask="255.255.255.0", start_up_duration=0) + node_a.power_on() - node_c = Computer(hostname="node_c", operating_state=ComputerOperatingState.ON) - nic_c = NIC(ip_address="10.0.0.13", subnet_mask="255.0.0.0") - node_c.connect_nic(nic_c) + node_b = Computer(hostname="node_b", ip_address="192.168.0.11", subnet_mask="255.255.255.0", start_up_duration=0) + node_b.power_on() + node_b.connect_nic(NIC(ip_address="10.0.0.12", subnet_mask="255.0.0.0")) - Link(endpoint_a=nic_a, endpoint_b=nic_b1) + node_c = Computer(hostname="node_c", ip_address="10.0.0.13", subnet_mask="255.0.0.0", start_up_duration=0) + node_c.power_on() - Link(endpoint_a=nic_b2, endpoint_b=nic_c) + network.connect(node_a.network_interface[1], node_b.network_interface[1]) + network.connect(node_b.network_interface[2], node_c.network_interface[1]) - node_a.ping("192.168.0.11") + assert node_a.ping(node_b.network_interface[1].ip_address) - assert node_c.ping("10.0.0.12") + assert node_c.ping(node_b.network_interface[2].ip_address) + + assert not node_a.ping(node_b.network_interface[2].ip_address) + + assert not node_a.ping(node_c.network_interface[1].ip_address) diff --git a/tests/integration_tests/network/test_network_creation.py b/tests/integration_tests/network/test_network_creation.py index d9792675..6a39e101 100644 --- a/tests/integration_tests/network/test_network_creation.py +++ b/tests/integration_tests/network/test_network_creation.py @@ -1,6 +1,6 @@ from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.host_node import NIC from primaite.simulator.network.hardware.nodes.host.server import Server @@ -26,7 +26,7 @@ def test_network(example_network): def test_adding_removing_nodes(): """Check that we can create and add a node to a network.""" net = Network() - n1 = Node(hostname="computer") + n1 = Computer(hostname="computer", ip_address="192.168.1.2", subnet_mask="255.255.255.0", start_up_duration=0) net.add_node(n1) assert n1.parent is net assert n1 in net @@ -39,7 +39,7 @@ def test_adding_removing_nodes(): def test_readding_node(): """Check that warning is raised when readding a node.""" net = Network() - n1 = Node(hostname="computer") + n1 = Computer(hostname="computer", ip_address="192.168.1.2", subnet_mask="255.255.255.0", start_up_duration=0) net.add_node(n1) net.add_node(n1) assert n1.parent is net @@ -49,7 +49,7 @@ def test_readding_node(): def test_removing_nonexistent_node(): """Check that warning is raised when trying to remove a node that is not in the network.""" net = Network() - n1 = Node(hostname="computer") + n1 = Computer(hostname="computer1", ip_address="192.168.1.1", subnet_mask="255.255.255.0", start_up_duration=0) net.remove_node(n1) assert n1.parent is None assert n1 not in net @@ -58,17 +58,13 @@ def test_removing_nonexistent_node(): def test_connecting_nodes(): """Check that two nodes on the network can be connected.""" net = Network() - n1 = Node(hostname="computer") - n1_nic = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0") - n1.connect_nic(n1_nic) - n2 = Node(hostname="server") - n2_nic = NIC(ip_address="120.30.0.2", gateway="192.168.0.1", subnet_mask="255.255.255.0") - n2.connect_nic(n2_nic) + n1 = Computer(hostname="computer1", ip_address="192.168.1.1", subnet_mask="255.255.255.0", start_up_duration=0) + n2 = Computer(hostname="computer2", ip_address="192.168.1.2", subnet_mask="255.255.255.0", start_up_duration=0) net.add_node(n1) net.add_node(n2) - net.connect(n1.network_interfaces[n1_nic.uuid], n2.network_interfaces[n2_nic.uuid], bandwidth=30) + net.connect(n1.network_interface[1], n2.network_interface[1]) assert len(net.links) == 1 link = list(net.links.values())[0] @@ -76,40 +72,32 @@ def test_connecting_nodes(): assert link.parent is net -def test_connecting_node_to_itself(): +def test_connecting_node_to_itself_fails(): net = Network() - node = Node(hostname="computer") - nic1 = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0") - node.connect_nic(nic1) - nic2 = NIC(ip_address="120.30.0.2", gateway="192.168.0.1", subnet_mask="255.255.255.0") - node.connect_nic(nic2) + node = Computer(hostname="node_b", ip_address="192.168.0.11", subnet_mask="255.255.255.0", start_up_duration=0) + node.power_on() + node.connect_nic(NIC(ip_address="10.0.0.12", subnet_mask="255.0.0.0")) net.add_node(node) - net.connect(node.network_interfaces[nic1.uuid], node.network_interfaces[nic2.uuid], bandwidth=30) + net.connect(node.network_interface[1], node.network_interface[2]) assert node in net - assert nic1._connected_link is None - assert nic2._connected_link is None + assert node.network_interface[1]._connected_link is None + assert node.network_interface[2]._connected_link is None assert len(net.links) == 0 def test_disconnecting_nodes(): net = Network() - n1 = Node(hostname="computer") - n1_nic = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0") - n1.connect_nic(n1_nic) - net.add_node(n1) + n1 = Computer(hostname="computer1", ip_address="192.168.1.1", subnet_mask="255.255.255.0", start_up_duration=0) + n2 = Computer(hostname="computer2", ip_address="192.168.1.2", subnet_mask="255.255.255.0", start_up_duration=0) - n2 = Node(hostname="server") - n2_nic = NIC(ip_address="120.30.0.2", gateway="192.168.0.1", subnet_mask="255.255.255.0") - n2.connect_nic(n2_nic) - net.add_node(n2) - - net.connect(n1.network_interfaces[n1_nic.uuid], n2.network_interfaces[n2_nic.uuid], bandwidth=30) + net.connect(n1.network_interface[1], n2.network_interface[1]) assert len(net.links) == 1 + link = list(net.links.values())[0] net.remove_link(link) assert link not in net diff --git a/tests/integration_tests/network/test_nic_link_connection.py b/tests/integration_tests/network/test_nic_link_connection.py index 228099c6..f13248a2 100644 --- a/tests/integration_tests/network/test_nic_link_connection.py +++ b/tests/integration_tests/network/test_nic_link_connection.py @@ -1,6 +1,7 @@ import pytest -from primaite.simulator.network.hardware.base import Link, NIC +from primaite.simulator.network.hardware.base import Link +from primaite.simulator.network.hardware.nodes.host.host_node import NIC def test_link_fails_with_same_nic(): diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index df47d8ad..c259501e 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -3,7 +3,9 @@ from typing import Tuple import pytest -from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database.database_service import DatabaseService @@ -12,17 +14,25 @@ from primaite.simulator.system.services.service import ServiceOperatingState @pytest.fixture(scope="function") -def peer_to_peer() -> Tuple[Node, Node]: - node_a = Node(hostname="node_a", operating_state=NodeOperatingState.ON) - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON) - node_a.connect_nic(nic_a) +def peer_to_peer() -> Tuple[Computer, Computer]: + network = Network() + node_a = Computer( + hostname="node_a", + ip_address="192.168.0.10", + subnet_mask="255.255.255.0", + start_up_duration=0 + ) + node_a.power_on() node_a.software_manager.get_open_ports() - node_b = Node(hostname="node_b", operating_state=NodeOperatingState.ON) - nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") - node_b.connect_nic(nic_b) - - Link(endpoint_a=nic_a, endpoint_b=nic_b) + node_b = Computer( + hostname="node_b", + ip_address="192.168.0.11", + subnet_mask="255.255.255.0", + start_up_duration=0 + ) + node_b.power_on() + network.connect(node_a.network_interface[1], node_b.network_interface[1]) assert node_a.ping("192.168.0.11") @@ -37,26 +47,11 @@ def peer_to_peer() -> Tuple[Node, Node]: @pytest.fixture(scope="function") -def peer_to_peer_secure_db() -> Tuple[Node, Node]: - node_a = Node(hostname="node_a", operating_state=NodeOperatingState.ON) - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON) - node_a.connect_nic(nic_a) - node_a.software_manager.get_open_ports() +def peer_to_peer_secure_db(peer_to_peer) -> Tuple[Computer, Computer]: + node_a, node_b = peer_to_peer - node_b = Node(hostname="node_b", operating_state=NodeOperatingState.ON) - nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0") - node_b.connect_nic(nic_b) - - Link(endpoint_a=nic_a, endpoint_b=nic_b) - - assert node_a.ping("192.168.0.11") - - node_a.software_manager.install(DatabaseClient) - node_a.software_manager.software["DatabaseClient"].configure(server_ip_address=IPv4Address("192.168.0.11")) - node_a.software_manager.software["DatabaseClient"].run() - - node_b.software_manager.install(DatabaseService) database_service: DatabaseService = node_b.software_manager.software["DatabaseService"] # noqa + database_service.stop() database_service.password = "12345" database_service.start() return node_a, node_b diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index 92133d50..7e52377b 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -47,11 +47,11 @@ def test_ntp_client_server(create_ntp_network): assert ntp_server.operating_state == ServiceOperatingState.RUNNING assert ntp_client.operating_state == ServiceOperatingState.RUNNING - ntp_client.configure(ntp_server_ip_address=IPv4Address("192.168.0.2")) + ntp_client.configure(ntp_server_ip_address=IPv4Address("192.168.1.3")) - assert ntp_client.time is None + assert not ntp_client.time ntp_client.request_time() - assert ntp_client.time is not None + assert ntp_client.time first_time = ntp_client.time sleep(0.1) ntp_client.apply_timestep(1) # Check time advances @@ -68,7 +68,7 @@ def test_ntp_server_failure(create_ntp_network): assert ntp_client.operating_state == ServiceOperatingState.RUNNING assert ntp_client.operating_state == ServiceOperatingState.RUNNING - ntp_client.configure(ntp_server_ip_address=IPv4Address("192.168.0.2")) + ntp_client.configure(ntp_server_ip_address=IPv4Address("192.168.1.3")) # Turn off ntp server. ntp_server.stop() diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py index 90b54b78..d0738c64 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_nic.py @@ -2,8 +2,10 @@ import re from ipaddress import IPv4Address import pytest +from pydantic import ValidationError -from primaite.simulator.network.hardware.base import generate_mac_address, NIC +from primaite.simulator.network.hardware.base import generate_mac_address +from primaite.simulator.network.hardware.nodes.host.host_node import NIC def test_mac_address_generation(): @@ -50,8 +52,5 @@ def test_nic_deserialize(): def test_nic_ip_address_as_network_address_fails(): """Tests NIC creation fails if ip address and subnet mask are a network address.""" - with pytest.raises(ValueError): - NIC( - ip_address="192.168.0.0", - subnet_mask="255.255.255.0", - ) + with pytest.raises(ValidationError): + NIC(ip_address="192.168.0.0", subnet_mask="255.255.255.0") diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node.py deleted file mode 100644 index 0e5fb4c7..00000000 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node.py +++ /dev/null @@ -1,10 +0,0 @@ -import re -from ipaddress import IPv4Address - -import pytest - -from primaite.simulator.network.hardware.base import Node - - -def test_node_creation(): - node = Node(hostname="host_1") diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py index b6f7a86d..a1b8a6c1 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/test_node_actions.py @@ -4,12 +4,13 @@ from primaite.simulator.file_system.file import File from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus from primaite.simulator.file_system.folder import Folder from primaite.simulator.network.hardware.base import Node, NodeOperatingState +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.system.software import SoftwareHealthState @pytest.fixture def node() -> Node: - return Node(hostname="test") + return Computer(hostname="test", ip_address="192.168.1.2", subnet_mask="255.255.255.0") def test_node_startup(node): diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index b56253fb..9d424697 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -108,7 +108,7 @@ def test_removing_node_that_does_not_exist(network): """Node that does not exist on network should not affect existing nodes.""" assert len(network.nodes) is 7 - network.remove_node(Node(hostname="new_node")) + network.remove_node(Computer(hostname="new_node", ip_address="192.168.1.2", subnet_mask="255.255.255.0")) assert len(network.nodes) is 7 diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py index 6fec4555..c7d807e9 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py @@ -4,23 +4,44 @@ from uuid import uuid4 import pytest -from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.services.database.database_service import DatabaseService @pytest.fixture(scope="function") def database_client_on_computer() -> Tuple[DatabaseClient, Computer]: - computer = Computer( - hostname="db_node", ip_address="192.168.0.1", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON - ) - computer.software_manager.install(DatabaseClient) + network = Network() - database_client: DatabaseClient = computer.software_manager.software.get("DatabaseClient") + db_server = Server( + hostname="db_server", + ip_address="192.168.0.1", + subnet_mask="255.255.255.0", + start_up_duration=0 + ) + db_server.power_on() + db_server.software_manager.install(DatabaseService) + db_server.software_manager.software["DatabaseService"].start() + + db_client = Computer( + hostname="db_client", + ip_address="192.168.0.2", + subnet_mask="255.255.255.0", + start_up_duration=0 + ) + db_client.power_on() + db_client.software_manager.install(DatabaseClient) + + database_client: DatabaseClient = db_client.software_manager.software.get("DatabaseClient") database_client.configure(server_ip_address=IPv4Address("192.168.0.1")) database_client.run() - return database_client, computer + + network.connect(db_server.network_interface[1], db_client.network_interface[1]) + + return database_client, db_client def test_creation(database_client_on_computer): @@ -50,7 +71,7 @@ def test_disconnect_when_client_is_closed(database_client_on_computer): """Database client disconnect should not do anything when it is not running.""" database_client, computer = database_client_on_computer - database_client.connected = True + database_client.connect() assert database_client.server_ip_address is not None database_client.close() @@ -66,24 +87,15 @@ def test_disconnect(database_client_on_computer): """Database client should remove the connection.""" database_client, computer = database_client_on_computer - database_client._connections[str(uuid4())] = {"item": True} - assert len(database_client.connections) == 1 + assert not database_client.connected - assert database_client.operating_state is ApplicationOperatingState.RUNNING - assert database_client.server_ip_address is not None + database_client.connect() + + assert database_client.connected database_client.disconnect() - assert len(database_client.connections) == 0 - - uuid = str(uuid4()) - database_client._connections[uuid] = {"item": True} - assert len(database_client.connections) == 1 - - database_client.disconnect(connection_id=uuid) - - assert len(database_client.connections) == 0 - + assert not database_client.connected def test_query_when_client_is_closed(database_client_on_computer): """Database client should return False when it is not running.""" diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py index 9dc7a52e..05d4a985 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py @@ -16,8 +16,9 @@ def web_browser() -> WebBrowser: ip_address="192.168.1.11", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", - operating_state=NodeOperatingState.ON, + start_up_duration=0 ) + computer.power_on() # Web Browser should be pre-installed in computer web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser") web_browser.run() diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py index 4d96b584..0df6cf27 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_database.py @@ -1,12 +1,14 @@ import pytest from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.system.services.database.database_service import DatabaseService @pytest.fixture(scope="function") def database_server() -> Node: - node = Node(hostname="db_node") + node = Computer(hostname="db_node", ip_address="192.168.1.2", subnet_mask="255.255.255.0", start_up_duration=0) + node.power_on() node.software_manager.install(DatabaseService) node.software_manager.software.get("DatabaseService").start() return node diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py index 97c1cf4e..bc11d278 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_client.py @@ -2,7 +2,6 @@ from ipaddress import IPv4Address import pytest -from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.protocols.dns import DNSPacket, DNSReply, DNSRequest @@ -13,7 +12,7 @@ from primaite.simulator.system.services.service import ServiceOperatingState @pytest.fixture(scope="function") -def dns_client() -> Node: +def dns_client() -> Computer: node = Computer( hostname="dns_client", ip_address="192.168.1.11", diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py index 5f5fdcba..937636a6 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py @@ -2,13 +2,15 @@ from ipaddress import IPv4Address import pytest +from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.base import Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.server import Server -from primaite.simulator.network.protocols.dns import DNSPacket, DNSRequest from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.services.dns.dns_server import DNSServer +from primaite.simulator.system.services.dns.dns_client import DNSClient @pytest.fixture(scope="function") @@ -51,14 +53,18 @@ def test_dns_server_receive(dns_server): # register the web server in the domain controller dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12")) - assert ( - dns_server_service.receive(payload=DNSPacket(dns_request=DNSRequest(domain_name_request="fake-domain.com"))) - is False - ) + client = Computer(hostname="client", ip_address="192.168.1.11", subnet_mask="255.255.255.0", start_up_duration=0) + client.power_on() + client.dns_server = IPv4Address("192.168.1.10") + network = Network() + network.connect(dns_server.network_interface[1], client.network_interface[1]) + dns_client: DNSClient = client.software_manager.software["DNSClient"] # noqa + dns_client.check_domain_exists("fake-domain.com") + + assert dns_client.check_domain_exists("fake-domain.com") is False + + assert dns_client.check_domain_exists("real-domain.com") is False + - assert ( - dns_server_service.receive(payload=DNSPacket(dns_request=DNSRequest(domain_name_request="real-domain.com"))) - is True - ) dns_server_service.show() diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py index 2e645435..d2190ed4 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py @@ -22,7 +22,7 @@ def web_server() -> Server: default_gateway="192.168.1.1", operating_state=NodeOperatingState.ON, ) - node.software_manager.install(software_class=WebServer) + node.software_manager.install(WebServer) node.software_manager.software.get("WebServer").start() return node @@ -53,17 +53,17 @@ def test_handling_get_request_home_page(web_server): assert response.status_code == HttpStatusCode.OK -def test_process_http_request_get(web_server): - payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url="http://domain.com/") - - web_server_service: WebServer = web_server.software_manager.software.get("WebServer") - - assert web_server_service._process_http_request(payload=payload) is True - - -def test_process_http_request_method_not_allowed(web_server): - payload = HttpRequestPacket(request_method=HttpRequestMethod.DELETE, request_url="http://domain.com/") - - web_server_service: WebServer = web_server.software_manager.software.get("WebServer") - - assert web_server_service._process_http_request(payload=payload) is False +# def test_process_http_request_get(web_server): +# payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url="http://domain.com/") +# +# web_server_service: WebServer = web_server.software_manager.software.get("WebServer") +# +# assert web_server_service._process_http_request(payload=payload) is True +# +# +# def test_process_http_request_method_not_allowed(web_server): +# payload = HttpRequestPacket(request_method=HttpRequestMethod.DELETE, request_url="http://domain.com/") +# +# web_server_service: WebServer = web_server.software_manager.software.get("WebServer") +# +# assert web_server_service._process_http_request(payload=payload) is False From ff17062e1cc0bfcfee645d553a5745e688cfaf3c Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 8 Feb 2024 09:19:18 +0000 Subject: [PATCH 572/980] Vary start node of red agent. --- .../config/_package_data/example_config.yaml | 12 +- .../example_config_2_rl_agents.yaml | 2 +- .../game/agent/data_manipulation_bot.py | 16 +- src/primaite/game/game.py | 12 +- src/primaite/notebooks/uc2_demo.ipynb | 739 +++++++++++++++++- .../assets/configs/bad_primaite_session.yaml | 2 +- .../configs/eval_only_primaite_session.yaml | 2 +- tests/assets/configs/multi_agent_session.yaml | 2 +- .../assets/configs/test_primaite_session.yaml | 2 +- .../configs/train_only_primaite_session.yaml | 2 +- 10 files changed, 745 insertions(+), 46 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 700a0c18..7290339e 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -85,7 +85,7 @@ agents: - - ref: client_1_data_manipulation_red_bot + - ref: data_manipulation_attacker team: RED type: RedDatabaseCorruptingAgent @@ -106,6 +106,9 @@ agents: - node_name: client_1 applications: - application_name: DataManipulationBot + - node_name: client_2 + applications: + - application_name: DataManipulationBot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -730,6 +733,13 @@ simulation: type: WebBrowser options: target_url: http://arcd.com/users/ + - ref: data_manipulation_bot + type: DataManipulationBot + options: + port_scan_p_of_success: 0.8 + data_manipulation_p_of_success: 0.8 + payload: "DELETE" + server_ip: 192.168.1.14 services: - ref: client_2_dns_client type: DNSClient diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index 6aa54487..993b3283 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -54,7 +54,7 @@ agents: frequency: 4 variance: 3 - - ref: client_1_data_manipulation_red_bot + - ref: data_manipulation_attacker team: RED type: RedDatabaseCorruptingAgent diff --git a/src/primaite/game/agent/data_manipulation_bot.py b/src/primaite/game/agent/data_manipulation_bot.py index 58b790ec..126c55ec 100644 --- a/src/primaite/game/agent/data_manipulation_bot.py +++ b/src/primaite/game/agent/data_manipulation_bot.py @@ -1,21 +1,20 @@ import random -from typing import Dict, List, Tuple +from typing import Dict, Tuple from gymnasium.core import ObsType from primaite.game.agent.interface import AbstractScriptedAgent -from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot class DataManipulationAgent(AbstractScriptedAgent): """Agent that uses a DataManipulationBot to perform an SQL injection attack.""" - data_manipulation_bots: List["DataManipulationBot"] = [] next_execution_timestep: int = 0 + starting_node_idx: int = 0 def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self._set_next_execution_timestep(self.agent_settings.start_settings.start_step) + self.reset_agent_for_episode() def _set_next_execution_timestep(self, timestep: int) -> None: """Set the next execution timestep with a configured random variance. @@ -44,9 +43,16 @@ class DataManipulationAgent(AbstractScriptedAgent): self._set_next_execution_timestep(current_timestep + self.agent_settings.start_settings.frequency) - return "NODE_APPLICATION_EXECUTE", {"node_id": 0, "application_id": 0} + return "NODE_APPLICATION_EXECUTE", {"node_id": self.starting_node_idx, "application_id": 0} def reset_agent_for_episode(self) -> None: """Set the next execution timestep when the episode resets.""" super().reset_agent_for_episode() + self._select_start_node() self._set_next_execution_timestep(self.agent_settings.start_settings.start_step) + + def _select_start_node(self) -> None: + """Set the starting starting node of the agent to be a random node from this agent's action manager.""" + # we are assuming that every node in the node manager has a data manipulation application at idx 0 + num_nodes = len(self.action_manager.node_names) + self.starting_node_idx = random.randint(0, num_nodes - 1) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index a2c4e86d..1fd0dc8b 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -1,6 +1,6 @@ """PrimAITE game - Encapsulates the simulation and agents.""" from ipaddress import IPv4Address -from typing import Dict, List +from typing import Dict, List, Tuple from pydantic import BaseModel, ConfigDict @@ -131,8 +131,14 @@ class PrimaiteGame: agent.update_reward(state) agent.reward_function.total_reward += agent.reward_function.current_reward - def apply_agent_actions(self) -> None: - """Apply all actions to simulation as requests.""" + def apply_agent_actions(self) -> Dict[str, Tuple[str, Dict]]: + """ + Apply all actions to simulation as requests. + + :return: A recap of each agent's actions, in CAOS format. + :rtype: Dict[str, Tuple[str, Dict]] + + """ agent_actions = {} for agent in self.agents: obs = agent.observation_manager.current_observation diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index 7454b6c4..b37e69fc 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -55,7 +55,7 @@ "source": [ "## Red agent\n", "\n", - "The red agent waits a bit then sends a DELETE query to the database from client 1. If the delete is successful, the database file is flagged as compromised to signal that data is not available.\n", + "At the start of every episode, the red agent randomly chooses either client 1 or client 2 to login to. It waits a bit then sends a DELETE query to the database from its chosen client. If the delete is successful, the database file is flagged as compromised to signal that data is not available.\n", "\n", "[](_package_data/uc2_attack.png)\n", "\n", @@ -68,7 +68,7 @@ "source": [ "## Blue agent\n", "\n", - "The blue agent can view the entire network, but the health statuses of components are not updated until a scan is performed. The blue agent should restore the database file from backup after it was compromised. It can also prevent further attacks by blocking client 1 from sending the malicious SQL query to the database server. This can be done by implementing an ACL rule on the router." + "The blue agent can view the entire network, but the health statuses of components are not updated until a scan is performed. The blue agent should restore the database file from backup after it was compromised. It can also prevent further attacks by blocking the red agent client from sending the malicious SQL query to the database server. This can be done by implementing an ACL rule on the router." ] }, { @@ -84,7 +84,7 @@ "source": [ "## Scripted agents:\n", "### Red\n", - "The red agent sits on client 1 and uses an application called DataManipulationBot whose sole purpose is to send a DELETE query to the database.\n", + "The red agent sits on a client and uses an application called DataManipulationBot whose sole purpose is to send a DELETE query to the database.\n", "The red agent can choose one of two action each timestep:\n", "1. do nothing\n", "2. execute the data manipulation application\n", @@ -92,6 +92,7 @@ "- start time\n", "- frequency\n", "- variance\n", + "\n", "Attacks start at a random timestep between (start_time - variance) and (start_time + variance). After each attack, another is attempted after a random delay between (frequency - variance) and (frequency + variance) timesteps.\n", "\n", "The data manipulation app itself has an element of randomness because the attack has a probability of success. The default is 0.8 to succeed with the port scan step and 0.8 to succeed with the attack itself.\n", @@ -290,10 +291,16 @@ "- `9`: Scan the database file - this refreshes the health status of the database file\n", "- `13`: Patch the database service - This triggers the database to restore data from the backup server\n", "- `19`: Shut down client 1\n", + "- `20`: Start up client 1\n", "- `22`: Block outgoing traffic from client 1\n", + "- `23`: Block outgoing traffic from client 2\n", "- `26`: Block TCP traffic from client 1 to the database node\n", + "- `27`: Block TCP traffic from client 2 to the database node\n", "- `28-37`: Remove ACL rules 1-10\n", "- `42`: Disconnect client 1 from the network\n", + "- `43`: Reconnect client 1 to the network\n", + "- `44`: Disconnect client 2 from the network\n", + "- `45`: Reconnect client 2 to the network\n", "\n", "The other actions will either have no effect or will negatively impact the network, so the blue agent should avoid taking them." ] @@ -326,7 +333,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -336,9 +343,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/cade/repos/PrimAITE/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n", + "2024-02-07 10:58:13,192\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", + "2024-02-07 10:58:17,136\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n" + ] + } + ], "source": [ "# Imports\n", "from primaite.config.load import example_config_path\n", @@ -359,16 +377,143 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Resetting environment, episode 0, avg. reward: 0.0\n", + "env created successfully\n", + "{'ACL': {1: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 0,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 2: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 1,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 3: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 2,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 4: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 3,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 5: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 4,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 6: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 5,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 7: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 6,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 8: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 7,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 9: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 8,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 10: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 9,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0}},\n", + " 'ICS': 0,\n", + " 'LINKS': {1: {'PROTOCOLS': {'ALL': 0}},\n", + " 2: {'PROTOCOLS': {'ALL': 0}},\n", + " 3: {'PROTOCOLS': {'ALL': 0}},\n", + " 4: {'PROTOCOLS': {'ALL': 0}},\n", + " 5: {'PROTOCOLS': {'ALL': 0}},\n", + " 6: {'PROTOCOLS': {'ALL': 0}},\n", + " 7: {'PROTOCOLS': {'ALL': 0}},\n", + " 8: {'PROTOCOLS': {'ALL': 0}},\n", + " 9: {'PROTOCOLS': {'ALL': 0}},\n", + " 10: {'PROTOCOLS': {'ALL': 0}}},\n", + " 'NODES': {1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}},\n", + " 'health_status': 1}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}}\n" + ] + } + ], "source": [ "# create the env\n", "with open(example_config_path(), 'r') as f:\n", " cfg = yaml.safe_load(f)\n", " # set success probability to 1.0 to avoid rerunning cells.\n", " cfg['simulation']['network']['nodes'][8]['applications'][0]['options']['data_manipulation_p_of_success'] = 1.0\n", + " cfg['simulation']['network']['nodes'][9]['applications'][0]['options']['data_manipulation_p_of_success'] = 1.0\n", " cfg['simulation']['network']['nodes'][8]['applications'][0]['options']['port_scan_p_of_success'] = 1.0\n", + " cfg['simulation']['network']['nodes'][9]['applications'][0]['options']['port_scan_p_of_success'] = 1.0\n", "game = PrimaiteGame.from_config(cfg)\n", "env = PrimaiteGymEnv(game = game)\n", "# Don't flatten obs as we are not training an agent and we wish to see the dict-formatted observations\n", @@ -382,18 +527,78 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The red agent will start attacking at some point between step 20 and 30. When this happens, the reward will go from 1.0 to 0.0, and to -1.0 when the green agent tries to access the webpage." + "The red agent will start attacking at some point between step 20 and 30. When this happens, the reward will drop immediately, then drop to -1.0 when green agents try to access the webpage." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "for step in range(32):\n", + "def friendly_output_red_action(info):\n", + " # parse the info dict form step output and write out what the red agent is doing\n", + " red_info = info['agent_actions']['data_manipulation_attacker']\n", + " red_action = red_info[0]\n", + " if red_action == 'DONOTHING':\n", + " red_str = 'DO NOTHING'\n", + " elif red_action == 'NODE_APPLICATION_EXECUTE':\n", + " client = \"client 1\" if red_info[1]['node_id'] == 0 else \"client 2\"\n", + " red_str = f\"ATTACK from {client}\"\n", + " return red_str" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 1, Red action: DO NOTHING, Blue reward:0.34\n", + "step: 2, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 3, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 4, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 5, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 6, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 7, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 8, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 9, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 10, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 11, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 12, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 13, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 14, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 15, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 16, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 17, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 18, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 19, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 20, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 21, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 22, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 23, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 24, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 25, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 26, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 27, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 28, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 29, Red action: DO NOTHING, Blue reward:1.0\n", + "step: 30, Red action: ATTACK from client 1, Blue reward:0.32\n", + "step: 31, Red action: DO NOTHING, Blue reward:0.32\n", + "step: 32, Red action: DO NOTHING, Blue reward:0.32\n", + "step: 33, Red action: DO NOTHING, Blue reward:-1.0\n", + "step: 34, Red action: DO NOTHING, Blue reward:-1.0\n", + "step: 35, Red action: DO NOTHING, Blue reward:-1.0\n" + ] + } + ], + "source": [ + "for step in range(35):\n", " obs, reward, terminated, truncated, info = env.step(0)\n", - " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}, Blue reward:{reward}\" )" + " print(f\"step: {env.game.step_counter}, Red action: {friendly_output_red_action(info)}, Blue reward:{reward}\" )" ] }, { @@ -405,9 +610,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}}, 'health_status': 1}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}\n" + ] + } + ], "source": [ "pprint(obs['NODES'])" ] @@ -421,9 +661,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 3, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 2}}, 'health_status': 1}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}\n" + ] + } + ], "source": [ "obs, reward, terminated, truncated, info = env.step(9) # scan database file\n", "obs, reward, terminated, truncated, info = env.step(1) # scan webapp service\n", @@ -447,13 +722,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 38\n", + "Red action: DONOTHING\n", + "Green action: NODE_APPLICATION_EXECUTE\n", + "Green action: NODE_APPLICATION_EXECUTE\n", + "Blue reward:-1.0\n" + ] + } + ], "source": [ "obs, reward, terminated, truncated, info = env.step(13) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", - "print(f\"Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}\" )\n", + "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker'][0]}\" )\n", "print(f\"Green action: {info['agent_actions']['client_1_green_user'][0]}\" )\n", "print(f\"Green action: {info['agent_actions']['client_2_green_user'][0]}\" )\n", "print(f\"Blue reward:{reward}\" )" @@ -465,20 +752,32 @@ "source": [ "The patching takes two steps, so the reward hasn't changed yet. Let's do nothing for another timestep, the reward should improve.\n", "\n", - "The reward will be 0 as soon as the file finishes restoring. Then, the reward will increase to 1 when the green agent makes a request. (Because the webapp access part of the reward does not update until a successful request is made.)\n", + "The reward will increase slightly as soon as the file finishes restoring. Then, the reward will increase to 1 when both green agents make successful requests.\n", "\n", "Run the following cell until the green action is `NODE_APPLICATION_EXECUTE`, then the reward should become 1. If you run it enough times, another red attack will happen and the reward will drop again." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 39\n", + "Red action: DONOTHING\n", + "Green action: NODE_APPLICATION_EXECUTE\n", + "Green action: DONOTHING\n", + "Blue reward:-0.32\n" + ] + } + ], "source": [ "obs, reward, terminated, truncated, info = env.step(0) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", - "print(f\"Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}\" )\n", + "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker'][0]}\" )\n", "print(f\"Green action: {info['agent_actions']['client_2_green_user'][0]}\" )\n", "print(f\"Green action: {info['agent_actions']['client_1_green_user'][0]}\" )\n", "print(f\"Blue reward:{reward}\" )" @@ -488,24 +787,69 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The blue agent can prevent attacks by implementing an ACL rule to stop client_1 from sending POSTGRES traffic to the database. (Let's also patch the database file to get the reward back up.)" + "The blue agent can prevent attacks by implementing an ACL rule to stop client_1 or client_2 from sending POSTGRES traffic to the database. (Let's also patch the database file to get the reward back up.)\n", + "\n", + "Let's block both clients from communicating directly with the database." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 139, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 140, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 141, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 142, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 143, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 144, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 145, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 146, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 147, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 148, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 149, Red action: NODE_APPLICATION_EXECUTE, Blue reward:-0.32\n", + "step: 150, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 151, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 152, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 153, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 154, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 155, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 156, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 157, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 158, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 159, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 160, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 161, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 162, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 163, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 164, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 165, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 166, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 167, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 168, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 169, Red action: NODE_APPLICATION_EXECUTE, Blue reward:-0.32\n", + "step: 170, Red action: DONOTHING, Blue reward:-0.32\n", + "step: 171, Red action: DONOTHING, Blue reward:-0.32\n" + ] + } + ], "source": [ "env.step(13) # Patch the database\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}, Blue reward:{reward}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward}\" )\n", "\n", "env.step(26) # Block client 1\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}, Blue reward:{reward}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward}\" )\n", + "\n", + "env.step(27) # Block client 2\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward}\" )\n", "\n", "for step in range(30):\n", " obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", - " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['client_1_data_manipulation_red_bot'][0]}, Blue reward:{reward}\" )" + " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward}\" )" ] }, { @@ -519,7 +863,340 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Let's also have a look at the ACL observation to verify our new ACL rule at position 5." + "Let's also have a look at the ACL observation to verify our new ACL rule at positions 5 and 6." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1: {'position': 0,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 2: {'position': 1,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 3: {'position': 2,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 4: {'position': 3,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 5: {'position': 4,\n", + " 'permission': 2,\n", + " 'source_node_id': 7,\n", + " 'source_port': 1,\n", + " 'dest_node_id': 4,\n", + " 'dest_port': 1,\n", + " 'protocol': 3},\n", + " 6: {'position': 5,\n", + " 'permission': 2,\n", + " 'source_node_id': 8,\n", + " 'source_port': 1,\n", + " 'dest_node_id': 4,\n", + " 'dest_port': 1,\n", + " 'protocol': 3},\n", + " 7: {'position': 6,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 8: {'position': 7,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 9: {'position': 8,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 10: {'position': 9,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0}}" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "obs['ACL']" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "router = env.game.simulation.network.get_node_by_hostname('router_1')" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+------------------------------------------------------------------------------------------------------------+\n", + "| router_1 Access Control List |\n", + "+-------+--------+----------+---------------+------------------------+--------------+------------------------+\n", + "| Index | Action | Protocol | Src IP | Src Port | Dst IP | Dst Port |\n", + "+-------+--------+----------+---------------+------------------------+--------------+------------------------+\n", + "| 5 | DENY | TCP | 192.168.10.21 | ANY | 192.168.1.14 | ANY |\n", + "| 6 | DENY | TCP | 192.168.10.22 | ANY | 192.168.1.14 | ANY |\n", + "| 18 | PERMIT | ANY | ANY | 5432 (POSTGRES_SERVER) | ANY | 5432 (POSTGRES_SERVER) |\n", + "| 19 | PERMIT | ANY | ANY | 53 (DNS) | ANY | 53 (DNS) |\n", + "| 20 | PERMIT | ANY | ANY | 21 (FTP) | ANY | 21 (FTP) |\n", + "| 21 | PERMIT | ANY | ANY | 80 (HTTP) | ANY | 80 (HTTP) |\n", + "| 22 | PERMIT | ANY | ANY | 219 (ARP) | ANY | 219 (ARP) |\n", + "| 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY |\n", + "| 24 | DENY | ANY | ANY | ANY | ANY | ANY |\n", + "+-------+--------+----------+---------------+------------------------+--------------+------------------------+\n" + ] + } + ], + "source": [ + "router.acl.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[(, 0.34),\n", + " (,\n", + " 0.33),\n", + " (,\n", + " 0.33)]" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "env.agent.reward_function.reward_components" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "client_1 = env.game.simulation.network.get_node_by_hostname('client_1')\n", + "client_2 = env.game.simulation.network.get_node_by_hostname('client_2')" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "client_1_browser = client_1.software_manager.software.get(\"WebBrowser\")\n", + "client_2_browser = client_2.software_manager.software.get(\"WebBrowser\")" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", + " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=)]" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client_2_browser.history" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client_1_browser.get_webpage()" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "database_server = env.game.simulation.network.get_node_by_hostname('database_server')" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "File(uuid='390c399a-c2ab-4d84-b98f-d5fc1f9114d2', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={'390c399a-c2ab-4d84-b98f-d5fc1f9114d2': File(uuid='390c399a-c2ab-4d84-b98f-d5fc1f9114d2', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={'e63e23dc-c443-4434-822d-3c2c01cbfe1e': File(uuid='e63e23dc-c443-4434-822d-3c2c01cbfe1e', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=True, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e'])), '646a198e-6ac1-4aea-b526-7ca5c2c30dfc': File(uuid='646a198e-6ac1-4aea-b526-7ca5c2c30dfc', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=True, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e'])), '23df7aba-074e-4ffa-939a-d87ad1fe7af1': File(uuid='23df7aba-074e-4ffa-939a-d87ad1fe7af1', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=True, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))}, deleted_files={'e63e23dc-c443-4434-822d-3c2c01cbfe1e': File(uuid='e63e23dc-c443-4434-822d-3c2c01cbfe1e', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=True, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={'390c399a-c2ab-4d84-b98f-d5fc1f9114d2': File(uuid='390c399a-c2ab-4d84-b98f-d5fc1f9114d2', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e'])), '646a198e-6ac1-4aea-b526-7ca5c2c30dfc': File(uuid='646a198e-6ac1-4aea-b526-7ca5c2c30dfc', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=True, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={'390c399a-c2ab-4d84-b98f-d5fc1f9114d2': File(uuid='390c399a-c2ab-4d84-b98f-d5fc1f9114d2', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e'])), '23df7aba-074e-4ffa-939a-d87ad1fe7af1': File(uuid='23df7aba-074e-4ffa-939a-d87ad1fe7af1', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=True, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={'390c399a-c2ab-4d84-b98f-d5fc1f9114d2': File(uuid='390c399a-c2ab-4d84-b98f-d5fc1f9114d2', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "database_server.file_system.get_file('database', 'database.db')" ] }, { @@ -528,7 +1205,7 @@ "metadata": {}, "outputs": [], "source": [ - "obs['ACL']" + "database_server." ] } ], diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 552351b2..662d704f 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -46,7 +46,7 @@ agents: frequency: 20 variance: 5 - - ref: client_1_data_manipulation_red_bot + - ref: data_manipulation_attacker team: RED type: RedDatabaseCorruptingAgent diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index d49562c8..254f7974 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -51,7 +51,7 @@ agents: frequency: 20 variance: 5 - - ref: client_1_data_manipulation_red_bot + - ref: data_manipulation_attacker team: RED type: RedDatabaseCorruptingAgent diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 29f0ae7f..f01b1a63 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -57,7 +57,7 @@ agents: frequency: 20 variance: 5 - - ref: client_1_data_manipulation_red_bot + - ref: data_manipulation_attacker team: RED type: RedDatabaseCorruptingAgent diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 0c70840d..55e8a273 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -55,7 +55,7 @@ agents: frequency: 20 variance: 5 - - ref: client_1_data_manipulation_red_bot + - ref: data_manipulation_attacker team: RED type: RedDatabaseCorruptingAgent diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index 0466a5ac..27236470 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -58,7 +58,7 @@ agents: frequency: 20 variance: 5 - - ref: client_1_data_manipulation_red_bot + - ref: data_manipulation_attacker team: RED type: RedDatabaseCorruptingAgent From a4b787860442cfa17e611edd8baac726eaab306d Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 8 Feb 2024 10:36:07 +0000 Subject: [PATCH 573/980] #2258: added NTPClient to system software + testing all installable software on client1 in config --- .../network/hardware/nodes/computer.py | 4 ++++ .../configs/basic_switched_network.yaml | 22 ++++++++++++++++--- tests/integration_tests/game_configuration.py | 7 +++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/primaite/simulator/network/hardware/nodes/computer.py b/src/primaite/simulator/network/hardware/nodes/computer.py index 0480aca9..9b076647 100644 --- a/src/primaite/simulator/network/hardware/nodes/computer.py +++ b/src/primaite/simulator/network/hardware/nodes/computer.py @@ -2,6 +2,7 @@ from primaite.simulator.network.hardware.base import NIC, Node from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.ntp.ntp_client import NTPClient class Computer(Node): @@ -49,6 +50,9 @@ class Computer(Node): # FTP self.software_manager.install(FTPClient) + # NTP + self.software_manager.install(NTPClient) + # Web Browser self.software_manager.install(WebBrowser) diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index f20fedce..774c4aa2 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -89,9 +89,25 @@ simulation: payload: "DELETE" server_ip: 192.168.1.14 services: - - ref: client_1_dns_client - type: DNSClient - + - ref: client_1_dns_server + type: DNSServer + options: + domain_mapping: + arcd.com: 192.168.1.12 # web server + - ref: client_1_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.10.21 + - ref: client_1_database_service + type: DatabaseService + options: + backup_server_ip: 192.168.10.21 + - ref: client_1_web_service + type: WebServer + - ref: client_1_ftp_server + type: FTPServer + - ref: client_1_ntp_server + type: NTPServer - ref: client_2 type: computer hostname: client_2 diff --git a/tests/integration_tests/game_configuration.py b/tests/integration_tests/game_configuration.py index 00c94d9e..ff977082 100644 --- a/tests/integration_tests/game_configuration.py +++ b/tests/integration_tests/game_configuration.py @@ -12,6 +12,7 @@ from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.ntp.ntp_client import NTPClient from tests import TEST_ASSETS_ROOT BASIC_CONFIG = TEST_ASSETS_ROOT / "configs/basic_switched_network.yaml" @@ -58,7 +59,7 @@ def test_node_software_install(): client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") client_2: Computer = game.simulation.network.get_node_by_hostname("client_2") - system_software = {DNSClient, FTPClient, WebBrowser} + system_software = {DNSClient, FTPClient, NTPClient, WebBrowser} # check that system software is installed on client 1 for software in system_software: @@ -73,5 +74,5 @@ def test_node_software_install(): assert client_1.software_manager.software.get(applications) is not None # check that services have been installed on client 1 - # for service in SERVICE_TYPES_MAPPING: - # assert client_1.software_manager.software.get(service) is not None + for service in SERVICE_TYPES_MAPPING: + assert client_1.software_manager.software.get(service) is not None From 411f0a320fb651179be2c2fb65b77579b8018aee Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 8 Feb 2024 10:53:30 +0000 Subject: [PATCH 574/980] #2248 - Final run over all the docstrings after running pre-commit. All tests now working. Updated CHANGELOG.md. --- CHANGELOG.md | 13 + src/primaite/game/agent/observations.py | 8 +- src/primaite/game/game.py | 2 +- src/primaite/simulator/network/container.py | 2 +- .../simulator/network/hardware/base.py | 72 +++-- .../network_interface/layer_3_interface.py | 9 - .../network_interface/wired/__init__.py | 0 .../wired/router_interface.py | 0 .../wireless/wireless_access_point.py | 3 +- .../wireless/wireless_nic.py | 3 +- .../network/hardware/nodes/host/computer.py | 2 +- .../network/hardware/nodes/host/host_node.py | 120 ++++--- .../network/hardware/nodes/host/server.py | 1 - .../hardware/nodes/network/network_node.py | 25 +- .../network/hardware/nodes/network/router.py | 304 ++++++++++++------ .../network/hardware/nodes/network/switch.py | 5 +- src/primaite/simulator/network/networks.py | 21 +- .../simulator/network/protocols/icmp.py | 2 +- .../network/transmission/data_link_layer.py | 1 - .../network/transmission/network_layer.py | 7 +- .../simulator/system/core/packet_capture.py | 1 - .../simulator/system/core/session_manager.py | 112 +++++-- .../simulator/system/core/software_manager.py | 29 +- .../simulator/system/services/arp/arp.py | 30 +- .../simulator/system/services/icmp/icmp.py | 33 +- .../system/services/ntp/ntp_server.py | 6 +- src/primaite/simulator/system/software.py | 2 +- src/primaite/utils/validators.py | 6 +- tests/conftest.py | 30 +- .../network/test_broadcast.py | 7 +- .../network/test_frame_transmission.py | 1 - .../network/test_network_creation.py | 1 - .../integration_tests/network/test_routing.py | 4 +- .../test_dos_bot_and_server.py | 2 +- .../system/test_database_on_node.py | 14 +- .../system/test_dns_client_server.py | 3 +- .../system/test_web_client_server.py | 5 +- .../test_web_client_server_and_database.py | 5 +- .../_applications/test_database_client.py | 13 +- .../_system/_applications/test_web_browser.py | 2 +- .../_system/_services/test_dns_server.py | 4 +- 41 files changed, 582 insertions(+), 328 deletions(-) delete mode 100644 src/primaite/simulator/network/hardware/network_interface/layer_3_interface.py delete mode 100644 src/primaite/simulator/network/hardware/network_interface/wired/__init__.py delete mode 100644 src/primaite/simulator/network/hardware/network_interface/wired/router_interface.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d8706ad..68bc3b81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,12 @@ SessionManager. - **Custom Layer-3 Processing**: The `RouterNIC` class includes custom handling for network frames, bypassing standard Node NIC's Layer 3 broadcast/unicast checks. This allows for more efficient routing behavior in network scenarios where router-specific frame processing is required. - **Enhanced Frame Reception**: The `receive_frame` method in `RouterNIC` is tailored to handle frames based on Layer 2 (Ethernet) checks, focusing on MAC address-based routing and broadcast frame acceptance. - **Subnet-Wide Broadcasting for Services and Applications**: Implemented the ability for services and applications to conduct broadcasts across an entire IPv4 subnet within the network simulation framework. +- Introduced the `NetworkInterface` abstract class to provide a common interface for all network interfaces. Subclasses are divided into two main categories: `WiredNetworkInterface` and `WirelessNetworkInterface`, each serving as an abstract base class (ABC) for more specific interface types. Under `WiredNetworkInterface`, the subclasses `NIC` and `SwitchPort` were added. For wireless interfaces, `WirelessNIC` and `WirelessAccessPoint` are the subclasses under `WirelessNetworkInterface`. +- Added `Layer3Interface` as an abstract base class for networking functionalities at layer 3, including IP addressing and routing capabilities. This class is inherited by `NIC`, `WirelessNIC`, and `WirelessAccessPoint` to provide them with layer 3 capabilities, facilitating their role in both wired and wireless networking contexts with IP-based communication. +- Created the `ARP` and `ICMP` service classes to handle Address Resolution Protocol operations and Internet Control Message Protocol messages, respectively, with `RouterARP` and `RouterICMP` for router-specific implementations. +- Created `HostNode` as a subclass of `Node`, extending its functionality with host-specific services and applications. This class is designed to represent end-user devices like computers or servers that can initiate and respond to network communications. +- Introduced a new `IPV4Address` type in the Pydantic model for enhanced validation and auto-conversion of IPv4 addresses from strings using an `ipv4_validator`. + ### Changed - Integrated the RouteTable into the Routers frame processing. @@ -67,6 +73,9 @@ SessionManager. - **NIC Functionality Update**: Updated the Network Interface Card (`NIC`) functionality to support Layer 3 (L3) broadcasts. - **Layer 3 Broadcast Handling**: Enhanced the existing `NIC` classes to correctly process and handle Layer 3 broadcasts. This update allows devices using standard NICs to effectively participate in network activities that involve L3 broadcasting. - **Improved Frame Reception Logic**: The `receive_frame` method of the `NIC` class has been updated to include additional checks and handling for L3 broadcasts, ensuring proper frame processing in a wider range of network scenarios. +- Standardised the way network interfaces are accessed across all `Node` subclasses (`HostNode`, `Router`, `Switch`) by maintaining a comprehensive `network_interface` attribute. This attribute captures all network interfaces by their port number, streamlining the management and interaction with network interfaces across different types of nodes. +- Refactored all tests to utilise new `Node` subclasses (`Computer`, `Server`, `Router`, `Switch`) instead of creating generic `Node` instances and manually adding network interfaces. This change aligns test setups more closely with the intended use cases and hierarchies within the network simulation framework. +- Updated all tests to employ the `Network()` class for managing nodes and their connections, ensuring a consistent and structured approach to setting up network topologies in testing scenarios. ### Removed @@ -74,6 +83,10 @@ SessionManager. - Removed legacy training modules - Removed tests for legacy code +### Fixed +- Addressed network transmission issues that previously allowed ARP requests to be incorrectly routed and repeated across different subnets. This fix ensures ARP requests are correctly managed and confined to their appropriate network segments. +- Resolved problems in `Node` and its subclasses where the default gateway configuration was not properly utilized for communications across different subnets. This correction ensures that nodes effectively use their configured default gateways for outbound communications to other network segments, thereby enhancing the network's routing functionality and reliability. + ## [2.0.0] - 2023-07-26 diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 8f1c739c..715e594e 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -494,7 +494,9 @@ class NodeObservation(AbstractObservation): obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} obs["operating_status"] = node_state["operating_state"] - obs["NETWORK_INTERFACES"] = {i + 1: network_interface.observe(state) for i, network_interface in enumerate(self.network_interfaces)} + obs["NETWORK_INTERFACES"] = { + i + 1: network_interface.observe(state) for i, network_interface in enumerate(self.network_interfaces) + } if self.logon_status: obs["logon_status"] = 0 @@ -508,7 +510,9 @@ class NodeObservation(AbstractObservation): "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), "operating_status": spaces.Discrete(5), - "NETWORK_INTERFACES": spaces.Dict({i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)}), + "NETWORK_INTERFACES": spaces.Dict( + {i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)} + ), } if self.logon_status: space_shape["logon_status"] = spaces.Discrete(3) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index c25f64ab..f1f66e40 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -14,8 +14,8 @@ from primaite.session.io import SessionIO, SessionIOSettings from primaite.simulator.network.hardware.base import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC -from primaite.simulator.network.hardware.nodes.network.router import Router from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.router import Router from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.sim_container import Simulation from primaite.simulator.system.applications.database_client import DatabaseClient diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 4789134b..d3a26e73 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -9,8 +9,8 @@ from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import Link, Node, WiredNetworkInterface from primaite.simulator.network.hardware.nodes.host.computer import Computer -from primaite.simulator.network.hardware.nodes.network.router import Router from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.router import Router from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.system.applications.application import Application from primaite.simulator.system.services.service import Service diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index b7b6d3d4..c742ca33 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -2,14 +2,13 @@ from __future__ import annotations import re import secrets -from abc import abstractmethod, ABC +from abc import ABC, abstractmethod from ipaddress import IPv4Address, IPv4Network from pathlib import Path -from typing import Any, Union -from typing import Dict, Optional +from typing import Any, Dict, Optional, Union from prettytable import MARKDOWN, PrettyTable -from pydantic import Field, BaseModel +from pydantic import BaseModel, Field from primaite import getLogger from primaite.exceptions import NetworkError @@ -48,7 +47,7 @@ def generate_mac_address(oui: Optional[str] = None) -> str: _LOGGER.error(msg) raise ValueError(msg) oui_bytes = [int(chunk, 16) for chunk in oui.split(":")] - mac = oui_bytes + random_bytes[len(oui_bytes):] + mac = oui_bytes + random_bytes[len(oui_bytes) :] else: mac = random_bytes @@ -198,9 +197,7 @@ class WiredNetworkInterface(NetworkInterface, ABC): return if not self._connected_link: - self._connected_node.sys_log.info( - f"Interface {self} cannot be enabled as there is no Link connected." - ) + self._connected_node.sys_log.info(f"Interface {self} cannot be enabled as there is no Link connected.") return self.enabled = True @@ -225,9 +222,9 @@ class WiredNetworkInterface(NetworkInterface, ABC): """ Connect this network interface to a specified link. - This method establishes a connection between the network interface and a network link if the network interface is not already - connected. If the network interface is already connected to a link, it logs an error and does not change the existing - connection. + This method establishes a connection between the network interface and a network link if the network interface + is not already connected. If the network interface is already connected to a link, it logs an error and does + not change the existing connection. :param link: The Link instance to connect to this network interface. """ @@ -246,8 +243,8 @@ class WiredNetworkInterface(NetworkInterface, ABC): """ Disconnect the network interface from its connected Link, if any. - This method removes the association between the network interface and its connected Link. It updates the connected Link's - endpoints to reflect the disconnection. + This method removes the association between the network interface and its connected Link. It updates the + connected Link's endpoints to reflect the disconnection. """ if self._connected_link.endpoint_a == self: self._connected_link.endpoint_a = None @@ -298,6 +295,7 @@ class Layer3Interface(BaseModel, ABC): :ivar IPv4Address subnet_mask: The subnet mask assigned to the interface. This mask helps in determining the network segment that the interface belongs to and is used in IP routing decisions. """ + ip_address: IPV4Address "The IP address assigned to the interface for communication on an IP-based network." @@ -357,10 +355,23 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): Derived classes should define specific behaviors and properties of an IP-capable wired network interface, customizing it for their specific use cases. """ + _connected_link: Optional[Link] = None "The network link to which the network interface is connected." def model_post_init(self, __context: Any) -> None: + """ + Performs post-initialisation checks to ensure the model's IP configuration is valid. + + This method is invoked after the initialisation of a network model object to validate its network settings, + particularly to ensure that the assigned IP address is not a network address. This validation is crucial for + maintaining the integrity of network simulations and avoiding configuration errors that could lead to + unrealistic or incorrect behavior. + + :param __context: Contextual information or parameters passed to the method, used for further initializing or + validating the model post-creation. + :raises ValueError: If the IP address is the same as the network address, indicating an incorrect configuration. + """ if self.ip_network.network_address == self.ip_address: raise ValueError(f"{self.ip_address}/{self.subnet_mask} must not be a network address") @@ -380,6 +391,17 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): return state def enable(self): + """ + Enables this wired network interface and attempts to send a "hello" message to the default gateway. + + This method activates the network interface, making it operational for network communications. After enabling, + it tries to initiate a default gateway "hello" process, typically to establish initial connectivity and resolve + the default gateway's MAC address. This step is crucial for ensuring the interface can successfully send data + to and receive data from the network. + + The method safely handles cases where the connected node might not have a default gateway set or the + `default_gateway_hello` method is not defined, ignoring such errors to proceed without interruption. + """ super().enable() try: pass @@ -440,8 +462,8 @@ class IPWirelessNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): As an abstract class, `IPWirelessNetworkInterface` does not implement specific methods but ensures that any derived class provides implementations for the functionalities of both `WirelessNetworkInterface` and `Layer3Interface`. This setup is ideal for representing network interfaces in devices that require wireless connections and are capable - of IP routing and addressing, such as wireless routers, access points, and wireless end-host devices like smartphones - and laptops. + of IP routing and addressing, such as wireless routers, access points, and wireless end-host devices like + smartphones and laptops. This class should be extended by concrete classes that define specific behaviors and properties of an IP-capable wireless network interface. @@ -804,8 +826,10 @@ class Node(SimComponent): { "hostname": self.hostname, "operating_state": self.operating_state.value, - "NICs": {eth_num: network_interface.describe_state() for eth_num, network_interface in - self.network_interface.items()}, + "NICs": { + eth_num: network_interface.describe_state() + for eth_num, network_interface in self.network_interface.items() + }, "file_system": self.file_system.describe_state(), "applications": {app.name: app.describe_state() for app in self.applications.values()}, "services": {svc.name: svc.describe_state() for svc in self.services.values()}, @@ -816,7 +840,7 @@ class Node(SimComponent): return state def show(self, markdown: bool = False): - "Show function that calls both show NIC and show open ports." + """Show function that calls both show NIC and show open ports.""" self.show_nic(markdown) self.show_open_ports(markdown) @@ -833,6 +857,14 @@ class Node(SimComponent): @property def has_enabled_network_interface(self) -> bool: + """ + Checks if the node has at least one enabled network interface. + + Iterates through all network interfaces associated with the node to determine if at least one is enabled. This + property is essential for determining the node's ability to communicate within the network. + + :return: True if there is at least one enabled network interface; otherwise, False. + """ for network_interface in self.network_interfaces.values(): if network_interface.enabled: return True @@ -1014,7 +1046,7 @@ class Node(SimComponent): """ if self.operating_state.ON: self.is_resetting = True - self.sys_log.info(f"Resetting") + self.sys_log.info("Resetting") self.power_off() def connect_nic(self, network_interface: NetworkInterface): @@ -1097,7 +1129,7 @@ class Node(SimComponent): self.software_manager.arp.add_arp_cache_entry( ip_address=frame.ip.src_ip_address, mac_address=frame.ethernet.src_mac_addr, - network_interface=from_network_interface + network_interface=from_network_interface, ) else: return diff --git a/src/primaite/simulator/network/hardware/network_interface/layer_3_interface.py b/src/primaite/simulator/network/hardware/network_interface/layer_3_interface.py deleted file mode 100644 index fdfd3b26..00000000 --- a/src/primaite/simulator/network/hardware/network_interface/layer_3_interface.py +++ /dev/null @@ -1,9 +0,0 @@ -from abc import ABC -from ipaddress import IPv4Network -from typing import Dict - -from pydantic import BaseModel - -from primaite.utils.validators import IPV4Address - - diff --git a/src/primaite/simulator/network/hardware/network_interface/wired/__init__.py b/src/primaite/simulator/network/hardware/network_interface/wired/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/primaite/simulator/network/hardware/network_interface/wired/router_interface.py b/src/primaite/simulator/network/hardware/network_interface/wired/router_interface.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py index f94b7faa..646c12f4 100644 --- a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py +++ b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py @@ -2,7 +2,6 @@ from typing import Dict from primaite.simulator.network.hardware.base import WirelessNetworkInterface from primaite.simulator.network.hardware.network_interface.layer_3_interface import Layer3Interface - from primaite.simulator.network.transmission.data_link_layer import Frame @@ -81,4 +80,4 @@ class WirelessAccessPoint(WirelessNetworkInterface, Layer3Interface): :return: A string combining the port number, MAC address and IP address of the NIC. """ - return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" \ No newline at end of file + return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" diff --git a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py index 12172608..40f357a0 100644 --- a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py +++ b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py @@ -2,7 +2,6 @@ from typing import Dict from primaite.simulator.network.hardware.base import WirelessNetworkInterface from primaite.simulator.network.hardware.network_interface.layer_3_interface import Layer3Interface - from primaite.simulator.network.transmission.data_link_layer import Frame @@ -78,4 +77,4 @@ class WirelessNIC(WirelessNetworkInterface, Layer3Interface): :return: A string combining the port number, MAC address and IP address of the NIC. """ - return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" \ No newline at end of file + return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" diff --git a/src/primaite/simulator/network/hardware/nodes/host/computer.py b/src/primaite/simulator/network/hardware/nodes/host/computer.py index dc75df69..0b13163e 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/computer.py +++ b/src/primaite/simulator/network/hardware/nodes/host/computer.py @@ -28,5 +28,5 @@ class Computer(HostNode): * Applications: * Web Browser """ - pass + pass diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index bd13e7e2..17390751 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -1,15 +1,13 @@ from __future__ import annotations -from typing import Dict, Any -from typing import Optional +from ipaddress import IPv4Address +from typing import Any, Dict, Optional from primaite import getLogger -from primaite.simulator.network.hardware.base import IPWiredNetworkInterface, Link -from primaite.simulator.network.hardware.base import Node +from primaite.simulator.network.hardware.base import IPWiredNetworkInterface, Link, Node from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.transmission.data_link_layer import Frame from primaite.simulator.system.applications.web_browser import WebBrowser -from primaite.simulator.system.core.packet_capture import PacketCapture from primaite.simulator.system.services.arp.arp import ARP, ARPPacket from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.ftp.ftp_client import FTPClient @@ -20,43 +18,45 @@ from primaite.utils.validators import IPV4Address _LOGGER = getLogger(__name__) -# Lives here due to pydantic circular dependency issue :( class HostARP(ARP): """ The Host ARP Service. - Extends the ARP service with functionalities specific to a host within the network. It provides mechanisms to - resolve and cache MAC addresses and NICs for given IP addresses, focusing on the host's perspective, including - handling the default gateway. + Extends the ARP service for host-specific functionalities within a network, focusing on resolving and caching + MAC addresses and network interfaces (NICs) based on IP addresses, especially concerning the default gateway. + + This specialized ARP service for hosts facilitates efficient network communication by managing ARP entries + and handling ARP requests and replies with additional logic for default gateway processing. """ def get_default_gateway_mac_address(self) -> Optional[str]: """ - Retrieves the MAC address of the default gateway from the ARP cache. + Retrieves the MAC address of the default gateway as known from the ARP cache. - :return: The MAC address of the default gateway if it exists in the ARP cache, otherwise None. + :return: The MAC address of the default gateway if present in the ARP cache; otherwise, None. """ if self.software_manager.node.default_gateway: return self.get_arp_cache_mac_address(self.software_manager.node.default_gateway) def get_default_gateway_network_interface(self) -> Optional[NIC]: """ - Retrieves the NIC associated with the default gateway from the ARP cache. + Obtains the network interface card (NIC) associated with the default gateway from the ARP cache. - :return: The NIC associated with the default gateway if it exists in the ARP cache, otherwise None. + :return: The NIC associated with the default gateway if it exists in the ARP cache; otherwise, None. """ if self.software_manager.node.default_gateway and self.software_manager.node.has_enabled_network_interface: return self.get_arp_cache_network_interface(self.software_manager.node.default_gateway) def _get_arp_cache_mac_address( - self, ip_address: IPV4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False + self, ip_address: IPV4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False ) -> Optional[str]: """ Internal method to retrieve the MAC address associated with an IP address from the ARP cache. :param ip_address: The IP address whose MAC address is to be retrieved. :param is_reattempt: Indicates if this call is a reattempt after a failed initial attempt. - :param is_default_gateway_attempt: Indicates if this call is an attempt to get the default gateway's MAC address. + :param is_default_gateway_attempt: Indicates if this call is an attempt to get the default gateway's MAC + address. :return: The MAC address associated with the IP address if found, otherwise None. """ arp_entry = self.arp.get(ip_address) @@ -76,22 +76,23 @@ class HostARP(ARP): if not is_default_gateway_attempt: self.send_arp_request(self.software_manager.node.default_gateway) return self._get_arp_cache_mac_address( - ip_address=self.software_manager.node.default_gateway, is_reattempt=True, - is_default_gateway_attempt=True + ip_address=self.software_manager.node.default_gateway, + is_reattempt=True, + is_default_gateway_attempt=True, ) return None - def get_arp_cache_mac_address(self, ip_address: IPV4Address) -> Optional[str]: + def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: """ - Retrieves the MAC address associated with an IP address from the ARP cache. + Retrieves the MAC address associated with a given IP address from the ARP cache. - :param ip_address: The IP address whose MAC address is to be retrieved. - :return: The MAC address associated with the IP address if found, otherwise None. - """ + :param ip_address: The IP address for which the MAC address is sought. + :return: The MAC address if available in the ARP cache; otherwise, None. + """ return self._get_arp_cache_mac_address(ip_address) def _get_arp_cache_network_interface( - self, ip_address: IPV4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False + self, ip_address: IPV4Address, is_reattempt: bool = False, is_default_gateway_attempt: bool = False ) -> Optional[NIC]: """ Internal method to retrieve the NIC associated with an IP address from the ARP cache. @@ -118,17 +119,18 @@ class HostARP(ARP): if not is_default_gateway_attempt: self.send_arp_request(self.software_manager.node.default_gateway) return self._get_arp_cache_network_interface( - ip_address=self.software_manager.node.default_gateway, is_reattempt=True, - is_default_gateway_attempt=True + ip_address=self.software_manager.node.default_gateway, + is_reattempt=True, + is_default_gateway_attempt=True, ) return None - def get_arp_cache_network_interface(self, ip_address: IPV4Address) -> Optional[NIC]: + def get_arp_cache_network_interface(self, ip_address: IPv4Address) -> Optional[NIC]: """ - Retrieves the NIC associated with an IP address from the ARP cache. + Retrieves the network interface card (NIC) associated with a given IP address from the ARP cache. - :param ip_address: The IP address whose NIC is to be retrieved. - :return: The NIC associated with the IP address if found, otherwise None. + :param ip_address: The IP address for which the associated NIC is sought. + :return: The NIC if available in the ARP cache; otherwise, None. """ return self._get_arp_cache_network_interface(ip_address) @@ -146,15 +148,17 @@ class HostARP(ARP): # Unmatched ARP Request if arp_packet.target_ip_address != from_network_interface.ip_address: self.sys_log.info( - f"Ignoring ARP request for {arp_packet.target_ip_address}. Current IP address is {from_network_interface.ip_address}" + f"Ignoring ARP request for {arp_packet.target_ip_address}. Current IP address is " + f"{from_network_interface.ip_address}" ) return # Matched ARP request # TODO: try taking this out self.add_arp_cache_entry( - ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, - network_interface=from_network_interface + ip_address=arp_packet.sender_ip_address, + mac_address=arp_packet.sender_mac_addr, + network_interface=from_network_interface, ) arp_packet = arp_packet.generate_reply(from_network_interface.mac_address) self.send_arp_reply(arp_packet) @@ -175,12 +179,25 @@ class NIC(IPWiredNetworkInterface): and disconnect from network links and to manage the enabled/disabled state of the interface. - Layer3Interface: Provides properties for Layer 3 network configuration, such as IP address and subnet mask. """ + _connected_link: Optional[Link] = None "The network link to which the network interface is connected." wake_on_lan: bool = False "Indicates if the NIC supports Wake-on-LAN functionality." def model_post_init(self, __context: Any) -> None: + """ + Performs post-initialisation checks to ensure the model's IP configuration is valid. + + This method is invoked after the initialisation of a network model object to validate its network settings, + particularly to ensure that the assigned IP address is not a network address. This validation is crucial for + maintaining the integrity of network simulations and avoiding configuration errors that could lead to + unrealistic or incorrect behavior. + + :param __context: Contextual information or parameters passed to the method, used for further initializing or + validating the model post-creation. + :raises ValueError: If the IP address is the same as the network address, indicating an incorrect configuration. + """ if self.ip_network.network_address == self.ip_address: raise ValueError(f"{self.ip_address}/{self.subnet_mask} must not be a network address") @@ -255,21 +272,24 @@ class HostNode(Node): """ Represents a host node in the network. - Extends the basic functionality of a Node with host-specific services and applications. A host node typically - represents an end-user device in the network, such as a Computer or a Server, and is capable of initiating and - responding to network communications. + An end-user device within the network, such as a computer or server, equipped with the capability to initiate and + respond to network communications. + + A `HostNode` extends the base `Node` class by incorporating host-specific services and applications, thereby + simulating the functionalities typically expected from a networked end-user device. + + **Example**:: - Example: >>> pc_a = HostNode( - hostname="pc_a", - ip_address="192.168.1.10", - subnet_mask="255.255.255.0", - default_gateway="192.168.1.1" - ) + ... hostname="pc_a", + ... ip_address="192.168.1.10", + ... subnet_mask="255.255.255.0", + ... default_gateway="192.168.1.1" + ... ) >>> pc_a.power_on() - The host comes pre-installed with core functionalities and a suite of services and applications, making it ready - for various network operations and tasks. These include: + The host node comes pre-equipped with a range of core functionalities, services, and applications necessary + for engaging in various network operations and tasks. Core Functionality: ------------------- @@ -291,6 +311,7 @@ class HostNode(Node): * Web Browser: Provides web browsing capabilities. """ + network_interfaces: Dict[str, NIC] = {} "The Network Interfaces on the node." network_interface: Dict[int, NIC] = {} @@ -301,7 +322,12 @@ class HostNode(Node): self.connect_nic(NIC(ip_address=ip_address, subnet_mask=subnet_mask)) def _install_system_software(self): - """Install System Software - software that is usually provided with the OS.""" + """ + Installs the system software and network services typically found on an operating system. + + This method equips the host with essential network services and applications, preparing it for various + network-related tasks and operations. + """ # ARP Service self.software_manager.install(HostARP) @@ -323,6 +349,12 @@ class HostNode(Node): super()._install_system_software() def default_gateway_hello(self): + """ + Sends a hello message to the default gateway to establish connectivity and resolve the gateway's MAC address. + + This method is invoked to ensure the host node can communicate with its default gateway, primarily to confirm + network connectivity and populate the ARP cache with the gateway's MAC address. + """ if self.operating_state == NodeOperatingState.ON and self.default_gateway: self.software_manager.arp.get_default_gateway_mac_address() diff --git a/src/primaite/simulator/network/hardware/nodes/host/server.py b/src/primaite/simulator/network/hardware/nodes/host/server.py index 148a277f..9f5157ad 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/server.py +++ b/src/primaite/simulator/network/hardware/nodes/host/server.py @@ -28,4 +28,3 @@ class Server(HostNode): * Applications: * Web Browser """ - diff --git a/src/primaite/simulator/network/hardware/nodes/network/network_node.py b/src/primaite/simulator/network/hardware/nodes/network/network_node.py index c7a2060b..ebdb6ed8 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/network_node.py +++ b/src/primaite/simulator/network/hardware/nodes/network/network_node.py @@ -1,9 +1,30 @@ -from primaite.simulator.network.hardware.base import Node, NetworkInterface +from abc import abstractmethod + +from primaite.simulator.network.hardware.base import NetworkInterface, Node from primaite.simulator.network.transmission.data_link_layer import Frame class NetworkNode(Node): - """""" + """ + Represents an abstract base class for a network node that can receive and process network frames. + This class provides a common interface for network nodes such as routers and switches, defining the essential + behavior that allows these devices to handle incoming network traffic. Implementations of this class must + provide functionality for receiving and processing frames received on their network interfaces. + """ + + @abstractmethod def receive_frame(self, frame: Frame, from_network_interface: NetworkInterface): + """ + Abstract method that must be implemented by subclasses to define how to receive and process frames. + + This method is called when a frame is received by a network interface belonging to this node. Subclasses + should implement the logic to process the frame, including examining its contents, making forwarding decisions, + or performing any necessary actions based on the frame's protocol and destination. + + :param frame: The network frame that has been received. + :type frame: Frame + :param from_network_interface: The network interface on which the frame was received. + :type from_network_interface: NetworkInterface + """ pass diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index e5f4cdcd..3a22931e 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -3,25 +3,22 @@ from __future__ import annotations import secrets from enum import Enum from ipaddress import IPv4Address, IPv4Network -from typing import Dict, Any -from typing import List, Optional, Tuple, Union +from typing import Any, Dict, List, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable -from pydantic import ValidationError from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import IPWiredNetworkInterface from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.network.network_node import NetworkNode from primaite.simulator.network.protocols.arp import ARPPacket -from primaite.simulator.network.protocols.icmp import ICMPType, ICMPPacket +from primaite.simulator.network.protocols.icmp import ICMPPacket, ICMPType from primaite.simulator.network.transmission.data_link_layer import Frame from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.services.arp.arp import ARP from primaite.simulator.system.services.icmp.icmp import ICMP -from primaite.utils.validators import IPV4Address class ACLAction(Enum): @@ -205,14 +202,14 @@ class AccessControlList(SimComponent): return self._acl def add_rule( - self, - action: ACLAction, - protocol: Optional[IPProtocol] = None, - src_ip_address: Optional[Union[str, IPv4Address]] = None, - src_port: Optional[Port] = None, - dst_ip_address: Optional[Union[str, IPv4Address]] = None, - dst_port: Optional[Port] = None, - position: int = 0, + self, + action: ACLAction, + protocol: Optional[IPProtocol] = None, + src_ip_address: Optional[Union[str, IPv4Address]] = None, + src_port: Optional[Port] = None, + dst_ip_address: Optional[Union[str, IPv4Address]] = None, + dst_port: Optional[Port] = None, + position: int = 0, ) -> None: """ Add a new ACL rule. @@ -259,12 +256,12 @@ class AccessControlList(SimComponent): raise ValueError(f"Cannot remove ACL rule, position {position} is out of bounds.") def is_permitted( - self, - protocol: IPProtocol, - src_ip_address: Union[str, IPv4Address], - src_port: Optional[Port], - dst_ip_address: Union[str, IPv4Address], - dst_port: Optional[Port], + self, + protocol: IPProtocol, + src_ip_address: Union[str, IPv4Address], + src_port: Optional[Port], + dst_ip_address: Union[str, IPv4Address], + dst_port: Optional[Port], ) -> Tuple[bool, Optional[Union[str, ACLRule]]]: """ Check if a packet with the given properties is permitted through the ACL. @@ -286,23 +283,23 @@ class AccessControlList(SimComponent): continue if ( - (rule.src_ip_address == src_ip_address or rule.src_ip_address is None) - and (rule.dst_ip_address == dst_ip_address or rule.dst_ip_address is None) - and (rule.protocol == protocol or rule.protocol is None) - and (rule.src_port == src_port or rule.src_port is None) - and (rule.dst_port == dst_port or rule.dst_port is None) + (rule.src_ip_address == src_ip_address or rule.src_ip_address is None) + and (rule.dst_ip_address == dst_ip_address or rule.dst_ip_address is None) + and (rule.protocol == protocol or rule.protocol is None) + and (rule.src_port == src_port or rule.src_port is None) + and (rule.dst_port == dst_port or rule.dst_port is None) ): return rule.action == ACLAction.PERMIT, rule return self.implicit_action == ACLAction.PERMIT, f"Implicit {self.implicit_action.name}" def get_relevant_rules( - self, - protocol: IPProtocol, - src_ip_address: Union[str, IPv4Address], - src_port: Port, - dst_ip_address: Union[str, IPv4Address], - dst_port: Port, + self, + protocol: IPProtocol, + src_ip_address: Union[str, IPv4Address], + src_port: Port, + dst_ip_address: Union[str, IPv4Address], + dst_port: Port, ) -> List[ACLRule]: """ Get the list of relevant rules for a packet with given properties. @@ -324,11 +321,11 @@ class AccessControlList(SimComponent): continue if ( - (rule.src_ip_address == src_ip_address or rule.src_ip_address is None) - or (rule.dst_ip_address == dst_ip_address or rule.dst_ip_address is None) - or (rule.protocol == protocol or rule.protocol is None) - or (rule.src_port == src_port or rule.src_port is None) - or (rule.dst_port == dst_port or rule.dst_port is None) + (rule.src_ip_address == src_ip_address or rule.src_ip_address is None) + or (rule.dst_ip_address == dst_ip_address or rule.dst_ip_address is None) + or (rule.protocol == protocol or rule.protocol is None) + or (rule.src_port == src_port or rule.src_port is None) + or (rule.dst_port == dst_port or rule.dst_port is None) ): relevant_rules.append(rule) @@ -445,11 +442,11 @@ class RouteTable(SimComponent): pass def add_route( - self, - address: Union[IPv4Address, str], - subnet_mask: Union[IPv4Address, str], - next_hop_ip_address: Union[IPv4Address, str], - metric: float = 0.0, + self, + address: Union[IPv4Address, str], + subnet_mask: Union[IPv4Address, str], + next_hop_ip_address: Union[IPv4Address, str], + metric: float = 0.0, ): """ Add a route to the routing table. @@ -539,16 +536,34 @@ class RouteTable(SimComponent): class RouterARP(ARP): """ - Inherits from ARPCache and adds router-specific ARP packet processing. + Extends ARP functionality with router-specific ARP packet processing capabilities. - :ivar SysLog sys_log: A system log for logging messages. - :ivar Router router: The router to which this ARP cache belongs. + This class is designed to manage ARP requests and replies within a router, handling both the resolution of MAC + addresses for IP addresses within the router's networks and the forwarding of ARP requests to other networks + based on routing information. """ + router: Optional[Router] = None def _get_arp_cache_mac_address( - self, ip_address: IPV4Address, is_reattempt: bool = False, is_default_route_attempt: bool = False + self, ip_address: IPv4Address, is_reattempt: bool = False, is_default_route_attempt: bool = False ) -> Optional[str]: + """ + Attempts to retrieve the MAC address associated with the given IP address from the ARP cache. + + If the address is not in the cache, an ARP request may be sent, and the method may reattempt the lookup. + + :param ip_address: The IP address for which to find the corresponding MAC address. + :type ip_address: IPv4Address + :param is_reattempt: Indicates whether this call is a reattempt after a failed initial attempt to find the MAC + address. + :type is_reattempt: bool + :param is_default_route_attempt: Indicates whether the attempt is being made to resolve the MAC address for the + default route. + :type is_default_route_attempt: bool + :return: The MAC address associated with the given IP address, if found; otherwise, None. + :rtype: Optional[str] + """ arp_entry = self.arp.get(ip_address) if arp_entry: @@ -558,9 +573,7 @@ class RouterARP(ARP): if self.router.ip_is_in_router_interface_subnet(ip_address): self.send_arp_request(ip_address) return self._get_arp_cache_mac_address( - ip_address=ip_address, - is_reattempt=True, - is_default_route_attempt=is_default_route_attempt + ip_address=ip_address, is_reattempt=True, is_default_route_attempt=is_default_route_attempt ) route = self.router.route_table.find_best_route(ip_address) @@ -569,7 +582,7 @@ class RouterARP(ARP): return self._get_arp_cache_mac_address( ip_address=route.next_hop_ip_address, is_reattempt=True, - is_default_route_attempt=is_default_route_attempt + is_default_route_attempt=is_default_route_attempt, ) else: if self.router.route_table.default_route: @@ -578,16 +591,40 @@ class RouterARP(ARP): return self._get_arp_cache_mac_address( ip_address=self.router.route_table.default_route.next_hop_ip_address, is_reattempt=True, - is_default_route_attempt=True + is_default_route_attempt=True, ) return None def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: + """ + Public interface to retrieve the MAC address associated with the given IP address from the ARP cache. + + :param ip_address: The IP address for which to find the corresponding MAC address. + :type ip_address: IPv4Address + :return: The MAC address associated with the given IP address, if found; otherwise, None. + :rtype: Optional[str] + """ return self._get_arp_cache_mac_address(ip_address) def _get_arp_cache_network_interface( - self, ip_address: IPV4Address, is_reattempt: bool = False, is_default_route_attempt: bool = False + self, ip_address: IPv4Address, is_reattempt: bool = False, is_default_route_attempt: bool = False ) -> Optional[RouterInterface]: + """ + Attempts to retrieve the router interface associated with the given IP address. + + If the address is not directly associated with a router interface, it may send an ARP request based on + routing information. + + :param ip_address: The IP address for which to find the corresponding router interface. + :type ip_address: IPv4Address + :param is_reattempt: Indicates whether this call is a reattempt after a failed initial attempt. + :type is_reattempt: bool + :param is_default_route_attempt: Indicates whether the attempt is being made for the default route's next-hop + IP address. + :type is_default_route_attempt: bool + :return: The router interface associated with the given IP address, if applicable; otherwise, None. + :rtype: Optional[RouterInterface] + """ arp_entry = self.arp.get(ip_address) if arp_entry: return self.software_manager.node.network_interfaces[arp_entry.network_interface_uuid] @@ -603,7 +640,7 @@ class RouterARP(ARP): return self._get_arp_cache_network_interface( ip_address=route.next_hop_ip_address, is_reattempt=True, - is_default_route_attempt=is_default_route_attempt + is_default_route_attempt=is_default_route_attempt, ) else: if self.router.route_table.default_route: @@ -612,17 +649,32 @@ class RouterARP(ARP): return self._get_arp_cache_network_interface( ip_address=self.router.route_table.default_route.next_hop_ip_address, is_reattempt=True, - is_default_route_attempt=True + is_default_route_attempt=True, ) return None - - def get_arp_cache_network_interface(self, ip_address: IPv4Address) -> Optional[RouterInterface]: + """ + Public interface to retrieve the router interface associated with the given IP address. - return self._get_arp_cache_network_interface(ip_address) + :param ip_address: The IP address for which to find the corresponding router interface. + :type ip_address: IPv4Address + :return: The router interface associated with the given IP address, if found; otherwise, None. + :rtype: Optional[RouterInterface] + """ + return self._get_arp_cache_network_interface(ip_address) def _process_arp_request(self, arp_packet: ARPPacket, from_network_interface: RouterInterface): + """ + Processes an ARP request packet received on a router interface. + + If the target IP address matches the interface's IP address, generates and sends an ARP reply. + + :param arp_packet: The received ARP request packet. + :type arp_packet: ARPPacket + :param from_network_interface: The router interface on which the ARP request was received. + :type from_network_interface: RouterInterface + """ super()._process_arp_request(arp_packet, from_network_interface) # If the target IP matches one of the router's NICs @@ -632,6 +684,14 @@ class RouterARP(ARP): return def _process_arp_reply(self, arp_packet: ARPPacket, from_network_interface: RouterInterface): + """ + Processes an ARP reply packet received on a router interface. Updates the ARP cache with the new information. + + :param arp_packet: The received ARP reply packet. + :type arp_packet: ARPPacket + :param from_network_interface: The router interface on which the ARP reply was received. + :type from_network_interface: RouterInterface + """ if arp_packet.target_ip_address == from_network_interface.ip_address: super()._process_arp_reply(arp_packet, from_network_interface) @@ -650,7 +710,7 @@ class RouterICMP(ICMP): router: Optional[Router] = None - def _process_icmp_echo_request(self, frame: Frame, from_network_interface): + def _process_icmp_echo_request(self, frame: Frame, from_network_interface: RouterInterface): """ Processes an ICMP echo request received by the service. @@ -664,7 +724,8 @@ class RouterICMP(ICMP): if not network_interface: self.sys_log.error( - "Cannot send ICMP echo reply as there is no outbound Network Interface to use. Try configuring the default gateway." + "Cannot send ICMP echo reply as there is no outbound Network Interface to use. Try configuring the " + "default gateway." ) return @@ -682,7 +743,7 @@ class RouterICMP(ICMP): dst_ip_address=frame.ip.src_ip_address, dst_port=self.port, ip_protocol=self.protocol, - icmp_packet=icmp_packet + icmp_packet=icmp_packet, ) def receive(self, payload: Any, session_id: str, **kwargs) -> bool: @@ -815,11 +876,19 @@ class RouterInterface(IPWiredNetworkInterface): class Router(NetworkNode): """ - A class to represent a network router node. + Represents a network router, managing routing and forwarding of IP packets across network interfaces. - :ivar str hostname: The name of the router node. - :ivar int num_ports: The number of ports in the router. - :ivar dict kwargs: Optional keyword arguments for SysLog, ACL, RouteTable, RouterARP, RouterICMP. + A router operates at the network layer and is responsible for receiving, processing, and forwarding data packets + between computer networks. It examines the destination IP address of incoming packets and determines the best way + to route them towards their destination. + + The router integrates various network services and protocols to facilitate IP routing, including ARP (Address + Resolution Protocol) and ICMP (Internet Control Message Protocol) for handling network diagnostics and errors. + + :ivar str hostname: The name of the router, used for identification and logging. + :ivar int num_ports: The number of physical or logical ports on the router. + :ivar dict kwargs: Optional keyword arguments for initializing components like SysLog, ACL (Access Control List), + RouteTable, RouterARP, and RouterICMP services. """ num_ports: int @@ -848,7 +917,13 @@ class Router(NetworkNode): self.set_original_state() def _install_system_software(self): - """Install System Software - software that is usually provided with the OS.""" + """ + Installs essential system software and network services on the router. + + This includes initializing and setting up RouterICMP for handling ICMP packets and RouterARP for address + resolution within the network. These services are crucial for the router's operation, enabling it to manage + network traffic efficiently. + """ self.software_manager.install(RouterICMP) icmp: RouterICMP = self.software_manager.icmp # noqa icmp.router = self @@ -857,11 +932,22 @@ class Router(NetworkNode): arp.router = self def _set_default_acl(self): + """ + Sets default access control rules for the router. + + Initializes the router's ACL (Access Control List) with default rules, permitting essential protocols like ARP + and ICMP, which are necessary for basic network operations and diagnostics. + """ self.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) self.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) def set_original_state(self): - """Sets the original state.""" + """ + Sets or resets the router to its original configuration state. + + This method is called to initialize the router's state or to revert it to a known good configuration during + network simulations or after configuration changes. + """ self.acl.set_original_state() self.route_table.set_original_state() super().set_original_state() @@ -869,7 +955,14 @@ class Router(NetworkNode): self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" + """ + Resets the router's components for a new network simulation episode. + + Clears ARP cache, resets ACL and route table to their original states, and re-enables all network interfaces. + This ensures that the router starts from a clean state for each simulation episode. + + :param episode: The episode number for which the router is being reset. + """ self.software_manager.arp.clear() self.acl.reset_component_for_episode(episode) self.route_table.reset_component_for_episode(episode) @@ -884,7 +977,14 @@ class Router(NetworkNode): rm.add_request("acl", RequestType(func=self.acl._request_manager)) return rm - def ip_is_router_interface(self, ip_address: IPV4Address, enabled_only: bool = False) -> bool: + def ip_is_router_interface(self, ip_address: IPv4Address, enabled_only: bool = False) -> bool: + """ + Checks if a given IP address belongs to any of the router's interfaces. + + :param ip_address: The IP address to check. + :param enabled_only: If True, only considers enabled network interfaces. + :return: True if the IP address is assigned to one of the router's interfaces; False otherwise. + """ for router_interface in self.network_interface.values(): if router_interface.ip_address == ip_address: if enabled_only: @@ -893,7 +993,14 @@ class Router(NetworkNode): return True return False - def ip_is_in_router_interface_subnet(self, ip_address: IPV4Address, enabled_only: bool = False) -> bool: + def ip_is_in_router_interface_subnet(self, ip_address: IPv4Address, enabled_only: bool = False) -> bool: + """ + Determines if a given IP address falls within the subnet of any router interface. + + :param ip_address: The IP address to check. + :param enabled_only: If True, only considers enabled network interfaces. + :return: True if the IP address is within the subnet of any router's interface; False otherwise. + """ for router_interface in self.network_interface.values(): if ip_address in router_interface.ip_network: if enabled_only: @@ -904,10 +1011,10 @@ class Router(NetworkNode): def _get_port_of_nic(self, target_nic: RouterInterface) -> Optional[int]: """ - Retrieve the port number for a given NIC. + Retrieves the port number associated with a given network interface controller (NIC). - :param target_nic: Target network interface. - :return: The port number if NIC is found, otherwise None. + :param target_nic: The NIC whose port number is being queried. + :return: The port number if the NIC is found; otherwise, None. """ for port, network_interface in self.network_interface.items(): if network_interface == target_nic: @@ -926,12 +1033,14 @@ class Router(NetworkNode): def receive_frame(self, frame: Frame, from_network_interface: RouterInterface): """ - Receive a frame from a RouterInterface and processes it based on its protocol. + Processes an incoming frame received on one of the router's interfaces. - :param frame: The incoming frame. - :param from_network_interface: The network interface where the frame is coming from. + Examines the frame's destination and protocol, applies ACL rules, and either forwards or drops the frame based + on routing decisions and ACL permissions. + + :param frame: The incoming frame to be processed. + :param from_network_interface: The router interface on which the frame was received. """ - if self.operating_state != NodeOperatingState.ON: return @@ -965,12 +1074,13 @@ class Router(NetworkNode): self.software_manager.arp.add_arp_cache_entry( ip_address=frame.ip.src_ip_address, mac_address=frame.ethernet.src_mac_addr, - network_interface=from_network_interface + network_interface=from_network_interface, ) send_to_session_manager = False - if ((frame.icmp and self.ip_is_router_interface(dst_ip_address)) - or (dst_port in self.software_manager.get_open_ports())): + if (frame.icmp and self.ip_is_router_interface(dst_ip_address)) or ( + dst_port in self.software_manager.get_open_ports() + ): send_to_session_manager = True if send_to_session_manager: @@ -981,17 +1091,20 @@ class Router(NetworkNode): def process_frame(self, frame: Frame, from_network_interface: RouterInterface) -> None: """ - Process a Frame. + Routes or forwards a frame based on the router's routing table and interface configurations. - :param frame: The frame to be routed. - :param from_network_interface: The source network interface. + This method is called if a frame is not directly addressed to the router or does not match any open service + ports. It determines the next hop for the frame and forwards it accordingly. + + :param frame: The frame to be routed or forwarded. + :param from_network_interface: The network interface from which the frame originated. """ # check if frame is addressed to this Router but has failed to be received by a service of application at the # receive_frame stage if frame.ip: for network_interface in self.network_interfaces.values(): if network_interface.ip_address == frame.ip.dst_ip_address: - self.sys_log.info(f"Dropping frame destined for this router on a port that isn't open.") + self.sys_log.info("Dropping frame destined for this router on a port that isn't open.") return network_interface: RouterInterface = self.software_manager.arp.get_arp_cache_network_interface( @@ -1031,6 +1144,15 @@ class Router(NetworkNode): self.route_frame(frame, from_network_interface) def route_frame(self, frame: Frame, from_network_interface: RouterInterface) -> None: + """ + Determines the best route for a frame and forwards it towards its destination. + + Uses the router's routing table to find the best route for the frame's destination IP address and forwards the + frame through the appropriate interface. + + :param frame: The frame to be routed. + :param from_network_interface: The source network interface. + """ route = self.route_table.find_best_route(frame.ip.dst_ip_address) if route: network_interface = self.software_manager.arp.get_arp_cache_network_interface(route.next_hop_ip_address) @@ -1059,11 +1181,11 @@ class Router(NetworkNode): def configure_port(self, port: int, ip_address: Union[IPv4Address, str], subnet_mask: Union[IPv4Address, str]): """ - Configure the IP settings of a given port. + Configures the IP settings for a specified router port. - :param port: The port to configure. - :param ip_address: The IP address to set. - :param subnet_mask: The subnet mask to set. + :param port: The port number to configure. + :param ip_address: The IP address to assign to the port. + :param subnet_mask: The subnet mask for the port. """ if not isinstance(ip_address, IPv4Address): ip_address = IPv4Address(ip_address) @@ -1072,16 +1194,14 @@ class Router(NetworkNode): network_interface = self.network_interface[port] network_interface.ip_address = ip_address network_interface.subnet_mask = subnet_mask - self.sys_log.info( - f"Configured Network Interface {network_interface}" - ) + self.sys_log.info(f"Configured Network Interface {network_interface}") self.set_original_state() def enable_port(self, port: int): """ - Enable a given port on the router. + Enables a specified port on the router. - :param port: The port to enable. + :param port: The port number to enable. """ network_interface = self.network_interface.get(port) if network_interface: @@ -1089,9 +1209,9 @@ class Router(NetworkNode): def disable_port(self, port: int): """ - Disable a given port on the router. + Disables a specified port on the router. - :param port: The port to disable. + :param port: The port number to disable. """ network_interface = self.network_interface.get(port) if network_interface: diff --git a/src/primaite/simulator/network/hardware/nodes/network/switch.py b/src/primaite/simulator/network/hardware/nodes/network/switch.py index 1878aab7..33e6ee9a 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/network/switch.py @@ -1,11 +1,12 @@ from __future__ import annotations + from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.exceptions import NetworkError -from primaite.simulator.network.hardware.base import WiredNetworkInterface, NetworkInterface, Link +from primaite.simulator.network.hardware.base import Link, WiredNetworkInterface from primaite.simulator.network.hardware.nodes.network.network_node import NetworkNode from primaite.simulator.network.transmission.data_link_layer import Frame @@ -27,6 +28,7 @@ class SwitchPort(WiredNetworkInterface): Switch ports typically do not have IP addresses assigned to them as they function at Layer 2, but managed switches can have management IP addresses for remote management and configuration purposes. """ + _connected_node: Optional[Switch] = None "The Switch to which the SwitchPort is connected." @@ -40,7 +42,6 @@ class SwitchPort(WiredNetworkInterface): """ Produce a dictionary describing the current state of this object. - :return: Current state of this object and child objects. :rtype: Dict """ diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index f830ad70..f82dee4a 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -1,11 +1,10 @@ from ipaddress import IPv4Address from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.base import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC -from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -56,7 +55,7 @@ def client_server_routed() -> Network: ip_address="192.168.2.2", subnet_mask="255.255.255.0", default_gateway="192.168.2.1", - start_up_duration=0 + start_up_duration=0, ) client_1.power_on() network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1]) @@ -67,7 +66,7 @@ def client_server_routed() -> Network: ip_address="192.168.1.2", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", - start_up_duration=0 + start_up_duration=0, ) server_1.power_on() network.connect(endpoint_b=server_1.network_interface[1], endpoint_a=switch_1.network_interface[1]) @@ -143,7 +142,7 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.10.1", dns_server=IPv4Address("192.168.1.10"), - start_up_duration=0 + start_up_duration=0, ) client_1.power_on() network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1]) @@ -163,7 +162,7 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.10.1", dns_server=IPv4Address("192.168.1.10"), - start_up_duration=0 + start_up_duration=0, ) client_2.power_on() web_browser = client_2.software_manager.software.get("WebBrowser") @@ -176,7 +175,7 @@ def arcd_uc2_network() -> Network: ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", - start_up_duration=0 + start_up_duration=0, ) domain_controller.power_on() domain_controller.software_manager.install(DNSServer) @@ -190,7 +189,7 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.1.1", dns_server=IPv4Address("192.168.1.10"), - start_up_duration=0 + start_up_duration=0, ) database_server.power_on() network.connect(endpoint_b=database_server.network_interface[1], endpoint_a=switch_1.network_interface[3]) @@ -264,7 +263,7 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.1.1", dns_server=IPv4Address("192.168.1.10"), - start_up_duration=0 + start_up_duration=0, ) web_server.power_on() web_server.software_manager.install(DatabaseClient) @@ -288,7 +287,7 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.1.1", dns_server=IPv4Address("192.168.1.10"), - start_up_duration=0 + start_up_duration=0, ) backup_server.power_on() backup_server.software_manager.install(FTPServer) @@ -301,7 +300,7 @@ def arcd_uc2_network() -> Network: subnet_mask="255.255.255.0", default_gateway="192.168.1.1", dns_server=IPv4Address("192.168.1.10"), - start_up_duration=0 + start_up_duration=0, ) security_suite.power_on() network.connect(endpoint_b=security_suite.network_interface[1], endpoint_a=switch_1.network_interface[7]) diff --git a/src/primaite/simulator/network/protocols/icmp.py b/src/primaite/simulator/network/protocols/icmp.py index 9f761393..66215db0 100644 --- a/src/primaite/simulator/network/protocols/icmp.py +++ b/src/primaite/simulator/network/protocols/icmp.py @@ -111,4 +111,4 @@ class ICMPPacket(BaseModel): return description msg = f"No Matching ICMP code for type:{self.icmp_type.name}, code:{self.icmp_code}" _LOGGER.error(msg) - raise ValueError(msg) \ No newline at end of file + raise ValueError(msg) diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index 5c25df01..27d40df0 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -4,7 +4,6 @@ from typing import Any, Optional from pydantic import BaseModel from primaite import getLogger -from primaite.simulator.network.protocols.arp import ARPPacket from primaite.simulator.network.protocols.icmp import ICMPPacket from primaite.simulator.network.protocols.packet import DataPacket from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol diff --git a/src/primaite/simulator/network/transmission/network_layer.py b/src/primaite/simulator/network/transmission/network_layer.py index 38fc1977..c6328a60 100644 --- a/src/primaite/simulator/network/transmission/network_layer.py +++ b/src/primaite/simulator/network/transmission/network_layer.py @@ -1,10 +1,7 @@ -import secrets from enum import Enum -from ipaddress import IPv4Address, IPv4Network -from typing import Union +from ipaddress import IPv4Address -from pydantic import BaseModel, field_validator, validate_call -from pydantic_core.core_schema import FieldValidationInfo +from pydantic import BaseModel from primaite import getLogger diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index 5d34fd63..3f34cad8 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -108,4 +108,3 @@ class PacketCapture: """ msg = frame.model_dump_json() self.outbound_logger.log(level=60, msg=msg) # Log at custom log level > CRITICAL - diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 4ef10a14..3fa2aa97 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -102,7 +102,7 @@ class SessionManager: @staticmethod def _get_session_key( - frame: Frame, inbound_frame: bool = True + frame: Frame, inbound_frame: bool = True ) -> Tuple[IPProtocol, IPv4Address, Optional[Port], Optional[Port]]: """ Extracts the session key from the given frame. @@ -140,27 +140,76 @@ class SessionManager: dst_port = None return protocol, with_ip_address, src_port, dst_port - def resolve_outbound_network_interface(self, dst_ip_address: IPv4Address) -> Optional['NetworkInterface']: + def resolve_outbound_network_interface(self, dst_ip_address: IPv4Address) -> Optional["NetworkInterface"]: + """ + Resolves the appropriate outbound network interface for a given destination IP address. + + This method determines the most suitable network interface for sending a packet to the specified + destination IP address. It considers only enabled network interfaces and checks if the destination + IP address falls within the subnet of each interface. If no suitable local network interface is found, + the method defaults to using the network interface associated with the default gateway. + + The search process prioritises local network interfaces based on the IP network to which they belong. + If the destination IP address does not match any local subnet, the method assumes that the destination + is outside the local network and hence, routes the packet through the default gateway's network interface. + + :param dst_ip_address: The destination IP address for which the outbound interface is to be resolved. + :type dst_ip_address: IPv4Address + :return: The network interface through which the packet should be sent to reach the destination IP address, + or the default gateway's network interface if the destination is not within any local subnet. + :rtype: Optional["NetworkInterface"] + """ for network_interface in self.node.network_interfaces.values(): if dst_ip_address in network_interface.ip_network and network_interface.enabled: return network_interface return self.software_manager.arp.get_default_gateway_network_interface() def resolve_outbound_transmission_details( - self, - dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, - src_port: Optional[Port] = None, - dst_port: Optional[Port] = None, - protocol: Optional[IPProtocol] = None, - session_id: Optional[str] = None + self, + dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, + src_port: Optional[Port] = None, + dst_port: Optional[Port] = None, + protocol: Optional[IPProtocol] = None, + session_id: Optional[str] = None, ) -> Tuple[ - Optional['NetworkInterface'], - Optional[str], IPv4Address, + Optional["NetworkInterface"], + Optional[str], + IPv4Address, Optional[Port], Optional[Port], Optional[IPProtocol], - bool + bool, ]: + """ + Resolves the necessary details for outbound transmission based on the provided parameters. + + This method determines whether the payload should be broadcast or unicast based on the destination IP address + and resolves the outbound network interface and destination MAC address accordingly. + + The method first checks if `session_id` is provided and uses the session details if available. For broadcast + transmissions, it finds a suitable network interface and uses a broadcast MAC address. For unicast + transmissions, it attempts to resolve the destination MAC address using ARP and finds the appropriate + outbound network interface. If the destination IP address is outside the local network and no specific MAC + address is resolved, it uses the default gateway for the transmission. + + :param dst_ip_address: The destination IP address or network. If an IPv4Network is provided, the method + treats the transmission as a broadcast to that network. Optional. + :type dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] + :param src_port: The source port number for the transmission. Optional. + :type src_port: Optional[Port] + :param dst_port: The destination port number for the transmission. Optional. + :type dst_port: Optional[Port] + :param protocol: The IP protocol to be used for the transmission. Optional. + :type protocol: Optional[IPProtocol] + :param session_id: The session ID associated with the transmission. If provided, the session details override + other parameters. Optional. + :type session_id: Optional[str] + :return: A tuple containing the resolved outbound network interface, destination MAC address, destination IP + address, source port, destination port, protocol, and a boolean indicating whether the transmission is a + broadcast. + :rtype: Tuple[Optional["NetworkInterface"], Optional[str], IPv4Address, Optional[Port], Optional[Port], + Optional[IPProtocol], bool] + """ if dst_ip_address and not isinstance(dst_ip_address, (IPv4Address, IPv4Network)): dst_ip_address = IPv4Address(dst_ip_address) is_broadcast = False @@ -207,14 +256,14 @@ class SessionManager: return outbound_network_interface, dst_mac_address, dst_ip_address, src_port, dst_port, protocol, is_broadcast def receive_payload_from_software_manager( - self, - payload: Any, - dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, - src_port: Optional[Port] = None, - dst_port: Optional[Port] = None, - session_id: Optional[str] = None, - ip_protocol: IPProtocol = IPProtocol.TCP, - icmp_packet: Optional[ICMPPacket] = None + self, + payload: Any, + dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, + src_port: Optional[Port] = None, + dst_port: Optional[Port] = None, + session_id: Optional[str] = None, + ip_protocol: IPProtocol = IPProtocol.TCP, + icmp_packet: Optional[ICMPPacket] = None, ) -> Union[Any, None]: """ Receive a payload from the SoftwareManager and send it to the appropriate NIC for transmission. @@ -239,15 +288,22 @@ class SessionManager: is_broadcast = payload.request ip_protocol = IPProtocol.UDP else: - vals = self.resolve_outbound_transmission_details( dst_ip_address=dst_ip_address, src_port=src_port, dst_port=dst_port, protocol=ip_protocol, - session_id=session_id + session_id=session_id, ) - outbound_network_interface, dst_mac_address, dst_ip_address, src_port, dst_port, protocol, is_broadcast = vals + ( + outbound_network_interface, + dst_mac_address, + dst_ip_address, + src_port, + dst_port, + protocol, + is_broadcast, + ) = vals if protocol: ip_protocol = protocol @@ -257,7 +313,7 @@ class SessionManager: if not (src_port or dst_port): raise ValueError( - f"Failed to resolve src or dst port. Have you sent the port from the service or application?" + "Failed to resolve src or dst port. Have you sent the port from the service or application?" ) tcp_header = None @@ -283,7 +339,11 @@ class SessionManager: # Construct the frame for transmission frame = Frame( ethernet=EthernetHeader(src_mac_addr=outbound_network_interface.mac_address, dst_mac_addr=dst_mac_address), - ip=IPPacket(src_ip_address=outbound_network_interface.ip_address, dst_ip_address=dst_ip_address, protocol=ip_protocol), + ip=IPPacket( + src_ip_address=outbound_network_interface.ip_address, + dst_ip_address=dst_ip_address, + protocol=ip_protocol, + ), tcp=tcp_header, udp=udp_header, icmp=icmp_packet, @@ -304,7 +364,7 @@ class SessionManager: # Send the frame through the NIC return outbound_network_interface.send_frame(frame) - def receive_frame(self, frame: Frame, from_network_interface: 'NetworkInterface'): + def receive_frame(self, frame: Frame, from_network_interface: "NetworkInterface"): """ Receive a Frame. @@ -334,7 +394,7 @@ class SessionManager: protocol=frame.ip.protocol, session_id=session.uuid, from_network_interface=from_network_interface, - frame=frame + frame=frame, ) def show(self, markdown: bool = False): diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index 53725c18..e6fe7b23 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -25,7 +25,14 @@ IOSoftwareClass = TypeVar("IOSoftwareClass", bound=IOSoftware) class SoftwareManager: - """A class that manages all running Services and Applications on a Node and facilitates their communication.""" + """ + Manages all running services and applications on a network node and facilitates their communication. + + This class is responsible for installing, uninstalling, and managing the operational state of various network + services and applications. It acts as a bridge between the node's session manager and its software components, + ensuring that incoming and outgoing network payloads are correctly routed to and from the appropriate services + or applications. + """ def __init__( self, @@ -50,11 +57,13 @@ class SoftwareManager: self.dns_server: Optional[IPv4Address] = dns_server @property - def arp(self) -> 'ARP': + def arp(self) -> "ARP": + """Provides access to the ARP service instance, if installed.""" return self.software.get("ARP") # noqa @property - def icmp(self) -> 'ICMP': + def icmp(self) -> "ICMP": + """Provides access to the ICMP service instance, if installed.""" return self.software.get("ICMP") # noqa def get_open_ports(self) -> List[Port]: @@ -167,7 +176,13 @@ class SoftwareManager: ) def receive_payload_from_session_manager( - self, payload: Any, port: Port, protocol: IPProtocol, session_id: str, from_network_interface: "NIC", frame: Frame + self, + payload: Any, + port: Port, + protocol: IPProtocol, + session_id: str, + from_network_interface: "NIC", + frame: Frame, ): """ Receive a payload from the SessionManager and forward it to the corresponding service or application. @@ -177,7 +192,9 @@ class SoftwareManager: """ receiver: Optional[Union[Service, Application]] = self.port_protocol_mapping.get((port, protocol), None) if receiver: - receiver.receive(payload=payload, session_id=session_id, from_network_interface=from_network_interface, frame=frame) + receiver.receive( + payload=payload, session_id=session_id, from_network_interface=from_network_interface, frame=frame + ) else: self.sys_log.error(f"No service or application found for port {port} and protocol {protocol}") pass @@ -202,7 +219,7 @@ class SoftwareManager: software.operating_state.name, software.health_state_actual.name, software.port.value if software.port != Port.NONE else None, - software.protocol.value + software.protocol.value, ] ) print(table) diff --git a/src/primaite/simulator/system/services/arp/arp.py b/src/primaite/simulator/system/services/arp/arp.py index 6a04e845..ca5b7619 100644 --- a/src/primaite/simulator/system/services/arp/arp.py +++ b/src/primaite/simulator/system/services/arp/arp.py @@ -20,6 +20,7 @@ class ARP(Service): Manages ARP for resolving network layer addresses into link layer addresses. It maintains an ARP cache, sends ARP requests and replies, and processes incoming ARP packets. """ + arp: Dict[IPV4Address, ARPEntry] = {} def __init__(self, **kwargs): @@ -29,6 +30,14 @@ class ARP(Service): super().__init__(**kwargs) def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + """ + state = super().describe_state() + state.update({str(ip): arp_entry.mac_address for ip, arp_entry in self.arp.items()}) + return super().describe_state() def show(self, markdown: bool = False): @@ -57,11 +66,7 @@ class ARP(Service): self.arp.clear() def add_arp_cache_entry( - self, - ip_address: IPV4Address, - mac_address: str, - network_interface: NetworkInterface, - override: bool = False + self, ip_address: IPV4Address, mac_address: str, network_interface: NetworkInterface, override: bool = False ): """ Add an ARP entry to the cache. @@ -139,7 +144,8 @@ class ARP(Service): ) else: self.sys_log.error( - "Cannot send ARP request as there is no outbound Network Interface to use. Try configuring the default gateway." + "Cannot send ARP request as there is no outbound Network Interface to use. Try configuring the default " + "gateway." ) def send_arp_reply(self, arp_reply: ARPPacket): @@ -147,12 +153,10 @@ class ARP(Service): Sends an ARP reply in response to an ARP request. :param arp_reply: The ARP packet containing the reply. - :param from_network_interface: The NIC from which the ARP reply is sent. """ - outbound_network_interface = self.software_manager.session_manager.resolve_outbound_network_interface( arp_reply.target_ip_address - ) + ) if outbound_network_interface: self.sys_log.info( f"Sending ARP reply from {arp_reply.sender_mac_addr}/{arp_reply.sender_ip_address} " @@ -162,14 +166,14 @@ class ARP(Service): payload=arp_reply, dst_ip_address=arp_reply.target_ip_address, dst_port=self.port, - ip_protocol=self.protocol + ip_protocol=self.protocol, ) else: self.sys_log.error( - "Cannot send ARP reply as there is no outbound Network Interface to use. Try configuring the default gateway." + "Cannot send ARP reply as there is no outbound Network Interface to use. Try configuring the default " + "gateway." ) - @abstractmethod def _process_arp_request(self, arp_packet: ARPPacket, from_network_interface: NetworkInterface): """ @@ -197,7 +201,7 @@ class ARP(Service): self.add_arp_cache_entry( ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, - network_interface=from_network_interface + network_interface=from_network_interface, ) def receive(self, payload: Any, session_id: str, **kwargs) -> bool: diff --git a/src/primaite/simulator/system/services/icmp/icmp.py b/src/primaite/simulator/system/services/icmp/icmp.py index 3ff7b21c..103d1c60 100644 --- a/src/primaite/simulator/system/services/icmp/icmp.py +++ b/src/primaite/simulator/system/services/icmp/icmp.py @@ -1,8 +1,9 @@ import secrets from ipaddress import IPv4Address -from typing import Dict, Any, Union, Optional, Tuple +from typing import Any, Dict, Optional, Tuple, Union from primaite import getLogger +from primaite.simulator.network.hardware.base import NetworkInterface from primaite.simulator.network.protocols.icmp import ICMPPacket, ICMPType from primaite.simulator.network.transmission.data_link_layer import Frame from primaite.simulator.network.transmission.network_layer import IPProtocol @@ -19,6 +20,7 @@ class ICMP(Service): Enables the sending and receiving of ICMP messages such as echo requests and replies. This is typically used for network diagnostics, notably the ping command. """ + request_replies: Dict = {} def __init__(self, **kwargs): @@ -28,7 +30,12 @@ class ICMP(Service): super().__init__(**kwargs) def describe_state(self) -> Dict: - pass + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + """ + return super().describe_state() def clear(self): """ @@ -56,9 +63,7 @@ class ICMP(Service): self.sys_log.info(f"Pinging {target_ip_address}:", to_terminal=True) sequence, identifier = 0, None while sequence < pings: - sequence, identifier = self._send_icmp_echo_request( - target_ip_address, sequence, identifier, pings - ) + sequence, identifier = self._send_icmp_echo_request(target_ip_address, sequence, identifier, pings) request_replies = self.software_manager.icmp.request_replies.get(identifier) passed = request_replies == pings if request_replies: @@ -76,7 +81,7 @@ class ICMP(Service): return passed def _send_icmp_echo_request( - self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None, pings: int = 4 + self, target_ip_address: IPv4Address, sequence: int = 0, identifier: Optional[int] = None, pings: int = 4 ) -> Tuple[int, Union[int, None]]: """ Sends an ICMP echo request to a specified target IP address. @@ -91,7 +96,8 @@ class ICMP(Service): if not network_interface: self.sys_log.error( - "Cannot send ICMP echo request as there is no outbound Network Interface to use. Try configuring the default gateway." + "Cannot send ICMP echo request as there is no outbound Network Interface to use. Try configuring the " + "default gateway." ) return pings, None @@ -105,11 +111,11 @@ class ICMP(Service): dst_ip_address=target_ip_address, dst_port=self.port, ip_protocol=self.protocol, - icmp_packet=icmp_packet + icmp_packet=icmp_packet, ) return sequence, icmp_packet.identifier - def _process_icmp_echo_request(self, frame: Frame, from_network_interface): + def _process_icmp_echo_request(self, frame: Frame, from_network_interface: NetworkInterface): """ Processes an ICMP echo request received by the service. @@ -121,11 +127,12 @@ class ICMP(Service): network_interface = self.software_manager.session_manager.resolve_outbound_network_interface( frame.ip.src_ip_address - ) + ) if not network_interface: self.sys_log.error( - "Cannot send ICMP echo reply as there is no outbound Network Interface to use. Try configuring the default gateway." + "Cannot send ICMP echo reply as there is no outbound Network Interface to use. Try configuring the " + "default gateway." ) return @@ -143,7 +150,7 @@ class ICMP(Service): dst_ip_address=frame.ip.src_ip_address, dst_port=self.port, ip_protocol=self.protocol, - icmp_packet=icmp_packet + icmp_packet=icmp_packet, ) def _process_icmp_echo_reply(self, frame: Frame): @@ -159,7 +166,7 @@ class ICMP(Service): f"bytes={len(frame.payload)}, " f"time={time_str}, " f"TTL={frame.ip.ttl}", - to_terminal=True + to_terminal=True, ) if not self.request_replies.get(frame.icmp.identifier): self.request_replies[frame.icmp.identifier] = 0 diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index 8e362880..3987fa2c 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -70,10 +70,6 @@ class NTPServer(Service): payload = payload.generate_reply(time) # send reply self.software_manager.session_manager.receive_payload_from_software_manager( - payload=payload, - src_port=self.port, - dst_port=self.port, - ip_protocol=self.protocol, - session_id=session_id + payload=payload, src_port=self.port, dst_port=self.port, ip_protocol=self.protocol, session_id=session_id ) return True diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 91629f9a..ce39930b 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -380,7 +380,7 @@ class IOSoftware(Software): dest_ip_address=dest_ip_address, dest_port=dest_port, ip_protocol=ip_protocol, - session_id=session_id + session_id=session_id, ) @abstractmethod diff --git a/src/primaite/utils/validators.py b/src/primaite/utils/validators.py index 13cff653..fb7abb29 100644 --- a/src/primaite/utils/validators.py +++ b/src/primaite/utils/validators.py @@ -1,9 +1,7 @@ from ipaddress import IPv4Address from typing import Any, Final -from pydantic import ( - BeforeValidator, -) +from pydantic import BeforeValidator from typing_extensions import Annotated @@ -30,7 +28,7 @@ def ipv4_validator(v: Any) -> IPv4Address: # with the IPv4Address type, ensuring that any usage of IPV4Address undergoes validation before assignment. IPV4Address: Final[Annotated] = Annotated[IPv4Address, BeforeValidator(ipv4_validator)] """ -IPv4Address with with pre-validation and auto-conversion from str using ipv4_validator. +IPv4Address with with IPv4Address with with pre-validation and auto-conversion from str using ipv4_validator.. This type is essentially an IPv4Address from the standard library's ipaddress module, but with added validation logic. If you use this custom type, the ipv4_validator function diff --git a/tests/conftest.py b/tests/conftest.py index b5226a34..8639cec3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,10 +5,10 @@ from typing import Any, Dict, Tuple, Union import pytest import yaml -from primaite import PRIMAITE_PATHS -from primaite import getLogger +from primaite import getLogger, PRIMAITE_PATHS from primaite.session.session import PrimaiteSession from primaite.simulator.file_system.file_system import FileSystem + # from primaite.environment.primaite_env import Primaite # from primaite.primaite_session import PrimaiteSession from primaite.simulator.network.container import Network @@ -212,31 +212,20 @@ def example_network() -> Network: network = Network() # Router 1 - router_1 = Router( - hostname="router_1", - start_up_duration=0 - ) + router_1 = Router(hostname="router_1", start_up_duration=0) router_1.power_on() router_1.configure_port(port=1, ip_address="192.168.1.1", subnet_mask="255.255.255.0") router_1.configure_port(port=2, ip_address="192.168.10.1", subnet_mask="255.255.255.0") # Switch 1 - switch_1 = Switch( - hostname="switch_1", - num_ports=8, - start_up_duration=0 - ) + switch_1 = Switch(hostname="switch_1", num_ports=8, start_up_duration=0) switch_1.power_on() network.connect(endpoint_a=router_1.network_interface[1], endpoint_b=switch_1.network_interface[8]) router_1.enable_port(1) # Switch 2 - switch_2 = Switch( - hostname="switch_2", - num_ports=8, - start_up_duration=0 - ) + switch_2 = Switch(hostname="switch_2", num_ports=8, start_up_duration=0) switch_2.power_on() network.connect(endpoint_a=router_1.network_interface[2], endpoint_b=switch_2.network_interface[8]) router_1.enable_port(2) @@ -247,7 +236,7 @@ def example_network() -> Network: ip_address="192.168.10.21", subnet_mask="255.255.255.0", default_gateway="192.168.10.1", - start_up_duration=0 + start_up_duration=0, ) client_1.power_on() network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1]) @@ -258,7 +247,7 @@ def example_network() -> Network: ip_address="192.168.10.22", subnet_mask="255.255.255.0", default_gateway="192.168.10.1", - start_up_duration=0 + start_up_duration=0, ) client_2.power_on() network.connect(endpoint_b=client_2.network_interface[1], endpoint_a=switch_2.network_interface[2]) @@ -269,7 +258,7 @@ def example_network() -> Network: ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", - start_up_duration=0 + start_up_duration=0, ) server_1.power_on() network.connect(endpoint_b=server_1.network_interface[1], endpoint_a=switch_1.network_interface[1]) @@ -280,7 +269,7 @@ def example_network() -> Network: ip_address="192.168.1.14", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", - start_up_duration=0 + start_up_duration=0, ) server_2.power_on() network.connect(endpoint_b=server_2.network_interface[1], endpoint_a=switch_1.network_interface[2]) @@ -290,5 +279,4 @@ def example_network() -> Network: assert all(link.is_up for link in network.links.values()) - return network diff --git a/tests/integration_tests/network/test_broadcast.py b/tests/integration_tests/network/test_broadcast.py index d6c52acc..6b6deb93 100644 --- a/tests/integration_tests/network/test_broadcast.py +++ b/tests/integration_tests/network/test_broadcast.py @@ -37,12 +37,7 @@ class BroadcastService(Service): def broadcast(self, ip_network: IPv4Network): # Send a broadcast payload to an entire IP network - super().send( - payload="broadcast", - dest_ip_address=ip_network, - dest_port=Port.HTTP, - ip_protocol=self.protocol - ) + super().send(payload="broadcast", dest_ip_address=ip_network, dest_port=Port.HTTP, ip_protocol=self.protocol) class BroadcastClient(Application): diff --git a/tests/integration_tests/network/test_frame_transmission.py b/tests/integration_tests/network/test_frame_transmission.py index 5ba4fe13..eb30a245 100644 --- a/tests/integration_tests/network/test_frame_transmission.py +++ b/tests/integration_tests/network/test_frame_transmission.py @@ -5,7 +5,6 @@ from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.hardware.nodes.network.switch import Switch - def test_node_to_node_ping(): """Tests two Computers are able to ping each other.""" network = Network() diff --git a/tests/integration_tests/network/test_network_creation.py b/tests/integration_tests/network/test_network_creation.py index 6a39e101..5cf36bce 100644 --- a/tests/integration_tests/network/test_network_creation.py +++ b/tests/integration_tests/network/test_network_creation.py @@ -97,7 +97,6 @@ def test_disconnecting_nodes(): net.connect(n1.network_interface[1], n2.network_interface[1]) assert len(net.links) == 1 - link = list(net.links.values())[0] net.remove_link(link) assert link not in net diff --git a/tests/integration_tests/network/test_routing.py b/tests/integration_tests/network/test_routing.py index 02524eab..4ada807f 100644 --- a/tests/integration_tests/network/test_routing.py +++ b/tests/integration_tests/network/test_routing.py @@ -19,7 +19,7 @@ def pc_a_pc_b_router_1() -> Tuple[Computer, Computer, Router]: ip_address="192.168.0.10", subnet_mask="255.255.255.0", default_gateway="192.168.0.1", - start_up_duration=0 + start_up_duration=0, ) pc_a.power_on() @@ -28,7 +28,7 @@ def pc_a_pc_b_router_1() -> Tuple[Computer, Computer, Router]: ip_address="192.168.1.10", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", - start_up_duration=0 + start_up_duration=0, ) pc_b.power_on() diff --git a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py index ecf2c5ae..7ab7d104 100644 --- a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py +++ b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py @@ -5,8 +5,8 @@ import pytest from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.host.computer import Computer -from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.database_client import DatabaseClient diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index c259501e..e015f9ee 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -16,21 +16,11 @@ from primaite.simulator.system.services.service import ServiceOperatingState @pytest.fixture(scope="function") def peer_to_peer() -> Tuple[Computer, Computer]: network = Network() - node_a = Computer( - hostname="node_a", - ip_address="192.168.0.10", - subnet_mask="255.255.255.0", - start_up_duration=0 - ) + node_a = Computer(hostname="node_a", ip_address="192.168.0.10", subnet_mask="255.255.255.0", start_up_duration=0) node_a.power_on() node_a.software_manager.get_open_ports() - node_b = Computer( - hostname="node_b", - ip_address="192.168.0.11", - subnet_mask="255.255.255.0", - start_up_duration=0 - ) + node_b = Computer(hostname="node_b", ip_address="192.168.0.11", subnet_mask="255.255.255.0", start_up_duration=0) node_b.power_on() network.connect(node_a.network_interface[1], node_b.network_interface[1]) diff --git a/tests/integration_tests/system/test_dns_client_server.py b/tests/integration_tests/system/test_dns_client_server.py index 18988043..78d2035c 100644 --- a/tests/integration_tests/system/test_dns_client_server.py +++ b/tests/integration_tests/system/test_dns_client_server.py @@ -28,7 +28,8 @@ def dns_client_and_dns_server(client_server) -> Tuple[DNSClient, Computer, DNSSe dns_server.start() # register arcd.com as a domain dns_server.dns_register( - domain_name="arcd.com", domain_ip_address=IPv4Address(server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address) + domain_name="arcd.com", + domain_ip_address=IPv4Address(server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address), ) return dns_client, computer, dns_server, server diff --git a/tests/integration_tests/system/test_web_client_server.py b/tests/integration_tests/system/test_web_client_server.py index c809f954..5e3ff544 100644 --- a/tests/integration_tests/system/test_web_client_server.py +++ b/tests/integration_tests/system/test_web_client_server.py @@ -37,7 +37,10 @@ def web_client_and_web_server(client_server) -> Tuple[WebBrowser, Computer, WebS server.software_manager.install(DNSServer) dns_server: DNSServer = server.software_manager.software.get("DNSServer") # register arcd.com to DNS - dns_server.dns_register(domain_name="arcd.com", domain_ip_address=server.network_interfaces[next(iter(server.network_interfaces))].ip_address) + dns_server.dns_register( + domain_name="arcd.com", + domain_ip_address=server.network_interfaces[next(iter(server.network_interfaces))].ip_address, + ) return web_browser, computer, web_server_service, server diff --git a/tests/integration_tests/system/test_web_client_server_and_database.py b/tests/integration_tests/system/test_web_client_server_and_database.py index efb29f41..70846ee8 100644 --- a/tests/integration_tests/system/test_web_client_server_and_database.py +++ b/tests/integration_tests/system/test_web_client_server_and_database.py @@ -5,8 +5,8 @@ import pytest from primaite.simulator.network.hardware.base import Link from primaite.simulator.network.hardware.nodes.host.computer import Computer -from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.web_browser import WebBrowser @@ -85,7 +85,8 @@ def web_client_web_server_database(example_network) -> Tuple[Computer, Server, S dns_server: DNSServer = web_server.software_manager.software.get("DNSServer") # register arcd.com to DNS dns_server.dns_register( - domain_name="arcd.com", domain_ip_address=web_server.network_interfaces[next(iter(web_server.network_interfaces))].ip_address + domain_name="arcd.com", + domain_ip_address=web_server.network_interfaces[next(iter(web_server.network_interfaces))].ip_address, ) # Install DatabaseClient service on web server diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py index c7d807e9..5f10ec96 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py @@ -16,21 +16,13 @@ from primaite.simulator.system.services.database.database_service import Databas def database_client_on_computer() -> Tuple[DatabaseClient, Computer]: network = Network() - db_server = Server( - hostname="db_server", - ip_address="192.168.0.1", - subnet_mask="255.255.255.0", - start_up_duration=0 - ) + db_server = Server(hostname="db_server", ip_address="192.168.0.1", subnet_mask="255.255.255.0", start_up_duration=0) db_server.power_on() db_server.software_manager.install(DatabaseService) db_server.software_manager.software["DatabaseService"].start() db_client = Computer( - hostname="db_client", - ip_address="192.168.0.2", - subnet_mask="255.255.255.0", - start_up_duration=0 + hostname="db_client", ip_address="192.168.0.2", subnet_mask="255.255.255.0", start_up_duration=0 ) db_client.power_on() db_client.software_manager.install(DatabaseClient) @@ -97,6 +89,7 @@ def test_disconnect(database_client_on_computer): assert not database_client.connected + def test_query_when_client_is_closed(database_client_on_computer): """Database client should return False when it is not running.""" database_client, computer = database_client_on_computer diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py index 05d4a985..d210ff40 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_web_browser.py @@ -16,7 +16,7 @@ def web_browser() -> WebBrowser: ip_address="192.168.1.11", subnet_mask="255.255.255.0", default_gateway="192.168.1.1", - start_up_duration=0 + start_up_duration=0, ) computer.power_on() # Web Browser should be pre-installed in computer diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py index 937636a6..9a513396 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_dns_server.py @@ -9,8 +9,8 @@ from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer @pytest.fixture(scope="function") @@ -65,6 +65,4 @@ def test_dns_server_receive(dns_server): assert dns_client.check_domain_exists("real-domain.com") is False - - dns_server_service.show() From 1dcb9214afe0dabe9d4a7a5c173b18da87a3f670 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 8 Feb 2024 12:04:49 +0000 Subject: [PATCH 575/980] #2258: Added DoSBot to list of applications --- src/primaite/game/game.py | 11 +++++++---- tests/assets/configs/basic_switched_network.yaml | 8 ++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index e0ad0384..b03828f1 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -19,6 +19,7 @@ from primaite.simulator.network.hardware.nodes.switch import Switch from primaite.simulator.sim_container import Simulation from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot +from primaite.simulator.system.applications.red_applications.dos_bot import DoSBot from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.dns.dns_client import DNSClient @@ -31,10 +32,7 @@ from primaite.simulator.system.services.web_server.web_server import WebServer _LOGGER = getLogger(__name__) -APPLICATION_TYPES_MAPPING = { - "WebBrowser": WebBrowser, - "DataManipulationBot": DataManipulationBot, -} +APPLICATION_TYPES_MAPPING = {"WebBrowser": WebBrowser, "DataManipulationBot": DataManipulationBot, "DoSBot": DoSBot} SERVICE_TYPES_MAPPING = { "DNSClient": DNSClient, @@ -308,6 +306,11 @@ class PrimaiteGame: if "options" in application_cfg: opt = application_cfg["options"] new_application.target_url = opt.get("target_url") + + elif application_type == "DoSBot": + if "options" in application_cfg: + opt = application_cfg["options"] + new_application.target_ip_address = opt.get("target_ip_address") if "nics" in node_cfg: for nic_num, nic_cfg in node_cfg["nics"].items(): new_node.connect_nic(NIC(ip_address=nic_cfg["ip_address"], subnet_mask=nic_cfg["subnet_mask"])) diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 774c4aa2..0687478d 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -88,6 +88,10 @@ simulation: data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 + - ref: dos_bot + type: DoSBot + options: + target_ip_address: 192.168.10.21 services: - ref: client_1_dns_server type: DNSServer @@ -98,6 +102,10 @@ simulation: type: DatabaseClient options: db_server_ip: 192.168.10.21 + - ref: client_1_dosbot + type: DoSBot + options: + db_server_ip: 192.168.10.21 - ref: client_1_database_service type: DatabaseService options: From 9b350ddd6f3120b0a504715121e941ab46454c36 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 8 Feb 2024 13:20:32 +0000 Subject: [PATCH 576/980] Apply suggestions from code review. --- src/primaite/game/agent/rewards.py | 9 ++++++++- src/primaite/notebooks/uc2_demo.ipynb | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 1a37b954..b5d5f998 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -68,6 +68,8 @@ class DummyReward(AbstractReward): :param config: dict of options for the reward component's constructor. Should be empty. :type config: dict + :return: The reward component. + :rtype: DummyReward """ return cls() @@ -230,7 +232,12 @@ class WebpageUnavailablePenalty(AbstractReward): @classmethod def from_config(cls, config: dict) -> AbstractReward: - """Build the reward component object from config.""" + """ + Build the reward component object from config. + + :param config: Configuration dictionary. + :type config: Dict + """ node_hostname = config.get("node_hostname") return cls(node_hostname=node_hostname) diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index 7454b6c4..51d787eb 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -307,7 +307,8 @@ "The blue agent's reward is calculated using two measures:\n", "1. Whether the database file is in a good state (+1 for good, -1 for corrupted, 0 for any other state)\n", "2. Whether each green agents' most recent webpage request was successful (+1 for a `200` return code, -1 for a `404` return code and 0 otherwise).\n", - "The file status reward and the two green-agent-related reward are averaged to get a total step reward.\n" + "\n", + "The file status reward and the two green-agent-related rewards are averaged to get a total step reward.\n" ] }, { From b31a9943d7bfe214391e83931fd252c1dab80f99 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 8 Feb 2024 16:02:37 +0000 Subject: [PATCH 577/980] #2258: testing individual application install --- src/primaite/game/game.py | 11 ++++- .../configs/basic_switched_network.yaml | 4 +- tests/integration_tests/game_configuration.py | 41 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index b03828f1..e16f4991 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -16,6 +16,7 @@ from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import Router from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.hardware.nodes.switch import Switch +from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.sim_container import Simulation from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot @@ -310,7 +311,15 @@ class PrimaiteGame: elif application_type == "DoSBot": if "options" in application_cfg: opt = application_cfg["options"] - new_application.target_ip_address = opt.get("target_ip_address") + new_application.configure( + target_ip_address=IPv4Address(opt.get("target_ip_address")), + target_port=Port(opt.get("target_port", Port.POSTGRES_SERVER.value)), + payload=opt.get("payload"), + repeat=bool(opt.get("repeat")), + port_scan_p_of_success=float(opt.get("port_scan_p_of_success", "0.1")), + dos_intensity=float(opt.get("dos_intensity", "1.0")), + max_sessions=int(opt.get("max_sessions", "1000")), + ) if "nics" in node_cfg: for nic_num, nic_cfg in node_cfg["nics"].items(): new_node.connect_nic(NIC(ip_address=nic_cfg["ip_address"], subnet_mask=nic_cfg["subnet_mask"])) diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 0687478d..d86af779 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -87,11 +87,13 @@ simulation: port_scan_p_of_success: 0.8 data_manipulation_p_of_success: 0.8 payload: "DELETE" - server_ip: 192.168.1.14 + server_ip: 192.168.1.21 - ref: dos_bot type: DoSBot options: target_ip_address: 192.168.10.21 + payload: SPOOF DATA + port_scan_p_of_success: 0.8 services: - ref: client_1_dns_server type: DNSServer diff --git a/tests/integration_tests/game_configuration.py b/tests/integration_tests/game_configuration.py index ff977082..274e8bd6 100644 --- a/tests/integration_tests/game_configuration.py +++ b/tests/integration_tests/game_configuration.py @@ -1,3 +1,4 @@ +from ipaddress import IPv4Address from pathlib import Path from typing import Union @@ -9,6 +10,8 @@ from primaite.game.agent.interface import ProxyAgent, RandomAgent from primaite.game.game import APPLICATION_TYPES_MAPPING, PrimaiteGame, SERVICE_TYPES_MAPPING from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot +from primaite.simulator.system.applications.red_applications.dos_bot import DoSBot from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.ftp.ftp_client import FTPClient @@ -76,3 +79,41 @@ def test_node_software_install(): # check that services have been installed on client 1 for service in SERVICE_TYPES_MAPPING: assert client_1.software_manager.software.get(service) is not None + + +def test_web_browser_install(): + """Test that the web browser can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + web_browser: WebBrowser = client_1.software_manager.software.get("WebBrowser") + + assert web_browser.target_url == "http://arcd.com/users/" + + +def test_data_manipulation_bot_install(): + """Test that the data manipulation bot can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + data_manipulation_bot: DataManipulationBot = client_1.software_manager.software.get("DataManipulationBot") + + assert data_manipulation_bot.server_ip_address == IPv4Address("192.168.1.21") + assert data_manipulation_bot.payload == "DELETE" + assert data_manipulation_bot.data_manipulation_p_of_success == 0.8 + assert data_manipulation_bot.port_scan_p_of_success == 0.8 + + +def test_dos_bot_install(): + """Test that the denial of service bot can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + dos_bot: DoSBot = client_1.software_manager.software.get("DoSBot") + + assert dos_bot.target_ip_address == IPv4Address("192.168.10.21") + assert dos_bot.payload == "SPOOF DATA" + assert dos_bot.port_scan_p_of_success == 0.8 + assert dos_bot.dos_intensity == 1.0 # default + assert dos_bot.max_sessions == 1000 # default + assert dos_bot.repeat is False # default From 0590f956e3443d916bb9273067b013c36130feeb Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 8 Feb 2024 16:21:08 +0000 Subject: [PATCH 578/980] #2258: ntp client should not request if ntp server is not set --- src/primaite/simulator/system/services/ntp/ntp_client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index e8c3d0cb..ccb2cbe7 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -127,6 +127,7 @@ class NTPClient(Service): super().apply_timestep(timestep) if self.operating_state == ServiceOperatingState.RUNNING: # request time from server - self.request_time() + if self.ntp_server is not None: + self.request_time() else: self.sys_log.debug(f"{self.name} ntp client not running") From a036160515ccfb4c1573df4a0482db8a074c2697 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 8 Feb 2024 22:37:21 +0000 Subject: [PATCH 579/980] #2248 - Enhances the PrimAITE documentation, covering the Node, network interfaces, Session Manager, Software Manager, PCAP service, SysLog functionality, and network devices like Routers, Switches, Computers, and Switch Nodes. It details their roles, workflows, and integration within the simulation, focusing on frame processing, software management, and logging. The documentation also clarifies the frame reception process, including port checks and application-level dispatching, ensuring a thorough understanding of network operations within the simulation --- CHANGELOG.md | 4 + docs/source/simulation.rst | 8 +- .../network/base_hardware.rst | 740 +----------------- .../simulation_components/network/network.rst | 8 +- .../network/network_interfaces.rst | 118 +++ .../network/nodes/host_node.rst | 47 ++ .../network/nodes/network_node.rst | 41 + .../network/nodes/router.rst | 41 + .../network/nodes/switch.rst | 29 + .../primaite_network_interface_model.png | Bin 0 -> 46770 bytes .../simulation_components/network/router.rst | 73 -- .../system/data_manipulation_bot.rst | 2 +- .../system/ftp_client_server.rst | 2 +- .../node_session_software_model_example.png | Bin 0 -> 52428 bytes .../simulation_components/system/pcap.rst | 51 ++ .../system/session_and_software_manager.rst | 90 +++ .../simulation_components/system/sys_log.rst | 51 ++ .../web_browser_and_web_server_service.rst | 2 +- .../wireless/wireless_access_point.py | 9 +- .../wireless/wireless_nic.py | 9 +- .../network/hardware/nodes/network/router.py | 41 - 21 files changed, 529 insertions(+), 837 deletions(-) create mode 100644 docs/source/simulation_components/network/network_interfaces.rst create mode 100644 docs/source/simulation_components/network/nodes/host_node.rst create mode 100644 docs/source/simulation_components/network/nodes/network_node.rst create mode 100644 docs/source/simulation_components/network/nodes/router.rst create mode 100644 docs/source/simulation_components/network/nodes/switch.rst create mode 100644 docs/source/simulation_components/network/primaite_network_interface_model.png delete mode 100644 docs/source/simulation_components/network/router.rst create mode 100644 docs/source/simulation_components/system/node_session_software_model_example.png create mode 100644 docs/source/simulation_components/system/pcap.rst create mode 100644 docs/source/simulation_components/system/session_and_software_manager.rst create mode 100644 docs/source/simulation_components/system/sys_log.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index 94c6aff0..9716fd0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,10 @@ SessionManager. - Created the `ARP` and `ICMP` service classes to handle Address Resolution Protocol operations and Internet Control Message Protocol messages, respectively, with `RouterARP` and `RouterICMP` for router-specific implementations. - Created `HostNode` as a subclass of `Node`, extending its functionality with host-specific services and applications. This class is designed to represent end-user devices like computers or servers that can initiate and respond to network communications. - Introduced a new `IPV4Address` type in the Pydantic model for enhanced validation and auto-conversion of IPv4 addresses from strings using an `ipv4_validator`. +- Comprehensive documentation for the Node and its network interfaces, detailing the operational workflow from frame reception to application-level processing. +- Detailed descriptions of the Session Manager and Software Manager functionalities, including their roles in managing sessions, software services, and applications within the simulation. +- Documentation for the Packet Capture (PCAP) service and SysLog functionality, highlighting their importance in logging network frames and system events, respectively. +- Expanded documentation on network devices such as Routers, Switches, Computers, and Switch Nodes, explaining their specific processing logic and protocol support. ### Changed diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index e5c0d2c8..d85a1449 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -17,9 +17,15 @@ Contents simulation_structure simulation_components/network/base_hardware + simulation_components/network/network_interfaces simulation_components/network/transport_to_data_link_layer - simulation_components/network/router + simulation_components/network/nodes/host_node + simulation_components/network/nodes/network_node + simulation_components/network/nodes/router simulation_components/network/switch simulation_components/network/network simulation_components/system/internal_frame_processing + simulation_components/system/sys_log + simulation_components/system/pcap + simulation_components/system/session_and_software_manager simulation_components/system/software diff --git a/docs/source/simulation_components/network/base_hardware.rst b/docs/source/simulation_components/network/base_hardware.rst index 01c68036..10ed59c6 100644 --- a/docs/source/simulation_components/network/base_hardware.rst +++ b/docs/source/simulation_components/network/base_hardware.rst @@ -6,719 +6,41 @@ Base Hardware ############# -The physical layer components are models of a NIC (Network Interface Card), SwitchPort, Node, Switch, and a Link. -These components allow modelling of layer 1 (physical layer) in the OSI model and the nodes that connect to and -transmit across layer 1. +The ``base.py`` module in ``primaite.simulator.network.hardware`` provides foundational components, interfaces, and classes for +modeling network hardware within PrimAITE simulations. It establishes core building blocks and abstractions that more +complex, specialized hardware components inherit from and build upon. -=== -NIC -=== +The key elements defined in ``base.py`` are: -The NIC class provides a realistic model of a Network Interface Card. The NIC acts as the interface between a Node and -a Link, handling IP and MAC addressing, status, and sending/receiving frames. +NetworkInterface +================ ----------- -Addressing ----------- +- Abstract base class for network interfaces like NICs. Defines common attributes like MAC address, speed, MTU. +- Requires subclasses to implement ``enable()``, ``disable()``, ``send_frame()`` and ``receive_frame()``. +- Provides basic state description and request handling capabilities. -A NIC has both an IPv4 address and MAC address assigned: - -- **ip_address** - The IPv4 address assigned to the NIC for communication on an IP network. -- **subnet_mask** - The subnet mask that defines the network subnet. -- **gateway** - The default gateway IP address for routing traffic beyond the local network. -- **mac_address** - A unique MAC address assigned to the NIC by the manufacturer. - - ------- -Status ------- - -The status of the NIC is represented by: - -- **enabled** - Indicates if the NIC is active/enabled or disabled/down. It must be enabled to send/receive frames. -- **connected_node** - The Node instance the NIC is attached to. -- **connected_link** - The Link instance the NIC is wired to. - - --------------- -Packet Capture --------------- - -- **pcap** - A PacketCapture instance attached to the NIC for capturing all frames sent and received. This allows packet -capture and analysis. - ------------------------- -Sending/Receiving Frames ------------------------- - -The NIC can send and receive Frames to/from the connected Link: - -- **send_frame()** - Sends a Frame through the NIC onto the attached Link. -- **receive_frame()** - Receives a Frame from the attached Link and processes it. - -This allows a NIC to handle sending, receiving, and forwarding of network traffic at layer 2 of the OSI model. -The Frames contain network data encapsulated with various protocol headers. - ------------ -Basic Usage ------------ - -.. code-block:: python - - nic1 = NIC( - ip_address="192.168.0.100", - subnet_mask="255.255.255.0", - gateway="192.168.0.1" - ) - nic1.enable() - frame = Frame(...) - nic1.send_frame(frame) - -========== -SwitchPort -========== - -The SwitchPort models a port on a network switch. It has similar attributes and methods to NIC for addressing, status, -packet capture, sending/receiving frames, etc. - -Key attributes: - -- **port_num**: The port number on the switch. -- **connected_switch**: The switch to which this port belongs. - -==== Node ==== -The Node class represents a base node that communicates on the Network. - -Nodes take more than 1 time step to power on (3 time steps by default). -To create a Node that is already powered on, the Node's operating state can be overriden. -Otherwise, the node ``start_up_duration`` (and ``shut_down_duration``) can be set to 0 if -the node will be powered off or on multiple times. This will still need ``power_on()`` to -be called to turn the node on. - -e.g. - -.. code-block:: python - - active_node = Node(hostname='server1', operating_state=NodeOperatingState.ON) - # node is already on, no need to call power_on() - - - instant_start_node = Node(hostname="client", start_up_duration=0, shut_down_duration=0) - instant_start_node.power_on() # node will still need to be powered on - -.. _Node Start up and Shut down: - ---------------------------- -Node Start up and Shut down ---------------------------- - -Nodes are powered on and off over multiple timesteps. By default, the node ``start_up_duration`` and ``shut_down_duration`` is 3 timesteps. - -Example code where a node is turned on: - -.. code-block:: python - - from primaite.simulator.network.hardware.base import Node - from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState - - node = Node(hostname="pc_a") - - assert node.operating_state is NodeOperatingState.OFF # By default, node is instantiated in an OFF state - - node.power_on() # power on the node - - assert node.operating_state is NodeOperatingState.BOOTING # node is booting up - - for i in range(node.start_up_duration + 1): - # apply timestep until the node start up duration - node.apply_timestep(timestep=i) - - assert node.operating_state is NodeOperatingState.ON # node is in ON state - - -If the node needs to be instantiated in an on state: - - -.. code-block:: python - - from primaite.simulator.network.hardware.base import Node - from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState - - node = Node(hostname="pc_a", operating_state=NodeOperatingState.ON) - - assert node.operating_state is NodeOperatingState.ON # node is in ON state - -Setting ``start_up_duration`` and/or ``shut_down_duration`` to ``0`` will allow for the ``power_on`` and ``power_off`` methods to be completed instantly without applying timesteps: - -.. code-block:: python - - from primaite.simulator.network.hardware.base import Node - from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState - - node = Node(hostname="pc_a", start_up_duration=0, shut_down_duration=0) - - assert node.operating_state is NodeOperatingState.OFF # node is in OFF state - - node.power_on() - - assert node.operating_state is NodeOperatingState.ON # node is in ON state - - node.power_off() - - assert node.operating_state is NodeOperatingState.OFF # node is in OFF state - ------------------- -Network Interfaces ------------------- - -A Node will typically have one or more NICs attached to it for network connectivity: - -- **network_interfaces** - A dictionary containing the NIC instances attached to the Node. NICs can be added/removed. - -------------- -Configuration -------------- - -- **hostname** - Configured hostname of the Node. -- **operating_state** - Current operating state like ON or OFF. The NICs will be enabled/disabled based on this. - ----------------- -Network Services ----------------- - -A Node runs various network services and components for handling traffic: - -- **session_manager** - Handles establishing sessions to/from the Node. -- **software_manager** - Manages software and applications on the Node. -- **arp** - ARP cache for resolving IP addresses to MAC addresses. -- **icmp** - ICMP service for responding to pings and echo requests. -- **sys_log** - System log service for logging internal events and messages. - -The SysLog provides a logging mechanism for the Node: - -The SysLog records informational, warning, and error events that occur on the Node during simulation. This allows -debugging and tracing program execution and network activity for each simulated Node. Other Node services like ARP and -ICMP, along with custom Applications, services, and Processes will log to the SysLog. - ------------------ -Sending/Receiving ------------------ - -The Node handles sending and receiving Frames via its attached NICs: - -- **send_frame()** - Sends a Frame to the network through one of the Node's NICs. -- **receive_frame()** - Receives a Frame from the network through a NIC. The Node then processes it appropriately based -on the protocols and payload. - ------------ -Basic Usage ------------ - -.. code-block:: python - - node1 = Node(hostname='server1') - node1.operating_state = NodeOperatingState.ON - - nic1 = NIC() - node1.connect_nic(nic1) - - Send a frame - frame = Frame(...) - node1.send_frame(frame) - -The Node class brings together the NICs, configuration, and services to model a full network node that can send, -receive, process, and forward traffic on a simulated network. - -====== -Switch -====== - -The Switch subclass models a network switch. It inherits from Node and acts at layer 2 of the OSI model to forward -frames based on MAC addresses. - --------------------------- -Inherits Node Capabilities --------------------------- - -Since Switch subclasses Node, it inherits all capabilities from Node like: - -- **Managing NICs** -- **Running network services like ARP, ICMP** -- **Sending and receiving frames** -- **Maintaining system logs** - ------ -Ports ------ - -A Switch has multiple ports implemented using SwitchPort instances: - -- **switch_ports** - A dictionary mapping port numbers to SwitchPort instances. -- **num_ports** - The number of ports the Switch has. - ----------- -Forwarding ----------- - -A Switch forwards frames between ports based on the destination MAC: - -- **dst_mac_table** - MAC address table that maps MACs to SwitchPorts. -- **forward_frame()** - Forwards a frame out the port associated with the destination MAC. - -When a frame is received on a SwitchPort: - -1. The source MAC address is extracted from the frame. -2. An entry is added to dst_mac_table that maps this source MAC to the SwitchPort it was received on. -3. When a frame with that destination MAC is received in the future, it will be forwarded out this SwitchPort. - -This allows the Switch to dynamically build up a mapping table between MAC addresses and SwitchPorts based on traffic -received. If no entry exists for a destination MAC, it floods the frame out all ports. - -==== -Link -==== - -The Link class represents a physical link or connection between two network endpoints like NICs or SwitchPorts. - ---------- -Endpoints ---------- - -A Link connects two endpoints: - -- **endpoint_a** - The first endpoint, a NIC or SwitchPort. -- **endpoint_b** - The second endpoint, a NIC or SwitchPort. - ------------- -Transmission ------------- - -Links transmit Frames between the endpoints: - -- **transmit_frame()** - Sends a Frame from one endpoint to the other. - -Uses bandwidth/load properties to determine if transmission is possible. - ----------------- -Bandwidth & Load ----------------- - -- **bandwidth** - The total capacity of the Link in Mbps. -- **current_load** - The current bandwidth utilization of the Link in Mbps. - -As Frames are sent over the Link, the load increases. The Link tracks if there is enough unused capacity to transmit a -Frame based on its size and the current load. - ------- -Status ------- - -- **up** - Boolean indicating if the Link is currently up/active based on the endpoint status. -- **endpoint_up()/down()** - Notifies the Link when an endpoint goes up or down. - -This allows the Link to realistically model the connection and transmission characteristics between two endpoints. - -======================= -Putting it all Together -======================= - -We'll now demonstrate how the nodes, NICs, switches, and links connect in a network, including full code examples and -syslog extracts to illustrate the step-by-step process. - -To demonstrate successful network communication between nodes and switches, we'll model a standard network with four -PC's and two switches. - - -.. image:: ../../../_static/four_node_two_switch_network.png - -------------------- -Create Nodes & NICs -------------------- - -First, we'll create the four nodes, each with a single NIC. - -.. code-block:: python - - from primaite.simulator.network.hardware.base import Node, NodeOperatingState, NIC - - pc_a = Node(hostname="pc_a", operating_state=NodeOperatingState.ON) - nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", gateway="192.168.0.1") - pc_a.connect_nic(nic_a) - - pc_b = Node(hostname="pc_b", operating_state=NodeOperatingState.ON) - nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0", gateway="192.168.0.1") - pc_b.connect_nic(nic_b) - - pc_c = Node(hostname="pc_c", operating_state=NodeOperatingState.ON) - nic_c = NIC(ip_address="192.168.0.12", subnet_mask="255.255.255.0", gateway="192.168.0.1") - pc_c.connect_nic(nic_c) - - pc_d = Node(hostname="pc_d", operating_state=NodeOperatingState.ON) - nic_d = NIC(ip_address="192.168.0.13", subnet_mask="255.255.255.0", gateway="192.168.0.1") - pc_d.connect_nic(nic_d) - -Creating the four nodes results in: - -**node_a NIC table** - -+-------------------+--------------+---------------+-----------------+--------------+----------+ -| MAC Address | IP Address | Subnet Mask | Default Gateway | Speed (Mbps) | Status | -+===================+==============+===============+=================+==============+==========+ -| 80:af:f2:f6:58:b7 | 102.169.0.10 | 255.255.255.0 | 192.168.0.1 | 100 | Disabled | -+-------------------+--------------+---------------+-----------------+--------------+----------+ - -**node_a sys log** - -.. code-block:: - - 2023-08-08 15:50:08,355 INFO: Connected NIC 80:af:f2:f6:58:b7/192.168.0.10 - -**node_b NIC table** - -+-------------------+--------------+---------------+-----------------+--------------+----------+ -| MAC Address | IP Address | Subnet Mask | Default Gateway | Speed (Mbps) | Status | -+===================+==============+===============+=================+==============+==========+ -| 98:ad:eb:7c:dc:cb | 102.169.0.11 | 255.255.255.0 | 192.168.0.1 | 100 | Disabled | -+-------------------+--------------+---------------+-----------------+--------------+----------+ - -**node_b sys log** - -.. code-block:: - - 2023-08-08 15:50:08,357 INFO: Connected NIC 98:ad:eb:7c:dc:cb/192.168.0.11 - -**node_c NIC table** - -+-------------------+--------------+---------------+-----------------+--------------+----------+ -| MAC Address | IP Address | Subnet Mask | Default Gateway | Speed (Mbps) | Status | -+===================+==============+===============+=================+==============+==========+ -| bc:72:82:5d:82:a4 | 102.169.0.12 | 255.255.255.0 | 192.168.0.1 | 100 | Disabled | -+-------------------+--------------+---------------+-----------------+--------------+----------+ - -**node_c sys log** - -.. code-block:: - - 2023-08-08 15:50:08,358 INFO: Connected NIC bc:72:82:5d:82:a4/192.168.0.12 - -**node_d NIC table** - -+-------------------+--------------+---------------+-----------------+--------------+----------+ -| MAC Address | IP Address | Subnet Mask | Default Gateway | Speed (Mbps) | Status | -+===================+==============+===============+=================+==============+==========+ -| 84:20:7c:ec:a5:c6 | 102.169.0.13 | 255.255.255.0 | 192.168.0.1 | 100 | Disabled | -+-------------------+--------------+---------------+-----------------+--------------+----------+ - -**node_d sys log** - -.. code-block:: - - 2023-08-08 15:50:08,359 INFO: Connected NIC 84:20:7c:ec:a5:c6/192.168.0.13 - ---------------- -Create Switches ---------------- - -Next, we'll create two six-port switches: - -.. code-block:: python - - switch_1 = Switch(hostname="switch_1", num_ports=6, operating_state=NodeOperatingState.ON) - - switch_2 = Switch(hostname="switch_2", num_ports=6, operating_state=NodeOperatingState.ON) - -This produces: - -**switch_1 MAC table** - -+------+-------------------+--------------+----------+ -| Port | MAC Address | Speed (Mbps) | Status | -+======+===================+==============+==========+ -| 1 | 9d:ac:59:a0:05:13 | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 2 | 45:f5:8e:b6:f5:d3 | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 3 | ef:f5:b9:28:cb:ae | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 4 | 88:76:0a:72:fc:14 | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 5 | 79:de:da:bd:e2:ba | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 6 | 91:d5:83:a0:02:f2 | 100 | Disabled | -+------+-------------------+--------------+----------+ - -**switch_1 sys log** - -.. code-block:: - - 2023-08-08 15:50:08,373 INFO: Turned on - -**switch_2 MAC table** - -+------+-------------------+--------------+----------+ -| Port | MAC Address | Speed (Mbps) | Status | -+======+===================+==============+==========+ -| 1 | aa:58:fa:66:d7:be | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 2 | 72:d2:1e:88:e9:45 | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 3 | 8a:fc:2a:56:d5:c5 | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 4 | fb:b5:9a:04:4a:49 | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 5 | 88:aa:48:d0:21:9e | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 6 | 96:77:39:d1:de:44 | 100 | Disabled | -+------+-------------------+--------------+----------+ - -**switch_2 sys log** - -.. code-block:: - - 2023-08-08 15:50:08,374 INFO: Turned on - ------------- -Create Links ------------- - -Finally, we'll create the five links that connect the nodes and the switches: - -.. code-block:: python - - link_nic_a_switch_1 = Link(endpoint_a=nic_a, endpoint_b=switch_1.switch_ports[1]) - link_nic_b_switch_1 = Link(endpoint_a=nic_b, endpoint_b=switch_1.switch_ports[2]) - link_nic_c_switch_2 = Link(endpoint_a=nic_c, endpoint_b=switch_2.switch_ports[1]) - link_nic_d_switch_2 = Link(endpoint_a=nic_d, endpoint_b=switch_2.switch_ports[2]) - link_switch_1_switch_2 = Link( - endpoint_a=switch_1.switch_ports[6], endpoint_b=switch_2.switch_ports[6] - ) - -This produces: - -**node_a NIC table** - -+-------------------+--------------+---------------+-----------------+--------------+---------+ -| MAC Address | IP Address | Subnet Mask | Default Gateway | Speed (Mbps) | Status | -+===================+==============+===============+=================+==============+=========+ -| 80:af:f2:f6:58:b7 | 102.169.0.10 | 255.255.255.0 | 192.168.0.1 | 100 | Enabled | -+-------------------+--------------+---------------+-----------------+--------------+---------+ - -**node_a sys log** - -.. code-block:: - - 2023-08-08 15:50:08,355 INFO: Connected NIC 80:af:f2:f6:58:b7/192.168.0.10 - 2023-08-08 15:50:08,355 INFO: Turned on - 2023-08-08 15:50:08,355 INFO: NIC 80:af:f2:f6:58:b7/192.168.0.10 enabled - -**node_b NIC table** - -+-------------------+--------------+---------------+-----------------+--------------+---------+ -| MAC Address | IP Address | Subnet Mask | Default Gateway | Speed (Mbps) | Status | -+===================+==============+===============+=================+==============+=========+ -| 98:ad:eb:7c:dc:cb | 102.169.0.11 | 255.255.255.0 | 192.168.0.1 | 100 | Enabled | -+-------------------+--------------+---------------+-----------------+--------------+---------+ - -**node_b sys log** - -.. code-block:: - - 2023-08-08 15:50:08,357 INFO: Connected NIC 98:ad:eb:7c:dc:cb/192.168.0.11 - 2023-08-08 15:50:08,357 INFO: Turned on - 2023-08-08 15:50:08,357 INFO: NIC 98:ad:eb:7c:dc:cb/192.168.0.11 enabled - -**node_c NIC table** - -+-------------------+--------------+---------------+-----------------+--------------+---------+ -| MAC Address | IP Address | Subnet Mask | Default Gateway | Speed (Mbps) | Status | -+===================+==============+===============+=================+==============+=========+ -| bc:72:82:5d:82:a4 | 102.169.0.12 | 255.255.255.0 | 192.168.0.1 | 100 | Enabled | -+-------------------+--------------+---------------+-----------------+--------------+---------+ - -**node_c sys log** - -.. code-block:: - - 2023-08-08 15:50:08,358 INFO: Connected NIC bc:72:82:5d:82:a4/192.168.0.12 - 2023-08-08 15:50:08,358 INFO: Turned on - 2023-08-08 15:50:08,358 INFO: NIC bc:72:82:5d:82:a4/192.168.0.12 enabled - -**node_d NIC table** - -+-------------------+--------------+---------------+-----------------+--------------+---------+ -| MAC Address | IP Address | Subnet Mask | Default Gateway | Speed (Mbps) | Status | -+===================+==============+===============+=================+==============+=========+ -| 84:20:7c:ec:a5:c6 | 102.169.0.13 | 255.255.255.0 | 192.168.0.1 | 100 | Enabled | -+-------------------+--------------+---------------+-----------------+--------------+---------+ - -**node_d sys log** - -.. code-block:: - - 2023-08-08 15:50:08,359 INFO: Connected NIC 84:20:7c:ec:a5:c6/192.168.0.13 - 2023-08-08 15:50:08,360 INFO: Turned on - 2023-08-08 15:50:08,360 INFO: NIC 84:20:7c:ec:a5:c6/192.168.0.13 enabled - -**switch_1 MAC table** - -+------+-------------------+--------------+----------+ -| Port | MAC Address | Speed (Mbps) | Status | -+======+===================+==============+==========+ -| 1 | 9d:ac:59:a0:05:13 | 100 | Enabled | -+------+-------------------+--------------+----------+ -| 2 | 45:f5:8e:b6:f5:d3 | 100 | Enabled | -+------+-------------------+--------------+----------+ -| 3 | ef:f5:b9:28:cb:ae | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 4 | 88:76:0a:72:fc:14 | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 5 | 79:de:da:bd:e2:ba | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 6 | 91:d5:83:a0:02:f2 | 100 | Enabled | -+------+-------------------+--------------+----------+ - - -**switch_1 sys log** - -.. code-block:: - - 2023-08-08 15:50:08,373 INFO: Turned on - 2023-08-08 15:50:08,378 INFO: SwitchPort 9d:ac:59:a0:05:13 enabled - 2023-08-08 15:50:08,380 INFO: SwitchPort 45:f5:8e:b6:f5:d3 enabled - 2023-08-08 15:50:08,384 INFO: SwitchPort 91:d5:83:a0:02:f2 enabled - - -**switch_2 MAC table** - -+------+-------------------+--------------+----------+ -| Port | MAC Address | Speed (Mbps) | Status | -+======+===================+==============+==========+ -| 1 | aa:58:fa:66:d7:be | 100 | Enabled | -+------+-------------------+--------------+----------+ -| 2 | 72:d2:1e:88:e9:45 | 100 | Enabled | -+------+-------------------+--------------+----------+ -| 3 | 8a:fc:2a:56:d5:c5 | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 4 | fb:b5:9a:04:4a:49 | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 5 | 88:aa:48:d0:21:9e | 100 | Disabled | -+------+-------------------+--------------+----------+ -| 6 | 96:77:39:d1:de:44 | 100 | Enabled | -+------+-------------------+--------------+----------+ - - -**switch_2 sys log** - -.. code-block:: - - 2023-08-08 15:50:08,374 INFO: Turned on - 2023-08-08 15:50:08,381 INFO: SwitchPort aa:58:fa:66:d7:be enabled - 2023-08-08 15:50:08,383 INFO: SwitchPort 72:d2:1e:88:e9:45 enabled - 2023-08-08 15:50:08,384 INFO: SwitchPort 96:77:39:d1:de:44 enabled - - ------------- -Perform Ping ------------- - -Now with the network setup and operational, we can perform a ping to confirm that communication between nodes over a -switched network is possible. In the below example, we ping 192.168.0.13 (node_d) from node_a: - -.. code-block:: python - - pc_a.ping("192.168.0.13") - - -This produces: - -**node_a sys log** - -.. code-block:: - - 2023-08-08 15:50:08,355 INFO: Connected NIC 80:af:f2:f6:58:b7/192.168.0.10 - 2023-08-08 15:50:08,355 INFO: Turned on - 2023-08-08 15:50:08,355 INFO: NIC 80:af:f2:f6:58:b7/192.168.0.10 enabled - 2023-08-08 15:50:08,406 INFO: Attempting to ping 192.168.0.13 - 2023-08-08 15:50:08,406 INFO: No entry in ARP cache for 192.168.0.13 - 2023-08-08 15:50:08,406 INFO: Sending ARP request from NIC 80:af:f2:f6:58:b7/192.168.0.10 for ip 192.168.0.13 - 2023-08-08 15:50:08,413 INFO: Received ARP response for 192.168.0.13 from 84:20:7c:ec:a5:c6 via NIC 80:af:f2:f6:58:b7/192.168.0.10 - 2023-08-08 15:50:08,413 INFO: Adding ARP cache entry for 84:20:7c:ec:a5:c6/192.168.0.13 via NIC 80:af:f2:f6:58:b7/192.168.0.10 - 2023-08-08 15:50:08,415 INFO: Sending echo request to 192.168.0.13 - 2023-08-08 15:50:08,417 INFO: Received echo reply from 192.168.0.13 - 2023-08-08 15:50:08,419 INFO: Sending echo request to 192.168.0.13 - 2023-08-08 15:50:08,421 INFO: Received echo reply from 192.168.0.13 - 2023-08-08 15:50:08,422 INFO: Sending echo request to 192.168.0.13 - 2023-08-08 15:50:08,424 INFO: Received echo reply from 192.168.0.13 - 2023-08-08 15:50:08,425 INFO: Sending echo request to 192.168.0.13 - 2023-08-08 15:50:08,427 INFO: Received echo reply from 192.168.0.13 - - -**node_b sys log** - -.. code-block:: - - 2023-08-08 15:50:08,357 INFO: Connected NIC 98:ad:eb:7c:dc:cb/192.168.0.11 - 2023-08-08 15:50:08,357 INFO: Turned on - 2023-08-08 15:50:08,357 INFO: NIC 98:ad:eb:7c:dc:cb/192.168.0.11 enabled - 2023-08-08 15:50:08,410 INFO: Received ARP request for 192.168.0.13 from 80:af:f2:f6:58:b7/192.168.0.10 - 2023-08-08 15:50:08,410 INFO: Ignoring ARP request for 192.168.0.13 - - -**node_c sys log** - -.. code-block:: - - 2023-08-08 15:50:08,358 INFO: Connected NIC bc:72:82:5d:82:a4/192.168.0.12 - 2023-08-08 15:50:08,358 INFO: Turned on - 2023-08-08 15:50:08,358 INFO: NIC bc:72:82:5d:82:a4/192.168.0.12 enabled - 2023-08-08 15:50:08,411 INFO: Received ARP request for 192.168.0.13 from 80:af:f2:f6:58:b7/192.168.0.10 - 2023-08-08 15:50:08,411 INFO: Ignoring ARP request for 192.168.0.13 - - -**node_d sys log** - -.. code-block:: - - 2023-08-08 15:50:08,359 INFO: Connected NIC 84:20:7c:ec:a5:c6/192.168.0.13 - 2023-08-08 15:50:08,360 INFO: Turned on - 2023-08-08 15:50:08,360 INFO: NIC 84:20:7c:ec:a5:c6/192.168.0.13 enabled - 2023-08-08 15:50:08,412 INFO: Received ARP request for 192.168.0.13 from 80:af:f2:f6:58:b7/192.168.0.10 - 2023-08-08 15:50:08,412 INFO: Adding ARP cache entry for 80:af:f2:f6:58:b7/192.168.0.10 via NIC 84:20:7c:ec:a5:c6/192.168.0.13 - 2023-08-08 15:50:08,412 INFO: Sending ARP reply from 84:20:7c:ec:a5:c6/192.168.0.13 to 192.168.0.10/80:af:f2:f6:58:b7 - 2023-08-08 15:50:08,416 INFO: Received echo request from 192.168.0.10 - 2023-08-08 15:50:08,417 INFO: Sending echo reply to 192.168.0.10 - 2023-08-08 15:50:08,420 INFO: Received echo request from 192.168.0.10 - 2023-08-08 15:50:08,420 INFO: Sending echo reply to 192.168.0.10 - 2023-08-08 15:50:08,423 INFO: Received echo request from 192.168.0.10 - 2023-08-08 15:50:08,423 INFO: Sending echo reply to 192.168.0.10 - 2023-08-08 15:50:08,426 INFO: Received echo request from 192.168.0.10 - 2023-08-08 15:50:08,426 INFO: Sending echo reply to 192.168.0.10 - - - -**switch_1 sys log** - -.. code-block:: - - 2023-08-08 15:50:08,373 INFO: Turned on - 2023-08-08 15:50:08,378 INFO: SwitchPort 9d:ac:59:a0:05:13 enabled - 2023-08-08 15:50:08,380 INFO: SwitchPort 45:f5:8e:b6:f5:d3 enabled - 2023-08-08 15:50:08,384 INFO: SwitchPort 91:d5:83:a0:02:f2 enabled - 2023-08-08 15:50:08,409 INFO: Added MAC table entry: Port 1 -> 80:af:f2:f6:58:b7 - 2023-08-08 15:50:08,413 INFO: Added MAC table entry: Port 6 -> 84:20:7c:ec:a5:c6 - - - -**switch_2 sys log** - -.. code-block:: - - 2023-08-08 15:50:08,374 INFO: Turned on - 2023-08-08 15:50:08,381 INFO: SwitchPort aa:58:fa:66:d7:be enabled - 2023-08-08 15:50:08,383 INFO: SwitchPort 72:d2:1e:88:e9:45 enabled - 2023-08-08 15:50:08,384 INFO: SwitchPort 96:77:39:d1:de:44 enabled - 2023-08-08 15:50:08,411 INFO: Added MAC table entry: Port 6 -> 80:af:f2:f6:58:b7 - 2023-08-08 15:50:08,412 INFO: Added MAC table entry: Port 2 -> 84:20:7c:ec:a5:c6 +The Node class is the most crucial component defined in base.py, serving as the parent class for all nodes within a +PrimAITE network simulation. + +It encapsulates the following key attributes and behaviors: + +- ``hostname`` - The node's hostname on the network. +- ``network_interfaces`` - Dict of NetworkInterface objects attached to the node. +- ``operating_state`` - The hardware state (on/off) of the node. +- ``sys_log`` - System log to record node events. +- ``session_manager`` - Manages user sessions on the node. +- ``software_manager`` - Manages software and services installed on the node. +- ``connect_nic()`` - Connects a NetworkInterface to the node. +- ``disconnect_nic()`` - Disconnects a NetworkInterface from the node. +- ``receive_frame()`` - Receive and process an incoming network frame. +- ``apply_timestep()`` - Progresses node state for a simulation timestep. +- ``power_on()`` - Powers on the node and enables NICs. +- ``power_off()`` - Powers off the node and disables NICs. + + +The Node class handles installation of system software, network connectivity, frame processing, system logging, and +power states. It establishes baseline functionality while allowing subclassing to model specific node types like hosts, +routers, firewalls etc. The flexible architecture enables composing complex network topologies. diff --git a/docs/source/simulation_components/network/network.rst b/docs/source/simulation_components/network/network.rst index cb6d9392..533a15f2 100644 --- a/docs/source/simulation_components/network/network.rst +++ b/docs/source/simulation_components/network/network.rst @@ -66,9 +66,9 @@ we'll use the following Network that has a client, server, two switches, and a r .. code-block:: python - network.connect(endpoint_a=router_1.ethernet_ports[1], endpoint_b=switch_1.switch_ports[6]) + network.connect(endpoint_a=router_1.network_interfaces[1], endpoint_b=switch_1.network_interface[6]) router_1.enable_port(1) - network.connect(endpoint_a=router_1.ethernet_ports[2], endpoint_b=switch_2.switch_ports[6]) + network.connect(endpoint_a=router_1.network_interfaces[2], endpoint_b=switch_2.network_interface[6]) router_1.enable_port(2) 6. Create the Client and Server nodes. @@ -94,8 +94,8 @@ we'll use the following Network that has a client, server, two switches, and a r .. code-block:: python - network.connect(endpoint_a=switch_2.switch_ports[1], endpoint_b=client_1.ethernet_port[1]) - network.connect(endpoint_a=switch_1.switch_ports[1], endpoint_b=server_1.ethernet_port[1]) + network.connect(endpoint_a=switch_2.network_interface[1], endpoint_b=client_1.network_interface[1]) + network.connect(endpoint_a=switch_1.network_interface[1], endpoint_b=server_1.network_interface[1]) 8. Add ACL rules on the Router to allow ARP and ICMP traffic. diff --git a/docs/source/simulation_components/network/network_interfaces.rst b/docs/source/simulation_components/network/network_interfaces.rst new file mode 100644 index 00000000..9e1ad80a --- /dev/null +++ b/docs/source/simulation_components/network/network_interfaces.rst @@ -0,0 +1,118 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +################################# +Network Interface Hierarchy Model +################################# + +The network interface hierarchy model is designed to represent the various types of network interfaces and their +functionalities within a networking system. This model is organised into five distinct layers, each serving a specific +purpose in the abstraction, implementation, and utilisation of network interfaces. This hierarchical structure +facilitates modular development, enhances maintainability, and supports scalability by clearly separating concerns and +allowing for focused enhancements within each layer. + +.. image:: primaite_network_interface_model.png + +Layer Descriptions +================== + +#. **Base Layer** + + * **Purpose:** Serves as the foundation of the hierarchy, defining the most abstract properties and behaviours common + to all network interfaces. + * **Content:** Contains the NetworkInterface class, which abstracts basic functionalities such as enabling/disabling + the interface, sending, and receiving frames. + * **Significance:** Ensures that core functionalities are universally available across all types of network + interfaces, promoting code reuse and consistency. + +#. **Connection Type Layer** + + * **Purpose:** Differentiates network interfaces based on their physical connection type: wired or wireless. + * **Content:** Includes ``WiredNetworkInterface`` and ``WirelessNetworkInterface`` classes, each tailoring the base + functionalities to specific mediums. + * **Significance:** Allows the development of medium-specific features (e.g., handling point-to-point links in + wired devices) while maintaining a clear separation from IP-related functionalities. + +#. **IP Layer** + + * **Purpose:** Introduces Internet Protocol (IP) capabilities to network interfaces, enabling IP-based networking. + * **Content:** Includes ``IPWiredNetworkInterface`` and ``IPWirelessNetworkInterface`` classes, extending connection + type-specific classes with IP functionalities. + * **Significance:** Facilitates the implementation of IP address assignment, subnetting, and other Layer 3 + networking features, crucial for modern networking applications. + +#. **Interface Layer** + + * **Purpose:** Defines concrete implementations of network interfaces for specific devices or roles within a network. + * **Content:** Includes ``NIC``, ``RouterInterface``, ``SwitchPort``, ``WirelessNIC``, and ``WirelessAccessPoint`` + classes, each designed for a particular networking function or device. + * **Significance:** This layer allows developers to directly utilise or extend pre-built interfaces tailored to + specific networking tasks, enhancing development efficiency and clarity. + +#. **Device Layer** + + * **Purpose:** Maps the concrete interface implementations to their respective devices within a network, + illustrating practical usage scenarios. + * **Content:** Conceptually groups devices such as ``Computer``, ``Server``, ``Switch``, ``Router``, and ``Firewall`` + with the interfaces they utilise (e.g., ``Computer`` might use ``NIC`` or ``WirelessNIC``). + * **Significance:** Provides a clear understanding of how various network interfaces are applied in real-world + devices, aiding in system design and architecture planning. + + +Network Interface Classes +========================= + +**NetworkInterface (Base Layer)** + +Abstract base class defining core interface properties like MAC address, speed, MTU. +Requires subclasses implement key methods like send/receive frames, enable/disable interface. +Establishes universal network interface capabilities. + +**WiredNetworkInterface (Connection Type Layer)** + +- Extends NetworkInterface for wired connection interfaces. +- Adds notions of physical/logical connectivity and link management. +- Mandates subclasses implement wired-specific methods. + +**WirelessNetworkInterface (Connection Type Layer)** + +- Extends NetworkInterface for wireless interfaces. +- Encapsulates wireless-specific behaviours like signal strength handling. +- Requires wireless-specific methods in subclasses. + +**Layer3Interface (IP Layer)** + +- Introduces IP addressing abilities with ip_address and subnet_mask. +- Validates address configuration. +- Enables participation in IP networking. + +**IPWiredNetworkInterface (IP Layer)** + +- Merges Layer3Interface and WiredNetworkInterface. +- Defines wired interfaces with IP capabilities. +- Meant to be extended, doesn't implement methods. + +**IPWirelessNetworkInterface (IP Layer)** + +- Combines Layer3Interface and WirelessNetworkInterface. +- Represents wireless interfaces with IP capabilities. +- Intended to be extended and specialised. + +**NIC (Interface Layer)** + +- Concrete wired NIC implementation combining IPWiredNetworkInterface and Layer3Interface. +- Provides network connectivity for host nodes. +- Manages MAC and IP addressing, frame processing. + +**WirelessNIC (Interface Layer)** + +- Concrete wireless NIC implementation combining IPWirelessNetworkInterface and Layer3Interface. +- Delivers wireless connectivity with IP for hosts. +- Handles wireless transmission/reception. + +**WirelessAccessPoint (Interface Layer)** + +- Concrete wireless access point implementation using IPWirelessNetworkInterface and Layer3Interface. +- Bridges wireless and wired networks. +- Manages wireless network. diff --git a/docs/source/simulation_components/network/nodes/host_node.rst b/docs/source/simulation_components/network/nodes/host_node.rst new file mode 100644 index 00000000..bc3c13a5 --- /dev/null +++ b/docs/source/simulation_components/network/nodes/host_node.rst @@ -0,0 +1,47 @@ + +######### +Host Node +######### + +The ``host_node.py`` module is a core component of the PrimAITE project, aimed at simulating network host. It +encapsulates the functionality necessary for modelling the behaviour, communication capabilities, and interactions of +hosts in a networked environment. + + +HostNode Class +============== + +The ``HostNode`` class acts as a foundational representation of a networked device or computer, capable of both +initiating and responding to network communications. + +**Attributes:** + +- Manages IP addressing with support for IPv4. +- Employs ``NIC`` or ``WirelessNIC`` (subclasses of``IPWiredNetworkInterface``) to simulate wired network connections. +- Integrates with ``SysLog`` for logging operational events, aiding in debugging and monitoring the host node's + behaviour. + +**Key Methods:** + +- Facilitates the sending and receiving of ``Frame`` objects to simulate data link layer communications. +- Manages a variety of network services and applications, enhancing the simulation's realism and functionality. + +Default Services and Applications +================================= + +Both the ``HostNode`` and its subclasses come equipped with a suite of default services and applications critical for +fundamental network operations: + +1. **ARP (Address Resolution Protocol):** The ``HostARP`` subclass enhances ARP functionality for host-specific + operations. + +2. **DNS (Domain Name System) Client:** Facilitates domain name resolution to IP addresses, enabling web navigation. + +3. **FTP (File Transfer Protocol) Client:** Supports file transfers across the network. + +4. **ICMP (Internet Control Message Protocol):** Utilised for network diagnostics and control, such as executing ping + requests. + +5. **NTP (Network Time Protocol) Client:** Synchronises the host's clock with network time servers. + +6. **Web Browser:** A simulated application that allows the host to request and display web content. diff --git a/docs/source/simulation_components/network/nodes/network_node.rst b/docs/source/simulation_components/network/nodes/network_node.rst new file mode 100644 index 00000000..eb9997ba --- /dev/null +++ b/docs/source/simulation_components/network/nodes/network_node.rst @@ -0,0 +1,41 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +############ +Network Node +############ + + +The ``network_node.py`` module within the PrimAITE project is pivotal for simulating network nodes like routers and +switches, which are integral to network traffic management. This module establishes the framework for these devices, +enabling them to receive and process network frames effectively. + +Overview +======== + +The module defines the ``NetworkNode`` class, an abstract base class that outlines essential behaviours for network +devices tasked with handling network traffic. It is designed to be extended by more specific device simulations that +implement these foundational capabilities. + +NetworkNode Class +================= + +The ``NetworkNode`` class is at the heart of the module, providing an interface for network devices that participate +in the transmission and routing of data within the simulated environment. + +**Key Features:** + +- **Frame Processing:** Central to the class is the ability to receive and process network frames, facilitating the +simulation of data flow through network devices. + +- **Abstract Methods:** Includes abstract methods such as ``receive_frame``, which subclasses must implement to specify + how devices handle incoming traffic. + +- **Extensibility:** Designed for extension, allowing for the creation of specific device simulations, such as router + and switch classes, that embody unique behaviours and functionalities. + + +The ``network_node.py`` module's abstract approach to defining network devices allows the PrimAITE project to simulate +a wide range of network behaviours and scenarios comprehensively. By providing a common framework for all network +nodes, it facilitates the development of a modular and scalable simulation environment. diff --git a/docs/source/simulation_components/network/nodes/router.rst b/docs/source/simulation_components/network/nodes/router.rst new file mode 100644 index 00000000..7679baa0 --- /dev/null +++ b/docs/source/simulation_components/network/nodes/router.rst @@ -0,0 +1,41 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +###### +Router +###### + +The ``router.py`` module is a pivotal component of the PrimAITE, designed to simulate the complex functionalities of a +router within a network simulation. Routers are essential for directing traffic between different network segments, +and this module provides the tools necessary to model these devices' behaviour and capabilities accurately. + +Router Class +------------ + +The ``Router`` class embodies the core functionalities of a network router, extending the ``NetworkNode`` class to +incorporate routing-specific behaviours. + +**Key Features:** + +- **IP Routing:** Supports dynamic handling of IP packets, including forwarding based on destination IP addresses and + subnetting. +- **Routing Table:** Maintains a routing table to determine the best path for forwarding packets. +- **Protocol Support:** Implements support for key networking protocols, including ARP for address resolution and ICMP + for diagnostic messages. +- **Interface Management:** Manages multiple ``RouterInterface`` instances, enabling connections to different network + segments. +- **Network Interface Configuration:** Tools for configuring router interfaces, including setting IP addresses, subnet + masks, and enabling/disabling interfaces. +- **Logging and Monitoring:** Integrates with ``SysLog`` for logging operational events, aiding in debugging and + monitoring router behaviour. + +**Operations:** + +- **Packet Forwarding:** Utilises the routing table to forward packets to their correct destination across + interconnected networks. +- **ARP Handling:** Responds to ARP requests for any IP addresses configured on its interfaces, facilitating + communication within local networks. +- **ICMP Processing:** Generates and processes ICMP packets, such as echo requests and replies, for network diagnostics. + +The ``router.py`` module offers a comprehensive simulation of router functionalities. By providing detailed modelling of router operations, including packet forwarding, interface management, and protocol handling, PrimAITE enables the exploration of advanced network topologies and routing scenarios. diff --git a/docs/source/simulation_components/network/nodes/switch.rst b/docs/source/simulation_components/network/nodes/switch.rst new file mode 100644 index 00000000..0595f363 --- /dev/null +++ b/docs/source/simulation_components/network/nodes/switch.rst @@ -0,0 +1,29 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +###### +Switch +###### + +The ``switch.py`` module is a crucial component of the PrimAITE, aimed at simulating network switches within a network simulation environment. Network switches play a vital role in managing data flow within local area networks (LANs) by forwarding frames based on MAC addresses. This module provides a comprehensive framework for modelling switch operations and behaviours. + +Switch Class Overview +--------------------- + +The module introduces the concept of switch ports through the ``SwitchPort`` class, which extends the functionality of ``WiredNetworkInterface`` to simulate the operation of switch ports in a network. + +**Key Features:** + +- **Data Link Layer Operation:** Operates at the data link layer (Layer 2) of the OSI model, handling the reception and forwarding of frames based on MAC addresses. +- **Port Management:** Tools for configuring switch ports, including enabling/disabling ports, setting port speeds, and managing port security features. +- **Logging and Monitoring:** Integrates with ``SysLog`` for logging operational events, aiding in debugging and + monitoring switch behaviour. + +Functionality and Implementation +--------------------------------- + +- **MAC Address Learning:** Dynamically learns and associates MAC addresses with switch ports, enabling intelligent frame forwarding. +- **Frame Forwarding:** Utilises the learned MAC address table to forward frames only to the specific port associated with the destination MAC address, minimising unnecessary network traffic. + +The ``switch.py`` module offers a realistic and configurable representation of switch operations. By detailing the functionalities of the ``SwitchPort`` class, the module lays the foundation for simulating complex network topologies. diff --git a/docs/source/simulation_components/network/primaite_network_interface_model.png b/docs/source/simulation_components/network/primaite_network_interface_model.png new file mode 100644 index 0000000000000000000000000000000000000000..68b052936ca54a5610520d0af17323216e1e5eb0 GIT binary patch literal 46770 zcmeFZXH-)`7dCnj4TzyADg+Qv5d;;`P(lY$ktQ8fKtz<#2}QurjRX*oE-myXML|H6 zUP6%;sv_t&N6)%wq^o!wtNp8Hv1oX37l%*`*TXzITTi*9Uc8~i>zzp#}3_I=K~g0#%s z_eGz|tB6r?N&Z3M`o?DQ$?1kB7X5?6GrwlDa`Joo`kk=emDR-fq;wU{`^(EK0l|@2 z51*mo(RcYDUiiK0=;|pdF3rl#4~>XFUn+<1J><2Feja z_huLY9{((1cTeVJw$h=a`9ZS8?Ch<|ckAD+Sc`sXy#JaSOGRFi{}2A`F~3U5*%009 zd^%4FEyURko0mNu+q)~J@@`B<<0u5FL@JF{Iyjd#2)erv3>&L-+?h^8vWFJk#8>-S zcBiK|l}xI^p0YnZT`+&H$RAtsl^Fwryq-t0tQo#oW6sedP(Vo{({JWa6g5`4miF(z zrEDrCKg(2%!Xaq&9*=uelGLs_4hca$JhcciJq?PI1VQRY&}8P>BXATYBzuZLfrg+r z&ygd5N(TcYbEYAA0V?g9eIma9pXmQrgpw>tP-Er@*eM&~UIgRR9@yWXqlQ^W!Jb;+ zp%5ef^2KhrJgWzL%Y%m#?XtP8iC`ouqe+6p8A@D=MN?&XNR}J)OCy{XH54Nj+fr@> zJss9L44tb%+<%I9$?CBYdi~k0Ov_@(`3!~Ejpz3Gye98g*zgG@>#a&!nGyWz-O7NIqe7)B0LW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+=BPx{{p70X$*{MB2oEp|tYE%~qA5j{X4{#WKE@9-#8(SUNsNu2;p){r#)qS2eF zcd{XkmUMIIPeQ;b5hyn}Wp7=de?TMd5v9IpzFAJ+b)KdzyhM*nmPI36Y$;ILYDlK% z2so6OD|I0b8R&oj?1y*wCKMtD;L_svJ%#T>vgVZWOkryxAEsNa0Cbmq{ z#z$KvS=%A|XS)^6MLSiKe10}nc(UVoyY21RN9Ku=Ea*Vd%P_iUJ+`)34Ni;$_`}72 z1wP;SiB{Hi4#0rLa?pVsYcRCH-bc`5H$toTS%&p*|Nm_kJ-jM)dndP@UOT8VyAuCR zY`y`WKOg|BS2$1^E>*R+_-n#hu;)M<2J>5bp$~#l#H*Eop^64j449_fNmGMmY@w__ zBzL|_TdxQ bool: - """ - Receive and process a network frame from the connected link, provided the NIC is enabled. - - This method is tailored for router behavior. It decrements the frame's Time To Live (TTL), checks for TTL - expiration, and captures the frame using PCAP (Packet Capture). The frame is accepted if it is destined for - this NIC's MAC address or is a broadcast frame. - - Key Differences from Standard NIC: - - Does not perform Layer 3 (IP-based) broadcast checks. - - Only checks for Layer 2 (Ethernet) destination MAC address and broadcast frames. - - :param frame: The network frame being received. This should be an instance of the Frame class. - :return: Returns True if the frame is processed and passed to the connected node, False otherwise. - """ - if self.enabled: - frame.decrement_ttl() - if frame.ip and frame.ip.ttl < 1: - self._connected_node.sys_log.info("Frame discarded as TTL limit reached") - return False - frame.set_received_timestamp() - self.pcap.capture_inbound(frame) - # If this destination or is broadcast - if frame.ethernet.dst_mac_addr == self.mac_address or frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": - self._connected_node.receive_frame(frame=frame, from_network_interface=self) - return True - return False - - def __str__(self) -> str: - return f"{self.mac_address}/{self.ip_address}" - - class RouterInterface(IPWiredNetworkInterface): """ Represents a Router Interface. From 0acd9a29385e543590e3c781b5eb68a149caa5a3 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 9 Feb 2024 10:27:22 +0000 Subject: [PATCH 580/980] #2248 - Removed redundant code and added more documentation from PR suggestions --- .../network/base_hardware.rst | 48 +++++++++++++------ .../simulator/network/hardware/base.py | 4 -- .../simulator/system/core/packet_capture.py | 2 +- .../_system/_services/test_web_server.py | 16 ------- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/docs/source/simulation_components/network/base_hardware.rst b/docs/source/simulation_components/network/base_hardware.rst index 10ed59c6..c7545810 100644 --- a/docs/source/simulation_components/network/base_hardware.rst +++ b/docs/source/simulation_components/network/base_hardware.rst @@ -21,24 +21,42 @@ NetworkInterface Node ==== +The Node class stands as a central component in ``base.py``, acting as the superclass for all network nodes within a +PrimAITE simulation. -The Node class is the most crucial component defined in base.py, serving as the parent class for all nodes within a -PrimAITE network simulation. -It encapsulates the following key attributes and behaviors: -- ``hostname`` - The node's hostname on the network. -- ``network_interfaces`` - Dict of NetworkInterface objects attached to the node. -- ``operating_state`` - The hardware state (on/off) of the node. -- ``sys_log`` - System log to record node events. -- ``session_manager`` - Manages user sessions on the node. -- ``software_manager`` - Manages software and services installed on the node. -- ``connect_nic()`` - Connects a NetworkInterface to the node. -- ``disconnect_nic()`` - Disconnects a NetworkInterface from the node. -- ``receive_frame()`` - Receive and process an incoming network frame. -- ``apply_timestep()`` - Progresses node state for a simulation timestep. -- ``power_on()`` - Powers on the node and enables NICs. -- ``power_off()`` - Powers off the node and disables NICs. +Node Attributes +--------------- + + +- **hostname**: The network hostname of the node. +- **operating_state**: Indicates the current hardware state of the node. +- **network_interfaces**: Maps interface names to NetworkInterface objects on the node. +- **network_interface**: Maps port IDs to ``NetworkInterface`` objects on the node. +- **dns_server**: Specifies DNS servers for domain name resolution. +- **start_up_duration**: The time it takes for the node to become fully operational after being powered on. +- **shut_down_duration**: The time required for the node to properly shut down. +- **sys_log**: A system log for recording events related to the node. +- **session_manager**: Manages user sessions within the node. +- **software_manager**: Controls the installation and management of software and services on the node. + +Node Behaviours/Functions +------------------------- + + +- **connect_nic()**: Connects a ``NetworkInterface`` to the node for network communication. +- **disconnect_nic()**: Removes a ``NetworkInterface`` from the node. +- **receive_frame()**: Handles the processing of incoming network frames. +- **apply_timestep()**: Advances the state of the node according to the simulation timestep. +- **power_on()**: Initiates the node, enabling all connected Network Interfaces and starting all Services and + Applications, taking into account the `start_up_duration`. +- **power_off()**: Stops the node's operations, adhering to the `shut_down_duration`. +- **ping()**: Sends ICMP echo requests to a specified IP address to test connectivity. +- **has_enabled_network_interface()**: Checks if the node has any network interfaces enabled, facilitating network + communication. +- **show()**: Provides a summary of the node's current state, including network interfaces, operational status, and + other key attributes. The Node class handles installation of system software, network connectivity, frame processing, system logging, and diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 541e6428..f5bd5ff5 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -725,10 +725,6 @@ class Node(SimComponent): self._install_system_software() self.set_original_state() - # def model_post_init(self, __context: Any) -> None: - # self._install_system_software() - # self.set_original_state() - def set_original_state(self): """Sets the original state.""" for software in self.software_manager.software.values(): diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index 3f34cad8..fb8a1624 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -102,7 +102,7 @@ class PacketCapture: def capture_outbound(self, frame): # noqa - I'll have a circular import and cant use if TYPE_CHECKING ;( """ - Capture an inbound Frame and log it. + Capture an outbound Frame and log it. :param frame: The PCAP frame to capture. """ diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py index 0d9d68b7..6fac0bcf 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py @@ -52,19 +52,3 @@ def test_handling_get_request_home_page(web_server): response: HttpResponsePacket = web_server_service._handle_get_request(payload=payload) assert response.status_code == HttpStatusCode.OK - - -# def test_process_http_request_get(web_server): -# payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url="http://domain.com/") -# -# web_server_service: WebServer = web_server.software_manager.software.get("WebServer") -# -# assert web_server_service._process_http_request(payload=payload) is True -# -# -# def test_process_http_request_method_not_allowed(web_server): -# payload = HttpRequestPacket(request_method=HttpRequestMethod.DELETE, request_url="http://domain.com/") -# -# web_server_service: WebServer = web_server.software_manager.software.get("WebServer") -# -# assert web_server_service._process_http_request(payload=payload) is False From bebfbd53be796bedb18ebc46958b07326a03165d Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 9 Feb 2024 10:30:39 +0000 Subject: [PATCH 581/980] #2248 - MAde tests use new way of accessing network interfaces by their port number --- .../system/red_applications/test_dos_bot_and_server.py | 4 ++-- tests/integration_tests/system/test_dns_client_server.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py index 7ab7d104..e42862bf 100644 --- a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py +++ b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py @@ -24,7 +24,7 @@ def dos_bot_and_db_server(client_server) -> Tuple[DoSBot, Computer, DatabaseServ dos_bot: DoSBot = computer.software_manager.software.get("DoSBot") dos_bot.configure( - target_ip_address=IPv4Address(server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address), + target_ip_address=IPv4Address(server.network_interface[1].ip_address), target_port=Port.POSTGRES_SERVER, ) @@ -54,7 +54,7 @@ def dos_bot_db_server_green_client(example_network) -> Network: dos_bot: DoSBot = client_1.software_manager.software.get("DoSBot") dos_bot.configure( - target_ip_address=IPv4Address(server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address), + target_ip_address=IPv4Address(server.network_interface[1].ip_address), target_port=Port.POSTGRES_SERVER, ) diff --git a/tests/integration_tests/system/test_dns_client_server.py b/tests/integration_tests/system/test_dns_client_server.py index 78d2035c..e6275459 100644 --- a/tests/integration_tests/system/test_dns_client_server.py +++ b/tests/integration_tests/system/test_dns_client_server.py @@ -29,7 +29,7 @@ def dns_client_and_dns_server(client_server) -> Tuple[DNSClient, Computer, DNSSe # register arcd.com as a domain dns_server.dns_register( domain_name="arcd.com", - domain_ip_address=IPv4Address(server.network_interfaces.get(next(iter(server.network_interfaces))).ip_address), + domain_ip_address=IPv4Address(server.network_interface[1].ip_address), ) return dns_client, computer, dns_server, server From 2518a426040d4274eafed70152c12dcd2b0b6cee Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 9 Feb 2024 11:03:48 +0000 Subject: [PATCH 582/980] #2248 - Dropped old router_arp.py module. Fixed the ICMP codes as per IANA (https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml) --- .../simulator/network/protocols/icmp.py | 4 +- .../system/services/arp/router_arp.py | 78 ------------------- 2 files changed, 2 insertions(+), 80 deletions(-) delete mode 100644 src/primaite/simulator/system/services/arp/router_arp.py diff --git a/src/primaite/simulator/network/protocols/icmp.py b/src/primaite/simulator/network/protocols/icmp.py index 66215db0..35b0a05d 100644 --- a/src/primaite/simulator/network/protocols/icmp.py +++ b/src/primaite/simulator/network/protocols/icmp.py @@ -21,9 +21,9 @@ class ICMPType(Enum): "Redirect." ECHO_REQUEST = 8 "Echo Request (ping)." - ROUTER_ADVERTISEMENT = 10 + ROUTER_ADVERTISEMENT = 9 "Router Advertisement." - ROUTER_SOLICITATION = 11 + ROUTER_SOLICITATION = 10 "Router discovery/selection/solicitation." TIME_EXCEEDED = 11 "Time Exceeded." diff --git a/src/primaite/simulator/system/services/arp/router_arp.py b/src/primaite/simulator/system/services/arp/router_arp.py deleted file mode 100644 index d9108910..00000000 --- a/src/primaite/simulator/system/services/arp/router_arp.py +++ /dev/null @@ -1,78 +0,0 @@ -# from ipaddress import IPv4Address -# from typing import Optional, Any -# -# from primaite.simulator.network.hardware.nodes.network.router import RouterInterface, Router -# from primaite.simulator.network.protocols.arp import ARPPacket -# from primaite.simulator.network.transmission.data_link_layer import Frame -# from primaite.simulator.system.services.arp.arp import ARP -# -# -# class RouterARP(ARP): -# """ -# Inherits from ARPCache and adds router-specific ARP packet processing. -# -# :ivar SysLog sys_log: A system log for logging messages. -# :ivar Router router: The router to which this ARP cache belongs. -# """ -# router: Router -# -# def get_arp_cache_mac_address(self, ip_address: IPv4Address) -> Optional[str]: -# arp_entry = self.arp.get(ip_address) -# -# if arp_entry: -# return arp_entry.mac_address -# return None -# -# def get_arp_cache_network_interface(self, ip_address: IPv4Address) -> Optional[RouterInterface]: -# arp_entry = self.arp.get(ip_address) -# if arp_entry: -# return self.software_manager.node.network_interfaces[arp_entry.network_interface_uuid] -# return None -# -# def _process_arp_request(self, arp_packet: ARPPacket, from_network_interface: RouterInterface): -# super()._process_arp_request(arp_packet, from_network_interface) -# self.add_arp_cache_entry( -# ip_address=arp_packet.sender_ip_address, mac_address=arp_packet.sender_mac_addr, -# network_interface=from_network_interface -# ) -# -# # If the target IP matches one of the router's NICs -# for network_interface in self.network_interfaces.values(): -# if network_interface.enabled and network_interface.ip_address == arp_packet.target_ip_address: -# arp_reply = arp_packet.generate_reply(from_network_interface.mac_address) -# self.send_arp_reply(arp_reply) -# return -# -# def _process_arp_reply(self, arp_packet: ARPPacket, from_network_interface: RouterInterface): -# if arp_packet.target_ip_address == from_network_interface.ip_address: -# super()._process_arp_reply(arp_packet, from_network_interface) -# -# def receive(self, payload: Any, session_id: str, **kwargs) -> bool: -# """ -# Processes received data, handling ARP packets. -# -# :param payload: The payload received. -# :param session_id: The session ID associated with the received data. -# :param kwargs: Additional keyword arguments. -# :return: True if the payload was processed successfully, otherwise False. -# """ -# if not super().receive(payload, session_id, **kwargs): -# return False -# -# arp_packet: ARPPacket = payload -# from_network_interface: RouterInterface = kwargs["from_network_interface"] -# -# for network_interface in self.network_interfaces.values(): -# # ARP frame is for this Router -# if network_interface.ip_address == arp_packet.target_ip_address: -# if payload.request: -# self._process_arp_request(arp_packet=arp_packet, from_network_interface=from_network_interface) -# else: -# self._process_arp_reply(arp_packet=arp_packet, from_network_interface=from_network_interface) -# return True -# -# # ARP frame is not for this router, pass back down to Router to continue routing -# frame: Frame = kwargs["frame"] -# self.router.process_frame(frame=frame, from_network_interface=from_network_interface) -# -# return True From cceb6208e04a680927b921ce5c1d866b54e50cdd Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 9 Feb 2024 11:09:44 +0000 Subject: [PATCH 583/980] #2248 - Reset the auto save pcap and syslog to False --- src/primaite/simulator/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index 97bcd57b..aebd77cf 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -12,8 +12,8 @@ class _SimOutput: self._path: Path = ( _PRIMAITE_ROOT.parent.parent / "simulation_output" / datetime.now().strftime("%Y-%m-%d_%H-%M-%S") ) - self.save_pcap_logs: bool = True - self.save_sys_logs: bool = True + self.save_pcap_logs: bool = False + self.save_sys_logs: bool = False @property def path(self) -> Path: From 6b3829dc48175d5711b771bf777ddceb4dec8002 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 9 Feb 2024 11:37:47 +0000 Subject: [PATCH 584/980] #2248 - Removed redundant Union from single type params --- src/primaite/simulator/network/container.py | 6 ++---- src/primaite/simulator/network/hardware/base.py | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 2ea2a7fa..b32d2630 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Optional, Union +from typing import Any, Dict, List, Optional import matplotlib.pyplot as plt import networkx as nx @@ -272,9 +272,7 @@ class Network(SimComponent): self._node_request_manager.remove_request(name=node.hostname) _LOGGER.info(f"Removed node {node.hostname} from network {self.uuid}") - def connect( - self, endpoint_a: Union[WiredNetworkInterface], endpoint_b: Union[WiredNetworkInterface], **kwargs - ) -> Optional[Link]: + def connect(self, endpoint_a: WiredNetworkInterface, endpoint_b: WiredNetworkInterface, **kwargs) -> Optional[Link]: """ Connect two endpoints on the network by creating a link between their NICs/SwitchPorts. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index f5bd5ff5..55640121 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -509,9 +509,9 @@ class Link(SimComponent): :param bandwidth: The bandwidth of the Link in Mbps (default is 100 Mbps). """ - endpoint_a: Union[WiredNetworkInterface] + endpoint_a: WiredNetworkInterface "The first WiredNetworkInterface connected to the Link." - endpoint_b: Union[WiredNetworkInterface] + endpoint_b: WiredNetworkInterface "The second WiredNetworkInterface connected to the Link." bandwidth: float = 100.0 "The bandwidth of the Link in Mbps (default is 100 Mbps)." @@ -596,7 +596,7 @@ class Link(SimComponent): return True return False - def transmit_frame(self, sender_nic: Union[WiredNetworkInterface], frame: Frame) -> bool: + def transmit_frame(self, sender_nic: WiredNetworkInterface, frame: Frame) -> bool: """ Send a network frame from one NIC or SwitchPort to another connected NIC or SwitchPort. From d1c3f891bf0ef19fcbccb5e22cb1b4c71aa47514 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 9 Feb 2024 11:41:06 +0000 Subject: [PATCH 585/980] #2258: moving applications to application types - more tests --- src/primaite/game/game.py | 26 +++-- .../configs/basic_switched_network.yaml | 22 +++-- tests/integration_tests/game_configuration.py | 99 +++++++++++++++++-- 3 files changed, 123 insertions(+), 24 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index b2b35f26..431db5fb 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -33,12 +33,16 @@ from primaite.simulator.system.services.web_server.web_server import WebServer _LOGGER = getLogger(__name__) -APPLICATION_TYPES_MAPPING = {"WebBrowser": WebBrowser, "DataManipulationBot": DataManipulationBot, "DoSBot": DoSBot} +APPLICATION_TYPES_MAPPING = { + "WebBrowser": WebBrowser, + "DatabaseClient": DatabaseClient, + "DataManipulationBot": DataManipulationBot, + "DoSBot": DoSBot, +} SERVICE_TYPES_MAPPING = { "DNSClient": DNSClient, "DNSServer": DNSServer, - "DatabaseClient": DatabaseClient, "DatabaseService": DatabaseService, "WebServer": WebServer, "FTPClient": FTPClient, @@ -262,22 +266,21 @@ class PrimaiteGame: else: _LOGGER.warning(f"service type not found {service_type}") # service-dependent options - if service_type == "DatabaseClient": + if service_type == "DNSClient": if "options" in service_cfg: opt = service_cfg["options"] - if "db_server_ip" in opt: - new_service.configure(server_ip_address=IPv4Address(opt["db_server_ip"])) + if "dns_server" in opt: + new_service.dns_server = IPv4Address(opt["dns_server"]) if service_type == "DNSServer": if "options" in service_cfg: opt = service_cfg["options"] if "domain_mapping" in opt: for domain, ip in opt["domain_mapping"].items(): - new_service.dns_register(domain, ip) + new_service.dns_register(domain, IPv4Address(ip)) if service_type == "DatabaseService": if "options" in service_cfg: opt = service_cfg["options"] - if "backup_server_ip" in opt: - new_service.configure_backup(backup_server=IPv4Address(opt["backup_server_ip"])) + new_service.configure_backup(backup_server=IPv4Address(opt.get("backup_server_ip"))) new_service.start() if "applications" in node_cfg: @@ -303,6 +306,13 @@ class PrimaiteGame: port_scan_p_of_success=float(opt.get("port_scan_p_of_success", "0.1")), data_manipulation_p_of_success=float(opt.get("data_manipulation_p_of_success", "0.1")), ) + elif application_type == "DatabaseClient": + if "options" in application_cfg: + opt = application_cfg["options"] + new_application.configure( + server_ip_address=IPv4Address(opt.get("db_server_ip")), + server_password=opt.get("server_password"), + ) elif application_type == "WebBrowser": if "options" in application_cfg: opt = application_cfg["options"] diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index d86af779..0050a0cb 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -81,6 +81,10 @@ simulation: type: WebBrowser options: target_url: http://arcd.com/users/ + - ref: client_1_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.10 - ref: data_manipulation_bot type: DataManipulationBot options: @@ -95,27 +99,25 @@ simulation: payload: SPOOF DATA port_scan_p_of_success: 0.8 services: + - ref: client_1_dns_client + type: DNSClient + options: + dns_server: 192.168.1.10 - ref: client_1_dns_server type: DNSServer options: domain_mapping: - arcd.com: 192.168.1.12 # web server - - ref: client_1_database_client - type: DatabaseClient - options: - db_server_ip: 192.168.10.21 - - ref: client_1_dosbot - type: DoSBot - options: - db_server_ip: 192.168.10.21 + arcd.com: 192.168.1.10 - ref: client_1_database_service type: DatabaseService options: - backup_server_ip: 192.168.10.21 + backup_server_ip: 192.168.1.10 - ref: client_1_web_service type: WebServer - ref: client_1_ftp_server type: FTPServer + - ref: client_1_ntp_client + type: NTPClient - ref: client_1_ntp_server type: NTPServer - ref: client_2 diff --git a/tests/integration_tests/game_configuration.py b/tests/integration_tests/game_configuration.py index 274e8bd6..9db894c5 100644 --- a/tests/integration_tests/game_configuration.py +++ b/tests/integration_tests/game_configuration.py @@ -10,12 +10,18 @@ from primaite.game.agent.interface import ProxyAgent, RandomAgent from primaite.game.game import APPLICATION_TYPES_MAPPING, PrimaiteGame, SERVICE_TYPES_MAPPING from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.applications.red_applications.dos_bot import DoSBot from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.dns.dns_client import DNSClient +from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.ftp.ftp_client import FTPClient +from primaite.simulator.system.services.ftp.ftp_server import FTPServer from primaite.simulator.system.services.ntp.ntp_client import NTPClient +from primaite.simulator.system.services.ntp.ntp_server import NTPServer +from primaite.simulator.system.services.web_server.web_server import WebServer from tests import TEST_ASSETS_ROOT BASIC_CONFIG = TEST_ASSETS_ROOT / "configs/basic_switched_network.yaml" @@ -33,19 +39,23 @@ def test_example_config(): """Test that the example config can be parsed properly.""" game = load_config(example_config_path()) - assert len(game.agents) == 3 # red, blue and green agent + assert len(game.agents) == 4 # red, blue and 2 green agents - # green agent + # green agent 1 assert game.agents[0].agent_name == "client_2_green_user" assert isinstance(game.agents[0], RandomAgent) + # green agent 2 + assert game.agents[1].agent_name == "client_1_green_user" + assert isinstance(game.agents[1], RandomAgent) + # red agent - assert game.agents[1].agent_name == "client_1_data_manipulation_red_bot" - assert isinstance(game.agents[1], DataManipulationAgent) + assert game.agents[2].agent_name == "client_1_data_manipulation_red_bot" + assert isinstance(game.agents[2], DataManipulationAgent) # blue agent - assert game.agents[2].agent_name == "defender" - assert isinstance(game.agents[2], ProxyAgent) + assert game.agents[3].agent_name == "defender" + assert isinstance(game.agents[3], ProxyAgent) network: Network = game.simulation.network @@ -91,6 +101,16 @@ def test_web_browser_install(): assert web_browser.target_url == "http://arcd.com/users/" +def test_database_client_install(): + """Test that the Database Client service can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + database_client: DatabaseClient = client_1.software_manager.software.get("DatabaseClient") + + assert database_client.server_ip_address == IPv4Address("192.168.1.10") + + def test_data_manipulation_bot_install(): """Test that the data manipulation bot can be configured via config.""" game = load_config(BASIC_CONFIG) @@ -117,3 +137,70 @@ def test_dos_bot_install(): assert dos_bot.dos_intensity == 1.0 # default assert dos_bot.max_sessions == 1000 # default assert dos_bot.repeat is False # default + + +def test_dns_client_install(): + """Test that the DNS Client service can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + dns_client: DNSClient = client_1.software_manager.software.get("DNSClient") + + assert dns_client.dns_server == IPv4Address("192.168.1.10") + + +def test_database_service_install(): + """Test that the Database Service can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + database_service: DatabaseService = client_1.software_manager.software.get("DatabaseService") + + assert database_service.backup_server_ip == IPv4Address("192.168.1.10") + + +def test_web_server_install(): + """Test that the Web Server Service can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + web_server_service: WebServer = client_1.software_manager.software.get("WebServer") + + # config should have also installed database client - web server service should be able to retrieve this + assert web_server_service.software_manager.software.get("DatabaseClient") is not None + + +def test_ftp_client_install(): + """Test that the FTP Client Service can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + ftp_client_service: FTPClient = client_1.software_manager.software.get("FTPClient") + assert ftp_client_service is not None + + +def test_ftp_server_install(): + """Test that the FTP Server Service can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + ftp_server_service: FTPServer = client_1.software_manager.software.get("FTPServer") + assert ftp_server_service is not None + + +def test_ntp_client_install(): + """Test that the NTP Client Service can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + ntp_client_service: NTPClient = client_1.software_manager.software.get("NTPClient") + assert ntp_client_service is not None + + +def test_ntp_server_install(): + """Test that the NTP Server Service can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + ntp_server_service: NTPServer = client_1.software_manager.software.get("NTPServer") + assert ntp_server_service is not None From 58af58810da74e17b5426da1697f229ce1b8dc49 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 9 Feb 2024 23:29:06 +0000 Subject: [PATCH 586/980] #2205 - Introduced a Firewall class for enhanced network security and control, extending Router functionalities. Updated ACLRule to support IP ranges via wildcard masking for refined traffic filtering. Includes documentation updates. --- CHANGELOG.md | 8 +- docs/source/simulation.rst | 1 + .../network/nodes/firewall.rst | 432 +++++++++++++++ src/primaite/simulator/__init__.py | 4 +- .../hardware/nodes/network/firewall.py | 492 ++++++++++++++++++ .../network/hardware/nodes/network/router.py | 387 ++++++++++---- .../network/transmission/network_layer.py | 6 +- .../network/test_firewall.py | 280 ++++++++++ .../_network/_hardware/nodes/test_acl.py | 330 +++++++++--- 9 files changed, 1759 insertions(+), 181 deletions(-) create mode 100644 docs/source/simulation_components/network/nodes/firewall.rst create mode 100644 src/primaite/simulator/network/hardware/nodes/network/firewall.py create mode 100644 tests/integration_tests/network/test_firewall.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 9716fd0e..a18e4d2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,7 +71,12 @@ SessionManager. - Detailed descriptions of the Session Manager and Software Manager functionalities, including their roles in managing sessions, software services, and applications within the simulation. - Documentation for the Packet Capture (PCAP) service and SysLog functionality, highlighting their importance in logging network frames and system events, respectively. - Expanded documentation on network devices such as Routers, Switches, Computers, and Switch Nodes, explaining their specific processing logic and protocol support. - +- **Firewall Node**: Introduced the `Firewall` class extending the functionality of the existing `Router` class. The `Firewall` class incorporates advanced features to scrutinize, direct, and filter traffic between various network zones, guided by predefined security rules and policies. Key functionalities include: + - Access Control Lists (ACLs) for traffic filtering based on IP addresses, protocols, and port numbers. + - Network zone segmentation for managing traffic across external, internal, and DMZ (De-Militarized Zone) networks. + - Interface configuration to establish connectivity and define network parameters for external, internal, and DMZ interfaces. + - Protocol and service management to oversee traffic and enforce security policies. + - Dynamic traffic processing and filtering to ensure network security and integrity. ### Changed - Integrated the RouteTable into the Routers frame processing. @@ -82,6 +87,7 @@ SessionManager. - Standardised the way network interfaces are accessed across all `Node` subclasses (`HostNode`, `Router`, `Switch`) by maintaining a comprehensive `network_interface` attribute. This attribute captures all network interfaces by their port number, streamlining the management and interaction with network interfaces across different types of nodes. - Refactored all tests to utilise new `Node` subclasses (`Computer`, `Server`, `Router`, `Switch`) instead of creating generic `Node` instances and manually adding network interfaces. This change aligns test setups more closely with the intended use cases and hierarchies within the network simulation framework. - Updated all tests to employ the `Network()` class for managing nodes and their connections, ensuring a consistent and structured approach to setting up network topologies in testing scenarios. +- **ACLRule Wildcard Masking**: Updated the `ACLRule` class to support IP ranges using wildcard masking. This enhancement allows for more flexible and granular control over traffic filtering, enabling the specification of broader or more specific IP address ranges in ACL rules. ### Removed diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index d85a1449..56761517 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -22,6 +22,7 @@ Contents simulation_components/network/nodes/host_node simulation_components/network/nodes/network_node simulation_components/network/nodes/router + simulation_components/network/nodes/firewall simulation_components/network/switch simulation_components/network/network simulation_components/system/internal_frame_processing diff --git a/docs/source/simulation_components/network/nodes/firewall.rst b/docs/source/simulation_components/network/nodes/firewall.rst new file mode 100644 index 00000000..39f804c4 --- /dev/null +++ b/docs/source/simulation_components/network/nodes/firewall.rst @@ -0,0 +1,432 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +######## +Firewall +######## + +The ``firewall.py`` module is a cornerstone in network security within the PrimAITE simulation, designed to simulate +the functionalities of a firewall in monitoring, controlling, and securing network traffic. + +Firewall Class +-------------- + +The ``Firewall`` class extends the ``Router`` class, incorporating advanced capabilities to scrutinise, direct, +and filter traffic between various network zones, guided by predefined security rules and policies. + +Key Features +============ + + +- **Access Control Lists (ACLs):** Employs ACLs to establish security rules for permitting or denying traffic + based on IP addresses, protocols, and port numbers, offering detailed oversight of network traffic. +- **Network Zone Segmentation:** Facilitates network division into distinct zones, including internal, external, + and DMZ (De-Militarized Zone), each governed by specific inbound and outbound traffic rules. +- **Interface Configuration:** Enables the configuration of network interfaces for connectivity to external, + internal, and DMZ networks, including setting up IP addressing and subnetting. +- **Protocol and Service Management:** Oversees and filters traffic across different protocols and services, + enforcing adherence to established security policies. +- **Dynamic Traffic Processing:** Actively processes incoming and outgoing traffic via relevant ACLs, determining + whether to forward or block based on the evaluation of rules. +- **Logging and Diagnostics:** Integrates with ``SysLog`` for detailed logging of firewall actions, supporting + security monitoring and incident investigation. + +Operations +========== + +- **Rule Definition and Management:** Permits the creation and administration of ACL rules for precise traffic + control, enabling the firewall to serve as an effective guard against unauthorised access. +- **Traffic Forwarding and Filtering:** Assesses network frames against ACL rules to allow or block traffic, + forwarding permitted traffic towards its destination whilst obstructing malicious or unauthorised requests. +- **Interface and Zone Configuration:** Provides mechanisms for configuring and managing network interfaces, + aligning with logical network architecture and security zoning requisites. + +Configuring Interfaces +====================== + +To set up firewall interfaces, allocate IP addresses and subnet masks to the external, internal, and DMZ interfaces +using the respective configuration methods: + +.. code-block:: python + + firewall.configure_external_port(ip_address="10.0.0.1", subnet_mask="255.255.255.0") + firewall.configure_internal_port(ip_address="192.168.1.1", subnet_mask="255.255.255.0") + firewall.configure_dmz_port(ip_address="172.16.0.1", subnet_mask="255.255.255.0") + + +Firewall ACLs +============= + +In the PrimAITE network simulation, six Access Control Lists (ACLs) are crucial for delineating and enforcing +comprehensive network security measures. These ACLs, designated as internal inbound, internal outbound, DMZ inbound, +DMZ outbound, external inbound, and external outbound, each serve a specific role in orchestrating the flow of data +through the network. They allow for meticulous control of traffic entering, exiting, and moving within the network, +ensuring robust protection against unauthorised access and potential cyber threats. By leveraging these ACLs both +individually and collectively, users can simulate a multi-layered security architecture. + +Internal Inbound ACL +^^^^^^^^^^^^^^^^^^^^ + +This ACL controls incoming traffic from the external network and DMZ to the internal network. It's crucial for +preventing unauthorised access to internal resources. By filtering incoming requests, it ensures that only legitimate +and necessary traffic can enter the internal network, protecting sensitive data and systems. + +Internal Outbound ACL +^^^^^^^^^^^^^^^^^^^^^ + +The internal outbound ACL manages traffic leaving the internal network to the external network or DMZ. It can restrict +internal users or systems from accessing potentially harmful external sites or services, mitigate data exfiltration +risks. + +DMZ Inbound ACL +^^^^^^^^^^^^^^^ + +This ACL regulates access to services hosted in the DMZ from the external network and internal network. Since the DMZ +hosts public-facing services like web and email servers, the DMZ inbound ACL is pivotal in allowing necessary access +while blocking malicious or unauthorised attempts, thus serving as a first line of defence. + +DMZ Outbound ACL +^^^^^^^^^^^^^^^^ + +The ACL controls traffic from DMZ to the external network and internal network. It's used to restrict the DMZ services +from initiating unauthorised connections, which is essential for preventing compromised DMZ services from being used +as launchpads for attacks or data exfiltration. + +External Inbound ACL +^^^^^^^^^^^^^^^^^^^^ + +This ACL filters all incoming traffic from the external network towards the internal network or DMZ. It's instrumental +in blocking unwanted or potentially harmful external traffic, ensuring that only traffic conforming to the security +policies is allowed into the network. **This ACL should only be used when the rule applies to both internal and DMZ +networks.** + +External Outbound ACL +^^^^^^^^^^^^^^^^^^^^^ + +This ACL governs traffic leaving the internal network or DMZ to the external network. It plays a critical role in data +loss prevention (DLP) by restricting the types of data and services that internal users and systems can access or +interact with on external networks. **This ACL should only be used when the rule applies to both internal and DMZ +networks.** + +Using ACLs Together +^^^^^^^^^^^^^^^^^^^ + +When these ACLs are used in concert, they create a robust security matrix that controls traffic flow in all directions: +into the internal network, out of the internal network, into the DMZ, out of the DMZ, and between these networks and +the external world. For example, while the external inbound ACL might block all incoming SSH requests to protect both +the internal network and DMZ, the internal outbound ACL could allow SSH access to specific external servers for +management purposes. Simultaneously, the DMZ inbound ACL might permit HTTP and HTTPS traffic to specific servers to +provide access to web services while the DMZ outbound ACL ensures these servers cannot make unauthorised outbound +connections. + +By effectively configuring and managing these ACLs, users can establish and experiment with detailed security policies +that are finely tuned to their simulated network's unique requirements and threat models, achieving granular oversight +over traffic flows. This not only enables secure simulated interactions and data exchanges within PrimAITE environments +but also fortifies the virtual network against unauthorised access and cyber threats, mirroring real-world network +security practices. + + +ACL Configuration Examples +========================== + +The subsequent examples provide detailed illustrations on configuring ACL rules within PrimAITE's firewall setup, +addressing various scenarios that encompass external attempts to access resources not only within the internal network +but also within the DMZ. These examples reflect the firewall's specific port configurations and showcase the +versatility and control that ACLs offer in managing network traffic, ensuring that security policies are precisely +enforced. Each example highlights different aspects of ACL usage, from basic traffic filtering to more complex +scenarios involving specific service access and protection against external threats. + +**Blocking External Traffic to Internal Network** + +To prevent all external traffic from accessing the internal network, with exceptions for approved services: + +.. code-block:: python + + # Default rule to deny all external traffic to the internal network + firewall.internal_inbound_acl.add_rule( + action=ACLAction.DENY, + src_ip_address="0.0.0.0", + src_wildcard_mask="255.255.255.255", + dst_ip_address="192.168.1.0", + dst_wildcard_mask="0.0.0.255", + position=1 + ) + + # Exception rule to allow HTTP traffic from external to internal network + firewall.internal_inbound_acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + dst_port=Port.HTTP, + dst_ip_address="192.168.1.0", + dst_wildcard_mask="0.0.0.255", + position=2 + ) + +**Allowing External Access to Specific Services in DMZ** + +To enable external traffic to access specific services hosted within the DMZ: + +.. code-block:: python + + # Allow HTTP and HTTPS traffic to the DMZ + firewall.dmz_inbound_acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + dst_port=Port.HTTP, + dst_ip_address="172.16.0.0", + dst_wildcard_mask="0.0.0.255", + position=3 + ) + firewall.dmz_inbound_acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + dst_port=Port.HTTPS, + dst_ip_address="172.16.0.0", + dst_wildcard_mask="0.0.0.255", + position=4 + ) + +**Edge Case - Permitting External SSH Access to a Specific Internal Server** + +To permit SSH access from a designated external IP to a specific server within the internal network: + +.. code-block:: python + + # Allow SSH from a specific external IP to an internal server + firewall.internal_inbound_acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + src_ip_address="10.0.0.2", + dst_port=Port.SSH, + dst_ip_address="192.168.1.10", + position=5 + ) + +**Restricting Access to Internal Database Server** + +To limit database server access to selected external IP addresses: + +.. code-block:: python + + # Allow PostgreSQL traffic from an authorized external IP to the internal DB server + firewall.internal_inbound_acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + src_ip_address="10.0.0.3", + dst_port=Port.POSTGRES_SERVER, + dst_ip_address="192.168.1.20", + position=6 + ) + + # Deny all other PostgreSQL traffic from external sources + firewall.internal_inbound_acl.add_rule( + action=ACLAction.DENY, + protocol=IPProtocol.TCP, + dst_port=Port.POSTGRES_SERVER, + dst_ip_address="192.168.1.0", + dst_wildcard_mask="0.0.0.255", + position=7 + ) + +**Permitting DMZ Web Server Access while Blocking Specific Threats* + +To authorize HTTP/HTTPS access to a DMZ-hosted web server, excluding known malicious IPs: + +.. code-block:: python + + # Deny access from a known malicious IP to any DMZ service + firewall.dmz_inbound_acl.add_rule( + action=ACLAction.DENY, + src_ip_address="10.0.0.4", + dst_ip_address="172.16.0.0", + dst_wildcard_mask="0.0.0.255", + position=8 + ) + + # Allow HTTP/HTTPS traffic to the DMZ web server + firewall.dmz_inbound_acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + dst_port=Port.HTTP, + dst_ip_address="172.16.0.2", + position=9 + ) + firewall.dmz_inbound_acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + dst_port=Port.HTTPS, + dst_ip_address="172.16.0.2", + position=10 + ) + +**Enabling Internal to DMZ Restricted Access** + +To facilitate restricted access from the internal network to DMZ-hosted services: + +.. code-block:: python + + # Permit specific internal application server HTTPS access to a DMZ-hosted API + firewall.internal_outbound_acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + src_ip_address="192.168.1.30", # Internal application server IP + dst_port=Port.HTTPS, + dst_ip_address="172.16.0.3", # DMZ API server IP + position=11 + ) + + # Deny all other traffic from the internal network to the DMZ + firewall.internal_outbound_acl.add_rule( + action=ACLAction.DENY, + src_ip_address="192.168.1.0", + src_wildcard_mask="0.0.0.255", + dst_ip_address="172.16.0.0", + dst_wildcard_mask="0.0.0.255", + position=12 + ) + + # Corresponding rule in DMZ inbound ACL to allow the traffic from the specific internal server + firewall.dmz_inbound_acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + src_ip_address="192.168.1.30", # Ensuring this specific source is allowed + dst_port=Port.HTTPS, + dst_ip_address="172.16.0.3", # DMZ API server IP + position=13 + ) + + # Deny all other internal traffic to the specific DMZ API server + firewall.dmz_inbound_acl.add_rule( + action=ACLAction.DENY, + src_ip_address="192.168.1.0", + src_wildcard_mask="0.0.0.255", + dst_port=Port.HTTPS, + dst_ip_address="172.16.0.3", # DMZ API server IP + position=14 + ) + +**Blocking Unwanted External Access** + +To block all SSH access attempts from the external network: + +.. code-block:: python + + # Deny all SSH traffic from any external source + firewall.external_inbound_acl.add_rule( + action=ACLAction.DENY, + protocol=IPProtocol.TCP, + dst_port=Port.SSH, + position=1 + ) + +**Allowing Specific External Communication** + +To allow the internal network to initiate HTTP connections to the external network: + +.. code-block:: python + + # Permit outgoing HTTP traffic from the internal network to any external destination + firewall.external_outbound_acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + dst_port=Port.HTTP, + position=2 + ) + + +The examples above demonstrate the versatility and power of ACLs in crafting nuanced security policies. By combining +rules that specify permitted and denied traffic, both broadly and narrowly defined, administrators can construct +a firewall policy that safeguards network resources while ensuring necessary access is maintained. + +Show Rules Function +=================== + +The show_rules function in the Firewall class displays the configurations of Access Control Lists (ACLs) within a +network firewall. It presents a comprehensive table detailing the rules that govern the filtering and management of +network traffic. + +**Functionality:** + +This function showcases each rule in an ACL, outlining its: + +- **Index**: The rule's position within the ACL. +- **Action**: Specifies whether to permit or deny matching traffic. +- **Protocol**: The network protocol to which the rule applies. +- **Src IP and Dst IP**: Source and destination IP addresses. +- **Src Wildcard and Dst** Wildcard: Wildcard masks for source and destination IP ranges. +- **Src Port and Dst Port**: Source and destination ports. +- **Hit Count**: The number of times the rule has been matched by traffic. + +Example Output: + +.. code-block:: text + + +---------------------------------------------------------------------------------------------------------------+ + | firewall_1 - External Inbound Access Control List | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Hit Count | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + | 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 1 | + | 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 0 | + | 24 | PERMIT | ANY | ANY | ANY | ANY | ANY | ANY | ANY | 2 | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + + +---------------------------------------------------------------------------------------------------------------+ + | firewall_1 - External Outbound Access Control List | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Hit Count | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + | 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 0 | + | 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 0 | + | 24 | PERMIT | ANY | ANY | ANY | ANY | ANY | ANY | ANY | 2 | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + + +---------------------------------------------------------------------------------------------------------------+ + | firewall_1 - Internal Inbound Access Control List | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Hit Count | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + | 1 | PERMIT | ANY | ANY | ANY | 123 (NTP) | ANY | ANY | 123 (NTP) | 1 | + | 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 0 | + | 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 0 | + | 24 | DENY | ANY | ANY | ANY | ANY | ANY | ANY | ANY | 0 | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + + +---------------------------------------------------------------------------------------------------------------+ + | firewall_1 - Internal Outbound Access Control List | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Hit Count | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + | 1 | PERMIT | ANY | ANY | ANY | 123 (NTP) | ANY | ANY | 123 (NTP) | 1 | + | 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 1 | + | 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 0 | + | 24 | DENY | ANY | ANY | ANY | ANY | ANY | ANY | ANY | 0 | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + + +---------------------------------------------------------------------------------------------------------------+ + | firewall_1 - DMZ Inbound Access Control List | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Hit Count | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + | 1 | PERMIT | ANY | ANY | ANY | 123 (NTP) | ANY | ANY | 123 (NTP) | 1 | + | 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 0 | + | 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 0 | + | 24 | DENY | ANY | ANY | ANY | ANY | ANY | ANY | ANY | 0 | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + + +---------------------------------------------------------------------------------------------------------------+ + | firewall_1 - DMZ Outbound Access Control List | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Hit Count | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + | 1 | PERMIT | ANY | ANY | ANY | 123 (NTP) | ANY | ANY | 123 (NTP) | 1 | + | 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 1 | + | 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 0 | + | 24 | DENY | ANY | ANY | ANY | ANY | ANY | ANY | ANY | 0 | + +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ + + +The ``firewall.py`` module within PrimAITE empowers users to accurately model and simulate the pivotal role of +firewalls in network security. It provides detailed command over traffic flow and enforces security policies to safeguard +networked assets. diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index aebd77cf..97bcd57b 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -12,8 +12,8 @@ class _SimOutput: self._path: Path = ( _PRIMAITE_ROOT.parent.parent / "simulation_output" / datetime.now().strftime("%Y-%m-%d_%H-%M-%S") ) - self.save_pcap_logs: bool = False - self.save_sys_logs: bool = False + self.save_pcap_logs: bool = True + self.save_sys_logs: bool = True @property def path(self) -> Path: diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py new file mode 100644 index 00000000..bccfeab1 --- /dev/null +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -0,0 +1,492 @@ +from typing import Dict, Final, Optional, Union + +from prettytable import MARKDOWN, PrettyTable +from pydantic import validate_call + +from primaite.simulator.network.hardware.nodes.network.router import ( + AccessControlList, + ACLAction, + Router, + RouterInterface, +) +from primaite.simulator.network.transmission.data_link_layer import Frame +from primaite.simulator.system.core.sys_log import SysLog +from primaite.utils.validators import IPV4Address + +EXTERNAL_PORT_ID: Final[int] = 1 +"""The Firewall port ID of the external port.""" +INTERNAL_PORT_ID: Final[int] = 2 +"""The Firewall port ID of the internal port.""" +DMZ_PORT_ID: Final[int] = 3 +"""The Firewall port ID of the DMZ port.""" + + +class Firewall(Router): + """ + A Firewall class that extends the functionality of a Router. + + The Firewall class acts as a network security system that monitors and controls incoming and outgoing + network traffic based on predetermined security rules. It is an intermediary between internal and external + networks (including DMZ - De-Militarized Zone), ensuring that all inbound and outbound traffic complies with + the security policies. + + The Firewall employs Access Control Lists (ACLs) to filter traffic. Both the internal and DMZ ports have both + inbound and outbound ACLs that determine what traffic is allowed to pass. + + In addition to the security functions, the Firewall can also perform some routing functions similar to a Router, + forwarding packets between its interfaces based on the destination IP address. + + Usage: + To utilise the Firewall class, instantiate it with a hostname and optionally specify sys_log for logging. + Configure the internal, external, and DMZ ports with IP addresses and subnet masks. Define ACL rules to + permit or deny traffic based on your security policies. The Firewall will process frames based on these + rules, determining whether to allow or block traffic at each network interface. + + Example: + >>> from primaite.simulator.network.transmission.network_layer import IPProtocol + >>> from primaite.simulator.network.transmission.transport_layer import Port + >>> firewall = Firewall(hostname="Firewall1") + >>> firewall.configure_internal_port(ip_address="192.168.1.1", subnet_mask="255.255.255.0") + >>> firewall.configure_external_port(ip_address="10.0.0.1", subnet_mask="255.255.255.0") + >>> firewall.configure_dmz_port(ip_address="172.16.0.1", subnet_mask="255.255.255.0") + >>> # Permit HTTP traffic to the DMZ + >>> firewall.dmz_inbound_acl.add_rule( + ... action=ACLAction.PERMIT, + ... protocol=IPProtocol.TCP, + ... dst_port=Port.HTTP, + ... src_ip_address="0.0.0.0", + ... src_wildcard_mask="0.0.0.0", + ... dst_ip_address="172.16.0.0", + ... dst_wildcard_mask="0.0.0.255" + ... ) + + :ivar str hostname: The Firewall hostname. + """ + + internal_inbound_acl: Optional[AccessControlList] = None + """Access Control List for managing entering the internal network.""" + + internal_outbound_acl: Optional[AccessControlList] = None + """Access Control List for managing traffic leaving the internal network.""" + + dmz_inbound_acl: Optional[AccessControlList] = None + """Access Control List for managing traffic entering the DMZ.""" + + dmz_outbound_acl: Optional[AccessControlList] = None + """Access Control List for managing traffic leaving the DMZ.""" + + external_inbound_acl: Optional[AccessControlList] = None + """Access Control List for managing traffic entering from an external network.""" + + external_outbound_acl: Optional[AccessControlList] = None + """Access Control List for managing traffic leaving towards an external network.""" + + def __init__(self, hostname: str, **kwargs): + if not kwargs.get("sys_log"): + kwargs["sys_log"] = SysLog(hostname) + + super().__init__(hostname=hostname, num_ports=3, **kwargs) + + # Initialise ACLs for internal and dmz interfaces with a default DENY policy + self.internal_inbound_acl = AccessControlList( + sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY, name=f"{hostname} - Internal Inbound" + ) + self.internal_outbound_acl = AccessControlList( + sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY, name=f"{hostname} - Internal Outbound" + ) + self.dmz_inbound_acl = AccessControlList( + sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY, name=f"{hostname} - DMZ Inbound" + ) + self.dmz_outbound_acl = AccessControlList( + sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY, name=f"{hostname} - DMZ Outbound" + ) + + # external ACLs should have a default PERMIT policy + self.external_inbound_acl = AccessControlList( + sys_log=kwargs["sys_log"], implicit_action=ACLAction.PERMIT, name=f"{hostname} - External Inbound" + ) + self.external_outbound_acl = AccessControlList( + sys_log=kwargs["sys_log"], implicit_action=ACLAction.PERMIT, name=f"{hostname} - External Outbound" + ) + + self.set_original_state() + + def set_original_state(self): + """Set the original state for the Firewall.""" + super().set_original_state() + vals_to_include = { + "internal_port", + "external_port", + "dmz_port", + "internal_inbound_acl", + "internal_outbound_acl", + "dmz_inbound_acl", + "dmz_outbound_acl", + } + self._original_state.update(self.model_dump(include=vals_to_include)) + + def describe_state(self) -> Dict: + """ + Describes the current state of the Firewall. + + :return: A dictionary representing the current state. + """ + state = super().describe_state() + + state.update( + { + "internal_port": self.internal_port.describe_state(), + "external_port": self.external_port.describe_state(), + "dmz_port": self.dmz_port.describe_state(), + "internal_inbound_acl": self.internal_inbound_acl.describe_state(), + "internal_outbound_acl": self.internal_outbound_acl.describe_state(), + "dmz_inbound_acl": self.dmz_inbound_acl.describe_state(), + "dmz_outbound_acl": self.dmz_outbound_acl.describe_state(), + } + ) + + return state + + def show(self, markdown: bool = False): + """ + Displays the current configuration of the firewall's network interfaces in a table format. + + The table includes information about each port (External, Internal, DMZ), their MAC addresses, IP + configurations, link speeds, and operational status. The output can be formatted as Markdown if specified. + + :param markdown: If True, formats the output table in Markdown style. Useful for documentation or reporting + purposes within Markdown-compatible platforms. + """ + table = PrettyTable(["Port", "MAC Address", "Address", "Speed", "Status"]) + if markdown: + table.set_style(MARKDOWN) + table.align = "l" + table.title = f"{self.hostname} Network Interfaces" + ports = {"External": self.external_port, "Internal": self.internal_port, "DMZ": self.dmz_port} + for port, network_interface in ports.items(): + table.add_row( + [ + port, + network_interface.mac_address, + f"{network_interface.ip_address}/{network_interface.ip_network.prefixlen}", + network_interface.speed, + "Enabled" if network_interface.enabled else "Disabled", + ] + ) + print(table) + + def show_rules(self, external: bool = True, internal: bool = True, dmz: bool = True, markdown: bool = False): + """ + Prints the configured ACL rules for each specified network zone of the firewall. + + This method allows selective viewing of ACL rules applied to external, internal, and DMZ interfaces, providing + a clear overview of the firewall's current traffic filtering policies. Each section can be independently + toggled. + + :param external: If True, shows ACL rules for external interfaces. + :param internal: If True, shows ACL rules for internal interfaces. + :param dmz: If True, shows ACL rules for DMZ interfaces. + :param markdown: If True, formats the output in Markdown, enhancing readability in Markdown-compatible viewers. + """ + print(f"{self.hostname} Firewall Rules") + print() + if external: + self.external_inbound_acl.show(markdown) + print() + self.external_outbound_acl.show(markdown) + print() + if internal: + self.internal_inbound_acl.show(markdown) + print() + self.internal_outbound_acl.show(markdown) + print() + if dmz: + self.dmz_inbound_acl.show(markdown) + print() + self.dmz_outbound_acl.show(markdown) + print() + + def receive_frame(self, frame: Frame, from_network_interface: RouterInterface): + """ + Receive a frame and process it. + + Acts as the primary entry point for all network frames arriving at the Firewall, determining the flow of + traffic based on the source network interface controller (NIC) and applying the appropriate Access Control + List (ACL) rules. + + This method categorizes the incoming traffic into three main pathways based on the source NIC: external inbound, + internal outbound, and DMZ (De-Militarized Zone) outbound. It plays a crucial role in enforcing the firewall's + security policies by directing each frame to the corresponding processing method that evaluates it against + specific ACL rules. + + Based on the originating NIC: + - Frames from the external port are processed as external inbound traffic, potentially destined for either the + DMZ or the internal network. + - Frames from the internal port are treated as internal outbound traffic, aimed at reaching the external + network or a service within the DMZ. + - Frames from the DMZ port are handled as DMZ outbound traffic, with potential destinations including the + internal network or the external network. + + :param frame: The network frame to be processed. + :param from_network_interface: The network interface controller from which the frame is coming. Used to + determine the direction of the traffic (inbound or outbound) and the zone (external, internal, + DMZ) it belongs to. + """ + # If the frame comes from the external port, it's considered as external inbound traffic + if from_network_interface == self.external_port: + self._process_external_inbound_frame(frame, from_network_interface) + return + # If the frame comes from the internal port, it's considered as internal outbound traffic + elif from_network_interface == self.internal_port: + self._process_internal_outbound_frame(frame, from_network_interface) + return + # If the frame comes from the DMZ port, it's considered as DMZ outbound traffic + elif from_network_interface == self.dmz_port: + self._process_dmz_outbound_frame(frame, from_network_interface) + return + + def _process_external_inbound_frame(self, frame: Frame, from_network_interface: RouterInterface) -> None: + """ + Process frames arriving from the external network. + + Determines the path for frames based on their destination IP addresses and ACL rules for the external inbound + interface. Frames destined for the DMZ or internal network are forwarded accordingly, if allowed by the ACL. + + If a frame is permitted by the ACL, it is either passed to the session manager (if applicable) or forwarded to + the appropriate network zone (DMZ/internal). Denied frames are logged and dropped. + + :param frame: The frame to be processed, containing network layer and transport layer information. + :param from_network_interface: The interface on the firewall through which the frame was received. + """ + # check if External Inbound ACL Rules permit frame + permitted, rule = self.external_inbound_acl.is_permitted(frame) + if not permitted: + self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}") + return + else: + self.software_manager.arp.add_arp_cache_entry( + ip_address=frame.ip.src_ip_address, + mac_address=frame.ethernet.src_mac_addr, + network_interface=from_network_interface, + ) + + if self.check_send_frame_to_session_manager(frame): + # Port is open on this Router so pass Frame up to session manager first + self.session_manager.receive_frame(frame, from_network_interface) + else: + # If the destination IP is within the DMZ network, process the frame as DMZ inbound + if frame.ip.dst_ip_address in self.dmz_port.ip_network: + self._process_dmz_inbound_frame(frame, from_network_interface) + else: + # Otherwise, process the frame as internal inbound + self._process_internal_inbound_frame(frame, from_network_interface) + + def _process_external_outbound_frame(self, frame: Frame, from_network_interface: RouterInterface) -> None: + """ + Process frames that are outbound towards the external network. + + :param frame: The frame to be processed. + :param from_network_interface: The network interface controller from which the frame is coming. + :param re_attempt: Indicates if the processing is a re-attempt, defaults to False. + """ + # check if External Outbound ACL Rules permit frame + permitted, rule = self.external_outbound_acl.is_permitted(frame=frame) + if not permitted: + self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}") + return + + self.process_frame(frame=frame, from_network_interface=from_network_interface) + + def _process_internal_inbound_frame(self, frame: Frame, from_network_interface: RouterInterface) -> None: + """ + Process frames that are inbound towards the internal LAN. + + This method is responsible for handling frames coming from either the external network or the DMZ towards + the internal LAN. It checks the frames against the internal inbound ACL to decide whether to allow or deny + the traffic, and take appropriate actions. + + :param frame: The frame to be processed. + :param from_network_interface: The network interface controller from which the frame is coming. + :param re_attempt: Indicates if the processing is a re-attempt, defaults to False. + """ + # check if Internal Inbound ACL Rules permit frame + permitted, rule = self.internal_inbound_acl.is_permitted(frame=frame) + if not permitted: + self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}") + return + + self.process_frame(frame=frame, from_network_interface=from_network_interface) + + def _process_internal_outbound_frame(self, frame: Frame, from_network_interface: RouterInterface) -> None: + """ + Process frames that are outbound from the internal network. + + This method handles frames that are leaving the internal network. Depending on the destination IP address, + the frame may be forwarded to the DMZ or to the external network. + + :param frame: The frame to be processed. + :param from_network_interface: The network interface controller from which the frame is coming. + :param re_attempt: Indicates if the processing is a re-attempt, defaults to False. + """ + permitted, rule = self.internal_outbound_acl.is_permitted(frame) + if not permitted: + self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}") + return + else: + self.software_manager.arp.add_arp_cache_entry( + ip_address=frame.ip.src_ip_address, + mac_address=frame.ethernet.src_mac_addr, + network_interface=from_network_interface, + ) + + if self.check_send_frame_to_session_manager(frame): + # Port is open on this Router so pass Frame up to session manager first + self.session_manager.receive_frame(frame, from_network_interface) + else: + # If the destination IP is within the DMZ network, process the frame as DMZ inbound + if frame.ip.dst_ip_address in self.dmz_port.ip_network: + self._process_dmz_inbound_frame(frame, from_network_interface) + else: + # If the destination IP is not within the DMZ network, process the frame as external outbound + self._process_external_outbound_frame(frame, from_network_interface) + + def _process_dmz_inbound_frame(self, frame: Frame, from_network_interface: RouterInterface) -> None: + """ + Process frames that are inbound from the DMZ. + + This method is responsible for handling frames coming from either the external network or the internal LAN + towards the DMZ. It checks the frames against the DMZ inbound ACL to decide whether to allow or deny the + traffic, and take appropriate actions. + + :param frame: The frame to be processed. + :param from_network_interface: The network interface controller from which the frame is coming. + :param re_attempt: Indicates if the processing is a re-attempt, defaults to False. + """ + # check if DMZ Inbound ACL Rules permit frame + permitted, rule = self.dmz_inbound_acl.is_permitted(frame=frame) + if not permitted: + self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}") + return + + self.process_frame(frame=frame, from_network_interface=from_network_interface) + + def _process_dmz_outbound_frame(self, frame: Frame, from_network_interface: RouterInterface) -> None: + """ + Process frames that are outbound from the DMZ. + + This method handles frames originating from the DMZ and determines their appropriate path based on the + destination IP address. It involves checking the DMZ outbound ACL, consulting the ARP cache and the routing + table to find the correct outbound NIC, and then forwarding the frame to either the internal network or the + external network. + + :param frame: The frame to be processed. + :param from_network_interface: The network interface controller from which the frame is coming. + :param re_attempt: Indicates if the processing is a re-attempt, defaults to False. + """ + permitted, rule = self.dmz_outbound_acl.is_permitted(frame) + if not permitted: + self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}") + return + else: + self.software_manager.arp.add_arp_cache_entry( + ip_address=frame.ip.src_ip_address, + mac_address=frame.ethernet.src_mac_addr, + network_interface=from_network_interface, + ) + + if self.check_send_frame_to_session_manager(frame): + # Port is open on this Router so pass Frame up to session manager first + self.session_manager.receive_frame(frame, from_network_interface) + else: + # Attempt to get the outbound NIC from the ARP cache using the destination IP address + outbound_nic = self.software_manager.arp.get_arp_cache_network_interface(frame.ip.dst_ip_address) + + # If outbound NIC is not found in the ARP cache, consult the routing table to find the best route + if not outbound_nic: + route = self.route_table.find_best_route(frame.ip.dst_ip_address) + if route: + # If a route is found, get the corresponding outbound NIC from the ARP cache using the next-hop IP + # address + outbound_nic = self.software_manager.arp.get_arp_cache_network_interface(route.next_hop_ip_address) + + # If an outbound NIC is determined + if outbound_nic: + if outbound_nic == self.external_port: + # If the outbound NIC is the external port, check the frame against the DMZ outbound ACL and + # process it as an external outbound frame + self._process_external_outbound_frame(frame, from_network_interface) + return + elif outbound_nic == self.internal_port: + # If the outbound NIC is the internal port, check the frame against the DMZ outbound ACL and + # process it as an internal inbound frame + self._process_internal_inbound_frame(frame, from_network_interface) + return + # TODO: What to do here? Destination unreachable? Send ICMP back? + return + + @property + def external_port(self) -> RouterInterface: + """ + The external port of the firewall. + + :return: The external port connecting the firewall to the external network. + """ + return self.network_interface[EXTERNAL_PORT_ID] + + @validate_call() + def configure_external_port(self, ip_address: Union[IPV4Address, str], subnet_mask: Union[IPV4Address, str]): + """ + Configure the external port with an IP address and a subnet mask. + + Enables the port once configured. + + :param ip_address: The IP address to assign to the external port. + :param subnet_mask: The subnet mask to assign to the external port. + """ + # Configure the external port with the specified IP address and subnet mask + self.configure_port(EXTERNAL_PORT_ID, ip_address, subnet_mask) + self.external_port.enable() + + @property + def internal_port(self) -> RouterInterface: + """ + The internal port of the firewall. + + :return: The external port connecting the firewall to the internal LAN. + """ + return self.network_interface[INTERNAL_PORT_ID] + + @validate_call() + def configure_internal_port(self, ip_address: Union[IPV4Address, str], subnet_mask: Union[IPV4Address, str]): + """ + Configure the internal port with an IP address and a subnet mask. + + Enables the port once configured. + + :param ip_address: The IP address to assign to the internal port. + :param subnet_mask: The subnet mask to assign to the internal port. + """ + self.configure_port(INTERNAL_PORT_ID, ip_address, subnet_mask) + self.internal_port.enable() + + @property + def dmz_port(self) -> RouterInterface: + """ + The DMZ port of the firewall. + + :return: The external port connecting the firewall to the DMZ. + """ + return self.network_interface[DMZ_PORT_ID] + + @validate_call() + def configure_dmz_port(self, ip_address: Union[IPV4Address, str], subnet_mask: Union[IPV4Address, str]): + """ + Configure the DMZ port with an IP address and a subnet mask. + + Enables the port once configured. + + :param ip_address: The IP address to assign to the DMZ port. + :param subnet_mask: The subnet mask to assign to the DMZ port. + """ + self.configure_port(DMZ_PORT_ID, ip_address, subnet_mask) + self.dmz_port.enable() diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 40cbc16d..0ad64d18 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -6,6 +6,7 @@ from ipaddress import IPv4Address, IPv4Network from typing import Any, Dict, List, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable +from pydantic import validate_call from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import IPWiredNetworkInterface @@ -19,6 +20,43 @@ from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.services.arp.arp import ARP from primaite.simulator.system.services.icmp.icmp import ICMP +from primaite.utils.validators import IPV4Address + + +@validate_call() +def ip_matches_masked_range(ip_to_check: IPV4Address, base_ip: IPV4Address, wildcard_mask: IPV4Address) -> bool: + """ + Determine if a given IP address matches a range defined by a base IP address and a wildcard mask. + + The wildcard mask specifies which bits in the IP address should be ignored (1) and which bits must match (0). + + The function applies the wildcard mask to both the base IP and the IP address to check by first negating the + wildcard mask and then performing a bitwise AND operation. This process effectively masks out the bits indicated + by the wildcard mask. If the resulting masked IP addresses are equal, it means the IP address to check falls within + the range defined by the base IP and wildcard mask. + + :param IPv4Address ip_to_check: The IP address to be checked. + :param IPv4Address base_ip: The base IP address defining the start of the range. + :param IPv4Address wildcard_mask: The wildcard mask specifying which bits to ignore. + :return: A boolean value indicating whether the IP address matches the masked range. + :rtype: bool + + Example usage: + >>> ip_matches_masked_range(ip_to_check="192.168.10.10", base_ip="192.168.1.1", wildcard_mask="0.0.255.255") + False + """ + # Convert the IP addresses from IPv4Address objects to integer representations for bitwise operations + base_ip_int = int(base_ip) + ip_to_check_int = int(ip_to_check) + wildcard_int = int(wildcard_mask) + + # Negate the wildcard mask and apply it to both the base IP and the IP to check using bitwise AND + # This step masks out the bits to be ignored according to the wildcard mask + masked_base_ip = base_ip_int & ~wildcard_int + masked_ip_to_check = ip_to_check_int & ~wildcard_int + + # Compare the masked IP addresses to determine if they match within the masked range + return masked_base_ip == masked_ip_to_check class ACLAction(Enum): @@ -30,22 +68,62 @@ class ACLAction(Enum): class ACLRule(SimComponent): """ - Represents an Access Control List (ACL) rule. + Represents an Access Control List (ACL) rule within a network device. - :ivar ACLAction action: Action to be performed (Permit/Deny). Default is DENY. - :ivar Optional[IPProtocol] protocol: Network protocol. Default is None. - :ivar Optional[IPv4Address] src_ip_address: Source IP address. Default is None. - :ivar Optional[Port] src_port: Source port number. Default is None. - :ivar Optional[IPv4Address] dst_ip_address: Destination IP address. Default is None. - :ivar Optional[Port] dst_port: Destination port number. Default is None. + Enables fine-grained control over network traffic based on specified criteria such as IP addresses, protocols, + and ports. ACL rules can be configured to permit or deny traffic, providing a powerful mechanism for enforcing + security policies and traffic flow. + + ACL rules support specifying exact match conditions, ranges of IP addresses using wildcard masks, and + protocol types. This flexibility allows for complex traffic filtering scenarios, from blocking or allowing + specific types of traffic to entire subnets. + + **Usage:** + + - **Dedicated IP Addresses**: To match traffic from or to a specific IP address, set the `src_ip_address` + and/or `dst_ip_address` without a wildcard mask. This is useful for rules that apply to individual hosts. + + - **IP Ranges with Wildcard Masks**: For rules that apply to a range of IP addresses, use the `src_wildcard_mask` + and/or `dst_wildcard_mask` in conjunction with the base IP address. Wildcard masks are a way to specify which + bits of the IP address should be matched exactly and which bits can vary. For example, a wildcard mask of + `0.0.0.255` applied to a base address of `192.168.1.0` allows for any address from `192.168.1.0` to + `192.168.1.255`. + + - **Allowing All IP Traffic**: To mimic the Cisco ACL rule that permits all IP traffic from a specific range, + you may use wildcard masks with the rule action set to `PERMIT`. If your implementation includes an `ALL` + option in the `IPProtocol` enum, use it to allow all protocols; otherwise, consider the rule without a + specified protocol to apply to all IP traffic. + + + The combination of these attributes allows for the creation of granular rules to control traffic flow + effectively, enhancing network security and management. + + + :ivar ACLAction action: Specifies whether to `PERMIT` or `DENY` the traffic that matches the rule conditions. + The default action is `DENY`. + :ivar Optional[IPProtocol] protocol: The network protocol (e.g., TCP, UDP, ICMP) to match. If `None`, the rule + applies to all protocols. + :ivar Optional[IPv4Address] src_ip_address: The source IP address to match. If combined with `src_wildcard_mask`, + it specifies the start of an IP range. + :ivar Optional[IPv4Address] src_wildcard_mask: The wildcard mask for the source IP address, defining the range + of addresses to match. + :ivar Optional[IPv4Address] dst_ip_address: The destination IP address to match. If combined with + `dst_wildcard_mask`, it specifies the start of an IP range. + :ivar Optional[IPv4Address] dst_wildcard_mask: The wildcard mask for the destination IP address, defining the + range of addresses to match. + :ivar Optional[Port] src_port: The source port number to match. Relevant for TCP/UDP protocols. + :ivar Optional[Port] dst_port: The destination port number to match. Relevant for TCP/UDP protocols. """ action: ACLAction = ACLAction.DENY protocol: Optional[IPProtocol] = None - src_ip_address: Optional[IPv4Address] = None + src_ip_address: Optional[IPV4Address] = None + src_wildcard_mask: Optional[IPV4Address] = None + dst_ip_address: Optional[IPV4Address] = None + dst_wildcard_mask: Optional[IPV4Address] = None src_port: Optional[Port] = None - dst_ip_address: Optional[IPv4Address] = None dst_port: Optional[Port] = None + hit_count: int = 0 def __str__(self) -> str: rule_strings = [] @@ -76,24 +154,132 @@ class ACLRule(SimComponent): state["src_port"] = self.src_port.name if self.src_port else None state["dst_ip_address"] = str(self.dst_ip_address) if self.dst_ip_address else None state["dst_port"] = self.dst_port.name if self.dst_port else None + state["hit_count"] = self.hit_count return state + def permit_frame_check(self, frame: Frame) -> bool: + """ + Evaluates whether a given network frame should be permitted or denied based on this ACL rule. + + This method checks the frame against the ACL rule's criteria, including protocol, source and destination IP + addresses (with support for wildcard masking), and source and destination ports. The method assumes that an + unspecified (None) criterion implies a match for any value in that category. For IP addresses, wildcard masking + can be used to specify ranges of addresses that match the rule. + + The method follows these steps to determine if a frame is permitted: + + 1. Check if the frame's protocol matches the ACL rule's protocol. + 2. For source and destination IP addresses: + 1. If a wildcard mask is defined, check if the frame's IP address is within the range specified by the base + IP address and the wildcard mask. + 2. If no wildcard mask is defined, directly compare the frame's IP address to the one specified in the rule. + 3. Check if the frame's source and destination ports match those specified in the rule. + 4. The frame is permitted if it matches all specified criteria and the rule's action is PERMIT. Conversely, it + is not permitted if any criterion does not match or if the rule's action is DENY. + + :param frame (Frame): The network frame to be evaluated. + :return: True if the frame is permitted by this ACL rule, False otherwise. + """ + protocol_matches = self.protocol == frame.ip.protocol if self.protocol else True + + src_ip_matches = self.src_ip_address is None # Assume match if no specific src IP is defined + if self.src_ip_address: + if self.src_wildcard_mask: + # If a src wildcard mask is provided, use it to check the range + src_ip_matches = ip_matches_masked_range( + ip_to_check=frame.ip.src_ip_address, + base_ip=self.src_ip_address, + wildcard_mask=self.src_wildcard_mask, + ) + else: + # Direct comparison if no wildcard mask is defined + src_ip_matches = frame.ip.src_ip_address == self.src_ip_address + + dst_ip_matches = self.dst_ip_address is None # Assume match if no specific dst IP is defined + if self.dst_ip_address: + if self.dst_wildcard_mask: + # If a dst wildcard mask is provided, use it to check the range + dst_ip_matches = ip_matches_masked_range( + ip_to_check=frame.ip.dst_ip_address, + base_ip=self.dst_ip_address, + wildcard_mask=self.dst_wildcard_mask, + ) + else: + # Direct comparison if no wildcard mask is defined + dst_ip_matches = frame.ip.dst_ip_address == self.dst_ip_address + + src_port = None + dst_port = None + if frame.tcp: + src_port = frame.tcp.src_port + dst_port = frame.tcp.dst_port + elif frame.udp: + src_port = frame.udp.src_port + dst_port = frame.udp.dst_port + + src_port_matches = self.src_port == src_port if self.src_port else True + dst_port_matches = self.dst_port == dst_port if self.dst_port else True + + # The frame is permitted if all conditions are met + if protocol_matches and src_ip_matches and dst_ip_matches and src_port_matches and dst_port_matches: + return self.action == ACLAction.PERMIT + else: + # If any condition is not met, the decision depends on the rule action + return False + class AccessControlList(SimComponent): """ Manages a list of ACLRules to filter network traffic. - :ivar SysLog sys_log: System logging instance. - :ivar ACLAction implicit_action: Default action for rules. - :ivar ACLRule implicit_rule: Implicit ACL rule, created based on implicit_action. - :ivar int max_acl_rules: Maximum number of ACL rules that can be added. Default is 25. - :ivar List[Optional[ACLRule]] _acl: A list containing the ACL rules. + Manages a list of ACLRule instances to filter network traffic based on predefined criteria. This class + provides functionalities to add, remove, and evaluate ACL rules, thereby controlling the flow of traffic + through a network device. + + ACL rules can specify conditions based on source and destination IP addresses, IP protocols (TCP, UDP, ICMP), + and port numbers. Rules can be configured to permit or deny traffic that matches these conditions, offering + granular control over network security policies. + + Usage: + - **Dedicated IP Addresses**: Directly specify the source and/or destination IP addresses in an ACL rule to + match traffic to or from specific hosts. + - **IP Ranges with Wildcard Masks**: Use wildcard masks along with base IP addresses to define ranges of IP + addresses that an ACL rule applies to. This is useful for specifying subnets or ranges of IP addresses. + - **Allowing All IP Traffic**: To mimic a Cisco-style ACL rule that allows all IP traffic from a specified + range, use the wildcard mask in conjunction with a permit action. If your system supports an `ALL` option + for the IP protocol, this can be used to allow all types of IP traffic; otherwise, the absence of a + specified protocol can be interpreted to mean all protocols. + + Methods include functionalities to add and remove rules, reset to default configurations, and evaluate + whether specific frames are permitted or denied based on the current set of rules. The class also provides + utility functions to describe the current state and display the rules in a human-readable format. + + Example: + >>> # To add a rule that permits all TCP traffic from the subnet 192.168.1.0/24 to 192.168.2.0/24: + >>> acl = AccessControlList() + >>> acl.add_rule( + ... action=ACLAction.PERMIT, + ... protocol=IPProtocol.TCP, + ... src_ip_address="192.168.1.0", + ... src_wildcard_mask="0.0.0.255", + ... dst_ip_address="192.168.2.0", + ... dst_wildcard_mask="0.0.0.255" + ...) + + This example demonstrates adding a rule with specific source and destination IP ranges, using wildcard masks + to allow a broad range of traffic while maintaining control over the flow of data for security and + management purposes. + + :ivar ACLAction implicit_action: The default action (permit or deny) applied when no other rule matches. + Typically set to deny to follow the principle of least privilege. + :ivar int max_acl_rules: The maximum number of ACL rules that can be added to the list. Defaults to 25. """ sys_log: SysLog implicit_action: ACLAction implicit_rule: ACLRule max_acl_rules: int = 25 + name: str _acl: List[Optional[ACLRule]] = [None] * 24 _default_config: Dict[int, dict] = {} """Config dict describing how the ACL list should look at episode start""" @@ -210,13 +396,16 @@ class AccessControlList(SimComponent): """ return len([rule for rule in self._acl if rule is not None]) + @validate_call() def add_rule( self, - action: ACLAction, + action: ACLAction = ACLAction.DENY, protocol: Optional[IPProtocol] = None, - src_ip_address: Optional[Union[str, IPv4Address]] = None, + src_ip_address: Optional[IPV4Address] = None, + src_wildcard_mask: Optional[IPV4Address] = None, + dst_ip_address: Optional[IPV4Address] = None, + dst_wildcard_mask: Optional[IPV4Address] = None, src_port: Optional[Port] = None, - dst_ip_address: Optional[Union[str, IPv4Address]] = None, dst_port: Optional[Port] = None, position: int = 0, ) -> None: @@ -224,25 +413,25 @@ class AccessControlList(SimComponent): Add a new ACL rule. :param ACLAction action: Action to be performed (Permit/Deny). - :param Optional[IPProtocol] protocol: Network protocol. - :param Optional[Union[str, IPv4Address]] src_ip_address: Source IP address. - :param Optional[Port] src_port: Source port number. - :param Optional[Union[str, IPv4Address]] dst_ip_address: Destination IP address. - :param Optional[Port] dst_port: Destination port number. - :param int position: Position in the ACL list to insert the rule. + :param protocol: Network protocol. Optional, default is None. + :param src_ip_address: Source IP address. Optional, default is None. + :param src_wildcard_mask: Source IP wildcard mask. Optional, default is None. + :param src_port: Source port number. Optional, default is None. + :param dst_ip_address: Destination IP address. Optional, default is None. + :param dst_wildcard_mask: Destination IP wildcard mask. Optional, default is None. + :param dst_port: Destination port number. Optional, default is None. + :param int position: Position in the ACL list to insert the rule. Optional, default is 1. :raises ValueError: When the position is out of bounds. """ - if isinstance(src_ip_address, str): - src_ip_address = IPv4Address(src_ip_address) - if isinstance(dst_ip_address, str): - dst_ip_address = IPv4Address(dst_ip_address) if 0 <= position < self.max_acl_rules: if self._acl[position]: self.sys_log.info(f"Overwriting ACL rule at position {position}") self._acl[position] = ACLRule( action=action, src_ip_address=src_ip_address, + src_wildcard_mask=src_wildcard_mask, dst_ip_address=dst_ip_address, + dst_wildcard_mask=dst_wildcard_mask, protocol=protocol, src_port=src_port, dst_port=dst_port, @@ -264,43 +453,25 @@ class AccessControlList(SimComponent): else: raise ValueError(f"Cannot remove ACL rule, position {position} is out of bounds.") - def is_permitted( - self, - protocol: IPProtocol, - src_ip_address: Union[str, IPv4Address], - src_port: Optional[Port], - dst_ip_address: Union[str, IPv4Address], - dst_port: Optional[Port], - ) -> Tuple[bool, Optional[Union[str, ACLRule]]]: - """ - Check if a packet with the given properties is permitted through the ACL. - - :param protocol: The protocol of the packet. - :param src_ip_address: Source IP address of the packet. Accepts string and IPv4Address. - :param src_port: Source port of the packet. Optional. - :param dst_ip_address: Destination IP address of the packet. Accepts string and IPv4Address. - :param dst_port: Destination port of the packet. Optional. - :return: A tuple with a boolean indicating if the packet is permitted and an optional rule or implicit action - string. - """ - if not isinstance(src_ip_address, IPv4Address): - src_ip_address = IPv4Address(src_ip_address) - if not isinstance(dst_ip_address, IPv4Address): - dst_ip_address = IPv4Address(dst_ip_address) - for rule in self._acl: - if not rule: + def is_permitted(self, frame: Frame) -> Tuple[bool, ACLRule]: + """Check if a packet with the given properties is permitted through the ACL.""" + permitted = False + rule: ACLRule = None + for _rule in self._acl: + if not _rule: continue - if ( - (rule.src_ip_address == src_ip_address or rule.src_ip_address is None) - and (rule.dst_ip_address == dst_ip_address or rule.dst_ip_address is None) - and (rule.protocol == protocol or rule.protocol is None) - and (rule.src_port == src_port or rule.src_port is None) - and (rule.dst_port == dst_port or rule.dst_port is None) - ): - return rule.action == ACLAction.PERMIT, rule + if _rule.permit_frame_check(frame): + permitted = True + rule = _rule + break + if not rule: + permitted = self.implicit_action == ACLAction.PERMIT + rule = self.implicit_rule - return self.implicit_action == ACLAction.PERMIT, f"Implicit {self.implicit_action.name}" + rule.hit_count += 1 + + return permitted, rule def get_relevant_rules( self, @@ -346,11 +517,25 @@ class AccessControlList(SimComponent): :param markdown: Whether to display the table in Markdown format. Defaults to False. """ - table = PrettyTable(["Index", "Action", "Protocol", "Src IP", "Src Port", "Dst IP", "Dst Port"]) + table = PrettyTable( + [ + "Index", + "Action", + "Protocol", + "Src IP", + "Src Wildcard", + "Src Port", + "Dst IP", + "Dst Wildcard", + "Dst Port", + "Hit Count", + ] + ) if markdown: table.set_style(MARKDOWN) table.align = "l" - table.title = f"{self.sys_log.hostname} Access Control List" + + table.title = f"{self.name} Access Control List" for index, rule in enumerate(self.acl + [self.implicit_rule]): if rule: table.add_row( @@ -359,22 +544,16 @@ class AccessControlList(SimComponent): rule.action.name if rule.action else "ANY", rule.protocol.name if rule.protocol else "ANY", rule.src_ip_address if rule.src_ip_address else "ANY", + rule.src_wildcard_mask if rule.src_wildcard_mask else "ANY", f"{rule.src_port.value} ({rule.src_port.name})" if rule.src_port else "ANY", rule.dst_ip_address if rule.dst_ip_address else "ANY", + rule.dst_wildcard_mask if rule.dst_wildcard_mask else "ANY", f"{rule.dst_port.value} ({rule.dst_port.name})" if rule.dst_port else "ANY", + rule.hit_count, ] ) print(table) - @property - def num_rules(self) -> int: - """ - Get the number of rules in the ACL. - - :return: The number of rules in the ACL. - """ - return len([rule for rule in self._acl if rule is not None]) - class RouteEntry(SimComponent): """ @@ -880,7 +1059,7 @@ class Router(NetworkNode): if not kwargs.get("sys_log"): kwargs["sys_log"] = SysLog(hostname) if not kwargs.get("acl"): - kwargs["acl"] = AccessControlList(sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY) + kwargs["acl"] = AccessControlList(sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY, name=hostname) if not kwargs.get("route_table"): kwargs["route_table"] = RouteTable(sys_log=kwargs["sys_log"]) super().__init__(hostname=hostname, num_ports=num_ports, **kwargs) @@ -1008,6 +1187,36 @@ class Router(NetworkNode): state["acl"] = self.acl.describe_state() return state + def check_send_frame_to_session_manager(self, frame: Frame) -> bool: + """ + Determines whether a given network frame should be forwarded to the session manager. + + his function evaluates whether the destination IP address of the frame corresponds to one of the router's + interface IP addresses. If so, it then checks if the frame is an ICMP packet or if the destination port matches + any of the ports that the router's software manager identifies as open. If either condition is met, the frame + is considered for further processing by the session manager, implying potential application-level handling or + response generation. + + :param frame: The network frame to be evaluated. + + :return: A boolean value indicating whether the frame should be sent to the session manager. ``True`` if the + frame's destination IP matches the router's interface and is directed to an open port or is an ICMP packet, + otherwise, ``False``. + """ + dst_ip_address = frame.ip.dst_ip_address + dst_port = None + if frame.ip.protocol == IPProtocol.TCP: + dst_port = frame.tcp.dst_port + elif frame.ip.protocol == IPProtocol.UDP: + dst_port = frame.udp.dst_port + + if self.ip_is_router_interface(dst_ip_address) and ( + frame.icmp or dst_port in self.software_manager.get_open_ports() + ): + return True + + return False + def receive_frame(self, frame: Frame, from_network_interface: RouterInterface): """ Processes an incoming frame received on one of the router's interfaces. @@ -1021,26 +1230,8 @@ class Router(NetworkNode): if self.operating_state != NodeOperatingState.ON: return - protocol = frame.ip.protocol - src_ip_address = frame.ip.src_ip_address - dst_ip_address = frame.ip.dst_ip_address - src_port = None - dst_port = None - if frame.ip.protocol == IPProtocol.TCP: - src_port = frame.tcp.src_port - dst_port = frame.tcp.dst_port - elif frame.ip.protocol == IPProtocol.UDP: - src_port = frame.udp.src_port - dst_port = frame.udp.dst_port - # Check if it's permitted - permitted, rule = self.acl.is_permitted( - protocol=protocol, - src_ip_address=src_ip_address, - src_port=src_port, - dst_ip_address=dst_ip_address, - dst_port=dst_port, - ) + permitted, rule = self.acl.is_permitted(frame) if not permitted: at_port = self._get_port_of_nic(from_network_interface) @@ -1054,13 +1245,7 @@ class Router(NetworkNode): network_interface=from_network_interface, ) - send_to_session_manager = False - if (frame.icmp and self.ip_is_router_interface(dst_ip_address)) or ( - dst_port in self.software_manager.get_open_ports() - ): - send_to_session_manager = True - - if send_to_session_manager: + if self.check_send_frame_to_session_manager(frame): # Port is open on this Router so pass Frame up to session manager first self.session_manager.receive_frame(frame, from_network_interface) else: @@ -1196,7 +1381,7 @@ class Router(NetworkNode): def show(self, markdown: bool = False): """ - Prints the state of the Ethernet interfaces on the Router. + Prints the state of the network interfaces on the Router. :param markdown: Flag to indicate if the output should be in markdown format. """ @@ -1205,7 +1390,7 @@ class Router(NetworkNode): if markdown: table.set_style(MARKDOWN) table.align = "l" - table.title = f"{self.hostname} Ethernet Interfaces" + table.title = f"{self.hostname} Network Interfaces" for port, network_interface in self.network_interface.items(): table.add_row( [ diff --git a/src/primaite/simulator/network/transmission/network_layer.py b/src/primaite/simulator/network/transmission/network_layer.py index c6328a60..bdf4babc 100644 --- a/src/primaite/simulator/network/transmission/network_layer.py +++ b/src/primaite/simulator/network/transmission/network_layer.py @@ -1,9 +1,9 @@ from enum import Enum -from ipaddress import IPv4Address from pydantic import BaseModel from primaite import getLogger +from primaite.utils.validators import IPV4Address _LOGGER = getLogger(__name__) @@ -73,9 +73,9 @@ class IPPacket(BaseModel): ... ) """ - src_ip_address: IPv4Address + src_ip_address: IPV4Address "Source IP address." - dst_ip_address: IPv4Address + dst_ip_address: IPV4Address "Destination IP address." protocol: IPProtocol = IPProtocol.TCP "IPProtocol." diff --git a/tests/integration_tests/network/test_firewall.py b/tests/integration_tests/network/test_firewall.py new file mode 100644 index 00000000..349ccd85 --- /dev/null +++ b/tests/integration_tests/network/test_firewall.py @@ -0,0 +1,280 @@ +from ipaddress import IPv4Address + +import pytest + +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.network.firewall import Firewall +from primaite.simulator.network.hardware.nodes.network.router import ACLAction +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.services.ntp.ntp_client import NTPClient +from primaite.simulator.system.services.ntp.ntp_server import NTPServer + + +@pytest.fixture(scope="function") +def dmz_external_internal_network() -> Network: + """ + Fixture for setting up a simulated network with a firewall, external node, internal node, and DMZ node. This + configuration is designed to test firewall rules and their impact on traffic between these network segments. + + -------------- -------------- -------------- + | external |---------| firewall |---------| internal | + -------------- -------------- -------------- + | + | + --------- + | DMZ | + --------- + + The network is set up as follows: + - An external node simulates an entity outside the organization's network. + - An internal node represents a device within the organization's LAN. + - A DMZ (Demilitarized Zone) node acts as a server or service exposed to external traffic. + - A firewall node controls traffic between these nodes based on ACL (Access Control List) rules. + + The firewall is configured to allow ICMP and ARP traffic across all interfaces to ensure basic connectivity + for the tests. Specific tests will modify ACL rules to test various traffic filtering scenarios. + + :return: A `Network` instance with the described nodes and configurations. + """ + network = Network() + + firewall_node: Firewall = Firewall(hostname="firewall_1", start_up_duration=0) + firewall_node.power_on() + # configure firewall ports + firewall_node.configure_external_port( + ip_address=IPv4Address("192.168.10.1"), subnet_mask=IPv4Address("255.255.255.0") + ) + firewall_node.configure_dmz_port(ip_address=IPv4Address("192.168.1.1"), subnet_mask=IPv4Address("255.255.255.0")) + firewall_node.configure_internal_port( + ip_address=IPv4Address("192.168.0.1"), subnet_mask=IPv4Address("255.255.255.0") + ) + + # Allow ICMP + firewall_node.internal_inbound_acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + firewall_node.internal_outbound_acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + firewall_node.external_inbound_acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + firewall_node.external_outbound_acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + firewall_node.dmz_inbound_acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + firewall_node.dmz_outbound_acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + + # Allow ARP + firewall_node.internal_inbound_acl.add_rule( + action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22 + ) + firewall_node.internal_outbound_acl.add_rule( + action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22 + ) + firewall_node.external_inbound_acl.add_rule( + action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22 + ) + firewall_node.external_outbound_acl.add_rule( + action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22 + ) + firewall_node.dmz_inbound_acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) + firewall_node.dmz_outbound_acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) + + # external node + external_node = Computer( + hostname="external_node", + ip_address="192.168.10.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.10.1", + start_up_duration=0, + ) + external_node.power_on() + external_node.software_manager.install(NTPServer) + ntp_service: NTPServer = external_node.software_manager.software["NTPServer"] + ntp_service.start() + # connect external node to firewall node + network.connect(endpoint_b=external_node.network_interface[1], endpoint_a=firewall_node.external_port) + + # internal node + internal_node = Computer( + hostname="internal_node", + ip_address="192.168.0.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.0.1", + start_up_duration=0, + ) + internal_node.power_on() + internal_node.software_manager.install(NTPClient) + internal_ntp_client: NTPClient = internal_node.software_manager.software["NTPClient"] + internal_ntp_client.configure(external_node.network_interface[1].ip_address) + internal_ntp_client.start() + # connect external node to firewall node + network.connect(endpoint_b=internal_node.network_interface[1], endpoint_a=firewall_node.internal_port) + + # dmz node + dmz_node = Computer( + hostname="dmz_node", + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + dmz_node.power_on() + dmz_ntp_client: NTPClient = dmz_node.software_manager.software["NTPClient"] + dmz_ntp_client.configure(external_node.network_interface[1].ip_address) + dmz_ntp_client.start() + # connect external node to firewall node + network.connect(endpoint_b=dmz_node.network_interface[1], endpoint_a=firewall_node.dmz_port) + + return network + + +def test_firewall_can_ping_nodes(dmz_external_internal_network): + """ + Tests the firewall's ability to ping the external, internal, and DMZ nodes in the network. + + Verifies that the firewall has connectivity to all nodes within the network by performing a ping operation. + Successful pings indicate proper network setup and basic ICMP traffic passage through the firewall. + """ + firewall = dmz_external_internal_network.get_node_by_hostname("firewall_1") + + # ping from the firewall + assert firewall.ping("192.168.0.2") # firewall to internal + assert firewall.ping("192.168.1.2") # firewall to dmz + assert firewall.ping("192.168.10.2") # firewall to external + + +def test_nodes_can_ping_default_gateway(dmz_external_internal_network): + """ + Checks if the external, internal, and DMZ nodes can ping their respective default gateways. + + This test confirms that each node is correctly configured with a route to its default gateway and that the + firewall permits ICMP traffic for these basic connectivity checks. + """ + external_node = dmz_external_internal_network.get_node_by_hostname("external_node") + internal_node = dmz_external_internal_network.get_node_by_hostname("internal_node") + dmz_node = dmz_external_internal_network.get_node_by_hostname("dmz_node") + + assert internal_node.ping(internal_node.default_gateway) # default gateway internal + assert dmz_node.ping(dmz_node.default_gateway) # default gateway dmz + assert external_node.ping(external_node.default_gateway) # default gateway external + + +def test_nodes_can_ping_default_gateway_on_another_subnet(dmz_external_internal_network): + """ + Verifies that nodes can ping default gateways located in a different subnet, facilitated by the firewall. + + This test assesses the routing and firewall ACL configurations that allow ICMP traffic between different + network segments, ensuring that nodes can reach default gateways outside their local subnet. + """ + external_node = dmz_external_internal_network.get_node_by_hostname("external_node") + internal_node = dmz_external_internal_network.get_node_by_hostname("internal_node") + dmz_node = dmz_external_internal_network.get_node_by_hostname("dmz_node") + + assert internal_node.ping(external_node.default_gateway) # internal node to external default gateway + assert internal_node.ping(dmz_node.default_gateway) # internal node to dmz default gateway + + assert dmz_node.ping(internal_node.default_gateway) # dmz node to internal default gateway + assert dmz_node.ping(external_node.default_gateway) # dmz node to external default gateway + + assert external_node.ping(external_node.default_gateway) # external node to internal default gateway + assert external_node.ping(dmz_node.default_gateway) # external node to dmz default gateway + + +def test_nodes_can_ping_each_other(dmz_external_internal_network): + """ + Evaluates the ability of each node (external, internal, DMZ) to ping the other nodes within the network. + + This comprehensive connectivity test checks if the firewall's current ACL configuration allows for inter-node + communication via ICMP pings, highlighting the effectiveness of the firewall rules in place. + """ + external_node = dmz_external_internal_network.get_node_by_hostname("external_node") + internal_node = dmz_external_internal_network.get_node_by_hostname("internal_node") + dmz_node = dmz_external_internal_network.get_node_by_hostname("dmz_node") + + # test that nodes can ping each other + assert internal_node.ping(external_node.network_interface[1].ip_address) + assert internal_node.ping(dmz_node.network_interface[1].ip_address) + + assert external_node.ping(internal_node.network_interface[1].ip_address) + assert external_node.ping(dmz_node.network_interface[1].ip_address) + + assert dmz_node.ping(internal_node.network_interface[1].ip_address) + assert dmz_node.ping(external_node.network_interface[1].ip_address) + + +def test_service_blocked(dmz_external_internal_network): + """ + Tests the firewall's default blocking stance on NTP service requests from internal and DMZ nodes. + + Initially, without specific ACL rules to allow NTP traffic, this test confirms that NTP clients on both the + internal and DMZ nodes are unable to update their time, demonstrating the firewall's effective blocking of + unspecified services. + """ + firewall = dmz_external_internal_network.get_node_by_hostname("firewall_1") + internal_node = dmz_external_internal_network.get_node_by_hostname("internal_node") + dmz_node = dmz_external_internal_network.get_node_by_hostname("dmz_node") + internal_ntp_client: NTPClient = internal_node.software_manager.software["NTPClient"] + dmz_ntp_client: NTPClient = dmz_node.software_manager.software["NTPClient"] + + assert not internal_ntp_client.time + + internal_ntp_client.request_time() + + assert not internal_ntp_client.time + + assert not dmz_ntp_client.time + + dmz_ntp_client.request_time() + + assert not dmz_ntp_client.time + + firewall.show_rules() + + +def test_service_allowed_with_rule(dmz_external_internal_network): + """ + Tests that NTP service requests are allowed through the firewall based on ACL rules. + + This test verifies the functionality of the firewall in a network scenario where both an internal node and + a node in the DMZ attempt to access NTP services. Initially, no NTP traffic is allowed. The test then + configures ACL rules on the firewall to permit NTP traffic and checks if the NTP clients on the internal + node and DMZ node can successfully request and receive time updates. + + Procedure: + 1. Assert that the internal node's NTP client initially has no time information due to ACL restrictions. + 2. Add ACL rules to the firewall to permit outbound and inbound NTP traffic from the internal network. + 3. Trigger an NTP time request from the internal node and assert that it successfully receives time + information. + 4. Assert that the DMZ node's NTP client initially has no time information. + 5. Add ACL rules to the firewall to permit outbound and inbound NTP traffic from the DMZ. + 6. Trigger an NTP time request from the DMZ node and assert that it successfully receives time information. + + Asserts: + - The internal node's NTP client has no time information before ACL rules are applied. + - The internal node's NTP client successfully receives time information after the appropriate ACL rules + are applied. + - The DMZ node's NTP client has no time information before ACL rules are applied for the DMZ. + - The DMZ node's NTP client successfully receives time information after the appropriate ACL rules for + the DMZ are applied. + """ + firewall = dmz_external_internal_network.get_node_by_hostname("firewall_1") + internal_node = dmz_external_internal_network.get_node_by_hostname("internal_node") + dmz_node = dmz_external_internal_network.get_node_by_hostname("dmz_node") + internal_ntp_client: NTPClient = internal_node.software_manager.software["NTPClient"] + dmz_ntp_client: NTPClient = dmz_node.software_manager.software["NTPClient"] + + assert not internal_ntp_client.time + + firewall.internal_outbound_acl.add_rule(action=ACLAction.PERMIT, src_port=Port.NTP, dst_port=Port.NTP, position=1) + firewall.internal_inbound_acl.add_rule(action=ACLAction.PERMIT, src_port=Port.NTP, dst_port=Port.NTP, position=1) + + internal_ntp_client.request_time() + + assert internal_ntp_client.time + + assert not dmz_ntp_client.time + + firewall.dmz_outbound_acl.add_rule(action=ACLAction.PERMIT, src_port=Port.NTP, dst_port=Port.NTP, position=1) + firewall.dmz_inbound_acl.add_rule(action=ACLAction.PERMIT, src_port=Port.NTP, dst_port=Port.NTP, position=1) + + dmz_ntp_client.request_time() + + assert dmz_ntp_client.time + + firewall.show_rules() diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py index 428f370c..8b1aa9be 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_acl.py @@ -1,111 +1,293 @@ from ipaddress import IPv4Address +import pytest + +from primaite.simulator.network.hardware.base import generate_mac_address from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router -from primaite.simulator.network.transmission.network_layer import IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.network.protocols.icmp import ICMPPacket +from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame +from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader, UDPHeader -def test_add_rule(): +@pytest.fixture(scope="function") +def router_with_acl_rules(): + """ + Provides a router instance with predefined ACL rules for testing. + + :Setup: + 1. Creates a Router object named "Router". + 2. Adds a PERMIT rule for TCP traffic from 192.168.1.1:HTTPS to 192.168.1.2:HTTP. + 3. Adds a DENY rule for TCP traffic from 192.168.1.3:8080 to 192.168.1.4:80. + + :return: A configured Router object with ACL rules. + """ router = Router("Router") acl = router.acl + # Add rules here as needed acl.add_rule( action=ACLAction.PERMIT, protocol=IPProtocol.TCP, - src_ip_address=IPv4Address("192.168.1.1"), + src_ip_address="192.168.1.1", + src_port=Port.HTTPS, + dst_ip_address="192.168.1.2", + dst_port=Port.HTTP, + position=1, + ) + acl.add_rule( + action=ACLAction.DENY, + protocol=IPProtocol.TCP, + src_ip_address="192.168.1.3", src_port=Port(8080), - dst_ip_address=IPv4Address("192.168.1.2"), + dst_ip_address="192.168.1.4", + dst_port=Port(80), + position=2, + ) + return router + + +@pytest.fixture(scope="function") +def router_with_wildcard_acl(): + """ + Provides a router instance with ACL rules that include wildcard masking for testing. + + :Setup: + 1. Creates a Router object named "Router". + 2. Adds a PERMIT rule for TCP traffic from 192.168.1.1:8080 to 10.1.1.2:80. + 3. Adds a DENY rule with a wildcard mask for TCP traffic from the 192.168.1.0/24 network to 10.1.1.3:443. + 4. Adds a PERMIT rule for any traffic to the 10.2.0.0/16 network. + + :return: A Router object with configured ACL rules, including rules with wildcard masking. + """ + router = Router("Router") + acl = router.acl + # Rule to permit traffic from a specific source IP and port to a specific destination IP and port + acl.add_rule( + action=ACLAction.PERMIT, + protocol=IPProtocol.TCP, + src_ip_address="192.168.1.1", + src_port=Port(8080), + dst_ip_address="10.1.1.2", dst_port=Port(80), position=1, ) + # Rule to deny traffic from an IP range to a specific destination IP and port + acl.add_rule( + action=ACLAction.DENY, + protocol=IPProtocol.TCP, + src_ip_address="192.168.1.0", + src_wildcard_mask="0.0.0.255", + dst_ip_address="10.1.1.3", + dst_port=Port(443), + position=2, + ) + # Rule to permit any traffic to a range of destination IPs + acl.add_rule( + action=ACLAction.PERMIT, + protocol=None, + src_ip_address=None, + dst_ip_address="10.2.0.0", + dst_wildcard_mask="0.0.255.255", + position=3, + ) + return router + + +def test_add_rule(router_with_acl_rules): + """ + Tests that an ACL rule is added correctly to the router's ACL. + + Asserts: + - The action of the added rule is PERMIT. + - The protocol of the added rule is TCP. + - The source IP address matches "192.168.1.1". + - The source port is HTTPS. + - The destination IP address matches "192.168.1.2". + - The destination port is HTTP. + """ + acl = router_with_acl_rules.acl + assert acl.acl[1].action == ACLAction.PERMIT assert acl.acl[1].protocol == IPProtocol.TCP assert acl.acl[1].src_ip_address == IPv4Address("192.168.1.1") - assert acl.acl[1].src_port == Port(8080) + assert acl.acl[1].src_port == Port.HTTPS assert acl.acl[1].dst_ip_address == IPv4Address("192.168.1.2") - assert acl.acl[1].dst_port == Port(80) + assert acl.acl[1].dst_port == Port.HTTP -def test_remove_rule(): - router = Router("Router") - acl = router.acl - acl.add_rule( - action=ACLAction.PERMIT, - protocol=IPProtocol.TCP, - src_ip_address=IPv4Address("192.168.1.1"), - src_port=Port(8080), - dst_ip_address=IPv4Address("192.168.1.2"), - dst_port=Port(80), - position=1, - ) +def test_remove_rule(router_with_acl_rules): + """ + Tests the removal of an ACL rule from the router's ACL. + + Asserts that accessing the removed rule index in the ACL returns None. + """ + acl = router_with_acl_rules.acl acl.remove_rule(1) - assert not acl.acl[1] + assert acl.acl[1] is None -def test_rules(): - router = Router("Router") - acl = router.acl - acl.add_rule( - action=ACLAction.PERMIT, - protocol=IPProtocol.TCP, - src_ip_address=IPv4Address("192.168.1.1"), - src_port=Port(8080), - dst_ip_address=IPv4Address("192.168.1.2"), - dst_port=Port(80), - position=1, - ) - acl.add_rule( - action=ACLAction.DENY, - protocol=IPProtocol.TCP, - src_ip_address=IPv4Address("192.168.1.3"), - src_port=Port(8080), - dst_ip_address=IPv4Address("192.168.1.4"), - dst_port=Port(80), - position=2, - ) - is_permitted, rule = acl.is_permitted( - protocol=IPProtocol.TCP, - src_ip_address=IPv4Address("192.168.1.1"), - src_port=Port(8080), - dst_ip_address=IPv4Address("192.168.1.2"), - dst_port=Port(80), +def test_traffic_permitted_by_specific_rule(router_with_acl_rules): + """ + Verifies that traffic matching a specific ACL rule is correctly permitted. + + Asserts traffic that matches a permit rule is allowed through the ACL. + """ + acl = router_with_acl_rules.acl + permitted_frame = Frame( + ethernet=EthernetHeader(src_mac_addr=generate_mac_address(), dst_mac_addr=generate_mac_address()), + ip=IPPacket(src_ip_address="192.168.1.1", dst_ip_address="192.168.1.2", protocol=IPProtocol.TCP), + tcp=TCPHeader(src_port=Port.HTTPS, dst_port=Port.HTTP), ) + is_permitted, _ = acl.is_permitted(permitted_frame) assert is_permitted - is_permitted, rule = acl.is_permitted( - protocol=IPProtocol.TCP, - src_ip_address=IPv4Address("192.168.1.3"), - src_port=Port(8080), - dst_ip_address=IPv4Address("192.168.1.4"), - dst_port=Port(80), + + +def test_traffic_denied_by_specific_rule(router_with_acl_rules): + """ + Verifies that traffic matching a specific ACL rule is correctly denied. + + Asserts traffic that matches a deny rule is blocked by the ACL. + """ + + acl = router_with_acl_rules.acl + not_permitted_frame = Frame( + ethernet=EthernetHeader(src_mac_addr=generate_mac_address(), dst_mac_addr=generate_mac_address()), + ip=IPPacket(src_ip_address="192.168.1.3", dst_ip_address="192.168.1.4", protocol=IPProtocol.TCP), + tcp=TCPHeader(src_port=Port(8080), dst_port=Port(80)), ) + is_permitted, _ = acl.is_permitted(not_permitted_frame) assert not is_permitted -def test_default_rule(): +def test_default_rule(router_with_acl_rules): + """ + Tests the default deny rule of the ACL. + + This test verifies that traffic which does not match any explicit permit rule in the ACL + is correctly denied, as per the common "default deny" security stance that ACLs implement. + + Asserts the frame does not match any of the predefined ACL rules and is therefore not permitted by the ACL, + illustrating the default deny behavior when no explicit permit rule is matched. + """ + acl = router_with_acl_rules.acl + not_permitted_frame = Frame( + ethernet=EthernetHeader(src_mac_addr=generate_mac_address(), dst_mac_addr=generate_mac_address()), + ip=IPPacket(src_ip_address="192.168.1.5", dst_ip_address="192.168.1.12", protocol=IPProtocol.UDP), + udp=UDPHeader(src_port=Port.HTTPS, dst_port=Port.HTTP), + ) + is_permitted, rule = acl.is_permitted(not_permitted_frame) + assert not is_permitted + + +def test_direct_ip_match_with_acl(router_with_wildcard_acl): + """ + Tests ACL functionality for a direct IP address match. + + Asserts direct IP address match traffic is permitted by the ACL rule. + """ + acl = router_with_wildcard_acl.acl + frame = Frame( + ethernet=EthernetHeader(src_mac_addr=generate_mac_address(), dst_mac_addr=generate_mac_address()), + ip=IPPacket(src_ip_address="192.168.1.1", dst_ip_address="10.1.1.2", protocol=IPProtocol.TCP), + tcp=TCPHeader(src_port=Port(8080), dst_port=Port(80)), + ) + assert acl.is_permitted(frame)[0], "Direct IP match should be permitted." + + +def test_ip_range_match_denied_with_acl(router_with_wildcard_acl): + """ + Tests ACL functionality for denying traffic from an IP range using wildcard masking. + + Asserts traffic from the specified IP range is correctly denied by the ACL rule. + """ + acl = router_with_wildcard_acl.acl + frame = Frame( + ethernet=EthernetHeader(src_mac_addr=generate_mac_address(), dst_mac_addr=generate_mac_address()), + ip=IPPacket(src_ip_address="192.168.1.100", dst_ip_address="10.1.1.3", protocol=IPProtocol.TCP), + tcp=TCPHeader(src_port=Port(8080), dst_port=Port(443)), + ) + assert not acl.is_permitted(frame)[0], "IP range match with wildcard mask should be denied." + + +def test_traffic_permitted_to_destination_range_with_acl(router_with_wildcard_acl): + """ + Tests ACL functionality for permitting traffic to a destination IP range using wildcard masking. + + Asserts traffic to the specified destination IP range is correctly permitted by the ACL rule. + """ + acl = router_with_wildcard_acl.acl + frame = Frame( + ethernet=EthernetHeader(src_mac_addr=generate_mac_address(), dst_mac_addr=generate_mac_address()), + ip=IPPacket(src_ip_address="192.168.1.50", dst_ip_address="10.2.200.200", protocol=IPProtocol.UDP), + udp=UDPHeader(src_port=Port(1433), dst_port=Port(1433)), + ) + assert acl.is_permitted(frame)[0], "Traffic to destination IP range should be permitted." + + +def test_ip_traffic_from_specific_subnet(): + """ + Tests that the ACL permits or denies IP traffic from specific subnets, mimicking a Cisco ACL rule for IP traffic. + + This test verifies the ACL's ability to permit all IP traffic from a specific subnet (192.168.1.0/24) while denying + traffic from other subnets. The test mimics a Cisco ACL rule that allows IP traffic from a specified range using + wildcard masking. + + The test frames are constructed with varying protocols (TCP, UDP, ICMP) and source IP addresses, to demonstrate the + rule's general applicability to all IP protocols and its enforcement based on source IP address range. + + Asserts + - Traffic from within the 192.168.1.0/24 subnet is permitted. + - Traffic from outside the 192.168.1.0/24 subnet is denied. + """ + router = Router("Router") acl = router.acl + # Add rules here as needed acl.add_rule( action=ACLAction.PERMIT, - protocol=IPProtocol.TCP, - src_ip_address=IPv4Address("192.168.1.1"), - src_port=Port(8080), - dst_ip_address=IPv4Address("192.168.1.2"), - dst_port=Port(80), + src_ip_address="192.168.1.0", + src_wildcard_mask="0.0.0.255", position=1, ) - acl.add_rule( - action=ACLAction.DENY, - protocol=IPProtocol.TCP, - src_ip_address=IPv4Address("192.168.1.3"), - src_port=Port(8080), - dst_ip_address=IPv4Address("192.168.1.4"), - dst_port=Port(80), - position=2, + + permitted_frame_1 = Frame( + ethernet=EthernetHeader(src_mac_addr=generate_mac_address(), dst_mac_addr=generate_mac_address()), + ip=IPPacket(src_ip_address="192.168.1.50", dst_ip_address="10.2.200.200", protocol=IPProtocol.TCP), + tcp=TCPHeader(src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER), ) - is_permitted, rule = acl.is_permitted( - protocol=IPProtocol.UDP, - src_ip_address=IPv4Address("192.168.1.5"), - src_port=Port(8080), - dst_ip_address=IPv4Address("192.168.1.12"), - dst_port=Port(80), + + assert acl.is_permitted(permitted_frame_1)[0] + + permitted_frame_2 = Frame( + ethernet=EthernetHeader(src_mac_addr=generate_mac_address(), dst_mac_addr=generate_mac_address()), + ip=IPPacket(src_ip_address="192.168.1.10", dst_ip_address="85.199.214.101", protocol=IPProtocol.UDP), + udp=UDPHeader(src_port=Port.NTP, dst_port=Port.NTP), ) - assert not is_permitted + + assert acl.is_permitted(permitted_frame_2)[0] + + permitted_frame_3 = Frame( + ethernet=EthernetHeader(src_mac_addr=generate_mac_address(), dst_mac_addr=generate_mac_address()), + ip=IPPacket(src_ip_address="192.168.1.200", dst_ip_address="192.168.1.1", protocol=IPProtocol.ICMP), + icmp=ICMPPacket(identifier=1), + ) + + assert acl.is_permitted(permitted_frame_3)[0] + + not_permitted_frame_1 = Frame( + ethernet=EthernetHeader(src_mac_addr=generate_mac_address(), dst_mac_addr=generate_mac_address()), + ip=IPPacket(src_ip_address="192.168.0.50", dst_ip_address="10.2.200.200", protocol=IPProtocol.TCP), + tcp=TCPHeader(src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER), + ) + + assert not acl.is_permitted(not_permitted_frame_1)[0] + + not_permitted_frame_2 = Frame( + ethernet=EthernetHeader(src_mac_addr=generate_mac_address(), dst_mac_addr=generate_mac_address()), + ip=IPPacket(src_ip_address="192.168.2.10", dst_ip_address="85.199.214.101", protocol=IPProtocol.UDP), + udp=UDPHeader(src_port=Port.NTP, dst_port=Port.NTP), + ) + + assert not acl.is_permitted(not_permitted_frame_2)[0] + + acl.show() From a8c1e2b9d97aaeeaacfc8b49964699cf661844d6 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Sat, 10 Feb 2024 21:32:13 +0000 Subject: [PATCH 587/980] #2205 - Fixed ACLRule.is_permitted function by returning a bool that indicates whether the rule was matched or not to allow the AccessControlList to know whether to pay attention to the rule or not when it's iterating over them. --- .../network/nodes/firewall.rst | 14 +-- .../network/hardware/nodes/network/router.py | 98 +++++++++++++------ 2 files changed, 73 insertions(+), 39 deletions(-) diff --git a/docs/source/simulation_components/network/nodes/firewall.rst b/docs/source/simulation_components/network/nodes/firewall.rst index 39f804c4..73168517 100644 --- a/docs/source/simulation_components/network/nodes/firewall.rst +++ b/docs/source/simulation_components/network/nodes/firewall.rst @@ -356,7 +356,7 @@ This function showcases each rule in an ACL, outlining its: - **Src IP and Dst IP**: Source and destination IP addresses. - **Src Wildcard and Dst** Wildcard: Wildcard masks for source and destination IP ranges. - **Src Port and Dst Port**: Source and destination ports. -- **Hit Count**: The number of times the rule has been matched by traffic. +- **Matched**: The number of times the rule has been matched by traffic. Example Output: @@ -365,7 +365,7 @@ Example Output: +---------------------------------------------------------------------------------------------------------------+ | firewall_1 - External Inbound Access Control List | +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ - | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Hit Count | + | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Matched | +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ | 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 1 | | 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 0 | @@ -375,7 +375,7 @@ Example Output: +---------------------------------------------------------------------------------------------------------------+ | firewall_1 - External Outbound Access Control List | +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ - | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Hit Count | + | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Matched | +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ | 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 0 | | 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 0 | @@ -385,7 +385,7 @@ Example Output: +---------------------------------------------------------------------------------------------------------------+ | firewall_1 - Internal Inbound Access Control List | +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ - | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Hit Count | + | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Matched | +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ | 1 | PERMIT | ANY | ANY | ANY | 123 (NTP) | ANY | ANY | 123 (NTP) | 1 | | 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 0 | @@ -396,7 +396,7 @@ Example Output: +---------------------------------------------------------------------------------------------------------------+ | firewall_1 - Internal Outbound Access Control List | +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ - | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Hit Count | + | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Matched | +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ | 1 | PERMIT | ANY | ANY | ANY | 123 (NTP) | ANY | ANY | 123 (NTP) | 1 | | 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 1 | @@ -407,7 +407,7 @@ Example Output: +---------------------------------------------------------------------------------------------------------------+ | firewall_1 - DMZ Inbound Access Control List | +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ - | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Hit Count | + | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Matched | +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ | 1 | PERMIT | ANY | ANY | ANY | 123 (NTP) | ANY | ANY | 123 (NTP) | 1 | | 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 0 | @@ -418,7 +418,7 @@ Example Output: +---------------------------------------------------------------------------------------------------------------+ | firewall_1 - DMZ Outbound Access Control List | +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ - | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Hit Count | + | Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Matched | +-------+--------+----------+--------+--------------+-----------+--------+--------------+-----------+-----------+ | 1 | PERMIT | ANY | ANY | ANY | 123 (NTP) | ANY | ANY | 123 (NTP) | 1 | | 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 1 | diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 0ad64d18..0d5b3d76 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -123,7 +123,7 @@ class ACLRule(SimComponent): dst_wildcard_mask: Optional[IPV4Address] = None src_port: Optional[Port] = None dst_port: Optional[Port] = None - hit_count: int = 0 + match_count: int = 0 def __str__(self) -> str: rule_strings = [] @@ -154,10 +154,10 @@ class ACLRule(SimComponent): state["src_port"] = self.src_port.name if self.src_port else None state["dst_ip_address"] = str(self.dst_ip_address) if self.dst_ip_address else None state["dst_port"] = self.dst_port.name if self.dst_port else None - state["hit_count"] = self.hit_count + state["match_count"] = self.match_count return state - def permit_frame_check(self, frame: Frame) -> bool: + def permit_frame_check(self, frame: Frame) -> Tuple[bool, bool]: """ Evaluates whether a given network frame should be permitted or denied based on this ACL rule. @@ -177,9 +177,13 @@ class ACLRule(SimComponent): 4. The frame is permitted if it matches all specified criteria and the rule's action is PERMIT. Conversely, it is not permitted if any criterion does not match or if the rule's action is DENY. - :param frame (Frame): The network frame to be evaluated. - :return: True if the frame is permitted by this ACL rule, False otherwise. + :param frame: The network frame to be evaluated. + :return: A tuple containing two boolean values: The first indicates if the frame is permitted by this rule ( + True if permitted, otherwise False). The second indicates if the frame matches the rule's criteria (True + if it matches, otherwise False). """ + permitted = False + frame_matches_rule = False protocol_matches = self.protocol == frame.ip.protocol if self.protocol else True src_ip_matches = self.src_ip_address is None # Assume match if no specific src IP is defined @@ -222,10 +226,10 @@ class ACLRule(SimComponent): # The frame is permitted if all conditions are met if protocol_matches and src_ip_matches and dst_ip_matches and src_port_matches and dst_port_matches: - return self.action == ACLAction.PERMIT - else: - # If any condition is not met, the decision depends on the rule action - return False + frame_matches_rule = True + permitted = self.action == ACLAction.PERMIT + + return permitted, frame_matches_rule class AccessControlList(SimComponent): @@ -336,6 +340,7 @@ class AccessControlList(SimComponent): ) def _init_request_manager(self) -> RequestManager: + # TODO: Add src and dst wildcard masks as positional args in this request. rm = super()._init_request_manager() # When the request reaches this action, it should now contain solely positional args for the 'add_rule' action. @@ -351,13 +356,13 @@ class AccessControlList(SimComponent): "add_rule", RequestType( func=lambda request, context: self.add_rule( - ACLAction[request[0]], - None if request[1] == "ALL" else IPProtocol[request[1]], - None if request[2] == "ALL" else IPv4Address(request[2]), - None if request[3] == "ALL" else Port[request[3]], - None if request[4] == "ALL" else IPv4Address(request[4]), - None if request[5] == "ALL" else Port[request[5]], - int(request[6]), + action=ACLAction[request[0]], + protocol=None if request[1] == "ALL" else IPProtocol[request[1]], + src_ip_address=None if request[2] == "ALL" else IPv4Address(request[2]), + src_port=None if request[3] == "ALL" else Port[request[3]], + dst_ip_address=None if request[4] == "ALL" else IPv4Address(request[4]), + dst_port=None if request[5] == "ALL" else Port[request[5]], + position=int(request[6]), ) ), ) @@ -410,18 +415,47 @@ class AccessControlList(SimComponent): position: int = 0, ) -> None: """ - Add a new ACL rule. + Adds a new ACL rule to control network traffic based on specified criteria. - :param ACLAction action: Action to be performed (Permit/Deny). - :param protocol: Network protocol. Optional, default is None. - :param src_ip_address: Source IP address. Optional, default is None. - :param src_wildcard_mask: Source IP wildcard mask. Optional, default is None. - :param src_port: Source port number. Optional, default is None. - :param dst_ip_address: Destination IP address. Optional, default is None. - :param dst_wildcard_mask: Destination IP wildcard mask. Optional, default is None. - :param dst_port: Destination port number. Optional, default is None. - :param int position: Position in the ACL list to insert the rule. Optional, default is 1. - :raises ValueError: When the position is out of bounds. + This method allows defining rules that specify whether to permit or deny traffic with particular + characteristics, including source and destination IP addresses, ports, and protocols. Wildcard masks can be + used to specify a range of IP addresses, allowing for broader rule application. If specifying a dedicated IP + address without needing a range, the wildcard mask can be omitted. + + Example: + >>> # To block all traffic except SSH from a specific IP range to a server: + >>> router = Router("router") + >>> router.add_rule( + ... action=ACLAction.DENY, + ... protocol=IPProtocol.TCP, + ... src_ip_address="192.168.1.0", + ... src_wildcard_mask="0.0.0.255", + ... dst_ip_address="10.10.10.5", + ... dst_port=Port.SSH, + ... position=5 + ... ) + >>> # This permits SSH traffic from the 192.168.1.0/24 subnet to the 10.10.10.5 server. + >>> + >>> # Then if we want to allow a specific IP address from this subnet to SSH into the server + >>> router.add_rule( + ... action=ACLAction.PERMIT, + ... protocol=IPProtocol.TCP, + ... src_ip_address="192.168.1.25", + ... dst_ip_address="10.10.10.5", + ... dst_port=Port.SSH, + ... position=4 + ... ) + + :param action: The action to take (Permit/Deny) when the rule matches traffic. + :param protocol: The network protocol (TCP/UDP/ICMP) to match. If None, matches any protocol. + :param src_ip_address: The source IP address to match. If None, matches any source IP. + :param src_wildcard_mask: Specifies a wildcard mask for the source IP. Use for IP ranges. + :param dst_ip_address: The destination IP address to match. If None, matches any destination IP. + :param dst_wildcard_mask: Specifies a wildcard mask for the destination IP. Use for IP ranges. + :param src_port: The source port to match. If None, matches any source port. + :param dst_port: The destination port to match. If None, matches any destination port. + :param int position: The position in the ACL list to insert this rule. Defaults is position 0 right at the top. + :raises ValueError: If the position is out of bounds. """ if 0 <= position < self.max_acl_rules: if self._acl[position]: @@ -461,15 +495,15 @@ class AccessControlList(SimComponent): if not _rule: continue - if _rule.permit_frame_check(frame): - permitted = True + permitted, rule_match = _rule.permit_frame_check(frame) + if rule_match: rule = _rule break if not rule: permitted = self.implicit_action == ACLAction.PERMIT rule = self.implicit_rule - rule.hit_count += 1 + rule.match_count += 1 return permitted, rule @@ -528,7 +562,7 @@ class AccessControlList(SimComponent): "Dst IP", "Dst Wildcard", "Dst Port", - "Hit Count", + "Matched", ] ) if markdown: @@ -549,7 +583,7 @@ class AccessControlList(SimComponent): rule.dst_ip_address if rule.dst_ip_address else "ANY", rule.dst_wildcard_mask if rule.dst_wildcard_mask else "ANY", f"{rule.dst_port.value} ({rule.dst_port.name})" if rule.dst_port else "ANY", - rule.hit_count, + rule.match_count, ] ) print(table) From 9df7ceed3deb733a0b6f5a509f7dc76922e4edc7 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Sat, 10 Feb 2024 23:44:08 +0000 Subject: [PATCH 588/980] #2205 - feat: Implement AirSpace and WirelessRouter for Enhanced Network Simulations This commit introduces the AirSpace and WirelessRouter classes, expanding the PrimAITE's capabilities to simulate wireless networking environments. The AirSpace class manages wireless communications, ensuring seamless transmission across different frequencies. Meanwhile, the WirelessRouter class integrates both wired and wireless networking functionalities. --- CHANGELOG.md | 4 + src/primaite/simulator/network/airspace.py | 308 ++++++++++++++++++ .../simulator/network/hardware/base.py | 80 ----- .../hardware/nodes/network/wireless_router.py | 217 ++++++++++++ 4 files changed, 529 insertions(+), 80 deletions(-) create mode 100644 src/primaite/simulator/network/airspace.py create mode 100644 src/primaite/simulator/network/hardware/nodes/network/wireless_router.py diff --git a/CHANGELOG.md b/CHANGELOG.md index a18e4d2f..cc52a197 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,10 @@ SessionManager. - Interface configuration to establish connectivity and define network parameters for external, internal, and DMZ interfaces. - Protocol and service management to oversee traffic and enforce security policies. - Dynamic traffic processing and filtering to ensure network security and integrity. +- `AirSpace` class to simulate wireless communications, managing wireless interfaces and facilitating the transmission of frames within specified frequencies. +- `AirSpaceFrequency` enum for defining standard wireless frequencies, including 2.4 GHz and 5 GHz bands, to support realistic wireless network simulations. +- `WirelessRouter` class, extending the `Router` class, to incorporate wireless networking capabilities alongside traditional wired connections. This class allows the configuration of wireless access points with specific IP settings and operating frequencies. + ### Changed - Integrated the RouteTable into the Routers frame processing. diff --git a/src/primaite/simulator/network/airspace.py b/src/primaite/simulator/network/airspace.py new file mode 100644 index 00000000..56cd1cc7 --- /dev/null +++ b/src/primaite/simulator/network/airspace.py @@ -0,0 +1,308 @@ +from __future__ import annotations + +from abc import ABC, abstractmethod +from enum import Enum +from typing import Any, Dict, Final, List, Optional + +from prettytable import PrettyTable + +from primaite import getLogger +from primaite.simulator.network.hardware.base import Layer3Interface, NetworkInterface, WiredNetworkInterface +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.transmission.data_link_layer import Frame +from primaite.simulator.system.core.packet_capture import PacketCapture + +_LOGGER = getLogger(__name__) + +__all__ = ["AIR_SPACE", "AirSpaceFrequency", "WirelessNetworkInterface", "IPWirelessNetworkInterface"] + + +class AirSpace: + """Represents a wireless airspace, managing wireless network interfaces and handling wireless transmission.""" + + def __init__(self): + self._wireless_interfaces: Dict[str, WirelessNetworkInterface] = {} + self._wireless_interfaces_by_frequency: Dict[AirSpaceFrequency, List[WirelessNetworkInterface]] = {} + + def show(self, frequency: Optional[AirSpaceFrequency] = None): + """ + Displays a summary of wireless interfaces in the airspace, optionally filtered by a specific frequency. + + :param frequency: The frequency band to filter devices by. If None, devices for all frequencies are shown. + """ + table = PrettyTable() + table.field_names = ["Connected Node", "MAC Address", "IP Address", "Subnet Mask", "Frequency", "Status"] + + # If a specific frequency is provided, filter by it; otherwise, use all frequencies. + frequencies_to_show = [frequency] if frequency else self._wireless_interfaces_by_frequency.keys() + + for freq in frequencies_to_show: + interfaces = self._wireless_interfaces_by_frequency.get(freq, []) + for interface in interfaces: + status = "Enabled" if interface.enabled else "Disabled" + table.add_row( + [ + interface._connected_node.hostname, # noqa + interface.mac_address, + interface.ip_address if hasattr(interface, "ip_address") else None, + interface.subnet_mask if hasattr(interface, "subnet_mask") else None, + str(freq), + status, + ] + ) + + print(table) + + def add_wireless_interface(self, wireless_interface: WirelessNetworkInterface): + """ + Adds a wireless network interface to the airspace if it's not already present. + + :param wireless_interface: The wireless network interface to be added. + """ + if wireless_interface.mac_address not in self._wireless_interfaces: + self._wireless_interfaces[wireless_interface.mac_address] = wireless_interface + if wireless_interface.frequency not in self._wireless_interfaces_by_frequency: + self._wireless_interfaces_by_frequency[wireless_interface.frequency] = [] + self._wireless_interfaces_by_frequency[wireless_interface.frequency].append(wireless_interface) + + def remove_wireless_interface(self, wireless_interface: WirelessNetworkInterface): + """ + Removes a wireless network interface from the airspace if it's present. + + :param wireless_interface: The wireless network interface to be removed. + """ + if wireless_interface.mac_address in self._wireless_interfaces: + self._wireless_interfaces.pop(wireless_interface.mac_address) + self._wireless_interfaces_by_frequency[wireless_interface.frequency].remove(wireless_interface) + + def clear(self): + """ + Clears all wireless network interfaces and their frequency associations from the airspace. + + After calling this method, the airspace will contain no wireless network interfaces, and transmissions cannot + occur until new interfaces are added again. + """ + self._wireless_interfaces.clear() + self._wireless_interfaces_by_frequency.clear() + + def transmit(self, frame: Frame, sender_network_interface: WirelessNetworkInterface): + """ + Transmits a frame to all enabled wireless network interfaces on a specific frequency within the airspace. + + This ensures that a wireless interface does not receive its own transmission. + + :param frame: The frame to be transmitted. + :param sender_network_interface: The wireless network interface sending the frame. This interface will be + excluded from the list of receivers to prevent it from receiving its own transmission. + """ + for wireless_interface in self._wireless_interfaces_by_frequency.get(sender_network_interface.frequency, []): + if wireless_interface != sender_network_interface and wireless_interface.enabled: + wireless_interface.receive_frame(frame) + + +AIR_SPACE: Final[AirSpace] = AirSpace() +""" +A singleton instance of the AirSpace class, representing the global wireless airspace. + +This instance acts as the central management point for all wireless communications within the simulated network +environment. By default, there is only one airspace in the simulation, making this variable a singleton that +manages the registration, removal, and transmission of wireless frames across all wireless network interfaces configured +in the simulation. It ensures that wireless frames are appropriately transmitted to and received by wireless +interfaces based on their operational status and frequency band. +""" + + +class AirSpaceFrequency(Enum): + """Enumeration representing the operating frequencies for wireless communications.""" + + WIFI_2_4 = 2.4e9 + """WiFi 2.4 GHz. Known for its extensive range and ability to penetrate solid objects effectively.""" + WIFI_5 = 5e9 + """WiFi 5 GHz. Known for its higher data transmission speeds and reduced interference from other devices.""" + + def __str__(self) -> str: + if self == AirSpaceFrequency.WIFI_2_4: + return "WiFi 2.4 GHz" + elif self == AirSpaceFrequency.WIFI_5: + return "WiFi 5 GHz" + else: + return "Unknown Frequency" + + +class WirelessNetworkInterface(NetworkInterface, ABC): + """ + Represents a wireless network interface in a network device. + + This abstract base class models wireless network interfaces, encapsulating properties and behaviors specific to + wireless connectivity. It provides a framework for managing wireless connections, including signal strength, + security protocols, and other wireless-specific attributes and methods. + + Wireless network interfaces differ from wired ones in their medium of communication, relying on radio frequencies + for data transmission and reception. This class serves as a base for more specific types of wireless network + interfaces, such as Wi-Fi adapters or radio network interfaces, ensuring that essential wireless functionality is + defined and standardised. + + Inherits from: + - NetworkInterface: Provides basic network interface properties and methods. + + As an abstract base class, it requires subclasses to implement specific methods related to wireless communication + and may define additional properties and methods specific to wireless technology. + """ + + frequency: AirSpaceFrequency = AirSpaceFrequency.WIFI_2_4 + + def enable(self): + """Attempt to enable the network interface.""" + if self.enabled: + return + + if not self._connected_node: + _LOGGER.error(f"Interface {self} cannot be enabled as it is not connected to a Node") + return + + if self._connected_node.operating_state != NodeOperatingState.ON: + self._connected_node.sys_log.info( + f"Interface {self} cannot be enabled as the connected Node is not powered on" + ) + return + + self.enabled = True + self._connected_node.sys_log.info(f"Network Interface {self} enabled") + self.pcap = PacketCapture(hostname=self._connected_node.hostname, interface_num=self.port_num) + AIR_SPACE.add_wireless_interface(self) + + def disable(self): + """Disable the network interface.""" + if not self.enabled: + return + self.enabled = False + if self._connected_node: + self._connected_node.sys_log.info(f"Network Interface {self} disabled") + else: + _LOGGER.debug(f"Interface {self} disabled") + AIR_SPACE.remove_wireless_interface(self) + + def send_frame(self, frame: Frame) -> bool: + """ + Attempts to send a network frame over the airspace. + + This method sends a frame if the network interface is enabled and connected to a wireless airspace. It captures + the frame using PCAP (if available) and transmits it through the airspace. Returns True if the frame is + successfully sent, False otherwise (e.g., if the network interface is disabled). + + :param frame: The network frame to be sent. + :return: True if the frame is sent successfully, False if the network interface is disabled. + """ + if self.enabled: + frame.set_sent_timestamp() + self.pcap.capture_outbound(frame) + AIR_SPACE.transmit(frame, self) + return True + # Cannot send Frame as the network interface is not enabled + return False + + @abstractmethod + def receive_frame(self, frame: Frame) -> bool: + """ + Receives a network frame on the network interface. + + :param frame: The network frame being received. + :return: A boolean indicating whether the frame was successfully received. + """ + pass + + +class IPWirelessNetworkInterface(WirelessNetworkInterface, Layer3Interface, ABC): + """ + Represents an IP wireless network interface. + + This interface operates at both the data link layer (Layer 2) and the network layer (Layer 3) of the OSI model, + specifically tailored for IP-based communication over wireless connections. This abstract class provides a + template for creating specific wireless network interfaces that support Internet Protocol (IP) functionalities. + + As this class is a combination of its parent classes without additional attributes or methods, please refer to + the documentation of `WirelessNetworkInterface` and `Layer3Interface` for more details on the supported operations + and functionalities. + + The class inherits from: + - `WirelessNetworkInterface`: Providing the functionalities and characteristics of a wireless connection, such as + managing wireless signal transmission, reception, and associated wireless protocols. + - `Layer3Interface`: Enabling network layer capabilities, including IP address assignment, routing, and + potentially, Layer 3 protocols like IPsec. + + As an abstract class, `IPWirelessNetworkInterface` does not implement specific methods but ensures that any derived + class provides implementations for the functionalities of both `WirelessNetworkInterface` and `Layer3Interface`. + This setup is ideal for representing network interfaces in devices that require wireless connections and are capable + of IP routing and addressing, such as wireless routers, access points, and wireless end-host devices like + smartphones and laptops. + + This class should be extended by concrete classes that define specific behaviors and properties of an IP-capable + wireless network interface. + """ + + def model_post_init(self, __context: Any) -> None: + """ + Performs post-initialisation checks to ensure the model's IP configuration is valid. + + This method is invoked after the initialisation of a network model object to validate its network settings, + particularly to ensure that the assigned IP address is not a network address. This validation is crucial for + maintaining the integrity of network simulations and avoiding configuration errors that could lead to + unrealistic or incorrect behavior. + + :param __context: Contextual information or parameters passed to the method, used for further initializing or + validating the model post-creation. + :raises ValueError: If the IP address is the same as the network address, indicating an incorrect configuration. + """ + if self.ip_network.network_address == self.ip_address: + raise ValueError(f"{self.ip_address}/{self.subnet_mask} must not be a network address") + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + # Get the state from the WiredNetworkInterface + state = WiredNetworkInterface.describe_state(self) + + # Update the state with information from Layer3Interface + state.update(Layer3Interface.describe_state(self)) + + state["frequency"] = self.frequency + + return state + + def set_original_state(self): + """Sets the original state.""" + vals_to_include = {"ip_address", "subnet_mask", "mac_address", "speed", "mtu", "wake_on_lan", "enabled"} + self._original_state = self.model_dump(include=vals_to_include) + + def enable(self): + """ + Enables this wired network interface and attempts to send a "hello" message to the default gateway. + + This method activates the network interface, making it operational for network communications. After enabling, + it tries to initiate a default gateway "hello" process, typically to establish initial connectivity and resolve + the default gateway's MAC address. This step is crucial for ensuring the interface can successfully send data + to and receive data from the network. + + The method safely handles cases where the connected node might not have a default gateway set or the + `default_gateway_hello` method is not defined, ignoring such errors to proceed without interruption. + """ + super().enable() + try: + pass + self._connected_node.default_gateway_hello() + except AttributeError: + pass + + @abstractmethod + def receive_frame(self, frame: Frame) -> bool: + """ + Receives a network frame on the interface. + + :param frame: The network frame being received. + :return: A boolean indicating whether the frame was successfully received. + """ + pass diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 55640121..7354725a 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -420,86 +420,6 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): pass -class WirelessNetworkInterface(NetworkInterface, ABC): - """ - Represents a wireless network interface in a network device. - - This abstract base class models wireless network interfaces, encapsulating properties and behaviors specific to - wireless connectivity. It provides a framework for managing wireless connections, including signal strength, - security protocols, and other wireless-specific attributes and methods. - - Wireless network interfaces differ from wired ones in their medium of communication, relying on radio frequencies - for data transmission and reception. This class serves as a base for more specific types of wireless interfaces, - such as Wi-Fi adapters or radio network interfaces, ensuring that essential wireless functionality is defined - and standardised. - - Inherits from: - - NetworkInterface: Provides basic network interface properties and methods. - - As an abstract base class, it requires subclasses to implement specific methods related to wireless communication - and may define additional properties and methods specific to wireless technology. - """ - - -class IPWirelessNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): - """ - Represents an IP wireless network interface. - - This interface operates at both the data link layer (Layer 2) and the network layer (Layer 3) of the OSI model, - specifically tailored for IP-based communication over wireless connections. This abstract class provides a - template for creating specific wireless network interfaces that support Internet Protocol (IP) functionalities. - - As this class is a combination of its parent classes without additional attributes or methods, please refer to - the documentation of `WirelessNetworkInterface` and `Layer3Interface` for more details on the supported operations - and functionalities. - - The class inherits from: - - `WirelessNetworkInterface`: Providing the functionalities and characteristics of a wireless connection, such as - managing wireless signal transmission, reception, and associated wireless protocols. - - `Layer3Interface`: Enabling network layer capabilities, including IP address assignment, routing, and - potentially, Layer 3 protocols like IPsec. - - As an abstract class, `IPWirelessNetworkInterface` does not implement specific methods but ensures that any derived - class provides implementations for the functionalities of both `WirelessNetworkInterface` and `Layer3Interface`. - This setup is ideal for representing network interfaces in devices that require wireless connections and are capable - of IP routing and addressing, such as wireless routers, access points, and wireless end-host devices like - smartphones and laptops. - - This class should be extended by concrete classes that define specific behaviors and properties of an IP-capable - wireless network interface. - """ - - @abstractmethod - def enable(self): - """Enable the interface.""" - pass - - @abstractmethod - def disable(self): - """Disable the interface.""" - pass - - @abstractmethod - def send_frame(self, frame: Frame) -> bool: - """ - Attempts to send a network frame through the interface. - - :param frame: The network frame to be sent. - :return: A boolean indicating whether the frame was successfully sent. - """ - pass - - @abstractmethod - def receive_frame(self, frame: Frame) -> bool: - """ - Receives a network frame on the interface. - - :param frame: The network frame being received. - :return: A boolean indicating whether the frame was successfully received. - """ - pass - - class Link(SimComponent): """ Represents a network link between NIC<-->NIC, NIC<-->SwitchPort, or SwitchPort<-->SwitchPort. diff --git a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py new file mode 100644 index 00000000..3a797031 --- /dev/null +++ b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py @@ -0,0 +1,217 @@ +from typing import Any, Dict, Union + +from pydantic import validate_call + +from primaite.simulator.network.airspace import AirSpaceFrequency, IPWirelessNetworkInterface +from primaite.simulator.network.hardware.nodes.network.router import Router, RouterInterface +from primaite.simulator.network.transmission.data_link_layer import Frame +from primaite.utils.validators import IPV4Address + + +class WirelessAccessPoint(IPWirelessNetworkInterface): + """ + Represents a Wireless Access Point (AP) in a network. + + This class models a Wireless Access Point, a device that allows wireless devices to connect to a wired network + using Wi-Fi or other wireless standards. The Wireless Access Point bridges the wireless and wired segments of + the network, allowing wireless devices to communicate with other devices on the network. + + As an integral component of wireless networking, a Wireless Access Point provides functionalities for network + management, signal broadcasting, security enforcement, and connection handling. It also possesses Layer 3 + capabilities such as IP addressing and subnetting, allowing for network segmentation and routing. + + Inherits from: + - WirelessNetworkInterface: Provides basic properties and methods specific to wireless interfaces. + - Layer3Interface: Provides Layer 3 properties like ip_address and subnet_mask, enabling the device to manage + network traffic and routing. + + This class can be further specialised or extended to support specific features or standards related to wireless + networking, such as different Wi-Fi versions, frequency bands, or advanced security protocols. + """ + + def model_post_init(self, __context: Any) -> None: + """ + Performs post-initialisation checks to ensure the model's IP configuration is valid. + + This method is invoked after the initialisation of a network model object to validate its network settings, + particularly to ensure that the assigned IP address is not a network address. This validation is crucial for + maintaining the integrity of network simulations and avoiding configuration errors that could lead to + unrealistic or incorrect behavior. + + :param __context: Contextual information or parameters passed to the method, used for further initializing or + validating the model post-creation. + :raises ValueError: If the IP address is the same as the network address, indicating an incorrect configuration. + """ + if self.ip_network.network_address == self.ip_address: + raise ValueError(f"{self.ip_address}/{self.subnet_mask} must not be a network address") + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + return super().describe_state() + + def receive_frame(self, frame: Frame) -> bool: + """ + Receives a network frame on the interface. + + :param frame: The network frame being received. + :return: A boolean indicating whether the frame was successfully received. + """ + if self.enabled: + frame.decrement_ttl() + if frame.ip and frame.ip.ttl < 1: + self._connected_node.sys_log.info("Frame discarded as TTL limit reached") + return False + frame.set_received_timestamp() + self.pcap.capture_inbound(frame) + # If this destination or is broadcast + if frame.ethernet.dst_mac_addr == self.mac_address or frame.ethernet.dst_mac_addr == "ff:ff:ff:ff:ff:ff": + self._connected_node.receive_frame(frame=frame, from_network_interface=self) + return True + return False + + def __str__(self) -> str: + """ + String representation of the NIC. + + :return: A string combining the port number, MAC address and IP address of the NIC. + """ + return f"Port {self.port_num}: {self.mac_address}/{self.ip_address} ({self.frequency})" + + +class WirelessRouter(Router): + """ + A WirelessRouter class that extends the functionality of a standard Router to include wireless capabilities. + + This class represents a network device that performs routing functions similar to a traditional router but also + includes the functionality of a wireless access point. This allows the WirelessRouter to not only direct traffic + between wired networks but also to manage and facilitate wireless network connections. + + A WirelessRouter is instantiated and configured with both wired and wireless interfaces. The wired interfaces are + managed similarly to those in a standard Router, while the wireless interfaces require additional configuration + specific to wireless settings, such as setting the frequency band (e.g., 2.4 GHz or 5 GHz for Wi-Fi). + + The WirelessRouter facilitates creating a network environment where devices can be interconnected via both + Ethernet (wired) and Wi-Fi (wireless), making it an essential component for simulating more complex and realistic + network topologies within PrimAITE. + + Example: + >>> wireless_router = WirelessRouter(hostname="wireless_router_1") + >>> wireless_router.configure_router_interface( + ... ip_address="192.168.1.1", + ... subnet_mask="255.255.255.0" + ... ) + >>> wireless_router.configure_wireless_access_point( + ... ip_address="10.10.10.1", + ... subnet_mask="255.255.255.0" + ... frequency=AirSpaceFrequency.WIFI_2_4 + ... ) + """ + + network_interfaces: Dict[str, Union[RouterInterface, WirelessAccessPoint]] = {} + network_interface: Dict[int, Union[RouterInterface, WirelessAccessPoint]] = {} + + def __init__(self, hostname: str, **kwargs): + super().__init__(hostname=hostname, num_ports=0, **kwargs) + + wap = WirelessAccessPoint(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") + wap.port_num = 1 + self.connect_nic(wap) + self.network_interface[1] = wap + + router_interface = RouterInterface(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") + router_interface.port_num = 2 + self.connect_nic(router_interface) + self.network_interface[2] = router_interface + + self.set_original_state() + + @property + def wireless_access_point(self) -> WirelessAccessPoint: + """ + Retrieves the wireless access point interface associated with this wireless router. + + This property provides direct access to the WirelessAccessPoint interface of the router, facilitating wireless + communications. Specifically, it returns the interface configured on port 1, dedicated to establishing and + managing wireless network connections. This interface is essential for enabling wireless connectivity, + allowing devices within connect to the network wirelessly. + + :return: The WirelessAccessPoint instance representing the wireless connection interface on port 1 of the + wireless router. + """ + return self.network_interface[1] + + @validate_call() + def configure_wireless_access_point( + self, + ip_address: IPV4Address, + subnet_mask: IPV4Address, + frequency: AirSpaceFrequency = AirSpaceFrequency.WIFI_2_4, + ): + """ + Configures a wireless access point (WAP). + + Sets its IP address, subnet mask, and operating frequency. This method ensures the wireless access point is + properly set up to manage wireless communication over the specified frequency band. + + The method first disables the WAP to safely apply configuration changes. After configuring the IP settings, + it sets the WAP to operate on the specified frequency band and then re-enables the WAP for operation. + + :param ip_address: The IP address to be assigned to the wireless access point. + :param subnet_mask: The subnet mask associated with the IP address + :param frequency: The operating frequency of the wireless access point, defined by the AirSpaceFrequency + enum. This determines the frequency band (e.g., 2.4 GHz or 5 GHz) the access point will use for wireless + communication. Default is AirSpaceFrequency.WIFI_2_4. + """ + self.wireless_access_point.disable() # Temporarily disable the WAP for reconfiguration + network_interface = self.network_interface[1] + network_interface.ip_address = ip_address + network_interface.subnet_mask = subnet_mask + self.sys_log.info(f"Configured WAP {network_interface}") + self.set_original_state() + self.wireless_access_point.frequency = frequency # Set operating frequency + self.wireless_access_point.enable() # Re-enable the WAP with new settings + + @property + def router_interface(self) -> RouterInterface: + """ + Retrieves the router interface associated with this wireless router. + + This property provides access to the router interface configured for wired connections. It specifically + returns the interface configured on port 2, which is reserved for wired LAN/WAN connections. + + :return: The RouterInterface instance representing the wired LAN/WAN connection on port 2 of the wireless + router. + """ + return self.network_interface[2] + + @validate_call() + def configure_router_interface( + self, + ip_address: IPV4Address, + subnet_mask: IPV4Address, + ): + """ + Configures a router interface. + + Sets its IP address and subnet mask. + + The method first disables the router interface to safely apply configuration changes. After configuring the IP + settings, it re-enables the router interface for operation. + + :param ip_address: The IP address to be assigned to the router interface. + :param subnet_mask: The subnet mask associated with the IP address + """ + self.router_interface.disable() # Temporarily disable the router interface for reconfiguration + super().configure_port(port=2, ip_address=ip_address, subnet_mask=subnet_mask) # Set IP configuration + self.router_interface.enable() # Re-enable the router interface with new settings + + def configure_port(self, port: int, ip_address: Union[IPV4Address, str], subnet_mask: Union[IPV4Address, str]): + """Not Implemented.""" + raise NotImplementedError( + "Please use the 'configure_wireless_access_point' and 'configure_router_interface' functions." + ) From da92d742366c574074e14070ae313897325e8888 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 12 Feb 2024 09:01:30 +0000 Subject: [PATCH 589/980] #2258: remove unnecessary ntp server check --- src/primaite/simulator/system/services/ntp/ntp_client.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index c9935a16..ddd794ae 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -132,7 +132,6 @@ class NTPClient(Service): super().apply_timestep(timestep) if self.operating_state == ServiceOperatingState.RUNNING: # request time from server - if self.ntp_server is not None: - self.request_time() + self.request_time() else: self.sys_log.debug(f"{self.name} ntp client not running") From 7beacfd95fb6c48f8f3581bd58be1addd42a1422 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 12 Feb 2024 11:41:55 +0000 Subject: [PATCH 590/980] #2258: missing some configuration items + added more tests --- src/primaite/game/game.py | 11 ++++++++++- tests/assets/configs/basic_switched_network.yaml | 6 ++++++ tests/integration_tests/game_configuration.py | 16 +++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 6ccd2f59..c03bca36 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -283,7 +283,16 @@ class PrimaiteGame: opt = service_cfg["options"] new_service.configure_backup(backup_server=IPv4Address(opt.get("backup_server_ip"))) new_service.start() - + if service_type == "FTPServer": + if "options" in service_cfg: + opt = service_cfg["options"] + new_service.server_password = opt.get("server_password") + new_service.start() + if service_type == "NTPClient": + if "options" in service_cfg: + opt = service_cfg["options"] + new_service.ntp_server = IPv4Address(opt.get("ntp_server_ip")) + new_service.start() if "applications" in node_cfg: for application_cfg in node_cfg["applications"]: new_application = None diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 0050a0cb..d1cec079 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -85,6 +85,7 @@ simulation: type: DatabaseClient options: db_server_ip: 192.168.1.10 + server_password: arcd - ref: data_manipulation_bot type: DataManipulationBot options: @@ -92,6 +93,7 @@ simulation: data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.21 + server_password: arcd - ref: dos_bot type: DoSBot options: @@ -116,8 +118,12 @@ simulation: type: WebServer - ref: client_1_ftp_server type: FTPServer + options: + server_password: arcd - ref: client_1_ntp_client type: NTPClient + options: + ntp_server_ip: 192.168.1.10 - ref: client_1_ntp_server type: NTPServer - ref: client_2 diff --git a/tests/integration_tests/game_configuration.py b/tests/integration_tests/game_configuration.py index 9db894c5..3bd870e3 100644 --- a/tests/integration_tests/game_configuration.py +++ b/tests/integration_tests/game_configuration.py @@ -9,7 +9,7 @@ from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import ProxyAgent, RandomAgent from primaite.game.game import APPLICATION_TYPES_MAPPING, PrimaiteGame, SERVICE_TYPES_MAPPING from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.applications.red_applications.dos_bot import DoSBot @@ -109,6 +109,7 @@ def test_database_client_install(): database_client: DatabaseClient = client_1.software_manager.software.get("DatabaseClient") assert database_client.server_ip_address == IPv4Address("192.168.1.10") + assert database_client.server_password == "arcd" def test_data_manipulation_bot_install(): @@ -122,6 +123,7 @@ def test_data_manipulation_bot_install(): assert data_manipulation_bot.payload == "DELETE" assert data_manipulation_bot.data_manipulation_p_of_success == 0.8 assert data_manipulation_bot.port_scan_p_of_success == 0.8 + assert data_manipulation_bot.server_password == "arcd" def test_dos_bot_install(): @@ -149,6 +151,16 @@ def test_dns_client_install(): assert dns_client.dns_server == IPv4Address("192.168.1.10") +def test_dns_server_install(): + """Test that the DNS Client service can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + dns_server: DNSServer = client_1.software_manager.software.get("DNSServer") + + assert dns_server.dns_lookup("arcd.com") == IPv4Address("192.168.1.10") + + def test_database_service_install(): """Test that the Database Service can be configured via config.""" game = load_config(BASIC_CONFIG) @@ -186,6 +198,7 @@ def test_ftp_server_install(): ftp_server_service: FTPServer = client_1.software_manager.software.get("FTPServer") assert ftp_server_service is not None + assert ftp_server_service.server_password == "arcd" def test_ntp_client_install(): @@ -195,6 +208,7 @@ def test_ntp_client_install(): ntp_client_service: NTPClient = client_1.software_manager.software.get("NTPClient") assert ntp_client_service is not None + assert ntp_client_service.ntp_server == IPv4Address("192.168.1.10") def test_ntp_server_install(): From cfd64333e26a137722d661679d2b480739c5d911 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 12 Feb 2024 12:31:08 +0000 Subject: [PATCH 591/980] #2205 - Added wireless router tests and documentation. Refactored some code based on PR suggestions. --- docs/source/simulation.rst | 1 + .../network/nodes/wireless_router.rst | 193 ++++++++++++++++++ .../hardware/nodes/network/firewall.py | 37 ++-- .../network/hardware/nodes/network/router.py | 6 +- .../network/test_wireless_router.py | 134 ++++++++++++ 5 files changed, 350 insertions(+), 21 deletions(-) create mode 100644 docs/source/simulation_components/network/nodes/wireless_router.rst create mode 100644 tests/integration_tests/network/test_wireless_router.py diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index 56761517..c703b299 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -22,6 +22,7 @@ Contents simulation_components/network/nodes/host_node simulation_components/network/nodes/network_node simulation_components/network/nodes/router + simulation_components/network/nodes/wireless_router simulation_components/network/nodes/firewall simulation_components/network/switch simulation_components/network/network diff --git a/docs/source/simulation_components/network/nodes/wireless_router.rst b/docs/source/simulation_components/network/nodes/wireless_router.rst new file mode 100644 index 00000000..75cbe0f7 --- /dev/null +++ b/docs/source/simulation_components/network/nodes/wireless_router.rst @@ -0,0 +1,193 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +###### +Router +###### + +The ``WirelessRouter`` class extends the functionality of the standard ``Router`` class within PrimAITE, +integrating wireless networking capabilities. This class enables the simulation of a router that supports both wired +and wireless connections, allowing for a more comprehensive network simulation environment. + +Overview +-------- + +The ``WirelessRouter`` class is designed to simulate the operations of a real-world wireless router, offering both +Ethernet and Wi-Fi connectivity. This includes managing wireless access points, configuring network interfaces for +different frequencies, and handling wireless frames transmission. + +Features +-------- + +- **Dual Interface Support:** Supports both wired (Ethernet) and wireless network interfaces. +- **Wireless Access Point Configuration:** Allows configuring a wireless access point, including setting its IP + address, subnet mask, and operating frequency. +- **Frequency Management:** Utilises the ``AirSpaceFrequency`` enum to set the operating frequency of wireless + interfaces, supporting common Wi-Fi bands like 2.4 GHz and 5 GHz. +- **Seamless Wireless Communication:** Integrates with the ``AirSpace`` class to manage wireless transmissions across + different frequencies, ensuring that wireless communication is realistically simulated. + +Usage +----- + +To use the ``WirelessRouter`` class in a network simulation, instantiate it similarly to a regular router but with +additional steps to configure wireless settings: + +.. code-block:: python + + from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter + from primaite.simulator.network.airspace import AirSpaceFrequency + + # Instantiate the WirelessRouter + wireless_router = WirelessRouter(hostname="MyWirelessRouter") + + # Configure a wired Ethernet interface + wireless_router.configure_port(port=2, ip_address="192.168.1.1", subnet_mask="255.255.255.0") + + # Configure a wireless access point + wireless_router.configure_wireless_access_point( + port=1, ip_address="192.168.2.1", + subnet_mask="255.255.255.0", + frequency=AirSpaceFrequency.WIFI_2_4 + ) + + + +Integration with AirSpace +------------------------- + +The ``WirelessRouter`` class works closely with the ``AirSpace`` class to simulate the transmission of wireless frames. +Frames sent from wireless interfaces are transmitted across the simulated airspace, allowing for interactions with +other wireless devices within the same frequency band. + +Example Scenario +---------------- + +This example sets up a network with two PCs (PC A and PC B), each connected to their own `WirelessRouter` +(Router 1 and Router 2). These routers are then wirelessly connected to each other, enabling communication between the +PCs through the routers over the airspace. Access Control Lists (ACLs) are configured on the routers to permit ARP and +ICMP traffic, ensuring basic network connectivity and ping functionality. + +.. code-block:: python + + from primaite.simulator.network.airspace import AIR_SPACE, AirSpaceFrequency + from primaite.simulator.network.container import Network + from primaite.simulator.network.hardware.nodes.host.computer import Computer + from primaite.simulator.network.hardware.nodes.network.router import ACLAction + from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter + from primaite.simulator.network.transmission.network_layer import IPProtocol + from primaite.simulator.network.transmission.transport_layer import Port + + network = Network() + + # Configure PC A + pc_a = Computer( + hostname="pc_a", + ip_address="192.168.0.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.0.1", + start_up_duration=0, + ) + pc_a.power_on() + network.add_node(pc_a) + + # Configure Router 1 + router_1 = WirelessRouter(hostname="router_1", start_up_duration=0) + router_1.power_on() + network.add_node(router_1) + + # Configure the connection between PC A and Router 1 port 2 + router_1.configure_router_interface("192.168.0.1", "255.255.255.0") + network.connect(pc_a.network_interface[1], router_1.router_interface) + + # Configure Router 1 ACLs + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) + router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + + # Configure PC B + pc_b = Computer( + hostname="pc_b", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.2.1", + start_up_duration=0, + ) + pc_b.power_on() + network.add_node(pc_b) + + # Configure Router 2 + router_2 = WirelessRouter(hostname="router_2", start_up_duration=0) + router_2.power_on() + network.add_node(router_2) + + # Configure the connection between PC B and Router 2 port 2 + router_2.configure_router_interface("192.168.2.1", "255.255.255.0") + network.connect(pc_b.network_interface[1], router_2.router_interface) + + # Configure the wireless connection between Router 1 and Router 2 + router_1.configure_wireless_access_point( + port=1, + ip_address="192.168.1.1", + subnet_mask="255.255.255.0", + frequency=AirSpaceFrequency.WIFI_2_4 + ) + router_2.configure_wireless_access_point( + port=1, + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + frequency=AirSpaceFrequency.WIFI_2_4 + ) + + # Configure routes for inter-router communication + router_1.route_table.add_route( + address="192.168.2.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.2" + ) + + router_2.route_table.add_route( + address="192.168.0.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.1" + ) + + # Test connectivity + print(pc_a.ping(pc_b.network_interface[1].ip_address)) + print(pc_b.ping(pc_a.network_interface[1].ip_address)) + +This setup demonstrates the `WirelessRouter` class's capability to manage both wired and wireless connections within a +simulated network environment. By configuring the wireless access points and enabling the appropriate ACL rules, the +example facilitates basic network operations such as ARP resolution and ICMP pinging between devices across different +network segments. + +Viewing Wireless Network Configuration +-------------------------------------- + +The `AirSpace.show()` function is an invaluable tool for inspecting the current wireless network configuration within +the PrimAITE environment. It presents a table summarising all wireless interfaces, including routers and access points, +that are active within the airspace. The table outlines each device's connected node name, MAC address, IP address, +subnet mask, operating frequency, and status, providing a comprehensive view of the wireless network topology. + +Example Output +^^^^^^^^^^^^^^^ + +Below is an example output of the `AirSpace.show()` function, demonstrating the visibility it provides into the +wireless network: + +.. code-block:: none + + +----------------+-------------------+-------------+---------------+--------------+---------+ + | Connected Node | MAC Address | IP Address | Subnet Mask | Frequency | Status | + +----------------+-------------------+-------------+---------------+--------------+---------+ + | router_1 | 31:29:46:53:ed:f8 | 192.168.1.1 | 255.255.255.0 | WiFi 2.4 GHz | Enabled | + | router_2 | 34:c8:47:43:98:78 | 192.168.1.2 | 255.255.255.0 | WiFi 2.4 GHz | Enabled | + +----------------+-------------------+-------------+---------------+--------------+---------+ + +This table aids in verifying that wireless devices are correctly configured and operational. It also helps in +diagnosing connectivity issues by ensuring that devices are on the correct frequency and have the appropriate network +settings. The `Status` column, indicating whether a device is enabled or disabled, further assists in troubleshooting +by quickly identifying any devices that are not actively participating in the network. + +Utilising the `AirSpace.show()` function is particularly beneficial in complex network simulations where multiple +wireless devices are in use. It provides a snapshot of the wireless landscape, facilitating the understanding of how +devices interact within the network and ensuring that configurations are aligned with the intended network architecture. + +The addition of the ``WirelessRouter`` class enriches the PrimAITE simulation toolkit by enabling the simulation of +mixed wired and wireless network environments. diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index bccfeab1..22effa2a 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -122,6 +122,8 @@ class Firewall(Router): "internal_outbound_acl", "dmz_inbound_acl", "dmz_outbound_acl", + "external_inbound_acl", + "external_outbound_acl", } self._original_state.update(self.model_dump(include=vals_to_include)) @@ -142,6 +144,8 @@ class Firewall(Router): "internal_outbound_acl": self.internal_outbound_acl.describe_state(), "dmz_inbound_acl": self.dmz_inbound_acl.describe_state(), "dmz_outbound_acl": self.dmz_outbound_acl.describe_state(), + "external_inbound_acl": self.external_inbound_acl.describe_state(), + "external_outbound_acl": self.external_outbound_acl.describe_state(), } ) @@ -263,12 +267,11 @@ class Firewall(Router): if not permitted: self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}") return - else: - self.software_manager.arp.add_arp_cache_entry( - ip_address=frame.ip.src_ip_address, - mac_address=frame.ethernet.src_mac_addr, - network_interface=from_network_interface, - ) + self.software_manager.arp.add_arp_cache_entry( + ip_address=frame.ip.src_ip_address, + mac_address=frame.ethernet.src_mac_addr, + network_interface=from_network_interface, + ) if self.check_send_frame_to_session_manager(frame): # Port is open on this Router so pass Frame up to session manager first @@ -332,12 +335,11 @@ class Firewall(Router): if not permitted: self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}") return - else: - self.software_manager.arp.add_arp_cache_entry( - ip_address=frame.ip.src_ip_address, - mac_address=frame.ethernet.src_mac_addr, - network_interface=from_network_interface, - ) + self.software_manager.arp.add_arp_cache_entry( + ip_address=frame.ip.src_ip_address, + mac_address=frame.ethernet.src_mac_addr, + network_interface=from_network_interface, + ) if self.check_send_frame_to_session_manager(frame): # Port is open on this Router so pass Frame up to session manager first @@ -387,12 +389,11 @@ class Firewall(Router): if not permitted: self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}") return - else: - self.software_manager.arp.add_arp_cache_entry( - ip_address=frame.ip.src_ip_address, - mac_address=frame.ethernet.src_mac_addr, - network_interface=from_network_interface, - ) + self.software_manager.arp.add_arp_cache_entry( + ip_address=frame.ip.src_ip_address, + mac_address=frame.ethernet.src_mac_addr, + network_interface=from_network_interface, + ) if self.check_send_frame_to_session_manager(frame): # Port is open on this Router so pass Frame up to session manager first diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 0d5b3d76..bb7b8a83 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -35,9 +35,9 @@ def ip_matches_masked_range(ip_to_check: IPV4Address, base_ip: IPV4Address, wild by the wildcard mask. If the resulting masked IP addresses are equal, it means the IP address to check falls within the range defined by the base IP and wildcard mask. - :param IPv4Address ip_to_check: The IP address to be checked. - :param IPv4Address base_ip: The base IP address defining the start of the range. - :param IPv4Address wildcard_mask: The wildcard mask specifying which bits to ignore. + :param IPV4Address ip_to_check: The IP address to be checked. + :param IPV4Address base_ip: The base IP address defining the start of the range. + :param IPV4Address wildcard_mask: The wildcard mask specifying which bits to ignore. :return: A boolean value indicating whether the IP address matches the masked range. :rtype: bool diff --git a/tests/integration_tests/network/test_wireless_router.py b/tests/integration_tests/network/test_wireless_router.py new file mode 100644 index 00000000..1b55c1b6 --- /dev/null +++ b/tests/integration_tests/network/test_wireless_router.py @@ -0,0 +1,134 @@ +import pytest + +from primaite.simulator.network.airspace import AIR_SPACE, AirSpaceFrequency +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.network.router import ACLAction +from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port + + +@pytest.fixture(scope="function") +def setup_network(): + network = Network() + + # Configure PC A + pc_a = Computer( + hostname="pc_a", + ip_address="192.168.0.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.0.1", + start_up_duration=0, + ) + pc_a.power_on() + network.add_node(pc_a) + + # Configure Router 1 + router_1 = WirelessRouter(hostname="router_1", start_up_duration=0) + router_1.power_on() + network.add_node(router_1) + + # Configure the connection between PC A and Router 1 port 2 + router_1.configure_router_interface("192.168.0.1", "255.255.255.0") + network.connect(pc_a.network_interface[1], router_1.network_interface[2]) + + # Configure Router 1 ACLs + router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.ARP, dst_port=Port.ARP, position=22) + router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=IPProtocol.ICMP, position=23) + + # Configure PC B + pc_b = Computer( + hostname="pc_b", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.2.1", + start_up_duration=0, + ) + pc_b.power_on() + network.add_node(pc_b) + + # Configure Router 2 + router_2 = WirelessRouter(hostname="router_2", start_up_duration=0) + router_2.power_on() + network.add_node(router_2) + + # Configure the connection between PC B and Router 2 port 2 + router_2.configure_router_interface("192.168.2.1", "255.255.255.0") + network.connect(pc_b.network_interface[1], router_2.network_interface[2]) + + # Configure Router 2 ACLs + + # Configure the wireless connection between Router 1 port 1 and Router 2 port 1 + router_1.configure_wireless_access_point("192.168.1.1", "255.255.255.0") + router_2.configure_wireless_access_point("192.168.1.2", "255.255.255.0") + + AIR_SPACE.show() + + router_1.route_table.add_route( + address="192.168.2.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.2" + ) + + # Configure Route from Router 2 to PC A subnet + router_2.route_table.add_route( + address="192.168.0.2", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.1" + ) + + # Configure PC C + pc_c = Computer( + hostname="pc_c", + ip_address="192.168.3.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.3.1", + start_up_duration=0, + ) + pc_c.power_on() + network.add_node(pc_c) + + # Configure Router 3 + router_3 = WirelessRouter(hostname="router_3", start_up_duration=0) + router_3.power_on() + network.add_node(router_3) + + # Configure the connection between PC C and Router 3 port 2 + router_3.configure_router_interface("192.168.3.1", "255.255.255.0") + network.connect(pc_c.network_interface[1], router_3.network_interface[2]) + + # Configure the wireless connection between Router 2 port 1 and Router 3 port 1 + router_3.configure_wireless_access_point("192.168.1.3", "255.255.255.0") + + # Configure Route from Router 1 to PC C subnet + router_1.route_table.add_route( + address="192.168.3.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.3" + ) + + # Configure Route from Router 2 to PC C subnet + router_2.route_table.add_route( + address="192.168.3.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.3" + ) + + # Configure Route from Router 3 to PC A and PC B subnets + router_3.route_table.add_route( + address="192.168.0.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.1" + ) + router_3.route_table.add_route( + address="192.168.2.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.2" + ) + + return pc_a, pc_b, pc_c, router_1, router_2, router_3 + + +def test_ping_default_gateways(setup_network): + pc_a, pc_b, pc_c, router_1, router_2, router_3 = setup_network + # Check if each PC can ping its default gateway + assert pc_a.ping(pc_a.default_gateway), "PC A should ping its default gateway successfully." + assert pc_b.ping(pc_b.default_gateway), "PC B should ping its default gateway successfully." + assert pc_c.ping(pc_c.default_gateway), "PC C should ping its default gateway successfully." + + +def test_cross_router_connectivity_pre_frequency_change(setup_network): + pc_a, pc_b, pc_c, router_1, router_2, router_3 = setup_network + # Ensure that PCs can ping across routers before any frequency change + assert pc_a.ping(pc_b.network_interface[1].ip_address), "PC A should ping PC B across routers successfully." + assert pc_a.ping(pc_c.network_interface[1].ip_address), "PC A should ping PC C across routers successfully." + assert pc_b.ping(pc_c.network_interface[1].ip_address), "PC B should ping PC C across routers successfully." From add09a0280057a877d2eaff43f4839626ae124c5 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 12 Feb 2024 14:08:55 +0000 Subject: [PATCH 592/980] #2205 - Tidied up interface creation and applied some suggestions from PR --- .../simulator/network/hardware/nodes/network/router.py | 8 ++++---- .../network/hardware/nodes/network/wireless_router.py | 10 ++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index bb7b8a83..774aae7c 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -103,11 +103,11 @@ class ACLRule(SimComponent): The default action is `DENY`. :ivar Optional[IPProtocol] protocol: The network protocol (e.g., TCP, UDP, ICMP) to match. If `None`, the rule applies to all protocols. - :ivar Optional[IPv4Address] src_ip_address: The source IP address to match. If combined with `src_wildcard_mask`, + :ivar Optional[IPV4Address] src_ip_address: The source IP address to match. If combined with `src_wildcard_mask`, it specifies the start of an IP range. - :ivar Optional[IPv4Address] src_wildcard_mask: The wildcard mask for the source IP address, defining the range + :ivar Optional[IPV4Address] src_wildcard_mask: The wildcard mask for the source IP address, defining the range of addresses to match. - :ivar Optional[IPv4Address] dst_ip_address: The destination IP address to match. If combined with + :ivar Optional[IPV4Address] dst_ip_address: The destination IP address to match. If combined with `dst_wildcard_mask`, it specifies the start of an IP range. :ivar Optional[IPv4Address] dst_wildcard_mask: The wildcard mask for the destination IP address, defining the range of addresses to match. @@ -1225,7 +1225,7 @@ class Router(NetworkNode): """ Determines whether a given network frame should be forwarded to the session manager. - his function evaluates whether the destination IP address of the frame corresponds to one of the router's + This function evaluates whether the destination IP address of the frame corresponds to one of the router's interface IP addresses. If so, it then checks if the frame is an ICMP packet or if the destination port matches any of the ports that the router's software manager identifies as open. If either condition is met, the frame is considered for further processing by the session manager, implying potential application-level handling or diff --git a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py index 3a797031..dd0b58d3 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py @@ -118,15 +118,9 @@ class WirelessRouter(Router): def __init__(self, hostname: str, **kwargs): super().__init__(hostname=hostname, num_ports=0, **kwargs) - wap = WirelessAccessPoint(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") - wap.port_num = 1 - self.connect_nic(wap) - self.network_interface[1] = wap + self.connect_nic(WirelessAccessPoint(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0")) - router_interface = RouterInterface(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") - router_interface.port_num = 2 - self.connect_nic(router_interface) - self.network_interface[2] = router_interface + self.connect_nic(RouterInterface(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0")) self.set_original_state() From fa08e53b150d83bd58aa21e56c515b52d87b5501 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Mon, 12 Feb 2024 17:01:53 +0000 Subject: [PATCH 593/980] 2297: Convert NTP Client and Server to UDP --- src/primaite/simulator/system/services/ntp/ntp_client.py | 2 +- src/primaite/simulator/system/services/ntp/ntp_server.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index ddd794ae..43d1d783 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -21,7 +21,7 @@ class NTPClient(Service): def __init__(self, **kwargs): kwargs["name"] = "NTPClient" kwargs["port"] = Port.NTP - kwargs["protocol"] = IPProtocol.TCP + kwargs["protocol"] = IPProtocol.UDP super().__init__(**kwargs) self.start() diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index 3987fa2c..3ae80936 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -16,7 +16,7 @@ class NTPServer(Service): def __init__(self, **kwargs): kwargs["name"] = "NTPServer" kwargs["port"] = Port.NTP - kwargs["protocol"] = IPProtocol.TCP + kwargs["protocol"] = IPProtocol.UDP super().__init__(**kwargs) self.start() From 697e53def8881620e67a2564df8da713c8ed8784 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Mon, 12 Feb 2024 17:12:59 +0000 Subject: [PATCH 594/980] 2297: Doc update. --- docs/source/simulation_components/system/ntp_client_server.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/simulation_components/system/ntp_client_server.rst b/docs/source/simulation_components/system/ntp_client_server.rst index 671126fb..2d49f34e 100644 --- a/docs/source/simulation_components/system/ntp_client_server.rst +++ b/docs/source/simulation_components/system/ntp_client_server.rst @@ -44,7 +44,7 @@ Usage ^^^^^ - Install on a Node via the ``SoftwareManager`` to start the database service. -- Service runs on TCP port 123 by default. +- Service runs on UDP port 123 by default. Implementation ^^^^^^^^^^^^^^ From 4c66d2b2524fbe7cf4cef51302dab3f5cd168d30 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Mon, 12 Feb 2024 17:24:28 +0000 Subject: [PATCH 595/980] 2297: Change missed reference TCP to UDP. --- docs/source/simulation_components/system/ntp_client_server.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/simulation_components/system/ntp_client_server.rst b/docs/source/simulation_components/system/ntp_client_server.rst index 2d49f34e..b6d57c13 100644 --- a/docs/source/simulation_components/system/ntp_client_server.rst +++ b/docs/source/simulation_components/system/ntp_client_server.rst @@ -22,7 +22,7 @@ Key capabilities Usage ^^^^^ - Install on a Node via the ``SoftwareManager`` to start the database service. -- Service runs on TCP port 123 by default. +- Service runs on UDP port 123 by default. Implementation ^^^^^^^^^^^^^^ From 2c743005cd4800f68a90462259393128483fc21c Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 12 Feb 2024 18:58:10 +0000 Subject: [PATCH 596/980] #2257: moved config tests into its own directory + added dmz_network.yaml to use in tests --- .../configs/basic_switched_network.yaml | 7 + tests/assets/configs/dmz_network.yaml | 230 ++++++++++++++++++ .../configuration_file_parsing/__init__.py | 0 .../router_game_configuration.py | 58 +++++ ...oftware_installation_and_configuration.py} | 0 5 files changed, 295 insertions(+) create mode 100644 tests/assets/configs/dmz_network.yaml create mode 100644 tests/integration_tests/configuration_file_parsing/__init__.py create mode 100644 tests/integration_tests/configuration_file_parsing/router_game_configuration.py rename tests/integration_tests/{game_configuration.py => configuration_file_parsing/software_installation_and_configuration.py} (100%) diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index d1cec079..a248065c 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -1,3 +1,10 @@ +# Basic Switched network +# +# -------------- -------------- -------------- +# | client_1 |------| switch_1 |------| client_2 | +# -------------- -------------- -------------- +# + training_config: rl_framework: SB3 rl_algorithm: PPO diff --git a/tests/assets/configs/dmz_network.yaml b/tests/assets/configs/dmz_network.yaml new file mode 100644 index 00000000..ddf8fb36 --- /dev/null +++ b/tests/assets/configs/dmz_network.yaml @@ -0,0 +1,230 @@ +# Network with DMZ +# +# An example network configuration with an internal network, a DMZ network and a couple of external networks. +# +# ............................................................................ +# . . +# . Internal Network . +# . . +# . -------------- -------------- -------------- . +# . | client_1 |------| switch_1 |------| router_1 | . +# . -------------- -------------- -------------- . +# . (Computer) | . +# ......................................................|..................... +# | +# | +# ......................................................|..................... +# . | . +# . DMZ Network | . +# . | . +# . -------------- -------------- -------------- . +# . | client_2 |------| switch_2 |------| router_2 | . +# . -------------- -------------- -------------- . +# . (Computer) | . +# ......................................................|..................... +# | +# External Network | +# | +# | +# ----------------------- -------------- --------------------- +# | external_computer |------| switch_3 |------| external_server | +# ----------------------- -------------- --------------------- +# +training_config: + rl_framework: SB3 + rl_algorithm: PPO + seed: 333 + n_learn_episodes: 1 + n_eval_episodes: 5 + max_steps_per_episode: 128 + deterministic_eval: false + n_agents: 1 + agent_references: + - defender + +io_settings: + save_checkpoints: true + checkpoint_interval: 5 + save_step_metadata: false + save_pcap_logs: true + save_sys_logs: true + + +game: + max_episode_length: 256 + ports: + - ARP + - DNS + - HTTP + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + - UDP + +agents: + - ref: client_2_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_2 + applications: + - application_name: WebBrowser + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_applications_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_settings: + start_step: 5 + frequency: 4 + variance: 3 + + +simulation: + network: + nodes: + - ref: client_1 + type: computer + hostname: client_1 + ip_address: 192.168.0.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.0.1 + dns_server: 192.168.20.10 + + - ref: switch_1 + type: switch + hostname: switch_1 + num_ports: 8 + + - ref: router_1 + type: router + hostname: router_1 + num_ports: 5 + ports: + 1: + ip_address: 192.168.0.1 + subnet_mask: 255.255.255.0 + 2: + ip_address: 192.168.1.1 + subnet_mask: 255.255.255.0 + acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + + - ref: client_2 + type: computer + hostname: client_2 + ip_address: 192.168.10.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.20.10 + + - ref: switch_2 + type: switch + hostname: switch_2 + num_ports: 8 + + - ref: router_2 + type: router + hostname: router_2 + num_ports: 5 + ports: + 1: + ip_address: 192.168.10.1 + subnet_mask: 255.255.255.0 + 2: + ip_address: 192.168.11.1 + subnet_mask: 255.255.255.0 + 3: + ip_address: 192.168.20.1 + subnet_mask: 255.255.255.0 + acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + + - ref: switch_3 + type: switch + hostname: switch_3 + num_ports: 8 + + - ref: external_computer + type: computer + hostname: external_computer + ip_address: 192.168.20.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.20.1 + dns_server: 192.168.20.10 + + - ref: external_server + type: server + hostname: external_server + ip_address: 192.168.20.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.20.1 + services: + - ref: domain_controller_dns_server + type: DNSServer + links: + - ref: client_1___switch_1 + endpoint_a_ref: client_1 + endpoint_a_port: 1 + endpoint_b_ref: switch_1 + endpoint_b_port: 1 + - ref: router_1___switch_1 + endpoint_a_ref: router_1 + endpoint_a_port: 1 + endpoint_b_ref: switch_1 + endpoint_b_port: 8 + - ref: router_1___router_2 + endpoint_a_ref: router_1 + endpoint_a_port: 2 + endpoint_b_ref: router_2 + endpoint_b_port: 2 + - ref: router_2___switch_2 + endpoint_a_ref: router_2 + endpoint_a_port: 1 + endpoint_b_ref: switch_2 + endpoint_b_port: 8 + - ref: client_2___switch_2 + endpoint_a_ref: client_2 + endpoint_a_port: 1 + endpoint_b_ref: switch_2 + endpoint_b_port: 1 + - ref: router_2___switch_3 + endpoint_a_ref: router_2 + endpoint_a_port: 3 + endpoint_b_ref: switch_3 + endpoint_b_port: 8 + - ref: external_computer___switch_3 + endpoint_a_ref: external_computer + endpoint_a_port: 1 + endpoint_b_ref: switch_3 + endpoint_b_port: 1 + - ref: external_server___switch_3 + endpoint_a_ref: external_server + endpoint_a_port: 1 + endpoint_b_ref: switch_3 + endpoint_b_port: 2 diff --git a/tests/integration_tests/configuration_file_parsing/__init__.py b/tests/integration_tests/configuration_file_parsing/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration_tests/configuration_file_parsing/router_game_configuration.py b/tests/integration_tests/configuration_file_parsing/router_game_configuration.py new file mode 100644 index 00000000..49b889d7 --- /dev/null +++ b/tests/integration_tests/configuration_file_parsing/router_game_configuration.py @@ -0,0 +1,58 @@ +from pathlib import Path +from typing import Union + +import yaml + +from primaite.game.game import PrimaiteGame +from primaite.simulator.network.container import Network +from tests import TEST_ASSETS_ROOT + +DMZ_NETWORK = TEST_ASSETS_ROOT / "configs/dmz_network.yaml" + + +def load_config(config_path: Union[str, Path]) -> PrimaiteGame: + """Returns a PrimaiteGame object which loads the contents of a given yaml path.""" + with open(config_path, "r") as f: + cfg = yaml.safe_load(f) + + return PrimaiteGame.from_config(cfg) + + +def test_dmz_config(): + """Test that the DMZ network config can be parsed properly.""" + game = load_config(DMZ_NETWORK) + + network: Network = game.simulation.network + + assert len(network.nodes) == 9 # 9 nodes in network + assert len(network.routers) == 2 # 2 routers in network + assert len(network.switches) == 3 # 3 switches in network + assert len(network.servers) == 1 # 1 server in network + + +def test_router_routes_are_correctly_added(): + """Test that makes sure that router routes have been added from the configuration file.""" + pass + + +def test_firewall_node_added_to_network(): + """Test that the firewall has been correctly added to and configured in the network.""" + pass + + +def test_router_acl_rules_correctly_added(): + """Test that makes sure that the router ACLs have been configured onto the router node via configuration file.""" + pass + + +def test_firewall_routes_are_correctly_added(): + """Test that the firewall routes have been correctly added to and configured in the network.""" + pass + + +def test_firewall_acl_rules_correctly_added(): + """ + Test that makes sure that the firewall ACLs have been configured onto the firewall + node via configuration file. + """ + pass diff --git a/tests/integration_tests/game_configuration.py b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py similarity index 100% rename from tests/integration_tests/game_configuration.py rename to tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py From 426c0a668279840e99f83db148348bc91469922d Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 13 Feb 2024 10:18:06 +0000 Subject: [PATCH 597/980] 2205 - Slimmed down the capability of the wireless router for now --- .../network/test_wireless_router.py | 57 ++----------------- 1 file changed, 5 insertions(+), 52 deletions(-) diff --git a/tests/integration_tests/network/test_wireless_router.py b/tests/integration_tests/network/test_wireless_router.py index 1b55c1b6..0e458974 100644 --- a/tests/integration_tests/network/test_wireless_router.py +++ b/tests/integration_tests/network/test_wireless_router.py @@ -74,61 +74,14 @@ def setup_network(): address="192.168.0.2", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.1" ) - # Configure PC C - pc_c = Computer( - hostname="pc_c", - ip_address="192.168.3.2", - subnet_mask="255.255.255.0", - default_gateway="192.168.3.1", - start_up_duration=0, - ) - pc_c.power_on() - network.add_node(pc_c) - - # Configure Router 3 - router_3 = WirelessRouter(hostname="router_3", start_up_duration=0) - router_3.power_on() - network.add_node(router_3) - - # Configure the connection between PC C and Router 3 port 2 - router_3.configure_router_interface("192.168.3.1", "255.255.255.0") - network.connect(pc_c.network_interface[1], router_3.network_interface[2]) - - # Configure the wireless connection between Router 2 port 1 and Router 3 port 1 - router_3.configure_wireless_access_point("192.168.1.3", "255.255.255.0") - - # Configure Route from Router 1 to PC C subnet - router_1.route_table.add_route( - address="192.168.3.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.3" - ) - - # Configure Route from Router 2 to PC C subnet - router_2.route_table.add_route( - address="192.168.3.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.3" - ) - - # Configure Route from Router 3 to PC A and PC B subnets - router_3.route_table.add_route( - address="192.168.0.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.1" - ) - router_3.route_table.add_route( - address="192.168.2.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.2" - ) - - return pc_a, pc_b, pc_c, router_1, router_2, router_3 + return pc_a, pc_b, router_1, router_2 -def test_ping_default_gateways(setup_network): - pc_a, pc_b, pc_c, router_1, router_2, router_3 = setup_network - # Check if each PC can ping its default gateway +def test_cross_router_connectivity(setup_network): + pc_a, pc_b, router_1, router_2 = setup_network + # Ensure that PCs can ping across routers before any frequency change assert pc_a.ping(pc_a.default_gateway), "PC A should ping its default gateway successfully." assert pc_b.ping(pc_b.default_gateway), "PC B should ping its default gateway successfully." - assert pc_c.ping(pc_c.default_gateway), "PC C should ping its default gateway successfully." - -def test_cross_router_connectivity_pre_frequency_change(setup_network): - pc_a, pc_b, pc_c, router_1, router_2, router_3 = setup_network - # Ensure that PCs can ping across routers before any frequency change assert pc_a.ping(pc_b.network_interface[1].ip_address), "PC A should ping PC B across routers successfully." - assert pc_a.ping(pc_c.network_interface[1].ip_address), "PC A should ping PC C across routers successfully." - assert pc_b.ping(pc_c.network_interface[1].ip_address), "PC B should ping PC C across routers successfully." + assert pc_b.ping(pc_a.network_interface[1].ip_address), "PC B should ping PC A across routers successfully." From 7b64d99a636768846e49fe467306e189989785dd Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 13 Feb 2024 12:56:41 +0000 Subject: [PATCH 598/980] #2205 - Final suggestions from PR --- src/primaite/simulator/network/airspace.py | 1 - tests/integration_tests/network/test_firewall.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/primaite/simulator/network/airspace.py b/src/primaite/simulator/network/airspace.py index 56cd1cc7..724b8728 100644 --- a/src/primaite/simulator/network/airspace.py +++ b/src/primaite/simulator/network/airspace.py @@ -292,7 +292,6 @@ class IPWirelessNetworkInterface(WirelessNetworkInterface, Layer3Interface, ABC) """ super().enable() try: - pass self._connected_node.default_gateway_hello() except AttributeError: pass diff --git a/tests/integration_tests/network/test_firewall.py b/tests/integration_tests/network/test_firewall.py index 349ccd85..846699f0 100644 --- a/tests/integration_tests/network/test_firewall.py +++ b/tests/integration_tests/network/test_firewall.py @@ -18,7 +18,7 @@ def dmz_external_internal_network() -> Network: Fixture for setting up a simulated network with a firewall, external node, internal node, and DMZ node. This configuration is designed to test firewall rules and their impact on traffic between these network segments. - -------------- -------------- -------------- + -------------- -------------- -------------- | external |---------| firewall |---------| internal | -------------- -------------- -------------- | From b277034e8b8d48afef97eccda9ccc213d9cdf0f8 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 13 Feb 2024 13:02:24 +0000 Subject: [PATCH 599/980] #2257: temporarily commit changes - added startup and shut down durations to node config + adding routes --- src/primaite/game/game.py | 14 ++- .../network/hardware/nodes/network/router.py | 8 ++ tests/assets/configs/dmz_network.yaml | 98 +++++++++++++------ .../router_game_configuration.py | 22 ++++- 4 files changed, 105 insertions(+), 37 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index c03bca36..3bc3789a 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -266,6 +266,10 @@ class PrimaiteGame: game.ref_map_services[service_ref] = new_service.uuid else: _LOGGER.warning(f"service type not found {service_type}") + + # start the service + new_service.start() + # service-dependent options if service_type == "DNSClient": if "options" in service_cfg: @@ -282,17 +286,14 @@ class PrimaiteGame: if "options" in service_cfg: opt = service_cfg["options"] new_service.configure_backup(backup_server=IPv4Address(opt.get("backup_server_ip"))) - new_service.start() if service_type == "FTPServer": if "options" in service_cfg: opt = service_cfg["options"] new_service.server_password = opt.get("server_password") - new_service.start() if service_type == "NTPClient": if "options" in service_cfg: opt = service_cfg["options"] new_service.ntp_server = IPv4Address(opt.get("ntp_server_ip")) - new_service.start() if "applications" in node_cfg: for application_cfg in node_cfg["applications"]: new_application = None @@ -306,6 +307,9 @@ class PrimaiteGame: else: _LOGGER.warning(f"application type not found {application_type}") + # run the application + new_application.run() + if application_type == "DataManipulationBot": if "options" in application_cfg: opt = application_cfg["options"] @@ -327,7 +331,6 @@ class PrimaiteGame: if "options" in application_cfg: opt = application_cfg["options"] new_application.target_url = opt.get("target_url") - elif application_type == "DoSBot": if "options" in application_cfg: opt = application_cfg["options"] @@ -344,6 +347,9 @@ class PrimaiteGame: for nic_num, nic_cfg in node_cfg["network_interfaces"].items(): new_node.connect_nic(NIC(ip_address=nic_cfg["ip_address"], subnet_mask=nic_cfg["subnet_mask"])) + new_node.start_up_duration = int(node_cfg.get("start_up_duration", 3)) + new_node.shut_down_duration = int(node_cfg.get("shut_down_duration", 3)) + net.add_node(new_node) new_node.power_on() game.ref_map_nodes[node_ref] = new_node.uuid diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 40cbc16d..f034fcbd 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1276,4 +1276,12 @@ class Router(NetworkNode): if "acl" in cfg: new.acl._default_config = cfg["acl"] # save the config to allow resetting new.acl._reset_rules_to_default() # read the config and apply rules + if "routes" in cfg: + for route in cfg.get("routes"): + new.route_table.add_route( + address=IPv4Address(route.get("address")), + subnet_mask=IPv4Address(route.get("subnet_mask")), + next_hop_ip_address=IPv4Address(route.get("subnet_mask")), + metric=float(route.get("metric")), + ) return new diff --git a/tests/assets/configs/dmz_network.yaml b/tests/assets/configs/dmz_network.yaml index ddf8fb36..0c67ba7c 100644 --- a/tests/assets/configs/dmz_network.yaml +++ b/tests/assets/configs/dmz_network.yaml @@ -9,26 +9,26 @@ # . -------------- -------------- -------------- . # . | client_1 |------| switch_1 |------| router_1 | . # . -------------- -------------- -------------- . -# . (Computer) | . -# ......................................................|..................... -# | -# | -# ......................................................|..................... -# . | . -# . DMZ Network | . -# . | . -# . -------------- -------------- -------------- . -# . | client_2 |------| switch_2 |------| router_2 | . -# . -------------- -------------- -------------- . -# . (Computer) | . -# ......................................................|..................... -# | -# External Network | -# | -# | -# ----------------------- -------------- --------------------- -# | external_computer |------| switch_3 |------| external_server | -# ----------------------- -------------- --------------------- +# . (Computer) | . +# ........................................................|..................... +# | +# | +# ........................................................|..................... +# . | . +# . DMZ Network | . +# . | . +# . ---------------- -------------- -------------- . +# . | dmz_server |------| switch_2 |------| router_2 | . +# . ---------------- -------------- -------------- . +# . (Computer) | . +# ........................................................|................... +# | +# External Network | +# | +# | +# ----------------------- -------------- --------------------- +# | external_computer |------| switch_3 |------| external_server | +# ----------------------- -------------- --------------------- # training_config: rl_framework: SB3 @@ -63,7 +63,7 @@ game: - UDP agents: - - ref: client_2_green_user + - ref: client_1_green_user team: GREEN type: GreenWebBrowsingAgent observation_space: @@ -74,7 +74,7 @@ agents: - type: NODE_APPLICATION_EXECUTE options: nodes: - - node_name: client_2 + - node_name: client_1 applications: - application_name: WebBrowser max_folders_per_node: 1 @@ -102,17 +102,23 @@ simulation: ip_address: 192.168.0.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.0.1 - dns_server: 192.168.20.10 + dns_server: 192.168.20.11 + start_up_duration: 0 + shut_down_duration: 0 - ref: switch_1 type: switch hostname: switch_1 num_ports: 8 + start_up_duration: 0 + shut_down_duration: 0 - ref: router_1 type: router hostname: router_1 num_ports: 5 + start_up_duration: 0 + shut_down_duration: 0 ports: 1: ip_address: 192.168.0.1 @@ -128,24 +134,43 @@ simulation: 23: action: PERMIT protocol: ICMP + routes: + - address: 192.168.10.10 + subnet_mask: 255.255.255.0 + next_hop_ip_address: 192.168.11.1 + metric: 0 + - address: 192.168.20.10 + subnet_mask: 255.255.255.0 + next_hop_ip_address: 192.168.11.1 + metric: 0 + - address: 192.168.20.11 + subnet_mask: 255.255.255.0 + next_hop_ip_address: 192.168.11.1 + metric: 0 - - ref: client_2 - type: computer - hostname: client_2 + - ref: dmz_server + type: server + hostname: dmz_server ip_address: 192.168.10.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 - dns_server: 192.168.20.10 + dns_server: 192.168.20.11 + start_up_duration: 0 + shut_down_duration: 0 - ref: switch_2 type: switch hostname: switch_2 num_ports: 8 + start_up_duration: 0 + shut_down_duration: 0 - ref: router_2 type: router hostname: router_2 num_ports: 5 + start_up_duration: 0 + shut_down_duration: 0 ports: 1: ip_address: 192.168.10.1 @@ -164,11 +189,18 @@ simulation: 23: action: PERMIT protocol: ICMP + routes: + - address: 192.168.0.10 + subnet_mask: 255.255.255.0 + next_hop_ip_address: 192.168.1.1 + metric: 0 - ref: switch_3 type: switch hostname: switch_3 num_ports: 8 + start_up_duration: 0 + shut_down_duration: 0 - ref: external_computer type: computer @@ -176,14 +208,18 @@ simulation: ip_address: 192.168.20.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.20.1 - dns_server: 192.168.20.10 + dns_server: 192.168.20.11 + start_up_duration: 0 + shut_down_duration: 0 - ref: external_server type: server hostname: external_server - ip_address: 192.168.20.10 + ip_address: 192.168.20.11 subnet_mask: 255.255.255.0 default_gateway: 192.168.20.1 + start_up_duration: 0 + shut_down_duration: 0 services: - ref: domain_controller_dns_server type: DNSServer @@ -208,8 +244,8 @@ simulation: endpoint_a_port: 1 endpoint_b_ref: switch_2 endpoint_b_port: 8 - - ref: client_2___switch_2 - endpoint_a_ref: client_2 + - ref: dmz_server___switch_2 + endpoint_a_ref: dmz_server endpoint_a_port: 1 endpoint_b_ref: switch_2 endpoint_b_port: 1 diff --git a/tests/integration_tests/configuration_file_parsing/router_game_configuration.py b/tests/integration_tests/configuration_file_parsing/router_game_configuration.py index 49b889d7..9d682dcc 100644 --- a/tests/integration_tests/configuration_file_parsing/router_game_configuration.py +++ b/tests/integration_tests/configuration_file_parsing/router_game_configuration.py @@ -5,6 +5,9 @@ import yaml from primaite.game.game import PrimaiteGame from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.router import Router from tests import TEST_ASSETS_ROOT DMZ_NETWORK = TEST_ASSETS_ROOT / "configs/dmz_network.yaml" @@ -27,12 +30,27 @@ def test_dmz_config(): assert len(network.nodes) == 9 # 9 nodes in network assert len(network.routers) == 2 # 2 routers in network assert len(network.switches) == 3 # 3 switches in network - assert len(network.servers) == 1 # 1 server in network + assert len(network.servers) == 2 # 2 servers in network def test_router_routes_are_correctly_added(): """Test that makes sure that router routes have been added from the configuration file.""" - pass + game = load_config(DMZ_NETWORK) + + network: Network = game.simulation.network + + router_1: Router = network.get_node_by_hostname("router_1") + client_1: Computer = network.get_node_by_hostname("client_1") + dmz_server: Server = network.get_node_by_hostname("dmz_server") + external_computer: Computer = network.get_node_by_hostname("external_computer") + external_server: Server = network.get_node_by_hostname("external_server") + + # test that client_1 has a route to the DMZ and external nodes - they are on a second router + + # there should be a route to the dmz server + assert router_1.route_table.find_best_route(dmz_server.network_interface[1].ip_address) + # ping DMZ server + # assert client_1.ping(dmz_server.network_interface[1].ip_address) def test_firewall_node_added_to_network(): From 07a934ab668b85d4ae87a9d0db52ff7080969d1e Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 14 Feb 2024 12:00:08 +0000 Subject: [PATCH 600/980] 2306: Update tests to verify INSERT query. --- tests/integration_tests/system/test_database_on_node.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index e015f9ee..ac0e65b4 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -101,6 +101,7 @@ def test_database_client_query(uc2_network): db_client.connect() assert db_client.query("SELECT") + assert db_client.query("INSERT") def test_create_database_backup(uc2_network): @@ -150,7 +151,7 @@ def test_database_client_cannot_query_offline_database_server(uc2_network): assert len(db_client.connections) assert db_client.query("SELECT") is True - + assert db_client.query("INSERT") is True db_server.power_off() for i in range(db_server.shut_down_duration + 1): @@ -160,3 +161,4 @@ def test_database_client_cannot_query_offline_database_server(uc2_network): assert db_service.operating_state is ServiceOperatingState.STOPPED assert db_client.query("SELECT") is False + assert db_client.query("INSERT") is False From 4a38672fea29b56b5f3bc72794072746bf79a5bc Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 14 Feb 2024 13:18:20 +0000 Subject: [PATCH 601/980] 2306: Handle INSERT query --- .../services/database/database_service.py | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index d75b4424..0b9554d5 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -189,7 +189,7 @@ class DatabaseService(Service): } def _process_sql( - self, query: Literal["SELECT", "DELETE"], query_id: str, connection_id: Optional[str] = None + self, query: Literal["SELECT", "DELETE", "INSERT"], query_id: str, connection_id: Optional[str] = None ) -> Dict[str, Union[int, List[Any]]]: """ Executes the given SQL query and returns the result. @@ -197,6 +197,7 @@ class DatabaseService(Service): Possible queries: - SELECT : returns the data - DELETE : deletes the data + - INSERT : inserts the data :param query: The SQL query to be executed. :return: Dictionary containing status code and data fetched. @@ -220,9 +221,27 @@ class DatabaseService(Service): return {"status_code": 404, "data": False} elif query == "DELETE": self.db_file.health_status = FileSystemItemHealthStatus.COMPROMISED - return {"status_code": 200, "type": "sql", "data": False, "uuid": query_id, "connection_id": connection_id} + return { + "status_code": 200, + "type": "sql", + "data": False, + "uuid": query_id, + "connection_id": connection_id, + } + elif query == "INSERT": + if self.health_state_actual == SoftwareHealthState.GOOD: + return { + "status_code": 200, + "type": "sql", + "data": False, + "uuid": query_id, + "connection_id": connection_id, + } + else: + return {"status_code": 404, "data": False} else: # Invalid query + self.sys_log.info(f"{self.name}: Invalid {query}") return {"status_code": 500, "data": False} def describe_state(self) -> Dict: From 8520f22e22de75768970a1b4dcadee0b5d389d2f Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 14 Feb 2024 13:35:08 +0000 Subject: [PATCH 602/980] 2306: Updated documentation --- CHANGELOG.md | 1 + .../simulation_components/system/database_client_server.rst | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc52a197..ce366d26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed a bug where the red agent acted to early - Fixed the order of service health state - Fixed an issue where starting a node didn't start the services on it +- Added support for SQL INSERT command. diff --git a/docs/source/simulation_components/system/database_client_server.rst b/docs/source/simulation_components/system/database_client_server.rst index 0b0dcc8e..07912f3e 100644 --- a/docs/source/simulation_components/system/database_client_server.rst +++ b/docs/source/simulation_components/system/database_client_server.rst @@ -17,7 +17,7 @@ Key capabilities - Creates a database file in the ``Node`` 's ``FileSystem`` upon creation. - Handles connecting clients by maintaining a dictionary of connections mapped to session IDs. - Authenticates connections using a configurable password. -- Simulates ``SELECT`` and ``DELETE`` SQL queries. +- Simulates ``SELECT``, ``DELETE`` and ``INSERT`` SQL queries. - Returns query results and status codes back to clients. - Leverages the Service base class for install/uninstall, status tracking, etc. From b7398233188ec12dcc11ed4a57c07f347e45d94f Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 15 Feb 2024 15:45:18 +0000 Subject: [PATCH 603/980] #2257: add firewall via config + fix router hop ip address + shuffling around tests --- src/primaite/game/game.py | 9 +- src/primaite/simulator/__init__.py | 4 +- .../hardware/nodes/network/firewall.py | 67 ++++++++++ .../network/hardware/nodes/network/router.py | 2 +- tests/assets/configs/dmz_network.yaml | 122 ++++++++++++------ tests/conftest.py | 19 +++ .../configuration_file_parsing/__init__.py | 19 +++ .../nodes/__init__.py | 0 .../nodes/network/__init__.py | 0 .../nodes/network/test_firewall_config.py | 45 +++++++ .../nodes/network/test_router_config.py | 54 ++++++++ .../nodes/test_node_config.py | 26 ++++ .../router_game_configuration.py | 76 ----------- ...software_installation_and_configuration.py | 52 +------- 14 files changed, 322 insertions(+), 173 deletions(-) create mode 100644 tests/integration_tests/configuration_file_parsing/nodes/__init__.py create mode 100644 tests/integration_tests/configuration_file_parsing/nodes/network/__init__.py create mode 100644 tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py create mode 100644 tests/integration_tests/configuration_file_parsing/nodes/network/test_router_config.py create mode 100644 tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py delete mode 100644 tests/integration_tests/configuration_file_parsing/router_game_configuration.py diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 3bc3789a..b860fb2a 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -15,6 +15,7 @@ from primaite.simulator.network.hardware.base import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.firewall import Firewall from primaite.simulator.network.hardware.nodes.network.router import Router from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.network.transmission.transport_layer import Port @@ -252,6 +253,8 @@ class PrimaiteGame: ) elif n_type == "router": new_node = Router.from_config(node_cfg) + elif n_type == "firewall": + new_node = Firewall.from_config(node_cfg) else: _LOGGER.warning(f"invalid node type {n_type} in config") if "services" in node_cfg: @@ -264,12 +267,12 @@ class PrimaiteGame: new_node.software_manager.install(SERVICE_TYPES_MAPPING[service_type]) new_service = new_node.software_manager.software[service_type] game.ref_map_services[service_ref] = new_service.uuid + + # start the service + new_service.start() else: _LOGGER.warning(f"service type not found {service_type}") - # start the service - new_service.start() - # service-dependent options if service_type == "DNSClient": if "options" in service_cfg: diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index 97bcd57b..aebd77cf 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -12,8 +12,8 @@ class _SimOutput: self._path: Path = ( _PRIMAITE_ROOT.parent.parent / "simulation_output" / datetime.now().strftime("%Y-%m-%d_%H-%M-%S") ) - self.save_pcap_logs: bool = True - self.save_sys_logs: bool = True + self.save_pcap_logs: bool = False + self.save_sys_logs: bool = False @property def path(self) -> Path: diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index 22effa2a..f48d0561 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -1,8 +1,10 @@ +from ipaddress import IPv4Address from typing import Dict, Final, Optional, Union from prettytable import MARKDOWN, PrettyTable from pydantic import validate_call +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.network.router import ( AccessControlList, ACLAction, @@ -491,3 +493,68 @@ class Firewall(Router): """ self.configure_port(DMZ_PORT_ID, ip_address, subnet_mask) self.dmz_port.enable() + + @classmethod + def from_config(cls, cfg: dict) -> "Firewall": + """Create a firewall based on a config dict.""" + new = Firewall(hostname=cfg["hostname"], operating_state=NodeOperatingState.ON) + if "ports" in cfg: + internal_port = cfg["ports"]["internal_port"] + external_port = cfg["ports"]["external_port"] + dmz_port = cfg["ports"]["dmz_port"] + + # configure internal port + new.configure_internal_port( + ip_address=IPV4Address(internal_port.get("ip_address")), + subnet_mask=IPV4Address(internal_port.get("subnet_mask")), + ) + + # configure external port + new.configure_external_port( + ip_address=IPV4Address(external_port.get("ip_address")), + subnet_mask=IPV4Address(external_port.get("subnet_mask")), + ) + + # configure dmz port + new.configure_dmz_port( + ip_address=IPV4Address(dmz_port.get("ip_address")), subnet_mask=IPV4Address(dmz_port.get("subnet_mask")) + ) + if "acl" in cfg: + # acl rules for internal_inbound_acl + if cfg["acl"]["internal_inbound_acl"]: + new.internal_inbound_acl._default_config = cfg["acl"]["internal_inbound_acl"] + new.internal_inbound_acl._reset_rules_to_default() + + # acl rules for internal_outbound_acl + if cfg["acl"]["internal_outbound_acl"]: + new.internal_outbound_acl._default_config = cfg["acl"]["internal_outbound_acl"] + new.internal_outbound_acl._reset_rules_to_default() + + # acl rules for dmz_inbound_acl + if cfg["acl"]["dmz_inbound_acl"]: + new.dmz_inbound_acl._default_config = cfg["acl"]["dmz_inbound_acl"] + new.dmz_inbound_acl._reset_rules_to_default() + + # acl rules for dmz_outbound_acl + if cfg["acl"]["dmz_outbound_acl"]: + new.dmz_outbound_acl._default_config = cfg["acl"]["dmz_outbound_acl"] + new.dmz_outbound_acl._reset_rules_to_default() + + # acl rules for external_inbound_acl + if cfg["acl"]["external_inbound_acl"]: + new.external_inbound_acl._default_config = cfg["acl"]["external_inbound_acl"] + new.external_inbound_acl._reset_rules_to_default() + + # acl rules for external_outbound_acl + if cfg["acl"]["external_outbound_acl"]: + new.external_outbound_acl._default_config = cfg["acl"]["external_outbound_acl"] + new.external_outbound_acl._reset_rules_to_default() + if "routes" in cfg: + for route in cfg.get("routes"): + new.route_table.add_route( + address=IPv4Address(route.get("address")), + subnet_mask=IPv4Address(route.get("subnet_mask")), + next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")), + metric=float(route.get("metric")), + ) + return new diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index fd18ce70..d52028a8 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1500,7 +1500,7 @@ class Router(NetworkNode): new.route_table.add_route( address=IPv4Address(route.get("address")), subnet_mask=IPv4Address(route.get("subnet_mask")), - next_hop_ip_address=IPv4Address(route.get("subnet_mask")), + next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")), metric=float(route.get("metric")), ) return new diff --git a/tests/assets/configs/dmz_network.yaml b/tests/assets/configs/dmz_network.yaml index 0c67ba7c..1a099e41 100644 --- a/tests/assets/configs/dmz_network.yaml +++ b/tests/assets/configs/dmz_network.yaml @@ -6,19 +6,19 @@ # . . # . Internal Network . # . . -# . -------------- -------------- -------------- . -# . | client_1 |------| switch_1 |------| router_1 | . -# . -------------- -------------- -------------- . +# . -------------- -------------- -------------- . +# . | client_1 |------| switch_1 |--------| router_1 | . +# . -------------- -------------- -------------- . # . (Computer) | . -# ........................................................|..................... +# ........................................................|................... # | # | -# ........................................................|..................... +# ........................................................|................... # . | . # . DMZ Network | . # . | . # . ---------------- -------------- -------------- . -# . | dmz_server |------| switch_2 |------| router_2 | . +# . | dmz_server |------| switch_2 |------| firewall | . # . ---------------- -------------- -------------- . # . (Computer) | . # ........................................................|................... @@ -135,17 +135,17 @@ simulation: action: PERMIT protocol: ICMP routes: - - address: 192.168.10.10 + - address: 192.168.10.10 # route to dmz_server subnet_mask: 255.255.255.0 - next_hop_ip_address: 192.168.11.1 + next_hop_ip_address: 192.168.1.2 metric: 0 - - address: 192.168.20.10 + - address: 192.168.20.10 # route to external_computer subnet_mask: 255.255.255.0 - next_hop_ip_address: 192.168.11.1 + next_hop_ip_address: 192.168.1.2 metric: 0 - - address: 192.168.20.11 + - address: 192.168.20.11 # route to external_server subnet_mask: 255.255.255.0 - next_hop_ip_address: 192.168.11.1 + next_hop_ip_address: 192.168.1.2 metric: 0 - ref: dmz_server @@ -165,32 +165,72 @@ simulation: start_up_duration: 0 shut_down_duration: 0 - - ref: router_2 - type: router - hostname: router_2 - num_ports: 5 + - ref: firewall + type: firewall + hostname: firewall start_up_duration: 0 shut_down_duration: 0 ports: - 1: - ip_address: 192.168.10.1 - subnet_mask: 255.255.255.0 - 2: - ip_address: 192.168.11.1 - subnet_mask: 255.255.255.0 - 3: + external_port: # port 1 ip_address: 192.168.20.1 subnet_mask: 255.255.255.0 + internal_port: # port 2 + ip_address: 192.168.1.2 + subnet_mask: 255.255.255.0 + dmz_port: # port 3 + ip_address: 192.168.10.1 + subnet_mask: 255.255.255.0 acl: - 22: - action: PERMIT - src_port: ARP - dst_port: ARP - 23: - action: PERMIT - protocol: ICMP + internal_inbound_acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + internal_outbound_acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + dmz_inbound_acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + dmz_outbound_acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + external_inbound_acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + external_outbound_acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP routes: - - address: 192.168.0.10 + - address: 192.168.0.10 # route to client_1 subnet_mask: 255.255.255.0 next_hop_ip_address: 192.168.1.1 metric: 0 @@ -234,14 +274,14 @@ simulation: endpoint_a_port: 1 endpoint_b_ref: switch_1 endpoint_b_port: 8 - - ref: router_1___router_2 - endpoint_a_ref: router_1 - endpoint_a_port: 2 - endpoint_b_ref: router_2 + - ref: router_1___firewall + endpoint_a_ref: firewall + endpoint_a_port: 2 # internal firewall port + endpoint_b_ref: router_1 endpoint_b_port: 2 - - ref: router_2___switch_2 - endpoint_a_ref: router_2 - endpoint_a_port: 1 + - ref: firewall___switch_2 + endpoint_a_ref: firewall + endpoint_a_port: 3 # dmz firewall port endpoint_b_ref: switch_2 endpoint_b_port: 8 - ref: dmz_server___switch_2 @@ -249,9 +289,9 @@ simulation: endpoint_a_port: 1 endpoint_b_ref: switch_2 endpoint_b_port: 1 - - ref: router_2___switch_3 - endpoint_a_ref: router_2 - endpoint_a_port: 3 + - ref: firewall___switch_3 + endpoint_a_ref: firewall + endpoint_a_port: 1 # external firewall port endpoint_b_ref: switch_3 endpoint_b_port: 8 - ref: external_computer___switch_3 diff --git a/tests/conftest.py b/tests/conftest.py index 5084c339..ada89026 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,11 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +from datetime import datetime from pathlib import Path from typing import Any, Dict, Tuple, Union import pytest import yaml +from _pytest.monkeypatch import MonkeyPatch from primaite import getLogger, PRIMAITE_PATHS from primaite.game.agent.actions import ActionManager @@ -12,6 +14,7 @@ from primaite.game.agent.observations import ICSObservation, ObservationManager from primaite.game.agent.rewards import RewardFunction from primaite.game.game import PrimaiteGame from primaite.session.session import PrimaiteSession +from primaite.simulator import SIM_OUTPUT from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.host.computer import Computer @@ -29,6 +32,7 @@ from primaite.simulator.system.services.dns.dns_client import DNSClient from primaite.simulator.system.services.dns.dns_server import DNSServer from primaite.simulator.system.services.service import Service from primaite.simulator.system.services.web_server.web_server import WebServer +from tests import TEST_ASSETS_ROOT from tests.mock_and_patch.get_session_path_mock import temp_user_sessions_path ACTION_SPACE_NODE_VALUES = 1 @@ -37,6 +41,21 @@ ACTION_SPACE_NODE_ACTION_VALUES = 1 _LOGGER = getLogger(__name__) +@pytest.fixture(scope="function", autouse=True) +def set_syslog_output_to_true(): + """Will be run before each test.""" + monkeypatch = MonkeyPatch() + monkeypatch.setattr( + SIM_OUTPUT, + "path", + Path(TEST_ASSETS_ROOT.parent.parent / "simulation_output" / datetime.now().strftime("%Y-%m-%d_%H-%M-%S")), + ) + monkeypatch.setattr(SIM_OUTPUT, "save_pcap_logs", True) + monkeypatch.setattr(SIM_OUTPUT, "save_sys_logs", True) + + yield + + class TestService(Service): """Test Service class""" diff --git a/tests/integration_tests/configuration_file_parsing/__init__.py b/tests/integration_tests/configuration_file_parsing/__init__.py index e69de29b..1c8481d6 100644 --- a/tests/integration_tests/configuration_file_parsing/__init__.py +++ b/tests/integration_tests/configuration_file_parsing/__init__.py @@ -0,0 +1,19 @@ +from pathlib import Path +from typing import Union + +import yaml + +from primaite.game.game import PrimaiteGame +from tests import TEST_ASSETS_ROOT + +BASIC_CONFIG = TEST_ASSETS_ROOT / "configs/basic_switched_network.yaml" + +DMZ_NETWORK = TEST_ASSETS_ROOT / "configs/dmz_network.yaml" + + +def load_config(config_path: Union[str, Path]) -> PrimaiteGame: + """Returns a PrimaiteGame object which loads the contents of a given yaml path.""" + with open(config_path, "r") as f: + cfg = yaml.safe_load(f) + + return PrimaiteGame.from_config(cfg) diff --git a/tests/integration_tests/configuration_file_parsing/nodes/__init__.py b/tests/integration_tests/configuration_file_parsing/nodes/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration_tests/configuration_file_parsing/nodes/network/__init__.py b/tests/integration_tests/configuration_file_parsing/nodes/network/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py b/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py new file mode 100644 index 00000000..65fe8c6d --- /dev/null +++ b/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py @@ -0,0 +1,45 @@ +import pytest + +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.firewall import Firewall +from tests.integration_tests.configuration_file_parsing import DMZ_NETWORK, load_config + + +@pytest.fixture(scope="function") +def dmz_config() -> Network: + game = load_config(DMZ_NETWORK) + return game.simulation.network + + +def test_firewall_is_in_configuration(dmz_config): + """Test that the firewall exists in the configuration file.""" + network: Network = dmz_config + + assert network.get_node_by_hostname("firewall") + + +def test_firewall_routes_are_correctly_added(dmz_config): + """Test that the firewall routes have been correctly added to and configured in the network.""" + network: Network = dmz_config + + firewall: Firewall = network.get_node_by_hostname("firewall") + client_1: Computer = network.get_node_by_hostname("client_1") + dmz_server: Server = network.get_node_by_hostname("dmz_server") + external_computer: Computer = network.get_node_by_hostname("external_computer") + external_server: Server = network.get_node_by_hostname("external_server") + + # there should be a route to client_1 + assert firewall.route_table.find_best_route(client_1.network_interface[1].ip_address) + assert dmz_server.ping(client_1.network_interface[1].ip_address) + assert external_computer.ping(client_1.network_interface[1].ip_address) + assert external_server.ping(client_1.network_interface[1].ip_address) + + +def test_firewall_acl_rules_correctly_added(): + """ + Test that makes sure that the firewall ACLs have been configured onto the firewall + node via configuration file. + """ + pass diff --git a/tests/integration_tests/configuration_file_parsing/nodes/network/test_router_config.py b/tests/integration_tests/configuration_file_parsing/nodes/network/test_router_config.py new file mode 100644 index 00000000..d09d2e94 --- /dev/null +++ b/tests/integration_tests/configuration_file_parsing/nodes/network/test_router_config.py @@ -0,0 +1,54 @@ +import pytest + +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.router import Router +from tests.integration_tests.configuration_file_parsing import DMZ_NETWORK, load_config + + +@pytest.fixture(scope="function") +def dmz_config() -> Network: + game = load_config(DMZ_NETWORK) + return game.simulation.network + + +def test_router_is_in_configuration(dmz_config): + """Test that the router exists in the configuration file.""" + network: Network = dmz_config + + assert network.get_node_by_hostname("router_1") + + +def test_router_routes_are_correctly_added(dmz_config): + """Test that makes sure that router routes have been added from the configuration file.""" + network: Network = dmz_config + + router_1: Router = network.get_node_by_hostname("router_1") + client_1: Computer = network.get_node_by_hostname("client_1") + dmz_server: Server = network.get_node_by_hostname("dmz_server") + external_computer: Computer = network.get_node_by_hostname("external_computer") + external_server: Server = network.get_node_by_hostname("external_server") + + # there should be a route to dmz_server + assert router_1.route_table.find_best_route(dmz_server.network_interface[1].ip_address) + assert client_1.ping(dmz_server.network_interface[1].ip_address) + assert external_computer.ping(dmz_server.network_interface[1].ip_address) + assert external_server.ping(dmz_server.network_interface[1].ip_address) + + # there should be a route to external_computer + assert router_1.route_table.find_best_route(external_computer.network_interface[1].ip_address) + assert client_1.ping(external_computer.network_interface[1].ip_address) + assert dmz_server.ping(external_computer.network_interface[1].ip_address) + assert external_server.ping(external_computer.network_interface[1].ip_address) + + # there should be a route to external_server + assert router_1.route_table.find_best_route(external_server.network_interface[1].ip_address) + assert client_1.ping(external_server.network_interface[1].ip_address) + assert dmz_server.ping(external_server.network_interface[1].ip_address) + assert external_computer.ping(external_server.network_interface[1].ip_address) + + +def test_router_acl_rules_correctly_added(): + """Test that makes sure that the router ACLs have been configured onto the router node via configuration file.""" + pass diff --git a/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py b/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py new file mode 100644 index 00000000..e222bfaf --- /dev/null +++ b/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py @@ -0,0 +1,26 @@ +from primaite.config.load import example_config_path +from primaite.simulator.network.container import Network +from tests.integration_tests.configuration_file_parsing import DMZ_NETWORK, load_config + + +def test_example_config(): + """Test that the example config can be parsed properly.""" + game = load_config(example_config_path()) + network: Network = game.simulation.network + + assert len(network.nodes) == 10 # 10 nodes in example network + assert len(network.routers) == 1 # 1 router in network + assert len(network.switches) == 2 # 2 switches in network + assert len(network.servers) == 5 # 5 servers in network + + +def test_dmz_config(): + """Test that the DMZ network config can be parsed properly.""" + game = load_config(DMZ_NETWORK) + + network: Network = game.simulation.network + + assert len(network.nodes) == 9 # 9 nodes in network + assert len(network.routers) == 2 # 2 routers in network + assert len(network.switches) == 3 # 3 switches in network + assert len(network.servers) == 2 # 2 servers in network diff --git a/tests/integration_tests/configuration_file_parsing/router_game_configuration.py b/tests/integration_tests/configuration_file_parsing/router_game_configuration.py deleted file mode 100644 index 9d682dcc..00000000 --- a/tests/integration_tests/configuration_file_parsing/router_game_configuration.py +++ /dev/null @@ -1,76 +0,0 @@ -from pathlib import Path -from typing import Union - -import yaml - -from primaite.game.game import PrimaiteGame -from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.nodes.host.computer import Computer -from primaite.simulator.network.hardware.nodes.host.server import Server -from primaite.simulator.network.hardware.nodes.network.router import Router -from tests import TEST_ASSETS_ROOT - -DMZ_NETWORK = TEST_ASSETS_ROOT / "configs/dmz_network.yaml" - - -def load_config(config_path: Union[str, Path]) -> PrimaiteGame: - """Returns a PrimaiteGame object which loads the contents of a given yaml path.""" - with open(config_path, "r") as f: - cfg = yaml.safe_load(f) - - return PrimaiteGame.from_config(cfg) - - -def test_dmz_config(): - """Test that the DMZ network config can be parsed properly.""" - game = load_config(DMZ_NETWORK) - - network: Network = game.simulation.network - - assert len(network.nodes) == 9 # 9 nodes in network - assert len(network.routers) == 2 # 2 routers in network - assert len(network.switches) == 3 # 3 switches in network - assert len(network.servers) == 2 # 2 servers in network - - -def test_router_routes_are_correctly_added(): - """Test that makes sure that router routes have been added from the configuration file.""" - game = load_config(DMZ_NETWORK) - - network: Network = game.simulation.network - - router_1: Router = network.get_node_by_hostname("router_1") - client_1: Computer = network.get_node_by_hostname("client_1") - dmz_server: Server = network.get_node_by_hostname("dmz_server") - external_computer: Computer = network.get_node_by_hostname("external_computer") - external_server: Server = network.get_node_by_hostname("external_server") - - # test that client_1 has a route to the DMZ and external nodes - they are on a second router - - # there should be a route to the dmz server - assert router_1.route_table.find_best_route(dmz_server.network_interface[1].ip_address) - # ping DMZ server - # assert client_1.ping(dmz_server.network_interface[1].ip_address) - - -def test_firewall_node_added_to_network(): - """Test that the firewall has been correctly added to and configured in the network.""" - pass - - -def test_router_acl_rules_correctly_added(): - """Test that makes sure that the router ACLs have been configured onto the router node via configuration file.""" - pass - - -def test_firewall_routes_are_correctly_added(): - """Test that the firewall routes have been correctly added to and configured in the network.""" - pass - - -def test_firewall_acl_rules_correctly_added(): - """ - Test that makes sure that the firewall ACLs have been configured onto the firewall - node via configuration file. - """ - pass diff --git a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py index 3bd870e3..54dca371 100644 --- a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py +++ b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py @@ -1,14 +1,6 @@ from ipaddress import IPv4Address -from pathlib import Path -from typing import Union -import yaml - -from primaite.config.load import example_config_path -from primaite.game.agent.data_manipulation_bot import DataManipulationAgent -from primaite.game.agent.interface import ProxyAgent, RandomAgent -from primaite.game.game import APPLICATION_TYPES_MAPPING, PrimaiteGame, SERVICE_TYPES_MAPPING -from primaite.simulator.network.container import Network +from primaite.game.game import APPLICATION_TYPES_MAPPING, SERVICE_TYPES_MAPPING from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot @@ -22,47 +14,7 @@ from primaite.simulator.system.services.ftp.ftp_server import FTPServer from primaite.simulator.system.services.ntp.ntp_client import NTPClient from primaite.simulator.system.services.ntp.ntp_server import NTPServer from primaite.simulator.system.services.web_server.web_server import WebServer -from tests import TEST_ASSETS_ROOT - -BASIC_CONFIG = TEST_ASSETS_ROOT / "configs/basic_switched_network.yaml" - - -def load_config(config_path: Union[str, Path]) -> PrimaiteGame: - """Returns a PrimaiteGame object which loads the contents of a given yaml path.""" - with open(config_path, "r") as f: - cfg = yaml.safe_load(f) - - return PrimaiteGame.from_config(cfg) - - -def test_example_config(): - """Test that the example config can be parsed properly.""" - game = load_config(example_config_path()) - - assert len(game.agents) == 4 # red, blue and 2 green agents - - # green agent 1 - assert game.agents[0].agent_name == "client_2_green_user" - assert isinstance(game.agents[0], RandomAgent) - - # green agent 2 - assert game.agents[1].agent_name == "client_1_green_user" - assert isinstance(game.agents[1], RandomAgent) - - # red agent - assert game.agents[2].agent_name == "client_1_data_manipulation_red_bot" - assert isinstance(game.agents[2], DataManipulationAgent) - - # blue agent - assert game.agents[3].agent_name == "defender" - assert isinstance(game.agents[3], ProxyAgent) - - network: Network = game.simulation.network - - assert len(network.nodes) == 10 # 10 nodes in example network - assert len(network.routers) == 1 # 1 router in network - assert len(network.switches) == 2 # 2 switches in network - assert len(network.servers) == 5 # 5 servers in network +from tests.integration_tests.configuration_file_parsing import BASIC_CONFIG, load_config def test_node_software_install(): From e390d8385c9f5e54dd3c6a929c1557c4b6c38e44 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 15 Feb 2024 16:29:36 +0000 Subject: [PATCH 604/980] #2257: acl tests --- tests/assets/configs/dmz_network.yaml | 6 -- .../nodes/network/test_firewall_config.py | 61 ++++++++++++++++++- .../nodes/network/test_router_config.py | 17 +++++- 3 files changed, 73 insertions(+), 11 deletions(-) diff --git a/tests/assets/configs/dmz_network.yaml b/tests/assets/configs/dmz_network.yaml index 1a099e41..971ed8cd 100644 --- a/tests/assets/configs/dmz_network.yaml +++ b/tests/assets/configs/dmz_network.yaml @@ -218,17 +218,11 @@ simulation: action: PERMIT src_port: ARP dst_port: ARP - 23: - action: PERMIT - protocol: ICMP external_outbound_acl: 22: action: PERMIT src_port: ARP dst_port: ARP - 23: - action: PERMIT - protocol: ICMP routes: - address: 192.168.0.10 # route to client_1 subnet_mask: 255.255.255.0 diff --git a/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py b/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py index 65fe8c6d..ae71809b 100644 --- a/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py +++ b/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py @@ -4,6 +4,9 @@ from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.hardware.nodes.network.firewall import Firewall +from primaite.simulator.network.hardware.nodes.network.router import ACLAction +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port from tests.integration_tests.configuration_file_parsing import DMZ_NETWORK, load_config @@ -37,9 +40,63 @@ def test_firewall_routes_are_correctly_added(dmz_config): assert external_server.ping(client_1.network_interface[1].ip_address) -def test_firewall_acl_rules_correctly_added(): +def test_firewall_acl_rules_correctly_added(dmz_config): """ Test that makes sure that the firewall ACLs have been configured onto the firewall node via configuration file. """ - pass + firewall: Firewall = dmz_config.get_node_by_hostname("firewall") + + # ICMP and ARP should be allowed internal_inbound + assert firewall.internal_inbound_acl.num_rules == 2 + assert firewall.internal_inbound_acl.acl[22].action == ACLAction.PERMIT + assert firewall.internal_inbound_acl.acl[22].src_port == Port.ARP + assert firewall.internal_inbound_acl.acl[22].dst_port == Port.ARP + assert firewall.internal_inbound_acl.acl[23].action == ACLAction.PERMIT + assert firewall.internal_inbound_acl.acl[23].protocol == IPProtocol.ICMP + assert firewall.internal_inbound_acl.implicit_action == ACLAction.DENY + + # ICMP and ARP should be allowed internal_outbound + assert firewall.internal_outbound_acl.num_rules == 2 + assert firewall.internal_outbound_acl.acl[22].action == ACLAction.PERMIT + assert firewall.internal_outbound_acl.acl[22].src_port == Port.ARP + assert firewall.internal_outbound_acl.acl[22].dst_port == Port.ARP + assert firewall.internal_outbound_acl.acl[23].action == ACLAction.PERMIT + assert firewall.internal_outbound_acl.acl[23].protocol == IPProtocol.ICMP + assert firewall.internal_outbound_acl.implicit_action == ACLAction.DENY + + # ICMP and ARP should be allowed dmz_inbound + assert firewall.dmz_inbound_acl.num_rules == 2 + assert firewall.dmz_inbound_acl.acl[22].action == ACLAction.PERMIT + assert firewall.dmz_inbound_acl.acl[22].src_port == Port.ARP + assert firewall.dmz_inbound_acl.acl[22].dst_port == Port.ARP + assert firewall.dmz_inbound_acl.acl[23].action == ACLAction.PERMIT + assert firewall.dmz_inbound_acl.acl[23].protocol == IPProtocol.ICMP + assert firewall.dmz_inbound_acl.implicit_action == ACLAction.DENY + + # ICMP and ARP should be allowed dmz_outbound + assert firewall.dmz_outbound_acl.num_rules == 2 + assert firewall.dmz_outbound_acl.acl[22].action == ACLAction.PERMIT + assert firewall.dmz_outbound_acl.acl[22].src_port == Port.ARP + assert firewall.dmz_outbound_acl.acl[22].dst_port == Port.ARP + assert firewall.dmz_outbound_acl.acl[23].action == ACLAction.PERMIT + assert firewall.dmz_outbound_acl.acl[23].protocol == IPProtocol.ICMP + assert firewall.dmz_outbound_acl.implicit_action == ACLAction.DENY + + # ICMP and ARP should be allowed external_inbound + assert firewall.external_inbound_acl.num_rules == 1 + assert firewall.external_inbound_acl.acl[22].action == ACLAction.PERMIT + assert firewall.external_inbound_acl.acl[22].src_port == Port.ARP + assert firewall.external_inbound_acl.acl[22].dst_port == Port.ARP + # external_inbound should have implicit action PERMIT + # ICMP does not have a provided ACL Rule but implicit action should allow anything + assert firewall.external_inbound_acl.implicit_action == ACLAction.PERMIT + + # ICMP and ARP should be allowed external_outbound + assert firewall.external_outbound_acl.num_rules == 1 + assert firewall.external_outbound_acl.acl[22].action == ACLAction.PERMIT + assert firewall.external_outbound_acl.acl[22].src_port == Port.ARP + assert firewall.external_outbound_acl.acl[22].dst_port == Port.ARP + # external_outbound should have implicit action PERMIT + # ICMP does not have a provided ACL Rule but implicit action should allow anything + assert firewall.external_outbound_acl.implicit_action == ACLAction.PERMIT diff --git a/tests/integration_tests/configuration_file_parsing/nodes/network/test_router_config.py b/tests/integration_tests/configuration_file_parsing/nodes/network/test_router_config.py index d09d2e94..fbaca12d 100644 --- a/tests/integration_tests/configuration_file_parsing/nodes/network/test_router_config.py +++ b/tests/integration_tests/configuration_file_parsing/nodes/network/test_router_config.py @@ -3,7 +3,9 @@ import pytest from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.server import Server -from primaite.simulator.network.hardware.nodes.network.router import Router +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port from tests.integration_tests.configuration_file_parsing import DMZ_NETWORK, load_config @@ -49,6 +51,15 @@ def test_router_routes_are_correctly_added(dmz_config): assert external_computer.ping(external_server.network_interface[1].ip_address) -def test_router_acl_rules_correctly_added(): +def test_router_acl_rules_correctly_added(dmz_config): """Test that makes sure that the router ACLs have been configured onto the router node via configuration file.""" - pass + router_1: Router = dmz_config.get_node_by_hostname("router_1") + + # ICMP and ARP should be allowed + assert router_1.acl.num_rules == 2 + assert router_1.acl.acl[22].action == ACLAction.PERMIT + assert router_1.acl.acl[22].src_port == Port.ARP + assert router_1.acl.acl[22].dst_port == Port.ARP + assert router_1.acl.acl[23].action == ACLAction.PERMIT + assert router_1.acl.acl[23].protocol == IPProtocol.ICMP + assert router_1.acl.implicit_action == ACLAction.DENY From 317fbdbb9c23f2a4c34111f0f3f2a89927c8823f Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 16 Feb 2024 12:46:36 +0000 Subject: [PATCH 605/980] 2230: Version bump --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index 43662e8c..fa7f84f1 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0b6 +3.0.0b7dev From 2e2d83c3e9775d1ba87f717abd0cba4937c37534 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 16 Feb 2024 16:14:36 +0000 Subject: [PATCH 606/980] #2257: update sphinx version + cleaning up some errors + splitting configuration page into multiple pages --- docs/api.rst | 2 + docs/conf.py | 11 +- docs/source/config.rst | 105 ++---------------- docs/source/configuration/agents.rst | 45 ++++++++ docs/source/configuration/game.rst | 8 ++ docs/source/configuration/io_settings.rst | 26 +++++ docs/source/configuration/simulation.rst | 27 +++++ docs/source/configuration/training_config.rst | 25 +++++ docs/source/dependencies.rst | 2 + docs/source/request_system.rst | 4 +- docs/source/simulation.rst | 2 +- .../network/base_hardware.rst | 59 ++++++++++ .../simulation_components/system/software.rst | 1 + docs/source/state_system.rst | 2 +- pyproject.toml | 4 +- 15 files changed, 220 insertions(+), 103 deletions(-) create mode 100644 docs/source/configuration/agents.rst create mode 100644 docs/source/configuration/game.rst create mode 100644 docs/source/configuration/io_settings.rst create mode 100644 docs/source/configuration/simulation.rst create mode 100644 docs/source/configuration/training_config.rst diff --git a/docs/api.rst b/docs/api.rst index aeaef4e2..13f3a1ec 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1,3 +1,5 @@ +:orphan: + .. only:: comment © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK diff --git a/docs/conf.py b/docs/conf.py index efd60b49..6cdc0ac4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,7 +15,6 @@ import furo # noqa sys.path.insert(0, os.path.abspath("../")) - # -- Project information ----------------------------------------------------- year = datetime.datetime.now().year project = "PrimAITE" @@ -45,13 +44,17 @@ extensions = [ "sphinx_copybutton", # Adds a copy button to code blocks ] - templates_path = ["_templates"] -exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] - +exclude_patterns = [ + "_build", + "Thumbs.db", + ".DS_Store", +] # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output html_theme = "furo" html_static_path = ["_static"] +html_theme_options = {"globaltoc_collapse": True, "globaltoc_maxdepth": 2} +html_copy_source = False diff --git a/docs/source/config.rst b/docs/source/config.rst index 575a3139..46631ab9 100644 --- a/docs/source/config.rst +++ b/docs/source/config.rst @@ -1,3 +1,7 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + Primaite v3 config ****************** @@ -5,98 +9,13 @@ PrimAITE uses a single configuration file to define everything needed to train a The entire config is used by the ``PrimaiteSession`` object for users who wish to let PrimAITE handle the agent definition and training. If you wish to define custom agents and control the training loop yourself, you can use the config with the ``PrimaiteGame``, and ``PrimaiteGymEnv`` objects instead. That way, only the network configuration and agent setup parts of the config are used, and the training section is ignored. Configurable items -================== +################## -``training_config`` -------------------- -This section allows selecting which training framework and algorithm to use, and set some training hyperparameters. +.. toctree:: + :maxdepth: 1 -``io_settings`` ---------------- -This section configures how PrimAITE saves data during simulation and training. - -**save_final_model**: Only used if training with PrimaiteSession, if true, the policy will be saved after the final training iteration. - -**save_checkpoints**: Only used if training with PrimaiteSession, if true, the policy will be saved periodically during training. - -**checkpoint_interval**: Only used if training with PrimaiteSession and if ``save_checkpoints`` is true. Defines how often to save the policy during training. - -**save_logs**: *currently unused*. - -**save_transactions**: *currently unused*. - -**save_tensorboard_logs**: *currently unused*. - -**save_step_metadata**: Whether to save the RL agents' action, environment state, and other data at every single step. - -**save_pcap_logs**: Whether to save pcap files of all network traffic during the simulation. - -**save_sys_logs**: Whether to save system logs from all nodes during the simulation. - -``game`` --------- -This section defines high-level settings that apply across the game, currently it's used to help shape the action and observation spaces by restricting which ports and internet protocols should be considered. Here, users can also set the maximum number of steps in an episode. - -``agents`` ----------- -Agents can be scripted (deterministic and stochastic), or controlled by a reinforcement learning algorithm. Not to be confused with an RL agent, the term agent here is used to refer to an entity that sends requests to the simulated network. In this part of the config, each agent's action space, observation space, and reward function can be defined. All three are defined in a modular way. - -**type**: Specifies which class should be used for the agent. ``ProxyAgent`` is used for agents that receive instructions from an RL algorithm. Scripted agents like ``RedDatabaseCorruptingAgent`` and ``GreenWebBrowsingAgent`` generate their own behaviour. - -**team**: Specifies if the agent is malicious (RED), benign (GREEN), or defensive (BLUE). Currently this value is not used for anything. - -**observation space:** - * ``type``: selects which python class from the ``primaite.game.agent.observation`` module is used for the overall observation structure. - * ``options``: allows configuring the chosen observation type. The ``UC2BlueObservation`` should be used for RL Agents. - * ``num_services_per_node``, ``num_folders_per_node``, ``num_files_per_folder``, ``num_nics_per_node`` all define the shape of the observation space. The size and shape of the obs space must remain constant, but the number of files, folders, ACL rules, and other components can change within an episode. Therefore padding is performed and these options set the size of the obs space. - * ``nodes``: list of nodes that will be present in this agent's observation space. The ``node_ref`` relates to the human-readable unique reference defined later in the ``simulation`` part of the config. Each node can also be configured with services, and files that should be monitored. - * ``links``: list of links that will be present in this agent's observation space. The ``link_ref`` relates to the human-readable unique reference defined later in the ``simulation`` part of the config. - * ``acl``: configure how the agent reads the access control list on the router in the simulation. ``router_node_ref`` is for selecting which router's ACL table should be used. ``ip_address_order`` sets the encoding of ip addresses as integers within the observation space. - -**action space:** -The action space is configured to be made up of individual action types. Once configured, the agent can select an action type and some optional action parameters at every step. For example: The ``NODE_SERVICE_SCAN`` action takes the parameters ``node_id`` and ``service_id``. - -Description of configurable items: - * ``action_list``: a list of action modules. The options are listed in the ``primaite.game.agent.actions`` module. - * ``action_map``: (optional). Restricts the possible combinations of action type / action parameter values to reduce the overall size of the action space. By default, every possible combination of actions and parameters will be assigned an integer for the agent's ``MultiDiscrete`` action space. Instead, the ``action_map`` allows you to list the actions corresponding to each integer in the ``MultiDiscrete`` space. - * ``options``: Options that apply too all action components. - * ``nodes``: list the nodes that the agent can act on, the order of this list defines the mapping between nodes and ``node_id`` integers. - * ``max_folders_per_node``, ``max_files_per_folder``, ``max_services_per_node``, ``max_nics_per_node``, ``max_acl_rules`` all are used to define the size of the action space. - -**reward function:** -Similar to action space, this is defined as a list of components. - -Description of configurable items: - * ``reward_components`` a list of reward components from the ``primaite.game.agent.reward`` module. - * ``weight``: relative importance of this reward component. The total reward for a step is a weighted sum of all reward components. - * ``options``: list of options passed to the reward component during initialisation, the exact options required depend on the reward component. - -**agent_settings**: -Settings passed to the agent during initialisation. These depend on the agent class. - -Reinforcement learning agents use the ``ProxyAgent`` class, they accept these agent settings: - -**flatten_obs**: If true, gymnasium flattening will be performed on the observation space before sending to the agent. Set this to true if your agent does not support nested observation spaces. - -``simulation`` --------------- -In this section the network layout is defined. This part of the config follows a hierarchical structure. Almost every component defines a ``ref`` field which acts as a human-readable unique identifier, used by other parts of the config, such as agents. - -At the top level of the network are ``nodes`` and ``links``. - -**nodes:** - * ``type``: one of ``router``, ``switch``, ``computer``, or ``server``, this affects what other sub-options should be defined. - * ``hostname`` - a non-unique name used for logging and outputs. - * ``num_ports`` (optional, routers and switches only): number of network interfaces present on the device. - * ``ports`` (optional, routers and switches only): configuration for each network interface, including IP address and subnet mask. - * ``acl`` (Router only): Define the ACL rules at each index of the ACL on the router. the possible options are: ``action`` (PERMIT or DENY), ``src_port``, ``dst_port``, ``protocol``, ``src_ip``, ``dst_ip``. Any options left blank default to none which usually means that it will apply across all options. For example leaving ``src_ip`` blank will apply the rule to all IP addresses. - * ``services`` (computers and servers only): a list of services to install on the node. They must define a ``ref``, ``type``, and ``options`` that depend on which ``type`` was selected. - * ``applications`` (computer and servers only): Similar to services. A list of application to install on the node. - * ``network_interfaces`` (computers and servers only): If the node has multiple networking devices, the second, third, fourth, etc... must be defined here with an ``ip_address`` and ``subnet_mask``. - -**links:** - * ``ref``: unique identifier for this link - * ``endpoint_a_ref``: Reference to the node at the first end of the link - * ``endpoint_a_port``: The ethernet port or switch port index of the second node - * ``endpoint_b_ref``: Reference to the node at the second end of the link - * ``endpoint_b_port``: The ethernet port or switch port index on the second node + configuration/training_config.rst + configuration/io_settings.rst + configuration/game.rst + configuration/agents.rst + configuration/simulation.rst diff --git a/docs/source/configuration/agents.rst b/docs/source/configuration/agents.rst new file mode 100644 index 00000000..4d81c89d --- /dev/null +++ b/docs/source/configuration/agents.rst @@ -0,0 +1,45 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + + +``agents`` +========== +Agents can be scripted (deterministic and stochastic), or controlled by a reinforcement learning algorithm. Not to be confused with an RL agent, the term agent here is used to refer to an entity that sends requests to the simulated network. In this part of the config, each agent's action space, observation space, and reward function can be defined. All three are defined in a modular way. + +**type**: Specifies which class should be used for the agent. ``ProxyAgent`` is used for agents that receive instructions from an RL algorithm. Scripted agents like ``RedDatabaseCorruptingAgent`` and ``GreenWebBrowsingAgent`` generate their own behaviour. + +**team**: Specifies if the agent is malicious (RED), benign (GREEN), or defensive (BLUE). Currently this value is not used for anything. + +**observation space:** + * ``type``: selects which python class from the ``primaite.game.agent.observation`` module is used for the overall observation structure. + * ``options``: allows configuring the chosen observation type. The ``UC2BlueObservation`` should be used for RL Agents. + * ``num_services_per_node``, ``num_folders_per_node``, ``num_files_per_folder``, ``num_nics_per_node`` all define the shape of the observation space. The size and shape of the obs space must remain constant, but the number of files, folders, ACL rules, and other components can change within an episode. Therefore padding is performed and these options set the size of the obs space. + * ``nodes``: list of nodes that will be present in this agent's observation space. The ``node_ref`` relates to the human-readable unique reference defined later in the ``simulation`` part of the config. Each node can also be configured with services, and files that should be monitored. + * ``links``: list of links that will be present in this agent's observation space. The ``link_ref`` relates to the human-readable unique reference defined later in the ``simulation`` part of the config. + * ``acl``: configure how the agent reads the access control list on the router in the simulation. ``router_node_ref`` is for selecting which router's ACL table should be used. ``ip_address_order`` sets the encoding of ip addresses as integers within the observation space. + +**action space:** +The action space is configured to be made up of individual action types. Once configured, the agent can select an action type and some optional action parameters at every step. For example: The ``NODE_SERVICE_SCAN`` action takes the parameters ``node_id`` and ``service_id``. + +Description of configurable items: + * ``action_list``: a list of action modules. The options are listed in the ``primaite.game.agent.actions`` module. + * ``action_map``: (optional). Restricts the possible combinations of action type / action parameter values to reduce the overall size of the action space. By default, every possible combination of actions and parameters will be assigned an integer for the agent's ``MultiDiscrete`` action space. Instead, the ``action_map`` allows you to list the actions corresponding to each integer in the ``MultiDiscrete`` space. + * ``options``: Options that apply too all action components. + * ``nodes``: list the nodes that the agent can act on, the order of this list defines the mapping between nodes and ``node_id`` integers. + * ``max_folders_per_node``, ``max_files_per_folder``, ``max_services_per_node``, ``max_nics_per_node``, ``max_acl_rules`` all are used to define the size of the action space. + +**reward function:** +Similar to action space, this is defined as a list of components. + +Description of configurable items: + * ``reward_components`` a list of reward components from the ``primaite.game.agent.reward`` module. + * ``weight``: relative importance of this reward component. The total reward for a step is a weighted sum of all reward components. + * ``options``: list of options passed to the reward component during initialisation, the exact options required depend on the reward component. + +**agent_settings**: +Settings passed to the agent during initialisation. These depend on the agent class. + +Reinforcement learning agents use the ``ProxyAgent`` class, they accept these agent settings: + +**flatten_obs**: If true, gymnasium flattening will be performed on the observation space before sending to the agent. Set this to true if your agent does not support nested observation spaces. diff --git a/docs/source/configuration/game.rst b/docs/source/configuration/game.rst new file mode 100644 index 00000000..797c3813 --- /dev/null +++ b/docs/source/configuration/game.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + + +``game`` +======== +This section defines high-level settings that apply across the game, currently it's used to help shape the action and observation spaces by restricting which ports and internet protocols should be considered. Here, users can also set the maximum number of steps in an episode. diff --git a/docs/source/configuration/io_settings.rst b/docs/source/configuration/io_settings.rst new file mode 100644 index 00000000..11d044bb --- /dev/null +++ b/docs/source/configuration/io_settings.rst @@ -0,0 +1,26 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + + +``io_settings`` +=============== +This section configures how PrimAITE saves data during simulation and training. + +**save_final_model**: Only used if training with PrimaiteSession, if true, the policy will be saved after the final training iteration. + +**save_checkpoints**: Only used if training with PrimaiteSession, if true, the policy will be saved periodically during training. + +**checkpoint_interval**: Only used if training with PrimaiteSession and if ``save_checkpoints`` is true. Defines how often to save the policy during training. + +**save_logs**: *currently unused*. + +**save_transactions**: *currently unused*. + +**save_tensorboard_logs**: *currently unused*. + +**save_step_metadata**: Whether to save the RL agents' action, environment state, and other data at every single step. + +**save_pcap_logs**: Whether to save pcap files of all network traffic during the simulation. + +**save_sys_logs**: Whether to save system logs from all nodes during the simulation. diff --git a/docs/source/configuration/simulation.rst b/docs/source/configuration/simulation.rst new file mode 100644 index 00000000..eb13e2be --- /dev/null +++ b/docs/source/configuration/simulation.rst @@ -0,0 +1,27 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + + +``simulation`` +============== +In this section the network layout is defined. This part of the config follows a hierarchical structure. Almost every component defines a ``ref`` field which acts as a human-readable unique identifier, used by other parts of the config, such as agents. + +At the top level of the network are ``nodes`` and ``links``. + +**nodes:** + * ``type``: one of ``router``, ``switch``, ``computer``, or ``server``, this affects what other sub-options should be defined. + * ``hostname`` - a non-unique name used for logging and outputs. + * ``num_ports`` (optional, routers and switches only): number of network interfaces present on the device. + * ``ports`` (optional, routers and switches only): configuration for each network interface, including IP address and subnet mask. + * ``acl`` (Router only): Define the ACL rules at each index of the ACL on the router. the possible options are: ``action`` (PERMIT or DENY), ``src_port``, ``dst_port``, ``protocol``, ``src_ip``, ``dst_ip``. Any options left blank default to none which usually means that it will apply across all options. For example leaving ``src_ip`` blank will apply the rule to all IP addresses. + * ``services`` (computers and servers only): a list of services to install on the node. They must define a ``ref``, ``type``, and ``options`` that depend on which ``type`` was selected. + * ``applications`` (computer and servers only): Similar to services. A list of application to install on the node. + * ``network_interfaces`` (computers and servers only): If the node has multiple networking devices, the second, third, fourth, etc... must be defined here with an ``ip_address`` and ``subnet_mask``. + +**links:** + * ``ref``: unique identifier for this link + * ``endpoint_a_ref``: Reference to the node at the first end of the link + * ``endpoint_a_port``: The ethernet port or switch port index of the second node + * ``endpoint_b_ref``: Reference to the node at the second end of the link + * ``endpoint_b_port``: The ethernet port or switch port index on the second node diff --git a/docs/source/configuration/training_config.rst b/docs/source/configuration/training_config.rst new file mode 100644 index 00000000..cde6cf52 --- /dev/null +++ b/docs/source/configuration/training_config.rst @@ -0,0 +1,25 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``training_config`` +=================== + +``rl_framework`` +---------------- +The RL (Reinforcement Learning) Framework to use in the training session + +Options available are: + +- ``SB3`` (Stable Baselines 3) +- ``RLLIB_single_agent`` (Single Agent Ray RLLib) +- ``RLLIB_multi_agent`` (Multi Agent Ray RLLib) + +``rl_algorithm`` +---------------- +The Reinforcement Learning Algorithm to use in the training session + +Options available are: + +- ``PPO`` (Proximal Policy Optimisation) +- ``A2C`` (Advantage Actor Critic) diff --git a/docs/source/dependencies.rst b/docs/source/dependencies.rst index 942ccfd8..ddea27fa 100644 --- a/docs/source/dependencies.rst +++ b/docs/source/dependencies.rst @@ -5,6 +5,8 @@ .. role:: raw-html(raw) :format: html +.. _Dependencies: + Dependencies ============ diff --git a/docs/source/request_system.rst b/docs/source/request_system.rst index 392bc792..e4c5584e 100644 --- a/docs/source/request_system.rst +++ b/docs/source/request_system.rst @@ -36,7 +36,7 @@ Technical Detail This system was achieved by implementing two classes, :py:class:`primaite.simulator.core.RequestType`, and :py:class:`primaite.simulator.core.RequestManager`. ``RequestType`` ------- +--------------- The ``RequestType`` object stores a reference to a method that executes the request, for example a node could have a request type that stores a reference to ``self.turn_on()``. Technically, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using ``lambda`` functions within a component's ``self._init_request_manager()`` method. Optionally, the ``RequestType`` object can also hold a validator that will permit/deny the request depending on context. @@ -60,7 +60,7 @@ A simple example without chaining can be seen in the :py:class:`primaite.simulat *ellipses (``...``) used to omit code impertinent to this explanation* Chaining RequestManagers ------------------------ +------------------------ A request function needs to be a callable that accepts ``request, context`` as parameters. Since the request manager resolves requests by invoking it with ``request, context`` as parameter, it is possible to use a ``RequestManager`` as a ``RequestType``. diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index c703b299..c4bf1bf0 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -22,9 +22,9 @@ Contents simulation_components/network/nodes/host_node simulation_components/network/nodes/network_node simulation_components/network/nodes/router + simulation_components/network/nodes/switch simulation_components/network/nodes/wireless_router simulation_components/network/nodes/firewall - simulation_components/network/switch simulation_components/network/network simulation_components/system/internal_frame_processing simulation_components/system/sys_log diff --git a/docs/source/simulation_components/network/base_hardware.rst b/docs/source/simulation_components/network/base_hardware.rst index c7545810..3aa6b073 100644 --- a/docs/source/simulation_components/network/base_hardware.rst +++ b/docs/source/simulation_components/network/base_hardware.rst @@ -41,6 +41,65 @@ Node Attributes - **session_manager**: Manages user sessions within the node. - **software_manager**: Controls the installation and management of software and services on the node. +.. _Node Start up and Shut down: + +Node Start up and Shut down +--------------------------- +Nodes are powered on and off over multiple timesteps. By default, the node ``start_up_duration`` and ``shut_down_duration`` is 3 timesteps. + +Example code where a node is turned on: + +.. code-block:: python + + from primaite.simulator.network.hardware.base import Node + from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState + + node = Node(hostname="pc_a") + + assert node.operating_state is NodeOperatingState.OFF # By default, node is instantiated in an OFF state + + node.power_on() # power on the node + + assert node.operating_state is NodeOperatingState.BOOTING # node is booting up + + for i in range(node.start_up_duration + 1): + # apply timestep until the node start up duration + node.apply_timestep(timestep=i) + + assert node.operating_state is NodeOperatingState.ON # node is in ON state + + +If the node needs to be instantiated in an on state: + + +.. code-block:: python + + from primaite.simulator.network.hardware.base import Node + from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState + + node = Node(hostname="pc_a", operating_state=NodeOperatingState.ON) + + assert node.operating_state is NodeOperatingState.ON # node is in ON state + +Setting ``start_up_duration`` and/or ``shut_down_duration`` to ``0`` will allow for the ``power_on`` and ``power_off`` methods to be completed instantly without applying timesteps: + +.. code-block:: python + + from primaite.simulator.network.hardware.base import Node + from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState + + node = Node(hostname="pc_a", start_up_duration=0, shut_down_duration=0) + + assert node.operating_state is NodeOperatingState.OFF # node is in OFF state + + node.power_on() + + assert node.operating_state is NodeOperatingState.ON # node is in ON state + + node.power_off() + + assert node.operating_state is NodeOperatingState.OFF # node is in OFF state + Node Behaviours/Functions ------------------------- diff --git a/docs/source/simulation_components/system/software.rst b/docs/source/simulation_components/system/software.rst index cd6b0aa3..7a1359f4 100644 --- a/docs/source/simulation_components/system/software.rst +++ b/docs/source/simulation_components/system/software.rst @@ -50,4 +50,5 @@ Services, Processes and Applications: data_manipulation_bot dns_client_server ftp_client_server + ntp_client_server web_browser_and_web_server_service diff --git a/docs/source/state_system.rst b/docs/source/state_system.rst index 860c9827..0bbbdd34 100644 --- a/docs/source/state_system.rst +++ b/docs/source/state_system.rst @@ -3,7 +3,7 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK Simulation State -============== +================ ``SimComponent`` objects in the simulation have a method called ``describe_state`` which return a dictionary of the state of the component. This is used to report pertinent data that could impact an agent's actions or rewards. For instance, the name and health status of a node is reported, which can be used by a reward function to punish corrupted or compromised nodes and reward healthy nodes. Each ``SimComponent`` object reports not only its own attributes in the state but also those of its child components. I.e. a computer node will report the state of its ``FileSystem`` and the ``FileSystem`` will report the state of its files and folders. This happens by recursively calling the childrens' own ``describe_state`` methods. diff --git a/pyproject.toml b/pyproject.toml index 3e5b959a..44ce75c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,7 @@ dev = [ "build==0.10.0", "flake8==6.0.0", "flake8-annotations", - "furo==2023.3.27", + "furo==2024.01.29", "gputil==1.4.0", "pip-licenses==4.3.0", "pre-commit==2.20.0", @@ -67,7 +67,7 @@ dev = [ "pytest-cov==4.0.0", "pytest-flake8==1.1.1", "setuptools==66", - "Sphinx==6.1.3", + "Sphinx==7.2.6", "sphinx-copybutton==0.5.2", "wheel==0.38.4" ] From 945db1341bb52af4cd1badbf60fe24972b99940c Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 20 Feb 2024 11:04:53 +0000 Subject: [PATCH 607/980] Make database client try to use most recent connection instead of generating new one --- .../simulator/system/applications/database_client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index fbeefe6a..dfa5e445 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -193,7 +193,10 @@ class DatabaseClient(Application): return False if connection_id is None: - connection_id = str(uuid4()) + if self.connections: + connection_id = list(self.connections.keys())[-1] + else: + connection_id = str(uuid4()) if not self.connections.get(connection_id): if not self.connect(connection_id=connection_id): From 701781b23e58fbf9f7cf21b2ce7b2ef7682cdf95 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 20 Feb 2024 11:05:09 +0000 Subject: [PATCH 608/980] Clear link load in new timestep --- src/primaite/simulator/network/hardware/base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 5334021a..01dd736d 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -599,6 +599,11 @@ class Link(SimComponent): def __str__(self) -> str: return f"{self.endpoint_a}<-->{self.endpoint_b}" + def apply_timestep(self, timestep: int) -> None: + """Apply a timestep to the simulation.""" + super().apply_timestep(timestep) + self.current_load = 0.0 + class ARPCache: """ From 4a3c66bdc605e5ce0ee6863f30395a6d3a83ed84 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 20 Feb 2024 12:04:07 +0000 Subject: [PATCH 609/980] Clear notebook code cells. --- src/primaite/notebooks/uc2_demo.ipynb | 680 +------------------------- 1 file changed, 21 insertions(+), 659 deletions(-) diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index b37e69fc..48ca795a 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -333,7 +333,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -343,20 +343,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/cade/repos/PrimAITE/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n", - "2024-02-07 10:58:13,192\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n", - "2024-02-07 10:58:17,136\tINFO util.py:159 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n" - ] - } - ], + "outputs": [], "source": [ "# Imports\n", "from primaite.config.load import example_config_path\n", @@ -377,134 +366,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Resetting environment, episode 0, avg. reward: 0.0\n", - "env created successfully\n", - "{'ACL': {1: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 0,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 2: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 1,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 3: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 2,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 4: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 3,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 5: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 4,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 6: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 5,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 7: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 6,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 8: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 7,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 9: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 8,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 10: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 9,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0}},\n", - " 'ICS': 0,\n", - " 'LINKS': {1: {'PROTOCOLS': {'ALL': 0}},\n", - " 2: {'PROTOCOLS': {'ALL': 0}},\n", - " 3: {'PROTOCOLS': {'ALL': 0}},\n", - " 4: {'PROTOCOLS': {'ALL': 0}},\n", - " 5: {'PROTOCOLS': {'ALL': 0}},\n", - " 6: {'PROTOCOLS': {'ALL': 0}},\n", - " 7: {'PROTOCOLS': {'ALL': 0}},\n", - " 8: {'PROTOCOLS': {'ALL': 0}},\n", - " 9: {'PROTOCOLS': {'ALL': 0}},\n", - " 10: {'PROTOCOLS': {'ALL': 0}}},\n", - " 'NODES': {1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}},\n", - " 'health_status': 1}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1}}}\n" - ] - } - ], + "outputs": [], "source": [ "# create the env\n", "with open(example_config_path(), 'r') as f:\n", @@ -532,7 +396,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -550,51 +414,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 1, Red action: DO NOTHING, Blue reward:0.34\n", - "step: 2, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 3, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 4, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 5, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 6, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 7, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 8, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 9, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 10, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 11, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 12, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 13, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 14, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 15, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 16, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 17, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 18, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 19, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 20, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 21, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 22, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 23, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 24, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 25, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 26, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 27, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 28, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 29, Red action: DO NOTHING, Blue reward:1.0\n", - "step: 30, Red action: ATTACK from client 1, Blue reward:0.32\n", - "step: 31, Red action: DO NOTHING, Blue reward:0.32\n", - "step: 32, Red action: DO NOTHING, Blue reward:0.32\n", - "step: 33, Red action: DO NOTHING, Blue reward:-1.0\n", - "step: 34, Red action: DO NOTHING, Blue reward:-1.0\n", - "step: 35, Red action: DO NOTHING, Blue reward:-1.0\n" - ] - } - ], + "outputs": [], "source": [ "for step in range(35):\n", " obs, reward, terminated, truncated, info = env.step(0)\n", @@ -610,44 +432,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}}, 'health_status': 1}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1}}\n" - ] - } - ], + "outputs": [], "source": [ "pprint(obs['NODES'])" ] @@ -661,44 +448,9 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 3, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 2}}, 'health_status': 1}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'nic_status': 1}, 2: {'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1}}\n" - ] - } - ], + "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(9) # scan database file\n", "obs, reward, terminated, truncated, info = env.step(1) # scan webapp service\n", @@ -722,21 +474,9 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 38\n", - "Red action: DONOTHING\n", - "Green action: NODE_APPLICATION_EXECUTE\n", - "Green action: NODE_APPLICATION_EXECUTE\n", - "Blue reward:-1.0\n" - ] - } - ], + "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(13) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", @@ -759,21 +499,9 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 39\n", - "Red action: DONOTHING\n", - "Green action: NODE_APPLICATION_EXECUTE\n", - "Green action: DONOTHING\n", - "Blue reward:-0.32\n" - ] - } - ], + "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(0) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", @@ -794,49 +522,9 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 139, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 140, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 141, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 142, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 143, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 144, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 145, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 146, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 147, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 148, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 149, Red action: NODE_APPLICATION_EXECUTE, Blue reward:-0.32\n", - "step: 150, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 151, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 152, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 153, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 154, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 155, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 156, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 157, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 158, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 159, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 160, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 161, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 162, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 163, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 164, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 165, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 166, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 167, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 168, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 169, Red action: NODE_APPLICATION_EXECUTE, Blue reward:-0.32\n", - "step: 170, Red action: DONOTHING, Blue reward:-0.32\n", - "step: 171, Red action: DONOTHING, Blue reward:-0.32\n" - ] - } - ], + "outputs": [], "source": [ "env.step(13) # Patch the database\n", "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward}\" )\n", @@ -868,345 +556,19 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{1: {'position': 0,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 2: {'position': 1,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 3: {'position': 2,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 4: {'position': 3,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 5: {'position': 4,\n", - " 'permission': 2,\n", - " 'source_node_id': 7,\n", - " 'source_port': 1,\n", - " 'dest_node_id': 4,\n", - " 'dest_port': 1,\n", - " 'protocol': 3},\n", - " 6: {'position': 5,\n", - " 'permission': 2,\n", - " 'source_node_id': 8,\n", - " 'source_port': 1,\n", - " 'dest_node_id': 4,\n", - " 'dest_port': 1,\n", - " 'protocol': 3},\n", - " 7: {'position': 6,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 8: {'position': 7,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 9: {'position': 8,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 10: {'position': 9,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0}}" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "obs['ACL']" ] }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [], - "source": [ - "router = env.game.simulation.network.get_node_by_hostname('router_1')" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+------------------------------------------------------------------------------------------------------------+\n", - "| router_1 Access Control List |\n", - "+-------+--------+----------+---------------+------------------------+--------------+------------------------+\n", - "| Index | Action | Protocol | Src IP | Src Port | Dst IP | Dst Port |\n", - "+-------+--------+----------+---------------+------------------------+--------------+------------------------+\n", - "| 5 | DENY | TCP | 192.168.10.21 | ANY | 192.168.1.14 | ANY |\n", - "| 6 | DENY | TCP | 192.168.10.22 | ANY | 192.168.1.14 | ANY |\n", - "| 18 | PERMIT | ANY | ANY | 5432 (POSTGRES_SERVER) | ANY | 5432 (POSTGRES_SERVER) |\n", - "| 19 | PERMIT | ANY | ANY | 53 (DNS) | ANY | 53 (DNS) |\n", - "| 20 | PERMIT | ANY | ANY | 21 (FTP) | ANY | 21 (FTP) |\n", - "| 21 | PERMIT | ANY | ANY | 80 (HTTP) | ANY | 80 (HTTP) |\n", - "| 22 | PERMIT | ANY | ANY | 219 (ARP) | ANY | 219 (ARP) |\n", - "| 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY |\n", - "| 24 | DENY | ANY | ANY | ANY | ANY | ANY |\n", - "+-------+--------+----------+---------------+------------------------+--------------+------------------------+\n" - ] - } - ], - "source": [ - "router.acl.show()" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[(, 0.34),\n", - " (,\n", - " 0.33),\n", - " (,\n", - " 0.33)]" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "env.agent.reward_function.reward_components" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [], - "source": [ - "client_1 = env.game.simulation.network.get_node_by_hostname('client_1')\n", - "client_2 = env.game.simulation.network.get_node_by_hostname('client_2')" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [], - "source": [ - "client_1_browser = client_1.software_manager.software.get(\"WebBrowser\")\n", - "client_2_browser = client_2.software_manager.software.get(\"WebBrowser\")" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=),\n", - " BrowserHistoryItem(url='http://arcd.com/users/', status=<_HistoryItemStatus.LOADED: 'LOADED'>, response_code=)]" - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "client_2_browser.history" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "client_1_browser.get_webpage()" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [], - "source": [ - "database_server = env.game.simulation.network.get_node_by_hostname('database_server')" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "File(uuid='390c399a-c2ab-4d84-b98f-d5fc1f9114d2', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={'390c399a-c2ab-4d84-b98f-d5fc1f9114d2': File(uuid='390c399a-c2ab-4d84-b98f-d5fc1f9114d2', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={'e63e23dc-c443-4434-822d-3c2c01cbfe1e': File(uuid='e63e23dc-c443-4434-822d-3c2c01cbfe1e', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=True, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e'])), '646a198e-6ac1-4aea-b526-7ca5c2c30dfc': File(uuid='646a198e-6ac1-4aea-b526-7ca5c2c30dfc', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=True, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e'])), '23df7aba-074e-4ffa-939a-d87ad1fe7af1': File(uuid='23df7aba-074e-4ffa-939a-d87ad1fe7af1', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=True, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))}, deleted_files={'e63e23dc-c443-4434-822d-3c2c01cbfe1e': File(uuid='e63e23dc-c443-4434-822d-3c2c01cbfe1e', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=True, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={'390c399a-c2ab-4d84-b98f-d5fc1f9114d2': File(uuid='390c399a-c2ab-4d84-b98f-d5fc1f9114d2', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e'])), '646a198e-6ac1-4aea-b526-7ca5c2c30dfc': File(uuid='646a198e-6ac1-4aea-b526-7ca5c2c30dfc', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=True, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={'390c399a-c2ab-4d84-b98f-d5fc1f9114d2': File(uuid='390c399a-c2ab-4d84-b98f-d5fc1f9114d2', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e'])), '23df7aba-074e-4ffa-939a-d87ad1fe7af1': File(uuid='23df7aba-074e-4ffa-939a-d87ad1fe7af1', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=True, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={'390c399a-c2ab-4d84-b98f-d5fc1f9114d2': File(uuid='390c399a-c2ab-4d84-b98f-d5fc1f9114d2', name='database.db', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='e602b9a6-ea1c-4c52-9025-8512d9116b1d', folder_name='database', file_type=, sim_size=15360000, real=False, sim_path=None, sim_root=PosixPath('/home/cade/primaite/3.0.0b6/sessions/2024-02-07/10-58-18/simulation_output/database_server/fs'), folder=Folder(uuid='e602b9a6-ea1c-4c52-9025-8512d9116b1d', name='database', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))}, deleted_files={...}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))}, scan_duration=3, scan_countdown=-1, red_scan_duration=3, red_scan_countdown=-1, restore_duration=3, restore_countdown=-1, original_file_uuids=['e63e23dc-c443-4434-822d-3c2c01cbfe1e']))" - ] - }, - "execution_count": 31, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "database_server.file_system.get_file('database', 'database.db')" - ] - }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "database_server." - ] + "source": [] } ], "metadata": { From 76db5dbaa234e32404ff9f89f1cd63b71137be10 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 20 Feb 2024 12:05:02 +0000 Subject: [PATCH 610/980] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc39a2b9..79cce02a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- Changed the red agent in the data manipulation scenario to randomly choose client 1 or client 2 to start its attack. - Changed the data manipulation scenario to include a second green agent on client 1. - Refactored actions and observations to be configurable via object name, instead of UUID. - Fixed a bug where ACL rules were not resetting on episode reset. From f7c1da31185cafaf1c01223c8bb137057f29bde0 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 20 Feb 2024 12:06:30 +0000 Subject: [PATCH 611/980] Update MARL config. --- .../config/_package_data/example_config_2_rl_agents.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index 993b3283..6d5b3602 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -74,7 +74,10 @@ agents: nodes: - node_ref: client_1 applications: - - application_ref: data_manipulation_bot + - application_name: DataManipulationBot + - node_name: client_2 + applications: + - application_name: DataManipulationBot max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 From 88f8e9cb42322a236d3718136afb52adb87ae1be Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 20 Feb 2024 12:09:32 +0000 Subject: [PATCH 612/980] Add todo comment. --- src/primaite/simulator/system/applications/database_client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index dfa5e445..2e0f4e3f 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -195,6 +195,7 @@ class DatabaseClient(Application): if connection_id is None: if self.connections: connection_id = list(self.connections.keys())[-1] + # TODO: if the most recent connection dies, it should be automatically cleared. else: connection_id = str(uuid4()) From 64b9ba3ecf2e1865e902917bd80d05bac70ab0bd Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 20 Feb 2024 16:21:03 +0000 Subject: [PATCH 613/980] Make environment reset reinstantiate the game --- src/primaite/game/game.py | 5 +--- .../notebooks/training_example_sb3.ipynb | 4 +-- src/primaite/session/environment.py | 27 ++++++++++++------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 1fd0dc8b..091438ce 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -67,9 +67,6 @@ class PrimaiteGame: self.step_counter: int = 0 """Current timestep within the episode.""" - self.episode_counter: int = 0 - """Current episode number.""" - self.options: PrimaiteGameOptions """Special options that apply for the entire game.""" @@ -163,7 +160,7 @@ class PrimaiteGame: return True return False - def reset(self) -> None: + def reset(self) -> None: # TODO: deprecated - remove me """Reset the game, this will reset the simulation.""" self.episode_counter += 1 self.step_counter = 0 diff --git a/src/primaite/notebooks/training_example_sb3.ipynb b/src/primaite/notebooks/training_example_sb3.ipynb index e5085c5e..164142b2 100644 --- a/src/primaite/notebooks/training_example_sb3.ipynb +++ b/src/primaite/notebooks/training_example_sb3.ipynb @@ -38,7 +38,7 @@ "metadata": {}, "outputs": [], "source": [ - "gym = PrimaiteGymEnv(game=game)" + "gym = PrimaiteGymEnv(game_config=cfg)" ] }, { @@ -65,7 +65,7 @@ "metadata": {}, "outputs": [], "source": [ - "model.learn(total_timesteps=1000)\n" + "model.learn(total_timesteps=10)\n" ] }, { diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index a3831bc1..ad770f8f 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -18,11 +18,18 @@ class PrimaiteGymEnv(gymnasium.Env): assumptions about the agent list always having a list of length 1. """ - def __init__(self, game: PrimaiteGame): + def __init__(self, game_config: Dict): """Initialise the environment.""" super().__init__() - self.game: "PrimaiteGame" = game + self.game_config: Dict = game_config + """PrimaiteGame definition. This can be changed between episodes to enable curriculum learning.""" + self.game: PrimaiteGame = PrimaiteGame.from_config(self.game_config) + """Current game.""" self.agent: ProxyAgent = self.game.rl_agents[0] + """The agent within the game that is controlled by the RL algorithm.""" + + self.episode_counter: int = 0 + """Current episode number.""" def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: """Perform a step in the environment.""" @@ -45,13 +52,13 @@ class PrimaiteGymEnv(gymnasium.Env): return next_obs, reward, terminated, truncated, info def _write_step_metadata_json(self, action: int, state: Dict, reward: int): - output_dir = SIM_OUTPUT.path / f"episode_{self.game.episode_counter}" / "step_metadata" + output_dir = SIM_OUTPUT.path / f"episode_{self.episode_counter}" / "step_metadata" output_dir.mkdir(parents=True, exist_ok=True) path = output_dir / f"step_{self.game.step_counter}.json" data = { - "episode": self.game.episode_counter, + "episode": self.episode_counter, "step": self.game.step_counter, "action": int(action), "reward": int(reward), @@ -63,10 +70,12 @@ class PrimaiteGymEnv(gymnasium.Env): def reset(self, seed: Optional[int] = None) -> Tuple[ObsType, Dict[str, Any]]: """Reset the environment.""" print( - f"Resetting environment, episode {self.game.episode_counter}, " + f"Resetting environment, episode {self.episode_counter}, " f"avg. reward: {self.game.rl_agents[0].reward_function.total_reward}" ) - self.game.reset() + self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=self.game_config) + self.agent = self.game.rl_agents[0] + self.episode_counter += 1 state = self.game.get_sim_state() self.game.update_agents(state) next_obs = self._get_obs() @@ -107,7 +116,7 @@ class PrimaiteRayEnv(gymnasium.Env): :type env_config: Dict[str, PrimaiteGame] """ self.env = PrimaiteGymEnv(game=PrimaiteGame.from_config(env_config["cfg"])) - self.env.game.episode_counter -= 1 + self.env.episode_counter -= 1 self.action_space = self.env.action_space self.observation_space = self.env.observation_space @@ -194,13 +203,13 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): return next_obs, rewards, terminateds, truncateds, infos def _write_step_metadata_json(self, actions: Dict, state: Dict, rewards: Dict): - output_dir = SIM_OUTPUT.path / f"episode_{self.game.episode_counter}" / "step_metadata" + output_dir = SIM_OUTPUT.path / f"episode_{self.episode_counter}" / "step_metadata" output_dir.mkdir(parents=True, exist_ok=True) path = output_dir / f"step_{self.game.step_counter}.json" data = { - "episode": self.game.episode_counter, + "episode": self.episode_counter, "step": self.game.step_counter, "actions": {agent_name: int(action) for agent_name, action in actions.items()}, "reward": rewards, From f82506023bcd978ff28e28a25491eb6b6facdee7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 20 Feb 2024 16:29:27 +0000 Subject: [PATCH 614/980] Delete set_original_state method definitions --- src/primaite/game/game.py | 2 - src/primaite/simulator/core.py | 10 +--- src/primaite/simulator/domain/account.py | 13 ----- src/primaite/simulator/file_system/file.py | 9 ---- .../simulator/file_system/file_system.py | 11 ---- .../file_system/file_system_item_abc.py | 5 -- src/primaite/simulator/file_system/folder.py | 17 ------- src/primaite/simulator/network/container.py | 7 --- .../simulator/network/hardware/base.py | 50 ------------------- .../network/hardware/nodes/router.py | 48 ------------------ src/primaite/simulator/sim_container.py | 4 -- .../system/applications/application.py | 6 --- .../system/applications/database_client.py | 8 --- .../red_applications/data_manipulation_bot.py | 15 ------ .../applications/red_applications/dos_bot.py | 16 ------ .../system/applications/web_browser.py | 8 --- .../simulator/system/processes/process.py | 6 --- .../services/database/database_service.py | 13 ----- .../system/services/dns/dns_client.py | 7 --- .../system/services/dns/dns_server.py | 7 --- .../system/services/ftp/ftp_client.py | 7 --- .../system/services/ftp/ftp_server.py | 7 --- .../simulator/system/services/service.py | 6 --- .../system/services/web_server/web_server.py | 7 --- src/primaite/simulator/system/software.py | 19 ------- .../_simulator/_domain/test_account.py | 2 - .../_file_system/test_file_system.py | 1 - .../_simulator/_network/test_container.py | 1 - .../_red_applications/test_dos_bot.py | 2 - 29 files changed, 1 insertion(+), 313 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 091438ce..bd7ed2cd 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -386,6 +386,4 @@ class PrimaiteGame: else: _LOGGER.warning(f"agent type {agent_type} not found") - game.simulation.set_original_state() - return game diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 98a7e8db..e21ce9eb 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -153,8 +153,6 @@ class SimComponent(BaseModel): uuid: str """The component UUID.""" - _original_state: Dict = {} - def __init__(self, **kwargs): if not kwargs.get("uuid"): kwargs["uuid"] = str(uuid4()) @@ -162,15 +160,9 @@ class SimComponent(BaseModel): self._request_manager: RequestManager = self._init_request_manager() self._parent: Optional["SimComponent"] = None - # @abstractmethod - def set_original_state(self): - """Sets the original state.""" - pass - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - for key, value in self._original_state.items(): - self.__setattr__(key, value) + pass def _init_request_manager(self) -> RequestManager: """ diff --git a/src/primaite/simulator/domain/account.py b/src/primaite/simulator/domain/account.py index d9dad06a..186caf5b 100644 --- a/src/primaite/simulator/domain/account.py +++ b/src/primaite/simulator/domain/account.py @@ -42,19 +42,6 @@ class Account(SimComponent): "Account Type, currently this can be service account (used by apps) or user account." enabled: bool = True - def set_original_state(self): - """Sets the original state.""" - vals_to_include = { - "num_logons", - "num_logoffs", - "num_group_changes", - "username", - "password", - "account_type", - "enabled", - } - self._original_state = self.model_dump(include=vals_to_include) - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index 608a1d78..4cd5cdbb 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -73,15 +73,6 @@ class File(FileSystemItemABC): self.sys_log.info(f"Created file /{self.path} (id: {self.uuid})") - self.set_original_state() - - def set_original_state(self): - """Sets the original state.""" - _LOGGER.debug(f"Setting File ({self.path}) original state on node {self.sys_log.hostname}") - super().set_original_state() - vals_to_include = {"folder_id", "folder_name", "file_type", "sim_size", "real", "sim_path", "sim_root"} - self._original_state.update(self.model_dump(include=vals_to_include)) - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" _LOGGER.debug(f"Resetting File ({self.path}) state on node {self.sys_log.hostname}") diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index ee80587d..a7252a2d 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -34,17 +34,6 @@ class FileSystem(SimComponent): if not self.folders: self.create_folder("root") - def set_original_state(self): - """Sets the original state.""" - _LOGGER.debug(f"Setting FileSystem original state on node {self.sys_log.hostname}") - for folder in self.folders.values(): - folder.set_original_state() - # Capture a list of all 'original' file uuids - original_keys = list(self.folders.keys()) - vals_to_include = {"sim_root"} - self._original_state.update(self.model_dump(include=vals_to_include)) - self._original_state["original_folder_uuids"] = original_keys - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" _LOGGER.debug(f"Resetting FileSystem state on node {self.sys_log.hostname}") diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py index c3e1426b..fbe5f4b3 100644 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -85,11 +85,6 @@ class FileSystemItemABC(SimComponent): deleted: bool = False "If true, the FileSystemItem was deleted." - def set_original_state(self): - """Sets the original state.""" - vals_to_keep = {"name", "health_status", "visible_health_status", "previous_hash", "revealed_to_red", "deleted"} - self._original_state = self.model_dump(include=vals_to_keep) - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 13fdc597..39c3dad8 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -49,23 +49,6 @@ class Folder(FileSystemItemABC): self.sys_log.info(f"Created file /{self.name} (id: {self.uuid})") - def set_original_state(self): - """Sets the original state.""" - _LOGGER.debug(f"Setting Folder ({self.name}) original state on node {self.sys_log.hostname}") - for file in self.files.values(): - file.set_original_state() - super().set_original_state() - vals_to_include = { - "scan_duration", - "scan_countdown", - "red_scan_duration", - "red_scan_countdown", - "restore_duration", - "restore_countdown", - } - self._original_state.update(self.model_dump(include=vals_to_include)) - self._original_state["original_file_uuids"] = list(self.files.keys()) - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" _LOGGER.debug(f"Resetting Folder ({self.name}) state on node {self.sys_log.hostname}") diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 8989a60f..48205bbd 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -45,13 +45,6 @@ class Network(SimComponent): self._nx_graph = MultiGraph() - def set_original_state(self): - """Sets the original state.""" - for node in self.nodes.values(): - node.set_original_state() - for link in self.links.values(): - link.set_original_state() - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" for node in self.nodes.values(): diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 01dd736d..68f3816d 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -123,13 +123,6 @@ class NIC(SimComponent): _LOGGER.error(msg) raise ValueError(msg) - self.set_original_state() - - def set_original_state(self): - """Sets the original state.""" - vals_to_include = {"ip_address", "subnet_mask", "mac_address", "speed", "mtu", "wake_on_lan", "enabled"} - self._original_state = self.model_dump(include=vals_to_include) - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" super().reset_component_for_episode(episode) @@ -349,14 +342,6 @@ class SwitchPort(SimComponent): kwargs["mac_address"] = generate_mac_address() super().__init__(**kwargs) - self.set_original_state() - - def set_original_state(self): - """Sets the original state.""" - vals_to_include = {"port_num", "mac_address", "speed", "mtu", "enabled"} - self._original_state = self.model_dump(include=vals_to_include) - super().set_original_state() - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -506,14 +491,6 @@ class Link(SimComponent): self.endpoint_b.connect_link(self) self.endpoint_up() - self.set_original_state() - - def set_original_state(self): - """Sets the original state.""" - vals_to_include = {"bandwidth", "current_load"} - self._original_state = self.model_dump(include=vals_to_include) - super().set_original_state() - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -1033,33 +1010,6 @@ class Node(SimComponent): self.arp.nics = self.nics self.session_manager.software_manager = self.software_manager self._install_system_software() - self.set_original_state() - - def set_original_state(self): - """Sets the original state.""" - for software in self.software_manager.software.values(): - software.set_original_state() - - self.file_system.set_original_state() - - for nic in self.nics.values(): - nic.set_original_state() - - vals_to_include = { - "hostname", - "default_gateway", - "operating_state", - "revealed_to_red", - "start_up_duration", - "start_up_countdown", - "shut_down_duration", - "shut_down_countdown", - "is_resetting", - "node_scan_duration", - "node_scan_countdown", - "red_scan_countdown", - } - self._original_state = self.model_dump(include=vals_to_include) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 9a34be0b..4b379be0 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -53,11 +53,6 @@ class ACLRule(SimComponent): rule_strings.append(f"{key}={value}") return ", ".join(rule_strings) - def set_original_state(self): - """Sets the original state.""" - vals_to_keep = {"action", "protocol", "src_ip_address", "src_port", "dst_ip_address", "dst_port"} - self._original_state = self.model_dump(include=vals_to_keep, exclude_none=True) - def describe_state(self) -> Dict: """ Describes the current state of the ACLRule. @@ -101,28 +96,6 @@ class AccessControlList(SimComponent): super().__init__(**kwargs) self._acl = [None] * (self.max_acl_rules - 1) - self.set_original_state() - - def set_original_state(self): - """Sets the original state.""" - self.implicit_rule.set_original_state() - vals_to_keep = {"implicit_action", "max_acl_rules", "acl"} - self._original_state = self.model_dump(include=vals_to_keep, exclude_none=True) - - for i, rule in enumerate(self._acl): - if not rule: - continue - self._default_config[i] = {"action": rule.action.name} - if rule.src_ip_address: - self._default_config[i]["src_ip"] = str(rule.src_ip_address) - if rule.dst_ip_address: - self._default_config[i]["dst_ip"] = str(rule.dst_ip_address) - if rule.src_port: - self._default_config[i]["src_port"] = rule.src_port.name - if rule.dst_port: - self._default_config[i]["dst_port"] = rule.dst_port.name - if rule.protocol: - self._default_config[i]["protocol"] = rule.protocol.name def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" @@ -389,11 +362,6 @@ class RouteEntry(SimComponent): metric: float = 0.0 "The cost metric for this route. Default is 0.0." - def set_original_state(self): - """Sets the original state.""" - vals_to_include = {"address", "subnet_mask", "next_hop_ip_address", "metric"} - self._original_values = self.model_dump(include=vals_to_include) - def describe_state(self) -> Dict: """ Describes the current state of the RouteEntry. @@ -426,11 +394,6 @@ class RouteTable(SimComponent): default_route: Optional[RouteEntry] = None sys_log: SysLog - def set_original_state(self): - """Sets the original state.""" - super().set_original_state() - self._original_state["routes_orig"] = self.routes - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" self.routes.clear() @@ -808,16 +771,6 @@ class Router(Node): self.arp.nics = self.nics self.icmp.arp = self.arp - self.set_original_state() - - def set_original_state(self): - """Sets the original state.""" - self.acl.set_original_state() - self.route_table.set_original_state() - super().set_original_state() - vals_to_include = {"num_ports"} - self._original_state.update(self.model_dump(include=vals_to_include)) - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" self.arp.clear() @@ -987,7 +940,6 @@ class Router(Node): nic.ip_address = ip_address nic.subnet_mask = subnet_mask self.sys_log.info(f"Configured port {port} with ip_address={ip_address}/{nic.ip_network.prefixlen}") - self.set_original_state() def enable_port(self, port: int): """ diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index 896861e6..18ed894c 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -21,10 +21,6 @@ class Simulation(SimComponent): super().__init__(**kwargs) - def set_original_state(self): - """Sets the original state.""" - self.network.set_original_state() - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" self.network.reset_component_for_episode(episode) diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 322ac808..513606a9 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -38,12 +38,6 @@ class Application(IOSoftware): def __init__(self, **kwargs): super().__init__(**kwargs) - def set_original_state(self): - """Sets the original state.""" - super().set_original_state() - vals_to_include = {"operating_state", "execution_control_status", "num_executions", "groups"} - self._original_state.update(self.model_dump(include=vals_to_include)) - @abstractmethod def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 2e0f4e3f..d05472d4 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -30,14 +30,6 @@ class DatabaseClient(Application): kwargs["port"] = Port.POSTGRES_SERVER kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) - self.set_original_state() - - def set_original_state(self): - """Sets the original state.""" - _LOGGER.debug(f"Setting DatabaseClient WebServer original state on node {self.software_manager.node.hostname}") - super().set_original_state() - vals_to_include = {"server_ip_address", "server_password", "connected", "_query_success_tracker"} - self._original_state.update(self.model_dump(include=vals_to_include)) def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index a844f059..bd4048c4 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -49,21 +49,6 @@ class DataManipulationBot(DatabaseClient): super().__init__(**kwargs) self.name = "DataManipulationBot" - def set_original_state(self): - """Sets the original state.""" - _LOGGER.debug(f"Setting DataManipulationBot original state on node {self.software_manager.node.hostname}") - super().set_original_state() - vals_to_include = { - "server_ip_address", - "payload", - "server_password", - "port_scan_p_of_success", - "data_manipulation_p_of_success", - "attack_stage", - "repeat", - } - self._original_state.update(self.model_dump(include=vals_to_include)) - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" _LOGGER.debug(f"Resetting DataManipulationBot state on node {self.software_manager.node.hostname}") diff --git a/src/primaite/simulator/system/applications/red_applications/dos_bot.py b/src/primaite/simulator/system/applications/red_applications/dos_bot.py index dfc48dd3..d4ea1a20 100644 --- a/src/primaite/simulator/system/applications/red_applications/dos_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/dos_bot.py @@ -57,22 +57,6 @@ class DoSBot(DatabaseClient, Application): self.name = "DoSBot" self.max_sessions = 1000 # override normal max sessions - def set_original_state(self): - """Set the original state of the Denial of Service Bot.""" - _LOGGER.debug(f"Setting {self.name} original state on node {self.software_manager.node.hostname}") - super().set_original_state() - vals_to_include = { - "target_ip_address", - "target_port", - "payload", - "repeat", - "attack_stage", - "max_sessions", - "port_scan_p_of_success", - "dos_intensity", - } - self._original_state.update(self.model_dump(include=vals_to_include)) - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" _LOGGER.debug(f"Resetting {self.name} state on node {self.software_manager.node.hostname}") diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index eef0ed5d..f1dbe3ef 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -47,16 +47,8 @@ class WebBrowser(Application): kwargs["port"] = Port.HTTP super().__init__(**kwargs) - self.set_original_state() self.run() - def set_original_state(self): - """Sets the original state.""" - _LOGGER.debug(f"Setting WebBrowser original state on node {self.software_manager.node.hostname}") - super().set_original_state() - vals_to_include = {"target_url", "domain_name_ip_address", "latest_response"} - self._original_state.update(self.model_dump(include=vals_to_include)) - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" _LOGGER.debug(f"Resetting WebBrowser state on node {self.software_manager.node.hostname}") diff --git a/src/primaite/simulator/system/processes/process.py b/src/primaite/simulator/system/processes/process.py index b753e3ad..458a6b5c 100644 --- a/src/primaite/simulator/system/processes/process.py +++ b/src/primaite/simulator/system/processes/process.py @@ -24,12 +24,6 @@ class Process(Software): operating_state: ProcessOperatingState "The current operating state of the Process." - def set_original_state(self): - """Sets the original state.""" - super().set_original_state() - vals_to_include = {"operating_state"} - self._original_state.update(self.model_dump(include=vals_to_include)) - @abstractmethod def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index d75b4424..4159c87c 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -40,19 +40,6 @@ class DatabaseService(Service): super().__init__(**kwargs) self._create_db_file() - def set_original_state(self): - """Sets the original state.""" - _LOGGER.debug(f"Setting DatabaseService original state on node {self.software_manager.node.hostname}") - super().set_original_state() - vals_to_include = { - "password", - "connections", - "backup_server_ip", - "latest_backup_directory", - "latest_backup_file_name", - } - self._original_state.update(self.model_dump(include=vals_to_include)) - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" _LOGGER.debug("Resetting DatabaseService original state on node {self.software_manager.node.hostname}") diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 2d3879ff..3c034705 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -29,13 +29,6 @@ class DNSClient(Service): super().__init__(**kwargs) self.start() - def set_original_state(self): - """Sets the original state.""" - _LOGGER.debug(f"Setting DNSClient original state on node {self.software_manager.node.hostname}") - super().set_original_state() - vals_to_include = {"dns_server"} - self._original_state.update(self.model_dump(include=vals_to_include)) - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" self.dns_cache.clear() diff --git a/src/primaite/simulator/system/services/dns/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py index 8decf7e9..eab94766 100644 --- a/src/primaite/simulator/system/services/dns/dns_server.py +++ b/src/primaite/simulator/system/services/dns/dns_server.py @@ -28,13 +28,6 @@ class DNSServer(Service): super().__init__(**kwargs) self.start() - def set_original_state(self): - """Sets the original state.""" - _LOGGER.debug(f"Setting DNSServer original state on node {self.software_manager.node.hostname}") - super().set_original_state() - vals_to_include = {"dns_table"} - self._original_state["dns_table_orig"] = self.model_dump(include=vals_to_include)["dns_table"] - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" self.dns_table.clear() diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 39bc57f0..457eaea9 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -27,13 +27,6 @@ class FTPClient(FTPServiceABC): super().__init__(**kwargs) self.start() - def set_original_state(self): - """Sets the original state.""" - _LOGGER.debug(f"Setting FTPClient original state on node {self.software_manager.node.hostname}") - super().set_original_state() - vals_to_include = {"connected"} - self._original_state.update(self.model_dump(include=vals_to_include)) - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" _LOGGER.debug(f"Resetting FTPClient state on node {self.software_manager.node.hostname}") diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index a82b0919..9534a5e9 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -27,13 +27,6 @@ class FTPServer(FTPServiceABC): super().__init__(**kwargs) self.start() - def set_original_state(self): - """Sets the original state.""" - _LOGGER.debug(f"Setting FTPServer original state on node {self.software_manager.node.hostname}") - super().set_original_state() - vals_to_include = {"server_password"} - self._original_state.update(self.model_dump(include=vals_to_include)) - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" _LOGGER.debug(f"Resetting FTPServer state on node {self.software_manager.node.hostname}") diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 162678a0..4102657c 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -78,12 +78,6 @@ class Service(IOSoftware): """ return super().receive(payload=payload, session_id=session_id, **kwargs) - def set_original_state(self): - """Sets the original state.""" - super().set_original_state() - vals_to_include = {"operating_state", "restart_duration", "restart_countdown"} - self._original_state.update(self.model_dump(include=vals_to_include)) - def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request("scan", RequestType(func=lambda request, context: self.scan())) diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index eaea6bb1..5888e72a 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -23,13 +23,6 @@ class WebServer(Service): last_response_status_code: Optional[HttpStatusCode] = None - def set_original_state(self): - """Sets the original state.""" - _LOGGER.debug(f"Setting WebServer original state on node {self.software_manager.node.hostname}") - super().set_original_state() - vals_to_include = {"last_response_status_code"} - self._original_state.update(self.model_dump(include=vals_to_include)) - def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" _LOGGER.debug(f"Resetting WebServer state on node {self.software_manager.node.hostname}") diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 662db08e..1fb8c989 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -96,19 +96,6 @@ class Software(SimComponent): _patching_countdown: Optional[int] = None "Current number of ticks left to patch the software." - def set_original_state(self): - """Sets the original state.""" - vals_to_include = { - "name", - "health_state_actual", - "health_state_visible", - "criticality", - "patching_count", - "scanning_count", - "revealed_to_red", - } - self._original_state = self.model_dump(include=vals_to_include) - def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request( @@ -245,12 +232,6 @@ class IOSoftware(Software): _connections: Dict[str, Dict] = {} "Active connections." - def set_original_state(self): - """Sets the original state.""" - super().set_original_state() - vals_to_include = {"installing_count", "max_sessions", "tcp", "udp", "port"} - self._original_state.update(self.model_dump(include=vals_to_include)) - @abstractmethod def describe_state(self) -> Dict: """ diff --git a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py index 01ad3871..695b15dd 100644 --- a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py +++ b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py @@ -7,7 +7,6 @@ from primaite.simulator.domain.account import Account, AccountType @pytest.fixture(scope="function") def account() -> Account: acct = Account(username="Jake", password="totally_hashed_password", account_type=AccountType.USER) - acct.set_original_state() return acct @@ -39,7 +38,6 @@ def test_original_state(account): account.log_on() account.log_off() account.disable() - account.set_original_state() account.log_on() state = account.describe_state() diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 9366d173..2fe3f04c 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -189,7 +189,6 @@ def test_reset_file_system(file_system): # file and folder that existed originally file_system.create_file(file_name="test_file.zip") file_system.create_folder(folder_name="test_folder") - file_system.set_original_state() # create a new file file_system.create_file(file_name="new_file.txt") diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index 7667a59f..994e5a45 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -33,7 +33,6 @@ def network(example_network) -> Network: assert len(example_network.computers) is 2 assert len(example_network.servers) is 2 - example_network.set_original_state() example_network.show() return example_network diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py index 71489171..da29a439 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py @@ -22,7 +22,6 @@ def dos_bot() -> DoSBot: dos_bot: DoSBot = computer.software_manager.software.get("DoSBot") dos_bot.configure(target_ip_address=IPv4Address("192.168.0.1")) - dos_bot.set_original_state() return dos_bot @@ -51,7 +50,6 @@ def test_dos_bot_reset(dos_bot): dos_bot.configure( target_ip_address=IPv4Address("192.168.1.1"), target_port=Port.HTTP, payload="payload", repeat=True ) - dos_bot.set_original_state() dos_bot.reset_component_for_episode(episode=1) # should reset to the configured value assert dos_bot.target_ip_address == IPv4Address("192.168.1.1") From 72f4cc0a5073e79f7b9734b27739b3264513c6f8 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 20 Feb 2024 16:56:25 +0000 Subject: [PATCH 615/980] Remove reset methods from most classes --- src/primaite/simulator/file_system/file.py | 5 --- .../simulator/file_system/file_system.py | 26 ----------- src/primaite/simulator/file_system/folder.py | 26 ----------- .../simulator/network/hardware/base.py | 9 ---- .../network/hardware/nodes/router.py | 45 ++++++------------- .../system/applications/database_client.py | 6 --- .../red_applications/data_manipulation_bot.py | 5 --- .../applications/red_applications/dos_bot.py | 5 --- .../system/applications/web_browser.py | 8 ---- .../services/database/database_service.py | 6 --- .../system/services/dns/dns_client.py | 5 --- .../system/services/dns/dns_server.py | 7 --- .../system/services/ftp/ftp_client.py | 5 --- .../system/services/ftp/ftp_server.py | 6 --- .../system/services/ntp/ntp_client.py | 13 +----- .../system/services/ntp/ntp_server.py | 10 ----- .../system/services/web_server/web_server.py | 5 --- 17 files changed, 16 insertions(+), 176 deletions(-) diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index 4cd5cdbb..d9b02e8e 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -73,11 +73,6 @@ class File(FileSystemItemABC): self.sys_log.info(f"Created file /{self.path} (id: {self.uuid})") - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - _LOGGER.debug(f"Resetting File ({self.path}) state on node {self.sys_log.hostname}") - super().reset_component_for_episode(episode) - @property def path(self) -> str: """ diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index a7252a2d..8fd4e5d7 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -34,32 +34,6 @@ class FileSystem(SimComponent): if not self.folders: self.create_folder("root") - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - _LOGGER.debug(f"Resetting FileSystem state on node {self.sys_log.hostname}") - # Move any 'original' folder that have been deleted back to folders - original_folder_uuids = self._original_state["original_folder_uuids"] - for uuid in original_folder_uuids: - if uuid in self.deleted_folders: - folder = self.deleted_folders[uuid] - self.deleted_folders.pop(uuid) - self.folders[uuid] = folder - - # Clear any other deleted folders that aren't original (have been created by agent) - self.deleted_folders.clear() - - # Now clear all non-original folders created by agent - current_folder_uuids = list(self.folders.keys()) - for uuid in current_folder_uuids: - if uuid not in original_folder_uuids: - folder = self.folders[uuid] - self.folders.pop(uuid) - - # Now reset all remaining folders - for folder in self.folders.values(): - folder.reset_component_for_episode(episode) - super().reset_component_for_episode(episode) - def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 39c3dad8..771dc7a0 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -49,32 +49,6 @@ class Folder(FileSystemItemABC): self.sys_log.info(f"Created file /{self.name} (id: {self.uuid})") - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - _LOGGER.debug(f"Resetting Folder ({self.name}) state on node {self.sys_log.hostname}") - # Move any 'original' file that have been deleted back to files - original_file_uuids = self._original_state["original_file_uuids"] - for uuid in original_file_uuids: - if uuid in self.deleted_files: - file = self.deleted_files[uuid] - self.deleted_files.pop(uuid) - self.files[uuid] = file - - # Clear any other deleted files that aren't original (have been created by agent) - self.deleted_files.clear() - - # Now clear all non-original files created by agent - current_file_uuids = list(self.files.keys()) - for uuid in current_file_uuids: - if uuid not in original_file_uuids: - file = self.files[uuid] - self.files.pop(uuid) - - # Now reset all remaining files - for file in self.files.values(): - file.reset_component_for_episode(episode) - super().reset_component_for_episode(episode) - def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request( diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 68f3816d..67ac42c8 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1015,15 +1015,6 @@ class Node(SimComponent): """Reset the original state of the SimComponent.""" super().reset_component_for_episode(episode) - # Reset ARP Cache - self.arp.clear() - - # Reset ICMP - self.icmp.clear() - - # Reset Session Manager - self.session_manager.clear() - # Reset File System self.file_system.reset_component_for_episode(episode) diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 4b379be0..aa154ad9 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -84,9 +84,7 @@ class AccessControlList(SimComponent): implicit_action: ACLAction implicit_rule: ACLRule max_acl_rules: int = 25 - _acl: List[Optional[ACLRule]] = [None] * 24 - _default_config: Dict[int, dict] = {} - """Config dict describing how the ACL list should look at episode start""" + _acl: List[Optional[ACLRule]] = [None] * 24 # TODO: this ignores the max_acl_rules and assumes it's default def __init__(self, **kwargs) -> None: if not kwargs.get("implicit_action"): @@ -97,26 +95,6 @@ class AccessControlList(SimComponent): super().__init__(**kwargs) self._acl = [None] * (self.max_acl_rules - 1) - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - self.implicit_rule.reset_component_for_episode(episode) - super().reset_component_for_episode(episode) - self._reset_rules_to_default() - - def _reset_rules_to_default(self) -> None: - """Clear all ACL rules and set them to the default rules config.""" - self._acl = [None] * (self.max_acl_rules - 1) - for r_num, r_cfg in self._default_config.items(): - self.add_rule( - action=ACLAction[r_cfg["action"]], - src_port=None if not (p := r_cfg.get("src_port")) else Port[p], - dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], - protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], - src_ip_address=r_cfg.get("src_ip"), - dst_ip_address=r_cfg.get("dst_ip"), - position=r_num, - ) - def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() @@ -394,12 +372,6 @@ class RouteTable(SimComponent): default_route: Optional[RouteEntry] = None sys_log: SysLog - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - self.routes.clear() - self.routes = self._original_state["routes_orig"] - super().reset_component_for_episode(episode) - def describe_state(self) -> Dict: """ Describes the current state of the RouteTable. @@ -1040,7 +1012,18 @@ class Router(Node): ip_address=port_cfg["ip_address"], subnet_mask=port_cfg["subnet_mask"], ) + + # Add the router's default ACL rules from the config. if "acl" in cfg: - new.acl._default_config = cfg["acl"] # save the config to allow resetting - new.acl._reset_rules_to_default() # read the config and apply rules + for r_num, r_cfg in cfg["acl"].items(): + new.add_rule( + action=ACLAction[r_cfg["action"]], + src_port=None if not (p := r_cfg.get("src_port")) else Port[p], + dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], + protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], + src_ip_address=r_cfg.get("src_ip"), + dst_ip_address=r_cfg.get("dst_ip"), + position=r_num, + ) + return new diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index d05472d4..25730c38 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -31,12 +31,6 @@ class DatabaseClient(Application): kwargs["protocol"] = IPProtocol.TCP super().__init__(**kwargs) - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - _LOGGER.debug(f"Resetting DataBaseClient state on node {self.software_manager.node.hostname}") - super().reset_component_for_episode(episode) - self._query_success_tracker.clear() - def describe_state(self) -> Dict: """ Describes the current state of the ACLRule. diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index bd4048c4..5fe951b7 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -49,11 +49,6 @@ class DataManipulationBot(DatabaseClient): super().__init__(**kwargs) self.name = "DataManipulationBot" - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - _LOGGER.debug(f"Resetting DataManipulationBot state on node {self.software_manager.node.hostname}") - super().reset_component_for_episode(episode) - def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() diff --git a/src/primaite/simulator/system/applications/red_applications/dos_bot.py b/src/primaite/simulator/system/applications/red_applications/dos_bot.py index d4ea1a20..9dac6b25 100644 --- a/src/primaite/simulator/system/applications/red_applications/dos_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/dos_bot.py @@ -57,11 +57,6 @@ class DoSBot(DatabaseClient, Application): self.name = "DoSBot" self.max_sessions = 1000 # override normal max sessions - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - _LOGGER.debug(f"Resetting {self.name} state on node {self.software_manager.node.hostname}") - super().reset_component_for_episode(episode) - def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index f1dbe3ef..6f2c479c 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -49,11 +49,6 @@ class WebBrowser(Application): super().__init__(**kwargs) self.run() - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - _LOGGER.debug(f"Resetting WebBrowser state on node {self.software_manager.node.hostname}") - super().reset_component_for_episode(episode) - def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request( @@ -72,9 +67,6 @@ class WebBrowser(Application): state["history"] = [hist_item.state() for hist_item in self.history] return state - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - def get_webpage(self, url: Optional[str] = None) -> bool: """ Retrieve the webpage. diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 4159c87c..5425ce75 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -40,12 +40,6 @@ class DatabaseService(Service): super().__init__(**kwargs) self._create_db_file() - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - _LOGGER.debug("Resetting DatabaseService original state on node {self.software_manager.node.hostname}") - self.clear_connections() - super().reset_component_for_episode(episode) - def configure_backup(self, backup_server: IPv4Address): """ Set up the database backup. diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 3c034705..967af6b2 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -29,11 +29,6 @@ class DNSClient(Service): super().__init__(**kwargs) self.start() - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - self.dns_cache.clear() - super().reset_component_for_episode(episode) - def describe_state(self) -> Dict: """ Describes the current state of the software. diff --git a/src/primaite/simulator/system/services/dns/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py index eab94766..4d0ebbb8 100644 --- a/src/primaite/simulator/system/services/dns/dns_server.py +++ b/src/primaite/simulator/system/services/dns/dns_server.py @@ -28,13 +28,6 @@ class DNSServer(Service): super().__init__(**kwargs) self.start() - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - self.dns_table.clear() - for key, value in self._original_state["dns_table_orig"].items(): - self.dns_table[key] = value - super().reset_component_for_episode(episode) - def describe_state(self) -> Dict: """ Describes the current state of the software. diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 457eaea9..7c334ced 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -27,11 +27,6 @@ class FTPClient(FTPServiceABC): super().__init__(**kwargs) self.start() - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - _LOGGER.debug(f"Resetting FTPClient state on node {self.software_manager.node.hostname}") - super().reset_component_for_episode(episode) - def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: """ Process the command in the FTP Packet. diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 9534a5e9..c5330de2 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -27,12 +27,6 @@ class FTPServer(FTPServiceABC): super().__init__(**kwargs) self.start() - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - _LOGGER.debug(f"Resetting FTPServer state on node {self.software_manager.node.hostname}") - self.clear_connections() - super().reset_component_for_episode(episode) - def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket: """ Process the command in the FTP Packet. diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index e8c3d0cb..5e4ae53a 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -1,6 +1,6 @@ from datetime import datetime from ipaddress import IPv4Address -from typing import Dict, Optional +from typing import Dict, List, Optional from primaite import getLogger from primaite.simulator.network.protocols.ntp import NTPPacket @@ -49,21 +49,12 @@ class NTPClient(Service): state = super().describe_state() return state - def reset_component_for_episode(self, episode: int): - """ - Resets the Service component for a new episode. - - This method ensures the Service is ready for a new episode, including resetting any - stateful properties or statistics, and clearing any message queues. - """ - pass - def send( self, payload: NTPPacket, session_id: Optional[str] = None, dest_ip_address: IPv4Address = None, - dest_port: [Port] = Port.NTP, + dest_port: List[Port] = Port.NTP, **kwargs, ) -> bool: """Requests NTP data from NTP server. diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index 0a66384a..29a320f6 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -34,16 +34,6 @@ class NTPServer(Service): state = super().describe_state() return state - def reset_component_for_episode(self, episode: int): - """ - Resets the Service component for a new episode. - - This method ensures the Service is ready for a new episode, including - resetting any stateful properties or statistics, and clearing any message - queues. - """ - pass - def receive( self, payload: NTPPacket, diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index 5888e72a..5e4a6f6e 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -23,11 +23,6 @@ class WebServer(Service): last_response_status_code: Optional[HttpStatusCode] = None - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" - _LOGGER.debug(f"Resetting WebServer state on node {self.software_manager.node.hostname}") - super().reset_component_for_episode(episode) - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. From deb7a3aa9d066ae4b25aa995628a9ac7d33e3c34 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 21 Feb 2024 14:49:59 +0000 Subject: [PATCH 616/980] #2257: massive docs addition for config file --- docs/_static/firewall_acl.png | Bin 0 -> 36036 bytes docs/_static/switched_p2p_network.png | Bin 0 -> 9178 bytes docs/source/config.rst | 19 ++ docs/source/configuration/agents.rst | 181 ++++++++++-- docs/source/configuration/game.rst | 38 +++ docs/source/configuration/io_settings.rst | 81 +++++- docs/source/configuration/simulation.rst | 89 +++++- .../common/common_host_node_attributes.rst | 41 +++ .../common/common_network_node_attributes.rst | 49 ++++ .../nodes/common/common_node_attributes.rst | 13 + .../nodes/common/node_type_list.rst | 18 ++ .../simulation/nodes/computer.rst | 39 +++ .../simulation/nodes/firewall.rst | 258 ++++++++++++++++++ .../configuration/simulation/nodes/router.rst | 125 +++++++++ .../configuration/simulation/nodes/server.rst | 39 +++ .../configuration/simulation/nodes/switch.rst | 37 +++ .../simulation/software/applications.rst | 10 + .../simulation/software/services.rst | 10 + docs/source/configuration/training_config.rst | 50 ++++ .../config/_package_data/example_config.yaml | 20 +- src/primaite/game/agent/actions.py | 4 +- src/primaite/game/agent/rewards.py | 5 +- src/primaite/game/game.py | 10 +- .../hardware/nodes/network/firewall.py | 12 +- .../network/hardware/nodes/network/router.py | 8 +- .../network/transmission/network_layer.py | 9 +- .../network/transmission/transport_layer.py | 6 +- tests/assets/configs/dmz_network.yaml | 2 +- 28 files changed, 1101 insertions(+), 72 deletions(-) create mode 100644 docs/_static/firewall_acl.png create mode 100644 docs/_static/switched_p2p_network.png create mode 100644 docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst create mode 100644 docs/source/configuration/simulation/nodes/common/common_network_node_attributes.rst create mode 100644 docs/source/configuration/simulation/nodes/common/common_node_attributes.rst create mode 100644 docs/source/configuration/simulation/nodes/common/node_type_list.rst create mode 100644 docs/source/configuration/simulation/nodes/computer.rst create mode 100644 docs/source/configuration/simulation/nodes/firewall.rst create mode 100644 docs/source/configuration/simulation/nodes/router.rst create mode 100644 docs/source/configuration/simulation/nodes/server.rst create mode 100644 docs/source/configuration/simulation/nodes/switch.rst create mode 100644 docs/source/configuration/simulation/software/applications.rst create mode 100644 docs/source/configuration/simulation/software/services.rst diff --git a/docs/_static/firewall_acl.png b/docs/_static/firewall_acl.png new file mode 100644 index 0000000000000000000000000000000000000000..1cdd25263cf0817dde59ae02124ab17879197237 GIT binary patch literal 36036 zcmeHv2|Scr|2Pv_L)k;LQo`6tp(Nc1sT*Y**|Q9Wu^W?6DYTL`ZCZqqeVIX0Sxa_f z5?Qhv`xx^-&!DTjz02=?-~W4mzwW17GiT0o&i8!x?K~F^^>x;GD54?W6A=Kx)Lt?&RHo%DdGwuz^UkDa5lE!}o`t))-f<=_rT zl;?K&gWKigtlZqBZ5*xaJ*-?%(yq3iUqoNy*8ckd@so zzh6!T`b$+>7Or%9X}*=ct?TlFN0EMx&dyfbker_2|+ zq^`2Hf}GQ-LjWFV4%*fO<%o1$KDNBHthB{OgbMrfT@|2a2 z%HgBOz3h*9BaeBX`t@onYr6R8cv!hP97WpLI)jC6e3qeClm#F{P}=w|ji@LAWI_Y> z9xMASZwn0^cl2913Jq{D&CAio7Pa*3@AZZpOQ(Rw58FE0JFM(1tE9U0i;LCD zODk3ahj8y??e z=zp@D-~I!7)}H%M9#K#@2)A=qF>yV9YK6VfR?c3_D7SI(1MmZZ_eOd+EujtN>AS+s z9!M`&8=Ck-vg+;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#;TL~974q$H>A_j?{FD@*?D4ze&Eo0tv~B!0F>#o9 zLv5G0{IBu1;ePVtiix_D4SPBsf(WUv;Li(_59VfwFK!W$)gvH>O{Q>vN!~X7gXEz} z>s=M}WtYQFl7FUUckG8N4vF8};gVua4qAlg5aN z)=sJMnV#~}SSy9~+IYpyMDm<_{OOZHN;M%*@KEMlqF**?@OX4ly@cwc{W+;Y6GTvW`xirSFFYhF~mEfZCE4C%#6!h?hTKra@uw8e&m+K>eY zEp0h?7**H|8mYIS0LT8PgEAO8zlfIqZDHx<$aBTjc`ZBU+%(7oW%aJOzM&PoH7;~z zn+-}PX2mN8I^Ub8eN`8L=aTB}!})jjW_){~H@)Pib` for a list of ports. + +``protocols`` +------------- + +A list of protocols that the Reinforcement Learning agent(s) are able to see in the observation space. + +See :ref:`List of IPProtocols ` for a list of protocols. diff --git a/docs/source/configuration/io_settings.rst b/docs/source/configuration/io_settings.rst index 11d044bb..96cc28fe 100644 --- a/docs/source/configuration/io_settings.rst +++ b/docs/source/configuration/io_settings.rst @@ -7,20 +7,83 @@ =============== This section configures how PrimAITE saves data during simulation and training. -**save_final_model**: Only used if training with PrimaiteSession, if true, the policy will be saved after the final training iteration. +``io_settings`` hierarchy +------------------------- -**save_checkpoints**: Only used if training with PrimaiteSession, if true, the policy will be saved periodically during training. +.. code-block:: yaml -**checkpoint_interval**: Only used if training with PrimaiteSession and if ``save_checkpoints`` is true. Defines how often to save the policy during training. + io_settings: + save_final_model: True + save_checkpoints: False + checkpoint_interval: 10 + # save_logs: True + # save_transactions: False + # save_tensorboard_logs: False + save_step_metadata: False + save_pcap_logs: False + save_sys_logs: False -**save_logs**: *currently unused*. +``save_final_model`` +-------------------- -**save_transactions**: *currently unused*. +Optional. Default value is ``True``. -**save_tensorboard_logs**: *currently unused*. +Only used if training with PrimaiteSession. +If ``True``, the policy will be saved after the final training iteration. -**save_step_metadata**: Whether to save the RL agents' action, environment state, and other data at every single step. -**save_pcap_logs**: Whether to save pcap files of all network traffic during the simulation. +``save_checkpoints`` +-------------------- -**save_sys_logs**: Whether to save system logs from all nodes during the simulation. +Optional. Default value is ``False``. + +Only used if training with PrimaiteSession. +If ``True``, the policy will be saved periodically during training. + + +``checkpoint_interval`` +----------------------- + +Optional. Default value is ``10``. + +Only used if training with PrimaiteSession and if ``save_checkpoints`` is ``True``. +Defines how often to save the policy during training. + + +``save_logs`` +------------- + +*currently unused*. + +``save_transactions`` +--------------------- + +*currently unused*. + +``save_tensorboard_logs`` +------------------------- + +*currently unused*. + +``save_step_metadata`` +---------------------- + +Optional. Default value is ``False``. + +If ``True``, The RL agent(s) actions, environment states and other data will be saved at every single step. + + +``save_pcap_logs`` +------------------ + +Optional. Default value is ``False``. + +If ``True``, then the pcap files which contain all network traffic during the simulation will be saved. + + +``save_sys_logs`` +----------------- + +Optional. Default value is ``False``. + +If ``True``, then the log files which contain all node actions during the simulation will be saved. diff --git a/docs/source/configuration/simulation.rst b/docs/source/configuration/simulation.rst index eb13e2be..d8497212 100644 --- a/docs/source/configuration/simulation.rst +++ b/docs/source/configuration/simulation.rst @@ -9,6 +9,17 @@ In this section the network layout is defined. This part of the config follows a At the top level of the network are ``nodes`` and ``links``. +e.g. + +.. code-block:: yaml + + simulation: + network: + nodes: + ... + links: + ... + **nodes:** * ``type``: one of ``router``, ``switch``, ``computer``, or ``server``, this affects what other sub-options should be defined. * ``hostname`` - a non-unique name used for logging and outputs. @@ -19,9 +30,75 @@ At the top level of the network are ``nodes`` and ``links``. * ``applications`` (computer and servers only): Similar to services. A list of application to install on the node. * ``network_interfaces`` (computers and servers only): If the node has multiple networking devices, the second, third, fourth, etc... must be defined here with an ``ip_address`` and ``subnet_mask``. -**links:** - * ``ref``: unique identifier for this link - * ``endpoint_a_ref``: Reference to the node at the first end of the link - * ``endpoint_a_port``: The ethernet port or switch port index of the second node - * ``endpoint_b_ref``: Reference to the node at the second end of the link - * ``endpoint_b_port``: The ethernet port or switch port index on the second node +``nodes`` +--------- + +This is where the list of nodes are defined. Some items will differ according to the node type, however, there will be common items such as a node's reference (which is used by the agent), the node's ``type`` and ``hostname`` + +To see the configuration for these nodes, refer to the following: + +.. toctree:: + :maxdepth: 1 + + simulation/nodes/computer.rst + simulation/nodes/firewall.rst + simulation/nodes/router.rst + simulation/nodes/server.rst + simulation/nodes/switch.rst + +``links`` +--------- + +This is where the links between the nodes are formed. + +e.g. + +In order to recreate the network below, we will need to create 2 links: + +- a link from computer_1 to the switch +- a link from computer_2 to the switch + +.. image:: ../../_static/switched_p2p_network.png + +this results in: + +.. code-block:: yaml + + links: + - ref: computer_1___switch + endpoint_a_ref: computer_1 + endpoint_a_port: 1 # port 1 on computer_1 + endpoint_b_ref: switch + endpoint_b_port: 1 # port 1 on switch + - ref: computer_2___switch + endpoint_a_ref: computer_2 + endpoint_a_port: 1 # port 1 on computer_2 + endpoint_b_ref: switch + endpoint_b_port: 2 # port 2 on switch + +``ref`` +^^^^^^^ + +The human readable name for the link. Not used in code, however is useful for a human to understand what the link is for. + +``endpoint_a_ref`` +^^^^^^^^^^^^^^^^^^ + +The name of the node which must be connected. + +``endpoint_a_port`` +^^^^^^^^^^^^^^^^^^^ + +The port on ``endpoint_a_ref`` which is to be connected to ``endpoint_b_port``. +This accepts an integer value e.g. if port 1 is to be connected, the configuration should be ``endpoint_a_port: 1`` + +``endpoint_b_ref`` +^^^^^^^^^^^^^^^^^^ + +The name of the node which must be connected. + +``endpoint_b_port`` +^^^^^^^^^^^^^^^^^^^ + +The port on ``endpoint_b_ref`` which is to be connected to ``endpoint_a_port``. +This accepts an integer value e.g. if port 1 is to be connected, the configuration should be ``endpoint_b_port: 1`` diff --git a/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst b/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst new file mode 100644 index 00000000..265c7106 --- /dev/null +++ b/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst @@ -0,0 +1,41 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``ip_address`` +^^^^^^^^^^^^^^ + +The IP address of the |NODE| in the network. + +``subnet_mask`` +^^^^^^^^^^^^^^^ + +Optional. Default value is ``255.255.255.0``. + +The subnet mask for the |NODE| to use. + +``default_gateway`` +^^^^^^^^^^^^^^^^^^^ + +The IP address that the |NODE| will use as the default gateway. Typically, this is the IP address of the closest router that the |NODE| is connected to. + +``dns_server`` +^^^^^^^^^^^^^^ + +Optional. Default value is ``None`` + +The IP address of the node which holds an instance of the DNS server. Some applications may use a domain name e.g. the WebBrowser (TODO: WebBrowser page) + +``applications`` +^^^^^^^^^^^^^^^^ + +A list of applications which are not considered system software that need to be installed on the |NODE|. + +See :ref:`Applications ` + +``services`` +^^^^^^^^^^^^ + +A list of services which are not considered system software that need to be installed on the |NODE|. + +See :ref:`Services ` diff --git a/docs/source/configuration/simulation/nodes/common/common_network_node_attributes.rst b/docs/source/configuration/simulation/nodes/common/common_network_node_attributes.rst new file mode 100644 index 00000000..83007145 --- /dev/null +++ b/docs/source/configuration/simulation/nodes/common/common_network_node_attributes.rst @@ -0,0 +1,49 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``routes`` +---------- + +A list of routes which tells the |NODE| where to forward the packet to depending on the target IP address. + +e.g. + +.. code-block:: yaml + + nodes: + - ref: node + ... + routes: + - address: 192.168.0.10 + subnet_mask: 255.255.255.0 + next_hop_ip_address: 192.168.1.1 + metric: 0 + +``address`` +""""""""""" + +The target IP address for the route. If the packet destination IP address matches this, the router will route the packet according to the ``next_hop_ip_address``. + +This must be a valid octet i.e. in the range of ``0.0.0.0`` and ``255.255.255.255``. + +``subnet_mask`` +""""""""""""""" + +Optional. Default value is ``255.255.255.0``. + +The subnet mask setting for the route. + +``next_hop_ip_address`` +""""""""""""""""""""""" + +The IP address of the next hop IP address that the packet will follow if the address matches the packet's destination IP address. + +This must be a valid octet i.e. in the range of ``0.0.0.0`` and ``255.255.255.255``. + +``metric`` +"""""""""" + +Optional. Default value is ``0``. This value accepts floats. + +The cost or distance of a route. The higher the value, the more cost or distance is attributed to the route. diff --git a/docs/source/configuration/simulation/nodes/common/common_node_attributes.rst b/docs/source/configuration/simulation/nodes/common/common_node_attributes.rst new file mode 100644 index 00000000..c1523518 --- /dev/null +++ b/docs/source/configuration/simulation/nodes/common/common_node_attributes.rst @@ -0,0 +1,13 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``ref`` +------- + +Human readable name used as reference for the |NODE|. Not used in code. + +``hostname`` +------------ + +The hostname of the |NODE|. This will be used to reference the |NODE|. diff --git a/docs/source/configuration/simulation/nodes/common/node_type_list.rst b/docs/source/configuration/simulation/nodes/common/node_type_list.rst new file mode 100644 index 00000000..ceee8207 --- /dev/null +++ b/docs/source/configuration/simulation/nodes/common/node_type_list.rst @@ -0,0 +1,18 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``type`` +-------- + +The type of node to add. + +Available options are: + +- ``computer`` +- ``firewall`` +- ``router`` +- ``server`` +- ``switch`` + +To create a |NODE|, type must be |NODE_TYPE|. diff --git a/docs/source/configuration/simulation/nodes/computer.rst b/docs/source/configuration/simulation/nodes/computer.rst new file mode 100644 index 00000000..bbdf087d --- /dev/null +++ b/docs/source/configuration/simulation/nodes/computer.rst @@ -0,0 +1,39 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _computer_configuration: + +``computer`` +============ + +A basic representation of a computer within the simulation. + +See :py:mod:`primaite.simulator.network.hardware.nodes.host.computer.Computer` + +example computer +---------------- + +.. code-block:: yaml + + nodes: + - ref: client_1 + hostname: client_1 + type: computer + ip_address: 192.168.0.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.0.1 + dns_server: 192.168.1.10 + applications: + ... + services: + ... + +.. include:: common/common_node_attributes.rst + +.. include:: common/node_type_list.rst + +.. include:: common/common_host_node_attributes.rst + +.. |NODE| replace:: computer +.. |NODE_TYPE| replace:: ``computer`` diff --git a/docs/source/configuration/simulation/nodes/firewall.rst b/docs/source/configuration/simulation/nodes/firewall.rst new file mode 100644 index 00000000..b1e4e5e1 --- /dev/null +++ b/docs/source/configuration/simulation/nodes/firewall.rst @@ -0,0 +1,258 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _firewall_configuration: + +``firewall`` +============ + +A basic representation of a network router within the simulation. + +The firewall is similar to how :ref:`Router ` works, with the difference being how firewall has specific ACL rules for inbound and outbound traffic as well as firewall being limited to 3 ports. + +See :py:mod:`primaite.simulator.network.hardware.nodes.network.firewall.Firewall` + +example firewall +---------------- + +.. code-block:: yaml + + nodes: + - ref: firewall + hostname: firewall + type: firewall + start_up_duration: 0 + shut_down_duration: 0 + ports: + external_port: # port 1 + ip_address: 192.168.20.1 + subnet_mask: 255.255.255.0 + internal_port: # port 2 + ip_address: 192.168.1.2 + subnet_mask: 255.255.255.0 + dmz_port: # port 3 + ip_address: 192.168.10.1 + subnet_mask: 255.255.255.0 + acl: + internal_inbound_acl: + ... + internal_outbound_acl: + ... + dmz_inbound_acl: + ... + dmz_outbound_acl: + ... + external_inbound_acl: + ... + external_outbound_acl: + ... + routes: + ... + +.. include:: common/common_node_attributes.rst + +.. include:: common/node_type_list.rst + +``ports`` +--------- + +The firewall node only has 3 ports. These specifically are: + +- ``external_port`` (port 1) +- ``internal_port`` (port 2) +- ``dmz_port`` (port 3) (can be optional) + +The ports should be defined with an ip address and subnet mask e.g. + +.. code-block:: yaml + + nodes: + - ref: firewall + ... + ports: + external_port: # port 1 + ip_address: 192.168.20.1 + subnet_mask: 255.255.255.0 + internal_port: # port 2 + ip_address: 192.168.1.2 + subnet_mask: 255.255.255.0 + dmz_port: # port 3 + ip_address: 192.168.10.1 + subnet_mask: 255.255.255.0 + +``ip_address`` +"""""""""""""" + +The IP address for the given port. This must be a valid octet i.e. in the range of ``0.0.0.0`` and ``255.255.255.255``. + +``subnet_mask`` +""""""""""""""" + +Optional. Default value is ``255.255.255.0``. + +The subnet mask setting for the port. + +``acl`` +------- + +There are 6 ACLs that can be defined for a firewall + +- ``internal_inbound_acl`` for traffic going towards the internal network +- ``internal_outbound_acl`` for traffic coming from the internal network +- ``dmz_inbound_acl`` for traffic going towards the dmz network +- ``dmz_outbound_acl`` for traffic coming from the dmz network +- ``external_inbound_acl`` for traffic coming from the external network +- ``external_outbound_acl`` for traffic going towards the external network + +.. image:: ../../../../_static/firewall_acl.png + +By default, ``external_inbound_acl`` and ``external_outbound_acl`` will permit any traffic through. + +See :py:mod:`primaite.simulator.network.hardware.nodes.network.router.AccessControlList` + +See :ref:`List of Ports ` for a list of ports. + +``internal_inbound_acl`` +"""""""""""""""""""""""" + +ACL rules for packets that have a destination IP address in what is considered the internal network. + +example: + +.. code-block:: yaml + + nodes: + - ref: firewall + ... + acl: + internal_inbound_acl: + 22: # position 22 on ACL list + action: PERMIT # allow packets that + src_port: ARP # are emitted from the ARP port + dst_port: ARP # are going towards an ARP port + 23: # position 23 on ACL list + action: PERMIT # allow packets that + protocol: ICMP # are ICMP + +``internal_outbound_acl`` +""""""""""""""""""""""""" + +ACL rules for packets that have a source IP address in what is considered the internal network and is going towards the DMZ network or the external network. + +example: + +.. code-block:: yaml + + nodes: + - ref: firewall + ... + acl: + internal_outbound_acl: + 22: # position 22 on ACL list + action: PERMIT # allow packets that + src_port: ARP # are emitted from the ARP port + dst_port: ARP # are going towards an ARP port + 23: # position 23 on ACL list + action: PERMIT # allow packets that + protocol: ICMP # are ICMP + + +``dmz_inbound_acl`` +""""""""""""""""""" + +ACL rules for packets that have a destination IP address in what is considered the DMZ network. + +example: + +.. code-block:: yaml + + nodes: + - ref: firewall + ... + acl: + dmz_inbound_acl: + 22: # position 22 on ACL list + action: PERMIT # allow packets that + src_port: ARP # are emitted from the ARP port + dst_port: ARP # are going towards an ARP port + 23: # position 23 on ACL list + action: PERMIT # allow packets that + protocol: ICMP # are ICMP + +``dmz_outbound_acl`` +"""""""""""""""""""" + +ACL rules for packets that have a source IP address in what is considered the DMZ network and is going towards the internal network or the external network. + +example: + +.. code-block:: yaml + + nodes: + - ref: firewall + ... + acl: + dmz_outbound_acl: + 22: # position 22 on ACL list + action: PERMIT # allow packets that + src_port: ARP # are emitted from the ARP port + dst_port: ARP # are going towards an ARP port + 23: # position 23 on ACL list + action: PERMIT # allow packets that + protocol: ICMP # are ICMP + + + +``external_inbound_acl`` +"""""""""""""""""""""""" + +Optional. By default, this will allow any traffic through. + +ACL rules for packets that have a destination IP address in what is considered the external network. + +example: + +.. code-block:: yaml + + nodes: + - ref: firewall + ... + acl: + external_inbound_acl: + 22: # position 22 on ACL list + action: PERMIT # allow packets that + src_port: ARP # are emitted from the ARP port + dst_port: ARP # are going towards an ARP port + 23: # position 23 on ACL list + action: PERMIT # allow packets that + protocol: ICMP # are ICMP + +``external_outbound_acl`` +""""""""""""""""""""""""" + +Optional. By default, this will allow any traffic through. + +ACL rules for packets that have a source IP address in what is considered the external network and is going towards the DMZ network or the internal network. + +example: + +.. code-block:: yaml + + nodes: + - ref: firewall + ... + acl: + external_outbound_acl: + 22: # position 22 on ACL list + action: PERMIT # allow packets that + src_port: ARP # are emitted from the ARP port + dst_port: ARP # are going towards an ARP port + 23: # position 23 on ACL list + action: PERMIT # allow packets that + protocol: ICMP # are ICMP + +.. include:: common/common_network_node_attributes.rst + +.. |NODE| replace:: firewall +.. |NODE_TYPE| replace:: ``firewall`` diff --git a/docs/source/configuration/simulation/nodes/router.rst b/docs/source/configuration/simulation/nodes/router.rst new file mode 100644 index 00000000..8a8efc06 --- /dev/null +++ b/docs/source/configuration/simulation/nodes/router.rst @@ -0,0 +1,125 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _router_configuration: + +``router`` +========== + +A basic representation of a network router within the simulation. + +See :py:mod:`primaite.simulator.network.hardware.nodes.network.router.Router` + +example router +-------------- + +.. code-block:: yaml + + nodes: + - ref: router_1 + hostname: router_1 + type: router + num_ports: 5 + ports: + ... + acl: + ... + +.. include:: common/common_node_attributes.rst + +.. include:: common/node_type_list.rst + +``num_ports`` +------------- + +Optional. Default value is ``5``. + +The number of ports the router will have. + +``ports`` +--------- + +Sets up the router's ports with an IP address and a subnet mask. + +Example of setting ports for a router with 2 ports: + +.. code-block:: yaml + + nodes: + - ref: router_1 + ... + ports: + 1: + ip_address: 192.168.1.1 + subnet_mask: 255.255.255.0 + 2: + ip_address: 192.168.10.1 + subnet_mask: 255.255.255.0 + +``ip_address`` +"""""""""""""" + +The IP address for the given port. This must be a valid octet i.e. in the range of ``0.0.0.0`` and ``255.255.255.255``. + +``subnet_mask`` +""""""""""""""" + +Optional. Default value is ``255.255.255.0``. + +The subnet mask setting for the port. + +``acl`` +------- + +Sets up the ACL rules for the router. + +e.g. + +.. code-block:: yaml + + nodes: + - ref: router_1 + ... + acl: + 1: + action: PERMIT + src_port: ARP + dst_port: ARP + 2: + action: PERMIT + protocol: ICMP + +See :py:mod:`primaite.simulator.network.hardware.nodes.network.router.AccessControlList` + +See :ref:`List of Ports ` for a list of ports. + +``action`` +"""""""""" + +Available options are + +- ``PERMIT`` : Allows the specified ``protocol`` or ``src_port`` and ``dst_port`` pairs +- ``DENY`` : Blocks the specified ``protocol`` or ``src_port`` and ``dst_port`` pairs + +``src_port`` +"""""""""""" + +Is used alongside ``dst_port``. Specifies the port where a packet originates. Used by the ACL Rule to determine if a packet with a specific source port is allowed to pass through the network node. + +``dst_port`` +"""""""""""" + +Is used alongside ``src_port``. Specifies the port where a packet is destined to arrive. Used by the ACL Rule to determine if a packet with a specific destination port is allowed to pass through the network node. + +``protocol`` +"""""""""""" + +Specifies which protocols are allowed by the ACL Rule to pass through the network node. + +See :ref:`List of IPProtocols ` for a list of protocols. + +.. include:: common/common_network_node_attributes.rst + +.. |NODE| replace:: router +.. |NODE_TYPE| replace:: ``router`` diff --git a/docs/source/configuration/simulation/nodes/server.rst b/docs/source/configuration/simulation/nodes/server.rst new file mode 100644 index 00000000..7f51eaf2 --- /dev/null +++ b/docs/source/configuration/simulation/nodes/server.rst @@ -0,0 +1,39 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _server_configuration: + +``server`` +========== + +A basic representation of a server within the simulation. + +See :py:mod:`primaite.simulator.network.hardware.nodes.host.server.Server` + +example server +-------------- + +.. code-block:: yaml + + nodes: + - ref: server_1 + hostname: server_1 + type: server + ip_address: 192.168.10.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + applications: + ... + services: + ... + +.. include:: common/common_node_attributes.rst + +.. include:: common/node_type_list.rst + +.. include:: common/common_host_node_attributes.rst + +.. |NODE| replace:: server +.. |NODE_TYPE| replace:: ``server`` diff --git a/docs/source/configuration/simulation/nodes/switch.rst b/docs/source/configuration/simulation/nodes/switch.rst new file mode 100644 index 00000000..4d57f76e --- /dev/null +++ b/docs/source/configuration/simulation/nodes/switch.rst @@ -0,0 +1,37 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _switch_configuration: + +``switch`` +========== + +A basic representation of a network switch within the simulation. + +See :py:mod:`primaite.simulator.network.hardware.nodes.network.switch.Switch` + +example switch +-------------- + +.. code-block:: yaml + + nodes: + - ref: switch_1 + hostname: switch_1 + type: switch + num_ports: 8 + +.. include:: common/common_node_attributes.rst + +.. include:: common/node_type_list.rst + +``num_ports`` +------------- + +Optional. Default value is ``8``. + +The number of ports the switch will have. + +.. |NODE| replace:: switch +.. |NODE_TYPE| replace:: ``switch`` diff --git a/docs/source/configuration/simulation/software/applications.rst b/docs/source/configuration/simulation/software/applications.rst new file mode 100644 index 00000000..75e0c64c --- /dev/null +++ b/docs/source/configuration/simulation/software/applications.rst @@ -0,0 +1,10 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _applications_config: + +``applications`` +================ + +apps diff --git a/docs/source/configuration/simulation/software/services.rst b/docs/source/configuration/simulation/software/services.rst new file mode 100644 index 00000000..5f1783af --- /dev/null +++ b/docs/source/configuration/simulation/software/services.rst @@ -0,0 +1,10 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _services_config: + +``services`` +============ + +services diff --git a/docs/source/configuration/training_config.rst b/docs/source/configuration/training_config.rst index cde6cf52..3e63f69b 100644 --- a/docs/source/configuration/training_config.rst +++ b/docs/source/configuration/training_config.rst @@ -4,6 +4,22 @@ ``training_config`` =================== +Configuration items relevant to how the Reinforcement Learning agent(s) will be trained. + +``training_config`` hierarchy +----------------------------- + +.. code-block:: yaml + + training_config: + rl_framework: SB3 # or RLLIB_single_agent or RLLIB_multi_agent + rl_algorithm: PPO # or A2C + n_learn_episodes: 5 + max_steps_per_episode: 200 + n_eval_episodes: 1 + deterministic_eval: True + seed: 123 + ``rl_framework`` ---------------- @@ -23,3 +39,37 @@ Options available are: - ``PPO`` (Proximal Policy Optimisation) - ``A2C`` (Advantage Actor Critic) + +``n_learn_episodes`` +-------------------- +The number of episodes to train the agent(s). +This should be an integer value above ``0`` + +``max_steps_per_episode`` +------------------------- +The number of steps each episode will last for. +This should be an integer value above ``0``. + + +``n_eval_episodes`` +------------------- +Optional. Default value is ``0``. + +The number of evaluation episodes to run the trained agent for. +This should be an integer value above ``0``. + +``deterministic_eval`` +---------------------- +Optional. By default this value is ``False``. + +If this is set to ``True``, the agents will act deterministically instead of stochastically. + + + +``seed`` +-------- +Optional. + +The seed is used (alongside ``deterministic_eval``) to reproduce a previous instance of training and evaluation of an RL agent. +The seed should be an integer value. +Useful for debugging. diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 6eab6c54..ae248f23 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -583,8 +583,8 @@ simulation: nodes: - ref: router_1 - type: router hostname: router_1 + type: router num_ports: 5 ports: 1: @@ -619,18 +619,18 @@ simulation: protocol: ICMP - ref: switch_1 - type: switch hostname: switch_1 + type: switch num_ports: 8 - ref: switch_2 - type: switch hostname: switch_2 + type: switch num_ports: 8 - ref: domain_controller - type: server hostname: domain_controller + type: server ip_address: 192.168.1.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -642,8 +642,8 @@ simulation: arcd.com: 192.168.1.12 # web server - ref: web_server - type: server hostname: web_server + type: server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -658,8 +658,8 @@ simulation: - ref: database_server - type: server hostname: database_server + type: server ip_address: 192.168.1.14 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -673,8 +673,8 @@ simulation: type: FTPClient - ref: backup_server - type: server hostname: backup_server + type: server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -684,8 +684,8 @@ simulation: type: FTPServer - ref: security_suite - type: server hostname: security_suite + type: server ip_address: 192.168.1.110 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -696,8 +696,8 @@ simulation: subnet_mask: 255.255.255.0 - ref: client_1 - type: computer hostname: client_1 + type: computer ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 @@ -719,8 +719,8 @@ simulation: type: DNSClient - ref: client_2 - type: computer hostname: client_2 + type: computer ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 1793d420..b85cf86c 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -572,7 +572,7 @@ class NetworkNICDisableAction(NetworkNICAbstractAction): class ActionManager: """Class which manages the action space for an agent.""" - _act_class_identifiers: Dict[str, type] = { + act_class_identifiers: Dict[str, type] = { "DONOTHING": DoNothingAction, "NODE_SERVICE_SCAN": NodeServiceScanAction, "NODE_SERVICE_STOP": NodeServiceStopAction, @@ -753,7 +753,7 @@ class ActionManager: # and `options` is an optional dict of options to pass to the init method of the action class act_type = act_spec.get("type") act_options = act_spec.get("options", {}) - self.actions[act_type] = self._act_class_identifiers[act_type](self, **global_action_args, **act_options) + self.actions[act_type] = self.act_class_identifiers[act_type](self, **global_action_args, **act_options) self.action_map: Dict[int, Tuple[str, Dict]] = {} """ diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index b5d5f998..27c39b65 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -245,12 +245,13 @@ class WebpageUnavailablePenalty(AbstractReward): class RewardFunction: """Manages the reward function for the agent.""" - __rew_class_identifiers: Dict[str, Type[AbstractReward]] = { + rew_class_identifiers: Dict[str, Type[AbstractReward]] = { "DUMMY": DummyReward, "DATABASE_FILE_INTEGRITY": DatabaseFileIntegrity, "WEB_SERVER_404_PENALTY": WebServer404Penalty, "WEBPAGE_UNAVAILABLE_PENALTY": WebpageUnavailablePenalty, } + """List of reward class identifiers.""" def __init__(self): """Initialise the reward function object.""" @@ -297,7 +298,7 @@ class RewardFunction: for rew_component_cfg in config["reward_components"]: rew_type = rew_component_cfg["type"] weight = rew_component_cfg.get("weight", 1.0) - rew_class = cls.__rew_class_identifiers[rew_type] + rew_class = cls.rew_class_identifiers[rew_type] rew_instance = rew_class.from_config(config=rew_component_cfg.get("options", {})) new.register_component(component=rew_instance, weight=weight) return new diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index b860fb2a..909b27a4 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -231,24 +231,24 @@ class PrimaiteGame: new_node = Computer( hostname=node_cfg["hostname"], ip_address=node_cfg["ip_address"], - subnet_mask=node_cfg["subnet_mask"], + subnet_mask=IPv4Address(node_cfg.get("subnet_mask", "255.255.255.0")), default_gateway=node_cfg["default_gateway"], - dns_server=node_cfg["dns_server"], + dns_server=node_cfg.get("dns_server", None), operating_state=NodeOperatingState.ON, ) elif n_type == "server": new_node = Server( hostname=node_cfg["hostname"], ip_address=node_cfg["ip_address"], - subnet_mask=node_cfg["subnet_mask"], + subnet_mask=IPv4Address(node_cfg.get("subnet_mask", "255.255.255.0")), default_gateway=node_cfg["default_gateway"], - dns_server=node_cfg.get("dns_server"), + dns_server=node_cfg.get("dns_server", None), operating_state=NodeOperatingState.ON, ) elif n_type == "switch": new_node = Switch( hostname=node_cfg["hostname"], - num_ports=node_cfg.get("num_ports"), + num_ports=int(node_cfg.get("num_ports", "8")), operating_state=NodeOperatingState.ON, ) elif n_type == "router": diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index f48d0561..903ce3f3 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -506,22 +506,24 @@ class Firewall(Router): # configure internal port new.configure_internal_port( ip_address=IPV4Address(internal_port.get("ip_address")), - subnet_mask=IPV4Address(internal_port.get("subnet_mask")), + subnet_mask=IPV4Address(internal_port.get("subnet_mask", "255.255.255.0")), ) # configure external port new.configure_external_port( ip_address=IPV4Address(external_port.get("ip_address")), - subnet_mask=IPV4Address(external_port.get("subnet_mask")), + subnet_mask=IPV4Address(external_port.get("subnet_mask", "255.255.255.0")), ) # configure dmz port new.configure_dmz_port( - ip_address=IPV4Address(dmz_port.get("ip_address")), subnet_mask=IPV4Address(dmz_port.get("subnet_mask")) + ip_address=IPV4Address(dmz_port.get("ip_address")), + subnet_mask=IPV4Address(dmz_port.get("subnet_mask", "255.255.255.0")), ) if "acl" in cfg: # acl rules for internal_inbound_acl if cfg["acl"]["internal_inbound_acl"]: + new.internal_inbound_acl.max_acl_rules new.internal_inbound_acl._default_config = cfg["acl"]["internal_inbound_acl"] new.internal_inbound_acl._reset_rules_to_default() @@ -553,8 +555,8 @@ class Firewall(Router): for route in cfg.get("routes"): new.route_table.add_route( address=IPv4Address(route.get("address")), - subnet_mask=IPv4Address(route.get("subnet_mask")), + subnet_mask=IPv4Address(route.get("subnet_mask", "255.255.255.0")), next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")), - metric=float(route.get("metric")), + metric=float(route.get("metric", 0)), ) return new diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index d52028a8..b3d7f7bf 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1482,7 +1482,7 @@ class Router(NetworkNode): """ new = Router( hostname=cfg["hostname"], - num_ports=cfg.get("num_ports"), + num_ports=int(cfg.get("num_ports", "5")), operating_state=NodeOperatingState.ON, ) if "ports" in cfg: @@ -1490,7 +1490,7 @@ class Router(NetworkNode): new.configure_port( port=port_num, ip_address=port_cfg["ip_address"], - subnet_mask=port_cfg["subnet_mask"], + subnet_mask=IPv4Address(port_cfg.get("subnet_mask", "255.255.255.0")), ) if "acl" in cfg: new.acl._default_config = cfg["acl"] # save the config to allow resetting @@ -1499,8 +1499,8 @@ class Router(NetworkNode): for route in cfg.get("routes"): new.route_table.add_route( address=IPv4Address(route.get("address")), - subnet_mask=IPv4Address(route.get("subnet_mask")), + subnet_mask=IPv4Address(route.get("subnet_mask", "255.255.255.0")), next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")), - metric=float(route.get("metric")), + metric=float(route.get("metric", 0)), ) return new diff --git a/src/primaite/simulator/network/transmission/network_layer.py b/src/primaite/simulator/network/transmission/network_layer.py index bdf4babc..dc848ade 100644 --- a/src/primaite/simulator/network/transmission/network_layer.py +++ b/src/primaite/simulator/network/transmission/network_layer.py @@ -9,11 +9,18 @@ _LOGGER = getLogger(__name__) class IPProtocol(Enum): - """Enum representing transport layer protocols in IP header.""" + """ + Enum representing transport layer protocols in IP header. + + .. _List of IPProtocols: + """ TCP = "tcp" + """Transmission Control Protocol.""" UDP = "udp" + """User Datagram Protocol.""" ICMP = "icmp" + """Internet Control Message Protocol.""" class Precedence(Enum): diff --git a/src/primaite/simulator/network/transmission/transport_layer.py b/src/primaite/simulator/network/transmission/transport_layer.py index 7c7509ab..c73e451a 100644 --- a/src/primaite/simulator/network/transmission/transport_layer.py +++ b/src/primaite/simulator/network/transmission/transport_layer.py @@ -5,7 +5,11 @@ from pydantic import BaseModel class Port(Enum): - """Enumeration of common known TCP/UDP ports used by protocols for operation of network applications.""" + """ + Enumeration of common known TCP/UDP ports used by protocols for operation of network applications. + + .. _List of Ports: + """ NONE = 0 "Place holder for a non-port." diff --git a/tests/assets/configs/dmz_network.yaml b/tests/assets/configs/dmz_network.yaml index 971ed8cd..880735d9 100644 --- a/tests/assets/configs/dmz_network.yaml +++ b/tests/assets/configs/dmz_network.yaml @@ -20,7 +20,7 @@ # . ---------------- -------------- -------------- . # . | dmz_server |------| switch_2 |------| firewall | . # . ---------------- -------------- -------------- . -# . (Computer) | . +# . (Server) | . # ........................................................|................... # | # External Network | From 98fb28cbbc97cb164378507dd2bac120ea67f391 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 21 Feb 2024 18:19:16 +0000 Subject: [PATCH 617/980] #2257: setting up application and service docs --- docs/source/configuration/simulation.rst | 10 ------ .../common/common_host_node_attributes.rst | 22 ++++-------- .../simulation/software/applications.rst | 29 ++++++++++++--- .../applications/data_manipulation_bot.rst | 8 +++++ .../software/applications/database_client.rst | 8 +++++ .../software/applications/dos_bot.rst | 8 +++++ .../software/applications/web_browser.rst | 8 +++++ .../software/common/system_software.rst | 12 +++++++ .../simulation/software/services.rst | 35 ++++++++++++++++--- .../software/services/database_service.rst | 8 +++++ .../software/services/dns_client.rst | 8 +++++ .../software/services/dns_server.rst | 8 +++++ .../software/services/ftp_client.rst | 8 +++++ .../software/services/ftp_server.rst | 8 +++++ .../software/services/ntp_client.rst | 8 +++++ .../software/services/ntp_server.rst | 8 +++++ .../software/services/web_server.rst | 8 +++++ src/primaite/game/game.py | 2 ++ .../network/hardware/nodes/host/host_node.py | 30 +++++++--------- 19 files changed, 185 insertions(+), 51 deletions(-) create mode 100644 docs/source/configuration/simulation/software/applications/data_manipulation_bot.rst create mode 100644 docs/source/configuration/simulation/software/applications/database_client.rst create mode 100644 docs/source/configuration/simulation/software/applications/dos_bot.rst create mode 100644 docs/source/configuration/simulation/software/applications/web_browser.rst create mode 100644 docs/source/configuration/simulation/software/common/system_software.rst create mode 100644 docs/source/configuration/simulation/software/services/database_service.rst create mode 100644 docs/source/configuration/simulation/software/services/dns_client.rst create mode 100644 docs/source/configuration/simulation/software/services/dns_server.rst create mode 100644 docs/source/configuration/simulation/software/services/ftp_client.rst create mode 100644 docs/source/configuration/simulation/software/services/ftp_server.rst create mode 100644 docs/source/configuration/simulation/software/services/ntp_client.rst create mode 100644 docs/source/configuration/simulation/software/services/ntp_server.rst create mode 100644 docs/source/configuration/simulation/software/services/web_server.rst diff --git a/docs/source/configuration/simulation.rst b/docs/source/configuration/simulation.rst index d8497212..7bb079e9 100644 --- a/docs/source/configuration/simulation.rst +++ b/docs/source/configuration/simulation.rst @@ -20,16 +20,6 @@ e.g. links: ... -**nodes:** - * ``type``: one of ``router``, ``switch``, ``computer``, or ``server``, this affects what other sub-options should be defined. - * ``hostname`` - a non-unique name used for logging and outputs. - * ``num_ports`` (optional, routers and switches only): number of network interfaces present on the device. - * ``ports`` (optional, routers and switches only): configuration for each network interface, including IP address and subnet mask. - * ``acl`` (Router only): Define the ACL rules at each index of the ACL on the router. the possible options are: ``action`` (PERMIT or DENY), ``src_port``, ``dst_port``, ``protocol``, ``src_ip``, ``dst_ip``. Any options left blank default to none which usually means that it will apply across all options. For example leaving ``src_ip`` blank will apply the rule to all IP addresses. - * ``services`` (computers and servers only): a list of services to install on the node. They must define a ``ref``, ``type``, and ``options`` that depend on which ``type`` was selected. - * ``applications`` (computer and servers only): Similar to services. A list of application to install on the node. - * ``network_interfaces`` (computers and servers only): If the node has multiple networking devices, the second, third, fourth, etc... must be defined here with an ``ip_address`` and ``subnet_mask``. - ``nodes`` --------- diff --git a/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst b/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst index 265c7106..a95f98d4 100644 --- a/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst +++ b/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst @@ -3,39 +3,29 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK ``ip_address`` -^^^^^^^^^^^^^^ +-------------- The IP address of the |NODE| in the network. ``subnet_mask`` -^^^^^^^^^^^^^^^ +--------------- Optional. Default value is ``255.255.255.0``. The subnet mask for the |NODE| to use. ``default_gateway`` -^^^^^^^^^^^^^^^^^^^ +------------------- The IP address that the |NODE| will use as the default gateway. Typically, this is the IP address of the closest router that the |NODE| is connected to. ``dns_server`` -^^^^^^^^^^^^^^ +-------------- Optional. Default value is ``None`` The IP address of the node which holds an instance of the DNS server. Some applications may use a domain name e.g. the WebBrowser (TODO: WebBrowser page) -``applications`` -^^^^^^^^^^^^^^^^ +.. include:: ../software/applications.rst -A list of applications which are not considered system software that need to be installed on the |NODE|. - -See :ref:`Applications ` - -``services`` -^^^^^^^^^^^^ - -A list of services which are not considered system software that need to be installed on the |NODE|. - -See :ref:`Services ` +.. include:: ../software/services.rst diff --git a/docs/source/configuration/simulation/software/applications.rst b/docs/source/configuration/simulation/software/applications.rst index 75e0c64c..7acde817 100644 --- a/docs/source/configuration/simulation/software/applications.rst +++ b/docs/source/configuration/simulation/software/applications.rst @@ -2,9 +2,30 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -.. _applications_config: - ``applications`` -================ +---------------- -apps +List of available applications that can be installed on a |NODE|: + +.. toctree:: + :maxdepth: 1 + + ../software/applications/data_manipulation_bot.rst + ../software/applications/database_client.rst + ../software/applications/dos_bot.rst + ../software/applications/web_browser.rst + +More info :py:mod:`primaite.game.game.APPLICATION_TYPES_MAPPING` + +.. include:: ../software/common/system_software.rst + + +.. toctree:: + :maxdepth: 1 + + ../software/applications/web_browser.rst + +More info :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.SYSTEM_SOFTWARE` + +.. |SOFTWARE_TYPE| replace:: application +.. |SOFTWARE_TYPES| replace:: applications diff --git a/docs/source/configuration/simulation/software/applications/data_manipulation_bot.rst b/docs/source/configuration/simulation/software/applications/data_manipulation_bot.rst new file mode 100644 index 00000000..6b650cf7 --- /dev/null +++ b/docs/source/configuration/simulation/software/applications/data_manipulation_bot.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``DataManipulationBot`` +----------------------- + +test diff --git a/docs/source/configuration/simulation/software/applications/database_client.rst b/docs/source/configuration/simulation/software/applications/database_client.rst new file mode 100644 index 00000000..81e827bc --- /dev/null +++ b/docs/source/configuration/simulation/software/applications/database_client.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``DatabaseClient`` +------------------ + +test diff --git a/docs/source/configuration/simulation/software/applications/dos_bot.rst b/docs/source/configuration/simulation/software/applications/dos_bot.rst new file mode 100644 index 00000000..98939e5b --- /dev/null +++ b/docs/source/configuration/simulation/software/applications/dos_bot.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``DoSBot`` +---------- + +test diff --git a/docs/source/configuration/simulation/software/applications/web_browser.rst b/docs/source/configuration/simulation/software/applications/web_browser.rst new file mode 100644 index 00000000..4af0d7b7 --- /dev/null +++ b/docs/source/configuration/simulation/software/applications/web_browser.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``WebBrowser`` +-------------- + +test diff --git a/docs/source/configuration/simulation/software/common/system_software.rst b/docs/source/configuration/simulation/software/common/system_software.rst new file mode 100644 index 00000000..64248272 --- /dev/null +++ b/docs/source/configuration/simulation/software/common/system_software.rst @@ -0,0 +1,12 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``system software`` +""""""""""""""""""" + +Some |SOFTWARE_TYPES| are pre installed on nodes - this is similar to how some |SOFTWARE_TYPES| are included with the Operating System. + +The |SOFTWARE_TYPE| may not be configured as needed, in which case, follow the steps above to configure them. + +The list of |SOFTWARE_TYPES| that are considered system software are: diff --git a/docs/source/configuration/simulation/software/services.rst b/docs/source/configuration/simulation/software/services.rst index 5f1783af..383f9de4 100644 --- a/docs/source/configuration/simulation/software/services.rst +++ b/docs/source/configuration/simulation/software/services.rst @@ -2,9 +2,36 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -.. _services_config: - ``services`` -============ +------------ -services +List of available services that can be installed on a |NODE|: + +.. toctree:: + :maxdepth: 1 + + ../software/services/database_service.rst + ../software/services/dns_client.rst + ../software/services/dns_server.rst + ../software/services/ftp_client.rst + ../software/services/ftp_server.rst + ../software/services/ntp_client.rst + ../software/services/ntp_server.rst + ../software/services/web_server.rst + +More info :py:mod:`primaite.game.game.SERVICE_TYPES_MAPPING` + +.. include:: ../software/common/system_software.rst + + +.. toctree:: + :maxdepth: 1 + + ../software/services/dns_client.rst + ../software/services/ftp_client.rst + ../software/services/ntp_client.rst + +More info :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.SYSTEM_SOFTWARE` + +.. |SOFTWARE_TYPE| replace:: service +.. |SOFTWARE_TYPES| replace:: services diff --git a/docs/source/configuration/simulation/software/services/database_service.rst b/docs/source/configuration/simulation/software/services/database_service.rst new file mode 100644 index 00000000..f03fde70 --- /dev/null +++ b/docs/source/configuration/simulation/software/services/database_service.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``DatabaseService`` +------------------- + +test diff --git a/docs/source/configuration/simulation/software/services/dns_client.rst b/docs/source/configuration/simulation/software/services/dns_client.rst new file mode 100644 index 00000000..d9b8008d --- /dev/null +++ b/docs/source/configuration/simulation/software/services/dns_client.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``DNSClient`` +------------- + +test diff --git a/docs/source/configuration/simulation/software/services/dns_server.rst b/docs/source/configuration/simulation/software/services/dns_server.rst new file mode 100644 index 00000000..a342967f --- /dev/null +++ b/docs/source/configuration/simulation/software/services/dns_server.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``DNSServer`` +------------- + +test diff --git a/docs/source/configuration/simulation/software/services/ftp_client.rst b/docs/source/configuration/simulation/software/services/ftp_client.rst new file mode 100644 index 00000000..d51a3dc1 --- /dev/null +++ b/docs/source/configuration/simulation/software/services/ftp_client.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``FTPClient`` +------------- + +test diff --git a/docs/source/configuration/simulation/software/services/ftp_server.rst b/docs/source/configuration/simulation/software/services/ftp_server.rst new file mode 100644 index 00000000..c7f92340 --- /dev/null +++ b/docs/source/configuration/simulation/software/services/ftp_server.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``FTPServer`` +------------- + +test diff --git a/docs/source/configuration/simulation/software/services/ntp_client.rst b/docs/source/configuration/simulation/software/services/ntp_client.rst new file mode 100644 index 00000000..51b2e061 --- /dev/null +++ b/docs/source/configuration/simulation/software/services/ntp_client.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``NTPClient`` +------------- + +test diff --git a/docs/source/configuration/simulation/software/services/ntp_server.rst b/docs/source/configuration/simulation/software/services/ntp_server.rst new file mode 100644 index 00000000..2efbdf1a --- /dev/null +++ b/docs/source/configuration/simulation/software/services/ntp_server.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``NTPServer`` +------------- + +test diff --git a/docs/source/configuration/simulation/software/services/web_server.rst b/docs/source/configuration/simulation/software/services/web_server.rst new file mode 100644 index 00000000..4fab660d --- /dev/null +++ b/docs/source/configuration/simulation/software/services/web_server.rst @@ -0,0 +1,8 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``WebServer`` +------------- + +test diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 909b27a4..7a17a03d 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -41,6 +41,7 @@ APPLICATION_TYPES_MAPPING = { "DataManipulationBot": DataManipulationBot, "DoSBot": DoSBot, } +"""List of available applications that can be installed on nodes in the PrimAITE Simulation.""" SERVICE_TYPES_MAPPING = { "DNSClient": DNSClient, @@ -52,6 +53,7 @@ SERVICE_TYPES_MAPPING = { "NTPClient": NTPClient, "NTPServer": NTPServer, } +"""List of available services that can be installed on nodes in the PrimAITE Simulation.""" class PrimaiteGameOptions(BaseModel): diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index 3f34f736..6db1e036 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -261,6 +261,17 @@ class NIC(IPWiredNetworkInterface): return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" +SYSTEM_SOFTWARE = { + "HostARP": HostARP, + "ICMP": ICMP, + "DNSClient": DNSClient, + "FTPClient": FTPClient, + "NTPClient": NTPClient, + "WebBrowser": WebBrowser, +} +"""List of system software that is automatically installed on nodes.""" + + class HostNode(Node): """ Represents a host node in the network. @@ -321,23 +332,8 @@ class HostNode(Node): This method equips the host with essential network services and applications, preparing it for various network-related tasks and operations. """ - # ARP Service - self.software_manager.install(HostARP) - - # ICMP Service - self.software_manager.install(ICMP) - - # DNS Client - self.software_manager.install(DNSClient) - - # FTP Client - self.software_manager.install(FTPClient) - - # NTP Client - self.software_manager.install(NTPClient) - - # Web Browser - self.software_manager.install(WebBrowser) + for _, software_class in SYSTEM_SOFTWARE.items(): + self.software_manager.install(software_class) super()._install_system_software() From 771a68dccba056428caee4fec18a9c0a4e4c2648 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 22 Feb 2024 22:43:14 +0000 Subject: [PATCH 618/980] #2238 - Implement NMNE detection and logging in NetworkInterface. - Enhance NicObservation for detailed NMNE event monitoring. - Add nmne_config options to simulation settings for customizable NMNE capturing. - Update documentation and tests for new NMNE features and simulation config. --- CHANGELOG.md | 6 +- .../network/network_interfaces.rst | 11 +- .../config/_package_data/example_config.yaml | 4 + .../example_config_2_rl_agents.yaml | 4 + src/primaite/game/agent/observations.py | 52 +++++++- src/primaite/game/game.py | 4 + .../simulator/network/hardware/base.py | 102 +++++++++++++-- .../network/hardware/nodes/host/host_node.py | 1 + src/primaite/simulator/network/nmne.py | 46 +++++++ .../network/test_capture_nmne.py | 120 ++++++++++++++++++ 10 files changed, 333 insertions(+), 17 deletions(-) create mode 100644 src/primaite/simulator/network/nmne.py create mode 100644 tests/integration_tests/network/test_capture_nmne.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 01e45d2e..40ac6535 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,7 +82,8 @@ SessionManager. - `AirSpace` class to simulate wireless communications, managing wireless interfaces and facilitating the transmission of frames within specified frequencies. - `AirSpaceFrequency` enum for defining standard wireless frequencies, including 2.4 GHz and 5 GHz bands, to support realistic wireless network simulations. - `WirelessRouter` class, extending the `Router` class, to incorporate wireless networking capabilities alongside traditional wired connections. This class allows the configuration of wireless access points with specific IP settings and operating frequencies. - +- NMNE capturing capabilities to `NetworkInterface` class for detecting and logging Malicious Network Events. +- New `nmne_config` settings in the simulation configuration to enable NMNE capturing and specify keywords such as "DELETE". ### Changed - Integrated the RouteTable into the Routers frame processing. @@ -94,7 +95,8 @@ SessionManager. - Refactored all tests to utilise new `Node` subclasses (`Computer`, `Server`, `Router`, `Switch`) instead of creating generic `Node` instances and manually adding network interfaces. This change aligns test setups more closely with the intended use cases and hierarchies within the network simulation framework. - Updated all tests to employ the `Network()` class for managing nodes and their connections, ensuring a consistent and structured approach to setting up network topologies in testing scenarios. - **ACLRule Wildcard Masking**: Updated the `ACLRule` class to support IP ranges using wildcard masking. This enhancement allows for more flexible and granular control over traffic filtering, enabling the specification of broader or more specific IP address ranges in ACL rules. - +- Updated `NetworkInterface` documentation to reflect the new NMNE capturing features and how to use them. +- Integration of NMNE capturing functionality within the `NicObservation` class. ### Removed - Removed legacy simulation modules: `acl`, `common`, `environment`, `links`, `nodes`, `pol` diff --git a/docs/source/simulation_components/network/network_interfaces.rst b/docs/source/simulation_components/network/network_interfaces.rst index 9e1ad80a..c74b54ae 100644 --- a/docs/source/simulation_components/network/network_interfaces.rst +++ b/docs/source/simulation_components/network/network_interfaces.rst @@ -65,9 +65,14 @@ Network Interface Classes **NetworkInterface (Base Layer)** -Abstract base class defining core interface properties like MAC address, speed, MTU. -Requires subclasses implement key methods like send/receive frames, enable/disable interface. -Establishes universal network interface capabilities. +- Abstract base class defining core interface properties like MAC address, speed, MTU. +- Requires subclasses implement key methods like send/receive frames, enable/disable interface. +- Establishes universal network interface capabilities. +- Malicious Network Events Monitoring: + + * Enhances network interfaces with the capability to monitor and capture Malicious Network Events (MNEs) based on predefined criteria such as specific keywords or traffic patterns. + * Integrates NMNE detection functionalities, leveraging configurable settings like ``capture_nmne``, `nmne_capture_keywords``, and observation mechanisms such as ``NicObservation`` to classify and record network anomalies. + * Offers an additional layer of security and data analysis, crucial for identifying and mitigating malicious activities within the network infrastructure. Provides vital information for network security analysis and reinforcement learning algorithms. **WiredNetworkInterface (Connection Type Layer)** diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index f85baf10..a72ebeca 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -583,6 +583,10 @@ agents: simulation: network: + nmne_config: + capture_nmne: true + nmne_capture_keywords: + - DELETE nodes: - ref: router_1 diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index 93019c9d..12461547 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -963,6 +963,10 @@ agents: simulation: network: + nmne_config: + capture_nmne: true + nmne_capture_keywords: + - DELETE nodes: - ref: router_1 diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index dfee2543..1d8799fd 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -8,6 +8,7 @@ from gymnasium.core import ObsType from primaite import getLogger from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +from primaite.simulator.network.nmne import CAPTURE_NMNE _LOGGER = getLogger(__name__) @@ -346,7 +347,14 @@ class FolderObservation(AbstractObservation): class NicObservation(AbstractObservation): """Observation of a Network Interface Card (NIC) in the network.""" - default_observation: spaces.Space = {"nic_status": 0} + @property + def default_observation(self) -> Dict: + """The default NIC observation dict.""" + data = {"nic_status": 0} + + if CAPTURE_NMNE: + data.update({"nmne": {"inbound": 0, "outbound": 0}}) + return data def __init__(self, where: Optional[Tuple[str]] = None) -> None: """Initialise NIC observation. @@ -360,6 +368,29 @@ class NicObservation(AbstractObservation): super().__init__() self.where: Optional[Tuple[str]] = where + def _categorise_mne_count(self, nmne_count: int) -> int: + """ + Categorise the number of Malicious Network Events (NMNEs) into discrete bins. + + This helps in classifying the severity or volume of MNEs into manageable levels for the agent. + + Bins are defined as follows: + - 0: No MNEs detected (0 events). + - 1: Low number of MNEs (1-5 events). + - 2: Moderate number of MNEs (6-10 events). + - 3: High number of MNEs (more than 10 events). + + :param nmne_count: Number of MNEs detected. + :return: Bin number corresponding to the number of MNEs. Returns 0, 1, 2, or 3 based on the detected MNE count. + """ + if nmne_count > 10: + return 3 + elif nmne_count > 5: + return 2 + elif nmne_count > 0: + return 1 + return 0 + def observe(self, state: Dict) -> Dict: """Generate observation based on the current state of the simulation. @@ -371,15 +402,30 @@ class NicObservation(AbstractObservation): if self.where is None: return self.default_observation nic_state = access_from_nested_dict(state, self.where) + if nic_state is NOT_PRESENT_IN_STATE: return self.default_observation else: - return {"nic_status": 1 if nic_state["enabled"] else 2} + obs_dict = {"nic_status": 1 if nic_state["enabled"] else 2, "nmne": {}} + if CAPTURE_NMNE: + direction_dict = nic_state["nmne"].get("direction", {}) + inbound_keywords = direction_dict.get("inbound", {}).get("keywords", {}) + inbound_count = inbound_keywords.get("*", 0) + outbound_keywords = direction_dict.get("outbound", {}).get("keywords", {}) + outbound_count = outbound_keywords.get("*", 0) + obs_dict["nmne"]["inbound"] = self._categorise_mne_count(inbound_count) + obs_dict["nmne"]["outbound"] = self._categorise_mne_count(outbound_count) + return obs_dict @property def space(self) -> spaces.Space: """Gymnasium space object describing the observation space shape.""" - return spaces.Dict({"nic_status": spaces.Discrete(3)}) + return spaces.Dict( + { + "nic_status": spaces.Discrete(3), + "nmne": spaces.Dict({"inbound": spaces.Discrete(6), "outbound": spaces.Discrete(6)}), + } + ) @classmethod def from_config(cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]]) -> "NicObservation": diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index ed98accd..1f5dc8fa 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -17,6 +17,7 @@ from primaite.simulator.network.hardware.nodes.host.host_node import NIC from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.hardware.nodes.network.router import Router from primaite.simulator.network.hardware.nodes.network.switch import Switch +from primaite.simulator.network.nmne import set_nmne_config from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.sim_container import Simulation from primaite.simulator.system.applications.database_client import DatabaseClient @@ -426,4 +427,7 @@ class PrimaiteGame: game.simulation.set_original_state() + # Set the NMNE capture config + set_nmne_config(cfg["simulation"]["network"].get("nmne_config", {})) + return game diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index fa135674..c0e69e60 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -17,6 +17,15 @@ from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.domain.account import Account from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.nmne import ( + CAPTURE_BY_DIRECTION, + CAPTURE_BY_IP_ADDRESS, + CAPTURE_BY_KEYWORD, + CAPTURE_BY_PORT, + CAPTURE_BY_PROTOCOL, + CAPTURE_NMNE, + NMNE_CAPTURE_KEYWORDS, +) from primaite.simulator.network.transmission.data_link_layer import Frame from primaite.simulator.system.applications.application import Application from primaite.simulator.system.core.packet_capture import PacketCapture @@ -88,6 +97,8 @@ class NetworkInterface(SimComponent, ABC): pcap: Optional[PacketCapture] = None "A PacketCapture instance for capturing and analysing packets passing through this interface." + nmne: Dict = Field(default_factory=lambda: {}) + def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() @@ -111,27 +122,99 @@ class NetworkInterface(SimComponent, ABC): "enabled": self.enabled, } ) + state.update({"nmne": self.nmne}) return state def reset_component_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" super().reset_component_for_episode(episode) + self.nmne = {} if episode and self.pcap: self.pcap.current_episode = episode self.pcap.setup_logger() self.enable() - @abstractmethod + # @abstractmethod def enable(self): """Enable the interface.""" pass - @abstractmethod + # @abstractmethod def disable(self): """Disable the interface.""" pass - @abstractmethod + def _capture_nmne(self, frame: Frame, inbound: bool = True): + """ + Processes and captures network frame data based on predefined global NMNE settings. + + This method updates the NMNE structure with counts of malicious network events based on the frame content and + direction. The structure is dynamically adjusted according to the enabled capture settings. + + :param frame: The network frame to process, containing IP, TCP/UDP, and payload information. + :param inbound: Boolean indicating if the frame direction is inbound. Defaults to True. + """ + # Exit function if NMNE capturing is disabled + if not CAPTURE_NMNE: + return + + # Initialise basic frame data variables + direction = "inbound" if inbound else "outbound" # Direction of the traffic + ip_address = str(frame.ip.src_ip_address if inbound else frame.ip.dst_ip_address) # Source or destination IP + protocol = frame.ip.protocol.name # Network protocol used in the frame + + # Initialise port variable; will be determined based on protocol type + port = None + + # Determine the source or destination port based on the protocol (TCP/UDP) + if frame.tcp: + port = frame.tcp.src_port.value if inbound else frame.tcp.dst_port.value + elif frame.udp: + port = frame.udp.src_port.value if inbound else frame.udp.dst_port.value + + # Convert frame payload to string for keyword checking + frame_str = str(frame.payload) + + # Proceed only if any NMNE keyword is present in the frame payload + if any(keyword in frame_str for keyword in NMNE_CAPTURE_KEYWORDS): + # Start with the root of the NMNE capture structure + current_level = self.nmne + + # Update NMNE structure based on enabled settings + if CAPTURE_BY_DIRECTION: + # Set or get the dictionary for the current direction + current_level = current_level.setdefault("direction", {}) + current_level = current_level.setdefault(direction, {}) + + if CAPTURE_BY_IP_ADDRESS: + # Set or get the dictionary for the current IP address + current_level = current_level.setdefault("ip_address", {}) + current_level = current_level.setdefault(ip_address, {}) + + if CAPTURE_BY_PROTOCOL: + # Set or get the dictionary for the current protocol + current_level = current_level.setdefault("protocol", {}) + current_level = current_level.setdefault(protocol, {}) + + if CAPTURE_BY_PORT: + # Set or get the dictionary for the current port + current_level = current_level.setdefault("port", {}) + current_level = current_level.setdefault(port, {}) + + # Ensure 'KEYWORD' level is present in the structure + keyword_level = current_level.setdefault("keywords", {}) + + # Increment the count for detected keywords in the payload + if CAPTURE_BY_KEYWORD: + for keyword in NMNE_CAPTURE_KEYWORDS: + if keyword in frame_str: + # Update the count for each keyword found + keyword_level[keyword] = keyword_level.get(keyword, 0) + 1 + else: + # Increment a generic counter if keyword capturing is not enabled + keyword_level["*"] = keyword_level.get("*", 0) + 1 + + # @abstractmethod def send_frame(self, frame: Frame) -> bool: """ Attempts to send a network frame through the interface. @@ -139,9 +222,9 @@ class NetworkInterface(SimComponent, ABC): :param frame: The network frame to be sent. :return: A boolean indicating whether the frame was successfully sent. """ - pass + self._capture_nmne(frame, inbound=False) - @abstractmethod + # @abstractmethod def receive_frame(self, frame: Frame) -> bool: """ Receives a network frame on the interface. @@ -149,7 +232,7 @@ class NetworkInterface(SimComponent, ABC): :param frame: The network frame being received. :return: A boolean indicating whether the frame was successfully received. """ - pass + self._capture_nmne(frame, inbound=True) def __str__(self) -> str: """ @@ -263,6 +346,7 @@ class WiredNetworkInterface(NetworkInterface, ABC): :param frame: The network frame to be sent. :return: True if the frame is sent, False if the Network Interface is disabled or not connected to a link. """ + super().send_frame(frame) if self.enabled: frame.set_sent_timestamp() self.pcap.capture_outbound(frame) @@ -279,7 +363,7 @@ class WiredNetworkInterface(NetworkInterface, ABC): :param frame: The network frame being received. :return: A boolean indicating whether the frame was successfully received. """ - pass + return super().receive_frame(frame) class Layer3Interface(BaseModel, ABC): @@ -409,7 +493,7 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): except AttributeError: pass - # @abstractmethod + @abstractmethod def receive_frame(self, frame: Frame) -> bool: """ Receives a network frame on the network interface. @@ -417,7 +501,7 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): :param frame: The network frame being received. :return: A boolean indicating whether the frame was successfully received. """ - pass + return super().receive_frame(frame) class Link(SimComponent): diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index 3f34f736..6ecd6733 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -248,6 +248,7 @@ class NIC(IPWiredNetworkInterface): accept_frame = True if accept_frame: + super().receive_frame(frame) self._connected_node.receive_frame(frame=frame, from_network_interface=self) return True return False diff --git a/src/primaite/simulator/network/nmne.py b/src/primaite/simulator/network/nmne.py new file mode 100644 index 00000000..d4c40631 --- /dev/null +++ b/src/primaite/simulator/network/nmne.py @@ -0,0 +1,46 @@ +from typing import Dict, Final, List + +CAPTURE_NMNE: bool = True +"""Indicates whether Malicious Network Events (MNEs) should be captured. Default is True.""" + +NMNE_CAPTURE_KEYWORDS: List[str] = [] +"""List of keywords to identify malicious network events.""" + +CAPTURE_BY_DIRECTION: Final[bool] = True +"""Flag to determine if captures should be organized by traffic direction (inbound/outbound).""" +CAPTURE_BY_IP_ADDRESS: Final[bool] = False +"""Flag to determine if captures should be organized by source or destination IP address.""" +CAPTURE_BY_PROTOCOL: Final[bool] = False +"""Flag to determine if captures should be organized by network protocol (e.g., TCP, UDP).""" +CAPTURE_BY_PORT: Final[bool] = False +"""Flag to determine if captures should be organized by source or destination port.""" +CAPTURE_BY_KEYWORD: Final[bool] = False +"""Flag to determine if captures should be filtered and categorised based on specific keywords.""" + + +def set_nmne_config(nmne_config: Dict): + """ + Sets the configuration for capturing Malicious Network Events (MNEs) based on a provided dictionary. + + This function updates global settings related to NMNE capture, including whether to capture NMNEs and what + keywords to use for identifying NMNEs. + + The function ensures that the settings are updated only if they are provided in the `nmne_config` dictionary, + and maintains type integrity by checking the types of the provided values. + + :param nmne_config: A dictionary containing the NMNE configuration settings. Possible keys include: + "capture_nmne" (bool) to indicate whether NMNEs should be captured, "nmne_capture_keywords" (list of strings) + to specify keywords for NMNE identification. + """ + global NMNE_CAPTURE_KEYWORDS + global CAPTURE_NMNE + + # Update the NMNE capture flag, defaulting to False if not specified or if the type is incorrect + CAPTURE_NMNE = nmne_config.get("capture_nmne", False) + if not isinstance(CAPTURE_NMNE, bool): + CAPTURE_NMNE = True # Revert to default True if the provided value is not a boolean + + # Update the NMNE capture keywords, appending new keywords if provided + NMNE_CAPTURE_KEYWORDS += nmne_config.get("nmne_capture_keywords", []) + if not isinstance(NMNE_CAPTURE_KEYWORDS, list): + NMNE_CAPTURE_KEYWORDS = [] # Reset to empty list if the provided value is not a list diff --git a/tests/integration_tests/network/test_capture_nmne.py b/tests/integration_tests/network/test_capture_nmne.py new file mode 100644 index 00000000..85ac23e8 --- /dev/null +++ b/tests/integration_tests/network/test_capture_nmne.py @@ -0,0 +1,120 @@ +from primaite.game.agent.observations import NicObservation +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.nmne import set_nmne_config +from primaite.simulator.sim_container import Simulation +from primaite.simulator.system.applications.database_client import DatabaseClient + + +def test_capture_nmne(uc2_network): + """ + Conducts a test to verify that Malicious Network Events (MNEs) are correctly captured. + + This test involves a web server querying a database server and checks if the MNEs are captured + based on predefined keywords in the network configuration. Specifically, it checks the capture + of the "DELETE" SQL command as a malicious network event. + """ + web_server: Server = uc2_network.get_node_by_hostname("web_server") # noqa + db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] # noqa + db_client.connect() + + db_server: Server = uc2_network.get_node_by_hostname("database_server") # noqa + + web_server_nic = web_server.network_interface[1] + db_server_nic = db_server.network_interface[1] + + # Set the NMNE configuration to capture DELETE queries as MNEs + nmne_config = { + "capture_nmne": True, # Enable the capture of MNEs + "nmne_capture_keywords": ["DELETE"], # Specify "DELETE" SQL command as a keyword for MNE detection + } + + # Apply the NMNE configuration settings + set_nmne_config(nmne_config) + + # Assert that initially, there are no captured MNEs on both web and database servers + assert web_server_nic.describe_state()["nmne"] == {} + assert db_server_nic.describe_state()["nmne"] == {} + + # Perform a "SELECT" query + db_client.query("SELECT") + + # Check that it does not trigger an MNE capture. + assert web_server_nic.describe_state()["nmne"] == {} + assert db_server_nic.describe_state()["nmne"] == {} + + # Perform a "DELETE" query + db_client.query("DELETE") + + # Check that the web server's outbound interface and the database server's inbound interface register the MNE + assert web_server_nic.describe_state()["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}} + assert db_server_nic.describe_state()["nmne"] == {"direction": {"inbound": {"keywords": {"*": 1}}}} + + # Perform another "SELECT" query + db_client.query("SELECT") + + # Check that no additional MNEs are captured + assert web_server_nic.describe_state()["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}} + assert db_server_nic.describe_state()["nmne"] == {"direction": {"inbound": {"keywords": {"*": 1}}}} + + # Perform another "DELETE" query + db_client.query("DELETE") + + # Check that the web server and database server interfaces register an additional MNE + assert web_server_nic.describe_state()["nmne"] == {"direction": {"outbound": {"keywords": {"*": 2}}}} + assert db_server_nic.describe_state()["nmne"] == {"direction": {"inbound": {"keywords": {"*": 2}}}} + + +def test_capture_nmne_observations(uc2_network): + """ + Tests the NicObservation class's functionality within a simulated network environment. + + This test ensures the observation space, as defined by instances of NicObservation, accurately reflects the + number of MNEs detected based on network activities over multiple iterations. + + The test employs a series of "DELETE" SQL operations, considered as MNEs, to validate the dynamic update + and accuracy of the observation space related to network interface conditions. It confirms that the + observed NIC states match expected MNE activity levels. + """ + # Initialise a new Simulation instance and assign the test network to it. + sim = Simulation() + sim.network = uc2_network + + web_server: Server = uc2_network.get_node_by_hostname("web_server") + db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] + db_client.connect() + + # Set the NMNE configuration to capture DELETE queries as MNEs + nmne_config = { + "capture_nmne": True, # Enable the capture of MNEs + "nmne_capture_keywords": ["DELETE"], # Specify "DELETE" SQL command as a keyword for MNE detection + } + + # Apply the NMNE configuration settings + set_nmne_config(nmne_config) + + # Define observations for the NICs of the database and web servers + db_server_nic_obs = NicObservation(where=["network", "nodes", "database_server", "NICs", 1]) + web_server_nic_obs = NicObservation(where=["network", "nodes", "web_server", "NICs", 1]) + + # Iterate through a set of test cases to simulate multiple DELETE queries + for i in range(1, 20): + # Perform a "DELETE" query each iteration + db_client.query("DELETE") + + # Observe the current state of NMNEs from the NICs of both the database and web servers + db_nic_obs = db_server_nic_obs.observe(sim.describe_state())["nmne"] + web_nic_obs = web_server_nic_obs.observe(sim.describe_state())["nmne"] + + # Define expected NMNE values based on the iteration count + if i > 10: + expected_nmne = 3 # High level of detected MNEs after 10 iterations + elif i > 5: + expected_nmne = 2 # Moderate level after more than 5 iterations + elif i > 0: + expected_nmne = 1 # Low level detected after just starting + else: + expected_nmne = 0 # No MNEs detected + + # Assert that the observed NMNEs match the expected values for both NICs + assert web_nic_obs["outbound"] == expected_nmne + assert db_nic_obs["inbound"] == expected_nmne From 5836ea68e339d59ffc9c6f56f472bb8dea2477cf Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 23 Feb 2024 08:55:32 +0000 Subject: [PATCH 619/980] #2257: rearrange software pages + creating a list of applications and services which is hopefully a single point that should be referred to --- docs/conf.py | 5 ++ docs/source/config.rst | 4 +- docs/source/configuration/simulation.rst | 2 + .../simulation/nodes/firewall.rst | 4 ++ .../simulation/software/applications.rst | 34 ++++----- .../applications/data_manipulation_bot.rst | 8 --- .../software/applications/database_client.rst | 8 --- .../software/applications/web_browser.rst | 8 --- .../software/common/system_software.rst | 12 ---- .../simulation/software/services.rst | 40 ++++------- .../software/services/database_service.rst | 8 --- .../software/services/dns_client.rst | 8 --- .../software/services/dns_server.rst | 8 --- .../software/services/ftp_client.rst | 8 --- .../software/services/ftp_server.rst | 8 --- .../software/services/ntp_client.rst | 8 --- .../software/services/ntp_server.rst | 8 --- .../software/services/web_server.rst | 8 --- docs/source/game_layer.rst | 2 +- .../network/network_interfaces.rst | 2 + .../network/nodes/firewall.rst | 2 +- .../network/nodes/network_node.rst | 2 +- .../data_manipulation_bot.rst | 1 + .../system/applications/database_client.rst | 38 ++++++++++ .../system}/applications/dos_bot.rst | 4 +- .../web_browser.rst} | 30 +------- .../system/database_client_server.rst | 71 ------------------- .../system/list_of_applications.rst | 11 +++ .../system/list_of_services.rst | 15 ++++ .../system/list_of_system_applications.rst | 19 +++++ .../system/list_of_system_services.rst | 21 ++++++ .../system/services/database_service.rst | 33 +++++++++ .../dns_client.rst} | 30 +------- .../system/services/dns_server.rst | 26 +++++++ .../ftp_client.rst} | 30 +------- .../system/services/ftp_server.rst | 27 +++++++ .../system/services/ntp_client.rst | 26 +++++++ .../ntp_server.rst} | 30 +------- .../system/services/web_server.rst | 27 +++++++ .../system/session_and_software_manager.rst | 2 + .../simulation_components/system/software.rst | 31 +++++--- docs/source/simulation_structure.rst | 11 +-- 42 files changed, 329 insertions(+), 351 deletions(-) delete mode 100644 docs/source/configuration/simulation/software/applications/data_manipulation_bot.rst delete mode 100644 docs/source/configuration/simulation/software/applications/database_client.rst delete mode 100644 docs/source/configuration/simulation/software/applications/web_browser.rst delete mode 100644 docs/source/configuration/simulation/software/common/system_software.rst delete mode 100644 docs/source/configuration/simulation/software/services/database_service.rst delete mode 100644 docs/source/configuration/simulation/software/services/dns_client.rst delete mode 100644 docs/source/configuration/simulation/software/services/dns_server.rst delete mode 100644 docs/source/configuration/simulation/software/services/ftp_client.rst delete mode 100644 docs/source/configuration/simulation/software/services/ftp_server.rst delete mode 100644 docs/source/configuration/simulation/software/services/ntp_client.rst delete mode 100644 docs/source/configuration/simulation/software/services/ntp_server.rst delete mode 100644 docs/source/configuration/simulation/software/services/web_server.rst rename docs/source/simulation_components/system/{ => applications}/data_manipulation_bot.rst (99%) create mode 100644 docs/source/simulation_components/system/applications/database_client.rst rename docs/source/{configuration/simulation/software => simulation_components/system}/applications/dos_bot.rst (82%) rename docs/source/simulation_components/system/{web_browser_and_web_server_service.rst => applications/web_browser.rst} (72%) delete mode 100644 docs/source/simulation_components/system/database_client_server.rst create mode 100644 docs/source/simulation_components/system/list_of_applications.rst create mode 100644 docs/source/simulation_components/system/list_of_services.rst create mode 100644 docs/source/simulation_components/system/list_of_system_applications.rst create mode 100644 docs/source/simulation_components/system/list_of_system_services.rst create mode 100644 docs/source/simulation_components/system/services/database_service.rst rename docs/source/simulation_components/system/{dns_client_server.rst => services/dns_client.rst} (52%) create mode 100644 docs/source/simulation_components/system/services/dns_server.rst rename docs/source/simulation_components/system/{ftp_client_server.rst => services/ftp_client.rst} (78%) create mode 100644 docs/source/simulation_components/system/services/ftp_server.rst create mode 100644 docs/source/simulation_components/system/services/ntp_client.rst rename docs/source/simulation_components/system/{ntp_client_server.rst => services/ntp_server.rst} (56%) create mode 100644 docs/source/simulation_components/system/services/web_server.rst diff --git a/docs/conf.py b/docs/conf.py index 6cdc0ac4..d246afe5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,6 +27,11 @@ with open("../src/primaite/VERSION", "r") as file: # The full version, including alpha/beta/rc tags release = version +# set global variables +rst_prolog = f""" +.. |VERSION| replace:: {release} +""" + html_title = f"{project} v{release} docs" # -- General configuration --------------------------------------------------- diff --git a/docs/source/config.rst b/docs/source/config.rst index b7bce731..89181a24 100644 --- a/docs/source/config.rst +++ b/docs/source/config.rst @@ -2,8 +2,8 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -Primaite v3 config -****************** +PrimAITE |VERSION| Configuration +******************************** PrimAITE uses a single configuration file to define everything needed to train and evaluate an RL policy in a custom cybersecurity scenario. This includes the configuration of the network, the scripted or trained agents that interact with the network, as well as settings that define how to perform training in Stable Baselines 3 or Ray RLLib. The entire config is used by the ``PrimaiteSession`` object for users who wish to let PrimAITE handle the agent definition and training. If you wish to define custom agents and control the training loop yourself, you can use the config with the ``PrimaiteGame``, and ``PrimaiteGymEnv`` objects instead. That way, only the network configuration and agent setup parts of the config are used, and the training section is ignored. diff --git a/docs/source/configuration/simulation.rst b/docs/source/configuration/simulation.rst index 7bb079e9..f24cc41d 100644 --- a/docs/source/configuration/simulation.rst +++ b/docs/source/configuration/simulation.rst @@ -49,6 +49,8 @@ In order to recreate the network below, we will need to create 2 links: - a link from computer_2 to the switch .. image:: ../../_static/switched_p2p_network.png + :width: 500 + :align: center this results in: diff --git a/docs/source/configuration/simulation/nodes/firewall.rst b/docs/source/configuration/simulation/nodes/firewall.rst index b1e4e5e1..c8a21a02 100644 --- a/docs/source/configuration/simulation/nodes/firewall.rst +++ b/docs/source/configuration/simulation/nodes/firewall.rst @@ -106,9 +106,13 @@ There are 6 ACLs that can be defined for a firewall - ``external_outbound_acl`` for traffic going towards the external network .. image:: ../../../../_static/firewall_acl.png + :width: 500 + :align: center By default, ``external_inbound_acl`` and ``external_outbound_acl`` will permit any traffic through. +``internal_inbound_acl``, ``internal_outbound_acl``, ``dmz_inbound_acl`` and ``dmz_outbound_acl`` will deny any traffic by default, so must be configured to allow defined ``src_port`` and ``dst_port`` or ``protocol``. + See :py:mod:`primaite.simulator.network.hardware.nodes.network.router.AccessControlList` See :ref:`List of Ports ` for a list of ports. diff --git a/docs/source/configuration/simulation/software/applications.rst b/docs/source/configuration/simulation/software/applications.rst index 7acde817..90ae3ec1 100644 --- a/docs/source/configuration/simulation/software/applications.rst +++ b/docs/source/configuration/simulation/software/applications.rst @@ -5,27 +5,21 @@ ``applications`` ---------------- -List of available applications that can be installed on a |NODE|: +List of available applications that can be installed on a |NODE| can be found in :ref:`List of Applications ` -.. toctree:: - :maxdepth: 1 +application in configuration +"""""""""""""""""""""""""""" - ../software/applications/data_manipulation_bot.rst - ../software/applications/database_client.rst - ../software/applications/dos_bot.rst - ../software/applications/web_browser.rst +Applications takes a list of applications as shown in the example below. -More info :py:mod:`primaite.game.game.APPLICATION_TYPES_MAPPING` +.. code-block:: yaml -.. include:: ../software/common/system_software.rst - - -.. toctree:: - :maxdepth: 1 - - ../software/applications/web_browser.rst - -More info :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.SYSTEM_SOFTWARE` - -.. |SOFTWARE_TYPE| replace:: application -.. |SOFTWARE_TYPES| replace:: applications + - ref: client_1 + hostname: client_1 + type: computer + ... + applications: + - ref: example_application + type: example_application_type + options: + # this section is different for each application diff --git a/docs/source/configuration/simulation/software/applications/data_manipulation_bot.rst b/docs/source/configuration/simulation/software/applications/data_manipulation_bot.rst deleted file mode 100644 index 6b650cf7..00000000 --- a/docs/source/configuration/simulation/software/applications/data_manipulation_bot.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``DataManipulationBot`` ------------------------ - -test diff --git a/docs/source/configuration/simulation/software/applications/database_client.rst b/docs/source/configuration/simulation/software/applications/database_client.rst deleted file mode 100644 index 81e827bc..00000000 --- a/docs/source/configuration/simulation/software/applications/database_client.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``DatabaseClient`` ------------------- - -test diff --git a/docs/source/configuration/simulation/software/applications/web_browser.rst b/docs/source/configuration/simulation/software/applications/web_browser.rst deleted file mode 100644 index 4af0d7b7..00000000 --- a/docs/source/configuration/simulation/software/applications/web_browser.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``WebBrowser`` --------------- - -test diff --git a/docs/source/configuration/simulation/software/common/system_software.rst b/docs/source/configuration/simulation/software/common/system_software.rst deleted file mode 100644 index 64248272..00000000 --- a/docs/source/configuration/simulation/software/common/system_software.rst +++ /dev/null @@ -1,12 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``system software`` -""""""""""""""""""" - -Some |SOFTWARE_TYPES| are pre installed on nodes - this is similar to how some |SOFTWARE_TYPES| are included with the Operating System. - -The |SOFTWARE_TYPE| may not be configured as needed, in which case, follow the steps above to configure them. - -The list of |SOFTWARE_TYPES| that are considered system software are: diff --git a/docs/source/configuration/simulation/software/services.rst b/docs/source/configuration/simulation/software/services.rst index 383f9de4..88957001 100644 --- a/docs/source/configuration/simulation/software/services.rst +++ b/docs/source/configuration/simulation/software/services.rst @@ -5,33 +5,21 @@ ``services`` ------------ -List of available services that can be installed on a |NODE|: +List of available services that can be installed on a |NODE| can be found in :ref:`List of Services ` -.. toctree:: - :maxdepth: 1 +services in configuration +""""""""""""""""""""""""" - ../software/services/database_service.rst - ../software/services/dns_client.rst - ../software/services/dns_server.rst - ../software/services/ftp_client.rst - ../software/services/ftp_server.rst - ../software/services/ntp_client.rst - ../software/services/ntp_server.rst - ../software/services/web_server.rst +Services takes a list of services as shown in the example below. -More info :py:mod:`primaite.game.game.SERVICE_TYPES_MAPPING` +.. code-block:: yaml -.. include:: ../software/common/system_software.rst - - -.. toctree:: - :maxdepth: 1 - - ../software/services/dns_client.rst - ../software/services/ftp_client.rst - ../software/services/ntp_client.rst - -More info :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.SYSTEM_SOFTWARE` - -.. |SOFTWARE_TYPE| replace:: service -.. |SOFTWARE_TYPES| replace:: services + - ref: client_1 + hostname: client_1 + type: computer + ... + applications: + - ref: example_service + type: example_service_type + options: + # this section is different for each service diff --git a/docs/source/configuration/simulation/software/services/database_service.rst b/docs/source/configuration/simulation/software/services/database_service.rst deleted file mode 100644 index f03fde70..00000000 --- a/docs/source/configuration/simulation/software/services/database_service.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``DatabaseService`` -------------------- - -test diff --git a/docs/source/configuration/simulation/software/services/dns_client.rst b/docs/source/configuration/simulation/software/services/dns_client.rst deleted file mode 100644 index d9b8008d..00000000 --- a/docs/source/configuration/simulation/software/services/dns_client.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``DNSClient`` -------------- - -test diff --git a/docs/source/configuration/simulation/software/services/dns_server.rst b/docs/source/configuration/simulation/software/services/dns_server.rst deleted file mode 100644 index a342967f..00000000 --- a/docs/source/configuration/simulation/software/services/dns_server.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``DNSServer`` -------------- - -test diff --git a/docs/source/configuration/simulation/software/services/ftp_client.rst b/docs/source/configuration/simulation/software/services/ftp_client.rst deleted file mode 100644 index d51a3dc1..00000000 --- a/docs/source/configuration/simulation/software/services/ftp_client.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``FTPClient`` -------------- - -test diff --git a/docs/source/configuration/simulation/software/services/ftp_server.rst b/docs/source/configuration/simulation/software/services/ftp_server.rst deleted file mode 100644 index c7f92340..00000000 --- a/docs/source/configuration/simulation/software/services/ftp_server.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``FTPServer`` -------------- - -test diff --git a/docs/source/configuration/simulation/software/services/ntp_client.rst b/docs/source/configuration/simulation/software/services/ntp_client.rst deleted file mode 100644 index 51b2e061..00000000 --- a/docs/source/configuration/simulation/software/services/ntp_client.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``NTPClient`` -------------- - -test diff --git a/docs/source/configuration/simulation/software/services/ntp_server.rst b/docs/source/configuration/simulation/software/services/ntp_server.rst deleted file mode 100644 index 2efbdf1a..00000000 --- a/docs/source/configuration/simulation/software/services/ntp_server.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``NTPServer`` -------------- - -test diff --git a/docs/source/configuration/simulation/software/services/web_server.rst b/docs/source/configuration/simulation/software/services/web_server.rst deleted file mode 100644 index 4fab660d..00000000 --- a/docs/source/configuration/simulation/software/services/web_server.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``WebServer`` -------------- - -test diff --git a/docs/source/game_layer.rst b/docs/source/game_layer.rst index cdae17dd..eb9b17c3 100644 --- a/docs/source/game_layer.rst +++ b/docs/source/game_layer.rst @@ -18,7 +18,7 @@ Game layer The game layer is responsible for managing agents and getting them to interface with the simulator correctly. It consists of several components: PrimAITE Session -^^^^^^^^^^^^^^^ +^^^^^^^^^^^^^^^^ ``PrimaiteSession`` is the main entry point into Primaite and it allows the simultaneous coordination of a simulation and agents that interact with it. ``PrimaiteSession`` keeps track of multiple agents of different types. diff --git a/docs/source/simulation_components/network/network_interfaces.rst b/docs/source/simulation_components/network/network_interfaces.rst index 9e1ad80a..f3d4d373 100644 --- a/docs/source/simulation_components/network/network_interfaces.rst +++ b/docs/source/simulation_components/network/network_interfaces.rst @@ -13,6 +13,8 @@ facilitates modular development, enhances maintainability, and supports scalabil allowing for focused enhancements within each layer. .. image:: primaite_network_interface_model.png + :width: 500 + :align: center Layer Descriptions ================== diff --git a/docs/source/simulation_components/network/nodes/firewall.rst b/docs/source/simulation_components/network/nodes/firewall.rst index 73168517..2f948081 100644 --- a/docs/source/simulation_components/network/nodes/firewall.rst +++ b/docs/source/simulation_components/network/nodes/firewall.rst @@ -229,7 +229,7 @@ To limit database server access to selected external IP addresses: position=7 ) -**Permitting DMZ Web Server Access while Blocking Specific Threats* +**Permitting DMZ Web Server Access while Blocking Specific Threats** To authorize HTTP/HTTPS access to a DMZ-hosted web server, excluding known malicious IPs: diff --git a/docs/source/simulation_components/network/nodes/network_node.rst b/docs/source/simulation_components/network/nodes/network_node.rst index eb9997ba..33bcea5b 100644 --- a/docs/source/simulation_components/network/nodes/network_node.rst +++ b/docs/source/simulation_components/network/nodes/network_node.rst @@ -27,7 +27,7 @@ in the transmission and routing of data within the simulated environment. **Key Features:** - **Frame Processing:** Central to the class is the ability to receive and process network frames, facilitating the -simulation of data flow through network devices. + simulation of data flow through network devices. - **Abstract Methods:** Includes abstract methods such as ``receive_frame``, which subclasses must implement to specify how devices handle incoming traffic. diff --git a/docs/source/simulation_components/system/data_manipulation_bot.rst b/docs/source/simulation_components/system/applications/data_manipulation_bot.rst similarity index 99% rename from docs/source/simulation_components/system/data_manipulation_bot.rst rename to docs/source/simulation_components/system/applications/data_manipulation_bot.rst index 1fd5e5c8..8c326b56 100644 --- a/docs/source/simulation_components/system/data_manipulation_bot.rst +++ b/docs/source/simulation_components/system/applications/data_manipulation_bot.rst @@ -16,6 +16,7 @@ The bot is intended to simulate a malicious actor carrying out attacks like: - Dropping tables - Deleting records - Modifying data + on a database server by abusing an application's trusted database connectivity. The bot performs attacks in the following stages to simulate the real pattern of an attack: diff --git a/docs/source/simulation_components/system/applications/database_client.rst b/docs/source/simulation_components/system/applications/database_client.rst new file mode 100644 index 00000000..47690cb6 --- /dev/null +++ b/docs/source/simulation_components/system/applications/database_client.rst @@ -0,0 +1,38 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + + +DatabaseClient +=============== + +The DatabaseClient provides a client interface for connecting to the ``DatabaseService``. + +Key features +^^^^^^^^^^^^ + +- Connects to the ``DatabaseService`` via the ``SoftwareManager``. +- Handles connecting and disconnecting. +- Executes SQL queries and retrieves result sets. + +Usage +^^^^^ + +- Initialise with server IP address and optional password. +- Connect to the ``DatabaseService`` with ``connect``. +- Retrieve results in a dictionary. +- Disconnect when finished. + +To create database backups: + +- Configure the backup server on the ``DatabaseService`` by providing the Backup server ``IPv4Address`` with ``configure_backup`` +- Create a backup using ``backup_database``. This fails if the backup server is not configured. +- Restore a backup using ``restore_backup``. By default, this uses the database created via ``backup_database``. + +Implementation +^^^^^^^^^^^^^^ + +- Leverages ``SoftwareManager`` for sending payloads over the network. +- Connect and disconnect methods manage sessions. +- Payloads serialised as dictionaries for transmission. +- Extends base Application class. diff --git a/docs/source/configuration/simulation/software/applications/dos_bot.rst b/docs/source/simulation_components/system/applications/dos_bot.rst similarity index 82% rename from docs/source/configuration/simulation/software/applications/dos_bot.rst rename to docs/source/simulation_components/system/applications/dos_bot.rst index 98939e5b..6aa849a7 100644 --- a/docs/source/configuration/simulation/software/applications/dos_bot.rst +++ b/docs/source/simulation_components/system/applications/dos_bot.rst @@ -2,7 +2,7 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -``DoSBot`` ----------- +DoSBot +------ test diff --git a/docs/source/simulation_components/system/web_browser_and_web_server_service.rst b/docs/source/simulation_components/system/applications/web_browser.rst similarity index 72% rename from docs/source/simulation_components/system/web_browser_and_web_server_service.rst rename to docs/source/simulation_components/system/applications/web_browser.rst index 538baa58..ee4e8b94 100644 --- a/docs/source/simulation_components/system/web_browser_and_web_server_service.rst +++ b/docs/source/simulation_components/system/applications/web_browser.rst @@ -2,35 +2,9 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -Web Browser and Web Server Service -================================== -Web Server Service ------------------- -Provides a Web Server simulation by extending the base Service class. - -Key capabilities -^^^^^^^^^^^^^^^^ - -- Simulates a web server with the capability to also request data from a database -- Allows the emulation of HTTP requests between client (e.g. a web browser) and server - - GET request sends a get all users request to the database server and returns an HTTP 200 status if the database is responsive -- Leverages the Service base class for install/uninstall, status tracking, etc. - -Usage -^^^^^ -- Install on a Node via the ``SoftwareManager`` to start the `WebServer`. -- Service runs on HTTP port 80 by default. (TODO: HTTPS) - -Implementation -^^^^^^^^^^^^^^ - -- HTTP request uses a ``HttpRequestPacket`` object -- HTTP response uses a ``HttpResponsePacket`` object -- Extends Service class for integration with ``SoftwareManager``. - -Web Browser (Web Client) ------------------------- +WebBrowser +========== The ``WebBrowser`` provides a client interface for connecting to the ``WebServer``. diff --git a/docs/source/simulation_components/system/database_client_server.rst b/docs/source/simulation_components/system/database_client_server.rst deleted file mode 100644 index 07912f3e..00000000 --- a/docs/source/simulation_components/system/database_client_server.rst +++ /dev/null @@ -1,71 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - - -Database Client Server -====================== - -Database Service ----------------- - -The ``DatabaseService`` provides a SQL database server simulation by extending the base Service class. - -Key capabilities -^^^^^^^^^^^^^^^^ - -- Creates a database file in the ``Node`` 's ``FileSystem`` upon creation. -- Handles connecting clients by maintaining a dictionary of connections mapped to session IDs. -- Authenticates connections using a configurable password. -- Simulates ``SELECT``, ``DELETE`` and ``INSERT`` SQL queries. -- Returns query results and status codes back to clients. -- Leverages the Service base class for install/uninstall, status tracking, etc. - -Usage -^^^^^ -- Install on a Node via the ``SoftwareManager`` to start the database service. -- Clients connect, execute queries, and disconnect. -- Service runs on TCP port 5432 by default. - -Implementation -^^^^^^^^^^^^^^ - -- Creates the database file within the node's file system. -- Manages client connections in a dictionary by session ID. -- Processes SQL queries. -- Returns results and status codes in a standard dictionary format. -- Extends Service class for integration with ``SoftwareManager``. - -Database Client ---------------- - -The DatabaseClient provides a client interface for connecting to the ``DatabaseService``. - -Key features -^^^^^^^^^^^^ - -- Connects to the ``DatabaseService`` via the ``SoftwareManager``. -- Handles connecting and disconnecting. -- Executes SQL queries and retrieves result sets. - -Usage -^^^^^ - -- Initialise with server IP address and optional password. -- Connect to the ``DatabaseService`` with ``connect``. -- Retrieve results in a dictionary. -- Disconnect when finished. - -To create database backups: - -- Configure the backup server on the ``DatabaseService`` by providing the Backup server ``IPv4Address`` with ``configure_backup`` -- Create a backup using ``backup_database``. This fails if the backup server is not configured. -- Restore a backup using ``restore_backup``. By default, this uses the database created via ``backup_database``. - -Implementation -^^^^^^^^^^^^^^ - -- Leverages ``SoftwareManager`` for sending payloads over the network. -- Connect and disconnect methods manage sessions. -- Payloads serialised as dictionaries for transmission. -- Extends base Application class. diff --git a/docs/source/simulation_components/system/list_of_applications.rst b/docs/source/simulation_components/system/list_of_applications.rst new file mode 100644 index 00000000..9aac23de --- /dev/null +++ b/docs/source/simulation_components/system/list_of_applications.rst @@ -0,0 +1,11 @@ +.. toctree:: + :maxdepth: 1 + + applications/data_manipulation_bot.rst + applications/database_client.rst + applications/dos_bot.rst + applications/web_browser.rst + +More info :py:mod:`primaite.game.game.APPLICATION_TYPES_MAPPING` + +.. include:: list_of_system_applications.rst diff --git a/docs/source/simulation_components/system/list_of_services.rst b/docs/source/simulation_components/system/list_of_services.rst new file mode 100644 index 00000000..07bc25ee --- /dev/null +++ b/docs/source/simulation_components/system/list_of_services.rst @@ -0,0 +1,15 @@ +.. toctree:: + :maxdepth: 1 + + services/database_service.rst + services/dns_client.rst + services/dns_server.rst + services/ftp_client.rst + services/ftp_server.rst + services/ntp_client.rst + services/ntp_server.rst + services/web_server.rst + +More info :py:mod:`primaite.game.game.SERVICE_TYPES_MAPPING` + +.. include:: list_of_system_services.rst diff --git a/docs/source/simulation_components/system/list_of_system_applications.rst b/docs/source/simulation_components/system/list_of_system_applications.rst new file mode 100644 index 00000000..ca5a7457 --- /dev/null +++ b/docs/source/simulation_components/system/list_of_system_applications.rst @@ -0,0 +1,19 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``system applications`` +""""""""""""""""""""""" + +Some applications are pre installed on nodes - this is similar to how some applications are included with the Operating System. + +The application may not be configured as needed, in which case, see the relevant application page. + +The list of applications that are considered system software are: + +.. toctree:: + :maxdepth: 1 + + applications/web_browser.rst + +More info :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.SYSTEM_SOFTWARE` diff --git a/docs/source/simulation_components/system/list_of_system_services.rst b/docs/source/simulation_components/system/list_of_system_services.rst new file mode 100644 index 00000000..657faa52 --- /dev/null +++ b/docs/source/simulation_components/system/list_of_system_services.rst @@ -0,0 +1,21 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +``system services`` +""""""""""""""""""" + +Some services are pre installed on nodes - this is similar to how some services are included with the Operating System. + +The service may not be configured as needed, in which case, see the relevant service page. + +The list of services that are considered system software are: + +.. toctree:: + :maxdepth: 1 + + services/dns_client.rst + services/ftp_client.rst + services/ntp_client.rst + +More info :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.SYSTEM_SOFTWARE` diff --git a/docs/source/simulation_components/system/services/database_service.rst b/docs/source/simulation_components/system/services/database_service.rst new file mode 100644 index 00000000..a4591d15 --- /dev/null +++ b/docs/source/simulation_components/system/services/database_service.rst @@ -0,0 +1,33 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +DatabaseService +=============== + +The ``DatabaseService`` provides a SQL database server simulation by extending the base Service class. + +Key capabilities +^^^^^^^^^^^^^^^^ + +- Creates a database file in the ``Node`` 's ``FileSystem`` upon creation. +- Handles connecting clients by maintaining a dictionary of connections mapped to session IDs. +- Authenticates connections using a configurable password. +- Simulates ``SELECT``, ``DELETE`` and ``INSERT`` SQL queries. +- Returns query results and status codes back to clients. +- Leverages the Service base class for install/uninstall, status tracking, etc. + +Usage +^^^^^ +- Install on a Node via the ``SoftwareManager`` to start the database service. +- Clients connect, execute queries, and disconnect. +- Service runs on TCP port 5432 by default. + +Implementation +^^^^^^^^^^^^^^ + +- Creates the database file within the node's file system. +- Manages client connections in a dictionary by session ID. +- Processes SQL queries. +- Returns results and status codes in a standard dictionary format. +- Extends Service class for integration with ``SoftwareManager``. diff --git a/docs/source/simulation_components/system/dns_client_server.rst b/docs/source/simulation_components/system/services/dns_client.rst similarity index 52% rename from docs/source/simulation_components/system/dns_client_server.rst rename to docs/source/simulation_components/system/services/dns_client.rst index f57f903b..f961ece3 100644 --- a/docs/source/simulation_components/system/dns_client_server.rst +++ b/docs/source/simulation_components/system/services/dns_client.rst @@ -2,34 +2,8 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -DNS Client Server -================= - -DNS Server ----------- -Also known as a DNS Resolver, the ``DNSServer`` provides a DNS Server simulation by extending the base Service class. - -Key capabilities -^^^^^^^^^^^^^^^^ - -- Simulates DNS requests and DNSPacket transfer across a network -- Registers domain names and the IP Address linked to the domain name -- Returns the IP address for a given domain name within a DNS Packet that a DNS Client can read -- Leverages the Service base class for install/uninstall, status tracking, etc. - -Usage -^^^^^ -- Install on a Node via the ``SoftwareManager`` to start the database service. -- Service runs on TCP port 53 by default. (TODO: TCP for now, should be UDP in future) - -Implementation -^^^^^^^^^^^^^^ - -- DNS request and responses use a ``DNSPacket`` object -- Extends Service class for integration with ``SoftwareManager``. - -DNS Client ----------- +DNSClient +========= The DNSClient provides a client interface for connecting to the ``DNSServer``. diff --git a/docs/source/simulation_components/system/services/dns_server.rst b/docs/source/simulation_components/system/services/dns_server.rst new file mode 100644 index 00000000..ef463d9a --- /dev/null +++ b/docs/source/simulation_components/system/services/dns_server.rst @@ -0,0 +1,26 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +DNSServer +========= +Also known as a DNS Resolver, the ``DNSServer`` provides a DNS Server simulation by extending the base Service class. + +Key capabilities +^^^^^^^^^^^^^^^^ + +- Simulates DNS requests and DNSPacket transfer across a network +- Registers domain names and the IP Address linked to the domain name +- Returns the IP address for a given domain name within a DNS Packet that a DNS Client can read +- Leverages the Service base class for install/uninstall, status tracking, etc. + +Usage +^^^^^ +- Install on a Node via the ``SoftwareManager`` to start the database service. +- Service runs on TCP port 53 by default. (TODO: TCP for now, should be UDP in future) + +Implementation +^^^^^^^^^^^^^^ + +- DNS request and responses use a ``DNSPacket`` object +- Extends Service class for integration with ``SoftwareManager``. diff --git a/docs/source/simulation_components/system/ftp_client_server.rst b/docs/source/simulation_components/system/services/ftp_client.rst similarity index 78% rename from docs/source/simulation_components/system/ftp_client_server.rst rename to docs/source/simulation_components/system/services/ftp_client.rst index a544b4c8..77111938 100644 --- a/docs/source/simulation_components/system/ftp_client_server.rst +++ b/docs/source/simulation_components/system/services/ftp_client.rst @@ -2,35 +2,9 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -FTP Client Server -================= -FTP Server ----------- -Provides a FTP Client-Server simulation by extending the base Service class. - -Key capabilities -^^^^^^^^^^^^^^^^ - -- Simulates FTP requests and FTPPacket transfer across a network -- Allows the emulation of FTP commands between an FTP client and server: - - STOR: stores a file from client to server - - RETR: retrieves a file from the FTP server -- Leverages the Service base class for install/uninstall, status tracking, etc. - -Usage -^^^^^ -- Install on a Node via the ``SoftwareManager`` to start the FTP server service. -- Service runs on FTP (command) port 21 by default. (TODO: look at in depth implementation of FTP PORT command) - -Implementation -^^^^^^^^^^^^^^ - -- FTP request and responses use a ``FTPPacket`` object -- Extends Service class for integration with ``SoftwareManager``. - -FTP Client ----------- +FTPClient +========= The ``FTPClient`` provides a client interface for connecting to the ``FTPServer``. diff --git a/docs/source/simulation_components/system/services/ftp_server.rst b/docs/source/simulation_components/system/services/ftp_server.rst new file mode 100644 index 00000000..81f51e6b --- /dev/null +++ b/docs/source/simulation_components/system/services/ftp_server.rst @@ -0,0 +1,27 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +FTPServer +========= +Provides a FTP Client-Server simulation by extending the base Service class. + +Key capabilities +^^^^^^^^^^^^^^^^ + +- Simulates FTP requests and FTPPacket transfer across a network +- Allows the emulation of FTP commands between an FTP client and server: + - STOR: stores a file from client to server + - RETR: retrieves a file from the FTP server +- Leverages the Service base class for install/uninstall, status tracking, etc. + +Usage +^^^^^ +- Install on a Node via the ``SoftwareManager`` to start the FTP server service. +- Service runs on FTP (command) port 21 by default. (TODO: look at in depth implementation of FTP PORT command) + +Implementation +^^^^^^^^^^^^^^ + +- FTP request and responses use a ``FTPPacket`` object +- Extends Service class for integration with ``SoftwareManager``. diff --git a/docs/source/simulation_components/system/services/ntp_client.rst b/docs/source/simulation_components/system/services/ntp_client.rst new file mode 100644 index 00000000..27cd27e4 --- /dev/null +++ b/docs/source/simulation_components/system/services/ntp_client.rst @@ -0,0 +1,26 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +NTPClient +========= + +The NTPClient provides a client interface for connecting to the ``NTPServer``. + +Key features +^^^^^^^^^^^^ + +- Connects to the ``NTPServer`` via the ``SoftwareManager``. + +Usage +^^^^^ + +- Install on a Node via the ``SoftwareManager`` to start the database service. +- Service runs on UDP port 123 by default. + +Implementation +^^^^^^^^^^^^^^ + +- Leverages ``SoftwareManager`` for sending payloads over the network. +- Provides easy interface for Nodes to find IP addresses via domain names. +- Extends base Service class. diff --git a/docs/source/simulation_components/system/ntp_client_server.rst b/docs/source/simulation_components/system/services/ntp_server.rst similarity index 56% rename from docs/source/simulation_components/system/ntp_client_server.rst rename to docs/source/simulation_components/system/services/ntp_server.rst index b6d57c13..066ad5ac 100644 --- a/docs/source/simulation_components/system/ntp_client_server.rst +++ b/docs/source/simulation_components/system/services/ntp_server.rst @@ -2,11 +2,8 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -NTP Client Server -================= - -NTP Server ----------- +NTPServer +========= The ``NTPServer`` provides a NTP Server simulation by extending the base Service class. NTP Client @@ -29,26 +26,3 @@ Implementation - NTP request and responses use a ``NTPPacket`` object - Extends Service class for integration with ``SoftwareManager``. - -NTP Client ----------- - -The NTPClient provides a client interface for connecting to the ``NTPServer``. - -Key features -^^^^^^^^^^^^ - -- Connects to the ``NTPServer`` via the ``SoftwareManager``. - -Usage -^^^^^ - -- Install on a Node via the ``SoftwareManager`` to start the database service. -- Service runs on UDP port 123 by default. - -Implementation -^^^^^^^^^^^^^^ - -- Leverages ``SoftwareManager`` for sending payloads over the network. -- Provides easy interface for Nodes to find IP addresses via domain names. -- Extends base Service class. diff --git a/docs/source/simulation_components/system/services/web_server.rst b/docs/source/simulation_components/system/services/web_server.rst new file mode 100644 index 00000000..ae3f32e6 --- /dev/null +++ b/docs/source/simulation_components/system/services/web_server.rst @@ -0,0 +1,27 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +WebServer +========= +Provides a Web Server simulation by extending the base Service class. + +Key capabilities +^^^^^^^^^^^^^^^^ + +- Simulates a web server with the capability to also request data from a database +- Allows the emulation of HTTP requests between client (e.g. a web browser) and server + - GET request sends a get all users request to the database server and returns an HTTP 200 status if the database is responsive +- Leverages the Service base class for install/uninstall, status tracking, etc. + +Usage +^^^^^ +- Install on a Node via the ``SoftwareManager`` to start the `WebServer`. +- Service runs on HTTP port 80 by default. (TODO: HTTPS) + +Implementation +^^^^^^^^^^^^^^ + +- HTTP request uses a ``HttpRequestPacket`` object +- HTTP response uses a ``HttpResponsePacket`` object +- Extends Service class for integration with ``SoftwareManager``. diff --git a/docs/source/simulation_components/system/session_and_software_manager.rst b/docs/source/simulation_components/system/session_and_software_manager.rst index a550faf1..8af96e87 100644 --- a/docs/source/simulation_components/system/session_and_software_manager.rst +++ b/docs/source/simulation_components/system/session_and_software_manager.rst @@ -16,6 +16,8 @@ ARP, ICMP, or the Web Client. This pathway exemplifies the structured processing each frame reaches its intended target within the simulated environment. .. image:: node_session_software_model_example.png + :width: 500 + :align: center Session Manager --------------- diff --git a/docs/source/simulation_components/system/software.rst b/docs/source/simulation_components/system/software.rst index 7a1359f4..459064f0 100644 --- a/docs/source/simulation_components/system/software.rst +++ b/docs/source/simulation_components/system/software.rst @@ -39,16 +39,27 @@ See :ref:`Node Start up and Shut down` assert node.operating_state is NodeOperatingState.ON assert web_server.operating_state is ServiceOperatingState.RUNNING # service turned back on when node is powered on +.. _List of Applications: -Services, Processes and Applications: -##################################### +Applications +############ -.. toctree:: - :maxdepth: 2 +These are a list of applications that are currently available in PrimAITE: - database_client_server - data_manipulation_bot - dns_client_server - ftp_client_server - ntp_client_server - web_browser_and_web_server_service +.. include:: list_of_applications.rst + +.. _List of Services: + +Services +######## + +These are a list of services that are currently available in PrimAITE: + +.. include:: list_of_services.rst + +.. _List of Processes: + +Processes +######### + +`To be implemented` diff --git a/docs/source/simulation_structure.rst b/docs/source/simulation_structure.rst index 6e0ab5ce..f9a69b26 100644 --- a/docs/source/simulation_structure.rst +++ b/docs/source/simulation_structure.rst @@ -12,14 +12,15 @@ and a domain controller for managing software and users. Each node of the simulation 'tree' has responsibility for creating, deleting, and updating its direct descendants. Also, when a component's ``describe_state()`` method is called, it will include the state of its descendants. The -``apply_request()`` method can be used to act on a component or one of its descendatnts. The diagram below shows the +``apply_request()`` method can be used to act on a component or one of its descendants. The diagram below shows the relationship between components. -.. image:: _static/component_relationship.png +.. image:: ../../_static/component_relationship.png :width: 500 - :alt: The top level simulation object owns a NetworkContainer and a DomainController. The DomainController has a - list of accounts. The network container has links and nodes. Nodes can own switchports, NICs, FileSystem, - Application, Service, and Process. + :align: center + :alt: :: The top level simulation object owns a NetworkContainer and a DomainController. The DomainController has a + list of accounts. The network container has links and nodes. Nodes can own switchports, NICs, FileSystem, + Application, Service, and Process. Actions From f933341df521feaca5e494bf739833b86d75ab28 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 23 Feb 2024 10:06:48 +0000 Subject: [PATCH 620/980] eod commit --- src/primaite/game/game.py | 10 ---------- src/primaite/simulator/core.py | 8 ++++++-- src/primaite/simulator/network/container.py | 8 ++++---- src/primaite/simulator/network/hardware/base.py | 14 +++++++------- .../simulator/network/hardware/nodes/router.py | 10 +++++----- src/primaite/simulator/sim_container.py | 4 ++-- 6 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index bd7ed2cd..72ad01e7 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -160,16 +160,6 @@ class PrimaiteGame: return True return False - def reset(self) -> None: # TODO: deprecated - remove me - """Reset the game, this will reset the simulation.""" - self.episode_counter += 1 - self.step_counter = 0 - _LOGGER.debug(f"Resetting primaite game, episode = {self.episode_counter}") - self.simulation.reset_component_for_episode(episode=self.episode_counter) - for agent in self.agents: - agent.reward_function.total_reward = 0.0 - agent.reset_agent_for_episode() - def close(self) -> None: """Close the game, this will close the simulation.""" return NotImplemented diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index e21ce9eb..b9188bf0 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -160,8 +160,12 @@ class SimComponent(BaseModel): self._request_manager: RequestManager = self._init_request_manager() self._parent: Optional["SimComponent"] = None - def reset_component_for_episode(self, episode: int): - """Reset the original state of the SimComponent.""" + def setup_for_episode(self, episode: int): + """ + Perform any additional setup on this component that can't happen during __init__. + + For instance, some components may require for the entire network to exist before some configuration can be set. + """ pass def _init_request_manager(self) -> RequestManager: diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 48205bbd..080a1004 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -45,12 +45,12 @@ class Network(SimComponent): self._nx_graph = MultiGraph() - def reset_component_for_episode(self, episode: int): + def setup_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" for node in self.nodes.values(): - node.reset_component_for_episode(episode) + node.setup_for_episode(episode) for link in self.links.values(): - link.reset_component_for_episode(episode) + link.setup_for_episode(episode) for node in self.nodes.values(): node.power_on() @@ -171,7 +171,7 @@ class Network(SimComponent): def clear_links(self): """Clear all the links in the network by resetting their component state for the episode.""" for link in self.links.values(): - link.reset_component_for_episode() + link.setup_for_episode() def draw(self, seed: int = 123): """ diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 67ac42c8..e2a90db1 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -123,9 +123,9 @@ class NIC(SimComponent): _LOGGER.error(msg) raise ValueError(msg) - def reset_component_for_episode(self, episode: int): + def setup_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - super().reset_component_for_episode(episode) + super().setup_for_episode(episode) if episode and self.pcap: self.pcap.current_episode = episode self.pcap.setup_logger() @@ -1011,19 +1011,19 @@ class Node(SimComponent): self.session_manager.software_manager = self.software_manager self._install_system_software() - def reset_component_for_episode(self, episode: int): + def setup_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - super().reset_component_for_episode(episode) + super().setup_for_episode(episode) # Reset File System - self.file_system.reset_component_for_episode(episode) + self.file_system.setup_for_episode(episode) # Reset all Nics for nic in self.nics.values(): - nic.reset_component_for_episode(episode) + nic.setup_for_episode(episode) for software in self.software_manager.software.values(): - software.reset_component_for_episode(episode) + software.setup_for_episode(episode) if episode and self.sys_log: self.sys_log.current_episode = episode diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index aa154ad9..887bc9be 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -743,16 +743,16 @@ class Router(Node): self.arp.nics = self.nics self.icmp.arp = self.arp - def reset_component_for_episode(self, episode: int): + def setup_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" self.arp.clear() - self.acl.reset_component_for_episode(episode) - self.route_table.reset_component_for_episode(episode) + self.acl.setup_for_episode(episode) + self.route_table.setup_for_episode(episode) for i, nic in self.ethernet_ports.items(): - nic.reset_component_for_episode(episode) + nic.setup_for_episode(episode) self.enable_port(i) - super().reset_component_for_episode(episode) + super().setup_for_episode(episode) def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index 18ed894c..bb6132a8 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -21,9 +21,9 @@ class Simulation(SimComponent): super().__init__(**kwargs) - def reset_component_for_episode(self, episode: int): + def setup_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - self.network.reset_component_for_episode(episode) + self.network.setup_for_episode(episode) def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() From 52677538a89f9f5c5ffa88b72e0b0e0415f85cc6 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 23 Feb 2024 15:12:46 +0000 Subject: [PATCH 621/980] #2238 - Tidied up code, added more docstrings, and implemented suggestions from PR. --- .../network/network_interfaces.rst | 2 +- src/primaite/game/agent/observations.py | 4 +--- .../simulator/network/hardware/base.py | 18 ++++++++++++------ .../network/hardware/nodes/host/host_node.py | 6 +----- src/primaite/simulator/network/nmne.py | 1 + 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/docs/source/simulation_components/network/network_interfaces.rst b/docs/source/simulation_components/network/network_interfaces.rst index c74b54ae..2bb8dda4 100644 --- a/docs/source/simulation_components/network/network_interfaces.rst +++ b/docs/source/simulation_components/network/network_interfaces.rst @@ -71,7 +71,7 @@ Network Interface Classes - Malicious Network Events Monitoring: * Enhances network interfaces with the capability to monitor and capture Malicious Network Events (MNEs) based on predefined criteria such as specific keywords or traffic patterns. - * Integrates NMNE detection functionalities, leveraging configurable settings like ``capture_nmne``, `nmne_capture_keywords``, and observation mechanisms such as ``NicObservation`` to classify and record network anomalies. + * Integrates Number of Malicious Network Events (NMNE) detection functionalities, leveraging configurable settings like ``capture_nmne``, `nmne_capture_keywords``, and observation mechanisms such as ``NicObservation`` to classify and record network anomalies. * Offers an additional layer of security and data analysis, crucial for identifying and mitigating malicious activities within the network infrastructure. Provides vital information for network security analysis and reinforcement learning algorithms. **WiredNetworkInterface (Connection Type Layer)** diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 1d8799fd..7ccc3f11 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -352,8 +352,6 @@ class NicObservation(AbstractObservation): """The default NIC observation dict.""" data = {"nic_status": 0} - if CAPTURE_NMNE: - data.update({"nmne": {"inbound": 0, "outbound": 0}}) return data def __init__(self, where: Optional[Tuple[str]] = None) -> None: @@ -407,7 +405,7 @@ class NicObservation(AbstractObservation): return self.default_observation else: obs_dict = {"nic_status": 1 if nic_state["enabled"] else 2, "nmne": {}} - if CAPTURE_NMNE: + if CAPTURE_NMNE and nic_state.get("nmne"): direction_dict = nic_state["nmne"].get("direction", {}) inbound_keywords = direction_dict.get("inbound", {}).get("keywords", {}) inbound_count = inbound_keywords.get("*", 0) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index c0e69e60..b22bea25 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -98,6 +98,7 @@ class NetworkInterface(SimComponent, ABC): "A PacketCapture instance for capturing and analysing packets passing through this interface." nmne: Dict = Field(default_factory=lambda: {}) + "A dict containing details of the number of malicious network events captured." def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() @@ -122,7 +123,6 @@ class NetworkInterface(SimComponent, ABC): "enabled": self.enabled, } ) - state.update({"nmne": self.nmne}) return state def reset_component_for_episode(self, episode: int): @@ -134,23 +134,29 @@ class NetworkInterface(SimComponent, ABC): self.pcap.setup_logger() self.enable() - # @abstractmethod + @abstractmethod def enable(self): """Enable the interface.""" pass - # @abstractmethod + @abstractmethod def disable(self): """Disable the interface.""" pass - def _capture_nmne(self, frame: Frame, inbound: bool = True): + def _capture_nmne(self, frame: Frame, inbound: bool = True) -> None: """ Processes and captures network frame data based on predefined global NMNE settings. This method updates the NMNE structure with counts of malicious network events based on the frame content and direction. The structure is dynamically adjusted according to the enabled capture settings. + .. note:: + While there is a lot of logic in this code that defines a multi-level hierarchical NMNE structure, + most of it is unused for now as a result of all `CAPTURE_BY_<>` variables in + ``primaite.simulator.network.nmne`` being hardcoded and set as final. Once they're 'released' and made + configurable, this function will be updated to properly explain the dynamic data structure. + :param frame: The network frame to process, containing IP, TCP/UDP, and payload information. :param inbound: Boolean indicating if the frame direction is inbound. Defaults to True. """ @@ -214,7 +220,7 @@ class NetworkInterface(SimComponent, ABC): # Increment a generic counter if keyword capturing is not enabled keyword_level["*"] = keyword_level.get("*", 0) + 1 - # @abstractmethod + @abstractmethod def send_frame(self, frame: Frame) -> bool: """ Attempts to send a network frame through the interface. @@ -224,7 +230,7 @@ class NetworkInterface(SimComponent, ABC): """ self._capture_nmne(frame, inbound=False) - # @abstractmethod + @abstractmethod def receive_frame(self, frame: Frame) -> bool: """ Receives a network frame on the interface. diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index 6ecd6733..8e104924 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -205,11 +205,7 @@ class NIC(IPWiredNetworkInterface): state = super().describe_state() # Update the state with NIC-specific information - state.update( - { - "wake_on_lan": self.wake_on_lan, - } - ) + state.update({"wake_on_lan": self.wake_on_lan, "nmne": self.nmne}) return state diff --git a/src/primaite/simulator/network/nmne.py b/src/primaite/simulator/network/nmne.py index d4c40631..87839712 100644 --- a/src/primaite/simulator/network/nmne.py +++ b/src/primaite/simulator/network/nmne.py @@ -6,6 +6,7 @@ CAPTURE_NMNE: bool = True NMNE_CAPTURE_KEYWORDS: List[str] = [] """List of keywords to identify malicious network events.""" +# TODO: Remove final and make configurable after example layout when the NicObservation creates nmne structure dynamically CAPTURE_BY_DIRECTION: Final[bool] = True """Flag to determine if captures should be organized by traffic direction (inbound/outbound).""" CAPTURE_BY_IP_ADDRESS: Final[bool] = False From fb148dc4fb100ae50545913094537bc5b7dfa3b2 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 23 Feb 2024 16:49:01 +0000 Subject: [PATCH 622/980] #2257: applications and services docs --- docs/source/configuration/simulation.rst | 7 +- .../simulation_components/network/network.rst | 10 +- .../applications/data_manipulation_bot.rst | 92 +++++++++-- .../system/applications/database_client.rst | 90 +++++++++- .../system/applications/dos_bot.rst | 156 +++++++++++++++++- .../system/applications/web_browser.rst | 103 +++++++----- .../system/common/common_configuration.rst | 14 ++ .../system/list_of_applications.rst | 8 +- .../system/list_of_services.rst | 12 +- .../system/list_of_system_applications.rst | 5 +- .../system/list_of_system_services.rst | 9 +- .../system/services/database_service.rst | 84 +++++++++- .../system/services/dns_client.rst | 83 +++++++++- .../system/services/dns_server.rst | 80 ++++++++- .../system/services/ftp_client.rst | 103 +++++------- .../system/services/ftp_server.rst | 74 ++++++++- .../system/services/ntp_client.rst | 77 ++++++++- .../system/services/ntp_server.rst | 68 +++++++- .../system/services/web_server.rst | 67 +++++++- src/primaite/game/game.py | 3 +- .../services/database/database_service.py | 3 + 21 files changed, 956 insertions(+), 192 deletions(-) create mode 100644 docs/source/simulation_components/system/common/common_configuration.rst diff --git a/docs/source/configuration/simulation.rst b/docs/source/configuration/simulation.rst index f24cc41d..89c1669b 100644 --- a/docs/source/configuration/simulation.rst +++ b/docs/source/configuration/simulation.rst @@ -29,12 +29,9 @@ To see the configuration for these nodes, refer to the following: .. toctree:: :maxdepth: 1 + :glob: - simulation/nodes/computer.rst - simulation/nodes/firewall.rst - simulation/nodes/router.rst - simulation/nodes/server.rst - simulation/nodes/switch.rst + simulation/nodes/* ``links`` --------- diff --git a/docs/source/simulation_components/network/network.rst b/docs/source/simulation_components/network/network.rst index 533a15f2..36e8ee48 100644 --- a/docs/source/simulation_components/network/network.rst +++ b/docs/source/simulation_components/network/network.rst @@ -30,11 +30,11 @@ we'll use the following Network that has a client, server, two switches, and a r .. code-block:: python from primaite.simulator.network.container import Network - from primaite.simulator.network.hardware.base import NIC - from primaite.simulator.network.hardware.nodes.computer import Computer - from primaite.simulator.network.hardware.nodes.router import Router, ACLAction - from primaite.simulator.network.hardware.nodes.server import Server - from primaite.simulator.network.hardware.nodes.switch import Switch + from primaite.simulator.network.hardware.base import NetworkInterface + from primaite.simulator.network.hardware.nodes.host.computer import Computer + from primaite.simulator.network.hardware.nodes.network.router import Router, ACLAction + from primaite.simulator.network.hardware.nodes.host.server import Server + from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port diff --git a/docs/source/simulation_components/system/applications/data_manipulation_bot.rst b/docs/source/simulation_components/system/applications/data_manipulation_bot.rst index 8c326b56..209cdcbd 100644 --- a/docs/source/simulation_components/system/applications/data_manipulation_bot.rst +++ b/docs/source/simulation_components/system/applications/data_manipulation_bot.rst @@ -2,14 +2,15 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _DataManipulationBot: DataManipulationBot -=================== +################### -The ``DataManipulationBot`` class provides functionality to connect to a ``DatabaseService`` and execute malicious SQL statements. +The ``DataManipulationBot`` class provides functionality to connect to a :ref:`DatabaseService` and execute malicious SQL statements. Overview --------- +======== The bot is intended to simulate a malicious actor carrying out attacks like: @@ -28,7 +29,7 @@ The bot performs attacks in the following stages to simulate the real pattern of Each of these stages has a random, configurable probability of succeeding (by default 10%). The bot can also be configured to repeat the attack once complete. Usage ------ +===== - Create an instance and call ``configure`` to set: - Target database server IP @@ -41,16 +42,35 @@ The bot handles connecting, executing the statement, and disconnecting. In a simulation, the bot can be controlled by using ``DataManipulationAgent`` which calls ``run`` on the bot at configured timesteps. -Example -------- +Implementation +============== + +The bot extends :ref:`DatabaseClient` and leverages its connectivity. + +- Uses the Application base class for lifecycle management. +- Credentials, target IP and other options set via ``configure``. +- ``run`` handles connecting, executing statement, and disconnecting. +- SQL payload executed via ``query`` method. +- Results in malicious SQL being executed on remote database server. + + +Examples +======== + +Python +"""""" .. code-block:: python + from primaite.simulator.network.hardware.nodes.host.computer import Computer + from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState + from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot + client_1 = Computer( hostname="client_1", ip_address="192.168.10.21", subnet_mask="255.255.255.0", - default_gateway="192.168.10.1" + default_gateway="192.168.10.1", operating_state=NodeOperatingState.ON # initialise the computer in an ON state ) network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1]) @@ -62,13 +82,13 @@ Example This would connect to the database service at 192.168.1.14, authenticate, and execute the SQL statement to drop the 'users' table. Example with ``DataManipulationAgent`` -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +"""""""""""""""""""""""""""""""""""""" If not using the data manipulation bot manually, it needs to be used with a data manipulation agent. Below is an example section of configuration file for setting up a simulation with data manipulation bot and agent. .. code-block:: yaml - game_config: + game: # ... agents: - ref: data_manipulation_red_bot @@ -129,13 +149,51 @@ If not using the data manipulation bot manually, it needs to be used with a data payload: "DELETE" server_ip: 192.168.1.14 -Implementation --------------- +Configuration +============= -The bot extends ``DatabaseClient`` and leverages its connectivity. +.. include:: ../common/common_configuration.rst -- Uses the Application base class for lifecycle management. -- Credentials, target IP and other options set via ``configure``. -- ``run`` handles connecting, executing statement, and disconnecting. -- SQL payload executed via ``query`` method. -- Results in malicious SQL being executed on remote database server. +.. |SOFTWARE_NAME| replace:: DataManipulationBot +.. |SOFTWARE_NAME_BACKTICK| replace:: ``DataManipulationBot`` + +``server_ip`` +""""""""""""" + +IP address of the :ref:`DatabaseService` which the ``DataManipulationBot`` will try to attack. + +This must be a valid octet i.e. in the range of ``0.0.0.0`` and ``255.255.255.255``. + +``server_password`` +""""""""""""""""""" + +Optional. Default value is ``None``. + +The password that the ``DataManipulationBot`` will use to access the :ref:`DatabaseService`. + +``payload`` +""""""""""" + +Optional. Default value is ``DELETE``. + +The payload that the ``DataManipulationBot`` will send to the :ref:`DatabaseService`. + +See :ref:`Database Payload List` + +``port_scan_p_of_success`` +"""""""""""""""""""""""""" + +Optional. Default value is ``0.1``. + +The chance of the ``DataManipulationBot`` to succeed with a port scan (and therefore continue the attack). + +This must be a float value between ``0`` and ``1``. + +``data_manipulation_p_of_success`` +"""""""""""""""""""""""""""""""""" + +Optional. Default value is ``0.1``. + +The chance of the ``DataManipulationBot`` to succeed with a data manipulation attack. + +This must be a float value between ``0`` and ``1``. diff --git a/docs/source/simulation_components/system/applications/database_client.rst b/docs/source/simulation_components/system/applications/database_client.rst index 47690cb6..61d955f2 100644 --- a/docs/source/simulation_components/system/applications/database_client.rst +++ b/docs/source/simulation_components/system/applications/database_client.rst @@ -2,37 +2,111 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _DatabaseClient: DatabaseClient -=============== +############## -The DatabaseClient provides a client interface for connecting to the ``DatabaseService``. +The ``DatabaseClient`` provides a client interface for connecting to the :ref:`DatabaseService`. Key features -^^^^^^^^^^^^ +============ -- Connects to the ``DatabaseService`` via the ``SoftwareManager``. +- Connects to the :ref:`DatabaseService` via the ``SoftwareManager``. - Handles connecting and disconnecting. - Executes SQL queries and retrieves result sets. Usage -^^^^^ +===== - Initialise with server IP address and optional password. -- Connect to the ``DatabaseService`` with ``connect``. +- Connect to the :ref:`DatabaseService` with ``connect``. - Retrieve results in a dictionary. - Disconnect when finished. To create database backups: -- Configure the backup server on the ``DatabaseService`` by providing the Backup server ``IPv4Address`` with ``configure_backup`` +- Configure the backup server on the :ref:`DatabaseService` by providing the Backup server ``IPv4Address`` with ``configure_backup`` - Create a backup using ``backup_database``. This fails if the backup server is not configured. - Restore a backup using ``restore_backup``. By default, this uses the database created via ``backup_database``. Implementation -^^^^^^^^^^^^^^ +============== - Leverages ``SoftwareManager`` for sending payloads over the network. - Connect and disconnect methods manage sessions. - Payloads serialised as dictionaries for transmission. - Extends base Application class. + +Examples +======== + +Python +"""""" + +.. code-block:: python + + from ipaddress import IPv4Address + + from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState + from primaite.simulator.network.hardware.nodes.host.computer import Computer + from primaite.simulator.system.applications.database_client import DatabaseClient + + client = Computer( + hostname="client", + ip_address="192.168.10.21", + subnet_mask="255.255.255.0", + default_gateway="192.168.10.1", + operating_state=NodeOperatingState.ON # initialise the computer in an ON state + ) + + # install DatabaseClient + client.software_manager.install(DatabaseClient) + + database_client: DatabaseClient = client.software_manager.software.get("DatabaseClient") + + # Configure the DatabaseClient + database_client.configure(server_ip_address=IPv4Address("192.168.0.1")) # address of the DatabaseService + database_client.run() + + +Via Configuration +""""""""""""""""" + +.. code-block:: yaml + + simulation: + network: + nodes: + - ref: example_computer + hostname: example_computer + type: computer + ... + applications: + - ref: database_client + type: DatabaseClient + options: + db_server_ip: 192.168.0.1 + +Configuration +============= + +.. include:: ../common/common_configuration.rst + +.. |SOFTWARE_NAME| replace:: DatabaseClient +.. |SOFTWARE_NAME_BACKTICK| replace:: ``DatabaseClient`` + + +``db_server_ip`` +"""""""""""""""" + +IP address of the :ref:`DatabaseService` that the ``DatabaseClient`` will connect to + +This must be a valid octet i.e. in the range of ``0.0.0.0`` and ``255.255.255.255``. + +``server_password`` +""""""""""""""""""" + +Optional. Default value is ``None``. + +The password that the ``DatabaseClient`` will use to access the :ref:`DatabaseService`. diff --git a/docs/source/simulation_components/system/applications/dos_bot.rst b/docs/source/simulation_components/system/applications/dos_bot.rst index 6aa849a7..fcf3f207 100644 --- a/docs/source/simulation_components/system/applications/dos_bot.rst +++ b/docs/source/simulation_components/system/applications/dos_bot.rst @@ -2,7 +2,157 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -DoSBot ------- +.. _DoSBot: -test +DoSBot +###### + +The ``DoSBot`` is an implementation of a Denial of Service attack within the PrimAITE simulation. This specifically simulates a `Slow Loris attack `. + +Key features +============ + +- Connects to the :ref:`DatabaseService` via the ``SoftwareManager``. +- Makes many connections to the :ref:`DatabaseService` which ends up using up the available connections. + +Usage +===== + +- Configure with target IP address and optional password. +- use ``run`` to run the application_loop of DoSBot to begin attacks +- DoSBot runs through different actions at each timestep + +Implementation +============== + +- Leverages :ref:`DatabaseClient` to create connections with :ref`DatabaseServer`. +- Extends base Application class. + +Examples +======== + +Python +"""""" + +.. code-block:: python + + from ipaddress import IPv4Address + + from primaite.simulator.network.hardware.nodes.host.computer import Computer + from primaite.simulator.system.applications.red_applications.dos_bot import DoSBot + + # Create Computer + computer = Computer( + hostname="computer", + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + computer.power_on() + + # Install DoSBot on computer + computer.software_manager.install(DoSBot) + dos_bot: DoSBot = computer.software_manager.software.get("DoSBot") + + # Configure the DoSBot + dos_bot.configure( + target_ip_address=IPv4Address("192.168.0.10"), + payload="SPOOF DATA", + repeat=False, + port_scan_p_of_success=0.8, + dos_intensity=1.0, + max_sessions=1000 + ) + + # run DoSBot + dos_bot.run() + + +Via Configuration +""""""""""""""""" + +.. code-block:: yaml + + simulation: + network: + nodes: + - ref: example_computer + hostname: example_computer + type: computer + ... + applications: + - ref: dos_bot + type: DoSBot + options: + target_ip_address: 192.168.0.10 + payload: SPOOF DATA + repeat: False + port_scan_p_of_success: 0.8 + dos_intensity: 1.0 + max_sessions: 1000 + +Configuration +============= + +.. include:: ../common/common_configuration.rst + +.. |SOFTWARE_NAME| replace:: DoSBot +.. |SOFTWARE_NAME_BACKTICK| replace:: ``DoSBot`` + +``target_ip_address`` +""""""""""""""""""""" + +IP address of the :ref:`DatabaseService` which the ``DataManipulationBot`` will try to attack. + +This must be a valid octet i.e. in the range of ``0.0.0.0`` and ``255.255.255.255``. + +``target_port`` +""""""""""""""" + +Optional. Default value is ``5432``. + +Port of the target service. + +See :ref:`List of IPProtocols ` for a list of protocols. + +``payload`` +""""""""""" + +Optional. Default value is ``None``. + +The payload that the ``DoSBot`` sends as part of its attack. + +``repeat`` +"""""""""" + +Optional. Default value is ``False``. + +If ``True`` the ``DoSBot`` will maintain its attack. + +``port_scan_p_of_success`` +"""""""""""""""""""""""""" + +Optional. Default value is ``0.1``. + +The chance of the ``DoSBot`` to succeed with a port scan (and therefore continue the attack). + +This must be a float value between ``0`` and ``1``. + +``dos_intensity`` +""""""""""""""""" + +Optional. Default value is ``1.0``. + +The intensity of the Denial of Service attack. This is multiplied by the number of ``max_sessions``. + +This must be a float value between ``0`` and ``1``. + +``max_sessions`` +"""""""""""""""" + +Optional. Default value is ``1000``. + +The maximum number of sessions the ``DoSBot`` is able to make. + +This must be an integer value above equal to or greater than ``0``. diff --git a/docs/source/simulation_components/system/applications/web_browser.rst b/docs/source/simulation_components/system/applications/web_browser.rst index ee4e8b94..c46089ba 100644 --- a/docs/source/simulation_components/system/applications/web_browser.rst +++ b/docs/source/simulation_components/system/applications/web_browser.rst @@ -2,16 +2,17 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _WebBrowser: WebBrowser -========== +########## -The ``WebBrowser`` provides a client interface for connecting to the ``WebServer``. +The ``WebBrowser`` provides a client interface for connecting to the :ref:`WebServer`. Key features -^^^^^^^^^^^^ +============ -- Connects to the ``WebServer`` via the ``SoftwareManager``. +- Connects to the :ref:`WebServer` via the ``SoftwareManager``. - Simulates HTTP requests and HTTP packet transfer across a network - Allows the emulation of HTTP requests between client and server: - Automatically uses ``DNSClient`` to resolve domain names @@ -19,66 +20,92 @@ Key features - Leverages the Service base class for install/uninstall, status tracking, etc. Usage -^^^^^ +===== - Install on a Node via the ``SoftwareManager`` to start the ``WebBrowser``. - Service runs on HTTP port 80 by default. (TODO: HTTPS) - Execute sending an HTTP GET request with ``get_webpage`` Implementation -^^^^^^^^^^^^^^ +============== - Leverages ``SoftwareManager`` for sending payloads over the network. - Provides easy interface for making HTTP requests between an HTTP client and server. - Extends base Service class. -Example Usage -------------- +Examples +======== -Dependencies -^^^^^^^^^^^^ +Python +"""""" + +The ``WebBrowser`` utilises :ref:`DNSClient` and :ref:`DNSServer` to resolve a URL. + +The :ref:`DNSClient` must be configured to use the :ref:`DNSServer`. The :ref:`DNSServer` should be configured to have the ``WebBrowser`` ``target_url`` within its ``domain_mapping``. .. code-block:: python - from primaite.simulator.network.container import Network - from primaite.simulator.network.hardware.nodes.computer import Computer - from primaite.simulator.network.hardware.nodes.server import Server + from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.system.applications.web_browser import WebBrowser - from primaite.simulator.system.services.web_server.web_server_service import WebServer -Example peer to peer network -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + # Create Computer + computer = Computer( + hostname="computer", + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + computer.power_on() -.. code-block:: python + # Install WebBrowser on computer + computer.software_manager.install(WebBrowser) + web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser") + web_browser.run() - net = Network() + # configure the WebBrowser + web_browser.target_url = "arcd.com" - pc1 = Computer(hostname="pc1", ip_address="192.168.1.50", subnet_mask="255.255.255.0") - srv = Server(hostname="srv", ip_address="192.168.1.10", subnet_mask="255.255.255.0") - pc1.power_on() - srv.power_on() - net.connect(pc1.network_interface[1], srv.network_interface[1]) + # once DNS server is configured with the correct domain mapping + # this should work + web_browser.get_webpage() -Install the Web Server -^^^^^^^^^^^^^^^^^^^^^^ +Via Configuration +""""""""""""""""" -.. code-block:: python +.. code-block:: yaml - # web browser is automatically installed in computer nodes - # IRL this is usually included with an OS - client: WebBrowser = pc1.software_manager.software['WebBrowser'] + simulation: + network: + nodes: + - ref: example_computer + hostname: example_computer + type: computer + ... + applications: + - ref: web_browser + type: WebBrowser + options: + target_url: http://arcd.com/ - # install web server - srv.software_manager.install(WebServer) - webserv: WebServer = srv.software_manager.software['WebServer'] +Configuration +============= -Open the web page -^^^^^^^^^^^^^^^^^ +.. include:: ../common/common_configuration.rst -Using a domain name to connect to a website requires setting up DNS Servers. For this example, it is possible to use the IP address directly +.. |SOFTWARE_NAME| replace:: WebBrowser +.. |SOFTWARE_NAME_BACKTICK| replace:: ``WebBrowser`` -.. code-block:: python +``target_url`` +"""""""""""""" - # check that the get request succeeded - print(client.get_webpage("http://192.168.1.10")) # should be True +The URL that the ``WebBrowser`` will request when ``get_webpage`` is called without parameters. + +The URL can be in any format so long as the domain is within it e.g. + +The domain ``arcd.com`` can be matched by + +- http://arcd.com/ +- http://arcd.com/users/ +- arcd.com diff --git a/docs/source/simulation_components/system/common/common_configuration.rst b/docs/source/simulation_components/system/common/common_configuration.rst new file mode 100644 index 00000000..86991655 --- /dev/null +++ b/docs/source/simulation_components/system/common/common_configuration.rst @@ -0,0 +1,14 @@ +``ref`` +======= + +Human readable name used as reference for the |SOFTWARE_NAME_BACKTICK|. Not used in code. + +``type`` +======== + +The type of software that should be added. To add |SOFTWARE_NAME| this must be |SOFTWARE_NAME_BACKTICK|. + +``options`` +=========== + +The configuration options are the attributes that fall under the options for an application. diff --git a/docs/source/simulation_components/system/list_of_applications.rst b/docs/source/simulation_components/system/list_of_applications.rst index 9aac23de..0ba0c45c 100644 --- a/docs/source/simulation_components/system/list_of_applications.rst +++ b/docs/source/simulation_components/system/list_of_applications.rst @@ -1,11 +1,11 @@ .. toctree:: :maxdepth: 1 + :glob: - applications/data_manipulation_bot.rst - applications/database_client.rst - applications/dos_bot.rst - applications/web_browser.rst + applications/* More info :py:mod:`primaite.game.game.APPLICATION_TYPES_MAPPING` .. include:: list_of_system_applications.rst + +.. |SOFTWARE_TYPE| replace:: application diff --git a/docs/source/simulation_components/system/list_of_services.rst b/docs/source/simulation_components/system/list_of_services.rst index 07bc25ee..e24b26dc 100644 --- a/docs/source/simulation_components/system/list_of_services.rst +++ b/docs/source/simulation_components/system/list_of_services.rst @@ -1,15 +1,11 @@ .. toctree:: :maxdepth: 1 + :glob: - services/database_service.rst - services/dns_client.rst - services/dns_server.rst - services/ftp_client.rst - services/ftp_server.rst - services/ntp_client.rst - services/ntp_server.rst - services/web_server.rst + services/* More info :py:mod:`primaite.game.game.SERVICE_TYPES_MAPPING` .. include:: list_of_system_services.rst + +.. |SOFTWARE_TYPE| replace:: service diff --git a/docs/source/simulation_components/system/list_of_system_applications.rst b/docs/source/simulation_components/system/list_of_system_applications.rst index ca5a7457..fae0f5d4 100644 --- a/docs/source/simulation_components/system/list_of_system_applications.rst +++ b/docs/source/simulation_components/system/list_of_system_applications.rst @@ -11,9 +11,6 @@ The application may not be configured as needed, in which case, see the relevant The list of applications that are considered system software are: -.. toctree:: - :maxdepth: 1 - - applications/web_browser.rst +- ``WebBrowser`` More info :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.SYSTEM_SOFTWARE` diff --git a/docs/source/simulation_components/system/list_of_system_services.rst b/docs/source/simulation_components/system/list_of_system_services.rst index 657faa52..4ff6f245 100644 --- a/docs/source/simulation_components/system/list_of_system_services.rst +++ b/docs/source/simulation_components/system/list_of_system_services.rst @@ -11,11 +11,8 @@ The service may not be configured as needed, in which case, see the relevant ser The list of services that are considered system software are: -.. toctree:: - :maxdepth: 1 - - services/dns_client.rst - services/ftp_client.rst - services/ntp_client.rst +- ``DNSClient`` +- ``FTPClient`` +- ``NTPClient`` More info :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.SYSTEM_SOFTWARE` diff --git a/docs/source/simulation_components/system/services/database_service.rst b/docs/source/simulation_components/system/services/database_service.rst index a4591d15..30d6b3ba 100644 --- a/docs/source/simulation_components/system/services/database_service.rst +++ b/docs/source/simulation_components/system/services/database_service.rst @@ -2,13 +2,15 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _DatabaseService: + DatabaseService -=============== +############### The ``DatabaseService`` provides a SQL database server simulation by extending the base Service class. Key capabilities -^^^^^^^^^^^^^^^^ +================ - Creates a database file in the ``Node`` 's ``FileSystem`` upon creation. - Handles connecting clients by maintaining a dictionary of connections mapped to session IDs. @@ -18,16 +20,90 @@ Key capabilities - Leverages the Service base class for install/uninstall, status tracking, etc. Usage -^^^^^ +===== - Install on a Node via the ``SoftwareManager`` to start the database service. - Clients connect, execute queries, and disconnect. - Service runs on TCP port 5432 by default. Implementation -^^^^^^^^^^^^^^ +============== - Creates the database file within the node's file system. - Manages client connections in a dictionary by session ID. - Processes SQL queries. - Returns results and status codes in a standard dictionary format. - Extends Service class for integration with ``SoftwareManager``. + +Examples +======== + +Python +"""""" + +.. code-block:: python + + from ipaddress import IPv4Address + + from primaite.simulator.network.hardware.nodes.host.server import Server + from primaite.simulator.system.services.database.database_service import DatabaseService + + # Create Server + server = Server( + hostname="server", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + server.power_on() + + # Install DatabaseService on server + server.software_manager.install(DatabaseService) + db_service: DatabaseService = server.software_manager.software.get("DatabaseService") + db_service.start() + + # configure DatabaseService + db_service.configure_backup(IPv4Address("192.168.0.10")) + + +Via Configuration +""""""""""""""""" + +.. code-block:: yaml + + simulation: + network: + nodes: + - ref: example_server + hostname: example_server + type: server + ... + services: + - ref: database_service + type: DatabaseService + options: + backup_server_ip: 192.168.0.10 + +Configuration +============= + +.. include:: ../common/common_configuration.rst + +.. |SOFTWARE_NAME| replace:: DatabaseService +.. |SOFTWARE_NAME_BACKTICK| replace:: ``DatabaseService`` + +``backup_server_ip`` +"""""""""""""""""""" + +Optional. Default value is ``None``. + +The IP Address of the backup server that the ``DatabaseService`` will use to create backups of the database. + +This must be a valid octet i.e. in the range of ``0.0.0.0`` and ``255.255.255.255``. + +``password`` +"""""""""""" + +Optional. Default value is ``None``. + +The password that needs to be provided by connecting clients in order to create a successful connection. diff --git a/docs/source/simulation_components/system/services/dns_client.rst b/docs/source/simulation_components/system/services/dns_client.rst index f961ece3..91461590 100644 --- a/docs/source/simulation_components/system/services/dns_client.rst +++ b/docs/source/simulation_components/system/services/dns_client.rst @@ -2,20 +2,22 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -DNSClient -========= +.. _DNSClient: -The DNSClient provides a client interface for connecting to the ``DNSServer``. +DNSClient +######### + +The DNSClient provides a client interface for connecting to the :ref:`DNSServer`. Key features -^^^^^^^^^^^^ +============ -- Connects to the ``DNSServer`` via the ``SoftwareManager``. +- Connects to the :ref:`DNSServer` via the ``SoftwareManager``. - Executes DNS lookup requests and keeps a cache of known domain name IP addresses. - Handles connection to DNSServer and querying for domain name IP addresses. Usage -^^^^^ +===== - Install on a Node via the ``SoftwareManager`` to start the database service. - Service runs on TCP port 53 by default. (TODO: TCP for now, should be UDP in future) @@ -23,8 +25,75 @@ Usage - ``DNSClient`` will automatically add the IP Address of the domain into its cache Implementation -^^^^^^^^^^^^^^ +============== - Leverages ``SoftwareManager`` for sending payloads over the network. - Provides easy interface for Nodes to find IP addresses via domain names. - Extends base Service class. + +Examples +======== + +Python +"""""" + +.. code-block:: python + + from ipaddress import IPv4Address + + from primaite.simulator.network.hardware.nodes.host.server import Server + from primaite.simulator.system.services.dns.dns_client import DNSClient + + # Create Server + server = Server( + hostname="server", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + server.power_on() + + # Install DNSClient on server + server.software_manager.install(DNSClient) + dns_client: DNSClient = server.software_manager.software.get("DNSClient") + dns_client.start() + + # configure DatabaseService + dns_client.dns_server = IPv4Address("192.168.0.10") + + +Via Configuration +""""""""""""""""" + +.. code-block:: yaml + + simulation: + network: + nodes: + - ref: example_server + hostname: example_server + type: server + ... + services: + - ref: dns_client + type: DNSClient + options: + dns_server: 192.168.0.10 + +Configuration +============= + +.. include:: ../common/common_configuration.rst + +.. |SOFTWARE_NAME| replace:: DNSClient +.. |SOFTWARE_NAME_BACKTICK| replace:: ``DNSClient`` + +``dns_server`` +"""""""""""""" + +Optional. Default value is ``None``. + +The IP Address of the :ref:`DNSServer`. + +This must be a valid octet i.e. in the range of ``0.0.0.0`` and ``255.255.255.255``. diff --git a/docs/source/simulation_components/system/services/dns_server.rst b/docs/source/simulation_components/system/services/dns_server.rst index ef463d9a..89ce7fc1 100644 --- a/docs/source/simulation_components/system/services/dns_server.rst +++ b/docs/source/simulation_components/system/services/dns_server.rst @@ -2,12 +2,15 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _DNSServer: + DNSServer -========= +######### + Also known as a DNS Resolver, the ``DNSServer`` provides a DNS Server simulation by extending the base Service class. Key capabilities -^^^^^^^^^^^^^^^^ +================ - Simulates DNS requests and DNSPacket transfer across a network - Registers domain names and the IP Address linked to the domain name @@ -15,12 +18,81 @@ Key capabilities - Leverages the Service base class for install/uninstall, status tracking, etc. Usage -^^^^^ +===== - Install on a Node via the ``SoftwareManager`` to start the database service. - Service runs on TCP port 53 by default. (TODO: TCP for now, should be UDP in future) Implementation -^^^^^^^^^^^^^^ +============== - DNS request and responses use a ``DNSPacket`` object - Extends Service class for integration with ``SoftwareManager``. + +Examples +======== + +Python +"""""" + +.. code-block:: python + + from ipaddress import IPv4Address + + from primaite.simulator.network.hardware.nodes.host.server import Server + from primaite.simulator.system.services.dns.dns_server import DNSServer + + # Create Server + server = Server( + hostname="server", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + server.power_on() + + # Install DNSServer on server + server.software_manager.install(DNSServer) + dns_server: DNSServer = server.software_manager.software.get("DNSServer") + dns_server.start() + + # configure DatabaseService + dns_server.dns_register("arcd.com", IPv4Address("192.168.10.10")) + + +Via Configuration +""""""""""""""""" + +.. code-block:: yaml + + simulation: + network: + nodes: + - ref: example_server + hostname: example_server + type: server + ... + services: + - ref: dns_server + type: DNSServer + options: + domain_mapping: + arcd.com: 192.168.0.10 + another-example.com: 192.168.10.10 + +Configuration +============= + +.. include:: ../common/common_configuration.rst + +.. |SOFTWARE_NAME| replace:: DNSServer +.. |SOFTWARE_NAME_BACKTICK| replace:: ``DNSServer`` + +domain_mapping +"""""""""""""" + +Domain mapping takes the domain and IP Addresses as a key-value pairs i.e. + +If the domain is "arcd.com" and the IP Address attributed to the domain is 192.168.0.10, then the value should be ``arcd.com: 192.168.0.10`` + +The key must be a string and the IP Address must be a valid octet i.e. in the range of ``0.0.0.0`` and ``255.255.255.255``. diff --git a/docs/source/simulation_components/system/services/ftp_client.rst b/docs/source/simulation_components/system/services/ftp_client.rst index 77111938..82b85770 100644 --- a/docs/source/simulation_components/system/services/ftp_client.rst +++ b/docs/source/simulation_components/system/services/ftp_client.rst @@ -2,16 +2,17 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _FTPClient: FTPClient -========= +######### -The ``FTPClient`` provides a client interface for connecting to the ``FTPServer``. +The ``FTPClient`` provides a client interface for connecting to the :ref:`FTPServer`. Key features -^^^^^^^^^^^^ +============ -- Connects to the ``FTPServer`` via the ``SoftwareManager``. +- Connects to the :ref:`FTPServer` via the ``SoftwareManager``. - Simulates FTP requests and FTPPacket transfer across a network - Allows the emulation of FTP commands between an FTP client and server: - PORT: specifies the port that server should connect to on the client (currently only uses ``Port.FTP``) @@ -21,7 +22,7 @@ Key features - Leverages the Service base class for install/uninstall, status tracking, etc. Usage -^^^^^ +===== - Install on a Node via the ``SoftwareManager`` to start the FTP client service. - Service runs on FTP (command) port 21 by default. (TODO: look at in depth implementation of FTP PORT command) @@ -29,81 +30,61 @@ Usage - Execute retrieving a file from the FTP server with ``request_file`` Implementation -^^^^^^^^^^^^^^ +============== - Leverages ``SoftwareManager`` for sending payloads over the network. - Provides easy interface for Nodes to transfer files between each other. - Extends base Service class. +Examples +======== -Example Usage -------------- - -Dependencies -^^^^^^^^^^^^ +Python +"""""" .. code-block:: python - from ipaddress import IPv4Address - - from primaite.simulator.network.container import Network - from primaite.simulator.network.hardware.nodes.computer import Computer - from primaite.simulator.network.hardware.nodes.server import Server - from primaite.simulator.system.services.ftp.ftp_server import FTPServer + from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.system.services.ftp.ftp_client import FTPClient - from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -Example peer to peer network -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. code-block:: python - - net = Network() - - pc1 = Computer( - hostname="pc1", - ip_address="120.10.10.10", + # Create Server + server = Server( + hostname="server", + ip_address="192.168.2.2", subnet_mask="255.255.255.0", - operating_state=NodeOperatingState.ON # initialise the computer in an ON state + default_gateway="192.168.1.1Ó", + start_up_duration=0, ) - srv = Server( - hostname="srv", - ip_address="120.10.10.20", - subnet_mask="255.255.255.0", - operating_state=NodeOperatingState.ON # initialise the server in an ON state - ) - net.connect(pc1.network_interface[1], srv.network_interface[1]) + server.power_on() -Install the FTP Server -^^^^^^^^^^^^^^^^^^^^^^ + # Install FTPClient on server + server.software_manager.install(FTPClient) + ftp_client: FTPClient = server.software_manager.software.get("FTPClient") + ftp_client.start() -FTP Client should be pre installed on nodes -.. code-block:: python +Via Configuration +""""""""""""""""" - srv.software_manager.install(FTPServer) - ftpserv: FTPServer = srv.software_manager.software['FTPServer'] +.. code-block:: yaml -Setting up the FTP Server -^^^^^^^^^^^^^^^^^^^^^^^^^ + simulation: + network: + nodes: + - ref: example_server + hostname: example_server + type: server + ... + services: + - ref: ftp_client + type: FTPClient -Set up the FTP Server with a file that the client will need to retrieve +Configuration +============= -.. code-block:: python +.. include:: ../common/common_configuration.rst - srv.file_system.create_file('my_file.png') +.. |SOFTWARE_NAME| replace:: FTPClient +.. |SOFTWARE_NAME_BACKTICK| replace:: ``FTPClient`` -Check that file was retrieved -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. code-block:: python - - client.request_file( - src_folder_name='root', - src_file_name='my_file.png', - dest_folder_name='root', - dest_file_name='test.png', - dest_ip_address=IPv4Address("120.10.10.20") - ) - - print(client.get_file(folder_name="root", file_name="test.png")) +**FTPClient has no configuration options** diff --git a/docs/source/simulation_components/system/services/ftp_server.rst b/docs/source/simulation_components/system/services/ftp_server.rst index 81f51e6b..d807a14f 100644 --- a/docs/source/simulation_components/system/services/ftp_server.rst +++ b/docs/source/simulation_components/system/services/ftp_server.rst @@ -2,12 +2,15 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _FTPServer: + FTPServer -========= +######### + Provides a FTP Client-Server simulation by extending the base Service class. Key capabilities -^^^^^^^^^^^^^^^^ +================ - Simulates FTP requests and FTPPacket transfer across a network - Allows the emulation of FTP commands between an FTP client and server: @@ -16,12 +19,75 @@ Key capabilities - Leverages the Service base class for install/uninstall, status tracking, etc. Usage -^^^^^ +===== + - Install on a Node via the ``SoftwareManager`` to start the FTP server service. - Service runs on FTP (command) port 21 by default. (TODO: look at in depth implementation of FTP PORT command) Implementation -^^^^^^^^^^^^^^ +============== - FTP request and responses use a ``FTPPacket`` object - Extends Service class for integration with ``SoftwareManager``. + + +Examples +======== + +Python +"""""" + +.. code-block:: python + + from primaite.simulator.network.hardware.nodes.host.server import Server + from primaite.simulator.system.services.ftp.ftp_server import FTPServer + + # Create Server + server = Server( + hostname="server", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + server.power_on() + + # Install FTPServer on server + server.software_manager.install(FTPServer) + ftp_server: FTPServer = server.software_manager.software.get("FTPServer") + ftp_server.start() + + ftp_server.server_password = "test" + +Via Configuration +""""""""""""""""" + +.. code-block:: yaml + + simulation: + network: + nodes: + - ref: example_server + hostname: example_server + type: server + ... + services: + - ref: ftp_server + type: FTPServer + options: + server_password: test + +Configuration +============= + +.. include:: ../common/common_configuration.rst + +.. |SOFTWARE_NAME| replace:: FTPServer +.. |SOFTWARE_NAME_BACKTICK| replace:: ``FTPServer`` + +``server_password`` +""""""""""""""""""" + +Optional. Default value is ``None``. + +The password that needs to be provided by a connecting :ref:`FTPClient` in order to create a successful connection. diff --git a/docs/source/simulation_components/system/services/ntp_client.rst b/docs/source/simulation_components/system/services/ntp_client.rst index 27cd27e4..aaba3261 100644 --- a/docs/source/simulation_components/system/services/ntp_client.rst +++ b/docs/source/simulation_components/system/services/ntp_client.rst @@ -2,25 +2,94 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _NTPClient: + NTPClient -========= +######### The NTPClient provides a client interface for connecting to the ``NTPServer``. Key features -^^^^^^^^^^^^ +============ - Connects to the ``NTPServer`` via the ``SoftwareManager``. Usage -^^^^^ +===== - Install on a Node via the ``SoftwareManager`` to start the database service. - Service runs on UDP port 123 by default. Implementation -^^^^^^^^^^^^^^ +============== - Leverages ``SoftwareManager`` for sending payloads over the network. - Provides easy interface for Nodes to find IP addresses via domain names. - Extends base Service class. + + +Examples +======== + +Python +"""""" + +.. code-block:: python + + from ipaddress import IPv4Address + + from primaite.simulator.network.hardware.nodes.host.server import Server + from primaite.simulator.system.services.ntp.ntp_client import NTPClient + + # Create Server + server = Server( + hostname="server", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + server.power_on() + + # Install NTPClient on server + server.software_manager.install(NTPClient) + ntp_client: NTPClient = server.software_manager.software.get("NTPClient") + ntp_client.start() + + ntp_client.configure(ntp_server_ip_address=IPv4Address("192.168.0.10")) + + +Via Configuration +""""""""""""""""" + +.. code-block:: yaml + + simulation: + network: + nodes: + - ref: example_server + hostname: example_server + type: server + ... + services: + - ref: ntp_client + type: NTPClient + options: + ntp_server_ip: 192.168.0.10 + +Configuration +============= + +.. include:: ../common/common_configuration.rst + +.. |SOFTWARE_NAME| replace:: NTPClient +.. |SOFTWARE_NAME_BACKTICK| replace:: ``NTPClient`` + +``ntp_server_ip`` +""""""""""""""""" + +Optional. Default value is ``None``. + +The IP address of an NTP Server which provides a time that the ``NTPClient`` can synchronise to. + +This must be a valid octet i.e. in the range of ``0.0.0.0`` and ``255.255.255.255``. diff --git a/docs/source/simulation_components/system/services/ntp_server.rst b/docs/source/simulation_components/system/services/ntp_server.rst index 066ad5ac..0025b428 100644 --- a/docs/source/simulation_components/system/services/ntp_server.rst +++ b/docs/source/simulation_components/system/services/ntp_server.rst @@ -2,27 +2,85 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _NTPServer: + NTPServer -========= +######### + The ``NTPServer`` provides a NTP Server simulation by extending the base Service class. NTP Client ----------- +========== + The ``NTPClient`` provides a NTP Client simulation by extending the base Service class. Key capabilities -^^^^^^^^^^^^^^^^ +================ - Simulates NTP requests and NTPPacket transfer across a network - Leverages the Service base class for install/uninstall, status tracking, etc. Usage -^^^^^ +===== - Install on a Node via the ``SoftwareManager`` to start the database service. - Service runs on UDP port 123 by default. Implementation -^^^^^^^^^^^^^^ +============== - NTP request and responses use a ``NTPPacket`` object - Extends Service class for integration with ``SoftwareManager``. + + +Examples +======== + +Python +"""""" + +.. code-block:: python + + from primaite.simulator.network.hardware.nodes.host.server import Server + from primaite.simulator.system.services.ntp.ntp_server import NTPServer + + # Create Server + server = Server( + hostname="server", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + server.power_on() + + # Install NTPServer on server + server.software_manager.install(NTPServer) + ntp_server: NTPServer = server.software_manager.software.get("NTPServer") + ntp_server.start() + + +Via Configuration +""""""""""""""""" + +.. code-block:: yaml + + simulation: + network: + nodes: + - ref: example_server + hostname: example_server + type: server + ... + services: + - ref: ntp_server + type: NTPServer + +Configuration +============= + +.. include:: ../common/common_configuration.rst + +.. |SOFTWARE_NAME| replace:: NTPServer +.. |SOFTWARE_NAME_BACKTICK| replace:: ``NTPServer`` + +**NTPServer has no configuration options** diff --git a/docs/source/simulation_components/system/services/web_server.rst b/docs/source/simulation_components/system/services/web_server.rst index ae3f32e6..62b1d090 100644 --- a/docs/source/simulation_components/system/services/web_server.rst +++ b/docs/source/simulation_components/system/services/web_server.rst @@ -2,12 +2,15 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _WebServer: + WebServer -========= +######### + Provides a Web Server simulation by extending the base Service class. Key capabilities -^^^^^^^^^^^^^^^^ +================ - Simulates a web server with the capability to also request data from a database - Allows the emulation of HTTP requests between client (e.g. a web browser) and server @@ -15,13 +18,69 @@ Key capabilities - Leverages the Service base class for install/uninstall, status tracking, etc. Usage -^^^^^ +===== + - Install on a Node via the ``SoftwareManager`` to start the `WebServer`. - Service runs on HTTP port 80 by default. (TODO: HTTPS) +- A :ref:`DatabaseClient` must be installed and configured on the same node as the ``WebServer`` if it is intended to send a users request i.e. + in the case that the :ref:`WebBrowser` sends a request with users in its request path, the ``WebServer`` will utilise the ``DatabaseClient`` to send a request to the ``DatabaseService`` Implementation -^^^^^^^^^^^^^^ +============== - HTTP request uses a ``HttpRequestPacket`` object - HTTP response uses a ``HttpResponsePacket`` object - Extends Service class for integration with ``SoftwareManager``. + + +Examples +======== + +Python +"""""" + +.. code-block:: python + + from primaite.simulator.network.hardware.nodes.host.server import Server + from primaite.simulator.system.services.web_server.web_server import WebServer + + # Create Server + server = Server( + hostname="server", + ip_address="192.168.2.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + server.power_on() + + # Install WebServer on server + server.software_manager.install(WebServer) + web_server: WebServer = server.software_manager.software.get("WebServer") + web_server.start() + +Via Configuration +""""""""""""""""" + +.. code-block:: yaml + + simulation: + network: + nodes: + - ref: example_server + hostname: example_server + type: server + ... + services: + - ref: web_server + type: WebServer + +Configuration +============= + +.. include:: ../common/common_configuration.rst + +.. |SOFTWARE_NAME| replace:: WebServer +.. |SOFTWARE_NAME_BACKTICK| replace:: ``WebServer`` + +**WebServer has no configuration options** diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 8e78f636..ef54893e 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -296,6 +296,7 @@ class PrimaiteGame: if service_type == "DatabaseService": if "options" in service_cfg: opt = service_cfg["options"] + new_service.password = opt.get("backup_server_ip", None) new_service.configure_backup(backup_server=IPv4Address(opt.get("backup_server_ip"))) if service_type == "FTPServer": if "options" in service_cfg: @@ -327,7 +328,7 @@ class PrimaiteGame: new_application.configure( server_ip_address=IPv4Address(opt.get("server_ip")), server_password=opt.get("server_password"), - payload=opt.get("payload"), + payload=opt.get("payload", "DELETE"), port_scan_p_of_success=float(opt.get("port_scan_p_of_success", "0.1")), data_manipulation_p_of_success=float(opt.get("data_manipulation_p_of_success", "0.1")), ) diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 0b9554d5..c0390b4f 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -23,6 +23,7 @@ class DatabaseService(Service): """ password: Optional[str] = None + """Password that needs to be provided by clients if they want to connect to the DatabaseService.""" backup_server_ip: IPv4Address = None """IP address of the backup server.""" @@ -194,6 +195,8 @@ class DatabaseService(Service): """ Executes the given SQL query and returns the result. + .. _Database Payload List: + Possible queries: - SELECT : returns the data - DELETE : deletes the data From c115095157f27d6d7480df430c2c83e50078184d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 25 Feb 2024 16:17:12 +0000 Subject: [PATCH 623/980] Fix router from config using wrong method --- src/primaite/simulator/network/hardware/nodes/router.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 887bc9be..6bf80b3c 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -1016,7 +1016,7 @@ class Router(Node): # Add the router's default ACL rules from the config. if "acl" in cfg: for r_num, r_cfg in cfg["acl"].items(): - new.add_rule( + new.acl.add_rule( action=ACLAction[r_cfg["action"]], src_port=None if not (p := r_cfg.get("src_port")) else Port[p], dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], From 994dbc3501b7c50584322cf3bba9db7aa7e0b77d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 25 Feb 2024 17:44:41 +0000 Subject: [PATCH 624/980] Finalise the refactor. It works well now. --- .../config/_package_data/example_config.yaml | 5 +- src/primaite/game/game.py | 12 +++- src/primaite/notebooks/uc2_demo.ipynb | 66 +++++++++---------- src/primaite/session/environment.py | 7 +- src/primaite/simulator/network/container.py | 6 +- .../simulator/network/hardware/base.py | 10 +-- .../network/hardware/nodes/network/router.py | 2 +- src/primaite/simulator/sim_container.py | 2 +- .../system/services/web_server/web_server.py | 2 +- src/primaite/simulator/system/software.py | 7 +- 10 files changed, 65 insertions(+), 54 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index f85baf10..a32696c7 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -652,12 +652,13 @@ simulation: default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: + - ref: web_server_web_service + type: WebServer + applications: - ref: web_server_database_client type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: web_server_web_service - type: WebServer - ref: database_server diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 02d36c8a..f5649589 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -185,6 +185,10 @@ class PrimaiteGame: """Close the game, this will close the simulation.""" return NotImplemented + def setup_for_episode(self, episode: int) -> None: + """Perform any final configuration of components to make them ready for the game to start.""" + self.simulation.setup_for_episode(episode=episode) + @classmethod def from_config(cls, cfg: Dict) -> "PrimaiteGame": """Create a PrimaiteGame object from a config dictionary. @@ -258,7 +262,9 @@ class PrimaiteGame: new_service = new_node.software_manager.software[service_type] game.ref_map_services[service_ref] = new_service.uuid else: - _LOGGER.warning(f"service type not found {service_type}") + msg = f"Configuration contains an invalid service type: {service_type}" + _LOGGER.error(msg) + raise ValueError(msg) # service-dependent options if service_type == "DNSClient": if "options" in service_cfg: @@ -297,7 +303,9 @@ class PrimaiteGame: new_application = new_node.software_manager.software[application_type] game.ref_map_applications[application_ref] = new_application.uuid else: - _LOGGER.warning(f"application type not found {application_type}") + msg = f"Configuration contains an invalid application type: {application_type}" + _LOGGER.error(msg) + raise ValueError(msg) if application_type == "DataManipulationBot": if "options" in application_cfg: diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index c4fe4c9a..460e3d27 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -335,9 +335,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", @@ -347,9 +345,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "# Imports\n", @@ -372,9 +368,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "# create the env\n", @@ -385,10 +379,10 @@ " cfg['simulation']['network']['nodes'][9]['applications'][0]['options']['data_manipulation_p_of_success'] = 1.0\n", " cfg['simulation']['network']['nodes'][8]['applications'][0]['options']['port_scan_p_of_success'] = 1.0\n", " cfg['simulation']['network']['nodes'][9]['applications'][0]['options']['port_scan_p_of_success'] = 1.0\n", - "game = PrimaiteGame.from_config(cfg)\n", - "env = PrimaiteGymEnv(game = game)\n", - "# Don't flatten obs as we are not training an agent and we wish to see the dict-formatted observations\n", - "env.agent.flatten_obs = False\n", + " # don't flatten observations so that we can see what is going on\n", + " cfg['agents'][3]['agent_settings']['flatten_obs'] = False\n", + "\n", + "env = PrimaiteGymEnv(game_config = cfg)\n", "obs, info = env.reset()\n", "print('env created successfully')\n", "pprint(obs)" @@ -422,9 +416,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "for step in range(35):\n", @@ -442,9 +434,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "pprint(obs['NODES'])" @@ -460,9 +450,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(9) # scan database file\n", @@ -488,9 +476,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(13) # patch the database\n", @@ -515,9 +501,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(0) # patch the database\n", @@ -540,9 +524,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "env.step(13) # Patch the database\n", @@ -582,6 +564,22 @@ "obs['ACL']" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Reset the cell, you can rerun the other cells to verify that the attack works the same every episode." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "env.reset()" + ] + }, { "cell_type": "code", "execution_count": null, @@ -592,7 +590,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "venv", "language": "python", "name": "python3" }, @@ -606,9 +604,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.10.12" } }, "nbformat": 4, - "nbformat_minor": 4 + "nbformat_minor": 2 } diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index ad770f8f..bab81253 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -74,6 +74,7 @@ class PrimaiteGymEnv(gymnasium.Env): f"avg. reward: {self.game.rl_agents[0].reward_function.total_reward}" ) self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=self.game_config) + self.game.setup_for_episode(episode=self.episode_counter) self.agent = self.game.rl_agents[0] self.episode_counter += 1 state = self.game.get_sim_state() @@ -97,12 +98,12 @@ class PrimaiteGymEnv(gymnasium.Env): def _get_obs(self) -> ObsType: """Return the current observation.""" - if not self.agent.flatten_obs: - return self.agent.observation_manager.current_observation - else: + if self.agent.flatten_obs: unflat_space = self.agent.observation_manager.space unflat_obs = self.agent.observation_manager.current_observation return gymnasium.spaces.flatten(unflat_space, unflat_obs) + else: + return self.agent.observation_manager.current_observation class PrimaiteRayEnv(gymnasium.Env): diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index c3ad84c3..b5a16430 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -48,9 +48,9 @@ class Network(SimComponent): def setup_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" for node in self.nodes.values(): - node.setup_for_episode(episode) + node.setup_for_episode(episode=episode) for link in self.links.values(): - link.setup_for_episode(episode) + link.setup_for_episode(episode=episode) for node in self.nodes.values(): node.power_on() @@ -172,7 +172,7 @@ class Network(SimComponent): def clear_links(self): """Clear all the links in the network by resetting their component state for the episode.""" for link in self.links.values(): - link.setup_for_episode() + link.setup_for_episode(episode=0) # TODO: shouldn't be using this method here. def draw(self, seed: int = 123): """ diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 771c3397..1b6d611e 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -90,7 +90,7 @@ class NetworkInterface(SimComponent, ABC): def setup_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - super().setup_for_episode(episode) + super().setup_for_episode(episode=episode) if episode and self.pcap: self.pcap.current_episode = episode self.pcap.setup_logger() @@ -643,17 +643,17 @@ class Node(SimComponent): def setup_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - super().setup_for_episode(episode) + super().setup_for_episode(episode=episode) # Reset File System - self.file_system.setup_for_episode(episode) + self.file_system.setup_for_episode(episode=episode) # Reset all Nics for network_interface in self.network_interfaces.values(): - network_interface.setup_for_episode(episode) + network_interface.setup_for_episode(episode=episode) for software in self.software_manager.software.values(): - software.setup_for_episode(episode) + software.setup_for_episode(episode=episode) if episode and self.sys_log: self.sys_log.current_episode = episode diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index c299dfb7..3111a153 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1078,7 +1078,7 @@ class Router(NetworkNode): for i, _ in self.network_interface.items(): self.enable_port(i) - super().setup_for_episode(episode) + super().setup_for_episode(episode=episode) def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index bb6132a8..a2285d92 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -23,7 +23,7 @@ class Simulation(SimComponent): def setup_for_episode(self, episode: int): """Reset the original state of the SimComponent.""" - self.network.setup_for_episode(episode) + self.network.setup_for_episode(episode=episode) def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index 5e4a6f6e..ce29a2f9 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -118,7 +118,7 @@ class WebServer(Service): self.set_health_state(SoftwareHealthState.COMPROMISED) return response - except Exception: + except Exception: # TODO: refactor this. Likely to cause silent bugs. # something went wrong on the server response.status_code = HttpStatusCode.INTERNAL_SERVER_ERROR return response diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 56a1e3d1..8864659c 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -3,7 +3,7 @@ from abc import abstractmethod from datetime import datetime from enum import Enum from ipaddress import IPv4Address, IPv4Network -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Optional, TYPE_CHECKING, Union from primaite.simulator.core import _LOGGER, RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file_system import FileSystem, Folder @@ -13,6 +13,9 @@ from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.session_manager import Session from primaite.simulator.system.core.sys_log import SysLog +if TYPE_CHECKING: + from primaite.simulator.system.core.software_manager import SoftwareManager + class SoftwareType(Enum): """ @@ -84,7 +87,7 @@ class Software(SimComponent): "The count of times the software has been scanned, defaults to 0." revealed_to_red: bool = False "Indicates if the software has been revealed to red agent, defaults is False." - software_manager: Any = None + software_manager: "SoftwareManager" = None "An instance of Software Manager that is used by the parent node." sys_log: SysLog = None "An instance of SysLog that is used by the parent node." From 63c9a36c30adf38716759526968067ae990f1fdc Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 25 Feb 2024 18:36:20 +0000 Subject: [PATCH 625/980] Fix typos --- src/primaite/notebooks/uc2_demo.ipynb | 2 +- src/primaite/simulator/system/services/ntp/ntp_client.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index 460e3d27..7c90a885 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -568,7 +568,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Reset the cell, you can rerun the other cells to verify that the attack works the same every episode." + "Reset the environment, you can rerun the other cells to verify that the attack works the same every episode." ] }, { diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index 1e9dc139..ad00065c 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -1,6 +1,6 @@ from datetime import datetime from ipaddress import IPv4Address -from typing import Dict, List, Optional +from typing import Dict, Optional from primaite import getLogger from primaite.simulator.network.protocols.ntp import NTPPacket @@ -54,7 +54,7 @@ class NTPClient(Service): payload: NTPPacket, session_id: Optional[str] = None, dest_ip_address: IPv4Address = None, - dest_port: List[Port] = Port.NTP, + dest_port: Port = Port.NTP, **kwargs, ) -> bool: """Requests NTP data from NTP server. From 07373d941eab4ea4d03caad49e8db327d2e1b84e Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 26 Feb 2024 08:44:08 +0000 Subject: [PATCH 626/980] #2257: Downgrade version of sphinx - 7.2.0 drops support for Python 3.8 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 44ce75c6..19b5b7fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,7 +67,7 @@ dev = [ "pytest-cov==4.0.0", "pytest-flake8==1.1.1", "setuptools==66", - "Sphinx==7.2.6", + "Sphinx==7.1.2", "sphinx-copybutton==0.5.2", "wheel==0.38.4" ] From 1d5c153752269428c67bda75652bcbd8cef5f3fc Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 26 Feb 2024 08:49:11 +0000 Subject: [PATCH 627/980] #2257: changelog update --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01e45d2e..e96bf4a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,12 @@ SessionManager. - `AirSpace` class to simulate wireless communications, managing wireless interfaces and facilitating the transmission of frames within specified frequencies. - `AirSpaceFrequency` enum for defining standard wireless frequencies, including 2.4 GHz and 5 GHz bands, to support realistic wireless network simulations. - `WirelessRouter` class, extending the `Router` class, to incorporate wireless networking capabilities alongside traditional wired connections. This class allows the configuration of wireless access points with specific IP settings and operating frequencies. +- Configuration examples in documentation: + - Examples include how to set up PrimAITE session + - Examples include how to create nodes and install software +- Ability to add Firewall node via config +- Ability to add Router routes via config +- Ability to add Router/Firewall ACL Rules via config ### Changed From e964b8a3eaebf3f3415dc089ccca9c6db4412183 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 26 Feb 2024 08:58:03 +0000 Subject: [PATCH 628/980] #2257: more in depth changelog --- CHANGELOG.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e96bf4a6..e51a912e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,12 +82,19 @@ SessionManager. - `AirSpace` class to simulate wireless communications, managing wireless interfaces and facilitating the transmission of frames within specified frequencies. - `AirSpaceFrequency` enum for defining standard wireless frequencies, including 2.4 GHz and 5 GHz bands, to support realistic wireless network simulations. - `WirelessRouter` class, extending the `Router` class, to incorporate wireless networking capabilities alongside traditional wired connections. This class allows the configuration of wireless access points with specific IP settings and operating frequencies. -- Configuration examples in documentation: - - Examples include how to set up PrimAITE session - - Examples include how to create nodes and install software -- Ability to add Firewall node via config -- Ability to add Router routes via config -- Ability to add Router/Firewall ACL Rules via config +- Documentation Updates: + - Examples include how to set up PrimAITE session via config + - Examples include how to create nodes and install software via config + - Examples include how to set up PrimAITE session via Python + - Examples include how to create nodes and install software via Python + - Added missing ``DoSBot`` documentation page + - Added diagrams where needed to make understanding some things easier + - Templated parts of the documentation to prevent unnecessary repetition and for easier maintaining of documentation + - Separated documentation pages of some items i.e. client and server software were on the same pages - which may make things confusing + - Configuration section at the bottom of the software pages specifying the configuration options available (and which ones are optional) +- Ability to add ``Firewall`` node via config +- Ability to add ``Router`` routes via config +- Ability to add ``Router``/``Firewall`` ``ACLRule`` via config ### Changed From 634f6340973eca2b2927f03e897593714034ded0 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 26 Feb 2024 09:47:12 +0000 Subject: [PATCH 629/980] #2257: fix text and make examples in node configs more specific --- .../common/common_network_node_attributes.rst | 2 +- .../simulation/nodes/computer.rst | 26 ++++---- .../simulation/nodes/firewall.rst | 64 ++++++++++--------- .../configuration/simulation/nodes/router.rst | 20 +++--- .../configuration/simulation/nodes/server.rst | 26 ++++---- .../configuration/simulation/nodes/switch.rst | 12 ++-- 6 files changed, 80 insertions(+), 70 deletions(-) diff --git a/docs/source/configuration/simulation/nodes/common/common_network_node_attributes.rst b/docs/source/configuration/simulation/nodes/common/common_network_node_attributes.rst index 83007145..d0b3e65b 100644 --- a/docs/source/configuration/simulation/nodes/common/common_network_node_attributes.rst +++ b/docs/source/configuration/simulation/nodes/common/common_network_node_attributes.rst @@ -23,7 +23,7 @@ e.g. ``address`` """"""""""" -The target IP address for the route. If the packet destination IP address matches this, the router will route the packet according to the ``next_hop_ip_address``. +The target IP address for the route. If the packet destination IP address matches this, the |NODE| will route the packet according to the ``next_hop_ip_address``. This must be a valid octet i.e. in the range of ``0.0.0.0`` and ``255.255.255.255``. diff --git a/docs/source/configuration/simulation/nodes/computer.rst b/docs/source/configuration/simulation/nodes/computer.rst index bbdf087d..04a45766 100644 --- a/docs/source/configuration/simulation/nodes/computer.rst +++ b/docs/source/configuration/simulation/nodes/computer.rst @@ -16,18 +16,20 @@ example computer .. code-block:: yaml - nodes: - - ref: client_1 - hostname: client_1 - type: computer - ip_address: 192.168.0.10 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.0.1 - dns_server: 192.168.1.10 - applications: - ... - services: - ... + simulation: + network: + nodes: + - ref: client_1 + hostname: client_1 + type: computer + ip_address: 192.168.0.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.0.1 + dns_server: 192.168.1.10 + applications: + ... + services: + ... .. include:: common/common_node_attributes.rst diff --git a/docs/source/configuration/simulation/nodes/firewall.rst b/docs/source/configuration/simulation/nodes/firewall.rst index c8a21a02..3c1fce0a 100644 --- a/docs/source/configuration/simulation/nodes/firewall.rst +++ b/docs/source/configuration/simulation/nodes/firewall.rst @@ -18,37 +18,39 @@ example firewall .. code-block:: yaml - nodes: - - ref: firewall - hostname: firewall - type: firewall - start_up_duration: 0 - shut_down_duration: 0 - ports: - external_port: # port 1 - ip_address: 192.168.20.1 - subnet_mask: 255.255.255.0 - internal_port: # port 2 - ip_address: 192.168.1.2 - subnet_mask: 255.255.255.0 - dmz_port: # port 3 - ip_address: 192.168.10.1 - subnet_mask: 255.255.255.0 - acl: - internal_inbound_acl: - ... - internal_outbound_acl: - ... - dmz_inbound_acl: - ... - dmz_outbound_acl: - ... - external_inbound_acl: - ... - external_outbound_acl: - ... - routes: - ... + simulation: + network: + nodes: + - ref: firewall + hostname: firewall + type: firewall + start_up_duration: 0 + shut_down_duration: 0 + ports: + external_port: # port 1 + ip_address: 192.168.20.1 + subnet_mask: 255.255.255.0 + internal_port: # port 2 + ip_address: 192.168.1.2 + subnet_mask: 255.255.255.0 + dmz_port: # port 3 + ip_address: 192.168.10.1 + subnet_mask: 255.255.255.0 + acl: + internal_inbound_acl: + ... + internal_outbound_acl: + ... + dmz_inbound_acl: + ... + dmz_outbound_acl: + ... + external_inbound_acl: + ... + external_outbound_acl: + ... + routes: + ... .. include:: common/common_node_attributes.rst diff --git a/docs/source/configuration/simulation/nodes/router.rst b/docs/source/configuration/simulation/nodes/router.rst index 8a8efc06..b9ba1ad5 100644 --- a/docs/source/configuration/simulation/nodes/router.rst +++ b/docs/source/configuration/simulation/nodes/router.rst @@ -16,15 +16,17 @@ example router .. code-block:: yaml - nodes: - - ref: router_1 - hostname: router_1 - type: router - num_ports: 5 - ports: - ... - acl: - ... + simulation: + network: + nodes: + - ref: router_1 + hostname: router_1 + type: router + num_ports: 5 + ports: + ... + acl: + ... .. include:: common/common_node_attributes.rst diff --git a/docs/source/configuration/simulation/nodes/server.rst b/docs/source/configuration/simulation/nodes/server.rst index 7f51eaf2..dbc32235 100644 --- a/docs/source/configuration/simulation/nodes/server.rst +++ b/docs/source/configuration/simulation/nodes/server.rst @@ -16,18 +16,20 @@ example server .. code-block:: yaml - nodes: - - ref: server_1 - hostname: server_1 - type: server - ip_address: 192.168.10.10 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.10.1 - dns_server: 192.168.1.10 - applications: - ... - services: - ... + simulation: + network: + nodes: + - ref: server_1 + hostname: server_1 + type: server + ip_address: 192.168.10.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + applications: + ... + services: + ... .. include:: common/common_node_attributes.rst diff --git a/docs/source/configuration/simulation/nodes/switch.rst b/docs/source/configuration/simulation/nodes/switch.rst index 4d57f76e..263bedbb 100644 --- a/docs/source/configuration/simulation/nodes/switch.rst +++ b/docs/source/configuration/simulation/nodes/switch.rst @@ -16,11 +16,13 @@ example switch .. code-block:: yaml - nodes: - - ref: switch_1 - hostname: switch_1 - type: switch - num_ports: 8 + simulation: + network: + nodes: + - ref: switch_1 + hostname: switch_1 + type: switch + num_ports: 8 .. include:: common/common_node_attributes.rst From e5982c4599b07ef5cf994218f4323d1105f65bc7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 26 Feb 2024 10:26:28 +0000 Subject: [PATCH 630/980] Change agents list in game object to dictionary --- .../example_config_2_rl_agents.yaml | 446 +++++++++++------- src/primaite/game/game.py | 18 +- .../training_example_ray_multi_agent.ipynb | 9 +- .../training_example_ray_single_agent.ipynb | 2 +- .../notebooks/training_example_sb3.ipynb | 11 +- src/primaite/session/environment.py | 52 +- tests/conftest.py | 2 +- tests/integration_tests/game_configuration.py | 16 +- 8 files changed, 331 insertions(+), 225 deletions(-) diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index 93019c9d..1ccd7b38 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -10,6 +10,8 @@ io_settings: save_checkpoints: true checkpoint_interval: 5 save_step_metadata: false + save_pcap_logs: true + save_sys_logs: true game: @@ -36,9 +38,9 @@ agents: - type: NODE_APPLICATION_EXECUTE options: nodes: - - node_ref: client_2 + - node_name: client_2 applications: - - application_ref: client_2_web_browser + - application_name: WebBrowser max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 @@ -54,6 +56,31 @@ agents: frequency: 4 variance: 3 + - ref: client_1_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_1 + applications: + - application_name: WebBrowser + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_applications_per_node: 1 + reward_function: + reward_components: + - type: DUMMY + + + + - ref: data_manipulation_attacker team: RED type: RedDatabaseCorruptingAgent @@ -72,7 +99,7 @@ agents: - type: NODE_OS_SCAN options: nodes: - - node_ref: client_1 + - node_name: client_1 applications: - application_name: DataManipulationBot - node_name: client_2 @@ -104,25 +131,21 @@ agents: num_files_per_folder: 1 num_nics_per_node: 2 nodes: - - node_ref: domain_controller + - node_hostname: domain_controller services: - - service_ref: domain_controller_dns_server - - node_ref: web_server + - service_name: DNSServer + - node_hostname: web_server services: - - service_ref: web_server_database_client - - node_ref: database_server - services: - - service_ref: database_service + - service_name: WebServer + - node_hostname: database_server folders: - folder_name: database files: - file_name: database.db - - node_ref: backup_server - # services: - # - service_ref: backup_service - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: backup_server + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 links: - link_ref: router_1___switch_1 - link_ref: router_1___switch_2 @@ -137,23 +160,23 @@ agents: acl: options: max_acl_rules: 10 - router_node_ref: router_1 + router_hostname: router_1 ip_address_order: - - node_ref: domain_controller + - node_hostname: domain_controller nic_num: 1 - - node_ref: web_server + - node_hostname: web_server nic_num: 1 - - node_ref: database_server + - node_hostname: database_server nic_num: 1 - - node_ref: backup_server + - node_hostname: backup_server nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 1 - - node_ref: client_1 + - node_hostname: client_1 nic_num: 1 - - node_ref: client_2 + - node_hostname: client_2 nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 2 ics: null @@ -184,10 +207,10 @@ agents: - type: NODE_RESET - type: NETWORK_ACL_ADDRULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_ACL_REMOVERULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -242,25 +265,25 @@ agents: action: "NODE_FILE_SCAN" options: node_id: 2 - folder_id: 1 + folder_id: 0 file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: node_id: 2 - folder_id: 1 + folder_id: 0 file_id: 0 11: action: "NODE_FILE_DELETE" options: node_id: 2 - folder_id: 1 + folder_id: 0 file_id: 0 12: action: "NODE_FILE_REPAIR" options: node_id: 2 - folder_id: 1 + folder_id: 0 file_id: 0 13: action: "NODE_SERVICE_PATCH" @@ -271,22 +294,22 @@ agents: action: "NODE_FOLDER_SCAN" options: node_id: 2 - folder_id: 1 + folder_id: 0 15: action: "NODE_FOLDER_CHECKHASH" options: node_id: 2 - folder_id: 1 + folder_id: 0 16: action: "NODE_FOLDER_REPAIR" options: node_id: 2 - folder_id: 1 + folder_id: 0 17: action: "NODE_FOLDER_RESTORE" options: node_id: 2 - folder_id: 1 + folder_id: 0 18: action: "NODE_OS_SCAN" options: @@ -303,63 +326,63 @@ agents: action: "NODE_RESET" options: node_id: 5 - 22: + 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" action: "NETWORK_ACL_ADDRULE" options: position: 1 permission: 2 - source_ip_id: 7 - dest_ip_id: 1 + source_ip_id: 7 # client 1 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: + 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 2 permission: 2 - source_ip_id: 8 - dest_ip_id: 1 + source_ip_id: 8 # client 2 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 24: + 24: # block tcp traffic from client 1 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 3 permission: 2 - source_ip_id: 7 - dest_ip_id: 3 + source_ip_id: 7 # client 1 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 25: + 25: # block tcp traffic from client 2 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 4 permission: 2 - source_ip_id: 8 - dest_ip_id: 3 + source_ip_id: 8 # client 2 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 26: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 5 permission: 2 - source_ip_id: 7 - dest_ip_id: 4 + source_ip_id: 7 # client 1 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 27: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 6 permission: 2 - source_ip_id: 8 - dest_ip_id: 4 + source_ip_id: 8 # client 2 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 @@ -407,123 +430,148 @@ agents: action: "NETWORK_NIC_DISABLE" options: node_id: 0 - nic_id: 1 + nic_id: 0 39: action: "NETWORK_NIC_ENABLE" options: node_id: 0 - nic_id: 1 + nic_id: 0 40: action: "NETWORK_NIC_DISABLE" options: node_id: 1 - nic_id: 1 + nic_id: 0 41: action: "NETWORK_NIC_ENABLE" options: node_id: 1 - nic_id: 1 + nic_id: 0 42: action: "NETWORK_NIC_DISABLE" options: node_id: 2 - nic_id: 1 + nic_id: 0 43: action: "NETWORK_NIC_ENABLE" options: node_id: 2 - nic_id: 1 + nic_id: 0 44: action: "NETWORK_NIC_DISABLE" options: node_id: 3 - nic_id: 1 + nic_id: 0 45: action: "NETWORK_NIC_ENABLE" options: node_id: 3 - nic_id: 1 + nic_id: 0 46: action: "NETWORK_NIC_DISABLE" options: node_id: 4 - nic_id: 1 + nic_id: 0 47: action: "NETWORK_NIC_ENABLE" options: node_id: 4 - nic_id: 1 + nic_id: 0 48: action: "NETWORK_NIC_DISABLE" options: node_id: 4 - nic_id: 2 + nic_id: 1 49: action: "NETWORK_NIC_ENABLE" options: node_id: 4 - nic_id: 2 + nic_id: 1 50: action: "NETWORK_NIC_DISABLE" options: node_id: 5 - nic_id: 1 + nic_id: 0 51: action: "NETWORK_NIC_ENABLE" options: node_id: 5 - nic_id: 1 + nic_id: 0 52: action: "NETWORK_NIC_DISABLE" options: node_id: 6 - nic_id: 1 + nic_id: 0 53: action: "NETWORK_NIC_ENABLE" options: node_id: 6 - nic_id: 1 + nic_id: 0 options: nodes: - - node_ref: domain_controller - - node_ref: web_server + - node_name: domain_controller + - node_name: web_server + applications: + - application_name: DatabaseClient services: - - service_ref: web_server_web_service - - node_ref: database_server + - service_name: WebServer + - node_name: database_server + folders: + - folder_name: database + files: + - file_name: database.db services: - - service_ref: database_service - - node_ref: backup_server - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - service_name: DatabaseService + - node_name: backup_server + - node_name: security_suite + - node_name: client_1 + - node_name: client_2 + max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 + ip_address_order: + - node_name: domain_controller + nic_num: 1 + - node_name: web_server + nic_num: 1 + - node_name: database_server + nic_num: 1 + - node_name: backup_server + nic_num: 1 + - node_name: security_suite + nic_num: 1 + - node_name: client_1 + nic_num: 1 + - node_name: client_2 + nic_num: 1 + - node_name: security_suite + nic_num: 2 + reward_function: reward_components: - type: DATABASE_FILE_INTEGRITY - weight: 0.5 + weight: 0.34 options: - node_ref: database_server + node_hostname: database_server folder_name: database file_name: database.db - - - - type: WEB_SERVER_404_PENALTY - weight: 0.5 + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.33 options: - node_ref: web_server - service_ref: web_server_web_service + node_hostname: client_1 + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.33 + options: + node_hostname: client_2 agent_settings: - # ... - + flatten_obs: true - ref: defender_2 team: BLUE @@ -537,25 +585,21 @@ agents: num_files_per_folder: 1 num_nics_per_node: 2 nodes: - - node_ref: domain_controller + - node_hostname: domain_controller services: - - service_ref: domain_controller_dns_server - - node_ref: web_server + - service_name: DNSServer + - node_hostname: web_server services: - - service_ref: web_server_database_client - - node_ref: database_server - services: - - service_ref: database_service + - service_name: WebServer + - node_hostname: database_server folders: - folder_name: database files: - file_name: database.db - - node_ref: backup_server - # services: - # - service_ref: backup_service - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - node_hostname: backup_server + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 links: - link_ref: router_1___switch_1 - link_ref: router_1___switch_2 @@ -570,23 +614,23 @@ agents: acl: options: max_acl_rules: 10 - router_node_ref: router_1 + router_hostname: router_1 ip_address_order: - - node_ref: domain_controller + - node_hostname: domain_controller nic_num: 1 - - node_ref: web_server + - node_hostname: web_server nic_num: 1 - - node_ref: database_server + - node_hostname: database_server nic_num: 1 - - node_ref: backup_server + - node_hostname: backup_server nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 1 - - node_ref: client_1 + - node_hostname: client_1 nic_num: 1 - - node_ref: client_2 + - node_hostname: client_2 nic_num: 1 - - node_ref: security_suite + - node_hostname: security_suite nic_num: 2 ics: null @@ -617,10 +661,10 @@ agents: - type: NODE_RESET - type: NETWORK_ACL_ADDRULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_ACL_REMOVERULE options: - target_router_ref: router_1 + target_router_hostname: router_1 - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -675,25 +719,25 @@ agents: action: "NODE_FILE_SCAN" options: node_id: 2 - folder_id: 1 + folder_id: 0 file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: node_id: 2 - folder_id: 1 + folder_id: 0 file_id: 0 11: action: "NODE_FILE_DELETE" options: node_id: 2 - folder_id: 1 + folder_id: 0 file_id: 0 12: action: "NODE_FILE_REPAIR" options: node_id: 2 - folder_id: 1 + folder_id: 0 file_id: 0 13: action: "NODE_SERVICE_PATCH" @@ -704,22 +748,22 @@ agents: action: "NODE_FOLDER_SCAN" options: node_id: 2 - folder_id: 1 + folder_id: 0 15: action: "NODE_FOLDER_CHECKHASH" options: node_id: 2 - folder_id: 1 + folder_id: 0 16: action: "NODE_FOLDER_REPAIR" options: node_id: 2 - folder_id: 1 + folder_id: 0 17: action: "NODE_FOLDER_RESTORE" options: node_id: 2 - folder_id: 1 + folder_id: 0 18: action: "NODE_OS_SCAN" options: @@ -736,63 +780,63 @@ agents: action: "NODE_RESET" options: node_id: 5 - 22: + 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" action: "NETWORK_ACL_ADDRULE" options: position: 1 permission: 2 - source_ip_id: 7 - dest_ip_id: 1 + source_ip_id: 7 # client 1 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: + 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 2 permission: 2 - source_ip_id: 8 - dest_ip_id: 1 + source_ip_id: 8 # client 2 + dest_ip_id: 1 # ALL source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 24: + 24: # block tcp traffic from client 1 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 3 permission: 2 - source_ip_id: 7 - dest_ip_id: 3 + source_ip_id: 7 # client 1 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 25: + 25: # block tcp traffic from client 2 to web app action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 4 permission: 2 - source_ip_id: 8 - dest_ip_id: 3 + source_ip_id: 8 # client 2 + dest_ip_id: 3 # web server source_port_id: 1 dest_port_id: 1 protocol_id: 3 26: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 5 permission: 2 - source_ip_id: 7 - dest_ip_id: 4 + source_ip_id: 7 # client 1 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 27: action: "NETWORK_ACL_ADDRULE" options: - position: 1 + position: 6 permission: 2 - source_ip_id: 8 - dest_ip_id: 4 + source_ip_id: 8 # client 2 + dest_ip_id: 4 # database source_port_id: 1 dest_port_id: 1 protocol_id: 3 @@ -840,122 +884,148 @@ agents: action: "NETWORK_NIC_DISABLE" options: node_id: 0 - nic_id: 1 + nic_id: 0 39: action: "NETWORK_NIC_ENABLE" options: node_id: 0 - nic_id: 1 + nic_id: 0 40: action: "NETWORK_NIC_DISABLE" options: node_id: 1 - nic_id: 1 + nic_id: 0 41: action: "NETWORK_NIC_ENABLE" options: node_id: 1 - nic_id: 1 + nic_id: 0 42: action: "NETWORK_NIC_DISABLE" options: node_id: 2 - nic_id: 1 + nic_id: 0 43: action: "NETWORK_NIC_ENABLE" options: node_id: 2 - nic_id: 1 + nic_id: 0 44: action: "NETWORK_NIC_DISABLE" options: node_id: 3 - nic_id: 1 + nic_id: 0 45: action: "NETWORK_NIC_ENABLE" options: node_id: 3 - nic_id: 1 + nic_id: 0 46: action: "NETWORK_NIC_DISABLE" options: node_id: 4 - nic_id: 1 + nic_id: 0 47: action: "NETWORK_NIC_ENABLE" options: node_id: 4 - nic_id: 1 + nic_id: 0 48: action: "NETWORK_NIC_DISABLE" options: node_id: 4 - nic_id: 2 + nic_id: 1 49: action: "NETWORK_NIC_ENABLE" options: node_id: 4 - nic_id: 2 + nic_id: 1 50: action: "NETWORK_NIC_DISABLE" options: node_id: 5 - nic_id: 1 + nic_id: 0 51: action: "NETWORK_NIC_ENABLE" options: node_id: 5 - nic_id: 1 + nic_id: 0 52: action: "NETWORK_NIC_DISABLE" options: node_id: 6 - nic_id: 1 + nic_id: 0 53: action: "NETWORK_NIC_ENABLE" options: node_id: 6 - nic_id: 1 + nic_id: 0 options: nodes: - - node_ref: domain_controller - - node_ref: web_server + - node_name: domain_controller + - node_name: web_server + applications: + - application_name: DatabaseClient services: - - service_ref: web_server_web_service - - node_ref: database_server + - service_name: WebServer + - node_name: database_server + folders: + - folder_name: database + files: + - file_name: database.db services: - - service_ref: database_service - - node_ref: backup_server - - node_ref: security_suite - - node_ref: client_1 - - node_ref: client_2 + - service_name: DatabaseService + - node_name: backup_server + - node_name: security_suite + - node_name: client_1 + - node_name: client_2 + max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 + ip_address_order: + - node_name: domain_controller + nic_num: 1 + - node_name: web_server + nic_num: 1 + - node_name: database_server + nic_num: 1 + - node_name: backup_server + nic_num: 1 + - node_name: security_suite + nic_num: 1 + - node_name: client_1 + nic_num: 1 + - node_name: client_2 + nic_num: 1 + - node_name: security_suite + nic_num: 2 + reward_function: reward_components: - type: DATABASE_FILE_INTEGRITY - weight: 0.5 + weight: 0.34 options: - node_ref: database_server + node_hostname: database_server folder_name: database file_name: database.db - - - - type: WEB_SERVER_404_PENALTY - weight: 0.5 + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.33 options: - node_ref: web_server - service_ref: web_server_web_service + node_hostname: client_1 + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.33 + options: + node_hostname: client_2 agent_settings: - # ... + flatten_obs: true @@ -1032,12 +1102,13 @@ simulation: default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: + - ref: web_server_web_service + type: WebServer + applications: - ref: web_server_database_client type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: web_server_web_service - type: WebServer - ref: database_server @@ -1089,10 +1160,14 @@ simulation: - ref: data_manipulation_bot type: DataManipulationBot options: - port_scan_p_of_success: 0.1 - data_manipulation_p_of_success: 0.1 + port_scan_p_of_success: 0.8 + data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 + - ref: client_1_web_browser + type: WebBrowser + options: + target_url: http://arcd.com/users/ services: - ref: client_1_dns_client type: DNSClient @@ -1109,6 +1184,13 @@ simulation: type: WebBrowser options: target_url: http://arcd.com/users/ + - ref: data_manipulation_bot + type: DataManipulationBot + options: + port_scan_p_of_success: 0.8 + data_manipulation_p_of_success: 0.8 + payload: "DELETE" + server_ip: 192.168.1.14 services: - ref: client_2_dns_client type: DNSClient diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index f5649589..8edf70ea 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -79,11 +79,11 @@ class PrimaiteGame: self.simulation: Simulation = Simulation() """Simulation object with which the agents will interact.""" - self.agents: List[AbstractAgent] = [] - """List of agents.""" + self.agents: Dict[str, AbstractAgent] = {} + """Mapping from agent name to agent object.""" - self.rl_agents: List[ProxyAgent] = [] - """Subset of agent list including only the reinforcement learning agents.""" + self.rl_agents: Dict[str, ProxyAgent] = {} + """Subset of agents which are intended for reinforcement learning.""" self.step_counter: int = 0 """Current timestep within the episode.""" @@ -144,7 +144,7 @@ class PrimaiteGame: def update_agents(self, state: Dict) -> None: """Update agents' observations and rewards based on the current state.""" - for agent in self.agents: + for name, agent in self.agents.items(): agent.update_observation(state) agent.update_reward(state) agent.reward_function.total_reward += agent.reward_function.current_reward @@ -158,7 +158,7 @@ class PrimaiteGame: """ agent_actions = {} - for agent in self.agents: + for name, agent in self.agents.items(): obs = agent.observation_manager.current_observation rew = agent.reward_function.current_reward action_choice, options = agent.get_action(obs, rew) @@ -396,7 +396,6 @@ class PrimaiteGame: reward_function=reward_function, agent_settings=agent_settings, ) - game.agents.append(new_agent) elif agent_type == "ProxyAgent": new_agent = ProxyAgent( agent_name=agent_cfg["ref"], @@ -405,8 +404,7 @@ class PrimaiteGame: reward_function=reward_function, agent_settings=agent_settings, ) - game.agents.append(new_agent) - game.rl_agents.append(new_agent) + game.rl_agents[agent_cfg["ref"]] = new_agent elif agent_type == "RedDatabaseCorruptingAgent": new_agent = DataManipulationAgent( agent_name=agent_cfg["ref"], @@ -415,8 +413,8 @@ class PrimaiteGame: reward_function=reward_function, agent_settings=agent_settings, ) - game.agents.append(new_agent) else: _LOGGER.warning(f"agent type {agent_type} not found") + game.agents[agent_cfg["ref"]] = new_agent return game diff --git a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb index 0d4b6d0e..4ef02443 100644 --- a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb @@ -60,7 +60,7 @@ " policies={'defender_1','defender_2'}, # These names are the same as the agents defined in the example config.\n", " policy_mapping_fn=lambda agent_id, episode, worker, **kw: agent_id,\n", " )\n", - " .environment(env=PrimaiteRayMARLEnv, env_config={\"cfg\":cfg})#, disable_env_checking=True)\n", + " .environment(env=PrimaiteRayMARLEnv, env_config=cfg)#, disable_env_checking=True)\n", " .rollouts(num_rollout_workers=0)\n", " .training(train_batch_size=128)\n", " )\n" @@ -88,6 +88,13 @@ " param_space=config\n", ").fit()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/src/primaite/notebooks/training_example_ray_single_agent.ipynb b/src/primaite/notebooks/training_example_ray_single_agent.ipynb index ea006ae9..3c27bdc6 100644 --- a/src/primaite/notebooks/training_example_ray_single_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_single_agent.ipynb @@ -54,7 +54,7 @@ "metadata": {}, "outputs": [], "source": [ - "env_config = {\"cfg\":cfg}\n", + "env_config = cfg\n", "\n", "config = (\n", " PPOConfig()\n", diff --git a/src/primaite/notebooks/training_example_sb3.ipynb b/src/primaite/notebooks/training_example_sb3.ipynb index 164142b2..0472854e 100644 --- a/src/primaite/notebooks/training_example_sb3.ipynb +++ b/src/primaite/notebooks/training_example_sb3.ipynb @@ -27,9 +27,7 @@ "outputs": [], "source": [ "with open(example_config_path(), 'r') as f:\n", - " cfg = yaml.safe_load(f)\n", - "\n", - "game = PrimaiteGame.from_config(cfg)" + " cfg = yaml.safe_load(f)\n" ] }, { @@ -76,6 +74,13 @@ "source": [ "model.save(\"deleteme\")" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index bab81253..f8dbab9d 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -1,5 +1,5 @@ import json -from typing import Any, Dict, Final, Optional, SupportsFloat, Tuple +from typing import Any, Dict, Optional, SupportsFloat, Tuple import gymnasium from gymnasium.core import ActType, ObsType @@ -25,12 +25,17 @@ class PrimaiteGymEnv(gymnasium.Env): """PrimaiteGame definition. This can be changed between episodes to enable curriculum learning.""" self.game: PrimaiteGame = PrimaiteGame.from_config(self.game_config) """Current game.""" - self.agent: ProxyAgent = self.game.rl_agents[0] - """The agent within the game that is controlled by the RL algorithm.""" + self._agent_name = next(iter(self.game.rl_agents)) + """Name of the RL agent. Since there should only be one RL agent we can just pull the first and only key.""" self.episode_counter: int = 0 """Current episode number.""" + @property + def agent(self) -> ProxyAgent: + """Grab a fresh reference to the agent object because it will be reinstantiated each episode.""" + return self.game.rl_agents[self._agent_name] + def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: """Perform a step in the environment.""" # make ProxyAgent store the action chosen my the RL policy @@ -71,11 +76,10 @@ class PrimaiteGymEnv(gymnasium.Env): """Reset the environment.""" print( f"Resetting environment, episode {self.episode_counter}, " - f"avg. reward: {self.game.rl_agents[0].reward_function.total_reward}" + f"avg. reward: {self.agent.reward_function.total_reward}" ) self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=self.game_config) self.game.setup_for_episode(episode=self.episode_counter) - self.agent = self.game.rl_agents[0] self.episode_counter += 1 state = self.game.get_sim_state() self.game.update_agents(state) @@ -112,11 +116,10 @@ class PrimaiteRayEnv(gymnasium.Env): def __init__(self, env_config: Dict) -> None: """Initialise the environment. - :param env_config: A dictionary containing the environment configuration. It must contain a single key, `game` - which is the PrimaiteGame instance. - :type env_config: Dict[str, PrimaiteGame] + :param env_config: A dictionary containing the environment configuration. + :type env_config: Dict """ - self.env = PrimaiteGymEnv(game=PrimaiteGame.from_config(env_config["cfg"])) + self.env = PrimaiteGymEnv(game_config=env_config) self.env.episode_counter -= 1 self.action_space = self.env.action_space self.observation_space = self.env.observation_space @@ -138,13 +141,16 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): :param env_config: A dictionary containing the environment configuration. It must contain a single key, `game` which is the PrimaiteGame instance. - :type env_config: Dict[str, PrimaiteGame] + :type env_config: Dict """ - self.game: PrimaiteGame = PrimaiteGame.from_config(env_config["cfg"]) + self.game_config: Dict = env_config + """PrimaiteGame definition. This can be changed between episodes to enable curriculum learning.""" + self.game: PrimaiteGame = PrimaiteGame.from_config(self.game_config) """Reference to the primaite game""" - self.agents: Final[Dict[str, ProxyAgent]] = {agent.agent_name: agent for agent in self.game.rl_agents} - """List of all possible agents in the environment. This list should not change!""" - self._agent_ids = list(self.agents.keys()) + self._agent_ids = list(self.game.rl_agents.keys()) + """Agent ids. This is a list of strings of agent names.""" + self.episode_counter: int = 0 + """Current episode number.""" self.terminateds = set() self.truncateds = set() @@ -159,9 +165,16 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): ) super().__init__() + @property + def agents(self) -> Dict[str, ProxyAgent]: + """Grab a fresh reference to the agents from this episode's game object.""" + return {name: self.game.rl_agents[name] for name in self._agent_ids} + def reset(self, *, seed: int = None, options: dict = None) -> Tuple[ObsType, Dict]: """Reset the environment.""" - self.game.reset() + self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=self.game_config) + self.game.setup_for_episode(episode=self.episode_counter) + self.episode_counter += 1 state = self.game.get_sim_state() self.game.update_agents(state) next_obs = self._get_obs() @@ -182,7 +195,7 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): # 1. Perform actions for agent_name, action in actions.items(): self.agents[agent_name].store_action(action) - agent_actions = self.game.apply_agent_actions() + self.game.apply_agent_actions() # 2. Advance timestep self.game.advance_timestep() @@ -196,7 +209,7 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): rewards = {name: agent.reward_function.current_reward for name, agent in self.agents.items()} terminateds = {name: False for name, _ in self.agents.items()} truncateds = {name: self.game.calculate_truncated() for name, _ in self.agents.items()} - infos = {"agent_actions": agent_actions} + infos = {name: {} for name, _ in self.agents.items()} terminateds["__all__"] = len(self.terminateds) == len(self.agents) truncateds["__all__"] = self.game.calculate_truncated() if self.game.save_step_metadata: @@ -222,8 +235,9 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): def _get_obs(self) -> Dict[str, ObsType]: """Return the current observation.""" obs = {} - for name, agent in self.agents.items(): + for agent_name in self._agent_ids: + agent = self.game.rl_agents[agent_name] unflat_space = agent.observation_manager.space unflat_obs = agent.observation_manager.current_observation - obs[name] = gymnasium.spaces.flatten(unflat_space, unflat_obs) + obs[agent_name] = gymnasium.spaces.flatten(unflat_space, unflat_obs) return obs diff --git a/tests/conftest.py b/tests/conftest.py index 5084c339..83ac9559 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -510,6 +510,6 @@ def game_and_agent(): reward_function=reward_function, ) - game.agents.append(test_agent) + game.agents["test_agent"] = test_agent return (game, test_agent) diff --git a/tests/integration_tests/game_configuration.py b/tests/integration_tests/game_configuration.py index 3bd870e3..f3dc51bd 100644 --- a/tests/integration_tests/game_configuration.py +++ b/tests/integration_tests/game_configuration.py @@ -42,20 +42,20 @@ def test_example_config(): assert len(game.agents) == 4 # red, blue and 2 green agents # green agent 1 - assert game.agents[0].agent_name == "client_2_green_user" - assert isinstance(game.agents[0], RandomAgent) + assert "client_2_green_user" in game.agents + assert isinstance(game.agents["client_2_green_user"], RandomAgent) # green agent 2 - assert game.agents[1].agent_name == "client_1_green_user" - assert isinstance(game.agents[1], RandomAgent) + assert "client_1_green_user" in game.agents + assert isinstance(game.agents["client_1_green_user"], RandomAgent) # red agent - assert game.agents[2].agent_name == "client_1_data_manipulation_red_bot" - assert isinstance(game.agents[2], DataManipulationAgent) + assert "client_1_data_manipulation_red_bot" in game.agents + assert isinstance(game.agents["client_1_data_manipulation_red_bot"], DataManipulationAgent) # blue agent - assert game.agents[3].agent_name == "defender" - assert isinstance(game.agents[3], ProxyAgent) + assert "defender" in game.agents + assert isinstance(game.agents["defender"], ProxyAgent) network: Network = game.simulation.network From ccb10f1160cee454216c205e15c08d2ecc0c02d7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 26 Feb 2024 11:02:37 +0000 Subject: [PATCH 631/980] Update docs based on reset refactor --- CHANGELOG.md | 1 + docs/index.rst | 1 + docs/source/environment.rst | 10 ++++++++++ docs/source/game_layer.rst | 5 +++++ docs/source/primaite_session.rst | 5 +++++ 5 files changed, 22 insertions(+) create mode 100644 docs/source/environment.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index 01e45d2e..d2a582be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- Made environment reset completely recreate the game object. - Changed the red agent in the data manipulation scenario to randomly choose client 1 or client 2 to start its attack. - Changed the data manipulation scenario to include a second green agent on client 1. - Refactored actions and observations to be configurable via object name, instead of UUID. diff --git a/docs/index.rst b/docs/index.rst index 9eae8adc..08e0ac21 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -108,6 +108,7 @@ Head over to the :ref:`getting-started` page to install and setup PrimAITE! source/simulation source/game_layer source/config + source/environment .. toctree:: :caption: Developer information: diff --git a/docs/source/environment.rst b/docs/source/environment.rst new file mode 100644 index 00000000..87e7f060 --- /dev/null +++ b/docs/source/environment.rst @@ -0,0 +1,10 @@ +RL Environments +*************** + +RL environments are the objects that directly interface with RL libraries such as Stable-Baselines3 and Ray RLLib. The PrimAITE simulation is exposed via three different environment APIs: + +* Gymnasium API - this is the standard interface that works with many RL libraries like SB3, Ray, Tianshou, etc. ``PrimaiteGymEnv`` adheres to the `Official Gymnasium documentation `_. +* Ray Single agent API - For training a single Ray RLLib agent +* Ray MARL API - For training multi-agent systems with Ray RLLib. ``PrimaiteRayMARLEnv`` adheres to the `Official Ray documentation `_. + +There is a Jupyter notebook which demonstrates integration with each of these three environments. They are located in ``~/primaite//notebooks/example_notebooks``. diff --git a/docs/source/game_layer.rst b/docs/source/game_layer.rst index cdae17dd..1f2921fe 100644 --- a/docs/source/game_layer.rst +++ b/docs/source/game_layer.rst @@ -20,6 +20,11 @@ The game layer is responsible for managing agents and getting them to interface PrimAITE Session ^^^^^^^^^^^^^^^ +.. admonition:: Deprecated + :class: deprecated + + PrimAITE Session is being deprecated in favour of Jupyter Notebooks. The `session` command will be removed in future releases, but example notebooks will be provided to demonstrate the same functionality. + ``PrimaiteSession`` is the main entry point into Primaite and it allows the simultaneous coordination of a simulation and agents that interact with it. ``PrimaiteSession`` keeps track of multiple agents of different types. Agents diff --git a/docs/source/primaite_session.rst b/docs/source/primaite_session.rst index 706397b6..87a3f03d 100644 --- a/docs/source/primaite_session.rst +++ b/docs/source/primaite_session.rst @@ -4,6 +4,11 @@ .. _run a primaite session: +.. admonition:: Deprecated + :class: deprecated + + PrimAITE Session is being deprecated in favour of Jupyter Notebooks. The ``session`` command will be removed in future releases, but example notebooks will be provided to demonstrate the same functionality. + Run a PrimAITE Session ====================== From d738a2370935c408973777ae5aeea542ba6e5294 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 26 Feb 2024 11:35:17 +0000 Subject: [PATCH 632/980] #2257: list of db payloads --- .../system/applications/data_manipulation_bot.rst | 2 +- .../system/applications/dos_bot.rst | 4 +++- .../system/common/common_configuration.rst | 4 ++++ .../system/common/db_payload_list.rst | 11 +++++++++++ .../system/services/database/database_service.py | 2 -- 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 docs/source/simulation_components/system/common/db_payload_list.rst diff --git a/docs/source/simulation_components/system/applications/data_manipulation_bot.rst b/docs/source/simulation_components/system/applications/data_manipulation_bot.rst index 209cdcbd..d0e89f2e 100644 --- a/docs/source/simulation_components/system/applications/data_manipulation_bot.rst +++ b/docs/source/simulation_components/system/applications/data_manipulation_bot.rst @@ -178,7 +178,7 @@ Optional. Default value is ``DELETE``. The payload that the ``DataManipulationBot`` will send to the :ref:`DatabaseService`. -See :ref:`Database Payload List` +.. include:: ../common/db_payload_list.rst ``port_scan_p_of_success`` """""""""""""""""""""""""" diff --git a/docs/source/simulation_components/system/applications/dos_bot.rst b/docs/source/simulation_components/system/applications/dos_bot.rst index fcf3f207..6ddbac72 100644 --- a/docs/source/simulation_components/system/applications/dos_bot.rst +++ b/docs/source/simulation_components/system/applications/dos_bot.rst @@ -123,6 +123,8 @@ Optional. Default value is ``None``. The payload that the ``DoSBot`` sends as part of its attack. +.. include:: ../common/db_payload_list.rst + ``repeat`` """""""""" @@ -155,4 +157,4 @@ Optional. Default value is ``1000``. The maximum number of sessions the ``DoSBot`` is able to make. -This must be an integer value above equal to or greater than ``0``. +This must be an integer value equal to or greater than ``0``. diff --git a/docs/source/simulation_components/system/common/common_configuration.rst b/docs/source/simulation_components/system/common/common_configuration.rst index 86991655..27625407 100644 --- a/docs/source/simulation_components/system/common/common_configuration.rst +++ b/docs/source/simulation_components/system/common/common_configuration.rst @@ -1,3 +1,7 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + ``ref`` ======= diff --git a/docs/source/simulation_components/system/common/db_payload_list.rst b/docs/source/simulation_components/system/common/db_payload_list.rst new file mode 100644 index 00000000..f51227c6 --- /dev/null +++ b/docs/source/simulation_components/system/common/db_payload_list.rst @@ -0,0 +1,11 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _Database Payload List: + +Available Database Payloads: + +- ``SELECT`` +- ``INSERT`` +- ``DELETE`` diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index c0390b4f..726d213e 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -195,8 +195,6 @@ class DatabaseService(Service): """ Executes the given SQL query and returns the result. - .. _Database Payload List: - Possible queries: - SELECT : returns the data - DELETE : deletes the data From a5043a8fbe01b38699cedf677129a17bec32655d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 26 Feb 2024 12:15:53 +0000 Subject: [PATCH 633/980] Modify tests based on refactoring --- src/primaite/session/session.py | 6 ++-- src/primaite/simulator/network/airspace.py | 5 --- .../network/hardware/nodes/host/host_node.py | 5 --- .../hardware/nodes/network/firewall.py | 18 ---------- .../network/hardware/nodes/network/switch.py | 6 ---- .../hardware/nodes/network/wireless_router.py | 3 -- .../assets/configs/bad_primaite_session.yaml | 7 ++-- .../configs/eval_only_primaite_session.yaml | 9 ++--- tests/assets/configs/multi_agent_session.yaml | 10 +++--- .../assets/configs/test_primaite_session.yaml | 9 ++--- .../configs/train_only_primaite_session.yaml | 9 ++--- .../environments/test_sb3_environment.py | 3 +- .../_simulator/_domain/test_account.py | 19 ----------- .../_file_system/test_file_system.py | 31 ----------------- .../_simulator/_network/test_container.py | 34 ------------------- .../_red_applications/test_dos_bot.py | 28 --------------- 16 files changed, 28 insertions(+), 174 deletions(-) diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py index 5c663cfd..b8f80e95 100644 --- a/src/primaite/session/session.py +++ b/src/primaite/session/session.py @@ -101,11 +101,11 @@ class PrimaiteSession: # CREATE ENVIRONMENT if sess.training_options.rl_framework == "RLLIB_single_agent": - sess.env = PrimaiteRayEnv(env_config={"cfg": cfg}) + sess.env = PrimaiteRayEnv(env_config=cfg) elif sess.training_options.rl_framework == "RLLIB_multi_agent": - sess.env = PrimaiteRayMARLEnv(env_config={"cfg": cfg}) + sess.env = PrimaiteRayMARLEnv(env_config=cfg) elif sess.training_options.rl_framework == "SB3": - sess.env = PrimaiteGymEnv(game=game) + sess.env = PrimaiteGymEnv(game_config=cfg) sess.policy = PolicyABC.from_config(sess.training_options, session=sess) if agent_load_path: diff --git a/src/primaite/simulator/network/airspace.py b/src/primaite/simulator/network/airspace.py index 724b8728..d264f751 100644 --- a/src/primaite/simulator/network/airspace.py +++ b/src/primaite/simulator/network/airspace.py @@ -273,11 +273,6 @@ class IPWirelessNetworkInterface(WirelessNetworkInterface, Layer3Interface, ABC) return state - def set_original_state(self): - """Sets the original state.""" - vals_to_include = {"ip_address", "subnet_mask", "mac_address", "speed", "mtu", "wake_on_lan", "enabled"} - self._original_state = self.model_dump(include=vals_to_include) - def enable(self): """ Enables this wired network interface and attempts to send a "hello" message to the default gateway. diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index 3f34f736..329a5fa0 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -213,11 +213,6 @@ class NIC(IPWiredNetworkInterface): return state - def set_original_state(self): - """Sets the original state.""" - vals_to_include = {"ip_address", "subnet_mask", "mac_address", "speed", "mtu", "wake_on_lan", "enabled"} - self._original_state = self.model_dump(include=vals_to_include) - def receive_frame(self, frame: Frame) -> bool: """ Attempt to receive and process a network frame from the connected Link. diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index 22effa2a..f2305652 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -109,24 +109,6 @@ class Firewall(Router): sys_log=kwargs["sys_log"], implicit_action=ACLAction.PERMIT, name=f"{hostname} - External Outbound" ) - self.set_original_state() - - def set_original_state(self): - """Set the original state for the Firewall.""" - super().set_original_state() - vals_to_include = { - "internal_port", - "external_port", - "dmz_port", - "internal_inbound_acl", - "internal_outbound_acl", - "dmz_inbound_acl", - "dmz_outbound_acl", - "external_inbound_acl", - "external_outbound_acl", - } - self._original_state.update(self.model_dump(include=vals_to_include)) - def describe_state(self) -> Dict: """ Describes the current state of the Firewall. diff --git a/src/primaite/simulator/network/hardware/nodes/network/switch.py b/src/primaite/simulator/network/hardware/nodes/network/switch.py index 33e6ee9a..557ea287 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/network/switch.py @@ -32,12 +32,6 @@ class SwitchPort(WiredNetworkInterface): _connected_node: Optional[Switch] = None "The Switch to which the SwitchPort is connected." - def set_original_state(self): - """Sets the original state.""" - vals_to_include = {"port_num", "mac_address", "speed", "mtu", "enabled"} - self._original_state = self.model_dump(include=vals_to_include) - super().set_original_state() - def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. diff --git a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py index dd0b58d3..91833d6a 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py @@ -122,8 +122,6 @@ class WirelessRouter(Router): self.connect_nic(RouterInterface(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0")) - self.set_original_state() - @property def wireless_access_point(self) -> WirelessAccessPoint: """ @@ -166,7 +164,6 @@ class WirelessRouter(Router): network_interface.ip_address = ip_address network_interface.subnet_mask = subnet_mask self.sys_log.info(f"Configured WAP {network_interface}") - self.set_original_state() self.wireless_access_point.frequency = frequency # Set operating frequency self.wireless_access_point.enable() # Re-enable the WAP with new settings diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 5bdc3273..c76aeef6 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -589,15 +589,16 @@ simulation: hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.10 + default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: + - ref: web_server_web_service + type: WebServer + applications: - ref: web_server_database_client type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: web_server_web_service - type: WebServer - ref: database_server diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index 8361e318..1cb59f87 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -593,15 +593,16 @@ simulation: hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.10 + default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: + - ref: web_server_web_service + type: WebServer + applications: - ref: web_server_database_client type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: web_server_web_service - type: WebServer - ref: database_server @@ -624,7 +625,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: backup_service - type: DatabaseBackup + type: FTPServer - ref: security_suite type: server diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 87bd9d1c..b1b15372 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -1043,16 +1043,16 @@ simulation: hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.10 + default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: + - ref: web_server_web_service + type: WebServer + applications: - ref: web_server_database_client type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: web_server_web_service - type: WebServer - - ref: database_server type: server @@ -1074,7 +1074,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: backup_service - type: DatabaseBackup + type: FTPServer - ref: security_suite type: server diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 76190a64..e5f9d544 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -599,15 +599,16 @@ simulation: hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.10 + default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: + - ref: web_server_web_service + type: WebServer + applications: - ref: web_server_database_client type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: web_server_web_service - type: WebServer - ref: database_server @@ -630,7 +631,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: backup_service - type: DatabaseBackup + type: FTPServer - ref: security_suite type: server diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index 5d004c7e..10e088d8 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -600,15 +600,16 @@ simulation: hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.10 + default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: + - ref: web_server_web_service + type: WebServer + applications: - ref: web_server_database_client type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: web_server_web_service - type: WebServer - ref: database_server @@ -631,7 +632,7 @@ simulation: dns_server: 192.168.1.10 services: - ref: backup_service - type: DatabaseBackup + type: FTPServer - ref: security_suite type: server diff --git a/tests/e2e_integration_tests/environments/test_sb3_environment.py b/tests/e2e_integration_tests/environments/test_sb3_environment.py index 91cf5c1e..dc5d10e9 100644 --- a/tests/e2e_integration_tests/environments/test_sb3_environment.py +++ b/tests/e2e_integration_tests/environments/test_sb3_environment.py @@ -17,8 +17,7 @@ def test_sb3_compatibility(): with open(example_config_path(), "r") as f: cfg = yaml.safe_load(f) - game = PrimaiteGame.from_config(cfg) - gym = PrimaiteGymEnv(game=game) + gym = PrimaiteGymEnv(game_config=cfg) model = PPO("MlpPolicy", gym) model.learn(total_timesteps=1000) diff --git a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py index 695b15dd..786fe851 100644 --- a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py +++ b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py @@ -12,20 +12,6 @@ def account() -> Account: def test_original_state(account): """Test the original state - see if it resets properly""" - account.log_on() - account.log_off() - account.disable() - - state = account.describe_state() - assert state["num_logons"] is 1 - assert state["num_logoffs"] is 1 - assert state["num_group_changes"] is 0 - assert state["username"] is "Jake" - assert state["password"] is "totally_hashed_password" - assert state["account_type"] is AccountType.USER.value - assert state["enabled"] is False - - account.reset_component_for_episode(episode=1) state = account.describe_state() assert state["num_logons"] is 0 assert state["num_logoffs"] is 0 @@ -39,11 +25,6 @@ def test_original_state(account): account.log_off() account.disable() - account.log_on() - state = account.describe_state() - assert state["num_logons"] is 2 - - account.reset_component_for_episode(episode=2) state = account.describe_state() assert state["num_logons"] is 1 assert state["num_logoffs"] is 1 diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 2fe3f04c..4defc80c 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -185,37 +185,6 @@ def test_get_file(file_system): file_system.show(full=True) -def test_reset_file_system(file_system): - # file and folder that existed originally - file_system.create_file(file_name="test_file.zip") - file_system.create_folder(folder_name="test_folder") - - # create a new file - file_system.create_file(file_name="new_file.txt") - - # create a new folder - file_system.create_folder(folder_name="new_folder") - - # delete the file that existed originally - file_system.delete_file(folder_name="root", file_name="test_file.zip") - assert file_system.get_file(folder_name="root", file_name="test_file.zip") is None - - # delete the folder that existed originally - file_system.delete_folder(folder_name="test_folder") - assert file_system.get_folder(folder_name="test_folder") is None - - # reset - file_system.reset_component_for_episode(episode=1) - - # deleted original file and folder should be back - assert file_system.get_file(folder_name="root", file_name="test_file.zip") - assert file_system.get_folder(folder_name="test_folder") - - # new file and folder should be removed - assert file_system.get_file(folder_name="root", file_name="new_file.txt") is None - assert file_system.get_folder(folder_name="new_folder") is None - - @pytest.mark.skip(reason="Skipping until we tackle serialisation") def test_serialisation(file_system): """Test to check that the object serialisation works correctly.""" diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index bf79677e..2cfc3f11 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -44,40 +44,6 @@ def test_describe_state(network): assert len(state["links"]) is 6 -def test_reset_network(network): - """ - Test that the network is properly reset. - - TODO: make sure that once implemented - any installed/uninstalled services, processes, apps, - etc are also removed/reinstalled - - """ - state_before = network.describe_state() - - client_1: Computer = network.get_node_by_hostname("client_1") - server_1: Computer = network.get_node_by_hostname("server_1") - - assert client_1.operating_state is NodeOperatingState.ON - assert server_1.operating_state is NodeOperatingState.ON - - client_1.power_off() - assert client_1.operating_state is NodeOperatingState.SHUTTING_DOWN - - server_1.power_off() - assert server_1.operating_state is NodeOperatingState.SHUTTING_DOWN - - assert network.describe_state() != state_before - - network.reset_component_for_episode(episode=1) - - assert client_1.operating_state is NodeOperatingState.ON - assert server_1.operating_state is NodeOperatingState.ON - # don't worry if UUIDs change - a = filter_keys_nested_item(json.dumps(network.describe_state(), sort_keys=True, indent=2), ["uuid"]) - b = filter_keys_nested_item(json.dumps(state_before, sort_keys=True, indent=2), ["uuid"]) - assert a == b - - def test_creating_container(): """Check that we can create a network container""" net = Network() diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py index 1f28244d..4bfd28d0 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_dos_bot.py @@ -27,34 +27,6 @@ def test_dos_bot_creation(dos_bot): assert dos_bot is not None -def test_dos_bot_reset(dos_bot): - assert dos_bot.target_ip_address == IPv4Address("192.168.0.1") - assert dos_bot.target_port is Port.POSTGRES_SERVER - assert dos_bot.payload is None - assert dos_bot.repeat is False - - dos_bot.configure( - target_ip_address=IPv4Address("192.168.1.1"), target_port=Port.HTTP, payload="payload", repeat=True - ) - - # should reset the relevant items - dos_bot.reset_component_for_episode(episode=0) - assert dos_bot.target_ip_address == IPv4Address("192.168.0.1") - assert dos_bot.target_port is Port.POSTGRES_SERVER - assert dos_bot.payload is None - assert dos_bot.repeat is False - - dos_bot.configure( - target_ip_address=IPv4Address("192.168.1.1"), target_port=Port.HTTP, payload="payload", repeat=True - ) - dos_bot.reset_component_for_episode(episode=1) - # should reset to the configured value - assert dos_bot.target_ip_address == IPv4Address("192.168.1.1") - assert dos_bot.target_port is Port.HTTP - assert dos_bot.payload == "payload" - assert dos_bot.repeat is True - - def test_dos_bot_cannot_run_when_node_offline(dos_bot): dos_bot_node: Computer = dos_bot.parent assert dos_bot_node.operating_state is NodeOperatingState.ON From 2076b011ba8837f8e85e362a68c71b1010aa8e0a Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 26 Feb 2024 14:26:47 +0000 Subject: [PATCH 634/980] Put back default router rules --- src/primaite/simulator/network/hardware/nodes/network/router.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 3111a153..52f38eb6 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1039,6 +1039,8 @@ class Router(NetworkNode): self.connect_nic(network_interface) self.network_interface[i] = network_interface + self._set_default_acl() + def _install_system_software(self): """ Installs essential system software and network services on the router. From f2d7a2fc1646e86f1c2fbb2d3f47020ac785a7c5 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 26 Feb 2024 14:34:34 +0000 Subject: [PATCH 635/980] #2257: added way to ensure nodes are on at start + more test to make sure nodes are on when added via config --- src/primaite/game/game.py | 9 +++++++-- .../nodes/network/test_firewall_config.py | 11 ++++++++++- .../nodes/network/test_router_config.py | 6 +++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index ef54893e..fbf6ea50 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -359,13 +359,18 @@ class PrimaiteGame: for nic_num, nic_cfg in node_cfg["network_interfaces"].items(): new_node.connect_nic(NIC(ip_address=nic_cfg["ip_address"], subnet_mask=nic_cfg["subnet_mask"])) - new_node.start_up_duration = int(node_cfg.get("start_up_duration", 3)) - new_node.shut_down_duration = int(node_cfg.get("shut_down_duration", 3)) + # temporarily set to 0 so all nodes are initially on + new_node.start_up_duration = 0 + new_node.shut_down_duration = 0 net.add_node(new_node) new_node.power_on() game.ref_map_nodes[node_ref] = new_node.uuid + # set start up and shut down duration + new_node.start_up_duration = int(node_cfg.get("start_up_duration", 3)) + new_node.shut_down_duration = int(node_cfg.get("shut_down_duration", 3)) + # 2. create links between nodes for link_cfg in links_cfg: node_a = net.nodes[game.ref_map_nodes[link_cfg["endpoint_a_ref"]]] diff --git a/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py b/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py index ae71809b..2e0556e9 100644 --- a/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py +++ b/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py @@ -1,6 +1,7 @@ import pytest from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.hardware.nodes.network.firewall import Firewall @@ -20,7 +21,10 @@ def test_firewall_is_in_configuration(dmz_config): """Test that the firewall exists in the configuration file.""" network: Network = dmz_config - assert network.get_node_by_hostname("firewall") + firewall: Firewall = network.get_node_by_hostname("firewall") + + assert firewall + assert firewall.operating_state == NodeOperatingState.ON def test_firewall_routes_are_correctly_added(dmz_config): @@ -39,6 +43,11 @@ def test_firewall_routes_are_correctly_added(dmz_config): assert external_computer.ping(client_1.network_interface[1].ip_address) assert external_server.ping(client_1.network_interface[1].ip_address) + # client_1 should be able to ping other nodes + assert client_1.ping(dmz_server.network_interface[1].ip_address) + assert client_1.ping(external_computer.network_interface[1].ip_address) + assert client_1.ping(external_server.network_interface[1].ip_address) + def test_firewall_acl_rules_correctly_added(dmz_config): """ diff --git a/tests/integration_tests/configuration_file_parsing/nodes/network/test_router_config.py b/tests/integration_tests/configuration_file_parsing/nodes/network/test_router_config.py index fbaca12d..4382cc30 100644 --- a/tests/integration_tests/configuration_file_parsing/nodes/network/test_router_config.py +++ b/tests/integration_tests/configuration_file_parsing/nodes/network/test_router_config.py @@ -1,6 +1,7 @@ import pytest from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router @@ -19,7 +20,10 @@ def test_router_is_in_configuration(dmz_config): """Test that the router exists in the configuration file.""" network: Network = dmz_config - assert network.get_node_by_hostname("router_1") + router_1: Router = network.get_node_by_hostname("router_1") + + assert router_1 + assert router_1.operating_state == NodeOperatingState.ON def test_router_routes_are_correctly_added(dmz_config): From f9cc5af7aab3d822dcc23472f65c74a04ced4650 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 26 Feb 2024 16:06:58 +0000 Subject: [PATCH 636/980] Not sure how this test was passing before --- .../_primaite/_simulator/_system/test_software.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/unit_tests/_primaite/_simulator/_system/test_software.py b/tests/unit_tests/_primaite/_simulator/_system/test_software.py index e77cd895..6f680012 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/test_software.py +++ b/tests/unit_tests/_primaite/_simulator/_system/test_software.py @@ -2,12 +2,14 @@ from typing import Dict import pytest +from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.sys_log import SysLog -from primaite.simulator.system.software import Software, SoftwareHealthState +from primaite.simulator.system.services.service import Service +from primaite.simulator.system.software import IOSoftware, SoftwareHealthState -class TestSoftware(Software): +class TestSoftware(Service): def describe_state(self) -> Dict: pass @@ -15,7 +17,11 @@ class TestSoftware(Software): @pytest.fixture(scope="function") def software(file_system): return TestSoftware( - name="TestSoftware", port=Port.ARP, file_system=file_system, sys_log=SysLog(hostname="test_service") + name="TestSoftware", + port=Port.ARP, + file_system=file_system, + sys_log=SysLog(hostname="test_service"), + protocol=IPProtocol.TCP, ) From 33d2ecc26a4ac125607477c0a2846afa1b6fc728 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 26 Feb 2024 16:58:43 +0000 Subject: [PATCH 637/980] Apply suggestions from code review. --- docs/source/environment.rst | 2 +- .../config/_package_data/example_config_2_rl_agents.yaml | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/source/environment.rst b/docs/source/environment.rst index 87e7f060..2b76572d 100644 --- a/docs/source/environment.rst +++ b/docs/source/environment.rst @@ -7,4 +7,4 @@ RL environments are the objects that directly interface with RL libraries such a * Ray Single agent API - For training a single Ray RLLib agent * Ray MARL API - For training multi-agent systems with Ray RLLib. ``PrimaiteRayMARLEnv`` adheres to the `Official Ray documentation `_. -There is a Jupyter notebook which demonstrates integration with each of these three environments. They are located in ``~/primaite//notebooks/example_notebooks``. +There are Jupyter notebooks which demonstrate integration with each of these three environments. They are located in ``~/primaite//notebooks/example_notebooks``. diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index 1ccd7b38..c1e077be 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -1,11 +1,17 @@ training_config: rl_framework: RLLIB_multi_agent - # rl_framework: SB3 + rl_algorithm: PPO + seed: 333 + n_learn_episodes: 1 + n_eval_episodes: 5 + max_steps_per_episode: 256 + deterministic_eval: false n_agents: 2 agent_references: - defender_1 - defender_2 + io_settings: save_checkpoints: true checkpoint_interval: 5 From 922298eaf02f2ab7897f7523aa9bf3122add51f4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 26 Feb 2024 20:07:02 +0000 Subject: [PATCH 638/980] Make database admin action possible --- .../config/_package_data/example_config.yaml | 69 ++++++++++++++++--- src/primaite/game/agent/rewards.py | 41 +++++++++++ .../system/applications/database_client.py | 30 +++++++- 3 files changed, 129 insertions(+), 11 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index f85baf10..a0e9667e 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -33,7 +33,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: GreenWebBrowsingAgent + type: GreenUC2Agent observation_space: type: UC2GreenObservation action_space: @@ -45,24 +45,39 @@ agents: - node_name: client_2 applications: - application_name: WebBrowser + - application_name: DatabaseClient max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 - max_applications_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 reward_function: reward_components: - type: DUMMY agent_settings: - start_settings: - start_step: 5 - frequency: 4 - variance: 3 + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 - ref: client_1_green_user team: GREEN - type: GreenWebBrowsingAgent + type: GreenUC2Agent observation_space: type: UC2GreenObservation action_space: @@ -74,14 +89,36 @@ agents: - node_name: client_1 applications: - application_name: WebBrowser + - application_name: DatabaseClient max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 - max_applications_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 + reward_function: reward_components: - type: DUMMY + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 + @@ -572,6 +609,14 @@ agents: weight: 0.33 options: node_hostname: client_2 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.1 + options: + node_hostname: client_1 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.1 + options: + node_hostname: client_2 agent_settings: @@ -717,6 +762,10 @@ simulation: type: WebBrowser options: target_url: http://arcd.com/users/ + - ref: client_1_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 services: - ref: client_1_dns_client type: DNSClient @@ -740,6 +789,10 @@ simulation: data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 + - ref: client_2_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 services: - ref: client_2_dns_client type: DNSClient diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index b5d5f998..acc37711 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -242,6 +242,46 @@ class WebpageUnavailablePenalty(AbstractReward): return cls(node_hostname=node_hostname) +class GreenAdminDatabaseUnreachablePenalty(AbstractReward): + """Penalises the agent when the green db clients fail to connect to the database.""" + + def __init__(self, node_hostname: str) -> None: + """ + Initialise the reward component. + + :param node_hostname: Hostname of the node where the database client sits. + :type node_hostname: str + """ + self._node = node_hostname + self.location_in_state = ["network", "nodes", node_hostname, "applications", "DatabaseClient"] + + def calculate(self, state: Dict) -> float: + """ + Calculate the reward based on current simulation state. + + :param state: The current state of the simulation. + :type state: Dict + """ + db_state = access_from_nested_dict(state, self.location_in_state) + if db_state is NOT_PRESENT_IN_STATE or "connections_status" not in db_state: + _LOGGER.debug(f"Can't calculate reward for {self.__class__.__name__}") + connections_status = db_state["connections_status"] + if False in connections_status: + return -1.0 + return 0 + + @classmethod + def from_config(cls, config: Dict) -> AbstractReward: + """ + Build the reward component object from config. + + :param config: Configuration dictionary. + :type config: Dict + """ + node_hostname = config.get("node_hostname") + return cls(node_hostname=node_hostname) + + class RewardFunction: """Manages the reward function for the agent.""" @@ -250,6 +290,7 @@ class RewardFunction: "DATABASE_FILE_INTEGRITY": DatabaseFileIntegrity, "WEB_SERVER_404_PENALTY": WebServer404Penalty, "WEBPAGE_UNAVAILABLE_PENALTY": WebpageUnavailablePenalty, + "GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY": GreenAdminDatabaseUnreachablePenalty, } def __init__(self): diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 50d9f3d4..67c0c9b4 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -1,8 +1,9 @@ from ipaddress import IPv4Address -from typing import Any, Dict, Optional +from typing import Any, Dict, List, Optional from uuid import uuid4 from primaite import getLogger +from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application @@ -25,6 +26,8 @@ class DatabaseClient(Application): server_password: Optional[str] = None connected: bool = False _query_success_tracker: Dict[str, bool] = {} + _connections_status: List[bool] = [] + """Keep track of connections that were established or verified during this step. Used for rewards.""" def __init__(self, **kwargs): kwargs["name"] = "DatabaseClient" @@ -33,6 +36,20 @@ class DatabaseClient(Application): super().__init__(**kwargs) self.set_original_state() + def _init_request_manager(self) -> RequestManager: + rm = super()._init_request_manager() + rm.add_request("execute", RequestType(func=lambda request, context: self.execute())) + return rm + + def execute(self) -> bool: + """Execution definition for db client: perform a select query.""" + if self.connections: + can_connect = self.connect(connection_id=list(self.connections.keys())[-1]) + else: + can_connect = self.connect() + self._connections_status.append(can_connect) + return can_connect + def set_original_state(self): """Sets the original state.""" _LOGGER.debug(f"Setting DatabaseClient WebServer original state on node {self.software_manager.node.hostname}") @@ -52,8 +69,11 @@ class DatabaseClient(Application): :return: A dictionary representing the current state. """ - pass - return super().describe_state() + state = super().describe_state() + # list of connections that were established or verified during this step. + state["connections_status"] = [c for c in self._connections_status] + self._connections_status.clear() + return state def configure(self, server_ip_address: IPv4Address, server_password: Optional[str] = None): """ @@ -74,6 +94,10 @@ class DatabaseClient(Application): if not connection_id: connection_id = str(uuid4()) + # if we are reusing a connection_id, remove it from self.connections so that its new status can be populated + # warning: janky + self._connections.pop(connection_id, None) + self.connected = self._connect( server_ip_address=self.server_ip_address, password=self.server_password, connection_id=connection_id ) From c54f82fb1bd8c961bc4d7a250e8ea9572fb44b33 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 26 Feb 2024 20:08:13 +0000 Subject: [PATCH 639/980] Start implementing green agent logic for UC2 --- src/primaite/game/agent/scripted_agents.py | 62 +++++++++++++++++++++- src/primaite/game/game.py | 5 +- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/primaite/game/agent/scripted_agents.py b/src/primaite/game/agent/scripted_agents.py index 3748494b..a88e563d 100644 --- a/src/primaite/game/agent/scripted_agents.py +++ b/src/primaite/game/agent/scripted_agents.py @@ -1,10 +1,70 @@ """Agents with predefined behaviours.""" +from typing import Dict, Optional, Tuple + +import numpy as np +import pydantic +from gymnasium.core import ObsType + +from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractScriptedAgent +from primaite.game.agent.observations import ObservationManager +from primaite.game.agent.rewards import RewardFunction -class GreenWebBrowsingAgent(AbstractScriptedAgent): +class GreenUC2Agent(AbstractScriptedAgent): """Scripted agent which attempts to send web requests to a target node.""" + class GreenUC2AgentSettings(pydantic.BaseModel): + model_config = pydantic.ConfigDict(extra="forbid") + action_probabilities: Dict[int, float] + """Probability to perform each action in the action map. The sum of probabilities should sum to 1.""" + random_seed: Optional[int] = None + + @pydantic.field_validator("action_probabilities", mode="after") + @classmethod + def probabilities_sum_to_one(cls, v: Dict[int, float]) -> Dict[int, float]: + if not abs(sum(v.values()) - 1) < 1e-6: + raise ValueError(f"Green action probabilities must sum to 1") + return v + + @pydantic.field_validator("action_probabilities", mode="after") + @classmethod + def action_map_covered_correctly(cls, v: Dict[int, float]) -> Dict[int, float]: + if not all((i in v) for i in range(len(v))): + raise ValueError( + "Green action probabilities must be defined as a mapping where the keys are consecutive integers " + "from 0 to N." + ) + + def __init__( + self, + agent_name: str, + action_space: Optional[ActionManager], + observation_space: Optional[ObservationManager], + reward_function: Optional[RewardFunction], + settings: Dict = {}, + ) -> None: + # If the action probabilities are not specified, create equal probabilities for all actions + if "action_probabilities" not in settings: + num_actions = len(action_space.action_map) + settings = {"action_probabilities": {i: 1 / num_actions for i in range(num_actions)}} + + # If seed not specified, set it to None so that numpy chooses a random one. + settings.setdefault("random_seed") + + self.settings = GreenUC2Agent.GreenUC2AgentSettings(settings) + + self.rng = np.random.default_rng(self.settings.random_seed) + + # convert probabilities from + self.probabilities = np.array[self.settings.action_probabilities.values()] + + super().__init__(agent_name, action_space, observation_space, reward_function) + + def get_action(self, obs: ObsType, reward: float = 0) -> Tuple[str, Dict]: + choice = self.rng.choice(len(self.action_manager.action_map), p=self.probabilities) + return self.action_manager.get_action(choice) + raise NotImplementedError diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index ed98accd..a9d564ba 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -10,6 +10,7 @@ from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent, RandomAgent from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction +from primaite.game.agent.scripted_agents import GreenUC2Agent from primaite.session.io import SessionIO, SessionIOSettings from primaite.simulator.network.hardware.base import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer @@ -392,9 +393,9 @@ class PrimaiteGame: agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) # CREATE AGENT - if agent_type == "GreenWebBrowsingAgent": + if agent_type == "GreenUC2Agent": # TODO: implement non-random agents and fix this parsing - new_agent = RandomAgent( + new_agent = GreenUC2Agent( agent_name=agent_cfg["ref"], action_space=action_space, observation_space=obs_space, From af8ca82fcbbb22a7c3d529b7f28f1befb1c20104 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 27 Feb 2024 13:30:16 +0000 Subject: [PATCH 640/980] Get the db admin green agent working --- .../config/_package_data/example_config.yaml | 19 +- .../example_config_2_rl_agents.yaml | 2 +- src/primaite/game/agent/actions.py | 43 ++-- .../game/agent/data_manipulation_bot.py | 10 +- src/primaite/game/agent/interface.py | 10 +- src/primaite/game/agent/scripted_agents.py | 43 ++-- src/primaite/game/game.py | 13 +- src/primaite/notebooks/uc2_demo.ipynb | 232 +++++++++++++++++- .../assets/configs/bad_primaite_session.yaml | 2 +- .../configs/basic_switched_network.yaml | 2 +- .../configs/eval_only_primaite_session.yaml | 2 +- tests/assets/configs/multi_agent_session.yaml | 2 +- .../assets/configs/test_primaite_session.yaml | 2 +- .../configs/train_only_primaite_session.yaml | 2 +- tests/conftest.py | 5 +- .../_game/_agent/test_probabilistic_agent.py | 84 +++++++ 16 files changed, 386 insertions(+), 87 deletions(-) create mode 100644 tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index a0e9667e..6813161d 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -33,7 +33,12 @@ game: agents: - ref: client_2_green_user team: GREEN - type: GreenUC2Agent + type: probabilistic_agent + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 observation_space: type: UC2GreenObservation action_space: @@ -69,15 +74,14 @@ agents: reward_components: - type: DUMMY + - ref: client_1_green_user + team: GREEN + type: probabilistic_agent agent_settings: action_probabilities: 0: 0.3 1: 0.6 2: 0.1 - - - ref: client_1_green_user - team: GREEN - type: GreenUC2Agent observation_space: type: UC2GreenObservation action_space: @@ -113,11 +117,6 @@ agents: reward_components: - type: DUMMY - agent_settings: - action_probabilities: - 0: 0.3 - 1: 0.6 - 2: 0.1 diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index 93019c9d..df6130d1 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -27,7 +27,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: GreenWebBrowsingAgent + type: probabilistic_agent observation_space: type: UC2GreenObservation action_space: diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 1793d420..18cb6262 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -607,7 +607,6 @@ class ActionManager: def __init__( self, - game: "PrimaiteGame", # reference to game for information lookup actions: List[Dict], # stores list of actions available to agent nodes: List[Dict], # extra configuration for each node max_folders_per_node: int = 2, # allows calculating shape @@ -618,7 +617,7 @@ class ActionManager: max_acl_rules: int = 10, # allows calculating shape protocols: List[str] = ["TCP", "UDP", "ICMP"], # allow mapping index to protocol ports: List[str] = ["HTTP", "DNS", "ARP", "FTP", "NTP"], # allow mapping index to port - ip_address_list: Optional[List[str]] = None, # to allow us to map an index to an ip address. + ip_address_list: List[str] = [], # to allow us to map an index to an ip address. act_map: Optional[Dict[int, Dict]] = None, # allows restricting set of possible actions ) -> None: """Init method for ActionManager. @@ -649,7 +648,6 @@ class ActionManager: :param act_map: Action map which maps integers to actions. Used for restricting the set of possible actions. :type act_map: Optional[Dict[int, Dict]] """ - self.game: "PrimaiteGame" = game self.node_names: List[str] = [n["node_name"] for n in nodes] """List of node names in this action space. The list order is the mapping between node index and node name.""" self.application_names: List[List[str]] = [] @@ -707,25 +705,7 @@ class ActionManager: self.protocols: List[str] = protocols self.ports: List[str] = ports - self.ip_address_list: List[str] - - # If the user has provided a list of IP addresses, use that. Otherwise, generate a list of IP addresses from - # the nodes in the simulation. - # TODO: refactor. Options: - # 1: This should be pulled out into it's own function for clarity - # 2: The simulation itself should be able to provide a list of IP addresses with its API, rather than having to - # go through the nodes here. - if ip_address_list is not None: - self.ip_address_list = ip_address_list - else: - self.ip_address_list = [] - for node_name in self.node_names: - node_obj = self.game.simulation.network.get_node_by_hostname(node_name) - if node_obj is None: - continue - network_interfaces = node_obj.network_interfaces - for nic_uuid, nic_obj in network_interfaces.items(): - self.ip_address_list.append(nic_obj.ip_address) + self.ip_address_list: List[str] = ip_address_list # action_args are settings which are applied to the action space as a whole. global_action_args = { @@ -958,6 +938,12 @@ class ActionManager: :return: The constructed ActionManager. :rtype: ActionManager """ + # If the user has provided a list of IP addresses, use that. Otherwise, generate a list of IP addresses from + # the nodes in the simulation. + # TODO: refactor. Options: + # 1: This should be pulled out into it's own function for clarity + # 2: The simulation itself should be able to provide a list of IP addresses with its API, rather than having to + # go through the nodes here. ip_address_order = cfg["options"].pop("ip_address_order", {}) ip_address_list = [] for entry in ip_address_order: @@ -967,13 +953,22 @@ class ActionManager: ip_address = node_obj.network_interface[nic_num].ip_address ip_address_list.append(ip_address) + if not ip_address_list: + node_names = [n["node_name"] for n in cfg.get("nodes", {})] + for node_name in node_names: + node_obj = game.simulation.network.get_node_by_hostname(node_name) + if node_obj is None: + continue + network_interfaces = node_obj.network_interfaces + for nic_uuid, nic_obj in network_interfaces.items(): + ip_address_list.append(nic_obj.ip_address) + obj = cls( - game=game, actions=cfg["action_list"], **cfg["options"], protocols=game.options.protocols, ports=game.options.ports, - ip_address_list=ip_address_list or None, + ip_address_list=ip_address_list, act_map=cfg.get("action_map"), ) diff --git a/src/primaite/game/agent/data_manipulation_bot.py b/src/primaite/game/agent/data_manipulation_bot.py index 126c55ec..b5de9a5a 100644 --- a/src/primaite/game/agent/data_manipulation_bot.py +++ b/src/primaite/game/agent/data_manipulation_bot.py @@ -1,5 +1,5 @@ import random -from typing import Dict, Tuple +from typing import Dict, Optional, Tuple from gymnasium.core import ObsType @@ -26,7 +26,7 @@ class DataManipulationAgent(AbstractScriptedAgent): ) self.next_execution_timestep = timestep + random_timestep_increment - def get_action(self, obs: ObsType, reward: float = None) -> Tuple[str, Dict]: + def get_action(self, obs: ObsType, reward: float = 0.0, timestep: Optional[int] = None) -> Tuple[str, Dict]: """Randomly sample an action from the action space. :param obs: _description_ @@ -36,12 +36,10 @@ class DataManipulationAgent(AbstractScriptedAgent): :return: _description_ :rtype: Tuple[str, Dict] """ - current_timestep = self.action_manager.game.step_counter - - if current_timestep < self.next_execution_timestep: + if timestep < self.next_execution_timestep: return "DONOTHING", {"dummy": 0} - self._set_next_execution_timestep(current_timestep + self.agent_settings.start_settings.frequency) + self._set_next_execution_timestep(timestep + self.agent_settings.start_settings.frequency) return "NODE_APPLICATION_EXECUTE", {"node_id": self.starting_node_idx, "application_id": 0} diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 276715f7..4f434bad 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -112,7 +112,7 @@ class AbstractAgent(ABC): return self.reward_function.update(state) @abstractmethod - def get_action(self, obs: ObsType, reward: float = 0.0) -> Tuple[str, Dict]: + def get_action(self, obs: ObsType, reward: float = 0.0, timestep: Optional[int] = None) -> Tuple[str, Dict]: """ Return an action to be taken in the environment. @@ -122,6 +122,8 @@ class AbstractAgent(ABC): :type obs: ObsType :param reward: Reward from the previous action, defaults to None TODO: should this parameter even be accepted? :type reward: float, optional + :param timestep: The current timestep in the simulation, used for non-RL agents. Optional + :type timestep: int :return: Action to be taken in the environment. :rtype: Tuple[str, Dict] """ @@ -144,13 +146,13 @@ class AbstractAgent(ABC): class AbstractScriptedAgent(AbstractAgent): """Base class for actors which generate their own behaviour.""" - ... + pass class RandomAgent(AbstractScriptedAgent): """Agent that ignores its observation and acts completely at random.""" - def get_action(self, obs: ObsType, reward: float = 0.0) -> Tuple[str, Dict]: + def get_action(self, obs: ObsType, reward: float = 0.0, timestep: Optional[int] = None) -> Tuple[str, Dict]: """Randomly sample an action from the action space. :param obs: _description_ @@ -183,7 +185,7 @@ class ProxyAgent(AbstractAgent): self.most_recent_action: ActType self.flatten_obs: bool = agent_settings.flatten_obs if agent_settings else False - def get_action(self, obs: ObsType, reward: float = 0.0) -> Tuple[str, Dict]: + def get_action(self, obs: ObsType, reward: float = 0.0, timestep: Optional[int] = None) -> Tuple[str, Dict]: """ Return the agent's most recent action, formatted in CAOS format. diff --git a/src/primaite/game/agent/scripted_agents.py b/src/primaite/game/agent/scripted_agents.py index a88e563d..28d94062 100644 --- a/src/primaite/game/agent/scripted_agents.py +++ b/src/primaite/game/agent/scripted_agents.py @@ -11,30 +11,39 @@ from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction -class GreenUC2Agent(AbstractScriptedAgent): - """Scripted agent which attempts to send web requests to a target node.""" +class ProbabilisticAgent(AbstractScriptedAgent): + """Scripted agent which randomly samples its action space with prescribed probabilities for each action.""" + + class Settings(pydantic.BaseModel): + """Config schema for Probabilistic agent settings.""" - class GreenUC2AgentSettings(pydantic.BaseModel): model_config = pydantic.ConfigDict(extra="forbid") + """Strict validation.""" action_probabilities: Dict[int, float] """Probability to perform each action in the action map. The sum of probabilities should sum to 1.""" random_seed: Optional[int] = None + """Random seed. If set, each episode the agent will choose the same random sequence of actions.""" + # TODO: give the option to still set a random seed, but have it vary each episode in a predictable way + # for example if the user sets seed 123, have it be 123 + episode_num, so that each ep it's the next seed. @pydantic.field_validator("action_probabilities", mode="after") @classmethod def probabilities_sum_to_one(cls, v: Dict[int, float]) -> Dict[int, float]: + """Make sure the probabilities sum to 1.""" if not abs(sum(v.values()) - 1) < 1e-6: - raise ValueError(f"Green action probabilities must sum to 1") + raise ValueError("Green action probabilities must sum to 1") return v @pydantic.field_validator("action_probabilities", mode="after") @classmethod def action_map_covered_correctly(cls, v: Dict[int, float]) -> Dict[int, float]: + """Ensure that the keys of the probability dictionary cover all integers from 0 to N.""" if not all((i in v) for i in range(len(v))): raise ValueError( "Green action probabilities must be defined as a mapping where the keys are consecutive integers " "from 0 to N." ) + return v def __init__( self, @@ -52,23 +61,27 @@ class GreenUC2Agent(AbstractScriptedAgent): # If seed not specified, set it to None so that numpy chooses a random one. settings.setdefault("random_seed") - self.settings = GreenUC2Agent.GreenUC2AgentSettings(settings) + self.settings = ProbabilisticAgent.Settings(**settings) self.rng = np.random.default_rng(self.settings.random_seed) # convert probabilities from - self.probabilities = np.array[self.settings.action_probabilities.values()] + self.probabilities = np.asarray(list(self.settings.action_probabilities.values())) super().__init__(agent_name, action_space, observation_space, reward_function) - def get_action(self, obs: ObsType, reward: float = 0) -> Tuple[str, Dict]: + def get_action(self, obs: ObsType, reward: float = 0.0, timestep: Optional[int] = None) -> Tuple[str, Dict]: + """ + Choose a random action from the action space. + + The probability of each action is given by the corresponding index in ``self.probabilities``. + + :param obs: Current observation of the simulation + :type obs: ObsType + :param reward: Reward for the last step, not used for scripted agents, defaults to 0 + :type reward: float, optional + :return: Action to be taken in CAOS format. + :rtype: Tuple[str, Dict] + """ choice = self.rng.choice(len(self.action_manager.action_map), p=self.probabilities) return self.action_manager.get_action(choice) - - raise NotImplementedError - - -class RedDatabaseCorruptingAgent(AbstractScriptedAgent): - """Scripted agent which attempts to corrupt the database of the target node.""" - - raise NotImplementedError diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index a9d564ba..b44abe16 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -7,10 +7,10 @@ from pydantic import BaseModel, ConfigDict from primaite import getLogger from primaite.game.agent.actions import ActionManager from primaite.game.agent.data_manipulation_bot import DataManipulationAgent -from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent, RandomAgent +from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction -from primaite.game.agent.scripted_agents import GreenUC2Agent +from primaite.game.agent.scripted_agents import ProbabilisticAgent from primaite.session.io import SessionIO, SessionIOSettings from primaite.simulator.network.hardware.base import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer @@ -165,7 +165,7 @@ class PrimaiteGame: for agent in self.agents: obs = agent.observation_manager.current_observation rew = agent.reward_function.current_reward - action_choice, options = agent.get_action(obs, rew) + action_choice, options = agent.get_action(obs, rew, timestep=self.step_counter) agent_actions[agent.agent_name] = (action_choice, options) request = agent.format_request(action_choice, options) self.simulation.apply_request(request) @@ -393,14 +393,15 @@ class PrimaiteGame: agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) # CREATE AGENT - if agent_type == "GreenUC2Agent": + if agent_type == "probabilistic_agent": # TODO: implement non-random agents and fix this parsing - new_agent = GreenUC2Agent( + settings = agent_cfg.get("agent_settings") + new_agent = ProbabilisticAgent( agent_name=agent_cfg["ref"], action_space=action_space, observation_space=obs_space, reward_function=reward_function, - agent_settings=agent_settings, + settings=settings, ) game.agents.append(new_agent) elif agent_type == "ProxyAgent": diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index c4fe4c9a..fa4a28a4 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -334,7 +334,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "tags": [] }, @@ -346,7 +346,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "tags": [] }, @@ -371,11 +371,150 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-02-27 09:43:39,312::WARNING::primaite.game.game::275::service type not found DatabaseClient\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Resetting environment, episode 0, avg. reward: 0.0\n", + "env created successfully\n", + "{'ACL': {1: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 0,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 2: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 1,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 3: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 2,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 4: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 3,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 5: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 4,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 6: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 5,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 7: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 6,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 8: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 7,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 9: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 8,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 10: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 9,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0}},\n", + " 'ICS': 0,\n", + " 'LINKS': {1: {'PROTOCOLS': {'ALL': 1}},\n", + " 2: {'PROTOCOLS': {'ALL': 1}},\n", + " 3: {'PROTOCOLS': {'ALL': 1}},\n", + " 4: {'PROTOCOLS': {'ALL': 1}},\n", + " 5: {'PROTOCOLS': {'ALL': 1}},\n", + " 6: {'PROTOCOLS': {'ALL': 1}},\n", + " 7: {'PROTOCOLS': {'ALL': 1}},\n", + " 8: {'PROTOCOLS': {'ALL': 1}},\n", + " 9: {'PROTOCOLS': {'ALL': 1}},\n", + " 10: {'PROTOCOLS': {'ALL': 0}}},\n", + " 'NODES': {1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1},\n", + " 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1},\n", + " 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}},\n", + " 'health_status': 1}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1},\n", + " 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1},\n", + " 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1},\n", + " 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1},\n", + " 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1},\n", + " 2: {'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}}\n" + ] + } + ], "source": [ "# create the env\n", "with open(example_config_path(), 'r') as f:\n", @@ -403,7 +542,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -421,15 +560,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 211, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 212, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 213, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 214, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 215, Red action: DO NOTHING, Blue reward:-0.42\n", + "step: 216, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 217, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 218, Red action: DO NOTHING, Blue reward:-0.42\n", + "step: 219, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 220, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 221, Red action: ATTACK from client 2, Blue reward:-0.32\n", + "step: 222, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 223, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 224, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 225, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 226, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 227, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 228, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 229, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 230, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 231, Red action: DO NOTHING, Blue reward:-0.42\n", + "step: 232, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 233, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 234, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 235, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 236, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 237, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 238, Red action: ATTACK from client 2, Blue reward:-0.32\n", + "step: 239, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 240, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 241, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 242, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 243, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 244, Red action: DO NOTHING, Blue reward:-0.32\n", + "step: 245, Red action: DO NOTHING, Blue reward:-0.32\n" + ] + } + ], "source": [ "for step in range(35):\n", " obs, reward, terminated, truncated, info = env.step(0)\n", - " print(f\"step: {env.game.step_counter}, Red action: {friendly_output_red_action(info)}, Blue reward:{reward}\" )" + " print(f\"step: {env.game.step_counter}, Red action: {friendly_output_red_action(info)}, Blue reward:{reward:.2f}\" )" ] }, { @@ -509,7 +690,7 @@ "\n", "The reward will increase slightly as soon as the file finishes restoring. Then, the reward will increase to 1 when both green agents make successful requests.\n", "\n", - "Run the following cell until the green action is `NODE_APPLICATION_EXECUTE`, then the reward should become 1. If you run it enough times, another red attack will happen and the reward will drop again." + "Run the following cell until the green action is `NODE_APPLICATION_EXECUTE` for application 0, then the reward should become 1. If you run it enough times, another red attack will happen and the reward will drop again." ] }, { @@ -523,8 +704,8 @@ "obs, reward, terminated, truncated, info = env.step(0) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker'][0]}\" )\n", - "print(f\"Green action: {info['agent_actions']['client_2_green_user'][0]}\" )\n", - "print(f\"Green action: {info['agent_actions']['client_1_green_user'][0]}\" )\n", + "print(f\"Green action: {info['agent_actions']['client_2_green_user']}\" )\n", + "print(f\"Green action: {info['agent_actions']['client_1_green_user']}\" )\n", "print(f\"Blue reward:{reward}\" )" ] }, @@ -582,6 +763,33 @@ "obs['ACL']" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "net = env.game.simulation.network" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "dbc = net.get_node_by_hostname('client_1').software_manager.software.get('DatabaseClient')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "dbc._query_success_tracker" + ] + }, { "cell_type": "code", "execution_count": null, @@ -606,7 +814,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 5bdc3273..892e6af7 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -21,7 +21,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: GreenWebBrowsingAgent + type: probabilistic_agent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index d1cec079..ad2ea787 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -33,7 +33,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: GreenWebBrowsingAgent + type: probabilistic_agent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index 8361e318..9b668686 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -25,7 +25,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: GreenWebBrowsingAgent + type: probabilistic_agent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 87bd9d1c..5a7d8366 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -31,7 +31,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: GreenWebBrowsingAgent + type: probabilistic_agent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 76190a64..42dd27fb 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -29,7 +29,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: GreenWebBrowsingAgent + type: probabilistic_agent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index 5d004c7e..8a4a1178 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -25,7 +25,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: GreenWebBrowsingAgent + type: probabilistic_agent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/conftest.py b/tests/conftest.py index 5084c339..2add835f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK from pathlib import Path -from typing import Any, Dict, Tuple, Union +from typing import Any, Dict, Optional, Tuple, Union import pytest import yaml @@ -309,7 +309,7 @@ class ControlledAgent(AbstractAgent): ) self.most_recent_action: Tuple[str, Dict] - def get_action(self, obs: None, reward: float = 0.0) -> Tuple[str, Dict]: + def get_action(self, obs: None, reward: float = 0.0, timestep: Optional[int] = None) -> Tuple[str, Dict]: """Return the agent's most recent action, formatted in CAOS format.""" return self.most_recent_action @@ -478,7 +478,6 @@ def game_and_agent(): ] action_space = ActionManager( - game=game, actions=actions, # ALL POSSIBLE ACTIONS nodes=[ { diff --git a/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py b/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py new file mode 100644 index 00000000..f0b37cac --- /dev/null +++ b/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py @@ -0,0 +1,84 @@ +from primaite.game.agent.actions import ActionManager +from primaite.game.agent.observations import ICSObservation, ObservationManager +from primaite.game.agent.rewards import RewardFunction +from primaite.game.agent.scripted_agents import ProbabilisticAgent + + +def test_probabilistic_agent(): + """ + Check that the probabilistic agent selects actions with approximately the right probabilities. + + Using a binomial probability calculator (https://www.wolframalpha.com/input/?i=binomial+distribution+calculator), + we can generate some lower and upper bounds of how many times we expect the agent to take each action. These values + were chosen to guarantee a less than 1 in a million chance of the test failing due to unlucky random number + generation. + """ + N_TRIALS = 10_000 + P_DO_NOTHING = 0.1 + P_NODE_APPLICATION_EXECUTE = 0.3 + P_NODE_FILE_DELETE = 0.6 + MIN_DO_NOTHING = 850 + MAX_DO_NOTHING = 1150 + MIN_NODE_APPLICATION_EXECUTE = 2800 + MAX_NODE_APPLICATION_EXECUTE = 3200 + MIN_NODE_FILE_DELETE = 5750 + MAX_NODE_FILE_DELETE = 6250 + + action_space = ActionManager( + actions=[ + {"type": "DONOTHING"}, + {"type": "NODE_APPLICATION_EXECUTE"}, + {"type": "NODE_FILE_DELETE"}, + ], + nodes=[ + { + "node_name": "client_1", + "applications": [{"application_name": "WebBrowser"}], + "folders": [{"folder_name": "downloads", "files": [{"file_name": "cat.png"}]}], + }, + ], + max_folders_per_node=2, + max_files_per_folder=2, + max_services_per_node=2, + max_applications_per_node=2, + max_nics_per_node=2, + max_acl_rules=10, + protocols=["TCP", "UDP", "ICMP"], + ports=["HTTP", "DNS", "ARP"], + act_map={ + 0: {"action": "DONOTHING", "options": {}}, + 1: {"action": "NODE_APPLICATION_EXECUTE", "options": {"node_id": 0, "application_id": 0}}, + 2: {"action": "NODE_FILE_DELETE", "options": {"node_id": 0, "folder_id": 0, "file_id": 0}}, + }, + ) + observation_space = ObservationManager(ICSObservation()) + reward_function = RewardFunction() + + pa = ProbabilisticAgent( + agent_name="test_agent", + action_space=action_space, + observation_space=observation_space, + reward_function=reward_function, + settings={ + "action_probabilities": {0: P_DO_NOTHING, 1: P_NODE_APPLICATION_EXECUTE, 2: P_NODE_FILE_DELETE}, + "random_seed": 120, + }, + ) + + do_nothing_count = 0 + node_application_execute_count = 0 + node_file_delete_count = 0 + for _ in range(N_TRIALS): + a = pa.get_action(0, timestep=0) + if a == ("DONOTHING", {}): + do_nothing_count += 1 + elif a == ("NODE_APPLICATION_EXECUTE", {"node_id": 0, "application_id": 0}): + node_application_execute_count += 1 + elif a == ("NODE_FILE_DELETE", {"node_id": 0, "folder_id": 0, "file_id": 0}): + node_file_delete_count += 1 + else: + raise AssertionError("Probabilistic agent produced an unexpected action.") + + assert MIN_DO_NOTHING < do_nothing_count < MAX_DO_NOTHING + assert MIN_NODE_APPLICATION_EXECUTE < node_application_execute_count < MAX_NODE_APPLICATION_EXECUTE + assert MIN_NODE_FILE_DELETE < node_file_delete_count < MAX_NODE_FILE_DELETE From d55b6a5b48bf0faa6aeed6bd5ee94c65ab90912b Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 28 Feb 2024 12:03:58 +0000 Subject: [PATCH 641/980] #2238 - Fixed the observations issue causing tests to fail --- src/primaite/game/agent/observations.py | 7 +++++-- src/primaite/simulator/network/hardware/base.py | 2 ++ .../simulator/network/hardware/nodes/host/host_node.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 7ccc3f11..82e11fe0 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -351,6 +351,8 @@ class NicObservation(AbstractObservation): def default_observation(self) -> Dict: """The default NIC observation dict.""" data = {"nic_status": 0} + if CAPTURE_NMNE: + data.update({"nmne": {"inbound": 0, "outbound": 0}}) return data @@ -404,8 +406,9 @@ class NicObservation(AbstractObservation): if nic_state is NOT_PRESENT_IN_STATE: return self.default_observation else: - obs_dict = {"nic_status": 1 if nic_state["enabled"] else 2, "nmne": {}} - if CAPTURE_NMNE and nic_state.get("nmne"): + obs_dict = {"nic_status": 1 if nic_state["enabled"] else 2} + if CAPTURE_NMNE: + obs_dict.update({"nmne": {}}) direction_dict = nic_state["nmne"].get("direction", {}) inbound_keywords = direction_dict.get("inbound", {}).get("keywords", {}) inbound_count = inbound_keywords.get("*", 0) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index b22bea25..35c90d05 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -123,6 +123,8 @@ class NetworkInterface(SimComponent, ABC): "enabled": self.enabled, } ) + if CAPTURE_NMNE: + state.update({"nmne": self.nmne}) return state def reset_component_for_episode(self, episode: int): diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index 8e104924..b48950b7 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -205,7 +205,7 @@ class NIC(IPWiredNetworkInterface): state = super().describe_state() # Update the state with NIC-specific information - state.update({"wake_on_lan": self.wake_on_lan, "nmne": self.nmne}) + state.update({"wake_on_lan": self.wake_on_lan}) return state From 63ea5478ab4fc39ffde3359983c332098fd318b6 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 28 Feb 2024 13:56:19 +0000 Subject: [PATCH 642/980] #2238 - Updated uc2_demo.ipynb to explain the NMNE in observation space --- src/primaite/notebooks/uc2_demo.ipynb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index c4fe4c9a..b1e12370 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -130,6 +130,9 @@ " - NETWORK_INTERFACES\n", " - \n", " - nic_status\n", + " - nmne\n", + " - inbound\n", + " - outbound\n", " - operating_status\n", "- LINKS\n", " - \n", @@ -220,6 +223,14 @@ "|1|ENABLED|\n", "|2|DISABLED|\n", "\n", + "NMNE (number of malicious network events) means, for inbound or outbound traffic, means:\n", + "|value|NMNEs|\n", + "|--|--|\n", + "|0|None|\n", + "|1|1 - 5|\n", + "|2|6 - 10|\n", + "|3|More than 10|\n", + "\n", "Link load has the following meaning:\n", "|load|percent utilisation|\n", "|--|--|\n", From 6d43c61058f4d342b2ed1f62bf601cb9bd824729 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 28 Feb 2024 15:08:00 +0000 Subject: [PATCH 643/980] #2257: apply PR suggestions --- .../common/common_host_node_attributes.rst | 2 +- .../simulation/nodes/firewall.rst | 38 ++++++++++++++++++- .../applications/data_manipulation_bot.rst | 4 +- .../system/list_of_applications.rst | 4 ++ .../system/list_of_services.rst | 4 ++ .../system/services/database_service.rst | 2 +- .../system/services/ftp_client.rst | 3 +- .../system/services/ftp_server.rst | 3 +- src/primaite/game/agent/rewards.py | 6 +-- .../hardware/nodes/network/firewall.py | 38 +++++++++---------- .../network/hardware/nodes/network/router.py | 12 +++--- 11 files changed, 81 insertions(+), 35 deletions(-) diff --git a/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst b/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst index a95f98d4..b9f173c6 100644 --- a/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst +++ b/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst @@ -24,7 +24,7 @@ The IP address that the |NODE| will use as the default gateway. Typically, this Optional. Default value is ``None`` -The IP address of the node which holds an instance of the DNS server. Some applications may use a domain name e.g. the WebBrowser (TODO: WebBrowser page) +The IP address of the node which holds an instance of the :ref:`DNSServer`. Some applications may use a domain name e.g. the :ref:`WebBrowser` .. include:: ../software/applications.rst diff --git a/docs/source/configuration/simulation/nodes/firewall.rst b/docs/source/configuration/simulation/nodes/firewall.rst index 3c1fce0a..47db4001 100644 --- a/docs/source/configuration/simulation/nodes/firewall.rst +++ b/docs/source/configuration/simulation/nodes/firewall.rst @@ -7,7 +7,7 @@ ``firewall`` ============ -A basic representation of a network router within the simulation. +A basic representation of a network firewall within the simulation. The firewall is similar to how :ref:`Router ` works, with the difference being how firewall has specific ACL rules for inbound and outbound traffic as well as firewall being limited to 3 ports. @@ -133,6 +133,10 @@ example: ... acl: internal_inbound_acl: + 21: # position 21 on ACL list + action: PERMIT # allow packets that + src_port: POSTGRES_SERVER # are emitted from the POSTGRES_SERVER port + dst_port: POSTGRES_SERVER # are going towards an POSTGRES_SERVER port 22: # position 22 on ACL list action: PERMIT # allow packets that src_port: ARP # are emitted from the ARP port @@ -155,6 +159,10 @@ example: ... acl: internal_outbound_acl: + 21: # position 21 on ACL list + action: PERMIT # allow packets that + src_port: POSTGRES_SERVER # are emitted from the POSTGRES_SERVER port + dst_port: POSTGRES_SERVER # are going towards an POSTGRES_SERVER port 22: # position 22 on ACL list action: PERMIT # allow packets that src_port: ARP # are emitted from the ARP port @@ -178,6 +186,18 @@ example: ... acl: dmz_inbound_acl: + 19: # position 19 on ACL list + action: PERMIT # allow packets that + src_port: POSTGRES_SERVER # are emitted from the POSTGRES_SERVER port + dst_port: POSTGRES_SERVER # are going towards an POSTGRES_SERVER port + 20: # position 20 on ACL list + action: PERMIT # allow packets that + src_port: HTTP # are emitted from the HTTP port + dst_port: HTTP # are going towards an HTTP port + 21: # position 21 on ACL list + action: PERMIT # allow packets that + src_port: HTTPS # are emitted from the HTTPS port + dst_port: HTTPS # are going towards an HTTPS port 22: # position 22 on ACL list action: PERMIT # allow packets that src_port: ARP # are emitted from the ARP port @@ -200,6 +220,18 @@ example: ... acl: dmz_outbound_acl: + 19: # position 19 on ACL list + action: PERMIT # allow packets that + src_port: POSTGRES_SERVER # are emitted from the POSTGRES_SERVER port + dst_port: POSTGRES_SERVER # are going towards an POSTGRES_SERVER port + 20: # position 20 on ACL list + action: PERMIT # allow packets that + src_port: HTTP # are emitted from the HTTP port + dst_port: HTTP # are going towards an HTTP port + 21: # position 21 on ACL list + action: PERMIT # allow packets that + src_port: HTTPS # are emitted from the HTTPS port + dst_port: HTTPS # are going towards an HTTPS port 22: # position 22 on ACL list action: PERMIT # allow packets that src_port: ARP # are emitted from the ARP port @@ -226,6 +258,10 @@ example: ... acl: external_inbound_acl: + 21: # position 19 on ACL list + action: DENY # deny packets that + src_port: POSTGRES_SERVER # are emitted from the POSTGRES_SERVER port + dst_port: POSTGRES_SERVER # are going towards an POSTGRES_SERVER port 22: # position 22 on ACL list action: PERMIT # allow packets that src_port: ARP # are emitted from the ARP port diff --git a/docs/source/simulation_components/system/applications/data_manipulation_bot.rst b/docs/source/simulation_components/system/applications/data_manipulation_bot.rst index d0e89f2e..d67e82d4 100644 --- a/docs/source/simulation_components/system/applications/data_manipulation_bot.rst +++ b/docs/source/simulation_components/system/applications/data_manipulation_bot.rst @@ -99,7 +99,7 @@ If not using the data manipulation bot manually, it needs to be used with a data type: UC2RedObservation options: nodes: - - node_ref: client_1 + - node_name: client_1 observations: - logon_status - operating_status @@ -116,7 +116,7 @@ If not using the data manipulation bot manually, it needs to be used with a data - type: NODE_APPLICATION_EXECUTE options: nodes: - - node_ref: client_1 + - node_name: client_1 applications: - application_ref: data_manipulation_bot max_folders_per_node: 1 diff --git a/docs/source/simulation_components/system/list_of_applications.rst b/docs/source/simulation_components/system/list_of_applications.rst index 0ba0c45c..8f792e4c 100644 --- a/docs/source/simulation_components/system/list_of_applications.rst +++ b/docs/source/simulation_components/system/list_of_applications.rst @@ -1,3 +1,7 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + .. toctree:: :maxdepth: 1 :glob: diff --git a/docs/source/simulation_components/system/list_of_services.rst b/docs/source/simulation_components/system/list_of_services.rst index e24b26dc..9f1c9fe2 100644 --- a/docs/source/simulation_components/system/list_of_services.rst +++ b/docs/source/simulation_components/system/list_of_services.rst @@ -1,3 +1,7 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + .. toctree:: :maxdepth: 1 :glob: diff --git a/docs/source/simulation_components/system/services/database_service.rst b/docs/source/simulation_components/system/services/database_service.rst index 30d6b3ba..2c962c0a 100644 --- a/docs/source/simulation_components/system/services/database_service.rst +++ b/docs/source/simulation_components/system/services/database_service.rst @@ -12,7 +12,7 @@ The ``DatabaseService`` provides a SQL database server simulation by extending t Key capabilities ================ -- Creates a database file in the ``Node`` 's ``FileSystem`` upon creation. +- Creates a database file in the ``FileSystem`` of the ``Node`` (which the ``DatabaseService`` is installed on) upon creation. - Handles connecting clients by maintaining a dictionary of connections mapped to session IDs. - Authenticates connections using a configurable password. - Simulates ``SELECT``, ``DELETE`` and ``INSERT`` SQL queries. diff --git a/docs/source/simulation_components/system/services/ftp_client.rst b/docs/source/simulation_components/system/services/ftp_client.rst index 82b85770..604ef8e8 100644 --- a/docs/source/simulation_components/system/services/ftp_client.rst +++ b/docs/source/simulation_components/system/services/ftp_client.rst @@ -20,6 +20,7 @@ Key features - RETR: retrieves a file from the FTP server - QUIT: disconnect from server - Leverages the Service base class for install/uninstall, status tracking, etc. +- :ref:`FTPClient` and ``FTPServer`` utilise port 21 (FTP) throughout all file transfer / request Usage ===== @@ -52,7 +53,7 @@ Python hostname="server", ip_address="192.168.2.2", subnet_mask="255.255.255.0", - default_gateway="192.168.1.1Ó", + default_gateway="192.168.1.10", start_up_duration=0, ) server.power_on() diff --git a/docs/source/simulation_components/system/services/ftp_server.rst b/docs/source/simulation_components/system/services/ftp_server.rst index d807a14f..fb57a762 100644 --- a/docs/source/simulation_components/system/services/ftp_server.rst +++ b/docs/source/simulation_components/system/services/ftp_server.rst @@ -17,12 +17,13 @@ Key capabilities - STOR: stores a file from client to server - RETR: retrieves a file from the FTP server - Leverages the Service base class for install/uninstall, status tracking, etc. +- :ref:`FTPClient` and ``FTPServer`` utilise port 21 (FTP) throughout all file transfer / request Usage ===== - Install on a Node via the ``SoftwareManager`` to start the FTP server service. -- Service runs on FTP (command) port 21 by default. (TODO: look at in depth implementation of FTP PORT command) +- Service runs on FTP (command) port 21 by default Implementation ============== diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 27c39b65..ba6d1fa3 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -13,7 +13,7 @@ the structure: - type: DATABASE_FILE_INTEGRITY weight: 0.5 options: - node_ref: database_server + node_name: database_server folder_name: database file_name: database.db @@ -21,7 +21,7 @@ the structure: - type: WEB_SERVER_404_PENALTY weight: 0.5 options: - node_ref: web_server + node_name: web_server service_ref: web_server_database_client ``` """ @@ -184,7 +184,7 @@ class WebServer404Penalty(AbstractReward): service_name = config.get("service_name") if not (node_hostname and service_name): msg = ( - f"{cls.__name__} could not be initialised from config because node_ref and service_ref were not " + f"{cls.__name__} could not be initialised from config because node_name and service_ref were not " "found in reward config." ) _LOGGER.warning(msg) diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index 903ce3f3..ce98cec4 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -497,66 +497,66 @@ class Firewall(Router): @classmethod def from_config(cls, cfg: dict) -> "Firewall": """Create a firewall based on a config dict.""" - new = Firewall(hostname=cfg["hostname"], operating_state=NodeOperatingState.ON) + firewall = Firewall(hostname=cfg["hostname"], operating_state=NodeOperatingState.ON) if "ports" in cfg: internal_port = cfg["ports"]["internal_port"] external_port = cfg["ports"]["external_port"] dmz_port = cfg["ports"]["dmz_port"] # configure internal port - new.configure_internal_port( + firewall.configure_internal_port( ip_address=IPV4Address(internal_port.get("ip_address")), subnet_mask=IPV4Address(internal_port.get("subnet_mask", "255.255.255.0")), ) # configure external port - new.configure_external_port( + firewall.configure_external_port( ip_address=IPV4Address(external_port.get("ip_address")), subnet_mask=IPV4Address(external_port.get("subnet_mask", "255.255.255.0")), ) # configure dmz port - new.configure_dmz_port( + firewall.configure_dmz_port( ip_address=IPV4Address(dmz_port.get("ip_address")), subnet_mask=IPV4Address(dmz_port.get("subnet_mask", "255.255.255.0")), ) if "acl" in cfg: # acl rules for internal_inbound_acl if cfg["acl"]["internal_inbound_acl"]: - new.internal_inbound_acl.max_acl_rules - new.internal_inbound_acl._default_config = cfg["acl"]["internal_inbound_acl"] - new.internal_inbound_acl._reset_rules_to_default() + firewall.internal_inbound_acl.max_acl_rules + firewall.internal_inbound_acl._default_config = cfg["acl"]["internal_inbound_acl"] + firewall.internal_inbound_acl._reset_rules_to_default() # acl rules for internal_outbound_acl if cfg["acl"]["internal_outbound_acl"]: - new.internal_outbound_acl._default_config = cfg["acl"]["internal_outbound_acl"] - new.internal_outbound_acl._reset_rules_to_default() + firewall.internal_outbound_acl._default_config = cfg["acl"]["internal_outbound_acl"] + firewall.internal_outbound_acl._reset_rules_to_default() # acl rules for dmz_inbound_acl if cfg["acl"]["dmz_inbound_acl"]: - new.dmz_inbound_acl._default_config = cfg["acl"]["dmz_inbound_acl"] - new.dmz_inbound_acl._reset_rules_to_default() + firewall.dmz_inbound_acl._default_config = cfg["acl"]["dmz_inbound_acl"] + firewall.dmz_inbound_acl._reset_rules_to_default() # acl rules for dmz_outbound_acl if cfg["acl"]["dmz_outbound_acl"]: - new.dmz_outbound_acl._default_config = cfg["acl"]["dmz_outbound_acl"] - new.dmz_outbound_acl._reset_rules_to_default() + firewall.dmz_outbound_acl._default_config = cfg["acl"]["dmz_outbound_acl"] + firewall.dmz_outbound_acl._reset_rules_to_default() # acl rules for external_inbound_acl if cfg["acl"]["external_inbound_acl"]: - new.external_inbound_acl._default_config = cfg["acl"]["external_inbound_acl"] - new.external_inbound_acl._reset_rules_to_default() + firewall.external_inbound_acl._default_config = cfg["acl"]["external_inbound_acl"] + firewall.external_inbound_acl._reset_rules_to_default() # acl rules for external_outbound_acl if cfg["acl"]["external_outbound_acl"]: - new.external_outbound_acl._default_config = cfg["acl"]["external_outbound_acl"] - new.external_outbound_acl._reset_rules_to_default() + firewall.external_outbound_acl._default_config = cfg["acl"]["external_outbound_acl"] + firewall.external_outbound_acl._reset_rules_to_default() if "routes" in cfg: for route in cfg.get("routes"): - new.route_table.add_route( + firewall.route_table.add_route( address=IPv4Address(route.get("address")), subnet_mask=IPv4Address(route.get("subnet_mask", "255.255.255.0")), next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")), metric=float(route.get("metric", 0)), ) - return new + return firewall diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index b3d7f7bf..a9e12401 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1480,27 +1480,27 @@ class Router(NetworkNode): :return: Configured router. :rtype: Router """ - new = Router( + router = Router( hostname=cfg["hostname"], num_ports=int(cfg.get("num_ports", "5")), operating_state=NodeOperatingState.ON, ) if "ports" in cfg: for port_num, port_cfg in cfg["ports"].items(): - new.configure_port( + router.configure_port( port=port_num, ip_address=port_cfg["ip_address"], subnet_mask=IPv4Address(port_cfg.get("subnet_mask", "255.255.255.0")), ) if "acl" in cfg: - new.acl._default_config = cfg["acl"] # save the config to allow resetting - new.acl._reset_rules_to_default() # read the config and apply rules + router.acl._default_config = cfg["acl"] # save the config to allow resetting + router.acl._reset_rules_to_default() # read the config and apply rules if "routes" in cfg: for route in cfg.get("routes"): - new.route_table.add_route( + router.route_table.add_route( address=IPv4Address(route.get("address")), subnet_mask=IPv4Address(route.get("subnet_mask", "255.255.255.0")), next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")), metric=float(route.get("metric", 0)), ) - return new + return router From 8730330f73bf5b38ade30bfc18c23ee3c5523367 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 29 Feb 2024 10:14:31 +0000 Subject: [PATCH 644/980] Apply PR suggestions --- src/primaite/config/_package_data/example_config.yaml | 2 +- .../_package_data/example_config_2_rl_agents.yaml | 2 +- src/primaite/game/game.py | 10 ++++++---- .../simulator/network/hardware/nodes/network/router.py | 1 - .../simulator/system/services/web_server/web_server.py | 2 +- .../environments/test_sb3_environment.py | 1 - 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index a32696c7..ebee4980 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -14,7 +14,7 @@ io_settings: save_checkpoints: true checkpoint_interval: 5 save_step_metadata: false - save_pcap_logs: true + save_pcap_logs: false save_sys_logs: true diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index c1e077be..992c3a1a 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -16,7 +16,7 @@ io_settings: save_checkpoints: true checkpoint_interval: 5 save_step_metadata: false - save_pcap_logs: true + save_pcap_logs: false save_sys_logs: true diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 8edf70ea..baa84d1d 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -133,7 +133,7 @@ class PrimaiteGame: self.update_agents(sim_state) # Apply all actions to simulation as requests - agent_actions = self.apply_agent_actions() # noqa + self.apply_agent_actions() # Advance timestep self.advance_timestep() @@ -144,7 +144,7 @@ class PrimaiteGame: def update_agents(self, state: Dict) -> None: """Update agents' observations and rewards based on the current state.""" - for name, agent in self.agents.items(): + for _, agent in self.agents.items(): agent.update_observation(state) agent.update_reward(state) agent.reward_function.total_reward += agent.reward_function.current_reward @@ -158,7 +158,7 @@ class PrimaiteGame: """ agent_actions = {} - for name, agent in self.agents.items(): + for _, agent in self.agents.items(): obs = agent.observation_manager.current_observation rew = agent.reward_function.current_reward action_choice, options = agent.get_action(obs, rew) @@ -414,7 +414,9 @@ class PrimaiteGame: agent_settings=agent_settings, ) else: - _LOGGER.warning(f"agent type {agent_type} not found") + msg(f"Configuration error: {agent_type} is not a valid agent type.") + _LOGGER.error(msg) + raise ValueError(msg) game.agents[agent_cfg["ref"]] = new_agent return game diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 52f38eb6..aa6eec3a 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1076,7 +1076,6 @@ class Router(NetworkNode): :param episode: The episode number for which the router is being reset. """ self.software_manager.arp.clear() - # self.acl.reset_component_for_episode(episode) for i, _ in self.network_interface.items(): self.enable_port(i) diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index ce29a2f9..5e7591e9 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -118,7 +118,7 @@ class WebServer(Service): self.set_health_state(SoftwareHealthState.COMPROMISED) return response - except Exception: # TODO: refactor this. Likely to cause silent bugs. + except Exception: # TODO: refactor this. Likely to cause silent bugs. (ADO ticket #2345 ) # something went wrong on the server response.status_code = HttpStatusCode.INTERNAL_SERVER_ERROR return response diff --git a/tests/e2e_integration_tests/environments/test_sb3_environment.py b/tests/e2e_integration_tests/environments/test_sb3_environment.py index dc5d10e9..c48ddbc9 100644 --- a/tests/e2e_integration_tests/environments/test_sb3_environment.py +++ b/tests/e2e_integration_tests/environments/test_sb3_environment.py @@ -11,7 +11,6 @@ from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteGymEnv -# @pytest.mark.skip(reason="no way of currently testing this") def test_sb3_compatibility(): """Test that the Gymnasium environment can be used with an SB3 agent.""" with open(example_config_path(), "r") as f: From 9a4587155b4c3eab5b50f272a1d214fe9e7ed878 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 29 Feb 2024 11:07:21 +0000 Subject: [PATCH 645/980] #2257: specifically stating that enpoint refs are node hostnames + remove TODO --- docs/source/configuration/simulation.rst | 4 ++-- .../simulation_components/system/services/ftp_client.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/configuration/simulation.rst b/docs/source/configuration/simulation.rst index 89c1669b..e2fa5476 100644 --- a/docs/source/configuration/simulation.rst +++ b/docs/source/configuration/simulation.rst @@ -73,7 +73,7 @@ The human readable name for the link. Not used in code, however is useful for a ``endpoint_a_ref`` ^^^^^^^^^^^^^^^^^^ -The name of the node which must be connected. +The ``hostname`` of the node which must be connected. ``endpoint_a_port`` ^^^^^^^^^^^^^^^^^^^ @@ -84,7 +84,7 @@ This accepts an integer value e.g. if port 1 is to be connected, the configurati ``endpoint_b_ref`` ^^^^^^^^^^^^^^^^^^ -The name of the node which must be connected. +The ``hostname`` of the node which must be connected. ``endpoint_b_port`` ^^^^^^^^^^^^^^^^^^^ diff --git a/docs/source/simulation_components/system/services/ftp_client.rst b/docs/source/simulation_components/system/services/ftp_client.rst index 604ef8e8..259a626d 100644 --- a/docs/source/simulation_components/system/services/ftp_client.rst +++ b/docs/source/simulation_components/system/services/ftp_client.rst @@ -26,7 +26,7 @@ Usage ===== - Install on a Node via the ``SoftwareManager`` to start the FTP client service. -- Service runs on FTP (command) port 21 by default. (TODO: look at in depth implementation of FTP PORT command) +- Service runs on FTP (command) port 21 by default - Execute sending a file to the FTP server with ``send_file`` - Execute retrieving a file from the FTP server with ``request_file`` From cf0674ce22198a3519023f6077ccbc1f98133b2f Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 29 Feb 2024 13:00:27 +0000 Subject: [PATCH 646/980] #2326 - Network Interface port name/num fixed so that it carries through to sys log and PCAP outputs. --- CHANGELOG.md | 2 +- src/primaite/simulator/network/airspace.py | 4 +++- .../simulator/network/hardware/base.py | 15 ++++++++++---- .../wireless/wireless_access_point.py | 2 +- .../wireless/wireless_nic.py | 2 +- .../network/hardware/nodes/host/host_node.py | 2 +- .../hardware/nodes/network/firewall.py | 12 ++++++++++- .../network/hardware/nodes/network/router.py | 2 +- .../hardware/nodes/network/wireless_router.py | 5 ++++- .../simulator/system/core/packet_capture.py | 20 +++++++++++++++---- 10 files changed, 50 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcff5934..55202de4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -107,7 +107,7 @@ SessionManager. ### Fixed - Addressed network transmission issues that previously allowed ARP requests to be incorrectly routed and repeated across different subnets. This fix ensures ARP requests are correctly managed and confined to their appropriate network segments. - Resolved problems in `Node` and its subclasses where the default gateway configuration was not properly utilized for communications across different subnets. This correction ensures that nodes effectively use their configured default gateways for outbound communications to other network segments, thereby enhancing the network's routing functionality and reliability. - +- Network Interface Port name/num being set properly for sys log and PCAP output. ## [2.0.0] - 2023-07-26 diff --git a/src/primaite/simulator/network/airspace.py b/src/primaite/simulator/network/airspace.py index d264f751..5ceedc8e 100644 --- a/src/primaite/simulator/network/airspace.py +++ b/src/primaite/simulator/network/airspace.py @@ -168,7 +168,9 @@ class WirelessNetworkInterface(NetworkInterface, ABC): self.enabled = True self._connected_node.sys_log.info(f"Network Interface {self} enabled") - self.pcap = PacketCapture(hostname=self._connected_node.hostname, interface_num=self.port_num) + self.pcap = PacketCapture( + hostname=self._connected_node.hostname, port_num=self.port_num, port_name=self.port_name + ) AIR_SPACE.add_wireless_interface(self) def disable(self): diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index ff79f314..991913dd 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -94,6 +94,9 @@ class NetworkInterface(SimComponent, ABC): port_num: Optional[int] = None "The port number assigned to this interface on the connected node." + port_name: Optional[str] = None + "The port name assigned to this interface on the connected node." + pcap: Optional[PacketCapture] = None "A PacketCapture instance for capturing and analysing packets passing through this interface." @@ -248,7 +251,7 @@ class NetworkInterface(SimComponent, ABC): :return: A string combining the port number and the mac address """ - return f"Port {self.port_num}: {self.mac_address}" + return f"Port {self.port_name if self.port_name else self.port_num}: {self.mac_address}" class WiredNetworkInterface(NetworkInterface, ABC): @@ -293,7 +296,9 @@ class WiredNetworkInterface(NetworkInterface, ABC): self.enabled = True self._connected_node.sys_log.info(f"Network Interface {self} enabled") - self.pcap = PacketCapture(hostname=self._connected_node.hostname, interface_num=self.port_num) + self.pcap = PacketCapture( + hostname=self._connected_node.hostname, port_num=self.port_num, port_name=self.port_name + ) if self._connected_link: self._connected_link.endpoint_up() @@ -1024,7 +1029,7 @@ class Node(SimComponent): self.sys_log.info("Resetting") self.power_off() - def connect_nic(self, network_interface: NetworkInterface): + def connect_nic(self, network_interface: NetworkInterface, port_name: Optional[str] = None): """ Connect a Network Interface to the node. @@ -1036,7 +1041,9 @@ class Node(SimComponent): new_nic_num = len(self.network_interfaces) self.network_interface[new_nic_num] = network_interface network_interface._connected_node = self - network_interface._port_num_on_node = new_nic_num + network_interface.port_num = new_nic_num + if port_name: + network_interface.port_name = port_name network_interface.parent = self self.sys_log.info(f"Connected Network Interface {network_interface}") if self.operating_state == NodeOperatingState.ON: diff --git a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py index bc24270e..721814f8 100644 --- a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py +++ b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py @@ -83,4 +83,4 @@ class WirelessAccessPoint(IPWirelessNetworkInterface): :return: A string combining the port number, MAC address and IP address of the NIC. """ - return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" + return f"Port {self.port_name if self.port_name else self.port_num}: {self.mac_address}/{self.ip_address}" diff --git a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py index 32acc08a..7b8f6f54 100644 --- a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py +++ b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py @@ -80,4 +80,4 @@ class WirelessNIC(IPWirelessNetworkInterface): :return: A string combining the port number, MAC address and IP address of the NIC. """ - return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" + return f"Port {self.port_name if self.port_name else self.port_num}: {self.mac_address}/{self.ip_address}" diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index 977380be..14a237a4 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -250,7 +250,7 @@ class NIC(IPWiredNetworkInterface): :return: A string combining the port number, MAC address and IP address of the NIC. """ - return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" + return f"Port {self.port_name if self.port_name else self.port_num}: {self.mac_address}/{self.ip_address}" class HostNode(Node): diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index f2305652..7912d5d6 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -85,7 +85,17 @@ class Firewall(Router): if not kwargs.get("sys_log"): kwargs["sys_log"] = SysLog(hostname) - super().__init__(hostname=hostname, num_ports=3, **kwargs) + super().__init__(hostname=hostname, num_ports=0, **kwargs) + + self.connect_nic( + RouterInterface(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0", port_name="external") + ) + self.connect_nic( + RouterInterface(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0", port_name="internal") + ) + self.connect_nic( + RouterInterface(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0", port_name="dmz") + ) # Initialise ACLs for internal and dmz interfaces with a default DENY policy self.internal_inbound_acl = AccessControlList( diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index aa6eec3a..b63fb43c 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -998,7 +998,7 @@ class RouterInterface(IPWiredNetworkInterface): :return: A string combining the port number, MAC address and IP address of the NIC. """ - return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" + return f"Port {self.port_name if self.port_name else self.port_num}: {self.mac_address}/{self.ip_address}" class Router(NetworkNode): diff --git a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py index 91833d6a..3e8d715f 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py @@ -80,7 +80,10 @@ class WirelessAccessPoint(IPWirelessNetworkInterface): :return: A string combining the port number, MAC address and IP address of the NIC. """ - return f"Port {self.port_num}: {self.mac_address}/{self.ip_address} ({self.frequency})" + return ( + f"Port {self.port_name if self.port_name else self.port_num}: " + f"{self.mac_address}/{self.ip_address} ({self.frequency})" + ) class WirelessRouter(Router): diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index fb8a1624..5419dde6 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -21,7 +21,13 @@ class PacketCapture: The PCAPs are logged to: //__pcap.log """ - def __init__(self, hostname: str, ip_address: Optional[str] = None, interface_num: Optional[int] = None): + def __init__( + self, + hostname: str, + ip_address: Optional[str] = None, + port_num: Optional[int] = None, + port_name: Optional[str] = None, + ): """ Initialize the PacketCapture process. @@ -32,9 +38,12 @@ class PacketCapture: "The hostname for which PCAP logs are being recorded." self.ip_address: str = ip_address "The IP address associated with the PCAP logs." - self.interface_num = interface_num + self.port_num = port_num "The interface num on the Node." + self.port_name = port_name + "The interface name on the Node." + self.inbound_logger = None self.outbound_logger = None @@ -42,6 +51,7 @@ class PacketCapture: self.setup_logger(outbound=False) self.setup_logger(outbound=True) + print(port_name) def setup_logger(self, outbound: bool = False): """Set up the logger configuration.""" @@ -79,10 +89,12 @@ class PacketCapture: def _get_logger_name(self, outbound: bool = False) -> str: """Get PCAP the logger name.""" + if self.port_name: + return f"{self.hostname}_{self.port_name}_{'outbound' if outbound else 'inbound'}_pcap" if self.ip_address: return f"{self.hostname}_{self.ip_address}_{'outbound' if outbound else 'inbound'}_pcap" - if self.interface_num: - return f"{self.hostname}_port-{self.interface_num}_{'outbound' if outbound else 'inbound'}_pcap" + if self.port_num: + return f"{self.hostname}_port-{self.port_num}_{'outbound' if outbound else 'inbound'}_pcap" return f"{self.hostname}_{'outbound' if outbound else 'inbound'}_pcap" def _get_log_path(self, outbound: bool = False) -> Path: From 2f3e40fb6b6abe943770119b109319bc0edb7266 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 29 Feb 2024 13:22:05 +0000 Subject: [PATCH 647/980] Fix issue around reset --- src/primaite/game/game.py | 2 +- src/primaite/session/environment.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index eeb0d007..3b9a21d4 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -417,7 +417,7 @@ class PrimaiteGame: agent_settings=agent_settings, ) else: - msg(f"Configuration error: {agent_type} is not a valid agent type.") + msg = f"Configuration error: {agent_type} is not a valid agent type." _LOGGER.error(msg) raise ValueError(msg) game.agents[agent_cfg["ref"]] = new_agent diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index f8dbab9d..d54503a3 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -1,3 +1,4 @@ +import copy import json from typing import Any, Dict, Optional, SupportsFloat, Tuple @@ -23,7 +24,7 @@ class PrimaiteGymEnv(gymnasium.Env): super().__init__() self.game_config: Dict = game_config """PrimaiteGame definition. This can be changed between episodes to enable curriculum learning.""" - self.game: PrimaiteGame = PrimaiteGame.from_config(self.game_config) + self.game: PrimaiteGame = PrimaiteGame.from_config(copy.deepcopy(self.game_config)) """Current game.""" self._agent_name = next(iter(self.game.rl_agents)) """Name of the RL agent. Since there should only be one RL agent we can just pull the first and only key.""" @@ -78,7 +79,7 @@ class PrimaiteGymEnv(gymnasium.Env): f"Resetting environment, episode {self.episode_counter}, " f"avg. reward: {self.agent.reward_function.total_reward}" ) - self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=self.game_config) + self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=copy.deepcopy(self.game_config)) self.game.setup_for_episode(episode=self.episode_counter) self.episode_counter += 1 state = self.game.get_sim_state() From bd0b2e003346482fb84a3ecac86c8100439382d2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 29 Feb 2024 13:22:41 +0000 Subject: [PATCH 648/980] Remove redundant notebook cells --- src/primaite/notebooks/uc2_demo.ipynb | 33 +++------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index cf973905..13fb7d80 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -345,7 +345,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "tags": [] }, @@ -357,7 +357,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "tags": [] }, @@ -412,7 +412,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -595,33 +595,6 @@ "env.reset()" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "net = env.game.simulation.network" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "dbc = net.get_node_by_hostname('client_1').software_manager.software.get('DatabaseClient')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "dbc._query_success_tracker" - ] - }, { "cell_type": "code", "execution_count": null, From 8f0de8521e087a580b8e3922a8114e418066b188 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 29 Feb 2024 14:08:42 +0000 Subject: [PATCH 649/980] #2326 - removed port_name print statement --- src/primaite/simulator/system/core/packet_capture.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index 5419dde6..4916966d 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -51,7 +51,6 @@ class PacketCapture: self.setup_logger(outbound=False) self.setup_logger(outbound=True) - print(port_name) def setup_logger(self, outbound: bool = False): """Set up the logger configuration.""" From 49a4e1fb5655f83d2d13437927bff71148d30c57 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 29 Feb 2024 15:20:54 +0000 Subject: [PATCH 650/980] #2257: added common node attributes page + ability to set node operating state via config + tests --- .../simulation/nodes/common/common.rst | 35 ++++++++ .../common/common_host_node_attributes.rst | 9 +- .../common/common_network_node_attributes.rst | 2 + .../nodes/common/common_node_attributes.rst | 42 ++++++++++ .../network/base_hardware.rst | 22 ++--- .../applications/data_manipulation_bot.rst | 2 +- .../system/applications/database_client.rst | 6 -- .../system/list_of_system_applications.rst | 2 +- .../system/list_of_system_services.rst | 2 +- .../simulation_components/system/software.rst | 2 +- src/primaite/game/game.py | 16 +++- src/primaite/simulator/core.py | 4 +- .../network/hardware/nodes/host/host_node.py | 25 +++--- .../hardware/nodes/network/firewall.py | 83 +++++++++++++++---- .../network/hardware/nodes/network/router.py | 4 +- .../configs/basic_switched_network.yaml | 11 +++ .../nodes/test_node_config.py | 20 ++++- ...software_installation_and_configuration.py | 10 ++- 18 files changed, 227 insertions(+), 70 deletions(-) create mode 100644 docs/source/configuration/simulation/nodes/common/common.rst diff --git a/docs/source/configuration/simulation/nodes/common/common.rst b/docs/source/configuration/simulation/nodes/common/common.rst new file mode 100644 index 00000000..d1c8f307 --- /dev/null +++ b/docs/source/configuration/simulation/nodes/common/common.rst @@ -0,0 +1,35 @@ +.. only:: comment + + © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK + +.. _Node Attributes: + +Common Attributes +################# + +Node Attributes +=============== + +Attributes that are shared by all nodes. + +.. include:: common_node_attributes.rst + +.. _Network Node Attributes: + +Network Node Attributes +======================= + +Attributes that are shared by nodes that inherit from :py:mod:`primaite.simulator.network.hardware.nodes.network.network_node.NetworkNode` + +.. include:: common_host_node_attributes.rst + +.. _Host Node Attributes: + +Host Node Attributes +==================== + +Attributes that are shared by nodes that inherit from :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.HostNode` + +.. include:: common_host_node_attributes.rst + +.. |NODE| replace:: node diff --git a/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst b/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst index b9f173c6..929d5714 100644 --- a/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst +++ b/docs/source/configuration/simulation/nodes/common/common_host_node_attributes.rst @@ -2,6 +2,8 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _common_host_node_attributes: + ``ip_address`` -------------- @@ -19,13 +21,6 @@ The subnet mask for the |NODE| to use. The IP address that the |NODE| will use as the default gateway. Typically, this is the IP address of the closest router that the |NODE| is connected to. -``dns_server`` --------------- - -Optional. Default value is ``None`` - -The IP address of the node which holds an instance of the :ref:`DNSServer`. Some applications may use a domain name e.g. the :ref:`WebBrowser` - .. include:: ../software/applications.rst .. include:: ../software/services.rst diff --git a/docs/source/configuration/simulation/nodes/common/common_network_node_attributes.rst b/docs/source/configuration/simulation/nodes/common/common_network_node_attributes.rst index d0b3e65b..1161059f 100644 --- a/docs/source/configuration/simulation/nodes/common/common_network_node_attributes.rst +++ b/docs/source/configuration/simulation/nodes/common/common_network_node_attributes.rst @@ -2,6 +2,8 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _common_network_node_attributes: + ``routes`` ---------- diff --git a/docs/source/configuration/simulation/nodes/common/common_node_attributes.rst b/docs/source/configuration/simulation/nodes/common/common_node_attributes.rst index c1523518..34519adc 100644 --- a/docs/source/configuration/simulation/nodes/common/common_node_attributes.rst +++ b/docs/source/configuration/simulation/nodes/common/common_node_attributes.rst @@ -2,6 +2,8 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK +.. _common_node_attributes: + ``ref`` ------- @@ -11,3 +13,43 @@ Human readable name used as reference for the |NODE|. Not used in code. ------------ The hostname of the |NODE|. This will be used to reference the |NODE|. + +``operating_state`` +------------------- + +The initial operating state of the node. + +Optional. Default value is ``ON``. + +Options available are: + +- ``ON`` +- ``OFF`` +- ``BOOTING`` +- ``SHUTTING_DOWN`` + +Note that YAML may assume non quoted ``ON`` and ``OFF`` as ``True`` and ``False`` respectively. To prevent this, use ``"ON"`` or ``"OFF"`` + +See :py:mod:`primaite.simulator.network.hardware.node_operating_state.NodeOperatingState` + + +``dns_server`` +-------------- + +Optional. Default value is ``None``. + +The IP address of the node which holds an instance of the :ref:`DNSServer`. Some applications may use a domain name e.g. the :ref:`WebBrowser` + +``start_up_duration`` +--------------------- + +Optional. Default value is ``3``. + +The number of time steps required to occur in order for the node to cycle from ``OFF`` to ``BOOTING_UP`` and then finally ``ON``. + +``shut_down_duration`` +---------------------- + +Optional. Default value is ``3``. + +The number of time steps required to occur in order for the node to cycle from ``ON`` to ``SHUTTING_DOWN`` and then finally ``OFF``. diff --git a/docs/source/simulation_components/network/base_hardware.rst b/docs/source/simulation_components/network/base_hardware.rst index 3aa6b073..1b83f3f4 100644 --- a/docs/source/simulation_components/network/base_hardware.rst +++ b/docs/source/simulation_components/network/base_hardware.rst @@ -12,34 +12,22 @@ complex, specialized hardware components inherit from and build upon. The key elements defined in ``base.py`` are: -NetworkInterface -================ +``NetworkInterface`` +==================== - Abstract base class for network interfaces like NICs. Defines common attributes like MAC address, speed, MTU. - Requires subclasses to implement ``enable()``, ``disable()``, ``send_frame()`` and ``receive_frame()``. - Provides basic state description and request handling capabilities. -Node -==== +``Node`` +======== The Node class stands as a central component in ``base.py``, acting as the superclass for all network nodes within a PrimAITE simulation. - - Node Attributes --------------- - -- **hostname**: The network hostname of the node. -- **operating_state**: Indicates the current hardware state of the node. -- **network_interfaces**: Maps interface names to NetworkInterface objects on the node. -- **network_interface**: Maps port IDs to ``NetworkInterface`` objects on the node. -- **dns_server**: Specifies DNS servers for domain name resolution. -- **start_up_duration**: The time it takes for the node to become fully operational after being powered on. -- **shut_down_duration**: The time required for the node to properly shut down. -- **sys_log**: A system log for recording events related to the node. -- **session_manager**: Manages user sessions within the node. -- **software_manager**: Controls the installation and management of software and services on the node. +See :ref:`Node Attributes` .. _Node Start up and Shut down: diff --git a/docs/source/simulation_components/system/applications/data_manipulation_bot.rst b/docs/source/simulation_components/system/applications/data_manipulation_bot.rst index d67e82d4..304621dd 100644 --- a/docs/source/simulation_components/system/applications/data_manipulation_bot.rst +++ b/docs/source/simulation_components/system/applications/data_manipulation_bot.rst @@ -79,7 +79,7 @@ Python data_manipulation_bot.configure(server_ip_address=IPv4Address("192.168.1.14"), payload="DELETE") data_manipulation_bot.run() -This would connect to the database service at 192.168.1.14, authenticate, and execute the SQL statement to drop the 'users' table. +This would connect to the database service at 192.168.1.14, authenticate, and execute the SQL statement to delete database contents. Example with ``DataManipulationAgent`` """""""""""""""""""""""""""""""""""""" diff --git a/docs/source/simulation_components/system/applications/database_client.rst b/docs/source/simulation_components/system/applications/database_client.rst index 61d955f2..ddf6db11 100644 --- a/docs/source/simulation_components/system/applications/database_client.rst +++ b/docs/source/simulation_components/system/applications/database_client.rst @@ -24,12 +24,6 @@ Usage - Retrieve results in a dictionary. - Disconnect when finished. -To create database backups: - -- Configure the backup server on the :ref:`DatabaseService` by providing the Backup server ``IPv4Address`` with ``configure_backup`` -- Create a backup using ``backup_database``. This fails if the backup server is not configured. -- Restore a backup using ``restore_backup``. By default, this uses the database created via ``backup_database``. - Implementation ============== diff --git a/docs/source/simulation_components/system/list_of_system_applications.rst b/docs/source/simulation_components/system/list_of_system_applications.rst index fae0f5d4..193b3dc6 100644 --- a/docs/source/simulation_components/system/list_of_system_applications.rst +++ b/docs/source/simulation_components/system/list_of_system_applications.rst @@ -13,4 +13,4 @@ The list of applications that are considered system software are: - ``WebBrowser`` -More info :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.SYSTEM_SOFTWARE` +More info :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.HostNode.SYSTEM_SOFTWARE` diff --git a/docs/source/simulation_components/system/list_of_system_services.rst b/docs/source/simulation_components/system/list_of_system_services.rst index 4ff6f245..5acfc12e 100644 --- a/docs/source/simulation_components/system/list_of_system_services.rst +++ b/docs/source/simulation_components/system/list_of_system_services.rst @@ -15,4 +15,4 @@ The list of services that are considered system software are: - ``FTPClient`` - ``NTPClient`` -More info :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.SYSTEM_SOFTWARE` +More info :py:mod:`primaite.simulator.network.hardware.nodes.host.host_node.HostNode.SYSTEM_SOFTWARE` diff --git a/docs/source/simulation_components/system/software.rst b/docs/source/simulation_components/system/software.rst index 459064f0..2ba8e841 100644 --- a/docs/source/simulation_components/system/software.rst +++ b/docs/source/simulation_components/system/software.rst @@ -10,7 +10,7 @@ Software Base Software ------------- -All software which inherits ``IOSoftware`` installed on a node will not work unless the node has been turned on. +Software which inherits ``IOSoftware`` installed on a node will not work unless the node has been turned on. See :ref:`Node Start up and Shut down` diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 8d272418..42d998c7 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -234,7 +234,9 @@ class PrimaiteGame: subnet_mask=IPv4Address(node_cfg.get("subnet_mask", "255.255.255.0")), default_gateway=node_cfg["default_gateway"], dns_server=node_cfg.get("dns_server", None), - operating_state=NodeOperatingState.ON, + operating_state=NodeOperatingState.ON + if not (p := node_cfg.get("operating_state")) + else NodeOperatingState[p.upper()], ) elif n_type == "server": new_node = Server( @@ -243,13 +245,17 @@ class PrimaiteGame: subnet_mask=IPv4Address(node_cfg.get("subnet_mask", "255.255.255.0")), default_gateway=node_cfg["default_gateway"], dns_server=node_cfg.get("dns_server", None), - operating_state=NodeOperatingState.ON, + operating_state=NodeOperatingState.ON + if not (p := node_cfg.get("operating_state")) + else NodeOperatingState[p.upper()], ) elif n_type == "switch": new_node = Switch( hostname=node_cfg["hostname"], num_ports=int(node_cfg.get("num_ports", "8")), - operating_state=NodeOperatingState.ON, + operating_state=NodeOperatingState.ON + if not (p := node_cfg.get("operating_state")) + else NodeOperatingState[p.upper()], ) elif n_type == "router": new_node = Router.from_config(node_cfg) @@ -359,7 +365,9 @@ class PrimaiteGame: new_node.shut_down_duration = 0 net.add_node(new_node) - new_node.power_on() + # run through the power on step if the node is to be turned on at the start + if new_node.operating_state == NodeOperatingState.ON: + new_node.power_on() game.ref_map_nodes[node_ref] = new_node.uuid # set start up and shut down duration diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 99e9be7f..6ab7c6e3 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -1,7 +1,7 @@ # flake8: noqa """Core of the PrimAITE Simulator.""" -from abc import ABC, abstractmethod -from typing import Callable, ClassVar, Dict, List, Optional, Union +from abc import abstractmethod +from typing import Callable, Dict, List, Optional, Union from uuid import uuid4 from pydantic import BaseModel, ConfigDict, Field diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index cb3c1bd7..703c2538 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -1,7 +1,7 @@ from __future__ import annotations from ipaddress import IPv4Address -from typing import Any, Dict, Optional +from typing import Any, ClassVar, Dict, Optional from primaite import getLogger from primaite.simulator.network.hardware.base import IPWiredNetworkInterface, Link, Node @@ -253,17 +253,6 @@ class NIC(IPWiredNetworkInterface): return f"Port {self.port_num}: {self.mac_address}/{self.ip_address}" -SYSTEM_SOFTWARE = { - "HostARP": HostARP, - "ICMP": ICMP, - "DNSClient": DNSClient, - "FTPClient": FTPClient, - "NTPClient": NTPClient, - "WebBrowser": WebBrowser, -} -"""List of system software that is automatically installed on nodes.""" - - class HostNode(Node): """ Represents a host node in the network. @@ -308,6 +297,16 @@ class HostNode(Node): * Web Browser: Provides web browsing capabilities. """ + SYSTEM_SOFTWARE: ClassVar[Dict] = { + "HostARP": HostARP, + "ICMP": ICMP, + "DNSClient": DNSClient, + "FTPClient": FTPClient, + "NTPClient": NTPClient, + "WebBrowser": WebBrowser, + } + """List of system software that is automatically installed on nodes.""" + network_interfaces: Dict[str, NIC] = {} "The Network Interfaces on the node." network_interface: Dict[int, NIC] = {} @@ -324,7 +323,7 @@ class HostNode(Node): This method equips the host with essential network services and applications, preparing it for various network-related tasks and operations. """ - for _, software_class in SYSTEM_SOFTWARE.items(): + for _, software_class in self.SYSTEM_SOFTWARE.items(): self.software_manager.install(software_class) super()._install_system_software() diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index b4d5cdba..26c50ff0 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -12,6 +12,8 @@ from primaite.simulator.network.hardware.nodes.network.router import ( RouterInterface, ) from primaite.simulator.network.transmission.data_link_layer import Frame +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.sys_log import SysLog from primaite.utils.validators import IPV4Address @@ -479,7 +481,12 @@ class Firewall(Router): @classmethod def from_config(cls, cfg: dict) -> "Firewall": """Create a firewall based on a config dict.""" - firewall = Firewall(hostname=cfg["hostname"], operating_state=NodeOperatingState.ON) + firewall = Firewall( + hostname=cfg["hostname"], + operating_state=NodeOperatingState.ON + if not (p := cfg.get("operating_state")) + else NodeOperatingState[p.upper()], + ) if "ports" in cfg: internal_port = cfg["ports"]["internal_port"] external_port = cfg["ports"]["external_port"] @@ -505,34 +512,82 @@ class Firewall(Router): if "acl" in cfg: # acl rules for internal_inbound_acl if cfg["acl"]["internal_inbound_acl"]: - firewall.internal_inbound_acl.max_acl_rules - firewall.internal_inbound_acl._default_config = cfg["acl"]["internal_inbound_acl"] - firewall.internal_inbound_acl._reset_rules_to_default() + for r_num, r_cfg in cfg["acl"]["internal_inbound_acl"].items(): + firewall.internal_inbound_acl.add_rule( + action=ACLAction[r_cfg["action"]], + src_port=None if not (p := r_cfg.get("src_port")) else Port[p], + dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], + protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], + src_ip_address=r_cfg.get("src_ip"), + dst_ip_address=r_cfg.get("dst_ip"), + position=r_num, + ) # acl rules for internal_outbound_acl if cfg["acl"]["internal_outbound_acl"]: - firewall.internal_outbound_acl._default_config = cfg["acl"]["internal_outbound_acl"] - firewall.internal_outbound_acl._reset_rules_to_default() + for r_num, r_cfg in cfg["acl"]["internal_outbound_acl"].items(): + firewall.internal_outbound_acl.add_rule( + action=ACLAction[r_cfg["action"]], + src_port=None if not (p := r_cfg.get("src_port")) else Port[p], + dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], + protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], + src_ip_address=r_cfg.get("src_ip"), + dst_ip_address=r_cfg.get("dst_ip"), + position=r_num, + ) # acl rules for dmz_inbound_acl if cfg["acl"]["dmz_inbound_acl"]: - firewall.dmz_inbound_acl._default_config = cfg["acl"]["dmz_inbound_acl"] - firewall.dmz_inbound_acl._reset_rules_to_default() + for r_num, r_cfg in cfg["acl"]["dmz_inbound_acl"].items(): + firewall.dmz_inbound_acl.add_rule( + action=ACLAction[r_cfg["action"]], + src_port=None if not (p := r_cfg.get("src_port")) else Port[p], + dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], + protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], + src_ip_address=r_cfg.get("src_ip"), + dst_ip_address=r_cfg.get("dst_ip"), + position=r_num, + ) # acl rules for dmz_outbound_acl if cfg["acl"]["dmz_outbound_acl"]: - firewall.dmz_outbound_acl._default_config = cfg["acl"]["dmz_outbound_acl"] - firewall.dmz_outbound_acl._reset_rules_to_default() + for r_num, r_cfg in cfg["acl"]["dmz_outbound_acl"].items(): + firewall.dmz_outbound_acl.add_rule( + action=ACLAction[r_cfg["action"]], + src_port=None if not (p := r_cfg.get("src_port")) else Port[p], + dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], + protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], + src_ip_address=r_cfg.get("src_ip"), + dst_ip_address=r_cfg.get("dst_ip"), + position=r_num, + ) # acl rules for external_inbound_acl if cfg["acl"]["external_inbound_acl"]: - firewall.external_inbound_acl._default_config = cfg["acl"]["external_inbound_acl"] - firewall.external_inbound_acl._reset_rules_to_default() + for r_num, r_cfg in cfg["acl"]["external_inbound_acl"].items(): + firewall.external_inbound_acl.add_rule( + action=ACLAction[r_cfg["action"]], + src_port=None if not (p := r_cfg.get("src_port")) else Port[p], + dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], + protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], + src_ip_address=r_cfg.get("src_ip"), + dst_ip_address=r_cfg.get("dst_ip"), + position=r_num, + ) # acl rules for external_outbound_acl if cfg["acl"]["external_outbound_acl"]: - firewall.external_outbound_acl._default_config = cfg["acl"]["external_outbound_acl"] - firewall.external_outbound_acl._reset_rules_to_default() + for r_num, r_cfg in cfg["acl"]["external_outbound_acl"].items(): + firewall.external_outbound_acl.add_rule( + action=ACLAction[r_cfg["action"]], + src_port=None if not (p := r_cfg.get("src_port")) else Port[p], + dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], + protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], + src_ip_address=r_cfg.get("src_ip"), + dst_ip_address=r_cfg.get("dst_ip"), + position=r_num, + ) + if "routes" in cfg: for route in cfg.get("routes"): firewall.route_table.add_route( diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 5b45f59c..d5302345 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1401,7 +1401,9 @@ class Router(NetworkNode): router = Router( hostname=cfg["hostname"], num_ports=int(cfg.get("num_ports", "5")), - operating_state=NodeOperatingState.ON, + operating_state=NodeOperatingState.ON + if not (p := cfg.get("operating_state")) + else NodeOperatingState[p.upper()], ) if "ports" in cfg: for port_num, port_cfg in cfg["ports"].items(): diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index a248065c..daa40aa7 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -141,6 +141,17 @@ simulation: default_gateway: 192.168.10.1 dns_server: 192.168.1.10 # pre installed services and applications + - ref: client_3 + type: computer + hostname: client_3 + ip_address: 192.168.10.23 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + start_up_duration: 0 + shut_down_duration: 0 + operating_state: "OFF" + # pre installed services and applications links: - ref: switch_1___client_1 diff --git a/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py b/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py index e222bfaf..f23e7612 100644 --- a/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py +++ b/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py @@ -1,6 +1,8 @@ from primaite.config.load import example_config_path from primaite.simulator.network.container import Network -from tests.integration_tests.configuration_file_parsing import DMZ_NETWORK, load_config +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from tests.integration_tests.configuration_file_parsing import BASIC_CONFIG, DMZ_NETWORK, load_config def test_example_config(): @@ -24,3 +26,19 @@ def test_dmz_config(): assert len(network.routers) == 2 # 2 routers in network assert len(network.switches) == 3 # 3 switches in network assert len(network.servers) == 2 # 2 servers in network + + +def test_basic_config(): + """Test that the basic_switched_network config can be parsed properly.""" + game = load_config(BASIC_CONFIG) + network: Network = game.simulation.network + assert len(network.nodes) == 4 # 4 nodes in network + + client_1: Computer = network.get_node_by_hostname("client_1") + assert client_1.operating_state == NodeOperatingState.ON + client_2: Computer = network.get_node_by_hostname("client_2") + assert client_2.operating_state == NodeOperatingState.ON + + # client 3 should not be online + client_3: Computer = network.get_node_by_hostname("client_3") + assert client_3.operating_state == NodeOperatingState.OFF diff --git a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py index 306f591d..f3dc51bd 100644 --- a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py +++ b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py @@ -1,6 +1,14 @@ from ipaddress import IPv4Address +from pathlib import Path +from typing import Union -from primaite.game.game import APPLICATION_TYPES_MAPPING, SERVICE_TYPES_MAPPING +import yaml + +from primaite.config.load import example_config_path +from primaite.game.agent.data_manipulation_bot import DataManipulationAgent +from primaite.game.agent.interface import ProxyAgent, RandomAgent +from primaite.game.game import APPLICATION_TYPES_MAPPING, PrimaiteGame, SERVICE_TYPES_MAPPING +from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot From 10a40538876930afa371bac5c77691626917472b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 1 Mar 2024 15:14:00 +0000 Subject: [PATCH 651/980] Fix tests --- docs/source/configuration/agents.rst | 6 +++--- .../_package_data/example_config_2_rl_agents.yaml | 2 +- src/primaite/session/session.py | 9 +++------ tests/assets/configs/dmz_network.yaml | 2 +- tests/e2e_integration_tests/test_primaite_session.py | 10 +++++----- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/docs/source/configuration/agents.rst b/docs/source/configuration/agents.rst index f32843b1..ac67c365 100644 --- a/docs/source/configuration/agents.rst +++ b/docs/source/configuration/agents.rst @@ -19,7 +19,7 @@ Agents can be scripted (deterministic and stochastic), or controlled by a reinfo ... - ref: green_agent_example team: GREEN - type: GreenWebBrowsingAgent + type: probabilistic_agent observation_space: type: UC2GreenObservation action_space: @@ -57,11 +57,11 @@ Specifies if the agent is malicious (``RED``), benign (``GREEN``), or defensive ``type`` -------- -Specifies which class should be used for the agent. ``ProxyAgent`` is used for agents that receive instructions from an RL algorithm. Scripted agents like ``RedDatabaseCorruptingAgent`` and ``GreenWebBrowsingAgent`` generate their own behaviour. +Specifies which class should be used for the agent. ``ProxyAgent`` is used for agents that receive instructions from an RL algorithm. Scripted agents like ``RedDatabaseCorruptingAgent`` and ``probabilistic_agent`` generate their own behaviour. Available agent types: -- ``GreenWebBrowsingAgent`` +- ``probabilistic_agent`` - ``ProxyAgent`` - ``RedDatabaseCorruptingAgent`` diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index d6d3f044..b6b07afa 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -64,7 +64,7 @@ agents: - ref: client_1_green_user team: GREEN - type: GreenWebBrowsingAgent + type: probabilistic_agent observation_space: type: UC2GreenObservation action_space: diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py index b8f80e95..d244f6b0 100644 --- a/src/primaite/session/session.py +++ b/src/primaite/session/session.py @@ -4,7 +4,6 @@ from typing import Dict, List, Literal, Optional, Union from pydantic import BaseModel, ConfigDict -from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteGymEnv, PrimaiteRayEnv, PrimaiteRayMARLEnv from primaite.session.io import SessionIO, SessionIOSettings @@ -40,7 +39,7 @@ class SessionMode(Enum): class PrimaiteSession: """The main entrypoint for PrimAITE sessions, this manages a simulation, policy training, and environments.""" - def __init__(self, game: PrimaiteGame): + def __init__(self, game_cfg: Dict): """Initialise PrimaiteSession object.""" self.training_options: TrainingOptions """Options specific to agent training.""" @@ -57,7 +56,7 @@ class PrimaiteSession: self.io_manager: Optional["SessionIO"] = None """IO manager for the session.""" - self.game: PrimaiteGame = game + self.game_cfg: Dict = game_cfg """Primaite Game object for managing main simulation loop and agents.""" def start_session(self) -> None: @@ -93,9 +92,7 @@ class PrimaiteSession: io_settings = cfg.get("io_settings", {}) io_manager = SessionIO(SessionIOSettings(**io_settings)) - game = PrimaiteGame.from_config(cfg) - - sess = cls(game=game) + sess = cls(game_cfg=cfg) sess.io_manager = io_manager sess.training_options = TrainingOptions(**cfg["training_config"]) diff --git a/tests/assets/configs/dmz_network.yaml b/tests/assets/configs/dmz_network.yaml index 880735d9..56a68410 100644 --- a/tests/assets/configs/dmz_network.yaml +++ b/tests/assets/configs/dmz_network.yaml @@ -65,7 +65,7 @@ game: agents: - ref: client_1_green_user team: GREEN - type: GreenWebBrowsingAgent + type: probabilistic_agent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index 7785e4ae..da13dcd8 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -21,15 +21,15 @@ class TestPrimaiteSession: raise AssertionError assert session is not None - assert session.game.simulation - assert len(session.game.agents) == 3 - assert len(session.game.rl_agents) == 1 + assert session.env.game.simulation + assert len(session.env.game.agents) == 3 + assert len(session.env.game.rl_agents) == 1 assert session.policy assert session.env - assert session.game.simulation.network - assert len(session.game.simulation.network.nodes) == 10 + assert session.env.game.simulation.network + assert len(session.env.game.simulation.network.nodes) == 10 @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) def test_start_session(self, temp_primaite_session): From ed01293b862cb28fc7d13b9d04e994d98ca663cb Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 1 Mar 2024 16:02:27 +0000 Subject: [PATCH 652/980] Make db admin reward persistent --- src/primaite/game/agent/rewards.py | 8 +++++--- src/primaite/game/game.py | 2 +- .../simulator/system/applications/database_client.py | 9 ++++----- .../simulator/system/applications/web_browser.py | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 4eb1ab3f..882ad024 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -263,11 +263,13 @@ class GreenAdminDatabaseUnreachablePenalty(AbstractReward): :type state: Dict """ db_state = access_from_nested_dict(state, self.location_in_state) - if db_state is NOT_PRESENT_IN_STATE or "connections_status" not in db_state: + if db_state is NOT_PRESENT_IN_STATE or "last_connection_successful" not in db_state: _LOGGER.debug(f"Can't calculate reward for {self.__class__.__name__}") - connections_status = db_state["connections_status"] - if False in connections_status: + last_connection_successful = db_state["last_connection_successful"] + if last_connection_successful is False: return -1.0 + elif last_connection_successful is True: + return 1.0 return 0 @classmethod diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index b9f92d3a..cf21dd40 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -296,7 +296,7 @@ class PrimaiteGame: if service_type == "DatabaseService": if "options" in service_cfg: opt = service_cfg["options"] - new_service.password = opt.get("backup_server_ip", None) + new_service.password = opt.get("db_password", None) new_service.configure_backup(backup_server=IPv4Address(opt.get("backup_server_ip"))) if service_type == "FTPServer": if "options" in service_cfg: diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index fe8180d7..addad35a 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -1,5 +1,5 @@ from ipaddress import IPv4Address -from typing import Any, Dict, List, Optional +from typing import Any, Dict, Optional from uuid import uuid4 from primaite import getLogger @@ -26,7 +26,7 @@ class DatabaseClient(Application): server_password: Optional[str] = None connected: bool = False _query_success_tracker: Dict[str, bool] = {} - _connections_status: List[bool] = [] + _last_connection_successful: Optional[bool] = None """Keep track of connections that were established or verified during this step. Used for rewards.""" def __init__(self, **kwargs): @@ -46,7 +46,7 @@ class DatabaseClient(Application): can_connect = self.connect(connection_id=list(self.connections.keys())[-1]) else: can_connect = self.connect() - self._connections_status.append(can_connect) + self._last_connection_successful = can_connect return can_connect def describe_state(self) -> Dict: @@ -57,8 +57,7 @@ class DatabaseClient(Application): """ state = super().describe_state() # list of connections that were established or verified during this step. - state["connections_status"] = [c for c in self._connections_status] - self._connections_status.clear() + state["last_connection_successful"] = self._last_connection_successful return state def configure(self, server_ip_address: IPv4Address, server_password: Optional[str] = None): diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 6f2c479c..9fa86328 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -199,7 +199,7 @@ class WebBrowser(Application): def state(self) -> Dict: """Return the contents of this dataclass as a dict for use with describe_state method.""" if self.status == self._HistoryItemStatus.LOADED: - outcome = self.response_code + outcome = self.response_code.value else: outcome = self.status.value return {"url": self.url, "outcome": outcome} From 2a1d99cccee0c49360f84fc0640240c77052c65f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 1 Mar 2024 16:36:41 +0000 Subject: [PATCH 653/980] Fix problem with checking connection for db admin --- .../system/applications/database_client.py | 14 ++++++++------ .../applications/red_applications/dos_bot.py | 2 +- .../system/services/database/database_service.py | 12 ++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index addad35a..69065225 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -43,9 +43,9 @@ class DatabaseClient(Application): def execute(self) -> bool: """Execution definition for db client: perform a select query.""" if self.connections: - can_connect = self.connect(connection_id=list(self.connections.keys())[-1]) + can_connect = self.check_connection(connection_id=list(self.connections.keys())[-1]) else: - can_connect = self.connect() + can_connect = self.check_connection(connection_id=str(uuid4())) self._last_connection_successful = can_connect return can_connect @@ -79,15 +79,17 @@ class DatabaseClient(Application): if not connection_id: connection_id = str(uuid4()) - # if we are reusing a connection_id, remove it from self.connections so that its new status can be populated - # warning: janky - self._connections.pop(connection_id, None) - self.connected = self._connect( server_ip_address=self.server_ip_address, password=self.server_password, connection_id=connection_id ) return self.connected + def check_connection(self, connection_id:str) -> bool: + if not self._can_perform_action(): + return False + print(self.query("SELECT * FROM pg_stat_activity", connection_id=connection_id)) + return self.connected + def _connect( self, server_ip_address: IPv4Address, diff --git a/src/primaite/simulator/system/applications/red_applications/dos_bot.py b/src/primaite/simulator/system/applications/red_applications/dos_bot.py index 9dac6b25..1247bc99 100644 --- a/src/primaite/simulator/system/applications/red_applications/dos_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/dos_bot.py @@ -28,7 +28,7 @@ class DoSAttackStage(IntEnum): "Attack is completed." -class DoSBot(DatabaseClient, Application): +class DoSBot(DatabaseClient): """A bot that simulates a Denial of Service attack.""" target_ip_address: Optional[IPv4Address] = None diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 9fdfd5ff..c73132eb 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -221,6 +221,18 @@ class DatabaseService(Service): } else: return {"status_code": 404, "data": False} + elif query == "SELECT * FROM pg_stat_activity": + # Check if the connection is active. + if self.health_state_actual == SoftwareHealthState.GOOD: + return { + "status_code": 200, + "type": "sql", + "data": False, + "uuid": query_id, + "connection_id": connection_id, + } + else: + return {"status_code": 401, "data": False} else: # Invalid query self.sys_log.info(f"{self.name}: Invalid {query}") From 78ff658e30f96418ed17db6ecaf147f5f1cc019d Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 1 Mar 2024 16:48:05 +0000 Subject: [PATCH 654/980] #2356: optional dmz port + optional external acl rules --- .../hardware/nodes/network/firewall.py | 17 +- tests/assets/configs/basic_firewall.yaml | 174 ++++++++++++++++++ .../configuration_file_parsing/__init__.py | 2 + .../nodes/network/test_firewall_config.py | 26 ++- 4 files changed, 210 insertions(+), 9 deletions(-) create mode 100644 tests/assets/configs/basic_firewall.yaml diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index f5ddcfad..d7b1dfd9 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -500,7 +500,7 @@ class Firewall(Router): if "ports" in cfg: internal_port = cfg["ports"]["internal_port"] external_port = cfg["ports"]["external_port"] - dmz_port = cfg["ports"]["dmz_port"] + dmz_port = cfg["ports"].get("dmz_port") # configure internal port firewall.configure_internal_port( @@ -514,11 +514,12 @@ class Firewall(Router): subnet_mask=IPV4Address(external_port.get("subnet_mask", "255.255.255.0")), ) - # configure dmz port - firewall.configure_dmz_port( - ip_address=IPV4Address(dmz_port.get("ip_address")), - subnet_mask=IPV4Address(dmz_port.get("subnet_mask", "255.255.255.0")), - ) + # configure dmz port if not none + if dmz_port is not None: + firewall.configure_dmz_port( + ip_address=IPV4Address(dmz_port.get("ip_address")), + subnet_mask=IPV4Address(dmz_port.get("subnet_mask", "255.255.255.0")), + ) if "acl" in cfg: # acl rules for internal_inbound_acl if cfg["acl"]["internal_inbound_acl"]: @@ -573,7 +574,7 @@ class Firewall(Router): ) # acl rules for external_inbound_acl - if cfg["acl"]["external_inbound_acl"]: + if cfg["acl"].get("external_inbound_acl"): for r_num, r_cfg in cfg["acl"]["external_inbound_acl"].items(): firewall.external_inbound_acl.add_rule( action=ACLAction[r_cfg["action"]], @@ -586,7 +587,7 @@ class Firewall(Router): ) # acl rules for external_outbound_acl - if cfg["acl"]["external_outbound_acl"]: + if cfg["acl"].get("external_outbound_acl"): for r_num, r_cfg in cfg["acl"]["external_outbound_acl"].items(): firewall.external_outbound_acl.add_rule( action=ACLAction[r_cfg["action"]], diff --git a/tests/assets/configs/basic_firewall.yaml b/tests/assets/configs/basic_firewall.yaml new file mode 100644 index 00000000..71dc31a7 --- /dev/null +++ b/tests/assets/configs/basic_firewall.yaml @@ -0,0 +1,174 @@ +# Basic Switched network +# +# -------------- -------------- -------------- +# | client_1 |------| switch_1 |------| client_2 | +# -------------- -------------- -------------- +# + +training_config: + rl_framework: SB3 + rl_algorithm: PPO + seed: 333 + n_learn_episodes: 1 + n_eval_episodes: 5 + max_steps_per_episode: 128 + deterministic_eval: false + n_agents: 1 + agent_references: + - defender + +io_settings: + save_checkpoints: true + checkpoint_interval: 5 + save_step_metadata: false + save_pcap_logs: true + save_sys_logs: true + + +game: + max_episode_length: 256 + ports: + - ARP + - DNS + - HTTP + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + - UDP + +agents: + - ref: client_2_green_user + team: GREEN + type: GreenWebBrowsingAgent + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_2 + applications: + - application_name: WebBrowser + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_applications_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_settings: + start_step: 5 + frequency: 4 + variance: 3 + +simulation: + network: + nodes: + + - ref: firewall + type: firewall + hostname: firewall + start_up_duration: 0 + shut_down_duration: 0 + ports: + external_port: # port 1 + ip_address: 192.168.20.1 + subnet_mask: 255.255.255.0 + internal_port: # port 2 + ip_address: 192.168.1.2 + subnet_mask: 255.255.255.0 + acl: + internal_inbound_acl: + 21: + action: PERMIT + protocol: TCP + 22: + action: PERMIT + protocol: UDP + 23: + action: PERMIT + protocol: ICMP + internal_outbound_acl: + 21: + action: PERMIT + protocol: TCP + 22: + action: PERMIT + protocol: UDP + 23: + action: PERMIT + protocol: ICMP + dmz_inbound_acl: + 21: + action: PERMIT + protocol: TCP + 22: + action: PERMIT + protocol: UDP + 23: + action: PERMIT + protocol: ICMP + dmz_outbound_acl: + 21: + action: PERMIT + protocol: TCP + 22: + action: PERMIT + protocol: UDP + 23: + action: PERMIT + protocol: ICMP + + - ref: switch_1 + type: switch + hostname: switch_1 + num_ports: 8 + - ref: switch_2 + type: switch + hostname: switch_2 + num_ports: 8 + + - ref: client_1 + type: computer + hostname: client_1 + ip_address: 192.168.10.21 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + # pre installed services and applications + - ref: client_2 + type: computer + hostname: client_2 + ip_address: 192.168.10.22 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + # pre installed services and applications + + links: + - ref: switch_1___client_1 + endpoint_a_ref: switch_1 + endpoint_a_port: 1 + endpoint_b_ref: client_1 + endpoint_b_port: 1 + - ref: switch_2___client_2 + endpoint_a_ref: switch_2 + endpoint_a_port: 1 + endpoint_b_ref: client_2 + endpoint_b_port: 1 + - ref: switch_1___firewall + endpoint_a_ref: switch_1 + endpoint_a_port: 2 + endpoint_b_ref: firewall + endpoint_b_port: 1 + - ref: switch_2___firewall + endpoint_a_ref: switch_2 + endpoint_a_port: 2 + endpoint_b_ref: firewall + endpoint_b_port: 2 diff --git a/tests/integration_tests/configuration_file_parsing/__init__.py b/tests/integration_tests/configuration_file_parsing/__init__.py index 1c8481d6..be21c036 100644 --- a/tests/integration_tests/configuration_file_parsing/__init__.py +++ b/tests/integration_tests/configuration_file_parsing/__init__.py @@ -10,6 +10,8 @@ BASIC_CONFIG = TEST_ASSETS_ROOT / "configs/basic_switched_network.yaml" DMZ_NETWORK = TEST_ASSETS_ROOT / "configs/dmz_network.yaml" +BASIC_FIREWALL = TEST_ASSETS_ROOT / "configs/basic_firewall.yaml" + def load_config(config_path: Union[str, Path]) -> PrimaiteGame: """Returns a PrimaiteGame object which loads the contents of a given yaml path.""" diff --git a/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py b/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py index 2e0556e9..fc6e05ec 100644 --- a/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py +++ b/tests/integration_tests/configuration_file_parsing/nodes/network/test_firewall_config.py @@ -1,3 +1,5 @@ +from ipaddress import IPv4Address + import pytest from primaite.simulator.network.container import Network @@ -8,7 +10,7 @@ from primaite.simulator.network.hardware.nodes.network.firewall import Firewall from primaite.simulator.network.hardware.nodes.network.router import ACLAction from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -from tests.integration_tests.configuration_file_parsing import DMZ_NETWORK, load_config +from tests.integration_tests.configuration_file_parsing import BASIC_FIREWALL, DMZ_NETWORK, load_config @pytest.fixture(scope="function") @@ -17,6 +19,12 @@ def dmz_config() -> Network: return game.simulation.network +@pytest.fixture(scope="function") +def basic_firewall_config() -> Network: + game = load_config(BASIC_FIREWALL) + return game.simulation.network + + def test_firewall_is_in_configuration(dmz_config): """Test that the firewall exists in the configuration file.""" network: Network = dmz_config @@ -109,3 +117,19 @@ def test_firewall_acl_rules_correctly_added(dmz_config): # external_outbound should have implicit action PERMIT # ICMP does not have a provided ACL Rule but implicit action should allow anything assert firewall.external_outbound_acl.implicit_action == ACLAction.PERMIT + + +def test_firewall_with_no_dmz_port(basic_firewall_config): + """ + Test to check that: + - the DMZ port can be ignored i.e. is optional. + - the external_outbound_acl and external_inbound_acl are optional + """ + network: Network = basic_firewall_config + + firewall: Firewall = network.get_node_by_hostname("firewall") + + assert firewall.dmz_port.ip_address == IPv4Address("127.0.0.1") + + assert firewall.external_outbound_acl.num_rules == 0 + assert firewall.external_inbound_acl.num_rules == 0 From af036f63f1961d136380ceaa4e1068aae20846f1 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 1 Mar 2024 22:37:51 +0000 Subject: [PATCH 655/980] #2357 - Allowed the config to not have nodes, links and agents and still be parsed --- src/primaite/game/game.py | 14 ++++++--- .../no_nodes_links_agents_network.yaml | 31 +++++++++++++++++++ .../test_no_nodes_links_agents_config.py | 19 ++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 tests/assets/configs/no_nodes_links_agents_network.yaml create mode 100644 tests/integration_tests/configuration_file_parsing/test_no_nodes_links_agents_config.py diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 42d998c7..2659abef 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -222,8 +222,12 @@ class PrimaiteGame: sim = game.simulation net = sim.network - nodes_cfg = cfg["simulation"]["network"]["nodes"] - links_cfg = cfg["simulation"]["network"]["links"] + simulation_config = cfg.get("simulation", {}) + network_config = simulation_config.get("network", {}) + + nodes_cfg = network_config.get("nodes", []) + links_cfg = network_config.get("links", []) + for node_cfg in nodes_cfg: node_ref = node_cfg["ref"] n_type = node_cfg["type"] @@ -390,7 +394,7 @@ class PrimaiteGame: game.ref_map_links[link_cfg["ref"]] = new_link.uuid # 3. create agents - agents_cfg = cfg["agents"] + agents_cfg = cfg.get("agents", []) for agent_cfg in agents_cfg: agent_ref = agent_cfg["ref"] # noqa: F841 @@ -439,12 +443,12 @@ class PrimaiteGame: agent_settings=agent_settings, ) else: - msg(f"Configuration error: {agent_type} is not a valid agent type.") + msg = f"Configuration error: {agent_type} is not a valid agent type." _LOGGER.error(msg) raise ValueError(msg) game.agents[agent_cfg["ref"]] = new_agent # Set the NMNE capture config - set_nmne_config(cfg["simulation"]["network"].get("nmne_config", {})) + set_nmne_config(network_config.get("nmne_config", {})) return game diff --git a/tests/assets/configs/no_nodes_links_agents_network.yaml b/tests/assets/configs/no_nodes_links_agents_network.yaml new file mode 100644 index 00000000..607a899a --- /dev/null +++ b/tests/assets/configs/no_nodes_links_agents_network.yaml @@ -0,0 +1,31 @@ +training_config: + rl_framework: SB3 + rl_algorithm: PPO + seed: 333 + n_learn_episodes: 1 + n_eval_episodes: 5 + max_steps_per_episode: 128 + deterministic_eval: false + n_agents: 1 + agent_references: + - defender + +io_settings: + save_checkpoints: true + checkpoint_interval: 5 + save_step_metadata: false + save_pcap_logs: true + save_sys_logs: true + + +game: + max_episode_length: 256 + ports: + - ARP + - DNS + - HTTP + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + - UDP diff --git a/tests/integration_tests/configuration_file_parsing/test_no_nodes_links_agents_config.py b/tests/integration_tests/configuration_file_parsing/test_no_nodes_links_agents_config.py new file mode 100644 index 00000000..5c9b0cb9 --- /dev/null +++ b/tests/integration_tests/configuration_file_parsing/test_no_nodes_links_agents_config.py @@ -0,0 +1,19 @@ +import yaml + +from primaite.game.game import PrimaiteGame +from tests import TEST_ASSETS_ROOT + +CONFIG_FILE = TEST_ASSETS_ROOT / "configs" / "no_nodes_links_agents_network.yaml" + + +def test_no_nodes_links_agents_config(): + """Tests PrimaiteGame can be created from config file where there are no nodes, links, agents in the config file.""" + with open(CONFIG_FILE, "r") as f: + cfg = yaml.safe_load(f) + + game = PrimaiteGame.from_config(cfg) + + network = game.simulation.network + + assert len(network.nodes) == 0 + assert len(network.links) == 0 From 81fd43035d84273a121b8d9601f6b8ab8b8432ea Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 1 Mar 2024 22:51:01 +0000 Subject: [PATCH 656/980] #2358 - the node-specific properties in Network class now simply use node.__class__.__name__ to check their type for filtering by type. Tests updated to use the new property function names --- src/primaite/simulator/network/container.py | 39 +++++++++++-------- tests/conftest.py | 2 +- .../nodes/test_node_config.py | 13 ++++--- ...software_installation_and_configuration.py | 6 +-- .../_simulator/_network/test_container.py | 8 ++-- 5 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index b5a16430..6c2f38c5 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -8,10 +8,6 @@ from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import Link, Node, WiredNetworkInterface -from primaite.simulator.network.hardware.nodes.host.computer import Computer -from primaite.simulator.network.hardware.nodes.host.server import Server -from primaite.simulator.network.hardware.nodes.network.router import Router -from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.system.applications.application import Application from primaite.simulator.system.services.service import Service @@ -85,24 +81,29 @@ class Network(SimComponent): self.links[link_id].apply_timestep(timestep=timestep) @property - def routers(self) -> List[Router]: + def router_nodes(self) -> List[Node]: """The Routers in the Network.""" - return [node for node in self.nodes.values() if isinstance(node, Router)] + return [node for node in self.nodes.values() if node.__class__.__name__ == "Router"] @property - def switches(self) -> List[Switch]: + def switch_nodes(self) -> List[Node]: """The Switches in the Network.""" - return [node for node in self.nodes.values() if isinstance(node, Switch)] + return [node for node in self.nodes.values() if node.__class__.__name__ == "Switch"] @property - def computers(self) -> List[Computer]: + def computer_nodes(self) -> List[Node]: """The Computers in the Network.""" - return [node for node in self.nodes.values() if isinstance(node, Computer) and not isinstance(node, Server)] + return [node for node in self.nodes.values() if node.__class__.__name__ == "Computer"] @property - def servers(self) -> List[Server]: + def server_nodes(self) -> List[Node]: """The Servers in the Network.""" - return [node for node in self.nodes.values() if isinstance(node, Server)] + return [node for node in self.nodes.values() if node.__class__.__name__ == "Server"] + + @property + def firewall_nodes(self) -> List[Node]: + """The Firewalls in the Network.""" + return [node for node in self.nodes.values() if node.__class__.__name__ == "Firewall"] def show(self, nodes: bool = True, ip_addresses: bool = True, links: bool = True, markdown: bool = False): """ @@ -117,10 +118,11 @@ class Network(SimComponent): :param markdown: Use Markdown style in table output. Defaults to False. """ nodes_type_map = { - "Router": self.routers, - "Switch": self.switches, - "Server": self.servers, - "Computer": self.computers, + "Router": self.router_nodes, + "Firewall": self.firewall_nodes, + "Switch": self.switch_nodes, + "Server": self.server_nodes, + "Computer": self.computer_nodes, } if nodes: table = PrettyTable(["Node", "Type", "Operating State"]) @@ -143,7 +145,10 @@ class Network(SimComponent): for node in nodes: for i, port in node.network_interface.items(): if hasattr(port, "ip_address"): - table.add_row([node.hostname, i, port.ip_address, port.subnet_mask, node.default_gateway]) + port_str = port.port_name if port.port_name else port.port_num + table.add_row( + [node.hostname, port_str, port.ip_address, port.subnet_mask, node.default_gateway] + ) print(table) if links: diff --git a/tests/conftest.py b/tests/conftest.py index dbfff2f3..a8c3bdd1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -422,7 +422,7 @@ def install_stuff_to_sim(sim: Simulation): assert len(sim.network.nodes) == 6 assert len(sim.network.links) == 5 # 5.1: Assert the router is correctly configured - r = sim.network.routers[0] + r = sim.network.router_nodes[0] for i, acl_rule in enumerate(r.acl.acl): if i == 1: assert acl_rule.src_port == acl_rule.dst_port == Port.DNS diff --git a/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py b/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py index f23e7612..8797bf2e 100644 --- a/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py +++ b/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py @@ -11,9 +11,9 @@ def test_example_config(): network: Network = game.simulation.network assert len(network.nodes) == 10 # 10 nodes in example network - assert len(network.routers) == 1 # 1 router in network - assert len(network.switches) == 2 # 2 switches in network - assert len(network.servers) == 5 # 5 servers in network + assert len(network.router_nodes) == 1 # 1 router in network + assert len(network.switch_nodes) == 2 # 2 switches in network + assert len(network.server_nodes) == 5 # 5 servers in network def test_dmz_config(): @@ -23,9 +23,10 @@ def test_dmz_config(): network: Network = game.simulation.network assert len(network.nodes) == 9 # 9 nodes in network - assert len(network.routers) == 2 # 2 routers in network - assert len(network.switches) == 3 # 3 switches in network - assert len(network.servers) == 2 # 2 servers in network + assert len(network.router_nodes) == 1 # 1 router in network + assert len(network.firewall_nodes) == 1 # 1 firewall in network + assert len(network.switch_nodes) == 3 # 3 switches in network + assert len(network.server_nodes) == 2 # 2 servers in network def test_basic_config(): diff --git a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py index f3dc51bd..7da66547 100644 --- a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py +++ b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py @@ -60,9 +60,9 @@ def test_example_config(): network: Network = game.simulation.network assert len(network.nodes) == 10 # 10 nodes in example network - assert len(network.routers) == 1 # 1 router in network - assert len(network.switches) == 2 # 2 switches in network - assert len(network.servers) == 5 # 5 servers in network + assert len(network.router_nodes) == 1 # 1 router in network + assert len(network.switch_nodes) == 2 # 2 switches in network + assert len(network.server_nodes) == 5 # 5 servers in network def test_node_software_install(): diff --git a/tests/unit_tests/_primaite/_simulator/_network/test_container.py b/tests/unit_tests/_primaite/_simulator/_network/test_container.py index 2cfc3f11..f0e386b8 100644 --- a/tests/unit_tests/_primaite/_simulator/_network/test_container.py +++ b/tests/unit_tests/_primaite/_simulator/_network/test_container.py @@ -26,10 +26,10 @@ def filter_keys_nested_item(data, keys): @pytest.fixture(scope="function") def network(example_network) -> Network: - assert len(example_network.routers) is 1 - assert len(example_network.switches) is 2 - assert len(example_network.computers) is 2 - assert len(example_network.servers) is 2 + assert len(example_network.router_nodes) is 1 + assert len(example_network.switch_nodes) is 2 + assert len(example_network.computer_nodes) is 2 + assert len(example_network.server_nodes) is 2 example_network.show() From 80158fd9b4e1b2beeff3c42843c1f50b0dbc6716 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 3 Mar 2024 11:18:06 +0000 Subject: [PATCH 657/980] Make db manipulation bot work with db client --- src/primaite/game/game.py | 6 +-- .../network/transmission/network_layer.py | 2 + .../system/applications/database_client.py | 9 +++- .../red_applications/data_manipulation_bot.py | 48 +++++++++++++++---- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index cf21dd40..10c02b39 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -409,9 +409,6 @@ class PrimaiteGame: # CREATE REWARD FUNCTION reward_function = RewardFunction.from_config(reward_function_cfg) - # OTHER AGENT SETTINGS - agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) - # CREATE AGENT if agent_type == "probabilistic_agent": # TODO: implement non-random agents and fix this parsing @@ -424,6 +421,7 @@ class PrimaiteGame: settings=settings, ) elif agent_type == "ProxyAgent": + agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) new_agent = ProxyAgent( agent_name=agent_cfg["ref"], action_space=action_space, @@ -433,6 +431,8 @@ class PrimaiteGame: ) game.rl_agents[agent_cfg["ref"]] = new_agent elif agent_type == "RedDatabaseCorruptingAgent": + agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) + new_agent = DataManipulationAgent( agent_name=agent_cfg["ref"], action_space=action_space, diff --git a/src/primaite/simulator/network/transmission/network_layer.py b/src/primaite/simulator/network/transmission/network_layer.py index dc848ade..22d7f97d 100644 --- a/src/primaite/simulator/network/transmission/network_layer.py +++ b/src/primaite/simulator/network/transmission/network_layer.py @@ -15,6 +15,8 @@ class IPProtocol(Enum): .. _List of IPProtocols: """ + NONE = "none" + """Placeholder for a non-port.""" TCP = "tcp" """Transmission Control Protocol.""" UDP = "udp" diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 69065225..a8eac196 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -84,7 +84,14 @@ class DatabaseClient(Application): ) return self.connected - def check_connection(self, connection_id:str) -> bool: + def check_connection(self, connection_id: str) -> bool: + """Check whether the connection can be successfully re-established. + + :param connection_id: connection ID to check + :type connection_id: str + :return: Whether the connection was successfully re-established. + :rtype: bool + """ if not self._can_perform_action(): return False print(self.query("SELECT * FROM pg_stat_activity", connection_id=connection_id)) diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index 5fe951b7..11eb71f5 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -1,10 +1,13 @@ from enum import IntEnum from ipaddress import IPv4Address -from typing import Optional +from typing import Dict, Optional from primaite import getLogger from primaite.game.science import simulate_trial from primaite.simulator.core import RequestManager, RequestType +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import Application from primaite.simulator.system.applications.database_client import DatabaseClient _LOGGER = getLogger(__name__) @@ -32,12 +35,12 @@ class DataManipulationAttackStage(IntEnum): "Signifies that the attack has failed." -class DataManipulationBot(DatabaseClient): +class DataManipulationBot(Application): """A bot that simulates a script which performs a SQL injection attack.""" - server_ip_address: Optional[IPv4Address] = None + # server_ip_address: Optional[IPv4Address] = None payload: Optional[str] = None - server_password: Optional[str] = None + # server_password: Optional[str] = None port_scan_p_of_success: float = 0.1 data_manipulation_p_of_success: float = 0.1 @@ -46,8 +49,31 @@ class DataManipulationBot(DatabaseClient): "Whether to repeat attacking once finished." def __init__(self, **kwargs): + kwargs["name"] = "DataManipulationBot" + kwargs["port"] = Port.NONE + kwargs["protocol"] = IPProtocol.NONE + super().__init__(**kwargs) - self.name = "DataManipulationBot" + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + return state + + @property + def _host_db_client(self) -> DatabaseClient: + """Return the database client that is installed on the same machine as the DataManipulationBot.""" + db_client = self.software_manager.software.get("DatabaseClient") + if db_client is None: + _LOGGER.info(f"{self.__class__.__name__} cannot find a database client on its host.") + return db_client def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() @@ -76,8 +102,8 @@ class DataManipulationBot(DatabaseClient): :param repeat: Whether to repeat attacking once finished. """ self.server_ip_address = server_ip_address - self.payload = payload self.server_password = server_password + self.payload = payload self.port_scan_p_of_success = port_scan_p_of_success self.data_manipulation_p_of_success = data_manipulation_p_of_success self.repeat = repeat @@ -123,15 +149,17 @@ class DataManipulationBot(DatabaseClient): :param p_of_success: Probability of successfully performing data manipulation, by default 0.1. """ + self._host_db_client.server_ip_address = self.server_ip_address + self._host_db_client.server_password = self.server_password if self.attack_stage == DataManipulationAttackStage.PORT_SCAN: # perform the actual data manipulation attack if simulate_trial(p_of_success): self.sys_log.info(f"{self.name}: Performing data manipulation") # perform the attack - if not len(self.connections): - self.connect() - if len(self.connections): - self.query(self.payload) + if not len(self._host_db_client.connections): + self._host_db_client.connect() + if len(self._host_db_client.connections): + self._host_db_client.query(self.payload) self.sys_log.info(f"{self.name} payload delivered: {self.payload}") attack_successful = True if attack_successful: From 4a292a6239d748baf224ef8a52519a1eed6a0f3c Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 3 Mar 2024 11:23:24 +0000 Subject: [PATCH 658/980] Fix checking connection in db client --- src/primaite/simulator/system/applications/database_client.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index a8eac196..7b259ff4 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -94,8 +94,7 @@ class DatabaseClient(Application): """ if not self._can_perform_action(): return False - print(self.query("SELECT * FROM pg_stat_activity", connection_id=connection_id)) - return self.connected + return self.query("SELECT * FROM pg_stat_activity", connection_id=connection_id) def _connect( self, From 9762927289568d7b68da5214a436e68ebd4b61c4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 3 Mar 2024 11:43:24 +0000 Subject: [PATCH 659/980] Update notebook with new changes --- src/primaite/notebooks/uc2_demo.ipynb | 620 ++++++++++++++++++++++++-- 1 file changed, 581 insertions(+), 39 deletions(-) diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index 13fb7d80..36942b73 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -13,7 +13,7 @@ "source": [ "## Scenario\n", "\n", - "The network consists of an office subnet and a server subnet. Clients in the office access a website which fetches data from a database.\n", + "The network consists of an office subnet and a server subnet. Clients in the office access a website which fetches data from a database. Occasionally, admins need to access the database directly from the clients.\n", "\n", "[](_package_data/uc2_network.png)\n", "\n", @@ -46,7 +46,9 @@ "source": [ "## Green agent\n", "\n", - "There are green agents logged onto client 1 and client 2. They use the web browser to navigate to `http://arcd.com/users`. The web server replies with a status code 200 if the data is available on the database or 404 if not available." + "There are green agents logged onto client 1 and client 2. They use the web browser to navigate to `http://arcd.com/users`. The web server replies with a status code 200 if the data is available on the database or 404 if not available.\n", + "\n", + "Sometimes, the green agents send a request directly to the database to check that it is reachable." ] }, { @@ -68,7 +70,9 @@ "source": [ "## Blue agent\n", "\n", - "The blue agent can view the entire network, but the health statuses of components are not updated until a scan is performed. The blue agent should restore the database file from backup after it was compromised. It can also prevent further attacks by blocking the red agent client from sending the malicious SQL query to the database server. This can be done by implementing an ACL rule on the router." + "The blue agent can view the entire network, but the health statuses of components are not updated until a scan is performed. The blue agent should restore the database file from backup after it was compromised. It can also prevent further attacks by blocking the red agent client from sending the malicious SQL query to the database server. This can be done by implementing an ACL rule on the router.\n", + "\n", + "However, these rules will also impact greens' ability to check the database connection. The blue agent should only block the infected client, it should let the other client connect freely. Once the attack has begun, automated traffic monitoring will detect it as suspicious network traffic. The blue agent's observation space will show this as an increase in the number of malicious network events (NMNE) on one of the network interfaces. To achieve optimal reward, the agent should only block the client which has the non-zero outbound NMNE." ] }, { @@ -101,9 +105,11 @@ "The red agent does not use information about the state of the network to decide its action.\n", "\n", "### Green\n", - "The green agents use the web browser application to send requests to the web server. The schedule of each green agent is currently random, meaning it will request webpage with a 50% probability, and do nothing with a 50% probability.\n", + "The green agents use the web browser application to send requests to the web server. The schedule of each green agent is currently random, it will do nothing 30% of the time, send a web request 60% of the time, and send a db status check 10% of the time.\n", "\n", - "When a green agent is blocked from accessing the data through the webpage, this incurs a negative reward to the RL defender." + "When a green agent is blocked from accessing the data through the webpage, this incurs a negative reward to the RL defender.\n", + "\n", + "Also, when the green agent is blocked from checking the database status, it causes a small negative reward." ] }, { @@ -322,9 +328,10 @@ "source": [ "## Reward Function\n", "\n", - "The blue agent's reward is calculated using two measures:\n", + "The blue agent's reward is calculated using these measures:\n", "1. Whether the database file is in a good state (+1 for good, -1 for corrupted, 0 for any other state)\n", "2. Whether each green agents' most recent webpage request was successful (+1 for a `200` return code, -1 for a `404` return code and 0 otherwise).\n", + "3. Whether each green agents' most recent DB status check was successful (+1 for a successful connection, -1 for no connection).\n", "\n", "The file status reward and the two green-agent-related rewards are averaged to get a total step reward.\n" ] @@ -345,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "tags": [] }, @@ -357,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "tags": [] }, @@ -382,9 +389,169 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Resetting environment, episode 0, avg. reward: 0.0\n", + "env created successfully\n", + "{'ACL': {1: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 0,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 2: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 1,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 3: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 2,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 4: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 3,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 5: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 4,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 6: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 5,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 7: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 6,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 8: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 7,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 9: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 8,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 10: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 9,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0}},\n", + " 'ICS': 0,\n", + " 'LINKS': {1: {'PROTOCOLS': {'ALL': 1}},\n", + " 2: {'PROTOCOLS': {'ALL': 1}},\n", + " 3: {'PROTOCOLS': {'ALL': 1}},\n", + " 4: {'PROTOCOLS': {'ALL': 1}},\n", + " 5: {'PROTOCOLS': {'ALL': 1}},\n", + " 6: {'PROTOCOLS': {'ALL': 1}},\n", + " 7: {'PROTOCOLS': {'ALL': 1}},\n", + " 8: {'PROTOCOLS': {'ALL': 1}},\n", + " 9: {'PROTOCOLS': {'ALL': 1}},\n", + " 10: {'PROTOCOLS': {'ALL': 0}}},\n", + " 'NODES': {1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}},\n", + " 'health_status': 1}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0,\n", + " 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}}\n" + ] + } + ], "source": [ "# create the env\n", "with open(example_config_path(), 'r') as f:\n", @@ -407,12 +574,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The red agent will start attacking at some point between step 20 and 30. When this happens, the reward will drop immediately, then drop to -1.0 when green agents try to access the webpage." + "The red agent will start attacking at some point between step 20 and 30. When this happens, the reward will drop immediately, then drop to -0.8 when green agents try to access the webpage." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -430,9 +597,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 1, Red action: DO NOTHING, Blue reward:0.77\n", + "step: 2, Red action: DO NOTHING, Blue reward:0.77\n", + "step: 3, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 4, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 5, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 6, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 7, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 8, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 9, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 10, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 11, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 12, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 13, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 14, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 15, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 16, Red action: DO NOTHING, Blue reward:1.10\n", + "step: 17, Red action: DO NOTHING, Blue reward:1.20\n", + "step: 18, Red action: DO NOTHING, Blue reward:1.20\n", + "step: 19, Red action: DO NOTHING, Blue reward:1.20\n", + "step: 20, Red action: DO NOTHING, Blue reward:1.20\n", + "step: 21, Red action: DO NOTHING, Blue reward:1.20\n", + "step: 22, Red action: DO NOTHING, Blue reward:1.20\n", + "step: 23, Red action: DO NOTHING, Blue reward:1.20\n", + "step: 24, Red action: ATTACK from client 2, Blue reward:0.52\n", + "step: 25, Red action: DO NOTHING, Blue reward:0.52\n", + "step: 26, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 27, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 28, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 29, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 30, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 31, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 32, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 33, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 34, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 35, Red action: DO NOTHING, Blue reward:-0.80\n" + ] + } + ], "source": [ "for step in range(35):\n", " obs, reward, terminated, truncated, info = env.step(0)\n", @@ -448,9 +657,65 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}}, 'health_status': 1}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 1, 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0, 'outbound': 1}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}\n" + ] + } + ], "source": [ "pprint(obs['NODES'])" ] @@ -464,9 +729,65 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 3, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 2}}, 'health_status': 1}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 1, 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", + " 'nmne': {'inbound': 0, 'outbound': 1}},\n", + " 2: {'nic_status': 0,\n", + " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}\n" + ] + } + ], "source": [ "obs, reward, terminated, truncated, info = env.step(9) # scan database file\n", "obs, reward, terminated, truncated, info = env.step(1) # scan webapp service\n", @@ -481,6 +802,13 @@ "File 1 in folder 1 on node 3 has `health_status = 2`, indicating that the database file is compromised." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Also, the NMNE outbound of either client 1 (node 6) or client 2 (node 7) has increased from 0 to 1. This tells us which client is being used by the red agent." + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -490,9 +818,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 38\n", + "Red action: DONOTHING\n", + "Green action: DONOTHING\n", + "Green action: DONOTHING\n", + "Blue reward:-0.8\n" + ] + } + ], "source": [ "obs, reward, terminated, truncated, info = env.step(13) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", @@ -515,16 +855,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 52\n", + "Red action: DONOTHING\n", + "Green action: ('NODE_APPLICATION_EXECUTE', {'node_id': 0, 'application_id': 0})\n", + "Green action: ('NODE_APPLICATION_EXECUTE', {'node_id': 0, 'application_id': 0})\n", + "Blue reward:-0.80\n" + ] + } + ], "source": [ "obs, reward, terminated, truncated, info = env.step(0) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker'][0]}\" )\n", "print(f\"Green action: {info['agent_actions']['client_2_green_user']}\" )\n", "print(f\"Green action: {info['agent_actions']['client_1_green_user']}\" )\n", - "print(f\"Blue reward:{reward}\" )" + "print(f\"Blue reward:{reward:.2f}\" )" ] }, { @@ -538,29 +890,69 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 53, Red action: DONOTHING, Blue reward:-0.80\n", + "step: 54, Red action: DONOTHING, Blue reward:-0.80\n", + "step: 55, Red action: DONOTHING, Blue reward:-0.80\n", + "step: 56, Red action: DONOTHING, Blue reward:0.54\n", + "step: 57, Red action: DONOTHING, Blue reward:1.20\n", + "step: 58, Red action: DONOTHING, Blue reward:1.20\n", + "step: 59, Red action: DONOTHING, Blue reward:1.20\n", + "step: 60, Red action: DONOTHING, Blue reward:1.20\n", + "step: 61, Red action: DONOTHING, Blue reward:1.20\n", + "step: 62, Red action: DONOTHING, Blue reward:1.20\n", + "step: 63, Red action: DONOTHING, Blue reward:1.20\n", + "step: 64, Red action: DONOTHING, Blue reward:1.20\n", + "step: 65, Red action: DONOTHING, Blue reward:1.00\n", + "step: 66, Red action: DONOTHING, Blue reward:1.00\n", + "step: 67, Red action: DONOTHING, Blue reward:1.00\n", + "step: 68, Red action: DONOTHING, Blue reward:1.00\n", + "step: 69, Red action: DONOTHING, Blue reward:1.00\n", + "step: 70, Red action: NODE_APPLICATION_EXECUTE, Blue reward:1.00\n", + "step: 71, Red action: DONOTHING, Blue reward:1.00\n", + "step: 72, Red action: DONOTHING, Blue reward:1.00\n", + "step: 73, Red action: DONOTHING, Blue reward:1.00\n", + "step: 74, Red action: DONOTHING, Blue reward:1.00\n", + "step: 75, Red action: DONOTHING, Blue reward:0.80\n", + "step: 76, Red action: DONOTHING, Blue reward:0.80\n", + "step: 77, Red action: DONOTHING, Blue reward:0.80\n", + "step: 78, Red action: DONOTHING, Blue reward:0.80\n", + "step: 79, Red action: DONOTHING, Blue reward:0.80\n", + "step: 80, Red action: DONOTHING, Blue reward:0.80\n", + "step: 81, Red action: DONOTHING, Blue reward:0.80\n", + "step: 82, Red action: DONOTHING, Blue reward:0.80\n", + "step: 83, Red action: DONOTHING, Blue reward:0.80\n", + "step: 84, Red action: DONOTHING, Blue reward:0.80\n", + "step: 85, Red action: NODE_APPLICATION_EXECUTE, Blue reward:0.80\n" + ] + } + ], "source": [ "env.step(13) # Patch the database\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )\n", "\n", "env.step(26) # Block client 1\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )\n", "\n", "env.step(27) # Block client 2\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )\n", "\n", "for step in range(30):\n", " obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", - " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward}\" )" + " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Now, even though the red agent executes an attack, the reward stays at 1.0" + "Now, even though the red agent executes an attack, the reward stays at 0.8." ] }, { @@ -572,11 +964,168 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1: {'position': 0,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 2: {'position': 1,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 3: {'position': 2,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 4: {'position': 3,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 5: {'position': 4,\n", + " 'permission': 2,\n", + " 'source_node_id': 7,\n", + " 'source_port': 1,\n", + " 'dest_node_id': 4,\n", + " 'dest_port': 1,\n", + " 'protocol': 3},\n", + " 6: {'position': 5,\n", + " 'permission': 2,\n", + " 'source_node_id': 8,\n", + " 'source_port': 1,\n", + " 'dest_node_id': 4,\n", + " 'dest_port': 1,\n", + " 'protocol': 3},\n", + " 7: {'position': 6,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 8: {'position': 7,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 9: {'position': 8,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 10: {'position': 9,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0}}" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "obs['ACL']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can slightly increase the reward by unblocking the client which isn't being used by the attacker. If node 6 has outbound NMNEs, let's unblock client 2, and if node 7 has outbound NMNEs, let's unblock client 1." + ] + }, + { + "cell_type": "code", + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ - "obs['ACL']" + "if obs['NODES'][6]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", + " # client 1 has NMNEs, let's unblock client 2\n", + " env.step(34) # remove ACL rule 6\n", + "elif obs['NODES'][7]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", + " env.step(33) # remove ACL rule 5\n", + "else:\n", + " print(\"something went wrong, neither client has NMNEs\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, the reward will eventually increase to 1.0, even after red agent attempts subsequent attacks." + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 117, Red action: DONOTHING, Blue reward:1.00\n", + "step: 118, Red action: DONOTHING, Blue reward:1.00\n", + "step: 119, Red action: DONOTHING, Blue reward:1.00\n", + "step: 120, Red action: DONOTHING, Blue reward:1.00\n", + "step: 121, Red action: DONOTHING, Blue reward:1.00\n", + "step: 122, Red action: DONOTHING, Blue reward:1.00\n", + "step: 123, Red action: DONOTHING, Blue reward:1.00\n", + "step: 124, Red action: DONOTHING, Blue reward:1.00\n", + "step: 125, Red action: NODE_APPLICATION_EXECUTE, Blue reward:1.00\n", + "step: 126, Red action: DONOTHING, Blue reward:1.00\n", + "step: 127, Red action: DONOTHING, Blue reward:1.00\n", + "step: 128, Red action: DONOTHING, Blue reward:1.00\n", + "step: 129, Red action: DONOTHING, Blue reward:1.00\n", + "step: 130, Red action: DONOTHING, Blue reward:1.00\n", + "step: 131, Red action: DONOTHING, Blue reward:1.00\n", + "step: 132, Red action: DONOTHING, Blue reward:1.00\n", + "step: 133, Red action: DONOTHING, Blue reward:1.00\n", + "step: 134, Red action: DONOTHING, Blue reward:1.00\n", + "step: 135, Red action: DONOTHING, Blue reward:1.00\n", + "step: 136, Red action: DONOTHING, Blue reward:1.00\n", + "step: 137, Red action: DONOTHING, Blue reward:1.00\n", + "step: 138, Red action: DONOTHING, Blue reward:1.00\n", + "step: 139, Red action: DONOTHING, Blue reward:1.00\n", + "step: 140, Red action: DONOTHING, Blue reward:1.00\n", + "step: 141, Red action: DONOTHING, Blue reward:1.00\n", + "step: 142, Red action: DONOTHING, Blue reward:1.00\n", + "step: 143, Red action: DONOTHING, Blue reward:1.00\n", + "step: 144, Red action: NODE_APPLICATION_EXECUTE, Blue reward:1.00\n", + "step: 145, Red action: DONOTHING, Blue reward:1.00\n", + "step: 146, Red action: DONOTHING, Blue reward:1.00\n" + ] + } + ], + "source": [ + "for step in range(30):\n", + " obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", + " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )" ] }, { @@ -594,13 +1143,6 @@ "source": [ "env.reset()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From 070655cfce3da94db274377d404beb5d86955a8b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 3 Mar 2024 11:47:50 +0000 Subject: [PATCH 660/980] Update data manipulation bot documentation --- .../system/applications/data_manipulation_bot.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/source/simulation_components/system/applications/data_manipulation_bot.rst b/docs/source/simulation_components/system/applications/data_manipulation_bot.rst index 304621dd..9188733b 100644 --- a/docs/source/simulation_components/system/applications/data_manipulation_bot.rst +++ b/docs/source/simulation_components/system/applications/data_manipulation_bot.rst @@ -45,7 +45,7 @@ In a simulation, the bot can be controlled by using ``DataManipulationAgent`` wh Implementation ============== -The bot extends :ref:`DatabaseClient` and leverages its connectivity. +The bot connects to a :ref:`DatabaseClient` and leverages its connectivity. The host running ``DataManipulationBot`` must also have a :ref:`DatabaseClient` installed on it. - Uses the Application base class for lifecycle management. - Credentials, target IP and other options set via ``configure``. @@ -65,6 +65,7 @@ Python from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot + from primaite.simulator.system.applications.database_client import DatabaseClient client_1 = Computer( hostname="client_1", @@ -74,6 +75,7 @@ Python operating_state=NodeOperatingState.ON # initialise the computer in an ON state ) network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1]) + client_1.software_manager.install(DatabaseClient) client_1.software_manager.install(DataManipulationBot) data_manipulation_bot: DataManipulationBot = client_1.software_manager.software.get("DataManipulationBot") data_manipulation_bot.configure(server_ip_address=IPv4Address("192.168.1.14"), payload="DELETE") @@ -148,6 +150,10 @@ If not using the data manipulation bot manually, it needs to be used with a data data_manipulation_p_of_success: 0.1 payload: "DELETE" server_ip: 192.168.1.14 + - ref: web_server_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 Configuration ============= From 4d51b1a4146bb861f80101f4b013df093395a1b2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 3 Mar 2024 14:57:28 +0000 Subject: [PATCH 661/980] Update configs to new db manipulation bot approach --- src/primaite/simulator/network/networks.py | 63 ++----------------- .../red_applications/data_manipulation_bot.py | 4 ++ tests/assets/configs/basic_firewall.yaml | 2 +- .../test_data_manipulation_bot.py | 15 ++++- 4 files changed, 23 insertions(+), 61 deletions(-) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index f82dee4a..fa9d86ef 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -146,6 +146,9 @@ def arcd_uc2_network() -> Network: ) client_1.power_on() network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1]) + db_client_1 = client_1.software_manager.install(DatabaseClient) + db_client_1 = client_1.software_manager.software.get("DatabaseClient") + db_client_1.run() client_1.software_manager.install(DataManipulationBot) db_manipulation_bot: DataManipulationBot = client_1.software_manager.software.get("DataManipulationBot") db_manipulation_bot.configure( @@ -165,6 +168,9 @@ def arcd_uc2_network() -> Network: start_up_duration=0, ) client_2.power_on() + client_2.software_manager.install(DatabaseClient) + db_client_2 = client_2.software_manager.software.get("DatabaseClient") + db_client_2.run() web_browser = client_2.software_manager.software.get("WebBrowser") web_browser.target_url = "http://arcd.com/users/" network.connect(endpoint_b=client_2.network_interface[1], endpoint_a=switch_2.network_interface[2]) @@ -194,67 +200,10 @@ def arcd_uc2_network() -> Network: database_server.power_on() network.connect(endpoint_b=database_server.network_interface[1], endpoint_a=switch_1.network_interface[3]) - ddl = """ - CREATE TABLE IF NOT EXISTS user ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name VARCHAR(50) NOT NULL, - email VARCHAR(50) NOT NULL, - age INT, - city VARCHAR(50), - occupation VARCHAR(50) - );""" - - user_insert_statements = [ - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('John Doe', 'johndoe@example.com', 32, 'New York', 'Engineer');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('Jane Smith', 'janesmith@example.com', 27, 'Los Angeles', 'Designer');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('Bob Johnson', 'bobjohnson@example.com', 45, 'Chicago', 'Manager');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('Alice Lee', 'alicelee@example.com', 22, 'San Francisco', 'Student');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('David Kim', 'davidkim@example.com', 38, 'Houston', 'Consultant');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('Emily Chen', 'emilychen@example.com', 29, 'Seattle', 'Software Developer');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('Frank Wang', 'frankwang@example.com', 55, 'New York', 'Entrepreneur');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('Grace Park', 'gracepark@example.com', 31, 'Los Angeles', 'Marketing Specialist');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('Henry Wu', 'henrywu@example.com', 40, 'Chicago', 'Accountant');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('Isabella Kim', 'isabellakim@example.com', 26, 'San Francisco', 'Graphic Designer');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('Jake Lee', 'jakelee@example.com', 33, 'Houston', 'Sales Manager');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('Kelly Chen', 'kellychen@example.com', 28, 'Seattle', 'Web Developer');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('Lucas Liu', 'lucasliu@example.com', 42, 'New York', 'Lawyer');", - # noqa - "INSERT INTO user (name, email, age, city, occupation) " - "VALUES ('Maggie Wang', 'maggiewang@example.com', 30, 'Los Angeles', 'Data Analyst');", - # noqa - ] database_server.software_manager.install(DatabaseService) database_service: DatabaseService = database_server.software_manager.software.get("DatabaseService") # noqa database_service.start() database_service.configure_backup(backup_server=IPv4Address("192.168.1.16")) - database_service._process_sql(ddl, None, None) # noqa - for insert_statement in user_insert_statements: - database_service._process_sql(insert_statement, None, None) # noqa # Web Server web_server = Server( diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index 11eb71f5..961f82c2 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -149,6 +149,10 @@ class DataManipulationBot(Application): :param p_of_success: Probability of successfully performing data manipulation, by default 0.1. """ + if self._host_db_client is None: + self.attack_stage = DataManipulationAttackStage.FAILED + return + self._host_db_client.server_ip_address = self.server_ip_address self._host_db_client.server_password = self.server_password if self.attack_stage == DataManipulationAttackStage.PORT_SCAN: diff --git a/tests/assets/configs/basic_firewall.yaml b/tests/assets/configs/basic_firewall.yaml index 71dc31a7..0a892650 100644 --- a/tests/assets/configs/basic_firewall.yaml +++ b/tests/assets/configs/basic_firewall.yaml @@ -40,7 +40,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: GreenWebBrowsingAgent + type: probabilistic_agent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_data_manipulation_bot.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_data_manipulation_bot.py index 2ca67119..6d00886a 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_data_manipulation_bot.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/_red_applications/test_data_manipulation_bot.py @@ -26,8 +26,8 @@ def test_create_dm_bot(dm_client): data_manipulation_bot: DataManipulationBot = dm_client.software_manager.software.get("DataManipulationBot") assert data_manipulation_bot.name == "DataManipulationBot" - assert data_manipulation_bot.port == Port.POSTGRES_SERVER - assert data_manipulation_bot.protocol == IPProtocol.TCP + assert data_manipulation_bot.port == Port.NONE + assert data_manipulation_bot.protocol == IPProtocol.NONE assert data_manipulation_bot.payload == "DELETE" @@ -70,4 +70,13 @@ def test_dm_bot_perform_data_manipulation_success(dm_bot): dm_bot._perform_data_manipulation(p_of_success=1.0) assert dm_bot.attack_stage in (DataManipulationAttackStage.SUCCEEDED, DataManipulationAttackStage.FAILED) - assert len(dm_bot.connections) + assert len(dm_bot._host_db_client.connections) + + +def test_dm_bot_fails_without_db_client(dm_client): + dm_client.software_manager.uninstall("DatabaseClient") + dm_bot = dm_client.software_manager.software.get("DataManipulationBot") + assert dm_bot._host_db_client is None + dm_bot.attack_stage = DataManipulationAttackStage.PORT_SCAN + dm_bot._perform_data_manipulation(p_of_success=1.0) + assert dm_bot.attack_stage is DataManipulationAttackStage.FAILED From afa775baff03a7754ff0818934563f9587a2a1cb Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 3 Mar 2024 15:52:34 +0000 Subject: [PATCH 662/980] Add test for new reward --- .../game_layer/test_rewards.py | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/integration_tests/game_layer/test_rewards.py b/tests/integration_tests/game_layer/test_rewards.py index fd8a89a4..53753967 100644 --- a/tests/integration_tests/game_layer/test_rewards.py +++ b/tests/integration_tests/game_layer/test_rewards.py @@ -1,7 +1,10 @@ -from primaite.game.agent.rewards import WebpageUnavailablePenalty +from primaite.game.agent.rewards import GreenAdminDatabaseUnreachablePenalty, WebpageUnavailablePenalty +from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.services.database.database_service import DatabaseService from tests.conftest import ControlledAgent @@ -35,3 +38,44 @@ def test_WebpageUnavailablePenalty(game_and_agent): agent.store_action(action) game.step() assert agent.reward_function.current_reward == -0.7 + + +def test_uc2_rewards(game_and_agent): + game, agent = game_and_agent + agent: ControlledAgent + + server_1: Server = game.simulation.network.get_node_by_hostname("server_1") + server_1.software_manager.install(DatabaseService) + db_service = server_1.software_manager.software.get("DatabaseService") + db_service.start() + + client_1 = game.simulation.network.get_node_by_hostname("client_1") + client_1.software_manager.install(DatabaseClient) + db_client: DatabaseClient = client_1.software_manager.software.get("DatabaseClient") + db_client.configure(server_ip_address=server_1.network_interface[1].ip_address) + db_client.run() + + router: Router = game.simulation.network.get_node_by_hostname("router") + router.acl.add_rule(ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER, position=2) + + comp = GreenAdminDatabaseUnreachablePenalty("client_1") + + db_client.apply_request( + [ + "execute", + ] + ) + state = game.get_sim_state() + reward_value = comp.calculate(state) + assert reward_value == 1.0 + + router.acl.remove_rule(position=2) + + db_client.apply_request( + [ + "execute", + ] + ) + state = game.get_sim_state() + reward_value = comp.calculate(state) + assert reward_value == -1.0 From ef1a2dc3f4635db875d7970ba859dce7bbc021df Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 3 Mar 2024 16:00:10 +0000 Subject: [PATCH 663/980] clear uc2 notebook outputs --- src/primaite/notebooks/uc2_demo.ipynb | 539 ++------------------------ 1 file changed, 22 insertions(+), 517 deletions(-) diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index 36942b73..94be8baa 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -352,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "tags": [] }, @@ -364,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "tags": [] }, @@ -389,169 +389,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Resetting environment, episode 0, avg. reward: 0.0\n", - "env created successfully\n", - "{'ACL': {1: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 0,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 2: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 1,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 3: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 2,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 4: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 3,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 5: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 4,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 6: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 5,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 7: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 6,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 8: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 7,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 9: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 8,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 10: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 9,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0}},\n", - " 'ICS': 0,\n", - " 'LINKS': {1: {'PROTOCOLS': {'ALL': 1}},\n", - " 2: {'PROTOCOLS': {'ALL': 1}},\n", - " 3: {'PROTOCOLS': {'ALL': 1}},\n", - " 4: {'PROTOCOLS': {'ALL': 1}},\n", - " 5: {'PROTOCOLS': {'ALL': 1}},\n", - " 6: {'PROTOCOLS': {'ALL': 1}},\n", - " 7: {'PROTOCOLS': {'ALL': 1}},\n", - " 8: {'PROTOCOLS': {'ALL': 1}},\n", - " 9: {'PROTOCOLS': {'ALL': 1}},\n", - " 10: {'PROTOCOLS': {'ALL': 0}}},\n", - " 'NODES': {1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}},\n", - " 'health_status': 1}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0,\n", - " 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1}}}\n" - ] - } - ], + "outputs": [], "source": [ "# create the env\n", "with open(example_config_path(), 'r') as f:\n", @@ -579,7 +419,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -597,51 +437,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 1, Red action: DO NOTHING, Blue reward:0.77\n", - "step: 2, Red action: DO NOTHING, Blue reward:0.77\n", - "step: 3, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 4, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 5, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 6, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 7, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 8, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 9, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 10, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 11, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 12, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 13, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 14, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 15, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 16, Red action: DO NOTHING, Blue reward:1.10\n", - "step: 17, Red action: DO NOTHING, Blue reward:1.20\n", - "step: 18, Red action: DO NOTHING, Blue reward:1.20\n", - "step: 19, Red action: DO NOTHING, Blue reward:1.20\n", - "step: 20, Red action: DO NOTHING, Blue reward:1.20\n", - "step: 21, Red action: DO NOTHING, Blue reward:1.20\n", - "step: 22, Red action: DO NOTHING, Blue reward:1.20\n", - "step: 23, Red action: DO NOTHING, Blue reward:1.20\n", - "step: 24, Red action: ATTACK from client 2, Blue reward:0.52\n", - "step: 25, Red action: DO NOTHING, Blue reward:0.52\n", - "step: 26, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 27, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 28, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 29, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 30, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 31, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 32, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 33, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 34, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 35, Red action: DO NOTHING, Blue reward:-0.80\n" - ] - } - ], + "outputs": [], "source": [ "for step in range(35):\n", " obs, reward, terminated, truncated, info = env.step(0)\n", @@ -657,65 +455,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}}, 'health_status': 1}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 1, 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0, 'outbound': 1}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1}}\n" - ] - } - ], + "outputs": [], "source": [ "pprint(obs['NODES'])" ] @@ -729,65 +471,9 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 3, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 2}}, 'health_status': 1}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 1, 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NETWORK_INTERFACES': {1: {'nic_status': 1,\n", - " 'nmne': {'inbound': 0, 'outbound': 1}},\n", - " 2: {'nic_status': 0,\n", - " 'nmne': {'inbound': 0, 'outbound': 0}}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1}}\n" - ] - } - ], + "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(9) # scan database file\n", "obs, reward, terminated, truncated, info = env.step(1) # scan webapp service\n", @@ -818,21 +504,9 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 38\n", - "Red action: DONOTHING\n", - "Green action: DONOTHING\n", - "Green action: DONOTHING\n", - "Blue reward:-0.8\n" - ] - } - ], + "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(13) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", @@ -855,21 +529,9 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 52\n", - "Red action: DONOTHING\n", - "Green action: ('NODE_APPLICATION_EXECUTE', {'node_id': 0, 'application_id': 0})\n", - "Green action: ('NODE_APPLICATION_EXECUTE', {'node_id': 0, 'application_id': 0})\n", - "Blue reward:-0.80\n" - ] - } - ], + "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(0) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", @@ -890,49 +552,9 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 53, Red action: DONOTHING, Blue reward:-0.80\n", - "step: 54, Red action: DONOTHING, Blue reward:-0.80\n", - "step: 55, Red action: DONOTHING, Blue reward:-0.80\n", - "step: 56, Red action: DONOTHING, Blue reward:0.54\n", - "step: 57, Red action: DONOTHING, Blue reward:1.20\n", - "step: 58, Red action: DONOTHING, Blue reward:1.20\n", - "step: 59, Red action: DONOTHING, Blue reward:1.20\n", - "step: 60, Red action: DONOTHING, Blue reward:1.20\n", - "step: 61, Red action: DONOTHING, Blue reward:1.20\n", - "step: 62, Red action: DONOTHING, Blue reward:1.20\n", - "step: 63, Red action: DONOTHING, Blue reward:1.20\n", - "step: 64, Red action: DONOTHING, Blue reward:1.20\n", - "step: 65, Red action: DONOTHING, Blue reward:1.00\n", - "step: 66, Red action: DONOTHING, Blue reward:1.00\n", - "step: 67, Red action: DONOTHING, Blue reward:1.00\n", - "step: 68, Red action: DONOTHING, Blue reward:1.00\n", - "step: 69, Red action: DONOTHING, Blue reward:1.00\n", - "step: 70, Red action: NODE_APPLICATION_EXECUTE, Blue reward:1.00\n", - "step: 71, Red action: DONOTHING, Blue reward:1.00\n", - "step: 72, Red action: DONOTHING, Blue reward:1.00\n", - "step: 73, Red action: DONOTHING, Blue reward:1.00\n", - "step: 74, Red action: DONOTHING, Blue reward:1.00\n", - "step: 75, Red action: DONOTHING, Blue reward:0.80\n", - "step: 76, Red action: DONOTHING, Blue reward:0.80\n", - "step: 77, Red action: DONOTHING, Blue reward:0.80\n", - "step: 78, Red action: DONOTHING, Blue reward:0.80\n", - "step: 79, Red action: DONOTHING, Blue reward:0.80\n", - "step: 80, Red action: DONOTHING, Blue reward:0.80\n", - "step: 81, Red action: DONOTHING, Blue reward:0.80\n", - "step: 82, Red action: DONOTHING, Blue reward:0.80\n", - "step: 83, Red action: DONOTHING, Blue reward:0.80\n", - "step: 84, Red action: DONOTHING, Blue reward:0.80\n", - "step: 85, Red action: NODE_APPLICATION_EXECUTE, Blue reward:0.80\n" - ] - } - ], + "outputs": [], "source": [ "env.step(13) # Patch the database\n", "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )\n", @@ -964,89 +586,9 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{1: {'position': 0,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 2: {'position': 1,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 3: {'position': 2,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 4: {'position': 3,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 5: {'position': 4,\n", - " 'permission': 2,\n", - " 'source_node_id': 7,\n", - " 'source_port': 1,\n", - " 'dest_node_id': 4,\n", - " 'dest_port': 1,\n", - " 'protocol': 3},\n", - " 6: {'position': 5,\n", - " 'permission': 2,\n", - " 'source_node_id': 8,\n", - " 'source_port': 1,\n", - " 'dest_node_id': 4,\n", - " 'dest_port': 1,\n", - " 'protocol': 3},\n", - " 7: {'position': 6,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 8: {'position': 7,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 9: {'position': 8,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 10: {'position': 9,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0}}" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "obs['ACL']" ] @@ -1060,7 +602,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -1082,46 +624,9 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 117, Red action: DONOTHING, Blue reward:1.00\n", - "step: 118, Red action: DONOTHING, Blue reward:1.00\n", - "step: 119, Red action: DONOTHING, Blue reward:1.00\n", - "step: 120, Red action: DONOTHING, Blue reward:1.00\n", - "step: 121, Red action: DONOTHING, Blue reward:1.00\n", - "step: 122, Red action: DONOTHING, Blue reward:1.00\n", - "step: 123, Red action: DONOTHING, Blue reward:1.00\n", - "step: 124, Red action: DONOTHING, Blue reward:1.00\n", - "step: 125, Red action: NODE_APPLICATION_EXECUTE, Blue reward:1.00\n", - "step: 126, Red action: DONOTHING, Blue reward:1.00\n", - "step: 127, Red action: DONOTHING, Blue reward:1.00\n", - "step: 128, Red action: DONOTHING, Blue reward:1.00\n", - "step: 129, Red action: DONOTHING, Blue reward:1.00\n", - "step: 130, Red action: DONOTHING, Blue reward:1.00\n", - "step: 131, Red action: DONOTHING, Blue reward:1.00\n", - "step: 132, Red action: DONOTHING, Blue reward:1.00\n", - "step: 133, Red action: DONOTHING, Blue reward:1.00\n", - "step: 134, Red action: DONOTHING, Blue reward:1.00\n", - "step: 135, Red action: DONOTHING, Blue reward:1.00\n", - "step: 136, Red action: DONOTHING, Blue reward:1.00\n", - "step: 137, Red action: DONOTHING, Blue reward:1.00\n", - "step: 138, Red action: DONOTHING, Blue reward:1.00\n", - "step: 139, Red action: DONOTHING, Blue reward:1.00\n", - "step: 140, Red action: DONOTHING, Blue reward:1.00\n", - "step: 141, Red action: DONOTHING, Blue reward:1.00\n", - "step: 142, Red action: DONOTHING, Blue reward:1.00\n", - "step: 143, Red action: DONOTHING, Blue reward:1.00\n", - "step: 144, Red action: NODE_APPLICATION_EXECUTE, Blue reward:1.00\n", - "step: 145, Red action: DONOTHING, Blue reward:1.00\n", - "step: 146, Red action: DONOTHING, Blue reward:1.00\n" - ] - } - ], + "outputs": [], "source": [ "for step in range(30):\n", " obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", From a6031d568d175a56a572f7e321cd29da2aad04a5 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 3 Mar 2024 16:36:08 +0000 Subject: [PATCH 664/980] Remove unused import --- .../simulator/system/applications/red_applications/dos_bot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/primaite/simulator/system/applications/red_applications/dos_bot.py b/src/primaite/simulator/system/applications/red_applications/dos_bot.py index 1247bc99..202fd189 100644 --- a/src/primaite/simulator/system/applications/red_applications/dos_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/dos_bot.py @@ -6,7 +6,6 @@ from primaite import getLogger from primaite.game.science import simulate_trial from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.system.applications.application import Application from primaite.simulator.system.applications.database_client import DatabaseClient _LOGGER = getLogger(__name__) From 0e8c60df4c8eb3f0727c4ef0b224c909d783a707 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 3 Mar 2024 16:53:18 +0000 Subject: [PATCH 665/980] Update actions --- .../config/_package_data/example_config.yaml | 244 ++++++++++++------ src/primaite/notebooks/uc2_demo.ipynb | 26 +- 2 files changed, 184 insertions(+), 86 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 478124a9..b906bba8 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -238,99 +238,196 @@ agents: 3: action: "NODE_SERVICE_START" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 4: action: "NODE_SERVICE_PAUSE" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 5: action: "NODE_SERVICE_RESUME" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 6: action: "NODE_SERVICE_RESTART" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 7: action: "NODE_SERVICE_DISABLE" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 8: action: "NODE_SERVICE_ENABLE" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 9: # check database.db file action: "NODE_FILE_SCAN" options: - node_id: 2 - folder_id: 0 - file_id: 0 + node_id: 2 + folder_id: 0 + file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: - node_id: 2 - folder_id: 0 - file_id: 0 + node_id: 2 + folder_id: 0 + file_id: 0 11: action: "NODE_FILE_DELETE" options: - node_id: 2 - folder_id: 0 - file_id: 0 + node_id: 2 + folder_id: 0 + file_id: 0 12: action: "NODE_FILE_REPAIR" options: - node_id: 2 - folder_id: 0 - file_id: 0 + node_id: 2 + folder_id: 0 + file_id: 0 13: action: "NODE_SERVICE_PATCH" options: - node_id: 2 - service_id: 0 + node_id: 2 + service_id: 0 14: action: "NODE_FOLDER_SCAN" options: - node_id: 2 - folder_id: 0 + node_id: 2 + folder_id: 0 15: action: "NODE_FOLDER_CHECKHASH" options: - node_id: 2 - folder_id: 0 + node_id: 2 + folder_id: 0 16: action: "NODE_FOLDER_REPAIR" options: - node_id: 2 - folder_id: 0 + node_id: 2 + folder_id: 0 17: action: "NODE_FOLDER_RESTORE" options: - node_id: 2 - folder_id: 0 + node_id: 2 + folder_id: 0 18: action: "NODE_OS_SCAN" options: - node_id: 2 - 19: # shutdown client 1 + node_id: 0 + 19: action: "NODE_SHUTDOWN" options: - node_id: 5 + node_id: 0 20: - action: "NODE_STARTUP" + action: NODE_STARTUP options: - node_id: 5 + node_id: 0 21: - action: "NODE_RESET" + action: NODE_RESET options: - node_id: 5 - 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" + node_id: 0 + 22: + action: "NODE_OS_SCAN" + options: + node_id: 1 + 23: + action: "NODE_SHUTDOWN" + options: + node_id: 1 + 24: + action: NODE_STARTUP + options: + node_id: 1 + 25: + action: NODE_RESET + options: + node_id: 1 + 26: # old action num: 18 + action: "NODE_OS_SCAN" + options: + node_id: 2 + 27: + action: "NODE_SHUTDOWN" + options: + node_id: 2 + 28: + action: NODE_STARTUP + options: + node_id: 2 + 29: + action: NODE_RESET + options: + node_id: 2 + 30: + action: "NODE_OS_SCAN" + options: + node_id: 3 + 31: + action: "NODE_SHUTDOWN" + options: + node_id: 3 + 32: + action: NODE_STARTUP + options: + node_id: 3 + 33: + action: NODE_RESET + options: + node_id: 3 + 34: + action: "NODE_OS_SCAN" + options: + node_id: 4 + 35: + action: "NODE_SHUTDOWN" + options: + node_id: 4 + 36: + action: NODE_STARTUP + options: + node_id: 4 + 37: + action: NODE_RESET + options: + node_id: 4 + 38: + action: "NODE_OS_SCAN" + options: + node_id: 5 + 39: # old action num: 19 # shutdown client 1 + action: "NODE_SHUTDOWN" + options: + node_id: 5 + 40: # old action num: 20 + action: NODE_STARTUP + options: + node_id: 5 + 41: # old action num: 21 + action: NODE_RESET + options: + node_id: 5 + 42: + action: "NODE_OS_SCAN" + options: + node_id: 6 + 43: + action: "NODE_SHUTDOWN" + options: + node_id: 6 + 44: + action: NODE_STARTUP + options: + node_id: 6 + 45: + action: NODE_RESET + options: + node_id: 6 + + 46: # old action num: 22 # "ACL: ADDRULE - Block outgoing traffic from client 1" action: "NETWORK_ACL_ADDRULE" options: position: 1 @@ -340,7 +437,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" + 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" action: "NETWORK_ACL_ADDRULE" options: position: 2 @@ -350,7 +447,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 24: # block tcp traffic from client 1 to web app + 48: # old action num: 24 # block tcp traffic from client 1 to web app action: "NETWORK_ACL_ADDRULE" options: position: 3 @@ -360,7 +457,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 25: # block tcp traffic from client 2 to web app + 49: # old action num: 25 # block tcp traffic from client 2 to web app action: "NETWORK_ACL_ADDRULE" options: position: 4 @@ -370,7 +467,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 26: + 50: # old action num: 26 action: "NETWORK_ACL_ADDRULE" options: position: 5 @@ -380,7 +477,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 27: + 51: # old action num: 27 action: "NETWORK_ACL_ADDRULE" options: position: 6 @@ -390,128 +487,129 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 28: + 52: # old action num: 28 action: "NETWORK_ACL_REMOVERULE" options: position: 0 - 29: + 53: # old action num: 29 action: "NETWORK_ACL_REMOVERULE" options: position: 1 - 30: + 54: # old action num: 30 action: "NETWORK_ACL_REMOVERULE" options: position: 2 - 31: + 55: # old action num: 31 action: "NETWORK_ACL_REMOVERULE" options: position: 3 - 32: + 56: # old action num: 32 action: "NETWORK_ACL_REMOVERULE" options: position: 4 - 33: + 57: # old action num: 33 action: "NETWORK_ACL_REMOVERULE" options: position: 5 - 34: + 58: # old action num: 34 action: "NETWORK_ACL_REMOVERULE" options: position: 6 - 35: + 59: # old action num: 35 action: "NETWORK_ACL_REMOVERULE" options: position: 7 - 36: + 60: # old action num: 36 action: "NETWORK_ACL_REMOVERULE" options: position: 8 - 37: + 61: # old action num: 37 action: "NETWORK_ACL_REMOVERULE" options: position: 9 - 38: + 62: # old action num: 38 action: "NETWORK_NIC_DISABLE" options: node_id: 0 nic_id: 0 - 39: + 63: # old action num: 39 action: "NETWORK_NIC_ENABLE" options: node_id: 0 nic_id: 0 - 40: + 64: # old action num: 40 action: "NETWORK_NIC_DISABLE" options: node_id: 1 nic_id: 0 - 41: + 65: # old action num: 41 action: "NETWORK_NIC_ENABLE" options: node_id: 1 nic_id: 0 - 42: + 66: # old action num: 42 action: "NETWORK_NIC_DISABLE" options: node_id: 2 nic_id: 0 - 43: + 67: # old action num: 43 action: "NETWORK_NIC_ENABLE" options: node_id: 2 nic_id: 0 - 44: + 68: # old action num: 44 action: "NETWORK_NIC_DISABLE" options: node_id: 3 nic_id: 0 - 45: + 69: # old action num: 45 action: "NETWORK_NIC_ENABLE" options: node_id: 3 nic_id: 0 - 46: + 70: # old action num: 46 action: "NETWORK_NIC_DISABLE" options: node_id: 4 nic_id: 0 - 47: + 71: # old action num: 47 action: "NETWORK_NIC_ENABLE" options: node_id: 4 nic_id: 0 - 48: + 72: # old action num: 48 action: "NETWORK_NIC_DISABLE" options: node_id: 4 nic_id: 1 - 49: + 73: # old action num: 49 action: "NETWORK_NIC_ENABLE" options: node_id: 4 nic_id: 1 - 50: + 74: # old action num: 50 action: "NETWORK_NIC_DISABLE" options: node_id: 5 nic_id: 0 - 51: + 75: # old action num: 51 action: "NETWORK_NIC_ENABLE" options: node_id: 5 nic_id: 0 - 52: + 76: # old action num: 52 action: "NETWORK_NIC_DISABLE" options: node_id: 6 nic_id: 0 - 53: + 77: # old action num: 53 action: "NETWORK_NIC_ENABLE" options: node_id: 6 nic_id: 0 + options: nodes: - node_name: domain_controller diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/uc2_demo.ipynb index c8f2595b..ca06ea8a 100644 --- a/src/primaite/notebooks/uc2_demo.ipynb +++ b/src/primaite/notebooks/uc2_demo.ipynb @@ -301,17 +301,17 @@ "- `1`: Scan the web service - this refreshes the health status in the observation space\n", "- `9`: Scan the database file - this refreshes the health status of the database file\n", "- `13`: Patch the database service - This triggers the database to restore data from the backup server\n", - "- `19`: Shut down client 1\n", - "- `20`: Start up client 1\n", - "- `22`: Block outgoing traffic from client 1\n", - "- `23`: Block outgoing traffic from client 2\n", - "- `26`: Block TCP traffic from client 1 to the database node\n", - "- `27`: Block TCP traffic from client 2 to the database node\n", - "- `28-37`: Remove ACL rules 1-10\n", - "- `42`: Disconnect client 1 from the network\n", - "- `43`: Reconnect client 1 to the network\n", - "- `44`: Disconnect client 2 from the network\n", - "- `45`: Reconnect client 2 to the network\n", + "- `39`: Shut down client 1\n", + "- `40`: Start up client 1\n", + "- `46`: Block outgoing traffic from client 1\n", + "- `47`: Block outgoing traffic from client 2\n", + "- `50`: Block TCP traffic from client 1 to the database node\n", + "- `51`: Block TCP traffic from client 2 to the database node\n", + "- `52-61`: Remove ACL rules 1-10\n", + "- `66`: Disconnect client 1 from the network\n", + "- `67`: Reconnect client 1 to the network\n", + "- `68`: Disconnect client 2 from the network\n", + "- `69`: Reconnect client 2 to the network\n", "\n", "The other actions will either have no effect or will negatively impact the network, so the blue agent should avoid taking them." ] @@ -541,10 +541,10 @@ "env.step(13) # Patch the database\n", "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward}\" )\n", "\n", - "env.step(26) # Block client 1\n", + "env.step(50) # Block client 1\n", "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward}\" )\n", "\n", - "env.step(27) # Block client 2\n", + "env.step(51) # Block client 2\n", "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward}\" )\n", "\n", "for step in range(30):\n", From afc3635bfe3cac06fdc4949bca0262c89cc5a1d1 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 3 Mar 2024 16:56:52 +0000 Subject: [PATCH 666/980] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d54af980..5416bb9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -111,6 +111,7 @@ SessionManager. - **ACLRule Wildcard Masking**: Updated the `ACLRule` class to support IP ranges using wildcard masking. This enhancement allows for more flexible and granular control over traffic filtering, enabling the specification of broader or more specific IP address ranges in ACL rules. - Updated `NetworkInterface` documentation to reflect the new NMNE capturing features and how to use them. - Integration of NMNE capturing functionality within the `NicObservation` class. +- Changed blue action set to enable applying node scan, reset, start, and shutdown to every host in data manipulation scenario ### Removed - Removed legacy simulation modules: `acl`, `common`, `environment`, `links`, `nodes`, `pol` From a4c723858b0d02430ebebeef4f6393707f508d2d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 3 Mar 2024 16:57:53 +0000 Subject: [PATCH 667/980] Update action map in second --- .../example_config_2_rl_agents.yaml | 487 ++++++++++++------ 1 file changed, 341 insertions(+), 146 deletions(-) diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index b6b07afa..fd5a3092 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -240,99 +240,196 @@ agents: 3: action: "NODE_SERVICE_START" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 4: action: "NODE_SERVICE_PAUSE" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 5: action: "NODE_SERVICE_RESUME" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 6: action: "NODE_SERVICE_RESTART" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 7: action: "NODE_SERVICE_DISABLE" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 8: action: "NODE_SERVICE_ENABLE" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 9: # check database.db file action: "NODE_FILE_SCAN" options: - node_id: 2 - folder_id: 0 - file_id: 0 + node_id: 2 + folder_id: 0 + file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: - node_id: 2 - folder_id: 0 - file_id: 0 + node_id: 2 + folder_id: 0 + file_id: 0 11: action: "NODE_FILE_DELETE" options: - node_id: 2 - folder_id: 0 - file_id: 0 + node_id: 2 + folder_id: 0 + file_id: 0 12: action: "NODE_FILE_REPAIR" options: - node_id: 2 - folder_id: 0 - file_id: 0 + node_id: 2 + folder_id: 0 + file_id: 0 13: action: "NODE_SERVICE_PATCH" options: - node_id: 2 - service_id: 0 + node_id: 2 + service_id: 0 14: action: "NODE_FOLDER_SCAN" options: - node_id: 2 - folder_id: 0 + node_id: 2 + folder_id: 0 15: action: "NODE_FOLDER_CHECKHASH" options: - node_id: 2 - folder_id: 0 + node_id: 2 + folder_id: 0 16: action: "NODE_FOLDER_REPAIR" options: - node_id: 2 - folder_id: 0 + node_id: 2 + folder_id: 0 17: action: "NODE_FOLDER_RESTORE" options: - node_id: 2 - folder_id: 0 + node_id: 2 + folder_id: 0 18: action: "NODE_OS_SCAN" options: - node_id: 2 - 19: # shutdown client 1 + node_id: 0 + 19: action: "NODE_SHUTDOWN" options: - node_id: 5 + node_id: 0 20: - action: "NODE_STARTUP" + action: NODE_STARTUP options: - node_id: 5 + node_id: 0 21: - action: "NODE_RESET" + action: NODE_RESET options: - node_id: 5 - 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" + node_id: 0 + 22: + action: "NODE_OS_SCAN" + options: + node_id: 1 + 23: + action: "NODE_SHUTDOWN" + options: + node_id: 1 + 24: + action: NODE_STARTUP + options: + node_id: 1 + 25: + action: NODE_RESET + options: + node_id: 1 + 26: # old action num: 18 + action: "NODE_OS_SCAN" + options: + node_id: 2 + 27: + action: "NODE_SHUTDOWN" + options: + node_id: 2 + 28: + action: NODE_STARTUP + options: + node_id: 2 + 29: + action: NODE_RESET + options: + node_id: 2 + 30: + action: "NODE_OS_SCAN" + options: + node_id: 3 + 31: + action: "NODE_SHUTDOWN" + options: + node_id: 3 + 32: + action: NODE_STARTUP + options: + node_id: 3 + 33: + action: NODE_RESET + options: + node_id: 3 + 34: + action: "NODE_OS_SCAN" + options: + node_id: 4 + 35: + action: "NODE_SHUTDOWN" + options: + node_id: 4 + 36: + action: NODE_STARTUP + options: + node_id: 4 + 37: + action: NODE_RESET + options: + node_id: 4 + 38: + action: "NODE_OS_SCAN" + options: + node_id: 5 + 39: # old action num: 19 # shutdown client 1 + action: "NODE_SHUTDOWN" + options: + node_id: 5 + 40: # old action num: 20 + action: NODE_STARTUP + options: + node_id: 5 + 41: # old action num: 21 + action: NODE_RESET + options: + node_id: 5 + 42: + action: "NODE_OS_SCAN" + options: + node_id: 6 + 43: + action: "NODE_SHUTDOWN" + options: + node_id: 6 + 44: + action: NODE_STARTUP + options: + node_id: 6 + 45: + action: NODE_RESET + options: + node_id: 6 + + 46: # old action num: 22 # "ACL: ADDRULE - Block outgoing traffic from client 1" action: "NETWORK_ACL_ADDRULE" options: position: 1 @@ -342,7 +439,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" + 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" action: "NETWORK_ACL_ADDRULE" options: position: 2 @@ -352,7 +449,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 24: # block tcp traffic from client 1 to web app + 48: # old action num: 24 # block tcp traffic from client 1 to web app action: "NETWORK_ACL_ADDRULE" options: position: 3 @@ -362,7 +459,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 25: # block tcp traffic from client 2 to web app + 49: # old action num: 25 # block tcp traffic from client 2 to web app action: "NETWORK_ACL_ADDRULE" options: position: 4 @@ -372,7 +469,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 26: + 50: # old action num: 26 action: "NETWORK_ACL_ADDRULE" options: position: 5 @@ -382,7 +479,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 27: + 51: # old action num: 27 action: "NETWORK_ACL_ADDRULE" options: position: 6 @@ -392,122 +489,122 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 28: + 52: # old action num: 28 action: "NETWORK_ACL_REMOVERULE" options: position: 0 - 29: + 53: # old action num: 29 action: "NETWORK_ACL_REMOVERULE" options: position: 1 - 30: + 54: # old action num: 30 action: "NETWORK_ACL_REMOVERULE" options: position: 2 - 31: + 55: # old action num: 31 action: "NETWORK_ACL_REMOVERULE" options: position: 3 - 32: + 56: # old action num: 32 action: "NETWORK_ACL_REMOVERULE" options: position: 4 - 33: + 57: # old action num: 33 action: "NETWORK_ACL_REMOVERULE" options: position: 5 - 34: + 58: # old action num: 34 action: "NETWORK_ACL_REMOVERULE" options: position: 6 - 35: + 59: # old action num: 35 action: "NETWORK_ACL_REMOVERULE" options: position: 7 - 36: + 60: # old action num: 36 action: "NETWORK_ACL_REMOVERULE" options: position: 8 - 37: + 61: # old action num: 37 action: "NETWORK_ACL_REMOVERULE" options: position: 9 - 38: + 62: # old action num: 38 action: "NETWORK_NIC_DISABLE" options: node_id: 0 nic_id: 0 - 39: + 63: # old action num: 39 action: "NETWORK_NIC_ENABLE" options: node_id: 0 nic_id: 0 - 40: + 64: # old action num: 40 action: "NETWORK_NIC_DISABLE" options: node_id: 1 nic_id: 0 - 41: + 65: # old action num: 41 action: "NETWORK_NIC_ENABLE" options: node_id: 1 nic_id: 0 - 42: + 66: # old action num: 42 action: "NETWORK_NIC_DISABLE" options: node_id: 2 nic_id: 0 - 43: + 67: # old action num: 43 action: "NETWORK_NIC_ENABLE" options: node_id: 2 nic_id: 0 - 44: + 68: # old action num: 44 action: "NETWORK_NIC_DISABLE" options: node_id: 3 nic_id: 0 - 45: + 69: # old action num: 45 action: "NETWORK_NIC_ENABLE" options: node_id: 3 nic_id: 0 - 46: + 70: # old action num: 46 action: "NETWORK_NIC_DISABLE" options: node_id: 4 nic_id: 0 - 47: + 71: # old action num: 47 action: "NETWORK_NIC_ENABLE" options: node_id: 4 nic_id: 0 - 48: + 72: # old action num: 48 action: "NETWORK_NIC_DISABLE" options: node_id: 4 nic_id: 1 - 49: + 73: # old action num: 49 action: "NETWORK_NIC_ENABLE" options: node_id: 4 nic_id: 1 - 50: + 74: # old action num: 50 action: "NETWORK_NIC_DISABLE" options: node_id: 5 nic_id: 0 - 51: + 75: # old action num: 51 action: "NETWORK_NIC_ENABLE" options: node_id: 5 nic_id: 0 - 52: + 76: # old action num: 52 action: "NETWORK_NIC_DISABLE" options: node_id: 6 nic_id: 0 - 53: + 77: # old action num: 53 action: "NETWORK_NIC_ENABLE" options: node_id: 6 @@ -694,99 +791,196 @@ agents: 3: action: "NODE_SERVICE_START" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 4: action: "NODE_SERVICE_PAUSE" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 5: action: "NODE_SERVICE_RESUME" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 6: action: "NODE_SERVICE_RESTART" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 7: action: "NODE_SERVICE_DISABLE" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 8: action: "NODE_SERVICE_ENABLE" options: - node_id: 1 - service_id: 0 + node_id: 1 + service_id: 0 9: # check database.db file action: "NODE_FILE_SCAN" options: - node_id: 2 - folder_id: 0 - file_id: 0 + node_id: 2 + folder_id: 0 + file_id: 0 10: action: "NODE_FILE_CHECKHASH" options: - node_id: 2 - folder_id: 0 - file_id: 0 + node_id: 2 + folder_id: 0 + file_id: 0 11: action: "NODE_FILE_DELETE" options: - node_id: 2 - folder_id: 0 - file_id: 0 + node_id: 2 + folder_id: 0 + file_id: 0 12: action: "NODE_FILE_REPAIR" options: - node_id: 2 - folder_id: 0 - file_id: 0 + node_id: 2 + folder_id: 0 + file_id: 0 13: action: "NODE_SERVICE_PATCH" options: - node_id: 2 - service_id: 0 + node_id: 2 + service_id: 0 14: action: "NODE_FOLDER_SCAN" options: - node_id: 2 - folder_id: 0 + node_id: 2 + folder_id: 0 15: action: "NODE_FOLDER_CHECKHASH" options: - node_id: 2 - folder_id: 0 + node_id: 2 + folder_id: 0 16: action: "NODE_FOLDER_REPAIR" options: - node_id: 2 - folder_id: 0 + node_id: 2 + folder_id: 0 17: action: "NODE_FOLDER_RESTORE" options: - node_id: 2 - folder_id: 0 + node_id: 2 + folder_id: 0 18: action: "NODE_OS_SCAN" options: - node_id: 2 - 19: # shutdown client 1 + node_id: 0 + 19: action: "NODE_SHUTDOWN" options: - node_id: 5 + node_id: 0 20: - action: "NODE_STARTUP" + action: NODE_STARTUP options: - node_id: 5 + node_id: 0 21: - action: "NODE_RESET" + action: NODE_RESET options: - node_id: 5 - 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" + node_id: 0 + 22: + action: "NODE_OS_SCAN" + options: + node_id: 1 + 23: + action: "NODE_SHUTDOWN" + options: + node_id: 1 + 24: + action: NODE_STARTUP + options: + node_id: 1 + 25: + action: NODE_RESET + options: + node_id: 1 + 26: # old action num: 18 + action: "NODE_OS_SCAN" + options: + node_id: 2 + 27: + action: "NODE_SHUTDOWN" + options: + node_id: 2 + 28: + action: NODE_STARTUP + options: + node_id: 2 + 29: + action: NODE_RESET + options: + node_id: 2 + 30: + action: "NODE_OS_SCAN" + options: + node_id: 3 + 31: + action: "NODE_SHUTDOWN" + options: + node_id: 3 + 32: + action: NODE_STARTUP + options: + node_id: 3 + 33: + action: NODE_RESET + options: + node_id: 3 + 34: + action: "NODE_OS_SCAN" + options: + node_id: 4 + 35: + action: "NODE_SHUTDOWN" + options: + node_id: 4 + 36: + action: NODE_STARTUP + options: + node_id: 4 + 37: + action: NODE_RESET + options: + node_id: 4 + 38: + action: "NODE_OS_SCAN" + options: + node_id: 5 + 39: # old action num: 19 # shutdown client 1 + action: "NODE_SHUTDOWN" + options: + node_id: 5 + 40: # old action num: 20 + action: NODE_STARTUP + options: + node_id: 5 + 41: # old action num: 21 + action: NODE_RESET + options: + node_id: 5 + 42: + action: "NODE_OS_SCAN" + options: + node_id: 6 + 43: + action: "NODE_SHUTDOWN" + options: + node_id: 6 + 44: + action: NODE_STARTUP + options: + node_id: 6 + 45: + action: NODE_RESET + options: + node_id: 6 + + 46: # old action num: 22 # "ACL: ADDRULE - Block outgoing traffic from client 1" action: "NETWORK_ACL_ADDRULE" options: position: 1 @@ -796,7 +990,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" + 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" action: "NETWORK_ACL_ADDRULE" options: position: 2 @@ -806,7 +1000,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 - 24: # block tcp traffic from client 1 to web app + 48: # old action num: 24 # block tcp traffic from client 1 to web app action: "NETWORK_ACL_ADDRULE" options: position: 3 @@ -816,7 +1010,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 25: # block tcp traffic from client 2 to web app + 49: # old action num: 25 # block tcp traffic from client 2 to web app action: "NETWORK_ACL_ADDRULE" options: position: 4 @@ -826,7 +1020,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 26: + 50: # old action num: 26 action: "NETWORK_ACL_ADDRULE" options: position: 5 @@ -836,7 +1030,7 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 27: + 51: # old action num: 27 action: "NETWORK_ACL_ADDRULE" options: position: 6 @@ -846,128 +1040,129 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 - 28: + 52: # old action num: 28 action: "NETWORK_ACL_REMOVERULE" options: position: 0 - 29: + 53: # old action num: 29 action: "NETWORK_ACL_REMOVERULE" options: position: 1 - 30: + 54: # old action num: 30 action: "NETWORK_ACL_REMOVERULE" options: position: 2 - 31: + 55: # old action num: 31 action: "NETWORK_ACL_REMOVERULE" options: position: 3 - 32: + 56: # old action num: 32 action: "NETWORK_ACL_REMOVERULE" options: position: 4 - 33: + 57: # old action num: 33 action: "NETWORK_ACL_REMOVERULE" options: position: 5 - 34: + 58: # old action num: 34 action: "NETWORK_ACL_REMOVERULE" options: position: 6 - 35: + 59: # old action num: 35 action: "NETWORK_ACL_REMOVERULE" options: position: 7 - 36: + 60: # old action num: 36 action: "NETWORK_ACL_REMOVERULE" options: position: 8 - 37: + 61: # old action num: 37 action: "NETWORK_ACL_REMOVERULE" options: position: 9 - 38: + 62: # old action num: 38 action: "NETWORK_NIC_DISABLE" options: node_id: 0 nic_id: 0 - 39: + 63: # old action num: 39 action: "NETWORK_NIC_ENABLE" options: node_id: 0 nic_id: 0 - 40: + 64: # old action num: 40 action: "NETWORK_NIC_DISABLE" options: node_id: 1 nic_id: 0 - 41: + 65: # old action num: 41 action: "NETWORK_NIC_ENABLE" options: node_id: 1 nic_id: 0 - 42: + 66: # old action num: 42 action: "NETWORK_NIC_DISABLE" options: node_id: 2 nic_id: 0 - 43: + 67: # old action num: 43 action: "NETWORK_NIC_ENABLE" options: node_id: 2 nic_id: 0 - 44: + 68: # old action num: 44 action: "NETWORK_NIC_DISABLE" options: node_id: 3 nic_id: 0 - 45: + 69: # old action num: 45 action: "NETWORK_NIC_ENABLE" options: node_id: 3 nic_id: 0 - 46: + 70: # old action num: 46 action: "NETWORK_NIC_DISABLE" options: node_id: 4 nic_id: 0 - 47: + 71: # old action num: 47 action: "NETWORK_NIC_ENABLE" options: node_id: 4 nic_id: 0 - 48: + 72: # old action num: 48 action: "NETWORK_NIC_DISABLE" options: node_id: 4 nic_id: 1 - 49: + 73: # old action num: 49 action: "NETWORK_NIC_ENABLE" options: node_id: 4 nic_id: 1 - 50: + 74: # old action num: 50 action: "NETWORK_NIC_DISABLE" options: node_id: 5 nic_id: 0 - 51: + 75: # old action num: 51 action: "NETWORK_NIC_ENABLE" options: node_id: 5 nic_id: 0 - 52: + 76: # old action num: 52 action: "NETWORK_NIC_DISABLE" options: node_id: 6 nic_id: 0 - 53: + 77: # old action num: 53 action: "NETWORK_NIC_ENABLE" options: node_id: 6 nic_id: 0 + options: nodes: - node_name: domain_controller From 0d490d618cb70b9a194c041af09c2f8643d023f9 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 3 Mar 2024 16:59:14 +0000 Subject: [PATCH 668/980] Update MARL config --- .../example_config_2_rl_agents.yaml | 96 +++++++++++++++---- 1 file changed, 78 insertions(+), 18 deletions(-) diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index fd5a3092..e8f271df 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -36,6 +36,11 @@ agents: - ref: client_2_green_user team: GREEN type: probabilistic_agent + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 observation_space: type: UC2GreenObservation action_space: @@ -47,24 +52,38 @@ agents: - node_name: client_2 applications: - application_name: WebBrowser + - application_name: DatabaseClient max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 - max_applications_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 reward_function: reward_components: - type: DUMMY - agent_settings: - start_settings: - start_step: 5 - frequency: 4 - variance: 3 - - ref: client_1_green_user team: GREEN type: probabilistic_agent + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 observation_space: type: UC2GreenObservation action_space: @@ -76,10 +95,26 @@ agents: - node_name: client_1 applications: - application_name: WebBrowser + - application_name: DatabaseClient max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 - max_applications_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 + reward_function: reward_components: - type: DUMMY @@ -87,6 +122,7 @@ agents: + - ref: data_manipulation_attacker team: RED type: RedDatabaseCorruptingAgent @@ -671,6 +707,14 @@ agents: weight: 0.33 options: node_hostname: client_2 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.1 + options: + node_hostname: client_1 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.1 + options: + node_hostname: client_2 agent_settings: @@ -1223,6 +1267,14 @@ agents: weight: 0.33 options: node_hostname: client_2 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.1 + options: + node_hostname: client_1 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.1 + options: + node_hostname: client_2 agent_settings: @@ -1241,8 +1293,8 @@ simulation: nodes: - ref: router_1 - type: router hostname: router_1 + type: router num_ports: 5 ports: 1: @@ -1277,18 +1329,18 @@ simulation: protocol: ICMP - ref: switch_1 - type: switch hostname: switch_1 + type: switch num_ports: 8 - ref: switch_2 - type: switch hostname: switch_2 + type: switch num_ports: 8 - ref: domain_controller - type: server hostname: domain_controller + type: server ip_address: 192.168.1.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -1300,8 +1352,8 @@ simulation: arcd.com: 192.168.1.12 # web server - ref: web_server - type: server hostname: web_server + type: server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -1317,8 +1369,8 @@ simulation: - ref: database_server - type: server hostname: database_server + type: server ip_address: 192.168.1.14 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -1332,8 +1384,8 @@ simulation: type: FTPClient - ref: backup_server - type: server hostname: backup_server + type: server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -1343,8 +1395,8 @@ simulation: type: FTPServer - ref: security_suite - type: server hostname: security_suite + type: server ip_address: 192.168.1.110 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -1355,8 +1407,8 @@ simulation: subnet_mask: 255.255.255.0 - ref: client_1 - type: computer hostname: client_1 + type: computer ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 @@ -1373,13 +1425,17 @@ simulation: type: WebBrowser options: target_url: http://arcd.com/users/ + - ref: client_1_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 services: - ref: client_1_dns_client type: DNSClient - ref: client_2 - type: computer hostname: client_2 + type: computer ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 @@ -1396,6 +1452,10 @@ simulation: data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 + - ref: client_2_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 services: - ref: client_2_dns_client type: DNSClient From d1480e4477f42f46a99776711f80c3a71ee90934 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Mar 2024 09:58:57 +0000 Subject: [PATCH 669/980] Apply suggestions from PR review. --- docs/source/configuration/agents.rst | 6 +++--- .../system/services/database_service.rst | 7 +++++++ src/primaite/config/_package_data/example_config.yaml | 4 ++-- .../config/_package_data/example_config_2_rl_agents.yaml | 4 ++-- src/primaite/game/game.py | 2 +- .../simulator/network/transmission/network_layer.py | 2 +- .../applications/red_applications/data_manipulation_bot.py | 2 -- tests/assets/configs/bad_primaite_session.yaml | 2 +- tests/assets/configs/basic_firewall.yaml | 2 +- tests/assets/configs/basic_switched_network.yaml | 2 +- tests/assets/configs/dmz_network.yaml | 2 +- tests/assets/configs/eval_only_primaite_session.yaml | 2 +- tests/assets/configs/multi_agent_session.yaml | 2 +- tests/assets/configs/test_primaite_session.yaml | 2 +- tests/assets/configs/train_only_primaite_session.yaml | 2 +- tests/integration_tests/game_layer/test_rewards.py | 1 + 16 files changed, 25 insertions(+), 19 deletions(-) diff --git a/docs/source/configuration/agents.rst b/docs/source/configuration/agents.rst index ac67c365..b8912883 100644 --- a/docs/source/configuration/agents.rst +++ b/docs/source/configuration/agents.rst @@ -19,7 +19,7 @@ Agents can be scripted (deterministic and stochastic), or controlled by a reinfo ... - ref: green_agent_example team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent observation_space: type: UC2GreenObservation action_space: @@ -57,11 +57,11 @@ Specifies if the agent is malicious (``RED``), benign (``GREEN``), or defensive ``type`` -------- -Specifies which class should be used for the agent. ``ProxyAgent`` is used for agents that receive instructions from an RL algorithm. Scripted agents like ``RedDatabaseCorruptingAgent`` and ``probabilistic_agent`` generate their own behaviour. +Specifies which class should be used for the agent. ``ProxyAgent`` is used for agents that receive instructions from an RL algorithm. Scripted agents like ``RedDatabaseCorruptingAgent`` and ``ProbabilisticAgent`` generate their own behaviour. Available agent types: -- ``probabilistic_agent`` +- ``ProbabilisticAgent`` - ``ProxyAgent`` - ``RedDatabaseCorruptingAgent`` diff --git a/docs/source/simulation_components/system/services/database_service.rst b/docs/source/simulation_components/system/services/database_service.rst index 2c962c0a..dd6dec41 100644 --- a/docs/source/simulation_components/system/services/database_service.rst +++ b/docs/source/simulation_components/system/services/database_service.rst @@ -25,6 +25,13 @@ Usage - Clients connect, execute queries, and disconnect. - Service runs on TCP port 5432 by default. +**Supported queries:** + +* ``SELECT``: As long as the database file is in a ``GOOD`` health state, the db service will respond with a 200 status code. +* ``DELETE``: This query represents an attack, it will cause the database file to enter a ``COMPROMISED`` state, and return a status code 200. +* ``INSERT``: If the database service is in a healthy state, this will return a 200 status, if it's not in a healthy state it will return 404. +* ``SELECT * FROM pg_stat_activity``: This query represents something an admin would send to check the status of the database. If the database service is in a healthy state, it returns a 200 status code, otherwise a 401 status code. + Implementation ============== diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 45d29b48..8d1b4293 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -33,7 +33,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent agent_settings: action_probabilities: 0: 0.3 @@ -76,7 +76,7 @@ agents: - ref: client_1_green_user team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent agent_settings: action_probabilities: 0: 0.3 diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index b6b07afa..260517b9 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -35,7 +35,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent observation_space: type: UC2GreenObservation action_space: @@ -64,7 +64,7 @@ agents: - ref: client_1_green_user team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent observation_space: type: UC2GreenObservation action_space: diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index bfbefd3c..0749e5db 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -414,7 +414,7 @@ class PrimaiteGame: reward_function = RewardFunction.from_config(reward_function_cfg) # CREATE AGENT - if agent_type == "probabilistic_agent": + if agent_type == "ProbabilisticAgent": # TODO: implement non-random agents and fix this parsing settings = agent_cfg.get("agent_settings") new_agent = ProbabilisticAgent( diff --git a/src/primaite/simulator/network/transmission/network_layer.py b/src/primaite/simulator/network/transmission/network_layer.py index 22d7f97d..8ee0b4af 100644 --- a/src/primaite/simulator/network/transmission/network_layer.py +++ b/src/primaite/simulator/network/transmission/network_layer.py @@ -16,7 +16,7 @@ class IPProtocol(Enum): """ NONE = "none" - """Placeholder for a non-port.""" + """Placeholder for a non-protocol.""" TCP = "tcp" """Transmission Control Protocol.""" UDP = "udp" diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index 961f82c2..ee98ea8e 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -38,9 +38,7 @@ class DataManipulationAttackStage(IntEnum): class DataManipulationBot(Application): """A bot that simulates a script which performs a SQL injection attack.""" - # server_ip_address: Optional[IPv4Address] = None payload: Optional[str] = None - # server_password: Optional[str] = None port_scan_p_of_success: float = 0.1 data_manipulation_p_of_success: float = 0.1 diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 017492ad..38d54ce3 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -21,7 +21,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/assets/configs/basic_firewall.yaml b/tests/assets/configs/basic_firewall.yaml index 0a892650..9d7b34cb 100644 --- a/tests/assets/configs/basic_firewall.yaml +++ b/tests/assets/configs/basic_firewall.yaml @@ -40,7 +40,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 6c6b2845..9a0d5313 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -40,7 +40,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/assets/configs/dmz_network.yaml b/tests/assets/configs/dmz_network.yaml index 56a68410..95e09e16 100644 --- a/tests/assets/configs/dmz_network.yaml +++ b/tests/assets/configs/dmz_network.yaml @@ -65,7 +65,7 @@ game: agents: - ref: client_1_green_user team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index e70814f5..f2815578 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -25,7 +25,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 6401bcda..8bbddb76 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -31,7 +31,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index c2616001..199cf8cc 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -29,7 +29,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index 8ef4b8fd..71a23989 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -25,7 +25,7 @@ game: agents: - ref: client_2_green_user team: GREEN - type: probabilistic_agent + type: ProbabilisticAgent observation_space: type: UC2GreenObservation action_space: diff --git a/tests/integration_tests/game_layer/test_rewards.py b/tests/integration_tests/game_layer/test_rewards.py index 53753967..8edbf0ac 100644 --- a/tests/integration_tests/game_layer/test_rewards.py +++ b/tests/integration_tests/game_layer/test_rewards.py @@ -41,6 +41,7 @@ def test_WebpageUnavailablePenalty(game_and_agent): def test_uc2_rewards(game_and_agent): + """Test that the reward component correctly applies a penalty when the selected client cannot reach the database.""" game, agent = game_and_agent agent: ControlledAgent From ac9d550e9b2f3ff48a5f93f5612f34395dba9a6d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Mar 2024 10:43:38 +0000 Subject: [PATCH 670/980] Change get_action signature for agents --- .../game/agent/data_manipulation_bot.py | 14 ++++++------- src/primaite/game/agent/interface.py | 20 +++++++++---------- src/primaite/game/agent/rewards.py | 2 +- src/primaite/game/agent/scripted_agents.py | 12 +++++------ src/primaite/game/game.py | 3 +-- tests/conftest.py | 2 +- .../_game/_agent/test_probabilistic_agent.py | 2 +- 7 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/primaite/game/agent/data_manipulation_bot.py b/src/primaite/game/agent/data_manipulation_bot.py index b5de9a5a..c758c926 100644 --- a/src/primaite/game/agent/data_manipulation_bot.py +++ b/src/primaite/game/agent/data_manipulation_bot.py @@ -1,5 +1,5 @@ import random -from typing import Dict, Optional, Tuple +from typing import Dict, Tuple from gymnasium.core import ObsType @@ -26,14 +26,14 @@ class DataManipulationAgent(AbstractScriptedAgent): ) self.next_execution_timestep = timestep + random_timestep_increment - def get_action(self, obs: ObsType, reward: float = 0.0, timestep: Optional[int] = None) -> Tuple[str, Dict]: - """Randomly sample an action from the action space. + def get_action(self, obs: ObsType, timestep: int) -> Tuple[str, Dict]: + """Waits until a specific timestep, then attempts to execute its data manipulation application. - :param obs: _description_ + :param obs: Current observation for this agent, not used in DataManipulationAgent :type obs: ObsType - :param reward: _description_, defaults to None - :type reward: float, optional - :return: _description_ + :param timestep: The current simulation timestep, used for scheduling actions + :type timestep: int + :return: Action formatted in CAOS format :rtype: Tuple[str, Dict] """ if timestep < self.next_execution_timestep: diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 4f434bad..88848479 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -112,7 +112,7 @@ class AbstractAgent(ABC): return self.reward_function.update(state) @abstractmethod - def get_action(self, obs: ObsType, reward: float = 0.0, timestep: Optional[int] = None) -> Tuple[str, Dict]: + def get_action(self, obs: ObsType, timestep: int = 0) -> Tuple[str, Dict]: """ Return an action to be taken in the environment. @@ -152,14 +152,14 @@ class AbstractScriptedAgent(AbstractAgent): class RandomAgent(AbstractScriptedAgent): """Agent that ignores its observation and acts completely at random.""" - def get_action(self, obs: ObsType, reward: float = 0.0, timestep: Optional[int] = None) -> Tuple[str, Dict]: - """Randomly sample an action from the action space. + def get_action(self, obs: ObsType, timestep: int = 0) -> Tuple[str, Dict]: + """Sample the action space randomly. - :param obs: _description_ + :param obs: Current observation for this agent, not used in RandomAgent :type obs: ObsType - :param reward: _description_, defaults to None - :type reward: float, optional - :return: _description_ + :param timestep: The current simulation timestep, not used in RandomAgent + :type timestep: int + :return: Action formatted in CAOS format :rtype: Tuple[str, Dict] """ return self.action_manager.get_action(self.action_manager.space.sample()) @@ -185,14 +185,14 @@ class ProxyAgent(AbstractAgent): self.most_recent_action: ActType self.flatten_obs: bool = agent_settings.flatten_obs if agent_settings else False - def get_action(self, obs: ObsType, reward: float = 0.0, timestep: Optional[int] = None) -> Tuple[str, Dict]: + def get_action(self, obs: ObsType, timestep: int = 0) -> Tuple[str, Dict]: """ Return the agent's most recent action, formatted in CAOS format. :param obs: Observation for the agent. Not used by ProxyAgents, but required by the interface. :type obs: ObsType - :param reward: Reward value for the agent. Not used by ProxyAgents, defaults to None. - :type reward: float, optional + :param timestep: Current simulation timestep. Not used by ProxyAgents, bur required for the interface. + :type timestep: int :return: Action to be taken in CAOS format. :rtype: Tuple[str, Dict] """ diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 882ad024..8c8e36ad 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -270,7 +270,7 @@ class GreenAdminDatabaseUnreachablePenalty(AbstractReward): return -1.0 elif last_connection_successful is True: return 1.0 - return 0 + return 0.0 @classmethod def from_config(cls, config: Dict) -> AbstractReward: diff --git a/src/primaite/game/agent/scripted_agents.py b/src/primaite/game/agent/scripted_agents.py index 28d94062..5111df32 100644 --- a/src/primaite/game/agent/scripted_agents.py +++ b/src/primaite/game/agent/scripted_agents.py @@ -70,17 +70,17 @@ class ProbabilisticAgent(AbstractScriptedAgent): super().__init__(agent_name, action_space, observation_space, reward_function) - def get_action(self, obs: ObsType, reward: float = 0.0, timestep: Optional[int] = None) -> Tuple[str, Dict]: + def get_action(self, obs: ObsType, timestep: int = 0) -> Tuple[str, Dict]: """ - Choose a random action from the action space. + Sample the action space randomly. The probability of each action is given by the corresponding index in ``self.probabilities``. - :param obs: Current observation of the simulation + :param obs: Current observation for this agent, not used in ProbabilisticAgent :type obs: ObsType - :param reward: Reward for the last step, not used for scripted agents, defaults to 0 - :type reward: float, optional - :return: Action to be taken in CAOS format. + :param timestep: The current simulation timestep, not used in ProbabilisticAgent + :type timestep: int + :return: Action formatted in CAOS format :rtype: Tuple[str, Dict] """ choice = self.rng.choice(len(self.action_manager.action_map), p=self.probabilities) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 0749e5db..cd88d832 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -165,8 +165,7 @@ class PrimaiteGame: agent_actions = {} for _, agent in self.agents.items(): obs = agent.observation_manager.current_observation - rew = agent.reward_function.current_reward - action_choice, options = agent.get_action(obs, rew, timestep=self.step_counter) + action_choice, options = agent.get_action(obs, timestep=self.step_counter) agent_actions[agent.agent_name] = (action_choice, options) request = agent.format_request(action_choice, options) self.simulation.apply_request(request) diff --git a/tests/conftest.py b/tests/conftest.py index b60de730..a117a1ef 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -328,7 +328,7 @@ class ControlledAgent(AbstractAgent): ) self.most_recent_action: Tuple[str, Dict] - def get_action(self, obs: None, reward: float = 0.0, timestep: Optional[int] = None) -> Tuple[str, Dict]: + def get_action(self, obs: None, timestep: int = 0) -> Tuple[str, Dict]: """Return the agent's most recent action, formatted in CAOS format.""" return self.most_recent_action diff --git a/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py b/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py index f0b37cac..73228e36 100644 --- a/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py +++ b/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py @@ -69,7 +69,7 @@ def test_probabilistic_agent(): node_application_execute_count = 0 node_file_delete_count = 0 for _ in range(N_TRIALS): - a = pa.get_action(0, timestep=0) + a = pa.get_action(0) if a == ("DONOTHING", {}): do_nothing_count += 1 elif a == ("NODE_APPLICATION_EXECUTE", {"node_id": 0, "application_id": 0}): From 2c3652979bfd11c6e322c256b64658ec5f404847 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Mar 2024 11:17:54 +0000 Subject: [PATCH 671/980] Add helpful error messages to action index errors --- src/primaite/game/agent/actions.py | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 392d07c6..84bd3f39 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -812,6 +812,13 @@ class ActionManager: :return: The node hostname. :rtype: str """ + if not node_idx < len(self.node_names): + msg = ( + f"Error: agent attempted to perform an action on node {node_idx}, but its action space only" + f"has {len(self.node_names)} nodes." + ) + _LOGGER.error(msg) + raise RuntimeError(msg) return self.node_names[node_idx] def get_folder_name_by_idx(self, node_idx: int, folder_idx: int) -> Optional[str]: @@ -825,6 +832,13 @@ class ActionManager: :return: The name of the folder. Or None if the node has fewer folders than the given index. :rtype: Optional[str] """ + if node_idx >= len(self.folder_names) or folder_idx >= len(self.folder_names[node_idx]): + msg = ( + f"Error: agent attempted to perform an action on node {node_idx} and folder {folder_idx}, but this" + f" is out of range for its action space. Folder on each node: {self.folder_names}" + ) + _LOGGER.error(msg) + raise RuntimeError(msg) return self.folder_names[node_idx][folder_idx] def get_file_name_by_idx(self, node_idx: int, folder_idx: int, file_idx: int) -> Optional[str]: @@ -840,6 +854,17 @@ class ActionManager: fewer files than the given index. :rtype: Optional[str] """ + if ( + node_idx >= len(self.file_names) + or folder_idx >= len(self.file_names[node_idx]) + or file_idx >= len(self.file_names[node_idx][folder_idx]) + ): + msg = ( + f"Error: agent attempted to perform an action on node {node_idx} folder {folder_idx} file {file_idx}" + f" but this is out of range for its action space. Files on each node: {self.file_names}" + ) + _LOGGER.error(msg) + raise RuntimeError(msg) return self.file_names[node_idx][folder_idx][file_idx] def get_service_name_by_idx(self, node_idx: int, service_idx: int) -> Optional[str]: @@ -852,6 +877,13 @@ class ActionManager: :return: The name of the service. Or None if the node has fewer services than the given index. :rtype: Optional[str] """ + if node_idx >= len(self.service_names) or service_idx >= len(self.service_names[node_idx]): + msg = ( + f"Error: agent attempted to perform an action on node {node_idx} and service {service_idx}, but this" + f" is out of range for its action space. Services on each node: {self.service_names}" + ) + _LOGGER.error(msg) + raise RuntimeError(msg) return self.service_names[node_idx][service_idx] def get_application_name_by_idx(self, node_idx: int, application_idx: int) -> Optional[str]: @@ -864,6 +896,13 @@ class ActionManager: :return: The name of the service. Or None if the node has fewer services than the given index. :rtype: Optional[str] """ + if node_idx >= len(self.application_names) or application_idx >= len(self.application_names[node_idx]): + msg = ( + f"Error: agent attempted to perform an action on node {node_idx} and app {application_idx}, but " + f"this is out of range for its action space. Applications on each node: {self.application_names}" + ) + _LOGGER.error(msg) + raise RuntimeError(msg) return self.application_names[node_idx][application_idx] def get_internet_protocol_by_idx(self, protocol_idx: int) -> str: @@ -874,6 +913,13 @@ class ActionManager: :return: The protocol. :rtype: str """ + if protocol_idx >= len(self.protocols): + msg = ( + f"Error: agent attempted to perform an action on protocol {protocol_idx} but this" + f" is out of range for its action space. Protocols: {self.protocols}" + ) + _LOGGER.error(msg) + raise RuntimeError(msg) return self.protocols[protocol_idx] def get_ip_address_by_idx(self, ip_idx: int) -> str: @@ -885,6 +931,13 @@ class ActionManager: :return: The IP address. :rtype: str """ + if ip_idx >= len(self.ip_address_list): + msg = ( + f"Error: agent attempted to perform an action on ip address {ip_idx} but this" + f" is out of range for its action space. IP address list: {self.ip_address_list}" + ) + _LOGGER.error(msg) + raise RuntimeError(msg) return self.ip_address_list[ip_idx] def get_port_by_idx(self, port_idx: int) -> str: @@ -896,6 +949,13 @@ class ActionManager: :return: The port. :rtype: str """ + if port_idx >= len(self.ports): + msg = ( + f"Error: agent attempted to perform an action on port {port_idx} but this" + f" is out of range for its action space. Port list: {self.ip_address_list}" + ) + _LOGGER.error(msg) + raise RuntimeError(msg) return self.ports[port_idx] def get_nic_num_by_idx(self, node_idx: int, nic_idx: int) -> int: From 2f456e7ae07660b6f9382f951cb59fe9b066fe31 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Mar 2024 18:47:50 +0000 Subject: [PATCH 672/980] Move IO to environments from session and add agent logging --- .../config/_package_data/example_config.yaml | 1 + .../example_config_2_rl_agents.yaml | 81 ++++++++++--- .../game/agent/data_manipulation_bot.py | 2 +- src/primaite/game/game.py | 7 +- src/primaite/session/environment.py | 28 ++++- src/primaite/session/io.py | 108 +++++++++++++----- src/primaite/session/policy/sb3.py | 4 +- src/primaite/session/session.py | 16 ++- 8 files changed, 183 insertions(+), 64 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index 8d1b4293..77296529 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -13,6 +13,7 @@ training_config: io_settings: save_checkpoints: true checkpoint_interval: 5 + save_agent_actions: true save_step_metadata: false save_pcap_logs: false save_sys_logs: true diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index 260517b9..a5a1d08f 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -15,6 +15,7 @@ training_config: io_settings: save_checkpoints: true checkpoint_interval: 5 + save_agent_actions: true save_step_metadata: false save_pcap_logs: false save_sys_logs: true @@ -36,6 +37,11 @@ agents: - ref: client_2_green_user team: GREEN type: ProbabilisticAgent + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 observation_space: type: UC2GreenObservation action_space: @@ -47,24 +53,38 @@ agents: - node_name: client_2 applications: - application_name: WebBrowser + - application_name: DatabaseClient max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 - max_applications_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 reward_function: reward_components: - type: DUMMY - agent_settings: - start_settings: - start_step: 5 - frequency: 4 - variance: 3 - - ref: client_1_green_user team: GREEN type: ProbabilisticAgent + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 observation_space: type: UC2GreenObservation action_space: @@ -76,10 +96,26 @@ agents: - node_name: client_1 applications: - application_name: WebBrowser + - application_name: DatabaseClient max_folders_per_node: 1 max_files_per_folder: 1 max_services_per_node: 1 - max_applications_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 + reward_function: reward_components: - type: DUMMY @@ -1036,7 +1072,6 @@ agents: - simulation: network: nmne_config: @@ -1046,8 +1081,8 @@ simulation: nodes: - ref: router_1 - type: router hostname: router_1 + type: router num_ports: 5 ports: 1: @@ -1082,18 +1117,18 @@ simulation: protocol: ICMP - ref: switch_1 - type: switch hostname: switch_1 + type: switch num_ports: 8 - ref: switch_2 - type: switch hostname: switch_2 + type: switch num_ports: 8 - ref: domain_controller - type: server hostname: domain_controller + type: server ip_address: 192.168.1.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -1105,8 +1140,8 @@ simulation: arcd.com: 192.168.1.12 # web server - ref: web_server - type: server hostname: web_server + type: server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -1122,8 +1157,8 @@ simulation: - ref: database_server - type: server hostname: database_server + type: server ip_address: 192.168.1.14 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -1137,8 +1172,8 @@ simulation: type: FTPClient - ref: backup_server - type: server hostname: backup_server + type: server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -1148,8 +1183,8 @@ simulation: type: FTPServer - ref: security_suite - type: server hostname: security_suite + type: server ip_address: 192.168.1.110 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 @@ -1160,8 +1195,8 @@ simulation: subnet_mask: 255.255.255.0 - ref: client_1 - type: computer hostname: client_1 + type: computer ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 @@ -1178,13 +1213,17 @@ simulation: type: WebBrowser options: target_url: http://arcd.com/users/ + - ref: client_1_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 services: - ref: client_1_dns_client type: DNSClient - ref: client_2 - type: computer hostname: client_2 + type: computer ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 @@ -1201,6 +1240,10 @@ simulation: data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 + - ref: client_2_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 services: - ref: client_2_dns_client type: DNSClient diff --git a/src/primaite/game/agent/data_manipulation_bot.py b/src/primaite/game/agent/data_manipulation_bot.py index c758c926..16453433 100644 --- a/src/primaite/game/agent/data_manipulation_bot.py +++ b/src/primaite/game/agent/data_manipulation_bot.py @@ -37,7 +37,7 @@ class DataManipulationAgent(AbstractScriptedAgent): :rtype: Tuple[str, Dict] """ if timestep < self.next_execution_timestep: - return "DONOTHING", {"dummy": 0} + return "DONOTHING", {} self._set_next_execution_timestep(timestep + self.agent_settings.start_settings.frequency) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index cd88d832..394a8154 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -11,7 +11,6 @@ from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAge from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction from primaite.game.agent.scripted_agents import ProbabilisticAgent -from primaite.session.io import SessionIO, SessionIOSettings from primaite.simulator.network.hardware.base import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC @@ -210,10 +209,6 @@ class PrimaiteGame: :return: A PrimaiteGame object. :rtype: PrimaiteGame """ - io_settings = cfg.get("io_settings", {}) - _ = SessionIO(SessionIOSettings(**io_settings)) - # Instantiating this ensures that the game saves to the correct output dir even without being part of a session - game = cls() game.options = PrimaiteGameOptions(**cfg["game"]) game.save_step_metadata = cfg.get("io_settings", {}).get("save_step_metadata") or False @@ -415,7 +410,7 @@ class PrimaiteGame: # CREATE AGENT if agent_type == "ProbabilisticAgent": # TODO: implement non-random agents and fix this parsing - settings = agent_cfg.get("agent_settings") + settings = agent_cfg.get("agent_settings", {}) new_agent = ProbabilisticAgent( agent_name=agent_cfg["ref"], action_space=action_space, diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index d54503a3..72d5ac9c 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -8,6 +8,7 @@ from ray.rllib.env.multi_agent_env import MultiAgentEnv from primaite.game.agent.interface import ProxyAgent from primaite.game.game import PrimaiteGame +from primaite.session.io import PrimaiteIO from primaite.simulator import SIM_OUTPUT @@ -32,6 +33,9 @@ class PrimaiteGymEnv(gymnasium.Env): self.episode_counter: int = 0 """Current episode number.""" + self.io = PrimaiteIO.from_config(game_config.get("io_settings", {})) + """Handles IO for the environment. This produces sys logs, agent logs, etc.""" + @property def agent(self) -> ProxyAgent: """Grab a fresh reference to the agent object because it will be reinstantiated each episode.""" @@ -55,6 +59,10 @@ class PrimaiteGymEnv(gymnasium.Env): info = {"agent_actions": agent_actions} # tell us what all the agents did for convenience. if self.game.save_step_metadata: self._write_step_metadata_json(action, state, reward) + if self.io.settings.save_agent_actions: + self.io.store_agent_actions( + agent_actions=agent_actions, episode=self.episode_counter, timestep=self.game.step_counter + ) return next_obs, reward, terminated, truncated, info def _write_step_metadata_json(self, action: int, state: Dict, reward: int): @@ -79,6 +87,9 @@ class PrimaiteGymEnv(gymnasium.Env): f"Resetting environment, episode {self.episode_counter}, " f"avg. reward: {self.agent.reward_function.total_reward}" ) + if self.io.settings.save_agent_actions: + self.io.write_agent_actions(episode=self.episode_counter) + self.io.clear_agent_actions() self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=copy.deepcopy(self.game_config)) self.game.setup_for_episode(episode=self.episode_counter) self.episode_counter += 1 @@ -146,7 +157,7 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): """ self.game_config: Dict = env_config """PrimaiteGame definition. This can be changed between episodes to enable curriculum learning.""" - self.game: PrimaiteGame = PrimaiteGame.from_config(self.game_config) + self.game: PrimaiteGame = PrimaiteGame.from_config(copy.deepcopy(self.game_config)) """Reference to the primaite game""" self._agent_ids = list(self.game.rl_agents.keys()) """Agent ids. This is a list of strings of agent names.""" @@ -164,6 +175,10 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): self.action_space = gymnasium.spaces.Dict( {name: agent.action_manager.space for name, agent in self.agents.items()} ) + + self.io = PrimaiteIO.from_config(env_config.get("io_settings")) + """Handles IO for the environment. This produces sys logs, agent logs, etc.""" + super().__init__() @property @@ -173,7 +188,10 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): def reset(self, *, seed: int = None, options: dict = None) -> Tuple[ObsType, Dict]: """Reset the environment.""" - self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=self.game_config) + if self.io.settings.save_agent_actions: + self.io.write_agent_actions(episode=self.episode_counter) + self.io.clear_agent_actions() + self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=copy.deepcopy(self.game_config)) self.game.setup_for_episode(episode=self.episode_counter) self.episode_counter += 1 state = self.game.get_sim_state() @@ -196,7 +214,7 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): # 1. Perform actions for agent_name, action in actions.items(): self.agents[agent_name].store_action(action) - self.game.apply_agent_actions() + agent_actions = self.game.apply_agent_actions() # 2. Advance timestep self.game.advance_timestep() @@ -215,6 +233,10 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): truncateds["__all__"] = self.game.calculate_truncated() if self.game.save_step_metadata: self._write_step_metadata_json(actions, state, rewards) + if self.io.settings.save_agent_actions: + self.io.store_agent_actions( + agent_actions=agent_actions, episode=self.episode_counter, timestep=self.game.step_counter + ) return next_obs, rewards, terminateds, truncateds, infos def _write_step_metadata_json(self, actions: Dict, state: Dict, rewards: Dict): diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index b4b740e9..22d9dbeb 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -1,53 +1,50 @@ +import json from datetime import datetime from pathlib import Path -from typing import Optional +from typing import Dict, List, Optional from pydantic import BaseModel, ConfigDict -from primaite import PRIMAITE_PATHS +from primaite import getLogger, PRIMAITE_PATHS from primaite.simulator import SIM_OUTPUT - -class SessionIOSettings(BaseModel): - """Schema for session IO settings.""" - - model_config = ConfigDict(extra="forbid") - - save_final_model: bool = True - """Whether to save the final model right at the end of training.""" - save_checkpoints: bool = False - """Whether to save a checkpoint model every `checkpoint_interval` episodes""" - checkpoint_interval: int = 10 - """How often to save a checkpoint model (if save_checkpoints is True).""" - save_logs: bool = True - """Whether to save logs""" - save_transactions: bool = True - """Whether to save transactions, If true, the session path will have a transactions folder.""" - save_tensorboard_logs: bool = False - """Whether to save tensorboard logs. If true, the session path will have a tensorboard_logs folder.""" - save_step_metadata: bool = False - """Whether to save the RL agents' action, environment state, and other data at every single step.""" - save_pcap_logs: bool = False - """Whether to save PCAP logs.""" - save_sys_logs: bool = False - """Whether to save system logs.""" +_LOGGER = getLogger(__name__) -class SessionIO: +class PrimaiteIO: """ Class for managing session IO. Currently it's handling path generation, but could expand to handle loading, transaction, tensorboard, and so on. """ - def __init__(self, settings: SessionIOSettings = SessionIOSettings()) -> None: - self.settings: SessionIOSettings = settings + class Settings(BaseModel): + """Config schema for PrimaiteIO object.""" + + model_config = ConfigDict(extra="forbid") + + save_logs: bool = True + """Whether to save logs""" + save_agent_actions: bool = True + """Whether to save a log of all agents' actions every step.""" + save_transactions: bool = True + """Whether to save transactions, If true, the session path will have a transactions folder.""" + save_step_metadata: bool = False + """Whether to save the RL agents' action, environment state, and other data at every single step.""" + save_pcap_logs: bool = False + """Whether to save PCAP logs.""" + save_sys_logs: bool = False + """Whether to save system logs.""" + + def __init__(self, settings: Optional[Settings] = None) -> None: + self.settings = settings or PrimaiteIO.Settings() self.session_path: Path = self.generate_session_path() # set global SIM_OUTPUT path SIM_OUTPUT.path = self.session_path / "simulation_output" SIM_OUTPUT.save_pcap_logs = self.settings.save_pcap_logs SIM_OUTPUT.save_sys_logs = self.settings.save_sys_logs + self.agent_action_log: List[Dict] = [] # warning TODO: must be careful not to re-initialise sessionIO because it will create a new path each time it's # possible refactor needed @@ -68,3 +65,56 @@ class SessionIO: def generate_checkpoint_save_path(self, agent_name: str, episode: int) -> Path: """Return the path where the checkpoint model will be saved (excluding filename extension).""" return self.session_path / "checkpoints" / f"{agent_name}_checkpoint_{episode}.pt" + + def generate_agent_actions_save_path(self, episode: int) -> Path: + """Return the path where agent actions will be saved.""" + return self.session_path / "agent_actions" / f"episode_{episode}.json" + + def store_agent_actions(self, agent_actions: Dict, episode: int, timestep: int) -> None: + """Cache agent actions for a particular step. + + :param agent_actions: Dictionary describing actions for any agents that acted in this timestep. The expected + format contains agent identifiers as keys. The keys should map to a tuple of [CAOS action, parameters] + CAOS action is a string representing one the CAOS actions. + parameters is a dict of parameter names and values for that particular CAOS action. + For example: + { + 'green1' : ('NODE_APPLICATION_EXECUTE', {'node_id':1, 'application_id':0}), + 'defender': ('DO_NOTHING', {}) + } + :type agent_actions: Dict + :param timestep: Simulation timestep when these actions occurred. + :type timestep: int + """ + self.agent_action_log.append( + [ + { + "episode": episode, + "timestep": timestep, + "agent_actions": {k: {"action": v[0], "parameters": v[1]} for k, v in agent_actions.items()}, + } + ] + ) + + def write_agent_actions(self, episode: int) -> None: + """Take the contents of the agent action log and write it to a file. + + :param episode: Episode number + :type episode: int + """ + path = self.generate_agent_actions_save_path(episode=episode) + path.parent.mkdir(exist_ok=True, parents=True) + path.touch() + _LOGGER.info(f"Saving agent action log to {path}") + with open(path, "w") as file: + json.dump(self.agent_action_log, fp=file, indent=1) + + def clear_agent_actions(self) -> None: + """Reset the agent action log back to an empty dictionary.""" + self.agent_action_log = [] + + @classmethod + def from_config(cls, config: Dict) -> "PrimaiteIO": + """Create an instance of PrimaiteIO based on a configuration dict.""" + new = cls() + return new diff --git a/src/primaite/session/policy/sb3.py b/src/primaite/session/policy/sb3.py index 254baf4d..6220371d 100644 --- a/src/primaite/session/policy/sb3.py +++ b/src/primaite/session/policy/sb3.py @@ -39,9 +39,9 @@ class SB3Policy(PolicyABC, identifier="SB3"): def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: """Train the agent.""" - if self.session.io_manager.settings.save_checkpoints: + if self.session.save_checkpoints: checkpoint_callback = CheckpointCallback( - save_freq=timesteps_per_episode * self.session.io_manager.settings.checkpoint_interval, + save_freq=timesteps_per_episode * self.session.checkpoint_interval, save_path=self.session.io_manager.generate_model_save_path("sb3"), name_prefix="sb3_model", ) diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py index d244f6b0..84dd9b2f 100644 --- a/src/primaite/session/session.py +++ b/src/primaite/session/session.py @@ -1,3 +1,4 @@ +# raise DeprecationWarning("This module is deprecated") from enum import Enum from pathlib import Path from typing import Dict, List, Literal, Optional, Union @@ -5,7 +6,7 @@ from typing import Dict, List, Literal, Optional, Union from pydantic import BaseModel, ConfigDict from primaite.session.environment import PrimaiteGymEnv, PrimaiteRayEnv, PrimaiteRayMARLEnv -from primaite.session.io import SessionIO, SessionIOSettings +from primaite.session.io import PrimaiteIO # from primaite.game.game import PrimaiteGame from primaite.session.policy.policy import PolicyABC @@ -53,12 +54,18 @@ class PrimaiteSession: self.policy: PolicyABC """The reinforcement learning policy.""" - self.io_manager: Optional["SessionIO"] = None + self.io_manager: Optional["PrimaiteIO"] = None """IO manager for the session.""" self.game_cfg: Dict = game_cfg """Primaite Game object for managing main simulation loop and agents.""" + self.save_checkpoints: bool = False + """Whether to save chcekpoints.""" + + self.checkpoint_interval: int = 10 + """If save_checkpoints is true, checkpoints will be saved every checkpoint_interval episodes.""" + def start_session(self) -> None: """Commence the training/eval session.""" print("Starting Primaite Session") @@ -89,12 +96,13 @@ class PrimaiteSession: def from_config(cls, cfg: Dict, agent_load_path: Optional[str] = None) -> "PrimaiteSession": """Create a PrimaiteSession object from a config dictionary.""" # READ IO SETTINGS (this sets the global session path as well) # TODO: GLOBAL SIDE EFFECTS... - io_settings = cfg.get("io_settings", {}) - io_manager = SessionIO(SessionIOSettings(**io_settings)) + io_manager = PrimaiteIO.from_config(cfg.get("io_settings", {})) sess = cls(game_cfg=cfg) sess.io_manager = io_manager sess.training_options = TrainingOptions(**cfg["training_config"]) + sess.save_checkpoints = cfg.get("io_settings", {}).get("save_checkpoints") + sess.checkpoint_interval = cfg.get("io_settings", {}).get("checkpoint_interval") # CREATE ENVIRONMENT if sess.training_options.rl_framework == "RLLIB_single_agent": From c3010ff816882e47809bd4889b2b9c15253c2ce9 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Mar 2024 18:59:03 +0000 Subject: [PATCH 673/980] Update changelog and docs --- CHANGELOG.md | 1 + docs/source/configuration/io_settings.rst | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d54af980..48998d57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed the order of service health state - Fixed an issue where starting a node didn't start the services on it - Added support for SQL INSERT command. +- Added ability to log each agent's action choices each step to a JSON file. diff --git a/docs/source/configuration/io_settings.rst b/docs/source/configuration/io_settings.rst index 96cc28fe..e5c6d2ce 100644 --- a/docs/source/configuration/io_settings.rst +++ b/docs/source/configuration/io_settings.rst @@ -19,6 +19,7 @@ This section configures how PrimAITE saves data during simulation and training. # save_logs: True # save_transactions: False # save_tensorboard_logs: False + save_agent_actions: True save_step_metadata: False save_pcap_logs: False save_sys_logs: False @@ -65,6 +66,12 @@ Defines how often to save the policy during training. *currently unused*. +``save_agent_actions`` + +Optional. Default value is ``True``. + +If ``True``, this will create a JSON file each episode detailing every agent's action each step in that episode, formatted according to the CAOS format. This includes scripted, RL, and red agents. + ``save_step_metadata`` ---------------------- From 1e8dfa40cf0214585f69834d3d6326be40799db7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Mar 2024 19:36:54 +0000 Subject: [PATCH 674/980] Give uc2 notebook a meaningful name --- .../{uc2_demo.ipynb => Data-Manipulation-E2E-Demonstration.ipynb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/primaite/notebooks/{uc2_demo.ipynb => Data-Manipulation-E2E-Demonstration.ipynb} (100%) diff --git a/src/primaite/notebooks/uc2_demo.ipynb b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb similarity index 100% rename from src/primaite/notebooks/uc2_demo.ipynb rename to src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb From a222a8c58fa8fa3b8a13043327b4211a9ed63d2b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Mar 2024 19:43:51 +0000 Subject: [PATCH 675/980] Give the UC2 config load function a meaningful name --- src/primaite/cli.py | 4 ++-- src/primaite/config/load.py | 2 +- src/primaite/main.py | 4 ++-- .../notebooks/Data-Manipulation-E2E-Demonstration.ipynb | 4 ++-- .../notebooks/training_example_ray_single_agent.ipynb | 4 ++-- src/primaite/notebooks/training_example_sb3.ipynb | 4 ++-- .../environments/test_rllib_multi_agent_environment.py | 4 ++-- .../environments/test_rllib_single_agent_environment.py | 4 ++-- .../environments/test_sb3_environment.py | 4 ++-- .../configuration_file_parsing/nodes/test_node_config.py | 4 ++-- .../software_installation_and_configuration.py | 4 ++-- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/primaite/cli.py b/src/primaite/cli.py index 81ab2792..18d21f7b 100644 --- a/src/primaite/cli.py +++ b/src/primaite/cli.py @@ -127,10 +127,10 @@ def session( :param config: The path to the config file. Optional, if None, the example config will be used. :type config: Optional[str] """ - from primaite.config.load import example_config_path + from primaite.config.load import data_manipulation_config_path from primaite.main import run if not config: - config = example_config_path() + config = data_manipulation_config_path() print(config) run(config_path=config, agent_load_path=agent_load_file) diff --git a/src/primaite/config/load.py b/src/primaite/config/load.py index b01eb129..6bd0d80d 100644 --- a/src/primaite/config/load.py +++ b/src/primaite/config/load.py @@ -30,7 +30,7 @@ def load(file_path: Union[str, Path]) -> Dict: return config -def example_config_path() -> Path: +def data_manipulation_config_path() -> Path: """ Get the path to the example config. diff --git a/src/primaite/main.py b/src/primaite/main.py index b63227a7..053ed65b 100644 --- a/src/primaite/main.py +++ b/src/primaite/main.py @@ -5,7 +5,7 @@ from pathlib import Path from typing import Optional, Union from primaite import getLogger -from primaite.config.load import example_config_path, load +from primaite.config.load import data_manipulation_config_path, load from primaite.session.session import PrimaiteSession # from primaite.primaite_session import PrimaiteSession @@ -42,6 +42,6 @@ if __name__ == "__main__": args = parser.parse_args() if not args.config: - args.config = example_config_path() + args.config = data_manipulation_config_path() run(args.config) diff --git a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb index 85061b2b..e35e6126 100644 --- a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb @@ -371,7 +371,7 @@ "outputs": [], "source": [ "# Imports\n", - "from primaite.config.load import example_config_path\n", + "from primaite.config.load import data_manipulation_config_path\n", "from primaite.session.environment import PrimaiteGymEnv\n", "from primaite.game.game import PrimaiteGame\n", "import yaml\n", @@ -394,7 +394,7 @@ "outputs": [], "source": [ "# create the env\n", - "with open(example_config_path(), 'r') as f:\n", + "with open(data_manipulation_config_path(), 'r') as f:\n", " cfg = yaml.safe_load(f)\n", " # set success probability to 1.0 to avoid rerunning cells.\n", " cfg['simulation']['network']['nodes'][8]['applications'][0]['options']['data_manipulation_p_of_success'] = 1.0\n", diff --git a/src/primaite/notebooks/training_example_ray_single_agent.ipynb b/src/primaite/notebooks/training_example_ray_single_agent.ipynb index 3c27bdc6..2fe84655 100644 --- a/src/primaite/notebooks/training_example_ray_single_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_single_agent.ipynb @@ -16,7 +16,7 @@ "source": [ "from primaite.game.game import PrimaiteGame\n", "import yaml\n", - "from primaite.config.load import example_config_path\n", + "from primaite.config.load import data_manipulation_config_path\n", "\n", "from primaite.session.environment import PrimaiteRayEnv\n", "from ray.rllib.algorithms import ppo\n", @@ -26,7 +26,7 @@ "\n", "# If you get an error saying this config file doesn't exist, you may need to run `primaite setup` in your command line\n", "# to copy the files to your user data path.\n", - "with open(example_config_path(), 'r') as f:\n", + "with open(data_manipulation_config_path(), 'r') as f:\n", " cfg = yaml.safe_load(f)\n", "\n", "ray.init(local_mode=True)\n" diff --git a/src/primaite/notebooks/training_example_sb3.ipynb b/src/primaite/notebooks/training_example_sb3.ipynb index 0472854e..cefcc429 100644 --- a/src/primaite/notebooks/training_example_sb3.ipynb +++ b/src/primaite/notebooks/training_example_sb3.ipynb @@ -17,7 +17,7 @@ "metadata": {}, "outputs": [], "source": [ - "from primaite.config.load import example_config_path" + "from primaite.config.load import data_manipulation_config_path" ] }, { @@ -26,7 +26,7 @@ "metadata": {}, "outputs": [], "source": [ - "with open(example_config_path(), 'r') as f:\n", + "with open(data_manipulation_config_path(), 'r') as f:\n", " cfg = yaml.safe_load(f)\n" ] }, diff --git a/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py b/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py index 3934ce5b..84897f9a 100644 --- a/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py +++ b/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py @@ -4,7 +4,7 @@ import yaml from ray import air, tune from ray.rllib.algorithms.ppo import PPOConfig -from primaite.config.load import example_config_path +from primaite.config.load import data_manipulation_config_path from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteRayMARLEnv @@ -13,7 +13,7 @@ from primaite.session.environment import PrimaiteRayMARLEnv def test_rllib_multi_agent_compatibility(): """Test that the PrimaiteRayEnv class can be used with a multi agent RLLIB system.""" - with open(example_config_path(), "r") as f: + with open(data_manipulation_config_path(), "r") as f: cfg = yaml.safe_load(f) game = PrimaiteGame.from_config(cfg) diff --git a/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py b/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py index 2b12ad98..4c4b8d8d 100644 --- a/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py +++ b/tests/e2e_integration_tests/environments/test_rllib_single_agent_environment.py @@ -6,7 +6,7 @@ import ray import yaml from ray.rllib.algorithms import ppo -from primaite.config.load import example_config_path +from primaite.config.load import data_manipulation_config_path from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteRayEnv @@ -14,7 +14,7 @@ from primaite.session.environment import PrimaiteRayEnv @pytest.mark.skip(reason="Slow, reenable later") def test_rllib_single_agent_compatibility(): """Test that the PrimaiteRayEnv class can be used with a single agent RLLIB system.""" - with open(example_config_path(), "r") as f: + with open(data_manipulation_config_path(), "r") as f: cfg = yaml.safe_load(f) game = PrimaiteGame.from_config(cfg) diff --git a/tests/e2e_integration_tests/environments/test_sb3_environment.py b/tests/e2e_integration_tests/environments/test_sb3_environment.py index c48ddbc9..83965191 100644 --- a/tests/e2e_integration_tests/environments/test_sb3_environment.py +++ b/tests/e2e_integration_tests/environments/test_sb3_environment.py @@ -6,14 +6,14 @@ import pytest import yaml from stable_baselines3 import PPO -from primaite.config.load import example_config_path +from primaite.config.load import data_manipulation_config_path from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteGymEnv def test_sb3_compatibility(): """Test that the Gymnasium environment can be used with an SB3 agent.""" - with open(example_config_path(), "r") as f: + with open(data_manipulation_config_path(), "r") as f: cfg = yaml.safe_load(f) gym = PrimaiteGymEnv(game_config=cfg) diff --git a/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py b/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py index 8797bf2e..174bd0c0 100644 --- a/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py +++ b/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py @@ -1,4 +1,4 @@ -from primaite.config.load import example_config_path +from primaite.config.load import data_manipulation_config_path from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer @@ -7,7 +7,7 @@ from tests.integration_tests.configuration_file_parsing import BASIC_CONFIG, DMZ def test_example_config(): """Test that the example config can be parsed properly.""" - game = load_config(example_config_path()) + game = load_config(data_manipulation_config_path()) network: Network = game.simulation.network assert len(network.nodes) == 10 # 10 nodes in example network diff --git a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py index 7da66547..3aff59af 100644 --- a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py +++ b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py @@ -4,7 +4,7 @@ from typing import Union import yaml -from primaite.config.load import example_config_path +from primaite.config.load import data_manipulation_config_path from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import ProxyAgent, RandomAgent from primaite.game.game import APPLICATION_TYPES_MAPPING, PrimaiteGame, SERVICE_TYPES_MAPPING @@ -37,7 +37,7 @@ def load_config(config_path: Union[str, Path]) -> PrimaiteGame: def test_example_config(): """Test that the example config can be parsed properly.""" - game = load_config(example_config_path()) + game = load_config(data_manipulation_config_path()) assert len(game.agents) == 4 # red, blue and 2 green agents From 758f892b74a1e05db3de8e254670bcfec47efd8b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 4 Mar 2024 21:04:27 +0000 Subject: [PATCH 676/980] Make notebook for varying red agent behaviour in uc2 --- docs/index.rst | 1 + docs/source/customising_scenarios.rst | 4 + .../config/_package_data/example_config.yaml | 3 - ...a-Manipulation-Customising-Red-Agent.ipynb | 444 ++++++++++++++++++ src/primaite/session/environment.py | 5 +- 5 files changed, 453 insertions(+), 4 deletions(-) create mode 100644 docs/source/customising_scenarios.rst create mode 100644 src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb diff --git a/docs/index.rst b/docs/index.rst index 08e0ac21..cf17b1c5 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -109,6 +109,7 @@ Head over to the :ref:`getting-started` page to install and setup PrimAITE! source/game_layer source/config source/environment + source/customising_scenarios .. toctree:: :caption: Developer information: diff --git a/docs/source/customising_scenarios.rst b/docs/source/customising_scenarios.rst new file mode 100644 index 00000000..709f032a --- /dev/null +++ b/docs/source/customising_scenarios.rst @@ -0,0 +1,4 @@ +Customising Agents +****************** + +For an example of how to customise red agent behaviour in the Data Manipulation scenario, please refer to the notebook ``Data-Manipulation-Customising-Red-Agent.ipynb``. diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index fbc12686..aea5d4fd 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -134,9 +134,6 @@ agents: action_list: - type: DONOTHING - type: NODE_APPLICATION_EXECUTE - - type: NODE_FILE_DELETE - - type: NODE_FILE_CORRUPT - - type: NODE_OS_SCAN options: nodes: - node_name: client_1 diff --git a/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb b/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb new file mode 100644 index 00000000..6fee18b1 --- /dev/null +++ b/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb @@ -0,0 +1,444 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Customising red agents\n", + "\n", + "This notebook will go over some examples of how red agent behaviour can be varied by changing its configuration parameters.\n", + "\n", + "First, let's load the standard Data Manipulation config file, and see what the red agent does.\n", + "\n", + "*(For a full explanation of the Data Manipulation scenario, check out the notebook `Data-Manipulation-E2E-Demonstration.ipynb`)*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Imports\n", + "\n", + "from primaite.config.load import data_manipulation_config_path\n", + "from primaite.session.environment import PrimaiteGymEnv\n", + "import yaml\n", + "from pprint import pprint" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def make_cfg_have_flat_obs(cfg):\n", + " for agent in cfg['agents']:\n", + " if agent['type'] == \"ProxyAgent\":\n", + " agent['agent_settings']['flatten_obs'] = False" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(data_manipulation_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + " make_cfg_have_flat_obs(cfg)\n", + "\n", + "env = PrimaiteGymEnv(game_config = cfg)\n", + "obs, info = env.reset()\n", + "print('env created successfully')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def friendly_output_red_action(info):\n", + " # parse the info dict form step output and write out what the red agent is doing\n", + " red_info = info['agent_actions']['data_manipulation_attacker']\n", + " red_action = red_info[0]\n", + " if red_action == 'DONOTHING':\n", + " red_str = 'DO NOTHING'\n", + " elif red_action == 'NODE_APPLICATION_EXECUTE':\n", + " client = \"client 1\" if red_info[1]['node_id'] == 0 else \"client 2\"\n", + " red_str = f\"ATTACK from {client}\"\n", + " return red_str" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "By default, the red agent can start on client 1 or client 2. It starts its attack on a random step between 20 and 30, and it repeats its attack every 15-25 steps.\n", + "\n", + "It also has a 20% chance to fail to perform the port scan, and a 20% chance to fail launching the SQL attack. However it will continue where it left off after a failed step. I.e. if lucky, it can perform the port scan and SQL attack on the first try. If the port scan works, but the sql attack fails the first time it tries to attack, the next time it will not need to port scan again, it can go straight to trying to use SQL attack again." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for step in range(35):\n", + " step_num = env.game.step_counter\n", + " obs, reward, terminated, truncated, info = env.step(0)\n", + " red = friendly_output_red_action(info)\n", + " print(f\"step: {step_num:3}, Red action: {friendly_output_red_action(info)}, Blue reward:{reward:.2f}\" )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Since the agent does nothing most of the time, let's only print the steps where it performs an attack." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "env.reset()\n", + "for step in range(100):\n", + " step_num = env.game.step_counter\n", + " obs, reward, terminated, truncated, info = env.step(0)\n", + " red = friendly_output_red_action(info)\n", + " if red.startswith(\"ATTACK\"):\n", + " print(f\"step: {step_num:3}, Red action: {friendly_output_red_action(info)}, Blue reward:{reward:.2f}\" )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Red Configuration\n", + "\n", + "There are two important parts of the YAML config for varying red agent behaviour.\n", + "\n", + "#### The red agent settings\n", + "Here is an annotated config for the red agent in the data manipulation scenario.\n", + "```yaml\n", + " - ref: data_manipulation_attacker # name of agent\n", + " team: RED # not used, just for human reference\n", + " type: RedDatabaseCorruptingAgent # type of agent - this lets primaite know which agent class to use\n", + "\n", + " # Since the agent does not need to react to what is happening in the environment, the observation space is empty.\n", + " observation_space:\n", + " type: UC2RedObservation\n", + " options:\n", + " nodes: {}\n", + "\n", + " action_space:\n", + "\n", + " # The agent has two action choices, either do nothing, or execute a pre-scripted attack by using \n", + " action_list:\n", + " - type: DONOTHING\n", + " - type: NODE_APPLICATION_EXECUTE\n", + "\n", + " # The agent has access to the DataManipulationBoth on clients 1 and 2.\n", + " options:\n", + " nodes:\n", + " - node_name: client_1 # The network should have a node called client_1\n", + " applications:\n", + " - application_name: DataManipulationBot # The node client_1 should have DataManipulationBot configured on it\n", + " - node_name: client_2 # The network should have a node called client_2\n", + " applications:\n", + " - application_name: DataManipulationBot # The node client_2 should have DataManipulationBot configured on it\n", + "\n", + " # not important\n", + " max_folders_per_node: 1\n", + " max_files_per_folder: 1\n", + " max_services_per_node: 1\n", + "\n", + " # red agent does not need a reward function\n", + " reward_function:\n", + " reward_components:\n", + " - type: DUMMY\n", + "\n", + " # These actions are passed to the RedDatabaseCorruptingAgent init method, they dictate the schedule of attacks\n", + " agent_settings:\n", + " start_settings:\n", + " start_step: 25 # first attack at step 25\n", + " frequency: 20 # attacks will happen every 20 steps (on average)\n", + " variance: 5 # the timing of attacks will vary by up to 5 steps earlier or later\n", + "```\n", + "\n", + "#### The settings of the red agent's attack application\n", + "The red agent uses an application called `DataManipulationBot` which leverages a node's `DatabaseClient` to send a malicious SQL query to the database server. Here's an annotated example of how this is configured in the yaml *(with impertinent config items omitted)*:\n", + "```yaml\n", + "simulation:\n", + " network:\n", + " nodes:\n", + " - ref: client_1\n", + " hostname: client_1\n", + " type: computer\n", + " ip_address: 192.168.10.21\n", + " subnet_mask: 255.255.255.0\n", + " default_gateway: 192.168.10.1\n", + " \n", + " # \n", + " applications:\n", + " - ref: data_manipulation_bot\n", + " type: DataManipulationBot\n", + " options:\n", + " port_scan_p_of_success: 0.8 # Probability that port scan is successful\n", + " data_manipulation_p_of_success: 0.8 # Probability that SQL attack is successful\n", + " payload: \"DELETE\" # The SQL query which causes the attack (this has to be DELETE)\n", + " server_ip: 192.168.1.14 # IP address of server hosting the database\n", + " - ref: client_1_database_client\n", + " type: DatabaseClient # Database client must be installed in order for DataManipulationBot to function\n", + " options:\n", + " db_server_ip: 192.168.1.14 # IP address of server hosting the database\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Removing randomness from attack timing\n", + "\n", + "We can make the attacks happen at completely predictable intervals if we set the variance parameter of the red agent to 0." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "change = yaml.safe_load(\"\"\"\n", + "start_settings:\n", + " start_step: 25\n", + " frequency: 20\n", + " variance: 0\n", + "\"\"\")\n", + "\n", + "with open(data_manipulation_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + " for agent in cfg['agents']:\n", + " if agent['ref'] == \"data_manipulation_attacker\":\n", + " agent['agent_settings'] = change\n", + "\n", + "env = PrimaiteGymEnv(game_config = cfg)\n", + "env.reset()\n", + "for step in range(100):\n", + " step_num = env.game.step_counter\n", + " obs, reward, terminated, truncated, info = env.step(0)\n", + " red = friendly_output_red_action(info)\n", + " if red.startswith(\"ATTACK\"):\n", + " print(f\"step: {step_num:3}, Red action: {friendly_output_red_action(info)}, Blue reward:{reward:.2f}\" )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Making the start node always the same\n", + "\n", + "Normally, the agent randomly chooses between the nodes in its action space to send attacks from:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Open the config without changing anyhing\n", + "with open(data_manipulation_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + "\n", + "env = PrimaiteGymEnv(game_config = cfg)\n", + "env.reset()\n", + "for ep in range(12):\n", + " env.reset()\n", + " for step in range(31):\n", + " step_num = env.game.step_counter\n", + " obs, reward, terminated, truncated, info = env.step(0)\n", + " red = friendly_output_red_action(info)\n", + " if red.startswith(\"ATTACK\"):\n", + " print(f\"Episode: {ep:2}, step: {step_num:3}, Red action: {friendly_output_red_action(info)}\" )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can make the agent always start on a node of our choice letting that be the only node in the agent's action space." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "change = yaml.safe_load(\"\"\"\n", + "action_space:\n", + " action_list:\n", + " - type: DONOTHING\n", + " - type: NODE_APPLICATION_EXECUTE\n", + " options:\n", + " nodes:\n", + " - node_name: client_1\n", + " applications:\n", + " - application_name: DataManipulationBot\n", + " max_folders_per_node: 1\n", + " max_files_per_folder: 1\n", + " max_services_per_node: 1\n", + "\"\"\")\n", + "\n", + "with open(data_manipulation_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + " for agent in cfg['agents']:\n", + " if agent['ref'] == \"data_manipulation_attacker\":\n", + " agent.update(change)\n", + "\n", + "env = PrimaiteGymEnv(game_config = cfg)\n", + "env.reset()\n", + "for ep in range(12):\n", + " env.reset()\n", + " for step in range(31):\n", + " step_num = env.game.step_counter\n", + " obs, reward, terminated, truncated, info = env.step(0)\n", + " red = friendly_output_red_action(info)\n", + " if red.startswith(\"ATTACK\"):\n", + " print(f\"Episode: {ep:2}, step: {step_num:3}, Red action: {friendly_output_red_action(info)}\" )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Make the attack less likely to succeed.\n", + "\n", + "We can change the success probabilities within the data manipulation bot application. When the attack succeeds, the reward goes down.\n", + "\n", + "Setting the probabilities to 1.0 means the attack always succeeds - the reward will always drop\n", + "\n", + "Setting the probabilities to 0.0 means the attack always fails - the reward will never drop." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Make attack always succeed.\n", + "change = yaml.safe_load(\"\"\"\n", + " applications:\n", + " - ref: data_manipulation_bot\n", + " type: DataManipulationBot\n", + " options:\n", + " port_scan_p_of_success: 1.0\n", + " data_manipulation_p_of_success: 1.0\n", + " payload: \"DELETE\"\n", + " server_ip: 192.168.1.14\n", + " - ref: client_1_web_browser\n", + " type: WebBrowser\n", + " options:\n", + " target_url: http://arcd.com/users/\n", + " - ref: client_1_database_client\n", + " type: DatabaseClient\n", + " options:\n", + " db_server_ip: 192.168.1.14\n", + "\"\"\")\n", + "\n", + "with open(data_manipulation_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + " cfg['simulation']['network']\n", + " for node in cfg['simulation']['network']['nodes']:\n", + " if node['ref'] in ['client_1', 'client_2']:\n", + " node['applications'] = change['applications']\n", + "\n", + "env = PrimaiteGymEnv(game_config = cfg)\n", + "env.reset()\n", + "for ep in range(5):\n", + " env.reset()\n", + " for step in range(36):\n", + " step_num = env.game.step_counter\n", + " obs, reward, terminated, truncated, info = env.step(0)\n", + " red = friendly_output_red_action(info)\n", + " if step_num == 35:\n", + " print(f\"Episode: {ep:2}, step: {step_num:3}, Reward: {reward:.2f}\" )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Make attack always fail.\n", + "change = yaml.safe_load(\"\"\"\n", + " applications:\n", + " - ref: data_manipulation_bot\n", + " type: DataManipulationBot\n", + " options:\n", + " port_scan_p_of_success: 0.0\n", + " data_manipulation_p_of_success: 0.0\n", + " payload: \"DELETE\"\n", + " server_ip: 192.168.1.14\n", + " - ref: client_1_web_browser\n", + " type: WebBrowser\n", + " options:\n", + " target_url: http://arcd.com/users/\n", + " - ref: client_1_database_client\n", + " type: DatabaseClient\n", + " options:\n", + " db_server_ip: 192.168.1.14\n", + "\"\"\")\n", + "\n", + "with open(data_manipulation_config_path(), 'r') as f:\n", + " cfg = yaml.safe_load(f)\n", + " cfg['simulation']['network']\n", + " for node in cfg['simulation']['network']['nodes']:\n", + " if node['ref'] in ['client_1', 'client_2']:\n", + " node['applications'] = change['applications']\n", + "\n", + "env = PrimaiteGymEnv(game_config = cfg)\n", + "env.reset()\n", + "for ep in range(5):\n", + " env.reset()\n", + " for step in range(36):\n", + " step_num = env.game.step_counter\n", + " obs, reward, terminated, truncated, info = env.step(0)\n", + " red = friendly_output_red_action(info)\n", + " if step_num == 35:\n", + " print(f\"Episode: {ep:2}, step: {step_num:3}, Reward: {reward:.2f}\" )" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index d54503a3..86bc52cb 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -6,10 +6,13 @@ import gymnasium from gymnasium.core import ActType, ObsType from ray.rllib.env.multi_agent_env import MultiAgentEnv +from primaite import getLogger from primaite.game.agent.interface import ProxyAgent from primaite.game.game import PrimaiteGame from primaite.simulator import SIM_OUTPUT +_LOGGER = getLogger(__name__) + class PrimaiteGymEnv(gymnasium.Env): """ @@ -75,7 +78,7 @@ class PrimaiteGymEnv(gymnasium.Env): def reset(self, seed: Optional[int] = None) -> Tuple[ObsType, Dict[str, Any]]: """Reset the environment.""" - print( + _LOGGER.info( f"Resetting environment, episode {self.episode_counter}, " f"avg. reward: {self.agent.reward_function.total_reward}" ) From 3e495c4622a89e02501fe25ebb972ea1f0f95e80 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 5 Mar 2024 09:28:22 +0000 Subject: [PATCH 677/980] Cosmetic changes to notebook --- ...Data-Manipulation-Customising-Red-Agent.ipynb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb b/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb index 6fee18b1..779d89f6 100644 --- a/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb @@ -120,11 +120,11 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Red Configuration\n", + "## Red Configuration\n", "\n", "There are two important parts of the YAML config for varying red agent behaviour.\n", "\n", - "#### The red agent settings\n", + "### Red agent settings\n", "Here is an annotated config for the red agent in the data manipulation scenario.\n", "```yaml\n", " - ref: data_manipulation_attacker # name of agent\n", @@ -172,7 +172,7 @@ " variance: 5 # the timing of attacks will vary by up to 5 steps earlier or later\n", "```\n", "\n", - "#### The settings of the red agent's attack application\n", + "### Malicious application settings\n", "The red agent uses an application called `DataManipulationBot` which leverages a node's `DatabaseClient` to send a malicious SQL query to the database server. Here's an annotated example of how this is configured in the yaml *(with impertinent config items omitted)*:\n", "```yaml\n", "simulation:\n", @@ -205,9 +205,11 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "## Editing red agent settings\n", + "\n", "### Removing randomness from attack timing\n", "\n", - "We can make the attacks happen at completely predictable intervals if we set the variance parameter of the red agent to 0." + "We can make the attacks happen at completely predictable intervals if we edit the red agent's settings to set variance to 0." ] }, { @@ -243,7 +245,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### Making the start node always the same\n", + "### Making the start node always the same\n", "\n", "Normally, the agent randomly chooses between the nodes in its action space to send attacks from:" ] @@ -254,7 +256,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Open the config without changing anyhing\n", + "# Open the config without changing anything\n", "with open(data_manipulation_config_path(), 'r') as f:\n", " cfg = yaml.safe_load(f)\n", "\n", @@ -320,7 +322,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### Make the attack less likely to succeed.\n", + "### Make the attack less likely to succeed.\n", "\n", "We can change the success probabilities within the data manipulation bot application. When the attack succeeds, the reward goes down.\n", "\n", From a7bfc56b98bd93f8c4043ffae678e72faa34f8f3 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 5 Mar 2024 11:21:49 +0000 Subject: [PATCH 678/980] Apply documentation changes based on PR review. --- CHANGELOG.md | 2 +- docs/source/configuration/io_settings.rst | 12 +----------- src/primaite/session/io.py | 12 +++++++----- src/primaite/session/session.py | 2 +- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8064a18e..cdf7b5c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed the order of service health state - Fixed an issue where starting a node didn't start the services on it - Added support for SQL INSERT command. -- Added ability to log each agent's action choices each step to a JSON file. +- Added ability to log each agent's action choices in each step to a JSON file. diff --git a/docs/source/configuration/io_settings.rst b/docs/source/configuration/io_settings.rst index e5c6d2ce..f9704541 100644 --- a/docs/source/configuration/io_settings.rst +++ b/docs/source/configuration/io_settings.rst @@ -18,7 +18,6 @@ This section configures how PrimAITE saves data during simulation and training. checkpoint_interval: 10 # save_logs: True # save_transactions: False - # save_tensorboard_logs: False save_agent_actions: True save_step_metadata: False save_pcap_logs: False @@ -56,21 +55,12 @@ Defines how often to save the policy during training. *currently unused*. -``save_transactions`` ---------------------- - -*currently unused*. - -``save_tensorboard_logs`` -------------------------- - -*currently unused*. ``save_agent_actions`` Optional. Default value is ``True``. -If ``True``, this will create a JSON file each episode detailing every agent's action each step in that episode, formatted according to the CAOS format. This includes scripted, RL, and red agents. +If ``True``, this will create a JSON file each episode detailing every agent's action in each step of that episode, formatted according to the CAOS format. This includes scripted, RL, and red agents. ``save_step_metadata`` ---------------------- diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index 22d9dbeb..3e21ed16 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -15,7 +15,7 @@ class PrimaiteIO: """ Class for managing session IO. - Currently it's handling path generation, but could expand to handle loading, transaction, tensorboard, and so on. + Currently it's handling path generation, but could expand to handle loading, transaction, and so on. """ class Settings(BaseModel): @@ -27,8 +27,6 @@ class PrimaiteIO: """Whether to save logs""" save_agent_actions: bool = True """Whether to save a log of all agents' actions every step.""" - save_transactions: bool = True - """Whether to save transactions, If true, the session path will have a transactions folder.""" save_step_metadata: bool = False """Whether to save the RL agents' action, environment state, and other data at every single step.""" save_pcap_logs: bool = False @@ -37,6 +35,12 @@ class PrimaiteIO: """Whether to save system logs.""" def __init__(self, settings: Optional[Settings] = None) -> None: + """ + Init the PrimaiteIO object. + + Note: Instantiating this object creates a new directory for outputs, and sets the global SIM_OUTPUT variable. + It is intended that this object is instantiated when a new environment is created. + """ self.settings = settings or PrimaiteIO.Settings() self.session_path: Path = self.generate_session_path() # set global SIM_OUTPUT path @@ -45,8 +49,6 @@ class PrimaiteIO: SIM_OUTPUT.save_sys_logs = self.settings.save_sys_logs self.agent_action_log: List[Dict] = [] - # warning TODO: must be careful not to re-initialise sessionIO because it will create a new path each time it's - # possible refactor needed def generate_session_path(self, timestamp: Optional[datetime] = None) -> Path: """Create a folder for the session and return the path to it.""" diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py index 84dd9b2f..9c935ae3 100644 --- a/src/primaite/session/session.py +++ b/src/primaite/session/session.py @@ -61,7 +61,7 @@ class PrimaiteSession: """Primaite Game object for managing main simulation loop and agents.""" self.save_checkpoints: bool = False - """Whether to save chcekpoints.""" + """Whether to save checkpoints.""" self.checkpoint_interval: int = 10 """If save_checkpoints is true, checkpoints will be saved every checkpoint_interval episodes.""" From e117f94f43ad52f0064e0ecaf2fe46d606bbc209 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 5 Mar 2024 15:46:30 +0000 Subject: [PATCH 679/980] Minor doc fix --- docs/source/configuration/io_settings.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/configuration/io_settings.rst b/docs/source/configuration/io_settings.rst index f9704541..979dbfae 100644 --- a/docs/source/configuration/io_settings.rst +++ b/docs/source/configuration/io_settings.rst @@ -57,6 +57,7 @@ Defines how often to save the policy during training. ``save_agent_actions`` +---------------------- Optional. Default value is ``True``. From a900d59f7b24124739dcb8be02a241220319d0b1 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 7 Mar 2024 12:15:30 +0000 Subject: [PATCH 680/980] Update NMNE to only count MNEs in the last step. --- .../simulator/network/hardware/base.py | 3 +- .../network/test_capture_nmne.py | 100 +++++++++++++++--- 2 files changed, 88 insertions(+), 15 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 991913dd..36716f27 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -136,7 +136,8 @@ class NetworkInterface(SimComponent, ABC): } ) if CAPTURE_NMNE: - state.update({"nmne": self.nmne}) + state.update({"nmne": {k: v for k, v in self.nmne.items()}}) + self.nmne.clear() return state @abstractmethod diff --git a/tests/integration_tests/network/test_capture_nmne.py b/tests/integration_tests/network/test_capture_nmne.py index 85ac23e8..d48b3784 100644 --- a/tests/integration_tests/network/test_capture_nmne.py +++ b/tests/integration_tests/network/test_capture_nmne.py @@ -32,36 +32,106 @@ def test_capture_nmne(uc2_network): set_nmne_config(nmne_config) # Assert that initially, there are no captured MNEs on both web and database servers - assert web_server_nic.describe_state()["nmne"] == {} - assert db_server_nic.describe_state()["nmne"] == {} + assert web_server_nic.nmne == {} + assert db_server_nic.nmne == {} # Perform a "SELECT" query db_client.query("SELECT") # Check that it does not trigger an MNE capture. - assert web_server_nic.describe_state()["nmne"] == {} - assert db_server_nic.describe_state()["nmne"] == {} + assert web_server_nic.nmne == {} + assert db_server_nic.nmne == {} # Perform a "DELETE" query db_client.query("DELETE") # Check that the web server's outbound interface and the database server's inbound interface register the MNE - assert web_server_nic.describe_state()["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}} - assert db_server_nic.describe_state()["nmne"] == {"direction": {"inbound": {"keywords": {"*": 1}}}} + assert web_server_nic.nmne == {"direction": {"outbound": {"keywords": {"*": 1}}}} + assert db_server_nic.nmne == {"direction": {"inbound": {"keywords": {"*": 1}}}} # Perform another "SELECT" query db_client.query("SELECT") # Check that no additional MNEs are captured - assert web_server_nic.describe_state()["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}} - assert db_server_nic.describe_state()["nmne"] == {"direction": {"inbound": {"keywords": {"*": 1}}}} + assert web_server_nic.nmne == {"direction": {"outbound": {"keywords": {"*": 1}}}} + assert db_server_nic.nmne == {"direction": {"inbound": {"keywords": {"*": 1}}}} # Perform another "DELETE" query db_client.query("DELETE") # Check that the web server and database server interfaces register an additional MNE - assert web_server_nic.describe_state()["nmne"] == {"direction": {"outbound": {"keywords": {"*": 2}}}} - assert db_server_nic.describe_state()["nmne"] == {"direction": {"inbound": {"keywords": {"*": 2}}}} + assert web_server_nic.nmne == {"direction": {"outbound": {"keywords": {"*": 2}}}} + assert db_server_nic.nmne == {"direction": {"inbound": {"keywords": {"*": 2}}}} + + +def test_describe_state_nmne(uc2_network): + """ + Conducts a test to verify that Malicious Network Events (MNEs) are correctly represented in the nic state. + + This test involves a web server querying a database server and checks if the MNEs are captured + based on predefined keywords in the network configuration. Specifically, it checks the capture + of the "DELETE" SQL command as a malicious network event. It also checks that running describe_state + only shows MNEs since the last time describe_state was called. + """ + web_server: Server = uc2_network.get_node_by_hostname("web_server") # noqa + db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] # noqa + db_client.connect() + + db_server: Server = uc2_network.get_node_by_hostname("database_server") # noqa + + web_server_nic = web_server.network_interface[1] + db_server_nic = db_server.network_interface[1] + + # Set the NMNE configuration to capture DELETE queries as MNEs + nmne_config = { + "capture_nmne": True, # Enable the capture of MNEs + "nmne_capture_keywords": ["DELETE"], # Specify "DELETE" SQL command as a keyword for MNE detection + } + + # Apply the NMNE configuration settings + set_nmne_config(nmne_config) + + # Assert that initially, there are no captured MNEs on both web and database servers + web_server_nic_state = web_server_nic.describe_state() + db_server_nic_state = db_server_nic.describe_state() + assert web_server_nic_state["nmne"] == {} + assert db_server_nic_state["nmne"] == {} + + # Perform a "SELECT" query + db_client.query("SELECT") + + # Check that it does not trigger an MNE capture. + web_server_nic_state = web_server_nic.describe_state() + db_server_nic_state = db_server_nic.describe_state() + assert web_server_nic_state["nmne"] == {} + assert db_server_nic_state["nmne"] == {} + + # Perform a "DELETE" query + db_client.query("DELETE") + + # Check that the web server's outbound interface and the database server's inbound interface register the MNE + web_server_nic_state = web_server_nic.describe_state() + db_server_nic_state = db_server_nic.describe_state() + assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}} + assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 1}}}} + + # Perform another "SELECT" query + db_client.query("SELECT") + + # Check that no additional MNEs are captured + web_server_nic_state = web_server_nic.describe_state() + db_server_nic_state = db_server_nic.describe_state() + assert web_server_nic_state["nmne"] == {} + assert db_server_nic_state["nmne"] == {} + + # Perform another "DELETE" query + db_client.query("DELETE") + + # Check that the web server and database server interfaces register an additional MNE + web_server_nic_state = web_server_nic.describe_state() + db_server_nic_state = db_server_nic.describe_state() + assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}} + assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 1}}}} def test_capture_nmne_observations(uc2_network): @@ -97,13 +167,15 @@ def test_capture_nmne_observations(uc2_network): web_server_nic_obs = NicObservation(where=["network", "nodes", "web_server", "NICs", 1]) # Iterate through a set of test cases to simulate multiple DELETE queries - for i in range(1, 20): + for i in range(0, 20): # Perform a "DELETE" query each iteration - db_client.query("DELETE") + for j in range(i): + db_client.query("DELETE") # Observe the current state of NMNEs from the NICs of both the database and web servers - db_nic_obs = db_server_nic_obs.observe(sim.describe_state())["nmne"] - web_nic_obs = web_server_nic_obs.observe(sim.describe_state())["nmne"] + state = sim.describe_state() + db_nic_obs = db_server_nic_obs.observe(state)["nmne"] + web_nic_obs = web_server_nic_obs.observe(state)["nmne"] # Define expected NMNE values based on the iteration count if i > 10: From 2547361dafdd4340d734de9c3ca045bea99c1c77 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 7 Mar 2024 13:52:26 +0000 Subject: [PATCH 681/980] Change default reward weights --- .../config/_package_data/example_config.yaml | 10 ++++----- .../example_config_2_rl_agents.yaml | 21 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/example_config.yaml index d0ba61b0..dffb40ea 100644 --- a/src/primaite/config/_package_data/example_config.yaml +++ b/src/primaite/config/_package_data/example_config.yaml @@ -691,25 +691,25 @@ agents: reward_function: reward_components: - type: DATABASE_FILE_INTEGRITY - weight: 0.34 + weight: 0.40 options: node_hostname: database_server folder_name: database file_name: database.db - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.33 + weight: 0.25 options: node_hostname: client_1 - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.33 + weight: 0.25 options: node_hostname: client_2 - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.1 + weight: 0.05 options: node_hostname: client_1 - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.1 + weight: 0.05 options: node_hostname: client_2 diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml index 575182a8..f7288cb0 100644 --- a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml +++ b/src/primaite/config/_package_data/example_config_2_rl_agents.yaml @@ -695,25 +695,25 @@ agents: reward_function: reward_components: - type: DATABASE_FILE_INTEGRITY - weight: 0.34 + weight: 0.40 options: node_hostname: database_server folder_name: database file_name: database.db - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.33 + weight: 0.25 options: node_hostname: client_1 - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.33 + weight: 0.25 options: node_hostname: client_2 - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.1 + weight: 0.05 options: node_hostname: client_1 - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.1 + weight: 0.05 options: node_hostname: client_2 @@ -1251,29 +1251,28 @@ agents: - node_name: security_suite nic_num: 2 - reward_function: reward_components: - type: DATABASE_FILE_INTEGRITY - weight: 0.34 + weight: 0.40 options: node_hostname: database_server folder_name: database file_name: database.db - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.33 + weight: 0.25 options: node_hostname: client_1 - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.33 + weight: 0.25 options: node_hostname: client_2 - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.1 + weight: 0.05 options: node_hostname: client_1 - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.1 + weight: 0.05 options: node_hostname: client_2 From 17d4807660b4a5deebd02f82970cb711c50c9601 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 7 Mar 2024 14:33:21 +0000 Subject: [PATCH 682/980] Rename configs --- .../{example_config.yaml => data_manipulation.yaml} | 0 ...mple_config_2_rl_agents.yaml => data_manipulation_marl.yaml} | 0 src/primaite/config/load.py | 2 +- src/primaite/notebooks/training_example_ray_multi_agent.ipynb | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename src/primaite/config/_package_data/{example_config.yaml => data_manipulation.yaml} (100%) rename src/primaite/config/_package_data/{example_config_2_rl_agents.yaml => data_manipulation_marl.yaml} (100%) diff --git a/src/primaite/config/_package_data/example_config.yaml b/src/primaite/config/_package_data/data_manipulation.yaml similarity index 100% rename from src/primaite/config/_package_data/example_config.yaml rename to src/primaite/config/_package_data/data_manipulation.yaml diff --git a/src/primaite/config/_package_data/example_config_2_rl_agents.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml similarity index 100% rename from src/primaite/config/_package_data/example_config_2_rl_agents.yaml rename to src/primaite/config/_package_data/data_manipulation_marl.yaml diff --git a/src/primaite/config/load.py b/src/primaite/config/load.py index 6bd0d80d..d5acd690 100644 --- a/src/primaite/config/load.py +++ b/src/primaite/config/load.py @@ -37,7 +37,7 @@ def data_manipulation_config_path() -> Path: :return: Path to the example config. :rtype: Path """ - path = _EXAMPLE_CFG / "example_config.yaml" + path = _EXAMPLE_CFG / "data_manipulation.yaml" if not path.exists(): msg = f"Example config does not exist: {path}. Have you run `primaite setup`?" _LOGGER.error(msg) diff --git a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb index 4ef02443..76623697 100644 --- a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb +++ b/src/primaite/notebooks/training_example_ray_multi_agent.ipynb @@ -35,7 +35,7 @@ "\n", "# If you get an error saying this config file doesn't exist, you may need to run `primaite setup` in your command line\n", "# to copy the files to your user data path.\n", - "with open(PRIMAITE_PATHS.user_config_path / 'example_config/example_config_2_rl_agents.yaml', 'r') as f:\n", + "with open(PRIMAITE_PATHS.user_config_path / 'example_config/data_manipulation_marl.yaml', 'r') as f:\n", " cfg = yaml.safe_load(f)\n", "\n", "ray.init(local_mode=True)" From 76752fd9af1d7a2d5b37247963e4d35873c10755 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 7 Mar 2024 14:44:44 +0000 Subject: [PATCH 683/980] Change the nmne clear to happen at apply_timestep instead of within describe_state --- src/primaite/simulator/network/hardware/base.py | 13 ++++++++++++- .../integration_tests/network/test_capture_nmne.py | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 36716f27..82fae164 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -137,7 +137,6 @@ class NetworkInterface(SimComponent, ABC): ) if CAPTURE_NMNE: state.update({"nmne": {k: v for k, v in self.nmne.items()}}) - self.nmne.clear() return state @abstractmethod @@ -254,6 +253,15 @@ class NetworkInterface(SimComponent, ABC): """ return f"Port {self.port_name if self.port_name else self.port_num}: {self.mac_address}" + def apply_timestep(self, timestep: int) -> None: + """ + Apply a timestep evolution to this component. + + This just clears the nmne count back to 0.tests/integration_tests/network/test_capture_nmne.py + """ + super().apply_timestep(timestep=timestep) + self.nmne.clear() + class WiredNetworkInterface(NetworkInterface, ABC): """ @@ -884,6 +892,9 @@ class Node(SimComponent): """ super().apply_timestep(timestep=timestep) + for network_interface in self.network_interfaces.values(): + network_interface.apply_timestep(timestep=timestep) + # count down to boot up if self.start_up_countdown > 0: self.start_up_countdown -= 1 diff --git a/tests/integration_tests/network/test_capture_nmne.py b/tests/integration_tests/network/test_capture_nmne.py index d48b3784..698bfc72 100644 --- a/tests/integration_tests/network/test_capture_nmne.py +++ b/tests/integration_tests/network/test_capture_nmne.py @@ -94,6 +94,7 @@ def test_describe_state_nmne(uc2_network): # Assert that initially, there are no captured MNEs on both web and database servers web_server_nic_state = web_server_nic.describe_state() db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) assert web_server_nic_state["nmne"] == {} assert db_server_nic_state["nmne"] == {} @@ -103,6 +104,7 @@ def test_describe_state_nmne(uc2_network): # Check that it does not trigger an MNE capture. web_server_nic_state = web_server_nic.describe_state() db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) assert web_server_nic_state["nmne"] == {} assert db_server_nic_state["nmne"] == {} @@ -112,6 +114,7 @@ def test_describe_state_nmne(uc2_network): # Check that the web server's outbound interface and the database server's inbound interface register the MNE web_server_nic_state = web_server_nic.describe_state() db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}} assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 1}}}} @@ -121,6 +124,7 @@ def test_describe_state_nmne(uc2_network): # Check that no additional MNEs are captured web_server_nic_state = web_server_nic.describe_state() db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) assert web_server_nic_state["nmne"] == {} assert db_server_nic_state["nmne"] == {} @@ -130,6 +134,7 @@ def test_describe_state_nmne(uc2_network): # Check that the web server and database server interfaces register an additional MNE web_server_nic_state = web_server_nic.describe_state() db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}} assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 1}}}} @@ -190,3 +195,4 @@ def test_capture_nmne_observations(uc2_network): # Assert that the observed NMNEs match the expected values for both NICs assert web_nic_obs["outbound"] == expected_nmne assert db_nic_obs["inbound"] == expected_nmne + uc2_network.apply_timestep(timestep=0) From 618da8abe9ebb0b471c8b88ca49db87090ae4855 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 7 Mar 2024 15:25:11 +0000 Subject: [PATCH 684/980] Rename notebooks --- ..._ray_multi_agent.ipynb => Training-an-RLLIB-MARL-System.ipynb} | 0 ...ample_ray_single_agent.ipynb => Training-an-RLLib-Agent.ipynb} | 0 .../{training_example_sb3.ipynb => Training-an-SB3-Agent.ipynb} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/primaite/notebooks/{training_example_ray_multi_agent.ipynb => Training-an-RLLIB-MARL-System.ipynb} (100%) rename src/primaite/notebooks/{training_example_ray_single_agent.ipynb => Training-an-RLLib-Agent.ipynb} (100%) rename src/primaite/notebooks/{training_example_sb3.ipynb => Training-an-SB3-Agent.ipynb} (100%) diff --git a/src/primaite/notebooks/training_example_ray_multi_agent.ipynb b/src/primaite/notebooks/Training-an-RLLIB-MARL-System.ipynb similarity index 100% rename from src/primaite/notebooks/training_example_ray_multi_agent.ipynb rename to src/primaite/notebooks/Training-an-RLLIB-MARL-System.ipynb diff --git a/src/primaite/notebooks/training_example_ray_single_agent.ipynb b/src/primaite/notebooks/Training-an-RLLib-Agent.ipynb similarity index 100% rename from src/primaite/notebooks/training_example_ray_single_agent.ipynb rename to src/primaite/notebooks/Training-an-RLLib-Agent.ipynb diff --git a/src/primaite/notebooks/training_example_sb3.ipynb b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb similarity index 100% rename from src/primaite/notebooks/training_example_sb3.ipynb rename to src/primaite/notebooks/Training-an-SB3-Agent.ipynb From e9eef2b4c09d12d7f42624a9667b7be1597f6b80 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 8 Mar 2024 11:16:27 +0000 Subject: [PATCH 685/980] #2350: add num_access, num_file_deletions and num_creations to file system --- src/primaite/simulator/file_system/file.py | 19 +++++++ .../simulator/file_system/file_system.py | 25 +++++++-- src/primaite/simulator/file_system/folder.py | 1 + .../system/applications/application.py | 10 ++++ .../system/applications/database_client.py | 2 + .../red_applications/data_manipulation_bot.py | 2 + .../system/applications/web_browser.py | 2 + .../_file_system/test_file_system.py | 52 ++++++++++++++++++- 8 files changed, 108 insertions(+), 5 deletions(-) diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index d9b02e8e..0897178d 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -38,6 +38,8 @@ class File(FileSystemItemABC): "The Path if real is True." sim_root: Optional[Path] = None "Root path of the simulation." + num_access: int = 0 + "Number of times the file was accessed in the current step." def __init__(self, **kwargs): """ @@ -93,11 +95,23 @@ class File(FileSystemItemABC): return os.path.getsize(self.sim_path) return self.sim_size + def apply_timestep(self, timestep: int) -> None: + """ + Apply a timestep to the file. + + :param timestep: The current timestep of the simulation. + """ + super().apply_timestep(timestep=timestep) + + # reset the number of accesses to 0 + self.num_access = 0 + def describe_state(self) -> Dict: """Produce a dictionary describing the current state of this object.""" state = super().describe_state() state["size"] = self.size state["file_type"] = self.file_type.name + state["num_access"] = self.num_access return state def scan(self) -> None: @@ -106,6 +120,7 @@ class File(FileSystemItemABC): self.sys_log.error(f"Unable to scan deleted file {self.folder_name}/{self.name}") return + self.num_access += 1 # file was accessed path = self.folder.name + "/" + self.name self.sys_log.info(f"Scanning file {self.sim_path if self.sim_path else path}") self.visible_health_status = self.health_status @@ -160,6 +175,7 @@ class File(FileSystemItemABC): if self.health_status == FileSystemItemHealthStatus.CORRUPT: self.health_status = FileSystemItemHealthStatus.GOOD + self.num_access += 1 # file was accessed path = self.folder.name + "/" + self.name self.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") @@ -173,6 +189,7 @@ class File(FileSystemItemABC): if self.health_status == FileSystemItemHealthStatus.GOOD: self.health_status = FileSystemItemHealthStatus.CORRUPT + self.num_access += 1 # file was accessed path = self.folder.name + "/" + self.name self.sys_log.info(f"Corrupted file {self.sim_path if self.sim_path else path}") @@ -185,6 +202,7 @@ class File(FileSystemItemABC): if self.health_status == FileSystemItemHealthStatus.CORRUPT: self.health_status = FileSystemItemHealthStatus.GOOD + self.num_access += 1 # file was accessed path = self.folder.name + "/" + self.name self.sys_log.info(f"Restored file {self.sim_path if self.sim_path else path}") @@ -194,5 +212,6 @@ class File(FileSystemItemABC): self.sys_log.error(f"Unable to delete an already deleted file {self.folder_name}/{self.name}") return + self.num_access += 1 # file was accessed self.deleted = True self.sys_log.info(f"File deleted {self.folder_name}/{self.name}") diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 8fd4e5d7..52144c72 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -27,6 +27,10 @@ class FileSystem(SimComponent): "Instance of SysLog used to create system logs." sim_root: Path "Root path of the simulation." + num_file_creations: int = 0 + "Number of file creations in the current step." + num_file_deletions: int = 0 + "Number of file deletions in the current step." def __init__(self, **kwargs): super().__init__(**kwargs) @@ -248,6 +252,8 @@ class FileSystem(SimComponent): ) folder.add_file(file) self._file_request_manager.add_request(name=file.name, request_type=RequestType(func=file._request_manager)) + # increment file creation + self.num_file_creations += 1 return file def get_file(self, folder_name: str, file_name: str, include_deleted: Optional[bool] = False) -> Optional[File]: @@ -308,6 +314,8 @@ class FileSystem(SimComponent): if folder: file = folder.get_file(file_name) if file: + # increment file creation + self.num_file_deletions += 1 folder.remove_file(file) def delete_file_by_id(self, folder_uuid: str, file_uuid: str): @@ -337,15 +345,14 @@ class FileSystem(SimComponent): """ file = self.get_file(folder_name=src_folder_name, file_name=src_file_name) if file: - src_folder = file.folder - # remove file from src - src_folder.remove_file(file) + self.delete_file(folder_name=file.folder_name, file_name=file.name) dst_folder = self.get_folder(folder_name=dst_folder_name) if not dst_folder: dst_folder = self.create_folder(dst_folder_name) # add file to dst dst_folder.add_file(file) + self.num_file_creations += 1 if file.real: old_sim_path = file.sim_path file.sim_path = file.sim_root / file.path @@ -373,6 +380,10 @@ class FileSystem(SimComponent): folder_name=dst_folder.name, **file.model_dump(exclude={"uuid", "folder_id", "folder_name", "sim_path"}), ) + self.num_file_creations += 1 + # increment access counter + file.num_access += 1 + dst_folder.add_file(file_copy, force=True) if file.real: @@ -390,12 +401,20 @@ class FileSystem(SimComponent): state = super().describe_state() state["folders"] = {folder.name: folder.describe_state() for folder in self.folders.values()} state["deleted_folders"] = {folder.name: folder.describe_state() for folder in self.deleted_folders.values()} + state["num_file_creations"] = self.num_file_creations + state["num_file_deletions"] = self.num_file_deletions return state def apply_timestep(self, timestep: int) -> None: """Apply time step to FileSystem and its child folders and files.""" super().apply_timestep(timestep=timestep) + # reset number of file creations + self.num_file_creations = 0 + + # reset number of file deletions + self.num_file_deletions = 0 + # apply timestep to folders for folder_id in self.folders: self.folders[folder_id].apply_timestep(timestep=timestep) diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 771dc7a0..3ddc1e5f 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -131,6 +131,7 @@ class Folder(FileSystemItemABC): file.scan() if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: self.visible_health_status = FileSystemItemHealthStatus.CORRUPT + self.visible_health_status = self.health_status def _reveal_to_red_timestep(self) -> None: """Apply reveal to red timestep.""" diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 513606a9..74013681 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -59,6 +59,16 @@ class Application(IOSoftware): ) return state + def apply_timestep(self, timestep: int) -> None: + """ + Apply a timestep to the application. + + :param timestep: The current timestep of the simulation. + """ + super().apply_timestep(timestep=timestep) + + self.num_executions = 0 # reset number of executions + def _can_perform_action(self) -> bool: """ Checks if the application can perform actions. diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 7b259ff4..302aca7e 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -76,6 +76,8 @@ class DatabaseClient(Application): if not self._can_perform_action(): return False + self.num_executions += 1 # trying to connect counts as an execution + if not connection_id: connection_id = str(uuid4()) diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index ee98ea8e..cce9fe8d 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -194,6 +194,8 @@ class DataManipulationBot(Application): """ if not self._can_perform_action(): return + + self.num_executions += 1 if self.server_ip_address and self.payload: self.sys_log.info(f"{self.name}: Running") self._logon() diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 9fa86328..90eda426 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -80,6 +80,8 @@ class WebBrowser(Application): if not self._can_perform_action(): return False + self.num_executions += 1 # trying to connect counts as an execution + # reset latest response self.latest_response = HttpResponsePacket(status_code=HttpStatusCode.NOT_FOUND) diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 4defc80c..05824834 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -1,7 +1,9 @@ import pytest +from primaite.simulator.file_system.file import File from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.file_system.file_type import FileType +from primaite.simulator.file_system.folder import Folder def test_create_folder_and_file(file_system): @@ -14,8 +16,15 @@ def test_create_folder_and_file(file_system): assert len(file_system.get_folder("test_folder").files) == 1 + assert file_system.num_file_creations == 1 + assert file_system.get_folder("test_folder").get_file("test_file.txt") + file_system.apply_timestep(0) + + # num file creations should reset + assert file_system.num_file_creations == 0 + file_system.show(full=True) @@ -23,24 +32,37 @@ def test_create_file_no_folder(file_system): """Tests that creating a file without a folder creates a folder and sets that as the file's parent.""" file = file_system.create_file(file_name="test_file.txt", size=10) assert len(file_system.folders) is 1 + assert file_system.num_file_creations == 1 assert file_system.get_folder("root").get_file("test_file.txt") == file assert file_system.get_folder("root").get_file("test_file.txt").file_type == FileType.TXT assert file_system.get_folder("root").get_file("test_file.txt").size == 10 + file_system.apply_timestep(0) + + # num file creations should reset + assert file_system.num_file_creations == 0 + file_system.show(full=True) def test_delete_file(file_system): """Tests that a file can be deleted.""" - file_system.create_file(file_name="test_file.txt") + file = file_system.create_file(file_name="test_file.txt") assert len(file_system.folders) == 1 assert len(file_system.get_folder("root").files) == 1 file_system.delete_file(folder_name="root", file_name="test_file.txt") + assert file.num_access == 1 + assert file_system.num_file_deletions == 1 assert len(file_system.folders) == 1 assert len(file_system.get_folder("root").files) == 0 assert len(file_system.get_folder("root").deleted_files) == 1 + file_system.apply_timestep(0) + + # num file deletions should reset + assert file_system.num_file_deletions == 0 + file_system.show(full=True) @@ -54,6 +76,7 @@ def test_delete_non_existent_file(file_system): # deleting should not change how many files are in folder file_system.delete_file(folder_name="root", file_name="does_not_exist!") + assert file_system.num_file_deletions == 0 # should still only be one folder assert len(file_system.folders) == 1 @@ -96,6 +119,7 @@ def test_create_duplicate_file(file_system): assert len(file_system.folders) is 2 file_system.create_file(file_name="test_file.txt", folder_name="test_folder") + assert file_system.num_file_creations == 1 assert len(file_system.get_folder("test_folder").files) == 1 @@ -103,6 +127,7 @@ def test_create_duplicate_file(file_system): file_system.create_file(file_name="test_file.txt", folder_name="test_folder") assert len(file_system.get_folder("test_folder").files) == 1 + assert file_system.num_file_creations == 1 file_system.show(full=True) @@ -136,13 +161,24 @@ def test_move_file(file_system): assert len(file_system.get_folder("src_folder").files) == 1 assert len(file_system.get_folder("dst_folder").files) == 0 + assert file_system.num_file_deletions == 0 + assert file_system.num_file_creations == 1 file_system.move_file(src_folder_name="src_folder", src_file_name="test_file.txt", dst_folder_name="dst_folder") + assert file_system.num_file_deletions == 1 + assert file_system.num_file_creations == 2 + assert file.num_access == 1 assert len(file_system.get_folder("src_folder").files) == 0 assert len(file_system.get_folder("dst_folder").files) == 1 assert file_system.get_file("dst_folder", "test_file.txt").uuid == original_uuid + file_system.apply_timestep(0) + + # num file creations and deletions should reset + assert file_system.num_file_creations == 0 + assert file_system.num_file_deletions == 0 + file_system.show(full=True) @@ -152,17 +188,25 @@ def test_copy_file(file_system): file_system.create_folder(folder_name="dst_folder") file = file_system.create_file(file_name="test_file.txt", size=10, folder_name="src_folder", real=True) + assert file_system.num_file_creations == 1 original_uuid = file.uuid assert len(file_system.get_folder("src_folder").files) == 1 assert len(file_system.get_folder("dst_folder").files) == 0 file_system.copy_file(src_folder_name="src_folder", src_file_name="test_file.txt", dst_folder_name="dst_folder") + assert file_system.num_file_creations == 2 + assert file.num_access == 1 assert len(file_system.get_folder("src_folder").files) == 1 assert len(file_system.get_folder("dst_folder").files) == 1 assert file_system.get_file("dst_folder", "test_file.txt").uuid != original_uuid + file_system.apply_timestep(0) + + # num file creations should reset + assert file_system.num_file_creations == 0 + file_system.show(full=True) @@ -172,13 +216,17 @@ def test_get_file(file_system): file1: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder") file2: File = file_system.create_file(file_name="test_file2.txt", folder_name="test_folder") - folder.remove_file(file2) + file_system.delete_file("test_folder", "test_file2.txt") + # file 2 was accessed before being deleted + assert file2.num_access == 1 assert file_system.get_file_by_id(file_uuid=file1.uuid, folder_uuid=folder.uuid) is not None assert file_system.get_file_by_id(file_uuid=file2.uuid, folder_uuid=folder.uuid) is None assert file_system.get_file_by_id(file_uuid=file2.uuid, folder_uuid=folder.uuid, include_deleted=True) is not None assert file_system.get_file_by_id(file_uuid=file2.uuid, include_deleted=True) is not None + assert file2.num_access == 1 # cannot access deleted file + file_system.delete_folder(folder_name="test_folder") assert file_system.get_file_by_id(file_uuid=file2.uuid, include_deleted=True) is not None From d331224b455efb8a7da0b58b2f5e847e0011c00b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 8 Mar 2024 12:42:22 +0000 Subject: [PATCH 686/980] Start introducing RequestResponse --- src/primaite/interface/__init__.py | 0 src/primaite/interface/request.py | 29 +++++++++++++++++++++ src/primaite/simulator/core.py | 24 ++++++++++------- src/primaite/simulator/domain/controller.py | 1 + src/primaite/simulator/sim_container.py | 4 ++- 5 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 src/primaite/interface/__init__.py create mode 100644 src/primaite/interface/request.py diff --git a/src/primaite/interface/__init__.py b/src/primaite/interface/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/interface/request.py b/src/primaite/interface/request.py new file mode 100644 index 00000000..10ce6254 --- /dev/null +++ b/src/primaite/interface/request.py @@ -0,0 +1,29 @@ +from typing import Dict, Literal + +from pydantic import BaseModel, ConfigDict + + +class RequestResponse(BaseModel): + """Schema for generic request responses.""" + + model_config = ConfigDict(extra="forbid") + """Cannot have extra fields in the response. Anything custom goes into the data field.""" + + status: Literal["pending", "success", "failure"] = "pending" + """ + What is the current status of the request: + - pending - the request has not been received yet, or it has been received but it's still being processed. + - success - the request has successfully been received and processed. + - failure - the request could not reach it's intended target or it was rejected. + + Note that the failure status should only be used when the request cannot be processed, for instance when the + target SimComponent doesn't exist, or is in an OFF state that prevents it from accepting requests. If the + request is received by the target and the associated action is executed, but couldn't be completed due to + downstream factors, the request was still successfully received, it's just that the result wasn't what was + intended. + """ + + data: Dict = {} + """Catch-all place to provide any additional data that was generated as a response to the request.""" + # TODO: currently, status and data have default values, because I don't want to interrupt existing functionality too + # much. However, in the future we might consider making them mandatory. diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 6ab7c6e3..9ea59305 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -1,12 +1,13 @@ # flake8: noqa """Core of the PrimAITE Simulator.""" from abc import abstractmethod -from typing import Callable, Dict, List, Optional, Union +from typing import Callable, Dict, List, Literal, Optional, Union from uuid import uuid4 -from pydantic import BaseModel, ConfigDict, Field +from pydantic import BaseModel, ConfigDict, Field, validate_call from primaite import getLogger +from primaite.interface.request import RequestResponse _LOGGER = getLogger(__name__) @@ -22,7 +23,7 @@ class RequestPermissionValidator(BaseModel): @abstractmethod def __call__(self, request: List[str], context: Dict) -> bool: - """Use the request and context paramters to decide whether the request should be permitted.""" + """Use the request and context parameters to decide whether the request should be permitted.""" pass @@ -42,7 +43,7 @@ class RequestType(BaseModel): the request can be performed or not. """ - func: Callable[[List[str], Dict], None] + func: Callable[[List[str], Dict], RequestResponse] """ ``func`` is a function that accepts a request and a context dict. Typically this would be a lambda function that invokes a class method of your SimComponent. For example if the component is a node and the request type is for @@ -71,7 +72,8 @@ class RequestManager(BaseModel): request_types: Dict[str, RequestType] = {} """maps request name to an RequestType object.""" - def __call__(self, request: Callable[[List[str], Dict], None], context: Dict) -> None: + @validate_call + def __call__(self, request: List[str], context: Dict) -> RequestResponse: """ Process an request request. @@ -84,23 +86,25 @@ class RequestManager(BaseModel): :raises RuntimeError: If the request parameter does not have a valid request name as the first item. """ request_key = request[0] + request_options = request[1:] if request_key not in self.request_types: msg = ( f"Request {request} could not be processed because {request_key} is not a valid request name", "within this RequestManager", ) - _LOGGER.error(msg) - raise RuntimeError(msg) + # _LOGGER.error(msg) + # raise RuntimeError(msg) + _LOGGER.debug(msg) + return RequestResponse(status="failure", data={"reason": msg}) request_type = self.request_types[request_key] - request_options = request[1:] if not request_type.validator(request_options, context): _LOGGER.debug(f"Request {request} was denied due to insufficient permissions") - return + return RequestResponse(status="failure", data={"reason": "request validation failed"}) - request_type.func(request_options, context) + return request_type.func(request_options, context) def add_request(self, name: str, request_type: RequestType) -> None: """ diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index bc428743..0936b5f8 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -87,6 +87,7 @@ class DomainController(SimComponent): "account", RequestType( func=lambda request, context: self.accounts[request.pop(0)].apply_request(request, context), + # TODO: not sure what should get returned here, revisit validator=GroupMembershipValidator(allowed_groups=[AccountGroup.DOMAIN_ADMIN]), ), ) diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index a2285d92..2f603f3a 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -1,5 +1,6 @@ from typing import Dict +from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.domain.controller import DomainController from primaite.simulator.network.container import Network @@ -31,7 +32,8 @@ class Simulation(SimComponent): rm.add_request("network", RequestType(func=self.network._request_manager)) # pass through domain requests to the domain object rm.add_request("domain", RequestType(func=self.domain._request_manager)) - rm.add_request("do_nothing", RequestType(func=lambda request, context: ())) + # if 'do_nothing' is requested, just return a success + rm.add_request("do_nothing", RequestType(func=lambda request, context: RequestResponse(status="success"))) return rm def describe_state(self) -> Dict: From b13725721d2a636e77334954a1f59de16c11fcbb Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 8 Mar 2024 13:49:00 +0000 Subject: [PATCH 687/980] #2350: splitting observations into separate files --- src/primaite/game/agent/interface.py | 21 +- .../game/agent/observations/__init__.py | 0 .../agent/observations/agent_observations.py | 188 ++++++++++++++ .../agent/observations/observation_manager.py | 73 ++++++ .../agent/{ => observations}/observations.py | 234 ------------------ .../game/agent/scripted_agents/__init__.py | 0 .../data_manipulation_bot.py | 0 .../probabilistic_agent.py} | 2 +- .../agent/scripted_agents/random_agent.py | 21 ++ src/primaite/game/game.py | 6 +- tests/conftest.py | 3 +- ...software_installation_and_configuration.py | 2 +- .../game_layer/test_actions.py | 18 +- .../game_layer/test_observations.py | 2 +- .../network/test_capture_nmne.py | 2 +- .../_game/_agent/test_probabilistic_agent.py | 5 +- 16 files changed, 300 insertions(+), 277 deletions(-) create mode 100644 src/primaite/game/agent/observations/__init__.py create mode 100644 src/primaite/game/agent/observations/agent_observations.py create mode 100644 src/primaite/game/agent/observations/observation_manager.py rename src/primaite/game/agent/{ => observations}/observations.py (79%) create mode 100644 src/primaite/game/agent/scripted_agents/__init__.py rename src/primaite/game/agent/{ => scripted_agents}/data_manipulation_bot.py (100%) rename src/primaite/game/agent/{scripted_agents.py => scripted_agents/probabilistic_agent.py} (97%) create mode 100644 src/primaite/game/agent/scripted_agents/random_agent.py diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 88848479..e641fabb 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -6,7 +6,7 @@ from gymnasium.core import ActType, ObsType from pydantic import BaseModel, model_validator from primaite.game.agent.actions import ActionManager -from primaite.game.agent.observations import ObservationManager +from primaite.game.agent.observations.observation_manager import ObservationManager from primaite.game.agent.rewards import RewardFunction if TYPE_CHECKING: @@ -146,23 +146,10 @@ class AbstractAgent(ABC): class AbstractScriptedAgent(AbstractAgent): """Base class for actors which generate their own behaviour.""" - pass - - -class RandomAgent(AbstractScriptedAgent): - """Agent that ignores its observation and acts completely at random.""" - + @abstractmethod def get_action(self, obs: ObsType, timestep: int = 0) -> Tuple[str, Dict]: - """Sample the action space randomly. - - :param obs: Current observation for this agent, not used in RandomAgent - :type obs: ObsType - :param timestep: The current simulation timestep, not used in RandomAgent - :type timestep: int - :return: Action formatted in CAOS format - :rtype: Tuple[str, Dict] - """ - return self.action_manager.get_action(self.action_manager.space.sample()) + """Return an action to be taken in the environment.""" + return super().get_action(obs=obs, timestep=timestep) class ProxyAgent(AbstractAgent): diff --git a/src/primaite/game/agent/observations/__init__.py b/src/primaite/game/agent/observations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/game/agent/observations/agent_observations.py b/src/primaite/game/agent/observations/agent_observations.py new file mode 100644 index 00000000..522cdb59 --- /dev/null +++ b/src/primaite/game/agent/observations/agent_observations.py @@ -0,0 +1,188 @@ +from typing import Dict, List, Optional, Tuple, TYPE_CHECKING + +from gymnasium import spaces + +from primaite.game.agent.observations.observations import ( + AbstractObservation, + AclObservation, + ICSObservation, + LinkObservation, + NodeObservation, + NullObservation, +) + +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame + + +class UC2BlueObservation(AbstractObservation): + """Container for all observations used by the blue agent in UC2. + + TODO: there's no real need for a UC2 blue container class, we should be able to simply use the observation handler + for the purpose of compiling several observation components. + """ + + def __init__( + self, + nodes: List[NodeObservation], + links: List[LinkObservation], + acl: AclObservation, + ics: ICSObservation, + where: Optional[List[str]] = None, + ) -> None: + """Initialise UC2 blue observation. + + :param nodes: List of node observations + :type nodes: List[NodeObservation] + :param links: List of link observations + :type links: List[LinkObservation] + :param acl: The Access Control List observation + :type acl: AclObservation + :param ics: The ICS observation + :type ics: ICSObservation + :param where: Where in the simulation state dict to find information. Not used in this particular observation + because it only compiles other observations and doesn't contribute any new information, defaults to None + :type where: Optional[List[str]], optional + """ + super().__init__() + self.where: Optional[Tuple[str]] = where + + self.nodes: List[NodeObservation] = nodes + self.links: List[LinkObservation] = links + self.acl: AclObservation = acl + self.ics: ICSObservation = ics + + self.default_observation: Dict = { + "NODES": {i + 1: n.default_observation for i, n in enumerate(self.nodes)}, + "LINKS": {i + 1: l.default_observation for i, l in enumerate(self.links)}, + "ACL": self.acl.default_observation, + "ICS": self.ics.default_observation, + } + + def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ + if self.where is None: + return self.default_observation + + obs = {} + obs["NODES"] = {i + 1: node.observe(state) for i, node in enumerate(self.nodes)} + obs["LINKS"] = {i + 1: link.observe(state) for i, link in enumerate(self.links)} + obs["ACL"] = self.acl.observe(state) + obs["ICS"] = self.ics.observe(state) + + return obs + + @property + def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Space + :rtype: spaces.Space + """ + return spaces.Dict( + { + "NODES": spaces.Dict({i + 1: node.space for i, node in enumerate(self.nodes)}), + "LINKS": spaces.Dict({i + 1: link.space for i, link in enumerate(self.links)}), + "ACL": self.acl.space, + "ICS": self.ics.space, + } + ) + + @classmethod + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "UC2BlueObservation": + """Create UC2 blue observation from a config. + + :param config: Dictionary containing the configuration for this UC2 blue observation. This includes the nodes, + links, ACL and ICS observations. + :type config: Dict + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame + :return: Constructed UC2 blue observation + :rtype: UC2BlueObservation + """ + node_configs = config["nodes"] + + num_services_per_node = config["num_services_per_node"] + num_folders_per_node = config["num_folders_per_node"] + num_files_per_folder = config["num_files_per_folder"] + num_nics_per_node = config["num_nics_per_node"] + nodes = [ + NodeObservation.from_config( + config=n, + game=game, + num_services_per_node=num_services_per_node, + num_folders_per_node=num_folders_per_node, + num_files_per_folder=num_files_per_folder, + num_nics_per_node=num_nics_per_node, + ) + for n in node_configs + ] + + link_configs = config["links"] + links = [LinkObservation.from_config(config=link, game=game) for link in link_configs] + + acl_config = config["acl"] + acl = AclObservation.from_config(config=acl_config, game=game) + + ics_config = config["ics"] + ics = ICSObservation.from_config(config=ics_config, game=game) + new = cls(nodes=nodes, links=links, acl=acl, ics=ics, where=["network"]) + return new + + +class UC2RedObservation(AbstractObservation): + """Container for all observations used by the red agent in UC2.""" + + def __init__(self, nodes: List[NodeObservation], where: Optional[List[str]] = None) -> None: + super().__init__() + self.where: Optional[List[str]] = where + self.nodes: List[NodeObservation] = nodes + + self.default_observation: Dict = { + "NODES": {i + 1: n.default_observation for i, n in enumerate(self.nodes)}, + } + + def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation.""" + if self.where is None: + return self.default_observation + + obs = {} + obs["NODES"] = {i + 1: node.observe(state) for i, node in enumerate(self.nodes)} + return obs + + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" + return spaces.Dict( + { + "NODES": spaces.Dict({i + 1: node.space for i, node in enumerate(self.nodes)}), + } + ) + + @classmethod + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "UC2RedObservation": + """ + Create UC2 red observation from a config. + + :param config: Dictionary containing the configuration for this UC2 red observation. + :type config: Dict + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame + """ + node_configs = config["nodes"] + nodes = [NodeObservation.from_config(config=cfg, game=game) for cfg in node_configs] + return cls(nodes=nodes, where=["network"]) + + +class UC2GreenObservation(NullObservation): + """Green agent observation. As the green agent's actions don't depend on the observation, this is empty.""" + + pass diff --git a/src/primaite/game/agent/observations/observation_manager.py b/src/primaite/game/agent/observations/observation_manager.py new file mode 100644 index 00000000..400345fa --- /dev/null +++ b/src/primaite/game/agent/observations/observation_manager.py @@ -0,0 +1,73 @@ +from typing import Dict, TYPE_CHECKING + +from gymnasium.core import ObsType + +from primaite.game.agent.observations.agent_observations import ( + UC2BlueObservation, + UC2GreenObservation, + UC2RedObservation, +) +from primaite.game.agent.observations.observations import AbstractObservation + +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame + + +class ObservationManager: + """ + Manage the observations of an Agent. + + The observation space has the purpose of: + 1. Reading the outputted state from the PrimAITE Simulation. + 2. Selecting parts of the simulation state that are requested by the simulation config + 3. Formatting this information so an agent can use it to make decisions. + """ + + # TODO: Dear code reader: This class currently doesn't do much except hold an observation object. It will be changed + # to have more of it's own behaviour, and it will replace UC2BlueObservation and UC2RedObservation during the next + # refactor. + + def __init__(self, observation: AbstractObservation) -> None: + """Initialise observation space. + + :param observation: Observation object + :type observation: AbstractObservation + """ + self.obs: AbstractObservation = observation + self.current_observation: ObsType + + def update(self, state: Dict) -> Dict: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + """ + self.current_observation = self.obs.observe(state) + return self.current_observation + + @property + def space(self) -> None: + """Gymnasium space object describing the observation space shape.""" + return self.obs.space + + @classmethod + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "ObservationManager": + """Create observation space from a config. + + :param config: Dictionary containing the configuration for this observation space. + It should contain the key 'type' which selects which observation class to use (from a choice of: + UC2BlueObservation, UC2RedObservation, UC2GreenObservation) + The other key is 'options' which are passed to the constructor of the selected observation class. + :type config: Dict + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame + """ + if config["type"] == "UC2BlueObservation": + return cls(UC2BlueObservation.from_config(config.get("options", {}), game=game)) + elif config["type"] == "UC2RedObservation": + return cls(UC2RedObservation.from_config(config.get("options", {}), game=game)) + elif config["type"] == "UC2GreenObservation": + return cls(UC2GreenObservation.from_config(config.get("options", {}), game=game)) + else: + raise ValueError("Observation space type invalid") diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations/observations.py similarity index 79% rename from src/primaite/game/agent/observations.py rename to src/primaite/game/agent/observations/observations.py index 82e11fe0..6d6614f4 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations/observations.py @@ -4,7 +4,6 @@ from ipaddress import IPv4Address from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium import spaces -from gymnasium.core import ObsType from primaite import getLogger from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE @@ -822,236 +821,3 @@ class ICSObservation(NullObservation): """ICS observation placeholder, currently not implemented so always returns a single 0.""" pass - - -class UC2BlueObservation(AbstractObservation): - """Container for all observations used by the blue agent in UC2. - - TODO: there's no real need for a UC2 blue container class, we should be able to simply use the observation handler - for the purpose of compiling several observation components. - """ - - def __init__( - self, - nodes: List[NodeObservation], - links: List[LinkObservation], - acl: AclObservation, - ics: ICSObservation, - where: Optional[List[str]] = None, - ) -> None: - """Initialise UC2 blue observation. - - :param nodes: List of node observations - :type nodes: List[NodeObservation] - :param links: List of link observations - :type links: List[LinkObservation] - :param acl: The Access Control List observation - :type acl: AclObservation - :param ics: The ICS observation - :type ics: ICSObservation - :param where: Where in the simulation state dict to find information. Not used in this particular observation - because it only compiles other observations and doesn't contribute any new information, defaults to None - :type where: Optional[List[str]], optional - """ - super().__init__() - self.where: Optional[Tuple[str]] = where - - self.nodes: List[NodeObservation] = nodes - self.links: List[LinkObservation] = links - self.acl: AclObservation = acl - self.ics: ICSObservation = ics - - self.default_observation: Dict = { - "NODES": {i + 1: n.default_observation for i, n in enumerate(self.nodes)}, - "LINKS": {i + 1: l.default_observation for i, l in enumerate(self.links)}, - "ACL": self.acl.default_observation, - "ICS": self.ics.default_observation, - } - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict - """ - if self.where is None: - return self.default_observation - - obs = {} - obs["NODES"] = {i + 1: node.observe(state) for i, node in enumerate(self.nodes)} - obs["LINKS"] = {i + 1: link.observe(state) for i, link in enumerate(self.links)} - obs["ACL"] = self.acl.observe(state) - obs["ICS"] = self.ics.observe(state) - - return obs - - @property - def space(self) -> spaces.Space: - """ - Gymnasium space object describing the observation space shape. - - :return: Space - :rtype: spaces.Space - """ - return spaces.Dict( - { - "NODES": spaces.Dict({i + 1: node.space for i, node in enumerate(self.nodes)}), - "LINKS": spaces.Dict({i + 1: link.space for i, link in enumerate(self.links)}), - "ACL": self.acl.space, - "ICS": self.ics.space, - } - ) - - @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "UC2BlueObservation": - """Create UC2 blue observation from a config. - - :param config: Dictionary containing the configuration for this UC2 blue observation. This includes the nodes, - links, ACL and ICS observations. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :return: Constructed UC2 blue observation - :rtype: UC2BlueObservation - """ - node_configs = config["nodes"] - - num_services_per_node = config["num_services_per_node"] - num_folders_per_node = config["num_folders_per_node"] - num_files_per_folder = config["num_files_per_folder"] - num_nics_per_node = config["num_nics_per_node"] - nodes = [ - NodeObservation.from_config( - config=n, - game=game, - num_services_per_node=num_services_per_node, - num_folders_per_node=num_folders_per_node, - num_files_per_folder=num_files_per_folder, - num_nics_per_node=num_nics_per_node, - ) - for n in node_configs - ] - - link_configs = config["links"] - links = [LinkObservation.from_config(config=link, game=game) for link in link_configs] - - acl_config = config["acl"] - acl = AclObservation.from_config(config=acl_config, game=game) - - ics_config = config["ics"] - ics = ICSObservation.from_config(config=ics_config, game=game) - new = cls(nodes=nodes, links=links, acl=acl, ics=ics, where=["network"]) - return new - - -class UC2RedObservation(AbstractObservation): - """Container for all observations used by the red agent in UC2.""" - - def __init__(self, nodes: List[NodeObservation], where: Optional[List[str]] = None) -> None: - super().__init__() - self.where: Optional[List[str]] = where - self.nodes: List[NodeObservation] = nodes - - self.default_observation: Dict = { - "NODES": {i + 1: n.default_observation for i, n in enumerate(self.nodes)}, - } - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation.""" - if self.where is None: - return self.default_observation - - obs = {} - obs["NODES"] = {i + 1: node.observe(state) for i, node in enumerate(self.nodes)} - return obs - - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" - return spaces.Dict( - { - "NODES": spaces.Dict({i + 1: node.space for i, node in enumerate(self.nodes)}), - } - ) - - @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "UC2RedObservation": - """ - Create UC2 red observation from a config. - - :param config: Dictionary containing the configuration for this UC2 red observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - """ - node_configs = config["nodes"] - nodes = [NodeObservation.from_config(config=cfg, game=game) for cfg in node_configs] - return cls(nodes=nodes, where=["network"]) - - -class UC2GreenObservation(NullObservation): - """Green agent observation. As the green agent's actions don't depend on the observation, this is empty.""" - - pass - - -class ObservationManager: - """ - Manage the observations of an Agent. - - The observation space has the purpose of: - 1. Reading the outputted state from the PrimAITE Simulation. - 2. Selecting parts of the simulation state that are requested by the simulation config - 3. Formatting this information so an agent can use it to make decisions. - """ - - # TODO: Dear code reader: This class currently doesn't do much except hold an observation object. It will be changed - # to have more of it's own behaviour, and it will replace UC2BlueObservation and UC2RedObservation during the next - # refactor. - - def __init__(self, observation: AbstractObservation) -> None: - """Initialise observation space. - - :param observation: Observation object - :type observation: AbstractObservation - """ - self.obs: AbstractObservation = observation - self.current_observation: ObsType - - def update(self, state: Dict) -> Dict: - """ - Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary - :type state: Dict - """ - self.current_observation = self.obs.observe(state) - return self.current_observation - - @property - def space(self) -> None: - """Gymnasium space object describing the observation space shape.""" - return self.obs.space - - @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "ObservationManager": - """Create observation space from a config. - - :param config: Dictionary containing the configuration for this observation space. - It should contain the key 'type' which selects which observation class to use (from a choice of: - UC2BlueObservation, UC2RedObservation, UC2GreenObservation) - The other key is 'options' which are passed to the constructor of the selected observation class. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - """ - if config["type"] == "UC2BlueObservation": - return cls(UC2BlueObservation.from_config(config.get("options", {}), game=game)) - elif config["type"] == "UC2RedObservation": - return cls(UC2RedObservation.from_config(config.get("options", {}), game=game)) - elif config["type"] == "UC2GreenObservation": - return cls(UC2GreenObservation.from_config(config.get("options", {}), game=game)) - else: - raise ValueError("Observation space type invalid") diff --git a/src/primaite/game/agent/scripted_agents/__init__.py b/src/primaite/game/agent/scripted_agents/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/primaite/game/agent/data_manipulation_bot.py b/src/primaite/game/agent/scripted_agents/data_manipulation_bot.py similarity index 100% rename from src/primaite/game/agent/data_manipulation_bot.py rename to src/primaite/game/agent/scripted_agents/data_manipulation_bot.py diff --git a/src/primaite/game/agent/scripted_agents.py b/src/primaite/game/agent/scripted_agents/probabilistic_agent.py similarity index 97% rename from src/primaite/game/agent/scripted_agents.py rename to src/primaite/game/agent/scripted_agents/probabilistic_agent.py index 5111df32..9cddc978 100644 --- a/src/primaite/game/agent/scripted_agents.py +++ b/src/primaite/game/agent/scripted_agents/probabilistic_agent.py @@ -7,7 +7,7 @@ from gymnasium.core import ObsType from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractScriptedAgent -from primaite.game.agent.observations import ObservationManager +from primaite.game.agent.observations.observation_manager import ObservationManager from primaite.game.agent.rewards import RewardFunction diff --git a/src/primaite/game/agent/scripted_agents/random_agent.py b/src/primaite/game/agent/scripted_agents/random_agent.py new file mode 100644 index 00000000..34a4b5ac --- /dev/null +++ b/src/primaite/game/agent/scripted_agents/random_agent.py @@ -0,0 +1,21 @@ +from typing import Dict, Tuple + +from gymnasium.core import ObsType + +from primaite.game.agent.interface import AbstractScriptedAgent + + +class RandomAgent(AbstractScriptedAgent): + """Agent that ignores its observation and acts completely at random.""" + + def get_action(self, obs: ObsType, timestep: int = 0) -> Tuple[str, Dict]: + """Sample the action space randomly. + + :param obs: Current observation for this agent, not used in RandomAgent + :type obs: ObsType + :param timestep: The current simulation timestep, not used in RandomAgent + :type timestep: int + :return: Action formatted in CAOS format + :rtype: Tuple[str, Dict] + """ + return self.action_manager.get_action(self.action_manager.space.sample()) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 394a8154..33f9186b 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -6,11 +6,11 @@ from pydantic import BaseModel, ConfigDict from primaite import getLogger from primaite.game.agent.actions import ActionManager -from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent -from primaite.game.agent.observations import ObservationManager +from primaite.game.agent.observations.observation_manager import ObservationManager from primaite.game.agent.rewards import RewardFunction -from primaite.game.agent.scripted_agents import ProbabilisticAgent +from primaite.game.agent.scripted_agents.data_manipulation_bot import DataManipulationAgent +from primaite.game.agent.scripted_agents.probabilistic_agent import ProbabilisticAgent from primaite.simulator.network.hardware.base import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC diff --git a/tests/conftest.py b/tests/conftest.py index a117a1ef..20600e73 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,7 +10,8 @@ from _pytest.monkeypatch import MonkeyPatch from primaite import getLogger, PRIMAITE_PATHS from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractAgent -from primaite.game.agent.observations import ICSObservation, ObservationManager +from primaite.game.agent.observations.observation_manager import ObservationManager +from primaite.game.agent.observations.observations import ICSObservation from primaite.game.agent.rewards import RewardFunction from primaite.game.game import PrimaiteGame from primaite.session.session import PrimaiteSession diff --git a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py index 3aff59af..f993af5f 100644 --- a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py +++ b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py @@ -5,8 +5,8 @@ from typing import Union import yaml from primaite.config.load import data_manipulation_config_path -from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import ProxyAgent, RandomAgent +from primaite.game.agent.scripted_agents.data_manipulation_bot import DataManipulationAgent from primaite.game.game import APPLICATION_TYPES_MAPPING, PrimaiteGame, SERVICE_TYPES_MAPPING from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.host.computer import Computer diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 8911632c..740fb491 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -10,28 +10,14 @@ # 4. Check that the simulation has changed in the way that I expect. # 5. Repeat for all actions. -from typing import Dict, Tuple +from typing import Tuple import pytest -from primaite.game.agent.actions import ActionManager -from primaite.game.agent.interface import AbstractAgent, ProxyAgent -from primaite.game.agent.observations import ICSObservation, ObservationManager -from primaite.game.agent.rewards import RewardFunction +from primaite.game.agent.interface import ProxyAgent from primaite.game.game import PrimaiteGame from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus -from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState -from primaite.simulator.network.hardware.nodes.host.computer import Computer -from primaite.simulator.network.hardware.nodes.host.server import Server -from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router -from primaite.simulator.network.hardware.nodes.network.switch import Switch -from primaite.simulator.network.transmission.network_layer import IPProtocol -from primaite.simulator.network.transmission.transport_layer import Port -from primaite.simulator.sim_container import Simulation from primaite.simulator.system.applications.web_browser import WebBrowser -from primaite.simulator.system.services.dns.dns_client import DNSClient -from primaite.simulator.system.services.dns.dns_server import DNSServer -from primaite.simulator.system.services.web_server.web_server import WebServer from primaite.simulator.system.software import SoftwareHealthState diff --git a/tests/integration_tests/game_layer/test_observations.py b/tests/integration_tests/game_layer/test_observations.py index d1301759..b6aed30b 100644 --- a/tests/integration_tests/game_layer/test_observations.py +++ b/tests/integration_tests/game_layer/test_observations.py @@ -1,6 +1,6 @@ from gymnasium import spaces -from primaite.game.agent.observations import FileObservation +from primaite.game.agent.observations.observations import FileObservation from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.sim_container import Simulation diff --git a/tests/integration_tests/network/test_capture_nmne.py b/tests/integration_tests/network/test_capture_nmne.py index 698bfc72..4bbde32f 100644 --- a/tests/integration_tests/network/test_capture_nmne.py +++ b/tests/integration_tests/network/test_capture_nmne.py @@ -1,4 +1,4 @@ -from primaite.game.agent.observations import NicObservation +from primaite.game.agent.observations.observations import NicObservation from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.nmne import set_nmne_config from primaite.simulator.sim_container import Simulation diff --git a/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py b/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py index 73228e36..c556cfad 100644 --- a/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py +++ b/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py @@ -1,7 +1,8 @@ from primaite.game.agent.actions import ActionManager -from primaite.game.agent.observations import ICSObservation, ObservationManager +from primaite.game.agent.observations.observation_manager import ObservationManager +from primaite.game.agent.observations.observations import ICSObservation from primaite.game.agent.rewards import RewardFunction -from primaite.game.agent.scripted_agents import ProbabilisticAgent +from primaite.game.agent.scripted_agents.probabilistic_agent import ProbabilisticAgent def test_probabilistic_agent(): From ba58204542ffce55d49a1a8107c543f9ebc99ad0 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 8 Mar 2024 14:08:35 +0000 Subject: [PATCH 688/980] #2350: split observations into smaller files --- .../agent/observations/agent_observations.py | 2 +- .../observations/file_system_observations.py | 177 ++++++++ .../agent/observations/node_observations.py | 199 +++++++++ .../game/agent/observations/observations.py | 412 ------------------ .../observations/software_observation.py | 71 +++ .../game_layer/test_observations.py | 2 +- 6 files changed, 449 insertions(+), 414 deletions(-) create mode 100644 src/primaite/game/agent/observations/file_system_observations.py create mode 100644 src/primaite/game/agent/observations/node_observations.py create mode 100644 src/primaite/game/agent/observations/software_observation.py diff --git a/src/primaite/game/agent/observations/agent_observations.py b/src/primaite/game/agent/observations/agent_observations.py index 522cdb59..70a83881 100644 --- a/src/primaite/game/agent/observations/agent_observations.py +++ b/src/primaite/game/agent/observations/agent_observations.py @@ -2,12 +2,12 @@ from typing import Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium import spaces +from primaite.game.agent.observations.node_observations import NodeObservation from primaite.game.agent.observations.observations import ( AbstractObservation, AclObservation, ICSObservation, LinkObservation, - NodeObservation, NullObservation, ) diff --git a/src/primaite/game/agent/observations/file_system_observations.py b/src/primaite/game/agent/observations/file_system_observations.py new file mode 100644 index 00000000..277bc51f --- /dev/null +++ b/src/primaite/game/agent/observations/file_system_observations.py @@ -0,0 +1,177 @@ +from typing import Dict, List, Optional, Tuple, TYPE_CHECKING + +from gymnasium import spaces + +from primaite import getLogger +from primaite.game.agent.observations.observations import AbstractObservation +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE + +_LOGGER = getLogger(__name__) + +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame + + +class FileObservation(AbstractObservation): + """Observation of a file on a node in the network.""" + + def __init__(self, where: Optional[Tuple[str]] = None) -> None: + """ + Initialise file observation. + + :param where: Store information about where in the simulation state dictionary to find the relevant information. + Optional. If None, this corresponds that the file does not exist and the observation will be populated with + zeroes. + + A typical location for a file looks like this: + ['network','nodes',,'file_system', 'folders',,'files',] + :type where: Optional[List[str]] + """ + super().__init__() + self.where: Optional[Tuple[str]] = where + self.default_observation: spaces.Space = {"health_status": 0} + "Default observation is what should be returned when the file doesn't exist, e.g. after it has been deleted." + + def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ + if self.where is None: + return self.default_observation + file_state = access_from_nested_dict(state, self.where) + if file_state is NOT_PRESENT_IN_STATE: + return self.default_observation + return {"health_status": file_state["visible_status"]} + + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape. + + :return: Gymnasium space + :rtype: spaces.Space + """ + return spaces.Dict({"health_status": spaces.Discrete(6)}) + + @classmethod + def from_config(cls, config: Dict, game: "PrimaiteGame", parent_where: List[str] = None) -> "FileObservation": + """Create file observation from a config. + + :param config: Dictionary containing the configuration for this file observation. + :type config: Dict + :param game: _description_ + :type game: PrimaiteGame + :param parent_where: _description_, defaults to None + :type parent_where: _type_, optional + :return: _description_ + :rtype: _type_ + """ + return cls(where=parent_where + ["files", config["file_name"]]) + + +class FolderObservation(AbstractObservation): + """Folder observation, including files inside of the folder.""" + + def __init__( + self, where: Optional[Tuple[str]] = None, files: List[FileObservation] = [], num_files_per_folder: int = 2 + ) -> None: + """Initialise folder Observation, including files inside the folder. + + :param where: Where in the simulation state dictionary to find the relevant information for this folder. + A typical location for a file looks like this: + ['network','nodes',,'file_system', 'folders',] + :type where: Optional[List[str]] + :param max_files: As size of the space must remain static, define max files that can be in this folder + , defaults to 5 + :type max_files: int, optional + :param file_positions: Defines the positioning within the observation space of particular files. This ensures + that even if new files are created, the existing files will always occupy the same space in the observation + space. The keys must be between 1 and max_files. Providing file_positions will reserve a spot in the + observation space for a file with that name, even if it's temporarily deleted, if it reappears with the same + name, it will take the position defined in this dict. Defaults to {} + :type file_positions: Dict[int, str], optional + """ + super().__init__() + + self.where: Optional[Tuple[str]] = where + + self.files: List[FileObservation] = files + while len(self.files) < num_files_per_folder: + self.files.append(FileObservation()) + while len(self.files) > num_files_per_folder: + truncated_file = self.files.pop() + msg = f"Too many files in folder observation. Truncating file {truncated_file}" + _LOGGER.warning(msg) + + self.default_observation = { + "health_status": 0, + "FILES": {i + 1: f.default_observation for i, f in enumerate(self.files)}, + } + + def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ + if self.where is None: + return self.default_observation + folder_state = access_from_nested_dict(state, self.where) + if folder_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + health_status = folder_state["health_status"] + + obs = {} + + obs["health_status"] = health_status + obs["FILES"] = {i + 1: file.observe(state) for i, file in enumerate(self.files)} + + return obs + + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape. + + :return: Gymnasium space + :rtype: spaces.Space + """ + return spaces.Dict( + { + "health_status": spaces.Discrete(6), + "FILES": spaces.Dict({i + 1: f.space for i, f in enumerate(self.files)}), + } + ) + + @classmethod + def from_config( + cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]], num_files_per_folder: int = 2 + ) -> "FolderObservation": + """Create folder observation from a config. Also creates child file observations. + + :param config: Dictionary containing the configuration for this folder observation. Includes the name of the + folder and the files inside of it. + :type config: Dict + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame + :param parent_where: Where in the simulation state dictionary to find the information about this folder's + parent node. A typical location for a node ``where`` can be: + ['network','nodes',,'file_system'] + :type parent_where: Optional[List[str]] + :param num_files_per_folder: How many spaces for files are in this folder observation (to preserve static + observation size) , defaults to 2 + :type num_files_per_folder: int, optional + :return: Constructed folder observation + :rtype: FolderObservation + """ + where = parent_where + ["folders", config["folder_name"]] + + file_configs = config["files"] + files = [FileObservation.from_config(config=f, game=game, parent_where=where) for f in file_configs] + + return cls(where=where, files=files, num_files_per_folder=num_files_per_folder) diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py new file mode 100644 index 00000000..93c6765b --- /dev/null +++ b/src/primaite/game/agent/observations/node_observations.py @@ -0,0 +1,199 @@ +from typing import Dict, List, Optional, Tuple, TYPE_CHECKING + +from gymnasium import spaces + +from primaite import getLogger +from primaite.game.agent.observations.file_system_observations import FolderObservation +from primaite.game.agent.observations.observations import AbstractObservation, NicObservation +from primaite.game.agent.observations.software_observation import ServiceObservation +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE + +_LOGGER = getLogger(__name__) + +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame + + +class NodeObservation(AbstractObservation): + """Observation of a node in the network. Includes services, folders and NICs.""" + + def __init__( + self, + where: Optional[Tuple[str]] = None, + services: List[ServiceObservation] = [], + folders: List[FolderObservation] = [], + network_interfaces: List[NicObservation] = [], + logon_status: bool = False, + num_services_per_node: int = 2, + num_folders_per_node: int = 2, + num_files_per_folder: int = 2, + num_nics_per_node: int = 2, + ) -> None: + """ + Configurable observation for a node in the simulation. + + :param where: Where in the simulation state dictionary for find relevant information for this observation. + A typical location for a node looks like this: + ['network','nodes',]. If empty list, a default null observation will be output, defaults to [] + :type where: List[str], optional + :param services: Mapping between position in observation space and service name, defaults to {} + :type services: Dict[int,str], optional + :param max_services: Max number of services that can be presented in observation space for this node + , defaults to 2 + :type max_services: int, optional + :param folders: Mapping between position in observation space and folder name, defaults to {} + :type folders: Dict[int,str], optional + :param max_folders: Max number of folders in this node's obs space, defaults to 2 + :type max_folders: int, optional + :param network_interfaces: Mapping between position in observation space and NIC idx, defaults to {} + :type network_interfaces: Dict[int,str], optional + :param max_nics: Max number of network interfaces in this node's obs space, defaults to 5 + :type max_nics: int, optional + """ + super().__init__() + self.where: Optional[Tuple[str]] = where + + self.services: List[ServiceObservation] = services + while len(self.services) < num_services_per_node: + # add empty service observation without `where` parameter so it always returns default (blank) observation + self.services.append(ServiceObservation()) + while len(self.services) > num_services_per_node: + truncated_service = self.services.pop() + msg = f"Too many services in Node observation space for node. Truncating service {truncated_service.where}" + _LOGGER.warning(msg) + # truncate service list + + self.folders: List[FolderObservation] = folders + # add empty folder observation without `where` parameter that will always return default (blank) observations + while len(self.folders) < num_folders_per_node: + self.folders.append(FolderObservation(num_files_per_folder=num_files_per_folder)) + while len(self.folders) > num_folders_per_node: + truncated_folder = self.folders.pop() + msg = f"Too many folders in Node observation for node. Truncating service {truncated_folder.where[-1]}" + _LOGGER.warning(msg) + + self.network_interfaces: List[NicObservation] = network_interfaces + while len(self.network_interfaces) < num_nics_per_node: + self.network_interfaces.append(NicObservation()) + while len(self.network_interfaces) > num_nics_per_node: + truncated_nic = self.network_interfaces.pop() + msg = f"Too many NICs in Node observation for node. Truncating service {truncated_nic.where[-1]}" + _LOGGER.warning(msg) + + self.logon_status: bool = logon_status + + self.default_observation: Dict = { + "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, + "FOLDERS": {i + 1: f.default_observation for i, f in enumerate(self.folders)}, + "NETWORK_INTERFACES": {i + 1: n.default_observation for i, n in enumerate(self.network_interfaces)}, + "operating_status": 0, + } + if self.logon_status: + self.default_observation["logon_status"] = 0 + + def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ + if self.where is None: + return self.default_observation + + node_state = access_from_nested_dict(state, self.where) + if node_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + obs = {} + obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} + obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} + obs["operating_status"] = node_state["operating_state"] + obs["NETWORK_INTERFACES"] = { + i + 1: network_interface.observe(state) for i, network_interface in enumerate(self.network_interfaces) + } + + if self.logon_status: + obs["logon_status"] = 0 + + return obs + + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" + space_shape = { + "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), + "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), + "operating_status": spaces.Discrete(5), + "NETWORK_INTERFACES": spaces.Dict( + {i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)} + ), + } + if self.logon_status: + space_shape["logon_status"] = spaces.Discrete(3) + + return spaces.Dict(space_shape) + + @classmethod + def from_config( + cls, + config: Dict, + game: "PrimaiteGame", + parent_where: Optional[List[str]] = None, + num_services_per_node: int = 2, + num_folders_per_node: int = 2, + num_files_per_folder: int = 2, + num_nics_per_node: int = 2, + ) -> "NodeObservation": + """Create node observation from a config. Also creates child service, folder and NIC observations. + + :param config: Dictionary containing the configuration for this node observation. + :type config: Dict + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame + :param parent_where: Where in the simulation state dictionary to find the information about this node's parent + network. A typical location for it would be: ['network',] + :type parent_where: Optional[List[str]] + :param num_services_per_node: How many spaces for services are in this node observation (to preserve static + observation size) , defaults to 2 + :type num_services_per_node: int, optional + :param num_folders_per_node: How many spaces for folders are in this node observation (to preserve static + observation size) , defaults to 2 + :type num_folders_per_node: int, optional + :param num_files_per_folder: How many spaces for files are in the folder observations (to preserve static + observation size) , defaults to 2 + :type num_files_per_folder: int, optional + :return: Constructed node observation + :rtype: NodeObservation + """ + node_hostname = config["node_hostname"] + if parent_where is None: + where = ["network", "nodes", node_hostname] + else: + where = parent_where + ["nodes", node_hostname] + + svc_configs = config.get("services", {}) + services = [ServiceObservation.from_config(config=c, game=game, parent_where=where) for c in svc_configs] + folder_configs = config.get("folders", {}) + folders = [ + FolderObservation.from_config( + config=c, game=game, parent_where=where + ["file_system"], num_files_per_folder=num_files_per_folder + ) + for c in folder_configs + ] + # create some configs for the NIC observation in the format {"nic_num":1}, {"nic_num":2}, {"nic_num":3}, etc. + nic_configs = [{"nic_num": i for i in range(num_nics_per_node)}] + network_interfaces = [NicObservation.from_config(config=c, game=game, parent_where=where) for c in nic_configs] + logon_status = config.get("logon_status", False) + return cls( + where=where, + services=services, + folders=folders, + network_interfaces=network_interfaces, + logon_status=logon_status, + num_services_per_node=num_services_per_node, + num_folders_per_node=num_folders_per_node, + num_files_per_folder=num_files_per_folder, + num_nics_per_node=num_nics_per_node, + ) diff --git a/src/primaite/game/agent/observations/observations.py b/src/primaite/game/agent/observations/observations.py index 6d6614f4..10e69ea5 100644 --- a/src/primaite/game/agent/observations/observations.py +++ b/src/primaite/game/agent/observations/observations.py @@ -46,128 +46,6 @@ class AbstractObservation(ABC): pass -class FileObservation(AbstractObservation): - """Observation of a file on a node in the network.""" - - def __init__(self, where: Optional[Tuple[str]] = None) -> None: - """ - Initialise file observation. - - :param where: Store information about where in the simulation state dictionary to find the relevant information. - Optional. If None, this corresponds that the file does not exist and the observation will be populated with - zeroes. - - A typical location for a file looks like this: - ['network','nodes',,'file_system', 'folders',,'files',] - :type where: Optional[List[str]] - """ - super().__init__() - self.where: Optional[Tuple[str]] = where - self.default_observation: spaces.Space = {"health_status": 0} - "Default observation is what should be returned when the file doesn't exist, e.g. after it has been deleted." - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict - """ - if self.where is None: - return self.default_observation - file_state = access_from_nested_dict(state, self.where) - if file_state is NOT_PRESENT_IN_STATE: - return self.default_observation - return {"health_status": file_state["visible_status"]} - - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape. - - :return: Gymnasium space - :rtype: spaces.Space - """ - return spaces.Dict({"health_status": spaces.Discrete(6)}) - - @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame", parent_where: List[str] = None) -> "FileObservation": - """Create file observation from a config. - - :param config: Dictionary containing the configuration for this file observation. - :type config: Dict - :param game: _description_ - :type game: PrimaiteGame - :param parent_where: _description_, defaults to None - :type parent_where: _type_, optional - :return: _description_ - :rtype: _type_ - """ - return cls(where=parent_where + ["files", config["file_name"]]) - - -class ServiceObservation(AbstractObservation): - """Observation of a service in the network.""" - - default_observation: spaces.Space = {"operating_status": 0, "health_status": 0} - "Default observation is what should be returned when the service doesn't exist." - - def __init__(self, where: Optional[Tuple[str]] = None) -> None: - """Initialise service observation. - - :param where: Store information about where in the simulation state dictionary to find the relevant information. - Optional. If None, this corresponds that the file does not exist and the observation will be populated with - zeroes. - - A typical location for a service looks like this: - `['network','nodes',,'services', ]` - :type where: Optional[List[str]] - """ - super().__init__() - self.where: Optional[Tuple[str]] = where - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict - """ - if self.where is None: - return self.default_observation - - service_state = access_from_nested_dict(state, self.where) - if service_state is NOT_PRESENT_IN_STATE: - return self.default_observation - return { - "operating_status": service_state["operating_state"], - "health_status": service_state["health_state_visible"], - } - - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" - return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(6)}) - - @classmethod - def from_config( - cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]] = None - ) -> "ServiceObservation": - """Create service observation from a config. - - :param config: Dictionary containing the configuration for this service observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :param parent_where: Where in the simulation state dictionary this service's parent node is located. Optional. - :type parent_where: Optional[List[str]], optional - :return: Constructed service observation - :rtype: ServiceObservation - """ - return cls(where=parent_where + ["services", config["service_name"]]) - - class LinkObservation(AbstractObservation): """Observation of a link in the network.""" @@ -238,111 +116,6 @@ class LinkObservation(AbstractObservation): return cls(where=["network", "links", game.ref_map_links[config["link_ref"]]]) -class FolderObservation(AbstractObservation): - """Folder observation, including files inside of the folder.""" - - def __init__( - self, where: Optional[Tuple[str]] = None, files: List[FileObservation] = [], num_files_per_folder: int = 2 - ) -> None: - """Initialise folder Observation, including files inside of the folder. - - :param where: Where in the simulation state dictionary to find the relevant information for this folder. - A typical location for a file looks like this: - ['network','nodes',,'file_system', 'folders',] - :type where: Optional[List[str]] - :param max_files: As size of the space must remain static, define max files that can be in this folder - , defaults to 5 - :type max_files: int, optional - :param file_positions: Defines the positioning within the observation space of particular files. This ensures - that even if new files are created, the existing files will always occupy the same space in the observation - space. The keys must be between 1 and max_files. Providing file_positions will reserve a spot in the - observation space for a file with that name, even if it's temporarily deleted, if it reappears with the same - name, it will take the position defined in this dict. Defaults to {} - :type file_positions: Dict[int, str], optional - """ - super().__init__() - - self.where: Optional[Tuple[str]] = where - - self.files: List[FileObservation] = files - while len(self.files) < num_files_per_folder: - self.files.append(FileObservation()) - while len(self.files) > num_files_per_folder: - truncated_file = self.files.pop() - msg = f"Too many files in folder observation. Truncating file {truncated_file}" - _LOGGER.warning(msg) - - self.default_observation = { - "health_status": 0, - "FILES": {i + 1: f.default_observation for i, f in enumerate(self.files)}, - } - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict - """ - if self.where is None: - return self.default_observation - folder_state = access_from_nested_dict(state, self.where) - if folder_state is NOT_PRESENT_IN_STATE: - return self.default_observation - - health_status = folder_state["health_status"] - - obs = {} - - obs["health_status"] = health_status - obs["FILES"] = {i + 1: file.observe(state) for i, file in enumerate(self.files)} - - return obs - - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape. - - :return: Gymnasium space - :rtype: spaces.Space - """ - return spaces.Dict( - { - "health_status": spaces.Discrete(6), - "FILES": spaces.Dict({i + 1: f.space for i, f in enumerate(self.files)}), - } - ) - - @classmethod - def from_config( - cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]], num_files_per_folder: int = 2 - ) -> "FolderObservation": - """Create folder observation from a config. Also creates child file observations. - - :param config: Dictionary containing the configuration for this folder observation. Includes the name of the - folder and the files inside of it. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :param parent_where: Where in the simulation state dictionary to find the information about this folder's - parent node. A typical location for a node ``where`` can be: - ['network','nodes',,'file_system'] - :type parent_where: Optional[List[str]] - :param num_files_per_folder: How many spaces for files are in this folder observation (to preserve static - observation size) , defaults to 2 - :type num_files_per_folder: int, optional - :return: Constructed folder observation - :rtype: FolderObservation - """ - where = parent_where + ["folders", config["folder_name"]] - - file_configs = config["files"] - files = [FileObservation.from_config(config=f, game=game, parent_where=where) for f in file_configs] - - return cls(where=where, files=files, num_files_per_folder=num_files_per_folder) - - class NicObservation(AbstractObservation): """Observation of a Network Interface Card (NIC) in the network.""" @@ -444,191 +217,6 @@ class NicObservation(AbstractObservation): return cls(where=parent_where + ["NICs", config["nic_num"]]) -class NodeObservation(AbstractObservation): - """Observation of a node in the network. Includes services, folders and NICs.""" - - def __init__( - self, - where: Optional[Tuple[str]] = None, - services: List[ServiceObservation] = [], - folders: List[FolderObservation] = [], - network_interfaces: List[NicObservation] = [], - logon_status: bool = False, - num_services_per_node: int = 2, - num_folders_per_node: int = 2, - num_files_per_folder: int = 2, - num_nics_per_node: int = 2, - ) -> None: - """ - Configurable observation for a node in the simulation. - - :param where: Where in the simulation state dictionary for find relevant information for this observation. - A typical location for a node looks like this: - ['network','nodes',]. If empty list, a default null observation will be output, defaults to [] - :type where: List[str], optional - :param services: Mapping between position in observation space and service name, defaults to {} - :type services: Dict[int,str], optional - :param max_services: Max number of services that can be presented in observation space for this node - , defaults to 2 - :type max_services: int, optional - :param folders: Mapping between position in observation space and folder name, defaults to {} - :type folders: Dict[int,str], optional - :param max_folders: Max number of folders in this node's obs space, defaults to 2 - :type max_folders: int, optional - :param network_interfaces: Mapping between position in observation space and NIC idx, defaults to {} - :type network_interfaces: Dict[int,str], optional - :param max_nics: Max number of network interfaces in this node's obs space, defaults to 5 - :type max_nics: int, optional - """ - super().__init__() - self.where: Optional[Tuple[str]] = where - - self.services: List[ServiceObservation] = services - while len(self.services) < num_services_per_node: - # add empty service observation without `where` parameter so it always returns default (blank) observation - self.services.append(ServiceObservation()) - while len(self.services) > num_services_per_node: - truncated_service = self.services.pop() - msg = f"Too many services in Node observation space for node. Truncating service {truncated_service.where}" - _LOGGER.warning(msg) - # truncate service list - - self.folders: List[FolderObservation] = folders - # add empty folder observation without `where` parameter that will always return default (blank) observations - while len(self.folders) < num_folders_per_node: - self.folders.append(FolderObservation(num_files_per_folder=num_files_per_folder)) - while len(self.folders) > num_folders_per_node: - truncated_folder = self.folders.pop() - msg = f"Too many folders in Node observation for node. Truncating service {truncated_folder.where[-1]}" - _LOGGER.warning(msg) - - self.network_interfaces: List[NicObservation] = network_interfaces - while len(self.network_interfaces) < num_nics_per_node: - self.network_interfaces.append(NicObservation()) - while len(self.network_interfaces) > num_nics_per_node: - truncated_nic = self.network_interfaces.pop() - msg = f"Too many NICs in Node observation for node. Truncating service {truncated_nic.where[-1]}" - _LOGGER.warning(msg) - - self.logon_status: bool = logon_status - - self.default_observation: Dict = { - "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, - "FOLDERS": {i + 1: f.default_observation for i, f in enumerate(self.folders)}, - "NETWORK_INTERFACES": {i + 1: n.default_observation for i, n in enumerate(self.network_interfaces)}, - "operating_status": 0, - } - if self.logon_status: - self.default_observation["logon_status"] = 0 - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict - """ - if self.where is None: - return self.default_observation - - node_state = access_from_nested_dict(state, self.where) - if node_state is NOT_PRESENT_IN_STATE: - return self.default_observation - - obs = {} - obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} - obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} - obs["operating_status"] = node_state["operating_state"] - obs["NETWORK_INTERFACES"] = { - i + 1: network_interface.observe(state) for i, network_interface in enumerate(self.network_interfaces) - } - - if self.logon_status: - obs["logon_status"] = 0 - - return obs - - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" - space_shape = { - "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), - "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), - "operating_status": spaces.Discrete(5), - "NETWORK_INTERFACES": spaces.Dict( - {i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)} - ), - } - if self.logon_status: - space_shape["logon_status"] = spaces.Discrete(3) - - return spaces.Dict(space_shape) - - @classmethod - def from_config( - cls, - config: Dict, - game: "PrimaiteGame", - parent_where: Optional[List[str]] = None, - num_services_per_node: int = 2, - num_folders_per_node: int = 2, - num_files_per_folder: int = 2, - num_nics_per_node: int = 2, - ) -> "NodeObservation": - """Create node observation from a config. Also creates child service, folder and NIC observations. - - :param config: Dictionary containing the configuration for this node observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :param parent_where: Where in the simulation state dictionary to find the information about this node's parent - network. A typical location for it would be: ['network',] - :type parent_where: Optional[List[str]] - :param num_services_per_node: How many spaces for services are in this node observation (to preserve static - observation size) , defaults to 2 - :type num_services_per_node: int, optional - :param num_folders_per_node: How many spaces for folders are in this node observation (to preserve static - observation size) , defaults to 2 - :type num_folders_per_node: int, optional - :param num_files_per_folder: How many spaces for files are in the folder observations (to preserve static - observation size) , defaults to 2 - :type num_files_per_folder: int, optional - :return: Constructed node observation - :rtype: NodeObservation - """ - node_hostname = config["node_hostname"] - if parent_where is None: - where = ["network", "nodes", node_hostname] - else: - where = parent_where + ["nodes", node_hostname] - - svc_configs = config.get("services", {}) - services = [ServiceObservation.from_config(config=c, game=game, parent_where=where) for c in svc_configs] - folder_configs = config.get("folders", {}) - folders = [ - FolderObservation.from_config( - config=c, game=game, parent_where=where + ["file_system"], num_files_per_folder=num_files_per_folder - ) - for c in folder_configs - ] - # create some configs for the NIC observation in the format {"nic_num":1}, {"nic_num":2}, {"nic_num":3}, etc. - nic_configs = [{"nic_num": i for i in range(num_nics_per_node)}] - network_interfaces = [NicObservation.from_config(config=c, game=game, parent_where=where) for c in nic_configs] - logon_status = config.get("logon_status", False) - return cls( - where=where, - services=services, - folders=folders, - network_interfaces=network_interfaces, - logon_status=logon_status, - num_services_per_node=num_services_per_node, - num_folders_per_node=num_folders_per_node, - num_files_per_folder=num_files_per_folder, - num_nics_per_node=num_nics_per_node, - ) - - class AclObservation(AbstractObservation): """Observation of an Access Control List (ACL) in the network.""" diff --git a/src/primaite/game/agent/observations/software_observation.py b/src/primaite/game/agent/observations/software_observation.py new file mode 100644 index 00000000..eae9dc1f --- /dev/null +++ b/src/primaite/game/agent/observations/software_observation.py @@ -0,0 +1,71 @@ +from typing import Dict, List, Optional, Tuple, TYPE_CHECKING + +from gymnasium import spaces + +from primaite.game.agent.observations.observations import AbstractObservation +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE + +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame + + +class ServiceObservation(AbstractObservation): + """Observation of a service in the network.""" + + default_observation: spaces.Space = {"operating_status": 0, "health_status": 0} + "Default observation is what should be returned when the service doesn't exist." + + def __init__(self, where: Optional[Tuple[str]] = None) -> None: + """Initialise service observation. + + :param where: Store information about where in the simulation state dictionary to find the relevant information. + Optional. If None, this corresponds that the file does not exist and the observation will be populated with + zeroes. + + A typical location for a service looks like this: + `['network','nodes',,'services', ]` + :type where: Optional[List[str]] + """ + super().__init__() + self.where: Optional[Tuple[str]] = where + + def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ + if self.where is None: + return self.default_observation + + service_state = access_from_nested_dict(state, self.where) + if service_state is NOT_PRESENT_IN_STATE: + return self.default_observation + return { + "operating_status": service_state["operating_state"], + "health_status": service_state["health_state_visible"], + } + + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" + return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(6)}) + + @classmethod + def from_config( + cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]] = None + ) -> "ServiceObservation": + """Create service observation from a config. + + :param config: Dictionary containing the configuration for this service observation. + :type config: Dict + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame + :param parent_where: Where in the simulation state dictionary this service's parent node is located. Optional. + :type parent_where: Optional[List[str]], optional + :return: Constructed service observation + :rtype: ServiceObservation + """ + return cls(where=parent_where + ["services", config["service_name"]]) diff --git a/tests/integration_tests/game_layer/test_observations.py b/tests/integration_tests/game_layer/test_observations.py index b6aed30b..f52b52f7 100644 --- a/tests/integration_tests/game_layer/test_observations.py +++ b/tests/integration_tests/game_layer/test_observations.py @@ -1,6 +1,6 @@ from gymnasium import spaces -from primaite.game.agent.observations.observations import FileObservation +from primaite.game.agent.observations.file_system_observations import FileObservation from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.sim_container import Simulation From 61aa24212847763737e2ef2759b05343ee0b5ef4 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 8 Mar 2024 14:48:31 +0000 Subject: [PATCH 689/980] #2350: tests + application --- .../observations/software_observation.py | 92 +++++++++++++++++++ src/primaite/simulator/file_system/folder.py | 2 +- .../game_layer/observations/__init__.py | 0 .../test_file_system_observations.py | 68 ++++++++++++++ .../observations/test_node_observations.py | 43 +++++++++ .../observations/test_observations.py | 35 +++++++ .../test_software_observations.py | 66 +++++++++++++ 7 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 tests/integration_tests/game_layer/observations/__init__.py create mode 100644 tests/integration_tests/game_layer/observations/test_file_system_observations.py create mode 100644 tests/integration_tests/game_layer/observations/test_node_observations.py create mode 100644 tests/integration_tests/game_layer/observations/test_observations.py create mode 100644 tests/integration_tests/game_layer/observations/test_software_observations.py diff --git a/src/primaite/game/agent/observations/software_observation.py b/src/primaite/game/agent/observations/software_observation.py index eae9dc1f..ff61714a 100644 --- a/src/primaite/game/agent/observations/software_observation.py +++ b/src/primaite/game/agent/observations/software_observation.py @@ -69,3 +69,95 @@ class ServiceObservation(AbstractObservation): :rtype: ServiceObservation """ return cls(where=parent_where + ["services", config["service_name"]]) + + +class ApplicationObservation(AbstractObservation): + """Observation of an application in the network.""" + + default_observation: spaces.Space = {"operating_status": 0, "health_status": 0, "num_executions": 0} + "Default observation is what should be returned when the application doesn't exist." + + def __init__(self, where: Optional[Tuple[str]] = None) -> None: + """Initialise application observation. + + :param where: Store information about where in the simulation state dictionary to find the relevant information. + Optional. If None, this corresponds that the file does not exist and the observation will be populated with + zeroes. + + A typical location for a service looks like this: + `['network','nodes',,'applications', ]` + :type where: Optional[List[str]] + """ + super().__init__() + self.where: Optional[Tuple[str]] = where + + def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ + if self.where is None: + return self.default_observation + + app_state = access_from_nested_dict(state, self.where) + if app_state is NOT_PRESENT_IN_STATE: + return self.default_observation + return { + "operating_status": app_state["operating_state"], + "health_status": app_state["health_state_visible"], + "num_executions": self._categorise_num_executions(app_state["num_executions"]), + } + + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" + return spaces.Dict( + { + "operating_status": spaces.Discrete(7), + "health_status": spaces.Discrete(6), + "num_executions": spaces.Discrete(4), + } + ) + + @classmethod + def from_config( + cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]] = None + ) -> "ApplicationObservation": + """Create application observation from a config. + + :param config: Dictionary containing the configuration for this service observation. + :type config: Dict + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame + :param parent_where: Where in the simulation state dictionary this service's parent node is located. Optional. + :type parent_where: Optional[List[str]], optional + :return: Constructed service observation + :rtype: ApplicationObservation + """ + return cls(where=parent_where + ["services", config["application_name"]]) + + @classmethod + def _categorise_num_executions(cls, num_executions: int) -> int: + """ + Categorise the number of executions of an application. + + Helps classify the number of application executions into different categories. + + Current categories: + - 0: Application is never executed + - 1: Application is executed a low number of times (1-5) + - 2: Application is executed often (6-10) + - 3: Application is executed a high number of times (more than 10) + + :param: num_executions: Number of times the application is executed + """ + if num_executions > 10: + return 3 + elif num_executions > 5: + return 2 + elif num_executions > 0: + return 1 + return 0 diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 3ddc1e5f..529bfe11 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -130,7 +130,7 @@ class Folder(FileSystemItemABC): file = self.get_file_by_id(file_uuid=file_id) file.scan() if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: - self.visible_health_status = FileSystemItemHealthStatus.CORRUPT + self.health_status = FileSystemItemHealthStatus.CORRUPT self.visible_health_status = self.health_status def _reveal_to_red_timestep(self) -> None: diff --git a/tests/integration_tests/game_layer/observations/__init__.py b/tests/integration_tests/game_layer/observations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration_tests/game_layer/observations/test_file_system_observations.py b/tests/integration_tests/game_layer/observations/test_file_system_observations.py new file mode 100644 index 00000000..808007cc --- /dev/null +++ b/tests/integration_tests/game_layer/observations/test_file_system_observations.py @@ -0,0 +1,68 @@ +import pytest +from gymnasium import spaces + +from primaite.game.agent.observations.file_system_observations import FileObservation, FolderObservation +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.sim_container import Simulation + + +@pytest.fixture(scope="function") +def simulation(example_network) -> Simulation: + sim = Simulation() + + # set simulation network as example network + sim.network = example_network + + return sim + + +def test_file_observation(simulation): + """Test the file observation.""" + pc: Computer = simulation.network.get_node_by_hostname("client_1") + # create a file on the pc + file = pc.file_system.create_file(file_name="dog.png") + + dog_file_obs = FileObservation( + where=["network", "nodes", pc.hostname, "file_system", "folders", "root", "files", "dog.png"] + ) + + assert dog_file_obs.space == spaces.Dict({"health_status": spaces.Discrete(6)}) + + observation_state = dog_file_obs.observe(simulation.describe_state()) + assert observation_state.get("health_status") == 1 # good initial + + file.corrupt() + observation_state = dog_file_obs.observe(simulation.describe_state()) + assert observation_state.get("health_status") == 1 # scan file so this changes + + file.scan() + file.apply_timestep(0) # apply time step + observation_state = dog_file_obs.observe(simulation.describe_state()) + assert observation_state.get("health_status") == 3 # corrupted + + +def test_folder_observation(simulation): + """Test the folder observation.""" + pc: Computer = simulation.network.get_node_by_hostname("client_1") + # create a file and folder on the pc + folder = pc.file_system.create_folder("test_folder") + file = pc.file_system.create_file(file_name="dog.png", folder_name="test_folder") + + root_folder_obs = FolderObservation( + where=["network", "nodes", pc.hostname, "file_system", "folders", "test_folder"] + ) + + observation_state = root_folder_obs.observe(simulation.describe_state()) + assert observation_state.get("FILES") is not None + assert observation_state.get("health_status") == 1 + + file.corrupt() # corrupt just the file + observation_state = root_folder_obs.observe(simulation.describe_state()) + assert observation_state.get("health_status") == 1 # scan folder to change this + + folder.scan() + for i in range(folder.scan_duration + 1): + folder.apply_timestep(i) # apply as many timesteps as needed for a scan + + observation_state = root_folder_obs.observe(simulation.describe_state()) + assert observation_state.get("health_status") == 3 # file is corrupt therefore folder is corrupted too diff --git a/tests/integration_tests/game_layer/observations/test_node_observations.py b/tests/integration_tests/game_layer/observations/test_node_observations.py new file mode 100644 index 00000000..835202c6 --- /dev/null +++ b/tests/integration_tests/game_layer/observations/test_node_observations.py @@ -0,0 +1,43 @@ +import copy +from uuid import uuid4 + +import pytest + +from primaite.game.agent.observations.node_observations import NodeObservation +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.sim_container import Simulation + + +@pytest.fixture(scope="function") +def simulation(example_network) -> Simulation: + sim = Simulation() + + # set simulation network as example network + sim.network = example_network + + return sim + + +def test_node_observation(simulation): + """Test a Node observation.""" + pc: Computer = simulation.network.get_node_by_hostname("client_1") + + node_obs = NodeObservation(where=["network", "nodes", pc.hostname]) + + observation_state = node_obs.observe(simulation.describe_state()) + assert observation_state.get("operating_status") == 1 # computer is on + + assert observation_state.get("SERVICES") is not None + assert observation_state.get("FOLDERS") is not None + assert observation_state.get("NETWORK_INTERFACES") is not None + + # turn off computer + pc.power_off() + observation_state = node_obs.observe(simulation.describe_state()) + assert observation_state.get("operating_status") == 4 # shutting down + + for i in range(pc.shut_down_duration + 1): + pc.apply_timestep(i) + + observation_state = node_obs.observe(simulation.describe_state()) + assert observation_state.get("operating_status") == 2 diff --git a/tests/integration_tests/game_layer/observations/test_observations.py b/tests/integration_tests/game_layer/observations/test_observations.py new file mode 100644 index 00000000..eccda238 --- /dev/null +++ b/tests/integration_tests/game_layer/observations/test_observations.py @@ -0,0 +1,35 @@ +import pytest + +from primaite.game.agent.observations.observations import NicObservation +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.host_node import NIC +from primaite.simulator.sim_container import Simulation + + +@pytest.fixture(scope="function") +def simulation(example_network) -> Simulation: + sim = Simulation() + + # set simulation network as example network + sim.network = example_network + + return sim + + +def test_nic(simulation): + """Test the NIC observation.""" + pc: Computer = simulation.network.get_node_by_hostname("client_1") + + nic: NIC = pc.network_interface[1] + + nic_obs = NicObservation(where=["network", "nodes", pc.hostname, "NICs", 1]) + + observation_state = nic_obs.observe(simulation.describe_state()) + assert observation_state.get("nic_status") == 1 # enabled + assert observation_state.get("nmne") is not None + assert observation_state["nmne"].get("inbound") == 0 + assert observation_state["nmne"].get("outbound") == 0 + + nic.disable() + observation_state = nic_obs.observe(simulation.describe_state()) + assert observation_state.get("nic_status") == 2 # disabled diff --git a/tests/integration_tests/game_layer/observations/test_software_observations.py b/tests/integration_tests/game_layer/observations/test_software_observations.py new file mode 100644 index 00000000..17fc386f --- /dev/null +++ b/tests/integration_tests/game_layer/observations/test_software_observations.py @@ -0,0 +1,66 @@ +import pytest + +from primaite.game.agent.observations.software_observation import ApplicationObservation, ServiceObservation +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.sim_container import Simulation +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.applications.web_browser import WebBrowser +from primaite.simulator.system.services.ntp.ntp_server import NTPServer + + +@pytest.fixture(scope="function") +def simulation(example_network) -> Simulation: + sim = Simulation() + + # set simulation network as example network + sim.network = example_network + + return sim + + +def test_service_observation(simulation): + """Test the service observation.""" + pc: Computer = simulation.network.get_node_by_hostname("client_1") + # install software on the computer + pc.software_manager.install(NTPServer) + + ntp_server = pc.software_manager.software.get("NTPServer") + assert ntp_server + + service_obs = ServiceObservation(where=["network", "nodes", pc.hostname, "services", "NTPServer"]) + + observation_state = service_obs.observe(simulation.describe_state()) + + assert observation_state.get("health_status") == 0 + assert observation_state.get("operating_status") == 1 # running + + ntp_server.restart() + observation_state = service_obs.observe(simulation.describe_state()) + assert observation_state.get("health_status") == 0 + assert observation_state.get("operating_status") == 6 # resetting + + +def test_application_observation(simulation): + """Test the application observation.""" + pc: Computer = simulation.network.get_node_by_hostname("client_1") + # install software on the computer + pc.software_manager.install(DatabaseClient) + + web_browser: WebBrowser = pc.software_manager.software.get("WebBrowser") + assert web_browser + + app_obs = ApplicationObservation(where=["network", "nodes", pc.hostname, "applications", "WebBrowser"]) + + web_browser.close() + observation_state = app_obs.observe(simulation.describe_state()) + assert observation_state.get("health_status") == 0 + assert observation_state.get("operating_status") == 2 # stopped + assert observation_state.get("num_executions") == 0 + + web_browser.run() + web_browser.scan() # scan to update health status + web_browser.get_webpage("test") + observation_state = app_obs.observe(simulation.describe_state()) + assert observation_state.get("health_status") == 1 + assert observation_state.get("operating_status") == 1 # running + assert observation_state.get("num_executions") == 1 From beb51834f9b3c00ad37102efbe525d4fd86d6536 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 8 Mar 2024 14:58:34 +0000 Subject: [PATCH 690/980] Make all requests return a RequestResponse --- src/primaite/interface/request.py | 37 +++++--- src/primaite/simulator/core.py | 4 +- .../simulator/file_system/file_system.py | 85 +++++++++++-------- .../file_system/file_system_item_abc.py | 45 ++++++---- src/primaite/simulator/file_system/folder.py | 25 +++++- .../simulator/network/hardware/base.py | 74 ++++++++++------ .../network/hardware/nodes/network/router.py | 32 ++++--- .../system/applications/database_client.py | 3 +- .../red_applications/data_manipulation_bot.py | 18 ++-- .../applications/red_applications/dos_bot.py | 17 ++-- .../system/applications/web_browser.py | 6 +- .../simulator/system/services/service.py | 46 ++++++---- src/primaite/simulator/system/software.py | 19 +++-- 13 files changed, 275 insertions(+), 136 deletions(-) diff --git a/src/primaite/interface/request.py b/src/primaite/interface/request.py index 10ce6254..8e61c1cb 100644 --- a/src/primaite/interface/request.py +++ b/src/primaite/interface/request.py @@ -1,6 +1,9 @@ -from typing import Dict, Literal +from typing import Dict, ForwardRef, Literal -from pydantic import BaseModel, ConfigDict +from pydantic import BaseModel, ConfigDict, validate_call + +RequestResponse = ForwardRef("RequestResponse") +"""This makes it possible to type-hint RequestResponse.from_bool return type.""" class RequestResponse(BaseModel): @@ -9,21 +12,33 @@ class RequestResponse(BaseModel): model_config = ConfigDict(extra="forbid") """Cannot have extra fields in the response. Anything custom goes into the data field.""" - status: Literal["pending", "success", "failure"] = "pending" + status: Literal["pending", "success", "failure", "unreachable"] = "pending" """ What is the current status of the request: - pending - the request has not been received yet, or it has been received but it's still being processed. - - success - the request has successfully been received and processed. - - failure - the request could not reach it's intended target or it was rejected. - - Note that the failure status should only be used when the request cannot be processed, for instance when the - target SimComponent doesn't exist, or is in an OFF state that prevents it from accepting requests. If the - request is received by the target and the associated action is executed, but couldn't be completed due to - downstream factors, the request was still successfully received, it's just that the result wasn't what was - intended. + - success - the request has been received and executed successfully. + - failure - the request has been received and attempted, but execution failed. + - unreachable - the request could not reach it's intended target, either because it doesn't exist or the target + is off. """ data: Dict = {} """Catch-all place to provide any additional data that was generated as a response to the request.""" # TODO: currently, status and data have default values, because I don't want to interrupt existing functionality too # much. However, in the future we might consider making them mandatory. + + @classmethod + @validate_call + def from_bool(cls, status_bool: bool) -> RequestResponse: + """ + Construct a basic request response from a boolean. + + True maps to a success status. False maps to a failure status. + + :param status_bool: Whether to create a successful response + :type status_bool: bool + """ + if status_bool is True: + return cls(status="success", data={}) + elif status_bool is False: + return cls(status="failure", data={}) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 9ea59305..64f33f6a 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -96,7 +96,7 @@ class RequestManager(BaseModel): # _LOGGER.error(msg) # raise RuntimeError(msg) _LOGGER.debug(msg) - return RequestResponse(status="failure", data={"reason": msg}) + return RequestResponse(status="unreachable", data={"reason": msg}) request_type = self.request_types[request_key] @@ -226,7 +226,7 @@ class SimComponent(BaseModel): """ if self._request_manager is None: return - self._request_manager(request, context) + return self._request_manager(request, context) def apply_timestep(self, timestep: int) -> None: """ diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 8fd4e5d7..3ff73a80 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -7,6 +7,7 @@ from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable from primaite import getLogger +from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file import File from primaite.simulator.file_system.file_type import FileType @@ -41,12 +42,16 @@ class FileSystem(SimComponent): self._delete_manager.add_request( name="file", request_type=RequestType( - func=lambda request, context: self.delete_file(folder_name=request[0], file_name=request[1]) + func=lambda request, context: RequestResponse.from_bool( + self.delete_file(folder_name=request[0], file_name=request[1]) + ) ), ) self._delete_manager.add_request( name="folder", - request_type=RequestType(func=lambda request, context: self.delete_folder(folder_name=request[0])), + request_type=RequestType( + func=lambda request, context: RequestResponse.from_bool(self.delete_folder(folder_name=request[0])) + ), ) rm.add_request( name="delete", @@ -57,12 +62,16 @@ class FileSystem(SimComponent): self._restore_manager.add_request( name="file", request_type=RequestType( - func=lambda request, context: self.restore_file(folder_name=request[0], file_name=request[1]) + func=lambda request, context: RequestResponse( + self.restore_file(folder_name=request[0], file_name=request[1]) + ) ), ) self._restore_manager.add_request( name="folder", - request_type=RequestType(func=lambda request, context: self.restore_folder(folder_name=request[0])), + request_type=RequestType( + func=lambda request, context: RequestResponse.from_bool(self.restore_folder(folder_name=request[0])) + ), ) rm.add_request( name="restore", @@ -138,7 +147,7 @@ class FileSystem(SimComponent): ) return folder - def delete_folder(self, folder_name: str): + def delete_folder(self, folder_name: str) -> bool: """ Deletes a folder, removes it from the folders list and removes any child folders and files. @@ -146,24 +155,26 @@ class FileSystem(SimComponent): """ if folder_name == "root": self.sys_log.warning("Cannot delete the root folder.") - return + return False folder = self.get_folder(folder_name) - if folder: - # set folder to deleted state - folder.delete() - - # remove from folder list - self.folders.pop(folder.uuid) - - # add to deleted list - folder.remove_all_files() - - self.deleted_folders[folder.uuid] = folder - self.sys_log.info(f"Deleted folder /{folder.name} and its contents") - else: + if not folder: _LOGGER.debug(f"Cannot delete folder as it does not exist: {folder_name}") + return False - def delete_folder_by_id(self, folder_uuid: str): + # set folder to deleted state + folder.delete() + + # remove from folder list + self.folders.pop(folder.uuid) + + # add to deleted list + folder.remove_all_files() + + self.deleted_folders[folder.uuid] = folder + self.sys_log.info(f"Deleted folder /{folder.name} and its contents") + return True + + def delete_folder_by_id(self, folder_uuid: str) -> None: """ Deletes a folder via its uuid. @@ -297,7 +308,7 @@ class FileSystem(SimComponent): return file - def delete_file(self, folder_name: str, file_name: str): + def delete_file(self, folder_name: str, file_name: str) -> bool: """ Delete a file by its name from a specific folder. @@ -309,8 +320,10 @@ class FileSystem(SimComponent): file = folder.get_file(file_name) if file: folder.remove_file(file) + return True + return False - def delete_file_by_id(self, folder_uuid: str, file_uuid: str): + def delete_file_by_id(self, folder_uuid: str, file_uuid: str) -> None: """ Deletes a file via its uuid. @@ -327,7 +340,7 @@ class FileSystem(SimComponent): else: self.sys_log.error(f"Unable to delete file that does not exist. (id: {file_uuid})") - def move_file(self, src_folder_name: str, src_file_name: str, dst_folder_name: str): + def move_file(self, src_folder_name: str, src_file_name: str, dst_folder_name: str) -> None: """ Move a file from one folder to another. @@ -404,7 +417,7 @@ class FileSystem(SimComponent): # Agent actions ############################################################### - def scan(self, instant_scan: bool = False): + def scan(self, instant_scan: bool = False) -> None: """ Scan all the folders (and child files) in the file system. @@ -413,7 +426,7 @@ class FileSystem(SimComponent): for folder_id in self.folders: self.folders[folder_id].scan(instant_scan=instant_scan) - def reveal_to_red(self, instant_scan: bool = False): + def reveal_to_red(self, instant_scan: bool = False) -> None: """ Reveals all the folders (and child files) in the file system to the red agent. @@ -422,7 +435,7 @@ class FileSystem(SimComponent): for folder_id in self.folders: self.folders[folder_id].reveal_to_red(instant_scan=instant_scan) - def restore_folder(self, folder_name: str): + def restore_folder(self, folder_name: str) -> bool: """ Restore a folder. @@ -435,13 +448,14 @@ class FileSystem(SimComponent): if folder is None: self.sys_log.error(f"Unable to restore folder {folder_name}. Folder is not in deleted folder list.") - return + return False self.deleted_folders.pop(folder.uuid, None) folder.restore() self.folders[folder.uuid] = folder + return True - def restore_file(self, folder_name: str, file_name: str): + def restore_file(self, folder_name: str, file_name: str) -> bool: """ Restore a file. @@ -454,12 +468,15 @@ class FileSystem(SimComponent): :type: file_name: str """ folder = self.get_folder(folder_name=folder_name) + if not folder: + _LOGGER.debug(f"Cannot restore file {file_name} in folder {folder_name} as the folder does not exist.") + return False - if folder: - file = folder.get_file(file_name=file_name, include_deleted=True) + file = folder.get_file(file_name=file_name, include_deleted=True) - if file is None: - self.sys_log.error(f"Unable to restore file {file_name}. File does not exist.") - return + if not file: + msg = f"Unable to restore file {file_name}. File was not found." + self.sys_log.error(msg) + return False - folder.restore_file(file_name=file_name) + return folder.restore_file(file_name=file_name) diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py index fbe5f4b3..efac97c3 100644 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -6,6 +6,7 @@ from enum import Enum from typing import Dict, Optional from primaite import getLogger +from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.system.core.sys_log import SysLog @@ -102,12 +103,26 @@ class FileSystemItemABC(SimComponent): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() - rm.add_request(name="scan", request_type=RequestType(func=lambda request, context: self.scan())) - rm.add_request(name="checkhash", request_type=RequestType(func=lambda request, context: self.check_hash())) - rm.add_request(name="repair", request_type=RequestType(func=lambda request, context: self.repair())) - rm.add_request(name="restore", request_type=RequestType(func=lambda request, context: self.restore())) + rm.add_request( + name="scan", request_type=RequestType(func=lambda request, context: RequestResponse.from_bool(self.scan())) + ) + rm.add_request( + name="checkhash", + request_type=RequestType(func=lambda request, context: RequestResponse.from_bool(self.check_hash())), + ) + rm.add_request( + name="repair", + request_type=RequestType(func=lambda request, context: RequestResponse.from_bool(self.repair())), + ) + rm.add_request( + name="restore", + request_type=RequestType(func=lambda request, context: RequestResponse.from_bool(self.restore())), + ) - rm.add_request(name="corrupt", request_type=RequestType(func=lambda request, context: self.corrupt())) + rm.add_request( + name="corrupt", + request_type=RequestType(func=lambda request, context: RequestResponse.from_bool(self.corrupt())), + ) return rm @@ -124,9 +139,9 @@ class FileSystemItemABC(SimComponent): return convert_size(self.size) @abstractmethod - def scan(self) -> None: + def scan(self) -> bool: """Scan the folder/file - updates the visible_health_status.""" - pass + return False @abstractmethod def reveal_to_red(self) -> None: @@ -134,7 +149,7 @@ class FileSystemItemABC(SimComponent): pass @abstractmethod - def check_hash(self) -> None: + def check_hash(self) -> bool: """ Checks the has of the file to detect any changes. @@ -142,30 +157,30 @@ class FileSystemItemABC(SimComponent): Return False if corruption is detected, otherwise True """ - pass + return False @abstractmethod - def repair(self) -> None: + def repair(self) -> bool: """ Repair the FileSystemItem. True if successfully repaired. False otherwise. """ - pass + return False @abstractmethod - def corrupt(self) -> None: + def corrupt(self) -> bool: """ Corrupt the FileSystemItem. True if successfully corrupted. False otherwise. """ - pass + return False @abstractmethod - def restore(self) -> None: + def restore(self) -> bool: """Restore the file/folder to the state before it got ruined.""" - pass + return False @abstractmethod def delete(self) -> None: diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 771dc7a0..9ef1ae59 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -5,6 +5,7 @@ from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable from primaite import getLogger +from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.file_system.file import File from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC, FileSystemItemHealthStatus @@ -53,7 +54,9 @@ class Folder(FileSystemItemABC): rm = super()._init_request_manager() rm.add_request( name="delete", - request_type=RequestType(func=lambda request, context: self.remove_file_by_id(file_uuid=request[0])), + request_type=RequestType( + func=lambda request, context: RequestResponse.from_bool(self.remove_file_by_name(file_name=request[0])) + ), ) self._file_request_manager = RequestManager() rm.add_request( @@ -249,6 +252,21 @@ class Folder(FileSystemItemABC): file = self.get_file_by_id(file_uuid=file_uuid) self.remove_file(file=file) + def remove_file_by_name(self, file_name: str) -> bool: + """ + Remove a file using its name. + + :param file_name: filename + :type file_name: str + :return: Whether it was successfully removed. + :rtype: bool + """ + for f in self.files.values(): + if f.name == file_name: + self.remove_file(f) + return True + return False + def remove_all_files(self): """Removes all the files in the folder.""" for file_id in self.files: @@ -258,7 +276,7 @@ class Folder(FileSystemItemABC): self.files = {} - def restore_file(self, file_name: str): + def restore_file(self, file_name: str) -> bool: """ Restores a file. @@ -268,13 +286,14 @@ class Folder(FileSystemItemABC): file = self.get_file(file_name=file_name, include_deleted=True) if not file: self.sys_log.error(f"Unable to restore file {file_name}. File does not exist.") - return + return False file.restore() self.files[file.uuid] = file if file.deleted: self.deleted_files.pop(file.uuid) + return True def quarantine(self): """Quarantines the File System Folder.""" diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 82fae164..3349bed4 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -12,6 +12,7 @@ from pydantic import BaseModel, Field from primaite import getLogger from primaite.exceptions import NetworkError +from primaite.interface.request import RequestResponse from primaite.simulator import SIM_OUTPUT from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.domain.account import Account @@ -115,8 +116,8 @@ class NetworkInterface(SimComponent, ABC): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() - rm.add_request("enable", RequestType(func=lambda request, context: self.enable())) - rm.add_request("disable", RequestType(func=lambda request, context: self.disable())) + rm.add_request("enable", RequestType(func=lambda request, context: RequestResponse.from_bool(self.enable()))) + rm.add_request("disable", RequestType(func=lambda request, context: RequestResponse.from_bool(self.disable()))) return rm @@ -140,14 +141,16 @@ class NetworkInterface(SimComponent, ABC): return state @abstractmethod - def enable(self): + def enable(self) -> bool: """Enable the interface.""" pass + return False @abstractmethod - def disable(self): + def disable(self) -> bool: """Disable the interface.""" pass + return False def _capture_nmne(self, frame: Frame, inbound: bool = True) -> None: """ @@ -783,16 +786,28 @@ class Node(SimComponent): self._application_request_manager = RequestManager() rm.add_request("application", RequestType(func=self._application_request_manager)) - rm.add_request("scan", RequestType(func=lambda request, context: self.reveal_to_red())) + rm.add_request( + "scan", RequestType(func=lambda request, context: RequestResponse.from_bool(self.reveal_to_red())) + ) - rm.add_request("shutdown", RequestType(func=lambda request, context: self.power_off())) - rm.add_request("startup", RequestType(func=lambda request, context: self.power_on())) - rm.add_request("reset", RequestType(func=lambda request, context: self.reset())) # TODO implement node reset - rm.add_request("logon", RequestType(func=lambda request, context: ...)) # TODO implement logon request - rm.add_request("logoff", RequestType(func=lambda request, context: ...)) # TODO implement logoff request + rm.add_request( + "shutdown", RequestType(func=lambda request, context: RequestResponse.from_bool(self.power_off())) + ) + rm.add_request("startup", RequestType(func=lambda request, context: RequestResponse.from_bool(self.power_on()))) + rm.add_request( + "reset", RequestType(func=lambda request, context: RequestResponse.from_bool(self.reset())) + ) # TODO implement node reset + rm.add_request( + "logon", RequestType(func=lambda request, context: RequestResponse.from_bool(False)) + ) # TODO implement logon request + rm.add_request( + "logoff", RequestType(func=lambda request, context: RequestResponse.from_bool(False)) + ) # TODO implement logoff request self._os_request_manager = RequestManager() - self._os_request_manager.add_request("scan", RequestType(func=lambda request, context: self.scan())) + self._os_request_manager.add_request( + "scan", RequestType(func=lambda request, context: RequestResponse.from_bool(self.scan())) + ) rm.add_request("os", RequestType(func=self._os_request_manager)) return rm @@ -973,7 +988,7 @@ class Node(SimComponent): self.file_system.apply_timestep(timestep=timestep) - def scan(self) -> None: + def scan(self) -> bool: """ Scan the node and all the items within it. @@ -987,8 +1002,9 @@ class Node(SimComponent): to the red agent. """ self.node_scan_countdown = self.node_scan_duration + return True - def reveal_to_red(self) -> None: + def reveal_to_red(self) -> bool: """ Reveals the node and all the items within it to the red agent. @@ -1002,34 +1018,40 @@ class Node(SimComponent): `revealed_to_red` to `True`. """ self.red_scan_countdown = self.node_scan_duration + return True - def power_on(self): + def power_on(self) -> bool: """Power on the Node, enabling its NICs if it is in the OFF state.""" - if self.operating_state == NodeOperatingState.OFF: - self.operating_state = NodeOperatingState.BOOTING - self.start_up_countdown = self.start_up_duration - if self.start_up_duration <= 0: self.operating_state = NodeOperatingState.ON self._start_up_actions() self.sys_log.info("Power on") for network_interface in self.network_interfaces.values(): network_interface.enable() + return True + if self.operating_state == NodeOperatingState.OFF: + self.operating_state = NodeOperatingState.BOOTING + self.start_up_countdown = self.start_up_duration + return True - def power_off(self): + return False + + def power_off(self) -> bool: """Power off the Node, disabling its NICs if it is in the ON state.""" + if self.shut_down_duration <= 0: + self._shut_down_actions() + self.operating_state = NodeOperatingState.OFF + self.sys_log.info("Power off") + return True if self.operating_state == NodeOperatingState.ON: for network_interface in self.network_interfaces.values(): network_interface.disable() self.operating_state = NodeOperatingState.SHUTTING_DOWN self.shut_down_countdown = self.shut_down_duration + return True + return False - if self.shut_down_duration <= 0: - self._shut_down_actions() - self.operating_state = NodeOperatingState.OFF - self.sys_log.info("Power off") - - def reset(self): + def reset(self) -> bool: """ Resets the node. @@ -1040,6 +1062,8 @@ class Node(SimComponent): self.is_resetting = True self.sys_log.info("Resetting") self.power_off() + return True + return False def connect_nic(self, network_interface: NetworkInterface, port_name: Optional[str] = None): """ diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 7f7190fd..2fab4a3d 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -8,6 +8,7 @@ from typing import Any, Dict, List, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable from pydantic import validate_call +from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import IPWiredNetworkInterface from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState @@ -308,19 +309,24 @@ class AccessControlList(SimComponent): rm.add_request( "add_rule", RequestType( - func=lambda request, context: self.add_rule( - action=ACLAction[request[0]], - protocol=None if request[1] == "ALL" else IPProtocol[request[1]], - src_ip_address=None if request[2] == "ALL" else IPv4Address(request[2]), - src_port=None if request[3] == "ALL" else Port[request[3]], - dst_ip_address=None if request[4] == "ALL" else IPv4Address(request[4]), - dst_port=None if request[5] == "ALL" else Port[request[5]], - position=int(request[6]), + func=lambda request, context: RequestResponse.from_bool( + self.add_rule( + action=ACLAction[request[0]], + protocol=None if request[1] == "ALL" else IPProtocol[request[1]], + src_ip_address=None if request[2] == "ALL" else IPv4Address(request[2]), + src_port=None if request[3] == "ALL" else Port[request[3]], + dst_ip_address=None if request[4] == "ALL" else IPv4Address(request[4]), + dst_port=None if request[5] == "ALL" else Port[request[5]], + position=int(request[6]), + ) ) ), ) - rm.add_request("remove_rule", RequestType(func=lambda request, context: self.remove_rule(int(request[0])))) + rm.add_request( + "remove_rule", + RequestType(func=lambda request, context: RequestResponse.from_bool(self.remove_rule(int(request[0])))), + ) return rm def describe_state(self) -> Dict: @@ -366,7 +372,7 @@ class AccessControlList(SimComponent): src_port: Optional[Port] = None, dst_port: Optional[Port] = None, position: int = 0, - ) -> None: + ) -> bool: """ Adds a new ACL rule to control network traffic based on specified criteria. @@ -423,10 +429,12 @@ class AccessControlList(SimComponent): src_port=src_port, dst_port=dst_port, ) + return True else: raise ValueError(f"Cannot add ACL rule, position {position} is out of bounds.") + return False - def remove_rule(self, position: int) -> None: + def remove_rule(self, position: int) -> bool: """ Remove an ACL rule from a specific position. @@ -437,8 +445,10 @@ class AccessControlList(SimComponent): rule = self._acl[position] # noqa self._acl[position] = None del rule + return True else: raise ValueError(f"Cannot remove ACL rule, position {position} is out of bounds.") + return False def is_permitted(self, frame: Frame) -> Tuple[bool, ACLRule]: """Check if a packet with the given properties is permitted through the ACL.""" diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 7b259ff4..12148683 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -3,6 +3,7 @@ from typing import Any, Dict, Optional from uuid import uuid4 from primaite import getLogger +from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -37,7 +38,7 @@ class DatabaseClient(Application): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() - rm.add_request("execute", RequestType(func=lambda request, context: self.execute())) + rm.add_request("execute", RequestType(func=lambda request, context: RequestResponse.from_bool(self.execute()))) return rm def execute(self) -> bool: diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index ee98ea8e..f71b1465 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -4,6 +4,7 @@ from typing import Dict, Optional from primaite import getLogger from primaite.game.science import simulate_trial +from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port @@ -76,7 +77,10 @@ class DataManipulationBot(Application): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() - rm.add_request(name="execute", request_type=RequestType(func=lambda request, context: self.attack())) + rm.add_request( + name="execute", + request_type=RequestType(func=lambda request, context: RequestResponse.from_bool(self.attack())), + ) return rm @@ -179,21 +183,21 @@ class DataManipulationBot(Application): """ super().run() - def attack(self): + def attack(self) -> bool: """Perform the attack steps after opening the application.""" if not self._can_perform_action(): _LOGGER.debug("Data manipulation application attempted to execute but it cannot perform actions right now.") self.run() - self._application_loop() + return self._application_loop() - def _application_loop(self): + def _application_loop(self) -> bool: """ The main application loop of the bot, handling the attack process. This is the core loop where the bot sequentially goes through the stages of the attack. """ if not self._can_perform_action(): - return + return False if self.server_ip_address and self.payload: self.sys_log.info(f"{self.name}: Running") self._logon() @@ -205,8 +209,12 @@ class DataManipulationBot(Application): DataManipulationAttackStage.FAILED, ): self.attack_stage = DataManipulationAttackStage.NOT_STARTED + + return True + else: self.sys_log.error(f"{self.name}: Failed to start as it requires both a target_ip_address and payload.") + return False def apply_timestep(self, timestep: int) -> None: """ diff --git a/src/primaite/simulator/system/applications/red_applications/dos_bot.py b/src/primaite/simulator/system/applications/red_applications/dos_bot.py index 202fd189..05f87f03 100644 --- a/src/primaite/simulator/system/applications/red_applications/dos_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/dos_bot.py @@ -4,6 +4,7 @@ from typing import Optional from primaite import getLogger from primaite.game.science import simulate_trial +from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient @@ -59,7 +60,10 @@ class DoSBot(DatabaseClient): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() - rm.add_request(name="execute", request_type=RequestType(func=lambda request, context: self.run())) + rm.add_request( + name="execute", + request_type=RequestType(func=lambda request, context: RequestResponse.from_bool(self.run())), + ) return rm @@ -97,26 +101,26 @@ class DoSBot(DatabaseClient): f"{repeat=}, {port_scan_p_of_success=}, {dos_intensity=}, {max_sessions=}." ) - def run(self): + def run(self) -> bool: """Run the Denial of Service Bot.""" super().run() - self._application_loop() + return self._application_loop() - def _application_loop(self): + def _application_loop(self) -> bool: """ The main application loop for the Denial of Service bot. The loop goes through the stages of a DoS attack. """ if not self._can_perform_action(): - return + return False # DoS bot cannot do anything without a target if not self.target_ip_address or not self.target_port: self.sys_log.error( f"{self.name} is not properly configured. {self.target_ip_address=}, {self.target_port=}" ) - return + return True self.clear_connections() self._perform_port_scan(p_of_success=self.port_scan_p_of_success) @@ -126,6 +130,7 @@ class DoSBot(DatabaseClient): self.attack_stage = DoSAttackStage.NOT_STARTED else: self.attack_stage = DoSAttackStage.COMPLETED + return True def _perform_port_scan(self, p_of_success: Optional[float] = 0.1): """ diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 9fa86328..5dee1dd5 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -6,6 +6,7 @@ from urllib.parse import urlparse from pydantic import BaseModel, ConfigDict from primaite import getLogger +from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.network.protocols.http import ( HttpRequestMethod, @@ -52,7 +53,10 @@ class WebBrowser(Application): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() rm.add_request( - name="execute", request_type=RequestType(func=lambda request, context: self.get_webpage()) # noqa + name="execute", + request_type=RequestType( + func=lambda request, context: RequestResponse.from_bool(self.get_webpage()) + ), # noqa ) return rm diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 4102657c..706f166b 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -3,6 +3,7 @@ from enum import Enum from typing import Any, Dict, Optional from primaite import getLogger +from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.system.software import IOSoftware, SoftwareHealthState @@ -80,14 +81,14 @@ class Service(IOSoftware): def _init_request_manager(self) -> RequestManager: rm = super()._init_request_manager() - rm.add_request("scan", RequestType(func=lambda request, context: self.scan())) - rm.add_request("stop", RequestType(func=lambda request, context: self.stop())) - rm.add_request("start", RequestType(func=lambda request, context: self.start())) - rm.add_request("pause", RequestType(func=lambda request, context: self.pause())) - rm.add_request("resume", RequestType(func=lambda request, context: self.resume())) - rm.add_request("restart", RequestType(func=lambda request, context: self.restart())) - rm.add_request("disable", RequestType(func=lambda request, context: self.disable())) - rm.add_request("enable", RequestType(func=lambda request, context: self.enable())) + rm.add_request("scan", RequestType(func=lambda request, context: RequestResponse.from_bool(self.scan()))) + rm.add_request("stop", RequestType(func=lambda request, context: RequestResponse.from_bool(self.stop()))) + rm.add_request("start", RequestType(func=lambda request, context: RequestResponse.from_bool(self.start()))) + rm.add_request("pause", RequestType(func=lambda request, context: RequestResponse.from_bool(self.pause()))) + rm.add_request("resume", RequestType(func=lambda request, context: RequestResponse.from_bool(self.resume()))) + rm.add_request("restart", RequestType(func=lambda request, context: RequestResponse.from_bool(self.restart()))) + rm.add_request("disable", RequestType(func=lambda request, context: RequestResponse.from_bool(self.disable()))) + rm.add_request("enable", RequestType(func=lambda request, context: RequestResponse.from_bool(self.enable()))) return rm @abstractmethod @@ -106,17 +107,19 @@ class Service(IOSoftware): state["health_state_visible"] = self.health_state_visible.value return state - def stop(self) -> None: + def stop(self) -> bool: """Stop the service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.sys_log.info(f"Stopping service {self.name}") self.operating_state = ServiceOperatingState.STOPPED + return True + return False - def start(self, **kwargs) -> None: + def start(self, **kwargs) -> bool: """Start the service.""" # cant start the service if the node it is on is off if not super()._can_perform_action(): - return + return False if self.operating_state == ServiceOperatingState.STOPPED: self.sys_log.info(f"Starting service {self.name}") @@ -124,36 +127,47 @@ class Service(IOSoftware): # set software health state to GOOD if initially set to UNUSED if self.health_state_actual == SoftwareHealthState.UNUSED: self.set_health_state(SoftwareHealthState.GOOD) + return True + return False - def pause(self) -> None: + def pause(self) -> bool: """Pause the service.""" if self.operating_state == ServiceOperatingState.RUNNING: self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.PAUSED + return True + return False - def resume(self) -> None: + def resume(self) -> bool: """Resume paused service.""" if self.operating_state == ServiceOperatingState.PAUSED: self.sys_log.info(f"Resuming service {self.name}") self.operating_state = ServiceOperatingState.RUNNING + return True + return False - def restart(self) -> None: + def restart(self) -> bool: """Restart running service.""" if self.operating_state in [ServiceOperatingState.RUNNING, ServiceOperatingState.PAUSED]: self.sys_log.info(f"Pausing service {self.name}") self.operating_state = ServiceOperatingState.RESTARTING self.restart_countdown = self.restart_duration + return True + return False - def disable(self) -> None: + def disable(self) -> bool: """Disable the service.""" self.sys_log.info(f"Disabling Application {self.name}") self.operating_state = ServiceOperatingState.DISABLED + return True - def enable(self) -> None: + def enable(self) -> bool: """Enable the disabled service.""" if self.operating_state == ServiceOperatingState.DISABLED: self.sys_log.info(f"Enabling Application {self.name}") self.operating_state = ServiceOperatingState.STOPPED + return True + return False def apply_timestep(self, timestep: int) -> None: """ diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 8864659c..2af53886 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -5,6 +5,7 @@ from enum import Enum from ipaddress import IPv4Address, IPv4Network from typing import Any, Dict, Optional, TYPE_CHECKING, Union +from primaite.interface.request import RequestResponse from primaite.simulator.core import _LOGGER, RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file_system import FileSystem, Folder from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState @@ -105,16 +106,18 @@ class Software(SimComponent): rm.add_request( "compromise", RequestType( - func=lambda request, context: self.set_health_state(SoftwareHealthState.COMPROMISED), + func=lambda request, context: RequestResponse.from_bool( + self.set_health_state(SoftwareHealthState.COMPROMISED) + ), ), ) rm.add_request( "patch", RequestType( - func=lambda request, context: self.patch(), + func=lambda request, context: RequestResponse.from_bool(self.patch()), ), ) - rm.add_request("scan", RequestType(func=lambda request, context: self.scan())) + rm.add_request("scan", RequestType(func=lambda request, context: RequestResponse.from_bool(self.scan()))) return rm def _get_session_details(self, session_id: str) -> Session: @@ -148,7 +151,7 @@ class Software(SimComponent): ) return state - def set_health_state(self, health_state: SoftwareHealthState) -> None: + def set_health_state(self, health_state: SoftwareHealthState) -> bool: """ Assign a new health state to this software. @@ -160,6 +163,7 @@ class Software(SimComponent): :type health_state: SoftwareHealthState """ self.health_state_actual = health_state + return True def install(self) -> None: """ @@ -180,15 +184,18 @@ class Software(SimComponent): """ pass - def scan(self) -> None: + def scan(self) -> bool: """Update the observed health status to match the actual health status.""" self.health_state_visible = self.health_state_actual + return True - def patch(self) -> None: + def patch(self) -> bool: """Perform a patch on the software.""" if self.health_state_actual in (SoftwareHealthState.COMPROMISED, SoftwareHealthState.GOOD): self._patching_countdown = self.patching_duration self.set_health_state(SoftwareHealthState.PATCHING) + return True + return False def _update_patch_status(self) -> None: """Update the patch status of the software.""" From 0447a05084d2422e1931bf34b3b215e5de8d638e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 8 Mar 2024 15:57:43 +0000 Subject: [PATCH 691/980] Add call validation --- src/primaite/game/agent/actions.py | 4 +-- src/primaite/game/game.py | 8 +++-- src/primaite/session/io.py | 2 +- src/primaite/simulator/core.py | 7 +++-- src/primaite/simulator/file_system/file.py | 30 +++++++++++-------- src/primaite/simulator/file_system/folder.py | 30 +++++++++++-------- .../simulator/network/hardware/base.py | 20 ++++++++----- .../wireless/wireless_access_point.py | 6 ++-- .../wireless/wireless_nic.py | 6 ++-- 9 files changed, 69 insertions(+), 44 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 84bd3f39..4d28328e 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -492,9 +492,9 @@ class NetworkACLAddRuleAction(AbstractAction): "add_rule", permission_str, protocol, - src_ip, + str(src_ip), src_port, - dst_ip, + str(dst_ip), dst_port, position, ] diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 394a8154..c94cb3ad 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -165,9 +165,13 @@ class PrimaiteGame: for _, agent in self.agents.items(): obs = agent.observation_manager.current_observation action_choice, options = agent.get_action(obs, timestep=self.step_counter) - agent_actions[agent.agent_name] = (action_choice, options) request = agent.format_request(action_choice, options) - self.simulation.apply_request(request) + response = self.simulation.apply_request(request) + agent_actions[agent.agent_name] = { + "action": action_choice, + "parameters": options, + "response": response.model_dump(), + } return agent_actions def advance_timestep(self) -> None: diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index 3e21ed16..ed2b4d62 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -93,7 +93,7 @@ class PrimaiteIO: { "episode": episode, "timestep": timestep, - "agent_actions": {k: {"action": v[0], "parameters": v[1]} for k, v in agent_actions.items()}, + "agent_actions": agent_actions, } ] ) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 64f33f6a..02481661 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -43,7 +43,7 @@ class RequestType(BaseModel): the request can be performed or not. """ - func: Callable[[List[str], Dict], RequestResponse] + func: Callable[[List[Union[str, int, float]], Dict], RequestResponse] """ ``func`` is a function that accepts a request and a context dict. Typically this would be a lambda function that invokes a class method of your SimComponent. For example if the component is a node and the request type is for @@ -73,7 +73,7 @@ class RequestManager(BaseModel): """maps request name to an RequestType object.""" @validate_call - def __call__(self, request: List[str], context: Dict) -> RequestResponse: + def __call__(self, request: List[Union[str, int, float]], context: Dict) -> RequestResponse: """ Process an request request. @@ -206,7 +206,8 @@ class SimComponent(BaseModel): } return state - def apply_request(self, request: List[str], context: Dict = {}) -> None: + @validate_call + def apply_request(self, request: List[Union[str, int, float]], context: Dict = {}) -> RequestResponse: """ Apply a request to a simulation component. Request data is passed in as a 'namespaced' list of strings. diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index d9b02e8e..4dc222fb 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -100,15 +100,16 @@ class File(FileSystemItemABC): state["file_type"] = self.file_type.name return state - def scan(self) -> None: + def scan(self) -> bool: """Updates the visible statuses of the file.""" if self.deleted: self.sys_log.error(f"Unable to scan deleted file {self.folder_name}/{self.name}") - return + return False path = self.folder.name + "/" + self.name self.sys_log.info(f"Scanning file {self.sim_path if self.sim_path else path}") self.visible_health_status = self.health_status + return True def reveal_to_red(self) -> None: """Reveals the folder/file to the red agent.""" @@ -117,7 +118,7 @@ class File(FileSystemItemABC): return self.revealed_to_red = True - def check_hash(self) -> None: + def check_hash(self) -> bool: """ Check if the file has been changed. @@ -127,7 +128,7 @@ class File(FileSystemItemABC): """ if self.deleted: self.sys_log.error(f"Unable to check hash of deleted file {self.folder_name}/{self.name}") - return + return False current_hash = None # if file is real, read the file contents @@ -149,12 +150,13 @@ class File(FileSystemItemABC): # if the previous hash and current hash do not match, mark file as corrupted if self.previous_hash is not current_hash: self.corrupt() + return True - def repair(self) -> None: + def repair(self) -> bool: """Repair a corrupted File by setting the status to FileSystemItemStatus.GOOD.""" if self.deleted: self.sys_log.error(f"Unable to repair deleted file {self.folder_name}/{self.name}") - return + return False # set file status to good if corrupt if self.health_status == FileSystemItemHealthStatus.CORRUPT: @@ -162,12 +164,13 @@ class File(FileSystemItemABC): path = self.folder.name + "/" + self.name self.sys_log.info(f"Repaired file {self.sim_path if self.sim_path else path}") + return True - def corrupt(self) -> None: + def corrupt(self) -> bool: """Corrupt a File by setting the status to FileSystemItemStatus.CORRUPT.""" if self.deleted: self.sys_log.error(f"Unable to corrupt deleted file {self.folder_name}/{self.name}") - return + return False # set file status to good if corrupt if self.health_status == FileSystemItemHealthStatus.GOOD: @@ -175,24 +178,27 @@ class File(FileSystemItemABC): path = self.folder.name + "/" + self.name self.sys_log.info(f"Corrupted file {self.sim_path if self.sim_path else path}") + return True - def restore(self) -> None: + def restore(self) -> bool: """Determines if the file needs to be repaired or unmarked as deleted.""" if self.deleted: self.deleted = False - return + return True if self.health_status == FileSystemItemHealthStatus.CORRUPT: self.health_status = FileSystemItemHealthStatus.GOOD path = self.folder.name + "/" + self.name self.sys_log.info(f"Restored file {self.sim_path if self.sim_path else path}") + return True - def delete(self): + def delete(self) -> bool: """Marks the file as deleted.""" if self.deleted: self.sys_log.error(f"Unable to delete an already deleted file {self.folder_name}/{self.name}") - return + return False self.deleted = True self.sys_log.info(f"File deleted {self.folder_name}/{self.name}") + return True diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 9ef1ae59..fff08b23 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -307,7 +307,7 @@ class Folder(FileSystemItemABC): """Returns true if the folder is being quarantined.""" pass - def scan(self, instant_scan: bool = False) -> None: + def scan(self, instant_scan: bool = False) -> bool: """ Update Folder visible status. @@ -315,7 +315,7 @@ class Folder(FileSystemItemABC): """ if self.deleted: self.sys_log.error(f"Unable to scan deleted folder {self.name}") - return + return False if instant_scan: for file_id in self.files: @@ -323,7 +323,7 @@ class Folder(FileSystemItemABC): file.scan() if file.visible_health_status == FileSystemItemHealthStatus.CORRUPT: self.visible_health_status = FileSystemItemHealthStatus.CORRUPT - return + return True if self.scan_countdown <= 0: # scan one file per timestep @@ -332,6 +332,7 @@ class Folder(FileSystemItemABC): else: # scan already in progress self.sys_log.info(f"Scan is already in progress {self.name} (id: {self.uuid})") + return True def reveal_to_red(self, instant_scan: bool = False): """ @@ -358,7 +359,7 @@ class Folder(FileSystemItemABC): # scan already in progress self.sys_log.info(f"Red Agent Scan is already in progress {self.name} (id: {self.uuid})") - def check_hash(self) -> None: + def check_hash(self) -> bool: """ Runs a :func:`check_hash` on all files in the folder. @@ -371,7 +372,7 @@ class Folder(FileSystemItemABC): """ if self.deleted: self.sys_log.error(f"Unable to check hash of deleted folder {self.name}") - return + return False # iterate through the files and run a check hash no_corrupted_files = True @@ -387,12 +388,13 @@ class Folder(FileSystemItemABC): self.corrupt() self.sys_log.info(f"Checking hash of folder {self.name} (id: {self.uuid})") + return True - def repair(self) -> None: + def repair(self) -> bool: """Repair a corrupted Folder by setting the folder and containing files status to FileSystemItemStatus.GOOD.""" if self.deleted: self.sys_log.error(f"Unable to repair deleted folder {self.name}") - return + return False # iterate through the files in the folder for file_id in self.files: @@ -406,8 +408,9 @@ class Folder(FileSystemItemABC): self.health_status = FileSystemItemHealthStatus.GOOD self.sys_log.info(f"Repaired folder {self.name} (id: {self.uuid})") + return True - def restore(self) -> None: + def restore(self) -> bool: """ If a Folder is corrupted, run a repair on the folder and its child files. @@ -423,12 +426,13 @@ class Folder(FileSystemItemABC): else: # scan already in progress self.sys_log.info(f"Folder restoration already in progress {self.name} (id: {self.uuid})") + return True - def corrupt(self) -> None: + def corrupt(self) -> bool: """Corrupt a File by setting the folder and containing files status to FileSystemItemStatus.CORRUPT.""" if self.deleted: self.sys_log.error(f"Unable to corrupt deleted folder {self.name}") - return + return False # iterate through the files in the folder for file_id in self.files: @@ -439,11 +443,13 @@ class Folder(FileSystemItemABC): self.health_status = FileSystemItemHealthStatus.CORRUPT self.sys_log.info(f"Corrupted folder {self.name} (id: {self.uuid})") + return True - def delete(self): + def delete(self) -> bool: """Marks the file as deleted. Prevents agent actions from occuring.""" if self.deleted: self.sys_log.error(f"Unable to delete an already deleted folder {self.name}") - return + return False self.deleted = True + return True diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 3349bed4..d5945653 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -287,24 +287,24 @@ class WiredNetworkInterface(NetworkInterface, ABC): _connected_link: Optional[Link] = None "The network link to which the network interface is connected." - def enable(self): + def enable(self) -> bool: """Attempt to enable the network interface.""" if self.enabled: - return + return True if not self._connected_node: _LOGGER.error(f"Interface {self} cannot be enabled as it is not connected to a Node") - return + return False if self._connected_node.operating_state != NodeOperatingState.ON: self._connected_node.sys_log.info( f"Interface {self} cannot be enabled as the connected Node is not powered on" ) - return + return False if not self._connected_link: self._connected_node.sys_log.info(f"Interface {self} cannot be enabled as there is no Link connected.") - return + return False self.enabled = True self._connected_node.sys_log.info(f"Network Interface {self} enabled") @@ -313,11 +313,12 @@ class WiredNetworkInterface(NetworkInterface, ABC): ) if self._connected_link: self._connected_link.endpoint_up() + return True - def disable(self): + def disable(self) -> bool: """Disable the network interface.""" if not self.enabled: - return + return True self.enabled = False if self._connected_node: self._connected_node.sys_log.info(f"Network Interface {self} disabled") @@ -325,6 +326,7 @@ class WiredNetworkInterface(NetworkInterface, ABC): _LOGGER.debug(f"Interface {self} disabled") if self._connected_link: self._connected_link.endpoint_down() + return True def connect_link(self, link: Link): """ @@ -499,7 +501,7 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): return state - def enable(self): + def enable(self) -> bool: """ Enables this wired network interface and attempts to send a "hello" message to the default gateway. @@ -515,8 +517,10 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): try: pass self._connected_node.default_gateway_hello() + return True except AttributeError: pass + return False @abstractmethod def receive_frame(self, frame: Frame) -> bool: diff --git a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py index 721814f8..4b73b6a8 100644 --- a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py +++ b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_access_point.py @@ -51,13 +51,15 @@ class WirelessAccessPoint(IPWirelessNetworkInterface): return state - def enable(self): + def enable(self) -> bool: """Enable the interface.""" pass + return True - def disable(self): + def disable(self) -> bool: """Disable the interface.""" pass + return True def send_frame(self, frame: Frame) -> bool: """ diff --git a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py index 7b8f6f54..2e0a1823 100644 --- a/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py +++ b/src/primaite/simulator/network/hardware/network_interface/wireless/wireless_nic.py @@ -48,13 +48,15 @@ class WirelessNIC(IPWirelessNetworkInterface): return state - def enable(self): + def enable(self) -> bool: """Enable the interface.""" pass + return True - def disable(self): + def disable(self) -> bool: """Disable the interface.""" pass + return True def send_frame(self, frame: Frame) -> bool: """ From 289b5c548ac9e9a19567d0911291ed064ef1c007 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 8 Mar 2024 17:14:41 +0000 Subject: [PATCH 692/980] Make a type alias for request & fix typo --- src/primaite/simulator/core.py | 15 +++++++-------- src/primaite/simulator/file_system/file_system.py | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 02481661..aeb4e865 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -11,6 +11,8 @@ from primaite.interface.request import RequestResponse _LOGGER = getLogger(__name__) +RequestFormat = List[Union[str, int, float]] + class RequestPermissionValidator(BaseModel): """ @@ -22,7 +24,7 @@ class RequestPermissionValidator(BaseModel): """ @abstractmethod - def __call__(self, request: List[str], context: Dict) -> bool: + def __call__(self, request: RequestFormat, context: Dict) -> bool: """Use the request and context parameters to decide whether the request should be permitted.""" pass @@ -30,7 +32,7 @@ class RequestPermissionValidator(BaseModel): class AllowAllValidator(RequestPermissionValidator): """Always allows the request.""" - def __call__(self, request: List[str], context: Dict) -> bool: + def __call__(self, request: RequestFormat, context: Dict) -> bool: """Always allow the request.""" return True @@ -43,7 +45,7 @@ class RequestType(BaseModel): the request can be performed or not. """ - func: Callable[[List[Union[str, int, float]], Dict], RequestResponse] + func: Callable[[RequestFormat, Dict], RequestResponse] """ ``func`` is a function that accepts a request and a context dict. Typically this would be a lambda function that invokes a class method of your SimComponent. For example if the component is a node and the request type is for @@ -72,8 +74,7 @@ class RequestManager(BaseModel): request_types: Dict[str, RequestType] = {} """maps request name to an RequestType object.""" - @validate_call - def __call__(self, request: List[Union[str, int, float]], context: Dict) -> RequestResponse: + def __call__(self, request: RequestFormat, context: Dict) -> RequestResponse: """ Process an request request. @@ -93,8 +94,6 @@ class RequestManager(BaseModel): f"Request {request} could not be processed because {request_key} is not a valid request name", "within this RequestManager", ) - # _LOGGER.error(msg) - # raise RuntimeError(msg) _LOGGER.debug(msg) return RequestResponse(status="unreachable", data={"reason": msg}) @@ -207,7 +206,7 @@ class SimComponent(BaseModel): return state @validate_call - def apply_request(self, request: List[Union[str, int, float]], context: Dict = {}) -> RequestResponse: + def apply_request(self, request: RequestFormat, context: Dict = {}) -> RequestResponse: """ Apply a request to a simulation component. Request data is passed in as a 'namespaced' list of strings. diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 3ff73a80..9e2a3b0e 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -62,7 +62,7 @@ class FileSystem(SimComponent): self._restore_manager.add_request( name="file", request_type=RequestType( - func=lambda request, context: RequestResponse( + func=lambda request, context: RequestResponse.from_bool( self.restore_file(folder_name=request[0], file_name=request[1]) ) ), From cc721056d89563d64aae94ae9c936480a7c6388a Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 8 Mar 2024 19:32:07 +0000 Subject: [PATCH 693/980] #2350: configurable NMNE category thresholds --- .../_package_data/data_manipulation.yaml | 5 + .../agent/observations/nic_observations.py | 175 ++++++++++++++++++ .../agent/observations/node_observations.py | 3 +- .../game/agent/observations/observations.py | 102 ---------- src/primaite/game/game.py | 7 +- ...software_installation_and_configuration.py | 11 +- .../test_game_options_config.py | 25 +++ .../observations/test_observations.py | 42 ++++- .../network/test_capture_nmne.py | 2 +- 9 files changed, 261 insertions(+), 111 deletions(-) create mode 100644 src/primaite/game/agent/observations/nic_observations.py create mode 100644 tests/integration_tests/configuration_file_parsing/test_game_options_config.py diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index dffb40ea..47204878 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -30,6 +30,11 @@ game: - ICMP - TCP - UDP + thresholds: + nmne: + high: 10 + medium: 5 + low: 0 agents: - ref: client_2_green_user diff --git a/src/primaite/game/agent/observations/nic_observations.py b/src/primaite/game/agent/observations/nic_observations.py new file mode 100644 index 00000000..39298ffe --- /dev/null +++ b/src/primaite/game/agent/observations/nic_observations.py @@ -0,0 +1,175 @@ +from typing import Dict, List, Optional, Tuple, TYPE_CHECKING + +from gymnasium import spaces + +from primaite.game.agent.observations.observations import AbstractObservation +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +from primaite.simulator.network.nmne import CAPTURE_NMNE + +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame + + +class NicObservation(AbstractObservation): + """Observation of a Network Interface Card (NIC) in the network.""" + + low_nmne_threshold: int = 0 + """The minimum number of malicious network events to be considered low.""" + med_nmne_threshold: int = 5 + """The minimum number of malicious network events to be considered medium.""" + high_nmne_threshold: int = 10 + """The minimum number of malicious network events to be considered high.""" + + @property + def default_observation(self) -> Dict: + """The default NIC observation dict.""" + data = {"nic_status": 0} + if CAPTURE_NMNE: + data.update({"nmne": {"inbound": 0, "outbound": 0}}) + + return data + + def __init__( + self, + where: Optional[Tuple[str]] = None, + low_nmne_threshold: Optional[int] = 0, + med_nmne_threshold: Optional[int] = 5, + high_nmne_threshold: Optional[int] = 10, + ) -> None: + """Initialise NIC observation. + + :param where: Where in the simulation state dictionary to find the relevant information for this NIC. A typical + example may look like this: + ['network','nodes',,'NICs',] + If None, this denotes that the NIC does not exist and the observation will be populated with zeroes. + :type where: Optional[Tuple[str]], optional + """ + super().__init__() + self.where: Optional[Tuple[str]] = where + + if low_nmne_threshold or med_nmne_threshold or high_nmne_threshold: + self._validate_nmne_categories( + low_nmne_threshold=low_nmne_threshold, + med_nmne_threshold=med_nmne_threshold, + high_nmne_threshold=high_nmne_threshold, + ) + + def _validate_nmne_categories( + self, low_nmne_threshold: int = 0, med_nmne_threshold: int = 5, high_nmne_threshold: int = 10 + ): + """ + Validates the nmne threshold config. + + If the configuration is valid, the thresholds will be set, otherwise, an exception is raised. + + :param: low_nmne_threshold: The minimum number of malicious network events to be considered low + :param: med_nmne_threshold: The minimum number of malicious network events to be considered medium + :param: high_nmne_threshold: The minimum number of malicious network events to be considered high + """ + if high_nmne_threshold <= med_nmne_threshold: + raise Exception( + f"nmne_categories: high nmne count ({high_nmne_threshold}) must be greater " + f"than medium nmne count ({med_nmne_threshold})" + ) + + if med_nmne_threshold <= low_nmne_threshold: + raise Exception( + f"nmne_categories: medium nmne count ({med_nmne_threshold}) must be greater " + f"than low nmne count ({low_nmne_threshold})" + ) + + self.high_nmne_threshold = high_nmne_threshold + self.med_nmne_threshold = med_nmne_threshold + self.low_nmne_threshold = low_nmne_threshold + + def _categorise_mne_count(self, nmne_count: int) -> int: + """ + Categorise the number of Malicious Network Events (NMNEs) into discrete bins. + + This helps in classifying the severity or volume of MNEs into manageable levels for the agent. + + Bins are defined as follows: + - 0: No MNEs detected (0 events). + - 1: Low number of MNEs (default 1-5 events). + - 2: Moderate number of MNEs (default 6-10 events). + - 3: High number of MNEs (default more than 10 events). + + :param nmne_count: Number of MNEs detected. + :return: Bin number corresponding to the number of MNEs. Returns 0, 1, 2, or 3 based on the detected MNE count. + """ + if nmne_count > self.high_nmne_threshold: + return 3 + elif nmne_count > self.med_nmne_threshold: + return 2 + elif nmne_count > self.low_nmne_threshold: + return 1 + return 0 + + def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ + if self.where is None: + return self.default_observation + nic_state = access_from_nested_dict(state, self.where) + + if nic_state is NOT_PRESENT_IN_STATE: + return self.default_observation + else: + obs_dict = {"nic_status": 1 if nic_state["enabled"] else 2} + if CAPTURE_NMNE: + obs_dict.update({"nmne": {}}) + direction_dict = nic_state["nmne"].get("direction", {}) + inbound_keywords = direction_dict.get("inbound", {}).get("keywords", {}) + inbound_count = inbound_keywords.get("*", 0) + outbound_keywords = direction_dict.get("outbound", {}).get("keywords", {}) + outbound_count = outbound_keywords.get("*", 0) + obs_dict["nmne"]["inbound"] = self._categorise_mne_count(inbound_count) + obs_dict["nmne"]["outbound"] = self._categorise_mne_count(outbound_count) + return obs_dict + + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" + return spaces.Dict( + { + "nic_status": spaces.Discrete(3), + "nmne": spaces.Dict({"inbound": spaces.Discrete(6), "outbound": spaces.Discrete(6)}), + } + ) + + @classmethod + def from_config(cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]]) -> "NicObservation": + """Create NIC observation from a config. + + :param config: Dictionary containing the configuration for this NIC observation. + :type config: Dict + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame + :param parent_where: Where in the simulation state dictionary to find the information about this NIC's parent + node. A typical location for a node ``where`` can be: ['network','nodes',] + :type parent_where: Optional[List[str]] + :return: Constructed NIC observation + :rtype: NicObservation + """ + low_nmne_threshold = None + med_nmne_threshold = None + high_nmne_threshold = None + + if game and game.options and game.options.thresholds and game.options.thresholds.get("nmne"): + threshold = game.options.thresholds["nmne"] + + low_nmne_threshold = int(threshold.get("low")) if threshold.get("low") is not None else None + med_nmne_threshold = int(threshold.get("medium")) if threshold.get("medium") is not None else None + high_nmne_threshold = int(threshold.get("high")) if threshold.get("high") is not None else None + + return cls( + where=parent_where + ["NICs", config["nic_num"]], + low_nmne_threshold=low_nmne_threshold, + med_nmne_threshold=med_nmne_threshold, + high_nmne_threshold=high_nmne_threshold, + ) diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index 93c6765b..f211a6b5 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -4,7 +4,8 @@ from gymnasium import spaces from primaite import getLogger from primaite.game.agent.observations.file_system_observations import FolderObservation -from primaite.game.agent.observations.observations import AbstractObservation, NicObservation +from primaite.game.agent.observations.nic_observations import NicObservation +from primaite.game.agent.observations.observations import AbstractObservation from primaite.game.agent.observations.software_observation import ServiceObservation from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE diff --git a/src/primaite/game/agent/observations/observations.py b/src/primaite/game/agent/observations/observations.py index 10e69ea5..6236b00d 100644 --- a/src/primaite/game/agent/observations/observations.py +++ b/src/primaite/game/agent/observations/observations.py @@ -7,7 +7,6 @@ from gymnasium import spaces from primaite import getLogger from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE -from primaite.simulator.network.nmne import CAPTURE_NMNE _LOGGER = getLogger(__name__) @@ -116,107 +115,6 @@ class LinkObservation(AbstractObservation): return cls(where=["network", "links", game.ref_map_links[config["link_ref"]]]) -class NicObservation(AbstractObservation): - """Observation of a Network Interface Card (NIC) in the network.""" - - @property - def default_observation(self) -> Dict: - """The default NIC observation dict.""" - data = {"nic_status": 0} - if CAPTURE_NMNE: - data.update({"nmne": {"inbound": 0, "outbound": 0}}) - - return data - - def __init__(self, where: Optional[Tuple[str]] = None) -> None: - """Initialise NIC observation. - - :param where: Where in the simulation state dictionary to find the relevant information for this NIC. A typical - example may look like this: - ['network','nodes',,'NICs',] - If None, this denotes that the NIC does not exist and the observation will be populated with zeroes. - :type where: Optional[Tuple[str]], optional - """ - super().__init__() - self.where: Optional[Tuple[str]] = where - - def _categorise_mne_count(self, nmne_count: int) -> int: - """ - Categorise the number of Malicious Network Events (NMNEs) into discrete bins. - - This helps in classifying the severity or volume of MNEs into manageable levels for the agent. - - Bins are defined as follows: - - 0: No MNEs detected (0 events). - - 1: Low number of MNEs (1-5 events). - - 2: Moderate number of MNEs (6-10 events). - - 3: High number of MNEs (more than 10 events). - - :param nmne_count: Number of MNEs detected. - :return: Bin number corresponding to the number of MNEs. Returns 0, 1, 2, or 3 based on the detected MNE count. - """ - if nmne_count > 10: - return 3 - elif nmne_count > 5: - return 2 - elif nmne_count > 0: - return 1 - return 0 - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict - """ - if self.where is None: - return self.default_observation - nic_state = access_from_nested_dict(state, self.where) - - if nic_state is NOT_PRESENT_IN_STATE: - return self.default_observation - else: - obs_dict = {"nic_status": 1 if nic_state["enabled"] else 2} - if CAPTURE_NMNE: - obs_dict.update({"nmne": {}}) - direction_dict = nic_state["nmne"].get("direction", {}) - inbound_keywords = direction_dict.get("inbound", {}).get("keywords", {}) - inbound_count = inbound_keywords.get("*", 0) - outbound_keywords = direction_dict.get("outbound", {}).get("keywords", {}) - outbound_count = outbound_keywords.get("*", 0) - obs_dict["nmne"]["inbound"] = self._categorise_mne_count(inbound_count) - obs_dict["nmne"]["outbound"] = self._categorise_mne_count(outbound_count) - return obs_dict - - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" - return spaces.Dict( - { - "nic_status": spaces.Discrete(3), - "nmne": spaces.Dict({"inbound": spaces.Discrete(6), "outbound": spaces.Discrete(6)}), - } - ) - - @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]]) -> "NicObservation": - """Create NIC observation from a config. - - :param config: Dictionary containing the configuration for this NIC observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :param parent_where: Where in the simulation state dictionary to find the information about this NIC's parent - node. A typical location for a node ``where`` can be: ['network','nodes',] - :type parent_where: Optional[List[str]] - :return: Constructed NIC observation - :rtype: NicObservation - """ - return cls(where=parent_where + ["NICs", config["nic_num"]]) - - class AclObservation(AbstractObservation): """Observation of an Access Control List (ACL) in the network.""" diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 33f9186b..3edb8651 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -1,6 +1,6 @@ """PrimAITE game - Encapsulates the simulation and agents.""" from ipaddress import IPv4Address -from typing import Dict, List, Tuple +from typing import Dict, List, Optional, Tuple from pydantic import BaseModel, ConfigDict @@ -67,8 +67,13 @@ class PrimaiteGameOptions(BaseModel): model_config = ConfigDict(extra="forbid") max_episode_length: int = 256 + """Maximum number of episodes for the PrimAITE game.""" ports: List[str] + """A whitelist of available ports in the simulation.""" protocols: List[str] + """A whitelist of available protocols in the simulation.""" + thresholds: Optional[Dict] = {} + """A dict containing the thresholds used for determining what is acceptable during observations.""" class PrimaiteGame: diff --git a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py index f993af5f..a5fcb372 100644 --- a/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py +++ b/tests/integration_tests/configuration_file_parsing/software_installation_and_configuration.py @@ -5,8 +5,9 @@ from typing import Union import yaml from primaite.config.load import data_manipulation_config_path -from primaite.game.agent.interface import ProxyAgent, RandomAgent +from primaite.game.agent.interface import ProxyAgent from primaite.game.agent.scripted_agents.data_manipulation_bot import DataManipulationAgent +from primaite.game.agent.scripted_agents.probabilistic_agent import ProbabilisticAgent from primaite.game.game import APPLICATION_TYPES_MAPPING, PrimaiteGame, SERVICE_TYPES_MAPPING from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.host.computer import Computer @@ -43,15 +44,15 @@ def test_example_config(): # green agent 1 assert "client_2_green_user" in game.agents - assert isinstance(game.agents["client_2_green_user"], RandomAgent) + assert isinstance(game.agents["client_2_green_user"], ProbabilisticAgent) # green agent 2 assert "client_1_green_user" in game.agents - assert isinstance(game.agents["client_1_green_user"], RandomAgent) + assert isinstance(game.agents["client_1_green_user"], ProbabilisticAgent) # red agent - assert "client_1_data_manipulation_red_bot" in game.agents - assert isinstance(game.agents["client_1_data_manipulation_red_bot"], DataManipulationAgent) + assert "data_manipulation_attacker" in game.agents + assert isinstance(game.agents["data_manipulation_attacker"], DataManipulationAgent) # blue agent assert "defender" in game.agents diff --git a/tests/integration_tests/configuration_file_parsing/test_game_options_config.py b/tests/integration_tests/configuration_file_parsing/test_game_options_config.py new file mode 100644 index 00000000..adbbf2b5 --- /dev/null +++ b/tests/integration_tests/configuration_file_parsing/test_game_options_config.py @@ -0,0 +1,25 @@ +from pathlib import Path +from typing import Union + +import yaml + +from primaite.config.load import data_manipulation_config_path +from primaite.game.game import PrimaiteGame +from tests import TEST_ASSETS_ROOT + +BASIC_CONFIG = TEST_ASSETS_ROOT / "configs/basic_switched_network.yaml" + + +def load_config(config_path: Union[str, Path]) -> PrimaiteGame: + """Returns a PrimaiteGame object which loads the contents of a given yaml path.""" + with open(config_path, "r") as f: + cfg = yaml.safe_load(f) + + return PrimaiteGame.from_config(cfg) + + +def test_thresholds(): + """Test that the game options can be parsed correctly.""" + game = load_config(data_manipulation_config_path()) + + assert game.options.thresholds is not None diff --git a/tests/integration_tests/game_layer/observations/test_observations.py b/tests/integration_tests/game_layer/observations/test_observations.py index eccda238..97df7882 100644 --- a/tests/integration_tests/game_layer/observations/test_observations.py +++ b/tests/integration_tests/game_layer/observations/test_observations.py @@ -1,6 +1,6 @@ import pytest -from primaite.game.agent.observations.observations import NicObservation +from primaite.game.agent.observations.nic_observations import NicObservation from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC from primaite.simulator.sim_container import Simulation @@ -33,3 +33,43 @@ def test_nic(simulation): nic.disable() observation_state = nic_obs.observe(simulation.describe_state()) assert observation_state.get("nic_status") == 2 # disabled + + +def test_nic_categories(simulation): + """Test the NIC observation nmne count categories.""" + pc: Computer = simulation.network.get_node_by_hostname("client_1") + + nic_obs = NicObservation(where=["network", "nodes", pc.hostname, "NICs", 1]) + + assert nic_obs.high_nmne_threshold == 10 # default + assert nic_obs.med_nmne_threshold == 5 # default + assert nic_obs.low_nmne_threshold == 0 # default + + nic_obs = NicObservation( + where=["network", "nodes", pc.hostname, "NICs", 1], + low_nmne_threshold=3, + med_nmne_threshold=6, + high_nmne_threshold=9, + ) + + assert nic_obs.high_nmne_threshold == 9 + assert nic_obs.med_nmne_threshold == 6 + assert nic_obs.low_nmne_threshold == 3 + + with pytest.raises(Exception): + # should throw an error + NicObservation( + where=["network", "nodes", pc.hostname, "NICs", 1], + low_nmne_threshold=9, + med_nmne_threshold=6, + high_nmne_threshold=9, + ) + + with pytest.raises(Exception): + # should throw an error + NicObservation( + where=["network", "nodes", pc.hostname, "NICs", 1], + low_nmne_threshold=3, + med_nmne_threshold=9, + high_nmne_threshold=9, + ) diff --git a/tests/integration_tests/network/test_capture_nmne.py b/tests/integration_tests/network/test_capture_nmne.py index 4bbde32f..32d4ee8f 100644 --- a/tests/integration_tests/network/test_capture_nmne.py +++ b/tests/integration_tests/network/test_capture_nmne.py @@ -1,4 +1,4 @@ -from primaite.game.agent.observations.observations import NicObservation +from primaite.game.agent.observations.nic_observations import NicObservation from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.nmne import set_nmne_config from primaite.simulator.sim_container import Simulation From 31ae4672acc3c19ac0ed6991004a23b1fb32a99e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sat, 9 Mar 2024 20:47:57 +0000 Subject: [PATCH 694/980] Make nodes only accept requests when they're on --- src/primaite/interface/request.py | 6 +- .../simulator/network/hardware/base.py | 52 ++++++++--- .../test_simulation/__init__.py | 0 .../test_simulation/test_request_response.py | 92 +++++++++++++++++++ .../_primaite/_interface/__init__.py | 0 .../_primaite/_interface/test_request.py | 32 +++++++ 6 files changed, 164 insertions(+), 18 deletions(-) create mode 100644 tests/integration_tests/test_simulation/__init__.py create mode 100644 tests/integration_tests/test_simulation/test_request_response.py create mode 100644 tests/unit_tests/_primaite/_interface/__init__.py create mode 100644 tests/unit_tests/_primaite/_interface/test_request.py diff --git a/src/primaite/interface/request.py b/src/primaite/interface/request.py index 8e61c1cb..8e922ef9 100644 --- a/src/primaite/interface/request.py +++ b/src/primaite/interface/request.py @@ -1,6 +1,6 @@ from typing import Dict, ForwardRef, Literal -from pydantic import BaseModel, ConfigDict, validate_call +from pydantic import BaseModel, ConfigDict, StrictBool, validate_call RequestResponse = ForwardRef("RequestResponse") """This makes it possible to type-hint RequestResponse.from_bool return type.""" @@ -9,7 +9,7 @@ RequestResponse = ForwardRef("RequestResponse") class RequestResponse(BaseModel): """Schema for generic request responses.""" - model_config = ConfigDict(extra="forbid") + model_config = ConfigDict(extra="forbid", strict=True) """Cannot have extra fields in the response. Anything custom goes into the data field.""" status: Literal["pending", "success", "failure", "unreachable"] = "pending" @@ -29,7 +29,7 @@ class RequestResponse(BaseModel): @classmethod @validate_call - def from_bool(cls, status_bool: bool) -> RequestResponse: + def from_bool(cls, status_bool: StrictBool) -> RequestResponse: """ Construct a basic request response from a boolean. diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index d5945653..f3cf29bb 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -14,7 +14,7 @@ from primaite import getLogger from primaite.exceptions import NetworkError from primaite.interface.request import RequestResponse from primaite.simulator import SIM_OUTPUT -from primaite.simulator.core import RequestManager, RequestType, SimComponent +from primaite.simulator.core import RequestFormat, RequestManager, RequestPermissionValidator, RequestType, SimComponent from primaite.simulator.domain.account import Account from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState @@ -772,47 +772,69 @@ class Node(SimComponent): self.sys_log.current_episode = episode self.sys_log.setup_logger() + class _NodeIsOnValidator(RequestPermissionValidator): + """ + When requests come in, this validator will only let them through if the node is on. + + This is useful because no actions should be being resolved if the node is off. + """ + + node: Node + """Save a reference to the node instance.""" + + def __call__(self, request: RequestFormat, context: Dict) -> bool: + """Return whether the node is on or off.""" + return self.node.operating_state == NodeOperatingState.ON + def _init_request_manager(self) -> RequestManager: - # TODO: I see that this code is really confusing and hard to read right now... I think some of these things will - # need a better name and better documentation. + _node_is_on = Node._NodeIsOnValidator(node=self) + rm = super()._init_request_manager() # since there are potentially many services, create an request manager that can map service name self._service_request_manager = RequestManager() - rm.add_request("service", RequestType(func=self._service_request_manager)) + rm.add_request("service", RequestType(func=self._service_request_manager, validator=_node_is_on)) self._nic_request_manager = RequestManager() - rm.add_request("network_interface", RequestType(func=self._nic_request_manager)) + rm.add_request("network_interface", RequestType(func=self._nic_request_manager, validator=_node_is_on)) - rm.add_request("file_system", RequestType(func=self.file_system._request_manager)) + rm.add_request("file_system", RequestType(func=self.file_system._request_manager, validator=_node_is_on)) # currently we don't have any applications nor processes, so these will be empty self._process_request_manager = RequestManager() - rm.add_request("process", RequestType(func=self._process_request_manager)) + rm.add_request("process", RequestType(func=self._process_request_manager, validator=_node_is_on)) self._application_request_manager = RequestManager() - rm.add_request("application", RequestType(func=self._application_request_manager)) + rm.add_request("application", RequestType(func=self._application_request_manager, validator=_node_is_on)) rm.add_request( - "scan", RequestType(func=lambda request, context: RequestResponse.from_bool(self.reveal_to_red())) + "scan", + RequestType( + func=lambda request, context: RequestResponse.from_bool(self.reveal_to_red()), validator=_node_is_on + ), ) rm.add_request( - "shutdown", RequestType(func=lambda request, context: RequestResponse.from_bool(self.power_off())) + "shutdown", + RequestType( + func=lambda request, context: RequestResponse.from_bool(self.power_off()), validator=_node_is_on + ), ) rm.add_request("startup", RequestType(func=lambda request, context: RequestResponse.from_bool(self.power_on()))) rm.add_request( - "reset", RequestType(func=lambda request, context: RequestResponse.from_bool(self.reset())) + "reset", + RequestType(func=lambda request, context: RequestResponse.from_bool(self.reset()), validator=_node_is_on), ) # TODO implement node reset rm.add_request( - "logon", RequestType(func=lambda request, context: RequestResponse.from_bool(False)) + "logon", RequestType(func=lambda request, context: RequestResponse.from_bool(False), validator=_node_is_on) ) # TODO implement logon request rm.add_request( - "logoff", RequestType(func=lambda request, context: RequestResponse.from_bool(False)) + "logoff", RequestType(func=lambda request, context: RequestResponse.from_bool(False), validator=_node_is_on) ) # TODO implement logoff request self._os_request_manager = RequestManager() self._os_request_manager.add_request( - "scan", RequestType(func=lambda request, context: RequestResponse.from_bool(self.scan())) + "scan", + RequestType(func=lambda request, context: RequestResponse.from_bool(self.scan()), validator=_node_is_on), ) - rm.add_request("os", RequestType(func=self._os_request_manager)) + rm.add_request("os", RequestType(func=self._os_request_manager, validator=_node_is_on)) return rm diff --git a/tests/integration_tests/test_simulation/__init__.py b/tests/integration_tests/test_simulation/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration_tests/test_simulation/test_request_response.py b/tests/integration_tests/test_simulation/test_request_response.py new file mode 100644 index 00000000..09680740 --- /dev/null +++ b/tests/integration_tests/test_simulation/test_request_response.py @@ -0,0 +1,92 @@ +# some test cases: +# 0. test that sending a request to a valid target results in a success +# 1. test that sending a request to a component that doesn't exist results in a failure +# 2. test that sending a request to a software on a turned-off component results in a failure +# 3. test every implemented action under several different situation, some of which should lead to a success and some to a failure. + +import pytest + +from primaite.interface.request import RequestResponse +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.host.host_node import HostNode +from tests.conftest import TestApplication, TestService + + +def test_successful_application_requests(example_network): + net = example_network + + client_1 = net.get_node_by_hostname("client_1") + client_1.software_manager.install(TestApplication) + client_1.software_manager.software.get("TestApplication").run() + + resp_1 = net.apply_request(["node", "client_1", "application", "TestApplication", "scan"]) + assert resp_1 == RequestResponse(status="success", data={}) + resp_2 = net.apply_request(["node", "client_1", "application", "TestApplication", "patch"]) + assert resp_2 == RequestResponse(status="success", data={}) + resp_3 = net.apply_request(["node", "client_1", "application", "TestApplication", "compromise"]) + assert resp_3 == RequestResponse(status="success", data={}) + + +def test_successful_service_requests(example_network): + net = example_network + server_1 = net.get_node_by_hostname("server_1") + server_1.software_manager.install(TestService) + + # Careful: the order here is important, for example we cannot run "stop" unless we run "start" first + for verb in [ + "disable", + "enable", + "start", + "stop", + "start", + "restart", + "pause", + "resume", + "compromise", + "scan", + "patch", + ]: + resp_1 = net.apply_request(["node", "server_1", "service", "TestService", verb]) + assert resp_1 == RequestResponse(status="success", data={}) + server_1.apply_timestep(timestep=1) + server_1.apply_timestep(timestep=1) + server_1.apply_timestep(timestep=1) + server_1.apply_timestep(timestep=1) + server_1.apply_timestep(timestep=1) + server_1.apply_timestep(timestep=1) + server_1.apply_timestep(timestep=1) + # lazily apply timestep 7 times to make absolutely sure any time-based things like restart have a chance to finish + + +def test_non_existent_requests(example_network): + net = example_network + resp_1 = net.apply_request(["fake"]) + assert resp_1.status == "unreachable" + resp_2 = net.apply_request(["network", "node", "client_39", "application", "WebBrowser", "execute"]) + assert resp_2.status == "unreachable" + + +@pytest.mark.parametrize( + "node_request", + [ + ["node", "client_1", "file_system", "folder", "root", "scan"], + ["node", "client_1", "os", "scan"], + ["node", "client_1", "service", "DNSClient", "stop"], + ["node", "client_1", "application", "WebBrowser", "scan"], + ["node", "client_1", "network_interface", 1, "disable"], + ], +) +def test_request_fails_if_node_off(example_network, node_request): + """Test that requests succeed when the node is on, and fail if the node is off.""" + net = example_network + client_1: HostNode = net.get_node_by_hostname("client_1") + client_1.shut_down_duration = 0 + + assert client_1.operating_state == NodeOperatingState.ON + resp_1 = net.apply_request(node_request) + assert resp_1.status == "success" + + client_1.power_off() + assert client_1.operating_state == NodeOperatingState.OFF + resp_2 = net.apply_request(node_request) + assert resp_2.status == "failure" diff --git a/tests/unit_tests/_primaite/_interface/__init__.py b/tests/unit_tests/_primaite/_interface/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_interface/test_request.py b/tests/unit_tests/_primaite/_interface/test_request.py new file mode 100644 index 00000000..5c65b572 --- /dev/null +++ b/tests/unit_tests/_primaite/_interface/test_request.py @@ -0,0 +1,32 @@ +import pytest +from pydantic import ValidationError + +from primaite.interface.request import RequestResponse + + +def test_creating_response_object(): + """Test that we can create a response object with given parameters.""" + r1 = RequestResponse(status="success", data={"test_data": 1, "other_data": 2}) + r2 = RequestResponse(status="unreachable") + r3 = RequestResponse(data={"test_data": "is_good"}) + r4 = RequestResponse() + assert isinstance(r1, RequestResponse) + assert isinstance(r2, RequestResponse) + assert isinstance(r3, RequestResponse) + assert isinstance(r4, RequestResponse) + + +def test_creating_response_from_boolean(): + """Test that we can build a response with a single boolean.""" + r1 = RequestResponse.from_bool(True) + assert r1.status == "success" + + r2 = RequestResponse.from_bool(False) + assert r2.status == "failure" + + with pytest.raises(ValidationError): + r3 = RequestResponse.from_bool(1) + with pytest.raises(ValidationError): + r4 = RequestResponse.from_bool("good") + with pytest.raises(ValidationError): + r5 = RequestResponse.from_bool({"data": True}) From 359777f4f8ebcb06aa06a4c454e698b60f3beb11 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sat, 9 Mar 2024 23:06:53 +0000 Subject: [PATCH 695/980] Add tests for request success/fail --- src/primaite/simulator/network/networks.py | 12 ++-- .../test_simulation/test_request_response.py | 68 +++++++++++++++++++ 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index fa9d86ef..c1eef224 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -146,9 +146,12 @@ def arcd_uc2_network() -> Network: ) client_1.power_on() network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1]) - db_client_1 = client_1.software_manager.install(DatabaseClient) - db_client_1 = client_1.software_manager.software.get("DatabaseClient") + client_1.software_manager.install(DatabaseClient) + db_client_1: DatabaseClient = client_1.software_manager.software.get("DatabaseClient") + db_client_1.configure(server_ip_address=IPv4Address("192.168.1.14")) db_client_1.run() + web_browser_1 = client_1.software_manager.software.get("WebBrowser") + web_browser_1.target_url = "http://arcd.com/users/" client_1.software_manager.install(DataManipulationBot) db_manipulation_bot: DataManipulationBot = client_1.software_manager.software.get("DataManipulationBot") db_manipulation_bot.configure( @@ -170,9 +173,10 @@ def arcd_uc2_network() -> Network: client_2.power_on() client_2.software_manager.install(DatabaseClient) db_client_2 = client_2.software_manager.software.get("DatabaseClient") + db_client_2.configure(server_ip_address=IPv4Address("192.168.1.14")) db_client_2.run() - web_browser = client_2.software_manager.software.get("WebBrowser") - web_browser.target_url = "http://arcd.com/users/" + web_browser_2 = client_2.software_manager.software.get("WebBrowser") + web_browser_2.target_url = "http://arcd.com/users/" network.connect(endpoint_b=client_2.network_interface[1], endpoint_a=switch_2.network_interface[2]) # Domain Controller diff --git a/tests/integration_tests/test_simulation/test_request_response.py b/tests/integration_tests/test_simulation/test_request_response.py index 09680740..aee5c816 100644 --- a/tests/integration_tests/test_simulation/test_request_response.py +++ b/tests/integration_tests/test_simulation/test_request_response.py @@ -9,6 +9,8 @@ import pytest from primaite.interface.request import RequestResponse from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.host_node import HostNode +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.transmission.transport_layer import Port from tests.conftest import TestApplication, TestService @@ -90,3 +92,69 @@ def test_request_fails_if_node_off(example_network, node_request): assert client_1.operating_state == NodeOperatingState.OFF resp_2 = net.apply_request(node_request) assert resp_2.status == "failure" + + +class TestDataManipulationGreenRequests: + def test_node_off(self, uc2_network): + """Test that green requests succeed when the node is on and fail if the node is off.""" + net = uc2_network + + client_1_browser_execute = net.apply_request(["node", "client_1", "application", "WebBrowser", "execute"]) + client_1_db_client_execute = net.apply_request(["node", "client_1", "application", "DatabaseClient", "execute"]) + client_2_browser_execute = net.apply_request(["node", "client_2", "application", "WebBrowser", "execute"]) + client_2_db_client_execute = net.apply_request(["node", "client_2", "application", "DatabaseClient", "execute"]) + assert client_1_browser_execute.status == "success" + assert client_1_db_client_execute.status == "success" + assert client_2_browser_execute.status == "success" + assert client_2_db_client_execute.status == "success" + + client_1 = net.get_node_by_hostname("client_1") + client_2 = net.get_node_by_hostname("client_2") + + client_1.shut_down_duration = 0 + client_1.power_off() + client_2.shut_down_duration = 0 + client_2.power_off() + + client_1_browser_execute_off = net.apply_request(["node", "client_1", "application", "WebBrowser", "execute"]) + client_1_db_client_execute_off = net.apply_request( + ["node", "client_1", "application", "DatabaseClient", "execute"] + ) + client_2_browser_execute_off = net.apply_request(["node", "client_2", "application", "WebBrowser", "execute"]) + client_2_db_client_execute_off = net.apply_request( + ["node", "client_2", "application", "DatabaseClient", "execute"] + ) + assert client_1_browser_execute_off.status == "failure" + assert client_1_db_client_execute_off.status == "failure" + assert client_2_browser_execute_off.status == "failure" + assert client_2_db_client_execute_off.status == "failure" + + def test_acl_block(self, uc2_network): + """Test that green requests succeed when not blocked by ACLs but fail when blocked.""" + net = uc2_network + + router: Router = net.get_node_by_hostname("router_1") + client_1: HostNode = net.get_node_by_hostname("client_1") + client_2: HostNode = net.get_node_by_hostname("client_2") + + client_1_browser_execute = net.apply_request(["node", "client_1", "application", "WebBrowser", "execute"]) + client_2_browser_execute = net.apply_request(["node", "client_2", "application", "WebBrowser", "execute"]) + assert client_1_browser_execute.status == "success" + assert client_2_browser_execute.status == "success" + + router.acl.add_rule(ACLAction.DENY, src_port=Port.HTTP, dst_port=Port.HTTP, position=3) + client_1_browser_execute = net.apply_request(["node", "client_1", "application", "WebBrowser", "execute"]) + client_2_browser_execute = net.apply_request(["node", "client_2", "application", "WebBrowser", "execute"]) + assert client_1_browser_execute.status == "failure" + assert client_2_browser_execute.status == "failure" + + client_1_db_client_execute = net.apply_request(["node", "client_1", "application", "DatabaseClient", "execute"]) + client_2_db_client_execute = net.apply_request(["node", "client_2", "application", "DatabaseClient", "execute"]) + assert client_1_db_client_execute.status == "success" + assert client_2_db_client_execute.status == "success" + + router.acl.add_rule(ACLAction.DENY, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER) + client_1_db_client_execute = net.apply_request(["node", "client_1", "application", "DatabaseClient", "execute"]) + client_2_db_client_execute = net.apply_request(["node", "client_2", "application", "DatabaseClient", "execute"]) + assert client_1_db_client_execute.status == "failure" + assert client_2_db_client_execute.status == "failure" From f4684b0349d306a9c1cbe756fba3749c6beb5fd7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sat, 9 Mar 2024 23:32:00 +0000 Subject: [PATCH 696/980] Fix how nmnes are getting put into obs space. --- src/primaite/game/agent/observations.py | 13 +++- .../Data-Manipulation-E2E-Demonstration.ipynb | 67 +++++++++++++------ .../simulator/network/hardware/base.py | 3 +- 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/primaite/game/agent/observations.py b/src/primaite/game/agent/observations.py index 82e11fe0..83d1c4be 100644 --- a/src/primaite/game/agent/observations.py +++ b/src/primaite/game/agent/observations.py @@ -367,6 +367,13 @@ class NicObservation(AbstractObservation): """ super().__init__() self.where: Optional[Tuple[str]] = where + if CAPTURE_NMNE: + self.nmne_inbound_last_step: int = 0 + """NMNEs persist for the whole episode, but we want to count per step. Keeping track of last step count lets + us find the difference.""" + self.nmne_outbound_last_step: int = 0 + """NMNEs persist for the whole episode, but we want to count per step. Keeping track of last step count lets + us find the difference.""" def _categorise_mne_count(self, nmne_count: int) -> int: """ @@ -414,8 +421,10 @@ class NicObservation(AbstractObservation): inbound_count = inbound_keywords.get("*", 0) outbound_keywords = direction_dict.get("outbound", {}).get("keywords", {}) outbound_count = outbound_keywords.get("*", 0) - obs_dict["nmne"]["inbound"] = self._categorise_mne_count(inbound_count) - obs_dict["nmne"]["outbound"] = self._categorise_mne_count(outbound_count) + obs_dict["nmne"]["inbound"] = self._categorise_mne_count(inbound_count - self.nmne_inbound_last_step) + obs_dict["nmne"]["outbound"] = self._categorise_mne_count(outbound_count - self.nmne_outbound_last_step) + self.nmne_inbound_last_step = inbound_count + self.nmne_outbound_last_step = outbound_count return obs_dict @property diff --git a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb index e35e6126..1d7cb157 100644 --- a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb @@ -426,13 +426,13 @@ "def friendly_output_red_action(info):\n", " # parse the info dict form step output and write out what the red agent is doing\n", " red_info = info['agent_actions']['data_manipulation_attacker']\n", - " red_action = red_info[0]\n", + " red_action = red_info['action']\n", " if red_action == 'DONOTHING':\n", " red_str = 'DO NOTHING'\n", " elif red_action == 'NODE_APPLICATION_EXECUTE':\n", - " client = \"client 1\" if red_info[1]['node_id'] == 0 else \"client 2\"\n", + " client = \"client 1\" if red_info['parameters']['node_id'] == 0 else \"client 2\"\n", " red_str = f\"ATTACK from {client}\"\n", - " return red_str" + " return red_str\n" ] }, { @@ -492,7 +492,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Also, the NMNE outbound of either client 1 (node 6) or client 2 (node 7) has increased from 0 to 1. This tells us which client is being used by the red agent." + "Also, the NMNE outbound of either client 1 (node 6) or client 2 (node 7) increased from 0 to 1, but only right after the red attack, so we probably cannot see it now." ] }, { @@ -510,9 +510,9 @@ "source": [ "obs, reward, terminated, truncated, info = env.step(13) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", - "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker'][0]}\" )\n", - "print(f\"Green action: {info['agent_actions']['client_1_green_user'][0]}\" )\n", - "print(f\"Green action: {info['agent_actions']['client_2_green_user'][0]}\" )\n", + "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker']['action']}\" )\n", + "print(f\"Green action: {info['agent_actions']['client_1_green_user']['action']}\" )\n", + "print(f\"Green action: {info['agent_actions']['client_2_green_user']['action']}\" )\n", "print(f\"Blue reward:{reward}\" )" ] }, @@ -535,7 +535,7 @@ "source": [ "obs, reward, terminated, truncated, info = env.step(0) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", - "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker'][0]}\" )\n", + "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker']['action']}\" )\n", "print(f\"Green action: {info['agent_actions']['client_2_green_user']}\" )\n", "print(f\"Green action: {info['agent_actions']['client_1_green_user']}\" )\n", "print(f\"Blue reward:{reward:.2f}\" )" @@ -557,17 +557,17 @@ "outputs": [], "source": [ "env.step(13) # Patch the database\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )\n", "\n", "env.step(50) # Block client 1\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )\n", "\n", "env.step(51) # Block client 2\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )\n", "\n", "for step in range(30):\n", " obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", - " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )" + " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )" ] }, { @@ -606,20 +606,35 @@ "metadata": {}, "outputs": [], "source": [ - "if obs['NODES'][6]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", - " # client 1 has NMNEs, let's unblock client 2\n", - " env.step(58) # remove ACL rule 6\n", - "elif obs['NODES'][7]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", - " env.step(57) # remove ACL rule 5\n", - "else:\n", - " print(\"something went wrong, neither client has NMNEs\")" + "env.step(58) # Remove the ACL rule that blocks client 1\n", + "env.step(57) # Remove the ACL rule that blocks client 2\n", + "\n", + "tries = 0\n", + "while True:\n", + " tries += 1\n", + " obs, reward, terminated, truncated, info = env.step(0)\n", + "\n", + " if obs['NODES'][6]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", + " # client 1 has NMNEs, let's block it\n", + " obs, reward, terminated, truncated, info = env.step(50) # block client 1\n", + " break\n", + " elif obs['NODES'][7]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", + " # client 2 has NMNEs, so let's block it\n", + " obs, reward, terminated, truncated, info = env.step(51) # block client 2\n", + " break\n", + " if tries>100:\n", + " print(\"Error: NMNE never increased\")\n", + " break\n", + "\n", + "env.step(13) # Patch the database\n", + "..." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Now, the reward will eventually increase to 1.0, even after red agent attempts subsequent attacks." + "Now, the reward will eventually increase to 0.9, even after red agent attempts subsequent attacks." ] }, { @@ -628,9 +643,10 @@ "metadata": {}, "outputs": [], "source": [ - "for step in range(30):\n", + "\n", + "for step in range(40):\n", " obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", - " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )" + " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )" ] }, { @@ -648,6 +664,13 @@ "source": [ "env.reset()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index f3cf29bb..69c6b1da 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -260,10 +260,9 @@ class NetworkInterface(SimComponent, ABC): """ Apply a timestep evolution to this component. - This just clears the nmne count back to 0.tests/integration_tests/network/test_capture_nmne.py + This just clears the nmne count back to 0. """ super().apply_timestep(timestep=timestep) - self.nmne.clear() class WiredNetworkInterface(NetworkInterface, ABC): From e5c5a85003d462e6e61beeb6929443530375504d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 10 Mar 2024 13:05:57 +0000 Subject: [PATCH 697/980] Add docs on request response --- docs/Makefile | 2 +- docs/source/request_system.rst | 41 ++++++++++++++++++++++++++++------ docs/source/state_system.rst | 4 ++-- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/docs/Makefile b/docs/Makefile index dd71ec33..82719283 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -6,7 +6,7 @@ SPHINXBUILD ?= sphinx-build SOURCEDIR = . BUILDDIR = _build -AUTOSUMMARY="source\_autosummary" +AUTOSUMMARY="source/_autosummary" # Remove command is different depending on OS ifdef OS diff --git a/docs/source/request_system.rst b/docs/source/request_system.rst index e4c5584e..fb9d3978 100644 --- a/docs/source/request_system.rst +++ b/docs/source/request_system.rst @@ -3,7 +3,7 @@ © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK Request System -============== +************** ``SimComponent`` objects in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``RequestManager`` and ``RequestType``. @@ -12,26 +12,37 @@ Just like other aspects of SimComponent, the request types are not managed centr - API When requesting an action within the simulation, these two arguments must be provided: - 1. ``request`` - selects which action you want to take on this ``SimComponent``. This is formatted as a list of strings such as `['network', 'node', '', 'service', '', 'restart']`. + 1. ``request`` - selects which action you want to take on this ``SimComponent``. This is formatted as a list of strings such as ``['network', 'node', '', 'service', '', 'restart']``. 2. ``context`` - optional extra information that can be used to decide how to process the request. This is formatted as a dictionary. For example, if the request requires authentication, the context can include information about the user that initiated the request to decide if their permissions are sufficient. + When a request is resolved, it returns a success status, and optional additional data about the request. + + ``status`` can be one of: + + * ``success``: the request was executed + * ``failure``: the request could not be executed + * ``unreachable``: the target for the request was not found + * ``pending``: the request was initiated, but has not finished during this step + + ``data`` can be a dictionary with any arbitrary JSON-like data to describe the outcome of the request. + - ``request`` detail The request is a list of strings which help specify who should handle the request. The strings in the request list help RequestManagers traverse the 'ownership tree' of SimComponent. The example given above would be handled in the following way: - 1. ``Simulation`` receives `['network', 'node', '', 'service', '', 'restart']`. + 1. ``Simulation`` receives ``['network', 'node', 'computer_1', 'service', 'DNSService', 'restart']``. The first element of the request is ``network``, therefore it passes the request down to its network. - 2. ``Network`` receives `['node', '', 'service', '', 'restart']`. + 2. ``Network`` receives ``['node', 'computer_1', 'service', 'DNSService', 'restart']``. The first element of the request is ``node``, therefore the network looks at the node name and passes the request down to the node with that name. - 3. ``Node`` receives `['service', '', 'restart']`. + 3. ``computer_1`` receives ``['service', 'DNSService', 'restart']``. The first element of the request is ``service``, therefore the node looks at the service name and passes the rest of the request to the service with that name. - 4. ``Service`` receives ``['restart']``. + 4. ``DNSService`` receives ``['restart']``. Since ``restart`` is a defined request type in the service's own RequestManager, the service performs a restart. - ``context`` detail The context is not used by any of the currently implemented components or requests. Technical Detail ----------------- +================ This system was achieved by implementing two classes, :py:class:`primaite.simulator.core.RequestType`, and :py:class:`primaite.simulator.core.RequestManager`. @@ -93,3 +104,19 @@ An example of how this works is in the :py:class:`primaite.simulator.network.har self._service_request_manager.add_request(service.name, RequestType(func=service._request_manager)) This process is repeated until the request word corresponds to a callable function rather than another ``RequestManager`` . + +Request Validation +------------------ + +There are times when a request should be rejected. For instance, if an agent attempts to run an application on a node that is currently off. For this purpose, requests are filtered by an object called a validator. :py:class:`primaite.simulator.core.RequestPermissionValidator` is a basic class whose ``__call__()`` method returns ``True`` if the request should be permitted or ``False`` if it cannot be permitted. For example, the Node class has a validator called :py:class:`primaite.simulator.network.hardware.base.Node._NodeIsOnValidator<_NodeIsOnValidator>` which allows requests only when the operating status of the node is ``ON``. + +Requests that are specified without a validator automatically get assigned an ``AllowAllValidator`` which allows requests no matter what. + +Request Response +---------------- + +The :py:class:`primaite.interface.request.RequestResponse` is a data transfer object that carries response data between the simulator and the game layer. The ``status`` field reports on the success or failure, and the ``data`` field is for any additional data. The most common way that this class is initiated is by its ``from_bool`` method. This way, given a True or False, a successful or failed request response is generated, respectively (with an empty data field). + +For instance, the ``execute`` action on a :py:class:`primaite.simulator.system.applications.web_browser.WebBrowser` calls the ``get_webpage()`` method of the ``WebBrowser``. ``get_webpage()`` returns a True if the webpage was successfully retrieved, and False if unsuccessful for any reason, such as being blocked by an ACL, or if the database server is unresponsive. The boolean returned from ``get_webpage()`` is used to create the request response. + +Just as the requests themselves were passed from owner to component, the request response is bubbled back up from component to owner until it arrives at the game layer. diff --git a/docs/source/state_system.rst b/docs/source/state_system.rst index 0bbbdd34..5fc12c23 100644 --- a/docs/source/state_system.rst +++ b/docs/source/state_system.rst @@ -5,9 +5,9 @@ Simulation State ================ -``SimComponent`` objects in the simulation have a method called ``describe_state`` which return a dictionary of the state of the component. This is used to report pertinent data that could impact an agent's actions or rewards. For instance, the name and health status of a node is reported, which can be used by a reward function to punish corrupted or compromised nodes and reward healthy nodes. Each ``SimComponent`` object reports not only its own attributes in the state but also those of its child components. I.e. a computer node will report the state of its ``FileSystem`` and the ``FileSystem`` will report the state of its files and folders. This happens by recursively calling the childrens' own ``describe_state`` methods. +``SimComponent`` objects in the simulation have a method called ``describe_state`` which return a dictionary of the state of the component. This is used to report pertinent data that could impact an agent's actions or rewards. For instance, the name and health status of a node is reported, which can be used by a reward function to punish corrupted or compromised nodes and reward healthy nodes. Each ``SimComponent`` object reports not only its own attributes in the state but also those of its child components. I.e. a computer node will report the state of its ``FileSystem`` and the ``FileSystem`` will report the state of its files and folders. This happens by recursively calling the children's own ``describe_state`` methods. -The game layer calls ``describe_state`` on the trunk ``SimComponent`` (the top-level parent) and then passes the state to the agents once per simulation step. For this reason, all ``SimComponent`` objetcs must have a ``describe_state`` method, and they must all be linked to the trunk ``SimComponent``. +The game layer calls ``describe_state`` on the trunk ``SimComponent`` (the top-level parent) and then passes the state to the agents once per simulation step. For this reason, all ``SimComponent`` objects must have a ``describe_state`` method, and they must all be linked to the trunk ``SimComponent``. This code snippet demonstrates how the state information is defined within the ``SimComponent`` class: From d2afcaa939d66449e75d9cd80131f70e8fe22953 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 10 Mar 2024 13:06:45 +0000 Subject: [PATCH 698/980] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdf7b5c3..ae40a36f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- Made requests fail to reach their target if the node is off +- Added responses to requests - Made environment reset completely recreate the game object. - Changed the red agent in the data manipulation scenario to randomly choose client 1 or client 2 to start its attack. - Changed the data manipulation scenario to include a second green agent on client 1. From a228a099175aeb40acaad33af87d13b19a6c34ef Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Sun, 10 Mar 2024 15:13:37 +0000 Subject: [PATCH 699/980] #2350: documentation --- docs/source/configuration/game.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/source/configuration/game.rst b/docs/source/configuration/game.rst index e43ea224..828571a7 100644 --- a/docs/source/configuration/game.rst +++ b/docs/source/configuration/game.rst @@ -23,6 +23,11 @@ This section defines high-level settings that apply across the game, currently i - ICMP - TCP - UDP + thresholds: + nmne: + high: 10 + medium: 5 + low: 0 ``max_episode_length`` ---------------------- @@ -44,3 +49,8 @@ See :ref:`List of Ports ` for a list of ports. A list of protocols that the Reinforcement Learning agent(s) are able to see in the observation space. See :ref:`List of IPProtocols ` for a list of protocols. + +``thresholds`` +-------------- + +These are used to determine the thresholds of high, medium and low categories for counted observation occurrences. From 66ab5ec980a806a384d0aa7c2fd9280aa9d35da4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 11 Mar 2024 09:18:31 +0000 Subject: [PATCH 700/980] Fix last tests --- .../component_creation/test_action_integration.py | 2 ++ tests/integration_tests/network/test_capture_nmne.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/integration_tests/component_creation/test_action_integration.py b/tests/integration_tests/component_creation/test_action_integration.py index f41a57af..e7c9fcc6 100644 --- a/tests/integration_tests/component_creation/test_action_integration.py +++ b/tests/integration_tests/component_creation/test_action_integration.py @@ -12,6 +12,8 @@ def test_passing_actions_down(monkeypatch) -> None: sim = Simulation() pc1 = Computer(hostname="PC-1", ip_address="10.10.1.1", subnet_mask="255.255.255.0") + pc1.start_up_duration = 0 + pc1.power_on() pc2 = Computer(hostname="PC-2", ip_address="10.10.1.2", subnet_mask="255.255.255.0") srv = Server(hostname="WEBSERVER", ip_address="10.10.1.100", subnet_mask="255.255.255.0") s1 = Switch(hostname="switch1") diff --git a/tests/integration_tests/network/test_capture_nmne.py b/tests/integration_tests/network/test_capture_nmne.py index 698bfc72..43bb176b 100644 --- a/tests/integration_tests/network/test_capture_nmne.py +++ b/tests/integration_tests/network/test_capture_nmne.py @@ -125,8 +125,8 @@ def test_describe_state_nmne(uc2_network): web_server_nic_state = web_server_nic.describe_state() db_server_nic_state = db_server_nic.describe_state() uc2_network.apply_timestep(timestep=0) - assert web_server_nic_state["nmne"] == {} - assert db_server_nic_state["nmne"] == {} + assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}} + assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 1}}}} # Perform another "DELETE" query db_client.query("DELETE") @@ -135,8 +135,8 @@ def test_describe_state_nmne(uc2_network): web_server_nic_state = web_server_nic.describe_state() db_server_nic_state = db_server_nic.describe_state() uc2_network.apply_timestep(timestep=0) - assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}} - assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 1}}}} + assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 2}}}} + assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 2}}}} def test_capture_nmne_observations(uc2_network): From 1faefbccac5b2e93041e044fbc2f0d2c1c5c6125 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 11 Mar 2024 10:20:47 +0000 Subject: [PATCH 701/980] Add docstring for init request manager --- src/primaite/simulator/domain/controller.py | 5 +++++ src/primaite/simulator/file_system/file_system.py | 5 +++++ .../simulator/file_system/file_system_item_abc.py | 5 +++++ src/primaite/simulator/file_system/folder.py | 5 +++++ src/primaite/simulator/network/container.py | 5 +++++ src/primaite/simulator/network/hardware/base.py | 10 ++++++++++ .../simulator/network/hardware/nodes/network/router.py | 10 ++++++++++ src/primaite/simulator/sim_container.py | 5 +++++ .../simulator/system/applications/database_client.py | 5 +++++ .../red_applications/data_manipulation_bot.py | 5 +++++ .../system/applications/red_applications/dos_bot.py | 5 +++++ .../simulator/system/applications/web_browser.py | 5 +++++ src/primaite/simulator/system/services/service.py | 5 +++++ src/primaite/simulator/system/software.py | 5 +++++ 14 files changed, 80 insertions(+) diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index 0936b5f8..432a1d9a 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -80,6 +80,11 @@ class DomainController(SimComponent): super().__init__(**kwargs) def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() # Action 'account' matches requests like: # ['account', '', *account_action] diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 9e2a3b0e..ade03412 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -36,6 +36,11 @@ class FileSystem(SimComponent): self.create_folder("root") def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() self._delete_manager = RequestManager() diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py index efac97c3..32f5f6be 100644 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -101,6 +101,11 @@ class FileSystemItemABC(SimComponent): return state def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() rm.add_request( diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index fff08b23..c3ddff8a 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -51,6 +51,11 @@ class Folder(FileSystemItemABC): self.sys_log.info(f"Created file /{self.name} (id: {self.uuid})") def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() rm.add_request( name="delete", diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 6c2f38c5..0e970c3d 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -61,6 +61,11 @@ class Network(SimComponent): software.run() def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() self._node_request_manager = RequestManager() rm.add_request( diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 69c6b1da..a91a709c 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -114,6 +114,11 @@ class NetworkInterface(SimComponent, ABC): self.enable() def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() rm.add_request("enable", RequestType(func=lambda request, context: RequestResponse.from_bool(self.enable()))) @@ -786,6 +791,11 @@ class Node(SimComponent): return self.node.operating_state == NodeOperatingState.ON def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ _node_is_on = Node._NodeIsOnValidator(node=self) rm = super()._init_request_manager() diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 2fab4a3d..d2b47c1a 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -294,6 +294,11 @@ class AccessControlList(SimComponent): self._acl = [None] * (self.max_acl_rules - 1) def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ # TODO: Add src and dst wildcard masks as positional args in this request. rm = super()._init_request_manager() @@ -1092,6 +1097,11 @@ class Router(NetworkNode): super().setup_for_episode(episode=episode) def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() rm.add_request("acl", RequestType(func=self.acl._request_manager)) return rm diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index 2f603f3a..997cc0be 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -27,6 +27,11 @@ class Simulation(SimComponent): self.network.setup_for_episode(episode=episode) def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() # pass through network requests to the network objects rm.add_request("network", RequestType(func=self.network._request_manager)) diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 12148683..de7103f7 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -37,6 +37,11 @@ class DatabaseClient(Application): super().__init__(**kwargs) def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() rm.add_request("execute", RequestType(func=lambda request, context: RequestResponse.from_bool(self.execute()))) return rm diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index f71b1465..23e69e4d 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -75,6 +75,11 @@ class DataManipulationBot(Application): return db_client def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() rm.add_request( diff --git a/src/primaite/simulator/system/applications/red_applications/dos_bot.py b/src/primaite/simulator/system/applications/red_applications/dos_bot.py index 05f87f03..27a4da05 100644 --- a/src/primaite/simulator/system/applications/red_applications/dos_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/dos_bot.py @@ -58,6 +58,11 @@ class DoSBot(DatabaseClient): self.max_sessions = 1000 # override normal max sessions def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() rm.add_request( diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index 5dee1dd5..a26570ed 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -51,6 +51,11 @@ class WebBrowser(Application): self.run() def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() rm.add_request( name="execute", diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 706f166b..e15377a9 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -80,6 +80,11 @@ class Service(IOSoftware): return super().receive(payload=payload, session_id=session_id, **kwargs) def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() rm.add_request("scan", RequestType(func=lambda request, context: RequestResponse.from_bool(self.scan()))) rm.add_request("stop", RequestType(func=lambda request, context: RequestResponse.from_bool(self.stop()))) diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 2af53886..d55f141f 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -102,6 +102,11 @@ class Software(SimComponent): "Current number of ticks left to patch the software." def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ rm = super()._init_request_manager() rm.add_request( "compromise", From cd6d6325db51ab7857efaf8af4fba03f06f79aa9 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 11 Mar 2024 17:47:33 +0000 Subject: [PATCH 702/980] #2350: add tests to check spaces + acl obs test + nmne space changes --- .../_package_data/data_manipulation.yaml | 2 - .../agent/observations/nic_observations.py | 29 ++++++-- .../observations/software_observation.py | 2 +- .../observations/test_acl_observations.py | 66 +++++++++++++++++ .../test_file_system_observations.py | 4 +- .../observations/test_link_observations.py | 73 +++++++++++++++++++ ...servations.py => test_nic_observations.py} | 22 ++++++ .../observations/test_node_observations.py | 3 + .../test_software_observations.py | 4 + 9 files changed, 193 insertions(+), 12 deletions(-) create mode 100644 tests/integration_tests/game_layer/observations/test_acl_observations.py create mode 100644 tests/integration_tests/game_layer/observations/test_link_observations.py rename tests/integration_tests/game_layer/observations/{test_observations.py => test_nic_observations.py} (76%) diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index 47204878..a3a7e44a 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -22,8 +22,6 @@ io_settings: game: max_episode_length: 256 ports: - - ARP - - DNS - HTTP - POSTGRES_SERVER protocols: diff --git a/src/primaite/game/agent/observations/nic_observations.py b/src/primaite/game/agent/observations/nic_observations.py index 39298ffe..735b41d4 100644 --- a/src/primaite/game/agent/observations/nic_observations.py +++ b/src/primaite/game/agent/observations/nic_observations.py @@ -20,6 +20,8 @@ class NicObservation(AbstractObservation): high_nmne_threshold: int = 10 """The minimum number of malicious network events to be considered high.""" + global CAPTURE_NMNE + @property def default_observation(self) -> Dict: """The default NIC observation dict.""" @@ -47,6 +49,15 @@ class NicObservation(AbstractObservation): super().__init__() self.where: Optional[Tuple[str]] = where + global CAPTURE_NMNE + if CAPTURE_NMNE: + self.nmne_inbound_last_step: int = 0 + """NMNEs persist for the whole episode, but we want to count per step. Keeping track of last step count lets + us find the difference.""" + self.nmne_outbound_last_step: int = 0 + """NMNEs persist for the whole episode, but we want to count per step. Keeping track of last step count lets + us find the difference.""" + if low_nmne_threshold or med_nmne_threshold or high_nmne_threshold: self._validate_nmne_categories( low_nmne_threshold=low_nmne_threshold, @@ -128,19 +139,21 @@ class NicObservation(AbstractObservation): inbound_count = inbound_keywords.get("*", 0) outbound_keywords = direction_dict.get("outbound", {}).get("keywords", {}) outbound_count = outbound_keywords.get("*", 0) - obs_dict["nmne"]["inbound"] = self._categorise_mne_count(inbound_count) - obs_dict["nmne"]["outbound"] = self._categorise_mne_count(outbound_count) + obs_dict["nmne"]["inbound"] = self._categorise_mne_count(inbound_count - self.nmne_inbound_last_step) + obs_dict["nmne"]["outbound"] = self._categorise_mne_count(outbound_count - self.nmne_outbound_last_step) + self.nmne_inbound_last_step = inbound_count + self.nmne_outbound_last_step = outbound_count return obs_dict @property def space(self) -> spaces.Space: """Gymnasium space object describing the observation space shape.""" - return spaces.Dict( - { - "nic_status": spaces.Discrete(3), - "nmne": spaces.Dict({"inbound": spaces.Discrete(6), "outbound": spaces.Discrete(6)}), - } - ) + space = spaces.Dict({"nic_status": spaces.Discrete(3)}) + + if CAPTURE_NMNE: + space["nmne"] = spaces.Dict({"inbound": spaces.Discrete(4), "outbound": spaces.Discrete(4)}) + + return space @classmethod def from_config(cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]]) -> "NicObservation": diff --git a/src/primaite/game/agent/observations/software_observation.py b/src/primaite/game/agent/observations/software_observation.py index ff61714a..6caf791c 100644 --- a/src/primaite/game/agent/observations/software_observation.py +++ b/src/primaite/game/agent/observations/software_observation.py @@ -51,7 +51,7 @@ class ServiceObservation(AbstractObservation): @property def space(self) -> spaces.Space: """Gymnasium space object describing the observation space shape.""" - return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(6)}) + return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(5)}) @classmethod def from_config( diff --git a/tests/integration_tests/game_layer/observations/test_acl_observations.py b/tests/integration_tests/game_layer/observations/test_acl_observations.py new file mode 100644 index 00000000..93867edd --- /dev/null +++ b/tests/integration_tests/game_layer/observations/test_acl_observations.py @@ -0,0 +1,66 @@ +import pytest + +from primaite.game.agent.observations.observations import AclObservation +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.sim_container import Simulation +from primaite.simulator.system.services.ntp.ntp_client import NTPClient +from primaite.simulator.system.services.ntp.ntp_server import NTPServer + + +@pytest.fixture(scope="function") +def simulation(example_network) -> Simulation: + sim = Simulation() + + # set simulation network as example network + sim.network = example_network + + return sim + + +def test_acl_observations(simulation): + """Test the ACL rule observations.""" + router: Router = simulation.network.get_node_by_hostname("router_1") + client_1: Computer = simulation.network.get_node_by_hostname("client_1") + server: Computer = simulation.network.get_node_by_hostname("server_1") + + # quick set up of ntp + client_1.software_manager.install(NTPClient) + ntp_client: NTPClient = client_1.software_manager.software.get("NTPClient") + ntp_client.configure(server.network_interface.get(1).ip_address) + server.software_manager.install(NTPServer) + + # add router acl rule + router.acl.add_rule(action=ACLAction.PERMIT, dst_port=Port.NTP, src_port=Port.NTP, position=1) + + acl_obs = AclObservation( + where=["network", "nodes", router.hostname, "acl", "acl"], + node_ip_to_id={}, + ports=["NTP", "HTTP", "POSTGRES_SERVER"], + protocols=["TCP", "UDP", "ICMP"], + ) + + observation_space = acl_obs.observe(simulation.describe_state()) + assert observation_space.get(1) is not None + rule_obs = observation_space.get(1) # this is the ACL Rule added to allow NTP + assert rule_obs.get("position") == 0 # rule was put at position 1 (0 because counting from 1 instead of 1) + assert rule_obs.get("permission") == 1 # permit = 1 deny = 2 + assert rule_obs.get("source_node_id") == 1 # applies to all source nodes + assert rule_obs.get("dest_node_id") == 1 # applies to all destination nodes + assert rule_obs.get("source_port") == 2 # NTP port is mapped to value 2 (1 = ALL, so 1+1 = 2 quik mafs) + assert rule_obs.get("dest_port") == 2 # NTP port is mapped to value 2 + assert rule_obs.get("protocol") == 1 # 1 = No Protocol + + router.acl.remove_rule(1) + + observation_space = acl_obs.observe(simulation.describe_state()) + assert observation_space.get(1) is not None + rule_obs = observation_space.get(1) # this is the ACL Rule added to allow NTP + assert rule_obs.get("position") == 0 + assert rule_obs.get("permission") == 0 + assert rule_obs.get("source_node_id") == 0 + assert rule_obs.get("dest_node_id") == 0 + assert rule_obs.get("source_port") == 0 + assert rule_obs.get("dest_port") == 0 + assert rule_obs.get("protocol") == 0 diff --git a/tests/integration_tests/game_layer/observations/test_file_system_observations.py b/tests/integration_tests/game_layer/observations/test_file_system_observations.py index 808007cc..35bb95fd 100644 --- a/tests/integration_tests/game_layer/observations/test_file_system_observations.py +++ b/tests/integration_tests/game_layer/observations/test_file_system_observations.py @@ -26,7 +26,7 @@ def test_file_observation(simulation): where=["network", "nodes", pc.hostname, "file_system", "folders", "root", "files", "dog.png"] ) - assert dog_file_obs.space == spaces.Dict({"health_status": spaces.Discrete(6)}) + assert dog_file_obs.space["health_status"] == spaces.Discrete(6) observation_state = dog_file_obs.observe(simulation.describe_state()) assert observation_state.get("health_status") == 1 # good initial @@ -52,6 +52,8 @@ def test_folder_observation(simulation): where=["network", "nodes", pc.hostname, "file_system", "folders", "test_folder"] ) + assert root_folder_obs.space["health_status"] == spaces.Discrete(6) + observation_state = root_folder_obs.observe(simulation.describe_state()) assert observation_state.get("FILES") is not None assert observation_state.get("health_status") == 1 diff --git a/tests/integration_tests/game_layer/observations/test_link_observations.py b/tests/integration_tests/game_layer/observations/test_link_observations.py new file mode 100644 index 00000000..bfe4d5cc --- /dev/null +++ b/tests/integration_tests/game_layer/observations/test_link_observations.py @@ -0,0 +1,73 @@ +import pytest +from gymnasium import spaces + +from primaite.game.agent.observations.observations import LinkObservation +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.base import Link, Node +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.sim_container import Simulation + + +@pytest.fixture(scope="function") +def simulation() -> Simulation: + sim = Simulation() + + network = Network() + + # Create Computer + computer = Computer( + hostname="computer", + ip_address="192.168.1.2", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + computer.power_on() + + # Create Server + server = Server( + hostname="server", + ip_address="192.168.1.3", + subnet_mask="255.255.255.0", + default_gateway="192.168.1.1", + start_up_duration=0, + ) + server.power_on() + + # Connect Computer and Server + network.connect(computer.network_interface[1], server.network_interface[1]) + + # Should be linked + assert next(iter(network.links.values())).is_up + + assert computer.ping(server.network_interface.get(1).ip_address) + + # set simulation network as example network + sim.network = network + + return sim + + +def test_link_observation(simulation): + """Test the link observation.""" + # get a link + link: Link = next(iter(simulation.network.links.values())) + + computer: Computer = simulation.network.get_node_by_hostname("computer") + server: Server = simulation.network.get_node_by_hostname("server") + + simulation.apply_timestep(0) # some pings when network was made - reset with apply timestep + + link_obs = LinkObservation(where=["network", "links", link.uuid]) + + assert link_obs.space["PROTOCOLS"]["ALL"] == spaces.Discrete(11) # test that the spaces are 0-10 including 0 and 10 + + observation_state = link_obs.observe(simulation.describe_state()) + assert observation_state.get("PROTOCOLS") is not None + assert observation_state["PROTOCOLS"]["ALL"] == 0 + + computer.ping(server.network_interface.get(1).ip_address) + + observation_state = link_obs.observe(simulation.describe_state()) + assert observation_state["PROTOCOLS"]["ALL"] == 1 diff --git a/tests/integration_tests/game_layer/observations/test_observations.py b/tests/integration_tests/game_layer/observations/test_nic_observations.py similarity index 76% rename from tests/integration_tests/game_layer/observations/test_observations.py rename to tests/integration_tests/game_layer/observations/test_nic_observations.py index 97df7882..c210b751 100644 --- a/tests/integration_tests/game_layer/observations/test_observations.py +++ b/tests/integration_tests/game_layer/observations/test_nic_observations.py @@ -1,9 +1,27 @@ +from pathlib import Path +from typing import Union + import pytest +import yaml +from gymnasium import spaces from primaite.game.agent.observations.nic_observations import NicObservation +from primaite.game.game import PrimaiteGame from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC +from primaite.simulator.network.nmne import CAPTURE_NMNE from primaite.simulator.sim_container import Simulation +from tests import TEST_ASSETS_ROOT + +BASIC_CONFIG = TEST_ASSETS_ROOT / "configs/basic_switched_network.yaml" + + +def load_config(config_path: Union[str, Path]) -> PrimaiteGame: + """Returns a PrimaiteGame object which loads the contents of a given yaml path.""" + with open(config_path, "r") as f: + cfg = yaml.safe_load(f) + + return PrimaiteGame.from_config(cfg) @pytest.fixture(scope="function") @@ -24,6 +42,10 @@ def test_nic(simulation): nic_obs = NicObservation(where=["network", "nodes", pc.hostname, "NICs", 1]) + assert nic_obs.space["nic_status"] == spaces.Discrete(3) + assert nic_obs.space["nmne"]["inbound"] == spaces.Discrete(4) + assert nic_obs.space["nmne"]["outbound"] == spaces.Discrete(4) + observation_state = nic_obs.observe(simulation.describe_state()) assert observation_state.get("nic_status") == 1 # enabled assert observation_state.get("nmne") is not None diff --git a/tests/integration_tests/game_layer/observations/test_node_observations.py b/tests/integration_tests/game_layer/observations/test_node_observations.py index 835202c6..b1563fbd 100644 --- a/tests/integration_tests/game_layer/observations/test_node_observations.py +++ b/tests/integration_tests/game_layer/observations/test_node_observations.py @@ -2,6 +2,7 @@ import copy from uuid import uuid4 import pytest +from gymnasium import spaces from primaite.game.agent.observations.node_observations import NodeObservation from primaite.simulator.network.hardware.nodes.host.computer import Computer @@ -24,6 +25,8 @@ def test_node_observation(simulation): node_obs = NodeObservation(where=["network", "nodes", pc.hostname]) + assert node_obs.space["operating_status"] == spaces.Discrete(5) + observation_state = node_obs.observe(simulation.describe_state()) assert observation_state.get("operating_status") == 1 # computer is on diff --git a/tests/integration_tests/game_layer/observations/test_software_observations.py b/tests/integration_tests/game_layer/observations/test_software_observations.py index 17fc386f..4ae0701e 100644 --- a/tests/integration_tests/game_layer/observations/test_software_observations.py +++ b/tests/integration_tests/game_layer/observations/test_software_observations.py @@ -1,4 +1,5 @@ import pytest +from gymnasium import spaces from primaite.game.agent.observations.software_observation import ApplicationObservation, ServiceObservation from primaite.simulator.network.hardware.nodes.host.computer import Computer @@ -29,6 +30,9 @@ def test_service_observation(simulation): service_obs = ServiceObservation(where=["network", "nodes", pc.hostname, "services", "NTPServer"]) + assert service_obs.space["operating_status"] == spaces.Discrete(7) + assert service_obs.space["health_status"] == spaces.Discrete(5) + observation_state = service_obs.observe(simulation.describe_state()) assert observation_state.get("health_status") == 0 From 759965587982931bd039df6a4084ff7aa364cbdd Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 11 Mar 2024 20:10:08 +0000 Subject: [PATCH 703/980] Add agent action history --- .../game/agent/data_manipulation_bot.py | 5 +- src/primaite/game/agent/interface.py | 37 ++++++++++++-- src/primaite/game/agent/rewards.py | 37 ++++++++++---- src/primaite/game/game.py | 51 +++++++++---------- src/primaite/interface/request.py | 4 +- .../Data-Manipulation-E2E-Demonstration.ipynb | 10 ++-- src/primaite/session/environment.py | 25 ++++----- src/primaite/session/io.py | 41 +++------------ src/primaite/simulator/core.py | 4 +- 9 files changed, 110 insertions(+), 104 deletions(-) diff --git a/src/primaite/game/agent/data_manipulation_bot.py b/src/primaite/game/agent/data_manipulation_bot.py index 16453433..d3ec19cb 100644 --- a/src/primaite/game/agent/data_manipulation_bot.py +++ b/src/primaite/game/agent/data_manipulation_bot.py @@ -14,7 +14,7 @@ class DataManipulationAgent(AbstractScriptedAgent): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.reset_agent_for_episode() + self.setup_agent() def _set_next_execution_timestep(self, timestep: int) -> None: """Set the next execution timestep with a configured random variance. @@ -43,9 +43,8 @@ class DataManipulationAgent(AbstractScriptedAgent): return "NODE_APPLICATION_EXECUTE", {"node_id": self.starting_node_idx, "application_id": 0} - def reset_agent_for_episode(self) -> None: + def setup_agent(self) -> None: """Set the next execution timestep when the episode resets.""" - super().reset_agent_for_episode() self._select_start_node() self._set_next_execution_timestep(self.agent_settings.start_settings.start_step) diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 88848479..0531b25f 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -1,6 +1,6 @@ """Interface for agents.""" from abc import ABC, abstractmethod -from typing import Dict, List, Optional, Tuple, TYPE_CHECKING +from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium.core import ActType, ObsType from pydantic import BaseModel, model_validator @@ -8,11 +8,31 @@ from pydantic import BaseModel, model_validator from primaite.game.agent.actions import ActionManager from primaite.game.agent.observations import ObservationManager from primaite.game.agent.rewards import RewardFunction +from primaite.interface.request import RequestFormat, RequestResponse if TYPE_CHECKING: pass +class AgentActionHistoryItem(BaseModel): + """One entry of an agent's action log - what the agent did and how the simulator responded in 1 step.""" + + timestep: int + """Timestep of this action.""" + + action: str + """CAOS Action name.""" + + parameters: Dict[str, Any] + """CAOS parameters for the given action.""" + + request: RequestFormat + """The request that was sent to the simulation based on the CAOS action chosen.""" + + response: RequestResponse + """The response sent back by the simulator for this action.""" + + class AgentStartSettings(BaseModel): """Configuration values for when an agent starts performing actions.""" @@ -90,6 +110,7 @@ class AbstractAgent(ABC): self.observation_manager: Optional[ObservationManager] = observation_space self.reward_function: Optional[RewardFunction] = reward_function self.agent_settings = agent_settings or AgentSettings() + self.action_history: List[AgentActionHistoryItem] = [] def update_observation(self, state: Dict) -> ObsType: """ @@ -109,7 +130,7 @@ class AbstractAgent(ABC): :return: Reward from the state. :rtype: float """ - return self.reward_function.update(state) + return self.reward_function.update(state=state, last_action_response=self.action_history[-1]) @abstractmethod def get_action(self, obs: ObsType, timestep: int = 0) -> Tuple[str, Dict]: @@ -138,9 +159,15 @@ class AbstractAgent(ABC): request = self.action_manager.form_request(action_identifier=action, action_options=options) return request - def reset_agent_for_episode(self) -> None: - """Agent reset logic should go here.""" - pass + def process_action_response( + self, timestep: int, action: str, parameters: Dict[str, Any], request: RequestFormat, response: RequestResponse + ) -> None: + """Process the response from the most recent action.""" + self.action_history.append( + AgentActionHistoryItem( + timestep=timestep, action=action, parameters=parameters, request=request, response=response + ) + ) class AbstractScriptedAgent(AbstractAgent): diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 8c8e36ad..6ab5aa42 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -26,11 +26,14 @@ the structure: ``` """ from abc import abstractmethod -from typing import Dict, List, Tuple, Type +from typing import Dict, List, Tuple, Type, TYPE_CHECKING from primaite import getLogger from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +if TYPE_CHECKING: + from primaite.game.agent.interface import AgentActionHistoryItem + _LOGGER = getLogger(__name__) @@ -38,7 +41,9 @@ class AbstractReward: """Base class for reward function components.""" @abstractmethod - def calculate(self, state: Dict) -> float: + def calculate( + self, state: Dict, last_action_response: "AgentActionHistoryItem" + ) -> float: # todo maybe make last_action_response optional? """Calculate the reward for the current state.""" return 0.0 @@ -58,7 +63,9 @@ class AbstractReward: class DummyReward(AbstractReward): """Dummy reward function component which always returns 0.""" - def calculate(self, state: Dict) -> float: + def calculate( + self, state: Dict, last_action_response: "AgentActionHistoryItem" + ) -> float: # todo maybe make last_action_response optional? """Calculate the reward for the current state.""" return 0.0 @@ -98,7 +105,9 @@ class DatabaseFileIntegrity(AbstractReward): file_name, ] - def calculate(self, state: Dict) -> float: + def calculate( + self, state: Dict, last_action_response: "AgentActionHistoryItem" + ) -> float: # todo maybe make last_action_response optional? """Calculate the reward for the current state. :param state: The current state of the simulation. @@ -153,7 +162,9 @@ class WebServer404Penalty(AbstractReward): """ self.location_in_state = ["network", "nodes", node_hostname, "services", service_name] - def calculate(self, state: Dict) -> float: + def calculate( + self, state: Dict, last_action_response: "AgentActionHistoryItem" + ) -> float: # todo maybe make last_action_response optional? """Calculate the reward for the current state. :param state: The current state of the simulation. @@ -206,7 +217,9 @@ class WebpageUnavailablePenalty(AbstractReward): self._node = node_hostname self.location_in_state = ["network", "nodes", node_hostname, "applications", "WebBrowser"] - def calculate(self, state: Dict) -> float: + def calculate( + self, state: Dict, last_action_response: "AgentActionHistoryItem" + ) -> float: # todo maybe make last_action_response optional? """ Calculate the reward based on current simulation state. @@ -255,13 +268,17 @@ class GreenAdminDatabaseUnreachablePenalty(AbstractReward): self._node = node_hostname self.location_in_state = ["network", "nodes", node_hostname, "applications", "DatabaseClient"] - def calculate(self, state: Dict) -> float: + def calculate( + self, state: Dict, last_action_response: "AgentActionHistoryItem" + ) -> float: # todo maybe make last_action_response optional? """ Calculate the reward based on current simulation state. :param state: The current state of the simulation. :type state: Dict """ + if last_action_response.request == ["network", "node", "client_2", "application", "DatabaseClient", "execute"]: + pass # TODO db_state = access_from_nested_dict(state, self.location_in_state) if db_state is NOT_PRESENT_IN_STATE or "last_connection_successful" not in db_state: _LOGGER.debug(f"Can't calculate reward for {self.__class__.__name__}") @@ -313,7 +330,9 @@ class RewardFunction: """ self.reward_components.append((component, weight)) - def update(self, state: Dict) -> float: + def update( + self, state: Dict, last_action_response: "AgentActionHistoryItem" + ) -> float: # todo maybe make last_action_response optional? """Calculate the overall reward for the current state. :param state: The current state of the simulation. @@ -323,7 +342,7 @@ class RewardFunction: for comp_and_weight in self.reward_components: comp = comp_and_weight[0] weight = comp_and_weight[1] - total += weight * comp.calculate(state=state) + total += weight * comp.calculate(state=state, last_action_response=last_action_response) self.current_reward = total return self.current_reward diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index c94cb3ad..1cc8cfed 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -1,6 +1,6 @@ """PrimAITE game - Encapsulates the simulation and agents.""" from ipaddress import IPv4Address -from typing import Dict, List, Tuple +from typing import Dict, List from pydantic import BaseModel, ConfigDict @@ -130,49 +130,44 @@ class PrimaiteGame: """ _LOGGER.debug(f"Stepping. Step counter: {self.step_counter}") - # Get the current state of the simulation - sim_state = self.get_sim_state() - - # Update agents' observations and rewards based on the current state - self.update_agents(sim_state) - # Apply all actions to simulation as requests - self.apply_agent_actions() + action_data = self.apply_agent_actions() # Advance timestep self.advance_timestep() + # Get the current state of the simulation + sim_state = self.get_sim_state() + + # Update agents' observations and rewards based on the current state, and the response from the last action + self.update_agents(state=sim_state, action_data=action_data) + def get_sim_state(self) -> Dict: """Get the current state of the simulation.""" return self.simulation.describe_state() def update_agents(self, state: Dict) -> None: """Update agents' observations and rewards based on the current state.""" - for _, agent in self.agents.items(): - agent.update_observation(state) - agent.update_reward(state) + for agent_name, agent in self.agents.items(): + if self.step_counter > 0: # can't get reward before first action + agent.update_reward(state=state) + agent.update_observation(state=state) agent.reward_function.total_reward += agent.reward_function.current_reward - def apply_agent_actions(self) -> Dict[str, Tuple[str, Dict]]: - """ - Apply all actions to simulation as requests. - - :return: A recap of each agent's actions, in CAOS format. - :rtype: Dict[str, Tuple[str, Dict]] - - """ - agent_actions = {} + def apply_agent_actions(self) -> None: + """Apply all actions to simulation as requests.""" for _, agent in self.agents.items(): obs = agent.observation_manager.current_observation - action_choice, options = agent.get_action(obs, timestep=self.step_counter) - request = agent.format_request(action_choice, options) + action_choice, parameters = agent.get_action(obs, timestep=self.step_counter) + request = agent.format_request(action_choice, parameters) response = self.simulation.apply_request(request) - agent_actions[agent.agent_name] = { - "action": action_choice, - "parameters": options, - "response": response.model_dump(), - } - return agent_actions + agent.process_action_response( + timestep=self.step_counter, + action=action_choice, + parameters=parameters, + request=request, + response=response, + ) def advance_timestep(self) -> None: """Advance timestep.""" diff --git a/src/primaite/interface/request.py b/src/primaite/interface/request.py index 8e922ef9..bc076599 100644 --- a/src/primaite/interface/request.py +++ b/src/primaite/interface/request.py @@ -1,7 +1,9 @@ -from typing import Dict, ForwardRef, Literal +from typing import Dict, ForwardRef, List, Literal, Union from pydantic import BaseModel, ConfigDict, StrictBool, validate_call +RequestFormat = List[Union[str, int, float]] + RequestResponse = ForwardRef("RequestResponse") """This makes it possible to type-hint RequestResponse.from_bool return type.""" diff --git a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb index 1d7cb157..b2522c2b 100644 --- a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb @@ -373,7 +373,7 @@ "# Imports\n", "from primaite.config.load import data_manipulation_config_path\n", "from primaite.session.environment import PrimaiteGymEnv\n", - "from primaite.game.game import PrimaiteGame\n", + "from primaite.game.agent.interface import AgentActionHistoryItem\n", "import yaml\n", "from pprint import pprint\n" ] @@ -425,14 +425,14 @@ "source": [ "def friendly_output_red_action(info):\n", " # parse the info dict form step output and write out what the red agent is doing\n", - " red_info = info['agent_actions']['data_manipulation_attacker']\n", - " red_action = red_info['action']\n", + " red_info : AgentActionHistoryItem = info['agent_actions']['data_manipulation_attacker']\n", + " red_action = red_info.action\n", " if red_action == 'DONOTHING':\n", " red_str = 'DO NOTHING'\n", " elif red_action == 'NODE_APPLICATION_EXECUTE':\n", - " client = \"client 1\" if red_info['parameters']['node_id'] == 0 else \"client 2\"\n", + " client = \"client 1\" if red_info.parameters['node_id'] == 0 else \"client 2\"\n", " red_str = f\"ATTACK from {client}\"\n", - " return red_str\n" + " return red_str" ] }, { diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 87638e7d..64534b04 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -49,23 +49,20 @@ class PrimaiteGymEnv(gymnasium.Env): # make ProxyAgent store the action chosen my the RL policy self.agent.store_action(action) # apply_agent_actions accesses the action we just stored - agent_actions = self.game.apply_agent_actions() + self.game.apply_agent_actions() self.game.advance_timestep() state = self.game.get_sim_state() - self.game.update_agents(state) - next_obs = self._get_obs() + next_obs = self._get_obs() # this doesn't update observation, just gets the current observation reward = self.agent.reward_function.current_reward terminated = False truncated = self.game.calculate_truncated() - info = {"agent_actions": agent_actions} # tell us what all the agents did for convenience. + info = { + "agent_actions": {name: agent.action_history[-1] for name, agent in self.game.agents.items()} + } # tell us what all the agents did for convenience. if self.game.save_step_metadata: self._write_step_metadata_json(action, state, reward) - if self.io.settings.save_agent_actions: - self.io.store_agent_actions( - agent_actions=agent_actions, episode=self.episode_counter, timestep=self.game.step_counter - ) return next_obs, reward, terminated, truncated, info def _write_step_metadata_json(self, action: int, state: Dict, reward: int): @@ -91,13 +88,13 @@ class PrimaiteGymEnv(gymnasium.Env): f"avg. reward: {self.agent.reward_function.total_reward}" ) if self.io.settings.save_agent_actions: - self.io.write_agent_actions(episode=self.episode_counter) - self.io.clear_agent_actions() + all_agent_actions = {name: agent.action_history for name, agent in self.game.agents.items()} + self.io.write_agent_actions(agent_actions=all_agent_actions, episode=self.episode_counter) self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=copy.deepcopy(self.game_config)) self.game.setup_for_episode(episode=self.episode_counter) self.episode_counter += 1 state = self.game.get_sim_state() - self.game.update_agents(state) + self.game.update_agents(state=state) next_obs = self._get_obs() info = {} return next_obs, info @@ -217,7 +214,7 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): # 1. Perform actions for agent_name, action in actions.items(): self.agents[agent_name].store_action(action) - agent_actions = self.game.apply_agent_actions() + self.game.apply_agent_actions() # 2. Advance timestep self.game.advance_timestep() @@ -236,10 +233,6 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): truncateds["__all__"] = self.game.calculate_truncated() if self.game.save_step_metadata: self._write_step_metadata_json(actions, state, rewards) - if self.io.settings.save_agent_actions: - self.io.store_agent_actions( - agent_actions=agent_actions, episode=self.episode_counter, timestep=self.game.step_counter - ) return next_obs, rewards, terminateds, truncateds, infos def _write_step_metadata_json(self, actions: Dict, state: Dict, rewards: Dict): diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index ed2b4d62..87289c43 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -48,8 +48,6 @@ class PrimaiteIO: SIM_OUTPUT.save_pcap_logs = self.settings.save_pcap_logs SIM_OUTPUT.save_sys_logs = self.settings.save_sys_logs - self.agent_action_log: List[Dict] = [] - def generate_session_path(self, timestamp: Optional[datetime] = None) -> Path: """Create a folder for the session and return the path to it.""" if timestamp is None: @@ -72,48 +70,23 @@ class PrimaiteIO: """Return the path where agent actions will be saved.""" return self.session_path / "agent_actions" / f"episode_{episode}.json" - def store_agent_actions(self, agent_actions: Dict, episode: int, timestep: int) -> None: - """Cache agent actions for a particular step. - - :param agent_actions: Dictionary describing actions for any agents that acted in this timestep. The expected - format contains agent identifiers as keys. The keys should map to a tuple of [CAOS action, parameters] - CAOS action is a string representing one the CAOS actions. - parameters is a dict of parameter names and values for that particular CAOS action. - For example: - { - 'green1' : ('NODE_APPLICATION_EXECUTE', {'node_id':1, 'application_id':0}), - 'defender': ('DO_NOTHING', {}) - } - :type agent_actions: Dict - :param timestep: Simulation timestep when these actions occurred. - :type timestep: int - """ - self.agent_action_log.append( - [ - { - "episode": episode, - "timestep": timestep, - "agent_actions": agent_actions, - } - ] - ) - - def write_agent_actions(self, episode: int) -> None: + def write_agent_actions(self, agent_actions: Dict[str, List], episode: int) -> None: """Take the contents of the agent action log and write it to a file. :param episode: Episode number :type episode: int """ + data = {} + longest_history = max([len(hist) for hist in agent_actions]) + for i in range(longest_history): + data[i] = {"timestep": i, "episode": episode, **{name: acts[i] for name, acts in agent_actions.items()}} + path = self.generate_agent_actions_save_path(episode=episode) path.parent.mkdir(exist_ok=True, parents=True) path.touch() _LOGGER.info(f"Saving agent action log to {path}") with open(path, "w") as file: - json.dump(self.agent_action_log, fp=file, indent=1) - - def clear_agent_actions(self) -> None: - """Reset the agent action log back to an empty dictionary.""" - self.agent_action_log = [] + json.dump(data, fp=file, indent=1) @classmethod def from_config(cls, config: Dict) -> "PrimaiteIO": diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index aeb4e865..6da8a2f8 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -7,12 +7,10 @@ from uuid import uuid4 from pydantic import BaseModel, ConfigDict, Field, validate_call from primaite import getLogger -from primaite.interface.request import RequestResponse +from primaite.interface.request import RequestFormat, RequestResponse _LOGGER = getLogger(__name__) -RequestFormat = List[Union[str, int, float]] - class RequestPermissionValidator(BaseModel): """ From c3f1cfb33d3516fcca84b5ffe944b46d080d1cf3 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 11 Mar 2024 22:53:39 +0000 Subject: [PATCH 704/980] Add shared reward --- .../_package_data/data_manipulation.yaml | 39 ++++--- src/primaite/game/agent/rewards.py | 100 +++++++++++++++--- src/primaite/game/game.py | 55 +++++++++- src/primaite/game/science.py | 79 ++++++++++++++ src/primaite/session/io.py | 7 +- 5 files changed, 242 insertions(+), 38 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index dffb40ea..f4789e50 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -73,7 +73,14 @@ agents: reward_function: reward_components: - - type: DUMMY + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.25 + options: + node_hostname: client_2 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.05 + options: + node_hostname: client_2 - ref: client_1_green_user team: GREEN @@ -116,7 +123,14 @@ agents: reward_function: reward_components: - - type: DUMMY + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.25 + options: + node_hostname: client_1 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.05 + options: + node_hostname: client_1 @@ -696,22 +710,15 @@ agents: node_hostname: database_server folder_name: database file_name: database.db - - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.25 + - type: SHARED_REWARD + weight: 1.0 options: - node_hostname: client_1 - - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.25 + agent_name: client_1_green_user + - type: SHARED_REWARD + weight: 1.0 options: - node_hostname: client_2 - - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.05 - options: - node_hostname: client_1 - - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.05 - options: - node_hostname: client_2 + agent_name: client_2_green_user + agent_settings: diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 6ab5aa42..86a61535 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -26,7 +26,9 @@ the structure: ``` """ from abc import abstractmethod -from typing import Dict, List, Tuple, Type, TYPE_CHECKING +from typing import Callable, Dict, List, Optional, Tuple, Type, TYPE_CHECKING + +from typing_extensions import Never from primaite import getLogger from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE @@ -214,18 +216,29 @@ class WebpageUnavailablePenalty(AbstractReward): :param node_hostname: Hostname of the node which has the web browser. :type node_hostname: str """ - self._node = node_hostname - self.location_in_state = ["network", "nodes", node_hostname, "applications", "WebBrowser"] + self._node: str = node_hostname + self.location_in_state: List[str] = ["network", "nodes", node_hostname, "applications", "WebBrowser"] + self._last_request_failed: bool = False def calculate( self, state: Dict, last_action_response: "AgentActionHistoryItem" ) -> float: # todo maybe make last_action_response optional? """ - Calculate the reward based on current simulation state. + Calculate the reward based on current simulation state, and the recent agent action. - :param state: The current state of the simulation. - :type state: Dict + When the green agent requests to execute the browser application, and that request fails, this reward + component will keep track of that information. In that case, it doesn't matter whether the last webpage + had a 200 status code, because there has been an unsuccessful request since. """ + if last_action_response.request == ["network", "node", self._node, "application", "DatabaseClient", "execute"]: + self._last_request_failed = last_action_response.response.status != "success" + + # if agent couldn't even get as far as sending the request (because for example the node was off), then + # apply a penalty + if self._last_request_failed: + return -1.0 + + # If the last request did actually go through, then check if the webpage also loaded web_browser_state = access_from_nested_dict(state, self.location_in_state) if web_browser_state is NOT_PRESENT_IN_STATE or "history" not in web_browser_state: _LOGGER.info( @@ -265,20 +278,28 @@ class GreenAdminDatabaseUnreachablePenalty(AbstractReward): :param node_hostname: Hostname of the node where the database client sits. :type node_hostname: str """ - self._node = node_hostname - self.location_in_state = ["network", "nodes", node_hostname, "applications", "DatabaseClient"] + self._node: str = node_hostname + self.location_in_state: List[str] = ["network", "nodes", node_hostname, "applications", "DatabaseClient"] + self._last_request_failed: bool = False - def calculate( - self, state: Dict, last_action_response: "AgentActionHistoryItem" - ) -> float: # todo maybe make last_action_response optional? + def calculate(self, state: Dict, last_action_response: "AgentActionHistoryItem") -> float: """ - Calculate the reward based on current simulation state. + Calculate the reward based on current simulation state, and the recent agent action. - :param state: The current state of the simulation. - :type state: Dict + When the green agent requests to execute the database client application, and that request fails, this reward + component will keep track of that information. In that case, it doesn't matter whether the last successful + request returned was able to connect to the database server, because there has been an unsuccessful request + since. """ - if last_action_response.request == ["network", "node", "client_2", "application", "DatabaseClient", "execute"]: - pass # TODO + if last_action_response.request == ["network", "node", self._node, "application", "DatabaseClient", "execute"]: + self._last_request_failed = last_action_response.response.status != "success" + + # if agent couldn't even get as far as sending the request (because for example the node was off), then + # apply a penalty + if self._last_request_failed: + return -1.0 + + # If the last request was actually sent, then check if the connection was established. db_state = access_from_nested_dict(state, self.location_in_state) if db_state is NOT_PRESENT_IN_STATE or "last_connection_successful" not in db_state: _LOGGER.debug(f"Can't calculate reward for {self.__class__.__name__}") @@ -301,6 +322,52 @@ class GreenAdminDatabaseUnreachablePenalty(AbstractReward): return cls(node_hostname=node_hostname) +class SharedReward(AbstractReward): + """Adds another agent's reward to the overall reward.""" + + def __init__(self, agent_name: Optional[str] = None) -> None: + """ + Initialise the shared reward. + + The agent_ref is a placeholder value. It starts off as none, but it must be set before this reward can work + correctly. + + :param agent_name: The name whose reward is an input + :type agent_ref: Optional[str] + """ + self.agent_name = agent_name + """Agent whose reward to track.""" + + def default_callback() -> Never: + """ + Default callback to prevent calling this reward until it's properly initialised. + + SharedReward should not be used until the game layer replaces self.callback with a reference to the + function that retrieves the desired agent's reward. Therefore, we define this default callback that raises + an error. + """ + raise RuntimeError("Attempted to calculate SharedReward but it was not initialised properly.") + + self.callback: Callable[[], float] = default_callback + """Method that retrieves an agent's current reward given the agent's name.""" + + def calculate(self, state: Dict, last_action_response: "AgentActionHistoryItem") -> float: + """Simply access the other agent's reward and return it.""" + print(self.callback(), self.agent_name) + return self.callback() + + @classmethod + def from_config(cls, config: Dict) -> "SharedReward": + """ + Build the SharedReward object from config. + + :param config: Configuration dictionary + :type config: Dict + """ + agent_name = config.get("agent_name") + return cls(agent_name=agent_name) + + class RewardFunction: """Manages the reward function for the agent.""" @@ -310,6 +377,7 @@ class RewardFunction: "WEB_SERVER_404_PENALTY": WebServer404Penalty, "WEBPAGE_UNAVAILABLE_PENALTY": WebpageUnavailablePenalty, "GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY": GreenAdminDatabaseUnreachablePenalty, + "SHARED_REWARD": SharedReward, } """List of reward class identifiers.""" diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 1cc8cfed..e766bcd3 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -9,8 +9,9 @@ from primaite.game.agent.actions import ActionManager from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent from primaite.game.agent.observations import ObservationManager -from primaite.game.agent.rewards import RewardFunction +from primaite.game.agent.rewards import RewardFunction, SharedReward from primaite.game.agent.scripted_agents import ProbabilisticAgent +from primaite.game.science import graph_has_cycle, topological_sort from primaite.simulator.network.hardware.base import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC @@ -110,6 +111,9 @@ class PrimaiteGame: self.save_step_metadata: bool = False """Whether to save the RL agents' action, environment state, and other data at every single step.""" + self._reward_calculation_order: List[str] = [name for name in self.agents] + """Agent order for reward evaluation, as some rewards can be dependent on other agents' rewards.""" + def step(self): """ Perform one step of the simulation/agent loop. @@ -148,10 +152,11 @@ class PrimaiteGame: def update_agents(self, state: Dict) -> None: """Update agents' observations and rewards based on the current state.""" - for agent_name, agent in self.agents.items(): + for agent_name in self._reward_calculation_order: + agent = self.agents[agent_name] if self.step_counter > 0: # can't get reward before first action agent.update_reward(state=state) - agent.update_observation(state=state) + agent.update_observation(state=state) # order of this doesn't matter so just use reward order agent.reward_function.total_reward += agent.reward_function.current_reward def apply_agent_actions(self) -> None: @@ -443,7 +448,51 @@ class PrimaiteGame: raise ValueError(msg) game.agents[agent_cfg["ref"]] = new_agent + # Validate that if any agents are sharing rewards, they aren't forming an infinite loop. + game.setup_reward_sharing() + # Set the NMNE capture config set_nmne_config(network_config.get("nmne_config", {})) return game + + def setup_reward_sharing(self): + """Do necessary setup to enable reward sharing between agents. + + This method ensures that there are no cycles in the reward sharing. A cycle would be for example if agent_1 + depends on agent_2 and agent_2 depends on agent_1. It would cause an infinite loop. + + Also, SharedReward requires us to pass it a callback method that will provide the reward of the agent who is + sharing their reward. This callback is provided by this setup method. + + Finally, this method sorts the agents in order in which rewards will be evaluated to make sure that any rewards + that rely on the value of another reward are evaluated later. + + :raises RuntimeError: If the reward sharing is specified with a cyclic dependency. + """ + # construct dependency graph in the reward sharing between agents. + graph = {} + for name, agent in self.agents.items(): + graph[name] = set() + for comp, weight in agent.reward_function.reward_components: + if isinstance(comp, SharedReward): + comp: SharedReward + graph[name].add(comp.agent_name) + + # while constructing the graph, we might as well set up the reward sharing itself. + comp.callback = lambda: self.agents[comp.agent_name].reward_function.current_reward + # TODO: make sure this lambda is working like I think it does -> it goes to the agent and fetches + # the most recent value of current_reward, NOT just simply caching the reward value at the time this + # callback method is defined. + + # make sure the graph is acyclic. Otherwise we will enter an infinite loop of reward sharing. + if graph_has_cycle(graph): + raise RuntimeError( + ( + "Detected cycle in agent reward sharing. Check the agent reward function ", + "configuration: reward sharing can only go one way.", + ) + ) + + # sort the agents so the rewards that depend on other rewards are always evaluated later + self._reward_calculation_order = topological_sort(graph) diff --git a/src/primaite/game/science.py b/src/primaite/game/science.py index 19a86237..801ef269 100644 --- a/src/primaite/game/science.py +++ b/src/primaite/game/science.py @@ -1,4 +1,5 @@ from random import random +from typing import Any, Iterable, Mapping def simulate_trial(p_of_success: float) -> bool: @@ -14,3 +15,81 @@ def simulate_trial(p_of_success: float) -> bool: :returns: True if the trial is successful (with probability 'p_of_success'); otherwise, False. """ return random() < p_of_success + + +def graph_has_cycle(graph: Mapping[Any, Iterable[Any]]) -> bool: + """Detect cycles in a directed graph. + + Provide the graph as a dictionary that describes which nodes are linked. For example: + {0: {1,2}, 1:{2,3}, 3:{0}} here there's a cycle 0 -> 1 -> 3 -> 0 + {'a': ('b','c'), c:('b')} here there is no cycle + + :param graph: a mapping from node to a set of nodes to which it is connected. + :type graph: Mapping[Any, Iterable[Any]] + :return: Whether the graph has any cycles + :rtype: bool + """ + visited = set() + currently_visiting = set() + + def depth_first_search(node: Any) -> bool: + """Perform depth-first search (DFS) traversal to detect cycles starting from a given node.""" + if node in currently_visiting: + return True # Cycle detected + if node in visited: + return False # Already visited, no need to explore further + + visited.add(node) + currently_visiting.add(node) + + for neighbour in graph.get(node, []): + if depth_first_search(neighbour): + return True # Cycle detected + + currently_visiting.remove(node) + return False + + # Start DFS traversal from each node + for node in graph: + if depth_first_search(node): + return True # Cycle detected + + return False # No cycles found + + +def topological_sort(graph: Mapping[Any, Iterable[Any]]) -> Iterable[Any]: + """ + Perform topological sorting on a directed graph. + + This guarantees that if there's a directed edge from node A to node B, then A appears before B. + + :param graph: A dictionary representing the directed graph, where keys are node identifiers + and values are lists of outgoing edges from each node. + :type graph: dict[int, list[Any]] + + :return: A topologically sorted list of node identifiers. + :rtype: list[Any] + """ + visited: set[Any] = set() + stack: list[Any] = [] + + def dfs(node: Any) -> None: + """ + Depth-first search traversal to visit nodes and their neighbors. + + :param node: The current node to visit. + :type node: Any + """ + if node in visited: + return + visited.add(node) + for neighbour in graph.get(node, []): + dfs(neighbour) + stack.append(node) + + # Perform DFS traversal from each node + for node in graph: + dfs(node) + + # Reverse the stack and return it. + return stack[::-1] diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index 87289c43..ef77c63d 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -77,16 +77,17 @@ class PrimaiteIO: :type episode: int """ data = {} - longest_history = max([len(hist) for hist in agent_actions]) + longest_history = max([len(hist) for hist in agent_actions.values()]) for i in range(longest_history): - data[i] = {"timestep": i, "episode": episode, **{name: acts[i] for name, acts in agent_actions.items()}} + data[i] = {"timestep": i, "episode": episode} + data[i].update({name: acts[i] for name, acts in agent_actions.items() if len(acts) > i}) path = self.generate_agent_actions_save_path(episode=episode) path.parent.mkdir(exist_ok=True, parents=True) path.touch() _LOGGER.info(f"Saving agent action log to {path}") with open(path, "w") as file: - json.dump(data, fp=file, indent=1) + json.dump(data, fp=file, indent=1, default=lambda x: x.model_dump()) @classmethod def from_config(cls, config: Dict) -> "PrimaiteIO": From 03ee976a2d66d40e35a20940c41f1aae88c5a9e2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 12 Mar 2024 11:00:55 +0000 Subject: [PATCH 705/980] remove extra print statement --- src/primaite/game/agent/rewards.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 86a61535..3d61c0b4 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -353,7 +353,6 @@ class SharedReward(AbstractReward): def calculate(self, state: Dict, last_action_response: "AgentActionHistoryItem") -> float: """Simply access the other agent's reward and return it.""" - print(self.callback(), self.agent_name) return self.callback() @classmethod From 24fdb8dc17f2a7608e7876a58afa054993e30851 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 12 Mar 2024 11:40:26 +0000 Subject: [PATCH 706/980] Fix minor reward sharing bugs --- src/primaite/game/agent/rewards.py | 8 ++--- src/primaite/game/game.py | 5 +-- src/primaite/game/science.py | 3 +- .../Data-Manipulation-E2E-Demonstration.ipynb | 32 +++++++++++-------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 3d61c0b4..a2ffd875 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -230,7 +230,7 @@ class WebpageUnavailablePenalty(AbstractReward): component will keep track of that information. In that case, it doesn't matter whether the last webpage had a 200 status code, because there has been an unsuccessful request since. """ - if last_action_response.request == ["network", "node", self._node, "application", "DatabaseClient", "execute"]: + if last_action_response.request == ["network", "node", self._node, "application", "WebBrowser", "execute"]: self._last_request_failed = last_action_response.response.status != "success" # if agent couldn't even get as far as sending the request (because for example the node was off), then @@ -338,7 +338,7 @@ class SharedReward(AbstractReward): self.agent_name = agent_name """Agent whose reward to track.""" - def default_callback() -> Never: + def default_callback(agent_name: str) -> Never: """ Default callback to prevent calling this reward until it's properly initialised. @@ -348,12 +348,12 @@ class SharedReward(AbstractReward): """ raise RuntimeError("Attempted to calculate SharedReward but it was not initialised properly.") - self.callback: Callable[[], float] = default_callback + self.callback: Callable[[str], float] = default_callback """Method that retrieves an agent's current reward given the agent's name.""" def calculate(self, state: Dict, last_action_response: "AgentActionHistoryItem") -> float: """Simply access the other agent's reward and return it.""" - return self.callback() + return self.callback(self.agent_name) @classmethod def from_config(cls, config: Dict) -> "SharedReward": diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index e766bcd3..ac23610c 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -480,10 +480,7 @@ class PrimaiteGame: graph[name].add(comp.agent_name) # while constructing the graph, we might as well set up the reward sharing itself. - comp.callback = lambda: self.agents[comp.agent_name].reward_function.current_reward - # TODO: make sure this lambda is working like I think it does -> it goes to the agent and fetches - # the most recent value of current_reward, NOT just simply caching the reward value at the time this - # callback method is defined. + comp.callback = lambda agent_name: self.agents[agent_name].reward_function.current_reward # make sure the graph is acyclic. Otherwise we will enter an infinite loop of reward sharing. if graph_has_cycle(graph): diff --git a/src/primaite/game/science.py b/src/primaite/game/science.py index 801ef269..908b326f 100644 --- a/src/primaite/game/science.py +++ b/src/primaite/game/science.py @@ -91,5 +91,4 @@ def topological_sort(graph: Mapping[Any, Iterable[Any]]) -> Iterable[Any]: for node in graph: dfs(node) - # Reverse the stack and return it. - return stack[::-1] + return stack diff --git a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb index b2522c2b..946202b6 100644 --- a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb @@ -450,7 +450,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Now the reward is -1, let's have a look at blue agent's observation." + "Now the reward is -0.8, let's have a look at blue agent's observation." ] }, { @@ -510,9 +510,9 @@ "source": [ "obs, reward, terminated, truncated, info = env.step(13) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", - "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker']['action']}\" )\n", - "print(f\"Green action: {info['agent_actions']['client_1_green_user']['action']}\" )\n", - "print(f\"Green action: {info['agent_actions']['client_2_green_user']['action']}\" )\n", + "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker'].action}\" )\n", + "print(f\"Green action: {info['agent_actions']['client_1_green_user'].action}\" )\n", + "print(f\"Green action: {info['agent_actions']['client_2_green_user'].action}\" )\n", "print(f\"Blue reward:{reward}\" )" ] }, @@ -533,9 +533,9 @@ "metadata": {}, "outputs": [], "source": [ - "obs, reward, terminated, truncated, info = env.step(0) # patch the database\n", + "obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", "print(f\"step: {env.game.step_counter}\")\n", - "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker']['action']}\" )\n", + "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker'].action}\" )\n", "print(f\"Green action: {info['agent_actions']['client_2_green_user']}\" )\n", "print(f\"Green action: {info['agent_actions']['client_1_green_user']}\" )\n", "print(f\"Blue reward:{reward:.2f}\" )" @@ -557,17 +557,19 @@ "outputs": [], "source": [ "env.step(13) # Patch the database\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'].action}, Blue reward:{reward:.2f}\" )\n", "\n", "env.step(50) # Block client 1\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'].action}, Blue reward:{reward:.2f}\" )\n", "\n", "env.step(51) # Block client 2\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'].action}, Blue reward:{reward:.2f}\" )\n", "\n", - "for step in range(30):\n", + "while abs(reward - 0.8) > 1e-5:\n", " obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", - " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )" + " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'].action}, Blue reward:{reward:.2f}\" )\n", + " if env.game.step_counter > 10000:\n", + " break # make sure there's no infinite loop if something went wrong" ] }, { @@ -617,17 +619,19 @@ " if obs['NODES'][6]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", " # client 1 has NMNEs, let's block it\n", " obs, reward, terminated, truncated, info = env.step(50) # block client 1\n", + " print(\"blocking client 1\")\n", " break\n", " elif obs['NODES'][7]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", " # client 2 has NMNEs, so let's block it\n", " obs, reward, terminated, truncated, info = env.step(51) # block client 2\n", + " print(\"blocking client 2\")\n", " break\n", " if tries>100:\n", " print(\"Error: NMNE never increased\")\n", " break\n", "\n", "env.step(13) # Patch the database\n", - "..." + "print()\n" ] }, { @@ -646,14 +650,14 @@ "\n", "for step in range(40):\n", " obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", - " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )" + " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'].action}, Blue reward:{reward:.2f}\" )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Reset the environment, you can rerun the other cells to verify that the attack works the same every episode." + "Reset the environment, you can rerun the other cells to verify that the attack works the same every episode. (except the red agent will move between `client_1` and `client_2`.)" ] }, { From 045f46740702918a711003f2b9859988def28dbd Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 12 Mar 2024 11:51:17 +0000 Subject: [PATCH 707/980] Update marl config --- .../_package_data/data_manipulation_marl.yaml | 58 +++++++++---------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index f7288cb0..be53d2c5 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -75,7 +75,14 @@ agents: reward_function: reward_components: - - type: DUMMY + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.25 + options: + node_hostname: client_2 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.05 + options: + node_hostname: client_2 - ref: client_1_green_user team: GREEN @@ -118,7 +125,14 @@ agents: reward_function: reward_components: - - type: DUMMY + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.25 + options: + node_hostname: client_1 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.05 + options: + node_hostname: client_1 @@ -700,22 +714,14 @@ agents: node_hostname: database_server folder_name: database file_name: database.db - - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.25 + - type: SHARED_REWARD + weight: 1.0 options: - node_hostname: client_1 - - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.25 + agent_name: client_1_green_user + - type: SHARED_REWARD + weight: 1.0 options: - node_hostname: client_2 - - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.05 - options: - node_hostname: client_1 - - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.05 - options: - node_hostname: client_2 + agent_name: client_2_green_user agent_settings: @@ -1259,22 +1265,14 @@ agents: node_hostname: database_server folder_name: database file_name: database.db - - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.25 + - type: SHARED_REWARD + weight: 1.0 options: - node_hostname: client_1 - - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.25 + agent_name: client_1_green_user + - type: SHARED_REWARD + weight: 1.0 options: - node_hostname: client_2 - - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.05 - options: - node_hostname: client_1 - - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.05 - options: - node_hostname: client_2 + agent_name: client_2_green_user agent_settings: From f2c6f10c21f445cf5d85db808ad4092ffa923993 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 12 Mar 2024 12:20:02 +0000 Subject: [PATCH 708/980] #2350: apply PR suggestions --- .../game/agent/observations/nic_observations.py | 10 +++++----- .../game/agent/observations/node_observations.py | 6 +++--- .../simulator/system/applications/database_client.py | 3 +-- .../red_applications/data_manipulation_bot.py | 3 ++- .../game_layer/observations/test_nic_observations.py | 10 +++++----- .../game_layer/observations/test_node_observations.py | 2 +- tests/integration_tests/network/test_capture_nmne.py | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/primaite/game/agent/observations/nic_observations.py b/src/primaite/game/agent/observations/nic_observations.py index 735b41d4..de83e03a 100644 --- a/src/primaite/game/agent/observations/nic_observations.py +++ b/src/primaite/game/agent/observations/nic_observations.py @@ -27,7 +27,7 @@ class NicObservation(AbstractObservation): """The default NIC observation dict.""" data = {"nic_status": 0} if CAPTURE_NMNE: - data.update({"nmne": {"inbound": 0, "outbound": 0}}) + data.update({"NMNE": {"inbound": 0, "outbound": 0}}) return data @@ -133,14 +133,14 @@ class NicObservation(AbstractObservation): else: obs_dict = {"nic_status": 1 if nic_state["enabled"] else 2} if CAPTURE_NMNE: - obs_dict.update({"nmne": {}}) + obs_dict.update({"NMNE": {}}) direction_dict = nic_state["nmne"].get("direction", {}) inbound_keywords = direction_dict.get("inbound", {}).get("keywords", {}) inbound_count = inbound_keywords.get("*", 0) outbound_keywords = direction_dict.get("outbound", {}).get("keywords", {}) outbound_count = outbound_keywords.get("*", 0) - obs_dict["nmne"]["inbound"] = self._categorise_mne_count(inbound_count - self.nmne_inbound_last_step) - obs_dict["nmne"]["outbound"] = self._categorise_mne_count(outbound_count - self.nmne_outbound_last_step) + obs_dict["NMNE"]["inbound"] = self._categorise_mne_count(inbound_count - self.nmne_inbound_last_step) + obs_dict["NMNE"]["outbound"] = self._categorise_mne_count(outbound_count - self.nmne_outbound_last_step) self.nmne_inbound_last_step = inbound_count self.nmne_outbound_last_step = outbound_count return obs_dict @@ -151,7 +151,7 @@ class NicObservation(AbstractObservation): space = spaces.Dict({"nic_status": spaces.Discrete(3)}) if CAPTURE_NMNE: - space["nmne"] = spaces.Dict({"inbound": spaces.Discrete(4), "outbound": spaces.Discrete(4)}) + space["NMNE"] = spaces.Dict({"inbound": spaces.Discrete(4), "outbound": spaces.Discrete(4)}) return space diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index f211a6b5..94f0974b 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -86,7 +86,7 @@ class NodeObservation(AbstractObservation): self.default_observation: Dict = { "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, "FOLDERS": {i + 1: f.default_observation for i, f in enumerate(self.folders)}, - "NETWORK_INTERFACES": {i + 1: n.default_observation for i, n in enumerate(self.network_interfaces)}, + "NICS": {i + 1: n.default_observation for i, n in enumerate(self.network_interfaces)}, "operating_status": 0, } if self.logon_status: @@ -111,7 +111,7 @@ class NodeObservation(AbstractObservation): obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} obs["operating_status"] = node_state["operating_state"] - obs["NETWORK_INTERFACES"] = { + obs["NICS"] = { i + 1: network_interface.observe(state) for i, network_interface in enumerate(self.network_interfaces) } @@ -127,7 +127,7 @@ class NodeObservation(AbstractObservation): "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), "operating_status": spaces.Discrete(5), - "NETWORK_INTERFACES": spaces.Dict( + "NICS": spaces.Dict( {i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)} ), } diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index bc51b3a2..d3afef59 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -48,6 +48,7 @@ class DatabaseClient(Application): def execute(self) -> bool: """Execution definition for db client: perform a select query.""" + self.num_executions += 1 # trying to connect counts as an execution if self.connections: can_connect = self.check_connection(connection_id=list(self.connections.keys())[-1]) else: @@ -82,8 +83,6 @@ class DatabaseClient(Application): if not self._can_perform_action(): return False - self.num_executions += 1 # trying to connect counts as an execution - if not connection_id: connection_id = str(uuid4()) diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index 2a6c2b11..ee276971 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -193,6 +193,8 @@ class DataManipulationBot(Application): if not self._can_perform_action(): _LOGGER.debug("Data manipulation application attempted to execute but it cannot perform actions right now.") self.run() + + self.num_executions += 1 return self._application_loop() def _application_loop(self) -> bool: @@ -202,7 +204,6 @@ class DataManipulationBot(Application): This is the core loop where the bot sequentially goes through the stages of the attack. """ if not self._can_perform_action(): - self.num_executions += 1 return False if self.server_ip_address and self.payload: self.sys_log.info(f"{self.name}: Running") diff --git a/tests/integration_tests/game_layer/observations/test_nic_observations.py b/tests/integration_tests/game_layer/observations/test_nic_observations.py index c210b751..332bc1f7 100644 --- a/tests/integration_tests/game_layer/observations/test_nic_observations.py +++ b/tests/integration_tests/game_layer/observations/test_nic_observations.py @@ -43,14 +43,14 @@ def test_nic(simulation): nic_obs = NicObservation(where=["network", "nodes", pc.hostname, "NICs", 1]) assert nic_obs.space["nic_status"] == spaces.Discrete(3) - assert nic_obs.space["nmne"]["inbound"] == spaces.Discrete(4) - assert nic_obs.space["nmne"]["outbound"] == spaces.Discrete(4) + assert nic_obs.space["NMNE"]["inbound"] == spaces.Discrete(4) + assert nic_obs.space["NMNE"]["outbound"] == spaces.Discrete(4) observation_state = nic_obs.observe(simulation.describe_state()) assert observation_state.get("nic_status") == 1 # enabled - assert observation_state.get("nmne") is not None - assert observation_state["nmne"].get("inbound") == 0 - assert observation_state["nmne"].get("outbound") == 0 + assert observation_state.get("NMNE") is not None + assert observation_state["NMNE"].get("inbound") == 0 + assert observation_state["NMNE"].get("outbound") == 0 nic.disable() observation_state = nic_obs.observe(simulation.describe_state()) diff --git a/tests/integration_tests/game_layer/observations/test_node_observations.py b/tests/integration_tests/game_layer/observations/test_node_observations.py index b1563fbd..dce05b6a 100644 --- a/tests/integration_tests/game_layer/observations/test_node_observations.py +++ b/tests/integration_tests/game_layer/observations/test_node_observations.py @@ -32,7 +32,7 @@ def test_node_observation(simulation): assert observation_state.get("SERVICES") is not None assert observation_state.get("FOLDERS") is not None - assert observation_state.get("NETWORK_INTERFACES") is not None + assert observation_state.get("NICS") is not None # turn off computer pc.power_off() diff --git a/tests/integration_tests/network/test_capture_nmne.py b/tests/integration_tests/network/test_capture_nmne.py index 85fcf102..9efc70f7 100644 --- a/tests/integration_tests/network/test_capture_nmne.py +++ b/tests/integration_tests/network/test_capture_nmne.py @@ -179,8 +179,8 @@ def test_capture_nmne_observations(uc2_network): # Observe the current state of NMNEs from the NICs of both the database and web servers state = sim.describe_state() - db_nic_obs = db_server_nic_obs.observe(state)["nmne"] - web_nic_obs = web_server_nic_obs.observe(state)["nmne"] + db_nic_obs = db_server_nic_obs.observe(state)["NMNE"] + web_nic_obs = web_server_nic_obs.observe(state)["NMNE"] # Define expected NMNE values based on the iteration count if i > 10: From 6dedb910990df2b289f31162b43e678d12cf0d12 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 13 Mar 2024 09:17:29 +0000 Subject: [PATCH 709/980] Remove redundant TODOs --- src/primaite/game/agent/interface.py | 2 -- src/primaite/game/agent/rewards.py | 24 ++++++------------------ 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/primaite/game/agent/interface.py b/src/primaite/game/agent/interface.py index 0531b25f..91fa03d4 100644 --- a/src/primaite/game/agent/interface.py +++ b/src/primaite/game/agent/interface.py @@ -141,8 +141,6 @@ class AbstractAgent(ABC): :param obs: Observation of the environment. :type obs: ObsType - :param reward: Reward from the previous action, defaults to None TODO: should this parameter even be accepted? - :type reward: float, optional :param timestep: The current timestep in the simulation, used for non-RL agents. Optional :type timestep: int :return: Action to be taken in the environment. diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index a2ffd875..d8cb1328 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -43,9 +43,7 @@ class AbstractReward: """Base class for reward function components.""" @abstractmethod - def calculate( - self, state: Dict, last_action_response: "AgentActionHistoryItem" - ) -> float: # todo maybe make last_action_response optional? + def calculate(self, state: Dict, last_action_response: "AgentActionHistoryItem") -> float: """Calculate the reward for the current state.""" return 0.0 @@ -65,9 +63,7 @@ class AbstractReward: class DummyReward(AbstractReward): """Dummy reward function component which always returns 0.""" - def calculate( - self, state: Dict, last_action_response: "AgentActionHistoryItem" - ) -> float: # todo maybe make last_action_response optional? + def calculate(self, state: Dict, last_action_response: "AgentActionHistoryItem") -> float: """Calculate the reward for the current state.""" return 0.0 @@ -107,9 +103,7 @@ class DatabaseFileIntegrity(AbstractReward): file_name, ] - def calculate( - self, state: Dict, last_action_response: "AgentActionHistoryItem" - ) -> float: # todo maybe make last_action_response optional? + def calculate(self, state: Dict, last_action_response: "AgentActionHistoryItem") -> float: """Calculate the reward for the current state. :param state: The current state of the simulation. @@ -164,9 +158,7 @@ class WebServer404Penalty(AbstractReward): """ self.location_in_state = ["network", "nodes", node_hostname, "services", service_name] - def calculate( - self, state: Dict, last_action_response: "AgentActionHistoryItem" - ) -> float: # todo maybe make last_action_response optional? + def calculate(self, state: Dict, last_action_response: "AgentActionHistoryItem") -> float: """Calculate the reward for the current state. :param state: The current state of the simulation. @@ -220,9 +212,7 @@ class WebpageUnavailablePenalty(AbstractReward): self.location_in_state: List[str] = ["network", "nodes", node_hostname, "applications", "WebBrowser"] self._last_request_failed: bool = False - def calculate( - self, state: Dict, last_action_response: "AgentActionHistoryItem" - ) -> float: # todo maybe make last_action_response optional? + def calculate(self, state: Dict, last_action_response: "AgentActionHistoryItem") -> float: """ Calculate the reward based on current simulation state, and the recent agent action. @@ -397,9 +387,7 @@ class RewardFunction: """ self.reward_components.append((component, weight)) - def update( - self, state: Dict, last_action_response: "AgentActionHistoryItem" - ) -> float: # todo maybe make last_action_response optional? + def update(self, state: Dict, last_action_response: "AgentActionHistoryItem") -> float: """Calculate the overall reward for the current state. :param state: The current state of the simulation. From 10ee9b300fe8e6596c25fbad6ebd689ac1bc4aaf Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 13 Mar 2024 12:08:20 +0000 Subject: [PATCH 710/980] Update docs on rewards --- docs/source/game_layer.rst | 72 ++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/docs/source/game_layer.rst b/docs/source/game_layer.rst index 39ab7bde..ba400ac2 100644 --- a/docs/source/game_layer.rst +++ b/docs/source/game_layer.rst @@ -6,19 +6,12 @@ The Primaite codebase consists of two main modules: * ``simulator``: The simulation logic including the network topology, the network state, and behaviour of various hardware and software classes. * ``game``: The agent-training infrastructure which helps reinforcement learning agents interface with the simulation. This includes the observation, action, and rewards, for RL agents, but also scripted deterministic agents. The game layer orchestrates all the interactions between modules. - The simulator and game layer communicate using the PrimAITE State API and the PrimAITE Request API. - -.. - TODO: write up these APIs and link them here. - - -Game layer ----------- +The simulator and game layer communicate using the PrimAITE State API and the PrimAITE Request API. The game layer is responsible for managing agents and getting them to interface with the simulator correctly. It consists of several components: PrimAITE Session -^^^^^^^^^^^^^^^^ +================ .. admonition:: Deprecated :class: deprecated @@ -28,7 +21,7 @@ PrimAITE Session ``PrimaiteSession`` is the main entry point into Primaite and it allows the simultaneous coordination of a simulation and agents that interact with it. ``PrimaiteSession`` keeps track of multiple agents of different types. Agents -^^^^^^ +====== All agents inherit from the :py:class:`primaite.game.agent.interface.AbstractAgent` class, which mandates that they have an ObservationManager, ActionManager, and RewardManager. The agent behaviour depends on the type of agent, but there are two main types: @@ -39,16 +32,67 @@ All agents inherit from the :py:class:`primaite.game.agent.interface.AbstractAge TODO: add seed to stochastic scripted agents Observations -^^^^^^^^^^^^^^^^^^ +============ An agent's observations are managed by the ``ObservationManager`` class. It generates observations based on the current simulation state dictionary. It also provides the observation space during initial setup. The data is formatted so it's compatible with ``Gymnasium.spaces``. Observation spaces are composed of one or more components which are defined by the ``AbstractObservation`` base class. Actions -^^^^^^^ +======= An agent's actions are managed by the ``ActionManager``. It converts actions selected by agents (which are typically integers chosen from a ``gymnasium.spaces.Discrete`` space) into simulation-friendly requests. It also provides the action space during initial setup. Action spaces are composed of one or more components which are defined by the ``AbstractAction`` base class. Rewards -^^^^^^^ +======= -An agent's reward function is managed by the ``RewardManager``. It calculates rewards based on the simulation state (in a way similar to observations). Rewards can be defined as a weighted sum of small reward components. For example, an agents reward can be based on the uptime of a database service plus the loss rate of packets between clients and a web server. The reward components are defined by the AbstractReward base class. +An agent's reward function is managed by the ``RewardManager``. It calculates rewards based on the simulation state (in a way similar to observations). Rewards can be defined as a weighted sum of small reward components. For example, an agents reward can be based on the uptime of a database service plus the loss rate of packets between clients and a web server. + +Reward Components +----------------- + +Currently implemented are reward components tailored to the data manipulation scenario. View the full API and description of how they work here: :py:module:`primaite.game.agent.reward`. + +Reward Sharing +-------------- + +An agent's reward can be based on rewards of other agents. This is particularly useful for modelling a situation where the blue agent's job is to protect the ability of green agents to perform their pattern-of-life. This can be configured in the YAML file this way: + +```yaml +green_agent_1: # this agent sometimes tries to access the webpage, and sometimes the database + # actions, observations, and agent settings go here + reward_function: + reward_components: + + # When the webpage loads, the reward goes up by 0.25 when it fails to load, it goes down to -0.25 + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.25 + options: + node_hostname: client_2 + + # When the database is reachable, the reward goes up by 0.05, when it is unreachable it goes down to -0.05 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.05 + options: + node_hostname: client_2 + +blue_agent: + # actions, observations, and agent settings go here + reward_function: + reward_components: + + # When the database file is in a good state, blue's reward is 0.4, when it's in a corrupted state the reward is -0.4 + - type: DATABASE_FILE_INTEGRITY + weight: 0.40 + options: + node_hostname: database_server + folder_name: database + file_name: database.db + + # The green's reward is added onto the blue's reward. + - type: SHARED_REWARD + weight: 1.0 + options: + agent_name: client_2_green_user + +``` + +When defining agent reward sharing, users must be careful to avoid circular references, as that would lead to an infinite calculation loop. PrimAITE will prevent circular dependencies and provide a helpful error message if they are detected in the yaml. From f438acf745c54137b08b41175b05d91e517d7db4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 13 Mar 2024 14:01:17 +0000 Subject: [PATCH 711/980] Add shared reward test --- tests/assets/configs/shared_rewards.yaml | 956 ++++++++++++++++++ .../game_layer/test_rewards.py | 27 + 2 files changed, 983 insertions(+) create mode 100644 tests/assets/configs/shared_rewards.yaml diff --git a/tests/assets/configs/shared_rewards.yaml b/tests/assets/configs/shared_rewards.yaml new file mode 100644 index 00000000..91ff20e7 --- /dev/null +++ b/tests/assets/configs/shared_rewards.yaml @@ -0,0 +1,956 @@ +training_config: + rl_framework: SB3 + rl_algorithm: PPO + seed: 333 + n_learn_episodes: 1 + n_eval_episodes: 5 + max_steps_per_episode: 128 + deterministic_eval: false + n_agents: 1 + agent_references: + - defender + +io_settings: + save_checkpoints: true + checkpoint_interval: 5 + save_agent_actions: true + save_step_metadata: false + save_pcap_logs: false + save_sys_logs: true + + +game: + max_episode_length: 256 + ports: + - HTTP + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + - UDP + thresholds: + nmne: + high: 10 + medium: 5 + low: 0 + +agents: + - ref: client_2_green_user + team: GREEN + type: ProbabilisticAgent + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_2 + applications: + - application_name: WebBrowser + - application_name: DatabaseClient + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 + + reward_function: + reward_components: + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.25 + options: + node_hostname: client_2 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.05 + options: + node_hostname: client_2 + + - ref: client_1_green_user + team: GREEN + type: ProbabilisticAgent + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_1 + applications: + - application_name: WebBrowser + - application_name: DatabaseClient + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 + + reward_function: + reward_components: + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.25 + options: + node_hostname: client_1 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.05 + options: + node_hostname: client_1 + + + + + + - ref: data_manipulation_attacker + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: + type: UC2RedObservation + options: + nodes: {} + + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_1 + applications: + - application_name: DataManipulationBot + - node_name: client_2 + applications: + - application_name: DataManipulationBot + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 + + - ref: defender + team: BLUE + type: ProxyAgent + + observation_space: + type: UC2BlueObservation + options: + num_services_per_node: 1 + num_folders_per_node: 1 + num_files_per_folder: 1 + num_nics_per_node: 2 + nodes: + - node_hostname: domain_controller + services: + - service_name: DNSServer + - node_hostname: web_server + services: + - service_name: WebServer + - node_hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - node_hostname: backup_server + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 + links: + - link_ref: router_1___switch_1 + - link_ref: router_1___switch_2 + - link_ref: switch_1___domain_controller + - link_ref: switch_1___web_server + - link_ref: switch_1___database_server + - link_ref: switch_1___backup_server + - link_ref: switch_1___security_suite + - link_ref: switch_2___client_1 + - link_ref: switch_2___client_2 + - link_ref: switch_2___security_suite + acl: + options: + max_acl_rules: 10 + router_hostname: router_1 + ip_address_order: + - node_hostname: domain_controller + nic_num: 1 + - node_hostname: web_server + nic_num: 1 + - node_hostname: database_server + nic_num: 1 + - node_hostname: backup_server + nic_num: 1 + - node_hostname: security_suite + nic_num: 1 + - node_hostname: client_1 + nic_num: 1 + - node_hostname: client_2 + nic_num: 1 + - node_hostname: security_suite + nic_num: 2 + ics: null + + action_space: + action_list: + - type: DONOTHING + - type: NODE_SERVICE_SCAN + - type: NODE_SERVICE_STOP + - type: NODE_SERVICE_START + - type: NODE_SERVICE_PAUSE + - type: NODE_SERVICE_RESUME + - type: NODE_SERVICE_RESTART + - type: NODE_SERVICE_DISABLE + - type: NODE_SERVICE_ENABLE + - type: NODE_SERVICE_PATCH + - type: NODE_FILE_SCAN + - type: NODE_FILE_CHECKHASH + - type: NODE_FILE_DELETE + - type: NODE_FILE_REPAIR + - type: NODE_FILE_RESTORE + - type: NODE_FOLDER_SCAN + - type: NODE_FOLDER_CHECKHASH + - type: NODE_FOLDER_REPAIR + - type: NODE_FOLDER_RESTORE + - type: NODE_OS_SCAN + - type: NODE_SHUTDOWN + - type: NODE_STARTUP + - type: NODE_RESET + - type: NETWORK_ACL_ADDRULE + options: + target_router_hostname: router_1 + - type: NETWORK_ACL_REMOVERULE + options: + target_router_hostname: router_1 + - type: NETWORK_NIC_ENABLE + - type: NETWORK_NIC_DISABLE + + action_map: + 0: + action: DONOTHING + options: {} + # scan webapp service + 1: + action: NODE_SERVICE_SCAN + options: + node_id: 1 + service_id: 0 + # stop webapp service + 2: + action: NODE_SERVICE_STOP + options: + node_id: 1 + service_id: 0 + # start webapp service + 3: + action: "NODE_SERVICE_START" + options: + node_id: 1 + service_id: 0 + 4: + action: "NODE_SERVICE_PAUSE" + options: + node_id: 1 + service_id: 0 + 5: + action: "NODE_SERVICE_RESUME" + options: + node_id: 1 + service_id: 0 + 6: + action: "NODE_SERVICE_RESTART" + options: + node_id: 1 + service_id: 0 + 7: + action: "NODE_SERVICE_DISABLE" + options: + node_id: 1 + service_id: 0 + 8: + action: "NODE_SERVICE_ENABLE" + options: + node_id: 1 + service_id: 0 + 9: # check database.db file + action: "NODE_FILE_SCAN" + options: + node_id: 2 + folder_id: 0 + file_id: 0 + 10: + action: "NODE_FILE_CHECKHASH" + options: + node_id: 2 + folder_id: 0 + file_id: 0 + 11: + action: "NODE_FILE_DELETE" + options: + node_id: 2 + folder_id: 0 + file_id: 0 + 12: + action: "NODE_FILE_REPAIR" + options: + node_id: 2 + folder_id: 0 + file_id: 0 + 13: + action: "NODE_SERVICE_PATCH" + options: + node_id: 2 + service_id: 0 + 14: + action: "NODE_FOLDER_SCAN" + options: + node_id: 2 + folder_id: 0 + 15: + action: "NODE_FOLDER_CHECKHASH" + options: + node_id: 2 + folder_id: 0 + 16: + action: "NODE_FOLDER_REPAIR" + options: + node_id: 2 + folder_id: 0 + 17: + action: "NODE_FOLDER_RESTORE" + options: + node_id: 2 + folder_id: 0 + 18: + action: "NODE_OS_SCAN" + options: + node_id: 0 + 19: + action: "NODE_SHUTDOWN" + options: + node_id: 0 + 20: + action: NODE_STARTUP + options: + node_id: 0 + 21: + action: NODE_RESET + options: + node_id: 0 + 22: + action: "NODE_OS_SCAN" + options: + node_id: 1 + 23: + action: "NODE_SHUTDOWN" + options: + node_id: 1 + 24: + action: NODE_STARTUP + options: + node_id: 1 + 25: + action: NODE_RESET + options: + node_id: 1 + 26: # old action num: 18 + action: "NODE_OS_SCAN" + options: + node_id: 2 + 27: + action: "NODE_SHUTDOWN" + options: + node_id: 2 + 28: + action: NODE_STARTUP + options: + node_id: 2 + 29: + action: NODE_RESET + options: + node_id: 2 + 30: + action: "NODE_OS_SCAN" + options: + node_id: 3 + 31: + action: "NODE_SHUTDOWN" + options: + node_id: 3 + 32: + action: NODE_STARTUP + options: + node_id: 3 + 33: + action: NODE_RESET + options: + node_id: 3 + 34: + action: "NODE_OS_SCAN" + options: + node_id: 4 + 35: + action: "NODE_SHUTDOWN" + options: + node_id: 4 + 36: + action: NODE_STARTUP + options: + node_id: 4 + 37: + action: NODE_RESET + options: + node_id: 4 + 38: + action: "NODE_OS_SCAN" + options: + node_id: 5 + 39: # old action num: 19 # shutdown client 1 + action: "NODE_SHUTDOWN" + options: + node_id: 5 + 40: # old action num: 20 + action: NODE_STARTUP + options: + node_id: 5 + 41: # old action num: 21 + action: NODE_RESET + options: + node_id: 5 + 42: + action: "NODE_OS_SCAN" + options: + node_id: 6 + 43: + action: "NODE_SHUTDOWN" + options: + node_id: 6 + 44: + action: NODE_STARTUP + options: + node_id: 6 + 45: + action: NODE_RESET + options: + node_id: 6 + + 46: # old action num: 22 # "ACL: ADDRULE - Block outgoing traffic from client 1" + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 7 # client 1 + dest_ip_id: 1 # ALL + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 + 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" + action: "NETWORK_ACL_ADDRULE" + options: + position: 2 + permission: 2 + source_ip_id: 8 # client 2 + dest_ip_id: 1 # ALL + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 + 48: # old action num: 24 # block tcp traffic from client 1 to web app + action: "NETWORK_ACL_ADDRULE" + options: + position: 3 + permission: 2 + source_ip_id: 7 # client 1 + dest_ip_id: 3 # web server + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 49: # old action num: 25 # block tcp traffic from client 2 to web app + action: "NETWORK_ACL_ADDRULE" + options: + position: 4 + permission: 2 + source_ip_id: 8 # client 2 + dest_ip_id: 3 # web server + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 50: # old action num: 26 + action: "NETWORK_ACL_ADDRULE" + options: + position: 5 + permission: 2 + source_ip_id: 7 # client 1 + dest_ip_id: 4 # database + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 51: # old action num: 27 + action: "NETWORK_ACL_ADDRULE" + options: + position: 6 + permission: 2 + source_ip_id: 8 # client 2 + dest_ip_id: 4 # database + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 52: # old action num: 28 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 0 + 53: # old action num: 29 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 1 + 54: # old action num: 30 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 2 + 55: # old action num: 31 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 3 + 56: # old action num: 32 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 4 + 57: # old action num: 33 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 5 + 58: # old action num: 34 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 6 + 59: # old action num: 35 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 7 + 60: # old action num: 36 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 8 + 61: # old action num: 37 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 9 + 62: # old action num: 38 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 0 + nic_id: 0 + 63: # old action num: 39 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 0 + nic_id: 0 + 64: # old action num: 40 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 1 + nic_id: 0 + 65: # old action num: 41 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 1 + nic_id: 0 + 66: # old action num: 42 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 2 + nic_id: 0 + 67: # old action num: 43 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 2 + nic_id: 0 + 68: # old action num: 44 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 3 + nic_id: 0 + 69: # old action num: 45 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 3 + nic_id: 0 + 70: # old action num: 46 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 4 + nic_id: 0 + 71: # old action num: 47 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 4 + nic_id: 0 + 72: # old action num: 48 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 4 + nic_id: 1 + 73: # old action num: 49 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 4 + nic_id: 1 + 74: # old action num: 50 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 5 + nic_id: 0 + 75: # old action num: 51 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 5 + nic_id: 0 + 76: # old action num: 52 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 6 + nic_id: 0 + 77: # old action num: 53 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 6 + nic_id: 0 + + + + options: + nodes: + - node_name: domain_controller + - node_name: web_server + applications: + - application_name: DatabaseClient + services: + - service_name: WebServer + - node_name: database_server + folders: + - folder_name: database + files: + - file_name: database.db + services: + - service_name: DatabaseService + - node_name: backup_server + - node_name: security_suite + - node_name: client_1 + - node_name: client_2 + + max_folders_per_node: 2 + max_files_per_folder: 2 + max_services_per_node: 2 + max_nics_per_node: 8 + max_acl_rules: 10 + ip_address_order: + - node_name: domain_controller + nic_num: 1 + - node_name: web_server + nic_num: 1 + - node_name: database_server + nic_num: 1 + - node_name: backup_server + nic_num: 1 + - node_name: security_suite + nic_num: 1 + - node_name: client_1 + nic_num: 1 + - node_name: client_2 + nic_num: 1 + - node_name: security_suite + nic_num: 2 + + + reward_function: + reward_components: + - type: SHARED_REWARD + weight: 1.0 + options: + agent_name: client_1_green_user + - type: SHARED_REWARD + weight: 1.0 + options: + agent_name: client_2_green_user + + + + agent_settings: + flatten_obs: true + + + + + +simulation: + network: + nmne_config: + capture_nmne: true + nmne_capture_keywords: + - DELETE + nodes: + + - ref: router_1 + hostname: router_1 + type: router + num_ports: 5 + ports: + 1: + ip_address: 192.168.1.1 + subnet_mask: 255.255.255.0 + 2: + ip_address: 192.168.10.1 + subnet_mask: 255.255.255.0 + acl: + 18: + action: PERMIT + src_port: POSTGRES_SERVER + dst_port: POSTGRES_SERVER + 19: + action: PERMIT + src_port: DNS + dst_port: DNS + 20: + action: PERMIT + src_port: FTP + dst_port: FTP + 21: + action: PERMIT + src_port: HTTP + dst_port: HTTP + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + + - ref: switch_1 + hostname: switch_1 + type: switch + num_ports: 8 + + - ref: switch_2 + hostname: switch_2 + type: switch + num_ports: 8 + + - ref: domain_controller + hostname: domain_controller + type: server + ip_address: 192.168.1.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + services: + - ref: domain_controller_dns_server + type: DNSServer + options: + domain_mapping: + arcd.com: 192.168.1.12 # web server + + - ref: web_server + hostname: web_server + type: server + ip_address: 192.168.1.12 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - ref: web_server_web_service + type: WebServer + applications: + - ref: web_server_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 + + + - ref: database_server + hostname: database_server + type: server + ip_address: 192.168.1.14 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - ref: database_service + type: DatabaseService + options: + backup_server_ip: 192.168.1.16 + - ref: database_ftp_client + type: FTPClient + + - ref: backup_server + hostname: backup_server + type: server + ip_address: 192.168.1.16 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - ref: backup_service + type: FTPServer + + - ref: security_suite + hostname: security_suite + type: server + ip_address: 192.168.1.110 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + network_interfaces: + 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot + ip_address: 192.168.10.110 + subnet_mask: 255.255.255.0 + + - ref: client_1 + hostname: client_1 + type: computer + ip_address: 192.168.10.21 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + applications: + - ref: data_manipulation_bot + type: DataManipulationBot + options: + port_scan_p_of_success: 0.8 + data_manipulation_p_of_success: 0.8 + payload: "DELETE" + server_ip: 192.168.1.14 + - ref: client_1_web_browser + type: WebBrowser + options: + target_url: http://arcd.com/users/ + - ref: client_1_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 + services: + - ref: client_1_dns_client + type: DNSClient + + - ref: client_2 + hostname: client_2 + type: computer + ip_address: 192.168.10.22 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + applications: + - ref: client_2_web_browser + type: WebBrowser + options: + target_url: http://arcd.com/users/ + - ref: data_manipulation_bot + type: DataManipulationBot + options: + port_scan_p_of_success: 0.8 + data_manipulation_p_of_success: 0.8 + payload: "DELETE" + server_ip: 192.168.1.14 + - ref: client_2_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 + services: + - ref: client_2_dns_client + type: DNSClient + + + + links: + - ref: router_1___switch_1 + endpoint_a_ref: router_1 + endpoint_a_port: 1 + endpoint_b_ref: switch_1 + endpoint_b_port: 8 + - ref: router_1___switch_2 + endpoint_a_ref: router_1 + endpoint_a_port: 2 + endpoint_b_ref: switch_2 + endpoint_b_port: 8 + - ref: switch_1___domain_controller + endpoint_a_ref: switch_1 + endpoint_a_port: 1 + endpoint_b_ref: domain_controller + endpoint_b_port: 1 + - ref: switch_1___web_server + endpoint_a_ref: switch_1 + endpoint_a_port: 2 + endpoint_b_ref: web_server + endpoint_b_port: 1 + - ref: switch_1___database_server + endpoint_a_ref: switch_1 + endpoint_a_port: 3 + endpoint_b_ref: database_server + endpoint_b_port: 1 + - ref: switch_1___backup_server + endpoint_a_ref: switch_1 + endpoint_a_port: 4 + endpoint_b_ref: backup_server + endpoint_b_port: 1 + - ref: switch_1___security_suite + endpoint_a_ref: switch_1 + endpoint_a_port: 7 + endpoint_b_ref: security_suite + endpoint_b_port: 1 + - ref: switch_2___client_1 + endpoint_a_ref: switch_2 + endpoint_a_port: 1 + endpoint_b_ref: client_1 + endpoint_b_port: 1 + - ref: switch_2___client_2 + endpoint_a_ref: switch_2 + endpoint_a_port: 2 + endpoint_b_ref: client_2 + endpoint_b_port: 1 + - ref: switch_2___security_suite + endpoint_a_ref: switch_2 + endpoint_a_port: 7 + endpoint_b_ref: security_suite + endpoint_b_port: 2 diff --git a/tests/integration_tests/game_layer/test_rewards.py b/tests/integration_tests/game_layer/test_rewards.py index 8edbf0ac..56ba2b8f 100644 --- a/tests/integration_tests/game_layer/test_rewards.py +++ b/tests/integration_tests/game_layer/test_rewards.py @@ -1,10 +1,15 @@ +import yaml + from primaite.game.agent.rewards import GreenAdminDatabaseUnreachablePenalty, WebpageUnavailablePenalty +from primaite.game.game import PrimaiteGame +from primaite.session.environment import PrimaiteGymEnv from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.services.database.database_service import DatabaseService +from tests import TEST_ASSETS_ROOT from tests.conftest import ControlledAgent @@ -80,3 +85,25 @@ def test_uc2_rewards(game_and_agent): state = game.get_sim_state() reward_value = comp.calculate(state) assert reward_value == -1.0 + + +def test_shared_reward(): + CFG_PATH = TEST_ASSETS_ROOT / "configs/shared_rewards.yaml" + with open(CFG_PATH, "r") as f: + cfg = yaml.safe_load(f) + + env = PrimaiteGymEnv(game_config=cfg) + + env.reset() + + order = env.game._reward_calculation_order + assert order.index("defender") > order.index("client_1_green_user") + assert order.index("defender") > order.index("client_2_green_user") + + for step in range(256): + act = env.action_space.sample() + env.step(act) + g1_reward = env.game.agents["client_1_green_user"].reward_function.current_reward + g2_reward = env.game.agents["client_2_green_user"].reward_function.current_reward + blue_reward = env.game.agents["defender"].reward_function.current_reward + assert blue_reward == g1_reward + g2_reward From c5e142a5005a7dc7df51bb9a0946f68cf6bbdaa4 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 13 Mar 2024 17:43:56 +0000 Subject: [PATCH 712/980] 2299: Remove calls to corrupt. --- src/primaite/simulator/file_system/file.py | 3 --- .../simulator/file_system/file_system_item_abc.py | 2 +- src/primaite/simulator/file_system/folder.py | 10 +++++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index 9331c40c..10819522 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -162,9 +162,6 @@ class File(FileSystemItemABC): if self.previous_hash is None: self.previous_hash = current_hash - # if the previous hash and current hash do not match, mark file as corrupted - if self.previous_hash is not current_hash: - self.corrupt() return True def repair(self) -> bool: diff --git a/src/primaite/simulator/file_system/file_system_item_abc.py b/src/primaite/simulator/file_system/file_system_item_abc.py index 32f5f6be..c89152b4 100644 --- a/src/primaite/simulator/file_system/file_system_item_abc.py +++ b/src/primaite/simulator/file_system/file_system_item_abc.py @@ -156,7 +156,7 @@ class FileSystemItemABC(SimComponent): @abstractmethod def check_hash(self) -> bool: """ - Checks the has of the file to detect any changes. + Checks the hash of the file to detect any changes. For current implementation, any change in file hash means it is compromised. diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 6ebd8d14..192d8627 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -381,17 +381,17 @@ class Folder(FileSystemItemABC): return False # iterate through the files and run a check hash - no_corrupted_files = True + # no_corrupted_files = True for file_id in self.files: file = self.get_file_by_id(file_uuid=file_id) file.check_hash() - if file.health_status == FileSystemItemHealthStatus.CORRUPT: - no_corrupted_files = False + # if file.health_status == FileSystemItemHealthStatus.CORRUPT: + # no_corrupted_files = False # if one file in the folder is corrupted, set the folder status to corrupted - if not no_corrupted_files: - self.corrupt() + # if not no_corrupted_files: + # self.corrupt() self.sys_log.info(f"Checking hash of folder {self.name} (id: {self.uuid})") return True From d33c80d0d61153a7fb599fefa6d209d3b0e602fe Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 14 Mar 2024 14:33:04 +0000 Subject: [PATCH 713/980] Minor fixes --- src/primaite/game/game.py | 9 +++++++-- src/primaite/session/environment.py | 4 ++-- tests/conftest.py | 2 ++ .../game_layer/test_rewards.py | 17 ++++++++++++++--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 84e5e7df..05b76679 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -139,8 +139,12 @@ class PrimaiteGame: """ _LOGGER.debug(f"Stepping. Step counter: {self.step_counter}") + if self.step_counter == 0: + state = self.get_sim_state() + for agent in self.agents.values(): + agent.update_observation(state=state) # Apply all actions to simulation as requests - action_data = self.apply_agent_actions() + self.apply_agent_actions() # Advance timestep self.advance_timestep() @@ -149,7 +153,7 @@ class PrimaiteGame: sim_state = self.get_sim_state() # Update agents' observations and rewards based on the current state, and the response from the last action - self.update_agents(state=sim_state, action_data=action_data) + self.update_agents(state=sim_state) def get_sim_state(self) -> Dict: """Get the current state of the simulation.""" @@ -458,6 +462,7 @@ class PrimaiteGame: # Set the NMNE capture config set_nmne_config(network_config.get("nmne_config", {})) + game.update_agents(game.get_sim_state()) return game diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 64534b04..1795f14b 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -189,8 +189,8 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): def reset(self, *, seed: int = None, options: dict = None) -> Tuple[ObsType, Dict]: """Reset the environment.""" if self.io.settings.save_agent_actions: - self.io.write_agent_actions(episode=self.episode_counter) - self.io.clear_agent_actions() + all_agent_actions = {name: agent.action_history for name, agent in self.game.agents.items()} + self.io.write_agent_actions(agent_actions=all_agent_actions, episode=self.episode_counter) self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=copy.deepcopy(self.game_config)) self.game.setup_for_episode(episode=self.episode_counter) self.episode_counter += 1 diff --git a/tests/conftest.py b/tests/conftest.py index 20600e73..3a9e2655 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -531,4 +531,6 @@ def game_and_agent(): game.agents["test_agent"] = test_agent + game.setup_reward_sharing() + return (game, test_agent) diff --git a/tests/integration_tests/game_layer/test_rewards.py b/tests/integration_tests/game_layer/test_rewards.py index 56ba2b8f..cfd013bc 100644 --- a/tests/integration_tests/game_layer/test_rewards.py +++ b/tests/integration_tests/game_layer/test_rewards.py @@ -1,5 +1,6 @@ import yaml +from primaite.game.agent.interface import AgentActionHistoryItem from primaite.game.agent.rewards import GreenAdminDatabaseUnreachablePenalty, WebpageUnavailablePenalty from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteGymEnv @@ -66,13 +67,18 @@ def test_uc2_rewards(game_and_agent): comp = GreenAdminDatabaseUnreachablePenalty("client_1") - db_client.apply_request( + response = db_client.apply_request( [ "execute", ] ) state = game.get_sim_state() - reward_value = comp.calculate(state) + reward_value = comp.calculate( + state, + last_action_response=AgentActionHistoryItem( + timestep=0, action="NODE_APPLICATION_EXECUTE", parameters={}, request=["execute"], response=response + ), + ) assert reward_value == 1.0 router.acl.remove_rule(position=2) @@ -83,7 +89,12 @@ def test_uc2_rewards(game_and_agent): ] ) state = game.get_sim_state() - reward_value = comp.calculate(state) + reward_value = comp.calculate( + state, + last_action_response=AgentActionHistoryItem( + timestep=0, action="NODE_APPLICATION_EXECUTE", parameters={}, request=["execute"], response=response + ), + ) assert reward_value == -1.0 From 88a3c42f2fe3f2a0d9e06d78cb49c7bc4f0d7885 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 14 Mar 2024 22:15:27 +0000 Subject: [PATCH 714/980] #2369: commiting work done so far --- docs/_static/notebooks/extensions.png | Bin 0 -> 70034 bytes docs/_static/notebooks/install_extensions.png | Bin 0 -> 197959 bytes docs/index.rst | 1 + docs/source/example_notebooks.rst | 79 ++++++++++++++++++ docs/source/getting_started.rst | 6 +- docs/source/primaite_session.rst | 4 +- 6 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 docs/_static/notebooks/extensions.png create mode 100644 docs/_static/notebooks/install_extensions.png create mode 100644 docs/source/example_notebooks.rst diff --git a/docs/_static/notebooks/extensions.png b/docs/_static/notebooks/extensions.png new file mode 100644 index 0000000000000000000000000000000000000000..8441802d34e1a826bec15cceae3decaca24b38e9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ll#0P z4(3H5GFh=u%=2TD_;FR!(b5$5edUSLjS5ClD5N-^3kyk9_mL zIK{KYsW0Jnt<}Zu{013F;vfxHi@o-Ck<2CaDQ{CmE!?^Z7bLO`K?yQx g|GzIY6g{8N&$^dC@ITQSzkpuS;tFC_BKp7o5Ae@Qxc~qF literal 0 HcmV?d00001 diff --git a/docs/_static/notebooks/install_extensions.png b/docs/_static/notebooks/install_extensions.png new file mode 100644 index 0000000000000000000000000000000000000000..db026ce38f37c6c7d164bda34ab6c81f7c98a62e GIT binary patch literal 197959 zcmbrmNv`wCwkCF7$7v*x6G&vszy;Eccfq=7ilRu0VkL?aiyrGjti+lGJOIzaJ-6(J z2jX$qv+xS-ea^er&wye0-~1&i7z{?SVin(7i~pl#$p7g-{^$Sr#~*+Er>i2`fBf+u z#y|e}m;d>{{coV;fBB#OhyMe<{$;df;gA3IfB!H4=O6#_zx{X9#haQfE9>-+zmeyk zv%e8o(T&sJNbzq35%&GxlQPVQuo?f}rV|vw^`=Y8tW1-iIs`^g|B8|Sic=0w{f#`~ zIDF9D-)Wu;e(HyL+Wt1EcSl**;ok^}{yPRu{a3ealWra1)NtSf$Do)L;0!J>&>TA5 z80x==uT$UGshdW(68a(0B>Q)gf#UyqQyg9U8*zs7x_qbbC8zPbL${oZp=+Q-!U^K< z(De72k1z{|@*kQ&V@jtm{~3>I4P+2kSY3%yIy8X8Wv-`*26|I?>r|0!Y7 zWTI~8!=KOjeJmk#D~7{>*8Drb z-=eIme@FLQ(8Iw0sRk-|{JSYdrEZx_#ZO(1V1Gt|%9XUti$9-?Grt3F!apnjj$|xC zAi8~Unp&QYsnh=?uO+PK-zoo@!*SaGBw(1MFNv4UcUc733R4M-p@mUeTisYr zKN}%dp`N_ zeV#gn{8l)5#>2+0r(vXG=8kT$+xrt2pw3pU3+LaTs8EeBMG&v2lQ^PwSn(7m%ST2x z2vzv9{X{b6&=ZWnvx`8MF#p@u>6Gqj70LDbl=(ht?c-YY5tLEas#~?QN~7=Wv9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1YA+#1$?PgFS%FkUrh$Bs`p#J*!^Q+}W z?ccV(aj%cev>PcWlWzuZ-MY0IK7KZrk&!V0Pa&OzlMfTqZ#q3_he|V|zi&v*i*7J8 zei{)LMp}rNdTsp^d!Ey8DaFnjYP!J?1QC>jJ9f+Rp*TMpQRop^t1~~|OM5jipimpV zWSDdHYQo^)V93(cfd5diDqdet&#?kc_W%A>0GYW0i^UGVdDq{ty8kA68S7|6^o@6u zZx-j?-3)!-YQHksEc!Q6D|!iuAE^$dCkhZRf^Dr|)8)w94iwO!it*9W>zD6L;%5$w zJr8}=IxsWBBp39IeOxozs#o}qE*ojKV~0pjPtWFcaBJx z?C2ZLy28dL)`_Z|c<_EJFl*UTPdnZWSBxSq_obmft!;i`pJy6>nr5=nJ187mt~Hn7 zHk3wTPm3R zBZ#s?YHpWVBQxgJJ!K(NO{_ihs~{|o0}Cv*6H&Z>cj+?5IISnJx)}sXdk#FiKoGEAbgkM3G|eI4&NydzV)g?R6z2w;5dZhvpfDe zviRHp(HMG{GmPiAkf<7E7!7FbL?`fW9;sdss}(Ae9QaTOscwfM(F|-%#6AbZFA6cx zzlM-R%2>%2}gh7uh znrnK(04O}MjV~i{)LCv@kHk^zAC*gw@{>#BL)QqdDE` page is completed as a prerequisite. + +Running Jupyter Notebooks +------------------------- + +1. Navigate to the PrimAITE directory + +.. code-block:: bash + :caption: Unix + + cd ~/primaite/PRIMAITE_VERSION_TOKEN + +.. code-block:: powershell + :caption: Windows (Powershell) + + cd ~\primaite\PRIMAITE_VERSION_TOKEN + +2. Run jupyter notebook + +.. code-block:: bash + :caption: Unix + + jupyter notebook + +.. code-block:: powershell + :caption: Windows (Powershell) + + jupyter notebook + +3. Opening the jupyter webpage (optional) + +The default web browser may automatically open the webpage. However, if that is not the case, open a web browser and navigate to |jupyter_index|. + +.. |jupyter_index| raw:: html + + http://localhost:8888/tree + +4. Navigate to the list of notebooks + +The example notebooks are located in notebooks/example_notebooks or by navigating to |jupyter_index_notebooks| + +.. |jupyter_index_notebooks| raw:: html + + http://localhost:8888/tree/notebooks/example_notebooks + +Running Jupyter Notebooks via VSCode +------------------------------------ + +It is also possible to view the Jupyter notebooks within VSCode. + +Installing extensions +""""""""""""""""""""" + +VSCode may need some extensions to be installed if not already done. +To do this, press the "Select Kernel" button on the top right. + +This should open a dialog which has the option to install python and jupyter extensions. + +.. image:: ../../_static/notebooks/install_extensions.png + :width: 700 + :align: center + :alt: :: The top dialog option that appears will automatically install the extensions + +The following extensions should now be installed + +.. image:: ../../_static/notebooks/extensions.png + :width: 300 + :align: center + +VSCode will then ask for a Python environment version to use. PrimAITE is compatible with Python versions 3.8 - 3.10 diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index a800ee56..c1559168 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -38,12 +38,12 @@ Install PrimAITE .. code-block:: bash :caption: Unix - mkdir ~/primaite/3.0.0 + mkdir -p ~/primaite/3.0.0b6 .. code-block:: powershell :caption: Windows (Powershell) - mkdir ~\primaite\3.0.0 + mkdir ~\primaite\3.0.0b6 2. Navigate to the primaite directory and create a new python virtual environment (venv) @@ -51,7 +51,7 @@ Install PrimAITE .. code-block:: bash :caption: Unix - cd ~/primaite/3.0.0 + cd ~/primaite/3.0.0b6 python3 -m venv .venv .. code-block:: powershell diff --git a/docs/source/primaite_session.rst b/docs/source/primaite_session.rst index 87a3f03d..b02e015e 100644 --- a/docs/source/primaite_session.rst +++ b/docs/source/primaite_session.rst @@ -35,7 +35,7 @@ Outputs ------- Running a session creates a session output directory in your user data folder. The filepath looks like this: -``~/primaite/3.0.0/sessions/YYYY-MM-DD/HH-MM-SS/``. This folder contains the simulation sys logs generated by each node, +``~/primaite/3.0.0b6/sessions/YYYY-MM-DD/HH-MM-SS/``. This folder contains the simulation sys logs generated by each node, the saved agent checkpoints, and final model. The folder also contains a .json file for each episode step that contains the action, reward, and simulation state. These can be found in -``~/primaite/3.0.0/sessions/YYYY-MM-DD/HH-MM-SS/simulation_output/episode_/step_metadata/step_.json`` +``~/primaite/3.0.0b6/sessions/YYYY-MM-DD/HH-MM-SS/simulation_output/episode_/step_metadata/step_.json`` From 1d09f0791a0dc4c89a8faafa8f545e348cf641e3 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 14 Mar 2024 23:17:34 +0000 Subject: [PATCH 715/980] #2369: Reduce dependency on manually replacing primaite version across documentation --- docs/conf.py | 19 +++++++++++++++++++ docs/source/example_notebooks.rst | 4 ++-- docs/source/getting_started.rst | 6 +++--- docs/source/primaite_session.rst | 4 ++-- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index d246afe5..a666e460 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,6 +10,7 @@ import datetime # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information import os import sys +from typing import Any import furo # noqa @@ -63,3 +64,21 @@ html_theme = "furo" html_static_path = ["_static"] html_theme_options = {"globaltoc_collapse": True, "globaltoc_maxdepth": 2} html_copy_source = False + + +def replace_token(app: Any, docname: Any, source: Any): + """Replaces a token from the list of tokens.""" + result = source[0] + for key in app.config.tokens: + result = result.replace(key, app.config.tokens[key]) + source[0] = result + + +tokens = {"{VERSION}": release} # Token VERSION is replaced by the value of the PrimAITE version in the version file +"""Dict containing the tokens that need to be replaced in documentation.""" + + +def setup(app: Any): + """Custom setup for sphinx.""" + app.add_config_value("tokens", {}, True) + app.connect("source-read", replace_token) diff --git a/docs/source/example_notebooks.rst b/docs/source/example_notebooks.rst index 9fb5cc9e..1ea94249 100644 --- a/docs/source/example_notebooks.rst +++ b/docs/source/example_notebooks.rst @@ -17,12 +17,12 @@ Running Jupyter Notebooks .. code-block:: bash :caption: Unix - cd ~/primaite/PRIMAITE_VERSION_TOKEN + cd ~/primaite/{VERSION} .. code-block:: powershell :caption: Windows (Powershell) - cd ~\primaite\PRIMAITE_VERSION_TOKEN + cd ~\primaite\{VERSION} 2. Run jupyter notebook diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index c1559168..7a23e4f8 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -38,12 +38,12 @@ Install PrimAITE .. code-block:: bash :caption: Unix - mkdir -p ~/primaite/3.0.0b6 + mkdir -p ~/primaite/{VERSION} .. code-block:: powershell :caption: Windows (Powershell) - mkdir ~\primaite\3.0.0b6 + mkdir ~\primaite\{VERSION} 2. Navigate to the primaite directory and create a new python virtual environment (venv) @@ -51,7 +51,7 @@ Install PrimAITE .. code-block:: bash :caption: Unix - cd ~/primaite/3.0.0b6 + cd ~/primaite/{VERSION} python3 -m venv .venv .. code-block:: powershell diff --git a/docs/source/primaite_session.rst b/docs/source/primaite_session.rst index b02e015e..d0caeaad 100644 --- a/docs/source/primaite_session.rst +++ b/docs/source/primaite_session.rst @@ -35,7 +35,7 @@ Outputs ------- Running a session creates a session output directory in your user data folder. The filepath looks like this: -``~/primaite/3.0.0b6/sessions/YYYY-MM-DD/HH-MM-SS/``. This folder contains the simulation sys logs generated by each node, +``~/primaite/{VERSION}/sessions/YYYY-MM-DD/HH-MM-SS/``. This folder contains the simulation sys logs generated by each node, the saved agent checkpoints, and final model. The folder also contains a .json file for each episode step that contains the action, reward, and simulation state. These can be found in -``~/primaite/3.0.0b6/sessions/YYYY-MM-DD/HH-MM-SS/simulation_output/episode_/step_metadata/step_.json`` +``~/primaite/{VERSION}/sessions/YYYY-MM-DD/HH-MM-SS/simulation_output/episode_/step_metadata/step_.json`` From a9bf0981e6624569eb75f2ef0c54451c18ccd27f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 09:22:55 +0000 Subject: [PATCH 716/980] Doc fixes --- docs/source/game_layer.rst | 4 +--- src/primaite/game/agent/rewards.py | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/source/game_layer.rst b/docs/source/game_layer.rst index ba400ac2..af3eadc6 100644 --- a/docs/source/game_layer.rst +++ b/docs/source/game_layer.rst @@ -26,10 +26,8 @@ Agents All agents inherit from the :py:class:`primaite.game.agent.interface.AbstractAgent` class, which mandates that they have an ObservationManager, ActionManager, and RewardManager. The agent behaviour depends on the type of agent, but there are two main types: * RL agents action during each step is decided by an appropriate RL algorithm. The agent within PrimAITE just acts to format and forward actions decided by an RL policy. -* Deterministic agents perform all of their decision making within the PrimAITE game layer. They typically have a scripted policy which always performs the same action or a rule-based policy which performs actions based on the current state of the simulation. They can have a stochastic element, and their seed will be settable. +* Deterministic agents perform all of their decision making within the PrimAITE game layer. They typically have a scripted policy which always performs the same action or a rule-based policy which performs actions based on the current state of the simulation. They can have a stochastic element, and their seed is settable. -.. - TODO: add seed to stochastic scripted agents Observations ============ diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index d8cb1328..52bed9e2 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -319,11 +319,11 @@ class SharedReward(AbstractReward): """ Initialise the shared reward. - The agent_ref is a placeholder value. It starts off as none, but it must be set before this reward can work + The agent_name is a placeholder value. It starts off as none, but it must be set before this reward can work correctly. :param agent_name: The name whose reward is an input - :type agent_ref: Optional[str] + :type agent_name: Optional[str] """ self.agent_name = agent_name """Agent whose reward to track.""" From 90224960e53dedde0d8da55a1b6f4d2bbd577017 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 15 Mar 2024 10:33:58 +0000 Subject: [PATCH 717/980] 2299: Backup Jupyter notebook changes. --- .../Data-Manipulation-E2E-Demonstration.ipynb | 271 ++++++++++++++---- 1 file changed, 221 insertions(+), 50 deletions(-) diff --git a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb index 1d7cb157..d4617d61 100644 --- a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb @@ -352,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "tags": [] }, @@ -364,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "tags": [] }, @@ -389,9 +389,162 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-03-13 16:52:48,201: Resetting environment, episode 0, avg. reward: 0.0\n", + "2024-03-13 16:52:48,205: Saving agent action log to C:\\Users\\NickTodd\\primaite\\3.0.0b6\\sessions\\2024-03-13\\16-52-48\\agent_actions\\episode_0.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "env created successfully\n", + "{'ACL': {1: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 0,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 2: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 1,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 3: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 2,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 4: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 3,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 5: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 4,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 6: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 5,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 7: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 6,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 8: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 7,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 9: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 8,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 10: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 9,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0}},\n", + " 'ICS': 0,\n", + " 'LINKS': {1: {'PROTOCOLS': {'ALL': 1}},\n", + " 2: {'PROTOCOLS': {'ALL': 1}},\n", + " 3: {'PROTOCOLS': {'ALL': 1}},\n", + " 4: {'PROTOCOLS': {'ALL': 1}},\n", + " 5: {'PROTOCOLS': {'ALL': 1}},\n", + " 6: {'PROTOCOLS': {'ALL': 1}},\n", + " 7: {'PROTOCOLS': {'ALL': 1}},\n", + " 8: {'PROTOCOLS': {'ALL': 1}},\n", + " 9: {'PROTOCOLS': {'ALL': 1}},\n", + " 10: {'PROTOCOLS': {'ALL': 0}}},\n", + " 'NODES': {1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}},\n", + " 'health_status': 1}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}}\n" + ] + } + ], "source": [ "# create the env\n", "with open(data_manipulation_config_path(), 'r') as f:\n", @@ -410,6 +563,46 @@ "pprint(obs)" ] }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "res = FileSystemItemHealthStatus.GOOD\n", + "res = FileSystemItemHealthStatus.GOOD\n", + "res = FileSystemItemHealthStatus.COMPROMISED\n", + "res = FileSystemItemHealthStatus.COMPROMISED\n" + ] + } + ], + "source": [ + "# Test NODE_FOLDER_CHECKHASH\n", + "res = env.game.simulation.network.get_node_by_hostname('database_server').file_system.get_folder(folder_name = 'database').health_status\n", + "print(f'Folder status = {res}')\n", + "obs, reward, terminated, truncated, info = env.step(15)\n", + "obs, reward, terminated, truncated, info = env.step(14) # scan database folder\n", + "\n", + "res = env.game.simulation.network.get_node_by_hostname('database_server').file_system.get_folder(folder_name = 'database').health_status\n", + "print(f'Folder status = {res}')\n", + "\n", + "\n", + "\n", + "# Test NODE_FILE_CHECKHASH\n", + "res = env.game.simulation.network.get_node_by_hostname('database_server').file_system.get_file(folder_name = 'database', file_name = 'database.db').health_status\n", + "print(f'File status = {res}')\n", + "obs, reward, terminated, truncated, info = env.step(10)\n", + "obs, reward, terminated, truncated, info = env.step(9) # scan database file\n", + "\n", + "res = env.game.simulation.network.get_node_by_hostname('database_server').file_system.get_file(folder_name = 'database', file_name = 'database.db').health_status\n", + "print(f'File status = {res}')\n", + "\n", + "# pprint(obs['NODES'])\n" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -426,13 +619,13 @@ "def friendly_output_red_action(info):\n", " # parse the info dict form step output and write out what the red agent is doing\n", " red_info = info['agent_actions']['data_manipulation_attacker']\n", - " red_action = red_info['action']\n", + " red_action = red_info[0]\n", " if red_action == 'DONOTHING':\n", " red_str = 'DO NOTHING'\n", " elif red_action == 'NODE_APPLICATION_EXECUTE':\n", - " client = \"client 1\" if red_info['parameters']['node_id'] == 0 else \"client 2\"\n", + " client = \"client 1\" if red_info[1]['node_id'] == 0 else \"client 2\"\n", " red_str = f\"ATTACK from {client}\"\n", - " return red_str\n" + " return red_str" ] }, { @@ -477,7 +670,8 @@ "source": [ "obs, reward, terminated, truncated, info = env.step(9) # scan database file\n", "obs, reward, terminated, truncated, info = env.step(1) # scan webapp service\n", - "pprint(obs['NODES'])" + "\n", + "pprint(obs['NODES'])\n" ] }, { @@ -492,7 +686,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Also, the NMNE outbound of either client 1 (node 6) or client 2 (node 7) increased from 0 to 1, but only right after the red attack, so we probably cannot see it now." + "Also, the NMNE outbound of either client 1 (node 6) or client 2 (node 7) has increased from 0 to 1. This tells us which client is being used by the red agent." ] }, { @@ -510,9 +704,9 @@ "source": [ "obs, reward, terminated, truncated, info = env.step(13) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", - "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker']['action']}\" )\n", - "print(f\"Green action: {info['agent_actions']['client_1_green_user']['action']}\" )\n", - "print(f\"Green action: {info['agent_actions']['client_2_green_user']['action']}\" )\n", + "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker'][0]}\" )\n", + "print(f\"Green action: {info['agent_actions']['client_1_green_user'][0]}\" )\n", + "print(f\"Green action: {info['agent_actions']['client_2_green_user'][0]}\" )\n", "print(f\"Blue reward:{reward}\" )" ] }, @@ -535,7 +729,7 @@ "source": [ "obs, reward, terminated, truncated, info = env.step(0) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", - "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker']['action']}\" )\n", + "print(f\"Red action: {info['agent_actions']['data_manipulation_attacker'][0]}\" )\n", "print(f\"Green action: {info['agent_actions']['client_2_green_user']}\" )\n", "print(f\"Green action: {info['agent_actions']['client_1_green_user']}\" )\n", "print(f\"Blue reward:{reward:.2f}\" )" @@ -557,17 +751,17 @@ "outputs": [], "source": [ "env.step(13) # Patch the database\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )\n", "\n", "env.step(50) # Block client 1\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )\n", "\n", "env.step(51) # Block client 2\n", - "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )\n", + "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )\n", "\n", "for step in range(30):\n", " obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", - " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )" + " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )" ] }, { @@ -606,35 +800,20 @@ "metadata": {}, "outputs": [], "source": [ - "env.step(58) # Remove the ACL rule that blocks client 1\n", - "env.step(57) # Remove the ACL rule that blocks client 2\n", - "\n", - "tries = 0\n", - "while True:\n", - " tries += 1\n", - " obs, reward, terminated, truncated, info = env.step(0)\n", - "\n", - " if obs['NODES'][6]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", - " # client 1 has NMNEs, let's block it\n", - " obs, reward, terminated, truncated, info = env.step(50) # block client 1\n", - " break\n", - " elif obs['NODES'][7]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", - " # client 2 has NMNEs, so let's block it\n", - " obs, reward, terminated, truncated, info = env.step(51) # block client 2\n", - " break\n", - " if tries>100:\n", - " print(\"Error: NMNE never increased\")\n", - " break\n", - "\n", - "env.step(13) # Patch the database\n", - "..." + "if obs['NODES'][6]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", + " # client 1 has NMNEs, let's unblock client 2\n", + " env.step(58) # remove ACL rule 6\n", + "elif obs['NODES'][7]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", + " env.step(57) # remove ACL rule 5\n", + "else:\n", + " print(\"something went wrong, neither client has NMNEs\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Now, the reward will eventually increase to 0.9, even after red agent attempts subsequent attacks." + "Now, the reward will eventually increase to 1.0, even after red agent attempts subsequent attacks." ] }, { @@ -643,10 +822,9 @@ "metadata": {}, "outputs": [], "source": [ - "\n", - "for step in range(40):\n", + "for step in range(30):\n", " obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", - " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker']['action']}, Blue reward:{reward:.2f}\" )" + " print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'][0]}, Blue reward:{reward:.2f}\" )" ] }, { @@ -664,13 +842,6 @@ "source": [ "env.reset()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From 04c86e30c9f488664ac880060460fe930e29fde2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 11:15:02 +0000 Subject: [PATCH 718/980] Fix some stuff --- .../config/_package_data/data_manipulation.yaml | 10 ++++------ .../_package_data/data_manipulation_marl.yaml | 12 ++++++------ src/primaite/session/io.py | 2 +- src/primaite/simulator/network/hardware/base.py | 2 +- .../simulator/system/core/packet_capture.py | 15 +++++++++------ 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index 748b0d77..c561030a 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -11,16 +11,14 @@ training_config: - defender io_settings: - save_checkpoints: true - checkpoint_interval: 5 save_agent_actions: true save_step_metadata: false save_pcap_logs: false - save_sys_logs: true + save_sys_logs: false game: - max_episode_length: 256 + max_episode_length: 128 ports: - HTTP - POSTGRES_SERVER @@ -323,7 +321,7 @@ agents: folder_id: 0 file_id: 0 10: - action: "NODE_FILE_CHECKHASH" + action: "NODE_FILE_SCAN" # CHECKHASH replaced by SCAN - but the behaviour is the same in this context. options: node_id: 2 folder_id: 0 @@ -351,7 +349,7 @@ agents: node_id: 2 folder_id: 0 15: - action: "NODE_FOLDER_CHECKHASH" + action: "NODE_FOLDER_SCAN" # CHECKHASH replaced by SCAN - but the behaviour is the same in this context. options: node_id: 2 folder_id: 0 diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index be53d2c5..e4c93161 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -4,7 +4,7 @@ training_config: seed: 333 n_learn_episodes: 1 n_eval_episodes: 5 - max_steps_per_episode: 256 + max_steps_per_episode: 128 deterministic_eval: false n_agents: 2 agent_references: @@ -22,7 +22,7 @@ io_settings: game: - max_episode_length: 256 + max_episode_length: 128 ports: - ARP - DNS @@ -325,7 +325,7 @@ agents: folder_id: 0 file_id: 0 10: - action: "NODE_FILE_CHECKHASH" + action: "NODE_FILE_SCAN" # CHECKHASH replaced by SCAN - but the behaviour is the same in this context. options: node_id: 2 folder_id: 0 @@ -353,7 +353,7 @@ agents: node_id: 2 folder_id: 0 15: - action: "NODE_FOLDER_CHECKHASH" + action: "NODE_FOLDER_SCAN" # CHECKHASH replaced by SCAN - but the behaviour is the same in this context. options: node_id: 2 folder_id: 0 @@ -876,7 +876,7 @@ agents: folder_id: 0 file_id: 0 10: - action: "NODE_FILE_CHECKHASH" + action: "NODE_FILE_SCAN" # CHECKHASH replaced by SCAN - but the behaviour is the same in this context. options: node_id: 2 folder_id: 0 @@ -904,7 +904,7 @@ agents: node_id: 2 folder_id: 0 15: - action: "NODE_FOLDER_CHECKHASH" + action: "NODE_FOLDER_SCAN" # CHECKHASH replaced by SCAN - but the behaviour is the same in this context. options: node_id: 2 folder_id: 0 diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index ef77c63d..e57f88ae 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -92,5 +92,5 @@ class PrimaiteIO: @classmethod def from_config(cls, config: Dict) -> "PrimaiteIO": """Create an instance of PrimaiteIO based on a configuration dict.""" - new = cls() + new = cls(settings=cls.Settings(**config)) return new diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index a91a709c..3d8640a6 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -108,7 +108,7 @@ class NetworkInterface(SimComponent, ABC): """Reset the original state of the SimComponent.""" super().setup_for_episode(episode=episode) self.nmne = {} - if episode and self.pcap: + if episode and self.pcap and SIM_OUTPUT.save_pcap_logs: self.pcap.current_episode = episode self.pcap.setup_logger() self.enable() diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index 4916966d..cf38e94b 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -49,8 +49,9 @@ class PacketCapture: self.current_episode: int = 1 - self.setup_logger(outbound=False) - self.setup_logger(outbound=True) + if SIM_OUTPUT.save_pcap_logs: + self.setup_logger(outbound=False) + self.setup_logger(outbound=True) def setup_logger(self, outbound: bool = False): """Set up the logger configuration.""" @@ -108,8 +109,9 @@ class PacketCapture: :param frame: The PCAP frame to capture. """ - msg = frame.model_dump_json() - self.inbound_logger.log(level=60, msg=msg) # Log at custom log level > CRITICAL + if SIM_OUTPUT.save_pcap_logs: + msg = frame.model_dump_json() + self.inbound_logger.log(level=60, msg=msg) # Log at custom log level > CRITICAL def capture_outbound(self, frame): # noqa - I'll have a circular import and cant use if TYPE_CHECKING ;( """ @@ -117,5 +119,6 @@ class PacketCapture: :param frame: The PCAP frame to capture. """ - msg = frame.model_dump_json() - self.outbound_logger.log(level=60, msg=msg) # Log at custom log level > CRITICAL + if SIM_OUTPUT.save_pcap_logs: + msg = frame.model_dump_json() + self.outbound_logger.log(level=60, msg=msg) # Log at custom log level > CRITICAL From e0eef8e56edba45a3b17df895a52a58d41b673e5 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 12:19:56 +0000 Subject: [PATCH 719/980] Fix tests --- tests/assets/configs/shared_rewards.yaml | 6 ++---- tests/assets/configs/test_primaite_session.yaml | 7 +++++-- tests/e2e_integration_tests/test_primaite_session.py | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/assets/configs/shared_rewards.yaml b/tests/assets/configs/shared_rewards.yaml index 91ff20e7..daffa585 100644 --- a/tests/assets/configs/shared_rewards.yaml +++ b/tests/assets/configs/shared_rewards.yaml @@ -11,12 +11,10 @@ training_config: - defender io_settings: - save_checkpoints: true - checkpoint_interval: 5 - save_agent_actions: true + save_agent_actions: false save_step_metadata: false save_pcap_logs: false - save_sys_logs: true + save_sys_logs: false game: diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 199cf8cc..121cc7f1 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -11,8 +11,11 @@ training_config: - defender io_settings: - save_checkpoints: true - checkpoint_interval: 5 + save_agent_actions: true + save_step_metadata: true + save_pcap_logs: true + save_sys_logs: true + game: diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index da13dcd8..c45a4690 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -31,6 +31,7 @@ class TestPrimaiteSession: assert session.env.game.simulation.network assert len(session.env.game.simulation.network.nodes) == 10 + @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) def test_start_session(self, temp_primaite_session): """Make sure you can go all the way through the session without errors.""" From 1ed2f48f54cb8feb1477b7426c6dc1a3731d6a53 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 15 Mar 2024 13:13:54 +0000 Subject: [PATCH 720/980] #2369: missed items --- docs/source/example_notebooks.rst | 6 +++++- docs/source/getting_started.rst | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/source/example_notebooks.rst b/docs/source/example_notebooks.rst index 1ea94249..e0c4169f 100644 --- a/docs/source/example_notebooks.rst +++ b/docs/source/example_notebooks.rst @@ -5,7 +5,7 @@ Example Jupyter Notebooks ========================= -There are a few example notebooks included which helps with the understanding of PrimAITE's capabilities. +There are a few example notebooks included which help with the understanding of PrimAITE's capabilities. The Jupyter Notebooks can be run via the 2 examples below. These assume that the instructions to install PrimAITE from the :ref:`Getting Started ` page is completed as a prerequisite. @@ -57,6 +57,8 @@ Running Jupyter Notebooks via VSCode It is also possible to view the Jupyter notebooks within VSCode. +The best place to start is by opening a notebook file (.ipynb) in VSCode. If using VSCode to view a notebook for the first time, follow the steps below. + Installing extensions """"""""""""""""""""" @@ -77,3 +79,5 @@ The following extensions should now be installed :align: center VSCode will then ask for a Python environment version to use. PrimAITE is compatible with Python versions 3.8 - 3.10 + +You should now be able to interact with the notebook. diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 7a23e4f8..91db4693 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -57,7 +57,7 @@ Install PrimAITE .. code-block:: powershell :caption: Windows (Powershell) - cd ~\primaite\3.0.0 + cd ~\primaite\{VERSION} python3 -m venv .venv attrib +h .venv /s /d # Hides the .venv directory From 2fde07178930d3dd9b8cb2d5c01d03beea7ac8a2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 13:25:50 +0000 Subject: [PATCH 721/980] Update docs on example notebooks --- docs/source/example_notebooks.rst | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/docs/source/example_notebooks.rst b/docs/source/example_notebooks.rst index 1ea94249..3bf14bcb 100644 --- a/docs/source/example_notebooks.rst +++ b/docs/source/example_notebooks.rst @@ -5,7 +5,7 @@ Example Jupyter Notebooks ========================= -There are a few example notebooks included which helps with the understanding of PrimAITE's capabilities. +There are a few example notebooks included which help with the understanding of PrimAITE's capabilities. The Jupyter Notebooks can be run via the 2 examples below. These assume that the instructions to install PrimAITE from the :ref:`Getting Started ` page is completed as a prerequisite. @@ -24,7 +24,7 @@ Running Jupyter Notebooks cd ~\primaite\{VERSION} -2. Run jupyter notebook +2. Run jupyter notebook (the python environment to which you installed PrimAITE must be active) .. code-block:: bash :caption: Unix @@ -38,19 +38,13 @@ Running Jupyter Notebooks 3. Opening the jupyter webpage (optional) -The default web browser may automatically open the webpage. However, if that is not the case, open a web browser and navigate to |jupyter_index|. +The default web browser may automatically open the webpage. However, if that is not the case, click the link shown in your command prompt output. It should look like this: ``http://localhost:8888/?token=ab83071fd13cb5a1384efba318...`` -.. |jupyter_index| raw:: html - - http://localhost:8888/tree 4. Navigate to the list of notebooks -The example notebooks are located in notebooks/example_notebooks or by navigating to |jupyter_index_notebooks| +The example notebooks are located in ``notebooks/example_notebooks/``. The file system shown in the jupyter webpage is relative to the location in which the ``jupyter notebook`` command was used. -.. |jupyter_index_notebooks| raw:: html - - http://localhost:8888/tree/notebooks/example_notebooks Running Jupyter Notebooks via VSCode ------------------------------------ From d9b65065728d41548851a5ed011240a4e5148610 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 13:42:59 +0000 Subject: [PATCH 722/980] Mention python version in getting started guide. --- docs/source/getting_started.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 91db4693..bb6e0019 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -11,7 +11,7 @@ Getting Started Pre-Requisites -In order to get **PrimAITE** installed, you will need to have a python version between 3.8 and 3.11 installed. If you don't already have it, this is how to install it: +In order to get **PrimAITE** installed, you will need Python, venv, and pip. If you don't already have them, this is how to install it: .. code-block:: bash @@ -30,6 +30,8 @@ In order to get **PrimAITE** installed, you will need to have a python version b **PrimAITE** is designed to be OS-agnostic, and thus should work on most variations/distros of Linux, Windows, and MacOS. +Installing PrimAITE has been tested with all supported python versions, venv 20.24.1, and pip 23. + Install PrimAITE **************** From 6f780f20d7316c91a845ead049530fd8977f00b1 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 15 Mar 2024 13:55:00 +0000 Subject: [PATCH 723/980] 2384: Updates for 3.0.0b7 release. --- CHANGELOG.md | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae40a36f..c01f0139 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,27 +12,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Changed the red agent in the data manipulation scenario to randomly choose client 1 or client 2 to start its attack. - Changed the data manipulation scenario to include a second green agent on client 1. - Refactored actions and observations to be configurable via object name, instead of UUID. -- Fixed a bug where ACL rules were not resetting on episode reset. -- Fixed a bug where blue agent's ACL actions were being applied against the wrong IP addresses -- Fixed a bug where deleted files and folders did not reset correctly on episode reset. -- Fixed a bug where service health status was using the actual health state instead of the visible health state -- Fixed a bug where the database file health status was using the incorrect value for negative rewards -- Fixed a bug preventing file actions from reaching their intended file - Made database patch correctly take 2 timesteps instead of being immediate - Made database patch only possible when the software is compromised or good, it's no longer possible when the software is OFF or RESETTING -- Temporarily disable the blue agent file delete action due to crashes. This issue is resolved in another branch that will be merged into dev soon. -- Fix a bug where ACLs were not showing up correctly in the observation space. - Added a notebook which explains Data manipulation scenario, demonstrates the attack, and shows off blue agent's action space, observation space, and reward function. - Made packet capture and system logging optional (off by default). To turn on, change the io_settings.save_pcap_logs and io_settings.save_sys_logs settings in the config. -- Made observation space flattening optional (on by default). To turn off for an agent, change the agent_settings.flatten_obs setting in the config. -- Fixed an issue where the data manipulation attack was triggered at episode start. -- Fixed a bug where FTP STOR stored an additional copy on the client machine's filesystem -- Fixed a bug where the red agent acted to early -- Fixed the order of service health state -- Fixed an issue where starting a node didn't start the services on it +- Made observation space flattening optional (on by default). To turn off for an agent, change the `agent_settings.flatten_obs` setting in the config. - Added support for SQL INSERT command. - Added ability to log each agent's action choices in each step to a JSON file. +### Bug Fixes + +- ACL rules were not resetting on episode reset. +- ACLs were not showing up correctly in the observation space. +- Blue agent's ACL actions were being applied against the wrong IP addresses +- Deleted files and folders did not reset correctly on episode reset. +- Service health status was using the actual health state instead of the visible health state +- Database file health status was using the incorrect value for negative rewards +- Preventing file actions from reaching their intended file +- The data manipulation attack was triggered at episode start. +- FTP STOR stored an additional copy on the client machine's filesystem +- The red agent acted to early +- Order of service health state +- Starting a node didn't start the services on it +- Fixed an issue where the services were still able to run even though the node the service is installed on is turned off + ### Added @@ -51,8 +54,12 @@ a Service/Application another machine. SessionManager. - Permission System - each action can define criteria that will be used to permit or deny agent actions. - File System - ability to emulate a node's file system during a simulation -- Example notebooks - There is currently 1 jupyter notebook which walks through using PrimAITE - 1. Creating a simulation - this notebook explains how to build up a simulation using the Python package. (WIP) +- Example notebooks - There are 5 jupyter notebook which walk through using PrimAITE + 1. Training a Stable Baselines 3 agent + 2. Training a single agent system using Ray RLLib + 3. Training a multi-agent system Ray RLLib + 4. Data manipulation end to end demonstration + 5. Data manipulation scenario with customised red agents - Database: - `DatabaseClient` and `DatabaseService` created to allow emulation of database actions - Ability for `DatabaseService` to backup its data to another server via FTP and restore data from backup @@ -62,7 +69,6 @@ SessionManager. - DNS Services: `DNSClient` and `DNSServer` - FTP Services: `FTPClient` and `FTPServer` - HTTP Services: `WebBrowser` to simulate a web client and `WebServer` -- Fixed an issue where the services were still able to run even though the node the service is installed on is turned off - NTP Services: `NTPClient` and `NTPServer` - **RouterNIC Class**: Introduced a new class `RouterNIC`, extending the standard `NIC` functionality. This class is specifically designed for router operations, optimizing the processing and routing of network traffic. - **Custom Layer-3 Processing**: The `RouterNIC` class includes custom handling for network frames, bypassing standard Node NIC's Layer 3 broadcast/unicast checks. This allows for more efficient routing behavior in network scenarios where router-specific frame processing is required. From 33dd6e4dcd742a4cde0d2a9ec2319861850a7aa8 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 14:03:37 +0000 Subject: [PATCH 724/980] Make sure notebook is using correct dict key --- .../Data-Manipulation-E2E-Demonstration.ipynb | 501 +++++++++++++++++- 1 file changed, 475 insertions(+), 26 deletions(-) diff --git a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb index 946202b6..93e1f27f 100644 --- a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb @@ -352,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "tags": [] }, @@ -364,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "tags": [] }, @@ -389,9 +389,154 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "env created successfully\n", + "{'ACL': {1: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 0,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 2: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 1,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 3: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 2,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 4: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 3,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 5: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 4,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 6: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 5,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 7: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 6,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 8: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 7,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 9: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 8,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0},\n", + " 10: {'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'permission': 0,\n", + " 'position': 9,\n", + " 'protocol': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0}},\n", + " 'ICS': 0,\n", + " 'LINKS': {1: {'PROTOCOLS': {'ALL': 1}},\n", + " 2: {'PROTOCOLS': {'ALL': 1}},\n", + " 3: {'PROTOCOLS': {'ALL': 1}},\n", + " 4: {'PROTOCOLS': {'ALL': 1}},\n", + " 5: {'PROTOCOLS': {'ALL': 1}},\n", + " 6: {'PROTOCOLS': {'ALL': 1}},\n", + " 7: {'PROTOCOLS': {'ALL': 1}},\n", + " 8: {'PROTOCOLS': {'ALL': 1}},\n", + " 9: {'PROTOCOLS': {'ALL': 1}},\n", + " 10: {'PROTOCOLS': {'ALL': 0}}},\n", + " 'NODES': {1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}},\n", + " 'health_status': 1}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", + " 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", + " 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}}\n" + ] + } + ], "source": [ "# create the env\n", "with open(data_manipulation_config_path(), 'r') as f:\n", @@ -419,7 +564,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -437,9 +582,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 1, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 2, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 3, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 4, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 5, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 6, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 7, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 8, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 9, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 10, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 11, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 12, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 13, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 14, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 15, Red action: DO NOTHING, Blue reward:0.90\n", + "step: 16, Red action: DO NOTHING, Blue reward:0.95\n", + "step: 17, Red action: DO NOTHING, Blue reward:0.95\n", + "step: 18, Red action: DO NOTHING, Blue reward:0.95\n", + "step: 19, Red action: DO NOTHING, Blue reward:0.95\n", + "step: 20, Red action: DO NOTHING, Blue reward:1.00\n", + "step: 21, Red action: DO NOTHING, Blue reward:1.00\n", + "step: 22, Red action: DO NOTHING, Blue reward:1.00\n", + "step: 23, Red action: DO NOTHING, Blue reward:1.00\n", + "step: 24, Red action: DO NOTHING, Blue reward:1.00\n", + "step: 25, Red action: DO NOTHING, Blue reward:1.00\n", + "step: 26, Red action: ATTACK from client 1, Blue reward:0.20\n", + "step: 27, Red action: DO NOTHING, Blue reward:-0.30\n", + "step: 28, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 29, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 30, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 31, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 32, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 33, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 34, Red action: DO NOTHING, Blue reward:-0.80\n", + "step: 35, Red action: DO NOTHING, Blue reward:-0.80\n" + ] + } + ], "source": [ "for step in range(35):\n", " obs, reward, terminated, truncated, info = env.step(0)\n", @@ -455,9 +642,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}}, 'health_status': 1}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}\n" + ] + } + ], "source": [ "pprint(obs['NODES'])" ] @@ -471,9 +700,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 3, 'operating_status': 1}},\n", + " 'operating_status': 1},\n", + " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 2}}, 'health_status': 1}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1},\n", + " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", + " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", + " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", + " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", + " 'operating_status': 1}}\n" + ] + } + ], "source": [ "obs, reward, terminated, truncated, info = env.step(9) # scan database file\n", "obs, reward, terminated, truncated, info = env.step(1) # scan webapp service\n", @@ -504,9 +775,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 38\n", + "Red action: DONOTHING\n", + "Green action: NODE_APPLICATION_EXECUTE\n", + "Green action: NODE_APPLICATION_EXECUTE\n", + "Blue reward:-0.8\n" + ] + } + ], "source": [ "obs, reward, terminated, truncated, info = env.step(13) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", @@ -529,9 +812,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 48\n", + "Red action: DONOTHING\n", + "Green action: timestep=47 action='NODE_APPLICATION_EXECUTE' parameters={'node_id': 0, 'application_id': 0} request=['network', 'node', 'client_2', 'application', 'WebBrowser', 'execute'] response=RequestResponse(status='failure', data={})\n", + "Green action: timestep=47 action='NODE_APPLICATION_EXECUTE' parameters={'node_id': 0, 'application_id': 0} request=['network', 'node', 'client_1', 'application', 'WebBrowser', 'execute'] response=RequestResponse(status='failure', data={})\n", + "Blue reward:-0.80\n" + ] + } + ], "source": [ "obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", "print(f\"step: {env.game.step_counter}\")\n", @@ -552,9 +847,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 49, Red action: DONOTHING, Blue reward:-0.80\n", + "step: 50, Red action: DONOTHING, Blue reward:-0.80\n", + "step: 51, Red action: DONOTHING, Blue reward:-0.80\n", + "step: 52, Red action: DONOTHING, Blue reward:1.00\n", + "step: 53, Red action: DONOTHING, Blue reward:0.90\n", + "step: 54, Red action: DONOTHING, Blue reward:0.90\n", + "step: 55, Red action: DONOTHING, Blue reward:0.90\n", + "step: 56, Red action: DONOTHING, Blue reward:0.90\n", + "step: 57, Red action: DONOTHING, Blue reward:0.90\n", + "step: 58, Red action: DONOTHING, Blue reward:0.90\n", + "step: 59, Red action: DONOTHING, Blue reward:0.80\n" + ] + } + ], "source": [ "env.step(13) # Patch the database\n", "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'].action}, Blue reward:{reward:.2f}\" )\n", @@ -576,7 +889,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Now, even though the red agent executes an attack, the reward stays at 0.8." + "Now, even though the red agent executes an attack, the reward will stay at 0.8." ] }, { @@ -588,9 +901,89 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{1: {'position': 0,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 2: {'position': 1,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 3: {'position': 2,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 4: {'position': 3,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 5: {'position': 4,\n", + " 'permission': 2,\n", + " 'source_node_id': 7,\n", + " 'source_port': 1,\n", + " 'dest_node_id': 4,\n", + " 'dest_port': 1,\n", + " 'protocol': 3},\n", + " 6: {'position': 5,\n", + " 'permission': 2,\n", + " 'source_node_id': 8,\n", + " 'source_port': 1,\n", + " 'dest_node_id': 4,\n", + " 'dest_port': 1,\n", + " 'protocol': 3},\n", + " 7: {'position': 6,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 8: {'position': 7,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 9: {'position': 8,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0},\n", + " 10: {'position': 9,\n", + " 'permission': 0,\n", + " 'source_node_id': 0,\n", + " 'source_port': 0,\n", + " 'dest_node_id': 0,\n", + " 'dest_port': 0,\n", + " 'protocol': 0}}" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "obs['ACL']" ] @@ -604,9 +997,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "blocking client 1\n", + "\n" + ] + } + ], "source": [ "env.step(58) # Remove the ACL rule that blocks client 1\n", "env.step(57) # Remove the ACL rule that blocks client 2\n", @@ -616,12 +1018,12 @@ " tries += 1\n", " obs, reward, terminated, truncated, info = env.step(0)\n", "\n", - " if obs['NODES'][6]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", + " if obs['NODES'][6]['NICS'][1]['NMNE']['outbound'] == 1:\n", " # client 1 has NMNEs, let's block it\n", " obs, reward, terminated, truncated, info = env.step(50) # block client 1\n", " print(\"blocking client 1\")\n", " break\n", - " elif obs['NODES'][7]['NETWORK_INTERFACES'][1]['nmne']['outbound'] == 1:\n", + " elif obs['NODES'][7]['NICS'][1]['NMNE']['outbound'] == 1:\n", " # client 2 has NMNEs, so let's block it\n", " obs, reward, terminated, truncated, info = env.step(51) # block client 2\n", " print(\"blocking client 2\")\n", @@ -643,9 +1045,56 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "step: 90, Red action: DONOTHING, Blue reward:0.00\n", + "step: 91, Red action: DONOTHING, Blue reward:1.00\n", + "step: 92, Red action: DONOTHING, Blue reward:1.00\n", + "step: 93, Red action: DONOTHING, Blue reward:1.00\n", + "step: 94, Red action: DONOTHING, Blue reward:1.00\n", + "step: 95, Red action: DONOTHING, Blue reward:1.00\n", + "step: 96, Red action: DONOTHING, Blue reward:0.90\n", + "step: 97, Red action: DONOTHING, Blue reward:0.90\n", + "step: 98, Red action: DONOTHING, Blue reward:0.90\n", + "step: 99, Red action: DONOTHING, Blue reward:0.90\n", + "step: 100, Red action: DONOTHING, Blue reward:0.90\n", + "step: 101, Red action: DONOTHING, Blue reward:0.90\n", + "step: 102, Red action: DONOTHING, Blue reward:0.90\n", + "step: 103, Red action: DONOTHING, Blue reward:0.90\n", + "step: 104, Red action: DONOTHING, Blue reward:0.90\n", + "step: 105, Red action: DONOTHING, Blue reward:0.90\n", + "step: 106, Red action: NODE_APPLICATION_EXECUTE, Blue reward:0.90\n", + "step: 107, Red action: DONOTHING, Blue reward:0.90\n", + "step: 108, Red action: DONOTHING, Blue reward:0.90\n", + "step: 109, Red action: DONOTHING, Blue reward:0.90\n", + "step: 110, Red action: DONOTHING, Blue reward:0.90\n", + "step: 111, Red action: DONOTHING, Blue reward:0.90\n", + "step: 112, Red action: DONOTHING, Blue reward:0.90\n", + "step: 113, Red action: DONOTHING, Blue reward:0.90\n", + "step: 114, Red action: DONOTHING, Blue reward:0.90\n", + "step: 115, Red action: DONOTHING, Blue reward:0.90\n", + "step: 116, Red action: DONOTHING, Blue reward:0.90\n", + "step: 117, Red action: DONOTHING, Blue reward:0.90\n", + "step: 118, Red action: DONOTHING, Blue reward:0.90\n", + "step: 119, Red action: DONOTHING, Blue reward:0.90\n", + "step: 120, Red action: DONOTHING, Blue reward:0.90\n", + "step: 121, Red action: DONOTHING, Blue reward:0.90\n", + "step: 122, Red action: DONOTHING, Blue reward:0.90\n", + "step: 123, Red action: DONOTHING, Blue reward:0.90\n", + "step: 124, Red action: DONOTHING, Blue reward:0.90\n", + "step: 125, Red action: DONOTHING, Blue reward:0.90\n", + "step: 126, Red action: DONOTHING, Blue reward:0.90\n", + "step: 127, Red action: DONOTHING, Blue reward:0.90\n", + "step: 128, Red action: NODE_APPLICATION_EXECUTE, Blue reward:0.90\n", + "step: 129, Red action: DONOTHING, Blue reward:0.90\n" + ] + } + ], "source": [ "\n", "for step in range(40):\n", From c8beb39facc2ae5ae364c002efb08d44095c78f2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 14:03:49 +0000 Subject: [PATCH 725/980] clear notebook output --- .../Data-Manipulation-E2E-Demonstration.ipynb | 495 +----------------- 1 file changed, 23 insertions(+), 472 deletions(-) diff --git a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb index 93e1f27f..7ec58b2c 100644 --- a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb @@ -352,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "tags": [] }, @@ -364,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "tags": [] }, @@ -389,154 +389,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "env created successfully\n", - "{'ACL': {1: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 0,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 2: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 1,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 3: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 2,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 4: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 3,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 5: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 4,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 6: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 5,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 7: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 6,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 8: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 7,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 9: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 8,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0},\n", - " 10: {'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'permission': 0,\n", - " 'position': 9,\n", - " 'protocol': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0}},\n", - " 'ICS': 0,\n", - " 'LINKS': {1: {'PROTOCOLS': {'ALL': 1}},\n", - " 2: {'PROTOCOLS': {'ALL': 1}},\n", - " 3: {'PROTOCOLS': {'ALL': 1}},\n", - " 4: {'PROTOCOLS': {'ALL': 1}},\n", - " 5: {'PROTOCOLS': {'ALL': 1}},\n", - " 6: {'PROTOCOLS': {'ALL': 1}},\n", - " 7: {'PROTOCOLS': {'ALL': 1}},\n", - " 8: {'PROTOCOLS': {'ALL': 1}},\n", - " 9: {'PROTOCOLS': {'ALL': 1}},\n", - " 10: {'PROTOCOLS': {'ALL': 0}}},\n", - " 'NODES': {1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}},\n", - " 'health_status': 1}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}},\n", - " 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0},\n", - " 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1}}}\n" - ] - } - ], + "outputs": [], "source": [ "# create the env\n", "with open(data_manipulation_config_path(), 'r') as f:\n", @@ -564,7 +419,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -582,51 +437,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 1, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 2, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 3, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 4, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 5, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 6, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 7, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 8, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 9, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 10, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 11, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 12, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 13, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 14, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 15, Red action: DO NOTHING, Blue reward:0.90\n", - "step: 16, Red action: DO NOTHING, Blue reward:0.95\n", - "step: 17, Red action: DO NOTHING, Blue reward:0.95\n", - "step: 18, Red action: DO NOTHING, Blue reward:0.95\n", - "step: 19, Red action: DO NOTHING, Blue reward:0.95\n", - "step: 20, Red action: DO NOTHING, Blue reward:1.00\n", - "step: 21, Red action: DO NOTHING, Blue reward:1.00\n", - "step: 22, Red action: DO NOTHING, Blue reward:1.00\n", - "step: 23, Red action: DO NOTHING, Blue reward:1.00\n", - "step: 24, Red action: DO NOTHING, Blue reward:1.00\n", - "step: 25, Red action: DO NOTHING, Blue reward:1.00\n", - "step: 26, Red action: ATTACK from client 1, Blue reward:0.20\n", - "step: 27, Red action: DO NOTHING, Blue reward:-0.30\n", - "step: 28, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 29, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 30, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 31, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 32, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 33, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 34, Red action: DO NOTHING, Blue reward:-0.80\n", - "step: 35, Red action: DO NOTHING, Blue reward:-0.80\n" - ] - } - ], + "outputs": [], "source": [ "for step in range(35):\n", " obs, reward, terminated, truncated, info = env.step(0)\n", @@ -642,51 +455,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 1}}, 'health_status': 1}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1}}\n" - ] - } - ], + "outputs": [], "source": [ "pprint(obs['NODES'])" ] @@ -700,51 +471,9 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{1: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 2: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 3, 'operating_status': 1}},\n", - " 'operating_status': 1},\n", - " 3: {'FOLDERS': {1: {'FILES': {1: {'health_status': 2}}, 'health_status': 1}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 4: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 5: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 6: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1},\n", - " 7: {'FOLDERS': {1: {'FILES': {1: {'health_status': 0}}, 'health_status': 0}},\n", - " 'NICS': {1: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 1},\n", - " 2: {'NMNE': {'inbound': 0, 'outbound': 0}, 'nic_status': 0}},\n", - " 'SERVICES': {1: {'health_status': 0, 'operating_status': 0}},\n", - " 'operating_status': 1}}\n" - ] - } - ], + "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(9) # scan database file\n", "obs, reward, terminated, truncated, info = env.step(1) # scan webapp service\n", @@ -775,21 +504,9 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 38\n", - "Red action: DONOTHING\n", - "Green action: NODE_APPLICATION_EXECUTE\n", - "Green action: NODE_APPLICATION_EXECUTE\n", - "Blue reward:-0.8\n" - ] - } - ], + "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(13) # patch the database\n", "print(f\"step: {env.game.step_counter}\")\n", @@ -812,21 +529,9 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 48\n", - "Red action: DONOTHING\n", - "Green action: timestep=47 action='NODE_APPLICATION_EXECUTE' parameters={'node_id': 0, 'application_id': 0} request=['network', 'node', 'client_2', 'application', 'WebBrowser', 'execute'] response=RequestResponse(status='failure', data={})\n", - "Green action: timestep=47 action='NODE_APPLICATION_EXECUTE' parameters={'node_id': 0, 'application_id': 0} request=['network', 'node', 'client_1', 'application', 'WebBrowser', 'execute'] response=RequestResponse(status='failure', data={})\n", - "Blue reward:-0.80\n" - ] - } - ], + "outputs": [], "source": [ "obs, reward, terminated, truncated, info = env.step(0) # do nothing\n", "print(f\"step: {env.game.step_counter}\")\n", @@ -847,27 +552,9 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 49, Red action: DONOTHING, Blue reward:-0.80\n", - "step: 50, Red action: DONOTHING, Blue reward:-0.80\n", - "step: 51, Red action: DONOTHING, Blue reward:-0.80\n", - "step: 52, Red action: DONOTHING, Blue reward:1.00\n", - "step: 53, Red action: DONOTHING, Blue reward:0.90\n", - "step: 54, Red action: DONOTHING, Blue reward:0.90\n", - "step: 55, Red action: DONOTHING, Blue reward:0.90\n", - "step: 56, Red action: DONOTHING, Blue reward:0.90\n", - "step: 57, Red action: DONOTHING, Blue reward:0.90\n", - "step: 58, Red action: DONOTHING, Blue reward:0.90\n", - "step: 59, Red action: DONOTHING, Blue reward:0.80\n" - ] - } - ], + "outputs": [], "source": [ "env.step(13) # Patch the database\n", "print(f\"step: {env.game.step_counter}, Red action: {info['agent_actions']['data_manipulation_attacker'].action}, Blue reward:{reward:.2f}\" )\n", @@ -901,89 +588,9 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{1: {'position': 0,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 2: {'position': 1,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 3: {'position': 2,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 4: {'position': 3,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 5: {'position': 4,\n", - " 'permission': 2,\n", - " 'source_node_id': 7,\n", - " 'source_port': 1,\n", - " 'dest_node_id': 4,\n", - " 'dest_port': 1,\n", - " 'protocol': 3},\n", - " 6: {'position': 5,\n", - " 'permission': 2,\n", - " 'source_node_id': 8,\n", - " 'source_port': 1,\n", - " 'dest_node_id': 4,\n", - " 'dest_port': 1,\n", - " 'protocol': 3},\n", - " 7: {'position': 6,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 8: {'position': 7,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 9: {'position': 8,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0},\n", - " 10: {'position': 9,\n", - " 'permission': 0,\n", - " 'source_node_id': 0,\n", - " 'source_port': 0,\n", - " 'dest_node_id': 0,\n", - " 'dest_port': 0,\n", - " 'protocol': 0}}" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "obs['ACL']" ] @@ -997,18 +604,9 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "blocking client 1\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "env.step(58) # Remove the ACL rule that blocks client 1\n", "env.step(57) # Remove the ACL rule that blocks client 2\n", @@ -1045,56 +643,9 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "step: 90, Red action: DONOTHING, Blue reward:0.00\n", - "step: 91, Red action: DONOTHING, Blue reward:1.00\n", - "step: 92, Red action: DONOTHING, Blue reward:1.00\n", - "step: 93, Red action: DONOTHING, Blue reward:1.00\n", - "step: 94, Red action: DONOTHING, Blue reward:1.00\n", - "step: 95, Red action: DONOTHING, Blue reward:1.00\n", - "step: 96, Red action: DONOTHING, Blue reward:0.90\n", - "step: 97, Red action: DONOTHING, Blue reward:0.90\n", - "step: 98, Red action: DONOTHING, Blue reward:0.90\n", - "step: 99, Red action: DONOTHING, Blue reward:0.90\n", - "step: 100, Red action: DONOTHING, Blue reward:0.90\n", - "step: 101, Red action: DONOTHING, Blue reward:0.90\n", - "step: 102, Red action: DONOTHING, Blue reward:0.90\n", - "step: 103, Red action: DONOTHING, Blue reward:0.90\n", - "step: 104, Red action: DONOTHING, Blue reward:0.90\n", - "step: 105, Red action: DONOTHING, Blue reward:0.90\n", - "step: 106, Red action: NODE_APPLICATION_EXECUTE, Blue reward:0.90\n", - "step: 107, Red action: DONOTHING, Blue reward:0.90\n", - "step: 108, Red action: DONOTHING, Blue reward:0.90\n", - "step: 109, Red action: DONOTHING, Blue reward:0.90\n", - "step: 110, Red action: DONOTHING, Blue reward:0.90\n", - "step: 111, Red action: DONOTHING, Blue reward:0.90\n", - "step: 112, Red action: DONOTHING, Blue reward:0.90\n", - "step: 113, Red action: DONOTHING, Blue reward:0.90\n", - "step: 114, Red action: DONOTHING, Blue reward:0.90\n", - "step: 115, Red action: DONOTHING, Blue reward:0.90\n", - "step: 116, Red action: DONOTHING, Blue reward:0.90\n", - "step: 117, Red action: DONOTHING, Blue reward:0.90\n", - "step: 118, Red action: DONOTHING, Blue reward:0.90\n", - "step: 119, Red action: DONOTHING, Blue reward:0.90\n", - "step: 120, Red action: DONOTHING, Blue reward:0.90\n", - "step: 121, Red action: DONOTHING, Blue reward:0.90\n", - "step: 122, Red action: DONOTHING, Blue reward:0.90\n", - "step: 123, Red action: DONOTHING, Blue reward:0.90\n", - "step: 124, Red action: DONOTHING, Blue reward:0.90\n", - "step: 125, Red action: DONOTHING, Blue reward:0.90\n", - "step: 126, Red action: DONOTHING, Blue reward:0.90\n", - "step: 127, Red action: DONOTHING, Blue reward:0.90\n", - "step: 128, Red action: NODE_APPLICATION_EXECUTE, Blue reward:0.90\n", - "step: 129, Red action: DONOTHING, Blue reward:0.90\n" - ] - } - ], + "outputs": [], "source": [ "\n", "for step in range(40):\n", From 7f4f3e9bfe85fd9aa8834e755e8d0128dd5fcbbf Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 14:09:02 +0000 Subject: [PATCH 726/980] Calm logging --- src/primaite/game/agent/rewards.py | 2 +- src/primaite/simulator/network/airspace.py | 2 +- src/primaite/simulator/network/hardware/base.py | 6 +++--- src/primaite/simulator/system/applications/application.py | 2 +- src/primaite/simulator/system/services/service.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 52bed9e2..d214ecc9 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -111,7 +111,7 @@ class DatabaseFileIntegrity(AbstractReward): """ database_file_state = access_from_nested_dict(state, self.location_in_state) if database_file_state is NOT_PRESENT_IN_STATE: - _LOGGER.info( + _LOGGER.debug( f"Could not calculate {self.__class__} reward because " "simulation state did not contain enough information." ) diff --git a/src/primaite/simulator/network/airspace.py b/src/primaite/simulator/network/airspace.py index 5ceedc8e..a8343675 100644 --- a/src/primaite/simulator/network/airspace.py +++ b/src/primaite/simulator/network/airspace.py @@ -157,7 +157,7 @@ class WirelessNetworkInterface(NetworkInterface, ABC): return if not self._connected_node: - _LOGGER.error(f"Interface {self} cannot be enabled as it is not connected to a Node") + _LOGGER.warning(f"Interface {self} cannot be enabled as it is not connected to a Node") return if self._connected_node.operating_state != NodeOperatingState.ON: diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index a91a709c..0695c1c7 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -297,7 +297,7 @@ class WiredNetworkInterface(NetworkInterface, ABC): return True if not self._connected_node: - _LOGGER.error(f"Interface {self} cannot be enabled as it is not connected to a Node") + _LOGGER.warning(f"Interface {self} cannot be enabled as it is not connected to a Node") return False if self._connected_node.operating_state != NodeOperatingState.ON: @@ -343,11 +343,11 @@ class WiredNetworkInterface(NetworkInterface, ABC): :param link: The Link instance to connect to this network interface. """ if self._connected_link: - _LOGGER.error(f"Cannot connect Link to network interface {self} as it already has a connection") + _LOGGER.warning(f"Cannot connect Link to network interface {self} as it already has a connection") return if self._connected_link == link: - _LOGGER.error(f"Cannot connect Link to network interface {self} as it is already connected") + _LOGGER.warning(f"Cannot connect Link to network interface {self} as it is already connected") return self._connected_link = link diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 74013681..b7422680 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -83,7 +83,7 @@ class Application(IOSoftware): if self.operating_state is not self.operating_state.RUNNING: # service is not running - _LOGGER.error(f"Cannot perform action: {self.name} is {self.operating_state.name}") + _LOGGER.debug(f"Cannot perform action: {self.name} is {self.operating_state.name}") return False return True diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index e15377a9..b2a6f685 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -59,7 +59,7 @@ class Service(IOSoftware): if self.operating_state is not ServiceOperatingState.RUNNING: # service is not running - _LOGGER.error(f"Cannot perform action: {self.name} is {self.operating_state.name}") + _LOGGER.debug(f"Cannot perform action: {self.name} is {self.operating_state.name}") return False return True From 8a9d8fb17cd7867a5ca58291d5cb8c7238c0afde Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 14:10:34 +0000 Subject: [PATCH 727/980] Calm logging again --- src/primaite/game/agent/rewards.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index d214ecc9..2201b09e 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -231,7 +231,7 @@ class WebpageUnavailablePenalty(AbstractReward): # If the last request did actually go through, then check if the webpage also loaded web_browser_state = access_from_nested_dict(state, self.location_in_state) if web_browser_state is NOT_PRESENT_IN_STATE or "history" not in web_browser_state: - _LOGGER.info( + _LOGGER.debug( "Web browser reward could not be calculated because the web browser history on node", f"{self._node} was not reported in the simulation state. Returning 0.0", ) From 9a38fcdae263f11462bcab1c3dc0b88052004904 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 14:19:30 +0000 Subject: [PATCH 728/980] Fix broken config --- src/primaite/config/_package_data/data_manipulation_marl.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index be53d2c5..652dd809 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -13,8 +13,6 @@ training_config: io_settings: - save_checkpoints: true - checkpoint_interval: 5 save_agent_actions: true save_step_metadata: false save_pcap_logs: false From fc67fc48337160f5e8dc291982161f004f475d94 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 14:37:28 +0000 Subject: [PATCH 729/980] Fix notebook parsing data --- .../Data-Manipulation-Customising-Red-Agent.ipynb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb b/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb index 779d89f6..56e9bf5a 100644 --- a/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb @@ -22,6 +22,7 @@ "# Imports\n", "\n", "from primaite.config.load import data_manipulation_config_path\n", + "from primaite.game.agent.interface import AgentActionHistoryItem\n", "from primaite.session.environment import PrimaiteGymEnv\n", "import yaml\n", "from pprint import pprint" @@ -62,12 +63,12 @@ "source": [ "def friendly_output_red_action(info):\n", " # parse the info dict form step output and write out what the red agent is doing\n", - " red_info = info['agent_actions']['data_manipulation_attacker']\n", - " red_action = red_info[0]\n", + " red_info : AgentActionHistoryItem = info['agent_actions']['data_manipulation_attacker']\n", + " red_action = red_info.action\n", " if red_action == 'DONOTHING':\n", " red_str = 'DO NOTHING'\n", " elif red_action == 'NODE_APPLICATION_EXECUTE':\n", - " client = \"client 1\" if red_info[1]['node_id'] == 0 else \"client 2\"\n", + " client = \"client 1\" if red_info.parameters['node_id'] == 0 else \"client 2\"\n", " red_str = f\"ATTACK from {client}\"\n", " return red_str" ] From b217869dd118a108f2eb61f318cf60340aea61ef Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 15:03:27 +0000 Subject: [PATCH 730/980] Improve clarity in docs --- docs/source/example_notebooks.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/example_notebooks.rst b/docs/source/example_notebooks.rst index e77b444e..99d47822 100644 --- a/docs/source/example_notebooks.rst +++ b/docs/source/example_notebooks.rst @@ -38,7 +38,7 @@ Running Jupyter Notebooks 3. Opening the jupyter webpage (optional) -The default web browser may automatically open the webpage. However, if that is not the case, click the link shown in your command prompt output. It should look like this: ``http://localhost:8888/?token=ab83071fd13cb5a1384efba318...`` +The default web browser may automatically open the webpage. However, if that is not the case, click the link shown in your command prompt output. It should look like this: ``http://localhost:8888/?token=0123456798abc0123456789abc`` 4. Navigate to the list of notebooks From b4d310eda258ee453f7ded0f111f4d44effedcc7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 16:17:38 +0000 Subject: [PATCH 731/980] Align step counts in logging --- src/primaite/session/environment.py | 34 ++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 1795f14b..ce9699d4 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -47,6 +47,7 @@ class PrimaiteGymEnv(gymnasium.Env): def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: """Perform a step in the environment.""" # make ProxyAgent store the action chosen my the RL policy + step = self.game.step_counter self.agent.store_action(action) # apply_agent_actions accesses the action we just stored self.game.apply_agent_actions() @@ -62,18 +63,18 @@ class PrimaiteGymEnv(gymnasium.Env): "agent_actions": {name: agent.action_history[-1] for name, agent in self.game.agents.items()} } # tell us what all the agents did for convenience. if self.game.save_step_metadata: - self._write_step_metadata_json(action, state, reward) + self._write_step_metadata_json(step, action, state, reward) return next_obs, reward, terminated, truncated, info - def _write_step_metadata_json(self, action: int, state: Dict, reward: int): + def _write_step_metadata_json(self, step: int, action: int, state: Dict, reward: int): output_dir = SIM_OUTPUT.path / f"episode_{self.episode_counter}" / "step_metadata" output_dir.mkdir(parents=True, exist_ok=True) - path = output_dir / f"step_{self.game.step_counter}.json" + path = output_dir / f"step_{step}.json" data = { "episode": self.episode_counter, - "step": self.game.step_counter, + "step": step, "action": int(action), "reward": int(reward), "state": state, @@ -121,6 +122,12 @@ class PrimaiteGymEnv(gymnasium.Env): else: return self.agent.observation_manager.current_observation + def close(self): + """Close the simulation.""" + if self.io.settings.save_agent_actions: + all_agent_actions = {name: agent.action_history for name, agent in self.game.agents.items()} + self.io.write_agent_actions(agent_actions=all_agent_actions, episode=self.episode_counter) + class PrimaiteRayEnv(gymnasium.Env): """Ray wrapper that accepts a single `env_config` parameter in init function for compatibility with Ray.""" @@ -144,6 +151,10 @@ class PrimaiteRayEnv(gymnasium.Env): """Perform a step in the environment.""" return self.env.step(action) + def close(self): + """Close the simulation.""" + self.env.close() + class PrimaiteRayMARLEnv(MultiAgentEnv): """Ray Environment that inherits from MultiAgentEnv to allow training MARL systems.""" @@ -211,6 +222,7 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): identifier. :rtype: Tuple[Dict[str,ObsType], Dict[str, SupportsFloat], Dict[str,bool], Dict[str,bool], Dict] """ + step = self.game.step_counter # 1. Perform actions for agent_name, action in actions.items(): self.agents[agent_name].store_action(action) @@ -232,18 +244,18 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): terminateds["__all__"] = len(self.terminateds) == len(self.agents) truncateds["__all__"] = self.game.calculate_truncated() if self.game.save_step_metadata: - self._write_step_metadata_json(actions, state, rewards) + self._write_step_metadata_json(step, actions, state, rewards) return next_obs, rewards, terminateds, truncateds, infos - def _write_step_metadata_json(self, actions: Dict, state: Dict, rewards: Dict): + def _write_step_metadata_json(self, step: int, actions: Dict, state: Dict, rewards: Dict): output_dir = SIM_OUTPUT.path / f"episode_{self.episode_counter}" / "step_metadata" output_dir.mkdir(parents=True, exist_ok=True) - path = output_dir / f"step_{self.game.step_counter}.json" + path = output_dir / f"step_{step}.json" data = { "episode": self.episode_counter, - "step": self.game.step_counter, + "step": step, "actions": {agent_name: int(action) for agent_name, action in actions.items()}, "reward": rewards, "state": state, @@ -260,3 +272,9 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): unflat_obs = agent.observation_manager.current_observation obs[agent_name] = gymnasium.spaces.flatten(unflat_space, unflat_obs) return obs + + def close(self): + """Close the simulation.""" + if self.io.settings.save_agent_actions: + all_agent_actions = {name: agent.action_history for name, agent in self.game.agents.items()} + self.io.write_agent_actions(agent_actions=all_agent_actions, episode=self.episode_counter) From bb0161991846be4787df7c49d3ab28005f42a560 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 15 Mar 2024 16:17:45 +0000 Subject: [PATCH 732/980] Bump version --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index fa7f84f1..1129dfd4 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0b7dev +3.0.0b7 From bef2bd80845fc7fda09f0c3dbbb43654d38eb4e4 Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Fri, 22 Mar 2024 16:35:53 +0000 Subject: [PATCH 733/980] add actions to enable/disable ports in routers/firewalls, improve notebook for training PPO agents --- src/primaite/game/agent/actions.py | 49 +++++++++++++++ .../notebooks/Training-an-SB3-Agent.ipynb | 32 ++++++++-- tests/conftest.py | 3 + .../game_layer/test_actions.py | 62 +++++++++++++++++++ 4 files changed, 140 insertions(+), 6 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 4d28328e..8cad4108 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -569,6 +569,53 @@ class NetworkNICDisableAction(NetworkNICAbstractAction): self.verb: str = "disable" +class NetworkPortAbstractAction(AbstractAction): + """ + Abstract base class for Port actions. + + Any action which applies to a Router/Firewall and uses node_id and port_id as its only two parameters + can inherit from this base class. + """ + + def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: + """Init method for NetworkNICAbstractAction. + + :param manager: Reference to the ActionManager which created this action. + :type manager: ActionManager + :param num_nodes: Number of nodes in the simulation. + :type num_nodes: int + :param max_nics_per_node: Maximum number of NICs per node. + :type max_nics_per_node: int + """ + super().__init__(manager=manager) + self.shape: Dict[str, int] = {"node_id": num_nodes, "port_id": max_nics_per_node} + self.verb: str # define but don't initialise: defends against children classes not defining this + + def form_request(self, node_id: int, port_id: int) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" + node_name = self.manager.get_node_name_by_idx(node_idx=node_id) + port_num = self.manager.get_nic_num_by_idx(node_idx=node_id, nic_idx=port_id) + if node_name is None or port_num is None: + return ["do_nothing"] + return ["network", "node", node_name, "network_interface", port_num, self.verb] + + +class NetworkPortEnableAction(NetworkPortAbstractAction): + """Action which enables a PORT.""" + + def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, max_nics_per_node=max_nics_per_node, **kwargs) + self.verb: str = "enable" + + +class NetworkPortDisableAction(NetworkPortAbstractAction): + """Action which disables a NIC.""" + + def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, max_nics_per_node=max_nics_per_node, **kwargs) + self.verb: str = "disable" + + class ActionManager: """Class which manages the action space for an agent.""" @@ -602,6 +649,8 @@ class ActionManager: "NETWORK_ACL_REMOVERULE": NetworkACLRemoveRuleAction, "NETWORK_NIC_ENABLE": NetworkNICEnableAction, "NETWORK_NIC_DISABLE": NetworkNICDisableAction, + "NETWORK_PORT_ENABLE": NetworkPortEnableAction, + "NETWORK_PORT_DISABLE": NetworkPortDisableAction, } """Dictionary which maps action type strings to the corresponding action class.""" diff --git a/src/primaite/notebooks/Training-an-SB3-Agent.ipynb b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb index cefcc429..e6f5aaee 100644 --- a/src/primaite/notebooks/Training-an-SB3-Agent.ipynb +++ b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb @@ -45,7 +45,13 @@ "metadata": {}, "outputs": [], "source": [ - "from stable_baselines3 import PPO" + "from stable_baselines3 import PPO\n", + "\n", + "EPISODE_LEN = 128\n", + "NO_STEPS = EPISODE_LEN * 10\n", + "BATCH_SIZE = EPISODE_LEN * 10\n", + "TOTAL_TIMESTEPS = 5e3 * EPISODE_LEN\n", + "LEARNING_RATE = 3e-4" ] }, { @@ -54,7 +60,7 @@ "metadata": {}, "outputs": [], "source": [ - "model = PPO('MlpPolicy', gym)\n" + "model = PPO('MlpPolicy', gym, learning_rate=LEARNING_RATE, n_steps=NO_STEPS, batch_size=BATCH_SIZE, verbose=0, tensorboard_log=\"./PPO_UC2/\")\n" ] }, { @@ -63,7 +69,7 @@ "metadata": {}, "outputs": [], "source": [ - "model.learn(total_timesteps=10)\n" + "model.learn(total_timesteps=TOTAL_TIMESTEPS)\n" ] }, { @@ -72,7 +78,7 @@ "metadata": {}, "outputs": [], "source": [ - "model.save(\"deleteme\")" + "model.save(\"PrimAITE-v3.0.0b7-PPO\")" ] }, { @@ -80,7 +86,21 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "eval_model = PPO(\"MlpPolicy\", gym)\n", + "eval_model = PPO.load(\"PrimAITE-v3.0.0b7-PPO\", gym)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from stable_baselines3.common.evaluation import evaluate_policy\n", + "\n", + "evaluate_policy(eval_model, gym, n_eval_episodes=10)" + ] } ], "metadata": { @@ -99,7 +119,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.9.18" } }, "nbformat": 4, diff --git a/tests/conftest.py b/tests/conftest.py index 3a9e2655..fbfd23f2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -495,6 +495,8 @@ def game_and_agent(): {"type": "NETWORK_ACL_REMOVERULE", "options": {"target_router_hostname": "router"}}, {"type": "NETWORK_NIC_ENABLE"}, {"type": "NETWORK_NIC_DISABLE"}, + {"type": "NETWORK_PORT_ENABLE"}, + {"type": "NETWORK_PORT_DISABLE"}, ] action_space = ActionManager( @@ -507,6 +509,7 @@ def game_and_agent(): }, {"node_name": "server_1", "services": [{"service_name": "DNSServer"}]}, {"node_name": "server_2", "services": [{"service_name": "WebServer"}]}, + {"node_name": "router"}, ], max_folders_per_node=2, max_files_per_folder=2, diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 740fb491..5ced802c 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -312,3 +312,65 @@ def test_node_file_delete_integration(game_and_agent: Tuple[PrimaiteGame, ProxyA assert not client_1.file_system.get_file("downloads", "cat.png") # 3.1 (but with the reference to the original file, we can check that deleted flag is True ) assert file.deleted + + +def test_network_router_port_disable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the NetworkPortDisableAction can form a request and that it is accepted by the simulation.""" + game, agent = game_and_agent + + # 1: Check that client_1 can access the network + client_1 = game.simulation.network.get_node_by_hostname("client_1") + server_1 = game.simulation.network.get_node_by_hostname("server_1") + router = game.simulation.network.get_node_by_hostname("router") + + browser: WebBrowser = client_1.software_manager.software.get("WebBrowser") + browser.run() + browser.target_url = "http://www.example.com" + assert browser.get_webpage() # check that the browser can access example.com before we block it + + # 2: Disable the NIC on client_1 + action = ( + "NETWORK_PORT_DISABLE", + { + "node_id": 3, # router + "port_id": 0, # port 1 + }, + ) + agent.store_action(action) + game.step() + + # 3: Check that the NIC is disabled, and that client 1 cannot access example.com + assert router.network_interface[1].enabled == False + assert not browser.get_webpage() + assert not client_1.ping("10.0.2.2") + assert not client_1.ping("10.0.2.3") + + # 4: check that servers can still communicate + assert server_1.ping("10.0.2.3") + + +def test_network_router_port_enable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the NetworkPortEnableAction can form a request and that it is accepted by the simulation.""" + + game, agent = game_and_agent + + # 1: Disable router port 1 + router = game.simulation.network.get_node_by_hostname("router") + client_1 = game.simulation.network.get_node_by_hostname("client_1") + router.network_interface[1].disable() + assert not client_1.ping("10.0.2.2") + + # 2: Use action to enable port + action = ( + "NETWORK_PORT_ENABLE", + { + "node_id": 3, # router + "port_id": 0, # port 1 + }, + ) + agent.store_action(action) + game.step() + + # 3: Check that the Port is enabled, and that client 1 can ping again + assert router.network_interface[1].enabled == True + assert client_1.ping("10.0.2.3") From 4a5dd9ba0fa992b683442c4b5370e9e10dff8064 Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Mon, 25 Mar 2024 11:08:36 +0000 Subject: [PATCH 734/980] fix typo --- src/primaite/game/agent/actions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 8cad4108..af90c1e1 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -609,7 +609,7 @@ class NetworkPortEnableAction(NetworkPortAbstractAction): class NetworkPortDisableAction(NetworkPortAbstractAction): - """Action which disables a NIC.""" + """Action which disables a PORT.""" def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, max_nics_per_node=max_nics_per_node, **kwargs) From 78b966ace48b4e991334ea1d3d8b2f6ab7768948 Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Mon, 25 Mar 2024 11:41:07 +0000 Subject: [PATCH 735/980] fix port/nic enable/disable actions returning failure when they succeed --- src/primaite/simulator/network/hardware/base.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 0cad4124..38d20e1f 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -519,12 +519,10 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC): """ super().enable() try: - pass self._connected_node.default_gateway_hello() - return True except AttributeError: pass - return False + return True @abstractmethod def receive_frame(self, frame: Frame) -> bool: From 600dc3f016b3c18add5c5f109b7ad0fe24c154ad Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Mon, 25 Mar 2024 16:58:27 +0000 Subject: [PATCH 736/980] #2404 add application scan, close, and fix actions, fix and enable service scan test --- src/primaite/game/agent/actions.py | 27 ++++++ .../system/applications/application.py | 14 +++ tests/conftest.py | 3 + .../game_layer/test_actions.py | 89 ++++++++++++++++++- 4 files changed, 129 insertions(+), 4 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index af90c1e1..bdb90b57 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -195,6 +195,30 @@ class NodeApplicationExecuteAction(NodeApplicationAbstractAction): self.verb: str = "execute" +class NodeApplicationScanAction(NodeApplicationAbstractAction): + """Action which scans an application.""" + + def __init__(self, manager: "ActionManager", num_nodes: int, num_applications: int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_applications=num_applications) + self.verb: str = "scan" + + +class NodeApplicationCloseAction(NodeApplicationAbstractAction): + """Action which closes an application.""" + + def __init__(self, manager: "ActionManager", num_nodes: int, num_applications: int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_applications=num_applications) + self.verb: str = "close" + + +class NodeApplicationFixAction(NodeApplicationAbstractAction): + """Action which fixes an application.""" + + def __init__(self, manager: "ActionManager", num_nodes: int, num_applications: int, **kwargs) -> None: + super().__init__(manager=manager, num_nodes=num_nodes, num_applications=num_applications) + self.verb: str = "patch" + + class NodeFolderAbstractAction(AbstractAction): """ Base class for folder actions. @@ -631,6 +655,9 @@ class ActionManager: "NODE_SERVICE_ENABLE": NodeServiceEnableAction, "NODE_SERVICE_PATCH": NodeServicePatchAction, "NODE_APPLICATION_EXECUTE": NodeApplicationExecuteAction, + "NODE_APPLICATION_SCAN": NodeApplicationScanAction, + "NODE_APPLICATION_CLOSE": NodeApplicationCloseAction, + "NODE_APPLICATION_FIX": NodeApplicationFixAction, "NODE_FILE_SCAN": NodeFileScanAction, "NODE_FILE_CHECKHASH": NodeFileCheckhashAction, "NODE_FILE_DELETE": NodeFileDeleteAction, diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index b7422680..4ea893e0 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -3,6 +3,8 @@ from enum import Enum from typing import Any, Dict, Set from primaite import getLogger +from primaite.interface.request import RequestResponse +from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.system.software import IOSoftware, SoftwareHealthState _LOGGER = getLogger(__name__) @@ -38,6 +40,17 @@ class Application(IOSoftware): def __init__(self, **kwargs): super().__init__(**kwargs) + def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ + rm = super()._init_request_manager() + + rm.add_request("close", RequestType(func=lambda request, context: RequestResponse.from_bool(self.close()))) + return rm + @abstractmethod def describe_state(self) -> Dict: """ @@ -109,6 +122,7 @@ class Application(IOSoftware): if self.operating_state == ApplicationOperatingState.RUNNING: self.sys_log.info(f"Closed Application{self.name}") self.operating_state = ApplicationOperatingState.CLOSED + return True def install(self) -> None: """Install Application.""" diff --git a/tests/conftest.py b/tests/conftest.py index fbfd23f2..9eaf1782 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -477,6 +477,9 @@ def game_and_agent(): {"type": "NODE_SERVICE_ENABLE"}, {"type": "NODE_SERVICE_PATCH"}, {"type": "NODE_APPLICATION_EXECUTE"}, + {"type": "NODE_APPLICATION_SCAN"}, + {"type": "NODE_APPLICATION_CLOSE"}, + {"type": "NODE_APPLICATION_FIX"}, {"type": "NODE_FILE_SCAN"}, {"type": "NODE_FILE_CHECKHASH"}, {"type": "NODE_FILE_DELETE"}, diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 5ced802c..98e6ea5d 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -17,6 +17,7 @@ import pytest from primaite.game.agent.interface import ProxyAgent from primaite.game.game import PrimaiteGame from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus +from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.software import SoftwareHealthState @@ -30,7 +31,6 @@ def test_do_nothing_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]) game.step() -@pytest.mark.skip(reason="Waiting to merge ticket 2166") def test_node_service_scan_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): """ Test that the NodeServiceScanAction can form a request and that it is accepted by the simulation. @@ -42,12 +42,12 @@ def test_node_service_scan_integration(game_and_agent: Tuple[PrimaiteGame, Proxy game, agent = game_and_agent # 1: Check that the service starts off in a good state, and that visible state is hidden until first scan - svc = game.simulation.network.get_node_by_hostname("client_1").software_manager.software.get("DNSClient") + svc = game.simulation.network.get_node_by_hostname("server_1").software_manager.software.get("DNSServer") assert svc.health_state_actual == SoftwareHealthState.GOOD assert svc.health_state_visible == SoftwareHealthState.UNUSED # 2: Scan and check that the visible state is now correct - action = ("NODE_SERVICE_SCAN", {"node_id": 0, "service_id": 0}) + action = ("NODE_SERVICE_SCAN", {"node_id": 1, "service_id": 0}) agent.store_action(action) game.step() assert svc.health_state_actual == SoftwareHealthState.GOOD @@ -58,7 +58,7 @@ def test_node_service_scan_integration(game_and_agent: Tuple[PrimaiteGame, Proxy assert svc.health_state_visible == SoftwareHealthState.GOOD # 4: Scan and check that the visible state is now correct - action = ("NODE_SERVICE_SCAN", {"node_id": 0, "service_id": 0}) + action = ("NODE_SERVICE_SCAN", {"node_id": 1, "service_id": 0}) agent.store_action(action) game.step() assert svc.health_state_actual == SoftwareHealthState.COMPROMISED @@ -374,3 +374,84 @@ def test_network_router_port_enable_integration(game_and_agent: Tuple[PrimaiteGa # 3: Check that the Port is enabled, and that client 1 can ping again assert router.network_interface[1].enabled == True assert client_1.ping("10.0.2.3") + + +def test_node_application_scan_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the NodeApplicationScanAction updates the application status as expected.""" + game, agent = game_and_agent + + # 1: Check that http traffic is going across the network nicely. + client_1 = game.simulation.network.get_node_by_hostname("client_1") + + browser: WebBrowser = client_1.software_manager.software.get("WebBrowser") + browser.run() + browser.target_url = "http://www.example.com" + assert browser.get_webpage() # check that the browser can access example.com + + assert browser.health_state_actual == SoftwareHealthState.GOOD + assert browser.health_state_visible == SoftwareHealthState.UNUSED + + # 2: Scan and check that the visible state is now correct + action = ("NODE_APPLICATION_SCAN", {"node_id": 0, "application_id": 0}) + agent.store_action(action) + game.step() + assert browser.health_state_actual == SoftwareHealthState.GOOD + assert browser.health_state_visible == SoftwareHealthState.GOOD + + # 3: Corrupt the service and check that the visible state is still good + browser.health_state_actual = SoftwareHealthState.COMPROMISED + assert browser.health_state_visible == SoftwareHealthState.GOOD + + # 4: Scan and check that the visible state is now correct + action = ("NODE_APPLICATION_SCAN", {"node_id": 0, "application_id": 0}) + agent.store_action(action) + game.step() + assert browser.health_state_actual == SoftwareHealthState.COMPROMISED + assert browser.health_state_visible == SoftwareHealthState.COMPROMISED + + +def test_node_application_fix_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the NodeApplicationFixAction can form a request and that it is accepted by the simulation. + + When you initiate a fix action, the software health state turns to PATCHING, then after a few steps, it goes + to GOOD.""" + game, agent = game_and_agent + + # 1: Check that http traffic is going across the network nicely. + client_1 = game.simulation.network.get_node_by_hostname("client_1") + + browser: WebBrowser = client_1.software_manager.software.get("WebBrowser") + browser.health_state_actual = SoftwareHealthState.COMPROMISED + + # 2: Apply a fix action + action = ("NODE_APPLICATION_FIX", {"node_id": 0, "application_id": 0}) + agent.store_action(action) + game.step() + + # 3: Check that the application is now in the patching state + assert browser.health_state_actual == SoftwareHealthState.PATCHING + + # 4: perform a few do-nothing steps and check that the application is now in the good state + action = ("DONOTHING", {}) + agent.store_action(action) + game.step() + assert browser.health_state_actual == SoftwareHealthState.GOOD + + +def test_node_application_close_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the NodeApplicationCloseAction can form a request and that it is accepted by the simulation. + + When you initiate a close action, the Application Operating State changes for CLOSED.""" + game, agent = game_and_agent + client_1 = game.simulation.network.get_node_by_hostname("client_1") + + browser: WebBrowser = client_1.software_manager.software.get("WebBrowser") + browser.run() + assert browser.operating_state == ApplicationOperatingState.RUNNING + + # 2: Apply a close action + action = ("NODE_APPLICATION_CLOSE", {"node_id": 0, "application_id": 0}) + agent.store_action(action) + game.step() + + assert browser.operating_state == ApplicationOperatingState.CLOSED From 944b248300fc6729e21cc9446f1682207e3847be Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Tue, 26 Mar 2024 10:51:33 +0000 Subject: [PATCH 737/980] #2404 rename software patch to fix --- .../config/benchmark_training_config.yaml | 2 +- .../v2.0.0/v2.0.0_benchmark_metadata.json | 2 +- diagram/classes.puml | 8 ++--- .../_package_data/data_manipulation.yaml | 4 +-- .../_package_data/data_manipulation_marl.yaml | 8 ++--- src/primaite/game/agent/actions.py | 10 +++--- .../services/database/database_service.py | 6 ++-- src/primaite/simulator/system/software.py | 32 +++++++++---------- .../assets/configs/bad_primaite_session.yaml | 4 +-- .../configs/eval_only_primaite_session.yaml | 4 +-- tests/assets/configs/multi_agent_session.yaml | 8 ++--- tests/assets/configs/shared_rewards.yaml | 4 +-- .../assets/configs/test_primaite_session.yaml | 4 +-- .../configs/train_only_primaite_session.yaml | 4 +-- .../session_metadata.json | 2 +- tests/conftest.py | 2 +- .../game_layer/test_actions.py | 6 ++-- .../test_simulation/test_request_response.py | 4 +-- .../_applications/test_applications.py | 2 +- .../_applications/test_database_client.py | 2 -- .../_system/_services/test_service_actions.py | 6 ++-- .../_system/_services/test_services.py | 6 ++-- 22 files changed, 64 insertions(+), 66 deletions(-) diff --git a/benchmark/config/benchmark_training_config.yaml b/benchmark/config/benchmark_training_config.yaml index 02b6377c..17811586 100644 --- a/benchmark/config/benchmark_training_config.yaml +++ b/benchmark/config/benchmark_training_config.yaml @@ -158,7 +158,7 @@ green_ier_blocked: -0.001 # Patching / Reset durations os_patching_duration: 5 # The time taken to patch the OS node_reset_duration: 5 # The time taken to reset a node (hardware) -service_patching_duration: 5 # The time taken to patch a service +service_fixing_duration: 5 # The time taken to patch a service file_system_repairing_limit: 5 # The time take to repair the file system file_system_restoring_limit: 5 # The time take to restore the file system file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/benchmark/results/v2.0.0/v2.0.0_benchmark_metadata.json b/benchmark/results/v2.0.0/v2.0.0_benchmark_metadata.json index b2745967..3ed57745 100644 --- a/benchmark/results/v2.0.0/v2.0.0_benchmark_metadata.json +++ b/benchmark/results/v2.0.0/v2.0.0_benchmark_metadata.json @@ -5634,7 +5634,7 @@ "green_ier_blocked": -0.001, "os_patching_duration": 5, "node_reset_duration": 5, - "service_patching_duration": 5, + "service_fixing_duration": 5, "file_system_repairing_limit": 5, "file_system_restoring_limit": 5, "file_system_scanning_limit": 5 diff --git a/diagram/classes.puml b/diagram/classes.puml index 4505f3e0..71e0b0b1 100644 --- a/diagram/classes.puml +++ b/diagram/classes.puml @@ -48,7 +48,7 @@ class "ActiveNode" as primaite.nodes.active_node.ActiveNode { file_system_state_actual : GOOD file_system_state_observed : REPAIRING, RESTORING, GOOD ip_address : str - patching_count : int + fixing_count : int software_state software_state : GOOD set_file_system_state(file_system_state: FileSystemState) -> None @@ -353,10 +353,10 @@ class "SB3Agent" as primaite.agents.sb3.SB3Agent { } class "Service" as primaite.common.service.Service { name : str - patching_count : int + fixing_count : int port : str software_state : GOOD - reduce_patching_count() -> None + reduce_fixing_count() -> None } class "ServiceNode" as primaite.nodes.service_node.ServiceNode { services : Dict[str, Service] @@ -455,7 +455,7 @@ class "TrainingConfig" as primaite.config.training_config.TrainingConfig { sb3_output_verbose_level scanning : float seed : Optional[int] - service_patching_duration : int + service_fixing_duration : int session_type time_delay : int from_dict(config_dict: Dict[str, Any]) -> TrainingConfig diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index c561030a..12f60b63 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -244,7 +244,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE - - type: NODE_SERVICE_PATCH + - type: NODE_SERVICE_FIX - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -339,7 +339,7 @@ agents: folder_id: 0 file_id: 0 13: - action: "NODE_SERVICE_PATCH" + action: "NODE_SERVICE_FIX" options: node_id: 2 service_id: 0 diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index 85d282ba..b632f626 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -246,7 +246,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE - - type: NODE_SERVICE_PATCH + - type: NODE_SERVICE_FIX - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -341,7 +341,7 @@ agents: folder_id: 0 file_id: 0 13: - action: "NODE_SERVICE_PATCH" + action: "NODE_SERVICE_FIX" options: node_id: 2 service_id: 0 @@ -797,7 +797,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE - - type: NODE_SERVICE_PATCH + - type: NODE_SERVICE_FIX - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -892,7 +892,7 @@ agents: folder_id: 0 file_id: 0 13: - action: "NODE_SERVICE_PATCH" + action: "NODE_SERVICE_FIX" options: node_id: 2 service_id: 0 diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index bdb90b57..b79fc985 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -156,12 +156,12 @@ class NodeServiceEnableAction(NodeServiceAbstractAction): self.verb: str = "enable" -class NodeServicePatchAction(NodeServiceAbstractAction): - """Action which patches a service.""" +class NodeServiceFixAction(NodeServiceAbstractAction): + """Action which fixes a service.""" def __init__(self, manager: "ActionManager", num_nodes: int, num_services: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_services=num_services) - self.verb: str = "patch" + self.verb: str = "fix" class NodeApplicationAbstractAction(AbstractAction): @@ -216,7 +216,7 @@ class NodeApplicationFixAction(NodeApplicationAbstractAction): def __init__(self, manager: "ActionManager", num_nodes: int, num_applications: int, **kwargs) -> None: super().__init__(manager=manager, num_nodes=num_nodes, num_applications=num_applications) - self.verb: str = "patch" + self.verb: str = "fix" class NodeFolderAbstractAction(AbstractAction): @@ -653,7 +653,7 @@ class ActionManager: "NODE_SERVICE_RESTART": NodeServiceRestartAction, "NODE_SERVICE_DISABLE": NodeServiceDisableAction, "NODE_SERVICE_ENABLE": NodeServiceEnableAction, - "NODE_SERVICE_PATCH": NodeServicePatchAction, + "NODE_SERVICE_FIX": NodeServiceFixAction, "NODE_APPLICATION_EXECUTE": NodeApplicationExecuteAction, "NODE_APPLICATION_SCAN": NodeApplicationScanAction, "NODE_APPLICATION_CLOSE": NodeApplicationCloseAction, diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index c73132eb..411359a2 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -304,8 +304,8 @@ class DatabaseService(Service): self.backup_database() return super().apply_timestep(timestep) - def _update_patch_status(self) -> None: + def _update_fix_status(self) -> None: """Perform a database restore when the patching countdown is finished.""" - super()._update_patch_status() - if self._patching_countdown is None: + super()._update_fix_status() + if self._fixing_countdown is None: self.restore_backup() diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index d55f141f..9b54f802 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -82,7 +82,7 @@ class Software(SimComponent): "The health state of the software visible to the red agent." criticality: SoftwareCriticality = SoftwareCriticality.LOWEST "The criticality level of the software." - patching_count: int = 0 + fixing_count: int = 0 "The count of patches applied to the software, defaults to 0." scanning_count: int = 0 "The count of times the software has been scanned, defaults to 0." @@ -96,9 +96,9 @@ class Software(SimComponent): "The FileSystem of the Node the Software is installed on." folder: Optional[Folder] = None "The folder on the file system the Software uses." - patching_duration: int = 2 + fixing_duration: int = 2 "The number of ticks it takes to patch the software." - _patching_countdown: Optional[int] = None + _fixing_countdown: Optional[int] = None "Current number of ticks left to patch the software." def _init_request_manager(self) -> RequestManager: @@ -117,9 +117,9 @@ class Software(SimComponent): ), ) rm.add_request( - "patch", + "fix", RequestType( - func=lambda request, context: RequestResponse.from_bool(self.patch()), + func=lambda request, context: RequestResponse.from_bool(self.fix()), ), ) rm.add_request("scan", RequestType(func=lambda request, context: RequestResponse.from_bool(self.scan()))) @@ -149,7 +149,7 @@ class Software(SimComponent): "health_state_actual": self.health_state_actual.value, "health_state_visible": self.health_state_visible.value, "criticality": self.criticality.value, - "patching_count": self.patching_count, + "fixing_count": self.fixing_count, "scanning_count": self.scanning_count, "revealed_to_red": self.revealed_to_red, } @@ -194,21 +194,21 @@ class Software(SimComponent): self.health_state_visible = self.health_state_actual return True - def patch(self) -> bool: - """Perform a patch on the software.""" + def fix(self) -> bool: + """Perform a fix on the software.""" if self.health_state_actual in (SoftwareHealthState.COMPROMISED, SoftwareHealthState.GOOD): - self._patching_countdown = self.patching_duration + self._fixing_countdown = self.fixing_duration self.set_health_state(SoftwareHealthState.PATCHING) return True return False - def _update_patch_status(self) -> None: - """Update the patch status of the software.""" - self._patching_countdown -= 1 - if self._patching_countdown <= 0: + def _update_fix_status(self) -> None: + """Update the fix status of the software.""" + self._fixing_countdown -= 1 + if self._fixing_countdown <= 0: self.set_health_state(SoftwareHealthState.GOOD) - self._patching_countdown = None - self.patching_count += 1 + self._fixing_countdown = None + self.fixing_count += 1 def reveal_to_red(self) -> None: """Reveals the software to the red agent.""" @@ -222,7 +222,7 @@ class Software(SimComponent): """ super().apply_timestep(timestep) if self.health_state_actual == SoftwareHealthState.PATCHING: - self._update_patch_status() + self._update_fix_status() class IOSoftware(Software): diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 38d54ce3..e599ee7e 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -155,7 +155,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE - - type: NODE_SERVICE_PATCH + - type: NODE_SERVICE_FIX - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -250,7 +250,7 @@ agents: folder_id: 1 file_id: 0 13: - action: "NODE_SERVICE_PATCH" + action: "NODE_SERVICE_FIX" options: node_id: 2 service_id: 0 diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index f2815578..9d1404d8 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -159,7 +159,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE - - type: NODE_SERVICE_PATCH + - type: NODE_SERVICE_FIX - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -254,7 +254,7 @@ agents: folder_id: 1 file_id: 0 13: - action: "NODE_SERVICE_PATCH" + action: "NODE_SERVICE_FIX" options: node_id: 2 service_id: 0 diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 8bbddb76..acb62c96 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -166,7 +166,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE - - type: NODE_SERVICE_PATCH + - type: NODE_SERVICE_FIX - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -261,7 +261,7 @@ agents: folder_id: 1 file_id: 0 13: - action: "NODE_SERVICE_PATCH" + action: "NODE_SERVICE_FIX" options: node_id: 2 service_id: 0 @@ -610,7 +610,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE - - type: NODE_SERVICE_PATCH + - type: NODE_SERVICE_FIX - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -705,7 +705,7 @@ agents: folder_id: 1 file_id: 0 13: - action: "NODE_SERVICE_PATCH" + action: "NODE_SERVICE_FIX" options: node_id: 2 service_id: 0 diff --git a/tests/assets/configs/shared_rewards.yaml b/tests/assets/configs/shared_rewards.yaml index daffa585..10feba9d 100644 --- a/tests/assets/configs/shared_rewards.yaml +++ b/tests/assets/configs/shared_rewards.yaml @@ -244,7 +244,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE - - type: NODE_SERVICE_PATCH + - type: NODE_SERVICE_FIX - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -339,7 +339,7 @@ agents: folder_id: 0 file_id: 0 13: - action: "NODE_SERVICE_PATCH" + action: "NODE_SERVICE_FIX" options: node_id: 2 service_id: 0 diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 121cc7f1..a8b33032 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -169,7 +169,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE - - type: NODE_SERVICE_PATCH + - type: NODE_SERVICE_FIX - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -264,7 +264,7 @@ agents: folder_id: 1 file_id: 0 13: - action: "NODE_SERVICE_PATCH" + action: "NODE_SERVICE_FIX" options: node_id: 2 service_id: 0 diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index 71a23989..d0cbaab3 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -167,7 +167,7 @@ agents: - type: NODE_SERVICE_RESTART - type: NODE_SERVICE_DISABLE - type: NODE_SERVICE_ENABLE - - type: NODE_SERVICE_PATCH + - type: NODE_SERVICE_FIX - type: NODE_FILE_SCAN - type: NODE_FILE_CHECKHASH - type: NODE_FILE_DELETE @@ -262,7 +262,7 @@ agents: folder_id: 1 file_id: 0 13: - action: "NODE_SERVICE_PATCH" + action: "NODE_SERVICE_FIX" options: node_id: 2 service_id: 0 diff --git a/tests/assets/example_sb3_agent_session/session_metadata.json b/tests/assets/example_sb3_agent_session/session_metadata.json index c0968ba7..085e20cc 100644 --- a/tests/assets/example_sb3_agent_session/session_metadata.json +++ b/tests/assets/example_sb3_agent_session/session_metadata.json @@ -1 +1 @@ -{ "uuid": "301874d3-2e14-43c2-ba7f-e2b03ad05dde", "start_datetime": "2023-07-14T09:48:22.973005", "end_datetime": "2023-07-14T09:48:34.182715", "learning": { "total_episodes": 10, "total_time_steps": 2560 }, "evaluation": { "total_episodes": 5, "total_time_steps": 1280 }, "env": { "training_config": { "agent_framework": "SB3", "deep_learning_framework": "TF2", "agent_identifier": "PPO", "hard_coded_agent_view": "FULL", "random_red_agent": false, "action_type": "NODE", "num_train_episodes": 10, "num_train_steps": 256, "num_eval_episodes": 5, "num_eval_steps": 256, "checkpoint_every_n_episodes": 10, "observation_space": { "components": [ { "name": "NODE_LINK_TABLE" } ] }, "time_delay": 5, "session_type": "TRAIN_EVAL", "load_agent": false, "agent_load_file": null, "observation_space_high_value": 1000000000, "sb3_output_verbose_level": "NONE", "all_ok": 0, "off_should_be_on": -0.001, "off_should_be_resetting": -0.0005, "on_should_be_off": -0.0002, "on_should_be_resetting": -0.0005, "resetting_should_be_on": -0.0005, "resetting_should_be_off": -0.0002, "resetting": -0.0003, "good_should_be_patching": 0.0002, "good_should_be_compromised": 0.0005, "good_should_be_overwhelmed": 0.0005, "patching_should_be_good": -0.0005, "patching_should_be_compromised": 0.0002, "patching_should_be_overwhelmed": 0.0002, "patching": -0.0003, "compromised_should_be_good": -0.002, "compromised_should_be_patching": -0.002, "compromised_should_be_overwhelmed": -0.002, "compromised": -0.002, "overwhelmed_should_be_good": -0.002, "overwhelmed_should_be_patching": -0.002, "overwhelmed_should_be_compromised": -0.002, "overwhelmed": -0.002, "good_should_be_repairing": 0.0002, "good_should_be_restoring": 0.0002, "good_should_be_corrupt": 0.0005, "good_should_be_destroyed": 0.001, "repairing_should_be_good": -0.0005, "repairing_should_be_restoring": 0.0002, "repairing_should_be_corrupt": 0.0002, "repairing_should_be_destroyed": 0.0, "repairing": -0.0003, "restoring_should_be_good": -0.001, "restoring_should_be_repairing": -0.0002, "restoring_should_be_corrupt": 0.0001, "restoring_should_be_destroyed": 0.0002, "restoring": -0.0006, "corrupt_should_be_good": -0.001, "corrupt_should_be_repairing": -0.001, "corrupt_should_be_restoring": -0.001, "corrupt_should_be_destroyed": 0.0002, "corrupt": -0.001, "destroyed_should_be_good": -0.002, "destroyed_should_be_repairing": -0.002, "destroyed_should_be_restoring": -0.002, "destroyed_should_be_corrupt": -0.002, "destroyed": -0.002, "scanning": -0.0002, "red_ier_running": -0.0005, "green_ier_blocked": -0.001, "os_patching_duration": 5, "node_reset_duration": 5, "node_booting_duration": 3, "node_shutdown_duration": 2, "service_patching_duration": 5, "file_system_repairing_limit": 5, "file_system_restoring_limit": 5, "file_system_scanning_limit": 5, "deterministic": true, "seed": 12345 }, "lay_down_config": [ { "item_type": "PORTS", "ports_list": [ { "port": "80" } ] }, { "item_type": "SERVICES", "service_list": [ { "name": "TCP" } ] }, { "item_type": "NODE", "node_id": "1", "name": "PC1", "node_class": "SERVICE", "node_type": "COMPUTER", "priority": "P5", "hardware_state": "ON", "ip_address": "192.168.1.2", "software_state": "GOOD", "file_system_state": "GOOD", "services": [ { "name": "TCP", "port": "80", "state": "GOOD" } ] }, { "item_type": "NODE", "node_id": "2", "name": "PC2", "node_class": "SERVICE", "node_type": "COMPUTER", "priority": "P5", "hardware_state": "ON", "ip_address": "192.168.1.3", "software_state": "GOOD", "file_system_state": "GOOD", "services": [ { "name": "TCP", "port": "80", "state": "GOOD" } ] }, { "item_type": "NODE", "node_id": "3", "name": "SWITCH1", "node_class": "ACTIVE", "node_type": "SWITCH", "priority": "P2", "hardware_state": "ON", "ip_address": "192.168.1.1", "software_state": "GOOD", "file_system_state": "GOOD" }, { "item_type": "NODE", "node_id": "4", "name": "SERVER1", "node_class": "SERVICE", "node_type": "SERVER", "priority": "P5", "hardware_state": "ON", "ip_address": "192.168.1.4", "software_state": "GOOD", "file_system_state": "GOOD", "services": [ { "name": "TCP", "port": "80", "state": "GOOD" } ] }, { "item_type": "LINK", "id": "5", "name": "link1", "bandwidth": 1000000000, "source": "1", "destination": "3" }, { "item_type": "LINK", "id": "6", "name": "link2", "bandwidth": 1000000000, "source": "2", "destination": "3" }, { "item_type": "LINK", "id": "7", "name": "link3", "bandwidth": 1000000000, "source": "3", "destination": "4" }, { "item_type": "GREEN_IER", "id": "8", "start_step": 1, "end_step": 256, "load": 10000, "protocol": "TCP", "port": "80", "source": "1", "destination": "4", "mission_criticality": 1 }, { "item_type": "GREEN_IER", "id": "9", "start_step": 1, "end_step": 256, "load": 10000, "protocol": "TCP", "port": "80", "source": "2", "destination": "4", "mission_criticality": 1 }, { "item_type": "GREEN_IER", "id": "10", "start_step": 1, "end_step": 256, "load": 10000, "protocol": "TCP", "port": "80", "source": "4", "destination": "2", "mission_criticality": 5 }, { "item_type": "ACL_RULE", "id": "11", "permission": "ALLOW", "source": "192.168.1.2", "destination": "192.168.1.4", "protocol": "TCP", "port": 80, "position": 0 }, { "item_type": "ACL_RULE", "id": "12", "permission": "ALLOW", "source": "192.168.1.3", "destination": "192.168.1.4", "protocol": "TCP", "port": 80, "position": 1 }, { "item_type": "ACL_RULE", "id": "13", "permission": "ALLOW", "source": "192.168.1.4", "destination": "192.168.1.3", "protocol": "TCP", "port": 80, "position": 2 }, { "item_type": "RED_POL", "id": "14", "start_step": 20, "end_step": 20, "targetNodeId": "1", "initiator": "DIRECT", "type": "SERVICE", "protocol": "TCP", "state": "COMPROMISED", "sourceNodeId": "NA", "sourceNodeService": "NA", "sourceNodeServiceState": "NA" }, { "item_type": "RED_IER", "id": "15", "start_step": 30, "end_step": 256, "load": 10000000, "protocol": "TCP", "port": "80", "source": "1", "destination": "4", "mission_criticality": 0 }, { "item_type": "RED_POL", "id": "16", "start_step": 40, "end_step": 40, "targetNodeId": "4", "initiator": "IER", "type": "SERVICE", "protocol": "TCP", "state": "OVERWHELMED", "sourceNodeId": "NA", "sourceNodeService": "NA", "sourceNodeServiceState": "NA" } ] } } +{ "uuid": "301874d3-2e14-43c2-ba7f-e2b03ad05dde", "start_datetime": "2023-07-14T09:48:22.973005", "end_datetime": "2023-07-14T09:48:34.182715", "learning": { "total_episodes": 10, "total_time_steps": 2560 }, "evaluation": { "total_episodes": 5, "total_time_steps": 1280 }, "env": { "training_config": { "agent_framework": "SB3", "deep_learning_framework": "TF2", "agent_identifier": "PPO", "hard_coded_agent_view": "FULL", "random_red_agent": false, "action_type": "NODE", "num_train_episodes": 10, "num_train_steps": 256, "num_eval_episodes": 5, "num_eval_steps": 256, "checkpoint_every_n_episodes": 10, "observation_space": { "components": [ { "name": "NODE_LINK_TABLE" } ] }, "time_delay": 5, "session_type": "TRAIN_EVAL", "load_agent": false, "agent_load_file": null, "observation_space_high_value": 1000000000, "sb3_output_verbose_level": "NONE", "all_ok": 0, "off_should_be_on": -0.001, "off_should_be_resetting": -0.0005, "on_should_be_off": -0.0002, "on_should_be_resetting": -0.0005, "resetting_should_be_on": -0.0005, "resetting_should_be_off": -0.0002, "resetting": -0.0003, "good_should_be_patching": 0.0002, "good_should_be_compromised": 0.0005, "good_should_be_overwhelmed": 0.0005, "patching_should_be_good": -0.0005, "patching_should_be_compromised": 0.0002, "patching_should_be_overwhelmed": 0.0002, "patching": -0.0003, "compromised_should_be_good": -0.002, "compromised_should_be_patching": -0.002, "compromised_should_be_overwhelmed": -0.002, "compromised": -0.002, "overwhelmed_should_be_good": -0.002, "overwhelmed_should_be_patching": -0.002, "overwhelmed_should_be_compromised": -0.002, "overwhelmed": -0.002, "good_should_be_repairing": 0.0002, "good_should_be_restoring": 0.0002, "good_should_be_corrupt": 0.0005, "good_should_be_destroyed": 0.001, "repairing_should_be_good": -0.0005, "repairing_should_be_restoring": 0.0002, "repairing_should_be_corrupt": 0.0002, "repairing_should_be_destroyed": 0.0, "repairing": -0.0003, "restoring_should_be_good": -0.001, "restoring_should_be_repairing": -0.0002, "restoring_should_be_corrupt": 0.0001, "restoring_should_be_destroyed": 0.0002, "restoring": -0.0006, "corrupt_should_be_good": -0.001, "corrupt_should_be_repairing": -0.001, "corrupt_should_be_restoring": -0.001, "corrupt_should_be_destroyed": 0.0002, "corrupt": -0.001, "destroyed_should_be_good": -0.002, "destroyed_should_be_repairing": -0.002, "destroyed_should_be_restoring": -0.002, "destroyed_should_be_corrupt": -0.002, "destroyed": -0.002, "scanning": -0.0002, "red_ier_running": -0.0005, "green_ier_blocked": -0.001, "os_patching_duration": 5, "node_reset_duration": 5, "node_booting_duration": 3, "node_shutdown_duration": 2, "service_fixing_duration": 5, "file_system_repairing_limit": 5, "file_system_restoring_limit": 5, "file_system_scanning_limit": 5, "deterministic": true, "seed": 12345 }, "lay_down_config": [ { "item_type": "PORTS", "ports_list": [ { "port": "80" } ] }, { "item_type": "SERVICES", "service_list": [ { "name": "TCP" } ] }, { "item_type": "NODE", "node_id": "1", "name": "PC1", "node_class": "SERVICE", "node_type": "COMPUTER", "priority": "P5", "hardware_state": "ON", "ip_address": "192.168.1.2", "software_state": "GOOD", "file_system_state": "GOOD", "services": [ { "name": "TCP", "port": "80", "state": "GOOD" } ] }, { "item_type": "NODE", "node_id": "2", "name": "PC2", "node_class": "SERVICE", "node_type": "COMPUTER", "priority": "P5", "hardware_state": "ON", "ip_address": "192.168.1.3", "software_state": "GOOD", "file_system_state": "GOOD", "services": [ { "name": "TCP", "port": "80", "state": "GOOD" } ] }, { "item_type": "NODE", "node_id": "3", "name": "SWITCH1", "node_class": "ACTIVE", "node_type": "SWITCH", "priority": "P2", "hardware_state": "ON", "ip_address": "192.168.1.1", "software_state": "GOOD", "file_system_state": "GOOD" }, { "item_type": "NODE", "node_id": "4", "name": "SERVER1", "node_class": "SERVICE", "node_type": "SERVER", "priority": "P5", "hardware_state": "ON", "ip_address": "192.168.1.4", "software_state": "GOOD", "file_system_state": "GOOD", "services": [ { "name": "TCP", "port": "80", "state": "GOOD" } ] }, { "item_type": "LINK", "id": "5", "name": "link1", "bandwidth": 1000000000, "source": "1", "destination": "3" }, { "item_type": "LINK", "id": "6", "name": "link2", "bandwidth": 1000000000, "source": "2", "destination": "3" }, { "item_type": "LINK", "id": "7", "name": "link3", "bandwidth": 1000000000, "source": "3", "destination": "4" }, { "item_type": "GREEN_IER", "id": "8", "start_step": 1, "end_step": 256, "load": 10000, "protocol": "TCP", "port": "80", "source": "1", "destination": "4", "mission_criticality": 1 }, { "item_type": "GREEN_IER", "id": "9", "start_step": 1, "end_step": 256, "load": 10000, "protocol": "TCP", "port": "80", "source": "2", "destination": "4", "mission_criticality": 1 }, { "item_type": "GREEN_IER", "id": "10", "start_step": 1, "end_step": 256, "load": 10000, "protocol": "TCP", "port": "80", "source": "4", "destination": "2", "mission_criticality": 5 }, { "item_type": "ACL_RULE", "id": "11", "permission": "ALLOW", "source": "192.168.1.2", "destination": "192.168.1.4", "protocol": "TCP", "port": 80, "position": 0 }, { "item_type": "ACL_RULE", "id": "12", "permission": "ALLOW", "source": "192.168.1.3", "destination": "192.168.1.4", "protocol": "TCP", "port": 80, "position": 1 }, { "item_type": "ACL_RULE", "id": "13", "permission": "ALLOW", "source": "192.168.1.4", "destination": "192.168.1.3", "protocol": "TCP", "port": 80, "position": 2 }, { "item_type": "RED_POL", "id": "14", "start_step": 20, "end_step": 20, "targetNodeId": "1", "initiator": "DIRECT", "type": "SERVICE", "protocol": "TCP", "state": "COMPROMISED", "sourceNodeId": "NA", "sourceNodeService": "NA", "sourceNodeServiceState": "NA" }, { "item_type": "RED_IER", "id": "15", "start_step": 30, "end_step": 256, "load": 10000000, "protocol": "TCP", "port": "80", "source": "1", "destination": "4", "mission_criticality": 0 }, { "item_type": "RED_POL", "id": "16", "start_step": 40, "end_step": 40, "targetNodeId": "4", "initiator": "IER", "type": "SERVICE", "protocol": "TCP", "state": "OVERWHELMED", "sourceNodeId": "NA", "sourceNodeService": "NA", "sourceNodeServiceState": "NA" } ] } } diff --git a/tests/conftest.py b/tests/conftest.py index 9eaf1782..078a78bd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -475,7 +475,7 @@ def game_and_agent(): {"type": "NODE_SERVICE_RESTART"}, {"type": "NODE_SERVICE_DISABLE"}, {"type": "NODE_SERVICE_ENABLE"}, - {"type": "NODE_SERVICE_PATCH"}, + {"type": "NODE_SERVICE_FIX"}, {"type": "NODE_APPLICATION_EXECUTE"}, {"type": "NODE_APPLICATION_SCAN"}, {"type": "NODE_APPLICATION_CLOSE"}, diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 98e6ea5d..5aa93e27 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -65,9 +65,9 @@ def test_node_service_scan_integration(game_and_agent: Tuple[PrimaiteGame, Proxy assert svc.health_state_visible == SoftwareHealthState.COMPROMISED -def test_node_service_patch_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): +def test_node_service_fix_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): """ - Test that the NodeServicePatchAction can form a request and that it is accepted by the simulation. + Test that the NodeServiceFixAction can form a request and that it is accepted by the simulation. When you initiate a patch action, the software health state turns to PATCHING, then after a few steps, it goes to GOOD. @@ -79,7 +79,7 @@ def test_node_service_patch_integration(game_and_agent: Tuple[PrimaiteGame, Prox svc.health_state_actual = SoftwareHealthState.COMPROMISED # 2: Apply a patch action - action = ("NODE_SERVICE_PATCH", {"node_id": 1, "service_id": 0}) + action = ("NODE_SERVICE_FIX", {"node_id": 1, "service_id": 0}) agent.store_action(action) game.step() diff --git a/tests/integration_tests/test_simulation/test_request_response.py b/tests/integration_tests/test_simulation/test_request_response.py index aee5c816..5df04fbb 100644 --- a/tests/integration_tests/test_simulation/test_request_response.py +++ b/tests/integration_tests/test_simulation/test_request_response.py @@ -23,7 +23,7 @@ def test_successful_application_requests(example_network): resp_1 = net.apply_request(["node", "client_1", "application", "TestApplication", "scan"]) assert resp_1 == RequestResponse(status="success", data={}) - resp_2 = net.apply_request(["node", "client_1", "application", "TestApplication", "patch"]) + resp_2 = net.apply_request(["node", "client_1", "application", "TestApplication", "fix"]) assert resp_2 == RequestResponse(status="success", data={}) resp_3 = net.apply_request(["node", "client_1", "application", "TestApplication", "compromise"]) assert resp_3 == RequestResponse(status="success", data={}) @@ -46,7 +46,7 @@ def test_successful_service_requests(example_network): "resume", "compromise", "scan", - "patch", + "fix", ]: resp_1 = net.apply_request(["node", "server_1", "service", "TestService", verb]) assert resp_1 == RequestResponse(status="success", data={}) diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_applications.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_applications.py index 6247a100..fbdd9bef 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_applications.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_applications.py @@ -46,5 +46,5 @@ def test_application_describe_states(application): application.set_health_state(SoftwareHealthState.COMPROMISED) assert SoftwareHealthState.COMPROMISED.value == application.describe_state().get("health_state_actual") - application.patch() + application.fix() assert SoftwareHealthState.PATCHING.value == application.describe_state().get("health_state_actual") diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py index 5f10ec96..b9b43b25 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py @@ -99,8 +99,6 @@ def test_query_when_client_is_closed(database_client_on_computer): assert database_client.query(sql="test") is False - -def test_query_fail_to_connect(database_client_on_computer): """Database client query should return False if the connect attempt fails.""" database_client, computer = database_client_on_computer diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py index 714644e4..dd2d7752 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py @@ -80,12 +80,12 @@ def test_service_enable(service): assert service.operating_state == ServiceOperatingState.STOPPED -def test_service_patch(service): - """Test that a service can be patched and that it takes two timesteps to complete.""" +def test_service_fix(service): + """Test that a service can be fixed and that it takes two timesteps to complete.""" service.start() assert service.health_state_actual == SoftwareHealthState.GOOD - service.apply_request(["patch"]) + service.apply_request(["fix"]) assert service.health_state_actual == SoftwareHealthState.PATCHING service.apply_timestep(1) assert service.health_state_actual == SoftwareHealthState.PATCHING diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py index ac36c660..59d9499b 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py @@ -136,16 +136,16 @@ def test_compromised_service_remains_compromised(service): assert service.health_state_actual == SoftwareHealthState.COMPROMISED -def test_service_patching(service): +def test_service_fixing(service): service.start() assert service.health_state_actual == SoftwareHealthState.GOOD service.set_health_state(SoftwareHealthState.COMPROMISED) - service.patch() + service.fix() assert service.health_state_actual == SoftwareHealthState.PATCHING - for i in range(service.patching_duration + 1): + for i in range(service.fixing_duration + 1): service.apply_timestep(i) assert service.health_state_actual == SoftwareHealthState.GOOD From e5605296391dcec5b8ffab1a15e8a31d6452fb8c Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Mar 2024 12:06:23 +0000 Subject: [PATCH 738/980] #2418 Add Printer and Wireless router to config parser --- src/primaite/game/game.py | 15 +++++++++++++-- .../network/hardware/nodes/host/server.py | 6 ++++++ tests/assets/configs/test_primaite_session.yaml | 6 ++++++ .../test_primaite_session.py | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 05b76679..6ba7e63c 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -15,10 +15,11 @@ from primaite.game.science import graph_has_cycle, topological_sort from primaite.simulator.network.hardware.base import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC -from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.host.server import Printer, Server from primaite.simulator.network.hardware.nodes.network.firewall import Firewall from primaite.simulator.network.hardware.nodes.network.router import Router from primaite.simulator.network.hardware.nodes.network.switch import Switch +from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter from primaite.simulator.network.nmne import set_nmne_config from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.sim_container import Simulation @@ -273,8 +274,18 @@ class PrimaiteGame: new_node = Router.from_config(node_cfg) elif n_type == "firewall": new_node = Firewall.from_config(node_cfg) + elif n_type == "wireless_router": + new_node = WirelessRouter.from_config(node_cfg) + elif n_type == "printer": + new_node = Printer( + hostname=node_cfg["hostname"], + ip_address=node_cfg["ip_address"], + subnet_mask=node_cfg["subnet_mask"], + ) else: - _LOGGER.warning(f"invalid node type {n_type} in config") + msg = f"invalid node type {n_type} in config" + _LOGGER.error(msg) + raise ValueError(msg) if "services" in node_cfg: for service_cfg in node_cfg["services"]: new_service = None diff --git a/src/primaite/simulator/network/hardware/nodes/host/server.py b/src/primaite/simulator/network/hardware/nodes/host/server.py index 9f5157ad..593cd0dd 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/server.py +++ b/src/primaite/simulator/network/hardware/nodes/host/server.py @@ -28,3 +28,9 @@ class Server(HostNode): * Applications: * Web Browser """ + + +class Printer(HostNode): + """Printer? I don't even know her!.""" + + # TODO: Implement printer-specific behaviour diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 121cc7f1..f4ae4783 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -681,6 +681,12 @@ simulation: - ref: client_2_dns_client type: DNSClient + - ref: HP_LaserJet_Pro_4102fdn_printer + type: printer + hostname: HP_LaserJet_Pro_4102fdn_printer + ip_address: 192.168.10.99 + subnet_mask: 255.255.255.0 + links: - ref: router_1___switch_1 endpoint_a_ref: router_1 diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index c45a4690..7febe39a 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -29,7 +29,7 @@ class TestPrimaiteSession: assert session.env assert session.env.game.simulation.network - assert len(session.env.game.simulation.network.nodes) == 10 + assert len(session.env.game.simulation.network.nodes) == 11 @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) From 128e2227d6068dd642c66893638d48b33c2d6b0d Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Tue, 26 Mar 2024 12:39:11 +0000 Subject: [PATCH 739/980] #2404 add missing test and revert some name changes --- benchmark/config/benchmark_training_config.yaml | 2 +- .../results/v2.0.0/v2.0.0_benchmark_metadata.json | 2 +- .../simulator/system/applications/application.py | 2 +- .../_system/_applications/test_database_client.py | 13 +++++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/benchmark/config/benchmark_training_config.yaml b/benchmark/config/benchmark_training_config.yaml index 17811586..02b6377c 100644 --- a/benchmark/config/benchmark_training_config.yaml +++ b/benchmark/config/benchmark_training_config.yaml @@ -158,7 +158,7 @@ green_ier_blocked: -0.001 # Patching / Reset durations os_patching_duration: 5 # The time taken to patch the OS node_reset_duration: 5 # The time taken to reset a node (hardware) -service_fixing_duration: 5 # The time taken to patch a service +service_patching_duration: 5 # The time taken to patch a service file_system_repairing_limit: 5 # The time take to repair the file system file_system_restoring_limit: 5 # The time take to restore the file system file_system_scanning_limit: 5 # The time taken to scan the file system diff --git a/benchmark/results/v2.0.0/v2.0.0_benchmark_metadata.json b/benchmark/results/v2.0.0/v2.0.0_benchmark_metadata.json index 3ed57745..b2745967 100644 --- a/benchmark/results/v2.0.0/v2.0.0_benchmark_metadata.json +++ b/benchmark/results/v2.0.0/v2.0.0_benchmark_metadata.json @@ -5634,7 +5634,7 @@ "green_ier_blocked": -0.001, "os_patching_duration": 5, "node_reset_duration": 5, - "service_fixing_duration": 5, + "service_patching_duration": 5, "file_system_repairing_limit": 5, "file_system_restoring_limit": 5, "file_system_scanning_limit": 5 diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 4ea893e0..617fdc23 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -117,7 +117,7 @@ class Application(IOSoftware): """The main application loop.""" pass - def close(self) -> None: + def close(self) -> bool: """Close the Application.""" if self.operating_state == ApplicationOperatingState.RUNNING: self.sys_log.info(f"Closed Application{self.name}") diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py index b9b43b25..5098fcde 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py @@ -111,6 +111,19 @@ def test_query_when_client_is_closed(database_client_on_computer): assert database_client.query(sql="test") is False +def test_query_fail_to_connect(database_client_on_computer): + """Database client query should return False if the connect attempt fails.""" + database_client, computer = database_client_on_computer + + def return_false(): + return False + + database_client.connect = return_false + database_client.connected = False + + assert database_client.query(sql="test") is False + + def test_client_receives_response_when_closed(database_client_on_computer): """Database client receive should return False when it is closed.""" database_client, computer = database_client_on_computer From 53126e79dfe793547be0f34826a2f1e88cb7d7ab Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Tue, 26 Mar 2024 12:43:45 +0000 Subject: [PATCH 740/980] #2404 remove extra code in test_query_when_client_is_closed --- .../_system/_applications/test_database_client.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py index 5098fcde..5f10ec96 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py @@ -99,17 +99,6 @@ def test_query_when_client_is_closed(database_client_on_computer): assert database_client.query(sql="test") is False - """Database client query should return False if the connect attempt fails.""" - database_client, computer = database_client_on_computer - - def return_false(): - return False - - database_client.connect = return_false - database_client.connected = False - - assert database_client.query(sql="test") is False - def test_query_fail_to_connect(database_client_on_computer): """Database client query should return False if the connect attempt fails.""" From b3c1b6b7a5e40ac1a06d9b896d89fadd8f39604c Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Tue, 26 Mar 2024 12:52:16 +0000 Subject: [PATCH 741/980] #2404 quick fix for failing test_query_fail_to_connect --- .../_simulator/_system/_applications/test_database_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py index 5f10ec96..4d964fa1 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_database_client.py @@ -104,7 +104,7 @@ def test_query_fail_to_connect(database_client_on_computer): """Database client query should return False if the connect attempt fails.""" database_client, computer = database_client_on_computer - def return_false(): + def return_false(**kwargs): return False database_client.connect = return_false From dca26b832db8a0674a87df4409eab286c5362890 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Mar 2024 13:21:22 +0000 Subject: [PATCH 742/980] #2418 Fix wireless router from config --- .../network/hardware/nodes/network/router.py | 2 +- .../hardware/nodes/network/wireless_router.py | 69 ++++++++++++++++++- .../assets/configs/test_primaite_session.yaml | 27 ++++++++ .../test_primaite_session.py | 9 ++- 4 files changed, 103 insertions(+), 4 deletions(-) diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index d2b47c1a..de308547 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1418,7 +1418,7 @@ class Router(NetworkNode): :return: Configured router. :rtype: Router """ - router = Router( + router = cls( hostname=cfg["hostname"], num_ports=int(cfg.get("num_ports", "5")), operating_state=NodeOperatingState.ON diff --git a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py index 3e8d715f..4bd3d101 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py @@ -1,10 +1,14 @@ +from ipaddress import IPv4Address from typing import Any, Dict, Union from pydantic import validate_call from primaite.simulator.network.airspace import AirSpaceFrequency, IPWirelessNetworkInterface -from primaite.simulator.network.hardware.nodes.network.router import Router, RouterInterface +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router, RouterInterface from primaite.simulator.network.transmission.data_link_layer import Frame +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port from primaite.utils.validators import IPV4Address @@ -209,3 +213,66 @@ class WirelessRouter(Router): raise NotImplementedError( "Please use the 'configure_wireless_access_point' and 'configure_router_interface' functions." ) + + @classmethod + def from_config(cls, cfg: Dict) -> "WirelessRouter": + """Generate the wireless router from config. + + Schema: + - hostname (str): unique name for this router. + - router_interface (dict): The values should be another dict specifying + - ip_address (str) + - subnet_mask (str) + - wireless_access_point (dict): Dict with + - ip address, + - subnet mask, + - frequency, (string: either WIFI_2_4 or WIFI_5) + - acl (dict): Dict with integers from 1 - max_acl_rules as keys. The key defines the position within the ACL + where the rule will be added (lower number is resolved first). The values should describe valid ACL + Rules as: + - action (str): either PERMIT or DENY + - src_port (str, optional): the named port such as HTTP, HTTPS, or POSTGRES_SERVER + - dst_port (str, optional): the named port such as HTTP, HTTPS, or POSTGRES_SERVER + - protocol (str, optional): the named IP protocol such as ICMP, TCP, or UDP + - src_ip_address (str, optional): IP address octet written in base 10 + - dst_ip_address (str, optional): IP address octet written in base 10 + + :param cfg: Config dictionary + :type cfg: Dict + :return: WirelessRouter instance. + :rtype: WirelessRouter + """ + operating_state = ( + NodeOperatingState.ON if not (p := cfg.get("operating_state")) else NodeOperatingState[p.upper()] + ) + router = cls(hostname=cfg["hostname"], operating_state=operating_state) + if "router_interface" in cfg: + ip_address = cfg["router_interface"]["ip_address"] + subnet_mask = cfg["router_interface"]["subnet_mask"] + router.configure_router_interface(ip_address=ip_address, subnet_mask=subnet_mask) + if "wireless_access_point" in cfg: + ip_address = cfg["wireless_access_point"]["ip_address"] + subnet_mask = cfg["wireless_access_point"]["subnet_mask"] + frequency = AirSpaceFrequency[cfg["wireless_access_point"]["frequency"]] + router.configure_wireless_access_point(ip_address=ip_address, subnet_mask=subnet_mask, frequency=frequency) + + if "acl" in cfg: + for r_num, r_cfg in cfg["acl"].items(): + router.acl.add_rule( + action=ACLAction[r_cfg["action"]], + src_port=None if not (p := r_cfg.get("src_port")) else Port[p], + dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], + protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], + src_ip_address=r_cfg.get("src_ip"), + dst_ip_address=r_cfg.get("dst_ip"), + position=r_num, + ) + if "routes" in cfg: + for route in cfg.get("routes"): + router.route_table.add_route( + address=IPv4Address(route.get("address")), + subnet_mask=IPv4Address(route.get("subnet_mask", "255.255.255.0")), + next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")), + metric=float(route.get("metric", 0)), + ) + return router diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index f4ae4783..11db08a7 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -687,6 +687,33 @@ simulation: ip_address: 192.168.10.99 subnet_mask: 255.255.255.0 + - ref: router_2 + type: wireless_router + hostname: router_2 + router_interface: + ip_address: 192.169.1.1 + subnet_mask: 255.255.255.0 + wireless_access_point: + ip_address: 192.169.1.1 + subnet_mask: 255.255.255.0 + frequency: WIFI_2_4 + acl: + 0: + action: PERMIT + src_port: POSTGRES_SERVER + dst_port: POSTGRES_SERVER + 1: + action: PERMIT + src_port: DNS + dst_port: DNS + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + links: - ref: router_1___switch_1 endpoint_a_ref: router_1 diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index 7febe39a..32f134a3 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -1,6 +1,8 @@ import pydantic import pytest +from primaite.simulator.network.hardware.nodes.host.server import Printer +from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter from tests import TEST_ASSETS_ROOT from tests.conftest import TempPrimaiteSession @@ -11,7 +13,6 @@ MISCONFIGURED_PATH = TEST_ASSETS_ROOT / "configs/bad_primaite_session.yaml" MULTI_AGENT_PATH = TEST_ASSETS_ROOT / "configs/multi_agent_session.yaml" -# @pytest.mark.skip(reason="no way of currently testing this") class TestPrimaiteSession: @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) def test_creating_session(self, temp_primaite_session): @@ -29,7 +30,11 @@ class TestPrimaiteSession: assert session.env assert session.env.game.simulation.network - assert len(session.env.game.simulation.network.nodes) == 11 + assert len(session.env.game.simulation.network.nodes) == 12 + wireless = session.env.game.simulation.network.get_node_by_hostname("router_2") + assert isinstance(wireless, WirelessRouter) + printer = session.env.game.simulation.network.get_node_by_hostname("HP_LaserJet_Pro_4102fdn_printer") + assert isinstance(printer, Printer) @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) From 0e90e6a262024a81411fc332c2fbd1767604831b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Mar 2024 16:23:39 +0000 Subject: [PATCH 743/980] #2418 - Change test config --- tests/assets/configs/test_primaite_session.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 11db08a7..4adbb225 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -694,7 +694,7 @@ simulation: ip_address: 192.169.1.1 subnet_mask: 255.255.255.0 wireless_access_point: - ip_address: 192.169.1.1 + ip_address: 192.170.1.1 subnet_mask: 255.255.255.0 frequency: WIFI_2_4 acl: From 5860c74ef97c7378a78ad2f1e2f3a13a99b0bccf Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Tue, 26 Mar 2024 16:41:11 +0000 Subject: [PATCH 744/980] #2404 change software state from patching to fixing to align with CAOS v0.8 --- docs/source/about.rst | 22 +++++++++---------- .../Data-Manipulation-E2E-Demonstration.ipynb | 2 +- .../services/database/database_service.py | 2 +- src/primaite/simulator/system/software.py | 8 +++---- .../game_layer/test_actions.py | 12 +++++----- .../_applications/test_applications.py | 2 +- .../_system/_services/test_service_actions.py | 4 ++-- .../_system/_services/test_services.py | 4 ++-- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/docs/source/about.rst b/docs/source/about.rst index 3f905933..782103d6 100644 --- a/docs/source/about.rst +++ b/docs/source/about.rst @@ -41,11 +41,11 @@ The game layer is built on top of the simulator and it consumes the simulation a * Hardware State (ON, OFF, RESETTING, SHUTTING_DOWN, BOOTING - enumeration) Active Nodes also have the following attributes (Class: Active Node): * IP Address - * Software State (GOOD, PATCHING, COMPROMISED - enumeration) + * Software State (GOOD, FIXING, COMPROMISED - enumeration) * File System State (GOOD, CORRUPT, DESTROYED, REPAIRING, RESTORING - enumeration) Service Nodes also have the following attributes (Class: Service Node): * List of Services (where service is composed of service name and port). There is no theoretical limit on the number of services that can be modelled. Services and protocols are currently intrinsically linked (i.e. a service is an application on a node transmitting traffic of this protocol type) - * Service state (GOOD, PATCHING, COMPROMISED, OVERWHELMED - enumeration) + * Service state (GOOD, FIXING, COMPROMISED, OVERWHELMED - enumeration) Passive Nodes are currently not used (but may be employed for non IP-based components such as machinery actuators in future releases). **Links** Links are modelled both as network edges (networkx) and as Python classes, in order to extend their functionality. Links include the following attributes: @@ -70,8 +70,8 @@ The game layer is built on top of the simulator and it consumes the simulation a * Running status (i.e. on / off) The application of green agent IERs between a source and destination follows a number of rules. Specifically: 1. Does the current simulation time step fall between IER start and end step - 2. Is the source node operational (both physically and at an O/S level), and is the service (protocol / port) associated with the IER (a) present on this node, and (b) in an operational state (i.e. not PATCHING) - 3. Is the destination node operational (both physically and at an O/S level), and is the service (protocol / port) associated with the IER (a) present on this node, and (b) in an operational state (i.e. not PATCHING) + 2. Is the source node operational (both physically and at an O/S level), and is the service (protocol / port) associated with the IER (a) present on this node, and (b) in an operational state (i.e. not FIXING) + 3. Is the destination node operational (both physically and at an O/S level), and is the service (protocol / port) associated with the IER (a) present on this node, and (b) in an operational state (i.e. not FIXING) 4. Are there any Access Control List rules in place that prevent the application of this IER 5. Are all switches in the (OSPF) path between source and destination operational (both physically and at an O/S level) For red agent IERs, the application of IERs between a source and destination follows a number of subtly different rules. Specifically: @@ -95,7 +95,7 @@ The game layer is built on top of the simulator and it consumes the simulation a * Active Nodes and Service Nodes: * Software State: * GOOD - * PATCHING - when a status of patching is entered, the node will automatically exit this state after a number of steps (as defined by the osPatchingDuration configuration item) after which it returns to a GOOD state + * FIXING - when a status of FIXING is entered, the node will automatically exit this state after a number of steps (as defined by the osFIXINGDuration configuration item) after which it returns to a GOOD state * COMPROMISED * File System State: * GOOD @@ -106,7 +106,7 @@ The game layer is built on top of the simulator and it consumes the simulation a * Service Nodes only: * Service State (for any associated service): * GOOD - * PATCHING - when a status of patching is entered, the service will automatically exit this state after a number of steps (as defined by the servicePatchingDuration configuration item) after which it returns to a GOOD state + * FIXING - when a status of FIXING is entered, the service will automatically exit this state after a number of steps (as defined by the serviceFIXINGDuration configuration item) after which it returns to a GOOD state * COMPROMISED * OVERWHELMED Red agent pattern-of-life has an additional feature not found in the green pattern-of-life. This is the ability to influence the state of the attributes of a node via a number of different conditions: @@ -211,8 +211,8 @@ The game layer is built on top of the simulator and it consumes the simulation a Hardware State (1=ON, 2=OFF, 3=RESETTING, 4=SHUTTING_DOWN, 5=BOOTING) Operating System State (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) File System State (0=none, 1=GOOD, 2=CORRUPT, 3=DESTROYED, 4=REPAIRING, 5=RESTORING) - Service1/Protocol1 state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) - Service2/Protocol2 state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) + Service1/Protocol1 state (0=none, 1=GOOD, 2=FIXING, 3=COMPROMISED) + Service2/Protocol2 state (0=none, 1=GOOD, 2=FIXING, 3=COMPROMISED) ] (Note that each service available in the network is provided as a column, although not all nodes may utilise all services) For the links, the following statuses are represented: @@ -241,8 +241,8 @@ The game layer is built on top of the simulator and it consumes the simulation a hardware_state (0=none, 1=ON, 2=OFF, 3=RESETTING, 4=SHUTTING_DOWN, 5=BOOTING) software_state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) file_system_state (0=none, 1=GOOD, 2=CORRUPT, 3=DESTROYED, 4=REPAIRING, 5=RESTORING) - service1_state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) - service2_state (0=none, 1=GOOD, 2=PATCHING, 3=COMPROMISED) + service1_state (0=none, 1=GOOD, 2=FIXING, 3=COMPROMISED) + service2_state (0=none, 1=GOOD, 2=FIXING, 3=COMPROMISED) ] In a network with three nodes and two services, the full observation space would have 15 elements. It can be written with ``gym`` notation to indicate the number of discrete options for each of the elements of the observation space. For example: .. code-block:: @@ -278,7 +278,7 @@ The game layer is built on top of the simulator and it consumes the simulation a 3. Any (Agent can take both node-based and ACL-based actions) The choice of action space used during a training session is determined in the config_[name].yaml file. **Node-Based** - The agent is able to influence the status of nodes by switching them off, resetting, or patching operating systems and services. In this instance, the action space is a Gymnasium spaces.Discrete type, as follows: + The agent is able to influence the status of nodes by switching them off, resetting, or FIXING operating systems and services. In this instance, the action space is a Gymnasium spaces.Discrete type, as follows: * Dictionary item {... ,1: [x1, x2, x3,x4] ...} The placeholders inside the list under the key '1' mean the following: * [0, num nodes] - Node ID (0 = nothing, node ID) diff --git a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb index 7ec58b2c..ebe0f329 100644 --- a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb @@ -520,7 +520,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The patching takes two steps, so the reward hasn't changed yet. Let's do nothing for another timestep, the reward should improve.\n", + "The fixing takes two steps, so the reward hasn't changed yet. Let's do nothing for another timestep, the reward should improve.\n", "\n", "The reward will increase slightly as soon as the file finishes restoring. Then, the reward will increase to 1 when both green agents make successful requests.\n", "\n", diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 411359a2..541a15c2 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -305,7 +305,7 @@ class DatabaseService(Service): return super().apply_timestep(timestep) def _update_fix_status(self) -> None: - """Perform a database restore when the patching countdown is finished.""" + """Perform a database restore when the FIXING countdown is finished.""" super()._update_fix_status() if self._fixing_countdown is None: self.restore_backup() diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 9b54f802..ab60adde 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -43,8 +43,8 @@ class SoftwareHealthState(Enum): "Unused state." GOOD = 1 "The software is in a good and healthy condition." - PATCHING = 2 - "The software is undergoing patching or updates." + FIXING = 2 + "The software is undergoing FIXING or updates." COMPROMISED = 3 "The software's security has been compromised." OVERWHELMED = 4 @@ -198,7 +198,7 @@ class Software(SimComponent): """Perform a fix on the software.""" if self.health_state_actual in (SoftwareHealthState.COMPROMISED, SoftwareHealthState.GOOD): self._fixing_countdown = self.fixing_duration - self.set_health_state(SoftwareHealthState.PATCHING) + self.set_health_state(SoftwareHealthState.FIXING) return True return False @@ -221,7 +221,7 @@ class Software(SimComponent): :param timestep: The current timestep of the simulation. """ super().apply_timestep(timestep) - if self.health_state_actual == SoftwareHealthState.PATCHING: + if self.health_state_actual == SoftwareHealthState.FIXING: self._update_fix_status() diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 5aa93e27..b3a52cd8 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -69,7 +69,7 @@ def test_node_service_fix_integration(game_and_agent: Tuple[PrimaiteGame, ProxyA """ Test that the NodeServiceFixAction can form a request and that it is accepted by the simulation. - When you initiate a patch action, the software health state turns to PATCHING, then after a few steps, it goes + When you initiate a patch action, the software health state turns to FIXING, then after a few steps, it goes to GOOD. """ game, agent = game_and_agent @@ -83,8 +83,8 @@ def test_node_service_fix_integration(game_and_agent: Tuple[PrimaiteGame, ProxyA agent.store_action(action) game.step() - # 3: Check that the service is now in the patching state - assert svc.health_state_actual == SoftwareHealthState.PATCHING + # 3: Check that the service is now in the FIXING state + assert svc.health_state_actual == SoftwareHealthState.FIXING # 4: perform a few do-nothing steps and check that the service is now in the good state action = ("DONOTHING", {}) @@ -413,7 +413,7 @@ def test_node_application_scan_integration(game_and_agent: Tuple[PrimaiteGame, P def test_node_application_fix_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): """Test that the NodeApplicationFixAction can form a request and that it is accepted by the simulation. - When you initiate a fix action, the software health state turns to PATCHING, then after a few steps, it goes + When you initiate a fix action, the software health state turns to FIXING, then after a few steps, it goes to GOOD.""" game, agent = game_and_agent @@ -428,8 +428,8 @@ def test_node_application_fix_integration(game_and_agent: Tuple[PrimaiteGame, Pr agent.store_action(action) game.step() - # 3: Check that the application is now in the patching state - assert browser.health_state_actual == SoftwareHealthState.PATCHING + # 3: Check that the application is now in the FIXING state + assert browser.health_state_actual == SoftwareHealthState.FIXING # 4: perform a few do-nothing steps and check that the application is now in the good state action = ("DONOTHING", {}) diff --git a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_applications.py b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_applications.py index fbdd9bef..90c3f303 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_applications/test_applications.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_applications/test_applications.py @@ -47,4 +47,4 @@ def test_application_describe_states(application): assert SoftwareHealthState.COMPROMISED.value == application.describe_state().get("health_state_actual") application.fix() - assert SoftwareHealthState.PATCHING.value == application.describe_state().get("health_state_actual") + assert SoftwareHealthState.FIXING.value == application.describe_state().get("health_state_actual") diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py index dd2d7752..edc111e3 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_service_actions.py @@ -86,8 +86,8 @@ def test_service_fix(service): assert service.health_state_actual == SoftwareHealthState.GOOD service.apply_request(["fix"]) - assert service.health_state_actual == SoftwareHealthState.PATCHING + assert service.health_state_actual == SoftwareHealthState.FIXING service.apply_timestep(1) - assert service.health_state_actual == SoftwareHealthState.PATCHING + assert service.health_state_actual == SoftwareHealthState.FIXING service.apply_timestep(2) assert service.health_state_actual == SoftwareHealthState.GOOD diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py index 59d9499b..4deeef74 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_services.py @@ -93,7 +93,7 @@ def test_restart_compromised(service): """ Service should be compromised even after reset. - Only way to remove compromised status is via patching. + Only way to remove compromised status is via FIXING. """ timestep = 0 @@ -143,7 +143,7 @@ def test_service_fixing(service): service.set_health_state(SoftwareHealthState.COMPROMISED) service.fix() - assert service.health_state_actual == SoftwareHealthState.PATCHING + assert service.health_state_actual == SoftwareHealthState.FIXING for i in range(service.fixing_duration + 1): service.apply_timestep(i) From 94e637375d73c830435bdebfcc63dabe46a16143 Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Tue, 26 Mar 2024 17:02:51 +0000 Subject: [PATCH 745/980] #2404 update software state to fixing in UC2 e2e notebook [skip ci] --- .../notebooks/Data-Manipulation-E2E-Demonstration.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb index ebe0f329..60d40f9c 100644 --- a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb @@ -208,7 +208,7 @@ "|--|--|\n", "|0|UNUSED|\n", "|1|GOOD|\n", - "|2|PATCHING|\n", + "|2|FIXING|\n", "|3|COMPROMISED|\n", "|4|OVERWHELMED|\n", "\n", From 9a8a42f3ecf8ee57b09de465d26e91b494e98c73 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Mar 2024 21:48:17 +0000 Subject: [PATCH 746/980] #2418 - add wildcard masks and from_config tests to routers --- .../network/hardware/nodes/network/router.py | 2 + .../hardware/nodes/network/wireless_router.py | 2 + .../_network/_hardware/nodes/test_router.py | 111 ++++++++++++++++++ .../_hardware/nodes/test_wireless_router.py | 97 +++++++++++++++ 4 files changed, 212 insertions(+) create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_wireless_router.py diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index de308547..102eb7dc 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1441,6 +1441,8 @@ class Router(NetworkNode): protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], src_ip_address=r_cfg.get("src_ip"), dst_ip_address=r_cfg.get("dst_ip"), + src_wildcard_mask=r_cfg.get("src_wildcard_mask"), + dst_wildcard_mask=r_cfg.get("dst_wildcard_mask"), position=r_num, ) if "routes" in cfg: diff --git a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py index 4bd3d101..62332269 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py @@ -265,6 +265,8 @@ class WirelessRouter(Router): protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], src_ip_address=r_cfg.get("src_ip"), dst_ip_address=r_cfg.get("dst_ip"), + src_wildcard_mask=r_cfg.get("src_wildcard_mask"), + dst_wildcard_mask=r_cfg.get("dst_wildcard_mask"), position=r_num, ) if "routes" in cfg: diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py new file mode 100644 index 00000000..be74a721 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py @@ -0,0 +1,111 @@ +from ipaddress import IPv4Address + +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port + + +def test_wireless_router_from_config(): + cfg = { + "ref": "router_1", + "type": "router", + "hostname": "router_1", + "num_ports": 6, + "ports": { + 1: { + "ip_address": "192.168.1.1", + "subnet_mask": "255.255.255.0", + }, + 2: { + "ip_address": "192.168.2.1", + "subnet_mask": "255.255.255.0", + }, + }, + "acl": { + 0: { + "action": "PERMIT", + "src_port": "POSTGRES_SERVER", + "dst_port": "POSTGRES_SERVER", + }, + 1: { + "action": "PERMIT", + "protocol": "ICMP", + }, + 2: { + "action": "PERMIT", + "src_ip": "100.100.100.1", + "dst_ip": "100.100.101.1", + }, + 3: { + "action": "PERMIT", + "src_ip": "100.100.102.0", + "dst_ip": "100.100.103.0", + "src_wildcard_mask": "0.0.0.255", + "dst_wildcard_mask": "0.0.0.255", + }, + 20: { + "action": "DENY", + }, + }, + } + + rt = Router.from_config(cfg=cfg) + + assert rt.num_ports == 6 + + assert rt.network_interface[1].ip_address == IPv4Address("192.168.1.1") + assert rt.network_interface[1].subnet_mask == IPv4Address("255.255.255.0") + + assert rt.network_interface[2].ip_address == IPv4Address("192.168.2.1") + assert rt.network_interface[2].subnet_mask == IPv4Address("255.255.255.0") + + assert not rt.network_interface[3].enabled + assert not rt.network_interface[4].enabled + assert not rt.network_interface[5].enabled + assert not rt.network_interface[6].enabled + + r0 = rt.acl.acl[0] + assert r0.action == ACLAction.PERMIT + assert r0.src_port == r0.dst_port == Port.POSTGRES_SERVER + assert r0.src_ip_address == r0.dst_ip_address == r0.dst_wildcard_mask == r0.src_wildcard_mask == r0.protocol == None + + r1 = rt.acl.acl[1] + assert r1.action == ACLAction.PERMIT + assert r1.protocol == IPProtocol.ICMP + assert ( + r1.src_ip_address + == r1.dst_ip_address + == r1.dst_wildcard_mask + == r1.src_wildcard_mask + == r1.src_port + == r1.dst_port + == None + ) + + r2 = rt.acl.acl[2] + assert r2.action == ACLAction.PERMIT + assert r2.src_ip_address == IPv4Address("100.100.100.1") + assert r2.dst_ip_address == IPv4Address("100.100.101.1") + assert r2.src_wildcard_mask == r2.dst_wildcard_mask == None + assert r2.src_port == r2.dst_port == r2.protocol == None + + r3 = rt.acl.acl[3] + assert r3.action == ACLAction.PERMIT + assert r3.src_ip_address == IPv4Address("100.100.102.0") + assert r3.dst_ip_address == IPv4Address("100.100.103.0") + assert r3.src_wildcard_mask == IPv4Address("0.0.0.255") + assert r3.dst_wildcard_mask == IPv4Address("0.0.0.255") + assert r3.src_port == r3.dst_port == r3.protocol == None + + r20 = rt.acl.acl[20] + assert r20.action == ACLAction.DENY + assert ( + r20.src_ip_address + == r20.dst_ip_address + == r20.src_wildcard_mask + == r20.dst_wildcard_mask + == r20.src_port + == r20.dst_port + == r20.protocol + == None + ) diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_wireless_router.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_wireless_router.py new file mode 100644 index 00000000..494f5a15 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_wireless_router.py @@ -0,0 +1,97 @@ +from ipaddress import IPv4Address + +from primaite.simulator.network.hardware.nodes.network.router import ACLAction +from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port + + +def test_wireless_router_from_config(): + cfg = { + "ref": "router_2", + "type": "wireless_router", + "hostname": "router_2", + "router_interface": { + "ip_address": "192.168.1.1", + "subnet_mask": "255.255.255.0", + }, + "wireless_access_point": { + "ip_address": "192.170.1.1", + "subnet_mask": "255.255.255.0", + "frequency": "WIFI_2_4", + }, + "acl": { + 0: { + "action": "PERMIT", + "src_port": "POSTGRES_SERVER", + "dst_port": "POSTGRES_SERVER", + }, + 1: { + "action": "PERMIT", + "protocol": "ICMP", + }, + 2: { + "action": "PERMIT", + "src_ip": "100.100.100.1", + "dst_ip": "100.100.101.1", + }, + 3: { + "action": "PERMIT", + "src_ip": "100.100.102.0", + "dst_ip": "100.100.103.0", + "src_wildcard_mask": "0.0.0.255", + "dst_wildcard_mask": "0.0.0.255", + }, + 20: { + "action": "DENY", + }, + }, + } + + rt = WirelessRouter.from_config(cfg=cfg) + + r0 = rt.acl.acl[0] + assert r0.action == ACLAction.PERMIT + assert r0.src_port == r0.dst_port == Port.POSTGRES_SERVER + assert r0.src_ip_address == r0.dst_ip_address == r0.dst_wildcard_mask == r0.src_wildcard_mask == r0.protocol == None + + r1 = rt.acl.acl[1] + assert r1.action == ACLAction.PERMIT + assert r1.protocol == IPProtocol.ICMP + assert ( + r1.src_ip_address + == r1.dst_ip_address + == r1.dst_wildcard_mask + == r1.src_wildcard_mask + == r1.src_port + == r1.dst_port + == None + ) + + r2 = rt.acl.acl[2] + assert r2.action == ACLAction.PERMIT + assert r2.src_ip_address == IPv4Address("100.100.100.1") + assert r2.dst_ip_address == IPv4Address("100.100.101.1") + assert r2.src_wildcard_mask == r2.dst_wildcard_mask == None + assert r2.src_port == r2.dst_port == r2.protocol == None + + r3 = rt.acl.acl[3] + assert r3.action == ACLAction.PERMIT + assert r3.src_ip_address == IPv4Address("100.100.102.0") + assert r3.dst_ip_address == IPv4Address("100.100.103.0") + assert r3.src_wildcard_mask == IPv4Address("0.0.0.255") + assert r3.dst_wildcard_mask == IPv4Address("0.0.0.255") + assert r3.src_port == r3.dst_port == r3.protocol == None + + r20 = rt.acl.acl[20] + assert r20.action == ACLAction.DENY + assert ( + r20.src_ip_address + == r20.dst_ip_address + == r20.src_wildcard_mask + == r20.dst_wildcard_mask + == r20.src_port + == r20.dst_port + == r20.protocol + == None + ) From 368542df03361a721fba64149174f626cf9e4637 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Mar 2024 21:51:27 +0000 Subject: [PATCH 747/980] #2418 - Add printer and wireless router as node types in network show --- src/primaite/simulator/network/container.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 0e970c3d..5ec47052 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -8,6 +8,7 @@ from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import Link, Node, WiredNetworkInterface +from primaite.simulator.network.hardware.nodes.host.server import Printer from primaite.simulator.system.applications.application import Application from primaite.simulator.system.services.service import Service @@ -110,6 +111,16 @@ class Network(SimComponent): """The Firewalls in the Network.""" return [node for node in self.nodes.values() if node.__class__.__name__ == "Firewall"] + @property + def printer_nodes(self) -> List[Node]: + """The printers on the network.""" + return [node for node in self.nodes.values() if isinstance(node, Printer)] + + @property + def wireless_router_nodes(self) -> List[Node]: + """The Routers in the Network.""" + return [node for node in self.nodes.values() if node.__class__.__name__ == "WirelessRouter"] + def show(self, nodes: bool = True, ip_addresses: bool = True, links: bool = True, markdown: bool = False): """ Print tables describing the Network. @@ -128,6 +139,8 @@ class Network(SimComponent): "Switch": self.switch_nodes, "Server": self.server_nodes, "Computer": self.computer_nodes, + "Printer": self.printer_nodes, + "Wireless Router": self.wireless_routers, } if nodes: table = PrettyTable(["Node", "Type", "Operating State"]) From 27bee58bf755cdaa555c998cc4bee6463fc56b3f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 27 Mar 2024 00:00:06 +0000 Subject: [PATCH 748/980] #2418 Fix broken property --- src/primaite/simulator/network/container.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 5ec47052..a4079fb8 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -140,7 +140,7 @@ class Network(SimComponent): "Server": self.server_nodes, "Computer": self.computer_nodes, "Printer": self.printer_nodes, - "Wireless Router": self.wireless_routers, + "Wireless Router": self.wireless_router_nodes, } if nodes: table = PrettyTable(["Node", "Type", "Operating State"]) From fbb4eba6b74cbd766fc4c9ecb1bb19cc866c896e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 27 Mar 2024 03:27:44 +0000 Subject: [PATCH 749/980] Draft new observation space config --- .../_package_data/data_manipulation.yaml | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index 12f60b63..06028ee1 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -176,13 +176,54 @@ agents: team: BLUE type: ProxyAgent + observation_space: + - type: NODES + label: NODES # What is the dictionary key called + options: + hosts: + - hostname: domain_controller + - hostname: web_server + - hostname: database_server + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + routers: + - hostname: router_1 + firewalls: {} + + num_host_services: 1 + num_host_applications: 0 + num_host_folders: 1 + num_host_files: 1 + num_host_network_interfaces: 2 + num_router_ports: 4 + num_acl_rules: 10 + num_firewall_ports: 4 + firewalls_internal_inbound_acl: true + firewalls_internal_outbound_acl: true + firewalls_dmz_inbound_acl: true + firewalls_dmz_outbound_acl: true + firewalls_external_inbound_acl: true + firewalls_external_outbound_acl: true + - type: LINKS + label: "LINKS" + options: + links: + - link_ref: router_1___switch_1 + - link_ref: router_1___switch_2 + - link_ref: switch_1___domain_controller + - link_ref: switch_1___web_server + - link_ref: switch_1___database_server + - link_ref: switch_1___backup_server + - link_ref: switch_1___security_suite + - link_ref: switch_2___client_1 + - link_ref: switch_2___client_2 + - link_ref: switch_2___security_suite + observation_space: type: UC2BlueObservation options: - num_services_per_node: 1 - num_folders_per_node: 1 - num_files_per_folder: 1 - num_nics_per_node: 2 nodes: - node_hostname: domain_controller services: From 8bb7f8a1775b8269c5d07ecb6b0969fb41a235e7 Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Wed, 27 Mar 2024 17:07:12 +0000 Subject: [PATCH 750/980] #2405 add application install and remove actions --- src/primaite/game/agent/actions.py | 46 +++++++ .../simulator/network/hardware/base.py | 121 +++++++++++++++++- src/primaite/simulator/system/software.py | 2 +- tests/conftest.py | 12 +- .../game_layer/test_actions.py | 26 ++++ 5 files changed, 203 insertions(+), 4 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index b79fc985..7c31ae7e 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -219,6 +219,50 @@ class NodeApplicationFixAction(NodeApplicationAbstractAction): self.verb: str = "fix" +class NodeApplicationInstallAction(AbstractAction): + """Action which installs an application.""" + + def __init__( + self, manager: "ActionManager", num_nodes: int, application_name: str, ip_address: str, **kwargs + ) -> None: + super().__init__(manager=manager) + self.shape: Dict[str, int] = {"node_id": num_nodes} + self.application_name = application_name + self.ip_address = ip_address + + def form_request(self, node_id: int) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" + node_name = self.manager.get_node_name_by_idx(node_id) + if node_name is None: + return ["do_nothing"] + return [ + "network", + "node", + node_name, + "software_manager", + "application", + "install", + self.application_name, + self.ip_address, + ] + + +class NodeApplicationRemoveAction(AbstractAction): + """Action which removes/uninstalls an application.""" + + def __init__(self, manager: "ActionManager", num_nodes: int, application_name: str, **kwargs) -> None: + super().__init__(manager=manager) + self.shape: Dict[str, int] = {"node_id": num_nodes} + self.application_name = application_name + + def form_request(self, node_id: int) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" + node_name = self.manager.get_node_name_by_idx(node_id) + if node_name is None: + return ["do_nothing"] + return ["network", "node", node_name, "software_manager", "application", "uninstall", self.application_name] + + class NodeFolderAbstractAction(AbstractAction): """ Base class for folder actions. @@ -658,6 +702,8 @@ class ActionManager: "NODE_APPLICATION_SCAN": NodeApplicationScanAction, "NODE_APPLICATION_CLOSE": NodeApplicationCloseAction, "NODE_APPLICATION_FIX": NodeApplicationFixAction, + "NODE_APPLICATION_INSTALL": NodeApplicationInstallAction, + "NODE_APPLICATION_REMOVE": NodeApplicationRemoveAction, "NODE_FILE_SCAN": NodeFileScanAction, "NODE_FILE_CHECKHASH": NodeFileCheckhashAction, "NODE_FILE_DELETE": NodeFileDeleteAction, diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 38d20e1f..132fc8b1 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -5,7 +5,7 @@ import secrets from abc import ABC, abstractmethod from ipaddress import IPv4Address, IPv4Network from pathlib import Path -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Optional, Type, TypeVar, Union from prettytable import MARKDOWN, PrettyTable from pydantic import BaseModel, Field @@ -35,8 +35,11 @@ from primaite.simulator.system.core.software_manager import SoftwareManager from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.processes.process import Process from primaite.simulator.system.services.service import Service +from primaite.simulator.system.software import IOSoftware from primaite.utils.validators import IPV4Address +IOSoftwareClass = TypeVar("IOSoftwareClass", bound=IOSoftware) + _LOGGER = getLogger(__name__) @@ -843,12 +846,56 @@ class Node(SimComponent): ) rm.add_request("os", RequestType(func=self._os_request_manager, validator=_node_is_on)) + self._software_manager = RequestManager() + rm.add_request("software_manager", RequestType(func=self._software_manager, validator=_node_is_on)) + self._application_manager = RequestManager() + self._software_manager.add_request(name="application", request_type=RequestType(func=self._application_manager)) + + self._application_manager.add_request( + name="install", + request_type=RequestType( + func=lambda request, context: RequestResponse.from_bool( + self.application_install_action( + application=self._read_application_type(request[0]), ip_address=request[1] + ) + ) + ), + ) + + self._application_manager.add_request( + name="uninstall", + request_type=RequestType( + func=lambda request, context: RequestResponse.from_bool( + self.application_uninstall_action(application=self._read_application_type(request[0])) + ) + ), + ) + return rm def _install_system_software(self): """Install System Software - software that is usually provided with the OS.""" pass + def _read_application_type(self, application_class_str: str) -> Type[IOSoftwareClass]: + """Wrapper that converts the string from the request manager into the appropriate class for the application.""" + if application_class_str.lower() == "DoSBot".lower(): + from primaite.simulator.system.applications.red_applications.dos_bot import DoSBot + + return DoSBot + elif application_class_str.lower() == "DataManipulationBot".lower(): + from primaite.simulator.system.applications.red_applications.data_manipulation_bot import ( + DataManipulationBot, + ) + + return DataManipulationBot + elif application_class_str.lower() == "WebBrowser".lower(): + from primaite.simulator.system.applications.web_browser import WebBrowser + + return WebBrowser + else: + return 0 + def describe_state(self) -> Dict: """ Produce a dictionary describing the current state of this object. @@ -1257,6 +1304,78 @@ class Node(SimComponent): _LOGGER.info(f"Removed application {application.name} from node {self.hostname}") self._application_request_manager.remove_request(application.name) + def application_install_action(self, application: Application, ip_address: Optional[str] = None) -> bool: + """ + Install an application on this node and configure it. + + This method is useful for allowing agents to take this action. + + :param application: Application instance that has not been installed on any node yet. + :type application: Application + :parm + """ + if application in self: + _LOGGER.warning( + f"Can't add application {application.__name__}" + f"to node {self.hostname}. It's already installed." + ) + self.software_manager.install(application) + + application_instance = self.software_manager.software.get(str(application.__name__)) + self.applications[application_instance.uuid] = application_instance + application.parent = self + self.sys_log.info(f"Installed application {application.__name__}") + _LOGGER.debug(f"Added application {application.__name__} to node {self.hostname}") + self._application_request_manager.add_request( + application_instance.name, RequestType(func=application_instance._request_manager) + ) + + # Configure application if additional parameters are given + if ip_address: + from primaite.simulator.system.applications.red_applications.data_manipulation_bot import ( + DataManipulationBot, + ) + from primaite.simulator.system.applications.red_applications.dos_bot import DoSBot + + if application == DoSBot: + application_instance.configure(target_ip_address=IPv4Address(ip_address)) + elif application == DataManipulationBot: + application_instance.configure(server_ip_address=IPv4Address(ip_address)) + else: + pass + + if application in self: + return True + else: + return False + + def application_uninstall_action(self, application: Application) -> bool: + """ + Uninstall and completely remove application from this node. + + This method is useful for allowing agents to take this action. + + :param application: Application object that is currently associated with this node. + :type application: Application + """ + if application.__name__ not in self.software_manager.software: + _LOGGER.warning( + f"Can't remove application {application.__name__}" + f"from node {self.hostname}. It's not installed." + ) + return True + application_instance = self.software_manager.software.get( + str(application.__name__) + ) # This works because we can't have two applications with the same name on the same node + self.applications.pop(application_instance.uuid) + application.parent = None + self.sys_log.info(f"Uninstalled application {application.__name__}") + _LOGGER.info(f"Removed application {application.__name__} from node {self.hostname}") + self._application_request_manager.remove_request(application_instance.name) + self.software_manager.uninstall(application_instance.name) + if application_instance.name not in self.software_manager.software: + return True + else: + return False + def _shut_down_actions(self): """Actions to perform when the node is shut down.""" # Turn off all the services in the node diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index ab60adde..3ab32bc6 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -88,7 +88,7 @@ class Software(SimComponent): "The count of times the software has been scanned, defaults to 0." revealed_to_red: bool = False "Indicates if the software has been revealed to red agent, defaults is False." - software_manager: "SoftwareManager" = None + software_manager: Optional["SoftwareManager"] = None "An instance of Software Manager that is used by the parent node." sys_log: SysLog = None "An instance of SysLog that is used by the parent node." diff --git a/tests/conftest.py b/tests/conftest.py index 078a78bd..be76fc92 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -480,6 +480,8 @@ def game_and_agent(): {"type": "NODE_APPLICATION_SCAN"}, {"type": "NODE_APPLICATION_CLOSE"}, {"type": "NODE_APPLICATION_FIX"}, + {"type": "NODE_APPLICATION_INSTALL", "options": {"application_name": "DoSBot", "ip_address": "192.168.1.14"}}, + {"type": "NODE_APPLICATION_REMOVE", "options": {"application_name": "DoSBot"}}, {"type": "NODE_FILE_SCAN"}, {"type": "NODE_FILE_CHECKHASH"}, {"type": "NODE_FILE_DELETE"}, @@ -507,10 +509,16 @@ def game_and_agent(): nodes=[ { "node_name": "client_1", - "applications": [{"application_name": "WebBrowser"}], + "applications": [ + {"application_name": "WebBrowser"}, + {"application_name": "DoSBot"}, + ], "folders": [{"folder_name": "downloads", "files": [{"file_name": "cat.png"}]}], }, - {"node_name": "server_1", "services": [{"service_name": "DNSServer"}]}, + { + "node_name": "server_1", + "services": [{"service_name": "DNSServer"}], + }, {"node_name": "server_2", "services": [{"service_name": "WebServer"}]}, {"node_name": "router"}, ], diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index b3a52cd8..5ba58ee5 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -10,6 +10,7 @@ # 4. Check that the simulation has changed in the way that I expect. # 5. Repeat for all actions. +from ipaddress import IPv4Address from typing import Tuple import pytest @@ -455,3 +456,28 @@ def test_node_application_close_integration(game_and_agent: Tuple[PrimaiteGame, game.step() assert browser.operating_state == ApplicationOperatingState.CLOSED + + +def test_node_application_install_and_uninstall_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the NodeApplicationInstallAction and NodeApplicationRemoveAction can form a request and that + it is accepted by the simulation. + + When you initiate a install action, the Application will be installed and configured on the node. + The remove action will uninstall the application from the node.""" + game, agent = game_and_agent + + client_1 = game.simulation.network.get_node_by_hostname("client_1") + + assert client_1.software_manager.software.get("DoSBot") is None + + action = ("NODE_APPLICATION_INSTALL", {"node_id": 0}) + agent.store_action(action) + game.step() + + assert client_1.software_manager.software.get("DoSBot") is not None + + action = ("NODE_APPLICATION_REMOVE", {"node_id": 0}) + agent.store_action(action) + game.step() + + assert client_1.software_manager.software.get("DoSBot") is None From cae9f64b93d62d1798fda00c6a20de6b19f25eb7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 27 Mar 2024 22:11:02 +0000 Subject: [PATCH 751/980] New observations --- .../agent/observations/agent_observations.py | 52 +- .../agent/observations/node_observations.py | 466 ++++++++++++++++- .../agent/observations/observation_manager.py | 20 +- .../game/agent/observations/observations.py | 490 +++++++++--------- src/primaite/game/agent/utils.py | 6 +- .../observations/test_node_observations.py | 2 +- 6 files changed, 727 insertions(+), 309 deletions(-) diff --git a/src/primaite/game/agent/observations/agent_observations.py b/src/primaite/game/agent/observations/agent_observations.py index 70a83881..2148697b 100644 --- a/src/primaite/game/agent/observations/agent_observations.py +++ b/src/primaite/game/agent/observations/agent_observations.py @@ -2,7 +2,7 @@ from typing import Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium import spaces -from primaite.game.agent.observations.node_observations import NodeObservation +from primaite.game.agent.observations.host import NodeObservation from primaite.game.agent.observations.observations import ( AbstractObservation, AclObservation, @@ -136,53 +136,3 @@ class UC2BlueObservation(AbstractObservation): new = cls(nodes=nodes, links=links, acl=acl, ics=ics, where=["network"]) return new - -class UC2RedObservation(AbstractObservation): - """Container for all observations used by the red agent in UC2.""" - - def __init__(self, nodes: List[NodeObservation], where: Optional[List[str]] = None) -> None: - super().__init__() - self.where: Optional[List[str]] = where - self.nodes: List[NodeObservation] = nodes - - self.default_observation: Dict = { - "NODES": {i + 1: n.default_observation for i, n in enumerate(self.nodes)}, - } - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation.""" - if self.where is None: - return self.default_observation - - obs = {} - obs["NODES"] = {i + 1: node.observe(state) for i, node in enumerate(self.nodes)} - return obs - - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" - return spaces.Dict( - { - "NODES": spaces.Dict({i + 1: node.space for i, node in enumerate(self.nodes)}), - } - ) - - @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "UC2RedObservation": - """ - Create UC2 red observation from a config. - - :param config: Dictionary containing the configuration for this UC2 red observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - """ - node_configs = config["nodes"] - nodes = [NodeObservation.from_config(config=cfg, game=game) for cfg in node_configs] - return cls(nodes=nodes, where=["network"]) - - -class UC2GreenObservation(NullObservation): - """Green agent observation. As the green agent's actions don't depend on the observation, this is empty.""" - - pass diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index 94f0974b..42bdb749 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -1,21 +1,473 @@ -from typing import Dict, List, Optional, Tuple, TYPE_CHECKING +from __future__ import annotations +from typing import Any, Dict, Iterable, List, Literal, Optional, Tuple, TYPE_CHECKING, Union from gymnasium import spaces +from gymnasium.core import ObsType +from pydantic import BaseModel, ConfigDict from primaite import getLogger -from primaite.game.agent.observations.file_system_observations import FolderObservation -from primaite.game.agent.observations.nic_observations import NicObservation from primaite.game.agent.observations.observations import AbstractObservation -from primaite.game.agent.observations.software_observation import ServiceObservation +# from primaite.game.agent.observations.file_system_observations import FolderObservation +# from primaite.game.agent.observations.nic_observations import NicObservation +# from primaite.game.agent.observations.software_observation import ServiceObservation from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE _LOGGER = getLogger(__name__) -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame +WhereType = Iterable[str | int] | None -class NodeObservation(AbstractObservation): +class ServiceObservation(AbstractObservation, identifier="SERVICE"): + class ConfigSchema(AbstractObservation.ConfigSchema): + service_name: str + + def __init__(self, where: WhereType)->None: + self.where = where + self.default_observation = {"operating_status": 0, "health_status": 0} + + def observe(self, state: Dict) -> Any: + service_state = access_from_nested_dict(state, self.where) + if service_state is NOT_PRESENT_IN_STATE: + return self.default_observation + return { + "operating_status": service_state["operating_state"], + "health_status": service_state["health_state_visible"], + } + + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" + return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(5)}) + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: + return cls(where=parent_where+["services", config.service_name]) + + +class ApplicationObservation(AbstractObservation, identifier="APPLICATION"): + class ConfigSchema(AbstractObservation.ConfigSchema): + application_name: str + + def __init__(self, where: WhereType)->None: + self.where = where + self.default_observation = {"operating_status": 0, "health_status": 0, "num_executions": 0} + + def observe(self, state: Dict) -> Any: + # raise NotImplementedError("TODO NUM EXECUTIONS NEEDS TO BE CONVERTED TO A CATEGORICAL") + application_state = access_from_nested_dict(state, self.where) + if application_state is NOT_PRESENT_IN_STATE: + return self.default_observation + return { + "operating_status": application_state["operating_state"], + "health_status": application_state["health_state_visible"], + "num_executions": application_state["num_executions"], + } + + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" + return spaces.Dict({ + "operating_status": spaces.Discrete(7), + "health_status": spaces.Discrete(5), + "num_executions": spaces.Discrete(4) + }) + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ApplicationObservation: + return cls(where=parent_where+["applications", config.application_name]) + + +class FileObservation(AbstractObservation, identifier="FILE"): + class ConfigSchema(AbstractObservation.ConfigSchema): + file_name: str + include_num_access : bool = False + + def __init__(self, where: WhereType, include_num_access: bool)->None: + self.where: WhereType = where + self.include_num_access :bool = include_num_access + + self.default_observation: ObsType = {"health_status": 0} + if self.include_num_access: + self.default_observation["num_access"] = 0 + + def observe(self, state: Dict) -> Any: + file_state = access_from_nested_dict(state, self.where) + if file_state is NOT_PRESENT_IN_STATE: + return self.default_observation + obs = {"health_status": file_state["visible_status"]} + if self.include_num_access: + obs["num_access"] = file_state["num_access"] + # raise NotImplementedError("TODO: need to fix num_access to use thresholds instead of raw value.") + return obs + + @property + def space(self) -> spaces.Space: + space = {"health_status": spaces.Discrete(6)} + if self.include_num_access: + space["num_access"] = spaces.Discrete(4) + return spaces.Dict(space) + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> FileObservation: + return cls(where=parent_where+["files", config.file_name], include_num_access=config.include_num_access) + + +class FolderObservation(AbstractObservation, identifier="FOLDER"): + class ConfigSchema(AbstractObservation.ConfigSchema): + folder_name: str + files: List[FileObservation.ConfigSchema] = [] + num_files : int = 0 + include_num_access : bool = False + + def __init__(self, where: WhereType, files: Iterable[FileObservation], num_files: int, include_num_access: bool)->None: + self.where: WhereType = where + + self.files: List[FileObservation] = files + while len(self.files) < num_files: + self.files.append(FileObservation(where=None,include_num_access=include_num_access)) + while len(self.files) > num_files: + truncated_file = self.files.pop() + msg = f"Too many files in folder observation. Truncating file {truncated_file}" + _LOGGER.warning(msg) + + self.default_observation = { + "health_status": 0, + "FILES": {i + 1: f.default_observation for i, f in enumerate(self.files)}, + } + + def observe(self, state: Dict) -> Any: + folder_state = access_from_nested_dict(state, self.where) + if folder_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + health_status = folder_state["health_status"] + + obs = {} + + obs["health_status"] = health_status + obs["FILES"] = {i + 1: file.observe(state) for i, file in enumerate(self.files)} + + return obs + + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape. + + :return: Gymnasium space + :rtype: spaces.Space + """ + return spaces.Dict( + { + "health_status": spaces.Discrete(6), + "FILES": spaces.Dict({i + 1: f.space for i, f in enumerate(self.files)}), + } + ) + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> FileObservation: + where = parent_where + ["folders", config.folder_name] + + #pass down shared/common config items + for file_config in config.files: + file_config.include_num_access = config.include_num_access + + files = [FileObservation.from_config(config=f, parent_where = where) for f in config.files] + return cls(where=where, files=files, num_files=config.num_files, include_num_access=config.include_num_access) + + +class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): + class ConfigSchema(AbstractObservation.ConfigSchema): + nic_num: int + include_nmne: bool = False + + + def __init__(self, where: WhereType, include_nmne: bool)->None: + self.where = where + self.include_nmne : bool = include_nmne + + self.default_observation: ObsType = {"nic_status": 0} + if self.include_nmne: + self.default_observation.update({"NMNE":{"inbound":0, "outbound":0}}) + + def observe(self, state: Dict) -> Any: + # raise NotImplementedError("TODO: CATEGORISATION") + nic_state = access_from_nested_dict(state, self.where) + + if nic_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + obs = {"nic_status": 1 if nic_state["enabled"] else 2} + if self.include_nmne: + obs.update({"NMNE": {}}) + direction_dict = nic_state["nmne"].get("direction", {}) + inbound_keywords = direction_dict.get("inbound", {}).get("keywords", {}) + inbound_count = inbound_keywords.get("*", 0) + outbound_keywords = direction_dict.get("outbound", {}).get("keywords", {}) + outbound_count = outbound_keywords.get("*", 0) + obs["NMNE"]["inbound"] = self._categorise_mne_count(inbound_count - self.nmne_inbound_last_step) + obs["NMNE"]["outbound"] = self._categorise_mne_count(outbound_count - self.nmne_outbound_last_step) + self.nmne_inbound_last_step = inbound_count + self.nmne_outbound_last_step = outbound_count + return obs + + + @property + def space(self) -> spaces.Space: + space = spaces.Dict({"nic_status": spaces.Discrete(3)}) + + if self.include_nmne: + space["NMNE"] = spaces.Dict({"inbound": spaces.Discrete(4), "outbound": spaces.Discrete(4)}) + + return space + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: + return cls(where = parent_where+["NICs", config.nic_num], include_nmne=config.include_nmne) + + +class HostObservation(AbstractObservation, identifier="HOST"): + class ConfigSchema(AbstractObservation.ConfigSchema): + hostname: str + services: List[ServiceObservation.ConfigSchema] = [] + applications: List[ApplicationObservation.ConfigSchema] = [] + folders: List[FolderObservation.ConfigSchema] = [] + network_interfaces: List[NICObservation.ConfigSchema] = [] + num_services: int + num_applications: int + num_folders: int + num_files: int + num_nics: int + include_nmne: bool + include_num_access: bool + + def __init__(self, + where: WhereType, + services:List[ServiceObservation], + applications:List[ApplicationObservation], + folders:List[FolderObservation], + network_interfaces:List[NICObservation], + num_services: int, + num_applications: int, + num_folders: int, + num_files: int, + num_nics: int, + include_nmne: bool, + include_num_access: bool + )->None: + + self.where : WhereType = where + + # ensure service list has length equal to num_services by truncating or padding + self.services: List[ServiceObservation] = services + while len(self.services) < num_services: + self.services.append(ServiceObservation(where=None)) + while len(self.services) > num_services: + truncated_service = self.services.pop() + msg = f"Too many services in Node observation space for node. Truncating service {truncated_service.where}" + _LOGGER.warning(msg) + + # ensure application list has length equal to num_applications by truncating or padding + self.applications: List[ApplicationObservation] = applications + while len(self.applications) < num_applications: + self.applications.append(ApplicationObservation(where=None)) + while len(self.applications) > num_applications: + truncated_application = self.applications.pop() + msg = f"Too many applications in Node observation space for node. Truncating application {truncated_application.where}" + _LOGGER.warning(msg) + + # ensure folder list has length equal to num_folders by truncating or padding + self.folders: List[FolderObservation] = folders + while len(self.folders) < num_folders: + self.folders.append(FolderObservation(where = None, files= [], num_files=num_files, include_num_access=include_num_access)) + while len(self.folders) > num_folders: + truncated_folder = self.folders.pop() + msg = f"Too many folders in Node observation space for node. Truncating folder {truncated_folder.where}" + _LOGGER.warning(msg) + + # ensure network_interface list has length equal to num_network_interfaces by truncating or padding + self.network_interfaces: List[NICObservation] = network_interfaces + while len(self.network_interfaces) < num_nics: + self.network_interfaces.append(NICObservation(where = None, include_nmne=include_nmne)) + while len(self.network_interfaces) > num_nics: + truncated_nic = self.network_interfaces.pop() + msg = f"Too many network_interfaces in Node observation space for node. Truncating {truncated_folder.where}" + _LOGGER.warning(msg) + + self.default_observation: ObsType = { + "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, + "FOLDERS": {i + 1: f.default_observation for i, f in enumerate(self.folders)}, + "NICS": {i + 1: n.default_observation for i, n in enumerate(self.network_interfaces)}, + "operating_status": 0, + "num_file_creations": 0, + "num_file_deletions": 0, + } + + + def observe(self, state: Dict) -> Any: + node_state = access_from_nested_dict(state, self.where) + if node_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + obs = {} + obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} + obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} + obs["operating_status"] = node_state["operating_state"] + obs["NICS"] = { + i + 1: network_interface.observe(state) for i, network_interface in enumerate(self.network_interfaces) + } + obs["num_file_creations"] = node_state["file_system"]["num_file_creations"] + obs["num_file_deletions"] = node_state["file_system"]["num_file_deletions"] + return obs + + @property + def space(self) -> spaces.Space: + shape = { + "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), + "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), + "operating_status": spaces.Discrete(5), + "NICS": spaces.Dict( + {i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)} + ), + "num_file_creations" : spaces.Discrete(4), + "num_file_deletions" : spaces.Discrete(4), + } + return spaces.Dict(shape) + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = None ) -> ServiceObservation: + if parent_where is None: + where = ["network", "nodes", config.hostname] + else: + where = parent_where + ["nodes", config.hostname] + + #pass down shared/common config items + for folder_config in config.folders: + folder_config.include_num_access = config.include_num_access + folder_config.num_files = config.num_files + for nic_config in config.network_interfaces: + nic_config.include_nmne = config.include_nmne + + services = [ServiceObservation.from_config(config=c,parent_where=where) for c in config.services] + applications = [ApplicationObservation.from_config(config=c, parent_where=where) for c in config.applications] + folders = [FolderObservation.from_config(config=c, parent_where=where) for c in config.folders] + nics = [NICObservation.from_config(config=c, parent_where=where) for c in config.network_interfaces] + + return cls( + where = where, + services = services, + applications = applications, + folders = folders, + network_interfaces = nics, + num_services = config.num_services, + num_applications = config.num_applications, + num_folders = config.num_folders, + num_files = config.num_files, + num_nics = config.num_nics, + include_nmne = config.include_nmne, + include_num_access = config.include_num_access, + ) + + +class PortObservation(AbstractObservation, identifier="PORT"): + class ConfigSchema(AbstractObservation.ConfigSchema): + pass + + def __init__(self, where: WhereType)->None: + pass + + def observe(self, state: Dict) -> Any: + pass + + @property + def space(self) -> spaces.Space: + pass + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: + pass + +class ACLObservation(AbstractObservation, identifier="ACL"): + class ConfigSchema(AbstractObservation.ConfigSchema): + pass + + def __init__(self, where: WhereType)->None: + pass + + def observe(self, state: Dict) -> Any: + pass + + @property + def space(self) -> spaces.Space: + pass + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: + pass + +class RouterObservation(AbstractObservation, identifier="ROUTER"): + class ConfigSchema(AbstractObservation.ConfigSchema): + hostname: str + ports: List[PortObservation.ConfigSchema] + + + def __init__(self, where: WhereType)->None: + pass + + def observe(self, state: Dict) -> Any: + pass + + @property + def space(self) -> spaces.Space: + pass + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: + pass + +class FirewallObservation(AbstractObservation, identifier="FIREWALL"): + class ConfigSchema(AbstractObservation.ConfigSchema): + hostname: str + ports: List[PortObservation.ConfigSchema] = [] + + def __init__(self, where: WhereType)->None: + pass + + def observe(self, state: Dict) -> Any: + pass + + @property + def space(self) -> spaces.Space: + pass + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: + pass + +class NodesObservation(AbstractObservation, identifier="NODES"): + class ConfigSchema(AbstractObservation.ConfigSchema): + """Config""" + hosts: List[HostObservation.ConfigSchema] = [] + routers: List[RouterObservation.ConfigSchema] = [] + firewalls: List[FirewallObservation.ConfigSchema] = [] + num_services: int = 1 + + + def __init__(self, where: WhereType)->None: + pass + + def observe(self, state: Dict) -> Any: + pass + + @property + def space(self) -> spaces.Space: + pass + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: + pass + +############################ OLD + +class NodeObservation(AbstractObservation, identifier= "OLD"): """Observation of a node in the network. Includes services, folders and NICs.""" def __init__( diff --git a/src/primaite/game/agent/observations/observation_manager.py b/src/primaite/game/agent/observations/observation_manager.py index 400345fa..be90041e 100644 --- a/src/primaite/game/agent/observations/observation_manager.py +++ b/src/primaite/game/agent/observations/observation_manager.py @@ -2,11 +2,6 @@ from typing import Dict, TYPE_CHECKING from gymnasium.core import ObsType -from primaite.game.agent.observations.agent_observations import ( - UC2BlueObservation, - UC2GreenObservation, - UC2RedObservation, -) from primaite.game.agent.observations.observations import AbstractObservation if TYPE_CHECKING: @@ -63,11 +58,10 @@ class ObservationManager: :param game: Reference to the PrimaiteGame object that spawned this observation. :type game: PrimaiteGame """ - if config["type"] == "UC2BlueObservation": - return cls(UC2BlueObservation.from_config(config.get("options", {}), game=game)) - elif config["type"] == "UC2RedObservation": - return cls(UC2RedObservation.from_config(config.get("options", {}), game=game)) - elif config["type"] == "UC2GreenObservation": - return cls(UC2GreenObservation.from_config(config.get("options", {}), game=game)) - else: - raise ValueError("Observation space type invalid") + + for obs_cfg in config: + obs_type = obs_cfg['type'] + obs_class = AbstractObservation._registry[obs_type] + observation = obs_class.from_config(obs_class.ConfigSchema(**obs_cfg['options'])) + obs_manager = cls(observation) + return obs_manager \ No newline at end of file diff --git a/src/primaite/game/agent/observations/observations.py b/src/primaite/game/agent/observations/observations.py index 6236b00d..dc41e8e5 100644 --- a/src/primaite/game/agent/observations/observations.py +++ b/src/primaite/game/agent/observations/observations.py @@ -1,9 +1,10 @@ """Manages the observation space for the agent.""" from abc import ABC, abstractmethod from ipaddress import IPv4Address -from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING +from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING, Type from gymnasium import spaces +from pydantic import BaseModel, ConfigDict from primaite import getLogger from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE @@ -17,6 +18,28 @@ if TYPE_CHECKING: class AbstractObservation(ABC): """Abstract class for an observation space component.""" + class ConfigSchema(ABC, BaseModel): + model_config = ConfigDict(extra="forbid") + + _registry: Dict[str, Type["AbstractObservation"]] = {} + """Registry of observation components, with their name as key. + + Automatically populated when subclasses are defined. Used for defining from_config. + """ + + def __init_subclass__(cls, identifier: str, **kwargs: Any) -> None: + """ + Register an observation type. + + :param identifier: Identifier used to uniquely specify observation component types. + :type identifier: str + :raises ValueError: When attempting to create a component with a name that is already in use. + """ + super().__init_subclass__(**kwargs) + if identifier in cls._registry: + raise ValueError(f"Duplicate observation component type {identifier}") + cls._registry[identifier] = cls + @abstractmethod def observe(self, state: Dict) -> Any: """ @@ -36,274 +59,271 @@ class AbstractObservation(ABC): pass @classmethod - @abstractmethod - def from_config(cls, config: Dict, game: "PrimaiteGame"): - """Create this observation space component form a serialised format. - - The `game` parameter is for a the PrimaiteGame object that spawns this component. - """ - pass + def from_config(cls, cfg: Dict) -> "AbstractObservation": + """Create this observation space component form a serialised format.""" + ObservationType = cls._registry[cfg['type']] + return ObservationType.from_config(cfg=cfg) -class LinkObservation(AbstractObservation): - """Observation of a link in the network.""" +# class LinkObservation(AbstractObservation): +# """Observation of a link in the network.""" - default_observation: spaces.Space = {"PROTOCOLS": {"ALL": 0}} - "Default observation is what should be returned when the link doesn't exist." +# default_observation: spaces.Space = {"PROTOCOLS": {"ALL": 0}} +# "Default observation is what should be returned when the link doesn't exist." - def __init__(self, where: Optional[Tuple[str]] = None) -> None: - """Initialise link observation. +# def __init__(self, where: Optional[Tuple[str]] = None) -> None: +# """Initialise link observation. - :param where: Store information about where in the simulation state dictionary to find the relevant information. - Optional. If None, this corresponds that the file does not exist and the observation will be populated with - zeroes. +# :param where: Store information about where in the simulation state dictionary to find the relevant information. +# Optional. If None, this corresponds that the file does not exist and the observation will be populated with +# zeroes. - A typical location for a service looks like this: - `['network','nodes',,'servics', ]` - :type where: Optional[List[str]] - """ - super().__init__() - self.where: Optional[Tuple[str]] = where +# A typical location for a service looks like this: +# `['network','nodes',,'servics', ]` +# :type where: Optional[List[str]] +# """ +# super().__init__() +# self.where: Optional[Tuple[str]] = where - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. +# def observe(self, state: Dict) -> Dict: +# """Generate observation based on the current state of the simulation. - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict - """ - if self.where is None: - return self.default_observation +# :param state: Simulation state dictionary +# :type state: Dict +# :return: Observation +# :rtype: Dict +# """ +# if self.where is None: +# return self.default_observation - link_state = access_from_nested_dict(state, self.where) - if link_state is NOT_PRESENT_IN_STATE: - return self.default_observation +# link_state = access_from_nested_dict(state, self.where) +# if link_state is NOT_PRESENT_IN_STATE: +# return self.default_observation - bandwidth = link_state["bandwidth"] - load = link_state["current_load"] - if load == 0: - utilisation_category = 0 - else: - utilisation_fraction = load / bandwidth - # 0 is UNUSED, 1 is 0%-10%. 2 is 10%-20%. 3 is 20%-30%. And so on... 10 is exactly 100% - utilisation_category = int(utilisation_fraction * 9) + 1 +# bandwidth = link_state["bandwidth"] +# load = link_state["current_load"] +# if load == 0: +# utilisation_category = 0 +# else: +# utilisation_fraction = load / bandwidth +# # 0 is UNUSED, 1 is 0%-10%. 2 is 10%-20%. 3 is 20%-30%. And so on... 10 is exactly 100% +# utilisation_category = int(utilisation_fraction * 9) + 1 - # TODO: once the links support separte load per protocol, this needs amendment to reflect that. - return {"PROTOCOLS": {"ALL": min(utilisation_category, 10)}} +# # TODO: once the links support separte load per protocol, this needs amendment to reflect that. +# return {"PROTOCOLS": {"ALL": min(utilisation_category, 10)}} - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape. +# @property +# def space(self) -> spaces.Space: +# """Gymnasium space object describing the observation space shape. - :return: Gymnasium space - :rtype: spaces.Space - """ - return spaces.Dict({"PROTOCOLS": spaces.Dict({"ALL": spaces.Discrete(11)})}) +# :return: Gymnasium space +# :rtype: spaces.Space +# """ +# return spaces.Dict({"PROTOCOLS": spaces.Dict({"ALL": spaces.Discrete(11)})}) - @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "LinkObservation": - """Create link observation from a config. +# @classmethod +# def from_config(cls, config: Dict, game: "PrimaiteGame") -> "LinkObservation": +# """Create link observation from a config. - :param config: Dictionary containing the configuration for this link observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :return: Constructed link observation - :rtype: LinkObservation - """ - return cls(where=["network", "links", game.ref_map_links[config["link_ref"]]]) +# :param config: Dictionary containing the configuration for this link observation. +# :type config: Dict +# :param game: Reference to the PrimaiteGame object that spawned this observation. +# :type game: PrimaiteGame +# :return: Constructed link observation +# :rtype: LinkObservation +# """ +# return cls(where=["network", "links", game.ref_map_links[config["link_ref"]]]) -class AclObservation(AbstractObservation): - """Observation of an Access Control List (ACL) in the network.""" +# class AclObservation(AbstractObservation): +# """Observation of an Access Control List (ACL) in the network.""" - # TODO: should where be optional, and we can use where=None to pad the observation space? - # definitely the current approach does not support tracking files that aren't specified by name, for example - # if a file is created at runtime, we have currently got no way of telling the observation space to track it. - # this needs adding, but not for the MVP. - def __init__( - self, - node_ip_to_id: Dict[str, int], - ports: List[int], - protocols: List[str], - where: Optional[Tuple[str]] = None, - num_rules: int = 10, - ) -> None: - """Initialise ACL observation. +# # TODO: should where be optional, and we can use where=None to pad the observation space? +# # definitely the current approach does not support tracking files that aren't specified by name, for example +# # if a file is created at runtime, we have currently got no way of telling the observation space to track it. +# # this needs adding, but not for the MVP. +# def __init__( +# self, +# node_ip_to_id: Dict[str, int], +# ports: List[int], +# protocols: List[str], +# where: Optional[Tuple[str]] = None, +# num_rules: int = 10, +# ) -> None: +# """Initialise ACL observation. - :param node_ip_to_id: Mapping between IP address and ID. - :type node_ip_to_id: Dict[str, int] - :param ports: List of ports which are part of the game that define the ordering when converting to an ID - :type ports: List[int] - :param protocols: List of protocols which are part of the game, defines ordering when converting to an ID - :type protocols: list[str] - :param where: Where in the simulation state dictionary to find the relevant information for this ACL. A typical - example may look like this: - ['network','nodes',,'acl','acl'] - :type where: Optional[Tuple[str]], optional - :param num_rules: , defaults to 10 - :type num_rules: int, optional - """ - super().__init__() - self.where: Optional[Tuple[str]] = where - self.num_rules: int = num_rules - self.node_to_id: Dict[str, int] = node_ip_to_id - "List of node IP addresses, order in this list determines how they are converted to an ID" - self.port_to_id: Dict[int, int] = {port: i + 2 for i, port in enumerate(ports)} - "List of ports which are part of the game that define the ordering when converting to an ID" - self.protocol_to_id: Dict[str, int] = {protocol: i + 2 for i, protocol in enumerate(protocols)} - "List of protocols which are part of the game, defines ordering when converting to an ID" - self.default_observation: Dict = { - i - + 1: { - "position": i, - "permission": 0, - "source_node_id": 0, - "source_port": 0, - "dest_node_id": 0, - "dest_port": 0, - "protocol": 0, - } - for i in range(self.num_rules) - } +# :param node_ip_to_id: Mapping between IP address and ID. +# :type node_ip_to_id: Dict[str, int] +# :param ports: List of ports which are part of the game that define the ordering when converting to an ID +# :type ports: List[int] +# :param protocols: List of protocols which are part of the game, defines ordering when converting to an ID +# :type protocols: list[str] +# :param where: Where in the simulation state dictionary to find the relevant information for this ACL. A typical +# example may look like this: +# ['network','nodes',,'acl','acl'] +# :type where: Optional[Tuple[str]], optional +# :param num_rules: , defaults to 10 +# :type num_rules: int, optional +# """ +# super().__init__() +# self.where: Optional[Tuple[str]] = where +# self.num_rules: int = num_rules +# self.node_to_id: Dict[str, int] = node_ip_to_id +# "List of node IP addresses, order in this list determines how they are converted to an ID" +# self.port_to_id: Dict[int, int] = {port: i + 2 for i, port in enumerate(ports)} +# "List of ports which are part of the game that define the ordering when converting to an ID" +# self.protocol_to_id: Dict[str, int] = {protocol: i + 2 for i, protocol in enumerate(protocols)} +# "List of protocols which are part of the game, defines ordering when converting to an ID" +# self.default_observation: Dict = { +# i +# + 1: { +# "position": i, +# "permission": 0, +# "source_node_id": 0, +# "source_port": 0, +# "dest_node_id": 0, +# "dest_port": 0, +# "protocol": 0, +# } +# for i in range(self.num_rules) +# } - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. +# def observe(self, state: Dict) -> Dict: +# """Generate observation based on the current state of the simulation. - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict - """ - if self.where is None: - return self.default_observation - acl_state: Dict = access_from_nested_dict(state, self.where) - if acl_state is NOT_PRESENT_IN_STATE: - return self.default_observation +# :param state: Simulation state dictionary +# :type state: Dict +# :return: Observation +# :rtype: Dict +# """ +# if self.where is None: +# return self.default_observation +# acl_state: Dict = access_from_nested_dict(state, self.where) +# if acl_state is NOT_PRESENT_IN_STATE: +# return self.default_observation - # TODO: what if the ACL has more rules than num of max rules for obs space - obs = {} - acl_items = dict(acl_state.items()) - i = 1 # don't show rule 0 for compatibility reasons. - while i < self.num_rules + 1: - rule_state = acl_items[i] - if rule_state is None: - obs[i] = { - "position": i - 1, - "permission": 0, - "source_node_id": 0, - "source_port": 0, - "dest_node_id": 0, - "dest_port": 0, - "protocol": 0, - } - else: - src_ip = rule_state["src_ip_address"] - src_node_id = 1 if src_ip is None else self.node_to_id[IPv4Address(src_ip)] - dst_ip = rule_state["dst_ip_address"] - dst_node_ip = 1 if dst_ip is None else self.node_to_id[IPv4Address(dst_ip)] - src_port = rule_state["src_port"] - src_port_id = 1 if src_port is None else self.port_to_id[src_port] - dst_port = rule_state["dst_port"] - dst_port_id = 1 if dst_port is None else self.port_to_id[dst_port] - protocol = rule_state["protocol"] - protocol_id = 1 if protocol is None else self.protocol_to_id[protocol] - obs[i] = { - "position": i - 1, - "permission": rule_state["action"], - "source_node_id": src_node_id, - "source_port": src_port_id, - "dest_node_id": dst_node_ip, - "dest_port": dst_port_id, - "protocol": protocol_id, - } - i += 1 - return obs +# # TODO: what if the ACL has more rules than num of max rules for obs space +# obs = {} +# acl_items = dict(acl_state.items()) +# i = 1 # don't show rule 0 for compatibility reasons. +# while i < self.num_rules + 1: +# rule_state = acl_items[i] +# if rule_state is None: +# obs[i] = { +# "position": i - 1, +# "permission": 0, +# "source_node_id": 0, +# "source_port": 0, +# "dest_node_id": 0, +# "dest_port": 0, +# "protocol": 0, +# } +# else: +# src_ip = rule_state["src_ip_address"] +# src_node_id = 1 if src_ip is None else self.node_to_id[IPv4Address(src_ip)] +# dst_ip = rule_state["dst_ip_address"] +# dst_node_ip = 1 if dst_ip is None else self.node_to_id[IPv4Address(dst_ip)] +# src_port = rule_state["src_port"] +# src_port_id = 1 if src_port is None else self.port_to_id[src_port] +# dst_port = rule_state["dst_port"] +# dst_port_id = 1 if dst_port is None else self.port_to_id[dst_port] +# protocol = rule_state["protocol"] +# protocol_id = 1 if protocol is None else self.protocol_to_id[protocol] +# obs[i] = { +# "position": i - 1, +# "permission": rule_state["action"], +# "source_node_id": src_node_id, +# "source_port": src_port_id, +# "dest_node_id": dst_node_ip, +# "dest_port": dst_port_id, +# "protocol": protocol_id, +# } +# i += 1 +# return obs - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape. +# @property +# def space(self) -> spaces.Space: +# """Gymnasium space object describing the observation space shape. - :return: Gymnasium space - :rtype: spaces.Space - """ - return spaces.Dict( - { - i - + 1: spaces.Dict( - { - "position": spaces.Discrete(self.num_rules), - "permission": spaces.Discrete(3), - # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) - "source_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), - "source_port": spaces.Discrete(len(self.port_to_id) + 2), - "dest_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), - "dest_port": spaces.Discrete(len(self.port_to_id) + 2), - "protocol": spaces.Discrete(len(self.protocol_to_id) + 2), - } - ) - for i in range(self.num_rules) - } - ) +# :return: Gymnasium space +# :rtype: spaces.Space +# """ +# return spaces.Dict( +# { +# i +# + 1: spaces.Dict( +# { +# "position": spaces.Discrete(self.num_rules), +# "permission": spaces.Discrete(3), +# # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) +# "source_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), +# "source_port": spaces.Discrete(len(self.port_to_id) + 2), +# "dest_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), +# "dest_port": spaces.Discrete(len(self.port_to_id) + 2), +# "protocol": spaces.Discrete(len(self.protocol_to_id) + 2), +# } +# ) +# for i in range(self.num_rules) +# } +# ) - @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "AclObservation": - """Generate ACL observation from a config. +# @classmethod +# def from_config(cls, config: Dict, game: "PrimaiteGame") -> "AclObservation": +# """Generate ACL observation from a config. - :param config: Dictionary containing the configuration for this ACL observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :return: Observation object - :rtype: AclObservation - """ - max_acl_rules = config["options"]["max_acl_rules"] - node_ip_to_idx = {} - for ip_idx, ip_map_config in enumerate(config["ip_address_order"]): - node_ref = ip_map_config["node_hostname"] - nic_num = ip_map_config["nic_num"] - node_obj = game.simulation.network.nodes[game.ref_map_nodes[node_ref]] - nic_obj = node_obj.network_interface[nic_num] - node_ip_to_idx[nic_obj.ip_address] = ip_idx + 2 +# :param config: Dictionary containing the configuration for this ACL observation. +# :type config: Dict +# :param game: Reference to the PrimaiteGame object that spawned this observation. +# :type game: PrimaiteGame +# :return: Observation object +# :rtype: AclObservation +# """ +# max_acl_rules = config["options"]["max_acl_rules"] +# node_ip_to_idx = {} +# for ip_idx, ip_map_config in enumerate(config["ip_address_order"]): +# node_ref = ip_map_config["node_hostname"] +# nic_num = ip_map_config["nic_num"] +# node_obj = game.simulation.network.nodes[game.ref_map_nodes[node_ref]] +# nic_obj = node_obj.network_interface[nic_num] +# node_ip_to_idx[nic_obj.ip_address] = ip_idx + 2 - router_hostname = config["router_hostname"] - return cls( - node_ip_to_id=node_ip_to_idx, - ports=game.options.ports, - protocols=game.options.protocols, - where=["network", "nodes", router_hostname, "acl", "acl"], - num_rules=max_acl_rules, - ) +# router_hostname = config["router_hostname"] +# return cls( +# node_ip_to_id=node_ip_to_idx, +# ports=game.options.ports, +# protocols=game.options.protocols, +# where=["network", "nodes", router_hostname, "acl", "acl"], +# num_rules=max_acl_rules, +# ) -class NullObservation(AbstractObservation): - """Null observation, returns a single 0 value for the observation space.""" +# class NullObservation(AbstractObservation): +# """Null observation, returns a single 0 value for the observation space.""" - def __init__(self, where: Optional[List[str]] = None): - """Initialise null observation.""" - self.default_observation: Dict = {} +# def __init__(self, where: Optional[List[str]] = None): +# """Initialise null observation.""" +# self.default_observation: Dict = {} - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation.""" - return 0 +# def observe(self, state: Dict) -> Dict: +# """Generate observation based on the current state of the simulation.""" +# return 0 - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" - return spaces.Discrete(1) +# @property +# def space(self) -> spaces.Space: +# """Gymnasium space object describing the observation space shape.""" +# return spaces.Discrete(1) - @classmethod - def from_config(cls, config: Dict, game: Optional["PrimaiteGame"] = None) -> "NullObservation": - """ - Create null observation from a config. +# @classmethod +# def from_config(cls, config: Dict, game: Optional["PrimaiteGame"] = None) -> "NullObservation": +# """ +# Create null observation from a config. - The parameters are ignored, they are here to match the signature of the other observation classes. - """ - return cls() +# The parameters are ignored, they are here to match the signature of the other observation classes. +# """ +# return cls() -class ICSObservation(NullObservation): - """ICS observation placeholder, currently not implemented so always returns a single 0.""" +# class ICSObservation(NullObservation): +# """ICS observation placeholder, currently not implemented so always returns a single 0.""" - pass +# pass diff --git a/src/primaite/game/agent/utils.py b/src/primaite/game/agent/utils.py index 1314087c..42e8f30b 100644 --- a/src/primaite/game/agent/utils.py +++ b/src/primaite/game/agent/utils.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, Hashable, Sequence +from typing import Any, Dict, Hashable, Optional, Sequence NOT_PRESENT_IN_STATE = object() """ @@ -7,7 +7,7 @@ the thing requested in the state could equal None. This NOT_PRESENT_IN_STATE is """ -def access_from_nested_dict(dictionary: Dict, keys: Sequence[Hashable]) -> Any: +def access_from_nested_dict(dictionary: Dict, keys: Optional[Sequence[Hashable]]) -> Any: """ Access an item from a deeply dictionary with a list of keys. @@ -21,6 +21,8 @@ def access_from_nested_dict(dictionary: Dict, keys: Sequence[Hashable]) -> Any: :return: The value in the dictionary :rtype: Any """ + if keys is None: + return NOT_PRESENT_IN_STATE key_list = [*keys] # copy keys to a new list to prevent editing original list if len(key_list) == 0: return dictionary diff --git a/tests/integration_tests/game_layer/observations/test_node_observations.py b/tests/integration_tests/game_layer/observations/test_node_observations.py index dce05b6a..a5195e1e 100644 --- a/tests/integration_tests/game_layer/observations/test_node_observations.py +++ b/tests/integration_tests/game_layer/observations/test_node_observations.py @@ -4,7 +4,7 @@ from uuid import uuid4 import pytest from gymnasium import spaces -from primaite.game.agent.observations.node_observations import NodeObservation +from primaite.game.agent.observations.host import NodeObservation from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.sim_container import Simulation From 0d0b5bc7d9fc64549f19017ded0569bfe9ba45ce Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 27 Mar 2024 22:11:37 +0000 Subject: [PATCH 752/980] fix previous commit --- src/primaite/game/agent/observations/agent_observations.py | 2 +- .../game_layer/observations/test_node_observations.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/game/agent/observations/agent_observations.py b/src/primaite/game/agent/observations/agent_observations.py index 2148697b..10370660 100644 --- a/src/primaite/game/agent/observations/agent_observations.py +++ b/src/primaite/game/agent/observations/agent_observations.py @@ -2,7 +2,7 @@ from typing import Dict, List, Optional, Tuple, TYPE_CHECKING from gymnasium import spaces -from primaite.game.agent.observations.host import NodeObservation +from primaite.game.agent.observations.node_observations import NodeObservation from primaite.game.agent.observations.observations import ( AbstractObservation, AclObservation, diff --git a/tests/integration_tests/game_layer/observations/test_node_observations.py b/tests/integration_tests/game_layer/observations/test_node_observations.py index a5195e1e..dce05b6a 100644 --- a/tests/integration_tests/game_layer/observations/test_node_observations.py +++ b/tests/integration_tests/game_layer/observations/test_node_observations.py @@ -4,7 +4,7 @@ from uuid import uuid4 import pytest from gymnasium import spaces -from primaite.game.agent.observations.host import NodeObservation +from primaite.game.agent.observations.node_observations import NodeObservation from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.sim_container import Simulation From cddb39e8e90709de243e2b8e9b2fb938ed37900e Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Thu, 28 Mar 2024 10:43:57 +0000 Subject: [PATCH 753/980] #2405 update docstrings --- src/primaite/simulator/network/hardware/base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 132fc8b1..1e29ceb6 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1312,7 +1312,10 @@ class Node(SimComponent): :param application: Application instance that has not been installed on any node yet. :type application: Application - :parm + :param ip_address: IP address used to configure the application + (target IP for the DoSBot or server IP for the DataManipulationBot) + :type ip_address: str + :return: True if the application is installed successfully, otherwise False. """ if application in self: _LOGGER.warning( @@ -1356,6 +1359,7 @@ class Node(SimComponent): :param application: Application object that is currently associated with this node. :type application: Application + :return: True if the application is uninstalled successfully, otherwise False. """ if application.__name__ not in self.software_manager.software: _LOGGER.warning( From d5b5c7d47a84768a512006226680536a7be6862c Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Thu, 28 Mar 2024 11:02:26 +0000 Subject: [PATCH 754/980] #2405 simplify implementation --- .../simulator/network/hardware/base.py | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 1e29ceb6..c464e9bf 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1325,23 +1325,17 @@ class Node(SimComponent): application_instance = self.software_manager.software.get(str(application.__name__)) self.applications[application_instance.uuid] = application_instance - application.parent = self - self.sys_log.info(f"Installed application {application.__name__}") - _LOGGER.debug(f"Added application {application.__name__} to node {self.hostname}") + self.sys_log.info(f"Installed application {application_instance.name}") + _LOGGER.debug(f"Added application {application_instance.name} to node {self.hostname}") self._application_request_manager.add_request( application_instance.name, RequestType(func=application_instance._request_manager) ) # Configure application if additional parameters are given if ip_address: - from primaite.simulator.system.applications.red_applications.data_manipulation_bot import ( - DataManipulationBot, - ) - from primaite.simulator.system.applications.red_applications.dos_bot import DoSBot - - if application == DoSBot: + if application_instance.name == "DoSBot": application_instance.configure(target_ip_address=IPv4Address(ip_address)) - elif application == DataManipulationBot: + elif application_instance.name == "DataManipulationBot": application_instance.configure(server_ip_address=IPv4Address(ip_address)) else: pass @@ -1370,11 +1364,12 @@ class Node(SimComponent): str(application.__name__) ) # This works because we can't have two applications with the same name on the same node self.applications.pop(application_instance.uuid) - application.parent = None - self.sys_log.info(f"Uninstalled application {application.__name__}") - _LOGGER.info(f"Removed application {application.__name__} from node {self.hostname}") + application_instance.parent = None + self.sys_log.info(f"Uninstalled application {application_instance.name}") + _LOGGER.info(f"Removed application {application_instance.name} from node {self.hostname}") self._application_request_manager.remove_request(application_instance.name) self.software_manager.uninstall(application_instance.name) + if application_instance.name not in self.software_manager.software: return True else: From 9b6135524efcf4f1aa0f05a9c0f02f9429e27579 Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Thu, 28 Mar 2024 11:08:30 +0000 Subject: [PATCH 755/980] #2504 update application_install_action docstring --- src/primaite/simulator/network/hardware/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index c464e9bf..239ef687 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1310,7 +1310,7 @@ class Node(SimComponent): This method is useful for allowing agents to take this action. - :param application: Application instance that has not been installed on any node yet. + :param application: Application object that has not been installed on any node yet. :type application: Application :param ip_address: IP address used to configure the application (target IP for the DoSBot or server IP for the DataManipulationBot) From 4301f3fdba18a013c518e20c7e56d91ff4a63344 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Mar 2024 12:06:23 +0000 Subject: [PATCH 756/980] #2418 Add Printer and Wireless router to config parser --- src/primaite/game/game.py | 15 +++++++++++++-- .../network/hardware/nodes/host/server.py | 6 ++++++ tests/assets/configs/test_primaite_session.yaml | 6 ++++++ .../test_primaite_session.py | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 05b76679..6ba7e63c 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -15,10 +15,11 @@ from primaite.game.science import graph_has_cycle, topological_sort from primaite.simulator.network.hardware.base import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC -from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.host.server import Printer, Server from primaite.simulator.network.hardware.nodes.network.firewall import Firewall from primaite.simulator.network.hardware.nodes.network.router import Router from primaite.simulator.network.hardware.nodes.network.switch import Switch +from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter from primaite.simulator.network.nmne import set_nmne_config from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.sim_container import Simulation @@ -273,8 +274,18 @@ class PrimaiteGame: new_node = Router.from_config(node_cfg) elif n_type == "firewall": new_node = Firewall.from_config(node_cfg) + elif n_type == "wireless_router": + new_node = WirelessRouter.from_config(node_cfg) + elif n_type == "printer": + new_node = Printer( + hostname=node_cfg["hostname"], + ip_address=node_cfg["ip_address"], + subnet_mask=node_cfg["subnet_mask"], + ) else: - _LOGGER.warning(f"invalid node type {n_type} in config") + msg = f"invalid node type {n_type} in config" + _LOGGER.error(msg) + raise ValueError(msg) if "services" in node_cfg: for service_cfg in node_cfg["services"]: new_service = None diff --git a/src/primaite/simulator/network/hardware/nodes/host/server.py b/src/primaite/simulator/network/hardware/nodes/host/server.py index 9f5157ad..593cd0dd 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/server.py +++ b/src/primaite/simulator/network/hardware/nodes/host/server.py @@ -28,3 +28,9 @@ class Server(HostNode): * Applications: * Web Browser """ + + +class Printer(HostNode): + """Printer? I don't even know her!.""" + + # TODO: Implement printer-specific behaviour diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index a8b33032..e1b0ac7b 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -681,6 +681,12 @@ simulation: - ref: client_2_dns_client type: DNSClient + - ref: HP_LaserJet_Pro_4102fdn_printer + type: printer + hostname: HP_LaserJet_Pro_4102fdn_printer + ip_address: 192.168.10.99 + subnet_mask: 255.255.255.0 + links: - ref: router_1___switch_1 endpoint_a_ref: router_1 diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index c45a4690..7febe39a 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -29,7 +29,7 @@ class TestPrimaiteSession: assert session.env assert session.env.game.simulation.network - assert len(session.env.game.simulation.network.nodes) == 10 + assert len(session.env.game.simulation.network.nodes) == 11 @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) From b12dee73ba5ac4e4b29713ed49cee5d9c929d47f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Mar 2024 13:21:22 +0000 Subject: [PATCH 757/980] #2418 Fix wireless router from config --- .../network/hardware/nodes/network/router.py | 2 +- .../hardware/nodes/network/wireless_router.py | 69 ++++++++++++++++++- .../assets/configs/test_primaite_session.yaml | 27 ++++++++ .../test_primaite_session.py | 9 ++- 4 files changed, 103 insertions(+), 4 deletions(-) diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index d2b47c1a..de308547 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1418,7 +1418,7 @@ class Router(NetworkNode): :return: Configured router. :rtype: Router """ - router = Router( + router = cls( hostname=cfg["hostname"], num_ports=int(cfg.get("num_ports", "5")), operating_state=NodeOperatingState.ON diff --git a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py index 3e8d715f..4bd3d101 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py @@ -1,10 +1,14 @@ +from ipaddress import IPv4Address from typing import Any, Dict, Union from pydantic import validate_call from primaite.simulator.network.airspace import AirSpaceFrequency, IPWirelessNetworkInterface -from primaite.simulator.network.hardware.nodes.network.router import Router, RouterInterface +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router, RouterInterface from primaite.simulator.network.transmission.data_link_layer import Frame +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port from primaite.utils.validators import IPV4Address @@ -209,3 +213,66 @@ class WirelessRouter(Router): raise NotImplementedError( "Please use the 'configure_wireless_access_point' and 'configure_router_interface' functions." ) + + @classmethod + def from_config(cls, cfg: Dict) -> "WirelessRouter": + """Generate the wireless router from config. + + Schema: + - hostname (str): unique name for this router. + - router_interface (dict): The values should be another dict specifying + - ip_address (str) + - subnet_mask (str) + - wireless_access_point (dict): Dict with + - ip address, + - subnet mask, + - frequency, (string: either WIFI_2_4 or WIFI_5) + - acl (dict): Dict with integers from 1 - max_acl_rules as keys. The key defines the position within the ACL + where the rule will be added (lower number is resolved first). The values should describe valid ACL + Rules as: + - action (str): either PERMIT or DENY + - src_port (str, optional): the named port such as HTTP, HTTPS, or POSTGRES_SERVER + - dst_port (str, optional): the named port such as HTTP, HTTPS, or POSTGRES_SERVER + - protocol (str, optional): the named IP protocol such as ICMP, TCP, or UDP + - src_ip_address (str, optional): IP address octet written in base 10 + - dst_ip_address (str, optional): IP address octet written in base 10 + + :param cfg: Config dictionary + :type cfg: Dict + :return: WirelessRouter instance. + :rtype: WirelessRouter + """ + operating_state = ( + NodeOperatingState.ON if not (p := cfg.get("operating_state")) else NodeOperatingState[p.upper()] + ) + router = cls(hostname=cfg["hostname"], operating_state=operating_state) + if "router_interface" in cfg: + ip_address = cfg["router_interface"]["ip_address"] + subnet_mask = cfg["router_interface"]["subnet_mask"] + router.configure_router_interface(ip_address=ip_address, subnet_mask=subnet_mask) + if "wireless_access_point" in cfg: + ip_address = cfg["wireless_access_point"]["ip_address"] + subnet_mask = cfg["wireless_access_point"]["subnet_mask"] + frequency = AirSpaceFrequency[cfg["wireless_access_point"]["frequency"]] + router.configure_wireless_access_point(ip_address=ip_address, subnet_mask=subnet_mask, frequency=frequency) + + if "acl" in cfg: + for r_num, r_cfg in cfg["acl"].items(): + router.acl.add_rule( + action=ACLAction[r_cfg["action"]], + src_port=None if not (p := r_cfg.get("src_port")) else Port[p], + dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], + protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], + src_ip_address=r_cfg.get("src_ip"), + dst_ip_address=r_cfg.get("dst_ip"), + position=r_num, + ) + if "routes" in cfg: + for route in cfg.get("routes"): + router.route_table.add_route( + address=IPv4Address(route.get("address")), + subnet_mask=IPv4Address(route.get("subnet_mask", "255.255.255.0")), + next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")), + metric=float(route.get("metric", 0)), + ) + return router diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index e1b0ac7b..0ce3fee7 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -687,6 +687,33 @@ simulation: ip_address: 192.168.10.99 subnet_mask: 255.255.255.0 + - ref: router_2 + type: wireless_router + hostname: router_2 + router_interface: + ip_address: 192.169.1.1 + subnet_mask: 255.255.255.0 + wireless_access_point: + ip_address: 192.169.1.1 + subnet_mask: 255.255.255.0 + frequency: WIFI_2_4 + acl: + 0: + action: PERMIT + src_port: POSTGRES_SERVER + dst_port: POSTGRES_SERVER + 1: + action: PERMIT + src_port: DNS + dst_port: DNS + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + links: - ref: router_1___switch_1 endpoint_a_ref: router_1 diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index 7febe39a..32f134a3 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -1,6 +1,8 @@ import pydantic import pytest +from primaite.simulator.network.hardware.nodes.host.server import Printer +from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter from tests import TEST_ASSETS_ROOT from tests.conftest import TempPrimaiteSession @@ -11,7 +13,6 @@ MISCONFIGURED_PATH = TEST_ASSETS_ROOT / "configs/bad_primaite_session.yaml" MULTI_AGENT_PATH = TEST_ASSETS_ROOT / "configs/multi_agent_session.yaml" -# @pytest.mark.skip(reason="no way of currently testing this") class TestPrimaiteSession: @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) def test_creating_session(self, temp_primaite_session): @@ -29,7 +30,11 @@ class TestPrimaiteSession: assert session.env assert session.env.game.simulation.network - assert len(session.env.game.simulation.network.nodes) == 11 + assert len(session.env.game.simulation.network.nodes) == 12 + wireless = session.env.game.simulation.network.get_node_by_hostname("router_2") + assert isinstance(wireless, WirelessRouter) + printer = session.env.game.simulation.network.get_node_by_hostname("HP_LaserJet_Pro_4102fdn_printer") + assert isinstance(printer, Printer) @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) From e21c59dff1d149abd21abca2a73e42e66d54ac95 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Mar 2024 16:23:39 +0000 Subject: [PATCH 758/980] #2418 - Change test config --- tests/assets/configs/test_primaite_session.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 0ce3fee7..b131c1b7 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -694,7 +694,7 @@ simulation: ip_address: 192.169.1.1 subnet_mask: 255.255.255.0 wireless_access_point: - ip_address: 192.169.1.1 + ip_address: 192.170.1.1 subnet_mask: 255.255.255.0 frequency: WIFI_2_4 acl: From c29c3971fab30467cf6b770a6ce7c7f1b1cb3bb9 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Mar 2024 21:48:17 +0000 Subject: [PATCH 759/980] #2418 - add wildcard masks and from_config tests to routers --- .../network/hardware/nodes/network/router.py | 2 + .../hardware/nodes/network/wireless_router.py | 2 + .../_network/_hardware/nodes/test_router.py | 111 ++++++++++++++++++ .../_hardware/nodes/test_wireless_router.py | 97 +++++++++++++++ 4 files changed, 212 insertions(+) create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py create mode 100644 tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_wireless_router.py diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index de308547..102eb7dc 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1441,6 +1441,8 @@ class Router(NetworkNode): protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], src_ip_address=r_cfg.get("src_ip"), dst_ip_address=r_cfg.get("dst_ip"), + src_wildcard_mask=r_cfg.get("src_wildcard_mask"), + dst_wildcard_mask=r_cfg.get("dst_wildcard_mask"), position=r_num, ) if "routes" in cfg: diff --git a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py index 4bd3d101..62332269 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py @@ -265,6 +265,8 @@ class WirelessRouter(Router): protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], src_ip_address=r_cfg.get("src_ip"), dst_ip_address=r_cfg.get("dst_ip"), + src_wildcard_mask=r_cfg.get("src_wildcard_mask"), + dst_wildcard_mask=r_cfg.get("dst_wildcard_mask"), position=r_num, ) if "routes" in cfg: diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py new file mode 100644 index 00000000..be74a721 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_router.py @@ -0,0 +1,111 @@ +from ipaddress import IPv4Address + +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port + + +def test_wireless_router_from_config(): + cfg = { + "ref": "router_1", + "type": "router", + "hostname": "router_1", + "num_ports": 6, + "ports": { + 1: { + "ip_address": "192.168.1.1", + "subnet_mask": "255.255.255.0", + }, + 2: { + "ip_address": "192.168.2.1", + "subnet_mask": "255.255.255.0", + }, + }, + "acl": { + 0: { + "action": "PERMIT", + "src_port": "POSTGRES_SERVER", + "dst_port": "POSTGRES_SERVER", + }, + 1: { + "action": "PERMIT", + "protocol": "ICMP", + }, + 2: { + "action": "PERMIT", + "src_ip": "100.100.100.1", + "dst_ip": "100.100.101.1", + }, + 3: { + "action": "PERMIT", + "src_ip": "100.100.102.0", + "dst_ip": "100.100.103.0", + "src_wildcard_mask": "0.0.0.255", + "dst_wildcard_mask": "0.0.0.255", + }, + 20: { + "action": "DENY", + }, + }, + } + + rt = Router.from_config(cfg=cfg) + + assert rt.num_ports == 6 + + assert rt.network_interface[1].ip_address == IPv4Address("192.168.1.1") + assert rt.network_interface[1].subnet_mask == IPv4Address("255.255.255.0") + + assert rt.network_interface[2].ip_address == IPv4Address("192.168.2.1") + assert rt.network_interface[2].subnet_mask == IPv4Address("255.255.255.0") + + assert not rt.network_interface[3].enabled + assert not rt.network_interface[4].enabled + assert not rt.network_interface[5].enabled + assert not rt.network_interface[6].enabled + + r0 = rt.acl.acl[0] + assert r0.action == ACLAction.PERMIT + assert r0.src_port == r0.dst_port == Port.POSTGRES_SERVER + assert r0.src_ip_address == r0.dst_ip_address == r0.dst_wildcard_mask == r0.src_wildcard_mask == r0.protocol == None + + r1 = rt.acl.acl[1] + assert r1.action == ACLAction.PERMIT + assert r1.protocol == IPProtocol.ICMP + assert ( + r1.src_ip_address + == r1.dst_ip_address + == r1.dst_wildcard_mask + == r1.src_wildcard_mask + == r1.src_port + == r1.dst_port + == None + ) + + r2 = rt.acl.acl[2] + assert r2.action == ACLAction.PERMIT + assert r2.src_ip_address == IPv4Address("100.100.100.1") + assert r2.dst_ip_address == IPv4Address("100.100.101.1") + assert r2.src_wildcard_mask == r2.dst_wildcard_mask == None + assert r2.src_port == r2.dst_port == r2.protocol == None + + r3 = rt.acl.acl[3] + assert r3.action == ACLAction.PERMIT + assert r3.src_ip_address == IPv4Address("100.100.102.0") + assert r3.dst_ip_address == IPv4Address("100.100.103.0") + assert r3.src_wildcard_mask == IPv4Address("0.0.0.255") + assert r3.dst_wildcard_mask == IPv4Address("0.0.0.255") + assert r3.src_port == r3.dst_port == r3.protocol == None + + r20 = rt.acl.acl[20] + assert r20.action == ACLAction.DENY + assert ( + r20.src_ip_address + == r20.dst_ip_address + == r20.src_wildcard_mask + == r20.dst_wildcard_mask + == r20.src_port + == r20.dst_port + == r20.protocol + == None + ) diff --git a/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_wireless_router.py b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_wireless_router.py new file mode 100644 index 00000000..494f5a15 --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_network/_hardware/nodes/test_wireless_router.py @@ -0,0 +1,97 @@ +from ipaddress import IPv4Address + +from primaite.simulator.network.hardware.nodes.network.router import ACLAction +from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port + + +def test_wireless_router_from_config(): + cfg = { + "ref": "router_2", + "type": "wireless_router", + "hostname": "router_2", + "router_interface": { + "ip_address": "192.168.1.1", + "subnet_mask": "255.255.255.0", + }, + "wireless_access_point": { + "ip_address": "192.170.1.1", + "subnet_mask": "255.255.255.0", + "frequency": "WIFI_2_4", + }, + "acl": { + 0: { + "action": "PERMIT", + "src_port": "POSTGRES_SERVER", + "dst_port": "POSTGRES_SERVER", + }, + 1: { + "action": "PERMIT", + "protocol": "ICMP", + }, + 2: { + "action": "PERMIT", + "src_ip": "100.100.100.1", + "dst_ip": "100.100.101.1", + }, + 3: { + "action": "PERMIT", + "src_ip": "100.100.102.0", + "dst_ip": "100.100.103.0", + "src_wildcard_mask": "0.0.0.255", + "dst_wildcard_mask": "0.0.0.255", + }, + 20: { + "action": "DENY", + }, + }, + } + + rt = WirelessRouter.from_config(cfg=cfg) + + r0 = rt.acl.acl[0] + assert r0.action == ACLAction.PERMIT + assert r0.src_port == r0.dst_port == Port.POSTGRES_SERVER + assert r0.src_ip_address == r0.dst_ip_address == r0.dst_wildcard_mask == r0.src_wildcard_mask == r0.protocol == None + + r1 = rt.acl.acl[1] + assert r1.action == ACLAction.PERMIT + assert r1.protocol == IPProtocol.ICMP + assert ( + r1.src_ip_address + == r1.dst_ip_address + == r1.dst_wildcard_mask + == r1.src_wildcard_mask + == r1.src_port + == r1.dst_port + == None + ) + + r2 = rt.acl.acl[2] + assert r2.action == ACLAction.PERMIT + assert r2.src_ip_address == IPv4Address("100.100.100.1") + assert r2.dst_ip_address == IPv4Address("100.100.101.1") + assert r2.src_wildcard_mask == r2.dst_wildcard_mask == None + assert r2.src_port == r2.dst_port == r2.protocol == None + + r3 = rt.acl.acl[3] + assert r3.action == ACLAction.PERMIT + assert r3.src_ip_address == IPv4Address("100.100.102.0") + assert r3.dst_ip_address == IPv4Address("100.100.103.0") + assert r3.src_wildcard_mask == IPv4Address("0.0.0.255") + assert r3.dst_wildcard_mask == IPv4Address("0.0.0.255") + assert r3.src_port == r3.dst_port == r3.protocol == None + + r20 = rt.acl.acl[20] + assert r20.action == ACLAction.DENY + assert ( + r20.src_ip_address + == r20.dst_ip_address + == r20.src_wildcard_mask + == r20.dst_wildcard_mask + == r20.src_port + == r20.dst_port + == r20.protocol + == None + ) From 09caa55c6524865be855ae72f2bf24261f513d1c Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 26 Mar 2024 21:51:27 +0000 Subject: [PATCH 760/980] #2418 - Add printer and wireless router as node types in network show --- src/primaite/simulator/network/container.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 0e970c3d..5ec47052 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -8,6 +8,7 @@ from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import Link, Node, WiredNetworkInterface +from primaite.simulator.network.hardware.nodes.host.server import Printer from primaite.simulator.system.applications.application import Application from primaite.simulator.system.services.service import Service @@ -110,6 +111,16 @@ class Network(SimComponent): """The Firewalls in the Network.""" return [node for node in self.nodes.values() if node.__class__.__name__ == "Firewall"] + @property + def printer_nodes(self) -> List[Node]: + """The printers on the network.""" + return [node for node in self.nodes.values() if isinstance(node, Printer)] + + @property + def wireless_router_nodes(self) -> List[Node]: + """The Routers in the Network.""" + return [node for node in self.nodes.values() if node.__class__.__name__ == "WirelessRouter"] + def show(self, nodes: bool = True, ip_addresses: bool = True, links: bool = True, markdown: bool = False): """ Print tables describing the Network. @@ -128,6 +139,8 @@ class Network(SimComponent): "Switch": self.switch_nodes, "Server": self.server_nodes, "Computer": self.computer_nodes, + "Printer": self.printer_nodes, + "Wireless Router": self.wireless_routers, } if nodes: table = PrettyTable(["Node", "Type", "Operating State"]) From 350b98831851518f26aa3b34c94f124e1a1041f7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 27 Mar 2024 00:00:06 +0000 Subject: [PATCH 761/980] #2418 Fix broken property --- src/primaite/simulator/network/container.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 5ec47052..a4079fb8 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -140,7 +140,7 @@ class Network(SimComponent): "Server": self.server_nodes, "Computer": self.computer_nodes, "Printer": self.printer_nodes, - "Wireless Router": self.wireless_routers, + "Wireless Router": self.wireless_router_nodes, } if nodes: table = PrettyTable(["Node", "Type", "Operating State"]) From 8612842b74f7520c58fa37401925a17e5747ed2c Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Thu, 28 Mar 2024 12:01:36 +0000 Subject: [PATCH 762/980] #2405 remove .lower from _read_application_type, rename _software_manager to _software_request_manager in base.py --- src/primaite/simulator/network/hardware/base.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 239ef687..721bc1cd 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -846,10 +846,10 @@ class Node(SimComponent): ) rm.add_request("os", RequestType(func=self._os_request_manager, validator=_node_is_on)) - self._software_manager = RequestManager() - rm.add_request("software_manager", RequestType(func=self._software_manager, validator=_node_is_on)) + self._software_request_manager = RequestManager() + rm.add_request("software_manager", RequestType(func=self._software_request_manager, validator=_node_is_on)) self._application_manager = RequestManager() - self._software_manager.add_request(name="application", request_type=RequestType(func=self._application_manager)) + self._software_request_manager.add_request(name="application", request_type=RequestType(func=self._application_manager)) self._application_manager.add_request( name="install", @@ -879,17 +879,17 @@ class Node(SimComponent): def _read_application_type(self, application_class_str: str) -> Type[IOSoftwareClass]: """Wrapper that converts the string from the request manager into the appropriate class for the application.""" - if application_class_str.lower() == "DoSBot".lower(): + if application_class_str == "DoSBot": from primaite.simulator.system.applications.red_applications.dos_bot import DoSBot return DoSBot - elif application_class_str.lower() == "DataManipulationBot".lower(): + elif application_class_str == "DataManipulationBot": from primaite.simulator.system.applications.red_applications.data_manipulation_bot import ( DataManipulationBot, ) return DataManipulationBot - elif application_class_str.lower() == "WebBrowser".lower(): + elif application_class_str == "WebBrowser": from primaite.simulator.system.applications.web_browser import WebBrowser return WebBrowser From f83d9cb1b01c5ddef20337a80de4da36ae176050 Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Thu, 28 Mar 2024 12:14:05 +0000 Subject: [PATCH 763/980] #2405 refactor application_uninstall_action to re-use existing code in uninstall_application --- src/primaite/simulator/network/hardware/base.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 721bc1cd..754c7a24 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -849,7 +849,9 @@ class Node(SimComponent): self._software_request_manager = RequestManager() rm.add_request("software_manager", RequestType(func=self._software_request_manager, validator=_node_is_on)) self._application_manager = RequestManager() - self._software_request_manager.add_request(name="application", request_type=RequestType(func=self._application_manager)) + self._software_request_manager.add_request( + name="application", request_type=RequestType(func=self._application_manager) + ) self._application_manager.add_request( name="install", @@ -1321,8 +1323,9 @@ class Node(SimComponent): _LOGGER.warning( f"Can't add application {application.__name__}" + f"to node {self.hostname}. It's already installed." ) - self.software_manager.install(application) + return True + self.software_manager.install(application) application_instance = self.software_manager.software.get(str(application.__name__)) self.applications[application_instance.uuid] = application_instance self.sys_log.info(f"Installed application {application_instance.name}") @@ -1360,14 +1363,11 @@ class Node(SimComponent): f"Can't remove application {application.__name__}" + f"from node {self.hostname}. It's not installed." ) return True + application_instance = self.software_manager.software.get( str(application.__name__) ) # This works because we can't have two applications with the same name on the same node - self.applications.pop(application_instance.uuid) - application_instance.parent = None - self.sys_log.info(f"Uninstalled application {application_instance.name}") - _LOGGER.info(f"Removed application {application_instance.name} from node {self.hostname}") - self._application_request_manager.remove_request(application_instance.name) + self.uninstall_application(application_instance) self.software_manager.uninstall(application_instance.name) if application_instance.name not in self.software_manager.software: From 1e1eea47f139ae24c1b413cef9041b399b7210df Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Thu, 28 Mar 2024 14:08:08 +0000 Subject: [PATCH 764/980] #2405 add e2e test for application install and uninstall, refactor input params --- src/primaite/game/agent/actions.py | 19 +- .../configs/test_application_install.yaml | 986 ++++++++++++++++++ tests/conftest.py | 4 +- .../test_uc2_data_manipulation_scenario.py | 29 + .../game_layer/test_actions.py | 4 +- 5 files changed, 1026 insertions(+), 16 deletions(-) create mode 100644 tests/assets/configs/test_application_install.yaml diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 7c31ae7e..e22c882c 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -222,15 +222,11 @@ class NodeApplicationFixAction(NodeApplicationAbstractAction): class NodeApplicationInstallAction(AbstractAction): """Action which installs an application.""" - def __init__( - self, manager: "ActionManager", num_nodes: int, application_name: str, ip_address: str, **kwargs - ) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes} - self.application_name = application_name - self.ip_address = ip_address - def form_request(self, node_id: int) -> List[str]: + def form_request(self, node_id: int, application_name: str, ip_address: str) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" node_name = self.manager.get_node_name_by_idx(node_id) if node_name is None: @@ -242,25 +238,24 @@ class NodeApplicationInstallAction(AbstractAction): "software_manager", "application", "install", - self.application_name, - self.ip_address, + application_name, + ip_address, ] class NodeApplicationRemoveAction(AbstractAction): """Action which removes/uninstalls an application.""" - def __init__(self, manager: "ActionManager", num_nodes: int, application_name: str, **kwargs) -> None: + def __init__(self, manager: "ActionManager", num_nodes: int, **kwargs) -> None: super().__init__(manager=manager) self.shape: Dict[str, int] = {"node_id": num_nodes} - self.application_name = application_name - def form_request(self, node_id: int) -> List[str]: + def form_request(self, node_id: int, application_name: str) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" node_name = self.manager.get_node_name_by_idx(node_id) if node_name is None: return ["do_nothing"] - return ["network", "node", node_name, "software_manager", "application", "uninstall", self.application_name] + return ["network", "node", node_name, "software_manager", "application", "uninstall", application_name] class NodeFolderAbstractAction(AbstractAction): diff --git a/tests/assets/configs/test_application_install.yaml b/tests/assets/configs/test_application_install.yaml new file mode 100644 index 00000000..c1908fc4 --- /dev/null +++ b/tests/assets/configs/test_application_install.yaml @@ -0,0 +1,986 @@ +training_config: + rl_framework: SB3 + rl_algorithm: PPO + seed: 333 + n_learn_episodes: 1 + n_eval_episodes: 5 + max_steps_per_episode: 128 + deterministic_eval: false + n_agents: 1 + agent_references: + - defender + +io_settings: + save_agent_actions: true + save_step_metadata: false + save_pcap_logs: false + save_sys_logs: false + + +game: + max_episode_length: 128 + ports: + - HTTP + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + - UDP + thresholds: + nmne: + high: 10 + medium: 5 + low: 0 + +agents: + - ref: client_2_green_user + team: GREEN + type: ProbabilisticAgent + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_2 + applications: + - application_name: WebBrowser + - application_name: DatabaseClient + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 + + reward_function: + reward_components: + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.25 + options: + node_hostname: client_2 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.05 + options: + node_hostname: client_2 + + - ref: client_1_green_user + team: GREEN + type: ProbabilisticAgent + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 + observation_space: + type: UC2GreenObservation + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_1 + applications: + - application_name: WebBrowser + - application_name: DatabaseClient + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 + + reward_function: + reward_components: + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.25 + options: + node_hostname: client_1 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.05 + options: + node_hostname: client_1 + + + + + + - ref: data_manipulation_attacker + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: + type: UC2RedObservation + options: + nodes: {} + + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_1 + applications: + - application_name: DataManipulationBot + - node_name: client_2 + applications: + - application_name: DataManipulationBot + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 + + - ref: defender + team: BLUE + type: ProxyAgent + + observation_space: + type: UC2BlueObservation + options: + num_services_per_node: 1 + num_folders_per_node: 1 + num_files_per_folder: 1 + num_nics_per_node: 2 + nodes: + - node_hostname: domain_controller + services: + - service_name: DNSServer + - node_hostname: web_server + services: + - service_name: WebServer + - node_hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - node_hostname: backup_server + - node_hostname: security_suite + - node_hostname: client_1 + - node_hostname: client_2 + links: + - link_ref: router_1___switch_1 + - link_ref: router_1___switch_2 + - link_ref: switch_1___domain_controller + - link_ref: switch_1___web_server + - link_ref: switch_1___database_server + - link_ref: switch_1___backup_server + - link_ref: switch_1___security_suite + - link_ref: switch_2___client_1 + - link_ref: switch_2___client_2 + - link_ref: switch_2___security_suite + acl: + options: + max_acl_rules: 10 + router_hostname: router_1 + ip_address_order: + - node_hostname: domain_controller + nic_num: 1 + - node_hostname: web_server + nic_num: 1 + - node_hostname: database_server + nic_num: 1 + - node_hostname: backup_server + nic_num: 1 + - node_hostname: security_suite + nic_num: 1 + - node_hostname: client_1 + nic_num: 1 + - node_hostname: client_2 + nic_num: 1 + - node_hostname: security_suite + nic_num: 2 + ics: null + + action_space: + action_list: + - type: DONOTHING + - type: NODE_SERVICE_SCAN + - type: NODE_SERVICE_STOP + - type: NODE_SERVICE_START + - type: NODE_SERVICE_PAUSE + - type: NODE_SERVICE_RESUME + - type: NODE_SERVICE_RESTART + - type: NODE_SERVICE_DISABLE + - type: NODE_SERVICE_ENABLE + - type: NODE_SERVICE_FIX + - type: NODE_FILE_SCAN + - type: NODE_FILE_CHECKHASH + - type: NODE_FILE_DELETE + - type: NODE_FILE_REPAIR + - type: NODE_FILE_RESTORE + - type: NODE_FOLDER_SCAN + - type: NODE_FOLDER_CHECKHASH + - type: NODE_FOLDER_REPAIR + - type: NODE_FOLDER_RESTORE + - type: NODE_OS_SCAN + - type: NODE_SHUTDOWN + - type: NODE_STARTUP + - type: NODE_RESET + - type: NETWORK_ACL_ADDRULE + options: + target_router_hostname: router_1 + - type: NETWORK_ACL_REMOVERULE + options: + target_router_hostname: router_1 + - type: NETWORK_NIC_ENABLE + - type: NETWORK_NIC_DISABLE + - type: NODE_APPLICATION_INSTALL + - type: NODE_APPLICATION_REMOVE + - type: NODE_APPLICATION_EXECUTE + + action_map: + 0: + action: DONOTHING + options: {} + # scan webapp service + 1: + action: NODE_SERVICE_SCAN + options: + node_id: 1 + service_id: 0 + # stop webapp service + 2: + action: NODE_SERVICE_STOP + options: + node_id: 1 + service_id: 0 + # start webapp service + 3: + action: "NODE_SERVICE_START" + options: + node_id: 1 + service_id: 0 + 4: + action: "NODE_SERVICE_PAUSE" + options: + node_id: 1 + service_id: 0 + 5: + action: "NODE_SERVICE_RESUME" + options: + node_id: 1 + service_id: 0 + 6: + action: "NODE_SERVICE_RESTART" + options: + node_id: 1 + service_id: 0 + 7: + action: "NODE_SERVICE_DISABLE" + options: + node_id: 1 + service_id: 0 + 8: + action: "NODE_SERVICE_ENABLE" + options: + node_id: 1 + service_id: 0 + 9: # check database.db file + action: "NODE_FILE_SCAN" + options: + node_id: 2 + folder_id: 0 + file_id: 0 + 10: + action: "NODE_FILE_SCAN" # CHECKHASH replaced by SCAN - but the behaviour is the same in this context. + options: + node_id: 2 + folder_id: 0 + file_id: 0 + 11: + action: "NODE_FILE_DELETE" + options: + node_id: 2 + folder_id: 0 + file_id: 0 + 12: + action: "NODE_FILE_REPAIR" + options: + node_id: 2 + folder_id: 0 + file_id: 0 + 13: + action: "NODE_SERVICE_FIX" + options: + node_id: 2 + service_id: 0 + 14: + action: "NODE_FOLDER_SCAN" + options: + node_id: 2 + folder_id: 0 + 15: + action: "NODE_FOLDER_SCAN" # CHECKHASH replaced by SCAN - but the behaviour is the same in this context. + options: + node_id: 2 + folder_id: 0 + 16: + action: "NODE_FOLDER_REPAIR" + options: + node_id: 2 + folder_id: 0 + 17: + action: "NODE_FOLDER_RESTORE" + options: + node_id: 2 + folder_id: 0 + 18: + action: "NODE_OS_SCAN" + options: + node_id: 0 + 19: + action: "NODE_SHUTDOWN" + options: + node_id: 0 + 20: + action: NODE_STARTUP + options: + node_id: 0 + 21: + action: NODE_RESET + options: + node_id: 0 + 22: + action: "NODE_OS_SCAN" + options: + node_id: 1 + 23: + action: "NODE_SHUTDOWN" + options: + node_id: 1 + 24: + action: NODE_STARTUP + options: + node_id: 1 + 25: + action: NODE_RESET + options: + node_id: 1 + 26: # old action num: 18 + action: "NODE_OS_SCAN" + options: + node_id: 2 + 27: + action: "NODE_SHUTDOWN" + options: + node_id: 2 + 28: + action: NODE_STARTUP + options: + node_id: 2 + 29: + action: NODE_RESET + options: + node_id: 2 + 30: + action: "NODE_OS_SCAN" + options: + node_id: 3 + 31: + action: "NODE_SHUTDOWN" + options: + node_id: 3 + 32: + action: NODE_STARTUP + options: + node_id: 3 + 33: + action: NODE_RESET + options: + node_id: 3 + 34: + action: "NODE_OS_SCAN" + options: + node_id: 4 + 35: + action: "NODE_SHUTDOWN" + options: + node_id: 4 + 36: + action: NODE_STARTUP + options: + node_id: 4 + 37: + action: NODE_RESET + options: + node_id: 4 + 38: + action: "NODE_OS_SCAN" + options: + node_id: 5 + 39: # old action num: 19 # shutdown client 1 + action: "NODE_SHUTDOWN" + options: + node_id: 5 + 40: # old action num: 20 + action: NODE_STARTUP + options: + node_id: 5 + 41: # old action num: 21 + action: NODE_RESET + options: + node_id: 5 + 42: + action: "NODE_OS_SCAN" + options: + node_id: 6 + 43: + action: "NODE_SHUTDOWN" + options: + node_id: 6 + 44: + action: NODE_STARTUP + options: + node_id: 6 + 45: + action: NODE_RESET + options: + node_id: 6 + + 46: # old action num: 22 # "ACL: ADDRULE - Block outgoing traffic from client 1" + action: "NETWORK_ACL_ADDRULE" + options: + position: 1 + permission: 2 + source_ip_id: 7 # client 1 + dest_ip_id: 1 # ALL + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 + 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" + action: "NETWORK_ACL_ADDRULE" + options: + position: 2 + permission: 2 + source_ip_id: 8 # client 2 + dest_ip_id: 1 # ALL + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 + 48: # old action num: 24 # block tcp traffic from client 1 to web app + action: "NETWORK_ACL_ADDRULE" + options: + position: 3 + permission: 2 + source_ip_id: 7 # client 1 + dest_ip_id: 3 # web server + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 49: # old action num: 25 # block tcp traffic from client 2 to web app + action: "NETWORK_ACL_ADDRULE" + options: + position: 4 + permission: 2 + source_ip_id: 8 # client 2 + dest_ip_id: 3 # web server + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 50: # old action num: 26 + action: "NETWORK_ACL_ADDRULE" + options: + position: 5 + permission: 2 + source_ip_id: 7 # client 1 + dest_ip_id: 4 # database + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 51: # old action num: 27 + action: "NETWORK_ACL_ADDRULE" + options: + position: 6 + permission: 2 + source_ip_id: 8 # client 2 + dest_ip_id: 4 # database + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + 52: # old action num: 28 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 0 + 53: # old action num: 29 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 1 + 54: # old action num: 30 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 2 + 55: # old action num: 31 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 3 + 56: # old action num: 32 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 4 + 57: # old action num: 33 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 5 + 58: # old action num: 34 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 6 + 59: # old action num: 35 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 7 + 60: # old action num: 36 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 8 + 61: # old action num: 37 + action: "NETWORK_ACL_REMOVERULE" + options: + position: 9 + 62: # old action num: 38 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 0 + nic_id: 0 + 63: # old action num: 39 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 0 + nic_id: 0 + 64: # old action num: 40 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 1 + nic_id: 0 + 65: # old action num: 41 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 1 + nic_id: 0 + 66: # old action num: 42 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 2 + nic_id: 0 + 67: # old action num: 43 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 2 + nic_id: 0 + 68: # old action num: 44 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 3 + nic_id: 0 + 69: # old action num: 45 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 3 + nic_id: 0 + 70: # old action num: 46 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 4 + nic_id: 0 + 71: # old action num: 47 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 4 + nic_id: 0 + 72: # old action num: 48 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 4 + nic_id: 1 + 73: # old action num: 49 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 4 + nic_id: 1 + 74: # old action num: 50 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 5 + nic_id: 0 + 75: # old action num: 51 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 5 + nic_id: 0 + 76: # old action num: 52 + action: "NETWORK_NIC_DISABLE" + options: + node_id: 6 + nic_id: 0 + 77: # old action num: 53 + action: "NETWORK_NIC_ENABLE" + options: + node_id: 6 + nic_id: 0 + 78: + action: NODE_APPLICATION_INSTALL + options: + node_id: 0 + application_name: DoSBot + ip_address: 192.168.1.14 + 79: + action: NODE_APPLICATION_REMOVE + options: + node_id: 0 + application_name: DoSBot + 80: + action: NODE_APPLICATION_REMOVE + options: + node_id: 0 + application_name: WebBrowser + 81: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + + + + options: + nodes: + - node_name: domain_controller + applications: + - application_name: DoSBot + - node_name: web_server + applications: + - application_name: DatabaseClient + services: + - service_name: WebServer + - node_name: database_server + folders: + - folder_name: database + files: + - file_name: database.db + services: + - service_name: DatabaseService + - node_name: backup_server + - node_name: security_suite + - node_name: client_1 + - node_name: client_2 + + max_folders_per_node: 2 + max_files_per_folder: 2 + max_services_per_node: 2 + max_nics_per_node: 8 + max_acl_rules: 10 + ip_address_order: + - node_name: domain_controller + nic_num: 1 + - node_name: web_server + nic_num: 1 + - node_name: database_server + nic_num: 1 + - node_name: backup_server + nic_num: 1 + - node_name: security_suite + nic_num: 1 + - node_name: client_1 + nic_num: 1 + - node_name: client_2 + nic_num: 1 + - node_name: security_suite + nic_num: 2 + + + reward_function: + reward_components: + - type: DATABASE_FILE_INTEGRITY + weight: 0.40 + options: + node_hostname: database_server + folder_name: database + file_name: database.db + - type: SHARED_REWARD + weight: 1.0 + options: + agent_name: client_1_green_user + - type: SHARED_REWARD + weight: 1.0 + options: + agent_name: client_2_green_user + + + + agent_settings: + flatten_obs: true + + + + + +simulation: + network: + nmne_config: + capture_nmne: true + nmne_capture_keywords: + - DELETE + nodes: + + - ref: router_1 + hostname: router_1 + type: router + num_ports: 5 + ports: + 1: + ip_address: 192.168.1.1 + subnet_mask: 255.255.255.0 + 2: + ip_address: 192.168.10.1 + subnet_mask: 255.255.255.0 + acl: + 18: + action: PERMIT + src_port: POSTGRES_SERVER + dst_port: POSTGRES_SERVER + 19: + action: PERMIT + src_port: DNS + dst_port: DNS + 20: + action: PERMIT + src_port: FTP + dst_port: FTP + 21: + action: PERMIT + src_port: HTTP + dst_port: HTTP + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + + - ref: switch_1 + hostname: switch_1 + type: switch + num_ports: 8 + + - ref: switch_2 + hostname: switch_2 + type: switch + num_ports: 8 + + - ref: domain_controller + hostname: domain_controller + type: server + ip_address: 192.168.1.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + services: + - ref: domain_controller_dns_server + type: DNSServer + options: + domain_mapping: + arcd.com: 192.168.1.12 # web server + + - ref: web_server + hostname: web_server + type: server + ip_address: 192.168.1.12 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - ref: web_server_web_service + type: WebServer + applications: + - ref: web_server_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 + + + - ref: database_server + hostname: database_server + type: server + ip_address: 192.168.1.14 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - ref: database_service + type: DatabaseService + options: + backup_server_ip: 192.168.1.16 + - ref: database_ftp_client + type: FTPClient + + - ref: backup_server + hostname: backup_server + type: server + ip_address: 192.168.1.16 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - ref: backup_service + type: FTPServer + + - ref: security_suite + hostname: security_suite + type: server + ip_address: 192.168.1.110 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + network_interfaces: + 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot + ip_address: 192.168.10.110 + subnet_mask: 255.255.255.0 + + - ref: client_1 + hostname: client_1 + type: computer + ip_address: 192.168.10.21 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + applications: + - ref: data_manipulation_bot + type: DataManipulationBot + options: + port_scan_p_of_success: 0.8 + data_manipulation_p_of_success: 0.8 + payload: "DELETE" + server_ip: 192.168.1.14 + - ref: client_1_web_browser + type: WebBrowser + options: + target_url: http://arcd.com/users/ + - ref: client_1_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 + services: + - ref: client_1_dns_client + type: DNSClient + + - ref: client_2 + hostname: client_2 + type: computer + ip_address: 192.168.10.22 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + applications: + - ref: client_2_web_browser + type: WebBrowser + options: + target_url: http://arcd.com/users/ + - ref: data_manipulation_bot + type: DataManipulationBot + options: + port_scan_p_of_success: 0.8 + data_manipulation_p_of_success: 0.8 + payload: "DELETE" + server_ip: 192.168.1.14 + - ref: client_2_database_client + type: DatabaseClient + options: + db_server_ip: 192.168.1.14 + services: + - ref: client_2_dns_client + type: DNSClient + + + + links: + - ref: router_1___switch_1 + endpoint_a_ref: router_1 + endpoint_a_port: 1 + endpoint_b_ref: switch_1 + endpoint_b_port: 8 + - ref: router_1___switch_2 + endpoint_a_ref: router_1 + endpoint_a_port: 2 + endpoint_b_ref: switch_2 + endpoint_b_port: 8 + - ref: switch_1___domain_controller + endpoint_a_ref: switch_1 + endpoint_a_port: 1 + endpoint_b_ref: domain_controller + endpoint_b_port: 1 + - ref: switch_1___web_server + endpoint_a_ref: switch_1 + endpoint_a_port: 2 + endpoint_b_ref: web_server + endpoint_b_port: 1 + - ref: switch_1___database_server + endpoint_a_ref: switch_1 + endpoint_a_port: 3 + endpoint_b_ref: database_server + endpoint_b_port: 1 + - ref: switch_1___backup_server + endpoint_a_ref: switch_1 + endpoint_a_port: 4 + endpoint_b_ref: backup_server + endpoint_b_port: 1 + - ref: switch_1___security_suite + endpoint_a_ref: switch_1 + endpoint_a_port: 7 + endpoint_b_ref: security_suite + endpoint_b_port: 1 + - ref: switch_2___client_1 + endpoint_a_ref: switch_2 + endpoint_a_port: 1 + endpoint_b_ref: client_1 + endpoint_b_port: 1 + - ref: switch_2___client_2 + endpoint_a_ref: switch_2 + endpoint_a_port: 2 + endpoint_b_ref: client_2 + endpoint_b_port: 1 + - ref: switch_2___security_suite + endpoint_a_ref: switch_2 + endpoint_a_port: 7 + endpoint_b_ref: security_suite + endpoint_b_port: 2 diff --git a/tests/conftest.py b/tests/conftest.py index be76fc92..fd8727cb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -480,8 +480,8 @@ def game_and_agent(): {"type": "NODE_APPLICATION_SCAN"}, {"type": "NODE_APPLICATION_CLOSE"}, {"type": "NODE_APPLICATION_FIX"}, - {"type": "NODE_APPLICATION_INSTALL", "options": {"application_name": "DoSBot", "ip_address": "192.168.1.14"}}, - {"type": "NODE_APPLICATION_REMOVE", "options": {"application_name": "DoSBot"}}, + {"type": "NODE_APPLICATION_INSTALL"}, + {"type": "NODE_APPLICATION_REMOVE"}, {"type": "NODE_FILE_SCAN"}, {"type": "NODE_FILE_CHECKHASH"}, {"type": "NODE_FILE_DELETE"}, diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index b68a887e..2fee561a 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -1,8 +1,13 @@ +import yaml + +from primaite.game.game import PrimaiteGame +from primaite.session.environment import PrimaiteGymEnv from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.services.database.database_service import DatabaseService +from tests import TEST_ASSETS_ROOT def test_data_manipulation(uc2_network): @@ -32,3 +37,27 @@ def test_data_manipulation(uc2_network): # Now check that the DB client on the web_server can successfully query the users table on the database assert db_client.query("SELECT") + + +def test_application_install_uninstall_on_uc2(): + """Test Application install and uninstall via agent actions mid episode.""" + with open(TEST_ASSETS_ROOT / "configs/test_application_install.yaml", "r") as f: + cfg = yaml.safe_load(f) + + env = PrimaiteGymEnv(game_config=cfg) + env.agent.flatten_obs = False + env.reset() + + _, _, _, _, _ = env.step(0) + domcon = env.game.simulation.network.get_node_by_hostname("domain_controller") + + _, _, _, _, _ = env.step(78) + assert "DoSBot" in domcon.software_manager.software + + _, _, _, _, _ = env.step(79) + + assert "DoSBot" not in domcon.software_manager.software + assert "WebBrowser" in domcon.software_manager.software + + _, _, _, _, _ = env.step(80) + assert "WebBrowser" not in domcon.software_manager.software diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 5ba58ee5..96e3f390 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -470,13 +470,13 @@ def test_node_application_install_and_uninstall_integration(game_and_agent: Tupl assert client_1.software_manager.software.get("DoSBot") is None - action = ("NODE_APPLICATION_INSTALL", {"node_id": 0}) + action = ("NODE_APPLICATION_INSTALL", {"node_id": 0, "application_name": "DoSBot", "ip_address": "192.168.1.14"}) agent.store_action(action) game.step() assert client_1.software_manager.software.get("DoSBot") is not None - action = ("NODE_APPLICATION_REMOVE", {"node_id": 0}) + action = ("NODE_APPLICATION_REMOVE", {"node_id": 0, "application_name": "DoSBot"}) agent.store_action(action) game.step() From cfea38c5a727bfcfa42922dcbc5c285636f833e0 Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Thu, 28 Mar 2024 15:34:47 +0000 Subject: [PATCH 765/980] #2405 refactor e2e test, fix uninstalled apps not being removed from the request manager --- .../simulator/network/hardware/base.py | 6 +++-- .../test_uc2_data_manipulation_scenario.py | 22 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 754c7a24..bfa547d2 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1343,7 +1343,7 @@ class Node(SimComponent): else: pass - if application in self: + if application_instance.name in self.software_manager.software: return True else: return False @@ -1367,7 +1367,7 @@ class Node(SimComponent): application_instance = self.software_manager.software.get( str(application.__name__) ) # This works because we can't have two applications with the same name on the same node - self.uninstall_application(application_instance) + # self.uninstall_application(application_instance) self.software_manager.uninstall(application_instance.name) if application_instance.name not in self.software_manager.software: @@ -1406,4 +1406,6 @@ class Node(SimComponent): def __contains__(self, item: Any) -> bool: if isinstance(item, Service): return item.uuid in self.services + elif isinstance(item, Application): + return item.uuid in self.applications return None diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index 2fee561a..0b31a353 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -51,13 +51,27 @@ def test_application_install_uninstall_on_uc2(): _, _, _, _, _ = env.step(0) domcon = env.game.simulation.network.get_node_by_hostname("domain_controller") - _, _, _, _, _ = env.step(78) + # Test we cannot execute the DoSBot app as it is not installed yet + _, _, _, _, info = env.step(81) + assert info["agent_actions"]["defender"].response.status == "unreachable" + + # Test we can Install the DoSBot app + _, _, _, _, info = env.step(78) assert "DoSBot" in domcon.software_manager.software - _, _, _, _, _ = env.step(79) + # Test we can now execute the DoSBot app + _, _, _, _, info = env.step(81) + assert info["agent_actions"]["defender"].response.status == "success" + # Test we can Uninstall the DoSBot app + _, _, _, _, info = env.step(79) assert "DoSBot" not in domcon.software_manager.software - assert "WebBrowser" in domcon.software_manager.software - _, _, _, _, _ = env.step(80) + # Test we cannot execute the DoSBot app as it was uninstalled + _, _, _, _, info = env.step(81) + assert info["agent_actions"]["defender"].response.status == "unreachable" + + # Test we can uninstall one of the default apps (WebBrowser) + assert "WebBrowser" in domcon.software_manager.software + _, _, _, _, info = env.step(80) assert "WebBrowser" not in domcon.software_manager.software From 1ac3e1c6b412e68055dd47a689ea6baca564f302 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 28 Mar 2024 15:52:08 +0000 Subject: [PATCH 766/980] #2149 - Created a Router-specific version of SessionManager that looks at route table rather than default gateway when dst ip address isn't for a locally attached network. Carried these changes through to arp. Added test for this. Made some minor improvements to show functions in container and node that assist debugging. --- CHANGELOG.md | 1 + src/primaite/simulator/network/container.py | 6 +- .../simulator/network/hardware/base.py | 7 +- .../network/hardware/nodes/network/router.py | 159 +++++++++++++++++- .../simulator/system/services/arp/arp.py | 4 + .../integration_tests/network/test_routing.py | 11 ++ 6 files changed, 177 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c01f0139..f9667525 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -107,6 +107,7 @@ SessionManager. - Ability to add ``Router``/``Firewall`` ``ACLRule`` via config - NMNE capturing capabilities to `NetworkInterface` class for detecting and logging Malicious Network Events. - New `nmne_config` settings in the simulation configuration to enable NMNE capturing and specify keywords such as "DELETE". +- Router-specific SessionManager Implementation: Introduced a specialized version of the SessionManager tailored for router operations. This enhancement enables the SessionManager to determine the routing path by consulting the route table. ### Changed - Integrated the RouteTable into the Routers frame processing. diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index a4079fb8..92ee9f0d 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -170,7 +170,9 @@ class Network(SimComponent): print(table) if links: - table = PrettyTable(["Endpoint A", "Endpoint B", "is Up", "Bandwidth (MBits)", "Current Load"]) + table = PrettyTable( + ["Endpoint A", "A Port", "Endpoint B", "B Port", "is Up", "Bandwidth (MBits)", "Current Load"] + ) if markdown: table.set_style(MARKDOWN) table.align = "l" @@ -183,7 +185,9 @@ class Network(SimComponent): table.add_row( [ link.endpoint_a.parent.hostname, + str(link.endpoint_a), link.endpoint_b.parent.hostname, + str(link.endpoint_b), link.is_up, link.bandwidth, link.current_load_percent, diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 38d20e1f..208185a3 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -889,8 +889,9 @@ class Node(SimComponent): table.align = "l" table.title = f"{self.hostname} Open Ports" for port in self.software_manager.get_open_ports(): - table.add_row([port.value, port.name]) - print(table) + if port.value > 0: + table.add_row([port.value, port.name]) + print(table.get_string(sortby="Port")) @property def has_enabled_network_interface(self) -> bool: @@ -918,7 +919,7 @@ class Node(SimComponent): table.add_row( [ port, - type(network_interface), + network_interface.__class__.__name__, network_interface.mac_address, f"{network_interface.ip_address}/{network_interface.ip_network.prefixlen}", network_interface.speed, diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 102eb7dc..6571829a 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -18,6 +18,7 @@ from primaite.simulator.network.protocols.icmp import ICMPPacket, ICMPType from primaite.simulator.network.transmission.data_link_layer import Frame from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.core.session_manager import SessionManager from primaite.simulator.system.core.sys_log import SysLog from primaite.simulator.system.services.arp.arp import ARP from primaite.simulator.system.services.icmp.icmp import ICMP @@ -624,11 +625,12 @@ class RouteTable(SimComponent): """ pass + @validate_call() def add_route( self, - address: Union[IPv4Address, str], - subnet_mask: Union[IPv4Address, str], - next_hop_ip_address: Union[IPv4Address, str], + address: Union[IPV4Address, str], + subnet_mask: Union[IPV4Address, str], + next_hop_ip_address: Union[IPV4Address, str], metric: float = 0.0, ): """ @@ -647,7 +649,8 @@ class RouteTable(SimComponent): ) self.routes.append(route) - def set_default_route_next_hop_ip_address(self, ip_address: IPv4Address): + @validate_call() + def set_default_route_next_hop_ip_address(self, ip_address: IPV4Address): """ Sets the next-hop IP address for the default route in a routing table. @@ -660,7 +663,7 @@ class RouteTable(SimComponent): """ if not self.default_route: self.default_route = RouteEntry( - ip_address=IPv4Address("0.0.0.0"), + address=IPv4Address("0.0.0.0"), subnet_mask=IPv4Address("0.0.0.0"), next_hop_ip_address=ip_address, ) @@ -1016,6 +1019,144 @@ class RouterInterface(IPWiredNetworkInterface): return f"Port {self.port_name if self.port_name else self.port_num}: {self.mac_address}/{self.ip_address}" +class RouterSessionManager(SessionManager): + """ + Manages network sessions, including session creation, lookup, and communication with other components. + + The RouterSessionManager is a Router/Firewall specific implementation of SessionManager. It enables to resolve + outbound interface transmission details functions to leverage the route table instead of the default gateway. + + :param sys_log: A reference to the system log component. + :param arp_cache: A reference to the ARP cache component. + """ + + def resolve_outbound_network_interface(self, dst_ip_address: IPv4Address) -> Optional[RouterInterface]: + """ + Resolves the appropriate outbound network interface for a given destination IP address. + + This method determines the most suitable network interface for sending a packet to the specified + destination IP address. It considers only enabled network interfaces and checks if the destination + IP address falls within the subnet of each interface. If no suitable local network interface is found, + the method defaults to performing a route table look-up to determine if there is a dedicated route or a default + route it can use. + + The search process prioritises local network interfaces based on the IP network to which they belong. + If the destination IP address does not match any local subnet, the method assumes that the destination + is outside the local network and hence, routes the packet according to route table look-up. + + :param dst_ip_address: The destination IP address for which the outbound interface is to be resolved. + :type dst_ip_address: IPv4Address + :return: The network interface through which the packet should be sent to reach the destination IP address, + or the default gateway's network interface if the destination is not within any local subnet. + :rtype: Optional[RouterInterface] + """ + network_interface = super().resolve_outbound_network_interface(dst_ip_address) + if not network_interface: + route = self.node.route_table.find_best_route(dst_ip_address) + if not route: + return None + network_interface = super().resolve_outbound_network_interface(route.next_hop_ip_address) + return network_interface + + def resolve_outbound_transmission_details( + self, + dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] = None, + src_port: Optional[Port] = None, + dst_port: Optional[Port] = None, + protocol: Optional[IPProtocol] = None, + session_id: Optional[str] = None, + ) -> Tuple[ + Optional[RouterInterface], + Optional[str], + IPv4Address, + Optional[Port], + Optional[Port], + Optional[IPProtocol], + bool, + ]: + """ + Resolves the necessary details for outbound transmission based on the provided parameters. + + This method determines whether the payload should be broadcast or unicast based on the destination IP address + and resolves the outbound network interface and destination MAC address accordingly. + + The method first checks if `session_id` is provided and uses the session details if available. For broadcast + transmissions, it finds a suitable network interface and uses a broadcast MAC address. For unicast + transmissions, it attempts to resolve the destination MAC address using ARP and finds the appropriate + outbound network interface. If the destination IP address is outside the local network and no specific MAC + address is resolved, it defaults to performing a route table look-up to determine if there is a dedicated route + or a default route it can use. + + :param dst_ip_address: The destination IP address or network. If an IPv4Network is provided, the method + treats the transmission as a broadcast to that network. Optional. + :type dst_ip_address: Optional[Union[IPv4Address, IPv4Network]] + :param src_port: The source port number for the transmission. Optional. + :type src_port: Optional[Port] + :param dst_port: The destination port number for the transmission. Optional. + :type dst_port: Optional[Port] + :param protocol: The IP protocol to be used for the transmission. Optional. + :type protocol: Optional[IPProtocol] + :param session_id: The session ID associated with the transmission. If provided, the session details override + other parameters. Optional. + :type session_id: Optional[str] + :return: A tuple containing the resolved outbound network interface, destination MAC address, destination IP + address, source port, destination port, protocol, and a boolean indicating whether the transmission is a + broadcast. + :rtype: Tuple[Optional[RouterInterface], Optional[str], IPv4Address, Optional[Port], Optional[Port], + Optional[IPProtocol], bool] + """ + if dst_ip_address and not isinstance(dst_ip_address, (IPv4Address, IPv4Network)): + dst_ip_address = IPv4Address(dst_ip_address) + is_broadcast = False + outbound_network_interface = None + dst_mac_address = None + + # Use session details if session_id is provided + if session_id: + session = self.sessions_by_uuid[session_id] + + dst_ip_address = session.with_ip_address + protocol = session.protocol + src_port = session.src_port + dst_port = session.dst_port + + # Determine if the payload is for broadcast or unicast + + # Handle broadcast transmission + if isinstance(dst_ip_address, IPv4Network): + is_broadcast = True + dst_ip_address = dst_ip_address.broadcast_address + if dst_ip_address: + # Find a suitable NIC for the broadcast + for network_interface in self.node.network_interfaces.values(): + if dst_ip_address in network_interface.ip_network and network_interface.enabled: + dst_mac_address = "ff:ff:ff:ff:ff:ff" + outbound_network_interface = network_interface + break + else: + # Resolve MAC address for unicast transmission + use_route_table = True + for network_interface in self.node.network_interfaces.values(): + if dst_ip_address in network_interface.ip_network and network_interface.enabled: + dst_mac_address = self.software_manager.arp.get_arp_cache_mac_address(dst_ip_address) + break + + if dst_mac_address: + use_route_table = False + outbound_network_interface = self.software_manager.arp.get_arp_cache_network_interface(dst_ip_address) + + if use_route_table: + route = self.node.route_table.find_best_route(dst_ip_address) + if not route: + raise Exception("cannot use route to resolve outbound details") + + dst_mac_address = self.software_manager.arp.get_arp_cache_mac_address(route.next_hop_ip_address) + outbound_network_interface = self.software_manager.arp.get_arp_cache_network_interface( + route.next_hop_ip_address + ) + return outbound_network_interface, dst_mac_address, dst_ip_address, src_port, dst_port, protocol, is_broadcast + + class Router(NetworkNode): """ Represents a network router, managing routing and forwarding of IP packets across network interfaces. @@ -1049,6 +1190,10 @@ class Router(NetworkNode): if not kwargs.get("route_table"): kwargs["route_table"] = RouteTable(sys_log=kwargs["sys_log"]) super().__init__(hostname=hostname, num_ports=num_ports, **kwargs) + self.session_manager = RouterSessionManager(sys_log=self.sys_log) + self.session_manager.node = self + self.software_manager.session_manager = self.session_manager + self.session_manager.software_manager = self.software_manager for i in range(1, self.num_ports + 1): network_interface = RouterInterface(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0") self.connect_nic(network_interface) @@ -1418,7 +1563,7 @@ class Router(NetworkNode): :return: Configured router. :rtype: Router """ - router = cls( + router = Router( hostname=cfg["hostname"], num_ports=int(cfg.get("num_ports", "5")), operating_state=NodeOperatingState.ON @@ -1440,8 +1585,8 @@ class Router(NetworkNode): dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], src_ip_address=r_cfg.get("src_ip"), - dst_ip_address=r_cfg.get("dst_ip"), src_wildcard_mask=r_cfg.get("src_wildcard_mask"), + dst_ip_address=r_cfg.get("dst_ip"), dst_wildcard_mask=r_cfg.get("dst_wildcard_mask"), position=r_num, ) diff --git a/src/primaite/simulator/system/services/arp/arp.py b/src/primaite/simulator/system/services/arp/arp.py index ca5b7619..75bb03ae 100644 --- a/src/primaite/simulator/system/services/arp/arp.py +++ b/src/primaite/simulator/system/services/arp/arp.py @@ -65,6 +65,10 @@ class ARP(Service): """Clears the arp cache.""" self.arp.clear() + def get_default_gateway_network_interface(self) -> Optional[NetworkInterface]: + """Not used at the parent ARP level. Should return None when there is no override by child class.""" + return None + def add_arp_cache_entry( self, ip_address: IPV4Address, mac_address: str, network_interface: NetworkInterface, override: bool = False ): diff --git a/tests/integration_tests/network/test_routing.py b/tests/integration_tests/network/test_routing.py index 4ada807f..869b27be 100644 --- a/tests/integration_tests/network/test_routing.py +++ b/tests/integration_tests/network/test_routing.py @@ -152,6 +152,17 @@ def test_with_routes_can_ping(multi_hop_network): assert pc_a.ping(pc_b.network_interface[1].ip_address) +def test_ping_router_port_multi_hop(multi_hop_network): + pc_a = multi_hop_network.get_node_by_hostname("pc_a") + router_2 = multi_hop_network.get_node_by_hostname("router_2") + + router_2.route_table.add_route( + address="192.168.0.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.1" + ) + + assert pc_a.ping(router_2.network_interface[1].ip_address) + + def test_routing_services(multi_hop_network): pc_a = multi_hop_network.get_node_by_hostname("pc_a") From f88b4c0f97716ff03344ae22d732252733749c58 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 28 Mar 2024 17:40:27 +0000 Subject: [PATCH 767/980] #2417 more observations --- .../agent/observations/node_observations.py | 539 +++++++++++------- 1 file changed, 322 insertions(+), 217 deletions(-) diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index 42bdb749..5d46b743 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -1,4 +1,6 @@ +# TODO: make sure when config options are being passed down from higher-level observations to lower-level, but the lower-level also defines that option, don't overwrite. from __future__ import annotations +from ipaddress import IPv4Address from typing import Any, Dict, Iterable, List, Literal, Optional, Tuple, TYPE_CHECKING, Union from gymnasium import spaces @@ -163,7 +165,7 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): } ) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> FileObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> FolderObservation: where = parent_where + ["folders", config.folder_name] #pass down shared/common config items @@ -220,7 +222,7 @@ class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): return space @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> NICObservation: return cls(where = parent_where+["NICs", config.nic_num], include_nmne=config.include_nmne) @@ -333,7 +335,7 @@ class HostObservation(AbstractObservation, identifier="HOST"): return spaces.Dict(shape) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = None ) -> ServiceObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = None ) -> HostObservation: if parent_where is None: where = ["network", "nodes", config.hostname] else: @@ -369,78 +371,282 @@ class HostObservation(AbstractObservation, identifier="HOST"): class PortObservation(AbstractObservation, identifier="PORT"): class ConfigSchema(AbstractObservation.ConfigSchema): - pass + port_id : int def __init__(self, where: WhereType)->None: - pass + self.where = where + self.default_observation: ObsType = {"operating_status" : 0} def observe(self, state: Dict) -> Any: - pass + port_state = access_from_nested_dict(state, self.where) + if port_state is NOT_PRESENT_IN_STATE: + return self.default_observation + return {"operating_status": 1 if port_state["enabled"] else 2 } @property def space(self) -> spaces.Space: - pass + return spaces.Dict({"operating_status": spaces.Discrete(3)}) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: - pass + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> PortObservation: + return cls(where = parent_where + ["NICs", config.port_id]) class ACLObservation(AbstractObservation, identifier="ACL"): class ConfigSchema(AbstractObservation.ConfigSchema): - pass + ip_list: List[IPv4Address] + port_list: List[int] + protocol_list: List[str] + num_rules: int - def __init__(self, where: WhereType)->None: - pass + def __init__(self, where: WhereType, num_rules: int, ip_list: List[IPv4Address], port_list: List[int],protocol_list: List[str])->None: + self.where = where + self.num_rules: int = num_rules + self.ip_to_id: Dict[str, int] = {i+2:p for i,p in enumerate(ip_list)} + self.port_to_id: Dict[int, int] = {i+2:p for i,p in enumerate(port_list)} + self.protocol_to_id: Dict[str, int] = {i+2:p for i,p in enumerate(protocol_list)} + self.default_observation: Dict = { + i + + 1: { + "position": i, + "permission": 0, + "source_node_id": 0, + "source_port": 0, + "dest_node_id": 0, + "dest_port": 0, + "protocol": 0, + } + for i in range(self.num_rules) + } def observe(self, state: Dict) -> Any: - pass + acl_state: Dict = access_from_nested_dict(state, self.where) + if acl_state is NOT_PRESENT_IN_STATE: + return self.default_observation + obs = {} + acl_items = dict(acl_state.items()) + i = 1 # don't show rule 0 for compatibility reasons. + while i < self.num_rules + 1: + rule_state = acl_items[i] + if rule_state is None: + obs[i] = { + "position": i - 1, + "permission": 0, + "source_node_id": 0, + "source_port": 0, + "dest_node_id": 0, + "dest_port": 0, + "protocol": 0, + } + else: + src_ip = rule_state["src_ip_address"] + src_node_id = 1 if src_ip is None else self.node_to_id[IPv4Address(src_ip)] + dst_ip = rule_state["dst_ip_address"] + dst_node_ip = 1 if dst_ip is None else self.node_to_id[IPv4Address(dst_ip)] + src_port = rule_state["src_port"] + src_port_id = 1 if src_port is None else self.port_to_id[src_port] + dst_port = rule_state["dst_port"] + dst_port_id = 1 if dst_port is None else self.port_to_id[dst_port] + protocol = rule_state["protocol"] + protocol_id = 1 if protocol is None else self.protocol_to_id[protocol] + obs[i] = { + "position": i - 1, + "permission": rule_state["action"], + "source_node_id": src_node_id, + "source_port": src_port_id, + "dest_node_id": dst_node_ip, + "dest_port": dst_port_id, + "protocol": protocol_id, + } + i += 1 + return obs @property def space(self) -> spaces.Space: - pass + raise NotImplementedError("TODO: need to add wildcard id.") + return spaces.Dict( + { + i + + 1: spaces.Dict( + { + "position": spaces.Discrete(self.num_rules), + "permission": spaces.Discrete(3), + # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) + "source_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), + "source_port": spaces.Discrete(len(self.port_to_id) + 2), + "dest_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), + "dest_port": spaces.Discrete(len(self.port_to_id) + 2), + "protocol": spaces.Discrete(len(self.protocol_to_id) + 2), + } + ) + for i in range(self.num_rules) + } + ) + @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: - pass + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ACLObservation: + return cls( + where = parent_where+["acl", "acl"], + num_rules = config.num_rules, + ip_list = config.ip_list, + ports = config.port_list, + protocols = config.protocol_list + ) class RouterObservation(AbstractObservation, identifier="ROUTER"): class ConfigSchema(AbstractObservation.ConfigSchema): hostname: str ports: List[PortObservation.ConfigSchema] + num_ports: int + acl: ACLObservation.ConfigSchema + ip_list: List[str] + port_list: List[int] + protocol_list: List[str] + num_rules: int + def __init__(self, + where: WhereType, + ports:List[PortObservation], + num_ports: int, + acl: ACLObservation, + )->None: + self.where: WhereType = where + self.ports: List[PortObservation] = ports + self.acl: ACLObservation = acl + self.num_ports:int = num_ports - def __init__(self, where: WhereType)->None: - pass + while len(self.ports) < num_ports: + self.ports.append(PortObservation(where=None)) + while len(self.ports) > num_ports: + self.ports.pop() + msg = f"Too many ports in router observation. Truncating." + _LOGGER.warning(msg) + + self.default_observation = { + "PORTS": {i+1:p.default_observation for i,p in enumerate(self.ports)}, + "ACL": self.acl.default_observation + } def observe(self, state: Dict) -> Any: - pass + router_state = access_from_nested_dict(state, self.where) + if router_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + obs = {} + obs["PORTS"] = {i+1:p.observe(state) for i,p in enumerate(self.ports)} + obs["ACL"] = self.acl.observe(state) + return obs @property def space(self) -> spaces.Space: - pass + return spaces.Dict({ + "PORTS": {i+1:p.space for i,p in self.ports}, + "ACL": self.acl.space + }) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: - pass + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> RouterObservation: + where = parent_where + ["nodes", config.hostname] + + if config.acl.num_rules is None: + config.acl.num_rules = config.num_rules + if config.acl.ip_list is None: + config.acl.ip_list = config.ip_list + if config.acl.port_list is None: + config.acl.port_list = config.port_list + if config.acl.protocol_list is None: + config.acl.protocol_list = config.protocol_list + + ports = [PortObservation.from_config(config=c, parent_where=where) for c in config.ports] + acl = ACLObservation.from_config(config=config.acl, parent_where=where) + return cls(where=where, ports=ports, num_ports=config.num_ports, acl=acl) class FirewallObservation(AbstractObservation, identifier="FIREWALL"): class ConfigSchema(AbstractObservation.ConfigSchema): hostname: str - ports: List[PortObservation.ConfigSchema] = [] + ip_list: List[str] + port_list: List[int] + protocol_list: List[str] + num_rules: int - def __init__(self, where: WhereType)->None: - pass + + def __init__(self, + where: WhereType, + ip_list: List[str], + port_list: List[int], + protocol_list: List[str], + num_rules: int, + )->None: + self.where: WhereType = where + + self.ports: List[PortObservation] = [PortObservation(where=[self.where+["port", port_num]]) for port_num in (1,2,3) ] + #TODO: check what the port nums are for firewall. + + self.internal_inbound_acl = ACLObservation(where = self.where+["acl","internal","inbound"], num_rules= num_rules, ip_list=ip_list, port_list=port_list, protocol_list=protocol_list) + self.internal_outbound_acl = ACLObservation(where = self.where+["acl","internal","outbound"], num_rules= num_rules, ip_list=ip_list, port_list=port_list, protocol_list=protocol_list) + self.dmz_inbound_acl = ACLObservation(where = self.where+["acl","dmz","inbound"], num_rules= num_rules, ip_list=ip_list, port_list=port_list, protocol_list=protocol_list) + self.dmz_outbound_acl = ACLObservation(where = self.where+["acl","dmz","outbound"], num_rules= num_rules, ip_list=ip_list, port_list=port_list, protocol_list=protocol_list) + self.external_inbound_acl = ACLObservation(where = self.where+["acl","external","inbound"], num_rules= num_rules, ip_list=ip_list, port_list=port_list, protocol_list=protocol_list) + self.external_outbound_acl = ACLObservation(where = self.where+["acl","external","outbound"], num_rules= num_rules, ip_list=ip_list, port_list=port_list, protocol_list=protocol_list) + + + self.default_observation = { + "PORTS": {i+1:p.default_observation for i,p in enumerate(self.ports)}, + "INTERNAL": { + "INBOUND": self.internal_inbound_acl.default_observation, + "OUTBOUND": self.internal_outbound_acl.default_observation, + }, + "DMZ": { + "INBOUND": self.dmz_inbound_acl.default_observation, + "OUTBOUND": self.dmz_outbound_acl.default_observation, + }, + "EXTERNAL": { + "INBOUND": self.external_inbound_acl.default_observation, + "OUTBOUND": self.external_outbound_acl.default_observation, + }, + } def observe(self, state: Dict) -> Any: - pass + obs = { + "PORTS": {i+1:p.observe(state) for i,p in enumerate(self.ports)}, + "INTERNAL": { + "INBOUND": self.internal_inbound_acl.observe(state), + "OUTBOUND": self.internal_outbound_acl.observe(state), + }, + "DMZ": { + "INBOUND": self.dmz_inbound_acl.observe(state), + "OUTBOUND": self.dmz_outbound_acl.observe(state), + }, + "EXTERNAL": { + "INBOUND": self.external_inbound_acl.observe(state), + "OUTBOUND": self.external_outbound_acl.observe(state), + }, + } + return obs @property def space(self) -> spaces.Space: - pass + space =spaces.Dict({ + "PORTS": spaces.Dict({i+1:p.space for i,p in enumerate(self.ports)}), + "INTERNAL": spaces.Dict({ + "INBOUND": self.internal_inbound_acl.space, + "OUTBOUND": self.internal_outbound_acl.space, + }), + "DMZ": spaces.Dict({ + "INBOUND": self.dmz_inbound_acl.space, + "OUTBOUND": self.dmz_outbound_acl.space, + }), + "EXTERNAL": spaces.Dict({ + "INBOUND": self.external_inbound_acl.space, + "OUTBOUND": self.external_outbound_acl.space, + }), + }) + return space @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: - pass + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> FirewallObservation: + where = parent_where+["nodes", config.hostname] + return cls(where=where, ip_list=config.ip_list, port_list=config.port_list, protocol_list=config.protocol_list, num_rules=config.num_rules) class NodesObservation(AbstractObservation, identifier="NODES"): class ConfigSchema(AbstractObservation.ConfigSchema): @@ -448,205 +654,104 @@ class NodesObservation(AbstractObservation, identifier="NODES"): hosts: List[HostObservation.ConfigSchema] = [] routers: List[RouterObservation.ConfigSchema] = [] firewalls: List[FirewallObservation.ConfigSchema] = [] - num_services: int = 1 + + num_services: int + num_applications: int + num_folders: int + num_files: int + num_nics: int + include_nmne: bool + include_num_access: bool + + ip_list: List[str] + port_list: List[int] + protocol_list: List[str] + num_rules: int - def __init__(self, where: WhereType)->None: - pass + def __init__(self, where: WhereType, hosts:List[HostObservation], routers:List[RouterObservation], firewalls:List[FirewallObservation])->None: + self.where :WhereType = where + + self.hosts: List[HostObservation] = hosts + self.routers: List[RouterObservation] = routers + self.firewalls: List[FirewallObservation] = firewalls + + self.default_observation = { + **{f"HOST{i}":host.default_observation for i,host in enumerate(self.hosts)}, + **{f"ROUTER{i}":router.default_observation for i,router in enumerate(self.routers)}, + **{f"FIREWALL{i}":firewall.default_observation for i,firewall in enumerate(self.firewalls)}, + } def observe(self, state: Dict) -> Any: - pass - - @property - def space(self) -> spaces.Space: - pass - - @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: - pass - -############################ OLD - -class NodeObservation(AbstractObservation, identifier= "OLD"): - """Observation of a node in the network. Includes services, folders and NICs.""" - - def __init__( - self, - where: Optional[Tuple[str]] = None, - services: List[ServiceObservation] = [], - folders: List[FolderObservation] = [], - network_interfaces: List[NicObservation] = [], - logon_status: bool = False, - num_services_per_node: int = 2, - num_folders_per_node: int = 2, - num_files_per_folder: int = 2, - num_nics_per_node: int = 2, - ) -> None: - """ - Configurable observation for a node in the simulation. - - :param where: Where in the simulation state dictionary for find relevant information for this observation. - A typical location for a node looks like this: - ['network','nodes',]. If empty list, a default null observation will be output, defaults to [] - :type where: List[str], optional - :param services: Mapping between position in observation space and service name, defaults to {} - :type services: Dict[int,str], optional - :param max_services: Max number of services that can be presented in observation space for this node - , defaults to 2 - :type max_services: int, optional - :param folders: Mapping between position in observation space and folder name, defaults to {} - :type folders: Dict[int,str], optional - :param max_folders: Max number of folders in this node's obs space, defaults to 2 - :type max_folders: int, optional - :param network_interfaces: Mapping between position in observation space and NIC idx, defaults to {} - :type network_interfaces: Dict[int,str], optional - :param max_nics: Max number of network interfaces in this node's obs space, defaults to 5 - :type max_nics: int, optional - """ - super().__init__() - self.where: Optional[Tuple[str]] = where - - self.services: List[ServiceObservation] = services - while len(self.services) < num_services_per_node: - # add empty service observation without `where` parameter so it always returns default (blank) observation - self.services.append(ServiceObservation()) - while len(self.services) > num_services_per_node: - truncated_service = self.services.pop() - msg = f"Too many services in Node observation space for node. Truncating service {truncated_service.where}" - _LOGGER.warning(msg) - # truncate service list - - self.folders: List[FolderObservation] = folders - # add empty folder observation without `where` parameter that will always return default (blank) observations - while len(self.folders) < num_folders_per_node: - self.folders.append(FolderObservation(num_files_per_folder=num_files_per_folder)) - while len(self.folders) > num_folders_per_node: - truncated_folder = self.folders.pop() - msg = f"Too many folders in Node observation for node. Truncating service {truncated_folder.where[-1]}" - _LOGGER.warning(msg) - - self.network_interfaces: List[NicObservation] = network_interfaces - while len(self.network_interfaces) < num_nics_per_node: - self.network_interfaces.append(NicObservation()) - while len(self.network_interfaces) > num_nics_per_node: - truncated_nic = self.network_interfaces.pop() - msg = f"Too many NICs in Node observation for node. Truncating service {truncated_nic.where[-1]}" - _LOGGER.warning(msg) - - self.logon_status: bool = logon_status - - self.default_observation: Dict = { - "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, - "FOLDERS": {i + 1: f.default_observation for i, f in enumerate(self.folders)}, - "NICS": {i + 1: n.default_observation for i, n in enumerate(self.network_interfaces)}, - "operating_status": 0, + obs = { + **{f"HOST{i}":host.observe(state) for i,host in enumerate(self.hosts)}, + **{f"ROUTER{i}":router.observe(state) for i,router in enumerate(self.routers)}, + **{f"FIREWALL{i}":firewall.observe(state) for i,firewall in enumerate(self.firewalls)}, } - if self.logon_status: - self.default_observation["logon_status"] = 0 - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict - """ - if self.where is None: - return self.default_observation - - node_state = access_from_nested_dict(state, self.where) - if node_state is NOT_PRESENT_IN_STATE: - return self.default_observation - - obs = {} - obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} - obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} - obs["operating_status"] = node_state["operating_state"] - obs["NICS"] = { - i + 1: network_interface.observe(state) for i, network_interface in enumerate(self.network_interfaces) - } - - if self.logon_status: - obs["logon_status"] = 0 - return obs @property def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" - space_shape = { - "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), - "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), - "operating_status": spaces.Discrete(5), - "NICS": spaces.Dict( - {i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)} - ), - } - if self.logon_status: - space_shape["logon_status"] = spaces.Discrete(3) - - return spaces.Dict(space_shape) + space = spaces.Dict({ + **{f"HOST{i}":host.space for i,host in enumerate(self.hosts)}, + **{f"ROUTER{i}":router.space for i,router in enumerate(self.routers)}, + **{f"FIREWALL{i}":firewall.space for i,firewall in enumerate(self.firewalls)}, + }) + return space @classmethod - def from_config( - cls, - config: Dict, - game: "PrimaiteGame", - parent_where: Optional[List[str]] = None, - num_services_per_node: int = 2, - num_folders_per_node: int = 2, - num_files_per_folder: int = 2, - num_nics_per_node: int = 2, - ) -> "NodeObservation": - """Create node observation from a config. Also creates child service, folder and NIC observations. - - :param config: Dictionary containing the configuration for this node observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :param parent_where: Where in the simulation state dictionary to find the information about this node's parent - network. A typical location for it would be: ['network',] - :type parent_where: Optional[List[str]] - :param num_services_per_node: How many spaces for services are in this node observation (to preserve static - observation size) , defaults to 2 - :type num_services_per_node: int, optional - :param num_folders_per_node: How many spaces for folders are in this node observation (to preserve static - observation size) , defaults to 2 - :type num_folders_per_node: int, optional - :param num_files_per_folder: How many spaces for files are in the folder observations (to preserve static - observation size) , defaults to 2 - :type num_files_per_folder: int, optional - :return: Constructed node observation - :rtype: NodeObservation - """ - node_hostname = config["node_hostname"] + def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: if parent_where is None: - where = ["network", "nodes", node_hostname] + where = ["network", "nodes"] else: - where = parent_where + ["nodes", node_hostname] + where = parent_where + ["nodes"] - svc_configs = config.get("services", {}) - services = [ServiceObservation.from_config(config=c, game=game, parent_where=where) for c in svc_configs] - folder_configs = config.get("folders", {}) - folders = [ - FolderObservation.from_config( - config=c, game=game, parent_where=where + ["file_system"], num_files_per_folder=num_files_per_folder - ) - for c in folder_configs - ] - # create some configs for the NIC observation in the format {"nic_num":1}, {"nic_num":2}, {"nic_num":3}, etc. - nic_configs = [{"nic_num": i for i in range(num_nics_per_node)}] - network_interfaces = [NicObservation.from_config(config=c, game=game, parent_where=where) for c in nic_configs] - logon_status = config.get("logon_status", False) - return cls( - where=where, - services=services, - folders=folders, - network_interfaces=network_interfaces, - logon_status=logon_status, - num_services_per_node=num_services_per_node, - num_folders_per_node=num_folders_per_node, - num_files_per_folder=num_files_per_folder, - num_nics_per_node=num_nics_per_node, - ) + for host_config in config.hosts: + if host_config.num_services is None: + host_config.num_services = config.num_services + if host_config.num_applications is None: + host_config.num_application = config.num_applications + if host_config.num_folders is None: + host_config.num_folder = config.num_folders + if host_config.num_files is None: + host_config.num_file = config.num_files + if host_config.num_nics is None: + host_config.num_nic = config.num_nics + if host_config.include_nmne is None: + host_config.include_nmne = config.include_nmne + if host_config.include_num_access is None: + host_config.include_num_access = config.include_num_access + + for router_config in config.routers: + if router_config.num_ports is None: + router_config.num_ports = config.num_ports + if router_config.ip_list is None: + router_config.ip_list = config.ip_list + + if router_config.port_list is None: + router_config.port_list = config.port_list + + if router_config.protocol_list is None: + router_config.protocol_list = config.protocol_list + + if router_config.num_rules is None: + router_config.num_rules = config.num_rules + + for firewall_config in config.firewalls: + if firewall_config.ip_list is None: + firewall_config.ip_list = config.ip_list + + if firewall_config.port_list is None: + firewall_config.port_list = config.port_list + + if firewall_config.protocol_list is None: + firewall_config.protocol_list = config.protocol_list + + if firewall_config.num_rules is None: + firewall_config.num_rules = config.num_rules + + hosts = [HostObservation.from_config(config=c, parent_where=where) for c in config.hosts] + routers = [RouterObservation.from_config(config=c, parent_where=where) for c in config.routers] + firewalls = [FirewallObservation.from_config(config=c, parent_where=where) for c in config.firewalls] + + cls(where=where, hosts=hosts, routers=routers, firewalls=firewalls) From 2eb900746b24959eb69d3bedf0a9f83d089e8eeb Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Fri, 29 Mar 2024 11:34:43 +0000 Subject: [PATCH 768/980] #2402 rename network_acl actions to router_acl and refactor how router_name is given --- .../_package_data/data_manipulation.yaml | 56 +++++---- .../_package_data/data_manipulation_marl.yaml | 112 +++++++++++------- src/primaite/game/agent/actions.py | 28 ++--- .../hardware/nodes/network/firewall.py | 61 ++++++++++ .../assets/configs/bad_primaite_session.yaml | 56 +++++---- .../configs/eval_only_primaite_session.yaml | 56 +++++---- tests/assets/configs/multi_agent_session.yaml | 112 +++++++++++------- tests/assets/configs/shared_rewards.yaml | 56 +++++---- .../assets/configs/test_primaite_session.yaml | 56 +++++---- .../configs/train_only_primaite_session.yaml | 56 +++++---- tests/conftest.py | 4 +- .../game_layer/test_actions.py | 17 +-- 12 files changed, 426 insertions(+), 244 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index 12f60b63..ad3c02cc 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -258,12 +258,8 @@ agents: - type: NODE_SHUTDOWN - type: NODE_STARTUP - type: NODE_RESET - - type: NETWORK_ACL_ADDRULE - options: - target_router_hostname: router_1 - - type: NETWORK_ACL_REMOVERULE - options: - target_router_hostname: router_1 + - type: ROUTER_ACL_ADDRULE + - type: ROUTER_ACL_REMOVERULE - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -477,8 +473,9 @@ agents: node_id: 6 46: # old action num: 22 # "ACL: ADDRULE - Block outgoing traffic from client 1" - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 1 permission: 2 source_ip_id: 7 # client 1 @@ -487,8 +484,9 @@ agents: dest_port_id: 1 protocol_id: 1 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 2 permission: 2 source_ip_id: 8 # client 2 @@ -497,8 +495,9 @@ agents: dest_port_id: 1 protocol_id: 1 48: # old action num: 24 # block tcp traffic from client 1 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 3 permission: 2 source_ip_id: 7 # client 1 @@ -507,8 +506,9 @@ agents: dest_port_id: 1 protocol_id: 3 49: # old action num: 25 # block tcp traffic from client 2 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 4 permission: 2 source_ip_id: 8 # client 2 @@ -517,8 +517,9 @@ agents: dest_port_id: 1 protocol_id: 3 50: # old action num: 26 - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 5 permission: 2 source_ip_id: 7 # client 1 @@ -527,8 +528,9 @@ agents: dest_port_id: 1 protocol_id: 3 51: # old action num: 27 - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 6 permission: 2 source_ip_id: 8 # client 2 @@ -537,44 +539,54 @@ agents: dest_port_id: 1 protocol_id: 3 52: # old action num: 28 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 0 53: # old action num: 29 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 1 54: # old action num: 30 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 2 55: # old action num: 31 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 3 56: # old action num: 32 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 4 57: # old action num: 33 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 5 58: # old action num: 34 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 6 59: # old action num: 35 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 7 60: # old action num: 36 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 8 61: # old action num: 37 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 9 62: # old action num: 38 action: "NETWORK_NIC_DISABLE" diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index b632f626..2a788b73 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -260,12 +260,8 @@ agents: - type: NODE_SHUTDOWN - type: NODE_STARTUP - type: NODE_RESET - - type: NETWORK_ACL_ADDRULE - options: - target_router_hostname: router_1 - - type: NETWORK_ACL_REMOVERULE - options: - target_router_hostname: router_1 + - type: ROUTER_ACL_ADDRULE + - type: ROUTER_ACL_REMOVERULE - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -479,8 +475,9 @@ agents: node_id: 6 46: # old action num: 22 # "ACL: ADDRULE - Block outgoing traffic from client 1" - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 1 permission: 2 source_ip_id: 7 # client 1 @@ -489,8 +486,9 @@ agents: dest_port_id: 1 protocol_id: 1 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 2 permission: 2 source_ip_id: 8 # client 2 @@ -499,8 +497,9 @@ agents: dest_port_id: 1 protocol_id: 1 48: # old action num: 24 # block tcp traffic from client 1 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 3 permission: 2 source_ip_id: 7 # client 1 @@ -509,8 +508,9 @@ agents: dest_port_id: 1 protocol_id: 3 49: # old action num: 25 # block tcp traffic from client 2 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 4 permission: 2 source_ip_id: 8 # client 2 @@ -519,8 +519,9 @@ agents: dest_port_id: 1 protocol_id: 3 50: # old action num: 26 - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 5 permission: 2 source_ip_id: 7 # client 1 @@ -529,8 +530,9 @@ agents: dest_port_id: 1 protocol_id: 3 51: # old action num: 27 - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 6 permission: 2 source_ip_id: 8 # client 2 @@ -539,44 +541,54 @@ agents: dest_port_id: 1 protocol_id: 3 52: # old action num: 28 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 0 53: # old action num: 29 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 1 54: # old action num: 30 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 2 55: # old action num: 31 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 3 56: # old action num: 32 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 4 57: # old action num: 33 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 5 58: # old action num: 34 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 6 59: # old action num: 35 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 7 60: # old action num: 36 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 8 61: # old action num: 37 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 9 62: # old action num: 38 action: "NETWORK_NIC_DISABLE" @@ -811,12 +823,12 @@ agents: - type: NODE_SHUTDOWN - type: NODE_STARTUP - type: NODE_RESET - - type: NETWORK_ACL_ADDRULE + - type: ROUTER_ACL_ADDRULE options: - target_router_hostname: router_1 - - type: NETWORK_ACL_REMOVERULE + target_router_nodename: router_1 + - type: ROUTER_ACL_REMOVERULE options: - target_router_hostname: router_1 + target_router_nodename: router_1 - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -1030,8 +1042,9 @@ agents: node_id: 6 46: # old action num: 22 # "ACL: ADDRULE - Block outgoing traffic from client 1" - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 1 permission: 2 source_ip_id: 7 # client 1 @@ -1040,8 +1053,9 @@ agents: dest_port_id: 1 protocol_id: 1 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 2 permission: 2 source_ip_id: 8 # client 2 @@ -1050,8 +1064,9 @@ agents: dest_port_id: 1 protocol_id: 1 48: # old action num: 24 # block tcp traffic from client 1 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 3 permission: 2 source_ip_id: 7 # client 1 @@ -1060,8 +1075,9 @@ agents: dest_port_id: 1 protocol_id: 3 49: # old action num: 25 # block tcp traffic from client 2 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 4 permission: 2 source_ip_id: 8 # client 2 @@ -1070,8 +1086,9 @@ agents: dest_port_id: 1 protocol_id: 3 50: # old action num: 26 - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 5 permission: 2 source_ip_id: 7 # client 1 @@ -1080,8 +1097,9 @@ agents: dest_port_id: 1 protocol_id: 3 51: # old action num: 27 - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 6 permission: 2 source_ip_id: 8 # client 2 @@ -1090,44 +1108,54 @@ agents: dest_port_id: 1 protocol_id: 3 52: # old action num: 28 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 0 53: # old action num: 29 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 1 54: # old action num: 30 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 2 55: # old action num: 31 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 3 56: # old action num: 32 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 4 57: # old action num: 33 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 5 58: # old action num: 34 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 6 59: # old action num: 35 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 7 60: # old action num: 36 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 8 61: # old action num: 37 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 9 62: # old action num: 38 action: "NETWORK_NIC_DISABLE" diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index b79fc985..d585273d 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -405,25 +405,22 @@ class NodeResetAction(NodeAbstractAction): self.verb: str = "reset" -class NetworkACLAddRuleAction(AbstractAction): +class RouterACLAddRuleAction(AbstractAction): """Action which adds a rule to a router's ACL.""" def __init__( self, manager: "ActionManager", - target_router_hostname: str, max_acl_rules: int, num_ips: int, num_ports: int, num_protocols: int, **kwargs, ) -> None: - """Init method for NetworkACLAddRuleAction. + """Init method for RouterACLAddRuleAction. :param manager: Reference to the ActionManager which created this action. :type manager: ActionManager - :param target_router_hostname: hostname of the router to which the ACL rule should be added. - :type target_router_hostname: str :param max_acl_rules: Maximum number of ACL rules that can be added to the router. :type max_acl_rules: int :param num_ips: Number of IP addresses in the simulation. @@ -444,10 +441,10 @@ class NetworkACLAddRuleAction(AbstractAction): "dest_port_id": num_ports, "protocol_id": num_protocols, } - self.target_router_name: str = target_router_hostname def form_request( self, + target_router_nodename: str, position: int, permission: int, source_ip_id: int, @@ -511,7 +508,7 @@ class NetworkACLAddRuleAction(AbstractAction): return [ "network", "node", - self.target_router_name, + target_router_nodename, "acl", "add_rule", permission_str, @@ -524,26 +521,23 @@ class NetworkACLAddRuleAction(AbstractAction): ] -class NetworkACLRemoveRuleAction(AbstractAction): +class RouterACLRemoveRuleAction(AbstractAction): """Action which removes a rule from a router's ACL.""" - def __init__(self, manager: "ActionManager", target_router_hostname: str, max_acl_rules: int, **kwargs) -> None: - """Init method for NetworkACLRemoveRuleAction. + def __init__(self, manager: "ActionManager", max_acl_rules: int, **kwargs) -> None: + """Init method for RouterACLRemoveRuleAction. :param manager: Reference to the ActionManager which created this action. :type manager: ActionManager - :param target_router_hostname: Hostname of the router from which the ACL rule should be removed. - :type target_router_hostname: str :param max_acl_rules: Maximum number of ACL rules that can be added to the router. :type max_acl_rules: int """ super().__init__(manager=manager) self.shape: Dict[str, int] = {"position": max_acl_rules} - self.target_router_name: str = target_router_hostname - def form_request(self, position: int) -> List[str]: + def form_request(self, target_router_nodename: str, position: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" - return ["network", "node", self.target_router_name, "acl", "remove_rule", position] + return ["network", "node", target_router_nodename, "acl", "remove_rule", position] class NetworkNICAbstractAction(AbstractAction): @@ -672,8 +666,8 @@ class ActionManager: "NODE_SHUTDOWN": NodeShutdownAction, "NODE_STARTUP": NodeStartupAction, "NODE_RESET": NodeResetAction, - "NETWORK_ACL_ADDRULE": NetworkACLAddRuleAction, - "NETWORK_ACL_REMOVERULE": NetworkACLRemoveRuleAction, + "ROUTER_ACL_ADDRULE": RouterACLAddRuleAction, + "ROUTER_ACL_REMOVERULE": RouterACLRemoveRuleAction, "NETWORK_NIC_ENABLE": NetworkNICEnableAction, "NETWORK_NIC_DISABLE": NetworkNICDisableAction, "NETWORK_PORT_ENABLE": NetworkPortEnableAction, diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index d7b1dfd9..ea353b2f 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -4,6 +4,7 @@ from typing import Dict, Final, Optional, Union from prettytable import MARKDOWN, PrettyTable from pydantic import validate_call +# from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.network.router import ( AccessControlList, @@ -123,6 +124,66 @@ class Firewall(Router): sys_log=kwargs["sys_log"], implicit_action=ACLAction.PERMIT, name=f"{hostname} - External Outbound" ) + # def _init_request_manager(self) -> RequestManager: + # """ + # Initialise the request manager. + + # More information in user guide and docstring for SimComponent._init_request_manager. + # """ + # rm = super()._init_request_manager() + # self._internal_acl_request_manager = RequestManager() + # rm.add_request("internal", RequestType(func=self._internal_acl_request_manager)) + + # self._dmz_acl_request_manager = RequestManager() + # rm.add_request("dmz", RequestType(func=self._dmz_acl_request_manager)) + + # self._external_acl_request_manager = RequestManager() + # rm.add_request("external", RequestType(func=self._external_acl_request_manager)) + + # self._internal_inbound_acl_request_manager = RequestManager() + # self._internal_outbound_acl_request_manager = RequestManager() + # self._internal_acl_request_manager.add_request( + # "inbound", RequestType(func=self._internal_inbound_acl_request_manager) + # ) + # self._internal_acl_request_manager.add_request( + # "outbound", RequestType(func=self._internal_outbound_acl_request_manager) + # ) + + # self.dmz_inbound_acl_request_manager = RequestManager() + # self.dmz_outbound_acl_request_manager = RequestManager() + # self._dmz_acl_request_manager.add_request("inbound", RequestType(func=self.dmz_inbound_acl_request_manager)) + # self._dmz_acl_request_manager.add_request("outbound", RequestType(func=self.dmz_outbound_acl_request_manager)) + + # self.external_inbound_acl_request_manager = RequestManager() + # self.external_outbound_acl_request_manager = RequestManager() + # self._external_acl_request_manager.add_request( + # "inbound", RequestType(func=self.external_inbound_acl_request_manager) + # ) + # self._external_acl_request_manager.add_request( + # "outbound", RequestType(func=self.external_outbound_acl_request_manager) + # ) + + # self._internal_inbound_acl_request_manager.add_request( + # "acl", RequestType(func=self.internal_inbound_acl._request_manager) + # ) + # self._internal_outbound_acl_request_manager.add_request( + # "acl", RequestType(func=self.internal_outbound_acl._request_manager) + # ) + + # self.dmz_inbound_acl_request_manager.add_request("acl", RequestType(func=self.dmz_inbound_acl._request_manager)) + # self.dmz_outbound_acl_request_manager.add_request( + # "acl", RequestType(func=self.dmz_outbound_acl._request_manager) + # ) + + # self.external_inbound_acl_request_manager.add_request( + # "acl", RequestType(func=self.external_inbound_acl._request_manager) + # ) + # self.external_outbound_acl_request_manager.add_request( + # "acl", RequestType(func=self.external_outbound_acl._request_manager) + # ) + + # return rm + def describe_state(self) -> Dict: """ Describes the current state of the Firewall. diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index e599ee7e..743d2bba 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -169,12 +169,8 @@ agents: - type: NODE_SHUTDOWN - type: NODE_STARTUP - type: NODE_RESET - - type: NETWORK_ACL_ADDRULE - options: - target_router_hostname: router_1 - - type: NETWORK_ACL_REMOVERULE - options: - target_router_hostname: router_1 + - type: ROUTER_ACL_ADDRULE + - type: ROUTER_ACL_REMOVERULE - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -291,8 +287,9 @@ agents: options: node_id: 5 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 1 permission: 2 source_ip_id: 7 # client 1 @@ -301,8 +298,9 @@ agents: dest_port_id: 1 protocol_id: 1 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 2 permission: 2 source_ip_id: 8 # client 2 @@ -311,8 +309,9 @@ agents: dest_port_id: 1 protocol_id: 1 24: # block tcp traffic from client 1 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 3 permission: 2 source_ip_id: 7 # client 1 @@ -321,8 +320,9 @@ agents: dest_port_id: 1 protocol_id: 3 25: # block tcp traffic from client 2 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 4 permission: 2 source_ip_id: 8 # client 2 @@ -331,8 +331,9 @@ agents: dest_port_id: 1 protocol_id: 3 26: - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 5 permission: 2 source_ip_id: 7 # client 1 @@ -341,8 +342,9 @@ agents: dest_port_id: 1 protocol_id: 3 27: - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 6 permission: 2 source_ip_id: 8 # client 2 @@ -351,44 +353,54 @@ agents: dest_port_id: 1 protocol_id: 3 28: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 0 29: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 1 30: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 2 31: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 3 32: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 4 33: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 5 34: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 6 35: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 7 36: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 8 37: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 9 38: action: "NETWORK_NIC_DISABLE" diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index 9d1404d8..525f7bb0 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -173,12 +173,8 @@ agents: - type: NODE_SHUTDOWN - type: NODE_STARTUP - type: NODE_RESET - - type: NETWORK_ACL_ADDRULE - options: - target_router_hostname: router_1 - - type: NETWORK_ACL_REMOVERULE - options: - target_router_hostname: router_1 + - type: ROUTER_ACL_ADDRULE + - type: ROUTER_ACL_REMOVERULE - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -295,8 +291,9 @@ agents: options: node_id: 5 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 1 permission: 2 source_ip_id: 7 # client 1 @@ -305,8 +302,9 @@ agents: dest_port_id: 1 protocol_id: 1 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 2 permission: 2 source_ip_id: 8 # client 2 @@ -315,8 +313,9 @@ agents: dest_port_id: 1 protocol_id: 1 24: # block tcp traffic from client 1 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 3 permission: 2 source_ip_id: 7 # client 1 @@ -325,8 +324,9 @@ agents: dest_port_id: 1 protocol_id: 3 25: # block tcp traffic from client 2 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 4 permission: 2 source_ip_id: 8 # client 2 @@ -335,8 +335,9 @@ agents: dest_port_id: 1 protocol_id: 3 26: - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 5 permission: 2 source_ip_id: 7 # client 1 @@ -345,8 +346,9 @@ agents: dest_port_id: 1 protocol_id: 3 27: - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 6 permission: 2 source_ip_id: 8 # client 2 @@ -355,44 +357,54 @@ agents: dest_port_id: 1 protocol_id: 3 28: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 0 29: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 1 30: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 2 31: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 3 32: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 4 33: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 5 34: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 6 35: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 7 36: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 8 37: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 9 38: action: "NETWORK_NIC_DISABLE" diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index acb62c96..77a17459 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -180,12 +180,8 @@ agents: - type: NODE_SHUTDOWN - type: NODE_STARTUP - type: NODE_RESET - - type: NETWORK_ACL_ADDRULE - options: - target_router_hostname: router_1 - - type: NETWORK_ACL_REMOVERULE - options: - target_router_hostname: router_1 + - type: ROUTER_ACL_ADDRULE + - type: ROUTER_ACL_REMOVERULE - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -302,8 +298,9 @@ agents: options: node_id: 5 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 1 permission: 2 source_ip_id: 7 # client 1 @@ -312,8 +309,9 @@ agents: dest_port_id: 1 protocol_id: 1 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 2 permission: 2 source_ip_id: 8 # client 2 @@ -322,8 +320,9 @@ agents: dest_port_id: 1 protocol_id: 1 24: # block tcp traffic from client 1 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 3 permission: 2 source_ip_id: 7 # client 1 @@ -332,8 +331,9 @@ agents: dest_port_id: 1 protocol_id: 3 25: # block tcp traffic from client 2 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 4 permission: 2 source_ip_id: 8 # client 2 @@ -342,8 +342,9 @@ agents: dest_port_id: 1 protocol_id: 3 26: - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 5 permission: 2 source_ip_id: 7 # client 1 @@ -352,8 +353,9 @@ agents: dest_port_id: 1 protocol_id: 3 27: - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 6 permission: 2 source_ip_id: 8 # client 2 @@ -362,44 +364,54 @@ agents: dest_port_id: 1 protocol_id: 3 28: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 0 29: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 1 30: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 2 31: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 3 32: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 4 33: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 5 34: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 6 35: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 7 36: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 8 37: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 9 38: action: "NETWORK_NIC_DISABLE" @@ -624,12 +636,8 @@ agents: - type: NODE_SHUTDOWN - type: NODE_STARTUP - type: NODE_RESET - - type: NETWORK_ACL_ADDRULE - options: - target_router_hostname: router_1 - - type: NETWORK_ACL_REMOVERULE - options: - target_router_hostname: router_1 + - type: ROUTER_ACL_ADDRULE + - type: ROUTER_ACL_REMOVERULE - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -746,8 +754,9 @@ agents: options: node_id: 5 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 1 permission: 2 source_ip_id: 7 # client 1 @@ -756,8 +765,9 @@ agents: dest_port_id: 1 protocol_id: 1 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 2 permission: 2 source_ip_id: 8 # client 2 @@ -766,8 +776,9 @@ agents: dest_port_id: 1 protocol_id: 1 24: # block tcp traffic from client 1 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 3 permission: 2 source_ip_id: 7 # client 1 @@ -776,8 +787,9 @@ agents: dest_port_id: 1 protocol_id: 3 25: # block tcp traffic from client 2 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 4 permission: 2 source_ip_id: 8 # client 2 @@ -786,8 +798,9 @@ agents: dest_port_id: 1 protocol_id: 3 26: - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 5 permission: 2 source_ip_id: 7 # client 1 @@ -796,8 +809,9 @@ agents: dest_port_id: 1 protocol_id: 3 27: - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 6 permission: 2 source_ip_id: 8 # client 2 @@ -806,44 +820,54 @@ agents: dest_port_id: 1 protocol_id: 3 28: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 0 29: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 1 30: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 2 31: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 3 32: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 4 33: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 5 34: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 6 35: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 7 36: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 8 37: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 9 38: action: "NETWORK_NIC_DISABLE" diff --git a/tests/assets/configs/shared_rewards.yaml b/tests/assets/configs/shared_rewards.yaml index 10feba9d..e7226b5f 100644 --- a/tests/assets/configs/shared_rewards.yaml +++ b/tests/assets/configs/shared_rewards.yaml @@ -258,12 +258,8 @@ agents: - type: NODE_SHUTDOWN - type: NODE_STARTUP - type: NODE_RESET - - type: NETWORK_ACL_ADDRULE - options: - target_router_hostname: router_1 - - type: NETWORK_ACL_REMOVERULE - options: - target_router_hostname: router_1 + - type: ROUTER_ACL_ADDRULE + - type: ROUTER_ACL_REMOVERULE - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -477,8 +473,9 @@ agents: node_id: 6 46: # old action num: 22 # "ACL: ADDRULE - Block outgoing traffic from client 1" - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 1 permission: 2 source_ip_id: 7 # client 1 @@ -487,8 +484,9 @@ agents: dest_port_id: 1 protocol_id: 1 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 2 permission: 2 source_ip_id: 8 # client 2 @@ -497,8 +495,9 @@ agents: dest_port_id: 1 protocol_id: 1 48: # old action num: 24 # block tcp traffic from client 1 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 3 permission: 2 source_ip_id: 7 # client 1 @@ -507,8 +506,9 @@ agents: dest_port_id: 1 protocol_id: 3 49: # old action num: 25 # block tcp traffic from client 2 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 4 permission: 2 source_ip_id: 8 # client 2 @@ -517,8 +517,9 @@ agents: dest_port_id: 1 protocol_id: 3 50: # old action num: 26 - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 5 permission: 2 source_ip_id: 7 # client 1 @@ -527,8 +528,9 @@ agents: dest_port_id: 1 protocol_id: 3 51: # old action num: 27 - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 6 permission: 2 source_ip_id: 8 # client 2 @@ -537,44 +539,54 @@ agents: dest_port_id: 1 protocol_id: 3 52: # old action num: 28 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 0 53: # old action num: 29 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 1 54: # old action num: 30 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 2 55: # old action num: 31 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 3 56: # old action num: 32 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 4 57: # old action num: 33 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 5 58: # old action num: 34 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 6 59: # old action num: 35 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 7 60: # old action num: 36 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 8 61: # old action num: 37 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 9 62: # old action num: 38 action: "NETWORK_NIC_DISABLE" diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index b131c1b7..0cb371d5 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -183,12 +183,8 @@ agents: - type: NODE_SHUTDOWN - type: NODE_STARTUP - type: NODE_RESET - - type: NETWORK_ACL_ADDRULE - options: - target_router_hostname: router_1 - - type: NETWORK_ACL_REMOVERULE - options: - target_router_hostname: router_1 + - type: ROUTER_ACL_ADDRULE + - type: ROUTER_ACL_REMOVERULE - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -305,8 +301,9 @@ agents: options: node_id: 5 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 1 permission: 2 source_ip_id: 7 # client 1 @@ -315,8 +312,9 @@ agents: dest_port_id: 1 protocol_id: 1 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 2 permission: 2 source_ip_id: 8 # client 2 @@ -325,8 +323,9 @@ agents: dest_port_id: 1 protocol_id: 1 24: # block tcp traffic from client 1 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 3 permission: 2 source_ip_id: 7 # client 1 @@ -335,8 +334,9 @@ agents: dest_port_id: 1 protocol_id: 3 25: # block tcp traffic from client 2 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 4 permission: 2 source_ip_id: 8 # client 2 @@ -345,8 +345,9 @@ agents: dest_port_id: 1 protocol_id: 3 26: - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 5 permission: 2 source_ip_id: 7 # client 1 @@ -355,8 +356,9 @@ agents: dest_port_id: 1 protocol_id: 3 27: - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 6 permission: 2 source_ip_id: 8 # client 2 @@ -365,44 +367,54 @@ agents: dest_port_id: 1 protocol_id: 3 28: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 0 29: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 1 30: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 2 31: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 3 32: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 4 33: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 5 34: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 6 35: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 7 36: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 8 37: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 9 38: action: "NETWORK_NIC_DISABLE" diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index d0cbaab3..619b7a23 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -181,12 +181,8 @@ agents: - type: NODE_SHUTDOWN - type: NODE_STARTUP - type: NODE_RESET - - type: NETWORK_ACL_ADDRULE - options: - target_router_hostname: router_1 - - type: NETWORK_ACL_REMOVERULE - options: - target_router_hostname: router_1 + - type: ROUTER_ACL_ADDRULE + - type: ROUTER_ACL_REMOVERULE - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE @@ -303,8 +299,9 @@ agents: options: node_id: 5 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 1 permission: 2 source_ip_id: 7 # client 1 @@ -313,8 +310,9 @@ agents: dest_port_id: 1 protocol_id: 1 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 2 permission: 2 source_ip_id: 8 # client 2 @@ -323,8 +321,9 @@ agents: dest_port_id: 1 protocol_id: 1 24: # block tcp traffic from client 1 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 3 permission: 2 source_ip_id: 7 # client 1 @@ -333,8 +332,9 @@ agents: dest_port_id: 1 protocol_id: 3 25: # block tcp traffic from client 2 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 4 permission: 2 source_ip_id: 8 # client 2 @@ -343,8 +343,9 @@ agents: dest_port_id: 1 protocol_id: 3 26: - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 5 permission: 2 source_ip_id: 7 # client 1 @@ -353,8 +354,9 @@ agents: dest_port_id: 1 protocol_id: 3 27: - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_nodename: router_1 position: 6 permission: 2 source_ip_id: 8 # client 2 @@ -363,44 +365,54 @@ agents: dest_port_id: 1 protocol_id: 3 28: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 0 29: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 1 30: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 2 31: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 3 32: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 4 33: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 5 34: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 6 35: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 7 36: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 8 37: - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_nodename: router_1 position: 9 38: action: "NETWORK_NIC_DISABLE" diff --git a/tests/conftest.py b/tests/conftest.py index 078a78bd..05b8e925 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -494,8 +494,8 @@ def game_and_agent(): {"type": "NODE_SHUTDOWN"}, {"type": "NODE_STARTUP"}, {"type": "NODE_RESET"}, - {"type": "NETWORK_ACL_ADDRULE", "options": {"target_router_hostname": "router"}}, - {"type": "NETWORK_ACL_REMOVERULE", "options": {"target_router_hostname": "router"}}, + {"type": "ROUTER_ACL_ADDRULE"}, + {"type": "ROUTER_ACL_REMOVERULE"}, {"type": "NETWORK_NIC_ENABLE"}, {"type": "NETWORK_NIC_DISABLE"}, {"type": "NETWORK_PORT_ENABLE"}, diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index b3a52cd8..7bb8930c 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -93,9 +93,9 @@ def test_node_service_fix_integration(game_and_agent: Tuple[PrimaiteGame, ProxyA assert svc.health_state_actual == SoftwareHealthState.GOOD -def test_network_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): +def test_router_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): """ - Test that the NetworkACLAddRuleAction can form a request and that it is accepted by the simulation. + Test that the RouterACLAddRuleAction can form a request and that it is accepted by the simulation. The ACL starts off with 4 rules, and we add a rule, and check that the ACL now has 5 rules. """ @@ -112,8 +112,9 @@ def test_network_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Pro # 2: Add a rule to block client 1 from reaching server 2 on router action = ( - "NETWORK_ACL_ADDRULE", + "ROUTER_ACL_ADDRULE", { + "target_router_nodename": "router", "position": 4, # 4th rule "permission": 2, # DENY "source_ip_id": 3, # 10.0.1.2 (client_1) @@ -136,8 +137,9 @@ def test_network_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Pro # 4: Add a rule to block server_1 from reaching server_2 on router (this should not affect comms as they are on same subnet) action = ( - "NETWORK_ACL_ADDRULE", + "ROUTER_ACL_ADDRULE", { + "target_router_nodename": "router", "position": 5, # 5th rule "permission": 2, # DENY "source_ip_id": 5, # 10.0.2.2 (server_1) @@ -155,8 +157,8 @@ def test_network_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Pro assert server_1.ping("10.0.2.3") # Can ping server_2 -def test_network_acl_removerule_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): - """Test that the NetworkACLRemoveRuleAction can form a request and that it is accepted by the simulation.""" +def test_router_acl_removerule_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the RouterACLRemoveRuleAction can form a request and that it is accepted by the simulation.""" game, agent = game_and_agent # 1: Check that http traffic is going across the network nicely. @@ -171,8 +173,9 @@ def test_network_acl_removerule_integration(game_and_agent: Tuple[PrimaiteGame, # 2: Remove rule that allows HTTP traffic across the network action = ( - "NETWORK_ACL_REMOVERULE", + "ROUTER_ACL_REMOVERULE", { + "target_router_nodename": "router", "position": 3, # 4th rule }, ) From d8a66104f50c2c9f41b4522d99bbf4988513ef80 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 29 Mar 2024 11:55:22 +0000 Subject: [PATCH 769/980] Fixed observations --- .../agent/observations/node_observations.py | 173 ++++++++++-------- .../network/hardware/nodes/network/router.py | 2 + 2 files changed, 102 insertions(+), 73 deletions(-) diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index 5d46b743..b51ea1f2 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -82,7 +82,7 @@ class ApplicationObservation(AbstractObservation, identifier="APPLICATION"): class FileObservation(AbstractObservation, identifier="FILE"): class ConfigSchema(AbstractObservation.ConfigSchema): file_name: str - include_num_access : bool = False + include_num_access: Optional[bool] = None def __init__(self, where: WhereType, include_num_access: bool)->None: self.where: WhereType = where @@ -118,8 +118,8 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): class ConfigSchema(AbstractObservation.ConfigSchema): folder_name: str files: List[FileObservation.ConfigSchema] = [] - num_files : int = 0 - include_num_access : bool = False + num_files : Optional[int] = None + include_num_access : Optional[bool] = None def __init__(self, where: WhereType, files: Iterable[FileObservation], num_files: int, include_num_access: bool)->None: self.where: WhereType = where @@ -179,7 +179,7 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): class ConfigSchema(AbstractObservation.ConfigSchema): nic_num: int - include_nmne: bool = False + include_nmne: Optional[bool] = None def __init__(self, where: WhereType, include_nmne: bool)->None: @@ -233,13 +233,13 @@ class HostObservation(AbstractObservation, identifier="HOST"): applications: List[ApplicationObservation.ConfigSchema] = [] folders: List[FolderObservation.ConfigSchema] = [] network_interfaces: List[NICObservation.ConfigSchema] = [] - num_services: int - num_applications: int - num_folders: int - num_files: int - num_nics: int - include_nmne: bool - include_num_access: bool + num_services: Optional[int] = None + num_applications: Optional[int] = None + num_folders: Optional[int] = None + num_files: Optional[int] = None + num_nics: Optional[int] = None + include_nmne: Optional[bool] = None + include_num_access: Optional[bool] = None def __init__(self, where: WhereType, @@ -296,6 +296,7 @@ class HostObservation(AbstractObservation, identifier="HOST"): self.default_observation: ObsType = { "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, + "APPLICATIONS": {i + 1: a.default_observation for i, a in enumerate(self.applications)}, "FOLDERS": {i + 1: f.default_observation for i, f in enumerate(self.folders)}, "NICS": {i + 1: n.default_observation for i, n in enumerate(self.network_interfaces)}, "operating_status": 0, @@ -311,6 +312,7 @@ class HostObservation(AbstractObservation, identifier="HOST"): obs = {} obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} + obs["APPLICATIONS"] = {i + 1: app.observe(state) for i, app in enumerate(self.applications)} obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} obs["operating_status"] = node_state["operating_state"] obs["NICS"] = { @@ -324,6 +326,7 @@ class HostObservation(AbstractObservation, identifier="HOST"): def space(self) -> spaces.Space: shape = { "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), + "APPLICATIONS": spaces.Dict({i + 1: app.space for i, app in enumerate(self.applications)}), "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), "operating_status": spaces.Discrete(5), "NICS": spaces.Dict( @@ -393,15 +396,17 @@ class PortObservation(AbstractObservation, identifier="PORT"): class ACLObservation(AbstractObservation, identifier="ACL"): class ConfigSchema(AbstractObservation.ConfigSchema): - ip_list: List[IPv4Address] - port_list: List[int] - protocol_list: List[str] - num_rules: int + ip_list: Optional[List[IPv4Address]] = None + wildcard_list: Optional[List[str]] = None + port_list: Optional[List[int]] = None + protocol_list: Optional[List[str]] = None + num_rules: Optional[int] = None - def __init__(self, where: WhereType, num_rules: int, ip_list: List[IPv4Address], port_list: List[int],protocol_list: List[str])->None: + def __init__(self, where: WhereType, num_rules: int, ip_list: List[IPv4Address], wildcard_list: List[str], port_list: List[int],protocol_list: List[str])->None: self.where = where self.num_rules: int = num_rules self.ip_to_id: Dict[str, int] = {i+2:p for i,p in enumerate(ip_list)} + self.wildcard_to_id: Dict[str, int] = {i+2:p for i,p in enumerate(wildcard_list)} self.port_to_id: Dict[int, int] = {i+2:p for i,p in enumerate(port_list)} self.protocol_to_id: Dict[str, int] = {i+2:p for i,p in enumerate(protocol_list)} self.default_observation: Dict = { @@ -409,10 +414,12 @@ class ACLObservation(AbstractObservation, identifier="ACL"): + 1: { "position": i, "permission": 0, - "source_node_id": 0, - "source_port": 0, - "dest_node_id": 0, - "dest_port": 0, + "source_ip_id": 0, + "source_wildcard_id": 0, + "source_port_id": 0, + "dest_ip_id": 0, + "dest_wildcard_id": 0, + "dest_port_id": 0, "protocol": 0, } for i in range(self.num_rules) @@ -431,30 +438,38 @@ class ACLObservation(AbstractObservation, identifier="ACL"): obs[i] = { "position": i - 1, "permission": 0, - "source_node_id": 0, - "source_port": 0, - "dest_node_id": 0, - "dest_port": 0, + "source_ip_id": 0, + "source_wildcard_id": 0, + "source_port_id": 0, + "dest_ip_id": 0, + "dest_wildcard_id": 0, + "dest_port_id": 0, "protocol": 0, } else: src_ip = rule_state["src_ip_address"] - src_node_id = 1 if src_ip is None else self.node_to_id[IPv4Address(src_ip)] + src_node_id = self.ip_to_id.get(src_ip, 1) dst_ip = rule_state["dst_ip_address"] - dst_node_ip = 1 if dst_ip is None else self.node_to_id[IPv4Address(dst_ip)] - src_port = rule_state["src_port"] - src_port_id = 1 if src_port is None else self.port_to_id[src_port] - dst_port = rule_state["dst_port"] - dst_port_id = 1 if dst_port is None else self.port_to_id[dst_port] + dst_node_ip = self.ip_to_id.get(dst_ip, 1) + src_wildcard = rule_state["source_wildcard_id"] + src_wildcard_id = self.wildcard_to_id.get(src_wildcard, 1) + dst_wildcard = rule_state["dest_wildcard_id"] + dst_wildcard_id = self.wildcard_to_id.get(dst_wildcard, 1) + src_port = rule_state["source_port_id"] + src_port_id = self.port_to_id.get(src_port, 1) + dst_port = rule_state["dest_port_id"] + dst_port_id = self.port_to_id.get(dst_port, 1) protocol = rule_state["protocol"] - protocol_id = 1 if protocol is None else self.protocol_to_id[protocol] + protocol_id = self.protocol_to_id.get(protocol, 1) obs[i] = { "position": i - 1, "permission": rule_state["action"], - "source_node_id": src_node_id, - "source_port": src_port_id, - "dest_node_id": dst_node_ip, - "dest_port": dst_port_id, + "source_ip_id": src_node_id, + "source_wildcard_id": src_wildcard_id, + "source_port_id": src_port_id, + "dest_ip_id": dst_node_ip, + "dest_wildcard_id": dst_wildcard_id, + "dest_port_id": dst_port_id, "protocol": protocol_id, } i += 1 @@ -462,7 +477,6 @@ class ACLObservation(AbstractObservation, identifier="ACL"): @property def space(self) -> spaces.Space: - raise NotImplementedError("TODO: need to add wildcard id.") return spaces.Dict( { i @@ -471,10 +485,12 @@ class ACLObservation(AbstractObservation, identifier="ACL"): "position": spaces.Discrete(self.num_rules), "permission": spaces.Discrete(3), # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) - "source_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), - "source_port": spaces.Discrete(len(self.port_to_id) + 2), - "dest_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), - "dest_port": spaces.Discrete(len(self.port_to_id) + 2), + "source_ip_id": spaces.Discrete(len(self.ip_to_id) + 2), + "source_wildcard_id": spaces.Discrete(len(self.wildcard_to_id)+2), + "source_port_id": spaces.Discrete(len(self.port_to_id) + 2), + "dest_ip_id": spaces.Discrete(len(self.ip_to_id) + 2), + "dest_wildcard_id": spaces.Discrete(len(self.wildcard_to_id)+2), + "dest_port_id": spaces.Discrete(len(self.port_to_id) + 2), "protocol": spaces.Discrete(len(self.protocol_to_id) + 2), } ) @@ -489,20 +505,22 @@ class ACLObservation(AbstractObservation, identifier="ACL"): where = parent_where+["acl", "acl"], num_rules = config.num_rules, ip_list = config.ip_list, - ports = config.port_list, - protocols = config.protocol_list + wildcard_list = config.wildcard_list, + port_list = config.port_list, + protocol_list = config.protocol_list ) class RouterObservation(AbstractObservation, identifier="ROUTER"): class ConfigSchema(AbstractObservation.ConfigSchema): hostname: str - ports: List[PortObservation.ConfigSchema] - num_ports: int - acl: ACLObservation.ConfigSchema - ip_list: List[str] - port_list: List[int] - protocol_list: List[str] - num_rules: int + ports: Optional[List[PortObservation.ConfigSchema]] = None + num_ports: Optional[int] = None + acl: Optional[ACLObservation.ConfigSchema] = None + ip_list: Optional[List[str]] = None + wildcard_list: Optional[List[str]] = None + port_list: Optional[List[int]] = None + protocol_list: Optional[List[str]] = None + num_rules: Optional[int] = None def __init__(self, where: WhereType, @@ -540,7 +558,7 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): @property def space(self) -> spaces.Space: return spaces.Dict({ - "PORTS": {i+1:p.space for i,p in self.ports}, + "PORTS": spaces.Dict({i+1:p.space for i,p in enumerate(self.ports)}), "ACL": self.acl.space }) @@ -548,15 +566,22 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> RouterObservation: where = parent_where + ["nodes", config.hostname] + if config.acl is None: + config.acl = ACLObservation.ConfigSchema() if config.acl.num_rules is None: config.acl.num_rules = config.num_rules if config.acl.ip_list is None: config.acl.ip_list = config.ip_list + if config.acl.wildcard_list is None: + config.acl.wildcard_list = config.wildcard_list if config.acl.port_list is None: config.acl.port_list = config.port_list if config.acl.protocol_list is None: config.acl.protocol_list = config.protocol_list + if config.ports is None: + config.ports = [PortObservation.ConfigSchema(port_id=i+1) for i in range(config.num_ports)] + ports = [PortObservation.from_config(config=c, parent_where=where) for c in config.ports] acl = ACLObservation.from_config(config=config.acl, parent_where=where) return cls(where=where, ports=ports, num_ports=config.num_ports, acl=acl) @@ -564,30 +589,32 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): class FirewallObservation(AbstractObservation, identifier="FIREWALL"): class ConfigSchema(AbstractObservation.ConfigSchema): hostname: str - ip_list: List[str] - port_list: List[int] - protocol_list: List[str] - num_rules: int + ip_list: Optional[List[str]] = None + wildcard_list: Optional[List[str]] = None + port_list: Optional[List[int]] = None + protocol_list: Optional[List[str]] = None + num_rules: Optional[int] = None def __init__(self, where: WhereType, ip_list: List[str], + wildcard_list: List[str], port_list: List[int], protocol_list: List[str], num_rules: int, )->None: self.where: WhereType = where - self.ports: List[PortObservation] = [PortObservation(where=[self.where+["port", port_num]]) for port_num in (1,2,3) ] + self.ports: List[PortObservation] = [PortObservation(where=self.where+["port", port_num]) for port_num in (1,2,3) ] #TODO: check what the port nums are for firewall. - self.internal_inbound_acl = ACLObservation(where = self.where+["acl","internal","inbound"], num_rules= num_rules, ip_list=ip_list, port_list=port_list, protocol_list=protocol_list) - self.internal_outbound_acl = ACLObservation(where = self.where+["acl","internal","outbound"], num_rules= num_rules, ip_list=ip_list, port_list=port_list, protocol_list=protocol_list) - self.dmz_inbound_acl = ACLObservation(where = self.where+["acl","dmz","inbound"], num_rules= num_rules, ip_list=ip_list, port_list=port_list, protocol_list=protocol_list) - self.dmz_outbound_acl = ACLObservation(where = self.where+["acl","dmz","outbound"], num_rules= num_rules, ip_list=ip_list, port_list=port_list, protocol_list=protocol_list) - self.external_inbound_acl = ACLObservation(where = self.where+["acl","external","inbound"], num_rules= num_rules, ip_list=ip_list, port_list=port_list, protocol_list=protocol_list) - self.external_outbound_acl = ACLObservation(where = self.where+["acl","external","outbound"], num_rules= num_rules, ip_list=ip_list, port_list=port_list, protocol_list=protocol_list) + self.internal_inbound_acl = ACLObservation(where = self.where+["acl","internal","inbound"], num_rules= num_rules, ip_list=ip_list, wildcard_list=wildcard_list, port_list=port_list, protocol_list=protocol_list) + self.internal_outbound_acl = ACLObservation(where = self.where+["acl","internal","outbound"], num_rules= num_rules, ip_list=ip_list, wildcard_list=wildcard_list, port_list=port_list, protocol_list=protocol_list) + self.dmz_inbound_acl = ACLObservation(where = self.where+["acl","dmz","inbound"], num_rules= num_rules, ip_list=ip_list, wildcard_list=wildcard_list, port_list=port_list, protocol_list=protocol_list) + self.dmz_outbound_acl = ACLObservation(where = self.where+["acl","dmz","outbound"], num_rules= num_rules, ip_list=ip_list, wildcard_list=wildcard_list, port_list=port_list, protocol_list=protocol_list) + self.external_inbound_acl = ACLObservation(where = self.where+["acl","external","inbound"], num_rules= num_rules, ip_list=ip_list, wildcard_list=wildcard_list, port_list=port_list, protocol_list=protocol_list) + self.external_outbound_acl = ACLObservation(where = self.where+["acl","external","outbound"], num_rules= num_rules, ip_list=ip_list, wildcard_list=wildcard_list, port_list=port_list, protocol_list=protocol_list) self.default_observation = { @@ -646,7 +673,7 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): @classmethod def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> FirewallObservation: where = parent_where+["nodes", config.hostname] - return cls(where=where, ip_list=config.ip_list, port_list=config.port_list, protocol_list=config.protocol_list, num_rules=config.num_rules) + return cls(where=where, ip_list=config.ip_list, wildcard_list=config.wildcard_list, port_list=config.port_list, protocol_list=config.protocol_list, num_rules=config.num_rules) class NodesObservation(AbstractObservation, identifier="NODES"): class ConfigSchema(AbstractObservation.ConfigSchema): @@ -663,7 +690,9 @@ class NodesObservation(AbstractObservation, identifier="NODES"): include_nmne: bool include_num_access: bool + num_ports: int ip_list: List[str] + wildcard_list: List[str] port_list: List[int] protocol_list: List[str] num_rules: int @@ -710,13 +739,13 @@ class NodesObservation(AbstractObservation, identifier="NODES"): if host_config.num_services is None: host_config.num_services = config.num_services if host_config.num_applications is None: - host_config.num_application = config.num_applications + host_config.num_applications = config.num_applications if host_config.num_folders is None: - host_config.num_folder = config.num_folders + host_config.num_folders = config.num_folders if host_config.num_files is None: - host_config.num_file = config.num_files + host_config.num_files = config.num_files if host_config.num_nics is None: - host_config.num_nic = config.num_nics + host_config.num_nics = config.num_nics if host_config.include_nmne is None: host_config.include_nmne = config.include_nmne if host_config.include_num_access is None: @@ -727,26 +756,24 @@ class NodesObservation(AbstractObservation, identifier="NODES"): router_config.num_ports = config.num_ports if router_config.ip_list is None: router_config.ip_list = config.ip_list - + if router_config.wildcard_list is None: + router_config.wildcard_list = config.wildcard_list if router_config.port_list is None: router_config.port_list = config.port_list - if router_config.protocol_list is None: router_config.protocol_list = config.protocol_list - if router_config.num_rules is None: router_config.num_rules = config.num_rules for firewall_config in config.firewalls: if firewall_config.ip_list is None: firewall_config.ip_list = config.ip_list - + if firewall_config.wildcard_list is None: + firewall_config.wildcard_list = config.wildcard_list if firewall_config.port_list is None: firewall_config.port_list = config.port_list - if firewall_config.protocol_list is None: firewall_config.protocol_list = config.protocol_list - if firewall_config.num_rules is None: firewall_config.num_rules = config.num_rules @@ -754,4 +781,4 @@ class NodesObservation(AbstractObservation, identifier="NODES"): routers = [RouterObservation.from_config(config=c, parent_where=where) for c in config.routers] firewalls = [FirewallObservation.from_config(config=c, parent_where=where) for c in config.firewalls] - cls(where=where, hosts=hosts, routers=routers, firewalls=firewalls) + return cls(where=where, hosts=hosts, routers=routers, firewalls=firewalls) diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index d2b47c1a..69ab6a82 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -147,8 +147,10 @@ class ACLRule(SimComponent): state["action"] = self.action.value state["protocol"] = self.protocol.name if self.protocol else None state["src_ip_address"] = str(self.src_ip_address) if self.src_ip_address else None + state["src_wildcard_mask"] = str(self.src_wildcard_mask) if self.src_wildcard_mask else None state["src_port"] = self.src_port.name if self.src_port else None state["dst_ip_address"] = str(self.dst_ip_address) if self.dst_ip_address else None + state["dst_wildcard_mask"] = str(self.dst_wildcard_mask) if self.dst_wildcard_mask else None state["dst_port"] = self.dst_port.name if self.dst_port else None state["match_count"] = self.match_count return state From 1751714d3d8f1f5e78a6b97f712765dbd23cc6fd Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 29 Mar 2024 12:21:52 +0000 Subject: [PATCH 770/980] Tidy up node observation file --- .../game/agent/observations/node_observations.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index b51ea1f2..ed930265 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -1,17 +1,12 @@ -# TODO: make sure when config options are being passed down from higher-level observations to lower-level, but the lower-level also defines that option, don't overwrite. from __future__ import annotations from ipaddress import IPv4Address -from typing import Any, Dict, Iterable, List, Literal, Optional, Tuple, TYPE_CHECKING, Union +from typing import Any, Dict, Iterable, List, Optional from gymnasium import spaces from gymnasium.core import ObsType -from pydantic import BaseModel, ConfigDict from primaite import getLogger from primaite.game.agent.observations.observations import AbstractObservation -# from primaite.game.agent.observations.file_system_observations import FolderObservation -# from primaite.game.agent.observations.nic_observations import NicObservation -# from primaite.game.agent.observations.software_observation import ServiceObservation from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE _LOGGER = getLogger(__name__) @@ -420,7 +415,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): "dest_ip_id": 0, "dest_wildcard_id": 0, "dest_port_id": 0, - "protocol": 0, + "protocol_id": 0, } for i in range(self.num_rules) } @@ -444,7 +439,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): "dest_ip_id": 0, "dest_wildcard_id": 0, "dest_port_id": 0, - "protocol": 0, + "protocol_id": 0, } else: src_ip = rule_state["src_ip_address"] @@ -470,7 +465,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): "dest_ip_id": dst_node_ip, "dest_wildcard_id": dst_wildcard_id, "dest_port_id": dst_port_id, - "protocol": protocol_id, + "protocol_id": protocol_id, } i += 1 return obs @@ -491,7 +486,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): "dest_ip_id": spaces.Discrete(len(self.ip_to_id) + 2), "dest_wildcard_id": spaces.Discrete(len(self.wildcard_to_id)+2), "dest_port_id": spaces.Discrete(len(self.port_to_id) + 2), - "protocol": spaces.Discrete(len(self.protocol_to_id) + 2), + "protocol_id": spaces.Discrete(len(self.protocol_to_id) + 2), } ) for i in range(self.num_rules) From 9123aff592e952df7f9df5d9257dbbb5c9ef973a Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 29 Mar 2024 13:15:31 +0000 Subject: [PATCH 771/980] #2417 Add hella docstrings --- .../agent/observations/node_observations.py | 997 ++++++++++++++---- 1 file changed, 792 insertions(+), 205 deletions(-) diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index ed930265..c702f8e2 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -1,4 +1,5 @@ from __future__ import annotations + from ipaddress import IPv4Address from typing import Any, Dict, Iterable, List, Optional @@ -15,14 +16,34 @@ WhereType = Iterable[str | int] | None class ServiceObservation(AbstractObservation, identifier="SERVICE"): - class ConfigSchema(AbstractObservation.ConfigSchema): - service_name: str + """Service observation, shows status of a service in the simulation environment.""" - def __init__(self, where: WhereType)->None: + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for ServiceObservation.""" + + service_name: str + """Name of the service, used for querying simulation state dictionary""" + + def __init__(self, where: WhereType) -> None: + """ + Initialize a service observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this service. + A typical location for a service might be ['network', 'nodes', , 'services', ]. + :type where: WhereType + """ self.where = where self.default_observation = {"operating_status": 0, "health_status": 0} - def observe(self, state: Dict) -> Any: + def observe(self, state: Dict) -> ObsType: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the operating status and health status of the service. + :rtype: Any + """ service_state = access_from_nested_dict(state, self.where) if service_state is NOT_PRESENT_IN_STATE: return self.default_observation @@ -33,24 +54,60 @@ class ServiceObservation(AbstractObservation, identifier="SERVICE"): @property def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for service status. + :rtype: spaces.Space + """ return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(5)}) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: - return cls(where=parent_where+["services", config.service_name]) + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ServiceObservation: + """ + Create a service observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the service observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this service's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed service observation instance. + :rtype: ServiceObservation + """ + return cls(where=parent_where + ["services", config.service_name]) class ApplicationObservation(AbstractObservation, identifier="APPLICATION"): - class ConfigSchema(AbstractObservation.ConfigSchema): - application_name: str + """Application observation, shows the status of an application within the simulation environment.""" - def __init__(self, where: WhereType)->None: + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for ApplicationObservation.""" + + application_name: str + """Name of the application, used for querying simulation state dictionary""" + + def __init__(self, where: WhereType) -> None: + """ + Initialise an application observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this application. + A typical location for an application might be + ['network', 'nodes', , 'applications', ]. + :type where: WhereType + """ self.where = where self.default_observation = {"operating_status": 0, "health_status": 0, "num_executions": 0} def observe(self, state: Dict) -> Any: - # raise NotImplementedError("TODO NUM EXECUTIONS NEEDS TO BE CONVERTED TO A CATEGORICAL") + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Obs containing the operating status, health status, and number of executions of the application. + :rtype: Any + """ application_state = access_from_nested_dict(state, self.where) if application_state is NOT_PRESENT_IN_STATE: return self.default_observation @@ -62,32 +119,74 @@ class ApplicationObservation(AbstractObservation, identifier="APPLICATION"): @property def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" - return spaces.Dict({ - "operating_status": spaces.Discrete(7), - "health_status": spaces.Discrete(5), - "num_executions": spaces.Discrete(4) - }) + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for application status. + :rtype: spaces.Space + """ + return spaces.Dict( + { + "operating_status": spaces.Discrete(7), + "health_status": spaces.Discrete(5), + "num_executions": spaces.Discrete(4), + } + ) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ApplicationObservation: - return cls(where=parent_where+["applications", config.application_name]) + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ApplicationObservation: + """ + Create an application observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the application observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this application's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed application observation instance. + :rtype: ApplicationObservation + """ + return cls(where=parent_where + ["applications", config.application_name]) class FileObservation(AbstractObservation, identifier="FILE"): - class ConfigSchema(AbstractObservation.ConfigSchema): - file_name: str - include_num_access: Optional[bool] = None + """File observation, provides status information about a file within the simulation environment.""" - def __init__(self, where: WhereType, include_num_access: bool)->None: + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for FileObservation.""" + + file_name: str + """Name of the file, used for querying simulation state dictionary.""" + include_num_access: Optional[bool] = None + """Whether to include the number of accesses to the file in the observation.""" + + def __init__(self, where: WhereType, include_num_access: bool) -> None: + """ + Initialize a file observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this file. + A typical location for a file might be + ['network', 'nodes', , 'file_system', 'folder', , 'files', ]. + :type where: WhereType + :param include_num_access: Whether to include the number of accesses to the file in the observation. + :type include_num_access: bool + """ self.where: WhereType = where - self.include_num_access :bool = include_num_access + self.include_num_access: bool = include_num_access self.default_observation: ObsType = {"health_status": 0} if self.include_num_access: self.default_observation["num_access"] = 0 def observe(self, state: Dict) -> Any: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the health status of the file and optionally the number of accesses. + :rtype: Any + """ file_state = access_from_nested_dict(state, self.where) if file_state is NOT_PRESENT_IN_STATE: return self.default_observation @@ -99,29 +198,69 @@ class FileObservation(AbstractObservation, identifier="FILE"): @property def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for file status. + :rtype: spaces.Space + """ space = {"health_status": spaces.Discrete(6)} if self.include_num_access: space["num_access"] = spaces.Discrete(4) return spaces.Dict(space) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> FileObservation: - return cls(where=parent_where+["files", config.file_name], include_num_access=config.include_num_access) + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FileObservation: + """ + Create a file observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the file observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this file's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed file observation instance. + :rtype: FileObservation + """ + return cls(where=parent_where + ["files", config.file_name], include_num_access=config.include_num_access) class FolderObservation(AbstractObservation, identifier="FOLDER"): - class ConfigSchema(AbstractObservation.ConfigSchema): - folder_name: str - files: List[FileObservation.ConfigSchema] = [] - num_files : Optional[int] = None - include_num_access : Optional[bool] = None + """Folder observation, provides status information about a folder within the simulation environment.""" - def __init__(self, where: WhereType, files: Iterable[FileObservation], num_files: int, include_num_access: bool)->None: + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for FolderObservation.""" + + folder_name: str + """Name of the folder, used for querying simulation state dictionary.""" + files: List[FileObservation.ConfigSchema] = [] + """List of file configurations within the folder.""" + num_files: Optional[int] = None + """Number of spaces for file observations in this folder.""" + include_num_access: Optional[bool] = None + """Whether files in this folder should include the number of accesses in their observation.""" + + def __init__( + self, where: WhereType, files: Iterable[FileObservation], num_files: int, include_num_access: bool + ) -> None: + """ + Initialize a folder observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this folder. + A typical location for a folder might be ['network', 'nodes', , 'folders', ]. + :type where: WhereType + :param files: List of file observation instances within the folder. + :type files: Iterable[FileObservation] + :param num_files: Number of files expected in the folder. + :type num_files: int + :param include_num_access: Whether to include the number of accesses to files in the observation. + :type include_num_access: bool + """ self.where: WhereType = where self.files: List[FileObservation] = files while len(self.files) < num_files: - self.files.append(FileObservation(where=None,include_num_access=include_num_access)) + self.files.append(FileObservation(where=None, include_num_access=include_num_access)) while len(self.files) > num_files: truncated_file = self.files.pop() msg = f"Too many files in folder observation. Truncating file {truncated_file}" @@ -133,6 +272,14 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): } def observe(self, state: Dict) -> Any: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the health status of the folder and status of files within the folder. + :rtype: Any + """ folder_state = access_from_nested_dict(state, self.where) if folder_state is NOT_PRESENT_IN_STATE: return self.default_observation @@ -148,9 +295,10 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): @property def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape. + """ + Gymnasium space object describing the observation space shape. - :return: Gymnasium space + :return: Gymnasium space representing the observation space for folder status. :rtype: spaces.Space """ return spaces.Dict( @@ -159,34 +307,68 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): "FILES": spaces.Dict({i + 1: f.space for i, f in enumerate(self.files)}), } ) + @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> FolderObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FolderObservation: + """ + Create a folder observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the folder observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this folder's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed folder observation instance. + :rtype: FolderObservation + """ where = parent_where + ["folders", config.folder_name] - #pass down shared/common config items + # pass down shared/common config items for file_config in config.files: file_config.include_num_access = config.include_num_access - files = [FileObservation.from_config(config=f, parent_where = where) for f in config.files] + files = [FileObservation.from_config(config=f, parent_where=where) for f in config.files] return cls(where=where, files=files, num_files=config.num_files, include_num_access=config.include_num_access) class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): + """Status information about a network interface within the simulation environment.""" + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for NICObservation.""" + nic_num: int + """Number of the network interface.""" include_nmne: Optional[bool] = None + """Whether to include number of malicious network events (NMNE) in the observation.""" + def __init__(self, where: WhereType, include_nmne: bool) -> None: + """ + Initialize a network interface observation instance. - def __init__(self, where: WhereType, include_nmne: bool)->None: + :param where: Where in the simulation state dictionary to find the relevant information for this interface. + A typical location for a network interface might be + ['network', 'nodes', , 'NICs', ]. + :type where: WhereType + :param include_nmne: Flag to determine whether to include NMNE information in the observation. + :type include_nmne: bool + """ self.where = where - self.include_nmne : bool = include_nmne + self.include_nmne: bool = include_nmne self.default_observation: ObsType = {"nic_status": 0} if self.include_nmne: - self.default_observation.update({"NMNE":{"inbound":0, "outbound":0}}) + self.default_observation.update({"NMNE": {"inbound": 0, "outbound": 0}}) def observe(self, state: Dict) -> Any: - # raise NotImplementedError("TODO: CATEGORISATION") + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the status of the network interface and optionally NMNE information. + :rtype: Any + """ nic_state = access_from_nested_dict(state, self.where) if nic_state is NOT_PRESENT_IN_STATE: @@ -206,9 +388,14 @@ class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): self.nmne_outbound_last_step = outbound_count return obs - @property def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for network interface status and NMNE information. + :rtype: spaces.Space + """ space = spaces.Dict({"nic_status": spaces.Discrete(3)}) if self.include_nmne: @@ -217,43 +404,99 @@ class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): return space @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> NICObservation: - return cls(where = parent_where+["NICs", config.nic_num], include_nmne=config.include_nmne) + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> NICObservation: + """ + Create a network interface observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the network interface observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this NIC's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed network interface observation instance. + :rtype: NICObservation + """ + return cls(where=parent_where + ["NICs", config.nic_num], include_nmne=config.include_nmne) class HostObservation(AbstractObservation, identifier="HOST"): + """Host observation, provides status information about a host within the simulation environment.""" + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for HostObservation.""" + hostname: str + """Hostname of the host, used for querying simulation state dictionary.""" services: List[ServiceObservation.ConfigSchema] = [] + """List of services to observe on the host.""" applications: List[ApplicationObservation.ConfigSchema] = [] + """List of applications to observe on the host.""" folders: List[FolderObservation.ConfigSchema] = [] + """List of folders to observe on the host.""" network_interfaces: List[NICObservation.ConfigSchema] = [] + """List of network interfaces to observe on the host.""" num_services: Optional[int] = None + """Number of spaces for service observations on this host.""" num_applications: Optional[int] = None + """Number of spaces for application observations on this host.""" num_folders: Optional[int] = None + """Number of spaces for folder observations on this host.""" num_files: Optional[int] = None + """Number of spaces for file observations on this host.""" num_nics: Optional[int] = None + """Number of spaces for network interface observations on this host.""" include_nmne: Optional[bool] = None + """Whether network interface observations should include number of malicious network events.""" include_num_access: Optional[bool] = None + """Whether to include the number of accesses to files observations on this host.""" - def __init__(self, - where: WhereType, - services:List[ServiceObservation], - applications:List[ApplicationObservation], - folders:List[FolderObservation], - network_interfaces:List[NICObservation], - num_services: int, - num_applications: int, - num_folders: int, - num_files: int, - num_nics: int, - include_nmne: bool, - include_num_access: bool - )->None: + def __init__( + self, + where: WhereType, + services: List[ServiceObservation], + applications: List[ApplicationObservation], + folders: List[FolderObservation], + network_interfaces: List[NICObservation], + num_services: int, + num_applications: int, + num_folders: int, + num_files: int, + num_nics: int, + include_nmne: bool, + include_num_access: bool, + ) -> None: + """ + Initialize a host observation instance. - self.where : WhereType = where + :param where: Where in the simulation state dictionary to find the relevant information for this host. + A typical location for a host might be ['network', 'nodes', ]. + :type where: WhereType + :param services: List of service observations on the host. + :type services: List[ServiceObservation] + :param applications: List of application observations on the host. + :type applications: List[ApplicationObservation] + :param folders: List of folder observations on the host. + :type folders: List[FolderObservation] + :param network_interfaces: List of network interface observations on the host. + :type network_interfaces: List[NICObservation] + :param num_services: Number of services to observe. + :type num_services: int + :param num_applications: Number of applications to observe. + :type num_applications: int + :param num_folders: Number of folders to observe. + :type num_folders: int + :param num_files: Number of files. + :type num_files: int + :param num_nics: Number of network interfaces. + :type num_nics: int + :param include_nmne: Flag to include network metrics and errors. + :type include_nmne: bool + :param include_num_access: Flag to include the number of accesses to files. + :type include_num_access: bool + """ + self.where: WhereType = where - # ensure service list has length equal to num_services by truncating or padding + # Ensure lists have lengths equal to specified counts by truncating or padding self.services: List[ServiceObservation] = services while len(self.services) < num_services: self.services.append(ServiceObservation(where=None)) @@ -262,31 +505,30 @@ class HostObservation(AbstractObservation, identifier="HOST"): msg = f"Too many services in Node observation space for node. Truncating service {truncated_service.where}" _LOGGER.warning(msg) - # ensure application list has length equal to num_applications by truncating or padding self.applications: List[ApplicationObservation] = applications while len(self.applications) < num_applications: self.applications.append(ApplicationObservation(where=None)) while len(self.applications) > num_applications: truncated_application = self.applications.pop() - msg = f"Too many applications in Node observation space for node. Truncating application {truncated_application.where}" + msg = f"Too many applications in Node observation space for node. Truncating {truncated_application.where}" _LOGGER.warning(msg) - # ensure folder list has length equal to num_folders by truncating or padding self.folders: List[FolderObservation] = folders while len(self.folders) < num_folders: - self.folders.append(FolderObservation(where = None, files= [], num_files=num_files, include_num_access=include_num_access)) + self.folders.append( + FolderObservation(where=None, files=[], num_files=num_files, include_num_access=include_num_access) + ) while len(self.folders) > num_folders: truncated_folder = self.folders.pop() msg = f"Too many folders in Node observation space for node. Truncating folder {truncated_folder.where}" _LOGGER.warning(msg) - # ensure network_interface list has length equal to num_network_interfaces by truncating or padding self.network_interfaces: List[NICObservation] = network_interfaces while len(self.network_interfaces) < num_nics: - self.network_interfaces.append(NICObservation(where = None, include_nmne=include_nmne)) + self.network_interfaces.append(NICObservation(where=None, include_nmne=include_nmne)) while len(self.network_interfaces) > num_nics: truncated_nic = self.network_interfaces.pop() - msg = f"Too many network_interfaces in Node observation space for node. Truncating {truncated_folder.where}" + msg = f"Too many network_interfaces in Node observation space for node. Truncating {truncated_nic.where}" _LOGGER.warning(msg) self.default_observation: ObsType = { @@ -299,8 +541,15 @@ class HostObservation(AbstractObservation, identifier="HOST"): "num_file_deletions": 0, } - def observe(self, state: Dict) -> Any: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the status information about the host. + :rtype: Any + """ node_state = access_from_nested_dict(state, self.where) if node_state is NOT_PRESENT_IN_STATE: return self.default_observation @@ -319,6 +568,12 @@ class HostObservation(AbstractObservation, identifier="HOST"): @property def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for host status. + :rtype: spaces.Space + """ shape = { "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), "APPLICATIONS": spaces.Dict({i + 1: app.space for i, app in enumerate(self.applications)}), @@ -327,83 +582,165 @@ class HostObservation(AbstractObservation, identifier="HOST"): "NICS": spaces.Dict( {i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)} ), - "num_file_creations" : spaces.Discrete(4), - "num_file_deletions" : spaces.Discrete(4), + "num_file_creations": spaces.Discrete(4), + "num_file_deletions": spaces.Discrete(4), } return spaces.Dict(shape) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = None ) -> HostObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = None) -> HostObservation: + """ + Create a host observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the host observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this host. + A typical location might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed host observation instance. + :rtype: HostObservation + """ if parent_where is None: where = ["network", "nodes", config.hostname] else: where = parent_where + ["nodes", config.hostname] - #pass down shared/common config items + # Pass down shared/common config items for folder_config in config.folders: folder_config.include_num_access = config.include_num_access folder_config.num_files = config.num_files for nic_config in config.network_interfaces: nic_config.include_nmne = config.include_nmne - services = [ServiceObservation.from_config(config=c,parent_where=where) for c in config.services] + services = [ServiceObservation.from_config(config=c, parent_where=where) for c in config.services] applications = [ApplicationObservation.from_config(config=c, parent_where=where) for c in config.applications] folders = [FolderObservation.from_config(config=c, parent_where=where) for c in config.folders] nics = [NICObservation.from_config(config=c, parent_where=where) for c in config.network_interfaces] return cls( - where = where, - services = services, - applications = applications, - folders = folders, - network_interfaces = nics, - num_services = config.num_services, - num_applications = config.num_applications, - num_folders = config.num_folders, - num_files = config.num_files, - num_nics = config.num_nics, - include_nmne = config.include_nmne, - include_num_access = config.include_num_access, + where=where, + services=services, + applications=applications, + folders=folders, + network_interfaces=nics, + num_services=config.num_services, + num_applications=config.num_applications, + num_folders=config.num_folders, + num_files=config.num_files, + num_nics=config.num_nics, + include_nmne=config.include_nmne, + include_num_access=config.include_num_access, ) class PortObservation(AbstractObservation, identifier="PORT"): - class ConfigSchema(AbstractObservation.ConfigSchema): - port_id : int + """Port observation, provides status information about a network port within the simulation environment.""" - def __init__(self, where: WhereType)->None: + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for PortObservation.""" + + port_id: int + """Identifier of the port, used for querying simulation state dictionary.""" + + def __init__(self, where: WhereType) -> None: + """ + Initialize a port observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this port. + A typical location for a port might be ['network', 'nodes', , 'NICs', ]. + :type where: WhereType + """ self.where = where - self.default_observation: ObsType = {"operating_status" : 0} + self.default_observation: ObsType = {"operating_status": 0} def observe(self, state: Dict) -> Any: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the operating status of the port. + :rtype: Any + """ port_state = access_from_nested_dict(state, self.where) if port_state is NOT_PRESENT_IN_STATE: return self.default_observation - return {"operating_status": 1 if port_state["enabled"] else 2 } + return {"operating_status": 1 if port_state["enabled"] else 2} @property def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for port status. + :rtype: spaces.Space + """ return spaces.Dict({"operating_status": spaces.Discrete(3)}) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> PortObservation: - return cls(where = parent_where + ["NICs", config.port_id]) + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> PortObservation: + """ + Create a port observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the port observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this port's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed port observation instance. + :rtype: PortObservation + """ + return cls(where=parent_where + ["NICs", config.port_id]) + class ACLObservation(AbstractObservation, identifier="ACL"): - class ConfigSchema(AbstractObservation.ConfigSchema): - ip_list: Optional[List[IPv4Address]] = None - wildcard_list: Optional[List[str]] = None - port_list: Optional[List[int]] = None - protocol_list: Optional[List[str]] = None - num_rules: Optional[int] = None + """ACL observation, provides information about access control lists within the simulation environment.""" - def __init__(self, where: WhereType, num_rules: int, ip_list: List[IPv4Address], wildcard_list: List[str], port_list: List[int],protocol_list: List[str])->None: + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for ACLObservation.""" + + ip_list: Optional[List[IPv4Address]] = None + """List of IP addresses.""" + wildcard_list: Optional[List[str]] = None + """List of wildcard strings.""" + port_list: Optional[List[int]] = None + """List of port numbers.""" + protocol_list: Optional[List[str]] = None + """List of protocol names.""" + num_rules: Optional[int] = None + """Number of ACL rules.""" + + def __init__( + self, + where: WhereType, + num_rules: int, + ip_list: List[IPv4Address], + wildcard_list: List[str], + port_list: List[int], + protocol_list: List[str], + ) -> None: + """ + Initialize an ACL observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this ACL. + :type where: WhereType + :param num_rules: Number of ACL rules. + :type num_rules: int + :param ip_list: List of IP addresses. + :type ip_list: List[IPv4Address] + :param wildcard_list: List of wildcard strings. + :type wildcard_list: List[str] + :param port_list: List of port numbers. + :type port_list: List[int] + :param protocol_list: List of protocol names. + :type protocol_list: List[str] + """ self.where = where self.num_rules: int = num_rules - self.ip_to_id: Dict[str, int] = {i+2:p for i,p in enumerate(ip_list)} - self.wildcard_to_id: Dict[str, int] = {i+2:p for i,p in enumerate(wildcard_list)} - self.port_to_id: Dict[int, int] = {i+2:p for i,p in enumerate(port_list)} - self.protocol_to_id: Dict[str, int] = {i+2:p for i,p in enumerate(protocol_list)} + self.ip_to_id: Dict[str, int] = {i + 2: p for i, p in enumerate(ip_list)} + self.wildcard_to_id: Dict[str, int] = {i + 2: p for i, p in enumerate(wildcard_list)} + self.port_to_id: Dict[int, int] = {i + 2: p for i, p in enumerate(port_list)} + self.protocol_to_id: Dict[str, int] = {i + 2: p for i, p in enumerate(protocol_list)} self.default_observation: Dict = { i + 1: { @@ -421,6 +758,14 @@ class ACLObservation(AbstractObservation, identifier="ACL"): } def observe(self, state: Dict) -> Any: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing ACL rules. + :rtype: Any + """ acl_state: Dict = access_from_nested_dict(state, self.where) if acl_state is NOT_PRESENT_IN_STATE: return self.default_observation @@ -472,6 +817,12 @@ class ACLObservation(AbstractObservation, identifier="ACL"): @property def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for ACL rules. + :rtype: spaces.Space + """ return spaces.Dict( { i @@ -481,10 +832,10 @@ class ACLObservation(AbstractObservation, identifier="ACL"): "permission": spaces.Discrete(3), # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) "source_ip_id": spaces.Discrete(len(self.ip_to_id) + 2), - "source_wildcard_id": spaces.Discrete(len(self.wildcard_to_id)+2), + "source_wildcard_id": spaces.Discrete(len(self.wildcard_to_id) + 2), "source_port_id": spaces.Discrete(len(self.port_to_id) + 2), "dest_ip_id": spaces.Discrete(len(self.ip_to_id) + 2), - "dest_wildcard_id": spaces.Discrete(len(self.wildcard_to_id)+2), + "dest_wildcard_id": spaces.Discrete(len(self.wildcard_to_id) + 2), "dest_port_id": spaces.Discrete(len(self.port_to_id) + 2), "protocol_id": spaces.Discrete(len(self.protocol_to_id) + 2), } @@ -493,72 +844,134 @@ class ACLObservation(AbstractObservation, identifier="ACL"): } ) - @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ACLObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ACLObservation: + """ + Create an ACL observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the ACL observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this ACL's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed ACL observation instance. + :rtype: ACLObservation + """ return cls( - where = parent_where+["acl", "acl"], - num_rules = config.num_rules, - ip_list = config.ip_list, - wildcard_list = config.wildcard_list, - port_list = config.port_list, - protocol_list = config.protocol_list - ) + where=parent_where + ["acl", "acl"], + num_rules=config.num_rules, + ip_list=config.ip_list, + wildcard_list=config.wildcard_list, + port_list=config.port_list, + protocol_list=config.protocol_list, + ) + class RouterObservation(AbstractObservation, identifier="ROUTER"): - class ConfigSchema(AbstractObservation.ConfigSchema): - hostname: str - ports: Optional[List[PortObservation.ConfigSchema]] = None - num_ports: Optional[int] = None - acl: Optional[ACLObservation.ConfigSchema] = None - ip_list: Optional[List[str]] = None - wildcard_list: Optional[List[str]] = None - port_list: Optional[List[int]] = None - protocol_list: Optional[List[str]] = None - num_rules: Optional[int] = None + """Router observation, provides status information about a router within the simulation environment.""" - def __init__(self, - where: WhereType, - ports:List[PortObservation], - num_ports: int, - acl: ACLObservation, - )->None: + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for RouterObservation.""" + + hostname: str + """Hostname of the router, used for querying simulation state dictionary.""" + ports: Optional[List[PortObservation.ConfigSchema]] = None + """Configuration of port observations for this router.""" + num_ports: Optional[int] = None + """Number of port observations configured for this router.""" + acl: Optional[ACLObservation.ConfigSchema] = None + """Configuration of ACL observation on this router.""" + ip_list: Optional[List[str]] = None + """List of IP addresses for encoding ACLs.""" + wildcard_list: Optional[List[str]] = None + """List of IP wildcards for encoding ACLs.""" + port_list: Optional[List[int]] = None + """List of ports for encoding ACLs.""" + protocol_list: Optional[List[str]] = None + """List of protocols for encoding ACLs.""" + num_rules: Optional[int] = None + """Number of rules ACL rules to show.""" + + def __init__( + self, + where: WhereType, + ports: List[PortObservation], + num_ports: int, + acl: ACLObservation, + ) -> None: + """ + Initialize a router observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this router. + A typical location for a router might be ['network', 'nodes', ]. + :type where: WhereType + :param ports: List of port observations representing the ports of the router. + :type ports: List[PortObservation] + :param num_ports: Number of ports for the router. + :type num_ports: int + :param acl: ACL observation representing the access control list of the router. + :type acl: ACLObservation + """ self.where: WhereType = where self.ports: List[PortObservation] = ports self.acl: ACLObservation = acl - self.num_ports:int = num_ports + self.num_ports: int = num_ports while len(self.ports) < num_ports: self.ports.append(PortObservation(where=None)) while len(self.ports) > num_ports: self.ports.pop() - msg = f"Too many ports in router observation. Truncating." + msg = "Too many ports in router observation. Truncating." _LOGGER.warning(msg) self.default_observation = { - "PORTS": {i+1:p.default_observation for i,p in enumerate(self.ports)}, - "ACL": self.acl.default_observation - } + "PORTS": {i + 1: p.default_observation for i, p in enumerate(self.ports)}, + "ACL": self.acl.default_observation, + } def observe(self, state: Dict) -> Any: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the status of ports and ACL configuration of the router. + :rtype: Any + """ router_state = access_from_nested_dict(state, self.where) if router_state is NOT_PRESENT_IN_STATE: return self.default_observation obs = {} - obs["PORTS"] = {i+1:p.observe(state) for i,p in enumerate(self.ports)} + obs["PORTS"] = {i + 1: p.observe(state) for i, p in enumerate(self.ports)} obs["ACL"] = self.acl.observe(state) return obs @property def space(self) -> spaces.Space: - return spaces.Dict({ - "PORTS": spaces.Dict({i+1:p.space for i,p in enumerate(self.ports)}), - "ACL": self.acl.space - }) + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for router status. + :rtype: spaces.Space + """ + return spaces.Dict( + {"PORTS": spaces.Dict({i + 1: p.space for i, p in enumerate(self.ports)}), "ACL": self.acl.space} + ) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> RouterObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> RouterObservation: + """ + Create a router observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the router observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this router's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed router observation instance. + :rtype: RouterObservation + """ where = parent_where + ["nodes", config.hostname] if config.acl is None: @@ -575,156 +988,330 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): config.acl.protocol_list = config.protocol_list if config.ports is None: - config.ports = [PortObservation.ConfigSchema(port_id=i+1) for i in range(config.num_ports)] + config.ports = [PortObservation.ConfigSchema(port_id=i + 1) for i in range(config.num_ports)] ports = [PortObservation.from_config(config=c, parent_where=where) for c in config.ports] acl = ACLObservation.from_config(config=config.acl, parent_where=where) return cls(where=where, ports=ports, num_ports=config.num_ports, acl=acl) + class FirewallObservation(AbstractObservation, identifier="FIREWALL"): + """Firewall observation, provides status information about a firewall within the simulation environment.""" + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for FirewallObservation.""" + hostname: str + """Hostname of the firewall node, used for querying simulation state dictionary.""" ip_list: Optional[List[str]] = None + """List of IP addresses for encoding ACLs.""" wildcard_list: Optional[List[str]] = None + """List of IP wildcards for encoding ACLs.""" port_list: Optional[List[int]] = None + """List of ports for encoding ACLs.""" protocol_list: Optional[List[str]] = None + """List of protocols for encoding ACLs.""" num_rules: Optional[int] = None + """Number of rules ACL rules to show.""" + def __init__( + self, + where: WhereType, + ip_list: List[str], + wildcard_list: List[str], + port_list: List[int], + protocol_list: List[str], + num_rules: int, + ) -> None: + """ + Initialize a firewall observation instance. - def __init__(self, - where: WhereType, - ip_list: List[str], - wildcard_list: List[str], - port_list: List[int], - protocol_list: List[str], - num_rules: int, - )->None: + :param where: Where in the simulation state dictionary to find the relevant information for this firewall. + A typical location for a firewall might be ['network', 'nodes', ]. + :type where: WhereType + :param ip_list: List of IP addresses. + :type ip_list: List[str] + :param wildcard_list: List of wildcard rules. + :type wildcard_list: List[str] + :param port_list: List of port numbers. + :type port_list: List[int] + :param protocol_list: List of protocol types. + :type protocol_list: List[str] + :param num_rules: Number of rules configured in the firewall. + :type num_rules: int + """ self.where: WhereType = where - self.ports: List[PortObservation] = [PortObservation(where=self.where+["port", port_num]) for port_num in (1,2,3) ] - #TODO: check what the port nums are for firewall. - - self.internal_inbound_acl = ACLObservation(where = self.where+["acl","internal","inbound"], num_rules= num_rules, ip_list=ip_list, wildcard_list=wildcard_list, port_list=port_list, protocol_list=protocol_list) - self.internal_outbound_acl = ACLObservation(where = self.where+["acl","internal","outbound"], num_rules= num_rules, ip_list=ip_list, wildcard_list=wildcard_list, port_list=port_list, protocol_list=protocol_list) - self.dmz_inbound_acl = ACLObservation(where = self.where+["acl","dmz","inbound"], num_rules= num_rules, ip_list=ip_list, wildcard_list=wildcard_list, port_list=port_list, protocol_list=protocol_list) - self.dmz_outbound_acl = ACLObservation(where = self.where+["acl","dmz","outbound"], num_rules= num_rules, ip_list=ip_list, wildcard_list=wildcard_list, port_list=port_list, protocol_list=protocol_list) - self.external_inbound_acl = ACLObservation(where = self.where+["acl","external","inbound"], num_rules= num_rules, ip_list=ip_list, wildcard_list=wildcard_list, port_list=port_list, protocol_list=protocol_list) - self.external_outbound_acl = ACLObservation(where = self.where+["acl","external","outbound"], num_rules= num_rules, ip_list=ip_list, wildcard_list=wildcard_list, port_list=port_list, protocol_list=protocol_list) + self.ports: List[PortObservation] = [ + PortObservation(where=self.where + ["port", port_num]) for port_num in (1, 2, 3) + ] + # TODO: check what the port nums are for firewall. + self.internal_inbound_acl = ACLObservation( + where=self.where + ["acl", "internal", "inbound"], + num_rules=num_rules, + ip_list=ip_list, + wildcard_list=wildcard_list, + port_list=port_list, + protocol_list=protocol_list, + ) + self.internal_outbound_acl = ACLObservation( + where=self.where + ["acl", "internal", "outbound"], + num_rules=num_rules, + ip_list=ip_list, + wildcard_list=wildcard_list, + port_list=port_list, + protocol_list=protocol_list, + ) + self.dmz_inbound_acl = ACLObservation( + where=self.where + ["acl", "dmz", "inbound"], + num_rules=num_rules, + ip_list=ip_list, + wildcard_list=wildcard_list, + port_list=port_list, + protocol_list=protocol_list, + ) + self.dmz_outbound_acl = ACLObservation( + where=self.where + ["acl", "dmz", "outbound"], + num_rules=num_rules, + ip_list=ip_list, + wildcard_list=wildcard_list, + port_list=port_list, + protocol_list=protocol_list, + ) + self.external_inbound_acl = ACLObservation( + where=self.where + ["acl", "external", "inbound"], + num_rules=num_rules, + ip_list=ip_list, + wildcard_list=wildcard_list, + port_list=port_list, + protocol_list=protocol_list, + ) + self.external_outbound_acl = ACLObservation( + where=self.where + ["acl", "external", "outbound"], + num_rules=num_rules, + ip_list=ip_list, + wildcard_list=wildcard_list, + port_list=port_list, + protocol_list=protocol_list, + ) self.default_observation = { - "PORTS": {i+1:p.default_observation for i,p in enumerate(self.ports)}, + "PORTS": {i + 1: p.default_observation for i, p in enumerate(self.ports)}, "INTERNAL": { "INBOUND": self.internal_inbound_acl.default_observation, "OUTBOUND": self.internal_outbound_acl.default_observation, - }, + }, "DMZ": { "INBOUND": self.dmz_inbound_acl.default_observation, "OUTBOUND": self.dmz_outbound_acl.default_observation, - }, + }, "EXTERNAL": { "INBOUND": self.external_inbound_acl.default_observation, "OUTBOUND": self.external_outbound_acl.default_observation, - }, - } + }, + } def observe(self, state: Dict) -> Any: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the status of ports and ACLs for internal, DMZ, and external traffic. + :rtype: Any + """ obs = { - "PORTS": {i+1:p.observe(state) for i,p in enumerate(self.ports)}, + "PORTS": {i + 1: p.observe(state) for i, p in enumerate(self.ports)}, "INTERNAL": { "INBOUND": self.internal_inbound_acl.observe(state), "OUTBOUND": self.internal_outbound_acl.observe(state), - }, + }, "DMZ": { "INBOUND": self.dmz_inbound_acl.observe(state), "OUTBOUND": self.dmz_outbound_acl.observe(state), - }, + }, "EXTERNAL": { "INBOUND": self.external_inbound_acl.observe(state), "OUTBOUND": self.external_outbound_acl.observe(state), - }, - } + }, + } return obs @property def space(self) -> spaces.Space: - space =spaces.Dict({ - "PORTS": spaces.Dict({i+1:p.space for i,p in enumerate(self.ports)}), - "INTERNAL": spaces.Dict({ - "INBOUND": self.internal_inbound_acl.space, - "OUTBOUND": self.internal_outbound_acl.space, - }), - "DMZ": spaces.Dict({ - "INBOUND": self.dmz_inbound_acl.space, - "OUTBOUND": self.dmz_outbound_acl.space, - }), - "EXTERNAL": spaces.Dict({ - "INBOUND": self.external_inbound_acl.space, - "OUTBOUND": self.external_outbound_acl.space, - }), - }) + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for firewall status. + :rtype: spaces.Space + """ + space = spaces.Dict( + { + "PORTS": spaces.Dict({i + 1: p.space for i, p in enumerate(self.ports)}), + "INTERNAL": spaces.Dict( + { + "INBOUND": self.internal_inbound_acl.space, + "OUTBOUND": self.internal_outbound_acl.space, + } + ), + "DMZ": spaces.Dict( + { + "INBOUND": self.dmz_inbound_acl.space, + "OUTBOUND": self.dmz_outbound_acl.space, + } + ), + "EXTERNAL": spaces.Dict( + { + "INBOUND": self.external_inbound_acl.space, + "OUTBOUND": self.external_outbound_acl.space, + } + ), + } + ) return space @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> FirewallObservation: - where = parent_where+["nodes", config.hostname] - return cls(where=where, ip_list=config.ip_list, wildcard_list=config.wildcard_list, port_list=config.port_list, protocol_list=config.protocol_list, num_rules=config.num_rules) + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FirewallObservation: + """ + Create a firewall observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the firewall observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this firewall's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed firewall observation instance. + :rtype: FirewallObservation + """ + where = parent_where + ["nodes", config.hostname] + return cls( + where=where, + ip_list=config.ip_list, + wildcard_list=config.wildcard_list, + port_list=config.port_list, + protocol_list=config.protocol_list, + num_rules=config.num_rules, + ) + class NodesObservation(AbstractObservation, identifier="NODES"): + """Nodes observation, provides status information about nodes within the simulation environment.""" + class ConfigSchema(AbstractObservation.ConfigSchema): - """Config""" + """Configuration schema for NodesObservation.""" + hosts: List[HostObservation.ConfigSchema] = [] + """List of configurations for host observations.""" routers: List[RouterObservation.ConfigSchema] = [] + """List of configurations for router observations.""" firewalls: List[FirewallObservation.ConfigSchema] = [] - + """List of configurations for firewall observations.""" num_services: int + """Number of services.""" num_applications: int + """Number of applications.""" num_folders: int + """Number of folders.""" num_files: int + """Number of files.""" num_nics: int + """Number of network interface cards (NICs).""" include_nmne: bool + """Flag to include nmne.""" include_num_access: bool - + """Flag to include the number of accesses.""" num_ports: int + """Number of ports.""" ip_list: List[str] + """List of IP addresses for encoding ACLs.""" wildcard_list: List[str] + """List of IP wildcards for encoding ACLs.""" port_list: List[int] + """List of ports for encoding ACLs.""" protocol_list: List[str] + """List of protocols for encoding ACLs.""" num_rules: int + """Number of rules ACL rules to show.""" + def __init__( + self, + where: WhereType, + hosts: List[HostObservation], + routers: List[RouterObservation], + firewalls: List[FirewallObservation], + ) -> None: + """ + Initialize a nodes observation instance. - def __init__(self, where: WhereType, hosts:List[HostObservation], routers:List[RouterObservation], firewalls:List[FirewallObservation])->None: - self.where :WhereType = where + :param where: Where in the simulation state dictionary to find the relevant information for nodes. + A typical location for nodes might be ['network', 'nodes']. + :type where: WhereType + :param hosts: List of host observations. + :type hosts: List[HostObservation] + :param routers: List of router observations. + :type routers: List[RouterObservation] + :param firewalls: List of firewall observations. + :type firewalls: List[FirewallObservation] + """ + self.where: WhereType = where self.hosts: List[HostObservation] = hosts self.routers: List[RouterObservation] = routers self.firewalls: List[FirewallObservation] = firewalls self.default_observation = { - **{f"HOST{i}":host.default_observation for i,host in enumerate(self.hosts)}, - **{f"ROUTER{i}":router.default_observation for i,router in enumerate(self.routers)}, - **{f"FIREWALL{i}":firewall.default_observation for i,firewall in enumerate(self.firewalls)}, + **{f"HOST{i}": host.default_observation for i, host in enumerate(self.hosts)}, + **{f"ROUTER{i}": router.default_observation for i, router in enumerate(self.routers)}, + **{f"FIREWALL{i}": firewall.default_observation for i, firewall in enumerate(self.firewalls)}, } def observe(self, state: Dict) -> Any: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing status information about nodes. + :rtype: Any + """ obs = { - **{f"HOST{i}":host.observe(state) for i,host in enumerate(self.hosts)}, - **{f"ROUTER{i}":router.observe(state) for i,router in enumerate(self.routers)}, - **{f"FIREWALL{i}":firewall.observe(state) for i,firewall in enumerate(self.firewalls)}, + **{f"HOST{i}": host.observe(state) for i, host in enumerate(self.hosts)}, + **{f"ROUTER{i}": router.observe(state) for i, router in enumerate(self.routers)}, + **{f"FIREWALL{i}": firewall.observe(state) for i, firewall in enumerate(self.firewalls)}, } return obs @property def space(self) -> spaces.Space: - space = spaces.Dict({ - **{f"HOST{i}":host.space for i,host in enumerate(self.hosts)}, - **{f"ROUTER{i}":router.space for i,router in enumerate(self.routers)}, - **{f"FIREWALL{i}":firewall.space for i,firewall in enumerate(self.firewalls)}, - }) + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for nodes. + :rtype: spaces.Space + """ + space = spaces.Dict( + { + **{f"HOST{i}": host.space for i, host in enumerate(self.hosts)}, + **{f"ROUTER{i}": router.space for i, router in enumerate(self.routers)}, + **{f"FIREWALL{i}": firewall.space for i, firewall in enumerate(self.firewalls)}, + } + ) return space @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = [] ) -> ServiceObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ServiceObservation: + """ + Create a nodes observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for nodes observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about nodes. + A typical location for nodes might be ['network', 'nodes']. + :type parent_where: WhereType, optional + :return: Constructed nodes observation instance. + :rtype: NodesObservation + """ if parent_where is None: where = ["network", "nodes"] else: From 22e1dfea2f4d92a812378e794c3cadd9c926cb50 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 29 Mar 2024 14:14:03 +0000 Subject: [PATCH 772/980] #2417 Move classes to correct files --- .../agent/observations/acl_observation.py | 187 +++ .../agent/observations/agent_observations.py | 138 -- .../observations/file_system_observations.py | 207 +-- .../observations/firewall_observation.py | 213 +++ .../agent/observations/host_observations.py | 229 ++++ .../agent/observations/nic_observations.py | 273 ++-- .../agent/observations/node_observations.py | 1197 +---------------- .../game/agent/observations/observations.py | 467 +++---- .../agent/observations/router_observation.py | 142 ++ .../observations/software_observation.py | 192 ++- 10 files changed, 1332 insertions(+), 1913 deletions(-) create mode 100644 src/primaite/game/agent/observations/acl_observation.py delete mode 100644 src/primaite/game/agent/observations/agent_observations.py create mode 100644 src/primaite/game/agent/observations/firewall_observation.py create mode 100644 src/primaite/game/agent/observations/host_observations.py create mode 100644 src/primaite/game/agent/observations/router_observation.py diff --git a/src/primaite/game/agent/observations/acl_observation.py b/src/primaite/game/agent/observations/acl_observation.py new file mode 100644 index 00000000..2d29223d --- /dev/null +++ b/src/primaite/game/agent/observations/acl_observation.py @@ -0,0 +1,187 @@ +from __future__ import annotations + +from ipaddress import IPv4Address +from typing import Dict, List, Optional + +from gymnasium import spaces +from gymnasium.core import ObsType + +from primaite import getLogger +from primaite.game.agent.observations.observations import AbstractObservation, WhereType +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE + +_LOGGER = getLogger(__name__) + + +class ACLObservation(AbstractObservation, identifier="ACL"): + """ACL observation, provides information about access control lists within the simulation environment.""" + + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for ACLObservation.""" + + ip_list: Optional[List[IPv4Address]] = None + """List of IP addresses.""" + wildcard_list: Optional[List[str]] = None + """List of wildcard strings.""" + port_list: Optional[List[int]] = None + """List of port numbers.""" + protocol_list: Optional[List[str]] = None + """List of protocol names.""" + num_rules: Optional[int] = None + """Number of ACL rules.""" + + def __init__( + self, + where: WhereType, + num_rules: int, + ip_list: List[IPv4Address], + wildcard_list: List[str], + port_list: List[int], + protocol_list: List[str], + ) -> None: + """ + Initialize an ACL observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this ACL. + :type where: WhereType + :param num_rules: Number of ACL rules. + :type num_rules: int + :param ip_list: List of IP addresses. + :type ip_list: List[IPv4Address] + :param wildcard_list: List of wildcard strings. + :type wildcard_list: List[str] + :param port_list: List of port numbers. + :type port_list: List[int] + :param protocol_list: List of protocol names. + :type protocol_list: List[str] + """ + self.where = where + self.num_rules: int = num_rules + self.ip_to_id: Dict[str, int] = {i + 2: p for i, p in enumerate(ip_list)} + self.wildcard_to_id: Dict[str, int] = {i + 2: p for i, p in enumerate(wildcard_list)} + self.port_to_id: Dict[int, int] = {i + 2: p for i, p in enumerate(port_list)} + self.protocol_to_id: Dict[str, int] = {i + 2: p for i, p in enumerate(protocol_list)} + self.default_observation: Dict = { + i + + 1: { + "position": i, + "permission": 0, + "source_ip_id": 0, + "source_wildcard_id": 0, + "source_port_id": 0, + "dest_ip_id": 0, + "dest_wildcard_id": 0, + "dest_port_id": 0, + "protocol_id": 0, + } + for i in range(self.num_rules) + } + + def observe(self, state: Dict) -> ObsType: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing ACL rules. + :rtype: ObsType + """ + acl_state: Dict = access_from_nested_dict(state, self.where) + if acl_state is NOT_PRESENT_IN_STATE: + return self.default_observation + obs = {} + acl_items = dict(acl_state.items()) + i = 1 # don't show rule 0 for compatibility reasons. + while i < self.num_rules + 1: + rule_state = acl_items[i] + if rule_state is None: + obs[i] = { + "position": i - 1, + "permission": 0, + "source_ip_id": 0, + "source_wildcard_id": 0, + "source_port_id": 0, + "dest_ip_id": 0, + "dest_wildcard_id": 0, + "dest_port_id": 0, + "protocol_id": 0, + } + else: + src_ip = rule_state["src_ip_address"] + src_node_id = self.ip_to_id.get(src_ip, 1) + dst_ip = rule_state["dst_ip_address"] + dst_node_ip = self.ip_to_id.get(dst_ip, 1) + src_wildcard = rule_state["source_wildcard_id"] + src_wildcard_id = self.wildcard_to_id.get(src_wildcard, 1) + dst_wildcard = rule_state["dest_wildcard_id"] + dst_wildcard_id = self.wildcard_to_id.get(dst_wildcard, 1) + src_port = rule_state["source_port_id"] + src_port_id = self.port_to_id.get(src_port, 1) + dst_port = rule_state["dest_port_id"] + dst_port_id = self.port_to_id.get(dst_port, 1) + protocol = rule_state["protocol"] + protocol_id = self.protocol_to_id.get(protocol, 1) + obs[i] = { + "position": i - 1, + "permission": rule_state["action"], + "source_ip_id": src_node_id, + "source_wildcard_id": src_wildcard_id, + "source_port_id": src_port_id, + "dest_ip_id": dst_node_ip, + "dest_wildcard_id": dst_wildcard_id, + "dest_port_id": dst_port_id, + "protocol_id": protocol_id, + } + i += 1 + return obs + + @property + def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for ACL rules. + :rtype: spaces.Space + """ + return spaces.Dict( + { + i + + 1: spaces.Dict( + { + "position": spaces.Discrete(self.num_rules), + "permission": spaces.Discrete(3), + # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) + "source_ip_id": spaces.Discrete(len(self.ip_to_id) + 2), + "source_wildcard_id": spaces.Discrete(len(self.wildcard_to_id) + 2), + "source_port_id": spaces.Discrete(len(self.port_to_id) + 2), + "dest_ip_id": spaces.Discrete(len(self.ip_to_id) + 2), + "dest_wildcard_id": spaces.Discrete(len(self.wildcard_to_id) + 2), + "dest_port_id": spaces.Discrete(len(self.port_to_id) + 2), + "protocol_id": spaces.Discrete(len(self.protocol_to_id) + 2), + } + ) + for i in range(self.num_rules) + } + ) + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ACLObservation: + """ + Create an ACL observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the ACL observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this ACL's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed ACL observation instance. + :rtype: ACLObservation + """ + return cls( + where=parent_where + ["acl", "acl"], + num_rules=config.num_rules, + ip_list=config.ip_list, + wildcard_list=config.wildcard_list, + port_list=config.port_list, + protocol_list=config.protocol_list, + ) diff --git a/src/primaite/game/agent/observations/agent_observations.py b/src/primaite/game/agent/observations/agent_observations.py deleted file mode 100644 index 10370660..00000000 --- a/src/primaite/game/agent/observations/agent_observations.py +++ /dev/null @@ -1,138 +0,0 @@ -from typing import Dict, List, Optional, Tuple, TYPE_CHECKING - -from gymnasium import spaces - -from primaite.game.agent.observations.node_observations import NodeObservation -from primaite.game.agent.observations.observations import ( - AbstractObservation, - AclObservation, - ICSObservation, - LinkObservation, - NullObservation, -) - -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame - - -class UC2BlueObservation(AbstractObservation): - """Container for all observations used by the blue agent in UC2. - - TODO: there's no real need for a UC2 blue container class, we should be able to simply use the observation handler - for the purpose of compiling several observation components. - """ - - def __init__( - self, - nodes: List[NodeObservation], - links: List[LinkObservation], - acl: AclObservation, - ics: ICSObservation, - where: Optional[List[str]] = None, - ) -> None: - """Initialise UC2 blue observation. - - :param nodes: List of node observations - :type nodes: List[NodeObservation] - :param links: List of link observations - :type links: List[LinkObservation] - :param acl: The Access Control List observation - :type acl: AclObservation - :param ics: The ICS observation - :type ics: ICSObservation - :param where: Where in the simulation state dict to find information. Not used in this particular observation - because it only compiles other observations and doesn't contribute any new information, defaults to None - :type where: Optional[List[str]], optional - """ - super().__init__() - self.where: Optional[Tuple[str]] = where - - self.nodes: List[NodeObservation] = nodes - self.links: List[LinkObservation] = links - self.acl: AclObservation = acl - self.ics: ICSObservation = ics - - self.default_observation: Dict = { - "NODES": {i + 1: n.default_observation for i, n in enumerate(self.nodes)}, - "LINKS": {i + 1: l.default_observation for i, l in enumerate(self.links)}, - "ACL": self.acl.default_observation, - "ICS": self.ics.default_observation, - } - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict - """ - if self.where is None: - return self.default_observation - - obs = {} - obs["NODES"] = {i + 1: node.observe(state) for i, node in enumerate(self.nodes)} - obs["LINKS"] = {i + 1: link.observe(state) for i, link in enumerate(self.links)} - obs["ACL"] = self.acl.observe(state) - obs["ICS"] = self.ics.observe(state) - - return obs - - @property - def space(self) -> spaces.Space: - """ - Gymnasium space object describing the observation space shape. - - :return: Space - :rtype: spaces.Space - """ - return spaces.Dict( - { - "NODES": spaces.Dict({i + 1: node.space for i, node in enumerate(self.nodes)}), - "LINKS": spaces.Dict({i + 1: link.space for i, link in enumerate(self.links)}), - "ACL": self.acl.space, - "ICS": self.ics.space, - } - ) - - @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "UC2BlueObservation": - """Create UC2 blue observation from a config. - - :param config: Dictionary containing the configuration for this UC2 blue observation. This includes the nodes, - links, ACL and ICS observations. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :return: Constructed UC2 blue observation - :rtype: UC2BlueObservation - """ - node_configs = config["nodes"] - - num_services_per_node = config["num_services_per_node"] - num_folders_per_node = config["num_folders_per_node"] - num_files_per_folder = config["num_files_per_folder"] - num_nics_per_node = config["num_nics_per_node"] - nodes = [ - NodeObservation.from_config( - config=n, - game=game, - num_services_per_node=num_services_per_node, - num_folders_per_node=num_folders_per_node, - num_files_per_folder=num_files_per_folder, - num_nics_per_node=num_nics_per_node, - ) - for n in node_configs - ] - - link_configs = config["links"] - links = [LinkObservation.from_config(config=link, game=game) for link in link_configs] - - acl_config = config["acl"] - acl = AclObservation.from_config(config=acl_config, game=game) - - ics_config = config["ics"] - ics = ICSObservation.from_config(config=ics_config, game=game) - new = cls(nodes=nodes, links=links, acl=acl, ics=ics, where=["network"]) - return new - diff --git a/src/primaite/game/agent/observations/file_system_observations.py b/src/primaite/game/agent/observations/file_system_observations.py index 277bc51f..a30bfc82 100644 --- a/src/primaite/game/agent/observations/file_system_observations.py +++ b/src/primaite/game/agent/observations/file_system_observations.py @@ -1,107 +1,130 @@ -from typing import Dict, List, Optional, Tuple, TYPE_CHECKING +from __future__ import annotations + +from typing import Dict, Iterable, List, Optional from gymnasium import spaces +from gymnasium.core import ObsType from primaite import getLogger -from primaite.game.agent.observations.observations import AbstractObservation +from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE _LOGGER = getLogger(__name__) -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame +class FileObservation(AbstractObservation, identifier="FILE"): + """File observation, provides status information about a file within the simulation environment.""" -class FileObservation(AbstractObservation): - """Observation of a file on a node in the network.""" + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for FileObservation.""" - def __init__(self, where: Optional[Tuple[str]] = None) -> None: + file_name: str + """Name of the file, used for querying simulation state dictionary.""" + include_num_access: Optional[bool] = None + """Whether to include the number of accesses to the file in the observation.""" + + def __init__(self, where: WhereType, include_num_access: bool) -> None: """ - Initialise file observation. + Initialize a file observation instance. - :param where: Store information about where in the simulation state dictionary to find the relevant information. - Optional. If None, this corresponds that the file does not exist and the observation will be populated with - zeroes. - - A typical location for a file looks like this: - ['network','nodes',,'file_system', 'folders',,'files',] - :type where: Optional[List[str]] + :param where: Where in the simulation state dictionary to find the relevant information for this file. + A typical location for a file might be + ['network', 'nodes', , 'file_system', 'folder', , 'files', ]. + :type where: WhereType + :param include_num_access: Whether to include the number of accesses to the file in the observation. + :type include_num_access: bool """ - super().__init__() - self.where: Optional[Tuple[str]] = where - self.default_observation: spaces.Space = {"health_status": 0} - "Default observation is what should be returned when the file doesn't exist, e.g. after it has been deleted." + self.where: WhereType = where + self.include_num_access: bool = include_num_access - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. + self.default_observation: ObsType = {"health_status": 0} + if self.include_num_access: + self.default_observation["num_access"] = 0 - :param state: Simulation state dictionary + def observe(self, state: Dict) -> ObsType: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. :type state: Dict - :return: Observation - :rtype: Dict + :return: Observation containing the health status of the file and optionally the number of accesses. + :rtype: ObsType """ - if self.where is None: - return self.default_observation file_state = access_from_nested_dict(state, self.where) if file_state is NOT_PRESENT_IN_STATE: return self.default_observation - return {"health_status": file_state["visible_status"]} + obs = {"health_status": file_state["visible_status"]} + if self.include_num_access: + obs["num_access"] = file_state["num_access"] + # raise NotImplementedError("TODO: need to fix num_access to use thresholds instead of raw value.") + return obs @property def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape. + """ + Gymnasium space object describing the observation space shape. - :return: Gymnasium space + :return: Gymnasium space representing the observation space for file status. :rtype: spaces.Space """ - return spaces.Dict({"health_status": spaces.Discrete(6)}) + space = {"health_status": spaces.Discrete(6)} + if self.include_num_access: + space["num_access"] = spaces.Discrete(4) + return spaces.Dict(space) @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame", parent_where: List[str] = None) -> "FileObservation": - """Create file observation from a config. - - :param config: Dictionary containing the configuration for this file observation. - :type config: Dict - :param game: _description_ - :type game: PrimaiteGame - :param parent_where: _description_, defaults to None - :type parent_where: _type_, optional - :return: _description_ - :rtype: _type_ + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FileObservation: """ - return cls(where=parent_where + ["files", config["file_name"]]) + Create a file observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the file observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this file's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed file observation instance. + :rtype: FileObservation + """ + return cls(where=parent_where + ["files", config.file_name], include_num_access=config.include_num_access) -class FolderObservation(AbstractObservation): - """Folder observation, including files inside of the folder.""" +class FolderObservation(AbstractObservation, identifier="FOLDER"): + """Folder observation, provides status information about a folder within the simulation environment.""" + + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for FolderObservation.""" + + folder_name: str + """Name of the folder, used for querying simulation state dictionary.""" + files: List[FileObservation.ConfigSchema] = [] + """List of file configurations within the folder.""" + num_files: Optional[int] = None + """Number of spaces for file observations in this folder.""" + include_num_access: Optional[bool] = None + """Whether files in this folder should include the number of accesses in their observation.""" def __init__( - self, where: Optional[Tuple[str]] = None, files: List[FileObservation] = [], num_files_per_folder: int = 2 + self, where: WhereType, files: Iterable[FileObservation], num_files: int, include_num_access: bool ) -> None: - """Initialise folder Observation, including files inside the folder. + """ + Initialize a folder observation instance. :param where: Where in the simulation state dictionary to find the relevant information for this folder. - A typical location for a file looks like this: - ['network','nodes',,'file_system', 'folders',] - :type where: Optional[List[str]] - :param max_files: As size of the space must remain static, define max files that can be in this folder - , defaults to 5 - :type max_files: int, optional - :param file_positions: Defines the positioning within the observation space of particular files. This ensures - that even if new files are created, the existing files will always occupy the same space in the observation - space. The keys must be between 1 and max_files. Providing file_positions will reserve a spot in the - observation space for a file with that name, even if it's temporarily deleted, if it reappears with the same - name, it will take the position defined in this dict. Defaults to {} - :type file_positions: Dict[int, str], optional + A typical location for a folder might be ['network', 'nodes', , 'folders', ]. + :type where: WhereType + :param files: List of file observation instances within the folder. + :type files: Iterable[FileObservation] + :param num_files: Number of files expected in the folder. + :type num_files: int + :param include_num_access: Whether to include the number of accesses to files in the observation. + :type include_num_access: bool """ - super().__init__() - - self.where: Optional[Tuple[str]] = where + self.where: WhereType = where self.files: List[FileObservation] = files - while len(self.files) < num_files_per_folder: - self.files.append(FileObservation()) - while len(self.files) > num_files_per_folder: + while len(self.files) < num_files: + self.files.append(FileObservation(where=None, include_num_access=include_num_access)) + while len(self.files) > num_files: truncated_file = self.files.pop() msg = f"Too many files in folder observation. Truncating file {truncated_file}" _LOGGER.warning(msg) @@ -111,16 +134,15 @@ class FolderObservation(AbstractObservation): "FILES": {i + 1: f.default_observation for i, f in enumerate(self.files)}, } - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict + def observe(self, state: Dict) -> ObsType: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the health status of the folder and status of files within the folder. + :rtype: ObsType """ - if self.where is None: - return self.default_observation folder_state = access_from_nested_dict(state, self.where) if folder_state is NOT_PRESENT_IN_STATE: return self.default_observation @@ -136,9 +158,10 @@ class FolderObservation(AbstractObservation): @property def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape. + """ + Gymnasium space object describing the observation space shape. - :return: Gymnasium space + :return: Gymnasium space representing the observation space for folder status. :rtype: spaces.Space """ return spaces.Dict( @@ -149,29 +172,23 @@ class FolderObservation(AbstractObservation): ) @classmethod - def from_config( - cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]], num_files_per_folder: int = 2 - ) -> "FolderObservation": - """Create folder observation from a config. Also creates child file observations. + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FolderObservation: + """ + Create a folder observation from a configuration schema. - :param config: Dictionary containing the configuration for this folder observation. Includes the name of the - folder and the files inside of it. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame + :param config: Configuration schema containing the necessary information for the folder observation. + :type config: ConfigSchema :param parent_where: Where in the simulation state dictionary to find the information about this folder's - parent node. A typical location for a node ``where`` can be: - ['network','nodes',,'file_system'] - :type parent_where: Optional[List[str]] - :param num_files_per_folder: How many spaces for files are in this folder observation (to preserve static - observation size) , defaults to 2 - :type num_files_per_folder: int, optional - :return: Constructed folder observation + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed folder observation instance. :rtype: FolderObservation """ - where = parent_where + ["folders", config["folder_name"]] + where = parent_where + ["folders", config.folder_name] - file_configs = config["files"] - files = [FileObservation.from_config(config=f, game=game, parent_where=where) for f in file_configs] + # pass down shared/common config items + for file_config in config.files: + file_config.include_num_access = config.include_num_access - return cls(where=where, files=files, num_files_per_folder=num_files_per_folder) + files = [FileObservation.from_config(config=f, parent_where=where) for f in config.files] + return cls(where=where, files=files, num_files=config.num_files, include_num_access=config.include_num_access) diff --git a/src/primaite/game/agent/observations/firewall_observation.py b/src/primaite/game/agent/observations/firewall_observation.py new file mode 100644 index 00000000..6397d473 --- /dev/null +++ b/src/primaite/game/agent/observations/firewall_observation.py @@ -0,0 +1,213 @@ +from __future__ import annotations + +from typing import Dict, List, Optional + +from gymnasium import spaces +from gymnasium.core import ObsType + +from primaite import getLogger +from primaite.game.agent.observations.acl_observation import ACLObservation +from primaite.game.agent.observations.nic_observations import PortObservation +from primaite.game.agent.observations.observations import AbstractObservation, WhereType + +_LOGGER = getLogger(__name__) + + +class FirewallObservation(AbstractObservation, identifier="FIREWALL"): + """Firewall observation, provides status information about a firewall within the simulation environment.""" + + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for FirewallObservation.""" + + hostname: str + """Hostname of the firewall node, used for querying simulation state dictionary.""" + ip_list: Optional[List[str]] = None + """List of IP addresses for encoding ACLs.""" + wildcard_list: Optional[List[str]] = None + """List of IP wildcards for encoding ACLs.""" + port_list: Optional[List[int]] = None + """List of ports for encoding ACLs.""" + protocol_list: Optional[List[str]] = None + """List of protocols for encoding ACLs.""" + num_rules: Optional[int] = None + """Number of rules ACL rules to show.""" + + def __init__( + self, + where: WhereType, + ip_list: List[str], + wildcard_list: List[str], + port_list: List[int], + protocol_list: List[str], + num_rules: int, + ) -> None: + """ + Initialize a firewall observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this firewall. + A typical location for a firewall might be ['network', 'nodes', ]. + :type where: WhereType + :param ip_list: List of IP addresses. + :type ip_list: List[str] + :param wildcard_list: List of wildcard rules. + :type wildcard_list: List[str] + :param port_list: List of port numbers. + :type port_list: List[int] + :param protocol_list: List of protocol types. + :type protocol_list: List[str] + :param num_rules: Number of rules configured in the firewall. + :type num_rules: int + """ + self.where: WhereType = where + + self.ports: List[PortObservation] = [ + PortObservation(where=self.where + ["port", port_num]) for port_num in (1, 2, 3) + ] + # TODO: check what the port nums are for firewall. + + self.internal_inbound_acl = ACLObservation( + where=self.where + ["acl", "internal", "inbound"], + num_rules=num_rules, + ip_list=ip_list, + wildcard_list=wildcard_list, + port_list=port_list, + protocol_list=protocol_list, + ) + self.internal_outbound_acl = ACLObservation( + where=self.where + ["acl", "internal", "outbound"], + num_rules=num_rules, + ip_list=ip_list, + wildcard_list=wildcard_list, + port_list=port_list, + protocol_list=protocol_list, + ) + self.dmz_inbound_acl = ACLObservation( + where=self.where + ["acl", "dmz", "inbound"], + num_rules=num_rules, + ip_list=ip_list, + wildcard_list=wildcard_list, + port_list=port_list, + protocol_list=protocol_list, + ) + self.dmz_outbound_acl = ACLObservation( + where=self.where + ["acl", "dmz", "outbound"], + num_rules=num_rules, + ip_list=ip_list, + wildcard_list=wildcard_list, + port_list=port_list, + protocol_list=protocol_list, + ) + self.external_inbound_acl = ACLObservation( + where=self.where + ["acl", "external", "inbound"], + num_rules=num_rules, + ip_list=ip_list, + wildcard_list=wildcard_list, + port_list=port_list, + protocol_list=protocol_list, + ) + self.external_outbound_acl = ACLObservation( + where=self.where + ["acl", "external", "outbound"], + num_rules=num_rules, + ip_list=ip_list, + wildcard_list=wildcard_list, + port_list=port_list, + protocol_list=protocol_list, + ) + + self.default_observation = { + "PORTS": {i + 1: p.default_observation for i, p in enumerate(self.ports)}, + "INTERNAL": { + "INBOUND": self.internal_inbound_acl.default_observation, + "OUTBOUND": self.internal_outbound_acl.default_observation, + }, + "DMZ": { + "INBOUND": self.dmz_inbound_acl.default_observation, + "OUTBOUND": self.dmz_outbound_acl.default_observation, + }, + "EXTERNAL": { + "INBOUND": self.external_inbound_acl.default_observation, + "OUTBOUND": self.external_outbound_acl.default_observation, + }, + } + + def observe(self, state: Dict) -> ObsType: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the status of ports and ACLs for internal, DMZ, and external traffic. + :rtype: ObsType + """ + obs = { + "PORTS": {i + 1: p.observe(state) for i, p in enumerate(self.ports)}, + "INTERNAL": { + "INBOUND": self.internal_inbound_acl.observe(state), + "OUTBOUND": self.internal_outbound_acl.observe(state), + }, + "DMZ": { + "INBOUND": self.dmz_inbound_acl.observe(state), + "OUTBOUND": self.dmz_outbound_acl.observe(state), + }, + "EXTERNAL": { + "INBOUND": self.external_inbound_acl.observe(state), + "OUTBOUND": self.external_outbound_acl.observe(state), + }, + } + return obs + + @property + def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for firewall status. + :rtype: spaces.Space + """ + space = spaces.Dict( + { + "PORTS": spaces.Dict({i + 1: p.space for i, p in enumerate(self.ports)}), + "INTERNAL": spaces.Dict( + { + "INBOUND": self.internal_inbound_acl.space, + "OUTBOUND": self.internal_outbound_acl.space, + } + ), + "DMZ": spaces.Dict( + { + "INBOUND": self.dmz_inbound_acl.space, + "OUTBOUND": self.dmz_outbound_acl.space, + } + ), + "EXTERNAL": spaces.Dict( + { + "INBOUND": self.external_inbound_acl.space, + "OUTBOUND": self.external_outbound_acl.space, + } + ), + } + ) + return space + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FirewallObservation: + """ + Create a firewall observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the firewall observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this firewall's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed firewall observation instance. + :rtype: FirewallObservation + """ + where = parent_where + ["nodes", config.hostname] + return cls( + where=where, + ip_list=config.ip_list, + wildcard_list=config.wildcard_list, + port_list=config.port_list, + protocol_list=config.protocol_list, + num_rules=config.num_rules, + ) diff --git a/src/primaite/game/agent/observations/host_observations.py b/src/primaite/game/agent/observations/host_observations.py new file mode 100644 index 00000000..34c9b3ff --- /dev/null +++ b/src/primaite/game/agent/observations/host_observations.py @@ -0,0 +1,229 @@ +from __future__ import annotations + +from typing import Dict, List, Optional + +from gymnasium import spaces +from gymnasium.core import ObsType + +from primaite import getLogger +from primaite.game.agent.observations.file_system_observations import FolderObservation +from primaite.game.agent.observations.nic_observations import NICObservation +from primaite.game.agent.observations.observations import AbstractObservation, WhereType +from primaite.game.agent.observations.software_observation import ApplicationObservation, ServiceObservation +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE + +_LOGGER = getLogger(__name__) + + +class HostObservation(AbstractObservation, identifier="HOST"): + """Host observation, provides status information about a host within the simulation environment.""" + + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for HostObservation.""" + + hostname: str + """Hostname of the host, used for querying simulation state dictionary.""" + services: List[ServiceObservation.ConfigSchema] = [] + """List of services to observe on the host.""" + applications: List[ApplicationObservation.ConfigSchema] = [] + """List of applications to observe on the host.""" + folders: List[FolderObservation.ConfigSchema] = [] + """List of folders to observe on the host.""" + network_interfaces: List[NICObservation.ConfigSchema] = [] + """List of network interfaces to observe on the host.""" + num_services: Optional[int] = None + """Number of spaces for service observations on this host.""" + num_applications: Optional[int] = None + """Number of spaces for application observations on this host.""" + num_folders: Optional[int] = None + """Number of spaces for folder observations on this host.""" + num_files: Optional[int] = None + """Number of spaces for file observations on this host.""" + num_nics: Optional[int] = None + """Number of spaces for network interface observations on this host.""" + include_nmne: Optional[bool] = None + """Whether network interface observations should include number of malicious network events.""" + include_num_access: Optional[bool] = None + """Whether to include the number of accesses to files observations on this host.""" + + def __init__( + self, + where: WhereType, + services: List[ServiceObservation], + applications: List[ApplicationObservation], + folders: List[FolderObservation], + network_interfaces: List[NICObservation], + num_services: int, + num_applications: int, + num_folders: int, + num_files: int, + num_nics: int, + include_nmne: bool, + include_num_access: bool, + ) -> None: + """ + Initialize a host observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this host. + A typical location for a host might be ['network', 'nodes', ]. + :type where: WhereType + :param services: List of service observations on the host. + :type services: List[ServiceObservation] + :param applications: List of application observations on the host. + :type applications: List[ApplicationObservation] + :param folders: List of folder observations on the host. + :type folders: List[FolderObservation] + :param network_interfaces: List of network interface observations on the host. + :type network_interfaces: List[NICObservation] + :param num_services: Number of services to observe. + :type num_services: int + :param num_applications: Number of applications to observe. + :type num_applications: int + :param num_folders: Number of folders to observe. + :type num_folders: int + :param num_files: Number of files. + :type num_files: int + :param num_nics: Number of network interfaces. + :type num_nics: int + :param include_nmne: Flag to include network metrics and errors. + :type include_nmne: bool + :param include_num_access: Flag to include the number of accesses to files. + :type include_num_access: bool + """ + self.where: WhereType = where + + # Ensure lists have lengths equal to specified counts by truncating or padding + self.services: List[ServiceObservation] = services + while len(self.services) < num_services: + self.services.append(ServiceObservation(where=None)) + while len(self.services) > num_services: + truncated_service = self.services.pop() + msg = f"Too many services in Node observation space for node. Truncating service {truncated_service.where}" + _LOGGER.warning(msg) + + self.applications: List[ApplicationObservation] = applications + while len(self.applications) < num_applications: + self.applications.append(ApplicationObservation(where=None)) + while len(self.applications) > num_applications: + truncated_application = self.applications.pop() + msg = f"Too many applications in Node observation space for node. Truncating {truncated_application.where}" + _LOGGER.warning(msg) + + self.folders: List[FolderObservation] = folders + while len(self.folders) < num_folders: + self.folders.append( + FolderObservation(where=None, files=[], num_files=num_files, include_num_access=include_num_access) + ) + while len(self.folders) > num_folders: + truncated_folder = self.folders.pop() + msg = f"Too many folders in Node observation space for node. Truncating folder {truncated_folder.where}" + _LOGGER.warning(msg) + + self.network_interfaces: List[NICObservation] = network_interfaces + while len(self.network_interfaces) < num_nics: + self.network_interfaces.append(NICObservation(where=None, include_nmne=include_nmne)) + while len(self.network_interfaces) > num_nics: + truncated_nic = self.network_interfaces.pop() + msg = f"Too many network_interfaces in Node observation space for node. Truncating {truncated_nic.where}" + _LOGGER.warning(msg) + + self.default_observation: ObsType = { + "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, + "APPLICATIONS": {i + 1: a.default_observation for i, a in enumerate(self.applications)}, + "FOLDERS": {i + 1: f.default_observation for i, f in enumerate(self.folders)}, + "NICS": {i + 1: n.default_observation for i, n in enumerate(self.network_interfaces)}, + "operating_status": 0, + "num_file_creations": 0, + "num_file_deletions": 0, + } + + def observe(self, state: Dict) -> ObsType: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the status information about the host. + :rtype: ObsType + """ + node_state = access_from_nested_dict(state, self.where) + if node_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + obs = {} + obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} + obs["APPLICATIONS"] = {i + 1: app.observe(state) for i, app in enumerate(self.applications)} + obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} + obs["operating_status"] = node_state["operating_state"] + obs["NICS"] = { + i + 1: network_interface.observe(state) for i, network_interface in enumerate(self.network_interfaces) + } + obs["num_file_creations"] = node_state["file_system"]["num_file_creations"] + obs["num_file_deletions"] = node_state["file_system"]["num_file_deletions"] + return obs + + @property + def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for host status. + :rtype: spaces.Space + """ + shape = { + "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), + "APPLICATIONS": spaces.Dict({i + 1: app.space for i, app in enumerate(self.applications)}), + "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), + "operating_status": spaces.Discrete(5), + "NICS": spaces.Dict( + {i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)} + ), + "num_file_creations": spaces.Discrete(4), + "num_file_deletions": spaces.Discrete(4), + } + return spaces.Dict(shape) + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = None) -> HostObservation: + """ + Create a host observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the host observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this host. + A typical location might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed host observation instance. + :rtype: HostObservation + """ + if parent_where is None: + where = ["network", "nodes", config.hostname] + else: + where = parent_where + ["nodes", config.hostname] + + # Pass down shared/common config items + for folder_config in config.folders: + folder_config.include_num_access = config.include_num_access + folder_config.num_files = config.num_files + for nic_config in config.network_interfaces: + nic_config.include_nmne = config.include_nmne + + services = [ServiceObservation.from_config(config=c, parent_where=where) for c in config.services] + applications = [ApplicationObservation.from_config(config=c, parent_where=where) for c in config.applications] + folders = [FolderObservation.from_config(config=c, parent_where=where) for c in config.folders] + nics = [NICObservation.from_config(config=c, parent_where=where) for c in config.network_interfaces] + + return cls( + where=where, + services=services, + applications=applications, + folders=folders, + network_interfaces=nics, + num_services=config.num_services, + num_applications=config.num_applications, + num_folders=config.num_folders, + num_files=config.num_files, + num_nics=config.num_nics, + include_nmne=config.include_nmne, + include_num_access=config.include_num_access, + ) diff --git a/src/primaite/game/agent/observations/nic_observations.py b/src/primaite/game/agent/observations/nic_observations.py index de83e03a..3be53112 100644 --- a/src/primaite/game/agent/observations/nic_observations.py +++ b/src/primaite/game/agent/observations/nic_observations.py @@ -1,188 +1,157 @@ -from typing import Dict, List, Optional, Tuple, TYPE_CHECKING +from __future__ import annotations + +from typing import Dict, Optional from gymnasium import spaces +from gymnasium.core import ObsType -from primaite.game.agent.observations.observations import AbstractObservation +from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE -from primaite.simulator.network.nmne import CAPTURE_NMNE - -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame -class NicObservation(AbstractObservation): - """Observation of a Network Interface Card (NIC) in the network.""" +class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): + """Status information about a network interface within the simulation environment.""" - low_nmne_threshold: int = 0 - """The minimum number of malicious network events to be considered low.""" - med_nmne_threshold: int = 5 - """The minimum number of malicious network events to be considered medium.""" - high_nmne_threshold: int = 10 - """The minimum number of malicious network events to be considered high.""" + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for NICObservation.""" - global CAPTURE_NMNE + nic_num: int + """Number of the network interface.""" + include_nmne: Optional[bool] = None + """Whether to include number of malicious network events (NMNE) in the observation.""" - @property - def default_observation(self) -> Dict: - """The default NIC observation dict.""" - data = {"nic_status": 0} - if CAPTURE_NMNE: - data.update({"NMNE": {"inbound": 0, "outbound": 0}}) - - return data - - def __init__( - self, - where: Optional[Tuple[str]] = None, - low_nmne_threshold: Optional[int] = 0, - med_nmne_threshold: Optional[int] = 5, - high_nmne_threshold: Optional[int] = 10, - ) -> None: - """Initialise NIC observation. - - :param where: Where in the simulation state dictionary to find the relevant information for this NIC. A typical - example may look like this: - ['network','nodes',,'NICs',] - If None, this denotes that the NIC does not exist and the observation will be populated with zeroes. - :type where: Optional[Tuple[str]], optional + def __init__(self, where: WhereType, include_nmne: bool) -> None: """ - super().__init__() - self.where: Optional[Tuple[str]] = where + Initialize a network interface observation instance. - global CAPTURE_NMNE - if CAPTURE_NMNE: - self.nmne_inbound_last_step: int = 0 - """NMNEs persist for the whole episode, but we want to count per step. Keeping track of last step count lets - us find the difference.""" - self.nmne_outbound_last_step: int = 0 - """NMNEs persist for the whole episode, but we want to count per step. Keeping track of last step count lets - us find the difference.""" - - if low_nmne_threshold or med_nmne_threshold or high_nmne_threshold: - self._validate_nmne_categories( - low_nmne_threshold=low_nmne_threshold, - med_nmne_threshold=med_nmne_threshold, - high_nmne_threshold=high_nmne_threshold, - ) - - def _validate_nmne_categories( - self, low_nmne_threshold: int = 0, med_nmne_threshold: int = 5, high_nmne_threshold: int = 10 - ): + :param where: Where in the simulation state dictionary to find the relevant information for this interface. + A typical location for a network interface might be + ['network', 'nodes', , 'NICs', ]. + :type where: WhereType + :param include_nmne: Flag to determine whether to include NMNE information in the observation. + :type include_nmne: bool """ - Validates the nmne threshold config. + self.where = where + self.include_nmne: bool = include_nmne - If the configuration is valid, the thresholds will be set, otherwise, an exception is raised. + self.default_observation: ObsType = {"nic_status": 0} + if self.include_nmne: + self.default_observation.update({"NMNE": {"inbound": 0, "outbound": 0}}) - :param: low_nmne_threshold: The minimum number of malicious network events to be considered low - :param: med_nmne_threshold: The minimum number of malicious network events to be considered medium - :param: high_nmne_threshold: The minimum number of malicious network events to be considered high + def observe(self, state: Dict) -> ObsType: """ - if high_nmne_threshold <= med_nmne_threshold: - raise Exception( - f"nmne_categories: high nmne count ({high_nmne_threshold}) must be greater " - f"than medium nmne count ({med_nmne_threshold})" - ) + Generate observation based on the current state of the simulation. - if med_nmne_threshold <= low_nmne_threshold: - raise Exception( - f"nmne_categories: medium nmne count ({med_nmne_threshold}) must be greater " - f"than low nmne count ({low_nmne_threshold})" - ) - - self.high_nmne_threshold = high_nmne_threshold - self.med_nmne_threshold = med_nmne_threshold - self.low_nmne_threshold = low_nmne_threshold - - def _categorise_mne_count(self, nmne_count: int) -> int: - """ - Categorise the number of Malicious Network Events (NMNEs) into discrete bins. - - This helps in classifying the severity or volume of MNEs into manageable levels for the agent. - - Bins are defined as follows: - - 0: No MNEs detected (0 events). - - 1: Low number of MNEs (default 1-5 events). - - 2: Moderate number of MNEs (default 6-10 events). - - 3: High number of MNEs (default more than 10 events). - - :param nmne_count: Number of MNEs detected. - :return: Bin number corresponding to the number of MNEs. Returns 0, 1, 2, or 3 based on the detected MNE count. - """ - if nmne_count > self.high_nmne_threshold: - return 3 - elif nmne_count > self.med_nmne_threshold: - return 2 - elif nmne_count > self.low_nmne_threshold: - return 1 - return 0 - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary + :param state: Simulation state dictionary. :type state: Dict - :return: Observation - :rtype: Dict + :return: Observation containing the status of the network interface and optionally NMNE information. + :rtype: ObsType """ - if self.where is None: - return self.default_observation nic_state = access_from_nested_dict(state, self.where) if nic_state is NOT_PRESENT_IN_STATE: return self.default_observation - else: - obs_dict = {"nic_status": 1 if nic_state["enabled"] else 2} - if CAPTURE_NMNE: - obs_dict.update({"NMNE": {}}) - direction_dict = nic_state["nmne"].get("direction", {}) - inbound_keywords = direction_dict.get("inbound", {}).get("keywords", {}) - inbound_count = inbound_keywords.get("*", 0) - outbound_keywords = direction_dict.get("outbound", {}).get("keywords", {}) - outbound_count = outbound_keywords.get("*", 0) - obs_dict["NMNE"]["inbound"] = self._categorise_mne_count(inbound_count - self.nmne_inbound_last_step) - obs_dict["NMNE"]["outbound"] = self._categorise_mne_count(outbound_count - self.nmne_outbound_last_step) - self.nmne_inbound_last_step = inbound_count - self.nmne_outbound_last_step = outbound_count - return obs_dict + + obs = {"nic_status": 1 if nic_state["enabled"] else 2} + if self.include_nmne: + obs.update({"NMNE": {}}) + direction_dict = nic_state["nmne"].get("direction", {}) + inbound_keywords = direction_dict.get("inbound", {}).get("keywords", {}) + inbound_count = inbound_keywords.get("*", 0) + outbound_keywords = direction_dict.get("outbound", {}).get("keywords", {}) + outbound_count = outbound_keywords.get("*", 0) + obs["NMNE"]["inbound"] = self._categorise_mne_count(inbound_count - self.nmne_inbound_last_step) + obs["NMNE"]["outbound"] = self._categorise_mne_count(outbound_count - self.nmne_outbound_last_step) + self.nmne_inbound_last_step = inbound_count + self.nmne_outbound_last_step = outbound_count + return obs @property def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for network interface status and NMNE information. + :rtype: spaces.Space + """ space = spaces.Dict({"nic_status": spaces.Discrete(3)}) - if CAPTURE_NMNE: + if self.include_nmne: space["NMNE"] = spaces.Dict({"inbound": spaces.Discrete(4), "outbound": spaces.Discrete(4)}) return space @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]]) -> "NicObservation": - """Create NIC observation from a config. - - :param config: Dictionary containing the configuration for this NIC observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :param parent_where: Where in the simulation state dictionary to find the information about this NIC's parent - node. A typical location for a node ``where`` can be: ['network','nodes',] - :type parent_where: Optional[List[str]] - :return: Constructed NIC observation - :rtype: NicObservation + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> NICObservation: """ - low_nmne_threshold = None - med_nmne_threshold = None - high_nmne_threshold = None + Create a network interface observation from a configuration schema. - if game and game.options and game.options.thresholds and game.options.thresholds.get("nmne"): - threshold = game.options.thresholds["nmne"] + :param config: Configuration schema containing the necessary information for the network interface observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this NIC's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed network interface observation instance. + :rtype: NICObservation + """ + return cls(where=parent_where + ["NICs", config.nic_num], include_nmne=config.include_nmne) - low_nmne_threshold = int(threshold.get("low")) if threshold.get("low") is not None else None - med_nmne_threshold = int(threshold.get("medium")) if threshold.get("medium") is not None else None - high_nmne_threshold = int(threshold.get("high")) if threshold.get("high") is not None else None - return cls( - where=parent_where + ["NICs", config["nic_num"]], - low_nmne_threshold=low_nmne_threshold, - med_nmne_threshold=med_nmne_threshold, - high_nmne_threshold=high_nmne_threshold, - ) +class PortObservation(AbstractObservation, identifier="PORT"): + """Port observation, provides status information about a network port within the simulation environment.""" + + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for PortObservation.""" + + port_id: int + """Identifier of the port, used for querying simulation state dictionary.""" + + def __init__(self, where: WhereType) -> None: + """ + Initialize a port observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this port. + A typical location for a port might be ['network', 'nodes', , 'NICs', ]. + :type where: WhereType + """ + self.where = where + self.default_observation: ObsType = {"operating_status": 0} + + def observe(self, state: Dict) -> ObsType: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the operating status of the port. + :rtype: ObsType + """ + port_state = access_from_nested_dict(state, self.where) + if port_state is NOT_PRESENT_IN_STATE: + return self.default_observation + return {"operating_status": 1 if port_state["enabled"] else 2} + + @property + def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for port status. + :rtype: spaces.Space + """ + return spaces.Dict({"operating_status": spaces.Discrete(3)}) + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> PortObservation: + """ + Create a port observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the port observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this port's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed port observation instance. + :rtype: PortObservation + """ + return cls(where=parent_where + ["NICs", config.port_id]) diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index c702f8e2..0e63f440 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -1,1199 +1,18 @@ from __future__ import annotations -from ipaddress import IPv4Address -from typing import Any, Dict, Iterable, List, Optional +from typing import Dict, List from gymnasium import spaces from gymnasium.core import ObsType from primaite import getLogger -from primaite.game.agent.observations.observations import AbstractObservation -from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +from primaite.game.agent.observations.firewall_observation import FirewallObservation +from primaite.game.agent.observations.host_observations import HostObservation +from primaite.game.agent.observations.observations import AbstractObservation, WhereType +from primaite.game.agent.observations.router_observation import RouterObservation _LOGGER = getLogger(__name__) -WhereType = Iterable[str | int] | None - - -class ServiceObservation(AbstractObservation, identifier="SERVICE"): - """Service observation, shows status of a service in the simulation environment.""" - - class ConfigSchema(AbstractObservation.ConfigSchema): - """Configuration schema for ServiceObservation.""" - - service_name: str - """Name of the service, used for querying simulation state dictionary""" - - def __init__(self, where: WhereType) -> None: - """ - Initialize a service observation instance. - - :param where: Where in the simulation state dictionary to find the relevant information for this service. - A typical location for a service might be ['network', 'nodes', , 'services', ]. - :type where: WhereType - """ - self.where = where - self.default_observation = {"operating_status": 0, "health_status": 0} - - def observe(self, state: Dict) -> ObsType: - """ - Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary. - :type state: Dict - :return: Observation containing the operating status and health status of the service. - :rtype: Any - """ - service_state = access_from_nested_dict(state, self.where) - if service_state is NOT_PRESENT_IN_STATE: - return self.default_observation - return { - "operating_status": service_state["operating_state"], - "health_status": service_state["health_state_visible"], - } - - @property - def space(self) -> spaces.Space: - """ - Gymnasium space object describing the observation space shape. - - :return: Gymnasium space representing the observation space for service status. - :rtype: spaces.Space - """ - return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(5)}) - - @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ServiceObservation: - """ - Create a service observation from a configuration schema. - - :param config: Configuration schema containing the necessary information for the service observation. - :type config: ConfigSchema - :param parent_where: Where in the simulation state dictionary to find the information about this service's - parent node. A typical location for a node might be ['network', 'nodes', ]. - :type parent_where: WhereType, optional - :return: Constructed service observation instance. - :rtype: ServiceObservation - """ - return cls(where=parent_where + ["services", config.service_name]) - - -class ApplicationObservation(AbstractObservation, identifier="APPLICATION"): - """Application observation, shows the status of an application within the simulation environment.""" - - class ConfigSchema(AbstractObservation.ConfigSchema): - """Configuration schema for ApplicationObservation.""" - - application_name: str - """Name of the application, used for querying simulation state dictionary""" - - def __init__(self, where: WhereType) -> None: - """ - Initialise an application observation instance. - - :param where: Where in the simulation state dictionary to find the relevant information for this application. - A typical location for an application might be - ['network', 'nodes', , 'applications', ]. - :type where: WhereType - """ - self.where = where - self.default_observation = {"operating_status": 0, "health_status": 0, "num_executions": 0} - - def observe(self, state: Dict) -> Any: - """ - Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary. - :type state: Dict - :return: Obs containing the operating status, health status, and number of executions of the application. - :rtype: Any - """ - application_state = access_from_nested_dict(state, self.where) - if application_state is NOT_PRESENT_IN_STATE: - return self.default_observation - return { - "operating_status": application_state["operating_state"], - "health_status": application_state["health_state_visible"], - "num_executions": application_state["num_executions"], - } - - @property - def space(self) -> spaces.Space: - """ - Gymnasium space object describing the observation space shape. - - :return: Gymnasium space representing the observation space for application status. - :rtype: spaces.Space - """ - return spaces.Dict( - { - "operating_status": spaces.Discrete(7), - "health_status": spaces.Discrete(5), - "num_executions": spaces.Discrete(4), - } - ) - - @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ApplicationObservation: - """ - Create an application observation from a configuration schema. - - :param config: Configuration schema containing the necessary information for the application observation. - :type config: ConfigSchema - :param parent_where: Where in the simulation state dictionary to find the information about this application's - parent node. A typical location for a node might be ['network', 'nodes', ]. - :type parent_where: WhereType, optional - :return: Constructed application observation instance. - :rtype: ApplicationObservation - """ - return cls(where=parent_where + ["applications", config.application_name]) - - -class FileObservation(AbstractObservation, identifier="FILE"): - """File observation, provides status information about a file within the simulation environment.""" - - class ConfigSchema(AbstractObservation.ConfigSchema): - """Configuration schema for FileObservation.""" - - file_name: str - """Name of the file, used for querying simulation state dictionary.""" - include_num_access: Optional[bool] = None - """Whether to include the number of accesses to the file in the observation.""" - - def __init__(self, where: WhereType, include_num_access: bool) -> None: - """ - Initialize a file observation instance. - - :param where: Where in the simulation state dictionary to find the relevant information for this file. - A typical location for a file might be - ['network', 'nodes', , 'file_system', 'folder', , 'files', ]. - :type where: WhereType - :param include_num_access: Whether to include the number of accesses to the file in the observation. - :type include_num_access: bool - """ - self.where: WhereType = where - self.include_num_access: bool = include_num_access - - self.default_observation: ObsType = {"health_status": 0} - if self.include_num_access: - self.default_observation["num_access"] = 0 - - def observe(self, state: Dict) -> Any: - """ - Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary. - :type state: Dict - :return: Observation containing the health status of the file and optionally the number of accesses. - :rtype: Any - """ - file_state = access_from_nested_dict(state, self.where) - if file_state is NOT_PRESENT_IN_STATE: - return self.default_observation - obs = {"health_status": file_state["visible_status"]} - if self.include_num_access: - obs["num_access"] = file_state["num_access"] - # raise NotImplementedError("TODO: need to fix num_access to use thresholds instead of raw value.") - return obs - - @property - def space(self) -> spaces.Space: - """ - Gymnasium space object describing the observation space shape. - - :return: Gymnasium space representing the observation space for file status. - :rtype: spaces.Space - """ - space = {"health_status": spaces.Discrete(6)} - if self.include_num_access: - space["num_access"] = spaces.Discrete(4) - return spaces.Dict(space) - - @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FileObservation: - """ - Create a file observation from a configuration schema. - - :param config: Configuration schema containing the necessary information for the file observation. - :type config: ConfigSchema - :param parent_where: Where in the simulation state dictionary to find the information about this file's - parent node. A typical location for a node might be ['network', 'nodes', ]. - :type parent_where: WhereType, optional - :return: Constructed file observation instance. - :rtype: FileObservation - """ - return cls(where=parent_where + ["files", config.file_name], include_num_access=config.include_num_access) - - -class FolderObservation(AbstractObservation, identifier="FOLDER"): - """Folder observation, provides status information about a folder within the simulation environment.""" - - class ConfigSchema(AbstractObservation.ConfigSchema): - """Configuration schema for FolderObservation.""" - - folder_name: str - """Name of the folder, used for querying simulation state dictionary.""" - files: List[FileObservation.ConfigSchema] = [] - """List of file configurations within the folder.""" - num_files: Optional[int] = None - """Number of spaces for file observations in this folder.""" - include_num_access: Optional[bool] = None - """Whether files in this folder should include the number of accesses in their observation.""" - - def __init__( - self, where: WhereType, files: Iterable[FileObservation], num_files: int, include_num_access: bool - ) -> None: - """ - Initialize a folder observation instance. - - :param where: Where in the simulation state dictionary to find the relevant information for this folder. - A typical location for a folder might be ['network', 'nodes', , 'folders', ]. - :type where: WhereType - :param files: List of file observation instances within the folder. - :type files: Iterable[FileObservation] - :param num_files: Number of files expected in the folder. - :type num_files: int - :param include_num_access: Whether to include the number of accesses to files in the observation. - :type include_num_access: bool - """ - self.where: WhereType = where - - self.files: List[FileObservation] = files - while len(self.files) < num_files: - self.files.append(FileObservation(where=None, include_num_access=include_num_access)) - while len(self.files) > num_files: - truncated_file = self.files.pop() - msg = f"Too many files in folder observation. Truncating file {truncated_file}" - _LOGGER.warning(msg) - - self.default_observation = { - "health_status": 0, - "FILES": {i + 1: f.default_observation for i, f in enumerate(self.files)}, - } - - def observe(self, state: Dict) -> Any: - """ - Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary. - :type state: Dict - :return: Observation containing the health status of the folder and status of files within the folder. - :rtype: Any - """ - folder_state = access_from_nested_dict(state, self.where) - if folder_state is NOT_PRESENT_IN_STATE: - return self.default_observation - - health_status = folder_state["health_status"] - - obs = {} - - obs["health_status"] = health_status - obs["FILES"] = {i + 1: file.observe(state) for i, file in enumerate(self.files)} - - return obs - - @property - def space(self) -> spaces.Space: - """ - Gymnasium space object describing the observation space shape. - - :return: Gymnasium space representing the observation space for folder status. - :rtype: spaces.Space - """ - return spaces.Dict( - { - "health_status": spaces.Discrete(6), - "FILES": spaces.Dict({i + 1: f.space for i, f in enumerate(self.files)}), - } - ) - - @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FolderObservation: - """ - Create a folder observation from a configuration schema. - - :param config: Configuration schema containing the necessary information for the folder observation. - :type config: ConfigSchema - :param parent_where: Where in the simulation state dictionary to find the information about this folder's - parent node. A typical location for a node might be ['network', 'nodes', ]. - :type parent_where: WhereType, optional - :return: Constructed folder observation instance. - :rtype: FolderObservation - """ - where = parent_where + ["folders", config.folder_name] - - # pass down shared/common config items - for file_config in config.files: - file_config.include_num_access = config.include_num_access - - files = [FileObservation.from_config(config=f, parent_where=where) for f in config.files] - return cls(where=where, files=files, num_files=config.num_files, include_num_access=config.include_num_access) - - -class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): - """Status information about a network interface within the simulation environment.""" - - class ConfigSchema(AbstractObservation.ConfigSchema): - """Configuration schema for NICObservation.""" - - nic_num: int - """Number of the network interface.""" - include_nmne: Optional[bool] = None - """Whether to include number of malicious network events (NMNE) in the observation.""" - - def __init__(self, where: WhereType, include_nmne: bool) -> None: - """ - Initialize a network interface observation instance. - - :param where: Where in the simulation state dictionary to find the relevant information for this interface. - A typical location for a network interface might be - ['network', 'nodes', , 'NICs', ]. - :type where: WhereType - :param include_nmne: Flag to determine whether to include NMNE information in the observation. - :type include_nmne: bool - """ - self.where = where - self.include_nmne: bool = include_nmne - - self.default_observation: ObsType = {"nic_status": 0} - if self.include_nmne: - self.default_observation.update({"NMNE": {"inbound": 0, "outbound": 0}}) - - def observe(self, state: Dict) -> Any: - """ - Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary. - :type state: Dict - :return: Observation containing the status of the network interface and optionally NMNE information. - :rtype: Any - """ - nic_state = access_from_nested_dict(state, self.where) - - if nic_state is NOT_PRESENT_IN_STATE: - return self.default_observation - - obs = {"nic_status": 1 if nic_state["enabled"] else 2} - if self.include_nmne: - obs.update({"NMNE": {}}) - direction_dict = nic_state["nmne"].get("direction", {}) - inbound_keywords = direction_dict.get("inbound", {}).get("keywords", {}) - inbound_count = inbound_keywords.get("*", 0) - outbound_keywords = direction_dict.get("outbound", {}).get("keywords", {}) - outbound_count = outbound_keywords.get("*", 0) - obs["NMNE"]["inbound"] = self._categorise_mne_count(inbound_count - self.nmne_inbound_last_step) - obs["NMNE"]["outbound"] = self._categorise_mne_count(outbound_count - self.nmne_outbound_last_step) - self.nmne_inbound_last_step = inbound_count - self.nmne_outbound_last_step = outbound_count - return obs - - @property - def space(self) -> spaces.Space: - """ - Gymnasium space object describing the observation space shape. - - :return: Gymnasium space representing the observation space for network interface status and NMNE information. - :rtype: spaces.Space - """ - space = spaces.Dict({"nic_status": spaces.Discrete(3)}) - - if self.include_nmne: - space["NMNE"] = spaces.Dict({"inbound": spaces.Discrete(4), "outbound": spaces.Discrete(4)}) - - return space - - @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> NICObservation: - """ - Create a network interface observation from a configuration schema. - - :param config: Configuration schema containing the necessary information for the network interface observation. - :type config: ConfigSchema - :param parent_where: Where in the simulation state dictionary to find the information about this NIC's - parent node. A typical location for a node might be ['network', 'nodes', ]. - :type parent_where: WhereType, optional - :return: Constructed network interface observation instance. - :rtype: NICObservation - """ - return cls(where=parent_where + ["NICs", config.nic_num], include_nmne=config.include_nmne) - - -class HostObservation(AbstractObservation, identifier="HOST"): - """Host observation, provides status information about a host within the simulation environment.""" - - class ConfigSchema(AbstractObservation.ConfigSchema): - """Configuration schema for HostObservation.""" - - hostname: str - """Hostname of the host, used for querying simulation state dictionary.""" - services: List[ServiceObservation.ConfigSchema] = [] - """List of services to observe on the host.""" - applications: List[ApplicationObservation.ConfigSchema] = [] - """List of applications to observe on the host.""" - folders: List[FolderObservation.ConfigSchema] = [] - """List of folders to observe on the host.""" - network_interfaces: List[NICObservation.ConfigSchema] = [] - """List of network interfaces to observe on the host.""" - num_services: Optional[int] = None - """Number of spaces for service observations on this host.""" - num_applications: Optional[int] = None - """Number of spaces for application observations on this host.""" - num_folders: Optional[int] = None - """Number of spaces for folder observations on this host.""" - num_files: Optional[int] = None - """Number of spaces for file observations on this host.""" - num_nics: Optional[int] = None - """Number of spaces for network interface observations on this host.""" - include_nmne: Optional[bool] = None - """Whether network interface observations should include number of malicious network events.""" - include_num_access: Optional[bool] = None - """Whether to include the number of accesses to files observations on this host.""" - - def __init__( - self, - where: WhereType, - services: List[ServiceObservation], - applications: List[ApplicationObservation], - folders: List[FolderObservation], - network_interfaces: List[NICObservation], - num_services: int, - num_applications: int, - num_folders: int, - num_files: int, - num_nics: int, - include_nmne: bool, - include_num_access: bool, - ) -> None: - """ - Initialize a host observation instance. - - :param where: Where in the simulation state dictionary to find the relevant information for this host. - A typical location for a host might be ['network', 'nodes', ]. - :type where: WhereType - :param services: List of service observations on the host. - :type services: List[ServiceObservation] - :param applications: List of application observations on the host. - :type applications: List[ApplicationObservation] - :param folders: List of folder observations on the host. - :type folders: List[FolderObservation] - :param network_interfaces: List of network interface observations on the host. - :type network_interfaces: List[NICObservation] - :param num_services: Number of services to observe. - :type num_services: int - :param num_applications: Number of applications to observe. - :type num_applications: int - :param num_folders: Number of folders to observe. - :type num_folders: int - :param num_files: Number of files. - :type num_files: int - :param num_nics: Number of network interfaces. - :type num_nics: int - :param include_nmne: Flag to include network metrics and errors. - :type include_nmne: bool - :param include_num_access: Flag to include the number of accesses to files. - :type include_num_access: bool - """ - self.where: WhereType = where - - # Ensure lists have lengths equal to specified counts by truncating or padding - self.services: List[ServiceObservation] = services - while len(self.services) < num_services: - self.services.append(ServiceObservation(where=None)) - while len(self.services) > num_services: - truncated_service = self.services.pop() - msg = f"Too many services in Node observation space for node. Truncating service {truncated_service.where}" - _LOGGER.warning(msg) - - self.applications: List[ApplicationObservation] = applications - while len(self.applications) < num_applications: - self.applications.append(ApplicationObservation(where=None)) - while len(self.applications) > num_applications: - truncated_application = self.applications.pop() - msg = f"Too many applications in Node observation space for node. Truncating {truncated_application.where}" - _LOGGER.warning(msg) - - self.folders: List[FolderObservation] = folders - while len(self.folders) < num_folders: - self.folders.append( - FolderObservation(where=None, files=[], num_files=num_files, include_num_access=include_num_access) - ) - while len(self.folders) > num_folders: - truncated_folder = self.folders.pop() - msg = f"Too many folders in Node observation space for node. Truncating folder {truncated_folder.where}" - _LOGGER.warning(msg) - - self.network_interfaces: List[NICObservation] = network_interfaces - while len(self.network_interfaces) < num_nics: - self.network_interfaces.append(NICObservation(where=None, include_nmne=include_nmne)) - while len(self.network_interfaces) > num_nics: - truncated_nic = self.network_interfaces.pop() - msg = f"Too many network_interfaces in Node observation space for node. Truncating {truncated_nic.where}" - _LOGGER.warning(msg) - - self.default_observation: ObsType = { - "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, - "APPLICATIONS": {i + 1: a.default_observation for i, a in enumerate(self.applications)}, - "FOLDERS": {i + 1: f.default_observation for i, f in enumerate(self.folders)}, - "NICS": {i + 1: n.default_observation for i, n in enumerate(self.network_interfaces)}, - "operating_status": 0, - "num_file_creations": 0, - "num_file_deletions": 0, - } - - def observe(self, state: Dict) -> Any: - """ - Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary. - :type state: Dict - :return: Observation containing the status information about the host. - :rtype: Any - """ - node_state = access_from_nested_dict(state, self.where) - if node_state is NOT_PRESENT_IN_STATE: - return self.default_observation - - obs = {} - obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} - obs["APPLICATIONS"] = {i + 1: app.observe(state) for i, app in enumerate(self.applications)} - obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} - obs["operating_status"] = node_state["operating_state"] - obs["NICS"] = { - i + 1: network_interface.observe(state) for i, network_interface in enumerate(self.network_interfaces) - } - obs["num_file_creations"] = node_state["file_system"]["num_file_creations"] - obs["num_file_deletions"] = node_state["file_system"]["num_file_deletions"] - return obs - - @property - def space(self) -> spaces.Space: - """ - Gymnasium space object describing the observation space shape. - - :return: Gymnasium space representing the observation space for host status. - :rtype: spaces.Space - """ - shape = { - "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), - "APPLICATIONS": spaces.Dict({i + 1: app.space for i, app in enumerate(self.applications)}), - "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), - "operating_status": spaces.Discrete(5), - "NICS": spaces.Dict( - {i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)} - ), - "num_file_creations": spaces.Discrete(4), - "num_file_deletions": spaces.Discrete(4), - } - return spaces.Dict(shape) - - @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = None) -> HostObservation: - """ - Create a host observation from a configuration schema. - - :param config: Configuration schema containing the necessary information for the host observation. - :type config: ConfigSchema - :param parent_where: Where in the simulation state dictionary to find the information about this host. - A typical location might be ['network', 'nodes', ]. - :type parent_where: WhereType, optional - :return: Constructed host observation instance. - :rtype: HostObservation - """ - if parent_where is None: - where = ["network", "nodes", config.hostname] - else: - where = parent_where + ["nodes", config.hostname] - - # Pass down shared/common config items - for folder_config in config.folders: - folder_config.include_num_access = config.include_num_access - folder_config.num_files = config.num_files - for nic_config in config.network_interfaces: - nic_config.include_nmne = config.include_nmne - - services = [ServiceObservation.from_config(config=c, parent_where=where) for c in config.services] - applications = [ApplicationObservation.from_config(config=c, parent_where=where) for c in config.applications] - folders = [FolderObservation.from_config(config=c, parent_where=where) for c in config.folders] - nics = [NICObservation.from_config(config=c, parent_where=where) for c in config.network_interfaces] - - return cls( - where=where, - services=services, - applications=applications, - folders=folders, - network_interfaces=nics, - num_services=config.num_services, - num_applications=config.num_applications, - num_folders=config.num_folders, - num_files=config.num_files, - num_nics=config.num_nics, - include_nmne=config.include_nmne, - include_num_access=config.include_num_access, - ) - - -class PortObservation(AbstractObservation, identifier="PORT"): - """Port observation, provides status information about a network port within the simulation environment.""" - - class ConfigSchema(AbstractObservation.ConfigSchema): - """Configuration schema for PortObservation.""" - - port_id: int - """Identifier of the port, used for querying simulation state dictionary.""" - - def __init__(self, where: WhereType) -> None: - """ - Initialize a port observation instance. - - :param where: Where in the simulation state dictionary to find the relevant information for this port. - A typical location for a port might be ['network', 'nodes', , 'NICs', ]. - :type where: WhereType - """ - self.where = where - self.default_observation: ObsType = {"operating_status": 0} - - def observe(self, state: Dict) -> Any: - """ - Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary. - :type state: Dict - :return: Observation containing the operating status of the port. - :rtype: Any - """ - port_state = access_from_nested_dict(state, self.where) - if port_state is NOT_PRESENT_IN_STATE: - return self.default_observation - return {"operating_status": 1 if port_state["enabled"] else 2} - - @property - def space(self) -> spaces.Space: - """ - Gymnasium space object describing the observation space shape. - - :return: Gymnasium space representing the observation space for port status. - :rtype: spaces.Space - """ - return spaces.Dict({"operating_status": spaces.Discrete(3)}) - - @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> PortObservation: - """ - Create a port observation from a configuration schema. - - :param config: Configuration schema containing the necessary information for the port observation. - :type config: ConfigSchema - :param parent_where: Where in the simulation state dictionary to find the information about this port's - parent node. A typical location for a node might be ['network', 'nodes', ]. - :type parent_where: WhereType, optional - :return: Constructed port observation instance. - :rtype: PortObservation - """ - return cls(where=parent_where + ["NICs", config.port_id]) - - -class ACLObservation(AbstractObservation, identifier="ACL"): - """ACL observation, provides information about access control lists within the simulation environment.""" - - class ConfigSchema(AbstractObservation.ConfigSchema): - """Configuration schema for ACLObservation.""" - - ip_list: Optional[List[IPv4Address]] = None - """List of IP addresses.""" - wildcard_list: Optional[List[str]] = None - """List of wildcard strings.""" - port_list: Optional[List[int]] = None - """List of port numbers.""" - protocol_list: Optional[List[str]] = None - """List of protocol names.""" - num_rules: Optional[int] = None - """Number of ACL rules.""" - - def __init__( - self, - where: WhereType, - num_rules: int, - ip_list: List[IPv4Address], - wildcard_list: List[str], - port_list: List[int], - protocol_list: List[str], - ) -> None: - """ - Initialize an ACL observation instance. - - :param where: Where in the simulation state dictionary to find the relevant information for this ACL. - :type where: WhereType - :param num_rules: Number of ACL rules. - :type num_rules: int - :param ip_list: List of IP addresses. - :type ip_list: List[IPv4Address] - :param wildcard_list: List of wildcard strings. - :type wildcard_list: List[str] - :param port_list: List of port numbers. - :type port_list: List[int] - :param protocol_list: List of protocol names. - :type protocol_list: List[str] - """ - self.where = where - self.num_rules: int = num_rules - self.ip_to_id: Dict[str, int] = {i + 2: p for i, p in enumerate(ip_list)} - self.wildcard_to_id: Dict[str, int] = {i + 2: p for i, p in enumerate(wildcard_list)} - self.port_to_id: Dict[int, int] = {i + 2: p for i, p in enumerate(port_list)} - self.protocol_to_id: Dict[str, int] = {i + 2: p for i, p in enumerate(protocol_list)} - self.default_observation: Dict = { - i - + 1: { - "position": i, - "permission": 0, - "source_ip_id": 0, - "source_wildcard_id": 0, - "source_port_id": 0, - "dest_ip_id": 0, - "dest_wildcard_id": 0, - "dest_port_id": 0, - "protocol_id": 0, - } - for i in range(self.num_rules) - } - - def observe(self, state: Dict) -> Any: - """ - Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary. - :type state: Dict - :return: Observation containing ACL rules. - :rtype: Any - """ - acl_state: Dict = access_from_nested_dict(state, self.where) - if acl_state is NOT_PRESENT_IN_STATE: - return self.default_observation - obs = {} - acl_items = dict(acl_state.items()) - i = 1 # don't show rule 0 for compatibility reasons. - while i < self.num_rules + 1: - rule_state = acl_items[i] - if rule_state is None: - obs[i] = { - "position": i - 1, - "permission": 0, - "source_ip_id": 0, - "source_wildcard_id": 0, - "source_port_id": 0, - "dest_ip_id": 0, - "dest_wildcard_id": 0, - "dest_port_id": 0, - "protocol_id": 0, - } - else: - src_ip = rule_state["src_ip_address"] - src_node_id = self.ip_to_id.get(src_ip, 1) - dst_ip = rule_state["dst_ip_address"] - dst_node_ip = self.ip_to_id.get(dst_ip, 1) - src_wildcard = rule_state["source_wildcard_id"] - src_wildcard_id = self.wildcard_to_id.get(src_wildcard, 1) - dst_wildcard = rule_state["dest_wildcard_id"] - dst_wildcard_id = self.wildcard_to_id.get(dst_wildcard, 1) - src_port = rule_state["source_port_id"] - src_port_id = self.port_to_id.get(src_port, 1) - dst_port = rule_state["dest_port_id"] - dst_port_id = self.port_to_id.get(dst_port, 1) - protocol = rule_state["protocol"] - protocol_id = self.protocol_to_id.get(protocol, 1) - obs[i] = { - "position": i - 1, - "permission": rule_state["action"], - "source_ip_id": src_node_id, - "source_wildcard_id": src_wildcard_id, - "source_port_id": src_port_id, - "dest_ip_id": dst_node_ip, - "dest_wildcard_id": dst_wildcard_id, - "dest_port_id": dst_port_id, - "protocol_id": protocol_id, - } - i += 1 - return obs - - @property - def space(self) -> spaces.Space: - """ - Gymnasium space object describing the observation space shape. - - :return: Gymnasium space representing the observation space for ACL rules. - :rtype: spaces.Space - """ - return spaces.Dict( - { - i - + 1: spaces.Dict( - { - "position": spaces.Discrete(self.num_rules), - "permission": spaces.Discrete(3), - # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) - "source_ip_id": spaces.Discrete(len(self.ip_to_id) + 2), - "source_wildcard_id": spaces.Discrete(len(self.wildcard_to_id) + 2), - "source_port_id": spaces.Discrete(len(self.port_to_id) + 2), - "dest_ip_id": spaces.Discrete(len(self.ip_to_id) + 2), - "dest_wildcard_id": spaces.Discrete(len(self.wildcard_to_id) + 2), - "dest_port_id": spaces.Discrete(len(self.port_to_id) + 2), - "protocol_id": spaces.Discrete(len(self.protocol_to_id) + 2), - } - ) - for i in range(self.num_rules) - } - ) - - @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ACLObservation: - """ - Create an ACL observation from a configuration schema. - - :param config: Configuration schema containing the necessary information for the ACL observation. - :type config: ConfigSchema - :param parent_where: Where in the simulation state dictionary to find the information about this ACL's - parent node. A typical location for a node might be ['network', 'nodes', ]. - :type parent_where: WhereType, optional - :return: Constructed ACL observation instance. - :rtype: ACLObservation - """ - return cls( - where=parent_where + ["acl", "acl"], - num_rules=config.num_rules, - ip_list=config.ip_list, - wildcard_list=config.wildcard_list, - port_list=config.port_list, - protocol_list=config.protocol_list, - ) - - -class RouterObservation(AbstractObservation, identifier="ROUTER"): - """Router observation, provides status information about a router within the simulation environment.""" - - class ConfigSchema(AbstractObservation.ConfigSchema): - """Configuration schema for RouterObservation.""" - - hostname: str - """Hostname of the router, used for querying simulation state dictionary.""" - ports: Optional[List[PortObservation.ConfigSchema]] = None - """Configuration of port observations for this router.""" - num_ports: Optional[int] = None - """Number of port observations configured for this router.""" - acl: Optional[ACLObservation.ConfigSchema] = None - """Configuration of ACL observation on this router.""" - ip_list: Optional[List[str]] = None - """List of IP addresses for encoding ACLs.""" - wildcard_list: Optional[List[str]] = None - """List of IP wildcards for encoding ACLs.""" - port_list: Optional[List[int]] = None - """List of ports for encoding ACLs.""" - protocol_list: Optional[List[str]] = None - """List of protocols for encoding ACLs.""" - num_rules: Optional[int] = None - """Number of rules ACL rules to show.""" - - def __init__( - self, - where: WhereType, - ports: List[PortObservation], - num_ports: int, - acl: ACLObservation, - ) -> None: - """ - Initialize a router observation instance. - - :param where: Where in the simulation state dictionary to find the relevant information for this router. - A typical location for a router might be ['network', 'nodes', ]. - :type where: WhereType - :param ports: List of port observations representing the ports of the router. - :type ports: List[PortObservation] - :param num_ports: Number of ports for the router. - :type num_ports: int - :param acl: ACL observation representing the access control list of the router. - :type acl: ACLObservation - """ - self.where: WhereType = where - self.ports: List[PortObservation] = ports - self.acl: ACLObservation = acl - self.num_ports: int = num_ports - - while len(self.ports) < num_ports: - self.ports.append(PortObservation(where=None)) - while len(self.ports) > num_ports: - self.ports.pop() - msg = "Too many ports in router observation. Truncating." - _LOGGER.warning(msg) - - self.default_observation = { - "PORTS": {i + 1: p.default_observation for i, p in enumerate(self.ports)}, - "ACL": self.acl.default_observation, - } - - def observe(self, state: Dict) -> Any: - """ - Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary. - :type state: Dict - :return: Observation containing the status of ports and ACL configuration of the router. - :rtype: Any - """ - router_state = access_from_nested_dict(state, self.where) - if router_state is NOT_PRESENT_IN_STATE: - return self.default_observation - - obs = {} - obs["PORTS"] = {i + 1: p.observe(state) for i, p in enumerate(self.ports)} - obs["ACL"] = self.acl.observe(state) - return obs - - @property - def space(self) -> spaces.Space: - """ - Gymnasium space object describing the observation space shape. - - :return: Gymnasium space representing the observation space for router status. - :rtype: spaces.Space - """ - return spaces.Dict( - {"PORTS": spaces.Dict({i + 1: p.space for i, p in enumerate(self.ports)}), "ACL": self.acl.space} - ) - - @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> RouterObservation: - """ - Create a router observation from a configuration schema. - - :param config: Configuration schema containing the necessary information for the router observation. - :type config: ConfigSchema - :param parent_where: Where in the simulation state dictionary to find the information about this router's - parent node. A typical location for a node might be ['network', 'nodes', ]. - :type parent_where: WhereType, optional - :return: Constructed router observation instance. - :rtype: RouterObservation - """ - where = parent_where + ["nodes", config.hostname] - - if config.acl is None: - config.acl = ACLObservation.ConfigSchema() - if config.acl.num_rules is None: - config.acl.num_rules = config.num_rules - if config.acl.ip_list is None: - config.acl.ip_list = config.ip_list - if config.acl.wildcard_list is None: - config.acl.wildcard_list = config.wildcard_list - if config.acl.port_list is None: - config.acl.port_list = config.port_list - if config.acl.protocol_list is None: - config.acl.protocol_list = config.protocol_list - - if config.ports is None: - config.ports = [PortObservation.ConfigSchema(port_id=i + 1) for i in range(config.num_ports)] - - ports = [PortObservation.from_config(config=c, parent_where=where) for c in config.ports] - acl = ACLObservation.from_config(config=config.acl, parent_where=where) - return cls(where=where, ports=ports, num_ports=config.num_ports, acl=acl) - - -class FirewallObservation(AbstractObservation, identifier="FIREWALL"): - """Firewall observation, provides status information about a firewall within the simulation environment.""" - - class ConfigSchema(AbstractObservation.ConfigSchema): - """Configuration schema for FirewallObservation.""" - - hostname: str - """Hostname of the firewall node, used for querying simulation state dictionary.""" - ip_list: Optional[List[str]] = None - """List of IP addresses for encoding ACLs.""" - wildcard_list: Optional[List[str]] = None - """List of IP wildcards for encoding ACLs.""" - port_list: Optional[List[int]] = None - """List of ports for encoding ACLs.""" - protocol_list: Optional[List[str]] = None - """List of protocols for encoding ACLs.""" - num_rules: Optional[int] = None - """Number of rules ACL rules to show.""" - - def __init__( - self, - where: WhereType, - ip_list: List[str], - wildcard_list: List[str], - port_list: List[int], - protocol_list: List[str], - num_rules: int, - ) -> None: - """ - Initialize a firewall observation instance. - - :param where: Where in the simulation state dictionary to find the relevant information for this firewall. - A typical location for a firewall might be ['network', 'nodes', ]. - :type where: WhereType - :param ip_list: List of IP addresses. - :type ip_list: List[str] - :param wildcard_list: List of wildcard rules. - :type wildcard_list: List[str] - :param port_list: List of port numbers. - :type port_list: List[int] - :param protocol_list: List of protocol types. - :type protocol_list: List[str] - :param num_rules: Number of rules configured in the firewall. - :type num_rules: int - """ - self.where: WhereType = where - - self.ports: List[PortObservation] = [ - PortObservation(where=self.where + ["port", port_num]) for port_num in (1, 2, 3) - ] - # TODO: check what the port nums are for firewall. - - self.internal_inbound_acl = ACLObservation( - where=self.where + ["acl", "internal", "inbound"], - num_rules=num_rules, - ip_list=ip_list, - wildcard_list=wildcard_list, - port_list=port_list, - protocol_list=protocol_list, - ) - self.internal_outbound_acl = ACLObservation( - where=self.where + ["acl", "internal", "outbound"], - num_rules=num_rules, - ip_list=ip_list, - wildcard_list=wildcard_list, - port_list=port_list, - protocol_list=protocol_list, - ) - self.dmz_inbound_acl = ACLObservation( - where=self.where + ["acl", "dmz", "inbound"], - num_rules=num_rules, - ip_list=ip_list, - wildcard_list=wildcard_list, - port_list=port_list, - protocol_list=protocol_list, - ) - self.dmz_outbound_acl = ACLObservation( - where=self.where + ["acl", "dmz", "outbound"], - num_rules=num_rules, - ip_list=ip_list, - wildcard_list=wildcard_list, - port_list=port_list, - protocol_list=protocol_list, - ) - self.external_inbound_acl = ACLObservation( - where=self.where + ["acl", "external", "inbound"], - num_rules=num_rules, - ip_list=ip_list, - wildcard_list=wildcard_list, - port_list=port_list, - protocol_list=protocol_list, - ) - self.external_outbound_acl = ACLObservation( - where=self.where + ["acl", "external", "outbound"], - num_rules=num_rules, - ip_list=ip_list, - wildcard_list=wildcard_list, - port_list=port_list, - protocol_list=protocol_list, - ) - - self.default_observation = { - "PORTS": {i + 1: p.default_observation for i, p in enumerate(self.ports)}, - "INTERNAL": { - "INBOUND": self.internal_inbound_acl.default_observation, - "OUTBOUND": self.internal_outbound_acl.default_observation, - }, - "DMZ": { - "INBOUND": self.dmz_inbound_acl.default_observation, - "OUTBOUND": self.dmz_outbound_acl.default_observation, - }, - "EXTERNAL": { - "INBOUND": self.external_inbound_acl.default_observation, - "OUTBOUND": self.external_outbound_acl.default_observation, - }, - } - - def observe(self, state: Dict) -> Any: - """ - Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary. - :type state: Dict - :return: Observation containing the status of ports and ACLs for internal, DMZ, and external traffic. - :rtype: Any - """ - obs = { - "PORTS": {i + 1: p.observe(state) for i, p in enumerate(self.ports)}, - "INTERNAL": { - "INBOUND": self.internal_inbound_acl.observe(state), - "OUTBOUND": self.internal_outbound_acl.observe(state), - }, - "DMZ": { - "INBOUND": self.dmz_inbound_acl.observe(state), - "OUTBOUND": self.dmz_outbound_acl.observe(state), - }, - "EXTERNAL": { - "INBOUND": self.external_inbound_acl.observe(state), - "OUTBOUND": self.external_outbound_acl.observe(state), - }, - } - return obs - - @property - def space(self) -> spaces.Space: - """ - Gymnasium space object describing the observation space shape. - - :return: Gymnasium space representing the observation space for firewall status. - :rtype: spaces.Space - """ - space = spaces.Dict( - { - "PORTS": spaces.Dict({i + 1: p.space for i, p in enumerate(self.ports)}), - "INTERNAL": spaces.Dict( - { - "INBOUND": self.internal_inbound_acl.space, - "OUTBOUND": self.internal_outbound_acl.space, - } - ), - "DMZ": spaces.Dict( - { - "INBOUND": self.dmz_inbound_acl.space, - "OUTBOUND": self.dmz_outbound_acl.space, - } - ), - "EXTERNAL": spaces.Dict( - { - "INBOUND": self.external_inbound_acl.space, - "OUTBOUND": self.external_outbound_acl.space, - } - ), - } - ) - return space - - @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FirewallObservation: - """ - Create a firewall observation from a configuration schema. - - :param config: Configuration schema containing the necessary information for the firewall observation. - :type config: ConfigSchema - :param parent_where: Where in the simulation state dictionary to find the information about this firewall's - parent node. A typical location for a node might be ['network', 'nodes', ]. - :type parent_where: WhereType, optional - :return: Constructed firewall observation instance. - :rtype: FirewallObservation - """ - where = parent_where + ["nodes", config.hostname] - return cls( - where=where, - ip_list=config.ip_list, - wildcard_list=config.wildcard_list, - port_list=config.port_list, - protocol_list=config.protocol_list, - num_rules=config.num_rules, - ) - class NodesObservation(AbstractObservation, identifier="NODES"): """Nodes observation, provides status information about nodes within the simulation environment.""" @@ -1266,14 +85,14 @@ class NodesObservation(AbstractObservation, identifier="NODES"): **{f"FIREWALL{i}": firewall.default_observation for i, firewall in enumerate(self.firewalls)}, } - def observe(self, state: Dict) -> Any: + def observe(self, state: Dict) -> ObsType: """ Generate observation based on the current state of the simulation. :param state: Simulation state dictionary. :type state: Dict :return: Observation containing status information about nodes. - :rtype: Any + :rtype: ObsType """ obs = { **{f"HOST{i}": host.observe(state) for i, host in enumerate(self.hosts)}, @@ -1300,7 +119,7 @@ class NodesObservation(AbstractObservation, identifier="NODES"): return space @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ServiceObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> NodesObservation: """ Create a nodes observation from a configuration schema. diff --git a/src/primaite/game/agent/observations/observations.py b/src/primaite/game/agent/observations/observations.py index dc41e8e5..08871072 100644 --- a/src/primaite/game/agent/observations/observations.py +++ b/src/primaite/game/agent/observations/observations.py @@ -1,24 +1,23 @@ """Manages the observation space for the agent.""" from abc import ABC, abstractmethod -from ipaddress import IPv4Address -from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING, Type +from typing import Any, Dict, Iterable, Type from gymnasium import spaces from pydantic import BaseModel, ConfigDict from primaite import getLogger -from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE _LOGGER = getLogger(__name__) -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame +WhereType = Iterable[str | int] | None class AbstractObservation(ABC): """Abstract class for an observation space component.""" class ConfigSchema(ABC, BaseModel): + """Config schema for observations.""" + model_config = ConfigDict(extra="forbid") _registry: Dict[str, Type["AbstractObservation"]] = {} @@ -61,269 +60,271 @@ class AbstractObservation(ABC): @classmethod def from_config(cls, cfg: Dict) -> "AbstractObservation": """Create this observation space component form a serialised format.""" - ObservationType = cls._registry[cfg['type']] + ObservationType = cls._registry[cfg["type"]] return ObservationType.from_config(cfg=cfg) -# class LinkObservation(AbstractObservation): -# """Observation of a link in the network.""" +''' +class LinkObservation(AbstractObservation): + """Observation of a link in the network.""" -# default_observation: spaces.Space = {"PROTOCOLS": {"ALL": 0}} -# "Default observation is what should be returned when the link doesn't exist." + default_observation: spaces.Space = {"PROTOCOLS": {"ALL": 0}} + "Default observation is what should be returned when the link doesn't exist." -# def __init__(self, where: Optional[Tuple[str]] = None) -> None: -# """Initialise link observation. + def __init__(self, where: Optional[Tuple[str]] = None) -> None: + """Initialise link observation. -# :param where: Store information about where in the simulation state dictionary to find the relevant information. -# Optional. If None, this corresponds that the file does not exist and the observation will be populated with -# zeroes. + :param where: Store information about where in the simulation state dictionary to find the relevant information. + Optional. If None, this corresponds that the file does not exist and the observation will be populated with + zeroes. -# A typical location for a service looks like this: -# `['network','nodes',,'servics', ]` -# :type where: Optional[List[str]] -# """ -# super().__init__() -# self.where: Optional[Tuple[str]] = where + A typical location for a service looks like this: + `['network','nodes',,'servics', ]` + :type where: Optional[List[str]] + """ + super().__init__() + self.where: Optional[Tuple[str]] = where -# def observe(self, state: Dict) -> Dict: -# """Generate observation based on the current state of the simulation. + def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. -# :param state: Simulation state dictionary -# :type state: Dict -# :return: Observation -# :rtype: Dict -# """ -# if self.where is None: -# return self.default_observation + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ + if self.where is None: + return self.default_observation -# link_state = access_from_nested_dict(state, self.where) -# if link_state is NOT_PRESENT_IN_STATE: -# return self.default_observation + link_state = access_from_nested_dict(state, self.where) + if link_state is NOT_PRESENT_IN_STATE: + return self.default_observation -# bandwidth = link_state["bandwidth"] -# load = link_state["current_load"] -# if load == 0: -# utilisation_category = 0 -# else: -# utilisation_fraction = load / bandwidth -# # 0 is UNUSED, 1 is 0%-10%. 2 is 10%-20%. 3 is 20%-30%. And so on... 10 is exactly 100% -# utilisation_category = int(utilisation_fraction * 9) + 1 + bandwidth = link_state["bandwidth"] + load = link_state["current_load"] + if load == 0: + utilisation_category = 0 + else: + utilisation_fraction = load / bandwidth + # 0 is UNUSED, 1 is 0%-10%. 2 is 10%-20%. 3 is 20%-30%. And so on... 10 is exactly 100% + utilisation_category = int(utilisation_fraction * 9) + 1 -# # TODO: once the links support separte load per protocol, this needs amendment to reflect that. -# return {"PROTOCOLS": {"ALL": min(utilisation_category, 10)}} + # TODO: once the links support separte load per protocol, this needs amendment to reflect that. + return {"PROTOCOLS": {"ALL": min(utilisation_category, 10)}} -# @property -# def space(self) -> spaces.Space: -# """Gymnasium space object describing the observation space shape. + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape. -# :return: Gymnasium space -# :rtype: spaces.Space -# """ -# return spaces.Dict({"PROTOCOLS": spaces.Dict({"ALL": spaces.Discrete(11)})}) + :return: Gymnasium space + :rtype: spaces.Space + """ + return spaces.Dict({"PROTOCOLS": spaces.Dict({"ALL": spaces.Discrete(11)})}) -# @classmethod -# def from_config(cls, config: Dict, game: "PrimaiteGame") -> "LinkObservation": -# """Create link observation from a config. + @classmethod + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "LinkObservation": + """Create link observation from a config. -# :param config: Dictionary containing the configuration for this link observation. -# :type config: Dict -# :param game: Reference to the PrimaiteGame object that spawned this observation. -# :type game: PrimaiteGame -# :return: Constructed link observation -# :rtype: LinkObservation -# """ -# return cls(where=["network", "links", game.ref_map_links[config["link_ref"]]]) + :param config: Dictionary containing the configuration for this link observation. + :type config: Dict + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame + :return: Constructed link observation + :rtype: LinkObservation + """ + return cls(where=["network", "links", game.ref_map_links[config["link_ref"]]]) -# class AclObservation(AbstractObservation): -# """Observation of an Access Control List (ACL) in the network.""" +class AclObservation(AbstractObservation): + """Observation of an Access Control List (ACL) in the network.""" -# # TODO: should where be optional, and we can use where=None to pad the observation space? -# # definitely the current approach does not support tracking files that aren't specified by name, for example -# # if a file is created at runtime, we have currently got no way of telling the observation space to track it. -# # this needs adding, but not for the MVP. -# def __init__( -# self, -# node_ip_to_id: Dict[str, int], -# ports: List[int], -# protocols: List[str], -# where: Optional[Tuple[str]] = None, -# num_rules: int = 10, -# ) -> None: -# """Initialise ACL observation. + # TODO: should where be optional, and we can use where=None to pad the observation space? + # definitely the current approach does not support tracking files that aren't specified by name, for example + # if a file is created at runtime, we have currently got no way of telling the observation space to track it. + # this needs adding, but not for the MVP. + def __init__( + self, + node_ip_to_id: Dict[str, int], + ports: List[int], + protocols: List[str], + where: Optional[Tuple[str]] = None, + num_rules: int = 10, + ) -> None: + """Initialise ACL observation. -# :param node_ip_to_id: Mapping between IP address and ID. -# :type node_ip_to_id: Dict[str, int] -# :param ports: List of ports which are part of the game that define the ordering when converting to an ID -# :type ports: List[int] -# :param protocols: List of protocols which are part of the game, defines ordering when converting to an ID -# :type protocols: list[str] -# :param where: Where in the simulation state dictionary to find the relevant information for this ACL. A typical -# example may look like this: -# ['network','nodes',,'acl','acl'] -# :type where: Optional[Tuple[str]], optional -# :param num_rules: , defaults to 10 -# :type num_rules: int, optional -# """ -# super().__init__() -# self.where: Optional[Tuple[str]] = where -# self.num_rules: int = num_rules -# self.node_to_id: Dict[str, int] = node_ip_to_id -# "List of node IP addresses, order in this list determines how they are converted to an ID" -# self.port_to_id: Dict[int, int] = {port: i + 2 for i, port in enumerate(ports)} -# "List of ports which are part of the game that define the ordering when converting to an ID" -# self.protocol_to_id: Dict[str, int] = {protocol: i + 2 for i, protocol in enumerate(protocols)} -# "List of protocols which are part of the game, defines ordering when converting to an ID" -# self.default_observation: Dict = { -# i -# + 1: { -# "position": i, -# "permission": 0, -# "source_node_id": 0, -# "source_port": 0, -# "dest_node_id": 0, -# "dest_port": 0, -# "protocol": 0, -# } -# for i in range(self.num_rules) -# } + :param node_ip_to_id: Mapping between IP address and ID. + :type node_ip_to_id: Dict[str, int] + :param ports: List of ports which are part of the game that define the ordering when converting to an ID + :type ports: List[int] + :param protocols: List of protocols which are part of the game, defines ordering when converting to an ID + :type protocols: list[str] + :param where: Where in the simulation state dictionary to find the relevant information for this ACL. A typical + example may look like this: + ['network','nodes',,'acl','acl'] + :type where: Optional[Tuple[str]], optional + :param num_rules: , defaults to 10 + :type num_rules: int, optional + """ + super().__init__() + self.where: Optional[Tuple[str]] = where + self.num_rules: int = num_rules + self.node_to_id: Dict[str, int] = node_ip_to_id + "List of node IP addresses, order in this list determines how they are converted to an ID" + self.port_to_id: Dict[int, int] = {port: i + 2 for i, port in enumerate(ports)} + "List of ports which are part of the game that define the ordering when converting to an ID" + self.protocol_to_id: Dict[str, int] = {protocol: i + 2 for i, protocol in enumerate(protocols)} + "List of protocols which are part of the game, defines ordering when converting to an ID" + self.default_observation: Dict = { + i + + 1: { + "position": i, + "permission": 0, + "source_node_id": 0, + "source_port": 0, + "dest_node_id": 0, + "dest_port": 0, + "protocol": 0, + } + for i in range(self.num_rules) + } -# def observe(self, state: Dict) -> Dict: -# """Generate observation based on the current state of the simulation. + def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation. -# :param state: Simulation state dictionary -# :type state: Dict -# :return: Observation -# :rtype: Dict -# """ -# if self.where is None: -# return self.default_observation -# acl_state: Dict = access_from_nested_dict(state, self.where) -# if acl_state is NOT_PRESENT_IN_STATE: -# return self.default_observation + :param state: Simulation state dictionary + :type state: Dict + :return: Observation + :rtype: Dict + """ + if self.where is None: + return self.default_observation + acl_state: Dict = access_from_nested_dict(state, self.where) + if acl_state is NOT_PRESENT_IN_STATE: + return self.default_observation -# # TODO: what if the ACL has more rules than num of max rules for obs space -# obs = {} -# acl_items = dict(acl_state.items()) -# i = 1 # don't show rule 0 for compatibility reasons. -# while i < self.num_rules + 1: -# rule_state = acl_items[i] -# if rule_state is None: -# obs[i] = { -# "position": i - 1, -# "permission": 0, -# "source_node_id": 0, -# "source_port": 0, -# "dest_node_id": 0, -# "dest_port": 0, -# "protocol": 0, -# } -# else: -# src_ip = rule_state["src_ip_address"] -# src_node_id = 1 if src_ip is None else self.node_to_id[IPv4Address(src_ip)] -# dst_ip = rule_state["dst_ip_address"] -# dst_node_ip = 1 if dst_ip is None else self.node_to_id[IPv4Address(dst_ip)] -# src_port = rule_state["src_port"] -# src_port_id = 1 if src_port is None else self.port_to_id[src_port] -# dst_port = rule_state["dst_port"] -# dst_port_id = 1 if dst_port is None else self.port_to_id[dst_port] -# protocol = rule_state["protocol"] -# protocol_id = 1 if protocol is None else self.protocol_to_id[protocol] -# obs[i] = { -# "position": i - 1, -# "permission": rule_state["action"], -# "source_node_id": src_node_id, -# "source_port": src_port_id, -# "dest_node_id": dst_node_ip, -# "dest_port": dst_port_id, -# "protocol": protocol_id, -# } -# i += 1 -# return obs + # TODO: what if the ACL has more rules than num of max rules for obs space + obs = {} + acl_items = dict(acl_state.items()) + i = 1 # don't show rule 0 for compatibility reasons. + while i < self.num_rules + 1: + rule_state = acl_items[i] + if rule_state is None: + obs[i] = { + "position": i - 1, + "permission": 0, + "source_node_id": 0, + "source_port": 0, + "dest_node_id": 0, + "dest_port": 0, + "protocol": 0, + } + else: + src_ip = rule_state["src_ip_address"] + src_node_id = 1 if src_ip is None else self.node_to_id[IPv4Address(src_ip)] + dst_ip = rule_state["dst_ip_address"] + dst_node_ip = 1 if dst_ip is None else self.node_to_id[IPv4Address(dst_ip)] + src_port = rule_state["src_port"] + src_port_id = 1 if src_port is None else self.port_to_id[src_port] + dst_port = rule_state["dst_port"] + dst_port_id = 1 if dst_port is None else self.port_to_id[dst_port] + protocol = rule_state["protocol"] + protocol_id = 1 if protocol is None else self.protocol_to_id[protocol] + obs[i] = { + "position": i - 1, + "permission": rule_state["action"], + "source_node_id": src_node_id, + "source_port": src_port_id, + "dest_node_id": dst_node_ip, + "dest_port": dst_port_id, + "protocol": protocol_id, + } + i += 1 + return obs -# @property -# def space(self) -> spaces.Space: -# """Gymnasium space object describing the observation space shape. + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape. -# :return: Gymnasium space -# :rtype: spaces.Space -# """ -# return spaces.Dict( -# { -# i -# + 1: spaces.Dict( -# { -# "position": spaces.Discrete(self.num_rules), -# "permission": spaces.Discrete(3), -# # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) -# "source_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), -# "source_port": spaces.Discrete(len(self.port_to_id) + 2), -# "dest_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), -# "dest_port": spaces.Discrete(len(self.port_to_id) + 2), -# "protocol": spaces.Discrete(len(self.protocol_to_id) + 2), -# } -# ) -# for i in range(self.num_rules) -# } -# ) + :return: Gymnasium space + :rtype: spaces.Space + """ + return spaces.Dict( + { + i + + 1: spaces.Dict( + { + "position": spaces.Discrete(self.num_rules), + "permission": spaces.Discrete(3), + # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) + "source_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), + "source_port": spaces.Discrete(len(self.port_to_id) + 2), + "dest_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), + "dest_port": spaces.Discrete(len(self.port_to_id) + 2), + "protocol": spaces.Discrete(len(self.protocol_to_id) + 2), + } + ) + for i in range(self.num_rules) + } + ) -# @classmethod -# def from_config(cls, config: Dict, game: "PrimaiteGame") -> "AclObservation": -# """Generate ACL observation from a config. + @classmethod + def from_config(cls, config: Dict, game: "PrimaiteGame") -> "AclObservation": + """Generate ACL observation from a config. -# :param config: Dictionary containing the configuration for this ACL observation. -# :type config: Dict -# :param game: Reference to the PrimaiteGame object that spawned this observation. -# :type game: PrimaiteGame -# :return: Observation object -# :rtype: AclObservation -# """ -# max_acl_rules = config["options"]["max_acl_rules"] -# node_ip_to_idx = {} -# for ip_idx, ip_map_config in enumerate(config["ip_address_order"]): -# node_ref = ip_map_config["node_hostname"] -# nic_num = ip_map_config["nic_num"] -# node_obj = game.simulation.network.nodes[game.ref_map_nodes[node_ref]] -# nic_obj = node_obj.network_interface[nic_num] -# node_ip_to_idx[nic_obj.ip_address] = ip_idx + 2 + :param config: Dictionary containing the configuration for this ACL observation. + :type config: Dict + :param game: Reference to the PrimaiteGame object that spawned this observation. + :type game: PrimaiteGame + :return: Observation object + :rtype: AclObservation + """ + max_acl_rules = config["options"]["max_acl_rules"] + node_ip_to_idx = {} + for ip_idx, ip_map_config in enumerate(config["ip_address_order"]): + node_ref = ip_map_config["node_hostname"] + nic_num = ip_map_config["nic_num"] + node_obj = game.simulation.network.nodes[game.ref_map_nodes[node_ref]] + nic_obj = node_obj.network_interface[nic_num] + node_ip_to_idx[nic_obj.ip_address] = ip_idx + 2 -# router_hostname = config["router_hostname"] -# return cls( -# node_ip_to_id=node_ip_to_idx, -# ports=game.options.ports, -# protocols=game.options.protocols, -# where=["network", "nodes", router_hostname, "acl", "acl"], -# num_rules=max_acl_rules, -# ) + router_hostname = config["router_hostname"] + return cls( + node_ip_to_id=node_ip_to_idx, + ports=game.options.ports, + protocols=game.options.protocols, + where=["network", "nodes", router_hostname, "acl", "acl"], + num_rules=max_acl_rules, + ) -# class NullObservation(AbstractObservation): -# """Null observation, returns a single 0 value for the observation space.""" +class NullObservation(AbstractObservation): + """Null observation, returns a single 0 value for the observation space.""" -# def __init__(self, where: Optional[List[str]] = None): -# """Initialise null observation.""" -# self.default_observation: Dict = {} + def __init__(self, where: Optional[List[str]] = None): + """Initialise null observation.""" + self.default_observation: Dict = {} -# def observe(self, state: Dict) -> Dict: -# """Generate observation based on the current state of the simulation.""" -# return 0 + def observe(self, state: Dict) -> Dict: + """Generate observation based on the current state of the simulation.""" + return 0 -# @property -# def space(self) -> spaces.Space: -# """Gymnasium space object describing the observation space shape.""" -# return spaces.Discrete(1) + @property + def space(self) -> spaces.Space: + """Gymnasium space object describing the observation space shape.""" + return spaces.Discrete(1) -# @classmethod -# def from_config(cls, config: Dict, game: Optional["PrimaiteGame"] = None) -> "NullObservation": -# """ -# Create null observation from a config. + @classmethod + def from_config(cls, config: Dict, game: Optional["PrimaiteGame"] = None) -> "NullObservation": + """ + Create null observation from a config. -# The parameters are ignored, they are here to match the signature of the other observation classes. -# """ -# return cls() + The parameters are ignored, they are here to match the signature of the other observation classes. + """ + return cls() -# class ICSObservation(NullObservation): -# """ICS observation placeholder, currently not implemented so always returns a single 0.""" +class ICSObservation(NullObservation): + """ICS observation placeholder, currently not implemented so always returns a single 0.""" -# pass + pass +''' diff --git a/src/primaite/game/agent/observations/router_observation.py b/src/primaite/game/agent/observations/router_observation.py new file mode 100644 index 00000000..b8dee2c2 --- /dev/null +++ b/src/primaite/game/agent/observations/router_observation.py @@ -0,0 +1,142 @@ +from __future__ import annotations + +from typing import Dict, List, Optional + +from gymnasium import spaces +from gymnasium.core import ObsType + +from primaite import getLogger +from primaite.game.agent.observations.acl_observation import ACLObservation +from primaite.game.agent.observations.nic_observations import PortObservation +from primaite.game.agent.observations.observations import AbstractObservation, WhereType +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE + +_LOGGER = getLogger(__name__) + + +class RouterObservation(AbstractObservation, identifier="ROUTER"): + """Router observation, provides status information about a router within the simulation environment.""" + + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for RouterObservation.""" + + hostname: str + """Hostname of the router, used for querying simulation state dictionary.""" + ports: Optional[List[PortObservation.ConfigSchema]] = None + """Configuration of port observations for this router.""" + num_ports: Optional[int] = None + """Number of port observations configured for this router.""" + acl: Optional[ACLObservation.ConfigSchema] = None + """Configuration of ACL observation on this router.""" + ip_list: Optional[List[str]] = None + """List of IP addresses for encoding ACLs.""" + wildcard_list: Optional[List[str]] = None + """List of IP wildcards for encoding ACLs.""" + port_list: Optional[List[int]] = None + """List of ports for encoding ACLs.""" + protocol_list: Optional[List[str]] = None + """List of protocols for encoding ACLs.""" + num_rules: Optional[int] = None + """Number of rules ACL rules to show.""" + + def __init__( + self, + where: WhereType, + ports: List[PortObservation], + num_ports: int, + acl: ACLObservation, + ) -> None: + """ + Initialize a router observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this router. + A typical location for a router might be ['network', 'nodes', ]. + :type where: WhereType + :param ports: List of port observations representing the ports of the router. + :type ports: List[PortObservation] + :param num_ports: Number of ports for the router. + :type num_ports: int + :param acl: ACL observation representing the access control list of the router. + :type acl: ACLObservation + """ + self.where: WhereType = where + self.ports: List[PortObservation] = ports + self.acl: ACLObservation = acl + self.num_ports: int = num_ports + + while len(self.ports) < num_ports: + self.ports.append(PortObservation(where=None)) + while len(self.ports) > num_ports: + self.ports.pop() + msg = "Too many ports in router observation. Truncating." + _LOGGER.warning(msg) + + self.default_observation = { + "PORTS": {i + 1: p.default_observation for i, p in enumerate(self.ports)}, + "ACL": self.acl.default_observation, + } + + def observe(self, state: Dict) -> ObsType: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the status of ports and ACL configuration of the router. + :rtype: ObsType + """ + router_state = access_from_nested_dict(state, self.where) + if router_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + obs = {} + obs["PORTS"] = {i + 1: p.observe(state) for i, p in enumerate(self.ports)} + obs["ACL"] = self.acl.observe(state) + return obs + + @property + def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for router status. + :rtype: spaces.Space + """ + return spaces.Dict( + {"PORTS": spaces.Dict({i + 1: p.space for i, p in enumerate(self.ports)}), "ACL": self.acl.space} + ) + + @classmethod + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> RouterObservation: + """ + Create a router observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the router observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this router's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed router observation instance. + :rtype: RouterObservation + """ + where = parent_where + ["nodes", config.hostname] + + if config.acl is None: + config.acl = ACLObservation.ConfigSchema() + if config.acl.num_rules is None: + config.acl.num_rules = config.num_rules + if config.acl.ip_list is None: + config.acl.ip_list = config.ip_list + if config.acl.wildcard_list is None: + config.acl.wildcard_list = config.wildcard_list + if config.acl.port_list is None: + config.acl.port_list = config.port_list + if config.acl.protocol_list is None: + config.acl.protocol_list = config.protocol_list + + if config.ports is None: + config.ports = [PortObservation.ConfigSchema(port_id=i + 1) for i in range(config.num_ports)] + + ports = [PortObservation.from_config(config=c, parent_where=where) for c in config.ports] + acl = ACLObservation.from_config(config=config.acl, parent_where=where) + return cls(where=where, ports=ports, num_ports=config.num_ports, acl=acl) diff --git a/src/primaite/game/agent/observations/software_observation.py b/src/primaite/game/agent/observations/software_observation.py index 6caf791c..eb94651d 100644 --- a/src/primaite/game/agent/observations/software_observation.py +++ b/src/primaite/game/agent/observations/software_observation.py @@ -1,45 +1,43 @@ -from typing import Dict, List, Optional, Tuple, TYPE_CHECKING +from __future__ import annotations + +from typing import Dict from gymnasium import spaces +from gymnasium.core import ObsType -from primaite.game.agent.observations.observations import AbstractObservation +from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame +class ServiceObservation(AbstractObservation, identifier="SERVICE"): + """Service observation, shows status of a service in the simulation environment.""" -class ServiceObservation(AbstractObservation): - """Observation of a service in the network.""" + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for ServiceObservation.""" - default_observation: spaces.Space = {"operating_status": 0, "health_status": 0} - "Default observation is what should be returned when the service doesn't exist." + service_name: str + """Name of the service, used for querying simulation state dictionary""" - def __init__(self, where: Optional[Tuple[str]] = None) -> None: - """Initialise service observation. - - :param where: Store information about where in the simulation state dictionary to find the relevant information. - Optional. If None, this corresponds that the file does not exist and the observation will be populated with - zeroes. - - A typical location for a service looks like this: - `['network','nodes',,'services', ]` - :type where: Optional[List[str]] + def __init__(self, where: WhereType) -> None: """ - super().__init__() - self.where: Optional[Tuple[str]] = where + Initialize a service observation instance. - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. + :param where: Where in the simulation state dictionary to find the relevant information for this service. + A typical location for a service might be ['network', 'nodes', , 'services', ]. + :type where: WhereType + """ + self.where = where + self.default_observation = {"operating_status": 0, "health_status": 0} - :param state: Simulation state dictionary + def observe(self, state: Dict) -> ObsType: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. :type state: Dict - :return: Observation - :rtype: Dict + :return: Observation containing the operating status and health status of the service. + :rtype: ObsType """ - if self.where is None: - return self.default_observation - service_state = access_from_nested_dict(state, self.where) if service_state is NOT_PRESENT_IN_STATE: return self.default_observation @@ -50,114 +48,96 @@ class ServiceObservation(AbstractObservation): @property def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for service status. + :rtype: spaces.Space + """ return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(5)}) @classmethod - def from_config( - cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]] = None - ) -> "ServiceObservation": - """Create service observation from a config. + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ServiceObservation: + """ + Create a service observation from a configuration schema. - :param config: Dictionary containing the configuration for this service observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :param parent_where: Where in the simulation state dictionary this service's parent node is located. Optional. - :type parent_where: Optional[List[str]], optional - :return: Constructed service observation + :param config: Configuration schema containing the necessary information for the service observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this service's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed service observation instance. :rtype: ServiceObservation """ - return cls(where=parent_where + ["services", config["service_name"]]) + return cls(where=parent_where + ["services", config.service_name]) -class ApplicationObservation(AbstractObservation): - """Observation of an application in the network.""" +class ApplicationObservation(AbstractObservation, identifier="APPLICATION"): + """Application observation, shows the status of an application within the simulation environment.""" - default_observation: spaces.Space = {"operating_status": 0, "health_status": 0, "num_executions": 0} - "Default observation is what should be returned when the application doesn't exist." + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for ApplicationObservation.""" - def __init__(self, where: Optional[Tuple[str]] = None) -> None: - """Initialise application observation. + application_name: str + """Name of the application, used for querying simulation state dictionary""" - :param where: Store information about where in the simulation state dictionary to find the relevant information. - Optional. If None, this corresponds that the file does not exist and the observation will be populated with - zeroes. - - A typical location for a service looks like this: - `['network','nodes',,'applications', ]` - :type where: Optional[List[str]] + def __init__(self, where: WhereType) -> None: """ - super().__init__() - self.where: Optional[Tuple[str]] = where + Initialise an application observation instance. - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. + :param where: Where in the simulation state dictionary to find the relevant information for this application. + A typical location for an application might be + ['network', 'nodes', , 'applications', ]. + :type where: WhereType + """ + self.where = where + self.default_observation = {"operating_status": 0, "health_status": 0, "num_executions": 0} - :param state: Simulation state dictionary + def observe(self, state: Dict) -> ObsType: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. :type state: Dict - :return: Observation - :rtype: Dict + :return: Obs containing the operating status, health status, and number of executions of the application. + :rtype: ObsType """ - if self.where is None: - return self.default_observation - - app_state = access_from_nested_dict(state, self.where) - if app_state is NOT_PRESENT_IN_STATE: + application_state = access_from_nested_dict(state, self.where) + if application_state is NOT_PRESENT_IN_STATE: return self.default_observation return { - "operating_status": app_state["operating_state"], - "health_status": app_state["health_state_visible"], - "num_executions": self._categorise_num_executions(app_state["num_executions"]), + "operating_status": application_state["operating_state"], + "health_status": application_state["health_state_visible"], + "num_executions": application_state["num_executions"], } @property def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for application status. + :rtype: spaces.Space + """ return spaces.Dict( { "operating_status": spaces.Discrete(7), - "health_status": spaces.Discrete(6), + "health_status": spaces.Discrete(5), "num_executions": spaces.Discrete(4), } ) @classmethod - def from_config( - cls, config: Dict, game: "PrimaiteGame", parent_where: Optional[List[str]] = None - ) -> "ApplicationObservation": - """Create application observation from a config. + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ApplicationObservation: + """ + Create an application observation from a configuration schema. - :param config: Dictionary containing the configuration for this service observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :param parent_where: Where in the simulation state dictionary this service's parent node is located. Optional. - :type parent_where: Optional[List[str]], optional - :return: Constructed service observation + :param config: Configuration schema containing the necessary information for the application observation. + :type config: ConfigSchema + :param parent_where: Where in the simulation state dictionary to find the information about this application's + parent node. A typical location for a node might be ['network', 'nodes', ]. + :type parent_where: WhereType, optional + :return: Constructed application observation instance. :rtype: ApplicationObservation """ - return cls(where=parent_where + ["services", config["application_name"]]) - - @classmethod - def _categorise_num_executions(cls, num_executions: int) -> int: - """ - Categorise the number of executions of an application. - - Helps classify the number of application executions into different categories. - - Current categories: - - 0: Application is never executed - - 1: Application is executed a low number of times (1-5) - - 2: Application is executed often (6-10) - - 3: Application is executed a high number of times (more than 10) - - :param: num_executions: Number of times the application is executed - """ - if num_executions > 10: - return 3 - elif num_executions > 5: - return 2 - elif num_executions > 0: - return 1 - return 0 + return cls(where=parent_where + ["applications", config.application_name]) From 7299a12c64369340373f2fcd5597cec98c046730 Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Fri, 29 Mar 2024 16:30:39 +0000 Subject: [PATCH 773/980] #2402 add firewall acl actions --- src/primaite/game/agent/actions.py | 154 +++++- .../hardware/nodes/network/firewall.py | 170 +++---- .../network/hardware/nodes/network/router.py | 2 +- .../configs/firewall_actions_network.yaml | 448 ++++++++++++++++++ .../game_layer/test_actions.py | 102 ++++ 5 files changed, 793 insertions(+), 83 deletions(-) create mode 100644 tests/assets/configs/firewall_actions_network.yaml diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index d585273d..ff59e77f 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -458,7 +458,7 @@ class RouterACLAddRuleAction(AbstractAction): permission_str = "UNUSED" return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS elif permission == 1: - permission_str = "ALLOW" + permission_str = "PERMIT" elif permission == 2: permission_str = "DENY" else: @@ -540,6 +540,156 @@ class RouterACLRemoveRuleAction(AbstractAction): return ["network", "node", target_router_nodename, "acl", "remove_rule", position] +class FirewallACLAddRuleAction(AbstractAction): + """Action which adds a rule to a firewall port's ACL.""" + + def __init__( + self, + manager: "ActionManager", + max_acl_rules: int, + num_ips: int, + num_ports: int, + num_protocols: int, + **kwargs, + ) -> None: + """Init method for FirewallACLAddRuleAction. + + :param manager: Reference to the ActionManager which created this action. + :type manager: ActionManager + :param max_acl_rules: Maximum number of ACL rules that can be added to the router. + :type max_acl_rules: int + :param num_ips: Number of IP addresses in the simulation. + :type num_ips: int + :param num_ports: Number of ports in the simulation. + :type num_ports: int + :param num_protocols: Number of protocols in the simulation. + :type num_protocols: int + """ + super().__init__(manager=manager) + num_permissions = 3 + self.shape: Dict[str, int] = { + "position": max_acl_rules, + "permission": num_permissions, + "source_ip_id": num_ips, + "dest_ip_id": num_ips, + "source_port_id": num_ports, + "dest_port_id": num_ports, + "protocol_id": num_protocols, + } + + def form_request( + self, + target_firewall_nodename: str, + firewall_port_name: str, + firewall_port_direction: str, + position: int, + permission: int, + source_ip_id: int, + dest_ip_id: int, + source_port_id: int, + dest_port_id: int, + protocol_id: int, + ) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" + if permission == 0: + permission_str = "UNUSED" + return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS + elif permission == 1: + permission_str = "PERMIT" + elif permission == 2: + permission_str = "DENY" + else: + _LOGGER.warning(f"{self.__class__} received permission {permission}, expected 0 or 1.") + + if protocol_id == 0: + return ["do_nothing"] # NOT SUPPORTED, JUST DO NOTHING IF WE COME ACROSS THIS + + if protocol_id == 1: + protocol = "ALL" + else: + protocol = self.manager.get_internet_protocol_by_idx(protocol_id - 2) + # subtract 2 to account for UNUSED=0 and ALL=1. + + if source_ip_id == 0: + return ["do_nothing"] # invalid formulation + elif source_ip_id == 1: + src_ip = "ALL" + else: + src_ip = self.manager.get_ip_address_by_idx(source_ip_id - 2) + # subtract 2 to account for UNUSED=0, and ALL=1 + + if source_port_id == 0: + return ["do_nothing"] # invalid formulation + elif source_port_id == 1: + src_port = "ALL" + else: + src_port = self.manager.get_port_by_idx(source_port_id - 2) + # subtract 2 to account for UNUSED=0, and ALL=1 + + if source_ip_id == 0: + return ["do_nothing"] # invalid formulation + elif dest_ip_id == 1: + dst_ip = "ALL" + else: + dst_ip = self.manager.get_ip_address_by_idx(dest_ip_id - 2) + # subtract 2 to account for UNUSED=0, and ALL=1 + + if dest_port_id == 0: + return ["do_nothing"] # invalid formulation + elif dest_port_id == 1: + dst_port = "ALL" + else: + dst_port = self.manager.get_port_by_idx(dest_port_id - 2) + # subtract 2 to account for UNUSED=0, and ALL=1 + + return [ + "network", + "node", + target_firewall_nodename, + firewall_port_name, + firewall_port_direction, + "acl", + "add_rule", + permission_str, + protocol, + str(src_ip), + src_port, + str(dst_ip), + dst_port, + position, + ] + + +class FirewallACLRemoveRuleAction(AbstractAction): + """Action which removes a rule from a firewall port's ACL.""" + + def __init__(self, manager: "ActionManager", max_acl_rules: int, **kwargs) -> None: + """Init method for RouterACLRemoveRuleAction. + + :param manager: Reference to the ActionManager which created this action. + :type manager: ActionManager + :param max_acl_rules: Maximum number of ACL rules that can be added to the router. + :type max_acl_rules: int + """ + super().__init__(manager=manager) + self.shape: Dict[str, int] = {"position": max_acl_rules} + + def form_request( + self, target_firewall_nodename: str, firewall_port_name: str, firewall_port_direction: str, position: int + ) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" + return [ + "network", + "node", + target_firewall_nodename, + firewall_port_name, + firewall_port_direction, + "acl", + "remove_rule", + position, + ] + + class NetworkNICAbstractAction(AbstractAction): """ Abstract base class for NIC actions. @@ -668,6 +818,8 @@ class ActionManager: "NODE_RESET": NodeResetAction, "ROUTER_ACL_ADDRULE": RouterACLAddRuleAction, "ROUTER_ACL_REMOVERULE": RouterACLRemoveRuleAction, + "FIREWALL_ACL_ADDRULE": FirewallACLAddRuleAction, + "FIREWALL_ACL_REMOVERULE": FirewallACLRemoveRuleAction, "NETWORK_NIC_ENABLE": NetworkNICEnableAction, "NETWORK_NIC_DISABLE": NetworkNICDisableAction, "NETWORK_PORT_ENABLE": NetworkPortEnableAction, diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index ea353b2f..a27b5cee 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -1,10 +1,10 @@ from ipaddress import IPv4Address -from typing import Dict, Final, Optional, Union +from typing import Dict, Final, Union from prettytable import MARKDOWN, PrettyTable -from pydantic import validate_call +from pydantic import Field, validate_call -# from primaite.simulator.core import RequestManager, RequestType +from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.network.router import ( AccessControlList, @@ -68,22 +68,34 @@ class Firewall(Router): :ivar str hostname: The Firewall hostname. """ - internal_inbound_acl: Optional[AccessControlList] = None + internal_inbound_acl: AccessControlList = Field( + default_factory=lambda: AccessControlList(name="Internal Inbound", implicit_action=ACLAction.DENY) + ) """Access Control List for managing entering the internal network.""" - internal_outbound_acl: Optional[AccessControlList] = None + internal_outbound_acl: AccessControlList = Field( + default_factory=lambda: AccessControlList(name="Internal Outbound", implicit_action=ACLAction.DENY) + ) """Access Control List for managing traffic leaving the internal network.""" - dmz_inbound_acl: Optional[AccessControlList] = None + dmz_inbound_acl: AccessControlList = Field( + default_factory=lambda: AccessControlList(name="DMZ Inbound", implicit_action=ACLAction.DENY) + ) """Access Control List for managing traffic entering the DMZ.""" - dmz_outbound_acl: Optional[AccessControlList] = None + dmz_outbound_acl: AccessControlList = Field( + default_factory=lambda: AccessControlList(name="DMZ Outbound", implicit_action=ACLAction.DENY) + ) """Access Control List for managing traffic leaving the DMZ.""" - external_inbound_acl: Optional[AccessControlList] = None + external_inbound_acl: AccessControlList = Field( + default_factory=lambda: AccessControlList(name="External Inbound", implicit_action=ACLAction.PERMIT) + ) """Access Control List for managing traffic entering from an external network.""" - external_outbound_acl: Optional[AccessControlList] = None + external_outbound_acl: AccessControlList = Field( + default_factory=lambda: AccessControlList(name="External Outbound", implicit_action=ACLAction.PERMIT) + ) """Access Control List for managing traffic leaving towards an external network.""" def __init__(self, hostname: str, **kwargs): @@ -101,88 +113,84 @@ class Firewall(Router): self.connect_nic( RouterInterface(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0", port_name="dmz") ) - # Initialise ACLs for internal and dmz interfaces with a default DENY policy - self.internal_inbound_acl = AccessControlList( - sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY, name=f"{hostname} - Internal Inbound" + self.internal_inbound_acl.sys_log = kwargs["sys_log"] + self.internal_inbound_acl.name = f"{hostname} - Internal Inbound" + + self.internal_outbound_acl.sys_log = kwargs["sys_log"] + self.internal_outbound_acl.name = f"{hostname} - Internal Outbound" + + self.dmz_inbound_acl.sys_log = kwargs["sys_log"] + self.dmz_inbound_acl.name = f"{hostname} - DMZ Inbound" + + self.dmz_outbound_acl.sys_log = kwargs["sys_log"] + self.dmz_outbound_acl.name = f"{hostname} - DMZ Outbound" + + self.external_inbound_acl.sys_log = kwargs["sys_log"] + self.external_inbound_acl.name = f"{hostname} - External Inbound" + + self.external_outbound_acl.sys_log = kwargs["sys_log"] + self.external_outbound_acl.name = f"{hostname} - External Outbound" + + def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ + rm = super()._init_request_manager() + self._internal_acl_request_manager = RequestManager() + rm.add_request("internal", RequestType(func=self._internal_acl_request_manager)) + + self._dmz_acl_request_manager = RequestManager() + rm.add_request("dmz", RequestType(func=self._dmz_acl_request_manager)) + + self._external_acl_request_manager = RequestManager() + rm.add_request("external", RequestType(func=self._external_acl_request_manager)) + + self._internal_inbound_acl_request_manager = RequestManager() + self._internal_outbound_acl_request_manager = RequestManager() + self._internal_acl_request_manager.add_request( + "inbound", RequestType(func=self._internal_inbound_acl_request_manager) ) - self.internal_outbound_acl = AccessControlList( - sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY, name=f"{hostname} - Internal Outbound" - ) - self.dmz_inbound_acl = AccessControlList( - sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY, name=f"{hostname} - DMZ Inbound" - ) - self.dmz_outbound_acl = AccessControlList( - sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY, name=f"{hostname} - DMZ Outbound" + self._internal_acl_request_manager.add_request( + "outbound", RequestType(func=self._internal_outbound_acl_request_manager) ) - # external ACLs should have a default PERMIT policy - self.external_inbound_acl = AccessControlList( - sys_log=kwargs["sys_log"], implicit_action=ACLAction.PERMIT, name=f"{hostname} - External Inbound" + self.dmz_inbound_acl_request_manager = RequestManager() + self.dmz_outbound_acl_request_manager = RequestManager() + self._dmz_acl_request_manager.add_request("inbound", RequestType(func=self.dmz_inbound_acl_request_manager)) + self._dmz_acl_request_manager.add_request("outbound", RequestType(func=self.dmz_outbound_acl_request_manager)) + + self.external_inbound_acl_request_manager = RequestManager() + self.external_outbound_acl_request_manager = RequestManager() + self._external_acl_request_manager.add_request( + "inbound", RequestType(func=self.external_inbound_acl_request_manager) ) - self.external_outbound_acl = AccessControlList( - sys_log=kwargs["sys_log"], implicit_action=ACLAction.PERMIT, name=f"{hostname} - External Outbound" + self._external_acl_request_manager.add_request( + "outbound", RequestType(func=self.external_outbound_acl_request_manager) ) - # def _init_request_manager(self) -> RequestManager: - # """ - # Initialise the request manager. + self._internal_inbound_acl_request_manager.add_request( + "acl", RequestType(func=self.internal_inbound_acl._request_manager) + ) + self._internal_outbound_acl_request_manager.add_request( + "acl", RequestType(func=self.internal_outbound_acl._request_manager) + ) - # More information in user guide and docstring for SimComponent._init_request_manager. - # """ - # rm = super()._init_request_manager() - # self._internal_acl_request_manager = RequestManager() - # rm.add_request("internal", RequestType(func=self._internal_acl_request_manager)) + self.dmz_inbound_acl_request_manager.add_request("acl", RequestType(func=self.dmz_inbound_acl._request_manager)) + self.dmz_outbound_acl_request_manager.add_request( + "acl", RequestType(func=self.dmz_outbound_acl._request_manager) + ) - # self._dmz_acl_request_manager = RequestManager() - # rm.add_request("dmz", RequestType(func=self._dmz_acl_request_manager)) + self.external_inbound_acl_request_manager.add_request( + "acl", RequestType(func=self.external_inbound_acl._request_manager) + ) + self.external_outbound_acl_request_manager.add_request( + "acl", RequestType(func=self.external_outbound_acl._request_manager) + ) - # self._external_acl_request_manager = RequestManager() - # rm.add_request("external", RequestType(func=self._external_acl_request_manager)) - - # self._internal_inbound_acl_request_manager = RequestManager() - # self._internal_outbound_acl_request_manager = RequestManager() - # self._internal_acl_request_manager.add_request( - # "inbound", RequestType(func=self._internal_inbound_acl_request_manager) - # ) - # self._internal_acl_request_manager.add_request( - # "outbound", RequestType(func=self._internal_outbound_acl_request_manager) - # ) - - # self.dmz_inbound_acl_request_manager = RequestManager() - # self.dmz_outbound_acl_request_manager = RequestManager() - # self._dmz_acl_request_manager.add_request("inbound", RequestType(func=self.dmz_inbound_acl_request_manager)) - # self._dmz_acl_request_manager.add_request("outbound", RequestType(func=self.dmz_outbound_acl_request_manager)) - - # self.external_inbound_acl_request_manager = RequestManager() - # self.external_outbound_acl_request_manager = RequestManager() - # self._external_acl_request_manager.add_request( - # "inbound", RequestType(func=self.external_inbound_acl_request_manager) - # ) - # self._external_acl_request_manager.add_request( - # "outbound", RequestType(func=self.external_outbound_acl_request_manager) - # ) - - # self._internal_inbound_acl_request_manager.add_request( - # "acl", RequestType(func=self.internal_inbound_acl._request_manager) - # ) - # self._internal_outbound_acl_request_manager.add_request( - # "acl", RequestType(func=self.internal_outbound_acl._request_manager) - # ) - - # self.dmz_inbound_acl_request_manager.add_request("acl", RequestType(func=self.dmz_inbound_acl._request_manager)) - # self.dmz_outbound_acl_request_manager.add_request( - # "acl", RequestType(func=self.dmz_outbound_acl._request_manager) - # ) - - # self.external_inbound_acl_request_manager.add_request( - # "acl", RequestType(func=self.external_inbound_acl._request_manager) - # ) - # self.external_outbound_acl_request_manager.add_request( - # "acl", RequestType(func=self.external_outbound_acl._request_manager) - # ) - - # return rm + return rm def describe_state(self) -> Dict: """ diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 102eb7dc..07b0dd26 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -275,7 +275,7 @@ class AccessControlList(SimComponent): :ivar int max_acl_rules: The maximum number of ACL rules that can be added to the list. Defaults to 25. """ - sys_log: SysLog + sys_log: Optional[SysLog] = None implicit_action: ACLAction implicit_rule: ACLRule max_acl_rules: int = 25 diff --git a/tests/assets/configs/firewall_actions_network.yaml b/tests/assets/configs/firewall_actions_network.yaml new file mode 100644 index 00000000..67c6243d --- /dev/null +++ b/tests/assets/configs/firewall_actions_network.yaml @@ -0,0 +1,448 @@ +# Network with DMZ +# +# An example network configuration with an internal network, a DMZ network and a couple of external networks. +# +# ............................................................................ +# . . +# . Internal Network . +# . . +# . -------------- -------------- -------------- . +# . | client_1 |------| switch_1 |--------| router_1 | . +# . -------------- -------------- -------------- . +# . (Computer) | . +# ........................................................|................... +# | +# | +# ........................................................|................... +# . | . +# . DMZ Network | . +# . | . +# . ---------------- -------------- -------------- . +# . | dmz_server |------| switch_2 |------| firewall | . +# . ---------------- -------------- -------------- . +# . (Server) | . +# ........................................................|................... +# | +# External Network | +# | +# | +# ----------------------- -------------- --------------------- +# | external_computer |------| switch_3 |------| external_server | +# ----------------------- -------------- --------------------- +# +training_config: + rl_framework: SB3 + rl_algorithm: PPO + seed: 333 + n_learn_episodes: 1 + n_eval_episodes: 5 + max_steps_per_episode: 128 + deterministic_eval: false + n_agents: 1 + agent_references: + - defender + +io_settings: + save_step_metadata: false + save_pcap_logs: true + save_sys_logs: true + + +game: + max_episode_length: 256 + ports: + - ARP + - DNS + - HTTP + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + - UDP + +agents: + - ref: defender + team: BLUE + type: ProxyAgent + observation_space: + type: UC2BlueObservation + options: + num_services_per_node: 1 + num_folders_per_node: 1 + num_files_per_folder: 1 + num_nics_per_node: 2 + nodes: + - node_hostname: client_1 + links: + - link_ref: client_1___switch_1 + acl: + options: + max_acl_rules: 10 + router_hostname: router_1 + ip_address_order: + - node_hostname: client_1 + nic_num: 1 + ics: null + action_space: + action_list: + - type: DONOTHING + - type: FIREWALL_ACL_ADDRULE + - type: FIREWALL_ACL_REMOVERULE + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: FIREWALL_ACL_ADDRULE + options: + target_firewall_nodename: firewall + firewall_port_name: internal + firewall_port_direction: inbound + position: 1 + permission: 1 + source_ip_id: 2 # client 1 + dest_ip_id: 1 # ALL + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 + 2: + action: FIREWALL_ACL_REMOVERULE + options: + target_firewall_nodename: firewall + firewall_port_name: internal + firewall_port_direction: inbound + position: 1 + 3: + action: FIREWALL_ACL_ADDRULE + options: + target_firewall_nodename: firewall + firewall_port_name: internal + firewall_port_direction: outbound + position: 1 + permission: 2 + source_ip_id: 2 # client 1 + dest_ip_id: 1 # ALL + source_port_id: 2 + dest_port_id: 3 + protocol_id: 2 + 4: + action: FIREWALL_ACL_REMOVERULE + options: + target_firewall_nodename: firewall + firewall_port_name: internal + firewall_port_direction: outbound + position: 1 + 5: + action: FIREWALL_ACL_ADDRULE + options: + target_firewall_nodename: firewall + firewall_port_name: dmz + firewall_port_direction: inbound + position: 1 + permission: 2 + source_ip_id: 3 # dmz_server + dest_ip_id: 2 # client_1 + source_port_id: 4 + dest_port_id: 4 + protocol_id: 4 + 6: + action: FIREWALL_ACL_REMOVERULE + options: + target_firewall_nodename: firewall + firewall_port_name: dmz + firewall_port_direction: inbound + position: 1 + 7: + action: FIREWALL_ACL_ADDRULE + options: + target_firewall_nodename: firewall + firewall_port_name: dmz + firewall_port_direction: outbound + position: 2 + permission: 2 + source_ip_id: 3 # dmz_server + dest_ip_id: 2 # client_1 + source_port_id: 4 + dest_port_id: 4 + protocol_id: 3 + 8: + action: FIREWALL_ACL_REMOVERULE + options: + target_firewall_nodename: firewall + firewall_port_name: dmz + firewall_port_direction: outbound + position: 2 + 9: + action: FIREWALL_ACL_ADDRULE + options: + target_firewall_nodename: firewall + firewall_port_name: external + firewall_port_direction: inbound + position: 10 + permission: 2 + source_ip_id: 4 # external_computer + dest_ip_id: 3 # dmz + source_port_id: 5 + dest_port_id: 5 + protocol_id: 2 + 10: + action: FIREWALL_ACL_REMOVERULE + options: + target_firewall_nodename: firewall + firewall_port_name: external + firewall_port_direction: inbound + position: 10 + 11: + action: FIREWALL_ACL_ADDRULE + options: + target_firewall_nodename: firewall + firewall_port_name: external + firewall_port_direction: outbound + position: 1 + permission: 2 + source_ip_id: 4 # external_computer + dest_ip_id: 2 # client_1 + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 + 12: + action: FIREWALL_ACL_REMOVERULE + options: + target_firewall_nodename: firewall + firewall_port_name: external + firewall_port_direction: outbound + position: 1 + options: + nodes: + - node_name: client_1 + - node_name: dmz_server + - node_name: external_computer + ip_address_order: + - node_name: client_1 + nic_num: 1 + - node_name: dmz_server + nic_num: 1 + - node_name: external_computer + nic_num: 1 + max_folders_per_node: 2 + max_files_per_folder: 2 + max_services_per_node: 2 + max_nics_per_node: 8 + max_acl_rules: 10 + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_settings: + start_step: 5 + frequency: 4 + variance: 3 + + + +simulation: + network: + nodes: + - ref: client_1 + type: computer + hostname: client_1 + ip_address: 192.168.0.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.0.1 + dns_server: 192.168.20.11 + start_up_duration: 0 + shut_down_duration: 0 + + - ref: switch_1 + type: switch + hostname: switch_1 + num_ports: 8 + start_up_duration: 0 + shut_down_duration: 0 + + - ref: router_1 + type: router + hostname: router_1 + num_ports: 5 + start_up_duration: 0 + shut_down_duration: 0 + ports: + 1: + ip_address: 192.168.0.1 + subnet_mask: 255.255.255.0 + 2: + ip_address: 192.168.1.1 + subnet_mask: 255.255.255.0 + acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + routes: + - address: 192.168.10.10 # route to dmz_server + subnet_mask: 255.255.255.0 + next_hop_ip_address: 192.168.1.2 + metric: 0 + - address: 192.168.20.10 # route to external_computer + subnet_mask: 255.255.255.0 + next_hop_ip_address: 192.168.1.2 + metric: 0 + - address: 192.168.20.11 # route to external_server + subnet_mask: 255.255.255.0 + next_hop_ip_address: 192.168.1.2 + metric: 0 + + - ref: dmz_server + type: server + hostname: dmz_server + ip_address: 192.168.10.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.20.11 + start_up_duration: 0 + shut_down_duration: 0 + + - ref: switch_2 + type: switch + hostname: switch_2 + num_ports: 8 + start_up_duration: 0 + shut_down_duration: 0 + + - ref: firewall + type: firewall + hostname: firewall + start_up_duration: 0 + shut_down_duration: 0 + ports: + external_port: # port 1 + ip_address: 192.168.20.1 + subnet_mask: 255.255.255.0 + internal_port: # port 2 + ip_address: 192.168.1.2 + subnet_mask: 255.255.255.0 + dmz_port: # port 3 + ip_address: 192.168.10.1 + subnet_mask: 255.255.255.0 + acl: + internal_inbound_acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + internal_outbound_acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + dmz_inbound_acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + dmz_outbound_acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + external_inbound_acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + external_outbound_acl: + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + routes: + - address: 192.168.0.10 # route to client_1 + subnet_mask: 255.255.255.0 + next_hop_ip_address: 192.168.1.1 + metric: 0 + + - ref: switch_3 + type: switch + hostname: switch_3 + num_ports: 8 + start_up_duration: 0 + shut_down_duration: 0 + + - ref: external_computer + type: computer + hostname: external_computer + ip_address: 192.168.20.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.20.1 + dns_server: 192.168.20.11 + start_up_duration: 0 + shut_down_duration: 0 + + - ref: external_server + type: server + hostname: external_server + ip_address: 192.168.20.11 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.20.1 + start_up_duration: 0 + shut_down_duration: 0 + services: + - ref: domain_controller_dns_server + type: DNSServer + links: + - ref: client_1___switch_1 + endpoint_a_ref: client_1 + endpoint_a_port: 1 + endpoint_b_ref: switch_1 + endpoint_b_port: 1 + - ref: router_1___switch_1 + endpoint_a_ref: router_1 + endpoint_a_port: 1 + endpoint_b_ref: switch_1 + endpoint_b_port: 8 + - ref: router_1___firewall + endpoint_a_ref: firewall + endpoint_a_port: 2 # internal firewall port + endpoint_b_ref: router_1 + endpoint_b_port: 2 + - ref: firewall___switch_2 + endpoint_a_ref: firewall + endpoint_a_port: 3 # dmz firewall port + endpoint_b_ref: switch_2 + endpoint_b_port: 8 + - ref: dmz_server___switch_2 + endpoint_a_ref: dmz_server + endpoint_a_port: 1 + endpoint_b_ref: switch_2 + endpoint_b_port: 1 + - ref: firewall___switch_3 + endpoint_a_ref: firewall + endpoint_a_port: 1 # external firewall port + endpoint_b_ref: switch_3 + endpoint_b_port: 8 + - ref: external_computer___switch_3 + endpoint_a_ref: external_computer + endpoint_a_port: 1 + endpoint_b_ref: switch_3 + endpoint_b_port: 1 + - ref: external_server___switch_3 + endpoint_a_ref: external_server + endpoint_a_port: 1 + endpoint_b_ref: switch_3 + endpoint_b_port: 2 diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 7bb8930c..1a8429b7 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -10,16 +10,24 @@ # 4. Check that the simulation has changed in the way that I expect. # 5. Repeat for all actions. +from ipaddress import IPv4Address from typing import Tuple import pytest +import yaml from primaite.game.agent.interface import ProxyAgent from primaite.game.game import PrimaiteGame +from primaite.session.environment import PrimaiteGymEnv from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import ApplicationOperatingState from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.software import SoftwareHealthState +from tests import TEST_ASSETS_ROOT + +FIREWALL_ACTIONS_NETWORK = TEST_ASSETS_ROOT / "configs/firewall_actions_network.yaml" def test_do_nothing_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): @@ -458,3 +466,97 @@ def test_node_application_close_integration(game_and_agent: Tuple[PrimaiteGame, game.step() assert browser.operating_state == ApplicationOperatingState.CLOSED + + +def test_firewall_acl_add_remove_rule_integration(): + """ + Test that FirewallACLAddRuleAction and FirewallACLRemoveRuleAction can form a request and that it is accepted by the simulation. + + Check that all the details of the ACL rules are correctly added to each ACL list of the Firewall. + Check that rules are removed as expected. + """ + with open(FIREWALL_ACTIONS_NETWORK, "r") as f: + cfg = yaml.safe_load(f) + + env = PrimaiteGymEnv(game_config=cfg) + + # 1: Check that traffic is normal and acl starts off with 4 rules. + firewall = env.game.simulation.network.get_node_by_hostname("firewall") + assert firewall.internal_inbound_acl.num_rules == 2 + assert firewall.internal_outbound_acl.num_rules == 2 + assert firewall.dmz_inbound_acl.num_rules == 2 + assert firewall.dmz_outbound_acl.num_rules == 2 + assert firewall.external_inbound_acl.num_rules == 1 + assert firewall.external_outbound_acl.num_rules == 1 + + env.step(1) # Add ACL rule to Internal Inbound + assert firewall.internal_inbound_acl.num_rules == 3 + assert firewall.internal_inbound_acl.acl[1].action.name == "PERMIT" + assert firewall.internal_inbound_acl.acl[1].src_ip_address == IPv4Address("192.168.0.10") + assert firewall.internal_inbound_acl.acl[1].dst_ip_address is None + assert firewall.internal_inbound_acl.acl[1].dst_port is None + assert firewall.internal_inbound_acl.acl[1].src_port is None + assert firewall.internal_inbound_acl.acl[1].protocol is None + + env.step(2) # Remove ACL rule from Internal Inbound + assert firewall.internal_inbound_acl.num_rules == 2 + + env.step(3) # Add ACL rule to Internal Outbound + assert firewall.internal_outbound_acl.num_rules == 3 + assert firewall.internal_outbound_acl.acl[1].action.name == "DENY" + assert firewall.internal_outbound_acl.acl[1].src_ip_address == IPv4Address("192.168.0.10") + assert firewall.internal_outbound_acl.acl[1].dst_ip_address is None + assert firewall.internal_outbound_acl.acl[1].dst_port == Port.DNS + assert firewall.internal_outbound_acl.acl[1].src_port == Port.ARP + assert firewall.internal_outbound_acl.acl[1].protocol == IPProtocol.ICMP + + env.step(4) # Remove ACL rule from Internal Outbound + assert firewall.internal_outbound_acl.num_rules == 2 + + env.step(5) # Add ACL rule to DMZ Inbound + assert firewall.dmz_inbound_acl.num_rules == 3 + assert firewall.dmz_inbound_acl.acl[1].action.name == "DENY" + assert firewall.dmz_inbound_acl.acl[1].src_ip_address == IPv4Address("192.168.10.10") + assert firewall.dmz_inbound_acl.acl[1].dst_ip_address == IPv4Address("192.168.0.10") + assert firewall.dmz_inbound_acl.acl[1].dst_port == Port.HTTP + assert firewall.dmz_inbound_acl.acl[1].src_port == Port.HTTP + assert firewall.dmz_inbound_acl.acl[1].protocol == IPProtocol.UDP + + env.step(6) # Remove ACL rule from DMZ Inbound + assert firewall.dmz_inbound_acl.num_rules == 2 + + env.step(7) # Add ACL rule to DMZ Outbound + assert firewall.dmz_outbound_acl.num_rules == 3 + assert firewall.dmz_outbound_acl.acl[2].action.name == "DENY" + assert firewall.dmz_outbound_acl.acl[2].src_ip_address == IPv4Address("192.168.10.10") + assert firewall.dmz_outbound_acl.acl[2].dst_ip_address == IPv4Address("192.168.0.10") + assert firewall.dmz_outbound_acl.acl[2].dst_port == Port.HTTP + assert firewall.dmz_outbound_acl.acl[2].src_port == Port.HTTP + assert firewall.dmz_outbound_acl.acl[2].protocol == IPProtocol.TCP + + env.step(8) # Remove ACL rule from DMZ Outbound + assert firewall.dmz_outbound_acl.num_rules == 2 + + env.step(9) # Add ACL rule to External Inbound + assert firewall.external_inbound_acl.num_rules == 2 + assert firewall.external_inbound_acl.acl[10].action.name == "DENY" + assert firewall.external_inbound_acl.acl[10].src_ip_address == IPv4Address("192.168.20.10") + assert firewall.external_inbound_acl.acl[10].dst_ip_address == IPv4Address("192.168.10.10") + assert firewall.external_inbound_acl.acl[10].dst_port == Port.POSTGRES_SERVER + assert firewall.external_inbound_acl.acl[10].src_port == Port.POSTGRES_SERVER + assert firewall.external_inbound_acl.acl[10].protocol == IPProtocol.ICMP + + env.step(10) # Remove ACL rule from External Inbound + assert firewall.external_inbound_acl.num_rules == 1 + + env.step(11) # Add ACL rule to External Outbound + assert firewall.external_outbound_acl.num_rules == 2 + assert firewall.external_outbound_acl.acl[1].action.name == "DENY" + assert firewall.external_outbound_acl.acl[1].src_ip_address == IPv4Address("192.168.20.10") + assert firewall.external_outbound_acl.acl[1].dst_ip_address == IPv4Address("192.168.0.10") + assert firewall.external_outbound_acl.acl[1].dst_port is None + assert firewall.external_outbound_acl.acl[1].src_port is None + assert firewall.external_outbound_acl.acl[1].protocol is None + + env.step(12) # Remove ACL rule from External Outbound + assert firewall.external_outbound_acl.num_rules == 1 From d1301002d3017df9901055d108458d6bfd1321be Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Fri, 29 Mar 2024 17:07:08 +0000 Subject: [PATCH 774/980] #2402 run pre-commits --- .../configs/firewall_actions_network.yaml | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/assets/configs/firewall_actions_network.yaml b/tests/assets/configs/firewall_actions_network.yaml index 67c6243d..d4d6f483 100644 --- a/tests/assets/configs/firewall_actions_network.yaml +++ b/tests/assets/configs/firewall_actions_network.yaml @@ -82,7 +82,7 @@ agents: ip_address_order: - node_hostname: client_1 nic_num: 1 - ics: null + ics: null action_space: action_list: - type: DONOTHING @@ -111,7 +111,7 @@ agents: target_firewall_nodename: firewall firewall_port_name: internal firewall_port_direction: inbound - position: 1 + position: 1 3: action: FIREWALL_ACL_ADDRULE options: @@ -124,14 +124,14 @@ agents: dest_ip_id: 1 # ALL source_port_id: 2 dest_port_id: 3 - protocol_id: 2 + protocol_id: 2 4: action: FIREWALL_ACL_REMOVERULE options: target_firewall_nodename: firewall firewall_port_name: internal firewall_port_direction: outbound - position: 1 + position: 1 5: action: FIREWALL_ACL_ADDRULE options: @@ -144,14 +144,14 @@ agents: dest_ip_id: 2 # client_1 source_port_id: 4 dest_port_id: 4 - protocol_id: 4 + protocol_id: 4 6: action: FIREWALL_ACL_REMOVERULE options: target_firewall_nodename: firewall firewall_port_name: dmz firewall_port_direction: inbound - position: 1 + position: 1 7: action: FIREWALL_ACL_ADDRULE options: @@ -164,14 +164,14 @@ agents: dest_ip_id: 2 # client_1 source_port_id: 4 dest_port_id: 4 - protocol_id: 3 + protocol_id: 3 8: action: FIREWALL_ACL_REMOVERULE options: target_firewall_nodename: firewall firewall_port_name: dmz firewall_port_direction: outbound - position: 2 + position: 2 9: action: FIREWALL_ACL_ADDRULE options: @@ -180,7 +180,7 @@ agents: firewall_port_direction: inbound position: 10 permission: 2 - source_ip_id: 4 # external_computer + source_ip_id: 4 # external_computer dest_ip_id: 3 # dmz source_port_id: 5 dest_port_id: 5 @@ -191,7 +191,7 @@ agents: target_firewall_nodename: firewall firewall_port_name: external firewall_port_direction: inbound - position: 10 + position: 10 11: action: FIREWALL_ACL_ADDRULE options: @@ -200,18 +200,18 @@ agents: firewall_port_direction: outbound position: 1 permission: 2 - source_ip_id: 4 # external_computer + source_ip_id: 4 # external_computer dest_ip_id: 2 # client_1 source_port_id: 1 dest_port_id: 1 - protocol_id: 1 + protocol_id: 1 12: action: FIREWALL_ACL_REMOVERULE options: target_firewall_nodename: firewall firewall_port_name: external firewall_port_direction: outbound - position: 1 + position: 1 options: nodes: - node_name: client_1 @@ -223,7 +223,7 @@ agents: - node_name: dmz_server nic_num: 1 - node_name: external_computer - nic_num: 1 + nic_num: 1 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 From 2d1f38bcb7431e6954beb12cb580c70e79a70093 Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Fri, 29 Mar 2024 17:28:40 +0000 Subject: [PATCH 775/980] #2402 fix test --- .../configs/test_application_install.yaml | 56 +++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/tests/assets/configs/test_application_install.yaml b/tests/assets/configs/test_application_install.yaml index c1908fc4..1bf88277 100644 --- a/tests/assets/configs/test_application_install.yaml +++ b/tests/assets/configs/test_application_install.yaml @@ -258,12 +258,8 @@ agents: - type: NODE_SHUTDOWN - type: NODE_STARTUP - type: NODE_RESET - - type: NETWORK_ACL_ADDRULE - options: - target_router_hostname: router_1 - - type: NETWORK_ACL_REMOVERULE - options: - target_router_hostname: router_1 + - type: ROUTER_ACL_ADDRULE + - type: ROUTER_ACL_REMOVERULE - type: NETWORK_NIC_ENABLE - type: NETWORK_NIC_DISABLE - type: NODE_APPLICATION_INSTALL @@ -480,8 +476,9 @@ agents: node_id: 6 46: # old action num: 22 # "ACL: ADDRULE - Block outgoing traffic from client 1" - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_hostname: router_1 position: 1 permission: 2 source_ip_id: 7 # client 1 @@ -490,8 +487,9 @@ agents: dest_port_id: 1 protocol_id: 1 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_hostname: router_1 position: 2 permission: 2 source_ip_id: 8 # client 2 @@ -500,8 +498,9 @@ agents: dest_port_id: 1 protocol_id: 1 48: # old action num: 24 # block tcp traffic from client 1 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_hostname: router_1 position: 3 permission: 2 source_ip_id: 7 # client 1 @@ -510,8 +509,9 @@ agents: dest_port_id: 1 protocol_id: 3 49: # old action num: 25 # block tcp traffic from client 2 to web app - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_hostname: router_1 position: 4 permission: 2 source_ip_id: 8 # client 2 @@ -520,8 +520,9 @@ agents: dest_port_id: 1 protocol_id: 3 50: # old action num: 26 - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_hostname: router_1 position: 5 permission: 2 source_ip_id: 7 # client 1 @@ -530,8 +531,9 @@ agents: dest_port_id: 1 protocol_id: 3 51: # old action num: 27 - action: "NETWORK_ACL_ADDRULE" + action: "ROUTER_ACL_ADDRULE" options: + target_router_hostname: router_1 position: 6 permission: 2 source_ip_id: 8 # client 2 @@ -540,44 +542,54 @@ agents: dest_port_id: 1 protocol_id: 3 52: # old action num: 28 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_hostname: router_1 position: 0 53: # old action num: 29 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_hostname: router_1 position: 1 54: # old action num: 30 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_hostname: router_1 position: 2 55: # old action num: 31 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_hostname: router_1 position: 3 56: # old action num: 32 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_hostname: router_1 position: 4 57: # old action num: 33 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_hostname: router_1 position: 5 58: # old action num: 34 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_hostname: router_1 position: 6 59: # old action num: 35 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_hostname: router_1 position: 7 60: # old action num: 36 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_hostname: router_1 position: 8 61: # old action num: 37 - action: "NETWORK_ACL_REMOVERULE" + action: "ROUTER_ACL_REMOVERULE" options: + target_router_hostname: router_1 position: 9 62: # old action num: 38 action: "NETWORK_NIC_DISABLE" From 2546f268ebba717122439ae6e6326574f8704ece Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Sun, 31 Mar 2024 11:59:31 +0000 Subject: [PATCH 776/980] #2402 refactor port actions to take same input params (hostname) as new acl actions for routers and firewalls --- .../_package_data/data_manipulation.yaml | 36 +++++----- .../_package_data/data_manipulation_marl.yaml | 72 +++++++++---------- src/primaite/game/agent/actions.py | 65 ++++++++--------- .../assets/configs/bad_primaite_session.yaml | 36 +++++----- .../configs/eval_only_primaite_session.yaml | 36 +++++----- .../configs/firewall_actions_network.yaml | 12 ++++ tests/assets/configs/multi_agent_session.yaml | 72 +++++++++---------- tests/assets/configs/shared_rewards.yaml | 36 +++++----- .../configs/test_application_install.yaml | 36 +++++----- .../assets/configs/test_primaite_session.yaml | 36 +++++----- .../configs/train_only_primaite_session.yaml | 36 +++++----- tests/conftest.py | 4 +- .../game_layer/test_actions.py | 39 +++++++--- 13 files changed, 269 insertions(+), 247 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index ad3c02cc..2ec5614a 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -260,8 +260,8 @@ agents: - type: NODE_RESET - type: ROUTER_ACL_ADDRULE - type: ROUTER_ACL_REMOVERULE - - type: NETWORK_NIC_ENABLE - - type: NETWORK_NIC_DISABLE + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE action_map: 0: @@ -589,82 +589,82 @@ agents: target_router_nodename: router_1 position: 9 62: # old action num: 38 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 0 nic_id: 0 63: # old action num: 39 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 0 nic_id: 0 64: # old action num: 40 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 1 nic_id: 0 65: # old action num: 41 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 1 nic_id: 0 66: # old action num: 42 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 2 nic_id: 0 67: # old action num: 43 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 2 nic_id: 0 68: # old action num: 44 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 3 nic_id: 0 69: # old action num: 45 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 3 nic_id: 0 70: # old action num: 46 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 0 71: # old action num: 47 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 0 72: # old action num: 48 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 1 73: # old action num: 49 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 1 74: # old action num: 50 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 5 nic_id: 0 75: # old action num: 51 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 5 nic_id: 0 76: # old action num: 52 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 6 nic_id: 0 77: # old action num: 53 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 6 nic_id: 0 diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index 2a788b73..276441a4 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -262,8 +262,8 @@ agents: - type: NODE_RESET - type: ROUTER_ACL_ADDRULE - type: ROUTER_ACL_REMOVERULE - - type: NETWORK_NIC_ENABLE - - type: NETWORK_NIC_DISABLE + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE action_map: 0: @@ -591,82 +591,82 @@ agents: target_router_nodename: router_1 position: 9 62: # old action num: 38 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 0 nic_id: 0 63: # old action num: 39 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 0 nic_id: 0 64: # old action num: 40 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 1 nic_id: 0 65: # old action num: 41 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 1 nic_id: 0 66: # old action num: 42 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 2 nic_id: 0 67: # old action num: 43 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 2 nic_id: 0 68: # old action num: 44 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 3 nic_id: 0 69: # old action num: 45 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 3 nic_id: 0 70: # old action num: 46 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 0 71: # old action num: 47 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 0 72: # old action num: 48 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 1 73: # old action num: 49 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 1 74: # old action num: 50 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 5 nic_id: 0 75: # old action num: 51 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 5 nic_id: 0 76: # old action num: 52 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 6 nic_id: 0 77: # old action num: 53 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 6 nic_id: 0 @@ -829,8 +829,8 @@ agents: - type: ROUTER_ACL_REMOVERULE options: target_router_nodename: router_1 - - type: NETWORK_NIC_ENABLE - - type: NETWORK_NIC_DISABLE + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE action_map: 0: @@ -1158,82 +1158,82 @@ agents: target_router_nodename: router_1 position: 9 62: # old action num: 38 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 0 nic_id: 0 63: # old action num: 39 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 0 nic_id: 0 64: # old action num: 40 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 1 nic_id: 0 65: # old action num: 41 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 1 nic_id: 0 66: # old action num: 42 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 2 nic_id: 0 67: # old action num: 43 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 2 nic_id: 0 68: # old action num: 44 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 3 nic_id: 0 69: # old action num: 45 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 3 nic_id: 0 70: # old action num: 46 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 0 71: # old action num: 47 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 0 72: # old action num: 48 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 1 73: # old action num: 49 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 1 74: # old action num: 50 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 5 nic_id: 0 75: # old action num: 51 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 5 nic_id: 0 76: # old action num: 52 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 6 nic_id: 0 77: # old action num: 53 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 6 nic_id: 0 diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 0dfdcfb8..090e8481 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -729,7 +729,7 @@ class FirewallACLRemoveRuleAction(AbstractAction): ] -class NetworkNICAbstractAction(AbstractAction): +class HostNICAbstractAction(AbstractAction): """ Abstract base class for NIC actions. @@ -738,7 +738,7 @@ class NetworkNICAbstractAction(AbstractAction): """ def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: - """Init method for NetworkNICAbstractAction. + """Init method for HostNICAbstractAction. :param manager: Reference to the ActionManager which created this action. :type manager: ActionManager @@ -760,7 +760,7 @@ class NetworkNICAbstractAction(AbstractAction): return ["network", "node", node_name, "network_interface", nic_num, self.verb] -class NetworkNICEnableAction(NetworkNICAbstractAction): +class HostNICEnableAction(HostNICAbstractAction): """Action which enables a NIC.""" def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: @@ -768,7 +768,7 @@ class NetworkNICEnableAction(NetworkNICAbstractAction): self.verb: str = "enable" -class NetworkNICDisableAction(NetworkNICAbstractAction): +class HostNICDisableAction(HostNICAbstractAction): """Action which disables a NIC.""" def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: @@ -776,51 +776,42 @@ class NetworkNICDisableAction(NetworkNICAbstractAction): self.verb: str = "disable" -class NetworkPortAbstractAction(AbstractAction): - """ - Abstract base class for Port actions. +class NetworkPortEnableAction(AbstractAction): + """Action which enables are port on a router or a firewall.""" - Any action which applies to a Router/Firewall and uses node_id and port_id as its only two parameters - can inherit from this base class. - """ + def __init__(self, manager: "ActionManager", max_nics_per_node: int, **kwargs) -> None: + """Init method for NetworkPortEnableAction. - def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: - """Init method for NetworkNICAbstractAction. - - :param manager: Reference to the ActionManager which created this action. - :type manager: ActionManager - :param num_nodes: Number of nodes in the simulation. - :type num_nodes: int :param max_nics_per_node: Maximum number of NICs per node. :type max_nics_per_node: int """ super().__init__(manager=manager) - self.shape: Dict[str, int] = {"node_id": num_nodes, "port_id": max_nics_per_node} - self.verb: str # define but don't initialise: defends against children classes not defining this + self.shape: Dict[str, int] = {"port_id": max_nics_per_node} - def form_request(self, node_id: int, port_id: int) -> List[str]: + def form_request(self, target_nodename: str, port_id: int) -> List[str]: """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" - node_name = self.manager.get_node_name_by_idx(node_idx=node_id) - port_num = self.manager.get_nic_num_by_idx(node_idx=node_id, nic_idx=port_id) - if node_name is None or port_num is None: + if target_nodename is None or port_id is None: return ["do_nothing"] - return ["network", "node", node_name, "network_interface", port_num, self.verb] + return ["network", "node", target_nodename, "network_interface", port_id, "enable"] -class NetworkPortEnableAction(NetworkPortAbstractAction): - """Action which enables a PORT.""" +class NetworkPortDisableAction(AbstractAction): + """Action which disables are port on a router or a firewall.""" - def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: - super().__init__(manager=manager, num_nodes=num_nodes, max_nics_per_node=max_nics_per_node, **kwargs) - self.verb: str = "enable" + def __init__(self, manager: "ActionManager", max_nics_per_node: int, **kwargs) -> None: + """Init method for NetworkPortDisableAction. + :param max_nics_per_node: Maximum number of NICs per node. + :type max_nics_per_node: int + """ + super().__init__(manager=manager) + self.shape: Dict[str, int] = {"port_id": max_nics_per_node} -class NetworkPortDisableAction(NetworkPortAbstractAction): - """Action which disables a PORT.""" - - def __init__(self, manager: "ActionManager", num_nodes: int, max_nics_per_node: int, **kwargs) -> None: - super().__init__(manager=manager, num_nodes=num_nodes, max_nics_per_node=max_nics_per_node, **kwargs) - self.verb: str = "disable" + def form_request(self, target_nodename: str, port_id: int) -> List[str]: + """Return the action formatted as a request which can be ingested by the PrimAITE simulation.""" + if target_nodename is None or port_id is None: + return ["do_nothing"] + return ["network", "node", target_nodename, "network_interface", port_id, "disable"] class ActionManager: @@ -861,8 +852,8 @@ class ActionManager: "ROUTER_ACL_REMOVERULE": RouterACLRemoveRuleAction, "FIREWALL_ACL_ADDRULE": FirewallACLAddRuleAction, "FIREWALL_ACL_REMOVERULE": FirewallACLRemoveRuleAction, - "NETWORK_NIC_ENABLE": NetworkNICEnableAction, - "NETWORK_NIC_DISABLE": NetworkNICDisableAction, + "HOST_NIC_ENABLE": HostNICEnableAction, + "HOST_NIC_DISABLE": HostNICDisableAction, "NETWORK_PORT_ENABLE": NetworkPortEnableAction, "NETWORK_PORT_DISABLE": NetworkPortDisableAction, } diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 743d2bba..0f0ca46e 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -171,8 +171,8 @@ agents: - type: NODE_RESET - type: ROUTER_ACL_ADDRULE - type: ROUTER_ACL_REMOVERULE - - type: NETWORK_NIC_ENABLE - - type: NETWORK_NIC_DISABLE + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE action_map: 0: @@ -403,82 +403,82 @@ agents: target_router_nodename: router_1 position: 9 38: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 0 nic_id: 0 39: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 0 nic_id: 0 40: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 1 nic_id: 0 41: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 1 nic_id: 0 42: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 2 nic_id: 0 43: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 2 nic_id: 0 44: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 3 nic_id: 0 45: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 3 nic_id: 0 46: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 0 47: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 0 48: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 1 49: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 1 50: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 5 nic_id: 0 51: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 5 nic_id: 0 52: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 6 nic_id: 0 53: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 6 nic_id: 0 diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index 525f7bb0..a5c3cd1c 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -175,8 +175,8 @@ agents: - type: NODE_RESET - type: ROUTER_ACL_ADDRULE - type: ROUTER_ACL_REMOVERULE - - type: NETWORK_NIC_ENABLE - - type: NETWORK_NIC_DISABLE + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE action_map: 0: @@ -407,82 +407,82 @@ agents: target_router_nodename: router_1 position: 9 38: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 0 nic_id: 0 39: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 0 nic_id: 0 40: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 1 nic_id: 0 41: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 1 nic_id: 0 42: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 2 nic_id: 0 43: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 2 nic_id: 0 44: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 3 nic_id: 0 45: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 3 nic_id: 0 46: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 0 47: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 0 48: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 1 49: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 1 50: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 5 nic_id: 0 51: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 5 nic_id: 0 52: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 6 nic_id: 0 53: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 6 nic_id: 0 diff --git a/tests/assets/configs/firewall_actions_network.yaml b/tests/assets/configs/firewall_actions_network.yaml index d4d6f483..b7848c53 100644 --- a/tests/assets/configs/firewall_actions_network.yaml +++ b/tests/assets/configs/firewall_actions_network.yaml @@ -88,6 +88,8 @@ agents: - type: DONOTHING - type: FIREWALL_ACL_ADDRULE - type: FIREWALL_ACL_REMOVERULE + - type: NETWORK_PORT_DISABLE + - type: NETWORK_PORT_ENABLE action_map: 0: action: DONOTHING @@ -212,6 +214,16 @@ agents: firewall_port_name: external firewall_port_direction: outbound position: 1 + 13: + action: NETWORK_PORT_DISABLE + options: + target_nodename: firewall + port_id: 3 + 14: + action: NETWORK_PORT_ENABLE + options: + target_nodename: firewall + port_id: 3 options: nodes: - node_name: client_1 diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 77a17459..af32a527 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -182,8 +182,8 @@ agents: - type: NODE_RESET - type: ROUTER_ACL_ADDRULE - type: ROUTER_ACL_REMOVERULE - - type: NETWORK_NIC_ENABLE - - type: NETWORK_NIC_DISABLE + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE action_map: 0: @@ -414,82 +414,82 @@ agents: target_router_nodename: router_1 position: 9 38: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 0 nic_id: 0 39: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 0 nic_id: 0 40: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 1 nic_id: 0 41: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 1 nic_id: 0 42: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 2 nic_id: 0 43: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 2 nic_id: 0 44: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 3 nic_id: 0 45: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 3 nic_id: 0 46: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 0 47: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 0 48: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 1 49: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 1 50: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 5 nic_id: 0 51: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 5 nic_id: 0 52: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 6 nic_id: 0 53: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 6 nic_id: 0 @@ -638,8 +638,8 @@ agents: - type: NODE_RESET - type: ROUTER_ACL_ADDRULE - type: ROUTER_ACL_REMOVERULE - - type: NETWORK_NIC_ENABLE - - type: NETWORK_NIC_DISABLE + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE action_map: 0: @@ -870,82 +870,82 @@ agents: target_router_nodename: router_1 position: 9 38: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 0 nic_id: 0 39: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 0 nic_id: 0 40: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 1 nic_id: 0 41: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 1 nic_id: 0 42: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 2 nic_id: 0 43: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 2 nic_id: 0 44: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 3 nic_id: 0 45: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 3 nic_id: 0 46: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 0 47: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 0 48: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 1 49: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 1 50: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 5 nic_id: 0 51: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 5 nic_id: 0 52: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 6 nic_id: 0 53: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 6 nic_id: 0 diff --git a/tests/assets/configs/shared_rewards.yaml b/tests/assets/configs/shared_rewards.yaml index e7226b5f..d283a7f1 100644 --- a/tests/assets/configs/shared_rewards.yaml +++ b/tests/assets/configs/shared_rewards.yaml @@ -260,8 +260,8 @@ agents: - type: NODE_RESET - type: ROUTER_ACL_ADDRULE - type: ROUTER_ACL_REMOVERULE - - type: NETWORK_NIC_ENABLE - - type: NETWORK_NIC_DISABLE + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE action_map: 0: @@ -589,82 +589,82 @@ agents: target_router_nodename: router_1 position: 9 62: # old action num: 38 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 0 nic_id: 0 63: # old action num: 39 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 0 nic_id: 0 64: # old action num: 40 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 1 nic_id: 0 65: # old action num: 41 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 1 nic_id: 0 66: # old action num: 42 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 2 nic_id: 0 67: # old action num: 43 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 2 nic_id: 0 68: # old action num: 44 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 3 nic_id: 0 69: # old action num: 45 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 3 nic_id: 0 70: # old action num: 46 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 0 71: # old action num: 47 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 0 72: # old action num: 48 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 1 73: # old action num: 49 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 1 74: # old action num: 50 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 5 nic_id: 0 75: # old action num: 51 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 5 nic_id: 0 76: # old action num: 52 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 6 nic_id: 0 77: # old action num: 53 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 6 nic_id: 0 diff --git a/tests/assets/configs/test_application_install.yaml b/tests/assets/configs/test_application_install.yaml index 1bf88277..b3fca4bc 100644 --- a/tests/assets/configs/test_application_install.yaml +++ b/tests/assets/configs/test_application_install.yaml @@ -260,8 +260,8 @@ agents: - type: NODE_RESET - type: ROUTER_ACL_ADDRULE - type: ROUTER_ACL_REMOVERULE - - type: NETWORK_NIC_ENABLE - - type: NETWORK_NIC_DISABLE + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE - type: NODE_APPLICATION_INSTALL - type: NODE_APPLICATION_REMOVE - type: NODE_APPLICATION_EXECUTE @@ -592,82 +592,82 @@ agents: target_router_hostname: router_1 position: 9 62: # old action num: 38 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 0 nic_id: 0 63: # old action num: 39 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 0 nic_id: 0 64: # old action num: 40 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 1 nic_id: 0 65: # old action num: 41 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 1 nic_id: 0 66: # old action num: 42 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 2 nic_id: 0 67: # old action num: 43 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 2 nic_id: 0 68: # old action num: 44 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 3 nic_id: 0 69: # old action num: 45 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 3 nic_id: 0 70: # old action num: 46 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 0 71: # old action num: 47 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 0 72: # old action num: 48 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 1 73: # old action num: 49 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 1 74: # old action num: 50 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 5 nic_id: 0 75: # old action num: 51 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 5 nic_id: 0 76: # old action num: 52 - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 6 nic_id: 0 77: # old action num: 53 - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 6 nic_id: 0 diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 0cb371d5..bcd86781 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -185,8 +185,8 @@ agents: - type: NODE_RESET - type: ROUTER_ACL_ADDRULE - type: ROUTER_ACL_REMOVERULE - - type: NETWORK_NIC_ENABLE - - type: NETWORK_NIC_DISABLE + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE action_map: 0: @@ -417,82 +417,82 @@ agents: target_router_nodename: router_1 position: 9 38: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 0 nic_id: 0 39: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 0 nic_id: 0 40: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 1 nic_id: 0 41: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 1 nic_id: 0 42: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 2 nic_id: 0 43: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 2 nic_id: 0 44: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 3 nic_id: 0 45: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 3 nic_id: 0 46: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 0 47: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 0 48: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 1 49: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 1 50: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 5 nic_id: 0 51: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 5 nic_id: 0 52: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 6 nic_id: 0 53: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 6 nic_id: 0 diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index 619b7a23..70b33caa 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -183,8 +183,8 @@ agents: - type: NODE_RESET - type: ROUTER_ACL_ADDRULE - type: ROUTER_ACL_REMOVERULE - - type: NETWORK_NIC_ENABLE - - type: NETWORK_NIC_DISABLE + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE action_map: 0: @@ -415,82 +415,82 @@ agents: target_router_nodename: router_1 position: 9 38: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 0 nic_id: 0 39: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 0 nic_id: 0 40: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 1 nic_id: 0 41: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 1 nic_id: 0 42: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 2 nic_id: 0 43: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 2 nic_id: 0 44: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 3 nic_id: 0 45: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 3 nic_id: 0 46: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 0 47: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 0 48: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 4 nic_id: 1 49: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 4 nic_id: 1 50: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 5 nic_id: 0 51: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 5 nic_id: 0 52: - action: "NETWORK_NIC_DISABLE" + action: "HOST_NIC_DISABLE" options: node_id: 6 nic_id: 0 53: - action: "NETWORK_NIC_ENABLE" + action: "HOST_NIC_ENABLE" options: node_id: 6 nic_id: 0 diff --git a/tests/conftest.py b/tests/conftest.py index d040f775..c6473ef5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -498,8 +498,8 @@ def game_and_agent(): {"type": "NODE_RESET"}, {"type": "ROUTER_ACL_ADDRULE"}, {"type": "ROUTER_ACL_REMOVERULE"}, - {"type": "NETWORK_NIC_ENABLE"}, - {"type": "NETWORK_NIC_DISABLE"}, + {"type": "HOST_NIC_ENABLE"}, + {"type": "HOST_NIC_DISABLE"}, {"type": "NETWORK_PORT_ENABLE"}, {"type": "NETWORK_PORT_DISABLE"}, ] diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index b66294fb..3ebce6ad 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -198,8 +198,8 @@ def test_router_acl_removerule_integration(game_and_agent: Tuple[PrimaiteGame, P assert client_1.ping("10.0.2.3") -def test_network_nic_disable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): - """Test that the NetworkNICDisableAction can form a request and that it is accepted by the simulation.""" +def test_host_nic_disable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the HostNICDisableAction can form a request and that it is accepted by the simulation.""" game, agent = game_and_agent # 1: Check that client_1 can access the network @@ -214,7 +214,7 @@ def test_network_nic_disable_integration(game_and_agent: Tuple[PrimaiteGame, Pro # 2: Disable the NIC on client_1 action = ( - "NETWORK_NIC_DISABLE", + "HOST_NIC_DISABLE", { "node_id": 0, # client_1 "nic_id": 0, # the only nic (eth-1) @@ -233,8 +233,8 @@ def test_network_nic_disable_integration(game_and_agent: Tuple[PrimaiteGame, Pro assert server_1.ping("10.0.2.3") -def test_network_nic_enable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): - """Test that the NetworkNICEnableAction can form a request and that it is accepted by the simulation.""" +def test_host_nic_enable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the HostNICEnableAction can form a request and that it is accepted by the simulation.""" game, agent = game_and_agent @@ -245,7 +245,7 @@ def test_network_nic_enable_integration(game_and_agent: Tuple[PrimaiteGame, Prox # 2: Use action to enable nic action = ( - "NETWORK_NIC_ENABLE", + "HOST_NIC_ENABLE", { "node_id": 0, # client_1 "nic_id": 0, # the only nic (eth-1) @@ -343,8 +343,8 @@ def test_network_router_port_disable_integration(game_and_agent: Tuple[PrimaiteG action = ( "NETWORK_PORT_DISABLE", { - "node_id": 3, # router - "port_id": 0, # port 1 + "target_nodename": "router", # router + "port_id": 1, # port 1 }, ) agent.store_action(action) @@ -375,8 +375,8 @@ def test_network_router_port_enable_integration(game_and_agent: Tuple[PrimaiteGa action = ( "NETWORK_PORT_ENABLE", { - "node_id": 3, # router - "port_id": 0, # port 1 + "target_nodename": "router", # router + "port_id": 1, # port 1 }, ) agent.store_action(action) @@ -585,3 +585,22 @@ def test_firewall_acl_add_remove_rule_integration(): env.step(12) # Remove ACL rule from External Outbound assert firewall.external_outbound_acl.num_rules == 1 + + +def test_firewall_port_disable_enable_integration(): + """ + Test that NetworkPortEnableAction and NetworkPortDisableAction can form a request and that it is accepted by the simulation. + """ + with open(FIREWALL_ACTIONS_NETWORK, "r") as f: + cfg = yaml.safe_load(f) + + env = PrimaiteGymEnv(game_config=cfg) + firewall = env.game.simulation.network.get_node_by_hostname("firewall") + + assert firewall.dmz_port.enabled == True + + env.step(13) # Disable Firewall DMZ Port + assert firewall.dmz_port.enabled == False + + env.step(14) # Enable Firewall DMZ Port + assert firewall.dmz_port.enabled == True From 15cb2e6970a184c83c6d56c01ad3ae3f26660b1e Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 31 Mar 2024 17:31:10 +0100 Subject: [PATCH 777/980] #2417 Add NestedObservation --- .../agent/observations/acl_observation.py | 2 +- .../observations/file_system_observations.py | 4 +- .../observations/firewall_observation.py | 2 +- .../agent/observations/host_observations.py | 2 +- .../agent/observations/nic_observations.py | 4 +- .../agent/observations/node_observations.py | 2 +- .../agent/observations/observation_manager.py | 136 ++++++++++++++++-- .../game/agent/observations/observations.py | 11 +- .../agent/observations/router_observation.py | 2 +- .../observations/software_observation.py | 2 +- 10 files changed, 140 insertions(+), 27 deletions(-) diff --git a/src/primaite/game/agent/observations/acl_observation.py b/src/primaite/game/agent/observations/acl_observation.py index 2d29223d..7601e678 100644 --- a/src/primaite/game/agent/observations/acl_observation.py +++ b/src/primaite/game/agent/observations/acl_observation.py @@ -40,7 +40,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): protocol_list: List[str], ) -> None: """ - Initialize an ACL observation instance. + Initialise an ACL observation instance. :param where: Where in the simulation state dictionary to find the relevant information for this ACL. :type where: WhereType diff --git a/src/primaite/game/agent/observations/file_system_observations.py b/src/primaite/game/agent/observations/file_system_observations.py index a30bfc82..3c931bc8 100644 --- a/src/primaite/game/agent/observations/file_system_observations.py +++ b/src/primaite/game/agent/observations/file_system_observations.py @@ -25,7 +25,7 @@ class FileObservation(AbstractObservation, identifier="FILE"): def __init__(self, where: WhereType, include_num_access: bool) -> None: """ - Initialize a file observation instance. + Initialise a file observation instance. :param where: Where in the simulation state dictionary to find the relevant information for this file. A typical location for a file might be @@ -107,7 +107,7 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): self, where: WhereType, files: Iterable[FileObservation], num_files: int, include_num_access: bool ) -> None: """ - Initialize a folder observation instance. + Initialise a folder observation instance. :param where: Where in the simulation state dictionary to find the relevant information for this folder. A typical location for a folder might be ['network', 'nodes', , 'folders', ]. diff --git a/src/primaite/game/agent/observations/firewall_observation.py b/src/primaite/game/agent/observations/firewall_observation.py index 6397d473..376e4824 100644 --- a/src/primaite/game/agent/observations/firewall_observation.py +++ b/src/primaite/game/agent/observations/firewall_observation.py @@ -42,7 +42,7 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): num_rules: int, ) -> None: """ - Initialize a firewall observation instance. + Initialise a firewall observation instance. :param where: Where in the simulation state dictionary to find the relevant information for this firewall. A typical location for a firewall might be ['network', 'nodes', ]. diff --git a/src/primaite/game/agent/observations/host_observations.py b/src/primaite/game/agent/observations/host_observations.py index 34c9b3ff..9146979a 100644 --- a/src/primaite/game/agent/observations/host_observations.py +++ b/src/primaite/game/agent/observations/host_observations.py @@ -62,7 +62,7 @@ class HostObservation(AbstractObservation, identifier="HOST"): include_num_access: bool, ) -> None: """ - Initialize a host observation instance. + Initialise a host observation instance. :param where: Where in the simulation state dictionary to find the relevant information for this host. A typical location for a host might be ['network', 'nodes', ]. diff --git a/src/primaite/game/agent/observations/nic_observations.py b/src/primaite/game/agent/observations/nic_observations.py index 3be53112..ff2731ff 100644 --- a/src/primaite/game/agent/observations/nic_observations.py +++ b/src/primaite/game/agent/observations/nic_observations.py @@ -22,7 +22,7 @@ class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): def __init__(self, where: WhereType, include_nmne: bool) -> None: """ - Initialize a network interface observation instance. + Initialise a network interface observation instance. :param where: Where in the simulation state dictionary to find the relevant information for this interface. A typical location for a network interface might be @@ -108,7 +108,7 @@ class PortObservation(AbstractObservation, identifier="PORT"): def __init__(self, where: WhereType) -> None: """ - Initialize a port observation instance. + Initialise a port observation instance. :param where: Where in the simulation state dictionary to find the relevant information for this port. A typical location for a port might be ['network', 'nodes', , 'NICs', ]. diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index 0e63f440..3f384ece 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -61,7 +61,7 @@ class NodesObservation(AbstractObservation, identifier="NODES"): firewalls: List[FirewallObservation], ) -> None: """ - Initialize a nodes observation instance. + Initialise a nodes observation instance. :param where: Where in the simulation state dictionary to find the relevant information for nodes. A typical location for nodes might be ['network', 'nodes']. diff --git a/src/primaite/game/agent/observations/observation_manager.py b/src/primaite/game/agent/observations/observation_manager.py index be90041e..a6981ddc 100644 --- a/src/primaite/game/agent/observations/observation_manager.py +++ b/src/primaite/game/agent/observations/observation_manager.py @@ -1,6 +1,10 @@ -from typing import Dict, TYPE_CHECKING +from __future__ import annotations +from typing import Any, Dict, List, TYPE_CHECKING + +from gymnasium import spaces from gymnasium.core import ObsType +from pydantic import BaseModel, ConfigDict, model_validator, ValidationError from primaite.game.agent.observations.observations import AbstractObservation @@ -8,6 +12,114 @@ if TYPE_CHECKING: from primaite.game.game import PrimaiteGame +class NestedObservation(AbstractObservation, identifier="CUSTOM"): + """Observation type that allows combining other observations into a gymnasium.spaces.Dict space.""" + + class NestedObservationItem(BaseModel): + """One list item of the config.""" + + model_config = ConfigDict(extra="forbid") + type: str + """Select observation class. It maps to the identifier of the obs class by checking the registry.""" + label: str + """Dict key in the final observation space.""" + options: Dict + """Options to pass to the observation class from_config method.""" + + @model_validator(mode="after") + def check_model(self) -> "NestedObservation.NestedObservationItem": + """Make sure tha the config options match up with the selected observation type.""" + obs_subclass_name = self.type + obs_options = self.options + if obs_subclass_name not in AbstractObservation._registry: + raise ValueError(f"Observation of type {obs_subclass_name} could not be found.") + obs_schema = AbstractObservation._registry[obs_subclass_name].ConfigSchema + try: + obs_schema(**obs_options) + except ValidationError as e: + raise ValueError(f"Observation options did not match schema, got this error: {e}") + return self + + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for NestedObservation.""" + + components: List[NestedObservation.NestedObservationItem] + """List of observation components to be part of this space.""" + + def __init__(self, components: Dict[str, AbstractObservation]) -> None: + """Initialise nested observation.""" + self.components: Dict[str, AbstractObservation] = components + """Maps label: observation object""" + + self.default_observation = {label: obs.default_observation for label, obs in self.components.items()} + """Default observation is just the default observations of constituents.""" + + def observe(self, state: Dict) -> Any: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing the status information about the host. + :rtype: ObsType + """ + return {label: obs.observe(state) for label, obs in self.components.items()} + + @property + def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the nested observation space. + :rtype: spaces.Space + """ + return spaces.Dict({label: obs.space for label, obs in self.components.items()}) + + @classmethod + def from_config(cls, config: ConfigSchema) -> NestedObservation: + """ + Read the Nested observation config and create all defined subcomponents. + + Example configuration that utilises NestedObservation: + This lets us have different options for different types of hosts. + + ```yaml + observation_space: + - type: CUSTOM + options: + components: + + - type: HOSTS + label: COMPUTERS # What is the dictionary key called + options: + hosts: + - client_1 + - client_2 + num_services: 0 + num_applications: 5 + ... # other options + + - type: HOSTS + label: SERVERS # What is the dictionary key called + options: + hosts: + - hostname: database_server + - hostname: web_server + num_services: 4 + num_applications: 0 + num_folders: 2 + num_files: 2 + + ``` + """ + instances = dict() + for component in config.components: + obs_class = AbstractObservation._registry[component.type] + obs_instance = obs_class.from_config(obs_class.ConfigSchema(**component.options)) + instances[component.label] = obs_instance + return cls(components=instances) + + class ObservationManager: """ Manage the observations of an Agent. @@ -18,18 +130,15 @@ class ObservationManager: 3. Formatting this information so an agent can use it to make decisions. """ - # TODO: Dear code reader: This class currently doesn't do much except hold an observation object. It will be changed - # to have more of it's own behaviour, and it will replace UC2BlueObservation and UC2RedObservation during the next - # refactor. - - def __init__(self, observation: AbstractObservation) -> None: + def __init__(self, obs: AbstractObservation) -> None: """Initialise observation space. :param observation: Observation object :type observation: AbstractObservation """ - self.obs: AbstractObservation = observation + self.obs: AbstractObservation = obs self.current_observation: ObsType + """Cached copy of the observation at the time it was most recently calculated.""" def update(self, state: Dict) -> Dict: """ @@ -48,7 +157,8 @@ class ObservationManager: @classmethod def from_config(cls, config: Dict, game: "PrimaiteGame") -> "ObservationManager": - """Create observation space from a config. + """ + Create observation space from a config. :param config: Dictionary containing the configuration for this observation space. It should contain the key 'type' which selects which observation class to use (from a choice of: @@ -58,10 +168,8 @@ class ObservationManager: :param game: Reference to the PrimaiteGame object that spawned this observation. :type game: PrimaiteGame """ - - for obs_cfg in config: - obs_type = obs_cfg['type'] - obs_class = AbstractObservation._registry[obs_type] - observation = obs_class.from_config(obs_class.ConfigSchema(**obs_cfg['options'])) + obs_type = config["type"] + obs_class = AbstractObservation._registry[obs_type] + observation = obs_class.from_config(obs_class.ConfigSchema(**config["options"])) obs_manager = cls(observation) - return obs_manager \ No newline at end of file + return obs_manager diff --git a/src/primaite/game/agent/observations/observations.py b/src/primaite/game/agent/observations/observations.py index 08871072..feddc3ed 100644 --- a/src/primaite/game/agent/observations/observations.py +++ b/src/primaite/game/agent/observations/observations.py @@ -3,6 +3,7 @@ from abc import ABC, abstractmethod from typing import Any, Dict, Iterable, Type from gymnasium import spaces +from gymnasium.core import ObsType from pydantic import BaseModel, ConfigDict from primaite import getLogger @@ -26,6 +27,10 @@ class AbstractObservation(ABC): Automatically populated when subclasses are defined. Used for defining from_config. """ + def __init__(self) -> None: + """Initialise an observation. This method must be overwritten.""" + self.default_observation: ObsType + def __init_subclass__(cls, identifier: str, **kwargs: Any) -> None: """ Register an observation type. @@ -58,10 +63,10 @@ class AbstractObservation(ABC): pass @classmethod - def from_config(cls, cfg: Dict) -> "AbstractObservation": + @abstractmethod + def from_config(cls, config: ConfigSchema) -> "AbstractObservation": """Create this observation space component form a serialised format.""" - ObservationType = cls._registry[cfg["type"]] - return ObservationType.from_config(cfg=cfg) + return cls() ''' diff --git a/src/primaite/game/agent/observations/router_observation.py b/src/primaite/game/agent/observations/router_observation.py index b8dee2c2..97d8ab41 100644 --- a/src/primaite/game/agent/observations/router_observation.py +++ b/src/primaite/game/agent/observations/router_observation.py @@ -47,7 +47,7 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): acl: ACLObservation, ) -> None: """ - Initialize a router observation instance. + Initialise a router observation instance. :param where: Where in the simulation state dictionary to find the relevant information for this router. A typical location for a router might be ['network', 'nodes', ]. diff --git a/src/primaite/game/agent/observations/software_observation.py b/src/primaite/game/agent/observations/software_observation.py index eb94651d..0c031345 100644 --- a/src/primaite/game/agent/observations/software_observation.py +++ b/src/primaite/game/agent/observations/software_observation.py @@ -20,7 +20,7 @@ class ServiceObservation(AbstractObservation, identifier="SERVICE"): def __init__(self, where: WhereType) -> None: """ - Initialize a service observation instance. + Initialise a service observation instance. :param where: Where in the simulation state dictionary to find the relevant information for this service. A typical location for a service might be ['network', 'nodes', , 'services', ]. From 62ebca8c08e9966cb52d29d01e5a98b7cbb9aff8 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 31 Mar 2024 21:39:24 +0100 Subject: [PATCH 778/980] #2417 Remove references to old obs names and add link obs --- CHANGELOG.md | 2 +- .../network/network_interfaces.rst | 2 +- .../agent/observations/acl_observation.py | 6 +- .../observations/file_system_observations.py | 10 +- .../observations/firewall_observation.py | 8 +- .../agent/observations/host_observations.py | 18 +- .../agent/observations/link_observation.py | 155 ++++++++++ .../agent/observations/nic_observations.py | 9 +- .../agent/observations/node_observations.py | 12 +- .../agent/observations/observation_manager.py | 14 +- .../game/agent/observations/observations.py | 275 +----------------- .../agent/observations/router_observation.py | 10 +- .../observations/software_observation.py | 13 +- src/primaite/simulator/network/nmne.py | 2 +- tests/conftest.py | 5 +- .../observations/test_acl_observations.py | 4 +- .../observations/test_link_observations.py | 2 +- .../observations/test_nic_observations.py | 12 +- .../observations/test_node_observations.py | 4 +- .../network/test_capture_nmne.py | 10 +- .../_game/_agent/test_probabilistic_agent.py | 5 +- 21 files changed, 247 insertions(+), 331 deletions(-) create mode 100644 src/primaite/game/agent/observations/link_observation.py diff --git a/CHANGELOG.md b/CHANGELOG.md index c01f0139..8931a3d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -119,7 +119,7 @@ SessionManager. - Updated all tests to employ the `Network()` class for managing nodes and their connections, ensuring a consistent and structured approach to setting up network topologies in testing scenarios. - **ACLRule Wildcard Masking**: Updated the `ACLRule` class to support IP ranges using wildcard masking. This enhancement allows for more flexible and granular control over traffic filtering, enabling the specification of broader or more specific IP address ranges in ACL rules. - Updated `NetworkInterface` documentation to reflect the new NMNE capturing features and how to use them. -- Integration of NMNE capturing functionality within the `NicObservation` class. +- Integration of NMNE capturing functionality within the `NICObservation` class. - Changed blue action set to enable applying node scan, reset, start, and shutdown to every host in data manipulation scenario ### Removed diff --git a/docs/source/simulation_components/network/network_interfaces.rst b/docs/source/simulation_components/network/network_interfaces.rst index ffba58e4..f50a1baa 100644 --- a/docs/source/simulation_components/network/network_interfaces.rst +++ b/docs/source/simulation_components/network/network_interfaces.rst @@ -73,7 +73,7 @@ Network Interface Classes - Malicious Network Events Monitoring: * Enhances network interfaces with the capability to monitor and capture Malicious Network Events (MNEs) based on predefined criteria such as specific keywords or traffic patterns. - * Integrates Number of Malicious Network Events (NMNE) detection functionalities, leveraging configurable settings like ``capture_nmne``, `nmne_capture_keywords``, and observation mechanisms such as ``NicObservation`` to classify and record network anomalies. + * Integrates Number of Malicious Network Events (NMNE) detection functionalities, leveraging configurable settings like ``capture_nmne``, `nmne_capture_keywords``, and observation mechanisms such as ``NICObservation`` to classify and record network anomalies. * Offers an additional layer of security and data analysis, crucial for identifying and mitigating malicious activities within the network infrastructure. Provides vital information for network security analysis and reinforcement learning algorithms. **WiredNetworkInterface (Connection Type Layer)** diff --git a/src/primaite/game/agent/observations/acl_observation.py b/src/primaite/game/agent/observations/acl_observation.py index 7601e678..ac599ea0 100644 --- a/src/primaite/game/agent/observations/acl_observation.py +++ b/src/primaite/game/agent/observations/acl_observation.py @@ -1,7 +1,7 @@ from __future__ import annotations from ipaddress import IPv4Address -from typing import Dict, List, Optional +from typing import Dict, List, Optional, TYPE_CHECKING from gymnasium import spaces from gymnasium.core import ObsType @@ -10,6 +10,8 @@ from primaite import getLogger from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -165,7 +167,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): ) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ACLObservation: + def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> ACLObservation: """ Create an ACL observation from a configuration schema. diff --git a/src/primaite/game/agent/observations/file_system_observations.py b/src/primaite/game/agent/observations/file_system_observations.py index 3c931bc8..a7c56a89 100644 --- a/src/primaite/game/agent/observations/file_system_observations.py +++ b/src/primaite/game/agent/observations/file_system_observations.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, Iterable, List, Optional +from typing import Dict, Iterable, List, Optional, TYPE_CHECKING from gymnasium import spaces from gymnasium.core import ObsType @@ -9,6 +9,8 @@ from primaite import getLogger from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -73,7 +75,7 @@ class FileObservation(AbstractObservation, identifier="FILE"): return spaces.Dict(space) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FileObservation: + def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> FileObservation: """ Create a file observation from a configuration schema. @@ -172,7 +174,7 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): ) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FolderObservation: + def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> FolderObservation: """ Create a folder observation from a configuration schema. @@ -190,5 +192,5 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): for file_config in config.files: file_config.include_num_access = config.include_num_access - files = [FileObservation.from_config(config=f, parent_where=where) for f in config.files] + files = [FileObservation.from_config(config=f, game=game, parent_where=where) for f in config.files] return cls(where=where, files=files, num_files=config.num_files, include_num_access=config.include_num_access) diff --git a/src/primaite/game/agent/observations/firewall_observation.py b/src/primaite/game/agent/observations/firewall_observation.py index 376e4824..69398d96 100644 --- a/src/primaite/game/agent/observations/firewall_observation.py +++ b/src/primaite/game/agent/observations/firewall_observation.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, List, Optional +from typing import Dict, List, Optional, TYPE_CHECKING from gymnasium import spaces from gymnasium.core import ObsType @@ -10,6 +10,8 @@ from primaite.game.agent.observations.acl_observation import ACLObservation from primaite.game.agent.observations.nic_observations import PortObservation from primaite.game.agent.observations.observations import AbstractObservation, WhereType +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -190,7 +192,9 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): return space @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FirewallObservation: + def from_config( + cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = [] + ) -> FirewallObservation: """ Create a firewall observation from a configuration schema. diff --git a/src/primaite/game/agent/observations/host_observations.py b/src/primaite/game/agent/observations/host_observations.py index 9146979a..d71583b3 100644 --- a/src/primaite/game/agent/observations/host_observations.py +++ b/src/primaite/game/agent/observations/host_observations.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, List, Optional +from typing import Dict, List, Optional, TYPE_CHECKING from gymnasium import spaces from gymnasium.core import ObsType @@ -12,6 +12,8 @@ from primaite.game.agent.observations.observations import AbstractObservation, W from primaite.game.agent.observations.software_observation import ApplicationObservation, ServiceObservation from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -184,7 +186,7 @@ class HostObservation(AbstractObservation, identifier="HOST"): return spaces.Dict(shape) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = None) -> HostObservation: + def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> HostObservation: """ Create a host observation from a configuration schema. @@ -196,7 +198,7 @@ class HostObservation(AbstractObservation, identifier="HOST"): :return: Constructed host observation instance. :rtype: HostObservation """ - if parent_where is None: + if parent_where == []: where = ["network", "nodes", config.hostname] else: where = parent_where + ["nodes", config.hostname] @@ -208,10 +210,12 @@ class HostObservation(AbstractObservation, identifier="HOST"): for nic_config in config.network_interfaces: nic_config.include_nmne = config.include_nmne - services = [ServiceObservation.from_config(config=c, parent_where=where) for c in config.services] - applications = [ApplicationObservation.from_config(config=c, parent_where=where) for c in config.applications] - folders = [FolderObservation.from_config(config=c, parent_where=where) for c in config.folders] - nics = [NICObservation.from_config(config=c, parent_where=where) for c in config.network_interfaces] + services = [ServiceObservation.from_config(config=c, game=game, parent_where=where) for c in config.services] + applications = [ + ApplicationObservation.from_config(config=c, game=game, parent_where=where) for c in config.applications + ] + folders = [FolderObservation.from_config(config=c, game=game, parent_where=where) for c in config.folders] + nics = [NICObservation.from_config(config=c, game=game, parent_where=where) for c in config.network_interfaces] return cls( where=where, diff --git a/src/primaite/game/agent/observations/link_observation.py b/src/primaite/game/agent/observations/link_observation.py new file mode 100644 index 00000000..f810bb36 --- /dev/null +++ b/src/primaite/game/agent/observations/link_observation.py @@ -0,0 +1,155 @@ +from __future__ import annotations + +from typing import Any, Dict, List, TYPE_CHECKING + +from gymnasium import spaces +from gymnasium.core import ObsType + +from primaite import getLogger +from primaite.game.agent.observations.observations import AbstractObservation, WhereType +from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE + +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame +_LOGGER = getLogger(__name__) + + +class LinkObservation(AbstractObservation, identifier="LINK"): + """Link observation, providing information about a specific link within the simulation environment.""" + + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for LinkObservation.""" + + link_reference: str + """Reference identifier for the link.""" + + def __init__(self, where: WhereType) -> None: + """ + Initialise a link observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for this link. + A typical location for a link might be ['network', 'links', ]. + :type where: WhereType + """ + self.where = where + self.default_observation: ObsType = {"PROTOCOLS": {"ALL": 0}} + + def observe(self, state: Dict) -> Any: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing information about the link. + :rtype: Any + """ + link_state = access_from_nested_dict(state, self.where) + if link_state is NOT_PRESENT_IN_STATE: + return self.default_observation + + bandwidth = link_state["bandwidth"] + load = link_state["current_load"] + if load == 0: + utilisation_category = 0 + else: + utilisation_fraction = load / bandwidth + utilisation_category = int(utilisation_fraction * 9) + 1 + + return {"PROTOCOLS": {"ALL": min(utilisation_category, 10)}} + + @property + def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for link status. + :rtype: spaces.Space + """ + return spaces.Dict({"PROTOCOLS": spaces.Dict({"ALL": spaces.Discrete(11)})}) + + @classmethod + def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> LinkObservation: + """ + Create a link observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the link observation. + :type config: ConfigSchema + :param game: The PrimaiteGame instance. + :type game: PrimaiteGame + :param parent_where: Where in the simulation state dictionary to find the information about this link. + A typical location might be ['network', 'links', ]. + :type parent_where: WhereType, optional + :return: Constructed link observation instance. + :rtype: LinkObservation + """ + link_reference = game.ref_map_links[config.link_reference] + if parent_where == []: + where = ["network", "links", link_reference] + else: + where = parent_where + ["links", link_reference] + return cls(where=where) + + +class LinksObservation(AbstractObservation, identifier="LINKS"): + """Collection of link observations representing multiple links within the simulation environment.""" + + class ConfigSchema(AbstractObservation.ConfigSchema): + """Configuration schema for LinksObservation.""" + + link_references: List[str] + """List of reference identifiers for the links.""" + + def __init__(self, where: WhereType, links: List[LinkObservation]) -> None: + """ + Initialise a links observation instance. + + :param where: Where in the simulation state dictionary to find the relevant information for these links. + A typical location for links might be ['network', 'links']. + :type where: WhereType + :param links: List of link observations. + :type links: List[LinkObservation] + """ + self.where: WhereType = where + self.links: List[LinkObservation] = links + self.default_observation: ObsType = {i + 1: l.default_observation for i, l in enumerate(self.links)} + + def observe(self, state: Dict) -> ObsType: + """ + Generate observation based on the current state of the simulation. + + :param state: Simulation state dictionary. + :type state: Dict + :return: Observation containing information about multiple links. + :rtype: ObsType + """ + return {i + 1: l.observe(state) for i, l in enumerate(self.links)} + + @property + def space(self) -> spaces.Space: + """ + Gymnasium space object describing the observation space shape. + + :return: Gymnasium space representing the observation space for multiple links. + :rtype: spaces.Space + """ + return {i + 1: l.space for i, l in enumerate(self.links)} + + @classmethod + def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> LinksObservation: + """ + Create a links observation from a configuration schema. + + :param config: Configuration schema containing the necessary information for the links observation. + :type config: ConfigSchema + :param game: The PrimaiteGame instance. + :type game: PrimaiteGame + :param parent_where: Where in the simulation state dictionary to find the information about these links. + A typical location might be ['network']. + :type parent_where: WhereType, optional + :return: Constructed links observation instance. + :rtype: LinksObservation + """ + where = parent_where + ["network"] + link_cfgs = [LinkObservation.ConfigSchema(link_reference=ref) for ref in config.link_references] + links = [LinkObservation.from_config(c, game=game, parent_where=where) for c in link_cfgs] + return cls(where=where, links=links) diff --git a/src/primaite/game/agent/observations/nic_observations.py b/src/primaite/game/agent/observations/nic_observations.py index ff2731ff..19826f84 100644 --- a/src/primaite/game/agent/observations/nic_observations.py +++ b/src/primaite/game/agent/observations/nic_observations.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, Optional +from typing import Dict, Optional, TYPE_CHECKING from gymnasium import spaces from gymnasium.core import ObsType @@ -8,6 +8,9 @@ from gymnasium.core import ObsType from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame + class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): """Status information about a network interface within the simulation environment.""" @@ -82,7 +85,7 @@ class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): return space @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> NICObservation: + def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> NICObservation: """ Create a network interface observation from a configuration schema. @@ -142,7 +145,7 @@ class PortObservation(AbstractObservation, identifier="PORT"): return spaces.Dict({"operating_status": spaces.Discrete(3)}) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> PortObservation: + def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> PortObservation: """ Create a port observation from a configuration schema. diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index 3f384ece..7d227bb7 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, List +from typing import Dict, List, TYPE_CHECKING from gymnasium import spaces from gymnasium.core import ObsType @@ -11,6 +11,8 @@ from primaite.game.agent.observations.host_observations import HostObservation from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.observations.router_observation import RouterObservation +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -119,7 +121,7 @@ class NodesObservation(AbstractObservation, identifier="NODES"): return space @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> NodesObservation: + def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> NodesObservation: """ Create a nodes observation from a configuration schema. @@ -178,8 +180,8 @@ class NodesObservation(AbstractObservation, identifier="NODES"): if firewall_config.num_rules is None: firewall_config.num_rules = config.num_rules - hosts = [HostObservation.from_config(config=c, parent_where=where) for c in config.hosts] - routers = [RouterObservation.from_config(config=c, parent_where=where) for c in config.routers] - firewalls = [FirewallObservation.from_config(config=c, parent_where=where) for c in config.firewalls] + hosts = [HostObservation.from_config(config=c, game=game, parent_where=where) for c in config.hosts] + routers = [RouterObservation.from_config(config=c, game=game, parent_where=where) for c in config.routers] + firewalls = [FirewallObservation.from_config(config=c, game=game, parent_where=where) for c in config.firewalls] return cls(where=where, hosts=hosts, routers=routers, firewalls=firewalls) diff --git a/src/primaite/game/agent/observations/observation_manager.py b/src/primaite/game/agent/observations/observation_manager.py index a6981ddc..84311984 100644 --- a/src/primaite/game/agent/observations/observation_manager.py +++ b/src/primaite/game/agent/observations/observation_manager.py @@ -1,12 +1,12 @@ from __future__ import annotations -from typing import Any, Dict, List, TYPE_CHECKING +from typing import Dict, List, TYPE_CHECKING from gymnasium import spaces from gymnasium.core import ObsType from pydantic import BaseModel, ConfigDict, model_validator, ValidationError -from primaite.game.agent.observations.observations import AbstractObservation +from primaite.game.agent.observations.observations import AbstractObservation, WhereType if TYPE_CHECKING: from primaite.game.game import PrimaiteGame @@ -43,7 +43,7 @@ class NestedObservation(AbstractObservation, identifier="CUSTOM"): class ConfigSchema(AbstractObservation.ConfigSchema): """Configuration schema for NestedObservation.""" - components: List[NestedObservation.NestedObservationItem] + components: List[NestedObservation.NestedObservationItem] = [] """List of observation components to be part of this space.""" def __init__(self, components: Dict[str, AbstractObservation]) -> None: @@ -54,7 +54,7 @@ class NestedObservation(AbstractObservation, identifier="CUSTOM"): self.default_observation = {label: obs.default_observation for label, obs in self.components.items()} """Default observation is just the default observations of constituents.""" - def observe(self, state: Dict) -> Any: + def observe(self, state: Dict) -> ObsType: """ Generate observation based on the current state of the simulation. @@ -76,7 +76,7 @@ class NestedObservation(AbstractObservation, identifier="CUSTOM"): return spaces.Dict({label: obs.space for label, obs in self.components.items()}) @classmethod - def from_config(cls, config: ConfigSchema) -> NestedObservation: + def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> NestedObservation: """ Read the Nested observation config and create all defined subcomponents. @@ -115,7 +115,7 @@ class NestedObservation(AbstractObservation, identifier="CUSTOM"): instances = dict() for component in config.components: obs_class = AbstractObservation._registry[component.type] - obs_instance = obs_class.from_config(obs_class.ConfigSchema(**component.options)) + obs_instance = obs_class.from_config(config=obs_class.ConfigSchema(**component.options), game=game) instances[component.label] = obs_instance return cls(components=instances) @@ -170,6 +170,6 @@ class ObservationManager: """ obs_type = config["type"] obs_class = AbstractObservation._registry[obs_type] - observation = obs_class.from_config(obs_class.ConfigSchema(**config["options"])) + observation = obs_class.from_config(config=obs_class.ConfigSchema(**config["options"]), game=game) obs_manager = cls(observation) return obs_manager diff --git a/src/primaite/game/agent/observations/observations.py b/src/primaite/game/agent/observations/observations.py index feddc3ed..6c9db571 100644 --- a/src/primaite/game/agent/observations/observations.py +++ b/src/primaite/game/agent/observations/observations.py @@ -1,6 +1,6 @@ """Manages the observation space for the agent.""" from abc import ABC, abstractmethod -from typing import Any, Dict, Iterable, Type +from typing import Any, Dict, Iterable, Type, TYPE_CHECKING from gymnasium import spaces from gymnasium.core import ObsType @@ -8,8 +8,9 @@ from pydantic import BaseModel, ConfigDict from primaite import getLogger +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) - WhereType = Iterable[str | int] | None @@ -64,272 +65,8 @@ class AbstractObservation(ABC): @classmethod @abstractmethod - def from_config(cls, config: ConfigSchema) -> "AbstractObservation": + def from_config( + cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = [] + ) -> "AbstractObservation": """Create this observation space component form a serialised format.""" return cls() - - -''' -class LinkObservation(AbstractObservation): - """Observation of a link in the network.""" - - default_observation: spaces.Space = {"PROTOCOLS": {"ALL": 0}} - "Default observation is what should be returned when the link doesn't exist." - - def __init__(self, where: Optional[Tuple[str]] = None) -> None: - """Initialise link observation. - - :param where: Store information about where in the simulation state dictionary to find the relevant information. - Optional. If None, this corresponds that the file does not exist and the observation will be populated with - zeroes. - - A typical location for a service looks like this: - `['network','nodes',,'servics', ]` - :type where: Optional[List[str]] - """ - super().__init__() - self.where: Optional[Tuple[str]] = where - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict - """ - if self.where is None: - return self.default_observation - - link_state = access_from_nested_dict(state, self.where) - if link_state is NOT_PRESENT_IN_STATE: - return self.default_observation - - bandwidth = link_state["bandwidth"] - load = link_state["current_load"] - if load == 0: - utilisation_category = 0 - else: - utilisation_fraction = load / bandwidth - # 0 is UNUSED, 1 is 0%-10%. 2 is 10%-20%. 3 is 20%-30%. And so on... 10 is exactly 100% - utilisation_category = int(utilisation_fraction * 9) + 1 - - # TODO: once the links support separte load per protocol, this needs amendment to reflect that. - return {"PROTOCOLS": {"ALL": min(utilisation_category, 10)}} - - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape. - - :return: Gymnasium space - :rtype: spaces.Space - """ - return spaces.Dict({"PROTOCOLS": spaces.Dict({"ALL": spaces.Discrete(11)})}) - - @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "LinkObservation": - """Create link observation from a config. - - :param config: Dictionary containing the configuration for this link observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :return: Constructed link observation - :rtype: LinkObservation - """ - return cls(where=["network", "links", game.ref_map_links[config["link_ref"]]]) - - -class AclObservation(AbstractObservation): - """Observation of an Access Control List (ACL) in the network.""" - - # TODO: should where be optional, and we can use where=None to pad the observation space? - # definitely the current approach does not support tracking files that aren't specified by name, for example - # if a file is created at runtime, we have currently got no way of telling the observation space to track it. - # this needs adding, but not for the MVP. - def __init__( - self, - node_ip_to_id: Dict[str, int], - ports: List[int], - protocols: List[str], - where: Optional[Tuple[str]] = None, - num_rules: int = 10, - ) -> None: - """Initialise ACL observation. - - :param node_ip_to_id: Mapping between IP address and ID. - :type node_ip_to_id: Dict[str, int] - :param ports: List of ports which are part of the game that define the ordering when converting to an ID - :type ports: List[int] - :param protocols: List of protocols which are part of the game, defines ordering when converting to an ID - :type protocols: list[str] - :param where: Where in the simulation state dictionary to find the relevant information for this ACL. A typical - example may look like this: - ['network','nodes',,'acl','acl'] - :type where: Optional[Tuple[str]], optional - :param num_rules: , defaults to 10 - :type num_rules: int, optional - """ - super().__init__() - self.where: Optional[Tuple[str]] = where - self.num_rules: int = num_rules - self.node_to_id: Dict[str, int] = node_ip_to_id - "List of node IP addresses, order in this list determines how they are converted to an ID" - self.port_to_id: Dict[int, int] = {port: i + 2 for i, port in enumerate(ports)} - "List of ports which are part of the game that define the ordering when converting to an ID" - self.protocol_to_id: Dict[str, int] = {protocol: i + 2 for i, protocol in enumerate(protocols)} - "List of protocols which are part of the game, defines ordering when converting to an ID" - self.default_observation: Dict = { - i - + 1: { - "position": i, - "permission": 0, - "source_node_id": 0, - "source_port": 0, - "dest_node_id": 0, - "dest_port": 0, - "protocol": 0, - } - for i in range(self.num_rules) - } - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation. - - :param state: Simulation state dictionary - :type state: Dict - :return: Observation - :rtype: Dict - """ - if self.where is None: - return self.default_observation - acl_state: Dict = access_from_nested_dict(state, self.where) - if acl_state is NOT_PRESENT_IN_STATE: - return self.default_observation - - # TODO: what if the ACL has more rules than num of max rules for obs space - obs = {} - acl_items = dict(acl_state.items()) - i = 1 # don't show rule 0 for compatibility reasons. - while i < self.num_rules + 1: - rule_state = acl_items[i] - if rule_state is None: - obs[i] = { - "position": i - 1, - "permission": 0, - "source_node_id": 0, - "source_port": 0, - "dest_node_id": 0, - "dest_port": 0, - "protocol": 0, - } - else: - src_ip = rule_state["src_ip_address"] - src_node_id = 1 if src_ip is None else self.node_to_id[IPv4Address(src_ip)] - dst_ip = rule_state["dst_ip_address"] - dst_node_ip = 1 if dst_ip is None else self.node_to_id[IPv4Address(dst_ip)] - src_port = rule_state["src_port"] - src_port_id = 1 if src_port is None else self.port_to_id[src_port] - dst_port = rule_state["dst_port"] - dst_port_id = 1 if dst_port is None else self.port_to_id[dst_port] - protocol = rule_state["protocol"] - protocol_id = 1 if protocol is None else self.protocol_to_id[protocol] - obs[i] = { - "position": i - 1, - "permission": rule_state["action"], - "source_node_id": src_node_id, - "source_port": src_port_id, - "dest_node_id": dst_node_ip, - "dest_port": dst_port_id, - "protocol": protocol_id, - } - i += 1 - return obs - - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape. - - :return: Gymnasium space - :rtype: spaces.Space - """ - return spaces.Dict( - { - i - + 1: spaces.Dict( - { - "position": spaces.Discrete(self.num_rules), - "permission": spaces.Discrete(3), - # adding two to lengths is to account for reserved values 0 (unused) and 1 (any) - "source_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), - "source_port": spaces.Discrete(len(self.port_to_id) + 2), - "dest_node_id": spaces.Discrete(len(set(self.node_to_id.values())) + 2), - "dest_port": spaces.Discrete(len(self.port_to_id) + 2), - "protocol": spaces.Discrete(len(self.protocol_to_id) + 2), - } - ) - for i in range(self.num_rules) - } - ) - - @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "AclObservation": - """Generate ACL observation from a config. - - :param config: Dictionary containing the configuration for this ACL observation. - :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame - :return: Observation object - :rtype: AclObservation - """ - max_acl_rules = config["options"]["max_acl_rules"] - node_ip_to_idx = {} - for ip_idx, ip_map_config in enumerate(config["ip_address_order"]): - node_ref = ip_map_config["node_hostname"] - nic_num = ip_map_config["nic_num"] - node_obj = game.simulation.network.nodes[game.ref_map_nodes[node_ref]] - nic_obj = node_obj.network_interface[nic_num] - node_ip_to_idx[nic_obj.ip_address] = ip_idx + 2 - - router_hostname = config["router_hostname"] - return cls( - node_ip_to_id=node_ip_to_idx, - ports=game.options.ports, - protocols=game.options.protocols, - where=["network", "nodes", router_hostname, "acl", "acl"], - num_rules=max_acl_rules, - ) - - -class NullObservation(AbstractObservation): - """Null observation, returns a single 0 value for the observation space.""" - - def __init__(self, where: Optional[List[str]] = None): - """Initialise null observation.""" - self.default_observation: Dict = {} - - def observe(self, state: Dict) -> Dict: - """Generate observation based on the current state of the simulation.""" - return 0 - - @property - def space(self) -> spaces.Space: - """Gymnasium space object describing the observation space shape.""" - return spaces.Discrete(1) - - @classmethod - def from_config(cls, config: Dict, game: Optional["PrimaiteGame"] = None) -> "NullObservation": - """ - Create null observation from a config. - - The parameters are ignored, they are here to match the signature of the other observation classes. - """ - return cls() - - -class ICSObservation(NullObservation): - """ICS observation placeholder, currently not implemented so always returns a single 0.""" - - pass -''' diff --git a/src/primaite/game/agent/observations/router_observation.py b/src/primaite/game/agent/observations/router_observation.py index 97d8ab41..c2919770 100644 --- a/src/primaite/game/agent/observations/router_observation.py +++ b/src/primaite/game/agent/observations/router_observation.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, List, Optional +from typing import Dict, List, Optional, TYPE_CHECKING from gymnasium import spaces from gymnasium.core import ObsType @@ -11,6 +11,8 @@ from primaite.game.agent.observations.nic_observations import PortObservation from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -107,7 +109,7 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): ) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> RouterObservation: + def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> RouterObservation: """ Create a router observation from a configuration schema. @@ -137,6 +139,6 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): if config.ports is None: config.ports = [PortObservation.ConfigSchema(port_id=i + 1) for i in range(config.num_ports)] - ports = [PortObservation.from_config(config=c, parent_where=where) for c in config.ports] - acl = ACLObservation.from_config(config=config.acl, parent_where=where) + ports = [PortObservation.from_config(config=c, game=game, parent_where=where) for c in config.ports] + acl = ACLObservation.from_config(config=config.acl, game=game, parent_where=where) return cls(where=where, ports=ports, num_ports=config.num_ports, acl=acl) diff --git a/src/primaite/game/agent/observations/software_observation.py b/src/primaite/game/agent/observations/software_observation.py index 0c031345..40788760 100644 --- a/src/primaite/game/agent/observations/software_observation.py +++ b/src/primaite/game/agent/observations/software_observation.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict +from typing import Dict, TYPE_CHECKING from gymnasium import spaces from gymnasium.core import ObsType @@ -8,6 +8,9 @@ from gymnasium.core import ObsType from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE +if TYPE_CHECKING: + from primaite.game.game import PrimaiteGame + class ServiceObservation(AbstractObservation, identifier="SERVICE"): """Service observation, shows status of a service in the simulation environment.""" @@ -57,7 +60,9 @@ class ServiceObservation(AbstractObservation, identifier="SERVICE"): return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(5)}) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ServiceObservation: + def from_config( + cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = [] + ) -> ServiceObservation: """ Create a service observation from a configuration schema. @@ -128,7 +133,9 @@ class ApplicationObservation(AbstractObservation, identifier="APPLICATION"): ) @classmethod - def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ApplicationObservation: + def from_config( + cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = [] + ) -> ApplicationObservation: """ Create an application observation from a configuration schema. diff --git a/src/primaite/simulator/network/nmne.py b/src/primaite/simulator/network/nmne.py index 87839712..1b3d838d 100644 --- a/src/primaite/simulator/network/nmne.py +++ b/src/primaite/simulator/network/nmne.py @@ -6,7 +6,7 @@ CAPTURE_NMNE: bool = True NMNE_CAPTURE_KEYWORDS: List[str] = [] """List of keywords to identify malicious network events.""" -# TODO: Remove final and make configurable after example layout when the NicObservation creates nmne structure dynamically +# TODO: Remove final and make configurable after example layout when the NICObservation creates nmne structure dynamically CAPTURE_BY_DIRECTION: Final[bool] = True """Flag to determine if captures should be organized by traffic direction (inbound/outbound).""" CAPTURE_BY_IP_ADDRESS: Final[bool] = False diff --git a/tests/conftest.py b/tests/conftest.py index 078a78bd..b08fd838 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,8 +10,7 @@ from _pytest.monkeypatch import MonkeyPatch from primaite import getLogger, PRIMAITE_PATHS from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractAgent -from primaite.game.agent.observations.observation_manager import ObservationManager -from primaite.game.agent.observations.observations import ICSObservation +from primaite.game.agent.observations.observation_manager import NestedObservation, ObservationManager from primaite.game.agent.rewards import RewardFunction from primaite.game.game import PrimaiteGame from primaite.session.session import PrimaiteSession @@ -525,7 +524,7 @@ def game_and_agent(): ip_address_list=["10.0.1.1", "10.0.1.2", "10.0.2.1", "10.0.2.2", "10.0.2.3"], act_map={}, ) - observation_space = ObservationManager(ICSObservation()) + observation_space = ObservationManager(NestedObservation(components={})) reward_function = RewardFunction() test_agent = ControlledAgent( diff --git a/tests/integration_tests/game_layer/observations/test_acl_observations.py b/tests/integration_tests/game_layer/observations/test_acl_observations.py index 93867edd..d0710f5f 100644 --- a/tests/integration_tests/game_layer/observations/test_acl_observations.py +++ b/tests/integration_tests/game_layer/observations/test_acl_observations.py @@ -1,6 +1,6 @@ import pytest -from primaite.game.agent.observations.observations import AclObservation +from primaite.game.agent.observations.acl_observation import ACLObservation from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router from primaite.simulator.network.transmission.transport_layer import Port @@ -34,7 +34,7 @@ def test_acl_observations(simulation): # add router acl rule router.acl.add_rule(action=ACLAction.PERMIT, dst_port=Port.NTP, src_port=Port.NTP, position=1) - acl_obs = AclObservation( + acl_obs = ACLObservation( where=["network", "nodes", router.hostname, "acl", "acl"], node_ip_to_id={}, ports=["NTP", "HTTP", "POSTGRES_SERVER"], diff --git a/tests/integration_tests/game_layer/observations/test_link_observations.py b/tests/integration_tests/game_layer/observations/test_link_observations.py index bfe4d5cc..b13314f1 100644 --- a/tests/integration_tests/game_layer/observations/test_link_observations.py +++ b/tests/integration_tests/game_layer/observations/test_link_observations.py @@ -1,7 +1,7 @@ import pytest from gymnasium import spaces -from primaite.game.agent.observations.observations import LinkObservation +from primaite.game.agent.observations.link_observation import LinkObservation from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.base import Link, Node from primaite.simulator.network.hardware.nodes.host.computer import Computer diff --git a/tests/integration_tests/game_layer/observations/test_nic_observations.py b/tests/integration_tests/game_layer/observations/test_nic_observations.py index 332bc1f7..bc4261ce 100644 --- a/tests/integration_tests/game_layer/observations/test_nic_observations.py +++ b/tests/integration_tests/game_layer/observations/test_nic_observations.py @@ -5,7 +5,7 @@ import pytest import yaml from gymnasium import spaces -from primaite.game.agent.observations.nic_observations import NicObservation +from primaite.game.agent.observations.nic_observations import NICObservation from primaite.game.game import PrimaiteGame from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC @@ -40,7 +40,7 @@ def test_nic(simulation): nic: NIC = pc.network_interface[1] - nic_obs = NicObservation(where=["network", "nodes", pc.hostname, "NICs", 1]) + nic_obs = NICObservation(where=["network", "nodes", pc.hostname, "NICs", 1]) assert nic_obs.space["nic_status"] == spaces.Discrete(3) assert nic_obs.space["NMNE"]["inbound"] == spaces.Discrete(4) @@ -61,13 +61,13 @@ def test_nic_categories(simulation): """Test the NIC observation nmne count categories.""" pc: Computer = simulation.network.get_node_by_hostname("client_1") - nic_obs = NicObservation(where=["network", "nodes", pc.hostname, "NICs", 1]) + nic_obs = NICObservation(where=["network", "nodes", pc.hostname, "NICs", 1]) assert nic_obs.high_nmne_threshold == 10 # default assert nic_obs.med_nmne_threshold == 5 # default assert nic_obs.low_nmne_threshold == 0 # default - nic_obs = NicObservation( + nic_obs = NICObservation( where=["network", "nodes", pc.hostname, "NICs", 1], low_nmne_threshold=3, med_nmne_threshold=6, @@ -80,7 +80,7 @@ def test_nic_categories(simulation): with pytest.raises(Exception): # should throw an error - NicObservation( + NICObservation( where=["network", "nodes", pc.hostname, "NICs", 1], low_nmne_threshold=9, med_nmne_threshold=6, @@ -89,7 +89,7 @@ def test_nic_categories(simulation): with pytest.raises(Exception): # should throw an error - NicObservation( + NICObservation( where=["network", "nodes", pc.hostname, "NICs", 1], low_nmne_threshold=3, med_nmne_threshold=9, diff --git a/tests/integration_tests/game_layer/observations/test_node_observations.py b/tests/integration_tests/game_layer/observations/test_node_observations.py index dce05b6a..2926ffa6 100644 --- a/tests/integration_tests/game_layer/observations/test_node_observations.py +++ b/tests/integration_tests/game_layer/observations/test_node_observations.py @@ -4,7 +4,7 @@ from uuid import uuid4 import pytest from gymnasium import spaces -from primaite.game.agent.observations.node_observations import NodeObservation +from primaite.game.agent.observations.host_observations import HostObservation from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.sim_container import Simulation @@ -23,7 +23,7 @@ def test_node_observation(simulation): """Test a Node observation.""" pc: Computer = simulation.network.get_node_by_hostname("client_1") - node_obs = NodeObservation(where=["network", "nodes", pc.hostname]) + node_obs = HostObservation(where=["network", "nodes", pc.hostname]) assert node_obs.space["operating_status"] == spaces.Discrete(5) diff --git a/tests/integration_tests/network/test_capture_nmne.py b/tests/integration_tests/network/test_capture_nmne.py index 9efc70f7..1578305b 100644 --- a/tests/integration_tests/network/test_capture_nmne.py +++ b/tests/integration_tests/network/test_capture_nmne.py @@ -1,4 +1,4 @@ -from primaite.game.agent.observations.nic_observations import NicObservation +from primaite.game.agent.observations.nic_observations import NICObservation from primaite.simulator.network.hardware.nodes.host.server import Server from primaite.simulator.network.nmne import set_nmne_config from primaite.simulator.sim_container import Simulation @@ -141,9 +141,9 @@ def test_describe_state_nmne(uc2_network): def test_capture_nmne_observations(uc2_network): """ - Tests the NicObservation class's functionality within a simulated network environment. + Tests the NICObservation class's functionality within a simulated network environment. - This test ensures the observation space, as defined by instances of NicObservation, accurately reflects the + This test ensures the observation space, as defined by instances of NICObservation, accurately reflects the number of MNEs detected based on network activities over multiple iterations. The test employs a series of "DELETE" SQL operations, considered as MNEs, to validate the dynamic update @@ -168,8 +168,8 @@ def test_capture_nmne_observations(uc2_network): set_nmne_config(nmne_config) # Define observations for the NICs of the database and web servers - db_server_nic_obs = NicObservation(where=["network", "nodes", "database_server", "NICs", 1]) - web_server_nic_obs = NicObservation(where=["network", "nodes", "web_server", "NICs", 1]) + db_server_nic_obs = NICObservation(where=["network", "nodes", "database_server", "NICs", 1]) + web_server_nic_obs = NICObservation(where=["network", "nodes", "web_server", "NICs", 1]) # Iterate through a set of test cases to simulate multiple DELETE queries for i in range(0, 20): diff --git a/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py b/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py index c556cfad..7eacb30d 100644 --- a/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py +++ b/tests/unit_tests/_primaite/_game/_agent/test_probabilistic_agent.py @@ -1,6 +1,5 @@ from primaite.game.agent.actions import ActionManager -from primaite.game.agent.observations.observation_manager import ObservationManager -from primaite.game.agent.observations.observations import ICSObservation +from primaite.game.agent.observations.observation_manager import NestedObservation, ObservationManager from primaite.game.agent.rewards import RewardFunction from primaite.game.agent.scripted_agents.probabilistic_agent import ProbabilisticAgent @@ -52,7 +51,7 @@ def test_probabilistic_agent(): 2: {"action": "NODE_FILE_DELETE", "options": {"node_id": 0, "folder_id": 0, "file_id": 0}}, }, ) - observation_space = ObservationManager(ICSObservation()) + observation_space = ObservationManager(NestedObservation(components={})) reward_function = RewardFunction() pa = ProbabilisticAgent( From 8da53db82224c0d9543e74ca2825030125a411b9 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 31 Mar 2024 23:20:48 +0100 Subject: [PATCH 779/980] #2417 Finalise parsing of observation space --- .../_package_data/data_manipulation.yaml | 172 +++++++----------- .../game/agent/observations/__init__.py | 12 ++ .../agent/observations/host_observations.py | 17 +- .../agent/observations/link_observation.py | 2 +- .../agent/observations/node_observations.py | 59 ++++-- .../agent/observations/observation_manager.py | 31 +++- 6 files changed, 167 insertions(+), 126 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index 06028ee1..d810e58a 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -41,8 +41,7 @@ agents: 0: 0.3 1: 0.6 2: 0.1 - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -91,8 +90,7 @@ agents: 0: 0.3 1: 0.6 2: 0.1 - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -141,10 +139,7 @@ agents: team: RED type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: {} + observation_space: null action_space: action_list: @@ -177,102 +172,73 @@ agents: type: ProxyAgent observation_space: - - type: NODES - label: NODES # What is the dictionary key called - options: - hosts: - - hostname: domain_controller - - hostname: web_server - - hostname: database_server - - hostname: backup_server - - hostname: security_suite - - hostname: client_1 - - hostname: client_2 - routers: - - hostname: router_1 - firewalls: {} - - num_host_services: 1 - num_host_applications: 0 - num_host_folders: 1 - num_host_files: 1 - num_host_network_interfaces: 2 - num_router_ports: 4 - num_acl_rules: 10 - num_firewall_ports: 4 - firewalls_internal_inbound_acl: true - firewalls_internal_outbound_acl: true - firewalls_dmz_inbound_acl: true - firewalls_dmz_outbound_acl: true - firewalls_external_inbound_acl: true - firewalls_external_outbound_acl: true - - type: LINKS - label: "LINKS" - options: - links: - - link_ref: router_1___switch_1 - - link_ref: router_1___switch_2 - - link_ref: switch_1___domain_controller - - link_ref: switch_1___web_server - - link_ref: switch_1___database_server - - link_ref: switch_1___backup_server - - link_ref: switch_1___security_suite - - link_ref: switch_2___client_1 - - link_ref: switch_2___client_2 - - link_ref: switch_2___security_suite - - observation_space: - type: UC2BlueObservation + type: CUSTOM options: - nodes: - - node_hostname: domain_controller - services: - - service_name: DNSServer - - node_hostname: web_server - services: - - service_name: WebServer - - node_hostname: database_server - folders: - - folder_name: database - files: - - file_name: database.db - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 - links: - - link_ref: router_1___switch_1 - - link_ref: router_1___switch_2 - - link_ref: switch_1___domain_controller - - link_ref: switch_1___web_server - - link_ref: switch_1___database_server - - link_ref: switch_1___backup_server - - link_ref: switch_1___security_suite - - link_ref: switch_2___client_1 - - link_ref: switch_2___client_2 - - link_ref: switch_2___security_suite - acl: - options: - max_acl_rules: 10 - router_hostname: router_1 - ip_address_order: - - node_hostname: domain_controller - nic_num: 1 - - node_hostname: web_server - nic_num: 1 - - node_hostname: database_server - nic_num: 1 - - node_hostname: backup_server - nic_num: 1 - - node_hostname: security_suite - nic_num: 1 - - node_hostname: client_1 - nic_num: 1 - - node_hostname: client_2 - nic_num: 1 - - node_hostname: security_suite - nic_num: 2 - ics: null + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: domain_controller + - hostname: web_server + services: + - service_name: WebServer + - hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - router_1___switch_1 + - router_1___switch_2 + - switch_1___domain_controller + - switch_1___web_server + - switch_1___database_server + - switch_1___backup_server + - switch_1___security_suite + - switch_2___client_1 + - switch_2___client_2 + - switch_2___security_suite + - type: "NONE" + label: ICS + options: {} action_space: action_list: diff --git a/src/primaite/game/agent/observations/__init__.py b/src/primaite/game/agent/observations/__init__.py index e69de29b..b9d97ae6 100644 --- a/src/primaite/game/agent/observations/__init__.py +++ b/src/primaite/game/agent/observations/__init__.py @@ -0,0 +1,12 @@ +# flake8: noqa +from primaite.game.agent.observations.acl_observation import ACLObservation +from primaite.game.agent.observations.file_system_observations import FileObservation, FolderObservation +from primaite.game.agent.observations.firewall_observation import FirewallObservation +from primaite.game.agent.observations.host_observations import HostObservation +from primaite.game.agent.observations.link_observation import LinkObservation, LinksObservation +from primaite.game.agent.observations.nic_observations import NICObservation, PortObservation +from primaite.game.agent.observations.node_observations import NodesObservation +from primaite.game.agent.observations.observation_manager import NestedObservation, NullObservation, ObservationManager +from primaite.game.agent.observations.observations import AbstractObservation +from primaite.game.agent.observations.router_observation import RouterObservation +from primaite.game.agent.observations.software_observation import ApplicationObservation, ServiceObservation diff --git a/src/primaite/game/agent/observations/host_observations.py b/src/primaite/game/agent/observations/host_observations.py index d71583b3..3ee5f2c7 100644 --- a/src/primaite/game/agent/observations/host_observations.py +++ b/src/primaite/game/agent/observations/host_observations.py @@ -94,6 +94,8 @@ class HostObservation(AbstractObservation, identifier="HOST"): """ self.where: WhereType = where + self.include_num_access = include_num_access + # Ensure lists have lengths equal to specified counts by truncating or padding self.services: List[ServiceObservation] = services while len(self.services) < num_services: @@ -135,9 +137,10 @@ class HostObservation(AbstractObservation, identifier="HOST"): "FOLDERS": {i + 1: f.default_observation for i, f in enumerate(self.folders)}, "NICS": {i + 1: n.default_observation for i, n in enumerate(self.network_interfaces)}, "operating_status": 0, - "num_file_creations": 0, - "num_file_deletions": 0, } + if self.include_num_access: + self.default_observation["num_file_creations"] = 0 + self.default_observation["num_file_deletions"] = 0 def observe(self, state: Dict) -> ObsType: """ @@ -160,8 +163,9 @@ class HostObservation(AbstractObservation, identifier="HOST"): obs["NICS"] = { i + 1: network_interface.observe(state) for i, network_interface in enumerate(self.network_interfaces) } - obs["num_file_creations"] = node_state["file_system"]["num_file_creations"] - obs["num_file_deletions"] = node_state["file_system"]["num_file_deletions"] + if self.include_num_access: + obs["num_file_creations"] = node_state["file_system"]["num_file_creations"] + obs["num_file_deletions"] = node_state["file_system"]["num_file_deletions"] return obs @property @@ -180,9 +184,10 @@ class HostObservation(AbstractObservation, identifier="HOST"): "NICS": spaces.Dict( {i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)} ), - "num_file_creations": spaces.Discrete(4), - "num_file_deletions": spaces.Discrete(4), } + if self.include_num_access: + shape["num_file_creations"] = spaces.Discrete(4) + shape["num_file_deletions"] = spaces.Discrete(4) return spaces.Dict(shape) @classmethod diff --git a/src/primaite/game/agent/observations/link_observation.py b/src/primaite/game/agent/observations/link_observation.py index f810bb36..be08657d 100644 --- a/src/primaite/game/agent/observations/link_observation.py +++ b/src/primaite/game/agent/observations/link_observation.py @@ -132,7 +132,7 @@ class LinksObservation(AbstractObservation, identifier="LINKS"): :return: Gymnasium space representing the observation space for multiple links. :rtype: spaces.Space """ - return {i + 1: l.space for i, l in enumerate(self.links)} + return spaces.Dict({i + 1: l.space for i, l in enumerate(self.links)}) @classmethod def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> LinksObservation: diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index 7d227bb7..dce33a04 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -1,9 +1,10 @@ from __future__ import annotations -from typing import Dict, List, TYPE_CHECKING +from typing import Dict, List, Optional, TYPE_CHECKING from gymnasium import spaces from gymnasium.core import ObsType +from pydantic import model_validator from primaite import getLogger from primaite.game.agent.observations.firewall_observation import FirewallObservation @@ -28,33 +29,63 @@ class NodesObservation(AbstractObservation, identifier="NODES"): """List of configurations for router observations.""" firewalls: List[FirewallObservation.ConfigSchema] = [] """List of configurations for firewall observations.""" - num_services: int + num_services: Optional[int] = None """Number of services.""" - num_applications: int + num_applications: Optional[int] = None """Number of applications.""" - num_folders: int + num_folders: Optional[int] = None """Number of folders.""" - num_files: int + num_files: Optional[int] = None """Number of files.""" - num_nics: int + num_nics: Optional[int] = None """Number of network interface cards (NICs).""" - include_nmne: bool + include_nmne: Optional[bool] = None """Flag to include nmne.""" - include_num_access: bool + include_num_access: Optional[bool] = None """Flag to include the number of accesses.""" - num_ports: int + num_ports: Optional[int] = None """Number of ports.""" - ip_list: List[str] + ip_list: Optional[List[str]] = None """List of IP addresses for encoding ACLs.""" - wildcard_list: List[str] + wildcard_list: Optional[List[str]] = None """List of IP wildcards for encoding ACLs.""" - port_list: List[int] + port_list: Optional[List[int]] = None """List of ports for encoding ACLs.""" - protocol_list: List[str] + protocol_list: Optional[List[str]] = None """List of protocols for encoding ACLs.""" - num_rules: int + num_rules: Optional[int] = None """Number of rules ACL rules to show.""" + @model_validator(mode="after") + def force_optional_fields(self) -> NodesObservation.ConfigSchema: + """Check that options are specified only if they are needed for the nodes that are part of the config.""" + # check for hosts: + host_fields = ( + self.num_services, + self.num_applications, + self.num_folders, + self.num_files, + self.num_nics, + self.include_nmne, + self.include_num_access, + ) + router_fields = ( + self.num_ports, + self.ip_list, + self.wildcard_list, + self.port_list, + self.protocol_list, + self.num_rules, + ) + firewall_fields = (self.ip_list, self.wildcard_list, self.port_list, self.protocol_list, self.num_rules) + if len(self.hosts) > 0 and any([x is None for x in host_fields]): + raise ValueError("Configuration error: Host observation options were not fully specified.") + if len(self.routers) > 0 and any([x is None for x in router_fields]): + raise ValueError("Configuration error: Router observation options were not fully specified.") + if len(self.firewalls) > 0 and any([x is None for x in firewall_fields]): + raise ValueError("Configuration error: Firewall observation options were not fully specified.") + return self + def __init__( self, where: WhereType, diff --git a/src/primaite/game/agent/observations/observation_manager.py b/src/primaite/game/agent/observations/observation_manager.py index 84311984..3703fa1c 100644 --- a/src/primaite/game/agent/observations/observation_manager.py +++ b/src/primaite/game/agent/observations/observation_manager.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, List, TYPE_CHECKING +from typing import Any, Dict, List, Optional, TYPE_CHECKING from gymnasium import spaces from gymnasium.core import ObsType @@ -120,6 +120,30 @@ class NestedObservation(AbstractObservation, identifier="CUSTOM"): return cls(components=instances) +class NullObservation(AbstractObservation, identifier="NONE"): + """Empty observation that acts as a placeholder.""" + + def __init__(self) -> None: + """Initialise the empty observation.""" + self.default_observation = 0 + + def observe(self, state: Dict) -> Any: + """Simply return 0.""" + return 0 + + @property + def space(self) -> spaces.Space: + """Essentially empty space.""" + return spaces.Discrete(1) + + @classmethod + def from_config( + cls, config: NullObservation.ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = [] + ) -> NullObservation: + """Instantiate a NullObservation. Accepts parameters to comply with API.""" + return cls() + + class ObservationManager: """ Manage the observations of an Agent. @@ -156,7 +180,7 @@ class ObservationManager: return self.obs.space @classmethod - def from_config(cls, config: Dict, game: "PrimaiteGame") -> "ObservationManager": + def from_config(cls, config: Optional[Dict], game: "PrimaiteGame") -> "ObservationManager": """ Create observation space from a config. @@ -168,6 +192,9 @@ class ObservationManager: :param game: Reference to the PrimaiteGame object that spawned this observation. :type game: PrimaiteGame """ + if config is None: + return cls(NullObservation()) + print(config) obs_type = config["type"] obs_class = AbstractObservation._registry[obs_type] observation = obs_class.from_config(config=obs_class.ConfigSchema(**config["options"]), game=game) From 0e0df1012fb20e0fe1b9f1963de2bbb74c03b0d7 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Sun, 31 Mar 2024 23:39:24 +0100 Subject: [PATCH 780/980] #2417 update observations init to autoimport all obs types --- src/primaite/game/agent/observations/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/primaite/game/agent/observations/__init__.py b/src/primaite/game/agent/observations/__init__.py index b9d97ae6..15fdf7ed 100644 --- a/src/primaite/game/agent/observations/__init__.py +++ b/src/primaite/game/agent/observations/__init__.py @@ -1,4 +1,5 @@ # flake8: noqa +# Pre-import all the observations when we load up the observations module so that they can be resolved by the parser. from primaite.game.agent.observations.acl_observation import ACLObservation from primaite.game.agent.observations.file_system_observations import FileObservation, FolderObservation from primaite.game.agent.observations.firewall_observation import FirewallObservation @@ -10,3 +11,10 @@ from primaite.game.agent.observations.observation_manager import NestedObservati from primaite.game.agent.observations.observations import AbstractObservation from primaite.game.agent.observations.router_observation import RouterObservation from primaite.game.agent.observations.software_observation import ApplicationObservation, ServiceObservation + +# fmt: off +__all__ = [ + "ACLObservation", "FileObservation", "FolderObservation", "FirewallObservation", "HostObservation", + "LinksObservation", "NICObservation", "PortObservation", "NodesObservation", "NestedObservation", + "ObservationManager", "ApplicationObservation", "ServiceObservation",] +# fmt: on From 0ba767d2a0988c404524a042d3d5a4396ac053d4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 1 Apr 2024 00:54:55 +0100 Subject: [PATCH 781/980] #2417 update observation tests and make old tests pass --- .../_package_data/data_manipulation_marl.yaml | 251 +++++++++-------- .../agent/observations/acl_observation.py | 22 +- .../observations/file_system_observations.py | 16 +- .../agent/observations/host_observations.py | 52 ++-- .../agent/observations/nic_observations.py | 36 ++- .../agent/observations/router_observation.py | 13 +- .../assets/configs/bad_primaite_session.yaml | 130 ++++----- tests/assets/configs/basic_firewall.yaml | 3 +- .../configs/basic_switched_network.yaml | 3 +- tests/assets/configs/dmz_network.yaml | 3 +- .../configs/eval_only_primaite_session.yaml | 130 ++++----- tests/assets/configs/multi_agent_session.yaml | 252 ++++++++++-------- tests/assets/configs/shared_rewards.yaml | 131 ++++----- .../assets/configs/test_primaite_session.yaml | 132 ++++----- .../configs/train_only_primaite_session.yaml | 130 ++++----- .../test_primaite_session.py | 8 +- .../observations/test_acl_observations.py | 28 +- .../test_file_system_observations.py | 8 +- .../observations/test_nic_observations.py | 11 +- .../observations/test_node_observations.py | 27 +- .../game_layer/test_observations.py | 3 +- .../network/test_capture_nmne.py | 4 +- 22 files changed, 767 insertions(+), 626 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index b632f626..3e95a6ee 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -40,8 +40,7 @@ agents: 0: 0.3 1: 0.6 2: 0.1 - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -90,8 +89,7 @@ agents: 0: 0.3 1: 0.6 2: 0.1 - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -140,10 +138,7 @@ agents: team: RED type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: {} + observation_space: null action_space: action_list: @@ -179,61 +174,73 @@ agents: type: ProxyAgent observation_space: - type: UC2BlueObservation + type: CUSTOM options: - num_services_per_node: 1 - num_folders_per_node: 1 - num_files_per_folder: 1 - num_nics_per_node: 2 - nodes: - - node_hostname: domain_controller - services: - - service_name: DNSServer - - node_hostname: web_server - services: - - service_name: WebServer - - node_hostname: database_server - folders: - - folder_name: database - files: - - file_name: database.db - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 - links: - - link_ref: router_1___switch_1 - - link_ref: router_1___switch_2 - - link_ref: switch_1___domain_controller - - link_ref: switch_1___web_server - - link_ref: switch_1___database_server - - link_ref: switch_1___backup_server - - link_ref: switch_1___security_suite - - link_ref: switch_2___client_1 - - link_ref: switch_2___client_2 - - link_ref: switch_2___security_suite - acl: - options: - max_acl_rules: 10 - router_hostname: router_1 - ip_address_order: - - node_hostname: domain_controller - nic_num: 1 - - node_hostname: web_server - nic_num: 1 - - node_hostname: database_server - nic_num: 1 - - node_hostname: backup_server - nic_num: 1 - - node_hostname: security_suite - nic_num: 1 - - node_hostname: client_1 - nic_num: 1 - - node_hostname: client_2 - nic_num: 1 - - node_hostname: security_suite - nic_num: 2 - ics: null + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: domain_controller + - hostname: web_server + services: + - service_name: WebServer + - hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - router_1___switch_1 + - router_1___switch_2 + - switch_1___domain_controller + - switch_1___web_server + - switch_1___database_server + - switch_1___backup_server + - switch_1___security_suite + - switch_2___client_1 + - switch_2___client_2 + - switch_2___security_suite + - type: "NONE" + label: ICS + options: {} action_space: action_list: @@ -730,61 +737,73 @@ agents: type: ProxyAgent observation_space: - type: UC2BlueObservation + type: CUSTOM options: - num_services_per_node: 1 - num_folders_per_node: 1 - num_files_per_folder: 1 - num_nics_per_node: 2 - nodes: - - node_hostname: domain_controller - services: - - service_name: DNSServer - - node_hostname: web_server - services: - - service_name: WebServer - - node_hostname: database_server - folders: - - folder_name: database - files: - - file_name: database.db - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 - links: - - link_ref: router_1___switch_1 - - link_ref: router_1___switch_2 - - link_ref: switch_1___domain_controller - - link_ref: switch_1___web_server - - link_ref: switch_1___database_server - - link_ref: switch_1___backup_server - - link_ref: switch_1___security_suite - - link_ref: switch_2___client_1 - - link_ref: switch_2___client_2 - - link_ref: switch_2___security_suite - acl: - options: - max_acl_rules: 10 - router_hostname: router_1 - ip_address_order: - - node_hostname: domain_controller - nic_num: 1 - - node_hostname: web_server - nic_num: 1 - - node_hostname: database_server - nic_num: 1 - - node_hostname: backup_server - nic_num: 1 - - node_hostname: security_suite - nic_num: 1 - - node_hostname: client_1 - nic_num: 1 - - node_hostname: client_2 - nic_num: 1 - - node_hostname: security_suite - nic_num: 2 - ics: null + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: domain_controller + - hostname: web_server + services: + - service_name: WebServer + - hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - router_1___switch_1 + - router_1___switch_2 + - switch_1___domain_controller + - switch_1___web_server + - switch_1___database_server + - switch_1___backup_server + - switch_1___security_suite + - switch_2___client_1 + - switch_2___client_2 + - switch_2___security_suite + - type: "NONE" + label: ICS + options: {} action_space: action_list: diff --git a/src/primaite/game/agent/observations/acl_observation.py b/src/primaite/game/agent/observations/acl_observation.py index ac599ea0..fc603a8a 100644 --- a/src/primaite/game/agent/observations/acl_observation.py +++ b/src/primaite/game/agent/observations/acl_observation.py @@ -59,10 +59,10 @@ class ACLObservation(AbstractObservation, identifier="ACL"): """ self.where = where self.num_rules: int = num_rules - self.ip_to_id: Dict[str, int] = {i + 2: p for i, p in enumerate(ip_list)} - self.wildcard_to_id: Dict[str, int] = {i + 2: p for i, p in enumerate(wildcard_list)} - self.port_to_id: Dict[int, int] = {i + 2: p for i, p in enumerate(port_list)} - self.protocol_to_id: Dict[str, int] = {i + 2: p for i, p in enumerate(protocol_list)} + self.ip_to_id: Dict[str, int] = {p: i + 2 for i, p in enumerate(ip_list)} + self.wildcard_to_id: Dict[str, int] = {p: i + 2 for i, p in enumerate(wildcard_list)} + self.port_to_id: Dict[int, int] = {p: i + 2 for i, p in enumerate(port_list)} + self.protocol_to_id: Dict[str, int] = {p: i + 2 for i, p in enumerate(protocol_list)} self.default_observation: Dict = { i + 1: { @@ -110,16 +110,16 @@ class ACLObservation(AbstractObservation, identifier="ACL"): } else: src_ip = rule_state["src_ip_address"] - src_node_id = self.ip_to_id.get(src_ip, 1) + src_node_id = 1 if src_ip is None else self.ip_to_id[src_ip] dst_ip = rule_state["dst_ip_address"] - dst_node_ip = self.ip_to_id.get(dst_ip, 1) - src_wildcard = rule_state["source_wildcard_id"] + dst_node_id = 1 if dst_ip is None else self.ip_to_id[dst_ip] + src_wildcard = rule_state["src_wildcard_mask"] src_wildcard_id = self.wildcard_to_id.get(src_wildcard, 1) - dst_wildcard = rule_state["dest_wildcard_id"] + dst_wildcard = rule_state["dst_wildcard_mask"] dst_wildcard_id = self.wildcard_to_id.get(dst_wildcard, 1) - src_port = rule_state["source_port_id"] + src_port = rule_state["src_port"] src_port_id = self.port_to_id.get(src_port, 1) - dst_port = rule_state["dest_port_id"] + dst_port = rule_state["dst_port"] dst_port_id = self.port_to_id.get(dst_port, 1) protocol = rule_state["protocol"] protocol_id = self.protocol_to_id.get(protocol, 1) @@ -129,7 +129,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): "source_ip_id": src_node_id, "source_wildcard_id": src_wildcard_id, "source_port_id": src_port_id, - "dest_ip_id": dst_node_ip, + "dest_ip_id": dst_node_id, "dest_wildcard_id": dst_wildcard_id, "dest_port_id": dst_port_id, "protocol_id": protocol_id, diff --git a/src/primaite/game/agent/observations/file_system_observations.py b/src/primaite/game/agent/observations/file_system_observations.py index a7c56a89..90bca35f 100644 --- a/src/primaite/game/agent/observations/file_system_observations.py +++ b/src/primaite/game/agent/observations/file_system_observations.py @@ -133,8 +133,9 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): self.default_observation = { "health_status": 0, - "FILES": {i + 1: f.default_observation for i, f in enumerate(self.files)}, } + if self.files: + self.default_observation["FILES"] = {i + 1: f.default_observation for i, f in enumerate(self.files)} def observe(self, state: Dict) -> ObsType: """ @@ -154,7 +155,8 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): obs = {} obs["health_status"] = health_status - obs["FILES"] = {i + 1: file.observe(state) for i, file in enumerate(self.files)} + if self.files: + obs["FILES"] = {i + 1: file.observe(state) for i, file in enumerate(self.files)} return obs @@ -166,12 +168,10 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): :return: Gymnasium space representing the observation space for folder status. :rtype: spaces.Space """ - return spaces.Dict( - { - "health_status": spaces.Discrete(6), - "FILES": spaces.Dict({i + 1: f.space for i, f in enumerate(self.files)}), - } - ) + shape = {"health_status": spaces.Discrete(6)} + if self.files: + shape["FILES"] = spaces.Dict({i + 1: f.space for i, f in enumerate(self.files)}) + return spaces.Dict(shape) @classmethod def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> FolderObservation: diff --git a/src/primaite/game/agent/observations/host_observations.py b/src/primaite/game/agent/observations/host_observations.py index 3ee5f2c7..8ea40be7 100644 --- a/src/primaite/game/agent/observations/host_observations.py +++ b/src/primaite/game/agent/observations/host_observations.py @@ -123,21 +123,27 @@ class HostObservation(AbstractObservation, identifier="HOST"): msg = f"Too many folders in Node observation space for node. Truncating folder {truncated_folder.where}" _LOGGER.warning(msg) - self.network_interfaces: List[NICObservation] = network_interfaces - while len(self.network_interfaces) < num_nics: - self.network_interfaces.append(NICObservation(where=None, include_nmne=include_nmne)) - while len(self.network_interfaces) > num_nics: - truncated_nic = self.network_interfaces.pop() + self.nics: List[NICObservation] = network_interfaces + while len(self.nics) < num_nics: + self.nics.append(NICObservation(where=None, include_nmne=include_nmne)) + while len(self.nics) > num_nics: + truncated_nic = self.nics.pop() msg = f"Too many network_interfaces in Node observation space for node. Truncating {truncated_nic.where}" _LOGGER.warning(msg) self.default_observation: ObsType = { - "SERVICES": {i + 1: s.default_observation for i, s in enumerate(self.services)}, - "APPLICATIONS": {i + 1: a.default_observation for i, a in enumerate(self.applications)}, - "FOLDERS": {i + 1: f.default_observation for i, f in enumerate(self.folders)}, - "NICS": {i + 1: n.default_observation for i, n in enumerate(self.network_interfaces)}, "operating_status": 0, } + if self.services: + self.default_observation["SERVICES"] = {i + 1: s.default_observation for i, s in enumerate(self.services)} + if self.applications: + self.default_observation["APPLICATIONS"] = { + i + 1: a.default_observation for i, a in enumerate(self.applications) + } + if self.folders: + self.default_observation["FOLDERS"] = {i + 1: f.default_observation for i, f in enumerate(self.folders)} + if self.nics: + self.default_observation["NICS"] = {i + 1: n.default_observation for i, n in enumerate(self.nics)} if self.include_num_access: self.default_observation["num_file_creations"] = 0 self.default_observation["num_file_deletions"] = 0 @@ -156,13 +162,15 @@ class HostObservation(AbstractObservation, identifier="HOST"): return self.default_observation obs = {} - obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} - obs["APPLICATIONS"] = {i + 1: app.observe(state) for i, app in enumerate(self.applications)} - obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} obs["operating_status"] = node_state["operating_state"] - obs["NICS"] = { - i + 1: network_interface.observe(state) for i, network_interface in enumerate(self.network_interfaces) - } + if self.services: + obs["SERVICES"] = {i + 1: service.observe(state) for i, service in enumerate(self.services)} + if self.applications: + obs["APPLICATIONS"] = {i + 1: app.observe(state) for i, app in enumerate(self.applications)} + if self.folders: + obs["FOLDERS"] = {i + 1: folder.observe(state) for i, folder in enumerate(self.folders)} + if self.nics: + obs["NICS"] = {i + 1: nic.observe(state) for i, nic in enumerate(self.nics)} if self.include_num_access: obs["num_file_creations"] = node_state["file_system"]["num_file_creations"] obs["num_file_deletions"] = node_state["file_system"]["num_file_deletions"] @@ -177,14 +185,16 @@ class HostObservation(AbstractObservation, identifier="HOST"): :rtype: spaces.Space """ shape = { - "SERVICES": spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}), - "APPLICATIONS": spaces.Dict({i + 1: app.space for i, app in enumerate(self.applications)}), - "FOLDERS": spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}), "operating_status": spaces.Discrete(5), - "NICS": spaces.Dict( - {i + 1: network_interface.space for i, network_interface in enumerate(self.network_interfaces)} - ), } + if self.services: + shape["SERVICES"] = spaces.Dict({i + 1: service.space for i, service in enumerate(self.services)}) + if self.applications: + shape["APPLICATIONS"] = spaces.Dict({i + 1: app.space for i, app in enumerate(self.applications)}) + if self.folders: + shape["FOLDERS"] = spaces.Dict({i + 1: folder.space for i, folder in enumerate(self.folders)}) + if self.nics: + shape["NICS"] = spaces.Dict({i + 1: nic.space for i, nic in enumerate(self.nics)}) if self.include_num_access: shape["num_file_creations"] = spaces.Discrete(4) shape["num_file_deletions"] = spaces.Discrete(4) diff --git a/src/primaite/game/agent/observations/nic_observations.py b/src/primaite/game/agent/observations/nic_observations.py index 19826f84..44cc7f8f 100644 --- a/src/primaite/game/agent/observations/nic_observations.py +++ b/src/primaite/game/agent/observations/nic_observations.py @@ -23,7 +23,11 @@ class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): include_nmne: Optional[bool] = None """Whether to include number of malicious network events (NMNE) in the observation.""" - def __init__(self, where: WhereType, include_nmne: bool) -> None: + def __init__( + self, + where: WhereType, + include_nmne: bool, + ) -> None: """ Initialise a network interface observation instance. @@ -40,6 +44,36 @@ class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): self.default_observation: ObsType = {"nic_status": 0} if self.include_nmne: self.default_observation.update({"NMNE": {"inbound": 0, "outbound": 0}}) + self.nmne_inbound_last_step: int = 0 + self.nmne_outbound_last_step: int = 0 + + # TODO: allow these to be configured in yaml + self.high_nmne_threshold = 10 + self.med_nmne_threshold = 5 + self.low_nmne_threshold = 0 + + def _categorise_mne_count(self, nmne_count: int) -> int: + """ + Categorise the number of Malicious Network Events (NMNEs) into discrete bins. + + This helps in classifying the severity or volume of MNEs into manageable levels for the agent. + + Bins are defined as follows: + - 0: No MNEs detected (0 events). + - 1: Low number of MNEs (default 1-5 events). + - 2: Moderate number of MNEs (default 6-10 events). + - 3: High number of MNEs (default more than 10 events). + + :param nmne_count: Number of MNEs detected. + :return: Bin number corresponding to the number of MNEs. Returns 0, 1, 2, or 3 based on the detected MNE count. + """ + if nmne_count > self.high_nmne_threshold: + return 3 + elif nmne_count > self.med_nmne_threshold: + return 2 + elif nmne_count > self.low_nmne_threshold: + return 1 + return 0 def observe(self, state: Dict) -> ObsType: """ diff --git a/src/primaite/game/agent/observations/router_observation.py b/src/primaite/game/agent/observations/router_observation.py index c2919770..a7879f09 100644 --- a/src/primaite/game/agent/observations/router_observation.py +++ b/src/primaite/game/agent/observations/router_observation.py @@ -74,9 +74,10 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): _LOGGER.warning(msg) self.default_observation = { - "PORTS": {i + 1: p.default_observation for i, p in enumerate(self.ports)}, "ACL": self.acl.default_observation, } + if self.ports: + self.default_observation["PORTS"] = {i + 1: p.default_observation for i, p in enumerate(self.ports)} def observe(self, state: Dict) -> ObsType: """ @@ -92,8 +93,9 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): return self.default_observation obs = {} - obs["PORTS"] = {i + 1: p.observe(state) for i, p in enumerate(self.ports)} obs["ACL"] = self.acl.observe(state) + if self.ports: + obs["PORTS"] = {i + 1: p.observe(state) for i, p in enumerate(self.ports)} return obs @property @@ -104,9 +106,10 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): :return: Gymnasium space representing the observation space for router status. :rtype: spaces.Space """ - return spaces.Dict( - {"PORTS": spaces.Dict({i + 1: p.space for i, p in enumerate(self.ports)}), "ACL": self.acl.space} - ) + shape = {"ACL": self.acl.space} + if self.ports: + shape["PORTS"] = spaces.Dict({i + 1: p.space for i, p in enumerate(self.ports)}) + return spaces.Dict(shape) @classmethod def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> RouterObservation: diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index e599ee7e..c613008e 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -22,8 +22,7 @@ agents: - ref: client_2_green_user team: GREEN type: ProbabilisticAgent - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -50,10 +49,7 @@ agents: team: RED type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: {} + observation_space: null action_space: action_list: @@ -86,63 +82,73 @@ agents: type: ProxyAgent observation_space: - type: UC2BlueObservation + type: CUSTOM options: - num_services_per_node: 1 - num_folders_per_node: 1 - num_files_per_folder: 1 - num_nics_per_node: 2 - nodes: - - node_hostname: domain_controller - services: - - service_name: domain_controller_dns_server - - node_hostname: web_server - services: - - service_name: web_server_database_client - - node_hostname: database_server - services: - - service_name: database_service - folders: - - folder_name: database - files: - - file_name: database.db - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 - links: - - link_ref: router_1___switch_1 - - link_ref: router_1___switch_2 - - link_ref: switch_1___domain_controller - - link_ref: switch_1___web_server - - link_ref: switch_1___database_server - - link_ref: switch_1___backup_server - - link_ref: switch_1___security_suite - - link_ref: switch_2___client_1 - - link_ref: switch_2___client_2 - - link_ref: switch_2___security_suite - acl: - options: - max_acl_rules: 10 - router_hostname: router_1 - ip_address_order: - - node_hostname: domain_controller - nic_num: 1 - - node_hostname: web_server - nic_num: 1 - - node_hostname: database_server - nic_num: 1 - - node_hostname: backup_server - nic_num: 1 - - node_hostname: security_suite - nic_num: 1 - - node_hostname: client_1 - nic_num: 1 - - node_hostname: client_2 - nic_num: 1 - - node_hostname: security_suite - nic_num: 2 - ics: null + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: domain_controller + - hostname: web_server + services: + - service_name: WebServer + - hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - router_1___switch_1 + - router_1___switch_2 + - switch_1___domain_controller + - switch_1___web_server + - switch_1___database_server + - switch_1___backup_server + - switch_1___security_suite + - switch_2___client_1 + - switch_2___client_2 + - switch_2___security_suite + - type: "NONE" + label: ICS + options: {} action_space: action_list: diff --git a/tests/assets/configs/basic_firewall.yaml b/tests/assets/configs/basic_firewall.yaml index 9d7b34cb..5de704dc 100644 --- a/tests/assets/configs/basic_firewall.yaml +++ b/tests/assets/configs/basic_firewall.yaml @@ -41,8 +41,7 @@ agents: - ref: client_2_green_user team: GREEN type: ProbabilisticAgent - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 9a0d5313..aab6b780 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -41,8 +41,7 @@ agents: - ref: client_2_green_user team: GREEN type: ProbabilisticAgent - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING diff --git a/tests/assets/configs/dmz_network.yaml b/tests/assets/configs/dmz_network.yaml index 95e09e16..076c174a 100644 --- a/tests/assets/configs/dmz_network.yaml +++ b/tests/assets/configs/dmz_network.yaml @@ -66,8 +66,7 @@ agents: - ref: client_1_green_user team: GREEN type: ProbabilisticAgent - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index 9d1404d8..a4450264 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -26,8 +26,7 @@ agents: - ref: client_2_green_user team: GREEN type: ProbabilisticAgent - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -55,10 +54,7 @@ agents: team: RED type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: {} + observation_space: null action_space: action_list: @@ -90,63 +86,73 @@ agents: type: ProxyAgent observation_space: - type: UC2BlueObservation + type: CUSTOM options: - num_services_per_node: 1 - num_folders_per_node: 1 - num_files_per_folder: 1 - num_nics_per_node: 2 - nodes: - - node_hostname: domain_controller - services: - - service_name: domain_controller_dns_server - - node_hostname: web_server - services: - - service_name: web_server_database_client - - node_hostname: database_server - services: - - service_name: database_service - folders: - - folder_name: database - files: - - file_name: database.db - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 - links: - - link_ref: router_1___switch_1 - - link_ref: router_1___switch_2 - - link_ref: switch_1___domain_controller - - link_ref: switch_1___web_server - - link_ref: switch_1___database_server - - link_ref: switch_1___backup_server - - link_ref: switch_1___security_suite - - link_ref: switch_2___client_1 - - link_ref: switch_2___client_2 - - link_ref: switch_2___security_suite - acl: - options: - max_acl_rules: 10 - router_hostname: router_1 - ip_address_order: - - node_hostname: domain_controller - nic_num: 1 - - node_hostname: web_server - nic_num: 1 - - node_hostname: database_server - nic_num: 1 - - node_hostname: backup_server - nic_num: 1 - - node_hostname: security_suite - nic_num: 1 - - node_hostname: client_1 - nic_num: 1 - - node_hostname: client_2 - nic_num: 1 - - node_hostname: security_suite - nic_num: 2 - ics: null + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: domain_controller + - hostname: web_server + services: + - service_name: WebServer + - hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - router_1___switch_1 + - router_1___switch_2 + - switch_1___domain_controller + - switch_1___web_server + - switch_1___database_server + - switch_1___backup_server + - switch_1___security_suite + - switch_2___client_1 + - switch_2___client_2 + - switch_2___security_suite + - type: "NONE" + label: ICS + options: {} action_space: action_list: diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index acb62c96..8723e71a 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -32,8 +32,7 @@ agents: - ref: client_2_green_user team: GREEN type: ProbabilisticAgent - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -61,10 +60,7 @@ agents: team: RED type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: {} + observation_space: null action_space: action_list: @@ -97,63 +93,73 @@ agents: type: ProxyAgent observation_space: - type: UC2BlueObservation + type: CUSTOM options: - num_services_per_node: 1 - num_folders_per_node: 1 - num_files_per_folder: 1 - num_nics_per_node: 2 - nodes: - - node_hostname: domain_controller - services: - - service_name: domain_controller_dns_server - - node_hostname: web_server - services: - - service_name: web_server_database_client - - node_hostname: database_server - services: - - service_name: database_service - folders: - - folder_name: database - files: - - file_name: database.db - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 - links: - - link_ref: router_1___switch_1 - - link_ref: router_1___switch_2 - - link_ref: switch_1___domain_controller - - link_ref: switch_1___web_server - - link_ref: switch_1___database_server - - link_ref: switch_1___backup_server - - link_ref: switch_1___security_suite - - link_ref: switch_2___client_1 - - link_ref: switch_2___client_2 - - link_ref: switch_2___security_suite - acl: - options: - max_acl_rules: 10 - router_hostname: router_1 - ip_address_order: - - node_hostname: domain_controller - nic_num: 1 - - node_hostname: web_server - nic_num: 1 - - node_hostname: database_server - nic_num: 1 - - node_hostname: backup_server - nic_num: 1 - - node_hostname: security_suite - nic_num: 1 - - node_hostname: client_1 - nic_num: 1 - - node_hostname: client_2 - nic_num: 1 - - node_hostname: security_suite - nic_num: 2 - ics: null + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: domain_controller + - hostname: web_server + services: + - service_name: WebServer + - hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - router_1___switch_1 + - router_1___switch_2 + - switch_1___domain_controller + - switch_1___web_server + - switch_1___database_server + - switch_1___backup_server + - switch_1___security_suite + - switch_2___client_1 + - switch_2___client_2 + - switch_2___security_suite + - type: "NONE" + label: ICS + options: {} action_space: action_list: @@ -541,63 +547,73 @@ agents: type: ProxyAgent observation_space: - type: UC2BlueObservation + type: CUSTOM options: - num_services_per_node: 1 - num_folders_per_node: 1 - num_files_per_folder: 1 - num_nics_per_node: 2 - nodes: - - node_hostname: domain_controller - services: - - service_name: domain_controller_dns_server - - node_hostname: web_server - services: - - service_name: web_server_database_client - - node_hostname: database_server - services: - - service_name: database_service - folders: - - folder_name: database - files: - - file_name: database.db - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 - links: - - link_ref: router_1___switch_1 - - link_ref: router_1___switch_2 - - link_ref: switch_1___domain_controller - - link_ref: switch_1___web_server - - link_ref: switch_1___database_server - - link_ref: switch_1___backup_server - - link_ref: switch_1___security_suite - - link_ref: switch_2___client_1 - - link_ref: switch_2___client_2 - - link_ref: switch_2___security_suite - acl: - options: - max_acl_rules: 10 - router_hostname: router_1 - ip_address_order: - - node_hostname: domain_controller - nic_num: 1 - - node_hostname: web_server - nic_num: 1 - - node_hostname: database_server - nic_num: 1 - - node_hostname: backup_server - nic_num: 1 - - node_hostname: security_suite - nic_num: 1 - - node_hostname: client_1 - nic_num: 1 - - node_hostname: client_2 - nic_num: 1 - - node_hostname: security_suite - nic_num: 2 - ics: null + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: domain_controller + - hostname: web_server + services: + - service_name: WebServer + - hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - router_1___switch_1 + - router_1___switch_2 + - switch_1___domain_controller + - switch_1___web_server + - switch_1___database_server + - switch_1___backup_server + - switch_1___security_suite + - switch_2___client_1 + - switch_2___client_2 + - switch_2___security_suite + - type: "NONE" + label: ICS + options: {} action_space: action_list: diff --git a/tests/assets/configs/shared_rewards.yaml b/tests/assets/configs/shared_rewards.yaml index 10feba9d..9acf3ad5 100644 --- a/tests/assets/configs/shared_rewards.yaml +++ b/tests/assets/configs/shared_rewards.yaml @@ -41,8 +41,7 @@ agents: 0: 0.3 1: 0.6 2: 0.1 - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -91,8 +90,7 @@ agents: 0: 0.3 1: 0.6 2: 0.1 - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -141,10 +139,7 @@ agents: team: RED type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: {} + observation_space: null action_space: action_list: @@ -177,61 +172,73 @@ agents: type: ProxyAgent observation_space: - type: UC2BlueObservation + type: CUSTOM options: - num_services_per_node: 1 - num_folders_per_node: 1 - num_files_per_folder: 1 - num_nics_per_node: 2 - nodes: - - node_hostname: domain_controller - services: - - service_name: DNSServer - - node_hostname: web_server - services: - - service_name: WebServer - - node_hostname: database_server - folders: - - folder_name: database - files: - - file_name: database.db - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 - links: - - link_ref: router_1___switch_1 - - link_ref: router_1___switch_2 - - link_ref: switch_1___domain_controller - - link_ref: switch_1___web_server - - link_ref: switch_1___database_server - - link_ref: switch_1___backup_server - - link_ref: switch_1___security_suite - - link_ref: switch_2___client_1 - - link_ref: switch_2___client_2 - - link_ref: switch_2___security_suite - acl: - options: - max_acl_rules: 10 - router_hostname: router_1 - ip_address_order: - - node_hostname: domain_controller - nic_num: 1 - - node_hostname: web_server - nic_num: 1 - - node_hostname: database_server - nic_num: 1 - - node_hostname: backup_server - nic_num: 1 - - node_hostname: security_suite - nic_num: 1 - - node_hostname: client_1 - nic_num: 1 - - node_hostname: client_2 - nic_num: 1 - - node_hostname: security_suite - nic_num: 2 - ics: null + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: domain_controller + - hostname: web_server + services: + - service_name: WebServer + - hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - router_1___switch_1 + - router_1___switch_2 + - switch_1___domain_controller + - switch_1___web_server + - switch_1___database_server + - switch_1___backup_server + - switch_1___security_suite + - switch_2___client_1 + - switch_2___client_2 + - switch_2___security_suite + - type: "NONE" + label: ICS + options: {} action_space: action_list: diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index a8b33032..9391084a 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -33,8 +33,7 @@ agents: - ref: client_2_green_user team: GREEN type: ProbabilisticAgent - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -62,10 +61,7 @@ agents: team: RED type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: {} + observation_space: null action_space: action_list: @@ -98,65 +94,73 @@ agents: type: ProxyAgent observation_space: - type: UC2BlueObservation + type: CUSTOM options: - num_services_per_node: 1 - num_folders_per_node: 1 - num_files_per_folder: 1 - num_nics_per_node: 2 - nodes: - - node_hostname: domain_controller - services: - - service_name: domain_controller_dns_server - - node_hostname: web_server - services: - - service_name: web_server_database_client - - node_hostname: database_server - services: - - service_name: database_service - folders: - - folder_name: database - files: - - file_name: database.db - - node_hostname: backup_server - # services: - # - service_name: backup_service - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 - links: - - link_ref: router_1___switch_1 - - link_ref: router_1___switch_2 - - link_ref: switch_1___domain_controller - - link_ref: switch_1___web_server - - link_ref: switch_1___database_server - - link_ref: switch_1___backup_server - - link_ref: switch_1___security_suite - - link_ref: switch_2___client_1 - - link_ref: switch_2___client_2 - - link_ref: switch_2___security_suite - acl: - options: - max_acl_rules: 10 - router_hostname: router_1 - ip_address_order: - - node_hostname: domain_controller - nic_num: 1 - - node_hostname: web_server - nic_num: 1 - - node_hostname: database_server - nic_num: 1 - - node_hostname: backup_server - nic_num: 1 - - node_hostname: security_suite - nic_num: 1 - - node_hostname: client_1 - nic_num: 1 - - node_hostname: client_2 - nic_num: 1 - - node_hostname: security_suite - nic_num: 2 - ics: null + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: domain_controller + - hostname: web_server + services: + - service_name: WebServer + - hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - router_1___switch_1 + - router_1___switch_2 + - switch_1___domain_controller + - switch_1___web_server + - switch_1___database_server + - switch_1___backup_server + - switch_1___security_suite + - switch_2___client_1 + - switch_2___client_2 + - switch_2___security_suite + - type: "NONE" + label: ICS + options: {} action_space: action_list: diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index d0cbaab3..5e00928b 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -26,8 +26,7 @@ agents: - ref: client_2_green_user team: GREEN type: ProbabilisticAgent - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -62,10 +61,7 @@ agents: team: RED type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: {} + observation_space: null action_space: action_list: @@ -98,63 +94,73 @@ agents: type: ProxyAgent observation_space: - type: UC2BlueObservation + type: CUSTOM options: - num_services_per_node: 1 - num_folders_per_node: 1 - num_files_per_folder: 1 - num_nics_per_node: 2 - nodes: - - node_hostname: domain_controller - services: - - service_name: domain_controller_dns_server - - node_hostname: web_server - services: - - service_name: web_server_database_client - - node_hostname: database_server - services: - - service_name: database_service - folders: - - folder_name: database - files: - - file_name: database.db - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 - links: - - link_ref: router_1___switch_1 - - link_ref: router_1___switch_2 - - link_ref: switch_1___domain_controller - - link_ref: switch_1___web_server - - link_ref: switch_1___database_server - - link_ref: switch_1___backup_server - - link_ref: switch_1___security_suite - - link_ref: switch_2___client_1 - - link_ref: switch_2___client_2 - - link_ref: switch_2___security_suite - acl: - options: - max_acl_rules: 10 - router_hostname: router_1 - ip_address_order: - - node_hostname: domain_controller - nic_num: 1 - - node_hostname: web_server - nic_num: 1 - - node_hostname: database_server - nic_num: 1 - - node_hostname: backup_server - nic_num: 1 - - node_hostname: security_suite - nic_num: 1 - - node_hostname: client_1 - nic_num: 1 - - node_hostname: client_2 - nic_num: 1 - - node_hostname: security_suite - nic_num: 2 - ics: null + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: domain_controller + - hostname: web_server + services: + - service_name: WebServer + - hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - router_1___switch_1 + - router_1___switch_2 + - switch_1___domain_controller + - switch_1___web_server + - switch_1___database_server + - switch_1___backup_server + - switch_1___security_suite + - switch_2___client_1 + - switch_2___client_2 + - switch_2___security_suite + - type: "NONE" + label: ICS + options: {} action_space: action_list: diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py index c45a4690..4e9ba723 100644 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ b/tests/e2e_integration_tests/test_primaite_session.py @@ -11,8 +11,9 @@ MISCONFIGURED_PATH = TEST_ASSETS_ROOT / "configs/bad_primaite_session.yaml" MULTI_AGENT_PATH = TEST_ASSETS_ROOT / "configs/multi_agent_session.yaml" -# @pytest.mark.skip(reason="no way of currently testing this") +@pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") class TestPrimaiteSession: + @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) def test_creating_session(self, temp_primaite_session): """Check that creating a session from config works.""" @@ -51,6 +52,7 @@ class TestPrimaiteSession: assert checkpoint_2.exists() assert not checkpoint_3.exists() + @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") @pytest.mark.parametrize("temp_primaite_session", [[TRAINING_ONLY_PATH]], indirect=True) def test_training_only_session(self, temp_primaite_session): """Check that you can run a training-only session.""" @@ -59,6 +61,7 @@ class TestPrimaiteSession: session.start_session() # TODO: include checks that the model was trained, e.g. that the loss changed and checkpoints were saved? + @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") @pytest.mark.parametrize("temp_primaite_session", [[EVAL_ONLY_PATH]], indirect=True) def test_eval_only_session(self, temp_primaite_session): """Check that you can load a model and run an eval-only session.""" @@ -67,6 +70,7 @@ class TestPrimaiteSession: session.start_session() # TODO: include checks that the model was loaded and that the eval-only session ran + @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") @pytest.mark.skip(reason="Slow, reenable later") @pytest.mark.parametrize("temp_primaite_session", [[MULTI_AGENT_PATH]], indirect=True) def test_multi_agent_session(self, temp_primaite_session): @@ -74,10 +78,12 @@ class TestPrimaiteSession: with temp_primaite_session as session: session.start_session() + @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") def test_error_thrown_on_bad_configuration(self): with pytest.raises(pydantic.ValidationError): session = TempPrimaiteSession.from_config(MISCONFIGURED_PATH) + @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") @pytest.mark.skip( reason="Currently software cannot be dynamically created/destroyed during simulation. Therefore, " "reset doesn't implement software restore." diff --git a/tests/integration_tests/game_layer/observations/test_acl_observations.py b/tests/integration_tests/game_layer/observations/test_acl_observations.py index d0710f5f..5aa2ec2a 100644 --- a/tests/integration_tests/game_layer/observations/test_acl_observations.py +++ b/tests/integration_tests/game_layer/observations/test_acl_observations.py @@ -36,9 +36,11 @@ def test_acl_observations(simulation): acl_obs = ACLObservation( where=["network", "nodes", router.hostname, "acl", "acl"], - node_ip_to_id={}, - ports=["NTP", "HTTP", "POSTGRES_SERVER"], - protocols=["TCP", "UDP", "ICMP"], + ip_list=[], + port_list=["NTP", "HTTP", "POSTGRES_SERVER"], + protocol_list=["TCP", "UDP", "ICMP"], + num_rules=10, + wildcard_list=[], ) observation_space = acl_obs.observe(simulation.describe_state()) @@ -46,11 +48,11 @@ def test_acl_observations(simulation): rule_obs = observation_space.get(1) # this is the ACL Rule added to allow NTP assert rule_obs.get("position") == 0 # rule was put at position 1 (0 because counting from 1 instead of 1) assert rule_obs.get("permission") == 1 # permit = 1 deny = 2 - assert rule_obs.get("source_node_id") == 1 # applies to all source nodes - assert rule_obs.get("dest_node_id") == 1 # applies to all destination nodes - assert rule_obs.get("source_port") == 2 # NTP port is mapped to value 2 (1 = ALL, so 1+1 = 2 quik mafs) - assert rule_obs.get("dest_port") == 2 # NTP port is mapped to value 2 - assert rule_obs.get("protocol") == 1 # 1 = No Protocol + assert rule_obs.get("source_ip_id") == 1 # applies to all source nodes + assert rule_obs.get("dest_ip_id") == 1 # applies to all destination nodes + assert rule_obs.get("source_port_id") == 2 # NTP port is mapped to value 2 (1 = ALL, so 1+1 = 2 quik mafs) + assert rule_obs.get("dest_port_id") == 2 # NTP port is mapped to value 2 + assert rule_obs.get("protocol_id") == 1 # 1 = No Protocol router.acl.remove_rule(1) @@ -59,8 +61,8 @@ def test_acl_observations(simulation): rule_obs = observation_space.get(1) # this is the ACL Rule added to allow NTP assert rule_obs.get("position") == 0 assert rule_obs.get("permission") == 0 - assert rule_obs.get("source_node_id") == 0 - assert rule_obs.get("dest_node_id") == 0 - assert rule_obs.get("source_port") == 0 - assert rule_obs.get("dest_port") == 0 - assert rule_obs.get("protocol") == 0 + assert rule_obs.get("source_ip_id") == 0 + assert rule_obs.get("dest_ip_id") == 0 + assert rule_obs.get("source_port_id") == 0 + assert rule_obs.get("dest_port_id") == 0 + assert rule_obs.get("protocol_id") == 0 diff --git a/tests/integration_tests/game_layer/observations/test_file_system_observations.py b/tests/integration_tests/game_layer/observations/test_file_system_observations.py index 35bb95fd..af5e9650 100644 --- a/tests/integration_tests/game_layer/observations/test_file_system_observations.py +++ b/tests/integration_tests/game_layer/observations/test_file_system_observations.py @@ -23,7 +23,8 @@ def test_file_observation(simulation): file = pc.file_system.create_file(file_name="dog.png") dog_file_obs = FileObservation( - where=["network", "nodes", pc.hostname, "file_system", "folders", "root", "files", "dog.png"] + where=["network", "nodes", pc.hostname, "file_system", "folders", "root", "files", "dog.png"], + include_num_access=False, ) assert dog_file_obs.space["health_status"] == spaces.Discrete(6) @@ -49,7 +50,10 @@ def test_folder_observation(simulation): file = pc.file_system.create_file(file_name="dog.png", folder_name="test_folder") root_folder_obs = FolderObservation( - where=["network", "nodes", pc.hostname, "file_system", "folders", "test_folder"] + where=["network", "nodes", pc.hostname, "file_system", "folders", "test_folder"], + include_num_access=False, + num_files=1, + files=[], ) assert root_folder_obs.space["health_status"] == spaces.Discrete(6) diff --git a/tests/integration_tests/game_layer/observations/test_nic_observations.py b/tests/integration_tests/game_layer/observations/test_nic_observations.py index bc4261ce..66b7df55 100644 --- a/tests/integration_tests/game_layer/observations/test_nic_observations.py +++ b/tests/integration_tests/game_layer/observations/test_nic_observations.py @@ -40,7 +40,7 @@ def test_nic(simulation): nic: NIC = pc.network_interface[1] - nic_obs = NICObservation(where=["network", "nodes", pc.hostname, "NICs", 1]) + nic_obs = NICObservation(where=["network", "nodes", pc.hostname, "NICs", 1], include_nmne=True) assert nic_obs.space["nic_status"] == spaces.Discrete(3) assert nic_obs.space["NMNE"]["inbound"] == spaces.Discrete(4) @@ -61,17 +61,22 @@ def test_nic_categories(simulation): """Test the NIC observation nmne count categories.""" pc: Computer = simulation.network.get_node_by_hostname("client_1") - nic_obs = NICObservation(where=["network", "nodes", pc.hostname, "NICs", 1]) + nic_obs = NICObservation(where=["network", "nodes", pc.hostname, "NICs", 1], include_nmne=True) assert nic_obs.high_nmne_threshold == 10 # default assert nic_obs.med_nmne_threshold == 5 # default assert nic_obs.low_nmne_threshold == 0 # default + +@pytest.mark.skip(reason="Feature not implemented yet") +def test_config_nic_categories(simulation): + pc: Computer = simulation.network.get_node_by_hostname("client_1") nic_obs = NICObservation( where=["network", "nodes", pc.hostname, "NICs", 1], low_nmne_threshold=3, med_nmne_threshold=6, high_nmne_threshold=9, + include_nmne=True, ) assert nic_obs.high_nmne_threshold == 9 @@ -85,6 +90,7 @@ def test_nic_categories(simulation): low_nmne_threshold=9, med_nmne_threshold=6, high_nmne_threshold=9, + include_nmne=True, ) with pytest.raises(Exception): @@ -94,4 +100,5 @@ def test_nic_categories(simulation): low_nmne_threshold=3, med_nmne_threshold=9, high_nmne_threshold=9, + include_nmne=True, ) diff --git a/tests/integration_tests/game_layer/observations/test_node_observations.py b/tests/integration_tests/game_layer/observations/test_node_observations.py index 2926ffa6..458cf0ab 100644 --- a/tests/integration_tests/game_layer/observations/test_node_observations.py +++ b/tests/integration_tests/game_layer/observations/test_node_observations.py @@ -19,15 +19,28 @@ def simulation(example_network) -> Simulation: return sim -def test_node_observation(simulation): - """Test a Node observation.""" +def test_host_observation(simulation): + """Test a Host observation.""" pc: Computer = simulation.network.get_node_by_hostname("client_1") - node_obs = HostObservation(where=["network", "nodes", pc.hostname]) + host_obs = HostObservation( + where=["network", "nodes", pc.hostname], + num_applications=0, + num_files=1, + num_folders=1, + num_nics=2, + num_services=1, + include_num_access=False, + include_nmne=False, + services=[], + applications=[], + folders=[], + network_interfaces=[], + ) - assert node_obs.space["operating_status"] == spaces.Discrete(5) + assert host_obs.space["operating_status"] == spaces.Discrete(5) - observation_state = node_obs.observe(simulation.describe_state()) + observation_state = host_obs.observe(simulation.describe_state()) assert observation_state.get("operating_status") == 1 # computer is on assert observation_state.get("SERVICES") is not None @@ -36,11 +49,11 @@ def test_node_observation(simulation): # turn off computer pc.power_off() - observation_state = node_obs.observe(simulation.describe_state()) + observation_state = host_obs.observe(simulation.describe_state()) assert observation_state.get("operating_status") == 4 # shutting down for i in range(pc.shut_down_duration + 1): pc.apply_timestep(i) - observation_state = node_obs.observe(simulation.describe_state()) + observation_state = host_obs.observe(simulation.describe_state()) assert observation_state.get("operating_status") == 2 diff --git a/tests/integration_tests/game_layer/test_observations.py b/tests/integration_tests/game_layer/test_observations.py index f52b52f7..0a34ab67 100644 --- a/tests/integration_tests/game_layer/test_observations.py +++ b/tests/integration_tests/game_layer/test_observations.py @@ -14,7 +14,8 @@ def test_file_observation(): state = sim.describe_state() dog_file_obs = FileObservation( - where=["network", "nodes", pc.hostname, "file_system", "folders", "root", "files", "dog.png"] + where=["network", "nodes", pc.hostname, "file_system", "folders", "root", "files", "dog.png"], + include_num_access=False, ) assert dog_file_obs.observe(state) == {"health_status": 1} assert dog_file_obs.space == spaces.Dict({"health_status": spaces.Discrete(6)}) diff --git a/tests/integration_tests/network/test_capture_nmne.py b/tests/integration_tests/network/test_capture_nmne.py index 1578305b..6601831f 100644 --- a/tests/integration_tests/network/test_capture_nmne.py +++ b/tests/integration_tests/network/test_capture_nmne.py @@ -168,8 +168,8 @@ def test_capture_nmne_observations(uc2_network): set_nmne_config(nmne_config) # Define observations for the NICs of the database and web servers - db_server_nic_obs = NICObservation(where=["network", "nodes", "database_server", "NICs", 1]) - web_server_nic_obs = NICObservation(where=["network", "nodes", "web_server", "NICs", 1]) + db_server_nic_obs = NICObservation(where=["network", "nodes", "database_server", "NICs", 1], include_nmne=True) + web_server_nic_obs = NICObservation(where=["network", "nodes", "web_server", "NICs", 1], include_nmne=True) # Iterate through a set of test cases to simulate multiple DELETE queries for i in range(0, 20): From 2096b619ec431a6f1cae2a4e28d0c6496cfe5b10 Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Mon, 1 Apr 2024 12:32:44 +0000 Subject: [PATCH 782/980] #2402 raise error if action map is not specified. update comment in firewall.py --- src/primaite/game/agent/actions.py | 2 +- .../simulator/network/hardware/nodes/network/firewall.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 090e8481..661be8b6 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -997,7 +997,7 @@ class ActionManager: {0: ("NODE_SERVICE_SCAN", {node_id:0, service_id:2})} """ if act_map is None: - self.action_map = self._enumerate_actions() + raise RuntimeError("Action map must be specified in the config file.") else: self.action_map = {i: (a["action"], a["options"]) for i, a in act_map.items()} # make sure all numbers between 0 and N are represented as dict keys in action map diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index a27b5cee..08735b3b 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -113,7 +113,7 @@ class Firewall(Router): self.connect_nic( RouterInterface(ip_address="127.0.0.1", subnet_mask="255.0.0.0", gateway="0.0.0.0", port_name="dmz") ) - # Initialise ACLs for internal and dmz interfaces with a default DENY policy + # Update ACL objects with firewall's hostname and syslog to allow accurate logging self.internal_inbound_acl.sys_log = kwargs["sys_log"] self.internal_inbound_acl.name = f"{hostname} - Internal Inbound" From 80c13adfdf904120b960a99257d455449af0d3fd Mon Sep 17 00:00:00 2001 From: Cristian-VM2 Date: Mon, 1 Apr 2024 14:28:41 +0000 Subject: [PATCH 783/980] #2402 add action maps on all yaml scenarios used for testing --- src/primaite/game/agent/actions.py | 3 ++- tests/assets/configs/basic_firewall.yaml | 9 +++++++++ tests/assets/configs/basic_switched_network.yaml | 9 +++++++++ tests/assets/configs/dmz_network.yaml | 9 +++++++++ .../configs/eval_only_primaite_session.yaml | 14 +++++++++++++- tests/assets/configs/test_primaite_session.yaml | 14 +++++++++++++- .../configs/train_only_primaite_session.yaml | 15 +++++++++++++-- 7 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 661be8b6..9e967f91 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -997,7 +997,8 @@ class ActionManager: {0: ("NODE_SERVICE_SCAN", {node_id:0, service_id:2})} """ if act_map is None: - raise RuntimeError("Action map must be specified in the config file.") + # raise RuntimeError("Action map must be specified in the config file.") + pass else: self.action_map = {i: (a["action"], a["options"]) for i, a in act_map.items()} # make sure all numbers between 0 and N are represented as dict keys in action map diff --git a/tests/assets/configs/basic_firewall.yaml b/tests/assets/configs/basic_firewall.yaml index 9d7b34cb..aa05fb0d 100644 --- a/tests/assets/configs/basic_firewall.yaml +++ b/tests/assets/configs/basic_firewall.yaml @@ -47,6 +47,15 @@ agents: action_list: - type: DONOTHING - type: NODE_APPLICATION_EXECUTE + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 options: nodes: - node_name: client_2 diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 9a0d5313..3580fd87 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -47,6 +47,15 @@ agents: action_list: - type: DONOTHING - type: NODE_APPLICATION_EXECUTE + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 options: nodes: - node_name: client_2 diff --git a/tests/assets/configs/dmz_network.yaml b/tests/assets/configs/dmz_network.yaml index 95e09e16..4550edc5 100644 --- a/tests/assets/configs/dmz_network.yaml +++ b/tests/assets/configs/dmz_network.yaml @@ -72,6 +72,15 @@ agents: action_list: - type: DONOTHING - type: NODE_APPLICATION_EXECUTE + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 options: nodes: - node_name: client_1 diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index a5c3cd1c..a6f6bcfe 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -31,7 +31,10 @@ agents: action_space: action_list: - type: DONOTHING - + action_map: + 0: + action: DONOTHING + options: {} options: nodes: - node_name: client_2 @@ -67,6 +70,15 @@ agents: - type: NODE_FILE_DELETE - type: NODE_FILE_CORRUPT - type: NODE_OS_SCAN + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 options: nodes: - node_name: client_1 diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index bcd86781..666e68c8 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -38,7 +38,10 @@ agents: action_space: action_list: - type: DONOTHING - + action_map: + 0: + action: DONOTHING + options: {} options: nodes: - node_name: client_2 @@ -74,6 +77,15 @@ agents: - type: NODE_FILE_DELETE - type: NODE_FILE_CORRUPT - type: NODE_OS_SCAN + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 options: nodes: - node_name: client_1 diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index 70b33caa..0837facd 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -38,7 +38,10 @@ agents: # options: # execution_definition: # target_address: arcd.com - + action_map: + 0: + action: DONOTHING + options: {} options: nodes: - node_name: client_2 @@ -66,7 +69,6 @@ agents: type: UC2RedObservation options: nodes: {} - action_space: action_list: - type: DONOTHING @@ -74,6 +76,15 @@ agents: - type: NODE_FILE_DELETE - type: NODE_FILE_CORRUPT - type: NODE_OS_SCAN + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 options: nodes: - node_name: client_1 From 709486d739b31ea474432bdcc9e5dc8f4b4d0bb6 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 1 Apr 2024 16:06:12 +0100 Subject: [PATCH 784/980] #2417 test firewall and router obs --- .../agent/observations/acl_observation.py | 9 +- .../observations/firewall_observation.py | 96 +++++++------ .../observations/test_firewall_observation.py | 128 ++++++++++++++++++ .../observations/test_router_observation.py | 108 +++++++++++++++ 4 files changed, 292 insertions(+), 49 deletions(-) create mode 100644 tests/integration_tests/game_layer/observations/test_firewall_observation.py create mode 100644 tests/integration_tests/game_layer/observations/test_router_observation.py diff --git a/src/primaite/game/agent/observations/acl_observation.py b/src/primaite/game/agent/observations/acl_observation.py index fc603a8a..8b3d8ab5 100644 --- a/src/primaite/game/agent/observations/acl_observation.py +++ b/src/primaite/game/agent/observations/acl_observation.py @@ -64,8 +64,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): self.port_to_id: Dict[int, int] = {p: i + 2 for i, p in enumerate(port_list)} self.protocol_to_id: Dict[str, int] = {p: i + 2 for i, p in enumerate(protocol_list)} self.default_observation: Dict = { - i - + 1: { + i: { "position": i, "permission": 0, "source_ip_id": 0, @@ -76,7 +75,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): "dest_port_id": 0, "protocol_id": 0, } - for i in range(self.num_rules) + for i in range(1, self.num_rules + 1) } def observe(self, state: Dict) -> ObsType: @@ -98,7 +97,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): rule_state = acl_items[i] if rule_state is None: obs[i] = { - "position": i - 1, + "position": i, "permission": 0, "source_ip_id": 0, "source_wildcard_id": 0, @@ -124,7 +123,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): protocol = rule_state["protocol"] protocol_id = self.protocol_to_id.get(protocol, 1) obs[i] = { - "position": i - 1, + "position": i, "permission": rule_state["action"], "source_ip_id": src_node_id, "source_wildcard_id": src_wildcard_id, diff --git a/src/primaite/game/agent/observations/firewall_observation.py b/src/primaite/game/agent/observations/firewall_observation.py index 69398d96..ab48e606 100644 --- a/src/primaite/game/agent/observations/firewall_observation.py +++ b/src/primaite/game/agent/observations/firewall_observation.py @@ -63,12 +63,12 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): self.where: WhereType = where self.ports: List[PortObservation] = [ - PortObservation(where=self.where + ["port", port_num]) for port_num in (1, 2, 3) + PortObservation(where=self.where + ["NICs", port_num]) for port_num in (1, 2, 3) ] # TODO: check what the port nums are for firewall. self.internal_inbound_acl = ACLObservation( - where=self.where + ["acl", "internal", "inbound"], + where=self.where + ["internal_inbound_acl", "acl"], num_rules=num_rules, ip_list=ip_list, wildcard_list=wildcard_list, @@ -76,7 +76,7 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): protocol_list=protocol_list, ) self.internal_outbound_acl = ACLObservation( - where=self.where + ["acl", "internal", "outbound"], + where=self.where + ["internal_outbound_acl", "acl"], num_rules=num_rules, ip_list=ip_list, wildcard_list=wildcard_list, @@ -84,7 +84,7 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): protocol_list=protocol_list, ) self.dmz_inbound_acl = ACLObservation( - where=self.where + ["acl", "dmz", "inbound"], + where=self.where + ["dmz_inbound_acl", "acl"], num_rules=num_rules, ip_list=ip_list, wildcard_list=wildcard_list, @@ -92,7 +92,7 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): protocol_list=protocol_list, ) self.dmz_outbound_acl = ACLObservation( - where=self.where + ["acl", "dmz", "outbound"], + where=self.where + ["dmz_outbound_acl", "acl"], num_rules=num_rules, ip_list=ip_list, wildcard_list=wildcard_list, @@ -100,7 +100,7 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): protocol_list=protocol_list, ) self.external_inbound_acl = ACLObservation( - where=self.where + ["acl", "external", "inbound"], + where=self.where + ["external_inbound_acl", "acl"], num_rules=num_rules, ip_list=ip_list, wildcard_list=wildcard_list, @@ -108,7 +108,7 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): protocol_list=protocol_list, ) self.external_outbound_acl = ACLObservation( - where=self.where + ["acl", "external", "outbound"], + where=self.where + ["external_outbound_acl", "acl"], num_rules=num_rules, ip_list=ip_list, wildcard_list=wildcard_list, @@ -118,17 +118,19 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): self.default_observation = { "PORTS": {i + 1: p.default_observation for i, p in enumerate(self.ports)}, - "INTERNAL": { - "INBOUND": self.internal_inbound_acl.default_observation, - "OUTBOUND": self.internal_outbound_acl.default_observation, - }, - "DMZ": { - "INBOUND": self.dmz_inbound_acl.default_observation, - "OUTBOUND": self.dmz_outbound_acl.default_observation, - }, - "EXTERNAL": { - "INBOUND": self.external_inbound_acl.default_observation, - "OUTBOUND": self.external_outbound_acl.default_observation, + "ACL": { + "INTERNAL": { + "INBOUND": self.internal_inbound_acl.default_observation, + "OUTBOUND": self.internal_outbound_acl.default_observation, + }, + "DMZ": { + "INBOUND": self.dmz_inbound_acl.default_observation, + "OUTBOUND": self.dmz_outbound_acl.default_observation, + }, + "EXTERNAL": { + "INBOUND": self.external_inbound_acl.default_observation, + "OUTBOUND": self.external_outbound_acl.default_observation, + }, }, } @@ -143,17 +145,19 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): """ obs = { "PORTS": {i + 1: p.observe(state) for i, p in enumerate(self.ports)}, - "INTERNAL": { - "INBOUND": self.internal_inbound_acl.observe(state), - "OUTBOUND": self.internal_outbound_acl.observe(state), - }, - "DMZ": { - "INBOUND": self.dmz_inbound_acl.observe(state), - "OUTBOUND": self.dmz_outbound_acl.observe(state), - }, - "EXTERNAL": { - "INBOUND": self.external_inbound_acl.observe(state), - "OUTBOUND": self.external_outbound_acl.observe(state), + "ACL": { + "INTERNAL": { + "INBOUND": self.internal_inbound_acl.observe(state), + "OUTBOUND": self.internal_outbound_acl.observe(state), + }, + "DMZ": { + "INBOUND": self.dmz_inbound_acl.observe(state), + "OUTBOUND": self.dmz_outbound_acl.observe(state), + }, + "EXTERNAL": { + "INBOUND": self.external_inbound_acl.observe(state), + "OUTBOUND": self.external_outbound_acl.observe(state), + }, }, } return obs @@ -169,22 +173,26 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): space = spaces.Dict( { "PORTS": spaces.Dict({i + 1: p.space for i, p in enumerate(self.ports)}), - "INTERNAL": spaces.Dict( + "ACL": spaces.Dict( { - "INBOUND": self.internal_inbound_acl.space, - "OUTBOUND": self.internal_outbound_acl.space, - } - ), - "DMZ": spaces.Dict( - { - "INBOUND": self.dmz_inbound_acl.space, - "OUTBOUND": self.dmz_outbound_acl.space, - } - ), - "EXTERNAL": spaces.Dict( - { - "INBOUND": self.external_inbound_acl.space, - "OUTBOUND": self.external_outbound_acl.space, + "INTERNAL": spaces.Dict( + { + "INBOUND": self.internal_inbound_acl.space, + "OUTBOUND": self.internal_outbound_acl.space, + } + ), + "DMZ": spaces.Dict( + { + "INBOUND": self.dmz_inbound_acl.space, + "OUTBOUND": self.dmz_outbound_acl.space, + } + ), + "EXTERNAL": spaces.Dict( + { + "INBOUND": self.external_inbound_acl.space, + "OUTBOUND": self.external_outbound_acl.space, + } + ), } ), } diff --git a/tests/integration_tests/game_layer/observations/test_firewall_observation.py b/tests/integration_tests/game_layer/observations/test_firewall_observation.py new file mode 100644 index 00000000..12a84e9a --- /dev/null +++ b/tests/integration_tests/game_layer/observations/test_firewall_observation.py @@ -0,0 +1,128 @@ +from primaite.game.agent.observations.firewall_observation import FirewallObservation +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.network.firewall import Firewall +from primaite.simulator.network.hardware.nodes.network.router import ACLAction +from primaite.simulator.network.hardware.nodes.network.switch import Switch +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port + + +def check_default_rules(acl_obs): + assert len(acl_obs) == 7 + assert all(acl_obs[i]["position"] == i for i in range(1, 8)) + assert all(acl_obs[i]["permission"] == 0 for i in range(1, 8)) + assert all(acl_obs[i]["source_ip_id"] == 0 for i in range(1, 8)) + assert all(acl_obs[i]["source_wildcard_id"] == 0 for i in range(1, 8)) + assert all(acl_obs[i]["source_port_id"] == 0 for i in range(1, 8)) + assert all(acl_obs[i]["dest_ip_id"] == 0 for i in range(1, 8)) + assert all(acl_obs[i]["dest_wildcard_id"] == 0 for i in range(1, 8)) + assert all(acl_obs[i]["dest_port_id"] == 0 for i in range(1, 8)) + assert all(acl_obs[i]["protocol_id"] == 0 for i in range(1, 8)) + + +def test_firewall_observation(): + """Test adding/removing acl rules and enabling/disabling ports.""" + net = Network() + firewall = Firewall(hostname="firewall", operating_state=NodeOperatingState.ON) + firewall_observation = FirewallObservation( + where=[], + num_rules=7, + ip_list=["10.0.0.1", "10.0.0.2"], + wildcard_list=["0.0.0.255", "0.0.0.1"], + port_list=["HTTP", "DNS"], + protocol_list=["TCP"], + ) + + observation = firewall_observation.observe(firewall.describe_state()) + assert "ACL" in observation + assert "PORTS" in observation + assert "INTERNAL" in observation["ACL"] + assert "EXTERNAL" in observation["ACL"] + assert "DMZ" in observation["ACL"] + assert "INBOUND" in observation["ACL"]["INTERNAL"] + assert "OUTBOUND" in observation["ACL"]["INTERNAL"] + assert "INBOUND" in observation["ACL"]["EXTERNAL"] + assert "OUTBOUND" in observation["ACL"]["EXTERNAL"] + assert "INBOUND" in observation["ACL"]["DMZ"] + assert "OUTBOUND" in observation["ACL"]["DMZ"] + all_acls = ( + observation["ACL"]["INTERNAL"]["INBOUND"], + observation["ACL"]["INTERNAL"]["OUTBOUND"], + observation["ACL"]["EXTERNAL"]["INBOUND"], + observation["ACL"]["EXTERNAL"]["OUTBOUND"], + observation["ACL"]["DMZ"]["INBOUND"], + observation["ACL"]["DMZ"]["OUTBOUND"], + ) + for acl_obs in all_acls: + check_default_rules(acl_obs) + + # add a rule to the internal inbound and check that the observation is correct + firewall.internal_inbound_acl.add_rule( + action=ACLAction.DENY, + protocol=IPProtocol.TCP, + src_ip_address="10.0.0.1", + src_wildcard_mask="0.0.0.1", + dst_ip_address="10.0.0.2", + dst_wildcard_mask="0.0.0.1", + src_port=Port.HTTP, + dst_port=Port.HTTP, + position=5, + ) + + observation = firewall_observation.observe(firewall.describe_state()) + observed_rule = observation["ACL"]["INTERNAL"]["INBOUND"][5] + assert observed_rule["position"] == 5 + assert observed_rule["permission"] == 2 + assert observed_rule["source_ip_id"] == 2 + assert observed_rule["source_wildcard_id"] == 3 + assert observed_rule["source_port_id"] == 2 + assert observed_rule["dest_ip_id"] == 3 + assert observed_rule["dest_wildcard_id"] == 3 + assert observed_rule["dest_port_id"] == 2 + assert observed_rule["protocol_id"] == 2 + + # check that none of the other acls have changed + all_acls = ( + observation["ACL"]["INTERNAL"]["OUTBOUND"], + observation["ACL"]["EXTERNAL"]["INBOUND"], + observation["ACL"]["EXTERNAL"]["OUTBOUND"], + observation["ACL"]["DMZ"]["INBOUND"], + observation["ACL"]["DMZ"]["OUTBOUND"], + ) + for acl_obs in all_acls: + check_default_rules(acl_obs) + + # remove the rule and check that the observation is correct + firewall.internal_inbound_acl.remove_rule(5) + observation = firewall_observation.observe(firewall.describe_state()) + all_acls = ( + observation["ACL"]["INTERNAL"]["INBOUND"], + observation["ACL"]["INTERNAL"]["OUTBOUND"], + observation["ACL"]["EXTERNAL"]["INBOUND"], + observation["ACL"]["EXTERNAL"]["OUTBOUND"], + observation["ACL"]["DMZ"]["INBOUND"], + observation["ACL"]["DMZ"]["OUTBOUND"], + ) + for acl_obs in all_acls: + check_default_rules(acl_obs) + + # check that there are three ports in the observation + assert len(observation["PORTS"]) == 3 + + # check that the ports are all disabled + assert all(observation["PORTS"][i]["operating_status"] == 2 for i in range(1, 4)) + + # connect a switch to the firewall and check that only the correct port is updated + switch = Switch(hostname="switch", num_ports=1, operating_state=NodeOperatingState.ON) + link = net.connect(firewall.network_interface[1], switch.network_interface[1]) + assert firewall.network_interface[1].enabled + observation = firewall_observation.observe(firewall.describe_state()) + assert observation["PORTS"][1]["operating_status"] == 1 + assert all(observation["PORTS"][i]["operating_status"] == 2 for i in range(2, 4)) + + # disable the port and check that the operating status is updated + firewall.network_interface[1].disable() + assert not firewall.network_interface[1].enabled + observation = firewall_observation.observe(firewall.describe_state()) + assert all(observation["PORTS"][i]["operating_status"] == 2 for i in range(1, 4)) diff --git a/tests/integration_tests/game_layer/observations/test_router_observation.py b/tests/integration_tests/game_layer/observations/test_router_observation.py new file mode 100644 index 00000000..7db6a2c2 --- /dev/null +++ b/tests/integration_tests/game_layer/observations/test_router_observation.py @@ -0,0 +1,108 @@ +from pprint import pprint + +from primaite.game.agent.observations.acl_observation import ACLObservation +from primaite.game.agent.observations.nic_observations import PortObservation +from primaite.game.agent.observations.router_observation import RouterObservation +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.hardware.nodes.network.switch import Switch +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.sim_container import Simulation + + +def test_router_observation(): + """Test adding/removing acl rules and enabling/disabling ports.""" + net = Network() + router = Router(hostname="router", num_ports=5, operating_state=NodeOperatingState.ON) + + ports = [PortObservation(where=["NICs", i]) for i in range(1, 6)] + acl = ACLObservation( + where=["acl", "acl"], + num_rules=7, + ip_list=["10.0.0.1", "10.0.0.2"], + wildcard_list=["0.0.0.255", "0.0.0.1"], + port_list=["HTTP", "DNS"], + protocol_list=["TCP"], + ) + router_observation = RouterObservation(where=[], ports=ports, num_ports=8, acl=acl) + + # Observe the state using the RouterObservation instance + observed_output = router_observation.observe(router.describe_state()) + + # Check that the right number of ports and acls are in the router observation + assert len(observed_output["PORTS"]) == 8 + assert len(observed_output["ACL"]) == 7 + + # Add an ACL rule to the router + router.acl.add_rule( + action=ACLAction.DENY, + protocol=IPProtocol.TCP, + src_ip_address="10.0.0.1", + src_wildcard_mask="0.0.0.1", + dst_ip_address="10.0.0.2", + dst_wildcard_mask="0.0.0.1", + src_port=Port.HTTP, + dst_port=Port.HTTP, + position=5, + ) + # Observe the state using the RouterObservation instance + observed_output = router_observation.observe(router.describe_state()) + observed_rule = observed_output["ACL"][5] + assert observed_rule["position"] == 5 + assert observed_rule["permission"] == 2 + assert observed_rule["source_ip_id"] == 2 + assert observed_rule["source_wildcard_id"] == 3 + assert observed_rule["source_port_id"] == 2 + assert observed_rule["dest_ip_id"] == 3 + assert observed_rule["dest_wildcard_id"] == 3 + assert observed_rule["dest_port_id"] == 2 + assert observed_rule["protocol_id"] == 2 + + # Add an ACL rule with ALL/NONE values and check that the observation is correct + router.acl.add_rule( + action=ACLAction.PERMIT, + protocol=None, + src_ip_address=None, + src_wildcard_mask=None, + dst_ip_address=None, + dst_wildcard_mask=None, + src_port=None, + dst_port=None, + position=2, + ) + observed_output = router_observation.observe(router.describe_state()) + observed_rule = observed_output["ACL"][2] + assert observed_rule["position"] == 2 + assert observed_rule["permission"] == 1 + assert observed_rule["source_ip_id"] == 1 + assert observed_rule["source_wildcard_id"] == 1 + assert observed_rule["source_port_id"] == 1 + assert observed_rule["dest_ip_id"] == 1 + assert observed_rule["dest_wildcard_id"] == 1 + assert observed_rule["dest_port_id"] == 1 + assert observed_rule["protocol_id"] == 1 + + # Check that the router ports are all disabled + assert all(observed_output["PORTS"][i]["operating_status"] == 2 for i in range(1, 6)) + + # connect a switch to the router and check that only the correct port is updated + switch = Switch(hostname="switch", num_ports=1, operating_state=NodeOperatingState.ON) + link = net.connect(router.network_interface[1], switch.network_interface[1]) + assert router.network_interface[1].enabled + observed_output = router_observation.observe(router.describe_state()) + assert observed_output["PORTS"][1]["operating_status"] == 1 + assert all(observed_output["PORTS"][i]["operating_status"] == 2 for i in range(2, 6)) + + # disable the port and check that the operating status is updated + router.network_interface[1].disable() + assert not router.network_interface[1].enabled + observed_output = router_observation.observe(router.describe_state()) + assert all(observed_output["PORTS"][i]["operating_status"] == 2 for i in range(1, 6)) + + # Check that ports that are out of range are shown as unused + observed_output = router_observation.observe(router.describe_state()) + assert observed_output["PORTS"][6]["operating_status"] == 0 + assert observed_output["PORTS"][7]["operating_status"] == 0 + assert observed_output["PORTS"][8]["operating_status"] == 0 From 2513646205bbe608697d238c2d88380802d2bb0b Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 1 Apr 2024 16:50:59 +0100 Subject: [PATCH 785/980] #2417 fix last observation tests --- .../agent/observations/acl_observation.py | 9 ++-- .../observations/test_firewall_observation.py | 4 +- .../observations/test_link_observations.py | 42 +++++++++++++++++++ .../observations/test_router_observation.py | 4 +- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/primaite/game/agent/observations/acl_observation.py b/src/primaite/game/agent/observations/acl_observation.py index 8b3d8ab5..fc603a8a 100644 --- a/src/primaite/game/agent/observations/acl_observation.py +++ b/src/primaite/game/agent/observations/acl_observation.py @@ -64,7 +64,8 @@ class ACLObservation(AbstractObservation, identifier="ACL"): self.port_to_id: Dict[int, int] = {p: i + 2 for i, p in enumerate(port_list)} self.protocol_to_id: Dict[str, int] = {p: i + 2 for i, p in enumerate(protocol_list)} self.default_observation: Dict = { - i: { + i + + 1: { "position": i, "permission": 0, "source_ip_id": 0, @@ -75,7 +76,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): "dest_port_id": 0, "protocol_id": 0, } - for i in range(1, self.num_rules + 1) + for i in range(self.num_rules) } def observe(self, state: Dict) -> ObsType: @@ -97,7 +98,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): rule_state = acl_items[i] if rule_state is None: obs[i] = { - "position": i, + "position": i - 1, "permission": 0, "source_ip_id": 0, "source_wildcard_id": 0, @@ -123,7 +124,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): protocol = rule_state["protocol"] protocol_id = self.protocol_to_id.get(protocol, 1) obs[i] = { - "position": i, + "position": i - 1, "permission": rule_state["action"], "source_ip_id": src_node_id, "source_wildcard_id": src_wildcard_id, diff --git a/tests/integration_tests/game_layer/observations/test_firewall_observation.py b/tests/integration_tests/game_layer/observations/test_firewall_observation.py index 12a84e9a..959e30f6 100644 --- a/tests/integration_tests/game_layer/observations/test_firewall_observation.py +++ b/tests/integration_tests/game_layer/observations/test_firewall_observation.py @@ -10,7 +10,7 @@ from primaite.simulator.network.transmission.transport_layer import Port def check_default_rules(acl_obs): assert len(acl_obs) == 7 - assert all(acl_obs[i]["position"] == i for i in range(1, 8)) + assert all(acl_obs[i]["position"] == i - 1 for i in range(1, 8)) assert all(acl_obs[i]["permission"] == 0 for i in range(1, 8)) assert all(acl_obs[i]["source_ip_id"] == 0 for i in range(1, 8)) assert all(acl_obs[i]["source_wildcard_id"] == 0 for i in range(1, 8)) @@ -72,7 +72,7 @@ def test_firewall_observation(): observation = firewall_observation.observe(firewall.describe_state()) observed_rule = observation["ACL"]["INTERNAL"]["INBOUND"][5] - assert observed_rule["position"] == 5 + assert observed_rule["position"] == 4 assert observed_rule["permission"] == 2 assert observed_rule["source_ip_id"] == 2 assert observed_rule["source_wildcard_id"] == 3 diff --git a/tests/integration_tests/game_layer/observations/test_link_observations.py b/tests/integration_tests/game_layer/observations/test_link_observations.py index b13314f1..1a41cad4 100644 --- a/tests/integration_tests/game_layer/observations/test_link_observations.py +++ b/tests/integration_tests/game_layer/observations/test_link_observations.py @@ -4,8 +4,10 @@ from gymnasium import spaces from primaite.game.agent.observations.link_observation import LinkObservation from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.base import Link, Node +from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.switch import Switch from primaite.simulator.sim_container import Simulation @@ -71,3 +73,43 @@ def test_link_observation(simulation): observation_state = link_obs.observe(simulation.describe_state()) assert observation_state["PROTOCOLS"]["ALL"] == 1 + + +def test_link_observation_again(): + net = Network() + sim = Simulation(network=net) + switch = Switch(hostname="switch", num_ports=5, operating_state=NodeOperatingState.ON) + computer_1 = Computer( + hostname="computer_1", ip_address="10.0.0.1", subnet_mask="255.255.255.0", start_up_duration=0 + ) + computer_2 = Computer( + hostname="computer_2", ip_address="10.0.0.2", subnet_mask="255.255.255.0", start_up_duration=0 + ) + computer_1.power_on() + computer_2.power_on() + link_1 = net.connect(switch.network_interface[1], computer_1.network_interface[1]) + link_2 = net.connect(switch.network_interface[2], computer_2.network_interface[1]) + assert link_1 is not None + assert link_2 is not None + + link_1_observation = LinkObservation(where=["network", "links", link_1.uuid]) + link_2_observation = LinkObservation(where=["network", "links", link_2.uuid]) + + state = sim.describe_state() + link_1_obs = link_1_observation.observe(state) + link_2_obs = link_2_observation.observe(state) + assert "PROTOCOLS" in link_1_obs + assert "PROTOCOLS" in link_2_obs + assert "ALL" in link_1_obs["PROTOCOLS"] + assert "ALL" in link_2_obs["PROTOCOLS"] + assert link_1_obs["PROTOCOLS"]["ALL"] == 0 + assert link_2_obs["PROTOCOLS"]["ALL"] == 0 + + # Test that the link observation is updated when a packet is sent + computer_1.ping("10.0.0.2") + computer_2.ping("10.0.0.1") + state = sim.describe_state() + link_1_obs = link_1_observation.observe(state) + link_2_obs = link_2_observation.observe(state) + assert link_1_obs["PROTOCOLS"]["ALL"] > 0 + assert link_2_obs["PROTOCOLS"]["ALL"] > 0 diff --git a/tests/integration_tests/game_layer/observations/test_router_observation.py b/tests/integration_tests/game_layer/observations/test_router_observation.py index 7db6a2c2..55471676 100644 --- a/tests/integration_tests/game_layer/observations/test_router_observation.py +++ b/tests/integration_tests/game_layer/observations/test_router_observation.py @@ -50,7 +50,7 @@ def test_router_observation(): # Observe the state using the RouterObservation instance observed_output = router_observation.observe(router.describe_state()) observed_rule = observed_output["ACL"][5] - assert observed_rule["position"] == 5 + assert observed_rule["position"] == 4 assert observed_rule["permission"] == 2 assert observed_rule["source_ip_id"] == 2 assert observed_rule["source_wildcard_id"] == 3 @@ -74,7 +74,7 @@ def test_router_observation(): ) observed_output = router_observation.observe(router.describe_state()) observed_rule = observed_output["ACL"][2] - assert observed_rule["position"] == 2 + assert observed_rule["position"] == 1 assert observed_rule["permission"] == 1 assert observed_rule["source_ip_id"] == 1 assert observed_rule["source_wildcard_id"] == 1 From d2c7ae481c975fddac7af3c2ae900abc624ac2a4 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 1 Apr 2024 22:03:28 +0100 Subject: [PATCH 786/980] #2417 Add categorisation and updated new configs from merge --- .../observations/file_system_observations.py | 23 ++- .../observations/firewall_observation.py | 3 +- .../agent/observations/observation_manager.py | 8 +- .../observations/software_observation.py | 22 ++- .../configs/firewall_actions_network.yaml | 76 +++++++--- .../configs/test_application_install.yaml | 131 +++++++++--------- .../test_file_system_observations.py | 3 + .../observations/test_link_observations.py | 29 +--- .../game_layer/test_observations.py | 5 + 9 files changed, 188 insertions(+), 112 deletions(-) diff --git a/src/primaite/game/agent/observations/file_system_observations.py b/src/primaite/game/agent/observations/file_system_observations.py index 90bca35f..9b9434af 100644 --- a/src/primaite/game/agent/observations/file_system_observations.py +++ b/src/primaite/game/agent/observations/file_system_observations.py @@ -43,6 +43,26 @@ class FileObservation(AbstractObservation, identifier="FILE"): if self.include_num_access: self.default_observation["num_access"] = 0 + # TODO: allow these to be configured in yaml + self.high_threshold = 10 + self.med_threshold = 5 + self.low_threshold = 0 + + def _categorise_num_access(self, num_access: int) -> int: + """ + Represent number of file accesses as a categorical variable. + + :param num_access: Number of file accesses. + :return: Bin number corresponding to the number of accesses. + """ + if num_access > self.high_threshold: + return 3 + elif num_access > self.med_threshold: + return 2 + elif num_access > self.low_threshold: + return 1 + return 0 + def observe(self, state: Dict) -> ObsType: """ Generate observation based on the current state of the simulation. @@ -57,8 +77,7 @@ class FileObservation(AbstractObservation, identifier="FILE"): return self.default_observation obs = {"health_status": file_state["visible_status"]} if self.include_num_access: - obs["num_access"] = file_state["num_access"] - # raise NotImplementedError("TODO: need to fix num_access to use thresholds instead of raw value.") + obs["num_access"] = self._categorise_num_access(file_state["num_access"]) return obs @property diff --git a/src/primaite/game/agent/observations/firewall_observation.py b/src/primaite/game/agent/observations/firewall_observation.py index ab48e606..0c10a8d2 100644 --- a/src/primaite/game/agent/observations/firewall_observation.py +++ b/src/primaite/game/agent/observations/firewall_observation.py @@ -214,9 +214,8 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): :return: Constructed firewall observation instance. :rtype: FirewallObservation """ - where = parent_where + ["nodes", config.hostname] return cls( - where=where, + where=parent_where + ["nodes", config.hostname], ip_list=config.ip_list, wildcard_list=config.wildcard_list, port_list=config.port_list, diff --git a/src/primaite/game/agent/observations/observation_manager.py b/src/primaite/game/agent/observations/observation_manager.py index 3703fa1c..1d428fa8 100644 --- a/src/primaite/game/agent/observations/observation_manager.py +++ b/src/primaite/game/agent/observations/observation_manager.py @@ -185,9 +185,11 @@ class ObservationManager: Create observation space from a config. :param config: Dictionary containing the configuration for this observation space. - It should contain the key 'type' which selects which observation class to use (from a choice of: - UC2BlueObservation, UC2RedObservation, UC2GreenObservation) - The other key is 'options' which are passed to the constructor of the selected observation class. + If None, a blank observation space is created. + Otherwise, this must be a Dict with a type field and options field. + type: string that corresponds to one of the observation identifiers that are provided when subclassing + AbstractObservation + options: this must adhere to the chosen observation type's ConfigSchema nested class. :type config: Dict :param game: Reference to the PrimaiteGame object that spawned this observation. :type game: PrimaiteGame diff --git a/src/primaite/game/agent/observations/software_observation.py b/src/primaite/game/agent/observations/software_observation.py index 40788760..2c4806d9 100644 --- a/src/primaite/game/agent/observations/software_observation.py +++ b/src/primaite/game/agent/observations/software_observation.py @@ -98,6 +98,26 @@ class ApplicationObservation(AbstractObservation, identifier="APPLICATION"): self.where = where self.default_observation = {"operating_status": 0, "health_status": 0, "num_executions": 0} + # TODO: allow these to be configured in yaml + self.high_threshold = 10 + self.med_threshold = 5 + self.low_threshold = 0 + + def _categorise_num_executions(self, num_executions: int) -> int: + """ + Represent number of file accesses as a categorical variable. + + :param num_access: Number of file accesses. + :return: Bin number corresponding to the number of accesses. + """ + if num_executions > self.high_threshold: + return 3 + elif num_executions > self.med_threshold: + return 2 + elif num_executions > self.low_threshold: + return 1 + return 0 + def observe(self, state: Dict) -> ObsType: """ Generate observation based on the current state of the simulation. @@ -113,7 +133,7 @@ class ApplicationObservation(AbstractObservation, identifier="APPLICATION"): return { "operating_status": application_state["operating_state"], "health_status": application_state["health_state_visible"], - "num_executions": application_state["num_executions"], + "num_executions": self._categorise_num_executions(application_state["num_executions"]), } @property diff --git a/tests/assets/configs/firewall_actions_network.yaml b/tests/assets/configs/firewall_actions_network.yaml index b7848c53..203ea3ea 100644 --- a/tests/assets/configs/firewall_actions_network.yaml +++ b/tests/assets/configs/firewall_actions_network.yaml @@ -64,25 +64,67 @@ agents: - ref: defender team: BLUE type: ProxyAgent + observation_space: - type: UC2BlueObservation + type: CUSTOM options: - num_services_per_node: 1 - num_folders_per_node: 1 - num_files_per_folder: 1 - num_nics_per_node: 2 - nodes: - - node_hostname: client_1 - links: - - link_ref: client_1___switch_1 - acl: - options: - max_acl_rules: 10 - router_hostname: router_1 - ip_address_order: - - node_hostname: client_1 - nic_num: 1 - ics: null + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: client_1 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.0.10 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - client_1___switch_1 + - type: "NONE" + label: ICS + options: {} + + # observation_space: + # type: UC2BlueObservation + # options: + # num_services_per_node: 1 + # num_folders_per_node: 1 + # num_files_per_folder: 1 + # num_nics_per_node: 2 + # nodes: + # - node_hostname: client_1 + # links: + # - link_ref: client_1___switch_1 + # acl: + # options: + # max_acl_rules: 10 + # router_hostname: router_1 + # ip_address_order: + # - node_hostname: client_1 + # nic_num: 1 + # ics: null action_space: action_list: - type: DONOTHING diff --git a/tests/assets/configs/test_application_install.yaml b/tests/assets/configs/test_application_install.yaml index b3fca4bc..ccd2228c 100644 --- a/tests/assets/configs/test_application_install.yaml +++ b/tests/assets/configs/test_application_install.yaml @@ -41,8 +41,7 @@ agents: 0: 0.3 1: 0.6 2: 0.1 - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -91,8 +90,7 @@ agents: 0: 0.3 1: 0.6 2: 0.1 - observation_space: - type: UC2GreenObservation + observation_space: null action_space: action_list: - type: DONOTHING @@ -141,10 +139,7 @@ agents: team: RED type: RedDatabaseCorruptingAgent - observation_space: - type: UC2RedObservation - options: - nodes: {} + observation_space: null action_space: action_list: @@ -177,61 +172,73 @@ agents: type: ProxyAgent observation_space: - type: UC2BlueObservation + type: CUSTOM options: - num_services_per_node: 1 - num_folders_per_node: 1 - num_files_per_folder: 1 - num_nics_per_node: 2 - nodes: - - node_hostname: domain_controller - services: - - service_name: DNSServer - - node_hostname: web_server - services: - - service_name: WebServer - - node_hostname: database_server - folders: - - folder_name: database - files: - - file_name: database.db - - node_hostname: backup_server - - node_hostname: security_suite - - node_hostname: client_1 - - node_hostname: client_2 - links: - - link_ref: router_1___switch_1 - - link_ref: router_1___switch_2 - - link_ref: switch_1___domain_controller - - link_ref: switch_1___web_server - - link_ref: switch_1___database_server - - link_ref: switch_1___backup_server - - link_ref: switch_1___security_suite - - link_ref: switch_2___client_1 - - link_ref: switch_2___client_2 - - link_ref: switch_2___security_suite - acl: - options: - max_acl_rules: 10 - router_hostname: router_1 - ip_address_order: - - node_hostname: domain_controller - nic_num: 1 - - node_hostname: web_server - nic_num: 1 - - node_hostname: database_server - nic_num: 1 - - node_hostname: backup_server - nic_num: 1 - - node_hostname: security_suite - nic_num: 1 - - node_hostname: client_1 - nic_num: 1 - - node_hostname: client_2 - nic_num: 1 - - node_hostname: security_suite - nic_num: 2 - ics: null + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: domain_controller + - hostname: web_server + services: + - service_name: WebServer + - hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - router_1___switch_1 + - router_1___switch_2 + - switch_1___domain_controller + - switch_1___web_server + - switch_1___database_server + - switch_1___backup_server + - switch_1___security_suite + - switch_2___client_1 + - switch_2___client_2 + - switch_2___security_suite + - type: "NONE" + label: ICS + options: {} action_space: action_list: diff --git a/tests/integration_tests/game_layer/observations/test_file_system_observations.py b/tests/integration_tests/game_layer/observations/test_file_system_observations.py index af5e9650..cb83ac5e 100644 --- a/tests/integration_tests/game_layer/observations/test_file_system_observations.py +++ b/tests/integration_tests/game_layer/observations/test_file_system_observations.py @@ -72,3 +72,6 @@ def test_folder_observation(simulation): observation_state = root_folder_obs.observe(simulation.describe_state()) assert observation_state.get("health_status") == 3 # file is corrupt therefore folder is corrupted too + + +# TODO: Add tests to check num access is correct. diff --git a/tests/integration_tests/game_layer/observations/test_link_observations.py b/tests/integration_tests/game_layer/observations/test_link_observations.py index 1a41cad4..3eee72e8 100644 --- a/tests/integration_tests/game_layer/observations/test_link_observations.py +++ b/tests/integration_tests/game_layer/observations/test_link_observations.py @@ -51,31 +51,8 @@ def simulation() -> Simulation: return sim -def test_link_observation(simulation): - """Test the link observation.""" - # get a link - link: Link = next(iter(simulation.network.links.values())) - - computer: Computer = simulation.network.get_node_by_hostname("computer") - server: Server = simulation.network.get_node_by_hostname("server") - - simulation.apply_timestep(0) # some pings when network was made - reset with apply timestep - - link_obs = LinkObservation(where=["network", "links", link.uuid]) - - assert link_obs.space["PROTOCOLS"]["ALL"] == spaces.Discrete(11) # test that the spaces are 0-10 including 0 and 10 - - observation_state = link_obs.observe(simulation.describe_state()) - assert observation_state.get("PROTOCOLS") is not None - assert observation_state["PROTOCOLS"]["ALL"] == 0 - - computer.ping(server.network_interface.get(1).ip_address) - - observation_state = link_obs.observe(simulation.describe_state()) - assert observation_state["PROTOCOLS"]["ALL"] == 1 - - -def test_link_observation_again(): +def test_link_observation(): + """Check the shape and contents of the link observation.""" net = Network() sim = Simulation(network=net) switch = Switch(hostname="switch", num_ports=5, operating_state=NodeOperatingState.ON) @@ -102,6 +79,8 @@ def test_link_observation_again(): assert "PROTOCOLS" in link_2_obs assert "ALL" in link_1_obs["PROTOCOLS"] assert "ALL" in link_2_obs["PROTOCOLS"] + assert link_1_observation.space["PROTOCOLS"]["ALL"] == spaces.Discrete(11) + assert link_2_observation.space["PROTOCOLS"]["ALL"] == spaces.Discrete(11) assert link_1_obs["PROTOCOLS"]["ALL"] == 0 assert link_2_obs["PROTOCOLS"]["ALL"] == 0 diff --git a/tests/integration_tests/game_layer/test_observations.py b/tests/integration_tests/game_layer/test_observations.py index 0a34ab67..ed07e030 100644 --- a/tests/integration_tests/game_layer/test_observations.py +++ b/tests/integration_tests/game_layer/test_observations.py @@ -19,3 +19,8 @@ def test_file_observation(): ) assert dog_file_obs.observe(state) == {"health_status": 1} assert dog_file_obs.space == spaces.Dict({"health_status": spaces.Discrete(6)}) + + +# TODO: +# def test_file_num_access(): +# ... From 82143a2a2efe904813e39f0dacbe0507cd266f57 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 2 Apr 2024 00:31:06 +0100 Subject: [PATCH 787/980] #2446 Fix io config parsing order --- src/primaite/session/environment.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index ce9699d4..4fdbbe34 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -28,6 +28,8 @@ class PrimaiteGymEnv(gymnasium.Env): super().__init__() self.game_config: Dict = game_config """PrimaiteGame definition. This can be changed between episodes to enable curriculum learning.""" + self.io = PrimaiteIO.from_config(game_config.get("io_settings", {})) + """Handles IO for the environment. This produces sys logs, agent logs, etc.""" self.game: PrimaiteGame = PrimaiteGame.from_config(copy.deepcopy(self.game_config)) """Current game.""" self._agent_name = next(iter(self.game.rl_agents)) @@ -36,9 +38,6 @@ class PrimaiteGymEnv(gymnasium.Env): self.episode_counter: int = 0 """Current episode number.""" - self.io = PrimaiteIO.from_config(game_config.get("io_settings", {})) - """Handles IO for the environment. This produces sys logs, agent logs, etc.""" - @property def agent(self) -> ProxyAgent: """Grab a fresh reference to the agent object because it will be reinstantiated each episode.""" @@ -168,6 +167,8 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): """ self.game_config: Dict = env_config """PrimaiteGame definition. This can be changed between episodes to enable curriculum learning.""" + self.io = PrimaiteIO.from_config(env_config.get("io_settings")) + """Handles IO for the environment. This produces sys logs, agent logs, etc.""" self.game: PrimaiteGame = PrimaiteGame.from_config(copy.deepcopy(self.game_config)) """Reference to the primaite game""" self._agent_ids = list(self.game.rl_agents.keys()) @@ -187,9 +188,6 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): {name: agent.action_manager.space for name, agent in self.agents.items()} ) - self.io = PrimaiteIO.from_config(env_config.get("io_settings")) - """Handles IO for the environment. This produces sys logs, agent logs, etc.""" - super().__init__() @property From bb937c10926d1ff9965b0cdf1fedb0d4fd64866d Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 2 Apr 2024 12:56:15 +0100 Subject: [PATCH 788/980] #2149 - docstring changes following PR suggestions. --- .../simulator/network/hardware/nodes/network/router.py | 6 +++--- src/primaite/simulator/system/core/session_manager.py | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 6571829a..f8b5623f 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1023,11 +1023,11 @@ class RouterSessionManager(SessionManager): """ Manages network sessions, including session creation, lookup, and communication with other components. - The RouterSessionManager is a Router/Firewall specific implementation of SessionManager. It enables to resolve - outbound interface transmission details functions to leverage the route table instead of the default gateway. + The RouterSessionManager is a Router/Firewall specific implementation of SessionManager. It overrides the + resolve_outbound_network_interface and resolve_outbound_transmission_details functions, allowing them to leverage + the route table instead of the default gateway. :param sys_log: A reference to the system log component. - :param arp_cache: A reference to the ARP cache component. """ def resolve_outbound_network_interface(self, dst_ip_address: IPv4Address) -> Optional[RouterInterface]: diff --git a/src/primaite/simulator/system/core/session_manager.py b/src/primaite/simulator/system/core/session_manager.py index 3fa2aa97..68f44dca 100644 --- a/src/primaite/simulator/system/core/session_manager.py +++ b/src/primaite/simulator/system/core/session_manager.py @@ -72,7 +72,6 @@ class SessionManager: Manages network sessions, including session creation, lookup, and communication with other components. :param sys_log: A reference to the system log component. - :param arp_cache: A reference to the ARP cache component. """ def __init__(self, sys_log: SysLog): From 989e7481f3aaa0f598a4193a3b5555edd4c8456a Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 2 Apr 2024 15:10:48 +0100 Subject: [PATCH 789/980] #2437: fix the visible health status not being carried on after restoring backup file --- .../services/database/database_service.py | 18 +++++- .../system/test_database_on_node.py | 63 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 541a15c2..ede2a54f 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -104,14 +104,30 @@ class DatabaseService(Service): self.sys_log.error("Unable to restore database backup.") return False + old_visible_state = SoftwareHealthState.GOOD + + # get db file regardless of whether or not it was deleted + db_file = self.file_system.get_file(folder_name="database", file_name="database.db", include_deleted=True) + + if db_file is None: + self.sys_log.error("Database file not initialised.") + return False + + # if the file was deleted, get the old visible health state + if db_file.deleted: + old_visible_state = db_file.visible_health_status + else: + old_visible_state = self.db_file.visible_health_status + self.file_system.delete_file(folder_name="database", file_name="database.db") + # replace db file - self.file_system.delete_file(folder_name="database", file_name="database.db") self.file_system.copy_file(src_folder_name="downloads", src_file_name="database.db", dst_folder_name="database") if self.db_file is None: self.sys_log.error("Copying database backup failed.") return False + self.db_file.visible_health_status = old_visible_state self.set_health_state(SoftwareHealthState.GOOD) return True diff --git a/tests/integration_tests/system/test_database_on_node.py b/tests/integration_tests/system/test_database_on_node.py index ac0e65b4..c555acff 100644 --- a/tests/integration_tests/system/test_database_on_node.py +++ b/tests/integration_tests/system/test_database_on_node.py @@ -3,6 +3,7 @@ from typing import Tuple import pytest +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer @@ -138,6 +139,68 @@ def test_restore_backup(uc2_network): assert db_service.file_system.get_file(folder_name="database", file_name="database.db") is not None +def test_restore_backup_without_updating_scan(uc2_network): + """Same test as restore backup but the file is previously seen as corrupted.""" + db_server: Server = uc2_network.get_node_by_hostname("database_server") + db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + + # create a back up + assert db_service.backup_database() is True + + db_service.db_file.corrupt() # corrupt the db + assert db_service.db_file.health_status == FileSystemItemHealthStatus.CORRUPT # db file is actually corrupt + assert db_service.db_file.visible_health_status == FileSystemItemHealthStatus.GOOD # not scanned yet + + db_service.db_file.scan() # scan the db file + + # db file is corrupt since last scan + assert db_service.db_file.visible_health_status == FileSystemItemHealthStatus.CORRUPT + + # back up should be restored + assert db_service.restore_backup() is True + + assert db_service.db_file.health_status == FileSystemItemHealthStatus.GOOD # db file is actually good + # db file is corrupt since last scan + assert db_service.db_file.visible_health_status == FileSystemItemHealthStatus.CORRUPT + + db_service.db_file.scan() # scan the db file + assert db_service.db_file.visible_health_status == FileSystemItemHealthStatus.GOOD # now looks good + + +def test_restore_backup_after_deleting_file_without_updating_scan(uc2_network): + """Same test as restore backup but the file is previously seen as corrupted.""" + db_server: Server = uc2_network.get_node_by_hostname("database_server") + db_service: DatabaseService = db_server.software_manager.software["DatabaseService"] + + # create a back up + assert db_service.backup_database() is True + + db_service.db_file.corrupt() # corrupt the db + assert db_service.db_file.health_status == FileSystemItemHealthStatus.CORRUPT # db file is actually corrupt + assert db_service.db_file.visible_health_status == FileSystemItemHealthStatus.GOOD # not scanned yet + + db_service.db_file.scan() # scan the db file + + # db file is corrupt since last scan + assert db_service.db_file.visible_health_status == FileSystemItemHealthStatus.CORRUPT + + # delete database locally + db_service.file_system.delete_file(folder_name="database", file_name="database.db") + + # db file is gone, reduced to atoms + assert db_service.db_file is None + + # back up should be restored + assert db_service.restore_backup() is True + + assert db_service.db_file.health_status == FileSystemItemHealthStatus.GOOD # db file is actually good + # db file is corrupt since last scan + assert db_service.db_file.visible_health_status == FileSystemItemHealthStatus.CORRUPT + + db_service.db_file.scan() # scan the db file + assert db_service.db_file.visible_health_status == FileSystemItemHealthStatus.GOOD # now looks good + + def test_database_client_cannot_query_offline_database_server(uc2_network): """Tests DB query across the network returns HTTP status 404 when db server is offline.""" db_server: Server = uc2_network.get_node_by_hostname("database_server") From a4caa3dfe4abbff8e9b88c8114f93d384d0927af Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 3 Apr 2024 15:58:01 +0100 Subject: [PATCH 790/980] #2449 fix observation integration --- .../game/agent/observations/file_system_observations.py | 2 +- .../game/agent/observations/firewall_observation.py | 2 +- src/primaite/game/agent/observations/host_observations.py | 2 +- src/primaite/game/agent/observations/node_observations.py | 2 +- src/primaite/game/agent/observations/router_observation.py | 2 +- .../notebooks/Data-Manipulation-E2E-Demonstration.ipynb | 6 +++--- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/primaite/game/agent/observations/file_system_observations.py b/src/primaite/game/agent/observations/file_system_observations.py index 9b9434af..3e262055 100644 --- a/src/primaite/game/agent/observations/file_system_observations.py +++ b/src/primaite/game/agent/observations/file_system_observations.py @@ -205,7 +205,7 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): :return: Constructed folder observation instance. :rtype: FolderObservation """ - where = parent_where + ["folders", config.folder_name] + where = parent_where + ["file_system", "folders", config.folder_name] # pass down shared/common config items for file_config in config.files: diff --git a/src/primaite/game/agent/observations/firewall_observation.py b/src/primaite/game/agent/observations/firewall_observation.py index 0c10a8d2..0a1498b1 100644 --- a/src/primaite/game/agent/observations/firewall_observation.py +++ b/src/primaite/game/agent/observations/firewall_observation.py @@ -215,7 +215,7 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): :rtype: FirewallObservation """ return cls( - where=parent_where + ["nodes", config.hostname], + where=parent_where + [config.hostname], ip_list=config.ip_list, wildcard_list=config.wildcard_list, port_list=config.port_list, diff --git a/src/primaite/game/agent/observations/host_observations.py b/src/primaite/game/agent/observations/host_observations.py index 8ea40be7..6dbde789 100644 --- a/src/primaite/game/agent/observations/host_observations.py +++ b/src/primaite/game/agent/observations/host_observations.py @@ -216,7 +216,7 @@ class HostObservation(AbstractObservation, identifier="HOST"): if parent_where == []: where = ["network", "nodes", config.hostname] else: - where = parent_where + ["nodes", config.hostname] + where = parent_where + [config.hostname] # Pass down shared/common config items for folder_config in config.folders: diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index dce33a04..f11ffebf 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -164,7 +164,7 @@ class NodesObservation(AbstractObservation, identifier="NODES"): :return: Constructed nodes observation instance. :rtype: NodesObservation """ - if parent_where is None: + if not parent_where: where = ["network", "nodes"] else: where = parent_where + ["nodes"] diff --git a/src/primaite/game/agent/observations/router_observation.py b/src/primaite/game/agent/observations/router_observation.py index a7879f09..aeac2766 100644 --- a/src/primaite/game/agent/observations/router_observation.py +++ b/src/primaite/game/agent/observations/router_observation.py @@ -124,7 +124,7 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): :return: Constructed router observation instance. :rtype: RouterObservation """ - where = parent_where + ["nodes", config.hostname] + where = parent_where + [config.hostname] if config.acl is None: config.acl = ACLObservation.ConfigSchema() diff --git a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb index 60d40f9c..a958aa0a 100644 --- a/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-E2E-Demonstration.ipynb @@ -592,7 +592,7 @@ "metadata": {}, "outputs": [], "source": [ - "obs['ACL']" + "obs['NODES']['ROUTER0']" ] }, { @@ -616,12 +616,12 @@ " tries += 1\n", " obs, reward, terminated, truncated, info = env.step(0)\n", "\n", - " if obs['NODES'][6]['NICS'][1]['NMNE']['outbound'] == 1:\n", + " if obs['NODES']['HOST5']['NICS'][1]['NMNE']['outbound'] == 1:\n", " # client 1 has NMNEs, let's block it\n", " obs, reward, terminated, truncated, info = env.step(50) # block client 1\n", " print(\"blocking client 1\")\n", " break\n", - " elif obs['NODES'][7]['NICS'][1]['NMNE']['outbound'] == 1:\n", + " elif obs['NODES']['HOST6']['NICS'][1]['NMNE']['outbound'] == 1:\n", " # client 2 has NMNEs, so let's block it\n", " obs, reward, terminated, truncated, info = env.step(51) # block client 2\n", " print(\"blocking client 2\")\n", From 2cd9e58994f47e960d736c6c48cffb1c0b36c352 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 3 Apr 2024 20:18:23 +0000 Subject: [PATCH 791/980] temp disable extra platforms for build pipeline --- .azure/azure-ci-build-pipeline.yaml | 50 ++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index dcfbde0e..9faaffaf 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -14,36 +14,36 @@ parameters: - name: matrix type: object default: - - job_name: 'UbuntuPython38' - py: '3.8' - img: 'ubuntu-latest' - every_time: false - publish_coverage: false + # - job_name: 'UbuntuPython38' + # py: '3.8' + # img: 'ubuntu-latest' + # every_time: false + # publish_coverage: false - job_name: 'UbuntuPython310' py: '3.10' img: 'ubuntu-latest' every_time: true publish_coverage: true - - job_name: 'WindowsPython38' - py: '3.8' - img: 'windows-latest' - every_time: false - publish_coverage: false - - job_name: 'WindowsPython310' - py: '3.10' - img: 'windows-latest' - every_time: false - publish_coverage: false - - job_name: 'MacOSPython38' - py: '3.8' - img: 'macOS-latest' - every_time: false - publish_coverage: false - - job_name: 'MacOSPython310' - py: '3.10' - img: 'macOS-latest' - every_time: false - publish_coverage: false + # - job_name: 'WindowsPython38' + # py: '3.8' + # img: 'windows-latest' + # every_time: false + # publish_coverage: false + # - job_name: 'WindowsPython310' + # py: '3.10' + # img: 'windows-latest' + # every_time: false + # publish_coverage: false + # - job_name: 'MacOSPython38' + # py: '3.8' + # img: 'macOS-latest' + # every_time: false + # publish_coverage: false + # - job_name: 'MacOSPython310' + # py: '3.10' + # img: 'macOS-latest' + # every_time: false + # publish_coverage: false stages: - stage: Test From e99d238568d3e8045fd848c30d32c716e6387f20 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 3 Apr 2024 21:39:13 +0100 Subject: [PATCH 792/980] #2450 remove link refs and put nice naming convention instead --- .../_package_data/data_manipulation.yaml | 52 ++++++-------- .../_package_data/data_manipulation_marl.yaml | 70 ++++++++----------- .../agent/observations/link_observation.py | 2 +- src/primaite/game/game.py | 6 +- src/primaite/simulator/network/container.py | 13 ++-- 5 files changed, 59 insertions(+), 84 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index b6899b79..c68480cf 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -226,16 +226,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -924,56 +924,44 @@ simulation: - ref: client_2_dns_client type: DNSClient - - links: - - ref: router_1___switch_1 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 1 endpoint_b_ref: switch_1 endpoint_b_port: 8 - - ref: router_1___switch_2 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 2 endpoint_b_ref: switch_2 endpoint_b_port: 8 - - ref: switch_1___domain_controller - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 1 endpoint_b_ref: domain_controller endpoint_b_port: 1 - - ref: switch_1___web_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 2 endpoint_b_ref: web_server endpoint_b_port: 1 - - ref: switch_1___database_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 3 endpoint_b_ref: database_server endpoint_b_port: 1 - - ref: switch_1___backup_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 4 endpoint_b_ref: backup_server endpoint_b_port: 1 - - ref: switch_1___security_suite - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 1 - - ref: switch_2___client_1 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 1 endpoint_b_ref: client_1 endpoint_b_port: 1 - - ref: switch_2___client_2 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 2 endpoint_b_ref: client_2 endpoint_b_port: 1 - - ref: switch_2___security_suite - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 2 diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index 86759b2d..9ec2a1f2 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -228,16 +228,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -803,16 +803,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -1505,53 +1505,43 @@ simulation: links: - - ref: router_1___switch_1 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 1 endpoint_b_ref: switch_1 endpoint_b_port: 8 - - ref: router_1___switch_2 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 2 endpoint_b_ref: switch_2 endpoint_b_port: 8 - - ref: switch_1___domain_controller - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 1 endpoint_b_ref: domain_controller endpoint_b_port: 1 - - ref: switch_1___web_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 2 endpoint_b_ref: web_server endpoint_b_port: 1 - - ref: switch_1___database_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 3 endpoint_b_ref: database_server endpoint_b_port: 1 - - ref: switch_1___backup_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 4 endpoint_b_ref: backup_server endpoint_b_port: 1 - - ref: switch_1___security_suite - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 1 - - ref: switch_2___client_1 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 1 endpoint_b_ref: client_1 endpoint_b_port: 1 - - ref: switch_2___client_2 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 2 endpoint_b_ref: client_2 endpoint_b_port: 1 - - ref: switch_2___security_suite - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 2 diff --git a/src/primaite/game/agent/observations/link_observation.py b/src/primaite/game/agent/observations/link_observation.py index be08657d..b55aae46 100644 --- a/src/primaite/game/agent/observations/link_observation.py +++ b/src/primaite/game/agent/observations/link_observation.py @@ -82,7 +82,7 @@ class LinkObservation(AbstractObservation, identifier="LINK"): :return: Constructed link observation instance. :rtype: LinkObservation """ - link_reference = game.ref_map_links[config.link_reference] + link_reference = config.link_reference if parent_where == []: where = ["network", "links", link_reference] else: diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 6ba7e63c..034d11bc 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -111,9 +111,6 @@ class PrimaiteGame: self.ref_map_applications: Dict[str, str] = {} """Mapping from human-readable application reference to application object. Used for parsing config files.""" - self.ref_map_links: Dict[str, str] = {} - """Mapping from human-readable link reference to link object. Used when parsing config files.""" - self.save_step_metadata: bool = False """Whether to save the RL agents' action, environment state, and other data at every single step.""" @@ -409,8 +406,7 @@ class PrimaiteGame: endpoint_b = node_b.network_interface[link_cfg["endpoint_b_port"]] else: endpoint_b = node_b.network_interface[link_cfg["endpoint_b_port"]] - new_link = net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b) - game.ref_map_links[link_cfg["ref"]] = new_link.uuid + net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b) # 3. create agents agents_cfg = cfg.get("agents", []) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 92ee9f0d..cfe66d89 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -225,18 +225,19 @@ class Network(SimComponent): } ) # Update the links one-by-one. The key is a 4-tuple of `hostname_a, port_a, hostname_b, port_b` - for uuid, link in self.links.items(): + for _, link in self.links.items(): node_a = link.endpoint_a._connected_node node_b = link.endpoint_b._connected_node hostname_a = node_a.hostname if node_a else None hostname_b = node_b.hostname if node_b else None port_a = link.endpoint_a.port_num port_b = link.endpoint_b.port_num - state["links"][uuid] = link.describe_state() - state["links"][uuid]["hostname_a"] = hostname_a - state["links"][uuid]["hostname_b"] = hostname_b - state["links"][uuid]["port_a"] = port_a - state["links"][uuid]["port_b"] = port_b + link_key = f"{hostname_a}:eth-{port_a}<->{hostname_b}:eth-{port_b}" + state["links"][link_key] = link.describe_state() + state["links"][link_key]["hostname_a"] = hostname_a + state["links"][link_key]["hostname_b"] = hostname_b + state["links"][link_key]["port_a"] = port_a + state["links"][link_key]["port_b"] = port_b return state From 53de4bf7ddcd11a6c0b16694ab16758f6ff9b478 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 3 Apr 2024 21:46:42 +0100 Subject: [PATCH 793/980] Update test assets to new link naming convention --- .../assets/configs/bad_primaite_session.yaml | 50 ++++++------- .../configs/basic_switched_network.yaml | 6 +- .../configs/eval_only_primaite_session.yaml | 50 ++++++------- .../configs/firewall_actions_network.yaml | 2 +- tests/assets/configs/multi_agent_session.yaml | 70 ++++++++----------- tests/assets/configs/shared_rewards.yaml | 50 ++++++------- .../configs/test_application_install.yaml | 50 ++++++------- .../assets/configs/test_primaite_session.yaml | 50 ++++++------- .../configs/train_only_primaite_session.yaml | 50 ++++++------- .../observations/test_link_observations.py | 4 +- 10 files changed, 155 insertions(+), 227 deletions(-) diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index d07a0376..19cad586 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -136,16 +136,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -687,53 +687,43 @@ simulation: type: DNSClient links: - - ref: router_1___switch_1 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 1 endpoint_b_ref: switch_1 endpoint_b_port: 8 - - ref: router_1___switch_2 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 2 endpoint_b_ref: switch_2 endpoint_b_port: 8 - - ref: switch_1___domain_controller - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 1 endpoint_b_ref: domain_controller endpoint_b_port: 1 - - ref: switch_1___web_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 2 endpoint_b_ref: web_server endpoint_b_port: 1 - - ref: switch_1___database_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 3 endpoint_b_ref: database_server endpoint_b_port: 1 - - ref: switch_1___backup_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 4 endpoint_b_ref: backup_server endpoint_b_port: 1 - - ref: switch_1___security_suite - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 1 - - ref: switch_2___client_1 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 1 endpoint_b_ref: client_1 endpoint_b_port: 1 - - ref: switch_2___client_2 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 2 endpoint_b_ref: client_2 endpoint_b_port: 1 - - ref: switch_2___security_suite - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 2 diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 9dfeae06..009f239a 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -162,13 +162,11 @@ simulation: # pre installed services and applications links: - - ref: switch_1___client_1 - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 1 endpoint_b_ref: client_1 endpoint_b_port: 1 - - ref: switch_1___client_2 - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 2 endpoint_b_ref: client_2 endpoint_b_port: 1 diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index 8723ae38..c342ed72 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -152,16 +152,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -703,53 +703,43 @@ simulation: type: DNSClient links: - - ref: router_1___switch_1 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 1 endpoint_b_ref: switch_1 endpoint_b_port: 8 - - ref: router_1___switch_2 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 2 endpoint_b_ref: switch_2 endpoint_b_port: 8 - - ref: switch_1___domain_controller - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 1 endpoint_b_ref: domain_controller endpoint_b_port: 1 - - ref: switch_1___web_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 2 endpoint_b_ref: web_server endpoint_b_port: 1 - - ref: switch_1___database_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 3 endpoint_b_ref: database_server endpoint_b_port: 1 - - ref: switch_1___backup_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 4 endpoint_b_ref: backup_server endpoint_b_port: 1 - - ref: switch_1___security_suite - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 1 - - ref: switch_2___client_1 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 1 endpoint_b_ref: client_1 endpoint_b_port: 1 - - ref: switch_2___client_2 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 2 endpoint_b_ref: client_2 endpoint_b_port: 1 - - ref: switch_2___security_suite - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 2 diff --git a/tests/assets/configs/firewall_actions_network.yaml b/tests/assets/configs/firewall_actions_network.yaml index 203ea3ea..cf10505e 100644 --- a/tests/assets/configs/firewall_actions_network.yaml +++ b/tests/assets/configs/firewall_actions_network.yaml @@ -101,7 +101,7 @@ agents: label: LINKS options: link_references: - - client_1___switch_1 + - client_1:eth-1<->switch_1:eth-1 - type: "NONE" label: ICS options: {} diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index dd416523..35431064 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -147,16 +147,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -613,16 +613,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -1162,53 +1162,43 @@ simulation: type: DNSClient links: - - ref: router_1___switch_1 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 1 endpoint_b_ref: switch_1 endpoint_b_port: 8 - - ref: router_1___switch_2 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 2 endpoint_b_ref: switch_2 endpoint_b_port: 8 - - ref: switch_1___domain_controller - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 1 endpoint_b_ref: domain_controller endpoint_b_port: 1 - - ref: switch_1___web_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 2 endpoint_b_ref: web_server endpoint_b_port: 1 - - ref: switch_1___database_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 3 endpoint_b_ref: database_server endpoint_b_port: 1 - - ref: switch_1___backup_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 4 endpoint_b_ref: backup_server endpoint_b_port: 1 - - ref: switch_1___security_suite - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 1 - - ref: switch_2___client_1 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 1 endpoint_b_ref: client_1 endpoint_b_port: 1 - - ref: switch_2___client_2 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 2 endpoint_b_ref: client_2 endpoint_b_port: 1 - - ref: switch_2___security_suite - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 2 diff --git a/tests/assets/configs/shared_rewards.yaml b/tests/assets/configs/shared_rewards.yaml index 4b925844..9cf4d17d 100644 --- a/tests/assets/configs/shared_rewards.yaml +++ b/tests/assets/configs/shared_rewards.yaml @@ -226,16 +226,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -921,53 +921,43 @@ simulation: links: - - ref: router_1___switch_1 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 1 endpoint_b_ref: switch_1 endpoint_b_port: 8 - - ref: router_1___switch_2 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 2 endpoint_b_ref: switch_2 endpoint_b_port: 8 - - ref: switch_1___domain_controller - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 1 endpoint_b_ref: domain_controller endpoint_b_port: 1 - - ref: switch_1___web_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 2 endpoint_b_ref: web_server endpoint_b_port: 1 - - ref: switch_1___database_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 3 endpoint_b_ref: database_server endpoint_b_port: 1 - - ref: switch_1___backup_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 4 endpoint_b_ref: backup_server endpoint_b_port: 1 - - ref: switch_1___security_suite - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 1 - - ref: switch_2___client_1 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 1 endpoint_b_ref: client_1 endpoint_b_port: 1 - - ref: switch_2___client_2 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 2 endpoint_b_ref: client_2 endpoint_b_port: 1 - - ref: switch_2___security_suite - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 2 diff --git a/tests/assets/configs/test_application_install.yaml b/tests/assets/configs/test_application_install.yaml index ccd2228c..d2e85f30 100644 --- a/tests/assets/configs/test_application_install.yaml +++ b/tests/assets/configs/test_application_install.yaml @@ -226,16 +226,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -953,53 +953,43 @@ simulation: links: - - ref: router_1___switch_1 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 1 endpoint_b_ref: switch_1 endpoint_b_port: 8 - - ref: router_1___switch_2 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 2 endpoint_b_ref: switch_2 endpoint_b_port: 8 - - ref: switch_1___domain_controller - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 1 endpoint_b_ref: domain_controller endpoint_b_port: 1 - - ref: switch_1___web_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 2 endpoint_b_ref: web_server endpoint_b_port: 1 - - ref: switch_1___database_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 3 endpoint_b_ref: database_server endpoint_b_port: 1 - - ref: switch_1___backup_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 4 endpoint_b_ref: backup_server endpoint_b_port: 1 - - ref: switch_1___security_suite - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 1 - - ref: switch_2___client_1 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 1 endpoint_b_ref: client_1 endpoint_b_port: 1 - - ref: switch_2___client_2 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 2 endpoint_b_ref: client_2 endpoint_b_port: 1 - - ref: switch_2___security_suite - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 2 diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 8bad2f0b..1fd489ec 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -160,16 +160,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -743,53 +743,43 @@ simulation: protocol: ICMP links: - - ref: router_1___switch_1 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 1 endpoint_b_ref: switch_1 endpoint_b_port: 8 - - ref: router_1___switch_2 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 2 endpoint_b_ref: switch_2 endpoint_b_port: 8 - - ref: switch_1___domain_controller - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 1 endpoint_b_ref: domain_controller endpoint_b_port: 1 - - ref: switch_1___web_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 2 endpoint_b_ref: web_server endpoint_b_port: 1 - - ref: switch_1___database_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 3 endpoint_b_ref: database_server endpoint_b_port: 1 - - ref: switch_1___backup_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 4 endpoint_b_ref: backup_server endpoint_b_port: 1 - - ref: switch_1___security_suite - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 1 - - ref: switch_2___client_1 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 1 endpoint_b_ref: client_1 endpoint_b_port: 1 - - ref: switch_2___client_2 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 2 endpoint_b_ref: client_2 endpoint_b_port: 1 - - ref: switch_2___security_suite - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 2 diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index fcfbaf15..ca26fc62 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -160,16 +160,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -710,53 +710,43 @@ simulation: type: DNSClient links: - - ref: router_1___switch_1 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 1 endpoint_b_ref: switch_1 endpoint_b_port: 8 - - ref: router_1___switch_2 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 2 endpoint_b_ref: switch_2 endpoint_b_port: 8 - - ref: switch_1___domain_controller - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 1 endpoint_b_ref: domain_controller endpoint_b_port: 1 - - ref: switch_1___web_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 2 endpoint_b_ref: web_server endpoint_b_port: 1 - - ref: switch_1___database_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 3 endpoint_b_ref: database_server endpoint_b_port: 1 - - ref: switch_1___backup_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 4 endpoint_b_ref: backup_server endpoint_b_port: 1 - - ref: switch_1___security_suite - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 1 - - ref: switch_2___client_1 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 1 endpoint_b_ref: client_1 endpoint_b_port: 1 - - ref: switch_2___client_2 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 2 endpoint_b_ref: client_2 endpoint_b_port: 1 - - ref: switch_2___security_suite - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 2 diff --git a/tests/integration_tests/game_layer/observations/test_link_observations.py b/tests/integration_tests/game_layer/observations/test_link_observations.py index 3eee72e8..dce7b23d 100644 --- a/tests/integration_tests/game_layer/observations/test_link_observations.py +++ b/tests/integration_tests/game_layer/observations/test_link_observations.py @@ -69,8 +69,8 @@ def test_link_observation(): assert link_1 is not None assert link_2 is not None - link_1_observation = LinkObservation(where=["network", "links", link_1.uuid]) - link_2_observation = LinkObservation(where=["network", "links", link_2.uuid]) + link_1_observation = LinkObservation(where=["network", "links", "switch:eth-1<->computer_1:eth-1"]) + link_2_observation = LinkObservation(where=["network", "links", "switch:eth-2<->computer_2:eth-1"]) state = sim.describe_state() link_1_obs = link_1_observation.observe(state) From 526dcc7ffea26600e330d68e8681f1ed18c5020d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 3 Apr 2024 22:16:54 +0100 Subject: [PATCH 794/980] #2450 remove the need to pass Game to observation objects --- .../agent/observations/acl_observation.py | 6 ++---- .../observations/file_system_observations.py | 10 ++++------ .../observations/firewall_observation.py | 8 ++------ .../agent/observations/host_observations.py | 16 ++++++---------- .../agent/observations/link_observation.py | 14 ++++---------- .../agent/observations/nic_observations.py | 9 +++------ .../agent/observations/node_observations.py | 12 +++++------- .../agent/observations/observation_manager.py | 19 ++++++------------- .../game/agent/observations/observations.py | 8 ++------ .../agent/observations/router_observation.py | 10 ++++------ .../observations/software_observation.py | 13 +++---------- src/primaite/game/game.py | 6 +++--- 12 files changed, 44 insertions(+), 87 deletions(-) diff --git a/src/primaite/game/agent/observations/acl_observation.py b/src/primaite/game/agent/observations/acl_observation.py index fc603a8a..934d688e 100644 --- a/src/primaite/game/agent/observations/acl_observation.py +++ b/src/primaite/game/agent/observations/acl_observation.py @@ -1,7 +1,7 @@ from __future__ import annotations from ipaddress import IPv4Address -from typing import Dict, List, Optional, TYPE_CHECKING +from typing import Dict, List, Optional from gymnasium import spaces from gymnasium.core import ObsType @@ -10,8 +10,6 @@ from primaite import getLogger from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -167,7 +165,7 @@ class ACLObservation(AbstractObservation, identifier="ACL"): ) @classmethod - def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> ACLObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ACLObservation: """ Create an ACL observation from a configuration schema. diff --git a/src/primaite/game/agent/observations/file_system_observations.py b/src/primaite/game/agent/observations/file_system_observations.py index 3e262055..baf27660 100644 --- a/src/primaite/game/agent/observations/file_system_observations.py +++ b/src/primaite/game/agent/observations/file_system_observations.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, Iterable, List, Optional, TYPE_CHECKING +from typing import Dict, Iterable, List, Optional from gymnasium import spaces from gymnasium.core import ObsType @@ -9,8 +9,6 @@ from primaite import getLogger from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -94,7 +92,7 @@ class FileObservation(AbstractObservation, identifier="FILE"): return spaces.Dict(space) @classmethod - def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> FileObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FileObservation: """ Create a file observation from a configuration schema. @@ -193,7 +191,7 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): return spaces.Dict(shape) @classmethod - def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> FolderObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FolderObservation: """ Create a folder observation from a configuration schema. @@ -211,5 +209,5 @@ class FolderObservation(AbstractObservation, identifier="FOLDER"): for file_config in config.files: file_config.include_num_access = config.include_num_access - files = [FileObservation.from_config(config=f, game=game, parent_where=where) for f in config.files] + files = [FileObservation.from_config(config=f, parent_where=where) for f in config.files] return cls(where=where, files=files, num_files=config.num_files, include_num_access=config.include_num_access) diff --git a/src/primaite/game/agent/observations/firewall_observation.py b/src/primaite/game/agent/observations/firewall_observation.py index 0a1498b1..97a8f814 100644 --- a/src/primaite/game/agent/observations/firewall_observation.py +++ b/src/primaite/game/agent/observations/firewall_observation.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, List, Optional, TYPE_CHECKING +from typing import Dict, List, Optional from gymnasium import spaces from gymnasium.core import ObsType @@ -10,8 +10,6 @@ from primaite.game.agent.observations.acl_observation import ACLObservation from primaite.game.agent.observations.nic_observations import PortObservation from primaite.game.agent.observations.observations import AbstractObservation, WhereType -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -200,9 +198,7 @@ class FirewallObservation(AbstractObservation, identifier="FIREWALL"): return space @classmethod - def from_config( - cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = [] - ) -> FirewallObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> FirewallObservation: """ Create a firewall observation from a configuration schema. diff --git a/src/primaite/game/agent/observations/host_observations.py b/src/primaite/game/agent/observations/host_observations.py index 6dbde789..b15ede9a 100644 --- a/src/primaite/game/agent/observations/host_observations.py +++ b/src/primaite/game/agent/observations/host_observations.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, List, Optional, TYPE_CHECKING +from typing import Dict, List, Optional from gymnasium import spaces from gymnasium.core import ObsType @@ -12,8 +12,6 @@ from primaite.game.agent.observations.observations import AbstractObservation, W from primaite.game.agent.observations.software_observation import ApplicationObservation, ServiceObservation from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -201,7 +199,7 @@ class HostObservation(AbstractObservation, identifier="HOST"): return spaces.Dict(shape) @classmethod - def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> HostObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> HostObservation: """ Create a host observation from a configuration schema. @@ -225,12 +223,10 @@ class HostObservation(AbstractObservation, identifier="HOST"): for nic_config in config.network_interfaces: nic_config.include_nmne = config.include_nmne - services = [ServiceObservation.from_config(config=c, game=game, parent_where=where) for c in config.services] - applications = [ - ApplicationObservation.from_config(config=c, game=game, parent_where=where) for c in config.applications - ] - folders = [FolderObservation.from_config(config=c, game=game, parent_where=where) for c in config.folders] - nics = [NICObservation.from_config(config=c, game=game, parent_where=where) for c in config.network_interfaces] + services = [ServiceObservation.from_config(config=c, parent_where=where) for c in config.services] + applications = [ApplicationObservation.from_config(config=c, parent_where=where) for c in config.applications] + folders = [FolderObservation.from_config(config=c, parent_where=where) for c in config.folders] + nics = [NICObservation.from_config(config=c, parent_where=where) for c in config.network_interfaces] return cls( where=where, diff --git a/src/primaite/game/agent/observations/link_observation.py b/src/primaite/game/agent/observations/link_observation.py index b55aae46..03a19fa0 100644 --- a/src/primaite/game/agent/observations/link_observation.py +++ b/src/primaite/game/agent/observations/link_observation.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Dict, List, TYPE_CHECKING +from typing import Any, Dict, List from gymnasium import spaces from gymnasium.core import ObsType @@ -9,8 +9,6 @@ from primaite import getLogger from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -68,14 +66,12 @@ class LinkObservation(AbstractObservation, identifier="LINK"): return spaces.Dict({"PROTOCOLS": spaces.Dict({"ALL": spaces.Discrete(11)})}) @classmethod - def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> LinkObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> LinkObservation: """ Create a link observation from a configuration schema. :param config: Configuration schema containing the necessary information for the link observation. :type config: ConfigSchema - :param game: The PrimaiteGame instance. - :type game: PrimaiteGame :param parent_where: Where in the simulation state dictionary to find the information about this link. A typical location might be ['network', 'links', ]. :type parent_where: WhereType, optional @@ -135,14 +131,12 @@ class LinksObservation(AbstractObservation, identifier="LINKS"): return spaces.Dict({i + 1: l.space for i, l in enumerate(self.links)}) @classmethod - def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> LinksObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> LinksObservation: """ Create a links observation from a configuration schema. :param config: Configuration schema containing the necessary information for the links observation. :type config: ConfigSchema - :param game: The PrimaiteGame instance. - :type game: PrimaiteGame :param parent_where: Where in the simulation state dictionary to find the information about these links. A typical location might be ['network']. :type parent_where: WhereType, optional @@ -151,5 +145,5 @@ class LinksObservation(AbstractObservation, identifier="LINKS"): """ where = parent_where + ["network"] link_cfgs = [LinkObservation.ConfigSchema(link_reference=ref) for ref in config.link_references] - links = [LinkObservation.from_config(c, game=game, parent_where=where) for c in link_cfgs] + links = [LinkObservation.from_config(c, parent_where=where) for c in link_cfgs] return cls(where=where, links=links) diff --git a/src/primaite/game/agent/observations/nic_observations.py b/src/primaite/game/agent/observations/nic_observations.py index 44cc7f8f..afce9095 100644 --- a/src/primaite/game/agent/observations/nic_observations.py +++ b/src/primaite/game/agent/observations/nic_observations.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, Optional, TYPE_CHECKING +from typing import Dict, Optional from gymnasium import spaces from gymnasium.core import ObsType @@ -8,9 +8,6 @@ from gymnasium.core import ObsType from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame - class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): """Status information about a network interface within the simulation environment.""" @@ -119,7 +116,7 @@ class NICObservation(AbstractObservation, identifier="NETWORK_INTERFACE"): return space @classmethod - def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> NICObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> NICObservation: """ Create a network interface observation from a configuration schema. @@ -179,7 +176,7 @@ class PortObservation(AbstractObservation, identifier="PORT"): return spaces.Dict({"operating_status": spaces.Discrete(3)}) @classmethod - def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> PortObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> PortObservation: """ Create a port observation from a configuration schema. diff --git a/src/primaite/game/agent/observations/node_observations.py b/src/primaite/game/agent/observations/node_observations.py index f11ffebf..8f7ac0fc 100644 --- a/src/primaite/game/agent/observations/node_observations.py +++ b/src/primaite/game/agent/observations/node_observations.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, List, Optional, TYPE_CHECKING +from typing import Dict, List, Optional from gymnasium import spaces from gymnasium.core import ObsType @@ -12,8 +12,6 @@ from primaite.game.agent.observations.host_observations import HostObservation from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.observations.router_observation import RouterObservation -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -152,7 +150,7 @@ class NodesObservation(AbstractObservation, identifier="NODES"): return space @classmethod - def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> NodesObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> NodesObservation: """ Create a nodes observation from a configuration schema. @@ -211,8 +209,8 @@ class NodesObservation(AbstractObservation, identifier="NODES"): if firewall_config.num_rules is None: firewall_config.num_rules = config.num_rules - hosts = [HostObservation.from_config(config=c, game=game, parent_where=where) for c in config.hosts] - routers = [RouterObservation.from_config(config=c, game=game, parent_where=where) for c in config.routers] - firewalls = [FirewallObservation.from_config(config=c, game=game, parent_where=where) for c in config.firewalls] + hosts = [HostObservation.from_config(config=c, parent_where=where) for c in config.hosts] + routers = [RouterObservation.from_config(config=c, parent_where=where) for c in config.routers] + firewalls = [FirewallObservation.from_config(config=c, parent_where=where) for c in config.firewalls] return cls(where=where, hosts=hosts, routers=routers, firewalls=firewalls) diff --git a/src/primaite/game/agent/observations/observation_manager.py b/src/primaite/game/agent/observations/observation_manager.py index 1d428fa8..047acce6 100644 --- a/src/primaite/game/agent/observations/observation_manager.py +++ b/src/primaite/game/agent/observations/observation_manager.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Dict, List, Optional, TYPE_CHECKING +from typing import Any, Dict, List, Optional from gymnasium import spaces from gymnasium.core import ObsType @@ -8,9 +8,6 @@ from pydantic import BaseModel, ConfigDict, model_validator, ValidationError from primaite.game.agent.observations.observations import AbstractObservation, WhereType -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame - class NestedObservation(AbstractObservation, identifier="CUSTOM"): """Observation type that allows combining other observations into a gymnasium.spaces.Dict space.""" @@ -76,7 +73,7 @@ class NestedObservation(AbstractObservation, identifier="CUSTOM"): return spaces.Dict({label: obs.space for label, obs in self.components.items()}) @classmethod - def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> NestedObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> NestedObservation: """ Read the Nested observation config and create all defined subcomponents. @@ -115,7 +112,7 @@ class NestedObservation(AbstractObservation, identifier="CUSTOM"): instances = dict() for component in config.components: obs_class = AbstractObservation._registry[component.type] - obs_instance = obs_class.from_config(config=obs_class.ConfigSchema(**component.options), game=game) + obs_instance = obs_class.from_config(config=obs_class.ConfigSchema(**component.options)) instances[component.label] = obs_instance return cls(components=instances) @@ -137,9 +134,7 @@ class NullObservation(AbstractObservation, identifier="NONE"): return spaces.Discrete(1) @classmethod - def from_config( - cls, config: NullObservation.ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = [] - ) -> NullObservation: + def from_config(cls, config: NullObservation.ConfigSchema, parent_where: WhereType = []) -> NullObservation: """Instantiate a NullObservation. Accepts parameters to comply with API.""" return cls() @@ -180,7 +175,7 @@ class ObservationManager: return self.obs.space @classmethod - def from_config(cls, config: Optional[Dict], game: "PrimaiteGame") -> "ObservationManager": + def from_config(cls, config: Optional[Dict]) -> "ObservationManager": """ Create observation space from a config. @@ -191,14 +186,12 @@ class ObservationManager: AbstractObservation options: this must adhere to the chosen observation type's ConfigSchema nested class. :type config: Dict - :param game: Reference to the PrimaiteGame object that spawned this observation. - :type game: PrimaiteGame """ if config is None: return cls(NullObservation()) print(config) obs_type = config["type"] obs_class = AbstractObservation._registry[obs_type] - observation = obs_class.from_config(config=obs_class.ConfigSchema(**config["options"]), game=game) + observation = obs_class.from_config(config=obs_class.ConfigSchema(**config["options"])) obs_manager = cls(observation) return obs_manager diff --git a/src/primaite/game/agent/observations/observations.py b/src/primaite/game/agent/observations/observations.py index 6c9db571..0d6ff2a3 100644 --- a/src/primaite/game/agent/observations/observations.py +++ b/src/primaite/game/agent/observations/observations.py @@ -1,6 +1,6 @@ """Manages the observation space for the agent.""" from abc import ABC, abstractmethod -from typing import Any, Dict, Iterable, Type, TYPE_CHECKING +from typing import Any, Dict, Iterable, Type from gymnasium import spaces from gymnasium.core import ObsType @@ -8,8 +8,6 @@ from pydantic import BaseModel, ConfigDict from primaite import getLogger -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) WhereType = Iterable[str | int] | None @@ -65,8 +63,6 @@ class AbstractObservation(ABC): @classmethod @abstractmethod - def from_config( - cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = [] - ) -> "AbstractObservation": + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> "AbstractObservation": """Create this observation space component form a serialised format.""" return cls() diff --git a/src/primaite/game/agent/observations/router_observation.py b/src/primaite/game/agent/observations/router_observation.py index aeac2766..3f7e6494 100644 --- a/src/primaite/game/agent/observations/router_observation.py +++ b/src/primaite/game/agent/observations/router_observation.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, List, Optional, TYPE_CHECKING +from typing import Dict, List, Optional from gymnasium import spaces from gymnasium.core import ObsType @@ -11,8 +11,6 @@ from primaite.game.agent.observations.nic_observations import PortObservation from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame _LOGGER = getLogger(__name__) @@ -112,7 +110,7 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): return spaces.Dict(shape) @classmethod - def from_config(cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = []) -> RouterObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> RouterObservation: """ Create a router observation from a configuration schema. @@ -142,6 +140,6 @@ class RouterObservation(AbstractObservation, identifier="ROUTER"): if config.ports is None: config.ports = [PortObservation.ConfigSchema(port_id=i + 1) for i in range(config.num_ports)] - ports = [PortObservation.from_config(config=c, game=game, parent_where=where) for c in config.ports] - acl = ACLObservation.from_config(config=config.acl, game=game, parent_where=where) + ports = [PortObservation.from_config(config=c, parent_where=where) for c in config.ports] + acl = ACLObservation.from_config(config=config.acl, parent_where=where) return cls(where=where, ports=ports, num_ports=config.num_ports, acl=acl) diff --git a/src/primaite/game/agent/observations/software_observation.py b/src/primaite/game/agent/observations/software_observation.py index 2c4806d9..f943f540 100644 --- a/src/primaite/game/agent/observations/software_observation.py +++ b/src/primaite/game/agent/observations/software_observation.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Dict, TYPE_CHECKING +from typing import Dict from gymnasium import spaces from gymnasium.core import ObsType @@ -8,9 +8,6 @@ from gymnasium.core import ObsType from primaite.game.agent.observations.observations import AbstractObservation, WhereType from primaite.game.agent.utils import access_from_nested_dict, NOT_PRESENT_IN_STATE -if TYPE_CHECKING: - from primaite.game.game import PrimaiteGame - class ServiceObservation(AbstractObservation, identifier="SERVICE"): """Service observation, shows status of a service in the simulation environment.""" @@ -60,9 +57,7 @@ class ServiceObservation(AbstractObservation, identifier="SERVICE"): return spaces.Dict({"operating_status": spaces.Discrete(7), "health_status": spaces.Discrete(5)}) @classmethod - def from_config( - cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = [] - ) -> ServiceObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ServiceObservation: """ Create a service observation from a configuration schema. @@ -153,9 +148,7 @@ class ApplicationObservation(AbstractObservation, identifier="APPLICATION"): ) @classmethod - def from_config( - cls, config: ConfigSchema, game: "PrimaiteGame", parent_where: WhereType = [] - ) -> ApplicationObservation: + def from_config(cls, config: ConfigSchema, parent_where: WhereType = []) -> ApplicationObservation: """ Create an application observation from a configuration schema. diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 034d11bc..2d007193 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -396,8 +396,8 @@ class PrimaiteGame: # 2. create links between nodes for link_cfg in links_cfg: - node_a = net.nodes[game.ref_map_nodes[link_cfg["endpoint_a_ref"]]] - node_b = net.nodes[game.ref_map_nodes[link_cfg["endpoint_b_ref"]]] + node_a = net.get_node_by_hostname(link_cfg["endpoint_a_ref"]) + node_b = net.get_node_by_hostname(link_cfg["endpoint_b_ref"]) if isinstance(node_a, Switch): endpoint_a = node_a.network_interface[link_cfg["endpoint_a_port"]] else: @@ -419,7 +419,7 @@ class PrimaiteGame: reward_function_cfg = agent_cfg["reward_function"] # CREATE OBSERVATION SPACE - obs_space = ObservationManager.from_config(observation_space_cfg, game) + obs_space = ObservationManager.from_config(observation_space_cfg) # CREATE ACTION SPACE action_space = ActionManager.from_config(game, action_space_cfg) From 698cb83e41596c4d44db6a543fd2400101489ead Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 3 Apr 2024 22:20:33 +0100 Subject: [PATCH 795/980] #2450 change link definition schema --- .../_package_data/data_manipulation.yaml | 40 +++++++++---------- .../_package_data/data_manipulation_marl.yaml | 40 +++++++++---------- src/primaite/game/game.py | 4 +- .../assets/configs/bad_primaite_session.yaml | 40 +++++++++---------- tests/assets/configs/basic_firewall.yaml | 16 ++++---- .../configs/basic_switched_network.yaml | 8 ++-- tests/assets/configs/dmz_network.yaml | 32 +++++++-------- .../configs/eval_only_primaite_session.yaml | 40 +++++++++---------- .../configs/firewall_actions_network.yaml | 32 +++++++-------- tests/assets/configs/multi_agent_session.yaml | 40 +++++++++---------- tests/assets/configs/shared_rewards.yaml | 40 +++++++++---------- .../configs/test_application_install.yaml | 40 +++++++++---------- .../assets/configs/test_primaite_session.yaml | 40 +++++++++---------- .../configs/train_only_primaite_session.yaml | 40 +++++++++---------- 14 files changed, 226 insertions(+), 226 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index c68480cf..f2e8938b 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -925,43 +925,43 @@ simulation: type: DNSClient links: - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 8 - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 2 - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 8 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 1 - endpoint_b_ref: domain_controller + endpoint_b_hostname: domain_controller endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 2 - endpoint_b_ref: web_server + endpoint_b_hostname: web_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 3 - endpoint_b_ref: database_server + endpoint_b_hostname: database_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 4 - endpoint_b_ref: backup_server + endpoint_b_hostname: backup_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 1 - endpoint_b_ref: client_1 + endpoint_b_hostname: client_1 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 2 - endpoint_b_ref: client_2 + endpoint_b_hostname: client_2 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 2 diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index 9ec2a1f2..ee9f094f 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -1505,43 +1505,43 @@ simulation: links: - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 8 - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 2 - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 8 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 1 - endpoint_b_ref: domain_controller + endpoint_b_hostname: domain_controller endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 2 - endpoint_b_ref: web_server + endpoint_b_hostname: web_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 3 - endpoint_b_ref: database_server + endpoint_b_hostname: database_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 4 - endpoint_b_ref: backup_server + endpoint_b_hostname: backup_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 1 - endpoint_b_ref: client_1 + endpoint_b_hostname: client_1 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 2 - endpoint_b_ref: client_2 + endpoint_b_hostname: client_2 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 2 diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 2d007193..bfbffc4d 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -396,8 +396,8 @@ class PrimaiteGame: # 2. create links between nodes for link_cfg in links_cfg: - node_a = net.get_node_by_hostname(link_cfg["endpoint_a_ref"]) - node_b = net.get_node_by_hostname(link_cfg["endpoint_b_ref"]) + node_a = net.get_node_by_hostname(link_cfg["endpoint_a_hostname"]) + node_b = net.get_node_by_hostname(link_cfg["endpoint_b_hostname"]) if isinstance(node_a, Switch): endpoint_a = node_a.network_interface[link_cfg["endpoint_a_port"]] else: diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 19cad586..493b0452 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -687,43 +687,43 @@ simulation: type: DNSClient links: - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 8 - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 2 - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 8 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 1 - endpoint_b_ref: domain_controller + endpoint_b_hostname: domain_controller endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 2 - endpoint_b_ref: web_server + endpoint_b_hostname: web_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 3 - endpoint_b_ref: database_server + endpoint_b_hostname: database_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 4 - endpoint_b_ref: backup_server + endpoint_b_hostname: backup_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 1 - endpoint_b_ref: client_1 + endpoint_b_hostname: client_1 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 2 - endpoint_b_ref: client_2 + endpoint_b_hostname: client_2 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 2 diff --git a/tests/assets/configs/basic_firewall.yaml b/tests/assets/configs/basic_firewall.yaml index da293167..3aa2ca2d 100644 --- a/tests/assets/configs/basic_firewall.yaml +++ b/tests/assets/configs/basic_firewall.yaml @@ -161,22 +161,22 @@ simulation: links: - ref: switch_1___client_1 - endpoint_a_ref: switch_1 + endpoint_a_hostname: switch_1 endpoint_a_port: 1 - endpoint_b_ref: client_1 + endpoint_b_hostname: client_1 endpoint_b_port: 1 - ref: switch_2___client_2 - endpoint_a_ref: switch_2 + endpoint_a_hostname: switch_2 endpoint_a_port: 1 - endpoint_b_ref: client_2 + endpoint_b_hostname: client_2 endpoint_b_port: 1 - ref: switch_1___firewall - endpoint_a_ref: switch_1 + endpoint_a_hostname: switch_1 endpoint_a_port: 2 - endpoint_b_ref: firewall + endpoint_b_hostname: firewall endpoint_b_port: 1 - ref: switch_2___firewall - endpoint_a_ref: switch_2 + endpoint_a_hostname: switch_2 endpoint_a_port: 2 - endpoint_b_ref: firewall + endpoint_b_hostname: firewall endpoint_b_port: 2 diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 009f239a..ab55a6ed 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -162,11 +162,11 @@ simulation: # pre installed services and applications links: - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 1 - endpoint_b_ref: client_1 + endpoint_b_hostname: client_1 endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 2 - endpoint_b_ref: client_2 + endpoint_b_hostname: client_2 endpoint_b_port: 1 diff --git a/tests/assets/configs/dmz_network.yaml b/tests/assets/configs/dmz_network.yaml index acac301a..0930bc7d 100644 --- a/tests/assets/configs/dmz_network.yaml +++ b/tests/assets/configs/dmz_network.yaml @@ -267,42 +267,42 @@ simulation: type: DNSServer links: - ref: client_1___switch_1 - endpoint_a_ref: client_1 + endpoint_a_hostname: client_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 1 - ref: router_1___switch_1 - endpoint_a_ref: router_1 + endpoint_a_hostname: router_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 8 - ref: router_1___firewall - endpoint_a_ref: firewall + endpoint_a_hostname: firewall endpoint_a_port: 2 # internal firewall port - endpoint_b_ref: router_1 + endpoint_b_hostname: router_1 endpoint_b_port: 2 - ref: firewall___switch_2 - endpoint_a_ref: firewall + endpoint_a_hostname: firewall endpoint_a_port: 3 # dmz firewall port - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 8 - ref: dmz_server___switch_2 - endpoint_a_ref: dmz_server + endpoint_a_hostname: dmz_server endpoint_a_port: 1 - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 1 - ref: firewall___switch_3 - endpoint_a_ref: firewall + endpoint_a_hostname: firewall endpoint_a_port: 1 # external firewall port - endpoint_b_ref: switch_3 + endpoint_b_hostname: switch_3 endpoint_b_port: 8 - ref: external_computer___switch_3 - endpoint_a_ref: external_computer + endpoint_a_hostname: external_computer endpoint_a_port: 1 - endpoint_b_ref: switch_3 + endpoint_b_hostname: switch_3 endpoint_b_port: 1 - ref: external_server___switch_3 - endpoint_a_ref: external_server + endpoint_a_hostname: external_server endpoint_a_port: 1 - endpoint_b_ref: switch_3 + endpoint_b_hostname: switch_3 endpoint_b_port: 2 diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index c342ed72..918f00ca 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -703,43 +703,43 @@ simulation: type: DNSClient links: - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 8 - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 2 - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 8 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 1 - endpoint_b_ref: domain_controller + endpoint_b_hostname: domain_controller endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 2 - endpoint_b_ref: web_server + endpoint_b_hostname: web_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 3 - endpoint_b_ref: database_server + endpoint_b_hostname: database_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 4 - endpoint_b_ref: backup_server + endpoint_b_hostname: backup_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 1 - endpoint_b_ref: client_1 + endpoint_b_hostname: client_1 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 2 - endpoint_b_ref: client_2 + endpoint_b_hostname: client_2 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 2 diff --git a/tests/assets/configs/firewall_actions_network.yaml b/tests/assets/configs/firewall_actions_network.yaml index cf10505e..4e134fe6 100644 --- a/tests/assets/configs/firewall_actions_network.yaml +++ b/tests/assets/configs/firewall_actions_network.yaml @@ -461,42 +461,42 @@ simulation: type: DNSServer links: - ref: client_1___switch_1 - endpoint_a_ref: client_1 + endpoint_a_hostname: client_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 1 - ref: router_1___switch_1 - endpoint_a_ref: router_1 + endpoint_a_hostname: router_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 8 - ref: router_1___firewall - endpoint_a_ref: firewall + endpoint_a_hostname: firewall endpoint_a_port: 2 # internal firewall port - endpoint_b_ref: router_1 + endpoint_b_hostname: router_1 endpoint_b_port: 2 - ref: firewall___switch_2 - endpoint_a_ref: firewall + endpoint_a_hostname: firewall endpoint_a_port: 3 # dmz firewall port - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 8 - ref: dmz_server___switch_2 - endpoint_a_ref: dmz_server + endpoint_a_hostname: dmz_server endpoint_a_port: 1 - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 1 - ref: firewall___switch_3 - endpoint_a_ref: firewall + endpoint_a_hostname: firewall endpoint_a_port: 1 # external firewall port - endpoint_b_ref: switch_3 + endpoint_b_hostname: switch_3 endpoint_b_port: 8 - ref: external_computer___switch_3 - endpoint_a_ref: external_computer + endpoint_a_hostname: external_computer endpoint_a_port: 1 - endpoint_b_ref: switch_3 + endpoint_b_hostname: switch_3 endpoint_b_port: 1 - ref: external_server___switch_3 - endpoint_a_ref: external_server + endpoint_a_hostname: external_server endpoint_a_port: 1 - endpoint_b_ref: switch_3 + endpoint_b_hostname: switch_3 endpoint_b_port: 2 diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 35431064..e4342582 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -1162,43 +1162,43 @@ simulation: type: DNSClient links: - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 8 - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 2 - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 8 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 1 - endpoint_b_ref: domain_controller + endpoint_b_hostname: domain_controller endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 2 - endpoint_b_ref: web_server + endpoint_b_hostname: web_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 3 - endpoint_b_ref: database_server + endpoint_b_hostname: database_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 4 - endpoint_b_ref: backup_server + endpoint_b_hostname: backup_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 1 - endpoint_b_ref: client_1 + endpoint_b_hostname: client_1 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 2 - endpoint_b_ref: client_2 + endpoint_b_hostname: client_2 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 2 diff --git a/tests/assets/configs/shared_rewards.yaml b/tests/assets/configs/shared_rewards.yaml index 9cf4d17d..7df6802c 100644 --- a/tests/assets/configs/shared_rewards.yaml +++ b/tests/assets/configs/shared_rewards.yaml @@ -921,43 +921,43 @@ simulation: links: - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 8 - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 2 - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 8 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 1 - endpoint_b_ref: domain_controller + endpoint_b_hostname: domain_controller endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 2 - endpoint_b_ref: web_server + endpoint_b_hostname: web_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 3 - endpoint_b_ref: database_server + endpoint_b_hostname: database_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 4 - endpoint_b_ref: backup_server + endpoint_b_hostname: backup_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 1 - endpoint_b_ref: client_1 + endpoint_b_hostname: client_1 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 2 - endpoint_b_ref: client_2 + endpoint_b_hostname: client_2 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 2 diff --git a/tests/assets/configs/test_application_install.yaml b/tests/assets/configs/test_application_install.yaml index d2e85f30..a2059913 100644 --- a/tests/assets/configs/test_application_install.yaml +++ b/tests/assets/configs/test_application_install.yaml @@ -953,43 +953,43 @@ simulation: links: - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 8 - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 2 - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 8 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 1 - endpoint_b_ref: domain_controller + endpoint_b_hostname: domain_controller endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 2 - endpoint_b_ref: web_server + endpoint_b_hostname: web_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 3 - endpoint_b_ref: database_server + endpoint_b_hostname: database_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 4 - endpoint_b_ref: backup_server + endpoint_b_hostname: backup_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 1 - endpoint_b_ref: client_1 + endpoint_b_hostname: client_1 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 2 - endpoint_b_ref: client_2 + endpoint_b_hostname: client_2 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 2 diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 1fd489ec..fc72cfd7 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -743,43 +743,43 @@ simulation: protocol: ICMP links: - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 8 - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 2 - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 8 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 1 - endpoint_b_ref: domain_controller + endpoint_b_hostname: domain_controller endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 2 - endpoint_b_ref: web_server + endpoint_b_hostname: web_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 3 - endpoint_b_ref: database_server + endpoint_b_hostname: database_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 4 - endpoint_b_ref: backup_server + endpoint_b_hostname: backup_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 1 - endpoint_b_ref: client_1 + endpoint_b_hostname: client_1 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 2 - endpoint_b_ref: client_2 + endpoint_b_hostname: client_2 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 2 diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index ca26fc62..b083505e 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -710,43 +710,43 @@ simulation: type: DNSClient links: - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 1 - endpoint_b_ref: switch_1 + endpoint_b_hostname: switch_1 endpoint_b_port: 8 - - endpoint_a_ref: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 2 - endpoint_b_ref: switch_2 + endpoint_b_hostname: switch_2 endpoint_b_port: 8 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 1 - endpoint_b_ref: domain_controller + endpoint_b_hostname: domain_controller endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 2 - endpoint_b_ref: web_server + endpoint_b_hostname: web_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 3 - endpoint_b_ref: database_server + endpoint_b_hostname: database_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 4 - endpoint_b_ref: backup_server + endpoint_b_hostname: backup_server endpoint_b_port: 1 - - endpoint_a_ref: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 1 - endpoint_b_ref: client_1 + endpoint_b_hostname: client_1 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 2 - endpoint_b_ref: client_2 + endpoint_b_hostname: client_2 endpoint_b_port: 1 - - endpoint_a_ref: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 7 - endpoint_b_ref: security_suite + endpoint_b_hostname: security_suite endpoint_b_port: 2 From 3b4962830a9d9763862b71ff4eeef2ec36a7c113 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Wed, 3 Apr 2024 22:52:06 +0100 Subject: [PATCH 796/980] #2450 remove unused ref maps in PrimaiteGame --- .../_package_data/data_manipulation.yaml | 72 +++++++------------ .../_package_data/data_manipulation_marl.yaml | 72 +++++++------------ src/primaite/game/game.py | 15 ---- .../assets/configs/bad_primaite_session.yaml | 57 +++++---------- tests/assets/configs/basic_firewall.yaml | 27 +++---- .../configs/basic_switched_network.yaml | 45 ++++-------- tests/assets/configs/dmz_network.yaml | 54 +++++--------- .../configs/eval_only_primaite_session.yaml | 57 +++++---------- .../configs/firewall_actions_network.yaml | 54 +++++--------- tests/assets/configs/multi_agent_session.yaml | 57 +++++---------- tests/assets/configs/shared_rewards.yaml | 72 +++++++------------ .../configs/test_application_install.yaml | 72 +++++++------------ .../assets/configs/test_primaite_session.yaml | 63 ++++++---------- .../configs/train_only_primaite_session.yaml | 57 +++++---------- 14 files changed, 253 insertions(+), 521 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index f2e8938b..deda5d73 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -756,8 +756,7 @@ simulation: - DELETE nodes: - - ref: router_1 - hostname: router_1 + - hostname: router_1 type: router num_ports: 5 ports: @@ -792,74 +791,61 @@ simulation: action: PERMIT protocol: ICMP - - ref: switch_1 - hostname: switch_1 + - hostname: switch_1 type: switch num_ports: 8 - - ref: switch_2 - hostname: switch_2 + - hostname: switch_2 type: switch num_ports: 8 - - ref: domain_controller - hostname: domain_controller + - hostname: domain_controller type: server ip_address: 192.168.1.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 services: - - ref: domain_controller_dns_server - type: DNSServer + - type: DNSServer options: domain_mapping: arcd.com: 192.168.1.12 # web server - - ref: web_server - hostname: web_server + - hostname: web_server type: server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: web_server_web_service - type: WebServer + - type: WebServer applications: - - ref: web_server_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: database_server - hostname: database_server + - hostname: database_server type: server ip_address: 192.168.1.14 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: database_service - type: DatabaseService + - type: DatabaseService options: backup_server_ip: 192.168.1.16 - - ref: database_ftp_client - type: FTPClient + - type: FTPClient - - ref: backup_server - hostname: backup_server + - hostname: backup_server type: server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: backup_service - type: FTPServer + - type: FTPServer - - ref: security_suite - hostname: security_suite + - hostname: security_suite type: server ip_address: 192.168.1.110 subnet_mask: 255.255.255.0 @@ -870,59 +856,49 @@ simulation: ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 - - ref: client_1 - hostname: client_1 + - hostname: client_1 type: computer ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.8 data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 - - ref: client_1_web_browser - type: WebBrowser + - type: WebBrowser options: target_url: http://arcd.com/users/ - - ref: client_1_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 services: - - ref: client_1_dns_client - type: DNSClient + - type: DNSClient - - ref: client_2 - hostname: client_2 + - hostname: client_2 type: computer ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: client_2_web_browser - type: WebBrowser + - type: WebBrowser options: target_url: http://arcd.com/users/ - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.8 data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 - - ref: client_2_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 services: - - ref: client_2_dns_client - type: DNSClient + - type: DNSClient links: - endpoint_a_hostname: router_1 diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index ee9f094f..653ddfd3 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -1334,8 +1334,7 @@ simulation: - DELETE nodes: - - ref: router_1 - hostname: router_1 + - hostname: router_1 type: router num_ports: 5 ports: @@ -1370,74 +1369,61 @@ simulation: action: PERMIT protocol: ICMP - - ref: switch_1 - hostname: switch_1 + - hostname: switch_1 type: switch num_ports: 8 - - ref: switch_2 - hostname: switch_2 + - hostname: switch_2 type: switch num_ports: 8 - - ref: domain_controller - hostname: domain_controller + - hostname: domain_controller type: server ip_address: 192.168.1.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 services: - - ref: domain_controller_dns_server - type: DNSServer + - type: DNSServer options: domain_mapping: arcd.com: 192.168.1.12 # web server - - ref: web_server - hostname: web_server + - hostname: web_server type: server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: web_server_web_service - type: WebServer + - type: WebServer applications: - - ref: web_server_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: database_server - hostname: database_server + - hostname: database_server type: server ip_address: 192.168.1.14 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: database_service - type: DatabaseService + - type: DatabaseService options: backup_server_ip: 192.168.1.16 - - ref: database_ftp_client - type: FTPClient + - type: FTPClient - - ref: backup_server - hostname: backup_server + - hostname: backup_server type: server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: backup_service - type: FTPServer + - type: FTPServer - - ref: security_suite - hostname: security_suite + - hostname: security_suite type: server ip_address: 192.168.1.110 subnet_mask: 255.255.255.0 @@ -1448,59 +1434,49 @@ simulation: ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 - - ref: client_1 - hostname: client_1 + - hostname: client_1 type: computer ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.8 data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 - - ref: client_1_web_browser - type: WebBrowser + - type: WebBrowser options: target_url: http://arcd.com/users/ - - ref: client_1_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 services: - - ref: client_1_dns_client - type: DNSClient + - type: DNSClient - - ref: client_2 - hostname: client_2 + - hostname: client_2 type: computer ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: client_2_web_browser - type: WebBrowser + - type: WebBrowser options: target_url: http://arcd.com/users/ - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.8 data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 - - ref: client_2_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 services: - - ref: client_2_dns_client - type: DNSClient + - ty DNSClient diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index bfbffc4d..f069433e 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -102,15 +102,6 @@ class PrimaiteGame: self.options: PrimaiteGameOptions """Special options that apply for the entire game.""" - self.ref_map_nodes: Dict[str, str] = {} - """Mapping from unique node reference name to node object. Used when parsing config files.""" - - self.ref_map_services: Dict[str, str] = {} - """Mapping from human-readable service reference to service object. Used for parsing config files.""" - - self.ref_map_applications: Dict[str, str] = {} - """Mapping from human-readable application reference to application object. Used for parsing config files.""" - self.save_step_metadata: bool = False """Whether to save the RL agents' action, environment state, and other data at every single step.""" @@ -235,7 +226,6 @@ class PrimaiteGame: links_cfg = network_config.get("links", []) for node_cfg in nodes_cfg: - node_ref = node_cfg["ref"] n_type = node_cfg["type"] if n_type == "computer": new_node = Computer( @@ -286,13 +276,11 @@ class PrimaiteGame: if "services" in node_cfg: for service_cfg in node_cfg["services"]: new_service = None - service_ref = service_cfg["ref"] service_type = service_cfg["type"] if service_type in SERVICE_TYPES_MAPPING: _LOGGER.debug(f"installing {service_type} on node {new_node.hostname}") new_node.software_manager.install(SERVICE_TYPES_MAPPING[service_type]) new_service = new_node.software_manager.software[service_type] - game.ref_map_services[service_ref] = new_service.uuid # start the service new_service.start() @@ -328,13 +316,11 @@ class PrimaiteGame: if "applications" in node_cfg: for application_cfg in node_cfg["applications"]: new_application = None - application_ref = application_cfg["ref"] application_type = application_cfg["type"] if application_type in APPLICATION_TYPES_MAPPING: new_node.software_manager.install(APPLICATION_TYPES_MAPPING[application_type]) new_application = new_node.software_manager.software[application_type] - game.ref_map_applications[application_ref] = new_application.uuid else: msg = f"Configuration contains an invalid application type: {application_type}" _LOGGER.error(msg) @@ -388,7 +374,6 @@ class PrimaiteGame: # run through the power on step if the node is to be turned on at the start if new_node.operating_state == NodeOperatingState.ON: new_node.power_on() - game.ref_map_nodes[node_ref] = new_node.uuid # set start up and shut down duration new_node.start_up_duration = int(node_cfg.get("start_up_duration", 3)) diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 493b0452..7d85ea9f 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -551,8 +551,7 @@ simulation: network: nodes: - - ref: router_1 - type: router + - type: router hostname: router_1 num_ports: 5 ports: @@ -579,70 +578,58 @@ simulation: action: PERMIT protocol: ICMP - - ref: switch_1 - type: switch + - type: switch hostname: switch_1 num_ports: 8 - - ref: switch_2 - type: switch + - type: switch hostname: switch_2 num_ports: 8 - - ref: domain_controller - type: server + - type: server hostname: domain_controller ip_address: 192.168.1.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 services: - - ref: domain_controller_dns_server - type: DNSServer + - type: DNSServer options: domain_mapping: arcd.com: 192.168.1.12 # web server - - ref: web_server - type: server + - type: server hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: web_server_web_service - type: WebServer + - type: WebServer applications: - - ref: web_server_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: database_server - type: server + - type: server hostname: database_server ip_address: 192.168.1.14 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: database_service - type: DatabaseService + - type: DatabaseService - - ref: backup_server - type: server + - type: server hostname: backup_server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: backup_service - type: FTPServer + - type: FTPServer - - ref: security_suite - type: server + - type: server hostname: security_suite ip_address: 192.168.1.110 subnet_mask: 255.255.255.0 @@ -653,38 +640,32 @@ simulation: ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 - - ref: client_1 - type: computer + - type: computer hostname: client_1 ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.1 data_manipulation_p_of_success: 0.1 payload: "DELETE" server_ip: 192.168.1.14 services: - - ref: client_1_dns_client - type: DNSClient + - type: DNSClient - - ref: client_2 - type: computer + - type: computer hostname: client_2 ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: client_2_web_browser - type: WebBrowser + - type: WebBrowser services: - - ref: client_2_dns_client - type: DNSClient + - type: DNSClient links: - endpoint_a_hostname: router_1 diff --git a/tests/assets/configs/basic_firewall.yaml b/tests/assets/configs/basic_firewall.yaml index 3aa2ca2d..0512fbe1 100644 --- a/tests/assets/configs/basic_firewall.yaml +++ b/tests/assets/configs/basic_firewall.yaml @@ -79,8 +79,7 @@ simulation: network: nodes: - - ref: firewall - type: firewall + - type: firewall hostname: firewall start_up_duration: 0 shut_down_duration: 0 @@ -133,25 +132,21 @@ simulation: action: PERMIT protocol: ICMP - - ref: switch_1 - type: switch + - type: switch hostname: switch_1 num_ports: 8 - - ref: switch_2 - type: switch + - type: switch hostname: switch_2 num_ports: 8 - - ref: client_1 - type: computer + - type: computer hostname: client_1 ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 # pre installed services and applications - - ref: client_2 - type: computer + - type: computer hostname: client_2 ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 @@ -160,23 +155,19 @@ simulation: # pre installed services and applications links: - - ref: switch_1___client_1 - endpoint_a_hostname: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 1 endpoint_b_hostname: client_1 endpoint_b_port: 1 - - ref: switch_2___client_2 - endpoint_a_hostname: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 1 endpoint_b_hostname: client_2 endpoint_b_port: 1 - - ref: switch_1___firewall - endpoint_a_hostname: switch_1 + - endpoint_a_hostname: switch_1 endpoint_a_port: 2 endpoint_b_hostname: firewall endpoint_b_port: 1 - - ref: switch_2___firewall - endpoint_a_hostname: switch_2 + - endpoint_a_hostname: switch_2 endpoint_a_port: 2 endpoint_b_hostname: firewall endpoint_b_port: 2 diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index ab55a6ed..bbc45de2 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -79,79 +79,64 @@ simulation: network: nodes: - - ref: switch_1 - type: switch + - type: switch hostname: switch_1 num_ports: 8 - - ref: client_1 + - hostname: client_1 type: computer - hostname: client_1 ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: client_1_web_browser - type: WebBrowser + - type: WebBrowser options: target_url: http://arcd.com/users/ - - ref: client_1_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.10 server_password: arcd - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.8 data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.21 server_password: arcd - - ref: dos_bot - type: DoSBot + - type: DoSBot options: target_ip_address: 192.168.10.21 payload: SPOOF DATA port_scan_p_of_success: 0.8 services: - - ref: client_1_dns_client - type: DNSClient + - type: DNSClient options: dns_server: 192.168.1.10 - - ref: client_1_dns_server - type: DNSServer + - type: DNSServer options: domain_mapping: arcd.com: 192.168.1.10 - - ref: client_1_database_service - type: DatabaseService + - type: DatabaseService options: backup_server_ip: 192.168.1.10 - - ref: client_1_web_service - type: WebServer - - ref: client_1_ftp_server - type: FTPServer + - type: WebServer + - type: FTPServer options: server_password: arcd - - ref: client_1_ntp_client - type: NTPClient + - type: NTPClient options: ntp_server_ip: 192.168.1.10 - - ref: client_1_ntp_server - type: NTPServer - - ref: client_2 + - type: NTPServer + - hostname: client_2 type: computer - hostname: client_2 ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 # pre installed services and applications - - ref: client_3 + - hostname: client_3 type: computer - hostname: client_3 ip_address: 192.168.10.23 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 diff --git a/tests/assets/configs/dmz_network.yaml b/tests/assets/configs/dmz_network.yaml index 0930bc7d..2ce722f7 100644 --- a/tests/assets/configs/dmz_network.yaml +++ b/tests/assets/configs/dmz_network.yaml @@ -104,8 +104,7 @@ agents: simulation: network: nodes: - - ref: client_1 - type: computer + - type: computer hostname: client_1 ip_address: 192.168.0.10 subnet_mask: 255.255.255.0 @@ -114,15 +113,13 @@ simulation: start_up_duration: 0 shut_down_duration: 0 - - ref: switch_1 - type: switch + - type: switch hostname: switch_1 num_ports: 8 start_up_duration: 0 shut_down_duration: 0 - - ref: router_1 - type: router + - type: router hostname: router_1 num_ports: 5 start_up_duration: 0 @@ -156,8 +153,7 @@ simulation: next_hop_ip_address: 192.168.1.2 metric: 0 - - ref: dmz_server - type: server + - type: server hostname: dmz_server ip_address: 192.168.10.10 subnet_mask: 255.255.255.0 @@ -166,15 +162,13 @@ simulation: start_up_duration: 0 shut_down_duration: 0 - - ref: switch_2 - type: switch + - type: switch hostname: switch_2 num_ports: 8 start_up_duration: 0 shut_down_duration: 0 - - ref: firewall - type: firewall + - type: firewall hostname: firewall start_up_duration: 0 shut_down_duration: 0 @@ -237,15 +231,13 @@ simulation: next_hop_ip_address: 192.168.1.1 metric: 0 - - ref: switch_3 - type: switch + - type: switch hostname: switch_3 num_ports: 8 start_up_duration: 0 shut_down_duration: 0 - - ref: external_computer - type: computer + - type: computer hostname: external_computer ip_address: 192.168.20.10 subnet_mask: 255.255.255.0 @@ -254,8 +246,7 @@ simulation: start_up_duration: 0 shut_down_duration: 0 - - ref: external_server - type: server + - type: server hostname: external_server ip_address: 192.168.20.11 subnet_mask: 255.255.255.0 @@ -263,46 +254,37 @@ simulation: start_up_duration: 0 shut_down_duration: 0 services: - - ref: domain_controller_dns_server - type: DNSServer + - type: DNSServer links: - - ref: client_1___switch_1 - endpoint_a_hostname: client_1 + - endpoint_a_hostname: client_1 endpoint_a_port: 1 endpoint_b_hostname: switch_1 endpoint_b_port: 1 - - ref: router_1___switch_1 - endpoint_a_hostname: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 1 endpoint_b_hostname: switch_1 endpoint_b_port: 8 - - ref: router_1___firewall - endpoint_a_hostname: firewall + - endpoint_a_hostname: firewall endpoint_a_port: 2 # internal firewall port endpoint_b_hostname: router_1 endpoint_b_port: 2 - - ref: firewall___switch_2 - endpoint_a_hostname: firewall + - endpoint_a_hostname: firewall endpoint_a_port: 3 # dmz firewall port endpoint_b_hostname: switch_2 endpoint_b_port: 8 - - ref: dmz_server___switch_2 - endpoint_a_hostname: dmz_server + - endpoint_a_hostname: dmz_server endpoint_a_port: 1 endpoint_b_hostname: switch_2 endpoint_b_port: 1 - - ref: firewall___switch_3 - endpoint_a_hostname: firewall + - endpoint_a_hostname: firewall endpoint_a_port: 1 # external firewall port endpoint_b_hostname: switch_3 endpoint_b_port: 8 - - ref: external_computer___switch_3 - endpoint_a_hostname: external_computer + - endpoint_a_hostname: external_computer endpoint_a_port: 1 endpoint_b_hostname: switch_3 endpoint_b_port: 1 - - ref: external_server___switch_3 - endpoint_a_hostname: external_server + - endpoint_a_hostname: external_server endpoint_a_port: 1 endpoint_b_hostname: switch_3 endpoint_b_port: 2 diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index 918f00ca..f05e3390 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -567,8 +567,7 @@ simulation: network: nodes: - - ref: router_1 - type: router + - type: router hostname: router_1 num_ports: 5 ports: @@ -595,70 +594,58 @@ simulation: action: PERMIT protocol: ICMP - - ref: switch_1 - type: switch + - type: switch hostname: switch_1 num_ports: 8 - - ref: switch_2 - type: switch + - type: switch hostname: switch_2 num_ports: 8 - - ref: domain_controller - type: server + - type: server hostname: domain_controller ip_address: 192.168.1.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 services: - - ref: domain_controller_dns_server - type: DNSServer + - type: DNSServer options: domain_mapping: arcd.com: 192.168.1.12 # web server - - ref: web_server - type: server + - type: server hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: web_server_web_service - type: WebServer + - type: WebServer applications: - - ref: web_server_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: database_server - type: server + - type: server hostname: database_server ip_address: 192.168.1.14 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: database_service - type: DatabaseService + - type: DatabaseService - - ref: backup_server - type: server + - type: server hostname: backup_server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: backup_service - type: FTPServer + - type: FTPServer - - ref: security_suite - type: server + - type: server hostname: security_suite ip_address: 192.168.1.110 subnet_mask: 255.255.255.0 @@ -669,38 +656,32 @@ simulation: ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 - - ref: client_1 - type: computer + - type: computer hostname: client_1 ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.1 data_manipulation_p_of_success: 0.1 payload: "DELETE" server_ip: 192.168.1.14 services: - - ref: client_1_dns_client - type: DNSClient + - type: DNSClient - - ref: client_2 - type: computer + - type: computer hostname: client_2 ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: client_2_web_browser - type: WebBrowser + - type: WebBrowser services: - - ref: client_2_dns_client - type: DNSClient + - type: DNSClient links: - endpoint_a_hostname: router_1 diff --git a/tests/assets/configs/firewall_actions_network.yaml b/tests/assets/configs/firewall_actions_network.yaml index 4e134fe6..1f4a45e0 100644 --- a/tests/assets/configs/firewall_actions_network.yaml +++ b/tests/assets/configs/firewall_actions_network.yaml @@ -298,8 +298,7 @@ agents: simulation: network: nodes: - - ref: client_1 - type: computer + - type: computer hostname: client_1 ip_address: 192.168.0.10 subnet_mask: 255.255.255.0 @@ -308,15 +307,13 @@ simulation: start_up_duration: 0 shut_down_duration: 0 - - ref: switch_1 - type: switch + - type: switch hostname: switch_1 num_ports: 8 start_up_duration: 0 shut_down_duration: 0 - - ref: router_1 - type: router + - type: router hostname: router_1 num_ports: 5 start_up_duration: 0 @@ -350,8 +347,7 @@ simulation: next_hop_ip_address: 192.168.1.2 metric: 0 - - ref: dmz_server - type: server + - type: server hostname: dmz_server ip_address: 192.168.10.10 subnet_mask: 255.255.255.0 @@ -360,15 +356,13 @@ simulation: start_up_duration: 0 shut_down_duration: 0 - - ref: switch_2 - type: switch + - type: switch hostname: switch_2 num_ports: 8 start_up_duration: 0 shut_down_duration: 0 - - ref: firewall - type: firewall + - type: firewall hostname: firewall start_up_duration: 0 shut_down_duration: 0 @@ -431,15 +425,13 @@ simulation: next_hop_ip_address: 192.168.1.1 metric: 0 - - ref: switch_3 - type: switch + - type: switch hostname: switch_3 num_ports: 8 start_up_duration: 0 shut_down_duration: 0 - - ref: external_computer - type: computer + - type: computer hostname: external_computer ip_address: 192.168.20.10 subnet_mask: 255.255.255.0 @@ -448,8 +440,7 @@ simulation: start_up_duration: 0 shut_down_duration: 0 - - ref: external_server - type: server + - type: server hostname: external_server ip_address: 192.168.20.11 subnet_mask: 255.255.255.0 @@ -457,46 +448,37 @@ simulation: start_up_duration: 0 shut_down_duration: 0 services: - - ref: domain_controller_dns_server - type: DNSServer + - type: DNSServer links: - - ref: client_1___switch_1 - endpoint_a_hostname: client_1 + - endpoint_a_hostname: client_1 endpoint_a_port: 1 endpoint_b_hostname: switch_1 endpoint_b_port: 1 - - ref: router_1___switch_1 - endpoint_a_hostname: router_1 + - endpoint_a_hostname: router_1 endpoint_a_port: 1 endpoint_b_hostname: switch_1 endpoint_b_port: 8 - - ref: router_1___firewall - endpoint_a_hostname: firewall + - endpoint_a_hostname: firewall endpoint_a_port: 2 # internal firewall port endpoint_b_hostname: router_1 endpoint_b_port: 2 - - ref: firewall___switch_2 - endpoint_a_hostname: firewall + - endpoint_a_hostname: firewall endpoint_a_port: 3 # dmz firewall port endpoint_b_hostname: switch_2 endpoint_b_port: 8 - - ref: dmz_server___switch_2 - endpoint_a_hostname: dmz_server + - endpoint_a_hostname: dmz_server endpoint_a_port: 1 endpoint_b_hostname: switch_2 endpoint_b_port: 1 - - ref: firewall___switch_3 - endpoint_a_hostname: firewall + - endpoint_a_hostname: firewall endpoint_a_port: 1 # external firewall port endpoint_b_hostname: switch_3 endpoint_b_port: 8 - - ref: external_computer___switch_3 - endpoint_a_hostname: external_computer + - endpoint_a_hostname: external_computer endpoint_a_port: 1 endpoint_b_hostname: switch_3 endpoint_b_port: 1 - - ref: external_server___switch_3 - endpoint_a_hostname: external_server + - endpoint_a_hostname: external_server endpoint_a_port: 1 endpoint_b_hostname: switch_3 endpoint_b_port: 2 diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index e4342582..6a37be80 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -1027,8 +1027,7 @@ simulation: network: nodes: - - ref: router_1 - type: router + - type: router hostname: router_1 num_ports: 5 ports: @@ -1055,69 +1054,57 @@ simulation: action: PERMIT protocol: ICMP - - ref: switch_1 - type: switch + - type: switch hostname: switch_1 num_ports: 8 - - ref: switch_2 - type: switch + - type: switch hostname: switch_2 num_ports: 8 - - ref: domain_controller - type: server + - type: server hostname: domain_controller ip_address: 192.168.1.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 services: - - ref: domain_controller_dns_server - type: DNSServer + - type: DNSServer options: domain_mapping: arcd.com: 192.168.1.12 # web server - - ref: web_server - type: server + - type: server hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: web_server_web_service - type: WebServer + - type: WebServer applications: - - ref: web_server_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: database_server - type: server + - type: server hostname: database_server ip_address: 192.168.1.14 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: database_service - type: DatabaseService + - type: DatabaseService - - ref: backup_server - type: server + - type: server hostname: backup_server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: backup_service - type: FTPServer + - type: FTPServer - - ref: security_suite - type: server + - type: server hostname: security_suite ip_address: 192.168.1.110 subnet_mask: 255.255.255.0 @@ -1128,38 +1115,32 @@ simulation: ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 - - ref: client_1 - type: computer + - type: computer hostname: client_1 ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.1 data_manipulation_p_of_success: 0.1 payload: "DELETE" server_ip: 192.168.1.14 services: - - ref: client_1_dns_client - type: DNSClient + - type: DNSClient - - ref: client_2 - type: computer + - type: computer hostname: client_2 ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: client_2_web_browser - type: WebBrowser + - type: WebBrowser services: - - ref: client_2_dns_client - type: DNSClient + - type: DNSClient links: - endpoint_a_hostname: router_1 diff --git a/tests/assets/configs/shared_rewards.yaml b/tests/assets/configs/shared_rewards.yaml index 7df6802c..bfa03ace 100644 --- a/tests/assets/configs/shared_rewards.yaml +++ b/tests/assets/configs/shared_rewards.yaml @@ -750,8 +750,7 @@ simulation: - DELETE nodes: - - ref: router_1 - hostname: router_1 + - hostname: router_1 type: router num_ports: 5 ports: @@ -786,74 +785,61 @@ simulation: action: PERMIT protocol: ICMP - - ref: switch_1 - hostname: switch_1 + - hostname: switch_1 type: switch num_ports: 8 - - ref: switch_2 - hostname: switch_2 + - hostname: switch_2 type: switch num_ports: 8 - - ref: domain_controller - hostname: domain_controller + - hostname: domain_controller type: server ip_address: 192.168.1.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 services: - - ref: domain_controller_dns_server - type: DNSServer + - type: DNSServer options: domain_mapping: arcd.com: 192.168.1.12 # web server - - ref: web_server - hostname: web_server + - hostname: web_server type: server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: web_server_web_service - type: WebServer + - type: WebServer applications: - - ref: web_server_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: database_server - hostname: database_server + - hostname: database_server type: server ip_address: 192.168.1.14 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: database_service - type: DatabaseService + - type: DatabaseService options: backup_server_ip: 192.168.1.16 - - ref: database_ftp_client - type: FTPClient + - type: FTPClient - - ref: backup_server - hostname: backup_server + - hostname: backup_server type: server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: backup_service - type: FTPServer + - type: FTPServer - - ref: security_suite - hostname: security_suite + - hostname: security_suite type: server ip_address: 192.168.1.110 subnet_mask: 255.255.255.0 @@ -864,59 +850,49 @@ simulation: ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 - - ref: client_1 - hostname: client_1 + - hostname: client_1 type: computer ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.8 data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 - - ref: client_1_web_browser - type: WebBrowser + - type: WebBrowser options: target_url: http://arcd.com/users/ - - ref: client_1_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 services: - - ref: client_1_dns_client - type: DNSClient + - type: DNSClient - - ref: client_2 - hostname: client_2 + - hostname: client_2 type: computer ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: client_2_web_browser - type: WebBrowser + - type: WebBrowser options: target_url: http://arcd.com/users/ - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.8 data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 - - ref: client_2_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 services: - - ref: client_2_dns_client - type: DNSClient + - type: DNSClient diff --git a/tests/assets/configs/test_application_install.yaml b/tests/assets/configs/test_application_install.yaml index a2059913..3323937e 100644 --- a/tests/assets/configs/test_application_install.yaml +++ b/tests/assets/configs/test_application_install.yaml @@ -782,8 +782,7 @@ simulation: - DELETE nodes: - - ref: router_1 - hostname: router_1 + - hostname: router_1 type: router num_ports: 5 ports: @@ -818,74 +817,61 @@ simulation: action: PERMIT protocol: ICMP - - ref: switch_1 - hostname: switch_1 + - hostname: switch_1 type: switch num_ports: 8 - - ref: switch_2 - hostname: switch_2 + - hostname: switch_2 type: switch num_ports: 8 - - ref: domain_controller - hostname: domain_controller + - hostname: domain_controller type: server ip_address: 192.168.1.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 services: - - ref: domain_controller_dns_server - type: DNSServer + - type: DNSServer options: domain_mapping: arcd.com: 192.168.1.12 # web server - - ref: web_server - hostname: web_server + - hostname: web_server type: server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: web_server_web_service - type: WebServer + - type: WebServer applications: - - ref: web_server_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: database_server - hostname: database_server + - hostname: database_server type: server ip_address: 192.168.1.14 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: database_service - type: DatabaseService + - type: DatabaseService options: backup_server_ip: 192.168.1.16 - - ref: database_ftp_client - type: FTPClient + - type: FTPClient - - ref: backup_server - hostname: backup_server + - hostname: backup_server type: server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: backup_service - type: FTPServer + - type: FTPServer - - ref: security_suite - hostname: security_suite + - hostname: security_suite type: server ip_address: 192.168.1.110 subnet_mask: 255.255.255.0 @@ -896,59 +882,49 @@ simulation: ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 - - ref: client_1 - hostname: client_1 + - hostname: client_1 type: computer ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.8 data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 - - ref: client_1_web_browser - type: WebBrowser + - type: WebBrowser options: target_url: http://arcd.com/users/ - - ref: client_1_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 services: - - ref: client_1_dns_client - type: DNSClient + - type: DNSClient - - ref: client_2 - hostname: client_2 + - hostname: client_2 type: computer ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: client_2_web_browser - type: WebBrowser + - type: WebBrowser options: target_url: http://arcd.com/users/ - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.8 data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.14 - - ref: client_2_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 services: - - ref: client_2_dns_client - type: DNSClient + - type: DNSClient diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index fc72cfd7..9284f1d1 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -574,8 +574,7 @@ simulation: network: nodes: - - ref: router_1 - type: router + - type: router hostname: router_1 num_ports: 5 ports: @@ -602,70 +601,58 @@ simulation: action: PERMIT protocol: ICMP - - ref: switch_1 - type: switch + - type: switch hostname: switch_1 num_ports: 8 - - ref: switch_2 - type: switch + - type: switch hostname: switch_2 num_ports: 8 - - ref: domain_controller - type: server + - type: server hostname: domain_controller ip_address: 192.168.1.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 services: - - ref: domain_controller_dns_server - type: DNSServer + - type: DNSServer options: domain_mapping: arcd.com: 192.168.1.12 # web server - - ref: web_server - type: server + - type: server hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: web_server_web_service - type: WebServer + - type: WebServer applications: - - ref: web_server_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: database_server - type: server + - type: server hostname: database_server ip_address: 192.168.1.14 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: database_service - type: DatabaseService + - type: DatabaseService - - ref: backup_server - type: server + - type: server hostname: backup_server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: backup_service - type: FTPServer + - type: FTPServer - - ref: security_suite - type: server + - type: server hostname: security_suite ip_address: 192.168.1.110 subnet_mask: 255.255.255.0 @@ -676,47 +663,39 @@ simulation: ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 - - ref: client_1 - type: computer + - type: computer hostname: client_1 ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.1 data_manipulation_p_of_success: 0.1 payload: "DELETE" server_ip: 192.168.1.14 services: - - ref: client_1_dns_client - type: DNSClient + - type: DNSClient - - ref: client_2 - type: computer + - type: computer hostname: client_2 ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: client_2_web_browser - type: WebBrowser + - type: WebBrowser services: - - ref: client_2_dns_client - type: DNSClient + - type: DNSClient - - ref: HP_LaserJet_Pro_4102fdn_printer - type: printer + - type: printer hostname: HP_LaserJet_Pro_4102fdn_printer ip_address: 192.168.10.99 subnet_mask: 255.255.255.0 - - ref: router_2 - type: wireless_router + - type: wireless_router hostname: router_2 router_interface: ip_address: 192.169.1.1 diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index b083505e..7d1ac09f 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -574,8 +574,7 @@ simulation: network: nodes: - - ref: router_1 - type: router + - type: router hostname: router_1 num_ports: 5 ports: @@ -602,70 +601,58 @@ simulation: action: PERMIT protocol: ICMP - - ref: switch_1 - type: switch + - type: switch hostname: switch_1 num_ports: 8 - - ref: switch_2 - type: switch + - type: switch hostname: switch_2 num_ports: 8 - - ref: domain_controller - type: server + - type: server hostname: domain_controller ip_address: 192.168.1.10 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 services: - - ref: domain_controller_dns_server - type: DNSServer + - type: DNSServer options: domain_mapping: arcd.com: 192.168.1.12 # web server - - ref: web_server - type: server + - type: server hostname: web_server ip_address: 192.168.1.12 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: web_server_web_service - type: WebServer + - type: WebServer applications: - - ref: web_server_database_client - type: DatabaseClient + - type: DatabaseClient options: db_server_ip: 192.168.1.14 - - ref: database_server - type: server + - type: server hostname: database_server ip_address: 192.168.1.14 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: database_service - type: DatabaseService + - type: DatabaseService - - ref: backup_server - type: server + - type: server hostname: backup_server ip_address: 192.168.1.16 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 dns_server: 192.168.1.10 services: - - ref: backup_service - type: FTPServer + - type: FTPServer - - ref: security_suite - type: server + - type: server hostname: security_suite ip_address: 192.168.1.110 subnet_mask: 255.255.255.0 @@ -676,38 +663,32 @@ simulation: ip_address: 192.168.10.110 subnet_mask: 255.255.255.0 - - ref: client_1 - type: computer + - type: computer hostname: client_1 ip_address: 192.168.10.21 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: data_manipulation_bot - type: DataManipulationBot + - type: DataManipulationBot options: port_scan_p_of_success: 0.1 data_manipulation_p_of_success: 0.1 payload: "DELETE" server_ip: 192.168.1.14 services: - - ref: client_1_dns_client - type: DNSClient + - type: DNSClient - - ref: client_2 - type: computer + - type: computer hostname: client_2 ip_address: 192.168.10.22 subnet_mask: 255.255.255.0 default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: - - ref: client_2_web_browser - type: WebBrowser + - type: WebBrowser services: - - ref: client_2_dns_client - type: DNSClient + - type: DNSClient links: - endpoint_a_hostname: router_1 From 383cf051df249b7fd3fcfece4ca38e0784ef7e72 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 4 Apr 2024 14:17:34 +0100 Subject: [PATCH 797/980] #2448: store last query response for db client --- .../system/applications/database_client.py | 6 + .../services/database/database_service.py | 6 +- .../test_data_manipulation_bot_and_server.py | 155 ++++++++++++++++++ 3 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 tests/integration_tests/system/red_applications/test_data_manipulation_bot_and_server.py diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index d3afef59..1de75dc5 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -29,6 +29,8 @@ class DatabaseClient(Application): _query_success_tracker: Dict[str, bool] = {} _last_connection_successful: Optional[bool] = None """Keep track of connections that were established or verified during this step. Used for rewards.""" + last_query_response: Optional[Dict] = None + """Keep track of the latest query response. Used to determine rewards.""" def __init__(self, **kwargs): kwargs["name"] = "DatabaseClient" @@ -219,6 +221,9 @@ class DatabaseClient(Application): if not self._can_perform_action(): return False + # reset last query response + self.last_query_response = None + if connection_id is None: if self.connections: connection_id = list(self.connections.keys())[-1] @@ -252,6 +257,7 @@ class DatabaseClient(Application): # add connection self.add_connection(connection_id=payload.get("connection_id"), session_id=session_id) elif payload["type"] == "sql": + self.last_query_response = payload query_id = payload.get("uuid") status_code = payload.get("status_code") self._query_success_tracker[query_id] = status_code == 200 diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index ede2a54f..321d9088 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -204,7 +204,7 @@ class DatabaseService(Service): if not self.db_file: self.sys_log.info(f"{self.name}: Failed to run {query} because the database file is missing.") - return {"status_code": 404, "data": False} + return {"status_code": 404, "type": "sql", "data": False} if query == "SELECT": if self.db_file.health_status == FileSystemItemHealthStatus.GOOD: @@ -216,7 +216,7 @@ class DatabaseService(Service): "connection_id": connection_id, } else: - return {"status_code": 404, "data": False} + return {"status_code": 404, "type": "sql", "data": False} elif query == "DELETE": self.db_file.health_status = FileSystemItemHealthStatus.COMPROMISED return { @@ -236,7 +236,7 @@ class DatabaseService(Service): "connection_id": connection_id, } else: - return {"status_code": 404, "data": False} + return {"status_code": 404, "type": "sql", "data": False} elif query == "SELECT * FROM pg_stat_activity": # Check if the connection is active. if self.health_state_actual == SoftwareHealthState.GOOD: diff --git a/tests/integration_tests/system/red_applications/test_data_manipulation_bot_and_server.py b/tests/integration_tests/system/red_applications/test_data_manipulation_bot_and_server.py new file mode 100644 index 00000000..1106d6ca --- /dev/null +++ b/tests/integration_tests/system/red_applications/test_data_manipulation_bot_and_server.py @@ -0,0 +1,155 @@ +from ipaddress import IPv4Address +from typing import Tuple + +import pytest + +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import ApplicationOperatingState +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.applications.red_applications.data_manipulation_bot import ( + DataManipulationAttackStage, + DataManipulationBot, +) +from primaite.simulator.system.applications.red_applications.dos_bot import DoSAttackStage, DoSBot +from primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.system.software import SoftwareHealthState + + +@pytest.fixture(scope="function") +def data_manipulation_bot_and_db_server(client_server) -> Tuple[DataManipulationBot, Computer, DatabaseService, Server]: + computer, server = client_server + + # install db client on computer + computer.software_manager.install(DatabaseClient) + db_client: DatabaseClient = computer.software_manager.software.get("DatabaseClient") + db_client.run() + + # Install DoSBot on computer + computer.software_manager.install(DataManipulationBot) + + data_manipulation_bot: DataManipulationBot = computer.software_manager.software.get("DataManipulationBot") + data_manipulation_bot.configure( + server_ip_address=IPv4Address(server.network_interface[1].ip_address), payload="DELETE" + ) + + # Install DB Server service on server + server.software_manager.install(DatabaseService) + db_server_service: DatabaseService = server.software_manager.software.get("DatabaseService") + db_server_service.start() + + return data_manipulation_bot, computer, db_server_service, server + + +@pytest.fixture(scope="function") +def data_manipulation_db_server_green_client(example_network) -> Network: + network: Network = example_network + + router_1: Router = example_network.get_node_by_hostname("router_1") + router_1.acl.add_rule( + action=ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER, position=0 + ) + + client_1: Computer = network.get_node_by_hostname("client_1") + client_2: Computer = network.get_node_by_hostname("client_2") + server: Server = network.get_node_by_hostname("server_1") + + # install db client on client 1 + client_1.software_manager.install(DatabaseClient) + db_client: DatabaseClient = client_1.software_manager.software.get("DatabaseClient") + db_client.run() + + # install Data Manipulation bot on client 1 + client_1.software_manager.install(DataManipulationBot) + + data_manipulation_bot: DataManipulationBot = client_1.software_manager.software.get("DataManipulationBot") + data_manipulation_bot.configure( + server_ip_address=IPv4Address(server.network_interface[1].ip_address), payload="DELETE" + ) + + # install db server service on server + server.software_manager.install(DatabaseService) + db_server_service: DatabaseService = server.software_manager.software.get("DatabaseService") + db_server_service.start() + + # Install DB client (green) on client 2 + client_2.software_manager.install(DatabaseClient) + + database_client: DatabaseClient = client_2.software_manager.software.get("DatabaseClient") + database_client.configure(server_ip_address=IPv4Address(server.network_interface[1].ip_address)) + database_client.run() + + return network + + +def test_repeating_data_manipulation_attack(data_manipulation_bot_and_db_server): + """Test a repeating data manipulation attack.""" + data_manipulation_bot, computer, db_server_service, server = data_manipulation_bot_and_db_server + + assert db_server_service.health_state_actual is SoftwareHealthState.GOOD + + data_manipulation_bot.port_scan_p_of_success = 1 + data_manipulation_bot.data_manipulation_p_of_success = 1 + data_manipulation_bot.repeat = True + data_manipulation_bot.attack() + + assert data_manipulation_bot.attack_stage == DataManipulationAttackStage.NOT_STARTED + assert db_server_service.db_file.health_status is FileSystemItemHealthStatus.COMPROMISED + + computer.apply_timestep(timestep=1) + server.apply_timestep(timestep=1) + + assert data_manipulation_bot.attack_stage == DataManipulationAttackStage.NOT_STARTED + assert db_server_service.db_file.health_status is FileSystemItemHealthStatus.COMPROMISED + + +def test_non_repeating_data_manipulation_attack(data_manipulation_bot_and_db_server): + """Test a non repeating data manipulation attack.""" + data_manipulation_bot, computer, db_server_service, server = data_manipulation_bot_and_db_server + + assert db_server_service.health_state_actual is SoftwareHealthState.GOOD + + data_manipulation_bot.port_scan_p_of_success = 1 + data_manipulation_bot.data_manipulation_p_of_success = 1 + data_manipulation_bot.repeat = False + data_manipulation_bot.attack() + + assert data_manipulation_bot.attack_stage == DataManipulationAttackStage.SUCCEEDED + assert db_server_service.db_file.health_status is FileSystemItemHealthStatus.COMPROMISED + + computer.apply_timestep(timestep=1) + server.apply_timestep(timestep=1) + + assert data_manipulation_bot.attack_stage == DataManipulationAttackStage.SUCCEEDED + assert db_server_service.db_file.health_status is FileSystemItemHealthStatus.COMPROMISED + + +def test_data_manipulation_disrupts_green_agent_connection(data_manipulation_db_server_green_client): + """Test to see that the data manipulation bot affects a green agent query.""" + network: Network = data_manipulation_db_server_green_client + + client_1: Computer = network.get_node_by_hostname("client_1") + data_manipulation_bot: DataManipulationBot = client_1.software_manager.software.get("DataManipulationBot") + + client_2: Computer = network.get_node_by_hostname("client_2") + green_db_client: DatabaseClient = client_2.software_manager.software.get("DatabaseClient") + + server: Server = network.get_node_by_hostname("server_1") + db_server_service: DatabaseService = server.software_manager.software.get("DatabaseService") + + assert db_server_service.db_file.health_status is FileSystemItemHealthStatus.GOOD + assert green_db_client.query("SELECT") + assert green_db_client.last_query_response.get("status_code") == 200 + + data_manipulation_bot.port_scan_p_of_success = 1 + data_manipulation_bot.data_manipulation_p_of_success = 1 + data_manipulation_bot.repeat = False + data_manipulation_bot.attack() + + assert db_server_service.db_file.health_status is FileSystemItemHealthStatus.COMPROMISED + assert green_db_client.query("SELECT") is False + assert green_db_client.last_query_response.get("status_code") != 200 From f8432bf53b0226132fd9deb9472bf064d0fc8542 Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Tue, 9 Apr 2024 13:26:35 +0100 Subject: [PATCH 798/980] #2453 - Example Notebooks Require Refactor - create_simulation_demo and network_simulator_demo notebooks have been updated with correct import paths to reflect refactoring within condebase. - Corrected typo within create-simulation_demo: my_swtich -> my_switch - updates to ARP implementation. This is now a property in HostNode and NetworkNode, meaning router.arp.show() now works in network_simulator_demo notebook as intended. --- .../notebooks/Training-an-SB3-Agent.ipynb | 7339 ++++++++++++++++- .../create-simulation_demo.ipynb | 608 +- .../network_simulator_demo.ipynb | 644 +- .../network/hardware/nodes/host/host_node.py | 4 + .../hardware/nodes/network/network_node.py | 7 +- .../network/hardware/nodes/network/router.py | 3 +- 6 files changed, 8494 insertions(+), 111 deletions(-) diff --git a/src/primaite/notebooks/Training-an-SB3-Agent.ipynb b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb index e6f5aaee..67d9748e 100644 --- a/src/primaite/notebooks/Training-an-SB3-Agent.ipynb +++ b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -32,16 +32,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + } + ], "source": [ "gym = PrimaiteGymEnv(game_config=cfg)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -56,7 +64,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -65,16 +73,7141 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:28,065: Resetting environment, episode 0, avg. reward: 0.0\n", + "2024-04-08 14:49:28,068: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_0.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:29,639: Resetting environment, episode 1, avg. reward: -17.149999999999974\n", + "2024-04-08 14:49:29,643: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_1.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:31,337: Resetting environment, episode 2, avg. reward: -12.099999999999989\n", + "2024-04-08 14:49:31,339: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_2.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:32,540: Resetting environment, episode 3, avg. reward: -44.500000000000064\n", + "2024-04-08 14:49:32,543: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_3.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:33,721: Resetting environment, episode 4, avg. reward: -22.949999999999953\n", + "2024-04-08 14:49:33,724: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_4.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:35,248: Resetting environment, episode 5, avg. reward: -17.64999999999998\n", + "2024-04-08 14:49:35,253: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_5.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:36,676: Resetting environment, episode 6, avg. reward: -21.949999999999953\n", + "2024-04-08 14:49:36,679: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_6.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:38,158: Resetting environment, episode 7, avg. reward: -88.5999999999998\n", + "2024-04-08 14:49:38,161: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_7.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:39,570: Resetting environment, episode 8, avg. reward: -42.750000000000156\n", + "2024-04-08 14:49:39,572: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_8.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:40,917: Resetting environment, episode 9, avg. reward: -13.999999999999982\n", + "2024-04-08 14:49:40,920: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_9.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:42,112: Resetting environment, episode 10, avg. reward: -34.55000000000001\n", + "2024-04-08 14:49:42,116: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_10.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:43,768: Resetting environment, episode 11, avg. reward: -19.399999999999963\n", + "2024-04-08 14:49:43,771: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_11.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:45,216: Resetting environment, episode 12, avg. reward: -11.049999999999988\n", + "2024-04-08 14:49:45,219: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_12.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:46,830: Resetting environment, episode 13, avg. reward: -33.1\n", + "2024-04-08 14:49:46,833: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_13.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:48,302: Resetting environment, episode 14, avg. reward: -17.499999999999968\n", + "2024-04-08 14:49:48,306: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_14.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:50,142: Resetting environment, episode 15, avg. reward: -22.299999999999955\n", + "2024-04-08 14:49:50,146: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_15.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:51,603: Resetting environment, episode 16, avg. reward: -64.8500000000001\n", + "2024-04-08 14:49:51,606: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_16.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:53,295: Resetting environment, episode 17, avg. reward: -67.24999999999999\n", + "2024-04-08 14:49:53,298: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_17.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:54,630: Resetting environment, episode 18, avg. reward: -20.799999999999958\n", + "2024-04-08 14:49:54,633: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_18.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:56,091: Resetting environment, episode 19, avg. reward: -62.55000000000001\n", + "2024-04-08 14:49:56,093: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_19.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:57,486: Resetting environment, episode 20, avg. reward: -24.649999999999984\n", + "2024-04-08 14:49:57,489: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_20.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:49:59,243: Resetting environment, episode 21, avg. reward: -9.649999999999997\n", + "2024-04-08 14:49:59,246: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_21.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:00,812: Resetting environment, episode 22, avg. reward: -21.749999999999957\n", + "2024-04-08 14:50:00,815: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_22.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:02,403: Resetting environment, episode 23, avg. reward: -15.949999999999978\n", + "2024-04-08 14:50:02,405: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_23.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:04,363: Resetting environment, episode 24, avg. reward: -83.15000000000002\n", + "2024-04-08 14:50:04,366: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_24.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:06,083: Resetting environment, episode 25, avg. reward: -36.15000000000003\n", + "2024-04-08 14:50:06,085: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_25.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:07,813: Resetting environment, episode 26, avg. reward: -67.25000000000007\n", + "2024-04-08 14:50:07,816: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_26.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:09,419: Resetting environment, episode 27, avg. reward: -44.200000000000074\n", + "2024-04-08 14:50:09,422: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_27.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:10,969: Resetting environment, episode 28, avg. reward: -64.1500000000001\n", + "2024-04-08 14:50:10,973: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_28.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:12,518: Resetting environment, episode 29, avg. reward: -18.34999999999997\n", + "2024-04-08 14:50:12,519: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_29.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:14,004: Resetting environment, episode 30, avg. reward: -17.69999999999997\n", + "2024-04-08 14:50:14,007: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_30.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:16,007: Resetting environment, episode 31, avg. reward: -28.700000000000017\n", + "2024-04-08 14:50:16,010: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_31.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:17,755: Resetting environment, episode 32, avg. reward: -53.65000000000015\n", + "2024-04-08 14:50:17,758: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_32.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:19,232: Resetting environment, episode 33, avg. reward: -43.65000000000005\n", + "2024-04-08 14:50:19,235: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_33.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:20,708: Resetting environment, episode 34, avg. reward: -2.499999999999969\n", + "2024-04-08 14:50:20,711: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_34.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:22,081: Resetting environment, episode 35, avg. reward: -51.45000000000008\n", + "2024-04-08 14:50:22,084: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_35.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:23,461: Resetting environment, episode 36, avg. reward: -24.749999999999986\n", + "2024-04-08 14:50:23,465: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_36.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:24,909: Resetting environment, episode 37, avg. reward: -72.70000000000002\n", + "2024-04-08 14:50:24,912: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_37.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:27,049: Resetting environment, episode 38, avg. reward: -16.049999999999976\n", + "2024-04-08 14:50:27,052: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_38.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:28,362: Resetting environment, episode 39, avg. reward: -27.79999999999996\n", + "2024-04-08 14:50:28,364: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_39.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:29,821: Resetting environment, episode 40, avg. reward: -61.9500000000001\n", + "2024-04-08 14:50:29,824: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_40.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:31,787: Resetting environment, episode 41, avg. reward: -36.00000000000004\n", + "2024-04-08 14:50:31,790: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_41.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:33,074: Resetting environment, episode 42, avg. reward: -44.35000000000007\n", + "2024-04-08 14:50:33,077: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_42.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:34,739: Resetting environment, episode 43, avg. reward: -51.100000000000065\n", + "2024-04-08 14:50:34,742: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_43.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:36,357: Resetting environment, episode 44, avg. reward: -65.95000000000002\n", + "2024-04-08 14:50:36,359: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_44.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:37,834: Resetting environment, episode 45, avg. reward: -45.750000000000064\n", + "2024-04-08 14:50:37,838: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_45.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:39,768: Resetting environment, episode 46, avg. reward: -22.39999999999994\n", + "2024-04-08 14:50:39,774: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_46.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:41,672: Resetting environment, episode 47, avg. reward: -18.749999999999993\n", + "2024-04-08 14:50:41,677: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_47.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:43,816: Resetting environment, episode 48, avg. reward: -65.4\n", + "2024-04-08 14:50:43,818: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_48.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:45,262: Resetting environment, episode 49, avg. reward: -20.09999999999996\n", + "2024-04-08 14:50:45,266: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_49.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:46,955: Resetting environment, episode 50, avg. reward: -21.899999999999967\n", + "2024-04-08 14:50:46,958: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_50.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:49,698: Resetting environment, episode 51, avg. reward: -20.399999999999963\n", + "2024-04-08 14:50:49,701: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_51.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:51,463: Resetting environment, episode 52, avg. reward: -21.399999999999956\n", + "2024-04-08 14:50:51,467: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_52.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:53,214: Resetting environment, episode 53, avg. reward: -19.249999999999982\n", + "2024-04-08 14:50:53,218: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_53.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:55,080: Resetting environment, episode 54, avg. reward: -57.90000000000009\n", + "2024-04-08 14:50:55,084: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_54.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:56,690: Resetting environment, episode 55, avg. reward: -14.099999999999982\n", + "2024-04-08 14:50:56,694: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_55.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:58,423: Resetting environment, episode 56, avg. reward: -22.79999999999995\n", + "2024-04-08 14:50:58,427: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_56.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:50:59,941: Resetting environment, episode 57, avg. reward: -18.39999999999997\n", + "2024-04-08 14:50:59,944: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_57.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:01,528: Resetting environment, episode 58, avg. reward: -49.25000000000011\n", + "2024-04-08 14:51:01,532: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_58.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:03,202: Resetting environment, episode 59, avg. reward: -14.449999999999964\n", + "2024-04-08 14:51:03,204: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_59.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:04,611: Resetting environment, episode 60, avg. reward: -11.649999999999991\n", + "2024-04-08 14:51:04,614: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_60.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:06,388: Resetting environment, episode 61, avg. reward: -17.59999999999997\n", + "2024-04-08 14:51:06,391: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_61.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:07,952: Resetting environment, episode 62, avg. reward: -68.39999999999998\n", + "2024-04-08 14:51:07,956: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_62.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:09,416: Resetting environment, episode 63, avg. reward: -19.999999999999957\n", + "2024-04-08 14:51:09,420: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_63.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:10,728: Resetting environment, episode 64, avg. reward: -49.25000000000008\n", + "2024-04-08 14:51:10,731: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_64.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:12,298: Resetting environment, episode 65, avg. reward: -21.29999999999999\n", + "2024-04-08 14:51:12,302: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_65.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:14,232: Resetting environment, episode 66, avg. reward: -46.55000000000018\n", + "2024-04-08 14:51:14,235: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_66.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:15,645: Resetting environment, episode 67, avg. reward: -30.050000000000008\n", + "2024-04-08 14:51:15,648: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_67.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:17,264: Resetting environment, episode 68, avg. reward: -72.80000000000003\n", + "2024-04-08 14:51:17,268: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_68.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:18,742: Resetting environment, episode 69, avg. reward: -100.84999999999998\n", + "2024-04-08 14:51:18,745: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_69.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:20,149: Resetting environment, episode 70, avg. reward: -33.85000000000002\n", + "2024-04-08 14:51:20,153: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_70.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:21,992: Resetting environment, episode 71, avg. reward: -93.30000000000003\n", + "2024-04-08 14:51:21,995: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_71.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:23,375: Resetting environment, episode 72, avg. reward: -18.049999999999965\n", + "2024-04-08 14:51:23,378: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_72.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:24,808: Resetting environment, episode 73, avg. reward: -52.80000000000021\n", + "2024-04-08 14:51:24,811: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_73.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:26,230: Resetting environment, episode 74, avg. reward: -16.449999999999974\n", + "2024-04-08 14:51:26,234: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_74.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:27,721: Resetting environment, episode 75, avg. reward: -56.400000000000006\n", + "2024-04-08 14:51:27,724: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_75.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:29,150: Resetting environment, episode 76, avg. reward: -13.799999999999976\n", + "2024-04-08 14:51:29,152: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_76.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:30,654: Resetting environment, episode 77, avg. reward: -22.749999999999996\n", + "2024-04-08 14:51:30,658: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_77.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:32,221: Resetting environment, episode 78, avg. reward: -8.949999999999998\n", + "2024-04-08 14:51:32,224: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_78.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:33,561: Resetting environment, episode 79, avg. reward: -35.84999999999997\n", + "2024-04-08 14:51:33,565: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_79.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:35,158: Resetting environment, episode 80, avg. reward: -7.049999999999989\n", + "2024-04-08 14:51:35,160: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_80.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:37,129: Resetting environment, episode 81, avg. reward: -27.349999999999984\n", + "2024-04-08 14:51:37,131: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_81.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:38,672: Resetting environment, episode 82, avg. reward: -40.65000000000012\n", + "2024-04-08 14:51:38,675: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_82.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:41,263: Resetting environment, episode 83, avg. reward: -52.10000000000015\n", + "2024-04-08 14:51:41,267: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_83.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:42,701: Resetting environment, episode 84, avg. reward: -21.649999999999956\n", + "2024-04-08 14:51:42,705: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_84.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:44,319: Resetting environment, episode 85, avg. reward: -31.600000000000016\n", + "2024-04-08 14:51:44,322: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_85.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:45,992: Resetting environment, episode 86, avg. reward: -24.300000000000004\n", + "2024-04-08 14:51:45,992: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_86.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:47,709: Resetting environment, episode 87, avg. reward: -11.849999999999982\n", + "2024-04-08 14:51:47,711: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_87.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:49,249: Resetting environment, episode 88, avg. reward: -11.799999999999992\n", + "2024-04-08 14:51:49,252: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_88.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:50,852: Resetting environment, episode 89, avg. reward: -10.099999999999964\n", + "2024-04-08 14:51:50,854: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_89.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:52,578: Resetting environment, episode 90, avg. reward: -27.799999999999972\n", + "2024-04-08 14:51:52,581: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_90.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:54,406: Resetting environment, episode 91, avg. reward: -23.04999999999995\n", + "2024-04-08 14:51:54,410: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_91.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:56,371: Resetting environment, episode 92, avg. reward: -18.449999999999967\n", + "2024-04-08 14:51:56,375: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_92.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:58,036: Resetting environment, episode 93, avg. reward: -12.04999999999997\n", + "2024-04-08 14:51:58,040: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_93.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:51:59,859: Resetting environment, episode 94, avg. reward: -10.749999999999984\n", + "2024-04-08 14:51:59,862: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_94.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:01,324: Resetting environment, episode 95, avg. reward: -16.999999999999975\n", + "2024-04-08 14:52:01,327: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_95.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:03,061: Resetting environment, episode 96, avg. reward: -64.80000000000003\n", + "2024-04-08 14:52:03,064: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_96.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:04,843: Resetting environment, episode 97, avg. reward: -93.19999999999995\n", + "2024-04-08 14:52:04,846: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_97.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:06,197: Resetting environment, episode 98, avg. reward: -23.44999999999995\n", + "2024-04-08 14:52:06,200: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_98.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:07,802: Resetting environment, episode 99, avg. reward: 1.7500000000000147\n", + "2024-04-08 14:52:07,810: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_99.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:09,595: Resetting environment, episode 100, avg. reward: -31.450000000000003\n", + "2024-04-08 14:52:09,598: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_100.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:11,206: Resetting environment, episode 101, avg. reward: -9.499999999999988\n", + "2024-04-08 14:52:11,209: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_101.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:13,334: Resetting environment, episode 102, avg. reward: -15.149999999999983\n", + "2024-04-08 14:52:13,337: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_102.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:15,208: Resetting environment, episode 103, avg. reward: 0.2500000000000171\n", + "2024-04-08 14:52:15,212: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_103.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:17,126: Resetting environment, episode 104, avg. reward: 14.55\n", + "2024-04-08 14:52:17,130: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_104.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:18,662: Resetting environment, episode 105, avg. reward: -16.04999999999997\n", + "2024-04-08 14:52:18,666: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_105.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:20,144: Resetting environment, episode 106, avg. reward: -80.69999999999997\n", + "2024-04-08 14:52:20,147: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_106.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:21,595: Resetting environment, episode 107, avg. reward: -16.099999999999977\n", + "2024-04-08 14:52:21,599: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_107.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:23,331: Resetting environment, episode 108, avg. reward: -46.80000000000007\n", + "2024-04-08 14:52:23,335: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_108.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:25,083: Resetting environment, episode 109, avg. reward: -22.84999999999995\n", + "2024-04-08 14:52:25,086: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_109.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:26,589: Resetting environment, episode 110, avg. reward: -10.199999999999996\n", + "2024-04-08 14:52:26,592: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_110.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:28,410: Resetting environment, episode 111, avg. reward: -95.99999999999997\n", + "2024-04-08 14:52:28,413: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_111.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:29,966: Resetting environment, episode 112, avg. reward: -17.59999999999997\n", + "2024-04-08 14:52:29,969: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_112.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:31,317: Resetting environment, episode 113, avg. reward: -20.099999999999962\n", + "2024-04-08 14:52:31,321: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_113.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:32,840: Resetting environment, episode 114, avg. reward: -42.850000000000165\n", + "2024-04-08 14:52:32,843: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_114.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:34,336: Resetting environment, episode 115, avg. reward: -22.249999999999954\n", + "2024-04-08 14:52:34,339: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_115.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:35,794: Resetting environment, episode 116, avg. reward: -90.9\n", + "2024-04-08 14:52:35,797: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_116.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:37,489: Resetting environment, episode 117, avg. reward: 5.90000000000003\n", + "2024-04-08 14:52:37,492: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_117.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:39,009: Resetting environment, episode 118, avg. reward: -66.1\n", + "2024-04-08 14:52:39,012: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_118.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:40,602: Resetting environment, episode 119, avg. reward: -36.749999999999964\n", + "2024-04-08 14:52:40,605: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_119.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:42,128: Resetting environment, episode 120, avg. reward: -13.79999999999999\n", + "2024-04-08 14:52:42,131: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_120.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:43,990: Resetting environment, episode 121, avg. reward: -30.750000000000007\n", + "2024-04-08 14:52:43,993: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_121.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:45,565: Resetting environment, episode 122, avg. reward: -99.95\n", + "2024-04-08 14:52:45,568: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_122.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:48,013: Resetting environment, episode 123, avg. reward: 0.3500000000000256\n", + "2024-04-08 14:52:48,016: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_123.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:50,029: Resetting environment, episode 124, avg. reward: -15.299999999999981\n", + "2024-04-08 14:52:50,032: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_124.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:51,501: Resetting environment, episode 125, avg. reward: -15.149999999999975\n", + "2024-04-08 14:52:51,502: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_125.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:53,184: Resetting environment, episode 126, avg. reward: -90.35\n", + "2024-04-08 14:52:53,186: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_126.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:54,836: Resetting environment, episode 127, avg. reward: -19.9\n", + "2024-04-08 14:52:54,839: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_127.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:56,110: Resetting environment, episode 128, avg. reward: -17.299999999999976\n", + "2024-04-08 14:52:56,113: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_128.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:57,610: Resetting environment, episode 129, avg. reward: -12.499999999999996\n", + "2024-04-08 14:52:57,613: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_129.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:52:59,237: Resetting environment, episode 130, avg. reward: -17.24999999999996\n", + "2024-04-08 14:52:59,240: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_130.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:00,835: Resetting environment, episode 131, avg. reward: -11.64999999999998\n", + "2024-04-08 14:53:00,838: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_131.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:02,203: Resetting environment, episode 132, avg. reward: -27.799999999999986\n", + "2024-04-08 14:53:02,206: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_132.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:03,544: Resetting environment, episode 133, avg. reward: -10.399999999999997\n", + "2024-04-08 14:53:03,547: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_133.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:04,974: Resetting environment, episode 134, avg. reward: -18.0\n", + "2024-04-08 14:53:04,977: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_134.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:06,363: Resetting environment, episode 135, avg. reward: -84.0\n", + "2024-04-08 14:53:06,367: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_135.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:07,884: Resetting environment, episode 136, avg. reward: -20.949999999999964\n", + "2024-04-08 14:53:07,886: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_136.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:09,146: Resetting environment, episode 137, avg. reward: -13.749999999999984\n", + "2024-04-08 14:53:09,149: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_137.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:10,482: Resetting environment, episode 138, avg. reward: -15.299999999999976\n", + "2024-04-08 14:53:10,484: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_138.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:11,761: Resetting environment, episode 139, avg. reward: -87.34999999999994\n", + "2024-04-08 14:53:11,764: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_139.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:13,069: Resetting environment, episode 140, avg. reward: -13.249999999999986\n", + "2024-04-08 14:53:13,072: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_140.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:14,623: Resetting environment, episode 141, avg. reward: -22.499999999999968\n", + "2024-04-08 14:53:14,626: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_141.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:16,023: Resetting environment, episode 142, avg. reward: -42.25\n", + "2024-04-08 14:53:16,026: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_142.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:17,572: Resetting environment, episode 143, avg. reward: -16.35000000000001\n", + "2024-04-08 14:53:17,575: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_143.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:18,887: Resetting environment, episode 144, avg. reward: -80.9\n", + "2024-04-08 14:53:18,891: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_144.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:20,236: Resetting environment, episode 145, avg. reward: -15.299999999999974\n", + "2024-04-08 14:53:20,239: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_145.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:21,625: Resetting environment, episode 146, avg. reward: -21.799999999999955\n", + "2024-04-08 14:53:21,628: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_146.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:23,799: Resetting environment, episode 147, avg. reward: -13.599999999999998\n", + "2024-04-08 14:53:23,802: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_147.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:25,308: Resetting environment, episode 148, avg. reward: -99.1\n", + "2024-04-08 14:53:25,310: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_148.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:27,254: Resetting environment, episode 149, avg. reward: -16.74999999999997\n", + "2024-04-08 14:53:27,259: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_149.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:29,053: Resetting environment, episode 150, avg. reward: -10.749999999999979\n", + "2024-04-08 14:53:29,057: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_150.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:30,939: Resetting environment, episode 151, avg. reward: -74.05\n", + "2024-04-08 14:53:30,942: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_151.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:32,476: Resetting environment, episode 152, avg. reward: -71.6\n", + "2024-04-08 14:53:32,476: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_152.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:34,490: Resetting environment, episode 153, avg. reward: -11.749999999999961\n", + "2024-04-08 14:53:34,493: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_153.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:36,594: Resetting environment, episode 154, avg. reward: -8.700000000000005\n", + "2024-04-08 14:53:36,598: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_154.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:38,245: Resetting environment, episode 155, avg. reward: -21.649999999999956\n", + "2024-04-08 14:53:38,249: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_155.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:39,875: Resetting environment, episode 156, avg. reward: -7.649999999999994\n", + "2024-04-08 14:53:39,879: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_156.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:41,685: Resetting environment, episode 157, avg. reward: -80.54999999999998\n", + "2024-04-08 14:53:41,690: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_157.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:43,273: Resetting environment, episode 158, avg. reward: -14.799999999999978\n", + "2024-04-08 14:53:43,279: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_158.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:44,718: Resetting environment, episode 159, avg. reward: -8.299999999999976\n", + "2024-04-08 14:53:44,720: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_159.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:46,211: Resetting environment, episode 160, avg. reward: -45.05000000000009\n", + "2024-04-08 14:53:46,215: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_160.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:48,427: Resetting environment, episode 161, avg. reward: -0.29999999999997673\n", + "2024-04-08 14:53:48,431: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_161.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:50,514: Resetting environment, episode 162, avg. reward: -24.199999999999946\n", + "2024-04-08 14:53:50,517: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_162.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:52,023: Resetting environment, episode 163, avg. reward: -22.249999999999954\n", + "2024-04-08 14:53:52,027: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_163.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:53,865: Resetting environment, episode 164, avg. reward: -16.44999999999996\n", + "2024-04-08 14:53:53,868: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_164.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:55,434: Resetting environment, episode 165, avg. reward: -75.8\n", + "2024-04-08 14:53:55,437: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_165.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:57,361: Resetting environment, episode 166, avg. reward: -15.74999999999998\n", + "2024-04-08 14:53:57,364: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_166.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:53:59,167: Resetting environment, episode 167, avg. reward: -97.04999999999997\n", + "2024-04-08 14:53:59,171: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_167.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:00,965: Resetting environment, episode 168, avg. reward: -26.450000000000006\n", + "2024-04-08 14:54:00,970: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_168.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:02,555: Resetting environment, episode 169, avg. reward: -1.7999999999999803\n", + "2024-04-08 14:54:02,556: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_169.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:04,283: Resetting environment, episode 170, avg. reward: -16.499999999999964\n", + "2024-04-08 14:54:04,292: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_170.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:06,710: Resetting environment, episode 171, avg. reward: -56.99999999999997\n", + "2024-04-08 14:54:06,714: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_171.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:08,495: Resetting environment, episode 172, avg. reward: -5.550000000000001\n", + "2024-04-08 14:54:08,502: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_172.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:10,090: Resetting environment, episode 173, avg. reward: -16.249999999999968\n", + "2024-04-08 14:54:10,094: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_173.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:13,065: Resetting environment, episode 174, avg. reward: -6.6499999999999915\n", + "2024-04-08 14:54:13,071: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_174.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:15,757: Resetting environment, episode 175, avg. reward: -3.7499999999999707\n", + "2024-04-08 14:54:15,761: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_175.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:18,490: Resetting environment, episode 176, avg. reward: 34.24999999999989\n", + "2024-04-08 14:54:18,493: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_176.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:20,751: Resetting environment, episode 177, avg. reward: -15.999999999999977\n", + "2024-04-08 14:54:20,755: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_177.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:23,269: Resetting environment, episode 178, avg. reward: -80.50000000000001\n", + "2024-04-08 14:54:23,273: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_178.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:25,507: Resetting environment, episode 179, avg. reward: -12.849999999999989\n", + "2024-04-08 14:54:25,510: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_179.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:27,454: Resetting environment, episode 180, avg. reward: -16.949999999999996\n", + "2024-04-08 14:54:27,458: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_180.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:29,884: Resetting environment, episode 181, avg. reward: 1.9000000000000221\n", + "2024-04-08 14:54:29,887: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_181.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:32,113: Resetting environment, episode 182, avg. reward: 9.500000000000046\n", + "2024-04-08 14:54:32,117: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_182.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:34,283: Resetting environment, episode 183, avg. reward: -91.0500000000001\n", + "2024-04-08 14:54:34,286: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_183.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:36,330: Resetting environment, episode 184, avg. reward: -43.15000000000006\n", + "2024-04-08 14:54:36,332: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_184.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:38,270: Resetting environment, episode 185, avg. reward: -99.0\n", + "2024-04-08 14:54:38,274: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_185.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:40,645: Resetting environment, episode 186, avg. reward: -19.849999999999962\n", + "2024-04-08 14:54:40,648: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_186.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:42,998: Resetting environment, episode 187, avg. reward: -24.299999999999983\n", + "2024-04-08 14:54:43,002: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_187.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:45,260: Resetting environment, episode 188, avg. reward: -15.449999999999973\n", + "2024-04-08 14:54:45,263: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_188.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:47,356: Resetting environment, episode 189, avg. reward: -46.15000000000005\n", + "2024-04-08 14:54:47,362: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_189.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:49,422: Resetting environment, episode 190, avg. reward: -15.849999999999996\n", + "2024-04-08 14:54:49,425: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_190.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:51,753: Resetting environment, episode 191, avg. reward: 2.200000000000034\n", + "2024-04-08 14:54:51,757: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_191.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:54,077: Resetting environment, episode 192, avg. reward: 8.950000000000049\n", + "2024-04-08 14:54:54,081: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_192.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:56,257: Resetting environment, episode 193, avg. reward: -10.949999999999985\n", + "2024-04-08 14:54:56,261: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_193.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:54:59,376: Resetting environment, episode 194, avg. reward: -23.449999999999957\n", + "2024-04-08 14:54:59,379: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_194.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:02,626: Resetting environment, episode 195, avg. reward: -98.24999999999996\n", + "2024-04-08 14:55:02,630: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_195.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:05,232: Resetting environment, episode 196, avg. reward: -20.299999999999976\n", + "2024-04-08 14:55:05,236: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_196.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:08,026: Resetting environment, episode 197, avg. reward: -6.399999999999993\n", + "2024-04-08 14:55:08,029: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_197.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:09,878: Resetting environment, episode 198, avg. reward: -20.099999999999962\n", + "2024-04-08 14:55:09,882: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_198.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:12,337: Resetting environment, episode 199, avg. reward: -20.59999999999996\n", + "2024-04-08 14:55:12,340: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_199.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:14,794: Resetting environment, episode 200, avg. reward: -80.65000000000002\n", + "2024-04-08 14:55:14,798: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_200.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:17,788: Resetting environment, episode 201, avg. reward: 11.249999999999932\n", + "2024-04-08 14:55:17,792: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_201.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:20,227: Resetting environment, episode 202, avg. reward: -85.35\n", + "2024-04-08 14:55:20,230: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_202.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:22,623: Resetting environment, episode 203, avg. reward: -67.9\n", + "2024-04-08 14:55:22,626: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_203.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:27,001: Resetting environment, episode 204, avg. reward: -94.30000000000017\n", + "2024-04-08 14:55:27,004: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_204.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:28,803: Resetting environment, episode 205, avg. reward: -30.39999999999997\n", + "2024-04-08 14:55:28,808: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_205.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:30,621: Resetting environment, episode 206, avg. reward: -25.14999999999995\n", + "2024-04-08 14:55:30,623: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_206.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:32,191: Resetting environment, episode 207, avg. reward: -98.14999999999998\n", + "2024-04-08 14:55:32,194: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_207.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:33,920: Resetting environment, episode 208, avg. reward: -17.64999999999998\n", + "2024-04-08 14:55:33,923: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_208.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:36,333: Resetting environment, episode 209, avg. reward: -88.25\n", + "2024-04-08 14:55:36,336: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_209.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:38,489: Resetting environment, episode 210, avg. reward: -85.35\n", + "2024-04-08 14:55:38,494: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_210.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:40,664: Resetting environment, episode 211, avg. reward: -15.649999999999979\n", + "2024-04-08 14:55:40,668: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_211.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:42,341: Resetting environment, episode 212, avg. reward: -15.24999999999998\n", + "2024-04-08 14:55:42,344: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_212.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:43,931: Resetting environment, episode 213, avg. reward: -100.25000000000009\n", + "2024-04-08 14:55:43,935: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_213.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:45,687: Resetting environment, episode 214, avg. reward: -50.59999999999998\n", + "2024-04-08 14:55:45,690: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_214.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:47,397: Resetting environment, episode 215, avg. reward: -14.94999999999998\n", + "2024-04-08 14:55:47,400: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_215.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:49,303: Resetting environment, episode 216, avg. reward: -91.64999999999995\n", + "2024-04-08 14:55:49,306: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_216.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:50,916: Resetting environment, episode 217, avg. reward: -75.89999999999999\n", + "2024-04-08 14:55:50,918: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_217.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:53,007: Resetting environment, episode 218, avg. reward: -91.50000000000007\n", + "2024-04-08 14:55:53,011: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_218.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:55,088: Resetting environment, episode 219, avg. reward: -8.300000000000004\n", + "2024-04-08 14:55:55,092: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_219.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:57,164: Resetting environment, episode 220, avg. reward: -29.449999999999996\n", + "2024-04-08 14:55:57,167: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_220.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:55:58,938: Resetting environment, episode 221, avg. reward: -38.20000000000004\n", + "2024-04-08 14:55:58,942: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_221.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:00,655: Resetting environment, episode 222, avg. reward: -38.60000000000001\n", + "2024-04-08 14:56:00,658: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_222.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:02,297: Resetting environment, episode 223, avg. reward: -37.79999999999999\n", + "2024-04-08 14:56:02,300: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_223.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:03,931: Resetting environment, episode 224, avg. reward: -53.24999999999996\n", + "2024-04-08 14:56:03,935: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_224.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:05,761: Resetting environment, episode 225, avg. reward: -77.99999999999997\n", + "2024-04-08 14:56:05,764: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_225.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:07,294: Resetting environment, episode 226, avg. reward: -26.799999999999972\n", + "2024-04-08 14:56:07,298: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_226.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:09,002: Resetting environment, episode 227, avg. reward: -94.5500000000001\n", + "2024-04-08 14:56:09,006: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_227.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:10,831: Resetting environment, episode 228, avg. reward: -76.05000000000001\n", + "2024-04-08 14:56:10,834: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_228.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:12,658: Resetting environment, episode 229, avg. reward: 3.350000000000028\n", + "2024-04-08 14:56:12,661: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_229.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:14,404: Resetting environment, episode 230, avg. reward: -51.25000000000004\n", + "2024-04-08 14:56:14,409: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_230.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:16,439: Resetting environment, episode 231, avg. reward: -86.5\n", + "2024-04-08 14:56:16,442: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_231.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:18,025: Resetting environment, episode 232, avg. reward: -9.550000000000002\n", + "2024-04-08 14:56:18,029: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_232.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:19,978: Resetting environment, episode 233, avg. reward: -46.75\n", + "2024-04-08 14:56:19,982: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_233.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:21,638: Resetting environment, episode 234, avg. reward: -87.14999999999999\n", + "2024-04-08 14:56:21,642: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_234.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:23,262: Resetting environment, episode 235, avg. reward: -60.94999999999995\n", + "2024-04-08 14:56:23,265: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_235.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:24,866: Resetting environment, episode 236, avg. reward: -5.299999999999963\n", + "2024-04-08 14:56:24,870: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_236.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:26,594: Resetting environment, episode 237, avg. reward: -7.49999999999999\n", + "2024-04-08 14:56:26,597: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_237.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:29,812: Resetting environment, episode 238, avg. reward: -4.749999999999977\n", + "2024-04-08 14:56:29,815: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_238.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:31,530: Resetting environment, episode 239, avg. reward: -13.349999999999982\n", + "2024-04-08 14:56:31,533: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_239.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:33,444: Resetting environment, episode 240, avg. reward: -0.599999999999985\n", + "2024-04-08 14:56:33,447: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_240.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:35,290: Resetting environment, episode 241, avg. reward: -95.3\n", + "2024-04-08 14:56:35,292: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_241.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:36,923: Resetting environment, episode 242, avg. reward: -94.94999999999996\n", + "2024-04-08 14:56:36,927: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_242.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:38,916: Resetting environment, episode 243, avg. reward: -72.49999999999993\n", + "2024-04-08 14:56:38,919: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_243.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:40,743: Resetting environment, episode 244, avg. reward: -0.7499999999999888\n", + "2024-04-08 14:56:40,746: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_244.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:42,525: Resetting environment, episode 245, avg. reward: -2.5999999999999943\n", + "2024-04-08 14:56:42,528: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_245.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:44,452: Resetting environment, episode 246, avg. reward: -79.40000000000002\n", + "2024-04-08 14:56:44,455: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_246.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:46,246: Resetting environment, episode 247, avg. reward: -72.7\n", + "2024-04-08 14:56:46,249: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_247.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:48,054: Resetting environment, episode 248, avg. reward: -26.04999999999994\n", + "2024-04-08 14:56:48,058: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_248.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:50,022: Resetting environment, episode 249, avg. reward: -51.100000000000016\n", + "2024-04-08 14:56:50,025: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_249.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:51,853: Resetting environment, episode 250, avg. reward: -9.89999999999996\n", + "2024-04-08 14:56:51,857: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_250.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:53,997: Resetting environment, episode 251, avg. reward: -64.64999999999995\n", + "2024-04-08 14:56:54,001: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_251.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:56,347: Resetting environment, episode 252, avg. reward: -44.999999999999964\n", + "2024-04-08 14:56:56,350: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_252.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:56:58,286: Resetting environment, episode 253, avg. reward: -91.30000000000001\n", + "2024-04-08 14:56:58,288: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_253.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:00,634: Resetting environment, episode 254, avg. reward: -95.24999999999997\n", + "2024-04-08 14:57:00,638: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_254.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:02,345: Resetting environment, episode 255, avg. reward: -15.099999999999978\n", + "2024-04-08 14:57:02,350: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_255.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:04,152: Resetting environment, episode 256, avg. reward: -84.75000000000011\n", + "2024-04-08 14:57:04,155: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_256.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:05,658: Resetting environment, episode 257, avg. reward: -17.399999999999974\n", + "2024-04-08 14:57:05,661: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_257.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:07,257: Resetting environment, episode 258, avg. reward: -17.74999999999997\n", + "2024-04-08 14:57:07,267: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_258.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:09,280: Resetting environment, episode 259, avg. reward: -95.50000000000001\n", + "2024-04-08 14:57:09,283: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_259.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:11,050: Resetting environment, episode 260, avg. reward: -1.4499999999999633\n", + "2024-04-08 14:57:11,054: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_260.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:13,023: Resetting environment, episode 261, avg. reward: -92.59999999999997\n", + "2024-04-08 14:57:13,026: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_261.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:14,723: Resetting environment, episode 262, avg. reward: -2.5999999999999814\n", + "2024-04-08 14:57:14,726: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_262.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:17,321: Resetting environment, episode 263, avg. reward: -60.95000000000002\n", + "2024-04-08 14:57:17,324: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_263.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:19,220: Resetting environment, episode 264, avg. reward: -19.449999999999964\n", + "2024-04-08 14:57:19,223: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_264.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:21,072: Resetting environment, episode 265, avg. reward: -86.4\n", + "2024-04-08 14:57:21,076: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_265.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:22,895: Resetting environment, episode 266, avg. reward: -91.89999999999996\n", + "2024-04-08 14:57:22,899: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_266.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:24,815: Resetting environment, episode 267, avg. reward: -44.5\n", + "2024-04-08 14:57:24,819: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_267.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:26,841: Resetting environment, episode 268, avg. reward: -3.3999999999999875\n", + "2024-04-08 14:57:26,845: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_268.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:28,525: Resetting environment, episode 269, avg. reward: -61.79999999999996\n", + "2024-04-08 14:57:28,528: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_269.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:30,709: Resetting environment, episode 270, avg. reward: -72.09999999999991\n", + "2024-04-08 14:57:30,712: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_270.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:33,009: Resetting environment, episode 271, avg. reward: -10.749999999999986\n", + "2024-04-08 14:57:33,012: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_271.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:34,883: Resetting environment, episode 272, avg. reward: -9.799999999999994\n", + "2024-04-08 14:57:34,886: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_272.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:36,728: Resetting environment, episode 273, avg. reward: -59.85000000000001\n", + "2024-04-08 14:57:36,730: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_273.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:38,769: Resetting environment, episode 274, avg. reward: -33.500000000000014\n", + "2024-04-08 14:57:38,772: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_274.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:40,947: Resetting environment, episode 275, avg. reward: -50.44999999999995\n", + "2024-04-08 14:57:40,950: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_275.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:44,475: Resetting environment, episode 276, avg. reward: -5.800000000000008\n", + "2024-04-08 14:57:44,479: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_276.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:47,898: Resetting environment, episode 277, avg. reward: -13.899999999999979\n", + "2024-04-08 14:57:47,901: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_277.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:50,377: Resetting environment, episode 278, avg. reward: -101.4\n", + "2024-04-08 14:57:50,380: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_278.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:52,619: Resetting environment, episode 279, avg. reward: 0.9500000000000095\n", + "2024-04-08 14:57:52,621: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_279.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:54,559: Resetting environment, episode 280, avg. reward: -86.94999999999999\n", + "2024-04-08 14:57:54,562: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_280.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:56,801: Resetting environment, episode 281, avg. reward: -6.999999999999982\n", + "2024-04-08 14:57:56,803: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_281.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:57:58,672: Resetting environment, episode 282, avg. reward: 11.200000000000063\n", + "2024-04-08 14:57:58,675: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_282.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:00,781: Resetting environment, episode 283, avg. reward: -78.80000000000007\n", + "2024-04-08 14:58:00,785: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_283.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:02,893: Resetting environment, episode 284, avg. reward: -68.24999999999996\n", + "2024-04-08 14:58:02,896: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_284.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:04,854: Resetting environment, episode 285, avg. reward: -43.44999999999995\n", + "2024-04-08 14:58:04,858: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_285.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:07,133: Resetting environment, episode 286, avg. reward: -4.199999999999984\n", + "2024-04-08 14:58:07,136: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_286.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:09,427: Resetting environment, episode 287, avg. reward: 25.550000000000022\n", + "2024-04-08 14:58:09,430: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_287.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:11,576: Resetting environment, episode 288, avg. reward: -11.599999999999985\n", + "2024-04-08 14:58:11,580: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_288.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:13,448: Resetting environment, episode 289, avg. reward: -37.44999999999999\n", + "2024-04-08 14:58:13,451: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_289.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:15,328: Resetting environment, episode 290, avg. reward: -78.99999999999999\n", + "2024-04-08 14:58:15,331: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_290.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:18,155: Resetting environment, episode 291, avg. reward: -56.800000000000026\n", + "2024-04-08 14:58:18,159: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_291.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:20,609: Resetting environment, episode 292, avg. reward: -91.19999999999995\n", + "2024-04-08 14:58:20,614: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_292.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:22,444: Resetting environment, episode 293, avg. reward: 5.200000000000042\n", + "2024-04-08 14:58:22,447: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_293.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:24,809: Resetting environment, episode 294, avg. reward: -20.550000000000047\n", + "2024-04-08 14:58:24,814: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_294.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:26,613: Resetting environment, episode 295, avg. reward: -90.79999999999998\n", + "2024-04-08 14:58:26,616: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_295.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:28,191: Resetting environment, episode 296, avg. reward: -81.50000000000001\n", + "2024-04-08 14:58:28,191: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_296.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:30,080: Resetting environment, episode 297, avg. reward: 18.799999999999965\n", + "2024-04-08 14:58:30,083: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_297.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:32,060: Resetting environment, episode 298, avg. reward: -16.649999999999995\n", + "2024-04-08 14:58:32,062: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_298.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:34,037: Resetting environment, episode 299, avg. reward: 10.250000000000062\n", + "2024-04-08 14:58:34,040: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_299.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:36,089: Resetting environment, episode 300, avg. reward: -41.89999999999998\n", + "2024-04-08 14:58:36,092: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_300.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:38,616: Resetting environment, episode 301, avg. reward: 7.69999999999999\n", + "2024-04-08 14:58:38,616: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_301.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:40,914: Resetting environment, episode 302, avg. reward: 39.7999999999998\n", + "2024-04-08 14:58:40,918: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_302.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:42,618: Resetting environment, episode 303, avg. reward: 6.25000000000006\n", + "2024-04-08 14:58:42,622: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_303.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:44,477: Resetting environment, episode 304, avg. reward: -31.200000000000017\n", + "2024-04-08 14:58:44,477: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_304.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:46,336: Resetting environment, episode 305, avg. reward: -93.50000000000017\n", + "2024-04-08 14:58:46,340: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_305.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:48,689: Resetting environment, episode 306, avg. reward: -33.549999999999955\n", + "2024-04-08 14:58:48,693: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_306.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:51,197: Resetting environment, episode 307, avg. reward: -11.599999999999987\n", + "2024-04-08 14:58:51,200: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_307.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:53,602: Resetting environment, episode 308, avg. reward: -23.900000000000034\n", + "2024-04-08 14:58:53,605: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_308.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:56,033: Resetting environment, episode 309, avg. reward: 3.500000000000001\n", + "2024-04-08 14:58:56,037: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_309.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:58:58,038: Resetting environment, episode 310, avg. reward: 16.04999999999999\n", + "2024-04-08 14:58:58,046: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_310.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:00,171: Resetting environment, episode 311, avg. reward: -13.449999999999982\n", + "2024-04-08 14:59:00,174: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_311.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:02,046: Resetting environment, episode 312, avg. reward: -82.39999999999998\n", + "2024-04-08 14:59:02,057: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_312.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:03,942: Resetting environment, episode 313, avg. reward: 0.3000000000000045\n", + "2024-04-08 14:59:03,944: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_313.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:05,578: Resetting environment, episode 314, avg. reward: -90.35000000000015\n", + "2024-04-08 14:59:05,582: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_314.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:07,340: Resetting environment, episode 315, avg. reward: 3.3000000000000043\n", + "2024-04-08 14:59:07,343: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_315.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:09,117: Resetting environment, episode 316, avg. reward: -44.74999999999995\n", + "2024-04-08 14:59:09,128: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_316.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:11,162: Resetting environment, episode 317, avg. reward: 8.450000000000045\n", + "2024-04-08 14:59:11,165: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_317.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:13,123: Resetting environment, episode 318, avg. reward: -10.049999999999985\n", + "2024-04-08 14:59:13,127: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_318.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:18,061: Resetting environment, episode 319, avg. reward: -17.04999999999999\n", + "2024-04-08 14:59:18,067: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_319.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:19,985: Resetting environment, episode 320, avg. reward: -81.19999999999999\n", + "2024-04-08 14:59:19,989: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_320.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:22,591: Resetting environment, episode 321, avg. reward: 25.900000000000055\n", + "2024-04-08 14:59:22,593: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_321.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:25,075: Resetting environment, episode 322, avg. reward: -6.0500000000000025\n", + "2024-04-08 14:59:25,079: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_322.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:27,224: Resetting environment, episode 323, avg. reward: -0.349999999999965\n", + "2024-04-08 14:59:27,227: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_323.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:29,419: Resetting environment, episode 324, avg. reward: -42.45\n", + "2024-04-08 14:59:29,423: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_324.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:31,350: Resetting environment, episode 325, avg. reward: -36.199999999999974\n", + "2024-04-08 14:59:31,353: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_325.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:33,118: Resetting environment, episode 326, avg. reward: -27.699999999999996\n", + "2024-04-08 14:59:33,120: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_326.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:35,352: Resetting environment, episode 327, avg. reward: 32.74999999999989\n", + "2024-04-08 14:59:35,356: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_327.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:37,251: Resetting environment, episode 328, avg. reward: -16.34999999999998\n", + "2024-04-08 14:59:37,254: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_328.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:39,253: Resetting environment, episode 329, avg. reward: -8.000000000000007\n", + "2024-04-08 14:59:39,259: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_329.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:41,104: Resetting environment, episode 330, avg. reward: -78.60000000000001\n", + "2024-04-08 14:59:41,107: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_330.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:43,172: Resetting environment, episode 331, avg. reward: 12.800000000000024\n", + "2024-04-08 14:59:43,176: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_331.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:45,374: Resetting environment, episode 332, avg. reward: 13.349999999999932\n", + "2024-04-08 14:59:45,378: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_332.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:47,299: Resetting environment, episode 333, avg. reward: -69.95000000000005\n", + "2024-04-08 14:59:47,302: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_333.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:49,565: Resetting environment, episode 334, avg. reward: -88.9000000000001\n", + "2024-04-08 14:59:49,568: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_334.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:51,919: Resetting environment, episode 335, avg. reward: -53.49999999999996\n", + "2024-04-08 14:59:51,919: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_335.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:54,398: Resetting environment, episode 336, avg. reward: -76.90000000000008\n", + "2024-04-08 14:59:54,401: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_336.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:56,196: Resetting environment, episode 337, avg. reward: -43.799999999999955\n", + "2024-04-08 14:59:56,199: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_337.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:57,848: Resetting environment, episode 338, avg. reward: -12.200000000000006\n", + "2024-04-08 14:59:57,852: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_338.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 14:59:59,546: Resetting environment, episode 339, avg. reward: -12.549999999999985\n", + "2024-04-08 14:59:59,550: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_339.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:01,249: Resetting environment, episode 340, avg. reward: -72.65\n", + "2024-04-08 15:00:01,252: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_340.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:03,211: Resetting environment, episode 341, avg. reward: -84.65000000000006\n", + "2024-04-08 15:00:03,214: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_341.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:04,902: Resetting environment, episode 342, avg. reward: -88.64999999999998\n", + "2024-04-08 15:00:04,905: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_342.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:06,894: Resetting environment, episode 343, avg. reward: 37.34999999999988\n", + "2024-04-08 15:00:06,898: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_343.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:08,548: Resetting environment, episode 344, avg. reward: -95.5\n", + "2024-04-08 15:00:08,551: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_344.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:10,369: Resetting environment, episode 345, avg. reward: -98.44999999999996\n", + "2024-04-08 15:00:10,372: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_345.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:12,514: Resetting environment, episode 346, avg. reward: -4.499999999999958\n", + "2024-04-08 15:00:12,517: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_346.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:14,791: Resetting environment, episode 347, avg. reward: -35.90000000000002\n", + "2024-04-08 15:00:14,795: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_347.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:17,226: Resetting environment, episode 348, avg. reward: 12.30000000000003\n", + "2024-04-08 15:00:17,230: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_348.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:18,972: Resetting environment, episode 349, avg. reward: -11.299999999999983\n", + "2024-04-08 15:00:18,972: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_349.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:20,959: Resetting environment, episode 350, avg. reward: -70.59999999999997\n", + "2024-04-08 15:00:20,962: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_350.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:22,880: Resetting environment, episode 351, avg. reward: -20.44999999999996\n", + "2024-04-08 15:00:22,883: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_351.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:24,645: Resetting environment, episode 352, avg. reward: 27.44999999999996\n", + "2024-04-08 15:00:24,649: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_352.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:26,468: Resetting environment, episode 353, avg. reward: 9.349999999999948\n", + "2024-04-08 15:00:26,470: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_353.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:28,268: Resetting environment, episode 354, avg. reward: -71.55\n", + "2024-04-08 15:00:28,271: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_354.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:29,968: Resetting environment, episode 355, avg. reward: -7.849999999999993\n", + "2024-04-08 15:00:29,972: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_355.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:31,672: Resetting environment, episode 356, avg. reward: -58.14999999999992\n", + "2024-04-08 15:00:31,676: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_356.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:33,599: Resetting environment, episode 357, avg. reward: 21.54999999999989\n", + "2024-04-08 15:00:33,602: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_357.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:35,524: Resetting environment, episode 358, avg. reward: 10.350000000000037\n", + "2024-04-08 15:00:35,533: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_358.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:37,442: Resetting environment, episode 359, avg. reward: 12.749999999999961\n", + "2024-04-08 15:00:37,446: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_359.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:39,754: Resetting environment, episode 360, avg. reward: 26.849999999999863\n", + "2024-04-08 15:00:39,758: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_360.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:42,148: Resetting environment, episode 361, avg. reward: 1.9500000000000377\n", + "2024-04-08 15:00:42,152: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_361.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:44,863: Resetting environment, episode 362, avg. reward: -84.79999999999984\n", + "2024-04-08 15:00:44,867: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_362.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:47,398: Resetting environment, episode 363, avg. reward: -37.899999999999956\n", + "2024-04-08 15:00:47,402: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_363.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:50,122: Resetting environment, episode 364, avg. reward: -11.250000000000085\n", + "2024-04-08 15:00:50,126: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_364.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:52,560: Resetting environment, episode 365, avg. reward: -84.9\n", + "2024-04-08 15:00:52,562: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_365.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:54,688: Resetting environment, episode 366, avg. reward: -66.45000000000002\n", + "2024-04-08 15:00:54,692: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_366.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:00:59,582: Resetting environment, episode 367, avg. reward: 26.95\n", + "2024-04-08 15:00:59,585: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_367.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:01,883: Resetting environment, episode 368, avg. reward: -36.3\n", + "2024-04-08 15:01:01,886: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_368.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:04,194: Resetting environment, episode 369, avg. reward: -42.04999999999998\n", + "2024-04-08 15:01:04,197: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_369.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:06,476: Resetting environment, episode 370, avg. reward: -79.85000000000004\n", + "2024-04-08 15:01:06,480: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_370.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:08,804: Resetting environment, episode 371, avg. reward: 42.4499999999998\n", + "2024-04-08 15:01:08,809: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_371.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:11,021: Resetting environment, episode 372, avg. reward: -21.04999999999998\n", + "2024-04-08 15:01:11,025: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_372.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:13,427: Resetting environment, episode 373, avg. reward: 60.24999999999987\n", + "2024-04-08 15:01:13,430: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_373.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:15,228: Resetting environment, episode 374, avg. reward: -71.3\n", + "2024-04-08 15:01:15,231: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_374.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:17,086: Resetting environment, episode 375, avg. reward: 27.249999999999872\n", + "2024-04-08 15:01:17,089: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_375.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:18,949: Resetting environment, episode 376, avg. reward: 24.149999999999984\n", + "2024-04-08 15:01:18,952: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_376.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:20,875: Resetting environment, episode 377, avg. reward: -53.54999999999999\n", + "2024-04-08 15:01:20,879: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_377.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:22,686: Resetting environment, episode 378, avg. reward: 31.84999999999999\n", + "2024-04-08 15:01:22,690: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_378.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:24,470: Resetting environment, episode 379, avg. reward: -65.4\n", + "2024-04-08 15:01:24,473: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_379.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:26,345: Resetting environment, episode 380, avg. reward: 52.84999999999978\n", + "2024-04-08 15:01:26,348: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_380.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:28,494: Resetting environment, episode 381, avg. reward: -50.450000000000024\n", + "2024-04-08 15:01:28,497: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_381.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:30,231: Resetting environment, episode 382, avg. reward: -71.99999999999991\n", + "2024-04-08 15:01:30,235: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_382.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:32,232: Resetting environment, episode 383, avg. reward: 20.400000000000073\n", + "2024-04-08 15:01:32,236: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_383.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:33,887: Resetting environment, episode 384, avg. reward: 14.799999999999994\n", + "2024-04-08 15:01:33,890: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_384.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:35,491: Resetting environment, episode 385, avg. reward: -46.900000000000055\n", + "2024-04-08 15:01:35,494: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_385.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:37,246: Resetting environment, episode 386, avg. reward: 0.8999999999999937\n", + "2024-04-08 15:01:37,249: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_386.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:38,777: Resetting environment, episode 387, avg. reward: -13.35\n", + "2024-04-08 15:01:38,780: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_387.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:40,765: Resetting environment, episode 388, avg. reward: -66.39999999999996\n", + "2024-04-08 15:01:40,765: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_388.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:43,096: Resetting environment, episode 389, avg. reward: -60.40000000000004\n", + "2024-04-08 15:01:43,098: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_389.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:45,309: Resetting environment, episode 390, avg. reward: -40.299999999999976\n", + "2024-04-08 15:01:45,312: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_390.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:47,533: Resetting environment, episode 391, avg. reward: -9.300000000000024\n", + "2024-04-08 15:01:47,536: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_391.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:49,645: Resetting environment, episode 392, avg. reward: -68.20000000000002\n", + "2024-04-08 15:01:49,650: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_392.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:51,698: Resetting environment, episode 393, avg. reward: -12.050000000000015\n", + "2024-04-08 15:01:51,698: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_393.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:53,431: Resetting environment, episode 394, avg. reward: -45.90000000000007\n", + "2024-04-08 15:01:53,434: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_394.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:55,444: Resetting environment, episode 395, avg. reward: -7.850000000000001\n", + "2024-04-08 15:01:55,444: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_395.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:01:57,778: Resetting environment, episode 396, avg. reward: -81.24999999999994\n", + "2024-04-08 15:01:57,783: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_396.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:00,035: Resetting environment, episode 397, avg. reward: 35.40000000000004\n", + "2024-04-08 15:02:00,039: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_397.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:02,146: Resetting environment, episode 398, avg. reward: -9.550000000000082\n", + "2024-04-08 15:02:02,148: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_398.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:04,122: Resetting environment, episode 399, avg. reward: 10.550000000000026\n", + "2024-04-08 15:02:04,126: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_399.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:06,128: Resetting environment, episode 400, avg. reward: -2.7499999999999734\n", + "2024-04-08 15:02:06,132: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_400.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:08,277: Resetting environment, episode 401, avg. reward: 11.199999999999974\n", + "2024-04-08 15:02:08,281: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_401.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:10,123: Resetting environment, episode 402, avg. reward: 38.94999999999992\n", + "2024-04-08 15:02:10,126: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_402.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:12,770: Resetting environment, episode 403, avg. reward: 40.150000000000006\n", + "2024-04-08 15:02:12,774: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_403.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:14,630: Resetting environment, episode 404, avg. reward: -28.65000000000003\n", + "2024-04-08 15:02:14,633: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_404.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:16,440: Resetting environment, episode 405, avg. reward: 32.25000000000001\n", + "2024-04-08 15:02:16,443: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_405.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:18,127: Resetting environment, episode 406, avg. reward: -11.699999999999982\n", + "2024-04-08 15:02:18,130: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_406.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:20,294: Resetting environment, episode 407, avg. reward: 51.299999999999976\n", + "2024-04-08 15:02:20,297: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_407.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:22,154: Resetting environment, episode 408, avg. reward: 10.399999999999963\n", + "2024-04-08 15:02:22,157: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_408.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:24,369: Resetting environment, episode 409, avg. reward: -12.599999999999984\n", + "2024-04-08 15:02:24,373: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_409.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:26,758: Resetting environment, episode 410, avg. reward: 13.600000000000026\n", + "2024-04-08 15:02:26,761: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_410.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:30,043: Resetting environment, episode 411, avg. reward: 31.89999999999995\n", + "2024-04-08 15:02:30,047: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_411.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:32,018: Resetting environment, episode 412, avg. reward: 22.050000000000054\n", + "2024-04-08 15:02:32,021: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_412.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:33,671: Resetting environment, episode 413, avg. reward: 38.74999999999982\n", + "2024-04-08 15:02:33,674: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_413.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:35,754: Resetting environment, episode 414, avg. reward: 21.250000000000092\n", + "2024-04-08 15:02:35,757: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_414.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:37,697: Resetting environment, episode 415, avg. reward: 52.64999999999991\n", + "2024-04-08 15:02:37,704: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_415.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:39,371: Resetting environment, episode 416, avg. reward: 15.300000000000079\n", + "2024-04-08 15:02:39,374: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_416.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:40,894: Resetting environment, episode 417, avg. reward: -0.24999999999995826\n", + "2024-04-08 15:02:40,896: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_417.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:42,813: Resetting environment, episode 418, avg. reward: -22.05000000000004\n", + "2024-04-08 15:02:42,817: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_418.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:44,725: Resetting environment, episode 419, avg. reward: -54.89999999999997\n", + "2024-04-08 15:02:44,727: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_419.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:48,515: Resetting environment, episode 420, avg. reward: -15.04999999999997\n", + "2024-04-08 15:02:48,518: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_420.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:50,655: Resetting environment, episode 421, avg. reward: -56.94999999999997\n", + "2024-04-08 15:02:50,659: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_421.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:52,515: Resetting environment, episode 422, avg. reward: -68.70000000000003\n", + "2024-04-08 15:02:52,517: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_422.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:54,132: Resetting environment, episode 423, avg. reward: -72.89999999999996\n", + "2024-04-08 15:02:54,134: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_423.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:55,908: Resetting environment, episode 424, avg. reward: 17.449999999999946\n", + "2024-04-08 15:02:55,911: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_424.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:57,497: Resetting environment, episode 425, avg. reward: -27.14999999999995\n", + "2024-04-08 15:02:57,501: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_425.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:02:59,501: Resetting environment, episode 426, avg. reward: -67.6\n", + "2024-04-08 15:02:59,504: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_426.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:01,163: Resetting environment, episode 427, avg. reward: 27.7999999999999\n", + "2024-04-08 15:03:01,166: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_427.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:02,845: Resetting environment, episode 428, avg. reward: 43.599999999999895\n", + "2024-04-08 15:03:02,849: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_428.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:04,688: Resetting environment, episode 429, avg. reward: 10.649999999999995\n", + "2024-04-08 15:03:04,691: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_429.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:06,537: Resetting environment, episode 430, avg. reward: 6.549999999999988\n", + "2024-04-08 15:03:06,540: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_430.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:08,508: Resetting environment, episode 431, avg. reward: -53.84999999999999\n", + "2024-04-08 15:03:08,510: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_431.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:10,547: Resetting environment, episode 432, avg. reward: -16.399999999999995\n", + "2024-04-08 15:03:10,550: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_432.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:12,415: Resetting environment, episode 433, avg. reward: 26.500000000000014\n", + "2024-04-08 15:03:12,418: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_433.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:13,905: Resetting environment, episode 434, avg. reward: -9.04999999999999\n", + "2024-04-08 15:03:13,909: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_434.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:15,659: Resetting environment, episode 435, avg. reward: -70.59999999999998\n", + "2024-04-08 15:03:15,662: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_435.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:17,377: Resetting environment, episode 436, avg. reward: 8.600000000000009\n", + "2024-04-08 15:03:17,381: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_436.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:19,455: Resetting environment, episode 437, avg. reward: 84.10000000000014\n", + "2024-04-08 15:03:19,458: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_437.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:21,741: Resetting environment, episode 438, avg. reward: -52.299999999999976\n", + "2024-04-08 15:03:21,744: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_438.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:23,696: Resetting environment, episode 439, avg. reward: 20.199999999999957\n", + "2024-04-08 15:03:23,700: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_439.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:25,663: Resetting environment, episode 440, avg. reward: -79.10000000000002\n", + "2024-04-08 15:03:25,667: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_440.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:27,924: Resetting environment, episode 441, avg. reward: 58.799999999999876\n", + "2024-04-08 15:03:27,928: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_441.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:29,603: Resetting environment, episode 442, avg. reward: -35.64999999999998\n", + "2024-04-08 15:03:29,606: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_442.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:31,271: Resetting environment, episode 443, avg. reward: -0.7500000000000195\n", + "2024-04-08 15:03:31,274: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_443.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:33,199: Resetting environment, episode 444, avg. reward: -83.49999999999989\n", + "2024-04-08 15:03:33,203: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_444.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:35,706: Resetting environment, episode 445, avg. reward: 58.54999999999981\n", + "2024-04-08 15:03:35,710: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_445.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:37,671: Resetting environment, episode 446, avg. reward: -39.45000000000003\n", + "2024-04-08 15:03:37,673: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_446.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:40,320: Resetting environment, episode 447, avg. reward: -63.049999999999955\n", + "2024-04-08 15:03:40,324: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_447.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:42,333: Resetting environment, episode 448, avg. reward: -48.29999999999998\n", + "2024-04-08 15:03:42,336: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_448.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:44,621: Resetting environment, episode 449, avg. reward: 87.55000000000031\n", + "2024-04-08 15:03:44,625: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_449.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:46,958: Resetting environment, episode 450, avg. reward: 59.89999999999991\n", + "2024-04-08 15:03:46,962: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_450.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:49,779: Resetting environment, episode 451, avg. reward: -35.349999999999994\n", + "2024-04-08 15:03:49,783: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_451.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:51,834: Resetting environment, episode 452, avg. reward: -61.19999999999991\n", + "2024-04-08 15:03:51,837: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_452.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:53,774: Resetting environment, episode 453, avg. reward: 1.6000000000000005\n", + "2024-04-08 15:03:53,777: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_453.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:56,025: Resetting environment, episode 454, avg. reward: 13.14999999999995\n", + "2024-04-08 15:03:56,028: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_454.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:03:58,535: Resetting environment, episode 455, avg. reward: 19.950000000000003\n", + "2024-04-08 15:03:58,538: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_455.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:00,845: Resetting environment, episode 456, avg. reward: -33.04999999999999\n", + "2024-04-08 15:04:00,848: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_456.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:02,904: Resetting environment, episode 457, avg. reward: 39.59999999999999\n", + "2024-04-08 15:04:02,909: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_457.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:05,202: Resetting environment, episode 458, avg. reward: -8.300000000000002\n", + "2024-04-08 15:04:05,206: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_458.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:07,216: Resetting environment, episode 459, avg. reward: -85.5\n", + "2024-04-08 15:04:07,219: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_459.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:09,300: Resetting environment, episode 460, avg. reward: 42.149999999999935\n", + "2024-04-08 15:04:09,304: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_460.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:11,700: Resetting environment, episode 461, avg. reward: -7.00000000000005\n", + "2024-04-08 15:04:11,703: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_461.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:13,865: Resetting environment, episode 462, avg. reward: 44.99999999999982\n", + "2024-04-08 15:04:13,868: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_462.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:15,915: Resetting environment, episode 463, avg. reward: -14.150000000000015\n", + "2024-04-08 15:04:15,919: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_463.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:18,129: Resetting environment, episode 464, avg. reward: -62.3\n", + "2024-04-08 15:04:18,133: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_464.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:20,618: Resetting environment, episode 465, avg. reward: -21.85\n", + "2024-04-08 15:04:20,623: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_465.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:22,808: Resetting environment, episode 466, avg. reward: -21.59999999999995\n", + "2024-04-08 15:04:22,811: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_466.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:24,768: Resetting environment, episode 467, avg. reward: -14.950000000000008\n", + "2024-04-08 15:04:24,772: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_467.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:26,660: Resetting environment, episode 468, avg. reward: 18.64999999999998\n", + "2024-04-08 15:04:26,663: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_468.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:28,354: Resetting environment, episode 469, avg. reward: -10.699999999999989\n", + "2024-04-08 15:04:28,357: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_469.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:30,242: Resetting environment, episode 470, avg. reward: -53.79999999999998\n", + "2024-04-08 15:04:30,245: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_470.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:33,035: Resetting environment, episode 471, avg. reward: 84.70000000000006\n", + "2024-04-08 15:04:33,038: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_471.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:35,091: Resetting environment, episode 472, avg. reward: -7.000000000000062\n", + "2024-04-08 15:04:35,093: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_472.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[8], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlearn\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtotal_timesteps\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mTOTAL_TIMESTEPS\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32mc:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\ppo\\ppo.py:308\u001b[0m, in \u001b[0;36mPPO.learn\u001b[1;34m(self, total_timesteps, callback, log_interval, tb_log_name, reset_num_timesteps, progress_bar)\u001b[0m\n\u001b[0;32m 299\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mlearn\u001b[39m(\n\u001b[0;32m 300\u001b[0m \u001b[38;5;28mself\u001b[39m: SelfPPO,\n\u001b[0;32m 301\u001b[0m total_timesteps: \u001b[38;5;28mint\u001b[39m,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 306\u001b[0m progress_bar: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[0;32m 307\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m SelfPPO:\n\u001b[1;32m--> 308\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlearn\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 309\u001b[0m \u001b[43m \u001b[49m\u001b[43mtotal_timesteps\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtotal_timesteps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 310\u001b[0m \u001b[43m \u001b[49m\u001b[43mcallback\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallback\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 311\u001b[0m \u001b[43m \u001b[49m\u001b[43mlog_interval\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlog_interval\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 312\u001b[0m \u001b[43m \u001b[49m\u001b[43mtb_log_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtb_log_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 313\u001b[0m \u001b[43m \u001b[49m\u001b[43mreset_num_timesteps\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mreset_num_timesteps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 314\u001b[0m \u001b[43m \u001b[49m\u001b[43mprogress_bar\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mprogress_bar\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 315\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32mc:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\common\\on_policy_algorithm.py:259\u001b[0m, in \u001b[0;36mOnPolicyAlgorithm.learn\u001b[1;34m(self, total_timesteps, callback, log_interval, tb_log_name, reset_num_timesteps, progress_bar)\u001b[0m\n\u001b[0;32m 256\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39menv \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 258\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnum_timesteps \u001b[38;5;241m<\u001b[39m total_timesteps:\n\u001b[1;32m--> 259\u001b[0m continue_training \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcollect_rollouts\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menv\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallback\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrollout_buffer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mn_rollout_steps\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mn_steps\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 261\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m continue_training \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m:\n\u001b[0;32m 262\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n", + "File \u001b[1;32mc:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\common\\on_policy_algorithm.py:178\u001b[0m, in \u001b[0;36mOnPolicyAlgorithm.collect_rollouts\u001b[1;34m(self, env, callback, rollout_buffer, n_rollout_steps)\u001b[0m\n\u001b[0;32m 175\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maction_space, spaces\u001b[38;5;241m.\u001b[39mBox):\n\u001b[0;32m 176\u001b[0m clipped_actions \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mclip(actions, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maction_space\u001b[38;5;241m.\u001b[39mlow, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maction_space\u001b[38;5;241m.\u001b[39mhigh)\n\u001b[1;32m--> 178\u001b[0m new_obs, rewards, dones, infos \u001b[38;5;241m=\u001b[39m \u001b[43menv\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstep\u001b[49m\u001b[43m(\u001b[49m\u001b[43mclipped_actions\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 180\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnum_timesteps \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m env\u001b[38;5;241m.\u001b[39mnum_envs\n\u001b[0;32m 182\u001b[0m \u001b[38;5;66;03m# Give access to local variables\u001b[39;00m\n", + "File \u001b[1;32mc:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\common\\vec_env\\base_vec_env.py:197\u001b[0m, in \u001b[0;36mVecEnv.step\u001b[1;34m(self, actions)\u001b[0m\n\u001b[0;32m 190\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 191\u001b[0m \u001b[38;5;124;03mStep the environments with the given action\u001b[39;00m\n\u001b[0;32m 192\u001b[0m \n\u001b[0;32m 193\u001b[0m \u001b[38;5;124;03m:param actions: the action\u001b[39;00m\n\u001b[0;32m 194\u001b[0m \u001b[38;5;124;03m:return: observation, reward, done, information\u001b[39;00m\n\u001b[0;32m 195\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 196\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstep_async(actions)\n\u001b[1;32m--> 197\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstep_wait\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32mc:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\common\\vec_env\\dummy_vec_env.py:58\u001b[0m, in \u001b[0;36mDummyVecEnv.step_wait\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 55\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mstep_wait\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m VecEnvStepReturn:\n\u001b[0;32m 56\u001b[0m \u001b[38;5;66;03m# Avoid circular imports\u001b[39;00m\n\u001b[0;32m 57\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m env_idx \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnum_envs):\n\u001b[1;32m---> 58\u001b[0m obs, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuf_rews[env_idx], terminated, truncated, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuf_infos[env_idx] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menvs\u001b[49m\u001b[43m[\u001b[49m\u001b[43menv_idx\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstep\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 59\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mactions\u001b[49m\u001b[43m[\u001b[49m\u001b[43menv_idx\u001b[49m\u001b[43m]\u001b[49m\n\u001b[0;32m 60\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 61\u001b[0m \u001b[38;5;66;03m# convert to SB3 VecEnv api\u001b[39;00m\n\u001b[0;32m 62\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuf_dones[env_idx] \u001b[38;5;241m=\u001b[39m terminated \u001b[38;5;129;01mor\u001b[39;00m truncated\n", + "File \u001b[1;32mc:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\common\\monitor.py:94\u001b[0m, in \u001b[0;36mMonitor.step\u001b[1;34m(self, action)\u001b[0m\n\u001b[0;32m 92\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mneeds_reset:\n\u001b[0;32m 93\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTried to step environment that needs reset\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 94\u001b[0m observation, reward, terminated, truncated, info \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menv\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstep\u001b[49m\u001b[43m(\u001b[49m\u001b[43maction\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 95\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrewards\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;28mfloat\u001b[39m(reward))\n\u001b[0;32m 96\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m terminated \u001b[38;5;129;01mor\u001b[39;00m truncated:\n", + "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\session\\environment.py:54\u001b[0m, in \u001b[0;36mPrimaiteGymEnv.step\u001b[1;34m(self, action)\u001b[0m\n\u001b[0;32m 52\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mgame\u001b[38;5;241m.\u001b[39mapply_agent_actions()\n\u001b[0;32m 53\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mgame\u001b[38;5;241m.\u001b[39madvance_timestep()\n\u001b[1;32m---> 54\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgame\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_sim_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 55\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mgame\u001b[38;5;241m.\u001b[39mupdate_agents(state)\n\u001b[0;32m 57\u001b[0m next_obs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_obs() \u001b[38;5;66;03m# this doesn't update observation, just gets the current observation\u001b[39;00m\n", + "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\game\\game.py:149\u001b[0m, in \u001b[0;36mPrimaiteGame.get_sim_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 147\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_sim_state\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict:\n\u001b[0;32m 148\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Get the current state of the simulation.\"\"\"\u001b[39;00m\n\u001b[1;32m--> 149\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msimulation\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\sim_container.py:56\u001b[0m, in \u001b[0;36mSimulation.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 45\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 46\u001b[0m \u001b[38;5;124;03mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[0;32m 47\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 51\u001b[0m \u001b[38;5;124;03m:rtype: Dict\u001b[39;00m\n\u001b[0;32m 52\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 53\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 54\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 55\u001b[0m {\n\u001b[1;32m---> 56\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnetwork\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mnetwork\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m,\n\u001b[0;32m 57\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdomain\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdomain\u001b[38;5;241m.\u001b[39mdescribe_state(),\n\u001b[0;32m 58\u001b[0m }\n\u001b[0;32m 59\u001b[0m )\n\u001b[0;32m 60\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", + "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\network\\container.py:223\u001b[0m, in \u001b[0;36mNetwork.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 215\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 216\u001b[0m \u001b[38;5;124;03mProduce a dictionary describing the current state of the Network.\u001b[39;00m\n\u001b[0;32m 217\u001b[0m \n\u001b[0;32m 218\u001b[0m \u001b[38;5;124;03m:return: A dictionary capturing the current state of the Network and its child objects.\u001b[39;00m\n\u001b[0;32m 219\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 220\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 221\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 222\u001b[0m {\n\u001b[1;32m--> 223\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnodes\u001b[39m\u001b[38;5;124m\"\u001b[39m: {node\u001b[38;5;241m.\u001b[39mhostname: node\u001b[38;5;241m.\u001b[39mdescribe_state() \u001b[38;5;28;01mfor\u001b[39;00m node \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnodes\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 224\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlinks\u001b[39m\u001b[38;5;124m\"\u001b[39m: {},\n\u001b[0;32m 225\u001b[0m }\n\u001b[0;32m 226\u001b[0m )\n\u001b[0;32m 227\u001b[0m \u001b[38;5;66;03m# Update the links one-by-one. The key is a 4-tuple of `hostname_a, port_a, hostname_b, port_b`\u001b[39;00m\n\u001b[0;32m 228\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m _, link \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlinks\u001b[38;5;241m.\u001b[39mitems():\n", + "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\network\\container.py:223\u001b[0m, in \u001b[0;36m\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m 215\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 216\u001b[0m \u001b[38;5;124;03mProduce a dictionary describing the current state of the Network.\u001b[39;00m\n\u001b[0;32m 217\u001b[0m \n\u001b[0;32m 218\u001b[0m \u001b[38;5;124;03m:return: A dictionary capturing the current state of the Network and its child objects.\u001b[39;00m\n\u001b[0;32m 219\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 220\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 221\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 222\u001b[0m {\n\u001b[1;32m--> 223\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnodes\u001b[39m\u001b[38;5;124m\"\u001b[39m: {node\u001b[38;5;241m.\u001b[39mhostname: \u001b[43mnode\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m node \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnodes\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 224\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlinks\u001b[39m\u001b[38;5;124m\"\u001b[39m: {},\n\u001b[0;32m 225\u001b[0m }\n\u001b[0;32m 226\u001b[0m )\n\u001b[0;32m 227\u001b[0m \u001b[38;5;66;03m# Update the links one-by-one. The key is a 4-tuple of `hostname_a, port_a, hostname_b, port_b`\u001b[39;00m\n\u001b[0;32m 228\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m _, link \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlinks\u001b[38;5;241m.\u001b[39mitems():\n", + "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\network\\hardware\\base.py:920\u001b[0m, in \u001b[0;36mNode.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 902\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 903\u001b[0m \u001b[38;5;124;03mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[0;32m 904\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 908\u001b[0m \u001b[38;5;124;03m:rtype: Dict\u001b[39;00m\n\u001b[0;32m 909\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 910\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 911\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 912\u001b[0m {\n\u001b[0;32m 913\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhostname\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhostname,\n\u001b[0;32m 914\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124moperating_state\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moperating_state\u001b[38;5;241m.\u001b[39mvalue,\n\u001b[0;32m 915\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNICs\u001b[39m\u001b[38;5;124m\"\u001b[39m: {\n\u001b[0;32m 916\u001b[0m eth_num: network_interface\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 917\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m eth_num, network_interface \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnetwork_interface\u001b[38;5;241m.\u001b[39mitems()\n\u001b[0;32m 918\u001b[0m },\n\u001b[0;32m 919\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfile_system\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfile_system\u001b[38;5;241m.\u001b[39mdescribe_state(),\n\u001b[1;32m--> 920\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapplications\u001b[39m\u001b[38;5;124m\"\u001b[39m: {app\u001b[38;5;241m.\u001b[39mname: app\u001b[38;5;241m.\u001b[39mdescribe_state() \u001b[38;5;28;01mfor\u001b[39;00m app \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mapplications\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 921\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mservices\u001b[39m\u001b[38;5;124m\"\u001b[39m: {svc\u001b[38;5;241m.\u001b[39mname: svc\u001b[38;5;241m.\u001b[39mdescribe_state() \u001b[38;5;28;01mfor\u001b[39;00m svc \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mservices\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 922\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mprocess\u001b[39m\u001b[38;5;124m\"\u001b[39m: {proc\u001b[38;5;241m.\u001b[39mname: proc\u001b[38;5;241m.\u001b[39mdescribe_state() \u001b[38;5;28;01mfor\u001b[39;00m proc \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocesses\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 923\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrevealed_to_red\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrevealed_to_red,\n\u001b[0;32m 924\u001b[0m }\n\u001b[0;32m 925\u001b[0m )\n\u001b[0;32m 926\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", + "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\network\\hardware\\base.py:920\u001b[0m, in \u001b[0;36m\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m 902\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 903\u001b[0m \u001b[38;5;124;03mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[0;32m 904\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 908\u001b[0m \u001b[38;5;124;03m:rtype: Dict\u001b[39;00m\n\u001b[0;32m 909\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 910\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 911\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 912\u001b[0m {\n\u001b[0;32m 913\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhostname\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhostname,\n\u001b[0;32m 914\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124moperating_state\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moperating_state\u001b[38;5;241m.\u001b[39mvalue,\n\u001b[0;32m 915\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNICs\u001b[39m\u001b[38;5;124m\"\u001b[39m: {\n\u001b[0;32m 916\u001b[0m eth_num: network_interface\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 917\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m eth_num, network_interface \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnetwork_interface\u001b[38;5;241m.\u001b[39mitems()\n\u001b[0;32m 918\u001b[0m },\n\u001b[0;32m 919\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfile_system\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfile_system\u001b[38;5;241m.\u001b[39mdescribe_state(),\n\u001b[1;32m--> 920\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapplications\u001b[39m\u001b[38;5;124m\"\u001b[39m: {app\u001b[38;5;241m.\u001b[39mname: \u001b[43mapp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m app \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mapplications\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 921\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mservices\u001b[39m\u001b[38;5;124m\"\u001b[39m: {svc\u001b[38;5;241m.\u001b[39mname: svc\u001b[38;5;241m.\u001b[39mdescribe_state() \u001b[38;5;28;01mfor\u001b[39;00m svc \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mservices\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 922\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mprocess\u001b[39m\u001b[38;5;124m\"\u001b[39m: {proc\u001b[38;5;241m.\u001b[39mname: proc\u001b[38;5;241m.\u001b[39mdescribe_state() \u001b[38;5;28;01mfor\u001b[39;00m proc \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocesses\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 923\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrevealed_to_red\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrevealed_to_red,\n\u001b[0;32m 924\u001b[0m }\n\u001b[0;32m 925\u001b[0m )\n\u001b[0;32m 926\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", + "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\system\\applications\\web_browser.py:75\u001b[0m, in \u001b[0;36mWebBrowser.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 69\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdescribe_state\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict:\n\u001b[0;32m 70\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 71\u001b[0m \u001b[38;5;124;03m Produce a dictionary describing the current state of the WebBrowser.\u001b[39;00m\n\u001b[0;32m 72\u001b[0m \n\u001b[0;32m 73\u001b[0m \u001b[38;5;124;03m :return: A dictionary capturing the current state of the WebBrowser and its child objects.\u001b[39;00m\n\u001b[0;32m 74\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 75\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 76\u001b[0m state[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhistory\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m [hist_item\u001b[38;5;241m.\u001b[39mstate() \u001b[38;5;28;01mfor\u001b[39;00m hist_item \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhistory]\n\u001b[0;32m 77\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", + "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\system\\applications\\application.py:64\u001b[0m, in \u001b[0;36mApplication.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 54\u001b[0m \u001b[38;5;129m@abstractmethod\u001b[39m\n\u001b[0;32m 55\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdescribe_state\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict:\n\u001b[0;32m 56\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 57\u001b[0m \u001b[38;5;124;03m Produce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[0;32m 58\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 62\u001b[0m \u001b[38;5;124;03m :rtype: Dict\u001b[39;00m\n\u001b[0;32m 63\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 64\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 65\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 66\u001b[0m {\n\u001b[0;32m 67\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124moperating_state\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moperating_state\u001b[38;5;241m.\u001b[39mvalue,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 71\u001b[0m }\n\u001b[0;32m 72\u001b[0m )\n\u001b[0;32m 73\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", + "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\system\\software.py:263\u001b[0m, in \u001b[0;36mIOSoftware.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 253\u001b[0m \u001b[38;5;129m@abstractmethod\u001b[39m\n\u001b[0;32m 254\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdescribe_state\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict:\n\u001b[0;32m 255\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 256\u001b[0m \u001b[38;5;124;03m Produce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[0;32m 257\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 261\u001b[0m \u001b[38;5;124;03m :rtype: Dict\u001b[39;00m\n\u001b[0;32m 262\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m--> 263\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 264\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 265\u001b[0m {\n\u001b[0;32m 266\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124minstalling_count\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minstalling_count,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 271\u001b[0m }\n\u001b[0;32m 272\u001b[0m )\n\u001b[0;32m 273\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", + "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\system\\software.py:149\u001b[0m, in \u001b[0;36mSoftware.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 138\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 139\u001b[0m \u001b[38;5;124;03mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[0;32m 140\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 144\u001b[0m \u001b[38;5;124;03m:rtype: Dict\u001b[39;00m\n\u001b[0;32m 145\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 146\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 147\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 148\u001b[0m {\n\u001b[1;32m--> 149\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhealth_state_actual\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhealth_state_actual\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvalue\u001b[49m,\n\u001b[0;32m 150\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhealth_state_visible\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhealth_state_visible\u001b[38;5;241m.\u001b[39mvalue,\n\u001b[0;32m 151\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcriticality\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcriticality\u001b[38;5;241m.\u001b[39mvalue,\n\u001b[0;32m 152\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfixing_count\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfixing_count,\n\u001b[0;32m 153\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mscanning_count\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mscanning_count,\n\u001b[0;32m 154\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrevealed_to_red\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrevealed_to_red,\n\u001b[0;32m 155\u001b[0m }\n\u001b[0;32m 156\u001b[0m )\n\u001b[0;32m 157\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", + "File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python310\\lib\\types.py:177\u001b[0m, in \u001b[0;36mDynamicClassAttribute.__get__\u001b[1;34m(self, instance, ownerclass)\u001b[0m\n\u001b[0;32m 176\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__get__\u001b[39m(\u001b[38;5;28mself\u001b[39m, instance, ownerclass\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[1;32m--> 177\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43minstance\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m:\n\u001b[0;32m 178\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m__isabstractmethod__:\n\u001b[0;32m 179\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\n", + "\u001b[1;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], "source": [ "model.learn(total_timesteps=TOTAL_TIMESTEPS)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -83,7 +7216,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -93,9 +7226,187 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "c:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\common\\evaluation.py:67: UserWarning: Evaluation environment is not wrapped with a ``Monitor`` wrapper. This may result in reporting modified episode lengths and rewards, if other wrappers happen to modify these. Consider wrapping environment first with ``Monitor`` wrapper.\n", + " warnings.warn(\n", + "2024-04-08 15:04:51,136: Resetting environment, episode 473, avg. reward: 0.0\n", + "2024-04-08 15:04:51,140: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_473.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:53,329: Resetting environment, episode 474, avg. reward: -62.59999999999992\n", + "2024-04-08 15:04:53,332: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_474.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:55,400: Resetting environment, episode 475, avg. reward: -58.649999999999935\n", + "2024-04-08 15:04:55,403: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_475.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:04:57,612: Resetting environment, episode 476, avg. reward: -54.549999999999955\n", + "2024-04-08 15:04:57,617: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_476.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:05:02,916: Resetting environment, episode 477, avg. reward: -64.99999999999991\n", + "2024-04-08 15:05:02,918: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_477.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:05:05,225: Resetting environment, episode 478, avg. reward: -53.19999999999996\n", + "2024-04-08 15:05:05,228: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_478.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:05:07,766: Resetting environment, episode 479, avg. reward: -55.79999999999997\n", + "2024-04-08 15:05:07,769: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_479.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:05:10,062: Resetting environment, episode 480, avg. reward: -32.75000000000003\n", + "2024-04-08 15:05:10,065: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_480.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:05:12,370: Resetting environment, episode 481, avg. reward: -23.549999999999986\n", + "2024-04-08 15:05:12,373: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_481.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:05:14,716: Resetting environment, episode 482, avg. reward: -15.04999999999997\n", + "2024-04-08 15:05:14,719: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_482.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-04-08 15:05:16,779: Resetting environment, episode 483, avg. reward: -50.549999999999976\n", + "2024-04-08 15:05:16,782: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_483.json\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" + ] + }, + { + "data": { + "text/plain": [ + "(-47.170001389086245, 16.315777792523683)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from stable_baselines3.common.evaluation import evaluate_policy\n", "\n", @@ -119,7 +7430,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.18" + "version": "3.10.11" } }, "nbformat": 4, diff --git a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb index d9742b50..57003e55 100644 --- a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb +++ b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 119, "metadata": {}, "outputs": [], "source": [ @@ -36,9 +36,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 120, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'uuid': '42d005b2-4dc8-4aec-be54-3493242eee32',\n", + " 'network': {'uuid': '069f61a4-ac40-431f-ad13-2fc9b26dc091',\n", + " 'nodes': {},\n", + " 'links': {}},\n", + " 'domain': {'uuid': 'f0629156-e9af-493d-b098-f47d73126122', 'accounts': {}}}" + ] + }, + "execution_count": 120, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_sim = Simulation()\n", "net = my_sim.network\n", @@ -54,22 +69,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 121, "metadata": {}, "outputs": [], "source": [ - "from primaite.simulator.network.hardware.base import Node\n" + "from primaite.simulator.network.hardware.nodes.host.computer import Computer\n", + "from primaite.simulator.network.hardware.nodes.host.server import Server" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 122, "metadata": {}, "outputs": [], "source": [ - "my_pc = Node(hostname=\"primaite_pc\",)\n", + "my_pc = Computer(hostname=\"primaite_pc\", ip_address=\"192.168.1.10\", subnet_mask=\"255.255.255.0\")\n", "net.add_node(my_pc)\n", - "my_server = Node(hostname=\"google_server\")\n", + "my_server = Server(hostname=\"google_server\", ip_address=\"192.168.1.11\", subnet_mask=\"255.255.255.0\")\n", "net.add_node(my_server)\n" ] }, @@ -82,32 +98,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 123, "metadata": {}, "outputs": [], "source": [ - "from primaite.simulator.network.hardware.base import NIC, Link, Switch\n" + "from primaite.simulator.network.hardware.nodes.host.host_node import NIC\n", + "from primaite.simulator.network.hardware.nodes.network.switch import Switch\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 124, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Link(uuid='42b8f911-3640-4ccb-b277-b48b294a1fc8', endpoint_a=NIC(ip_address=IPv4Address('130.1.1.2'), subnet_mask=IPv4Address('255.255.255.0'), uuid='53993d8f-216e-4c00-9b03-c6bb9e2437b5', mac_address='17:9d:82:db:ca:c8', speed=100, mtu=1500, enabled=False, port_num=2, port_name=None, pcap=None, nmne={}, wake_on_lan=False, gateway='130.1.1.255'), endpoint_b=SwitchPort(uuid='c03d4d22-f309-49b6-a1ad-45a04c40d25e', mac_address='84:01:f3:bb:47:1c', speed=100, mtu=1500, enabled=False, port_num=2, port_name=None, pcap=None, nmne={}), bandwidth=100.0, current_load=0.0)" + ] + }, + "execution_count": 124, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "my_swtich = Switch(hostname=\"switch1\", num_ports=12)\n", - "net.add_node(my_swtich)\n", + "my_switch = Switch(hostname=\"switch1\", num_ports=12)\n", + "net.add_node(my_switch)\n", "\n", "pc_nic = NIC(ip_address=\"130.1.1.1\", gateway=\"130.1.1.255\", subnet_mask=\"255.255.255.0\")\n", "my_pc.connect_nic(pc_nic)\n", "\n", - "\n", "server_nic = NIC(ip_address=\"130.1.1.2\", gateway=\"130.1.1.255\", subnet_mask=\"255.255.255.0\")\n", "my_server.connect_nic(server_nic)\n", "\n", - "\n", - "net.connect(pc_nic, my_swtich.switch_ports[1])\n", - "net.connect(server_nic, my_swtich.switch_ports[2])\n" + "net.connect(pc_nic, my_switch.network_interface[1])\n", + "net.connect(server_nic, my_switch.network_interface[2])\n" ] }, { @@ -119,29 +145,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 125, "metadata": {}, "outputs": [], "source": [ "from primaite.simulator.file_system.file_type import FileType\n", - "from primaite.simulator.file_system.file_system import File" + "from primaite.simulator.file_system.file_system import File\n", + "from primaite.simulator.system.core.sys_log import SysLog" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 126, "metadata": {}, "outputs": [], "source": [ "my_pc_downloads_folder = my_pc.file_system.create_folder(\"downloads\")\n", - "my_pc_downloads_folder.add_file(File(name=\"firefox_installer.zip\",file_type=FileType.ZIP))" + "my_pc_downloads_folder.add_file(File(name=\"firefox_installer.zip\",folder_id=\"Test\", folder_name=\"downloads\" ,file_type=FileType.ZIP, sys_log=SysLog(hostname=\"Test\")))" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 127, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "File(uuid='24789051-6762-48f4-8a56-c28882374273', name='favicon.ico', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='7a86576b-607f-468b-826f-4834cf2b3511', folder_name='root', file_type=, sim_size=0, real=False, sim_path=None, sim_root=WindowsPath('C:/Projects/PrimAITE/simulation_output/2024-04-08_12-19-36/google_server/fs'), num_access=0, folder=Folder(uuid='7a86576b-607f-468b-826f-4834cf2b3511', name='root', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={'24789051-6762-48f4-8a56-c28882374273': File(uuid='24789051-6762-48f4-8a56-c28882374273', name='favicon.ico', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='7a86576b-607f-468b-826f-4834cf2b3511', folder_name='root', file_type=, sim_size=0, real=False, sim_path=None, sim_root=WindowsPath('C:/Projects/PrimAITE/simulation_output/2024-04-08_12-19-36/google_server/fs'), num_access=0, folder=Folder(uuid='7a86576b-607f-468b-826f-4834cf2b3511', name='root', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={}, scan_duration=3, scan_countdown=0, red_scan_duration=3, red_scan_countdown=0, restore_duration=3, restore_countdown=0))}, deleted_files={}, scan_duration=3, scan_countdown=0, red_scan_duration=3, red_scan_countdown=0, restore_duration=3, restore_countdown=0))" + ] + }, + "execution_count": 127, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_server_folder = my_server.file_system.create_folder(\"static\")\n", "my_server.file_system.create_file(\"favicon.ico\", file_type=FileType.PNG)" @@ -156,13 +194,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 128, "metadata": {}, "outputs": [], "source": [ "from primaite.simulator.system.applications.application import Application, ApplicationOperatingState\n", "from primaite.simulator.system.software import SoftwareHealthState, SoftwareCriticality\n", "from primaite.simulator.network.transmission.transport_layer import Port\n", + "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", + "from primaite.simulator.file_system.file_system import FileSystem\n", + "from pathlib import Path\n", "\n", "# no applications exist yet so we will create our own.\n", "class MSPaint(Application):\n", @@ -172,16 +213,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 129, "metadata": {}, "outputs": [], "source": [ - "mspaint = MSPaint(name = \"mspaint\", health_state_actual=SoftwareHealthState.GOOD, health_state_visible=SoftwareHealthState.GOOD, criticality=SoftwareCriticality.MEDIUM, ports={Port.HTTP}, operating_state=ApplicationOperatingState.RUNNING,execution_control_status='manual')" + "mspaint = MSPaint(name = \"mspaint\", health_state_actual=SoftwareHealthState.GOOD, health_state_visible=SoftwareHealthState.GOOD, criticality=SoftwareCriticality.MEDIUM, port=Port.HTTP, protocol = IPProtocol.NONE,operating_state=ApplicationOperatingState.RUNNING,execution_control_status='manual', file_system=FileSystem(sys_log=SysLog(hostname=\"Test\"), sim_root=Path(__name__).parent),)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 130, "metadata": {}, "outputs": [], "source": [ @@ -197,7 +238,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 131, "metadata": {}, "outputs": [], "source": [ @@ -206,7 +247,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 132, "metadata": {}, "outputs": [], "source": [ @@ -223,18 +264,515 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 133, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'uuid': '42d005b2-4dc8-4aec-be54-3493242eee32',\n", + " 'network': {'uuid': '069f61a4-ac40-431f-ad13-2fc9b26dc091',\n", + " 'nodes': {'primaite_pc': {'uuid': '52246eed-9a3f-4b19-ad0c-48fc3bbb998d',\n", + " 'hostname': 'primaite_pc',\n", + " 'operating_state': 2,\n", + " 'NICs': {1: {'uuid': '73dcb42e-7db4-45cf-b439-9b8066c8e32e',\n", + " 'mac_address': 'c9:84:ec:48:87:77',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {},\n", + " 'ip_address': '192.168.1.10',\n", + " 'subnet_mask': '255.255.255.0',\n", + " 'wake_on_lan': False},\n", + " 2: {'uuid': 'e0fbda66-afcb-4a79-b696-aad0778279a2',\n", + " 'mac_address': 'cb:66:8b:b2:dc:51',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {},\n", + " 'ip_address': '130.1.1.1',\n", + " 'subnet_mask': '255.255.255.0',\n", + " 'wake_on_lan': False}},\n", + " 'file_system': {'uuid': '8a857927-dd5e-40e9-86fd-1df8b3a2b463',\n", + " 'folders': {'root': {'uuid': 'acb725c9-461e-40c5-b2c0-ed198865e1f2',\n", + " 'name': 'root',\n", + " 'health_status': 1,\n", + " 'visible_status': 1,\n", + " 'previous_hash': None,\n", + " 'revealed_to_red': False,\n", + " 'files': {},\n", + " 'deleted_files': {}},\n", + " 'downloads': {'uuid': '484f7bcf-b8da-4995-8538-82b2a4d059c7',\n", + " 'name': 'downloads',\n", + " 'health_status': 1,\n", + " 'visible_status': 1,\n", + " 'previous_hash': None,\n", + " 'revealed_to_red': False,\n", + " 'files': {'firefox_installer.zip': {'uuid': '5e1e5bec-a984-4ae1-9799-78083bd2e3c2',\n", + " 'name': 'firefox_installer.zip',\n", + " 'health_status': 1,\n", + " 'visible_status': 1,\n", + " 'previous_hash': None,\n", + " 'revealed_to_red': False,\n", + " 'size': 1024000,\n", + " 'file_type': 'ZIP',\n", + " 'num_access': 0}},\n", + " 'deleted_files': {}}},\n", + " 'deleted_folders': {},\n", + " 'num_file_creations': 0,\n", + " 'num_file_deletions': 0},\n", + " 'applications': {'WebBrowser': {'uuid': '5987fc38-686d-439f-b513-23166884596e',\n", + " 'health_state_actual': 0,\n", + " 'health_state_visible': 0,\n", + " 'criticality': 1,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 80,\n", + " 'operating_state': 2,\n", + " 'execution_control_status': 'manual',\n", + " 'num_executions': 0,\n", + " 'groups': [],\n", + " 'history': []},\n", + " 'mspaint': {'uuid': '88eb36c5-dba4-4f79-ad95-5957f7de3fa2',\n", + " 'health_state_actual': 1,\n", + " 'health_state_visible': 1,\n", + " 'criticality': 3,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 80,\n", + " 'operating_state': 1,\n", + " 'execution_control_status': 'manual',\n", + " 'num_executions': 0,\n", + " 'groups': []}},\n", + " 'services': {'ARP': {'uuid': 'e220dde6-88d5-4e24-a2de-5bce0cd4a916',\n", + " 'health_state_actual': 0,\n", + " 'health_state_visible': 0,\n", + " 'criticality': 1,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 219,\n", + " 'operating_state': 2},\n", + " 'ICMP': {'uuid': 'ef728c73-97b7-480f-bedb-04dc3d5efd57',\n", + " 'health_state_actual': 0,\n", + " 'health_state_visible': 0,\n", + " 'criticality': 1,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 0,\n", + " 'operating_state': 2},\n", + " 'DNSClient': {'uuid': '30b159f1-a4e8-41f5-923b-c692d104f385',\n", + " 'health_state_actual': 0,\n", + " 'health_state_visible': 0,\n", + " 'criticality': 1,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 53,\n", + " 'operating_state': 2},\n", + " 'FTPClient': {'uuid': '5f267d5f-6bb8-4e97-b6b9-855ee2d50c25',\n", + " 'health_state_actual': 0,\n", + " 'health_state_visible': 0,\n", + " 'criticality': 1,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 21,\n", + " 'operating_state': 2},\n", + " 'NTPClient': {'uuid': '1ea99f1e-dc04-4548-a384-913851a7e4fd',\n", + " 'health_state_actual': 0,\n", + " 'health_state_visible': 0,\n", + " 'criticality': 1,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 123,\n", + " 'operating_state': 2}},\n", + " 'process': {},\n", + " 'revealed_to_red': False},\n", + " 'google_server': {'uuid': 'b9a41d9c-6642-441b-8049-8302ddafd3b1',\n", + " 'hostname': 'google_server',\n", + " 'operating_state': 2,\n", + " 'NICs': {1: {'uuid': 'd0736beb-085a-4754-8b44-de73e6a8c80f',\n", + " 'mac_address': '45:27:ed:64:ac:09',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {},\n", + " 'ip_address': '192.168.1.11',\n", + " 'subnet_mask': '255.255.255.0',\n", + " 'wake_on_lan': False},\n", + " 2: {'uuid': '53993d8f-216e-4c00-9b03-c6bb9e2437b5',\n", + " 'mac_address': '17:9d:82:db:ca:c8',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {},\n", + " 'ip_address': '130.1.1.2',\n", + " 'subnet_mask': '255.255.255.0',\n", + " 'wake_on_lan': False}},\n", + " 'file_system': {'uuid': '8d4ded3a-56bb-46f0-ad7f-40d65b523581',\n", + " 'folders': {'root': {'uuid': '7a86576b-607f-468b-826f-4834cf2b3511',\n", + " 'name': 'root',\n", + " 'health_status': 1,\n", + " 'visible_status': 1,\n", + " 'previous_hash': None,\n", + " 'revealed_to_red': False,\n", + " 'files': {'favicon.ico': {'uuid': '24789051-6762-48f4-8a56-c28882374273',\n", + " 'name': 'favicon.ico',\n", + " 'health_status': 1,\n", + " 'visible_status': 1,\n", + " 'previous_hash': None,\n", + " 'revealed_to_red': False,\n", + " 'size': 0,\n", + " 'file_type': 'UNKNOWN',\n", + " 'num_access': 0}},\n", + " 'deleted_files': {}},\n", + " 'static': {'uuid': '154b2ad3-e43d-4924-b758-e11db0e176de',\n", + " 'name': 'static',\n", + " 'health_status': 1,\n", + " 'visible_status': 1,\n", + " 'previous_hash': None,\n", + " 'revealed_to_red': False,\n", + " 'files': {},\n", + " 'deleted_files': {}}},\n", + " 'deleted_folders': {},\n", + " 'num_file_creations': 1,\n", + " 'num_file_deletions': 0},\n", + " 'applications': {'WebBrowser': {'uuid': '9b368321-e22d-4e35-9395-80632492c20a',\n", + " 'health_state_actual': 0,\n", + " 'health_state_visible': 0,\n", + " 'criticality': 1,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 80,\n", + " 'operating_state': 2,\n", + " 'execution_control_status': 'manual',\n", + " 'num_executions': 0,\n", + " 'groups': [],\n", + " 'history': []}},\n", + " 'services': {'ARP': {'uuid': '30df82c0-5823-4464-8c23-5b99922f98f7',\n", + " 'health_state_actual': 0,\n", + " 'health_state_visible': 0,\n", + " 'criticality': 1,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 219,\n", + " 'operating_state': 2},\n", + " 'ICMP': {'uuid': '2d02a2de-7ec8-4da1-9538-c85eb397d4e3',\n", + " 'health_state_actual': 0,\n", + " 'health_state_visible': 0,\n", + " 'criticality': 1,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 0,\n", + " 'operating_state': 2},\n", + " 'DNSClient': {'uuid': 'db979263-ff81-4a04-95e8-d94442e9ddfa',\n", + " 'health_state_actual': 0,\n", + " 'health_state_visible': 0,\n", + " 'criticality': 1,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 53,\n", + " 'operating_state': 2},\n", + " 'FTPClient': {'uuid': 'd9d6417b-d1e0-416b-a711-3478fa248194',\n", + " 'health_state_actual': 0,\n", + " 'health_state_visible': 0,\n", + " 'criticality': 1,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 21,\n", + " 'operating_state': 2},\n", + " 'NTPClient': {'uuid': 'b23a1032-a817-492b-bdd6-2ecc6fb4591c',\n", + " 'health_state_actual': 0,\n", + " 'health_state_visible': 0,\n", + " 'criticality': 1,\n", + " 'fixing_count': 0,\n", + " 'scanning_count': 0,\n", + " 'revealed_to_red': False,\n", + " 'installing_count': 0,\n", + " 'max_sessions': 100,\n", + " 'tcp': True,\n", + " 'udp': True,\n", + " 'port': 123,\n", + " 'operating_state': 2}},\n", + " 'process': {},\n", + " 'revealed_to_red': False},\n", + " 'switch1': {'uuid': 'e658eac3-c4b8-4768-bf27-e2d90b7f57c0',\n", + " 'hostname': 'switch1',\n", + " 'operating_state': 2,\n", + " 'NICs': {1: {'uuid': '7ebc80f5-902f-4253-8ea6-0cafa3d1cccd',\n", + " 'mac_address': 'df:d2:c7:2a:a1:52',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 2: {'uuid': 'c03d4d22-f309-49b6-a1ad-45a04c40d25e',\n", + " 'mac_address': '84:01:f3:bb:47:1c',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 3: {'uuid': '4207353c-e0cd-456d-89fe-13ddfc605cff',\n", + " 'mac_address': '8b:31:ac:cc:05:c9',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 4: {'uuid': '8aa1395f-e360-48a7-be97-ed1a5ca191ae',\n", + " 'mac_address': '75:3c:ae:bd:3a:b5',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 5: {'uuid': '8b5d575c-ab0c-43ac-abfc-fa5ae75183e5',\n", + " 'mac_address': 'e7:7f:c4:af:8e:5b',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 6: {'uuid': '9d3cd584-f684-4f2e-9c8a-423d859fe3d3',\n", + " 'mac_address': '48:cf:18:8d:92:80',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 7: {'uuid': 'd42338bb-d579-483d-9e05-0318e17e574a',\n", + " 'mac_address': 'c6:99:5c:41:13:d7',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 8: {'uuid': '55bbd70b-491d-4452-8326-390ec3fadc28',\n", + " 'mac_address': '81:ab:39:0c:a2:dd',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 9: {'uuid': '0755d768-79c7-48cf-9220-d2dad32e574b',\n", + " 'mac_address': '62:35:0c:5e:cc:5d',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 10: {'uuid': 'deaecc57-ec76-4e27-a37e-f66964901b03',\n", + " 'mac_address': '51:26:00:c6:7e:ac',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 11: {'uuid': '53fe318c-4969-42fe-920b-37a491f54d84',\n", + " 'mac_address': '35:59:c7:13:ab:a5',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 12: {'uuid': '5a81caa0-9d91-4a86-9bd4-4ecb589c70ae',\n", + " 'mac_address': '7a:6b:ec:15:1e:de',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}}},\n", + " 'file_system': {'uuid': '289bea1e-69bf-44d5-80fe-212dad8afcd5',\n", + " 'folders': {'root': {'uuid': '3b588b3c-bc4a-4c06-a688-eced0128b128',\n", + " 'name': 'root',\n", + " 'health_status': 1,\n", + " 'visible_status': 1,\n", + " 'previous_hash': None,\n", + " 'revealed_to_red': False,\n", + " 'files': {},\n", + " 'deleted_files': {}}},\n", + " 'deleted_folders': {},\n", + " 'num_file_creations': 0,\n", + " 'num_file_deletions': 0},\n", + " 'applications': {},\n", + " 'services': {},\n", + " 'process': {},\n", + " 'revealed_to_red': False,\n", + " 'ports': {1: {'uuid': '7ebc80f5-902f-4253-8ea6-0cafa3d1cccd',\n", + " 'mac_address': 'df:d2:c7:2a:a1:52',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 2: {'uuid': 'c03d4d22-f309-49b6-a1ad-45a04c40d25e',\n", + " 'mac_address': '84:01:f3:bb:47:1c',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 3: {'uuid': '4207353c-e0cd-456d-89fe-13ddfc605cff',\n", + " 'mac_address': '8b:31:ac:cc:05:c9',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 4: {'uuid': '8aa1395f-e360-48a7-be97-ed1a5ca191ae',\n", + " 'mac_address': '75:3c:ae:bd:3a:b5',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 5: {'uuid': '8b5d575c-ab0c-43ac-abfc-fa5ae75183e5',\n", + " 'mac_address': 'e7:7f:c4:af:8e:5b',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 6: {'uuid': '9d3cd584-f684-4f2e-9c8a-423d859fe3d3',\n", + " 'mac_address': '48:cf:18:8d:92:80',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 7: {'uuid': 'd42338bb-d579-483d-9e05-0318e17e574a',\n", + " 'mac_address': 'c6:99:5c:41:13:d7',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 8: {'uuid': '55bbd70b-491d-4452-8326-390ec3fadc28',\n", + " 'mac_address': '81:ab:39:0c:a2:dd',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 9: {'uuid': '0755d768-79c7-48cf-9220-d2dad32e574b',\n", + " 'mac_address': '62:35:0c:5e:cc:5d',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 10: {'uuid': 'deaecc57-ec76-4e27-a37e-f66964901b03',\n", + " 'mac_address': '51:26:00:c6:7e:ac',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 11: {'uuid': '53fe318c-4969-42fe-920b-37a491f54d84',\n", + " 'mac_address': '35:59:c7:13:ab:a5',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}},\n", + " 12: {'uuid': '5a81caa0-9d91-4a86-9bd4-4ecb589c70ae',\n", + " 'mac_address': '7a:6b:ec:15:1e:de',\n", + " 'speed': 100,\n", + " 'mtu': 1500,\n", + " 'enabled': False,\n", + " 'nmne': {}}},\n", + " 'num_ports': 12,\n", + " 'mac_address_table': {}}},\n", + " 'links': {'primaite_pc:eth-2<->switch1:eth-1': {'uuid': '3d053257-7473-4a66-afbc-ee33a18f2e39',\n", + " 'endpoint_a': 'e0fbda66-afcb-4a79-b696-aad0778279a2',\n", + " 'endpoint_b': '7ebc80f5-902f-4253-8ea6-0cafa3d1cccd',\n", + " 'bandwidth': 100.0,\n", + " 'current_load': 0.0,\n", + " 'hostname_a': 'primaite_pc',\n", + " 'hostname_b': 'switch1',\n", + " 'port_a': 2,\n", + " 'port_b': 1},\n", + " 'google_server:eth-2<->switch1:eth-2': {'uuid': '42b8f911-3640-4ccb-b277-b48b294a1fc8',\n", + " 'endpoint_a': '53993d8f-216e-4c00-9b03-c6bb9e2437b5',\n", + " 'endpoint_b': 'c03d4d22-f309-49b6-a1ad-45a04c40d25e',\n", + " 'bandwidth': 100.0,\n", + " 'current_load': 0.0,\n", + " 'hostname_a': 'google_server',\n", + " 'hostname_b': 'switch1',\n", + " 'port_a': 2,\n", + " 'port_b': 2}}},\n", + " 'domain': {'uuid': 'f0629156-e9af-493d-b098-f47d73126122',\n", + " 'accounts': {'admin': {'uuid': 'b76653a9-d40e-483b-85a3-1b44628a11d0',\n", + " 'num_logons': 0,\n", + " 'num_logoffs': 0,\n", + " 'num_group_changes': 0,\n", + " 'username': 'admin',\n", + " 'password': 'admin12',\n", + " 'account_type': 2,\n", + " 'enabled': True}}}}" + ] + }, + "execution_count": 133, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_sim.describe_state()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 134, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'{\"uuid\": \"42d005b2-4dc8-4aec-be54-3493242eee32\", \"network\": {\"uuid\": \"069f61a4-ac40-431f-ad13-2fc9b26dc091\", \"nodes\": {\"primaite_pc\": {\"uuid\": \"52246eed-9a3f-4b19-ad0c-48fc3bbb998d\", \"hostname\": \"primaite_pc\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"73dcb42e-7db4-45cf-b439-9b8066c8e32e\", \"mac_address\": \"c9:84:ec:48:87:77\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"192.168.1.10\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}, \"2\": {\"uuid\": \"e0fbda66-afcb-4a79-b696-aad0778279a2\", \"mac_address\": \"cb:66:8b:b2:dc:51\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}}, \"file_system\": {\"uuid\": \"8a857927-dd5e-40e9-86fd-1df8b3a2b463\", \"folders\": {\"root\": {\"uuid\": \"acb725c9-461e-40c5-b2c0-ed198865e1f2\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}, \"downloads\": {\"uuid\": \"484f7bcf-b8da-4995-8538-82b2a4d059c7\", \"name\": \"downloads\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {\"firefox_installer.zip\": {\"uuid\": \"5e1e5bec-a984-4ae1-9799-78083bd2e3c2\", \"name\": \"firefox_installer.zip\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"size\": 1024000, \"file_type\": \"ZIP\", \"num_access\": 0}}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 0, \"num_file_deletions\": 0}, \"applications\": {\"WebBrowser\": {\"uuid\": \"5987fc38-686d-439f-b513-23166884596e\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 2, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": [], \"history\": []}, \"mspaint\": {\"uuid\": \"88eb36c5-dba4-4f79-ad95-5957f7de3fa2\", \"health_state_actual\": 1, \"health_state_visible\": 1, \"criticality\": 3, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 1, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {\"ARP\": {\"uuid\": \"e220dde6-88d5-4e24-a2de-5bce0cd4a916\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 219, \"operating_state\": 2}, \"ICMP\": {\"uuid\": \"ef728c73-97b7-480f-bedb-04dc3d5efd57\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 0, \"operating_state\": 2}, \"DNSClient\": {\"uuid\": \"30b159f1-a4e8-41f5-923b-c692d104f385\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 53, \"operating_state\": 2}, \"FTPClient\": {\"uuid\": \"5f267d5f-6bb8-4e97-b6b9-855ee2d50c25\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 21, \"operating_state\": 2}, \"NTPClient\": {\"uuid\": \"1ea99f1e-dc04-4548-a384-913851a7e4fd\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 123, \"operating_state\": 2}}, \"process\": {}, \"revealed_to_red\": false}, \"google_server\": {\"uuid\": \"b9a41d9c-6642-441b-8049-8302ddafd3b1\", \"hostname\": \"google_server\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"d0736beb-085a-4754-8b44-de73e6a8c80f\", \"mac_address\": \"45:27:ed:64:ac:09\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"192.168.1.11\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}, \"2\": {\"uuid\": \"53993d8f-216e-4c00-9b03-c6bb9e2437b5\", \"mac_address\": \"17:9d:82:db:ca:c8\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}}, \"file_system\": {\"uuid\": \"8d4ded3a-56bb-46f0-ad7f-40d65b523581\", \"folders\": {\"root\": {\"uuid\": \"7a86576b-607f-468b-826f-4834cf2b3511\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {\"favicon.ico\": {\"uuid\": \"24789051-6762-48f4-8a56-c28882374273\", \"name\": \"favicon.ico\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"size\": 0, \"file_type\": \"UNKNOWN\", \"num_access\": 0}}, \"deleted_files\": {}}, \"static\": {\"uuid\": \"154b2ad3-e43d-4924-b758-e11db0e176de\", \"name\": \"static\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 1, \"num_file_deletions\": 0}, \"applications\": {\"WebBrowser\": {\"uuid\": \"9b368321-e22d-4e35-9395-80632492c20a\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 2, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": [], \"history\": []}}, \"services\": {\"ARP\": {\"uuid\": \"30df82c0-5823-4464-8c23-5b99922f98f7\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 219, \"operating_state\": 2}, \"ICMP\": {\"uuid\": \"2d02a2de-7ec8-4da1-9538-c85eb397d4e3\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 0, \"operating_state\": 2}, \"DNSClient\": {\"uuid\": \"db979263-ff81-4a04-95e8-d94442e9ddfa\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 53, \"operating_state\": 2}, \"FTPClient\": {\"uuid\": \"d9d6417b-d1e0-416b-a711-3478fa248194\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 21, \"operating_state\": 2}, \"NTPClient\": {\"uuid\": \"b23a1032-a817-492b-bdd6-2ecc6fb4591c\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 123, \"operating_state\": 2}}, \"process\": {}, \"revealed_to_red\": false}, \"switch1\": {\"uuid\": \"e658eac3-c4b8-4768-bf27-e2d90b7f57c0\", \"hostname\": \"switch1\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"7ebc80f5-902f-4253-8ea6-0cafa3d1cccd\", \"mac_address\": \"df:d2:c7:2a:a1:52\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"2\": {\"uuid\": \"c03d4d22-f309-49b6-a1ad-45a04c40d25e\", \"mac_address\": \"84:01:f3:bb:47:1c\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"3\": {\"uuid\": \"4207353c-e0cd-456d-89fe-13ddfc605cff\", \"mac_address\": \"8b:31:ac:cc:05:c9\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"4\": {\"uuid\": \"8aa1395f-e360-48a7-be97-ed1a5ca191ae\", \"mac_address\": \"75:3c:ae:bd:3a:b5\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"5\": {\"uuid\": \"8b5d575c-ab0c-43ac-abfc-fa5ae75183e5\", \"mac_address\": \"e7:7f:c4:af:8e:5b\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"6\": {\"uuid\": \"9d3cd584-f684-4f2e-9c8a-423d859fe3d3\", \"mac_address\": \"48:cf:18:8d:92:80\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"7\": {\"uuid\": \"d42338bb-d579-483d-9e05-0318e17e574a\", \"mac_address\": \"c6:99:5c:41:13:d7\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"8\": {\"uuid\": \"55bbd70b-491d-4452-8326-390ec3fadc28\", \"mac_address\": \"81:ab:39:0c:a2:dd\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"9\": {\"uuid\": \"0755d768-79c7-48cf-9220-d2dad32e574b\", \"mac_address\": \"62:35:0c:5e:cc:5d\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"10\": {\"uuid\": \"deaecc57-ec76-4e27-a37e-f66964901b03\", \"mac_address\": \"51:26:00:c6:7e:ac\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"11\": {\"uuid\": \"53fe318c-4969-42fe-920b-37a491f54d84\", \"mac_address\": \"35:59:c7:13:ab:a5\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"12\": {\"uuid\": \"5a81caa0-9d91-4a86-9bd4-4ecb589c70ae\", \"mac_address\": \"7a:6b:ec:15:1e:de\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}}, \"file_system\": {\"uuid\": \"289bea1e-69bf-44d5-80fe-212dad8afcd5\", \"folders\": {\"root\": {\"uuid\": \"3b588b3c-bc4a-4c06-a688-eced0128b128\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 0, \"num_file_deletions\": 0}, \"applications\": {}, \"services\": {}, \"process\": {}, \"revealed_to_red\": false, \"ports\": {\"1\": {\"uuid\": \"7ebc80f5-902f-4253-8ea6-0cafa3d1cccd\", \"mac_address\": \"df:d2:c7:2a:a1:52\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"2\": {\"uuid\": \"c03d4d22-f309-49b6-a1ad-45a04c40d25e\", \"mac_address\": \"84:01:f3:bb:47:1c\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"3\": {\"uuid\": \"4207353c-e0cd-456d-89fe-13ddfc605cff\", \"mac_address\": \"8b:31:ac:cc:05:c9\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"4\": {\"uuid\": \"8aa1395f-e360-48a7-be97-ed1a5ca191ae\", \"mac_address\": \"75:3c:ae:bd:3a:b5\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"5\": {\"uuid\": \"8b5d575c-ab0c-43ac-abfc-fa5ae75183e5\", \"mac_address\": \"e7:7f:c4:af:8e:5b\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"6\": {\"uuid\": \"9d3cd584-f684-4f2e-9c8a-423d859fe3d3\", \"mac_address\": \"48:cf:18:8d:92:80\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"7\": {\"uuid\": \"d42338bb-d579-483d-9e05-0318e17e574a\", \"mac_address\": \"c6:99:5c:41:13:d7\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"8\": {\"uuid\": \"55bbd70b-491d-4452-8326-390ec3fadc28\", \"mac_address\": \"81:ab:39:0c:a2:dd\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"9\": {\"uuid\": \"0755d768-79c7-48cf-9220-d2dad32e574b\", \"mac_address\": \"62:35:0c:5e:cc:5d\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"10\": {\"uuid\": \"deaecc57-ec76-4e27-a37e-f66964901b03\", \"mac_address\": \"51:26:00:c6:7e:ac\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"11\": {\"uuid\": \"53fe318c-4969-42fe-920b-37a491f54d84\", \"mac_address\": \"35:59:c7:13:ab:a5\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"12\": {\"uuid\": \"5a81caa0-9d91-4a86-9bd4-4ecb589c70ae\", \"mac_address\": \"7a:6b:ec:15:1e:de\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}}, \"num_ports\": 12, \"mac_address_table\": {}}}, \"links\": {\"primaite_pc:eth-2<->switch1:eth-1\": {\"uuid\": \"3d053257-7473-4a66-afbc-ee33a18f2e39\", \"endpoint_a\": \"e0fbda66-afcb-4a79-b696-aad0778279a2\", \"endpoint_b\": \"7ebc80f5-902f-4253-8ea6-0cafa3d1cccd\", \"bandwidth\": 100.0, \"current_load\": 0.0, \"hostname_a\": \"primaite_pc\", \"hostname_b\": \"switch1\", \"port_a\": 2, \"port_b\": 1}, \"google_server:eth-2<->switch1:eth-2\": {\"uuid\": \"42b8f911-3640-4ccb-b277-b48b294a1fc8\", \"endpoint_a\": \"53993d8f-216e-4c00-9b03-c6bb9e2437b5\", \"endpoint_b\": \"c03d4d22-f309-49b6-a1ad-45a04c40d25e\", \"bandwidth\": 100.0, \"current_load\": 0.0, \"hostname_a\": \"google_server\", \"hostname_b\": \"switch1\", \"port_a\": 2, \"port_b\": 2}}}, \"domain\": {\"uuid\": \"f0629156-e9af-493d-b098-f47d73126122\", \"accounts\": {\"admin\": {\"uuid\": \"b76653a9-d40e-483b-85a3-1b44628a11d0\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": 2, \"enabled\": true}}}}'" + ] + }, + "execution_count": 134, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import json\n", "json.dumps(my_sim.describe_state())" @@ -257,7 +795,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.10.11" }, "orig_nbformat": 4 }, diff --git a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb index b537f54b..47703c9c 100644 --- a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb +++ b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb @@ -59,7 +59,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "de57ac8c-5b28-4847-a759-2ceaf5593329", "metadata": { "tags": [] @@ -71,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "a1e2e4df-67c0-4584-ab27-47e2c7c7fcd2", "metadata": { "tags": [] @@ -91,12 +91,70 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "cc199741-ef2e-47f5-b2f0-e20049ccf40f", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+------------------------------------------------+\n", + "| Nodes |\n", + "+-------------------+----------+-----------------+\n", + "| Node | Type | Operating State |\n", + "+-------------------+----------+-----------------+\n", + "| router_1 | Router | ON |\n", + "| switch_1 | Switch | ON |\n", + "| switch_2 | Switch | ON |\n", + "| domain_controller | Server | ON |\n", + "| database_server | Server | ON |\n", + "| web_server | Server | ON |\n", + "| backup_server | Server | ON |\n", + "| security_suite | Server | ON |\n", + "| client_1 | Computer | ON |\n", + "| client_2 | Computer | ON |\n", + "+-------------------+----------+-----------------+\n", + "+-----------------------------------------------------------------------------+\n", + "| IP Addresses |\n", + "+-------------------+------+----------------+---------------+-----------------+\n", + "| Node | Port | IP Address | Subnet Mask | Default Gateway |\n", + "+-------------------+------+----------------+---------------+-----------------+\n", + "| router_1 | 1 | 192.168.1.1 | 255.255.255.0 | None |\n", + "| router_1 | 2 | 192.168.10.1 | 255.255.255.0 | None |\n", + "| router_1 | 3 | 127.0.0.1 | 255.0.0.0 | None |\n", + "| router_1 | 4 | 127.0.0.1 | 255.0.0.0 | None |\n", + "| router_1 | 5 | 127.0.0.1 | 255.0.0.0 | None |\n", + "| domain_controller | 1 | 192.168.1.10 | 255.255.255.0 | 192.168.1.1 |\n", + "| database_server | 1 | 192.168.1.14 | 255.255.255.0 | 192.168.1.1 |\n", + "| web_server | 1 | 192.168.1.12 | 255.255.255.0 | 192.168.1.1 |\n", + "| backup_server | 1 | 192.168.1.16 | 255.255.255.0 | 192.168.1.1 |\n", + "| security_suite | 1 | 192.168.1.110 | 255.255.255.0 | 192.168.1.1 |\n", + "| security_suite | 2 | 192.168.10.110 | 255.255.255.0 | 192.168.1.1 |\n", + "| client_1 | 1 | 192.168.10.21 | 255.255.255.0 | 192.168.10.1 |\n", + "| client_2 | 1 | 192.168.10.22 | 255.255.255.0 | 192.168.10.1 |\n", + "+-------------------+------+----------------+---------------+-----------------+\n", + "+---------------------------------------------------------------------------------------------------------------------------------------------------------------+\n", + "| Links |\n", + "+------------+----------------------------------------+-------------------+------------------------------------------+-------+-------------------+--------------+\n", + "| Endpoint A | A Port | Endpoint B | B Port | is Up | Bandwidth (MBits) | Current Load |\n", + "+------------+----------------------------------------+-------------------+------------------------------------------+-------+-------------------+--------------+\n", + "| router_1 | Port 2: eb:31:e8:11:28:ac/192.168.10.1 | switch_2 | Port 8: d3:59:e2:73:4e:b8 | True | 100.0 | 0.00006% |\n", + "| router_1 | Port 1: 3f:c3:3d:00:74:c4/192.168.1.1 | switch_1 | Port 8: a9:ea:54:9f:35:f8 | True | 100.0 | 0.00018% |\n", + "| switch_1 | Port 7: 63:ea:45:e6:f4:22 | security_suite | Port 1: 18:9d:a1:f0:6f:0b/192.168.1.110 | True | 100.0 | 0.00003% |\n", + "| switch_1 | Port 4: 08:0e:a9:03:d7:3c | backup_server | Port 1: c3:e5:81:c9:8b:74/192.168.1.16 | True | 100.0 | 0.00003% |\n", + "| switch_1 | Port 2: 75:c5:30:0f:5d:92 | web_server | Port 1: 90:94:52:a6:1f:c5/192.168.1.12 | True | 100.0 | 0.00015% |\n", + "| switch_1 | Port 3: f1:62:75:5d:d9:59 | database_server | Port 1: 2e:e8:cb:a5:97:12/192.168.1.14 | True | 100.0 | 0.00017% |\n", + "| switch_1 | Port 1: 08:79:a7:3f:b5:96 | domain_controller | Port 1: 00:c3:ff:62:87:8f/192.168.1.10 | True | 100.0 | 0.00003% |\n", + "| switch_2 | Port 7: 88:9c:57:5c:53:5e | security_suite | Port 2: 9e:b2:c8:04:d8:97/192.168.10.110 | True | 100.0 | 0.00000% |\n", + "| switch_2 | Port 2: a8:1b:b2:78:12:34 | client_2 | Port 1: 6a:b1:ff:36:ef:40/192.168.10.22 | True | 100.0 | 0.00003% |\n", + "| switch_2 | Port 1: 42:08:3f:1e:ea:dd | client_1 | Port 1: f6:6d:35:8a:67:d8/192.168.10.21 | True | 100.0 | 0.00003% |\n", + "+------------+----------------------------------------+-------------------+------------------------------------------+-------+-------------------+--------------+\n" + ] + } + ], "source": [ "network.show()" ] @@ -133,12 +191,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "e76d1854-961e-438c-b40f-77fd9c3abe38", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+---------------------------------------------------------------+\n", + "| router_1 Network Interfaces |\n", + "+------+-------------------+-----------------+-------+----------+\n", + "| Port | MAC Address | Address | Speed | Status |\n", + "+------+-------------------+-----------------+-------+----------+\n", + "| 1 | 3f:c3:3d:00:74:c4 | 192.168.1.1/24 | 100 | Enabled |\n", + "| 2 | eb:31:e8:11:28:ac | 192.168.10.1/24 | 100 | Enabled |\n", + "| 3 | 7b:4f:23:8d:b5:18 | 127.0.0.1/8 | 100 | Disabled |\n", + "| 4 | cd:89:ba:42:ee:04 | 127.0.0.1/8 | 100 | Disabled |\n", + "| 5 | 8d:92:27:76:79:c5 | 127.0.0.1/8 | 100 | Disabled |\n", + "+------+-------------------+-----------------+-------+----------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"router_1\").show()" ] @@ -153,12 +229,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "92de8b42-92d7-4934-9c12-50bf724c9eb2", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-------------------------------------------------------+\n", + "| router_1 ARP Cache |\n", + "+---------------+-------------------+-------------------+\n", + "| IP Address | MAC Address | Via |\n", + "+---------------+-------------------+-------------------+\n", + "| 192.168.10.21 | f6:6d:35:8a:67:d8 | eb:31:e8:11:28:ac |\n", + "| 192.168.10.22 | 6a:b1:ff:36:ef:40 | eb:31:e8:11:28:ac |\n", + "| 192.168.1.10 | 00:c3:ff:62:87:8f | 3f:c3:3d:00:74:c4 |\n", + "| 192.168.1.14 | 2e:e8:cb:a5:97:12 | 3f:c3:3d:00:74:c4 |\n", + "| 192.168.1.12 | 90:94:52:a6:1f:c5 | 3f:c3:3d:00:74:c4 |\n", + "| 192.168.1.16 | c3:e5:81:c9:8b:74 | 3f:c3:3d:00:74:c4 |\n", + "| 192.168.1.110 | 18:9d:a1:f0:6f:0b | 3f:c3:3d:00:74:c4 |\n", + "+---------------+-------------------+-------------------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"router_1\").arp.show()" ] @@ -173,12 +269,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "5922282a-d22b-4e55-9176-f3f3654c849f", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+---------------------------------------------------------------------------------------------------------------------------------------+\n", + "| router_1 Access Control List |\n", + "+-------+--------+----------+--------+--------------+------------------------+--------+--------------+------------------------+---------+\n", + "| Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Matched |\n", + "+-------+--------+----------+--------+--------------+------------------------+--------+--------------+------------------------+---------+\n", + "| 0 | PERMIT | ANY | ANY | ANY | 5432 (POSTGRES_SERVER) | ANY | ANY | 5432 (POSTGRES_SERVER) | 0 |\n", + "| 1 | PERMIT | ANY | ANY | ANY | 53 (DNS) | ANY | ANY | 53 (DNS) | 0 |\n", + "| 2 | PERMIT | ANY | ANY | ANY | 21 (FTP) | ANY | ANY | 21 (FTP) | 0 |\n", + "| 3 | PERMIT | ANY | ANY | ANY | 80 (HTTP) | ANY | ANY | 80 (HTTP) | 0 |\n", + "| 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 0 |\n", + "| 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 0 |\n", + "| 24 | DENY | ANY | ANY | ANY | ANY | ANY | ANY | ANY | 0 |\n", + "+-------+--------+----------+--------+--------------+------------------------+--------+--------------+------------------------+---------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"router_1\").acl.show()" ] @@ -193,12 +309,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "327203be-f475-4727-82a1-e992d3b70ed8", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-------------------------------------+\n", + "| router_1 Route Table |\n", + "+-------+---------+----------+--------+\n", + "| Index | Address | Next Hop | Metric |\n", + "+-------+---------+----------+--------+\n", + "+-------+---------+----------+--------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"router_1\").route_table.show()" ] @@ -213,12 +342,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "3d0aa004-b10c-445f-aaab-340e0e716c74", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-----------------------------+\n", + "| router_1 Sys Log |\n", + "+-----------+-------+---------+\n", + "| Timestamp | Level | Message |\n", + "+-----------+-------+---------+\n", + "+-----------+-------+---------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"router_1\").sys_log.show(last_n=10)" ] @@ -238,17 +380,52 @@ "id": "4879394d-2981-40de-a229-e19b09a34e6e", "metadata": {}, "source": [ - "Calling `switch.show()` displays the Switch orts on the Switch." + "Calling `switch.show()` displays the Switch ports on the Switch." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "id": "e7fd439b-5442-4e9d-9e7d-86dacb77f458", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+---------------------------------------------+\n", + "| switch_1 Switch Ports |\n", + "+------+-------------------+-------+----------+\n", + "| Port | MAC Address | Speed | Status |\n", + "+------+-------------------+-------+----------+\n", + "| 1 | 08:79:a7:3f:b5:96 | 100 | Enabled |\n", + "| 2 | 75:c5:30:0f:5d:92 | 100 | Enabled |\n", + "| 3 | f1:62:75:5d:d9:59 | 100 | Enabled |\n", + "| 4 | 08:0e:a9:03:d7:3c | 100 | Enabled |\n", + "| 5 | ae:40:29:58:c7:95 | 100 | Disabled |\n", + "| 6 | 7d:54:38:7f:79:e8 | 100 | Disabled |\n", + "| 7 | 63:ea:45:e6:f4:22 | 100 | Enabled |\n", + "| 8 | a9:ea:54:9f:35:f8 | 100 | Enabled |\n", + "+------+-------------------+-------+----------+\n", + "+---------------------------------------------+\n", + "| switch_2 Switch Ports |\n", + "+------+-------------------+-------+----------+\n", + "| Port | MAC Address | Speed | Status |\n", + "+------+-------------------+-------+----------+\n", + "| 1 | 42:08:3f:1e:ea:dd | 100 | Enabled |\n", + "| 2 | a8:1b:b2:78:12:34 | 100 | Enabled |\n", + "| 3 | 43:e4:54:fe:e7:1f | 100 | Disabled |\n", + "| 4 | 24:bf:74:7c:c4:11 | 100 | Disabled |\n", + "| 5 | 4b:57:f7:46:c9:4f | 100 | Disabled |\n", + "| 6 | 10:03:9d:39:0c:81 | 100 | Disabled |\n", + "| 7 | 88:9c:57:5c:53:5e | 100 | Enabled |\n", + "| 8 | d3:59:e2:73:4e:b8 | 100 | Enabled |\n", + "+------+-------------------+-------+----------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"switch_1\").show()" ] @@ -265,14 +442,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "d06e1310-4a77-4315-a59f-cb1b49ca2352", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+--------------------------------+\n", + "| switch_1 ARP Cache |\n", + "+------------+-------------+-----+\n", + "| IP Address | MAC Address | Via |\n", + "+------------+-------------+-----+\n", + "+------------+-------------+-----+\n" + ] + } + ], "source": [ - "network.get_node_by_hostname(\"switch_1\").arp.show()" + "network.get_node_by_hostname(\"switch_1\").arp.show()\n", + "#network.get_node_by_hostname(\"switch_1\").software_manager" ] }, { @@ -285,12 +476,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "a0d984b7-a7c1-4bbd-aa5a-9d3caecb08dc", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-----------------------------+\n", + "| switch_1 Sys Log |\n", + "+-----------+-------+---------+\n", + "| Timestamp | Level | Message |\n", + "+-----------+-------+---------+\n", + "+-----------+-------+---------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"switch_1\").sys_log.show()" ] @@ -317,12 +521,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "656c37f6-b145-42af-9714-8d2886d0eff8", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-----------------------------------------------------------------------+\n", + "| security_suite Network Interface Cards |\n", + "+------+------+-------------------+-------------------+-------+---------+\n", + "| Port | Type | MAC Address | Address | Speed | Status |\n", + "+------+------+-------------------+-------------------+-------+---------+\n", + "| 1 | NIC | 18:9d:a1:f0:6f:0b | 192.168.1.110/24 | 100 | Enabled |\n", + "| 2 | NIC | 9e:b2:c8:04:d8:97 | 192.168.10.110/24 | 100 | Enabled |\n", + "+------+------+-------------------+-------------------+-------+---------+\n", + "+---------------------------+\n", + "| security_suite Open Ports |\n", + "+-------------+-------------+\n", + "| Port | Name |\n", + "+-------------+-------------+\n", + "| 21 | FTP |\n", + "| 53 | DNS |\n", + "| 80 | HTTP |\n", + "| 123 | NTP |\n", + "| 219 | ARP |\n", + "+-------------+-------------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"security_suite\").show()" ] @@ -337,12 +567,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "66b267d6-2308-486a-b9aa-cb8d3bcf0753", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-----------------------------------------------------+\n", + "| security_suite ARP Cache |\n", + "+-------------+-------------------+-------------------+\n", + "| IP Address | MAC Address | Via |\n", + "+-------------+-------------------+-------------------+\n", + "| 192.168.1.1 | 3f:c3:3d:00:74:c4 | 18:9d:a1:f0:6f:0b |\n", + "+-------------+-------------------+-------------------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"security_suite\").arp.show()" ] @@ -357,12 +601,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "1b5debe8-ef1b-445d-8fa9-6a45568f21f3", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-----------------------------+\n", + "| security_suite Sys Log |\n", + "+-----------+-------+---------+\n", + "| Timestamp | Level | Message |\n", + "+-----------+-------+---------+\n", + "+-----------+-------+---------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"security_suite\").sys_log.show()" ] @@ -379,12 +636,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "495b7de4-b6ce-41a6-9114-f74752ab4491", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-----------------------------------------------------------------------------+\n", + "| IP Addresses |\n", + "+-------------------+------+----------------+---------------+-----------------+\n", + "| Node | Port | IP Address | Subnet Mask | Default Gateway |\n", + "+-------------------+------+----------------+---------------+-----------------+\n", + "| router_1 | 1 | 192.168.1.1 | 255.255.255.0 | None |\n", + "| router_1 | 2 | 192.168.10.1 | 255.255.255.0 | None |\n", + "| router_1 | 3 | 127.0.0.1 | 255.0.0.0 | None |\n", + "| router_1 | 4 | 127.0.0.1 | 255.0.0.0 | None |\n", + "| router_1 | 5 | 127.0.0.1 | 255.0.0.0 | None |\n", + "| domain_controller | 1 | 192.168.1.10 | 255.255.255.0 | 192.168.1.1 |\n", + "| database_server | 1 | 192.168.1.14 | 255.255.255.0 | 192.168.1.1 |\n", + "| web_server | 1 | 192.168.1.12 | 255.255.255.0 | 192.168.1.1 |\n", + "| backup_server | 1 | 192.168.1.16 | 255.255.255.0 | 192.168.1.1 |\n", + "| security_suite | 1 | 192.168.1.110 | 255.255.255.0 | 192.168.1.1 |\n", + "| security_suite | 2 | 192.168.10.110 | 255.255.255.0 | 192.168.1.1 |\n", + "| client_1 | 1 | 192.168.10.21 | 255.255.255.0 | 192.168.10.1 |\n", + "| client_2 | 1 | 192.168.10.22 | 255.255.255.0 | 192.168.10.1 |\n", + "+-------------------+------+----------------+---------------+-----------------+\n" + ] + } + ], "source": [ "network.show(nodes=False, links=False)" ] @@ -399,24 +682,60 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "id": "a38abb71-994e-49e8-8f51-e9a550e95b99", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Pinging 192.168.10.1:\n", + "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", + "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", + "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", + "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", + "Ping statistics for 192.168.10.1: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "network.get_node_by_hostname(\"client_1\").ping(\"192.168.10.1\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "id": "8388e1e9-30e3-4534-8e5a-c6e9144149d2", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-----------------------------+\n", + "| client_1 Sys Log |\n", + "+-----------+-------+---------+\n", + "| Timestamp | Level | Message |\n", + "+-----------+-------+---------+\n", + "+-----------+-------+---------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"client_1\").sys_log.show(15)" ] @@ -431,12 +750,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "ff8e976a-c16b-470c-8923-325713a30d6c", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Pinging 192.168.1.1:\n", + "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", + "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", + "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", + "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", + "Ping statistics for 192.168.1.1: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "network.get_node_by_hostname(\"client_1\").ping(\"192.168.1.1\")" ] @@ -451,12 +793,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "c4163f8d-6a72-410c-9f5c-4f881b7de45e", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Pinging 192.168.1.12:\n", + "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", + "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", + "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", + "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", + "Ping statistics for 192.168.1.12: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "network.get_node_by_hostname(\"client_1\").ping(\"192.168.1.12\")" ] @@ -471,12 +836,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "e79a523a-5780-45b6-8798-c434e0e522bd", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-----------------------------+\n", + "| web_server Sys Log |\n", + "+-----------+-------+---------+\n", + "| Timestamp | Level | Message |\n", + "+-----------+-------+---------+\n", + "+-----------+-------+---------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"web_server\").sys_log.show()" ] @@ -501,12 +879,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "603cf913-e261-49da-a7dd-85e1bb6dec56", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Pinging 192.168.1.12:\n", + "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", + "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", + "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", + "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", + "Ping statistics for 192.168.1.12: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "network.get_node_by_hostname(\"client_2\").ping(\"192.168.1.12\")" ] @@ -521,12 +922,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "e047de00-3de4-4823-b26a-2c8d64c7a663", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-----------------------------+\n", + "| client_2 Sys Log |\n", + "+-----------+-------+---------+\n", + "| Timestamp | Level | Message |\n", + "+-----------+-------+---------+\n", + "+-----------+-------+---------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"client_2\").sys_log.show()" ] @@ -541,16 +955,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "6db355ae-b99a-441b-a2c4-4ffe78f46bff", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", "from primaite.simulator.network.transmission.transport_layer import Port\n", - "from primaite.simulator.network.hardware.nodes.router import ACLAction\n", + "from primaite.simulator.network.hardware.nodes.network.router import ACLAction\n", "network.get_node_by_hostname(\"router_1\").acl.add_rule(\n", " action=ACLAction.DENY,\n", " protocol=IPProtocol.ICMP,\n", @@ -561,12 +986,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "a345e000-8842-4827-af96-adc0fbe390fb", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+----------------------------------------------------------------------------------------------------------------------------------------------+\n", + "| router_1 Access Control List |\n", + "+-------+--------+----------+---------------+--------------+------------------------+--------+--------------+------------------------+---------+\n", + "| Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Matched |\n", + "+-------+--------+----------+---------------+--------------+------------------------+--------+--------------+------------------------+---------+\n", + "| 0 | PERMIT | ANY | ANY | ANY | 5432 (POSTGRES_SERVER) | ANY | ANY | 5432 (POSTGRES_SERVER) | 0 |\n", + "| 1 | DENY | ICMP | 192.168.10.22 | ANY | ANY | ANY | ANY | ANY | 0 |\n", + "| 2 | PERMIT | ANY | ANY | ANY | 21 (FTP) | ANY | ANY | 21 (FTP) | 0 |\n", + "| 3 | PERMIT | ANY | ANY | ANY | 80 (HTTP) | ANY | ANY | 80 (HTTP) | 0 |\n", + "| 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 0 |\n", + "| 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 24 |\n", + "| 24 | DENY | ANY | ANY | ANY | ANY | ANY | ANY | ANY | 0 |\n", + "+-------+--------+----------+---------------+--------------+------------------------+--------+--------------+------------------------+---------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"router_1\").acl.show()" ] @@ -581,12 +1026,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "id": "a4f4ff31-590f-40fb-b13d-efaa8c2720b6", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Pinging 192.168.1.12:\n", + "Ping statistics for 192.168.1.12: Packets: Sent = 4, Received = 0, Lost = 4 (100.0% loss)\n" + ] + }, + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "network.get_node_by_hostname(\"client_2\").ping(\"192.168.1.12\")" ] @@ -601,12 +1065,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "id": "f62b8a4e-fd3b-4059-b108-3d4a0b18f2a0", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-----------------------------+\n", + "| client_2 Sys Log |\n", + "+-----------+-------+---------+\n", + "| Timestamp | Level | Message |\n", + "+-----------+-------+---------+\n", + "+-----------+-------+---------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"client_2\").sys_log.show()" ] @@ -621,12 +1098,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "id": "7e53d776-99da-4d2c-a2a7-bd7ce27bff4c", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-----------------------------+\n", + "| router_1 Sys Log |\n", + "+-----------+-------+---------+\n", + "| Timestamp | Level | Message |\n", + "+-----------+-------+---------+\n", + "+-----------+-------+---------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"router_1\").sys_log.show()" ] @@ -641,24 +1131,60 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "id": "d542734b-7582-4af7-8254-bda3de50d091", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Pinging 192.168.1.12:\n", + "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", + "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", + "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", + "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", + "Ping statistics for 192.168.1.12: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "network.get_node_by_hostname(\"client_1\").ping(\"192.168.1.12\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "id": "d78e9fe3-02c6-4792-944f-5622e26e0412", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+-----------------------------+\n", + "| client_1 Sys Log |\n", + "+-----------+-------+---------+\n", + "| Timestamp | Level | Message |\n", + "+-----------+-------+---------+\n", + "+-----------+-------+---------+\n" + ] + } + ], "source": [ "network.get_node_by_hostname(\"client_1\").sys_log.show()" ] diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index 31378689..9d08b9f4 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -316,6 +316,10 @@ class HostNode(Node): super().__init__(**kwargs) self.connect_nic(NIC(ip_address=ip_address, subnet_mask=subnet_mask)) + @property + def arp(self) -> Optional[ARP]: + return self.software_manager.software.get("ARP") + def _install_system_software(self): """ Installs the system software and network services typically found on an operating system. diff --git a/src/primaite/simulator/network/hardware/nodes/network/network_node.py b/src/primaite/simulator/network/hardware/nodes/network/network_node.py index ebdb6ed8..a3dc3be3 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/network_node.py +++ b/src/primaite/simulator/network/hardware/nodes/network/network_node.py @@ -1,8 +1,9 @@ from abc import abstractmethod +from typing import Optional from primaite.simulator.network.hardware.base import NetworkInterface, Node from primaite.simulator.network.transmission.data_link_layer import Frame - +from primaite.simulator.system.services.arp.arp import ARP class NetworkNode(Node): """ @@ -28,3 +29,7 @@ class NetworkNode(Node): :type from_network_interface: NetworkInterface """ pass + + @property + def arp(self) -> Optional[ARP]: + return self.software_manager.software.get("ARP") diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 1c36c696..426c5415 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1215,8 +1215,7 @@ class Router(NetworkNode): icmp: RouterICMP = self.software_manager.icmp # noqa icmp.router = self self.software_manager.install(RouterARP) - arp: RouterARP = self.software_manager.arp # noqa - arp.router = self + self.arp.router = self def _set_default_acl(self): """ From c13d3f191faf9a414f64728fd73fe2bb4d1cb187 Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Tue, 9 Apr 2024 13:34:57 +0100 Subject: [PATCH 799/980] #2453 - Correcting errors found from pipeline pre-commit checks --- .../create-simulation_demo.ipynb | 240 +++++++++--------- .../network_simulator_demo.ipynb | 170 +++++-------- .../network/hardware/nodes/host/host_node.py | 6 + .../hardware/nodes/network/network_node.py | 6 + 4 files changed, 192 insertions(+), 230 deletions(-) diff --git a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb index 57003e55..5ef31243 100644 --- a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb +++ b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": 119, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -36,20 +36,20 @@ }, { "cell_type": "code", - "execution_count": 120, + "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'uuid': '42d005b2-4dc8-4aec-be54-3493242eee32',\n", - " 'network': {'uuid': '069f61a4-ac40-431f-ad13-2fc9b26dc091',\n", + "{'uuid': '91c88b2a-caf1-47be-a394-d0c22e5110be',\n", + " 'network': {'uuid': 'a9121808-0401-460c-9833-23d4ba91e9bc',\n", " 'nodes': {},\n", " 'links': {}},\n", - " 'domain': {'uuid': 'f0629156-e9af-493d-b098-f47d73126122', 'accounts': {}}}" + " 'domain': {'uuid': '25fbe0e9-76e8-4fd7-ad22-da2d2b5a509d', 'accounts': {}}}" ] }, - "execution_count": 120, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -69,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": 121, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -79,7 +79,7 @@ }, { "cell_type": "code", - "execution_count": 122, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -98,7 +98,7 @@ }, { "cell_type": "code", - "execution_count": 123, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -108,16 +108,16 @@ }, { "cell_type": "code", - "execution_count": 124, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Link(uuid='42b8f911-3640-4ccb-b277-b48b294a1fc8', endpoint_a=NIC(ip_address=IPv4Address('130.1.1.2'), subnet_mask=IPv4Address('255.255.255.0'), uuid='53993d8f-216e-4c00-9b03-c6bb9e2437b5', mac_address='17:9d:82:db:ca:c8', speed=100, mtu=1500, enabled=False, port_num=2, port_name=None, pcap=None, nmne={}, wake_on_lan=False, gateway='130.1.1.255'), endpoint_b=SwitchPort(uuid='c03d4d22-f309-49b6-a1ad-45a04c40d25e', mac_address='84:01:f3:bb:47:1c', speed=100, mtu=1500, enabled=False, port_num=2, port_name=None, pcap=None, nmne={}), bandwidth=100.0, current_load=0.0)" + "Link(uuid='2bd19485-0a6b-4878-978b-b082a672d9b9', endpoint_a=NIC(ip_address=IPv4Address('130.1.1.2'), subnet_mask=IPv4Address('255.255.255.0'), uuid='8a628493-83fb-44bf-a1b0-ef19e362ae5f', mac_address='44:89:a5:ce:7f:6f', speed=100, mtu=1500, enabled=False, port_num=2, port_name=None, pcap=None, nmne={}, wake_on_lan=False, gateway='130.1.1.255'), endpoint_b=SwitchPort(uuid='a049bb8f-53d3-4575-b325-dfb55516edcd', mac_address='aa:45:88:e1:13:e5', speed=100, mtu=1500, enabled=False, port_num=2, port_name=None, pcap=None, nmne={}), bandwidth=100.0, current_load=0.0)" ] }, - "execution_count": 124, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -145,7 +145,7 @@ }, { "cell_type": "code", - "execution_count": 125, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -156,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": 126, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -166,16 +166,16 @@ }, { "cell_type": "code", - "execution_count": 127, + "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "File(uuid='24789051-6762-48f4-8a56-c28882374273', name='favicon.ico', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='7a86576b-607f-468b-826f-4834cf2b3511', folder_name='root', file_type=, sim_size=0, real=False, sim_path=None, sim_root=WindowsPath('C:/Projects/PrimAITE/simulation_output/2024-04-08_12-19-36/google_server/fs'), num_access=0, folder=Folder(uuid='7a86576b-607f-468b-826f-4834cf2b3511', name='root', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={'24789051-6762-48f4-8a56-c28882374273': File(uuid='24789051-6762-48f4-8a56-c28882374273', name='favicon.ico', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='7a86576b-607f-468b-826f-4834cf2b3511', folder_name='root', file_type=, sim_size=0, real=False, sim_path=None, sim_root=WindowsPath('C:/Projects/PrimAITE/simulation_output/2024-04-08_12-19-36/google_server/fs'), num_access=0, folder=Folder(uuid='7a86576b-607f-468b-826f-4834cf2b3511', name='root', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={}, scan_duration=3, scan_countdown=0, red_scan_duration=3, red_scan_countdown=0, restore_duration=3, restore_countdown=0))}, deleted_files={}, scan_duration=3, scan_countdown=0, red_scan_duration=3, red_scan_countdown=0, restore_duration=3, restore_countdown=0))" + "File(uuid='3ceeded4-77b9-4a86-949c-73188d5f4c34', name='favicon.ico', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='cbbd3631-a915-400d-bc02-f31f72447ce5', folder_name='root', file_type=, sim_size=0, real=False, sim_path=None, sim_root=WindowsPath('C:/Projects/PrimAITE/simulation_output/2024-04-09_13-24-30/google_server/fs'), num_access=0, folder=Folder(uuid='cbbd3631-a915-400d-bc02-f31f72447ce5', name='root', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={'3ceeded4-77b9-4a86-949c-73188d5f4c34': File(uuid='3ceeded4-77b9-4a86-949c-73188d5f4c34', name='favicon.ico', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='cbbd3631-a915-400d-bc02-f31f72447ce5', folder_name='root', file_type=, sim_size=0, real=False, sim_path=None, sim_root=WindowsPath('C:/Projects/PrimAITE/simulation_output/2024-04-09_13-24-30/google_server/fs'), num_access=0, folder=Folder(uuid='cbbd3631-a915-400d-bc02-f31f72447ce5', name='root', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={}, scan_duration=3, scan_countdown=0, red_scan_duration=3, red_scan_countdown=0, restore_duration=3, restore_countdown=0))}, deleted_files={}, scan_duration=3, scan_countdown=0, red_scan_duration=3, red_scan_countdown=0, restore_duration=3, restore_countdown=0))" ] }, - "execution_count": 127, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -194,16 +194,16 @@ }, { "cell_type": "code", - "execution_count": 128, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ + "from pathlib import Path\n", "from primaite.simulator.system.applications.application import Application, ApplicationOperatingState\n", "from primaite.simulator.system.software import SoftwareHealthState, SoftwareCriticality\n", "from primaite.simulator.network.transmission.transport_layer import Port\n", "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", "from primaite.simulator.file_system.file_system import FileSystem\n", - "from pathlib import Path\n", "\n", "# no applications exist yet so we will create our own.\n", "class MSPaint(Application):\n", @@ -213,7 +213,7 @@ }, { "cell_type": "code", - "execution_count": 129, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -222,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": 130, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -238,7 +238,7 @@ }, { "cell_type": "code", - "execution_count": 131, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -247,7 +247,7 @@ }, { "cell_type": "code", - "execution_count": 132, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -264,19 +264,19 @@ }, { "cell_type": "code", - "execution_count": 133, + "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'uuid': '42d005b2-4dc8-4aec-be54-3493242eee32',\n", - " 'network': {'uuid': '069f61a4-ac40-431f-ad13-2fc9b26dc091',\n", - " 'nodes': {'primaite_pc': {'uuid': '52246eed-9a3f-4b19-ad0c-48fc3bbb998d',\n", + "{'uuid': '91c88b2a-caf1-47be-a394-d0c22e5110be',\n", + " 'network': {'uuid': 'a9121808-0401-460c-9833-23d4ba91e9bc',\n", + " 'nodes': {'primaite_pc': {'uuid': 'dd0e95be-2491-4d5b-8388-df3975a19e8a',\n", " 'hostname': 'primaite_pc',\n", " 'operating_state': 2,\n", - " 'NICs': {1: {'uuid': '73dcb42e-7db4-45cf-b439-9b8066c8e32e',\n", - " 'mac_address': 'c9:84:ec:48:87:77',\n", + " 'NICs': {1: {'uuid': '279e2645-b680-4d2e-b13c-66d5cfacbd38',\n", + " 'mac_address': 'bd:76:20:24:cf:04',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", @@ -284,8 +284,8 @@ " 'ip_address': '192.168.1.10',\n", " 'subnet_mask': '255.255.255.0',\n", " 'wake_on_lan': False},\n", - " 2: {'uuid': 'e0fbda66-afcb-4a79-b696-aad0778279a2',\n", - " 'mac_address': 'cb:66:8b:b2:dc:51',\n", + " 2: {'uuid': '40c0db02-4d14-4826-b49b-e6a521941cec',\n", + " 'mac_address': 'd8:b2:0c:af:3f:83',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", @@ -293,8 +293,8 @@ " 'ip_address': '130.1.1.1',\n", " 'subnet_mask': '255.255.255.0',\n", " 'wake_on_lan': False}},\n", - " 'file_system': {'uuid': '8a857927-dd5e-40e9-86fd-1df8b3a2b463',\n", - " 'folders': {'root': {'uuid': 'acb725c9-461e-40c5-b2c0-ed198865e1f2',\n", + " 'file_system': {'uuid': '91d3aed7-53c6-471f-b903-9889396be280',\n", + " 'folders': {'root': {'uuid': '81bdc04e-9a0d-4306-9a9c-ee926fff6df8',\n", " 'name': 'root',\n", " 'health_status': 1,\n", " 'visible_status': 1,\n", @@ -302,13 +302,13 @@ " 'revealed_to_red': False,\n", " 'files': {},\n", " 'deleted_files': {}},\n", - " 'downloads': {'uuid': '484f7bcf-b8da-4995-8538-82b2a4d059c7',\n", + " 'downloads': {'uuid': '56abdf27-b8d4-42f4-9b09-b7912db1c4f3',\n", " 'name': 'downloads',\n", " 'health_status': 1,\n", " 'visible_status': 1,\n", " 'previous_hash': None,\n", " 'revealed_to_red': False,\n", - " 'files': {'firefox_installer.zip': {'uuid': '5e1e5bec-a984-4ae1-9799-78083bd2e3c2',\n", + " 'files': {'firefox_installer.zip': {'uuid': '02236b61-14bb-46aa-9fd5-7174c0d7d730',\n", " 'name': 'firefox_installer.zip',\n", " 'health_status': 1,\n", " 'visible_status': 1,\n", @@ -321,7 +321,7 @@ " 'deleted_folders': {},\n", " 'num_file_creations': 0,\n", " 'num_file_deletions': 0},\n", - " 'applications': {'WebBrowser': {'uuid': '5987fc38-686d-439f-b513-23166884596e',\n", + " 'applications': {'WebBrowser': {'uuid': 'a6a12776-e307-4d71-9e7a-d9ca97ecd6b0',\n", " 'health_state_actual': 0,\n", " 'health_state_visible': 0,\n", " 'criticality': 1,\n", @@ -338,7 +338,7 @@ " 'num_executions': 0,\n", " 'groups': [],\n", " 'history': []},\n", - " 'mspaint': {'uuid': '88eb36c5-dba4-4f79-ad95-5957f7de3fa2',\n", + " 'mspaint': {'uuid': 'efd34549-cc92-4474-80ab-5fb6c3159ff6',\n", " 'health_state_actual': 1,\n", " 'health_state_visible': 1,\n", " 'criticality': 3,\n", @@ -354,7 +354,7 @@ " 'execution_control_status': 'manual',\n", " 'num_executions': 0,\n", " 'groups': []}},\n", - " 'services': {'ARP': {'uuid': 'e220dde6-88d5-4e24-a2de-5bce0cd4a916',\n", + " 'services': {'ARP': {'uuid': 'e61c25ff-a6c2-4eec-b031-131eaf33490c',\n", " 'health_state_actual': 0,\n", " 'health_state_visible': 0,\n", " 'criticality': 1,\n", @@ -367,7 +367,7 @@ " 'udp': True,\n", " 'port': 219,\n", " 'operating_state': 2},\n", - " 'ICMP': {'uuid': 'ef728c73-97b7-480f-bedb-04dc3d5efd57',\n", + " 'ICMP': {'uuid': '74debeed-b758-41cb-bea2-51ac283e6ae2',\n", " 'health_state_actual': 0,\n", " 'health_state_visible': 0,\n", " 'criticality': 1,\n", @@ -380,7 +380,7 @@ " 'udp': True,\n", " 'port': 0,\n", " 'operating_state': 2},\n", - " 'DNSClient': {'uuid': '30b159f1-a4e8-41f5-923b-c692d104f385',\n", + " 'DNSClient': {'uuid': '6680efc0-e005-41e8-bb49-39a0d9c4b118',\n", " 'health_state_actual': 0,\n", " 'health_state_visible': 0,\n", " 'criticality': 1,\n", @@ -393,7 +393,7 @@ " 'udp': True,\n", " 'port': 53,\n", " 'operating_state': 2},\n", - " 'FTPClient': {'uuid': '5f267d5f-6bb8-4e97-b6b9-855ee2d50c25',\n", + " 'FTPClient': {'uuid': '21b05ac9-e9b4-4c5c-a812-f6748e14d8c3',\n", " 'health_state_actual': 0,\n", " 'health_state_visible': 0,\n", " 'criticality': 1,\n", @@ -406,7 +406,7 @@ " 'udp': True,\n", " 'port': 21,\n", " 'operating_state': 2},\n", - " 'NTPClient': {'uuid': '1ea99f1e-dc04-4548-a384-913851a7e4fd',\n", + " 'NTPClient': {'uuid': '7ab7c911-5037-4e82-b00c-be4f72c13aa7',\n", " 'health_state_actual': 0,\n", " 'health_state_visible': 0,\n", " 'criticality': 1,\n", @@ -421,11 +421,11 @@ " 'operating_state': 2}},\n", " 'process': {},\n", " 'revealed_to_red': False},\n", - " 'google_server': {'uuid': 'b9a41d9c-6642-441b-8049-8302ddafd3b1',\n", + " 'google_server': {'uuid': '42d61d8d-2493-4b8a-944f-7962abc9d20b',\n", " 'hostname': 'google_server',\n", " 'operating_state': 2,\n", - " 'NICs': {1: {'uuid': 'd0736beb-085a-4754-8b44-de73e6a8c80f',\n", - " 'mac_address': '45:27:ed:64:ac:09',\n", + " 'NICs': {1: {'uuid': 'e384a4fc-754f-44a4-9158-c63f72f52f76',\n", + " 'mac_address': 'ea:5d:4f:10:b2:27',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", @@ -433,8 +433,8 @@ " 'ip_address': '192.168.1.11',\n", " 'subnet_mask': '255.255.255.0',\n", " 'wake_on_lan': False},\n", - " 2: {'uuid': '53993d8f-216e-4c00-9b03-c6bb9e2437b5',\n", - " 'mac_address': '17:9d:82:db:ca:c8',\n", + " 2: {'uuid': '8a628493-83fb-44bf-a1b0-ef19e362ae5f',\n", + " 'mac_address': '44:89:a5:ce:7f:6f',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", @@ -442,14 +442,14 @@ " 'ip_address': '130.1.1.2',\n", " 'subnet_mask': '255.255.255.0',\n", " 'wake_on_lan': False}},\n", - " 'file_system': {'uuid': '8d4ded3a-56bb-46f0-ad7f-40d65b523581',\n", - " 'folders': {'root': {'uuid': '7a86576b-607f-468b-826f-4834cf2b3511',\n", + " 'file_system': {'uuid': 'f25cee1f-2ebe-4fd3-8d5c-649b0d342b61',\n", + " 'folders': {'root': {'uuid': 'cbbd3631-a915-400d-bc02-f31f72447ce5',\n", " 'name': 'root',\n", " 'health_status': 1,\n", " 'visible_status': 1,\n", " 'previous_hash': None,\n", " 'revealed_to_red': False,\n", - " 'files': {'favicon.ico': {'uuid': '24789051-6762-48f4-8a56-c28882374273',\n", + " 'files': {'favicon.ico': {'uuid': '3ceeded4-77b9-4a86-949c-73188d5f4c34',\n", " 'name': 'favicon.ico',\n", " 'health_status': 1,\n", " 'visible_status': 1,\n", @@ -459,7 +459,7 @@ " 'file_type': 'UNKNOWN',\n", " 'num_access': 0}},\n", " 'deleted_files': {}},\n", - " 'static': {'uuid': '154b2ad3-e43d-4924-b758-e11db0e176de',\n", + " 'static': {'uuid': 'd8241ce0-f55e-43ec-bd68-741b79a9a565',\n", " 'name': 'static',\n", " 'health_status': 1,\n", " 'visible_status': 1,\n", @@ -470,7 +470,7 @@ " 'deleted_folders': {},\n", " 'num_file_creations': 1,\n", " 'num_file_deletions': 0},\n", - " 'applications': {'WebBrowser': {'uuid': '9b368321-e22d-4e35-9395-80632492c20a',\n", + " 'applications': {'WebBrowser': {'uuid': '957d0049-e703-4882-8e57-b2ab4c79d458',\n", " 'health_state_actual': 0,\n", " 'health_state_visible': 0,\n", " 'criticality': 1,\n", @@ -487,7 +487,7 @@ " 'num_executions': 0,\n", " 'groups': [],\n", " 'history': []}},\n", - " 'services': {'ARP': {'uuid': '30df82c0-5823-4464-8c23-5b99922f98f7',\n", + " 'services': {'ARP': {'uuid': '82ea1bcf-a0fe-418d-873e-5f075ebb4d3b',\n", " 'health_state_actual': 0,\n", " 'health_state_visible': 0,\n", " 'criticality': 1,\n", @@ -500,7 +500,7 @@ " 'udp': True,\n", " 'port': 219,\n", " 'operating_state': 2},\n", - " 'ICMP': {'uuid': '2d02a2de-7ec8-4da1-9538-c85eb397d4e3',\n", + " 'ICMP': {'uuid': 'bc084dc4-0a7d-4954-9e6e-54bed797e837',\n", " 'health_state_actual': 0,\n", " 'health_state_visible': 0,\n", " 'criticality': 1,\n", @@ -513,7 +513,7 @@ " 'udp': True,\n", " 'port': 0,\n", " 'operating_state': 2},\n", - " 'DNSClient': {'uuid': 'db979263-ff81-4a04-95e8-d94442e9ddfa',\n", + " 'DNSClient': {'uuid': '5a9ecc18-71c0-4728-a9c6-e31b33529581',\n", " 'health_state_actual': 0,\n", " 'health_state_visible': 0,\n", " 'criticality': 1,\n", @@ -526,7 +526,7 @@ " 'udp': True,\n", " 'port': 53,\n", " 'operating_state': 2},\n", - " 'FTPClient': {'uuid': 'd9d6417b-d1e0-416b-a711-3478fa248194',\n", + " 'FTPClient': {'uuid': 'f0a411eb-5423-4c98-8689-d94af57deefc',\n", " 'health_state_actual': 0,\n", " 'health_state_visible': 0,\n", " 'criticality': 1,\n", @@ -539,7 +539,7 @@ " 'udp': True,\n", " 'port': 21,\n", " 'operating_state': 2},\n", - " 'NTPClient': {'uuid': 'b23a1032-a817-492b-bdd6-2ecc6fb4591c',\n", + " 'NTPClient': {'uuid': 'd36f2c4f-af30-4618-ae8e-fe68c98e1382',\n", " 'health_state_actual': 0,\n", " 'health_state_visible': 0,\n", " 'criticality': 1,\n", @@ -554,83 +554,83 @@ " 'operating_state': 2}},\n", " 'process': {},\n", " 'revealed_to_red': False},\n", - " 'switch1': {'uuid': 'e658eac3-c4b8-4768-bf27-e2d90b7f57c0',\n", + " 'switch1': {'uuid': 'a9e08b28-d1f4-4c34-b410-71333cd6b42b',\n", " 'hostname': 'switch1',\n", " 'operating_state': 2,\n", - " 'NICs': {1: {'uuid': '7ebc80f5-902f-4253-8ea6-0cafa3d1cccd',\n", - " 'mac_address': 'df:d2:c7:2a:a1:52',\n", + " 'NICs': {1: {'uuid': '3546e960-30f8-49ee-95b9-57570b228333',\n", + " 'mac_address': '8d:d9:3e:f3:a3:ce',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 2: {'uuid': 'c03d4d22-f309-49b6-a1ad-45a04c40d25e',\n", - " 'mac_address': '84:01:f3:bb:47:1c',\n", + " 2: {'uuid': 'a049bb8f-53d3-4575-b325-dfb55516edcd',\n", + " 'mac_address': 'aa:45:88:e1:13:e5',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 3: {'uuid': '4207353c-e0cd-456d-89fe-13ddfc605cff',\n", - " 'mac_address': '8b:31:ac:cc:05:c9',\n", + " 3: {'uuid': '179c030c-d8fe-474b-a9d1-6c6bd6e6ca63',\n", + " 'mac_address': '10:d7:bc:39:4d:9d',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 4: {'uuid': '8aa1395f-e360-48a7-be97-ed1a5ca191ae',\n", - " 'mac_address': '75:3c:ae:bd:3a:b5',\n", + " 4: {'uuid': '56f84a14-0a98-4bc5-983b-31900fc9a2c5',\n", + " 'mac_address': '61:62:18:cf:2a:ea',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 5: {'uuid': '8b5d575c-ab0c-43ac-abfc-fa5ae75183e5',\n", - " 'mac_address': 'e7:7f:c4:af:8e:5b',\n", + " 5: {'uuid': '0ff4b64e-be4c-473e-8dcd-b7a0078ff890',\n", + " 'mac_address': '21:5e:6b:1b:d0:bf',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 6: {'uuid': '9d3cd584-f684-4f2e-9c8a-423d859fe3d3',\n", - " 'mac_address': '48:cf:18:8d:92:80',\n", + " 6: {'uuid': '0edf239b-bbb8-4076-ba85-cb07c65722d5',\n", + " 'mac_address': '40:58:ac:11:9c:1a',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 7: {'uuid': 'd42338bb-d579-483d-9e05-0318e17e574a',\n", - " 'mac_address': 'c6:99:5c:41:13:d7',\n", + " 7: {'uuid': 'a7f578e5-a6f5-4cf8-abca-207e483637c2',\n", + " 'mac_address': 'e0:ef:90:e2:ce:b4',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 8: {'uuid': '55bbd70b-491d-4452-8326-390ec3fadc28',\n", - " 'mac_address': '81:ab:39:0c:a2:dd',\n", + " 8: {'uuid': 'dc2069dd-ef3c-4e0b-81cb-a73caba917a8',\n", + " 'mac_address': '2c:2a:27:d6:9a:a8',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 9: {'uuid': '0755d768-79c7-48cf-9220-d2dad32e574b',\n", - " 'mac_address': '62:35:0c:5e:cc:5d',\n", + " 9: {'uuid': 'afbc1a01-efdb-424c-9a7d-b3c3165f6d78',\n", + " 'mac_address': 'e0:f5:79:04:4f:2a',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 10: {'uuid': 'deaecc57-ec76-4e27-a37e-f66964901b03',\n", - " 'mac_address': '51:26:00:c6:7e:ac',\n", + " 10: {'uuid': 'bdd805f4-a3dc-4a94-ba67-3a62b138f41c',\n", + " 'mac_address': '9a:20:3d:cb:a0:98',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 11: {'uuid': '53fe318c-4969-42fe-920b-37a491f54d84',\n", - " 'mac_address': '35:59:c7:13:ab:a5',\n", + " 11: {'uuid': '19f6f871-cba9-423a-a1a5-6a0e347e98cb',\n", + " 'mac_address': '69:d9:8c:1d:a9:75',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 12: {'uuid': '5a81caa0-9d91-4a86-9bd4-4ecb589c70ae',\n", - " 'mac_address': '7a:6b:ec:15:1e:de',\n", + " 12: {'uuid': '5c2aa6f5-12ce-466b-b46b-95ec519a5f47',\n", + " 'mac_address': 'db:7e:8c:91:1b:3f',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}}},\n", - " 'file_system': {'uuid': '289bea1e-69bf-44d5-80fe-212dad8afcd5',\n", - " 'folders': {'root': {'uuid': '3b588b3c-bc4a-4c06-a688-eced0128b128',\n", + " 'file_system': {'uuid': '91dea1d3-3947-49b9-a691-750bc25bbb9c',\n", + " 'folders': {'root': {'uuid': 'b7ebbf43-d86f-43d3-bbc7-f6b197af40b9',\n", " 'name': 'root',\n", " 'health_status': 1,\n", " 'visible_status': 1,\n", @@ -645,100 +645,100 @@ " 'services': {},\n", " 'process': {},\n", " 'revealed_to_red': False,\n", - " 'ports': {1: {'uuid': '7ebc80f5-902f-4253-8ea6-0cafa3d1cccd',\n", - " 'mac_address': 'df:d2:c7:2a:a1:52',\n", + " 'ports': {1: {'uuid': '3546e960-30f8-49ee-95b9-57570b228333',\n", + " 'mac_address': '8d:d9:3e:f3:a3:ce',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 2: {'uuid': 'c03d4d22-f309-49b6-a1ad-45a04c40d25e',\n", - " 'mac_address': '84:01:f3:bb:47:1c',\n", + " 2: {'uuid': 'a049bb8f-53d3-4575-b325-dfb55516edcd',\n", + " 'mac_address': 'aa:45:88:e1:13:e5',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 3: {'uuid': '4207353c-e0cd-456d-89fe-13ddfc605cff',\n", - " 'mac_address': '8b:31:ac:cc:05:c9',\n", + " 3: {'uuid': '179c030c-d8fe-474b-a9d1-6c6bd6e6ca63',\n", + " 'mac_address': '10:d7:bc:39:4d:9d',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 4: {'uuid': '8aa1395f-e360-48a7-be97-ed1a5ca191ae',\n", - " 'mac_address': '75:3c:ae:bd:3a:b5',\n", + " 4: {'uuid': '56f84a14-0a98-4bc5-983b-31900fc9a2c5',\n", + " 'mac_address': '61:62:18:cf:2a:ea',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 5: {'uuid': '8b5d575c-ab0c-43ac-abfc-fa5ae75183e5',\n", - " 'mac_address': 'e7:7f:c4:af:8e:5b',\n", + " 5: {'uuid': '0ff4b64e-be4c-473e-8dcd-b7a0078ff890',\n", + " 'mac_address': '21:5e:6b:1b:d0:bf',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 6: {'uuid': '9d3cd584-f684-4f2e-9c8a-423d859fe3d3',\n", - " 'mac_address': '48:cf:18:8d:92:80',\n", + " 6: {'uuid': '0edf239b-bbb8-4076-ba85-cb07c65722d5',\n", + " 'mac_address': '40:58:ac:11:9c:1a',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 7: {'uuid': 'd42338bb-d579-483d-9e05-0318e17e574a',\n", - " 'mac_address': 'c6:99:5c:41:13:d7',\n", + " 7: {'uuid': 'a7f578e5-a6f5-4cf8-abca-207e483637c2',\n", + " 'mac_address': 'e0:ef:90:e2:ce:b4',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 8: {'uuid': '55bbd70b-491d-4452-8326-390ec3fadc28',\n", - " 'mac_address': '81:ab:39:0c:a2:dd',\n", + " 8: {'uuid': 'dc2069dd-ef3c-4e0b-81cb-a73caba917a8',\n", + " 'mac_address': '2c:2a:27:d6:9a:a8',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 9: {'uuid': '0755d768-79c7-48cf-9220-d2dad32e574b',\n", - " 'mac_address': '62:35:0c:5e:cc:5d',\n", + " 9: {'uuid': 'afbc1a01-efdb-424c-9a7d-b3c3165f6d78',\n", + " 'mac_address': 'e0:f5:79:04:4f:2a',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 10: {'uuid': 'deaecc57-ec76-4e27-a37e-f66964901b03',\n", - " 'mac_address': '51:26:00:c6:7e:ac',\n", + " 10: {'uuid': 'bdd805f4-a3dc-4a94-ba67-3a62b138f41c',\n", + " 'mac_address': '9a:20:3d:cb:a0:98',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 11: {'uuid': '53fe318c-4969-42fe-920b-37a491f54d84',\n", - " 'mac_address': '35:59:c7:13:ab:a5',\n", + " 11: {'uuid': '19f6f871-cba9-423a-a1a5-6a0e347e98cb',\n", + " 'mac_address': '69:d9:8c:1d:a9:75',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}},\n", - " 12: {'uuid': '5a81caa0-9d91-4a86-9bd4-4ecb589c70ae',\n", - " 'mac_address': '7a:6b:ec:15:1e:de',\n", + " 12: {'uuid': '5c2aa6f5-12ce-466b-b46b-95ec519a5f47',\n", + " 'mac_address': 'db:7e:8c:91:1b:3f',\n", " 'speed': 100,\n", " 'mtu': 1500,\n", " 'enabled': False,\n", " 'nmne': {}}},\n", " 'num_ports': 12,\n", " 'mac_address_table': {}}},\n", - " 'links': {'primaite_pc:eth-2<->switch1:eth-1': {'uuid': '3d053257-7473-4a66-afbc-ee33a18f2e39',\n", - " 'endpoint_a': 'e0fbda66-afcb-4a79-b696-aad0778279a2',\n", - " 'endpoint_b': '7ebc80f5-902f-4253-8ea6-0cafa3d1cccd',\n", + " 'links': {'primaite_pc:eth-2<->switch1:eth-1': {'uuid': '405f3032-6f5d-427f-b42e-5eee4cdc3a7c',\n", + " 'endpoint_a': '40c0db02-4d14-4826-b49b-e6a521941cec',\n", + " 'endpoint_b': '3546e960-30f8-49ee-95b9-57570b228333',\n", " 'bandwidth': 100.0,\n", " 'current_load': 0.0,\n", " 'hostname_a': 'primaite_pc',\n", " 'hostname_b': 'switch1',\n", " 'port_a': 2,\n", " 'port_b': 1},\n", - " 'google_server:eth-2<->switch1:eth-2': {'uuid': '42b8f911-3640-4ccb-b277-b48b294a1fc8',\n", - " 'endpoint_a': '53993d8f-216e-4c00-9b03-c6bb9e2437b5',\n", - " 'endpoint_b': 'c03d4d22-f309-49b6-a1ad-45a04c40d25e',\n", + " 'google_server:eth-2<->switch1:eth-2': {'uuid': '2bd19485-0a6b-4878-978b-b082a672d9b9',\n", + " 'endpoint_a': '8a628493-83fb-44bf-a1b0-ef19e362ae5f',\n", + " 'endpoint_b': 'a049bb8f-53d3-4575-b325-dfb55516edcd',\n", " 'bandwidth': 100.0,\n", " 'current_load': 0.0,\n", " 'hostname_a': 'google_server',\n", " 'hostname_b': 'switch1',\n", " 'port_a': 2,\n", " 'port_b': 2}}},\n", - " 'domain': {'uuid': 'f0629156-e9af-493d-b098-f47d73126122',\n", - " 'accounts': {'admin': {'uuid': 'b76653a9-d40e-483b-85a3-1b44628a11d0',\n", + " 'domain': {'uuid': '25fbe0e9-76e8-4fd7-ad22-da2d2b5a509d',\n", + " 'accounts': {'admin': {'uuid': '78783f13-6149-47b3-9b9d-f98d658bf54a',\n", " 'num_logons': 0,\n", " 'num_logoffs': 0,\n", " 'num_group_changes': 0,\n", @@ -748,7 +748,7 @@ " 'enabled': True}}}}" ] }, - "execution_count": 133, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -759,16 +759,16 @@ }, { "cell_type": "code", - "execution_count": 134, + "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'{\"uuid\": \"42d005b2-4dc8-4aec-be54-3493242eee32\", \"network\": {\"uuid\": \"069f61a4-ac40-431f-ad13-2fc9b26dc091\", \"nodes\": {\"primaite_pc\": {\"uuid\": \"52246eed-9a3f-4b19-ad0c-48fc3bbb998d\", \"hostname\": \"primaite_pc\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"73dcb42e-7db4-45cf-b439-9b8066c8e32e\", \"mac_address\": \"c9:84:ec:48:87:77\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"192.168.1.10\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}, \"2\": {\"uuid\": \"e0fbda66-afcb-4a79-b696-aad0778279a2\", \"mac_address\": \"cb:66:8b:b2:dc:51\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}}, \"file_system\": {\"uuid\": \"8a857927-dd5e-40e9-86fd-1df8b3a2b463\", \"folders\": {\"root\": {\"uuid\": \"acb725c9-461e-40c5-b2c0-ed198865e1f2\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}, \"downloads\": {\"uuid\": \"484f7bcf-b8da-4995-8538-82b2a4d059c7\", \"name\": \"downloads\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {\"firefox_installer.zip\": {\"uuid\": \"5e1e5bec-a984-4ae1-9799-78083bd2e3c2\", \"name\": \"firefox_installer.zip\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"size\": 1024000, \"file_type\": \"ZIP\", \"num_access\": 0}}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 0, \"num_file_deletions\": 0}, \"applications\": {\"WebBrowser\": {\"uuid\": \"5987fc38-686d-439f-b513-23166884596e\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 2, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": [], \"history\": []}, \"mspaint\": {\"uuid\": \"88eb36c5-dba4-4f79-ad95-5957f7de3fa2\", \"health_state_actual\": 1, \"health_state_visible\": 1, \"criticality\": 3, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 1, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {\"ARP\": {\"uuid\": \"e220dde6-88d5-4e24-a2de-5bce0cd4a916\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 219, \"operating_state\": 2}, \"ICMP\": {\"uuid\": \"ef728c73-97b7-480f-bedb-04dc3d5efd57\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 0, \"operating_state\": 2}, \"DNSClient\": {\"uuid\": \"30b159f1-a4e8-41f5-923b-c692d104f385\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 53, \"operating_state\": 2}, \"FTPClient\": {\"uuid\": \"5f267d5f-6bb8-4e97-b6b9-855ee2d50c25\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 21, \"operating_state\": 2}, \"NTPClient\": {\"uuid\": \"1ea99f1e-dc04-4548-a384-913851a7e4fd\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 123, \"operating_state\": 2}}, \"process\": {}, \"revealed_to_red\": false}, \"google_server\": {\"uuid\": \"b9a41d9c-6642-441b-8049-8302ddafd3b1\", \"hostname\": \"google_server\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"d0736beb-085a-4754-8b44-de73e6a8c80f\", \"mac_address\": \"45:27:ed:64:ac:09\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"192.168.1.11\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}, \"2\": {\"uuid\": \"53993d8f-216e-4c00-9b03-c6bb9e2437b5\", \"mac_address\": \"17:9d:82:db:ca:c8\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}}, \"file_system\": {\"uuid\": \"8d4ded3a-56bb-46f0-ad7f-40d65b523581\", \"folders\": {\"root\": {\"uuid\": \"7a86576b-607f-468b-826f-4834cf2b3511\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {\"favicon.ico\": {\"uuid\": \"24789051-6762-48f4-8a56-c28882374273\", \"name\": \"favicon.ico\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"size\": 0, \"file_type\": \"UNKNOWN\", \"num_access\": 0}}, \"deleted_files\": {}}, \"static\": {\"uuid\": \"154b2ad3-e43d-4924-b758-e11db0e176de\", \"name\": \"static\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 1, \"num_file_deletions\": 0}, \"applications\": {\"WebBrowser\": {\"uuid\": \"9b368321-e22d-4e35-9395-80632492c20a\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 2, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": [], \"history\": []}}, \"services\": {\"ARP\": {\"uuid\": \"30df82c0-5823-4464-8c23-5b99922f98f7\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 219, \"operating_state\": 2}, \"ICMP\": {\"uuid\": \"2d02a2de-7ec8-4da1-9538-c85eb397d4e3\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 0, \"operating_state\": 2}, \"DNSClient\": {\"uuid\": \"db979263-ff81-4a04-95e8-d94442e9ddfa\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 53, \"operating_state\": 2}, \"FTPClient\": {\"uuid\": \"d9d6417b-d1e0-416b-a711-3478fa248194\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 21, \"operating_state\": 2}, \"NTPClient\": {\"uuid\": \"b23a1032-a817-492b-bdd6-2ecc6fb4591c\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 123, \"operating_state\": 2}}, \"process\": {}, \"revealed_to_red\": false}, \"switch1\": {\"uuid\": \"e658eac3-c4b8-4768-bf27-e2d90b7f57c0\", \"hostname\": \"switch1\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"7ebc80f5-902f-4253-8ea6-0cafa3d1cccd\", \"mac_address\": \"df:d2:c7:2a:a1:52\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"2\": {\"uuid\": \"c03d4d22-f309-49b6-a1ad-45a04c40d25e\", \"mac_address\": \"84:01:f3:bb:47:1c\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"3\": {\"uuid\": \"4207353c-e0cd-456d-89fe-13ddfc605cff\", \"mac_address\": \"8b:31:ac:cc:05:c9\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"4\": {\"uuid\": \"8aa1395f-e360-48a7-be97-ed1a5ca191ae\", \"mac_address\": \"75:3c:ae:bd:3a:b5\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"5\": {\"uuid\": \"8b5d575c-ab0c-43ac-abfc-fa5ae75183e5\", \"mac_address\": \"e7:7f:c4:af:8e:5b\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"6\": {\"uuid\": \"9d3cd584-f684-4f2e-9c8a-423d859fe3d3\", \"mac_address\": \"48:cf:18:8d:92:80\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"7\": {\"uuid\": \"d42338bb-d579-483d-9e05-0318e17e574a\", \"mac_address\": \"c6:99:5c:41:13:d7\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"8\": {\"uuid\": \"55bbd70b-491d-4452-8326-390ec3fadc28\", \"mac_address\": \"81:ab:39:0c:a2:dd\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"9\": {\"uuid\": \"0755d768-79c7-48cf-9220-d2dad32e574b\", \"mac_address\": \"62:35:0c:5e:cc:5d\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"10\": {\"uuid\": \"deaecc57-ec76-4e27-a37e-f66964901b03\", \"mac_address\": \"51:26:00:c6:7e:ac\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"11\": {\"uuid\": \"53fe318c-4969-42fe-920b-37a491f54d84\", \"mac_address\": \"35:59:c7:13:ab:a5\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"12\": {\"uuid\": \"5a81caa0-9d91-4a86-9bd4-4ecb589c70ae\", \"mac_address\": \"7a:6b:ec:15:1e:de\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}}, \"file_system\": {\"uuid\": \"289bea1e-69bf-44d5-80fe-212dad8afcd5\", \"folders\": {\"root\": {\"uuid\": \"3b588b3c-bc4a-4c06-a688-eced0128b128\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 0, \"num_file_deletions\": 0}, \"applications\": {}, \"services\": {}, \"process\": {}, \"revealed_to_red\": false, \"ports\": {\"1\": {\"uuid\": \"7ebc80f5-902f-4253-8ea6-0cafa3d1cccd\", \"mac_address\": \"df:d2:c7:2a:a1:52\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"2\": {\"uuid\": \"c03d4d22-f309-49b6-a1ad-45a04c40d25e\", \"mac_address\": \"84:01:f3:bb:47:1c\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"3\": {\"uuid\": \"4207353c-e0cd-456d-89fe-13ddfc605cff\", \"mac_address\": \"8b:31:ac:cc:05:c9\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"4\": {\"uuid\": \"8aa1395f-e360-48a7-be97-ed1a5ca191ae\", \"mac_address\": \"75:3c:ae:bd:3a:b5\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"5\": {\"uuid\": \"8b5d575c-ab0c-43ac-abfc-fa5ae75183e5\", \"mac_address\": \"e7:7f:c4:af:8e:5b\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"6\": {\"uuid\": \"9d3cd584-f684-4f2e-9c8a-423d859fe3d3\", \"mac_address\": \"48:cf:18:8d:92:80\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"7\": {\"uuid\": \"d42338bb-d579-483d-9e05-0318e17e574a\", \"mac_address\": \"c6:99:5c:41:13:d7\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"8\": {\"uuid\": \"55bbd70b-491d-4452-8326-390ec3fadc28\", \"mac_address\": \"81:ab:39:0c:a2:dd\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"9\": {\"uuid\": \"0755d768-79c7-48cf-9220-d2dad32e574b\", \"mac_address\": \"62:35:0c:5e:cc:5d\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"10\": {\"uuid\": \"deaecc57-ec76-4e27-a37e-f66964901b03\", \"mac_address\": \"51:26:00:c6:7e:ac\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"11\": {\"uuid\": \"53fe318c-4969-42fe-920b-37a491f54d84\", \"mac_address\": \"35:59:c7:13:ab:a5\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"12\": {\"uuid\": \"5a81caa0-9d91-4a86-9bd4-4ecb589c70ae\", \"mac_address\": \"7a:6b:ec:15:1e:de\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}}, \"num_ports\": 12, \"mac_address_table\": {}}}, \"links\": {\"primaite_pc:eth-2<->switch1:eth-1\": {\"uuid\": \"3d053257-7473-4a66-afbc-ee33a18f2e39\", \"endpoint_a\": \"e0fbda66-afcb-4a79-b696-aad0778279a2\", \"endpoint_b\": \"7ebc80f5-902f-4253-8ea6-0cafa3d1cccd\", \"bandwidth\": 100.0, \"current_load\": 0.0, \"hostname_a\": \"primaite_pc\", \"hostname_b\": \"switch1\", \"port_a\": 2, \"port_b\": 1}, \"google_server:eth-2<->switch1:eth-2\": {\"uuid\": \"42b8f911-3640-4ccb-b277-b48b294a1fc8\", \"endpoint_a\": \"53993d8f-216e-4c00-9b03-c6bb9e2437b5\", \"endpoint_b\": \"c03d4d22-f309-49b6-a1ad-45a04c40d25e\", \"bandwidth\": 100.0, \"current_load\": 0.0, \"hostname_a\": \"google_server\", \"hostname_b\": \"switch1\", \"port_a\": 2, \"port_b\": 2}}}, \"domain\": {\"uuid\": \"f0629156-e9af-493d-b098-f47d73126122\", \"accounts\": {\"admin\": {\"uuid\": \"b76653a9-d40e-483b-85a3-1b44628a11d0\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": 2, \"enabled\": true}}}}'" + "'{\"uuid\": \"91c88b2a-caf1-47be-a394-d0c22e5110be\", \"network\": {\"uuid\": \"a9121808-0401-460c-9833-23d4ba91e9bc\", \"nodes\": {\"primaite_pc\": {\"uuid\": \"dd0e95be-2491-4d5b-8388-df3975a19e8a\", \"hostname\": \"primaite_pc\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"279e2645-b680-4d2e-b13c-66d5cfacbd38\", \"mac_address\": \"bd:76:20:24:cf:04\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"192.168.1.10\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}, \"2\": {\"uuid\": \"40c0db02-4d14-4826-b49b-e6a521941cec\", \"mac_address\": \"d8:b2:0c:af:3f:83\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}}, \"file_system\": {\"uuid\": \"91d3aed7-53c6-471f-b903-9889396be280\", \"folders\": {\"root\": {\"uuid\": \"81bdc04e-9a0d-4306-9a9c-ee926fff6df8\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}, \"downloads\": {\"uuid\": \"56abdf27-b8d4-42f4-9b09-b7912db1c4f3\", \"name\": \"downloads\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {\"firefox_installer.zip\": {\"uuid\": \"02236b61-14bb-46aa-9fd5-7174c0d7d730\", \"name\": \"firefox_installer.zip\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"size\": 1024000, \"file_type\": \"ZIP\", \"num_access\": 0}}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 0, \"num_file_deletions\": 0}, \"applications\": {\"WebBrowser\": {\"uuid\": \"a6a12776-e307-4d71-9e7a-d9ca97ecd6b0\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 2, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": [], \"history\": []}, \"mspaint\": {\"uuid\": \"efd34549-cc92-4474-80ab-5fb6c3159ff6\", \"health_state_actual\": 1, \"health_state_visible\": 1, \"criticality\": 3, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 1, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {\"ARP\": {\"uuid\": \"e61c25ff-a6c2-4eec-b031-131eaf33490c\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 219, \"operating_state\": 2}, \"ICMP\": {\"uuid\": \"74debeed-b758-41cb-bea2-51ac283e6ae2\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 0, \"operating_state\": 2}, \"DNSClient\": {\"uuid\": \"6680efc0-e005-41e8-bb49-39a0d9c4b118\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 53, \"operating_state\": 2}, \"FTPClient\": {\"uuid\": \"21b05ac9-e9b4-4c5c-a812-f6748e14d8c3\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 21, \"operating_state\": 2}, \"NTPClient\": {\"uuid\": \"7ab7c911-5037-4e82-b00c-be4f72c13aa7\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 123, \"operating_state\": 2}}, \"process\": {}, \"revealed_to_red\": false}, \"google_server\": {\"uuid\": \"42d61d8d-2493-4b8a-944f-7962abc9d20b\", \"hostname\": \"google_server\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"e384a4fc-754f-44a4-9158-c63f72f52f76\", \"mac_address\": \"ea:5d:4f:10:b2:27\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"192.168.1.11\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}, \"2\": {\"uuid\": \"8a628493-83fb-44bf-a1b0-ef19e362ae5f\", \"mac_address\": \"44:89:a5:ce:7f:6f\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}}, \"file_system\": {\"uuid\": \"f25cee1f-2ebe-4fd3-8d5c-649b0d342b61\", \"folders\": {\"root\": {\"uuid\": \"cbbd3631-a915-400d-bc02-f31f72447ce5\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {\"favicon.ico\": {\"uuid\": \"3ceeded4-77b9-4a86-949c-73188d5f4c34\", \"name\": \"favicon.ico\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"size\": 0, \"file_type\": \"UNKNOWN\", \"num_access\": 0}}, \"deleted_files\": {}}, \"static\": {\"uuid\": \"d8241ce0-f55e-43ec-bd68-741b79a9a565\", \"name\": \"static\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 1, \"num_file_deletions\": 0}, \"applications\": {\"WebBrowser\": {\"uuid\": \"957d0049-e703-4882-8e57-b2ab4c79d458\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 2, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": [], \"history\": []}}, \"services\": {\"ARP\": {\"uuid\": \"82ea1bcf-a0fe-418d-873e-5f075ebb4d3b\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 219, \"operating_state\": 2}, \"ICMP\": {\"uuid\": \"bc084dc4-0a7d-4954-9e6e-54bed797e837\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 0, \"operating_state\": 2}, \"DNSClient\": {\"uuid\": \"5a9ecc18-71c0-4728-a9c6-e31b33529581\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 53, \"operating_state\": 2}, \"FTPClient\": {\"uuid\": \"f0a411eb-5423-4c98-8689-d94af57deefc\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 21, \"operating_state\": 2}, \"NTPClient\": {\"uuid\": \"d36f2c4f-af30-4618-ae8e-fe68c98e1382\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 123, \"operating_state\": 2}}, \"process\": {}, \"revealed_to_red\": false}, \"switch1\": {\"uuid\": \"a9e08b28-d1f4-4c34-b410-71333cd6b42b\", \"hostname\": \"switch1\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"3546e960-30f8-49ee-95b9-57570b228333\", \"mac_address\": \"8d:d9:3e:f3:a3:ce\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"2\": {\"uuid\": \"a049bb8f-53d3-4575-b325-dfb55516edcd\", \"mac_address\": \"aa:45:88:e1:13:e5\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"3\": {\"uuid\": \"179c030c-d8fe-474b-a9d1-6c6bd6e6ca63\", \"mac_address\": \"10:d7:bc:39:4d:9d\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"4\": {\"uuid\": \"56f84a14-0a98-4bc5-983b-31900fc9a2c5\", \"mac_address\": \"61:62:18:cf:2a:ea\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"5\": {\"uuid\": \"0ff4b64e-be4c-473e-8dcd-b7a0078ff890\", \"mac_address\": \"21:5e:6b:1b:d0:bf\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"6\": {\"uuid\": \"0edf239b-bbb8-4076-ba85-cb07c65722d5\", \"mac_address\": \"40:58:ac:11:9c:1a\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"7\": {\"uuid\": \"a7f578e5-a6f5-4cf8-abca-207e483637c2\", \"mac_address\": \"e0:ef:90:e2:ce:b4\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"8\": {\"uuid\": \"dc2069dd-ef3c-4e0b-81cb-a73caba917a8\", \"mac_address\": \"2c:2a:27:d6:9a:a8\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"9\": {\"uuid\": \"afbc1a01-efdb-424c-9a7d-b3c3165f6d78\", \"mac_address\": \"e0:f5:79:04:4f:2a\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"10\": {\"uuid\": \"bdd805f4-a3dc-4a94-ba67-3a62b138f41c\", \"mac_address\": \"9a:20:3d:cb:a0:98\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"11\": {\"uuid\": \"19f6f871-cba9-423a-a1a5-6a0e347e98cb\", \"mac_address\": \"69:d9:8c:1d:a9:75\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"12\": {\"uuid\": \"5c2aa6f5-12ce-466b-b46b-95ec519a5f47\", \"mac_address\": \"db:7e:8c:91:1b:3f\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}}, \"file_system\": {\"uuid\": \"91dea1d3-3947-49b9-a691-750bc25bbb9c\", \"folders\": {\"root\": {\"uuid\": \"b7ebbf43-d86f-43d3-bbc7-f6b197af40b9\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 0, \"num_file_deletions\": 0}, \"applications\": {}, \"services\": {}, \"process\": {}, \"revealed_to_red\": false, \"ports\": {\"1\": {\"uuid\": \"3546e960-30f8-49ee-95b9-57570b228333\", \"mac_address\": \"8d:d9:3e:f3:a3:ce\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"2\": {\"uuid\": \"a049bb8f-53d3-4575-b325-dfb55516edcd\", \"mac_address\": \"aa:45:88:e1:13:e5\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"3\": {\"uuid\": \"179c030c-d8fe-474b-a9d1-6c6bd6e6ca63\", \"mac_address\": \"10:d7:bc:39:4d:9d\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"4\": {\"uuid\": \"56f84a14-0a98-4bc5-983b-31900fc9a2c5\", \"mac_address\": \"61:62:18:cf:2a:ea\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"5\": {\"uuid\": \"0ff4b64e-be4c-473e-8dcd-b7a0078ff890\", \"mac_address\": \"21:5e:6b:1b:d0:bf\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"6\": {\"uuid\": \"0edf239b-bbb8-4076-ba85-cb07c65722d5\", \"mac_address\": \"40:58:ac:11:9c:1a\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"7\": {\"uuid\": \"a7f578e5-a6f5-4cf8-abca-207e483637c2\", \"mac_address\": \"e0:ef:90:e2:ce:b4\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"8\": {\"uuid\": \"dc2069dd-ef3c-4e0b-81cb-a73caba917a8\", \"mac_address\": \"2c:2a:27:d6:9a:a8\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"9\": {\"uuid\": \"afbc1a01-efdb-424c-9a7d-b3c3165f6d78\", \"mac_address\": \"e0:f5:79:04:4f:2a\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"10\": {\"uuid\": \"bdd805f4-a3dc-4a94-ba67-3a62b138f41c\", \"mac_address\": \"9a:20:3d:cb:a0:98\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"11\": {\"uuid\": \"19f6f871-cba9-423a-a1a5-6a0e347e98cb\", \"mac_address\": \"69:d9:8c:1d:a9:75\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"12\": {\"uuid\": \"5c2aa6f5-12ce-466b-b46b-95ec519a5f47\", \"mac_address\": \"db:7e:8c:91:1b:3f\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}}, \"num_ports\": 12, \"mac_address_table\": {}}}, \"links\": {\"primaite_pc:eth-2<->switch1:eth-1\": {\"uuid\": \"405f3032-6f5d-427f-b42e-5eee4cdc3a7c\", \"endpoint_a\": \"40c0db02-4d14-4826-b49b-e6a521941cec\", \"endpoint_b\": \"3546e960-30f8-49ee-95b9-57570b228333\", \"bandwidth\": 100.0, \"current_load\": 0.0, \"hostname_a\": \"primaite_pc\", \"hostname_b\": \"switch1\", \"port_a\": 2, \"port_b\": 1}, \"google_server:eth-2<->switch1:eth-2\": {\"uuid\": \"2bd19485-0a6b-4878-978b-b082a672d9b9\", \"endpoint_a\": \"8a628493-83fb-44bf-a1b0-ef19e362ae5f\", \"endpoint_b\": \"a049bb8f-53d3-4575-b325-dfb55516edcd\", \"bandwidth\": 100.0, \"current_load\": 0.0, \"hostname_a\": \"google_server\", \"hostname_b\": \"switch1\", \"port_a\": 2, \"port_b\": 2}}}, \"domain\": {\"uuid\": \"25fbe0e9-76e8-4fd7-ad22-da2d2b5a509d\", \"accounts\": {\"admin\": {\"uuid\": \"78783f13-6149-47b3-9b9d-f98d658bf54a\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": 2, \"enabled\": true}}}}'" ] }, - "execution_count": 134, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } diff --git a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb index 47703c9c..7a095b53 100644 --- a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb +++ b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb @@ -141,16 +141,16 @@ "+------------+----------------------------------------+-------------------+------------------------------------------+-------+-------------------+--------------+\n", "| Endpoint A | A Port | Endpoint B | B Port | is Up | Bandwidth (MBits) | Current Load |\n", "+------------+----------------------------------------+-------------------+------------------------------------------+-------+-------------------+--------------+\n", - "| router_1 | Port 2: eb:31:e8:11:28:ac/192.168.10.1 | switch_2 | Port 8: d3:59:e2:73:4e:b8 | True | 100.0 | 0.00006% |\n", - "| router_1 | Port 1: 3f:c3:3d:00:74:c4/192.168.1.1 | switch_1 | Port 8: a9:ea:54:9f:35:f8 | True | 100.0 | 0.00018% |\n", - "| switch_1 | Port 7: 63:ea:45:e6:f4:22 | security_suite | Port 1: 18:9d:a1:f0:6f:0b/192.168.1.110 | True | 100.0 | 0.00003% |\n", - "| switch_1 | Port 4: 08:0e:a9:03:d7:3c | backup_server | Port 1: c3:e5:81:c9:8b:74/192.168.1.16 | True | 100.0 | 0.00003% |\n", - "| switch_1 | Port 2: 75:c5:30:0f:5d:92 | web_server | Port 1: 90:94:52:a6:1f:c5/192.168.1.12 | True | 100.0 | 0.00015% |\n", - "| switch_1 | Port 3: f1:62:75:5d:d9:59 | database_server | Port 1: 2e:e8:cb:a5:97:12/192.168.1.14 | True | 100.0 | 0.00017% |\n", - "| switch_1 | Port 1: 08:79:a7:3f:b5:96 | domain_controller | Port 1: 00:c3:ff:62:87:8f/192.168.1.10 | True | 100.0 | 0.00003% |\n", - "| switch_2 | Port 7: 88:9c:57:5c:53:5e | security_suite | Port 2: 9e:b2:c8:04:d8:97/192.168.10.110 | True | 100.0 | 0.00000% |\n", - "| switch_2 | Port 2: a8:1b:b2:78:12:34 | client_2 | Port 1: 6a:b1:ff:36:ef:40/192.168.10.22 | True | 100.0 | 0.00003% |\n", - "| switch_2 | Port 1: 42:08:3f:1e:ea:dd | client_1 | Port 1: f6:6d:35:8a:67:d8/192.168.10.21 | True | 100.0 | 0.00003% |\n", + "| router_1 | Port 2: 6e:3e:9f:58:c3:f8/192.168.10.1 | switch_2 | Port 8: 00:a7:49:9f:b7:40 | True | 100.0 | 0.00006% |\n", + "| router_1 | Port 1: 7c:0a:49:bd:2d:5f/192.168.1.1 | switch_1 | Port 8: e6:5e:9e:61:f6:71 | True | 100.0 | 0.00018% |\n", + "| switch_1 | Port 7: 8c:96:32:d5:ef:4b | security_suite | Port 1: 92:17:67:5f:09:f0/192.168.1.110 | True | 100.0 | 0.00003% |\n", + "| switch_1 | Port 4: ef:da:44:ee:68:1d | backup_server | Port 1: 82:23:ff:c5:03:45/192.168.1.16 | True | 100.0 | 0.00003% |\n", + "| switch_1 | Port 2: ab:84:4b:96:bc:b6 | web_server | Port 1: 30:3c:b4:54:b2:ef/192.168.1.12 | True | 100.0 | 0.00015% |\n", + "| switch_1 | Port 3: d8:07:d0:d6:27:52 | database_server | Port 1: 7c:cd:b5:ba:46:33/192.168.1.14 | True | 100.0 | 0.00017% |\n", + "| switch_1 | Port 1: e0:06:93:2c:45:cf | domain_controller | Port 1: 6d:3e:3e:b3:f6:6f/192.168.1.10 | True | 100.0 | 0.00003% |\n", + "| switch_2 | Port 7: 4f:55:6c:c3:ff:e9 | security_suite | Port 2: 64:6f:aa:ba:cb:d0/192.168.10.110 | True | 100.0 | 0.00000% |\n", + "| switch_2 | Port 2: f7:42:43:63:75:c9 | client_2 | Port 1: 21:bb:1b:75:02:fb/192.168.10.22 | True | 100.0 | 0.00003% |\n", + "| switch_2 | Port 1: 45:93:50:03:48:f5 | client_1 | Port 1: ca:f5:26:85:a7:54/192.168.10.21 | True | 100.0 | 0.00003% |\n", "+------------+----------------------------------------+-------------------+------------------------------------------+-------+-------------------+--------------+\n" ] } @@ -206,11 +206,11 @@ "+------+-------------------+-----------------+-------+----------+\n", "| Port | MAC Address | Address | Speed | Status |\n", "+------+-------------------+-----------------+-------+----------+\n", - "| 1 | 3f:c3:3d:00:74:c4 | 192.168.1.1/24 | 100 | Enabled |\n", - "| 2 | eb:31:e8:11:28:ac | 192.168.10.1/24 | 100 | Enabled |\n", - "| 3 | 7b:4f:23:8d:b5:18 | 127.0.0.1/8 | 100 | Disabled |\n", - "| 4 | cd:89:ba:42:ee:04 | 127.0.0.1/8 | 100 | Disabled |\n", - "| 5 | 8d:92:27:76:79:c5 | 127.0.0.1/8 | 100 | Disabled |\n", + "| 1 | 7c:0a:49:bd:2d:5f | 192.168.1.1/24 | 100 | Enabled |\n", + "| 2 | 6e:3e:9f:58:c3:f8 | 192.168.10.1/24 | 100 | Enabled |\n", + "| 3 | 44:c9:4c:25:4c:9b | 127.0.0.1/8 | 100 | Disabled |\n", + "| 4 | 4a:99:e4:a0:87:ba | 127.0.0.1/8 | 100 | Disabled |\n", + "| 5 | ca:5c:3b:6e:52:ef | 127.0.0.1/8 | 100 | Disabled |\n", "+------+-------------------+-----------------+-------+----------+\n" ] } @@ -244,13 +244,13 @@ "+---------------+-------------------+-------------------+\n", "| IP Address | MAC Address | Via |\n", "+---------------+-------------------+-------------------+\n", - "| 192.168.10.21 | f6:6d:35:8a:67:d8 | eb:31:e8:11:28:ac |\n", - "| 192.168.10.22 | 6a:b1:ff:36:ef:40 | eb:31:e8:11:28:ac |\n", - "| 192.168.1.10 | 00:c3:ff:62:87:8f | 3f:c3:3d:00:74:c4 |\n", - "| 192.168.1.14 | 2e:e8:cb:a5:97:12 | 3f:c3:3d:00:74:c4 |\n", - "| 192.168.1.12 | 90:94:52:a6:1f:c5 | 3f:c3:3d:00:74:c4 |\n", - "| 192.168.1.16 | c3:e5:81:c9:8b:74 | 3f:c3:3d:00:74:c4 |\n", - "| 192.168.1.110 | 18:9d:a1:f0:6f:0b | 3f:c3:3d:00:74:c4 |\n", + "| 192.168.10.21 | ca:f5:26:85:a7:54 | 6e:3e:9f:58:c3:f8 |\n", + "| 192.168.10.22 | 21:bb:1b:75:02:fb | 6e:3e:9f:58:c3:f8 |\n", + "| 192.168.1.10 | 6d:3e:3e:b3:f6:6f | 7c:0a:49:bd:2d:5f |\n", + "| 192.168.1.14 | 7c:cd:b5:ba:46:33 | 7c:0a:49:bd:2d:5f |\n", + "| 192.168.1.12 | 30:3c:b4:54:b2:ef | 7c:0a:49:bd:2d:5f |\n", + "| 192.168.1.16 | 82:23:ff:c5:03:45 | 7c:0a:49:bd:2d:5f |\n", + "| 192.168.1.110 | 92:17:67:5f:09:f0 | 7c:0a:49:bd:2d:5f |\n", "+---------------+-------------------+-------------------+\n" ] } @@ -385,7 +385,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 9, "id": "e7fd439b-5442-4e9d-9e7d-86dacb77f458", "metadata": { "tags": [] @@ -400,28 +400,14 @@ "+------+-------------------+-------+----------+\n", "| Port | MAC Address | Speed | Status |\n", "+------+-------------------+-------+----------+\n", - "| 1 | 08:79:a7:3f:b5:96 | 100 | Enabled |\n", - "| 2 | 75:c5:30:0f:5d:92 | 100 | Enabled |\n", - "| 3 | f1:62:75:5d:d9:59 | 100 | Enabled |\n", - "| 4 | 08:0e:a9:03:d7:3c | 100 | Enabled |\n", - "| 5 | ae:40:29:58:c7:95 | 100 | Disabled |\n", - "| 6 | 7d:54:38:7f:79:e8 | 100 | Disabled |\n", - "| 7 | 63:ea:45:e6:f4:22 | 100 | Enabled |\n", - "| 8 | a9:ea:54:9f:35:f8 | 100 | Enabled |\n", - "+------+-------------------+-------+----------+\n", - "+---------------------------------------------+\n", - "| switch_2 Switch Ports |\n", - "+------+-------------------+-------+----------+\n", - "| Port | MAC Address | Speed | Status |\n", - "+------+-------------------+-------+----------+\n", - "| 1 | 42:08:3f:1e:ea:dd | 100 | Enabled |\n", - "| 2 | a8:1b:b2:78:12:34 | 100 | Enabled |\n", - "| 3 | 43:e4:54:fe:e7:1f | 100 | Disabled |\n", - "| 4 | 24:bf:74:7c:c4:11 | 100 | Disabled |\n", - "| 5 | 4b:57:f7:46:c9:4f | 100 | Disabled |\n", - "| 6 | 10:03:9d:39:0c:81 | 100 | Disabled |\n", - "| 7 | 88:9c:57:5c:53:5e | 100 | Enabled |\n", - "| 8 | d3:59:e2:73:4e:b8 | 100 | Enabled |\n", + "| 1 | e0:06:93:2c:45:cf | 100 | Enabled |\n", + "| 2 | ab:84:4b:96:bc:b6 | 100 | Enabled |\n", + "| 3 | d8:07:d0:d6:27:52 | 100 | Enabled |\n", + "| 4 | ef:da:44:ee:68:1d | 100 | Enabled |\n", + "| 5 | b6:76:3d:1d:7e:be | 100 | Disabled |\n", + "| 6 | 02:ce:fa:da:9a:a4 | 100 | Disabled |\n", + "| 7 | 8c:96:32:d5:ef:4b | 100 | Enabled |\n", + "| 8 | e6:5e:9e:61:f6:71 | 100 | Enabled |\n", "+------+-------------------+-------+----------+\n" ] } @@ -430,42 +416,6 @@ "network.get_node_by_hostname(\"switch_1\").show()" ] }, - { - "cell_type": "markdown", - "id": "beb8dbd6-7250-4ac9-9fa2-d2a9c0e5fd19", - "metadata": { - "tags": [] - }, - "source": [ - "Calling `switch.arp.show()` displays the Switch ARP Cache." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "d06e1310-4a77-4315-a59f-cb1b49ca2352", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+--------------------------------+\n", - "| switch_1 ARP Cache |\n", - "+------------+-------------+-----+\n", - "| IP Address | MAC Address | Via |\n", - "+------------+-------------+-----+\n", - "+------------+-------------+-----+\n" - ] - } - ], - "source": [ - "network.get_node_by_hostname(\"switch_1\").arp.show()\n", - "#network.get_node_by_hostname(\"switch_1\").software_manager" - ] - }, { "cell_type": "markdown", "id": "fda75ac3-8123-4234-8f36-86547891d8df", @@ -476,7 +426,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "id": "a0d984b7-a7c1-4bbd-aa5a-9d3caecb08dc", "metadata": { "tags": [] @@ -521,7 +471,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "id": "656c37f6-b145-42af-9714-8d2886d0eff8", "metadata": { "tags": [] @@ -536,8 +486,8 @@ "+------+------+-------------------+-------------------+-------+---------+\n", "| Port | Type | MAC Address | Address | Speed | Status |\n", "+------+------+-------------------+-------------------+-------+---------+\n", - "| 1 | NIC | 18:9d:a1:f0:6f:0b | 192.168.1.110/24 | 100 | Enabled |\n", - "| 2 | NIC | 9e:b2:c8:04:d8:97 | 192.168.10.110/24 | 100 | Enabled |\n", + "| 1 | NIC | 92:17:67:5f:09:f0 | 192.168.1.110/24 | 100 | Enabled |\n", + "| 2 | NIC | 64:6f:aa:ba:cb:d0 | 192.168.10.110/24 | 100 | Enabled |\n", "+------+------+-------------------+-------------------+-------+---------+\n", "+---------------------------+\n", "| security_suite Open Ports |\n", @@ -567,7 +517,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "id": "66b267d6-2308-486a-b9aa-cb8d3bcf0753", "metadata": { "tags": [] @@ -582,7 +532,7 @@ "+-------------+-------------------+-------------------+\n", "| IP Address | MAC Address | Via |\n", "+-------------+-------------------+-------------------+\n", - "| 192.168.1.1 | 3f:c3:3d:00:74:c4 | 18:9d:a1:f0:6f:0b |\n", + "| 192.168.1.1 | 7c:0a:49:bd:2d:5f | 92:17:67:5f:09:f0 |\n", "+-------------+-------------------+-------------------+\n" ] } @@ -601,7 +551,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "id": "1b5debe8-ef1b-445d-8fa9-6a45568f21f3", "metadata": { "tags": [] @@ -636,7 +586,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "id": "495b7de4-b6ce-41a6-9114-f74752ab4491", "metadata": { "tags": [] @@ -682,7 +632,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "id": "a38abb71-994e-49e8-8f51-e9a550e95b99", "metadata": { "tags": [] @@ -706,7 +656,7 @@ "True" ] }, - "execution_count": 16, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -717,7 +667,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "id": "8388e1e9-30e3-4534-8e5a-c6e9144149d2", "metadata": { "tags": [] @@ -750,7 +700,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "id": "ff8e976a-c16b-470c-8923-325713a30d6c", "metadata": { "tags": [] @@ -774,7 +724,7 @@ "True" ] }, - "execution_count": 18, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -793,7 +743,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "id": "c4163f8d-6a72-410c-9f5c-4f881b7de45e", "metadata": { "tags": [] @@ -817,7 +767,7 @@ "True" ] }, - "execution_count": 19, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -836,7 +786,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 19, "id": "e79a523a-5780-45b6-8798-c434e0e522bd", "metadata": { "tags": [] @@ -879,7 +829,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "id": "603cf913-e261-49da-a7dd-85e1bb6dec56", "metadata": { "tags": [] @@ -903,7 +853,7 @@ "True" ] }, - "execution_count": 21, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -922,7 +872,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "id": "e047de00-3de4-4823-b26a-2c8d64c7a663", "metadata": { "tags": [] @@ -955,7 +905,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 22, "id": "6db355ae-b99a-441b-a2c4-4ffe78f46bff", "metadata": { "tags": [] @@ -967,7 +917,7 @@ "True" ] }, - "execution_count": 23, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -986,7 +936,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 23, "id": "a345e000-8842-4827-af96-adc0fbe390fb", "metadata": { "tags": [] @@ -1026,7 +976,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 24, "id": "a4f4ff31-590f-40fb-b13d-efaa8c2720b6", "metadata": { "tags": [] @@ -1046,7 +996,7 @@ "False" ] }, - "execution_count": 25, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -1065,7 +1015,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 25, "id": "f62b8a4e-fd3b-4059-b108-3d4a0b18f2a0", "metadata": { "tags": [] @@ -1098,7 +1048,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 26, "id": "7e53d776-99da-4d2c-a2a7-bd7ce27bff4c", "metadata": { "tags": [] @@ -1131,7 +1081,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 27, "id": "d542734b-7582-4af7-8254-bda3de50d091", "metadata": { "tags": [] @@ -1155,7 +1105,7 @@ "True" ] }, - "execution_count": 28, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -1166,7 +1116,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 28, "id": "d78e9fe3-02c6-4792-944f-5622e26e0412", "metadata": { "tags": [] diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index 9d08b9f4..e354d96a 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -318,6 +318,12 @@ class HostNode(Node): @property def arp(self) -> Optional[ARP]: + """ + Return the ARP Cache of the HostNode + + :return: ARP Cache for given HostNode + :rtype: Optional[ARP] + """ return self.software_manager.software.get("ARP") def _install_system_software(self): diff --git a/src/primaite/simulator/network/hardware/nodes/network/network_node.py b/src/primaite/simulator/network/hardware/nodes/network/network_node.py index a3dc3be3..d9304f4d 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/network_node.py +++ b/src/primaite/simulator/network/hardware/nodes/network/network_node.py @@ -32,4 +32,10 @@ class NetworkNode(Node): @property def arp(self) -> Optional[ARP]: + """ + Return the ARP Cache of the NetworkNode + + :return: ARP Cache for given NetworkNode + :rtype: Optional[ARP] + """ return self.software_manager.software.get("ARP") From d02b12d1e56e4bff4c9d37b1cf937a0348262153 Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Tue, 9 Apr 2024 13:45:27 +0100 Subject: [PATCH 800/980] #2453 Addressing some flake8 corrections --- src/primaite/simulator/network/hardware/nodes/host/host_node.py | 2 +- .../simulator/network/hardware/nodes/network/network_node.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index e354d96a..6eb88131 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -319,7 +319,7 @@ class HostNode(Node): @property def arp(self) -> Optional[ARP]: """ - Return the ARP Cache of the HostNode + Return the ARP Cache of the HostNode. :return: ARP Cache for given HostNode :rtype: Optional[ARP] diff --git a/src/primaite/simulator/network/hardware/nodes/network/network_node.py b/src/primaite/simulator/network/hardware/nodes/network/network_node.py index d9304f4d..89b3d80f 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/network_node.py +++ b/src/primaite/simulator/network/hardware/nodes/network/network_node.py @@ -33,7 +33,7 @@ class NetworkNode(Node): @property def arp(self) -> Optional[ARP]: """ - Return the ARP Cache of the NetworkNode + Return the ARP Cache of the NetworkNode. :return: ARP Cache for given NetworkNode :rtype: Optional[ARP] From 8e6689d881333648668127dc21f69b9deba504dc Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Tue, 9 Apr 2024 13:56:21 +0100 Subject: [PATCH 801/980] #2453 - Corrected flake8 linting errors ahead of creating PR, after finally managing to get it to run locally. This should now be ready for review --- .../simulator/network/hardware/nodes/host/host_node.py | 2 +- .../simulator/network/hardware/nodes/network/network_node.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index 6eb88131..8928e8ef 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -322,7 +322,7 @@ class HostNode(Node): Return the ARP Cache of the HostNode. :return: ARP Cache for given HostNode - :rtype: Optional[ARP] + :rtype: Optional[ARP] """ return self.software_manager.software.get("ARP") diff --git a/src/primaite/simulator/network/hardware/nodes/network/network_node.py b/src/primaite/simulator/network/hardware/nodes/network/network_node.py index 89b3d80f..0474ca08 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/network_node.py +++ b/src/primaite/simulator/network/hardware/nodes/network/network_node.py @@ -5,6 +5,7 @@ from primaite.simulator.network.hardware.base import NetworkInterface, Node from primaite.simulator.network.transmission.data_link_layer import Frame from primaite.simulator.system.services.arp.arp import ARP + class NetworkNode(Node): """ Represents an abstract base class for a network node that can receive and process network frames. @@ -36,6 +37,6 @@ class NetworkNode(Node): Return the ARP Cache of the NetworkNode. :return: ARP Cache for given NetworkNode - :rtype: Optional[ARP] + :rtype: Optional[ARP] """ return self.software_manager.software.get("ARP") From 265f25b442b48be46cc306b88d6c20a6b1c4d1a7 Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Tue, 9 Apr 2024 14:15:51 +0100 Subject: [PATCH 802/980] #2453 - One final typo correction found in network_simulator_demo.ipynb. Correcting switch.sys_log.show() to computer.sys_log.show() in Computer/Server Nodes section --- .../network_simulator_demo.ipynb | 608 ++---------------- 1 file changed, 55 insertions(+), 553 deletions(-) diff --git a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb index 7a095b53..98dcaaac 100644 --- a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb +++ b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb @@ -59,7 +59,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "de57ac8c-5b28-4847-a759-2ceaf5593329", "metadata": { "tags": [] @@ -71,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "a1e2e4df-67c0-4584-ab27-47e2c7c7fcd2", "metadata": { "tags": [] @@ -91,70 +91,12 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "cc199741-ef2e-47f5-b2f0-e20049ccf40f", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+------------------------------------------------+\n", - "| Nodes |\n", - "+-------------------+----------+-----------------+\n", - "| Node | Type | Operating State |\n", - "+-------------------+----------+-----------------+\n", - "| router_1 | Router | ON |\n", - "| switch_1 | Switch | ON |\n", - "| switch_2 | Switch | ON |\n", - "| domain_controller | Server | ON |\n", - "| database_server | Server | ON |\n", - "| web_server | Server | ON |\n", - "| backup_server | Server | ON |\n", - "| security_suite | Server | ON |\n", - "| client_1 | Computer | ON |\n", - "| client_2 | Computer | ON |\n", - "+-------------------+----------+-----------------+\n", - "+-----------------------------------------------------------------------------+\n", - "| IP Addresses |\n", - "+-------------------+------+----------------+---------------+-----------------+\n", - "| Node | Port | IP Address | Subnet Mask | Default Gateway |\n", - "+-------------------+------+----------------+---------------+-----------------+\n", - "| router_1 | 1 | 192.168.1.1 | 255.255.255.0 | None |\n", - "| router_1 | 2 | 192.168.10.1 | 255.255.255.0 | None |\n", - "| router_1 | 3 | 127.0.0.1 | 255.0.0.0 | None |\n", - "| router_1 | 4 | 127.0.0.1 | 255.0.0.0 | None |\n", - "| router_1 | 5 | 127.0.0.1 | 255.0.0.0 | None |\n", - "| domain_controller | 1 | 192.168.1.10 | 255.255.255.0 | 192.168.1.1 |\n", - "| database_server | 1 | 192.168.1.14 | 255.255.255.0 | 192.168.1.1 |\n", - "| web_server | 1 | 192.168.1.12 | 255.255.255.0 | 192.168.1.1 |\n", - "| backup_server | 1 | 192.168.1.16 | 255.255.255.0 | 192.168.1.1 |\n", - "| security_suite | 1 | 192.168.1.110 | 255.255.255.0 | 192.168.1.1 |\n", - "| security_suite | 2 | 192.168.10.110 | 255.255.255.0 | 192.168.1.1 |\n", - "| client_1 | 1 | 192.168.10.21 | 255.255.255.0 | 192.168.10.1 |\n", - "| client_2 | 1 | 192.168.10.22 | 255.255.255.0 | 192.168.10.1 |\n", - "+-------------------+------+----------------+---------------+-----------------+\n", - "+---------------------------------------------------------------------------------------------------------------------------------------------------------------+\n", - "| Links |\n", - "+------------+----------------------------------------+-------------------+------------------------------------------+-------+-------------------+--------------+\n", - "| Endpoint A | A Port | Endpoint B | B Port | is Up | Bandwidth (MBits) | Current Load |\n", - "+------------+----------------------------------------+-------------------+------------------------------------------+-------+-------------------+--------------+\n", - "| router_1 | Port 2: 6e:3e:9f:58:c3:f8/192.168.10.1 | switch_2 | Port 8: 00:a7:49:9f:b7:40 | True | 100.0 | 0.00006% |\n", - "| router_1 | Port 1: 7c:0a:49:bd:2d:5f/192.168.1.1 | switch_1 | Port 8: e6:5e:9e:61:f6:71 | True | 100.0 | 0.00018% |\n", - "| switch_1 | Port 7: 8c:96:32:d5:ef:4b | security_suite | Port 1: 92:17:67:5f:09:f0/192.168.1.110 | True | 100.0 | 0.00003% |\n", - "| switch_1 | Port 4: ef:da:44:ee:68:1d | backup_server | Port 1: 82:23:ff:c5:03:45/192.168.1.16 | True | 100.0 | 0.00003% |\n", - "| switch_1 | Port 2: ab:84:4b:96:bc:b6 | web_server | Port 1: 30:3c:b4:54:b2:ef/192.168.1.12 | True | 100.0 | 0.00015% |\n", - "| switch_1 | Port 3: d8:07:d0:d6:27:52 | database_server | Port 1: 7c:cd:b5:ba:46:33/192.168.1.14 | True | 100.0 | 0.00017% |\n", - "| switch_1 | Port 1: e0:06:93:2c:45:cf | domain_controller | Port 1: 6d:3e:3e:b3:f6:6f/192.168.1.10 | True | 100.0 | 0.00003% |\n", - "| switch_2 | Port 7: 4f:55:6c:c3:ff:e9 | security_suite | Port 2: 64:6f:aa:ba:cb:d0/192.168.10.110 | True | 100.0 | 0.00000% |\n", - "| switch_2 | Port 2: f7:42:43:63:75:c9 | client_2 | Port 1: 21:bb:1b:75:02:fb/192.168.10.22 | True | 100.0 | 0.00003% |\n", - "| switch_2 | Port 1: 45:93:50:03:48:f5 | client_1 | Port 1: ca:f5:26:85:a7:54/192.168.10.21 | True | 100.0 | 0.00003% |\n", - "+------------+----------------------------------------+-------------------+------------------------------------------+-------+-------------------+--------------+\n" - ] - } - ], + "outputs": [], "source": [ "network.show()" ] @@ -191,30 +133,12 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "e76d1854-961e-438c-b40f-77fd9c3abe38", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+---------------------------------------------------------------+\n", - "| router_1 Network Interfaces |\n", - "+------+-------------------+-----------------+-------+----------+\n", - "| Port | MAC Address | Address | Speed | Status |\n", - "+------+-------------------+-----------------+-------+----------+\n", - "| 1 | 7c:0a:49:bd:2d:5f | 192.168.1.1/24 | 100 | Enabled |\n", - "| 2 | 6e:3e:9f:58:c3:f8 | 192.168.10.1/24 | 100 | Enabled |\n", - "| 3 | 44:c9:4c:25:4c:9b | 127.0.0.1/8 | 100 | Disabled |\n", - "| 4 | 4a:99:e4:a0:87:ba | 127.0.0.1/8 | 100 | Disabled |\n", - "| 5 | ca:5c:3b:6e:52:ef | 127.0.0.1/8 | 100 | Disabled |\n", - "+------+-------------------+-----------------+-------+----------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"router_1\").show()" ] @@ -229,32 +153,12 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "92de8b42-92d7-4934-9c12-50bf724c9eb2", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-------------------------------------------------------+\n", - "| router_1 ARP Cache |\n", - "+---------------+-------------------+-------------------+\n", - "| IP Address | MAC Address | Via |\n", - "+---------------+-------------------+-------------------+\n", - "| 192.168.10.21 | ca:f5:26:85:a7:54 | 6e:3e:9f:58:c3:f8 |\n", - "| 192.168.10.22 | 21:bb:1b:75:02:fb | 6e:3e:9f:58:c3:f8 |\n", - "| 192.168.1.10 | 6d:3e:3e:b3:f6:6f | 7c:0a:49:bd:2d:5f |\n", - "| 192.168.1.14 | 7c:cd:b5:ba:46:33 | 7c:0a:49:bd:2d:5f |\n", - "| 192.168.1.12 | 30:3c:b4:54:b2:ef | 7c:0a:49:bd:2d:5f |\n", - "| 192.168.1.16 | 82:23:ff:c5:03:45 | 7c:0a:49:bd:2d:5f |\n", - "| 192.168.1.110 | 92:17:67:5f:09:f0 | 7c:0a:49:bd:2d:5f |\n", - "+---------------+-------------------+-------------------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"router_1\").arp.show()" ] @@ -269,32 +173,12 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "5922282a-d22b-4e55-9176-f3f3654c849f", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+---------------------------------------------------------------------------------------------------------------------------------------+\n", - "| router_1 Access Control List |\n", - "+-------+--------+----------+--------+--------------+------------------------+--------+--------------+------------------------+---------+\n", - "| Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Matched |\n", - "+-------+--------+----------+--------+--------------+------------------------+--------+--------------+------------------------+---------+\n", - "| 0 | PERMIT | ANY | ANY | ANY | 5432 (POSTGRES_SERVER) | ANY | ANY | 5432 (POSTGRES_SERVER) | 0 |\n", - "| 1 | PERMIT | ANY | ANY | ANY | 53 (DNS) | ANY | ANY | 53 (DNS) | 0 |\n", - "| 2 | PERMIT | ANY | ANY | ANY | 21 (FTP) | ANY | ANY | 21 (FTP) | 0 |\n", - "| 3 | PERMIT | ANY | ANY | ANY | 80 (HTTP) | ANY | ANY | 80 (HTTP) | 0 |\n", - "| 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 0 |\n", - "| 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 0 |\n", - "| 24 | DENY | ANY | ANY | ANY | ANY | ANY | ANY | ANY | 0 |\n", - "+-------+--------+----------+--------+--------------+------------------------+--------+--------------+------------------------+---------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"router_1\").acl.show()" ] @@ -309,25 +193,12 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "id": "327203be-f475-4727-82a1-e992d3b70ed8", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-------------------------------------+\n", - "| router_1 Route Table |\n", - "+-------+---------+----------+--------+\n", - "| Index | Address | Next Hop | Metric |\n", - "+-------+---------+----------+--------+\n", - "+-------+---------+----------+--------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"router_1\").route_table.show()" ] @@ -342,25 +213,12 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "3d0aa004-b10c-445f-aaab-340e0e716c74", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-----------------------------+\n", - "| router_1 Sys Log |\n", - "+-----------+-------+---------+\n", - "| Timestamp | Level | Message |\n", - "+-----------+-------+---------+\n", - "+-----------+-------+---------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"router_1\").sys_log.show(last_n=10)" ] @@ -385,33 +243,12 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "e7fd439b-5442-4e9d-9e7d-86dacb77f458", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+---------------------------------------------+\n", - "| switch_1 Switch Ports |\n", - "+------+-------------------+-------+----------+\n", - "| Port | MAC Address | Speed | Status |\n", - "+------+-------------------+-------+----------+\n", - "| 1 | e0:06:93:2c:45:cf | 100 | Enabled |\n", - "| 2 | ab:84:4b:96:bc:b6 | 100 | Enabled |\n", - "| 3 | d8:07:d0:d6:27:52 | 100 | Enabled |\n", - "| 4 | ef:da:44:ee:68:1d | 100 | Enabled |\n", - "| 5 | b6:76:3d:1d:7e:be | 100 | Disabled |\n", - "| 6 | 02:ce:fa:da:9a:a4 | 100 | Disabled |\n", - "| 7 | 8c:96:32:d5:ef:4b | 100 | Enabled |\n", - "| 8 | e6:5e:9e:61:f6:71 | 100 | Enabled |\n", - "+------+-------------------+-------+----------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"switch_1\").show()" ] @@ -426,25 +263,12 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "a0d984b7-a7c1-4bbd-aa5a-9d3caecb08dc", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-----------------------------+\n", - "| switch_1 Sys Log |\n", - "+-----------+-------+---------+\n", - "| Timestamp | Level | Message |\n", - "+-----------+-------+---------+\n", - "+-----------+-------+---------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"switch_1\").sys_log.show()" ] @@ -471,38 +295,12 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "656c37f6-b145-42af-9714-8d2886d0eff8", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-----------------------------------------------------------------------+\n", - "| security_suite Network Interface Cards |\n", - "+------+------+-------------------+-------------------+-------+---------+\n", - "| Port | Type | MAC Address | Address | Speed | Status |\n", - "+------+------+-------------------+-------------------+-------+---------+\n", - "| 1 | NIC | 92:17:67:5f:09:f0 | 192.168.1.110/24 | 100 | Enabled |\n", - "| 2 | NIC | 64:6f:aa:ba:cb:d0 | 192.168.10.110/24 | 100 | Enabled |\n", - "+------+------+-------------------+-------------------+-------+---------+\n", - "+---------------------------+\n", - "| security_suite Open Ports |\n", - "+-------------+-------------+\n", - "| Port | Name |\n", - "+-------------+-------------+\n", - "| 21 | FTP |\n", - "| 53 | DNS |\n", - "| 80 | HTTP |\n", - "| 123 | NTP |\n", - "| 219 | ARP |\n", - "+-------------+-------------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"security_suite\").show()" ] @@ -517,26 +315,12 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "66b267d6-2308-486a-b9aa-cb8d3bcf0753", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-----------------------------------------------------+\n", - "| security_suite ARP Cache |\n", - "+-------------+-------------------+-------------------+\n", - "| IP Address | MAC Address | Via |\n", - "+-------------+-------------------+-------------------+\n", - "| 192.168.1.1 | 7c:0a:49:bd:2d:5f | 92:17:67:5f:09:f0 |\n", - "+-------------+-------------------+-------------------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"security_suite\").arp.show()" ] @@ -546,30 +330,17 @@ "id": "0d1fcad8-5b1a-4d8b-a49f-aa54a95fcaf0", "metadata": {}, "source": [ - "Calling `switch.sys_log.show()` displays the Computer/Server system log. By default, only the last 10 log entries are displayed, this can be changed by passing `last_n=`." + "Calling `computer.sys_log.show()` displays the Computer/Server system log. By default, only the last 10 log entries are displayed, this can be changed by passing `last_n=`." ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "1b5debe8-ef1b-445d-8fa9-6a45568f21f3", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-----------------------------+\n", - "| security_suite Sys Log |\n", - "+-----------+-------+---------+\n", - "| Timestamp | Level | Message |\n", - "+-----------+-------+---------+\n", - "+-----------+-------+---------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"security_suite\").sys_log.show()" ] @@ -586,38 +357,12 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "495b7de4-b6ce-41a6-9114-f74752ab4491", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-----------------------------------------------------------------------------+\n", - "| IP Addresses |\n", - "+-------------------+------+----------------+---------------+-----------------+\n", - "| Node | Port | IP Address | Subnet Mask | Default Gateway |\n", - "+-------------------+------+----------------+---------------+-----------------+\n", - "| router_1 | 1 | 192.168.1.1 | 255.255.255.0 | None |\n", - "| router_1 | 2 | 192.168.10.1 | 255.255.255.0 | None |\n", - "| router_1 | 3 | 127.0.0.1 | 255.0.0.0 | None |\n", - "| router_1 | 4 | 127.0.0.1 | 255.0.0.0 | None |\n", - "| router_1 | 5 | 127.0.0.1 | 255.0.0.0 | None |\n", - "| domain_controller | 1 | 192.168.1.10 | 255.255.255.0 | 192.168.1.1 |\n", - "| database_server | 1 | 192.168.1.14 | 255.255.255.0 | 192.168.1.1 |\n", - "| web_server | 1 | 192.168.1.12 | 255.255.255.0 | 192.168.1.1 |\n", - "| backup_server | 1 | 192.168.1.16 | 255.255.255.0 | 192.168.1.1 |\n", - "| security_suite | 1 | 192.168.1.110 | 255.255.255.0 | 192.168.1.1 |\n", - "| security_suite | 2 | 192.168.10.110 | 255.255.255.0 | 192.168.1.1 |\n", - "| client_1 | 1 | 192.168.10.21 | 255.255.255.0 | 192.168.10.1 |\n", - "| client_2 | 1 | 192.168.10.22 | 255.255.255.0 | 192.168.10.1 |\n", - "+-------------------+------+----------------+---------------+-----------------+\n" - ] - } - ], + "outputs": [], "source": [ "network.show(nodes=False, links=False)" ] @@ -632,60 +377,24 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "id": "a38abb71-994e-49e8-8f51-e9a550e95b99", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Pinging 192.168.10.1:\n", - "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", - "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", - "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", - "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", - "Ping statistics for 192.168.10.1: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n" - ] - }, - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"client_1\").ping(\"192.168.10.1\")" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "id": "8388e1e9-30e3-4534-8e5a-c6e9144149d2", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-----------------------------+\n", - "| client_1 Sys Log |\n", - "+-----------+-------+---------+\n", - "| Timestamp | Level | Message |\n", - "+-----------+-------+---------+\n", - "+-----------+-------+---------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"client_1\").sys_log.show(15)" ] @@ -700,35 +409,12 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "id": "ff8e976a-c16b-470c-8923-325713a30d6c", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Pinging 192.168.1.1:\n", - "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", - "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", - "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", - "Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n", - "Ping statistics for 192.168.1.1: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n" - ] - }, - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"client_1\").ping(\"192.168.1.1\")" ] @@ -743,35 +429,12 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "id": "c4163f8d-6a72-410c-9f5c-4f881b7de45e", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Pinging 192.168.1.12:\n", - "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", - "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", - "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", - "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", - "Ping statistics for 192.168.1.12: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n" - ] - }, - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"client_1\").ping(\"192.168.1.12\")" ] @@ -786,25 +449,12 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "id": "e79a523a-5780-45b6-8798-c434e0e522bd", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-----------------------------+\n", - "| web_server Sys Log |\n", - "+-----------+-------+---------+\n", - "| Timestamp | Level | Message |\n", - "+-----------+-------+---------+\n", - "+-----------+-------+---------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"web_server\").sys_log.show()" ] @@ -829,35 +479,12 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "id": "603cf913-e261-49da-a7dd-85e1bb6dec56", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Pinging 192.168.1.12:\n", - "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", - "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", - "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", - "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", - "Ping statistics for 192.168.1.12: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n" - ] - }, - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"client_2\").ping(\"192.168.1.12\")" ] @@ -872,25 +499,12 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "id": "e047de00-3de4-4823-b26a-2c8d64c7a663", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-----------------------------+\n", - "| client_2 Sys Log |\n", - "+-----------+-------+---------+\n", - "| Timestamp | Level | Message |\n", - "+-----------+-------+---------+\n", - "+-----------+-------+---------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"client_2\").sys_log.show()" ] @@ -905,23 +519,12 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "id": "6db355ae-b99a-441b-a2c4-4ffe78f46bff", "metadata": { "tags": [] }, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "from primaite.simulator.network.transmission.network_layer import IPProtocol\n", "from primaite.simulator.network.transmission.transport_layer import Port\n", @@ -936,32 +539,12 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "id": "a345e000-8842-4827-af96-adc0fbe390fb", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+----------------------------------------------------------------------------------------------------------------------------------------------+\n", - "| router_1 Access Control List |\n", - "+-------+--------+----------+---------------+--------------+------------------------+--------+--------------+------------------------+---------+\n", - "| Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Matched |\n", - "+-------+--------+----------+---------------+--------------+------------------------+--------+--------------+------------------------+---------+\n", - "| 0 | PERMIT | ANY | ANY | ANY | 5432 (POSTGRES_SERVER) | ANY | ANY | 5432 (POSTGRES_SERVER) | 0 |\n", - "| 1 | DENY | ICMP | 192.168.10.22 | ANY | ANY | ANY | ANY | ANY | 0 |\n", - "| 2 | PERMIT | ANY | ANY | ANY | 21 (FTP) | ANY | ANY | 21 (FTP) | 0 |\n", - "| 3 | PERMIT | ANY | ANY | ANY | 80 (HTTP) | ANY | ANY | 80 (HTTP) | 0 |\n", - "| 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 0 |\n", - "| 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 24 |\n", - "| 24 | DENY | ANY | ANY | ANY | ANY | ANY | ANY | ANY | 0 |\n", - "+-------+--------+----------+---------------+--------------+------------------------+--------+--------------+------------------------+---------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"router_1\").acl.show()" ] @@ -976,31 +559,12 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "id": "a4f4ff31-590f-40fb-b13d-efaa8c2720b6", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Pinging 192.168.1.12:\n", - "Ping statistics for 192.168.1.12: Packets: Sent = 4, Received = 0, Lost = 4 (100.0% loss)\n" - ] - }, - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"client_2\").ping(\"192.168.1.12\")" ] @@ -1015,25 +579,12 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "id": "f62b8a4e-fd3b-4059-b108-3d4a0b18f2a0", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-----------------------------+\n", - "| client_2 Sys Log |\n", - "+-----------+-------+---------+\n", - "| Timestamp | Level | Message |\n", - "+-----------+-------+---------+\n", - "+-----------+-------+---------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"client_2\").sys_log.show()" ] @@ -1048,25 +599,12 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "id": "7e53d776-99da-4d2c-a2a7-bd7ce27bff4c", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-----------------------------+\n", - "| router_1 Sys Log |\n", - "+-----------+-------+---------+\n", - "| Timestamp | Level | Message |\n", - "+-----------+-------+---------+\n", - "+-----------+-------+---------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"router_1\").sys_log.show()" ] @@ -1081,60 +619,24 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "id": "d542734b-7582-4af7-8254-bda3de50d091", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Pinging 192.168.1.12:\n", - "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", - "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", - "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", - "Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n", - "Ping statistics for 192.168.1.12: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n" - ] - }, - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"client_1\").ping(\"192.168.1.12\")" ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "id": "d78e9fe3-02c6-4792-944f-5622e26e0412", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+-----------------------------+\n", - "| client_1 Sys Log |\n", - "+-----------+-------+---------+\n", - "| Timestamp | Level | Message |\n", - "+-----------+-------+---------+\n", - "+-----------+-------+---------+\n" - ] - } - ], + "outputs": [], "source": [ "network.get_node_by_hostname(\"client_1\").sys_log.show()" ] From 89de5a298d9e18798710837e7b7edd58331ef59c Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 9 Apr 2024 14:47:31 +0100 Subject: [PATCH 803/980] #2455: Fix typo in config file and notebook --- src/primaite/config/_package_data/data_manipulation_marl.yaml | 2 +- .../notebooks/Data-Manipulation-Customising-Red-Agent.ipynb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index 653ddfd3..deb43eea 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -1476,7 +1476,7 @@ simulation: options: db_server_ip: 192.168.1.14 services: - - ty DNSClient + - type: DNSClient diff --git a/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb b/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb index 56e9bf5a..74a1e0ef 100644 --- a/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb @@ -362,7 +362,7 @@ " cfg = yaml.safe_load(f)\n", " cfg['simulation']['network']\n", " for node in cfg['simulation']['network']['nodes']:\n", - " if node['ref'] in ['client_1', 'client_2']:\n", + " if node['hostname'] in ['client_1', 'client_2']:\n", " node['applications'] = change['applications']\n", "\n", "env = PrimaiteGymEnv(game_config = cfg)\n", @@ -407,7 +407,7 @@ " cfg = yaml.safe_load(f)\n", " cfg['simulation']['network']\n", " for node in cfg['simulation']['network']['nodes']:\n", - " if node['ref'] in ['client_1', 'client_2']:\n", + " if node['hostname'] in ['client_1', 'client_2']:\n", " node['applications'] = change['applications']\n", "\n", "env = PrimaiteGymEnv(game_config = cfg)\n", From 3245c7e81eec7c41991a5f404f8efa441f0ad401 Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Tue, 9 Apr 2024 14:48:49 +0100 Subject: [PATCH 804/980] #2453 - Renaming Server hostname in create-simulation_demo and removing saved output --- .../create-simulation_demo.ipynb | 580 +----------------- 1 file changed, 23 insertions(+), 557 deletions(-) diff --git a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb index 5ef31243..756a48fc 100644 --- a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb +++ b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -36,24 +36,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'uuid': '91c88b2a-caf1-47be-a394-d0c22e5110be',\n", - " 'network': {'uuid': 'a9121808-0401-460c-9833-23d4ba91e9bc',\n", - " 'nodes': {},\n", - " 'links': {}},\n", - " 'domain': {'uuid': '25fbe0e9-76e8-4fd7-ad22-da2d2b5a509d', 'accounts': {}}}" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_sim = Simulation()\n", "net = my_sim.network\n", @@ -69,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -79,13 +64,13 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "my_pc = Computer(hostname=\"primaite_pc\", ip_address=\"192.168.1.10\", subnet_mask=\"255.255.255.0\")\n", + "my_pc = Computer(hostname=\"Computer\", ip_address=\"192.168.1.10\", subnet_mask=\"255.255.255.0\")\n", "net.add_node(my_pc)\n", - "my_server = Server(hostname=\"google_server\", ip_address=\"192.168.1.11\", subnet_mask=\"255.255.255.0\")\n", + "my_server = Server(hostname=\"Server\", ip_address=\"192.168.1.11\", subnet_mask=\"255.255.255.0\")\n", "net.add_node(my_server)\n" ] }, @@ -98,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -108,20 +93,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Link(uuid='2bd19485-0a6b-4878-978b-b082a672d9b9', endpoint_a=NIC(ip_address=IPv4Address('130.1.1.2'), subnet_mask=IPv4Address('255.255.255.0'), uuid='8a628493-83fb-44bf-a1b0-ef19e362ae5f', mac_address='44:89:a5:ce:7f:6f', speed=100, mtu=1500, enabled=False, port_num=2, port_name=None, pcap=None, nmne={}, wake_on_lan=False, gateway='130.1.1.255'), endpoint_b=SwitchPort(uuid='a049bb8f-53d3-4575-b325-dfb55516edcd', mac_address='aa:45:88:e1:13:e5', speed=100, mtu=1500, enabled=False, port_num=2, port_name=None, pcap=None, nmne={}), bandwidth=100.0, current_load=0.0)" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_switch = Switch(hostname=\"switch1\", num_ports=12)\n", "net.add_node(my_switch)\n", @@ -145,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -156,7 +130,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -166,20 +140,9 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "File(uuid='3ceeded4-77b9-4a86-949c-73188d5f4c34', name='favicon.ico', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='cbbd3631-a915-400d-bc02-f31f72447ce5', folder_name='root', file_type=, sim_size=0, real=False, sim_path=None, sim_root=WindowsPath('C:/Projects/PrimAITE/simulation_output/2024-04-09_13-24-30/google_server/fs'), num_access=0, folder=Folder(uuid='cbbd3631-a915-400d-bc02-f31f72447ce5', name='root', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={'3ceeded4-77b9-4a86-949c-73188d5f4c34': File(uuid='3ceeded4-77b9-4a86-949c-73188d5f4c34', name='favicon.ico', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, folder_id='cbbd3631-a915-400d-bc02-f31f72447ce5', folder_name='root', file_type=, sim_size=0, real=False, sim_path=None, sim_root=WindowsPath('C:/Projects/PrimAITE/simulation_output/2024-04-09_13-24-30/google_server/fs'), num_access=0, folder=Folder(uuid='cbbd3631-a915-400d-bc02-f31f72447ce5', name='root', health_status=, visible_health_status=, previous_hash=None, revealed_to_red=False, sys_log=, deleted=False, files={...}, deleted_files={}, scan_duration=3, scan_countdown=0, red_scan_duration=3, red_scan_countdown=0, restore_duration=3, restore_countdown=0))}, deleted_files={}, scan_duration=3, scan_countdown=0, red_scan_duration=3, red_scan_countdown=0, restore_duration=3, restore_countdown=0))" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_server_folder = my_server.file_system.create_folder(\"static\")\n", "my_server.file_system.create_file(\"favicon.ico\", file_type=FileType.PNG)" @@ -194,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -213,7 +176,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -222,7 +185,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -238,7 +201,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -247,7 +210,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -264,515 +227,18 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'uuid': '91c88b2a-caf1-47be-a394-d0c22e5110be',\n", - " 'network': {'uuid': 'a9121808-0401-460c-9833-23d4ba91e9bc',\n", - " 'nodes': {'primaite_pc': {'uuid': 'dd0e95be-2491-4d5b-8388-df3975a19e8a',\n", - " 'hostname': 'primaite_pc',\n", - " 'operating_state': 2,\n", - " 'NICs': {1: {'uuid': '279e2645-b680-4d2e-b13c-66d5cfacbd38',\n", - " 'mac_address': 'bd:76:20:24:cf:04',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {},\n", - " 'ip_address': '192.168.1.10',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'wake_on_lan': False},\n", - " 2: {'uuid': '40c0db02-4d14-4826-b49b-e6a521941cec',\n", - " 'mac_address': 'd8:b2:0c:af:3f:83',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {},\n", - " 'ip_address': '130.1.1.1',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'wake_on_lan': False}},\n", - " 'file_system': {'uuid': '91d3aed7-53c6-471f-b903-9889396be280',\n", - " 'folders': {'root': {'uuid': '81bdc04e-9a0d-4306-9a9c-ee926fff6df8',\n", - " 'name': 'root',\n", - " 'health_status': 1,\n", - " 'visible_status': 1,\n", - " 'previous_hash': None,\n", - " 'revealed_to_red': False,\n", - " 'files': {},\n", - " 'deleted_files': {}},\n", - " 'downloads': {'uuid': '56abdf27-b8d4-42f4-9b09-b7912db1c4f3',\n", - " 'name': 'downloads',\n", - " 'health_status': 1,\n", - " 'visible_status': 1,\n", - " 'previous_hash': None,\n", - " 'revealed_to_red': False,\n", - " 'files': {'firefox_installer.zip': {'uuid': '02236b61-14bb-46aa-9fd5-7174c0d7d730',\n", - " 'name': 'firefox_installer.zip',\n", - " 'health_status': 1,\n", - " 'visible_status': 1,\n", - " 'previous_hash': None,\n", - " 'revealed_to_red': False,\n", - " 'size': 1024000,\n", - " 'file_type': 'ZIP',\n", - " 'num_access': 0}},\n", - " 'deleted_files': {}}},\n", - " 'deleted_folders': {},\n", - " 'num_file_creations': 0,\n", - " 'num_file_deletions': 0},\n", - " 'applications': {'WebBrowser': {'uuid': 'a6a12776-e307-4d71-9e7a-d9ca97ecd6b0',\n", - " 'health_state_actual': 0,\n", - " 'health_state_visible': 0,\n", - " 'criticality': 1,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 80,\n", - " 'operating_state': 2,\n", - " 'execution_control_status': 'manual',\n", - " 'num_executions': 0,\n", - " 'groups': [],\n", - " 'history': []},\n", - " 'mspaint': {'uuid': 'efd34549-cc92-4474-80ab-5fb6c3159ff6',\n", - " 'health_state_actual': 1,\n", - " 'health_state_visible': 1,\n", - " 'criticality': 3,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 80,\n", - " 'operating_state': 1,\n", - " 'execution_control_status': 'manual',\n", - " 'num_executions': 0,\n", - " 'groups': []}},\n", - " 'services': {'ARP': {'uuid': 'e61c25ff-a6c2-4eec-b031-131eaf33490c',\n", - " 'health_state_actual': 0,\n", - " 'health_state_visible': 0,\n", - " 'criticality': 1,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 219,\n", - " 'operating_state': 2},\n", - " 'ICMP': {'uuid': '74debeed-b758-41cb-bea2-51ac283e6ae2',\n", - " 'health_state_actual': 0,\n", - " 'health_state_visible': 0,\n", - " 'criticality': 1,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 0,\n", - " 'operating_state': 2},\n", - " 'DNSClient': {'uuid': '6680efc0-e005-41e8-bb49-39a0d9c4b118',\n", - " 'health_state_actual': 0,\n", - " 'health_state_visible': 0,\n", - " 'criticality': 1,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 53,\n", - " 'operating_state': 2},\n", - " 'FTPClient': {'uuid': '21b05ac9-e9b4-4c5c-a812-f6748e14d8c3',\n", - " 'health_state_actual': 0,\n", - " 'health_state_visible': 0,\n", - " 'criticality': 1,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 21,\n", - " 'operating_state': 2},\n", - " 'NTPClient': {'uuid': '7ab7c911-5037-4e82-b00c-be4f72c13aa7',\n", - " 'health_state_actual': 0,\n", - " 'health_state_visible': 0,\n", - " 'criticality': 1,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 123,\n", - " 'operating_state': 2}},\n", - " 'process': {},\n", - " 'revealed_to_red': False},\n", - " 'google_server': {'uuid': '42d61d8d-2493-4b8a-944f-7962abc9d20b',\n", - " 'hostname': 'google_server',\n", - " 'operating_state': 2,\n", - " 'NICs': {1: {'uuid': 'e384a4fc-754f-44a4-9158-c63f72f52f76',\n", - " 'mac_address': 'ea:5d:4f:10:b2:27',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {},\n", - " 'ip_address': '192.168.1.11',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'wake_on_lan': False},\n", - " 2: {'uuid': '8a628493-83fb-44bf-a1b0-ef19e362ae5f',\n", - " 'mac_address': '44:89:a5:ce:7f:6f',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {},\n", - " 'ip_address': '130.1.1.2',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'wake_on_lan': False}},\n", - " 'file_system': {'uuid': 'f25cee1f-2ebe-4fd3-8d5c-649b0d342b61',\n", - " 'folders': {'root': {'uuid': 'cbbd3631-a915-400d-bc02-f31f72447ce5',\n", - " 'name': 'root',\n", - " 'health_status': 1,\n", - " 'visible_status': 1,\n", - " 'previous_hash': None,\n", - " 'revealed_to_red': False,\n", - " 'files': {'favicon.ico': {'uuid': '3ceeded4-77b9-4a86-949c-73188d5f4c34',\n", - " 'name': 'favicon.ico',\n", - " 'health_status': 1,\n", - " 'visible_status': 1,\n", - " 'previous_hash': None,\n", - " 'revealed_to_red': False,\n", - " 'size': 0,\n", - " 'file_type': 'UNKNOWN',\n", - " 'num_access': 0}},\n", - " 'deleted_files': {}},\n", - " 'static': {'uuid': 'd8241ce0-f55e-43ec-bd68-741b79a9a565',\n", - " 'name': 'static',\n", - " 'health_status': 1,\n", - " 'visible_status': 1,\n", - " 'previous_hash': None,\n", - " 'revealed_to_red': False,\n", - " 'files': {},\n", - " 'deleted_files': {}}},\n", - " 'deleted_folders': {},\n", - " 'num_file_creations': 1,\n", - " 'num_file_deletions': 0},\n", - " 'applications': {'WebBrowser': {'uuid': '957d0049-e703-4882-8e57-b2ab4c79d458',\n", - " 'health_state_actual': 0,\n", - " 'health_state_visible': 0,\n", - " 'criticality': 1,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 80,\n", - " 'operating_state': 2,\n", - " 'execution_control_status': 'manual',\n", - " 'num_executions': 0,\n", - " 'groups': [],\n", - " 'history': []}},\n", - " 'services': {'ARP': {'uuid': '82ea1bcf-a0fe-418d-873e-5f075ebb4d3b',\n", - " 'health_state_actual': 0,\n", - " 'health_state_visible': 0,\n", - " 'criticality': 1,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 219,\n", - " 'operating_state': 2},\n", - " 'ICMP': {'uuid': 'bc084dc4-0a7d-4954-9e6e-54bed797e837',\n", - " 'health_state_actual': 0,\n", - " 'health_state_visible': 0,\n", - " 'criticality': 1,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 0,\n", - " 'operating_state': 2},\n", - " 'DNSClient': {'uuid': '5a9ecc18-71c0-4728-a9c6-e31b33529581',\n", - " 'health_state_actual': 0,\n", - " 'health_state_visible': 0,\n", - " 'criticality': 1,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 53,\n", - " 'operating_state': 2},\n", - " 'FTPClient': {'uuid': 'f0a411eb-5423-4c98-8689-d94af57deefc',\n", - " 'health_state_actual': 0,\n", - " 'health_state_visible': 0,\n", - " 'criticality': 1,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 21,\n", - " 'operating_state': 2},\n", - " 'NTPClient': {'uuid': 'd36f2c4f-af30-4618-ae8e-fe68c98e1382',\n", - " 'health_state_actual': 0,\n", - " 'health_state_visible': 0,\n", - " 'criticality': 1,\n", - " 'fixing_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 100,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 123,\n", - " 'operating_state': 2}},\n", - " 'process': {},\n", - " 'revealed_to_red': False},\n", - " 'switch1': {'uuid': 'a9e08b28-d1f4-4c34-b410-71333cd6b42b',\n", - " 'hostname': 'switch1',\n", - " 'operating_state': 2,\n", - " 'NICs': {1: {'uuid': '3546e960-30f8-49ee-95b9-57570b228333',\n", - " 'mac_address': '8d:d9:3e:f3:a3:ce',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 2: {'uuid': 'a049bb8f-53d3-4575-b325-dfb55516edcd',\n", - " 'mac_address': 'aa:45:88:e1:13:e5',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 3: {'uuid': '179c030c-d8fe-474b-a9d1-6c6bd6e6ca63',\n", - " 'mac_address': '10:d7:bc:39:4d:9d',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 4: {'uuid': '56f84a14-0a98-4bc5-983b-31900fc9a2c5',\n", - " 'mac_address': '61:62:18:cf:2a:ea',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 5: {'uuid': '0ff4b64e-be4c-473e-8dcd-b7a0078ff890',\n", - " 'mac_address': '21:5e:6b:1b:d0:bf',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 6: {'uuid': '0edf239b-bbb8-4076-ba85-cb07c65722d5',\n", - " 'mac_address': '40:58:ac:11:9c:1a',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 7: {'uuid': 'a7f578e5-a6f5-4cf8-abca-207e483637c2',\n", - " 'mac_address': 'e0:ef:90:e2:ce:b4',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 8: {'uuid': 'dc2069dd-ef3c-4e0b-81cb-a73caba917a8',\n", - " 'mac_address': '2c:2a:27:d6:9a:a8',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 9: {'uuid': 'afbc1a01-efdb-424c-9a7d-b3c3165f6d78',\n", - " 'mac_address': 'e0:f5:79:04:4f:2a',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 10: {'uuid': 'bdd805f4-a3dc-4a94-ba67-3a62b138f41c',\n", - " 'mac_address': '9a:20:3d:cb:a0:98',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 11: {'uuid': '19f6f871-cba9-423a-a1a5-6a0e347e98cb',\n", - " 'mac_address': '69:d9:8c:1d:a9:75',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 12: {'uuid': '5c2aa6f5-12ce-466b-b46b-95ec519a5f47',\n", - " 'mac_address': 'db:7e:8c:91:1b:3f',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}}},\n", - " 'file_system': {'uuid': '91dea1d3-3947-49b9-a691-750bc25bbb9c',\n", - " 'folders': {'root': {'uuid': 'b7ebbf43-d86f-43d3-bbc7-f6b197af40b9',\n", - " 'name': 'root',\n", - " 'health_status': 1,\n", - " 'visible_status': 1,\n", - " 'previous_hash': None,\n", - " 'revealed_to_red': False,\n", - " 'files': {},\n", - " 'deleted_files': {}}},\n", - " 'deleted_folders': {},\n", - " 'num_file_creations': 0,\n", - " 'num_file_deletions': 0},\n", - " 'applications': {},\n", - " 'services': {},\n", - " 'process': {},\n", - " 'revealed_to_red': False,\n", - " 'ports': {1: {'uuid': '3546e960-30f8-49ee-95b9-57570b228333',\n", - " 'mac_address': '8d:d9:3e:f3:a3:ce',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 2: {'uuid': 'a049bb8f-53d3-4575-b325-dfb55516edcd',\n", - " 'mac_address': 'aa:45:88:e1:13:e5',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 3: {'uuid': '179c030c-d8fe-474b-a9d1-6c6bd6e6ca63',\n", - " 'mac_address': '10:d7:bc:39:4d:9d',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 4: {'uuid': '56f84a14-0a98-4bc5-983b-31900fc9a2c5',\n", - " 'mac_address': '61:62:18:cf:2a:ea',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 5: {'uuid': '0ff4b64e-be4c-473e-8dcd-b7a0078ff890',\n", - " 'mac_address': '21:5e:6b:1b:d0:bf',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 6: {'uuid': '0edf239b-bbb8-4076-ba85-cb07c65722d5',\n", - " 'mac_address': '40:58:ac:11:9c:1a',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 7: {'uuid': 'a7f578e5-a6f5-4cf8-abca-207e483637c2',\n", - " 'mac_address': 'e0:ef:90:e2:ce:b4',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 8: {'uuid': 'dc2069dd-ef3c-4e0b-81cb-a73caba917a8',\n", - " 'mac_address': '2c:2a:27:d6:9a:a8',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 9: {'uuid': 'afbc1a01-efdb-424c-9a7d-b3c3165f6d78',\n", - " 'mac_address': 'e0:f5:79:04:4f:2a',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 10: {'uuid': 'bdd805f4-a3dc-4a94-ba67-3a62b138f41c',\n", - " 'mac_address': '9a:20:3d:cb:a0:98',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 11: {'uuid': '19f6f871-cba9-423a-a1a5-6a0e347e98cb',\n", - " 'mac_address': '69:d9:8c:1d:a9:75',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}},\n", - " 12: {'uuid': '5c2aa6f5-12ce-466b-b46b-95ec519a5f47',\n", - " 'mac_address': 'db:7e:8c:91:1b:3f',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False,\n", - " 'nmne': {}}},\n", - " 'num_ports': 12,\n", - " 'mac_address_table': {}}},\n", - " 'links': {'primaite_pc:eth-2<->switch1:eth-1': {'uuid': '405f3032-6f5d-427f-b42e-5eee4cdc3a7c',\n", - " 'endpoint_a': '40c0db02-4d14-4826-b49b-e6a521941cec',\n", - " 'endpoint_b': '3546e960-30f8-49ee-95b9-57570b228333',\n", - " 'bandwidth': 100.0,\n", - " 'current_load': 0.0,\n", - " 'hostname_a': 'primaite_pc',\n", - " 'hostname_b': 'switch1',\n", - " 'port_a': 2,\n", - " 'port_b': 1},\n", - " 'google_server:eth-2<->switch1:eth-2': {'uuid': '2bd19485-0a6b-4878-978b-b082a672d9b9',\n", - " 'endpoint_a': '8a628493-83fb-44bf-a1b0-ef19e362ae5f',\n", - " 'endpoint_b': 'a049bb8f-53d3-4575-b325-dfb55516edcd',\n", - " 'bandwidth': 100.0,\n", - " 'current_load': 0.0,\n", - " 'hostname_a': 'google_server',\n", - " 'hostname_b': 'switch1',\n", - " 'port_a': 2,\n", - " 'port_b': 2}}},\n", - " 'domain': {'uuid': '25fbe0e9-76e8-4fd7-ad22-da2d2b5a509d',\n", - " 'accounts': {'admin': {'uuid': '78783f13-6149-47b3-9b9d-f98d658bf54a',\n", - " 'num_logons': 0,\n", - " 'num_logoffs': 0,\n", - " 'num_group_changes': 0,\n", - " 'username': 'admin',\n", - " 'password': 'admin12',\n", - " 'account_type': 2,\n", - " 'enabled': True}}}}" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_sim.describe_state()" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'{\"uuid\": \"91c88b2a-caf1-47be-a394-d0c22e5110be\", \"network\": {\"uuid\": \"a9121808-0401-460c-9833-23d4ba91e9bc\", \"nodes\": {\"primaite_pc\": {\"uuid\": \"dd0e95be-2491-4d5b-8388-df3975a19e8a\", \"hostname\": \"primaite_pc\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"279e2645-b680-4d2e-b13c-66d5cfacbd38\", \"mac_address\": \"bd:76:20:24:cf:04\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"192.168.1.10\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}, \"2\": {\"uuid\": \"40c0db02-4d14-4826-b49b-e6a521941cec\", \"mac_address\": \"d8:b2:0c:af:3f:83\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}}, \"file_system\": {\"uuid\": \"91d3aed7-53c6-471f-b903-9889396be280\", \"folders\": {\"root\": {\"uuid\": \"81bdc04e-9a0d-4306-9a9c-ee926fff6df8\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}, \"downloads\": {\"uuid\": \"56abdf27-b8d4-42f4-9b09-b7912db1c4f3\", \"name\": \"downloads\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {\"firefox_installer.zip\": {\"uuid\": \"02236b61-14bb-46aa-9fd5-7174c0d7d730\", \"name\": \"firefox_installer.zip\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"size\": 1024000, \"file_type\": \"ZIP\", \"num_access\": 0}}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 0, \"num_file_deletions\": 0}, \"applications\": {\"WebBrowser\": {\"uuid\": \"a6a12776-e307-4d71-9e7a-d9ca97ecd6b0\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 2, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": [], \"history\": []}, \"mspaint\": {\"uuid\": \"efd34549-cc92-4474-80ab-5fb6c3159ff6\", \"health_state_actual\": 1, \"health_state_visible\": 1, \"criticality\": 3, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 1, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {\"ARP\": {\"uuid\": \"e61c25ff-a6c2-4eec-b031-131eaf33490c\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 219, \"operating_state\": 2}, \"ICMP\": {\"uuid\": \"74debeed-b758-41cb-bea2-51ac283e6ae2\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 0, \"operating_state\": 2}, \"DNSClient\": {\"uuid\": \"6680efc0-e005-41e8-bb49-39a0d9c4b118\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 53, \"operating_state\": 2}, \"FTPClient\": {\"uuid\": \"21b05ac9-e9b4-4c5c-a812-f6748e14d8c3\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 21, \"operating_state\": 2}, \"NTPClient\": {\"uuid\": \"7ab7c911-5037-4e82-b00c-be4f72c13aa7\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 123, \"operating_state\": 2}}, \"process\": {}, \"revealed_to_red\": false}, \"google_server\": {\"uuid\": \"42d61d8d-2493-4b8a-944f-7962abc9d20b\", \"hostname\": \"google_server\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"e384a4fc-754f-44a4-9158-c63f72f52f76\", \"mac_address\": \"ea:5d:4f:10:b2:27\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"192.168.1.11\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}, \"2\": {\"uuid\": \"8a628493-83fb-44bf-a1b0-ef19e362ae5f\", \"mac_address\": \"44:89:a5:ce:7f:6f\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}, \"ip_address\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"wake_on_lan\": false}}, \"file_system\": {\"uuid\": \"f25cee1f-2ebe-4fd3-8d5c-649b0d342b61\", \"folders\": {\"root\": {\"uuid\": \"cbbd3631-a915-400d-bc02-f31f72447ce5\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {\"favicon.ico\": {\"uuid\": \"3ceeded4-77b9-4a86-949c-73188d5f4c34\", \"name\": \"favicon.ico\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"size\": 0, \"file_type\": \"UNKNOWN\", \"num_access\": 0}}, \"deleted_files\": {}}, \"static\": {\"uuid\": \"d8241ce0-f55e-43ec-bd68-741b79a9a565\", \"name\": \"static\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 1, \"num_file_deletions\": 0}, \"applications\": {\"WebBrowser\": {\"uuid\": \"957d0049-e703-4882-8e57-b2ab4c79d458\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 80, \"operating_state\": 2, \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": [], \"history\": []}}, \"services\": {\"ARP\": {\"uuid\": \"82ea1bcf-a0fe-418d-873e-5f075ebb4d3b\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 219, \"operating_state\": 2}, \"ICMP\": {\"uuid\": \"bc084dc4-0a7d-4954-9e6e-54bed797e837\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 0, \"operating_state\": 2}, \"DNSClient\": {\"uuid\": \"5a9ecc18-71c0-4728-a9c6-e31b33529581\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 53, \"operating_state\": 2}, \"FTPClient\": {\"uuid\": \"f0a411eb-5423-4c98-8689-d94af57deefc\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 21, \"operating_state\": 2}, \"NTPClient\": {\"uuid\": \"d36f2c4f-af30-4618-ae8e-fe68c98e1382\", \"health_state_actual\": 0, \"health_state_visible\": 0, \"criticality\": 1, \"fixing_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 100, \"tcp\": true, \"udp\": true, \"port\": 123, \"operating_state\": 2}}, \"process\": {}, \"revealed_to_red\": false}, \"switch1\": {\"uuid\": \"a9e08b28-d1f4-4c34-b410-71333cd6b42b\", \"hostname\": \"switch1\", \"operating_state\": 2, \"NICs\": {\"1\": {\"uuid\": \"3546e960-30f8-49ee-95b9-57570b228333\", \"mac_address\": \"8d:d9:3e:f3:a3:ce\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"2\": {\"uuid\": \"a049bb8f-53d3-4575-b325-dfb55516edcd\", \"mac_address\": \"aa:45:88:e1:13:e5\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"3\": {\"uuid\": \"179c030c-d8fe-474b-a9d1-6c6bd6e6ca63\", \"mac_address\": \"10:d7:bc:39:4d:9d\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"4\": {\"uuid\": \"56f84a14-0a98-4bc5-983b-31900fc9a2c5\", \"mac_address\": \"61:62:18:cf:2a:ea\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"5\": {\"uuid\": \"0ff4b64e-be4c-473e-8dcd-b7a0078ff890\", \"mac_address\": \"21:5e:6b:1b:d0:bf\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"6\": {\"uuid\": \"0edf239b-bbb8-4076-ba85-cb07c65722d5\", \"mac_address\": \"40:58:ac:11:9c:1a\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"7\": {\"uuid\": \"a7f578e5-a6f5-4cf8-abca-207e483637c2\", \"mac_address\": \"e0:ef:90:e2:ce:b4\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"8\": {\"uuid\": \"dc2069dd-ef3c-4e0b-81cb-a73caba917a8\", \"mac_address\": \"2c:2a:27:d6:9a:a8\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"9\": {\"uuid\": \"afbc1a01-efdb-424c-9a7d-b3c3165f6d78\", \"mac_address\": \"e0:f5:79:04:4f:2a\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"10\": {\"uuid\": \"bdd805f4-a3dc-4a94-ba67-3a62b138f41c\", \"mac_address\": \"9a:20:3d:cb:a0:98\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"11\": {\"uuid\": \"19f6f871-cba9-423a-a1a5-6a0e347e98cb\", \"mac_address\": \"69:d9:8c:1d:a9:75\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"12\": {\"uuid\": \"5c2aa6f5-12ce-466b-b46b-95ec519a5f47\", \"mac_address\": \"db:7e:8c:91:1b:3f\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}}, \"file_system\": {\"uuid\": \"91dea1d3-3947-49b9-a691-750bc25bbb9c\", \"folders\": {\"root\": {\"uuid\": \"b7ebbf43-d86f-43d3-bbc7-f6b197af40b9\", \"name\": \"root\", \"health_status\": 1, \"visible_status\": 1, \"previous_hash\": null, \"revealed_to_red\": false, \"files\": {}, \"deleted_files\": {}}}, \"deleted_folders\": {}, \"num_file_creations\": 0, \"num_file_deletions\": 0}, \"applications\": {}, \"services\": {}, \"process\": {}, \"revealed_to_red\": false, \"ports\": {\"1\": {\"uuid\": \"3546e960-30f8-49ee-95b9-57570b228333\", \"mac_address\": \"8d:d9:3e:f3:a3:ce\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"2\": {\"uuid\": \"a049bb8f-53d3-4575-b325-dfb55516edcd\", \"mac_address\": \"aa:45:88:e1:13:e5\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"3\": {\"uuid\": \"179c030c-d8fe-474b-a9d1-6c6bd6e6ca63\", \"mac_address\": \"10:d7:bc:39:4d:9d\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"4\": {\"uuid\": \"56f84a14-0a98-4bc5-983b-31900fc9a2c5\", \"mac_address\": \"61:62:18:cf:2a:ea\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"5\": {\"uuid\": \"0ff4b64e-be4c-473e-8dcd-b7a0078ff890\", \"mac_address\": \"21:5e:6b:1b:d0:bf\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"6\": {\"uuid\": \"0edf239b-bbb8-4076-ba85-cb07c65722d5\", \"mac_address\": \"40:58:ac:11:9c:1a\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"7\": {\"uuid\": \"a7f578e5-a6f5-4cf8-abca-207e483637c2\", \"mac_address\": \"e0:ef:90:e2:ce:b4\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"8\": {\"uuid\": \"dc2069dd-ef3c-4e0b-81cb-a73caba917a8\", \"mac_address\": \"2c:2a:27:d6:9a:a8\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"9\": {\"uuid\": \"afbc1a01-efdb-424c-9a7d-b3c3165f6d78\", \"mac_address\": \"e0:f5:79:04:4f:2a\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"10\": {\"uuid\": \"bdd805f4-a3dc-4a94-ba67-3a62b138f41c\", \"mac_address\": \"9a:20:3d:cb:a0:98\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"11\": {\"uuid\": \"19f6f871-cba9-423a-a1a5-6a0e347e98cb\", \"mac_address\": \"69:d9:8c:1d:a9:75\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}, \"12\": {\"uuid\": \"5c2aa6f5-12ce-466b-b46b-95ec519a5f47\", \"mac_address\": \"db:7e:8c:91:1b:3f\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false, \"nmne\": {}}}, \"num_ports\": 12, \"mac_address_table\": {}}}, \"links\": {\"primaite_pc:eth-2<->switch1:eth-1\": {\"uuid\": \"405f3032-6f5d-427f-b42e-5eee4cdc3a7c\", \"endpoint_a\": \"40c0db02-4d14-4826-b49b-e6a521941cec\", \"endpoint_b\": \"3546e960-30f8-49ee-95b9-57570b228333\", \"bandwidth\": 100.0, \"current_load\": 0.0, \"hostname_a\": \"primaite_pc\", \"hostname_b\": \"switch1\", \"port_a\": 2, \"port_b\": 1}, \"google_server:eth-2<->switch1:eth-2\": {\"uuid\": \"2bd19485-0a6b-4878-978b-b082a672d9b9\", \"endpoint_a\": \"8a628493-83fb-44bf-a1b0-ef19e362ae5f\", \"endpoint_b\": \"a049bb8f-53d3-4575-b325-dfb55516edcd\", \"bandwidth\": 100.0, \"current_load\": 0.0, \"hostname_a\": \"google_server\", \"hostname_b\": \"switch1\", \"port_a\": 2, \"port_b\": 2}}}, \"domain\": {\"uuid\": \"25fbe0e9-76e8-4fd7-ad22-da2d2b5a509d\", \"accounts\": {\"admin\": {\"uuid\": \"78783f13-6149-47b3-9b9d-f98d658bf54a\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": 2, \"enabled\": true}}}}'" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import json\n", "json.dumps(my_sim.describe_state())" From 9496441169052fb6925ea655de9503b6c0705c58 Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Tue, 9 Apr 2024 15:19:45 +0100 Subject: [PATCH 805/980] #2453 - Ignore this commit. Removing saved output in Training-an-SB3-Agent Notebook --- .../notebooks/Training-an-SB3-Agent.ipynb | 7337 +---------------- 1 file changed, 13 insertions(+), 7324 deletions(-) diff --git a/src/primaite/notebooks/Training-an-SB3-Agent.ipynb b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb index 67d9748e..8d6789ee 100644 --- a/src/primaite/notebooks/Training-an-SB3-Agent.ipynb +++ b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -32,24 +32,16 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - } - ], + "outputs": [], "source": [ "gym = PrimaiteGymEnv(game_config=cfg)" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -64,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -73,7141 +65,16 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:28,065: Resetting environment, episode 0, avg. reward: 0.0\n", - "2024-04-08 14:49:28,068: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_0.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:29,639: Resetting environment, episode 1, avg. reward: -17.149999999999974\n", - "2024-04-08 14:49:29,643: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_1.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:31,337: Resetting environment, episode 2, avg. reward: -12.099999999999989\n", - "2024-04-08 14:49:31,339: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_2.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:32,540: Resetting environment, episode 3, avg. reward: -44.500000000000064\n", - "2024-04-08 14:49:32,543: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_3.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:33,721: Resetting environment, episode 4, avg. reward: -22.949999999999953\n", - "2024-04-08 14:49:33,724: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_4.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:35,248: Resetting environment, episode 5, avg. reward: -17.64999999999998\n", - "2024-04-08 14:49:35,253: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_5.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:36,676: Resetting environment, episode 6, avg. reward: -21.949999999999953\n", - "2024-04-08 14:49:36,679: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_6.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:38,158: Resetting environment, episode 7, avg. reward: -88.5999999999998\n", - "2024-04-08 14:49:38,161: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_7.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:39,570: Resetting environment, episode 8, avg. reward: -42.750000000000156\n", - "2024-04-08 14:49:39,572: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_8.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:40,917: Resetting environment, episode 9, avg. reward: -13.999999999999982\n", - "2024-04-08 14:49:40,920: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_9.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:42,112: Resetting environment, episode 10, avg. reward: -34.55000000000001\n", - "2024-04-08 14:49:42,116: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_10.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:43,768: Resetting environment, episode 11, avg. reward: -19.399999999999963\n", - "2024-04-08 14:49:43,771: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_11.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:45,216: Resetting environment, episode 12, avg. reward: -11.049999999999988\n", - "2024-04-08 14:49:45,219: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_12.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:46,830: Resetting environment, episode 13, avg. reward: -33.1\n", - "2024-04-08 14:49:46,833: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_13.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:48,302: Resetting environment, episode 14, avg. reward: -17.499999999999968\n", - "2024-04-08 14:49:48,306: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_14.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:50,142: Resetting environment, episode 15, avg. reward: -22.299999999999955\n", - "2024-04-08 14:49:50,146: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_15.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:51,603: Resetting environment, episode 16, avg. reward: -64.8500000000001\n", - "2024-04-08 14:49:51,606: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_16.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:53,295: Resetting environment, episode 17, avg. reward: -67.24999999999999\n", - "2024-04-08 14:49:53,298: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_17.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:54,630: Resetting environment, episode 18, avg. reward: -20.799999999999958\n", - "2024-04-08 14:49:54,633: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_18.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:56,091: Resetting environment, episode 19, avg. reward: -62.55000000000001\n", - "2024-04-08 14:49:56,093: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_19.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:57,486: Resetting environment, episode 20, avg. reward: -24.649999999999984\n", - "2024-04-08 14:49:57,489: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_20.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:49:59,243: Resetting environment, episode 21, avg. reward: -9.649999999999997\n", - "2024-04-08 14:49:59,246: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_21.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:00,812: Resetting environment, episode 22, avg. reward: -21.749999999999957\n", - "2024-04-08 14:50:00,815: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_22.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:02,403: Resetting environment, episode 23, avg. reward: -15.949999999999978\n", - "2024-04-08 14:50:02,405: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_23.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:04,363: Resetting environment, episode 24, avg. reward: -83.15000000000002\n", - "2024-04-08 14:50:04,366: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_24.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:06,083: Resetting environment, episode 25, avg. reward: -36.15000000000003\n", - "2024-04-08 14:50:06,085: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_25.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:07,813: Resetting environment, episode 26, avg. reward: -67.25000000000007\n", - "2024-04-08 14:50:07,816: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_26.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:09,419: Resetting environment, episode 27, avg. reward: -44.200000000000074\n", - "2024-04-08 14:50:09,422: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_27.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:10,969: Resetting environment, episode 28, avg. reward: -64.1500000000001\n", - "2024-04-08 14:50:10,973: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_28.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:12,518: Resetting environment, episode 29, avg. reward: -18.34999999999997\n", - "2024-04-08 14:50:12,519: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_29.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:14,004: Resetting environment, episode 30, avg. reward: -17.69999999999997\n", - "2024-04-08 14:50:14,007: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_30.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:16,007: Resetting environment, episode 31, avg. reward: -28.700000000000017\n", - "2024-04-08 14:50:16,010: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_31.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:17,755: Resetting environment, episode 32, avg. reward: -53.65000000000015\n", - "2024-04-08 14:50:17,758: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_32.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:19,232: Resetting environment, episode 33, avg. reward: -43.65000000000005\n", - "2024-04-08 14:50:19,235: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_33.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:20,708: Resetting environment, episode 34, avg. reward: -2.499999999999969\n", - "2024-04-08 14:50:20,711: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_34.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:22,081: Resetting environment, episode 35, avg. reward: -51.45000000000008\n", - "2024-04-08 14:50:22,084: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_35.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:23,461: Resetting environment, episode 36, avg. reward: -24.749999999999986\n", - "2024-04-08 14:50:23,465: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_36.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:24,909: Resetting environment, episode 37, avg. reward: -72.70000000000002\n", - "2024-04-08 14:50:24,912: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_37.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:27,049: Resetting environment, episode 38, avg. reward: -16.049999999999976\n", - "2024-04-08 14:50:27,052: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_38.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:28,362: Resetting environment, episode 39, avg. reward: -27.79999999999996\n", - "2024-04-08 14:50:28,364: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_39.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:29,821: Resetting environment, episode 40, avg. reward: -61.9500000000001\n", - "2024-04-08 14:50:29,824: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_40.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:31,787: Resetting environment, episode 41, avg. reward: -36.00000000000004\n", - "2024-04-08 14:50:31,790: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_41.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:33,074: Resetting environment, episode 42, avg. reward: -44.35000000000007\n", - "2024-04-08 14:50:33,077: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_42.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:34,739: Resetting environment, episode 43, avg. reward: -51.100000000000065\n", - "2024-04-08 14:50:34,742: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_43.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:36,357: Resetting environment, episode 44, avg. reward: -65.95000000000002\n", - "2024-04-08 14:50:36,359: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_44.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:37,834: Resetting environment, episode 45, avg. reward: -45.750000000000064\n", - "2024-04-08 14:50:37,838: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_45.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:39,768: Resetting environment, episode 46, avg. reward: -22.39999999999994\n", - "2024-04-08 14:50:39,774: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_46.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:41,672: Resetting environment, episode 47, avg. reward: -18.749999999999993\n", - "2024-04-08 14:50:41,677: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_47.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:43,816: Resetting environment, episode 48, avg. reward: -65.4\n", - "2024-04-08 14:50:43,818: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_48.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:45,262: Resetting environment, episode 49, avg. reward: -20.09999999999996\n", - "2024-04-08 14:50:45,266: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_49.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:46,955: Resetting environment, episode 50, avg. reward: -21.899999999999967\n", - "2024-04-08 14:50:46,958: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_50.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:49,698: Resetting environment, episode 51, avg. reward: -20.399999999999963\n", - "2024-04-08 14:50:49,701: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_51.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:51,463: Resetting environment, episode 52, avg. reward: -21.399999999999956\n", - "2024-04-08 14:50:51,467: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_52.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:53,214: Resetting environment, episode 53, avg. reward: -19.249999999999982\n", - "2024-04-08 14:50:53,218: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_53.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:55,080: Resetting environment, episode 54, avg. reward: -57.90000000000009\n", - "2024-04-08 14:50:55,084: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_54.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:56,690: Resetting environment, episode 55, avg. reward: -14.099999999999982\n", - "2024-04-08 14:50:56,694: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_55.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:58,423: Resetting environment, episode 56, avg. reward: -22.79999999999995\n", - "2024-04-08 14:50:58,427: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_56.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:50:59,941: Resetting environment, episode 57, avg. reward: -18.39999999999997\n", - "2024-04-08 14:50:59,944: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_57.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:01,528: Resetting environment, episode 58, avg. reward: -49.25000000000011\n", - "2024-04-08 14:51:01,532: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_58.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:03,202: Resetting environment, episode 59, avg. reward: -14.449999999999964\n", - "2024-04-08 14:51:03,204: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_59.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:04,611: Resetting environment, episode 60, avg. reward: -11.649999999999991\n", - "2024-04-08 14:51:04,614: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_60.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:06,388: Resetting environment, episode 61, avg. reward: -17.59999999999997\n", - "2024-04-08 14:51:06,391: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_61.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:07,952: Resetting environment, episode 62, avg. reward: -68.39999999999998\n", - "2024-04-08 14:51:07,956: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_62.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:09,416: Resetting environment, episode 63, avg. reward: -19.999999999999957\n", - "2024-04-08 14:51:09,420: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_63.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:10,728: Resetting environment, episode 64, avg. reward: -49.25000000000008\n", - "2024-04-08 14:51:10,731: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_64.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:12,298: Resetting environment, episode 65, avg. reward: -21.29999999999999\n", - "2024-04-08 14:51:12,302: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_65.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:14,232: Resetting environment, episode 66, avg. reward: -46.55000000000018\n", - "2024-04-08 14:51:14,235: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_66.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:15,645: Resetting environment, episode 67, avg. reward: -30.050000000000008\n", - "2024-04-08 14:51:15,648: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_67.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:17,264: Resetting environment, episode 68, avg. reward: -72.80000000000003\n", - "2024-04-08 14:51:17,268: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_68.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:18,742: Resetting environment, episode 69, avg. reward: -100.84999999999998\n", - "2024-04-08 14:51:18,745: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_69.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:20,149: Resetting environment, episode 70, avg. reward: -33.85000000000002\n", - "2024-04-08 14:51:20,153: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_70.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:21,992: Resetting environment, episode 71, avg. reward: -93.30000000000003\n", - "2024-04-08 14:51:21,995: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_71.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:23,375: Resetting environment, episode 72, avg. reward: -18.049999999999965\n", - "2024-04-08 14:51:23,378: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_72.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:24,808: Resetting environment, episode 73, avg. reward: -52.80000000000021\n", - "2024-04-08 14:51:24,811: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_73.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:26,230: Resetting environment, episode 74, avg. reward: -16.449999999999974\n", - "2024-04-08 14:51:26,234: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_74.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:27,721: Resetting environment, episode 75, avg. reward: -56.400000000000006\n", - "2024-04-08 14:51:27,724: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_75.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:29,150: Resetting environment, episode 76, avg. reward: -13.799999999999976\n", - "2024-04-08 14:51:29,152: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_76.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:30,654: Resetting environment, episode 77, avg. reward: -22.749999999999996\n", - "2024-04-08 14:51:30,658: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_77.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:32,221: Resetting environment, episode 78, avg. reward: -8.949999999999998\n", - "2024-04-08 14:51:32,224: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_78.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:33,561: Resetting environment, episode 79, avg. reward: -35.84999999999997\n", - "2024-04-08 14:51:33,565: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_79.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:35,158: Resetting environment, episode 80, avg. reward: -7.049999999999989\n", - "2024-04-08 14:51:35,160: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_80.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:37,129: Resetting environment, episode 81, avg. reward: -27.349999999999984\n", - "2024-04-08 14:51:37,131: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_81.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:38,672: Resetting environment, episode 82, avg. reward: -40.65000000000012\n", - "2024-04-08 14:51:38,675: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_82.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:41,263: Resetting environment, episode 83, avg. reward: -52.10000000000015\n", - "2024-04-08 14:51:41,267: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_83.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:42,701: Resetting environment, episode 84, avg. reward: -21.649999999999956\n", - "2024-04-08 14:51:42,705: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_84.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:44,319: Resetting environment, episode 85, avg. reward: -31.600000000000016\n", - "2024-04-08 14:51:44,322: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_85.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:45,992: Resetting environment, episode 86, avg. reward: -24.300000000000004\n", - "2024-04-08 14:51:45,992: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_86.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:47,709: Resetting environment, episode 87, avg. reward: -11.849999999999982\n", - "2024-04-08 14:51:47,711: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_87.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:49,249: Resetting environment, episode 88, avg. reward: -11.799999999999992\n", - "2024-04-08 14:51:49,252: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_88.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:50,852: Resetting environment, episode 89, avg. reward: -10.099999999999964\n", - "2024-04-08 14:51:50,854: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_89.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:52,578: Resetting environment, episode 90, avg. reward: -27.799999999999972\n", - "2024-04-08 14:51:52,581: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_90.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:54,406: Resetting environment, episode 91, avg. reward: -23.04999999999995\n", - "2024-04-08 14:51:54,410: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_91.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:56,371: Resetting environment, episode 92, avg. reward: -18.449999999999967\n", - "2024-04-08 14:51:56,375: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_92.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:58,036: Resetting environment, episode 93, avg. reward: -12.04999999999997\n", - "2024-04-08 14:51:58,040: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_93.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:51:59,859: Resetting environment, episode 94, avg. reward: -10.749999999999984\n", - "2024-04-08 14:51:59,862: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_94.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:01,324: Resetting environment, episode 95, avg. reward: -16.999999999999975\n", - "2024-04-08 14:52:01,327: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_95.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:03,061: Resetting environment, episode 96, avg. reward: -64.80000000000003\n", - "2024-04-08 14:52:03,064: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_96.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:04,843: Resetting environment, episode 97, avg. reward: -93.19999999999995\n", - "2024-04-08 14:52:04,846: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_97.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:06,197: Resetting environment, episode 98, avg. reward: -23.44999999999995\n", - "2024-04-08 14:52:06,200: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_98.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:07,802: Resetting environment, episode 99, avg. reward: 1.7500000000000147\n", - "2024-04-08 14:52:07,810: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_99.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:09,595: Resetting environment, episode 100, avg. reward: -31.450000000000003\n", - "2024-04-08 14:52:09,598: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_100.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:11,206: Resetting environment, episode 101, avg. reward: -9.499999999999988\n", - "2024-04-08 14:52:11,209: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_101.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:13,334: Resetting environment, episode 102, avg. reward: -15.149999999999983\n", - "2024-04-08 14:52:13,337: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_102.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:15,208: Resetting environment, episode 103, avg. reward: 0.2500000000000171\n", - "2024-04-08 14:52:15,212: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_103.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:17,126: Resetting environment, episode 104, avg. reward: 14.55\n", - "2024-04-08 14:52:17,130: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_104.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:18,662: Resetting environment, episode 105, avg. reward: -16.04999999999997\n", - "2024-04-08 14:52:18,666: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_105.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:20,144: Resetting environment, episode 106, avg. reward: -80.69999999999997\n", - "2024-04-08 14:52:20,147: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_106.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:21,595: Resetting environment, episode 107, avg. reward: -16.099999999999977\n", - "2024-04-08 14:52:21,599: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_107.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:23,331: Resetting environment, episode 108, avg. reward: -46.80000000000007\n", - "2024-04-08 14:52:23,335: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_108.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:25,083: Resetting environment, episode 109, avg. reward: -22.84999999999995\n", - "2024-04-08 14:52:25,086: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_109.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:26,589: Resetting environment, episode 110, avg. reward: -10.199999999999996\n", - "2024-04-08 14:52:26,592: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_110.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:28,410: Resetting environment, episode 111, avg. reward: -95.99999999999997\n", - "2024-04-08 14:52:28,413: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_111.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:29,966: Resetting environment, episode 112, avg. reward: -17.59999999999997\n", - "2024-04-08 14:52:29,969: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_112.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:31,317: Resetting environment, episode 113, avg. reward: -20.099999999999962\n", - "2024-04-08 14:52:31,321: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_113.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:32,840: Resetting environment, episode 114, avg. reward: -42.850000000000165\n", - "2024-04-08 14:52:32,843: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_114.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:34,336: Resetting environment, episode 115, avg. reward: -22.249999999999954\n", - "2024-04-08 14:52:34,339: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_115.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:35,794: Resetting environment, episode 116, avg. reward: -90.9\n", - "2024-04-08 14:52:35,797: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_116.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:37,489: Resetting environment, episode 117, avg. reward: 5.90000000000003\n", - "2024-04-08 14:52:37,492: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_117.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:39,009: Resetting environment, episode 118, avg. reward: -66.1\n", - "2024-04-08 14:52:39,012: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_118.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:40,602: Resetting environment, episode 119, avg. reward: -36.749999999999964\n", - "2024-04-08 14:52:40,605: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_119.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:42,128: Resetting environment, episode 120, avg. reward: -13.79999999999999\n", - "2024-04-08 14:52:42,131: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_120.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:43,990: Resetting environment, episode 121, avg. reward: -30.750000000000007\n", - "2024-04-08 14:52:43,993: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_121.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:45,565: Resetting environment, episode 122, avg. reward: -99.95\n", - "2024-04-08 14:52:45,568: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_122.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:48,013: Resetting environment, episode 123, avg. reward: 0.3500000000000256\n", - "2024-04-08 14:52:48,016: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_123.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:50,029: Resetting environment, episode 124, avg. reward: -15.299999999999981\n", - "2024-04-08 14:52:50,032: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_124.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:51,501: Resetting environment, episode 125, avg. reward: -15.149999999999975\n", - "2024-04-08 14:52:51,502: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_125.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:53,184: Resetting environment, episode 126, avg. reward: -90.35\n", - "2024-04-08 14:52:53,186: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_126.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:54,836: Resetting environment, episode 127, avg. reward: -19.9\n", - "2024-04-08 14:52:54,839: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_127.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:56,110: Resetting environment, episode 128, avg. reward: -17.299999999999976\n", - "2024-04-08 14:52:56,113: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_128.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:57,610: Resetting environment, episode 129, avg. reward: -12.499999999999996\n", - "2024-04-08 14:52:57,613: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_129.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:52:59,237: Resetting environment, episode 130, avg. reward: -17.24999999999996\n", - "2024-04-08 14:52:59,240: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_130.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:00,835: Resetting environment, episode 131, avg. reward: -11.64999999999998\n", - "2024-04-08 14:53:00,838: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_131.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:02,203: Resetting environment, episode 132, avg. reward: -27.799999999999986\n", - "2024-04-08 14:53:02,206: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_132.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:03,544: Resetting environment, episode 133, avg. reward: -10.399999999999997\n", - "2024-04-08 14:53:03,547: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_133.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:04,974: Resetting environment, episode 134, avg. reward: -18.0\n", - "2024-04-08 14:53:04,977: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_134.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:06,363: Resetting environment, episode 135, avg. reward: -84.0\n", - "2024-04-08 14:53:06,367: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_135.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:07,884: Resetting environment, episode 136, avg. reward: -20.949999999999964\n", - "2024-04-08 14:53:07,886: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_136.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:09,146: Resetting environment, episode 137, avg. reward: -13.749999999999984\n", - "2024-04-08 14:53:09,149: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_137.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:10,482: Resetting environment, episode 138, avg. reward: -15.299999999999976\n", - "2024-04-08 14:53:10,484: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_138.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:11,761: Resetting environment, episode 139, avg. reward: -87.34999999999994\n", - "2024-04-08 14:53:11,764: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_139.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:13,069: Resetting environment, episode 140, avg. reward: -13.249999999999986\n", - "2024-04-08 14:53:13,072: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_140.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:14,623: Resetting environment, episode 141, avg. reward: -22.499999999999968\n", - "2024-04-08 14:53:14,626: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_141.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:16,023: Resetting environment, episode 142, avg. reward: -42.25\n", - "2024-04-08 14:53:16,026: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_142.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:17,572: Resetting environment, episode 143, avg. reward: -16.35000000000001\n", - "2024-04-08 14:53:17,575: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_143.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:18,887: Resetting environment, episode 144, avg. reward: -80.9\n", - "2024-04-08 14:53:18,891: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_144.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:20,236: Resetting environment, episode 145, avg. reward: -15.299999999999974\n", - "2024-04-08 14:53:20,239: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_145.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:21,625: Resetting environment, episode 146, avg. reward: -21.799999999999955\n", - "2024-04-08 14:53:21,628: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_146.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:23,799: Resetting environment, episode 147, avg. reward: -13.599999999999998\n", - "2024-04-08 14:53:23,802: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_147.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:25,308: Resetting environment, episode 148, avg. reward: -99.1\n", - "2024-04-08 14:53:25,310: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_148.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:27,254: Resetting environment, episode 149, avg. reward: -16.74999999999997\n", - "2024-04-08 14:53:27,259: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_149.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:29,053: Resetting environment, episode 150, avg. reward: -10.749999999999979\n", - "2024-04-08 14:53:29,057: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_150.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:30,939: Resetting environment, episode 151, avg. reward: -74.05\n", - "2024-04-08 14:53:30,942: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_151.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:32,476: Resetting environment, episode 152, avg. reward: -71.6\n", - "2024-04-08 14:53:32,476: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_152.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:34,490: Resetting environment, episode 153, avg. reward: -11.749999999999961\n", - "2024-04-08 14:53:34,493: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_153.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:36,594: Resetting environment, episode 154, avg. reward: -8.700000000000005\n", - "2024-04-08 14:53:36,598: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_154.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:38,245: Resetting environment, episode 155, avg. reward: -21.649999999999956\n", - "2024-04-08 14:53:38,249: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_155.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:39,875: Resetting environment, episode 156, avg. reward: -7.649999999999994\n", - "2024-04-08 14:53:39,879: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_156.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:41,685: Resetting environment, episode 157, avg. reward: -80.54999999999998\n", - "2024-04-08 14:53:41,690: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_157.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:43,273: Resetting environment, episode 158, avg. reward: -14.799999999999978\n", - "2024-04-08 14:53:43,279: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_158.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:44,718: Resetting environment, episode 159, avg. reward: -8.299999999999976\n", - "2024-04-08 14:53:44,720: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_159.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:46,211: Resetting environment, episode 160, avg. reward: -45.05000000000009\n", - "2024-04-08 14:53:46,215: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_160.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:48,427: Resetting environment, episode 161, avg. reward: -0.29999999999997673\n", - "2024-04-08 14:53:48,431: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_161.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:50,514: Resetting environment, episode 162, avg. reward: -24.199999999999946\n", - "2024-04-08 14:53:50,517: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_162.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:52,023: Resetting environment, episode 163, avg. reward: -22.249999999999954\n", - "2024-04-08 14:53:52,027: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_163.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:53,865: Resetting environment, episode 164, avg. reward: -16.44999999999996\n", - "2024-04-08 14:53:53,868: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_164.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:55,434: Resetting environment, episode 165, avg. reward: -75.8\n", - "2024-04-08 14:53:55,437: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_165.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:57,361: Resetting environment, episode 166, avg. reward: -15.74999999999998\n", - "2024-04-08 14:53:57,364: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_166.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:53:59,167: Resetting environment, episode 167, avg. reward: -97.04999999999997\n", - "2024-04-08 14:53:59,171: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_167.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:00,965: Resetting environment, episode 168, avg. reward: -26.450000000000006\n", - "2024-04-08 14:54:00,970: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_168.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:02,555: Resetting environment, episode 169, avg. reward: -1.7999999999999803\n", - "2024-04-08 14:54:02,556: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_169.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:04,283: Resetting environment, episode 170, avg. reward: -16.499999999999964\n", - "2024-04-08 14:54:04,292: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_170.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:06,710: Resetting environment, episode 171, avg. reward: -56.99999999999997\n", - "2024-04-08 14:54:06,714: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_171.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:08,495: Resetting environment, episode 172, avg. reward: -5.550000000000001\n", - "2024-04-08 14:54:08,502: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_172.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:10,090: Resetting environment, episode 173, avg. reward: -16.249999999999968\n", - "2024-04-08 14:54:10,094: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_173.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:13,065: Resetting environment, episode 174, avg. reward: -6.6499999999999915\n", - "2024-04-08 14:54:13,071: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_174.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:15,757: Resetting environment, episode 175, avg. reward: -3.7499999999999707\n", - "2024-04-08 14:54:15,761: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_175.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:18,490: Resetting environment, episode 176, avg. reward: 34.24999999999989\n", - "2024-04-08 14:54:18,493: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_176.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:20,751: Resetting environment, episode 177, avg. reward: -15.999999999999977\n", - "2024-04-08 14:54:20,755: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_177.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:23,269: Resetting environment, episode 178, avg. reward: -80.50000000000001\n", - "2024-04-08 14:54:23,273: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_178.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:25,507: Resetting environment, episode 179, avg. reward: -12.849999999999989\n", - "2024-04-08 14:54:25,510: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_179.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:27,454: Resetting environment, episode 180, avg. reward: -16.949999999999996\n", - "2024-04-08 14:54:27,458: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_180.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:29,884: Resetting environment, episode 181, avg. reward: 1.9000000000000221\n", - "2024-04-08 14:54:29,887: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_181.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:32,113: Resetting environment, episode 182, avg. reward: 9.500000000000046\n", - "2024-04-08 14:54:32,117: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_182.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:34,283: Resetting environment, episode 183, avg. reward: -91.0500000000001\n", - "2024-04-08 14:54:34,286: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_183.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:36,330: Resetting environment, episode 184, avg. reward: -43.15000000000006\n", - "2024-04-08 14:54:36,332: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_184.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:38,270: Resetting environment, episode 185, avg. reward: -99.0\n", - "2024-04-08 14:54:38,274: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_185.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:40,645: Resetting environment, episode 186, avg. reward: -19.849999999999962\n", - "2024-04-08 14:54:40,648: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_186.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:42,998: Resetting environment, episode 187, avg. reward: -24.299999999999983\n", - "2024-04-08 14:54:43,002: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_187.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:45,260: Resetting environment, episode 188, avg. reward: -15.449999999999973\n", - "2024-04-08 14:54:45,263: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_188.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:47,356: Resetting environment, episode 189, avg. reward: -46.15000000000005\n", - "2024-04-08 14:54:47,362: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_189.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:49,422: Resetting environment, episode 190, avg. reward: -15.849999999999996\n", - "2024-04-08 14:54:49,425: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_190.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:51,753: Resetting environment, episode 191, avg. reward: 2.200000000000034\n", - "2024-04-08 14:54:51,757: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_191.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:54,077: Resetting environment, episode 192, avg. reward: 8.950000000000049\n", - "2024-04-08 14:54:54,081: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_192.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:56,257: Resetting environment, episode 193, avg. reward: -10.949999999999985\n", - "2024-04-08 14:54:56,261: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_193.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:54:59,376: Resetting environment, episode 194, avg. reward: -23.449999999999957\n", - "2024-04-08 14:54:59,379: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_194.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:02,626: Resetting environment, episode 195, avg. reward: -98.24999999999996\n", - "2024-04-08 14:55:02,630: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_195.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:05,232: Resetting environment, episode 196, avg. reward: -20.299999999999976\n", - "2024-04-08 14:55:05,236: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_196.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:08,026: Resetting environment, episode 197, avg. reward: -6.399999999999993\n", - "2024-04-08 14:55:08,029: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_197.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:09,878: Resetting environment, episode 198, avg. reward: -20.099999999999962\n", - "2024-04-08 14:55:09,882: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_198.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:12,337: Resetting environment, episode 199, avg. reward: -20.59999999999996\n", - "2024-04-08 14:55:12,340: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_199.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:14,794: Resetting environment, episode 200, avg. reward: -80.65000000000002\n", - "2024-04-08 14:55:14,798: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_200.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:17,788: Resetting environment, episode 201, avg. reward: 11.249999999999932\n", - "2024-04-08 14:55:17,792: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_201.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:20,227: Resetting environment, episode 202, avg. reward: -85.35\n", - "2024-04-08 14:55:20,230: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_202.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:22,623: Resetting environment, episode 203, avg. reward: -67.9\n", - "2024-04-08 14:55:22,626: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_203.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:27,001: Resetting environment, episode 204, avg. reward: -94.30000000000017\n", - "2024-04-08 14:55:27,004: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_204.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:28,803: Resetting environment, episode 205, avg. reward: -30.39999999999997\n", - "2024-04-08 14:55:28,808: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_205.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:30,621: Resetting environment, episode 206, avg. reward: -25.14999999999995\n", - "2024-04-08 14:55:30,623: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_206.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:32,191: Resetting environment, episode 207, avg. reward: -98.14999999999998\n", - "2024-04-08 14:55:32,194: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_207.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:33,920: Resetting environment, episode 208, avg. reward: -17.64999999999998\n", - "2024-04-08 14:55:33,923: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_208.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:36,333: Resetting environment, episode 209, avg. reward: -88.25\n", - "2024-04-08 14:55:36,336: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_209.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:38,489: Resetting environment, episode 210, avg. reward: -85.35\n", - "2024-04-08 14:55:38,494: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_210.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:40,664: Resetting environment, episode 211, avg. reward: -15.649999999999979\n", - "2024-04-08 14:55:40,668: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_211.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:42,341: Resetting environment, episode 212, avg. reward: -15.24999999999998\n", - "2024-04-08 14:55:42,344: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_212.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:43,931: Resetting environment, episode 213, avg. reward: -100.25000000000009\n", - "2024-04-08 14:55:43,935: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_213.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:45,687: Resetting environment, episode 214, avg. reward: -50.59999999999998\n", - "2024-04-08 14:55:45,690: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_214.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:47,397: Resetting environment, episode 215, avg. reward: -14.94999999999998\n", - "2024-04-08 14:55:47,400: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_215.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:49,303: Resetting environment, episode 216, avg. reward: -91.64999999999995\n", - "2024-04-08 14:55:49,306: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_216.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:50,916: Resetting environment, episode 217, avg. reward: -75.89999999999999\n", - "2024-04-08 14:55:50,918: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_217.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:53,007: Resetting environment, episode 218, avg. reward: -91.50000000000007\n", - "2024-04-08 14:55:53,011: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_218.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:55,088: Resetting environment, episode 219, avg. reward: -8.300000000000004\n", - "2024-04-08 14:55:55,092: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_219.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:57,164: Resetting environment, episode 220, avg. reward: -29.449999999999996\n", - "2024-04-08 14:55:57,167: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_220.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:55:58,938: Resetting environment, episode 221, avg. reward: -38.20000000000004\n", - "2024-04-08 14:55:58,942: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_221.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:00,655: Resetting environment, episode 222, avg. reward: -38.60000000000001\n", - "2024-04-08 14:56:00,658: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_222.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:02,297: Resetting environment, episode 223, avg. reward: -37.79999999999999\n", - "2024-04-08 14:56:02,300: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_223.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:03,931: Resetting environment, episode 224, avg. reward: -53.24999999999996\n", - "2024-04-08 14:56:03,935: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_224.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:05,761: Resetting environment, episode 225, avg. reward: -77.99999999999997\n", - "2024-04-08 14:56:05,764: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_225.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:07,294: Resetting environment, episode 226, avg. reward: -26.799999999999972\n", - "2024-04-08 14:56:07,298: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_226.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:09,002: Resetting environment, episode 227, avg. reward: -94.5500000000001\n", - "2024-04-08 14:56:09,006: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_227.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:10,831: Resetting environment, episode 228, avg. reward: -76.05000000000001\n", - "2024-04-08 14:56:10,834: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_228.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:12,658: Resetting environment, episode 229, avg. reward: 3.350000000000028\n", - "2024-04-08 14:56:12,661: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_229.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:14,404: Resetting environment, episode 230, avg. reward: -51.25000000000004\n", - "2024-04-08 14:56:14,409: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_230.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:16,439: Resetting environment, episode 231, avg. reward: -86.5\n", - "2024-04-08 14:56:16,442: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_231.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:18,025: Resetting environment, episode 232, avg. reward: -9.550000000000002\n", - "2024-04-08 14:56:18,029: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_232.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:19,978: Resetting environment, episode 233, avg. reward: -46.75\n", - "2024-04-08 14:56:19,982: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_233.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:21,638: Resetting environment, episode 234, avg. reward: -87.14999999999999\n", - "2024-04-08 14:56:21,642: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_234.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:23,262: Resetting environment, episode 235, avg. reward: -60.94999999999995\n", - "2024-04-08 14:56:23,265: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_235.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:24,866: Resetting environment, episode 236, avg. reward: -5.299999999999963\n", - "2024-04-08 14:56:24,870: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_236.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:26,594: Resetting environment, episode 237, avg. reward: -7.49999999999999\n", - "2024-04-08 14:56:26,597: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_237.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:29,812: Resetting environment, episode 238, avg. reward: -4.749999999999977\n", - "2024-04-08 14:56:29,815: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_238.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:31,530: Resetting environment, episode 239, avg. reward: -13.349999999999982\n", - "2024-04-08 14:56:31,533: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_239.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:33,444: Resetting environment, episode 240, avg. reward: -0.599999999999985\n", - "2024-04-08 14:56:33,447: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_240.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:35,290: Resetting environment, episode 241, avg. reward: -95.3\n", - "2024-04-08 14:56:35,292: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_241.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:36,923: Resetting environment, episode 242, avg. reward: -94.94999999999996\n", - "2024-04-08 14:56:36,927: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_242.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:38,916: Resetting environment, episode 243, avg. reward: -72.49999999999993\n", - "2024-04-08 14:56:38,919: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_243.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:40,743: Resetting environment, episode 244, avg. reward: -0.7499999999999888\n", - "2024-04-08 14:56:40,746: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_244.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:42,525: Resetting environment, episode 245, avg. reward: -2.5999999999999943\n", - "2024-04-08 14:56:42,528: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_245.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:44,452: Resetting environment, episode 246, avg. reward: -79.40000000000002\n", - "2024-04-08 14:56:44,455: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_246.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:46,246: Resetting environment, episode 247, avg. reward: -72.7\n", - "2024-04-08 14:56:46,249: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_247.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:48,054: Resetting environment, episode 248, avg. reward: -26.04999999999994\n", - "2024-04-08 14:56:48,058: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_248.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:50,022: Resetting environment, episode 249, avg. reward: -51.100000000000016\n", - "2024-04-08 14:56:50,025: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_249.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:51,853: Resetting environment, episode 250, avg. reward: -9.89999999999996\n", - "2024-04-08 14:56:51,857: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_250.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:53,997: Resetting environment, episode 251, avg. reward: -64.64999999999995\n", - "2024-04-08 14:56:54,001: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_251.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:56,347: Resetting environment, episode 252, avg. reward: -44.999999999999964\n", - "2024-04-08 14:56:56,350: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_252.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:56:58,286: Resetting environment, episode 253, avg. reward: -91.30000000000001\n", - "2024-04-08 14:56:58,288: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_253.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:00,634: Resetting environment, episode 254, avg. reward: -95.24999999999997\n", - "2024-04-08 14:57:00,638: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_254.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:02,345: Resetting environment, episode 255, avg. reward: -15.099999999999978\n", - "2024-04-08 14:57:02,350: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_255.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:04,152: Resetting environment, episode 256, avg. reward: -84.75000000000011\n", - "2024-04-08 14:57:04,155: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_256.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:05,658: Resetting environment, episode 257, avg. reward: -17.399999999999974\n", - "2024-04-08 14:57:05,661: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_257.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:07,257: Resetting environment, episode 258, avg. reward: -17.74999999999997\n", - "2024-04-08 14:57:07,267: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_258.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:09,280: Resetting environment, episode 259, avg. reward: -95.50000000000001\n", - "2024-04-08 14:57:09,283: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_259.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:11,050: Resetting environment, episode 260, avg. reward: -1.4499999999999633\n", - "2024-04-08 14:57:11,054: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_260.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:13,023: Resetting environment, episode 261, avg. reward: -92.59999999999997\n", - "2024-04-08 14:57:13,026: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_261.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:14,723: Resetting environment, episode 262, avg. reward: -2.5999999999999814\n", - "2024-04-08 14:57:14,726: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_262.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:17,321: Resetting environment, episode 263, avg. reward: -60.95000000000002\n", - "2024-04-08 14:57:17,324: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_263.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:19,220: Resetting environment, episode 264, avg. reward: -19.449999999999964\n", - "2024-04-08 14:57:19,223: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_264.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:21,072: Resetting environment, episode 265, avg. reward: -86.4\n", - "2024-04-08 14:57:21,076: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_265.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:22,895: Resetting environment, episode 266, avg. reward: -91.89999999999996\n", - "2024-04-08 14:57:22,899: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_266.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:24,815: Resetting environment, episode 267, avg. reward: -44.5\n", - "2024-04-08 14:57:24,819: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_267.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:26,841: Resetting environment, episode 268, avg. reward: -3.3999999999999875\n", - "2024-04-08 14:57:26,845: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_268.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:28,525: Resetting environment, episode 269, avg. reward: -61.79999999999996\n", - "2024-04-08 14:57:28,528: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_269.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:30,709: Resetting environment, episode 270, avg. reward: -72.09999999999991\n", - "2024-04-08 14:57:30,712: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_270.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:33,009: Resetting environment, episode 271, avg. reward: -10.749999999999986\n", - "2024-04-08 14:57:33,012: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_271.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:34,883: Resetting environment, episode 272, avg. reward: -9.799999999999994\n", - "2024-04-08 14:57:34,886: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_272.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:36,728: Resetting environment, episode 273, avg. reward: -59.85000000000001\n", - "2024-04-08 14:57:36,730: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_273.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:38,769: Resetting environment, episode 274, avg. reward: -33.500000000000014\n", - "2024-04-08 14:57:38,772: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_274.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:40,947: Resetting environment, episode 275, avg. reward: -50.44999999999995\n", - "2024-04-08 14:57:40,950: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_275.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:44,475: Resetting environment, episode 276, avg. reward: -5.800000000000008\n", - "2024-04-08 14:57:44,479: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_276.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:47,898: Resetting environment, episode 277, avg. reward: -13.899999999999979\n", - "2024-04-08 14:57:47,901: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_277.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:50,377: Resetting environment, episode 278, avg. reward: -101.4\n", - "2024-04-08 14:57:50,380: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_278.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:52,619: Resetting environment, episode 279, avg. reward: 0.9500000000000095\n", - "2024-04-08 14:57:52,621: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_279.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:54,559: Resetting environment, episode 280, avg. reward: -86.94999999999999\n", - "2024-04-08 14:57:54,562: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_280.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:56,801: Resetting environment, episode 281, avg. reward: -6.999999999999982\n", - "2024-04-08 14:57:56,803: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_281.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:57:58,672: Resetting environment, episode 282, avg. reward: 11.200000000000063\n", - "2024-04-08 14:57:58,675: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_282.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:00,781: Resetting environment, episode 283, avg. reward: -78.80000000000007\n", - "2024-04-08 14:58:00,785: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_283.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:02,893: Resetting environment, episode 284, avg. reward: -68.24999999999996\n", - "2024-04-08 14:58:02,896: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_284.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:04,854: Resetting environment, episode 285, avg. reward: -43.44999999999995\n", - "2024-04-08 14:58:04,858: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_285.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:07,133: Resetting environment, episode 286, avg. reward: -4.199999999999984\n", - "2024-04-08 14:58:07,136: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_286.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:09,427: Resetting environment, episode 287, avg. reward: 25.550000000000022\n", - "2024-04-08 14:58:09,430: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_287.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:11,576: Resetting environment, episode 288, avg. reward: -11.599999999999985\n", - "2024-04-08 14:58:11,580: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_288.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:13,448: Resetting environment, episode 289, avg. reward: -37.44999999999999\n", - "2024-04-08 14:58:13,451: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_289.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:15,328: Resetting environment, episode 290, avg. reward: -78.99999999999999\n", - "2024-04-08 14:58:15,331: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_290.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:18,155: Resetting environment, episode 291, avg. reward: -56.800000000000026\n", - "2024-04-08 14:58:18,159: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_291.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:20,609: Resetting environment, episode 292, avg. reward: -91.19999999999995\n", - "2024-04-08 14:58:20,614: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_292.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:22,444: Resetting environment, episode 293, avg. reward: 5.200000000000042\n", - "2024-04-08 14:58:22,447: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_293.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:24,809: Resetting environment, episode 294, avg. reward: -20.550000000000047\n", - "2024-04-08 14:58:24,814: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_294.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:26,613: Resetting environment, episode 295, avg. reward: -90.79999999999998\n", - "2024-04-08 14:58:26,616: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_295.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:28,191: Resetting environment, episode 296, avg. reward: -81.50000000000001\n", - "2024-04-08 14:58:28,191: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_296.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:30,080: Resetting environment, episode 297, avg. reward: 18.799999999999965\n", - "2024-04-08 14:58:30,083: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_297.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:32,060: Resetting environment, episode 298, avg. reward: -16.649999999999995\n", - "2024-04-08 14:58:32,062: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_298.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:34,037: Resetting environment, episode 299, avg. reward: 10.250000000000062\n", - "2024-04-08 14:58:34,040: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_299.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:36,089: Resetting environment, episode 300, avg. reward: -41.89999999999998\n", - "2024-04-08 14:58:36,092: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_300.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:38,616: Resetting environment, episode 301, avg. reward: 7.69999999999999\n", - "2024-04-08 14:58:38,616: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_301.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:40,914: Resetting environment, episode 302, avg. reward: 39.7999999999998\n", - "2024-04-08 14:58:40,918: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_302.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:42,618: Resetting environment, episode 303, avg. reward: 6.25000000000006\n", - "2024-04-08 14:58:42,622: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_303.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:44,477: Resetting environment, episode 304, avg. reward: -31.200000000000017\n", - "2024-04-08 14:58:44,477: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_304.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:46,336: Resetting environment, episode 305, avg. reward: -93.50000000000017\n", - "2024-04-08 14:58:46,340: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_305.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:48,689: Resetting environment, episode 306, avg. reward: -33.549999999999955\n", - "2024-04-08 14:58:48,693: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_306.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:51,197: Resetting environment, episode 307, avg. reward: -11.599999999999987\n", - "2024-04-08 14:58:51,200: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_307.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:53,602: Resetting environment, episode 308, avg. reward: -23.900000000000034\n", - "2024-04-08 14:58:53,605: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_308.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:56,033: Resetting environment, episode 309, avg. reward: 3.500000000000001\n", - "2024-04-08 14:58:56,037: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_309.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:58:58,038: Resetting environment, episode 310, avg. reward: 16.04999999999999\n", - "2024-04-08 14:58:58,046: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_310.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:00,171: Resetting environment, episode 311, avg. reward: -13.449999999999982\n", - "2024-04-08 14:59:00,174: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_311.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:02,046: Resetting environment, episode 312, avg. reward: -82.39999999999998\n", - "2024-04-08 14:59:02,057: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_312.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:03,942: Resetting environment, episode 313, avg. reward: 0.3000000000000045\n", - "2024-04-08 14:59:03,944: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_313.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:05,578: Resetting environment, episode 314, avg. reward: -90.35000000000015\n", - "2024-04-08 14:59:05,582: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_314.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:07,340: Resetting environment, episode 315, avg. reward: 3.3000000000000043\n", - "2024-04-08 14:59:07,343: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_315.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:09,117: Resetting environment, episode 316, avg. reward: -44.74999999999995\n", - "2024-04-08 14:59:09,128: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_316.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:11,162: Resetting environment, episode 317, avg. reward: 8.450000000000045\n", - "2024-04-08 14:59:11,165: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_317.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:13,123: Resetting environment, episode 318, avg. reward: -10.049999999999985\n", - "2024-04-08 14:59:13,127: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_318.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:18,061: Resetting environment, episode 319, avg. reward: -17.04999999999999\n", - "2024-04-08 14:59:18,067: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_319.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:19,985: Resetting environment, episode 320, avg. reward: -81.19999999999999\n", - "2024-04-08 14:59:19,989: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_320.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:22,591: Resetting environment, episode 321, avg. reward: 25.900000000000055\n", - "2024-04-08 14:59:22,593: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_321.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:25,075: Resetting environment, episode 322, avg. reward: -6.0500000000000025\n", - "2024-04-08 14:59:25,079: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_322.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:27,224: Resetting environment, episode 323, avg. reward: -0.349999999999965\n", - "2024-04-08 14:59:27,227: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_323.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:29,419: Resetting environment, episode 324, avg. reward: -42.45\n", - "2024-04-08 14:59:29,423: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_324.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:31,350: Resetting environment, episode 325, avg. reward: -36.199999999999974\n", - "2024-04-08 14:59:31,353: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_325.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:33,118: Resetting environment, episode 326, avg. reward: -27.699999999999996\n", - "2024-04-08 14:59:33,120: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_326.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:35,352: Resetting environment, episode 327, avg. reward: 32.74999999999989\n", - "2024-04-08 14:59:35,356: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_327.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:37,251: Resetting environment, episode 328, avg. reward: -16.34999999999998\n", - "2024-04-08 14:59:37,254: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_328.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:39,253: Resetting environment, episode 329, avg. reward: -8.000000000000007\n", - "2024-04-08 14:59:39,259: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_329.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:41,104: Resetting environment, episode 330, avg. reward: -78.60000000000001\n", - "2024-04-08 14:59:41,107: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_330.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:43,172: Resetting environment, episode 331, avg. reward: 12.800000000000024\n", - "2024-04-08 14:59:43,176: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_331.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:45,374: Resetting environment, episode 332, avg. reward: 13.349999999999932\n", - "2024-04-08 14:59:45,378: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_332.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:47,299: Resetting environment, episode 333, avg. reward: -69.95000000000005\n", - "2024-04-08 14:59:47,302: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_333.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:49,565: Resetting environment, episode 334, avg. reward: -88.9000000000001\n", - "2024-04-08 14:59:49,568: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_334.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:51,919: Resetting environment, episode 335, avg. reward: -53.49999999999996\n", - "2024-04-08 14:59:51,919: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_335.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:54,398: Resetting environment, episode 336, avg. reward: -76.90000000000008\n", - "2024-04-08 14:59:54,401: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_336.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:56,196: Resetting environment, episode 337, avg. reward: -43.799999999999955\n", - "2024-04-08 14:59:56,199: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_337.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:57,848: Resetting environment, episode 338, avg. reward: -12.200000000000006\n", - "2024-04-08 14:59:57,852: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_338.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 14:59:59,546: Resetting environment, episode 339, avg. reward: -12.549999999999985\n", - "2024-04-08 14:59:59,550: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_339.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:01,249: Resetting environment, episode 340, avg. reward: -72.65\n", - "2024-04-08 15:00:01,252: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_340.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:03,211: Resetting environment, episode 341, avg. reward: -84.65000000000006\n", - "2024-04-08 15:00:03,214: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_341.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:04,902: Resetting environment, episode 342, avg. reward: -88.64999999999998\n", - "2024-04-08 15:00:04,905: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_342.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:06,894: Resetting environment, episode 343, avg. reward: 37.34999999999988\n", - "2024-04-08 15:00:06,898: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_343.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:08,548: Resetting environment, episode 344, avg. reward: -95.5\n", - "2024-04-08 15:00:08,551: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_344.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:10,369: Resetting environment, episode 345, avg. reward: -98.44999999999996\n", - "2024-04-08 15:00:10,372: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_345.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:12,514: Resetting environment, episode 346, avg. reward: -4.499999999999958\n", - "2024-04-08 15:00:12,517: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_346.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:14,791: Resetting environment, episode 347, avg. reward: -35.90000000000002\n", - "2024-04-08 15:00:14,795: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_347.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:17,226: Resetting environment, episode 348, avg. reward: 12.30000000000003\n", - "2024-04-08 15:00:17,230: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_348.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:18,972: Resetting environment, episode 349, avg. reward: -11.299999999999983\n", - "2024-04-08 15:00:18,972: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_349.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:20,959: Resetting environment, episode 350, avg. reward: -70.59999999999997\n", - "2024-04-08 15:00:20,962: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_350.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:22,880: Resetting environment, episode 351, avg. reward: -20.44999999999996\n", - "2024-04-08 15:00:22,883: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_351.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:24,645: Resetting environment, episode 352, avg. reward: 27.44999999999996\n", - "2024-04-08 15:00:24,649: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_352.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:26,468: Resetting environment, episode 353, avg. reward: 9.349999999999948\n", - "2024-04-08 15:00:26,470: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_353.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:28,268: Resetting environment, episode 354, avg. reward: -71.55\n", - "2024-04-08 15:00:28,271: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_354.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:29,968: Resetting environment, episode 355, avg. reward: -7.849999999999993\n", - "2024-04-08 15:00:29,972: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_355.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:31,672: Resetting environment, episode 356, avg. reward: -58.14999999999992\n", - "2024-04-08 15:00:31,676: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_356.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:33,599: Resetting environment, episode 357, avg. reward: 21.54999999999989\n", - "2024-04-08 15:00:33,602: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_357.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:35,524: Resetting environment, episode 358, avg. reward: 10.350000000000037\n", - "2024-04-08 15:00:35,533: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_358.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:37,442: Resetting environment, episode 359, avg. reward: 12.749999999999961\n", - "2024-04-08 15:00:37,446: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_359.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:39,754: Resetting environment, episode 360, avg. reward: 26.849999999999863\n", - "2024-04-08 15:00:39,758: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_360.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:42,148: Resetting environment, episode 361, avg. reward: 1.9500000000000377\n", - "2024-04-08 15:00:42,152: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_361.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:44,863: Resetting environment, episode 362, avg. reward: -84.79999999999984\n", - "2024-04-08 15:00:44,867: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_362.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:47,398: Resetting environment, episode 363, avg. reward: -37.899999999999956\n", - "2024-04-08 15:00:47,402: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_363.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:50,122: Resetting environment, episode 364, avg. reward: -11.250000000000085\n", - "2024-04-08 15:00:50,126: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_364.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:52,560: Resetting environment, episode 365, avg. reward: -84.9\n", - "2024-04-08 15:00:52,562: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_365.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:54,688: Resetting environment, episode 366, avg. reward: -66.45000000000002\n", - "2024-04-08 15:00:54,692: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_366.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:00:59,582: Resetting environment, episode 367, avg. reward: 26.95\n", - "2024-04-08 15:00:59,585: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_367.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:01,883: Resetting environment, episode 368, avg. reward: -36.3\n", - "2024-04-08 15:01:01,886: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_368.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:04,194: Resetting environment, episode 369, avg. reward: -42.04999999999998\n", - "2024-04-08 15:01:04,197: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_369.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:06,476: Resetting environment, episode 370, avg. reward: -79.85000000000004\n", - "2024-04-08 15:01:06,480: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_370.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:08,804: Resetting environment, episode 371, avg. reward: 42.4499999999998\n", - "2024-04-08 15:01:08,809: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_371.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:11,021: Resetting environment, episode 372, avg. reward: -21.04999999999998\n", - "2024-04-08 15:01:11,025: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_372.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:13,427: Resetting environment, episode 373, avg. reward: 60.24999999999987\n", - "2024-04-08 15:01:13,430: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_373.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:15,228: Resetting environment, episode 374, avg. reward: -71.3\n", - "2024-04-08 15:01:15,231: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_374.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:17,086: Resetting environment, episode 375, avg. reward: 27.249999999999872\n", - "2024-04-08 15:01:17,089: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_375.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:18,949: Resetting environment, episode 376, avg. reward: 24.149999999999984\n", - "2024-04-08 15:01:18,952: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_376.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:20,875: Resetting environment, episode 377, avg. reward: -53.54999999999999\n", - "2024-04-08 15:01:20,879: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_377.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:22,686: Resetting environment, episode 378, avg. reward: 31.84999999999999\n", - "2024-04-08 15:01:22,690: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_378.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:24,470: Resetting environment, episode 379, avg. reward: -65.4\n", - "2024-04-08 15:01:24,473: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_379.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:26,345: Resetting environment, episode 380, avg. reward: 52.84999999999978\n", - "2024-04-08 15:01:26,348: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_380.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:28,494: Resetting environment, episode 381, avg. reward: -50.450000000000024\n", - "2024-04-08 15:01:28,497: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_381.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:30,231: Resetting environment, episode 382, avg. reward: -71.99999999999991\n", - "2024-04-08 15:01:30,235: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_382.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:32,232: Resetting environment, episode 383, avg. reward: 20.400000000000073\n", - "2024-04-08 15:01:32,236: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_383.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:33,887: Resetting environment, episode 384, avg. reward: 14.799999999999994\n", - "2024-04-08 15:01:33,890: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_384.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:35,491: Resetting environment, episode 385, avg. reward: -46.900000000000055\n", - "2024-04-08 15:01:35,494: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_385.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:37,246: Resetting environment, episode 386, avg. reward: 0.8999999999999937\n", - "2024-04-08 15:01:37,249: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_386.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:38,777: Resetting environment, episode 387, avg. reward: -13.35\n", - "2024-04-08 15:01:38,780: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_387.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:40,765: Resetting environment, episode 388, avg. reward: -66.39999999999996\n", - "2024-04-08 15:01:40,765: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_388.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:43,096: Resetting environment, episode 389, avg. reward: -60.40000000000004\n", - "2024-04-08 15:01:43,098: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_389.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:45,309: Resetting environment, episode 390, avg. reward: -40.299999999999976\n", - "2024-04-08 15:01:45,312: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_390.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:47,533: Resetting environment, episode 391, avg. reward: -9.300000000000024\n", - "2024-04-08 15:01:47,536: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_391.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:49,645: Resetting environment, episode 392, avg. reward: -68.20000000000002\n", - "2024-04-08 15:01:49,650: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_392.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:51,698: Resetting environment, episode 393, avg. reward: -12.050000000000015\n", - "2024-04-08 15:01:51,698: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_393.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:53,431: Resetting environment, episode 394, avg. reward: -45.90000000000007\n", - "2024-04-08 15:01:53,434: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_394.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:55,444: Resetting environment, episode 395, avg. reward: -7.850000000000001\n", - "2024-04-08 15:01:55,444: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_395.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:01:57,778: Resetting environment, episode 396, avg. reward: -81.24999999999994\n", - "2024-04-08 15:01:57,783: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_396.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:00,035: Resetting environment, episode 397, avg. reward: 35.40000000000004\n", - "2024-04-08 15:02:00,039: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_397.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:02,146: Resetting environment, episode 398, avg. reward: -9.550000000000082\n", - "2024-04-08 15:02:02,148: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_398.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:04,122: Resetting environment, episode 399, avg. reward: 10.550000000000026\n", - "2024-04-08 15:02:04,126: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_399.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:06,128: Resetting environment, episode 400, avg. reward: -2.7499999999999734\n", - "2024-04-08 15:02:06,132: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_400.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:08,277: Resetting environment, episode 401, avg. reward: 11.199999999999974\n", - "2024-04-08 15:02:08,281: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_401.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:10,123: Resetting environment, episode 402, avg. reward: 38.94999999999992\n", - "2024-04-08 15:02:10,126: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_402.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:12,770: Resetting environment, episode 403, avg. reward: 40.150000000000006\n", - "2024-04-08 15:02:12,774: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_403.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:14,630: Resetting environment, episode 404, avg. reward: -28.65000000000003\n", - "2024-04-08 15:02:14,633: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_404.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:16,440: Resetting environment, episode 405, avg. reward: 32.25000000000001\n", - "2024-04-08 15:02:16,443: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_405.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:18,127: Resetting environment, episode 406, avg. reward: -11.699999999999982\n", - "2024-04-08 15:02:18,130: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_406.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:20,294: Resetting environment, episode 407, avg. reward: 51.299999999999976\n", - "2024-04-08 15:02:20,297: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_407.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:22,154: Resetting environment, episode 408, avg. reward: 10.399999999999963\n", - "2024-04-08 15:02:22,157: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_408.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:24,369: Resetting environment, episode 409, avg. reward: -12.599999999999984\n", - "2024-04-08 15:02:24,373: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_409.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:26,758: Resetting environment, episode 410, avg. reward: 13.600000000000026\n", - "2024-04-08 15:02:26,761: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_410.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:30,043: Resetting environment, episode 411, avg. reward: 31.89999999999995\n", - "2024-04-08 15:02:30,047: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_411.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:32,018: Resetting environment, episode 412, avg. reward: 22.050000000000054\n", - "2024-04-08 15:02:32,021: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_412.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:33,671: Resetting environment, episode 413, avg. reward: 38.74999999999982\n", - "2024-04-08 15:02:33,674: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_413.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:35,754: Resetting environment, episode 414, avg. reward: 21.250000000000092\n", - "2024-04-08 15:02:35,757: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_414.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:37,697: Resetting environment, episode 415, avg. reward: 52.64999999999991\n", - "2024-04-08 15:02:37,704: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_415.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:39,371: Resetting environment, episode 416, avg. reward: 15.300000000000079\n", - "2024-04-08 15:02:39,374: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_416.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:40,894: Resetting environment, episode 417, avg. reward: -0.24999999999995826\n", - "2024-04-08 15:02:40,896: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_417.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:42,813: Resetting environment, episode 418, avg. reward: -22.05000000000004\n", - "2024-04-08 15:02:42,817: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_418.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:44,725: Resetting environment, episode 419, avg. reward: -54.89999999999997\n", - "2024-04-08 15:02:44,727: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_419.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:48,515: Resetting environment, episode 420, avg. reward: -15.04999999999997\n", - "2024-04-08 15:02:48,518: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_420.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:50,655: Resetting environment, episode 421, avg. reward: -56.94999999999997\n", - "2024-04-08 15:02:50,659: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_421.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:52,515: Resetting environment, episode 422, avg. reward: -68.70000000000003\n", - "2024-04-08 15:02:52,517: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_422.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:54,132: Resetting environment, episode 423, avg. reward: -72.89999999999996\n", - "2024-04-08 15:02:54,134: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_423.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:55,908: Resetting environment, episode 424, avg. reward: 17.449999999999946\n", - "2024-04-08 15:02:55,911: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_424.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:57,497: Resetting environment, episode 425, avg. reward: -27.14999999999995\n", - "2024-04-08 15:02:57,501: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_425.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:02:59,501: Resetting environment, episode 426, avg. reward: -67.6\n", - "2024-04-08 15:02:59,504: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_426.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:01,163: Resetting environment, episode 427, avg. reward: 27.7999999999999\n", - "2024-04-08 15:03:01,166: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_427.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:02,845: Resetting environment, episode 428, avg. reward: 43.599999999999895\n", - "2024-04-08 15:03:02,849: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_428.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:04,688: Resetting environment, episode 429, avg. reward: 10.649999999999995\n", - "2024-04-08 15:03:04,691: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_429.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:06,537: Resetting environment, episode 430, avg. reward: 6.549999999999988\n", - "2024-04-08 15:03:06,540: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_430.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:08,508: Resetting environment, episode 431, avg. reward: -53.84999999999999\n", - "2024-04-08 15:03:08,510: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_431.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:10,547: Resetting environment, episode 432, avg. reward: -16.399999999999995\n", - "2024-04-08 15:03:10,550: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_432.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:12,415: Resetting environment, episode 433, avg. reward: 26.500000000000014\n", - "2024-04-08 15:03:12,418: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_433.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:13,905: Resetting environment, episode 434, avg. reward: -9.04999999999999\n", - "2024-04-08 15:03:13,909: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_434.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:15,659: Resetting environment, episode 435, avg. reward: -70.59999999999998\n", - "2024-04-08 15:03:15,662: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_435.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:17,377: Resetting environment, episode 436, avg. reward: 8.600000000000009\n", - "2024-04-08 15:03:17,381: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_436.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:19,455: Resetting environment, episode 437, avg. reward: 84.10000000000014\n", - "2024-04-08 15:03:19,458: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_437.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:21,741: Resetting environment, episode 438, avg. reward: -52.299999999999976\n", - "2024-04-08 15:03:21,744: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_438.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:23,696: Resetting environment, episode 439, avg. reward: 20.199999999999957\n", - "2024-04-08 15:03:23,700: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_439.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:25,663: Resetting environment, episode 440, avg. reward: -79.10000000000002\n", - "2024-04-08 15:03:25,667: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_440.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:27,924: Resetting environment, episode 441, avg. reward: 58.799999999999876\n", - "2024-04-08 15:03:27,928: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_441.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:29,603: Resetting environment, episode 442, avg. reward: -35.64999999999998\n", - "2024-04-08 15:03:29,606: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_442.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:31,271: Resetting environment, episode 443, avg. reward: -0.7500000000000195\n", - "2024-04-08 15:03:31,274: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_443.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:33,199: Resetting environment, episode 444, avg. reward: -83.49999999999989\n", - "2024-04-08 15:03:33,203: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_444.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:35,706: Resetting environment, episode 445, avg. reward: 58.54999999999981\n", - "2024-04-08 15:03:35,710: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_445.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:37,671: Resetting environment, episode 446, avg. reward: -39.45000000000003\n", - "2024-04-08 15:03:37,673: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_446.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:40,320: Resetting environment, episode 447, avg. reward: -63.049999999999955\n", - "2024-04-08 15:03:40,324: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_447.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:42,333: Resetting environment, episode 448, avg. reward: -48.29999999999998\n", - "2024-04-08 15:03:42,336: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_448.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:44,621: Resetting environment, episode 449, avg. reward: 87.55000000000031\n", - "2024-04-08 15:03:44,625: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_449.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:46,958: Resetting environment, episode 450, avg. reward: 59.89999999999991\n", - "2024-04-08 15:03:46,962: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_450.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:49,779: Resetting environment, episode 451, avg. reward: -35.349999999999994\n", - "2024-04-08 15:03:49,783: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_451.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:51,834: Resetting environment, episode 452, avg. reward: -61.19999999999991\n", - "2024-04-08 15:03:51,837: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_452.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:53,774: Resetting environment, episode 453, avg. reward: 1.6000000000000005\n", - "2024-04-08 15:03:53,777: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_453.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:56,025: Resetting environment, episode 454, avg. reward: 13.14999999999995\n", - "2024-04-08 15:03:56,028: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_454.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:03:58,535: Resetting environment, episode 455, avg. reward: 19.950000000000003\n", - "2024-04-08 15:03:58,538: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_455.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:00,845: Resetting environment, episode 456, avg. reward: -33.04999999999999\n", - "2024-04-08 15:04:00,848: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_456.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:02,904: Resetting environment, episode 457, avg. reward: 39.59999999999999\n", - "2024-04-08 15:04:02,909: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_457.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:05,202: Resetting environment, episode 458, avg. reward: -8.300000000000002\n", - "2024-04-08 15:04:05,206: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_458.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:07,216: Resetting environment, episode 459, avg. reward: -85.5\n", - "2024-04-08 15:04:07,219: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_459.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:09,300: Resetting environment, episode 460, avg. reward: 42.149999999999935\n", - "2024-04-08 15:04:09,304: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_460.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:11,700: Resetting environment, episode 461, avg. reward: -7.00000000000005\n", - "2024-04-08 15:04:11,703: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_461.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:13,865: Resetting environment, episode 462, avg. reward: 44.99999999999982\n", - "2024-04-08 15:04:13,868: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_462.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:15,915: Resetting environment, episode 463, avg. reward: -14.150000000000015\n", - "2024-04-08 15:04:15,919: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_463.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:18,129: Resetting environment, episode 464, avg. reward: -62.3\n", - "2024-04-08 15:04:18,133: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_464.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:20,618: Resetting environment, episode 465, avg. reward: -21.85\n", - "2024-04-08 15:04:20,623: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_465.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:22,808: Resetting environment, episode 466, avg. reward: -21.59999999999995\n", - "2024-04-08 15:04:22,811: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_466.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:24,768: Resetting environment, episode 467, avg. reward: -14.950000000000008\n", - "2024-04-08 15:04:24,772: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_467.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:26,660: Resetting environment, episode 468, avg. reward: 18.64999999999998\n", - "2024-04-08 15:04:26,663: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_468.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:28,354: Resetting environment, episode 469, avg. reward: -10.699999999999989\n", - "2024-04-08 15:04:28,357: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_469.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:30,242: Resetting environment, episode 470, avg. reward: -53.79999999999998\n", - "2024-04-08 15:04:30,245: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_470.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:33,035: Resetting environment, episode 471, avg. reward: 84.70000000000006\n", - "2024-04-08 15:04:33,038: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_471.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:35,091: Resetting environment, episode 472, avg. reward: -7.000000000000062\n", - "2024-04-08 15:04:35,093: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_472.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "ename": "KeyboardInterrupt", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[8], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlearn\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtotal_timesteps\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mTOTAL_TIMESTEPS\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[1;32mc:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\ppo\\ppo.py:308\u001b[0m, in \u001b[0;36mPPO.learn\u001b[1;34m(self, total_timesteps, callback, log_interval, tb_log_name, reset_num_timesteps, progress_bar)\u001b[0m\n\u001b[0;32m 299\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mlearn\u001b[39m(\n\u001b[0;32m 300\u001b[0m \u001b[38;5;28mself\u001b[39m: SelfPPO,\n\u001b[0;32m 301\u001b[0m total_timesteps: \u001b[38;5;28mint\u001b[39m,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 306\u001b[0m progress_bar: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[0;32m 307\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m SelfPPO:\n\u001b[1;32m--> 308\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlearn\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 309\u001b[0m \u001b[43m \u001b[49m\u001b[43mtotal_timesteps\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtotal_timesteps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 310\u001b[0m \u001b[43m \u001b[49m\u001b[43mcallback\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallback\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 311\u001b[0m \u001b[43m \u001b[49m\u001b[43mlog_interval\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlog_interval\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 312\u001b[0m \u001b[43m \u001b[49m\u001b[43mtb_log_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtb_log_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 313\u001b[0m \u001b[43m \u001b[49m\u001b[43mreset_num_timesteps\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mreset_num_timesteps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 314\u001b[0m \u001b[43m \u001b[49m\u001b[43mprogress_bar\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mprogress_bar\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 315\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[1;32mc:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\common\\on_policy_algorithm.py:259\u001b[0m, in \u001b[0;36mOnPolicyAlgorithm.learn\u001b[1;34m(self, total_timesteps, callback, log_interval, tb_log_name, reset_num_timesteps, progress_bar)\u001b[0m\n\u001b[0;32m 256\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39menv \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 258\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnum_timesteps \u001b[38;5;241m<\u001b[39m total_timesteps:\n\u001b[1;32m--> 259\u001b[0m continue_training \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcollect_rollouts\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menv\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallback\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrollout_buffer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mn_rollout_steps\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mn_steps\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 261\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m continue_training \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m:\n\u001b[0;32m 262\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n", - "File \u001b[1;32mc:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\common\\on_policy_algorithm.py:178\u001b[0m, in \u001b[0;36mOnPolicyAlgorithm.collect_rollouts\u001b[1;34m(self, env, callback, rollout_buffer, n_rollout_steps)\u001b[0m\n\u001b[0;32m 175\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maction_space, spaces\u001b[38;5;241m.\u001b[39mBox):\n\u001b[0;32m 176\u001b[0m clipped_actions \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mclip(actions, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maction_space\u001b[38;5;241m.\u001b[39mlow, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maction_space\u001b[38;5;241m.\u001b[39mhigh)\n\u001b[1;32m--> 178\u001b[0m new_obs, rewards, dones, infos \u001b[38;5;241m=\u001b[39m \u001b[43menv\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstep\u001b[49m\u001b[43m(\u001b[49m\u001b[43mclipped_actions\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 180\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnum_timesteps \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m env\u001b[38;5;241m.\u001b[39mnum_envs\n\u001b[0;32m 182\u001b[0m \u001b[38;5;66;03m# Give access to local variables\u001b[39;00m\n", - "File \u001b[1;32mc:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\common\\vec_env\\base_vec_env.py:197\u001b[0m, in \u001b[0;36mVecEnv.step\u001b[1;34m(self, actions)\u001b[0m\n\u001b[0;32m 190\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 191\u001b[0m \u001b[38;5;124;03mStep the environments with the given action\u001b[39;00m\n\u001b[0;32m 192\u001b[0m \n\u001b[0;32m 193\u001b[0m \u001b[38;5;124;03m:param actions: the action\u001b[39;00m\n\u001b[0;32m 194\u001b[0m \u001b[38;5;124;03m:return: observation, reward, done, information\u001b[39;00m\n\u001b[0;32m 195\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 196\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstep_async(actions)\n\u001b[1;32m--> 197\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstep_wait\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[1;32mc:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\common\\vec_env\\dummy_vec_env.py:58\u001b[0m, in \u001b[0;36mDummyVecEnv.step_wait\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 55\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mstep_wait\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m VecEnvStepReturn:\n\u001b[0;32m 56\u001b[0m \u001b[38;5;66;03m# Avoid circular imports\u001b[39;00m\n\u001b[0;32m 57\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m env_idx \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnum_envs):\n\u001b[1;32m---> 58\u001b[0m obs, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuf_rews[env_idx], terminated, truncated, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuf_infos[env_idx] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menvs\u001b[49m\u001b[43m[\u001b[49m\u001b[43menv_idx\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstep\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 59\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mactions\u001b[49m\u001b[43m[\u001b[49m\u001b[43menv_idx\u001b[49m\u001b[43m]\u001b[49m\n\u001b[0;32m 60\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 61\u001b[0m \u001b[38;5;66;03m# convert to SB3 VecEnv api\u001b[39;00m\n\u001b[0;32m 62\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuf_dones[env_idx] \u001b[38;5;241m=\u001b[39m terminated \u001b[38;5;129;01mor\u001b[39;00m truncated\n", - "File \u001b[1;32mc:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\common\\monitor.py:94\u001b[0m, in \u001b[0;36mMonitor.step\u001b[1;34m(self, action)\u001b[0m\n\u001b[0;32m 92\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mneeds_reset:\n\u001b[0;32m 93\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTried to step environment that needs reset\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 94\u001b[0m observation, reward, terminated, truncated, info \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menv\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstep\u001b[49m\u001b[43m(\u001b[49m\u001b[43maction\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 95\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrewards\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;28mfloat\u001b[39m(reward))\n\u001b[0;32m 96\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m terminated \u001b[38;5;129;01mor\u001b[39;00m truncated:\n", - "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\session\\environment.py:54\u001b[0m, in \u001b[0;36mPrimaiteGymEnv.step\u001b[1;34m(self, action)\u001b[0m\n\u001b[0;32m 52\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mgame\u001b[38;5;241m.\u001b[39mapply_agent_actions()\n\u001b[0;32m 53\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mgame\u001b[38;5;241m.\u001b[39madvance_timestep()\n\u001b[1;32m---> 54\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgame\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_sim_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 55\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mgame\u001b[38;5;241m.\u001b[39mupdate_agents(state)\n\u001b[0;32m 57\u001b[0m next_obs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_obs() \u001b[38;5;66;03m# this doesn't update observation, just gets the current observation\u001b[39;00m\n", - "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\game\\game.py:149\u001b[0m, in \u001b[0;36mPrimaiteGame.get_sim_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 147\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_sim_state\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict:\n\u001b[0;32m 148\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Get the current state of the simulation.\"\"\"\u001b[39;00m\n\u001b[1;32m--> 149\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msimulation\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\sim_container.py:56\u001b[0m, in \u001b[0;36mSimulation.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 45\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 46\u001b[0m \u001b[38;5;124;03mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[0;32m 47\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 51\u001b[0m \u001b[38;5;124;03m:rtype: Dict\u001b[39;00m\n\u001b[0;32m 52\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 53\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 54\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 55\u001b[0m {\n\u001b[1;32m---> 56\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnetwork\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mnetwork\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m,\n\u001b[0;32m 57\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdomain\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdomain\u001b[38;5;241m.\u001b[39mdescribe_state(),\n\u001b[0;32m 58\u001b[0m }\n\u001b[0;32m 59\u001b[0m )\n\u001b[0;32m 60\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", - "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\network\\container.py:223\u001b[0m, in \u001b[0;36mNetwork.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 215\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 216\u001b[0m \u001b[38;5;124;03mProduce a dictionary describing the current state of the Network.\u001b[39;00m\n\u001b[0;32m 217\u001b[0m \n\u001b[0;32m 218\u001b[0m \u001b[38;5;124;03m:return: A dictionary capturing the current state of the Network and its child objects.\u001b[39;00m\n\u001b[0;32m 219\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 220\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 221\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 222\u001b[0m {\n\u001b[1;32m--> 223\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnodes\u001b[39m\u001b[38;5;124m\"\u001b[39m: {node\u001b[38;5;241m.\u001b[39mhostname: node\u001b[38;5;241m.\u001b[39mdescribe_state() \u001b[38;5;28;01mfor\u001b[39;00m node \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnodes\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 224\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlinks\u001b[39m\u001b[38;5;124m\"\u001b[39m: {},\n\u001b[0;32m 225\u001b[0m }\n\u001b[0;32m 226\u001b[0m )\n\u001b[0;32m 227\u001b[0m \u001b[38;5;66;03m# Update the links one-by-one. The key is a 4-tuple of `hostname_a, port_a, hostname_b, port_b`\u001b[39;00m\n\u001b[0;32m 228\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m _, link \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlinks\u001b[38;5;241m.\u001b[39mitems():\n", - "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\network\\container.py:223\u001b[0m, in \u001b[0;36m\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m 215\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 216\u001b[0m \u001b[38;5;124;03mProduce a dictionary describing the current state of the Network.\u001b[39;00m\n\u001b[0;32m 217\u001b[0m \n\u001b[0;32m 218\u001b[0m \u001b[38;5;124;03m:return: A dictionary capturing the current state of the Network and its child objects.\u001b[39;00m\n\u001b[0;32m 219\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 220\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 221\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 222\u001b[0m {\n\u001b[1;32m--> 223\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnodes\u001b[39m\u001b[38;5;124m\"\u001b[39m: {node\u001b[38;5;241m.\u001b[39mhostname: \u001b[43mnode\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m node \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnodes\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 224\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlinks\u001b[39m\u001b[38;5;124m\"\u001b[39m: {},\n\u001b[0;32m 225\u001b[0m }\n\u001b[0;32m 226\u001b[0m )\n\u001b[0;32m 227\u001b[0m \u001b[38;5;66;03m# Update the links one-by-one. The key is a 4-tuple of `hostname_a, port_a, hostname_b, port_b`\u001b[39;00m\n\u001b[0;32m 228\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m _, link \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlinks\u001b[38;5;241m.\u001b[39mitems():\n", - "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\network\\hardware\\base.py:920\u001b[0m, in \u001b[0;36mNode.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 902\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 903\u001b[0m \u001b[38;5;124;03mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[0;32m 904\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 908\u001b[0m \u001b[38;5;124;03m:rtype: Dict\u001b[39;00m\n\u001b[0;32m 909\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 910\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 911\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 912\u001b[0m {\n\u001b[0;32m 913\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhostname\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhostname,\n\u001b[0;32m 914\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124moperating_state\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moperating_state\u001b[38;5;241m.\u001b[39mvalue,\n\u001b[0;32m 915\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNICs\u001b[39m\u001b[38;5;124m\"\u001b[39m: {\n\u001b[0;32m 916\u001b[0m eth_num: network_interface\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 917\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m eth_num, network_interface \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnetwork_interface\u001b[38;5;241m.\u001b[39mitems()\n\u001b[0;32m 918\u001b[0m },\n\u001b[0;32m 919\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfile_system\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfile_system\u001b[38;5;241m.\u001b[39mdescribe_state(),\n\u001b[1;32m--> 920\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapplications\u001b[39m\u001b[38;5;124m\"\u001b[39m: {app\u001b[38;5;241m.\u001b[39mname: app\u001b[38;5;241m.\u001b[39mdescribe_state() \u001b[38;5;28;01mfor\u001b[39;00m app \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mapplications\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 921\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mservices\u001b[39m\u001b[38;5;124m\"\u001b[39m: {svc\u001b[38;5;241m.\u001b[39mname: svc\u001b[38;5;241m.\u001b[39mdescribe_state() \u001b[38;5;28;01mfor\u001b[39;00m svc \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mservices\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 922\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mprocess\u001b[39m\u001b[38;5;124m\"\u001b[39m: {proc\u001b[38;5;241m.\u001b[39mname: proc\u001b[38;5;241m.\u001b[39mdescribe_state() \u001b[38;5;28;01mfor\u001b[39;00m proc \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocesses\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 923\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrevealed_to_red\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrevealed_to_red,\n\u001b[0;32m 924\u001b[0m }\n\u001b[0;32m 925\u001b[0m )\n\u001b[0;32m 926\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", - "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\network\\hardware\\base.py:920\u001b[0m, in \u001b[0;36m\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m 902\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 903\u001b[0m \u001b[38;5;124;03mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[0;32m 904\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 908\u001b[0m \u001b[38;5;124;03m:rtype: Dict\u001b[39;00m\n\u001b[0;32m 909\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 910\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 911\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 912\u001b[0m {\n\u001b[0;32m 913\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhostname\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhostname,\n\u001b[0;32m 914\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124moperating_state\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moperating_state\u001b[38;5;241m.\u001b[39mvalue,\n\u001b[0;32m 915\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNICs\u001b[39m\u001b[38;5;124m\"\u001b[39m: {\n\u001b[0;32m 916\u001b[0m eth_num: network_interface\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 917\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m eth_num, network_interface \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnetwork_interface\u001b[38;5;241m.\u001b[39mitems()\n\u001b[0;32m 918\u001b[0m },\n\u001b[0;32m 919\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfile_system\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfile_system\u001b[38;5;241m.\u001b[39mdescribe_state(),\n\u001b[1;32m--> 920\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapplications\u001b[39m\u001b[38;5;124m\"\u001b[39m: {app\u001b[38;5;241m.\u001b[39mname: \u001b[43mapp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m app \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mapplications\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 921\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mservices\u001b[39m\u001b[38;5;124m\"\u001b[39m: {svc\u001b[38;5;241m.\u001b[39mname: svc\u001b[38;5;241m.\u001b[39mdescribe_state() \u001b[38;5;28;01mfor\u001b[39;00m svc \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mservices\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 922\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mprocess\u001b[39m\u001b[38;5;124m\"\u001b[39m: {proc\u001b[38;5;241m.\u001b[39mname: proc\u001b[38;5;241m.\u001b[39mdescribe_state() \u001b[38;5;28;01mfor\u001b[39;00m proc \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocesses\u001b[38;5;241m.\u001b[39mvalues()},\n\u001b[0;32m 923\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrevealed_to_red\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrevealed_to_red,\n\u001b[0;32m 924\u001b[0m }\n\u001b[0;32m 925\u001b[0m )\n\u001b[0;32m 926\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", - "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\system\\applications\\web_browser.py:75\u001b[0m, in \u001b[0;36mWebBrowser.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 69\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdescribe_state\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict:\n\u001b[0;32m 70\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 71\u001b[0m \u001b[38;5;124;03m Produce a dictionary describing the current state of the WebBrowser.\u001b[39;00m\n\u001b[0;32m 72\u001b[0m \n\u001b[0;32m 73\u001b[0m \u001b[38;5;124;03m :return: A dictionary capturing the current state of the WebBrowser and its child objects.\u001b[39;00m\n\u001b[0;32m 74\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 75\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 76\u001b[0m state[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhistory\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m [hist_item\u001b[38;5;241m.\u001b[39mstate() \u001b[38;5;28;01mfor\u001b[39;00m hist_item \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhistory]\n\u001b[0;32m 77\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", - "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\system\\applications\\application.py:64\u001b[0m, in \u001b[0;36mApplication.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 54\u001b[0m \u001b[38;5;129m@abstractmethod\u001b[39m\n\u001b[0;32m 55\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdescribe_state\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict:\n\u001b[0;32m 56\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 57\u001b[0m \u001b[38;5;124;03m Produce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[0;32m 58\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 62\u001b[0m \u001b[38;5;124;03m :rtype: Dict\u001b[39;00m\n\u001b[0;32m 63\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 64\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 65\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 66\u001b[0m {\n\u001b[0;32m 67\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124moperating_state\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moperating_state\u001b[38;5;241m.\u001b[39mvalue,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 71\u001b[0m }\n\u001b[0;32m 72\u001b[0m )\n\u001b[0;32m 73\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", - "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\system\\software.py:263\u001b[0m, in \u001b[0;36mIOSoftware.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 253\u001b[0m \u001b[38;5;129m@abstractmethod\u001b[39m\n\u001b[0;32m 254\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdescribe_state\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict:\n\u001b[0;32m 255\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 256\u001b[0m \u001b[38;5;124;03m Produce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[0;32m 257\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 261\u001b[0m \u001b[38;5;124;03m :rtype: Dict\u001b[39;00m\n\u001b[0;32m 262\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m--> 263\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdescribe_state\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 264\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 265\u001b[0m {\n\u001b[0;32m 266\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124minstalling_count\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minstalling_count,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 271\u001b[0m }\n\u001b[0;32m 272\u001b[0m )\n\u001b[0;32m 273\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", - "File \u001b[1;32mC:\\Projects\\PrimAITE\\src\\primaite\\simulator\\system\\software.py:149\u001b[0m, in \u001b[0;36mSoftware.describe_state\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 138\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 139\u001b[0m \u001b[38;5;124;03mProduce a dictionary describing the current state of this object.\u001b[39;00m\n\u001b[0;32m 140\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 144\u001b[0m \u001b[38;5;124;03m:rtype: Dict\u001b[39;00m\n\u001b[0;32m 145\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 146\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mdescribe_state()\n\u001b[0;32m 147\u001b[0m state\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 148\u001b[0m {\n\u001b[1;32m--> 149\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhealth_state_actual\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhealth_state_actual\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvalue\u001b[49m,\n\u001b[0;32m 150\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhealth_state_visible\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhealth_state_visible\u001b[38;5;241m.\u001b[39mvalue,\n\u001b[0;32m 151\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcriticality\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcriticality\u001b[38;5;241m.\u001b[39mvalue,\n\u001b[0;32m 152\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfixing_count\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfixing_count,\n\u001b[0;32m 153\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mscanning_count\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mscanning_count,\n\u001b[0;32m 154\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrevealed_to_red\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrevealed_to_red,\n\u001b[0;32m 155\u001b[0m }\n\u001b[0;32m 156\u001b[0m )\n\u001b[0;32m 157\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m state\n", - "File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python310\\lib\\types.py:177\u001b[0m, in \u001b[0;36mDynamicClassAttribute.__get__\u001b[1;34m(self, instance, ownerclass)\u001b[0m\n\u001b[0;32m 176\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__get__\u001b[39m(\u001b[38;5;28mself\u001b[39m, instance, ownerclass\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[1;32m--> 177\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43minstance\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m:\n\u001b[0;32m 178\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m__isabstractmethod__:\n\u001b[0;32m 179\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\n", - "\u001b[1;31mKeyboardInterrupt\u001b[0m: " - ] - } - ], + "outputs": [], "source": [ "model.learn(total_timesteps=TOTAL_TIMESTEPS)\n" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -7216,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -7226,187 +93,9 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "c:\\Projects\\PrimAITE\\.venv\\lib\\site-packages\\stable_baselines3\\common\\evaluation.py:67: UserWarning: Evaluation environment is not wrapped with a ``Monitor`` wrapper. This may result in reporting modified episode lengths and rewards, if other wrappers happen to modify these. Consider wrapping environment first with ``Monitor`` wrapper.\n", - " warnings.warn(\n", - "2024-04-08 15:04:51,136: Resetting environment, episode 473, avg. reward: 0.0\n", - "2024-04-08 15:04:51,140: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_473.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:53,329: Resetting environment, episode 474, avg. reward: -62.59999999999992\n", - "2024-04-08 15:04:53,332: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_474.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:55,400: Resetting environment, episode 475, avg. reward: -58.649999999999935\n", - "2024-04-08 15:04:55,403: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_475.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:04:57,612: Resetting environment, episode 476, avg. reward: -54.549999999999955\n", - "2024-04-08 15:04:57,617: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_476.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:05:02,916: Resetting environment, episode 477, avg. reward: -64.99999999999991\n", - "2024-04-08 15:05:02,918: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_477.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:05:05,225: Resetting environment, episode 478, avg. reward: -53.19999999999996\n", - "2024-04-08 15:05:05,228: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_478.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:05:07,766: Resetting environment, episode 479, avg. reward: -55.79999999999997\n", - "2024-04-08 15:05:07,769: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_479.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:05:10,062: Resetting environment, episode 480, avg. reward: -32.75000000000003\n", - "2024-04-08 15:05:10,065: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_480.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:05:12,370: Resetting environment, episode 481, avg. reward: -23.549999999999986\n", - "2024-04-08 15:05:12,373: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_481.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:05:14,716: Resetting environment, episode 482, avg. reward: -15.04999999999997\n", - "2024-04-08 15:05:14,719: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_482.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-04-08 15:05:16,779: Resetting environment, episode 483, avg. reward: -50.549999999999976\n", - "2024-04-08 15:05:16,782: Saving agent action log to C:\\Users\\CharlieCrane\\primaite\\3.0.0b7\\sessions\\2024-04-08\\14-49-25\\agent_actions\\episode_483.json\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'type': 'CUSTOM', 'options': {'components': [{'type': 'NODES', 'label': 'NODES', 'options': {'hosts': [{'hostname': 'domain_controller'}, {'hostname': 'web_server', 'services': [{'service_name': 'WebServer'}]}, {'hostname': 'database_server', 'folders': [{'folder_name': 'database', 'files': [{'file_name': 'database.db'}]}]}, {'hostname': 'backup_server'}, {'hostname': 'security_suite'}, {'hostname': 'client_1'}, {'hostname': 'client_2'}], 'num_services': 1, 'num_applications': 0, 'num_folders': 1, 'num_files': 1, 'num_nics': 2, 'include_num_access': False, 'include_nmne': True, 'routers': [{'hostname': 'router_1'}], 'num_ports': 0, 'ip_list': ['192.168.1.10', '192.168.1.12', '192.168.1.14', '192.168.1.16', '192.168.1.110', '192.168.10.21', '192.168.10.22', '192.168.10.110'], 'wildcard_list': ['0.0.0.1'], 'port_list': [80, 5432], 'protocol_list': ['ICMP', 'TCP', 'UDP'], 'num_rules': 10}}, {'type': 'LINKS', 'label': 'LINKS', 'options': {'link_references': ['router_1:eth-1<->switch_1:eth-8', 'router_1:eth-2<->switch_2:eth-8', 'switch_1:eth-1<->domain_controller:eth-1', 'switch_1:eth-2<->web_server:eth-1', 'switch_1:eth-3<->database_server:eth-1', 'switch_1:eth-4<->backup_server:eth-1', 'switch_1:eth-7<->security_suite:eth-1', 'switch_2:eth-1<->client_1:eth-1', 'switch_2:eth-2<->client_2:eth-1', 'switch_2:eth-7<->security_suite:eth-2']}}, {'type': 'NONE', 'label': 'ICS', 'options': {}}]}}\n" - ] - }, - { - "data": { - "text/plain": [ - "(-47.170001389086245, 16.315777792523683)" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "from stable_baselines3.common.evaluation import evaluate_policy\n", "\n", From 0828f70b4c277fd02c3bf1e55502bbc9bf4012d2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 15 Apr 2024 11:50:08 +0100 Subject: [PATCH 806/980] #2459 back-sync b8 changes into core --- .pre-commit-config.yaml | 6 +- docs/source/configuration/agents.rst | 2 +- .../simulation/nodes/firewall.rst | 56 ++-- docs/source/simulation.rst | 2 + .../_package_data/data_manipulation.yaml | 52 ++- .../_package_data/data_manipulation_marl.yaml | 64 ++-- src/primaite/game/agent/actions.py | 75 +++-- .../agent/observations/link_observation.py | 5 +- .../agent/observations/observation_manager.py | 1 - src/primaite/game/agent/rewards.py | 1 + .../agent/scripted_agents/random_agent.py | 64 +++- .../game/agent/scripted_agents/tap001.py | 78 +++++ src/primaite/game/game.py | 46 +++ src/primaite/session/environment.py | 5 + src/primaite/session/io.py | 8 +- src/primaite/simulator/__init__.py | 1 + src/primaite/simulator/core.py | 9 + src/primaite/simulator/file_system/file.py | 4 + .../simulator/file_system/file_system.py | 12 +- src/primaite/simulator/file_system/folder.py | 7 + src/primaite/simulator/network/container.py | 20 +- src/primaite/simulator/network/creation.py | 14 +- .../simulator/network/hardware/base.py | 35 +- .../hardware/nodes/network/firewall.py | 12 + .../network/hardware/nodes/network/router.py | 51 ++- .../network/hardware/nodes/network/switch.py | 9 +- .../network/transmission/data_link_layer.py | 36 +- .../network/transmission/transport_layer.py | 3 + src/primaite/simulator/sim_container.py | 5 + .../system/applications/application.py | 5 +- .../system/applications/database_client.py | 57 ++-- .../red_applications/ransomware_script.py | 316 ++++++++++++++++++ src/primaite/simulator/system/core/sys_log.py | 19 +- .../services/database/database_service.py | 33 +- .../system/services/ntp/ntp_client.py | 8 +- src/primaite/simulator/system/software.py | 4 + .../assets/configs/bad_primaite_session.yaml | 38 ++- tests/assets/configs/basic_firewall.yaml | 14 - .../configs/basic_switched_network.yaml | 15 - tests/assets/configs/dmz_network.yaml | 14 - .../configs/eval_only_primaite_session.yaml | 38 ++- .../configs/firewall_actions_network.yaml | 42 +-- tests/assets/configs/multi_agent_session.yaml | 76 +++-- .../no_nodes_links_agents_network.yaml | 14 - tests/assets/configs/shared_rewards.yaml | 42 +-- .../configs/test_application_install.yaml | 38 ++- .../assets/configs/test_primaite_session.yaml | 38 ++- .../configs/train_only_primaite_session.yaml | 38 ++- tests/conftest.py | 6 +- .../game_layer/test_actions.py | 4 + .../network/test_capture_nmne.py | 94 +++++- .../integration_tests/network/test_routing.py | 16 + .../test_dos_bot_and_server.py | 4 + .../test_ransomware_script.py | 163 +++++++++ .../_file_system/test_file_system.py | 5 + 55 files changed, 1383 insertions(+), 441 deletions(-) create mode 100644 src/primaite/game/agent/scripted_agents/tap001.py create mode 100644 src/primaite/simulator/system/applications/red_applications/ransomware_script.py create mode 100644 tests/integration_tests/system/red_applications/test_ransomware_script.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 494ea937..56dc6424 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - id: check-added-large-files - args: ['--maxkb=1000'] + args: ['--maxkb=5000'] - id: mixed-line-ending - id: requirements-txt-fixer - repo: http://github.com/psf/black @@ -28,3 +28,7 @@ repos: additional_dependencies: - flake8-docstrings - flake8-annotations + - repo: https://github.com/kynan/nbstripout + rev: 0.7.1 + hooks: + - id: nbstripout diff --git a/docs/source/configuration/agents.rst b/docs/source/configuration/agents.rst index b8912883..5acf17a4 100644 --- a/docs/source/configuration/agents.rst +++ b/docs/source/configuration/agents.rst @@ -82,7 +82,7 @@ Allows configuration of the chosen observation type. These are optional. * ``num_services_per_node``, ``num_folders_per_node``, ``num_files_per_folder``, ``num_nics_per_node`` all define the shape of the observation space. The size and shape of the obs space must remain constant, but the number of files, folders, ACL rules, and other components can change within an episode. Therefore padding is performed and these options set the size of the obs space. * ``nodes``: list of nodes that will be present in this agent's observation space. The ``node_ref`` relates to the human-readable unique reference defined later in the ``simulation`` part of the config. Each node can also be configured with services, and files that should be monitored. * ``links``: list of links that will be present in this agent's observation space. The ``link_ref`` relates to the human-readable unique reference defined later in the ``simulation`` part of the config. - * ``acl``: configure how the agent reads the access control list on the router in the simulation. ``router_node_ref`` is for selecting which router's ACL table should be used. ``ip_address_order`` sets the encoding of ip addresses as integers within the observation space. + * ``acl``: configure how the agent reads the access control list on the router in the simulation. ``router_node_ref`` is for selecting which router's ACL table should be used. ``ip_list`` sets the encoding of ip addresses as integers within the observation space. For more information see :py:mod:`primaite.game.agent.observations` diff --git a/docs/source/configuration/simulation/nodes/firewall.rst b/docs/source/configuration/simulation/nodes/firewall.rst index 47db4001..77e6cd12 100644 --- a/docs/source/configuration/simulation/nodes/firewall.rst +++ b/docs/source/configuration/simulation/nodes/firewall.rst @@ -22,35 +22,35 @@ example firewall network: nodes: - ref: firewall - hostname: firewall - type: firewall - start_up_duration: 0 - shut_down_duration: 0 - ports: - external_port: # port 1 - ip_address: 192.168.20.1 - subnet_mask: 255.255.255.0 - internal_port: # port 2 - ip_address: 192.168.1.2 - subnet_mask: 255.255.255.0 - dmz_port: # port 3 - ip_address: 192.168.10.1 - subnet_mask: 255.255.255.0 - acl: - internal_inbound_acl: + hostname: firewall + type: firewall + start_up_duration: 0 + shut_down_duration: 0 + ports: + external_port: # port 1 + ip_address: 192.168.20.1 + subnet_mask: 255.255.255.0 + internal_port: # port 2 + ip_address: 192.168.1.2 + subnet_mask: 255.255.255.0 + dmz_port: # port 3 + ip_address: 192.168.10.1 + subnet_mask: 255.255.255.0 + acl: + internal_inbound_acl: + ... + internal_outbound_acl: + ... + dmz_inbound_acl: + ... + dmz_outbound_acl: + ... + external_inbound_acl: + ... + external_outbound_acl: + ... + routes: ... - internal_outbound_acl: - ... - dmz_inbound_acl: - ... - dmz_outbound_acl: - ... - external_inbound_acl: - ... - external_outbound_acl: - ... - routes: - ... .. include:: common/common_node_attributes.rst diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index c4bf1bf0..20e1182a 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -25,6 +25,8 @@ Contents simulation_components/network/nodes/switch simulation_components/network/nodes/wireless_router simulation_components/network/nodes/firewall + simulation_components/network/switch + simulation_components/network/radio simulation_components/network/network simulation_components/system/internal_frame_processing simulation_components/system/sys_log diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index deda5d73..8c365320 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -1,15 +1,3 @@ -training_config: - rl_framework: SB3 - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 1 - n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: - - defender - io_settings: save_agent_actions: true save_step_metadata: false @@ -490,6 +478,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" action: "ROUTER_ACL_ADDRULE" options: @@ -501,6 +491,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 48: # old action num: 24 # block tcp traffic from client 1 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -512,6 +504,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 49: # old action num: 25 # block tcp traffic from client 2 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -523,6 +517,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 50: # old action num: 26 action: "ROUTER_ACL_ADDRULE" options: @@ -534,6 +530,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 51: # old action num: 27 action: "ROUTER_ACL_ADDRULE" options: @@ -545,6 +543,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 52: # old action num: 28 action: "ROUTER_ACL_REMOVERULE" options: @@ -703,23 +703,15 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 - ip_address_order: - - node_name: domain_controller - nic_num: 1 - - node_name: web_server - nic_num: 1 - - node_name: database_server - nic_num: 1 - - node_name: backup_server - nic_num: 1 - - node_name: security_suite - nic_num: 1 - - node_name: client_1 - nic_num: 1 - - node_name: client_2 - nic_num: 1 - - node_name: security_suite - nic_num: 2 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 reward_function: @@ -730,10 +722,12 @@ agents: node_hostname: database_server folder_name: database file_name: database.db + - type: SHARED_REWARD weight: 1.0 options: agent_name: client_1_green_user + - type: SHARED_REWARD weight: 1.0 options: diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index 653ddfd3..eaee132b 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -492,6 +492,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" action: "ROUTER_ACL_ADDRULE" options: @@ -503,6 +505,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 48: # old action num: 24 # block tcp traffic from client 1 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -514,6 +518,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 49: # old action num: 25 # block tcp traffic from client 2 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -525,6 +531,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 50: # old action num: 26 action: "ROUTER_ACL_ADDRULE" options: @@ -536,6 +544,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 51: # old action num: 27 action: "ROUTER_ACL_ADDRULE" options: @@ -547,6 +557,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 52: # old action num: 28 action: "ROUTER_ACL_REMOVERULE" options: @@ -704,23 +716,15 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 - ip_address_order: - - node_name: domain_controller - nic_num: 1 - - node_name: web_server - nic_num: 1 - - node_name: database_server - nic_num: 1 - - node_name: backup_server - nic_num: 1 - - node_name: security_suite - nic_num: 1 - - node_name: client_1 - nic_num: 1 - - node_name: client_2 - nic_num: 1 - - node_name: security_suite - nic_num: 2 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 reward_function: @@ -1284,23 +1288,15 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 - ip_address_order: - - node_name: domain_controller - nic_num: 1 - - node_name: web_server - nic_num: 1 - - node_name: database_server - nic_num: 1 - - node_name: backup_server - nic_num: 1 - - node_name: security_suite - nic_num: 1 - - node_name: client_1 - nic_num: 1 - - node_name: client_2 - nic_num: 1 - - node_name: security_suite - nic_num: 2 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 reward_function: reward_components: diff --git a/src/primaite/game/agent/actions.py b/src/primaite/game/agent/actions.py index 9e967f91..f4f9a2cc 100644 --- a/src/primaite/game/agent/actions.py +++ b/src/primaite/game/agent/actions.py @@ -487,7 +487,9 @@ class RouterACLAddRuleAction(AbstractAction): position: int, permission: int, source_ip_id: int, + source_wildcard_id: int, dest_ip_id: int, + dest_wildcard_id: int, source_port_id: int, dest_port_id: int, protocol_id: int, @@ -519,7 +521,7 @@ class RouterACLAddRuleAction(AbstractAction): else: src_ip = self.manager.get_ip_address_by_idx(source_ip_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 - + src_wildcard = self.manager.get_wildcard_by_idx(source_wildcard_id) if source_port_id == 0: return ["do_nothing"] # invalid formulation elif source_port_id == 1: @@ -528,13 +530,14 @@ class RouterACLAddRuleAction(AbstractAction): src_port = self.manager.get_port_by_idx(source_port_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 - if source_ip_id == 0: + if dest_ip_id == 0: return ["do_nothing"] # invalid formulation elif dest_ip_id == 1: dst_ip = "ALL" else: dst_ip = self.manager.get_ip_address_by_idx(dest_ip_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 + dst_wildcard = self.manager.get_wildcard_by_idx(dest_wildcard_id) if dest_port_id == 0: return ["do_nothing"] # invalid formulation @@ -553,8 +556,10 @@ class RouterACLAddRuleAction(AbstractAction): permission_str, protocol, str(src_ip), + src_wildcard, src_port, str(dst_ip), + dst_wildcard, dst_port, position, ] @@ -624,7 +629,9 @@ class FirewallACLAddRuleAction(AbstractAction): position: int, permission: int, source_ip_id: int, + source_wildcard_id: int, dest_ip_id: int, + dest_wildcard_id: int, source_port_id: int, dest_port_id: int, protocol_id: int, @@ -665,7 +672,7 @@ class FirewallACLAddRuleAction(AbstractAction): src_port = self.manager.get_port_by_idx(source_port_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 - if source_ip_id == 0: + if dest_ip_id == 0: return ["do_nothing"] # invalid formulation elif dest_ip_id == 1: dst_ip = "ALL" @@ -680,6 +687,8 @@ class FirewallACLAddRuleAction(AbstractAction): else: dst_port = self.manager.get_port_by_idx(dest_port_id - 2) # subtract 2 to account for UNUSED=0, and ALL=1 + src_wildcard = self.manager.get_wildcard_by_idx(source_wildcard_id) + dst_wildcard = self.manager.get_wildcard_by_idx(dest_wildcard_id) return [ "network", @@ -692,8 +701,10 @@ class FirewallACLAddRuleAction(AbstractAction): permission_str, protocol, str(src_ip), + src_wildcard, src_port, str(dst_ip), + dst_wildcard, dst_port, position, ] @@ -871,7 +882,8 @@ class ActionManager: max_acl_rules: int = 10, # allows calculating shape protocols: List[str] = ["TCP", "UDP", "ICMP"], # allow mapping index to protocol ports: List[str] = ["HTTP", "DNS", "ARP", "FTP", "NTP"], # allow mapping index to port - ip_address_list: List[str] = [], # to allow us to map an index to an ip address. + ip_list: List[str] = [], # to allow us to map an index to an ip address. + wildcard_list: List[str] = [], # to allow mapping from wildcard index to act_map: Optional[Dict[int, Dict]] = None, # allows restricting set of possible actions ) -> None: """Init method for ActionManager. @@ -897,8 +909,8 @@ class ActionManager: :type protocols: List[str] :param ports: List of ports that are available in the simulation. Used for calculating action shape. :type ports: List[str] - :param ip_address_list: List of IP addresses that known to this agent. Used for calculating action shape. - :type ip_address_list: Optional[List[str]] + :param ip_list: List of IP addresses that known to this agent. Used for calculating action shape. + :type ip_list: Optional[List[str]] :param act_map: Action map which maps integers to actions. Used for restricting the set of possible actions. :type act_map: Optional[Dict[int, Dict]] """ @@ -959,8 +971,10 @@ class ActionManager: self.protocols: List[str] = protocols self.ports: List[str] = ports - self.ip_address_list: List[str] = ip_address_list - + self.ip_address_list: List[str] = ip_list + self.wildcard_list: List[str] = wildcard_list + if self.wildcard_list == []: + self.wildcard_list = ["NONE"] # action_args are settings which are applied to the action space as a whole. global_action_args = { "num_nodes": len(self.node_names), @@ -1195,6 +1209,24 @@ class ActionManager: raise RuntimeError(msg) return self.ip_address_list[ip_idx] + def get_wildcard_by_idx(self, wildcard_idx: int) -> str: + """ + Get the IP wildcard corresponding to the given index. + + :param ip_idx: The index of the IP wildcard to retrieve. + :type ip_idx: int + :return: The wildcard address. + :rtype: str + """ + if wildcard_idx >= len(self.wildcard_list): + msg = ( + f"Error: agent attempted to perform an action on ip wildcard {wildcard_idx} but this" + f" is out of range for its action space. Wildcard list: {self.wildcard_list}" + ) + _LOGGER.error(msg) + raise RuntimeError(msg) + return self.wildcard_list[wildcard_idx] + def get_port_by_idx(self, port_idx: int) -> str: """ Get the port corresponding to the given index. @@ -1253,37 +1285,14 @@ class ActionManager: :return: The constructed ActionManager. :rtype: ActionManager """ - # If the user has provided a list of IP addresses, use that. Otherwise, generate a list of IP addresses from - # the nodes in the simulation. - # TODO: refactor. Options: - # 1: This should be pulled out into it's own function for clarity - # 2: The simulation itself should be able to provide a list of IP addresses with its API, rather than having to - # go through the nodes here. - ip_address_order = cfg["options"].pop("ip_address_order", {}) - ip_address_list = [] - for entry in ip_address_order: - node_name = entry["node_name"] - nic_num = entry["nic_num"] - node_obj = game.simulation.network.get_node_by_hostname(node_name) - ip_address = node_obj.network_interface[nic_num].ip_address - ip_address_list.append(ip_address) - - if not ip_address_list: - node_names = [n["node_name"] for n in cfg.get("nodes", {})] - for node_name in node_names: - node_obj = game.simulation.network.get_node_by_hostname(node_name) - if node_obj is None: - continue - network_interfaces = node_obj.network_interfaces - for nic_uuid, nic_obj in network_interfaces.items(): - ip_address_list.append(nic_obj.ip_address) + if "ip_list" not in cfg["options"]: + cfg["options"]["ip_list"] = [] obj = cls( actions=cfg["action_list"], **cfg["options"], protocols=game.options.protocols, ports=game.options.ports, - ip_address_list=ip_address_list, act_map=cfg.get("action_map"), ) diff --git a/src/primaite/game/agent/observations/link_observation.py b/src/primaite/game/agent/observations/link_observation.py index 03a19fa0..50dc1105 100644 --- a/src/primaite/game/agent/observations/link_observation.py +++ b/src/primaite/game/agent/observations/link_observation.py @@ -43,7 +43,10 @@ class LinkObservation(AbstractObservation, identifier="LINK"): """ link_state = access_from_nested_dict(state, self.where) if link_state is NOT_PRESENT_IN_STATE: - return self.default_observation + self.where[-1] = "<->".join(self.where[-1].split("<->")[::-1]) # try swapping endpoint A and B + link_state = access_from_nested_dict(state, self.where) + if link_state is NOT_PRESENT_IN_STATE: + return self.default_observation bandwidth = link_state["bandwidth"] load = link_state["current_load"] diff --git a/src/primaite/game/agent/observations/observation_manager.py b/src/primaite/game/agent/observations/observation_manager.py index 047acce6..352003d6 100644 --- a/src/primaite/game/agent/observations/observation_manager.py +++ b/src/primaite/game/agent/observations/observation_manager.py @@ -189,7 +189,6 @@ class ObservationManager: """ if config is None: return cls(NullObservation()) - print(config) obs_type = config["type"] obs_class = AbstractObservation._registry[obs_type] observation = obs_class.from_config(config=obs_class.ConfigSchema(**config["options"])) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 2201b09e..f3398631 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -293,6 +293,7 @@ class GreenAdminDatabaseUnreachablePenalty(AbstractReward): db_state = access_from_nested_dict(state, self.location_in_state) if db_state is NOT_PRESENT_IN_STATE or "last_connection_successful" not in db_state: _LOGGER.debug(f"Can't calculate reward for {self.__class__.__name__}") + return 0.0 last_connection_successful = db_state["last_connection_successful"] if last_connection_successful is False: return -1.0 diff --git a/src/primaite/game/agent/scripted_agents/random_agent.py b/src/primaite/game/agent/scripted_agents/random_agent.py index 34a4b5ac..5021a832 100644 --- a/src/primaite/game/agent/scripted_agents/random_agent.py +++ b/src/primaite/game/agent/scripted_agents/random_agent.py @@ -1,8 +1,13 @@ -from typing import Dict, Tuple +import random +from typing import Dict, Optional, Tuple from gymnasium.core import ObsType +from pydantic import BaseModel +from primaite.game.agent.actions import ActionManager from primaite.game.agent.interface import AbstractScriptedAgent +from primaite.game.agent.observations.observation_manager import ObservationManager +from primaite.game.agent.rewards import RewardFunction class RandomAgent(AbstractScriptedAgent): @@ -19,3 +24,60 @@ class RandomAgent(AbstractScriptedAgent): :rtype: Tuple[str, Dict] """ return self.action_manager.get_action(self.action_manager.space.sample()) + + +class PeriodicAgent(AbstractScriptedAgent): + """Agent that does nothing most of the time, but executes application at regular intervals (with variance).""" + + class Settings(BaseModel): + """Configuration values for when an agent starts performing actions.""" + + start_step: int = 20 + "The timestep at which an agent begins performing it's actions." + start_variance: int = 5 + "Deviation around the start step." + frequency: int = 5 + "The number of timesteps to wait between performing actions." + variance: int = 0 + "The amount the frequency can randomly change to." + max_executions: int = 999999 + "Maximum number of times the agent can execute its action." + + def __init__( + self, + agent_name: str, + action_space: ActionManager, + observation_space: ObservationManager, + reward_function: RewardFunction, + settings: Optional[Settings] = None, + ) -> None: + """Initialise PeriodicAgent.""" + super().__init__( + agent_name=agent_name, + action_space=action_space, + observation_space=observation_space, + reward_function=reward_function, + ) + self.settings = settings or PeriodicAgent.Settings() + self._set_next_execution_timestep(timestep=self.settings.start_step, variance=self.settings.start_variance) + self.num_executions = 0 + + def _set_next_execution_timestep(self, timestep: int, variance: int) -> None: + """Set the next execution timestep with a configured random variance. + + :param timestep: The timestep when the next execute action should be taken. + :type timestep: int + :param variance: Uniform random variance applied to the timestep + :type variance: int + """ + random_increment = random.randint(-variance, variance) + self.next_execution_timestep = timestep + random_increment + + def get_action(self, obs: ObsType, timestep: int) -> Tuple[str, Dict]: + """Do nothing, unless the current timestep is the next execution timestep, in which case do the action.""" + if timestep == self.next_execution_timestep and self.num_executions < self.settings.max_executions: + self.num_executions += 1 + self._set_next_execution_timestep(timestep + self.settings.frequency, self.settings.variance) + return "NODE_APPLICATION_EXECUTE", {"node_id": 0, "application_id": 0} + + return "DONOTHING", {} diff --git a/src/primaite/game/agent/scripted_agents/tap001.py b/src/primaite/game/agent/scripted_agents/tap001.py new file mode 100644 index 00000000..88fa37cf --- /dev/null +++ b/src/primaite/game/agent/scripted_agents/tap001.py @@ -0,0 +1,78 @@ +import random +from typing import Dict, Tuple + +from gymnasium.core import ObsType + +from primaite.game.agent.interface import AbstractScriptedAgent + + +class TAP001(AbstractScriptedAgent): + """ + TAP001 | Mobile Malware -- Ransomware Variant. + + Scripted Red Agent. Capable of one action; launching the kill-chain (Ransomware Application) + """ + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.setup_agent() + + next_execution_timestep: int = 0 + starting_node_idx: int = 0 + installed: bool = False + + def _set_next_execution_timestep(self, timestep: int) -> None: + """Set the next execution timestep with a configured random variance. + + :param timestep: The timestep to add variance to. + """ + random_timestep_increment = random.randint( + -self.agent_settings.start_settings.variance, self.agent_settings.start_settings.variance + ) + self.next_execution_timestep = timestep + random_timestep_increment + + def get_action(self, obs: ObsType, timestep: int) -> Tuple[str, Dict]: + """Waits until a specific timestep, then attempts to execute the ransomware application. + + This application acts a wrapper around the kill-chain, similar to green-analyst and + the previous UC2 data manipulation bot. + + :param obs: Current observation for this agent. + :type obs: ObsType + :param timestep: The current simulation timestep, used for scheduling actions + :type timestep: int + :return: Action formatted in CAOS format + :rtype: Tuple[str, Dict] + """ + if timestep < self.next_execution_timestep: + return "DONOTHING", {} + + self._set_next_execution_timestep(timestep + self.agent_settings.start_settings.frequency) + + if not self.installed: + self.installed = True + return "NODE_APPLICATION_INSTALL", { + "node_id": self.starting_node_idx, + "application_name": "RansomwareScript", + "ip_address": self.ip_address, + } + + return "NODE_APPLICATION_EXECUTE", {"node_id": self.starting_node_idx, "application_id": 0} + + def setup_agent(self) -> None: + """Set the next execution timestep when the episode resets.""" + self._select_start_node() + self._set_next_execution_timestep(self.agent_settings.start_settings.start_step) + for n, act in self.action_manager.action_map.items(): + if not act[0] == "NODE_APPLICATION_INSTALL": + continue + if act[1]["node_id"] == self.starting_node_idx: + self.ip_address = act[1]["ip_address"] + return + raise RuntimeError("TAP001 agent could not find database server ip address in action map") + + def _select_start_node(self) -> None: + """Set the starting starting node of the agent to be a random node from this agent's action manager.""" + # we are assuming that every node in the node manager has a data manipulation application at idx 0 + num_nodes = len(self.action_manager.node_names) + self.starting_node_idx = random.randint(0, num_nodes - 1) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index f069433e..27fd452d 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -11,7 +11,10 @@ from primaite.game.agent.observations.observation_manager import ObservationMana from primaite.game.agent.rewards import RewardFunction, SharedReward from primaite.game.agent.scripted_agents.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.scripted_agents.probabilistic_agent import ProbabilisticAgent +from primaite.game.agent.scripted_agents.random_agent import PeriodicAgent +from primaite.game.agent.scripted_agents.tap001 import TAP001 from primaite.game.science import graph_has_cycle, topological_sort +from primaite.simulator.network.airspace import AIR_SPACE from primaite.simulator.network.hardware.base import NodeOperatingState from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC @@ -26,6 +29,7 @@ from primaite.simulator.sim_container import Simulation from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.applications.red_applications.dos_bot import DoSBot +from primaite.simulator.system.applications.red_applications.ransomware_script import RansomwareScript from primaite.simulator.system.applications.web_browser import WebBrowser from primaite.simulator.system.services.database.database_service import DatabaseService from primaite.simulator.system.services.dns.dns_client import DNSClient @@ -43,6 +47,7 @@ APPLICATION_TYPES_MAPPING = { "DatabaseClient": DatabaseClient, "DataManipulationBot": DataManipulationBot, "DoSBot": DoSBot, + "RansomwareScript": RansomwareScript, } """List of available applications that can be installed on nodes in the PrimAITE Simulation.""" @@ -128,6 +133,8 @@ class PrimaiteGame: """ _LOGGER.debug(f"Stepping. Step counter: {self.step_counter}") + self.pre_timestep() + if self.step_counter == 0: state = self.get_sim_state() for agent in self.agents.values(): @@ -172,6 +179,10 @@ class PrimaiteGame: response=response, ) + def pre_timestep(self) -> None: + """Apply any pre-timestep logic that helps make sure we have the correct observations.""" + self.simulation.pre_timestep(self.step_counter) + def advance_timestep(self) -> None: """Advance timestep.""" self.step_counter += 1 @@ -211,6 +222,7 @@ class PrimaiteGame: :return: A PrimaiteGame object. :rtype: PrimaiteGame """ + AIR_SPACE.clear() game = cls() game.options = PrimaiteGameOptions(**cfg["game"]) game.save_step_metadata = cfg.get("io_settings", {}).get("save_step_metadata") or False @@ -268,6 +280,9 @@ class PrimaiteGame: hostname=node_cfg["hostname"], ip_address=node_cfg["ip_address"], subnet_mask=node_cfg["subnet_mask"], + operating_state=NodeOperatingState.ON + if not (p := node_cfg.get("operating_state")) + else NodeOperatingState[p.upper()], ) else: msg = f"invalid node type {n_type} in config" @@ -339,6 +354,19 @@ class PrimaiteGame: port_scan_p_of_success=float(opt.get("port_scan_p_of_success", "0.1")), data_manipulation_p_of_success=float(opt.get("data_manipulation_p_of_success", "0.1")), ) + elif application_type == "RansomwareScript": + if "options" in application_cfg: + opt = application_cfg["options"] + new_application.configure( + server_ip_address=IPv4Address(opt.get("server_ip")), + server_password=opt.get("server_password"), + payload=opt.get("payload", "ENCRYPT"), + c2_beacon_p_of_success=float(opt.get("c2_beacon_p_of_success", "0.5")), + target_scan_p_of_success=float(opt.get("target_scan_p_of_success", "0.1")), + ransomware_encrypt_p_of_success=float( + opt.get("ransomware_encrypt_p_of_success", "0.1") + ), + ) elif application_type == "DatabaseClient": if "options" in application_cfg: opt = application_cfg["options"] @@ -423,6 +451,15 @@ class PrimaiteGame: reward_function=reward_function, settings=settings, ) + elif agent_type == "PeriodicAgent": + settings = PeriodicAgent.Settings(**agent_cfg.get("settings", {})) + new_agent = PeriodicAgent( + agent_name=agent_cfg["ref"], + action_space=action_space, + observation_space=obs_space, + reward_function=reward_function, + settings=settings, + ) elif agent_type == "ProxyAgent": agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) new_agent = ProxyAgent( @@ -443,6 +480,15 @@ class PrimaiteGame: reward_function=reward_function, agent_settings=agent_settings, ) + elif agent_type == "TAP001": + agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) + new_agent = TAP001( + agent_name=agent_cfg["ref"], + action_space=action_space, + observation_space=obs_space, + reward_function=reward_function, + agent_settings=agent_settings, + ) else: msg = f"Configuration error: {agent_type} is not a valid agent type." _LOGGER.error(msg) diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 4fdbbe34..cb891cd7 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -26,6 +26,9 @@ class PrimaiteGymEnv(gymnasium.Env): def __init__(self, game_config: Dict): """Initialise the environment.""" super().__init__() + self.io = PrimaiteIO.from_config(game_config.get("io_settings", {})) + """Handles IO for the environment. This produces sys logs, agent logs, etc.""" + self.game_config: Dict = game_config """PrimaiteGame definition. This can be changed between episodes to enable curriculum learning.""" self.io = PrimaiteIO.from_config(game_config.get("io_settings", {})) @@ -49,6 +52,7 @@ class PrimaiteGymEnv(gymnasium.Env): step = self.game.step_counter self.agent.store_action(action) # apply_agent_actions accesses the action we just stored + self.game.pre_timestep() self.game.apply_agent_actions() self.game.advance_timestep() state = self.game.get_sim_state() @@ -224,6 +228,7 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): # 1. Perform actions for agent_name, action in actions.items(): self.agents[agent_name].store_action(action) + self.game.pre_timestep() self.game.apply_agent_actions() # 2. Advance timestep diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index e57f88ae..69cea614 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -29,10 +29,12 @@ class PrimaiteIO: """Whether to save a log of all agents' actions every step.""" save_step_metadata: bool = False """Whether to save the RL agents' action, environment state, and other data at every single step.""" - save_pcap_logs: bool = False + save_pcap_logs: bool = True """Whether to save PCAP logs.""" - save_sys_logs: bool = False + save_sys_logs: bool = True """Whether to save system logs.""" + write_sys_log_to_terminal: bool = False + """Whether to write the sys log to the terminal.""" def __init__(self, settings: Optional[Settings] = None) -> None: """ @@ -47,6 +49,7 @@ class PrimaiteIO: SIM_OUTPUT.path = self.session_path / "simulation_output" SIM_OUTPUT.save_pcap_logs = self.settings.save_pcap_logs SIM_OUTPUT.save_sys_logs = self.settings.save_sys_logs + SIM_OUTPUT.write_sys_log_to_terminal = self.settings.write_sys_log_to_terminal def generate_session_path(self, timestamp: Optional[datetime] = None) -> Path: """Create a folder for the session and return the path to it.""" @@ -93,4 +96,5 @@ class PrimaiteIO: def from_config(cls, config: Dict) -> "PrimaiteIO": """Create an instance of PrimaiteIO based on a configuration dict.""" new = cls(settings=cls.Settings(**config)) + return new diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index aebd77cf..9e2ce9a1 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -14,6 +14,7 @@ class _SimOutput: ) self.save_pcap_logs: bool = False self.save_sys_logs: bool = False + self.write_sys_log_to_terminal: bool = False @property def path(self) -> Path: diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index 6da8a2f8..8e954229 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -226,6 +226,15 @@ class SimComponent(BaseModel): return return self._request_manager(request, context) + def pre_timestep(self, timestep: int) -> None: + """ + Apply any logic that needs to happen at the beginning of the timestep to ensure correct observations/rewards. + + :param timestep: what's the current time + :type timestep: int + """ + pass + def apply_timestep(self, timestep: int) -> None: """ Apply a timestep evolution to this component. diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index 9331c40c..3a1c24df 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -103,6 +103,10 @@ class File(FileSystemItemABC): """ super().apply_timestep(timestep=timestep) + def pre_timestep(self, timestep: int) -> None: + """Apply pre-timestep logic.""" + super().pre_timestep(timestep) + # reset the number of accesses to 0 self.num_access = 0 diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 9166178c..aacb7d01 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -427,15 +427,21 @@ class FileSystem(SimComponent): """Apply time step to FileSystem and its child folders and files.""" super().apply_timestep(timestep=timestep) + # apply timestep to folders + for folder_id in self.folders: + self.folders[folder_id].apply_timestep(timestep=timestep) + + def pre_timestep(self, timestep: int) -> None: + """Apply pre-timestep logic.""" + super().pre_timestep(timestep) # reset number of file creations self.num_file_creations = 0 # reset number of file deletions self.num_file_deletions = 0 - # apply timestep to folders - for folder_id in self.folders: - self.folders[folder_id].apply_timestep(timestep=timestep) + for folder in self.folders.values(): + folder.pre_timestep(timestep) ############################################################### # Agent actions diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 6ebd8d14..9f176660 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -128,6 +128,13 @@ class Folder(FileSystemItemABC): for file_id in self.files: self.files[file_id].apply_timestep(timestep=timestep) + def pre_timestep(self, timestep: int) -> None: + """Apply pre-timestep logic.""" + super().pre_timestep(timestep) + + for file in self.files.values(): + file.pre_timestep(timestep) + def _scan_timestep(self) -> None: """Apply the scan action timestep.""" if self.scan_countdown >= 0: diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index cfe66d89..e9a938ce 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -1,3 +1,4 @@ +from ipaddress import IPv4Address from typing import Any, Dict, List, Optional import matplotlib.pyplot as plt @@ -86,6 +87,16 @@ class Network(SimComponent): for link_id in self.links: self.links[link_id].apply_timestep(timestep=timestep) + def pre_timestep(self, timestep: int) -> None: + """Apply pre-timestep logic.""" + super().pre_timestep(timestep) + + for node in self.nodes.values(): + node.pre_timestep(timestep) + + for link in self.links.values(): + link.pre_timestep(timestep) + @property def router_nodes(self) -> List[Node]: """The Routers in the Network.""" @@ -163,10 +174,11 @@ class Network(SimComponent): for node in nodes: for i, port in node.network_interface.items(): if hasattr(port, "ip_address"): - port_str = port.port_name if port.port_name else port.port_num - table.add_row( - [node.hostname, port_str, port.ip_address, port.subnet_mask, node.default_gateway] - ) + if port.ip_address != IPv4Address("127.0.0.1"): + port_str = port.port_name if port.port_name else port.port_num + table.add_row( + [node.hostname, port_str, port.ip_address, port.subnet_mask, node.default_gateway] + ) print(table) if links: diff --git a/src/primaite/simulator/network/creation.py b/src/primaite/simulator/network/creation.py index c1b0d43a..8bda626a 100644 --- a/src/primaite/simulator/network/creation.py +++ b/src/primaite/simulator/network/creation.py @@ -9,7 +9,7 @@ from primaite.simulator.network.transmission.network_layer import IPProtocol from primaite.simulator.network.transmission.transport_layer import Port -def num_of_switches_required(num_nodes: int, max_switch_ports: int = 24) -> int: +def num_of_switches_required(num_nodes: int, max_network_interface: int = 24) -> int: """ Calculate the minimum number of network switches required to connect a given number of nodes. @@ -18,7 +18,7 @@ def num_of_switches_required(num_nodes: int, max_switch_ports: int = 24) -> int: to accommodate all nodes under this constraint. :param num_nodes: The total number of nodes that need to be connected in the network. - :param max_switch_ports: The maximum number of ports available on each switch. Defaults to 24. + :param max_network_interface: The maximum number of ports available on each switch. Defaults to 24. :return: The minimum number of switches required to connect all PCs. @@ -33,11 +33,11 @@ def num_of_switches_required(num_nodes: int, max_switch_ports: int = 24) -> int: 3 """ # Reduce the effective number of switch ports by 1 to leave space for the router - effective_switch_ports = max_switch_ports - 1 + effective_network_interface = max_network_interface - 1 # Calculate the number of fully utilised switches and any additional switch for remaining PCs - full_switches = num_nodes // effective_switch_ports - extra_pcs = num_nodes % effective_switch_ports + full_switches = num_nodes // effective_network_interface + extra_pcs = num_nodes % effective_network_interface # Return the total number of switches required return full_switches + (1 if extra_pcs > 0 else 0) @@ -77,7 +77,7 @@ def create_office_lan( # Calculate the required number of switches num_of_switches = num_of_switches_required(num_nodes=num_pcs) - effective_switch_ports = 23 # One port less for router connection + effective_network_interface = 23 # One port less for router connection if pcs_ip_block_start <= num_of_switches: raise ValueError(f"pcs_ip_block_start must be greater than the number of required switches {num_of_switches}") @@ -116,7 +116,7 @@ def create_office_lan( # Add PCs to the LAN and connect them to switches for i in range(1, num_pcs + 1): # Add a new edge switch if the current one is full - if switch_port == effective_switch_ports: + if switch_port == effective_network_interface: switch_n += 1 switch_port = 0 switch = Switch(hostname=f"switch_edge_{switch_n}_{lan_name}", start_up_duration=0) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 1aa4366b..55636356 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -264,6 +264,9 @@ class NetworkInterface(SimComponent, ABC): """ return f"Port {self.port_name if self.port_name else self.port_num}: {self.mac_address}" + def __hash__(self) -> int: + return hash(self.uuid) + def apply_timestep(self, timestep: int) -> None: """ Apply a timestep evolution to this component. @@ -661,6 +664,10 @@ class Link(SimComponent): def apply_timestep(self, timestep: int) -> None: """Apply a timestep to the simulation.""" super().apply_timestep(timestep) + + def pre_timestep(self, timestep: int) -> None: + """Apply pre-timestep logic.""" + super().pre_timestep(timestep) self.current_load = 0.0 @@ -895,6 +902,10 @@ class Node(SimComponent): from primaite.simulator.system.applications.web_browser import WebBrowser return WebBrowser + elif application_class_str == "RansomwareScript": + from primaite.simulator.system.applications.red_applications.ransomware_script import RansomwareScript + + return RansomwareScript else: return 0 @@ -965,12 +976,15 @@ class Node(SimComponent): table.align = "l" table.title = f"{self.hostname} Network Interface Cards" for port, network_interface in self.network_interface.items(): + ip_address = "" + if hasattr(network_interface, "ip_address"): + ip_address = f"{network_interface.ip_address}/{network_interface.ip_network.prefixlen}" table.add_row( [ port, network_interface.__class__.__name__, network_interface.mac_address, - f"{network_interface.ip_address}/{network_interface.ip_network.prefixlen}", + ip_address, network_interface.speed, "Enabled" if network_interface.enabled else "Disabled", ] @@ -1071,6 +1085,23 @@ class Node(SimComponent): self.file_system.apply_timestep(timestep=timestep) + def pre_timestep(self, timestep: int) -> None: + """Apply pre-timestep logic.""" + super().pre_timestep(timestep) + for network_interface in self.network_interfaces.values(): + network_interface.pre_timestep(timestep=timestep) + + for process_id in self.processes: + self.processes[process_id].pre_timestep(timestep=timestep) + + for service_id in self.services: + self.services[service_id].pre_timestep(timestep=timestep) + + for application_id in self.applications: + self.applications[application_id].pre_timestep(timestep=timestep) + + self.file_system.pre_timestep(timestep=timestep) + def scan(self) -> bool: """ Scan the node and all the items within it. @@ -1341,6 +1372,8 @@ class Node(SimComponent): application_instance.configure(target_ip_address=IPv4Address(ip_address)) elif application_instance.name == "DataManipulationBot": application_instance.configure(server_ip_address=IPv4Address(ip_address)) + elif application_instance.name == "RansomwareScript": + application_instance.configure(server_ip_address=IPv4Address(ip_address)) else: pass diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index 08735b3b..84ed3ee5 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -599,7 +599,9 @@ class Firewall(Router): dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], src_ip_address=r_cfg.get("src_ip"), + src_wildcard_mask=r_cfg.get("src_wildcard_mask"), dst_ip_address=r_cfg.get("dst_ip"), + dst_wildcard_mask=r_cfg.get("dst_wildcard_mask"), position=r_num, ) @@ -612,7 +614,9 @@ class Firewall(Router): dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], src_ip_address=r_cfg.get("src_ip"), + src_wildcard_mask=r_cfg.get("src_wildcard_mask"), dst_ip_address=r_cfg.get("dst_ip"), + dst_wildcard_mask=r_cfg.get("dst_wildcard_mask"), position=r_num, ) @@ -625,7 +629,9 @@ class Firewall(Router): dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], src_ip_address=r_cfg.get("src_ip"), + src_wildcard_mask=r_cfg.get("src_wildcard_mask"), dst_ip_address=r_cfg.get("dst_ip"), + dst_wildcard_mask=r_cfg.get("dst_wildcard_mask"), position=r_num, ) @@ -638,7 +644,9 @@ class Firewall(Router): dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], src_ip_address=r_cfg.get("src_ip"), + src_wildcard_mask=r_cfg.get("src_wildcard_mask"), dst_ip_address=r_cfg.get("dst_ip"), + dst_wildcard_mask=r_cfg.get("dst_wildcard_mask"), position=r_num, ) @@ -651,7 +659,9 @@ class Firewall(Router): dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], src_ip_address=r_cfg.get("src_ip"), + src_wildcard_mask=r_cfg.get("src_wildcard_mask"), dst_ip_address=r_cfg.get("dst_ip"), + dst_wildcard_mask=r_cfg.get("dst_wildcard_mask"), position=r_num, ) @@ -664,7 +674,9 @@ class Firewall(Router): dst_port=None if not (p := r_cfg.get("dst_port")) else Port[p], protocol=None if not (p := r_cfg.get("protocol")) else IPProtocol[p], src_ip_address=r_cfg.get("src_ip"), + src_wildcard_mask=r_cfg.get("src_wildcard_mask"), dst_ip_address=r_cfg.get("dst_ip"), + dst_wildcard_mask=r_cfg.get("dst_wildcard_mask"), position=r_num, ) diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 1c36c696..5d041fd1 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -322,10 +322,12 @@ class AccessControlList(SimComponent): action=ACLAction[request[0]], protocol=None if request[1] == "ALL" else IPProtocol[request[1]], src_ip_address=None if request[2] == "ALL" else IPv4Address(request[2]), - src_port=None if request[3] == "ALL" else Port[request[3]], - dst_ip_address=None if request[4] == "ALL" else IPv4Address(request[4]), - dst_port=None if request[5] == "ALL" else Port[request[5]], - position=int(request[6]), + src_wildcard_mask=None if request[3] == "NONE" else IPv4Address(request[3]), + src_port=None if request[4] == "ALL" else Port[request[4]], + dst_ip_address=None if request[5] == "ALL" else IPv4Address(request[5]), + dst_wildcard_mask=None if request[6] == "NONE" else IPv4Address(request[6]), + dst_port=None if request[7] == "ALL" else Port[request[7]], + position=int(request[8]), ) ) ), @@ -772,6 +774,13 @@ class RouterARP(ARP): is_reattempt=True, is_default_route_attempt=is_default_route_attempt, ) + elif route and route == self.router.route_table.default_route: + self.send_arp_request(self.router.route_table.default_route.next_hop_ip_address) + return self._get_arp_cache_mac_address( + ip_address=self.router.route_table.default_route.next_hop_ip_address, + is_reattempt=True, + is_default_route_attempt=True, + ) else: if self.router.route_table.default_route: if not is_default_route_attempt: @@ -822,6 +831,12 @@ class RouterARP(ARP): return network_interface if not is_reattempt: + if self.router.ip_is_in_router_interface_subnet(ip_address): + self.send_arp_request(ip_address) + return self._get_arp_cache_network_interface( + ip_address=ip_address, is_reattempt=True, is_default_route_attempt=is_default_route_attempt + ) + route = self.router.route_table.find_best_route(ip_address) if route and route != self.router.route_table.default_route: self.send_arp_request(route.next_hop_ip_address) @@ -830,6 +845,13 @@ class RouterARP(ARP): is_reattempt=True, is_default_route_attempt=is_default_route_attempt, ) + elif route and route == self.router.route_table.default_route: + self.send_arp_request(self.router.route_table.default_route.next_hop_ip_address) + return self._get_arp_cache_network_interface( + ip_address=self.router.route_table.default_route.next_hop_ip_address, + is_reattempt=True, + is_default_route_attempt=True, + ) else: if self.router.route_table.default_route: if not is_default_route_attempt: @@ -1460,6 +1482,8 @@ class Router(NetworkNode): frame.ethernet.src_mac_addr = network_interface.mac_address frame.ethernet.dst_mac_addr = target_mac network_interface.send_frame(frame) + else: + self.sys_log.error(f"Frame dropped as there is no route to {frame.ip.dst_ip_address}") def configure_port(self, port: int, ip_address: Union[IPv4Address, str], subnet_mask: Union[IPv4Address, str]): """ @@ -1540,6 +1564,13 @@ class Router(NetworkNode): - protocol (str, optional): the named IP protocol such as ICMP, TCP, or UDP - src_ip_address (str, optional): IP address octet written in base 10 - dst_ip_address (str, optional): IP address octet written in base 10 + - routes (list[dict]): List of route dicts with values: + - address (str): The destination address of the route. + - subnet_mask (str): The subnet mask of the route. + - next_hop_ip_address (str): The next hop IP for the route. + - metric (int): The metric of the route. Optional. + - default_route: + - next_hop_ip_address (str): The next hop IP for the route. Example config: ``` @@ -1550,6 +1581,10 @@ class Router(NetworkNode): 1: { 'ip_address' : '192.168.1.1', 'subnet_mask' : '255.255.255.0', + }, + 2: { + 'ip_address' : '192.168.0.1', + 'subnet_mask' : '255.255.255.252', } }, 'acl' : { @@ -1557,6 +1592,10 @@ class Router(NetworkNode): 22: {'action': 'PERMIT', 'src_port': 'ARP', 'dst_port': 'ARP'}, 23: {'action': 'PERMIT', 'protocol': 'ICMP'}, }, + 'routes' : [ + {'address': '192.168.0.0', 'subnet_mask': '255.255.255.0', 'next_hop_ip_address': '192.168.1.2'} + ], + 'default_route': {'next_hop_ip_address': '192.168.0.2'} } ``` @@ -1600,4 +1639,8 @@ class Router(NetworkNode): next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")), metric=float(route.get("metric", 0)), ) + if "default_route" in cfg: + next_hop_ip_address = cfg["default_route"].get("next_hop_ip_address", None) + if next_hop_ip_address: + router.route_table.set_default_route_next_hop_ip_address(next_hop_ip_address) return router diff --git a/src/primaite/simulator/network/hardware/nodes/network/switch.py b/src/primaite/simulator/network/hardware/nodes/network/switch.py index 557ea287..aa405e14 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/network/switch.py @@ -100,13 +100,8 @@ class Switch(NetworkNode): def __init__(self, **kwargs): super().__init__(**kwargs) - if not self.network_interface: - self.network_interface = {i: SwitchPort() for i in range(1, self.num_ports + 1)} - for port_num, port in self.network_interface.items(): - port._connected_node = self - port.port_num = port_num - port.parent = self - port.port_num = port_num + for i in range(1, self.num_ports + 1): + self.connect_nic(SwitchPort()) def show(self, markdown: bool = False): """ diff --git a/src/primaite/simulator/network/transmission/data_link_layer.py b/src/primaite/simulator/network/transmission/data_link_layer.py index 27d40df0..e3189cd8 100644 --- a/src/primaite/simulator/network/transmission/data_link_layer.py +++ b/src/primaite/simulator/network/transmission/data_link_layer.py @@ -8,7 +8,7 @@ from primaite.simulator.network.protocols.icmp import ICMPPacket from primaite.simulator.network.protocols.packet import DataPacket from primaite.simulator.network.transmission.network_layer import IPPacket, IPProtocol from primaite.simulator.network.transmission.primaite_layer import PrimaiteHeader -from primaite.simulator.network.transmission.transport_layer import TCPHeader, UDPHeader +from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader, UDPHeader from primaite.simulator.network.utils import convert_bytes_to_megabits _LOGGER = getLogger(__name__) @@ -141,3 +141,37 @@ class Frame(BaseModel): def size_Mbits(self) -> float: # noqa - Keep it as MBits as this is how they're expressed """The daa transfer size of the Frame in Mbits.""" return convert_bytes_to_megabits(self.size) + + @property + def is_broadcast(self) -> bool: + """ + Determines if the Frame is a broadcast frame. + + A Frame is considered a broadcast frame if the destination MAC address is set to the broadcast address + "ff:ff:ff:ff:ff:ff". + + :return: True if the destination MAC address is a broadcast address, otherwise False. + """ + return self.ethernet.dst_mac_addr.lower() == "ff:ff:ff:ff:ff:ff" + + @property + def is_arp(self) -> bool: + """ + Checks if the Frame is an ARP (Address Resolution Protocol) packet. + + This is determined by checking if the destination port of the TCP header is equal to the ARP port. + + :return: True if the Frame is an ARP packet, otherwise False. + """ + return self.udp.dst_port == Port.ARP + + @property + def is_icmp(self) -> bool: + """ + Determines if the Frame is an ICMP (Internet Control Message Protocol) packet. + + This check is performed by verifying if the 'icmp' attribute of the Frame instance is present (not None). + + :return: True if the Frame is an ICMP packet (i.e., has an ICMP header), otherwise False. + """ + return self.icmp is not None diff --git a/src/primaite/simulator/network/transmission/transport_layer.py b/src/primaite/simulator/network/transmission/transport_layer.py index c73e451a..bf739ad1 100644 --- a/src/primaite/simulator/network/transmission/transport_layer.py +++ b/src/primaite/simulator/network/transmission/transport_layer.py @@ -11,6 +11,9 @@ class Port(Enum): .. _List of Ports: """ + UNUSED = -1 + "An unused port stub." + NONE = 0 "Place holder for a non-port." WOL = 9 diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index 997cc0be..9e2e5da4 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -63,3 +63,8 @@ class Simulation(SimComponent): """Apply a timestep to the simulation.""" super().apply_timestep(timestep) self.network.apply_timestep(timestep) + + def pre_timestep(self, timestep: int) -> None: + """Apply pre-timestep logic.""" + super().pre_timestep(timestep) + self.network.pre_timestep(timestep) diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index 617fdc23..ff71b51a 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -80,7 +80,10 @@ class Application(IOSoftware): """ super().apply_timestep(timestep=timestep) - self.num_executions = 0 # reset number of executions + def pre_timestep(self, timestep: int) -> None: + """Apply pre-timestep logic.""" + super().pre_timestep(timestep) + self.num_executions = 0 def _can_perform_action(self) -> bool: """ diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index 1de75dc5..d304c200 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -31,6 +31,7 @@ class DatabaseClient(Application): """Keep track of connections that were established or verified during this step. Used for rewards.""" last_query_response: Optional[Dict] = None """Keep track of the latest query response. Used to determine rewards.""" + _server_connection_id: Optional[str] = None def __init__(self, **kwargs): kwargs["name"] = "DatabaseClient" @@ -51,10 +52,9 @@ class DatabaseClient(Application): def execute(self) -> bool: """Execution definition for db client: perform a select query.""" self.num_executions += 1 # trying to connect counts as an execution - if self.connections: - can_connect = self.check_connection(connection_id=list(self.connections.keys())[-1]) - else: - can_connect = self.check_connection(connection_id=str(uuid4())) + if not self._server_connection_id: + self.connect() + can_connect = self.check_connection(connection_id=self._server_connection_id) self._last_connection_successful = can_connect return can_connect @@ -80,17 +80,21 @@ class DatabaseClient(Application): self.server_password = server_password self.sys_log.info(f"{self.name}: Configured the {self.name} with {server_ip_address=}, {server_password=}.") - def connect(self, connection_id: Optional[str] = None) -> bool: + def connect(self) -> bool: """Connect to a Database Service.""" if not self._can_perform_action(): return False - if not connection_id: - connection_id = str(uuid4()) + if not self._server_connection_id: + self._server_connection_id = str(uuid4()) self.connected = self._connect( - server_ip_address=self.server_ip_address, password=self.server_password, connection_id=connection_id + server_ip_address=self.server_ip_address, + password=self.server_password, + connection_id=self._server_connection_id, ) + if not self.connected: + self._server_connection_id = None return self.connected def check_connection(self, connection_id: str) -> bool: @@ -125,7 +129,7 @@ class DatabaseClient(Application): :type: is_reattempt: Optional[bool] """ if is_reattempt: - if self.connections.get(connection_id): + if self._server_connection_id: self.sys_log.info( f"{self.name} {connection_id=}: DatabaseClient connection to {server_ip_address} authorised" ) @@ -149,31 +153,28 @@ class DatabaseClient(Application): server_ip_address=server_ip_address, password=password, connection_id=connection_id, is_reattempt=True ) - def disconnect(self, connection_id: Optional[str] = None) -> bool: + def disconnect(self) -> bool: """Disconnect from the Database Service.""" if not self._can_perform_action(): self.sys_log.error(f"Unable to disconnect - {self.name} is {self.operating_state.name}") return False # if there are no connections - nothing to disconnect - if not len(self.connections): + if not self._server_connection_id: self.sys_log.error(f"Unable to disconnect - {self.name} has no active connections.") return False # if no connection provided, disconnect the first connection - if not connection_id: - connection_id = list(self.connections.keys())[0] - software_manager: SoftwareManager = self.software_manager software_manager.send_payload_to_session_manager( - payload={"type": "disconnect", "connection_id": connection_id}, + payload={"type": "disconnect", "connection_id": self._server_connection_id}, dest_ip_address=self.server_ip_address, dest_port=self.port, ) - self.remove_connection(connection_id=connection_id) + self.remove_connection(connection_id=self._server_connection_id) self.sys_log.info( - f"{self.name}: DatabaseClient disconnected connection {connection_id} from {self.server_ip_address}" + f"{self.name}: DatabaseClient disconnected {self._server_connection_id} from {self.server_ip_address}" ) self.connected = False @@ -224,18 +225,20 @@ class DatabaseClient(Application): # reset last query response self.last_query_response = None - if connection_id is None: - if self.connections: - connection_id = list(self.connections.keys())[-1] - # TODO: if the most recent connection dies, it should be automatically cleared. - else: - connection_id = str(uuid4()) + connection_id: str - if not self.connections.get(connection_id): - if not self.connect(connection_id=connection_id): - return False + if not connection_id: + connection_id = self._server_connection_id + + if not connection_id: + self.connect() + connection_id = self._server_connection_id + + if not connection_id: + msg = "Cannot run sql query, could not establish connection with the server." + self.parent.sys_log(msg) + return False - # Initialise the tracker of this ID to False uuid = str(uuid4()) self._query_success_tracker[uuid] = False return self._query(sql=sql, query_id=uuid, connection_id=connection_id) diff --git a/src/primaite/simulator/system/applications/red_applications/ransomware_script.py b/src/primaite/simulator/system/applications/red_applications/ransomware_script.py new file mode 100644 index 00000000..54880271 --- /dev/null +++ b/src/primaite/simulator/system/applications/red_applications/ransomware_script.py @@ -0,0 +1,316 @@ +from enum import IntEnum +from ipaddress import IPv4Address +from typing import Dict, Optional + +from primaite import getLogger +from primaite.game.science import simulate_trial +from primaite.interface.request import RequestResponse +from primaite.simulator.core import RequestManager, RequestType +from primaite.simulator.network.transmission.network_layer import IPProtocol +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import Application +from primaite.simulator.system.applications.database_client import DatabaseClient + +_LOGGER = getLogger(__name__) + + +class RansomwareAttackStage(IntEnum): + """ + Enumeration representing different attack stages of the ransomware script. + + This enumeration defines the various stages a data manipulation attack can be in during its lifecycle + in the simulation. + Each stage represents a specific phase in the attack process. + """ + + NOT_STARTED = 0 + "Indicates that the attack has not started yet." + DOWNLOAD = 1 + "Installing the Encryption Script - Testing" + INSTALL = 2 + "The stage where logon procedures are simulated." + ACTIVATE = 3 + "Operating Status Changes" + PROPAGATE = 4 + "Represents the stage of performing a horizontal port scan on the target." + COMMAND_AND_CONTROL = 5 + "Represents the stage of setting up a rely C2 Beacon (Not Implemented)" + PAYLOAD = 6 + "Stage of actively attacking the target." + SUCCEEDED = 7 + "Indicates the attack has been successfully completed." + FAILED = 8 + "Signifies that the attack has failed." + + +class RansomwareScript(Application): + """Ransomware Kill Chain - Designed to be used by the TAP001 Agent on the example layout Network. + + :ivar payload: The attack stage query payload. (Default Corrupt) + :ivar target_scan_p_of_success: The probability of success for the target scan stage. + :ivar c2_beacon_p_of_success: The probability of success for the c2_beacon stage + :ivar ransomware_encrypt_p_of_success: The probability of success for the ransomware 'attack' (encrypt) stage. + :ivar repeat: Whether to repeat attacking once finished. + """ + + server_ip_address: Optional[IPv4Address] = None + """IP address of node which hosts the database.""" + server_password: Optional[str] = None + """Password required to access the database.""" + payload: Optional[str] = "ENCRYPT" + "Payload String for the payload stage" + target_scan_p_of_success: float = 0.9 + "Probability of the target scan succeeding: Default 0.9" + c2_beacon_p_of_success: float = 0.9 + "Probability of the c2 beacon setup stage succeeding: Default 0.9" + ransomware_encrypt_p_of_success: float = 0.9 + "Probability of the ransomware attack succeeding: Default 0.9" + repeat: bool = False + "If true, the Denial of Service bot will keep performing the attack." + attack_stage: RansomwareAttackStage = RansomwareAttackStage.NOT_STARTED + "The ransomware attack stage. See RansomwareAttackStage Class" + + def __init__(self, **kwargs): + kwargs["name"] = "RansomwareScript" + kwargs["port"] = Port.NONE + kwargs["protocol"] = IPProtocol.NONE + + super().__init__(**kwargs) + + def describe_state(self) -> Dict: + """ + Produce a dictionary describing the current state of this object. + + Please see :py:meth:`primaite.simulator.core.SimComponent.describe_state` for a more detailed explanation. + + :return: Current state of this object and child objects. + :rtype: Dict + """ + state = super().describe_state() + return state + + @property + def _host_db_client(self) -> DatabaseClient: + """Return the database client that is installed on the same machine as the Ransomware Script.""" + db_client = self.software_manager.software.get("DatabaseClient") + if db_client is None: + _LOGGER.info(f"{self.__class__.__name__} cannot find a database client on its host.") + return db_client + + def _init_request_manager(self) -> RequestManager: + """ + Initialise the request manager. + + More information in user guide and docstring for SimComponent._init_request_manager. + """ + rm = super()._init_request_manager() + rm.add_request( + name="execute", + request_type=RequestType(func=lambda request, context: RequestResponse.from_bool(self.attack())), + ) + return rm + + def _activate(self): + """ + Simulate the install process as the initial stage of the attack. + + Advances the attack stage to 'ACTIVATE' attack state. + """ + if self.attack_stage == RansomwareAttackStage.INSTALL: + self.sys_log.info(f"{self.name}: Activated!") + self.attack_stage = RansomwareAttackStage.ACTIVATE + + def apply_timestep(self, timestep: int) -> None: + """ + Apply a timestep to the bot, triggering the application loop. + + :param timestep: The timestep value to update the bot's state. + """ + pass + + def run(self) -> bool: + """Calls the parent classes execute method before starting the application loop.""" + super().run() + return True + + def _application_loop(self) -> bool: + """ + The main application loop of the script, handling the attack process. + + This is the core loop where the bot sequentially goes through the stages of the attack. + """ + if not self._can_perform_action(): + return False + if self.server_ip_address and self.payload: + self.sys_log.info(f"{self.name}: Running") + self.attack_stage = RansomwareAttackStage.NOT_STARTED + self._local_download() + self._install() + self._activate() + self._perform_target_scan() + self._setup_beacon() + self._perform_ransomware_encrypt() + + if self.repeat and self.attack_stage in ( + RansomwareAttackStage.SUCCEEDED, + RansomwareAttackStage.FAILED, + ): + self.attack_stage = RansomwareAttackStage.NOT_STARTED + return True + else: + self.sys_log.error(f"{self.name}: Failed to start as it requires both a target_ip_address and payload.") + return False + + def configure( + self, + server_ip_address: IPv4Address, + server_password: Optional[str] = None, + payload: Optional[str] = None, + target_scan_p_of_success: Optional[float] = None, + c2_beacon_p_of_success: Optional[float] = None, + ransomware_encrypt_p_of_success: Optional[float] = None, + repeat: bool = True, + ): + """ + Configure the Ransomware Script to communicate with a DatabaseService. + + :param server_ip_address: The IP address of the Node the DatabaseService is on. + :param server_password: The password on the DatabaseService. + :param payload: The attack stage query (Encrypt / Delete) + :param target_scan_p_of_success: The probability of success for the target scan stage. + :param c2_beacon_p_of_success: The probability of success for the c2_beacon stage + :param ransomware_encrypt_p_of_success: The probability of success for the ransomware 'attack' (encrypt) stage. + :param repeat: Whether to repeat attacking once finished. + """ + if server_ip_address: + self.server_ip_address = server_ip_address + if server_password: + self.server_password = server_password + if payload: + self.payload = payload + if target_scan_p_of_success: + self.target_scan_p_of_success = target_scan_p_of_success + if c2_beacon_p_of_success: + self.c2_beacon_p_of_success = c2_beacon_p_of_success + if ransomware_encrypt_p_of_success: + self.ransomware_encrypt_p_of_success = ransomware_encrypt_p_of_success + if repeat: + self.repeat = repeat + self.sys_log.info( + f"{self.name}: Configured the {self.name} with {server_ip_address=}, {payload=}, {server_password=}, " + f"{repeat=}." + ) + + def _install(self): + """ + Simulate the install stage in the kill-chain. + + Advances the attack stage to 'ACTIVATE' if successful. + + From this attack stage onwards. + the ransomware application is now visible from this point onwardin the observation space. + """ + if self.attack_stage == RansomwareAttackStage.DOWNLOAD: + self.sys_log.info(f"{self.name}: Malware installed on the local file system") + downloads_folder = self.file_system.get_folder(folder_name="downloads") + ransomware_file = downloads_folder.get_file(file_name="ransom_script.pdf") + ransomware_file.num_access += 1 + self.attack_stage = RansomwareAttackStage.INSTALL + + def _setup_beacon(self): + """ + Simulates setting up a c2 beacon; currently a pseudo step for increasing red variance. + + Advances the attack stage to 'COMMAND AND CONTROL` if successful. + + :param p_of_sucess: Probability of a successful c2 setup (Advancing this step), + by default the success rate is 0.5 + """ + if self.attack_stage == RansomwareAttackStage.PROPAGATE: + self.sys_log.info(f"{self.name} Attempting to set up C&C Beacon - Scan 1/2") + if simulate_trial(self.c2_beacon_p_of_success): + self.sys_log.info(f"{self.name} C&C Successful setup - Scan 2/2") + c2c_setup = True # TODO Implement the c2c step via an FTP Application/Service + if c2c_setup: + self.attack_stage = RansomwareAttackStage.COMMAND_AND_CONTROL + + def _perform_target_scan(self): + """ + Perform a simulated port scan to check for open SQL ports. + + Advances the attack stage to `PROPAGATE` if successful. + + :param p_of_success: Probability of successful port scan, by default 0.1. + """ + if self.attack_stage == RansomwareAttackStage.ACTIVATE: + # perform a port scan to identify that the SQL port is open on the server + self.sys_log.info(f"{self.name}: Scanning for vulnerable databases - Scan 0/2") + if simulate_trial(self.target_scan_p_of_success): + self.sys_log.info(f"{self.name}: Found a target database! Scan 1/2") + port_is_open = True # TODO Implement a NNME Triggering scan as a seperate Red Application + if port_is_open: + self.attack_stage = RansomwareAttackStage.PROPAGATE + + def attack(self) -> bool: + """Perform the attack steps after opening the application.""" + if not self._can_perform_action(): + _LOGGER.debug("Ransomware application is unable to perform it's actions.") + self.run() + self.num_executions += 1 + return self._application_loop() + + def _perform_ransomware_encrypt(self): + """ + Execute the Ransomware Encrypt payload on the target. + + Advances the attack stage to `COMPLETE` if successful, or 'FAILED' if unsuccessful. + :param p_of_success: Probability of successfully performing ransomware encryption, by default 0.1. + """ + if self._host_db_client is None: + self.sys_log.info(f"{self.name}: Failed to connect to db_client - Ransomware Script") + self.attack_stage = RansomwareAttackStage.FAILED + return + + self._host_db_client.server_ip_address = self.server_ip_address + self._host_db_client.server_password = self.server_password + if self.attack_stage == RansomwareAttackStage.COMMAND_AND_CONTROL: + if simulate_trial(self.ransomware_encrypt_p_of_success): + self.sys_log.info(f"{self.name}: Attempting to launch payload") + if not len(self._host_db_client.connections): + self._host_db_client.connect() + if len(self._host_db_client.connections): + self._host_db_client.query(self.payload) + self.sys_log.info(f"{self.name} Payload delivered: {self.payload}") + attack_successful = True + if attack_successful: + self.sys_log.info(f"{self.name}: Payload Successful") + self.attack_stage = RansomwareAttackStage.SUCCEEDED + else: + self.sys_log.info(f"{self.name}: Payload failed") + self.attack_stage = RansomwareAttackStage.FAILED + else: + self.sys_log.error("Attack Attempted to launch too quickly") + self.attack_stage = RansomwareAttackStage.FAILED + + def _local_download(self): + """Downloads itself via the onto the local file_system.""" + if self.attack_stage == RansomwareAttackStage.NOT_STARTED: + if self._local_download_verify(): + self.attack_stage = RansomwareAttackStage.DOWNLOAD + else: + self.sys_log.info("Malware failed to create a installation location") + self.attack_stage = RansomwareAttackStage.FAILED + else: + self.sys_log.info("Malware failed to download") + self.attack_stage = RansomwareAttackStage.FAILED + + def _local_download_verify(self) -> bool: + """Verifies a download location - Creates one if needed.""" + for folder in self.file_system.folders: + if self.file_system.folders[folder].name == "downloads": + self.file_system.num_file_creations += 1 + return True + + self.file_system.create_folder("downloads") + self.file_system.create_file(folder_name="downloads", file_name="ransom_script.pdf") + return True diff --git a/src/primaite/simulator/system/core/sys_log.py b/src/primaite/simulator/system/core/sys_log.py index 414bacef..c10f7d3c 100644 --- a/src/primaite/simulator/system/core/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -88,6 +88,10 @@ class SysLog: root.mkdir(exist_ok=True, parents=True) return root / f"{self.hostname}_sys.log" + def _write_to_terminal(self, msg: str, level: str, to_terminal: bool = False): + if to_terminal or SIM_OUTPUT.write_sys_log_to_terminal: + print(f"{self.hostname}: ({level}) {msg}") + def debug(self, msg: str, to_terminal: bool = False): """ Logs a message with the DEBUG level. @@ -97,8 +101,7 @@ class SysLog: """ if SIM_OUTPUT.save_sys_logs: self.logger.debug(msg) - if to_terminal: - print(msg) + self._write_to_terminal(msg, "DEBUG", to_terminal) def info(self, msg: str, to_terminal: bool = False): """ @@ -109,8 +112,7 @@ class SysLog: """ if SIM_OUTPUT.save_sys_logs: self.logger.info(msg) - if to_terminal: - print(msg) + self._write_to_terminal(msg, "INFO", to_terminal) def warning(self, msg: str, to_terminal: bool = False): """ @@ -121,8 +123,7 @@ class SysLog: """ if SIM_OUTPUT.save_sys_logs: self.logger.warning(msg) - if to_terminal: - print(msg) + self._write_to_terminal(msg, "WARNING", to_terminal) def error(self, msg: str, to_terminal: bool = False): """ @@ -133,8 +134,7 @@ class SysLog: """ if SIM_OUTPUT.save_sys_logs: self.logger.error(msg) - if to_terminal: - print(msg) + self._write_to_terminal(msg, "ERROR", to_terminal) def critical(self, msg: str, to_terminal: bool = False): """ @@ -145,5 +145,4 @@ class SysLog: """ if SIM_OUTPUT.save_sys_logs: self.logger.critical(msg) - if to_terminal: - print(msg) + self._write_to_terminal(msg, "CRITICAL", to_terminal) diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 321d9088..833b1fa5 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -141,8 +141,7 @@ class DatabaseService(Service): """Returns the database file.""" return self.file_system.get_file(folder_name="database", file_name="database.db") - @property - def folder(self) -> Folder: + def _return_database_folder(self) -> Folder: """Returns the database folder.""" return self.file_system.get_folder_by_id(self.db_file.folder_id) @@ -187,7 +186,10 @@ class DatabaseService(Service): } def _process_sql( - self, query: Literal["SELECT", "DELETE", "INSERT"], query_id: str, connection_id: Optional[str] = None + self, + query: Literal["SELECT", "DELETE", "INSERT", "ENCRYPT"], + query_id: str, + connection_id: Optional[str] = None, ) -> Dict[str, Union[int, List[Any]]]: """ Executes the given SQL query and returns the result. @@ -196,6 +198,7 @@ class DatabaseService(Service): - SELECT : returns the data - DELETE : deletes the data - INSERT : inserts the data + - ENCRYPT : corrupts the data :param query: The SQL query to be executed. :return: Dictionary containing status code and data fetched. @@ -207,7 +210,15 @@ class DatabaseService(Service): return {"status_code": 404, "type": "sql", "data": False} if query == "SELECT": - if self.db_file.health_status == FileSystemItemHealthStatus.GOOD: + if self.db_file.health_status == FileSystemItemHealthStatus.CORRUPT: + return { + "status_code": 200, + "type": "sql", + "data": False, + "uuid": query_id, + "connection_id": connection_id, + } + elif self.db_file.health_status == FileSystemItemHealthStatus.GOOD: return { "status_code": 200, "type": "sql", @@ -226,6 +237,20 @@ class DatabaseService(Service): "uuid": query_id, "connection_id": connection_id, } + elif query == "ENCRYPT": + self.file_system.num_file_creations += 1 + self.db_file.health_status = FileSystemItemHealthStatus.CORRUPT + self.db_file.num_access += 1 + database_folder = self._return_database_folder() + database_folder.health_status = FileSystemItemHealthStatus.CORRUPT + self.file_system.num_file_deletions += 1 + return { + "status_code": 200, + "type": "sql", + "data": False, + "uuid": query_id, + "connection_id": connection_id, + } elif query == "INSERT": if self.health_state_actual == SoftwareHealthState.GOOD: return { diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index ad00065c..fe351dba 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -87,13 +87,9 @@ class NTPClient(Service): :return: True if successful, False otherwise. """ if not isinstance(payload, NTPPacket): - _LOGGER.debug(f"{payload} is not a NTPPacket") + _LOGGER.debug(f"{self.name}: Failed to parse NTP update") return False if payload.ntp_reply.ntp_datetime: - self.sys_log.info( - f"{self.name}: \ - Received time update from NTP server{payload.ntp_reply.ntp_datetime}" - ) self.time = payload.ntp_reply.ntp_datetime return True @@ -124,5 +120,3 @@ class NTPClient(Service): if self.operating_state == ServiceOperatingState.RUNNING: # request time from server self.request_time() - else: - self.sys_log.debug(f"{self.name} ntp client not running") diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 3ab32bc6..50c96c17 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -224,6 +224,10 @@ class Software(SimComponent): if self.health_state_actual == SoftwareHealthState.FIXING: self._update_fix_status() + def pre_timestep(self, timestep: int) -> None: + """Apply pre-timestep logic.""" + super().pre_timestep(timestep) + class IOSoftware(Software): """ diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 7d85ea9f..18b86bf3 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -303,6 +303,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "ROUTER_ACL_ADDRULE" options: @@ -314,6 +316,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 24: # block tcp traffic from client 1 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -325,6 +329,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 25: # block tcp traffic from client 2 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -336,6 +342,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 26: action: "ROUTER_ACL_ADDRULE" options: @@ -347,6 +355,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 27: action: "ROUTER_ACL_ADDRULE" options: @@ -358,6 +368,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 28: action: "ROUTER_ACL_REMOVERULE" options: @@ -505,23 +517,15 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 - ip_address_order: - - node_name: domain_controller - nic_num: 1 - - node_name: web_server - nic_num: 1 - - node_name: database_server - nic_num: 1 - - node_name: backup_server - nic_num: 1 - - node_name: security_suite - nic_num: 1 - - node_name: client_1 - nic_num: 1 - - node_name: client_2 - nic_num: 1 - - node_name: security_suite - nic_num: 2 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 reward_function: reward_components: diff --git a/tests/assets/configs/basic_firewall.yaml b/tests/assets/configs/basic_firewall.yaml index 0512fbe1..0253a4d2 100644 --- a/tests/assets/configs/basic_firewall.yaml +++ b/tests/assets/configs/basic_firewall.yaml @@ -5,21 +5,7 @@ # -------------- -------------- -------------- # -training_config: - rl_framework: SB3 - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 1 - n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: - - defender - io_settings: - save_checkpoints: true - checkpoint_interval: 5 save_step_metadata: false save_pcap_logs: true save_sys_logs: true diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index bbc45de2..15dd377e 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -4,22 +4,7 @@ # | client_1 |------| switch_1 |------| client_2 | # -------------- -------------- -------------- # - -training_config: - rl_framework: SB3 - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 1 - n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: - - defender - io_settings: - save_checkpoints: true - checkpoint_interval: 5 save_step_metadata: false save_pcap_logs: true save_sys_logs: true diff --git a/tests/assets/configs/dmz_network.yaml b/tests/assets/configs/dmz_network.yaml index 2ce722f7..52316260 100644 --- a/tests/assets/configs/dmz_network.yaml +++ b/tests/assets/configs/dmz_network.yaml @@ -30,21 +30,7 @@ # | external_computer |------| switch_3 |------| external_server | # ----------------------- -------------- --------------------- # -training_config: - rl_framework: SB3 - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 1 - n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: - - defender - io_settings: - save_checkpoints: true - checkpoint_interval: 5 save_step_metadata: false save_pcap_logs: true save_sys_logs: true diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index f05e3390..eab0720a 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -319,6 +319,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "ROUTER_ACL_ADDRULE" options: @@ -330,6 +332,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 24: # block tcp traffic from client 1 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -341,6 +345,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 25: # block tcp traffic from client 2 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -352,6 +358,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 26: action: "ROUTER_ACL_ADDRULE" options: @@ -363,6 +371,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 27: action: "ROUTER_ACL_ADDRULE" options: @@ -374,6 +384,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 28: action: "ROUTER_ACL_REMOVERULE" options: @@ -521,23 +533,15 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 - ip_address_order: - - node_name: domain_controller - nic_num: 1 - - node_name: web_server - nic_num: 1 - - node_name: database_server - nic_num: 1 - - node_name: backup_server - nic_num: 1 - - node_name: security_suite - nic_num: 1 - - node_name: client_1 - nic_num: 1 - - node_name: client_2 - nic_num: 1 - - node_name: security_suite - nic_num: 2 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 reward_function: reward_components: diff --git a/tests/assets/configs/firewall_actions_network.yaml b/tests/assets/configs/firewall_actions_network.yaml index 1f4a45e0..fdf29599 100644 --- a/tests/assets/configs/firewall_actions_network.yaml +++ b/tests/assets/configs/firewall_actions_network.yaml @@ -106,25 +106,6 @@ agents: label: ICS options: {} - # observation_space: - # type: UC2BlueObservation - # options: - # num_services_per_node: 1 - # num_folders_per_node: 1 - # num_files_per_folder: 1 - # num_nics_per_node: 2 - # nodes: - # - node_hostname: client_1 - # links: - # - link_ref: client_1___switch_1 - # acl: - # options: - # max_acl_rules: 10 - # router_hostname: router_1 - # ip_address_order: - # - node_hostname: client_1 - # nic_num: 1 - # ics: null action_space: action_list: - type: DONOTHING @@ -149,6 +130,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 2: action: FIREWALL_ACL_REMOVERULE options: @@ -169,6 +152,8 @@ agents: source_port_id: 2 dest_port_id: 3 protocol_id: 2 + source_wildcard_id: 0 + dest_wildcard_id: 0 4: action: FIREWALL_ACL_REMOVERULE options: @@ -189,6 +174,8 @@ agents: source_port_id: 4 dest_port_id: 4 protocol_id: 4 + source_wildcard_id: 0 + dest_wildcard_id: 0 6: action: FIREWALL_ACL_REMOVERULE options: @@ -209,6 +196,8 @@ agents: source_port_id: 4 dest_port_id: 4 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 8: action: FIREWALL_ACL_REMOVERULE options: @@ -229,6 +218,8 @@ agents: source_port_id: 5 dest_port_id: 5 protocol_id: 2 + source_wildcard_id: 0 + dest_wildcard_id: 0 10: action: FIREWALL_ACL_REMOVERULE options: @@ -249,6 +240,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 12: action: FIREWALL_ACL_REMOVERULE options: @@ -271,13 +264,10 @@ agents: - node_name: client_1 - node_name: dmz_server - node_name: external_computer - ip_address_order: - - node_name: client_1 - nic_num: 1 - - node_name: dmz_server - nic_num: 1 - - node_name: external_computer - nic_num: 1 + ip_list: + - 192.168.0.10 + - 192.168.10.10 + - 192.168.20.10 max_folders_per_node: 2 max_files_per_folder: 2 max_services_per_node: 2 diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 6a37be80..0b0685c0 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -314,6 +314,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "ROUTER_ACL_ADDRULE" options: @@ -325,6 +327,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 24: # block tcp traffic from client 1 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -336,6 +340,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 25: # block tcp traffic from client 2 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -347,6 +353,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 26: action: "ROUTER_ACL_ADDRULE" options: @@ -358,6 +366,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 27: action: "ROUTER_ACL_ADDRULE" options: @@ -369,6 +379,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 28: action: "ROUTER_ACL_REMOVERULE" options: @@ -516,23 +528,15 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 - ip_address_order: - - node_name: domain_controller - nic_num: 1 - - node_name: web_server - nic_num: 1 - - node_name: database_server - nic_num: 1 - - node_name: backup_server - nic_num: 1 - - node_name: security_suite - nic_num: 1 - - node_name: client_1 - nic_num: 1 - - node_name: client_2 - nic_num: 1 - - node_name: security_suite - nic_num: 2 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 reward_function: reward_components: @@ -780,6 +784,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "ROUTER_ACL_ADDRULE" options: @@ -791,6 +797,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 24: # block tcp traffic from client 1 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -802,6 +810,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 25: # block tcp traffic from client 2 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -813,6 +823,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 26: action: "ROUTER_ACL_ADDRULE" options: @@ -824,6 +836,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 27: action: "ROUTER_ACL_ADDRULE" options: @@ -835,6 +849,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 28: action: "ROUTER_ACL_REMOVERULE" options: @@ -981,23 +997,15 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 - ip_address_order: - - node_name: domain_controller - nic_num: 1 - - node_name: web_server - nic_num: 1 - - node_name: database_server - nic_num: 1 - - node_name: backup_server - nic_num: 1 - - node_name: security_suite - nic_num: 1 - - node_name: client_1 - nic_num: 1 - - node_name: client_2 - nic_num: 1 - - node_name: security_suite - nic_num: 2 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 reward_function: reward_components: diff --git a/tests/assets/configs/no_nodes_links_agents_network.yaml b/tests/assets/configs/no_nodes_links_agents_network.yaml index 607a899a..b20835bc 100644 --- a/tests/assets/configs/no_nodes_links_agents_network.yaml +++ b/tests/assets/configs/no_nodes_links_agents_network.yaml @@ -1,18 +1,4 @@ -training_config: - rl_framework: SB3 - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 1 - n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: - - defender - io_settings: - save_checkpoints: true - checkpoint_interval: 5 save_step_metadata: false save_pcap_logs: true save_sys_logs: true diff --git a/tests/assets/configs/shared_rewards.yaml b/tests/assets/configs/shared_rewards.yaml index bfa03ace..c5ba06b1 100644 --- a/tests/assets/configs/shared_rewards.yaml +++ b/tests/assets/configs/shared_rewards.yaml @@ -131,10 +131,6 @@ agents: options: node_hostname: client_1 - - - - - ref: data_manipulation_attacker team: RED type: RedDatabaseCorruptingAgent @@ -490,6 +486,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" action: "ROUTER_ACL_ADDRULE" options: @@ -501,6 +499,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 48: # old action num: 24 # block tcp traffic from client 1 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -512,6 +512,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 49: # old action num: 25 # block tcp traffic from client 2 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -523,6 +525,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 50: # old action num: 26 action: "ROUTER_ACL_ADDRULE" options: @@ -534,6 +538,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 51: # old action num: 27 action: "ROUTER_ACL_ADDRULE" options: @@ -545,6 +551,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 52: # old action num: 28 action: "ROUTER_ACL_REMOVERULE" options: @@ -703,23 +711,15 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 - ip_address_order: - - node_name: domain_controller - nic_num: 1 - - node_name: web_server - nic_num: 1 - - node_name: database_server - nic_num: 1 - - node_name: backup_server - nic_num: 1 - - node_name: security_suite - nic_num: 1 - - node_name: client_1 - nic_num: 1 - - node_name: client_2 - nic_num: 1 - - node_name: security_suite - nic_num: 2 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 reward_function: diff --git a/tests/assets/configs/test_application_install.yaml b/tests/assets/configs/test_application_install.yaml index 3323937e..d1fed272 100644 --- a/tests/assets/configs/test_application_install.yaml +++ b/tests/assets/configs/test_application_install.yaml @@ -493,6 +493,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" action: "ROUTER_ACL_ADDRULE" options: @@ -504,6 +506,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 48: # old action num: 24 # block tcp traffic from client 1 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -515,6 +519,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 49: # old action num: 25 # block tcp traffic from client 2 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -526,6 +532,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 50: # old action num: 26 action: "ROUTER_ACL_ADDRULE" options: @@ -537,6 +545,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 51: # old action num: 27 action: "ROUTER_ACL_ADDRULE" options: @@ -548,6 +558,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 52: # old action num: 28 action: "ROUTER_ACL_REMOVERULE" options: @@ -729,23 +741,15 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 - ip_address_order: - - node_name: domain_controller - nic_num: 1 - - node_name: web_server - nic_num: 1 - - node_name: database_server - nic_num: 1 - - node_name: backup_server - nic_num: 1 - - node_name: security_suite - nic_num: 1 - - node_name: client_1 - nic_num: 1 - - node_name: client_2 - nic_num: 1 - - node_name: security_suite - nic_num: 2 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 reward_function: diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 9284f1d1..490e99d4 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -327,6 +327,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "ROUTER_ACL_ADDRULE" options: @@ -338,6 +340,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 24: # block tcp traffic from client 1 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -349,6 +353,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 25: # block tcp traffic from client 2 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -360,6 +366,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 26: action: "ROUTER_ACL_ADDRULE" options: @@ -371,6 +379,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 27: action: "ROUTER_ACL_ADDRULE" options: @@ -382,6 +392,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 28: action: "ROUTER_ACL_REMOVERULE" options: @@ -528,23 +540,15 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 - ip_address_order: - - node_name: domain_controller - nic_num: 1 - - node_name: web_server - nic_num: 1 - - node_name: database_server - nic_num: 1 - - node_name: backup_server - nic_num: 1 - - node_name: security_suite - nic_num: 1 - - node_name: client_1 - nic_num: 1 - - node_name: client_2 - nic_num: 1 - - node_name: security_suite - nic_num: 2 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 reward_function: reward_components: diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml index 7d1ac09f..3de2c80a 100644 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ b/tests/assets/configs/train_only_primaite_session.yaml @@ -327,6 +327,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) action: "ROUTER_ACL_ADDRULE" options: @@ -338,6 +340,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 24: # block tcp traffic from client 1 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -349,6 +353,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 25: # block tcp traffic from client 2 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -360,6 +366,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 26: action: "ROUTER_ACL_ADDRULE" options: @@ -371,6 +379,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 27: action: "ROUTER_ACL_ADDRULE" options: @@ -382,6 +392,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 28: action: "ROUTER_ACL_REMOVERULE" options: @@ -528,23 +540,15 @@ agents: max_services_per_node: 2 max_nics_per_node: 8 max_acl_rules: 10 - ip_address_order: - - node_name: domain_controller - nic_num: 1 - - node_name: web_server - nic_num: 1 - - node_name: database_server - nic_num: 1 - - node_name: backup_server - nic_num: 1 - - node_name: security_suite - nic_num: 1 - - node_name: client_1 - nic_num: 1 - - node_name: client_2 - nic_num: 1 - - node_name: security_suite - nic_num: 2 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 reward_function: reward_components: diff --git a/tests/conftest.py b/tests/conftest.py index f5b5cb1b..018dcb70 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -50,8 +50,8 @@ def set_syslog_output_to_true(): "path", Path(TEST_ASSETS_ROOT.parent.parent / "simulation_output" / datetime.now().strftime("%Y-%m-%d_%H-%M-%S")), ) - monkeypatch.setattr(SIM_OUTPUT, "save_pcap_logs", True) - monkeypatch.setattr(SIM_OUTPUT, "save_sys_logs", True) + monkeypatch.setattr(SIM_OUTPUT, "save_pcap_logs", False) + monkeypatch.setattr(SIM_OUTPUT, "save_sys_logs", False) yield @@ -529,7 +529,7 @@ def game_and_agent(): max_acl_rules=10, protocols=["TCP", "UDP", "ICMP"], ports=["HTTP", "DNS", "ARP"], - ip_address_list=["10.0.1.1", "10.0.1.2", "10.0.2.1", "10.0.2.2", "10.0.2.3"], + ip_list=["10.0.1.1", "10.0.1.2", "10.0.2.1", "10.0.2.2", "10.0.2.3"], act_map={}, ) observation_space = ObservationManager(NestedObservation(components={})) diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 3ebce6ad..855bc38d 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -130,6 +130,8 @@ def test_router_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Prox "dest_port_id": 1, # ALL "source_port_id": 1, # ALL "protocol_id": 1, # ALL + "source_wildcard_id": 0, + "dest_wildcard_id": 0, }, ) agent.store_action(action) @@ -155,6 +157,8 @@ def test_router_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Prox "dest_port_id": 1, # ALL "source_port_id": 1, # ALL "protocol_id": 1, # ALL + "source_wildcard_id": 0, + "dest_wildcard_id": 0, }, ) agent.store_action(action) diff --git a/tests/integration_tests/network/test_capture_nmne.py b/tests/integration_tests/network/test_capture_nmne.py index 6601831f..1f9a35d9 100644 --- a/tests/integration_tests/network/test_capture_nmne.py +++ b/tests/integration_tests/network/test_capture_nmne.py @@ -22,10 +22,13 @@ def test_capture_nmne(uc2_network): web_server_nic = web_server.network_interface[1] db_server_nic = db_server.network_interface[1] - # Set the NMNE configuration to capture DELETE queries as MNEs + # Set the NMNE configuration to capture DELETE/ENCRYPT queries as MNEs nmne_config = { "capture_nmne": True, # Enable the capture of MNEs - "nmne_capture_keywords": ["DELETE"], # Specify "DELETE" SQL command as a keyword for MNE detection + "nmne_capture_keywords": [ + "DELETE", + "ENCRYPT", + ], # Specify "DELETE/ENCRYPT" SQL command as a keyword for MNE detection } # Apply the NMNE configuration settings @@ -63,6 +66,20 @@ def test_capture_nmne(uc2_network): assert web_server_nic.nmne == {"direction": {"outbound": {"keywords": {"*": 2}}}} assert db_server_nic.nmne == {"direction": {"inbound": {"keywords": {"*": 2}}}} + # Perform an "ENCRYPT" query + db_client.query("ENCRYPT") + + # Check that the web server and database server interfaces register an additional MNE + assert web_server_nic.nmne == {"direction": {"outbound": {"keywords": {"*": 3}}}} + assert db_server_nic.nmne == {"direction": {"inbound": {"keywords": {"*": 3}}}} + + # Perform another "SELECT" query + db_client.query("SELECT") + + # Check that no additional MNEs are captured + assert web_server_nic.nmne == {"direction": {"outbound": {"keywords": {"*": 3}}}} + assert db_server_nic.nmne == {"direction": {"inbound": {"keywords": {"*": 3}}}} + def test_describe_state_nmne(uc2_network): """ @@ -70,7 +87,7 @@ def test_describe_state_nmne(uc2_network): This test involves a web server querying a database server and checks if the MNEs are captured based on predefined keywords in the network configuration. Specifically, it checks the capture - of the "DELETE" SQL command as a malicious network event. It also checks that running describe_state + of the "DELETE" / "ENCRYPT" SQL commands as a malicious network event. It also checks that running describe_state only shows MNEs since the last time describe_state was called. """ web_server: Server = uc2_network.get_node_by_hostname("web_server") # noqa @@ -82,10 +99,13 @@ def test_describe_state_nmne(uc2_network): web_server_nic = web_server.network_interface[1] db_server_nic = db_server.network_interface[1] - # Set the NMNE configuration to capture DELETE queries as MNEs + # Set the NMNE configuration to capture DELETE/ENCRYPT queries as MNEs nmne_config = { "capture_nmne": True, # Enable the capture of MNEs - "nmne_capture_keywords": ["DELETE"], # Specify "DELETE" SQL command as a keyword for MNE detection + "nmne_capture_keywords": [ + "DELETE", + "ENCRYPT", + ], # "DELETE" & "ENCRYPT" SQL commands as a keywords for MNE detection } # Apply the NMNE configuration settings @@ -138,6 +158,36 @@ def test_describe_state_nmne(uc2_network): assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 2}}}} assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 2}}}} + # Perform a "ENCRYPT" query + db_client.query("ENCRYPT") + + # Check that the web server's outbound interface and the database server's inbound interface register the MNE + web_server_nic_state = web_server_nic.describe_state() + db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) + assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 3}}}} + assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 3}}}} + + # Perform another "SELECT" query + db_client.query("SELECT") + + # Check that no additional MNEs are captured + web_server_nic_state = web_server_nic.describe_state() + db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) + assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 3}}}} + assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 3}}}} + + # Perform another "ENCRYPT" + db_client.query("ENCRYPT") + + # Check that the web server and database server interfaces register an additional MNE + web_server_nic_state = web_server_nic.describe_state() + db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) + assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 4}}}} + assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 4}}}} + def test_capture_nmne_observations(uc2_network): """ @@ -146,7 +196,7 @@ def test_capture_nmne_observations(uc2_network): This test ensures the observation space, as defined by instances of NICObservation, accurately reflects the number of MNEs detected based on network activities over multiple iterations. - The test employs a series of "DELETE" SQL operations, considered as MNEs, to validate the dynamic update + The test employs a series of "DELETE" and "ENCRYPT" SQL operations, considered as MNEs, to validate the dynamic update and accuracy of the observation space related to network interface conditions. It confirms that the observed NIC states match expected MNE activity levels. """ @@ -158,10 +208,13 @@ def test_capture_nmne_observations(uc2_network): db_client: DatabaseClient = web_server.software_manager.software["DatabaseClient"] db_client.connect() - # Set the NMNE configuration to capture DELETE queries as MNEs + # Set the NMNE configuration to capture DELETE/ENCRYPT queries as MNEs nmne_config = { "capture_nmne": True, # Enable the capture of MNEs - "nmne_capture_keywords": ["DELETE"], # Specify "DELETE" SQL command as a keyword for MNE detection + "nmne_capture_keywords": [ + "DELETE", + "ENCRYPT", + ], # Specify "DELETE" & "ENCRYPT" SQL commands as a keywords for MNE detection } # Apply the NMNE configuration settings @@ -196,3 +249,28 @@ def test_capture_nmne_observations(uc2_network): assert web_nic_obs["outbound"] == expected_nmne assert db_nic_obs["inbound"] == expected_nmne uc2_network.apply_timestep(timestep=0) + + for i in range(0, 20): + # Perform a "ENCRYPT" query each iteration + for j in range(i): + db_client.query("ENCRYPT") + + # Observe the current state of NMNEs from the NICs of both the database and web servers + state = sim.describe_state() + db_nic_obs = db_server_nic_obs.observe(state)["NMNE"] + web_nic_obs = web_server_nic_obs.observe(state)["NMNE"] + + # Define expected NMNE values based on the iteration count + if i > 10: + expected_nmne = 3 # High level of detected MNEs after 10 iterations + elif i > 5: + expected_nmne = 2 # Moderate level after more than 5 iterations + elif i > 0: + expected_nmne = 1 # Low level detected after just starting + else: + expected_nmne = 0 # No MNEs detected + + # Assert that the observed NMNEs match the expected values for both NICs + assert web_nic_obs["outbound"] == expected_nmne + assert db_nic_obs["inbound"] == expected_nmne + uc2_network.apply_timestep(timestep=0) diff --git a/tests/integration_tests/network/test_routing.py b/tests/integration_tests/network/test_routing.py index 869b27be..267b9b53 100644 --- a/tests/integration_tests/network/test_routing.py +++ b/tests/integration_tests/network/test_routing.py @@ -152,6 +152,22 @@ def test_with_routes_can_ping(multi_hop_network): assert pc_a.ping(pc_b.network_interface[1].ip_address) +def test_with_default_routes_can_ping(multi_hop_network): + pc_a = multi_hop_network.get_node_by_hostname("pc_a") + pc_b = multi_hop_network.get_node_by_hostname("pc_b") + + router_1: Router = multi_hop_network.get_node_by_hostname("router_1") # noqa + router_2: Router = multi_hop_network.get_node_by_hostname("router_2") # noqa + + # Configure Route from Router 1 to PC B subnet + router_1.route_table.set_default_route_next_hop_ip_address("192.168.1.2") + + # Configure Route from Router 2 to PC A subnet + router_2.route_table.set_default_route_next_hop_ip_address("192.168.1.1") + + assert pc_a.ping(pc_b.network_interface[1].ip_address) + + def test_ping_router_port_multi_hop(multi_hop_network): pc_a = multi_hop_network.get_node_by_hostname("pc_a") router_2 = multi_hop_network.get_node_by_hostname("router_2") diff --git a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py index e42862bf..8ed10da6 100644 --- a/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py +++ b/tests/integration_tests/system/red_applications/test_dos_bot_and_server.py @@ -73,6 +73,7 @@ def dos_bot_db_server_green_client(example_network) -> Network: return network +@pytest.mark.xfail(reason="Tests fail due to recent changes in how DB connections are handled for example layout.") def test_repeating_dos_attack(dos_bot_and_db_server): dos_bot, computer, db_server_service, server = dos_bot_and_db_server @@ -104,6 +105,7 @@ def test_repeating_dos_attack(dos_bot_and_db_server): assert db_server_service.health_state_actual is SoftwareHealthState.OVERWHELMED +@pytest.mark.xfail(reason="Tests fail due to recent changes in how DB connections are handled for example layout.") def test_non_repeating_dos_attack(dos_bot_and_db_server): dos_bot, computer, db_server_service, server = dos_bot_and_db_server @@ -135,6 +137,7 @@ def test_non_repeating_dos_attack(dos_bot_and_db_server): assert db_server_service.health_state_actual is SoftwareHealthState.GOOD +@pytest.mark.xfail(reason="Tests fail due to recent changes in how DB connections are handled for example layout.") def test_dos_bot_database_service_connection(dos_bot_and_db_server): dos_bot, computer, db_server_service, server = dos_bot_and_db_server @@ -147,6 +150,7 @@ def test_dos_bot_database_service_connection(dos_bot_and_db_server): assert len(dos_bot.connections) == db_server_service.max_sessions +@pytest.mark.xfail(reason="Tests fail due to recent changes in how DB connections are handled for example layout.") def test_dos_blocks_green_agent_connection(dos_bot_db_server_green_client): network: Network = dos_bot_db_server_green_client diff --git a/tests/integration_tests/system/red_applications/test_ransomware_script.py b/tests/integration_tests/system/red_applications/test_ransomware_script.py new file mode 100644 index 00000000..72a444ff --- /dev/null +++ b/tests/integration_tests/system/red_applications/test_ransomware_script.py @@ -0,0 +1,163 @@ +from ipaddress import IPv4Address +from typing import Tuple + +import pytest + +from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus +from primaite.simulator.network.container import Network +from primaite.simulator.network.hardware.nodes.host.computer import Computer +from primaite.simulator.network.hardware.nodes.host.server import Server +from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router +from primaite.simulator.network.transmission.transport_layer import Port +from primaite.simulator.system.applications.application import ApplicationOperatingState +from primaite.simulator.system.applications.database_client import DatabaseClient +from primaite.simulator.system.applications.red_applications.ransomware_script import ( + RansomwareAttackStage, + RansomwareScript, +) +from primaite.simulator.system.services.database.database_service import DatabaseService +from primaite.simulator.system.software import SoftwareHealthState + + +@pytest.fixture(scope="function") +def ransomware_script_and_db_server(client_server) -> Tuple[RansomwareScript, Computer, DatabaseService, Server]: + computer, server = client_server + + # install db client on computer + computer.software_manager.install(DatabaseClient) + db_client: DatabaseClient = computer.software_manager.software.get("DatabaseClient") + db_client.run() + + # Install DoSBot on computer + computer.software_manager.install(RansomwareScript) + + ransomware_script_application: RansomwareScript = computer.software_manager.software.get("RansomwareScript") + ransomware_script_application.configure( + server_ip_address=IPv4Address(server.network_interface[1].ip_address), payload="ENCRYPT" + ) + + # Install DB Server service on server + server.software_manager.install(DatabaseService) + db_server_service: DatabaseService = server.software_manager.software.get("DatabaseService") + db_server_service.start() + + return ransomware_script_application, computer, db_server_service, server + + +@pytest.fixture(scope="function") +def ransomware_script_db_server_green_client(example_network) -> Network: + network: Network = example_network + + router_1: Router = example_network.get_node_by_hostname("router_1") + router_1.acl.add_rule( + action=ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER, position=0 + ) + + client_1: Computer = network.get_node_by_hostname("client_1") + client_2: Computer = network.get_node_by_hostname("client_2") + server: Server = network.get_node_by_hostname("server_1") + + # install db client on client 1 + client_1.software_manager.install(DatabaseClient) + db_client: DatabaseClient = client_1.software_manager.software.get("DatabaseClient") + db_client.run() + + # install Ransomware Script bot on client 1 + client_1.software_manager.install(RansomwareScript) + + ransomware_script_application: RansomwareScript = client_1.software_manager.software.get("RansomwareScript") + ransomware_script_application.configure( + server_ip_address=IPv4Address(server.network_interface[1].ip_address), payload="ENCRYPT" + ) + + # install db server service on server + server.software_manager.install(DatabaseService) + db_server_service: DatabaseService = server.software_manager.software.get("DatabaseService") + db_server_service.start() + + # Install DB client (green) on client 2 + client_2.software_manager.install(DatabaseClient) + + database_client: DatabaseClient = client_2.software_manager.software.get("DatabaseClient") + database_client.configure(server_ip_address=IPv4Address(server.network_interface[1].ip_address)) + database_client.run() + + return network + + +def test_repeating_ransomware_script_attack(ransomware_script_and_db_server): + """Test a repeating data manipulation attack.""" + RansomwareScript, computer, db_server_service, server = ransomware_script_and_db_server + + assert db_server_service.health_state_actual is SoftwareHealthState.GOOD + assert computer.file_system.num_file_creations == 0 + + RansomwareScript.target_scan_p_of_success = 1 + RansomwareScript.c2_beacon_p_of_success = 1 + RansomwareScript.ransomware_encrypt_p_of_success = 1 + RansomwareScript.repeat = True + RansomwareScript.attack() + + assert RansomwareScript.attack_stage == RansomwareAttackStage.NOT_STARTED + assert db_server_service.db_file.health_status is FileSystemItemHealthStatus.COMPROMISED + assert computer.file_system.num_file_creations == 1 + + computer.apply_timestep(timestep=1) + server.apply_timestep(timestep=1) + + assert RansomwareScript.attack_stage == RansomwareAttackStage.NOT_STARTED + assert db_server_service.db_file.health_status is FileSystemItemHealthStatus.COMPROMISED + + +def test_repeating_ransomware_script_attack(ransomware_script_and_db_server): + """Test a repeating ransowmare script attack.""" + RansomwareScript, computer, db_server_service, server = ransomware_script_and_db_server + + assert db_server_service.health_state_actual is SoftwareHealthState.GOOD + + RansomwareScript.target_scan_p_of_success = 1 + RansomwareScript.c2_beacon_p_of_success = 1 + RansomwareScript.ransomware_encrypt_p_of_success = 1 + RansomwareScript.repeat = False + RansomwareScript.attack() + + assert RansomwareScript.attack_stage == RansomwareAttackStage.SUCCEEDED + assert db_server_service.db_file.health_status is FileSystemItemHealthStatus.CORRUPT + assert computer.file_system.num_file_creations == 1 + + computer.apply_timestep(timestep=1) + computer.pre_timestep(timestep=1) + server.apply_timestep(timestep=1) + server.pre_timestep(timestep=1) + + assert RansomwareScript.attack_stage == RansomwareAttackStage.SUCCEEDED + assert db_server_service.db_file.health_status is FileSystemItemHealthStatus.CORRUPT + assert computer.file_system.num_file_creations == 0 + + +def test_ransomware_disrupts_green_agent_connection(ransomware_script_db_server_green_client): + """Test to see show that the database service still operate""" + network: Network = ransomware_script_db_server_green_client + + client_1: Computer = network.get_node_by_hostname("client_1") + ransomware_script_application: RansomwareScript = client_1.software_manager.software.get("RansomwareScript") + + client_2: Computer = network.get_node_by_hostname("client_2") + green_db_client: DatabaseClient = client_2.software_manager.software.get("DatabaseClient") + + server: Server = network.get_node_by_hostname("server_1") + db_server_service: DatabaseService = server.software_manager.software.get("DatabaseService") + + assert db_server_service.db_file.health_status is FileSystemItemHealthStatus.GOOD + assert green_db_client.query("SELECT") + assert green_db_client.last_query_response.get("status_code") == 200 + + ransomware_script_application.target_scan_p_of_success = 1 + ransomware_script_application.ransomware_encrypt_p_of_success = 1 + ransomware_script_application.c2_beacon_p_of_success = 1 + ransomware_script_application.repeat = False + ransomware_script_application.attack() + + assert db_server_service.db_file.health_status is FileSystemItemHealthStatus.CORRUPT + assert green_db_client.query("SELECT") is True + assert green_db_client.last_query_response.get("status_code") == 200 diff --git a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py index 05824834..9b2ecf45 100644 --- a/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py +++ b/tests/unit_tests/_primaite/_simulator/_file_system/test_file_system.py @@ -21,6 +21,7 @@ def test_create_folder_and_file(file_system): assert file_system.get_folder("test_folder").get_file("test_file.txt") file_system.apply_timestep(0) + file_system.pre_timestep(0) # num file creations should reset assert file_system.num_file_creations == 0 @@ -38,6 +39,7 @@ def test_create_file_no_folder(file_system): assert file_system.get_folder("root").get_file("test_file.txt").size == 10 file_system.apply_timestep(0) + file_system.pre_timestep(0) # num file creations should reset assert file_system.num_file_creations == 0 @@ -59,6 +61,7 @@ def test_delete_file(file_system): assert len(file_system.get_folder("root").deleted_files) == 1 file_system.apply_timestep(0) + file_system.pre_timestep(0) # num file deletions should reset assert file_system.num_file_deletions == 0 @@ -174,6 +177,7 @@ def test_move_file(file_system): assert file_system.get_file("dst_folder", "test_file.txt").uuid == original_uuid file_system.apply_timestep(0) + file_system.pre_timestep(0) # num file creations and deletions should reset assert file_system.num_file_creations == 0 @@ -203,6 +207,7 @@ def test_copy_file(file_system): assert file_system.get_file("dst_folder", "test_file.txt").uuid != original_uuid file_system.apply_timestep(0) + file_system.pre_timestep(0) # num file creations should reset assert file_system.num_file_creations == 0 From e876bb5d41b40b623a8a6176e084d5215c493cfc Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 15 Apr 2024 11:59:17 +0100 Subject: [PATCH 807/980] #2459 update doc page --- docs/source/simulation.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/simulation.rst b/docs/source/simulation.rst index 20e1182a..fe494453 100644 --- a/docs/source/simulation.rst +++ b/docs/source/simulation.rst @@ -26,7 +26,6 @@ Contents simulation_components/network/nodes/wireless_router simulation_components/network/nodes/firewall simulation_components/network/switch - simulation_components/network/radio simulation_components/network/network simulation_components/system/internal_frame_processing simulation_components/system/sys_log From 72283e61843bd557436c39fc0fa598be630f4ba1 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 15 Apr 2024 12:40:50 +0100 Subject: [PATCH 808/980] #2459 Align whitespace and typing --- src/primaite/game/agent/rewards.py | 3 ++- src/primaite/game/game.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index f3398631..726afaa4 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -26,7 +26,7 @@ the structure: ``` """ from abc import abstractmethod -from typing import Callable, Dict, List, Optional, Tuple, Type, TYPE_CHECKING +from typing import Callable, Dict, Iterable, List, Optional, Tuple, Type, TYPE_CHECKING from typing_extensions import Never @@ -37,6 +37,7 @@ if TYPE_CHECKING: from primaite.game.agent.interface import AgentActionHistoryItem _LOGGER = getLogger(__name__) +WhereType = Iterable[str | int] | None class AbstractReward: diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 27fd452d..a1f9cb58 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -411,6 +411,7 @@ class PrimaiteGame: for link_cfg in links_cfg: node_a = net.get_node_by_hostname(link_cfg["endpoint_a_hostname"]) node_b = net.get_node_by_hostname(link_cfg["endpoint_b_hostname"]) + if isinstance(node_a, Switch): endpoint_a = node_a.network_interface[link_cfg["endpoint_a_port"]] else: @@ -460,6 +461,7 @@ class PrimaiteGame: reward_function=reward_function, settings=settings, ) + elif agent_type == "ProxyAgent": agent_settings = AgentSettings.from_config(agent_cfg.get("agent_settings")) new_agent = ProxyAgent( From 39ec55c7b69c7b6d688237fac802aeb572e2778a Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 15 Apr 2024 13:12:51 +0100 Subject: [PATCH 809/980] #2459 strip notebook outputs to appease pre-commit --- .../create-simulation_demo.ipynb | 3 +- .../network_simulator_demo.ipynb | 122 +++++++++--------- 2 files changed, 62 insertions(+), 63 deletions(-) diff --git a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb index d9742b50..f403176a 100644 --- a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb +++ b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb @@ -258,8 +258,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb index b537f54b..1da58409 100644 --- a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb +++ b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "03b2013a-b7d1-47ee-b08c-8dab83833720", + "id": "0", "metadata": {}, "source": [ "# PrimAITE Router Simulation Demo\n", @@ -12,7 +12,7 @@ }, { "cell_type": "raw", - "id": "c8bb5698-e746-4e90-9c2f-efe962acdfa0", + "id": "1", "metadata": {}, "source": [ " +------------+\n", @@ -48,7 +48,7 @@ }, { "cell_type": "markdown", - "id": "415d487c-6457-497d-85d6-99439b3541e7", + "id": "2", "metadata": {}, "source": [ "## The Network\n", @@ -60,7 +60,7 @@ { "cell_type": "code", "execution_count": null, - "id": "de57ac8c-5b28-4847-a759-2ceaf5593329", + "id": "3", "metadata": { "tags": [] }, @@ -72,7 +72,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a1e2e4df-67c0-4584-ab27-47e2c7c7fcd2", + "id": "4", "metadata": { "tags": [] }, @@ -83,7 +83,7 @@ }, { "cell_type": "markdown", - "id": "fb052c56-e9ca-4093-9115-d0c440b5ff53", + "id": "5", "metadata": {}, "source": [ "Most of the Network components have a `.show()` function that prints a table of information about that object. We can view the Nodes and Links on the Network by calling `network.show()`." @@ -92,7 +92,7 @@ { "cell_type": "code", "execution_count": null, - "id": "cc199741-ef2e-47f5-b2f0-e20049ccf40f", + "id": "6", "metadata": { "tags": [] }, @@ -103,7 +103,7 @@ }, { "cell_type": "markdown", - "id": "76d2b7e9-280b-4741-a8b3-a84bed219fac", + "id": "7", "metadata": { "tags": [] }, @@ -115,7 +115,7 @@ }, { "cell_type": "markdown", - "id": "84113002-843e-4cab-b899-667b50f25f6b", + "id": "8", "metadata": {}, "source": [ "### Router Nodes\n", @@ -125,7 +125,7 @@ }, { "cell_type": "markdown", - "id": "bf63a178-eee5-4669-bf64-13aea7ecf6cb", + "id": "9", "metadata": {}, "source": [ "Calling `router.show()` displays the Ethernet interfaces on the Router. If you need a table in markdown format, pass `markdown=True`." @@ -134,7 +134,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e76d1854-961e-438c-b40f-77fd9c3abe38", + "id": "10", "metadata": { "tags": [] }, @@ -145,7 +145,7 @@ }, { "cell_type": "markdown", - "id": "e000540c-687c-4254-870c-1d814603bdbf", + "id": "11", "metadata": {}, "source": [ "Calling `router.arp.show()` displays the Router ARP Cache." @@ -154,7 +154,7 @@ { "cell_type": "code", "execution_count": null, - "id": "92de8b42-92d7-4934-9c12-50bf724c9eb2", + "id": "12", "metadata": { "tags": [] }, @@ -165,7 +165,7 @@ }, { "cell_type": "markdown", - "id": "a9ff7ee8-9482-44de-9039-b684866bdc82", + "id": "13", "metadata": {}, "source": [ "Calling `router.acl.show()` displays the Access Control List." @@ -174,7 +174,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5922282a-d22b-4e55-9176-f3f3654c849f", + "id": "14", "metadata": { "tags": [] }, @@ -185,7 +185,7 @@ }, { "cell_type": "markdown", - "id": "71c87884-f793-4c9f-b004-5b0df86cf585", + "id": "15", "metadata": {}, "source": [ "Calling `router.router_table.show()` displays the static routes the Router provides." @@ -194,7 +194,7 @@ { "cell_type": "code", "execution_count": null, - "id": "327203be-f475-4727-82a1-e992d3b70ed8", + "id": "16", "metadata": { "tags": [] }, @@ -205,7 +205,7 @@ }, { "cell_type": "markdown", - "id": "eef561a8-3d39-4c8b-bbc8-e8b10b8ed25f", + "id": "17", "metadata": {}, "source": [ "Calling `router.sys_log.show()` displays the Router system log. By default, only the last 10 log entries are displayed, this can be changed by passing `last_n=`." @@ -214,7 +214,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3d0aa004-b10c-445f-aaab-340e0e716c74", + "id": "18", "metadata": { "tags": [] }, @@ -225,7 +225,7 @@ }, { "cell_type": "markdown", - "id": "25630c90-c54e-4b5d-8bf4-ad1b0722e126", + "id": "19", "metadata": {}, "source": [ "### Switch Nodes\n", @@ -235,7 +235,7 @@ }, { "cell_type": "markdown", - "id": "4879394d-2981-40de-a229-e19b09a34e6e", + "id": "20", "metadata": {}, "source": [ "Calling `switch.show()` displays the Switch orts on the Switch." @@ -244,7 +244,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e7fd439b-5442-4e9d-9e7d-86dacb77f458", + "id": "21", "metadata": { "tags": [] }, @@ -255,7 +255,7 @@ }, { "cell_type": "markdown", - "id": "beb8dbd6-7250-4ac9-9fa2-d2a9c0e5fd19", + "id": "22", "metadata": { "tags": [] }, @@ -266,7 +266,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d06e1310-4a77-4315-a59f-cb1b49ca2352", + "id": "23", "metadata": { "tags": [] }, @@ -277,7 +277,7 @@ }, { "cell_type": "markdown", - "id": "fda75ac3-8123-4234-8f36-86547891d8df", + "id": "24", "metadata": {}, "source": [ "Calling `switch.sys_log.show()` displays the Switch system log. By default, only the last 10 log entries are displayed, this can be changed by passing `last_n=`." @@ -286,7 +286,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a0d984b7-a7c1-4bbd-aa5a-9d3caecb08dc", + "id": "25", "metadata": { "tags": [] }, @@ -297,7 +297,7 @@ }, { "cell_type": "markdown", - "id": "2f1d99ad-db4f-4baf-8a35-e1d95f269586", + "id": "26", "metadata": {}, "source": [ "### Computer/Server Nodes\n", @@ -307,7 +307,7 @@ }, { "cell_type": "markdown", - "id": "c9e2251a-1b47-46e5-840f-7fec3e39c5aa", + "id": "27", "metadata": { "tags": [] }, @@ -318,7 +318,7 @@ { "cell_type": "code", "execution_count": null, - "id": "656c37f6-b145-42af-9714-8d2886d0eff8", + "id": "28", "metadata": { "tags": [] }, @@ -329,7 +329,7 @@ }, { "cell_type": "markdown", - "id": "f1097a49-a3da-4d79-a06d-ae8af452918f", + "id": "29", "metadata": {}, "source": [ "Calling `computer.arp.show()` displays the Computer/Server ARP Cache." @@ -338,7 +338,7 @@ { "cell_type": "code", "execution_count": null, - "id": "66b267d6-2308-486a-b9aa-cb8d3bcf0753", + "id": "30", "metadata": { "tags": [] }, @@ -349,7 +349,7 @@ }, { "cell_type": "markdown", - "id": "0d1fcad8-5b1a-4d8b-a49f-aa54a95fcaf0", + "id": "31", "metadata": {}, "source": [ "Calling `switch.sys_log.show()` displays the Computer/Server system log. By default, only the last 10 log entries are displayed, this can be changed by passing `last_n=`." @@ -358,7 +358,7 @@ { "cell_type": "code", "execution_count": null, - "id": "1b5debe8-ef1b-445d-8fa9-6a45568f21f3", + "id": "32", "metadata": { "tags": [] }, @@ -369,7 +369,7 @@ }, { "cell_type": "markdown", - "id": "fcfa1773-798c-4ada-9318-c3ad928217da", + "id": "33", "metadata": {}, "source": [ "## Basic Network Comms Check\n", @@ -380,7 +380,7 @@ { "cell_type": "code", "execution_count": null, - "id": "495b7de4-b6ce-41a6-9114-f74752ab4491", + "id": "34", "metadata": { "tags": [] }, @@ -391,7 +391,7 @@ }, { "cell_type": "markdown", - "id": "3e13922a-217f-4f4e-99b6-57a07613cade", + "id": "35", "metadata": {}, "source": [ "We'll first ping client_1's default gateway." @@ -400,7 +400,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a38abb71-994e-49e8-8f51-e9a550e95b99", + "id": "36", "metadata": { "tags": [] }, @@ -412,7 +412,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8388e1e9-30e3-4534-8e5a-c6e9144149d2", + "id": "37", "metadata": { "tags": [] }, @@ -423,7 +423,7 @@ }, { "cell_type": "markdown", - "id": "02c76d5c-d954-49db-912d-cb9c52f46375", + "id": "38", "metadata": {}, "source": [ "Next, we'll ping the interface of the 192.168.1.0/24 Network on the Router (port 1)." @@ -432,7 +432,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ff8e976a-c16b-470c-8923-325713a30d6c", + "id": "39", "metadata": { "tags": [] }, @@ -443,7 +443,7 @@ }, { "cell_type": "markdown", - "id": "80280404-a5ab-452f-8a02-771a0d7496b1", + "id": "40", "metadata": {}, "source": [ "And finally, we'll ping the web server." @@ -452,7 +452,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c4163f8d-6a72-410c-9f5c-4f881b7de45e", + "id": "41", "metadata": { "tags": [] }, @@ -463,7 +463,7 @@ }, { "cell_type": "markdown", - "id": "1194c045-ba77-4427-be30-ed7b5b224850", + "id": "42", "metadata": {}, "source": [ "To confirm that the ping was received and processed by the web_server, we can view the sys log" @@ -472,7 +472,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e79a523a-5780-45b6-8798-c434e0e522bd", + "id": "43", "metadata": { "tags": [] }, @@ -483,7 +483,7 @@ }, { "cell_type": "markdown", - "id": "5928f6dd-1006-45e3-99f3-8f311a875faa", + "id": "44", "metadata": {}, "source": [ "## Advanced Network Usage\n", @@ -493,7 +493,7 @@ }, { "cell_type": "markdown", - "id": "5e023ef3-7d18-4006-96ee-042a06a481fc", + "id": "45", "metadata": {}, "source": [ "Let's attempt to prevent client_2 from being able to ping the web server. First, we'll confirm that it can ping the server first..." @@ -502,7 +502,7 @@ { "cell_type": "code", "execution_count": null, - "id": "603cf913-e261-49da-a7dd-85e1bb6dec56", + "id": "46", "metadata": { "tags": [] }, @@ -513,7 +513,7 @@ }, { "cell_type": "markdown", - "id": "5cf962a4-20e6-44ae-9748-7fc5267ae111", + "id": "47", "metadata": {}, "source": [ "If we look at the client_2 sys log we can see that the four ICMP echo requests were sent and four ICMP each replies were received:" @@ -522,7 +522,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e047de00-3de4-4823-b26a-2c8d64c7a663", + "id": "48", "metadata": { "tags": [] }, @@ -533,7 +533,7 @@ }, { "cell_type": "markdown", - "id": "bdc4741d-6e3e-4aec-a69c-c2e9653bd02c", + "id": "49", "metadata": {}, "source": [ "Now we'll add an ACL to block ICMP from 192.168.10.22" @@ -542,7 +542,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6db355ae-b99a-441b-a2c4-4ffe78f46bff", + "id": "50", "metadata": { "tags": [] }, @@ -562,7 +562,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a345e000-8842-4827-af96-adc0fbe390fb", + "id": "51", "metadata": { "tags": [] }, @@ -573,7 +573,7 @@ }, { "cell_type": "markdown", - "id": "3a5bfd9f-04cb-493e-a86c-cd268563a262", + "id": "52", "metadata": {}, "source": [ "Now we attempt (and fail) to ping the web server" @@ -582,7 +582,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a4f4ff31-590f-40fb-b13d-efaa8c2720b6", + "id": "53", "metadata": { "tags": [] }, @@ -593,7 +593,7 @@ }, { "cell_type": "markdown", - "id": "83e56497-097b-45cb-964e-b15c72547b38", + "id": "54", "metadata": {}, "source": [ "We can check that the ping was actually sent by client_2 by viewing the sys log" @@ -602,7 +602,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f62b8a4e-fd3b-4059-b108-3d4a0b18f2a0", + "id": "55", "metadata": { "tags": [] }, @@ -613,7 +613,7 @@ }, { "cell_type": "markdown", - "id": "c7040311-a879-4620-86a0-55d0774156e5", + "id": "56", "metadata": {}, "source": [ "We can check the router sys log to see why the traffic was blocked" @@ -622,7 +622,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7e53d776-99da-4d2c-a2a7-bd7ce27bff4c", + "id": "57", "metadata": { "tags": [] }, @@ -633,7 +633,7 @@ }, { "cell_type": "markdown", - "id": "aba0bc7d-da57-477b-b34a-3688b5aab2c6", + "id": "58", "metadata": {}, "source": [ "Now a final check to ensure that client_1 can still ping the web_server." @@ -642,7 +642,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d542734b-7582-4af7-8254-bda3de50d091", + "id": "59", "metadata": { "tags": [] }, @@ -654,7 +654,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d78e9fe3-02c6-4792-944f-5622e26e0412", + "id": "60", "metadata": { "tags": [] }, From b797662b1d79203b9be14084873116f6814569ee Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 15 Apr 2024 14:15:58 +0100 Subject: [PATCH 810/980] bump version --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index 1129dfd4..f08efbdc 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0b7 +3.0.0b9dev From f0ed9d2240126de3499170bc4010b960e7909cd5 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 15 Apr 2024 14:16:09 +0100 Subject: [PATCH 811/980] re-enable multi platform builds --- .azure/azure-ci-build-pipeline.yaml | 40 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/.azure/azure-ci-build-pipeline.yaml b/.azure/azure-ci-build-pipeline.yaml index 9faaffaf..e9139d5b 100644 --- a/.azure/azure-ci-build-pipeline.yaml +++ b/.azure/azure-ci-build-pipeline.yaml @@ -24,26 +24,26 @@ parameters: img: 'ubuntu-latest' every_time: true publish_coverage: true - # - job_name: 'WindowsPython38' - # py: '3.8' - # img: 'windows-latest' - # every_time: false - # publish_coverage: false - # - job_name: 'WindowsPython310' - # py: '3.10' - # img: 'windows-latest' - # every_time: false - # publish_coverage: false - # - job_name: 'MacOSPython38' - # py: '3.8' - # img: 'macOS-latest' - # every_time: false - # publish_coverage: false - # - job_name: 'MacOSPython310' - # py: '3.10' - # img: 'macOS-latest' - # every_time: false - # publish_coverage: false + - job_name: 'WindowsPython38' + py: '3.8' + img: 'windows-latest' + every_time: false + publish_coverage: false + - job_name: 'WindowsPython310' + py: '3.10' + img: 'windows-latest' + every_time: false + publish_coverage: false + - job_name: 'MacOSPython38' + py: '3.8' + img: 'macOS-latest' + every_time: false + publish_coverage: false + - job_name: 'MacOSPython310' + py: '3.10' + img: 'macOS-latest' + every_time: false + publish_coverage: false stages: - stage: Test From 2d444f71c97b09b8de46fb43e28ea2029689b176 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 16 Apr 2024 08:53:55 +0000 Subject: [PATCH 812/980] Updated VERSION --- src/primaite/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/VERSION b/src/primaite/VERSION index 1129dfd4..6783f3bd 100644 --- a/src/primaite/VERSION +++ b/src/primaite/VERSION @@ -1 +1 @@ -3.0.0b7 +3.0.0b8 From 8d0d323e0bab94bc89e5f9b1a214a47a6a74075c Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 16 Apr 2024 11:26:17 +0100 Subject: [PATCH 813/980] #2374 Remove primaite session --- benchmark/primaite_benchmark.py | 4 + docs/source/config.rst | 6 +- docs/source/configuration/io_settings.rst | 30 - docs/source/configuration/training_config.rst | 75 -- docs/source/game_layer.rst | 9 - docs/source/primaite_session.rst | 41 - src/primaite/cli.py | 20 - .../_package_data/data_manipulation_marl.yaml | 14 - src/primaite/game/game.py | 4 +- src/primaite/main.py | 47 -- src/primaite/session/environment.py | 2 +- src/primaite/session/io.py | 1 + src/primaite/session/policy/__init__.py | 4 - src/primaite/session/policy/policy.py | 82 -- src/primaite/session/policy/rllib.py | 111 --- src/primaite/session/policy/sb3.py | 79 -- src/primaite/session/session.py | 119 --- src/primaite/simulator/network/airspace.py | 2 +- src/primaite/utils/session_metadata_parser.py | 4 + src/primaite/utils/session_output_reader.py | 4 + src/primaite/utils/session_output_writer.py | 4 + .../assets/configs/bad_primaite_session.yaml | 9 - .../configs/eval_only_primaite_session.yaml | 13 - .../configs/firewall_actions_network.yaml | 12 - tests/assets/configs/multi_agent_session.yaml | 101 +-- tests/assets/configs/shared_rewards.yaml | 12 - .../configs/test_application_install.yaml | 12 - .../assets/configs/test_primaite_session.yaml | 14 +- .../configs/train_only_primaite_session.yaml | 737 ------------------ tests/conftest.py | 33 - .../test_rllib_multi_agent_environment.py | 17 +- .../e2e_integration_tests/test_environment.py | 91 +++ .../test_primaite_session.py | 109 --- 33 files changed, 122 insertions(+), 1700 deletions(-) delete mode 100644 docs/source/configuration/training_config.rst delete mode 100644 docs/source/primaite_session.rst delete mode 100644 src/primaite/main.py delete mode 100644 src/primaite/session/policy/__init__.py delete mode 100644 src/primaite/session/policy/policy.py delete mode 100644 src/primaite/session/policy/rllib.py delete mode 100644 src/primaite/session/policy/sb3.py delete mode 100644 src/primaite/session/session.py delete mode 100644 tests/assets/configs/train_only_primaite_session.yaml create mode 100644 tests/e2e_integration_tests/test_environment.py delete mode 100644 tests/e2e_integration_tests/test_primaite_session.py diff --git a/benchmark/primaite_benchmark.py b/benchmark/primaite_benchmark.py index 9fec5711..226bb71e 100644 --- a/benchmark/primaite_benchmark.py +++ b/benchmark/primaite_benchmark.py @@ -1,3 +1,7 @@ +# flake8: noqa +raise DeprecationWarning( + "Benchmarking depends on deprecated functionality and it has not been updated to primaite v3 yet." +) # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK import json import platform diff --git a/docs/source/config.rst b/docs/source/config.rst index 89181a24..b334d99b 100644 --- a/docs/source/config.rst +++ b/docs/source/config.rst @@ -5,8 +5,7 @@ PrimAITE |VERSION| Configuration ******************************** -PrimAITE uses a single configuration file to define everything needed to train and evaluate an RL policy in a custom cybersecurity scenario. This includes the configuration of the network, the scripted or trained agents that interact with the network, as well as settings that define how to perform training in Stable Baselines 3 or Ray RLLib. -The entire config is used by the ``PrimaiteSession`` object for users who wish to let PrimAITE handle the agent definition and training. If you wish to define custom agents and control the training loop yourself, you can use the config with the ``PrimaiteGame``, and ``PrimaiteGymEnv`` objects instead. That way, only the network configuration and agent setup parts of the config are used, and the training section is ignored. +PrimAITE uses a single configuration file to define everything needed to create the training environment for RL agents, including the network, the scripted agents, and the RL agent's action space, observation space, and reward function. Example Configuration Hierarchy ############################### @@ -14,8 +13,6 @@ The top level configuration items in a configuration file is as follows .. code-block:: yaml - training_config: - ... io_settings: ... game: @@ -33,7 +30,6 @@ Configurable items .. toctree:: :maxdepth: 1 - configuration/training_config.rst configuration/io_settings.rst configuration/game.rst configuration/agents.rst diff --git a/docs/source/configuration/io_settings.rst b/docs/source/configuration/io_settings.rst index 979dbfae..67734751 100644 --- a/docs/source/configuration/io_settings.rst +++ b/docs/source/configuration/io_settings.rst @@ -13,42 +13,12 @@ This section configures how PrimAITE saves data during simulation and training. .. code-block:: yaml io_settings: - save_final_model: True - save_checkpoints: False - checkpoint_interval: 10 # save_logs: True - # save_transactions: False save_agent_actions: True save_step_metadata: False save_pcap_logs: False save_sys_logs: False -``save_final_model`` --------------------- - -Optional. Default value is ``True``. - -Only used if training with PrimaiteSession. -If ``True``, the policy will be saved after the final training iteration. - - -``save_checkpoints`` --------------------- - -Optional. Default value is ``False``. - -Only used if training with PrimaiteSession. -If ``True``, the policy will be saved periodically during training. - - -``checkpoint_interval`` ------------------------ - -Optional. Default value is ``10``. - -Only used if training with PrimaiteSession and if ``save_checkpoints`` is ``True``. -Defines how often to save the policy during training. - ``save_logs`` ------------- diff --git a/docs/source/configuration/training_config.rst b/docs/source/configuration/training_config.rst deleted file mode 100644 index 3e63f69b..00000000 --- a/docs/source/configuration/training_config.rst +++ /dev/null @@ -1,75 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -``training_config`` -=================== -Configuration items relevant to how the Reinforcement Learning agent(s) will be trained. - -``training_config`` hierarchy ------------------------------ - -.. code-block:: yaml - - training_config: - rl_framework: SB3 # or RLLIB_single_agent or RLLIB_multi_agent - rl_algorithm: PPO # or A2C - n_learn_episodes: 5 - max_steps_per_episode: 200 - n_eval_episodes: 1 - deterministic_eval: True - seed: 123 - - -``rl_framework`` ----------------- -The RL (Reinforcement Learning) Framework to use in the training session - -Options available are: - -- ``SB3`` (Stable Baselines 3) -- ``RLLIB_single_agent`` (Single Agent Ray RLLib) -- ``RLLIB_multi_agent`` (Multi Agent Ray RLLib) - -``rl_algorithm`` ----------------- -The Reinforcement Learning Algorithm to use in the training session - -Options available are: - -- ``PPO`` (Proximal Policy Optimisation) -- ``A2C`` (Advantage Actor Critic) - -``n_learn_episodes`` --------------------- -The number of episodes to train the agent(s). -This should be an integer value above ``0`` - -``max_steps_per_episode`` -------------------------- -The number of steps each episode will last for. -This should be an integer value above ``0``. - - -``n_eval_episodes`` -------------------- -Optional. Default value is ``0``. - -The number of evaluation episodes to run the trained agent for. -This should be an integer value above ``0``. - -``deterministic_eval`` ----------------------- -Optional. By default this value is ``False``. - -If this is set to ``True``, the agents will act deterministically instead of stochastically. - - - -``seed`` --------- -Optional. - -The seed is used (alongside ``deterministic_eval``) to reproduce a previous instance of training and evaluation of an RL agent. -The seed should be an integer value. -Useful for debugging. diff --git a/docs/source/game_layer.rst b/docs/source/game_layer.rst index af3eadc6..68984a1b 100644 --- a/docs/source/game_layer.rst +++ b/docs/source/game_layer.rst @@ -10,15 +10,6 @@ The simulator and game layer communicate using the PrimAITE State API and the Pr The game layer is responsible for managing agents and getting them to interface with the simulator correctly. It consists of several components: -PrimAITE Session -================ - -.. admonition:: Deprecated - :class: deprecated - - PrimAITE Session is being deprecated in favour of Jupyter Notebooks. The `session` command will be removed in future releases, but example notebooks will be provided to demonstrate the same functionality. - -``PrimaiteSession`` is the main entry point into Primaite and it allows the simultaneous coordination of a simulation and agents that interact with it. ``PrimaiteSession`` keeps track of multiple agents of different types. Agents ====== diff --git a/docs/source/primaite_session.rst b/docs/source/primaite_session.rst deleted file mode 100644 index d0caeaad..00000000 --- a/docs/source/primaite_session.rst +++ /dev/null @@ -1,41 +0,0 @@ -.. only:: comment - - © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK - -.. _run a primaite session: - -.. admonition:: Deprecated - :class: deprecated - - PrimAITE Session is being deprecated in favour of Jupyter Notebooks. The ``session`` command will be removed in future releases, but example notebooks will be provided to demonstrate the same functionality. - -Run a PrimAITE Session -====================== - -``PrimaiteSession`` allows the user to train or evaluate an RL agent on the primaite simulation with just a config file, -no code required. It manages the lifecycle of a training or evaluation session, including the setup of the environment, -policy, simulator, agents, and IO. - -If you want finer control over the RL policy, you can interface with the :py:module::`primaite.session.environment` -module directly without running a session. - - - -Run ---- - -A PrimAITE session can be started either with the ``primaite session`` command from the cli -(See :func:`primaite.cli.session`), or by calling :func:`primaite.main.run` from a Python terminal or Jupyter Notebook. - -There are two parameters that can be specified: - - ``--config``: The path to the config file to use. If not specified, the default config file is used. - - ``--agent-load-file``: The path to the pre-trained agent to load. If not specified, a new agent is created. - -Outputs -------- - -Running a session creates a session output directory in your user data folder. The filepath looks like this: -``~/primaite/{VERSION}/sessions/YYYY-MM-DD/HH-MM-SS/``. This folder contains the simulation sys logs generated by each node, -the saved agent checkpoints, and final model. The folder also contains a .json file for each episode step that -contains the action, reward, and simulation state. These can be found in -``~/primaite/{VERSION}/sessions/YYYY-MM-DD/HH-MM-SS/simulation_output/episode_/step_metadata/step_.json`` diff --git a/src/primaite/cli.py b/src/primaite/cli.py index 18d21f7b..ca493493 100644 --- a/src/primaite/cli.py +++ b/src/primaite/cli.py @@ -114,23 +114,3 @@ def setup(overwrite_existing: bool = True) -> None: reset_example_configs.run(overwrite_existing=True) _LOGGER.info("PrimAITE setup complete!") - - -@app.command() -def session( - config: Optional[str] = None, - agent_load_file: Optional[str] = None, -) -> None: - """ - Run a PrimAITE session. - - :param config: The path to the config file. Optional, if None, the example config will be used. - :type config: Optional[str] - """ - from primaite.config.load import data_manipulation_config_path - from primaite.main import run - - if not config: - config = data_manipulation_config_path() - print(config) - run(config_path=config, agent_load_path=agent_load_file) diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index eaee132b..cb94a128 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -1,17 +1,3 @@ -training_config: - rl_framework: RLLIB_multi_agent - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 1 - n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 2 - agent_references: - - defender_1 - - defender_2 - - io_settings: save_agent_actions: true save_step_metadata: false diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index a1f9cb58..908b5148 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -210,8 +210,8 @@ class PrimaiteGame: """Create a PrimaiteGame object from a config dictionary. The config dictionary should have the following top-level keys: - 1. training_config: options for training the RL agent. - 2. game_config: options for the game itself. Used by PrimaiteGame. + 1. io_settings: options for logging data during training + 2. game_config: options for the game itself, such as agents. 3. simulation: defines the network topology and the initial state of the simulation. The specification for each of the three major areas is described in a separate documentation page. diff --git a/src/primaite/main.py b/src/primaite/main.py deleted file mode 100644 index 053ed65b..00000000 --- a/src/primaite/main.py +++ /dev/null @@ -1,47 +0,0 @@ -# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK -"""The main PrimAITE session runner module.""" -import argparse -from pathlib import Path -from typing import Optional, Union - -from primaite import getLogger -from primaite.config.load import data_manipulation_config_path, load -from primaite.session.session import PrimaiteSession - -# from primaite.primaite_session import PrimaiteSession - -_LOGGER = getLogger(__name__) - - -def run( - config_path: Optional[Union[str, Path]] = "", - agent_load_path: Optional[Union[str, Path]] = None, -) -> None: - """ - Run the PrimAITE Session. - - :param training_config_path: YAML file containing configurable items defined in - `primaite.config.training_config.TrainingConfig` - :type training_config_path: Union[path, str] - :param lay_down_config_path: YAML file containing configurable items for generating network laydown. - :type lay_down_config_path: Union[path, str] - :param session_path: directory path of the session to load - :param legacy_training_config: True if the training config file is a legacy file from PrimAITE < 2.0, - otherwise False. - :param legacy_lay_down_config: True if the lay_down config file is a legacy file from PrimAITE < 2.0, - otherwise False. - """ - cfg = load(config_path) - sess = PrimaiteSession.from_config(cfg=cfg, agent_load_path=agent_load_path) - sess.start_session() - - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument("--config") - - args = parser.parse_args() - if not args.config: - args.config = data_manipulation_config_path() - - run(args.config) diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index cb891cd7..9311e1f7 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -48,7 +48,7 @@ class PrimaiteGymEnv(gymnasium.Env): def step(self, action: ActType) -> Tuple[ObsType, SupportsFloat, bool, bool, Dict[str, Any]]: """Perform a step in the environment.""" - # make ProxyAgent store the action chosen my the RL policy + # make ProxyAgent store the action chosen by the RL policy step = self.game.step_counter self.agent.store_action(action) # apply_agent_actions accesses the action we just stored diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index 69cea614..0b22f784 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -95,6 +95,7 @@ class PrimaiteIO: @classmethod def from_config(cls, config: Dict) -> "PrimaiteIO": """Create an instance of PrimaiteIO based on a configuration dict.""" + config = config or {} new = cls(settings=cls.Settings(**config)) return new diff --git a/src/primaite/session/policy/__init__.py b/src/primaite/session/policy/__init__.py deleted file mode 100644 index 811c7a54..00000000 --- a/src/primaite/session/policy/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from primaite.session.policy.rllib import RaySingleAgentPolicy -from primaite.session.policy.sb3 import SB3Policy - -__all__ = ["SB3Policy", "RaySingleAgentPolicy"] diff --git a/src/primaite/session/policy/policy.py b/src/primaite/session/policy/policy.py deleted file mode 100644 index 984466d1..00000000 --- a/src/primaite/session/policy/policy.py +++ /dev/null @@ -1,82 +0,0 @@ -"""Base class and common logic for RL policies.""" -from abc import ABC, abstractmethod -from pathlib import Path -from typing import Any, Dict, Type, TYPE_CHECKING - -if TYPE_CHECKING: - from primaite.session.session import PrimaiteSession, TrainingOptions - - -class PolicyABC(ABC): - """Base class for reinforcement learning agents.""" - - _registry: Dict[str, Type["PolicyABC"]] = {} - """ - Registry of policy types, keyed by name. - - Automatically populated when PolicyABC subclasses are defined. Used for defining from_config. - """ - - def __init_subclass__(cls, identifier: str, **kwargs: Any) -> None: - """ - Register a policy subclass. - - :param name: Identifier used by from_config to create an instance of the policy. - :type name: str - :raises ValueError: When attempting to create a policy with a duplicate name. - """ - super().__init_subclass__(**kwargs) - if identifier in cls._registry: - raise ValueError(f"Duplicate policy name {identifier}") - cls._registry[identifier] = cls - return - - @abstractmethod - def __init__(self, session: "PrimaiteSession") -> None: - """ - Initialize a reinforcement learning policy. - - :param session: The session context. - :type session: PrimaiteSession - :param agents: The agents to train. - :type agents: List[RLAgent] - """ - self.session: "PrimaiteSession" = session - """Reference to the session.""" - - @abstractmethod - def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: - """Train the agent.""" - pass - - @abstractmethod - def eval(self, n_episodes: int, timesteps_per_episode: int, deterministic: bool) -> None: - """Evaluate the agent.""" - pass - - @abstractmethod - def save(self, save_path: Path) -> None: - """Save the agent.""" - pass - - @abstractmethod - def load(self) -> None: - """Load agent from a file.""" - pass - - def close(self) -> None: - """Close the agent.""" - pass - - @classmethod - def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "PolicyABC": - """ - Create an RL policy from a config by calling the relevant subclass's from_config method. - - Subclasses should not call super().from_config(), they should just handle creation form config. - """ - # Assume that basically the contents of training_config are passed into here. - # I should really define a config schema class using pydantic. - - PolicyType = cls._registry[config.rl_framework] - return PolicyType.from_config(config=config, session=session) diff --git a/src/primaite/session/policy/rllib.py b/src/primaite/session/policy/rllib.py deleted file mode 100644 index ca69a2a8..00000000 --- a/src/primaite/session/policy/rllib.py +++ /dev/null @@ -1,111 +0,0 @@ -from pathlib import Path -from typing import Literal, Optional, TYPE_CHECKING - -from primaite.session.environment import PrimaiteRayEnv, PrimaiteRayMARLEnv -from primaite.session.policy.policy import PolicyABC - -if TYPE_CHECKING: - from primaite.session.session import PrimaiteSession, TrainingOptions - -import ray -from ray import air, tune -from ray.rllib.algorithms import ppo -from ray.rllib.algorithms.ppo import PPOConfig - -from primaite import getLogger - -_LOGGER = getLogger(__name__) - - -class RaySingleAgentPolicy(PolicyABC, identifier="RLLIB_single_agent"): - """Single agent RL policy using Ray RLLib.""" - - def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): - super().__init__(session=session) - - self.config = { - "env": PrimaiteRayEnv, - "env_config": {"game": session.game}, - "disable_env_checking": True, - "num_rollout_workers": 0, - } - - ray.shutdown() - ray.init() - - def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: - """Train the agent.""" - self.config["training_iterations"] = n_episodes * timesteps_per_episode - self.config["train_batch_size"] = 128 - self._algo = ppo.PPO(config=self.config) - _LOGGER.info("Starting RLLIB training session") - self._algo.train() - - def eval(self, n_episodes: int, deterministic: bool) -> None: - """Evaluate the agent.""" - for ep in range(n_episodes): - obs, info = self.session.env.reset() - for step in range(self.session.game.options.max_episode_length): - action = self._algo.compute_single_action(observation=obs, explore=False) - obs, rew, term, trunc, info = self.session.env.step(action) - - def save(self, save_path: Path) -> None: - """Save the policy to a file.""" - self._algo.save(save_path) - - def load(self, model_path: Path) -> None: - """Load policy parameters from a file.""" - raise NotImplementedError - - @classmethod - def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "RaySingleAgentPolicy": - """Create a policy from a config.""" - return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) - - -class RayMultiAgentPolicy(PolicyABC, identifier="RLLIB_multi_agent"): - """Mutli agent RL policy using Ray RLLib.""" - - def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO"], seed: Optional[int] = None): - """Initialise multi agent policy wrapper.""" - super().__init__(session=session) - - self.config = ( - PPOConfig() - .environment(env=PrimaiteRayMARLEnv, env_config={"game": session.game}) - .rollouts(num_rollout_workers=0) - .multi_agent( - policies={agent.agent_name for agent in session.game.rl_agents}, - policy_mapping_fn=lambda agent_id, episode, worker, **kw: agent_id, - ) - .training(train_batch_size=128) - ) - - def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: - """Train the agent.""" - checkpoint_freq = self.session.io_manager.settings.checkpoint_interval - tune.Tuner( - "PPO", - run_config=air.RunConfig( - stop={"training_iteration": n_episodes * timesteps_per_episode}, - checkpoint_config=air.CheckpointConfig(checkpoint_frequency=checkpoint_freq), - ), - param_space=self.config, - ).fit() - - def load(self, model_path: Path) -> None: - """Load policy parameters from a file.""" - return NotImplemented - - def eval(self, n_episodes: int, deterministic: bool) -> None: - """Evaluate trained policy.""" - return NotImplemented - - def save(self, save_path: Path) -> None: - """Save policy parameters to a file.""" - return NotImplemented - - @classmethod - def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "RayMultiAgentPolicy": - """Create policy from config.""" - return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) diff --git a/src/primaite/session/policy/sb3.py b/src/primaite/session/policy/sb3.py deleted file mode 100644 index 6220371d..00000000 --- a/src/primaite/session/policy/sb3.py +++ /dev/null @@ -1,79 +0,0 @@ -"""Stable baselines 3 policy.""" -from pathlib import Path -from typing import Literal, Optional, Type, TYPE_CHECKING, Union - -from stable_baselines3 import A2C, PPO -from stable_baselines3.a2c import MlpPolicy as A2C_MLP -from stable_baselines3.common.callbacks import CheckpointCallback -from stable_baselines3.common.evaluation import evaluate_policy -from stable_baselines3.ppo import MlpPolicy as PPO_MLP - -from primaite.session.policy.policy import PolicyABC - -if TYPE_CHECKING: - from primaite.session.session import PrimaiteSession, TrainingOptions - - -class SB3Policy(PolicyABC, identifier="SB3"): - """Single agent RL policy using stable baselines 3.""" - - def __init__(self, session: "PrimaiteSession", algorithm: Literal["PPO", "A2C"], seed: Optional[int] = None): - """Initialize a stable baselines 3 policy.""" - super().__init__(session=session) - - self._agent_class: Type[Union[PPO, A2C]] - if algorithm == "PPO": - self._agent_class = PPO - policy = PPO_MLP - elif algorithm == "A2C": - self._agent_class = A2C - policy = A2C_MLP - else: - raise ValueError(f"Unknown algorithm `{algorithm}` for stable_baselines3 policy") - self._agent = self._agent_class( - policy=policy, - env=self.session.env, - n_steps=128, # this is not the number of steps in an episode, but the number of steps in a batch - seed=seed, - ) - - def learn(self, n_episodes: int, timesteps_per_episode: int) -> None: - """Train the agent.""" - if self.session.save_checkpoints: - checkpoint_callback = CheckpointCallback( - save_freq=timesteps_per_episode * self.session.checkpoint_interval, - save_path=self.session.io_manager.generate_model_save_path("sb3"), - name_prefix="sb3_model", - ) - else: - checkpoint_callback = None - self._agent.learn(total_timesteps=n_episodes * timesteps_per_episode, callback=checkpoint_callback) - - def eval(self, n_episodes: int, deterministic: bool) -> None: - """Evaluate the agent.""" - _ = evaluate_policy( - self._agent, - self.session.env, - n_eval_episodes=n_episodes, - deterministic=deterministic, - return_episode_rewards=True, - ) - - def save(self, save_path: Path) -> None: - """ - Save the current policy parameters. - - Warning: The recommended way to save model checkpoints is to use a callback within the `learn()` method. Please - refer to https://stable-baselines3.readthedocs.io/en/master/guide/callbacks.html for more information. - Therefore, this method is only used to save the final model. - """ - self._agent.save(save_path) - - def load(self, model_path: Path) -> None: - """Load agent from a checkpoint.""" - self._agent = self._agent_class.load(model_path, env=self.session.env) - - @classmethod - def from_config(cls, config: "TrainingOptions", session: "PrimaiteSession") -> "SB3Policy": - """Create an agent from config file.""" - return cls(session=session, algorithm=config.rl_algorithm, seed=config.seed) diff --git a/src/primaite/session/session.py b/src/primaite/session/session.py deleted file mode 100644 index 9c935ae3..00000000 --- a/src/primaite/session/session.py +++ /dev/null @@ -1,119 +0,0 @@ -# raise DeprecationWarning("This module is deprecated") -from enum import Enum -from pathlib import Path -from typing import Dict, List, Literal, Optional, Union - -from pydantic import BaseModel, ConfigDict - -from primaite.session.environment import PrimaiteGymEnv, PrimaiteRayEnv, PrimaiteRayMARLEnv -from primaite.session.io import PrimaiteIO - -# from primaite.game.game import PrimaiteGame -from primaite.session.policy.policy import PolicyABC - - -class TrainingOptions(BaseModel): - """Options for training the RL agent.""" - - model_config = ConfigDict(extra="forbid") - - rl_framework: Literal["SB3", "RLLIB_single_agent", "RLLIB_multi_agent"] - rl_algorithm: Literal["PPO", "A2C"] - n_learn_episodes: int - n_eval_episodes: Optional[int] = None - max_steps_per_episode: int - # checkpoint_freq: Optional[int] = None - deterministic_eval: bool - seed: Optional[int] - n_agents: int - agent_references: List[str] - - -class SessionMode(Enum): - """Helper to keep track of the current session mode.""" - - TRAIN = "train" - EVAL = "eval" - MANUAL = "manual" - - -class PrimaiteSession: - """The main entrypoint for PrimAITE sessions, this manages a simulation, policy training, and environments.""" - - def __init__(self, game_cfg: Dict): - """Initialise PrimaiteSession object.""" - self.training_options: TrainingOptions - """Options specific to agent training.""" - - self.mode: SessionMode = SessionMode.MANUAL - """Current session mode.""" - - self.env: Union[PrimaiteGymEnv, PrimaiteRayEnv, PrimaiteRayMARLEnv] - """The environment that the RL algorithm can consume.""" - - self.policy: PolicyABC - """The reinforcement learning policy.""" - - self.io_manager: Optional["PrimaiteIO"] = None - """IO manager for the session.""" - - self.game_cfg: Dict = game_cfg - """Primaite Game object for managing main simulation loop and agents.""" - - self.save_checkpoints: bool = False - """Whether to save checkpoints.""" - - self.checkpoint_interval: int = 10 - """If save_checkpoints is true, checkpoints will be saved every checkpoint_interval episodes.""" - - def start_session(self) -> None: - """Commence the training/eval session.""" - print("Starting Primaite Session") - self.mode = SessionMode.TRAIN - n_learn_episodes = self.training_options.n_learn_episodes - n_eval_episodes = self.training_options.n_eval_episodes - max_steps_per_episode = self.training_options.max_steps_per_episode - - deterministic_eval = self.training_options.deterministic_eval - self.policy.learn( - n_episodes=n_learn_episodes, - timesteps_per_episode=max_steps_per_episode, - ) - self.save_models() - - self.mode = SessionMode.EVAL - if n_eval_episodes > 0: - self.policy.eval(n_episodes=n_eval_episodes, deterministic=deterministic_eval) - - self.mode = SessionMode.MANUAL - - def save_models(self) -> None: - """Save the RL models.""" - save_path = self.io_manager.generate_model_save_path("temp_model_name") - self.policy.save(save_path) - - @classmethod - def from_config(cls, cfg: Dict, agent_load_path: Optional[str] = None) -> "PrimaiteSession": - """Create a PrimaiteSession object from a config dictionary.""" - # READ IO SETTINGS (this sets the global session path as well) # TODO: GLOBAL SIDE EFFECTS... - io_manager = PrimaiteIO.from_config(cfg.get("io_settings", {})) - - sess = cls(game_cfg=cfg) - sess.io_manager = io_manager - sess.training_options = TrainingOptions(**cfg["training_config"]) - sess.save_checkpoints = cfg.get("io_settings", {}).get("save_checkpoints") - sess.checkpoint_interval = cfg.get("io_settings", {}).get("checkpoint_interval") - - # CREATE ENVIRONMENT - if sess.training_options.rl_framework == "RLLIB_single_agent": - sess.env = PrimaiteRayEnv(env_config=cfg) - elif sess.training_options.rl_framework == "RLLIB_multi_agent": - sess.env = PrimaiteRayMARLEnv(env_config=cfg) - elif sess.training_options.rl_framework == "SB3": - sess.env = PrimaiteGymEnv(game_config=cfg) - - sess.policy = PolicyABC.from_config(sess.training_options, session=sess) - if agent_load_path: - sess.policy.load(Path(agent_load_path)) - - return sess diff --git a/src/primaite/simulator/network/airspace.py b/src/primaite/simulator/network/airspace.py index a8343675..abda587e 100644 --- a/src/primaite/simulator/network/airspace.py +++ b/src/primaite/simulator/network/airspace.py @@ -271,7 +271,7 @@ class IPWirelessNetworkInterface(WirelessNetworkInterface, Layer3Interface, ABC) # Update the state with information from Layer3Interface state.update(Layer3Interface.describe_state(self)) - state["frequency"] = self.frequency + state["frequency"] = self.frequency.value return state diff --git a/src/primaite/utils/session_metadata_parser.py b/src/primaite/utils/session_metadata_parser.py index 2548a8b6..083d55ba 100644 --- a/src/primaite/utils/session_metadata_parser.py +++ b/src/primaite/utils/session_metadata_parser.py @@ -1,3 +1,7 @@ +# flake8: noqa +raise DeprecationWarning( + "Benchmarking depends on deprecated functionality and it has not been updated to primaite v3 yet." +) # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK import json from pathlib import Path diff --git a/src/primaite/utils/session_output_reader.py b/src/primaite/utils/session_output_reader.py index 30febff1..322b3b8d 100644 --- a/src/primaite/utils/session_output_reader.py +++ b/src/primaite/utils/session_output_reader.py @@ -1,3 +1,7 @@ +# flake8: noqa +raise DeprecationWarning( + "Benchmarking depends on deprecated functionality and it has not been updated to primaite v3 yet." +) # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK from pathlib import Path from typing import Any, Dict, Tuple, Union diff --git a/src/primaite/utils/session_output_writer.py b/src/primaite/utils/session_output_writer.py index 0eb18038..9253147a 100644 --- a/src/primaite/utils/session_output_writer.py +++ b/src/primaite/utils/session_output_writer.py @@ -1,3 +1,7 @@ +# flake8: noqa +raise DeprecationWarning( + "Benchmarking depends on deprecated functionality and it has not been updated to primaite v3 yet." +) # © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK import csv from logging import Logger diff --git a/tests/assets/configs/bad_primaite_session.yaml b/tests/assets/configs/bad_primaite_session.yaml index 18b86bf3..231c69ab 100644 --- a/tests/assets/configs/bad_primaite_session.yaml +++ b/tests/assets/configs/bad_primaite_session.yaml @@ -1,12 +1,3 @@ -training_config: - rl_framework: SB3 - rl_algorithm: PPO - se3ed: 333 # Purposeful typo to check that error is raised with bad configuration. - n_learn_steps: 2560 - n_eval_episodes: 5 - - - game: ports: - ARP diff --git a/tests/assets/configs/eval_only_primaite_session.yaml b/tests/assets/configs/eval_only_primaite_session.yaml index eab0720a..4cf0e68c 100644 --- a/tests/assets/configs/eval_only_primaite_session.yaml +++ b/tests/assets/configs/eval_only_primaite_session.yaml @@ -1,16 +1,3 @@ -training_config: - rl_framework: SB3 - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 0 - n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: - - defender - - game: ports: - ARP diff --git a/tests/assets/configs/firewall_actions_network.yaml b/tests/assets/configs/firewall_actions_network.yaml index fdf29599..fd5b1bf8 100644 --- a/tests/assets/configs/firewall_actions_network.yaml +++ b/tests/assets/configs/firewall_actions_network.yaml @@ -30,18 +30,6 @@ # | external_computer |------| switch_3 |------| external_server | # ----------------------- -------------- --------------------- # -training_config: - rl_framework: SB3 - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 1 - n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: - - defender - io_settings: save_step_metadata: false save_pcap_logs: true diff --git a/tests/assets/configs/multi_agent_session.yaml b/tests/assets/configs/multi_agent_session.yaml index 0b0685c0..0c89bef4 100644 --- a/tests/assets/configs/multi_agent_session.yaml +++ b/tests/assets/configs/multi_agent_session.yaml @@ -1,21 +1,3 @@ -training_config: - rl_framework: RLLIB_multi_agent - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 2 - n_eval_episodes: 1 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: #not used :( - - defender1 - - defender2 - -io_settings: - save_checkpoints: true - checkpoint_interval: 5 - - game: max_episode_length: 128 ports: @@ -31,11 +13,12 @@ game: agents: - ref: client_2_green_user team: GREEN - type: ProbabilisticAgent + type: PeriodicAgent observation_space: null action_space: action_list: - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE options: nodes: @@ -901,86 +884,6 @@ agents: options: target_router_nodename: router_1 position: 9 - 38: - action: "HOST_NIC_DISABLE" - options: - node_id: 0 - nic_id: 0 - 39: - action: "HOST_NIC_ENABLE" - options: - node_id: 0 - nic_id: 0 - 40: - action: "HOST_NIC_DISABLE" - options: - node_id: 1 - nic_id: 0 - 41: - action: "HOST_NIC_ENABLE" - options: - node_id: 1 - nic_id: 0 - 42: - action: "HOST_NIC_DISABLE" - options: - node_id: 2 - nic_id: 0 - 43: - action: "HOST_NIC_ENABLE" - options: - node_id: 2 - nic_id: 0 - 44: - action: "HOST_NIC_DISABLE" - options: - node_id: 3 - nic_id: 0 - 45: - action: "HOST_NIC_ENABLE" - options: - node_id: 3 - nic_id: 0 - 46: - action: "HOST_NIC_DISABLE" - options: - node_id: 4 - nic_id: 0 - 47: - action: "HOST_NIC_ENABLE" - options: - node_id: 4 - nic_id: 0 - 48: - action: "HOST_NIC_DISABLE" - options: - node_id: 4 - nic_id: 1 - 49: - action: "HOST_NIC_ENABLE" - options: - node_id: 4 - nic_id: 1 - 50: - action: "HOST_NIC_DISABLE" - options: - node_id: 5 - nic_id: 0 - 51: - action: "HOST_NIC_ENABLE" - options: - node_id: 5 - nic_id: 0 - 52: - action: "HOST_NIC_DISABLE" - options: - node_id: 6 - nic_id: 0 - 53: - action: "HOST_NIC_ENABLE" - options: - node_id: 6 - nic_id: 0 options: diff --git a/tests/assets/configs/shared_rewards.yaml b/tests/assets/configs/shared_rewards.yaml index c5ba06b1..c90e1cc2 100644 --- a/tests/assets/configs/shared_rewards.yaml +++ b/tests/assets/configs/shared_rewards.yaml @@ -1,15 +1,3 @@ -training_config: - rl_framework: SB3 - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 1 - n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: - - defender - io_settings: save_agent_actions: false save_step_metadata: false diff --git a/tests/assets/configs/test_application_install.yaml b/tests/assets/configs/test_application_install.yaml index d1fed272..87402f73 100644 --- a/tests/assets/configs/test_application_install.yaml +++ b/tests/assets/configs/test_application_install.yaml @@ -1,15 +1,3 @@ -training_config: - rl_framework: SB3 - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 1 - n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: - - defender - io_settings: save_agent_actions: true save_step_metadata: false diff --git a/tests/assets/configs/test_primaite_session.yaml b/tests/assets/configs/test_primaite_session.yaml index 490e99d4..f41ef475 100644 --- a/tests/assets/configs/test_primaite_session.yaml +++ b/tests/assets/configs/test_primaite_session.yaml @@ -1,15 +1,3 @@ -training_config: - rl_framework: SB3 - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 10 - n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: - - defender - io_settings: save_agent_actions: true save_step_metadata: true @@ -568,7 +556,7 @@ agents: agent_settings: - # ... + flatten_obs: true diff --git a/tests/assets/configs/train_only_primaite_session.yaml b/tests/assets/configs/train_only_primaite_session.yaml deleted file mode 100644 index 3de2c80a..00000000 --- a/tests/assets/configs/train_only_primaite_session.yaml +++ /dev/null @@ -1,737 +0,0 @@ -training_config: - rl_framework: SB3 - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 10 - n_eval_episodes: 0 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 1 - agent_references: - - defender - - -game: - ports: - - ARP - - DNS - - HTTP - - POSTGRES_SERVER - protocols: - - ICMP - - TCP - - UDP - -agents: - - ref: client_2_green_user - team: GREEN - type: ProbabilisticAgent - observation_space: null - action_space: - action_list: - - type: DONOTHING - # - # - type: NODE_LOGON - # - type: NODE_LOGOFF - # - type: NODE_APPLICATION_EXECUTE - # options: - # execution_definition: - # target_address: arcd.com - action_map: - 0: - action: DONOTHING - options: {} - options: - nodes: - - node_name: client_2 - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_nics_per_node: 2 - max_acl_rules: 10 - - reward_function: - reward_components: - - type: DUMMY - - agent_settings: # options specific to this particular agent type, basically args of __init__(self) - start_settings: - start_step: 25 - frequency: 20 - variance: 5 - - - ref: data_manipulation_attacker - team: RED - type: RedDatabaseCorruptingAgent - - observation_space: null - - action_space: - action_list: - - type: DONOTHING - - type: NODE_APPLICATION_EXECUTE - - type: NODE_FILE_DELETE - - type: NODE_FILE_CORRUPT - - type: NODE_OS_SCAN - action_map: - 0: - action: DONOTHING - options: {} - 1: - action: NODE_APPLICATION_EXECUTE - options: - node_id: 0 - application_id: 0 - options: - nodes: - - node_name: client_1 - applications: - - application_name: DataManipulationBot - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - - reward_function: - reward_components: - - type: DUMMY - - agent_settings: # options specific to this particular agent type, basically args of __init__(self) - start_settings: - start_step: 25 - frequency: 20 - variance: 5 - - - ref: defender - team: BLUE - type: ProxyAgent - - observation_space: - type: CUSTOM - options: - components: - - type: NODES - label: NODES - options: - hosts: - - hostname: domain_controller - - hostname: web_server - services: - - service_name: WebServer - - hostname: database_server - folders: - - folder_name: database - files: - - file_name: database.db - - hostname: backup_server - - hostname: security_suite - - hostname: client_1 - - hostname: client_2 - num_services: 1 - num_applications: 0 - num_folders: 1 - num_files: 1 - num_nics: 2 - include_num_access: false - include_nmne: true - routers: - - hostname: router_1 - num_ports: 0 - ip_list: - - 192.168.1.10 - - 192.168.1.12 - - 192.168.1.14 - - 192.168.1.16 - - 192.168.1.110 - - 192.168.10.21 - - 192.168.10.22 - - 192.168.10.110 - wildcard_list: - - 0.0.0.1 - port_list: - - 80 - - 5432 - protocol_list: - - ICMP - - TCP - - UDP - num_rules: 10 - - - type: LINKS - label: LINKS - options: - link_references: - - router_1:eth-1<->switch_1:eth-8 - - router_1:eth-2<->switch_2:eth-8 - - switch_1:eth-1<->domain_controller:eth-1 - - switch_1:eth-2<->web_server:eth-1 - - switch_1:eth-3<->database_server:eth-1 - - switch_1:eth-4<->backup_server:eth-1 - - switch_1:eth-7<->security_suite:eth-1 - - switch_2:eth-1<->client_1:eth-1 - - switch_2:eth-2<->client_2:eth-1 - - switch_2:eth-7<->security_suite:eth-2 - - type: "NONE" - label: ICS - options: {} - - action_space: - action_list: - - type: DONOTHING - - type: NODE_SERVICE_SCAN - - type: NODE_SERVICE_STOP - - type: NODE_SERVICE_START - - type: NODE_SERVICE_PAUSE - - type: NODE_SERVICE_RESUME - - type: NODE_SERVICE_RESTART - - type: NODE_SERVICE_DISABLE - - type: NODE_SERVICE_ENABLE - - type: NODE_SERVICE_FIX - - type: NODE_FILE_SCAN - - type: NODE_FILE_CHECKHASH - - type: NODE_FILE_DELETE - - type: NODE_FILE_REPAIR - - type: NODE_FILE_RESTORE - - type: NODE_FOLDER_SCAN - - type: NODE_FOLDER_CHECKHASH - - type: NODE_FOLDER_REPAIR - - type: NODE_FOLDER_RESTORE - - type: NODE_OS_SCAN - - type: NODE_SHUTDOWN - - type: NODE_STARTUP - - type: NODE_RESET - - type: ROUTER_ACL_ADDRULE - - type: ROUTER_ACL_REMOVERULE - - type: HOST_NIC_ENABLE - - type: HOST_NIC_DISABLE - - action_map: - 0: - action: DONOTHING - options: {} - # scan webapp service - 1: - action: NODE_SERVICE_SCAN - options: - node_id: 1 - service_id: 0 - # stop webapp service - 2: - action: NODE_SERVICE_STOP - options: - node_id: 1 - service_id: 0 - # start webapp service - 3: - action: "NODE_SERVICE_START" - options: - node_id: 1 - service_id: 0 - 4: - action: "NODE_SERVICE_PAUSE" - options: - node_id: 1 - service_id: 0 - 5: - action: "NODE_SERVICE_RESUME" - options: - node_id: 1 - service_id: 0 - 6: - action: "NODE_SERVICE_RESTART" - options: - node_id: 1 - service_id: 0 - 7: - action: "NODE_SERVICE_DISABLE" - options: - node_id: 1 - service_id: 0 - 8: - action: "NODE_SERVICE_ENABLE" - options: - node_id: 1 - service_id: 0 - 9: # check database.db file - action: "NODE_FILE_SCAN" - options: - node_id: 2 - folder_id: 1 - file_id: 0 - 10: - action: "NODE_FILE_CHECKHASH" - options: - node_id: 2 - folder_id: 1 - file_id: 0 - 11: - action: "NODE_FILE_DELETE" - options: - node_id: 2 - folder_id: 1 - file_id: 0 - 12: - action: "NODE_FILE_REPAIR" - options: - node_id: 2 - folder_id: 1 - file_id: 0 - 13: - action: "NODE_SERVICE_FIX" - options: - node_id: 2 - service_id: 0 - 14: - action: "NODE_FOLDER_SCAN" - options: - node_id: 2 - folder_id: 1 - 15: - action: "NODE_FOLDER_CHECKHASH" - options: - node_id: 2 - folder_id: 1 - 16: - action: "NODE_FOLDER_REPAIR" - options: - node_id: 2 - folder_id: 1 - 17: - action: "NODE_FOLDER_RESTORE" - options: - node_id: 2 - folder_id: 1 - 18: - action: "NODE_OS_SCAN" - options: - node_id: 2 - 19: # shutdown client 1 - action: "NODE_SHUTDOWN" - options: - node_id: 5 - 20: - action: "NODE_STARTUP" - options: - node_id: 5 - 21: - action: "NODE_RESET" - options: - node_id: 5 - 22: # "ACL: ADDRULE - Block outgoing traffic from client 1" (not supported in Primaite) - action: "ROUTER_ACL_ADDRULE" - options: - target_router_nodename: router_1 - position: 1 - permission: 2 - source_ip_id: 7 # client 1 - dest_ip_id: 1 # ALL - source_port_id: 1 - dest_port_id: 1 - protocol_id: 1 - source_wildcard_id: 0 - dest_wildcard_id: 0 - 23: # "ACL: ADDRULE - Block outgoing traffic from client 2" (not supported in Primaite) - action: "ROUTER_ACL_ADDRULE" - options: - target_router_nodename: router_1 - position: 2 - permission: 2 - source_ip_id: 8 # client 2 - dest_ip_id: 1 # ALL - source_port_id: 1 - dest_port_id: 1 - protocol_id: 1 - source_wildcard_id: 0 - dest_wildcard_id: 0 - 24: # block tcp traffic from client 1 to web app - action: "ROUTER_ACL_ADDRULE" - options: - target_router_nodename: router_1 - position: 3 - permission: 2 - source_ip_id: 7 # client 1 - dest_ip_id: 3 # web server - source_port_id: 1 - dest_port_id: 1 - protocol_id: 3 - source_wildcard_id: 0 - dest_wildcard_id: 0 - 25: # block tcp traffic from client 2 to web app - action: "ROUTER_ACL_ADDRULE" - options: - target_router_nodename: router_1 - position: 4 - permission: 2 - source_ip_id: 8 # client 2 - dest_ip_id: 3 # web server - source_port_id: 1 - dest_port_id: 1 - protocol_id: 3 - source_wildcard_id: 0 - dest_wildcard_id: 0 - 26: - action: "ROUTER_ACL_ADDRULE" - options: - target_router_nodename: router_1 - position: 5 - permission: 2 - source_ip_id: 7 # client 1 - dest_ip_id: 4 # database - source_port_id: 1 - dest_port_id: 1 - protocol_id: 3 - source_wildcard_id: 0 - dest_wildcard_id: 0 - 27: - action: "ROUTER_ACL_ADDRULE" - options: - target_router_nodename: router_1 - position: 6 - permission: 2 - source_ip_id: 8 # client 2 - dest_ip_id: 4 # database - source_port_id: 1 - dest_port_id: 1 - protocol_id: 3 - source_wildcard_id: 0 - dest_wildcard_id: 0 - 28: - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 0 - 29: - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 1 - 30: - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 2 - 31: - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 3 - 32: - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 4 - 33: - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 5 - 34: - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 6 - 35: - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 7 - 36: - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 8 - 37: - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 9 - 38: - action: "HOST_NIC_DISABLE" - options: - node_id: 0 - nic_id: 0 - 39: - action: "HOST_NIC_ENABLE" - options: - node_id: 0 - nic_id: 0 - 40: - action: "HOST_NIC_DISABLE" - options: - node_id: 1 - nic_id: 0 - 41: - action: "HOST_NIC_ENABLE" - options: - node_id: 1 - nic_id: 0 - 42: - action: "HOST_NIC_DISABLE" - options: - node_id: 2 - nic_id: 0 - 43: - action: "HOST_NIC_ENABLE" - options: - node_id: 2 - nic_id: 0 - 44: - action: "HOST_NIC_DISABLE" - options: - node_id: 3 - nic_id: 0 - 45: - action: "HOST_NIC_ENABLE" - options: - node_id: 3 - nic_id: 0 - 46: - action: "HOST_NIC_DISABLE" - options: - node_id: 4 - nic_id: 0 - 47: - action: "HOST_NIC_ENABLE" - options: - node_id: 4 - nic_id: 0 - 48: - action: "HOST_NIC_DISABLE" - options: - node_id: 4 - nic_id: 1 - 49: - action: "HOST_NIC_ENABLE" - options: - node_id: 4 - nic_id: 1 - 50: - action: "HOST_NIC_DISABLE" - options: - node_id: 5 - nic_id: 0 - 51: - action: "HOST_NIC_ENABLE" - options: - node_id: 5 - nic_id: 0 - 52: - action: "HOST_NIC_DISABLE" - options: - node_id: 6 - nic_id: 0 - 53: - action: "HOST_NIC_ENABLE" - options: - node_id: 6 - nic_id: 0 - - - options: - nodes: - - node_name: domain_controller - - node_name: web_server - - node_name: database_server - - node_name: backup_server - - node_name: security_suite - - node_name: client_1 - - node_name: client_2 - max_folders_per_node: 2 - max_files_per_folder: 2 - max_services_per_node: 2 - max_nics_per_node: 8 - max_acl_rules: 10 - ip_list: - - 192.168.1.10 - - 192.168.1.12 - - 192.168.1.14 - - 192.168.1.16 - - 192.168.1.110 - - 192.168.10.21 - - 192.168.10.22 - - 192.168.10.110 - - reward_function: - reward_components: - - type: DATABASE_FILE_INTEGRITY - weight: 0.5 - options: - node_hostname: database_server - folder_name: database - file_name: database.db - - - - type: WEB_SERVER_404_PENALTY - weight: 0.5 - options: - node_hostname: web_server - service_name: web_service - - - agent_settings: - # ... - - - - - -simulation: - network: - nodes: - - - type: router - hostname: router_1 - num_ports: 5 - ports: - 1: - ip_address: 192.168.1.1 - subnet_mask: 255.255.255.0 - 2: - ip_address: 192.168.1.1 - subnet_mask: 255.255.255.0 - acl: - 0: - action: PERMIT - src_port: POSTGRES_SERVER - dst_port: POSTGRES_SERVER - 1: - action: PERMIT - src_port: DNS - dst_port: DNS - 22: - action: PERMIT - src_port: ARP - dst_port: ARP - 23: - action: PERMIT - protocol: ICMP - - - type: switch - hostname: switch_1 - num_ports: 8 - - - type: switch - hostname: switch_2 - num_ports: 8 - - - type: server - hostname: domain_controller - ip_address: 192.168.1.10 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.1 - services: - - type: DNSServer - options: - domain_mapping: - arcd.com: 192.168.1.12 # web server - - - type: server - hostname: web_server - ip_address: 192.168.1.12 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.1 - dns_server: 192.168.1.10 - services: - - type: WebServer - applications: - - type: DatabaseClient - options: - db_server_ip: 192.168.1.14 - - - - type: server - hostname: database_server - ip_address: 192.168.1.14 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.1 - dns_server: 192.168.1.10 - services: - - type: DatabaseService - - - type: server - hostname: backup_server - ip_address: 192.168.1.16 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.1 - dns_server: 192.168.1.10 - services: - - type: FTPServer - - - type: server - hostname: security_suite - ip_address: 192.168.1.110 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.1 - dns_server: 192.168.1.10 - network_interfaces: - 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot - ip_address: 192.168.10.110 - subnet_mask: 255.255.255.0 - - - type: computer - hostname: client_1 - ip_address: 192.168.10.21 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.10.1 - dns_server: 192.168.1.10 - applications: - - type: DataManipulationBot - options: - port_scan_p_of_success: 0.1 - data_manipulation_p_of_success: 0.1 - payload: "DELETE" - server_ip: 192.168.1.14 - services: - - type: DNSClient - - - type: computer - hostname: client_2 - ip_address: 192.168.10.22 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.10.1 - dns_server: 192.168.1.10 - applications: - - type: WebBrowser - services: - - type: DNSClient - - links: - - endpoint_a_hostname: router_1 - endpoint_a_port: 1 - endpoint_b_hostname: switch_1 - endpoint_b_port: 8 - - endpoint_a_hostname: router_1 - endpoint_a_port: 2 - endpoint_b_hostname: switch_2 - endpoint_b_port: 8 - - endpoint_a_hostname: switch_1 - endpoint_a_port: 1 - endpoint_b_hostname: domain_controller - endpoint_b_port: 1 - - endpoint_a_hostname: switch_1 - endpoint_a_port: 2 - endpoint_b_hostname: web_server - endpoint_b_port: 1 - - endpoint_a_hostname: switch_1 - endpoint_a_port: 3 - endpoint_b_hostname: database_server - endpoint_b_port: 1 - - endpoint_a_hostname: switch_1 - endpoint_a_port: 4 - endpoint_b_hostname: backup_server - endpoint_b_port: 1 - - endpoint_a_hostname: switch_1 - endpoint_a_port: 7 - endpoint_b_hostname: security_suite - endpoint_b_port: 1 - - endpoint_a_hostname: switch_2 - endpoint_a_port: 1 - endpoint_b_hostname: client_1 - endpoint_b_port: 1 - - endpoint_a_hostname: switch_2 - endpoint_a_port: 2 - endpoint_b_hostname: client_2 - endpoint_b_port: 1 - - endpoint_a_hostname: switch_2 - endpoint_a_port: 7 - endpoint_b_hostname: security_suite - endpoint_b_port: 2 diff --git a/tests/conftest.py b/tests/conftest.py index 018dcb70..7de2bfde 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,7 +13,6 @@ from primaite.game.agent.interface import AbstractAgent from primaite.game.agent.observations.observation_manager import NestedObservation, ObservationManager from primaite.game.agent.rewards import RewardFunction from primaite.game.game import PrimaiteGame -from primaite.session.session import PrimaiteSession from primaite.simulator import SIM_OUTPUT from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.container import Network @@ -121,38 +120,6 @@ def file_system() -> FileSystem: return computer.file_system -# PrimAITE v2 stuff -class TempPrimaiteSession(PrimaiteSession): - """ - A temporary PrimaiteSession class. - - Uses context manager for deletion of files upon exit. - """ - - @classmethod - def from_config(cls, config_path: Union[str, Path]) -> "TempPrimaiteSession": - """Create a temporary PrimaiteSession object from a config file.""" - config_path = Path(config_path) - with open(config_path, "r") as f: - config = yaml.safe_load(f) - - return super().from_config(cfg=config) - - def __enter__(self): - return self - - def __exit__(self, type, value, tb): - pass - - -@pytest.fixture -def temp_primaite_session(request, monkeypatch) -> TempPrimaiteSession: - """Create a temporary PrimaiteSession object.""" - monkeypatch.setattr(PRIMAITE_PATHS, "user_sessions_path", temp_user_sessions_path()) - config_path = request.param[0] - return TempPrimaiteSession.from_config(config_path=config_path) - - @pytest.fixture(scope="function") def client_server() -> Tuple[Computer, Server]: network = Network() diff --git a/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py b/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py index 84897f9a..712a16c4 100644 --- a/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py +++ b/tests/e2e_integration_tests/environments/test_rllib_multi_agent_environment.py @@ -1,33 +1,28 @@ -import pytest import ray import yaml from ray import air, tune from ray.rllib.algorithms.ppo import PPOConfig -from primaite.config.load import data_manipulation_config_path -from primaite.game.game import PrimaiteGame from primaite.session.environment import PrimaiteRayMARLEnv +from tests import TEST_ASSETS_ROOT + +MULTI_AGENT_PATH = TEST_ASSETS_ROOT / "configs/multi_agent_session.yaml" -@pytest.mark.skip(reason="Slow, reenable later") def test_rllib_multi_agent_compatibility(): """Test that the PrimaiteRayEnv class can be used with a multi agent RLLIB system.""" - with open(data_manipulation_config_path(), "r") as f: + with open(MULTI_AGENT_PATH, "r") as f: cfg = yaml.safe_load(f) - game = PrimaiteGame.from_config(cfg) - - ray.shutdown() ray.init() - env_config = {"game": game} config = ( PPOConfig() - .environment(env=PrimaiteRayMARLEnv, env_config={"game": game}) + .environment(env=PrimaiteRayMARLEnv, env_config=cfg) .rollouts(num_rollout_workers=0) .multi_agent( - policies={agent.agent_name for agent in game.rl_agents}, + policies={agent["ref"] for agent in cfg["agents"]}, policy_mapping_fn=lambda agent_id, episode, worker, **kw: agent_id, ) .training(train_batch_size=128) diff --git a/tests/e2e_integration_tests/test_environment.py b/tests/e2e_integration_tests/test_environment.py new file mode 100644 index 00000000..673e1dc4 --- /dev/null +++ b/tests/e2e_integration_tests/test_environment.py @@ -0,0 +1,91 @@ +import pydantic +import pytest +import yaml +from gymnasium.core import ObsType +from numpy import ndarray + +from primaite.session.environment import PrimaiteGymEnv, PrimaiteRayMARLEnv +from primaite.simulator.network.hardware.nodes.host.server import Printer +from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter +from tests import TEST_ASSETS_ROOT + +CFG_PATH = TEST_ASSETS_ROOT / "configs/test_primaite_session.yaml" +TRAINING_ONLY_PATH = TEST_ASSETS_ROOT / "configs/train_only_primaite_session.yaml" +EVAL_ONLY_PATH = TEST_ASSETS_ROOT / "configs/eval_only_primaite_session.yaml" +MISCONFIGURED_PATH = TEST_ASSETS_ROOT / "configs/bad_primaite_session.yaml" +MULTI_AGENT_PATH = TEST_ASSETS_ROOT / "configs/multi_agent_session.yaml" + + +class TestPrimaiteEnvironment: + def test_creating_env(self): + """Check that environment loads correctly from config and it can be reset.""" + with open(CFG_PATH, "r") as f: + cfg = yaml.safe_load(f) + env = PrimaiteGymEnv(game_config=cfg) + + def env_checks(): + assert env is not None + assert env.game.simulation + assert len(env.game.agents) == 3 + assert len(env.game.rl_agents) == 1 + + assert env.game.simulation.network + assert len(env.game.simulation.network.nodes) == 12 + wireless = env.game.simulation.network.get_node_by_hostname("router_2") + assert isinstance(wireless, WirelessRouter) + printer = env.game.simulation.network.get_node_by_hostname("HP_LaserJet_Pro_4102fdn_printer") + assert isinstance(printer, Printer) + + env_checks() + env.reset() + env_checks() + + def test_step_env(self): + """Make sure you can go all the way through the session without errors.""" + with open(CFG_PATH, "r") as f: + cfg = yaml.safe_load(f) + env = PrimaiteGymEnv(game_config=cfg) + + assert (num_actions := len(env.agent.action_manager.action_map)) == 54 + # run every action and make sure there's no crash + for act in range(num_actions): + env.step(act) + # try running action number outside the action map to check that it fails. + with pytest.raises(KeyError): + env.step(num_actions) + + obs, rew, trunc, term, info = env.step(0) + assert isinstance(obs, ndarray) + + def test_multi_agent_env(self): + """Check that we can run a training session with a multi agent system.""" + with open(MULTI_AGENT_PATH, "r") as f: + cfg = yaml.safe_load(f) + env = PrimaiteRayMARLEnv(env_config=cfg) + + assert set(env._agent_ids) == {"defender1", "defender2"} + + assert len(env.agents) == 2 + defender1 = env.agents["defender1"] + defender2 = env.agents["defender2"] + assert (num_actions_1 := len(defender1.action_manager.action_map)) == 54 + assert (num_actions_2 := len(defender2.action_manager.action_map)) == 38 + + # ensure we can run all valid actions without error + for act_1 in range(num_actions_1): + env.step({"defender1": act_1, "defender2": 0}) + for act_2 in range(num_actions_2): + env.step({"defender1": 0, "defender2": act_2}) + + # ensure we get error when taking an invalid action + with pytest.raises(KeyError): + env.step({"defender1": num_actions_1, "defender2": 0}) + with pytest.raises(KeyError): + env.step({"defender1": 0, "defender2": num_actions_2}) + + def test_error_thrown_on_bad_configuration(self): + """Make sure we throw an error when the config is bad.""" + with open(MISCONFIGURED_PATH, "r") as f: + cfg = yaml.safe_load(f) + with pytest.raises(pydantic.ValidationError): + env = PrimaiteGymEnv(game_config=cfg) diff --git a/tests/e2e_integration_tests/test_primaite_session.py b/tests/e2e_integration_tests/test_primaite_session.py deleted file mode 100644 index d115f255..00000000 --- a/tests/e2e_integration_tests/test_primaite_session.py +++ /dev/null @@ -1,109 +0,0 @@ -import pydantic -import pytest - -from primaite.simulator.network.hardware.nodes.host.server import Printer -from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter -from tests import TEST_ASSETS_ROOT -from tests.conftest import TempPrimaiteSession - -CFG_PATH = TEST_ASSETS_ROOT / "configs/test_primaite_session.yaml" -TRAINING_ONLY_PATH = TEST_ASSETS_ROOT / "configs/train_only_primaite_session.yaml" -EVAL_ONLY_PATH = TEST_ASSETS_ROOT / "configs/eval_only_primaite_session.yaml" -MISCONFIGURED_PATH = TEST_ASSETS_ROOT / "configs/bad_primaite_session.yaml" -MULTI_AGENT_PATH = TEST_ASSETS_ROOT / "configs/multi_agent_session.yaml" - - -@pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") -class TestPrimaiteSession: - @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") - @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) - def test_creating_session(self, temp_primaite_session): - """Check that creating a session from config works.""" - with temp_primaite_session as session: - if not isinstance(session, TempPrimaiteSession): - raise AssertionError - - assert session is not None - assert session.env.game.simulation - assert len(session.env.game.agents) == 3 - assert len(session.env.game.rl_agents) == 1 - - assert session.policy - assert session.env - - assert session.env.game.simulation.network - assert len(session.env.game.simulation.network.nodes) == 12 - wireless = session.env.game.simulation.network.get_node_by_hostname("router_2") - assert isinstance(wireless, WirelessRouter) - printer = session.env.game.simulation.network.get_node_by_hostname("HP_LaserJet_Pro_4102fdn_printer") - assert isinstance(printer, Printer) - - @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") - @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) - def test_start_session(self, temp_primaite_session): - """Make sure you can go all the way through the session without errors.""" - with temp_primaite_session as session: - session: TempPrimaiteSession - session.start_session() - - session_path = session.io_manager.session_path - assert session_path.exists() - print(list(session_path.glob("*"))) - checkpoint_dir = session_path / "checkpoints" / "sb3_final" - assert checkpoint_dir.exists() - checkpoint_1 = checkpoint_dir / "sb3_model_640_steps.zip" - checkpoint_2 = checkpoint_dir / "sb3_model_1280_steps.zip" - checkpoint_3 = checkpoint_dir / "sb3_model_1920_steps.zip" - assert checkpoint_1.exists() - assert checkpoint_2.exists() - assert not checkpoint_3.exists() - - @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") - @pytest.mark.parametrize("temp_primaite_session", [[TRAINING_ONLY_PATH]], indirect=True) - def test_training_only_session(self, temp_primaite_session): - """Check that you can run a training-only session.""" - with temp_primaite_session as session: - session: TempPrimaiteSession - session.start_session() - # TODO: include checks that the model was trained, e.g. that the loss changed and checkpoints were saved? - - @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") - @pytest.mark.parametrize("temp_primaite_session", [[EVAL_ONLY_PATH]], indirect=True) - def test_eval_only_session(self, temp_primaite_session): - """Check that you can load a model and run an eval-only session.""" - with temp_primaite_session as session: - session: TempPrimaiteSession - session.start_session() - # TODO: include checks that the model was loaded and that the eval-only session ran - - @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") - @pytest.mark.skip(reason="Slow, reenable later") - @pytest.mark.parametrize("temp_primaite_session", [[MULTI_AGENT_PATH]], indirect=True) - def test_multi_agent_session(self, temp_primaite_session): - """Check that we can run a training session with a multi agent system.""" - with temp_primaite_session as session: - session.start_session() - - @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") - def test_error_thrown_on_bad_configuration(self): - with pytest.raises(pydantic.ValidationError): - session = TempPrimaiteSession.from_config(MISCONFIGURED_PATH) - - @pytest.mark.skip(reason="Session is not being maintained and will be removed in the subsequent beta release.") - @pytest.mark.skip( - reason="Currently software cannot be dynamically created/destroyed during simulation. Therefore, " - "reset doesn't implement software restore." - ) - @pytest.mark.parametrize("temp_primaite_session", [[CFG_PATH]], indirect=True) - def test_session_sim_reset(self, temp_primaite_session): - with temp_primaite_session as session: - session: TempPrimaiteSession - client_1 = session.game.simulation.network.get_node_by_hostname("client_1") - client_1.software_manager.uninstall("DataManipulationBot") - - assert "DataManipulationBot" not in client_1.software_manager.software - - session.game.reset() - client_1 = session.game.simulation.network.get_node_by_hostname("client_1") - - assert "DataManipulationBot" in client_1.software_manager.software From 7c0a7702c490c8fa9bb7abe7a3d78bf18bb449f9 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 16 Apr 2024 11:39:13 +0100 Subject: [PATCH 814/980] #2374 update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d95b6315..d30ae5e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 3.0.0b9 +- Removed deprecated `PrimaiteSession` class. + ## [Unreleased] - Made requests fail to reach their target if the node is off - Added responses to requests From db56eea4ce569addeee401501db09d8c90681ecc Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 16 Apr 2024 13:20:07 +0100 Subject: [PATCH 815/980] #2374 Update readme and minor fix to yaml --- README.md | 36 ++++++++++++------- .../_package_data/data_manipulation_marl.yaml | 2 +- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7dfe15bd..2265538a 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ PrimAITE presents the following features: ## Getting Started with PrimAITE -### 💫 Install & Run +### 💫 Installation **PrimAITE** is designed to be OS-agnostic, and thus should work on most variations/distros of Linux, Windows, and MacOS. Currently, the PrimAITE wheel can only be installed from GitHub. This may change in the future with release to PyPi. @@ -47,11 +47,6 @@ pip install https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/relea primaite setup ``` -**Run:** - -``` bash -primaite session -``` #### Unix @@ -75,12 +70,6 @@ pip install https://github.com/Autonomous-Resilient-Cyber-Defence/PrimAITE/relea primaite setup ``` -**Run:** - -``` bash -primaite session -``` - ### Developer Install from Source @@ -125,6 +114,29 @@ python3 -m pip install -e .[dev] primaite setup ``` +### Running PrimAITE + +Use the provided jupyter notebooks as a starting point to try running PrimAITE. They are automatically copied to your PrimAITE notebook folder when you run `primaite setup`. + +#### 1. Activate the virtual environment + +##### Windows (Powershell) +```powershell +.\venv\Scripts\activate +``` + +##### Unix +```bash +source venv/bin/activate +``` + +#### 2. Open jupyter notebook + +```bash +python -m jupyter notebook +``` +Then, click the URL provided by the jupyter command to open the jupyter application in your browser. You can also open notebooks in your IDE if supported. + ## 📚 Building documentation The PrimAITE documentation can be built with the following commands: diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index cb94a128..359d7c55 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -1458,7 +1458,7 @@ simulation: options: db_server_ip: 192.168.1.14 services: - - ty DNSClient + - type: DNSClient From 4903c77f6513bf46c32686c32fe71cf390d93ea2 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Tue, 16 Apr 2024 14:17:58 +0100 Subject: [PATCH 816/980] #2455: Add missing source_wildcard_id and dest_wildcard_id data. --- .../_package_data/data_manipulation_marl.yaml | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index 6c9ac64e..45779036 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -1,17 +1,3 @@ -training_config: - rl_framework: RLLIB_multi_agent - rl_algorithm: PPO - seed: 333 - n_learn_episodes: 1 - n_eval_episodes: 5 - max_steps_per_episode: 128 - deterministic_eval: false - n_agents: 2 - agent_references: - - defender_1 - - defender_2 - - io_settings: save_agent_actions: true save_step_metadata: false @@ -1075,6 +1061,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" action: "ROUTER_ACL_ADDRULE" options: @@ -1086,6 +1074,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 48: # old action num: 24 # block tcp traffic from client 1 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -1097,6 +1087,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 49: # old action num: 25 # block tcp traffic from client 2 to web app action: "ROUTER_ACL_ADDRULE" options: @@ -1108,6 +1100,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 50: # old action num: 26 action: "ROUTER_ACL_ADDRULE" options: @@ -1119,6 +1113,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 51: # old action num: 27 action: "ROUTER_ACL_ADDRULE" options: @@ -1130,6 +1126,8 @@ agents: source_port_id: 1 dest_port_id: 1 protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 52: # old action num: 28 action: "ROUTER_ACL_REMOVERULE" options: From 750cc98703105f6571c9313345ebd993cf5bd5bc Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Tue, 16 Apr 2024 16:52:36 +0100 Subject: [PATCH 817/980] #2453 - Actioning review comments --- .../simulator/_package_data/create-simulation_demo.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb index 937e9831..06ecd4be 100644 --- a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb +++ b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb @@ -6,7 +6,7 @@ "source": [ "# Build a simulation using the Python API\n", "\n", - "Currently, this notbook manipulates the simulation by directly placing objects inside of the attributes of the network and domain. It should be refactored when proper methods exist for adding these objects.\n" + "Currently, this notebook manipulates the simulation by directly placing objects inside of the attributes of the network and domain. It should be refactored when proper methods exist for adding these objects.\n" ] }, { @@ -261,7 +261,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.10.11" } }, "nbformat": 4, From 999044a4441497abafdf8511e2cdd75a1f42ce0d Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Wed, 17 Apr 2024 10:44:44 +0100 Subject: [PATCH 818/980] 2453 - removal of notebook metadata --- .../simulator/_package_data/network_simulator_demo.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb index 462ee625..7f4cf3b1 100644 --- a/src/primaite/simulator/_package_data/network_simulator_demo.ipynb +++ b/src/primaite/simulator/_package_data/network_simulator_demo.ipynb @@ -466,7 +466,7 @@ "source": [ "## Advanced Network Usage\n", "\n", - "We can now use the Network to perform some more advaced things." + "We can now use the Network to perform some more advanced things." ] }, { From b57deaf9e1e1845d64e05a9e92a2b84626ff1760 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 17 Apr 2024 18:13:00 +0100 Subject: [PATCH 819/980] #2470: implementing log levels into sys log --- src/primaite/simulator/__init__.py | 19 +++ src/primaite/simulator/system/core/sys_log.py | 17 +- .../_simulator/_system/core/test_sys_log.py | 149 ++++++++++++++++++ 3 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 tests/unit_tests/_primaite/_simulator/_system/core/test_sys_log.py diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index 9e2ce9a1..cfae2ab7 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -1,5 +1,6 @@ """Warning: SIM_OUTPUT is a mutable global variable for the simulation output directory.""" from datetime import datetime +from enum import Enum from pathlib import Path from primaite import _PRIMAITE_ROOT @@ -7,6 +8,23 @@ from primaite import _PRIMAITE_ROOT __all__ = ["SIM_OUTPUT"] +class LogLevel(Enum): + """Enum containing all the available log levels for PrimAITE simulation output.""" + + OFF = 999 + """No logs will be output to terminal or log file.""" + DEBUG = 1 + """Debug items will be output to terminal or log file.""" + INFO = 2 + """Info items will be output to terminal or log file.""" + WARNING = 3 + """Warnings will be output to terminal or log file.""" + ERROR = 4 + """Errors will be output to terminal or log file.""" + CRITICAL = 5 + """Critical errors will be output to terminal or log file.""" + + class _SimOutput: def __init__(self): self._path: Path = ( @@ -15,6 +33,7 @@ class _SimOutput: self.save_pcap_logs: bool = False self.save_sys_logs: bool = False self.write_sys_log_to_terminal: bool = False + self.log_level: LogLevel = LogLevel.INFO # default log level is at INFO @property def path(self) -> Path: diff --git a/src/primaite/simulator/system/core/sys_log.py b/src/primaite/simulator/system/core/sys_log.py index c10f7d3c..775f9b30 100644 --- a/src/primaite/simulator/system/core/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -3,7 +3,7 @@ from pathlib import Path from prettytable import MARKDOWN, PrettyTable -from primaite.simulator import SIM_OUTPUT +from primaite.simulator import LogLevel, SIM_OUTPUT class _NotJSONFilter(logging.Filter): @@ -99,6 +99,9 @@ class SysLog: :param msg: The message to be logged. :param to_terminal: If True, prints to the terminal too. """ + if SIM_OUTPUT.log_level.value > LogLevel.DEBUG.value: + return + if SIM_OUTPUT.save_sys_logs: self.logger.debug(msg) self._write_to_terminal(msg, "DEBUG", to_terminal) @@ -110,6 +113,9 @@ class SysLog: :param msg: The message to be logged. :param to_terminal: If True, prints to the terminal too. """ + if SIM_OUTPUT.log_level.value > LogLevel.INFO.value: + return + if SIM_OUTPUT.save_sys_logs: self.logger.info(msg) self._write_to_terminal(msg, "INFO", to_terminal) @@ -121,6 +127,9 @@ class SysLog: :param msg: The message to be logged. :param to_terminal: If True, prints to the terminal too. """ + if SIM_OUTPUT.log_level.value > LogLevel.WARNING.value: + return + if SIM_OUTPUT.save_sys_logs: self.logger.warning(msg) self._write_to_terminal(msg, "WARNING", to_terminal) @@ -132,6 +141,9 @@ class SysLog: :param msg: The message to be logged. :param to_terminal: If True, prints to the terminal too. """ + if SIM_OUTPUT.log_level.value > LogLevel.ERROR.value: + return + if SIM_OUTPUT.save_sys_logs: self.logger.error(msg) self._write_to_terminal(msg, "ERROR", to_terminal) @@ -143,6 +155,9 @@ class SysLog: :param msg: The message to be logged. :param to_terminal: If True, prints to the terminal too. """ + if LogLevel.CRITICAL.value < SIM_OUTPUT.log_level.value: + return + if SIM_OUTPUT.save_sys_logs: self.logger.critical(msg) self._write_to_terminal(msg, "CRITICAL", to_terminal) diff --git a/tests/unit_tests/_primaite/_simulator/_system/core/test_sys_log.py b/tests/unit_tests/_primaite/_simulator/_system/core/test_sys_log.py new file mode 100644 index 00000000..610aad1c --- /dev/null +++ b/tests/unit_tests/_primaite/_simulator/_system/core/test_sys_log.py @@ -0,0 +1,149 @@ +from uuid import uuid4 + +import pytest + +from primaite.simulator import LogLevel, SIM_OUTPUT +from primaite.simulator.system.core.sys_log import SysLog + + +@pytest.fixture(scope="function") +def syslog() -> SysLog: + return SysLog(hostname="test") + + +def test_off_log_level(syslog, capsys): + """Test that the debug log level logs debug syslogs and above.""" + SIM_OUTPUT.log_level = LogLevel.OFF + SIM_OUTPUT.write_sys_log_to_terminal = True + + test_string = str(uuid4()) + + syslog.debug(test_string) + syslog.info(test_string) + syslog.warning(test_string) + syslog.error(test_string) + syslog.critical(test_string) + + captured = "".join(capsys.readouterr()) + + assert test_string not in captured + assert "DEBUG" not in captured + assert "INFO" not in captured + assert "WARNING" not in captured + assert "ERROR" not in captured + assert "CRITICAL" not in captured + + +def test_debug_log_level(syslog, capsys): + """Test that the debug log level logs debug syslogs and above.""" + SIM_OUTPUT.log_level = LogLevel.DEBUG + SIM_OUTPUT.write_sys_log_to_terminal = True + + test_string = str(uuid4()) + + syslog.debug(test_string) + syslog.info(test_string) + syslog.warning(test_string) + syslog.error(test_string) + syslog.critical(test_string) + + captured = "".join(capsys.readouterr()) + + assert test_string in captured + assert "DEBUG" in captured + assert "INFO" in captured + assert "WARNING" in captured + assert "ERROR" in captured + assert "CRITICAL" in captured + + +def test_info_log_level(syslog, capsys): + """Test that the debug log level logs debug syslogs and above.""" + SIM_OUTPUT.log_level = LogLevel.INFO + SIM_OUTPUT.write_sys_log_to_terminal = True + + test_string = str(uuid4()) + + syslog.debug(test_string) + syslog.info(test_string) + syslog.warning(test_string) + syslog.error(test_string) + syslog.critical(test_string) + + captured = "".join(capsys.readouterr()) + + assert test_string in captured + assert "DEBUG" not in captured + assert "INFO" in captured + assert "WARNING" in captured + assert "ERROR" in captured + assert "CRITICAL" in captured + + +def test_warning_log_level(syslog, capsys): + """Test that the debug log level logs debug syslogs and above.""" + SIM_OUTPUT.log_level = LogLevel.WARNING + SIM_OUTPUT.write_sys_log_to_terminal = True + + test_string = str(uuid4()) + + syslog.debug(test_string) + syslog.info(test_string) + syslog.warning(test_string) + syslog.error(test_string) + syslog.critical(test_string) + + captured = "".join(capsys.readouterr()) + + assert test_string in captured + assert "DEBUG" not in captured + assert "INFO" not in captured + assert "WARNING" in captured + assert "ERROR" in captured + assert "CRITICAL" in captured + + +def test_error_log_level(syslog, capsys): + """Test that the debug log level logs debug syslogs and above.""" + SIM_OUTPUT.log_level = LogLevel.ERROR + SIM_OUTPUT.write_sys_log_to_terminal = True + + test_string = str(uuid4()) + + syslog.debug(test_string) + syslog.info(test_string) + syslog.warning(test_string) + syslog.error(test_string) + syslog.critical(test_string) + + captured = "".join(capsys.readouterr()) + + assert test_string in captured + assert "DEBUG" not in captured + assert "INFO" not in captured + assert "WARNING" not in captured + assert "ERROR" in captured + assert "CRITICAL" in captured + + +def test_critical_log_level(syslog, capsys): + """Test that the debug log level logs debug syslogs and above.""" + SIM_OUTPUT.log_level = LogLevel.CRITICAL + SIM_OUTPUT.write_sys_log_to_terminal = True + + test_string = str(uuid4()) + + syslog.debug(test_string) + syslog.info(test_string) + syslog.warning(test_string) + syslog.error(test_string) + syslog.critical(test_string) + + captured = "".join(capsys.readouterr()) + + assert test_string in captured + assert "DEBUG" not in captured + assert "INFO" not in captured + assert "WARNING" not in captured + assert "ERROR" not in captured + assert "CRITICAL" in captured From 49be3b36391fa95a61205a387445a7b5fc92c561 Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Thu, 18 Apr 2024 10:23:26 +0100 Subject: [PATCH 820/980] #2453 - Updates to Training-an-SB3-agent.ipynb following review --- src/primaite/notebooks/Training-an-SB3-Agent.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/primaite/notebooks/Training-an-SB3-Agent.ipynb b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb index 8d6789ee..8e18c5c1 100644 --- a/src/primaite/notebooks/Training-an-SB3-Agent.ipynb +++ b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb @@ -48,9 +48,9 @@ "from stable_baselines3 import PPO\n", "\n", "EPISODE_LEN = 128\n", - "NO_STEPS = EPISODE_LEN * 10\n", - "BATCH_SIZE = EPISODE_LEN * 10\n", - "TOTAL_TIMESTEPS = 5e3 * EPISODE_LEN\n", + "NUM_EPISODES = 10\n", + "NO_STEPS = EPISODE_LEN * NUM_EPISODES\n", + "BATCH_SIZE = 32\n", "LEARNING_RATE = 3e-4" ] }, @@ -69,7 +69,7 @@ "metadata": {}, "outputs": [], "source": [ - "model.learn(total_timesteps=TOTAL_TIMESTEPS)\n" + "model.learn(total_timesteps=NO_STEPS)\n" ] }, { From bb88d43b90e0eec249c7af6815dabe9718b8a987 Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Thu, 18 Apr 2024 13:50:47 +0100 Subject: [PATCH 821/980] #2453 - Updating with some explanation to improve the readability of the notebook --- .../notebooks/Training-an-SB3-Agent.ipynb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/primaite/notebooks/Training-an-SB3-Agent.ipynb b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb index 8e18c5c1..59fd46c4 100644 --- a/src/primaite/notebooks/Training-an-SB3-Agent.ipynb +++ b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb @@ -1,5 +1,16 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Training an SB3 Agent\n", + "\n", + "This notebook will demonstrate how to use primaite to create and train a PPO agent.\n", + "\n", + "#### First, import `PrimaiteGymEnv` and read our config file" + ] + }, { "cell_type": "code", "execution_count": null, @@ -69,7 +80,8 @@ "metadata": {}, "outputs": [], "source": [ - "model.learn(total_timesteps=NO_STEPS)\n" + "model.learn(total_timesteps=NO_STEPS)\n", + "model.save(\"PrimAITE-PPO-example-agent\")" ] }, { @@ -78,7 +90,7 @@ "metadata": {}, "outputs": [], "source": [ - "model.save(\"PrimAITE-v3.0.0b7-PPO\")" + "model.save(\"PrimAITE-PPO-example-agent\")" ] }, { @@ -88,7 +100,7 @@ "outputs": [], "source": [ "eval_model = PPO(\"MlpPolicy\", gym)\n", - "eval_model = PPO.load(\"PrimAITE-v3.0.0b7-PPO\", gym)" + "eval_model = PPO.load(\"PrimAITE-PPO-example-agent\", gym)" ] }, { From abf94fc4bb23e56e53ad3066b17b0067e3dbdd18 Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Thu, 18 Apr 2024 13:52:43 +0100 Subject: [PATCH 822/980] #2453 - Committing additional explanations to notebook --- .../notebooks/Training-an-SB3-Agent.ipynb | 60 ++++++++++++++++--- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/src/primaite/notebooks/Training-an-SB3-Agent.ipynb b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb index 59fd46c4..140df1b8 100644 --- a/src/primaite/notebooks/Training-an-SB3-Agent.ipynb +++ b/src/primaite/notebooks/Training-an-SB3-Agent.ipynb @@ -6,9 +6,14 @@ "source": [ "# Training an SB3 Agent\n", "\n", - "This notebook will demonstrate how to use primaite to create and train a PPO agent.\n", - "\n", - "#### First, import `PrimaiteGymEnv` and read our config file" + "This notebook will demonstrate how to use primaite to create and train a PPO agent, using a pre-defined configuration file." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### First, we import the inital packages and read in our configuration file." ] }, { @@ -38,7 +43,14 @@ "outputs": [], "source": [ "with open(data_manipulation_config_path(), 'r') as f:\n", - " cfg = yaml.safe_load(f)\n" + " cfg = yaml.safe_load(f)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using the given configuration, we generate the environment our agent will train in." ] }, { @@ -50,6 +62,13 @@ "gym = PrimaiteGymEnv(game_config=cfg)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Lets define training parameters for the agent." + ] + }, { "cell_type": "code", "execution_count": null, @@ -71,7 +90,14 @@ "metadata": {}, "outputs": [], "source": [ - "model = PPO('MlpPolicy', gym, learning_rate=LEARNING_RATE, n_steps=NO_STEPS, batch_size=BATCH_SIZE, verbose=0, tensorboard_log=\"./PPO_UC2/\")\n" + "model = PPO('MlpPolicy', gym, learning_rate=LEARNING_RATE, n_steps=NO_STEPS, batch_size=BATCH_SIZE, verbose=0, tensorboard_log=\"./PPO_UC2/\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "With the agent configured, let's train for our defined number of episodes." ] }, { @@ -80,8 +106,14 @@ "metadata": {}, "outputs": [], "source": [ - "model.learn(total_timesteps=NO_STEPS)\n", - "model.save(\"PrimAITE-PPO-example-agent\")" + "model.learn(total_timesteps=NO_STEPS)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next, let's save the agent to a zip file that can be used in future evaluation." ] }, { @@ -93,6 +125,13 @@ "model.save(\"PrimAITE-PPO-example-agent\")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, we load the saved agent and run it in evaluation mode." + ] + }, { "cell_type": "code", "execution_count": null, @@ -103,6 +142,13 @@ "eval_model = PPO.load(\"PrimAITE-PPO-example-agent\", gym)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Finally, evaluate the agent." + ] + }, { "cell_type": "code", "execution_count": null, From 94ca13c0f932d118d4282e8dc8b6568718bad6c9 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 18 Apr 2024 15:14:40 +0100 Subject: [PATCH 823/980] #2470: add log level via config + test --- src/primaite/session/environment.py | 3 - src/primaite/session/io.py | 9 +- .../configs/basic_switched_network.yaml | 97 +++++++++++++++++++ .../test_io_settings.py | 36 +++++++ 4 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 tests/integration_tests/configuration_file_parsing/test_io_settings.py diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 9311e1f7..678a444a 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -26,9 +26,6 @@ class PrimaiteGymEnv(gymnasium.Env): def __init__(self, game_config: Dict): """Initialise the environment.""" super().__init__() - self.io = PrimaiteIO.from_config(game_config.get("io_settings", {})) - """Handles IO for the environment. This produces sys logs, agent logs, etc.""" - self.game_config: Dict = game_config """PrimaiteGame definition. This can be changed between episodes to enable curriculum learning.""" self.io = PrimaiteIO.from_config(game_config.get("io_settings", {})) diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index 0b22f784..ffc07e4e 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -6,7 +6,7 @@ from typing import Dict, List, Optional from pydantic import BaseModel, ConfigDict from primaite import getLogger, PRIMAITE_PATHS -from primaite.simulator import SIM_OUTPUT +from primaite.simulator import LogLevel, SIM_OUTPUT _LOGGER = getLogger(__name__) @@ -35,6 +35,8 @@ class PrimaiteIO: """Whether to save system logs.""" write_sys_log_to_terminal: bool = False """Whether to write the sys log to the terminal.""" + log_level: LogLevel = LogLevel.INFO + """The level of log that should be included in the logfiles/logged into terminal.""" def __init__(self, settings: Optional[Settings] = None) -> None: """ @@ -50,6 +52,7 @@ class PrimaiteIO: SIM_OUTPUT.save_pcap_logs = self.settings.save_pcap_logs SIM_OUTPUT.save_sys_logs = self.settings.save_sys_logs SIM_OUTPUT.write_sys_log_to_terminal = self.settings.write_sys_log_to_terminal + SIM_OUTPUT.log_level = self.settings.log_level def generate_session_path(self, timestamp: Optional[datetime] = None) -> Path: """Create a folder for the session and return the path to it.""" @@ -96,6 +99,10 @@ class PrimaiteIO: def from_config(cls, config: Dict) -> "PrimaiteIO": """Create an instance of PrimaiteIO based on a configuration dict.""" config = config or {} + + if config.get("log_level"): + config["log_level"] = LogLevel[config["log_level"].upper()] # convert to enum + new = cls(settings=cls.Settings(**config)) return new diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 15dd377e..4e45b008 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -8,6 +8,7 @@ io_settings: save_step_metadata: false save_pcap_logs: true save_sys_logs: true + log_level: WARNING game: @@ -60,6 +61,102 @@ agents: frequency: 4 variance: 3 + + + - ref: defender + team: BLUE + type: ProxyAgent + + observation_space: + type: CUSTOM + options: + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: client_1 + - hostname: client_2 + - hostname: client_3 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.23 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - switch_1:eth-1<->client_1:eth-1 + - switch_1:eth-2<->client_2:eth-1 + - type: "NONE" + label: ICS + options: {} + + action_space: + action_list: + - type: DONOTHING + + action_map: + 0: + action: DONOTHING + options: {} + options: + nodes: + - node_name: switch + - node_name: client_1 + - node_name: client_2 + - node_name: client_3 + max_folders_per_node: 2 + max_files_per_folder: 2 + max_services_per_node: 2 + max_nics_per_node: 8 + max_acl_rules: 10 + ip_list: + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.23 + + reward_function: + reward_components: + - type: DATABASE_FILE_INTEGRITY + weight: 0.5 + options: + node_hostname: database_server + folder_name: database + file_name: database.db + + + - type: WEB_SERVER_404_PENALTY + weight: 0.5 + options: + node_hostname: web_server + service_name: web_server_web_service + + + agent_settings: + flatten_obs: true + simulation: network: nodes: diff --git a/tests/integration_tests/configuration_file_parsing/test_io_settings.py b/tests/integration_tests/configuration_file_parsing/test_io_settings.py new file mode 100644 index 00000000..83df31ff --- /dev/null +++ b/tests/integration_tests/configuration_file_parsing/test_io_settings.py @@ -0,0 +1,36 @@ +from pathlib import Path +from typing import Union + +import yaml + +from primaite.config.load import data_manipulation_config_path +from primaite.game.game import PrimaiteGame +from primaite.session.environment import PrimaiteGymEnv +from primaite.simulator import LogLevel +from tests import TEST_ASSETS_ROOT + +BASIC_CONFIG = TEST_ASSETS_ROOT / "configs/basic_switched_network.yaml" + + +def load_config(config_path: Union[str, Path]) -> PrimaiteGame: + """Returns a PrimaiteGame object which loads the contents of a given yaml path.""" + with open(config_path, "r") as f: + cfg = yaml.safe_load(f) + + return PrimaiteGame.from_config(cfg) + + +def test_io_settings(): + """Test that the io_settings are loaded correctly.""" + with open(BASIC_CONFIG, "r") as f: + cfg = yaml.safe_load(f) + env = PrimaiteGymEnv(game_config=cfg) + + assert env.io.settings is not None + + assert env.io.settings.log_level is LogLevel.WARNING + assert env.io.settings.save_pcap_logs + assert env.io.settings.save_sys_logs + assert env.io.settings.save_step_metadata is False + + assert env.io.settings.write_sys_log_to_terminal is False # false by default From 2a1203675dd50587acb6f3547a1082a6f7467bbe Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 18 Apr 2024 15:57:02 +0100 Subject: [PATCH 824/980] #2470: changelog + documentation --- CHANGELOG.md | 1 + docs/source/configuration/io_settings.rst | 24 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d30ae5e2..d11c4ec7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 3.0.0b9 - Removed deprecated `PrimaiteSession` class. +- Added ability to set log levels via configuration. ## [Unreleased] - Made requests fail to reach their target if the node is off diff --git a/docs/source/configuration/io_settings.rst b/docs/source/configuration/io_settings.rst index 67734751..085074a1 100644 --- a/docs/source/configuration/io_settings.rst +++ b/docs/source/configuration/io_settings.rst @@ -18,6 +18,30 @@ This section configures how PrimAITE saves data during simulation and training. save_step_metadata: False save_pcap_logs: False save_sys_logs: False + log_level: INFO + + +``log_level`` +------------- + +Optional. Default value is ``INFO``. + +The level of logging that should be visible in the sys logs or the logs output to the terminal. + +Available options are: + +- ``OFF``: No logs +- ``DEBUG``: Debug level items and the items below +- ``INFO``: Info level items and the items below +- ``WARNING``: Warning level items and the items below +- ``ERROR``: Error level items and the items below +- ``CRITICAL``: Only critical level logs + +See also |logging_levels| + +.. |logging_levels| raw:: html + + Python logging levels ``save_logs`` From 34773ed2255b318e5517cbc1321fdb8f0ddbc3d0 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 18 Apr 2024 16:38:42 +0100 Subject: [PATCH 825/980] #2470: implement PR suggestions --- docs/source/configuration/io_settings.rst | 47 ++++++++++--------- src/primaite/session/io.py | 8 ++-- src/primaite/simulator/__init__.py | 18 ++++--- src/primaite/simulator/system/core/sys_log.py | 10 ++-- .../configs/basic_switched_network.yaml | 2 +- .../test_io_settings.py | 2 +- .../_simulator/_system/core/test_sys_log.py | 43 ++++------------- 7 files changed, 53 insertions(+), 77 deletions(-) diff --git a/docs/source/configuration/io_settings.rst b/docs/source/configuration/io_settings.rst index 085074a1..c3bcdf7b 100644 --- a/docs/source/configuration/io_settings.rst +++ b/docs/source/configuration/io_settings.rst @@ -21,29 +21,6 @@ This section configures how PrimAITE saves data during simulation and training. log_level: INFO -``log_level`` -------------- - -Optional. Default value is ``INFO``. - -The level of logging that should be visible in the sys logs or the logs output to the terminal. - -Available options are: - -- ``OFF``: No logs -- ``DEBUG``: Debug level items and the items below -- ``INFO``: Info level items and the items below -- ``WARNING``: Warning level items and the items below -- ``ERROR``: Error level items and the items below -- ``CRITICAL``: Only critical level logs - -See also |logging_levels| - -.. |logging_levels| raw:: html - - Python logging levels - - ``save_logs`` ------------- @@ -79,3 +56,27 @@ If ``True``, then the pcap files which contain all network traffic during the si Optional. Default value is ``False``. If ``True``, then the log files which contain all node actions during the simulation will be saved. + + +``sys_log_level`` +------------- + +Optional. Default value is ``INFO``. + +The level of logging that should be visible in the sys logs or the logs output to the terminal. + +``save_sys_logs`` has to be set to ``True`` for this setting to be used. + +Available options are: + +- ``DEBUG``: Debug level items and the items below +- ``INFO``: Info level items and the items below +- ``WARNING``: Warning level items and the items below +- ``ERROR``: Error level items and the items below +- ``CRITICAL``: Only critical level logs + +See also |logging_levels| + +.. |logging_levels| raw:: html + + Python logging levels diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index ffc07e4e..6aff6f9f 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -35,7 +35,7 @@ class PrimaiteIO: """Whether to save system logs.""" write_sys_log_to_terminal: bool = False """Whether to write the sys log to the terminal.""" - log_level: LogLevel = LogLevel.INFO + sys_log_level: LogLevel = LogLevel.INFO """The level of log that should be included in the logfiles/logged into terminal.""" def __init__(self, settings: Optional[Settings] = None) -> None: @@ -52,7 +52,7 @@ class PrimaiteIO: SIM_OUTPUT.save_pcap_logs = self.settings.save_pcap_logs SIM_OUTPUT.save_sys_logs = self.settings.save_sys_logs SIM_OUTPUT.write_sys_log_to_terminal = self.settings.write_sys_log_to_terminal - SIM_OUTPUT.log_level = self.settings.log_level + SIM_OUTPUT.sys_log_level = self.settings.sys_log_level def generate_session_path(self, timestamp: Optional[datetime] = None) -> Path: """Create a folder for the session and return the path to it.""" @@ -100,8 +100,8 @@ class PrimaiteIO: """Create an instance of PrimaiteIO based on a configuration dict.""" config = config or {} - if config.get("log_level"): - config["log_level"] = LogLevel[config["log_level"].upper()] # convert to enum + if config.get("sys_log_level"): + config["sys_log_level"] = LogLevel[config["sys_log_level"].upper()] # convert to enum new = cls(settings=cls.Settings(**config)) diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index cfae2ab7..ddb098c6 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -1,6 +1,6 @@ """Warning: SIM_OUTPUT is a mutable global variable for the simulation output directory.""" from datetime import datetime -from enum import Enum +from enum import IntEnum from pathlib import Path from primaite import _PRIMAITE_ROOT @@ -8,20 +8,18 @@ from primaite import _PRIMAITE_ROOT __all__ = ["SIM_OUTPUT"] -class LogLevel(Enum): +class LogLevel(IntEnum): """Enum containing all the available log levels for PrimAITE simulation output.""" - OFF = 999 - """No logs will be output to terminal or log file.""" - DEBUG = 1 + DEBUG = 10 """Debug items will be output to terminal or log file.""" - INFO = 2 + INFO = 20 """Info items will be output to terminal or log file.""" - WARNING = 3 + WARNING = 30 """Warnings will be output to terminal or log file.""" - ERROR = 4 + ERROR = 40 """Errors will be output to terminal or log file.""" - CRITICAL = 5 + CRITICAL = 50 """Critical errors will be output to terminal or log file.""" @@ -33,7 +31,7 @@ class _SimOutput: self.save_pcap_logs: bool = False self.save_sys_logs: bool = False self.write_sys_log_to_terminal: bool = False - self.log_level: LogLevel = LogLevel.INFO # default log level is at INFO + self.sys_log_level: LogLevel = LogLevel.INFO # default log level is at INFO @property def path(self) -> Path: diff --git a/src/primaite/simulator/system/core/sys_log.py b/src/primaite/simulator/system/core/sys_log.py index 775f9b30..225bd4d8 100644 --- a/src/primaite/simulator/system/core/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -99,7 +99,7 @@ class SysLog: :param msg: The message to be logged. :param to_terminal: If True, prints to the terminal too. """ - if SIM_OUTPUT.log_level.value > LogLevel.DEBUG.value: + if SIM_OUTPUT.sys_log_level > LogLevel.DEBUG: return if SIM_OUTPUT.save_sys_logs: @@ -113,7 +113,7 @@ class SysLog: :param msg: The message to be logged. :param to_terminal: If True, prints to the terminal too. """ - if SIM_OUTPUT.log_level.value > LogLevel.INFO.value: + if SIM_OUTPUT.sys_log_level > LogLevel.INFO: return if SIM_OUTPUT.save_sys_logs: @@ -127,7 +127,7 @@ class SysLog: :param msg: The message to be logged. :param to_terminal: If True, prints to the terminal too. """ - if SIM_OUTPUT.log_level.value > LogLevel.WARNING.value: + if SIM_OUTPUT.sys_log_level > LogLevel.WARNING: return if SIM_OUTPUT.save_sys_logs: @@ -141,7 +141,7 @@ class SysLog: :param msg: The message to be logged. :param to_terminal: If True, prints to the terminal too. """ - if SIM_OUTPUT.log_level.value > LogLevel.ERROR.value: + if SIM_OUTPUT.sys_log_level > LogLevel.ERROR: return if SIM_OUTPUT.save_sys_logs: @@ -155,7 +155,7 @@ class SysLog: :param msg: The message to be logged. :param to_terminal: If True, prints to the terminal too. """ - if LogLevel.CRITICAL.value < SIM_OUTPUT.log_level.value: + if LogLevel.CRITICAL < SIM_OUTPUT.sys_log_level: return if SIM_OUTPUT.save_sys_logs: diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 4e45b008..aaddebd0 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -8,7 +8,7 @@ io_settings: save_step_metadata: false save_pcap_logs: true save_sys_logs: true - log_level: WARNING + sys_log_level: WARNING game: diff --git a/tests/integration_tests/configuration_file_parsing/test_io_settings.py b/tests/integration_tests/configuration_file_parsing/test_io_settings.py index 83df31ff..e66350cf 100644 --- a/tests/integration_tests/configuration_file_parsing/test_io_settings.py +++ b/tests/integration_tests/configuration_file_parsing/test_io_settings.py @@ -28,7 +28,7 @@ def test_io_settings(): assert env.io.settings is not None - assert env.io.settings.log_level is LogLevel.WARNING + assert env.io.settings.sys_log_level is LogLevel.WARNING assert env.io.settings.save_pcap_logs assert env.io.settings.save_sys_logs assert env.io.settings.save_step_metadata is False diff --git a/tests/unit_tests/_primaite/_simulator/_system/core/test_sys_log.py b/tests/unit_tests/_primaite/_simulator/_system/core/test_sys_log.py index 610aad1c..56b58d71 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/core/test_sys_log.py +++ b/tests/unit_tests/_primaite/_simulator/_system/core/test_sys_log.py @@ -11,32 +11,9 @@ def syslog() -> SysLog: return SysLog(hostname="test") -def test_off_log_level(syslog, capsys): +def test_debug_sys_log_level(syslog, capsys): """Test that the debug log level logs debug syslogs and above.""" - SIM_OUTPUT.log_level = LogLevel.OFF - SIM_OUTPUT.write_sys_log_to_terminal = True - - test_string = str(uuid4()) - - syslog.debug(test_string) - syslog.info(test_string) - syslog.warning(test_string) - syslog.error(test_string) - syslog.critical(test_string) - - captured = "".join(capsys.readouterr()) - - assert test_string not in captured - assert "DEBUG" not in captured - assert "INFO" not in captured - assert "WARNING" not in captured - assert "ERROR" not in captured - assert "CRITICAL" not in captured - - -def test_debug_log_level(syslog, capsys): - """Test that the debug log level logs debug syslogs and above.""" - SIM_OUTPUT.log_level = LogLevel.DEBUG + SIM_OUTPUT.sys_log_level = LogLevel.DEBUG SIM_OUTPUT.write_sys_log_to_terminal = True test_string = str(uuid4()) @@ -57,9 +34,9 @@ def test_debug_log_level(syslog, capsys): assert "CRITICAL" in captured -def test_info_log_level(syslog, capsys): +def test_info_sys_log_level(syslog, capsys): """Test that the debug log level logs debug syslogs and above.""" - SIM_OUTPUT.log_level = LogLevel.INFO + SIM_OUTPUT.sys_log_level = LogLevel.INFO SIM_OUTPUT.write_sys_log_to_terminal = True test_string = str(uuid4()) @@ -80,9 +57,9 @@ def test_info_log_level(syslog, capsys): assert "CRITICAL" in captured -def test_warning_log_level(syslog, capsys): +def test_warning_sys_log_level(syslog, capsys): """Test that the debug log level logs debug syslogs and above.""" - SIM_OUTPUT.log_level = LogLevel.WARNING + SIM_OUTPUT.sys_log_level = LogLevel.WARNING SIM_OUTPUT.write_sys_log_to_terminal = True test_string = str(uuid4()) @@ -103,9 +80,9 @@ def test_warning_log_level(syslog, capsys): assert "CRITICAL" in captured -def test_error_log_level(syslog, capsys): +def test_error_sys_log_level(syslog, capsys): """Test that the debug log level logs debug syslogs and above.""" - SIM_OUTPUT.log_level = LogLevel.ERROR + SIM_OUTPUT.sys_log_level = LogLevel.ERROR SIM_OUTPUT.write_sys_log_to_terminal = True test_string = str(uuid4()) @@ -126,9 +103,9 @@ def test_error_log_level(syslog, capsys): assert "CRITICAL" in captured -def test_critical_log_level(syslog, capsys): +def test_critical_sys_log_level(syslog, capsys): """Test that the debug log level logs debug syslogs and above.""" - SIM_OUTPUT.log_level = LogLevel.CRITICAL + SIM_OUTPUT.sys_log_level = LogLevel.CRITICAL SIM_OUTPUT.write_sys_log_to_terminal = True test_string = str(uuid4()) From cbea0fd5955a5a14c19e392e9c467d544a6b1d7c Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 18 Apr 2024 16:40:05 +0100 Subject: [PATCH 826/980] #2470: fix documentation --- docs/source/configuration/io_settings.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/configuration/io_settings.rst b/docs/source/configuration/io_settings.rst index c3bcdf7b..bce28d4d 100644 --- a/docs/source/configuration/io_settings.rst +++ b/docs/source/configuration/io_settings.rst @@ -18,7 +18,7 @@ This section configures how PrimAITE saves data during simulation and training. save_step_metadata: False save_pcap_logs: False save_sys_logs: False - log_level: INFO + sys_log_level: INFO ``save_logs`` From 833fd18936391e886f7cef5673642f319bcc21f0 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 18 Apr 2024 16:44:18 +0100 Subject: [PATCH 827/980] #2470: add write_sys_log_to_terminal to documentation --- docs/source/configuration/io_settings.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/source/configuration/io_settings.rst b/docs/source/configuration/io_settings.rst index bce28d4d..3c6c5b19 100644 --- a/docs/source/configuration/io_settings.rst +++ b/docs/source/configuration/io_settings.rst @@ -18,6 +18,7 @@ This section configures how PrimAITE saves data during simulation and training. save_step_metadata: False save_pcap_logs: False save_sys_logs: False + write_sys_log_to_terminal: False sys_log_level: INFO @@ -26,7 +27,6 @@ This section configures how PrimAITE saves data during simulation and training. *currently unused*. - ``save_agent_actions`` ---------------------- @@ -58,6 +58,14 @@ Optional. Default value is ``False``. If ``True``, then the log files which contain all node actions during the simulation will be saved. +``write_sys_log_to_terminal`` +----------------------------- + +Optional. Default value is ``False``. + +If ``True``, PrimAITE will print sys log to the terminal. + + ``sys_log_level`` ------------- @@ -65,7 +73,7 @@ Optional. Default value is ``INFO``. The level of logging that should be visible in the sys logs or the logs output to the terminal. -``save_sys_logs`` has to be set to ``True`` for this setting to be used. +``save_sys_logs`` or ``write_sys_log_to_terminal`` has to be set to ``True`` for this setting to be used. Available options are: From 9334b1e79b1de1c0f47f8399d4c5b29f3b95c41a Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Fri, 19 Apr 2024 11:07:32 +0100 Subject: [PATCH 828/980] #2455: Add NICObservation.ConfigSchema to NIC list. --- src/primaite/game/agent/observations/host_observations.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/primaite/game/agent/observations/host_observations.py b/src/primaite/game/agent/observations/host_observations.py index b15ede9a..c9c73e16 100644 --- a/src/primaite/game/agent/observations/host_observations.py +++ b/src/primaite/game/agent/observations/host_observations.py @@ -227,6 +227,11 @@ class HostObservation(AbstractObservation, identifier="HOST"): applications = [ApplicationObservation.from_config(config=c, parent_where=where) for c in config.applications] folders = [FolderObservation.from_config(config=c, parent_where=where) for c in config.folders] nics = [NICObservation.from_config(config=c, parent_where=where) for c in config.network_interfaces] + count = 1 + while len(nics) < config.num_nics: + nic_config = NICObservation.ConfigSchema(nic_num=count, include_nmne=config.include_nmne) + nics.append(NICObservation.from_config(config=nic_config, parent_where=where)) + count += 1 return cls( where=where, From b8d4a8cc8dbd4f81cf13b78489faddfdafa1ab1b Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 19 Apr 2024 11:37:52 +0100 Subject: [PATCH 829/980] #2470: changed default log level to warning + changed sys logging in code to be more aligned with severity of messages --- .../config/_package_data/data_manipulation.yaml | 1 + src/primaite/simulator/__init__.py | 2 +- src/primaite/simulator/file_system/file.py | 2 +- .../simulator/file_system/file_system.py | 13 +++++-------- src/primaite/simulator/file_system/folder.py | 5 +---- src/primaite/simulator/network/airspace.py | 2 +- src/primaite/simulator/network/hardware/base.py | 8 ++++---- .../network/hardware/nodes/host/host_node.py | 2 +- .../network/hardware/nodes/network/router.py | 4 ++-- .../network/hardware/nodes/network/switch.py | 2 +- .../hardware/nodes/network/wireless_router.py | 2 +- .../simulator/system/applications/application.py | 5 +---- .../system/applications/database_client.py | 15 ++++++--------- .../red_applications/data_manipulation_bot.py | 16 +++++++++------- .../applications/red_applications/dos_bot.py | 4 ++-- .../red_applications/ransomware_script.py | 11 ++++------- .../simulator/system/applications/web_browser.py | 10 ++++++---- .../simulator/system/core/software_manager.py | 6 +++--- .../simulator/system/services/arp/arp.py | 4 ++-- .../system/services/database/database_service.py | 12 ++++++------ .../simulator/system/services/dns/dns_client.py | 9 +++++---- .../simulator/system/services/dns/dns_server.py | 3 ++- .../simulator/system/services/ftp/ftp_client.py | 9 +++++---- .../simulator/system/services/ftp/ftp_server.py | 3 ++- .../simulator/system/services/icmp/icmp.py | 4 ++-- .../simulator/system/services/ntp/ntp_client.py | 3 +-- .../simulator/system/services/ntp/ntp_server.py | 3 ++- .../simulator/system/services/service.py | 4 ++-- .../system/services/web_server/web_server.py | 3 ++- src/primaite/simulator/system/software.py | 10 ++++++---- 30 files changed, 87 insertions(+), 90 deletions(-) diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index 8c365320..9dea1b14 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -3,6 +3,7 @@ io_settings: save_step_metadata: false save_pcap_logs: false save_sys_logs: false + sys_log_level: WARNING game: diff --git a/src/primaite/simulator/__init__.py b/src/primaite/simulator/__init__.py index ddb098c6..3f371ee5 100644 --- a/src/primaite/simulator/__init__.py +++ b/src/primaite/simulator/__init__.py @@ -31,7 +31,7 @@ class _SimOutput: self.save_pcap_logs: bool = False self.save_sys_logs: bool = False self.write_sys_log_to_terminal: bool = False - self.sys_log_level: LogLevel = LogLevel.INFO # default log level is at INFO + self.sys_log_level: LogLevel = LogLevel.WARNING # default log level is at WARNING @property def path(self) -> Path: diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index 3a1c24df..7e2847a5 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -223,5 +223,5 @@ class File(FileSystemItemABC): self.num_access += 1 # file was accessed self.deleted = True - self.sys_log.info(f"File deleted {self.folder_name}/{self.name}") + self.sys_log.warning(f"File deleted {self.folder_name}/{self.name}") return True diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index aacb7d01..0eae6009 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -6,7 +6,6 @@ from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable -from primaite import getLogger from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file import File @@ -14,8 +13,6 @@ from primaite.simulator.file_system.file_type import FileType from primaite.simulator.file_system.folder import Folder from primaite.simulator.system.core.sys_log import SysLog -_LOGGER = getLogger(__name__) - class FileSystem(SimComponent): """Class that contains all the simulation File System.""" @@ -163,11 +160,11 @@ class FileSystem(SimComponent): :param folder_name: The name of the folder. """ if folder_name == "root": - self.sys_log.warning("Cannot delete the root folder.") + self.sys_log.error("Cannot delete the root folder.") return False folder = self.get_folder(folder_name) if not folder: - _LOGGER.debug(f"Cannot delete folder as it does not exist: {folder_name}") + self.sys_log.error(f"Cannot delete folder as it does not exist: {folder_name}") return False # set folder to deleted state @@ -180,7 +177,7 @@ class FileSystem(SimComponent): folder.remove_all_files() self.deleted_folders[folder.uuid] = folder - self.sys_log.info(f"Deleted folder /{folder.name} and its contents") + self.sys_log.warning(f"Deleted folder /{folder.name} and its contents") return True def delete_folder_by_id(self, folder_uuid: str) -> None: @@ -283,7 +280,7 @@ class FileSystem(SimComponent): folder = self.get_folder(folder_name, include_deleted=include_deleted) if folder: return folder.get_file(file_name, include_deleted=include_deleted) - self.sys_log.info(f"File not found /{folder_name}/{file_name}") + self.sys_log.warning(f"File not found /{folder_name}/{file_name}") def get_file_by_id( self, file_uuid: str, folder_uuid: Optional[str] = None, include_deleted: Optional[bool] = False @@ -499,7 +496,7 @@ class FileSystem(SimComponent): """ folder = self.get_folder(folder_name=folder_name) if not folder: - _LOGGER.debug(f"Cannot restore file {file_name} in folder {folder_name} as the folder does not exist.") + self.sys_log.error(f"Cannot restore file {file_name} in folder {folder_name} as the folder does not exist.") return False file = folder.get_file(file_name=file_name, include_deleted=True) diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 9f176660..51b7a819 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -4,14 +4,11 @@ from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable -from primaite import getLogger from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.file_system.file import File from primaite.simulator.file_system.file_system_item_abc import FileSystemItemABC, FileSystemItemHealthStatus -_LOGGER = getLogger(__name__) - class Folder(FileSystemItemABC): """Simulation Folder.""" @@ -254,7 +251,7 @@ class Folder(FileSystemItemABC): file.delete() self.sys_log.info(f"Removed file {file.name} (id: {file.uuid})") else: - _LOGGER.debug(f"File with UUID {file.uuid} was not found.") + self.sys_log.error(f"File with UUID {file.uuid} was not found.") def remove_file_by_id(self, file_uuid: str): """ diff --git a/src/primaite/simulator/network/airspace.py b/src/primaite/simulator/network/airspace.py index abda587e..3c5c048c 100644 --- a/src/primaite/simulator/network/airspace.py +++ b/src/primaite/simulator/network/airspace.py @@ -161,7 +161,7 @@ class WirelessNetworkInterface(NetworkInterface, ABC): return if self._connected_node.operating_state != NodeOperatingState.ON: - self._connected_node.sys_log.info( + self._connected_node.sys_log.error( f"Interface {self} cannot be enabled as the connected Node is not powered on" ) return diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 55636356..ac78ce62 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -307,13 +307,13 @@ class WiredNetworkInterface(NetworkInterface, ABC): return False if self._connected_node.operating_state != NodeOperatingState.ON: - self._connected_node.sys_log.info( + self._connected_node.sys_log.error( f"Interface {self} cannot be enabled as the connected Node is not powered on" ) return False if not self._connected_link: - self._connected_node.sys_log.info(f"Interface {self} cannot be enabled as there is no Link connected.") + self._connected_node.sys_log.warning(f"Interface {self} cannot be enabled as there is no Link connected.") return False self.enabled = True @@ -1201,7 +1201,7 @@ class Node(SimComponent): self._nic_request_manager.add_request(new_nic_num, RequestType(func=network_interface._request_manager)) else: msg = f"Cannot connect NIC {network_interface} as it is already connected" - self.sys_log.logger.error(msg) + self.sys_log.logger.warning(msg) raise NetworkError(msg) def disconnect_nic(self, network_interface: Union[NetworkInterface, str]): @@ -1228,7 +1228,7 @@ class Node(SimComponent): self._nic_request_manager.remove_request(network_interface_num) else: msg = f"Cannot disconnect Network Interface {network_interface} as it is not connected" - self.sys_log.logger.error(msg) + self.sys_log.logger.warning(msg) raise NetworkError(msg) def ping(self, target_ip_address: Union[IPv4Address, str], pings: int = 4) -> bool: diff --git a/src/primaite/simulator/network/hardware/nodes/host/host_node.py b/src/primaite/simulator/network/hardware/nodes/host/host_node.py index 31378689..517b16e9 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/host_node.py +++ b/src/primaite/simulator/network/hardware/nodes/host/host_node.py @@ -147,7 +147,7 @@ class HostARP(ARP): super()._process_arp_request(arp_packet, from_network_interface) # Unmatched ARP Request if arp_packet.target_ip_address != from_network_interface.ip_address: - self.sys_log.info( + self.sys_log.warning( f"Ignoring ARP request for {arp_packet.target_ip_address}. Current IP address is " f"{from_network_interface.ip_address}" ) diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index 5d041fd1..0e5e1bfc 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -933,7 +933,7 @@ class RouterICMP(ICMP): ) if not network_interface: - self.sys_log.error( + self.sys_log.warning( "Cannot send ICMP echo reply as there is no outbound Network Interface to use. Try configuring the " "default gateway." ) @@ -1483,7 +1483,7 @@ class Router(NetworkNode): frame.ethernet.dst_mac_addr = target_mac network_interface.send_frame(frame) else: - self.sys_log.error(f"Frame dropped as there is no route to {frame.ip.dst_ip_address}") + self.sys_log.warning(f"Frame dropped as there is no route to {frame.ip.dst_ip_address}") def configure_port(self, port: int, ip_address: Union[IPv4Address, str], subnet_mask: Union[IPv4Address, str]): """ diff --git a/src/primaite/simulator/network/hardware/nodes/network/switch.py b/src/primaite/simulator/network/hardware/nodes/network/switch.py index aa405e14..db1863e0 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/switch.py +++ b/src/primaite/simulator/network/hardware/nodes/network/switch.py @@ -74,7 +74,7 @@ class SwitchPort(WiredNetworkInterface): if self.enabled: frame.decrement_ttl() if frame.ip and frame.ip.ttl < 1: - self._connected_node.sys_log.info("Frame discarded as TTL limit reached") + self._connected_node.sys_log.warning("Frame discarded as TTL limit reached") return False self.pcap.capture_inbound(frame) self._connected_node.receive_frame(frame=frame, from_network_interface=self) diff --git a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py index 62332269..f66ebd27 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py @@ -68,7 +68,7 @@ class WirelessAccessPoint(IPWirelessNetworkInterface): if self.enabled: frame.decrement_ttl() if frame.ip and frame.ip.ttl < 1: - self._connected_node.sys_log.info("Frame discarded as TTL limit reached") + self._connected_node.sys_log.warning("Frame discarded as TTL limit reached") return False frame.set_received_timestamp() self.pcap.capture_inbound(frame) diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index ff71b51a..7ba3f8cf 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -2,13 +2,10 @@ from abc import abstractmethod from enum import Enum from typing import Any, Dict, Set -from primaite import getLogger from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.system.software import IOSoftware, SoftwareHealthState -_LOGGER = getLogger(__name__) - class ApplicationOperatingState(Enum): """Enumeration of Application Operating States.""" @@ -99,7 +96,7 @@ class Application(IOSoftware): if self.operating_state is not self.operating_state.RUNNING: # service is not running - _LOGGER.debug(f"Cannot perform action: {self.name} is {self.operating_state.name}") + self.sys_log.error(f"Cannot perform action: {self.name} is {self.operating_state.name}") return False return True diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index d304c200..675ff817 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -2,7 +2,6 @@ from ipaddress import IPv4Address from typing import Any, Dict, Optional from uuid import uuid4 -from primaite import getLogger from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.network.transmission.network_layer import IPProtocol @@ -10,8 +9,6 @@ from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application from primaite.simulator.system.core.software_manager import SoftwareManager -_LOGGER = getLogger(__name__) - class DatabaseClient(Application): """ @@ -136,7 +133,7 @@ class DatabaseClient(Application): self.server_ip_address = server_ip_address return True else: - self.sys_log.info( + self.sys_log.warning( f"{self.name} {connection_id=}: DatabaseClient connection to {server_ip_address} declined" ) return False @@ -156,12 +153,12 @@ class DatabaseClient(Application): def disconnect(self) -> bool: """Disconnect from the Database Service.""" if not self._can_perform_action(): - self.sys_log.error(f"Unable to disconnect - {self.name} is {self.operating_state.name}") + self.sys_log.warning(f"Unable to disconnect - {self.name} is {self.operating_state.name}") return False # if there are no connections - nothing to disconnect if not self._server_connection_id: - self.sys_log.error(f"Unable to disconnect - {self.name} has no active connections.") + self.sys_log.warning(f"Unable to disconnect - {self.name} has no active connections.") return False # if no connection provided, disconnect the first connection @@ -196,7 +193,7 @@ class DatabaseClient(Application): if success: self.sys_log.info(f"{self.name}: Query successful {sql}") return True - self.sys_log.info(f"{self.name}: Unable to run query {sql}") + self.sys_log.error(f"{self.name}: Unable to run query {sql}") return False else: software_manager: SoftwareManager = self.software_manager @@ -236,7 +233,7 @@ class DatabaseClient(Application): if not connection_id: msg = "Cannot run sql query, could not establish connection with the server." - self.parent.sys_log(msg) + self.sys_log.warning(msg) return False uuid = str(uuid4()) @@ -265,5 +262,5 @@ class DatabaseClient(Application): status_code = payload.get("status_code") self._query_success_tracker[query_id] = status_code == 200 if self._query_success_tracker[query_id]: - _LOGGER.debug(f"Received payload {payload}") + self.sys_log.debug(f"Received {payload=}") return True diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index ee276971..abb564dd 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -71,7 +71,7 @@ class DataManipulationBot(Application): """Return the database client that is installed on the same machine as the DataManipulationBot.""" db_client = self.software_manager.software.get("DatabaseClient") if db_client is None: - _LOGGER.info(f"{self.__class__.__name__} cannot find a database client on its host.") + self.sys_log.warning(f"{self.__class__.__name__} cannot find a database client on its host.") return db_client def _init_request_manager(self) -> RequestManager: @@ -127,7 +127,7 @@ class DataManipulationBot(Application): """ if self.attack_stage == DataManipulationAttackStage.NOT_STARTED: # Bypass this stage as we're not dealing with logon for now - self.sys_log.info(f"{self.name}: ") + self.sys_log.debug(f"{self.name}: ") self.attack_stage = DataManipulationAttackStage.LOGON def _perform_port_scan(self, p_of_success: Optional[float] = 0.1): @@ -145,7 +145,7 @@ class DataManipulationBot(Application): # perform the port scan port_is_open = True # Temporary; later we can implement NMAP port scan. if port_is_open: - self.sys_log.info(f"{self.name}: ") + self.sys_log.debug(f"{self.name}: ") self.attack_stage = DataManipulationAttackStage.PORT_SCAN def _perform_data_manipulation(self, p_of_success: Optional[float] = 0.1): @@ -177,7 +177,7 @@ class DataManipulationBot(Application): self.sys_log.info(f"{self.name}: Data manipulation successful") self.attack_stage = DataManipulationAttackStage.SUCCEEDED else: - self.sys_log.info(f"{self.name}: Data manipulation failed") + self.sys_log.error(f"{self.name}: Data manipulation failed") self.attack_stage = DataManipulationAttackStage.FAILED def run(self): @@ -191,7 +191,9 @@ class DataManipulationBot(Application): def attack(self) -> bool: """Perform the attack steps after opening the application.""" if not self._can_perform_action(): - _LOGGER.debug("Data manipulation application attempted to execute but it cannot perform actions right now.") + self.sys_log.warning( + "Data manipulation application attempted to execute but it cannot perform actions right now." + ) self.run() self.num_executions += 1 @@ -206,7 +208,7 @@ class DataManipulationBot(Application): if not self._can_perform_action(): return False if self.server_ip_address and self.payload: - self.sys_log.info(f"{self.name}: Running") + self.sys_log.debug(f"{self.name}: Running") self._logon() self._perform_port_scan(p_of_success=self.port_scan_p_of_success) self._perform_data_manipulation(p_of_success=self.data_manipulation_p_of_success) @@ -220,7 +222,7 @@ class DataManipulationBot(Application): return True else: - self.sys_log.error(f"{self.name}: Failed to start as it requires both a target_ip_address and payload.") + self.sys_log.warning(f"{self.name}: Failed to start as it requires both a target_ip_address and payload.") return False def apply_timestep(self, timestep: int) -> None: diff --git a/src/primaite/simulator/system/applications/red_applications/dos_bot.py b/src/primaite/simulator/system/applications/red_applications/dos_bot.py index 27a4da05..53fc9740 100644 --- a/src/primaite/simulator/system/applications/red_applications/dos_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/dos_bot.py @@ -122,7 +122,7 @@ class DoSBot(DatabaseClient): # DoS bot cannot do anything without a target if not self.target_ip_address or not self.target_port: - self.sys_log.error( + self.sys_log.warning( f"{self.name} is not properly configured. {self.target_ip_address=}, {self.target_port=}" ) return True @@ -152,7 +152,7 @@ class DoSBot(DatabaseClient): # perform the port scan port_is_open = True # Temporary; later we can implement NMAP port scan. if port_is_open: - self.sys_log.info(f"{self.name}: ") + self.sys_log.debug(f"{self.name}: ") self.attack_stage = DoSAttackStage.PORT_SCAN def _perform_dos(self): diff --git a/src/primaite/simulator/system/applications/red_applications/ransomware_script.py b/src/primaite/simulator/system/applications/red_applications/ransomware_script.py index 54880271..74d8a196 100644 --- a/src/primaite/simulator/system/applications/red_applications/ransomware_script.py +++ b/src/primaite/simulator/system/applications/red_applications/ransomware_script.py @@ -2,7 +2,6 @@ from enum import IntEnum from ipaddress import IPv4Address from typing import Dict, Optional -from primaite import getLogger from primaite.game.science import simulate_trial from primaite.interface.request import RequestResponse from primaite.simulator.core import RequestManager, RequestType @@ -11,8 +10,6 @@ from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.applications.application import Application from primaite.simulator.system.applications.database_client import DatabaseClient -_LOGGER = getLogger(__name__) - class RansomwareAttackStage(IntEnum): """ @@ -94,7 +91,7 @@ class RansomwareScript(Application): """Return the database client that is installed on the same machine as the Ransomware Script.""" db_client = self.software_manager.software.get("DatabaseClient") if db_client is None: - _LOGGER.info(f"{self.__class__.__name__} cannot find a database client on its host.") + self.sys_log.warning(f"{self.__class__.__name__} cannot find a database client on its host.") return db_client def _init_request_manager(self) -> RequestManager: @@ -158,7 +155,7 @@ class RansomwareScript(Application): self.attack_stage = RansomwareAttackStage.NOT_STARTED return True else: - self.sys_log.error(f"{self.name}: Failed to start as it requires both a target_ip_address and payload.") + self.sys_log.warning(f"{self.name}: Failed to start as it requires both a target_ip_address and payload.") return False def configure( @@ -254,7 +251,7 @@ class RansomwareScript(Application): def attack(self) -> bool: """Perform the attack steps after opening the application.""" if not self._can_perform_action(): - _LOGGER.debug("Ransomware application is unable to perform it's actions.") + self.sys_log.warning("Ransomware application is unable to perform it's actions.") self.run() self.num_executions += 1 return self._application_loop() @@ -289,7 +286,7 @@ class RansomwareScript(Application): self.sys_log.info(f"{self.name}: Payload failed") self.attack_stage = RansomwareAttackStage.FAILED else: - self.sys_log.error("Attack Attempted to launch too quickly") + self.sys_log.warning("Attack Attempted to launch too quickly") self.attack_stage = RansomwareAttackStage.FAILED def _local_download(self): diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py index e669ca32..0e6fec00 100644 --- a/src/primaite/simulator/system/applications/web_browser.py +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -97,7 +97,7 @@ class WebBrowser(Application): try: parsed_url = urlparse(url) except Exception: - self.sys_log.error(f"{url} is not a valid URL") + self.sys_log.warning(f"{url} is not a valid URL") return False # get the IP address of the domain name via DNS @@ -114,7 +114,7 @@ class WebBrowser(Application): self.domain_name_ip_address = IPv4Address(parsed_url.hostname) except Exception: # unable to deal with this request - self.sys_log.error(f"{self.name}: Unable to resolve URL {url}") + self.sys_log.warning(f"{self.name}: Unable to resolve URL {url}") return False # create HTTPRequest payload @@ -140,7 +140,8 @@ class WebBrowser(Application): ) return self.latest_response.status_code is HttpStatusCode.OK else: - self.sys_log.error(f"Error sending Http Packet {str(payload)}") + self.sys_log.warning(f"{self.name}: Error sending Http Packet") + self.sys_log.debug(f"{self.name}: {payload=}") self.history.append( WebBrowser.BrowserHistoryItem( url=url, status=self.BrowserHistoryItem._HistoryItemStatus.SERVER_UNREACHABLE @@ -181,7 +182,8 @@ class WebBrowser(Application): :return: True if successful, False otherwise. """ if not isinstance(payload, HttpResponsePacket): - self.sys_log.error(f"{self.name} received a packet that is not an HttpResponsePacket") + self.sys_log.warning(f"{self.name} received a packet that is not an HttpResponsePacket") + self.sys_log.debug(f"{self.name}: {payload=}") return False self.sys_log.info(f"{self.name}: Received HTTP {payload.status_code.value}") self.latest_response = payload diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index e6fe7b23..ff7f8502 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -87,7 +87,7 @@ class SoftwareManager: # TODO: Software manager and node itself both have an install method. Need to refactor to have more logical # separation of concerns. if software_class in self._software_class_to_name_map: - self.sys_log.info(f"Cannot install {software_class} as it is already installed") + self.sys_log.warning(f"Cannot install {software_class} as it is already installed") return software = software_class( software_manager=self, sys_log=self.sys_log, file_system=self.file_system, dns_server=self.dns_server @@ -144,7 +144,7 @@ class SoftwareManager: if receiver: receiver.receive_payload(payload) else: - self.sys_log.error(f"No Service of Application found with the name {target_software}") + self.sys_log.warning(f"No Service of Application found with the name {target_software}") def send_payload_to_session_manager( self, @@ -196,7 +196,7 @@ class SoftwareManager: payload=payload, session_id=session_id, from_network_interface=from_network_interface, frame=frame ) else: - self.sys_log.error(f"No service or application found for port {port} and protocol {protocol}") + self.sys_log.warning(f"No service or application found for port {port} and protocol {protocol}") pass def show(self, markdown: bool = False): diff --git a/src/primaite/simulator/system/services/arp/arp.py b/src/primaite/simulator/system/services/arp/arp.py index 75bb03ae..bfbc8c9c 100644 --- a/src/primaite/simulator/system/services/arp/arp.py +++ b/src/primaite/simulator/system/services/arp/arp.py @@ -147,7 +147,7 @@ class ARP(Service): payload=arp_packet, dst_ip_address=target_ip_address, dst_port=self.port, ip_protocol=self.protocol ) else: - self.sys_log.error( + self.sys_log.warning( "Cannot send ARP request as there is no outbound Network Interface to use. Try configuring the default " "gateway." ) @@ -173,7 +173,7 @@ class ARP(Service): ip_protocol=self.protocol, ) else: - self.sys_log.error( + self.sys_log.warning( "Cannot send ARP reply as there is no outbound Network Interface to use. Try configuring the default " "gateway." ) diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 833b1fa5..9fdd0cdd 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -57,7 +57,7 @@ class DatabaseService(Service): # check if the backup server was configured if self.backup_server_ip is None: - self.sys_log.error(f"{self.name} - {self.sys_log.hostname}: not configured.") + self.sys_log.warning(f"{self.name} - {self.sys_log.hostname}: not configured.") return False software_manager: SoftwareManager = self.software_manager @@ -110,7 +110,7 @@ class DatabaseService(Service): db_file = self.file_system.get_file(folder_name="database", file_name="database.db", include_deleted=True) if db_file is None: - self.sys_log.error("Database file not initialised.") + self.sys_log.warning("Database file not initialised.") return False # if the file was deleted, get the old visible health state @@ -170,12 +170,12 @@ class DatabaseService(Service): # try to create connection if not self.add_connection(connection_id=connection_id): status_code = 500 - self.sys_log.info(f"{self.name}: Connect request for {connection_id=} declined") + self.sys_log.warning(f"{self.name}: Connect request for {connection_id=} declined") else: self.sys_log.info(f"{self.name}: Connect request for {connection_id=} authorised") else: status_code = 401 # Unauthorised - self.sys_log.info(f"{self.name}: Connect request for {connection_id=} declined") + self.sys_log.warning(f"{self.name}: Connect request for {connection_id=} declined") else: status_code = 404 # service not found return { @@ -206,7 +206,7 @@ class DatabaseService(Service): self.sys_log.info(f"{self.name}: Running {query}") if not self.db_file: - self.sys_log.info(f"{self.name}: Failed to run {query} because the database file is missing.") + self.sys_log.error(f"{self.name}: Failed to run {query} because the database file is missing.") return {"status_code": 404, "type": "sql", "data": False} if query == "SELECT": @@ -276,7 +276,7 @@ class DatabaseService(Service): return {"status_code": 401, "data": False} else: # Invalid query - self.sys_log.info(f"{self.name}: Invalid {query}") + self.sys_log.warning(f"{self.name}: Invalid {query}") return {"status_code": 500, "data": False} def describe_state(self) -> Dict: diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 967af6b2..063ff74f 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -72,7 +72,7 @@ class DNSClient(Service): # check if DNS server is configured if self.dns_server is None: - self.sys_log.error(f"{self.name}: DNS Server is not configured") + self.sys_log.warning(f"{self.name}: DNS Server is not configured") return False # check if the target domain is in the client's DNS cache @@ -88,7 +88,7 @@ class DNSClient(Service): else: # return False if already reattempted if is_reattempt: - self.sys_log.info(f"{self.name}: Domain lookup for {target_domain} failed") + self.sys_log.warning(f"{self.name}: Domain lookup for {target_domain} failed") return False else: # send a request to check if domain name exists in the DNS Server @@ -143,7 +143,8 @@ class DNSClient(Service): """ # The payload should be a DNS packet if not isinstance(payload, DNSPacket): - _LOGGER.debug(f"{payload} is not a DNSPacket") + self.sys_log.warning(f"{self.name}: Payload is not a DNSPacket") + self.sys_log.debug(f"{self.name}: {payload}") return False if payload.dns_reply is not None: @@ -156,5 +157,5 @@ class DNSClient(Service): self.dns_cache[payload.dns_request.domain_name_request] = payload.dns_reply.domain_name_ip_address return True - self.sys_log.error(f"Failed to resolve domain name {payload.dns_request.domain_name_request}") + self.sys_log.warning(f"Failed to resolve domain name {payload.dns_request.domain_name_request}") return False diff --git a/src/primaite/simulator/system/services/dns/dns_server.py b/src/primaite/simulator/system/services/dns/dns_server.py index 4d0ebbb8..7dbc5d60 100644 --- a/src/primaite/simulator/system/services/dns/dns_server.py +++ b/src/primaite/simulator/system/services/dns/dns_server.py @@ -90,7 +90,8 @@ class DNSServer(Service): # The payload should be a DNS packet if not isinstance(payload, DNSPacket): - _LOGGER.debug(f"{payload} is not a DNSPacket") + self.sys_log.warning(f"{payload} is not a DNSPacket") + self.sys_log.debug(f"{payload} is not a DNSPacket") return False # cast payload into a DNS packet diff --git a/src/primaite/simulator/system/services/ftp/ftp_client.py b/src/primaite/simulator/system/services/ftp/ftp_client.py index 7c334ced..f2b78d52 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_client.py +++ b/src/primaite/simulator/system/services/ftp/ftp_client.py @@ -82,7 +82,7 @@ class FTPClient(FTPServiceABC): else: if is_reattempt: # reattempt failed - self.sys_log.info( + self.sys_log.warning( f"{self.name}: Unable to connect to FTP Server " f"{dest_ip_address} via port {payload.ftp_command_args.value}" ) @@ -93,7 +93,7 @@ class FTPClient(FTPServiceABC): dest_ip_address=dest_ip_address, dest_port=dest_port, session_id=session_id, is_reattempt=True ) else: - self.sys_log.error(f"{self.name}: Unable to send FTPPacket") + self.sys_log.warning(f"{self.name}: Unable to send FTPPacket") return False def _disconnect_from_server( @@ -158,7 +158,7 @@ class FTPClient(FTPServiceABC): # check if the file to transfer exists on the client file_to_transfer: File = self.file_system.get_file(folder_name=src_folder_name, file_name=src_file_name) if not file_to_transfer: - self.sys_log.error(f"Unable to send file that does not exist: {src_folder_name}/{src_file_name}") + self.sys_log.warning(f"Unable to send file that does not exist: {src_folder_name}/{src_file_name}") return False # check if FTP is currently connected to IP @@ -253,7 +253,8 @@ class FTPClient(FTPServiceABC): :type: session_id: Optional[str] """ if not isinstance(payload, FTPPacket): - self.sys_log.error(f"{payload} is not an FTP packet") + self.sys_log.warning(f"{self.name}: Payload is not an FTP packet") + self.sys_log.debug(f"{self.name}: {payload}") return False """ diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index c5330de2..de714a10 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -70,7 +70,8 @@ class FTPServer(FTPServiceABC): def receive(self, payload: Any, session_id: Optional[str] = None, **kwargs) -> bool: """Receives a payload from the SessionManager.""" if not isinstance(payload, FTPPacket): - self.sys_log.error(f"{payload} is not an FTP packet") + self.sys_log.warning(f"{self.name}: Payload is not an FTP packet") + self.sys_log.debug(f"{self.name}: {payload}") return False if not super().receive(payload=payload, session_id=session_id, **kwargs): diff --git a/src/primaite/simulator/system/services/icmp/icmp.py b/src/primaite/simulator/system/services/icmp/icmp.py index 103d1c60..c4b4173f 100644 --- a/src/primaite/simulator/system/services/icmp/icmp.py +++ b/src/primaite/simulator/system/services/icmp/icmp.py @@ -95,7 +95,7 @@ class ICMP(Service): network_interface = self.software_manager.session_manager.resolve_outbound_network_interface(target_ip_address) if not network_interface: - self.sys_log.error( + self.sys_log.warning( "Cannot send ICMP echo request as there is no outbound Network Interface to use. Try configuring the " "default gateway." ) @@ -130,7 +130,7 @@ class ICMP(Service): ) if not network_interface: - self.sys_log.error( + self.sys_log.warning( "Cannot send ICMP echo reply as there is no outbound Network Interface to use. Try configuring the " "default gateway." ) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index fe351dba..dcc502c7 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -87,7 +87,7 @@ class NTPClient(Service): :return: True if successful, False otherwise. """ if not isinstance(payload, NTPPacket): - _LOGGER.debug(f"{self.name}: Failed to parse NTP update") + self.sys_log.warning(f"{self.name}: Failed to parse NTP update") return False if payload.ntp_reply.ntp_datetime: self.time = payload.ntp_reply.ntp_datetime @@ -115,7 +115,6 @@ class NTPClient(Service): :param timestep: The current timestep number. (Amount of time since simulation episode began) :type timestep: int """ - self.sys_log.info(f"{self.name} apply_timestep") super().apply_timestep(timestep) if self.operating_state == ServiceOperatingState.RUNNING: # request time from server diff --git a/src/primaite/simulator/system/services/ntp/ntp_server.py b/src/primaite/simulator/system/services/ntp/ntp_server.py index f9d9ee7c..01d10b84 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_server.py +++ b/src/primaite/simulator/system/services/ntp/ntp_server.py @@ -51,7 +51,8 @@ class NTPServer(Service): :return: True if valid NTP request else False. """ if not (isinstance(payload, NTPPacket)): - _LOGGER.debug(f"{payload} is not a NTPPacket") + self.sys_log.warning(f"{self.name}: Payload is not a NTPPacket") + self.sys_log.debug(f"{self.name}: {payload}") return False payload: NTPPacket = payload diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index b2a6f685..caaefc06 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -59,7 +59,7 @@ class Service(IOSoftware): if self.operating_state is not ServiceOperatingState.RUNNING: # service is not running - _LOGGER.debug(f"Cannot perform action: {self.name} is {self.operating_state.name}") + self.sys_log.debug(f"Cannot perform action: {self.name} is {self.operating_state.name}") return False return True @@ -187,6 +187,6 @@ class Service(IOSoftware): super().apply_timestep(timestep) if self.operating_state == ServiceOperatingState.RESTARTING: if self.restart_countdown <= 0: - _LOGGER.debug(f"Restarting finished for service {self.name}") + self.sys_log.debug(f"Restarting finished for service {self.name}") self.operating_state = ServiceOperatingState.RUNNING self.restart_countdown -= 1 diff --git a/src/primaite/simulator/system/services/web_server/web_server.py b/src/primaite/simulator/system/services/web_server/web_server.py index 5e7591e9..c0eb0632 100644 --- a/src/primaite/simulator/system/services/web_server/web_server.py +++ b/src/primaite/simulator/system/services/web_server/web_server.py @@ -167,7 +167,8 @@ class WebServer(Service): # check if the payload is an HTTPPacket if not isinstance(payload, HttpRequestPacket): - self.sys_log.error("Payload is not an HTTPPacket") + self.sys_log.warning(f"{self.name}: Payload is not an HTTPPacket") + self.sys_log.debug(f"{self.name}: {payload}") return False return self._process_http_request(payload=payload, session_id=session_id) diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index 50c96c17..b609b0b2 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -6,7 +6,7 @@ from ipaddress import IPv4Address, IPv4Network from typing import Any, Dict, Optional, TYPE_CHECKING, Union from primaite.interface.request import RequestResponse -from primaite.simulator.core import _LOGGER, RequestManager, RequestType, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file_system import FileSystem, Folder from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState from primaite.simulator.network.transmission.network_layer import IPProtocol @@ -287,7 +287,9 @@ class IOSoftware(Software): Returns true if the software can perform actions. """ if self.software_manager and self.software_manager.node.operating_state != NodeOperatingState.ON: - _LOGGER.debug(f"{self.name} Error: {self.software_manager.node.hostname} is not online.") + self.software_manager.node.sys_log.error( + f"{self.name} Error: {self.software_manager.node.hostname} is not online." + ) return False return True @@ -308,7 +310,7 @@ class IOSoftware(Software): # if over or at capacity, set to overwhelmed if len(self._connections) >= self.max_sessions: self.set_health_state(SoftwareHealthState.OVERWHELMED) - self.sys_log.error(f"{self.name}: Connect request for {connection_id=} declined. Service is at capacity.") + self.sys_log.warning(f"{self.name}: Connect request for {connection_id=} declined. Service is at capacity.") return False else: # if service was previously overwhelmed, set to good because there is enough space for connections @@ -327,7 +329,7 @@ class IOSoftware(Software): self.sys_log.info(f"{self.name}: Connect request for {connection_id=} authorised") return True # connection with given id already exists - self.sys_log.error( + self.sys_log.warning( f"{self.name}: Connect request for {connection_id=} declined. Connection already exists." ) return False From 57e6f8bca7b208015d2a1260ad1bd85bdeaf02de Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Fri, 19 Apr 2024 11:55:38 +0100 Subject: [PATCH 830/980] #2470: update documentation --- docs/source/configuration/io_settings.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/configuration/io_settings.rst b/docs/source/configuration/io_settings.rst index 3c6c5b19..49bc2620 100644 --- a/docs/source/configuration/io_settings.rst +++ b/docs/source/configuration/io_settings.rst @@ -69,7 +69,7 @@ If ``True``, PrimAITE will print sys log to the terminal. ``sys_log_level`` ------------- -Optional. Default value is ``INFO``. +Optional. Default value is ``WARNING``. The level of logging that should be visible in the sys logs or the logs output to the terminal. From 9a55b7b864511fbc5fe870b538864cb91b0d65e9 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 19 Apr 2024 15:58:50 +0100 Subject: [PATCH 831/980] #2266 - Fixed some minor bugs that prevented basic networks without a default gateway from being parsed. Completed the basic client-server P2P network documentation, file and retrieval method. --- .../simulation/nodes/network_examples.rst | 68 +++++++++++++++++++ .../client-server-p2p-network-example.yaml | 10 ++- .../game/agent/observations/observations.py | 4 +- src/primaite/game/agent/rewards.py | 4 +- src/primaite/game/game.py | 4 +- src/primaite/simulator/network/networks.py | 14 ++++ 6 files changed, 97 insertions(+), 7 deletions(-) diff --git a/docs/source/configuration/simulation/nodes/network_examples.rst b/docs/source/configuration/simulation/nodes/network_examples.rst index 572d8bb5..f5084d4c 100644 --- a/docs/source/configuration/simulation/nodes/network_examples.rst +++ b/docs/source/configuration/simulation/nodes/network_examples.rst @@ -29,7 +29,75 @@ and a Server on the same subnet with a single Link connecting the two. :width: 800 :align: center +The yaml file contains two nodes in the ``simulation.network.nodes`` array, one with the `pc_1` reference and another +with the `server_1` reference. both nodes are given a node type, `pc_1` being a `computer` and `server_1` being a +`server`. Both nodes are then given an ip address and subnet mask. +The link between the two nodes is configured in the ``simulation.network.links`` array, with the hostname and network +interface for each being configured under ``endpoint__hostname`` and ``endpoint__port`` respectively. + + + +.. code-block:: yaml + :linenos: + :emphasive-lines: + + simulation: + network: + nodes: + - hostname: pc_1 + type: computer + ip_address: 192.168.1.11 + subnet_mask: 255.255.255.0 + + - hostname: server_1 + type: server + ip_address: 192.168.1.13 + subnet_mask: 255.255.255.0 + + links: + - endpoint_a_hostname: pc_1 + endpoint_a_port: 1 + endpoint_b_hostname: server_1 + endpoint_b_port: 1 + +The following codeblock demonstrates how to access this network and all ``.show()`` to output the network details: + +.. code-block:: python + + from primaite.simulator.network.networks import client_server_p2p_network + + network = client_server_p2p_network() + + network.show() + +Which gives the output: + +.. code-block:: text + + +---------------------------------------+ + | Nodes | + +----------+----------+-----------------+ + | Node | Type | Operating State | + +----------+----------+-----------------+ + | server_1 | Server | ON | + | pc_1 | Computer | ON | + +----------+----------+-----------------+ + +------------------------------------------------------------------+ + | IP Addresses | + +----------+------+--------------+---------------+-----------------+ + | Node | Port | IP Address | Subnet Mask | Default Gateway | + +----------+------+--------------+---------------+-----------------+ + | server_1 | 1 | 192.168.1.13 | 255.255.255.0 | None | + | pc_1 | 1 | 192.168.1.11 | 255.255.255.0 | None | + +----------+------+--------------+---------------+-----------------+ + +------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Links | + +------------+----------------------------------------+------------+----------------------------------------+-------+-------------------+--------------+ + | Endpoint A | A Port | Endpoint B | B Port | is Up | Bandwidth (MBits) | Current Load | + +------------+----------------------------------------+------------+----------------------------------------+-------+-------------------+--------------+ + | pc_1 | Port 1: dd:70:be:52:b1:a9/192.168.1.11 | server_1 | Port 1: 17:3a:11:af:9b:b1/192.168.1.13 | True | 100.0 | 0.00000% | + +------------+----------------------------------------+------------+----------------------------------------+-------+-------------------+--------------+ #2. Basic Switched Network -------------------------- diff --git a/src/primaite/config/_package_data/client-server-p2p-network-example.yaml b/src/primaite/config/_package_data/client-server-p2p-network-example.yaml index edaeb6f4..798dd318 100644 --- a/src/primaite/config/_package_data/client-server-p2p-network-example.yaml +++ b/src/primaite/config/_package_data/client-server-p2p-network-example.yaml @@ -1,3 +1,11 @@ +game: + ports: + - ARP + protocols: + - ICMP + - TCP + - UDP + simulation: network: nodes: @@ -8,7 +16,7 @@ simulation: - hostname: server_1 type: server - ip_address: 192.168.1.11 + ip_address: 192.168.1.13 subnet_mask: 255.255.255.0 links: diff --git a/src/primaite/game/agent/observations/observations.py b/src/primaite/game/agent/observations/observations.py index 0d6ff2a3..518fdf9f 100644 --- a/src/primaite/game/agent/observations/observations.py +++ b/src/primaite/game/agent/observations/observations.py @@ -1,6 +1,6 @@ """Manages the observation space for the agent.""" from abc import ABC, abstractmethod -from typing import Any, Dict, Iterable, Type +from typing import Any, Dict, Iterable, Type, Optional, Union from gymnasium import spaces from gymnasium.core import ObsType @@ -9,7 +9,7 @@ from pydantic import BaseModel, ConfigDict from primaite import getLogger _LOGGER = getLogger(__name__) -WhereType = Iterable[str | int] | None +WhereType = Optional[Iterable[Union[str, int]]] class AbstractObservation(ABC): diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 726afaa4..0222bfcc 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -26,7 +26,7 @@ the structure: ``` """ from abc import abstractmethod -from typing import Callable, Dict, Iterable, List, Optional, Tuple, Type, TYPE_CHECKING +from typing import Callable, Dict, Iterable, List, Optional, Tuple, Type, TYPE_CHECKING, Union from typing_extensions import Never @@ -37,7 +37,7 @@ if TYPE_CHECKING: from primaite.game.agent.interface import AgentActionHistoryItem _LOGGER = getLogger(__name__) -WhereType = Iterable[str | int] | None +WhereType = Optional[Iterable[Union[str, int]]] class AbstractReward: diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 908b5148..336c27df 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -244,7 +244,7 @@ class PrimaiteGame: hostname=node_cfg["hostname"], ip_address=node_cfg["ip_address"], subnet_mask=IPv4Address(node_cfg.get("subnet_mask", "255.255.255.0")), - default_gateway=node_cfg["default_gateway"], + default_gateway=node_cfg.get("default_gateway"), dns_server=node_cfg.get("dns_server", None), operating_state=NodeOperatingState.ON if not (p := node_cfg.get("operating_state")) @@ -255,7 +255,7 @@ class PrimaiteGame: hostname=node_cfg["hostname"], ip_address=node_cfg["ip_address"], subnet_mask=IPv4Address(node_cfg.get("subnet_mask", "255.255.255.0")), - default_gateway=node_cfg["default_gateway"], + default_gateway=node_cfg.get("default_gateway"), dns_server=node_cfg.get("dns_server", None), operating_state=NodeOperatingState.ON if not (p := node_cfg.get("operating_state")) diff --git a/src/primaite/simulator/network/networks.py b/src/primaite/simulator/network/networks.py index c1eef224..36d34bc3 100644 --- a/src/primaite/simulator/network/networks.py +++ b/src/primaite/simulator/network/networks.py @@ -1,5 +1,9 @@ from ipaddress import IPv4Address +import yaml + +from primaite import PRIMAITE_PATHS +from primaite.game.game import PrimaiteGame from primaite.simulator.network.container import Network from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.network.hardware.nodes.host.host_node import NIC @@ -279,3 +283,13 @@ def arcd_uc2_network() -> Network: router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.HTTP, dst_port=Port.HTTP, position=3) return network + + +def client_server_p2p_network_example() -> Network: + path = PRIMAITE_PATHS.user_config_path / "example_config" / "client-server-p2p-network-example.yaml" + with open(path, "r") as file: + cfg = yaml.safe_load(file) + + game = PrimaiteGame.from_config(cfg) + + return game.simulation.network From a7dae6e373c91f254104a1ee98c1f9739d13bf88 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Mon, 22 Apr 2024 08:49:08 +0100 Subject: [PATCH 832/980] #2511 - Upgraded pydantic to version 2.7.0. Added ipywidgets to the dependencies (for #2300) --- CHANGELOG.md | 2 ++ pyproject.toml | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d30ae5e2..fab36bd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 3.0.0b9 - Removed deprecated `PrimaiteSession` class. +- Upgraded pydantic to version 2.7.0 +- Added ipywidgets to the dependencies ## [Unreleased] - Made requests fail to reach their target if the node is off diff --git a/pyproject.toml b/pyproject.toml index 19b5b7fa..7a6383b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,8 +38,9 @@ dependencies = [ "stable-baselines3[extra]==2.1.0", "tensorflow==2.12.0", "typer[all]==0.9.0", - "pydantic==2.1.1", - "ray[rllib] == 2.8.0, < 3" + "pydantic==2.7.0", + "ray[rllib] == 2.8.0", + "ipywidgets" ] [tool.setuptools.dynamic] From 6726a2da3789c6f14f17f4179af7a13ba8f13d26 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Mon, 22 Apr 2024 14:09:12 +0100 Subject: [PATCH 833/980] #2245: Add comment --- src/primaite/game/agent/observations/host_observations.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/primaite/game/agent/observations/host_observations.py b/src/primaite/game/agent/observations/host_observations.py index c9c73e16..02c0d17f 100644 --- a/src/primaite/game/agent/observations/host_observations.py +++ b/src/primaite/game/agent/observations/host_observations.py @@ -227,6 +227,8 @@ class HostObservation(AbstractObservation, identifier="HOST"): applications = [ApplicationObservation.from_config(config=c, parent_where=where) for c in config.applications] folders = [FolderObservation.from_config(config=c, parent_where=where) for c in config.folders] nics = [NICObservation.from_config(config=c, parent_where=where) for c in config.network_interfaces] + # If list of network interfaces is not defined, assume we want to + # monitor the first N interfaces. Network interface numbering starts at 1. count = 1 while len(nics) < config.num_nics: nic_config = NICObservation.ConfigSchema(nic_num=count, include_nmne=config.include_nmne) From 6060cbbc5babee998e9b4b1fdf0561896ff36c2c Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Tue, 23 Apr 2024 09:04:17 +0100 Subject: [PATCH 834/980] #2511 - Put the ray rlllib dep back to "ray[rllib] == 2.8.0, < 3" --- pyproject.toml | 2 +- src/primaite/game/agent/observations/observations.py | 4 ++-- src/primaite/game/agent/rewards.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7a6383b6..9d0bc3a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ dependencies = [ "tensorflow==2.12.0", "typer[all]==0.9.0", "pydantic==2.7.0", - "ray[rllib] == 2.8.0", + "ray[rllib] == 2.8.0, < 3", "ipywidgets" ] diff --git a/src/primaite/game/agent/observations/observations.py b/src/primaite/game/agent/observations/observations.py index 0d6ff2a3..518fdf9f 100644 --- a/src/primaite/game/agent/observations/observations.py +++ b/src/primaite/game/agent/observations/observations.py @@ -1,6 +1,6 @@ """Manages the observation space for the agent.""" from abc import ABC, abstractmethod -from typing import Any, Dict, Iterable, Type +from typing import Any, Dict, Iterable, Type, Optional, Union from gymnasium import spaces from gymnasium.core import ObsType @@ -9,7 +9,7 @@ from pydantic import BaseModel, ConfigDict from primaite import getLogger _LOGGER = getLogger(__name__) -WhereType = Iterable[str | int] | None +WhereType = Optional[Iterable[Union[str, int]]] class AbstractObservation(ABC): diff --git a/src/primaite/game/agent/rewards.py b/src/primaite/game/agent/rewards.py index 726afaa4..0222bfcc 100644 --- a/src/primaite/game/agent/rewards.py +++ b/src/primaite/game/agent/rewards.py @@ -26,7 +26,7 @@ the structure: ``` """ from abc import abstractmethod -from typing import Callable, Dict, Iterable, List, Optional, Tuple, Type, TYPE_CHECKING +from typing import Callable, Dict, Iterable, List, Optional, Tuple, Type, TYPE_CHECKING, Union from typing_extensions import Never @@ -37,7 +37,7 @@ if TYPE_CHECKING: from primaite.game.agent.interface import AgentActionHistoryItem _LOGGER = getLogger(__name__) -WhereType = Iterable[str | int] | None +WhereType = Optional[Iterable[Union[str, int]]] class AbstractReward: From 2b3664ce36b4c9d1acf7319c9ff6e1b52f597ef2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 23 Apr 2024 09:29:59 +0100 Subject: [PATCH 835/980] #2476 Add proof of concept yaml combining notebook --- .pre-commit-config.yaml | 1 + .../scenario_with_placeholders/greens_1.yaml | 98 +++ .../scenario_with_placeholders/greens_2.yaml | 49 ++ .../scenario_with_placeholders/reds_1.yaml | 32 + .../scenario_with_placeholders/reds_2.yaml | 32 + .../scenario_with_placeholders/scenario.yaml | 788 ++++++++++++++++++ .../scenario_with_placeholders/schedule.yaml | 18 + .../notebooks/Scenario-Placeholders.ipynb | 142 ++++ src/primaite/notebooks/variables.yaml | 7 + 9 files changed, 1167 insertions(+) create mode 100644 src/primaite/config/_package_data/scenario_with_placeholders/greens_1.yaml create mode 100644 src/primaite/config/_package_data/scenario_with_placeholders/greens_2.yaml create mode 100644 src/primaite/config/_package_data/scenario_with_placeholders/reds_1.yaml create mode 100644 src/primaite/config/_package_data/scenario_with_placeholders/reds_2.yaml create mode 100644 src/primaite/config/_package_data/scenario_with_placeholders/scenario.yaml create mode 100644 src/primaite/config/_package_data/scenario_with_placeholders/schedule.yaml create mode 100644 src/primaite/notebooks/Scenario-Placeholders.ipynb create mode 100644 src/primaite/notebooks/variables.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 56dc6424..91230171 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,6 +3,7 @@ repos: rev: v4.4.0 hooks: - id: check-yaml + exclude: scenario_with_placeholders/ - id: end-of-file-fixer - id: trailing-whitespace - id: check-added-large-files diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/greens_1.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/greens_1.yaml new file mode 100644 index 00000000..2702cbe6 --- /dev/null +++ b/src/primaite/config/_package_data/scenario_with_placeholders/greens_1.yaml @@ -0,0 +1,98 @@ +greens: &greens + - ref: green_client_2 + team: GREEN + type: ProbabilisticAgent + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 + observation_space: null + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_2 + applications: + - application_name: WebBrowser + - application_name: DatabaseClient + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 + + reward_function: + reward_components: + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.25 + options: + node_hostname: client_2 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.05 + options: + node_hostname: client_2 + + - ref: green_client_1 + team: GREEN + type: ProbabilisticAgent + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 + observation_space: null + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_1 + applications: + - application_name: WebBrowser + - application_name: DatabaseClient + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 + + reward_function: + reward_components: + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.25 + options: + node_hostname: client_1 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.05 + options: + node_hostname: client_1 diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/greens_2.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/greens_2.yaml new file mode 100644 index 00000000..e0c33656 --- /dev/null +++ b/src/primaite/config/_package_data/scenario_with_placeholders/greens_2.yaml @@ -0,0 +1,49 @@ +greens: &greens + - ref: green_client_2 + team: GREEN + type: ProbabilisticAgent + agent_settings: + action_probabilities: + 0: 0.3 + 1: 0.6 + 2: 0.1 + observation_space: null + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_2 + applications: + - application_name: WebBrowser + - application_name: DatabaseClient + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + max_applications_per_node: 2 + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + 2: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 1 + + reward_function: + reward_components: + - type: WEBPAGE_UNAVAILABLE_PENALTY + weight: 0.25 + options: + node_hostname: client_2 + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 0.05 + options: + node_hostname: client_2 diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/reds_1.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/reds_1.yaml new file mode 100644 index 00000000..f41fca8d --- /dev/null +++ b/src/primaite/config/_package_data/scenario_with_placeholders/reds_1.yaml @@ -0,0 +1,32 @@ +reds: &reds + - ref: attacker_1 + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: null + + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_1 + applications: + - application_name: DataManipulationBot + - node_name: client_2 + applications: + - application_name: DataManipulationBot + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 25 + frequency: 20 + variance: 5 diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/reds_2.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/reds_2.yaml new file mode 100644 index 00000000..13e1dd3b --- /dev/null +++ b/src/primaite/config/_package_data/scenario_with_placeholders/reds_2.yaml @@ -0,0 +1,32 @@ +reds: &reds + - ref: attacker_2 + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: null + + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client_1 + applications: + - application_name: DataManipulationBot + - node_name: client_2 + applications: + - application_name: DataManipulationBot + max_folders_per_node: 1 + max_files_per_folder: 1 + max_services_per_node: 1 + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: # options specific to this particular agent type, basically args of __init__(self) + start_settings: + start_step: 10 + frequency: 4 + variance: 1 diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/scenario.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/scenario.yaml new file mode 100644 index 00000000..426b79c7 --- /dev/null +++ b/src/primaite/config/_package_data/scenario_with_placeholders/scenario.yaml @@ -0,0 +1,788 @@ +io_settings: + save_agent_actions: true + save_step_metadata: false + save_pcap_logs: false + save_sys_logs: false + + +game: + max_episode_length: 128 + ports: + - HTTP + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + - UDP + thresholds: + nmne: + high: 10 + medium: 5 + low: 0 + +agents: + - *greens + - *reds + - *blue(s) + + - ref: defender + team: BLUE + type: ProxyAgent + observation_space: + type: CUSTOM + options: + components: + - type: NODES + label: NODES + options: + hosts: + - hostname: domain_controller + - hostname: web_server + services: + - service_name: WebServer + - hostname: database_server + folders: + - folder_name: database + files: + - file_name: database.db + - hostname: backup_server + - hostname: security_suite + - hostname: client_1 + - hostname: client_2 + num_services: 1 + num_applications: 0 + num_folders: 1 + num_files: 1 + num_nics: 2 + include_num_access: false + include_nmne: true + routers: + - hostname: router_1 + num_ports: 0 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + wildcard_list: + - 0.0.0.1 + port_list: + - 80 + - 5432 + protocol_list: + - ICMP + - TCP + - UDP + num_rules: 10 + + - type: LINKS + label: LINKS + options: + link_references: + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 + - type: "NONE" + label: ICS + options: {} + action_space: + action_list: + - type: DONOTHING + - type: NODE_SERVICE_SCAN + - type: NODE_SERVICE_STOP + - type: NODE_SERVICE_START + - type: NODE_SERVICE_PAUSE + - type: NODE_SERVICE_RESUME + - type: NODE_SERVICE_RESTART + - type: NODE_SERVICE_DISABLE + - type: NODE_SERVICE_ENABLE + - type: NODE_SERVICE_FIX + - type: NODE_FILE_SCAN + - type: NODE_FILE_CHECKHASH + - type: NODE_FILE_DELETE + - type: NODE_FILE_REPAIR + - type: NODE_FILE_RESTORE + - type: NODE_FOLDER_SCAN + - type: NODE_FOLDER_CHECKHASH + - type: NODE_FOLDER_REPAIR + - type: NODE_FOLDER_RESTORE + - type: NODE_OS_SCAN + - type: NODE_SHUTDOWN + - type: NODE_STARTUP + - type: NODE_RESET + - type: ROUTER_ACL_ADDRULE + - type: ROUTER_ACL_REMOVERULE + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE + + action_map: + 0: + action: DONOTHING + options: {} + # scan webapp service + 1: + action: NODE_SERVICE_SCAN + options: + node_id: 1 + service_id: 0 + # stop webapp service + 2: + action: NODE_SERVICE_STOP + options: + node_id: 1 + service_id: 0 + # start webapp service + 3: + action: "NODE_SERVICE_START" + options: + node_id: 1 + service_id: 0 + 4: + action: "NODE_SERVICE_PAUSE" + options: + node_id: 1 + service_id: 0 + 5: + action: "NODE_SERVICE_RESUME" + options: + node_id: 1 + service_id: 0 + 6: + action: "NODE_SERVICE_RESTART" + options: + node_id: 1 + service_id: 0 + 7: + action: "NODE_SERVICE_DISABLE" + options: + node_id: 1 + service_id: 0 + 8: + action: "NODE_SERVICE_ENABLE" + options: + node_id: 1 + service_id: 0 + 9: # check database.db file + action: "NODE_FILE_SCAN" + options: + node_id: 2 + folder_id: 0 + file_id: 0 + 10: + action: "NODE_FILE_SCAN" # CHECKHASH replaced by SCAN - but the behaviour is the same in this context. + options: + node_id: 2 + folder_id: 0 + file_id: 0 + 11: + action: "NODE_FILE_DELETE" + options: + node_id: 2 + folder_id: 0 + file_id: 0 + 12: + action: "NODE_FILE_REPAIR" + options: + node_id: 2 + folder_id: 0 + file_id: 0 + 13: + action: "NODE_SERVICE_FIX" + options: + node_id: 2 + service_id: 0 + 14: + action: "NODE_FOLDER_SCAN" + options: + node_id: 2 + folder_id: 0 + 15: + action: "NODE_FOLDER_SCAN" # CHECKHASH replaced by SCAN - but the behaviour is the same in this context. + options: + node_id: 2 + folder_id: 0 + 16: + action: "NODE_FOLDER_REPAIR" + options: + node_id: 2 + folder_id: 0 + 17: + action: "NODE_FOLDER_RESTORE" + options: + node_id: 2 + folder_id: 0 + 18: + action: "NODE_OS_SCAN" + options: + node_id: 0 + 19: + action: "NODE_SHUTDOWN" + options: + node_id: 0 + 20: + action: NODE_STARTUP + options: + node_id: 0 + 21: + action: NODE_RESET + options: + node_id: 0 + 22: + action: "NODE_OS_SCAN" + options: + node_id: 1 + 23: + action: "NODE_SHUTDOWN" + options: + node_id: 1 + 24: + action: NODE_STARTUP + options: + node_id: 1 + 25: + action: NODE_RESET + options: + node_id: 1 + 26: # old action num: 18 + action: "NODE_OS_SCAN" + options: + node_id: 2 + 27: + action: "NODE_SHUTDOWN" + options: + node_id: 2 + 28: + action: NODE_STARTUP + options: + node_id: 2 + 29: + action: NODE_RESET + options: + node_id: 2 + 30: + action: "NODE_OS_SCAN" + options: + node_id: 3 + 31: + action: "NODE_SHUTDOWN" + options: + node_id: 3 + 32: + action: NODE_STARTUP + options: + node_id: 3 + 33: + action: NODE_RESET + options: + node_id: 3 + 34: + action: "NODE_OS_SCAN" + options: + node_id: 4 + 35: + action: "NODE_SHUTDOWN" + options: + node_id: 4 + 36: + action: NODE_STARTUP + options: + node_id: 4 + 37: + action: NODE_RESET + options: + node_id: 4 + 38: + action: "NODE_OS_SCAN" + options: + node_id: 5 + 39: # old action num: 19 # shutdown client 1 + action: "NODE_SHUTDOWN" + options: + node_id: 5 + 40: # old action num: 20 + action: NODE_STARTUP + options: + node_id: 5 + 41: # old action num: 21 + action: NODE_RESET + options: + node_id: 5 + 42: + action: "NODE_OS_SCAN" + options: + node_id: 6 + 43: + action: "NODE_SHUTDOWN" + options: + node_id: 6 + 44: + action: NODE_STARTUP + options: + node_id: 6 + 45: + action: NODE_RESET + options: + node_id: 6 + + 46: # old action num: 22 # "ACL: ADDRULE - Block outgoing traffic from client 1" + action: "ROUTER_ACL_ADDRULE" + options: + target_router_nodename: router_1 + position: 1 + permission: 2 + source_ip_id: 7 # client 1 + dest_ip_id: 1 # ALL + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 + 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" + action: "ROUTER_ACL_ADDRULE" + options: + target_router_nodename: router_1 + position: 2 + permission: 2 + source_ip_id: 8 # client 2 + dest_ip_id: 1 # ALL + source_port_id: 1 + dest_port_id: 1 + protocol_id: 1 + source_wildcard_id: 0 + dest_wildcard_id: 0 + 48: # old action num: 24 # block tcp traffic from client 1 to web app + action: "ROUTER_ACL_ADDRULE" + options: + target_router_nodename: router_1 + position: 3 + permission: 2 + source_ip_id: 7 # client 1 + dest_ip_id: 3 # web server + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 + 49: # old action num: 25 # block tcp traffic from client 2 to web app + action: "ROUTER_ACL_ADDRULE" + options: + target_router_nodename: router_1 + position: 4 + permission: 2 + source_ip_id: 8 # client 2 + dest_ip_id: 3 # web server + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 + 50: # old action num: 26 + action: "ROUTER_ACL_ADDRULE" + options: + target_router_nodename: router_1 + position: 5 + permission: 2 + source_ip_id: 7 # client 1 + dest_ip_id: 4 # database + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 + 51: # old action num: 27 + action: "ROUTER_ACL_ADDRULE" + options: + target_router_nodename: router_1 + position: 6 + permission: 2 + source_ip_id: 8 # client 2 + dest_ip_id: 4 # database + source_port_id: 1 + dest_port_id: 1 + protocol_id: 3 + source_wildcard_id: 0 + dest_wildcard_id: 0 + 52: # old action num: 28 + action: "ROUTER_ACL_REMOVERULE" + options: + target_router_nodename: router_1 + position: 0 + 53: # old action num: 29 + action: "ROUTER_ACL_REMOVERULE" + options: + target_router_nodename: router_1 + position: 1 + 54: # old action num: 30 + action: "ROUTER_ACL_REMOVERULE" + options: + target_router_nodename: router_1 + position: 2 + 55: # old action num: 31 + action: "ROUTER_ACL_REMOVERULE" + options: + target_router_nodename: router_1 + position: 3 + 56: # old action num: 32 + action: "ROUTER_ACL_REMOVERULE" + options: + target_router_nodename: router_1 + position: 4 + 57: # old action num: 33 + action: "ROUTER_ACL_REMOVERULE" + options: + target_router_nodename: router_1 + position: 5 + 58: # old action num: 34 + action: "ROUTER_ACL_REMOVERULE" + options: + target_router_nodename: router_1 + position: 6 + 59: # old action num: 35 + action: "ROUTER_ACL_REMOVERULE" + options: + target_router_nodename: router_1 + position: 7 + 60: # old action num: 36 + action: "ROUTER_ACL_REMOVERULE" + options: + target_router_nodename: router_1 + position: 8 + 61: # old action num: 37 + action: "ROUTER_ACL_REMOVERULE" + options: + target_router_nodename: router_1 + position: 9 + 62: # old action num: 38 + action: "HOST_NIC_DISABLE" + options: + node_id: 0 + nic_id: 0 + 63: # old action num: 39 + action: "HOST_NIC_ENABLE" + options: + node_id: 0 + nic_id: 0 + 64: # old action num: 40 + action: "HOST_NIC_DISABLE" + options: + node_id: 1 + nic_id: 0 + 65: # old action num: 41 + action: "HOST_NIC_ENABLE" + options: + node_id: 1 + nic_id: 0 + 66: # old action num: 42 + action: "HOST_NIC_DISABLE" + options: + node_id: 2 + nic_id: 0 + 67: # old action num: 43 + action: "HOST_NIC_ENABLE" + options: + node_id: 2 + nic_id: 0 + 68: # old action num: 44 + action: "HOST_NIC_DISABLE" + options: + node_id: 3 + nic_id: 0 + 69: # old action num: 45 + action: "HOST_NIC_ENABLE" + options: + node_id: 3 + nic_id: 0 + 70: # old action num: 46 + action: "HOST_NIC_DISABLE" + options: + node_id: 4 + nic_id: 0 + 71: # old action num: 47 + action: "HOST_NIC_ENABLE" + options: + node_id: 4 + nic_id: 0 + 72: # old action num: 48 + action: "HOST_NIC_DISABLE" + options: + node_id: 4 + nic_id: 1 + 73: # old action num: 49 + action: "HOST_NIC_ENABLE" + options: + node_id: 4 + nic_id: 1 + 74: # old action num: 50 + action: "HOST_NIC_DISABLE" + options: + node_id: 5 + nic_id: 0 + 75: # old action num: 51 + action: "HOST_NIC_ENABLE" + options: + node_id: 5 + nic_id: 0 + 76: # old action num: 52 + action: "HOST_NIC_DISABLE" + options: + node_id: 6 + nic_id: 0 + 77: # old action num: 53 + action: "HOST_NIC_ENABLE" + options: + node_id: 6 + nic_id: 0 + + + + options: + nodes: + - node_name: domain_controller + - node_name: web_server + applications: + - application_name: DatabaseClient + services: + - service_name: WebServer + - node_name: database_server + folders: + - folder_name: database + files: + - file_name: database.db + services: + - service_name: DatabaseService + - node_name: backup_server + - node_name: security_suite + - node_name: client_1 + - node_name: client_2 + + max_folders_per_node: 2 + max_files_per_folder: 2 + max_services_per_node: 2 + max_nics_per_node: 8 + max_acl_rules: 10 + ip_list: + - 192.168.1.10 + - 192.168.1.12 + - 192.168.1.14 + - 192.168.1.16 + - 192.168.1.110 + - 192.168.10.21 + - 192.168.10.22 + - 192.168.10.110 + reward_function: + reward_components: + - type: DATABASE_FILE_INTEGRITY + weight: 0.40 + options: + node_hostname: database_server + folder_name: database + file_name: database.db + + agent_settings: + flatten_obs: true + + +simulation: + network: + nmne_config: + capture_nmne: true + nmne_capture_keywords: + - DELETE + nodes: + + - hostname: router_1 + type: router + num_ports: 5 + ports: + 1: + ip_address: 192.168.1.1 + subnet_mask: 255.255.255.0 + 2: + ip_address: 192.168.10.1 + subnet_mask: 255.255.255.0 + acl: + 18: + action: PERMIT + src_port: POSTGRES_SERVER + dst_port: POSTGRES_SERVER + 19: + action: PERMIT + src_port: DNS + dst_port: DNS + 20: + action: PERMIT + src_port: FTP + dst_port: FTP + 21: + action: PERMIT + src_port: HTTP + dst_port: HTTP + 22: + action: PERMIT + src_port: ARP + dst_port: ARP + 23: + action: PERMIT + protocol: ICMP + + - hostname: switch_1 + type: switch + num_ports: 8 + + - hostname: switch_2 + type: switch + num_ports: 8 + + - hostname: domain_controller + type: server + ip_address: 192.168.1.10 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + services: + - type: DNSServer + options: + domain_mapping: + arcd.com: 192.168.1.12 # web server + + - hostname: web_server + type: server + ip_address: 192.168.1.12 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - type: WebServer + applications: + - type: DatabaseClient + options: + db_server_ip: 192.168.1.14 + + + - hostname: database_server + type: server + ip_address: 192.168.1.14 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - type: DatabaseService + options: + backup_server_ip: 192.168.1.16 + - type: FTPClient + + - hostname: backup_server + type: server + ip_address: 192.168.1.16 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + services: + - type: FTPServer + + - hostname: security_suite + type: server + ip_address: 192.168.1.110 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + dns_server: 192.168.1.10 + network_interfaces: + 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot + ip_address: 192.168.10.110 + subnet_mask: 255.255.255.0 + + - hostname: client_1 + type: computer + ip_address: 192.168.10.21 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + applications: + - type: DataManipulationBot + options: + port_scan_p_of_success: 0.8 + data_manipulation_p_of_success: 0.8 + payload: "DELETE" + server_ip: 192.168.1.14 + - type: WebBrowser + options: + target_url: http://arcd.com/users/ + - type: DatabaseClient + options: + db_server_ip: 192.168.1.14 + services: + - type: DNSClient + + - hostname: client_2 + type: computer + ip_address: 192.168.10.22 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.10.1 + dns_server: 192.168.1.10 + applications: + - type: WebBrowser + options: + target_url: http://arcd.com/users/ + - type: DataManipulationBot + options: + port_scan_p_of_success: 0.8 + data_manipulation_p_of_success: 0.8 + payload: "DELETE" + server_ip: 192.168.1.14 + - type: DatabaseClient + options: + db_server_ip: 192.168.1.14 + services: + - type: DNSClient + + links: + - endpoint_a_hostname: router_1 + endpoint_a_port: 1 + endpoint_b_hostname: switch_1 + endpoint_b_port: 8 + - endpoint_a_hostname: router_1 + endpoint_a_port: 2 + endpoint_b_hostname: switch_2 + endpoint_b_port: 8 + - endpoint_a_hostname: switch_1 + endpoint_a_port: 1 + endpoint_b_hostname: domain_controller + endpoint_b_port: 1 + - endpoint_a_hostname: switch_1 + endpoint_a_port: 2 + endpoint_b_hostname: web_server + endpoint_b_port: 1 + - endpoint_a_hostname: switch_1 + endpoint_a_port: 3 + endpoint_b_hostname: database_server + endpoint_b_port: 1 + - endpoint_a_hostname: switch_1 + endpoint_a_port: 4 + endpoint_b_hostname: backup_server + endpoint_b_port: 1 + - endpoint_a_hostname: switch_1 + endpoint_a_port: 7 + endpoint_b_hostname: security_suite + endpoint_b_port: 1 + - endpoint_a_hostname: switch_2 + endpoint_a_port: 1 + endpoint_b_hostname: client_1 + endpoint_b_port: 1 + - endpoint_a_hostname: switch_2 + endpoint_a_port: 2 + endpoint_b_hostname: client_2 + endpoint_b_port: 1 + - endpoint_a_hostname: switch_2 + endpoint_a_port: 7 + endpoint_b_hostname: security_suite + endpoint_b_port: 2 diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/schedule.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/schedule.yaml new file mode 100644 index 00000000..866c9895 --- /dev/null +++ b/src/primaite/config/_package_data/scenario_with_placeholders/schedule.yaml @@ -0,0 +1,18 @@ +base_scenario: scenario.yaml +schedule: + 0: + green: greens_1.yaml + red: reds_1.yaml + 1: + green: greens_1.yaml + red: reds_2.yaml + 2: + green: greens_2.yaml + red: reds_1.yaml + 3: + green: greens_2.yaml + red: reds_2.yaml + +# touch base with container to see what they've implemented for training schedule and evaluation schedule - for naming convention consistency +# when you exceed the number of episodes defined in the yaml, raise a warning and loop back to the beginning +# provide minimal functionality for checking compatibility- but we will assume that the user will correctly specify the blue/red/green agents and environment. diff --git a/src/primaite/notebooks/Scenario-Placeholders.ipynb b/src/primaite/notebooks/Scenario-Placeholders.ipynb new file mode 100644 index 00000000..67835999 --- /dev/null +++ b/src/primaite/notebooks/Scenario-Placeholders.ipynb @@ -0,0 +1,142 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import yaml\n", + "from pprint import pprint\n", + "from pathlib import Path\n", + "from typing import Sequence\n", + "from primaite.session.environment import PrimaiteGymEnv\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "froot = Path('/home/cade/repos/PrimAITE/src/primaite/config/_package_data/scenario_with_placeholders/')\n", + "sch = froot / 'schedule.yaml'\n", + "fp = froot / 'scenario.yaml'\n", + "fpr1 = froot / 'reds_1.yaml'\n", + "fpr2 = froot / 'reds_2.yaml'\n", + "fpg1 = froot / 'greens_1.yaml'\n", + "fpg2 = froot / 'greens_2.yaml'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "\n", + "\n", + "with open(sch,'r') as f:\n", + " schedule = yaml.safe_load(f)\n", + "\n", + "base_scenario_path = froot / schedule['base_scenario']\n", + "episodes = [v for n,v in schedule['schedule'].items()]\n", + "all_episode_paths = {x for ep in episodes for x in ep.values()}\n", + "episode_data = {fp:open(froot / fp, 'r').read() for fp in all_episode_paths}\n", + "base_scenario = open(base_scenario_path).read()\n", + "\n", + "def get_ep_config(ep_num):\n", + " episode = episodes[ep_num]\n", + " # print(episode.values())\n", + " parsed_cfg = yaml.safe_load('\\n'.join([episode_data[v] for v in episode.values()] + [base_scenario]))\n", + " flat_agents_list = []\n", + " for a in parsed_cfg['agents']:\n", + " if isinstance(a,Sequence):\n", + " flat_agents_list.extend(a)\n", + " else:\n", + " flat_agents_list.append(a)\n", + " parsed_cfg['agents'] = flat_agents_list\n", + " return parsed_cfg\n", + "\n", + "\n", + "pprint(len(get_ep_config(0)['agents']))\n", + "# pprint(get_ep_config(0)['agents'])\n", + "\n", + "# conf_data = open('test_data_1.yaml','r').read()\n", + "# variables = open('variables.yaml','r').read()\n", + "\n", + "# yaml.safe_load(f\"{variables}\\n{conf_data}\")\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gym = PrimaiteGymEnv(game_config=get_ep_config(0))\n", + "print(list(gym.game.agents.keys()))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gym = PrimaiteGymEnv(game_config=get_ep_config(1))\n", + "print(list(gym.game.agents.keys()))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gym = PrimaiteGymEnv(game_config=get_ep_config(2))\n", + "print(list(gym.game.agents.keys()))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gym = PrimaiteGymEnv(game_config=get_ep_config(3))\n", + "print(list(gym.game.agents.keys()))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/primaite/notebooks/variables.yaml b/src/primaite/notebooks/variables.yaml new file mode 100644 index 00000000..cb4637e0 --- /dev/null +++ b/src/primaite/notebooks/variables.yaml @@ -0,0 +1,7 @@ +placeholder_1: &placeholder_1 + - a + - b + +placeholder_2: &placeholder_2 + - c + - d From 2b19c8c91dbcfc34a53cc8cafd124d0de4e953ab Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 23 Apr 2024 09:51:56 +0100 Subject: [PATCH 836/980] #2551 upgrade ray to >2.9 and resolve logging error in db client --- pyproject.toml | 2 +- src/primaite/simulator/system/applications/database_client.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9d0bc3a6..333132bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ dependencies = [ "tensorflow==2.12.0", "typer[all]==0.9.0", "pydantic==2.7.0", - "ray[rllib] == 2.8.0, < 3", + "ray[rllib] >= 2.9, < 3", "ipywidgets" ] diff --git a/src/primaite/simulator/system/applications/database_client.py b/src/primaite/simulator/system/applications/database_client.py index d304c200..e21846a3 100644 --- a/src/primaite/simulator/system/applications/database_client.py +++ b/src/primaite/simulator/system/applications/database_client.py @@ -236,7 +236,7 @@ class DatabaseClient(Application): if not connection_id: msg = "Cannot run sql query, could not establish connection with the server." - self.parent.sys_log(msg) + self.parent.sys_log.error(msg) return False uuid = str(uuid4()) From 1eca20157bb7d25689a9b56bb07ebf9e7806107f Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 23 Apr 2024 09:04:49 +0000 Subject: [PATCH 837/980] Updated CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fab36bd8..d6932739 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 3.0.0b9 - Removed deprecated `PrimaiteSession` class. - Upgraded pydantic to version 2.7.0 +- Upgraded Ray to version >= 2.9 - Added ipywidgets to the dependencies ## [Unreleased] From 28c8b7c9d98f8c16043279abf07ebbfa9014d1ec Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 23 Apr 2024 11:51:50 +0100 Subject: [PATCH 838/980] #2476 Get episode schedule working --- .../scenario_with_placeholders/greens_1.yaml | 4 +- .../scenario_with_placeholders/greens_2.yaml | 2 +- .../scenario_with_placeholders/reds_1.yaml | 2 +- .../scenario_with_placeholders/reds_2.yaml | 2 +- .../scenario_with_placeholders/scenario.yaml | 1 - .../scenario_with_placeholders/schedule.yaml | 16 +-- .../notebooks/Scenario-Placeholders.ipynb | 48 +++++++ src/primaite/session/environment.py | 21 ++- src/primaite/session/episode_schedule.py | 127 ++++++++++++++++++ 9 files changed, 198 insertions(+), 25 deletions(-) create mode 100644 src/primaite/session/episode_schedule.py diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/greens_1.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/greens_1.yaml index 2702cbe6..e152f23f 100644 --- a/src/primaite/config/_package_data/scenario_with_placeholders/greens_1.yaml +++ b/src/primaite/config/_package_data/scenario_with_placeholders/greens_1.yaml @@ -1,5 +1,5 @@ greens: &greens - - ref: green_client_2 + - ref: green_A team: GREEN type: ProbabilisticAgent agent_settings: @@ -48,7 +48,7 @@ greens: &greens options: node_hostname: client_2 - - ref: green_client_1 + - ref: green_B team: GREEN type: ProbabilisticAgent agent_settings: diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/greens_2.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/greens_2.yaml index e0c33656..87c8ffe3 100644 --- a/src/primaite/config/_package_data/scenario_with_placeholders/greens_2.yaml +++ b/src/primaite/config/_package_data/scenario_with_placeholders/greens_2.yaml @@ -1,5 +1,5 @@ greens: &greens - - ref: green_client_2 + - ref: green_C team: GREEN type: ProbabilisticAgent agent_settings: diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/reds_1.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/reds_1.yaml index f41fca8d..9019f6c6 100644 --- a/src/primaite/config/_package_data/scenario_with_placeholders/reds_1.yaml +++ b/src/primaite/config/_package_data/scenario_with_placeholders/reds_1.yaml @@ -1,5 +1,5 @@ reds: &reds - - ref: attacker_1 + - ref: red_A team: RED type: RedDatabaseCorruptingAgent diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/reds_2.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/reds_2.yaml index 13e1dd3b..c3304e17 100644 --- a/src/primaite/config/_package_data/scenario_with_placeholders/reds_2.yaml +++ b/src/primaite/config/_package_data/scenario_with_placeholders/reds_2.yaml @@ -1,5 +1,5 @@ reds: &reds - - ref: attacker_2 + - ref: red_B team: RED type: RedDatabaseCorruptingAgent diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/scenario.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/scenario.yaml index 426b79c7..b3d47f78 100644 --- a/src/primaite/config/_package_data/scenario_with_placeholders/scenario.yaml +++ b/src/primaite/config/_package_data/scenario_with_placeholders/scenario.yaml @@ -23,7 +23,6 @@ game: agents: - *greens - *reds - - *blue(s) - ref: defender team: BLUE diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/schedule.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/schedule.yaml index 866c9895..2d26eb31 100644 --- a/src/primaite/config/_package_data/scenario_with_placeholders/schedule.yaml +++ b/src/primaite/config/_package_data/scenario_with_placeholders/schedule.yaml @@ -1,17 +1,17 @@ base_scenario: scenario.yaml schedule: 0: - green: greens_1.yaml - red: reds_1.yaml + - greens_1.yaml + - reds_1.yaml 1: - green: greens_1.yaml - red: reds_2.yaml + - greens_1.yaml + - reds_2.yaml 2: - green: greens_2.yaml - red: reds_1.yaml + - greens_2.yaml + - reds_1.yaml 3: - green: greens_2.yaml - red: reds_2.yaml + - greens_2.yaml + - reds_2.yaml # touch base with container to see what they've implemented for training schedule and evaluation schedule - for naming convention consistency # when you exceed the number of episodes defined in the yaml, raise a warning and loop back to the beginning diff --git a/src/primaite/notebooks/Scenario-Placeholders.ipynb b/src/primaite/notebooks/Scenario-Placeholders.ipynb index 67835999..9de34a81 100644 --- a/src/primaite/notebooks/Scenario-Placeholders.ipynb +++ b/src/primaite/notebooks/Scenario-Placeholders.ipynb @@ -110,6 +110,54 @@ "print(list(gym.game.agents.keys()))" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from primaite.session.environment import PrimaiteGymEnv" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "env_2 = PrimaiteGymEnv(game_config='/home/cade/repos/PrimAITE/src/primaite/config/_package_data/scenario_with_placeholders')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for i in range(10):\n", + " print(env_2.episode_counter)\n", + " print(list(env_2.game.agents.keys()))\n", + " env_2.reset()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "env = PrimaiteGymEnv(game_config='/home/cade/repos/PrimAITE/src/primaite/config/_package_data/data_manipulation.yaml')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sum([[1,2],[3,4]])" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 9311e1f7..dea6b1dc 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -1,6 +1,7 @@ import copy import json -from typing import Any, Dict, Optional, SupportsFloat, Tuple +from os import PathLike +from typing import Any, Dict, Optional, SupportsFloat, Tuple, Union import gymnasium from gymnasium.core import ActType, ObsType @@ -9,6 +10,7 @@ from ray.rllib.env.multi_agent_env import MultiAgentEnv from primaite import getLogger from primaite.game.agent.interface import ProxyAgent from primaite.game.game import PrimaiteGame +from primaite.session.episode_schedule import build_scheduler, EpisodeScheduler from primaite.session.io import PrimaiteIO from primaite.simulator import SIM_OUTPUT @@ -23,17 +25,14 @@ class PrimaiteGymEnv(gymnasium.Env): assumptions about the agent list always having a list of length 1. """ - def __init__(self, game_config: Dict): + def __init__(self, game_config: Union[Dict, str, PathLike]): """Initialise the environment.""" super().__init__() - self.io = PrimaiteIO.from_config(game_config.get("io_settings", {})) + self.episode_scheduler: EpisodeScheduler = build_scheduler(game_config) + """Object that returns a config corresponding to the current episode.""" + self.io = PrimaiteIO.from_config(self.episode_scheduler(0).get("io_settings", {})) """Handles IO for the environment. This produces sys logs, agent logs, etc.""" - - self.game_config: Dict = game_config - """PrimaiteGame definition. This can be changed between episodes to enable curriculum learning.""" - self.io = PrimaiteIO.from_config(game_config.get("io_settings", {})) - """Handles IO for the environment. This produces sys logs, agent logs, etc.""" - self.game: PrimaiteGame = PrimaiteGame.from_config(copy.deepcopy(self.game_config)) + self.game: PrimaiteGame = PrimaiteGame.from_config(self.episode_scheduler(0)) """Current game.""" self._agent_name = next(iter(self.game.rl_agents)) """Name of the RL agent. Since there should only be one RL agent we can just pull the first and only key.""" @@ -94,9 +93,9 @@ class PrimaiteGymEnv(gymnasium.Env): if self.io.settings.save_agent_actions: all_agent_actions = {name: agent.action_history for name, agent in self.game.agents.items()} self.io.write_agent_actions(agent_actions=all_agent_actions, episode=self.episode_counter) - self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=copy.deepcopy(self.game_config)) - self.game.setup_for_episode(episode=self.episode_counter) self.episode_counter += 1 + self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=self.episode_scheduler(self.episode_counter)) + self.game.setup_for_episode(episode=self.episode_counter) state = self.game.get_sim_state() self.game.update_agents(state=state) next_obs = self._get_obs() diff --git a/src/primaite/session/episode_schedule.py b/src/primaite/session/episode_schedule.py new file mode 100644 index 00000000..2245e2b5 --- /dev/null +++ b/src/primaite/session/episode_schedule.py @@ -0,0 +1,127 @@ +import copy +from abc import ABC, abstractmethod +from os import PathLike +from pathlib import Path +from typing import Dict, List, Mapping, Sequence, Union + +import pydantic + +from primaite import getLogger + +_LOGGER = getLogger(__name__) +import warnings +from itertools import chain + +import yaml + + +class EpisodeScheduler(pydantic.BaseModel, ABC): + """ + Episode schedulers provide functionality to select different scenarios and game setups for each episode. + + This is useful when implementing advanced RL concepts like curriculum learning and domain randomisation. + """ + + @abstractmethod + def __call__(self, episode_num: int) -> Dict: + """Return the config that should be used during this episode.""" + + +class ConstantEpisodeScheduler(EpisodeScheduler): + """ + The constant episode schedule simply provides the same game setup every time. + """ + + config: Dict + + def __call__(self, episode_num: int) -> Dict: + """Return the same config every time.""" + return copy.deepcopy(self.config) + + +class EpisodeListScheduler(EpisodeScheduler): + """The episode list u""" + + schedule: Mapping[int, List[str]] + """Mapping from episode number to list of filenames""" + episode_data: Mapping[str, str] + """Mapping from filename to yaml string.""" + base_scenario: str + """yaml string containing the base scenario.""" + + _exceeded_episode_list: bool = False + """ + Flag that's set to true when attempting to keep generating episodes after schedule runs out. + + When this happens, we loop back to the beginning, but a warning is raised. + """ + + # TODO: be careful about off-by-one errors with episode number- should it start at 0 or 1? + def __call__(self, episode_num: int) -> Dict: + if episode_num > len(self.schedule): + if not self._exceeded_episode_list: + self._exceeded_episode_list = True + _LOGGER.warn( + f"Running episode {episode_num} but the schedule only defines" + f"{len(self.schedule)} episodes. Looping back to the beginning" + ) + # not sure if we should be using a traditional warning, or a _LOGGER.warning + episode_num = episode_num % len(self.schedule) + + filenames_to_join = self.schedule[episode_num] + yaml_data_to_join = [self.episode_data[fn] for fn in filenames_to_join] + [self.base_scenario] + joined_yaml = "\n".join(yaml_data_to_join) + parsed_cfg = yaml.safe_load(joined_yaml) + + # Unfortunately, using placeholders like this is slightly hacky, so we have to flatten the list of agents + flat_agents_list = [] + for a in parsed_cfg["agents"]: + if isinstance(a, Sequence): + flat_agents_list.extend(a) + else: + flat_agents_list.append(a) + parsed_cfg["agents"] = flat_agents_list + + return parsed_cfg + + +def build_scheduler(config: Union[str, Path, Dict]) -> EpisodeScheduler: + """ + Convenience method to build an EpisodeScheduler with a dict, file path, or folder path. + + If a path to a folder is provided, it will be treated as a list of game scenarios. + Otherwise, if a dict or a single file is provided, it will be treated as a constant game scenario. + """ + # If we get a dict, return a constant episode schedule that repeats that one config forever + if isinstance(config, Dict): + return ConstantEpisodeScheduler(config=config) + + # Cast string to Path + if isinstance(config, str): + config = Path(config) + + if not config.exists(): + raise FileNotFoundError(f"Provided config path {config} could not be found.") + + if config.is_file(): + with open(config, "r") as f: + cfg_data = yaml.safe_load(f) + return ConstantEpisodeScheduler(config=cfg_data) + + if not config.is_dir(): + raise RuntimeError("Something went wrong while building Primaite config.") + + root = config + schedule_path = root / "schedule.yaml" + + with open(schedule_path, "r") as f: + schedule = yaml.safe_load(f) + + base_scenario_path = root / schedule["base_scenario"] + files_to_load = set(chain.from_iterable(schedule["schedule"].values())) + + episode_data = {fp: (root / fp).read_text() for fp in files_to_load} + + return EpisodeListScheduler( + schedule=schedule["schedule"], episode_data=episode_data, base_scenario=base_scenario_path.read_text() + ) From c13b7d7c819d042f8175b232c7d95d45a4f23c48 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 23 Apr 2024 11:54:34 +0100 Subject: [PATCH 839/980] #2510: cleaning up logs and add logging handler clearing to prevent duplicate logs --- src/primaite/simulator/network/hardware/base.py | 1 - src/primaite/simulator/system/applications/application.py | 1 - src/primaite/simulator/system/core/software_manager.py | 1 - src/primaite/simulator/system/core/sys_log.py | 1 + src/primaite/simulator/system/services/ntp/ntp_client.py | 1 - tests/assets/configs/basic_switched_network.yaml | 1 + 6 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 55636356..70d36ea8 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -1360,7 +1360,6 @@ class Node(SimComponent): self.software_manager.install(application) application_instance = self.software_manager.software.get(str(application.__name__)) self.applications[application_instance.uuid] = application_instance - self.sys_log.info(f"Installed application {application_instance.name}") _LOGGER.debug(f"Added application {application_instance.name} to node {self.hostname}") self._application_request_manager.add_request( application_instance.name, RequestType(func=application_instance._request_manager) diff --git a/src/primaite/simulator/system/applications/application.py b/src/primaite/simulator/system/applications/application.py index ff71b51a..232c1afa 100644 --- a/src/primaite/simulator/system/applications/application.py +++ b/src/primaite/simulator/system/applications/application.py @@ -131,7 +131,6 @@ class Application(IOSoftware): """Install Application.""" super().install() if self.operating_state == ApplicationOperatingState.CLOSED: - self.sys_log.info(f"Installing Application {self.name}") self.operating_state = ApplicationOperatingState.INSTALLING def receive(self, payload: Any, session_id: str, **kwargs) -> bool: diff --git a/src/primaite/simulator/system/core/software_manager.py b/src/primaite/simulator/system/core/software_manager.py index e6fe7b23..8189caf3 100644 --- a/src/primaite/simulator/system/core/software_manager.py +++ b/src/primaite/simulator/system/core/software_manager.py @@ -97,7 +97,6 @@ class SoftwareManager: software.software_manager = self self.software[software.name] = software self.port_protocol_mapping[(software.port, software.protocol)] = software - self.sys_log.info(f"Installed {software.name}") if isinstance(software, Application): software.operating_state = ApplicationOperatingState.CLOSED diff --git a/src/primaite/simulator/system/core/sys_log.py b/src/primaite/simulator/system/core/sys_log.py index c10f7d3c..7800aeca 100644 --- a/src/primaite/simulator/system/core/sys_log.py +++ b/src/primaite/simulator/system/core/sys_log.py @@ -52,6 +52,7 @@ class SysLog: file_handler.setFormatter(logging.Formatter(log_format)) self.logger = logging.getLogger(f"{self.hostname}_sys_log") + self.logger.handlers.clear() # clear handlers self.logger.setLevel(logging.DEBUG) self.logger.addHandler(file_handler) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index fe351dba..c2e61297 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -115,7 +115,6 @@ class NTPClient(Service): :param timestep: The current timestep number. (Amount of time since simulation episode began) :type timestep: int """ - self.sys_log.info(f"{self.name} apply_timestep") super().apply_timestep(timestep) if self.operating_state == ServiceOperatingState.RUNNING: # request time from server diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 15dd377e..34a7a4d8 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -75,6 +75,7 @@ simulation: default_gateway: 192.168.10.1 dns_server: 192.168.1.10 applications: + - type: RansomwareScript - type: WebBrowser options: target_url: http://arcd.com/users/ From 8e008b6d24398c289e23cf55457a05cbf72a5194 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Tue, 23 Apr 2024 13:54:56 +0100 Subject: [PATCH 840/980] #2511 Appease isort pre commit hook --- src/primaite/game/agent/observations/observations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/game/agent/observations/observations.py b/src/primaite/game/agent/observations/observations.py index 518fdf9f..1ba87a30 100644 --- a/src/primaite/game/agent/observations/observations.py +++ b/src/primaite/game/agent/observations/observations.py @@ -1,6 +1,6 @@ """Manages the observation space for the agent.""" from abc import ABC, abstractmethod -from typing import Any, Dict, Iterable, Type, Optional, Union +from typing import Any, Dict, Iterable, Optional, Type, Union from gymnasium import spaces from gymnasium.core import ObsType From 90343bd5ec07b0bf251a4881733f131e13e41cb4 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Tue, 23 Apr 2024 16:52:53 +0100 Subject: [PATCH 841/980] #2470: apply PR suggestions --- src/primaite/simulator/file_system/file.py | 2 +- src/primaite/simulator/network/hardware/base.py | 2 +- .../applications/red_applications/data_manipulation_bot.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index 7e2847a5..3a1c24df 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -223,5 +223,5 @@ class File(FileSystemItemABC): self.num_access += 1 # file was accessed self.deleted = True - self.sys_log.warning(f"File deleted {self.folder_name}/{self.name}") + self.sys_log.info(f"File deleted {self.folder_name}/{self.name}") return True diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index ac78ce62..9811870d 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -307,7 +307,7 @@ class WiredNetworkInterface(NetworkInterface, ABC): return False if self._connected_node.operating_state != NodeOperatingState.ON: - self._connected_node.sys_log.error( + self._connected_node.sys_log.warning( f"Interface {self} cannot be enabled as the connected Node is not powered on" ) return False diff --git a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py index abb564dd..86dbbb7c 100644 --- a/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py +++ b/src/primaite/simulator/system/applications/red_applications/data_manipulation_bot.py @@ -177,7 +177,7 @@ class DataManipulationBot(Application): self.sys_log.info(f"{self.name}: Data manipulation successful") self.attack_stage = DataManipulationAttackStage.SUCCEEDED else: - self.sys_log.error(f"{self.name}: Data manipulation failed") + self.sys_log.warning(f"{self.name}: Data manipulation failed") self.attack_stage = DataManipulationAttackStage.FAILED def run(self): From d4aaeda4b6534c2b1a386235d7a62eed1800e702 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Wed, 24 Apr 2024 10:11:23 +0100 Subject: [PATCH 842/980] #2470: update doc to reflect the default log level --- docs/source/configuration/io_settings.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/configuration/io_settings.rst b/docs/source/configuration/io_settings.rst index 49bc2620..46b2f1b2 100644 --- a/docs/source/configuration/io_settings.rst +++ b/docs/source/configuration/io_settings.rst @@ -19,7 +19,7 @@ This section configures how PrimAITE saves data during simulation and training. save_pcap_logs: False save_sys_logs: False write_sys_log_to_terminal: False - sys_log_level: INFO + sys_log_level: WARNING ``save_logs`` From 228a8099a38b33b7e91ff5bfe8238146c9e821b0 Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 24 Apr 2024 17:27:27 +0100 Subject: [PATCH 843/980] #2299: Revert changes to disable check_hash() --- src/primaite/simulator/file_system/file.py | 4 ++++ src/primaite/simulator/file_system/folder.py | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/primaite/simulator/file_system/file.py b/src/primaite/simulator/file_system/file.py index f1df87fb..52fe4f85 100644 --- a/src/primaite/simulator/file_system/file.py +++ b/src/primaite/simulator/file_system/file.py @@ -166,6 +166,10 @@ class File(FileSystemItemABC): if self.previous_hash is None: self.previous_hash = current_hash + # if the previous hash and current hash do not match, mark file as corrupted + if self.previous_hash is not current_hash: + self.corrupt() + return True def repair(self) -> bool: diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index 64b4a91d..9f176660 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -388,17 +388,17 @@ class Folder(FileSystemItemABC): return False # iterate through the files and run a check hash - # no_corrupted_files = True + no_corrupted_files = True for file_id in self.files: file = self.get_file_by_id(file_uuid=file_id) file.check_hash() - # if file.health_status == FileSystemItemHealthStatus.CORRUPT: - # no_corrupted_files = False + if file.health_status == FileSystemItemHealthStatus.CORRUPT: + no_corrupted_files = False # if one file in the folder is corrupted, set the folder status to corrupted - # if not no_corrupted_files: - # self.corrupt() + if not no_corrupted_files: + self.corrupt() self.sys_log.info(f"Checking hash of folder {self.name} (id: {self.uuid})") return True From a92898d00191789bd502977fd3846bf8d164f523 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Apr 2024 13:25:26 +0100 Subject: [PATCH 844/980] #2476 Finalise explanation notebook for episode schedule --- .../scenario_with_placeholders/greens_0.yaml | 2 + .../scenario_with_placeholders/greens_1.yaml | 76 +- .../scenario_with_placeholders/greens_2.yaml | 29 +- .../scenario_with_placeholders/reds_0.yaml | 2 + .../scenario_with_placeholders/reds_1.yaml | 16 +- .../scenario_with_placeholders/reds_2.yaml | 14 +- .../scenario_with_placeholders/scenario.yaml | 779 ++---------------- .../scenario_with_placeholders/schedule.yaml | 14 +- .../notebooks/Scenario-Placeholders.ipynb | 190 ----- .../notebooks/Using-Episode-Schedules.ipynb | 372 +++++++++ src/primaite/session/episode_schedule.py | 17 +- 11 files changed, 489 insertions(+), 1022 deletions(-) create mode 100644 src/primaite/config/_package_data/scenario_with_placeholders/greens_0.yaml create mode 100644 src/primaite/config/_package_data/scenario_with_placeholders/reds_0.yaml delete mode 100644 src/primaite/notebooks/Scenario-Placeholders.ipynb create mode 100644 src/primaite/notebooks/Using-Episode-Schedules.ipynb diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/greens_0.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/greens_0.yaml new file mode 100644 index 00000000..f31c52fa --- /dev/null +++ b/src/primaite/config/_package_data/scenario_with_placeholders/greens_0.yaml @@ -0,0 +1,2 @@ +# No green agents present +greens: &greens [] diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/greens_1.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/greens_1.yaml index e152f23f..98d2392a 100644 --- a/src/primaite/config/_package_data/scenario_with_placeholders/greens_1.yaml +++ b/src/primaite/config/_package_data/scenario_with_placeholders/greens_1.yaml @@ -1,12 +1,11 @@ -greens: &greens +agents: &greens - ref: green_A team: GREEN type: ProbabilisticAgent agent_settings: action_probabilities: - 0: 0.3 - 1: 0.6 - 2: 0.1 + 0: 0.2 + 1: 0.8 observation_space: null action_space: action_list: @@ -14,14 +13,9 @@ greens: &greens - type: NODE_APPLICATION_EXECUTE options: nodes: - - node_name: client_2 + - node_name: client applications: - - application_name: WebBrowser - application_name: DatabaseClient - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_applications_per_node: 2 action_map: 0: action: DONOTHING @@ -31,68 +25,10 @@ greens: &greens options: node_id: 0 application_id: 0 - 2: - action: NODE_APPLICATION_EXECUTE - options: - node_id: 0 - application_id: 1 reward_function: reward_components: - - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.25 - options: - node_hostname: client_2 - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.05 + weight: 1.0 options: - node_hostname: client_2 - - - ref: green_B - team: GREEN - type: ProbabilisticAgent - agent_settings: - action_probabilities: - 0: 0.3 - 1: 0.6 - 2: 0.1 - observation_space: null - action_space: - action_list: - - type: DONOTHING - - type: NODE_APPLICATION_EXECUTE - options: - nodes: - - node_name: client_1 - applications: - - application_name: WebBrowser - - application_name: DatabaseClient - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_applications_per_node: 2 - action_map: - 0: - action: DONOTHING - options: {} - 1: - action: NODE_APPLICATION_EXECUTE - options: - node_id: 0 - application_id: 0 - 2: - action: NODE_APPLICATION_EXECUTE - options: - node_id: 0 - application_id: 1 - - reward_function: - reward_components: - - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.25 - options: - node_hostname: client_1 - - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.05 - options: - node_hostname: client_1 + node_hostname: client diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/greens_2.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/greens_2.yaml index 87c8ffe3..17a5977b 100644 --- a/src/primaite/config/_package_data/scenario_with_placeholders/greens_2.yaml +++ b/src/primaite/config/_package_data/scenario_with_placeholders/greens_2.yaml @@ -1,12 +1,11 @@ -greens: &greens - - ref: green_C +agents: &greens + - ref: green_B team: GREEN type: ProbabilisticAgent agent_settings: action_probabilities: - 0: 0.3 - 1: 0.6 - 2: 0.1 + 0: 0.95 + 1: 0.05 observation_space: null action_space: action_list: @@ -14,14 +13,9 @@ greens: &greens - type: NODE_APPLICATION_EXECUTE options: nodes: - - node_name: client_2 + - node_name: client applications: - - application_name: WebBrowser - application_name: DatabaseClient - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 - max_applications_per_node: 2 action_map: 0: action: DONOTHING @@ -31,19 +25,10 @@ greens: &greens options: node_id: 0 application_id: 0 - 2: - action: NODE_APPLICATION_EXECUTE - options: - node_id: 0 - application_id: 1 reward_function: reward_components: - - type: WEBPAGE_UNAVAILABLE_PENALTY - weight: 0.25 - options: - node_hostname: client_2 - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY - weight: 0.05 + weight: 1.0 options: - node_hostname: client_2 + node_hostname: client diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/reds_0.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/reds_0.yaml new file mode 100644 index 00000000..878aba97 --- /dev/null +++ b/src/primaite/config/_package_data/scenario_with_placeholders/reds_0.yaml @@ -0,0 +1,2 @@ +# No red agents present +reds: &reds [] diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/reds_1.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/reds_1.yaml index 9019f6c6..31675a0b 100644 --- a/src/primaite/config/_package_data/scenario_with_placeholders/reds_1.yaml +++ b/src/primaite/config/_package_data/scenario_with_placeholders/reds_1.yaml @@ -11,22 +11,16 @@ reds: &reds - type: NODE_APPLICATION_EXECUTE options: nodes: - - node_name: client_1 + - node_name: client applications: - application_name: DataManipulationBot - - node_name: client_2 - applications: - - application_name: DataManipulationBot - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 reward_function: reward_components: - type: DUMMY - agent_settings: # options specific to this particular agent type, basically args of __init__(self) + agent_settings: start_settings: - start_step: 25 - frequency: 20 - variance: 5 + start_step: 10 + frequency: 10 + variance: 0 diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/reds_2.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/reds_2.yaml index c3304e17..c5572b89 100644 --- a/src/primaite/config/_package_data/scenario_with_placeholders/reds_2.yaml +++ b/src/primaite/config/_package_data/scenario_with_placeholders/reds_2.yaml @@ -11,22 +11,16 @@ reds: &reds - type: NODE_APPLICATION_EXECUTE options: nodes: - - node_name: client_1 + - node_name: client applications: - application_name: DataManipulationBot - - node_name: client_2 - applications: - - application_name: DataManipulationBot - max_folders_per_node: 1 - max_files_per_folder: 1 - max_services_per_node: 1 reward_function: reward_components: - type: DUMMY - agent_settings: # options specific to this particular agent type, basically args of __init__(self) + agent_settings: start_settings: - start_step: 10 - frequency: 4 + start_step: 3 + frequency: 2 variance: 1 diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/scenario.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/scenario.yaml index b3d47f78..81848b2d 100644 --- a/src/primaite/config/_package_data/scenario_with_placeholders/scenario.yaml +++ b/src/primaite/config/_package_data/scenario_with_placeholders/scenario.yaml @@ -34,551 +34,86 @@ agents: - type: NODES label: NODES options: + routers: [] hosts: - - hostname: domain_controller - - hostname: web_server - services: - - service_name: WebServer - - hostname: database_server - folders: - - folder_name: database - files: - - file_name: database.db - - hostname: backup_server - - hostname: security_suite - - hostname: client_1 - - hostname: client_2 + - hostname: client + - hostname: server num_services: 1 - num_applications: 0 + num_applications: 1 num_folders: 1 num_files: 1 - num_nics: 2 + num_nics: 1 include_num_access: false include_nmne: true - routers: - - hostname: router_1 - num_ports: 0 - ip_list: - - 192.168.1.10 - - 192.168.1.12 - - 192.168.1.14 - - 192.168.1.16 - - 192.168.1.110 - - 192.168.10.21 - - 192.168.10.22 - - 192.168.10.110 - wildcard_list: - - 0.0.0.1 - port_list: - - 80 - - 5432 - protocol_list: - - ICMP - - TCP - - UDP - num_rules: 10 - type: LINKS label: LINKS options: link_references: - - router_1:eth-1<->switch_1:eth-8 - - router_1:eth-2<->switch_2:eth-8 - - switch_1:eth-1<->domain_controller:eth-1 - - switch_1:eth-2<->web_server:eth-1 - - switch_1:eth-3<->database_server:eth-1 - - switch_1:eth-4<->backup_server:eth-1 - - switch_1:eth-7<->security_suite:eth-1 - - switch_2:eth-1<->client_1:eth-1 - - switch_2:eth-2<->client_2:eth-1 - - switch_2:eth-7<->security_suite:eth-2 - - type: "NONE" - label: ICS - options: {} + - client:eth-1<->switch_1:eth-1 + - server:eth-1<->switch_1:eth-2 + action_space: action_list: - type: DONOTHING - - type: NODE_SERVICE_SCAN - - type: NODE_SERVICE_STOP - - type: NODE_SERVICE_START - - type: NODE_SERVICE_PAUSE - - type: NODE_SERVICE_RESUME - - type: NODE_SERVICE_RESTART - - type: NODE_SERVICE_DISABLE - - type: NODE_SERVICE_ENABLE - - type: NODE_SERVICE_FIX - - type: NODE_FILE_SCAN - - type: NODE_FILE_CHECKHASH - - type: NODE_FILE_DELETE - - type: NODE_FILE_REPAIR - - type: NODE_FILE_RESTORE - - type: NODE_FOLDER_SCAN - - type: NODE_FOLDER_CHECKHASH - - type: NODE_FOLDER_REPAIR - - type: NODE_FOLDER_RESTORE - - type: NODE_OS_SCAN - type: NODE_SHUTDOWN - type: NODE_STARTUP - - type: NODE_RESET - - type: ROUTER_ACL_ADDRULE - - type: ROUTER_ACL_REMOVERULE - type: HOST_NIC_ENABLE - type: HOST_NIC_DISABLE - action_map: - 0: - action: DONOTHING - options: {} - # scan webapp service - 1: - action: NODE_SERVICE_SCAN - options: - node_id: 1 - service_id: 0 - # stop webapp service - 2: - action: NODE_SERVICE_STOP - options: - node_id: 1 - service_id: 0 - # start webapp service - 3: - action: "NODE_SERVICE_START" - options: - node_id: 1 - service_id: 0 - 4: - action: "NODE_SERVICE_PAUSE" - options: - node_id: 1 - service_id: 0 - 5: - action: "NODE_SERVICE_RESUME" - options: - node_id: 1 - service_id: 0 - 6: - action: "NODE_SERVICE_RESTART" - options: - node_id: 1 - service_id: 0 - 7: - action: "NODE_SERVICE_DISABLE" - options: - node_id: 1 - service_id: 0 - 8: - action: "NODE_SERVICE_ENABLE" - options: - node_id: 1 - service_id: 0 - 9: # check database.db file - action: "NODE_FILE_SCAN" - options: - node_id: 2 - folder_id: 0 - file_id: 0 - 10: - action: "NODE_FILE_SCAN" # CHECKHASH replaced by SCAN - but the behaviour is the same in this context. - options: - node_id: 2 - folder_id: 0 - file_id: 0 - 11: - action: "NODE_FILE_DELETE" - options: - node_id: 2 - folder_id: 0 - file_id: 0 - 12: - action: "NODE_FILE_REPAIR" - options: - node_id: 2 - folder_id: 0 - file_id: 0 - 13: - action: "NODE_SERVICE_FIX" - options: - node_id: 2 - service_id: 0 - 14: - action: "NODE_FOLDER_SCAN" - options: - node_id: 2 - folder_id: 0 - 15: - action: "NODE_FOLDER_SCAN" # CHECKHASH replaced by SCAN - but the behaviour is the same in this context. - options: - node_id: 2 - folder_id: 0 - 16: - action: "NODE_FOLDER_REPAIR" - options: - node_id: 2 - folder_id: 0 - 17: - action: "NODE_FOLDER_RESTORE" - options: - node_id: 2 - folder_id: 0 - 18: - action: "NODE_OS_SCAN" - options: - node_id: 0 - 19: - action: "NODE_SHUTDOWN" - options: - node_id: 0 - 20: - action: NODE_STARTUP - options: - node_id: 0 - 21: - action: NODE_RESET - options: - node_id: 0 - 22: - action: "NODE_OS_SCAN" - options: - node_id: 1 - 23: - action: "NODE_SHUTDOWN" - options: - node_id: 1 - 24: - action: NODE_STARTUP - options: - node_id: 1 - 25: - action: NODE_RESET - options: - node_id: 1 - 26: # old action num: 18 - action: "NODE_OS_SCAN" - options: - node_id: 2 - 27: - action: "NODE_SHUTDOWN" - options: - node_id: 2 - 28: - action: NODE_STARTUP - options: - node_id: 2 - 29: - action: NODE_RESET - options: - node_id: 2 - 30: - action: "NODE_OS_SCAN" - options: - node_id: 3 - 31: - action: "NODE_SHUTDOWN" - options: - node_id: 3 - 32: - action: NODE_STARTUP - options: - node_id: 3 - 33: - action: NODE_RESET - options: - node_id: 3 - 34: - action: "NODE_OS_SCAN" - options: - node_id: 4 - 35: - action: "NODE_SHUTDOWN" - options: - node_id: 4 - 36: - action: NODE_STARTUP - options: - node_id: 4 - 37: - action: NODE_RESET - options: - node_id: 4 - 38: - action: "NODE_OS_SCAN" - options: - node_id: 5 - 39: # old action num: 19 # shutdown client 1 - action: "NODE_SHUTDOWN" - options: - node_id: 5 - 40: # old action num: 20 - action: NODE_STARTUP - options: - node_id: 5 - 41: # old action num: 21 - action: NODE_RESET - options: - node_id: 5 - 42: - action: "NODE_OS_SCAN" - options: - node_id: 6 - 43: - action: "NODE_SHUTDOWN" - options: - node_id: 6 - 44: - action: NODE_STARTUP - options: - node_id: 6 - 45: - action: NODE_RESET - options: - node_id: 6 - - 46: # old action num: 22 # "ACL: ADDRULE - Block outgoing traffic from client 1" - action: "ROUTER_ACL_ADDRULE" - options: - target_router_nodename: router_1 - position: 1 - permission: 2 - source_ip_id: 7 # client 1 - dest_ip_id: 1 # ALL - source_port_id: 1 - dest_port_id: 1 - protocol_id: 1 - source_wildcard_id: 0 - dest_wildcard_id: 0 - 47: # old action num: 23 # "ACL: ADDRULE - Block outgoing traffic from client 2" - action: "ROUTER_ACL_ADDRULE" - options: - target_router_nodename: router_1 - position: 2 - permission: 2 - source_ip_id: 8 # client 2 - dest_ip_id: 1 # ALL - source_port_id: 1 - dest_port_id: 1 - protocol_id: 1 - source_wildcard_id: 0 - dest_wildcard_id: 0 - 48: # old action num: 24 # block tcp traffic from client 1 to web app - action: "ROUTER_ACL_ADDRULE" - options: - target_router_nodename: router_1 - position: 3 - permission: 2 - source_ip_id: 7 # client 1 - dest_ip_id: 3 # web server - source_port_id: 1 - dest_port_id: 1 - protocol_id: 3 - source_wildcard_id: 0 - dest_wildcard_id: 0 - 49: # old action num: 25 # block tcp traffic from client 2 to web app - action: "ROUTER_ACL_ADDRULE" - options: - target_router_nodename: router_1 - position: 4 - permission: 2 - source_ip_id: 8 # client 2 - dest_ip_id: 3 # web server - source_port_id: 1 - dest_port_id: 1 - protocol_id: 3 - source_wildcard_id: 0 - dest_wildcard_id: 0 - 50: # old action num: 26 - action: "ROUTER_ACL_ADDRULE" - options: - target_router_nodename: router_1 - position: 5 - permission: 2 - source_ip_id: 7 # client 1 - dest_ip_id: 4 # database - source_port_id: 1 - dest_port_id: 1 - protocol_id: 3 - source_wildcard_id: 0 - dest_wildcard_id: 0 - 51: # old action num: 27 - action: "ROUTER_ACL_ADDRULE" - options: - target_router_nodename: router_1 - position: 6 - permission: 2 - source_ip_id: 8 # client 2 - dest_ip_id: 4 # database - source_port_id: 1 - dest_port_id: 1 - protocol_id: 3 - source_wildcard_id: 0 - dest_wildcard_id: 0 - 52: # old action num: 28 - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 0 - 53: # old action num: 29 - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 1 - 54: # old action num: 30 - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 2 - 55: # old action num: 31 - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 3 - 56: # old action num: 32 - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 4 - 57: # old action num: 33 - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 5 - 58: # old action num: 34 - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 6 - 59: # old action num: 35 - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 7 - 60: # old action num: 36 - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 8 - 61: # old action num: 37 - action: "ROUTER_ACL_REMOVERULE" - options: - target_router_nodename: router_1 - position: 9 - 62: # old action num: 38 - action: "HOST_NIC_DISABLE" - options: - node_id: 0 - nic_id: 0 - 63: # old action num: 39 - action: "HOST_NIC_ENABLE" - options: - node_id: 0 - nic_id: 0 - 64: # old action num: 40 - action: "HOST_NIC_DISABLE" - options: - node_id: 1 - nic_id: 0 - 65: # old action num: 41 - action: "HOST_NIC_ENABLE" - options: - node_id: 1 - nic_id: 0 - 66: # old action num: 42 - action: "HOST_NIC_DISABLE" - options: - node_id: 2 - nic_id: 0 - 67: # old action num: 43 - action: "HOST_NIC_ENABLE" - options: - node_id: 2 - nic_id: 0 - 68: # old action num: 44 - action: "HOST_NIC_DISABLE" - options: - node_id: 3 - nic_id: 0 - 69: # old action num: 45 - action: "HOST_NIC_ENABLE" - options: - node_id: 3 - nic_id: 0 - 70: # old action num: 46 - action: "HOST_NIC_DISABLE" - options: - node_id: 4 - nic_id: 0 - 71: # old action num: 47 - action: "HOST_NIC_ENABLE" - options: - node_id: 4 - nic_id: 0 - 72: # old action num: 48 - action: "HOST_NIC_DISABLE" - options: - node_id: 4 - nic_id: 1 - 73: # old action num: 49 - action: "HOST_NIC_ENABLE" - options: - node_id: 4 - nic_id: 1 - 74: # old action num: 50 - action: "HOST_NIC_DISABLE" - options: - node_id: 5 - nic_id: 0 - 75: # old action num: 51 - action: "HOST_NIC_ENABLE" - options: - node_id: 5 - nic_id: 0 - 76: # old action num: 52 - action: "HOST_NIC_DISABLE" - options: - node_id: 6 - nic_id: 0 - 77: # old action num: 53 - action: "HOST_NIC_ENABLE" - options: - node_id: 6 - nic_id: 0 - - - + 0: + action: DONOTHING + options: {} + 1: + action: NODE_SHUTDOWN + options: + node_id: 0 + 2: + action: NODE_SHUTDOWN + options: + node_id: 1 + 3: + action: NODE_STARTUP + options: + node_id: 0 + 4: + action: NODE_STARTUP + options: + node_id: 1 + 5: + action: HOST_NIC_DISABLE + options: + node_id: 0 + nic_id: 0 + 6: + action: HOST_NIC_DISABLE + options: + node_id: 1 + nic_id: 0 + 7: + action: HOST_NIC_ENABLE + options: + node_id: 0 + nic_id: 0 + 8: + action: HOST_NIC_ENABLE + options: + node_id: 1 + nic_id: 0 options: nodes: - - node_name: domain_controller - - node_name: web_server - applications: - - application_name: DatabaseClient - services: - - service_name: WebServer - - node_name: database_server - folders: - - folder_name: database - files: - - file_name: database.db - services: - - service_name: DatabaseService - - node_name: backup_server - - node_name: security_suite - - node_name: client_1 - - node_name: client_2 + - node_name: client + - node_name: server - max_folders_per_node: 2 - max_files_per_folder: 2 - max_services_per_node: 2 - max_nics_per_node: 8 - max_acl_rules: 10 + max_folders_per_node: 0 + max_files_per_folder: 0 + max_services_per_node: 0 + max_nics_per_node: 1 + max_acl_rules: 0 ip_list: - - 192.168.1.10 - - 192.168.1.12 - - 192.168.1.14 - - 192.168.1.16 - - 192.168.1.110 - - 192.168.10.21 - - 192.168.10.22 - - 192.168.10.110 + - 192.168.1.2 + - 192.168.1.3 + reward_function: reward_components: - type: DATABASE_FILE_INTEGRITY @@ -589,199 +124,45 @@ agents: file_name: database.db agent_settings: - flatten_obs: true + flatten_obs: false simulation: network: - nmne_config: - capture_nmne: true - nmne_capture_keywords: - - DELETE nodes: - - - hostname: router_1 - type: router - num_ports: 5 - ports: - 1: - ip_address: 192.168.1.1 - subnet_mask: 255.255.255.0 - 2: - ip_address: 192.168.10.1 - subnet_mask: 255.255.255.0 - acl: - 18: - action: PERMIT - src_port: POSTGRES_SERVER - dst_port: POSTGRES_SERVER - 19: - action: PERMIT - src_port: DNS - dst_port: DNS - 20: - action: PERMIT - src_port: FTP - dst_port: FTP - 21: - action: PERMIT - src_port: HTTP - dst_port: HTTP - 22: - action: PERMIT - src_port: ARP - dst_port: ARP - 23: - action: PERMIT - protocol: ICMP + - hostname: client + type: computer + ip_address: 192.168.1.2 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + applications: + - type: DatabaseClient + options: + db_server_ip: 192.168.1.3 + - type: DataManipulationBot + options: + server_ip: 192.168.1.3 + payload: "DELETE" - hostname: switch_1 type: switch - num_ports: 8 + num_ports: 2 - - hostname: switch_2 - type: switch - num_ports: 8 - - - hostname: domain_controller + - hostname: server type: server - ip_address: 192.168.1.10 + ip_address: 192.168.1.3 subnet_mask: 255.255.255.0 default_gateway: 192.168.1.1 services: - - type: DNSServer - options: - domain_mapping: - arcd.com: 192.168.1.12 # web server - - - hostname: web_server - type: server - ip_address: 192.168.1.12 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.1 - dns_server: 192.168.1.10 - services: - - type: WebServer - applications: - - type: DatabaseClient - options: - db_server_ip: 192.168.1.14 - - - - hostname: database_server - type: server - ip_address: 192.168.1.14 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.1 - dns_server: 192.168.1.10 - services: - - type: DatabaseService - options: - backup_server_ip: 192.168.1.16 - - type: FTPClient - - - hostname: backup_server - type: server - ip_address: 192.168.1.16 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.1 - dns_server: 192.168.1.10 - services: - - type: FTPServer - - - hostname: security_suite - type: server - ip_address: 192.168.1.110 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.1.1 - dns_server: 192.168.1.10 - network_interfaces: - 2: # unfortunately this number is currently meaningless, they're just added in order and take up the next available slot - ip_address: 192.168.10.110 - subnet_mask: 255.255.255.0 - - - hostname: client_1 - type: computer - ip_address: 192.168.10.21 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.10.1 - dns_server: 192.168.1.10 - applications: - - type: DataManipulationBot - options: - port_scan_p_of_success: 0.8 - data_manipulation_p_of_success: 0.8 - payload: "DELETE" - server_ip: 192.168.1.14 - - type: WebBrowser - options: - target_url: http://arcd.com/users/ - - type: DatabaseClient - options: - db_server_ip: 192.168.1.14 - services: - - type: DNSClient - - - hostname: client_2 - type: computer - ip_address: 192.168.10.22 - subnet_mask: 255.255.255.0 - default_gateway: 192.168.10.1 - dns_server: 192.168.1.10 - applications: - - type: WebBrowser - options: - target_url: http://arcd.com/users/ - - type: DataManipulationBot - options: - port_scan_p_of_success: 0.8 - data_manipulation_p_of_success: 0.8 - payload: "DELETE" - server_ip: 192.168.1.14 - - type: DatabaseClient - options: - db_server_ip: 192.168.1.14 - services: - - type: DNSClient + - type: DatabaseService links: - - endpoint_a_hostname: router_1 + - endpoint_a_hostname: client endpoint_a_port: 1 endpoint_b_hostname: switch_1 - endpoint_b_port: 8 - - endpoint_a_hostname: router_1 - endpoint_a_port: 2 - endpoint_b_hostname: switch_2 - endpoint_b_port: 8 - - endpoint_a_hostname: switch_1 + endpoint_b_port: 1 + + - endpoint_a_hostname: server endpoint_a_port: 1 - endpoint_b_hostname: domain_controller - endpoint_b_port: 1 - - endpoint_a_hostname: switch_1 - endpoint_a_port: 2 - endpoint_b_hostname: web_server - endpoint_b_port: 1 - - endpoint_a_hostname: switch_1 - endpoint_a_port: 3 - endpoint_b_hostname: database_server - endpoint_b_port: 1 - - endpoint_a_hostname: switch_1 - endpoint_a_port: 4 - endpoint_b_hostname: backup_server - endpoint_b_port: 1 - - endpoint_a_hostname: switch_1 - endpoint_a_port: 7 - endpoint_b_hostname: security_suite - endpoint_b_port: 1 - - endpoint_a_hostname: switch_2 - endpoint_a_port: 1 - endpoint_b_hostname: client_1 - endpoint_b_port: 1 - - endpoint_a_hostname: switch_2 - endpoint_a_port: 2 - endpoint_b_hostname: client_2 - endpoint_b_port: 1 - - endpoint_a_hostname: switch_2 - endpoint_a_port: 7 - endpoint_b_hostname: security_suite + endpoint_b_hostname: switch_1 endpoint_b_port: 2 diff --git a/src/primaite/config/_package_data/scenario_with_placeholders/schedule.yaml b/src/primaite/config/_package_data/scenario_with_placeholders/schedule.yaml index 2d26eb31..07ee4e50 100644 --- a/src/primaite/config/_package_data/scenario_with_placeholders/schedule.yaml +++ b/src/primaite/config/_package_data/scenario_with_placeholders/schedule.yaml @@ -1,18 +1,14 @@ base_scenario: scenario.yaml schedule: 0: - - greens_1.yaml - - reds_1.yaml + - greens_0.yaml + - reds_0.yaml 1: - - greens_1.yaml - - reds_2.yaml + - greens_0.yaml + - reds_1.yaml 2: - - greens_2.yaml + - greens_1.yaml - reds_1.yaml 3: - greens_2.yaml - reds_2.yaml - -# touch base with container to see what they've implemented for training schedule and evaluation schedule - for naming convention consistency -# when you exceed the number of episodes defined in the yaml, raise a warning and loop back to the beginning -# provide minimal functionality for checking compatibility- but we will assume that the user will correctly specify the blue/red/green agents and environment. diff --git a/src/primaite/notebooks/Scenario-Placeholders.ipynb b/src/primaite/notebooks/Scenario-Placeholders.ipynb deleted file mode 100644 index 9de34a81..00000000 --- a/src/primaite/notebooks/Scenario-Placeholders.ipynb +++ /dev/null @@ -1,190 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import yaml\n", - "from pprint import pprint\n", - "from pathlib import Path\n", - "from typing import Sequence\n", - "from primaite.session.environment import PrimaiteGymEnv\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "froot = Path('/home/cade/repos/PrimAITE/src/primaite/config/_package_data/scenario_with_placeholders/')\n", - "sch = froot / 'schedule.yaml'\n", - "fp = froot / 'scenario.yaml'\n", - "fpr1 = froot / 'reds_1.yaml'\n", - "fpr2 = froot / 'reds_2.yaml'\n", - "fpg1 = froot / 'greens_1.yaml'\n", - "fpg2 = froot / 'greens_2.yaml'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "\n", - "\n", - "with open(sch,'r') as f:\n", - " schedule = yaml.safe_load(f)\n", - "\n", - "base_scenario_path = froot / schedule['base_scenario']\n", - "episodes = [v for n,v in schedule['schedule'].items()]\n", - "all_episode_paths = {x for ep in episodes for x in ep.values()}\n", - "episode_data = {fp:open(froot / fp, 'r').read() for fp in all_episode_paths}\n", - "base_scenario = open(base_scenario_path).read()\n", - "\n", - "def get_ep_config(ep_num):\n", - " episode = episodes[ep_num]\n", - " # print(episode.values())\n", - " parsed_cfg = yaml.safe_load('\\n'.join([episode_data[v] for v in episode.values()] + [base_scenario]))\n", - " flat_agents_list = []\n", - " for a in parsed_cfg['agents']:\n", - " if isinstance(a,Sequence):\n", - " flat_agents_list.extend(a)\n", - " else:\n", - " flat_agents_list.append(a)\n", - " parsed_cfg['agents'] = flat_agents_list\n", - " return parsed_cfg\n", - "\n", - "\n", - "pprint(len(get_ep_config(0)['agents']))\n", - "# pprint(get_ep_config(0)['agents'])\n", - "\n", - "# conf_data = open('test_data_1.yaml','r').read()\n", - "# variables = open('variables.yaml','r').read()\n", - "\n", - "# yaml.safe_load(f\"{variables}\\n{conf_data}\")\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gym = PrimaiteGymEnv(game_config=get_ep_config(0))\n", - "print(list(gym.game.agents.keys()))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gym = PrimaiteGymEnv(game_config=get_ep_config(1))\n", - "print(list(gym.game.agents.keys()))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gym = PrimaiteGymEnv(game_config=get_ep_config(2))\n", - "print(list(gym.game.agents.keys()))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gym = PrimaiteGymEnv(game_config=get_ep_config(3))\n", - "print(list(gym.game.agents.keys()))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from primaite.session.environment import PrimaiteGymEnv" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "env_2 = PrimaiteGymEnv(game_config='/home/cade/repos/PrimAITE/src/primaite/config/_package_data/scenario_with_placeholders')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "for i in range(10):\n", - " print(env_2.episode_counter)\n", - " print(list(env_2.game.agents.keys()))\n", - " env_2.reset()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "env = PrimaiteGymEnv(game_config='/home/cade/repos/PrimAITE/src/primaite/config/_package_data/data_manipulation.yaml')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sum([[1,2],[3,4]])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "venv", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.12" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/src/primaite/notebooks/Using-Episode-Schedules.ipynb b/src/primaite/notebooks/Using-Episode-Schedules.ipynb new file mode 100644 index 00000000..80e67065 --- /dev/null +++ b/src/primaite/notebooks/Using-Episode-Schedules.ipynb @@ -0,0 +1,372 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Using Episode Schedules\n", + "\n", + "PrimAITE supports the ability to use different variations on a scenario at different episodes. This can be used to increase \n", + "domain randomisation to prevent overfitting, or to set up curriculum learning to train agents to perform more complicated tasks.\n", + "\n", + "When using a fixed scenario, a single yaml config file is used. However, to use episode schedules, PrimAITE uses a \n", + "directory with several config files that work together." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Defining variations in the config file.\n", + "\n", + "### Base scenario\n", + "The base scenario is essentially the same as a fixed yaml configuration, but it can contain placeholders that are \n", + "populated with different things at runtime each episode. The base scenario contains any network, agent, or settings that\n", + "remain fixed for the entire training/evaluation session.\n", + "\n", + "The placeholders are defined as YAML Aliases and they are denoted by an asterisk (`*placeholder`).\n", + "\n", + "### Variations\n", + "For each variation that could be used in a placeholder, there is a separate yaml file that contains the data that should populate the placeholder.\n", + "\n", + "The data that fills the placeholder is defined as a YAML Anchor in a separate file, denoted by an ampersand (`&anchor`).\n", + "\n", + "[Learn more about YAML Aliases and Anchors here.](https://www.educative.io/blog/advanced-yaml-syntax-cheatsheet#:~:text=YAML%20Anchors%20and%20Alias)\n", + "\n", + "### Schedule\n", + "Users must define which combination of scenario variations should be loaded in each episode. This takes the form of a\n", + "YAML file with a relative path to the base scenario and a list of paths to be loaded in during each episode.\n", + "\n", + "It takes the following format:\n", + "```yaml\n", + "base_scenario: base.yaml\n", + "schedule:\n", + " 0: # list of variations to load in at episode 0 (before the first call to env.reset() happens)\n", + " - laydown_1.yaml\n", + " - attack_1.yaml\n", + " 1: # list of variations to load in at episode 1 (after the first env.reset() call)\n", + " - laydown_2.yaml\n", + " - attack_2.yaml\n", + "```\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Demonstration" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Run `primaite setup` to copy the example config files into the correct directory. Then, import and define config location." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "!primaite setup" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import yaml\n", + "from primaite.session.environment import PrimaiteGymEnv\n", + "from primaite import PRIMAITE_PATHS\n", + "from prettytable import PrettyTable\n", + "scenario_path = PRIMAITE_PATHS.user_config_path / \"example_config/scenario_with_placeholders\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Base Scenario File\n", + "Let's view the contents of the base scenario file:\n", + "\n", + "It contains all the base settings that stay fixed throughout all episodes, including the `io_settings`, `game` settings, the network layout and the blue agent definition. There are two placeholders: `*greens` and `*reds`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(scenario_path/\"scenario.yaml\") as f:\n", + " print(f.read())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Schedule File\n", + "Let's view the contents of the schedule file:\n", + "\n", + "This file references the base scenario file and defines which variations should be loaded in at each episode. In this instance, there are four episodes, during the first episode `greens_0` and `reds_0` is used, during the second episode `greens_0` and `reds_1` is used, and so on." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(scenario_path/\"schedule.yaml\") as f:\n", + " print(f.read())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Green Agent Variation Files\n", + "\n", + "There are three different variants of the green agent setup. In `greens_0`, there are no green agents, in `greens_1` there is a green agent that executes the database client application 80% of the time, and in `greens_2` there is a green agent that executes the database client application 5% of the time.\n", + "\n", + "(the difference between `greens_1` and `greens_2` is in the agent name and action probabilities)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(scenario_path/\"greens_0.yaml\") as f:\n", + " print(f.read())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(scenario_path/\"greens_1.yaml\") as f:\n", + " print(f.read())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(scenario_path/\"greens_2.yaml\") as f:\n", + " print(f.read())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Red Agent Variation Files\n", + "\n", + "There are three different variants of the red agent setup. In `reds_0`, there are no red agents, in `reds_1` there is a red agent that executes every 20 steps, but in `reds_2` there is a red agent that executes every 2 steps." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(scenario_path/\"reds_0.yaml\") as f:\n", + " print(f.read())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(scenario_path/\"reds_1.yaml\") as f:\n", + " print(f.read())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open(scenario_path/\"reds_2.yaml\") as f:\n", + " print(f.read())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Running the simulation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create the environment using the variable config." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "env = PrimaiteGymEnv(game_config=scenario_path)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Episode 0\n", + "Let' run the episodes to verify that the agents are changing as expected. In episode 0, there should be no green or red agents, just the defender blue agent." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(f\"Current episode number: {env.episode_counter}\")\n", + "print(f\"Agents present: {list(env.game.agents.keys())}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Episode 1\n", + "When we reset the environment, it moves onto episode 1, where it will bring in reds_1 for red agent definition.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "env.reset()\n", + "print(f\"Current episode number: {env.episode_counter}\")\n", + "print(f\"Agents present: {list(env.game.agents.keys())}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Episode 2\n", + "When we reset the environment again, it moves onto episode 2, where it will bring in greens_1 and reds_1 for green and red agent definitions. Let's verify the agent names and that they take actions at the defined frequency.\n", + "\n", + "Most green actions will be `NODE_APPLICATION_EXECUTE` while red will `DONOTHING` except at steps 10 and 20." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "env.reset()\n", + "print(f\"Current episode number: {env.episode_counter}\")\n", + "print(f\"Agents present: {list(env.game.agents.keys())}\")\n", + "for i in range(21):\n", + " env.step(0)\n", + "\n", + "table = PrettyTable()\n", + "table.field_names = [\"step\", \"Green Action\", \"Red Action\"]\n", + "for i in range(21):\n", + " green_action = env.game.agents['green_A'].action_history[i].action\n", + " red_action = env.game.agents['red_A'].action_history[i].action\n", + " table.add_row([i, green_action, red_action])\n", + "print(table)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Episode 3\n", + "When we reset the environment again, it moves onto episode 3, where it will bring in greens_2 and reds_2 for green and red agent definitions. Let's verify the agent names and that they take actions at the defined frequency.\n", + "\n", + "Now, green will perform `NODE_APPLICATION_EXECUTE` only 5% of the time, while red will perform `NODE_APPLICATION_EXECUTE` more frequently than before." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "env.reset()\n", + "print(f\"Current episode number: {env.episode_counter}\")\n", + "print(f\"Agents present: {list(env.game.agents.keys())}\")\n", + "for i in range(21):\n", + " env.step(0)\n", + "\n", + "table = PrettyTable()\n", + "table.field_names = [\"step\", \"Green Action\", \"Red Action\"]\n", + "for i in range(21):\n", + " green_action = env.game.agents['green_B'].action_history[i].action\n", + " red_action = env.game.agents['red_B'].action_history[i].action\n", + " table.add_row([i, green_action, red_action])\n", + "print(table)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Further Episodes\n", + "\n", + "Since the schedule definition only goes up to episode 3, if we reset the environment again, we run out of episodes. The environment will simply loop back to the beginning, but it produces a warning message to make users aware that the episodes are being repeated." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "env.reset(); # semicolon suppresses jupyter outputting the observation space.\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/primaite/session/episode_schedule.py b/src/primaite/session/episode_schedule.py index 2245e2b5..c726dcff 100644 --- a/src/primaite/session/episode_schedule.py +++ b/src/primaite/session/episode_schedule.py @@ -1,18 +1,15 @@ import copy from abc import ABC, abstractmethod -from os import PathLike +from itertools import chain from pathlib import Path from typing import Dict, List, Mapping, Sequence, Union import pydantic +import yaml from primaite import getLogger _LOGGER = getLogger(__name__) -import warnings -from itertools import chain - -import yaml class EpisodeScheduler(pydantic.BaseModel, ABC): @@ -28,9 +25,7 @@ class EpisodeScheduler(pydantic.BaseModel, ABC): class ConstantEpisodeScheduler(EpisodeScheduler): - """ - The constant episode schedule simply provides the same game setup every time. - """ + """The constant episode schedule simply provides the same game setup every time.""" config: Dict @@ -40,7 +35,7 @@ class ConstantEpisodeScheduler(EpisodeScheduler): class EpisodeListScheduler(EpisodeScheduler): - """The episode list u""" + """Cycle through a list of different game setups for each episode.""" schedule: Mapping[int, List[str]] """Mapping from episode number to list of filenames""" @@ -56,9 +51,9 @@ class EpisodeListScheduler(EpisodeScheduler): When this happens, we loop back to the beginning, but a warning is raised. """ - # TODO: be careful about off-by-one errors with episode number- should it start at 0 or 1? def __call__(self, episode_num: int) -> Dict: - if episode_num > len(self.schedule): + """Return the config for the given episode number.""" + if episode_num >= len(self.schedule): if not self._exceeded_episode_list: self._exceeded_episode_list = True _LOGGER.warn( From 96b6fb81da71a935696336accdaff8f83f2150e5 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 25 Apr 2024 13:32:57 +0100 Subject: [PATCH 845/980] #2447: added mode to primaite cli + printing session to current working directory if in dev mode --- src/primaite/cli.py | 46 ++++++++++++++++++- src/primaite/session/io.py | 10 +++- .../setup/_package_data/primaite_config.yaml | 13 +----- src/primaite/utils/primaite_config_utils.py | 11 +++++ 4 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 src/primaite/utils/primaite_config_utils.py diff --git a/src/primaite/cli.py b/src/primaite/cli.py index ca493493..b65a6c97 100644 --- a/src/primaite/cli.py +++ b/src/primaite/cli.py @@ -11,7 +11,7 @@ from typing_extensions import Annotated from primaite import PRIMAITE_PATHS -app = typer.Typer() +app = typer.Typer(no_args_is_help=True) @app.command() @@ -114,3 +114,47 @@ def setup(overwrite_existing: bool = True) -> None: reset_example_configs.run(overwrite_existing=True) _LOGGER.info("PrimAITE setup complete!") + + +@app.command() +def mode( + dev: Annotated[bool, typer.Option("--dev", help="Activates PrimAITE developer mode")] = None, + prod: Annotated[bool, typer.Option("--prod", help="Activates PrimAITE production mode")] = None, +) -> None: + """ + Switch PrimAITE between developer mode and production mode. + + By default, PrimAITE will be in production mode. + + To view the current mode, use: primaite mode + + To set to development mode, use: primaite mode --dev + + To return to production mode, use: primaite mode --prod + """ + if PRIMAITE_PATHS.app_config_file_path.exists(): + with open(PRIMAITE_PATHS.app_config_file_path, "r") as file: + primaite_config = yaml.safe_load(file) + if dev and prod: + print("Unable to activate developer and production modes concurrently.") + return + + if (dev is None) and (prod is None): + is_dev_mode = primaite_config["developer_mode"] + + if is_dev_mode: + print("PrimAITE is running in developer mode.") + else: + print("PrimAITE is running in production mode.") + if dev: + # activate dev mode + primaite_config["developer_mode"] = True + with open(PRIMAITE_PATHS.app_config_file_path, "w") as file: + yaml.dump(primaite_config, file) + print("PrimAITE is running in developer mode.") + if prod: + # activate prod mode + primaite_config["developer_mode"] = False + with open(PRIMAITE_PATHS.app_config_file_path, "w") as file: + yaml.dump(primaite_config, file) + print("PrimAITE is running in production mode.") diff --git a/src/primaite/session/io.py b/src/primaite/session/io.py index 6aff6f9f..22001fd2 100644 --- a/src/primaite/session/io.py +++ b/src/primaite/session/io.py @@ -7,6 +7,7 @@ from pydantic import BaseModel, ConfigDict from primaite import getLogger, PRIMAITE_PATHS from primaite.simulator import LogLevel, SIM_OUTPUT +from src.primaite.utils.primaite_config_utils import is_dev_mode _LOGGER = getLogger(__name__) @@ -60,7 +61,14 @@ class PrimaiteIO: timestamp = datetime.now() date_str = timestamp.strftime("%Y-%m-%d") time_str = timestamp.strftime("%H-%M-%S") - session_path = PRIMAITE_PATHS.user_sessions_path / date_str / time_str + + # check if running in dev mode + if is_dev_mode(): + # if dev mode, simulation output will be the current working directory + session_path = Path.cwd() / "simulation_output" / date_str / time_str + else: + session_path = PRIMAITE_PATHS.user_sessions_path / date_str / time_str + session_path.mkdir(exist_ok=True, parents=True) return session_path diff --git a/src/primaite/setup/_package_data/primaite_config.yaml b/src/primaite/setup/_package_data/primaite_config.yaml index b9e0d73c..f80f4d8a 100644 --- a/src/primaite/setup/_package_data/primaite_config.yaml +++ b/src/primaite/setup/_package_data/primaite_config.yaml @@ -1,5 +1,7 @@ # The main PrimAITE application config file +developer_mode: False # false by default + # Logging logging: log_level: INFO @@ -9,14 +11,3 @@ logging: WARNING: '%(asctime)s::%(levelname)s::%(name)s::%(lineno)s::%(message)s' ERROR: '%(asctime)s::%(levelname)s::%(name)s::%(lineno)s::%(message)s' CRITICAL: '%(asctime)s::%(levelname)s::%(name)s::%(lineno)s::%(message)s' - -# Session -session: - outputs: - plots: - size: - auto_size: false - width: 1500 - height: 900 - template: plotly_white - range_slider: false diff --git a/src/primaite/utils/primaite_config_utils.py b/src/primaite/utils/primaite_config_utils.py new file mode 100644 index 00000000..70a7e4ba --- /dev/null +++ b/src/primaite/utils/primaite_config_utils.py @@ -0,0 +1,11 @@ +import yaml + +from primaite import PRIMAITE_PATHS + + +def is_dev_mode() -> bool: + """Returns True if PrimAITE is currently running in developer mode.""" + if PRIMAITE_PATHS.app_config_file_path.exists(): + with open(PRIMAITE_PATHS.app_config_file_path, "r") as file: + primaite_config = yaml.safe_load(file) + return primaite_config["developer_mode"] From 0fff29ef27fee9c7f8d04cbbc95e1e46f4fd6a96 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Thu, 25 Apr 2024 13:50:41 +0100 Subject: [PATCH 846/980] #2447: changelog + documentation --- CHANGELOG.md | 1 + docs/source/getting_started.rst | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81fe5621..ec5b999d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Upgraded pydantic to version 2.7.0 - Upgraded Ray to version >= 2.9 - Added ipywidgets to the dependencies +- added ability to set PrimAITE between development and production modes via PrimAITE CLI ``mode`` command ## [Unreleased] - Made requests fail to reach their target if the node is off diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index bb6e0019..d88be5c9 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -141,3 +141,29 @@ of your choice: pip install -e .[dev] To view the complete list of packages installed during PrimAITE installation, go to the dependencies page (:ref:`Dependencies`). + +4. Set PrimAITE to run on development mode + +Running step 3 should have installed PrimAITE, verify this by running + +.. code-block:: bash + :caption: Unix + + primaite setup + +.. code-block:: powershell + :caption: Windows (Powershell) + + primaite setup + +To set PrimAITE to run in development mode: + +.. code-block:: bash + :caption: Unix + + primaite mode --dev + +.. code-block:: powershell + :caption: Windows (Powershell) + + primaite mode --dev From 42ce264e7352d09c8ce7449718028ab17bc1a813 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Apr 2024 13:54:05 +0100 Subject: [PATCH 847/980] #2476 Fix string formatting --- src/primaite/session/episode_schedule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primaite/session/episode_schedule.py b/src/primaite/session/episode_schedule.py index c726dcff..69ae5778 100644 --- a/src/primaite/session/episode_schedule.py +++ b/src/primaite/session/episode_schedule.py @@ -57,7 +57,7 @@ class EpisodeListScheduler(EpisodeScheduler): if not self._exceeded_episode_list: self._exceeded_episode_list = True _LOGGER.warn( - f"Running episode {episode_num} but the schedule only defines" + f"Running episode {episode_num} but the schedule only defines " f"{len(self.schedule)} episodes. Looping back to the beginning" ) # not sure if we should be using a traditional warning, or a _LOGGER.warning From 66f31e8ed1111fbfe71c2105d82d3ae22422a80d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Apr 2024 15:09:46 +0100 Subject: [PATCH 848/980] #2476 Add test for episode scheduler --- CHANGELOG.md | 2 + .../notebooks/Using-Episode-Schedules.ipynb | 2 +- src/primaite/session/environment.py | 30 ++-- src/primaite/session/episode_schedule.py | 1 + .../scenario_with_placeholders/greens_0.yaml | 2 + .../scenario_with_placeholders/greens_1.yaml | 34 ++++ .../scenario_with_placeholders/greens_2.yaml | 34 ++++ .../scenario_with_placeholders/reds_0.yaml | 2 + .../scenario_with_placeholders/reds_1.yaml | 26 +++ .../scenario_with_placeholders/reds_2.yaml | 26 +++ .../scenario_with_placeholders/scenario.yaml | 168 ++++++++++++++++++ .../scenario_with_placeholders/schedule.yaml | 14 ++ .../environments/test_sb3_environment.py | 2 +- .../e2e_integration_tests/test_environment.py | 6 +- .../test_uc2_data_manipulation_scenario.py | 2 +- .../test_episode_scheduler.py | 68 +++++++ .../test_io_settings.py | 2 +- .../game_layer/test_actions.py | 4 +- .../game_layer/test_rewards.py | 2 +- .../unit_tests/_primaite/_session/__init__.py | 0 .../_session/test_episode_schedule.py | 52 ++++++ 21 files changed, 456 insertions(+), 23 deletions(-) create mode 100644 tests/assets/configs/scenario_with_placeholders/greens_0.yaml create mode 100644 tests/assets/configs/scenario_with_placeholders/greens_1.yaml create mode 100644 tests/assets/configs/scenario_with_placeholders/greens_2.yaml create mode 100644 tests/assets/configs/scenario_with_placeholders/reds_0.yaml create mode 100644 tests/assets/configs/scenario_with_placeholders/reds_1.yaml create mode 100644 tests/assets/configs/scenario_with_placeholders/reds_2.yaml create mode 100644 tests/assets/configs/scenario_with_placeholders/scenario.yaml create mode 100644 tests/assets/configs/scenario_with_placeholders/schedule.yaml create mode 100644 tests/integration_tests/configuration_file_parsing/test_episode_scheduler.py create mode 100644 tests/unit_tests/_primaite/_session/__init__.py create mode 100644 tests/unit_tests/_primaite/_session/test_episode_schedule.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 81fe5621..4147d6f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Upgraded pydantic to version 2.7.0 - Upgraded Ray to version >= 2.9 - Added ipywidgets to the dependencies +- Added ability to define scenarios that change depending on the episode number. +- Standardised Environment API by renaming the config parameter of `PrimaiteGymEnv` from `game_config` to `env_config` ## [Unreleased] - Made requests fail to reach their target if the node is off diff --git a/src/primaite/notebooks/Using-Episode-Schedules.ipynb b/src/primaite/notebooks/Using-Episode-Schedules.ipynb index 80e67065..c616a410 100644 --- a/src/primaite/notebooks/Using-Episode-Schedules.ipynb +++ b/src/primaite/notebooks/Using-Episode-Schedules.ipynb @@ -227,7 +227,7 @@ "metadata": {}, "outputs": [], "source": [ - "env = PrimaiteGymEnv(game_config=scenario_path)" + "env = PrimaiteGymEnv(env_config=scenario_path)" ] }, { diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index dea6b1dc..abbf051b 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -1,4 +1,3 @@ -import copy import json from os import PathLike from typing import Any, Dict, Optional, SupportsFloat, Tuple, Union @@ -25,10 +24,10 @@ class PrimaiteGymEnv(gymnasium.Env): assumptions about the agent list always having a list of length 1. """ - def __init__(self, game_config: Union[Dict, str, PathLike]): + def __init__(self, env_config: Union[Dict, str, PathLike]): """Initialise the environment.""" super().__init__() - self.episode_scheduler: EpisodeScheduler = build_scheduler(game_config) + self.episode_scheduler: EpisodeScheduler = build_scheduler(env_config) """Object that returns a config corresponding to the current episode.""" self.io = PrimaiteIO.from_config(self.episode_scheduler(0).get("io_settings", {})) """Handles IO for the environment. This produces sys logs, agent logs, etc.""" @@ -140,8 +139,8 @@ class PrimaiteRayEnv(gymnasium.Env): :param env_config: A dictionary containing the environment configuration. :type env_config: Dict """ - self.env = PrimaiteGymEnv(game_config=env_config) - self.env.episode_counter -= 1 + self.env = PrimaiteGymEnv(env_config=env_config) + # self.env.episode_counter -= 1 self.action_space = self.env.action_space self.observation_space = self.env.observation_space @@ -157,6 +156,11 @@ class PrimaiteRayEnv(gymnasium.Env): """Close the simulation.""" self.env.close() + @property + def game(self) -> PrimaiteGame: + """Pass through game from env.""" + return self.env.game + class PrimaiteRayMARLEnv(MultiAgentEnv): """Ray Environment that inherits from MultiAgentEnv to allow training MARL systems.""" @@ -168,16 +172,16 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): which is the PrimaiteGame instance. :type env_config: Dict """ - self.game_config: Dict = env_config - """PrimaiteGame definition. This can be changed between episodes to enable curriculum learning.""" - self.io = PrimaiteIO.from_config(env_config.get("io_settings")) + self.episode_counter: int = 0 + """Current episode number.""" + self.episode_scheduler: EpisodeScheduler = build_scheduler(env_config) + """Object that returns a config corresponding to the current episode.""" + self.io = PrimaiteIO.from_config(self.episode_scheduler(0).get("io_settings", {})) """Handles IO for the environment. This produces sys logs, agent logs, etc.""" - self.game: PrimaiteGame = PrimaiteGame.from_config(copy.deepcopy(self.game_config)) + self.game: PrimaiteGame = PrimaiteGame.from_config(self.episode_scheduler(self.episode_counter)) """Reference to the primaite game""" self._agent_ids = list(self.game.rl_agents.keys()) """Agent ids. This is a list of strings of agent names.""" - self.episode_counter: int = 0 - """Current episode number.""" self.terminateds = set() self.truncateds = set() @@ -203,9 +207,9 @@ class PrimaiteRayMARLEnv(MultiAgentEnv): if self.io.settings.save_agent_actions: all_agent_actions = {name: agent.action_history for name, agent in self.game.agents.items()} self.io.write_agent_actions(agent_actions=all_agent_actions, episode=self.episode_counter) - self.game: PrimaiteGame = PrimaiteGame.from_config(cfg=copy.deepcopy(self.game_config)) - self.game.setup_for_episode(episode=self.episode_counter) self.episode_counter += 1 + self.game: PrimaiteGame = PrimaiteGame.from_config(self.episode_scheduler(self.episode_counter)) + self.game.setup_for_episode(episode=self.episode_counter) state = self.game.get_sim_state() self.game.update_agents(state) next_obs = self._get_obs() diff --git a/src/primaite/session/episode_schedule.py b/src/primaite/session/episode_schedule.py index 69ae5778..fa010d27 100644 --- a/src/primaite/session/episode_schedule.py +++ b/src/primaite/session/episode_schedule.py @@ -22,6 +22,7 @@ class EpisodeScheduler(pydantic.BaseModel, ABC): @abstractmethod def __call__(self, episode_num: int) -> Dict: """Return the config that should be used during this episode.""" + ... class ConstantEpisodeScheduler(EpisodeScheduler): diff --git a/tests/assets/configs/scenario_with_placeholders/greens_0.yaml b/tests/assets/configs/scenario_with_placeholders/greens_0.yaml new file mode 100644 index 00000000..f31c52fa --- /dev/null +++ b/tests/assets/configs/scenario_with_placeholders/greens_0.yaml @@ -0,0 +1,2 @@ +# No green agents present +greens: &greens [] diff --git a/tests/assets/configs/scenario_with_placeholders/greens_1.yaml b/tests/assets/configs/scenario_with_placeholders/greens_1.yaml new file mode 100644 index 00000000..98d2392a --- /dev/null +++ b/tests/assets/configs/scenario_with_placeholders/greens_1.yaml @@ -0,0 +1,34 @@ +agents: &greens + - ref: green_A + team: GREEN + type: ProbabilisticAgent + agent_settings: + action_probabilities: + 0: 0.2 + 1: 0.8 + observation_space: null + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client + applications: + - application_name: DatabaseClient + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + + reward_function: + reward_components: + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 1.0 + options: + node_hostname: client diff --git a/tests/assets/configs/scenario_with_placeholders/greens_2.yaml b/tests/assets/configs/scenario_with_placeholders/greens_2.yaml new file mode 100644 index 00000000..17a5977b --- /dev/null +++ b/tests/assets/configs/scenario_with_placeholders/greens_2.yaml @@ -0,0 +1,34 @@ +agents: &greens + - ref: green_B + team: GREEN + type: ProbabilisticAgent + agent_settings: + action_probabilities: + 0: 0.95 + 1: 0.05 + observation_space: null + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client + applications: + - application_name: DatabaseClient + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_APPLICATION_EXECUTE + options: + node_id: 0 + application_id: 0 + + reward_function: + reward_components: + - type: GREEN_ADMIN_DATABASE_UNREACHABLE_PENALTY + weight: 1.0 + options: + node_hostname: client diff --git a/tests/assets/configs/scenario_with_placeholders/reds_0.yaml b/tests/assets/configs/scenario_with_placeholders/reds_0.yaml new file mode 100644 index 00000000..878aba97 --- /dev/null +++ b/tests/assets/configs/scenario_with_placeholders/reds_0.yaml @@ -0,0 +1,2 @@ +# No red agents present +reds: &reds [] diff --git a/tests/assets/configs/scenario_with_placeholders/reds_1.yaml b/tests/assets/configs/scenario_with_placeholders/reds_1.yaml new file mode 100644 index 00000000..31675a0b --- /dev/null +++ b/tests/assets/configs/scenario_with_placeholders/reds_1.yaml @@ -0,0 +1,26 @@ +reds: &reds + - ref: red_A + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: null + + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client + applications: + - application_name: DataManipulationBot + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_settings: + start_step: 10 + frequency: 10 + variance: 0 diff --git a/tests/assets/configs/scenario_with_placeholders/reds_2.yaml b/tests/assets/configs/scenario_with_placeholders/reds_2.yaml new file mode 100644 index 00000000..c5572b89 --- /dev/null +++ b/tests/assets/configs/scenario_with_placeholders/reds_2.yaml @@ -0,0 +1,26 @@ +reds: &reds + - ref: red_B + team: RED + type: RedDatabaseCorruptingAgent + + observation_space: null + + action_space: + action_list: + - type: DONOTHING + - type: NODE_APPLICATION_EXECUTE + options: + nodes: + - node_name: client + applications: + - application_name: DataManipulationBot + + reward_function: + reward_components: + - type: DUMMY + + agent_settings: + start_settings: + start_step: 3 + frequency: 2 + variance: 1 diff --git a/tests/assets/configs/scenario_with_placeholders/scenario.yaml b/tests/assets/configs/scenario_with_placeholders/scenario.yaml new file mode 100644 index 00000000..81848b2d --- /dev/null +++ b/tests/assets/configs/scenario_with_placeholders/scenario.yaml @@ -0,0 +1,168 @@ +io_settings: + save_agent_actions: true + save_step_metadata: false + save_pcap_logs: false + save_sys_logs: false + + +game: + max_episode_length: 128 + ports: + - HTTP + - POSTGRES_SERVER + protocols: + - ICMP + - TCP + - UDP + thresholds: + nmne: + high: 10 + medium: 5 + low: 0 + +agents: + - *greens + - *reds + + - ref: defender + team: BLUE + type: ProxyAgent + observation_space: + type: CUSTOM + options: + components: + - type: NODES + label: NODES + options: + routers: [] + hosts: + - hostname: client + - hostname: server + num_services: 1 + num_applications: 1 + num_folders: 1 + num_files: 1 + num_nics: 1 + include_num_access: false + include_nmne: true + + - type: LINKS + label: LINKS + options: + link_references: + - client:eth-1<->switch_1:eth-1 + - server:eth-1<->switch_1:eth-2 + + action_space: + action_list: + - type: DONOTHING + - type: NODE_SHUTDOWN + - type: NODE_STARTUP + - type: HOST_NIC_ENABLE + - type: HOST_NIC_DISABLE + action_map: + 0: + action: DONOTHING + options: {} + 1: + action: NODE_SHUTDOWN + options: + node_id: 0 + 2: + action: NODE_SHUTDOWN + options: + node_id: 1 + 3: + action: NODE_STARTUP + options: + node_id: 0 + 4: + action: NODE_STARTUP + options: + node_id: 1 + 5: + action: HOST_NIC_DISABLE + options: + node_id: 0 + nic_id: 0 + 6: + action: HOST_NIC_DISABLE + options: + node_id: 1 + nic_id: 0 + 7: + action: HOST_NIC_ENABLE + options: + node_id: 0 + nic_id: 0 + 8: + action: HOST_NIC_ENABLE + options: + node_id: 1 + nic_id: 0 + options: + nodes: + - node_name: client + - node_name: server + + max_folders_per_node: 0 + max_files_per_folder: 0 + max_services_per_node: 0 + max_nics_per_node: 1 + max_acl_rules: 0 + ip_list: + - 192.168.1.2 + - 192.168.1.3 + + reward_function: + reward_components: + - type: DATABASE_FILE_INTEGRITY + weight: 0.40 + options: + node_hostname: database_server + folder_name: database + file_name: database.db + + agent_settings: + flatten_obs: false + + +simulation: + network: + nodes: + - hostname: client + type: computer + ip_address: 192.168.1.2 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + applications: + - type: DatabaseClient + options: + db_server_ip: 192.168.1.3 + - type: DataManipulationBot + options: + server_ip: 192.168.1.3 + payload: "DELETE" + + - hostname: switch_1 + type: switch + num_ports: 2 + + - hostname: server + type: server + ip_address: 192.168.1.3 + subnet_mask: 255.255.255.0 + default_gateway: 192.168.1.1 + services: + - type: DatabaseService + + links: + - endpoint_a_hostname: client + endpoint_a_port: 1 + endpoint_b_hostname: switch_1 + endpoint_b_port: 1 + + - endpoint_a_hostname: server + endpoint_a_port: 1 + endpoint_b_hostname: switch_1 + endpoint_b_port: 2 diff --git a/tests/assets/configs/scenario_with_placeholders/schedule.yaml b/tests/assets/configs/scenario_with_placeholders/schedule.yaml new file mode 100644 index 00000000..07ee4e50 --- /dev/null +++ b/tests/assets/configs/scenario_with_placeholders/schedule.yaml @@ -0,0 +1,14 @@ +base_scenario: scenario.yaml +schedule: + 0: + - greens_0.yaml + - reds_0.yaml + 1: + - greens_0.yaml + - reds_1.yaml + 2: + - greens_1.yaml + - reds_1.yaml + 3: + - greens_2.yaml + - reds_2.yaml diff --git a/tests/e2e_integration_tests/environments/test_sb3_environment.py b/tests/e2e_integration_tests/environments/test_sb3_environment.py index 83965191..f6ff595f 100644 --- a/tests/e2e_integration_tests/environments/test_sb3_environment.py +++ b/tests/e2e_integration_tests/environments/test_sb3_environment.py @@ -16,7 +16,7 @@ def test_sb3_compatibility(): with open(data_manipulation_config_path(), "r") as f: cfg = yaml.safe_load(f) - gym = PrimaiteGymEnv(game_config=cfg) + gym = PrimaiteGymEnv(env_config=cfg) model = PPO("MlpPolicy", gym) model.learn(total_timesteps=1000) diff --git a/tests/e2e_integration_tests/test_environment.py b/tests/e2e_integration_tests/test_environment.py index 673e1dc4..accfad50 100644 --- a/tests/e2e_integration_tests/test_environment.py +++ b/tests/e2e_integration_tests/test_environment.py @@ -21,7 +21,7 @@ class TestPrimaiteEnvironment: """Check that environment loads correctly from config and it can be reset.""" with open(CFG_PATH, "r") as f: cfg = yaml.safe_load(f) - env = PrimaiteGymEnv(game_config=cfg) + env = PrimaiteGymEnv(env_config=cfg) def env_checks(): assert env is not None @@ -44,7 +44,7 @@ class TestPrimaiteEnvironment: """Make sure you can go all the way through the session without errors.""" with open(CFG_PATH, "r") as f: cfg = yaml.safe_load(f) - env = PrimaiteGymEnv(game_config=cfg) + env = PrimaiteGymEnv(env_config=cfg) assert (num_actions := len(env.agent.action_manager.action_map)) == 54 # run every action and make sure there's no crash @@ -88,4 +88,4 @@ class TestPrimaiteEnvironment: with open(MISCONFIGURED_PATH, "r") as f: cfg = yaml.safe_load(f) with pytest.raises(pydantic.ValidationError): - env = PrimaiteGymEnv(game_config=cfg) + env = PrimaiteGymEnv(env_config=cfg) diff --git a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py index 0b31a353..db79e504 100644 --- a/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py +++ b/tests/e2e_integration_tests/test_uc2_data_manipulation_scenario.py @@ -44,7 +44,7 @@ def test_application_install_uninstall_on_uc2(): with open(TEST_ASSETS_ROOT / "configs/test_application_install.yaml", "r") as f: cfg = yaml.safe_load(f) - env = PrimaiteGymEnv(game_config=cfg) + env = PrimaiteGymEnv(env_config=cfg) env.agent.flatten_obs = False env.reset() diff --git a/tests/integration_tests/configuration_file_parsing/test_episode_scheduler.py b/tests/integration_tests/configuration_file_parsing/test_episode_scheduler.py new file mode 100644 index 00000000..6b40fb1a --- /dev/null +++ b/tests/integration_tests/configuration_file_parsing/test_episode_scheduler.py @@ -0,0 +1,68 @@ +import pytest +import yaml + +from primaite.session.environment import PrimaiteGymEnv, PrimaiteRayEnv, PrimaiteRayMARLEnv +from tests.conftest import TEST_ASSETS_ROOT + +folder_path = TEST_ASSETS_ROOT / "configs" / "scenario_with_placeholders" +single_yaml_config = TEST_ASSETS_ROOT / "configs" / "test_primaite_session.yaml" +with open(single_yaml_config, "r") as f: + config_dict = yaml.safe_load(f) + + +@pytest.mark.parametrize("env_type", [PrimaiteGymEnv, PrimaiteRayEnv, PrimaiteRayMARLEnv]) +def test_creating_env_with_folder(env_type): + """Check that the environment can be created with a folder path.""" + + def check_taking_steps(e): + if isinstance(e, PrimaiteRayMARLEnv): + for i in range(9): + e.step({k: i for k in e.game.rl_agents}) + else: + for i in range(9): + e.step(i) + + env = env_type(env_config=folder_path) + assert env is not None + for _ in range(3): # do it multiple times to ensure it loops back to the beginning + assert len(env.game.agents) == 1 + assert "defender" in env.game.agents + check_taking_steps(env) + + env.reset() + assert len(env.game.agents) == 2 + assert "defender" in env.game.agents + assert "red_A" in env.game.agents + check_taking_steps(env) + + env.reset() + assert len(env.game.agents) == 3 + assert all([a in env.game.agents for a in ["defender", "green_A", "red_A"]]) + check_taking_steps(env) + + env.reset() + assert len(env.game.agents) == 3 + assert all([a in env.game.agents for a in ["defender", "green_B", "red_B"]]) + check_taking_steps(env) + + env.reset() + + +@pytest.mark.parametrize( + "env_data, env_type", + [ + (single_yaml_config, PrimaiteGymEnv), + (single_yaml_config, PrimaiteRayEnv), + (single_yaml_config, PrimaiteRayMARLEnv), + (config_dict, PrimaiteGymEnv), + (config_dict, PrimaiteRayEnv), + (config_dict, PrimaiteRayMARLEnv), + ], +) +def test_creating_env_with_static_config(env_data, env_type): + """Check that the environment can be created with a single yaml file.""" + env = env_type(env_config=single_yaml_config) + assert env is not None + agents_before = len(env.game.agents) + env.reset() + assert len(env.game.agents) == agents_before diff --git a/tests/integration_tests/configuration_file_parsing/test_io_settings.py b/tests/integration_tests/configuration_file_parsing/test_io_settings.py index e66350cf..21f56e97 100644 --- a/tests/integration_tests/configuration_file_parsing/test_io_settings.py +++ b/tests/integration_tests/configuration_file_parsing/test_io_settings.py @@ -24,7 +24,7 @@ def test_io_settings(): """Test that the io_settings are loaded correctly.""" with open(BASIC_CONFIG, "r") as f: cfg = yaml.safe_load(f) - env = PrimaiteGymEnv(game_config=cfg) + env = PrimaiteGymEnv(env_config=cfg) assert env.io.settings is not None diff --git a/tests/integration_tests/game_layer/test_actions.py b/tests/integration_tests/game_layer/test_actions.py index 855bc38d..edaf5d8d 100644 --- a/tests/integration_tests/game_layer/test_actions.py +++ b/tests/integration_tests/game_layer/test_actions.py @@ -507,7 +507,7 @@ def test_firewall_acl_add_remove_rule_integration(): with open(FIREWALL_ACTIONS_NETWORK, "r") as f: cfg = yaml.safe_load(f) - env = PrimaiteGymEnv(game_config=cfg) + env = PrimaiteGymEnv(env_config=cfg) # 1: Check that traffic is normal and acl starts off with 4 rules. firewall = env.game.simulation.network.get_node_by_hostname("firewall") @@ -598,7 +598,7 @@ def test_firewall_port_disable_enable_integration(): with open(FIREWALL_ACTIONS_NETWORK, "r") as f: cfg = yaml.safe_load(f) - env = PrimaiteGymEnv(game_config=cfg) + env = PrimaiteGymEnv(env_config=cfg) firewall = env.game.simulation.network.get_node_by_hostname("firewall") assert firewall.dmz_port.enabled == True diff --git a/tests/integration_tests/game_layer/test_rewards.py b/tests/integration_tests/game_layer/test_rewards.py index cfd013bc..7c38057e 100644 --- a/tests/integration_tests/game_layer/test_rewards.py +++ b/tests/integration_tests/game_layer/test_rewards.py @@ -103,7 +103,7 @@ def test_shared_reward(): with open(CFG_PATH, "r") as f: cfg = yaml.safe_load(f) - env = PrimaiteGymEnv(game_config=cfg) + env = PrimaiteGymEnv(env_config=cfg) env.reset() diff --git a/tests/unit_tests/_primaite/_session/__init__.py b/tests/unit_tests/_primaite/_session/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit_tests/_primaite/_session/test_episode_schedule.py b/tests/unit_tests/_primaite/_session/test_episode_schedule.py new file mode 100644 index 00000000..5d28f24e --- /dev/null +++ b/tests/unit_tests/_primaite/_session/test_episode_schedule.py @@ -0,0 +1,52 @@ +# FILEPATH: /home/cade/repos/PrimAITE/tests/unit_tests/_primaite/_session/test_episode_schedule.py + +import pytest +import yaml + +from primaite.session.episode_schedule import ConstantEpisodeScheduler, EpisodeListScheduler + + +def test_episode_list_scheduler(): + # Initialize an instance of EpisodeListScheduler + + # Define a schedule and episode data for testing + schedule = {0: ["episode1"], 1: ["episode2"]} + episode_data = {"episode1": "data1: 1", "episode2": "data2: 2"} + base_scenario = """agents: []""" + + scheduler = EpisodeListScheduler(schedule=schedule, episode_data=episode_data, base_scenario=base_scenario) + # Test when episode number is within the schedule + result = scheduler(0) + assert isinstance(result, dict) + assert yaml.safe_load("data1: 1\nagents: []") == result + + # Test next episode + result = scheduler(1) + assert isinstance(result, dict) + assert yaml.safe_load("data2: 2\nagents: []") == result + + # Test when episode number exceeds the schedule + result = scheduler(2) + assert isinstance(result, dict) + assert yaml.safe_load("data1: 1\nagents: []") == result + assert scheduler._exceeded_episode_list + + # Test when episode number is a sequence + scheduler.schedule = {0: ["episode1", "episode2"]} + result = scheduler(0) + assert isinstance(result, dict) + assert yaml.safe_load("data1: 1\ndata2: 2\nagents: []") == result + + +def test_constant_episode_scheduler(): + # Initialize an instance of ConstantEpisodeScheduler + config = {"key": "value"} + scheduler = ConstantEpisodeScheduler(config=config) + + result = scheduler(0) + assert isinstance(result, dict) + assert {"key": "value"} == result + + result = scheduler(1) + assert isinstance(result, dict) + assert {"key": "value"} == result From 736408f8b4b0ac070be6e49544ed5feb2ccccb16 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Thu, 25 Apr 2024 15:12:46 +0100 Subject: [PATCH 849/980] Reference the episode schedule notebook in docs --- docs/source/config.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/source/config.rst b/docs/source/config.rst index b334d99b..57948ae2 100644 --- a/docs/source/config.rst +++ b/docs/source/config.rst @@ -5,7 +5,7 @@ PrimAITE |VERSION| Configuration ******************************** -PrimAITE uses a single configuration file to define everything needed to create the training environment for RL agents, including the network, the scripted agents, and the RL agent's action space, observation space, and reward function. +PrimAITE uses YAML configuration files to define everything needed to create the training environment for RL agents, including the network, the scripted agents, and the RL agent's action space, observation space, and reward function. Example Configuration Hierarchy ############################### @@ -34,3 +34,8 @@ Configurable items configuration/game.rst configuration/agents.rst configuration/simulation.rst + +Varying The Configuration Each Episode +###################################### + +PrimAITE allows for the configuration to be varied each episode. This is done by specifying a configuration folder instead of a single file. A full explanation is provided in the notebook `Using-Episode-Schedules.ipynb`. Please find the notebook in the user notebooks directory. From c93c432bf171d74f094e93b012a54cc1885ef77b Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Thu, 25 Apr 2024 15:14:40 +0100 Subject: [PATCH 850/980] #2266 - Added final complex network to the examples. Just need to finalise the building the config section --- ...rimaite_example_basic_lan_network_dark.png | Bin 0 -> 46820 bytes ...imaite_example_basic_lan_network_light.png | Bin 0 -> 45179 bytes ...aite_example_client_server_p2p_network.png | Bin 18342 -> 0 bytes ...example_client_server_p2p_network_dark.png | Bin 0 -> 14868 bytes ...xample_client_server_p2p_network_light.png | Bin 0 -> 14600 bytes ...e_multi_lan_with_internet_network_dark.png | Bin 0 -> 210643 bytes ..._multi_lan_with_internet_network_light.png | Bin 0 -> 202328 bytes .../images/primaite_node_type_colour_key.png | Bin 72331 -> 0 bytes .../primaite_node_type_colour_key_dark.png | Bin 0 -> 74226 bytes .../primaite_node_type_colour_key_light.png | Bin 0 -> 66675 bytes .../simulation/nodes/network_examples.rst | 407 +++++++++++++++++- .../basic-lan-network-example.yaml | 65 +++ .../multi_lan_internet_network_example.yaml | 354 +++++++++++++++ src/primaite/simulator/network/networks.py | 33 +- 14 files changed, 837 insertions(+), 22 deletions(-) create mode 100644 docs/source/configuration/simulation/nodes/images/primaite_example_basic_lan_network_dark.png create mode 100644 docs/source/configuration/simulation/nodes/images/primaite_example_basic_lan_network_light.png delete mode 100644 docs/source/configuration/simulation/nodes/images/primaite_example_client_server_p2p_network.png create mode 100644 docs/source/configuration/simulation/nodes/images/primaite_example_client_server_p2p_network_dark.png create mode 100644 docs/source/configuration/simulation/nodes/images/primaite_example_client_server_p2p_network_light.png create mode 100644 docs/source/configuration/simulation/nodes/images/primaite_example_multi_lan_with_internet_network_dark.png create mode 100644 docs/source/configuration/simulation/nodes/images/primaite_example_multi_lan_with_internet_network_light.png delete mode 100644 docs/source/configuration/simulation/nodes/images/primaite_node_type_colour_key.png create mode 100644 docs/source/configuration/simulation/nodes/images/primaite_node_type_colour_key_dark.png create mode 100644 docs/source/configuration/simulation/nodes/images/primaite_node_type_colour_key_light.png create mode 100644 src/primaite/config/_package_data/basic-lan-network-example.yaml create mode 100644 src/primaite/config/_package_data/multi_lan_internet_network_example.yaml diff --git a/docs/source/configuration/simulation/nodes/images/primaite_example_basic_lan_network_dark.png b/docs/source/configuration/simulation/nodes/images/primaite_example_basic_lan_network_dark.png new file mode 100644 index 0000000000000000000000000000000000000000..c76f3daf3b1b10ae2a703ff5f396ac51b39ef575 GIT binary patch literal 46820 zcmeFZXIN8N_czRpBRGm6Hc%;|C@KgdqSBI45JZ}a(jhcOiGUC~Byon3A|(m}N{hlE z9YhEnqC<()h?F2LK!5;&1PCFJkmNl9oO|Z}|3AE6pXV7qa9ufPpMBQ;?X`ZZ?3F~` zG|}I^^YBgq0fF5H*L80T2>k3MAh4}#hahkTZm-iJAn-)MK=;a>0QauPbr#5`*-LHp9Cpg7{B_{w{+bfKN;*%^mg(A&C$P2 zR|USS@y}0Z`I!>#SafvyLzHLEI=st!m+k6jIUjO|W6HZ=rd#XZZ4$TaP-lj`xD9wc z|If3sU$huhJ3|*3HI4%(p^3{^INx?}-V>;m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_UGI;wp`gi03OgA4^Rv`Hu^ZS>yk#9+BC~T{Pk|($>q+8F2ElD-Jez$ z4OXjkLl~9NsWj^+K5OnM_?ATz5s~TjtONJ~%!QTj`}M*vIFD{=Qvux}mO454$XK+i0QPV&Tbr4O?qwX;nX9Xctpm$ zUD(Vp%TR;1ZaeP8p15z}OIx*W4btfv^$xkU>=R*%&I_7gdre@rg5MCj*+s9QDvW-s z3BAYrF-as3ImezrdfUcP-qWu&__HkfJc9eL%TUF1qRrc=Nn`~AHJKd|fhKOhzzYPpk^AoLV@rQ6A7{W!M|ozG;;?T2b;Db)^03?B3pSZnN54 z=!D|Nq3xu^*RV)Teu{QTknyRCz-uy0F&*m1<=X67>3gXeWd!7_-mUfVNZ+*%IqbI_ zMHW57R5Hf+UOV;+-M4)FqJKa2lnZq{U$*6k(ax^>L0KCVQtXzy@2Z_pcofBa{DPkM nauT;_rEIIzc6FodLtYT`ZXv}YHGQg+)x3`OC9OhD`_TUd9&!%A literal 0 HcmV?d00001 diff --git a/docs/source/configuration/simulation/nodes/images/primaite_example_client_server_p2p_network.png b/docs/source/configuration/simulation/nodes/images/primaite_example_client_server_p2p_network.png deleted file mode 100644 index 54fb7442d9f37eccd72e648ed702a7c5e3c604c7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 18342 zcmeIac|4SD_%}RCv{>pc386cRWM{};DN9+BEqk&rV;yAIMrAA6cagD=FqXlngsg)x zCI&;Y4kqiwSe|q0e%|-<{_(tjzJI)*-`sc7%v{@f9_R60j^nys-P6-#JQ>jki~}(h+--P z!s(TXHc$p1Fg?1fc?)tt|1Y;0@eaIm%uCD67XlF%p#Ncb{6WnhyvYpL*1gR<&v=?u z!(02-4Wq}S%j3atBmC$6)j8-wd_lsOlP_dlkG*+%?o-4`gI5N(T5n%D zBYa9C_x;PGNjDQ8of#-XIp03{E5T>=slg4|q>Kws8KTE-F<#-mV08ZQxy!Pvy7Nla zyL+dE9DVxIdIaC~Fko^}meJK%SWc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+W$#DK>hKSE$cNW!A6|)J(*8~X z{n-o$+pD1NoLImg_WQ>2=%vMPZ!dx;dsrD3DxY6LAA&rc^l#jxk*K(xO?r1|CL8~L zp7bBc^hO%y|Zd(9l>)mEe} zRYSw~Ntd+sm8Ep+NUBda_#k?xqS!b@pqmLLl5^1#{-G8}O`)9o$~{Flu3M zfqeMycFknp(8{0}J~rXE6NXBRufisp8cLAZlk-|hE%Q+cj*_sXJGJPx1 z0Zva~kfU|r*&5}?y_-NBYS8akrC)EWl?wfWB4UlUHdzP26EjM>25D9jn$c$$$7X(b znX*Ir9@{MKG>Lp&l_ryE2fX9bX*RxJz`dG~OYqwd;P$p~2Sqy{2k;j}T2fk8Oj1@% zO2J4=NNl8UX$(Mpw^l<*aH-LHCyEq2^pEuYJoWX((g#WK2z+GStzHnQZ Z*Z+B&3iq!k!8Q=>+j_SuZa#eazX1C^Vr>8b diff --git a/docs/source/configuration/simulation/nodes/images/primaite_example_client_server_p2p_network_dark.png b/docs/source/configuration/simulation/nodes/images/primaite_example_client_server_p2p_network_dark.png new file mode 100644 index 0000000000000000000000000000000000000000..066695f5380d370dc2a88db1b1684e9649a065ff GIT binary patch literal 14868 zcmeHudpy(q`@il!)qSUQP(%(XQnygZY1mznTNtGrhPiXdnGiF_?%Wm0A>=$O%7~G} zoMzTRx5JEtEgM!&i(wdM#`b$p_xG;P{r&y>dpv%B-2ZrZy!Sd@uj_hV&)4<3t^{j{ z>F%A8iLNAQfHiM%@DPN?sdJZ{!ffGXupmUVQ>tq;Y~e-wFD z(7v%~C%5i54BskjIBy&8R0~|j87SSdta?>stwT|6ESp9@%@*^ML|7j$0-m&M! zR*{*j zi0~Ak=o=fWNIDO)&W~NST6mjcB=?8GERL4ampFzgwMu!%`%*OV>bO~OEdPtC6^}cv z5-JcAj{gc4KUTCL*YUgg>-}bPbUH7NWdz%snt!MG!f+#an?>vfrLAn7c?9T6n3P3p z8gcxT_iT0)i+6aH0aqJ1XOT7@L&D|p*)9gV&rkAljn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Zf-n-&iU$4x(7!5B1n6minU7{(KH1C>j^6IV? z`tRZoK9DZ+f0Jd)VE-)+|4+mrT7k_L&1o-7c3?1j;4i?RcoDOb{J4XYknV5#8O?8I z1KvEf4TVp63fj7_tvq2w+(JcVXj|7uNL{e=E%l;wZd9Le2WmS%I5fHvzVc+_*U|6( zXby%qLyaC3tj>v-!~g8Cx=a{3EBHjYga{a|Ny&=8Ii*}6j*vPA!1L<~Uti&dqiI#t z>P-JDbAom6w{mjK0{r3GaDM-(NNMSKVzHB=lv$A$rVQ9 zX4|@RU;kOJ(bqo;GMD3M+6cHlJlJ8IUS$DSvcE%TcEJxm+^|XE@wWlRAF#twl3&>O zuAm&?rk$Id=1twzA5qEYnn7mxjTL)%$3eD81X~UVza7JYC8n8hE%GRuBocx&n_ri1 zJVzx5(@0{zWWPLt@hSVOr>p$T=8dvQ|83Av>xn;_A|JC~6vK*H_sUSVt{;FhVYyat jPH1yEZ|lRDXA*6d_@y;k|9`DX`?0pPwt&A0y(Pmx;6 literal 0 HcmV?d00001 diff --git a/docs/source/configuration/simulation/nodes/images/primaite_node_type_colour_key.png b/docs/source/configuration/simulation/nodes/images/primaite_node_type_colour_key.png deleted file mode 100644 index ace553510f70d874fa995cc877bca70adbac5d2c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 72331 zcmeFZXH-*B*EJeM#X_+oT}4IdQl(=7M5GAP2}Pv$5_$kd!A23Jmw@yR(g{@r6ok+N z384rfw9rEd1il@g=lym6+;M;2@73YJ5zaY#@3q&OYp%KW$pwAY|}S@H_+p6NW$*%^?u!1PFxL zHKqQ!EcnIAmuf1HAxG4|>5aKD;FHs?PYgXE5J7J0KN_EG1uyU+ou{h065agqiwtZ6 zRugs)!4n~>j~~47!7StaeJZGTNwZ$d2nt^d`#yewK#A>)toAR}CwDci<0U``MS*6z~sv48)ApicoafIp*` zGC2PIC;3JtE%iUs2M`G*TRQ5`mYn~6$p6~p z|6)IRVOhu*7aza0iBdo(irRQ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wj|>MMLC2R*_USov6h`ActT_&# za%xkxciVLmr8`P0{}ZravkD5e89DpoU+N#sZZ>^?`)!JD0#UYnu?a}RP2KvYCzTMGnC zTMp)HUWOqd1u>vdK+cdXOc(Xq4ET+ZfBaj=ssAoignYvPCv}=e{QxfLghP1NLA01b z%FAk{AM*VB6$1e908j}Nrr^|Zo$ayuM1>NR>REaICX-mC6*k=)Ak;zlQ#a*EJ>Zu_ zFlPd|vT0C&Z9=x}cM^k+n5QUI@+&3Rk8zQm6enzE!jf8;J5(Uh3WLPbsDp@hi#jFB zDqA4J|ATD$QBNfg_=%*$NiKpi7or&J&%vv~?J_asQB)hSh+4;-^nNEY0+DdTQv8g= z%#@$oBp?=vkMdo*Eg*0mbJY6L@;tq~gW$BiWO|nI6p~X@#Ze#HOe)3-52oAx$bIB*4js_L+6xGz(avR{YgS$&h>~I{987ipaba zLGWAf`W7P-a~tjc)t976L%pO1h_I6YscAwzITidS@XF#uLARu+XjO!Q_d`!8z7x9V zs5%UgIRqm4El6G3e3H*JK7N!AEyLW+GLXP)9Yw{=3lO5hRFW4O5P>}EuF z0!M-o$X29+5&}Q7xqcn$f{is;n1U>Ux(%t2zCY1H*6u8DDJW*FK7SUeB0(!7_{2fp zBt_?b!45;aRUv>PvsTufG*mscp~`ax9u;*zciH{AmAj3y^=%vY3w7+svE$N5j!Pds zVR%$d`Iw^eae1jDN0g5oA%)5{{Feq!F4ygEc>nhex|)J+LW4v9>kaPqPBw1tR!+D6 W`!-LiGxCrLV9s4UOH{vl?>_+U?8jRG diff --git a/docs/source/configuration/simulation/nodes/images/primaite_node_type_colour_key_dark.png b/docs/source/configuration/simulation/nodes/images/primaite_node_type_colour_key_dark.png new file mode 100644 index 0000000000000000000000000000000000000000..fa803ec7969677ac33b57b840602c2a319699fe3 GIT binary patch literal 74226 zcmeFYd05iv_djekW@%>2sFkTx&19u!WvOXOX=P1|tuCNqnM>l58g2+wrdF0trh_P2M_E$p`tQRprWFRTQDE^B#lwDPetXD%E7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EzKOBti z*MxDvp?kl)zhF2=8OU#Km&p=h`3tTIPzK>syNH|PEiw@u;JLAc4Ze;Dz(ahDA0vFZ+i z?7##8UFzp>4?hN6jTu*`LI8ia<;!?%_wCP{FX;x2)G}M0s%i~IFb6PZch|dk4;NeX zBh`S}gj)U>6yFhzZDh8AQ8hAa6ENz|$-jj`qCW_O{NPck1_$1N*pR){ZCaAbLl^PV z`935vp?F_rf#l-FL`{eKU9_VvKxF7$L`-G>{Rmn@WSJ%u+mfd1dWKeCJ)?n%5k7y3 zd)bjyCaR{qRyp#Zp z+RG49;bfHJJTVxwq-XN2q4T!CLQMrKsuKSasHnloKT}x<5l6q<1%`{?#YC=5Q4(o9 z^z|7tBJu4onX_;d#P#Ulmf|Pxq7cKjj_$#GUYuB|YfyGjcY9edMF22J_xJ68I~eLy z9NGUB(v4yz{1TVhdp@7jc>YT2t+{!p7jLS1(m30tan6y0dMDN@qbs(0UQd6;lYaM^ z@yoEC3>y&lnSK%8`-`s2*tVs-hLU68A3+-^w*#Jle>Cn3v#yY8k zN+fH|z^_h!eT--4ri&DHc}zhR>NfQM%ZWw=F)RKx`M!$h zW=0ul9bG*bBN~C0+$KK5K3%M1_=#r>oV4Z_D=gLqZ04o*hKb+9*A)&9u91SDd6#h+0iUsmIF`@& z11-E|$D7J;p!A5Es?f)mL4Pjr=Y1HnSe}m@($LZ-5+$SOvlcUwW56#TxRsp|*>cq5 zrCel3H<2o}c`X`}2ZP>(y1!>Oe;~sp{F-P(K!6$J18dUHCwI?wCMJPTGrs%w$9+Y6 H{m=dvR5=N{ literal 0 HcmV?d00001 diff --git a/docs/source/configuration/simulation/nodes/images/primaite_node_type_colour_key_light.png b/docs/source/configuration/simulation/nodes/images/primaite_node_type_colour_key_light.png new file mode 100644 index 0000000000000000000000000000000000000000..4b02e9dfa664a50eb102e18be8879f4f336f1eae GIT binary patch literal 66675 zcmeFZc~lbW8a`@+Wm%aGS~=}oLIDXVoN@@j1N=h0dvr6)tbZYrADXGg+Cyp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